1/**
2 * Video test suite
3 */
4
5#include <stdio.h>
6#include <string.h>
7
8/* Visual Studio 2008 doesn't have stdint.h */
9#if defined(_MSC_VER) && _MSC_VER <= 1500
10#define UINT8_MAX ~(Uint8)0
11#define UINT16_MAX ~(Uint16)0
12#define UINT32_MAX ~(Uint32)0
13#define UINT64_MAX ~(Uint64)0
14#else
15#include <stdint.h>
16#endif
17
18#include "SDL.h"
19#include "SDL_test.h"
20
21/* Private helpers */
22
23/*
24 * Create a test window
25 */
26SDL_Window *_createVideoSuiteTestWindow(const char *title)
27{
28 SDL_Window* window;
29 int x, y, w, h;
30 SDL_WindowFlags flags;
31
32 /* Standard window */
33 x = SDLTest_RandomIntegerInRange(1, 100);
34 y = SDLTest_RandomIntegerInRange(1, 100);
35 w = SDLTest_RandomIntegerInRange(320, 1024);
36 h = SDLTest_RandomIntegerInRange(320, 768);
37 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
38
39 window = SDL_CreateWindow(title, x, y, w, h, flags);
40 SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
41 SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
42
43 return window;
44}
45
46/*
47 * Destroy test window
48 */
49void _destroyVideoSuiteTestWindow(SDL_Window *window)
50{
51 if (window != NULL) {
52 SDL_DestroyWindow(window);
53 window = NULL;
54 SDLTest_AssertPass("Call to SDL_DestroyWindow()");
55 }
56}
57
58/* Test case functions */
59
60/**
61 * @brief Enable and disable screensaver while checking state
62 */
63int
64video_enableDisableScreensaver(void *arg)
65{
66 SDL_bool initialResult;
67 SDL_bool result;
68
69 /* Get current state and proceed according to current state */
70 initialResult = SDL_IsScreenSaverEnabled();
71 SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
72 if (initialResult == SDL_TRUE) {
73
74 /* Currently enabled: disable first, then enable again */
75
76 /* Disable screensaver and check */
77 SDL_DisableScreenSaver();
78 SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
79 result = SDL_IsScreenSaverEnabled();
80 SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
81 SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
82
83 /* Enable screensaver and check */
84 SDL_EnableScreenSaver();
85 SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
86 result = SDL_IsScreenSaverEnabled();
87 SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
88 SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
89
90 } else {
91
92 /* Currently disabled: enable first, then disable again */
93
94 /* Enable screensaver and check */
95 SDL_EnableScreenSaver();
96 SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
97 result = SDL_IsScreenSaverEnabled();
98 SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
99 SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
100
101 /* Disable screensaver and check */
102 SDL_DisableScreenSaver();
103 SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
104 result = SDL_IsScreenSaverEnabled();
105 SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
106 SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
107 }
108
109 return TEST_COMPLETED;
110}
111
112/**
113 * @brief Tests the functionality of the SDL_CreateWindow function using different positions
114 */
115int
116video_createWindowVariousPositions(void *arg)
117{
118 SDL_Window* window;
119 const char* title = "video_createWindowVariousPositions Test Window";
120 int x, y, w, h;
121 int xVariation, yVariation;
122
123 for (xVariation = 0; xVariation < 6; xVariation++) {
124 for (yVariation = 0; yVariation < 6; yVariation++) {
125 switch(xVariation) {
126 case 0:
127 /* Zero X Position */
128 x = 0;
129 break;
130 case 1:
131 /* Random X position inside screen */
132 x = SDLTest_RandomIntegerInRange(1, 100);
133 break;
134 case 2:
135 /* Random X position outside screen (positive) */
136 x = SDLTest_RandomIntegerInRange(10000, 11000);
137 break;
138 case 3:
139 /* Random X position outside screen (negative) */
140 x = SDLTest_RandomIntegerInRange(-1000, -100);
141 break;
142 case 4:
143 /* Centered X position */
144 x = SDL_WINDOWPOS_CENTERED;
145 break;
146 case 5:
147 /* Undefined X position */
148 x = SDL_WINDOWPOS_UNDEFINED;
149 break;
150 }
151
152 switch(yVariation) {
153 case 0:
154 /* Zero X Position */
155 y = 0;
156 break;
157 case 1:
158 /* Random X position inside screen */
159 y = SDLTest_RandomIntegerInRange(1, 100);
160 break;
161 case 2:
162 /* Random X position outside screen (positive) */
163 y = SDLTest_RandomIntegerInRange(10000, 11000);
164 break;
165 case 3:
166 /* Random Y position outside screen (negative) */
167 y = SDLTest_RandomIntegerInRange(-1000, -100);
168 break;
169 case 4:
170 /* Centered Y position */
171 y = SDL_WINDOWPOS_CENTERED;
172 break;
173 case 5:
174 /* Undefined Y position */
175 y = SDL_WINDOWPOS_UNDEFINED;
176 break;
177 }
178
179 w = SDLTest_RandomIntegerInRange(32, 96);
180 h = SDLTest_RandomIntegerInRange(32, 96);
181 window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
182 SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
183 SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
184
185 /* Clean up */
186 _destroyVideoSuiteTestWindow(window);
187 }
188 }
189
190 return TEST_COMPLETED;
191}
192
193/**
194 * @brief Tests the functionality of the SDL_CreateWindow function using different sizes
195 */
196int
197video_createWindowVariousSizes(void *arg)
198{
199 SDL_Window* window;
200 const char* title = "video_createWindowVariousSizes Test Window";
201 int x, y, w, h;
202 int wVariation, hVariation;
203
204 x = SDLTest_RandomIntegerInRange(1, 100);
205 y = SDLTest_RandomIntegerInRange(1, 100);
206 for (wVariation = 0; wVariation < 3; wVariation++) {
207 for (hVariation = 0; hVariation < 3; hVariation++) {
208 switch(wVariation) {
209 case 0:
210 /* Width of 1 */
211 w = 1;
212 break;
213 case 1:
214 /* Random "normal" width */
215 w = SDLTest_RandomIntegerInRange(320, 1920);
216 break;
217 case 2:
218 /* Random "large" width */
219 w = SDLTest_RandomIntegerInRange(2048, 4095);
220 break;
221 }
222
223 switch(hVariation) {
224 case 0:
225 /* Height of 1 */
226 h = 1;
227 break;
228 case 1:
229 /* Random "normal" height */
230 h = SDLTest_RandomIntegerInRange(320, 1080);
231 break;
232 case 2:
233 /* Random "large" height */
234 h = SDLTest_RandomIntegerInRange(2048, 4095);
235 break;
236 }
237
238 window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
239 SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
240 SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
241
242 /* Clean up */
243 _destroyVideoSuiteTestWindow(window);
244 }
245 }
246
247 return TEST_COMPLETED;
248}
249
250/**
251 * @brief Tests the functionality of the SDL_CreateWindow function using different flags
252 */
253int
254video_createWindowVariousFlags(void *arg)
255{
256 SDL_Window* window;
257 const char* title = "video_createWindowVariousFlags Test Window";
258 int x, y, w, h;
259 int fVariation;
260 SDL_WindowFlags flags;
261
262 /* Standard window */
263 x = SDLTest_RandomIntegerInRange(1, 100);
264 y = SDLTest_RandomIntegerInRange(1, 100);
265 w = SDLTest_RandomIntegerInRange(320, 1024);
266 h = SDLTest_RandomIntegerInRange(320, 768);
267
268 for (fVariation = 0; fVariation < 14; fVariation++) {
269 switch(fVariation) {
270 case 0:
271 flags = SDL_WINDOW_FULLSCREEN;
272 /* Skip - blanks screen; comment out next line to run test */
273 continue;
274 break;
275 case 1:
276 flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
277 /* Skip - blanks screen; comment out next line to run test */
278 continue;
279 break;
280 case 2:
281 flags = SDL_WINDOW_OPENGL;
282 break;
283 case 3:
284 flags = SDL_WINDOW_SHOWN;
285 break;
286 case 4:
287 flags = SDL_WINDOW_HIDDEN;
288 break;
289 case 5:
290 flags = SDL_WINDOW_BORDERLESS;
291 break;
292 case 6:
293 flags = SDL_WINDOW_RESIZABLE;
294 break;
295 case 7:
296 flags = SDL_WINDOW_MINIMIZED;
297 break;
298 case 8:
299 flags = SDL_WINDOW_MAXIMIZED;
300 break;
301 case 9:
302 flags = SDL_WINDOW_MOUSE_GRABBED;
303 break;
304 case 10:
305 flags = SDL_WINDOW_INPUT_FOCUS;
306 break;
307 case 11:
308 flags = SDL_WINDOW_MOUSE_FOCUS;
309 break;
310 case 12:
311 flags = SDL_WINDOW_FOREIGN;
312 break;
313 case 13:
314 flags = SDL_WINDOW_KEYBOARD_GRABBED;
315 break;
316 }
317
318 window = SDL_CreateWindow(title, x, y, w, h, flags);
319 SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
320 SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
321
322 /* Clean up */
323 _destroyVideoSuiteTestWindow(window);
324 }
325
326 return TEST_COMPLETED;
327}
328
329
330/**
331 * @brief Tests the functionality of the SDL_GetWindowFlags function
332 */
333int
334video_getWindowFlags(void *arg)
335{
336 SDL_Window* window;
337 const char* title = "video_getWindowFlags Test Window";
338 SDL_WindowFlags flags;
339 Uint32 actualFlags;
340
341 /* Reliable flag set always set in test window */
342 flags = SDL_WINDOW_SHOWN;
343
344 /* Call against new test window */
345 window = _createVideoSuiteTestWindow(title);
346 if (window != NULL) {
347 actualFlags = SDL_GetWindowFlags(window);
348 SDLTest_AssertPass("Call to SDL_GetWindowFlags()");
349 SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
350 }
351
352 /* Clean up */
353 _destroyVideoSuiteTestWindow(window);
354
355 return TEST_COMPLETED;
356}
357
358/**
359 * @brief Tests the functionality of the SDL_GetNumDisplayModes function
360 */
361int
362video_getNumDisplayModes(void *arg)
363{
364 int result;
365 int displayNum;
366 int i;
367
368 /* Get number of displays */
369 displayNum = SDL_GetNumVideoDisplays();
370 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
371
372 /* Make call for each display */
373 for (i=0; i<displayNum; i++) {
374 result = SDL_GetNumDisplayModes(i);
375 SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
376 SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
377 }
378
379 return TEST_COMPLETED;
380}
381
382/**
383 * @brief Tests negative call to SDL_GetNumDisplayModes function
384 */
385int
386video_getNumDisplayModesNegative(void *arg)
387{
388 int result;
389 int displayNum;
390 int displayIndex;
391
392 /* Get number of displays */
393 displayNum = SDL_GetNumVideoDisplays();
394 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
395
396 /* Invalid boundary values */
397 displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
398 result = SDL_GetNumDisplayModes(displayIndex);
399 SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
400 SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
401
402 /* Large (out-of-bounds) display index */
403 displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
404 result = SDL_GetNumDisplayModes(displayIndex);
405 SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
406 SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
407
408 displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
409 result = SDL_GetNumDisplayModes(displayIndex);
410 SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
411 SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
412
413 return TEST_COMPLETED;
414}
415
416/**
417 * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
418 */
419int
420video_getClosestDisplayModeCurrentResolution(void *arg)
421{
422 int result;
423 SDL_DisplayMode current;
424 SDL_DisplayMode target;
425 SDL_DisplayMode closest;
426 SDL_DisplayMode* dResult;
427 int displayNum;
428 int i;
429 int variation;
430
431 /* Get number of displays */
432 displayNum = SDL_GetNumVideoDisplays();
433 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
434
435 /* Make calls for each display */
436 for (i=0; i<displayNum; i++) {
437 SDLTest_Log("Testing against display: %d", i);
438
439 /* Get first display mode to get a sane resolution; this should always work */
440 result = SDL_GetDisplayMode(i, 0, &current);
441 SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
442 SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
443 if (result != 0) {
444 return TEST_ABORTED;
445 }
446
447 /* Set the desired resolution equals to current resolution */
448 target.w = current.w;
449 target.h = current.h;
450 for (variation = 0; variation < 8; variation ++) {
451 /* Vary constraints on other query parameters */
452 target.format = (variation & 1) ? current.format : 0;
453 target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
454 target.driverdata = (variation & 4) ? current.driverdata : 0;
455
456 /* Make call */
457 dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
458 SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
459 SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL");
460
461 /* Check that one gets the current resolution back again */
462 SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
463 SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
464 SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
465 SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
466 }
467 }
468
469 return TEST_COMPLETED;
470}
471
472/**
473 * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
474 */
475int
476video_getClosestDisplayModeRandomResolution(void *arg)
477{
478 SDL_DisplayMode target;
479 SDL_DisplayMode closest;
480 int displayNum;
481 int i;
482 int variation;
483
484 /* Get number of displays */
485 displayNum = SDL_GetNumVideoDisplays();
486 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
487
488 /* Make calls for each display */
489 for (i=0; i<displayNum; i++) {
490 SDLTest_Log("Testing against display: %d", i);
491
492 for (variation = 0; variation < 16; variation ++) {
493
494 /* Set random constraints */
495 target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
496 target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
497 target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
498 target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
499 target.driverdata = 0;
500
501 /* Make call; may or may not find anything, so don't validate any further */
502 SDL_GetClosestDisplayMode(i, &target, &closest);
503 SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
504 }
505 }
506
507 return TEST_COMPLETED;
508}
509
510/**
511 * @brief Tests call to SDL_GetWindowBrightness
512 *
513* @sa http://wiki.libsdl.org/SDL_GetWindowBrightness
514 */
515int
516video_getWindowBrightness(void *arg)
517{
518 SDL_Window* window;
519 const char* title = "video_getWindowBrightness Test Window";
520 float result;
521
522 /* Call against new test window */
523 window = _createVideoSuiteTestWindow(title);
524 if (window != NULL) {
525 result = SDL_GetWindowBrightness(window);
526 SDLTest_AssertPass("Call to SDL_GetWindowBrightness()");
527 SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
528 }
529
530 /* Clean up */
531 _destroyVideoSuiteTestWindow(window);
532
533 return TEST_COMPLETED;
534}
535
536/**
537 * @brief Tests call to SDL_GetWindowBrightness with invalid input
538 *
539* @sa http://wiki.libsdl.org/SDL_GetWindowBrightness
540 */
541int
542video_getWindowBrightnessNegative(void *arg)
543{
544 const char *invalidWindowError = "Invalid window";
545 char *lastError;
546 float result;
547
548 /* Call against invalid window */
549 result = SDL_GetWindowBrightness(NULL);
550 SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)");
551 SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result);
552 lastError = (char *)SDL_GetError();
553 SDLTest_AssertPass("SDL_GetError()");
554 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
555 if (lastError != NULL) {
556 SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
557 "SDL_GetError(): expected message '%s', was message: '%s'",
558 invalidWindowError,
559 lastError);
560 }
561
562 return TEST_COMPLETED;
563}
564
565/**
566 * @brief Tests call to SDL_GetWindowDisplayMode
567 *
568 * @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
569 */
570int
571video_getWindowDisplayMode(void *arg)
572{
573 SDL_Window* window;
574 const char* title = "video_getWindowDisplayMode Test Window";
575 SDL_DisplayMode mode;
576 int result;
577
578 /* Invalidate part of the mode content so we can check values later */
579 mode.w = -1;
580 mode.h = -1;
581 mode.refresh_rate = -1;
582
583 /* Call against new test window */
584 window = _createVideoSuiteTestWindow(title);
585 if (window != NULL) {
586 result = SDL_GetWindowDisplayMode(window, &mode);
587 SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()");
588 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
589 SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w);
590 SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h);
591 SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate);
592 }
593
594 /* Clean up */
595 _destroyVideoSuiteTestWindow(window);
596
597 return TEST_COMPLETED;
598}
599
600/* Helper function that checks for an 'Invalid window' error */
601void _checkInvalidWindowError()
602{
603 const char *invalidWindowError = "Invalid window";
604 char *lastError;
605
606 lastError = (char *)SDL_GetError();
607 SDLTest_AssertPass("SDL_GetError()");
608 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
609 if (lastError != NULL) {
610 SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
611 "SDL_GetError(): expected message '%s', was message: '%s'",
612 invalidWindowError,
613 lastError);
614 SDL_ClearError();
615 SDLTest_AssertPass("Call to SDL_ClearError()");
616 }
617}
618
619/**
620 * @brief Tests call to SDL_GetWindowDisplayMode with invalid input
621 *
622 * @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
623 */
624int
625video_getWindowDisplayModeNegative(void *arg)
626{
627 const char *expectedError = "Parameter 'mode' is invalid";
628 char *lastError;
629 SDL_Window* window;
630 const char* title = "video_getWindowDisplayModeNegative Test Window";
631 SDL_DisplayMode mode;
632 int result;
633
634 /* Call against new test window */
635 window = _createVideoSuiteTestWindow(title);
636 if (window != NULL) {
637 result = SDL_GetWindowDisplayMode(window, NULL);
638 SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)");
639 SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
640 lastError = (char *)SDL_GetError();
641 SDLTest_AssertPass("SDL_GetError()");
642 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
643 if (lastError != NULL) {
644 SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0,
645 "SDL_GetError(): expected message '%s', was message: '%s'",
646 expectedError,
647 lastError);
648 }
649 }
650
651 /* Clean up */
652 _destroyVideoSuiteTestWindow(window);
653
654 /* Call against invalid window */
655 result = SDL_GetWindowDisplayMode(NULL, &mode);
656 SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)");
657 SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
658 _checkInvalidWindowError();
659
660 return TEST_COMPLETED;
661}
662
663/**
664 * @brief Tests call to SDL_GetWindowGammaRamp
665 *
666 * @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp
667 */
668int
669video_getWindowGammaRamp(void *arg)
670{
671 SDL_Window* window;
672 const char* title = "video_getWindowGammaRamp Test Window";
673 Uint16 red[256];
674 Uint16 green[256];
675 Uint16 blue[256];
676 int result;
677
678 /* Call against new test window */
679 window = _createVideoSuiteTestWindow(title);
680 if (window == NULL) return TEST_ABORTED;
681
682 /* Retrieve no channel */
683 result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL);
684 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)");
685 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
686
687 /* Retrieve single channel */
688 result = SDL_GetWindowGammaRamp(window, red, NULL, NULL);
689 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)");
690 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
691
692 result = SDL_GetWindowGammaRamp(window, NULL, green, NULL);
693 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)");
694 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
695
696 result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue);
697 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)");
698 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
699
700 /* Retrieve two channels */
701 result = SDL_GetWindowGammaRamp(window, red, green, NULL);
702 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)");
703 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
704
705 result = SDL_GetWindowGammaRamp(window, NULL, green, blue);
706 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)");
707 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
708
709 result = SDL_GetWindowGammaRamp(window, red, NULL, blue);
710 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)");
711 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
712
713 /* Retrieve all channels */
714 result = SDL_GetWindowGammaRamp(window, red, green, blue);
715 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)");
716 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
717
718 /* Clean up */
719 _destroyVideoSuiteTestWindow(window);
720
721 return TEST_COMPLETED;
722}
723
724/**
725 * @brief Tests call to SDL_GetWindowGammaRamp with invalid input
726 *
727* @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp
728 */
729int
730video_getWindowGammaRampNegative(void *arg)
731{
732 Uint16 red[256];
733 Uint16 green[256];
734 Uint16 blue[256];
735 int result;
736
737 SDL_ClearError();
738 SDLTest_AssertPass("Call to SDL_ClearError()");
739
740 /* Call against invalid window */
741 result = SDL_GetWindowGammaRamp(NULL, red, green, blue);
742 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)");
743 SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %i", result);
744 _checkInvalidWindowError();
745
746 return TEST_COMPLETED;
747}
748
749/* Helper for setting and checking the window mouse grab state */
750void
751_setAndCheckWindowMouseGrabState(SDL_Window* window, SDL_bool desiredState)
752{
753 SDL_bool currentState;
754
755 /* Set state */
756 SDL_SetWindowMouseGrab(window, desiredState);
757 SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
758
759 /* Get and check state */
760 currentState = SDL_GetWindowMouseGrab(window);
761 SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
762 SDLTest_AssertCheck(
763 currentState == desiredState,
764 "Validate returned state; expected: %s, got: %s",
765 (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
766 (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
767
768 if (desiredState) {
769 SDLTest_AssertCheck(
770 SDL_GetGrabbedWindow() == window,
771 "Grabbed window should be to our window");
772 SDLTest_AssertCheck(
773 SDL_GetWindowGrab(window),
774 "SDL_GetWindowGrab() should return SDL_TRUE");
775 SDLTest_AssertCheck(
776 SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED,
777 "SDL_WINDOW_MOUSE_GRABBED should be set");
778 } else {
779 SDLTest_AssertCheck(
780 !(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED),
781 "SDL_WINDOW_MOUSE_GRABBED should be unset");
782 }
783}
784
785/* Helper for setting and checking the window keyboard grab state */
786void
787_setAndCheckWindowKeyboardGrabState(SDL_Window* window, SDL_bool desiredState)
788{
789 SDL_bool currentState;
790
791 /* Set state */
792 SDL_SetWindowKeyboardGrab(window, desiredState);
793 SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
794
795 /* Get and check state */
796 currentState = SDL_GetWindowKeyboardGrab(window);
797 SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
798 SDLTest_AssertCheck(
799 currentState == desiredState,
800 "Validate returned state; expected: %s, got: %s",
801 (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
802 (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
803
804 if (desiredState) {
805 SDLTest_AssertCheck(
806 SDL_GetGrabbedWindow() == window,
807 "Grabbed window should be set to our window");
808 SDLTest_AssertCheck(
809 SDL_GetWindowGrab(window),
810 "SDL_GetWindowGrab() should return SDL_TRUE");
811 SDLTest_AssertCheck(
812 SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED,
813 "SDL_WINDOW_KEYBOARD_GRABBED should be set");
814 } else {
815 SDLTest_AssertCheck(
816 !(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED),
817 "SDL_WINDOW_KEYBOARD_GRABBED should be unset");
818 }
819}
820
821/**
822 * @brief Tests keyboard and mouse grab support
823 *
824 * @sa http://wiki.libsdl.org/SDL_GetWindowGrab
825 * @sa http://wiki.libsdl.org/SDL_SetWindowGrab
826 */
827int
828video_getSetWindowGrab(void *arg)
829{
830 const char* title = "video_getSetWindowGrab Test Window";
831 SDL_Window* window;
832 SDL_bool originalMouseState, originalKeyboardState;
833
834 /* Call against new test window */
835 window = _createVideoSuiteTestWindow(title);
836 if (window == NULL) return TEST_ABORTED;
837
838 /* Get state */
839 originalMouseState = SDL_GetWindowMouseGrab(window);
840 SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
841 originalKeyboardState = SDL_GetWindowKeyboardGrab(window);
842 SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
843
844 /* F */
845 _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
846 _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
847 SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
848 "SDL_GetWindowGrab should return SDL_FALSE");
849 SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
850 "Expected NULL grabbed window");
851
852 /* F --> F */
853 _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
854 _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
855 SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
856 "Expected NULL grabbed window");
857
858 /* F --> T */
859 _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
860 _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
861 SDLTest_AssertCheck(SDL_GetWindowGrab(window),
862 "SDL_GetWindowGrab() should return SDL_TRUE");
863
864 /* T --> T */
865 _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
866 _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
867 SDLTest_AssertCheck(SDL_GetWindowGrab(window),
868 "SDL_GetWindowGrab() should return SDL_TRUE");
869
870 /* M: T --> F */
871 /* K: T --> T */
872 _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
873 _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
874 SDLTest_AssertCheck(SDL_GetWindowGrab(window),
875 "SDL_GetWindowGrab() should return SDL_TRUE");
876
877 /* M: F --> T */
878 /* K: T --> F */
879 _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
880 _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
881 SDLTest_AssertCheck(SDL_GetWindowGrab(window),
882 "SDL_GetWindowGrab() should return SDL_TRUE");
883
884 /* M: T --> F */
885 /* K: F --> F */
886 _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
887 _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
888 SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
889 "SDL_GetWindowGrab() should return SDL_FALSE");
890 SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
891 "Expected NULL grabbed window");
892
893 /* Using the older SDL_SetWindowGrab API should only grab mouse by default */
894 SDL_SetWindowGrab(window, SDL_TRUE);
895 SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
896 SDLTest_AssertCheck(SDL_GetWindowGrab(window),
897 "SDL_GetWindowGrab() should return SDL_TRUE");
898 SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
899 "SDL_GetWindowMouseGrab() should return SDL_TRUE");
900 SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
901 "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
902 SDL_SetWindowGrab(window, SDL_FALSE);
903 SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
904 "SDL_GetWindowGrab() should return SDL_FALSE");
905 SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
906 "SDL_GetWindowMouseGrab() should return SDL_FALSE");
907 SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
908 "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
909
910 /* Now test with SDL_HINT_GRAB_KEYBOARD set. We should get keyboard grab now. */
911 SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
912 SDL_SetWindowGrab(window, SDL_TRUE);
913 SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
914 SDLTest_AssertCheck(SDL_GetWindowGrab(window),
915 "SDL_GetWindowGrab() should return SDL_TRUE");
916 SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
917 "SDL_GetWindowMouseGrab() should return SDL_TRUE");
918 SDLTest_AssertCheck(SDL_GetWindowKeyboardGrab(window),
919 "SDL_GetWindowKeyboardGrab() should return SDL_TRUE");
920 SDL_SetWindowGrab(window, SDL_FALSE);
921 SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
922 "SDL_GetWindowGrab() should return SDL_FALSE");
923 SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
924 "SDL_GetWindowMouseGrab() should return SDL_FALSE");
925 SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
926 "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
927
928 /* Negative tests */
929 SDL_GetWindowGrab(NULL);
930 SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
931 _checkInvalidWindowError();
932
933 SDL_GetWindowKeyboardGrab(NULL);
934 SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)");
935 _checkInvalidWindowError();
936
937 SDL_SetWindowGrab(NULL, SDL_FALSE);
938 SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
939 _checkInvalidWindowError();
940
941 SDL_SetWindowKeyboardGrab(NULL, SDL_FALSE);
942 SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE)");
943 _checkInvalidWindowError();
944
945 SDL_SetWindowGrab(NULL, SDL_TRUE);
946 SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_TRUE)");
947 _checkInvalidWindowError();
948
949 SDL_SetWindowKeyboardGrab(NULL, SDL_TRUE);
950 SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE)");
951 _checkInvalidWindowError();
952
953 /* Restore state */
954 _setAndCheckWindowMouseGrabState(window, originalMouseState);
955 _setAndCheckWindowKeyboardGrabState(window, originalKeyboardState);
956
957 /* Clean up */
958 _destroyVideoSuiteTestWindow(window);
959
960 return TEST_COMPLETED;
961}
962
963
964/**
965 * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID
966 *
967 * @sa http://wiki.libsdl.org/SDL_GetWindowID
968 * @sa http://wiki.libsdl.org/SDL_SetWindowFromID
969 */
970int
971video_getWindowId(void *arg)
972{
973 const char* title = "video_getWindowId Test Window";
974 SDL_Window* window;
975 SDL_Window* result;
976 Uint32 id, randomId;
977
978 /* Call against new test window */
979 window = _createVideoSuiteTestWindow(title);
980 if (window == NULL) return TEST_ABORTED;
981
982 /* Get ID */
983 id = SDL_GetWindowID(window);
984 SDLTest_AssertPass("Call to SDL_GetWindowID()");
985
986 /* Get window from ID */
987 result = SDL_GetWindowFromID(id);
988 SDLTest_AssertPass("Call to SDL_GetWindowID(%d)", id);
989 SDLTest_AssertCheck(result == window, "Verify result matches window pointer");
990
991 /* Get window from random large ID, no result check */
992 randomId = SDLTest_RandomIntegerInRange(UINT8_MAX,UINT16_MAX);
993 result = SDL_GetWindowFromID(randomId);
994 SDLTest_AssertPass("Call to SDL_GetWindowID(%d/random_large)", randomId);
995
996 /* Get window from 0 and Uint32 max ID, no result check */
997 result = SDL_GetWindowFromID(0);
998 SDLTest_AssertPass("Call to SDL_GetWindowID(0)");
999 result = SDL_GetWindowFromID(UINT32_MAX);
1000 SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)");
1001
1002 /* Clean up */
1003 _destroyVideoSuiteTestWindow(window);
1004
1005 /* Get window from ID for closed window */
1006 result = SDL_GetWindowFromID(id);
1007 SDLTest_AssertPass("Call to SDL_GetWindowID(%d/closed_window)", id);
1008 SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
1009
1010 /* Negative test */
1011 SDL_ClearError();
1012 SDLTest_AssertPass("Call to SDL_ClearError()");
1013 id = SDL_GetWindowID(NULL);
1014 SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
1015 _checkInvalidWindowError();
1016
1017 return TEST_COMPLETED;
1018}
1019
1020/**
1021 * @brief Tests call to SDL_GetWindowPixelFormat
1022 *
1023 * @sa http://wiki.libsdl.org/SDL_GetWindowPixelFormat
1024 */
1025int
1026video_getWindowPixelFormat(void *arg)
1027{
1028 const char* title = "video_getWindowPixelFormat Test Window";
1029 SDL_Window* window;
1030 Uint32 format;
1031
1032 /* Call against new test window */
1033 window = _createVideoSuiteTestWindow(title);
1034 if (window == NULL) return TEST_ABORTED;
1035
1036 /* Get format */
1037 format = SDL_GetWindowPixelFormat(window);
1038 SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
1039 SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %d", SDL_PIXELFORMAT_UNKNOWN, format);
1040
1041 /* Clean up */
1042 _destroyVideoSuiteTestWindow(window);
1043
1044 /* Negative test */
1045 SDL_ClearError();
1046 SDLTest_AssertPass("Call to SDL_ClearError()");
1047 format = SDL_GetWindowPixelFormat(NULL);
1048 SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
1049 _checkInvalidWindowError();
1050
1051 return TEST_COMPLETED;
1052}
1053
1054/**
1055 * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
1056 *
1057 * @sa http://wiki.libsdl.org/SDL_GetWindowPosition
1058 * @sa http://wiki.libsdl.org/SDL_SetWindowPosition
1059 */
1060int
1061video_getSetWindowPosition(void *arg)
1062{
1063 const char* title = "video_getSetWindowPosition Test Window";
1064 SDL_Window* window;
1065 int xVariation, yVariation;
1066 int referenceX, referenceY;
1067 int currentX, currentY;
1068 int desiredX, desiredY;
1069
1070 /* Call against new test window */
1071 window = _createVideoSuiteTestWindow(title);
1072 if (window == NULL) return TEST_ABORTED;
1073
1074 for (xVariation = 0; xVariation < 4; xVariation++) {
1075 for (yVariation = 0; yVariation < 4; yVariation++) {
1076 switch(xVariation) {
1077 case 0:
1078 /* Zero X Position */
1079 desiredX = 0;
1080 break;
1081 case 1:
1082 /* Random X position inside screen */
1083 desiredX = SDLTest_RandomIntegerInRange(1, 100);
1084 break;
1085 case 2:
1086 /* Random X position outside screen (positive) */
1087 desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
1088 break;
1089 case 3:
1090 /* Random X position outside screen (negative) */
1091 desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
1092 break;
1093 }
1094
1095 switch(yVariation) {
1096 case 0:
1097 /* Zero X Position */
1098 desiredY = 0;
1099 break;
1100 case 1:
1101 /* Random X position inside screen */
1102 desiredY = SDLTest_RandomIntegerInRange(1, 100);
1103 break;
1104 case 2:
1105 /* Random X position outside screen (positive) */
1106 desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
1107 break;
1108 case 3:
1109 /* Random Y position outside screen (negative) */
1110 desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
1111 break;
1112 }
1113
1114 /* Set position */
1115 SDL_SetWindowPosition(window, desiredX, desiredY);
1116 SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
1117
1118 /* Get position */
1119 currentX = desiredX + 1;
1120 currentY = desiredY + 1;
1121 SDL_GetWindowPosition(window, &currentX, &currentY);
1122 SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
1123 SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
1124 SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
1125
1126 /* Get position X */
1127 currentX = desiredX + 1;
1128 SDL_GetWindowPosition(window, &currentX, NULL);
1129 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
1130 SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
1131
1132 /* Get position Y */
1133 currentY = desiredY + 1;
1134 SDL_GetWindowPosition(window, NULL, &currentY);
1135 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
1136 SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
1137 }
1138 }
1139
1140 /* Dummy call with both pointers NULL */
1141 SDL_GetWindowPosition(window, NULL, NULL);
1142 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
1143
1144 /* Clean up */
1145 _destroyVideoSuiteTestWindow(window);
1146
1147 /* Set some 'magic' value for later check that nothing was changed */
1148 referenceX = SDLTest_RandomSint32();
1149 referenceY = SDLTest_RandomSint32();
1150 currentX = referenceX;
1151 currentY = referenceY;
1152 desiredX = SDLTest_RandomSint32();
1153 desiredY = SDLTest_RandomSint32();
1154
1155 /* Negative tests */
1156 SDL_ClearError();
1157 SDLTest_AssertPass("Call to SDL_ClearError()");
1158 SDL_GetWindowPosition(NULL, &currentX, &currentY);
1159 SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
1160 SDLTest_AssertCheck(
1161 currentX == referenceX && currentY == referenceY,
1162 "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
1163 referenceX, referenceY,
1164 currentX, currentY);
1165 _checkInvalidWindowError();
1166
1167 SDL_GetWindowPosition(NULL, NULL, NULL);
1168 SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
1169 _checkInvalidWindowError();
1170
1171 SDL_SetWindowPosition(NULL, desiredX, desiredY);
1172 SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
1173 _checkInvalidWindowError();
1174
1175 return TEST_COMPLETED;
1176}
1177
1178/* Helper function that checks for an 'Invalid parameter' error */
1179void _checkInvalidParameterError()
1180{
1181 const char *invalidParameterError = "Parameter";
1182 char *lastError;
1183
1184 lastError = (char *)SDL_GetError();
1185 SDLTest_AssertPass("SDL_GetError()");
1186 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
1187 if (lastError != NULL) {
1188 SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
1189 "SDL_GetError(): expected message starts with '%s', was message: '%s'",
1190 invalidParameterError,
1191 lastError);
1192 SDL_ClearError();
1193 SDLTest_AssertPass("Call to SDL_ClearError()");
1194 }
1195}
1196
1197/**
1198 * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize
1199 *
1200 * @sa http://wiki.libsdl.org/SDL_GetWindowSize
1201 * @sa http://wiki.libsdl.org/SDL_SetWindowSize
1202 */
1203int
1204video_getSetWindowSize(void *arg)
1205{
1206 const char* title = "video_getSetWindowSize Test Window";
1207 SDL_Window* window;
1208 int result;
1209 SDL_Rect display;
1210 int maxwVariation, maxhVariation;
1211 int wVariation, hVariation;
1212 int referenceW, referenceH;
1213 int currentW, currentH;
1214 int desiredW, desiredH;
1215
1216 /* Get display bounds for size range */
1217 result = SDL_GetDisplayBounds(0, &display);
1218 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1219 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1220 if (result != 0) return TEST_ABORTED;
1221
1222 /* Call against new test window */
1223 window = _createVideoSuiteTestWindow(title);
1224 if (window == NULL) return TEST_ABORTED;
1225
1226#ifdef __WIN32__
1227 /* Platform clips window size to screen size */
1228 maxwVariation = 4;
1229 maxhVariation = 4;
1230#else
1231 /* Platform allows window size >= screen size */
1232 maxwVariation = 5;
1233 maxhVariation = 5;
1234#endif
1235
1236 for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
1237 for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
1238 switch(wVariation) {
1239 case 0:
1240 /* 1 Pixel Wide */
1241 desiredW = 1;
1242 break;
1243 case 1:
1244 /* Random width inside screen */
1245 desiredW = SDLTest_RandomIntegerInRange(1, 100);
1246 break;
1247 case 2:
1248 /* Width 1 pixel smaller than screen */
1249 desiredW = display.w - 1;
1250 break;
1251 case 3:
1252 /* Width at screen size */
1253 desiredW = display.w;
1254 break;
1255 case 4:
1256 /* Width 1 pixel larger than screen */
1257 desiredW = display.w + 1;
1258 break;
1259 }
1260
1261 switch(hVariation) {
1262 case 0:
1263 /* 1 Pixel High */
1264 desiredH = 1;
1265 break;
1266 case 1:
1267 /* Random height inside screen */
1268 desiredH = SDLTest_RandomIntegerInRange(1, 100);
1269 break;
1270 case 2:
1271 /* Height 1 pixel smaller than screen */
1272 desiredH = display.h - 1;
1273 break;
1274 case 3:
1275 /* Height at screen size */
1276 desiredH = display.h;
1277 break;
1278 case 4:
1279 /* Height 1 pixel larger than screen */
1280 desiredH = display.h + 1;
1281 break;
1282 }
1283
1284 /* Set size */
1285 SDL_SetWindowSize(window, desiredW, desiredH);
1286 SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1287
1288 /* Get size */
1289 currentW = desiredW + 1;
1290 currentH = desiredH + 1;
1291 SDL_GetWindowSize(window, &currentW, &currentH);
1292 SDLTest_AssertPass("Call to SDL_GetWindowSize()");
1293 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1294 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1295
1296 /* Get just width */
1297 currentW = desiredW + 1;
1298 SDL_GetWindowSize(window, &currentW, NULL);
1299 SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
1300 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1301
1302 /* Get just height */
1303 currentH = desiredH + 1;
1304 SDL_GetWindowSize(window, NULL, &currentH);
1305 SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
1306 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1307 }
1308 }
1309
1310 /* Dummy call with both pointers NULL */
1311 SDL_GetWindowSize(window, NULL, NULL);
1312 SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
1313
1314 /* Negative tests for parameter input */
1315 SDL_ClearError();
1316 SDLTest_AssertPass("Call to SDL_ClearError()");
1317 for (desiredH = -2; desiredH < 2; desiredH++) {
1318 for (desiredW = -2; desiredW < 2; desiredW++) {
1319 if (desiredW <= 0 || desiredH <= 0) {
1320 SDL_SetWindowSize(window, desiredW, desiredH);
1321 SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1322 _checkInvalidParameterError();
1323 }
1324 }
1325 }
1326
1327 /* Clean up */
1328 _destroyVideoSuiteTestWindow(window);
1329
1330 /* Set some 'magic' value for later check that nothing was changed */
1331 referenceW = SDLTest_RandomSint32();
1332 referenceH = SDLTest_RandomSint32();
1333 currentW = referenceW;
1334 currentH = referenceH;
1335 desiredW = SDLTest_RandomSint32();
1336 desiredH = SDLTest_RandomSint32();
1337
1338 /* Negative tests for window input */
1339 SDL_ClearError();
1340 SDLTest_AssertPass("Call to SDL_ClearError()");
1341 SDL_GetWindowSize(NULL, &currentW, &currentH);
1342 SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
1343 SDLTest_AssertCheck(
1344 currentW == referenceW && currentH == referenceH,
1345 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1346 referenceW, referenceH,
1347 currentW, currentH);
1348 _checkInvalidWindowError();
1349
1350 SDL_GetWindowSize(NULL, NULL, NULL);
1351 SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
1352 _checkInvalidWindowError();
1353
1354 SDL_SetWindowSize(NULL, desiredW, desiredH);
1355 SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
1356 _checkInvalidWindowError();
1357
1358 return TEST_COMPLETED;
1359}
1360
1361/**
1362 * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
1363 *
1364 */
1365int
1366video_getSetWindowMinimumSize(void *arg)
1367{
1368 const char* title = "video_getSetWindowMinimumSize Test Window";
1369 SDL_Window* window;
1370 int result;
1371 SDL_Rect display;
1372 int wVariation, hVariation;
1373 int referenceW, referenceH;
1374 int currentW, currentH;
1375 int desiredW, desiredH;
1376
1377 /* Get display bounds for size range */
1378 result = SDL_GetDisplayBounds(0, &display);
1379 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1380 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1381 if (result != 0) return TEST_ABORTED;
1382
1383 /* Call against new test window */
1384 window = _createVideoSuiteTestWindow(title);
1385 if (window == NULL) return TEST_ABORTED;
1386
1387 for (wVariation = 0; wVariation < 5; wVariation++) {
1388 for (hVariation = 0; hVariation < 5; hVariation++) {
1389 switch(wVariation) {
1390 case 0:
1391 /* 1 Pixel Wide */
1392 desiredW = 1;
1393 break;
1394 case 1:
1395 /* Random width inside screen */
1396 desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1397 break;
1398 case 2:
1399 /* Width at screen size */
1400 desiredW = display.w;
1401 break;
1402 }
1403
1404 switch(hVariation) {
1405 case 0:
1406 /* 1 Pixel High */
1407 desiredH = 1;
1408 break;
1409 case 1:
1410 /* Random height inside screen */
1411 desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1412 break;
1413 case 2:
1414 /* Height at screen size */
1415 desiredH = display.h;
1416 break;
1417 case 4:
1418 /* Height 1 pixel larger than screen */
1419 desiredH = display.h + 1;
1420 break;
1421 }
1422
1423 /* Set size */
1424 SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1425 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1426
1427 /* Get size */
1428 currentW = desiredW + 1;
1429 currentH = desiredH + 1;
1430 SDL_GetWindowMinimumSize(window, &currentW, &currentH);
1431 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
1432 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1433 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1434
1435 /* Get just width */
1436 currentW = desiredW + 1;
1437 SDL_GetWindowMinimumSize(window, &currentW, NULL);
1438 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
1439 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1440
1441 /* Get just height */
1442 currentH = desiredH + 1;
1443 SDL_GetWindowMinimumSize(window, NULL, &currentH);
1444 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
1445 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1446 }
1447 }
1448
1449 /* Dummy call with both pointers NULL */
1450 SDL_GetWindowMinimumSize(window, NULL, NULL);
1451 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
1452
1453 /* Negative tests for parameter input */
1454 SDL_ClearError();
1455 SDLTest_AssertPass("Call to SDL_ClearError()");
1456 for (desiredH = -2; desiredH < 2; desiredH++) {
1457 for (desiredW = -2; desiredW < 2; desiredW++) {
1458 if (desiredW <= 0 || desiredH <= 0) {
1459 SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1460 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1461 _checkInvalidParameterError();
1462 }
1463 }
1464 }
1465
1466 /* Clean up */
1467 _destroyVideoSuiteTestWindow(window);
1468
1469 /* Set some 'magic' value for later check that nothing was changed */
1470 referenceW = SDLTest_RandomSint32();
1471 referenceH = SDLTest_RandomSint32();
1472 currentW = referenceW;
1473 currentH = referenceH;
1474 desiredW = SDLTest_RandomSint32();
1475 desiredH = SDLTest_RandomSint32();
1476
1477 /* Negative tests for window input */
1478 SDL_ClearError();
1479 SDLTest_AssertPass("Call to SDL_ClearError()");
1480 SDL_GetWindowMinimumSize(NULL, &currentW, &currentH);
1481 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
1482 SDLTest_AssertCheck(
1483 currentW == referenceW && currentH == referenceH,
1484 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1485 referenceW, referenceH,
1486 currentW, currentH);
1487 _checkInvalidWindowError();
1488
1489 SDL_GetWindowMinimumSize(NULL, NULL, NULL);
1490 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
1491 _checkInvalidWindowError();
1492
1493 SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
1494 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
1495 _checkInvalidWindowError();
1496
1497 return TEST_COMPLETED;
1498}
1499
1500/**
1501 * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
1502 *
1503 */
1504int
1505video_getSetWindowMaximumSize(void *arg)
1506{
1507 const char* title = "video_getSetWindowMaximumSize Test Window";
1508 SDL_Window* window;
1509 int result;
1510 SDL_Rect display;
1511 int wVariation, hVariation;
1512 int referenceW, referenceH;
1513 int currentW, currentH;
1514 int desiredW, desiredH;
1515
1516 /* Get display bounds for size range */
1517 result = SDL_GetDisplayBounds(0, &display);
1518 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1519 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1520 if (result != 0) return TEST_ABORTED;
1521
1522 /* Call against new test window */
1523 window = _createVideoSuiteTestWindow(title);
1524 if (window == NULL) return TEST_ABORTED;
1525
1526 for (wVariation = 0; wVariation < 3; wVariation++) {
1527 for (hVariation = 0; hVariation < 3; hVariation++) {
1528 switch(wVariation) {
1529 case 0:
1530 /* 1 Pixel Wide */
1531 desiredW = 1;
1532 break;
1533 case 1:
1534 /* Random width inside screen */
1535 desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1536 break;
1537 case 2:
1538 /* Width at screen size */
1539 desiredW = display.w;
1540 break;
1541 }
1542
1543 switch(hVariation) {
1544 case 0:
1545 /* 1 Pixel High */
1546 desiredH = 1;
1547 break;
1548 case 1:
1549 /* Random height inside screen */
1550 desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1551 break;
1552 case 2:
1553 /* Height at screen size */
1554 desiredH = display.h;
1555 break;
1556 }
1557
1558 /* Set size */
1559 SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1560 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1561
1562 /* Get size */
1563 currentW = desiredW + 1;
1564 currentH = desiredH + 1;
1565 SDL_GetWindowMaximumSize(window, &currentW, &currentH);
1566 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
1567 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1568 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1569
1570 /* Get just width */
1571 currentW = desiredW + 1;
1572 SDL_GetWindowMaximumSize(window, &currentW, NULL);
1573 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
1574 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1575
1576 /* Get just height */
1577 currentH = desiredH + 1;
1578 SDL_GetWindowMaximumSize(window, NULL, &currentH);
1579 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
1580 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1581 }
1582 }
1583
1584 /* Dummy call with both pointers NULL */
1585 SDL_GetWindowMaximumSize(window, NULL, NULL);
1586 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
1587
1588 /* Negative tests for parameter input */
1589 SDL_ClearError();
1590 SDLTest_AssertPass("Call to SDL_ClearError()");
1591 for (desiredH = -2; desiredH < 2; desiredH++) {
1592 for (desiredW = -2; desiredW < 2; desiredW++) {
1593 if (desiredW <= 0 || desiredH <= 0) {
1594 SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1595 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1596 _checkInvalidParameterError();
1597 }
1598 }
1599 }
1600
1601 /* Clean up */
1602 _destroyVideoSuiteTestWindow(window);
1603
1604 /* Set some 'magic' value for later check that nothing was changed */
1605 referenceW = SDLTest_RandomSint32();
1606 referenceH = SDLTest_RandomSint32();
1607 currentW = referenceW;
1608 currentH = referenceH;
1609 desiredW = SDLTest_RandomSint32();
1610 desiredH = SDLTest_RandomSint32();
1611
1612 /* Negative tests */
1613 SDL_ClearError();
1614 SDLTest_AssertPass("Call to SDL_ClearError()");
1615 SDL_GetWindowMaximumSize(NULL, &currentW, &currentH);
1616 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
1617 SDLTest_AssertCheck(
1618 currentW == referenceW && currentH == referenceH,
1619 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1620 referenceW, referenceH,
1621 currentW, currentH);
1622 _checkInvalidWindowError();
1623
1624 SDL_GetWindowMaximumSize(NULL, NULL, NULL);
1625 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
1626 _checkInvalidWindowError();
1627
1628 SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
1629 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
1630 _checkInvalidWindowError();
1631
1632 return TEST_COMPLETED;
1633}
1634
1635
1636/**
1637 * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
1638 *
1639 * @sa http://wiki.libsdl.org/SDL_SetWindowData
1640 * @sa http://wiki.libsdl.org/SDL_GetWindowData
1641 */
1642int
1643video_getSetWindowData(void *arg)
1644{
1645 int returnValue = TEST_COMPLETED;
1646 const char* title = "video_setGetWindowData Test Window";
1647 SDL_Window* window;
1648 const char *referenceName = "TestName";
1649 const char *name = "TestName";
1650 const char *referenceName2 = "TestName2";
1651 const char *name2 = "TestName2";
1652 int datasize;
1653 char *referenceUserdata = NULL;
1654 char *userdata = NULL;
1655 char *referenceUserdata2 = NULL;
1656 char *userdata2 = NULL;
1657 char *result;
1658 int iteration;
1659
1660 /* Call against new test window */
1661 window = _createVideoSuiteTestWindow(title);
1662 if (window == NULL) return TEST_ABORTED;
1663
1664 /* Create testdata */
1665 datasize = SDLTest_RandomIntegerInRange(1, 32);
1666 referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
1667 if (referenceUserdata == NULL) {
1668 returnValue = TEST_ABORTED;
1669 goto cleanup;
1670 }
1671 userdata = SDL_strdup(referenceUserdata);
1672 if (userdata == NULL) {
1673 returnValue = TEST_ABORTED;
1674 goto cleanup;
1675 }
1676 datasize = SDLTest_RandomIntegerInRange(1, 32);
1677 referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
1678 if (referenceUserdata2 == NULL) {
1679 returnValue = TEST_ABORTED;
1680 goto cleanup;
1681 }
1682 userdata2 = (char *)SDL_strdup(referenceUserdata2);
1683 if (userdata2 == NULL) {
1684 returnValue = TEST_ABORTED;
1685 goto cleanup;
1686 }
1687
1688 /* Get non-existent data */
1689 result = (char *)SDL_GetWindowData(window, name);
1690 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1691 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1692 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1693
1694 /* Set data */
1695 result = (char *)SDL_SetWindowData(window, name, userdata);
1696 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
1697 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1698 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1699 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1700
1701 /* Get data (twice) */
1702 for (iteration = 1; iteration <= 2; iteration++) {
1703 result = (char *)SDL_GetWindowData(window, name);
1704 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
1705 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1706 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1707 }
1708
1709 /* Set data again twice */
1710 for (iteration = 1; iteration <= 2; iteration++) {
1711 result = (char *)SDL_SetWindowData(window, name, userdata);
1712 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
1713 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1714 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1715 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1716 }
1717
1718 /* Get data again */
1719 result = (char *)SDL_GetWindowData(window, name);
1720 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
1721 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1722 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1723
1724 /* Set data with new data */
1725 result = (char *)SDL_SetWindowData(window, name, userdata2);
1726 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
1727 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1728 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1729 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1730 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1731
1732 /* Set data with new data again */
1733 result = (char *)SDL_SetWindowData(window, name, userdata2);
1734 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
1735 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1736 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1737 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1738 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1739
1740 /* Get new data */
1741 result = (char *)SDL_GetWindowData(window, name);
1742 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1743 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1744 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1745
1746 /* Set data with NULL to clear */
1747 result = (char *)SDL_SetWindowData(window, name, NULL);
1748 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
1749 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1750 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1751 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1752 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1753
1754 /* Set data with NULL to clear again */
1755 result = (char *)SDL_SetWindowData(window, name, NULL);
1756 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
1757 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1758 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1759 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1760 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1761
1762 /* Get non-existent data */
1763 result = (char *)SDL_GetWindowData(window, name);
1764 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1765 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1766 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1767
1768 /* Get non-existent data new name */
1769 result = (char *)SDL_GetWindowData(window, name2);
1770 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
1771 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1772 SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
1773
1774 /* Set data (again) */
1775 result = (char *)SDL_SetWindowData(window, name, userdata);
1776 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
1777 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1778 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1779 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1780
1781 /* Get data (again) */
1782 result = (char *)SDL_GetWindowData(window, name);
1783 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
1784 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1785 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1786
1787 /* Negative test */
1788 SDL_ClearError();
1789 SDLTest_AssertPass("Call to SDL_ClearError()");
1790
1791 /* Set with invalid window */
1792 result = (char *)SDL_SetWindowData(NULL, name, userdata);
1793 SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)");
1794 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1795 _checkInvalidWindowError();
1796
1797 /* Set data with NULL name, valid userdata */
1798 result = (char *)SDL_SetWindowData(window, NULL, userdata);
1799 SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
1800 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1801 _checkInvalidParameterError();
1802
1803 /* Set data with empty name, valid userdata */
1804 result = (char *)SDL_SetWindowData(window, "", userdata);
1805 SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
1806 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1807 _checkInvalidParameterError();
1808
1809 /* Set data with NULL name, NULL userdata */
1810 result = (char *)SDL_SetWindowData(window, NULL, NULL);
1811 SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
1812 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1813 _checkInvalidParameterError();
1814
1815 /* Set data with empty name, NULL userdata */
1816 result = (char *)SDL_SetWindowData(window, "", NULL);
1817 SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
1818 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1819 _checkInvalidParameterError();
1820
1821 /* Get with invalid window */
1822 result = (char *)SDL_GetWindowData(NULL, name);
1823 SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)");
1824 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1825 _checkInvalidWindowError();
1826
1827 /* Get data with NULL name */
1828 result = (char *)SDL_GetWindowData(window, NULL);
1829 SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
1830 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1831 _checkInvalidParameterError();
1832
1833 /* Get data with empty name */
1834 result = (char *)SDL_GetWindowData(window, "");
1835 SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
1836 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1837 _checkInvalidParameterError();
1838
1839 /* Clean up */
1840 _destroyVideoSuiteTestWindow(window);
1841
1842 cleanup:
1843 SDL_free(referenceUserdata);
1844 SDL_free(referenceUserdata2);
1845 SDL_free(userdata);
1846 SDL_free(userdata2);
1847
1848 return returnValue;
1849}
1850
1851
1852/* ================= Test References ================== */
1853
1854/* Video test cases */
1855static const SDLTest_TestCaseReference videoTest1 =
1856 { (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED };
1857
1858static const SDLTest_TestCaseReference videoTest2 =
1859 { (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions", "Create windows at various locations", TEST_ENABLED };
1860
1861static const SDLTest_TestCaseReference videoTest3 =
1862 { (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED };
1863
1864static const SDLTest_TestCaseReference videoTest4 =
1865 { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED };
1866
1867static const SDLTest_TestCaseReference videoTest5 =
1868 { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
1869
1870static const SDLTest_TestCaseReference videoTest6 =
1871 { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
1872
1873static const SDLTest_TestCaseReference videoTest7 =
1874 { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
1875
1876static const SDLTest_TestCaseReference videoTest8 =
1877 { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
1878
1879static const SDLTest_TestCaseReference videoTest9 =
1880 { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
1881
1882static const SDLTest_TestCaseReference videoTest10 =
1883 { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED };
1884
1885static const SDLTest_TestCaseReference videoTest11 =
1886 { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED };
1887
1888static const SDLTest_TestCaseReference videoTest12 =
1889 { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED };
1890
1891static const SDLTest_TestCaseReference videoTest13 =
1892 { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED };
1893
1894static const SDLTest_TestCaseReference videoTest14 =
1895 { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED };
1896
1897static const SDLTest_TestCaseReference videoTest15 =
1898 { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED };
1899
1900static const SDLTest_TestCaseReference videoTest16 =
1901 { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED };
1902
1903static const SDLTest_TestCaseReference videoTest17 =
1904 { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED };
1905
1906static const SDLTest_TestCaseReference videoTest18 =
1907 { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED };
1908
1909static const SDLTest_TestCaseReference videoTest19 =
1910 { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED };
1911
1912static const SDLTest_TestCaseReference videoTest20 =
1913 { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED };
1914
1915static const SDLTest_TestCaseReference videoTest21 =
1916 { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED };
1917
1918static const SDLTest_TestCaseReference videoTest22 =
1919 { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED };
1920
1921static const SDLTest_TestCaseReference videoTest23 =
1922 { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
1923
1924/* Sequence of Video test cases */
1925static const SDLTest_TestCaseReference *videoTests[] = {
1926 &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
1927 &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
1928 &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
1929 &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
1930 &videoTest23, NULL
1931};
1932
1933/* Video test suite (global) */
1934SDLTest_TestSuiteReference videoTestSuite = {
1935 "Video",
1936 NULL,
1937 videoTests,
1938 NULL
1939};
1940