diff options
author | Neeraj Kumar | 2010-06-06 14:06:51 +0000 |
---|---|---|
committer | Neeraj Kumar | 2010-06-06 14:06:51 +0000 |
commit | 1819c8b23b0beac173ed61f777a3656879d020d1 (patch) | |
tree | 6ba28fedb2e952a42f5928679aff96a7be8a4aae /engines/testbed | |
parent | 333989fc6d6a254f0383407de6d69be6c8ca994c (diff) | |
download | scummvm-rg350-1819c8b23b0beac173ed61f777a3656879d020d1.tar.gz scummvm-rg350-1819c8b23b0beac173ed61f777a3656879d020d1.tar.bz2 scummvm-rg350-1819c8b23b0beac173ed61f777a3656879d020d1.zip |
polished the interface to interact with testsuites, added code to report test results
svn-id: r49456
Diffstat (limited to 'engines/testbed')
-rw-r--r-- | engines/testbed/gfxtests.cpp | 65 | ||||
-rw-r--r-- | engines/testbed/graphics.cpp | 42 | ||||
-rw-r--r-- | engines/testbed/graphics.h | 17 | ||||
-rw-r--r-- | engines/testbed/testbed.cpp | 19 | ||||
-rw-r--r-- | engines/testbed/testsuite.h | 91 |
5 files changed, 152 insertions, 82 deletions
diff --git a/engines/testbed/gfxtests.cpp b/engines/testbed/gfxtests.cpp index 8ed8c49a1b..092e56ab39 100644 --- a/engines/testbed/gfxtests.cpp +++ b/engines/testbed/gfxtests.cpp @@ -1,7 +1,6 @@ #include "testbed/gfxtests.h" #include "testbed/testsuite.h" -#include "graphics/pixelformat.h" #include "graphics/fontman.h" #include "graphics/surface.h" @@ -9,7 +8,12 @@ namespace Testbed { bool testFullScreenMode() { - printf("Testing fullscreen mode\n"); + Testsuite::displayMessage("Testing fullscreen mode. \n \ + If the feature is supported by the backend, you should expect to see a toggle between fullscreen and normal modes"); + + Common::Point pt(0,100); + Common::Rect rect = Testsuite::writeOnScreen("Testing fullscreen mode", pt); + g_system->delayMillis(1000); bool isFeaturePresent; bool isFeatureEnabled; @@ -17,11 +21,8 @@ bool testFullScreenMode() { isFeaturePresent = g_system->hasFeature(OSystem::kFeatureFullscreenMode); isFeatureEnabled = g_system->getFeatureState(OSystem::kFeatureFullscreenMode); - printf("Testing Feature Presence.. \n"); - if (isFeaturePresent) { //Toggle - printf("Supported\n"); g_system->beginGFXTransaction(); g_system->setFeatureState(OSystem::kFeatureFullscreenMode, !isFeatureEnabled); @@ -33,62 +34,16 @@ bool testFullScreenMode() { g_system->setFeatureState(OSystem::kFeatureFullscreenMode, isFeatureEnabled); g_system->endGFXTransaction(); } + else { + Testsuite::displayMessage("feature not supported"); + } + Testsuite::clearScreen(rect); return true; } bool testAspectRatio() { - - int x_lim; - int y_lim; - - x_lim = g_system->getWidth(); - y_lim = g_system->getHeight(); - - Graphics::PixelFormat f = g_system->getScreenFormat(); - - printf("Screen is %d x %d using %d bytes per pixel\n", x_lim, y_lim, f.bytesPerPixel); - - char blackbuf[16 * 20]; - memset(blackbuf, 1, 16 * 20); // Prepare a buffer 16px wide and 240px high, to fit on a lateral strip - - uint8 pal[3 * 4]; - g_system->grabPalette(pal, 0, 3); - pal[4] = 255; - pal[5] = 255; - pal[6] = 255; - - pal[8] = 0; - pal[9] = 255; - pal[10] = 0; - - g_system->setPalette(pal, 0, 3); - - //g_system->copyRectToScreen((const byte *)blackbuf, 16, 20, 28, 16, 20); - //g_system->updateScreen(); - - // Font usage - - Graphics::Surface *screen = g_system->lockScreen(); - - const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont)); - - uint16 h = font.getFontHeight(); - uint16 y = g_system->getHeight() / 2 - h / 2; - - - Common::Rect r(0,y,screen->w,y+h); - screen->fillRect(r,0); - - Common::String text("Hi thr!"); - - font.drawString(screen, text, 0, y, screen->w, 1, Graphics::kTextAlignCenter); - - g_system->unlockScreen(); - g_system->updateScreen(); - return true; - } } diff --git a/engines/testbed/graphics.cpp b/engines/testbed/graphics.cpp index 67176683ee..a5658a1213 100644 --- a/engines/testbed/graphics.cpp +++ b/engines/testbed/graphics.cpp @@ -4,29 +4,47 @@ namespace Testbed { GFXTestSuite::GFXTestSuite() { - //addTest("FullScreenMode", &testFullScreenMode); + // Initialize color palettes + // Te fourth field is for alpha channel which is unused + // Assuming 8bpp as of now + _palette[0] =_palette[1] =_palette[2] = 0; + _palette[4] =_palette[5] =_palette[6] = 255; + _palette[8] =_palette[9] =_palette[10] = 255; + g_system->setPalette(_palette, 0, 3); + g_system->grabPalette(_palette, 0, 3); + + // Add tests here + addTest("FullScreenMode", &testFullScreenMode); addTest("AspectRatio", &testAspectRatio); } -GFXTestSuite::~GFXTestSuite() { - for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) { - delete (*i); - } -} - const char *GFXTestSuite::getName() { return "GFX"; } -int GFXTestSuite::execute() { - //TODO: Implement the method +void GFXTestSuite::setCustomColor(uint r, uint g, uint b) { + _palette[8] = r; + _palette[9] = g; + _palette[10] = b; + g_system->setPalette(_palette, 0, 3); + g_system->grabPalette(_palette, 0, 3); +} + +void GFXTestSuite::execute() { for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) { printf("Executing Test:%s\n", ((*i)->featureName).c_str()); - printf("Result:%d\n",(*i)->driver()); + // Invoke the test + (*i)->driver(); + _numTestsExecuted++; + // Verify result by Interacting with the tester. + Common::String prompt("Was this similar to what you expected?"); + if (handleInteractiveInput(prompt)) { + _numTestsPassed++; + } } - return 1; + // Report Generation + genReport(); } - } diff --git a/engines/testbed/graphics.h b/engines/testbed/graphics.h index 5afa765364..5dcd02abac 100644 --- a/engines/testbed/graphics.h +++ b/engines/testbed/graphics.h @@ -16,9 +16,20 @@ public: * @see addTest() */ GFXTestSuite(); - ~GFXTestSuite(); - int execute(); - const char *getName(); + ~GFXTestSuite(){} + void execute(); + const char *getName(); + void setCustomColor(uint r, uint g, uint b); + +private: + /** + * A Palette consists of 4 components RGBA. + * As of now we only take 3 colors + * 0 (R:0, G:0, B:0) Black (kColorBlack) + * 1 (R:255, G:255, B:255) White (kColorWhite) + * 2 (R:255, G:255, B:255) your customized color (by default white) (kColorCustom) + */ + byte _palette[3 * 4]; }; } // End of namespace Testbed diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp index 6cf69dc176..4d178d80bd 100644 --- a/engines/testbed/testbed.cpp +++ b/engines/testbed/testbed.cpp @@ -50,11 +50,22 @@ Common::Error TestbedEngine::run() { // Additional setup. printf("TestbedEngine::init\n"); - GFXTestSuite ts; - ts.execute(); + // As of now we are using GUI::MessageDialog for interaction, Test if it works. + // interactive mode could also be modified by a config parameter "non-interactive=1" + // TODO: Implement that - // Your main even loop should be (invoked from) here. - printf("TestbedEngine::go: Hello, World!\n"); + 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 are seeing this correctly, it means interactive tests would run on this system :)"); + interactive = Testsuite::handleInteractiveInput(prompt); + + if (interactive) { + printf("Running tests in Interactive Mode\n"); + // Executing GFX Tests + GFXTestSuite ts; + ts.execute(); + } return Common::kNoError; } diff --git a/engines/testbed/testsuite.h b/engines/testbed/testsuite.h index 4db898c1cd..9605ba5ff3 100644 --- a/engines/testbed/testsuite.h +++ b/engines/testbed/testsuite.h @@ -5,8 +5,19 @@ #include "common/str.h" #include "common/array.h" +#include "graphics/fontman.h" +#include "graphics/surface.h" + +#include "gui/message.h" + namespace Testbed { +enum { + kColorBlack = 0, + kColorWhite = 1, + kColorCustom = 2 +}; + typedef bool (*invokingFunction)(); /** @@ -30,14 +41,72 @@ struct Test { class Testsuite { public: Testsuite() { - _backend = g_system; _numTestsPassed = 0; _numTestsExecuted = 0; } - virtual ~Testsuite() {} + + virtual ~Testsuite() { + for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) { + delete (*i); + } + } + inline int getNumTests() { return _testsToExecute.size(); } inline int getNumTestsPassed() { return _numTestsPassed; } inline int getNumTestsFailed() { return _numTestsExecuted - _numTestsPassed; } + inline void genReport() { + printf("Subsystem:%s\n",getName()); + printf("Tests executed:%d\n", _numTestsExecuted); + printf("Tests Passed:%d\n", _numTestsPassed); + printf("Tests Failed:%d\n", getNumTestsFailed()); + } + + /** + * Prompts for User Input in form of "Yes" or "No" for interactive tests + * e.g: "Is this like you expect?" "Yes" or "No" + * + * @param textToDisplay Display text + * @return true if "Yes" false otherwise + */ + static inline bool handleInteractiveInput(Common::String& textToDisplay) { + GUI::MessageDialog prompt(textToDisplay, "Yes", "No"); + return prompt.runModal() == GUI::kMessageOK ? true : false; + } + + static inline void displayMessage(const char *textToDisplay) { + Common::String message(textToDisplay); + GUI::MessageDialog prompt(message); + prompt.runModal(); + } + + static inline Common::Rect writeOnScreen(const char *textToDisplay, Common::Point &pt) { + const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont)); + + 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); + + screen->fillRect(rect, kColorBlack); + Common::String text(textToDisplay); + font.drawString(screen, text, rect.left, rect.top, screen->w, kColorWhite, Graphics::kTextAlignCenter); + + g_system->unlockScreen(); + g_system->updateScreen(); + + return rect; + } + + static inline void clearScreen(Common::Rect rect) { + Graphics::Surface *screen = g_system->lockScreen(); + + screen->fillRect(rect, kColorBlack); + + g_system->unlockScreen(); + g_system->updateScreen(); + } /** * Adds a test to the list of tests to be executed @@ -54,16 +123,22 @@ public: * The driver function for the testsuite * All code should go in here. */ - virtual int execute() = 0; + 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()) { + _numTestsPassed++; + } + } + genReport(); + } virtual const char *getName() = 0; -private: - OSystem *_backend; ///< Pointer to OSystem backend - int _numTestsPassed; ///< Number of tests passed - int _numTestsExecuted; ///< Number of tests executed - protected: Common::Array<Test*> _testsToExecute; ///< List of tests to be executed + int _numTestsPassed; ///< Number of tests passed + int _numTestsExecuted; ///< Number of tests executed }; } // End of namespace testbed |