test/testautomation_keyboard.c
changeset 6811 60d95fcfaf3c
parent 6808 3ad413bd1cd6
child 6813 b21879e67db2
     1.1 --- a/test/testautomation_keyboard.c	Sat Jan 12 14:06:58 2013 -0500
     1.2 +++ b/test/testautomation_keyboard.c	Sat Jan 12 22:58:12 2013 -0800
     1.3 @@ -382,7 +382,7 @@
     1.4  int
     1.5  keyboard_setTextInputRectNegative(void *arg)
     1.6  {      
     1.7 -   const char *expectedError = "Parameter is invalid";
     1.8 +   const char *expectedError = "Parameter 'rect' is invalid";
     1.9     const char *error;
    1.10     
    1.11     SDL_ClearError();
    1.12 @@ -405,6 +405,157 @@
    1.13     return TEST_COMPLETED;
    1.14  }
    1.15  
    1.16 +/**
    1.17 + * @brief Check call to SDL_GetScancodeFromKey
    1.18 + * 
    1.19 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
    1.20 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
    1.21 + */
    1.22 +int
    1.23 +keyboard_getScancodeFromKey(void *arg)
    1.24 +{      
    1.25 +   SDL_Scancode scancode;
    1.26 +   
    1.27 +   /* Regular key */
    1.28 +   scancode = SDL_GetScancodeFromKey(SDLK_4);
    1.29 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
    1.30 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode); 
    1.31 +
    1.32 +   /* Virtual key */
    1.33 +   scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
    1.34 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
    1.35 +   SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode); 
    1.36 +        
    1.37 +   return TEST_COMPLETED;
    1.38 +}
    1.39 +
    1.40 +/**
    1.41 + * @brief Check call to SDL_GetScancodeFromName
    1.42 + * 
    1.43 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
    1.44 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
    1.45 + */
    1.46 +int
    1.47 +keyboard_getScancodeFromName(void *arg)
    1.48 +{      
    1.49 +   SDL_Scancode scancode;
    1.50 +
    1.51 +   /* Regular key, 1 character, first name in list */
    1.52 +   scancode = SDL_GetScancodeFromName("A");
    1.53 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
    1.54 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode); 
    1.55 +
    1.56 +   /* Regular key, 1 character */
    1.57 +   scancode = SDL_GetScancodeFromName("4");
    1.58 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
    1.59 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode); 
    1.60 +
    1.61 +   /* Regular key, 2 characters */
    1.62 +   scancode = SDL_GetScancodeFromName("F1");
    1.63 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
    1.64 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode); 
    1.65 +
    1.66 +   /* Regular key, 3 characters */
    1.67 +   scancode = SDL_GetScancodeFromName("End");
    1.68 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
    1.69 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode); 
    1.70 +
    1.71 +   /* Regular key, 4 characters */
    1.72 +   scancode = SDL_GetScancodeFromName("Find");
    1.73 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
    1.74 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode); 
    1.75 +
    1.76 +   /* Regular key, several characters */
    1.77 +   scancode = SDL_GetScancodeFromName("Backspace");
    1.78 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
    1.79 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode); 
    1.80 +
    1.81 +   /* Regular key, several characters with space */
    1.82 +   scancode = SDL_GetScancodeFromName("Keypad Enter");
    1.83 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
    1.84 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode); 
    1.85 +
    1.86 +   /* Regular key, last name in list */
    1.87 +   scancode = SDL_GetScancodeFromName("Sleep");
    1.88 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
    1.89 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode); 
    1.90 +   
    1.91 +   return TEST_COMPLETED;
    1.92 +}
    1.93 +
    1.94 +/**
    1.95 + * @brief Check call to SDL_GetScancodeFromName with invalid data
    1.96 + * 
    1.97 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
    1.98 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
    1.99 + */
   1.100 +int
   1.101 +keyboard_getScancodeFromNameNegative(void *arg)
   1.102 +{      
   1.103 +   char *name;
   1.104 +   SDL_Scancode scancode;
   1.105 +   const char *expectedError = "Parameter 'name' is invalid";
   1.106 +   const char *error;
   1.107 +
   1.108 +   SDL_ClearError();
   1.109 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   1.110 +
   1.111 +   /* Random string input */
   1.112 +   name = SDLTest_RandomAsciiStringOfSize(32);
   1.113 +   SDLTest_Assert(name != NULL, "Check that random name is not NULL");
   1.114 +   if (name == NULL) {
   1.115 +      return TEST_ABORTED;
   1.116 +   }   
   1.117 +   scancode = SDL_GetScancodeFromName((const char *)name);
   1.118 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
   1.119 +   SDL_free(name);
   1.120 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   1.121 +   error = SDL_GetError();
   1.122 +   SDLTest_AssertPass("Call to SDL_GetError()");
   1.123 +   SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   1.124 +   if (error != NULL) {
   1.125 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   1.126 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   1.127 +   }
   1.128 +
   1.129 +   SDL_ClearError();
   1.130 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   1.131 +         
   1.132 +   /* Zero length string input */
   1.133 +   name = "";
   1.134 +   scancode = SDL_GetScancodeFromName((const char *)name);
   1.135 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
   1.136 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   1.137 +   error = SDL_GetError();
   1.138 +   SDLTest_AssertPass("Call to SDL_GetError()");
   1.139 +   SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   1.140 +   if (error != NULL) {
   1.141 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   1.142 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   1.143 +   }
   1.144 +
   1.145 +   SDL_ClearError();
   1.146 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   1.147 +
   1.148 +   /* NULL input */
   1.149 +   name = NULL;
   1.150 +   scancode = SDL_GetScancodeFromName((const char *)name);
   1.151 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
   1.152 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   1.153 +   error = SDL_GetError();
   1.154 +   SDLTest_AssertPass("Call to SDL_GetError()");
   1.155 +   SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   1.156 +   if (error != NULL) {
   1.157 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   1.158 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   1.159 +   }
   1.160 +
   1.161 +   SDL_ClearError();
   1.162 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   1.163 +   
   1.164 +   return TEST_COMPLETED;
   1.165 +}
   1.166 +
   1.167  
   1.168  
   1.169  /* ================= Test References ================== */
   1.170 @@ -437,10 +588,19 @@
   1.171  static const SDLTest_TestCaseReference keyboardTest9 =
   1.172  		{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
   1.173  
   1.174 +static const SDLTest_TestCaseReference keyboardTest10 =
   1.175 +		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
   1.176 +
   1.177 +static const SDLTest_TestCaseReference keyboardTest11 =
   1.178 +		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
   1.179 +
   1.180 +static const SDLTest_TestCaseReference keyboardTest12 =
   1.181 +		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
   1.182 +
   1.183  /* Sequence of Keyboard test cases */
   1.184  static const SDLTest_TestCaseReference *keyboardTests[] =  {
   1.185  	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, 
   1.186 -	&keyboardTest7, &keyboardTest8, &keyboardTest9, NULL
   1.187 +	&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, NULL
   1.188  };
   1.189  
   1.190  /* Keyboard test suite (global) */