7c5b983badf35a1f363319acd9687a6048c475dc
[platform/upstream/SDL.git] / test / testautomation_video.c
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  */
26 SDL_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  */
49 void _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  */
63 int
64 video_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  */
115 int
116 video_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  */
196 int
197 video_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  */
253 int
254 video_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 < 13; 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_INPUT_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     }
314
315     window = SDL_CreateWindow(title, x, y, w, h, flags);
316     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
317     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
318
319     /* Clean up */
320     _destroyVideoSuiteTestWindow(window);
321   }
322
323   return TEST_COMPLETED;
324 }
325
326
327 /**
328  * @brief Tests the functionality of the SDL_GetWindowFlags function
329  */
330 int
331 video_getWindowFlags(void *arg)
332 {
333   SDL_Window* window;
334   const char* title = "video_getWindowFlags Test Window";
335   SDL_WindowFlags flags;
336   Uint32 actualFlags;
337
338   /* Reliable flag set always set in test window */
339   flags = SDL_WINDOW_SHOWN;
340
341   /* Call against new test window */
342   window = _createVideoSuiteTestWindow(title);
343   if (window != NULL) {
344       actualFlags = SDL_GetWindowFlags(window);
345       SDLTest_AssertPass("Call to SDL_GetWindowFlags()");
346       SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
347   }
348
349   /* Clean up */
350   _destroyVideoSuiteTestWindow(window);
351
352   return TEST_COMPLETED;
353 }
354
355 /**
356  * @brief Tests the functionality of the SDL_GetNumDisplayModes function
357  */
358 int
359 video_getNumDisplayModes(void *arg)
360 {
361   int result;
362   int displayNum;
363   int i;
364
365   /* Get number of displays */
366   displayNum = SDL_GetNumVideoDisplays();
367   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
368
369   /* Make call for each display */
370   for (i=0; i<displayNum; i++) {
371     result = SDL_GetNumDisplayModes(i);
372     SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
373     SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
374   }
375
376   return TEST_COMPLETED;
377 }
378
379 /**
380  * @brief Tests negative call to SDL_GetNumDisplayModes function
381  */
382 int
383 video_getNumDisplayModesNegative(void *arg)
384 {
385   int result;
386   int displayNum;
387   int displayIndex;
388
389   /* Get number of displays */
390   displayNum = SDL_GetNumVideoDisplays();
391   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
392
393   /* Invalid boundary values */
394   displayIndex =  SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
395   result = SDL_GetNumDisplayModes(displayIndex);
396   SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
397   SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
398
399   /* Large (out-of-bounds) display index */
400   displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
401   result = SDL_GetNumDisplayModes(displayIndex);
402   SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
403   SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
404
405   displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
406   result = SDL_GetNumDisplayModes(displayIndex);
407   SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
408   SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
409
410   return TEST_COMPLETED;
411 }
412
413 /**
414  * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
415  */
416 int
417 video_getClosestDisplayModeCurrentResolution(void *arg)
418 {
419   int result;
420   SDL_DisplayMode current;
421   SDL_DisplayMode target;
422   SDL_DisplayMode closest;
423   SDL_DisplayMode* dResult;
424   int displayNum;
425   int i;
426   int variation;
427
428   /* Get number of displays */
429   displayNum = SDL_GetNumVideoDisplays();
430   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
431
432   /* Make calls for each display */
433   for (i=0; i<displayNum; i++) {
434     SDLTest_Log("Testing against display: %d", i);
435
436     /* Get first display mode to get a sane resolution; this should always work */
437     result = SDL_GetDisplayMode(i, 0, &current);
438     SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
439     SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
440     if (result != 0) {
441       return TEST_ABORTED;
442     }
443
444     /* Set the desired resolution equals to current resolution */
445     target.w = current.w;
446     target.h = current.h;
447     for (variation = 0; variation < 8; variation ++) {
448       /* Vary constraints on other query parameters */
449       target.format = (variation & 1) ? current.format : 0;
450       target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
451       target.driverdata = (variation & 4) ? current.driverdata : 0;
452
453       /* Make call */
454       dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
455       SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
456       SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL");
457
458       /* Check that one gets the current resolution back again */
459       SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
460       SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
461       SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
462       SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
463     }
464   }
465
466   return TEST_COMPLETED;
467 }
468
469 /**
470  * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
471  */
472 int
473 video_getClosestDisplayModeRandomResolution(void *arg)
474 {
475   SDL_DisplayMode target;
476   SDL_DisplayMode closest;
477   SDL_DisplayMode* dResult;
478   int displayNum;
479   int i;
480   int variation;
481
482   /* Get number of displays */
483   displayNum = SDL_GetNumVideoDisplays();
484   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
485
486   /* Make calls for each display */
487   for (i=0; i<displayNum; i++) {
488     SDLTest_Log("Testing against display: %d", i);
489
490     for (variation = 0; variation < 16; variation ++) {
491
492       /* Set random constraints */
493       target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
494       target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
495       target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
496       target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
497       target.driverdata = 0;
498
499       /* Make call; may or may not find anything, so don't validate any further */
500       dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
501       SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
502     }
503   }
504
505   return TEST_COMPLETED;
506 }
507
508 /**
509  * @brief Tests call to SDL_GetWindowBrightness
510  *
511 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
512  */
513 int
514 video_getWindowBrightness(void *arg)
515 {
516   SDL_Window* window;
517   const char* title = "video_getWindowBrightness Test Window";
518   float result;
519
520   /* Call against new test window */
521   window = _createVideoSuiteTestWindow(title);
522   if (window != NULL) {
523       result = SDL_GetWindowBrightness(window);
524       SDLTest_AssertPass("Call to SDL_GetWindowBrightness()");
525       SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
526   }
527
528   /* Clean up */
529   _destroyVideoSuiteTestWindow(window);
530
531   return TEST_COMPLETED;
532 }
533
534 /**
535  * @brief Tests call to SDL_GetWindowBrightness with invalid input
536  *
537 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
538  */
539 int
540 video_getWindowBrightnessNegative(void *arg)
541 {
542   const char *invalidWindowError = "Invalid window";
543   char *lastError;
544   float result;
545
546   /* Call against invalid window */
547   result = SDL_GetWindowBrightness(NULL);
548   SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)");
549   SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result);
550   lastError = (char *)SDL_GetError();
551   SDLTest_AssertPass("SDL_GetError()");
552   SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
553   if (lastError != NULL) {
554       SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
555          "SDL_GetError(): expected message '%s', was message: '%s'",
556          invalidWindowError,
557          lastError);
558   }
559
560   return TEST_COMPLETED;
561 }
562
563 /**
564  * @brief Tests call to SDL_GetWindowDisplayMode
565  *
566  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
567  */
568 int
569 video_getWindowDisplayMode(void *arg)
570 {
571   SDL_Window* window;
572   const char* title = "video_getWindowDisplayMode Test Window";
573   SDL_DisplayMode mode;
574   int result;
575
576   /* Invalidate part of the mode content so we can check values later */
577   mode.w = -1;
578   mode.h = -1;
579   mode.refresh_rate = -1;
580
581   /* Call against new test window */
582   window = _createVideoSuiteTestWindow(title);
583   if (window != NULL) {
584       result = SDL_GetWindowDisplayMode(window, &mode);
585       SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()");
586       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
587       SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w);
588       SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h);
589       SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate);
590   }
591
592   /* Clean up */
593   _destroyVideoSuiteTestWindow(window);
594
595   return TEST_COMPLETED;
596 }
597
598 /* Helper function that checks for an 'Invalid window' error */
599 void _checkInvalidWindowError()
600 {
601   const char *invalidWindowError = "Invalid window";
602   char *lastError;
603
604   lastError = (char *)SDL_GetError();
605   SDLTest_AssertPass("SDL_GetError()");
606   SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
607   if (lastError != NULL) {
608       SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
609          "SDL_GetError(): expected message '%s', was message: '%s'",
610          invalidWindowError,
611          lastError);
612       SDL_ClearError();
613       SDLTest_AssertPass("Call to SDL_ClearError()");
614   }
615 }
616
617 /**
618  * @brief Tests call to SDL_GetWindowDisplayMode with invalid input
619  *
620  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
621  */
622 int
623 video_getWindowDisplayModeNegative(void *arg)
624 {
625   const char *expectedError = "Parameter 'mode' is invalid";
626   char *lastError;
627   SDL_Window* window;
628   const char* title = "video_getWindowDisplayModeNegative Test Window";
629   SDL_DisplayMode mode;
630   int result;
631
632   /* Call against new test window */
633   window = _createVideoSuiteTestWindow(title);
634   if (window != NULL) {
635       result = SDL_GetWindowDisplayMode(window, NULL);
636       SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)");
637       SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
638       lastError = (char *)SDL_GetError();
639       SDLTest_AssertPass("SDL_GetError()");
640       SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
641       if (lastError != NULL) {
642         SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0,
643              "SDL_GetError(): expected message '%s', was message: '%s'",
644              expectedError,
645              lastError);
646       }
647   }
648
649   /* Clean up */
650   _destroyVideoSuiteTestWindow(window);
651
652   /* Call against invalid window */
653   result = SDL_GetWindowDisplayMode(NULL, &mode);
654   SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)");
655   SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
656   _checkInvalidWindowError();
657
658   return TEST_COMPLETED;
659 }
660
661 /**
662  * @brief Tests call to SDL_GetWindowGammaRamp
663  *
664  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
665  */
666 int
667 video_getWindowGammaRamp(void *arg)
668 {
669   SDL_Window* window;
670   const char* title = "video_getWindowGammaRamp Test Window";
671   Uint16 red[256];
672   Uint16 green[256];
673   Uint16 blue[256];
674   int result;
675
676   /* Call against new test window */
677   window = _createVideoSuiteTestWindow(title);
678   if (window == NULL) return TEST_ABORTED;
679
680   /* Retrieve no channel */
681   result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL);
682   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)");
683   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
684
685   /* Retrieve single channel */
686   result = SDL_GetWindowGammaRamp(window, red, NULL, NULL);
687   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)");
688   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
689
690   result = SDL_GetWindowGammaRamp(window, NULL, green, NULL);
691   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)");
692   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
693
694   result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue);
695   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)");
696   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
697
698   /* Retrieve two channels */
699   result = SDL_GetWindowGammaRamp(window, red, green, NULL);
700   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)");
701   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
702
703   result = SDL_GetWindowGammaRamp(window, NULL, green, blue);
704   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)");
705   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
706
707   result = SDL_GetWindowGammaRamp(window, red, NULL, blue);
708   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)");
709   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
710
711   /* Retrieve all channels */
712   result = SDL_GetWindowGammaRamp(window, red, green, blue);
713   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)");
714   SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
715
716   /* Clean up */
717   _destroyVideoSuiteTestWindow(window);
718
719   return TEST_COMPLETED;
720 }
721
722 /**
723  * @brief Tests call to SDL_GetWindowGammaRamp with invalid input
724  *
725 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
726  */
727 int
728 video_getWindowGammaRampNegative(void *arg)
729 {
730   Uint16 red[256];
731   Uint16 green[256];
732   Uint16 blue[256];
733   int result;
734
735   SDL_ClearError();
736   SDLTest_AssertPass("Call to SDL_ClearError()");
737
738   /* Call against invalid window */
739   result = SDL_GetWindowGammaRamp(NULL, red, green, blue);
740   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)");
741   SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %i", result);
742   _checkInvalidWindowError();
743
744   return TEST_COMPLETED;
745 }
746
747 /* Helper for setting and checking the window grab state */
748 void
749 _setAndCheckWindowGrabState(SDL_Window* window, SDL_bool desiredState)
750 {
751   SDL_bool currentState;
752
753   /* Set state */
754   SDL_SetWindowGrab(window, desiredState);
755   SDLTest_AssertPass("Call to SDL_SetWindowGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
756
757   /* Get and check state */
758   currentState = SDL_GetWindowGrab(window);
759   SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
760   SDLTest_AssertCheck(
761       currentState == desiredState,
762       "Validate returned state; expected: %s, got: %s",
763       (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
764       (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
765 }
766
767 /**
768  * @brief Tests call to SDL_GetWindowGrab and SDL_SetWindowGrab
769  *
770  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGrab
771  * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowGrab
772  */
773 int
774 video_getSetWindowGrab(void *arg)
775 {
776   const char* title = "video_getSetWindowGrab Test Window";
777   SDL_Window* window;
778   SDL_bool originalState, dummyState, currentState, desiredState;
779
780   /* Call against new test window */
781   window = _createVideoSuiteTestWindow(title);
782   if (window == NULL) return TEST_ABORTED;
783
784   /* Get state */
785   originalState = SDL_GetWindowGrab(window);
786   SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
787
788   /* F */
789   _setAndCheckWindowGrabState(window, SDL_FALSE);
790
791   /* F --> F */
792   _setAndCheckWindowGrabState(window, SDL_FALSE);
793
794   /* F --> T */
795   _setAndCheckWindowGrabState(window, SDL_TRUE);
796
797   /* T --> T */
798   _setAndCheckWindowGrabState(window, SDL_TRUE);
799
800   /* T --> F */
801   _setAndCheckWindowGrabState(window, SDL_FALSE);
802
803   /* Negative tests */
804   dummyState = SDL_GetWindowGrab(NULL);
805   SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
806   _checkInvalidWindowError();
807
808   SDL_SetWindowGrab(NULL, SDL_FALSE);
809   SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
810   _checkInvalidWindowError();
811
812   SDL_SetWindowGrab(NULL, SDL_TRUE);
813   SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
814   _checkInvalidWindowError();
815
816   /* State should still be F */
817   desiredState = SDL_FALSE;
818   currentState = SDL_GetWindowGrab(window);
819   SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
820   SDLTest_AssertCheck(
821       currentState == desiredState,
822       "Validate returned state; expected: %s, got: %s",
823       (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
824       (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
825
826   /* Restore state */
827   _setAndCheckWindowGrabState(window, originalState);
828
829   /* Clean up */
830   _destroyVideoSuiteTestWindow(window);
831
832   return TEST_COMPLETED;
833 }
834
835
836 /**
837  * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID
838  *
839  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowID
840  * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowFromID
841  */
842 int
843 video_getWindowId(void *arg)
844 {
845   const char* title = "video_getWindowId Test Window";
846   SDL_Window* window;
847   SDL_Window* result;
848   Uint32 id, randomId;
849
850   /* Call against new test window */
851   window = _createVideoSuiteTestWindow(title);
852   if (window == NULL) return TEST_ABORTED;
853
854   /* Get ID */
855   id = SDL_GetWindowID(window);
856   SDLTest_AssertPass("Call to SDL_GetWindowID()");
857
858   /* Get window from ID */
859   result = SDL_GetWindowFromID(id);
860   SDLTest_AssertPass("Call to SDL_GetWindowID(%d)", id);
861   SDLTest_AssertCheck(result == window, "Verify result matches window pointer");
862
863   /* Get window from random large ID, no result check */
864   randomId = SDLTest_RandomIntegerInRange(UINT8_MAX,UINT16_MAX);
865   result = SDL_GetWindowFromID(randomId);
866   SDLTest_AssertPass("Call to SDL_GetWindowID(%d/random_large)", randomId);
867
868   /* Get window from 0 and Uint32 max ID, no result check */
869   result = SDL_GetWindowFromID(0);
870   SDLTest_AssertPass("Call to SDL_GetWindowID(0)");
871   result = SDL_GetWindowFromID(UINT32_MAX);
872   SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)");
873
874   /* Clean up */
875   _destroyVideoSuiteTestWindow(window);
876
877   /* Get window from ID for closed window */
878   result = SDL_GetWindowFromID(id);
879   SDLTest_AssertPass("Call to SDL_GetWindowID(%d/closed_window)", id);
880   SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
881
882   /* Negative test */
883   SDL_ClearError();
884   SDLTest_AssertPass("Call to SDL_ClearError()");
885   id = SDL_GetWindowID(NULL);
886   SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
887   _checkInvalidWindowError();
888
889   return TEST_COMPLETED;
890 }
891
892 /**
893  * @brief Tests call to SDL_GetWindowPixelFormat
894  *
895  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPixelFormat
896  */
897 int
898 video_getWindowPixelFormat(void *arg)
899 {
900 #if defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_TIZEN)
901   return TEST_UNSUPPORTED;
902 #endif
903   const char* title = "video_getWindowPixelFormat Test Window";
904   SDL_Window* window;
905   Uint32 format;
906
907   /* Call against new test window */
908   window = _createVideoSuiteTestWindow(title);
909   if (window == NULL) return TEST_ABORTED;
910
911   /* Get format */
912   format = SDL_GetWindowPixelFormat(window);
913   SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
914   SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %d", SDL_PIXELFORMAT_UNKNOWN, format);
915
916   /* Clean up */
917   _destroyVideoSuiteTestWindow(window);
918
919   /* Negative test */
920   SDL_ClearError();
921   SDLTest_AssertPass("Call to SDL_ClearError()");
922   format = SDL_GetWindowPixelFormat(NULL);
923   SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
924   _checkInvalidWindowError();
925
926   return TEST_COMPLETED;
927 }
928
929 /**
930  * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
931  *
932  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPosition
933  * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowPosition
934  */
935 int
936 video_getSetWindowPosition(void *arg)
937 {
938   const char* title = "video_getSetWindowPosition Test Window";
939   SDL_Window* window;
940   int xVariation, yVariation;
941   int referenceX, referenceY;
942   int currentX, currentY;
943   int desiredX, desiredY;
944
945   /* Call against new test window */
946   window = _createVideoSuiteTestWindow(title);
947   if (window == NULL) return TEST_ABORTED;
948
949   for (xVariation = 0; xVariation < 4; xVariation++) {
950    for (yVariation = 0; yVariation < 4; yVariation++) {
951     switch(xVariation) {
952      case 0:
953       /* Zero X Position */
954       desiredX = 0;
955       break;
956      case 1:
957       /* Random X position inside screen */
958       desiredX = SDLTest_RandomIntegerInRange(1, 100);
959       break;
960      case 2:
961       /* Random X position outside screen (positive) */
962       desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
963       break;
964      case 3:
965       /* Random X position outside screen (negative) */
966       desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
967       break;
968     }
969
970     switch(yVariation) {
971      case 0:
972       /* Zero X Position */
973       desiredY = 0;
974       break;
975      case 1:
976       /* Random X position inside screen */
977       desiredY = SDLTest_RandomIntegerInRange(1, 100);
978       break;
979      case 2:
980       /* Random X position outside screen (positive) */
981       desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
982       break;
983      case 3:
984       /* Random Y position outside screen (negative) */
985       desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
986       break;
987     }
988
989     /* Set position */
990     SDL_SetWindowPosition(window, desiredX, desiredY);
991     SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
992
993     /* Get position */
994     currentX = desiredX + 1;
995     currentY = desiredY + 1;
996     SDL_GetWindowPosition(window, &currentX, &currentY);
997     SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
998     SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
999     SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
1000
1001     /* Get position X */
1002     currentX = desiredX + 1;
1003     SDL_GetWindowPosition(window, &currentX, NULL);
1004     SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
1005     SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
1006
1007     /* Get position Y */
1008     currentY = desiredY + 1;
1009     SDL_GetWindowPosition(window, NULL, &currentY);
1010     SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
1011     SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
1012    }
1013   }
1014
1015   /* Dummy call with both pointers NULL */
1016   SDL_GetWindowPosition(window, NULL, NULL);
1017   SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
1018
1019   /* Clean up */
1020   _destroyVideoSuiteTestWindow(window);
1021
1022   /* Set some 'magic' value for later check that nothing was changed */
1023   referenceX = SDLTest_RandomSint32();
1024   referenceY = SDLTest_RandomSint32();
1025   currentX = referenceX;
1026   currentY = referenceY;
1027   desiredX = SDLTest_RandomSint32();
1028   desiredY = SDLTest_RandomSint32();
1029
1030   /* Negative tests */
1031   SDL_ClearError();
1032   SDLTest_AssertPass("Call to SDL_ClearError()");
1033   SDL_GetWindowPosition(NULL, &currentX, &currentY);
1034   SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
1035   SDLTest_AssertCheck(
1036     currentX == referenceX && currentY == referenceY,
1037     "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
1038     referenceX, referenceY,
1039     currentX, currentY);
1040   _checkInvalidWindowError();
1041
1042   SDL_GetWindowPosition(NULL, NULL, NULL);
1043   SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
1044   _checkInvalidWindowError();
1045
1046   SDL_SetWindowPosition(NULL, desiredX, desiredY);
1047   SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
1048   _checkInvalidWindowError();
1049
1050   return TEST_COMPLETED;
1051 }
1052
1053 /* Helper function that checks for an 'Invalid parameter' error */
1054 void _checkInvalidParameterError()
1055 {
1056   const char *invalidParameterError = "Parameter";
1057   char *lastError;
1058
1059   lastError = (char *)SDL_GetError();
1060   SDLTest_AssertPass("SDL_GetError()");
1061   SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
1062   if (lastError != NULL) {
1063       SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
1064          "SDL_GetError(): expected message starts with '%s', was message: '%s'",
1065          invalidParameterError,
1066          lastError);
1067       SDL_ClearError();
1068       SDLTest_AssertPass("Call to SDL_ClearError()");
1069   }
1070 }
1071
1072 /**
1073  * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize
1074  *
1075  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowSize
1076  * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowSize
1077  */
1078 int
1079 video_getSetWindowSize(void *arg)
1080 {
1081   const char* title = "video_getSetWindowSize Test Window";
1082   SDL_Window* window;
1083   int result;
1084   SDL_Rect display;
1085   int maxwVariation, maxhVariation;
1086   int wVariation, hVariation;
1087   int referenceW, referenceH;
1088   int currentW, currentH;
1089   int desiredW, desiredH;
1090
1091   /* Get display bounds for size range */
1092   result = SDL_GetDisplayBounds(0, &display);
1093   SDLTest_AssertPass("SDL_GetDisplayBounds()");
1094   SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1095   if (result != 0) return TEST_ABORTED;
1096
1097   /* Call against new test window */
1098   window = _createVideoSuiteTestWindow(title);
1099   if (window == NULL) return TEST_ABORTED;
1100
1101 #ifdef __WIN32__
1102   /* Platform clips window size to screen size */
1103   maxwVariation = 4;
1104   maxhVariation = 4;
1105 #else
1106   /* Platform allows window size >= screen size */
1107   maxwVariation = 5;
1108   maxhVariation = 5;
1109 #endif
1110   
1111   for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
1112    for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
1113     switch(wVariation) {
1114      case 0:
1115       /* 1 Pixel Wide */
1116       desiredW = 1;
1117       break;
1118      case 1:
1119       /* Random width inside screen */
1120       desiredW = SDLTest_RandomIntegerInRange(1, 100);
1121       break;
1122      case 2:
1123       /* Width 1 pixel smaller than screen */
1124       desiredW = display.w - 1;
1125       break;
1126      case 3:
1127       /* Width at screen size */
1128       desiredW = display.w;
1129       break;
1130      case 4:
1131       /* Width 1 pixel larger than screen */
1132       desiredW = display.w + 1;
1133       break;
1134     }
1135
1136     switch(hVariation) {
1137      case 0:
1138       /* 1 Pixel High */
1139       desiredH = 1;
1140       break;
1141      case 1:
1142       /* Random height inside screen */
1143       desiredH = SDLTest_RandomIntegerInRange(1, 100);
1144       break;
1145      case 2:
1146       /* Height 1 pixel smaller than screen */
1147       desiredH = display.h - 1;
1148       break;
1149      case 3:
1150       /* Height at screen size */
1151       desiredH = display.h;
1152       break;
1153      case 4:
1154       /* Height 1 pixel larger than screen */
1155       desiredH = display.h + 1;
1156       break;
1157     }
1158
1159     /* Set size */
1160     SDL_SetWindowSize(window, desiredW, desiredH);
1161     SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1162
1163     /* Get size */
1164     currentW = desiredW + 1;
1165     currentH = desiredH + 1;
1166     SDL_GetWindowSize(window, &currentW, &currentH);
1167     SDLTest_AssertPass("Call to SDL_GetWindowSize()");
1168     SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1169     SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1170
1171     /* Get just width */
1172     currentW = desiredW + 1;
1173     SDL_GetWindowSize(window, &currentW, NULL);
1174     SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
1175     SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1176
1177     /* Get just height */
1178     currentH = desiredH + 1;
1179     SDL_GetWindowSize(window, NULL, &currentH);
1180     SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
1181     SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1182    }
1183   }
1184
1185   /* Dummy call with both pointers NULL */
1186   SDL_GetWindowSize(window, NULL, NULL);
1187   SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
1188
1189   /* Negative tests for parameter input */
1190   SDL_ClearError();
1191   SDLTest_AssertPass("Call to SDL_ClearError()");
1192   for (desiredH = -2; desiredH < 2; desiredH++) {
1193     for (desiredW = -2; desiredW < 2; desiredW++) {
1194       if (desiredW <= 0 || desiredH <= 0) {
1195         SDL_SetWindowSize(window, desiredW, desiredH);
1196         SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1197         _checkInvalidParameterError();
1198       }
1199     }
1200   }
1201
1202   /* Clean up */
1203   _destroyVideoSuiteTestWindow(window);
1204
1205   /* Set some 'magic' value for later check that nothing was changed */
1206   referenceW = SDLTest_RandomSint32();
1207   referenceH = SDLTest_RandomSint32();
1208   currentW = referenceW;
1209   currentH = referenceH;
1210   desiredW = SDLTest_RandomSint32();
1211   desiredH = SDLTest_RandomSint32();
1212
1213   /* Negative tests for window input */
1214   SDL_ClearError();
1215   SDLTest_AssertPass("Call to SDL_ClearError()");
1216   SDL_GetWindowSize(NULL, &currentW, &currentH);
1217   SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
1218   SDLTest_AssertCheck(
1219     currentW == referenceW && currentH == referenceH,
1220     "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1221     referenceW, referenceH,
1222     currentW, currentH);
1223   _checkInvalidWindowError();
1224
1225   SDL_GetWindowSize(NULL, NULL, NULL);
1226   SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
1227   _checkInvalidWindowError();
1228
1229   SDL_SetWindowSize(NULL, desiredW, desiredH);
1230   SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
1231   _checkInvalidWindowError();
1232
1233   return TEST_COMPLETED;
1234 }
1235
1236 /**
1237  * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
1238  *
1239  */
1240 int
1241 video_getSetWindowMinimumSize(void *arg)
1242 {
1243   const char* title = "video_getSetWindowMinimumSize Test Window";
1244   SDL_Window* window;
1245   int result;
1246   SDL_Rect display;
1247   int wVariation, hVariation;
1248   int referenceW, referenceH;
1249   int currentW, currentH;
1250   int desiredW, desiredH;
1251
1252   /* Get display bounds for size range */
1253   result = SDL_GetDisplayBounds(0, &display);
1254   SDLTest_AssertPass("SDL_GetDisplayBounds()");
1255   SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1256   if (result != 0) return TEST_ABORTED;
1257
1258   /* Call against new test window */
1259   window = _createVideoSuiteTestWindow(title);
1260   if (window == NULL) return TEST_ABORTED;
1261
1262   for (wVariation = 0; wVariation < 5; wVariation++) {
1263    for (hVariation = 0; hVariation < 5; hVariation++) {
1264     switch(wVariation) {
1265      case 0:
1266       /* 1 Pixel Wide */
1267       desiredW = 1;
1268       break;
1269      case 1:
1270       /* Random width inside screen */
1271       desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1272       break;
1273      case 2:
1274       /* Width at screen size */
1275       desiredW = display.w;
1276       break;
1277     }
1278
1279     switch(hVariation) {
1280      case 0:
1281       /* 1 Pixel High */
1282       desiredH = 1;
1283       break;
1284      case 1:
1285       /* Random height inside screen */
1286       desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1287       break;
1288      case 2:
1289       /* Height at screen size */
1290       desiredH = display.h;
1291       break;
1292      case 4:
1293       /* Height 1 pixel larger than screen */
1294       desiredH = display.h + 1;
1295       break;
1296     }
1297
1298     /* Set size */
1299     SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1300     SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1301
1302     /* Get size */
1303     currentW = desiredW + 1;
1304     currentH = desiredH + 1;
1305     SDL_GetWindowMinimumSize(window, &currentW, &currentH);
1306     SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
1307     SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1308     SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1309
1310     /* Get just width */
1311     currentW = desiredW + 1;
1312     SDL_GetWindowMinimumSize(window, &currentW, NULL);
1313     SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
1314     SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1315
1316     /* Get just height */
1317     currentH = desiredH + 1;
1318     SDL_GetWindowMinimumSize(window, NULL, &currentH);
1319     SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
1320     SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1321    }
1322   }
1323
1324   /* Dummy call with both pointers NULL */
1325   SDL_GetWindowMinimumSize(window, NULL, NULL);
1326   SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
1327
1328   /* Negative tests for parameter input */
1329   SDL_ClearError();
1330   SDLTest_AssertPass("Call to SDL_ClearError()");
1331   for (desiredH = -2; desiredH < 2; desiredH++) {
1332     for (desiredW = -2; desiredW < 2; desiredW++) {
1333       if (desiredW <= 0 || desiredH <= 0) {
1334         SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1335         SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1336         _checkInvalidParameterError();
1337       }
1338     }
1339   }
1340
1341   /* Clean up */
1342   _destroyVideoSuiteTestWindow(window);
1343
1344   /* Set some 'magic' value for later check that nothing was changed */
1345   referenceW = SDLTest_RandomSint32();
1346   referenceH = SDLTest_RandomSint32();
1347   currentW = referenceW;
1348   currentH = referenceH;
1349   desiredW = SDLTest_RandomSint32();
1350   desiredH = SDLTest_RandomSint32();
1351
1352   /* Negative tests for window input */
1353   SDL_ClearError();
1354   SDLTest_AssertPass("Call to SDL_ClearError()");
1355   SDL_GetWindowMinimumSize(NULL, &currentW, &currentH);
1356   SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
1357   SDLTest_AssertCheck(
1358     currentW == referenceW && currentH == referenceH,
1359     "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1360     referenceW, referenceH,
1361     currentW, currentH);
1362   _checkInvalidWindowError();
1363
1364   SDL_GetWindowMinimumSize(NULL, NULL, NULL);
1365   SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
1366   _checkInvalidWindowError();
1367
1368   SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
1369   SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
1370   _checkInvalidWindowError();
1371
1372   return TEST_COMPLETED;
1373 }
1374
1375 /**
1376  * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
1377  *
1378  */
1379 int
1380 video_getSetWindowMaximumSize(void *arg)
1381 {
1382   const char* title = "video_getSetWindowMaximumSize Test Window";
1383   SDL_Window* window;
1384   int result;
1385   SDL_Rect display;
1386   int wVariation, hVariation;
1387   int referenceW, referenceH;
1388   int currentW, currentH;
1389   int desiredW, desiredH;
1390
1391   /* Get display bounds for size range */
1392   result = SDL_GetDisplayBounds(0, &display);
1393   SDLTest_AssertPass("SDL_GetDisplayBounds()");
1394   SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1395   if (result != 0) return TEST_ABORTED;
1396
1397   /* Call against new test window */
1398   window = _createVideoSuiteTestWindow(title);
1399   if (window == NULL) return TEST_ABORTED;
1400
1401   for (wVariation = 0; wVariation < 3; wVariation++) {
1402    for (hVariation = 0; hVariation < 3; hVariation++) {
1403     switch(wVariation) {
1404      case 0:
1405       /* 1 Pixel Wide */
1406       desiredW = 1;
1407       break;
1408      case 1:
1409       /* Random width inside screen */
1410       desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1411       break;
1412      case 2:
1413       /* Width at screen size */
1414       desiredW = display.w;
1415       break;
1416     }
1417
1418     switch(hVariation) {
1419      case 0:
1420       /* 1 Pixel High */
1421       desiredH = 1;
1422       break;
1423      case 1:
1424       /* Random height inside screen */
1425       desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1426       break;
1427      case 2:
1428       /* Height at screen size */
1429       desiredH = display.h;
1430       break;
1431     }
1432
1433     /* Set size */
1434     SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1435     SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1436
1437     /* Get size */
1438     currentW = desiredW + 1;
1439     currentH = desiredH + 1;
1440     SDL_GetWindowMaximumSize(window, &currentW, &currentH);
1441     SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
1442     SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1443     SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1444
1445     /* Get just width */
1446     currentW = desiredW + 1;
1447     SDL_GetWindowMaximumSize(window, &currentW, NULL);
1448     SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
1449     SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1450
1451     /* Get just height */
1452     currentH = desiredH + 1;
1453     SDL_GetWindowMaximumSize(window, NULL, &currentH);
1454     SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
1455     SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1456    }
1457   }
1458
1459   /* Dummy call with both pointers NULL */
1460   SDL_GetWindowMaximumSize(window, NULL, NULL);
1461   SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
1462
1463   /* Negative tests for parameter input */
1464   SDL_ClearError();
1465   SDLTest_AssertPass("Call to SDL_ClearError()");
1466   for (desiredH = -2; desiredH < 2; desiredH++) {
1467     for (desiredW = -2; desiredW < 2; desiredW++) {
1468       if (desiredW <= 0 || desiredH <= 0) {
1469         SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1470         SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1471         _checkInvalidParameterError();
1472       }
1473     }
1474   }
1475
1476   /* Clean up */
1477   _destroyVideoSuiteTestWindow(window);
1478
1479   /* Set some 'magic' value for later check that nothing was changed */
1480   referenceW = SDLTest_RandomSint32();
1481   referenceH = SDLTest_RandomSint32();
1482   currentW = referenceW;
1483   currentH = referenceH;
1484   desiredW = SDLTest_RandomSint32();
1485   desiredH = SDLTest_RandomSint32();
1486
1487   /* Negative tests */
1488   SDL_ClearError();
1489   SDLTest_AssertPass("Call to SDL_ClearError()");
1490   SDL_GetWindowMaximumSize(NULL, &currentW, &currentH);
1491   SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
1492   SDLTest_AssertCheck(
1493     currentW == referenceW && currentH == referenceH,
1494     "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1495     referenceW, referenceH,
1496     currentW, currentH);
1497   _checkInvalidWindowError();
1498
1499   SDL_GetWindowMaximumSize(NULL, NULL, NULL);
1500   SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
1501   _checkInvalidWindowError();
1502
1503   SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
1504   SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
1505   _checkInvalidWindowError();
1506
1507   return TEST_COMPLETED;
1508 }
1509
1510
1511 /**
1512  * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
1513  *
1514  * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowData
1515  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowData
1516  */
1517 int
1518 video_getSetWindowData(void *arg)
1519 {
1520   int returnValue = TEST_COMPLETED;
1521   const char* title = "video_setGetWindowData Test Window";
1522   SDL_Window* window;
1523   const char *referenceName = "TestName";
1524   const char *name = "TestName";
1525   const char *referenceName2 = "TestName2";
1526   const char *name2 = "TestName2";
1527   int datasize;
1528   char *referenceUserdata = NULL;
1529   char *userdata = NULL;
1530   char *referenceUserdata2 = NULL;
1531   char *userdata2 = NULL;
1532   char *result;
1533   int iteration;
1534
1535   /* Call against new test window */
1536   window = _createVideoSuiteTestWindow(title);
1537   if (window == NULL) return TEST_ABORTED;
1538
1539   /* Create testdata */
1540   datasize = SDLTest_RandomIntegerInRange(1, 32);
1541   referenceUserdata =  SDLTest_RandomAsciiStringOfSize(datasize);
1542   if (referenceUserdata == NULL) {
1543     returnValue = TEST_ABORTED;
1544     goto cleanup;
1545   }
1546   userdata = SDL_strdup(referenceUserdata);
1547   if (userdata == NULL) {
1548     returnValue = TEST_ABORTED;
1549     goto cleanup;
1550   }
1551   datasize = SDLTest_RandomIntegerInRange(1, 32);
1552   referenceUserdata2 =  SDLTest_RandomAsciiStringOfSize(datasize);
1553   if (referenceUserdata2 == NULL) {
1554     returnValue = TEST_ABORTED;
1555     goto cleanup;
1556   }
1557   userdata2 = (char *)SDL_strdup(referenceUserdata2);
1558   if (userdata2 == NULL) {
1559     returnValue = TEST_ABORTED;
1560     goto cleanup;
1561   }
1562
1563   /* Get non-existent data */
1564   result = (char *)SDL_GetWindowData(window, name);
1565   SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1566   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1567   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1568
1569   /* Set data */
1570   result = (char *)SDL_SetWindowData(window, name, userdata);
1571   SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
1572   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1573   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1574   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1575
1576   /* Get data (twice) */
1577   for (iteration = 1; iteration <= 2; iteration++) {
1578     result = (char *)SDL_GetWindowData(window, name);
1579     SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
1580     SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1581     SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1582   }
1583
1584   /* Set data again twice */
1585   for (iteration = 1; iteration <= 2; iteration++) {
1586     result = (char *)SDL_SetWindowData(window, name, userdata);
1587     SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
1588     SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1589     SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1590     SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1591   }
1592
1593   /* Get data again */
1594   result = (char *)SDL_GetWindowData(window, name);
1595   SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
1596   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1597   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1598
1599   /* Set data with new data */
1600   result = (char *)SDL_SetWindowData(window, name, userdata2);
1601   SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
1602   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1603   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1604   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1605   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1606
1607   /* Set data with new data again */
1608   result = (char *)SDL_SetWindowData(window, name, userdata2);
1609   SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
1610   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1611   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1612   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1613   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1614
1615   /* Get new data */
1616   result = (char *)SDL_GetWindowData(window, name);
1617   SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1618   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1619   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1620
1621   /* Set data with NULL to clear */
1622   result = (char *)SDL_SetWindowData(window, name, NULL);
1623   SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
1624   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1625   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1626   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1627   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1628
1629   /* Set data with NULL to clear again */
1630   result = (char *)SDL_SetWindowData(window, name, NULL);
1631   SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
1632   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1633   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1634   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1635   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1636
1637   /* Get non-existent data */
1638   result = (char *)SDL_GetWindowData(window, name);
1639   SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1640   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1641   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1642
1643   /* Get non-existent data new name */
1644   result = (char *)SDL_GetWindowData(window, name2);
1645   SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
1646   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1647   SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
1648
1649   /* Set data (again) */
1650   result = (char *)SDL_SetWindowData(window, name, userdata);
1651   SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
1652   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1653   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1654   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1655
1656   /* Get data (again) */
1657   result = (char *)SDL_GetWindowData(window, name);
1658   SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
1659   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1660   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1661
1662   /* Negative test */
1663   SDL_ClearError();
1664   SDLTest_AssertPass("Call to SDL_ClearError()");
1665
1666   /* Set with invalid window */
1667   result = (char *)SDL_SetWindowData(NULL, name, userdata);
1668   SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)");
1669   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1670   _checkInvalidWindowError();
1671
1672   /* Set data with NULL name, valid userdata */
1673   result = (char *)SDL_SetWindowData(window, NULL, userdata);
1674   SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
1675   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1676   _checkInvalidParameterError();
1677
1678   /* Set data with empty name, valid userdata */
1679   result = (char *)SDL_SetWindowData(window, "", userdata);
1680   SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
1681   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1682   _checkInvalidParameterError();
1683
1684   /* Set data with NULL name, NULL userdata */
1685   result = (char *)SDL_SetWindowData(window, NULL, NULL);
1686   SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
1687   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1688   _checkInvalidParameterError();
1689
1690   /* Set data with empty name, NULL userdata */
1691   result = (char *)SDL_SetWindowData(window, "", NULL);
1692   SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
1693   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1694   _checkInvalidParameterError();
1695
1696   /* Get with invalid window */
1697   result = (char *)SDL_GetWindowData(NULL, name);
1698   SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)");
1699   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1700   _checkInvalidWindowError();
1701
1702   /* Get data with NULL name */
1703   result = (char *)SDL_GetWindowData(window, NULL);
1704   SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
1705   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1706   _checkInvalidParameterError();
1707
1708   /* Get data with empty name */
1709   result = (char *)SDL_GetWindowData(window, "");
1710   SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
1711   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1712   _checkInvalidParameterError();
1713
1714   /* Clean up */
1715   _destroyVideoSuiteTestWindow(window);
1716
1717   cleanup:
1718   SDL_free(referenceUserdata);
1719   SDL_free(referenceUserdata2);
1720   SDL_free(userdata);
1721   SDL_free(userdata2);
1722
1723   return returnValue;
1724 }
1725
1726
1727 /* ================= Test References ================== */
1728
1729 /* Video test cases */
1730 static const SDLTest_TestCaseReference videoTest1 =
1731         { (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver",  "Enable and disable screenaver while checking state", TEST_ENABLED };
1732
1733 static const SDLTest_TestCaseReference videoTest2 =
1734         { (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions",  "Create windows at various locations", TEST_ENABLED };
1735
1736 static const SDLTest_TestCaseReference videoTest3 =
1737         { (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes",  "Create windows with various sizes", TEST_ENABLED };
1738
1739 static const SDLTest_TestCaseReference videoTest4 =
1740         { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags",  "Create windows using various flags", TEST_ENABLED };
1741
1742 static const SDLTest_TestCaseReference videoTest5 =
1743         { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags",  "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
1744
1745 static const SDLTest_TestCaseReference videoTest6 =
1746         { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes",  "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
1747
1748 static const SDLTest_TestCaseReference videoTest7 =
1749         { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative",  "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
1750
1751 static const SDLTest_TestCaseReference videoTest8 =
1752         { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution",  "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
1753
1754 static const SDLTest_TestCaseReference videoTest9 =
1755         { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution",  "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
1756
1757 static const SDLTest_TestCaseReference videoTest10 =
1758         { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness",  "Get window brightness", TEST_ENABLED };
1759
1760 static const SDLTest_TestCaseReference videoTest11 =
1761         { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative",  "Get window brightness with invalid input", TEST_ENABLED };
1762
1763 static const SDLTest_TestCaseReference videoTest12 =
1764         { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode",  "Get window display mode", TEST_ENABLED };
1765
1766 static const SDLTest_TestCaseReference videoTest13 =
1767         { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative",  "Get window display mode with invalid input", TEST_ENABLED };
1768
1769 static const SDLTest_TestCaseReference videoTest14 =
1770         { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp",  "Get window gamma ramp", TEST_ENABLED };
1771
1772 static const SDLTest_TestCaseReference videoTest15 =
1773         { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative",  "Get window gamma ramp against invalid input", TEST_ENABLED };
1774
1775 static const SDLTest_TestCaseReference videoTest16 =
1776         { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab",  "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED };
1777
1778 static const SDLTest_TestCaseReference videoTest17 =
1779         { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId",  "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED };
1780
1781 static const SDLTest_TestCaseReference videoTest18 =
1782         { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat",  "Checks SDL_GetWindowPixelFormat", TEST_ENABLED };
1783
1784 static const SDLTest_TestCaseReference videoTest19 =
1785         { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition",  "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED };
1786
1787 static const SDLTest_TestCaseReference videoTest20 =
1788         { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize",  "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED };
1789
1790 static const SDLTest_TestCaseReference videoTest21 =
1791         { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize",  "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED };
1792
1793 static const SDLTest_TestCaseReference videoTest22 =
1794         { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize",  "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED };
1795
1796 static const SDLTest_TestCaseReference videoTest23 =
1797         { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData",  "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
1798
1799 /* Sequence of Video test cases */
1800 static const SDLTest_TestCaseReference *videoTests[] =  {
1801     &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
1802     &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
1803     &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
1804     &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
1805     &videoTest23, NULL
1806 };
1807
1808 /* Video test suite (global) */
1809 SDLTest_TestSuiteReference videoTestSuite = {
1810     "Video",
1811     NULL,
1812     videoTests,
1813     NULL
1814 };