test/testautomation_keyboard.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Sun, 13 Jan 2013 22:55:26 -0800
changeset 6813 b21879e67db2
parent 6811 60d95fcfaf3c
child 6983 b72f56ab9867
permissions -rw-r--r--
Add input validation to SDL_GetKeyFromScancode; fix compiler warning in testautomation driver on Linux; update keyboard test suite
     1 /**
     2  * Keyboard test suite
     3  */
     4 
     5 #include <stdio.h>
     6 
     7 #include "SDL_config.h"
     8 #include "SDL.h"
     9 #include "SDL_test.h"
    10 
    11 /* ================= Test Case Implementation ================== */
    12 
    13 /* Test case functions */
    14 
    15 /**
    16  * @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
    17  * 
    18  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
    19  */
    20 int
    21 keyboard_getKeyboardState(void *arg)
    22 {
    23    int numkeys;
    24    Uint8 *state;
    25 
    26    /* Case where numkeys pointer is NULL */    
    27    state = SDL_GetKeyboardState(NULL);
    28    SDLTest_AssertPass("Call to SDL_GetKeyboardState(NULL)");
    29    SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
    30 
    31    /* Case where numkeys pointer is not NULL */
    32    numkeys = -1;
    33    state = SDL_GetKeyboardState(&numkeys);
    34    SDLTest_AssertPass("Call to SDL_GetKeyboardState(&numkeys)");
    35    SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
    36    SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
    37    
    38    return TEST_COMPLETED;
    39 }
    40 
    41 /**
    42  * @brief Check call to SDL_GetKeyboardFocus
    43  * 
    44  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus
    45  */
    46 int
    47 keyboard_getKeyboardFocus(void *arg)
    48 {
    49    SDL_Window* window;
    50 
    51    /* Call, but ignore return value */
    52    window = SDL_GetKeyboardFocus();
    53    SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
    54 
    55    return TEST_COMPLETED;
    56 }
    57 
    58 /**
    59  * @brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
    60  * 
    61  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName
    62  */
    63 int
    64 keyboard_getKeyFromName(void *arg)
    65 {
    66    SDL_Keycode result;
    67 
    68    /* Case where Key is known, 1 character input */
    69    result = SDL_GetKeyFromName("A");
    70    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/single)");
    71    SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
    72 
    73    /* Case where Key is known, 2 character input */
    74    result = SDL_GetKeyFromName("F1");
    75    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
    76    SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %i", SDLK_F1, result);
    77 
    78    /* Case where Key is known, 3 character input */
    79    result = SDL_GetKeyFromName("End");
    80    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
    81    SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %i", SDLK_END, result);
    82 
    83    /* Case where Key is known, 4 character input */
    84    result = SDL_GetKeyFromName("Find");
    85    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
    86    SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %i", SDLK_FIND, result);
    87 
    88    /* Case where Key is known, multiple character input */
    89    result = SDL_GetKeyFromName("AudioStop");
    90    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
    91    SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %i", SDLK_AUDIOSTOP, result);
    92 
    93    /* Case where Key is unknown */
    94    result = SDL_GetKeyFromName("NotThere");
    95    SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
    96    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
    97 
    98    /* Case where input is NULL/invalid */
    99    result = SDL_GetKeyFromName(NULL);
   100    SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
   101    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   102 
   103    return TEST_COMPLETED;
   104 }
   105 
   106 /**
   107  * @brief Check call to SDL_GetKeyFromScancode
   108  * 
   109  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
   110  */
   111 int
   112 keyboard_getKeyFromScancode(void *arg)
   113 {
   114    const char *expectedError = "Parameter 'scancode' is invalid";
   115    const char *error;   
   116    SDL_Keycode result;
   117 
   118    /* Case where input is valid */
   119    result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
   120    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
   121    SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
   122 
   123    /* Case where input is zero */
   124    result = SDL_GetKeyFromScancode(0);
   125    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
   126    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   127 
   128    SDL_ClearError();
   129    SDLTest_AssertPass("Call to SDL_ClearError()");
   130 
   131    /* Case where input is invalid (too small) */
   132    result = SDL_GetKeyFromScancode(-999);
   133    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
   134    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   135    error = SDL_GetError();
   136    SDLTest_AssertPass("Call to SDL_GetError()");
   137    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   138    if (error != NULL) {
   139       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   140           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   141    }
   142 
   143    SDL_ClearError();
   144    SDLTest_AssertPass("Call to SDL_ClearError()");
   145 
   146    /* Case where input is invalid (too big) */
   147    result = SDL_GetKeyFromScancode(999);
   148    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
   149    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   150    error = SDL_GetError();
   151    SDLTest_AssertPass("Call to SDL_GetError()");
   152    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   153    if (error != NULL) {
   154       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   155           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   156    }
   157 
   158    SDL_ClearError();
   159    SDLTest_AssertPass("Call to SDL_ClearError()");
   160 
   161    return TEST_COMPLETED;
   162 }
   163 
   164 /**
   165  * @brief Check call to SDL_GetKeyName
   166  * 
   167  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
   168  */
   169 int
   170 keyboard_getKeyName(void *arg)
   171 {   
   172    char *result;
   173    char *expected;
   174 
   175    /* Case where key has a 1 character name */
   176    expected = "3";
   177    result = (char *)SDL_GetKeyName(SDLK_3);
   178    SDLTest_AssertPass("Call to SDL_GetKeyName()");
   179    SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   180    SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
   181 
   182    /* Case where key has a 2 character name */
   183    expected = "F1";
   184    result = (char *)SDL_GetKeyName(SDLK_F1);
   185    SDLTest_AssertPass("Call to SDL_GetKeyName()");
   186    SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   187    SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
   188 
   189    /* Case where key has a 3 character name */
   190    expected = "Cut";
   191    result = (char *)SDL_GetKeyName(SDLK_CUT);
   192    SDLTest_AssertPass("Call to SDL_GetKeyName()");
   193    SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   194    SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
   195 
   196    /* Case where key has a 4 character name */
   197    expected = "Down";
   198    result = (char *)SDL_GetKeyName(SDLK_DOWN);
   199    SDLTest_AssertPass("Call to SDL_GetKeyName()");
   200    SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   201    SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
   202 
   203    /* Case where key has a N character name */
   204    expected = "BrightnessUp";
   205    result = (char *)SDL_GetKeyName(SDLK_BRIGHTNESSUP);
   206    SDLTest_AssertPass("Call to SDL_GetKeyName()");
   207    SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   208    SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
   209 
   210    /* Case where key has a N character name with space */
   211    expected = "Keypad MemStore";
   212    result = (char *)SDL_GetKeyName(SDLK_KP_MEMSTORE);
   213    SDLTest_AssertPass("Call to SDL_GetKeyName()");
   214    SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
   215    SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
   216 
   217    return TEST_COMPLETED;
   218 }
   219 
   220 /**
   221  * @brief Check call to SDL_GetModState and SDL_SetModState
   222  * 
   223  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
   224  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
   225  */
   226 int
   227 keyboard_getSetModState(void *arg)
   228 {   
   229    SDL_Keymod result;
   230    SDL_Keymod currentState;
   231    SDL_Keymod newState;
   232    SDL_Keymod allStates =     
   233     KMOD_NONE |
   234     KMOD_LSHIFT |
   235     KMOD_RSHIFT |
   236     KMOD_LCTRL |
   237     KMOD_RCTRL |
   238     KMOD_LALT |
   239     KMOD_RALT |
   240     KMOD_LGUI |
   241     KMOD_RGUI |
   242     KMOD_NUM |
   243     KMOD_CAPS |
   244     KMOD_MODE |
   245     KMOD_RESERVED;
   246 
   247    /* Get state, cache for later reset */                                                   
   248    result = SDL_GetModState();
   249    SDLTest_AssertPass("Call to SDL_GetModState()");
   250    SDLTest_AssertCheck(result >=0 && result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);   
   251    currentState = result;
   252 
   253    /* Set random state */   
   254    newState = SDLTest_RandomIntegerInRange(0, allStates);
   255    SDL_SetModState(newState);
   256    SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState);
   257    result = SDL_GetModState();
   258    SDLTest_AssertPass("Call to SDL_GetModState()");
   259    SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result);
   260 
   261    /* Set zero state */
   262    SDL_SetModState(0);
   263    SDLTest_AssertPass("Call to SDL_SetModState(0)");
   264    result = SDL_GetModState();
   265    SDLTest_AssertPass("Call to SDL_GetModState()");
   266    SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result);
   267 
   268    /* Revert back to cached current state if needed */
   269    if (currentState != 0) {
   270      SDL_SetModState(currentState);
   271      SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState);
   272      result = SDL_GetModState();
   273      SDLTest_AssertPass("Call to SDL_GetModState()");
   274      SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result);
   275    }
   276 
   277    return TEST_COMPLETED;
   278 }
   279 
   280 
   281 /**
   282  * @brief Check call to SDL_StartTextInput and SDL_StopTextInput
   283  * 
   284  * @sa http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
   285  * @sa http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput
   286  */
   287 int
   288 keyboard_startStopTextInput(void *arg)
   289 {   
   290    /* Start-Stop */
   291    SDL_StartTextInput();
   292    SDLTest_AssertPass("Call to SDL_StartTextInput()");
   293    SDL_StopTextInput();
   294    SDLTest_AssertPass("Call to SDL_StopTextInput()");
   295 
   296    /* Stop-Start */
   297    SDL_StartTextInput();
   298    SDLTest_AssertPass("Call to SDL_StartTextInput()");
   299    
   300    /* Start-Start */
   301    SDL_StartTextInput();
   302    SDLTest_AssertPass("Call to SDL_StartTextInput()");
   303 
   304    /* Stop-Stop */   
   305    SDL_StopTextInput();
   306    SDLTest_AssertPass("Call to SDL_StopTextInput()");
   307    SDL_StopTextInput();
   308    SDLTest_AssertPass("Call to SDL_StopTextInput()");
   309 
   310    return TEST_COMPLETED;
   311 }
   312 
   313 /* Internal function to test SDL_SetTextInputRect */
   314 void _testSetTextInputRect(SDL_Rect refRect)
   315 {
   316    SDL_Rect testRect;
   317    
   318    testRect = refRect;
   319    SDL_SetTextInputRect(&testRect);
   320    SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i)", refRect.x, refRect.y, refRect.w, refRect.h);
   321    SDLTest_AssertCheck(
   322       (refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h), 
   323       "Check that input data was not modified, expected: x:%i,y:%i,w:%i,h:%i, got: x:%i,y:%i,w:%i,h:%i", 
   324       refRect.x, refRect.y, refRect.w, refRect.h, 
   325       testRect.x, testRect.y, testRect.w, testRect.h);
   326 }
   327 
   328 /**
   329  * @brief Check call to SDL_SetTextInputRect
   330  * 
   331  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
   332  */
   333 int
   334 keyboard_setTextInputRect(void *arg)
   335 {   
   336    SDL_Rect refRect;
   337    
   338    /* Normal visible refRect, origin inside */
   339    refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
   340    refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
   341    refRect.w = SDLTest_RandomIntegerInRange(10, 50);
   342    refRect.h = SDLTest_RandomIntegerInRange(10, 50);
   343    _testSetTextInputRect(refRect);
   344    
   345    /* Normal visible refRect, origin 0,0 */
   346    refRect.x = 0;
   347    refRect.y = 0;
   348    refRect.w = SDLTest_RandomIntegerInRange(10, 50);
   349    refRect.h = SDLTest_RandomIntegerInRange(10, 50);
   350    _testSetTextInputRect(refRect);
   351 
   352    /* 1Pixel refRect */
   353    refRect.x = SDLTest_RandomIntegerInRange(10, 50);;
   354    refRect.y = SDLTest_RandomIntegerInRange(10, 50);;
   355    refRect.w = 1;
   356    refRect.h = 1;
   357    _testSetTextInputRect(refRect);
   358 
   359    /* 0pixel refRect */
   360    refRect.x = 1;
   361    refRect.y = 1;
   362    refRect.w = 1;
   363    refRect.h = 0;
   364    _testSetTextInputRect(refRect);
   365 
   366    /* 0pixel refRect */
   367    refRect.x = 1;
   368    refRect.y = 1;
   369    refRect.w = 0;
   370    refRect.h = 1;
   371    _testSetTextInputRect(refRect);
   372 
   373    /* 0pixel refRect */
   374    refRect.x = 1;
   375    refRect.y = 1;
   376    refRect.w = 0;
   377    refRect.h = 0;
   378    _testSetTextInputRect(refRect);
   379 
   380    /* 0pixel refRect */
   381    refRect.x = 0;
   382    refRect.y = 0;
   383    refRect.w = 0;
   384    refRect.h = 0;
   385    _testSetTextInputRect(refRect);
   386 
   387    /* negative refRect */
   388    refRect.x = SDLTest_RandomIntegerInRange(-200, -100);;
   389    refRect.y = SDLTest_RandomIntegerInRange(-200, -100);;
   390    refRect.w = 50;
   391    refRect.h = 50;
   392    _testSetTextInputRect(refRect);
   393 
   394    /* oversized refRect */
   395    refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
   396    refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
   397    refRect.w = 5000;
   398    refRect.h = 5000;
   399    _testSetTextInputRect(refRect);
   400 
   401    /* NULL refRect */
   402    SDL_SetTextInputRect(NULL);
   403    SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
   404 
   405    return TEST_COMPLETED;
   406 }
   407 
   408 /**
   409  * @brief Check call to SDL_SetTextInputRect with invalid data
   410  * 
   411  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
   412  */
   413 int
   414 keyboard_setTextInputRectNegative(void *arg)
   415 {      
   416    /* Some platforms set also an error message; prepare for checking it */
   417 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA  
   418    const char *expectedError = "Parameter 'rect' is invalid";
   419    const char *error;
   420    
   421    SDL_ClearError();
   422    SDLTest_AssertPass("Call to SDL_ClearError()");
   423 #endif
   424    
   425    /* NULL refRect */
   426    SDL_SetTextInputRect(NULL);
   427    SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
   428 
   429    /* Some platforms set also an error message; so check it */
   430 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA  
   431    error = SDL_GetError();
   432    SDLTest_AssertPass("Call to SDL_GetError()");
   433    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   434    if (error != NULL) {
   435       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   436           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   437    }
   438 
   439    SDL_ClearError();
   440    SDLTest_AssertPass("Call to SDL_ClearError()");
   441 #endif
   442       
   443    return TEST_COMPLETED;
   444 }
   445 
   446 /**
   447  * @brief Check call to SDL_GetScancodeFromKey
   448  * 
   449  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
   450  * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
   451  */
   452 int
   453 keyboard_getScancodeFromKey(void *arg)
   454 {      
   455    SDL_Scancode scancode;
   456    
   457    /* Regular key */
   458    scancode = SDL_GetScancodeFromKey(SDLK_4);
   459    SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
   460    SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode); 
   461 
   462    /* Virtual key */
   463    scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
   464    SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
   465    SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode); 
   466         
   467    return TEST_COMPLETED;
   468 }
   469 
   470 /**
   471  * @brief Check call to SDL_GetScancodeFromName
   472  * 
   473  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
   474  * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
   475  */
   476 int
   477 keyboard_getScancodeFromName(void *arg)
   478 {      
   479    SDL_Scancode scancode;
   480 
   481    /* Regular key, 1 character, first name in list */
   482    scancode = SDL_GetScancodeFromName("A");
   483    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
   484    SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode); 
   485 
   486    /* Regular key, 1 character */
   487    scancode = SDL_GetScancodeFromName("4");
   488    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
   489    SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode); 
   490 
   491    /* Regular key, 2 characters */
   492    scancode = SDL_GetScancodeFromName("F1");
   493    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
   494    SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode); 
   495 
   496    /* Regular key, 3 characters */
   497    scancode = SDL_GetScancodeFromName("End");
   498    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
   499    SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode); 
   500 
   501    /* Regular key, 4 characters */
   502    scancode = SDL_GetScancodeFromName("Find");
   503    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
   504    SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode); 
   505 
   506    /* Regular key, several characters */
   507    scancode = SDL_GetScancodeFromName("Backspace");
   508    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
   509    SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode); 
   510 
   511    /* Regular key, several characters with space */
   512    scancode = SDL_GetScancodeFromName("Keypad Enter");
   513    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
   514    SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode); 
   515 
   516    /* Regular key, last name in list */
   517    scancode = SDL_GetScancodeFromName("Sleep");
   518    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
   519    SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode); 
   520    
   521    return TEST_COMPLETED;
   522 }
   523 
   524 /**
   525  * @brief Check call to SDL_GetScancodeFromName with invalid data
   526  * 
   527  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
   528  * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
   529  */
   530 int
   531 keyboard_getScancodeFromNameNegative(void *arg)
   532 {      
   533    char *name;
   534    SDL_Scancode scancode;
   535    const char *expectedError = "Parameter 'name' is invalid";
   536    const char *error;
   537 
   538    SDL_ClearError();
   539    SDLTest_AssertPass("Call to SDL_ClearError()");
   540 
   541    /* Random string input */
   542    name = SDLTest_RandomAsciiStringOfSize(32);
   543    SDLTest_Assert(name != NULL, "Check that random name is not NULL");
   544    if (name == NULL) {
   545       return TEST_ABORTED;
   546    }   
   547    scancode = SDL_GetScancodeFromName((const char *)name);
   548    SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
   549    SDL_free(name);
   550    SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   551    error = SDL_GetError();
   552    SDLTest_AssertPass("Call to SDL_GetError()");
   553    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   554    if (error != NULL) {
   555       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   556           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   557    }
   558 
   559    SDL_ClearError();
   560    SDLTest_AssertPass("Call to SDL_ClearError()");
   561          
   562    /* Zero length string input */
   563    name = "";
   564    scancode = SDL_GetScancodeFromName((const char *)name);
   565    SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
   566    SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   567    error = SDL_GetError();
   568    SDLTest_AssertPass("Call to SDL_GetError()");
   569    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   570    if (error != NULL) {
   571       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   572           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   573    }
   574 
   575    SDL_ClearError();
   576    SDLTest_AssertPass("Call to SDL_ClearError()");
   577 
   578    /* NULL input */
   579    name = NULL;
   580    scancode = SDL_GetScancodeFromName((const char *)name);
   581    SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
   582    SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   583    error = SDL_GetError();
   584    SDLTest_AssertPass("Call to SDL_GetError()");
   585    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   586    if (error != NULL) {
   587       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   588           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   589    }
   590 
   591    SDL_ClearError();
   592    SDLTest_AssertPass("Call to SDL_ClearError()");
   593    
   594    return TEST_COMPLETED;
   595 }
   596 
   597 
   598 
   599 /* ================= Test References ================== */
   600 
   601 /* Keyboard test cases */
   602 static const SDLTest_TestCaseReference keyboardTest1 =
   603 		{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
   604 
   605 static const SDLTest_TestCaseReference keyboardTest2 =
   606 		{ (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED };
   607 
   608 static const SDLTest_TestCaseReference keyboardTest3 =
   609 		{ (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED };
   610 
   611 static const SDLTest_TestCaseReference keyboardTest4 =
   612 		{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
   613 
   614 static const SDLTest_TestCaseReference keyboardTest5 =
   615 		{ (SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED };
   616 
   617 static const SDLTest_TestCaseReference keyboardTest6 =
   618 		{ (SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED };
   619 
   620 static const SDLTest_TestCaseReference keyboardTest7 =
   621 		{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
   622 
   623 static const SDLTest_TestCaseReference keyboardTest8 =
   624 		{ (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED };
   625 
   626 static const SDLTest_TestCaseReference keyboardTest9 =
   627 		{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
   628 
   629 static const SDLTest_TestCaseReference keyboardTest10 =
   630 		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
   631 
   632 static const SDLTest_TestCaseReference keyboardTest11 =
   633 		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
   634 
   635 static const SDLTest_TestCaseReference keyboardTest12 =
   636 		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
   637 
   638 /* Sequence of Keyboard test cases */
   639 static const SDLTest_TestCaseReference *keyboardTests[] =  {
   640 	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, 
   641 	&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, NULL
   642 };
   643 
   644 /* Keyboard test suite (global) */
   645 SDLTest_TestSuiteReference keyboardTestSuite = {
   646 	"Keyboard",
   647 	NULL,
   648 	keyboardTests,
   649 	NULL
   650 };