test/testautomation_keyboard.c
changeset 6803 fbe83a6d10fa
parent 6800 26c6795ec1a4
child 6807 e3610bc90cf3
equal deleted inserted replaced
6801:f92e3d5f71a2 6803:fbe83a6d10fa
     7 #include "SDL.h"
     7 #include "SDL.h"
     8 #include "SDL_test.h"
     8 #include "SDL_test.h"
     9 
     9 
    10 /* ================= Test Case Implementation ================== */
    10 /* ================= Test Case Implementation ================== */
    11 
    11 
    12 /*!
       
    13  * TODO: Add tests for keyboard here
       
    14  *
       
    15  */
       
    16 
       
    17 /* Test case functions */
    12 /* Test case functions */
    18 
    13 
    19 /**
    14 /**
    20  * @brief Check call to SDL_GetKeyboardState
    15  * @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
    21  * 
    16  * 
       
    17  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
    22  */
    18  */
    23 int
    19 int
    24 keyboard_getKeyboardState(void *arg)
    20 keyboard_getKeyboardState(void *arg)
    25 {
    21 {
    26    int numkeys;
    22    int numkeys;
    39    SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
    35    SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
    40    
    36    
    41    return TEST_COMPLETED;
    37    return TEST_COMPLETED;
    42 }
    38 }
    43 
    39 
       
    40 /**
       
    41  * @brief Check call to SDL_GetKeyboardFocus
       
    42  * 
       
    43  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus
       
    44  */
       
    45 int
       
    46 keyboard_getKeyboardFocus(void *arg)
       
    47 {
       
    48    SDL_Window* window;
       
    49 
       
    50    /* Call, but ignore return value */
       
    51    window = SDL_GetKeyboardFocus();
       
    52    SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
       
    53 
       
    54    return TEST_COMPLETED;
       
    55 }
       
    56 
       
    57 /**
       
    58  * @brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
       
    59  * 
       
    60  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName
       
    61  */
       
    62 int
       
    63 keyboard_getKeyFromName(void *arg)
       
    64 {
       
    65    SDL_Keycode result;
       
    66 
       
    67    /* Case where Key is known, 1 character input */
       
    68    result = SDL_GetKeyFromName("A");
       
    69    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/single)");
       
    70    SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
       
    71 
       
    72    /* Case where Key is known, 2 character input */
       
    73    result = SDL_GetKeyFromName("F1");
       
    74    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
       
    75    SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %i", SDLK_F1, result);
       
    76 
       
    77    /* Case where Key is known, 3 character input */
       
    78    result = SDL_GetKeyFromName("End");
       
    79    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
       
    80    SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %i", SDLK_END, result);
       
    81 
       
    82    /* Case where Key is known, 4 character input */
       
    83    result = SDL_GetKeyFromName("Find");
       
    84    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
       
    85    SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %i", SDLK_FIND, result);
       
    86 
       
    87    /* Case where Key is known, multiple character input */
       
    88    result = SDL_GetKeyFromName("AudioStop");
       
    89    SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
       
    90    SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %i", SDLK_AUDIOSTOP, result);
       
    91 
       
    92    /* Case where Key is unknown */
       
    93    result = SDL_GetKeyFromName("NotThere");
       
    94    SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
       
    95    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
       
    96 
       
    97    /* Case where input is NULL/invalid */
       
    98    result = SDL_GetKeyFromName(NULL);
       
    99    SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
       
   100    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
       
   101 
       
   102    return TEST_COMPLETED;
       
   103 }
       
   104 
       
   105 /**
       
   106  * @brief Check call to SDL_GetKeyFromScancode
       
   107  * 
       
   108  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
       
   109  */
       
   110 int
       
   111 keyboard_getKeyFromScancode(void *arg)
       
   112 {
       
   113    SDL_Keycode result;
       
   114 
       
   115    /* Case where input is valid */
       
   116    result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
       
   117    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
       
   118    SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
       
   119 
       
   120    /* Case where input is zero */
       
   121    result = SDL_GetKeyFromScancode(0);
       
   122    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(zero)");
       
   123    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
       
   124 
       
   125    /* Case where input is invalid */
       
   126    result = SDL_GetKeyFromScancode(-999);
       
   127    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(invalid)");
       
   128    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
       
   129 
       
   130    return TEST_COMPLETED;
       
   131 }
       
   132 
       
   133 
       
   134 
    44 /* ================= Test References ================== */
   135 /* ================= Test References ================== */
    45 
   136 
    46 /* Keyboard test cases */
   137 /* Keyboard test cases */
    47 static const SDLTest_TestCaseReference keyboardTest1 =
   138 static const SDLTest_TestCaseReference keyboardTest1 =
    48 		{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState", TEST_ENABLED };
   139 		{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
       
   140 
       
   141 static const SDLTest_TestCaseReference keyboardTest2 =
       
   142 		{ (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED };
       
   143 
       
   144 static const SDLTest_TestCaseReference keyboardTest3 =
       
   145 		{ (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED };
       
   146 
       
   147 static const SDLTest_TestCaseReference keyboardTest4 =
       
   148 		{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
    49 
   149 
    50 /* Sequence of Keyboard test cases */
   150 /* Sequence of Keyboard test cases */
    51 static const SDLTest_TestCaseReference *keyboardTests[] =  {
   151 static const SDLTest_TestCaseReference *keyboardTests[] =  {
    52 	&keyboardTest1, NULL
   152 	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, NULL
    53 };
   153 };
    54 
   154 
    55 /* Keyboard test suite (global) */
   155 /* Keyboard test suite (global) */
    56 SDLTest_TestSuiteReference keyboardTestSuite = {
   156 SDLTest_TestSuiteReference keyboardTestSuite = {
    57 	"Keyboard",
   157 	"Keyboard",