diff options
author | Neeraj Kumar | 2010-06-26 12:30:57 +0000 |
---|---|---|
committer | Neeraj Kumar | 2010-06-26 12:30:57 +0000 |
commit | ba36675351e40b801458cf5563abf5d419922e15 (patch) | |
tree | 1a169dd167634091d82a1bd2bd049fb7fbd80378 /engines | |
parent | 82bfb7b7bfce5fed14b8d0d1463a01f8cc8156fd (diff) | |
download | scummvm-rg350-ba36675351e40b801458cf5563abf5d419922e15.tar.gz scummvm-rg350-ba36675351e40b801458cf5563abf5d419922e15.tar.bz2 scummvm-rg350-ba36675351e40b801458cf5563abf5d419922e15.zip |
completed the savefile tests
svn-id: r50319
Diffstat (limited to 'engines')
-rw-r--r-- | engines/testbed/savegame.cpp | 146 | ||||
-rw-r--r-- | engines/testbed/savegame.h | 7 | ||||
-rw-r--r-- | engines/testbed/testbed.cpp | 2 | ||||
-rw-r--r-- | engines/testbed/testsuite.h | 3 |
4 files changed, 150 insertions, 8 deletions
diff --git a/engines/testbed/savegame.cpp b/engines/testbed/savegame.cpp index 89f2a52f7b..c6efa0168c 100644 --- a/engines/testbed/savegame.cpp +++ b/engines/testbed/savegame.cpp @@ -9,21 +9,27 @@ namespace Testbed { * It is intended to test saving and loading from savefiles. */ -bool SaveGametests::testSaveLoadState() { +bool SaveGametests::writeDataToFile(const char *fileName, const char *msg) { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); - Common::OutSaveFile *saveFile = saveFileMan->openForSaving("saveFile.0"); + Common::OutSaveFile *saveFile = saveFileMan->openForSaving(fileName); if (!saveFile) { - printf("LOG: Can't open saveFile\n"); + printf("LOG: Can't open saveFile %s\n", fileName); return false; } - saveFile->writeString("ScummVM Rocks!"); + saveFile->writeString(msg); saveFile->finalize(); delete saveFile; - Common::InSaveFile *loadFile = saveFileMan->openForLoading("saveFile.0"); + return true; +} +bool SaveGametests::readAndVerifyData(const char *fileName, const char *expected) { + + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::InSaveFile *loadFile = saveFileMan->openForLoading(fileName); if (!loadFile) { printf("LOG: Can't open save File to load\n"); @@ -33,15 +39,143 @@ bool SaveGametests::testSaveLoadState() { Common::String lineToRead = loadFile->readLine(); delete loadFile; - if (lineToRead.equals("ScummVM Rocks!")) { + if (lineToRead.equals(expected)) { return true; } return false; } + +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"); + return false; + } + + // Verify if it contains the same data + if (!readAndVerifyData("tBedSavefile.0", "ScummVM Rocks!")) { + printf("LOG: Reading data from savefile failed\n"); + return false; + } + + return true; +} + +bool SaveGametests::testRemovingSavefile() { + + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + + // Create a dummy savefile + if (!writeDataToFile("tBedSavefileToRemove.0", "Dummy Savefile!")) { + printf("LOG: Writing data to savefile failed\n"); + return false; + } + + // Remove it + saveFileMan->removeSavefile("tBedSavefileToRemove.0"); + + // Try opening it Now + Common::InSaveFile *loadFile = saveFileMan->openForLoading("saveFile.0"); + if (loadFile) { + // Removing failed + printf("LOG: Removing savefile failed\n"); + return false; + } + + return true; +} + +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"); + return false; + } + + // Rename it + saveFileMan->renameSavefile("tBedSomeWeirdName.0", "tBedSomeCoolName.0"); + + // Verify if it contains the same data + if (!readAndVerifyData("tBedSomeCoolName.0", "Rename me!")) { + printf("LOG: Renaming savefile failed\n"); + return false; + } + + return true; +} + +bool SaveGametests::testListingSavefile() { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + saveFileMan->clearError(); + + // create some savefiles + const char *savefileName[] = {"tBedSavefileToList.0", "tBedSavefileToList.1", "tBedSavefileToList.2"}; + writeDataToFile("tBedSavefileToList.0", "Save me!"); + writeDataToFile("tBedSavefileToList.1", "Save me!"); + writeDataToFile("tBedSavefileToList.2", "Save me!"); + + Common::Error error = saveFileMan->getError(); + + if ( error != Common::kNoError) { + // Abort. Some Error in writing files + printf("LOG: Error while creating savefiles: %s\n", Common::errorToString(error)); + return false; + } + + Common::StringArray savefileList = saveFileMan->listSavefiles("tBedSavefileToList.?"); + if (savefileList.size() == ARRAYSIZE(savefileName)) { + // Match them exactly + // As the order of savefileList may be platform specific, match them exhaustively + for (uint i = 0; i < ARRAYSIZE(savefileName); i++) { + for (uint j = 0; j < savefileList.size(); j++) { + if (savefileList[j].equals(savefileName[i])) { + break; + } + if (savefileList.size() == j) { + // A match for this name not found + printf("LOG: Listed Names don't match\n"); + return false; + } + } + } + return true; + } else { + printf("LOG: listing Savefiles failed!\n"); + return false; + } + + return false; +} + + +bool SaveGametests::testErrorMessages() { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + saveFileMan->clearError(); + + // Try opening a non existing file + readAndVerifyData("tBedSomeNonExistentSaveFile.0", "I don't exist!"); + + Common::Error error = saveFileMan->getError(); + if (error == Common::kNoError) { + // blunder! how come? + printf("LOG: 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()); + return true; +} + SaveGameTestSuite::SaveGameTestSuite() { addTest("Opening SaveFile", &SaveGametests::testSaveLoadState); + addTest("Removing SaveFile", &SaveGametests::testRemovingSavefile); + addTest("Renaming SaveFile", &SaveGametests::testRenamingSavefile); + addTest("Listing SaveFile", &SaveGametests::testListingSavefile); + addTest("Verify Error Messages", &SaveGametests::testErrorMessages); } const char *SaveGameTestSuite::getName() const { diff --git a/engines/testbed/savegame.h b/engines/testbed/savegame.h index 337bd46786..e56309ae67 100644 --- a/engines/testbed/savegame.h +++ b/engines/testbed/savegame.h @@ -8,9 +8,14 @@ namespace Testbed { namespace SaveGametests { // Helper functions for SaveGame tests - +bool writeDataToFile(const char *fileName, const char *msg); +bool readAndVerifyData(const char *fileName, const char *expected); // will contain function declarations for SaveGame tests bool testSaveLoadState(); +bool testRemovingSavefile(); +bool testRenamingSavefile(); +bool testListingSavefile(); +bool testErrorMessages(); // add more here } diff --git a/engines/testbed/testbed.cpp b/engines/testbed/testbed.cpp index 8446bda574..707873a307 100644 --- a/engines/testbed/testbed.cpp +++ b/engines/testbed/testbed.cpp @@ -63,7 +63,7 @@ Common::Error TestbedEngine::run() { // To be set from config file // XXX: disabling these as of now for fastly testing other tests - interactive = true; + interactive = false; if (interactive) { printf("Running Interactive tests as well\n"); diff --git a/engines/testbed/testsuite.h b/engines/testbed/testsuite.h index b9de1ed5be..81021502e5 100644 --- a/engines/testbed/testsuite.h +++ b/engines/testbed/testsuite.h @@ -162,7 +162,10 @@ public: printf("Executing Test:%s\n", ((*i)->featureName).c_str()); _numTestsExecuted++; if ((*i)->driver()) { + printf("RESULT: Passed\n"); _numTestsPassed++; + } else { + printf("RESULT: Failed\n"); } } genReport(); |