test/testautomation_keyboard.c
changeset 6807 e3610bc90cf3
parent 6803 fbe83a6d10fa
child 6808 3ad413bd1cd6
     1.1 --- a/test/testautomation_keyboard.c	Tue Jan 08 09:30:53 2013 -0300
     1.2 +++ b/test/testautomation_keyboard.c	Thu Jan 10 23:26:49 2013 -0800
     1.3 @@ -130,6 +130,155 @@
     1.4     return TEST_COMPLETED;
     1.5  }
     1.6  
     1.7 +/**
     1.8 + * @brief Check call to SDL_GetKeyName
     1.9 + * 
    1.10 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
    1.11 + */
    1.12 +int
    1.13 +keyboard_getKeyName(void *arg)
    1.14 +{   
    1.15 +   char *result;
    1.16 +   char *expected;
    1.17 +
    1.18 +   /* Case where key has a 1 character name */
    1.19 +   expected = "3";
    1.20 +   result = (char *)SDL_GetKeyName(SDLK_3);
    1.21 +   SDLTest_AssertPass("Call to SDL_GetKeyName()");
    1.22 +   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
    1.23 +   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
    1.24 +
    1.25 +   /* Case where key has a 2 character name */
    1.26 +   expected = "F1";
    1.27 +   result = (char *)SDL_GetKeyName(SDLK_F1);
    1.28 +   SDLTest_AssertPass("Call to SDL_GetKeyName()");
    1.29 +   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
    1.30 +   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
    1.31 +
    1.32 +   /* Case where key has a 3 character name */
    1.33 +   expected = "Cut";
    1.34 +   result = (char *)SDL_GetKeyName(SDLK_CUT);
    1.35 +   SDLTest_AssertPass("Call to SDL_GetKeyName()");
    1.36 +   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
    1.37 +   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
    1.38 +
    1.39 +   /* Case where key has a 4 character name */
    1.40 +   expected = "Down";
    1.41 +   result = (char *)SDL_GetKeyName(SDLK_DOWN);
    1.42 +   SDLTest_AssertPass("Call to SDL_GetKeyName()");
    1.43 +   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
    1.44 +   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
    1.45 +
    1.46 +   /* Case where key has a N character name */
    1.47 +   expected = "BrightnessUp";
    1.48 +   result = (char *)SDL_GetKeyName(SDLK_BRIGHTNESSUP);
    1.49 +   SDLTest_AssertPass("Call to SDL_GetKeyName()");
    1.50 +   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
    1.51 +   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
    1.52 +
    1.53 +   /* Case where key has a N character name with space */
    1.54 +   expected = "Keypad MemStore";
    1.55 +   result = (char *)SDL_GetKeyName(SDLK_KP_MEMSTORE);
    1.56 +   SDLTest_AssertPass("Call to SDL_GetKeyName()");
    1.57 +   SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
    1.58 +   SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
    1.59 +
    1.60 +   return TEST_COMPLETED;
    1.61 +}
    1.62 +
    1.63 +/**
    1.64 + * @brief Check call to SDL_GetModState and SDL_SetModState
    1.65 + * 
    1.66 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
    1.67 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
    1.68 + */
    1.69 +int
    1.70 +keyboard_getSetModState(void *arg)
    1.71 +{   
    1.72 +   SDL_Keymod result;
    1.73 +   SDL_Keymod currentState;
    1.74 +   SDL_Keymod newState;
    1.75 +   SDL_Keymod allStates =     
    1.76 +    KMOD_NONE |
    1.77 +    KMOD_LSHIFT |
    1.78 +    KMOD_RSHIFT |
    1.79 +    KMOD_LCTRL |
    1.80 +    KMOD_RCTRL |
    1.81 +    KMOD_LALT |
    1.82 +    KMOD_RALT |
    1.83 +    KMOD_LGUI |
    1.84 +    KMOD_RGUI |
    1.85 +    KMOD_NUM |
    1.86 +    KMOD_CAPS |
    1.87 +    KMOD_MODE |
    1.88 +    KMOD_RESERVED;
    1.89 +
    1.90 +   /* Get state, cache for later reset */                                                   
    1.91 +   result = SDL_GetModState();
    1.92 +   SDLTest_AssertPass("Call to SDL_GetModState()");
    1.93 +   SDLTest_AssertCheck(result >=0 && result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);   
    1.94 +   currentState = result;
    1.95 +
    1.96 +   /* Set random state */   
    1.97 +   newState = SDLTest_RandomIntegerInRange(0, allStates);
    1.98 +   SDL_SetModState(newState);
    1.99 +   SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState);
   1.100 +   result = SDL_GetModState();
   1.101 +   SDLTest_AssertPass("Call to SDL_GetModState()");
   1.102 +   SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result);
   1.103 +
   1.104 +   /* Set zero state */
   1.105 +   SDL_SetModState(0);
   1.106 +   SDLTest_AssertPass("Call to SDL_SetModState(0)");
   1.107 +   result = SDL_GetModState();
   1.108 +   SDLTest_AssertPass("Call to SDL_GetModState()");
   1.109 +   SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result);
   1.110 +
   1.111 +   /* Revert back to cached current state if needed */
   1.112 +   if (currentState != 0) {
   1.113 +     SDL_SetModState(currentState);
   1.114 +     SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState);
   1.115 +     result = SDL_GetModState();
   1.116 +     SDLTest_AssertPass("Call to SDL_GetModState()");
   1.117 +     SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result);
   1.118 +   }
   1.119 +
   1.120 +   return TEST_COMPLETED;
   1.121 +}
   1.122 +
   1.123 +
   1.124 +/**
   1.125 + * @brief Check call to SDL_StartTextInput and SDL_StopTextInput
   1.126 + * 
   1.127 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
   1.128 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput
   1.129 + */
   1.130 +int
   1.131 +keyboard_startStopTextInput(void *arg)
   1.132 +{   
   1.133 +   /* Start-Stop */
   1.134 +   SDL_StartTextInput();
   1.135 +   SDLTest_AssertPass("Call to SDL_StartTextInput()");
   1.136 +   SDL_StopTextInput();
   1.137 +   SDLTest_AssertPass("Call to SDL_StopTextInput()");
   1.138 +
   1.139 +   /* Stop-Start */
   1.140 +   SDL_StartTextInput();
   1.141 +   SDLTest_AssertPass("Call to SDL_StartTextInput()");
   1.142 +   
   1.143 +   /* Start-Start */
   1.144 +   SDL_StartTextInput();
   1.145 +   SDLTest_AssertPass("Call to SDL_StartTextInput()");
   1.146 +
   1.147 +   /* Stop-Stop */   
   1.148 +   SDL_StopTextInput();
   1.149 +   SDLTest_AssertPass("Call to SDL_StopTextInput()");
   1.150 +   SDL_StopTextInput();
   1.151 +   SDLTest_AssertPass("Call to SDL_StopTextInput()");
   1.152 +
   1.153 +   return TEST_COMPLETED;
   1.154 +}
   1.155 +
   1.156  
   1.157  
   1.158  /* ================= Test References ================== */
   1.159 @@ -147,9 +296,18 @@
   1.160  static const SDLTest_TestCaseReference keyboardTest4 =
   1.161  		{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
   1.162  
   1.163 +static const SDLTest_TestCaseReference keyboardTest5 =
   1.164 +		{ (SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED };
   1.165 +
   1.166 +static const SDLTest_TestCaseReference keyboardTest6 =
   1.167 +		{ (SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED };
   1.168 +
   1.169 +static const SDLTest_TestCaseReference keyboardTest7 =
   1.170 +		{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
   1.171 +
   1.172  /* Sequence of Keyboard test cases */
   1.173  static const SDLTest_TestCaseReference *keyboardTests[] =  {
   1.174 -	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, NULL
   1.175 +	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, &keyboardTest7, NULL
   1.176  };
   1.177  
   1.178  /* Keyboard test suite (global) */