testautomation_video.c 74 KB

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