Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
713 lines (595 loc) · 25.9 KB

testautomation_keyboard.c

File metadata and controls

713 lines (595 loc) · 25.9 KB
 
1
2
3
4
5
/**
* Keyboard test suite
*/
#include <stdio.h>
Mar 9, 2013
Mar 9, 2013
6
#include <limits.h>
Jan 14, 2013
Jan 14, 2013
8
#include "SDL_config.h"
9
10
11
12
13
14
15
16
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
/* Test case functions */
/**
Jan 7, 2013
Jan 7, 2013
17
* @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
May 18, 2013
May 18, 2013
18
*
Jan 7, 2013
Jan 7, 2013
19
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
20
21
22
23
24
25
26
*/
int
keyboard_getKeyboardState(void *arg)
{
int numkeys;
Uint8 *state;
May 18, 2013
May 18, 2013
27
/* Case where numkeys pointer is NULL */
Jun 4, 2013
Jun 4, 2013
28
state = (Uint8 *)SDL_GetKeyboardState(NULL);
29
30
31
32
33
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;
Jun 4, 2013
Jun 4, 2013
34
state = (Uint8 *)SDL_GetKeyboardState(&numkeys);
35
36
37
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);
May 18, 2013
May 18, 2013
38
39
40
41
return TEST_COMPLETED;
}
Jan 7, 2013
Jan 7, 2013
42
43
/**
* @brief Check call to SDL_GetKeyboardFocus
May 18, 2013
May 18, 2013
44
*
Jan 7, 2013
Jan 7, 2013
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
* @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.
May 18, 2013
May 18, 2013
61
*
Jan 7, 2013
Jan 7, 2013
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
* @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;
}
May 18, 2013
May 18, 2013
107
/*
Mar 9, 2013
Mar 9, 2013
108
109
110
111
112
113
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidScancodeError()
{
const char *expectedError = "Parameter 'scancode' is invalid";
May 18, 2013
May 18, 2013
114
const char *error;
Mar 9, 2013
Mar 9, 2013
115
116
117
118
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
119
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
Mar 9, 2013
Mar 9, 2013
120
121
122
123
124
125
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
}
}
Jan 7, 2013
Jan 7, 2013
126
127
/**
* @brief Check call to SDL_GetKeyFromScancode
May 18, 2013
May 18, 2013
128
*
Jan 7, 2013
Jan 7, 2013
129
130
131
132
133
134
135
136
137
138
139
140
141
142
* @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);
Jan 14, 2013
Jan 14, 2013
143
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(0)");
Jan 7, 2013
Jan 7, 2013
144
145
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
Mar 9, 2013
Mar 9, 2013
146
/* Clear error message */
Jan 14, 2013
Jan 14, 2013
147
148
149
150
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
/* Case where input is invalid (too small) */
Jan 7, 2013
Jan 7, 2013
151
result = SDL_GetKeyFromScancode(-999);
Jan 14, 2013
Jan 14, 2013
152
153
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);
Mar 9, 2013
Mar 9, 2013
154
_checkInvalidScancodeError();
Jan 14, 2013
Jan 14, 2013
155
156
157
158
/* Case where input is invalid (too big) */
result = SDL_GetKeyFromScancode(999);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(999)");
Jan 7, 2013
Jan 7, 2013
159
SDLTest_AssertCheck(result == SDLK_UNKNOWN, "Verify result from call is UNKNOWN, expected: %i, got: %i", SDLK_UNKNOWN, result);
Mar 9, 2013
Mar 9, 2013
160
_checkInvalidScancodeError();
Jan 7, 2013
Jan 7, 2013
161
162
163
164
return TEST_COMPLETED;
}
Jan 11, 2013
Jan 11, 2013
165
166
/**
* @brief Check call to SDL_GetKeyName
May 18, 2013
May 18, 2013
167
*
Jan 11, 2013
Jan 11, 2013
168
169
170
171
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
*/
int
keyboard_getKeyName(void *arg)
May 18, 2013
May 18, 2013
172
{
Jan 11, 2013
Jan 11, 2013
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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;
}
Mar 9, 2013
Mar 9, 2013
221
222
/**
* @brief SDL_GetScancodeName negative cases
May 18, 2013
May 18, 2013
223
*
Mar 9, 2013
Mar 9, 2013
224
225
226
227
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName
*/
int
keyboard_getScancodeNameNegative(void *arg)
May 18, 2013
May 18, 2013
228
{
Mar 9, 2013
Mar 9, 2013
229
230
231
232
233
234
235
236
SDL_Scancode scancode;
char *result;
char *expected = "";
/* Clear error message */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
May 12, 2013
May 12, 2013
237
238
/* Out-of-bounds scancode */
scancode = (SDL_Scancode)SDL_NUM_SCANCODES;
Mar 9, 2013
Mar 9, 2013
239
240
241
242
243
244
245
246
247
248
249
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
May 18, 2013
May 18, 2013
250
*
Mar 9, 2013
Mar 9, 2013
251
252
253
254
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
*/
int
keyboard_getKeyNameNegative(void *arg)
May 18, 2013
May 18, 2013
255
{
Mar 9, 2013
Mar 9, 2013
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
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;
}
Jan 11, 2013
Jan 11, 2013
285
286
/**
* @brief Check call to SDL_GetModState and SDL_SetModState
May 18, 2013
May 18, 2013
287
*
Jan 11, 2013
Jan 11, 2013
288
289
290
291
292
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
*/
int
keyboard_getSetModState(void *arg)
May 18, 2013
May 18, 2013
293
{
Jan 11, 2013
Jan 11, 2013
294
295
296
SDL_Keymod result;
SDL_Keymod currentState;
SDL_Keymod newState;
May 18, 2013
May 18, 2013
297
SDL_Keymod allStates =
Jan 11, 2013
Jan 11, 2013
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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;
May 18, 2013
May 18, 2013
312
/* Get state, cache for later reset */
Jan 11, 2013
Jan 11, 2013
313
314
result = SDL_GetModState();
SDLTest_AssertPass("Call to SDL_GetModState()");
May 18, 2013
May 18, 2013
315
SDLTest_AssertCheck(result >=0 && result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result);
Jan 11, 2013
Jan 11, 2013
316
317
currentState = result;
May 18, 2013
May 18, 2013
318
/* Set random state */
Jan 11, 2013
Jan 11, 2013
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
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
May 18, 2013
May 18, 2013
348
*
Jan 11, 2013
Jan 11, 2013
349
350
351
352
353
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput
*/
int
keyboard_startStopTextInput(void *arg)
May 18, 2013
May 18, 2013
354
{
Jan 11, 2013
Jan 11, 2013
355
356
357
358
359
360
361
362
363
/* 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()");
May 18, 2013
May 18, 2013
364
Jan 11, 2013
Jan 11, 2013
365
366
367
368
/* Start-Start */
SDL_StartTextInput();
SDLTest_AssertPass("Call to SDL_StartTextInput()");
May 18, 2013
May 18, 2013
369
/* Stop-Stop */
Jan 11, 2013
Jan 11, 2013
370
371
372
373
374
375
376
377
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
SDL_StopTextInput();
SDLTest_AssertPass("Call to SDL_StopTextInput()");
return TEST_COMPLETED;
}
Jan 12, 2013
Jan 12, 2013
378
379
380
381
/* Internal function to test SDL_SetTextInputRect */
void _testSetTextInputRect(SDL_Rect refRect)
{
SDL_Rect testRect;
May 18, 2013
May 18, 2013
382
Jan 12, 2013
Jan 12, 2013
383
384
385
386
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(
May 18, 2013
May 18, 2013
387
388
389
(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,
Jan 12, 2013
Jan 12, 2013
390
391
392
393
394
testRect.x, testRect.y, testRect.w, testRect.h);
}
/**
* @brief Check call to SDL_SetTextInputRect
May 18, 2013
May 18, 2013
395
*
Jan 12, 2013
Jan 12, 2013
396
397
398
399
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
*/
int
keyboard_setTextInputRect(void *arg)
May 18, 2013
May 18, 2013
400
{
Jan 12, 2013
Jan 12, 2013
401
SDL_Rect refRect;
May 18, 2013
May 18, 2013
402
Jan 12, 2013
Jan 12, 2013
403
404
405
406
407
408
/* 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);
May 18, 2013
May 18, 2013
409
Jan 12, 2013
Jan 12, 2013
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/* 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
May 18, 2013
May 18, 2013
475
*
Jan 12, 2013
Jan 12, 2013
476
477
478
479
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
*/
int
keyboard_setTextInputRectNegative(void *arg)
May 18, 2013
May 18, 2013
480
{
Jan 14, 2013
Jan 14, 2013
481
/* Some platforms set also an error message; prepare for checking it */
May 18, 2013
May 18, 2013
482
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
Jan 13, 2013
Jan 13, 2013
483
const char *expectedError = "Parameter 'rect' is invalid";
Jan 12, 2013
Jan 12, 2013
484
const char *error;
May 18, 2013
May 18, 2013
485
Jan 12, 2013
Jan 12, 2013
486
487
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
Jan 14, 2013
Jan 14, 2013
488
#endif
May 18, 2013
May 18, 2013
489
Jan 12, 2013
Jan 12, 2013
490
491
492
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
Jan 14, 2013
Jan 14, 2013
493
494
/* Some platforms set also an error message; so check it */
May 18, 2013
May 18, 2013
495
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
Jan 12, 2013
Jan 12, 2013
496
497
498
499
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
500
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
Jan 12, 2013
Jan 12, 2013
501
502
503
504
505
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
Jan 14, 2013
Jan 14, 2013
506
#endif
May 18, 2013
May 18, 2013
507
Jan 12, 2013
Jan 12, 2013
508
509
510
return TEST_COMPLETED;
}
Jan 13, 2013
Jan 13, 2013
511
512
/**
* @brief Check call to SDL_GetScancodeFromKey
May 18, 2013
May 18, 2013
513
*
Jan 13, 2013
Jan 13, 2013
514
515
516
517
518
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
*/
int
keyboard_getScancodeFromKey(void *arg)
May 18, 2013
May 18, 2013
519
{
Jan 13, 2013
Jan 13, 2013
520
SDL_Scancode scancode;
May 18, 2013
May 18, 2013
521
Jan 13, 2013
Jan 13, 2013
522
523
524
/* Regular key */
scancode = SDL_GetScancodeFromKey(SDLK_4);
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
May 18, 2013
May 18, 2013
525
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
Jan 13, 2013
Jan 13, 2013
526
527
528
529
/* Virtual key */
scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
May 18, 2013
May 18, 2013
530
531
SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode);
Jan 13, 2013
Jan 13, 2013
532
533
534
535
536
return TEST_COMPLETED;
}
/**
* @brief Check call to SDL_GetScancodeFromName
May 18, 2013
May 18, 2013
537
*
Jan 13, 2013
Jan 13, 2013
538
539
540
541
542
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
*/
int
keyboard_getScancodeFromName(void *arg)
May 18, 2013
May 18, 2013
543
{
Jan 13, 2013
Jan 13, 2013
544
545
546
547
548
SDL_Scancode scancode;
/* Regular key, 1 character, first name in list */
scancode = SDL_GetScancodeFromName("A");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
May 18, 2013
May 18, 2013
549
SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode);
Jan 13, 2013
Jan 13, 2013
550
551
552
553
/* Regular key, 1 character */
scancode = SDL_GetScancodeFromName("4");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
May 18, 2013
May 18, 2013
554
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
Jan 13, 2013
Jan 13, 2013
555
556
557
558
/* Regular key, 2 characters */
scancode = SDL_GetScancodeFromName("F1");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
May 18, 2013
May 18, 2013
559
SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode);
Jan 13, 2013
Jan 13, 2013
560
561
562
563
/* Regular key, 3 characters */
scancode = SDL_GetScancodeFromName("End");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
May 18, 2013
May 18, 2013
564
SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode);
Jan 13, 2013
Jan 13, 2013
565
566
567
568
/* Regular key, 4 characters */
scancode = SDL_GetScancodeFromName("Find");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
May 18, 2013
May 18, 2013
569
SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode);
Jan 13, 2013
Jan 13, 2013
570
571
572
573
/* Regular key, several characters */
scancode = SDL_GetScancodeFromName("Backspace");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
May 18, 2013
May 18, 2013
574
SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode);
Jan 13, 2013
Jan 13, 2013
575
576
577
578
/* Regular key, several characters with space */
scancode = SDL_GetScancodeFromName("Keypad Enter");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
May 18, 2013
May 18, 2013
579
SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode);
Jan 13, 2013
Jan 13, 2013
580
581
582
583
/* Regular key, last name in list */
scancode = SDL_GetScancodeFromName("Sleep");
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
May 18, 2013
May 18, 2013
584
585
SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode);
Jan 13, 2013
Jan 13, 2013
586
587
588
return TEST_COMPLETED;
}
May 18, 2013
May 18, 2013
589
/*
Mar 9, 2013
Mar 9, 2013
590
591
592
593
594
595
* Local helper to check for the invalid scancode error message
*/
void
_checkInvalidNameError()
{
const char *expectedError = "Parameter 'name' is invalid";
May 18, 2013
May 18, 2013
596
const char *error;
Mar 9, 2013
Mar 9, 2013
597
598
599
600
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
601
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
Mar 9, 2013
Mar 9, 2013
602
603
604
605
606
607
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
}
}
Jan 13, 2013
Jan 13, 2013
608
609
/**
* @brief Check call to SDL_GetScancodeFromName with invalid data
May 18, 2013
May 18, 2013
610
*
Jan 13, 2013
Jan 13, 2013
611
612
613
614
615
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
*/
int
keyboard_getScancodeFromNameNegative(void *arg)
May 18, 2013
May 18, 2013
616
{
Jan 13, 2013
Jan 13, 2013
617
618
619
char *name;
SDL_Scancode scancode;
Mar 9, 2013
Mar 9, 2013
620
/* Clear error message */
Jan 13, 2013
Jan 13, 2013
621
622
623
624
625
626
627
628
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;
May 18, 2013
May 18, 2013
629
}
Jan 13, 2013
Jan 13, 2013
630
631
632
633
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);
Mar 9, 2013
Mar 9, 2013
634
_checkInvalidNameError();
May 18, 2013
May 18, 2013
635
Jan 13, 2013
Jan 13, 2013
636
637
638
639
640
/* 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);
Mar 9, 2013
Mar 9, 2013
641
_checkInvalidNameError();
Jan 13, 2013
Jan 13, 2013
642
643
644
645
646
647
/* 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);
Mar 9, 2013
Mar 9, 2013
648
_checkInvalidNameError();
May 18, 2013
May 18, 2013
649
Jan 13, 2013
Jan 13, 2013
650
651
652
return TEST_COMPLETED;
}
Jan 7, 2013
Jan 7, 2013
653
654
655
656
657
658
/* ================= Test References ================== */
/* Keyboard test cases */
static const SDLTest_TestCaseReference keyboardTest1 =
May 18, 2013
May 18, 2013
659
{ (SDLTest_TestCaseFp)keyboard_getKeyboardState, "keyboard_getKeyboardState", "Check call to SDL_GetKeyboardState with and without numkeys reference", TEST_ENABLED };
Jan 7, 2013
Jan 7, 2013
660
661
static const SDLTest_TestCaseReference keyboardTest2 =
May 18, 2013
May 18, 2013
662
{ (SDLTest_TestCaseFp)keyboard_getKeyboardFocus, "keyboard_getKeyboardFocus", "Check call to SDL_GetKeyboardFocus", TEST_ENABLED };
Jan 7, 2013
Jan 7, 2013
663
664
static const SDLTest_TestCaseReference keyboardTest3 =
May 18, 2013
May 18, 2013
665
{ (SDLTest_TestCaseFp)keyboard_getKeyFromName, "keyboard_getKeyFromName", "Check call to SDL_GetKeyFromName for known, unknown and invalid name", TEST_ENABLED };
Jan 7, 2013
Jan 7, 2013
666
667
static const SDLTest_TestCaseReference keyboardTest4 =
May 18, 2013
May 18, 2013
668
{ (SDLTest_TestCaseFp)keyboard_getKeyFromScancode, "keyboard_getKeyFromScancode", "Check call to SDL_GetKeyFromScancode", TEST_ENABLED };
Jan 11, 2013
Jan 11, 2013
670
static const SDLTest_TestCaseReference keyboardTest5 =
May 18, 2013
May 18, 2013
671
{ (SDLTest_TestCaseFp)keyboard_getKeyName, "keyboard_getKeyName", "Check call to SDL_GetKeyName", TEST_ENABLED };
Jan 11, 2013
Jan 11, 2013
672
673
static const SDLTest_TestCaseReference keyboardTest6 =
May 18, 2013
May 18, 2013
674
{ (SDLTest_TestCaseFp)keyboard_getSetModState, "keyboard_getSetModState", "Check call to SDL_GetModState and SDL_SetModState", TEST_ENABLED };
Jan 11, 2013
Jan 11, 2013
675
676
static const SDLTest_TestCaseReference keyboardTest7 =
May 18, 2013
May 18, 2013
677
{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
Jan 11, 2013
Jan 11, 2013
678
Jan 12, 2013
Jan 12, 2013
679
static const SDLTest_TestCaseReference keyboardTest8 =
May 18, 2013
May 18, 2013
680
{ (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED };
Jan 12, 2013
Jan 12, 2013
681
682
static const SDLTest_TestCaseReference keyboardTest9 =
May 18, 2013
May 18, 2013
683
{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
Jan 12, 2013
Jan 12, 2013
684
Jan 13, 2013
Jan 13, 2013
685
static const SDLTest_TestCaseReference keyboardTest10 =
May 18, 2013
May 18, 2013
686
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
Jan 13, 2013
Jan 13, 2013
687
688
static const SDLTest_TestCaseReference keyboardTest11 =
May 18, 2013
May 18, 2013
689
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
Jan 13, 2013
Jan 13, 2013
690
691
static const SDLTest_TestCaseReference keyboardTest12 =
May 18, 2013
May 18, 2013
692
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
Jan 13, 2013
Jan 13, 2013
693
Mar 9, 2013
Mar 9, 2013
694
static const SDLTest_TestCaseReference keyboardTest13 =
May 18, 2013
May 18, 2013
695
{ (SDLTest_TestCaseFp)keyboard_getKeyNameNegative, "keyboard_getKeyNameNegative", "Check call to SDL_GetKeyName with invalid data", TEST_ENABLED };
Mar 9, 2013
Mar 9, 2013
696
697
static const SDLTest_TestCaseReference keyboardTest14 =
May 18, 2013
May 18, 2013
698
{ (SDLTest_TestCaseFp)keyboard_getScancodeNameNegative, "keyboard_getScancodeNameNegative", "Check call to SDL_GetScancodeName with invalid data", TEST_ENABLED };
Mar 9, 2013
Mar 9, 2013
699
700
701
/* Sequence of Keyboard test cases */
static const SDLTest_TestCaseReference *keyboardTests[] = {
May 18, 2013
May 18, 2013
702
703
704
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6,
&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12,
&keyboardTest13, &keyboardTest14, NULL
705
706
707
708
};
/* Keyboard test suite (global) */
SDLTest_TestSuiteReference keyboardTestSuite = {
May 18, 2013
May 18, 2013
709
710
711
712
"Keyboard",
NULL,
keyboardTests,
NULL