| 1 |
/** |
| 2 |
* Video test suite |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
/* Visual Studio 2008 doesn't have stdint.h */ |
| 9 |
#if defined(_MSC_VER) && _MSC_VER <= 1500 |
| 10 |
#define UINT8_MAX ~(Uint8)0 |
| 11 |
#define UINT16_MAX ~(Uint16)0 |
| 12 |
#define UINT32_MAX ~(Uint32)0 |
| 13 |
#define UINT64_MAX ~(Uint64)0 |
| 14 |
#else |
| 15 |
#include <stdint.h> |
| 16 |
#endif |
| 17 |
|
| 18 |
#include "SDL.h" |
| 19 |
#include "SDL_test.h" |
| 20 |
|
| 21 |
/* Private helpers */ |
| 22 |
|
| 23 |
/* |
| 24 |
* Create a test window |
| 25 |
*/ |
| 26 |
SDL_Window *_createVideoSuiteTestWindow(const char *title) |
| 27 |
{ |
| 28 |
SDL_Window *window; |
| 29 |
int x, y, w, h; |
| 30 |
SDL_WindowFlags flags; |
| 31 |
SDL_bool needs_renderer = SDL_FALSE; |
| 32 |
|
| 33 |
/* Standard window */ |
| 34 |
x = SDLTest_RandomIntegerInRange(1, 100); |
| 35 |
y = SDLTest_RandomIntegerInRange(1, 100); |
| 36 |
w = SDLTest_RandomIntegerInRange(320, 1024); |
| 37 |
h = SDLTest_RandomIntegerInRange(320, 768); |
| 38 |
flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS; |
| 39 |
|
| 40 |
window = SDL_CreateWindow(title, x, y, w, h, flags); |
| 41 |
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); |
| 42 |
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); |
| 43 |
|
| 44 |
/* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen. |
| 45 |
* This is required for the mouse/keyboard grab tests to pass. |
| 46 |
*/ |
| 47 |
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) { |
| 48 |
needs_renderer = SDL_TRUE; |
| 49 |
} else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { |
| 50 |
/* Try to detect if the x11 driver is running under XWayland */ |
| 51 |
const char *session_type = SDL_getenv("XDG_SESSION_TYPE"); |
| 52 |
if (session_type && SDL_strcasecmp(session_type, "wayland") == 0) { |
| 53 |
needs_renderer = SDL_TRUE; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
if (needs_renderer) { |
| 58 |
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); |
| 59 |
if (renderer) { |
| 60 |
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); |
| 61 |
SDL_RenderClear(renderer); |
| 62 |
SDL_RenderPresent(renderer); |
| 63 |
|
| 64 |
/* Some desktops don't display the window immediately after presentation, |
| 65 |
* so delay to give the window time to actually appear on the desktop. |
| 66 |
*/ |
| 67 |
SDL_Delay(100); |
| 68 |
} else { |
| 69 |
SDLTest_Log("Unable to create a renderer, some tests may fail on Wayland/XWayland"); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
return window; |
| 74 |
} |
| 75 |
|
| 76 |
/* |
| 77 |
* Destroy test window |
| 78 |
*/ |
| 79 |
void _destroyVideoSuiteTestWindow(SDL_Window *window) |
| 80 |
{ |
| 81 |
if (window) { |
| 82 |
SDL_DestroyWindow(window); |
| 83 |
window = NULL; |
| 84 |
SDLTest_AssertPass("Call to SDL_DestroyWindow()"); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/* Test case functions */ |
| 89 |
|
| 90 |
/** |
| 91 |
* @brief Enable and disable screensaver while checking state |
| 92 |
*/ |
| 93 |
int video_enableDisableScreensaver(void *arg) |
| 94 |
{ |
| 95 |
SDL_bool initialResult; |
| 96 |
SDL_bool result; |
| 97 |
|
| 98 |
/* Get current state and proceed according to current state */ |
| 99 |
initialResult = SDL_IsScreenSaverEnabled(); |
| 100 |
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); |
| 101 |
if (initialResult == SDL_TRUE) { |
| 102 |
|
| 103 |
/* Currently enabled: disable first, then enable again */ |
| 104 |
|
| 105 |
/* Disable screensaver and check */ |
| 106 |
SDL_DisableScreenSaver(); |
| 107 |
SDLTest_AssertPass("Call to SDL_DisableScreenSaver()"); |
| 108 |
result = SDL_IsScreenSaverEnabled(); |
| 109 |
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); |
| 110 |
SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result); |
| 111 |
|
| 112 |
/* Enable screensaver and check */ |
| 113 |
SDL_EnableScreenSaver(); |
| 114 |
SDLTest_AssertPass("Call to SDL_EnableScreenSaver()"); |
| 115 |
result = SDL_IsScreenSaverEnabled(); |
| 116 |
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); |
| 117 |
SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result); |
| 118 |
|
| 119 |
} else { |
| 120 |
|
| 121 |
/* Currently disabled: enable first, then disable again */ |
| 122 |
|
| 123 |
/* Enable screensaver and check */ |
| 124 |
SDL_EnableScreenSaver(); |
| 125 |
SDLTest_AssertPass("Call to SDL_EnableScreenSaver()"); |
| 126 |
result = SDL_IsScreenSaverEnabled(); |
| 127 |
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); |
| 128 |
SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result); |
| 129 |
|
| 130 |
/* Disable screensaver and check */ |
| 131 |
SDL_DisableScreenSaver(); |
| 132 |
SDLTest_AssertPass("Call to SDL_DisableScreenSaver()"); |
| 133 |
result = SDL_IsScreenSaverEnabled(); |
| 134 |
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()"); |
| 135 |
SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result); |
| 136 |
} |
| 137 |
|
| 138 |
return TEST_COMPLETED; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* @brief Tests the functionality of the SDL_CreateWindow function using different positions |
| 143 |
*/ |
| 144 |
int video_createWindowVariousPositions(void *arg) |
| 145 |
{ |
| 146 |
SDL_Window *window; |
| 147 |
const char *title = "video_createWindowVariousPositions Test Window"; |
| 148 |
int x, y, w, h; |
| 149 |
int xVariation, yVariation; |
| 150 |
|
| 151 |
for (xVariation = 0; xVariation < 6; xVariation++) { |
| 152 |
for (yVariation = 0; yVariation < 6; yVariation++) { |
| 153 |
switch (xVariation) { |
| 154 |
default: |
| 155 |
case 0: |
| 156 |
/* Zero X Position */ |
| 157 |
x = 0; |
| 158 |
break; |
| 159 |
case 1: |
| 160 |
/* Random X position inside screen */ |
| 161 |
x = SDLTest_RandomIntegerInRange(1, 100); |
| 162 |
break; |
| 163 |
case 2: |
| 164 |
/* Random X position outside screen (positive) */ |
| 165 |
x = SDLTest_RandomIntegerInRange(10000, 11000); |
| 166 |
break; |
| 167 |
case 3: |
| 168 |
/* Random X position outside screen (negative) */ |
| 169 |
x = SDLTest_RandomIntegerInRange(-1000, -100); |
| 170 |
break; |
| 171 |
case 4: |
| 172 |
/* Centered X position */ |
| 173 |
x = SDL_WINDOWPOS_CENTERED; |
| 174 |
break; |
| 175 |
case 5: |
| 176 |
/* Undefined X position */ |
| 177 |
x = SDL_WINDOWPOS_UNDEFINED; |
| 178 |
break; |
| 179 |
} |
| 180 |
|
| 181 |
switch (yVariation) { |
| 182 |
default: |
| 183 |
case 0: |
| 184 |
/* Zero X Position */ |
| 185 |
y = 0; |
| 186 |
break; |
| 187 |
case 1: |
| 188 |
/* Random X position inside screen */ |
| 189 |
y = SDLTest_RandomIntegerInRange(1, 100); |
| 190 |
break; |
| 191 |
case 2: |
| 192 |
/* Random X position outside screen (positive) */ |
| 193 |
y = SDLTest_RandomIntegerInRange(10000, 11000); |
| 194 |
break; |
| 195 |
case 3: |
| 196 |
/* Random Y position outside screen (negative) */ |
| 197 |
y = SDLTest_RandomIntegerInRange(-1000, -100); |
| 198 |
break; |
| 199 |
case 4: |
| 200 |
/* Centered Y position */ |
| 201 |
y = SDL_WINDOWPOS_CENTERED; |
| 202 |
break; |
| 203 |
case 5: |
| 204 |
/* Undefined Y position */ |
| 205 |
y = SDL_WINDOWPOS_UNDEFINED; |
| 206 |
break; |
| 207 |
} |
| 208 |
|
| 209 |
w = SDLTest_RandomIntegerInRange(32, 96); |
| 210 |
h = SDLTest_RandomIntegerInRange(32, 96); |
| 211 |
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); |
| 212 |
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); |
| 213 |
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); |
| 214 |
|
| 215 |
/* Clean up */ |
| 216 |
_destroyVideoSuiteTestWindow(window); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
return TEST_COMPLETED; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* @brief Tests the functionality of the SDL_CreateWindow function using different sizes |
| 225 |
*/ |
| 226 |
int video_createWindowVariousSizes(void *arg) |
| 227 |
{ |
| 228 |
SDL_Window *window; |
| 229 |
const char *title = "video_createWindowVariousSizes Test Window"; |
| 230 |
int x, y, w, h; |
| 231 |
int wVariation, hVariation; |
| 232 |
|
| 233 |
x = SDLTest_RandomIntegerInRange(1, 100); |
| 234 |
y = SDLTest_RandomIntegerInRange(1, 100); |
| 235 |
for (wVariation = 0; wVariation < 3; wVariation++) { |
| 236 |
for (hVariation = 0; hVariation < 3; hVariation++) { |
| 237 |
switch (wVariation) { |
| 238 |
case 0: |
| 239 |
/* Width of 1 */ |
| 240 |
w = 1; |
| 241 |
break; |
| 242 |
case 1: |
| 243 |
/* Random "normal" width */ |
| 244 |
w = SDLTest_RandomIntegerInRange(320, 1920); |
| 245 |
break; |
| 246 |
case 2: |
| 247 |
/* Random "large" width */ |
| 248 |
w = SDLTest_RandomIntegerInRange(2048, 4095); |
| 249 |
break; |
| 250 |
} |
| 251 |
|
| 252 |
switch (hVariation) { |
| 253 |
case 0: |
| 254 |
/* Height of 1 */ |
| 255 |
h = 1; |
| 256 |
break; |
| 257 |
case 1: |
| 258 |
/* Random "normal" height */ |
| 259 |
h = SDLTest_RandomIntegerInRange(320, 1080); |
| 260 |
break; |
| 261 |
case 2: |
| 262 |
/* Random "large" height */ |
| 263 |
h = SDLTest_RandomIntegerInRange(2048, 4095); |
| 264 |
break; |
| 265 |
} |
| 266 |
|
| 267 |
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); |
| 268 |
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); |
| 269 |
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); |
| 270 |
|
| 271 |
/* Clean up */ |
| 272 |
_destroyVideoSuiteTestWindow(window); |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
return TEST_COMPLETED; |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* @brief Tests the functionality of the SDL_CreateWindow function using different flags |
| 281 |
*/ |
| 282 |
int video_createWindowVariousFlags(void *arg) |
| 283 |
{ |
| 284 |
SDL_Window *window; |
| 285 |
const char *title = "video_createWindowVariousFlags Test Window"; |
| 286 |
int x, y, w, h; |
| 287 |
int fVariation; |
| 288 |
SDL_WindowFlags flags; |
| 289 |
|
| 290 |
/* Standard window */ |
| 291 |
x = SDLTest_RandomIntegerInRange(1, 100); |
| 292 |
y = SDLTest_RandomIntegerInRange(1, 100); |
| 293 |
w = SDLTest_RandomIntegerInRange(320, 1024); |
| 294 |
h = SDLTest_RandomIntegerInRange(320, 768); |
| 295 |
|
| 296 |
for (fVariation = 0; fVariation < 14; fVariation++) { |
| 297 |
switch (fVariation) { |
| 298 |
default: |
| 299 |
case 0: |
| 300 |
flags = SDL_WINDOW_FULLSCREEN; |
| 301 |
/* Skip - blanks screen; comment out next line to run test */ |
| 302 |
continue; |
| 303 |
break; |
| 304 |
case 1: |
| 305 |
flags = SDL_WINDOW_FULLSCREEN_DESKTOP; |
| 306 |
/* Skip - blanks screen; comment out next line to run test */ |
| 307 |
continue; |
| 308 |
break; |
| 309 |
case 2: |
| 310 |
flags = SDL_WINDOW_OPENGL; |
| 311 |
/* Skip - not every video driver supports OpenGL; comment out next line to run test */ |
| 312 |
continue; |
| 313 |
break; |
| 314 |
case 3: |
| 315 |
flags = SDL_WINDOW_SHOWN; |
| 316 |
break; |
| 317 |
case 4: |
| 318 |
flags = SDL_WINDOW_HIDDEN; |
| 319 |
break; |
| 320 |
case 5: |
| 321 |
flags = SDL_WINDOW_BORDERLESS; |
| 322 |
break; |
| 323 |
case 6: |
| 324 |
flags = SDL_WINDOW_RESIZABLE; |
| 325 |
break; |
| 326 |
case 7: |
| 327 |
flags = SDL_WINDOW_MINIMIZED; |
| 328 |
break; |
| 329 |
case 8: |
| 330 |
flags = SDL_WINDOW_MAXIMIZED; |
| 331 |
break; |
| 332 |
case 9: |
| 333 |
flags = SDL_WINDOW_MOUSE_GRABBED; |
| 334 |
break; |
| 335 |
case 10: |
| 336 |
flags = SDL_WINDOW_INPUT_FOCUS; |
| 337 |
break; |
| 338 |
case 11: |
| 339 |
flags = SDL_WINDOW_MOUSE_FOCUS; |
| 340 |
break; |
| 341 |
case 12: |
| 342 |
flags = SDL_WINDOW_FOREIGN; |
| 343 |
break; |
| 344 |
case 13: |
| 345 |
flags = SDL_WINDOW_KEYBOARD_GRABBED; |
| 346 |
break; |
| 347 |
} |
| 348 |
|
| 349 |
window = SDL_CreateWindow(title, x, y, w, h, flags); |
| 350 |
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); |
| 351 |
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); |
| 352 |
|
| 353 |
/* Clean up */ |
| 354 |
_destroyVideoSuiteTestWindow(window); |
| 355 |
} |
| 356 |
|
| 357 |
return TEST_COMPLETED; |
| 358 |
} |
| 359 |
|
| 360 |
/** |
| 361 |
* @brief Tests the functionality of the SDL_GetWindowFlags function |
| 362 |
*/ |
| 363 |
int video_getWindowFlags(void *arg) |
| 364 |
{ |
| 365 |
SDL_Window *window; |
| 366 |
const char *title = "video_getWindowFlags Test Window"; |
| 367 |
SDL_WindowFlags flags; |
| 368 |
Uint32 actualFlags; |
| 369 |
|
| 370 |
/* Reliable flag set always set in test window */ |
| 371 |
flags = SDL_WINDOW_SHOWN; |
| 372 |
|
| 373 |
/* Call against new test window */ |
| 374 |
window = _createVideoSuiteTestWindow(title); |
| 375 |
if (window != NULL) { |
| 376 |
actualFlags = SDL_GetWindowFlags(window); |
| 377 |
SDLTest_AssertPass("Call to SDL_GetWindowFlags()"); |
| 378 |
SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %" SDL_PRIu32, flags, actualFlags); |
| 379 |
} |
| 380 |
|
| 381 |
/* Clean up */ |
| 382 |
_destroyVideoSuiteTestWindow(window); |
| 383 |
|
| 384 |
return TEST_COMPLETED; |
| 385 |
} |
| 386 |
|
| 387 |
/** |
| 388 |
* @brief Tests the functionality of the SDL_GetNumDisplayModes function |
| 389 |
*/ |
| 390 |
int video_getNumDisplayModes(void *arg) |
| 391 |
{ |
| 392 |
int result; |
| 393 |
int displayNum; |
| 394 |
int i; |
| 395 |
|
| 396 |
/* Get number of displays */ |
| 397 |
displayNum = SDL_GetNumVideoDisplays(); |
| 398 |
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); |
| 399 |
|
| 400 |
/* Make call for each display */ |
| 401 |
for (i = 0; i < displayNum; i++) { |
| 402 |
result = SDL_GetNumDisplayModes(i); |
| 403 |
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i); |
| 404 |
SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result); |
| 405 |
} |
| 406 |
|
| 407 |
return TEST_COMPLETED; |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* @brief Tests negative call to SDL_GetNumDisplayModes function |
| 412 |
*/ |
| 413 |
int video_getNumDisplayModesNegative(void *arg) |
| 414 |
{ |
| 415 |
int result; |
| 416 |
int displayNum; |
| 417 |
int displayIndex; |
| 418 |
|
| 419 |
/* Get number of displays */ |
| 420 |
displayNum = SDL_GetNumVideoDisplays(); |
| 421 |
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); |
| 422 |
|
| 423 |
/* Invalid boundary values */ |
| 424 |
displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE); |
| 425 |
result = SDL_GetNumDisplayModes(displayIndex); |
| 426 |
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex); |
| 427 |
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); |
| 428 |
|
| 429 |
/* Large (out-of-bounds) display index */ |
| 430 |
displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000); |
| 431 |
result = SDL_GetNumDisplayModes(displayIndex); |
| 432 |
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex); |
| 433 |
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); |
| 434 |
|
| 435 |
displayIndex = SDLTest_RandomIntegerInRange(1000, 2000); |
| 436 |
result = SDL_GetNumDisplayModes(displayIndex); |
| 437 |
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex); |
| 438 |
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); |
| 439 |
|
| 440 |
return TEST_COMPLETED; |
| 441 |
} |
| 442 |
|
| 443 |
/** |
| 444 |
* @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution |
| 445 |
*/ |
| 446 |
int video_getClosestDisplayModeCurrentResolution(void *arg) |
| 447 |
{ |
| 448 |
int result; |
| 449 |
SDL_DisplayMode current; |
| 450 |
SDL_DisplayMode target; |
| 451 |
SDL_DisplayMode closest; |
| 452 |
SDL_DisplayMode *dResult; |
| 453 |
int displayNum; |
| 454 |
int i; |
| 455 |
int variation; |
| 456 |
|
| 457 |
/* Get number of displays */ |
| 458 |
displayNum = SDL_GetNumVideoDisplays(); |
| 459 |
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); |
| 460 |
|
| 461 |
/* Make calls for each display */ |
| 462 |
for (i = 0; i < displayNum; i++) { |
| 463 |
SDLTest_Log("Testing against display: %d", i); |
| 464 |
|
| 465 |
/* Get first display mode to get a sane resolution; this should always work */ |
| 466 |
result = SDL_GetDisplayMode(i, 0, ¤t); |
| 467 |
SDLTest_AssertPass("Call to SDL_GetDisplayMode()"); |
| 468 |
SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result); |
| 469 |
if (result != 0) { |
| 470 |
return TEST_ABORTED; |
| 471 |
} |
| 472 |
|
| 473 |
/* Set the desired resolution equals to current resolution */ |
| 474 |
target.w = current.w; |
| 475 |
target.h = current.h; |
| 476 |
for (variation = 0; variation < 8; variation++) { |
| 477 |
/* Vary constraints on other query parameters */ |
| 478 |
target.format = (variation & 1) ? current.format : 0; |
| 479 |
target.refresh_rate = (variation & 2) ? current.refresh_rate : 0; |
| 480 |
target.driverdata = (variation & 4) ? current.driverdata : 0; |
| 481 |
|
| 482 |
/* Make call */ |
| 483 |
dResult = SDL_GetClosestDisplayMode(i, &target, &closest); |
| 484 |
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation); |
| 485 |
SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL"); |
| 486 |
|
| 487 |
/* Check that one gets the current resolution back again */ |
| 488 |
SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w); |
| 489 |
SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h); |
| 490 |
/* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */ |
| 491 |
SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w); |
| 492 |
SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h); |
| 493 |
/* NOLINTEND(clang-analyzer-core.NullDereference) */ |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
return TEST_COMPLETED; |
| 498 |
} |
| 499 |
|
| 500 |
/** |
| 501 |
* @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution |
| 502 |
*/ |
| 503 |
int video_getClosestDisplayModeRandomResolution(void *arg) |
| 504 |
{ |
| 505 |
SDL_DisplayMode target; |
| 506 |
SDL_DisplayMode closest; |
| 507 |
int displayNum; |
| 508 |
int i; |
| 509 |
int variation; |
| 510 |
|
| 511 |
/* Get number of displays */ |
| 512 |
displayNum = SDL_GetNumVideoDisplays(); |
| 513 |
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); |
| 514 |
|
| 515 |
/* Make calls for each display */ |
| 516 |
for (i = 0; i < displayNum; i++) { |
| 517 |
SDLTest_Log("Testing against display: %d", i); |
| 518 |
|
| 519 |
for (variation = 0; variation < 16; variation++) { |
| 520 |
|
| 521 |
/* Set random constraints */ |
| 522 |
target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; |
| 523 |
target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; |
| 524 |
target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0; |
| 525 |
target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0; |
| 526 |
target.driverdata = 0; |
| 527 |
|
| 528 |
/* Make call; may or may not find anything, so don't validate any further */ |
| 529 |
SDL_GetClosestDisplayMode(i, &target, &closest); |
| 530 |
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation); |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
return TEST_COMPLETED; |
| 535 |
} |
| 536 |
|
| 537 |
/** |
| 538 |
* @brief Tests call to SDL_GetWindowBrightness |
| 539 |
* |
| 540 |
* @sa http://wiki.libsdl.org/SDL_GetWindowBrightness |
| 541 |
*/ |
| 542 |
int |
| 543 |
video_getWindowBrightness(void *arg) |
| 544 |
{ |
| 545 |
SDL_Window* window; |
| 546 |
const char* title = "video_getWindowBrightness Test Window"; |
| 547 |
float result; |
| 548 |
|
| 549 |
/* Call against new test window */ |
| 550 |
window = _createVideoSuiteTestWindow(title); |
| 551 |
if (window != NULL) { |
| 552 |
result = SDL_GetWindowBrightness(window); |
| 553 |
SDLTest_AssertPass("Call to SDL_GetWindowBrightness()"); |
| 554 |
SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result); |
| 555 |
} |
| 556 |
|
| 557 |
/* Clean up */ |
| 558 |
_destroyVideoSuiteTestWindow(window); |
| 559 |
|
| 560 |
return TEST_COMPLETED; |
| 561 |
} |
| 562 |
|
| 563 |
/** |
| 564 |
* @brief Tests call to SDL_GetWindowBrightness with invalid input |
| 565 |
* |
| 566 |
* @sa http://wiki.libsdl.org/SDL_GetWindowBrightness |
| 567 |
*/ |
| 568 |
int |
| 569 |
video_getWindowBrightnessNegative(void *arg) |
| 570 |
{ |
| 571 |
const char *invalidWindowError = "Invalid window"; |
| 572 |
char *lastError; |
| 573 |
float result; |
| 574 |
|
| 575 |
/* Call against invalid window */ |
| 576 |
result = SDL_GetWindowBrightness(NULL); |
| 577 |
SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)"); |
| 578 |
SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result); |
| 579 |
lastError = (char *)SDL_GetError(); |
| 580 |
SDLTest_AssertPass("SDL_GetError()"); |
| 581 |
SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); |
| 582 |
if (lastError != NULL) { |
| 583 |
SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, |
| 584 |
"SDL_GetError(): expected message '%s', was message: '%s'", |
| 585 |
invalidWindowError, |
| 586 |
lastError); |
| 587 |
} |
| 588 |
|
| 589 |
return TEST_COMPLETED; |
| 590 |
} |
| 591 |
|
| 592 |
/** |
| 593 |
* @brief Tests call to SDL_GetWindowDisplayMode |
| 594 |
* |
| 595 |
* @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode |
| 596 |
*/ |
| 597 |
int video_getWindowDisplayMode(void *arg) |
| 598 |
{ |
| 599 |
SDL_Window *window; |
| 600 |
const char *title = "video_getWindowDisplayMode Test Window"; |
| 601 |
SDL_DisplayMode mode; |
| 602 |
int result; |
| 603 |
|
| 604 |
/* Invalidate part of the mode content so we can check values later */ |
| 605 |
mode.w = -1; |
| 606 |
mode.h = -1; |
| 607 |
mode.refresh_rate = -1; |
| 608 |
|
| 609 |
/* Call against new test window */ |
| 610 |
window = _createVideoSuiteTestWindow(title); |
| 611 |
if (window) { |
| 612 |
result = SDL_GetWindowDisplayMode(window, &mode); |
| 613 |
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()"); |
| 614 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 615 |
SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w); |
| 616 |
SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h); |
| 617 |
SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate); |
| 618 |
} |
| 619 |
|
| 620 |
/* Clean up */ |
| 621 |
_destroyVideoSuiteTestWindow(window); |
| 622 |
|
| 623 |
return TEST_COMPLETED; |
| 624 |
} |
| 625 |
|
| 626 |
/* Helper function that checks for an 'Invalid window' error */ |
| 627 |
void _checkInvalidWindowError(void) |
| 628 |
{ |
| 629 |
const char *invalidWindowError = "Invalid window"; |
| 630 |
char *lastError; |
| 631 |
|
| 632 |
lastError = (char *)SDL_GetError(); |
| 633 |
SDLTest_AssertPass("SDL_GetError()"); |
| 634 |
SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); |
| 635 |
if (lastError != NULL) { |
| 636 |
SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0, |
| 637 |
"SDL_GetError(): expected message '%s', was message: '%s'", |
| 638 |
invalidWindowError, |
| 639 |
lastError); |
| 640 |
SDL_ClearError(); |
| 641 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
/** |
| 646 |
* @brief Tests call to SDL_GetWindowDisplayMode with invalid input |
| 647 |
* |
| 648 |
* @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode |
| 649 |
*/ |
| 650 |
int video_getWindowDisplayModeNegative(void *arg) |
| 651 |
{ |
| 652 |
const char *expectedError = "Parameter 'mode' is invalid"; |
| 653 |
char *lastError; |
| 654 |
SDL_Window *window; |
| 655 |
const char *title = "video_getWindowDisplayModeNegative Test Window"; |
| 656 |
SDL_DisplayMode mode; |
| 657 |
int result; |
| 658 |
|
| 659 |
/* Call against new test window */ |
| 660 |
window = _createVideoSuiteTestWindow(title); |
| 661 |
if (window != NULL) { |
| 662 |
result = SDL_GetWindowDisplayMode(window, NULL); |
| 663 |
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)"); |
| 664 |
SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result); |
| 665 |
lastError = (char *)SDL_GetError(); |
| 666 |
SDLTest_AssertPass("SDL_GetError()"); |
| 667 |
SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); |
| 668 |
if (lastError != NULL) { |
| 669 |
SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0, |
| 670 |
"SDL_GetError(): expected message '%s', was message: '%s'", |
| 671 |
expectedError, |
| 672 |
lastError); |
| 673 |
} |
| 674 |
} |
| 675 |
|
| 676 |
/* Clean up */ |
| 677 |
_destroyVideoSuiteTestWindow(window); |
| 678 |
|
| 679 |
/* Call against invalid window */ |
| 680 |
result = SDL_GetWindowDisplayMode(NULL, &mode); |
| 681 |
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)"); |
| 682 |
SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result); |
| 683 |
_checkInvalidWindowError(); |
| 684 |
|
| 685 |
return TEST_COMPLETED; |
| 686 |
} |
| 687 |
|
| 688 |
/** |
| 689 |
* @brief Tests call to SDL_GetWindowGammaRamp |
| 690 |
* |
| 691 |
* @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp |
| 692 |
*/ |
| 693 |
int |
| 694 |
video_getWindowGammaRamp(void *arg) |
| 695 |
{ |
| 696 |
SDL_Window* window; |
| 697 |
const char* title = "video_getWindowGammaRamp Test Window"; |
| 698 |
Uint16 red[256]; |
| 699 |
Uint16 green[256]; |
| 700 |
Uint16 blue[256]; |
| 701 |
int result; |
| 702 |
|
| 703 |
/* Call against new test window */ |
| 704 |
window = _createVideoSuiteTestWindow(title); |
| 705 |
if (!window) return TEST_ABORTED; |
| 706 |
|
| 707 |
/* Retrieve no channel */ |
| 708 |
result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL); |
| 709 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)"); |
| 710 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 711 |
|
| 712 |
/* Retrieve single channel */ |
| 713 |
result = SDL_GetWindowGammaRamp(window, red, NULL, NULL); |
| 714 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)"); |
| 715 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 716 |
|
| 717 |
result = SDL_GetWindowGammaRamp(window, NULL, green, NULL); |
| 718 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)"); |
| 719 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 720 |
|
| 721 |
result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue); |
| 722 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)"); |
| 723 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 724 |
|
| 725 |
/* Retrieve two channels */ |
| 726 |
result = SDL_GetWindowGammaRamp(window, red, green, NULL); |
| 727 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)"); |
| 728 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 729 |
|
| 730 |
result = SDL_GetWindowGammaRamp(window, NULL, green, blue); |
| 731 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)"); |
| 732 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 733 |
|
| 734 |
result = SDL_GetWindowGammaRamp(window, red, NULL, blue); |
| 735 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)"); |
| 736 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 737 |
|
| 738 |
/* Retrieve all channels */ |
| 739 |
result = SDL_GetWindowGammaRamp(window, red, green, blue); |
| 740 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)"); |
| 741 |
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result); |
| 742 |
|
| 743 |
/* Clean up */ |
| 744 |
_destroyVideoSuiteTestWindow(window); |
| 745 |
|
| 746 |
return TEST_COMPLETED; |
| 747 |
} |
| 748 |
|
| 749 |
/** |
| 750 |
* @brief Tests call to SDL_GetWindowGammaRamp with invalid input |
| 751 |
* |
| 752 |
* @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp |
| 753 |
*/ |
| 754 |
int |
| 755 |
video_getWindowGammaRampNegative(void *arg) |
| 756 |
{ |
| 757 |
Uint16 red[256]; |
| 758 |
Uint16 green[256]; |
| 759 |
Uint16 blue[256]; |
| 760 |
int result; |
| 761 |
|
| 762 |
SDL_ClearError(); |
| 763 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 764 |
|
| 765 |
/* Call against invalid window */ |
| 766 |
result = SDL_GetWindowGammaRamp(NULL, red, green, blue); |
| 767 |
SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)"); |
| 768 |
SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %i", result); |
| 769 |
_checkInvalidWindowError(); |
| 770 |
|
| 771 |
return TEST_COMPLETED; |
| 772 |
} |
| 773 |
|
| 774 |
/* Helper for setting and checking the window mouse grab state */ |
| 775 |
void _setAndCheckWindowMouseGrabState(SDL_Window *window, SDL_bool desiredState) |
| 776 |
{ |
| 777 |
SDL_bool currentState; |
| 778 |
|
| 779 |
/* Set state */ |
| 780 |
SDL_SetWindowMouseGrab(window, desiredState); |
| 781 |
SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); |
| 782 |
|
| 783 |
/* Get and check state */ |
| 784 |
currentState = SDL_GetWindowMouseGrab(window); |
| 785 |
SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()"); |
| 786 |
SDLTest_AssertCheck( |
| 787 |
currentState == desiredState, |
| 788 |
"Validate returned state; expected: %s, got: %s", |
| 789 |
(desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE", |
| 790 |
(currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); |
| 791 |
|
| 792 |
if (desiredState) { |
| 793 |
SDLTest_AssertCheck( |
| 794 |
SDL_GetGrabbedWindow() == window, |
| 795 |
"Grabbed window should be to our window"); |
| 796 |
SDLTest_AssertCheck( |
| 797 |
SDL_GetWindowGrab(window), |
| 798 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 799 |
SDLTest_AssertCheck( |
| 800 |
SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED, |
| 801 |
"SDL_WINDOW_MOUSE_GRABBED should be set"); |
| 802 |
} else { |
| 803 |
SDLTest_AssertCheck( |
| 804 |
!(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED), |
| 805 |
"SDL_WINDOW_MOUSE_GRABBED should be unset"); |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
/* Helper for setting and checking the window keyboard grab state */ |
| 810 |
void _setAndCheckWindowKeyboardGrabState(SDL_Window *window, SDL_bool desiredState) |
| 811 |
{ |
| 812 |
SDL_bool currentState; |
| 813 |
|
| 814 |
/* Set state */ |
| 815 |
SDL_SetWindowKeyboardGrab(window, desiredState); |
| 816 |
SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); |
| 817 |
|
| 818 |
/* Get and check state */ |
| 819 |
currentState = SDL_GetWindowKeyboardGrab(window); |
| 820 |
SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()"); |
| 821 |
SDLTest_AssertCheck( |
| 822 |
currentState == desiredState, |
| 823 |
"Validate returned state; expected: %s, got: %s", |
| 824 |
(desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE", |
| 825 |
(currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE"); |
| 826 |
|
| 827 |
if (desiredState) { |
| 828 |
SDLTest_AssertCheck( |
| 829 |
SDL_GetGrabbedWindow() == window, |
| 830 |
"Grabbed window should be set to our window"); |
| 831 |
SDLTest_AssertCheck( |
| 832 |
SDL_GetWindowGrab(window), |
| 833 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 834 |
SDLTest_AssertCheck( |
| 835 |
SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED, |
| 836 |
"SDL_WINDOW_KEYBOARD_GRABBED should be set"); |
| 837 |
} else { |
| 838 |
SDLTest_AssertCheck( |
| 839 |
!(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED), |
| 840 |
"SDL_WINDOW_KEYBOARD_GRABBED should be unset"); |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
/** |
| 845 |
* @brief Tests keyboard and mouse grab support |
| 846 |
* |
| 847 |
* @sa http://wiki.libsdl.org/SDL_GetWindowGrab |
| 848 |
* @sa http://wiki.libsdl.org/SDL_SetWindowGrab |
| 849 |
*/ |
| 850 |
int video_getSetWindowGrab(void *arg) |
| 851 |
{ |
| 852 |
const char *title = "video_getSetWindowGrab Test Window"; |
| 853 |
SDL_Window *window; |
| 854 |
SDL_bool originalMouseState, originalKeyboardState; |
| 855 |
SDL_bool hasFocusGained = SDL_FALSE; |
| 856 |
|
| 857 |
/* Call against new test window */ |
| 858 |
window = _createVideoSuiteTestWindow(title); |
| 859 |
if (!window) { |
| 860 |
return TEST_ABORTED; |
| 861 |
} |
| 862 |
|
| 863 |
/* Need to raise the window to have and SDL_EVENT_WINDOW_FOCUS_GAINED, |
| 864 |
* so that the window gets the flags SDL_WINDOW_INPUT_FOCUS, |
| 865 |
* so that it can be "grabbed" */ |
| 866 |
SDL_RaiseWindow(window); |
| 867 |
|
| 868 |
{ |
| 869 |
SDL_Event evt; |
| 870 |
SDL_zero(evt); |
| 871 |
while (SDL_PollEvent(&evt)) { |
| 872 |
if (evt.type == SDL_WINDOWEVENT) { |
| 873 |
if (evt.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { |
| 874 |
hasFocusGained = SDL_TRUE; |
| 875 |
} |
| 876 |
} |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
SDLTest_AssertCheck(hasFocusGained == SDL_TRUE, "Expected window with focus"); |
| 881 |
|
| 882 |
/* Get state */ |
| 883 |
originalMouseState = SDL_GetWindowMouseGrab(window); |
| 884 |
SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()"); |
| 885 |
originalKeyboardState = SDL_GetWindowKeyboardGrab(window); |
| 886 |
SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()"); |
| 887 |
|
| 888 |
/* F */ |
| 889 |
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE); |
| 890 |
_setAndCheckWindowMouseGrabState(window, SDL_FALSE); |
| 891 |
SDLTest_AssertCheck(!SDL_GetWindowGrab(window), |
| 892 |
"SDL_GetWindowGrab should return SDL_FALSE"); |
| 893 |
SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL, |
| 894 |
"Expected NULL grabbed window"); |
| 895 |
|
| 896 |
/* F --> F */ |
| 897 |
_setAndCheckWindowMouseGrabState(window, SDL_FALSE); |
| 898 |
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE); |
| 899 |
SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL, |
| 900 |
"Expected NULL grabbed window"); |
| 901 |
|
| 902 |
/* F --> T */ |
| 903 |
_setAndCheckWindowMouseGrabState(window, SDL_TRUE); |
| 904 |
_setAndCheckWindowKeyboardGrabState(window, SDL_TRUE); |
| 905 |
SDLTest_AssertCheck(SDL_GetWindowGrab(window), |
| 906 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 907 |
|
| 908 |
/* T --> T */ |
| 909 |
_setAndCheckWindowKeyboardGrabState(window, SDL_TRUE); |
| 910 |
_setAndCheckWindowMouseGrabState(window, SDL_TRUE); |
| 911 |
SDLTest_AssertCheck(SDL_GetWindowGrab(window), |
| 912 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 913 |
|
| 914 |
/* M: T --> F */ |
| 915 |
/* K: T --> T */ |
| 916 |
_setAndCheckWindowKeyboardGrabState(window, SDL_TRUE); |
| 917 |
_setAndCheckWindowMouseGrabState(window, SDL_FALSE); |
| 918 |
SDLTest_AssertCheck(SDL_GetWindowGrab(window), |
| 919 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 920 |
|
| 921 |
/* M: F --> T */ |
| 922 |
/* K: T --> F */ |
| 923 |
_setAndCheckWindowMouseGrabState(window, SDL_TRUE); |
| 924 |
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE); |
| 925 |
SDLTest_AssertCheck(SDL_GetWindowGrab(window), |
| 926 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 927 |
|
| 928 |
/* M: T --> F */ |
| 929 |
/* K: F --> F */ |
| 930 |
_setAndCheckWindowMouseGrabState(window, SDL_FALSE); |
| 931 |
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE); |
| 932 |
SDLTest_AssertCheck(!SDL_GetWindowGrab(window), |
| 933 |
"SDL_GetWindowGrab() should return SDL_FALSE"); |
| 934 |
SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL, |
| 935 |
"Expected NULL grabbed window"); |
| 936 |
|
| 937 |
/* Using the older SDL_SetWindowGrab API should only grab mouse by default */ |
| 938 |
SDL_SetWindowGrab(window, SDL_TRUE); |
| 939 |
SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)"); |
| 940 |
SDLTest_AssertCheck(SDL_GetWindowGrab(window), |
| 941 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 942 |
SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window), |
| 943 |
"SDL_GetWindowMouseGrab() should return SDL_TRUE"); |
| 944 |
SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window), |
| 945 |
"SDL_GetWindowKeyboardGrab() should return SDL_FALSE"); |
| 946 |
SDL_SetWindowGrab(window, SDL_FALSE); |
| 947 |
SDLTest_AssertCheck(!SDL_GetWindowGrab(window), |
| 948 |
"SDL_GetWindowGrab() should return SDL_FALSE"); |
| 949 |
SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window), |
| 950 |
"SDL_GetWindowMouseGrab() should return SDL_FALSE"); |
| 951 |
SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window), |
| 952 |
"SDL_GetWindowKeyboardGrab() should return SDL_FALSE"); |
| 953 |
|
| 954 |
/* Now test with SDL_HINT_GRAB_KEYBOARD set. We should get keyboard grab now. */ |
| 955 |
SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1"); |
| 956 |
SDL_SetWindowGrab(window, SDL_TRUE); |
| 957 |
SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)"); |
| 958 |
SDLTest_AssertCheck(SDL_GetWindowGrab(window), |
| 959 |
"SDL_GetWindowGrab() should return SDL_TRUE"); |
| 960 |
SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window), |
| 961 |
"SDL_GetWindowMouseGrab() should return SDL_TRUE"); |
| 962 |
SDLTest_AssertCheck(SDL_GetWindowKeyboardGrab(window), |
| 963 |
"SDL_GetWindowKeyboardGrab() should return SDL_TRUE"); |
| 964 |
SDL_SetWindowGrab(window, SDL_FALSE); |
| 965 |
SDLTest_AssertCheck(!SDL_GetWindowGrab(window), |
| 966 |
"SDL_GetWindowGrab() should return SDL_FALSE"); |
| 967 |
SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window), |
| 968 |
"SDL_GetWindowMouseGrab() should return SDL_FALSE"); |
| 969 |
SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window), |
| 970 |
"SDL_GetWindowKeyboardGrab() should return SDL_FALSE"); |
| 971 |
|
| 972 |
/* Negative tests */ |
| 973 |
SDL_GetWindowGrab(NULL); |
| 974 |
SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)"); |
| 975 |
_checkInvalidWindowError(); |
| 976 |
|
| 977 |
SDL_GetWindowKeyboardGrab(NULL); |
| 978 |
SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)"); |
| 979 |
_checkInvalidWindowError(); |
| 980 |
|
| 981 |
SDL_SetWindowGrab(NULL, SDL_FALSE); |
| 982 |
SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)"); |
| 983 |
_checkInvalidWindowError(); |
| 984 |
|
| 985 |
SDL_SetWindowKeyboardGrab(NULL, SDL_FALSE); |
| 986 |
SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE)"); |
| 987 |
_checkInvalidWindowError(); |
| 988 |
|
| 989 |
SDL_SetWindowGrab(NULL, SDL_TRUE); |
| 990 |
SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_TRUE)"); |
| 991 |
_checkInvalidWindowError(); |
| 992 |
|
| 993 |
SDL_SetWindowKeyboardGrab(NULL, SDL_TRUE); |
| 994 |
SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE)"); |
| 995 |
_checkInvalidWindowError(); |
| 996 |
|
| 997 |
/* Restore state */ |
| 998 |
_setAndCheckWindowMouseGrabState(window, originalMouseState); |
| 999 |
_setAndCheckWindowKeyboardGrabState(window, originalKeyboardState); |
| 1000 |
|
| 1001 |
/* Clean up */ |
| 1002 |
_destroyVideoSuiteTestWindow(window); |
| 1003 |
|
| 1004 |
return TEST_COMPLETED; |
| 1005 |
} |
| 1006 |
|
| 1007 |
/** |
| 1008 |
* @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID |
| 1009 |
* |
| 1010 |
* @sa http://wiki.libsdl.org/SDL_GetWindowID |
| 1011 |
* @sa http://wiki.libsdl.org/SDL_SetWindowFromID |
| 1012 |
*/ |
| 1013 |
int video_getWindowId(void *arg) |
| 1014 |
{ |
| 1015 |
const char *title = "video_getWindowId Test Window"; |
| 1016 |
SDL_Window *window; |
| 1017 |
SDL_Window *result; |
| 1018 |
Uint32 id, randomId; |
| 1019 |
|
| 1020 |
/* Call against new test window */ |
| 1021 |
window = _createVideoSuiteTestWindow(title); |
| 1022 |
if (!window) { |
| 1023 |
return TEST_ABORTED; |
| 1024 |
} |
| 1025 |
|
| 1026 |
/* Get ID */ |
| 1027 |
id = SDL_GetWindowID(window); |
| 1028 |
SDLTest_AssertPass("Call to SDL_GetWindowID()"); |
| 1029 |
|
| 1030 |
/* Get window from ID */ |
| 1031 |
result = SDL_GetWindowFromID(id); |
| 1032 |
SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 ")", id); |
| 1033 |
SDLTest_AssertCheck(result == window, "Verify result matches window pointer"); |
| 1034 |
|
| 1035 |
/* Get window from random large ID, no result check */ |
| 1036 |
randomId = SDLTest_RandomIntegerInRange(UINT8_MAX, UINT16_MAX); |
| 1037 |
result = SDL_GetWindowFromID(randomId); |
| 1038 |
SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/random_large)", randomId); |
| 1039 |
|
| 1040 |
/* Get window from 0 and Uint32 max ID, no result check */ |
| 1041 |
result = SDL_GetWindowFromID(0); |
| 1042 |
SDLTest_AssertPass("Call to SDL_GetWindowID(0)"); |
| 1043 |
result = SDL_GetWindowFromID(UINT32_MAX); |
| 1044 |
SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)"); |
| 1045 |
|
| 1046 |
/* Clean up */ |
| 1047 |
_destroyVideoSuiteTestWindow(window); |
| 1048 |
|
| 1049 |
/* Get window from ID for closed window */ |
| 1050 |
result = SDL_GetWindowFromID(id); |
| 1051 |
SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/closed_window)", id); |
| 1052 |
SDLTest_AssertCheck(result == NULL, "Verify result is NULL"); |
| 1053 |
|
| 1054 |
/* Negative test */ |
| 1055 |
SDL_ClearError(); |
| 1056 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1057 |
id = SDL_GetWindowID(NULL); |
| 1058 |
SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)"); |
| 1059 |
_checkInvalidWindowError(); |
| 1060 |
|
| 1061 |
return TEST_COMPLETED; |
| 1062 |
} |
| 1063 |
|
| 1064 |
/** |
| 1065 |
* @brief Tests call to SDL_GetWindowPixelFormat |
| 1066 |
* |
| 1067 |
* @sa http://wiki.libsdl.org/SDL_GetWindowPixelFormat |
| 1068 |
*/ |
| 1069 |
int video_getWindowPixelFormat(void *arg) |
| 1070 |
{ |
| 1071 |
const char *title = "video_getWindowPixelFormat Test Window"; |
| 1072 |
SDL_Window *window; |
| 1073 |
Uint32 format; |
| 1074 |
|
| 1075 |
/* Call against new test window */ |
| 1076 |
window = _createVideoSuiteTestWindow(title); |
| 1077 |
if (!window) { |
| 1078 |
return TEST_ABORTED; |
| 1079 |
} |
| 1080 |
|
| 1081 |
/* Get format */ |
| 1082 |
format = SDL_GetWindowPixelFormat(window); |
| 1083 |
SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()"); |
| 1084 |
SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %" SDL_PRIu32, SDL_PIXELFORMAT_UNKNOWN, format); |
| 1085 |
|
| 1086 |
/* Clean up */ |
| 1087 |
_destroyVideoSuiteTestWindow(window); |
| 1088 |
|
| 1089 |
/* Negative test */ |
| 1090 |
SDL_ClearError(); |
| 1091 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1092 |
format = SDL_GetWindowPixelFormat(NULL); |
| 1093 |
SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)"); |
| 1094 |
_checkInvalidWindowError(); |
| 1095 |
|
| 1096 |
return TEST_COMPLETED; |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
static SDL_bool getPositionFromEvent(int *x, int *y) |
| 1101 |
{ |
| 1102 |
SDL_bool ret = SDL_FALSE; |
| 1103 |
SDL_Event evt; |
| 1104 |
SDL_zero(evt); |
| 1105 |
while (SDL_PollEvent(&evt)) { |
| 1106 |
if (evt.type == SDL_WINDOWEVENT && evt.window.event == SDL_WINDOWEVENT_MOVED) { |
| 1107 |
*x = evt.window.data1; |
| 1108 |
*y = evt.window.data2; |
| 1109 |
ret = SDL_TRUE; |
| 1110 |
} |
| 1111 |
} |
| 1112 |
return ret; |
| 1113 |
} |
| 1114 |
|
| 1115 |
static SDL_bool getSizeFromEvent(int *w, int *h) |
| 1116 |
{ |
| 1117 |
SDL_bool ret = SDL_FALSE; |
| 1118 |
SDL_Event evt; |
| 1119 |
SDL_zero(evt); |
| 1120 |
while (SDL_PollEvent(&evt)) { |
| 1121 |
if (evt.type == SDL_WINDOWEVENT && evt.window.event == SDL_WINDOWEVENT_RESIZED) { |
| 1122 |
*w = evt.window.data1; |
| 1123 |
*h = evt.window.data2; |
| 1124 |
ret = SDL_TRUE; |
| 1125 |
} |
| 1126 |
} |
| 1127 |
return ret; |
| 1128 |
} |
| 1129 |
|
| 1130 |
/** |
| 1131 |
* @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition |
| 1132 |
* |
| 1133 |
* @sa http://wiki.libsdl.org/SDL_GetWindowPosition |
| 1134 |
* @sa http://wiki.libsdl.org/SDL_SetWindowPosition |
| 1135 |
*/ |
| 1136 |
int video_getSetWindowPosition(void *arg) |
| 1137 |
{ |
| 1138 |
const char *title = "video_getSetWindowPosition Test Window"; |
| 1139 |
SDL_Window *window; |
| 1140 |
int maxxVariation, maxyVariation; |
| 1141 |
int xVariation, yVariation; |
| 1142 |
int referenceX, referenceY; |
| 1143 |
int currentX, currentY; |
| 1144 |
int desiredX, desiredY; |
| 1145 |
SDL_Rect display_bounds; |
| 1146 |
|
| 1147 |
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) { |
| 1148 |
SDLTest_Log("Skipping test: wayland does not support window positioning"); |
| 1149 |
return TEST_SKIPPED; |
| 1150 |
} |
| 1151 |
|
| 1152 |
/* Call against new test window */ |
| 1153 |
window = _createVideoSuiteTestWindow(title); |
| 1154 |
if (!window) { |
| 1155 |
return TEST_ABORTED; |
| 1156 |
} |
| 1157 |
|
| 1158 |
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { |
| 1159 |
/* The X11 server allows arbitrary window placement, but compositing |
| 1160 |
* window managers such as GNOME and KDE force windows to be within |
| 1161 |
* desktop bounds. |
| 1162 |
*/ |
| 1163 |
maxxVariation = 2; |
| 1164 |
maxyVariation = 2; |
| 1165 |
|
| 1166 |
SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(window), &display_bounds); |
| 1167 |
} else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "cocoa") == 0) { |
| 1168 |
/* Platform doesn't allow windows with negative Y desktop bounds */ |
| 1169 |
maxxVariation = 4; |
| 1170 |
maxyVariation = 3; |
| 1171 |
|
| 1172 |
SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(window), &display_bounds); |
| 1173 |
} else { |
| 1174 |
/* Platform allows windows to be placed out of bounds */ |
| 1175 |
maxxVariation = 4; |
| 1176 |
maxyVariation = 4; |
| 1177 |
|
| 1178 |
SDL_GetDisplayBounds(SDL_GetWindowDisplayIndex(window), &display_bounds); |
| 1179 |
} |
| 1180 |
|
| 1181 |
for (xVariation = 0; xVariation < maxxVariation; xVariation++) { |
| 1182 |
for (yVariation = 0; yVariation < maxyVariation; yVariation++) { |
| 1183 |
switch (xVariation) { |
| 1184 |
default: |
| 1185 |
case 0: |
| 1186 |
/* Zero X Position */ |
| 1187 |
desiredX = display_bounds.x > 0 ? display_bounds.x : 0; |
| 1188 |
break; |
| 1189 |
case 1: |
| 1190 |
/* Random X position inside screen */ |
| 1191 |
desiredX = SDLTest_RandomIntegerInRange(display_bounds.x + 1, display_bounds.x + 100); |
| 1192 |
break; |
| 1193 |
case 2: |
| 1194 |
/* Random X position outside screen (positive) */ |
| 1195 |
desiredX = SDLTest_RandomIntegerInRange(10000, 11000); |
| 1196 |
break; |
| 1197 |
case 3: |
| 1198 |
/* Random X position outside screen (negative) */ |
| 1199 |
desiredX = SDLTest_RandomIntegerInRange(-1000, -100); |
| 1200 |
break; |
| 1201 |
} |
| 1202 |
|
| 1203 |
switch (yVariation) { |
| 1204 |
default: |
| 1205 |
case 0: |
| 1206 |
/* Zero Y Position */ |
| 1207 |
desiredY = display_bounds.y > 0 ? display_bounds.y : 0; |
| 1208 |
break; |
| 1209 |
case 1: |
| 1210 |
/* Random Y position inside screen */ |
| 1211 |
desiredY = SDLTest_RandomIntegerInRange(display_bounds.y + 1, display_bounds.y + 100); |
| 1212 |
break; |
| 1213 |
case 2: |
| 1214 |
/* Random Y position outside screen (positive) */ |
| 1215 |
desiredY = SDLTest_RandomIntegerInRange(10000, 11000); |
| 1216 |
break; |
| 1217 |
case 3: |
| 1218 |
/* Random Y position outside screen (negative) */ |
| 1219 |
desiredY = SDLTest_RandomIntegerInRange(-1000, -100); |
| 1220 |
break; |
| 1221 |
} |
| 1222 |
|
| 1223 |
/* Set position */ |
| 1224 |
SDL_SetWindowPosition(window, desiredX, desiredY); |
| 1225 |
SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY); |
| 1226 |
|
| 1227 |
/* Get position */ |
| 1228 |
currentX = desiredX + 1; |
| 1229 |
currentY = desiredY + 1; |
| 1230 |
SDL_GetWindowPosition(window, ¤tX, ¤tY); |
| 1231 |
SDLTest_AssertPass("Call to SDL_GetWindowPosition()"); |
| 1232 |
|
| 1233 |
if (desiredX == currentX && desiredY == currentY) { |
| 1234 |
SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); |
| 1235 |
SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); |
| 1236 |
} else { |
| 1237 |
SDL_bool hasEvent; |
| 1238 |
/* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size, |
| 1239 |
* and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */ |
| 1240 |
desiredX = currentX + 1; |
| 1241 |
desiredY = currentY + 1; |
| 1242 |
hasEvent = getPositionFromEvent(&desiredX, &desiredY); |
| 1243 |
SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing position was not honored by WM, checking present of SDL_WINDOWEVENT_MOVED"); |
| 1244 |
if (hasEvent) { |
| 1245 |
SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position is the position from SDL event; expected: %d, got: %d", desiredX, currentX); |
| 1246 |
SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position is the position from SDL event; expected: %d, got: %d", desiredY, currentY); |
| 1247 |
} |
| 1248 |
} |
| 1249 |
|
| 1250 |
/* Get position X */ |
| 1251 |
currentX = desiredX + 1; |
| 1252 |
SDL_GetWindowPosition(window, ¤tX, NULL); |
| 1253 |
SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)"); |
| 1254 |
SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX); |
| 1255 |
|
| 1256 |
/* Get position Y */ |
| 1257 |
currentY = desiredY + 1; |
| 1258 |
SDL_GetWindowPosition(window, NULL, ¤tY); |
| 1259 |
SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)"); |
| 1260 |
SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY); |
| 1261 |
} |
| 1262 |
} |
| 1263 |
|
| 1264 |
/* Dummy call with both pointers NULL */ |
| 1265 |
SDL_GetWindowPosition(window, NULL, NULL); |
| 1266 |
SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)"); |
| 1267 |
|
| 1268 |
/* Clean up */ |
| 1269 |
_destroyVideoSuiteTestWindow(window); |
| 1270 |
|
| 1271 |
/* Set some 'magic' value for later check that nothing was changed */ |
| 1272 |
referenceX = SDLTest_RandomSint32(); |
| 1273 |
referenceY = SDLTest_RandomSint32(); |
| 1274 |
currentX = referenceX; |
| 1275 |
currentY = referenceY; |
| 1276 |
desiredX = SDLTest_RandomSint32(); |
| 1277 |
desiredY = SDLTest_RandomSint32(); |
| 1278 |
|
| 1279 |
/* Negative tests */ |
| 1280 |
SDL_ClearError(); |
| 1281 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1282 |
SDL_GetWindowPosition(NULL, ¤tX, ¤tY); |
| 1283 |
SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)"); |
| 1284 |
SDLTest_AssertCheck( |
| 1285 |
currentX == referenceX && currentY == referenceY, |
| 1286 |
"Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d", |
| 1287 |
referenceX, referenceY, |
| 1288 |
currentX, currentY); |
| 1289 |
_checkInvalidWindowError(); |
| 1290 |
|
| 1291 |
SDL_GetWindowPosition(NULL, NULL, NULL); |
| 1292 |
SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)"); |
| 1293 |
_checkInvalidWindowError(); |
| 1294 |
|
| 1295 |
SDL_SetWindowPosition(NULL, desiredX, desiredY); |
| 1296 |
SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)"); |
| 1297 |
_checkInvalidWindowError(); |
| 1298 |
|
| 1299 |
return TEST_COMPLETED; |
| 1300 |
} |
| 1301 |
|
| 1302 |
/* Helper function that checks for an 'Invalid parameter' error */ |
| 1303 |
void _checkInvalidParameterError(void) |
| 1304 |
{ |
| 1305 |
const char *invalidParameterError = "Parameter"; |
| 1306 |
char *lastError; |
| 1307 |
|
| 1308 |
lastError = (char *)SDL_GetError(); |
| 1309 |
SDLTest_AssertPass("SDL_GetError()"); |
| 1310 |
SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL"); |
| 1311 |
if (lastError != NULL) { |
| 1312 |
SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0, |
| 1313 |
"SDL_GetError(): expected message starts with '%s', was message: '%s'", |
| 1314 |
invalidParameterError, |
| 1315 |
lastError); |
| 1316 |
SDL_ClearError(); |
| 1317 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1318 |
} |
| 1319 |
} |
| 1320 |
|
| 1321 |
/** |
| 1322 |
* @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize |
| 1323 |
* |
| 1324 |
* @sa http://wiki.libsdl.org/SDL_GetWindowSize |
| 1325 |
* @sa http://wiki.libsdl.org/SDL_SetWindowSize |
| 1326 |
*/ |
| 1327 |
int video_getSetWindowSize(void *arg) |
| 1328 |
{ |
| 1329 |
const char *title = "video_getSetWindowSize Test Window"; |
| 1330 |
SDL_Window *window; |
| 1331 |
int result; |
| 1332 |
SDL_Rect display; |
| 1333 |
int maxwVariation, maxhVariation; |
| 1334 |
int wVariation, hVariation; |
| 1335 |
int referenceW, referenceH; |
| 1336 |
int currentW, currentH; |
| 1337 |
int desiredW, desiredH; |
| 1338 |
|
| 1339 |
/* Get display bounds for size range */ |
| 1340 |
result = SDL_GetDisplayUsableBounds(0, &display); |
| 1341 |
SDLTest_AssertPass("SDL_GetDisplayBounds()"); |
| 1342 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 1343 |
if (result != 0) { |
| 1344 |
return TEST_ABORTED; |
| 1345 |
} |
| 1346 |
|
| 1347 |
/* Call against new test window */ |
| 1348 |
window = _createVideoSuiteTestWindow(title); |
| 1349 |
if (!window) { |
| 1350 |
return TEST_ABORTED; |
| 1351 |
} |
| 1352 |
|
| 1353 |
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") == 0 || |
| 1354 |
SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) { |
| 1355 |
/* Platform clips window size to screen size */ |
| 1356 |
maxwVariation = 4; |
| 1357 |
maxhVariation = 4; |
| 1358 |
} else { |
| 1359 |
/* Platform allows window size >= screen size */ |
| 1360 |
maxwVariation = 5; |
| 1361 |
maxhVariation = 5; |
| 1362 |
} |
| 1363 |
|
| 1364 |
for (wVariation = 0; wVariation < maxwVariation; wVariation++) { |
| 1365 |
for (hVariation = 0; hVariation < maxhVariation; hVariation++) { |
| 1366 |
switch (wVariation) { |
| 1367 |
default: |
| 1368 |
case 0: |
| 1369 |
/* 1 Pixel Wide */ |
| 1370 |
desiredW = 1; |
| 1371 |
break; |
| 1372 |
case 1: |
| 1373 |
/* Random width inside screen */ |
| 1374 |
desiredW = SDLTest_RandomIntegerInRange(1, 100); |
| 1375 |
break; |
| 1376 |
case 2: |
| 1377 |
/* Width 1 pixel smaller than screen */ |
| 1378 |
desiredW = display.w - 1; |
| 1379 |
break; |
| 1380 |
case 3: |
| 1381 |
/* Width at screen size */ |
| 1382 |
desiredW = display.w; |
| 1383 |
break; |
| 1384 |
case 4: |
| 1385 |
/* Width 1 pixel larger than screen */ |
| 1386 |
desiredW = display.w + 1; |
| 1387 |
break; |
| 1388 |
} |
| 1389 |
|
| 1390 |
switch (hVariation) { |
| 1391 |
default: |
| 1392 |
case 0: |
| 1393 |
/* 1 Pixel High */ |
| 1394 |
desiredH = 1; |
| 1395 |
break; |
| 1396 |
case 1: |
| 1397 |
/* Random height inside screen */ |
| 1398 |
desiredH = SDLTest_RandomIntegerInRange(1, 100); |
| 1399 |
break; |
| 1400 |
case 2: |
| 1401 |
/* Height 1 pixel smaller than screen */ |
| 1402 |
desiredH = display.h - 1; |
| 1403 |
break; |
| 1404 |
case 3: |
| 1405 |
/* Height at screen size */ |
| 1406 |
desiredH = display.h; |
| 1407 |
break; |
| 1408 |
case 4: |
| 1409 |
/* Height 1 pixel larger than screen */ |
| 1410 |
desiredH = display.h + 1; |
| 1411 |
break; |
| 1412 |
} |
| 1413 |
|
| 1414 |
/* Set size */ |
| 1415 |
SDL_SetWindowSize(window, desiredW, desiredH); |
| 1416 |
SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); |
| 1417 |
|
| 1418 |
/* Get size */ |
| 1419 |
currentW = desiredW + 1; |
| 1420 |
currentH = desiredH + 1; |
| 1421 |
SDL_GetWindowSize(window, ¤tW, ¤tH); |
| 1422 |
SDLTest_AssertPass("Call to SDL_GetWindowSize()"); |
| 1423 |
|
| 1424 |
if (desiredW == currentW && desiredH == currentH) { |
| 1425 |
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); |
| 1426 |
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); |
| 1427 |
} else { |
| 1428 |
SDL_bool hasEvent; |
| 1429 |
/* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size, |
| 1430 |
* and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */ |
| 1431 |
desiredW = currentW + 1; |
| 1432 |
desiredH = currentH + 1; |
| 1433 |
hasEvent = getSizeFromEvent(&desiredW, &desiredH); |
| 1434 |
SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing size was not honored by WM, checking presence of SDL_WINDOWEVENT_RESIZED"); |
| 1435 |
if (hasEvent) { |
| 1436 |
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width is the one from SDL event; expected: %d, got: %d", desiredW, currentW); |
| 1437 |
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height is the one from SDL event; expected: %d, got: %d", desiredH, currentH); |
| 1438 |
} |
| 1439 |
} |
| 1440 |
|
| 1441 |
/* Get just width */ |
| 1442 |
currentW = desiredW + 1; |
| 1443 |
SDL_GetWindowSize(window, ¤tW, NULL); |
| 1444 |
SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)"); |
| 1445 |
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); |
| 1446 |
|
| 1447 |
/* Get just height */ |
| 1448 |
currentH = desiredH + 1; |
| 1449 |
SDL_GetWindowSize(window, NULL, ¤tH); |
| 1450 |
SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)"); |
| 1451 |
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); |
| 1452 |
} |
| 1453 |
} |
| 1454 |
|
| 1455 |
/* Dummy call with both pointers NULL */ |
| 1456 |
SDL_GetWindowSize(window, NULL, NULL); |
| 1457 |
SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)"); |
| 1458 |
|
| 1459 |
/* Negative tests for parameter input */ |
| 1460 |
SDL_ClearError(); |
| 1461 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1462 |
for (desiredH = -2; desiredH < 2; desiredH++) { |
| 1463 |
for (desiredW = -2; desiredW < 2; desiredW++) { |
| 1464 |
if (desiredW <= 0 || desiredH <= 0) { |
| 1465 |
SDL_SetWindowSize(window, desiredW, desiredH); |
| 1466 |
SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH); |
| 1467 |
_checkInvalidParameterError(); |
| 1468 |
} |
| 1469 |
} |
| 1470 |
} |
| 1471 |
|
| 1472 |
/* Clean up */ |
| 1473 |
_destroyVideoSuiteTestWindow(window); |
| 1474 |
|
| 1475 |
/* Set some 'magic' value for later check that nothing was changed */ |
| 1476 |
referenceW = SDLTest_RandomSint32(); |
| 1477 |
referenceH = SDLTest_RandomSint32(); |
| 1478 |
currentW = referenceW; |
| 1479 |
currentH = referenceH; |
| 1480 |
desiredW = SDLTest_RandomSint32(); |
| 1481 |
desiredH = SDLTest_RandomSint32(); |
| 1482 |
|
| 1483 |
/* Negative tests for window input */ |
| 1484 |
SDL_ClearError(); |
| 1485 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1486 |
SDL_GetWindowSize(NULL, ¤tW, ¤tH); |
| 1487 |
SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)"); |
| 1488 |
SDLTest_AssertCheck( |
| 1489 |
currentW == referenceW && currentH == referenceH, |
| 1490 |
"Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", |
| 1491 |
referenceW, referenceH, |
| 1492 |
currentW, currentH); |
| 1493 |
_checkInvalidWindowError(); |
| 1494 |
|
| 1495 |
SDL_GetWindowSize(NULL, NULL, NULL); |
| 1496 |
SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)"); |
| 1497 |
_checkInvalidWindowError(); |
| 1498 |
|
| 1499 |
SDL_SetWindowSize(NULL, desiredW, desiredH); |
| 1500 |
SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)"); |
| 1501 |
_checkInvalidWindowError(); |
| 1502 |
|
| 1503 |
return TEST_COMPLETED; |
| 1504 |
} |
| 1505 |
|
| 1506 |
/** |
| 1507 |
* @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize |
| 1508 |
* |
| 1509 |
*/ |
| 1510 |
int video_getSetWindowMinimumSize(void *arg) |
| 1511 |
{ |
| 1512 |
const char *title = "video_getSetWindowMinimumSize Test Window"; |
| 1513 |
SDL_Window *window; |
| 1514 |
int result; |
| 1515 |
SDL_Rect display; |
| 1516 |
int wVariation, hVariation; |
| 1517 |
int referenceW, referenceH; |
| 1518 |
int currentW, currentH; |
| 1519 |
int desiredW = 1; |
| 1520 |
int desiredH = 1; |
| 1521 |
|
| 1522 |
/* Get display bounds for size range */ |
| 1523 |
result = SDL_GetDisplayBounds(0, &display); |
| 1524 |
SDLTest_AssertPass("SDL_GetDisplayBounds()"); |
| 1525 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 1526 |
if (result != 0) { |
| 1527 |
return TEST_ABORTED; |
| 1528 |
} |
| 1529 |
|
| 1530 |
/* Call against new test window */ |
| 1531 |
window = _createVideoSuiteTestWindow(title); |
| 1532 |
if (!window) { |
| 1533 |
return TEST_ABORTED; |
| 1534 |
} |
| 1535 |
|
| 1536 |
for (wVariation = 0; wVariation < 5; wVariation++) { |
| 1537 |
for (hVariation = 0; hVariation < 5; hVariation++) { |
| 1538 |
switch (wVariation) { |
| 1539 |
case 0: |
| 1540 |
/* 1 Pixel Wide */ |
| 1541 |
desiredW = 1; |
| 1542 |
break; |
| 1543 |
case 1: |
| 1544 |
/* Random width inside screen */ |
| 1545 |
desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); |
| 1546 |
break; |
| 1547 |
case 2: |
| 1548 |
/* Width at screen size */ |
| 1549 |
desiredW = display.w; |
| 1550 |
break; |
| 1551 |
} |
| 1552 |
|
| 1553 |
switch (hVariation) { |
| 1554 |
case 0: |
| 1555 |
/* 1 Pixel High */ |
| 1556 |
desiredH = 1; |
| 1557 |
break; |
| 1558 |
case 1: |
| 1559 |
/* Random height inside screen */ |
| 1560 |
desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); |
| 1561 |
break; |
| 1562 |
case 2: |
| 1563 |
/* Height at screen size */ |
| 1564 |
desiredH = display.h; |
| 1565 |
break; |
| 1566 |
case 4: |
| 1567 |
/* Height 1 pixel larger than screen */ |
| 1568 |
desiredH = display.h + 1; |
| 1569 |
break; |
| 1570 |
} |
| 1571 |
|
| 1572 |
/* Set size */ |
| 1573 |
SDL_SetWindowMinimumSize(window, desiredW, desiredH); |
| 1574 |
SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); |
| 1575 |
|
| 1576 |
/* Get size */ |
| 1577 |
currentW = desiredW + 1; |
| 1578 |
currentH = desiredH + 1; |
| 1579 |
SDL_GetWindowMinimumSize(window, ¤tW, ¤tH); |
| 1580 |
SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()"); |
| 1581 |
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); |
| 1582 |
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); |
| 1583 |
|
| 1584 |
/* Get just width */ |
| 1585 |
currentW = desiredW + 1; |
| 1586 |
SDL_GetWindowMinimumSize(window, ¤tW, NULL); |
| 1587 |
SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)"); |
| 1588 |
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); |
| 1589 |
|
| 1590 |
/* Get just height */ |
| 1591 |
currentH = desiredH + 1; |
| 1592 |
SDL_GetWindowMinimumSize(window, NULL, ¤tH); |
| 1593 |
SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)"); |
| 1594 |
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); |
| 1595 |
} |
| 1596 |
} |
| 1597 |
|
| 1598 |
/* Dummy call with both pointers NULL */ |
| 1599 |
SDL_GetWindowMinimumSize(window, NULL, NULL); |
| 1600 |
SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)"); |
| 1601 |
|
| 1602 |
/* Negative tests for parameter input */ |
| 1603 |
SDL_ClearError(); |
| 1604 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1605 |
for (desiredH = -2; desiredH < 2; desiredH++) { |
| 1606 |
for (desiredW = -2; desiredW < 2; desiredW++) { |
| 1607 |
if (desiredW <= 0 || desiredH <= 0) { |
| 1608 |
SDL_SetWindowMinimumSize(window, desiredW, desiredH); |
| 1609 |
SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH); |
| 1610 |
_checkInvalidParameterError(); |
| 1611 |
} |
| 1612 |
} |
| 1613 |
} |
| 1614 |
|
| 1615 |
/* Clean up */ |
| 1616 |
_destroyVideoSuiteTestWindow(window); |
| 1617 |
|
| 1618 |
/* Set some 'magic' value for later check that nothing was changed */ |
| 1619 |
referenceW = SDLTest_RandomSint32(); |
| 1620 |
referenceH = SDLTest_RandomSint32(); |
| 1621 |
currentW = referenceW; |
| 1622 |
currentH = referenceH; |
| 1623 |
desiredW = SDLTest_RandomSint32(); |
| 1624 |
desiredH = SDLTest_RandomSint32(); |
| 1625 |
|
| 1626 |
/* Negative tests for window input */ |
| 1627 |
SDL_ClearError(); |
| 1628 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1629 |
SDL_GetWindowMinimumSize(NULL, ¤tW, ¤tH); |
| 1630 |
SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)"); |
| 1631 |
SDLTest_AssertCheck( |
| 1632 |
currentW == referenceW && currentH == referenceH, |
| 1633 |
"Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", |
| 1634 |
referenceW, referenceH, |
| 1635 |
currentW, currentH); |
| 1636 |
_checkInvalidWindowError(); |
| 1637 |
|
| 1638 |
SDL_GetWindowMinimumSize(NULL, NULL, NULL); |
| 1639 |
SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)"); |
| 1640 |
_checkInvalidWindowError(); |
| 1641 |
|
| 1642 |
SDL_SetWindowMinimumSize(NULL, desiredW, desiredH); |
| 1643 |
SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)"); |
| 1644 |
_checkInvalidWindowError(); |
| 1645 |
|
| 1646 |
return TEST_COMPLETED; |
| 1647 |
} |
| 1648 |
|
| 1649 |
/** |
| 1650 |
* @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize |
| 1651 |
* |
| 1652 |
*/ |
| 1653 |
int video_getSetWindowMaximumSize(void *arg) |
| 1654 |
{ |
| 1655 |
const char *title = "video_getSetWindowMaximumSize Test Window"; |
| 1656 |
SDL_Window *window; |
| 1657 |
int result; |
| 1658 |
SDL_Rect display; |
| 1659 |
int wVariation, hVariation; |
| 1660 |
int referenceW, referenceH; |
| 1661 |
int currentW, currentH; |
| 1662 |
int desiredW, desiredH; |
| 1663 |
|
| 1664 |
/* Get display bounds for size range */ |
| 1665 |
result = SDL_GetDisplayBounds(0, &display); |
| 1666 |
SDLTest_AssertPass("SDL_GetDisplayBounds()"); |
| 1667 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 1668 |
if (result != 0) { |
| 1669 |
return TEST_ABORTED; |
| 1670 |
} |
| 1671 |
|
| 1672 |
/* Call against new test window */ |
| 1673 |
window = _createVideoSuiteTestWindow(title); |
| 1674 |
if (!window) { |
| 1675 |
return TEST_ABORTED; |
| 1676 |
} |
| 1677 |
|
| 1678 |
for (wVariation = 0; wVariation < 3; wVariation++) { |
| 1679 |
for (hVariation = 0; hVariation < 3; hVariation++) { |
| 1680 |
switch (wVariation) { |
| 1681 |
case 0: |
| 1682 |
/* 1 Pixel Wide */ |
| 1683 |
desiredW = 1; |
| 1684 |
break; |
| 1685 |
case 1: |
| 1686 |
/* Random width inside screen */ |
| 1687 |
desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1); |
| 1688 |
break; |
| 1689 |
case 2: |
| 1690 |
/* Width at screen size */ |
| 1691 |
desiredW = display.w; |
| 1692 |
break; |
| 1693 |
} |
| 1694 |
|
| 1695 |
switch (hVariation) { |
| 1696 |
case 0: |
| 1697 |
/* 1 Pixel High */ |
| 1698 |
desiredH = 1; |
| 1699 |
break; |
| 1700 |
case 1: |
| 1701 |
/* Random height inside screen */ |
| 1702 |
desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1); |
| 1703 |
break; |
| 1704 |
case 2: |
| 1705 |
/* Height at screen size */ |
| 1706 |
desiredH = display.h; |
| 1707 |
break; |
| 1708 |
} |
| 1709 |
|
| 1710 |
/* Set size */ |
| 1711 |
SDL_SetWindowMaximumSize(window, desiredW, desiredH); |
| 1712 |
SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); |
| 1713 |
|
| 1714 |
/* Get size */ |
| 1715 |
currentW = desiredW + 1; |
| 1716 |
currentH = desiredH + 1; |
| 1717 |
SDL_GetWindowMaximumSize(window, ¤tW, ¤tH); |
| 1718 |
SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()"); |
| 1719 |
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW); |
| 1720 |
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH); |
| 1721 |
|
| 1722 |
/* Get just width */ |
| 1723 |
currentW = desiredW + 1; |
| 1724 |
SDL_GetWindowMaximumSize(window, ¤tW, NULL); |
| 1725 |
SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)"); |
| 1726 |
SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH); |
| 1727 |
|
| 1728 |
/* Get just height */ |
| 1729 |
currentH = desiredH + 1; |
| 1730 |
SDL_GetWindowMaximumSize(window, NULL, ¤tH); |
| 1731 |
SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)"); |
| 1732 |
SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH); |
| 1733 |
} |
| 1734 |
} |
| 1735 |
|
| 1736 |
/* Dummy call with both pointers NULL */ |
| 1737 |
SDL_GetWindowMaximumSize(window, NULL, NULL); |
| 1738 |
SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)"); |
| 1739 |
|
| 1740 |
/* Negative tests for parameter input */ |
| 1741 |
SDL_ClearError(); |
| 1742 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1743 |
for (desiredH = -2; desiredH < 2; desiredH++) { |
| 1744 |
for (desiredW = -2; desiredW < 2; desiredW++) { |
| 1745 |
if (desiredW <= 0 || desiredH <= 0) { |
| 1746 |
SDL_SetWindowMaximumSize(window, desiredW, desiredH); |
| 1747 |
SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH); |
| 1748 |
_checkInvalidParameterError(); |
| 1749 |
} |
| 1750 |
} |
| 1751 |
} |
| 1752 |
|
| 1753 |
/* Clean up */ |
| 1754 |
_destroyVideoSuiteTestWindow(window); |
| 1755 |
|
| 1756 |
/* Set some 'magic' value for later check that nothing was changed */ |
| 1757 |
referenceW = SDLTest_RandomSint32(); |
| 1758 |
referenceH = SDLTest_RandomSint32(); |
| 1759 |
currentW = referenceW; |
| 1760 |
currentH = referenceH; |
| 1761 |
desiredW = SDLTest_RandomSint32(); |
| 1762 |
desiredH = SDLTest_RandomSint32(); |
| 1763 |
|
| 1764 |
/* Negative tests */ |
| 1765 |
SDL_ClearError(); |
| 1766 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1767 |
SDL_GetWindowMaximumSize(NULL, ¤tW, ¤tH); |
| 1768 |
SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)"); |
| 1769 |
SDLTest_AssertCheck( |
| 1770 |
currentW == referenceW && currentH == referenceH, |
| 1771 |
"Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d", |
| 1772 |
referenceW, referenceH, |
| 1773 |
currentW, currentH); |
| 1774 |
_checkInvalidWindowError(); |
| 1775 |
|
| 1776 |
SDL_GetWindowMaximumSize(NULL, NULL, NULL); |
| 1777 |
SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)"); |
| 1778 |
_checkInvalidWindowError(); |
| 1779 |
|
| 1780 |
SDL_SetWindowMaximumSize(NULL, desiredW, desiredH); |
| 1781 |
SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)"); |
| 1782 |
_checkInvalidWindowError(); |
| 1783 |
|
| 1784 |
return TEST_COMPLETED; |
| 1785 |
} |
| 1786 |
|
| 1787 |
/** |
| 1788 |
* @brief Tests call to SDL_SetWindowData and SDL_GetWindowData |
| 1789 |
* |
| 1790 |
* @sa http://wiki.libsdl.org/SDL_SetWindowData |
| 1791 |
* @sa http://wiki.libsdl.org/SDL_GetWindowData |
| 1792 |
*/ |
| 1793 |
int video_getSetWindowData(void *arg) |
| 1794 |
{ |
| 1795 |
int returnValue = TEST_COMPLETED; |
| 1796 |
const char *title = "video_setGetWindowData Test Window"; |
| 1797 |
SDL_Window *window; |
| 1798 |
const char *referenceName = "TestName"; |
| 1799 |
const char *name = "TestName"; |
| 1800 |
const char *referenceName2 = "TestName2"; |
| 1801 |
const char *name2 = "TestName2"; |
| 1802 |
int datasize; |
| 1803 |
char *referenceUserdata = NULL; |
| 1804 |
char *userdata = NULL; |
| 1805 |
char *referenceUserdata2 = NULL; |
| 1806 |
char *userdata2 = NULL; |
| 1807 |
char *result; |
| 1808 |
int iteration; |
| 1809 |
|
| 1810 |
/* Call against new test window */ |
| 1811 |
window = _createVideoSuiteTestWindow(title); |
| 1812 |
if (!window) { |
| 1813 |
return TEST_ABORTED; |
| 1814 |
} |
| 1815 |
|
| 1816 |
/* Create testdata */ |
| 1817 |
datasize = SDLTest_RandomIntegerInRange(1, 32); |
| 1818 |
referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize); |
| 1819 |
if (!referenceUserdata) { |
| 1820 |
returnValue = TEST_ABORTED; |
| 1821 |
goto cleanup; |
| 1822 |
} |
| 1823 |
userdata = SDL_strdup(referenceUserdata); |
| 1824 |
if (!userdata) { |
| 1825 |
returnValue = TEST_ABORTED; |
| 1826 |
goto cleanup; |
| 1827 |
} |
| 1828 |
datasize = SDLTest_RandomIntegerInRange(1, 32); |
| 1829 |
referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize); |
| 1830 |
if (!referenceUserdata2) { |
| 1831 |
returnValue = TEST_ABORTED; |
| 1832 |
goto cleanup; |
| 1833 |
} |
| 1834 |
userdata2 = SDL_strdup(referenceUserdata2); |
| 1835 |
if (!userdata2) { |
| 1836 |
returnValue = TEST_ABORTED; |
| 1837 |
goto cleanup; |
| 1838 |
} |
| 1839 |
|
| 1840 |
/* Get non-existent data */ |
| 1841 |
result = (char *)SDL_GetWindowData(window, name); |
| 1842 |
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); |
| 1843 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1844 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1845 |
|
| 1846 |
/* Set data */ |
| 1847 |
result = (char *)SDL_SetWindowData(window, name, userdata); |
| 1848 |
SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata); |
| 1849 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1850 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1851 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); |
| 1852 |
|
| 1853 |
/* Get data (twice) */ |
| 1854 |
for (iteration = 1; iteration <= 2; iteration++) { |
| 1855 |
result = (char *)SDL_GetWindowData(window, name); |
| 1856 |
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration); |
| 1857 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); |
| 1858 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1859 |
} |
| 1860 |
|
| 1861 |
/* Set data again twice */ |
| 1862 |
for (iteration = 1; iteration <= 2; iteration++) { |
| 1863 |
result = (char *)SDL_SetWindowData(window, name, userdata); |
| 1864 |
SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration); |
| 1865 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); |
| 1866 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1867 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); |
| 1868 |
} |
| 1869 |
|
| 1870 |
/* Get data again */ |
| 1871 |
result = (char *)SDL_GetWindowData(window, name); |
| 1872 |
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name); |
| 1873 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); |
| 1874 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1875 |
|
| 1876 |
/* Set data with new data */ |
| 1877 |
result = (char *)SDL_SetWindowData(window, name, userdata2); |
| 1878 |
SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2); |
| 1879 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); |
| 1880 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1881 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); |
| 1882 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); |
| 1883 |
|
| 1884 |
/* Set data with new data again */ |
| 1885 |
result = (char *)SDL_SetWindowData(window, name, userdata2); |
| 1886 |
SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2); |
| 1887 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); |
| 1888 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1889 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); |
| 1890 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); |
| 1891 |
|
| 1892 |
/* Get new data */ |
| 1893 |
result = (char *)SDL_GetWindowData(window, name); |
| 1894 |
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); |
| 1895 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); |
| 1896 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1897 |
|
| 1898 |
/* Set data with NULL to clear */ |
| 1899 |
result = (char *)SDL_SetWindowData(window, name, NULL); |
| 1900 |
SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name); |
| 1901 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result); |
| 1902 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1903 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); |
| 1904 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); |
| 1905 |
|
| 1906 |
/* Set data with NULL to clear again */ |
| 1907 |
result = (char *)SDL_SetWindowData(window, name, NULL); |
| 1908 |
SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name); |
| 1909 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1910 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1911 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); |
| 1912 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2); |
| 1913 |
|
| 1914 |
/* Get non-existent data */ |
| 1915 |
result = (char *)SDL_GetWindowData(window, name); |
| 1916 |
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name); |
| 1917 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1918 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1919 |
|
| 1920 |
/* Get non-existent data new name */ |
| 1921 |
result = (char *)SDL_GetWindowData(window, name2); |
| 1922 |
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2); |
| 1923 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1924 |
SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2); |
| 1925 |
|
| 1926 |
/* Set data (again) */ |
| 1927 |
result = (char *)SDL_SetWindowData(window, name, userdata); |
| 1928 |
SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata); |
| 1929 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1930 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1931 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata); |
| 1932 |
|
| 1933 |
/* Get data (again) */ |
| 1934 |
result = (char *)SDL_GetWindowData(window, name); |
| 1935 |
SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name); |
| 1936 |
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result); |
| 1937 |
SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name); |
| 1938 |
|
| 1939 |
/* Negative test */ |
| 1940 |
SDL_ClearError(); |
| 1941 |
SDLTest_AssertPass("Call to SDL_ClearError()"); |
| 1942 |
|
| 1943 |
/* Set with invalid window */ |
| 1944 |
result = (char *)SDL_SetWindowData(NULL, name, userdata); |
| 1945 |
SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)"); |
| 1946 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1947 |
_checkInvalidWindowError(); |
| 1948 |
|
| 1949 |
/* Set data with NULL name, valid userdata */ |
| 1950 |
result = (char *)SDL_SetWindowData(window, NULL, userdata); |
| 1951 |
SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)"); |
| 1952 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1953 |
_checkInvalidParameterError(); |
| 1954 |
|
| 1955 |
/* Set data with empty name, valid userdata */ |
| 1956 |
result = (char *)SDL_SetWindowData(window, "", userdata); |
| 1957 |
SDLTest_AssertPass("Call to SDL_SetWindowData(name='')"); |
| 1958 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1959 |
_checkInvalidParameterError(); |
| 1960 |
|
| 1961 |
/* Set data with NULL name, NULL userdata */ |
| 1962 |
result = (char *)SDL_SetWindowData(window, NULL, NULL); |
| 1963 |
SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)"); |
| 1964 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1965 |
_checkInvalidParameterError(); |
| 1966 |
|
| 1967 |
/* Set data with empty name, NULL userdata */ |
| 1968 |
result = (char *)SDL_SetWindowData(window, "", NULL); |
| 1969 |
SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)"); |
| 1970 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1971 |
_checkInvalidParameterError(); |
| 1972 |
|
| 1973 |
/* Get with invalid window */ |
| 1974 |
result = (char *)SDL_GetWindowData(NULL, name); |
| 1975 |
SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)"); |
| 1976 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1977 |
_checkInvalidWindowError(); |
| 1978 |
|
| 1979 |
/* Get data with NULL name */ |
| 1980 |
result = (char *)SDL_GetWindowData(window, NULL); |
| 1981 |
SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)"); |
| 1982 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1983 |
_checkInvalidParameterError(); |
| 1984 |
|
| 1985 |
/* Get data with empty name */ |
| 1986 |
result = (char *)SDL_GetWindowData(window, ""); |
| 1987 |
SDLTest_AssertPass("Call to SDL_GetWindowData(name='')"); |
| 1988 |
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); |
| 1989 |
_checkInvalidParameterError(); |
| 1990 |
|
| 1991 |
/* Clean up */ |
| 1992 |
_destroyVideoSuiteTestWindow(window); |
| 1993 |
|
| 1994 |
cleanup: |
| 1995 |
SDL_free(referenceUserdata); |
| 1996 |
SDL_free(referenceUserdata2); |
| 1997 |
SDL_free(userdata); |
| 1998 |
SDL_free(userdata2); |
| 1999 |
|
| 2000 |
return returnValue; |
| 2001 |
} |
| 2002 |
|
| 2003 |
/** |
| 2004 |
* @brief Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN_DESKTOP. |
| 2005 |
* |
| 2006 |
* Espeically useful when run on a multi-monitor system with different DPI scales per monitor, |
| 2007 |
* to test that the window size is maintained when moving between monitors. |
| 2008 |
*/ |
| 2009 |
int video_setWindowCenteredOnDisplay(void *arg) |
| 2010 |
{ |
| 2011 |
SDL_Window *window; |
| 2012 |
const char *title = "video_setWindowCenteredOnDisplay Test Window"; |
| 2013 |
int x, y, w, h; |
| 2014 |
int xVariation, yVariation; |
| 2015 |
int displayNum; |
| 2016 |
int result; |
| 2017 |
SDL_Rect display0, display1; |
| 2018 |
|
| 2019 |
displayNum = SDL_GetNumVideoDisplays(); |
| 2020 |
SDLTest_AssertPass("SDL_GetNumVideoDisplays()"); |
| 2021 |
SDLTest_AssertCheck(displayNum >= 1, "Validate result (current: %d, expected >= 1)", displayNum); |
| 2022 |
if (displayNum <= 0) { |
| 2023 |
return TEST_ABORTED; |
| 2024 |
} |
| 2025 |
|
| 2026 |
/* Get display bounds */ |
| 2027 |
result = SDL_GetDisplayUsableBounds(0 % displayNum, &display0); /* SDL2-COMPAT change -- was SDL_GetDisplayBounds() */ |
| 2028 |
SDLTest_AssertPass("SDL_GetDisplayBounds()"); |
| 2029 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 2030 |
if (result != 0) { |
| 2031 |
return TEST_ABORTED; |
| 2032 |
} |
| 2033 |
|
| 2034 |
result = SDL_GetDisplayUsableBounds(1 % displayNum, &display1); /* SDL2-COMPAT change -- was SDL_GetDisplayBounds() */ |
| 2035 |
SDLTest_AssertPass("SDL_GetDisplayBounds()"); |
| 2036 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 2037 |
if (result != 0) { |
| 2038 |
return TEST_ABORTED; |
| 2039 |
} |
| 2040 |
|
| 2041 |
for (xVariation = 0; xVariation < 2; xVariation++) { |
| 2042 |
for (yVariation = 0; yVariation < 2; yVariation++) { |
| 2043 |
int currentX = 0, currentY = 0; |
| 2044 |
int currentW = 0, currentH = 0; |
| 2045 |
int expectedX = 0, expectedY = 0; |
| 2046 |
int currentDisplay; |
| 2047 |
int expectedDisplay; |
| 2048 |
SDL_Rect expectedFullscreenRect; /* Added for SDL2-COMPAT -- see below */ |
| 2049 |
SDL_Rect expectedDisplayRect; |
| 2050 |
SDL_bool video_driver_is_wayland = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0; |
| 2051 |
|
| 2052 |
/* xVariation is the display we start on */ |
| 2053 |
expectedDisplay = xVariation % displayNum; |
| 2054 |
x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); |
| 2055 |
y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); |
| 2056 |
w = SDLTest_RandomIntegerInRange(640, 800); |
| 2057 |
h = SDLTest_RandomIntegerInRange(400, 600); |
| 2058 |
expectedDisplayRect = (xVariation == 0) ? display0 : display1; |
| 2059 |
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); |
| 2060 |
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); |
| 2061 |
|
| 2062 |
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS); |
| 2063 |
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); |
| 2064 |
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); |
| 2065 |
|
| 2066 |
/* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */ |
| 2067 |
if (video_driver_is_wayland) { |
| 2068 |
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); |
| 2069 |
|
| 2070 |
if (renderer) { |
| 2071 |
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); |
| 2072 |
SDL_RenderClear(renderer); |
| 2073 |
SDL_RenderPresent(renderer); |
| 2074 |
|
| 2075 |
/* Some desktops don't display the window immediately after presentation, |
| 2076 |
* so delay to give the window time to actually appear on the desktop. |
| 2077 |
*/ |
| 2078 |
SDL_Delay(100); |
| 2079 |
} else { |
| 2080 |
SDLTest_Log("Unable to create a renderer, tests may fail under Wayland"); |
| 2081 |
} |
| 2082 |
} |
| 2083 |
|
| 2084 |
/* Check the window is centered on the requested display */ |
| 2085 |
currentDisplay = SDL_GetWindowDisplayIndex(window); |
| 2086 |
SDL_GetWindowSize(window, ¤tW, ¤tH); |
| 2087 |
SDL_GetWindowPosition(window, ¤tX, ¤tY); |
| 2088 |
|
| 2089 |
if (!video_driver_is_wayland) { |
| 2090 |
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); |
| 2091 |
} else { |
| 2092 |
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning"); |
| 2093 |
} |
| 2094 |
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); |
| 2095 |
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); |
| 2096 |
if (!video_driver_is_wayland) { |
| 2097 |
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); |
| 2098 |
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); |
| 2099 |
} else { |
| 2100 |
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning"); |
| 2101 |
} |
| 2102 |
|
| 2103 |
/* Enter fullscreen desktop */ |
| 2104 |
result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); |
| 2105 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 2106 |
|
| 2107 |
/* Check we are filling the full display */ |
| 2108 |
currentDisplay = SDL_GetWindowDisplayIndex(window); |
| 2109 |
SDL_GetWindowSize(window, ¤tW, ¤tH); |
| 2110 |
SDL_GetWindowPosition(window, ¤tX, ¤tY); |
| 2111 |
|
| 2112 |
/* SDL2-COMPAT addition: Get the expected fullscreen rect. |
| 2113 |
* This needs to be queried after window creation and positioning as some drivers can alter the |
| 2114 |
* usable bounds based on the window scaling mode. |
| 2115 |
*/ |
| 2116 |
result = SDL_GetDisplayBounds(expectedDisplay, &expectedFullscreenRect); |
| 2117 |
SDLTest_AssertPass("SDL_GetDisplayBounds()"); |
| 2118 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 2119 |
|
| 2120 |
if (!video_driver_is_wayland) { |
| 2121 |
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); |
| 2122 |
} else { |
| 2123 |
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning"); |
| 2124 |
} |
| 2125 |
/* The following four checks changed from expectedDisplayRect to expectedFullscreenRect for SDL2-COMPAT: */ |
| 2126 |
SDLTest_AssertCheck(currentW == expectedFullscreenRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedFullscreenRect.w); |
| 2127 |
SDLTest_AssertCheck(currentH == expectedFullscreenRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedFullscreenRect.h); |
| 2128 |
if (!video_driver_is_wayland) { |
| 2129 |
SDLTest_AssertCheck(currentX == expectedFullscreenRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedFullscreenRect.x); |
| 2130 |
SDLTest_AssertCheck(currentY == expectedFullscreenRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedFullscreenRect.y); |
| 2131 |
} else { |
| 2132 |
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning"); |
| 2133 |
} |
| 2134 |
|
| 2135 |
/* Leave fullscreen desktop */ |
| 2136 |
result = SDL_SetWindowFullscreen(window, 0); |
| 2137 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 2138 |
|
| 2139 |
/* Check window was restored correctly */ |
| 2140 |
currentDisplay = SDL_GetWindowDisplayIndex(window); |
| 2141 |
SDL_GetWindowSize(window, ¤tW, ¤tH); |
| 2142 |
SDL_GetWindowPosition(window, ¤tX, ¤tY); |
| 2143 |
|
| 2144 |
if (!video_driver_is_wayland) { |
| 2145 |
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); |
| 2146 |
} else { |
| 2147 |
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning"); |
| 2148 |
} |
| 2149 |
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); |
| 2150 |
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); |
| 2151 |
if (!video_driver_is_wayland) { |
| 2152 |
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); |
| 2153 |
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); |
| 2154 |
} else { |
| 2155 |
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning"); |
| 2156 |
} |
| 2157 |
|
| 2158 |
/* Center on display yVariation, and check window properties */ |
| 2159 |
|
| 2160 |
expectedDisplay = yVariation % displayNum; |
| 2161 |
x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); |
| 2162 |
y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); |
| 2163 |
expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1; |
| 2164 |
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); |
| 2165 |
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); |
| 2166 |
SDL_SetWindowPosition(window, x, y); |
| 2167 |
|
| 2168 |
currentDisplay = SDL_GetWindowDisplayIndex(window); |
| 2169 |
SDL_GetWindowSize(window, ¤tW, ¤tH); |
| 2170 |
SDL_GetWindowPosition(window, ¤tX, ¤tY); |
| 2171 |
|
| 2172 |
if (!video_driver_is_wayland) { |
| 2173 |
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); |
| 2174 |
} else { |
| 2175 |
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning"); |
| 2176 |
} |
| 2177 |
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); |
| 2178 |
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); |
| 2179 |
if (!video_driver_is_wayland) { |
| 2180 |
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); |
| 2181 |
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); |
| 2182 |
} else { |
| 2183 |
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning"); |
| 2184 |
} |
| 2185 |
|
| 2186 |
/* Clean up */ |
| 2187 |
_destroyVideoSuiteTestWindow(window); |
| 2188 |
} |
| 2189 |
} |
| 2190 |
|
| 2191 |
return TEST_COMPLETED; |
| 2192 |
} |
| 2193 |
|
| 2194 |
/** |
| 2195 |
* Tests window surface functionality |
| 2196 |
*/ |
| 2197 |
static int video_getWindowSurface(void *arg) |
| 2198 |
{ |
| 2199 |
const char *title = "video_getWindowSurface Test Window"; |
| 2200 |
SDL_Window *window; |
| 2201 |
SDL_Surface *surface; |
| 2202 |
SDL_Renderer *renderer; |
| 2203 |
Uint32 renderer_flags = SDL_RENDERER_ACCELERATED; |
| 2204 |
int result; |
| 2205 |
|
| 2206 |
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "dummy") == 0) { |
| 2207 |
renderer_flags = SDL_RENDERER_SOFTWARE; |
| 2208 |
} |
| 2209 |
|
| 2210 |
/* Make sure we're testing interaction with an accelerated renderer */ |
| 2211 |
SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1"); |
| 2212 |
|
| 2213 |
window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 320, 0); |
| 2214 |
SDLTest_AssertPass("Call to SDL_CreateWindow('%s', SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 320, 0)", title); |
| 2215 |
SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL"); |
| 2216 |
|
| 2217 |
surface = SDL_GetWindowSurface(window); |
| 2218 |
SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)"); |
| 2219 |
SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL"); |
| 2220 |
SDLTest_AssertCheck(SDL_HasWindowSurface(window), "Validate that window has a surface"); |
| 2221 |
|
| 2222 |
result = SDL_UpdateWindowSurface(window); |
| 2223 |
SDLTest_AssertPass("Call to SDL_UpdateWindowSurface(window)"); |
| 2224 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 2225 |
|
| 2226 |
/* We shouldn't be able to create a renderer on a window with a surface */ |
| 2227 |
renderer = SDL_CreateRenderer(window, -1, renderer_flags); |
| 2228 |
SDLTest_AssertPass("Call to SDL_CreateRenderer(window)"); |
| 2229 |
SDLTest_AssertCheck(renderer == NULL, "Validate that returned renderer is NULL"); |
| 2230 |
|
| 2231 |
result = SDL_DestroyWindowSurface(window); |
| 2232 |
SDLTest_AssertPass("Call to SDL_DestroyWindowSurface(window)"); |
| 2233 |
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); |
| 2234 |
SDLTest_AssertCheck(!SDL_HasWindowSurface(window), "Validate that window does not have a surface"); |
| 2235 |
|
| 2236 |
/* We should be able to create a renderer on the window now */ |
| 2237 |
renderer = SDL_CreateRenderer(window, -1, renderer_flags); |
| 2238 |
SDLTest_AssertPass("Call to SDL_CreateRenderer(window)"); |
| 2239 |
SDLTest_AssertCheck(renderer != NULL, "Validate that returned renderer is not NULL"); |
| 2240 |
|
| 2241 |
/* We should not be able to create a window surface now, unless it was created by the renderer */ |
| 2242 |
if (!SDL_HasWindowSurface(window)) { |
| 2243 |
surface = SDL_GetWindowSurface(window); |
| 2244 |
SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)"); |
| 2245 |
SDLTest_AssertCheck(surface == NULL, "Validate that returned surface is NULL"); |
| 2246 |
} |
| 2247 |
|
| 2248 |
SDL_DestroyRenderer(renderer); |
| 2249 |
SDLTest_AssertPass("Call to SDL_DestroyRenderer(renderer)"); |
| 2250 |
SDLTest_AssertCheck(!SDL_HasWindowSurface(window), "Validate that window does not have a surface"); |
| 2251 |
|
| 2252 |
/* We should be able to create a window surface again */ |
| 2253 |
surface = SDL_GetWindowSurface(window); |
| 2254 |
SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)"); |
| 2255 |
SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL"); |
| 2256 |
SDLTest_AssertCheck(SDL_HasWindowSurface(window), "Validate that window has a surface"); |
| 2257 |
|
| 2258 |
/* Clean up */ |
| 2259 |
SDL_DestroyWindow(window); |
| 2260 |
|
| 2261 |
return TEST_COMPLETED; |
| 2262 |
} |
| 2263 |
|
| 2264 |
/** |
| 2265 |
* Tests SDL_SetWindowInputFocus |
| 2266 |
*/ |
| 2267 |
static int video_setWindowInputFocus(void *arg) |
| 2268 |
{ |
| 2269 |
int result; |
| 2270 |
SDL_Window *window; |
| 2271 |
|
| 2272 |
SDLTest_AssertPass("SDL_SetWindowInputFocus is not supported on dummy and SDL2 wayland driver"); |
| 2273 |
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "dummy") == 0 || SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) { |
| 2274 |
return TEST_SKIPPED; |
| 2275 |
} |
| 2276 |
|
| 2277 |
window = _createVideoSuiteTestWindow("video_setWindowInputFocus"); |
| 2278 |
if (!window) { |
| 2279 |
return TEST_ABORTED; |
| 2280 |
} |
| 2281 |
|
| 2282 |
SDLTest_AssertPass("About to call SDL_SetWindowInputFocus(window)"); |
| 2283 |
result = SDL_SetWindowInputFocus(window); |
| 2284 |
SDLTest_AssertCheck(result == 0, "Result is %d, expected 0", result); |
| 2285 |
|
| 2286 |
_destroyVideoSuiteTestWindow(window); |
| 2287 |
|
| 2288 |
return TEST_COMPLETED; |
| 2289 |
} |
| 2290 |
|
| 2291 |
/* ================= Test References ================== */ |
| 2292 |
|
| 2293 |
/* Video test cases */ |
| 2294 |
static const SDLTest_TestCaseReference videoTest1 = { |
| 2295 |
(SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED |
| 2296 |
}; |
| 2297 |
|
| 2298 |
static const SDLTest_TestCaseReference videoTest2 = { |
| 2299 |
(SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions", "Create windows at various locations", TEST_ENABLED |
| 2300 |
}; |
| 2301 |
|
| 2302 |
static const SDLTest_TestCaseReference videoTest3 = { |
| 2303 |
(SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED |
| 2304 |
}; |
| 2305 |
|
| 2306 |
static const SDLTest_TestCaseReference videoTest4 = { |
| 2307 |
(SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED |
| 2308 |
}; |
| 2309 |
|
| 2310 |
static const SDLTest_TestCaseReference videoTest5 = { |
| 2311 |
(SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED |
| 2312 |
}; |
| 2313 |
|
| 2314 |
static const SDLTest_TestCaseReference videoTest6 = { |
| 2315 |
(SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED |
| 2316 |
}; |
| 2317 |
|
| 2318 |
static const SDLTest_TestCaseReference videoTest7 = { |
| 2319 |
(SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED |
| 2320 |
}; |
| 2321 |
|
| 2322 |
static const SDLTest_TestCaseReference videoTest8 = { |
| 2323 |
(SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED |
| 2324 |
}; |
| 2325 |
|
| 2326 |
static const SDLTest_TestCaseReference videoTest9 = { |
| 2327 |
(SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED |
| 2328 |
}; |
| 2329 |
|
| 2330 |
static const SDLTest_TestCaseReference videoTest10 = |
| 2331 |
{ (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED }; |
| 2332 |
|
| 2333 |
static const SDLTest_TestCaseReference videoTest11 = |
| 2334 |
{ (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED }; |
| 2335 |
|
| 2336 |
static const SDLTest_TestCaseReference videoTest12 = |
| 2337 |
{ (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED }; |
| 2338 |
|
| 2339 |
static const SDLTest_TestCaseReference videoTest13 = |
| 2340 |
{ (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED }; |
| 2341 |
|
| 2342 |
static const SDLTest_TestCaseReference videoTest14 = |
| 2343 |
{ (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED }; |
| 2344 |
|
| 2345 |
static const SDLTest_TestCaseReference videoTest15 = |
| 2346 |
{ (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED }; |
| 2347 |
|
| 2348 |
static const SDLTest_TestCaseReference videoTest16 = |
| 2349 |
{ (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED }; |
| 2350 |
|
| 2351 |
static const SDLTest_TestCaseReference videoTest17 = |
| 2352 |
{ (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED }; |
| 2353 |
|
| 2354 |
static const SDLTest_TestCaseReference videoTest18 = |
| 2355 |
{ (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED }; |
| 2356 |
|
| 2357 |
static const SDLTest_TestCaseReference videoTest19 = |
| 2358 |
{ (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED }; |
| 2359 |
|
| 2360 |
static const SDLTest_TestCaseReference videoTest20 = |
| 2361 |
{ (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED }; |
| 2362 |
|
| 2363 |
static const SDLTest_TestCaseReference videoTest21 = |
| 2364 |
{ (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED }; |
| 2365 |
|
| 2366 |
static const SDLTest_TestCaseReference videoTest22 = |
| 2367 |
{ (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED }; |
| 2368 |
|
| 2369 |
static const SDLTest_TestCaseReference videoTest23 = |
| 2370 |
{ (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED }; |
| 2371 |
|
| 2372 |
static const SDLTest_TestCaseReference videoTest24 = |
| 2373 |
{ (SDLTest_TestCaseFp) video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED }; |
| 2374 |
|
| 2375 |
static const SDLTest_TestCaseReference videoTest25 = { |
| 2376 |
(SDLTest_TestCaseFp)video_getWindowSurface, "video_getWindowSurface", "Checks window surface functionality", TEST_ENABLED |
| 2377 |
}; |
| 2378 |
static const SDLTest_TestCaseReference videoTest26 = { |
| 2379 |
(SDLTest_TestCaseFp)video_setWindowInputFocus, "video_setWindowInputFocus", "Checks window input focus", TEST_ENABLED |
| 2380 |
}; |
| 2381 |
|
| 2382 |
/* Sequence of Video test cases */ |
| 2383 |
static const SDLTest_TestCaseReference *videoTests[] = { |
| 2384 |
&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, |
| 2385 |
&videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, |
| 2386 |
&videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17, |
| 2387 |
&videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22, |
| 2388 |
&videoTest23, &videoTest24, &videoTest25, &videoTest26, NULL |
| 2389 |
}; |
| 2390 |
|
| 2391 |
/* Video test suite (global) */ |
| 2392 |
SDLTest_TestSuiteReference videoTestSuite = { |
| 2393 |
"Video", |
| 2394 |
NULL, |
| 2395 |
videoTests, |
| 2396 |
NULL |
| 2397 |
}; |