aboutsummaryrefslogtreecommitdiff
path: root/engines/testbed
diff options
context:
space:
mode:
authorNeeraj Kumar2010-06-29 22:46:56 +0000
committerNeeraj Kumar2010-06-29 22:46:56 +0000
commit68d691bc3e5ee711daad2979c7db325c16e4c1f0 (patch)
tree31c807b49cbb113ce9f572f9c6ba7b01c2a3840d /engines/testbed
parente022dd7013aaf007ba7594ecf1e15d4c27502704 (diff)
downloadscummvm-rg350-68d691bc3e5ee711daad2979c7db325c16e4c1f0.tar.gz
scummvm-rg350-68d691bc3e5ee711daad2979c7db325c16e4c1f0.tar.bz2
scummvm-rg350-68d691bc3e5ee711daad2979c7db325c16e4c1f0.zip
removed all printfs, added logging feature in form of logPrintf
svn-id: r50512
Diffstat (limited to 'engines/testbed')
-rw-r--r--engines/testbed/fs.cpp20
-rw-r--r--engines/testbed/graphics.cpp38
-rw-r--r--engines/testbed/misc.cpp14
-rw-r--r--engines/testbed/savegame.cpp28
-rw-r--r--engines/testbed/testbed.cpp35
-rw-r--r--engines/testbed/testbed.h7
-rw-r--r--engines/testbed/testsuite.cpp93
-rw-r--r--engines/testbed/testsuite.h20
8 files changed, 172 insertions, 83 deletions
diff --git a/engines/testbed/fs.cpp b/engines/testbed/fs.cpp
index 78fd1537dc..c59455ee83 100644
--- a/engines/testbed/fs.cpp
+++ b/engines/testbed/fs.cpp
@@ -43,19 +43,19 @@ bool FStests::readDataFromFile(Common::FSDirectory *directory, const char *file)
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 @@ bool FStests::testReadFile() {
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 @@ bool FStests::testReadFile() {
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 @@ bool FStests::testReadFile() {
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 @@ bool FStests::testReadFile() {
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 @@ bool FStests::testWriteFile() {
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 @@ bool FStests::testWriteFile() {
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;
}
diff --git a/engines/testbed/graphics.cpp b/engines/testbed/graphics.cpp
index e80fb0d4b2..51f4030dd0 100644
--- a/engines/testbed/graphics.cpp
+++ b/engines/testbed/graphics.cpp
@@ -311,9 +311,9 @@ bool GFXtests::fullScreenMode() {
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 @@ bool GFXtests::fullScreenMode() {
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 @@ bool GFXtests::fullScreenMode() {
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 @@ bool GFXtests::fullScreenMode() {
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 @@ bool GFXtests::aspectRatio() {
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 @@ bool GFXtests::aspectRatio() {
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 @@ bool GFXtests::aspectRatio() {
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 @@ bool GFXtests::palettizedCursors() {
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 @@ bool GFXtests::palettizedCursors() {
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 @@ bool GFXtests::scaledCursors() {
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 @@ bool GFXtests::scaledCursors() {
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 @@ bool GFXtests::shakingEffect() {
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 @@ bool GFXtests::focusRectangle() {
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 @@ bool GFXtests::overlayGraphics() {
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 @@ bool GFXtests::pixelFormats() {
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 @@ bool GFXtests::pixelFormats() {
// 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 @@ bool GFXtests::pixelFormats() {
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;
}
diff --git a/engines/testbed/misc.cpp b/engines/testbed/misc.cpp
index 77614532a5..4359127053 100644
--- a/engines/testbed/misc.cpp
+++ b/engines/testbed/misc.cpp
@@ -45,7 +45,7 @@ void MiscTests::timerCallback(void *arg) {
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 @@ void MiscTests::criticalSection(void *arg) {
}
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 @@ void MiscTests::criticalSection(void *arg) {
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 @@ bool MiscTests::testDateTime() {
// 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 @@ bool MiscTests::testMutexes() {
// 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) {
diff --git a/engines/testbed/savegame.cpp b/engines/testbed/savegame.cpp
index 7dd065a6ac..1e645c2439 100644
--- a/engines/testbed/savegame.cpp
+++ b/engines/testbed/savegame.cpp
@@ -39,7 +39,7 @@ bool SaveGametests::writeDataToFile(const char *fileName, const char *msg) {
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 @@ bool SaveGametests::readAndVerifyData(const char *fileName, const char *expected
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::readAndVerifyData(const char *fileName, const char *expected
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 @@ bool SaveGametests::testRemovingSavefile() {
// 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 @@ bool SaveGametests::testRemovingSavefile() {
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 @@ bool SaveGametests::testRenamingSavefile() {
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 @@ bool SaveGametests::testRenamingSavefile() {
// 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 @@ bool SaveGametests::testListingSavefile() {
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 @@ bool SaveGametests::testListingSavefile() {
}
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 @@ bool SaveGametests::testErrorMessages() {
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;
}
diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp
index 5731483c66..3bb2490cf3 100644
--- a/engines/testbed/testbed.cpp
+++ b/engines/testbed/testbed.cpp
@@ -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 @@ TestbedEngine::TestbedEngine(OSystem *syst)
// 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 @@ Common::Error TestbedEngine::run() {
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();
diff --git a/engines/testbed/testbed.h b/engines/testbed/testbed.h
index 23871d2efa..554c0290a0 100644
--- a/engines/testbed/testbed.h
+++ b/engines/testbed/testbed.h
@@ -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);
diff --git a/engines/testbed/testsuite.cpp b/engines/testbed/testsuite.cpp
index f9fb651881..488f3e0a8c 100644
--- a/engines/testbed/testsuite.cpp
+++ b/engines/testbed/testsuite.cpp
@@ -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 @@ namespace Testbed {
// 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 @@ Testsuite::~Testsuite() {
}
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::addTest(const Common::String &name, InvokingFunction f) {
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();
diff --git a/engines/testbed/testsuite.h b/engines/testbed/testsuite.h
index 071ddf322a..b67023ae07 100644
--- a/engines/testbed/testsuite.h
+++ b/engines/testbed/testsuite.h
@@ -103,6 +103,18 @@ public:
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 @@ public:
* 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