Ticket #9160: gsoc_scummvm.patch

File gsoc_scummvm.patch, 6.5 KB (added by SF/sud03r, 14 years ago)

A patch file containg the above changes.

  • test/common/tokenizer.h

     
     1#include <cxxtest/TestSuite.h>
     2
     3#include "common/tokenizer.h"
     4
     5class TokenizerTestSuite : public CxxTest::TestSuite {
     6public:
     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

     
    6363        kReadingFailed,                         ///< Failed creating a (savestate) file
    6464        kWritingFailed,                         ///< Failure to write data -- disk full?
    6565
    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
    6769};
    6870
     71/**
     72 * Maps an error code to equivalent string description
     73 * @param error : error code to be converted
     74 */
     75const 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 */
     82void displayErrorDialog(const char* extraText, Error error = kDefaultArgument);
     83
    6984} // End of namespace Common
    7085
    7186#endif //COMMON_ERROR_H
  • common/error.cpp

     
     1#include "common/error.h"
     2#include "gui/message.h"
     3
     4namespace Common {
     5
     6/**
     7 * Error Table: Maps error codes to their default descriptions
     8 */
     9
     10struct ErrorMessage {
     11        Error error;
     12        const char* errMsg;
     13};
     14
     15static 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
     36const 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
     48void 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

     
    2424        unzip.o \
    2525        util.o \
    2626        xmlparser.o \
    27         zlib.o
     27        zlib.o \
     28        error.o
    2829
    2930# Include common rules
    3031include $(srcdir)/rules.mk
  • base/main.cpp

     
    136136        if (!engine || err != Common::kNoError) {
    137137                // TODO: Show an error dialog or so?
    138138                // 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               
    139143                //GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!");
    140144                //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);
    152146
    153147                warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
    154148                        plugin->getName(),
     
    392386                        // Did an error occur ?
    393387                        if (result != Common::kNoError) {
    394388                                // 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);
    395391                        }
    396392
    397393                        // Quit unless an error occurred, or Return to launcher was requested
     
    417413                } else {
    418414                        // A dialog would be nicer, but we don't have any
    419415                        // screen to draw on yet.
     416                        Common::displayErrorDialog("Could not find any engine capable of running the selected game");
    420417                        warning("Could not find any engine capable of running the selected game");
    421418                }
    422419