testautomation_video.c 74 KB

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