test/testautomation_keyboard.c
changeset 6813 b21879e67db2
parent 6811 60d95fcfaf3c
child 6983 b72f56ab9867
equal deleted inserted replaced
6812:1f92a4ad24e7 6813:b21879e67db2
     2  * Keyboard test suite
     2  * Keyboard test suite
     3  */
     3  */
     4 
     4 
     5 #include <stdio.h>
     5 #include <stdio.h>
     6 
     6 
       
     7 #include "SDL_config.h"
     7 #include "SDL.h"
     8 #include "SDL.h"
     8 #include "SDL_test.h"
     9 #include "SDL_test.h"
     9 
    10 
    10 /* ================= Test Case Implementation ================== */
    11 /* ================= Test Case Implementation ================== */
    11 
    12 
   108  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
   109  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
   109  */
   110  */
   110 int
   111 int
   111 keyboard_getKeyFromScancode(void *arg)
   112 keyboard_getKeyFromScancode(void *arg)
   112 {
   113 {
       
   114    const char *expectedError = "Parameter 'scancode' is invalid";
       
   115    const char *error;   
   113    SDL_Keycode result;
   116    SDL_Keycode result;
   114 
   117 
   115    /* Case where input is valid */
   118    /* Case where input is valid */
   116    result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
   119    result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
   117    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
   120    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
   118    SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
   121    SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
   119 
   122 
   120    /* Case where input is zero */
   123    /* Case where input is zero */
   121    result = SDL_GetKeyFromScancode(0);
   124    result = SDL_GetKeyFromScancode(0);
   122    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(zero)");
   125    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
   123    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   126    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   124 
   127 
   125    /* Case where input is invalid */
   128    SDL_ClearError();
       
   129    SDLTest_AssertPass("Call to SDL_ClearError()");
       
   130 
       
   131    /* Case where input is invalid (too small) */
   126    result = SDL_GetKeyFromScancode(-999);
   132    result = SDL_GetKeyFromScancode(-999);
   127    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(invalid)");
   133    SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
   128    SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
   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()");
   129 
   160 
   130    return TEST_COMPLETED;
   161    return TEST_COMPLETED;
   131 }
   162 }
   132 
   163 
   133 /**
   164 /**
   380  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
   411  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
   381  */
   412  */
   382 int
   413 int
   383 keyboard_setTextInputRectNegative(void *arg)
   414 keyboard_setTextInputRectNegative(void *arg)
   384 {      
   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  
   385    const char *expectedError = "Parameter 'rect' is invalid";
   418    const char *expectedError = "Parameter 'rect' is invalid";
   386    const char *error;
   419    const char *error;
   387    
   420    
   388    SDL_ClearError();
   421    SDL_ClearError();
   389    SDLTest_AssertPass("Call to SDL_ClearError()");
   422    SDLTest_AssertPass("Call to SDL_ClearError()");
       
   423 #endif
   390    
   424    
   391    /* NULL refRect */
   425    /* NULL refRect */
   392    SDL_SetTextInputRect(NULL);
   426    SDL_SetTextInputRect(NULL);
   393    SDLTest_AssertPass("Call to 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  
   394    error = SDL_GetError();
   431    error = SDL_GetError();
   395    SDLTest_AssertPass("Call to SDL_GetError()");
   432    SDLTest_AssertPass("Call to SDL_GetError()");
   396    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   433    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   397    if (error != NULL) {
   434    if (error != NULL) {
   398       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   435       SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   399           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   436           "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   400    }
   437    }
   401 
   438 
   402    SDL_ClearError();
   439    SDL_ClearError();
   403    SDLTest_AssertPass("Call to SDL_ClearError()");
   440    SDLTest_AssertPass("Call to SDL_ClearError()");
       
   441 #endif
   404       
   442       
   405    return TEST_COMPLETED;
   443    return TEST_COMPLETED;
   406 }
   444 }
   407 
   445 
   408 /**
   446 /**