2010-06-26 13:07:13 +00:00
|
|
|
/* 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$
|
|
|
|
*/
|
|
|
|
|
2010-06-01 18:06:31 +00:00
|
|
|
#ifndef TESTSUITE_H
|
|
|
|
#define TESTSUITE_H
|
|
|
|
|
|
|
|
#include "common/system.h"
|
2010-06-02 04:45:44 +00:00
|
|
|
#include "common/str.h"
|
|
|
|
#include "common/array.h"
|
2010-06-01 18:06:31 +00:00
|
|
|
|
2010-06-06 14:06:51 +00:00
|
|
|
#include "graphics/fontman.h"
|
|
|
|
#include "graphics/surface.h"
|
|
|
|
|
|
|
|
#include "gui/message.h"
|
|
|
|
|
2010-06-01 18:06:31 +00:00
|
|
|
namespace Testbed {
|
|
|
|
|
2010-06-06 14:06:51 +00:00
|
|
|
enum {
|
|
|
|
kColorBlack = 0,
|
|
|
|
kColorWhite = 1,
|
|
|
|
kColorCustom = 2
|
|
|
|
};
|
|
|
|
|
2010-06-14 20:15:15 +00:00
|
|
|
enum OptionSelected {
|
|
|
|
kOptionLeft = 1,
|
|
|
|
kOptionRight = 0
|
|
|
|
};
|
|
|
|
|
2010-06-14 05:39:10 +00:00
|
|
|
typedef bool (*InvokingFunction)();
|
2010-06-01 18:06:31 +00:00
|
|
|
|
2010-06-02 04:45:44 +00:00
|
|
|
/**
|
|
|
|
* This represents a feature to be tested
|
|
|
|
*/
|
|
|
|
|
2010-06-01 18:06:31 +00:00
|
|
|
struct Test {
|
2010-06-14 05:39:10 +00:00
|
|
|
Test(Common::String name, InvokingFunction f) : featureName(name), driver(f), enabled(true), passed(false) {}
|
2010-06-02 04:45:44 +00:00
|
|
|
Common::String featureName; ///< Name of feature to be tested
|
2010-06-14 05:39:10 +00:00
|
|
|
InvokingFunction driver; ///< Pointer to the function that will invoke this feature test
|
2010-06-02 04:45:44 +00:00
|
|
|
bool enabled; ///< Decides whether or not this test is to be executed
|
|
|
|
bool passed; ///< Collects and stores result of this feature test
|
2010-06-01 18:06:31 +00:00
|
|
|
};
|
|
|
|
|
2010-06-02 04:45:44 +00:00
|
|
|
|
2010-06-01 18:06:31 +00:00
|
|
|
/**
|
|
|
|
* The basic Testsuite class
|
|
|
|
* All the other testsuites would inherit it and override its virtual methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Testsuite {
|
|
|
|
public:
|
|
|
|
Testsuite() {
|
2010-06-02 04:45:44 +00:00
|
|
|
_numTestsPassed = 0;
|
|
|
|
_numTestsExecuted = 0;
|
2010-06-01 18:06:31 +00:00
|
|
|
}
|
2010-06-06 14:06:51 +00:00
|
|
|
|
|
|
|
virtual ~Testsuite() {
|
|
|
|
for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) {
|
|
|
|
delete (*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 19:19:06 +00:00
|
|
|
int getNumTests() const { return _testsToExecute.size(); }
|
|
|
|
int getNumTestsPassed() const { return _numTestsPassed; }
|
|
|
|
int getNumTestsFailed() const { return _numTestsExecuted - _numTestsPassed; }
|
|
|
|
void genReport() const {
|
2010-06-17 11:23:51 +00:00
|
|
|
printf("\nSubsystem: %s\n",getName());
|
|
|
|
printf("Tests executed: %d\n", _numTestsExecuted);
|
|
|
|
printf("Tests Passed: %d\n", _numTestsPassed);
|
|
|
|
printf("Tests Failed: %d\n\n", getNumTestsFailed());
|
2010-06-06 14:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2010-06-14 20:15:15 +00:00
|
|
|
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;
|
2010-06-06 14:06:51 +00:00
|
|
|
}
|
|
|
|
|
2010-06-14 20:15:15 +00:00
|
|
|
static void displayMessage(const Common::String &textToDisplay, const char *defaultButton = "OK", const char *altButton = 0) {
|
2010-06-10 12:40:58 +00:00
|
|
|
GUI::MessageDialog prompt(textToDisplay, defaultButton);
|
2010-06-06 14:06:51 +00:00
|
|
|
prompt.runModal();
|
|
|
|
}
|
|
|
|
|
2010-06-25 14:49:11 +00:00
|
|
|
static Common::Rect writeOnScreen(const Common::String &textToDisplay, const Common::Point &pt, bool flag = false) {
|
2010-06-06 14:06:51 +00:00
|
|
|
const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont));
|
2010-06-25 14:49:11 +00:00
|
|
|
uint fillColor = kColorBlack;
|
|
|
|
uint textColor = kColorWhite;
|
2010-06-06 14:06:51 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-06-25 14:49:11 +00:00
|
|
|
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);
|
2010-06-06 14:06:51 +00:00
|
|
|
|
|
|
|
g_system->unlockScreen();
|
|
|
|
g_system->updateScreen();
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2010-06-06 16:55:29 +00:00
|
|
|
static void clearScreen(const Common::Rect &rect) {
|
2010-06-06 14:06:51 +00:00
|
|
|
Graphics::Surface *screen = g_system->lockScreen();
|
|
|
|
|
|
|
|
screen->fillRect(rect, kColorBlack);
|
|
|
|
|
|
|
|
g_system->unlockScreen();
|
|
|
|
g_system->updateScreen();
|
2010-06-13 07:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void clearScreen() {
|
2010-06-25 14:49:11 +00:00
|
|
|
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();
|
2010-06-13 07:49:36 +00:00
|
|
|
g_system->updateScreen();
|
2010-06-06 14:06:51 +00:00
|
|
|
}
|
2010-06-02 04:45:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a test to the list of tests to be executed
|
|
|
|
*
|
|
|
|
* @param name the string description of the test, for display purposes
|
|
|
|
* @param f pointer to the function that invokes this test
|
|
|
|
*/
|
2010-06-14 05:39:10 +00:00
|
|
|
void addTest(const Common::String &name, InvokingFunction f) {
|
2010-06-02 13:56:04 +00:00
|
|
|
Test* featureTest = new Test(name, f);
|
2010-06-01 18:06:31 +00:00
|
|
|
_testsToExecute.push_back(featureTest);
|
|
|
|
}
|
2010-06-02 04:45:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The driver function for the testsuite
|
|
|
|
* All code should go in here.
|
|
|
|
*/
|
2010-06-06 14:06:51 +00:00
|
|
|
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()) {
|
2010-06-26 12:30:57 +00:00
|
|
|
printf("RESULT: Passed\n");
|
2010-06-06 14:06:51 +00:00
|
|
|
_numTestsPassed++;
|
2010-06-26 12:30:57 +00:00
|
|
|
} else {
|
|
|
|
printf("RESULT: Failed\n");
|
2010-06-06 14:06:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
genReport();
|
|
|
|
}
|
2010-06-13 19:19:06 +00:00
|
|
|
virtual const char *getName() const = 0;
|
2010-06-01 18:06:31 +00:00
|
|
|
|
2010-06-02 13:56:04 +00:00
|
|
|
protected:
|
|
|
|
Common::Array<Test*> _testsToExecute; ///< List of tests to be executed
|
2010-06-06 14:06:51 +00:00
|
|
|
int _numTestsPassed; ///< Number of tests passed
|
|
|
|
int _numTestsExecuted; ///< Number of tests executed
|
2010-06-02 13:56:04 +00:00
|
|
|
};
|
2010-06-01 18:06:31 +00:00
|
|
|
|
|
|
|
} // End of namespace testbed
|
|
|
|
|
|
|
|
#endif
|