1.1 --- a/test/testautomation_mouse.c Mon Feb 25 00:54:25 2013 -0800
1.2 +++ b/test/testautomation_mouse.c Mon Feb 25 08:05:26 2013 -0800
1.3 @@ -413,13 +413,13 @@
1.4 #define MOUSE_TESTWINDOW_HEIGHT 200
1.5
1.6 /**
1.7 - * Create s test window
1.8 + * Creates a test window
1.9 */
1.10 -SDL_Window *_createTestWindow()
1.11 +SDL_Window *_createMouseSuiteTestWindow()
1.12 {
1.13 int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
1.14 SDL_Window *window;
1.15 - window = SDL_CreateWindow("mouse_createTestWindow", posX, posY, width, height, 0);
1.16 + window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0);
1.17 SDLTest_AssertPass("SDL_CreateWindow()");
1.18 SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
1.19 return window;
1.20 @@ -428,12 +428,12 @@
1.21 /*
1.22 * Destroy test window
1.23 */
1.24 -void _destroyTestWindow(SDL_Window *window)
1.25 +void _destroyMouseSuiteTestWindow(SDL_Window *window)
1.26 {
1.27 if (window != NULL) {
1.28 SDL_DestroyWindow(window);
1.29 window = NULL;
1.30 - SDLTest_AssertPass("SDL_DestroyWindow");
1.31 + SDLTest_AssertPass("SDL_DestroyWindow()");
1.32 }
1.33 }
1.34
1.35 @@ -453,7 +453,7 @@
1.36 SDL_Window *window;
1.37
1.38 /* Create test window */
1.39 - window = _createTestWindow();
1.40 + window = _createMouseSuiteTestWindow();
1.41 if (window == NULL) return TEST_ABORTED;
1.42
1.43 /* Mouse to random position inside window */
1.44 @@ -482,7 +482,7 @@
1.45
1.46
1.47 /* Clean up test window */
1.48 - _destroyTestWindow(window);
1.49 + _destroyMouseSuiteTestWindow(window);
1.50
1.51 return TEST_COMPLETED;
1.52 }
1.53 @@ -505,7 +505,7 @@
1.54 SDLTest_AssertPass("SDL_GetMouseFocus()");
1.55
1.56 /* Create test window */
1.57 - window = _createTestWindow();
1.58 + window = _createMouseSuiteTestWindow();
1.59 if (window == NULL) return TEST_ABORTED;
1.60
1.61 /* Mouse to random position inside window */
1.62 @@ -531,7 +531,7 @@
1.63 SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
1.64
1.65 /* Clean up test window */
1.66 - _destroyTestWindow(window);
1.67 + _destroyMouseSuiteTestWindow(window);
1.68
1.69 /* Pump events to update focus state */
1.70 SDL_PumpEvents();
2.1 --- a/test/testautomation_video.c Mon Feb 25 00:54:25 2013 -0800
2.2 +++ b/test/testautomation_video.c Mon Feb 25 08:05:26 2013 -0800
2.3 @@ -7,6 +7,43 @@
2.4 #include "SDL.h"
2.5 #include "SDL_test.h"
2.6
2.7 +/* Private helpers */
2.8 +
2.9 +/*
2.10 + * Create a test window
2.11 + */
2.12 +SDL_Window *_createVideoSuiteTestWindow(const char *title)
2.13 +{
2.14 + SDL_Window* window;
2.15 + int x, y, w, h;
2.16 + SDL_WindowFlags flags;
2.17 +
2.18 + /* Standard window */
2.19 + x = SDLTest_RandomIntegerInRange(1, 100);
2.20 + y = SDLTest_RandomIntegerInRange(1, 100);
2.21 + w = SDLTest_RandomIntegerInRange(320, 1024);
2.22 + h = SDLTest_RandomIntegerInRange(320, 768);
2.23 + flags = SDL_WINDOW_SHOWN;
2.24 +
2.25 + window = SDL_CreateWindow(title, x, y, w, h, flags);
2.26 + SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
2.27 + SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
2.28 +
2.29 + return window;
2.30 +}
2.31 +
2.32 +/*
2.33 + * Destroy test window
2.34 + */
2.35 +void _destroyVideoSuiteTestWindow(SDL_Window *window)
2.36 +{
2.37 + if (window != NULL) {
2.38 + SDL_DestroyWindow(window);
2.39 + window = NULL;
2.40 + SDLTest_AssertPass("Call to SDL_DestroyWindow");
2.41 + }
2.42 +}
2.43 +
2.44 /* Test case functions */
2.45
2.46 /**
2.47 @@ -133,10 +170,9 @@
2.48 window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
2.49 SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
2.50 SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
2.51 - if (window != NULL) {
2.52 - SDL_DestroyWindow(window);
2.53 - SDLTest_AssertPass("Call to SDL_DestroyWindow");
2.54 - }
2.55 +
2.56 + /* Clean up */
2.57 + _destroyVideoSuiteTestWindow(window);
2.58 }
2.59 }
2.60
2.61 @@ -191,10 +227,9 @@
2.62 window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
2.63 SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
2.64 SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
2.65 - if (window != NULL) {
2.66 - SDL_DestroyWindow(window);
2.67 - SDLTest_AssertPass("Call to SDL_DestroyWindow");
2.68 - }
2.69 +
2.70 + /* Clean up */
2.71 + _destroyVideoSuiteTestWindow(window);
2.72 }
2.73 }
2.74
2.75 @@ -269,15 +304,16 @@
2.76 window = SDL_CreateWindow(title, x, y, w, h, flags);
2.77 SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
2.78 SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
2.79 - if (window != NULL) {
2.80 - SDL_DestroyWindow(window);
2.81 - SDLTest_AssertPass("Call to SDL_DestroyWindow");
2.82 - }
2.83 +
2.84 +
2.85 + /* Clean up */
2.86 + _destroyVideoSuiteTestWindow(window);
2.87 }
2.88
2.89 return TEST_COMPLETED;
2.90 }
2.91
2.92 +
2.93 /**
2.94 * @brief Tests the functionality of the SDL_GetWindowFlags function
2.95 */
2.96 @@ -286,33 +322,203 @@
2.97 {
2.98 SDL_Window* window;
2.99 const char* title = "video_getWindowFlags Test Window";
2.100 - int x, y, w, h;
2.101 SDL_WindowFlags flags;
2.102 Uint32 actualFlags;
2.103
2.104 - /* Standard window */
2.105 - x = SDLTest_RandomIntegerInRange(1, 100);
2.106 - y = SDLTest_RandomIntegerInRange(1, 100);
2.107 - w = SDLTest_RandomIntegerInRange(320, 1024);
2.108 - h = SDLTest_RandomIntegerInRange(320, 768);
2.109 -
2.110 - /* Reliable flag */
2.111 + /* Reliable flag set always set in test window */
2.112 flags = SDL_WINDOW_SHOWN;
2.113
2.114 - window = SDL_CreateWindow(title, x, y, w, h, flags);
2.115 - SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
2.116 - SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
2.117 + /* Call against new test window */
2.118 + window = _createVideoSuiteTestWindow(title);
2.119 if (window != NULL) {
2.120 actualFlags = SDL_GetWindowFlags(window);
2.121 SDLTest_AssertPass("Call to SDL_GetWindowFlags");
2.122 SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
2.123 - SDL_DestroyWindow(window);
2.124 - SDLTest_AssertPass("Call to SDL_DestroyWindow");
2.125 + }
2.126 +
2.127 + /* Clean up */
2.128 + _destroyVideoSuiteTestWindow(window);
2.129 +
2.130 + return TEST_COMPLETED;
2.131 +}
2.132 +
2.133 +/**
2.134 + * @brief Tests the functionality of the SDL_GetNumDisplayModes function
2.135 + */
2.136 +int
2.137 +video_getNumDisplayModes(void *arg)
2.138 +{
2.139 + int result;
2.140 + int displayNum;
2.141 + int i;
2.142 +
2.143 + /* Get number of displays */
2.144 + displayNum = SDL_GetNumVideoDisplays();
2.145 + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
2.146 +
2.147 + /* Make call for each display */
2.148 + for (i=0; i<displayNum; i++) {
2.149 + result = SDL_GetNumDisplayModes(i);
2.150 + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
2.151 + SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
2.152 }
2.153
2.154 return TEST_COMPLETED;
2.155 }
2.156
2.157 +/**
2.158 + * @brief Tests negative call to SDL_GetNumDisplayModes function
2.159 + */
2.160 +int
2.161 +video_getNumDisplayModesNegative(void *arg)
2.162 +{
2.163 + int result;
2.164 + int displayNum;
2.165 + int displayIndex;
2.166 +
2.167 + /* Get number of displays */
2.168 + displayNum = SDL_GetNumVideoDisplays();
2.169 + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
2.170 +
2.171 + /* Invalid boundary values */
2.172 + displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
2.173 + result = SDL_GetNumDisplayModes(displayIndex);
2.174 + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
2.175 + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
2.176 +
2.177 + /* Large (out-of-bounds) display index */
2.178 + displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
2.179 + result = SDL_GetNumDisplayModes(displayIndex);
2.180 + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
2.181 + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
2.182 +
2.183 + displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
2.184 + result = SDL_GetNumDisplayModes(displayIndex);
2.185 + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
2.186 + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
2.187 +
2.188 + return TEST_COMPLETED;
2.189 +}
2.190 +
2.191 +/**
2.192 + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
2.193 + */
2.194 +int
2.195 +video_getClosestDisplayModeCurrentResolution(void *arg)
2.196 +{
2.197 + int result;
2.198 + SDL_DisplayMode current;
2.199 + SDL_DisplayMode target;
2.200 + SDL_DisplayMode closest;
2.201 + SDL_DisplayMode* dResult;
2.202 + int displayNum;
2.203 + int i;
2.204 + int variation;
2.205 +
2.206 + /* Get number of displays */
2.207 + displayNum = SDL_GetNumVideoDisplays();
2.208 + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
2.209 +
2.210 + /* Make calls for each display */
2.211 + for (i=0; i<displayNum; i++) {
2.212 + SDLTest_Log("Testing against display: %d", i);
2.213 +
2.214 + /* Get first display mode to get a sane resolution; this should always work */
2.215 + result = SDL_GetDisplayMode(i, 0, ¤t);
2.216 + SDLTest_AssertPass("Call to SDL_GetDisplayMode");
2.217 + SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
2.218 + if (result != 0) {
2.219 + return TEST_ABORTED;
2.220 + }
2.221 +
2.222 + /* Set the desired resolution equals to current resolution */
2.223 + target.w = current.w;
2.224 + target.h = current.h;
2.225 + for (variation = 0; variation < 8; variation ++) {
2.226 + /* Vary constraints on other query parameters */
2.227 + target.format = (variation & 1) ? current.format : 0;
2.228 + target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
2.229 + target.driverdata = (variation & 4) ? current.driverdata : 0;
2.230 +
2.231 + /* Make call */
2.232 + dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
2.233 + SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
2.234 + SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL");
2.235 +
2.236 + /* Check that one gets the current resolution back again */
2.237 + SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
2.238 + SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
2.239 + SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
2.240 + SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
2.241 + }
2.242 + }
2.243 +
2.244 + return TEST_COMPLETED;
2.245 +}
2.246 +
2.247 +/**
2.248 + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
2.249 + */
2.250 +int
2.251 +video_getClosestDisplayModeRandomResolution(void *arg)
2.252 +{
2.253 + SDL_DisplayMode target;
2.254 + SDL_DisplayMode closest;
2.255 + SDL_DisplayMode* dResult;
2.256 + int displayNum;
2.257 + int i;
2.258 + int variation;
2.259 +
2.260 + /* Get number of displays */
2.261 + displayNum = SDL_GetNumVideoDisplays();
2.262 + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
2.263 +
2.264 + /* Make calls for each display */
2.265 + for (i=0; i<displayNum; i++) {
2.266 + SDLTest_Log("Testing against display: %d", i);
2.267 +
2.268 + for (variation = 0; variation < 16; variation ++) {
2.269 +
2.270 + /* Set random constraints */
2.271 + target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
2.272 + target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
2.273 + target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
2.274 + target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
2.275 + target.driverdata = 0;
2.276 +
2.277 + /* Make call; may or may not find anything, so don't validate any further */
2.278 + dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
2.279 + SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
2.280 + }
2.281 + }
2.282 +
2.283 + return TEST_COMPLETED;
2.284 +}
2.285 +
2.286 +/**
2.287 + * @brief Tests call to SDL_GetWindowBrightness
2.288 + */
2.289 +int
2.290 +video_getWindowBrightness(void *arg)
2.291 +{
2.292 + SDL_Window* window;
2.293 + const char* title = "video_getWindowBrightness Test Window";
2.294 + float result;
2.295 +
2.296 + /* Call against new test window */
2.297 + window = _createVideoSuiteTestWindow(title);
2.298 + if (window != NULL) {
2.299 + result = SDL_GetWindowBrightness(window);
2.300 + SDLTest_AssertPass("Call to SDL_GetWindowBrightness");
2.301 + SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
2.302 + }
2.303 +
2.304 + /* Clean up */
2.305 + _destroyVideoSuiteTestWindow(window);
2.306 +
2.307 + return TEST_COMPLETED;
2.308 +}
2.309 +
2.310 /* ================= Test References ================== */
2.311
2.312 /* Video test cases */
2.313 @@ -329,11 +535,27 @@
2.314 { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED };
2.315
2.316 static const SDLTest_TestCaseReference videoTest5 =
2.317 - { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Set and get window flags", TEST_ENABLED };
2.318 + { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
2.319 +
2.320 +static const SDLTest_TestCaseReference videoTest6 =
2.321 + { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
2.322 +
2.323 +static const SDLTest_TestCaseReference videoTest7 =
2.324 + { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
2.325 +
2.326 +static const SDLTest_TestCaseReference videoTest8 =
2.327 + { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
2.328 +
2.329 +static const SDLTest_TestCaseReference videoTest9 =
2.330 + { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
2.331 +
2.332 +static const SDLTest_TestCaseReference videoTest10 =
2.333 + { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED };
2.334
2.335 /* Sequence of Video test cases */
2.336 static const SDLTest_TestCaseReference *videoTests[] = {
2.337 - &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, NULL
2.338 + &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
2.339 + &videoTest7, &videoTest8, &videoTest9, &videoTest10, NULL
2.340 };
2.341
2.342 /* Video test suite (global) */