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