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

sud03r at users.sourceforge.net sud03r at users.sourceforge.net
Sat Jul 24 18:05:19 CEST 2010


Revision: 51248
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51248&view=rev
Author:   sud03r
Date:     2010-07-24 16:05:19 +0000 (Sat, 24 Jul 2010)

Log Message:
-----------
Implemented selection of tests using a config file, config file layout resembles to that of .scummvmrc on linux

Modified Paths:
--------------
    scummvm/branches/gsoc2010-testbed/engines/testbed/config.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/config.h
    scummvm/branches/gsoc2010-testbed/engines/testbed/events.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/misc.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/savegame.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/config.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/config.cpp	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/config.cpp	2010-07-24 16:05:19 UTC (rev 51248)
@@ -22,12 +22,26 @@
  * $Id$
  */
 
+#include "common/fs.h"
+#include "common/stream.h"
+#include "common/config-manager.h"
 #include "engines/engine.h"
 #include "testbed/config.h"
 
 namespace Testbed {
 
-TestbedOptionsDialog::TestbedOptionsDialog(Common::Array<Testsuite *> &tsList, TestbedConfigManager *tsConfMan) : GUI::Dialog("Browser") {
+/**
+ * Stores testbed setting to be accessed/modified from config file.
+ * As of now there is only one entry "isSessionInteractive"
+ */
+struct TestbedSettings {
+	const char *name;
+	bool value;
+} testbedSettings[] = {
+	{"isSessionInteractive", true}
+};
+
+TestbedOptionsDialog::TestbedOptionsDialog(Common::Array<Testsuite *> &tsList, TestbedConfigManager *tsConfMan) : GUI::Dialog("Browser"), _testbedConfMan(tsConfMan) {
 	
 	new GUI::StaticTextWidget(this, "Browser.Headline", "Select Testsuites to Execute");
 	new GUI::StaticTextWidget(this, "Browser.Path", "Use Doubleclick to select/deselect");
@@ -64,6 +78,7 @@
 
 void TestbedOptionsDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
 	Testsuite *ts;
+	Common::WriteStream *ws;
 	switch (cmd) {
 	case GUI::kListItemDoubleClickedCmd:
 		ts  = _testSuiteArray[_testListDisplay->getSelected()];
@@ -106,13 +121,184 @@
 			}
 		}
 		break;
-
+	case GUI::kCloseCmd:
+		// This is final selected state, write it to config file.
+		ws = _testbedConfMan->getConfigWriteStream();
+		_testbedConfMan->writeTestbedConfigToStream(ws);
+		delete ws;
 	default:
 		GUI::Dialog::handleCommand(sender, cmd, data);
 	
 	}
 }
 
+void TestbedConfigManager::writeTestbedConfigToStream(Common::WriteStream *ws) {
+	Common::String wStr;
+	for (Common::Array<Testsuite *>::const_iterator i = _testsuiteList.begin(); i < _testsuiteList.end(); i++) {
+		// Construct the string
+		wStr = "[";
+		wStr += (*i)->getName();
+		wStr += " = ";
+		wStr += (*i)->isEnabled() ? "true" : "false";
+		wStr += "]\n";
+		ws->writeString(wStr);
+		// TODO : for every test
+		const Common::Array<Test *> &testList = (*i)->getTestList();
+		for (Common::Array<Test *>::const_iterator j = testList.begin(); j != testList.end(); j++) {
+			wStr = (*j)->featureName;
+			wStr += " = ";
+			wStr += (*j)->enabled ? "true\n": "false\n";
+			ws->writeString(wStr);
+		}
+		ws->writeString("\n");
+	}
+}
+
+Common::SeekableReadStream *TestbedConfigManager::getConfigReadStream() {
+	// Look for config file in game-path
+	const Common::String &path = ConfMan.get("path");
+	Common::FSDirectory gameRoot(path);
+	Common::SeekableReadStream *rs = gameRoot.createReadStreamForMember(_configFileName);
+	return rs;
+}
+
+Common::WriteStream *TestbedConfigManager::getConfigWriteStream() {
+	// Look for config file in game-path
+	const Common::String &path = ConfMan.get("path");
+	Common::FSNode gameRoot(path);
+	Common::FSNode config = gameRoot.getChild(_configFileName);
+	if (!config.exists()) {
+		Testsuite::logPrintf("Info! No config file found, creating new one");
+	}
+	return config.createWriteStream();
+}
+
+void TestbedConfigManager::editSettingParam(Common::String param, bool value) {
+	for (int i = 0; i < ARRAYSIZE(testbedSettings); i++) {
+		if (param.equalsIgnoreCase(testbedSettings[i].name)) {
+			testbedSettings[i].value = value;
+		}
+	}
+}
+
+void TestbedConfigManager::parseConfigFile() {	
+	Common::SeekableReadStream *rs = getConfigReadStream();
+	if (!rs) {
+		Testsuite::logPrintf("Info! No config file found, using default configuration.\n");
+		return;
+	}
+	Testsuite *currTS = 0;
+	bool globalSettings = true;
+
+	int lineno = 0;
+	while (!rs->eos() && !rs->err()) {
+		Common::String line = rs->readLine();
+		lineno++;
+		// Trim leading / trailing whitespaces
+		line.trim();
+
+		if (0 ==line.size() || '#' == line[0]) {
+			// Skip blank lines and comments
+			continue;
+		}
+
+		if (line.contains("[Global]") || line.contains("[global]")) {
+			// Global settings.
+			globalSettings = true;
+			continue;
+		}
+
+		if (globalSettings) {
+			const char* t = line.c_str();
+			const char *p = strchr(t, '=');
+			Common::String key(t, p);
+			Common::String value(p + 1);
+			// trim both of spaces
+			key.trim();
+			value.trim();
+			if (value.equalsIgnoreCase("true")) {
+				editSettingParam(key, true);
+			} else {
+				editSettingParam(key, false);
+			}
+			continue;
+		}
+
+		// Check testsuites first
+		if ('[' == line[0]) {
+			// This is a testsuite, extract key value
+			const char* t = line.c_str() + 1;
+			const char *p = strchr(t, '=');
+			
+			if (!p) {
+				Testsuite::logPrintf("Error! Parsing : Malformed config file, token '=' missing at line %d\n", lineno);
+				break;
+			}
+
+			Common::String tsName(t, p);
+			Common::String toEnable(p + 1);
+			// trim both of spaces
+			tsName.trim();
+			toEnable.trim();
+			
+			currTS = getTestsuiteByName(tsName);
+			globalSettings = false;
+			if (!currTS) {	
+				Testsuite::logPrintf("Error! Parsing : Unrecognized testsuite name at line %d\n", lineno);
+				break;
+			}
+			toEnable.toLowercase();
+			if (toEnable.contains("true")) {
+				currTS->enable(true);
+			} else {
+				currTS->enable(false);
+			}
+		} else {
+			// A test under "currTS" testsuite
+			if (!currTS) {
+				Testsuite::logPrintf("Error! Parsing : Malformed config file, No testsuite corresponding to test at line %d\n", lineno);
+				break;
+			}
+			// Extract key value
+			const char* t = line.c_str();
+			const char *p = strchr(t, '=');
+			Common::String key(t, p);
+			Common::String value(p + 1);
+			// trim both of spaces
+			key.trim();
+			value.trim();
+			bool isValid = true;
+			if (value.equalsIgnoreCase("true")) {
+				isValid = currTS->enableTest(key, true);
+			} else {
+				isValid = currTS->enableTest(key, false);
+			}
+			if (!isValid) {
+				Testsuite::logPrintf("Error! Parsing : Unrecognized test for testsuite %s at line %d\n", currTS->getName(), lineno);
+			}
+		}
+	}
+	delete rs;
+}
+
+Testsuite *TestbedConfigManager::getTestsuiteByName(const Common::String &name) {
+	for (uint i = 0; i < _testsuiteList.size(); i++) {
+		if (name.equalsIgnoreCase(_testsuiteList[i]->getName())) {
+			return _testsuiteList[i];
+		}
+	}
+	return 0;
+}
+
+bool TestbedConfigManager::getConfigParamValue(const Common::String param) {
+	for (int i = 0; i < ARRAYSIZE(testbedSettings); i++) {
+		if (param.equalsIgnoreCase(testbedSettings[i].name)) {
+			return testbedSettings[i].value;
+		}
+	}
+	return false;
+}
+
 void TestbedConfigManager::selectTestsuites() {
 
 
@@ -122,7 +308,7 @@
 	// TODO : Implement this method
 
 	parseConfigFile();
-
+	Testsuite::isSessionInteractive = getConfigParamValue("isSessionInteractive");
 	if (!Testsuite::isSessionInteractive) {
 		// Non interactive sessions don't need to go beyond
 		return;

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/config.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/config.h	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/config.h	2010-07-24 16:05:19 UTC (rev 51248)
@@ -44,14 +44,24 @@
 	kTestbedDeselectAll = 'dAll'
 };
 
+
+
 class TestbedConfigManager {
 public:
-	TestbedConfigManager(Common::Array<Testsuite *> &tList) : _testsuiteList(tList) {}
+	TestbedConfigManager(Common::Array<Testsuite *> &tList, const Common::String fName) : _testsuiteList(tList), _configFileName(fName) {}
 	~TestbedConfigManager() {}
 	void selectTestsuites();
+	void setConfigFile(const Common::String fName) { _configFileName = fName; }
+	Common::SeekableReadStream *getConfigReadStream();
+	Common::WriteStream *getConfigWriteStream();
+	void writeTestbedConfigToStream(Common::WriteStream *ws);
+	Testsuite *getTestsuiteByName(const Common::String &name);
+	bool getConfigParamValue(const Common::String param);
 private:
 	Common::Array<Testsuite *> &_testsuiteList;
-	void parseConfigFile() {}
+	Common::String	_configFileName;
+	void parseConfigFile();
+	void editSettingParam(Common::String param, bool value);
 };
 
 class TestbedListWidget : public GUI::ListWidget {
@@ -96,6 +106,7 @@
 	Common::Array<Testsuite *> _testSuiteArray;
 	Common::StringArray _testSuiteDescArray;
 	TestbedListWidget *_testListDisplay;
+	TestbedConfigManager *_testbedConfMan;
 };
 
 } // End of namespace Testbed

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/events.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/events.cpp	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/events.cpp	2010-07-24 16:05:19 UTC (rev 51248)
@@ -266,9 +266,9 @@
 }
 
 EventTestSuite::EventTestSuite() {
-	addTest("Mouse Events", &EventTests::mouseEvents);
-	addTest("Keyboard Events", &EventTests::kbdEvents);
-	addTest("Mainmenu Event", &EventTests::showMainMenu);
+	addTest("MouseEvents", &EventTests::mouseEvents);
+	addTest("KeyboardEvents", &EventTests::kbdEvents);
+	addTest("MainmenuEvent", &EventTests::showMainMenu);
 }
 
 } // End of namespace Testbed

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-07-24 16:05:19 UTC (rev 51248)
@@ -73,7 +73,7 @@
 	addTest("Overlays", &GFXtests::overlayGraphics);
 
 	// Specific Tests:
-	addTest("Palette Rotation", &GFXtests::paletteRotation);
+	addTest("PaletteRotation", &GFXtests::paletteRotation);
 	//addTest("Pixel Formats", &GFXtests::pixelFormats);
 }
 
@@ -800,7 +800,7 @@
 	Testsuite::writeOnScreen("If Shaking Effect works, this should shake!", pt);
 	int times = 35;
 	while (times--) {
-		g_system->setShakePos(10);
+		g_system->setShakePos(25);
 		g_system->updateScreen();
 		g_system->setShakePos(0);
 		g_system->updateScreen();

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/misc.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/misc.cpp	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/misc.cpp	2010-07-24 16:05:19 UTC (rev 51248)
@@ -164,7 +164,7 @@
 }
 
 MiscTestSuite::MiscTestSuite() {
-	addTest("Date/time", &MiscTests::testDateTime, false);
+	addTest("Datetime", &MiscTests::testDateTime, false);
 	addTest("Timers", &MiscTests::testTimers, false);
 	addTest("Mutexes", &MiscTests::testMutexes, false);
 }

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/savegame.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/savegame.cpp	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/savegame.cpp	2010-07-24 16:05:19 UTC (rev 51248)
@@ -189,11 +189,11 @@
 }
 
 SaveGameTestSuite::SaveGameTestSuite() {
-	addTest("Opening SaveFile", &SaveGametests::testSaveLoadState, false);
-	addTest("Removing SaveFile", &SaveGametests::testRemovingSavefile, false);
-	addTest("Renaming SaveFile", &SaveGametests::testRenamingSavefile, false);
-	addTest("Listing SaveFile", &SaveGametests::testListingSavefile, false);
-	addTest("Verify Error Messages", &SaveGametests::testErrorMessages, false);
+	addTest("OpeningSaveFile", &SaveGametests::testSaveLoadState, false);
+	addTest("RemovingSaveFile", &SaveGametests::testRemovingSavefile, false);
+	addTest("RenamingSaveFile", &SaveGametests::testRenamingSavefile, false);
+	addTest("ListingSaveFile", &SaveGametests::testListingSavefile, false);
+	addTest("VerifyErrorMessages", &SaveGametests::testErrorMessages, false);
 }
 
 } // End of namespace Testbed

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp	2010-07-24 16:05:19 UTC (rev 51248)
@@ -105,7 +105,7 @@
 	// interactive mode could also be modified by a config parameter "non-interactive=1"
 	// TODO: Implement that
 
-	TestbedConfigManager cfMan(_testsuiteList);
+	TestbedConfigManager cfMan(_testsuiteList, "testbed.config");
 	cfMan.selectTestsuites();
 	
 	// check if user wanted to exit.

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp	2010-07-24 16:05:19 UTC (rev 51248)
@@ -273,6 +273,16 @@
 	g_system->updateScreen();
 }
 
+bool Testsuite::enableTest(const Common::String &testName, bool toEnable) {
+	for (uint i = 0; i < _testsToExecute.size(); i++) {
+		if (_testsToExecute[i]->featureName.equalsIgnoreCase(testName)) {
+			_testsToExecute[i]->enabled = toEnable;
+			return true;
+		}
+	}
+	return false;
+}
+
 void Testsuite::execute() {
 	// Main Loop for a testsuite
 
@@ -286,6 +296,11 @@
 	pt.y += getLineSeparation();
 
 	for (Common::Array<Test *>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) {
+		if (!(*i)->enabled) {
+			logPrintf("Info! Skipping Test: %s, Skipped by configuration.\n", ((*i)->featureName).c_str());
+			continue;	
+		}
+
 		if (toQuit == kSkipNext) {
 			logPrintf("Info! Skipping Test: %s, Skipped by user.\n", ((*i)->featureName).c_str());
 			toQuit = kLoopNormal;

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h	2010-07-24 15:30:06 UTC (rev 51247)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h	2010-07-24 16:05:19 UTC (rev 51248)
@@ -90,6 +90,7 @@
 	virtual void enable(bool flag) {
 		_isTsEnabled = flag;
 	}
+	bool enableTest(const Common::String &testName, bool enable);
 
 	/**
 	 * Prompts for User Input in form of "Yes" or "No" for interactive tests
@@ -162,6 +163,7 @@
 	static void setCurrentFontUsageType(Graphics::FontManager::FontUsage f) { _displayFont = f; }
 
 	static void updateStats(const char *prefix, const char *info, uint numTests, uint testNum, Common::Point pt);
+	const Common::Array<Test *>& getTestList() { return _testsToExecute; }
 
 
 protected:


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