SDL 2.0
testautomation_keyboard.c File Reference
#include <stdio.h>
#include <limits.h>
#include "SDL_config.h"
#include "SDL.h"
#include "SDL_test.h"
+ Include dependency graph for testautomation_keyboard.c:

Go to the source code of this file.

Functions

int keyboard_getKeyboardState (void *arg)
 Check call to SDL_GetKeyboardState with and without numkeys reference. More...
 
int keyboard_getKeyboardFocus (void *arg)
 Check call to SDL_GetKeyboardFocus. More...
 
int keyboard_getKeyFromName (void *arg)
 Check call to SDL_GetKeyFromName for known, unknown and invalid name. More...
 
void _checkInvalidScancodeError ()
 
int keyboard_getKeyFromScancode (void *arg)
 Check call to SDL_GetKeyFromScancode. More...
 
int keyboard_getKeyName (void *arg)
 Check call to SDL_GetKeyName. More...
 
int keyboard_getScancodeNameNegative (void *arg)
 SDL_GetScancodeName negative cases. More...
 
int keyboard_getKeyNameNegative (void *arg)
 SDL_GetKeyName negative cases. More...
 
int keyboard_getSetModState (void *arg)
 Check call to SDL_GetModState and SDL_SetModState. More...
 
int keyboard_startStopTextInput (void *arg)
 Check call to SDL_StartTextInput and SDL_StopTextInput. More...
 
void _testSetTextInputRect (SDL_Rect refRect)
 
int keyboard_setTextInputRect (void *arg)
 Check call to SDL_SetTextInputRect. More...
 
int keyboard_setTextInputRectNegative (void *arg)
 Check call to SDL_SetTextInputRect with invalid data. More...
 
int keyboard_getScancodeFromKey (void *arg)
 Check call to SDL_GetScancodeFromKey. More...
 
int keyboard_getScancodeFromName (void *arg)
 Check call to SDL_GetScancodeFromName. More...
 
void _checkInvalidNameError ()
 
int keyboard_getScancodeFromNameNegative (void *arg)
 Check call to SDL_GetScancodeFromName with invalid data. More...
 

Variables

static const SDLTest_TestCaseReference keyboardTest1
 
static const SDLTest_TestCaseReference keyboardTest2
 
static const SDLTest_TestCaseReference keyboardTest3
 
static const SDLTest_TestCaseReference keyboardTest4
 
static const SDLTest_TestCaseReference keyboardTest5
 
static const SDLTest_TestCaseReference keyboardTest6
 
static const SDLTest_TestCaseReference keyboardTest7
 
static const SDLTest_TestCaseReference keyboardTest8
 
static const SDLTest_TestCaseReference keyboardTest9
 
static const SDLTest_TestCaseReference keyboardTest10
 
static const SDLTest_TestCaseReference keyboardTest11
 
static const SDLTest_TestCaseReference keyboardTest12
 
static const SDLTest_TestCaseReference keyboardTest13
 
static const SDLTest_TestCaseReference keyboardTest14
 
static const SDLTest_TestCaseReferencekeyboardTests []
 
SDLTest_TestSuiteReference keyboardTestSuite
 

Function Documentation

◆ _checkInvalidNameError()

void _checkInvalidNameError ( )

Definition at line 593 of file testautomation_keyboard.c.

594{
595 const char *expectedError = "Parameter 'name' is invalid";
596 const char *error;
597 error = SDL_GetError();
598 SDLTest_AssertPass("Call to SDL_GetError()");
599 SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
600 if (error != NULL) {
601 SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
602 "Validate error message, expected: '%s', got: '%s'", expectedError, error);
604 SDLTest_AssertPass("Call to SDL_ClearError()");
605 }
606}
#define SDL_GetError
#define SDL_ClearError
#define SDL_strcmp
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.
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...
#define NULL
Definition: begin_code.h:167

References NULL, SDL_ClearError, SDL_GetError, SDL_strcmp, SDLTest_AssertCheck(), and SDLTest_AssertPass().

Referenced by keyboard_getScancodeFromNameNegative().

◆ _checkInvalidScancodeError()

void _checkInvalidScancodeError ( )

Definition at line 111 of file testautomation_keyboard.c.

112{
113 const char *expectedError = "Parameter 'scancode' is invalid";
114 const char *error;
115 error = SDL_GetError();
116 SDLTest_AssertPass("Call to SDL_GetError()");
117 SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
118 if (error != NULL) {
119 SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
120 "Validate error message, expected: '%s', got: '%s'", expectedError, error);
122 SDLTest_AssertPass("Call to SDL_ClearError()");
123 }
124}

References NULL, SDL_ClearError, SDL_GetError, SDL_strcmp, SDLTest_AssertCheck(), and SDLTest_AssertPass().

Referenced by keyboard_getKeyFromScancode(), keyboard_getKeyNameNegative(), and keyboard_getScancodeNameNegative().

◆ _testSetTextInputRect()

void _testSetTextInputRect ( SDL_Rect  refRect)

Definition at line 379 of file testautomation_keyboard.c.

380{
381 SDL_Rect testRect;
382
383 testRect = refRect;
384 SDL_SetTextInputRect(&testRect);
385 SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i)", refRect.x, refRect.y, refRect.w, refRect.h);
387 (refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h),
388 "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",
389 refRect.x, refRect.y, refRect.w, refRect.h,
390 testRect.x, testRect.y, testRect.w, testRect.h);
391}
#define SDL_SetTextInputRect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79

References SDL_Rect::h, SDL_SetTextInputRect, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by keyboard_setTextInputRect().

◆ keyboard_getKeyboardFocus()

int keyboard_getKeyboardFocus ( void arg)

Check call to SDL_GetKeyboardFocus.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus

Definition at line 48 of file testautomation_keyboard.c.

49{
51
52 /* Call, but ignore return value */
54 SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
55
56 return TEST_COMPLETED;
57}
#define SDL_GetKeyboardFocus
#define TEST_COMPLETED
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:74

References SDL_GetKeyboardFocus, SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_getKeyboardState()

int keyboard_getKeyboardState ( void arg)

Check call to SDL_GetKeyboardState with and without numkeys reference.

Keyboard test suite

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState

Definition at line 22 of file testautomation_keyboard.c.

23{
24 int numkeys;
25 Uint8 *state;
26
27 /* Case where numkeys pointer is NULL */
29 SDLTest_AssertPass("Call to SDL_GetKeyboardState(NULL)");
30 SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
31
32 /* Case where numkeys pointer is not NULL */
33 numkeys = -1;
34 state = (Uint8 *)SDL_GetKeyboardState(&numkeys);
35 SDLTest_AssertPass("Call to SDL_GetKeyboardState(&numkeys)");
36 SDLTest_AssertCheck(state != NULL, "Validate that return value from SDL_GetKeyboardState is not NULL");
37 SDLTest_AssertCheck(numkeys >= 0, "Validate that value of numkeys is >= 0, got: %i", numkeys);
38
39 return TEST_COMPLETED;
40}
#define SDL_GetKeyboardState
uint8_t Uint8
Definition: SDL_stdinc.h:179
struct xkb_state * state

References NULL, SDL_GetKeyboardState, SDLTest_AssertCheck(), SDLTest_AssertPass(), state, and TEST_COMPLETED.

◆ keyboard_getKeyFromName()

int keyboard_getKeyFromName ( void arg)

Check call to SDL_GetKeyFromName for known, unknown and invalid name.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName

Definition at line 65 of file testautomation_keyboard.c.

66{
68
69 /* Case where Key is known, 1 character input */
71 SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/single)");
72 SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
73
74 /* Case where Key is known, 2 character input */
76 SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/double)");
77 SDLTest_AssertCheck(result == SDLK_F1, "Verify result from call, expected: %i, got: %i", SDLK_F1, result);
78
79 /* Case where Key is known, 3 character input */
81 SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/triple)");
82 SDLTest_AssertCheck(result == SDLK_END, "Verify result from call, expected: %i, got: %i", SDLK_END, result);
83
84 /* Case where Key is known, 4 character input */
85 result = SDL_GetKeyFromName("Find");
86 SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/quad)");
87 SDLTest_AssertCheck(result == SDLK_FIND, "Verify result from call, expected: %i, got: %i", SDLK_FIND, result);
88
89 /* Case where Key is known, multiple character input */
90 result = SDL_GetKeyFromName("AudioStop");
91 SDLTest_AssertPass("Call to SDL_GetKeyFromName(known/multi)");
92 SDLTest_AssertCheck(result == SDLK_AUDIOSTOP, "Verify result from call, expected: %i, got: %i", SDLK_AUDIOSTOP, result);
93
94 /* Case where Key is unknown */
95 result = SDL_GetKeyFromName("NotThere");
96 SDLTest_AssertPass("Call to SDL_GetKeyFromName(unknown)");
97 SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
98
99 /* Case where input is NULL/invalid */
101 SDLTest_AssertPass("Call to SDL_GetKeyFromName(NULL)");
102 SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
103
104 return TEST_COMPLETED;
105}
#define SDL_GetKeyFromName
@ SDLK_a
Definition: SDL_keycode.h:100
@ SDLK_F1
Definition: SDL_keycode.h:129
@ SDLK_AUDIOSTOP
Definition: SDL_keycode.h:289
@ SDLK_END
Definition: SDL_keycode.h:149
@ SDLK_FIND
Definition: SDL_keycode.h:199
@ SDLK_UNKNOWN
Definition: SDL_keycode.h:52
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:45
GLuint64EXT * result

References NULL, SDL_GetKeyFromName, SDLK_a, SDLK_AUDIOSTOP, SDLK_END, SDLK_F1, SDLK_FIND, SDLK_UNKNOWN, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_getKeyFromScancode()

int keyboard_getKeyFromScancode ( void arg)

Check call to SDL_GetKeyFromScancode.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode

Definition at line 132 of file testautomation_keyboard.c.

133{
135
136 /* Case where input is valid */
138 SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
139 SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %i", SDLK_a, result);
140
141 /* Case where input is zero */
143 SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
144 SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
145
146 /* Clear error message */
148 SDLTest_AssertPass("Call to SDL_ClearError()");
149
150 /* Case where input is invalid (too small) */
152 SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(-999)");
153 SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
155
156 /* Case where input is invalid (too big) */
158 SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
159 SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
161
162 return TEST_COMPLETED;
163}
#define SDL_GetKeyFromScancode
@ SDL_SCANCODE_A
Definition: SDL_scancode.h:54
void _checkInvalidScancodeError()

References _checkInvalidScancodeError(), SDL_ClearError, SDL_GetKeyFromScancode, SDL_SCANCODE_A, SDLK_a, SDLK_UNKNOWN, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_getKeyName()

int keyboard_getKeyName ( void arg)

Check call to SDL_GetKeyName.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName

Definition at line 171 of file testautomation_keyboard.c.

172{
173 char *result;
174 char *expected;
175
176 /* Case where key has a 1 character name */
177 expected = "3";
178 result = (char *)SDL_GetKeyName(SDLK_3);
179 SDLTest_AssertPass("Call to SDL_GetKeyName()");
180 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
181 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
182
183 /* Case where key has a 2 character name */
184 expected = "F1";
185 result = (char *)SDL_GetKeyName(SDLK_F1);
186 SDLTest_AssertPass("Call to SDL_GetKeyName()");
187 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
188 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
189
190 /* Case where key has a 3 character name */
191 expected = "Cut";
192 result = (char *)SDL_GetKeyName(SDLK_CUT);
193 SDLTest_AssertPass("Call to SDL_GetKeyName()");
194 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
195 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
196
197 /* Case where key has a 4 character name */
198 expected = "Down";
200 SDLTest_AssertPass("Call to SDL_GetKeyName()");
201 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
202 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
203
204 /* Case where key has a N character name */
205 expected = "BrightnessUp";
207 SDLTest_AssertPass("Call to SDL_GetKeyName()");
208 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
209 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
210
211 /* Case where key has a N character name with space */
212 expected = "Keypad MemStore";
214 SDLTest_AssertPass("Call to SDL_GetKeyName()");
215 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
216 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: %s, got: %s", expected, result);
217
218 return TEST_COMPLETED;
219}
#define SDL_GetKeyName
@ SDLK_KP_MEMSTORE
Definition: SDL_keycode.h:258
@ SDLK_DOWN
Definition: SDL_keycode.h:153
@ SDLK_BRIGHTNESSUP
Definition: SDL_keycode.h:307
@ SDLK_CUT
Definition: SDL_keycode.h:196
@ SDLK_3
Definition: SDL_keycode.h:77

References NULL, SDL_GetKeyName, SDL_strcmp, SDLK_3, SDLK_BRIGHTNESSUP, SDLK_CUT, SDLK_DOWN, SDLK_F1, SDLK_KP_MEMSTORE, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_getKeyNameNegative()

int keyboard_getKeyNameNegative ( void arg)

SDL_GetKeyName negative cases.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName

Definition at line 254 of file testautomation_keyboard.c.

255{
256 SDL_Keycode keycode;
257 char *result;
258 char *expected = "";
259
260 /* Unknown keycode */
261 keycode = SDLK_UNKNOWN;
262 result = (char *)SDL_GetKeyName(keycode);
263 SDLTest_AssertPass("Call to SDL_GetKeyName(%d/unknown)", keycode);
264 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
265 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
266
267 /* Clear error message */
269 SDLTest_AssertPass("Call to SDL_ClearError()");
270
271 /* Negative keycode */
272 keycode = (SDL_Keycode)SDLTest_RandomIntegerInRange(-255, -1);
273 result = (char *)SDL_GetKeyName(keycode);
274 SDLTest_AssertPass("Call to SDL_GetKeyName(%d/negative)", keycode);
275 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
276 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
278
280 SDLTest_AssertPass("Call to SDL_ClearError()");
281
282 return TEST_COMPLETED;
283}
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)

References _checkInvalidScancodeError(), NULL, SDL_ClearError, SDL_GetKeyName, SDL_strcmp, SDLK_UNKNOWN, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), and TEST_COMPLETED.

◆ keyboard_getScancodeFromKey()

int keyboard_getScancodeFromKey ( void arg)

Check call to SDL_GetScancodeFromKey.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
http://wiki.libsdl.org/moin.cgi/SDL_Keycode

Definition at line 518 of file testautomation_keyboard.c.

519{
520 SDL_Scancode scancode;
521
522 /* Regular key */
523 scancode = SDL_GetScancodeFromKey(SDLK_4);
524 SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
525 SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
526
527 /* Virtual key */
529 SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
530 SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode);
531
532 return TEST_COMPLETED;
533}
#define SDL_GetScancodeFromKey
@ SDLK_PLUS
Definition: SDL_keycode.h:69
@ SDLK_4
Definition: SDL_keycode.h:78
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:44
@ SDL_SCANCODE_4
Definition: SDL_scancode.h:84

References SDL_GetScancodeFromKey, SDL_SCANCODE_4, SDLK_4, SDLK_PLUS, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_getScancodeFromName()

int keyboard_getScancodeFromName ( void arg)

Check call to SDL_GetScancodeFromName.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
http://wiki.libsdl.org/moin.cgi/SDL_Keycode

Definition at line 542 of file testautomation_keyboard.c.

543{
544 SDL_Scancode scancode;
545
546 /* Regular key, 1 character, first name in list */
547 scancode = SDL_GetScancodeFromName("A");
548 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
549 SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode);
550
551 /* Regular key, 1 character */
552 scancode = SDL_GetScancodeFromName("4");
553 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
554 SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
555
556 /* Regular key, 2 characters */
557 scancode = SDL_GetScancodeFromName("F1");
558 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
559 SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode);
560
561 /* Regular key, 3 characters */
562 scancode = SDL_GetScancodeFromName("End");
563 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
564 SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode);
565
566 /* Regular key, 4 characters */
567 scancode = SDL_GetScancodeFromName("Find");
568 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
569 SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode);
570
571 /* Regular key, several characters */
572 scancode = SDL_GetScancodeFromName("Backspace");
573 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
574 SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode);
575
576 /* Regular key, several characters with space */
577 scancode = SDL_GetScancodeFromName("Keypad Enter");
578 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
579 SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode);
580
581 /* Regular key, last name in list */
582 scancode = SDL_GetScancodeFromName("Sleep");
583 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
584 SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode);
585
586 return TEST_COMPLETED;
587}
#define SDL_GetScancodeFromName
@ SDL_SCANCODE_END
Definition: SDL_scancode.h:174
@ SDL_SCANCODE_F1
Definition: SDL_scancode.h:153
@ SDL_SCANCODE_KP_ENTER
Definition: SDL_scancode.h:187
@ SDL_SCANCODE_FIND
Definition: SDL_scancode.h:237
@ SDL_SCANCODE_SLEEP
Definition: SDL_scancode.h:386
@ SDL_SCANCODE_BACKSPACE
Definition: SDL_scancode.h:94

References SDL_GetScancodeFromName, SDL_SCANCODE_4, SDL_SCANCODE_A, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_END, SDL_SCANCODE_F1, SDL_SCANCODE_FIND, SDL_SCANCODE_KP_ENTER, SDL_SCANCODE_SLEEP, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_getScancodeFromNameNegative()

int keyboard_getScancodeFromNameNegative ( void arg)

Check call to SDL_GetScancodeFromName with invalid data.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
http://wiki.libsdl.org/moin.cgi/SDL_Keycode

Definition at line 615 of file testautomation_keyboard.c.

616{
617 char *name;
618 SDL_Scancode scancode;
619
620 /* Clear error message */
622 SDLTest_AssertPass("Call to SDL_ClearError()");
623
624 /* Random string input */
626 SDLTest_Assert(name != NULL, "Check that random name is not NULL");
627 if (name == NULL) {
628 return TEST_ABORTED;
629 }
630 scancode = SDL_GetScancodeFromName((const char *)name);
631 SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
632 SDL_free(name);
633 SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
635
636 /* Zero length string input */
637 name = "";
638 scancode = SDL_GetScancodeFromName((const char *)name);
639 SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
640 SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
642
643 /* NULL input */
644 name = NULL;
645 scancode = SDL_GetScancodeFromName((const char *)name);
646 SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
647 SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
649
650 return TEST_COMPLETED;
651}
#define SDL_free
GLuint const GLchar * name
@ SDL_SCANCODE_UNKNOWN
Definition: SDL_scancode.h:45
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.
char * SDLTest_RandomAsciiStringOfSize(int size)
#define TEST_ABORTED
void _checkInvalidNameError()

References _checkInvalidNameError(), NULL, SDL_ClearError, SDL_free, SDL_GetScancodeFromName, SDL_SCANCODE_UNKNOWN, SDLTest_Assert(), SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomAsciiStringOfSize(), TEST_ABORTED, and TEST_COMPLETED.

◆ keyboard_getScancodeNameNegative()

int keyboard_getScancodeNameNegative ( void arg)

SDL_GetScancodeName negative cases.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName

Definition at line 227 of file testautomation_keyboard.c.

228{
229 SDL_Scancode scancode;
230 char *result;
231 char *expected = "";
232
233 /* Clear error message */
235 SDLTest_AssertPass("Call to SDL_ClearError()");
236
237 /* Out-of-bounds scancode */
239 result = (char *)SDL_GetScancodeName(scancode);
240 SDLTest_AssertPass("Call to SDL_GetScancodeName(%d/large)", scancode);
241 SDLTest_AssertCheck(result != NULL, "Verify result from call is not NULL");
242 SDLTest_AssertCheck(SDL_strcmp(result, expected) == 0, "Verify result from call is valid, expected: '%s', got: '%s'", expected, result);
244
245 return TEST_COMPLETED;
246}
#define SDL_GetScancodeName
@ SDL_NUM_SCANCODES
Definition: SDL_scancode.h:407

References _checkInvalidScancodeError(), NULL, SDL_ClearError, SDL_GetScancodeName, SDL_NUM_SCANCODES, SDL_strcmp, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_getSetModState()

int keyboard_getSetModState ( void arg)

Check call to SDL_GetModState and SDL_SetModState.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetModState
http://wiki.libsdl.org/moin.cgi/SDL_SetModState

Definition at line 292 of file testautomation_keyboard.c.

293{
295 SDL_Keymod currentState;
296 SDL_Keymod newState;
297 SDL_Keymod allStates =
298 KMOD_NONE |
301 KMOD_LCTRL |
302 KMOD_RCTRL |
303 KMOD_LALT |
304 KMOD_RALT |
305 KMOD_LGUI |
306 KMOD_RGUI |
307 KMOD_NUM |
308 KMOD_CAPS |
309 KMOD_MODE |
311
312 /* Get state, cache for later reset */
314 SDLTest_AssertPass("Call to SDL_GetModState()");
315 SDLTest_AssertCheck(/*result >= 0 &&*/ result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);
316 currentState = result;
317
318 /* Set random state */
319 newState = SDLTest_RandomIntegerInRange(0, allStates);
320 SDL_SetModState(newState);
321 SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState);
323 SDLTest_AssertPass("Call to SDL_GetModState()");
324 SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result);
325
326 /* Set zero state */
328 SDLTest_AssertPass("Call to SDL_SetModState(0)");
330 SDLTest_AssertPass("Call to SDL_GetModState()");
331 SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result);
332
333 /* Revert back to cached current state if needed */
334 if (currentState != 0) {
335 SDL_SetModState(currentState);
336 SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState);
338 SDLTest_AssertPass("Call to SDL_GetModState()");
339 SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result);
340 }
341
342 return TEST_COMPLETED;
343}
#define SDL_SetModState
#define SDL_GetModState
SDL_Keymod
Enumeration of valid key mods (possibly OR'd together).
Definition: SDL_keycode.h:326
@ KMOD_MODE
Definition: SDL_keycode.h:338
@ KMOD_RALT
Definition: SDL_keycode.h:333
@ KMOD_LSHIFT
Definition: SDL_keycode.h:328
@ KMOD_RESERVED
Definition: SDL_keycode.h:339
@ KMOD_LGUI
Definition: SDL_keycode.h:334
@ KMOD_CAPS
Definition: SDL_keycode.h:337
@ KMOD_LALT
Definition: SDL_keycode.h:332
@ KMOD_RCTRL
Definition: SDL_keycode.h:331
@ KMOD_NONE
Definition: SDL_keycode.h:327
@ KMOD_RGUI
Definition: SDL_keycode.h:335
@ KMOD_LCTRL
Definition: SDL_keycode.h:330
@ KMOD_RSHIFT
Definition: SDL_keycode.h:329
@ KMOD_NUM
Definition: SDL_keycode.h:336

References KMOD_CAPS, KMOD_LALT, KMOD_LCTRL, KMOD_LGUI, KMOD_LSHIFT, KMOD_MODE, KMOD_NONE, KMOD_NUM, KMOD_RALT, KMOD_RCTRL, KMOD_RESERVED, KMOD_RGUI, KMOD_RSHIFT, SDL_GetModState, SDL_SetModState, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), and TEST_COMPLETED.

◆ keyboard_setTextInputRect()

int keyboard_setTextInputRect ( void arg)

Check call to SDL_SetTextInputRect.

See also
http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect

Definition at line 399 of file testautomation_keyboard.c.

400{
401 SDL_Rect refRect;
402
403 /* Normal visible refRect, origin inside */
404 refRect.x = SDLTest_RandomIntegerInRange(1, 50);
405 refRect.y = SDLTest_RandomIntegerInRange(1, 50);
406 refRect.w = SDLTest_RandomIntegerInRange(10, 50);
407 refRect.h = SDLTest_RandomIntegerInRange(10, 50);
408 _testSetTextInputRect(refRect);
409
410 /* Normal visible refRect, origin 0,0 */
411 refRect.x = 0;
412 refRect.y = 0;
413 refRect.w = SDLTest_RandomIntegerInRange(10, 50);
414 refRect.h = SDLTest_RandomIntegerInRange(10, 50);
415 _testSetTextInputRect(refRect);
416
417 /* 1Pixel refRect */
418 refRect.x = SDLTest_RandomIntegerInRange(10, 50);
419 refRect.y = SDLTest_RandomIntegerInRange(10, 50);
420 refRect.w = 1;
421 refRect.h = 1;
422 _testSetTextInputRect(refRect);
423
424 /* 0pixel refRect */
425 refRect.x = 1;
426 refRect.y = 1;
427 refRect.w = 1;
428 refRect.h = 0;
429 _testSetTextInputRect(refRect);
430
431 /* 0pixel refRect */
432 refRect.x = 1;
433 refRect.y = 1;
434 refRect.w = 0;
435 refRect.h = 1;
436 _testSetTextInputRect(refRect);
437
438 /* 0pixel refRect */
439 refRect.x = 1;
440 refRect.y = 1;
441 refRect.w = 0;
442 refRect.h = 0;
443 _testSetTextInputRect(refRect);
444
445 /* 0pixel refRect */
446 refRect.x = 0;
447 refRect.y = 0;
448 refRect.w = 0;
449 refRect.h = 0;
450 _testSetTextInputRect(refRect);
451
452 /* negative refRect */
453 refRect.x = SDLTest_RandomIntegerInRange(-200, -100);
454 refRect.y = SDLTest_RandomIntegerInRange(-200, -100);
455 refRect.w = 50;
456 refRect.h = 50;
457 _testSetTextInputRect(refRect);
458
459 /* oversized refRect */
460 refRect.x = SDLTest_RandomIntegerInRange(1, 50);
461 refRect.y = SDLTest_RandomIntegerInRange(1, 50);
462 refRect.w = 5000;
463 refRect.h = 5000;
464 _testSetTextInputRect(refRect);
465
466 /* NULL refRect */
468 SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
469
470 return TEST_COMPLETED;
471}
void _testSetTextInputRect(SDL_Rect refRect)

References _testSetTextInputRect(), SDL_Rect::h, NULL, SDL_SetTextInputRect, SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), TEST_COMPLETED, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

◆ keyboard_setTextInputRectNegative()

int keyboard_setTextInputRectNegative ( void arg)

Check call to SDL_SetTextInputRect with invalid data.

See also
http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect

Definition at line 479 of file testautomation_keyboard.c.

480{
481 /* Some platforms set also an error message; prepare for checking it */
482#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
483 const char *expectedError = "Parameter 'rect' is invalid";
484 const char *error;
485
487 SDLTest_AssertPass("Call to SDL_ClearError()");
488#endif
489
490 /* NULL refRect */
492 SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
493
494 /* Some platforms set also an error message; so check it */
495#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
496 error = SDL_GetError();
497 SDLTest_AssertPass("Call to SDL_GetError()");
498 SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
499 if (error != NULL) {
500 SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
501 "Validate error message, expected: '%s', got: '%s'", expectedError, error);
502 }
503
505 SDLTest_AssertPass("Call to SDL_ClearError()");
506#endif
507
508 return TEST_COMPLETED;
509}

References NULL, SDL_ClearError, SDL_GetError, SDL_SetTextInputRect, SDL_strcmp, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

◆ keyboard_startStopTextInput()

int keyboard_startStopTextInput ( void arg)

Check call to SDL_StartTextInput and SDL_StopTextInput.

See also
http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput

Definition at line 353 of file testautomation_keyboard.c.

354{
355 /* Start-Stop */
357 SDLTest_AssertPass("Call to SDL_StartTextInput()");
359 SDLTest_AssertPass("Call to SDL_StopTextInput()");
360
361 /* Stop-Start */
363 SDLTest_AssertPass("Call to SDL_StartTextInput()");
364
365 /* Start-Start */
367 SDLTest_AssertPass("Call to SDL_StartTextInput()");
368
369 /* Stop-Stop */
371 SDLTest_AssertPass("Call to SDL_StopTextInput()");
373 SDLTest_AssertPass("Call to SDL_StopTextInput()");
374
375 return TEST_COMPLETED;
376}
#define SDL_StartTextInput
#define SDL_StopTextInput

References SDL_StartTextInput, SDL_StopTextInput, SDLTest_AssertPass(), and TEST_COMPLETED.

Variable Documentation

◆ keyboardTest1

const SDLTest_TestCaseReference keyboardTest1
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED }
#define TEST_ENABLED
int(* SDLTest_TestCaseFp)(void *arg)
int keyboard_getKeyboardState(void *arg)
Check call to SDL_GetKeyboardState with and without numkeys reference.

Definition at line 658 of file testautomation_keyboard.c.

◆ keyboardTest10

const SDLTest_TestCaseReference keyboardTest10
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED }
int keyboard_getScancodeFromKey(void *arg)
Check call to SDL_GetScancodeFromKey.

Definition at line 685 of file testautomation_keyboard.c.

◆ keyboardTest11

const SDLTest_TestCaseReference keyboardTest11
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED }
int keyboard_getScancodeFromName(void *arg)
Check call to SDL_GetScancodeFromName.

Definition at line 688 of file testautomation_keyboard.c.

◆ keyboardTest12

const SDLTest_TestCaseReference keyboardTest12
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED }
int keyboard_getScancodeFromNameNegative(void *arg)
Check call to SDL_GetScancodeFromName with invalid data.

Definition at line 691 of file testautomation_keyboard.c.

◆ keyboardTest13

const SDLTest_TestCaseReference keyboardTest13
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED }
int keyboard_getKeyNameNegative(void *arg)
SDL_GetKeyName negative cases.

Definition at line 694 of file testautomation_keyboard.c.

◆ keyboardTest14

const SDLTest_TestCaseReference keyboardTest14
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED }
int keyboard_getScancodeNameNegative(void *arg)
SDL_GetScancodeName negative cases.

Definition at line 697 of file testautomation_keyboard.c.

◆ keyboardTest2

const SDLTest_TestCaseReference keyboardTest2
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED }
int keyboard_getKeyboardFocus(void *arg)
Check call to SDL_GetKeyboardFocus.

Definition at line 661 of file testautomation_keyboard.c.

◆ keyboardTest3

const SDLTest_TestCaseReference keyboardTest3
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED }
int keyboard_getKeyFromName(void *arg)
Check call to SDL_GetKeyFromName for known, unknown and invalid name.

Definition at line 664 of file testautomation_keyboard.c.

◆ keyboardTest4

const SDLTest_TestCaseReference keyboardTest4
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED }
int keyboard_getKeyFromScancode(void *arg)
Check call to SDL_GetKeyFromScancode.

Definition at line 667 of file testautomation_keyboard.c.

◆ keyboardTest5

const SDLTest_TestCaseReference keyboardTest5
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED }
int keyboard_getKeyName(void *arg)
Check call to SDL_GetKeyName.

Definition at line 670 of file testautomation_keyboard.c.

◆ keyboardTest6

const SDLTest_TestCaseReference keyboardTest6
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED }
int keyboard_getSetModState(void *arg)
Check call to SDL_GetModState and SDL_SetModState.

Definition at line 673 of file testautomation_keyboard.c.

◆ keyboardTest7

const SDLTest_TestCaseReference keyboardTest7
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED }
int keyboard_startStopTextInput(void *arg)
Check call to SDL_StartTextInput and SDL_StopTextInput.

Definition at line 676 of file testautomation_keyboard.c.

◆ keyboardTest8

const SDLTest_TestCaseReference keyboardTest8
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED }
int keyboard_setTextInputRect(void *arg)
Check call to SDL_SetTextInputRect.

Definition at line 679 of file testautomation_keyboard.c.

◆ keyboardTest9

const SDLTest_TestCaseReference keyboardTest9
static
Initial value:
=
{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED }
int keyboard_setTextInputRectNegative(void *arg)
Check call to SDL_SetTextInputRect with invalid data.

Definition at line 682 of file testautomation_keyboard.c.

◆ keyboardTests

const SDLTest_TestCaseReference* keyboardTests[]
static
Initial value:
= {
}
static const SDLTest_TestCaseReference keyboardTest6
static const SDLTest_TestCaseReference keyboardTest5
static const SDLTest_TestCaseReference keyboardTest2
static const SDLTest_TestCaseReference keyboardTest8
static const SDLTest_TestCaseReference keyboardTest4
static const SDLTest_TestCaseReference keyboardTest9
static const SDLTest_TestCaseReference keyboardTest3
static const SDLTest_TestCaseReference keyboardTest10
static const SDLTest_TestCaseReference keyboardTest14
static const SDLTest_TestCaseReference keyboardTest7
static const SDLTest_TestCaseReference keyboardTest11
static const SDLTest_TestCaseReference keyboardTest13
static const SDLTest_TestCaseReference keyboardTest12
static const SDLTest_TestCaseReference keyboardTest1

Definition at line 701 of file testautomation_keyboard.c.

◆ keyboardTestSuite

SDLTest_TestSuiteReference keyboardTestSuite
Initial value:
= {
"Keyboard",
}
static const SDLTest_TestCaseReference * keyboardTests[]

Definition at line 708 of file testautomation_keyboard.c.