Ticket #9160: modified_scummvm.patch
File modified_scummvm.patch, 6.4 KB (added by , 15 years ago) |
---|
-
test/common/tokenizer.h
1 #include <cxxtest/TestSuite.h> 2 #include "common/util.h" 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 15 for (int i = 0; i < ARRAYSIZE(tokenArray); 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 s1(""); 24 TS_ASSERT_EQUALS("", s1.nextToken()); 25 26 // Empty Delimiter 27 Common::StringTokenizer s2("test String", ""); 28 TS_ASSERT_EQUALS("test String", s2.nextToken()); 29 30 // String is the delimiter 31 Common::StringTokenizer s3("abc", "abc"); 32 TS_ASSERT_EQUALS("", s3.nextToken()); 33 // Tokenizer should be empty 34 TS_ASSERT(s3.empty()); 35 36 // consecutive delimiters in the string 37 Common::StringTokenizer s4("strstr,after all!!", "str, !"); 38 TS_ASSERT_EQUALS("af", s4.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
66 66 kUnknownError ///< Catch-all error, used if no other error code matches 67 67 }; 68 68 69 /** 70 * Maps an error code to equivalent string description. 71 * 72 * @param error error code to be converted 73 * @return a pointer to string description of the error 74 */ 75 const char *errorToString(Error error); 76 77 /** 78 * Displays an error dialog for some error code. 79 * 80 * @param error error code 81 * @param extraText extra text to be displayed in addition to default string description(optional) 82 */ 83 void displayErrorDialog(Error error, const char *extraText = ""); 84 85 /** 86 * Displays an error dialog for a given message. 87 * 88 * @param text message to be displayed 89 */ 90 void displayErrorDialog(const char *text); 91 69 92 } // End of namespace Common 70 93 71 94 #endif //COMMON_ERROR_H -
common/error.cpp
1 #include "common/error.h" 2 #include "common/util.h" 3 #include "gui/message.h" 4 5 namespace Common { 6 7 /** 8 * Error Table: Maps error codes to their default descriptions 9 */ 10 11 struct ErrorMessage { 12 Error error; 13 const char *errMsg; 14 }; 15 16 static const ErrorMessage _errMsgTable[] = { 17 { kInvalidPathError, "Invalid Path" }, 18 { kNoGameDataFoundError, "Game Data not found" }, 19 { kUnsupportedGameidError, "Game Id not supported" }, 20 { kUnsupportedColorMode, "Unsupported Color Mode" }, 21 22 { kReadPermissionDenied, "Read permission denied" }, 23 { kWritePermissionDenied, "Write permission denied" }, 24 25 // The following three overlap a bit with kInvalidPathError and each other. Which to keep? 26 { kPathDoesNotExist, "Path not exists" }, 27 { kPathNotDirectory, "Path not a directory" }, 28 { kPathNotFile, "Path not a file" }, 29 30 { kCreatingFileFailed, "Can not create file" }, 31 { kReadingFailed, "Reading failed" }, 32 { kWritingFailed, "Writing data failed" }, 33 34 { kUnknownError, "Unknown Error" } 35 }; 36 37 const char *errorToString(Error error) { 38 39 for (int i = 0; i < ARRAYSIZE(_errMsgTable); 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 *text) { 49 GUI::MessageDialog alert(text); 50 alert.runModal(); 51 } 52 53 void displayErrorDialog(Error error, const char *extraText) { 54 String errorText(extraText); 55 errorText += " "; 56 errorText += errorToString(error); 57 GUI::MessageDialog alert(errorText); 58 alert.runModal(); 59 } 60 61 } -
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 = Common::errorToString(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 Common::displayErrorDialog(result, "Error running game:"); 395 391 } 396 392 397 393 // Quit unless an error occurred, or Return to launcher was requested … … 418 414 // A dialog would be nicer, but we don't have any 419 415 // screen to draw on yet. 420 416 warning("Could not find any engine capable of running the selected game"); 417 Common::displayErrorDialog("Could not find any engine capable of running the selected game"); 421 418 } 422 419 423 420 // We will destroy the AudioCDManager singleton here to save some memory.