Ticket #9160: gsoc_scummvm.patch
File gsoc_scummvm.patch, 6.5 KB (added by , 15 years ago) |
---|
-
test/common/tokenizer.h
1 #include <cxxtest/TestSuite.h> 2 3 #include "common/tokenizer.h" 4 5 class TokenizerTestSuite : public CxxTest::TestSuite { 6 public: 7 void test_nextToken() { 8 9 // test Common::StringTokenizer class 10 11 // test normal behavior 12 Common::StringTokenizer strTokenizer("Now, this is a test!", " ,!"); 13 Common::String tokenArray[] = {"Now", "this", "is", "a", "test"}; 14 int szTokenArray = sizeof(tokenArray) / sizeof(Common::String); 15 for (int i = 0; i < szTokenArray; i++ ) { 16 // make sure nextToken works correctly 17 TS_ASSERT_EQUALS(tokenArray[i], strTokenizer.nextToken()); 18 } 19 20 // test edgy conditions: 21 22 // Empty String 23 Common::StringTokenizer strTokenizer_1(""); 24 TS_ASSERT_EQUALS("", strTokenizer_1.nextToken()); 25 26 // Empty Delimiter 27 Common::StringTokenizer strTokenizer_2("test String", ""); 28 TS_ASSERT_EQUALS("test String", strTokenizer_2.nextToken()); 29 30 // String is the delimiter 31 Common::StringTokenizer strTokenizer_3("abc", "abc"); 32 TS_ASSERT_EQUALS("", strTokenizer_3.nextToken()); 33 // Tokenizer should be empty 34 TS_ASSERT(strTokenizer_3.empty()); 35 36 // consecutive delimiters in the string 37 Common::StringTokenizer strTokenizer_4("strstr,after all!!", "str, !"); 38 TS_ASSERT_EQUALS("af", strTokenizer_4.nextToken()); 39 } 40 41 void test_resetAndEmpty() { 42 Common::StringTokenizer strTokenizer("Just, another test!", " ,!"); 43 44 // test reset() 45 Common::String token1 = strTokenizer.nextToken(); //Just 46 strTokenizer.reset(); 47 Common::String token2 = strTokenizer.nextToken(); //Just 48 49 TS_ASSERT_EQUALS(token1,token2); 50 51 // test empty() 52 TS_ASSERT(!strTokenizer.empty()); 53 strTokenizer.nextToken(); //another 54 strTokenizer.nextToken(); //test 55 TS_ASSERT(strTokenizer.empty()); 56 } 57 58 }; 59 -
common/error.h
63 63 kReadingFailed, ///< Failed creating a (savestate) file 64 64 kWritingFailed, ///< Failure to write data -- disk full? 65 65 66 kUnknownError ///< Catch-all error, used if no other error code matches 66 kUnknownError, ///< Catch-all error, used if no other error code matches 67 68 kDefaultArgument ///< Used as a default argument in displayErrorDialog Function 67 69 }; 68 70 71 /** 72 * Maps an error code to equivalent string description 73 * @param error : error code to be converted 74 */ 75 const char* errToString(Error error); 76 77 /** 78 * Displays an error dialog for some error code 79 * @param extraText : extra text to be displayed in addition to default string description 80 * @param error : error code 81 */ 82 void displayErrorDialog(const char* extraText, Error error = kDefaultArgument); 83 69 84 } // End of namespace Common 70 85 71 86 #endif //COMMON_ERROR_H -
common/error.cpp
1 #include "common/error.h" 2 #include "gui/message.h" 3 4 namespace Common { 5 6 /** 7 * Error Table: Maps error codes to their default descriptions 8 */ 9 10 struct ErrorMessage { 11 Error error; 12 const char* errMsg; 13 }; 14 15 static const ErrorMessage _errMsgTable[] = { 16 { kInvalidPathError, "Invalid Path" }, 17 { kNoGameDataFoundError, "Game Data not found" }, 18 { kUnsupportedGameidError, "Game Id not supported" }, 19 { kUnsupportedColorMode, "Unsupported Color Mode" }, 20 21 { kReadPermissionDenied, "Read permission denied" }, 22 { kWritePermissionDenied, "Write permission denied" }, 23 24 // The following three overlap a bit with kInvalidPathError and each other. Which to keep? 25 { kPathDoesNotExist, "Path not exists" }, 26 { kPathNotDirectory, "Path not a directory" }, 27 { kPathNotFile, "Path not a file" }, 28 29 { kCreatingFileFailed, "Can't create file" }, 30 { kReadingFailed, "Reading failed" }, 31 { kWritingFailed, "Writing data failed" }, 32 33 { kUnknownError, "Unknown Error" } 34 }; 35 36 const char* errToString(Error error) { 37 int tableSize = sizeof(_errMsgTable) / sizeof(ErrorMessage); 38 39 for (int i = 0; i < tableSize; i++) { 40 if (error == _errMsgTable[i].error) { 41 return _errMsgTable[i].errMsg; 42 } 43 } 44 45 return "Unknown Error"; 46 } 47 48 void displayErrorDialog(const char* extraText, Error error) { 49 String errorText(extraText); 50 if (error != kDefaultArgument) { 51 errorText += errToString(error); 52 } 53 GUI::MessageDialog alert(errorText); 54 alert.runModal(); 55 } 56 57 } -
common/module.mk
24 24 unzip.o \ 25 25 util.o \ 26 26 xmlparser.o \ 27 zlib.o 27 zlib.o \ 28 error.o 28 29 29 30 # Include common rules 30 31 include $(srcdir)/rules.mk -
base/main.cpp
136 136 if (!engine || err != Common::kNoError) { 137 137 // TODO: Show an error dialog or so? 138 138 // TODO: Also take 'err' into consideration... 139 140 // An errorDialog for this and engine related errors is displayed already in the scummvm_main function 141 // Is a separate dialog here still required? 142 139 143 //GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!"); 140 144 //alert.runModal(); 141 const char *errMsg = 0; 142 switch (err) { 143 case Common::kInvalidPathError: 144 errMsg = "Invalid game path"; 145 break; 146 case Common::kNoGameDataFoundError: 147 errMsg = "Unable to locate game data"; 148 break; 149 default: 150 errMsg = "Unknown error"; 151 } 145 const char *errMsg = errToString(err); 152 146 153 147 warning("%s failed to instantiate engine: %s (target '%s', path '%s')", 154 148 plugin->getName(), … … 392 386 // Did an error occur ? 393 387 if (result != Common::kNoError) { 394 388 // TODO: Show an informative error dialog if starting the selected game failed. 389 // Done (Covers more error values than that in runGame()). 390 displayErrorDialog("Error running game: ", result); 395 391 } 396 392 397 393 // Quit unless an error occurred, or Return to launcher was requested … … 417 413 } else { 418 414 // A dialog would be nicer, but we don't have any 419 415 // screen to draw on yet. 416 Common::displayErrorDialog("Could not find any engine capable of running the selected game"); 420 417 warning("Could not find any engine capable of running the selected game"); 421 418 } 422 419