diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testautomation_video.c')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/testautomation_video.c | 2571 |
1 files changed, 2571 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testautomation_video.c b/src/contrib/SDL-3.2.20/test/testautomation_video.c new file mode 100644 index 0000000..09c55e7 --- /dev/null +++ b/src/contrib/SDL-3.2.20/test/testautomation_video.c | |||
@@ -0,0 +1,2571 @@ | |||
1 | /** | ||
2 | * Video test suite | ||
3 | */ | ||
4 | #include <SDL3/SDL.h> | ||
5 | #include <SDL3/SDL_test.h> | ||
6 | #include "testautomation_suites.h" | ||
7 | |||
8 | /* Private helpers */ | ||
9 | |||
10 | /** | ||
11 | * Create a test window | ||
12 | */ | ||
13 | static SDL_Window *createVideoSuiteTestWindow(const char *title) | ||
14 | { | ||
15 | SDL_Window *window; | ||
16 | SDL_Window **windows; | ||
17 | SDL_Event event; | ||
18 | int w, h; | ||
19 | int count; | ||
20 | SDL_WindowFlags flags; | ||
21 | bool needs_renderer = false; | ||
22 | bool needs_events_pumped = false; | ||
23 | |||
24 | /* Standard window */ | ||
25 | w = SDLTest_RandomIntegerInRange(320, 1024); | ||
26 | h = SDLTest_RandomIntegerInRange(320, 768); | ||
27 | flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS; | ||
28 | |||
29 | window = SDL_CreateWindow(title, w, h, flags); | ||
30 | SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%" SDL_PRIu64 ")", w, h, flags); | ||
31 | SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL"); | ||
32 | |||
33 | /* Check the window is available in the window list */ | ||
34 | windows = SDL_GetWindows(&count); | ||
35 | SDLTest_AssertCheck(windows != NULL, "Validate that returned window list is not NULL"); | ||
36 | SDLTest_AssertCheck(windows[0] == window, "Validate that the window is first in the window list"); | ||
37 | SDL_free(windows); | ||
38 | |||
39 | /* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen. | ||
40 | * This is required for the mouse/keyboard grab tests to pass. | ||
41 | */ | ||
42 | if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) { | ||
43 | needs_renderer = true; | ||
44 | } else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { | ||
45 | /* Try to detect if the x11 driver is running under XWayland */ | ||
46 | const char *session_type = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "XDG_SESSION_TYPE"); | ||
47 | if (session_type && SDL_strcasecmp(session_type, "wayland") == 0) { | ||
48 | needs_renderer = true; | ||
49 | } | ||
50 | |||
51 | /* X11 needs the initial events pumped, or it can erroneously deliver old configuration events at a later time. */ | ||
52 | needs_events_pumped = true; | ||
53 | } | ||
54 | |||
55 | if (needs_renderer) { | ||
56 | SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL); | ||
57 | if (renderer) { | ||
58 | SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); | ||
59 | SDL_RenderClear(renderer); | ||
60 | SDL_RenderPresent(renderer); | ||
61 | |||
62 | /* Some desktops don't display the window immediately after presentation, | ||
63 | * so delay to give the window time to actually appear on the desktop. | ||
64 | */ | ||
65 | SDL_Delay(100); | ||
66 | } else { | ||
67 | SDLTest_Log("Unable to create a renderer, some tests may fail on Wayland/XWayland"); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | if (needs_events_pumped) { | ||
72 | /* Pump out the event queue */ | ||
73 | while (SDL_PollEvent(&event)) { | ||
74 | } | ||
75 | } | ||
76 | |||
77 | return window; | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * Destroy test window | ||
82 | */ | ||
83 | static void destroyVideoSuiteTestWindow(SDL_Window *window) | ||
84 | { | ||
85 | if (window != NULL) { | ||
86 | SDL_Renderer *renderer = SDL_GetRenderer(window); | ||
87 | if (renderer) { | ||
88 | SDL_DestroyRenderer(renderer); | ||
89 | } | ||
90 | SDL_DestroyWindow(window); | ||
91 | window = NULL; | ||
92 | SDLTest_AssertPass("Call to SDL_DestroyWindow()"); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | /* Test case functions */ | ||
97 | |||
98 | /** | ||
99 | * Enable and disable screensaver while checking state | ||
100 | */ | ||
101 | static int SDLCALL video_enableDisableScreensaver(void *arg) | ||
102 | { | ||
103 | bool initialResult; | ||
104 | bool result; | ||
105 | |||
106 | /* Get current state and proceed according to current state */ | ||
107 | initialResult = SDL_ScreenSaverEnabled(); | ||
108 | SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()"); | ||
109 | if (initialResult == true) { | ||
110 | |||
111 | /* Currently enabled: disable first, then enable again */ | ||
112 | |||
113 | /* Disable screensaver and check */ | ||
114 | SDL_DisableScreenSaver(); | ||
115 | SDLTest_AssertPass("Call to SDL_DisableScreenSaver()"); | ||
116 | result = SDL_ScreenSaverEnabled(); | ||
117 | SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()"); | ||
118 | SDLTest_AssertCheck(result == false, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", false, result); | ||
119 | |||
120 | /* Enable screensaver and check */ | ||
121 | SDL_EnableScreenSaver(); | ||
122 | SDLTest_AssertPass("Call to SDL_EnableScreenSaver()"); | ||
123 | result = SDL_ScreenSaverEnabled(); | ||
124 | SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()"); | ||
125 | SDLTest_AssertCheck(result == true, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", true, result); | ||
126 | |||
127 | } else { | ||
128 | |||
129 | /* Currently disabled: enable first, then disable again */ | ||
130 | |||
131 | /* Enable screensaver and check */ | ||
132 | SDL_EnableScreenSaver(); | ||
133 | SDLTest_AssertPass("Call to SDL_EnableScreenSaver()"); | ||
134 | result = SDL_ScreenSaverEnabled(); | ||
135 | SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()"); | ||
136 | SDLTest_AssertCheck(result == true, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", true, result); | ||
137 | |||
138 | /* Disable screensaver and check */ | ||
139 | SDL_DisableScreenSaver(); | ||
140 | SDLTest_AssertPass("Call to SDL_DisableScreenSaver()"); | ||
141 | result = SDL_ScreenSaverEnabled(); | ||
142 | SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()"); | ||
143 | SDLTest_AssertCheck(result == false, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", false, result); | ||
144 | } | ||
145 | |||
146 | return TEST_COMPLETED; | ||
147 | } | ||
148 | |||
149 | /** | ||
150 | * Tests the functionality of the SDL_CreateWindow function using different sizes | ||
151 | */ | ||
152 | static int SDLCALL video_createWindowVariousSizes(void *arg) | ||
153 | { | ||
154 | SDL_Window *window; | ||
155 | const char *title = "video_createWindowVariousSizes Test Window"; | ||
156 | int w = 0, h = 0; | ||
157 | int wVariation, hVariation; | ||
158 | |||
159 | for (wVariation = 0; wVariation < 3; wVariation++) { | ||
160 | for (hVariation = 0; hVariation < 3; hVariation++) { | ||
161 | switch (wVariation) { | ||
162 | case 0: | ||
163 | /* Width of 1 */ | ||
164 | w = 1; | ||
165 | break; | ||
166 | case 1: | ||
167 | /* Random "normal" width */ | ||
168 | w = SDLTest_RandomIntegerInRange(320, 1920); | ||
169 | break; | ||
170 | case 2: | ||
171 | /* Random "large" width */ | ||
172 | w = SDLTest_RandomIntegerInRange(2048, 4095); | ||
173 | break; | ||
174 | } | ||
175 | |||
176 | switch (hVariation) { | ||
177 | case 0: | ||
178 | /* Height of 1 */ | ||
179 | h = 1; | ||
180 | break; | ||
181 | case 1: | ||
182 | /* Random "normal" height */ | ||
183 | h = SDLTest_RandomIntegerInRange(320, 1080); | ||
184 | break; | ||
185 | case 2: | ||
186 | /* Random "large" height */ | ||
187 | h = SDLTest_RandomIntegerInRange(2048, 4095); | ||
188 | break; | ||
189 | } | ||
190 | |||
191 | window = SDL_CreateWindow(title, w, h, 0); | ||
192 | SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,SHOWN)", w, h); | ||
193 | SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL"); | ||
194 | |||
195 | /* Clean up */ | ||
196 | destroyVideoSuiteTestWindow(window); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | return TEST_COMPLETED; | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Tests the functionality of the SDL_CreateWindow function using different flags | ||
205 | */ | ||
206 | static int SDLCALL video_createWindowVariousFlags(void *arg) | ||
207 | { | ||
208 | SDL_Window *window; | ||
209 | const char *title = "video_createWindowVariousFlags Test Window"; | ||
210 | int w, h; | ||
211 | int fVariation; | ||
212 | SDL_WindowFlags flags; | ||
213 | |||
214 | /* Standard window */ | ||
215 | w = SDLTest_RandomIntegerInRange(320, 1024); | ||
216 | h = SDLTest_RandomIntegerInRange(320, 768); | ||
217 | |||
218 | for (fVariation = 1; fVariation < 14; fVariation++) { | ||
219 | switch (fVariation) { | ||
220 | default: | ||
221 | case 1: | ||
222 | flags = SDL_WINDOW_FULLSCREEN; | ||
223 | /* Skip - blanks screen; comment out next line to run test */ | ||
224 | continue; | ||
225 | break; | ||
226 | case 2: | ||
227 | flags = SDL_WINDOW_OPENGL; | ||
228 | /* Skip - not every video driver supports OpenGL; comment out next line to run test */ | ||
229 | continue; | ||
230 | break; | ||
231 | case 3: | ||
232 | flags = 0; | ||
233 | break; | ||
234 | case 4: | ||
235 | flags = SDL_WINDOW_HIDDEN; | ||
236 | break; | ||
237 | case 5: | ||
238 | flags = SDL_WINDOW_BORDERLESS; | ||
239 | break; | ||
240 | case 6: | ||
241 | flags = SDL_WINDOW_RESIZABLE; | ||
242 | break; | ||
243 | case 7: | ||
244 | flags = SDL_WINDOW_MINIMIZED; | ||
245 | break; | ||
246 | case 8: | ||
247 | flags = SDL_WINDOW_MAXIMIZED; | ||
248 | break; | ||
249 | case 9: | ||
250 | flags = SDL_WINDOW_MOUSE_GRABBED; | ||
251 | break; | ||
252 | case 10: | ||
253 | flags = SDL_WINDOW_INPUT_FOCUS; | ||
254 | break; | ||
255 | case 11: | ||
256 | flags = SDL_WINDOW_MOUSE_FOCUS; | ||
257 | break; | ||
258 | case 12: | ||
259 | flags = SDL_WINDOW_EXTERNAL; | ||
260 | break; | ||
261 | case 13: | ||
262 | flags = SDL_WINDOW_KEYBOARD_GRABBED; | ||
263 | break; | ||
264 | } | ||
265 | |||
266 | window = SDL_CreateWindow(title, w, h, flags); | ||
267 | SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%" SDL_PRIu64 ")", w, h, flags); | ||
268 | SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL"); | ||
269 | |||
270 | /* Clean up */ | ||
271 | destroyVideoSuiteTestWindow(window); | ||
272 | } | ||
273 | |||
274 | return TEST_COMPLETED; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * Tests the functionality of the SDL_GetWindowFlags function | ||
279 | */ | ||
280 | static int SDLCALL video_getWindowFlags(void *arg) | ||
281 | { | ||
282 | SDL_Window *window; | ||
283 | const char *title = "video_getWindowFlags Test Window"; | ||
284 | SDL_WindowFlags flags; | ||
285 | SDL_WindowFlags actualFlags; | ||
286 | |||
287 | /* Reliable flag set always set in test window */ | ||
288 | flags = 0; | ||
289 | |||
290 | /* Call against new test window */ | ||
291 | window = createVideoSuiteTestWindow(title); | ||
292 | if (window != NULL) { | ||
293 | actualFlags = SDL_GetWindowFlags(window); | ||
294 | SDLTest_AssertPass("Call to SDL_GetWindowFlags()"); | ||
295 | SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %" SDL_PRIu64 " set, got: %" SDL_PRIu64, flags, actualFlags); | ||
296 | } | ||
297 | |||
298 | /* Clean up */ | ||
299 | destroyVideoSuiteTestWindow(window); | ||
300 | |||
301 | return TEST_COMPLETED; | ||
302 | } | ||
303 | |||
304 | /** | ||
305 | * Tests the functionality of the SDL_GetFullscreenDisplayModes function | ||
306 | */ | ||
307 | static int SDLCALL video_getFullscreenDisplayModes(void *arg) | ||
308 | { | ||
309 | SDL_DisplayID *displays; | ||
310 | SDL_DisplayMode **modes; | ||
311 | int count; | ||
312 | int i; | ||
313 | |||
314 | /* Get number of displays */ | ||
315 | displays = SDL_GetDisplays(NULL); | ||
316 | if (displays) { | ||
317 | SDLTest_AssertPass("Call to SDL_GetDisplays()"); | ||
318 | |||
319 | /* Make call for each display */ | ||
320 | for (i = 0; displays[i]; ++i) { | ||
321 | modes = SDL_GetFullscreenDisplayModes(displays[i], &count); | ||
322 | SDLTest_AssertPass("Call to SDL_GetFullscreenDisplayModes(%" SDL_PRIu32 ")", displays[i]); | ||
323 | SDLTest_AssertCheck(modes != NULL, "Validate returned value from function; expected != NULL; got: %p", modes); | ||
324 | SDLTest_AssertCheck(count >= 0, "Validate number of modes; expected: >= 0; got: %d", count); | ||
325 | SDL_free(modes); | ||
326 | } | ||
327 | SDL_free(displays); | ||
328 | } | ||
329 | |||
330 | return TEST_COMPLETED; | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against current resolution | ||
335 | */ | ||
336 | static int SDLCALL video_getClosestDisplayModeCurrentResolution(void *arg) | ||
337 | { | ||
338 | SDL_DisplayID *displays; | ||
339 | SDL_DisplayMode **modes; | ||
340 | SDL_DisplayMode current; | ||
341 | SDL_DisplayMode closest; | ||
342 | int i, result, num_modes; | ||
343 | |||
344 | /* Get number of displays */ | ||
345 | displays = SDL_GetDisplays(NULL); | ||
346 | if (displays) { | ||
347 | SDLTest_AssertPass("Call to SDL_GetDisplays()"); | ||
348 | |||
349 | /* Make calls for each display */ | ||
350 | for (i = 0; displays[i]; ++i) { | ||
351 | SDLTest_Log("Testing against display: %" SDL_PRIu32, displays[i]); | ||
352 | |||
353 | /* Get first display mode to get a sane resolution; this should always work */ | ||
354 | modes = SDL_GetFullscreenDisplayModes(displays[i], &num_modes); | ||
355 | SDLTest_AssertPass("Call to SDL_GetDisplayModes()"); | ||
356 | SDLTest_Assert(modes != NULL, "Verify returned value is not NULL"); | ||
357 | if (num_modes > 0) { | ||
358 | SDL_memcpy(¤t, modes[0], sizeof(current)); | ||
359 | |||
360 | /* Make call */ | ||
361 | result = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, false, &closest); | ||
362 | SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)"); | ||
363 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
364 | |||
365 | /* Check that one gets the current resolution back again */ | ||
366 | if (result == 0) { | ||
367 | SDLTest_AssertCheck(closest.w == current.w, | ||
368 | "Verify returned width matches current width; expected: %d, got: %d", | ||
369 | current.w, closest.w); | ||
370 | SDLTest_AssertCheck(closest.h == current.h, | ||
371 | "Verify returned height matches current height; expected: %d, got: %d", | ||
372 | current.h, closest.h); | ||
373 | } | ||
374 | } | ||
375 | SDL_free(modes); | ||
376 | } | ||
377 | SDL_free(displays); | ||
378 | } | ||
379 | |||
380 | return TEST_COMPLETED; | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against random resolution | ||
385 | */ | ||
386 | static int SDLCALL video_getClosestDisplayModeRandomResolution(void *arg) | ||
387 | { | ||
388 | SDL_DisplayID *displays; | ||
389 | SDL_DisplayMode target; | ||
390 | SDL_DisplayMode closest; | ||
391 | int i; | ||
392 | int variation; | ||
393 | |||
394 | /* Get number of displays */ | ||
395 | displays = SDL_GetDisplays(NULL); | ||
396 | if (displays) { | ||
397 | SDLTest_AssertPass("Call to SDL_GetDisplays()"); | ||
398 | |||
399 | /* Make calls for each display */ | ||
400 | for (i = 0; displays[i]; ++i) { | ||
401 | SDLTest_Log("Testing against display: %" SDL_PRIu32, displays[i]); | ||
402 | |||
403 | for (variation = 0; variation < 16; variation++) { | ||
404 | |||
405 | /* Set random constraints */ | ||
406 | SDL_zero(target); | ||
407 | target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; | ||
408 | target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; | ||
409 | target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f; | ||
410 | |||
411 | /* Make call; may or may not find anything, so don't validate any further */ | ||
412 | SDL_GetClosestFullscreenDisplayMode(displays[i], target.w, target.h, target.refresh_rate, false, &closest); | ||
413 | SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d)", variation); | ||
414 | } | ||
415 | } | ||
416 | SDL_free(displays); | ||
417 | } | ||
418 | |||
419 | return TEST_COMPLETED; | ||
420 | } | ||
421 | |||
422 | /** | ||
423 | * Tests call to SDL_GetWindowFullscreenMode | ||
424 | * | ||
425 | * \sa SDL_GetWindowFullscreenMode | ||
426 | */ | ||
427 | static int SDLCALL video_getWindowDisplayMode(void *arg) | ||
428 | { | ||
429 | SDL_Window *window; | ||
430 | const char *title = "video_getWindowDisplayMode Test Window"; | ||
431 | const SDL_DisplayMode *mode; | ||
432 | |||
433 | /* Call against new test window */ | ||
434 | window = createVideoSuiteTestWindow(title); | ||
435 | if (window != NULL) { | ||
436 | mode = SDL_GetWindowFullscreenMode(window); | ||
437 | SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode()"); | ||
438 | SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode); | ||
439 | } | ||
440 | |||
441 | /* Clean up */ | ||
442 | destroyVideoSuiteTestWindow(window); | ||
443 | |||
444 | return TEST_COMPLETED; | ||
445 | } | ||
446 | |||
447 | /* Helper function that checks for an 'Invalid window' error */ | ||
448 | static void checkInvalidWindowError(void) | ||
449 | { | ||
450 | const char *invalidWindowError = "Invalid window"; | ||
451 | const char *lastError; | ||
452 | |||
453 | lastError = SDL_GetError(); | ||
454 | SDLTest_AssertPass("SDL_GetError()"); | ||
455 | SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); | ||
456 | if (lastError != NULL) { | ||
457 | SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, | ||
458 | "SDL_GetError(): expected message '%s', was message: '%s'", | ||
459 | invalidWindowError, | ||
460 | lastError); | ||
461 | SDL_ClearError(); | ||
462 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
463 | } | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * Tests call to SDL_GetWindowFullscreenMode with invalid input | ||
468 | * | ||
469 | * \sa SDL_GetWindowFullscreenMode | ||
470 | */ | ||
471 | static int SDLCALL video_getWindowDisplayModeNegative(void *arg) | ||
472 | { | ||
473 | const SDL_DisplayMode *mode; | ||
474 | |||
475 | /* Call against invalid window */ | ||
476 | mode = SDL_GetWindowFullscreenMode(NULL); | ||
477 | SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode(window=NULL)"); | ||
478 | SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode); | ||
479 | checkInvalidWindowError(); | ||
480 | |||
481 | return TEST_COMPLETED; | ||
482 | } | ||
483 | |||
484 | /* Helper for setting and checking the window mouse grab state */ | ||
485 | static void setAndCheckWindowMouseGrabState(SDL_Window *window, bool desiredState) | ||
486 | { | ||
487 | bool currentState; | ||
488 | |||
489 | /* Set state */ | ||
490 | SDL_SetWindowMouseGrab(window, desiredState); | ||
491 | SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == false) ? "false" : "true"); | ||
492 | |||
493 | /* Get and check state */ | ||
494 | currentState = SDL_GetWindowMouseGrab(window); | ||
495 | SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()"); | ||
496 | SDLTest_AssertCheck( | ||
497 | currentState == desiredState, | ||
498 | "Validate returned state; expected: %s, got: %s", | ||
499 | (desiredState == false) ? "false" : "true", | ||
500 | (currentState == false) ? "false" : "true"); | ||
501 | |||
502 | if (desiredState) { | ||
503 | SDLTest_AssertCheck( | ||
504 | SDL_GetGrabbedWindow() == window, | ||
505 | "Grabbed window should be to our window"); | ||
506 | SDLTest_AssertCheck( | ||
507 | SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED, | ||
508 | "SDL_WINDOW_MOUSE_GRABBED should be set"); | ||
509 | } else { | ||
510 | SDLTest_AssertCheck( | ||
511 | !(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED), | ||
512 | "SDL_WINDOW_MOUSE_GRABBED should be unset"); | ||
513 | } | ||
514 | } | ||
515 | |||
516 | /* Helper for setting and checking the window keyboard grab state */ | ||
517 | static void setAndCheckWindowKeyboardGrabState(SDL_Window *window, bool desiredState) | ||
518 | { | ||
519 | bool currentState; | ||
520 | |||
521 | /* Set state */ | ||
522 | SDL_SetWindowKeyboardGrab(window, desiredState); | ||
523 | SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == false) ? "false" : "true"); | ||
524 | |||
525 | /* Get and check state */ | ||
526 | currentState = SDL_GetWindowKeyboardGrab(window); | ||
527 | SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()"); | ||
528 | SDLTest_AssertCheck( | ||
529 | currentState == desiredState, | ||
530 | "Validate returned state; expected: %s, got: %s", | ||
531 | (desiredState == false) ? "false" : "true", | ||
532 | (currentState == false) ? "false" : "true"); | ||
533 | |||
534 | if (desiredState) { | ||
535 | SDLTest_AssertCheck( | ||
536 | SDL_GetGrabbedWindow() == window, | ||
537 | "Grabbed window should be set to our window"); | ||
538 | SDLTest_AssertCheck( | ||
539 | SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED, | ||
540 | "SDL_WINDOW_KEYBOARD_GRABBED should be set"); | ||
541 | } else { | ||
542 | SDLTest_AssertCheck( | ||
543 | !(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED), | ||
544 | "SDL_WINDOW_KEYBOARD_GRABBED should be unset"); | ||
545 | } | ||
546 | } | ||
547 | |||
548 | /** | ||
549 | * Tests keyboard and mouse grab support | ||
550 | * | ||
551 | * \sa SDL_GetWindowMouseGrab | ||
552 | * \sa SDL_GetWindowKeyboardGrab | ||
553 | * \sa SDL_SetWindowMouseGrab | ||
554 | * \sa SDL_SetWindowKeyboardGrab | ||
555 | */ | ||
556 | static int SDLCALL video_getSetWindowGrab(void *arg) | ||
557 | { | ||
558 | const char *title = "video_getSetWindowGrab Test Window"; | ||
559 | SDL_Window *window; | ||
560 | bool originalMouseState, originalKeyboardState; | ||
561 | bool hasFocusGained = false; | ||
562 | |||
563 | /* Call against new test window */ | ||
564 | window = createVideoSuiteTestWindow(title); | ||
565 | if (!window) { | ||
566 | return TEST_ABORTED; | ||
567 | } | ||
568 | |||
569 | /* Need to raise the window to have and SDL_EVENT_WINDOW_FOCUS_GAINED, | ||
570 | * so that the window gets the flags SDL_WINDOW_INPUT_FOCUS, | ||
571 | * so that it can be "grabbed" */ | ||
572 | SDL_RaiseWindow(window); | ||
573 | |||
574 | if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS)) { | ||
575 | int count = 0; | ||
576 | SDL_Event evt; | ||
577 | SDL_zero(evt); | ||
578 | while (!hasFocusGained && count++ < 3) { | ||
579 | while (SDL_PollEvent(&evt)) { | ||
580 | if (evt.type == SDL_EVENT_WINDOW_FOCUS_GAINED) { | ||
581 | hasFocusGained = true; | ||
582 | } | ||
583 | } | ||
584 | } | ||
585 | } else { | ||
586 | hasFocusGained = true; | ||
587 | } | ||
588 | |||
589 | SDLTest_AssertCheck(hasFocusGained == true, "Expectded window with focus"); | ||
590 | |||
591 | /* Get state */ | ||
592 | originalMouseState = SDL_GetWindowMouseGrab(window); | ||
593 | SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()"); | ||
594 | originalKeyboardState = SDL_GetWindowKeyboardGrab(window); | ||
595 | SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()"); | ||
596 | |||
597 | /* F */ | ||
598 | setAndCheckWindowKeyboardGrabState(window, false); | ||
599 | setAndCheckWindowMouseGrabState(window, false); | ||
600 | SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL, | ||
601 | "Expected NULL grabbed window"); | ||
602 | |||
603 | /* F --> F */ | ||
604 | setAndCheckWindowMouseGrabState(window, false); | ||
605 | setAndCheckWindowKeyboardGrabState(window, false); | ||
606 | SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL, | ||
607 | "Expected NULL grabbed window"); | ||
608 | |||
609 | /* F --> T */ | ||
610 | setAndCheckWindowMouseGrabState(window, true); | ||
611 | setAndCheckWindowKeyboardGrabState(window, true); | ||
612 | |||
613 | /* T --> T */ | ||
614 | setAndCheckWindowKeyboardGrabState(window, true); | ||
615 | setAndCheckWindowMouseGrabState(window, true); | ||
616 | |||
617 | /* M: T --> F */ | ||
618 | /* K: T --> T */ | ||
619 | setAndCheckWindowKeyboardGrabState(window, true); | ||
620 | setAndCheckWindowMouseGrabState(window, false); | ||
621 | |||
622 | /* M: F --> T */ | ||
623 | /* K: T --> F */ | ||
624 | setAndCheckWindowMouseGrabState(window, true); | ||
625 | setAndCheckWindowKeyboardGrabState(window, false); | ||
626 | |||
627 | /* M: T --> F */ | ||
628 | /* K: F --> F */ | ||
629 | setAndCheckWindowMouseGrabState(window, false); | ||
630 | setAndCheckWindowKeyboardGrabState(window, false); | ||
631 | SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL, | ||
632 | "Expected NULL grabbed window"); | ||
633 | |||
634 | /* Negative tests */ | ||
635 | SDL_GetWindowMouseGrab(NULL); | ||
636 | SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab(window=NULL)"); | ||
637 | checkInvalidWindowError(); | ||
638 | |||
639 | SDL_GetWindowKeyboardGrab(NULL); | ||
640 | SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)"); | ||
641 | checkInvalidWindowError(); | ||
642 | |||
643 | SDL_SetWindowMouseGrab(NULL, false); | ||
644 | SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(window=NULL,false)"); | ||
645 | checkInvalidWindowError(); | ||
646 | |||
647 | SDL_SetWindowKeyboardGrab(NULL, false); | ||
648 | SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,false)"); | ||
649 | checkInvalidWindowError(); | ||
650 | |||
651 | SDL_SetWindowMouseGrab(NULL, true); | ||
652 | SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(window=NULL,true)"); | ||
653 | checkInvalidWindowError(); | ||
654 | |||
655 | SDL_SetWindowKeyboardGrab(NULL, true); | ||
656 | SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,true)"); | ||
657 | checkInvalidWindowError(); | ||
658 | |||
659 | /* Restore state */ | ||
660 | setAndCheckWindowMouseGrabState(window, originalMouseState); | ||
661 | setAndCheckWindowKeyboardGrabState(window, originalKeyboardState); | ||
662 | |||
663 | /* Clean up */ | ||
664 | destroyVideoSuiteTestWindow(window); | ||
665 | |||
666 | return TEST_COMPLETED; | ||
667 | } | ||
668 | |||
669 | /** | ||
670 | * Tests call to SDL_GetWindowID and SDL_GetWindowFromID | ||
671 | * | ||
672 | * \sa SDL_GetWindowID | ||
673 | * \sa SDL_SetWindowFromID | ||
674 | */ | ||
675 | static int SDLCALL video_getWindowId(void *arg) | ||
676 | { | ||
677 | const char *title = "video_getWindowId Test Window"; | ||
678 | SDL_Window *window; | ||
679 | SDL_Window *result; | ||
680 | Uint32 id, randomId; | ||
681 | |||
682 | /* Call against new test window */ | ||
683 | window = createVideoSuiteTestWindow(title); | ||
684 | if (!window) { | ||
685 | return TEST_ABORTED; | ||
686 | } | ||
687 | |||
688 | /* Get ID */ | ||
689 | id = SDL_GetWindowID(window); | ||
690 | SDLTest_AssertPass("Call to SDL_GetWindowID()"); | ||
691 | |||
692 | /* Get window from ID */ | ||
693 | result = SDL_GetWindowFromID(id); | ||
694 | SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 ")", id); | ||
695 | SDLTest_AssertCheck(result == window, "Verify result matches window pointer"); | ||
696 | |||
697 | /* Get window from random large ID, no result check */ | ||
698 | randomId = SDLTest_RandomIntegerInRange(UINT8_MAX, UINT16_MAX); | ||
699 | result = SDL_GetWindowFromID(randomId); | ||
700 | SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/random_large)", randomId); | ||
701 | |||
702 | /* Get window from 0 and Uint32 max ID, no result check */ | ||
703 | result = SDL_GetWindowFromID(0); | ||
704 | SDLTest_AssertPass("Call to SDL_GetWindowID(0)"); | ||
705 | result = SDL_GetWindowFromID(UINT32_MAX); | ||
706 | SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)"); | ||
707 | |||
708 | /* Clean up */ | ||
709 | destroyVideoSuiteTestWindow(window); | ||
710 | |||
711 | /* Get window from ID for closed window */ | ||
712 | result = SDL_GetWindowFromID(id); | ||
713 | SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/closed_window)", id); | ||
714 | SDLTest_AssertCheck(result == NULL, "Verify result is NULL"); | ||
715 | |||
716 | /* Negative test */ | ||
717 | SDL_ClearError(); | ||
718 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
719 | id = SDL_GetWindowID(NULL); | ||
720 | SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)"); | ||
721 | checkInvalidWindowError(); | ||
722 | |||
723 | return TEST_COMPLETED; | ||
724 | } | ||
725 | |||
726 | /** | ||
727 | * Tests call to SDL_GetWindowPixelFormat | ||
728 | * | ||
729 | * \sa SDL_GetWindowPixelFormat | ||
730 | */ | ||
731 | static int SDLCALL video_getWindowPixelFormat(void *arg) | ||
732 | { | ||
733 | const char *title = "video_getWindowPixelFormat Test Window"; | ||
734 | SDL_Window *window; | ||
735 | SDL_PixelFormat format; | ||
736 | |||
737 | /* Call against new test window */ | ||
738 | window = createVideoSuiteTestWindow(title); | ||
739 | if (!window) { | ||
740 | return TEST_ABORTED; | ||
741 | } | ||
742 | |||
743 | /* Get format */ | ||
744 | format = SDL_GetWindowPixelFormat(window); | ||
745 | SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()"); | ||
746 | SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != SDL_PIXELFORMAT_UNKNOWN, got: SDL_PIXELFORMAT_UNKNOWN"); | ||
747 | |||
748 | /* Clean up */ | ||
749 | destroyVideoSuiteTestWindow(window); | ||
750 | |||
751 | /* Negative test */ | ||
752 | SDL_ClearError(); | ||
753 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
754 | format = SDL_GetWindowPixelFormat(NULL); | ||
755 | SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)"); | ||
756 | checkInvalidWindowError(); | ||
757 | |||
758 | return TEST_COMPLETED; | ||
759 | } | ||
760 | |||
761 | |||
762 | static bool getPositionFromEvent(int *x, int *y) | ||
763 | { | ||
764 | bool ret = false; | ||
765 | SDL_Event evt; | ||
766 | SDL_zero(evt); | ||
767 | while (SDL_PollEvent(&evt)) { | ||
768 | if (evt.type == SDL_EVENT_WINDOW_MOVED) { | ||
769 | *x = evt.window.data1; | ||
770 | *y = evt.window.data2; | ||
771 | ret = true; | ||
772 | } | ||
773 | } | ||
774 | return ret; | ||
775 | } | ||
776 | |||
777 | static bool getSizeFromEvent(int *w, int *h) | ||
778 | { | ||
779 | bool ret = false; | ||
780 | SDL_Event evt; | ||
781 | SDL_zero(evt); | ||
782 | while (SDL_PollEvent(&evt)) { | ||
783 | if (evt.type == SDL_EVENT_WINDOW_RESIZED) { | ||
784 | *w = evt.window.data1; | ||
785 | *h = evt.window.data2; | ||
786 | ret = true; | ||
787 | } | ||
788 | } | ||
789 | return ret; | ||
790 | } | ||
791 | |||
792 | /** | ||
793 | * Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition | ||
794 | * | ||
795 | * \sa SDL_GetWindowPosition | ||
796 | * \sa SDL_SetWindowPosition | ||
797 | */ | ||
798 | static int SDLCALL video_getSetWindowPosition(void *arg) | ||
799 | { | ||
800 | const char *title = "video_getSetWindowPosition Test Window"; | ||
801 | SDL_Window *window; | ||
802 | int result; | ||
803 | int maxxVariation, maxyVariation; | ||
804 | int xVariation, yVariation; | ||
805 | int referenceX, referenceY; | ||
806 | int currentX, currentY; | ||
807 | int desiredX, desiredY; | ||
808 | SDL_Rect display_bounds; | ||
809 | |||
810 | /* Call against new test window */ | ||
811 | window = createVideoSuiteTestWindow(title); | ||
812 | if (!window) { | ||
813 | return TEST_ABORTED; | ||
814 | } | ||
815 | |||
816 | /* Sanity check */ | ||
817 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
818 | if (!SDL_SetWindowPosition(window, currentX, currentY)) { | ||
819 | SDLTest_Log("Skipping window positioning tests: %s reports window positioning as unsupported", SDL_GetCurrentVideoDriver()); | ||
820 | goto null_tests; | ||
821 | } | ||
822 | |||
823 | if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { | ||
824 | /* The X11 server allows arbitrary window placement, but compositing | ||
825 | * window managers such as GNOME and KDE force windows to be within | ||
826 | * desktop bounds. | ||
827 | */ | ||
828 | maxxVariation = 2; | ||
829 | maxyVariation = 2; | ||
830 | |||
831 | SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display_bounds); | ||
832 | } else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "cocoa") == 0) { | ||
833 | /* Platform doesn't allow windows with negative Y desktop bounds */ | ||
834 | maxxVariation = 4; | ||
835 | maxyVariation = 3; | ||
836 | |||
837 | SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display_bounds); | ||
838 | } else { | ||
839 | /* Platform allows windows to be placed out of bounds */ | ||
840 | maxxVariation = 4; | ||
841 | maxyVariation = 4; | ||
842 | |||
843 | SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display_bounds); | ||
844 | } | ||
845 | |||
846 | for (xVariation = 0; xVariation < maxxVariation; xVariation++) { | ||
847 | for (yVariation = 0; yVariation < maxyVariation; yVariation++) { | ||
848 | switch (xVariation) { | ||
849 | default: | ||
850 | case 0: | ||
851 | /* Zero X Position */ | ||
852 | desiredX = display_bounds.x > 0 ? display_bounds.x : 0; | ||
853 | break; | ||
854 | case 1: | ||
855 | /* Random X position inside screen */ | ||
856 | desiredX = SDLTest_RandomIntegerInRange(display_bounds.x + 1, display_bounds.x + 100); | ||
857 | break; | ||
858 | case 2: | ||
859 | /* Random X position outside screen (positive) */ | ||
860 | desiredX = SDLTest_RandomIntegerInRange(10000, 11000); | ||
861 | break; | ||
862 | case 3: | ||
863 | /* Random X position outside screen (negative) */ | ||
864 | desiredX = SDLTest_RandomIntegerInRange(-1000, -100); | ||
865 | break; | ||
866 | } | ||
867 | |||
868 | switch (yVariation) { | ||
869 | default: | ||
870 | case 0: | ||
871 | /* Zero Y Position */ | ||
872 | desiredY = display_bounds.y > 0 ? display_bounds.y : 0; | ||
873 | break; | ||
874 | case 1: | ||
875 | /* Random Y position inside screen */ | ||
876 | desiredY = SDLTest_RandomIntegerInRange(display_bounds.y + 1, display_bounds.y + 100); | ||
877 | break; | ||
878 | case 2: | ||
879 | /* Random Y position outside screen (positive) */ | ||
880 | desiredY = SDLTest_RandomIntegerInRange(10000, 11000); | ||
881 | break; | ||
882 | case 3: | ||
883 | /* Random Y position outside screen (negative) */ | ||
884 | desiredY = SDLTest_RandomIntegerInRange(-1000, -100); | ||
885 | break; | ||
886 | } | ||
887 | |||
888 | /* Set position */ | ||
889 | SDL_SetWindowPosition(window, desiredX, desiredY); | ||
890 | SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY); | ||
891 | |||
892 | result = SDL_SyncWindow(window); | ||
893 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
894 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
895 | |||
896 | /* Get position */ | ||
897 | currentX = desiredX + 1; | ||
898 | currentY = desiredY + 1; | ||
899 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
900 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
901 | |||
902 | if (desiredX == currentX && desiredY == currentY) { | ||
903 | SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); | ||
904 | SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); | ||
905 | } else { | ||
906 | bool hasEvent; | ||
907 | /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size, | ||
908 | * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */ | ||
909 | currentX = desiredX + 1; | ||
910 | currentY = desiredY + 1; | ||
911 | hasEvent = getPositionFromEvent(¤tX, ¤tY); | ||
912 | SDLTest_AssertCheck(hasEvent == true, "Changing position was not honored by WM, checking present of SDL_EVENT_WINDOW_MOVED"); | ||
913 | if (hasEvent) { | ||
914 | SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position is the position from SDL event; expected: %d, got: %d", desiredX, currentX); | ||
915 | SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position is the position from SDL event; expected: %d, got: %d", desiredY, currentY); | ||
916 | } | ||
917 | } | ||
918 | |||
919 | /* Get position X */ | ||
920 | currentX = desiredX + 1; | ||
921 | SDL_GetWindowPosition(window, ¤tX, NULL); | ||
922 | SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)"); | ||
923 | SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); | ||
924 | |||
925 | /* Get position Y */ | ||
926 | currentY = desiredY + 1; | ||
927 | SDL_GetWindowPosition(window, NULL, ¤tY); | ||
928 | SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)"); | ||
929 | SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); | ||
930 | } | ||
931 | } | ||
932 | |||
933 | null_tests: | ||
934 | |||
935 | /* Dummy call with both pointers NULL */ | ||
936 | SDL_GetWindowPosition(window, NULL, NULL); | ||
937 | SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)"); | ||
938 | |||
939 | /* Clean up */ | ||
940 | destroyVideoSuiteTestWindow(window); | ||
941 | |||
942 | /* Set some 'magic' value for later check that nothing was changed */ | ||
943 | referenceX = SDLTest_RandomSint32(); | ||
944 | referenceY = SDLTest_RandomSint32(); | ||
945 | currentX = referenceX; | ||
946 | currentY = referenceY; | ||
947 | desiredX = SDLTest_RandomSint32(); | ||
948 | desiredY = SDLTest_RandomSint32(); | ||
949 | |||
950 | /* Negative tests */ | ||
951 | SDL_ClearError(); | ||
952 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
953 | SDL_GetWindowPosition(NULL, ¤tX, ¤tY); | ||
954 | SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)"); | ||
955 | SDLTest_AssertCheck( | ||
956 | currentX == referenceX && currentY == referenceY, | ||
957 | "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d", | ||
958 | referenceX, referenceY, | ||
959 | currentX, currentY); | ||
960 | checkInvalidWindowError(); | ||
961 | |||
962 | SDL_GetWindowPosition(NULL, NULL, NULL); | ||
963 | SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)"); | ||
964 | checkInvalidWindowError(); | ||
965 | |||
966 | SDL_SetWindowPosition(NULL, desiredX, desiredY); | ||
967 | SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)"); | ||
968 | checkInvalidWindowError(); | ||
969 | |||
970 | return TEST_COMPLETED; | ||
971 | } | ||
972 | |||
973 | /* Helper function that checks for an 'Invalid parameter' error */ | ||
974 | static void checkInvalidParameterError(void) | ||
975 | { | ||
976 | const char *invalidParameterError = "Parameter"; | ||
977 | const char *lastError; | ||
978 | |||
979 | lastError = SDL_GetError(); | ||
980 | SDLTest_AssertPass("SDL_GetError()"); | ||
981 | SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); | ||
982 | if (lastError != NULL) { | ||
983 | SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0, | ||
984 | "SDL_GetError(): expected message starts with '%s', was message: '%s'", | ||
985 | invalidParameterError, | ||
986 | lastError); | ||
987 | SDL_ClearError(); | ||
988 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
989 | } | ||
990 | } | ||
991 | |||
992 | /** | ||
993 | * Tests call to SDL_GetWindowSize and SDL_SetWindowSize | ||
994 | * | ||
995 | * \sa SDL_GetWindowSize | ||
996 | * \sa SDL_SetWindowSize | ||
997 | */ | ||
998 | static int SDLCALL video_getSetWindowSize(void *arg) | ||
999 | { | ||
1000 | const char *title = "video_getSetWindowSize Test Window"; | ||
1001 | SDL_Window *window; | ||
1002 | int result; | ||
1003 | SDL_Rect display; | ||
1004 | int maxwVariation, maxhVariation; | ||
1005 | int wVariation, hVariation; | ||
1006 | int referenceW, referenceH; | ||
1007 | int currentW, currentH; | ||
1008 | int desiredW, desiredH; | ||
1009 | |||
1010 | /* Get display bounds for size range */ | ||
1011 | result = SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display); | ||
1012 | SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); | ||
1013 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1014 | if (!result) { | ||
1015 | return TEST_ABORTED; | ||
1016 | } | ||
1017 | |||
1018 | /* Call against new test window */ | ||
1019 | window = createVideoSuiteTestWindow(title); | ||
1020 | if (!window) { | ||
1021 | return TEST_ABORTED; | ||
1022 | } | ||
1023 | |||
1024 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
1025 | if (!SDL_SetWindowSize(window, currentW, currentH)) { | ||
1026 | SDLTest_Log("Skipping window resize tests: %s reports window resizing as unsupported", SDL_GetCurrentVideoDriver()); | ||
1027 | goto null_tests; | ||
1028 | } | ||
1029 | |||
1030 | if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") == 0 || | ||
1031 | SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { | ||
1032 | /* Platform clips window size to screen size */ | ||
1033 | maxwVariation = 4; | ||
1034 | maxhVariation = 4; | ||
1035 | } else { | ||
1036 | /* Platform allows window size >= screen size */ | ||
1037 | maxwVariation = 5; | ||
1038 | maxhVariation = 5; | ||
1039 | } | ||
1040 | |||
1041 | for (wVariation = 0; wVariation < maxwVariation; wVariation++) { | ||
1042 | for (hVariation = 0; hVariation < maxhVariation; hVariation++) { | ||
1043 | switch (wVariation) { | ||
1044 | default: | ||
1045 | case 0: | ||
1046 | /* 1 Pixel Wide */ | ||
1047 | desiredW = 1; | ||
1048 | break; | ||
1049 | case 1: | ||
1050 | /* Random width inside screen */ | ||
1051 | desiredW = SDLTest_RandomIntegerInRange(1, 100); | ||
1052 | break; | ||
1053 | case 2: | ||
1054 | /* Width 1 pixel smaller than screen */ | ||
1055 | desiredW = display.w - 1; | ||
1056 | break; | ||
1057 | case 3: | ||
1058 | /* Width at screen size */ | ||
1059 | desiredW = display.w; | ||
1060 | break; | ||
1061 | case 4: | ||
1062 | /* Width 1 pixel larger than screen */ | ||
1063 | desiredW = display.w + 1; | ||
1064 | break; | ||
1065 | } | ||
1066 | |||
1067 | switch (hVariation) { | ||
1068 | default: | ||
1069 | case 0: | ||
1070 | /* 1 Pixel High */ | ||
1071 | desiredH = 1; | ||
1072 | break; | ||
1073 | case 1: | ||
1074 | /* Random height inside screen */ | ||
1075 | desiredH = SDLTest_RandomIntegerInRange(1, 100); | ||
1076 | break; | ||
1077 | case 2: | ||
1078 | /* Height 1 pixel smaller than screen */ | ||
1079 | desiredH = display.h - 1; | ||
1080 | break; | ||
1081 | case 3: | ||
1082 | /* Height at screen size */ | ||
1083 | desiredH = display.h; | ||
1084 | break; | ||
1085 | case 4: | ||
1086 | /* Height 1 pixel larger than screen */ | ||
1087 | desiredH = display.h + 1; | ||
1088 | break; | ||
1089 | } | ||
1090 | |||
1091 | /* Set size */ | ||
1092 | SDL_SetWindowSize(window, desiredW, desiredH); | ||
1093 | SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); | ||
1094 | |||
1095 | result = SDL_SyncWindow(window); | ||
1096 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
1097 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1098 | |||
1099 | /* Get size */ | ||
1100 | currentW = desiredW + 1; | ||
1101 | currentH = desiredH + 1; | ||
1102 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
1103 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
1104 | |||
1105 | if (desiredW == currentW && desiredH == currentH) { | ||
1106 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); | ||
1107 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); | ||
1108 | } else { | ||
1109 | bool hasEvent; | ||
1110 | /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size, | ||
1111 | * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */ | ||
1112 | currentW = desiredW + 1; | ||
1113 | currentH = desiredH + 1; | ||
1114 | hasEvent = getSizeFromEvent(¤tW, ¤tH); | ||
1115 | SDLTest_AssertCheck(hasEvent == true, "Changing size was not honored by WM, checking presence of SDL_EVENT_WINDOW_RESIZED"); | ||
1116 | if (hasEvent) { | ||
1117 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width is the one from SDL event; expected: %d, got: %d", desiredW, currentW); | ||
1118 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height is the one from SDL event; expected: %d, got: %d", desiredH, currentH); | ||
1119 | } | ||
1120 | } | ||
1121 | |||
1122 | |||
1123 | /* Get just width */ | ||
1124 | currentW = desiredW + 1; | ||
1125 | SDL_GetWindowSize(window, ¤tW, NULL); | ||
1126 | SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)"); | ||
1127 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); | ||
1128 | |||
1129 | /* Get just height */ | ||
1130 | currentH = desiredH + 1; | ||
1131 | SDL_GetWindowSize(window, NULL, ¤tH); | ||
1132 | SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)"); | ||
1133 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); | ||
1134 | } | ||
1135 | } | ||
1136 | |||
1137 | null_tests: | ||
1138 | |||
1139 | /* Dummy call with both pointers NULL */ | ||
1140 | SDL_GetWindowSize(window, NULL, NULL); | ||
1141 | SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)"); | ||
1142 | |||
1143 | /* Negative tests for parameter input */ | ||
1144 | SDL_ClearError(); | ||
1145 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
1146 | for (desiredH = -2; desiredH < 2; desiredH++) { | ||
1147 | for (desiredW = -2; desiredW < 2; desiredW++) { | ||
1148 | if (desiredW <= 0 || desiredH <= 0) { | ||
1149 | SDL_SetWindowSize(window, desiredW, desiredH); | ||
1150 | SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); | ||
1151 | checkInvalidParameterError(); | ||
1152 | } | ||
1153 | } | ||
1154 | } | ||
1155 | |||
1156 | /* Clean up */ | ||
1157 | destroyVideoSuiteTestWindow(window); | ||
1158 | |||
1159 | /* Set some 'magic' value for later check that nothing was changed */ | ||
1160 | referenceW = SDLTest_RandomSint32(); | ||
1161 | referenceH = SDLTest_RandomSint32(); | ||
1162 | currentW = referenceW; | ||
1163 | currentH = referenceH; | ||
1164 | desiredW = SDLTest_RandomSint32(); | ||
1165 | desiredH = SDLTest_RandomSint32(); | ||
1166 | |||
1167 | /* Negative tests for window input */ | ||
1168 | SDL_ClearError(); | ||
1169 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
1170 | SDL_GetWindowSize(NULL, ¤tW, ¤tH); | ||
1171 | SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)"); | ||
1172 | SDLTest_AssertCheck( | ||
1173 | currentW == referenceW && currentH == referenceH, | ||
1174 | "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", | ||
1175 | referenceW, referenceH, | ||
1176 | currentW, currentH); | ||
1177 | checkInvalidWindowError(); | ||
1178 | |||
1179 | SDL_GetWindowSize(NULL, NULL, NULL); | ||
1180 | SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)"); | ||
1181 | checkInvalidWindowError(); | ||
1182 | |||
1183 | SDL_SetWindowSize(NULL, desiredW, desiredH); | ||
1184 | SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)"); | ||
1185 | checkInvalidWindowError(); | ||
1186 | |||
1187 | return TEST_COMPLETED; | ||
1188 | } | ||
1189 | |||
1190 | /** | ||
1191 | * Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize | ||
1192 | * | ||
1193 | */ | ||
1194 | static int SDLCALL video_getSetWindowMinimumSize(void *arg) | ||
1195 | { | ||
1196 | const char *title = "video_getSetWindowMinimumSize Test Window"; | ||
1197 | SDL_Window *window; | ||
1198 | int result; | ||
1199 | SDL_Rect display; | ||
1200 | int wVariation, hVariation; | ||
1201 | int referenceW, referenceH; | ||
1202 | int currentW, currentH; | ||
1203 | int desiredW = 1; | ||
1204 | int desiredH = 1; | ||
1205 | |||
1206 | /* Get display bounds for size range */ | ||
1207 | result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display); | ||
1208 | SDLTest_AssertPass("SDL_GetDisplayBounds()"); | ||
1209 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1210 | if (!result) { | ||
1211 | return TEST_ABORTED; | ||
1212 | } | ||
1213 | |||
1214 | /* Call against new test window */ | ||
1215 | window = createVideoSuiteTestWindow(title); | ||
1216 | if (!window) { | ||
1217 | return TEST_ABORTED; | ||
1218 | } | ||
1219 | |||
1220 | for (wVariation = 0; wVariation < 5; wVariation++) { | ||
1221 | for (hVariation = 0; hVariation < 5; hVariation++) { | ||
1222 | switch (wVariation) { | ||
1223 | case 0: | ||
1224 | /* 1 Pixel Wide */ | ||
1225 | desiredW = 1; | ||
1226 | break; | ||
1227 | case 1: | ||
1228 | /* Random width inside screen */ | ||
1229 | desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); | ||
1230 | break; | ||
1231 | case 2: | ||
1232 | /* Width at screen size */ | ||
1233 | desiredW = display.w; | ||
1234 | break; | ||
1235 | } | ||
1236 | |||
1237 | switch (hVariation) { | ||
1238 | case 0: | ||
1239 | /* 1 Pixel High */ | ||
1240 | desiredH = 1; | ||
1241 | break; | ||
1242 | case 1: | ||
1243 | /* Random height inside screen */ | ||
1244 | desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); | ||
1245 | break; | ||
1246 | case 2: | ||
1247 | /* Height at screen size */ | ||
1248 | desiredH = display.h; | ||
1249 | break; | ||
1250 | case 4: | ||
1251 | /* Height 1 pixel larger than screen */ | ||
1252 | desiredH = display.h + 1; | ||
1253 | break; | ||
1254 | } | ||
1255 | |||
1256 | /* Set size */ | ||
1257 | SDL_SetWindowMinimumSize(window, desiredW, desiredH); | ||
1258 | SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); | ||
1259 | |||
1260 | /* Get size */ | ||
1261 | currentW = desiredW + 1; | ||
1262 | currentH = desiredH + 1; | ||
1263 | SDL_GetWindowMinimumSize(window, ¤tW, ¤tH); | ||
1264 | SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()"); | ||
1265 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); | ||
1266 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); | ||
1267 | |||
1268 | /* Get just width */ | ||
1269 | currentW = desiredW + 1; | ||
1270 | SDL_GetWindowMinimumSize(window, ¤tW, NULL); | ||
1271 | SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)"); | ||
1272 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); | ||
1273 | |||
1274 | /* Get just height */ | ||
1275 | currentH = desiredH + 1; | ||
1276 | SDL_GetWindowMinimumSize(window, NULL, ¤tH); | ||
1277 | SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)"); | ||
1278 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); | ||
1279 | } | ||
1280 | } | ||
1281 | |||
1282 | /* Dummy call with both pointers NULL */ | ||
1283 | SDL_GetWindowMinimumSize(window, NULL, NULL); | ||
1284 | SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)"); | ||
1285 | |||
1286 | /* Negative tests for parameter input */ | ||
1287 | SDL_ClearError(); | ||
1288 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
1289 | for (desiredH = -2; desiredH < 2; desiredH++) { | ||
1290 | for (desiredW = -2; desiredW < 2; desiredW++) { | ||
1291 | if (desiredW < 0 || desiredH < 0) { | ||
1292 | SDL_SetWindowMinimumSize(window, desiredW, desiredH); | ||
1293 | SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); | ||
1294 | checkInvalidParameterError(); | ||
1295 | } | ||
1296 | } | ||
1297 | } | ||
1298 | |||
1299 | /* Clean up */ | ||
1300 | destroyVideoSuiteTestWindow(window); | ||
1301 | |||
1302 | /* Set some 'magic' value for later check that nothing was changed */ | ||
1303 | referenceW = SDLTest_RandomSint32(); | ||
1304 | referenceH = SDLTest_RandomSint32(); | ||
1305 | currentW = referenceW; | ||
1306 | currentH = referenceH; | ||
1307 | desiredW = SDLTest_RandomSint32(); | ||
1308 | desiredH = SDLTest_RandomSint32(); | ||
1309 | |||
1310 | /* Negative tests for window input */ | ||
1311 | SDL_ClearError(); | ||
1312 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
1313 | SDL_GetWindowMinimumSize(NULL, ¤tW, ¤tH); | ||
1314 | SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)"); | ||
1315 | SDLTest_AssertCheck( | ||
1316 | currentW == referenceW && currentH == referenceH, | ||
1317 | "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", | ||
1318 | referenceW, referenceH, | ||
1319 | currentW, currentH); | ||
1320 | checkInvalidWindowError(); | ||
1321 | |||
1322 | SDL_GetWindowMinimumSize(NULL, NULL, NULL); | ||
1323 | SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)"); | ||
1324 | checkInvalidWindowError(); | ||
1325 | |||
1326 | SDL_SetWindowMinimumSize(NULL, desiredW, desiredH); | ||
1327 | SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)"); | ||
1328 | checkInvalidWindowError(); | ||
1329 | |||
1330 | return TEST_COMPLETED; | ||
1331 | } | ||
1332 | |||
1333 | /** | ||
1334 | * Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize | ||
1335 | * | ||
1336 | */ | ||
1337 | static int SDLCALL video_getSetWindowMaximumSize(void *arg) | ||
1338 | { | ||
1339 | const char *title = "video_getSetWindowMaximumSize Test Window"; | ||
1340 | SDL_Window *window; | ||
1341 | int result; | ||
1342 | SDL_Rect display; | ||
1343 | int wVariation, hVariation; | ||
1344 | int referenceW, referenceH; | ||
1345 | int currentW, currentH; | ||
1346 | int desiredW = 0, desiredH = 0; | ||
1347 | |||
1348 | /* Get display bounds for size range */ | ||
1349 | result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display); | ||
1350 | SDLTest_AssertPass("SDL_GetDisplayBounds()"); | ||
1351 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1352 | if (!result) { | ||
1353 | return TEST_ABORTED; | ||
1354 | } | ||
1355 | |||
1356 | /* Call against new test window */ | ||
1357 | window = createVideoSuiteTestWindow(title); | ||
1358 | if (!window) { | ||
1359 | return TEST_ABORTED; | ||
1360 | } | ||
1361 | |||
1362 | for (wVariation = 0; wVariation < 3; wVariation++) { | ||
1363 | for (hVariation = 0; hVariation < 3; hVariation++) { | ||
1364 | switch (wVariation) { | ||
1365 | case 0: | ||
1366 | /* 1 Pixel Wide */ | ||
1367 | desiredW = 1; | ||
1368 | break; | ||
1369 | case 1: | ||
1370 | /* Random width inside screen */ | ||
1371 | desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); | ||
1372 | break; | ||
1373 | case 2: | ||
1374 | /* Width at screen size */ | ||
1375 | desiredW = display.w; | ||
1376 | break; | ||
1377 | } | ||
1378 | |||
1379 | switch (hVariation) { | ||
1380 | case 0: | ||
1381 | /* 1 Pixel High */ | ||
1382 | desiredH = 1; | ||
1383 | break; | ||
1384 | case 1: | ||
1385 | /* Random height inside screen */ | ||
1386 | desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); | ||
1387 | break; | ||
1388 | case 2: | ||
1389 | /* Height at screen size */ | ||
1390 | desiredH = display.h; | ||
1391 | break; | ||
1392 | } | ||
1393 | |||
1394 | /* Set size */ | ||
1395 | SDL_SetWindowMaximumSize(window, desiredW, desiredH); | ||
1396 | SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); | ||
1397 | |||
1398 | /* Get size */ | ||
1399 | currentW = desiredW + 1; | ||
1400 | currentH = desiredH + 1; | ||
1401 | SDL_GetWindowMaximumSize(window, ¤tW, ¤tH); | ||
1402 | SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()"); | ||
1403 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); | ||
1404 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); | ||
1405 | |||
1406 | /* Get just width */ | ||
1407 | currentW = desiredW + 1; | ||
1408 | SDL_GetWindowMaximumSize(window, ¤tW, NULL); | ||
1409 | SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)"); | ||
1410 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); | ||
1411 | |||
1412 | /* Get just height */ | ||
1413 | currentH = desiredH + 1; | ||
1414 | SDL_GetWindowMaximumSize(window, NULL, ¤tH); | ||
1415 | SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)"); | ||
1416 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); | ||
1417 | } | ||
1418 | } | ||
1419 | |||
1420 | /* Dummy call with both pointers NULL */ | ||
1421 | SDL_GetWindowMaximumSize(window, NULL, NULL); | ||
1422 | SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)"); | ||
1423 | |||
1424 | /* Negative tests for parameter input */ | ||
1425 | SDL_ClearError(); | ||
1426 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
1427 | for (desiredH = -2; desiredH < 2; desiredH++) { | ||
1428 | for (desiredW = -2; desiredW < 2; desiredW++) { | ||
1429 | if (desiredW < 0 || desiredH < 0) { | ||
1430 | SDL_SetWindowMaximumSize(window, desiredW, desiredH); | ||
1431 | SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); | ||
1432 | checkInvalidParameterError(); | ||
1433 | } | ||
1434 | } | ||
1435 | } | ||
1436 | |||
1437 | /* Clean up */ | ||
1438 | destroyVideoSuiteTestWindow(window); | ||
1439 | |||
1440 | /* Set some 'magic' value for later check that nothing was changed */ | ||
1441 | referenceW = SDLTest_RandomSint32(); | ||
1442 | referenceH = SDLTest_RandomSint32(); | ||
1443 | currentW = referenceW; | ||
1444 | currentH = referenceH; | ||
1445 | desiredW = SDLTest_RandomSint32(); | ||
1446 | desiredH = SDLTest_RandomSint32(); | ||
1447 | |||
1448 | /* Negative tests */ | ||
1449 | SDL_ClearError(); | ||
1450 | SDLTest_AssertPass("Call to SDL_ClearError()"); | ||
1451 | SDL_GetWindowMaximumSize(NULL, ¤tW, ¤tH); | ||
1452 | SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)"); | ||
1453 | SDLTest_AssertCheck( | ||
1454 | currentW == referenceW && currentH == referenceH, | ||
1455 | "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", | ||
1456 | referenceW, referenceH, | ||
1457 | currentW, currentH); | ||
1458 | checkInvalidWindowError(); | ||
1459 | |||
1460 | SDL_GetWindowMaximumSize(NULL, NULL, NULL); | ||
1461 | SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)"); | ||
1462 | checkInvalidWindowError(); | ||
1463 | |||
1464 | SDL_SetWindowMaximumSize(NULL, desiredW, desiredH); | ||
1465 | SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)"); | ||
1466 | checkInvalidWindowError(); | ||
1467 | |||
1468 | return TEST_COMPLETED; | ||
1469 | } | ||
1470 | |||
1471 | /** | ||
1472 | * Tests call to SDL_SetWindowData and SDL_GetWindowData | ||
1473 | * | ||
1474 | * \sa SDL_SetWindowData | ||
1475 | * \sa SDL_GetWindowData | ||
1476 | */ | ||
1477 | static int SDLCALL video_getSetWindowData(void *arg) | ||
1478 | { | ||
1479 | int returnValue = TEST_COMPLETED; | ||
1480 | const char *title = "video_setGetWindowData Test Window"; | ||
1481 | SDL_Window *window; | ||
1482 | const char *referenceName = "TestName"; | ||
1483 | const char *name = "TestName"; | ||
1484 | const char *referenceName2 = "TestName2"; | ||
1485 | const char *name2 = "TestName2"; | ||
1486 | int datasize; | ||
1487 | char *referenceUserdata = NULL; | ||
1488 | char *userdata = NULL; | ||
1489 | char *referenceUserdata2 = NULL; | ||
1490 | char *userdata2 = NULL; | ||
1491 | char *result; | ||
1492 | int iteration; | ||
1493 | |||
1494 | /* Call against new test window */ | ||
1495 | window = createVideoSuiteTestWindow(title); | ||
1496 | if (!window) { | ||
1497 | return TEST_ABORTED; | ||
1498 | } | ||
1499 | |||
1500 | /* Create testdata */ | ||
1501 | datasize = SDLTest_RandomIntegerInRange(1, 32); | ||
1502 | referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize); | ||
1503 | if (!referenceUserdata) { | ||
1504 | returnValue = TEST_ABORTED; | ||
1505 | goto cleanup; | ||
1506 | } | ||
1507 | userdata = SDL_strdup(referenceUserdata); | ||
1508 | if (!userdata) { | ||
1509 | returnValue = TEST_ABORTED; | ||
1510 | goto cleanup; | ||
1511 | } | ||
1512 | datasize = SDLTest_RandomIntegerInRange(1, 32); | ||
1513 | referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize); | ||
1514 | if (!referenceUserdata2) { | ||
1515 | returnValue = TEST_ABORTED; | ||
1516 | goto cleanup; | ||
1517 | } | ||
1518 | userdata2 = SDL_strdup(referenceUserdata2); | ||
1519 | if (!userdata2) { | ||
1520 | returnValue = TEST_ABORTED; | ||
1521 | goto cleanup; | ||
1522 | } | ||
1523 | |||
1524 | /* Get non-existent data */ | ||
1525 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1526 | SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); | ||
1527 | SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); | ||
1528 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1529 | |||
1530 | /* Set data */ | ||
1531 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata); | ||
1532 | SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata); | ||
1533 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1534 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); | ||
1535 | |||
1536 | /* Get data (twice) */ | ||
1537 | for (iteration = 1; iteration <= 2; iteration++) { | ||
1538 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1539 | SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration); | ||
1540 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); | ||
1541 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1542 | } | ||
1543 | |||
1544 | /* Set data again twice */ | ||
1545 | for (iteration = 1; iteration <= 2; iteration++) { | ||
1546 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata); | ||
1547 | SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration); | ||
1548 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1549 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); | ||
1550 | } | ||
1551 | |||
1552 | /* Get data again */ | ||
1553 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1554 | SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name); | ||
1555 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); | ||
1556 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1557 | |||
1558 | /* Set data with new data */ | ||
1559 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata2); | ||
1560 | SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2); | ||
1561 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1562 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); | ||
1563 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); | ||
1564 | |||
1565 | /* Set data with new data again */ | ||
1566 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata2); | ||
1567 | SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2); | ||
1568 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1569 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); | ||
1570 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); | ||
1571 | |||
1572 | /* Get new data */ | ||
1573 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1574 | SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); | ||
1575 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); | ||
1576 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1577 | |||
1578 | /* Set data with NULL to clear */ | ||
1579 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1580 | SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name); | ||
1581 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1582 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); | ||
1583 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); | ||
1584 | |||
1585 | /* Set data with NULL to clear again */ | ||
1586 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1587 | SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name); | ||
1588 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1589 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); | ||
1590 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); | ||
1591 | |||
1592 | /* Get non-existent data */ | ||
1593 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1594 | SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); | ||
1595 | SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); | ||
1596 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1597 | |||
1598 | /* Get non-existent data new name */ | ||
1599 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name2, NULL); | ||
1600 | SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2); | ||
1601 | SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); | ||
1602 | SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2); | ||
1603 | |||
1604 | /* Set data (again) */ | ||
1605 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata); | ||
1606 | SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata); | ||
1607 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1608 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); | ||
1609 | |||
1610 | /* Get data (again) */ | ||
1611 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL); | ||
1612 | SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name); | ||
1613 | SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); | ||
1614 | SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); | ||
1615 | |||
1616 | /* Set data with NULL name, valid userdata */ | ||
1617 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), NULL, userdata); | ||
1618 | SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)"); | ||
1619 | checkInvalidParameterError(); | ||
1620 | |||
1621 | /* Set data with empty name, valid userdata */ | ||
1622 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), "", userdata); | ||
1623 | SDLTest_AssertPass("Call to SDL_SetWindowData(name='')"); | ||
1624 | checkInvalidParameterError(); | ||
1625 | |||
1626 | /* Set data with NULL name, NULL userdata */ | ||
1627 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), NULL, NULL); | ||
1628 | SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)"); | ||
1629 | checkInvalidParameterError(); | ||
1630 | |||
1631 | /* Set data with empty name, NULL userdata */ | ||
1632 | SDL_SetPointerProperty(SDL_GetWindowProperties(window), "", NULL); | ||
1633 | SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)"); | ||
1634 | checkInvalidParameterError(); | ||
1635 | |||
1636 | /* Get data with NULL name */ | ||
1637 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), NULL, NULL); | ||
1638 | SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)"); | ||
1639 | SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); | ||
1640 | |||
1641 | /* Get data with empty name */ | ||
1642 | result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), "", NULL); | ||
1643 | SDLTest_AssertPass("Call to SDL_GetWindowData(name='')"); | ||
1644 | SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); | ||
1645 | |||
1646 | /* Clean up */ | ||
1647 | destroyVideoSuiteTestWindow(window); | ||
1648 | |||
1649 | cleanup: | ||
1650 | SDL_free(referenceUserdata); | ||
1651 | SDL_free(referenceUserdata2); | ||
1652 | SDL_free(userdata); | ||
1653 | SDL_free(userdata2); | ||
1654 | |||
1655 | return returnValue; | ||
1656 | } | ||
1657 | |||
1658 | /** | ||
1659 | * Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN. | ||
1660 | * | ||
1661 | * Especially useful when run on a multi-monitor system with different DPI scales per monitor, | ||
1662 | * to test that the window size is maintained when moving between monitors. | ||
1663 | * | ||
1664 | * As the Wayland windowing protocol does not allow application windows to control their position in the | ||
1665 | * desktop space, coupled with the general asynchronous nature of Wayland compositors, the positioning | ||
1666 | * tests don't work in windowed mode and are unreliable in fullscreen mode, thus are disabled when using | ||
1667 | * the Wayland video driver. All that can be done is check that the windows are the expected size. | ||
1668 | */ | ||
1669 | static int SDLCALL video_setWindowCenteredOnDisplay(void *arg) | ||
1670 | { | ||
1671 | SDL_DisplayID *displays; | ||
1672 | SDL_Window *window; | ||
1673 | const char *title = "video_setWindowCenteredOnDisplay Test Window"; | ||
1674 | int x, y, w, h; | ||
1675 | int xVariation, yVariation; | ||
1676 | int displayNum; | ||
1677 | int result; | ||
1678 | SDL_Rect display0, display1; | ||
1679 | const char *video_driver = SDL_GetCurrentVideoDriver(); | ||
1680 | bool video_driver_is_wayland = SDL_strcmp(video_driver, "wayland") == 0; | ||
1681 | bool video_driver_is_emscripten = SDL_strcmp(video_driver, "emscripten") == 0; | ||
1682 | |||
1683 | displays = SDL_GetDisplays(&displayNum); | ||
1684 | if (displays) { | ||
1685 | |||
1686 | /* Get display bounds */ | ||
1687 | result = SDL_GetDisplayUsableBounds(displays[0 % displayNum], &display0); | ||
1688 | SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); | ||
1689 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1690 | if (!result) { | ||
1691 | return TEST_ABORTED; | ||
1692 | } | ||
1693 | |||
1694 | result = SDL_GetDisplayUsableBounds(displays[1 % displayNum], &display1); | ||
1695 | SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); | ||
1696 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1697 | if (!result) { | ||
1698 | return TEST_ABORTED; | ||
1699 | } | ||
1700 | |||
1701 | for (xVariation = 0; xVariation < 2; xVariation++) { | ||
1702 | for (yVariation = 0; yVariation < 2; yVariation++) { | ||
1703 | int currentX = 0, currentY = 0; | ||
1704 | int currentW = 0, currentH = 0; | ||
1705 | int expectedX = 0, expectedY = 0; | ||
1706 | int currentDisplay; | ||
1707 | int expectedDisplay; | ||
1708 | SDL_Rect expectedDisplayRect, expectedFullscreenRect; | ||
1709 | SDL_PropertiesID props; | ||
1710 | |||
1711 | /* xVariation is the display we start on */ | ||
1712 | expectedDisplay = displays[xVariation % displayNum]; | ||
1713 | x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); | ||
1714 | y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); | ||
1715 | w = SDLTest_RandomIntegerInRange(640, 800); | ||
1716 | h = SDLTest_RandomIntegerInRange(400, 600); | ||
1717 | expectedDisplayRect = (xVariation == 0) ? display0 : display1; | ||
1718 | expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); | ||
1719 | expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); | ||
1720 | |||
1721 | props = SDL_CreateProperties(); | ||
1722 | SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, title); | ||
1723 | SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, x); | ||
1724 | SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, y); | ||
1725 | SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, w); | ||
1726 | SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h); | ||
1727 | SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN, true); | ||
1728 | window = SDL_CreateWindowWithProperties(props); | ||
1729 | SDL_DestroyProperties(props); | ||
1730 | SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); | ||
1731 | SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL"); | ||
1732 | |||
1733 | /* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */ | ||
1734 | if (video_driver_is_wayland) { | ||
1735 | SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL); | ||
1736 | |||
1737 | if (renderer) { | ||
1738 | SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); | ||
1739 | SDL_RenderClear(renderer); | ||
1740 | SDL_RenderPresent(renderer); | ||
1741 | |||
1742 | /* Some desktops don't display the window immediately after presentation, | ||
1743 | * so delay to give the window time to actually appear on the desktop. | ||
1744 | */ | ||
1745 | SDL_Delay(100); | ||
1746 | } else { | ||
1747 | SDLTest_Log("Unable to create a renderer, tests may fail under Wayland"); | ||
1748 | } | ||
1749 | } | ||
1750 | |||
1751 | /* Check the window is centered on the requested display */ | ||
1752 | currentDisplay = SDL_GetDisplayForWindow(window); | ||
1753 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
1754 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
1755 | |||
1756 | if (video_driver_is_wayland) { | ||
1757 | SDLTest_Log("Skipping display ID validation: %s driver does not support window positioning", video_driver); | ||
1758 | } else { | ||
1759 | SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay); | ||
1760 | } | ||
1761 | if (video_driver_is_emscripten) { | ||
1762 | SDLTest_Log("Skipping window size validation: %s driver does not support window resizing", video_driver); | ||
1763 | } else { | ||
1764 | SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); | ||
1765 | SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); | ||
1766 | } | ||
1767 | if (video_driver_is_emscripten || video_driver_is_wayland) { | ||
1768 | SDLTest_Log("Skipping window position validation: %s driver does not support window positioning", video_driver); | ||
1769 | } else { | ||
1770 | SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); | ||
1771 | SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); | ||
1772 | } | ||
1773 | |||
1774 | /* Enter fullscreen desktop */ | ||
1775 | SDL_SetWindowPosition(window, x, y); | ||
1776 | result = SDL_SetWindowFullscreen(window, true); | ||
1777 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1778 | |||
1779 | result = SDL_SyncWindow(window); | ||
1780 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
1781 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1782 | |||
1783 | /* Check we are filling the full display */ | ||
1784 | currentDisplay = SDL_GetDisplayForWindow(window); | ||
1785 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
1786 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
1787 | |||
1788 | /* Get the expected fullscreen rect. | ||
1789 | * This needs to be queried after window creation and positioning as some drivers can alter the | ||
1790 | * usable bounds based on the window scaling mode. | ||
1791 | */ | ||
1792 | result = SDL_GetDisplayBounds(expectedDisplay, &expectedFullscreenRect); | ||
1793 | SDLTest_AssertPass("SDL_GetDisplayBounds()"); | ||
1794 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1795 | |||
1796 | if (video_driver_is_wayland) { | ||
1797 | SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning"); | ||
1798 | } else { | ||
1799 | SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay); | ||
1800 | } | ||
1801 | |||
1802 | if (video_driver_is_emscripten) { | ||
1803 | SDLTest_Log("Skipping window position validation: %s driver does not support window resizing", video_driver); | ||
1804 | } else { | ||
1805 | SDLTest_AssertCheck(currentW == expectedFullscreenRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedFullscreenRect.w); | ||
1806 | SDLTest_AssertCheck(currentH == expectedFullscreenRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedFullscreenRect.h); | ||
1807 | } | ||
1808 | if (video_driver_is_emscripten || video_driver_is_wayland) { | ||
1809 | SDLTest_Log("Skipping window position validation: %s driver does not support window positioning", video_driver); | ||
1810 | } else { | ||
1811 | SDLTest_AssertCheck(currentX == expectedFullscreenRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedFullscreenRect.x); | ||
1812 | SDLTest_AssertCheck(currentY == expectedFullscreenRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedFullscreenRect.y); | ||
1813 | } | ||
1814 | |||
1815 | /* Leave fullscreen desktop */ | ||
1816 | result = SDL_SetWindowFullscreen(window, false); | ||
1817 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1818 | |||
1819 | result = SDL_SyncWindow(window); | ||
1820 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
1821 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1822 | |||
1823 | /* Check window was restored correctly */ | ||
1824 | currentDisplay = SDL_GetDisplayForWindow(window); | ||
1825 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
1826 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
1827 | |||
1828 | if (video_driver_is_wayland) { | ||
1829 | SDLTest_Log("Skipping display ID validation: %s driver does not support window positioning", video_driver); | ||
1830 | } else { | ||
1831 | SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); | ||
1832 | } | ||
1833 | if (video_driver_is_emscripten) { | ||
1834 | SDLTest_Log("Skipping window position validation: %s driver does not support window resizing", video_driver); | ||
1835 | } else { | ||
1836 | SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); | ||
1837 | SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); | ||
1838 | } | ||
1839 | if (video_driver_is_emscripten || video_driver_is_wayland) { | ||
1840 | SDLTest_Log("Skipping window position validation: %s driver does not support window positioning", video_driver); | ||
1841 | } else { | ||
1842 | SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); | ||
1843 | SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); | ||
1844 | } | ||
1845 | |||
1846 | /* Center on display yVariation, and check window properties */ | ||
1847 | |||
1848 | expectedDisplay = displays[yVariation % displayNum]; | ||
1849 | x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); | ||
1850 | y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); | ||
1851 | expectedDisplayRect = (yVariation == 0) ? display0 : display1; | ||
1852 | expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); | ||
1853 | expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); | ||
1854 | SDL_SetWindowPosition(window, x, y); | ||
1855 | |||
1856 | result = SDL_SyncWindow(window); | ||
1857 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
1858 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1859 | |||
1860 | currentDisplay = SDL_GetDisplayForWindow(window); | ||
1861 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
1862 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
1863 | |||
1864 | if (video_driver_is_wayland) { | ||
1865 | SDLTest_Log("Skipping display ID validation: %s driver does not support window positioning", video_driver); | ||
1866 | } else { | ||
1867 | SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay); | ||
1868 | } | ||
1869 | if (video_driver_is_emscripten) { | ||
1870 | SDLTest_Log("Skipping window position validation: %s driver does not support window resizing", video_driver); | ||
1871 | } else { | ||
1872 | SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); | ||
1873 | SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); | ||
1874 | } | ||
1875 | if (video_driver_is_emscripten || video_driver_is_wayland) { | ||
1876 | SDLTest_Log("Skipping window position validation: %s driver does not support window positioning", video_driver); | ||
1877 | } else { | ||
1878 | SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); | ||
1879 | SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); | ||
1880 | } | ||
1881 | |||
1882 | /* Clean up */ | ||
1883 | destroyVideoSuiteTestWindow(window); | ||
1884 | } | ||
1885 | } | ||
1886 | SDL_free(displays); | ||
1887 | } | ||
1888 | |||
1889 | return TEST_COMPLETED; | ||
1890 | } | ||
1891 | |||
1892 | /** | ||
1893 | * Tests calls to SDL_MaximizeWindow(), SDL_RestoreWindow(), and SDL_SetWindowFullscreen(), | ||
1894 | * interspersed with calls to set the window size and position, and verifies the flags, | ||
1895 | * sizes, and positions of maximized, fullscreen, and restored windows. | ||
1896 | * | ||
1897 | * NOTE: This test is good on Mac, Win32, GNOME, and KDE (Wayland and X11). Other *nix | ||
1898 | * desktops, particularly tiling desktops, may not support the expected behavior, | ||
1899 | * so don't be surprised if this fails. | ||
1900 | */ | ||
1901 | static int SDLCALL video_getSetWindowState(void *arg) | ||
1902 | { | ||
1903 | const char *title = "video_getSetWindowState Test Window"; | ||
1904 | SDL_Window *window; | ||
1905 | int result; | ||
1906 | SDL_Rect display; | ||
1907 | SDL_WindowFlags flags; | ||
1908 | int windowedX, windowedY; | ||
1909 | int currentX, currentY; | ||
1910 | int desiredX = 0, desiredY = 0; | ||
1911 | int windowedW, windowedH; | ||
1912 | int currentW, currentH; | ||
1913 | int desiredW = 0, desiredH = 0; | ||
1914 | SDL_WindowFlags skipFlags = 0; | ||
1915 | const bool restoreHint = SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", true); | ||
1916 | const bool skipPos = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0; | ||
1917 | |||
1918 | /* This test is known to be good only on GNOME and KDE. At the time of writing, Weston seems to have maximize related bugs | ||
1919 | * that prevent it from running correctly (no configure events are received when unsetting maximize), and tiling window | ||
1920 | * managers such as Sway have fundamental behavioral differences that conflict with it. | ||
1921 | * | ||
1922 | * Other desktops can be enabled in the future as required. | ||
1923 | */ | ||
1924 | if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0 || SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { | ||
1925 | const char *desktop = SDL_GetEnvironmentVariable(SDL_GetEnvironment(), "XDG_CURRENT_DESKTOP"); | ||
1926 | if (SDL_strcmp(desktop, "GNOME") != 0 && SDL_strcmp(desktop, "KDE") != 0) { | ||
1927 | SDLTest_Log("Skipping test video_getSetWindowState: desktop environment %s not supported", desktop); | ||
1928 | return TEST_SKIPPED; | ||
1929 | } | ||
1930 | } | ||
1931 | |||
1932 | /* Win32 borderless windows are not resizable by default and need this undocumented hint */ | ||
1933 | SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", "1"); | ||
1934 | |||
1935 | /* Call against new test window */ | ||
1936 | window = createVideoSuiteTestWindow(title); | ||
1937 | if (!window) { | ||
1938 | return TEST_ABORTED; | ||
1939 | } | ||
1940 | |||
1941 | SDL_GetWindowSize(window, &windowedW, &windowedH); | ||
1942 | SDLTest_AssertPass("SDL_GetWindowSize()"); | ||
1943 | |||
1944 | SDL_GetWindowPosition(window, &windowedX, &windowedY); | ||
1945 | SDLTest_AssertPass("SDL_GetWindowPosition()"); | ||
1946 | |||
1947 | if (skipPos) { | ||
1948 | SDLTest_Log("Skipping positioning tests: %s reports window positioning as unsupported", SDL_GetCurrentVideoDriver()); | ||
1949 | } | ||
1950 | |||
1951 | /* Maximize and check the dimensions */ | ||
1952 | result = SDL_MaximizeWindow(window); | ||
1953 | SDLTest_AssertPass("SDL_MaximizeWindow()"); | ||
1954 | if (!result) { | ||
1955 | SDLTest_Log("Skipping state transition tests: %s reports window maximizing as unsupported", SDL_GetCurrentVideoDriver()); | ||
1956 | skipFlags |= SDL_WINDOW_MAXIMIZED; | ||
1957 | goto minimize_test; | ||
1958 | } | ||
1959 | |||
1960 | result = SDL_SyncWindow(window); | ||
1961 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
1962 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1963 | |||
1964 | flags = SDL_GetWindowFlags(window); | ||
1965 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
1966 | SDLTest_AssertCheck(flags & SDL_WINDOW_MAXIMIZED, "Verify the `SDL_WINDOW_MAXIMIZED` flag is set: %s", (flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
1967 | |||
1968 | /* Check that the maximized window doesn't extend beyond the usable display bounds. | ||
1969 | * FIXME: Maximizing Win32 borderless windows is broken, so this always fails. | ||
1970 | * Skip it for now. | ||
1971 | */ | ||
1972 | if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") != 0) { | ||
1973 | result = SDL_GetDisplayUsableBounds(SDL_GetDisplayForWindow(window), &display); | ||
1974 | SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); | ||
1975 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1976 | |||
1977 | desiredW = display.w; | ||
1978 | desiredH = display.h; | ||
1979 | currentW = windowedW + 1; | ||
1980 | currentH = windowedH + 1; | ||
1981 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
1982 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
1983 | SDLTest_AssertCheck(currentW <= desiredW, "Verify returned width; expected: <= %d, got: %d", desiredW, | ||
1984 | currentW); | ||
1985 | SDLTest_AssertCheck(currentH <= desiredH, "Verify returned height; expected: <= %d, got: %d", desiredH, | ||
1986 | currentH); | ||
1987 | } | ||
1988 | |||
1989 | /* Restore and check the dimensions */ | ||
1990 | result = SDL_RestoreWindow(window); | ||
1991 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
1992 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1993 | |||
1994 | result = SDL_SyncWindow(window); | ||
1995 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
1996 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
1997 | |||
1998 | flags = SDL_GetWindowFlags(window); | ||
1999 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2000 | SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
2001 | |||
2002 | if (!skipPos) { | ||
2003 | currentX = windowedX + 1; | ||
2004 | currentY = windowedY + 1; | ||
2005 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
2006 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
2007 | SDLTest_AssertCheck(windowedX == currentX, "Verify returned X coordinate; expected: %d, got: %d", windowedX, currentX); | ||
2008 | SDLTest_AssertCheck(windowedY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", windowedY, currentY); | ||
2009 | } | ||
2010 | |||
2011 | currentW = windowedW + 1; | ||
2012 | currentH = windowedH + 1; | ||
2013 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
2014 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
2015 | SDLTest_AssertCheck(windowedW == currentW, "Verify returned width; expected: %d, got: %d", windowedW, currentW); | ||
2016 | SDLTest_AssertCheck(windowedH == currentH, "Verify returned height; expected: %d, got: %d", windowedH, currentH); | ||
2017 | |||
2018 | /* Maximize, then immediately restore */ | ||
2019 | result = SDL_MaximizeWindow(window); | ||
2020 | SDLTest_AssertPass("SDL_MaximizeWindow()"); | ||
2021 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2022 | |||
2023 | result = SDL_RestoreWindow(window); | ||
2024 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
2025 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2026 | |||
2027 | result = SDL_SyncWindow(window); | ||
2028 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
2029 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2030 | |||
2031 | flags = SDL_GetWindowFlags(window); | ||
2032 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2033 | SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
2034 | |||
2035 | /* Make sure the restored size and position matches the original windowed size and position. */ | ||
2036 | if (!skipPos) { | ||
2037 | currentX = windowedX + 1; | ||
2038 | currentY = windowedY + 1; | ||
2039 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
2040 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
2041 | SDLTest_AssertCheck(windowedX == currentX, "Verify returned X coordinate; expected: %d, got: %d", windowedX, currentX); | ||
2042 | SDLTest_AssertCheck(windowedY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", windowedY, currentY); | ||
2043 | } | ||
2044 | |||
2045 | currentW = windowedW + 1; | ||
2046 | currentH = windowedH + 1; | ||
2047 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
2048 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
2049 | SDLTest_AssertCheck(windowedW == currentW, "Verify returned width; expected: %d, got: %d", windowedW, currentW); | ||
2050 | SDLTest_AssertCheck(windowedH == currentH, "Verify returned height; expected: %d, got: %d", windowedH, currentH); | ||
2051 | |||
2052 | /* Maximize, then enter fullscreen */ | ||
2053 | result = SDL_MaximizeWindow(window); | ||
2054 | SDLTest_AssertPass("SDL_MaximizeWindow()"); | ||
2055 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2056 | |||
2057 | result = SDL_SetWindowFullscreen(window, true); | ||
2058 | SDLTest_AssertPass("SDL_SetWindowFullscreen(true)"); | ||
2059 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2060 | |||
2061 | result = SDL_SyncWindow(window); | ||
2062 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
2063 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2064 | |||
2065 | flags = SDL_GetWindowFlags(window); | ||
2066 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2067 | SDLTest_AssertCheck(flags & SDL_WINDOW_FULLSCREEN, "Verify the `SDL_WINDOW_FULLSCREEN` flag is set: %s", (flags & SDL_WINDOW_FULLSCREEN) ? "true" : "false"); | ||
2068 | SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
2069 | |||
2070 | /* Verify the fullscreen size and position */ | ||
2071 | result = SDL_GetDisplayBounds(SDL_GetDisplayForWindow(window), &display); | ||
2072 | SDLTest_AssertPass("SDL_GetDisplayBounds()"); | ||
2073 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2074 | |||
2075 | if (!skipPos) { | ||
2076 | desiredX = display.x; | ||
2077 | desiredY = display.y; | ||
2078 | currentX = windowedX + 1; | ||
2079 | currentY = windowedY + 1; | ||
2080 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
2081 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
2082 | SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX); | ||
2083 | SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY); | ||
2084 | } | ||
2085 | |||
2086 | desiredW = display.w; | ||
2087 | desiredH = display.h; | ||
2088 | currentW = windowedW + 1; | ||
2089 | currentH = windowedH + 1; | ||
2090 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
2091 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
2092 | SDLTest_AssertCheck(currentW == desiredW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); | ||
2093 | SDLTest_AssertCheck(currentH == desiredH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); | ||
2094 | |||
2095 | /* Leave fullscreen and restore the window */ | ||
2096 | result = SDL_SetWindowFullscreen(window, false); | ||
2097 | SDLTest_AssertPass("SDL_SetWindowFullscreen(false)"); | ||
2098 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2099 | |||
2100 | result = SDL_RestoreWindow(window); | ||
2101 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
2102 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2103 | |||
2104 | result = SDL_SyncWindow(window); | ||
2105 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
2106 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2107 | |||
2108 | flags = SDL_GetWindowFlags(window); | ||
2109 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2110 | SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
2111 | |||
2112 | /* Make sure the restored size and position matches the original windowed size and position. */ | ||
2113 | if (!skipPos) { | ||
2114 | currentX = windowedX + 1; | ||
2115 | currentY = windowedY + 1; | ||
2116 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
2117 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
2118 | SDLTest_AssertCheck(windowedX == currentX, "Verify returned X coordinate; expected: %d, got: %d", windowedX, currentX); | ||
2119 | SDLTest_AssertCheck(windowedY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", windowedY, currentY); | ||
2120 | } | ||
2121 | |||
2122 | currentW = windowedW + 1; | ||
2123 | currentH = windowedH + 1; | ||
2124 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
2125 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
2126 | SDLTest_AssertCheck(windowedW == currentW, "Verify returned width; expected: %d, got: %d", windowedW, currentW); | ||
2127 | SDLTest_AssertCheck(windowedH == currentH, "Verify returned height; expected: %d, got: %d", windowedH, currentH); | ||
2128 | |||
2129 | /* Maximize, restore, and change size */ | ||
2130 | result = SDL_MaximizeWindow(window); | ||
2131 | SDLTest_AssertPass("SDL_MaximizeWindow()"); | ||
2132 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2133 | |||
2134 | result = SDL_RestoreWindow(window); | ||
2135 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
2136 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2137 | |||
2138 | desiredW = windowedW + 10; | ||
2139 | desiredH = windowedH + 10; | ||
2140 | result = SDL_SetWindowSize(window, desiredW, desiredH); | ||
2141 | SDLTest_AssertPass("SDL_SetWindowSize()"); | ||
2142 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2143 | |||
2144 | if (!skipPos) { | ||
2145 | desiredX = windowedX + 10; | ||
2146 | desiredY = windowedY + 10; | ||
2147 | result = SDL_SetWindowPosition(window, desiredX, desiredY); | ||
2148 | SDLTest_AssertPass("SDL_SetWindowPosition()"); | ||
2149 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2150 | } | ||
2151 | |||
2152 | result = SDL_SyncWindow(window); | ||
2153 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
2154 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2155 | |||
2156 | flags = SDL_GetWindowFlags(window); | ||
2157 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2158 | SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
2159 | |||
2160 | if (!skipPos) { | ||
2161 | currentX = desiredX + 1; | ||
2162 | currentY = desiredY + 1; | ||
2163 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
2164 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
2165 | SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX); | ||
2166 | SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY); | ||
2167 | } | ||
2168 | |||
2169 | currentW = desiredW + 1; | ||
2170 | currentH = desiredH + 1; | ||
2171 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
2172 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
2173 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); | ||
2174 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); | ||
2175 | |||
2176 | /* Maximize, change size/position (should be ignored), and restore. */ | ||
2177 | result = SDL_MaximizeWindow(window); | ||
2178 | SDLTest_AssertPass("SDL_MaximizeWindow()"); | ||
2179 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2180 | |||
2181 | desiredW = windowedW + 10; | ||
2182 | desiredH = windowedH + 10; | ||
2183 | result = SDL_SetWindowSize(window, desiredW, desiredH); | ||
2184 | SDLTest_AssertPass("SDL_SetWindowSize()"); | ||
2185 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2186 | |||
2187 | if (!skipPos) { | ||
2188 | desiredX = windowedX + 10; | ||
2189 | desiredY = windowedY + 10; | ||
2190 | result = SDL_SetWindowPosition(window, desiredX, desiredY); | ||
2191 | SDLTest_AssertPass("SDL_SetWindowPosition()"); | ||
2192 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2193 | } | ||
2194 | |||
2195 | result = SDL_RestoreWindow(window); | ||
2196 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
2197 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2198 | |||
2199 | result = SDL_SyncWindow(window); | ||
2200 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
2201 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2202 | |||
2203 | flags = SDL_GetWindowFlags(window); | ||
2204 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2205 | SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
2206 | |||
2207 | if (!skipPos) { | ||
2208 | int previousX = desiredX + 1; | ||
2209 | int previousY = desiredY + 1; | ||
2210 | SDL_GetWindowPosition(window, &previousX, &previousY); | ||
2211 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
2212 | SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", previousX, currentX); | ||
2213 | SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", previousY, currentY); | ||
2214 | } | ||
2215 | |||
2216 | int previousW = desiredW + 1; | ||
2217 | int previousH = desiredH + 1; | ||
2218 | SDL_GetWindowSize(window, &previousW, &previousH); | ||
2219 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
2220 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", previousW, currentW); | ||
2221 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", previousH, currentH); | ||
2222 | |||
2223 | /* Change size and position, maximize and restore */ | ||
2224 | desiredW = windowedW - 5; | ||
2225 | desiredH = windowedH - 5; | ||
2226 | result = SDL_SetWindowSize(window, desiredW, desiredH); | ||
2227 | SDLTest_AssertPass("SDL_SetWindowSize()"); | ||
2228 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2229 | |||
2230 | if (!skipPos) { | ||
2231 | desiredX = windowedX + 5; | ||
2232 | desiredY = windowedY + 5; | ||
2233 | result = SDL_SetWindowPosition(window, desiredX, desiredY); | ||
2234 | SDLTest_AssertPass("SDL_SetWindowPosition()"); | ||
2235 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2236 | } | ||
2237 | |||
2238 | result = SDL_MaximizeWindow(window); | ||
2239 | SDLTest_AssertPass("SDL_MaximizeWindow()"); | ||
2240 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2241 | |||
2242 | result = SDL_RestoreWindow(window); | ||
2243 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
2244 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2245 | |||
2246 | result = SDL_SyncWindow(window); | ||
2247 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
2248 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2249 | |||
2250 | flags = SDL_GetWindowFlags(window); | ||
2251 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2252 | SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false"); | ||
2253 | |||
2254 | if (!skipPos) { | ||
2255 | currentX = desiredX + 1; | ||
2256 | currentY = desiredY + 1; | ||
2257 | SDL_GetWindowPosition(window, ¤tX, ¤tY); | ||
2258 | SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); | ||
2259 | SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX); | ||
2260 | SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY); | ||
2261 | } | ||
2262 | |||
2263 | currentW = desiredW + 1; | ||
2264 | currentH = desiredH + 1; | ||
2265 | SDL_GetWindowSize(window, ¤tW, ¤tH); | ||
2266 | SDLTest_AssertPass("Call to SDL_GetWindowSize()"); | ||
2267 | SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); | ||
2268 | SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); | ||
2269 | |||
2270 | minimize_test: | ||
2271 | |||
2272 | /* Minimize */ | ||
2273 | result = SDL_MinimizeWindow(window); | ||
2274 | if (result) { | ||
2275 | SDLTest_AssertPass("SDL_MinimizeWindow()"); | ||
2276 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2277 | |||
2278 | result = SDL_SyncWindow(window); | ||
2279 | SDLTest_AssertPass("SDL_SyncWindow()"); | ||
2280 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2281 | |||
2282 | flags = SDL_GetWindowFlags(window); | ||
2283 | SDLTest_AssertPass("SDL_GetWindowFlags()"); | ||
2284 | SDLTest_AssertCheck(flags & SDL_WINDOW_MINIMIZED, "Verify that the `SDL_WINDOW_MINIMIZED` flag is set: %s", (flags & SDL_WINDOW_MINIMIZED) ? "true" : "false"); | ||
2285 | } else { | ||
2286 | SDLTest_Log("Skipping minimize test: %s reports window minimizing as unsupported", SDL_GetCurrentVideoDriver()); | ||
2287 | skipFlags |= SDL_WINDOW_MINIMIZED; | ||
2288 | } | ||
2289 | |||
2290 | /* Clean up */ | ||
2291 | destroyVideoSuiteTestWindow(window); | ||
2292 | |||
2293 | /* Restore the hint to the previous value */ | ||
2294 | SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", restoreHint ? "1" : "0"); | ||
2295 | |||
2296 | return skipFlags != (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED) ? TEST_COMPLETED : TEST_SKIPPED; | ||
2297 | } | ||
2298 | |||
2299 | static int SDLCALL video_createMinimized(void *arg) | ||
2300 | { | ||
2301 | const char *title = "video_createMinimized Test Window"; | ||
2302 | int result; | ||
2303 | SDL_Window *window; | ||
2304 | int windowedX, windowedY; | ||
2305 | int windowedW, windowedH; | ||
2306 | |||
2307 | /* Call against new test window */ | ||
2308 | window = SDL_CreateWindow(title, 320, 200, SDL_WINDOW_MINIMIZED); | ||
2309 | if (!window) { | ||
2310 | return TEST_ABORTED; | ||
2311 | } | ||
2312 | |||
2313 | SDL_GetWindowSize(window, &windowedW, &windowedH); | ||
2314 | SDLTest_AssertPass("SDL_GetWindowSize()"); | ||
2315 | SDLTest_AssertCheck(windowedW > 0 && windowedH > 0, "Verify return value; expected: 320x200, got: %dx%d", windowedW, windowedH); | ||
2316 | |||
2317 | SDL_GetWindowSizeInPixels(window, &windowedW, &windowedH); | ||
2318 | SDLTest_AssertPass("SDL_GetWindowSizeInPixels()"); | ||
2319 | SDLTest_AssertCheck(windowedW > 0 && windowedH > 0, "Verify return value; expected: > 0, got: %dx%d", windowedW, windowedH); | ||
2320 | |||
2321 | SDL_GetWindowPosition(window, &windowedX, &windowedY); | ||
2322 | SDLTest_AssertPass("SDL_GetWindowPosition()"); | ||
2323 | SDLTest_AssertCheck(windowedX >= 0 && windowedY >= 0, "Verify return value; expected: >= 0, got: %d,%d", windowedX, windowedY); | ||
2324 | |||
2325 | if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) { | ||
2326 | result = SDL_RestoreWindow(window); | ||
2327 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
2328 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2329 | } else { | ||
2330 | SDLTest_Log("Requested minimized window on creation, but that isn't supported on this platform."); | ||
2331 | } | ||
2332 | |||
2333 | SDL_DestroyWindow(window); | ||
2334 | |||
2335 | return TEST_COMPLETED; | ||
2336 | } | ||
2337 | |||
2338 | static int SDLCALL video_createMaximized(void *arg) | ||
2339 | { | ||
2340 | const char *title = "video_createMaximized Test Window"; | ||
2341 | int result; | ||
2342 | SDL_Window *window; | ||
2343 | int windowedX, windowedY; | ||
2344 | int windowedW, windowedH; | ||
2345 | |||
2346 | /* Call against new test window */ | ||
2347 | window = SDL_CreateWindow(title, 320, 200, SDL_WINDOW_MAXIMIZED); | ||
2348 | if (!window) { | ||
2349 | return TEST_ABORTED; | ||
2350 | } | ||
2351 | |||
2352 | SDL_GetWindowSize(window, &windowedW, &windowedH); | ||
2353 | SDLTest_AssertPass("SDL_GetWindowSize()"); | ||
2354 | SDLTest_AssertCheck(windowedW > 0 && windowedH > 0, "Verify return value; expected: 320x200, got: %dx%d", windowedW, windowedH); | ||
2355 | |||
2356 | SDL_GetWindowSizeInPixels(window, &windowedW, &windowedH); | ||
2357 | SDLTest_AssertPass("SDL_GetWindowSizeInPixels()"); | ||
2358 | SDLTest_AssertCheck(windowedW > 0 && windowedH > 0, "Verify return value; expected: > 0, got: %dx%d", windowedW, windowedH); | ||
2359 | |||
2360 | SDL_GetWindowPosition(window, &windowedX, &windowedY); | ||
2361 | SDLTest_AssertPass("SDL_GetWindowPosition()"); | ||
2362 | SDLTest_AssertCheck(windowedX >= 0 && windowedY >= 0, "Verify return value; expected: >= 0, got: %d,%d", windowedX, windowedY); | ||
2363 | |||
2364 | if (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED) { | ||
2365 | result = SDL_RestoreWindow(window); | ||
2366 | SDLTest_AssertPass("SDL_RestoreWindow()"); | ||
2367 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2368 | } else { | ||
2369 | SDLTest_Log("Requested maximized window on creation, but that isn't supported on this platform."); | ||
2370 | } | ||
2371 | |||
2372 | SDL_DestroyWindow(window); | ||
2373 | |||
2374 | return TEST_COMPLETED; | ||
2375 | } | ||
2376 | |||
2377 | /** | ||
2378 | * Tests window surface functionality | ||
2379 | */ | ||
2380 | static int SDLCALL video_getWindowSurface(void *arg) | ||
2381 | { | ||
2382 | const char *title = "video_getWindowSurface Test Window"; | ||
2383 | SDL_Window *window; | ||
2384 | SDL_Surface *surface; | ||
2385 | SDL_Renderer *renderer; | ||
2386 | const char *renderer_name = NULL; | ||
2387 | int result; | ||
2388 | |||
2389 | if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "dummy") == 0) { | ||
2390 | renderer_name = SDL_SOFTWARE_RENDERER; | ||
2391 | } | ||
2392 | |||
2393 | /* Make sure we're testing interaction with an accelerated renderer */ | ||
2394 | SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1"); | ||
2395 | |||
2396 | window = SDL_CreateWindow(title, 320, 320, 0); | ||
2397 | SDLTest_AssertPass("Call to SDL_CreateWindow('Title',320,320,0)"); | ||
2398 | SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL"); | ||
2399 | |||
2400 | surface = SDL_GetWindowSurface(window); | ||
2401 | SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)"); | ||
2402 | SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL"); | ||
2403 | SDLTest_AssertCheck(SDL_WindowHasSurface(window), "Validate that window has a surface"); | ||
2404 | |||
2405 | result = SDL_UpdateWindowSurface(window); | ||
2406 | SDLTest_AssertPass("Call to SDL_UpdateWindowSurface(window)"); | ||
2407 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2408 | |||
2409 | /* We shouldn't be able to create a renderer on a window with a surface */ | ||
2410 | renderer = SDL_CreateRenderer(window, renderer_name); | ||
2411 | SDLTest_AssertPass("Call to SDL_CreateRenderer(window, %s)", renderer_name); | ||
2412 | SDLTest_AssertCheck(renderer == NULL, "Validate that returned renderer is NULL"); | ||
2413 | |||
2414 | result = SDL_DestroyWindowSurface(window); | ||
2415 | SDLTest_AssertPass("Call to SDL_DestroyWindowSurface(window)"); | ||
2416 | SDLTest_AssertCheck(result == true, "Verify return value; expected: true, got: %d", result); | ||
2417 | SDLTest_AssertCheck(!SDL_WindowHasSurface(window), "Validate that window does not have a surface"); | ||
2418 | |||
2419 | /* We should be able to create a renderer on the window now */ | ||
2420 | renderer = SDL_CreateRenderer(window, renderer_name); | ||
2421 | SDLTest_AssertPass("Call to SDL_CreateRenderer(window, %s)", renderer_name); | ||
2422 | SDLTest_AssertCheck(renderer != NULL, "Validate that returned renderer is not NULL"); | ||
2423 | |||
2424 | /* We should not be able to create a window surface now, unless it was created by the renderer */ | ||
2425 | if (!SDL_WindowHasSurface(window)) { | ||
2426 | surface = SDL_GetWindowSurface(window); | ||
2427 | SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)"); | ||
2428 | SDLTest_AssertCheck(surface == NULL, "Validate that returned surface is NULL"); | ||
2429 | } | ||
2430 | |||
2431 | SDL_DestroyRenderer(renderer); | ||
2432 | SDLTest_AssertPass("Call to SDL_DestroyRenderer(renderer)"); | ||
2433 | SDLTest_AssertCheck(!SDL_WindowHasSurface(window), "Validate that window does not have a surface"); | ||
2434 | |||
2435 | /* We should be able to create a window surface again */ | ||
2436 | surface = SDL_GetWindowSurface(window); | ||
2437 | SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)"); | ||
2438 | SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL"); | ||
2439 | SDLTest_AssertCheck(SDL_WindowHasSurface(window), "Validate that window has a surface"); | ||
2440 | |||
2441 | /* Clean up */ | ||
2442 | SDL_DestroyWindow(window); | ||
2443 | |||
2444 | return TEST_COMPLETED; | ||
2445 | } | ||
2446 | |||
2447 | /* ================= Test References ================== */ | ||
2448 | |||
2449 | /* Video test cases */ | ||
2450 | static const SDLTest_TestCaseReference videoTestEnableDisableScreensaver = { | ||
2451 | video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED | ||
2452 | }; | ||
2453 | |||
2454 | static const SDLTest_TestCaseReference videoTestCreateWindowVariousSizes = { | ||
2455 | video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED | ||
2456 | }; | ||
2457 | |||
2458 | static const SDLTest_TestCaseReference videoTestCreateWindowVariousFlags = { | ||
2459 | video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED | ||
2460 | }; | ||
2461 | |||
2462 | static const SDLTest_TestCaseReference videoTestGetWindowFlags = { | ||
2463 | video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED | ||
2464 | }; | ||
2465 | |||
2466 | static const SDLTest_TestCaseReference videoTestGetFullscreenDisplayModes = { | ||
2467 | video_getFullscreenDisplayModes, "video_getFullscreenDisplayModes", "Use SDL_GetFullscreenDisplayModes function to get number of display modes", TEST_ENABLED | ||
2468 | }; | ||
2469 | |||
2470 | static const SDLTest_TestCaseReference videoTestGetClosestDisplayModeCurrentResolution = { | ||
2471 | video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED | ||
2472 | }; | ||
2473 | |||
2474 | static const SDLTest_TestCaseReference videoTestGetClosestDisplayModeRandomResolution = { | ||
2475 | video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED | ||
2476 | }; | ||
2477 | |||
2478 | static const SDLTest_TestCaseReference videoTestGetWindowDisplayMode = { | ||
2479 | video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED | ||
2480 | }; | ||
2481 | |||
2482 | static const SDLTest_TestCaseReference videoTestGetWindowDisplayModeNegative = { | ||
2483 | video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED | ||
2484 | }; | ||
2485 | |||
2486 | static const SDLTest_TestCaseReference videoTestGetSetWindowGrab = { | ||
2487 | video_getSetWindowGrab, "video_getSetWindowGrab", "Checks input grab positive and negative cases", TEST_ENABLED | ||
2488 | }; | ||
2489 | |||
2490 | static const SDLTest_TestCaseReference videoTestGetWindowID = { | ||
2491 | video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED | ||
2492 | }; | ||
2493 | |||
2494 | static const SDLTest_TestCaseReference videoTestGetWindowPixelFormat = { | ||
2495 | video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED | ||
2496 | }; | ||
2497 | |||
2498 | static const SDLTest_TestCaseReference videoTestGetSetWindowPosition = { | ||
2499 | video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED | ||
2500 | }; | ||
2501 | |||
2502 | static const SDLTest_TestCaseReference videoTestGetSetWindowSize = { | ||
2503 | video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED | ||
2504 | }; | ||
2505 | |||
2506 | static const SDLTest_TestCaseReference videoTestGetSetWindowMinimumSize = { | ||
2507 | video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED | ||
2508 | }; | ||
2509 | |||
2510 | static const SDLTest_TestCaseReference videoTestGetSetWindowMaximumSize = { | ||
2511 | video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED | ||
2512 | }; | ||
2513 | |||
2514 | static const SDLTest_TestCaseReference videoTestGetSetWindowData = { | ||
2515 | video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED | ||
2516 | }; | ||
2517 | |||
2518 | static const SDLTest_TestCaseReference videoTestSetWindowCenteredOnDisplay = { | ||
2519 | video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED | ||
2520 | }; | ||
2521 | |||
2522 | static const SDLTest_TestCaseReference videoTestGetSetWindowState = { | ||
2523 | video_getSetWindowState, "video_getSetWindowState", "Checks transitioning between windowed, minimized, maximized, and fullscreen states", TEST_ENABLED | ||
2524 | }; | ||
2525 | |||
2526 | static const SDLTest_TestCaseReference videoTestCreateMinimized = { | ||
2527 | video_createMinimized, "video_createMinimized", "Checks window state for windows created minimized", TEST_ENABLED | ||
2528 | }; | ||
2529 | |||
2530 | static const SDLTest_TestCaseReference videoTestCreateMaximized = { | ||
2531 | video_createMaximized, "video_createMaximized", "Checks window state for windows created maximized", TEST_ENABLED | ||
2532 | }; | ||
2533 | |||
2534 | static const SDLTest_TestCaseReference videoTestGetWindowSurface = { | ||
2535 | video_getWindowSurface, "video_getWindowSurface", "Checks window surface functionality", TEST_ENABLED | ||
2536 | }; | ||
2537 | |||
2538 | /* Sequence of Video test cases */ | ||
2539 | static const SDLTest_TestCaseReference *videoTests[] = { | ||
2540 | &videoTestEnableDisableScreensaver, | ||
2541 | &videoTestCreateWindowVariousSizes, | ||
2542 | &videoTestCreateWindowVariousFlags, | ||
2543 | &videoTestGetWindowFlags, | ||
2544 | &videoTestGetFullscreenDisplayModes, | ||
2545 | &videoTestGetClosestDisplayModeCurrentResolution, | ||
2546 | &videoTestGetClosestDisplayModeRandomResolution, | ||
2547 | &videoTestGetWindowDisplayMode, | ||
2548 | &videoTestGetWindowDisplayModeNegative, | ||
2549 | &videoTestGetSetWindowGrab, | ||
2550 | &videoTestGetWindowID, | ||
2551 | &videoTestGetWindowPixelFormat, | ||
2552 | &videoTestGetSetWindowPosition, | ||
2553 | &videoTestGetSetWindowSize, | ||
2554 | &videoTestGetSetWindowMinimumSize, | ||
2555 | &videoTestGetSetWindowMaximumSize, | ||
2556 | &videoTestGetSetWindowData, | ||
2557 | &videoTestSetWindowCenteredOnDisplay, | ||
2558 | &videoTestGetSetWindowState, | ||
2559 | &videoTestCreateMinimized, | ||
2560 | &videoTestCreateMaximized, | ||
2561 | &videoTestGetWindowSurface, | ||
2562 | NULL | ||
2563 | }; | ||
2564 | |||
2565 | /* Video test suite (global) */ | ||
2566 | SDLTest_TestSuiteReference videoTestSuite = { | ||
2567 | "Video", | ||
2568 | NULL, | ||
2569 | videoTests, | ||
2570 | NULL | ||
2571 | }; | ||