diff options
author | Neeraj Kumar | 2010-06-26 14:29:50 +0000 |
---|---|---|
committer | Neeraj Kumar | 2010-06-26 14:29:50 +0000 |
commit | e537ce48bbbdbb0e322370c984e5f906052db003 (patch) | |
tree | e01b4dc8e7856bc7a297878c782746c47074a993 | |
parent | 3cc204f461bc08c16b6c8a0920c432355b4a4d74 (diff) | |
download | scummvm-rg350-e537ce48bbbdbb0e322370c984e5f906052db003.tar.gz scummvm-rg350-e537ce48bbbdbb0e322370c984e5f906052db003.tar.bz2 scummvm-rg350-e537ce48bbbdbb0e322370c984e5f906052db003.zip |
split testsuite.h into testsuite.cpp
svn-id: r50322
-rw-r--r-- | engines/testbed/fs.h | 2 | ||||
-rw-r--r-- | engines/testbed/module.mk | 3 | ||||
-rw-r--r-- | engines/testbed/testbed.cpp | 6 | ||||
-rw-r--r-- | engines/testbed/testsuite.cpp | 144 | ||||
-rw-r--r-- | engines/testbed/testsuite.h | 129 |
5 files changed, 173 insertions, 111 deletions
diff --git a/engines/testbed/fs.h b/engines/testbed/fs.h index 3ba5c46674..50a001e4fe 100644 --- a/engines/testbed/fs.h +++ b/engines/testbed/fs.h @@ -25,6 +25,8 @@ #ifndef FS_H #define FS_H +#include "common/fs.h" + #include "testbed/testsuite.h" namespace Testbed { diff --git a/engines/testbed/module.mk b/engines/testbed/module.mk index 62addd4224..252064b1b4 100644 --- a/engines/testbed/module.mk +++ b/engines/testbed/module.mk @@ -5,7 +5,8 @@ MODULE_OBJS := \ fs.o \ graphics.o \ savegame.o \ - testbed.o + testbed.o \ + testsuite.o MODULE_DIRS += \ engines/testbed diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp index 372b2bf895..4f3acc45d8 100644 --- a/engines/testbed/testbed.cpp +++ b/engines/testbed/testbed.cpp @@ -80,16 +80,16 @@ Common::Error TestbedEngine::run() { // interactive mode could also be modified by a config parameter "non-interactive=1" // TODO: Implement that - bool interactive; Common::String prompt("Welcome to the ScummVM testbed!\n" "It is a framework to test the various ScummVM subsystems namely GFX, Sound, FS, events etc.\n" "If you see this, it means interactive tests would run on this system :)"); // To be set from config file + // By default Interactive tests are enabled // XXX: disabling these as of now for fastly testing other tests - interactive = false; + // Testsuite::isInteractive = false; - if (interactive) { + if (Testsuite::isInteractive) { printf("Running Interactive tests as well\n"); Testsuite::displayMessage(prompt, "proceed?"); // Executing GFX Tests diff --git a/engines/testbed/testsuite.cpp b/engines/testbed/testsuite.cpp new file mode 100644 index 0000000000..f9fb651881 --- /dev/null +++ b/engines/testbed/testsuite.cpp @@ -0,0 +1,144 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#include "graphics/fontman.h" +#include "graphics/surface.h" + +#include "gui/message.h" + +#include "testbed/testsuite.h" + +namespace Testbed { + +// Static public variable of Testsuite +bool Testsuite::isInteractive = true; + +Testsuite::Testsuite() { + _numTestsPassed = 0; + _numTestsExecuted = 0; +} + +Testsuite::~Testsuite() { + for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) { + delete (*i); + } +} + +void Testsuite::genReport() const { + printf("\nSubsystem: %s\n",getName()); + printf("Tests executed: %d\n", _numTestsExecuted); + printf("Tests Passed: %d\n", _numTestsPassed); + printf("Tests Failed: %d\n\n", getNumTestsFailed()); +} + +bool Testsuite::handleInteractiveInput(const Common::String &textToDisplay, const char *opt1, const char *opt2, OptionSelected result) { + GUI::MessageDialog prompt(textToDisplay, opt1, opt2); + return prompt.runModal() == result ? true : false; +} + +void Testsuite::displayMessage(const Common::String &textToDisplay, const char *defaultButton, const char *altButton) { + GUI::MessageDialog prompt(textToDisplay, defaultButton); + prompt.runModal(); +} + +Common::Rect Testsuite::writeOnScreen(const Common::String &textToDisplay, const Common::Point &pt, bool flag) { + const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont)); + uint fillColor = kColorBlack; + uint textColor = kColorWhite; + + Graphics::Surface *screen = g_system->lockScreen(); + + int height = font.getFontHeight(); + int width = screen->w; + + Common::Rect rect(pt.x, pt.y, pt.x + width, pt.y + height); + + if (flag) { + Graphics::PixelFormat pf = g_system->getScreenFormat(); + fillColor = pf.RGBToColor(0 , 0, 0); + textColor = pf.RGBToColor(255 , 255, 255); + } + + screen->fillRect(rect, fillColor); + font.drawString(screen, textToDisplay, rect.left, rect.top, screen->w, textColor, Graphics::kTextAlignCenter); + + g_system->unlockScreen(); + g_system->updateScreen(); + + return rect; +} + +void Testsuite::clearScreen(const Common::Rect &rect) { + Graphics::Surface *screen = g_system->lockScreen(); + + screen->fillRect(rect, kColorBlack); + + g_system->unlockScreen(); + g_system->updateScreen(); +} + +void Testsuite::clearScreen() { + int numBytesPerLine = g_system->getWidth() * g_system->getScreenFormat().bytesPerPixel; + int size = g_system->getHeight() * numBytesPerLine; + 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(); +} + +void Testsuite::clearScreen(bool flag) { + Graphics::Surface *screen = g_system->lockScreen(); + uint fillColor = kColorBlack; + + if (flag) { + fillColor = g_system->getScreenFormat().RGBToColor(0, 0, 0); + } + + screen->fillRect(Common::Rect(0, 0, g_system->getWidth(), g_system->getHeight()), fillColor); + + g_system->unlockScreen(); + g_system->updateScreen(); +} + +void Testsuite::addTest(const Common::String &name, InvokingFunction f) { + Test* featureTest = new Test(name, f); + _testsToExecute.push_back(featureTest); +} + +void Testsuite::execute() { + for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) { + printf("Executing Test:%s\n", ((*i)->featureName).c_str()); + _numTestsExecuted++; + if ((*i)->driver()) { + printf("RESULT: Passed\n"); + _numTestsPassed++; + } else { + printf("RESULT: Failed\n"); + } + } + genReport(); +} + +} // end of namespace Testebed + diff --git a/engines/testbed/testsuite.h b/engines/testbed/testsuite.h index cfdd329922..ca68454d55 100644 --- a/engines/testbed/testsuite.h +++ b/engines/testbed/testsuite.h @@ -29,10 +29,6 @@ #include "common/str.h" #include "common/array.h" -#include "graphics/fontman.h" -#include "graphics/surface.h" - -#include "gui/message.h" namespace Testbed { @@ -69,27 +65,13 @@ struct Test { class Testsuite { public: - Testsuite() { - _numTestsPassed = 0; - _numTestsExecuted = 0; - } - - virtual ~Testsuite() { - for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) { - delete (*i); - } - } - + Testsuite(); + virtual ~Testsuite(); int getNumTests() const { return _testsToExecute.size(); } int getNumTestsPassed() const { return _numTestsPassed; } int getNumTestsFailed() const { return _numTestsExecuted - _numTestsPassed; } - void genReport() const { - printf("\nSubsystem: %s\n",getName()); - printf("Tests executed: %d\n", _numTestsExecuted); - printf("Tests Passed: %d\n", _numTestsPassed); - printf("Tests Failed: %d\n\n", getNumTestsFailed()); - } - + void genReport() const; + /** * Prompts for User Input in form of "Yes" or "No" for interactive tests * e.g: "Is this like you expect?" "Yes" or "No" @@ -97,74 +79,13 @@ public: * @param textToDisplay Display text * @return true if "Yes" false otherwise */ - static bool handleInteractiveInput(const Common::String &textToDisplay, const char *opt1 = "Yes", const char *opt2 = "No", OptionSelected result = kOptionLeft) { - GUI::MessageDialog prompt(textToDisplay, opt1, opt2); - return prompt.runModal() == result ? true : false; - } - - static void displayMessage(const Common::String &textToDisplay, const char *defaultButton = "OK", const char *altButton = 0) { - GUI::MessageDialog prompt(textToDisplay, defaultButton); - prompt.runModal(); - } - - static Common::Rect writeOnScreen(const Common::String &textToDisplay, const Common::Point &pt, bool flag = false) { - const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont)); - uint fillColor = kColorBlack; - uint textColor = kColorWhite; - - Graphics::Surface *screen = g_system->lockScreen(); - - int height = font.getFontHeight(); - int width = screen->w; - - Common::Rect rect(pt.x, pt.y, pt.x + width, pt.y + height); - - if (flag) { - Graphics::PixelFormat pf = g_system->getScreenFormat(); - fillColor = pf.RGBToColor(0 , 0, 0); - textColor = pf.RGBToColor(255 , 255, 255); - } - - screen->fillRect(rect, fillColor); - font.drawString(screen, textToDisplay, rect.left, rect.top, screen->w, textColor, Graphics::kTextAlignCenter); - - g_system->unlockScreen(); - g_system->updateScreen(); - - return rect; - } - - static void clearScreen(const Common::Rect &rect) { - Graphics::Surface *screen = g_system->lockScreen(); - - screen->fillRect(rect, kColorBlack); - - g_system->unlockScreen(); - g_system->updateScreen(); - } + static bool handleInteractiveInput(const Common::String &textToDisplay, const char *opt1 = "Yes", const char *opt2 = "No", OptionSelected result = kOptionLeft); - static void clearScreen() { - int numBytesPerLine = g_system->getWidth() * g_system->getScreenFormat().bytesPerPixel; - int size = g_system->getHeight() * numBytesPerLine; - 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(); - } - - static void clearScreen(bool flag) { - Graphics::Surface *screen = g_system->lockScreen(); - uint fillColor = kColorBlack; - - if (flag) { - fillColor = g_system->getScreenFormat().RGBToColor(0, 0, 0); - } - - screen->fillRect(Common::Rect(0, 0, g_system->getWidth(), g_system->getHeight()), fillColor); - - g_system->unlockScreen(); - g_system->updateScreen(); - } + static void displayMessage(const Common::String &textToDisplay, const char *defaultButton = "OK", const char *altButton = 0); + static Common::Rect writeOnScreen(const Common::String &textToDisplay, const Common::Point &pt, bool flag = false); + static void clearScreen(const Common::Rect &rect); + static void clearScreen(); + static void clearScreen(bool flag); /** * Adds a test to the list of tests to be executed @@ -172,34 +93,28 @@ public: * @param name the string description of the test, for display purposes * @param f pointer to the function that invokes this test */ - void addTest(const Common::String &name, InvokingFunction f) { - Test* featureTest = new Test(name, f); - _testsToExecute.push_back(featureTest); - } - + void addTest(const Common::String &name, InvokingFunction f); + /** * The driver function for the testsuite * All code should go in here. */ - virtual void execute() { - for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) { - printf("Executing Test:%s\n", ((*i)->featureName).c_str()); - _numTestsExecuted++; - if ((*i)->driver()) { - printf("RESULT: Passed\n"); - _numTestsPassed++; - } else { - printf("RESULT: Failed\n"); - } - } - genReport(); - } + virtual void execute(); + virtual const char *getName() const = 0; protected: Common::Array<Test*> _testsToExecute; ///< List of tests to be executed int _numTestsPassed; ///< Number of tests passed int _numTestsExecuted; ///< Number of tests executed + +public: + + /** + * Static variable of this class that determines if the tests are interactive or not. + * Used by various tests to respond accordingly + */ + static bool isInteractive; }; } // End of namespace testbed |