test/testautomation_keyboard.c
changeset 6803 fbe83a6d10fa
parent 6800 26c6795ec1a4
child 6807 e3610bc90cf3
     1.1 --- a/test/testautomation_keyboard.c	Sun Jan 06 18:19:30 2013 -0800
     1.2 +++ b/test/testautomation_keyboard.c	Mon Jan 07 07:39:15 2013 -0800
     1.3 @@ -9,16 +9,12 @@
     1.4  
     1.5  /* ================= Test Case Implementation ================== */
     1.6  
     1.7 -/*!
     1.8 - * TODO: Add tests for keyboard here
     1.9 - *
    1.10 - */
    1.11 -
    1.12  /* Test case functions */
    1.13  
    1.14  /**
    1.15 - * @brief Check call to SDL_GetKeyboardState
    1.16 + * @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
    1.17   * 
    1.18 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
    1.19   */
    1.20  int
    1.21  keyboard_getKeyboardState(void *arg)
    1.22 @@ -41,15 +37,119 @@
    1.23     return TEST_COMPLETED;
    1.24  }
    1.25  
    1.26 +/**
    1.27 + * @brief Check call to SDL_GetKeyboardFocus
    1.28 + * 
    1.29 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus
    1.30 + */
    1.31 +int
    1.32 +keyboard_getKeyboardFocus(void *arg)
    1.33 +{
    1.34 +   SDL_Window* window;
    1.35 +
    1.36 +   /* Call, but ignore return value */
    1.37 +   window = SDL_GetKeyboardFocus();
    1.38 +   SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
    1.39 +
    1.40 +   return TEST_COMPLETED;
    1.41 +}
    1.42 +
    1.43 +/**
    1.44 + * @brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
    1.45 + * 
    1.46 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName
    1.47 + */
    1.48 +int
    1.49 +keyboard_getKeyFromName(void *arg)
    1.50 +{
    1.51 +   SDL_Keycode result;
    1.52 +
    1.53 +   /* Case where Key is known, 1 character input */
    1.54 +   result = SDL_GetKeyFromName("A");
    1.55 +   SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/single)");
    1.56 +   SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
    1.57 +
    1.58 +   /* Case where Key is known, 2 character input */
    1.59 +   result = SDL_GetKeyFromName("F1");
    1.60 +   SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
    1.61 +   SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %i", SDLK_F1, result);
    1.62 +
    1.63 +   /* Case where Key is known, 3 character input */
    1.64 +   result = SDL_GetKeyFromName("End");
    1.65 +   SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
    1.66 +   SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %i", SDLK_END, result);
    1.67 +
    1.68 +   /* Case where Key is known, 4 character input */
    1.69 +   result = SDL_GetKeyFromName("Find");
    1.70 +   SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
    1.71 +   SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %i", SDLK_FIND, result);
    1.72 +
    1.73 +   /* Case where Key is known, multiple character input */
    1.74 +   result = SDL_GetKeyFromName("AudioStop");
    1.75 +   SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
    1.76 +   SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %i", SDLK_AUDIOSTOP, result);
    1.77 +
    1.78 +   /* Case where Key is unknown */
    1.79 +   result = SDL_GetKeyFromName("NotThere");
    1.80 +   SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
    1.81 +   SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
    1.82 +
    1.83 +   /* Case where input is NULL/invalid */
    1.84 +   result = SDL_GetKeyFromName(NULL);
    1.85 +   SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
    1.86 +   SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
    1.87 +
    1.88 +   return TEST_COMPLETED;
    1.89 +}
    1.90 +
    1.91 +/**
    1.92 + * @brief Check call to SDL_GetKeyFromScancode
    1.93 + * 
    1.94 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
    1.95 + */
    1.96 +int
    1.97 +keyboard_getKeyFromScancode(void *arg)
    1.98 +{
    1.99 +   SDL_Keycode result;
   1.100 +
   1.101 +   /* Case where input is valid */
   1.102 +   result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
   1.103 +   SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
   1.104 +   SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
   1.105 +
   1.106 +   /* Case where input is zero */
   1.107 +   result = SDL_GetKeyFromScancode(0);
   1.108 +   SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(zero)");
   1.109 +   SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   1.110 +
   1.111 +   /* Case where input is invalid */
   1.112 +   result = SDL_GetKeyFromScancode(-999);
   1.113 +   SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(invalid)");
   1.114 +   SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   1.115 +
   1.116 +   return TEST_COMPLETED;
   1.117 +}
   1.118 +
   1.119 +
   1.120 +
   1.121  /* ================= Test References ================== */
   1.122  
   1.123  /* Keyboard test cases */
   1.124  static const SDLTest_TestCaseReference keyboardTest1 =
   1.125 -		{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState", TEST_ENABLED };
   1.126 +		{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
   1.127 +
   1.128 +static const SDLTest_TestCaseReference keyboardTest2 =
   1.129 +		{ (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED };
   1.130 +
   1.131 +static const SDLTest_TestCaseReference keyboardTest3 =
   1.132 +		{ (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED };
   1.133 +
   1.134 +static const SDLTest_TestCaseReference keyboardTest4 =
   1.135 +		{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
   1.136  
   1.137  /* Sequence of Keyboard test cases */
   1.138  static const SDLTest_TestCaseReference *keyboardTests[] =  {
   1.139 -	&keyboardTest1, NULL
   1.140 +	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, NULL
   1.141  };
   1.142  
   1.143  /* Keyboard test suite (global) */