SDL  2.0
testautomation_keyboard.c
Go to the documentation of this file.
1 /**
2  * Keyboard test suite
3  */
4 
5 #include <stdio.h>
6 #include <limits.h>
7 
8 #include "SDL_config.h"
9 #include "SDL.h"
10 #include "SDL_test.h"
11 
12 /* ================= Test Case Implementation ================== */
13 
14 /* Test case functions */
15 
16 /**
17  * @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
18  *
19  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
20  */
21 int
23 {
24  int numkeys;
25  Uint8 *state;
26 
27  /* Case where numkeys pointer is NULL */
28  state = (Uint8 *)SDL_GetKeyboardState(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 }
41 
42 /**
43  * @brief Check call to SDL_GetKeyboardFocus
44  *
45  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus
46  */
47 int
49 {
51 
52  /* Call, but ignore return value */
53  window = SDL_GetKeyboardFocus();
54  SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
55 
56  return TEST_COMPLETED;
57 }
58 
59 /**
60  * @brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
61  *
62  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName
63  */
64 int
66 {
68 
69  /* Case where Key is known, 1 character input */
70  result = SDL_GetKeyFromName("A");
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 */
75  result = SDL_GetKeyFromName("F1");
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 */
80  result = SDL_GetKeyFromName("End");
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 */
100  result = SDL_GetKeyFromName(NULL);
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 }
106 
107 /*
108  * Local helper to check for the invalid scancode error message
109  */
110 void
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);
121  SDL_ClearError();
122  SDLTest_AssertPass("Call to SDL_ClearError()");
123  }
124 }
125 
126 /**
127  * @brief Check call to SDL_GetKeyFromScancode
128  *
129  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
130  */
131 int
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 */
142  result = SDL_GetKeyFromScancode(0);
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 */
147  SDL_ClearError();
148  SDLTest_AssertPass("Call to SDL_ClearError()");
149 
150  /* Case where input is invalid (too small) */
151  result = SDL_GetKeyFromScancode(-999);
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) */
157  result = SDL_GetKeyFromScancode(999);
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 }
164 
165 /**
166  * @brief Check call to SDL_GetKeyName
167  *
168  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
169  */
170 int
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";
199  result = (char *)SDL_GetKeyName(SDLK_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";
206  result = (char *)SDL_GetKeyName(SDLK_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";
213  result = (char *)SDL_GetKeyName(SDLK_KP_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 }
220 
221 /**
222  * @brief SDL_GetScancodeName negative cases
223  *
224  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName
225  */
226 int
228 {
229  SDL_Scancode scancode;
230  char *result;
231  char *expected = "";
232 
233  /* Clear error message */
234  SDL_ClearError();
235  SDLTest_AssertPass("Call to SDL_ClearError()");
236 
237  /* Out-of-bounds scancode */
238  scancode = (SDL_Scancode)SDL_NUM_SCANCODES;
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 }
247 
248 /**
249  * @brief SDL_GetKeyName negative cases
250  *
251  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
252  */
253 int
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 */
268  SDL_ClearError();
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 
279  SDL_ClearError();
280  SDLTest_AssertPass("Call to SDL_ClearError()");
281 
282  return TEST_COMPLETED;
283 }
284 
285 /**
286  * @brief Check call to SDL_GetModState and SDL_SetModState
287  *
288  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
289  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
290  */
291 int
293 {
295  SDL_Keymod currentState;
296  SDL_Keymod newState;
297  SDL_Keymod allStates =
298  KMOD_NONE |
299  KMOD_LSHIFT |
300  KMOD_RSHIFT |
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 */
313  result = SDL_GetModState();
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);
322  result = SDL_GetModState();
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 */
327  SDL_SetModState(0);
328  SDLTest_AssertPass("Call to SDL_SetModState(0)");
329  result = SDL_GetModState();
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);
337  result = SDL_GetModState();
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 }
344 
345 
346 /**
347  * @brief Check call to SDL_StartTextInput and SDL_StopTextInput
348  *
349  * @sa http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
350  * @sa http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput
351  */
352 int
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 }
377 
378 /* Internal function to test SDL_SetTextInputRect */
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 }
392 
393 /**
394  * @brief Check call to SDL_SetTextInputRect
395  *
396  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
397  */
398 int
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 }
472 
473 /**
474  * @brief Check call to SDL_SetTextInputRect with invalid data
475  *
476  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
477  */
478 int
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 
486  SDL_ClearError();
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 
504  SDL_ClearError();
505  SDLTest_AssertPass("Call to SDL_ClearError()");
506 #endif
507 
508  return TEST_COMPLETED;
509 }
510 
511 /**
512  * @brief Check call to SDL_GetScancodeFromKey
513  *
514  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
515  * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
516  */
517 int
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 */
528  scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
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 }
534 
535 /**
536  * @brief Check call to SDL_GetScancodeFromName
537  *
538  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
539  * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
540  */
541 int
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 }
588 
589 /*
590  * Local helper to check for the invalid scancode error message
591  */
592 void
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);
603  SDL_ClearError();
604  SDLTest_AssertPass("Call to SDL_ClearError()");
605  }
606 }
607 
608 /**
609  * @brief Check call to SDL_GetScancodeFromName with invalid data
610  *
611  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
612  * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
613  */
614 int
616 {
617  char *name;
618  SDL_Scancode scancode;
619 
620  /* Clear error message */
621  SDL_ClearError();
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 }
652 
653 
654 
655 /* ================= Test References ================== */
656 
657 /* Keyboard test cases */
659  { (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
660 
662  { (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED };
663 
665  { (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED };
666 
668  { (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
669 
671  { (SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED };
672 
674  { (SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED };
675 
677  { (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
678 
680  { (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED };
681 
683  { (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
684 
686  { (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
687 
689  { (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
690 
692  { (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
693 
695  { (SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED };
696 
698  { (SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED };
699 
700 /* Sequence of Keyboard test cases */
705 };
706 
707 /* Keyboard test suite (global) */
709  "Keyboard",
710  NULL,
712  NULL
713 };
#define SDL_ClearError
#define SDL_GetError
#define TEST_ABORTED
static const SDLTest_TestCaseReference keyboardTest1
static const SDLTest_TestCaseReference keyboardTest8
GLuint64EXT * result
int keyboard_getScancodeFromNameNegative(void *arg)
Check call to SDL_GetScancodeFromName with invalid data.
int keyboard_setTextInputRect(void *arg)
Check call to SDL_SetTextInputRect.
static const SDLTest_TestCaseReference keyboardTest9
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
#define SDL_GetKeyFromScancode
int keyboard_setTextInputRectNegative(void *arg)
Check call to SDL_SetTextInputRect with invalid data.
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.
struct xkb_state * state
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.
static const SDLTest_TestCaseReference keyboardTest14
#define SDL_SetModState
#define SDL_GetKeyboardFocus
int keyboard_getSetModState(void *arg)
Check call to SDL_GetModState and SDL_SetModState.
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:45
int keyboard_getKeyNameNegative(void *arg)
SDL_GetKeyName negative cases.
GLuint const GLchar * name
SDLTest_TestSuiteReference keyboardTestSuite
#define SDL_GetScancodeFromName
void _checkInvalidNameError()
int(* SDLTest_TestCaseFp)(void *arg)
#define SDL_GetScancodeFromKey
char * SDLTest_RandomAsciiStringOfSize(int size)
#define SDL_StopTextInput
int keyboard_getScancodeNameNegative(void *arg)
SDL_GetScancodeName negative cases.
int keyboard_getScancodeFromKey(void *arg)
Check call to SDL_GetScancodeFromKey.
static const SDLTest_TestCaseReference keyboardTest7
#define SDL_GetKeyboardState
void _checkInvalidScancodeError()
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...
uint8_t Uint8
Definition: SDL_stdinc.h:157
int keyboard_getKeyboardState(void *arg)
Check call to SDL_GetKeyboardState with and without numkeys reference.
#define SDL_free
static const SDLTest_TestCaseReference keyboardTest4
static const SDLTest_TestCaseReference keyboardTest11
int keyboard_getKeyFromScancode(void *arg)
Check call to SDL_GetKeyFromScancode.
int keyboard_getScancodeFromName(void *arg)
Check call to SDL_GetScancodeFromName.
int keyboard_getKeyboardFocus(void *arg)
Check call to SDL_GetKeyboardFocus.
int x
Definition: SDL_rect.h:66
#define TEST_COMPLETED
int w
Definition: SDL_rect.h:67
#define SDL_StartTextInput
SDL_Keymod
Enumeration of valid key mods (possibly OR&#39;d together).
Definition: SDL_keycode.h:325
#define TEST_ENABLED
int keyboard_getKeyFromName(void *arg)
Check call to SDL_GetKeyFromName for known, unknown and invalid name.
static const SDLTest_TestCaseReference keyboardTest12
static const SDLTest_TestCaseReference keyboardTest13
void _testSetTextInputRect(SDL_Rect refRect)
#define NULL
Definition: begin_code.h:164
#define SDL_GetScancodeName
#define SDL_SetTextInputRect
static const SDLTest_TestCaseReference * keyboardTests[]
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
static const SDLTest_TestCaseReference keyboardTest3
int keyboard_startStopTextInput(void *arg)
Check call to SDL_StartTextInput and SDL_StopTextInput.
int h
Definition: SDL_rect.h:67
The type used to identify a window.
Definition: SDL_sysvideo.h:73
#define SDL_GetKeyFromName
static const SDLTest_TestCaseReference keyboardTest10
#define SDL_GetKeyName
int keyboard_getKeyName(void *arg)
Check call to SDL_GetKeyName.
#define SDL_strcmp
static const SDLTest_TestCaseReference keyboardTest2
#define SDL_GetModState
int y
Definition: SDL_rect.h:66
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
static const SDLTest_TestCaseReference keyboardTest6
static const SDLTest_TestCaseReference keyboardTest5