testautomation_video.c 74 KB

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