testautomation: add video_setWindowCenteredOnDisplay test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
diff --git a/test/testautomation_video.c b/test/testautomation_video.c
index edf8dff..c5b648c 100644
--- a/test/testautomation_video.c
+++ b/test/testautomation_video.c
@@ -1849,6 +1849,129 @@ video_getSetWindowData(void *arg)
return returnValue;
}
+/**
+* @brief Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN_DESKTOP.
+*
+* Espeically useful when run on a multi-monitor system with different DPI scales per monitor,
+* to test that the window size is maintained when moving between monitors.
+*/
+int
+video_setWindowCenteredOnDisplay(void *arg)
+{
+ SDL_Window *window;
+ const char *title = "video_setWindowCenteredOnDisplay Test Window";
+ int x, y, w, h;
+ int xVariation, yVariation;
+ int displayNum;
+ int result;
+ SDL_Rect display0, display1;
+
+ displayNum = SDL_GetNumVideoDisplays();
+
+ /* Get display bounds */
+ result = SDL_GetDisplayBounds(0 % displayNum, &display0);
+ SDLTest_AssertPass("SDL_GetDisplayBounds()");
+ SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
+ if (result != 0)
+ return TEST_ABORTED;
+
+ result = SDL_GetDisplayBounds(1 % displayNum, &display1);
+ SDLTest_AssertPass("SDL_GetDisplayBounds()");
+ SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
+ if (result != 0)
+ return TEST_ABORTED;
+
+ for (xVariation = 0; xVariation < 2; xVariation++) {
+ for (yVariation = 0; yVariation < 2; yVariation++) {
+ int currentX = 0, currentY = 0;
+ int currentW = 0, currentH = 0;
+ int expectedX = 0, expectedY = 0;
+ int currentDisplay;
+ int expectedDisplay;
+ SDL_Rect expectedDisplayRect;
+
+ /* xVariation is the display we start on */
+ expectedDisplay = xVariation % displayNum;
+ x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
+ y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
+ w = SDLTest_RandomIntegerInRange(640, 800);
+ h = SDLTest_RandomIntegerInRange(400, 600);
+ expectedDisplayRect = (xVariation == 0) ? display0 : display1;
+ expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
+ expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
+
+ window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
+ SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
+ SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
+
+ /* Check the window is centered on the requested display */
+ currentDisplay = SDL_GetWindowDisplayIndex(window);
+ SDL_GetWindowSize(window, ¤tW, ¤tH);
+ SDL_GetWindowPosition(window, ¤tX, ¤tY);
+
+ SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
+ SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
+ SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
+ SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
+ SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
+
+ /* Enter fullscreen desktop */
+ result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+ SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
+
+ /* Check we are filling the full display */
+ currentDisplay = SDL_GetWindowDisplayIndex(window);
+ SDL_GetWindowSize(window, ¤tW, ¤tH);
+ SDL_GetWindowPosition(window, ¤tX, ¤tY);
+
+ SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
+ SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w);
+ SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h);
+ SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
+ SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
+
+ /* Leave fullscreen desktop */
+ result = SDL_SetWindowFullscreen(window, 0);
+ SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
+
+ /* Check window was restored correctly */
+ currentDisplay = SDL_GetWindowDisplayIndex(window);
+ SDL_GetWindowSize(window, ¤tW, ¤tH);
+ SDL_GetWindowPosition(window, ¤tX, ¤tY);
+
+ SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
+ SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
+ SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
+ SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
+ SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
+
+ /* Center on display yVariation, and check window properties */
+
+ expectedDisplay = yVariation % displayNum;
+ x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
+ y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
+ expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1;
+ expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
+ expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
+ SDL_SetWindowPosition(window, x, y);
+
+ currentDisplay = SDL_GetWindowDisplayIndex(window);
+ SDL_GetWindowSize(window, ¤tW, ¤tH);
+ SDL_GetWindowPosition(window, ¤tX, ¤tY);
+
+ SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
+ SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
+ SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
+ SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
+ SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
+
+ /* Clean up */
+ _destroyVideoSuiteTestWindow(window);
+ }
+ }
+
+ return TEST_COMPLETED;
+}
/* ================= Test References ================== */
@@ -1922,13 +2045,16 @@ static const SDLTest_TestCaseReference videoTest22 =
static const SDLTest_TestCaseReference videoTest23 =
{ (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
+static const SDLTest_TestCaseReference videoTest24 =
+ { (SDLTest_TestCaseFp) video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED };
+
/* Sequence of Video test cases */
static const SDLTest_TestCaseReference *videoTests[] = {
&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
&videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
&videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
&videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
- &videoTest23, NULL
+ &videoTest23, &videoTest24, NULL
};
/* Video test suite (global) */