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

sud03r at users.sourceforge.net sud03r at users.sourceforge.net
Wed Jun 30 00:46:56 CEST 2010


Revision: 50512
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50512&view=rev
Author:   sud03r
Date:     2010-06-29 22:46:56 +0000 (Tue, 29 Jun 2010)

Log Message:
-----------
removed all printfs, added logging feature in form of logPrintf

Modified Paths:
--------------
    scummvm/branches/gsoc2010-testbed/engines/testbed/fs.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/testbed.h
    scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp
    scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/fs.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/fs.cpp	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/fs.cpp	2010-06-29 22:46:56 UTC (rev 50512)
@@ -43,19 +43,19 @@
 	Common::SeekableReadStream *readStream = directory->createReadStreamForMember(file);
 
 	if (!readStream) {
-		printf("LOG:Can't open game file for reading\n");
+		Testsuite::logDetailedPrintf("Can't open game file for reading\n");
 		return false;
 	} 
 	
 	Common::String msg = readStream->readLine();
 	delete readStream;
-	printf("LOG: Message Extracted from %s/%s : %s\n",directory->getFSNode().getName().c_str(), file, msg.c_str());
+	Testsuite::logDetailedPrintf("Message Extracted from %s/%s : %s\n",directory->getFSNode().getName().c_str(), file, msg.c_str());
 
 
 	Common::String expectedMsg = "It works!";
 
 	if (!msg.equals(expectedMsg)) {
-		printf("LOG: Can't read Correct data from file\n");
+		Testsuite::logDetailedPrintf("Can't read Correct data from file\n");
 		return false;
 	}
 
@@ -69,7 +69,7 @@
 	int numFailed = 0;
 	
 	if (!gameRoot.getFSNode().isDirectory()) {
-		printf("LOG:game Path should be a directory");
+		Testsuite::logDetailedPrintf("game Path should be a directory");
 		return false;
 	}
 	
@@ -82,7 +82,7 @@
 		Common::FSDirectory *directory = gameRoot.getSubDirectory(dirName); 
 
 		if (!readDataFromFile(directory, fileName.c_str())) {
-			printf("LOG : reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
+			Testsuite::logDetailedPrintf("Reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
 			numFailed++;
 		}
 		
@@ -91,7 +91,7 @@
 		directory = gameRoot.getSubDirectory(dirName); 
 		
 		if (!readDataFromFile(directory, fileName.c_str())) {
-			printf("LOG : reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
+			Testsuite::logDetailedPrintf("Reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
 			numFailed++;
 		}
 		
@@ -100,12 +100,12 @@
 		directory = gameRoot.getSubDirectory(dirName); 
 		
 		if (!readDataFromFile(directory, fileName.c_str())) {
-			printf("LOG : reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
+			Testsuite::logDetailedPrintf("Reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
 			numFailed++;
 		}
 	}
 	
-	printf("LOG:failed %d out of 15\n", numFailed);
+	Testsuite::logDetailedPrintf("Failed %d out of 15\n", numFailed);
 	return false;
 }
 
@@ -123,7 +123,7 @@
 	Common::WriteStream *ws = fileToWrite.createWriteStream();
 	
 	if (!ws) {
-		printf("LOG: Can't open writable file in game data dir\n");
+		Testsuite::logDetailedPrintf("Can't open writable file in game data dir\n");
 		return false;
 	}
 	
@@ -137,7 +137,7 @@
 
 	if (readFromFile.equals("ScummVM Rocks!")) {
 		// All good
-		printf("LOG: Data written and read correctly\n");
+		Testsuite::logDetailedPrintf("Data written and read correctly\n");
 		return true;
 	}
 

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/graphics.cpp	2010-06-29 22:46:56 UTC (rev 50512)
@@ -311,9 +311,9 @@
 		g_system->delayMillis(1000);
 		
 		if (isFeatureEnabled) {
-			printf("LOG: Current Mode is Fullsecreen\n");
+			Testsuite::logDetailedPrintf("Current Mode is Fullsecreen\n");
 		} else {
-			printf("LOG: Current Mode is Windowed\n");
+			Testsuite::logDetailedPrintf("Current Mode is Windowed\n");
 		}
 
 		prompt = " Which mode do you see currently ?  ";
@@ -321,7 +321,7 @@
 		if (!Testsuite::handleInteractiveInput(prompt, "Fullscreen", "Windowed", shouldSelect)) {
 			// User selected incorrect current state
 			passed = false;
-			printf("LOG: g_system->getFeatureState() failed\n");
+			Testsuite::logDetailedPrintf("g_system->getFeatureState() failed\n");
 		}
 
 		g_system->beginGFXTransaction();
@@ -339,7 +339,7 @@
 		if (!Testsuite::handleInteractiveInput(prompt, "Fullscreen", "Windowed", shouldSelect)) {
 			// User selected incorrect mode
 			passed = false;
-			printf("LOG: g_system->setFeatureState() failed\n");
+			Testsuite::logDetailedPrintf("g_system->setFeatureState() failed\n");
 		}
 		
 		g_system->beginGFXTransaction();
@@ -352,7 +352,7 @@
 		
 		if (!Testsuite::handleInteractiveInput(prompt, "Yes, it is", "Nopes", shouldSelect)) {
 			// User selected incorrect mode
-			printf("LOG: switching back to initial state failed\n");
+			Testsuite::logDetailedPrintf("switching back to initial state failed\n");
 			passed = false;
 		}
 
@@ -393,7 +393,7 @@
 		if (!Testsuite::handleInteractiveInput(prompt, "Circle", "Ellipse", shouldSelect)) {
 			// User selected incorrect option
 			passed = false;
-			printf("LOG: Aspect Ratio Correction failed\n");
+			Testsuite::logDetailedPrintf("Aspect Ratio Correction failed\n");
 		}
 		
 		g_system->beginGFXTransaction();
@@ -407,7 +407,7 @@
 		if (!Testsuite::handleInteractiveInput(prompt, "Circle", "Ellipse", shouldSelect)) {
 			// User selected incorrect option
 			passed = false;
-			printf("LOG: Aspect Ratio Correction failed\n");
+			Testsuite::logDetailedPrintf("Aspect Ratio Correction failed\n");
 		}
 		
 		g_system->beginGFXTransaction();
@@ -421,7 +421,7 @@
 	
 	if (Testsuite::handleInteractiveInput("This should definetely be your initial state?", "Yes, it is", "Nopes", kOptionRight)) {
 		// User selected incorrect mode
-		printf("LOG: switching back to initial state failed\n");
+		Testsuite::logDetailedPrintf("Switching back to initial state failed\n");
 		passed = false;
 	}
 	
@@ -448,7 +448,7 @@
 	mouseMovements();
 	
 	if (Testsuite::handleInteractiveInput("Which color did the cursor appeared to you?", "Yellow", "Any other", kOptionRight)) {
-		printf("LOG: Couldn't use cursor palette for rendering cursor\n");
+		Testsuite::logDetailedPrintf("Couldn't use cursor palette for rendering cursor\n");
 		passed = false;
 	}	
 
@@ -457,7 +457,7 @@
 	setupMouseLoop(true);
 	
 	if (Testsuite::handleInteractiveInput("Which color did the cursor appeared to you?", "Red", "Any other", kOptionRight)) {
-		printf("LOG: Couldn't use Game palette for rendering cursor\n");
+		Testsuite::logDetailedPrintf("Couldn't use Game palette for rendering cursor\n");
 		passed = false;
 	}	
 
@@ -586,7 +586,7 @@
 			Testsuite::clearScreen();
 
 		} else {
-			printf("LOG: Switching to graphics mode %s failed\n", gfxMode->name);
+			Testsuite::logDetailedPrintf("Switching to graphics mode %s failed\n", gfxMode->name);
 			return false;
 		}
 		gfxMode++;
@@ -600,7 +600,7 @@
 	OSystem::TransactionError gfxError = g_system->endGFXTransaction();
 
 	if (gfxError != OSystem::kTransactionSuccess || !isGFXModeSet) {
-		printf("LOG: Switcing to initial state failed\n");
+		Testsuite::logDetailedPrintf("Switcing to initial state failed\n");
 		return false;
 	}
 
@@ -624,7 +624,7 @@
 	g_system->delayMillis(1500);
 
 	if (Testsuite::handleInteractiveInput("Did the test worked as you were expecting?", "Yes", "No", kOptionRight)) {
-		printf("LOG: Shaking Effect didn't worked");
+		Testsuite::logDetailedPrintf("Shaking Effect didn't worked");
 		return false;
 	}
 	Testsuite::clearScreen();
@@ -668,7 +668,7 @@
 	g_system->clearFocusRectangle();
 
 	if (Testsuite::handleInteractiveInput("Did you noticed a variation in focus?", "Yes", "No", kOptionRight)) {
-		printf("LOG: Focus Rectangle feature doesn't works. Check platform.\n");
+		Testsuite::logDetailedPrintf("Focus Rectangle feature doesn't works. Check platform.\n");
 	}
 	
 	Testsuite::clearScreen();
@@ -696,7 +696,7 @@
 	g_system->updateScreen();
 
 	if (Testsuite::handleInteractiveInput("Did you see a green overlayed rectangle?", "Yes", "No", kOptionRight)) {
-		printf("LOG: Overlay Rectangle feature doesn't works\n");
+		Testsuite::logDetailedPrintf("Overlay Rectangle feature doesn't works\n");
 		return false;
 	}
 	
@@ -758,7 +758,7 @@
 	int numPassed = 0;
 	bool numFailed = 0;
 	
-	printf("LOG: Testing Pixel Formats. Size of list : %d\n", pfList.size());
+	Testsuite::logDetailedPrintf("Testing Pixel Formats. Size of list : %d\n", pfList.size());
 	
 	for (iter = pfList.begin(); iter != pfList.end(); iter++) {
 		
@@ -767,7 +767,7 @@
 			// Palettes already tested
 			continue;
 		} else if (iter->bytesPerPixel > 2) {
-			printf("LOG: Can't test pixels with bpp > 2\n");
+			Testsuite::logDetailedPrintf("Can't test pixels with bpp > 2\n");
 			continue;
 		}
 		
@@ -815,11 +815,11 @@
 			numPassed++;
 		} else {
 			numFailed++;
-			printf("LOG: Testing pixel format failed for format #%d on the list\n", numFormatsTested);
+			Testsuite::logDetailedPrintf("Testing pixel format failed for format #%d on the list\n", numFormatsTested);
 		}
 	}
 	if (numFailed) {
-		printf("LOG: Pixel Format test: Failed : %d, Passed : %d, Ignored %d\n",numFailed, numPassed, numFormatsTested - (numPassed + numFailed));
+		Testsuite::logDetailedPrintf("Pixel Format test: Failed : %d, Passed : %d, Ignored %d\n",numFailed, numPassed, numFormatsTested - (numPassed + numFailed));
 		return false;
 	}
 	

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/misc.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/misc.cpp	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/misc.cpp	2010-06-29 22:46:56 UTC (rev 50512)
@@ -45,7 +45,7 @@
 void MiscTests::criticalSection(void *arg) {
 	SharedVars &sv = *((SharedVars *) arg);
 	
-	printf("LOG: Before critical section: %d %d\n", sv.first, sv.second);
+	Testsuite::logDetailedPrintf("Before critical section: %d %d\n", sv.first, sv.second);
 	g_system->lockMutex(sv.mutex);
 
 	// In any case, the two vars must be equal at entry, if mutex works fine.
@@ -63,7 +63,7 @@
 	}
 
 	sv.second *= sv.first;
-	printf("LOG: After critical section: %d %d\n", sv.first, sv.second);
+	Testsuite::logDetailedPrintf("After critical section: %d %d\n", sv.first, sv.second);
 	g_system->unlockMutex(sv.mutex);
 
 	g_system->getTimerManager()->removeTimerProc(criticalSection);
@@ -72,10 +72,10 @@
 bool MiscTests::testDateTime() {
 	TimeDate t1, t2;
 	g_system->getTimeAndDate(t1);
-	printf("LOG: Current Time and Date: ");
+	Testsuite::logDetailedPrintf("Current Time and Date: ");
 	Common::String dateTimeNow;
 	getHumanReadableFormat(t1, dateTimeNow);
-	printf("%s\n", dateTimeNow.c_str());
+	Testsuite::logDetailedPrintf("%s\n", dateTimeNow.c_str());
 
 	if (Testsuite::isInteractive) {
 		// Directly verify date
@@ -89,9 +89,9 @@
 	// Now, Put some delay
 	g_system->delayMillis(2000);
 	g_system->getTimeAndDate(t2);
-	printf("LOG: Time and Date 2s later: ");
+	Testsuite::logDetailedPrintf("Time and Date 2s later: ");
 	getHumanReadableFormat(t2, dateTimeNow);
-	printf("%s\n", dateTimeNow.c_str());
+	Testsuite::logDetailedPrintf("%s\n", dateTimeNow.c_str());
 	
 	if (t1.tm_year == t2.tm_year && t1.tm_mon == t2.tm_mon && t1.tm_mday == t2.tm_mday) {
 		if (t1.tm_mon == t2.tm_mon && t1.tm_year == t2.tm_year){
@@ -132,7 +132,7 @@
 	// wait till timed process exits
 	g_system->delayMillis(3000);
 
-	printf("LOG: Final Value: %d %d\n", sv.first, sv.second);
+	Testsuite::logDetailedPrintf("Final Value: %d %d\n", sv.first, sv.second);
 	g_system->deleteMutex(sv.mutex);
 
 	if (sv.resultSoFar && 6 == sv.second) {

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/savegame.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/savegame.cpp	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/savegame.cpp	2010-06-29 22:46:56 UTC (rev 50512)
@@ -39,7 +39,7 @@
 	Common::OutSaveFile *saveFile = saveFileMan->openForSaving(fileName);
 
 	if (!saveFile) {
-		printf("LOG: Can't open saveFile %s\n", fileName);
+		Testsuite::logDetailedPrintf("Can't open saveFile %s\n", fileName);
 		return false;
 	}
 
@@ -56,7 +56,7 @@
 	Common::InSaveFile *loadFile = saveFileMan->openForLoading(fileName);
 	
 	if (!loadFile) {
-		printf("LOG: Can't open save File to load\n");
+		Testsuite::logDetailedPrintf("Can't open save File to load\n");
 		return false;
 	}
 
@@ -74,13 +74,13 @@
 bool SaveGametests::testSaveLoadState() {
 	// create a savefile with "ScummVM Rocks!" written on it
 	if (!writeDataToFile("tBedSavefile.0", "ScummVM Rocks!")) {
-		printf("LOG: Writing data to savefile failed\n");
+		Testsuite::logDetailedPrintf("Writing data to savefile failed\n");
 		return false;
 	}
 
 	// Verify if it contains the same data
 	if (!readAndVerifyData("tBedSavefile.0", "ScummVM Rocks!")) {
-		printf("LOG: Reading data from savefile failed\n");
+		Testsuite::logDetailedPrintf("Reading data from savefile failed\n");
 		return false;
 	}
 
@@ -93,7 +93,7 @@
 
 	// Create a dummy savefile
 	if (!writeDataToFile("tBedSavefileToRemove.0", "Dummy Savefile!")) {
-		printf("LOG: Writing data to savefile failed\n");
+		Testsuite::logDetailedPrintf("Writing data to savefile failed\n");
 		return false;
 	}
 
@@ -104,7 +104,7 @@
 	Common::InSaveFile *loadFile = saveFileMan->openForLoading("saveFile.0");
 	if (loadFile) {
 		// Removing failed
-		printf("LOG: Removing savefile failed\n");
+		Testsuite::logDetailedPrintf("Removing savefile failed\n");
 		return false;
 	}
 
@@ -115,7 +115,7 @@
 	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
 	// Open a file for renaming
 	if (!writeDataToFile("tBedSomeWeirdName.0", "Rename me!")) {
-		printf("LOG: Writing data to savefile failed\n");
+		Testsuite::logDetailedPrintf("Writing data to savefile failed\n");
 		return false;
 	}
 	
@@ -124,7 +124,7 @@
 
 	// Verify if it contains the same data
 	if (!readAndVerifyData("tBedSomeCoolName.0", "Rename me!")) {
-		printf("LOG: Renaming savefile failed\n");
+		Testsuite::logDetailedPrintf("Renaming savefile failed\n");
 		return false;
 	}
 	
@@ -145,7 +145,7 @@
 
 	if ( error != Common::kNoError) {
 		// Abort. Some Error in writing files
-		printf("LOG: Error while creating savefiles: %s\n", Common::errorToString(error));
+		Testsuite::logDetailedPrintf("Error while creating savefiles: %s\n", Common::errorToString(error));
 		return false;
 	}
 
@@ -160,14 +160,14 @@
 				}
 				if (savefileList.size() == j) {
 					// A match for this name not found
-					printf("LOG: Listed Names don't match\n");
+					Testsuite::logDetailedPrintf("Listed Names don't match\n");
 					return false;
 				}
 			}
 		}
 		return true;
 	} else {
-		printf("LOG: listing Savefiles failed!\n");
+		Testsuite::logDetailedPrintf("listing Savefiles failed!\n");
 		return false;
 	}
 
@@ -180,17 +180,17 @@
 	saveFileMan->clearError();
 	
 	// Try opening a non existing file
-	readAndVerifyData("tBedSomeNonExistentSaveFile.0", "I don't exist!");
+	readAndVerifyData("tBedSomeNonExistentSaveFile.0", "File doesn't exists!");
 
 	Common::Error error = saveFileMan->getError();
 	if (error == Common::kNoError) {
 		// blunder! how come?
-		printf("LOG: SaveFileMan.getError() failed\n");
+		Testsuite::logDetailedPrintf("SaveFileMan.getError() failed\n");
 		return false;
 	}
 	// Can't actually predict whether which error, kInvalidPath or kPathDoesNotExist or some other?
 	// So just return true if some error
-	printf("LOG: getError returned : %s\n", saveFileMan->getErrorDesc().c_str());
+	Testsuite::logDetailedPrintf("getError returned : %s\n", saveFileMan->getErrorDesc().c_str());
 	return true;
 }
 

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.cpp	2010-06-29 22:46:56 UTC (rev 50512)
@@ -22,9 +22,10 @@
  * $Id$
  */
 
+#include "common/debug-channels.h"
 #include "common/scummsys.h"
 #include "common/system.h"
- 
+
 #include "engines/util.h"
  
 #include "testbed/fs.h"
@@ -32,6 +33,7 @@
 #include "testbed/misc.h"
 #include "testbed/savegame.h"
 #include "testbed/testbed.h"
+#include "testbed/testsuite.h"
  
 namespace Testbed {
  
@@ -45,38 +47,21 @@
  
 	// However this is the place to specify all default directories
  
-	printf("TestbedEngine::TestbedEngine()\n");
+	DebugMan.addDebugChannel(kTestbedLogOutput, "LOG", "Log of test results generated by testbed");
+	DebugMan.addDebugChannel(kTestbedEngineDebug, "Debug", "Engine-specific debug statements");
+	DebugMan.enableDebugChannel("LOG");
 }
  
 TestbedEngine::~TestbedEngine() {
-	// Dispose your resources here
-	printf("TestbedEngine::~TestbedEngine()\n");
- 
+	Testsuite::deleteWriteStream();
 	// Remove all of our debug levels here
+	DebugMan.clearAllDebugChannels();
 }
 
 Common::Error TestbedEngine::run() {
 	// Initialize graphics using following:
 	initGraphics(320, 200, false);
  
-	// You could use backend transactions directly as an alternative,
-	// but it isn't recommended, until you want to handle the error values
-	// from OSystem::endGFXTransaction yourself.
-	// This is just an example template:
-	//_system->beginGFXTransaction();
-	//	// This setup the graphics mode according to users seetings
-	//	initCommonGFX(false);
-	//
-	//	// Specify dimensions of game graphics window.
-	//	// In this example: 320x200
-	//	_system->initSize(320, 200);
-	//FIXME: You really want to handle
-	//OSystem::kTransactionSizeChangeFailed here
-	//_system->endGFXTransaction();
- 
-	// Additional setup.
-	printf("TestbedEngine::init\n");
-
 	// 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
@@ -91,8 +76,8 @@
 	Testsuite::isInteractive = false;
 
 	if (Testsuite::isInteractive) {
-		printf("Running Interactive tests as well\n");		
-		Testsuite::displayMessage(prompt, "proceed?");
+		Testsuite::logPrintf("Info! : Interactive tests are also being executed.\n");		
+		Testsuite::displayMessage(prompt, "Proceed?");
 		// Executing GFX Tests
 		GFXTestSuite gts;
 		gts.execute();

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.h	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testbed.h	2010-06-29 22:46:56 UTC (rev 50512)
@@ -28,7 +28,12 @@
 #include "engines/engine.h"
  
 namespace Testbed {
- 
+
+enum {
+	kTestbedLogOutput = 1 << 0,
+	kTestbedEngineDebug = 1 << 2
+};
+
 class TestbedEngine : public Engine {
 public:
 	TestbedEngine(OSystem *syst);

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.cpp	2010-06-29 22:46:56 UTC (rev 50512)
@@ -22,11 +22,15 @@
  * $Id$
  */
 
+#include "common/config-manager.h"
+#include "common/stream.h"
+
 #include "graphics/fontman.h"
 #include "graphics/surface.h"
 
 #include "gui/message.h"
 
+#include "testbed/testbed.h"
 #include "testbed/testsuite.h"
 
 namespace Testbed {
@@ -34,6 +38,78 @@
 // Static public variable of Testsuite
 bool Testsuite::isInteractive = true;
 
+// Static private variable of Testsuite
+Common::String Testsuite::_logDirectory = "";
+Common::String Testsuite::_logFilename = "";
+Common::WriteStream *Testsuite::_ws = 0;
+
+void Testsuite::setLogDir(const char *dirname) {
+	_logDirectory = dirname;
+}
+
+void Testsuite::setLogFile(const char *filename) {
+	_logFilename = filename;
+}
+
+void Testsuite::deleteWriteStream() {
+	if (_ws) {
+		delete _ws;
+	}
+}
+
+void Testsuite::initLogging(const char *logdir, const char *filename, bool enable) {
+	setLogDir(logdir);
+	setLogFile(filename);
+	
+	if (enable) {
+		_ws = Common::FSNode(_logDirectory).getChild(_logFilename).createWriteStream();
+	} else {
+		_ws = 0;
+	}
+}
+
+void Testsuite::initLogging(bool enable) {
+	setLogDir(ConfMan.get("path").c_str());
+	setLogFile("testbed.log");
+	
+	if (enable) {
+		_ws = Common::FSNode(_logDirectory).getChild(_logFilename).createWriteStream();
+	} else {
+		_ws = 0;
+	}
+}
+
+void Testsuite::logPrintf(const char *fmt, ...) {
+	// Assuming log message size to be not greater than STRINGBUFLEN i.e 256
+	char buffer[STRINGBUFLEN];
+	va_list vl;
+	va_start(vl, fmt);
+	vsnprintf(buffer, STRINGBUFLEN, fmt, vl);
+	va_end(vl);
+	
+	if (_ws) {
+		_ws->writeString(buffer);
+	} else {
+		debugCN(kTestbedLogOutput, "%s", buffer);
+	}
+}
+
+void Testsuite::logDetailedPrintf(const char *fmt, ...) {
+	// Assuming log message size to be not greater than STRINGBUFLEN i.e 256
+	// Messages with this function would only be displayed if -d1 is specified on command line
+	char buffer[STRINGBUFLEN];
+	va_list vl;
+	va_start(vl, fmt);
+	vsnprintf(buffer, STRINGBUFLEN, fmt, vl);
+	va_end(vl);
+	
+	if (_ws) {
+		_ws->writeString(buffer);
+	} else {
+		debugCN(1, kTestbedLogOutput, "%s", buffer);
+	}
+}
+
 Testsuite::Testsuite() {
 		_numTestsPassed = 0;
 		_numTestsExecuted = 0;
@@ -46,10 +122,13 @@
 }
 
 void Testsuite::genReport() const {
-	printf("\nSubsystem: %s\n",getName());
-	printf("Tests executed: %d\n", _numTestsExecuted);
-	printf("Tests Passed: %d\n", _numTestsPassed);
-	printf("Tests Failed: %d\n\n", getNumTestsFailed());
+	logPrintf("\n");
+	logPrintf("Consolidating results...\n");
+	logPrintf("Subsystem: %s ",getName());
+	logPrintf("(Tests Executed: %d)\n", _numTestsExecuted);
+	logPrintf("Passed: %d ", _numTestsPassed);
+	logPrintf("Failed: %d\n", getNumTestsFailed());
+	logPrintf("\n");
 }
 	
 bool Testsuite::handleInteractiveInput(const Common::String &textToDisplay, const char *opt1, const char *opt2, OptionSelected result) {
@@ -128,13 +207,13 @@
 	
 void Testsuite::execute() {
 	for (Common::Array<Test*>::iterator i = _testsToExecute.begin(); i != _testsToExecute.end(); ++i) {
-		printf("Executing Test:%s\n", ((*i)->featureName).c_str());
+		logPrintf("Info! Executing Test: %s\n", ((*i)->featureName).c_str());
 		_numTestsExecuted++;
 		if ((*i)->driver()) {
-			printf("RESULT: Passed\n");
+			logPrintf("Result: Passed\n");
 			_numTestsPassed++;
 		} else {
-			printf("RESULT: Failed\n");
+			logPrintf("Result: Failed\n");
 		}
 	}
 	genReport();

Modified: scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h
===================================================================
--- scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h	2010-06-29 22:44:39 UTC (rev 50511)
+++ scummvm/branches/gsoc2010-testbed/engines/testbed/testsuite.h	2010-06-29 22:46:56 UTC (rev 50512)
@@ -103,6 +103,18 @@
 	
 	virtual const char *getName() const = 0;
 
+	static void logPrintf(const char *s, ...) GCC_PRINTF(1, 2);
+	static void logDetailedPrintf(const char *s, ...) GCC_PRINTF(1, 2);
+	/**
+	 * Note: To enable logging, this function must be called once first.
+	 */
+	static void initLogging(const char *dirname, const char *filename, bool enable = true);
+	static void initLogging(bool enable = true);
+	static void setLogDir(const char *dirname);
+	static void setLogFile(const char *filename);
+	
+	static void deleteWriteStream();
+
 protected:
 	Common::Array<Test*> _testsToExecute;			///< List of tests to be executed
 	int		    _numTestsPassed;					///< Number of tests passed
@@ -115,6 +127,14 @@
 	 * Used by various tests to respond accordingly
 	 */
 	static bool isInteractive;
+
+private:
+	/**
+	 * Private variables related to logging files
+	 */
+	static Common::String _logDirectory;
+	static Common::String _logFilename;
+	static Common::WriteStream *_ws;
 };
 
 }	// 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