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";
544 const char* title = "video_getWindowBrightnessNegative Test Window";
547 /* Call against invalid window */
548 result = SDL_GetWindowBrightness(NULL);
549 SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)");
550 SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result);
551 lastError = (char *)SDL_GetError();
552 SDLTest_AssertPass("SDL_GetError()");
553 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
554 if (lastError != NULL) {
555 SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
556 "SDL_GetError(): expected message '%s', was message: '%s'",
561 return TEST_COMPLETED;
565 * @brief Tests call to SDL_GetWindowDisplayMode
567 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
570 video_getWindowDisplayMode(void *arg)
573 const char* title = "video_getWindowDisplayMode Test Window";
574 SDL_DisplayMode mode;
577 /* Invalidate part of the mode content so we can check values later */
580 mode.refresh_rate = -1;
582 /* Call against new test window */
583 window = _createVideoSuiteTestWindow(title);
584 if (window != NULL) {
585 result = SDL_GetWindowDisplayMode(window, &mode);
586 SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode");
587 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
588 SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w);
589 SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h);
590 SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate);
594 _destroyVideoSuiteTestWindow(window);
596 return TEST_COMPLETED;
599 /* Helper function that checks for an 'Invalid window' error */
600 void _checkInvalidWindowError()
602 const char *invalidWindowError = "Invalid window";
605 lastError = (char *)SDL_GetError();
606 SDLTest_AssertPass("SDL_GetError()");
607 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
608 if (lastError != NULL) {
609 SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
610 "SDL_GetError(): expected message '%s', was message: '%s'",
614 SDLTest_AssertPass("Call to SDL_ClearError()");
619 * @brief Tests call to SDL_GetWindowDisplayMode with invalid input
621 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
624 video_getWindowDisplayModeNegative(void *arg)
626 const char *expectedError = "Parameter 'mode' is invalid";
629 const char* title = "video_getWindowDisplayModeNegative Test Window";
630 SDL_DisplayMode mode;
633 /* Call against new test window */
634 window = _createVideoSuiteTestWindow(title);
635 if (window != NULL) {
636 result = SDL_GetWindowDisplayMode(window, NULL);
637 SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)");
638 SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
639 lastError = (char *)SDL_GetError();
640 SDLTest_AssertPass("SDL_GetError()");
641 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
642 if (lastError != NULL) {
643 SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0,
644 "SDL_GetError(): expected message '%s', was message: '%s'",
651 _destroyVideoSuiteTestWindow(window);
653 /* Call against invalid window */
654 result = SDL_GetWindowDisplayMode(NULL, &mode);
655 SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)");
656 SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
657 _checkInvalidWindowError();
659 return TEST_COMPLETED;
663 * @brief Tests call to SDL_GetWindowGammaRamp
665 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
668 video_getWindowGammaRamp(void *arg)
671 const char* title = "video_getWindowGammaRamp Test Window";
677 /* Call against new test window */
678 window = _createVideoSuiteTestWindow(title);
679 if (window == NULL) return TEST_ABORTED;
681 /* Retrieve no channel */
682 result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL);
683 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)");
684 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
686 /* Retrieve single channel */
687 result = SDL_GetWindowGammaRamp(window, red, NULL, NULL);
688 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)");
689 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
691 result = SDL_GetWindowGammaRamp(window, NULL, green, NULL);
692 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)");
693 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
695 result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue);
696 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)");
697 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
699 /* Retrieve two channels */
700 result = SDL_GetWindowGammaRamp(window, red, green, NULL);
701 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)");
702 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
704 result = SDL_GetWindowGammaRamp(window, NULL, green, blue);
705 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)");
706 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
708 result = SDL_GetWindowGammaRamp(window, red, NULL, blue);
709 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)");
710 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
712 /* Retrieve all channels */
713 result = SDL_GetWindowGammaRamp(window, red, green, blue);
714 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)");
715 SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
718 _destroyVideoSuiteTestWindow(window);
720 return TEST_COMPLETED;
724 * @brief Tests call to SDL_GetWindowGammaRamp with invalid input
726 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
729 video_getWindowGammaRampNegative(void *arg)
731 const char* title = "video_getWindowGammaRampNegative Test Window";
738 SDLTest_AssertPass("Call to SDL_ClearError()");
740 /* Call against invalid window */
741 result = SDL_GetWindowGammaRamp(NULL, red, green, blue);
742 SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)");
743 SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %f", result);
744 _checkInvalidWindowError();
746 return TEST_COMPLETED;
749 /* Helper for setting and checking the window grab state */
751 _setAndCheckWindowGrabState(SDL_Window* window, SDL_bool desiredState)
753 SDL_bool currentState;
756 SDL_SetWindowGrab(window, desiredState);
757 SDLTest_AssertPass("Call to SDL_SetWindowGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
759 /* Get and check state */
760 currentState = SDL_GetWindowGrab(window);
761 SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
763 currentState == desiredState,
764 "Validate returned state; expected: %s, got: %s",
765 (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
766 (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
770 * @brief Tests call to SDL_GetWindowGrab and SDL_SetWindowGrab
772 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGrab
773 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowGrab
776 video_getSetWindowGrab(void *arg)
778 const char* title = "video_getSetWindowGrab Test Window";
780 SDL_bool originalState, dummyState, currentState, desiredState;
782 /* Call against new test window */
783 window = _createVideoSuiteTestWindow(title);
784 if (window == NULL) return TEST_ABORTED;
787 originalState = SDL_GetWindowGrab(window);
788 SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
791 _setAndCheckWindowGrabState(window, SDL_FALSE);
794 _setAndCheckWindowGrabState(window, SDL_FALSE);
797 _setAndCheckWindowGrabState(window, SDL_TRUE);
800 _setAndCheckWindowGrabState(window, SDL_TRUE);
803 _setAndCheckWindowGrabState(window, SDL_FALSE);
806 dummyState = SDL_GetWindowGrab(NULL);
807 SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
808 _checkInvalidWindowError();
810 SDL_SetWindowGrab(NULL, SDL_FALSE);
811 SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
812 _checkInvalidWindowError();
814 SDL_SetWindowGrab(NULL, SDL_TRUE);
815 SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
816 _checkInvalidWindowError();
818 /* State should still be F */
819 desiredState = SDL_FALSE;
820 currentState = SDL_GetWindowGrab(window);
821 SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
823 currentState == desiredState,
824 "Validate returned state; expected: %s, got: %s",
825 (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
826 (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
829 _setAndCheckWindowGrabState(window, originalState);
832 _destroyVideoSuiteTestWindow(window);
834 return TEST_COMPLETED;
839 * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID
841 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowID
842 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowFromID
845 video_getWindowId(void *arg)
847 const char* title = "video_getWindowId Test Window";
852 /* Call against new test window */
853 window = _createVideoSuiteTestWindow(title);
854 if (window == NULL) return TEST_ABORTED;
857 id = SDL_GetWindowID(window);
858 SDLTest_AssertPass("Call to SDL_GetWindowID()");
860 /* Get window from ID */
861 result = SDL_GetWindowFromID(id);
862 SDLTest_AssertPass("Call to SDL_GetWindowID(%d)", id);
863 SDLTest_AssertCheck(result == window, "Verify result matches window pointer");
865 /* Get window from random large ID, no result check */
866 randomId = SDLTest_RandomIntegerInRange(UINT8_MAX,UINT16_MAX);
867 result = SDL_GetWindowFromID(randomId);
868 SDLTest_AssertPass("Call to SDL_GetWindowID(%d/random_large)", randomId);
870 /* Get window from 0 and Uint32 max ID, no result check */
871 result = SDL_GetWindowFromID(0);
872 SDLTest_AssertPass("Call to SDL_GetWindowID(0)");
873 result = SDL_GetWindowFromID(UINT32_MAX);
874 SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)");
877 _destroyVideoSuiteTestWindow(window);
879 /* Get window from ID for closed window */
880 result = SDL_GetWindowFromID(id);
881 SDLTest_AssertPass("Call to SDL_GetWindowID(%d/closed_window)", id);
882 SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
886 SDLTest_AssertPass("Call to SDL_ClearError()");
887 id = SDL_GetWindowID(NULL);
888 SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
889 _checkInvalidWindowError();
891 return TEST_COMPLETED;
895 * @brief Tests call to SDL_GetWindowPixelFormat
897 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPixelFormat
900 video_getWindowPixelFormat(void *arg)
902 const char* title = "video_getWindowPixelFormat Test Window";
906 /* Call against new test window */
907 window = _createVideoSuiteTestWindow(title);
908 if (window == NULL) return TEST_ABORTED;
911 format = SDL_GetWindowPixelFormat(window);
912 SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
913 SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %d", SDL_PIXELFORMAT_UNKNOWN, format);
916 _destroyVideoSuiteTestWindow(window);
920 SDLTest_AssertPass("Call to SDL_ClearError()");
921 format = SDL_GetWindowPixelFormat(NULL);
922 SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
923 _checkInvalidWindowError();
925 return TEST_COMPLETED;
929 * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
931 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPosition
932 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowPosition
935 video_getSetWindowPosition(void *arg)
937 const char* title = "video_getSetWindowPosition Test Window";
939 int xVariation, yVariation;
940 int referenceX, referenceY;
941 int currentX, currentY;
942 int desiredX, desiredY;
944 /* Call against new test window */
945 window = _createVideoSuiteTestWindow(title);
946 if (window == NULL) return TEST_ABORTED;
948 for (xVariation = 0; xVariation < 4; xVariation++) {
949 for (yVariation = 0; yVariation < 4; yVariation++) {
952 /* Zero X Position */
956 /* Random X position inside screen */
957 desiredX = SDLTest_RandomIntegerInRange(1, 100);
960 /* Random X position outside screen (positive) */
961 desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
964 /* Random X position outside screen (negative) */
965 desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
971 /* Zero X Position */
975 /* Random X position inside screen */
976 desiredY = SDLTest_RandomIntegerInRange(1, 100);
979 /* Random X position outside screen (positive) */
980 desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
983 /* Random Y position outside screen (negative) */
984 desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
989 SDL_SetWindowPosition(window, desiredX, desiredY);
990 SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
993 currentX = desiredX + 1;
994 currentY = desiredY + 1;
995 SDL_GetWindowPosition(window, ¤tX, ¤tY);
996 SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
997 SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
998 SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
1000 /* Get position X */
1001 currentX = desiredX + 1;
1002 SDL_GetWindowPosition(window, ¤tX, NULL);
1003 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
1004 SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
1006 /* Get position Y */
1007 currentY = desiredY + 1;
1008 SDL_GetWindowPosition(window, NULL, ¤tY);
1009 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
1010 SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
1014 /* Dummy call with both pointers NULL */
1015 SDL_GetWindowPosition(window, NULL, NULL);
1016 SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
1019 _destroyVideoSuiteTestWindow(window);
1021 /* Set some 'magic' value for later check that nothing was changed */
1022 referenceX = SDLTest_RandomSint32();
1023 referenceY = SDLTest_RandomSint32();
1024 currentX = referenceX;
1025 currentY = referenceY;
1026 desiredX = SDLTest_RandomSint32();
1027 desiredY = SDLTest_RandomSint32();
1029 /* Negative tests */
1031 SDLTest_AssertPass("Call to SDL_ClearError()");
1032 SDL_GetWindowPosition(NULL, ¤tX, ¤tY);
1033 SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
1034 SDLTest_AssertCheck(
1035 currentX == referenceX && currentY == referenceY,
1036 "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
1037 referenceX, referenceY,
1038 currentX, currentY);
1039 _checkInvalidWindowError();
1041 SDL_GetWindowPosition(NULL, NULL, NULL);
1042 SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
1043 _checkInvalidWindowError();
1045 SDL_SetWindowPosition(NULL, desiredX, desiredY);
1046 SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
1047 _checkInvalidWindowError();
1049 return TEST_COMPLETED;
1052 /* Helper function that checks for an 'Invalid parameter' error */
1053 void _checkInvalidParameterError()
1055 const char *invalidParameterError = "Parameter";
1058 lastError = (char *)SDL_GetError();
1059 SDLTest_AssertPass("SDL_GetError()");
1060 SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
1061 if (lastError != NULL) {
1062 SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
1063 "SDL_GetError(): expected message starts with '%s', was message: '%s'",
1064 invalidParameterError,
1067 SDLTest_AssertPass("Call to SDL_ClearError()");
1072 * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize
1074 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowSize
1075 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowSize
1078 video_getSetWindowSize(void *arg)
1080 const char* title = "video_getSetWindowSize Test Window";
1084 int maxwVariation, maxhVariation;
1085 int wVariation, hVariation;
1086 int referenceW, referenceH;
1087 int currentW, currentH;
1088 int desiredW, desiredH;
1090 /* Get display bounds for size range */
1091 result = SDL_GetDisplayBounds(0, &display);
1092 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1093 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1094 if (result != 0) return TEST_ABORTED;
1096 /* Call against new test window */
1097 window = _createVideoSuiteTestWindow(title);
1098 if (window == NULL) return TEST_ABORTED;
1101 /* Platform clips window size to screen size */
1105 /* Platform allows window size >= screen size */
1110 for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
1111 for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
1112 switch(wVariation) {
1118 /* Random width inside screen */
1119 desiredW = SDLTest_RandomIntegerInRange(1, 100);
1122 /* Width 1 pixel smaller than screen */
1123 desiredW = display.w - 1;
1126 /* Width at screen size */
1127 desiredW = display.w;
1130 /* Width 1 pixel larger than screen */
1131 desiredW = display.w + 1;
1135 switch(hVariation) {
1141 /* Random height inside screen */
1142 desiredH = SDLTest_RandomIntegerInRange(1, 100);
1145 /* Height 1 pixel smaller than screen */
1146 desiredH = display.h - 1;
1149 /* Height at screen size */
1150 desiredH = display.h;
1153 /* Height 1 pixel larger than screen */
1154 desiredH = display.h + 1;
1159 SDL_SetWindowSize(window, desiredW, desiredH);
1160 SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1163 currentW = desiredW + 1;
1164 currentH = desiredH + 1;
1165 SDL_GetWindowSize(window, ¤tW, ¤tH);
1166 SDLTest_AssertPass("Call to SDL_GetWindowSize()");
1167 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1168 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1170 /* Get just width */
1171 currentW = desiredW + 1;
1172 SDL_GetWindowSize(window, ¤tW, NULL);
1173 SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
1174 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1176 /* Get just height */
1177 currentH = desiredH + 1;
1178 SDL_GetWindowSize(window, NULL, ¤tH);
1179 SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
1180 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1184 /* Dummy call with both pointers NULL */
1185 SDL_GetWindowSize(window, NULL, NULL);
1186 SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
1188 /* Negative tests for parameter input */
1190 SDLTest_AssertPass("Call to SDL_ClearError()");
1191 for (desiredH = -2; desiredH < 2; desiredH++) {
1192 for (desiredW = -2; desiredW < 2; desiredW++) {
1193 if (desiredW <= 0 || desiredH <= 0) {
1194 SDL_SetWindowSize(window, desiredW, desiredH);
1195 SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
1196 _checkInvalidParameterError();
1202 _destroyVideoSuiteTestWindow(window);
1204 /* Set some 'magic' value for later check that nothing was changed */
1205 referenceW = SDLTest_RandomSint32();
1206 referenceH = SDLTest_RandomSint32();
1207 currentW = referenceW;
1208 currentH = referenceH;
1209 desiredW = SDLTest_RandomSint32();
1210 desiredH = SDLTest_RandomSint32();
1212 /* Negative tests for window input */
1214 SDLTest_AssertPass("Call to SDL_ClearError()");
1215 SDL_GetWindowSize(NULL, ¤tW, ¤tH);
1216 SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
1217 SDLTest_AssertCheck(
1218 currentW == referenceW && currentH == referenceH,
1219 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1220 referenceW, referenceH,
1221 currentW, currentH);
1222 _checkInvalidWindowError();
1224 SDL_GetWindowSize(NULL, NULL, NULL);
1225 SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
1226 _checkInvalidWindowError();
1228 SDL_SetWindowSize(NULL, desiredW, desiredH);
1229 SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
1230 _checkInvalidWindowError();
1232 return TEST_COMPLETED;
1236 * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
1240 video_getSetWindowMinimumSize(void *arg)
1242 const char* title = "video_getSetWindowMinimumSize Test Window";
1246 int wVariation, hVariation;
1247 int referenceW, referenceH;
1248 int currentW, currentH;
1249 int desiredW, desiredH;
1251 /* Get display bounds for size range */
1252 result = SDL_GetDisplayBounds(0, &display);
1253 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1254 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1255 if (result != 0) return TEST_ABORTED;
1257 /* Call against new test window */
1258 window = _createVideoSuiteTestWindow(title);
1259 if (window == NULL) return TEST_ABORTED;
1261 for (wVariation = 0; wVariation < 5; wVariation++) {
1262 for (hVariation = 0; hVariation < 5; hVariation++) {
1263 switch(wVariation) {
1269 /* Random width inside screen */
1270 desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1273 /* Width at screen size */
1274 desiredW = display.w;
1278 switch(hVariation) {
1284 /* Random height inside screen */
1285 desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1288 /* Height at screen size */
1289 desiredH = display.h;
1292 /* Height 1 pixel larger than screen */
1293 desiredH = display.h + 1;
1298 SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1299 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1302 currentW = desiredW + 1;
1303 currentH = desiredH + 1;
1304 SDL_GetWindowMinimumSize(window, ¤tW, ¤tH);
1305 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
1306 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1307 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1309 /* Get just width */
1310 currentW = desiredW + 1;
1311 SDL_GetWindowMinimumSize(window, ¤tW, NULL);
1312 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
1313 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1315 /* Get just height */
1316 currentH = desiredH + 1;
1317 SDL_GetWindowMinimumSize(window, NULL, ¤tH);
1318 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
1319 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1323 /* Dummy call with both pointers NULL */
1324 SDL_GetWindowMinimumSize(window, NULL, NULL);
1325 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
1327 /* Negative tests for parameter input */
1329 SDLTest_AssertPass("Call to SDL_ClearError()");
1330 for (desiredH = -2; desiredH < 2; desiredH++) {
1331 for (desiredW = -2; desiredW < 2; desiredW++) {
1332 if (desiredW <= 0 || desiredH <= 0) {
1333 SDL_SetWindowMinimumSize(window, desiredW, desiredH);
1334 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
1335 _checkInvalidParameterError();
1341 _destroyVideoSuiteTestWindow(window);
1343 /* Set some 'magic' value for later check that nothing was changed */
1344 referenceW = SDLTest_RandomSint32();
1345 referenceH = SDLTest_RandomSint32();
1346 currentW = referenceW;
1347 currentH = referenceH;
1348 desiredW = SDLTest_RandomSint32();
1349 desiredH = SDLTest_RandomSint32();
1351 /* Negative tests for window input */
1353 SDLTest_AssertPass("Call to SDL_ClearError()");
1354 SDL_GetWindowMinimumSize(NULL, ¤tW, ¤tH);
1355 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
1356 SDLTest_AssertCheck(
1357 currentW == referenceW && currentH == referenceH,
1358 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1359 referenceW, referenceH,
1360 currentW, currentH);
1361 _checkInvalidWindowError();
1363 SDL_GetWindowMinimumSize(NULL, NULL, NULL);
1364 SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
1365 _checkInvalidWindowError();
1367 SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
1368 SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
1369 _checkInvalidWindowError();
1371 return TEST_COMPLETED;
1375 * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
1379 video_getSetWindowMaximumSize(void *arg)
1381 const char* title = "video_getSetWindowMaximumSize Test Window";
1385 int wVariation, hVariation;
1386 int referenceW, referenceH;
1387 int currentW, currentH;
1388 int desiredW, desiredH;
1390 /* Get display bounds for size range */
1391 result = SDL_GetDisplayBounds(0, &display);
1392 SDLTest_AssertPass("SDL_GetDisplayBounds()");
1393 SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
1394 if (result != 0) return TEST_ABORTED;
1396 /* Call against new test window */
1397 window = _createVideoSuiteTestWindow(title);
1398 if (window == NULL) return TEST_ABORTED;
1400 for (wVariation = 0; wVariation < 3; wVariation++) {
1401 for (hVariation = 0; hVariation < 3; hVariation++) {
1402 switch(wVariation) {
1408 /* Random width inside screen */
1409 desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
1412 /* Width at screen size */
1413 desiredW = display.w;
1417 switch(hVariation) {
1423 /* Random height inside screen */
1424 desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
1427 /* Height at screen size */
1428 desiredH = display.h;
1433 SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1434 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1437 currentW = desiredW + 1;
1438 currentH = desiredH + 1;
1439 SDL_GetWindowMaximumSize(window, ¤tW, ¤tH);
1440 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
1441 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
1442 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
1444 /* Get just width */
1445 currentW = desiredW + 1;
1446 SDL_GetWindowMaximumSize(window, ¤tW, NULL);
1447 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
1448 SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
1450 /* Get just height */
1451 currentH = desiredH + 1;
1452 SDL_GetWindowMaximumSize(window, NULL, ¤tH);
1453 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
1454 SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
1458 /* Dummy call with both pointers NULL */
1459 SDL_GetWindowMaximumSize(window, NULL, NULL);
1460 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
1462 /* Negative tests for parameter input */
1464 SDLTest_AssertPass("Call to SDL_ClearError()");
1465 for (desiredH = -2; desiredH < 2; desiredH++) {
1466 for (desiredW = -2; desiredW < 2; desiredW++) {
1467 if (desiredW <= 0 || desiredH <= 0) {
1468 SDL_SetWindowMaximumSize(window, desiredW, desiredH);
1469 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
1470 _checkInvalidParameterError();
1476 _destroyVideoSuiteTestWindow(window);
1478 /* Set some 'magic' value for later check that nothing was changed */
1479 referenceW = SDLTest_RandomSint32();
1480 referenceH = SDLTest_RandomSint32();
1481 currentW = referenceW;
1482 currentH = referenceH;
1483 desiredW = SDLTest_RandomSint32();
1484 desiredH = SDLTest_RandomSint32();
1486 /* Negative tests */
1488 SDLTest_AssertPass("Call to SDL_ClearError()");
1489 SDL_GetWindowMaximumSize(NULL, ¤tW, ¤tH);
1490 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
1491 SDLTest_AssertCheck(
1492 currentW == referenceW && currentH == referenceH,
1493 "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
1494 referenceW, referenceH,
1495 currentW, currentH);
1496 _checkInvalidWindowError();
1498 SDL_GetWindowMaximumSize(NULL, NULL, NULL);
1499 SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
1500 _checkInvalidWindowError();
1502 SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
1503 SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
1504 _checkInvalidWindowError();
1506 return TEST_COMPLETED;
1511 * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
1513 * @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowData
1514 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowData
1517 video_getSetWindowData(void *arg)
1519 int returnValue = TEST_COMPLETED;
1520 const char* title = "video_setGetWindowData Test Window";
1522 const char *referenceName = "TestName";
1523 const char *name = "TestName";
1524 const char *referenceName2 = "TestName2";
1525 const char *name2 = "TestName2";
1527 char *referenceUserdata;
1529 char *referenceUserdata2;
1534 /* Call against new test window */
1535 window = _createVideoSuiteTestWindow(title);
1536 if (window == NULL) return TEST_ABORTED;
1538 /* Create testdata */
1539 datasize = SDLTest_RandomIntegerInRange(1, 32);
1540 referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
1541 if (referenceUserdata == NULL) {
1542 returnValue = TEST_ABORTED;
1545 userdata = SDL_strdup(referenceUserdata);
1546 if (userdata == NULL) {
1547 returnValue = TEST_ABORTED;
1550 datasize = SDLTest_RandomIntegerInRange(1, 32);
1551 referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
1552 if (referenceUserdata2 == NULL) {
1553 returnValue = TEST_ABORTED;
1556 userdata2 = (char *)SDL_strdup(referenceUserdata2);
1557 if (userdata2 == NULL) {
1558 returnValue = TEST_ABORTED;
1562 /* Get non-existent data */
1563 result = (char *)SDL_GetWindowData(window, name);
1564 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1565 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1566 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1569 result = (char *)SDL_SetWindowData(window, name, userdata);
1570 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
1571 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1572 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1573 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1575 /* Get data (twice) */
1576 for (iteration = 1; iteration <= 2; iteration++) {
1577 result = (char *)SDL_GetWindowData(window, name);
1578 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
1579 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1580 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1583 /* Set data again twice */
1584 for (iteration = 1; iteration <= 2; iteration++) {
1585 result = (char *)SDL_SetWindowData(window, name, userdata);
1586 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
1587 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1588 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1589 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1592 /* Get data again */
1593 result = (char *)SDL_GetWindowData(window, name);
1594 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
1595 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1596 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1598 /* Set data with new data */
1599 result = (char *)SDL_SetWindowData(window, name, userdata2);
1600 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
1601 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1602 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1603 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1604 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1606 /* Set data with new data again */
1607 result = (char *)SDL_SetWindowData(window, name, userdata2);
1608 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
1609 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1610 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1611 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1612 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1615 result = (char *)SDL_GetWindowData(window, name);
1616 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1617 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1618 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1620 /* Set data with NULL to clear */
1621 result = (char *)SDL_SetWindowData(window, name, NULL);
1622 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name, userdata);
1623 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
1624 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1625 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1626 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1628 /* Set data with NULL to clear again */
1629 result = (char *)SDL_SetWindowData(window, name, NULL);
1630 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name, userdata);
1631 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1632 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1633 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1634 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
1636 /* Get non-existent data */
1637 result = (char *)SDL_GetWindowData(window, name);
1638 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
1639 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1640 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1642 /* Get non-existent data new name */
1643 result = (char *)SDL_GetWindowData(window, name2);
1644 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
1645 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1646 SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
1648 /* Set data (again) */
1649 result = (char *)SDL_SetWindowData(window, name, userdata);
1650 SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
1651 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1652 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1653 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
1655 /* Get data (again) */
1656 result = (char *)SDL_GetWindowData(window, name);
1657 SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
1658 SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
1659 SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
1663 SDLTest_AssertPass("Call to SDL_ClearError()");
1665 /* Set with invalid window */
1666 result = (char *)SDL_SetWindowData(NULL, name, userdata);
1667 SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)");
1668 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1669 _checkInvalidWindowError();
1671 /* Set data with NULL name, valid userdata */
1672 result = (char *)SDL_SetWindowData(window, NULL, userdata);
1673 SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
1674 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1675 _checkInvalidParameterError();
1677 /* Set data with empty name, valid userdata */
1678 result = (char *)SDL_SetWindowData(window, "", userdata);
1679 SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
1680 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1681 _checkInvalidParameterError();
1683 /* Set data with NULL name, NULL userdata */
1684 result = (char *)SDL_SetWindowData(window, NULL, NULL);
1685 SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
1686 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1687 _checkInvalidParameterError();
1689 /* Set data with empty name, NULL userdata */
1690 result = (char *)SDL_SetWindowData(window, "", NULL);
1691 SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
1692 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1693 _checkInvalidParameterError();
1695 /* Get with invalid window */
1696 result = (char *)SDL_GetWindowData(NULL, name);
1697 SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)");
1698 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1699 _checkInvalidWindowError();
1701 /* Get data with NULL name */
1702 result = (char *)SDL_GetWindowData(window, NULL);
1703 SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
1704 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1705 _checkInvalidParameterError();
1707 /* Get data with empty name */
1708 result = (char *)SDL_GetWindowData(window, "");
1709 SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
1710 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
1711 _checkInvalidParameterError();
1714 _destroyVideoSuiteTestWindow(window);
1717 SDL_free(referenceUserdata);
1718 SDL_free(referenceUserdata2);
1720 SDL_free(userdata2);
1726 /* ================= Test References ================== */
1728 /* Video test cases */
1729 static const SDLTest_TestCaseReference videoTest1 =
1730 { (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED };
1732 static const SDLTest_TestCaseReference videoTest2 =
1733 { (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions", "Create windows at various locations", TEST_ENABLED };
1735 static const SDLTest_TestCaseReference videoTest3 =
1736 { (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED };
1738 static const SDLTest_TestCaseReference videoTest4 =
1739 { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED };
1741 static const SDLTest_TestCaseReference videoTest5 =
1742 { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
1744 static const SDLTest_TestCaseReference videoTest6 =
1745 { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
1747 static const SDLTest_TestCaseReference videoTest7 =
1748 { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
1750 static const SDLTest_TestCaseReference videoTest8 =
1751 { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
1753 static const SDLTest_TestCaseReference videoTest9 =
1754 { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
1756 static const SDLTest_TestCaseReference videoTest10 =
1757 { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED };
1759 static const SDLTest_TestCaseReference videoTest11 =
1760 { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED };
1762 static const SDLTest_TestCaseReference videoTest12 =
1763 { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED };
1765 static const SDLTest_TestCaseReference videoTest13 =
1766 { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED };
1768 static const SDLTest_TestCaseReference videoTest14 =
1769 { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED };
1771 static const SDLTest_TestCaseReference videoTest15 =
1772 { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED };
1774 static const SDLTest_TestCaseReference videoTest16 =
1775 { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED };
1777 static const SDLTest_TestCaseReference videoTest17 =
1778 { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED };
1780 static const SDLTest_TestCaseReference videoTest18 =
1781 { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED };
1783 static const SDLTest_TestCaseReference videoTest19 =
1784 { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED };
1786 static const SDLTest_TestCaseReference videoTest20 =
1787 { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED };
1789 static const SDLTest_TestCaseReference videoTest21 =
1790 { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED };
1792 static const SDLTest_TestCaseReference videoTest22 =
1793 { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED };
1795 static const SDLTest_TestCaseReference videoTest23 =
1796 { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
1798 /* Sequence of Video test cases */
1799 static const SDLTest_TestCaseReference *videoTests[] = {
1800 &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
1801 &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
1802 &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
1803 &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
1807 /* Video test suite (global) */
1808 SDLTest_TestSuiteReference videoTestSuite = {