testautomation_keyboard.c
Go to the documentation of this file.
/**
* Keyboard test suite
*/
#include <stdio.h>
#include <limits.h>
#include "SDL_config.h"
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
/* Test case functions */
/**
* @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
*/
int
keyboard_getKeyboardState(void *arg)
{
int numkeys;
Uint8 *state;
/* Case where numkeys pointer is NULL */
state = (Uint8 *)SDL_GetKeyboardState(NULL);
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;
state = (Uint8 *)SDL_GetKeyboardState(&numkeys);
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;
}
/**
* @brief Check call to SDL_GetKeyboardFocus
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus
*/
int
keyboard_getKeyboardFocus(void *arg)
{
SDL_Window* window;
/* Call, but ignore return value */
window = SDL_GetKeyboardFocus();
SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName
*/
int
keyboard_getKeyFromName(void *arg)
{
SDL_Keycode result;
/* Case where Key is known, 1 character input */
result = SDL_GetKeyFromName("A");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/single)");
SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
/* Case where Key is known, 2 character input */
result = SDL_GetKeyFromName("F1");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %i", SDLK_F1, result);
/* Case where Key is known, 3 character input */
result = SDL_GetKeyFromName("End");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %i", SDLK_END, result);
/* Case where Key is known, 4 character input */
result = SDL_GetKeyFromName("Find");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %i", SDLK_FIND, result);
/* Case where Key is known, multiple character input */
result = SDL_GetKeyFromName("AudioStop");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %i", SDLK_AUDIOSTOP, result);
/* Case where Key is unknown */
result = SDL_GetKeyFromName("NotThere");
SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
/* Case where input is NULL/invalid */
result = SDL_GetKeyFromName(NULL);
SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
return TEST_COMPLETED;
}
/*
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidScancodeError()
{
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()");
}
}
/**
* @brief Check call to SDL_GetKeyFromScancode
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
*/
int
keyboard_getKeyFromScancode(void *arg)
{
SDL_Keycode result;
/* Case where input is valid */
result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
/* Case where input is zero */
result = SDL_GetKeyFromScancode(0);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
/* 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)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
_checkInvalidScancodeError();
/* Case where input is invalid (too big) */
result = SDL_GetKeyFromScancode(999);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
_checkInvalidScancodeError();
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_GetKeyName
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
*/
int
keyboard_getKeyName(void *arg)
{
char *result;
char *expected;
/* Case where key has a 1 character name */
expected = "3";
result = (char *)SDL_GetKeyName(SDLK_3);
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";
result = (char *)SDL_GetKeyName(SDLK_F1);
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";
result = (char *)SDL_GetKeyName(SDLK_CUT);
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";
result = (char *)SDL_GetKeyName(SDLK_DOWN);
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";
result = (char *)SDL_GetKeyName(SDLK_BRIGHTNESSUP);
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";
result = (char *)SDL_GetKeyName(SDLK_KP_MEMSTORE);
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;
}
/**
* @brief SDL_GetScancodeName negative cases
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName
*/
int
keyboard_getScancodeNameNegative(void *arg)
{
SDL_Scancode scancode;
char *result;
char *expected = "";
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Out-of-bounds scancode */
scancode = (SDL_Scancode)SDL_NUM_SCANCODES;
result = (char *)SDL_GetScancodeName(scancode);
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);
_checkInvalidScancodeError();
return TEST_COMPLETED;
}
/**
* @brief SDL_GetKeyName negative cases
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
*/
int
keyboard_getKeyNameNegative(void *arg)
{
SDL_Keycode keycode;
char *result;
char *expected = "";
/* Unknown keycode */
keycode = SDLK_UNKNOWN;
result = (char *)SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode);
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);
result = (char *)SDL_GetKeyName(keycode);
SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode);
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);
_checkInvalidScancodeError();
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_GetModState and SDL_SetModState
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
*/
int
keyboard_getSetModState(void *arg)
{
SDL_Keymod result;
SDL_Keymod currentState;
SDL_Keymod newState;
SDL_Keymod allStates =
KMOD_NONE |
KMOD_LSHIFT |
KMOD_RSHIFT |
KMOD_LCTRL |
KMOD_RCTRL |
KMOD_LALT |
KMOD_RALT |
KMOD_LGUI |
KMOD_RGUI |
KMOD_NUM |
KMOD_CAPS |
KMOD_MODE |
KMOD_RESERVED;
/* 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;
}
/**
* @brief Check call to SDL_StartTextInput and SDL_StopTextInput
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput
*/
int
keyboard_startStopTextInput(void *arg)
{
/* 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;
}
/* Internal function to test SDL_SetTextInputRect */
void _testSetTextInputRect(SDL_Rect refRect)
{
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);
}
/**
* @brief Check call to SDL_SetTextInputRect
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
*/
int
keyboard_setTextInputRect(void *arg)
{
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);
_testSetTextInputRect(refRect);
/* Normal visible refRect, origin 0,0 */
refRect.x = 0;
refRect.y = 0;
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
_testSetTextInputRect(refRect);
/* 1Pixel refRect */
refRect.x = SDLTest_RandomIntegerInRange(10, 50);;
refRect.y = SDLTest_RandomIntegerInRange(10, 50);;
refRect.w = 1;
refRect.h = 1;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 1;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 1;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* 0pixel refRect */
refRect.x = 0;
refRect.y = 0;
refRect.w = 0;
refRect.h = 0;
_testSetTextInputRect(refRect);
/* negative refRect */
refRect.x = SDLTest_RandomIntegerInRange(-200, -100);;
refRect.y = SDLTest_RandomIntegerInRange(-200, -100);;
refRect.w = 50;
refRect.h = 50;
_testSetTextInputRect(refRect);
/* oversized refRect */
refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
refRect.w = 5000;
refRect.h = 5000;
_testSetTextInputRect(refRect);
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_SetTextInputRect with invalid data
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
*/
int
keyboard_setTextInputRectNegative(void *arg)
{
/* Some platforms set also an error message; prepare for checking it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
const char *expectedError = "Parameter 'rect' is invalid";
const char *error;
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
#endif
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
/* Some platforms set also an error message; so check it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
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()");
#endif
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_GetScancodeFromKey
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
*/
int
keyboard_getScancodeFromKey(void *arg)
{
SDL_Scancode scancode;
/* 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);
/* 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);
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_GetScancodeFromName
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
*/
int
keyboard_getScancodeFromName(void *arg)
{
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;
}
/*
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidNameError()
{
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()");
}
}
/**
* @brief Check call to SDL_GetScancodeFromName with invalid data
*
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
*/
int
keyboard_getScancodeFromNameNegative(void *arg)
{
char *name;
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((const char *)name);
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
SDL_free(name);
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
_checkInvalidNameError();
/* Zero length string input */
name = "";
scancode = SDL_GetScancodeFromName((const char *)name);
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);
_checkInvalidNameError();
/* NULL input */
name = NULL;
scancode = SDL_GetScancodeFromName((const char *)name);
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);
_checkInvalidNameError();
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Keyboard test cases */
static const SDLTest_TestCaseReference keyboardTest1 =
{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest2 =
{ (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest3 =
{ (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest4 =
{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest5 =
{ (SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest6 =
{ (SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest7 =
{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest8 =
{ (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest9 =
{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest10 =
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest11 =
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest12 =
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest13 =
{ (SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED };
static const SDLTest_TestCaseReference keyboardTest14 =
{ (SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED };
/* Sequence of Keyboard test cases */
static const SDLTest_TestCaseReference *keyboardTests[] = {
&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
};
SDL_test.h
SDL_ClearError
#define SDL_ClearError
Definition: SDL_dynapi_overrides.h:120
SDL_SCANCODE_KP_ENTER
Definition: SDL_scancode.h:187
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:119
KMOD_LCTRL
Definition: SDL_keycode.h:322
TEST_ABORTED
#define TEST_ABORTED
Definition: SDL_test_harness.h:51
keyboardTest1
static const SDLTest_TestCaseReference keyboardTest1
Definition: testautomation_keyboard.c:658
keyboardTest8
static const SDLTest_TestCaseReference keyboardTest8
Definition: testautomation_keyboard.c:679
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
SDLTest_TestSuiteReference
Definition: SDL_test_harness.h:89
keyboard_getScancodeFromNameNegative
int keyboard_getScancodeFromNameNegative(void *arg)
Check call to SDL_GetScancodeFromName with invalid data.
Definition: testautomation_keyboard.c:615
SDLK_KP_MEMSTORE
Definition: SDL_keycode.h:255
keyboard_setTextInputRect
int keyboard_setTextInputRect(void *arg)
Check call to SDL_SetTextInputRect.
Definition: testautomation_keyboard.c:399
keyboardTest9
static const SDLTest_TestCaseReference keyboardTest9
Definition: testautomation_keyboard.c:682
SDLTest_RandomIntegerInRange
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
Definition: SDL_test_fuzzer.c:156
SDL_GetKeyFromScancode
#define SDL_GetKeyFromScancode
Definition: SDL_dynapi_overrides.h:226
KMOD_RCTRL
Definition: SDL_keycode.h:323
keyboard_setTextInputRectNegative
int keyboard_setTextInputRectNegative(void *arg)
Check call to SDL_SetTextInputRect with invalid data.
Definition: testautomation_keyboard.c:479
KMOD_RESERVED
Definition: SDL_keycode.h:331
SDLTest_AssertPass
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
Definition: SDL_test_assert.c:94
KMOD_LSHIFT
Definition: SDL_keycode.h:320
window
SDL_Window * window
Definition: testautomation_render.c:26
SDLK_a
Definition: SDL_keycode.h:97
SDL_SCANCODE_4
Definition: SDL_scancode.h:84
state
struct xkb_state * state
Definition: SDL_waylandsym.h:94
SDLTest_Assert
void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert that logs and break execution flow on failures.
Definition: SDL_test_assert.c:47
keyboardTest14
static const SDLTest_TestCaseReference keyboardTest14
Definition: testautomation_keyboard.c:697
SDLK_END
Definition: SDL_keycode.h:146
SDL_SetModState
#define SDL_SetModState
Definition: SDL_dynapi_overrides.h:225
SDL_SCANCODE_FIND
Definition: SDL_scancode.h:237
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_GetKeyboardFocus
#define SDL_GetKeyboardFocus
Definition: SDL_dynapi_overrides.h:222
keyboard_getSetModState
int keyboard_getSetModState(void *arg)
Check call to SDL_GetModState and SDL_SetModState.
Definition: testautomation_keyboard.c:292
SDL_SCANCODE_SLEEP
Definition: SDL_scancode.h:386
SDL_Keycode
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:42
SDLK_3
Definition: SDL_keycode.h:74
keyboard_getKeyNameNegative
int keyboard_getKeyNameNegative(void *arg)
SDL_GetKeyName negative cases.
Definition: testautomation_keyboard.c:254
SDL_config.h
KMOD_NONE
Definition: SDL_keycode.h:319
SDLK_PLUS
Definition: SDL_keycode.h:66
keyboardTestSuite
SDLTest_TestSuiteReference keyboardTestSuite
Definition: testautomation_keyboard.c:708
SDL_GetScancodeFromName
#define SDL_GetScancodeFromName
Definition: SDL_dynapi_overrides.h:229
SDLK_CUT
Definition: SDL_keycode.h:193
_checkInvalidNameError
void _checkInvalidNameError()
Definition: testautomation_keyboard.c:593
KMOD_RGUI
Definition: SDL_keycode.h:327
SDLTest_TestCaseFp
int(* SDLTest_TestCaseFp)(void *arg)
Definition: SDL_test_harness.h:67
SDL_GetScancodeFromKey
#define SDL_GetScancodeFromKey
Definition: SDL_dynapi_overrides.h:227
SDLK_BRIGHTNESSUP
Definition: SDL_keycode.h:304
SDLTest_RandomAsciiStringOfSize
char * SDLTest_RandomAsciiStringOfSize(int size)
Definition: SDL_test_fuzzer.c:500
SDL_StopTextInput
#define SDL_StopTextInput
Definition: SDL_dynapi_overrides.h:234
SDL_SCANCODE_A
Definition: SDL_scancode.h:54
keyboard_getScancodeNameNegative
int keyboard_getScancodeNameNegative(void *arg)
SDL_GetScancodeName negative cases.
Definition: testautomation_keyboard.c:227
keyboard_getScancodeFromKey
int keyboard_getScancodeFromKey(void *arg)
Check call to SDL_GetScancodeFromKey.
Definition: testautomation_keyboard.c:518
keyboardTest7
static const SDLTest_TestCaseReference keyboardTest7
Definition: testautomation_keyboard.c:676
SDL_GetKeyboardState
#define SDL_GetKeyboardState
Definition: SDL_dynapi_overrides.h:223
_checkInvalidScancodeError
void _checkInvalidScancodeError()
Definition: testautomation_keyboard.c:111
SDLTest_AssertCheck
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
Definition: SDL_test_assert.c:65
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
keyboard_getKeyboardState
int keyboard_getKeyboardState(void *arg)
Check call to SDL_GetKeyboardState with and without numkeys reference.
Definition: testautomation_keyboard.c:22
SDL_free
void SDL_free(void *mem)
KMOD_CAPS
Definition: SDL_keycode.h:329
KMOD_MODE
Definition: SDL_keycode.h:330
keyboardTest4
static const SDLTest_TestCaseReference keyboardTest4
Definition: testautomation_keyboard.c:667
keyboardTest11
static const SDLTest_TestCaseReference keyboardTest11
Definition: testautomation_keyboard.c:688
KMOD_NUM
Definition: SDL_keycode.h:328
keyboard_getKeyFromScancode
int keyboard_getKeyFromScancode(void *arg)
Check call to SDL_GetKeyFromScancode.
Definition: testautomation_keyboard.c:132
keyboard_getScancodeFromName
int keyboard_getScancodeFromName(void *arg)
Check call to SDL_GetScancodeFromName.
Definition: testautomation_keyboard.c:542
keyboard_getKeyboardFocus
int keyboard_getKeyboardFocus(void *arg)
Check call to SDL_GetKeyboardFocus.
Definition: testautomation_keyboard.c:48
SDL_Rect::x
int x
Definition: SDL_rect.h:66
TEST_COMPLETED
#define TEST_COMPLETED
Definition: SDL_test_harness.h:53
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_SCANCODE_BACKSPACE
Definition: SDL_scancode.h:94
SDL_StartTextInput
#define SDL_StartTextInput
Definition: SDL_dynapi_overrides.h:232
SDL_Keymod
SDL_Keymod
Enumeration of valid key mods (possibly OR&#39;d together).
Definition: SDL_keycode.h:317
TEST_ENABLED
#define TEST_ENABLED
Definition: SDL_test_harness.h:47
keyboard_getKeyFromName
int keyboard_getKeyFromName(void *arg)
Check call to SDL_GetKeyFromName for known, unknown and invalid name.
Definition: testautomation_keyboard.c:65
keyboardTest12
static const SDLTest_TestCaseReference keyboardTest12
Definition: testautomation_keyboard.c:691
keyboardTest13
static const SDLTest_TestCaseReference keyboardTest13
Definition: testautomation_keyboard.c:694
_testSetTextInputRect
void _testSetTextInputRect(SDL_Rect refRect)
Definition: testautomation_keyboard.c:379
NULL
#define NULL
Definition: begin_code.h:143
SDL_SCANCODE_UNKNOWN
Definition: SDL_scancode.h:45
SDLK_UNKNOWN
Definition: SDL_keycode.h:49
SDL_GetScancodeName
#define SDL_GetScancodeName
Definition: SDL_dynapi_overrides.h:228
KMOD_LGUI
Definition: SDL_keycode.h:326
SDL_SetTextInputRect
#define SDL_SetTextInputRect
Definition: SDL_dynapi_overrides.h:235
keyboardTests
static const SDLTest_TestCaseReference * keyboardTests[]
Definition: testautomation_keyboard.c:701
SDLK_AUDIOSTOP
Definition: SDL_keycode.h:286
SDLK_F1
Definition: SDL_keycode.h:126
SDLK_DOWN
Definition: SDL_keycode.h:150
keyboardTest3
static const SDLTest_TestCaseReference keyboardTest3
Definition: testautomation_keyboard.c:664
keyboard_startStopTextInput
int keyboard_startStopTextInput(void *arg)
Check call to SDL_StartTextInput and SDL_StopTextInput.
Definition: testautomation_keyboard.c:353
KMOD_LALT
Definition: SDL_keycode.h:324
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDLTest_TestCaseReference
Definition: SDL_test_harness.h:75
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_GetKeyFromName
#define SDL_GetKeyFromName
Definition: SDL_dynapi_overrides.h:231
SDL_NUM_SCANCODES
Definition: SDL_scancode.h:395
KMOD_RALT
Definition: SDL_keycode.h:325
keyboardTest10
static const SDLTest_TestCaseReference keyboardTest10
Definition: testautomation_keyboard.c:685
SDL_GetKeyName
#define SDL_GetKeyName
Definition: SDL_dynapi_overrides.h:230
SDLK_FIND
Definition: SDL_keycode.h:196
SDL_SCANCODE_F1
Definition: SDL_scancode.h:153
keyboard_getKeyName
int keyboard_getKeyName(void *arg)
Check call to SDL_GetKeyName.
Definition: testautomation_keyboard.c:171
SDL_SCANCODE_END
Definition: SDL_scancode.h:174
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:423
keyboardTest2
static const SDLTest_TestCaseReference keyboardTest2
Definition: testautomation_keyboard.c:661
SDL.h
KMOD_RSHIFT
Definition: SDL_keycode.h:321
SDL_GetModState
#define SDL_GetModState
Definition: SDL_dynapi_overrides.h:224
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_Scancode
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
keyboardTest6
static const SDLTest_TestCaseReference keyboardTest6
Definition: testautomation_keyboard.c:673
SDLK_4
Definition: SDL_keycode.h:75
keyboardTest5
static const SDLTest_TestCaseReference keyboardTest5
Definition: testautomation_keyboard.c:670