testautomation_video.c 74 KB

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