🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2145 lines
85 KiB

  1. /**
  2. * Video test suite
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. /* Visual Studio 2008 doesn't have stdint.h */
  7. #if defined(_MSC_VER) && _MSC_VER <= 1500
  8. #define UINT8_MAX ~(Uint8)0
  9. #define UINT16_MAX ~(Uint16)0
  10. #define UINT32_MAX ~(Uint32)0
  11. #define UINT64_MAX ~(Uint64)0
  12. #else
  13. #include <stdint.h>
  14. #endif
  15. #include "SDL.h"
  16. #include "SDL_test.h"
  17. /* Private helpers */
  18. /*
  19. * Create a test window
  20. */
  21. SDL_Window *_createVideoSuiteTestWindow(const char *title)
  22. {
  23. SDL_Window *window;
  24. int x, y, w, h;
  25. SDL_WindowFlags flags;
  26. /* Standard window */
  27. x = SDLTest_RandomIntegerInRange(1, 100);
  28. y = SDLTest_RandomIntegerInRange(1, 100);
  29. w = SDLTest_RandomIntegerInRange(320, 1024);
  30. h = SDLTest_RandomIntegerInRange(320, 768);
  31. flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
  32. window = SDL_CreateWindow(title, x, y, w, h, flags);
  33. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
  34. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  35. return window;
  36. }
  37. /*
  38. * Destroy test window
  39. */
  40. void _destroyVideoSuiteTestWindow(SDL_Window *window)
  41. {
  42. if (window != NULL) {
  43. SDL_DestroyWindow(window);
  44. window = NULL;
  45. SDLTest_AssertPass("Call to SDL_DestroyWindow()");
  46. }
  47. }
  48. /* Test case functions */
  49. /**
  50. * @brief Enable and disable screensaver while checking state
  51. */
  52. int video_enableDisableScreensaver(void *arg)
  53. {
  54. SDL_bool initialResult;
  55. SDL_bool result;
  56. /* Get current state and proceed according to current state */
  57. initialResult = SDL_IsScreenSaverEnabled();
  58. SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
  59. if (initialResult == SDL_TRUE) {
  60. /* Currently enabled: disable first, then enable again */
  61. /* Disable screensaver and check */
  62. SDL_DisableScreenSaver();
  63. SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
  64. result = SDL_IsScreenSaverEnabled();
  65. SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
  66. SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
  67. /* Enable screensaver and check */
  68. SDL_EnableScreenSaver();
  69. SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
  70. result = SDL_IsScreenSaverEnabled();
  71. SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
  72. SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
  73. } else {
  74. /* Currently disabled: enable first, then disable again */
  75. /* Enable screensaver and check */
  76. SDL_EnableScreenSaver();
  77. SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
  78. result = SDL_IsScreenSaverEnabled();
  79. SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
  80. SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
  81. /* Disable screensaver and check */
  82. SDL_DisableScreenSaver();
  83. SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
  84. result = SDL_IsScreenSaverEnabled();
  85. SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
  86. SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
  87. }
  88. return TEST_COMPLETED;
  89. }
  90. /**
  91. * @brief Tests the functionality of the SDL_CreateWindow function using different positions
  92. */
  93. int video_createWindowVariousPositions(void *arg)
  94. {
  95. SDL_Window *window;
  96. const char *title = "video_createWindowVariousPositions Test Window";
  97. int x, y, w, h;
  98. int xVariation, yVariation;
  99. for (xVariation = 0; xVariation < 6; xVariation++) {
  100. for (yVariation = 0; yVariation < 6; yVariation++) {
  101. switch (xVariation) {
  102. default:
  103. case 0:
  104. /* Zero X Position */
  105. x = 0;
  106. break;
  107. case 1:
  108. /* Random X position inside screen */
  109. x = SDLTest_RandomIntegerInRange(1, 100);
  110. break;
  111. case 2:
  112. /* Random X position outside screen (positive) */
  113. x = SDLTest_RandomIntegerInRange(10000, 11000);
  114. break;
  115. case 3:
  116. /* Random X position outside screen (negative) */
  117. x = SDLTest_RandomIntegerInRange(-1000, -100);
  118. break;
  119. case 4:
  120. /* Centered X position */
  121. x = SDL_WINDOWPOS_CENTERED;
  122. break;
  123. case 5:
  124. /* Undefined X position */
  125. x = SDL_WINDOWPOS_UNDEFINED;
  126. break;
  127. }
  128. switch (yVariation) {
  129. default:
  130. case 0:
  131. /* Zero X Position */
  132. y = 0;
  133. break;
  134. case 1:
  135. /* Random X position inside screen */
  136. y = SDLTest_RandomIntegerInRange(1, 100);
  137. break;
  138. case 2:
  139. /* Random X position outside screen (positive) */
  140. y = SDLTest_RandomIntegerInRange(10000, 11000);
  141. break;
  142. case 3:
  143. /* Random Y position outside screen (negative) */
  144. y = SDLTest_RandomIntegerInRange(-1000, -100);
  145. break;
  146. case 4:
  147. /* Centered Y position */
  148. y = SDL_WINDOWPOS_CENTERED;
  149. break;
  150. case 5:
  151. /* Undefined Y position */
  152. y = SDL_WINDOWPOS_UNDEFINED;
  153. break;
  154. }
  155. w = SDLTest_RandomIntegerInRange(32, 96);
  156. h = SDLTest_RandomIntegerInRange(32, 96);
  157. window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
  158. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
  159. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  160. /* Clean up */
  161. _destroyVideoSuiteTestWindow(window);
  162. }
  163. }
  164. return TEST_COMPLETED;
  165. }
  166. /**
  167. * @brief Tests the functionality of the SDL_CreateWindow function using different sizes
  168. */
  169. int video_createWindowVariousSizes(void *arg)
  170. {
  171. SDL_Window *window;
  172. const char *title = "video_createWindowVariousSizes Test Window";
  173. int x, y, w, h;
  174. int wVariation, hVariation;
  175. x = SDLTest_RandomIntegerInRange(1, 100);
  176. y = SDLTest_RandomIntegerInRange(1, 100);
  177. for (wVariation = 0; wVariation < 3; wVariation++) {
  178. for (hVariation = 0; hVariation < 3; hVariation++) {
  179. switch (wVariation) {
  180. case 0:
  181. /* Width of 1 */
  182. w = 1;
  183. break;
  184. case 1:
  185. /* Random "normal" width */
  186. w = SDLTest_RandomIntegerInRange(320, 1920);
  187. break;
  188. case 2:
  189. /* Random "large" width */
  190. w = SDLTest_RandomIntegerInRange(2048, 4095);
  191. break;
  192. }
  193. switch (hVariation) {
  194. case 0:
  195. /* Height of 1 */
  196. h = 1;
  197. break;
  198. case 1:
  199. /* Random "normal" height */
  200. h = SDLTest_RandomIntegerInRange(320, 1080);
  201. break;
  202. case 2:
  203. /* Random "large" height */
  204. h = SDLTest_RandomIntegerInRange(2048, 4095);
  205. break;
  206. }
  207. window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
  208. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
  209. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  210. /* Clean up */
  211. _destroyVideoSuiteTestWindow(window);
  212. }
  213. }
  214. return TEST_COMPLETED;
  215. }
  216. /**
  217. * @brief Tests the functionality of the SDL_CreateWindow function using different flags
  218. */
  219. int video_createWindowVariousFlags(void *arg)
  220. {
  221. SDL_Window *window;
  222. const char *title = "video_createWindowVariousFlags Test Window";
  223. int x, y, w, h;
  224. int fVariation;
  225. SDL_WindowFlags flags;
  226. /* Standard window */
  227. x = SDLTest_RandomIntegerInRange(1, 100);
  228. y = SDLTest_RandomIntegerInRange(1, 100);
  229. w = SDLTest_RandomIntegerInRange(320, 1024);
  230. h = SDLTest_RandomIntegerInRange(320, 768);
  231. for (fVariation = 0; fVariation < 14; fVariation++) {
  232. switch (fVariation) {
  233. default:
  234. case 0:
  235. flags = SDL_WINDOW_FULLSCREEN;
  236. /* Skip - blanks screen; comment out next line to run test */
  237. continue;
  238. break;
  239. case 1:
  240. flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
  241. /* Skip - blanks screen; comment out next line to run test */
  242. continue;
  243. break;
  244. case 2:
  245. flags = SDL_WINDOW_OPENGL;
  246. break;
  247. case 3:
  248. flags = SDL_WINDOW_SHOWN;
  249. break;
  250. case 4:
  251. flags = SDL_WINDOW_HIDDEN;
  252. break;
  253. case 5:
  254. flags = SDL_WINDOW_BORDERLESS;
  255. break;
  256. case 6:
  257. flags = SDL_WINDOW_RESIZABLE;
  258. break;
  259. case 7:
  260. flags = SDL_WINDOW_MINIMIZED;
  261. break;
  262. case 8:
  263. flags = SDL_WINDOW_MAXIMIZED;
  264. break;
  265. case 9:
  266. flags = SDL_WINDOW_MOUSE_GRABBED;
  267. break;
  268. case 10:
  269. flags = SDL_WINDOW_INPUT_FOCUS;
  270. break;
  271. case 11:
  272. flags = SDL_WINDOW_MOUSE_FOCUS;
  273. break;
  274. case 12:
  275. flags = SDL_WINDOW_FOREIGN;
  276. break;
  277. case 13:
  278. flags = SDL_WINDOW_KEYBOARD_GRABBED;
  279. break;
  280. }
  281. window = SDL_CreateWindow(title, x, y, w, h, flags);
  282. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
  283. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  284. /* Clean up */
  285. _destroyVideoSuiteTestWindow(window);
  286. }
  287. return TEST_COMPLETED;
  288. }
  289. /**
  290. * @brief Tests the functionality of the SDL_GetWindowFlags function
  291. */
  292. int video_getWindowFlags(void *arg)
  293. {
  294. SDL_Window *window;
  295. const char *title = "video_getWindowFlags Test Window";
  296. SDL_WindowFlags flags;
  297. Uint32 actualFlags;
  298. /* Reliable flag set always set in test window */
  299. flags = SDL_WINDOW_SHOWN;
  300. /* Call against new test window */
  301. window = _createVideoSuiteTestWindow(title);
  302. if (window != NULL) {
  303. actualFlags = SDL_GetWindowFlags(window);
  304. SDLTest_AssertPass("Call to SDL_GetWindowFlags()");
  305. SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %" SDL_PRIu32, flags, actualFlags);
  306. }
  307. /* Clean up */
  308. _destroyVideoSuiteTestWindow(window);
  309. return TEST_COMPLETED;
  310. }
  311. /**
  312. * @brief Tests the functionality of the SDL_GetNumDisplayModes function
  313. */
  314. int video_getNumDisplayModes(void *arg)
  315. {
  316. int result;
  317. int displayNum;
  318. int i;
  319. /* Get number of displays */
  320. displayNum = SDL_GetNumVideoDisplays();
  321. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  322. /* Make call for each display */
  323. for (i = 0; i < displayNum; i++) {
  324. result = SDL_GetNumDisplayModes(i);
  325. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
  326. SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
  327. }
  328. return TEST_COMPLETED;
  329. }
  330. /**
  331. * @brief Tests negative call to SDL_GetNumDisplayModes function
  332. */
  333. int video_getNumDisplayModesNegative(void *arg)
  334. {
  335. int result;
  336. int displayNum;
  337. int displayIndex;
  338. /* Get number of displays */
  339. displayNum = SDL_GetNumVideoDisplays();
  340. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  341. /* Invalid boundary values */
  342. displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
  343. result = SDL_GetNumDisplayModes(displayIndex);
  344. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
  345. SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
  346. /* Large (out-of-bounds) display index */
  347. displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
  348. result = SDL_GetNumDisplayModes(displayIndex);
  349. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
  350. SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
  351. displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
  352. result = SDL_GetNumDisplayModes(displayIndex);
  353. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
  354. SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
  355. return TEST_COMPLETED;
  356. }
  357. /**
  358. * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
  359. */
  360. int video_getClosestDisplayModeCurrentResolution(void *arg)
  361. {
  362. int result;
  363. SDL_DisplayMode current;
  364. SDL_DisplayMode target;
  365. SDL_DisplayMode closest;
  366. SDL_DisplayMode *dResult;
  367. int displayNum;
  368. int i;
  369. int variation;
  370. /* Get number of displays */
  371. displayNum = SDL_GetNumVideoDisplays();
  372. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  373. /* Make calls for each display */
  374. for (i = 0; i < displayNum; i++) {
  375. SDLTest_Log("Testing against display: %d", i);
  376. /* Get first display mode to get a sane resolution; this should always work */
  377. result = SDL_GetDisplayMode(i, 0, &current);
  378. SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
  379. SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
  380. if (result != 0) {
  381. return TEST_ABORTED;
  382. }
  383. /* Set the desired resolution equals to current resolution */
  384. target.w = current.w;
  385. target.h = current.h;
  386. for (variation = 0; variation < 8; variation++) {
  387. /* Vary constraints on other query parameters */
  388. target.format = (variation & 1) ? current.format : 0;
  389. target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
  390. target.driverdata = (variation & 4) ? current.driverdata : 0;
  391. /* Make call */
  392. dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
  393. SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
  394. SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL");
  395. /* Check that one gets the current resolution back again */
  396. SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
  397. SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
  398. /* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */
  399. SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
  400. SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
  401. /* NOLINTEND(clang-analyzer-core.NullDereference) */
  402. }
  403. }
  404. return TEST_COMPLETED;
  405. }
  406. /**
  407. * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
  408. */
  409. int video_getClosestDisplayModeRandomResolution(void *arg)
  410. {
  411. SDL_DisplayMode target;
  412. SDL_DisplayMode closest;
  413. int displayNum;
  414. int i;
  415. int variation;
  416. /* Get number of displays */
  417. displayNum = SDL_GetNumVideoDisplays();
  418. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  419. /* Make calls for each display */
  420. for (i = 0; i < displayNum; i++) {
  421. SDLTest_Log("Testing against display: %d", i);
  422. for (variation = 0; variation < 16; variation++) {
  423. /* Set random constraints */
  424. target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  425. target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  426. target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
  427. target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
  428. target.driverdata = 0;
  429. /* Make call; may or may not find anything, so don't validate any further */
  430. SDL_GetClosestDisplayMode(i, &target, &closest);
  431. SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
  432. }
  433. }
  434. return TEST_COMPLETED;
  435. }
  436. /**
  437. * @brief Tests call to SDL_GetWindowBrightness
  438. *
  439. * @sa http://wiki.libsdl.org/SDL_GetWindowBrightness
  440. */
  441. int
  442. video_getWindowBrightness(void *arg)
  443. {
  444. SDL_Window* window;
  445. const char* title = "video_getWindowBrightness Test Window";
  446. float result;
  447. /* Call against new test window */
  448. window = _createVideoSuiteTestWindow(title);
  449. if (window != NULL) {
  450. result = SDL_GetWindowBrightness(window);
  451. SDLTest_AssertPass("Call to SDL_GetWindowBrightness()");
  452. SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
  453. }
  454. /* Clean up */
  455. _destroyVideoSuiteTestWindow(window);
  456. return TEST_COMPLETED;
  457. }
  458. /**
  459. * @brief Tests call to SDL_GetWindowBrightness with invalid input
  460. *
  461. * @sa http://wiki.libsdl.org/SDL_GetWindowBrightness
  462. */
  463. int
  464. video_getWindowBrightnessNegative(void *arg)
  465. {
  466. const char *invalidWindowError = "Invalid window";
  467. char *lastError;
  468. float result;
  469. /* Call against invalid window */
  470. result = SDL_GetWindowBrightness(NULL);
  471. SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)");
  472. SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result);
  473. lastError = (char *)SDL_GetError();
  474. SDLTest_AssertPass("SDL_GetError()");
  475. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  476. if (lastError != NULL) {
  477. SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
  478. "SDL_GetError(): expected message '%s', was message: '%s'",
  479. invalidWindowError,
  480. lastError);
  481. }
  482. return TEST_COMPLETED;
  483. }
  484. /**
  485. * @brief Tests call to SDL_GetWindowDisplayMode
  486. *
  487. * @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
  488. */
  489. int video_getWindowDisplayMode(void *arg)
  490. {
  491. SDL_Window *window;
  492. const char *title = "video_getWindowDisplayMode Test Window";
  493. SDL_DisplayMode mode;
  494. int result;
  495. /* Invalidate part of the mode content so we can check values later */
  496. mode.w = -1;
  497. mode.h = -1;
  498. mode.refresh_rate = -1;
  499. /* Call against new test window */
  500. window = _createVideoSuiteTestWindow(title);
  501. if (window != NULL) {
  502. result = SDL_GetWindowDisplayMode(window, &mode);
  503. SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()");
  504. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  505. SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w);
  506. SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h);
  507. SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate);
  508. }
  509. /* Clean up */
  510. _destroyVideoSuiteTestWindow(window);
  511. return TEST_COMPLETED;
  512. }
  513. /* Helper function that checks for an 'Invalid window' error */
  514. void _checkInvalidWindowError()
  515. {
  516. const char *invalidWindowError = "Invalid window";
  517. char *lastError;
  518. lastError = (char *)SDL_GetError();
  519. SDLTest_AssertPass("SDL_GetError()");
  520. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  521. if (lastError != NULL) {
  522. SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
  523. "SDL_GetError(): expected message '%s', was message: '%s'",
  524. invalidWindowError,
  525. lastError);
  526. SDL_ClearError();
  527. SDLTest_AssertPass("Call to SDL_ClearError()");
  528. }
  529. }
  530. /**
  531. * @brief Tests call to SDL_GetWindowDisplayMode with invalid input
  532. *
  533. * @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
  534. */
  535. int video_getWindowDisplayModeNegative(void *arg)
  536. {
  537. const char *expectedError = "Parameter 'mode' is invalid";
  538. char *lastError;
  539. SDL_Window *window;
  540. const char *title = "video_getWindowDisplayModeNegative Test Window";
  541. SDL_DisplayMode mode;
  542. int result;
  543. /* Call against new test window */
  544. window = _createVideoSuiteTestWindow(title);
  545. if (window != NULL) {
  546. result = SDL_GetWindowDisplayMode(window, NULL);
  547. SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)");
  548. SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
  549. lastError = (char *)SDL_GetError();
  550. SDLTest_AssertPass("SDL_GetError()");
  551. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  552. if (lastError != NULL) {
  553. SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0,
  554. "SDL_GetError(): expected message '%s', was message: '%s'",
  555. expectedError,
  556. lastError);
  557. }
  558. }
  559. /* Clean up */
  560. _destroyVideoSuiteTestWindow(window);
  561. /* Call against invalid window */
  562. result = SDL_GetWindowDisplayMode(NULL, &mode);
  563. SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)");
  564. SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
  565. _checkInvalidWindowError();
  566. return TEST_COMPLETED;
  567. }
  568. /**
  569. * @brief Tests call to SDL_GetWindowGammaRamp
  570. *
  571. * @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp
  572. */
  573. int
  574. video_getWindowGammaRamp(void *arg)
  575. {
  576. SDL_Window* window;
  577. const char* title = "video_getWindowGammaRamp Test Window";
  578. Uint16 red[256];
  579. Uint16 green[256];
  580. Uint16 blue[256];
  581. int result;
  582. /* Call against new test window */
  583. window = _createVideoSuiteTestWindow(title);
  584. if (window == NULL) return TEST_ABORTED;
  585. /* Retrieve no channel */
  586. result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL);
  587. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)");
  588. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  589. /* Retrieve single channel */
  590. result = SDL_GetWindowGammaRamp(window, red, NULL, NULL);
  591. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)");
  592. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  593. result = SDL_GetWindowGammaRamp(window, NULL, green, NULL);
  594. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)");
  595. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  596. result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue);
  597. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)");
  598. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  599. /* Retrieve two channels */
  600. result = SDL_GetWindowGammaRamp(window, red, green, NULL);
  601. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)");
  602. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  603. result = SDL_GetWindowGammaRamp(window, NULL, green, blue);
  604. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)");
  605. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  606. result = SDL_GetWindowGammaRamp(window, red, NULL, blue);
  607. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)");
  608. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  609. /* Retrieve all channels */
  610. result = SDL_GetWindowGammaRamp(window, red, green, blue);
  611. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)");
  612. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  613. /* Clean up */
  614. _destroyVideoSuiteTestWindow(window);
  615. return TEST_COMPLETED;
  616. }
  617. /**
  618. * @brief Tests call to SDL_GetWindowGammaRamp with invalid input
  619. *
  620. * @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp
  621. */
  622. int
  623. video_getWindowGammaRampNegative(void *arg)
  624. {
  625. Uint16 red[256];
  626. Uint16 green[256];
  627. Uint16 blue[256];
  628. int result;
  629. SDL_ClearError();
  630. SDLTest_AssertPass("Call to SDL_ClearError()");
  631. /* Call against invalid window */
  632. result = SDL_GetWindowGammaRamp(NULL, red, green, blue);
  633. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)");
  634. SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %i", result);
  635. _checkInvalidWindowError();
  636. return TEST_COMPLETED;
  637. }
  638. /* Helper for setting and checking the window mouse grab state */
  639. void _setAndCheckWindowMouseGrabState(SDL_Window *window, SDL_bool desiredState)
  640. {
  641. SDL_bool currentState;
  642. /* Set state */
  643. SDL_SetWindowMouseGrab(window, desiredState);
  644. SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  645. /* Get and check state */
  646. currentState = SDL_GetWindowMouseGrab(window);
  647. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  648. SDLTest_AssertCheck(
  649. currentState == desiredState,
  650. "Validate returned state; expected: %s, got: %s",
  651. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  652. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  653. if (desiredState) {
  654. SDLTest_AssertCheck(
  655. SDL_GetGrabbedWindow() == window,
  656. "Grabbed window should be to our window");
  657. SDLTest_AssertCheck(
  658. SDL_GetWindowGrab(window),
  659. "SDL_GetWindowGrab() should return SDL_TRUE");
  660. SDLTest_AssertCheck(
  661. SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED,
  662. "SDL_WINDOW_MOUSE_GRABBED should be set");
  663. } else {
  664. SDLTest_AssertCheck(
  665. !(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED),
  666. "SDL_WINDOW_MOUSE_GRABBED should be unset");
  667. }
  668. }
  669. /* Helper for setting and checking the window keyboard grab state */
  670. void _setAndCheckWindowKeyboardGrabState(SDL_Window *window, SDL_bool desiredState)
  671. {
  672. SDL_bool currentState;
  673. /* Set state */
  674. SDL_SetWindowKeyboardGrab(window, desiredState);
  675. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  676. /* Get and check state */
  677. currentState = SDL_GetWindowKeyboardGrab(window);
  678. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  679. SDLTest_AssertCheck(
  680. currentState == desiredState,
  681. "Validate returned state; expected: %s, got: %s",
  682. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  683. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  684. if (desiredState) {
  685. SDLTest_AssertCheck(
  686. SDL_GetGrabbedWindow() == window,
  687. "Grabbed window should be set to our window");
  688. SDLTest_AssertCheck(
  689. SDL_GetWindowGrab(window),
  690. "SDL_GetWindowGrab() should return SDL_TRUE");
  691. SDLTest_AssertCheck(
  692. SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED,
  693. "SDL_WINDOW_KEYBOARD_GRABBED should be set");
  694. } else {
  695. SDLTest_AssertCheck(
  696. !(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED),
  697. "SDL_WINDOW_KEYBOARD_GRABBED should be unset");
  698. }
  699. }
  700. /**
  701. * @brief Tests keyboard and mouse grab support
  702. *
  703. * @sa http://wiki.libsdl.org/SDL_GetWindowGrab
  704. * @sa http://wiki.libsdl.org/SDL_SetWindowGrab
  705. */
  706. int video_getSetWindowGrab(void *arg)
  707. {
  708. const char *title = "video_getSetWindowGrab Test Window";
  709. SDL_Window *window;
  710. SDL_bool originalMouseState, originalKeyboardState;
  711. /* Call against new test window */
  712. window = _createVideoSuiteTestWindow(title);
  713. if (window == NULL) {
  714. return TEST_ABORTED;
  715. }
  716. /* Get state */
  717. originalMouseState = SDL_GetWindowMouseGrab(window);
  718. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  719. originalKeyboardState = SDL_GetWindowKeyboardGrab(window);
  720. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  721. /* F */
  722. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  723. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  724. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  725. "SDL_GetWindowGrab should return SDL_FALSE");
  726. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  727. "Expected NULL grabbed window");
  728. /* F --> F */
  729. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  730. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  731. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  732. "Expected NULL grabbed window");
  733. /* F --> T */
  734. _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  735. _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  736. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  737. "SDL_GetWindowGrab() should return SDL_TRUE");
  738. /* T --> T */
  739. _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  740. _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  741. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  742. "SDL_GetWindowGrab() should return SDL_TRUE");
  743. /* M: T --> F */
  744. /* K: T --> T */
  745. _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  746. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  747. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  748. "SDL_GetWindowGrab() should return SDL_TRUE");
  749. /* M: F --> T */
  750. /* K: T --> F */
  751. _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  752. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  753. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  754. "SDL_GetWindowGrab() should return SDL_TRUE");
  755. /* M: T --> F */
  756. /* K: F --> F */
  757. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  758. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  759. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  760. "SDL_GetWindowGrab() should return SDL_FALSE");
  761. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  762. "Expected NULL grabbed window");
  763. /* Using the older SDL_SetWindowGrab API should only grab mouse by default */
  764. SDL_SetWindowGrab(window, SDL_TRUE);
  765. SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
  766. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  767. "SDL_GetWindowGrab() should return SDL_TRUE");
  768. SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
  769. "SDL_GetWindowMouseGrab() should return SDL_TRUE");
  770. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  771. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  772. SDL_SetWindowGrab(window, SDL_FALSE);
  773. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  774. "SDL_GetWindowGrab() should return SDL_FALSE");
  775. SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
  776. "SDL_GetWindowMouseGrab() should return SDL_FALSE");
  777. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  778. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  779. /* Now test with SDL_HINT_GRAB_KEYBOARD set. We should get keyboard grab now. */
  780. SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
  781. SDL_SetWindowGrab(window, SDL_TRUE);
  782. SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
  783. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  784. "SDL_GetWindowGrab() should return SDL_TRUE");
  785. SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
  786. "SDL_GetWindowMouseGrab() should return SDL_TRUE");
  787. SDLTest_AssertCheck(SDL_GetWindowKeyboardGrab(window),
  788. "SDL_GetWindowKeyboardGrab() should return SDL_TRUE");
  789. SDL_SetWindowGrab(window, SDL_FALSE);
  790. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  791. "SDL_GetWindowGrab() should return SDL_FALSE");
  792. SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
  793. "SDL_GetWindowMouseGrab() should return SDL_FALSE");
  794. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  795. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  796. /* Negative tests */
  797. SDL_GetWindowGrab(NULL);
  798. SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
  799. _checkInvalidWindowError();
  800. SDL_GetWindowKeyboardGrab(NULL);
  801. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)");
  802. _checkInvalidWindowError();
  803. SDL_SetWindowGrab(NULL, SDL_FALSE);
  804. SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
  805. _checkInvalidWindowError();
  806. SDL_SetWindowKeyboardGrab(NULL, SDL_FALSE);
  807. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE)");
  808. _checkInvalidWindowError();
  809. SDL_SetWindowGrab(NULL, SDL_TRUE);
  810. SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_TRUE)");
  811. _checkInvalidWindowError();
  812. SDL_SetWindowKeyboardGrab(NULL, SDL_TRUE);
  813. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE)");
  814. _checkInvalidWindowError();
  815. /* Restore state */
  816. _setAndCheckWindowMouseGrabState(window, originalMouseState);
  817. _setAndCheckWindowKeyboardGrabState(window, originalKeyboardState);
  818. /* Clean up */
  819. _destroyVideoSuiteTestWindow(window);
  820. return TEST_COMPLETED;
  821. }
  822. /**
  823. * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID
  824. *
  825. * @sa http://wiki.libsdl.org/SDL_GetWindowID
  826. * @sa http://wiki.libsdl.org/SDL_SetWindowFromID
  827. */
  828. int video_getWindowId(void *arg)
  829. {
  830. const char *title = "video_getWindowId Test Window";
  831. SDL_Window *window;
  832. SDL_Window *result;
  833. Uint32 id, randomId;
  834. /* Call against new test window */
  835. window = _createVideoSuiteTestWindow(title);
  836. if (window == NULL) {
  837. return TEST_ABORTED;
  838. }
  839. /* Get ID */
  840. id = SDL_GetWindowID(window);
  841. SDLTest_AssertPass("Call to SDL_GetWindowID()");
  842. /* Get window from ID */
  843. result = SDL_GetWindowFromID(id);
  844. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 ")", id);
  845. SDLTest_AssertCheck(result == window, "Verify result matches window pointer");
  846. /* Get window from random large ID, no result check */
  847. randomId = SDLTest_RandomIntegerInRange(UINT8_MAX, UINT16_MAX);
  848. result = SDL_GetWindowFromID(randomId);
  849. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/random_large)", randomId);
  850. /* Get window from 0 and Uint32 max ID, no result check */
  851. result = SDL_GetWindowFromID(0);
  852. SDLTest_AssertPass("Call to SDL_GetWindowID(0)");
  853. result = SDL_GetWindowFromID(UINT32_MAX);
  854. SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)");
  855. /* Clean up */
  856. _destroyVideoSuiteTestWindow(window);
  857. /* Get window from ID for closed window */
  858. result = SDL_GetWindowFromID(id);
  859. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/closed_window)", id);
  860. SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
  861. /* Negative test */
  862. SDL_ClearError();
  863. SDLTest_AssertPass("Call to SDL_ClearError()");
  864. id = SDL_GetWindowID(NULL);
  865. SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
  866. _checkInvalidWindowError();
  867. return TEST_COMPLETED;
  868. }
  869. /**
  870. * @brief Tests call to SDL_GetWindowPixelFormat
  871. *
  872. * @sa http://wiki.libsdl.org/SDL_GetWindowPixelFormat
  873. */
  874. int video_getWindowPixelFormat(void *arg)
  875. {
  876. const char *title = "video_getWindowPixelFormat Test Window";
  877. SDL_Window *window;
  878. Uint32 format;
  879. /* Call against new test window */
  880. window = _createVideoSuiteTestWindow(title);
  881. if (window == NULL) {
  882. return TEST_ABORTED;
  883. }
  884. /* Get format */
  885. format = SDL_GetWindowPixelFormat(window);
  886. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
  887. SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %" SDL_PRIu32, SDL_PIXELFORMAT_UNKNOWN, format);
  888. /* Clean up */
  889. _destroyVideoSuiteTestWindow(window);
  890. /* Negative test */
  891. SDL_ClearError();
  892. SDLTest_AssertPass("Call to SDL_ClearError()");
  893. format = SDL_GetWindowPixelFormat(NULL);
  894. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
  895. _checkInvalidWindowError();
  896. return TEST_COMPLETED;
  897. }
  898. static SDL_bool getPositionFromEvent(int *x, int *y)
  899. {
  900. SDL_bool ret = SDL_FALSE;
  901. SDL_Event evt;
  902. SDL_zero(evt);
  903. while (SDL_PollEvent(&evt)) {
  904. if (evt.type == SDL_WINDOWEVENT && evt.window.event == SDL_WINDOWEVENT_MOVED) {
  905. *x = evt.window.data1;
  906. *y = evt.window.data2;
  907. ret = SDL_TRUE;
  908. }
  909. }
  910. return ret;
  911. }
  912. static SDL_bool getSizeFromEvent(int *w, int *h)
  913. {
  914. SDL_bool ret = SDL_FALSE;
  915. SDL_Event evt;
  916. SDL_zero(evt);
  917. while (SDL_PollEvent(&evt)) {
  918. if (evt.type == SDL_WINDOWEVENT && evt.window.event == SDL_WINDOWEVENT_RESIZED) {
  919. *w = evt.window.data1;
  920. *h = evt.window.data2;
  921. ret = SDL_TRUE;
  922. }
  923. }
  924. return ret;
  925. }
  926. /**
  927. * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
  928. *
  929. * @sa http://wiki.libsdl.org/SDL_GetWindowPosition
  930. * @sa http://wiki.libsdl.org/SDL_SetWindowPosition
  931. */
  932. int video_getSetWindowPosition(void *arg)
  933. {
  934. const char *title = "video_getSetWindowPosition Test Window";
  935. SDL_Window *window;
  936. int xVariation, yVariation;
  937. int referenceX, referenceY;
  938. int currentX, currentY;
  939. int desiredX, desiredY;
  940. /* Call against new test window */
  941. window = _createVideoSuiteTestWindow(title);
  942. if (window == NULL) {
  943. return TEST_ABORTED;
  944. }
  945. for (xVariation = 0; xVariation < 4; xVariation++) {
  946. for (yVariation = 0; yVariation < 4; yVariation++) {
  947. switch (xVariation) {
  948. default:
  949. case 0:
  950. /* Zero X Position */
  951. desiredX = 0;
  952. break;
  953. case 1:
  954. /* Random X position inside screen */
  955. desiredX = SDLTest_RandomIntegerInRange(1, 100);
  956. break;
  957. case 2:
  958. /* Random X position outside screen (positive) */
  959. desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
  960. break;
  961. case 3:
  962. /* Random X position outside screen (negative) */
  963. desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
  964. break;
  965. }
  966. switch (yVariation) {
  967. default:
  968. case 0:
  969. /* Zero X Position */
  970. desiredY = 0;
  971. break;
  972. case 1:
  973. /* Random X position inside screen */
  974. desiredY = SDLTest_RandomIntegerInRange(1, 100);
  975. break;
  976. case 2:
  977. /* Random X position outside screen (positive) */
  978. desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
  979. break;
  980. case 3:
  981. /* Random Y position outside screen (negative) */
  982. desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
  983. break;
  984. }
  985. /* Set position */
  986. SDL_SetWindowPosition(window, desiredX, desiredY);
  987. SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
  988. /* Get position */
  989. currentX = desiredX + 1;
  990. currentY = desiredY + 1;
  991. SDL_GetWindowPosition(window, &currentX, &currentY);
  992. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  993. if (desiredX == currentX && desiredY == currentY) {
  994. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  995. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  996. } else {
  997. SDL_bool hasEvent;
  998. /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
  999. * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */
  1000. desiredX = currentX + 1;
  1001. desiredY = currentY + 1;
  1002. hasEvent = getPositionFromEvent(&desiredX, &desiredY);
  1003. SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing position was not honored by WM, checking present of SDL_WINDOWEVENT_MOVED");
  1004. if (hasEvent) {
  1005. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position is the position from SDL event; expected: %d, got: %d", desiredX, currentX);
  1006. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position is the position from SDL event; expected: %d, got: %d", desiredY, currentY);
  1007. }
  1008. }
  1009. /* Get position X */
  1010. currentX = desiredX + 1;
  1011. SDL_GetWindowPosition(window, &currentX, NULL);
  1012. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
  1013. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  1014. /* Get position Y */
  1015. currentY = desiredY + 1;
  1016. SDL_GetWindowPosition(window, NULL, &currentY);
  1017. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
  1018. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  1019. }
  1020. }
  1021. /* Dummy call with both pointers NULL */
  1022. SDL_GetWindowPosition(window, NULL, NULL);
  1023. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
  1024. /* Clean up */
  1025. _destroyVideoSuiteTestWindow(window);
  1026. /* Set some 'magic' value for later check that nothing was changed */
  1027. referenceX = SDLTest_RandomSint32();
  1028. referenceY = SDLTest_RandomSint32();
  1029. currentX = referenceX;
  1030. currentY = referenceY;
  1031. desiredX = SDLTest_RandomSint32();
  1032. desiredY = SDLTest_RandomSint32();
  1033. /* Negative tests */
  1034. SDL_ClearError();
  1035. SDLTest_AssertPass("Call to SDL_ClearError()");
  1036. SDL_GetWindowPosition(NULL, &currentX, &currentY);
  1037. SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
  1038. SDLTest_AssertCheck(
  1039. currentX == referenceX && currentY == referenceY,
  1040. "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
  1041. referenceX, referenceY,
  1042. currentX, currentY);
  1043. _checkInvalidWindowError();
  1044. SDL_GetWindowPosition(NULL, NULL, NULL);
  1045. SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
  1046. _checkInvalidWindowError();
  1047. SDL_SetWindowPosition(NULL, desiredX, desiredY);
  1048. SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
  1049. _checkInvalidWindowError();
  1050. return TEST_COMPLETED;
  1051. }
  1052. /* Helper function that checks for an 'Invalid parameter' error */
  1053. void _checkInvalidParameterError()
  1054. {
  1055. const char *invalidParameterError = "Parameter";
  1056. char *lastError;
  1057. lastError = (char *)SDL_GetError();
  1058. SDLTest_AssertPass("SDL_GetError()");
  1059. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  1060. if (lastError != NULL) {
  1061. SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
  1062. "SDL_GetError(): expected message starts with '%s', was message: '%s'",
  1063. invalidParameterError,
  1064. lastError);
  1065. SDL_ClearError();
  1066. SDLTest_AssertPass("Call to SDL_ClearError()");
  1067. }
  1068. }
  1069. /**
  1070. * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize
  1071. *
  1072. * @sa http://wiki.libsdl.org/SDL_GetWindowSize
  1073. * @sa http://wiki.libsdl.org/SDL_SetWindowSize
  1074. */
  1075. int video_getSetWindowSize(void *arg)
  1076. {
  1077. const char *title = "video_getSetWindowSize Test Window";
  1078. SDL_Window *window;
  1079. int result;
  1080. SDL_Rect display;
  1081. int maxwVariation, maxhVariation;
  1082. int wVariation, hVariation;
  1083. int referenceW, referenceH;
  1084. int currentW, currentH;
  1085. int desiredW, desiredH;
  1086. /* Get display bounds for size range */
  1087. result = SDL_GetDisplayBounds(0, &display);
  1088. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1089. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1090. if (result != 0) {
  1091. return TEST_ABORTED;
  1092. }
  1093. /* Call against new test window */
  1094. window = _createVideoSuiteTestWindow(title);
  1095. if (window == NULL) {
  1096. return TEST_ABORTED;
  1097. }
  1098. #ifdef __WIN32__
  1099. /* Platform clips window size to screen size */
  1100. maxwVariation = 4;
  1101. maxhVariation = 4;
  1102. #else
  1103. /* Platform allows window size >= screen size */
  1104. maxwVariation = 5;
  1105. maxhVariation = 5;
  1106. #endif
  1107. for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
  1108. for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
  1109. switch (wVariation) {
  1110. default:
  1111. case 0:
  1112. /* 1 Pixel Wide */
  1113. desiredW = 1;
  1114. break;
  1115. case 1:
  1116. /* Random width inside screen */
  1117. desiredW = SDLTest_RandomIntegerInRange(1, 100);
  1118. break;
  1119. case 2:
  1120. /* Width 1 pixel smaller than screen */
  1121. desiredW = display.w - 1;
  1122. break;
  1123. case 3:
  1124. /* Width at screen size */
  1125. desiredW = display.w;
  1126. break;
  1127. case 4:
  1128. /* Width 1 pixel larger than screen */
  1129. desiredW = display.w + 1;
  1130. break;
  1131. }
  1132. switch (hVariation) {
  1133. default:
  1134. case 0:
  1135. /* 1 Pixel High */
  1136. desiredH = 1;
  1137. break;
  1138. case 1:
  1139. /* Random height inside screen */
  1140. desiredH = SDLTest_RandomIntegerInRange(1, 100);
  1141. break;
  1142. case 2:
  1143. /* Height 1 pixel smaller than screen */
  1144. desiredH = display.h - 1;
  1145. break;
  1146. case 3:
  1147. /* Height at screen size */
  1148. desiredH = display.h;
  1149. break;
  1150. case 4:
  1151. /* Height 1 pixel larger than screen */
  1152. desiredH = display.h + 1;
  1153. break;
  1154. }
  1155. /* Set size */
  1156. SDL_SetWindowSize(window, desiredW, desiredH);
  1157. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  1158. /* Get size */
  1159. currentW = desiredW + 1;
  1160. currentH = desiredH + 1;
  1161. SDL_GetWindowSize(window, &currentW, &currentH);
  1162. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1163. if (desiredW == currentW && desiredH == currentH) {
  1164. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1165. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1166. } else {
  1167. SDL_bool hasEvent;
  1168. /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
  1169. * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */
  1170. desiredW = currentW + 1;
  1171. desiredH = currentH + 1;
  1172. hasEvent = getSizeFromEvent(&desiredW, &desiredH);
  1173. SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing size was not honored by WM, checking presence of SDL_WINDOWEVENT_RESIZED");
  1174. if (hasEvent) {
  1175. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width is the one from SDL event; expected: %d, got: %d", desiredW, currentW);
  1176. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height is the one from SDL event; expected: %d, got: %d", desiredH, currentH);
  1177. }
  1178. }
  1179. /* Get just width */
  1180. currentW = desiredW + 1;
  1181. SDL_GetWindowSize(window, &currentW, NULL);
  1182. SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
  1183. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1184. /* Get just height */
  1185. currentH = desiredH + 1;
  1186. SDL_GetWindowSize(window, NULL, &currentH);
  1187. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
  1188. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1189. }
  1190. }
  1191. /* Dummy call with both pointers NULL */
  1192. SDL_GetWindowSize(window, NULL, NULL);
  1193. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
  1194. /* Negative tests for parameter input */
  1195. SDL_ClearError();
  1196. SDLTest_AssertPass("Call to SDL_ClearError()");
  1197. for (desiredH = -2; desiredH < 2; desiredH++) {
  1198. for (desiredW = -2; desiredW < 2; desiredW++) {
  1199. if (desiredW <= 0 || desiredH <= 0) {
  1200. SDL_SetWindowSize(window, desiredW, desiredH);
  1201. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  1202. _checkInvalidParameterError();
  1203. }
  1204. }
  1205. }
  1206. /* Clean up */
  1207. _destroyVideoSuiteTestWindow(window);
  1208. /* Set some 'magic' value for later check that nothing was changed */
  1209. referenceW = SDLTest_RandomSint32();
  1210. referenceH = SDLTest_RandomSint32();
  1211. currentW = referenceW;
  1212. currentH = referenceH;
  1213. desiredW = SDLTest_RandomSint32();
  1214. desiredH = SDLTest_RandomSint32();
  1215. /* Negative tests for window input */
  1216. SDL_ClearError();
  1217. SDLTest_AssertPass("Call to SDL_ClearError()");
  1218. SDL_GetWindowSize(NULL, &currentW, &currentH);
  1219. SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
  1220. SDLTest_AssertCheck(
  1221. currentW == referenceW && currentH == referenceH,
  1222. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1223. referenceW, referenceH,
  1224. currentW, currentH);
  1225. _checkInvalidWindowError();
  1226. SDL_GetWindowSize(NULL, NULL, NULL);
  1227. SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
  1228. _checkInvalidWindowError();
  1229. SDL_SetWindowSize(NULL, desiredW, desiredH);
  1230. SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
  1231. _checkInvalidWindowError();
  1232. return TEST_COMPLETED;
  1233. }
  1234. /**
  1235. * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
  1236. *
  1237. */
  1238. int video_getSetWindowMinimumSize(void *arg)
  1239. {
  1240. const char *title = "video_getSetWindowMinimumSize Test Window";
  1241. SDL_Window *window;
  1242. int result;
  1243. SDL_Rect display;
  1244. int wVariation, hVariation;
  1245. int referenceW, referenceH;
  1246. int currentW, currentH;
  1247. int desiredW = 1;
  1248. int desiredH = 1;
  1249. /* Get display bounds for size range */
  1250. result = SDL_GetDisplayBounds(0, &display);
  1251. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1252. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1253. if (result != 0) {
  1254. return TEST_ABORTED;
  1255. }
  1256. /* Call against new test window */
  1257. window = _createVideoSuiteTestWindow(title);
  1258. if (window == NULL) {
  1259. return TEST_ABORTED;
  1260. }
  1261. for (wVariation = 0; wVariation < 5; wVariation++) {
  1262. for (hVariation = 0; hVariation < 5; hVariation++) {
  1263. switch (wVariation) {
  1264. case 0:
  1265. /* 1 Pixel Wide */
  1266. desiredW = 1;
  1267. break;
  1268. case 1:
  1269. /* Random width inside screen */
  1270. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1271. break;
  1272. case 2:
  1273. /* Width at screen size */
  1274. desiredW = display.w;
  1275. break;
  1276. }
  1277. switch (hVariation) {
  1278. case 0:
  1279. /* 1 Pixel High */
  1280. desiredH = 1;
  1281. break;
  1282. case 1:
  1283. /* Random height inside screen */
  1284. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1285. break;
  1286. case 2:
  1287. /* Height at screen size */
  1288. desiredH = display.h;
  1289. break;
  1290. case 4:
  1291. /* Height 1 pixel larger than screen */
  1292. desiredH = display.h + 1;
  1293. break;
  1294. }
  1295. /* Set size */
  1296. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1297. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1298. /* Get size */
  1299. currentW = desiredW + 1;
  1300. currentH = desiredH + 1;
  1301. SDL_GetWindowMinimumSize(window, &currentW, &currentH);
  1302. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
  1303. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1304. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1305. /* Get just width */
  1306. currentW = desiredW + 1;
  1307. SDL_GetWindowMinimumSize(window, &currentW, NULL);
  1308. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
  1309. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1310. /* Get just height */
  1311. currentH = desiredH + 1;
  1312. SDL_GetWindowMinimumSize(window, NULL, &currentH);
  1313. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
  1314. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1315. }
  1316. }
  1317. /* Dummy call with both pointers NULL */
  1318. SDL_GetWindowMinimumSize(window, NULL, NULL);
  1319. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
  1320. /* Negative tests for parameter input */
  1321. SDL_ClearError();
  1322. SDLTest_AssertPass("Call to SDL_ClearError()");
  1323. for (desiredH = -2; desiredH < 2; desiredH++) {
  1324. for (desiredW = -2; desiredW < 2; desiredW++) {
  1325. if (desiredW <= 0 || desiredH <= 0) {
  1326. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1327. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1328. _checkInvalidParameterError();
  1329. }
  1330. }
  1331. }
  1332. /* Clean up */
  1333. _destroyVideoSuiteTestWindow(window);
  1334. /* Set some 'magic' value for later check that nothing was changed */
  1335. referenceW = SDLTest_RandomSint32();
  1336. referenceH = SDLTest_RandomSint32();
  1337. currentW = referenceW;
  1338. currentH = referenceH;
  1339. desiredW = SDLTest_RandomSint32();
  1340. desiredH = SDLTest_RandomSint32();
  1341. /* Negative tests for window input */
  1342. SDL_ClearError();
  1343. SDLTest_AssertPass("Call to SDL_ClearError()");
  1344. SDL_GetWindowMinimumSize(NULL, &currentW, &currentH);
  1345. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
  1346. SDLTest_AssertCheck(
  1347. currentW == referenceW && currentH == referenceH,
  1348. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1349. referenceW, referenceH,
  1350. currentW, currentH);
  1351. _checkInvalidWindowError();
  1352. SDL_GetWindowMinimumSize(NULL, NULL, NULL);
  1353. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
  1354. _checkInvalidWindowError();
  1355. SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
  1356. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
  1357. _checkInvalidWindowError();
  1358. return TEST_COMPLETED;
  1359. }
  1360. /**
  1361. * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
  1362. *
  1363. */
  1364. int video_getSetWindowMaximumSize(void *arg)
  1365. {
  1366. const char *title = "video_getSetWindowMaximumSize Test Window";
  1367. SDL_Window *window;
  1368. int result;
  1369. SDL_Rect display;
  1370. int wVariation, hVariation;
  1371. int referenceW, referenceH;
  1372. int currentW, currentH;
  1373. int desiredW, desiredH;
  1374. /* Get display bounds for size range */
  1375. result = SDL_GetDisplayBounds(0, &display);
  1376. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1377. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1378. if (result != 0) {
  1379. return TEST_ABORTED;
  1380. }
  1381. /* Call against new test window */
  1382. window = _createVideoSuiteTestWindow(title);
  1383. if (window == NULL) {
  1384. return TEST_ABORTED;
  1385. }
  1386. for (wVariation = 0; wVariation < 3; wVariation++) {
  1387. for (hVariation = 0; hVariation < 3; hVariation++) {
  1388. switch (wVariation) {
  1389. case 0:
  1390. /* 1 Pixel Wide */
  1391. desiredW = 1;
  1392. break;
  1393. case 1:
  1394. /* Random width inside screen */
  1395. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1396. break;
  1397. case 2:
  1398. /* Width at screen size */
  1399. desiredW = display.w;
  1400. break;
  1401. }
  1402. switch (hVariation) {
  1403. case 0:
  1404. /* 1 Pixel High */
  1405. desiredH = 1;
  1406. break;
  1407. case 1:
  1408. /* Random height inside screen */
  1409. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1410. break;
  1411. case 2:
  1412. /* Height at screen size */
  1413. desiredH = display.h;
  1414. break;
  1415. }
  1416. /* Set size */
  1417. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1418. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1419. /* Get size */
  1420. currentW = desiredW + 1;
  1421. currentH = desiredH + 1;
  1422. SDL_GetWindowMaximumSize(window, &currentW, &currentH);
  1423. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
  1424. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1425. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1426. /* Get just width */
  1427. currentW = desiredW + 1;
  1428. SDL_GetWindowMaximumSize(window, &currentW, NULL);
  1429. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
  1430. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1431. /* Get just height */
  1432. currentH = desiredH + 1;
  1433. SDL_GetWindowMaximumSize(window, NULL, &currentH);
  1434. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
  1435. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1436. }
  1437. }
  1438. /* Dummy call with both pointers NULL */
  1439. SDL_GetWindowMaximumSize(window, NULL, NULL);
  1440. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
  1441. /* Negative tests for parameter input */
  1442. SDL_ClearError();
  1443. SDLTest_AssertPass("Call to SDL_ClearError()");
  1444. for (desiredH = -2; desiredH < 2; desiredH++) {
  1445. for (desiredW = -2; desiredW < 2; desiredW++) {
  1446. if (desiredW <= 0 || desiredH <= 0) {
  1447. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1448. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1449. _checkInvalidParameterError();
  1450. }
  1451. }
  1452. }
  1453. /* Clean up */
  1454. _destroyVideoSuiteTestWindow(window);
  1455. /* Set some 'magic' value for later check that nothing was changed */
  1456. referenceW = SDLTest_RandomSint32();
  1457. referenceH = SDLTest_RandomSint32();
  1458. currentW = referenceW;
  1459. currentH = referenceH;
  1460. desiredW = SDLTest_RandomSint32();
  1461. desiredH = SDLTest_RandomSint32();
  1462. /* Negative tests */
  1463. SDL_ClearError();
  1464. SDLTest_AssertPass("Call to SDL_ClearError()");
  1465. SDL_GetWindowMaximumSize(NULL, &currentW, &currentH);
  1466. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
  1467. SDLTest_AssertCheck(
  1468. currentW == referenceW && currentH == referenceH,
  1469. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1470. referenceW, referenceH,
  1471. currentW, currentH);
  1472. _checkInvalidWindowError();
  1473. SDL_GetWindowMaximumSize(NULL, NULL, NULL);
  1474. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
  1475. _checkInvalidWindowError();
  1476. SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
  1477. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
  1478. _checkInvalidWindowError();
  1479. return TEST_COMPLETED;
  1480. }
  1481. /**
  1482. * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
  1483. *
  1484. * @sa http://wiki.libsdl.org/SDL_SetWindowData
  1485. * @sa http://wiki.libsdl.org/SDL_GetWindowData
  1486. */
  1487. int video_getSetWindowData(void *arg)
  1488. {
  1489. int returnValue = TEST_COMPLETED;
  1490. const char *title = "video_setGetWindowData Test Window";
  1491. SDL_Window *window;
  1492. const char *referenceName = "TestName";
  1493. const char *name = "TestName";
  1494. const char *referenceName2 = "TestName2";
  1495. const char *name2 = "TestName2";
  1496. int datasize;
  1497. char *referenceUserdata = NULL;
  1498. char *userdata = NULL;
  1499. char *referenceUserdata2 = NULL;
  1500. char *userdata2 = NULL;
  1501. char *result;
  1502. int iteration;
  1503. /* Call against new test window */
  1504. window = _createVideoSuiteTestWindow(title);
  1505. if (window == NULL) {
  1506. return TEST_ABORTED;
  1507. }
  1508. /* Create testdata */
  1509. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1510. referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
  1511. if (referenceUserdata == NULL) {
  1512. returnValue = TEST_ABORTED;
  1513. goto cleanup;
  1514. }
  1515. userdata = SDL_strdup(referenceUserdata);
  1516. if (userdata == NULL) {
  1517. returnValue = TEST_ABORTED;
  1518. goto cleanup;
  1519. }
  1520. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1521. referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
  1522. if (referenceUserdata2 == NULL) {
  1523. returnValue = TEST_ABORTED;
  1524. goto cleanup;
  1525. }
  1526. userdata2 = SDL_strdup(referenceUserdata2);
  1527. if (userdata2 == NULL) {
  1528. returnValue = TEST_ABORTED;
  1529. goto cleanup;
  1530. }
  1531. /* Get non-existent data */
  1532. result = (char *)SDL_GetWindowData(window, name);
  1533. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1534. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1535. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1536. /* Set data */
  1537. result = (char *)SDL_SetWindowData(window, name, userdata);
  1538. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
  1539. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1540. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1541. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1542. /* Get data (twice) */
  1543. for (iteration = 1; iteration <= 2; iteration++) {
  1544. result = (char *)SDL_GetWindowData(window, name);
  1545. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
  1546. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1547. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1548. }
  1549. /* Set data again twice */
  1550. for (iteration = 1; iteration <= 2; iteration++) {
  1551. result = (char *)SDL_SetWindowData(window, name, userdata);
  1552. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
  1553. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1554. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1555. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1556. }
  1557. /* Get data again */
  1558. result = (char *)SDL_GetWindowData(window, name);
  1559. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
  1560. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1561. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1562. /* Set data with new data */
  1563. result = (char *)SDL_SetWindowData(window, name, userdata2);
  1564. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
  1565. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1566. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1567. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1568. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1569. /* Set data with new data again */
  1570. result = (char *)SDL_SetWindowData(window, name, userdata2);
  1571. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
  1572. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1573. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1574. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1575. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1576. /* Get new data */
  1577. result = (char *)SDL_GetWindowData(window, name);
  1578. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1579. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1580. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1581. /* Set data with NULL to clear */
  1582. result = (char *)SDL_SetWindowData(window, name, NULL);
  1583. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
  1584. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1585. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1586. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1587. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1588. /* Set data with NULL to clear again */
  1589. result = (char *)SDL_SetWindowData(window, name, NULL);
  1590. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
  1591. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1592. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1593. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1594. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1595. /* Get non-existent data */
  1596. result = (char *)SDL_GetWindowData(window, name);
  1597. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1598. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1599. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1600. /* Get non-existent data new name */
  1601. result = (char *)SDL_GetWindowData(window, name2);
  1602. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
  1603. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1604. SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
  1605. /* Set data (again) */
  1606. result = (char *)SDL_SetWindowData(window, name, userdata);
  1607. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
  1608. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1609. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1610. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1611. /* Get data (again) */
  1612. result = (char *)SDL_GetWindowData(window, name);
  1613. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
  1614. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1615. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1616. /* Negative test */
  1617. SDL_ClearError();
  1618. SDLTest_AssertPass("Call to SDL_ClearError()");
  1619. /* Set with invalid window */
  1620. result = (char *)SDL_SetWindowData(NULL, name, userdata);
  1621. SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)");
  1622. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1623. _checkInvalidWindowError();
  1624. /* Set data with NULL name, valid userdata */
  1625. result = (char *)SDL_SetWindowData(window, NULL, userdata);
  1626. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
  1627. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1628. _checkInvalidParameterError();
  1629. /* Set data with empty name, valid userdata */
  1630. result = (char *)SDL_SetWindowData(window, "", userdata);
  1631. SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
  1632. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1633. _checkInvalidParameterError();
  1634. /* Set data with NULL name, NULL userdata */
  1635. result = (char *)SDL_SetWindowData(window, NULL, NULL);
  1636. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
  1637. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1638. _checkInvalidParameterError();
  1639. /* Set data with empty name, NULL userdata */
  1640. result = (char *)SDL_SetWindowData(window, "", NULL);
  1641. SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
  1642. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1643. _checkInvalidParameterError();
  1644. /* Get with invalid window */
  1645. result = (char *)SDL_GetWindowData(NULL, name);
  1646. SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)");
  1647. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1648. _checkInvalidWindowError();
  1649. /* Get data with NULL name */
  1650. result = (char *)SDL_GetWindowData(window, NULL);
  1651. SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
  1652. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1653. _checkInvalidParameterError();
  1654. /* Get data with empty name */
  1655. result = (char *)SDL_GetWindowData(window, "");
  1656. SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
  1657. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1658. _checkInvalidParameterError();
  1659. /* Clean up */
  1660. _destroyVideoSuiteTestWindow(window);
  1661. cleanup:
  1662. SDL_free(referenceUserdata);
  1663. SDL_free(referenceUserdata2);
  1664. SDL_free(userdata);
  1665. SDL_free(userdata2);
  1666. return returnValue;
  1667. }
  1668. /**
  1669. * @brief Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN_DESKTOP.
  1670. *
  1671. * Espeically useful when run on a multi-monitor system with different DPI scales per monitor,
  1672. * to test that the window size is maintained when moving between monitors.
  1673. */
  1674. int video_setWindowCenteredOnDisplay(void *arg)
  1675. {
  1676. SDL_Window *window;
  1677. const char *title = "video_setWindowCenteredOnDisplay Test Window";
  1678. int x, y, w, h;
  1679. int xVariation, yVariation;
  1680. int displayNum;
  1681. int result;
  1682. SDL_Rect display0, display1;
  1683. displayNum = SDL_GetNumVideoDisplays();
  1684. /* Get display bounds */
  1685. result = SDL_GetDisplayBounds(0 % displayNum, &display0);
  1686. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1687. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1688. if (result != 0) {
  1689. return TEST_ABORTED;
  1690. }
  1691. result = SDL_GetDisplayBounds(1 % displayNum, &display1);
  1692. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1693. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1694. if (result != 0) {
  1695. return TEST_ABORTED;
  1696. }
  1697. for (xVariation = 0; xVariation < 2; xVariation++) {
  1698. for (yVariation = 0; yVariation < 2; yVariation++) {
  1699. int currentX = 0, currentY = 0;
  1700. int currentW = 0, currentH = 0;
  1701. int expectedX = 0, expectedY = 0;
  1702. int currentDisplay;
  1703. int expectedDisplay;
  1704. SDL_Rect expectedDisplayRect;
  1705. /* xVariation is the display we start on */
  1706. expectedDisplay = xVariation % displayNum;
  1707. x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1708. y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1709. w = SDLTest_RandomIntegerInRange(640, 800);
  1710. h = SDLTest_RandomIntegerInRange(400, 600);
  1711. expectedDisplayRect = (xVariation == 0) ? display0 : display1;
  1712. expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
  1713. expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
  1714. window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
  1715. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
  1716. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  1717. /* Check the window is centered on the requested display */
  1718. currentDisplay = SDL_GetWindowDisplayIndex(window);
  1719. SDL_GetWindowSize(window, &currentW, &currentH);
  1720. SDL_GetWindowPosition(window, &currentX, &currentY);
  1721. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1722. SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
  1723. SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
  1724. SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
  1725. SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
  1726. /* Enter fullscreen desktop */
  1727. result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
  1728. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1729. /* Check we are filling the full display */
  1730. currentDisplay = SDL_GetWindowDisplayIndex(window);
  1731. SDL_GetWindowSize(window, &currentW, &currentH);
  1732. SDL_GetWindowPosition(window, &currentX, &currentY);
  1733. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1734. SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w);
  1735. SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h);
  1736. SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
  1737. SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
  1738. /* Leave fullscreen desktop */
  1739. result = SDL_SetWindowFullscreen(window, 0);
  1740. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1741. /* Check window was restored correctly */
  1742. currentDisplay = SDL_GetWindowDisplayIndex(window);
  1743. SDL_GetWindowSize(window, &currentW, &currentH);
  1744. SDL_GetWindowPosition(window, &currentX, &currentY);
  1745. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1746. SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
  1747. SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
  1748. SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
  1749. SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
  1750. /* Center on display yVariation, and check window properties */
  1751. expectedDisplay = yVariation % displayNum;
  1752. x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1753. y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1754. expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1;
  1755. expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
  1756. expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
  1757. SDL_SetWindowPosition(window, x, y);
  1758. currentDisplay = SDL_GetWindowDisplayIndex(window);
  1759. SDL_GetWindowSize(window, &currentW, &currentH);
  1760. SDL_GetWindowPosition(window, &currentX, &currentY);
  1761. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1762. SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
  1763. SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
  1764. SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
  1765. SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
  1766. /* Clean up */
  1767. _destroyVideoSuiteTestWindow(window);
  1768. }
  1769. }
  1770. return TEST_COMPLETED;
  1771. }
  1772. /* ================= Test References ================== */
  1773. /* Video test cases */
  1774. static const SDLTest_TestCaseReference videoTest1 = {
  1775. (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED
  1776. };
  1777. static const SDLTest_TestCaseReference videoTest2 = {
  1778. (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions", "Create windows at various locations", TEST_ENABLED
  1779. };
  1780. static const SDLTest_TestCaseReference videoTest3 = {
  1781. (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED
  1782. };
  1783. static const SDLTest_TestCaseReference videoTest4 = {
  1784. (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED
  1785. };
  1786. static const SDLTest_TestCaseReference videoTest5 = {
  1787. (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED
  1788. };
  1789. static const SDLTest_TestCaseReference videoTest6 = {
  1790. (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED
  1791. };
  1792. static const SDLTest_TestCaseReference videoTest7 = {
  1793. (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED
  1794. };
  1795. static const SDLTest_TestCaseReference videoTest8 = {
  1796. (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED
  1797. };
  1798. static const SDLTest_TestCaseReference videoTest9 = {
  1799. (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED
  1800. };
  1801. static const SDLTest_TestCaseReference videoTest10 =
  1802. { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED };
  1803. static const SDLTest_TestCaseReference videoTest11 =
  1804. { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED };
  1805. static const SDLTest_TestCaseReference videoTest12 =
  1806. { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED };
  1807. static const SDLTest_TestCaseReference videoTest13 =
  1808. { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED };
  1809. static const SDLTest_TestCaseReference videoTest14 =
  1810. { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED };
  1811. static const SDLTest_TestCaseReference videoTest15 =
  1812. { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED };
  1813. static const SDLTest_TestCaseReference videoTest16 =
  1814. { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED };
  1815. static const SDLTest_TestCaseReference videoTest17 =
  1816. { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED };
  1817. static const SDLTest_TestCaseReference videoTest18 =
  1818. { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED };
  1819. static const SDLTest_TestCaseReference videoTest19 =
  1820. { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED };
  1821. static const SDLTest_TestCaseReference videoTest20 =
  1822. { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED };
  1823. static const SDLTest_TestCaseReference videoTest21 =
  1824. { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED };
  1825. static const SDLTest_TestCaseReference videoTest22 =
  1826. { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED };
  1827. static const SDLTest_TestCaseReference videoTest23 =
  1828. { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
  1829. static const SDLTest_TestCaseReference videoTest24 =
  1830. { (SDLTest_TestCaseFp) video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED };
  1831. /* Sequence of Video test cases */
  1832. static const SDLTest_TestCaseReference *videoTests[] = {
  1833. &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
  1834. &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
  1835. &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
  1836. &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
  1837. &videoTest23, &videoTest24, NULL
  1838. };
  1839. /* Video test suite (global) */
  1840. SDLTest_TestSuiteReference videoTestSuite = {
  1841. "Video",
  1842. NULL,
  1843. videoTests,
  1844. NULL
  1845. };