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
24 * Create a test window
26 SDL_Window *_createVideoSuiteTestWindow(const char *title)
30 SDL_WindowFlags flags;
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;
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");
49 void _destroyVideoSuiteTestWindow(SDL_Window *window)
52 SDL_DestroyWindow(window);
54 SDLTest_AssertPass("Call to SDL_DestroyWindow()");
58 /* Test case functions */
61 * @brief Enable and disable screensaver while checking state
64 video_enableDisableScreensaver(void *arg)
66 SDL_bool initialResult;
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) {
74 /* Currently enabled: disable first, then enable again */
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);
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);
92 /* Currently disabled: enable first, then disable again */
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);
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);
109 return TEST_COMPLETED;
113 * @brief Tests the functionality of the SDL_CreateWindow function using different positions
116 video_createWindowVariousPositions(void *arg)
119 const char* title = "video_createWindowVariousPositions Test Window";
121 int xVariation, yVariation;
123 for (xVariation = 0; xVariation < 6; xVariation++) {
124 for (yVariation = 0; yVariation < 6; yVariation++) {
127 /* Zero X Position */
131 /* Random X position inside screen */
132 x = SDLTest_RandomIntegerInRange(1, 100);
135 /* Random X position outside screen (positive) */
136 x = SDLTest_RandomIntegerInRange(10000, 11000);
139 /* Random X position outside screen (negative) */
140 x = SDLTest_RandomIntegerInRange(-1000, -100);
143 /* Centered X position */
144 x = SDL_WINDOWPOS_CENTERED;
147 /* Undefined X position */
148 x = SDL_WINDOWPOS_UNDEFINED;
154 /* Zero X Position */
158 /* Random X position inside screen */
159 y = SDLTest_RandomIntegerInRange(1, 100);
162 /* Random X position outside screen (positive) */
163 y = SDLTest_RandomIntegerInRange(10000, 11000);
166 /* Random Y position outside screen (negative) */
167 y = SDLTest_RandomIntegerInRange(-1000, -100);
170 /* Centered Y position */
171 y = SDL_WINDOWPOS_CENTERED;
174 /* Undefined Y position */
175 y = SDL_WINDOWPOS_UNDEFINED;
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");
186 _destroyVideoSuiteTestWindow(window);
190 return TEST_COMPLETED;
194 * @brief Tests the functionality of the SDL_CreateWindow function using different sizes
197 video_createWindowVariousSizes(void *arg)
200 const char* title = "video_createWindowVariousSizes Test Window";
202 int wVariation, hVariation;
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++) {
214 /* Random "normal" width */
215 w = SDLTest_RandomIntegerInRange(320, 1920);
218 /* Random "large" width */
219 w = SDLTest_RandomIntegerInRange(2048, 4095);
229 /* Random "normal" height */
230 h = SDLTest_RandomIntegerInRange(320, 1080);
233 /* Random "large" height */
234 h = SDLTest_RandomIntegerInRange(2048, 4095);
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");
243 _destroyVideoSuiteTestWindow(window);
247 return TEST_COMPLETED;
251 * @brief Tests the functionality of the SDL_CreateWindow function using different flags
254 video_createWindowVariousFlags(void *arg)
257 const char* title = "video_createWindowVariousFlags Test Window";
260 SDL_WindowFlags flags;
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);
268 for (fVariation = 0; fVariation < 13; fVariation++) {
271 flags = SDL_WINDOW_FULLSCREEN;
272 /* Skip - blanks screen; comment out next line to run test */
276 flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
277 /* Skip - blanks screen; comment out next line to run test */
281 flags = SDL_WINDOW_OPENGL;
284 flags = SDL_WINDOW_SHOWN;
287 flags = SDL_WINDOW_HIDDEN;
290 flags = SDL_WINDOW_BORDERLESS;
293 flags = SDL_WINDOW_RESIZABLE;
296 flags = SDL_WINDOW_MINIMIZED;
299 flags = SDL_WINDOW_MAXIMIZED;
302 flags = SDL_WINDOW_INPUT_GRABBED;
305 flags = SDL_WINDOW_INPUT_FOCUS;
308 flags = SDL_WINDOW_MOUSE_FOCUS;
311 flags = SDL_WINDOW_FOREIGN;
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");
320 _destroyVideoSuiteTestWindow(window);
323 return TEST_COMPLETED;
328 * @brief Tests the functionality of the SDL_GetWindowFlags function
331 video_getWindowFlags(void *arg)
334 const char* title = "video_getWindowFlags Test Window";
335 SDL_WindowFlags flags;
338 /* Reliable flag set always set in test window */
339 flags = SDL_WINDOW_SHOWN;
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);
350 _destroyVideoSuiteTestWindow(window);
352 return TEST_COMPLETED;
356 * @brief Tests the functionality of the SDL_GetNumDisplayModes function
359 video_getNumDisplayModes(void *arg)
365 /* Get number of displays */
366 displayNum = SDL_GetNumVideoDisplays();
367 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
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);
376 return TEST_COMPLETED;
380 * @brief Tests negative call to SDL_GetNumDisplayModes function
383 video_getNumDisplayModesNegative(void *arg)
389 /* Get number of displays */
390 displayNum = SDL_GetNumVideoDisplays();
391 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
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);
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);
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);
410 return TEST_COMPLETED;
414 * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
417 video_getClosestDisplayModeCurrentResolution(void *arg)
420 SDL_DisplayMode current;
421 SDL_DisplayMode target;
422 SDL_DisplayMode closest;
423 SDL_DisplayMode* dResult;
428 /* Get number of displays */
429 displayNum = SDL_GetNumVideoDisplays();
430 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
432 /* Make calls for each display */
433 for (i=0; i<displayNum; i++) {
434 SDLTest_Log("Testing against display: %d", i);
436 /* Get first display mode to get a sane resolution; this should always work */
437 result = SDL_GetDisplayMode(i, 0, ¤t);
438 SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
439 SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
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;
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");
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);
466 return TEST_COMPLETED;
470 * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
473 video_getClosestDisplayModeRandomResolution(void *arg)
475 SDL_DisplayMode target;
476 SDL_DisplayMode closest;
477 SDL_DisplayMode* dResult;
482 /* Get number of displays */
483 displayNum = SDL_GetNumVideoDisplays();
484 SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
486 /* Make calls for each display */
487 for (i=0; i<displayNum; i++) {
488 SDLTest_Log("Testing against display: %d", i);
490 for (variation = 0; variation < 16; variation ++) {
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;
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);
505 return TEST_COMPLETED;
509 * @brief Tests call to SDL_GetWindowBrightness
511 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
514 video_getWindowBrightness(void *arg)
517 const char* title = "video_getWindowBrightness Test Window";
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);
529 _destroyVideoSuiteTestWindow(window);
531 return TEST_COMPLETED;
535 * @brief Tests call to SDL_GetWindowBrightness with invalid input
537 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
540 video_getWindowBrightnessNegative(void *arg)
542 const char *invalidWindowError = "Invalid window";
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'",
560 return TEST_COMPLETED;
564 * @brief Tests call to SDL_GetWindowDisplayMode
566 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
569 video_getWindowDisplayMode(void *arg)
572 const char* title = "video_getWindowDisplayMode Test Window";
573 SDL_DisplayMode mode;
576 /* Invalidate part of the mode content so we can check values later */
579 mode.refresh_rate = -1;
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);
593 _destroyVideoSuiteTestWindow(window);
595 return TEST_COMPLETED;
598 /* Helper function that checks for an 'Invalid window' error */
599 void _checkInvalidWindowError()
601 const char *invalidWindowError = "Invalid window";
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'",
613 SDLTest_AssertPass("Call to SDL_ClearError()");
618 * @brief Tests call to SDL_GetWindowDisplayMode with invalid input
620 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
623 video_getWindowDisplayModeNegative(void *arg)
625 const char *expectedError = "Parameter 'mode' is invalid";
628 const char* title = "video_getWindowDisplayModeNegative Test Window";
629 SDL_DisplayMode mode;
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'",
650 _destroyVideoSuiteTestWindow(window);
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();
658 return TEST_COMPLETED;
662 * @brief Tests call to SDL_GetWindowGammaRamp
664 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
667 video_getWindowGammaRamp(void *arg)
670 const char* title = "video_getWindowGammaRamp Test Window";
676 /* Call against new test window */
677 window = _createVideoSuiteTestWindow(title);
678 if (window == NULL) return TEST_ABORTED;
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);
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);
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);
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);
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);
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);
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);
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);
717 _destroyVideoSuiteTestWindow(window);
719 return TEST_COMPLETED;
723 * @brief Tests call to SDL_GetWindowGammaRamp with invalid input
725 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
728 video_getWindowGammaRampNegative(void *arg)
736 SDLTest_AssertPass("Call to SDL_ClearError()");
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();
744 return TEST_COMPLETED;
747 /* Helper for setting and checking the window grab state */
749 _setAndCheckWindowGrabState(SDL_Window* window, SDL_bool desiredState)
751 SDL_bool currentState;
754 SDL_SetWindowGrab(window, desiredState);
755 SDLTest_AssertPass("Call to SDL_SetWindowGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
757 /* Get and check state */
758 currentState = SDL_GetWindowGrab(window);
759 SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
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");
768 * @brief Tests call to SDL_GetWindowGrab and SDL_SetWindowGrab
770 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGrab
771 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowGrab
774 video_getSetWindowGrab(void *arg)
776 const char* title = "video_getSetWindowGrab Test Window";
778 SDL_bool originalState, dummyState, currentState, desiredState;
780 /* Call against new test window */
781 window = _createVideoSuiteTestWindow(title);
782 if (window == NULL) return TEST_ABORTED;
785 originalState = SDL_GetWindowGrab(window);
786 SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
789 _setAndCheckWindowGrabState(window, SDL_FALSE);
792 _setAndCheckWindowGrabState(window, SDL_FALSE);
795 _setAndCheckWindowGrabState(window, SDL_TRUE);
798 _setAndCheckWindowGrabState(window, SDL_TRUE);
801 _setAndCheckWindowGrabState(window, SDL_FALSE);
804 dummyState = SDL_GetWindowGrab(NULL);
805 SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
806 _checkInvalidWindowError();
808 SDL_SetWindowGrab(NULL, SDL_FALSE);
809 SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
810 _checkInvalidWindowError();
812 SDL_SetWindowGrab(NULL, SDL_TRUE);
813 SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
814 _checkInvalidWindowError();
816 /* State should still be F */
817 desiredState = SDL_FALSE;
818 currentState = SDL_GetWindowGrab(window);
819 SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
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");
827 _setAndCheckWindowGrabState(window, originalState);
830 _destroyVideoSuiteTestWindow(window);
832 return TEST_COMPLETED;
837 * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID
839 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowID
840 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowFromID
843 video_getWindowId(void *arg)
845 const char* title = "video_getWindowId Test Window";
850 /* Call against new test window */
851 window = _createVideoSuiteTestWindow(title);
852 if (window == NULL) return TEST_ABORTED;
855 id = SDL_GetWindowID(window);
856 SDLTest_AssertPass("Call to SDL_GetWindowID()");
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");
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);
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)");
875 _destroyVideoSuiteTestWindow(window);
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");
884 SDLTest_AssertPass("Call to SDL_ClearError()");
885 id = SDL_GetWindowID(NULL);
886 SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
887 _checkInvalidWindowError();
889 return TEST_COMPLETED;
893 * @brief Tests call to SDL_GetWindowPixelFormat
895 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPixelFormat
898 video_getWindowPixelFormat(void *arg)
900 const char* title = "video_getWindowPixelFormat Test Window";
904 /* Call against new test window */
905 window = _createVideoSuiteTestWindow(title);
906 if (window == NULL) return TEST_ABORTED;
909 format = SDL_GetWindowPixelFormat(window);
910 SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
911 SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %d", SDL_PIXELFORMAT_UNKNOWN, format);
914 _destroyVideoSuiteTestWindow(window);
918 SDLTest_AssertPass("Call to SDL_ClearError()");
919 format = SDL_GetWindowPixelFormat(NULL);
920 SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
921 _checkInvalidWindowError();
923 return TEST_COMPLETED;
927 * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
929 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPosition
930 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowPosition
933 video_getSetWindowPosition(void *arg)
935 const char* title = "video_getSetWindowPosition Test Window";
937 int xVariation, yVariation;
938 int referenceX, referenceY;
939 int currentX, currentY;
940 int desiredX, desiredY;
942 /* Call against new test window */
943 window = _createVideoSuiteTestWindow(title);
944 if (window == NULL) return TEST_ABORTED;
946 for (xVariation = 0; xVariation < 4; xVariation++) {
947 for (yVariation = 0; yVariation < 4; yVariation++) {
950 /* Zero X Position */
954 /* Random X position inside screen */
955 desiredX = SDLTest_RandomIntegerInRange(1, 100);
958 /* Random X position outside screen (positive) */
959 desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
962 /* Random X position outside screen (negative) */
963 desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
969 /* Zero X Position */
973 /* Random X position inside screen */
974 desiredY = SDLTest_RandomIntegerInRange(1, 100);
977 /* Random X position outside screen (positive) */
978 desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
981 /* Random Y position outside screen (negative) */
982 desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
987 SDL_SetWindowPosition(window, desiredX, desiredY);
988 SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
991 currentX = desiredX + 1;
992 currentY = desiredY + 1;
993 SDL_GetWindowPosition(window, ¤tX, ¤tY);
994 SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
995 SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
996 SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
999 currentX = desiredX + 1;
1000 SDL_GetWindowPosition(window, ¤tX, NULL);
1001 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
1002 SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
1004 /* Get position Y */
1005 currentY = desiredY + 1;
1006 SDL_GetWindowPosition(window, NULL, ¤tY);
1007 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
1008 SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
1012 /* Dummy call with both pointers NULL */
1013 SDL_GetWindowPosition(window, NULL, NULL);
1014 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
1017 _destroyVideoSuiteTestWindow(window);
1019 /* Set some 'magic' value for later check that nothing was changed */
1020 referenceX = SDLTest_RandomSint32();
1021 referenceY = SDLTest_RandomSint32();
1022 currentX = referenceX;
1023 currentY = referenceY;
1024 desiredX = SDLTest_RandomSint32();
1025 desiredY = SDLTest_RandomSint32();
1027 /* Negative tests */
1029 SDLTest_AssertPass("Call to SDL_ClearError()");
1030 SDL_GetWindowPosition(NULL, ¤tX, ¤tY);
1031 SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
1032 SDLTest_AssertCheck(
1033 currentX == referenceX && currentY == referenceY,
1034 "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
1035 referenceX, referenceY,
1036 currentX, currentY);
1037 _checkInvalidWindowError();
1039 SDL_GetWindowPosition(NULL, NULL, NULL);
1040 SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
1041 _checkInvalidWindowError();
1043 SDL_SetWindowPosition(NULL, desiredX, desiredY);
1044 SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
1045 _checkInvalidWindowError();
1047 return TEST_COMPLETED;
1050 /* Helper function that checks for an 'Invalid parameter' error */
1051 void _checkInvalidParameterError()
1053 const char *invalidParameterError = "Parameter";
1056 lastError = (char *)SDL_GetError();
1057 SDLTest_AssertPass("SDL_GetError()");
1058 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
1059 if (lastError != NULL) {
1060 SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
1061 "SDL_GetError(): expected message starts with '%s', was message: '%s'",
1062 invalidParameterError,
1065 SDLTest_AssertPass("Call to SDL_ClearError()");
1070 * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize
1072 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowSize
1073 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowSize
1076 video_getSetWindowSize(void *arg)
1078 const char* title = "video_getSetWindowSize Test Window";
1082 int maxwVariation, maxhVariation;
1083 int wVariation, hVariation;
1084 int referenceW, referenceH;
1085 int currentW, currentH;
1086 int desiredW, desiredH;
1088 /* Get display bounds for size range */
1089 result = SDL_GetDisplayBounds(0, &display);
1090 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1091 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1092 if (result != 0) return TEST_ABORTED;
1094 /* Call against new test window */
1095 window = _createVideoSuiteTestWindow(title);
1096 if (window == NULL) return TEST_ABORTED;
1099 /* Platform clips window size to screen size */
1103 /* Platform allows window size >= screen size */
1108 for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
1109 for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
1110 switch(wVariation) {
1116 /* Random width inside screen */
1117 desiredW = SDLTest_RandomIntegerInRange(1, 100);
1120 /* Width 1 pixel smaller than screen */
1121 desiredW = display.w - 1;
1124 /* Width at screen size */
1125 desiredW = display.w;
1128 /* Width 1 pixel larger than screen */
1129 desiredW = display.w + 1;
1133 switch(hVariation) {
1139 /* Random height inside screen */
1140 desiredH = SDLTest_RandomIntegerInRange(1, 100);
1143 /* Height 1 pixel smaller than screen */
1144 desiredH = display.h - 1;
1147 /* Height at screen size */
1148 desiredH = display.h;
1151 /* Height 1 pixel larger than screen */
1152 desiredH = display.h + 1;
1157 SDL_SetWindowSize(window, desiredW, desiredH);
1158 SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1161 currentW = desiredW + 1;
1162 currentH = desiredH + 1;
1163 SDL_GetWindowSize(window, ¤tW, ¤tH);
1164 SDLTest_AssertPass("Call to SDL_GetWindowSize()");
1165 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1166 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1168 /* Get just width */
1169 currentW = desiredW + 1;
1170 SDL_GetWindowSize(window, ¤tW, NULL);
1171 SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
1172 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1174 /* Get just height */
1175 currentH = desiredH + 1;
1176 SDL_GetWindowSize(window, NULL, ¤tH);
1177 SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
1178 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1182 /* Dummy call with both pointers NULL */
1183 SDL_GetWindowSize(window, NULL, NULL);
1184 SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
1186 /* Negative tests for parameter input */
1188 SDLTest_AssertPass("Call to SDL_ClearError()");
1189 for (desiredH = -2; desiredH < 2; desiredH++) {
1190 for (desiredW = -2; desiredW < 2; desiredW++) {
1191 if (desiredW <= 0 || desiredH <= 0) {
1192 SDL_SetWindowSize(window, desiredW, desiredH);
1193 SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1194 _checkInvalidParameterError();
1200 _destroyVideoSuiteTestWindow(window);
1202 /* Set some 'magic' value for later check that nothing was changed */
1203 referenceW = SDLTest_RandomSint32();
1204 referenceH = SDLTest_RandomSint32();
1205 currentW = referenceW;
1206 currentH = referenceH;
1207 desiredW = SDLTest_RandomSint32();
1208 desiredH = SDLTest_RandomSint32();
1210 /* Negative tests for window input */
1212 SDLTest_AssertPass("Call to SDL_ClearError()");
1213 SDL_GetWindowSize(NULL, ¤tW, ¤tH);
1214 SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
1215 SDLTest_AssertCheck(
1216 currentW == referenceW && currentH == referenceH,
1217 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1218 referenceW, referenceH,
1219 currentW, currentH);
1220 _checkInvalidWindowError();
1222 SDL_GetWindowSize(NULL, NULL, NULL);
1223 SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
1224 _checkInvalidWindowError();
1226 SDL_SetWindowSize(NULL, desiredW, desiredH);
1227 SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
1228 _checkInvalidWindowError();
1230 return TEST_COMPLETED;
1234 * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
1238 video_getSetWindowMinimumSize(void *arg)
1240 const char* title = "video_getSetWindowMinimumSize Test Window";
1244 int wVariation, hVariation;
1245 int referenceW, referenceH;
1246 int currentW, currentH;
1247 int desiredW, desiredH;
1249 /* Get display bounds for size range */
1250 result = SDL_GetDisplayBounds(0, &display);
1251 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1252 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1253 if (result != 0) return TEST_ABORTED;
1255 /* Call against new test window */
1256 window = _createVideoSuiteTestWindow(title);
1257 if (window == NULL) return TEST_ABORTED;
1259 for (wVariation = 0; wVariation < 5; wVariation++) {
1260 for (hVariation = 0; hVariation < 5; hVariation++) {
1261 switch(wVariation) {
1267 /* Random width inside screen */
1268 desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1271 /* Width at screen size */
1272 desiredW = display.w;
1276 switch(hVariation) {
1282 /* Random height inside screen */
1283 desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1286 /* Height at screen size */
1287 desiredH = display.h;
1290 /* Height 1 pixel larger than screen */
1291 desiredH = display.h + 1;
1296 SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1297 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1300 currentW = desiredW + 1;
1301 currentH = desiredH + 1;
1302 SDL_GetWindowMinimumSize(window, ¤tW, ¤tH);
1303 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
1304 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1305 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1307 /* Get just width */
1308 currentW = desiredW + 1;
1309 SDL_GetWindowMinimumSize(window, ¤tW, NULL);
1310 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
1311 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1313 /* Get just height */
1314 currentH = desiredH + 1;
1315 SDL_GetWindowMinimumSize(window, NULL, ¤tH);
1316 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
1317 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1321 /* Dummy call with both pointers NULL */
1322 SDL_GetWindowMinimumSize(window, NULL, NULL);
1323 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
1325 /* Negative tests for parameter input */
1327 SDLTest_AssertPass("Call to SDL_ClearError()");
1328 for (desiredH = -2; desiredH < 2; desiredH++) {
1329 for (desiredW = -2; desiredW < 2; desiredW++) {
1330 if (desiredW <= 0 || desiredH <= 0) {
1331 SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1332 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1333 _checkInvalidParameterError();
1339 _destroyVideoSuiteTestWindow(window);
1341 /* Set some 'magic' value for later check that nothing was changed */
1342 referenceW = SDLTest_RandomSint32();
1343 referenceH = SDLTest_RandomSint32();
1344 currentW = referenceW;
1345 currentH = referenceH;
1346 desiredW = SDLTest_RandomSint32();
1347 desiredH = SDLTest_RandomSint32();
1349 /* Negative tests for window input */
1351 SDLTest_AssertPass("Call to SDL_ClearError()");
1352 SDL_GetWindowMinimumSize(NULL, ¤tW, ¤tH);
1353 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
1354 SDLTest_AssertCheck(
1355 currentW == referenceW && currentH == referenceH,
1356 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1357 referenceW, referenceH,
1358 currentW, currentH);
1359 _checkInvalidWindowError();
1361 SDL_GetWindowMinimumSize(NULL, NULL, NULL);
1362 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
1363 _checkInvalidWindowError();
1365 SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
1366 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
1367 _checkInvalidWindowError();
1369 return TEST_COMPLETED;
1373 * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
1377 video_getSetWindowMaximumSize(void *arg)
1379 const char* title = "video_getSetWindowMaximumSize Test Window";
1383 int wVariation, hVariation;
1384 int referenceW, referenceH;
1385 int currentW, currentH;
1386 int desiredW, desiredH;
1388 /* Get display bounds for size range */
1389 result = SDL_GetDisplayBounds(0, &display);
1390 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1391 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1392 if (result != 0) return TEST_ABORTED;
1394 /* Call against new test window */
1395 window = _createVideoSuiteTestWindow(title);
1396 if (window == NULL) return TEST_ABORTED;
1398 for (wVariation = 0; wVariation < 3; wVariation++) {
1399 for (hVariation = 0; hVariation < 3; hVariation++) {
1400 switch(wVariation) {
1406 /* Random width inside screen */
1407 desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1410 /* Width at screen size */
1411 desiredW = display.w;
1415 switch(hVariation) {
1421 /* Random height inside screen */
1422 desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1425 /* Height at screen size */
1426 desiredH = display.h;
1431 SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1432 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1435 currentW = desiredW + 1;
1436 currentH = desiredH + 1;
1437 SDL_GetWindowMaximumSize(window, ¤tW, ¤tH);
1438 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
1439 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1440 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1442 /* Get just width */
1443 currentW = desiredW + 1;
1444 SDL_GetWindowMaximumSize(window, ¤tW, NULL);
1445 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
1446 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1448 /* Get just height */
1449 currentH = desiredH + 1;
1450 SDL_GetWindowMaximumSize(window, NULL, ¤tH);
1451 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
1452 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1456 /* Dummy call with both pointers NULL */
1457 SDL_GetWindowMaximumSize(window, NULL, NULL);
1458 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
1460 /* Negative tests for parameter input */
1462 SDLTest_AssertPass("Call to SDL_ClearError()");
1463 for (desiredH = -2; desiredH < 2; desiredH++) {
1464 for (desiredW = -2; desiredW < 2; desiredW++) {
1465 if (desiredW <= 0 || desiredH <= 0) {
1466 SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1467 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1468 _checkInvalidParameterError();
1474 _destroyVideoSuiteTestWindow(window);
1476 /* Set some 'magic' value for later check that nothing was changed */
1477 referenceW = SDLTest_RandomSint32();
1478 referenceH = SDLTest_RandomSint32();
1479 currentW = referenceW;
1480 currentH = referenceH;
1481 desiredW = SDLTest_RandomSint32();
1482 desiredH = SDLTest_RandomSint32();
1484 /* Negative tests */
1486 SDLTest_AssertPass("Call to SDL_ClearError()");
1487 SDL_GetWindowMaximumSize(NULL, ¤tW, ¤tH);
1488 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
1489 SDLTest_AssertCheck(
1490 currentW == referenceW && currentH == referenceH,
1491 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1492 referenceW, referenceH,
1493 currentW, currentH);
1494 _checkInvalidWindowError();
1496 SDL_GetWindowMaximumSize(NULL, NULL, NULL);
1497 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
1498 _checkInvalidWindowError();
1500 SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
1501 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
1502 _checkInvalidWindowError();
1504 return TEST_COMPLETED;
1509 * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
1511 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowData
1512 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowData
1515 video_getSetWindowData(void *arg)
1517 int returnValue = TEST_COMPLETED;
1518 const char* title = "video_setGetWindowData Test Window";
1520 const char *referenceName = "TestName";
1521 const char *name = "TestName";
1522 const char *referenceName2 = "TestName2";
1523 const char *name2 = "TestName2";
1525 char *referenceUserdata = NULL;
1526 char *userdata = NULL;
1527 char *referenceUserdata2 = NULL;
1528 char *userdata2 = NULL;
1532 /* Call against new test window */
1533 window = _createVideoSuiteTestWindow(title);
1534 if (window == NULL) return TEST_ABORTED;
1536 /* Create testdata */
1537 datasize = SDLTest_RandomIntegerInRange(1, 32);
1538 referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
1539 if (referenceUserdata == NULL) {
1540 returnValue = TEST_ABORTED;
1543 userdata = SDL_strdup(referenceUserdata);
1544 if (userdata == NULL) {
1545 returnValue = TEST_ABORTED;
1548 datasize = SDLTest_RandomIntegerInRange(1, 32);
1549 referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
1550 if (referenceUserdata2 == NULL) {
1551 returnValue = TEST_ABORTED;
1554 userdata2 = (char *)SDL_strdup(referenceUserdata2);
1555 if (userdata2 == NULL) {
1556 returnValue = TEST_ABORTED;
1560 /* Get non-existent data */
1561 result = (char *)SDL_GetWindowData(window, name);
1562 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1563 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1564 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1567 result = (char *)SDL_SetWindowData(window, name, userdata);
1568 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
1569 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1570 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1571 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1573 /* Get data (twice) */
1574 for (iteration = 1; iteration <= 2; iteration++) {
1575 result = (char *)SDL_GetWindowData(window, name);
1576 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
1577 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1578 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1581 /* Set data again twice */
1582 for (iteration = 1; iteration <= 2; iteration++) {
1583 result = (char *)SDL_SetWindowData(window, name, userdata);
1584 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
1585 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1586 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1587 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1590 /* Get data again */
1591 result = (char *)SDL_GetWindowData(window, name);
1592 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
1593 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1594 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1596 /* Set data with new data */
1597 result = (char *)SDL_SetWindowData(window, name, userdata2);
1598 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
1599 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1600 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1601 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1602 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1604 /* Set data with new data again */
1605 result = (char *)SDL_SetWindowData(window, name, userdata2);
1606 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
1607 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1608 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1609 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1610 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1613 result = (char *)SDL_GetWindowData(window, name);
1614 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1615 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1616 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1618 /* Set data with NULL to clear */
1619 result = (char *)SDL_SetWindowData(window, name, NULL);
1620 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
1621 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1622 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1623 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1624 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1626 /* Set data with NULL to clear again */
1627 result = (char *)SDL_SetWindowData(window, name, NULL);
1628 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
1629 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1630 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1631 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1632 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1634 /* Get non-existent data */
1635 result = (char *)SDL_GetWindowData(window, name);
1636 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1637 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1638 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1640 /* Get non-existent data new name */
1641 result = (char *)SDL_GetWindowData(window, name2);
1642 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
1643 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1644 SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
1646 /* Set data (again) */
1647 result = (char *)SDL_SetWindowData(window, name, userdata);
1648 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
1649 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1650 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1651 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1653 /* Get data (again) */
1654 result = (char *)SDL_GetWindowData(window, name);
1655 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
1656 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1657 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1661 SDLTest_AssertPass("Call to SDL_ClearError()");
1663 /* Set with invalid window */
1664 result = (char *)SDL_SetWindowData(NULL, name, userdata);
1665 SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)");
1666 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1667 _checkInvalidWindowError();
1669 /* Set data with NULL name, valid userdata */
1670 result = (char *)SDL_SetWindowData(window, NULL, userdata);
1671 SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
1672 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1673 _checkInvalidParameterError();
1675 /* Set data with empty name, valid userdata */
1676 result = (char *)SDL_SetWindowData(window, "", userdata);
1677 SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
1678 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1679 _checkInvalidParameterError();
1681 /* Set data with NULL name, NULL userdata */
1682 result = (char *)SDL_SetWindowData(window, NULL, NULL);
1683 SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
1684 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1685 _checkInvalidParameterError();
1687 /* Set data with empty name, NULL userdata */
1688 result = (char *)SDL_SetWindowData(window, "", NULL);
1689 SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
1690 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1691 _checkInvalidParameterError();
1693 /* Get with invalid window */
1694 result = (char *)SDL_GetWindowData(NULL, name);
1695 SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)");
1696 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1697 _checkInvalidWindowError();
1699 /* Get data with NULL name */
1700 result = (char *)SDL_GetWindowData(window, NULL);
1701 SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
1702 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1703 _checkInvalidParameterError();
1705 /* Get data with empty name */
1706 result = (char *)SDL_GetWindowData(window, "");
1707 SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
1708 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1709 _checkInvalidParameterError();
1712 _destroyVideoSuiteTestWindow(window);
1715 SDL_free(referenceUserdata);
1716 SDL_free(referenceUserdata2);
1718 SDL_free(userdata2);
1724 /* ================= Test References ================== */
1726 /* Video test cases */
1727 static const SDLTest_TestCaseReference videoTest1 =
1728 { (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED };
1730 static const SDLTest_TestCaseReference videoTest2 =
1731 { (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions", "Create windows at various locations", TEST_ENABLED };
1733 static const SDLTest_TestCaseReference videoTest3 =
1734 { (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED };
1736 static const SDLTest_TestCaseReference videoTest4 =
1737 { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED };
1739 static const SDLTest_TestCaseReference videoTest5 =
1740 { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
1742 static const SDLTest_TestCaseReference videoTest6 =
1743 { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
1745 static const SDLTest_TestCaseReference videoTest7 =
1746 { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
1748 static const SDLTest_TestCaseReference videoTest8 =
1749 { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
1751 static const SDLTest_TestCaseReference videoTest9 =
1752 { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
1754 static const SDLTest_TestCaseReference videoTest10 =
1755 { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED };
1757 static const SDLTest_TestCaseReference videoTest11 =
1758 { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED };
1760 static const SDLTest_TestCaseReference videoTest12 =
1761 { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED };
1763 static const SDLTest_TestCaseReference videoTest13 =
1764 { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED };
1766 static const SDLTest_TestCaseReference videoTest14 =
1767 { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED };
1769 static const SDLTest_TestCaseReference videoTest15 =
1770 { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED };
1772 static const SDLTest_TestCaseReference videoTest16 =
1773 { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED };
1775 static const SDLTest_TestCaseReference videoTest17 =
1776 { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED };
1778 static const SDLTest_TestCaseReference videoTest18 =
1779 { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED };
1781 static const SDLTest_TestCaseReference videoTest19 =
1782 { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED };
1784 static const SDLTest_TestCaseReference videoTest20 =
1785 { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED };
1787 static const SDLTest_TestCaseReference videoTest21 =
1788 { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED };
1790 static const SDLTest_TestCaseReference videoTest22 =
1791 { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED };
1793 static const SDLTest_TestCaseReference videoTest23 =
1794 { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
1796 /* Sequence of Video test cases */
1797 static const SDLTest_TestCaseReference *videoTests[] = {
1798 &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
1799 &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
1800 &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
1801 &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
1805 /* Video test suite (global) */
1806 SDLTest_TestSuiteReference videoTestSuite = {