2015-06-21 09:33:46 -06:00
/**
* Keyboard test suite
*/
2022-11-26 21:43:38 -07:00
# include <SDL3/SDL.h>
# include <SDL3/SDL_test.h>
2023-03-08 08:12:45 -07:00
# include "testautomation_suites.h"
2015-06-21 09:33:46 -06:00
/* ================= Test Case Implementation ================== */
/* Test case functions */
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetKeyboardState with and without numkeys reference .
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetKeyboardState
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getKeyboardState ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
int numkeys ;
2023-03-08 13:18:02 -07:00
const Uint8 * state ;
2022-11-30 13:51:59 -07:00
/* Case where numkeys pointer is NULL */
2023-03-08 13:18:02 -07:00
state = SDL_GetKeyboardState ( NULL ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyboardState(NULL) " ) ;
SDLTest_AssertCheck ( state ! = NULL , " Validate that return value from SDL_GetKeyboardState is not NULL " ) ;
/* Case where numkeys pointer is not NULL */
numkeys = - 1 ;
2023-03-08 13:18:02 -07:00
state = SDL_GetKeyboardState ( & numkeys ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyboardState(&numkeys) " ) ;
SDLTest_AssertCheck ( state ! = NULL , " Validate that return value from SDL_GetKeyboardState is not NULL " ) ;
SDLTest_AssertCheck ( numkeys > = 0 , " Validate that value of numkeys is >= 0, got: %i " , numkeys ) ;
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetKeyboardFocus
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetKeyboardFocus
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getKeyboardFocus ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
/* Call, but ignore return value */
SDL_GetKeyboardFocus ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyboardFocus() " ) ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetKeyFromName for known , unknown and invalid name .
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetKeyFromName
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getKeyFromName ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Keycode result ;
/* Case where Key is known, 1 character input */
result = SDL_GetKeyFromName ( " A " ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromName(known/single) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_a , " Verify result from call, expected: %i, got: %i " , SDLK_a , result ) ;
2022-11-30 13:51:59 -07:00
/* Case where Key is known, 2 character input */
result = SDL_GetKeyFromName ( " F1 " ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromName(known/double) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_F1 , " Verify result from call, expected: %i, got: %i " , SDLK_F1 , result ) ;
2022-11-30 13:51:59 -07:00
/* Case where Key is known, 3 character input */
result = SDL_GetKeyFromName ( " End " ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromName(known/triple) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_END , " Verify result from call, expected: %i, got: %i " , SDLK_END , result ) ;
2022-11-30 13:51:59 -07:00
/* Case where Key is known, 4 character input */
result = SDL_GetKeyFromName ( " Find " ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromName(known/quad) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_FIND , " Verify result from call, expected: %i, got: %i " , SDLK_FIND , result ) ;
2022-11-30 13:51:59 -07:00
/* Case where Key is known, multiple character input */
result = SDL_GetKeyFromName ( " AudioStop " ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromName(known/multi) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_AUDIOSTOP , " Verify result from call, expected: %i, got: %i " , SDLK_AUDIOSTOP , result ) ;
2022-11-30 13:51:59 -07:00
/* Case where Key is unknown */
result = SDL_GetKeyFromName ( " NotThere " ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromName(unknown) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_UNKNOWN , " Verify result from call is UNKNOWN, expected: %i, got: %i " , SDLK_UNKNOWN , result ) ;
2022-11-30 13:51:59 -07:00
/* Case where input is NULL/invalid */
result = SDL_GetKeyFromName ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromName(NULL) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_UNKNOWN , " Verify result from call is UNKNOWN, expected: %i, got: %i " , SDLK_UNKNOWN , result ) ;
2022-11-30 13:51:59 -07:00
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/*
* Local helper to check for the invalid scancode error message
*/
2023-03-08 08:12:45 -07:00
static void checkInvalidScancodeError ( void )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
const char * expectedError = " Parameter 'scancode' is invalid " ;
const char * error ;
error = SDL_GetError ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetError() " ) ;
SDLTest_AssertCheck ( error ! = NULL , " Validate that error message was not NULL " ) ;
if ( error ! = NULL ) {
SDLTest_AssertCheck ( SDL_strcmp ( error , expectedError ) = = 0 ,
" Validate error message, expected: '%s', got: '%s' " , expectedError , error ) ;
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
}
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetKeyFromScancode
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetKeyFromScancode
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getKeyFromScancode ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Keycode result ;
/* Case where input is valid */
result = SDL_GetKeyFromScancode ( SDL_SCANCODE_A ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromScancode(valid) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_a , " Verify result from call, expected: %i, got: %i " , SDLK_a , result ) ;
2022-11-30 13:51:59 -07:00
/* Case where input is zero */
result = SDL_GetKeyFromScancode ( 0 ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromScancode(0) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_UNKNOWN , " Verify result from call is UNKNOWN, expected: %i, got: %i " , SDLK_UNKNOWN , result ) ;
2022-11-30 13:51:59 -07:00
/* Clear error message */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
/* Case where input is invalid (too small) */
result = SDL_GetKeyFromScancode ( - 999 ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromScancode(-999) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_UNKNOWN , " Verify result from call is UNKNOWN, expected: %i, got: %i " , SDLK_UNKNOWN , result ) ;
2022-12-29 14:58:16 -07:00
checkInvalidScancodeError ( ) ;
2022-11-30 13:51:59 -07:00
/* Case where input is invalid (too big) */
result = SDL_GetKeyFromScancode ( 999 ) ;
SDLTest_AssertPass ( " Call to SDL_GetKeyFromScancode(999) " ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertCheck ( result = = SDLK_UNKNOWN , " Verify result from call is UNKNOWN, expected: %i, got: %i " , SDLK_UNKNOWN , result ) ;
2022-12-29 14:58:16 -07:00
checkInvalidScancodeError ( ) ;
2022-11-30 13:51:59 -07:00
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetKeyName
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetKeyName
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getKeyName ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
const char * result ;
const char * expected ;
/* Case where key has a 1 character name */
expected = " 3 " ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( SDLK_3 ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName() " ) ;
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: %s, got: %s " , expected , result ) ;
/* Case where key has a 2 character name */
expected = " F1 " ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( SDLK_F1 ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName() " ) ;
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: %s, got: %s " , expected , result ) ;
/* Case where key has a 3 character name */
expected = " Cut " ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( SDLK_CUT ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName() " ) ;
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: %s, got: %s " , expected , result ) ;
/* Case where key has a 4 character name */
expected = " Down " ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( SDLK_DOWN ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName() " ) ;
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: %s, got: %s " , expected , result ) ;
/* Case where key has a N character name */
expected = " BrightnessUp " ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( SDLK_BRIGHTNESSUP ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName() " ) ;
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: %s, got: %s " , expected , result ) ;
/* Case where key has a N character name with space */
expected = " Keypad MemStore " ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( SDLK_KP_MEMSTORE ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName() " ) ;
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: %s, got: %s " , expected , result ) ;
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* SDL_GetScancodeName negative cases
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetScancodeName
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getScancodeNameNegative ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Scancode scancode ;
const char * result ;
const char * expected = " " ;
/* Clear error message */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
/* Out-of-bounds scancode */
scancode = ( SDL_Scancode ) SDL_NUM_SCANCODES ;
2023-03-08 13:18:02 -07:00
result = SDL_GetScancodeName ( scancode ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetScancodeName(%d/large) " , scancode ) ;
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: '%s', got: '%s' " , expected , result ) ;
2022-12-29 14:58:16 -07:00
checkInvalidScancodeError ( ) ;
2022-11-30 13:51:59 -07:00
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* SDL_GetKeyName negative cases
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetKeyName
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getKeyNameNegative ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Keycode keycode ;
const char * result ;
const char * expected = " " ;
/* Unknown keycode */
keycode = SDLK_UNKNOWN ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( keycode ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName(%i/unknown) " , keycode ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: '%s', got: '%s' " , expected , result ) ;
/* Clear error message */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
/* Negative keycode */
keycode = ( SDL_Keycode ) SDLTest_RandomIntegerInRange ( - 255 , - 1 ) ;
2023-03-08 13:18:02 -07:00
result = SDL_GetKeyName ( keycode ) ;
2024-03-06 11:35:18 -07:00
SDLTest_AssertPass ( " Call to SDL_GetKeyName(%i/negative) " , keycode ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertCheck ( result ! = NULL , " Verify result from call is not NULL " ) ;
SDLTest_AssertCheck ( SDL_strcmp ( result , expected ) = = 0 , " Verify result from call is valid, expected: '%s', got: '%s' " , expected , result ) ;
2022-12-29 14:58:16 -07:00
checkInvalidScancodeError ( ) ;
2022-11-30 13:51:59 -07:00
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetModState and SDL_SetModState
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetModState
* \ sa SDL_SetModState
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getSetModState ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Keymod result ;
SDL_Keymod currentState ;
SDL_Keymod newState ;
SDL_Keymod allStates =
2022-12-23 18:52:46 -07:00
SDL_KMOD_NONE |
SDL_KMOD_LSHIFT |
SDL_KMOD_RSHIFT |
SDL_KMOD_LCTRL |
SDL_KMOD_RCTRL |
SDL_KMOD_LALT |
SDL_KMOD_RALT |
SDL_KMOD_LGUI |
SDL_KMOD_RGUI |
SDL_KMOD_NUM |
SDL_KMOD_CAPS |
SDL_KMOD_MODE |
SDL_KMOD_SCROLL ;
2022-11-30 13:51:59 -07:00
/* Get state, cache for later reset */
result = SDL_GetModState ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetModState() " ) ;
SDLTest_AssertCheck ( /*result >= 0 &&*/ result < = allStates , " Verify result from call is valid, expected: 0 <= result <= %i, got: %i " , allStates , result ) ;
currentState = result ;
/* Set random state */
newState = SDLTest_RandomIntegerInRange ( 0 , allStates ) ;
SDL_SetModState ( newState ) ;
SDLTest_AssertPass ( " Call to SDL_SetModState(%i) " , newState ) ;
result = SDL_GetModState ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetModState() " ) ;
SDLTest_AssertCheck ( result = = newState , " Verify result from call is valid, expected: %i, got: %i " , newState , result ) ;
/* Set zero state */
SDL_SetModState ( 0 ) ;
SDLTest_AssertPass ( " Call to SDL_SetModState(0) " ) ;
result = SDL_GetModState ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetModState() " ) ;
SDLTest_AssertCheck ( result = = 0 , " Verify result from call is valid, expected: 0, got: %i " , result ) ;
/* Revert back to cached current state if needed */
if ( currentState ! = 0 ) {
SDL_SetModState ( currentState ) ;
SDLTest_AssertPass ( " Call to SDL_SetModState(%i) " , currentState ) ;
result = SDL_GetModState ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetModState() " ) ;
SDLTest_AssertCheck ( result = = currentState , " Verify result from call is valid, expected: %i, got: %i " , currentState , result ) ;
}
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_StartTextInput and SDL_StopTextInput
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_StartTextInput
* \ sa SDL_StopTextInput
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_startStopTextInput ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
/* Start-Stop */
SDL_StartTextInput ( ) ;
SDLTest_AssertPass ( " Call to SDL_StartTextInput() " ) ;
SDL_StopTextInput ( ) ;
SDLTest_AssertPass ( " Call to SDL_StopTextInput() " ) ;
/* Stop-Start */
SDL_StartTextInput ( ) ;
SDLTest_AssertPass ( " Call to SDL_StartTextInput() " ) ;
/* Start-Start */
SDL_StartTextInput ( ) ;
SDLTest_AssertPass ( " Call to SDL_StartTextInput() " ) ;
/* Stop-Stop */
SDL_StopTextInput ( ) ;
SDLTest_AssertPass ( " Call to SDL_StopTextInput() " ) ;
SDL_StopTextInput ( ) ;
SDLTest_AssertPass ( " Call to SDL_StopTextInput() " ) ;
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/* Internal function to test SDL_SetTextInputRect */
2022-12-29 14:58:16 -07:00
static void testSetTextInputRect ( SDL_Rect refRect )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Rect testRect ;
testRect = refRect ;
SDL_SetTextInputRect ( & testRect ) ;
SDLTest_AssertPass ( " Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i) " , refRect . x , refRect . y , refRect . w , refRect . h ) ;
SDLTest_AssertCheck (
( refRect . x = = testRect . x ) & & ( refRect . y = = testRect . y ) & & ( refRect . w = = testRect . w ) & & ( refRect . h = = testRect . h ) ,
" Check that input data was not modified, expected: x:%i,y:%i,w:%i,h:%i, got: x:%i,y:%i,w:%i,h:%i " ,
refRect . x , refRect . y , refRect . w , refRect . h ,
testRect . x , testRect . y , testRect . w , testRect . h ) ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_SetTextInputRect
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_SetTextInputRect
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_setTextInputRect ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Rect refRect ;
/* Normal visible refRect, origin inside */
refRect . x = SDLTest_RandomIntegerInRange ( 1 , 50 ) ;
refRect . y = SDLTest_RandomIntegerInRange ( 1 , 50 ) ;
refRect . w = SDLTest_RandomIntegerInRange ( 10 , 50 ) ;
refRect . h = SDLTest_RandomIntegerInRange ( 10 , 50 ) ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* Normal visible refRect, origin 0,0 */
refRect . x = 0 ;
refRect . y = 0 ;
refRect . w = SDLTest_RandomIntegerInRange ( 10 , 50 ) ;
refRect . h = SDLTest_RandomIntegerInRange ( 10 , 50 ) ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* 1Pixel refRect */
refRect . x = SDLTest_RandomIntegerInRange ( 10 , 50 ) ;
refRect . y = SDLTest_RandomIntegerInRange ( 10 , 50 ) ;
refRect . w = 1 ;
refRect . h = 1 ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* 0pixel refRect */
refRect . x = 1 ;
refRect . y = 1 ;
refRect . w = 1 ;
refRect . h = 0 ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* 0pixel refRect */
refRect . x = 1 ;
refRect . y = 1 ;
refRect . w = 0 ;
refRect . h = 1 ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* 0pixel refRect */
refRect . x = 1 ;
refRect . y = 1 ;
refRect . w = 0 ;
refRect . h = 0 ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* 0pixel refRect */
refRect . x = 0 ;
refRect . y = 0 ;
refRect . w = 0 ;
refRect . h = 0 ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* negative refRect */
refRect . x = SDLTest_RandomIntegerInRange ( - 200 , - 100 ) ;
refRect . y = SDLTest_RandomIntegerInRange ( - 200 , - 100 ) ;
refRect . w = 50 ;
refRect . h = 50 ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* oversized refRect */
refRect . x = SDLTest_RandomIntegerInRange ( 1 , 50 ) ;
refRect . y = SDLTest_RandomIntegerInRange ( 1 , 50 ) ;
refRect . w = 5000 ;
refRect . h = 5000 ;
2022-12-29 14:58:16 -07:00
testSetTextInputRect ( refRect ) ;
2022-11-30 13:51:59 -07:00
/* NULL refRect */
SDL_SetTextInputRect ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_SetTextInputRect(NULL) " ) ;
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_SetTextInputRect with invalid data
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_SetTextInputRect
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_setTextInputRectNegative ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
/* Some platforms set also an error message; prepare for checking it */
2023-03-29 15:49:01 -06:00
# if defined(SDL_VIDEO_DRIVER_WINDOWS) || defined(SDL_VIDEO_DRIVER_ANDROID) || defined(SDL_VIDEO_DRIVER_COCOA)
2022-11-30 13:51:59 -07:00
const char * expectedError = " Parameter 'rect' is invalid " ;
const char * error ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
2015-06-21 09:33:46 -06:00
# endif
2022-11-30 13:51:59 -07:00
/* NULL refRect */
SDL_SetTextInputRect ( NULL ) ;
SDLTest_AssertPass ( " Call to SDL_SetTextInputRect(NULL) " ) ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
/* Some platforms set also an error message; so check it */
2023-03-29 15:49:01 -06:00
# if defined(SDL_VIDEO_DRIVER_WINDOWS) || defined(SDL_VIDEO_DRIVER_ANDROID) || defined(SDL_VIDEO_DRIVER_COCOA)
2022-11-30 13:51:59 -07:00
error = SDL_GetError ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetError() " ) ;
SDLTest_AssertCheck ( error ! = NULL , " Validate that error message was not NULL " ) ;
if ( error ! = NULL ) {
SDLTest_AssertCheck ( SDL_strcmp ( error , expectedError ) = = 0 ,
" Validate error message, expected: '%s', got: '%s' " , expectedError , error ) ;
}
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
2015-06-21 09:33:46 -06:00
# endif
2022-11-30 13:51:59 -07:00
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetScancodeFromKey
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetScancodeFromKey
* \ sa SDL_Keycode
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getScancodeFromKey ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Scancode scancode ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
/* Regular key */
scancode = SDL_GetScancodeFromKey ( SDLK_4 ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromKey(SDLK_4) " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_4 , " Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i " , SDL_SCANCODE_4 , scancode ) ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
/* Virtual key */
scancode = SDL_GetScancodeFromKey ( SDLK_PLUS ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromKey(SDLK_PLUS) " ) ;
SDLTest_AssertCheck ( scancode = = 0 , " Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i " , scancode ) ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetScancodeFromName
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetScancodeFromName
* \ sa SDL_Keycode
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getScancodeFromName ( void * arg )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
SDL_Scancode scancode ;
/* Regular key, 1 character, first name in list */
scancode = SDL_GetScancodeFromName ( " A " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('A') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_A , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_A , scancode ) ;
/* Regular key, 1 character */
scancode = SDL_GetScancodeFromName ( " 4 " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('4') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_4 , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_4 , scancode ) ;
/* Regular key, 2 characters */
scancode = SDL_GetScancodeFromName ( " F1 " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('F1') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_F1 , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_F1 , scancode ) ;
/* Regular key, 3 characters */
scancode = SDL_GetScancodeFromName ( " End " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('End') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_END , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_END , scancode ) ;
/* Regular key, 4 characters */
scancode = SDL_GetScancodeFromName ( " Find " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('Find') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_FIND , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_FIND , scancode ) ;
/* Regular key, several characters */
scancode = SDL_GetScancodeFromName ( " Backspace " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('Backspace') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_BACKSPACE , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_BACKSPACE , scancode ) ;
/* Regular key, several characters with space */
scancode = SDL_GetScancodeFromName ( " Keypad Enter " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('Keypad Enter') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_KP_ENTER , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_KP_ENTER , scancode ) ;
/* Regular key, last name in list */
scancode = SDL_GetScancodeFromName ( " Sleep " ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('Sleep') " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_SLEEP , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_SLEEP , scancode ) ;
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/*
* Local helper to check for the invalid scancode error message
*/
2023-03-08 08:12:45 -07:00
static void checkInvalidNameError ( void )
2015-06-21 09:33:46 -06:00
{
2022-11-30 13:51:59 -07:00
const char * expectedError = " Parameter 'name' is invalid " ;
const char * error ;
error = SDL_GetError ( ) ;
SDLTest_AssertPass ( " Call to SDL_GetError() " ) ;
SDLTest_AssertCheck ( error ! = NULL , " Validate that error message was not NULL " ) ;
if ( error ! = NULL ) {
SDLTest_AssertCheck ( SDL_strcmp ( error , expectedError ) = = 0 ,
" Validate error message, expected: '%s', got: '%s' " , expectedError , error ) ;
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
}
2015-06-21 09:33:46 -06:00
}
/**
2023-11-06 08:26:06 -07:00
* Check call to SDL_GetScancodeFromName with invalid data
2015-06-21 09:33:46 -06:00
*
2023-02-01 16:21:53 -07:00
* \ sa SDL_GetScancodeFromName
* \ sa SDL_Keycode
2015-06-21 09:33:46 -06:00
*/
2023-03-08 08:12:45 -07:00
static int keyboard_getScancodeFromNameNegative ( void * arg )
2015-06-21 09:33:46 -06:00
{
2023-03-08 13:18:02 -07:00
char * name ;
2022-11-30 13:51:59 -07:00
SDL_Scancode scancode ;
/* Clear error message */
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " Call to SDL_ClearError() " ) ;
/* Random string input */
name = SDLTest_RandomAsciiStringOfSize ( 32 ) ;
SDLTest_Assert ( name ! = NULL , " Check that random name is not NULL " ) ;
if ( name = = NULL ) {
return TEST_ABORTED ;
}
scancode = SDL_GetScancodeFromName ( name ) ;
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName('%s') " , name ) ;
2023-03-08 13:18:02 -07:00
SDL_free ( name ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_UNKNOWN , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_UNKNOWN , scancode ) ;
2022-12-29 14:58:16 -07:00
checkInvalidNameError ( ) ;
2022-11-30 13:51:59 -07:00
/* Zero length string input */
name = " " ;
2022-12-01 14:07:03 -07:00
scancode = SDL_GetScancodeFromName ( name ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName(NULL) " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_UNKNOWN , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_UNKNOWN , scancode ) ;
2022-12-29 14:58:16 -07:00
checkInvalidNameError ( ) ;
2022-11-30 13:51:59 -07:00
/* NULL input */
name = NULL ;
2022-12-01 14:07:03 -07:00
scancode = SDL_GetScancodeFromName ( name ) ;
2022-11-30 13:51:59 -07:00
SDLTest_AssertPass ( " Call to SDL_GetScancodeFromName(NULL) " ) ;
SDLTest_AssertCheck ( scancode = = SDL_SCANCODE_UNKNOWN , " Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i " , SDL_SCANCODE_UNKNOWN , scancode ) ;
2022-12-29 14:58:16 -07:00
checkInvalidNameError ( ) ;
2022-11-30 13:51:59 -07:00
return TEST_COMPLETED ;
2015-06-21 09:33:46 -06:00
}
/* ================= Test References ================== */
/* Keyboard test cases */
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest1 = {
( SDLTest_TestCaseFp ) keyboard_getKeyboardState , " keyboard_getKeyboardState " , " Check call to SDL_GetKeyboardState with and without numkeys reference " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest2 = {
( SDLTest_TestCaseFp ) keyboard_getKeyboardFocus , " keyboard_getKeyboardFocus " , " Check call to SDL_GetKeyboardFocus " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest3 = {
( SDLTest_TestCaseFp ) keyboard_getKeyFromName , " keyboard_getKeyFromName " , " Check call to SDL_GetKeyFromName for known, unknown and invalid name " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest4 = {
( SDLTest_TestCaseFp ) keyboard_getKeyFromScancode , " keyboard_getKeyFromScancode " , " Check call to SDL_GetKeyFromScancode " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest5 = {
( SDLTest_TestCaseFp ) keyboard_getKeyName , " keyboard_getKeyName " , " Check call to SDL_GetKeyName " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest6 = {
( SDLTest_TestCaseFp ) keyboard_getSetModState , " keyboard_getSetModState " , " Check call to SDL_GetModState and SDL_SetModState " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest7 = {
( SDLTest_TestCaseFp ) keyboard_startStopTextInput , " keyboard_startStopTextInput " , " Check call to SDL_StartTextInput and SDL_StopTextInput " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest8 = {
( SDLTest_TestCaseFp ) keyboard_setTextInputRect , " keyboard_setTextInputRect " , " Check call to SDL_SetTextInputRect " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest9 = {
( SDLTest_TestCaseFp ) keyboard_setTextInputRectNegative , " keyboard_setTextInputRectNegative " , " Check call to SDL_SetTextInputRect with invalid data " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest10 = {
( SDLTest_TestCaseFp ) keyboard_getScancodeFromKey , " keyboard_getScancodeFromKey " , " Check call to SDL_GetScancodeFromKey " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest11 = {
( SDLTest_TestCaseFp ) keyboard_getScancodeFromName , " keyboard_getScancodeFromName " , " Check call to SDL_GetScancodeFromName " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest12 = {
( SDLTest_TestCaseFp ) keyboard_getScancodeFromNameNegative , " keyboard_getScancodeFromNameNegative " , " Check call to SDL_GetScancodeFromName with invalid data " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest13 = {
( SDLTest_TestCaseFp ) keyboard_getKeyNameNegative , " keyboard_getKeyNameNegative " , " Check call to SDL_GetKeyName with invalid data " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference keyboardTest14 = {
( SDLTest_TestCaseFp ) keyboard_getScancodeNameNegative , " keyboard_getScancodeNameNegative " , " Check call to SDL_GetScancodeName with invalid data " , TEST_ENABLED
} ;
2015-06-21 09:33:46 -06:00
/* Sequence of Keyboard test cases */
2022-11-30 13:51:59 -07:00
static const SDLTest_TestCaseReference * keyboardTests [ ] = {
2015-06-21 09:33:46 -06:00
& keyboardTest1 , & keyboardTest2 , & keyboardTest3 , & keyboardTest4 , & keyboardTest5 , & keyboardTest6 ,
& keyboardTest7 , & keyboardTest8 , & keyboardTest9 , & keyboardTest10 , & keyboardTest11 , & keyboardTest12 ,
& keyboardTest13 , & keyboardTest14 , NULL
} ;
/* Keyboard test suite (global) */
SDLTest_TestSuiteReference keyboardTestSuite = {
" Keyboard " ,
NULL ,
keyboardTests ,
NULL
} ;