From 85958744a2314d5b2556bece162dbf6bc4d54505 Mon Sep 17 00:00:00 2001 From: Neeraj Kumar Date: Tue, 13 Jul 2010 19:26:45 +0000 Subject: Added code to enable testsuite selection using checkboxes svn-id: r50850 --- engines/testbed/testbed.cpp | 66 +++++++++++++++++++++++++++++++++---------- engines/testbed/testbed.h | 21 ++++++++++++-- engines/testbed/testsuite.cpp | 3 +- 3 files changed, 72 insertions(+), 18 deletions(-) (limited to 'engines') diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp index ef241d66f8..db1fe6045c 100644 --- a/engines/testbed/testbed.cpp +++ b/engines/testbed/testbed.cpp @@ -27,7 +27,8 @@ #include "common/system.h" #include "engines/util.h" - +#include "gui/options.h" + #include "testbed/events.h" #include "testbed/fs.h" #include "testbed/graphics.h" @@ -83,13 +84,11 @@ TestbedEngine::~TestbedEngine() { } } -void TestbedEngine::enableTestsuite(const char *name, bool enable) { +void TestbedEngine::enableTestsuite(const Common::String &name, bool enable) { Common::Array::const_iterator iter; - Common::String tsName(name); - for (iter = _testsuiteList.begin(); iter != _testsuiteList.end(); iter++) { - if (tsName.equalsIgnoreCase((*iter)->getName())) { + if (name.equalsIgnoreCase((*iter)->getName())) { (*iter)->enable(enable); break; } @@ -108,6 +107,34 @@ void TestbedEngine::invokeTestsuites() { } } +TestbedOptionsDialog::TestbedOptionsDialog() : GUI::OptionsDialog("Select", 120, 120, 360, 200), _hOffset(15), _vOffset(15), _boxWidth(300), _boxHeight(10) { + new GUI::StaticTextWidget(this, _hOffset, _vOffset, _boxWidth, _boxHeight, "Select testsuites to Execute", Graphics::kTextAlignCenter); + _vOffset += 20; + addCheckbox("FS"); + addCheckbox("GFX"); + addCheckbox("Savegames"); + addCheckbox("Misc"); + addCheckbox("Events"); + new GUI::ButtonWidget(this, 80 , _vOffset + 10, 80, 25, "Continue", GUI::kOKCmd, 'C'); + new GUI::ButtonWidget(this, 200, _vOffset + 10, 80, 25, "Exit", GUI::kCloseCmd, 'X'); +} + +TestbedOptionsDialog::~TestbedOptionsDialog() {} + +void TestbedOptionsDialog::addCheckbox(const Common::String &tsName) { + _checkBoxes.push_back(new GUI::CheckboxWidget(this, _hOffset, _vOffset, _boxWidth, _boxHeight, tsName)); + _vOffset += 20; +} + +bool TestbedOptionsDialog::isEnabled(const Common::String &tsName) { + for (uint i = 0; i < _checkBoxes.size(); i++) { + if (_checkBoxes[i]->getLabel().equalsIgnoreCase(tsName)) { + return _checkBoxes[i]->getState(); + } + } + return false; +} + Common::Error TestbedEngine::run() { // Initialize graphics using following: initGraphics(320, 200, false); @@ -129,17 +156,26 @@ Common::Error TestbedEngine::run() { Testsuite::logPrintf("Info! : Interactive tests are also being executed.\n"); Testsuite::displayMessage(prompt, "Proceed?"); } - - // Enable the testsuites you want to execute - enableTestsuite("FS", true); - enableTestsuite("GFX", true); - // enableTestsuite("savegames", true); - // enableTestsuite("misc", true); - // enableTestsuite("events", true); - // invoke them + + // Select testsuites using checkboxes + TestbedOptionsDialog tbd; + tbd.runModal(); + + // check if user wanted to exit. + if (shouldQuit()) { + return Common::kNoError; + } + + // Enable selected testsuites + Common::String tsName; + for (uint i = 0; i < _testsuiteList.size(); i++) { + tsName = _testsuiteList[i]->getName(); + if (tbd.isEnabled(tsName)) { + enableTestsuite(tsName, true); + } + } + invokeTestsuites(); - - return Common::kNoError; } diff --git a/engines/testbed/testbed.h b/engines/testbed/testbed.h index 914e39dad6..e85bae3784 100644 --- a/engines/testbed/testbed.h +++ b/engines/testbed/testbed.h @@ -27,6 +27,8 @@ #include "engines/engine.h" +#include "gui/options.h" + #include "testbed/testsuite.h" namespace Testbed { @@ -47,7 +49,7 @@ public: * All testsuites are disabled by default * To enable testsuite X, call enableTestsuite("X", true); */ - void enableTestsuite(const char *name, bool enable); + void enableTestsuite(const Common::String &name, bool enable); /** * Invokes configured testsuites. @@ -57,7 +59,22 @@ public: bool hasFeature(EngineFeature f) const; private: - Common::Array _testsuiteList; + Common::Array _testsuiteList; +}; + +class TestbedOptionsDialog : public GUI::OptionsDialog { +public: + TestbedOptionsDialog(); + ~TestbedOptionsDialog(); + void addCheckbox(const Common::String &tsName); + bool isEnabled(const Common::String &tsName); + +private: + Common::Array _checkBoxes; + const int _hOffset; // current offset from left + int _vOffset; // current offset from top + const int _boxWidth; + const int _boxHeight; }; } // End of namespace Testbed diff --git a/engines/testbed/testsuite.cpp b/engines/testbed/testsuite.cpp index c941a71a88..ab87a31c52 100644 --- a/engines/testbed/testsuite.cpp +++ b/engines/testbed/testsuite.cpp @@ -187,7 +187,8 @@ void Testsuite::clearScreen() { byte *buffer = new byte[size]; memset(buffer, 0, size); g_system->copyRectToScreen(buffer, numBytesPerLine, 0, 0, g_system->getWidth(), g_system->getHeight()); - g_system->updateScreen(); + g_system->updateScreen(); + delete[] buffer; } void Testsuite::clearScreen(bool flag) { -- cgit v1.2.3