🛠️🐜 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.

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