diff options
| -rw-r--r-- | engines/testbed/config.cpp | 192 | ||||
| -rw-r--r-- | engines/testbed/config.h | 15 | ||||
| -rw-r--r-- | engines/testbed/events.cpp | 6 | ||||
| -rw-r--r-- | engines/testbed/graphics.cpp | 4 | ||||
| -rw-r--r-- | engines/testbed/misc.cpp | 2 | ||||
| -rw-r--r-- | engines/testbed/savegame.cpp | 10 | ||||
| -rw-r--r-- | engines/testbed/testbed.cpp | 2 | ||||
| -rw-r--r-- | engines/testbed/testsuite.cpp | 15 | ||||
| -rw-r--r-- | engines/testbed/testsuite.h | 2 | 
9 files changed, 231 insertions, 17 deletions
| diff --git a/engines/testbed/config.cpp b/engines/testbed/config.cpp index 7fe058198e..21f4bd121b 100644 --- a/engines/testbed/config.cpp +++ b/engines/testbed/config.cpp @@ -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 @@ TestbedOptionsDialog::~TestbedOptionsDialog() {}  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 @@ void TestbedOptionsDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd,  			}  		}  		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 @@ void TestbedConfigManager::selectTestsuites() {  	// TODO : Implement this method  	parseConfigFile(); - +	Testsuite::isSessionInteractive = getConfigParamValue("isSessionInteractive");  	if (!Testsuite::isSessionInteractive) {  		// Non interactive sessions don't need to go beyond  		return; diff --git a/engines/testbed/config.h b/engines/testbed/config.h index bbb591d337..42320bbee8 100644 --- a/engines/testbed/config.h +++ b/engines/testbed/config.h @@ -44,14 +44,24 @@ enum {  	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 @@ private:  	Common::Array<Testsuite *> _testSuiteArray;  	Common::StringArray _testSuiteDescArray;  	TestbedListWidget *_testListDisplay; +	TestbedConfigManager *_testbedConfMan;  };  } // End of namespace Testbed diff --git a/engines/testbed/events.cpp b/engines/testbed/events.cpp index a7c0d534cf..838112c124 100644 --- a/engines/testbed/events.cpp +++ b/engines/testbed/events.cpp @@ -266,9 +266,9 @@ bool EventTests::showMainMenu() {  }  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 diff --git a/engines/testbed/graphics.cpp b/engines/testbed/graphics.cpp index 40eab3de3e..4cbe963031 100644 --- a/engines/testbed/graphics.cpp +++ b/engines/testbed/graphics.cpp @@ -73,7 +73,7 @@ GFXTestSuite::GFXTestSuite() {  	addTest("Overlays", &GFXtests::overlayGraphics);  	// Specific Tests: -	addTest("Palette Rotation", &GFXtests::paletteRotation); +	addTest("PaletteRotation", &GFXtests::paletteRotation);  	//addTest("Pixel Formats", &GFXtests::pixelFormats);  } @@ -800,7 +800,7 @@ bool GFXtests::shakingEffect() {  	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(); diff --git a/engines/testbed/misc.cpp b/engines/testbed/misc.cpp index e2b0fef488..74f0af2948 100644 --- a/engines/testbed/misc.cpp +++ b/engines/testbed/misc.cpp @@ -164,7 +164,7 @@ bool MiscTests::testMutexes() {  }  MiscTestSuite::MiscTestSuite() { -	addTest("Date/time", &MiscTests::testDateTime, false); +	addTest("Datetime", &MiscTests::testDateTime, false);  	addTest("Timers", &MiscTests::testTimers, false);  	addTest("Mutexes", &MiscTests::testMutexes, false);  } diff --git a/engines/testbed/savegame.cpp b/engines/testbed/savegame.cpp index af0eaa7bcd..80c83725d2 100644 --- a/engines/testbed/savegame.cpp +++ b/engines/testbed/savegame.cpp @@ -189,11 +189,11 @@ bool SaveGametests::testErrorMessages() {  }  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 diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp index 5702f0356f..c7c2fd219d 100644 --- a/engines/testbed/testbed.cpp +++ b/engines/testbed/testbed.cpp @@ -105,7 +105,7 @@ Common::Error TestbedEngine::run() {  	// 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. diff --git a/engines/testbed/testsuite.cpp b/engines/testbed/testsuite.cpp index 5dbdb72515..99892b7425 100644 --- a/engines/testbed/testsuite.cpp +++ b/engines/testbed/testsuite.cpp @@ -273,6 +273,16 @@ void Testsuite::updateStats(const char *prefix, const char *info, uint testNum,  	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 @@ void Testsuite::execute() {  	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; diff --git a/engines/testbed/testsuite.h b/engines/testbed/testsuite.h index 08591d7b49..b4c30a7cdd 100644 --- a/engines/testbed/testsuite.h +++ b/engines/testbed/testsuite.h @@ -90,6 +90,7 @@ public:  	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 @@ public:  	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: | 
