[Scummvm-cvs-logs] SF.net SVN: scummvm:[49456] scummvm/branches/gsoc2010-testbed/engines/ testbed

sud03r at users.sourceforge.net sud03r at users.sourceforge.net
Sun Jun 6 16:06:51 CEST 2010


Revision: 49456
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49456&view=rev
Author:   sud03r
Date:     2010-06-06 14:06:51 +0000 (Sun, 06 Jun 2010)

Log Message:
-----------
polished the interface to interact with testsuites, added code to report test results

Modified Paths:
--------------
    scummvm/branches/gsoc2010-testbed/engines/testbed/gfxtests.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h
    scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/gfxtests.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/gfxtests.cpp	2010-06-06 13:40:15 UTC (rev 49455)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/gfxtests.cpp	2010-06-06 14:06:51 UTC (rev 49456)
@@ -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 @@
 
 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 @@
 	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 @@
 		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;
-
 }
 
 }

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-06-06 13:40:15 UTC (rev 49455)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-06-06 14:06:51 UTC (rev 49456)
@@ -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();
 }
 
-
 }

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h	2010-06-06 13:40:15 UTC (rev 49455)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.h	2010-06-06 14:06:51 UTC (rev 49456)
@@ -16,9 +16,20 @@
 	 * @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

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp	2010-06-06 13:40:15 UTC (rev 49455)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp	2010-06-06 14:06:51 UTC (rev 49456)
@@ -50,11 +50,22 @@
 	// 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;
 }

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h	2010-06-06 13:40:15 UTC (rev 49455)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h	2010-06-06 14:06:51 UTC (rev 49456)
@@ -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,15 +41,73 @@
 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 @@
 	 * 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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list