testautomation_video.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407
  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. SDL_Window * const *windows;
  15. SDL_Event event;
  16. int w, h;
  17. int count;
  18. SDL_WindowFlags flags;
  19. SDL_bool needs_renderer = SDL_FALSE;
  20. SDL_bool needs_events_pumped = SDL_FALSE;
  21. /* Standard window */
  22. w = SDLTest_RandomIntegerInRange(320, 1024);
  23. h = SDLTest_RandomIntegerInRange(320, 768);
  24. flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
  25. window = SDL_CreateWindow(title, w, h, flags);
  26. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%" SDL_PRIu64 ")", w, h, flags);
  27. SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL");
  28. /* Check the window is available in the window list */
  29. windows = SDL_GetWindows(&count);
  30. SDLTest_AssertCheck(windows != NULL, "Validate that returned window list is not NULL");
  31. SDLTest_AssertCheck(windows[0] == window, "Validate that the window is first in the window list");
  32. /* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen.
  33. * This is required for the mouse/keyboard grab tests to pass.
  34. */
  35. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
  36. needs_renderer = SDL_TRUE;
  37. } else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
  38. /* Try to detect if the x11 driver is running under XWayland */
  39. const char *session_type = SDL_getenv("XDG_SESSION_TYPE");
  40. if (session_type && SDL_strcasecmp(session_type, "wayland") == 0) {
  41. needs_renderer = SDL_TRUE;
  42. }
  43. /* X11 needs the initial events pumped, or it can erroneously deliver old configuration events at a later time. */
  44. needs_events_pumped = SDL_TRUE;
  45. }
  46. if (needs_renderer) {
  47. SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL);
  48. if (renderer) {
  49. SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
  50. SDL_RenderClear(renderer);
  51. SDL_RenderPresent(renderer);
  52. /* Some desktops don't display the window immediately after presentation,
  53. * so delay to give the window time to actually appear on the desktop.
  54. */
  55. SDL_Delay(100);
  56. } else {
  57. SDLTest_Log("Unable to create a renderer, some tests may fail on Wayland/XWayland");
  58. }
  59. }
  60. if (needs_events_pumped) {
  61. /* Pump out the event queue */
  62. while (SDL_PollEvent(&event)) {
  63. }
  64. }
  65. return window;
  66. }
  67. /**
  68. * Destroy test window
  69. */
  70. static void destroyVideoSuiteTestWindow(SDL_Window *window)
  71. {
  72. if (window != NULL) {
  73. SDL_Renderer *renderer = SDL_GetRenderer(window);
  74. if (renderer) {
  75. SDL_DestroyRenderer(renderer);
  76. }
  77. SDL_DestroyWindow(window);
  78. window = NULL;
  79. SDLTest_AssertPass("Call to SDL_DestroyWindow()");
  80. }
  81. }
  82. /* Test case functions */
  83. /**
  84. * Enable and disable screensaver while checking state
  85. */
  86. static int video_enableDisableScreensaver(void *arg)
  87. {
  88. SDL_bool initialResult;
  89. SDL_bool result;
  90. /* Get current state and proceed according to current state */
  91. initialResult = SDL_ScreenSaverEnabled();
  92. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  93. if (initialResult == SDL_TRUE) {
  94. /* Currently enabled: disable first, then enable again */
  95. /* Disable screensaver and check */
  96. SDL_DisableScreenSaver();
  97. SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
  98. result = SDL_ScreenSaverEnabled();
  99. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  100. SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
  101. /* Enable screensaver and check */
  102. SDL_EnableScreenSaver();
  103. SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
  104. result = SDL_ScreenSaverEnabled();
  105. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  106. SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
  107. } else {
  108. /* Currently disabled: enable first, then disable again */
  109. /* Enable screensaver and check */
  110. SDL_EnableScreenSaver();
  111. SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
  112. result = SDL_ScreenSaverEnabled();
  113. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  114. SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
  115. /* Disable screensaver and check */
  116. SDL_DisableScreenSaver();
  117. SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
  118. result = SDL_ScreenSaverEnabled();
  119. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  120. SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
  121. }
  122. return TEST_COMPLETED;
  123. }
  124. /**
  125. * Tests the functionality of the SDL_CreateWindow function using different sizes
  126. */
  127. static int video_createWindowVariousSizes(void *arg)
  128. {
  129. SDL_Window *window;
  130. const char *title = "video_createWindowVariousSizes Test Window";
  131. int w = 0, h = 0;
  132. int wVariation, hVariation;
  133. for (wVariation = 0; wVariation < 3; wVariation++) {
  134. for (hVariation = 0; hVariation < 3; hVariation++) {
  135. switch (wVariation) {
  136. case 0:
  137. /* Width of 1 */
  138. w = 1;
  139. break;
  140. case 1:
  141. /* Random "normal" width */
  142. w = SDLTest_RandomIntegerInRange(320, 1920);
  143. break;
  144. case 2:
  145. /* Random "large" width */
  146. w = SDLTest_RandomIntegerInRange(2048, 4095);
  147. break;
  148. }
  149. switch (hVariation) {
  150. case 0:
  151. /* Height of 1 */
  152. h = 1;
  153. break;
  154. case 1:
  155. /* Random "normal" height */
  156. h = SDLTest_RandomIntegerInRange(320, 1080);
  157. break;
  158. case 2:
  159. /* Random "large" height */
  160. h = SDLTest_RandomIntegerInRange(2048, 4095);
  161. break;
  162. }
  163. window = SDL_CreateWindow(title, w, h, 0);
  164. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,SHOWN)", w, h);
  165. SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL");
  166. /* Clean up */
  167. destroyVideoSuiteTestWindow(window);
  168. }
  169. }
  170. return TEST_COMPLETED;
  171. }
  172. /**
  173. * Tests the functionality of the SDL_CreateWindow function using different flags
  174. */
  175. static int video_createWindowVariousFlags(void *arg)
  176. {
  177. SDL_Window *window;
  178. const char *title = "video_createWindowVariousFlags Test Window";
  179. int w, h;
  180. int fVariation;
  181. SDL_WindowFlags flags;
  182. /* Standard window */
  183. w = SDLTest_RandomIntegerInRange(320, 1024);
  184. h = SDLTest_RandomIntegerInRange(320, 768);
  185. for (fVariation = 1; fVariation < 14; fVariation++) {
  186. switch (fVariation) {
  187. default:
  188. case 1:
  189. flags = SDL_WINDOW_FULLSCREEN;
  190. /* Skip - blanks screen; comment out next line to run test */
  191. continue;
  192. break;
  193. case 2:
  194. flags = SDL_WINDOW_OPENGL;
  195. /* Skip - not every video driver supports OpenGL; comment out next line to run test */
  196. continue;
  197. break;
  198. case 3:
  199. flags = 0;
  200. break;
  201. case 4:
  202. flags = SDL_WINDOW_HIDDEN;
  203. break;
  204. case 5:
  205. flags = SDL_WINDOW_BORDERLESS;
  206. break;
  207. case 6:
  208. flags = SDL_WINDOW_RESIZABLE;
  209. break;
  210. case 7:
  211. flags = SDL_WINDOW_MINIMIZED;
  212. break;
  213. case 8:
  214. flags = SDL_WINDOW_MAXIMIZED;
  215. break;
  216. case 9:
  217. flags = SDL_WINDOW_MOUSE_GRABBED;
  218. break;
  219. case 10:
  220. flags = SDL_WINDOW_INPUT_FOCUS;
  221. break;
  222. case 11:
  223. flags = SDL_WINDOW_MOUSE_FOCUS;
  224. break;
  225. case 12:
  226. flags = SDL_WINDOW_EXTERNAL;
  227. break;
  228. case 13:
  229. flags = SDL_WINDOW_KEYBOARD_GRABBED;
  230. break;
  231. }
  232. window = SDL_CreateWindow(title, w, h, flags);
  233. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%" SDL_PRIu64 ")", w, h, flags);
  234. SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL");
  235. /* Clean up */
  236. destroyVideoSuiteTestWindow(window);
  237. }
  238. return TEST_COMPLETED;
  239. }
  240. /**
  241. * Tests the functionality of the SDL_GetWindowFlags function
  242. */
  243. static int video_getWindowFlags(void *arg)
  244. {
  245. SDL_Window *window;
  246. const char *title = "video_getWindowFlags Test Window";
  247. SDL_WindowFlags flags;
  248. SDL_WindowFlags actualFlags;
  249. /* Reliable flag set always set in test window */
  250. flags = 0;
  251. /* Call against new test window */
  252. window = createVideoSuiteTestWindow(title);
  253. if (window != NULL) {
  254. actualFlags = SDL_GetWindowFlags(window);
  255. SDLTest_AssertPass("Call to SDL_GetWindowFlags()");
  256. SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %" SDL_PRIu64 " set, got: %" SDL_PRIu64, flags, actualFlags);
  257. }
  258. /* Clean up */
  259. destroyVideoSuiteTestWindow(window);
  260. return TEST_COMPLETED;
  261. }
  262. /**
  263. * Tests the functionality of the SDL_GetFullscreenDisplayModes function
  264. */
  265. static int video_getFullscreenDisplayModes(void *arg)
  266. {
  267. SDL_DisplayID *displays;
  268. const SDL_DisplayMode **modes;
  269. int count;
  270. int i;
  271. /* Get number of displays */
  272. displays = SDL_GetDisplays(NULL);
  273. if (displays) {
  274. SDLTest_AssertPass("Call to SDL_GetDisplays()");
  275. /* Make call for each display */
  276. for (i = 0; displays[i]; ++i) {
  277. modes = SDL_GetFullscreenDisplayModes(displays[i], &count);
  278. SDLTest_AssertPass("Call to SDL_GetFullscreenDisplayModes(%" SDL_PRIu32 ")", displays[i]);
  279. SDLTest_AssertCheck(modes != NULL, "Validate returned value from function; expected != NULL; got: %p", modes);
  280. SDLTest_AssertCheck(count >= 0, "Validate number of modes; expected: >= 0; got: %d", count);
  281. SDL_free((void *)modes);
  282. }
  283. SDL_free(displays);
  284. }
  285. return TEST_COMPLETED;
  286. }
  287. /**
  288. * Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against current resolution
  289. */
  290. static int video_getClosestDisplayModeCurrentResolution(void *arg)
  291. {
  292. SDL_DisplayID *displays;
  293. const SDL_DisplayMode **modes;
  294. SDL_DisplayMode current;
  295. const SDL_DisplayMode *closest;
  296. int i, num_modes;
  297. /* Get number of displays */
  298. displays = SDL_GetDisplays(NULL);
  299. if (displays) {
  300. SDLTest_AssertPass("Call to SDL_GetDisplays()");
  301. /* Make calls for each display */
  302. for (i = 0; displays[i]; ++i) {
  303. SDLTest_Log("Testing against display: %" SDL_PRIu32, displays[i]);
  304. /* Get first display mode to get a sane resolution; this should always work */
  305. modes = SDL_GetFullscreenDisplayModes(displays[i], &num_modes);
  306. SDLTest_AssertPass("Call to SDL_GetDisplayModes()");
  307. SDLTest_Assert(modes != NULL, "Verify returned value is not NULL");
  308. if (num_modes > 0) {
  309. SDL_memcpy(&current, modes[0], sizeof(current));
  310. /* Make call */
  311. closest = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, SDL_FALSE);
  312. SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)");
  313. SDLTest_Assert(closest != NULL, "Verify returned value is not NULL");
  314. /* Check that one gets the current resolution back again */
  315. if (closest) {
  316. SDLTest_AssertCheck(closest->w == current.w,
  317. "Verify returned width matches current width; expected: %d, got: %d",
  318. current.w, closest->w);
  319. SDLTest_AssertCheck(closest->h == current.h,
  320. "Verify returned height matches current height; expected: %d, got: %d",
  321. current.h, closest->h);
  322. }
  323. }
  324. SDL_free((void *)modes);
  325. }
  326. SDL_free(displays);
  327. }
  328. return TEST_COMPLETED;
  329. }
  330. /**
  331. * Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against random resolution
  332. */
  333. static int video_getClosestDisplayModeRandomResolution(void *arg)
  334. {
  335. SDL_DisplayID *displays;
  336. SDL_DisplayMode target;
  337. int i;
  338. int variation;
  339. /* Get number of displays */
  340. displays = SDL_GetDisplays(NULL);
  341. if (displays) {
  342. SDLTest_AssertPass("Call to SDL_GetDisplays()");
  343. /* Make calls for each display */
  344. for (i = 0; displays[i]; ++i) {
  345. SDLTest_Log("Testing against display: %" SDL_PRIu32, displays[i]);
  346. for (variation = 0; variation < 16; variation++) {
  347. /* Set random constraints */
  348. SDL_zero(target);
  349. target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  350. target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  351. target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
  352. /* Make call; may or may not find anything, so don't validate any further */
  353. SDL_GetClosestFullscreenDisplayMode(displays[i], target.w, target.h, target.refresh_rate, SDL_FALSE);
  354. SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d)", variation);
  355. }
  356. }
  357. SDL_free(displays);
  358. }
  359. return TEST_COMPLETED;
  360. }
  361. /**
  362. * Tests call to SDL_GetWindowFullscreenMode
  363. *
  364. * \sa SDL_GetWindowFullscreenMode
  365. */
  366. static int video_getWindowDisplayMode(void *arg)
  367. {
  368. SDL_Window *window;
  369. const char *title = "video_getWindowDisplayMode Test Window";
  370. const SDL_DisplayMode *mode;
  371. /* Call against new test window */
  372. window = createVideoSuiteTestWindow(title);
  373. if (window != NULL) {
  374. mode = SDL_GetWindowFullscreenMode(window);
  375. SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode()");
  376. SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode);
  377. }
  378. /* Clean up */
  379. destroyVideoSuiteTestWindow(window);
  380. return TEST_COMPLETED;
  381. }
  382. /* Helper function that checks for an 'Invalid window' error */
  383. static void checkInvalidWindowError(void)
  384. {
  385. const char *invalidWindowError = "Invalid window";
  386. const char *lastError;
  387. lastError = SDL_GetError();
  388. SDLTest_AssertPass("SDL_GetError()");
  389. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  390. if (lastError != NULL) {
  391. SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
  392. "SDL_GetError(): expected message '%s', was message: '%s'",
  393. invalidWindowError,
  394. lastError);
  395. SDL_ClearError();
  396. SDLTest_AssertPass("Call to SDL_ClearError()");
  397. }
  398. }
  399. /**
  400. * Tests call to SDL_GetWindowFullscreenMode with invalid input
  401. *
  402. * \sa SDL_GetWindowFullscreenMode
  403. */
  404. static int video_getWindowDisplayModeNegative(void *arg)
  405. {
  406. const SDL_DisplayMode *mode;
  407. /* Call against invalid window */
  408. mode = SDL_GetWindowFullscreenMode(NULL);
  409. SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode(window=NULL)");
  410. SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode);
  411. checkInvalidWindowError();
  412. return TEST_COMPLETED;
  413. }
  414. /* Helper for setting and checking the window mouse grab state */
  415. static void setAndCheckWindowMouseGrabState(SDL_Window *window, SDL_bool desiredState)
  416. {
  417. SDL_bool currentState;
  418. /* Set state */
  419. SDL_SetWindowMouseGrab(window, desiredState);
  420. SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  421. /* Get and check state */
  422. currentState = SDL_GetWindowMouseGrab(window);
  423. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  424. SDLTest_AssertCheck(
  425. currentState == desiredState,
  426. "Validate returned state; expected: %s, got: %s",
  427. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  428. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  429. if (desiredState) {
  430. SDLTest_AssertCheck(
  431. SDL_GetGrabbedWindow() == window,
  432. "Grabbed window should be to our window");
  433. SDLTest_AssertCheck(
  434. SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED,
  435. "SDL_WINDOW_MOUSE_GRABBED should be set");
  436. } else {
  437. SDLTest_AssertCheck(
  438. !(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED),
  439. "SDL_WINDOW_MOUSE_GRABBED should be unset");
  440. }
  441. }
  442. /* Helper for setting and checking the window keyboard grab state */
  443. static void setAndCheckWindowKeyboardGrabState(SDL_Window *window, SDL_bool desiredState)
  444. {
  445. SDL_bool currentState;
  446. /* Set state */
  447. SDL_SetWindowKeyboardGrab(window, desiredState);
  448. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  449. /* Get and check state */
  450. currentState = SDL_GetWindowKeyboardGrab(window);
  451. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  452. SDLTest_AssertCheck(
  453. currentState == desiredState,
  454. "Validate returned state; expected: %s, got: %s",
  455. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  456. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  457. if (desiredState) {
  458. SDLTest_AssertCheck(
  459. SDL_GetGrabbedWindow() == window,
  460. "Grabbed window should be set to our window");
  461. SDLTest_AssertCheck(
  462. SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED,
  463. "SDL_WINDOW_KEYBOARD_GRABBED should be set");
  464. } else {
  465. SDLTest_AssertCheck(
  466. !(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED),
  467. "SDL_WINDOW_KEYBOARD_GRABBED should be unset");
  468. }
  469. }
  470. /**
  471. * Tests keyboard and mouse grab support
  472. *
  473. * \sa SDL_GetWindowMouseGrab
  474. * \sa SDL_GetWindowKeyboardGrab
  475. * \sa SDL_SetWindowMouseGrab
  476. * \sa SDL_SetWindowKeyboardGrab
  477. */
  478. static int video_getSetWindowGrab(void *arg)
  479. {
  480. const char *title = "video_getSetWindowGrab Test Window";
  481. SDL_Window *window;
  482. SDL_bool originalMouseState, originalKeyboardState;
  483. SDL_bool hasFocusGained = SDL_FALSE;
  484. /* Call against new test window */
  485. window = createVideoSuiteTestWindow(title);
  486. if (!window) {
  487. return TEST_ABORTED;
  488. }
  489. /* Need to raise the window to have and SDL_EVENT_WINDOW_FOCUS_GAINED,
  490. * so that the window gets the flags SDL_WINDOW_INPUT_FOCUS,
  491. * so that it can be "grabbed" */
  492. SDL_RaiseWindow(window);
  493. if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS)) {
  494. int count = 0;
  495. SDL_Event evt;
  496. SDL_zero(evt);
  497. while (!hasFocusGained && count++ < 3) {
  498. while (SDL_PollEvent(&evt)) {
  499. if (evt.type == SDL_EVENT_WINDOW_FOCUS_GAINED) {
  500. hasFocusGained = SDL_TRUE;
  501. }
  502. }
  503. }
  504. } else {
  505. hasFocusGained = SDL_TRUE;
  506. }
  507. SDLTest_AssertCheck(hasFocusGained == SDL_TRUE, "Expectded window with focus");
  508. /* Get state */
  509. originalMouseState = SDL_GetWindowMouseGrab(window);
  510. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  511. originalKeyboardState = SDL_GetWindowKeyboardGrab(window);
  512. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  513. /* F */
  514. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  515. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  516. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  517. "Expected NULL grabbed window");
  518. /* F --> F */
  519. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  520. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  521. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  522. "Expected NULL grabbed window");
  523. /* F --> T */
  524. setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  525. setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  526. /* T --> T */
  527. setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  528. setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  529. /* M: T --> F */
  530. /* K: T --> T */
  531. setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  532. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  533. /* M: F --> T */
  534. /* K: T --> F */
  535. setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  536. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  537. /* M: T --> F */
  538. /* K: F --> F */
  539. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  540. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  541. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  542. "Expected NULL grabbed window");
  543. /* Negative tests */
  544. SDL_GetWindowMouseGrab(NULL);
  545. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab(window=NULL)");
  546. checkInvalidWindowError();
  547. SDL_GetWindowKeyboardGrab(NULL);
  548. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)");
  549. checkInvalidWindowError();
  550. SDL_SetWindowMouseGrab(NULL, SDL_FALSE);
  551. SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(window=NULL,SDL_FALSE)");
  552. checkInvalidWindowError();
  553. SDL_SetWindowKeyboardGrab(NULL, SDL_FALSE);
  554. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE)");
  555. checkInvalidWindowError();
  556. SDL_SetWindowMouseGrab(NULL, SDL_TRUE);
  557. SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(window=NULL,SDL_TRUE)");
  558. checkInvalidWindowError();
  559. SDL_SetWindowKeyboardGrab(NULL, SDL_TRUE);
  560. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE)");
  561. checkInvalidWindowError();
  562. /* Restore state */
  563. setAndCheckWindowMouseGrabState(window, originalMouseState);
  564. setAndCheckWindowKeyboardGrabState(window, originalKeyboardState);
  565. /* Clean up */
  566. destroyVideoSuiteTestWindow(window);
  567. return TEST_COMPLETED;
  568. }
  569. /**
  570. * Tests call to SDL_GetWindowID and SDL_GetWindowFromID
  571. *
  572. * \sa SDL_GetWindowID
  573. * \sa SDL_SetWindowFromID
  574. */
  575. static int video_getWindowId(void *arg)
  576. {
  577. const char *title = "video_getWindowId Test Window";
  578. SDL_Window *window;
  579. SDL_Window *result;
  580. Uint32 id, randomId;
  581. /* Call against new test window */
  582. window = createVideoSuiteTestWindow(title);
  583. if (!window) {
  584. return TEST_ABORTED;
  585. }
  586. /* Get ID */
  587. id = SDL_GetWindowID(window);
  588. SDLTest_AssertPass("Call to SDL_GetWindowID()");
  589. /* Get window from ID */
  590. result = SDL_GetWindowFromID(id);
  591. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 ")", id);
  592. SDLTest_AssertCheck(result == window, "Verify result matches window pointer");
  593. /* Get window from random large ID, no result check */
  594. randomId = SDLTest_RandomIntegerInRange(UINT8_MAX, UINT16_MAX);
  595. result = SDL_GetWindowFromID(randomId);
  596. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/random_large)", randomId);
  597. /* Get window from 0 and Uint32 max ID, no result check */
  598. result = SDL_GetWindowFromID(0);
  599. SDLTest_AssertPass("Call to SDL_GetWindowID(0)");
  600. result = SDL_GetWindowFromID(UINT32_MAX);
  601. SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)");
  602. /* Clean up */
  603. destroyVideoSuiteTestWindow(window);
  604. /* Get window from ID for closed window */
  605. result = SDL_GetWindowFromID(id);
  606. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/closed_window)", id);
  607. SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
  608. /* Negative test */
  609. SDL_ClearError();
  610. SDLTest_AssertPass("Call to SDL_ClearError()");
  611. id = SDL_GetWindowID(NULL);
  612. SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
  613. checkInvalidWindowError();
  614. return TEST_COMPLETED;
  615. }
  616. /**
  617. * Tests call to SDL_GetWindowPixelFormat
  618. *
  619. * \sa SDL_GetWindowPixelFormat
  620. */
  621. static int video_getWindowPixelFormat(void *arg)
  622. {
  623. const char *title = "video_getWindowPixelFormat Test Window";
  624. SDL_Window *window;
  625. SDL_PixelFormat format;
  626. /* Call against new test window */
  627. window = createVideoSuiteTestWindow(title);
  628. if (!window) {
  629. return TEST_ABORTED;
  630. }
  631. /* Get format */
  632. format = SDL_GetWindowPixelFormat(window);
  633. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
  634. SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != SDL_PIXELFORMAT_UNKNOWN, got: SDL_PIXELFORMAT_UNKNOWN");
  635. /* Clean up */
  636. destroyVideoSuiteTestWindow(window);
  637. /* Negative test */
  638. SDL_ClearError();
  639. SDLTest_AssertPass("Call to SDL_ClearError()");
  640. format = SDL_GetWindowPixelFormat(NULL);
  641. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
  642. checkInvalidWindowError();
  643. return TEST_COMPLETED;
  644. }
  645. static SDL_bool getPositionFromEvent(int *x, int *y)
  646. {
  647. SDL_bool ret = SDL_FALSE;
  648. SDL_Event evt;
  649. SDL_zero(evt);
  650. while (SDL_PollEvent(&evt)) {
  651. if (evt.type == SDL_EVENT_WINDOW_MOVED) {
  652. *x = evt.window.data1;
  653. *y = evt.window.data2;
  654. ret = SDL_TRUE;
  655. }
  656. }
  657. return ret;
  658. }
  659. static SDL_bool getSizeFromEvent(int *w, int *h)
  660. {
  661. SDL_bool ret = SDL_FALSE;
  662. SDL_Event evt;
  663. SDL_zero(evt);
  664. while (SDL_PollEvent(&evt)) {
  665. if (evt.type == SDL_EVENT_WINDOW_RESIZED) {
  666. *w = evt.window.data1;
  667. *h = evt.window.data2;
  668. ret = SDL_TRUE;
  669. }
  670. }
  671. return ret;
  672. }
  673. /**
  674. * Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
  675. *
  676. * \sa SDL_GetWindowPosition
  677. * \sa SDL_SetWindowPosition
  678. */
  679. static int video_getSetWindowPosition(void *arg)
  680. {
  681. const char *title = "video_getSetWindowPosition Test Window";
  682. SDL_Window *window;
  683. int result;
  684. int maxxVariation, maxyVariation;
  685. int xVariation, yVariation;
  686. int referenceX, referenceY;
  687. int currentX, currentY;
  688. int desiredX, desiredY;
  689. SDL_Rect display_bounds;
  690. /* Call against new test window */
  691. window = createVideoSuiteTestWindow(title);
  692. if (!window) {
  693. return TEST_ABORTED;
  694. }
  695. /* Sanity check */
  696. SDL_GetWindowPosition(window, &currentX, &currentY);
  697. if (SDL_SetWindowPosition(window, currentX, currentY) < 0) {
  698. SDLTest_Log("Skipping window positioning tests: %s reports window positioning as unsupported", SDL_GetCurrentVideoDriver());
  699. goto null_tests;
  700. }
  701. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
  702. /* The X11 server allows arbitrary window placement, but compositing
  703. * window managers such as GNOME and KDE force windows to be within
  704. * desktop bounds.
  705. */
  706. maxxVariation = 2;
  707. maxyVariation = 2;
  708. SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display_bounds);
  709. } else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "cocoa") == 0) {
  710. /* Platform doesn't allow windows with negative Y desktop bounds */
  711. maxxVariation = 4;
  712. maxyVariation = 3;
  713. SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display_bounds);
  714. } else {
  715. /* Platform allows windows to be placed out of bounds */
  716. maxxVariation = 4;
  717. maxyVariation = 4;
  718. SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display_bounds);
  719. }
  720. for (xVariation = 0; xVariation < maxxVariation; xVariation++) {
  721. for (yVariation = 0; yVariation < maxyVariation; yVariation++) {
  722. switch (xVariation) {
  723. default:
  724. case 0:
  725. /* Zero X Position */
  726. desiredX = display_bounds.x > 0 ? display_bounds.x : 0;
  727. break;
  728. case 1:
  729. /* Random X position inside screen */
  730. desiredX = SDLTest_RandomIntegerInRange(display_bounds.x + 1, display_bounds.x + 100);
  731. break;
  732. case 2:
  733. /* Random X position outside screen (positive) */
  734. desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
  735. break;
  736. case 3:
  737. /* Random X position outside screen (negative) */
  738. desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
  739. break;
  740. }
  741. switch (yVariation) {
  742. default:
  743. case 0:
  744. /* Zero Y Position */
  745. desiredY = display_bounds.y > 0 ? display_bounds.y : 0;
  746. break;
  747. case 1:
  748. /* Random Y position inside screen */
  749. desiredY = SDLTest_RandomIntegerInRange(display_bounds.y + 1, display_bounds.y + 100);
  750. break;
  751. case 2:
  752. /* Random Y position outside screen (positive) */
  753. desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
  754. break;
  755. case 3:
  756. /* Random Y position outside screen (negative) */
  757. desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
  758. break;
  759. }
  760. /* Set position */
  761. SDL_SetWindowPosition(window, desiredX, desiredY);
  762. SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
  763. result = SDL_SyncWindow(window);
  764. SDLTest_AssertPass("SDL_SyncWindow()");
  765. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  766. /* Get position */
  767. currentX = desiredX + 1;
  768. currentY = desiredY + 1;
  769. SDL_GetWindowPosition(window, &currentX, &currentY);
  770. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  771. if (desiredX == currentX && desiredY == currentY) {
  772. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  773. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  774. } else {
  775. SDL_bool hasEvent;
  776. /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
  777. * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */
  778. currentX = desiredX + 1;
  779. currentY = desiredY + 1;
  780. hasEvent = getPositionFromEvent(&currentX, &currentY);
  781. SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing position was not honored by WM, checking present of SDL_EVENT_WINDOW_MOVED");
  782. if (hasEvent) {
  783. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position is the position from SDL event; expected: %d, got: %d", desiredX, currentX);
  784. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position is the position from SDL event; expected: %d, got: %d", desiredY, currentY);
  785. }
  786. }
  787. /* Get position X */
  788. currentX = desiredX + 1;
  789. SDL_GetWindowPosition(window, &currentX, NULL);
  790. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
  791. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  792. /* Get position Y */
  793. currentY = desiredY + 1;
  794. SDL_GetWindowPosition(window, NULL, &currentY);
  795. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
  796. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  797. }
  798. }
  799. null_tests:
  800. /* Dummy call with both pointers NULL */
  801. SDL_GetWindowPosition(window, NULL, NULL);
  802. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
  803. /* Clean up */
  804. destroyVideoSuiteTestWindow(window);
  805. /* Set some 'magic' value for later check that nothing was changed */
  806. referenceX = SDLTest_RandomSint32();
  807. referenceY = SDLTest_RandomSint32();
  808. currentX = referenceX;
  809. currentY = referenceY;
  810. desiredX = SDLTest_RandomSint32();
  811. desiredY = SDLTest_RandomSint32();
  812. /* Negative tests */
  813. SDL_ClearError();
  814. SDLTest_AssertPass("Call to SDL_ClearError()");
  815. SDL_GetWindowPosition(NULL, &currentX, &currentY);
  816. SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
  817. SDLTest_AssertCheck(
  818. currentX == referenceX && currentY == referenceY,
  819. "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
  820. referenceX, referenceY,
  821. currentX, currentY);
  822. checkInvalidWindowError();
  823. SDL_GetWindowPosition(NULL, NULL, NULL);
  824. SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
  825. checkInvalidWindowError();
  826. SDL_SetWindowPosition(NULL, desiredX, desiredY);
  827. SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
  828. checkInvalidWindowError();
  829. return TEST_COMPLETED;
  830. }
  831. /* Helper function that checks for an 'Invalid parameter' error */
  832. static void checkInvalidParameterError(void)
  833. {
  834. const char *invalidParameterError = "Parameter";
  835. const char *lastError;
  836. lastError = SDL_GetError();
  837. SDLTest_AssertPass("SDL_GetError()");
  838. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  839. if (lastError != NULL) {
  840. SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
  841. "SDL_GetError(): expected message starts with '%s', was message: '%s'",
  842. invalidParameterError,
  843. lastError);
  844. SDL_ClearError();
  845. SDLTest_AssertPass("Call to SDL_ClearError()");
  846. }
  847. }
  848. /**
  849. * Tests call to SDL_GetWindowSize and SDL_SetWindowSize
  850. *
  851. * \sa SDL_GetWindowSize
  852. * \sa SDL_SetWindowSize
  853. */
  854. static int video_getSetWindowSize(void *arg)
  855. {
  856. const char *title = "video_getSetWindowSize Test Window";
  857. SDL_Window *window;
  858. int result;
  859. SDL_Rect display;
  860. int maxwVariation, maxhVariation;
  861. int wVariation, hVariation;
  862. int referenceW, referenceH;
  863. int currentW, currentH;
  864. int desiredW, desiredH;
  865. const SDL_bool restoreHint = SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", SDL_TRUE);
  866. /* Win32 borderless windows are not resizable by default and need this undocumented hint */
  867. SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", "1");
  868. /* Get display bounds for size range */
  869. result = SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display);
  870. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  871. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  872. if (result != 0) {
  873. return TEST_ABORTED;
  874. }
  875. /* Call against new test window */
  876. window = createVideoSuiteTestWindow(title);
  877. if (!window) {
  878. return TEST_ABORTED;
  879. }
  880. SDL_GetWindowSize(window, &currentW, &currentH);
  881. if (SDL_SetWindowSize(window, currentW, currentH)) {
  882. SDLTest_Log("Skipping window resize tests: %s reports window resizing as unsupported", SDL_GetCurrentVideoDriver());
  883. goto null_tests;
  884. }
  885. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") == 0 ||
  886. SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
  887. /* Platform clips window size to screen size */
  888. maxwVariation = 4;
  889. maxhVariation = 4;
  890. } else {
  891. /* Platform allows window size >= screen size */
  892. maxwVariation = 5;
  893. maxhVariation = 5;
  894. }
  895. for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
  896. for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
  897. switch (wVariation) {
  898. default:
  899. case 0:
  900. /* 1 Pixel Wide */
  901. desiredW = 1;
  902. break;
  903. case 1:
  904. /* Random width inside screen */
  905. desiredW = SDLTest_RandomIntegerInRange(1, 100);
  906. break;
  907. case 2:
  908. /* Width 1 pixel smaller than screen */
  909. desiredW = display.w - 1;
  910. break;
  911. case 3:
  912. /* Width at screen size */
  913. desiredW = display.w;
  914. break;
  915. case 4:
  916. /* Width 1 pixel larger than screen */
  917. desiredW = display.w + 1;
  918. break;
  919. }
  920. switch (hVariation) {
  921. default:
  922. case 0:
  923. /* 1 Pixel High */
  924. desiredH = 1;
  925. break;
  926. case 1:
  927. /* Random height inside screen */
  928. desiredH = SDLTest_RandomIntegerInRange(1, 100);
  929. break;
  930. case 2:
  931. /* Height 1 pixel smaller than screen */
  932. desiredH = display.h - 1;
  933. break;
  934. case 3:
  935. /* Height at screen size */
  936. desiredH = display.h;
  937. break;
  938. case 4:
  939. /* Height 1 pixel larger than screen */
  940. desiredH = display.h + 1;
  941. break;
  942. }
  943. /* Set size */
  944. SDL_SetWindowSize(window, desiredW, desiredH);
  945. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  946. result = SDL_SyncWindow(window);
  947. SDLTest_AssertPass("SDL_SyncWindow()");
  948. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  949. /* Get size */
  950. currentW = desiredW + 1;
  951. currentH = desiredH + 1;
  952. SDL_GetWindowSize(window, &currentW, &currentH);
  953. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  954. if (desiredW == currentW && desiredH == currentH) {
  955. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  956. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  957. } else {
  958. SDL_bool hasEvent;
  959. /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
  960. * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */
  961. currentW = desiredW + 1;
  962. currentH = desiredH + 1;
  963. hasEvent = getSizeFromEvent(&currentW, &currentH);
  964. SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing size was not honored by WM, checking presence of SDL_EVENT_WINDOW_RESIZED");
  965. if (hasEvent) {
  966. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width is the one from SDL event; expected: %d, got: %d", desiredW, currentW);
  967. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height is the one from SDL event; expected: %d, got: %d", desiredH, currentH);
  968. }
  969. }
  970. /* Get just width */
  971. currentW = desiredW + 1;
  972. SDL_GetWindowSize(window, &currentW, NULL);
  973. SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
  974. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  975. /* Get just height */
  976. currentH = desiredH + 1;
  977. SDL_GetWindowSize(window, NULL, &currentH);
  978. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
  979. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  980. }
  981. }
  982. null_tests:
  983. /* Dummy call with both pointers NULL */
  984. SDL_GetWindowSize(window, NULL, NULL);
  985. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
  986. /* Negative tests for parameter input */
  987. SDL_ClearError();
  988. SDLTest_AssertPass("Call to SDL_ClearError()");
  989. for (desiredH = -2; desiredH < 2; desiredH++) {
  990. for (desiredW = -2; desiredW < 2; desiredW++) {
  991. if (desiredW <= 0 || desiredH <= 0) {
  992. SDL_SetWindowSize(window, desiredW, desiredH);
  993. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  994. checkInvalidParameterError();
  995. }
  996. }
  997. }
  998. /* Clean up */
  999. destroyVideoSuiteTestWindow(window);
  1000. /* Set some 'magic' value for later check that nothing was changed */
  1001. referenceW = SDLTest_RandomSint32();
  1002. referenceH = SDLTest_RandomSint32();
  1003. currentW = referenceW;
  1004. currentH = referenceH;
  1005. desiredW = SDLTest_RandomSint32();
  1006. desiredH = SDLTest_RandomSint32();
  1007. /* Negative tests for window input */
  1008. SDL_ClearError();
  1009. SDLTest_AssertPass("Call to SDL_ClearError()");
  1010. SDL_GetWindowSize(NULL, &currentW, &currentH);
  1011. SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
  1012. SDLTest_AssertCheck(
  1013. currentW == referenceW && currentH == referenceH,
  1014. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1015. referenceW, referenceH,
  1016. currentW, currentH);
  1017. checkInvalidWindowError();
  1018. SDL_GetWindowSize(NULL, NULL, NULL);
  1019. SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
  1020. checkInvalidWindowError();
  1021. SDL_SetWindowSize(NULL, desiredW, desiredH);
  1022. SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
  1023. checkInvalidWindowError();
  1024. /* Restore the hint to the previous value */
  1025. SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", restoreHint ? "1" : "0");
  1026. return TEST_COMPLETED;
  1027. }
  1028. /**
  1029. * Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
  1030. *
  1031. */
  1032. static int video_getSetWindowMinimumSize(void *arg)
  1033. {
  1034. const char *title = "video_getSetWindowMinimumSize Test Window";
  1035. SDL_Window *window;
  1036. int result;
  1037. SDL_Rect display;
  1038. int wVariation, hVariation;
  1039. int referenceW, referenceH;
  1040. int currentW, currentH;
  1041. int desiredW = 1;
  1042. int desiredH = 1;
  1043. /* Get display bounds for size range */
  1044. result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display);
  1045. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1046. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1047. if (result != 0) {
  1048. return TEST_ABORTED;
  1049. }
  1050. /* Call against new test window */
  1051. window = createVideoSuiteTestWindow(title);
  1052. if (!window) {
  1053. return TEST_ABORTED;
  1054. }
  1055. for (wVariation = 0; wVariation < 5; wVariation++) {
  1056. for (hVariation = 0; hVariation < 5; hVariation++) {
  1057. switch (wVariation) {
  1058. case 0:
  1059. /* 1 Pixel Wide */
  1060. desiredW = 1;
  1061. break;
  1062. case 1:
  1063. /* Random width inside screen */
  1064. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1065. break;
  1066. case 2:
  1067. /* Width at screen size */
  1068. desiredW = display.w;
  1069. break;
  1070. }
  1071. switch (hVariation) {
  1072. case 0:
  1073. /* 1 Pixel High */
  1074. desiredH = 1;
  1075. break;
  1076. case 1:
  1077. /* Random height inside screen */
  1078. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1079. break;
  1080. case 2:
  1081. /* Height at screen size */
  1082. desiredH = display.h;
  1083. break;
  1084. case 4:
  1085. /* Height 1 pixel larger than screen */
  1086. desiredH = display.h + 1;
  1087. break;
  1088. }
  1089. /* Set size */
  1090. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1091. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1092. /* Get size */
  1093. currentW = desiredW + 1;
  1094. currentH = desiredH + 1;
  1095. SDL_GetWindowMinimumSize(window, &currentW, &currentH);
  1096. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
  1097. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1098. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1099. /* Get just width */
  1100. currentW = desiredW + 1;
  1101. SDL_GetWindowMinimumSize(window, &currentW, NULL);
  1102. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
  1103. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1104. /* Get just height */
  1105. currentH = desiredH + 1;
  1106. SDL_GetWindowMinimumSize(window, NULL, &currentH);
  1107. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
  1108. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1109. }
  1110. }
  1111. /* Dummy call with both pointers NULL */
  1112. SDL_GetWindowMinimumSize(window, NULL, NULL);
  1113. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
  1114. /* Negative tests for parameter input */
  1115. SDL_ClearError();
  1116. SDLTest_AssertPass("Call to SDL_ClearError()");
  1117. for (desiredH = -2; desiredH < 2; desiredH++) {
  1118. for (desiredW = -2; desiredW < 2; desiredW++) {
  1119. if (desiredW < 0 || desiredH < 0) {
  1120. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1121. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1122. checkInvalidParameterError();
  1123. }
  1124. }
  1125. }
  1126. /* Clean up */
  1127. destroyVideoSuiteTestWindow(window);
  1128. /* Set some 'magic' value for later check that nothing was changed */
  1129. referenceW = SDLTest_RandomSint32();
  1130. referenceH = SDLTest_RandomSint32();
  1131. currentW = referenceW;
  1132. currentH = referenceH;
  1133. desiredW = SDLTest_RandomSint32();
  1134. desiredH = SDLTest_RandomSint32();
  1135. /* Negative tests for window input */
  1136. SDL_ClearError();
  1137. SDLTest_AssertPass("Call to SDL_ClearError()");
  1138. SDL_GetWindowMinimumSize(NULL, &currentW, &currentH);
  1139. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
  1140. SDLTest_AssertCheck(
  1141. currentW == referenceW && currentH == referenceH,
  1142. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1143. referenceW, referenceH,
  1144. currentW, currentH);
  1145. checkInvalidWindowError();
  1146. SDL_GetWindowMinimumSize(NULL, NULL, NULL);
  1147. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
  1148. checkInvalidWindowError();
  1149. SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
  1150. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
  1151. checkInvalidWindowError();
  1152. return TEST_COMPLETED;
  1153. }
  1154. /**
  1155. * Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
  1156. *
  1157. */
  1158. static int video_getSetWindowMaximumSize(void *arg)
  1159. {
  1160. const char *title = "video_getSetWindowMaximumSize Test Window";
  1161. SDL_Window *window;
  1162. int result;
  1163. SDL_Rect display;
  1164. int wVariation, hVariation;
  1165. int referenceW, referenceH;
  1166. int currentW, currentH;
  1167. int desiredW = 0, desiredH = 0;
  1168. /* Get display bounds for size range */
  1169. result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display);
  1170. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1171. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1172. if (result != 0) {
  1173. return TEST_ABORTED;
  1174. }
  1175. /* Call against new test window */
  1176. window = createVideoSuiteTestWindow(title);
  1177. if (!window) {
  1178. return TEST_ABORTED;
  1179. }
  1180. for (wVariation = 0; wVariation < 3; wVariation++) {
  1181. for (hVariation = 0; hVariation < 3; hVariation++) {
  1182. switch (wVariation) {
  1183. case 0:
  1184. /* 1 Pixel Wide */
  1185. desiredW = 1;
  1186. break;
  1187. case 1:
  1188. /* Random width inside screen */
  1189. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1190. break;
  1191. case 2:
  1192. /* Width at screen size */
  1193. desiredW = display.w;
  1194. break;
  1195. }
  1196. switch (hVariation) {
  1197. case 0:
  1198. /* 1 Pixel High */
  1199. desiredH = 1;
  1200. break;
  1201. case 1:
  1202. /* Random height inside screen */
  1203. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1204. break;
  1205. case 2:
  1206. /* Height at screen size */
  1207. desiredH = display.h;
  1208. break;
  1209. }
  1210. /* Set size */
  1211. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1212. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1213. /* Get size */
  1214. currentW = desiredW + 1;
  1215. currentH = desiredH + 1;
  1216. SDL_GetWindowMaximumSize(window, &currentW, &currentH);
  1217. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
  1218. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1219. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1220. /* Get just width */
  1221. currentW = desiredW + 1;
  1222. SDL_GetWindowMaximumSize(window, &currentW, NULL);
  1223. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
  1224. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1225. /* Get just height */
  1226. currentH = desiredH + 1;
  1227. SDL_GetWindowMaximumSize(window, NULL, &currentH);
  1228. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
  1229. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1230. }
  1231. }
  1232. /* Dummy call with both pointers NULL */
  1233. SDL_GetWindowMaximumSize(window, NULL, NULL);
  1234. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
  1235. /* Negative tests for parameter input */
  1236. SDL_ClearError();
  1237. SDLTest_AssertPass("Call to SDL_ClearError()");
  1238. for (desiredH = -2; desiredH < 2; desiredH++) {
  1239. for (desiredW = -2; desiredW < 2; desiredW++) {
  1240. if (desiredW < 0 || desiredH < 0) {
  1241. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1242. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1243. checkInvalidParameterError();
  1244. }
  1245. }
  1246. }
  1247. /* Clean up */
  1248. destroyVideoSuiteTestWindow(window);
  1249. /* Set some 'magic' value for later check that nothing was changed */
  1250. referenceW = SDLTest_RandomSint32();
  1251. referenceH = SDLTest_RandomSint32();
  1252. currentW = referenceW;
  1253. currentH = referenceH;
  1254. desiredW = SDLTest_RandomSint32();
  1255. desiredH = SDLTest_RandomSint32();
  1256. /* Negative tests */
  1257. SDL_ClearError();
  1258. SDLTest_AssertPass("Call to SDL_ClearError()");
  1259. SDL_GetWindowMaximumSize(NULL, &currentW, &currentH);
  1260. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
  1261. SDLTest_AssertCheck(
  1262. currentW == referenceW && currentH == referenceH,
  1263. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1264. referenceW, referenceH,
  1265. currentW, currentH);
  1266. checkInvalidWindowError();
  1267. SDL_GetWindowMaximumSize(NULL, NULL, NULL);
  1268. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
  1269. checkInvalidWindowError();
  1270. SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
  1271. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
  1272. checkInvalidWindowError();
  1273. return TEST_COMPLETED;
  1274. }
  1275. /**
  1276. * Tests call to SDL_SetWindowData and SDL_GetWindowData
  1277. *
  1278. * \sa SDL_SetWindowData
  1279. * \sa SDL_GetWindowData
  1280. */
  1281. static int video_getSetWindowData(void *arg)
  1282. {
  1283. int returnValue = TEST_COMPLETED;
  1284. const char *title = "video_setGetWindowData Test Window";
  1285. SDL_Window *window;
  1286. const char *referenceName = "TestName";
  1287. const char *name = "TestName";
  1288. const char *referenceName2 = "TestName2";
  1289. const char *name2 = "TestName2";
  1290. int datasize;
  1291. char *referenceUserdata = NULL;
  1292. char *userdata = NULL;
  1293. char *referenceUserdata2 = NULL;
  1294. char *userdata2 = NULL;
  1295. char *result;
  1296. int iteration;
  1297. /* Call against new test window */
  1298. window = createVideoSuiteTestWindow(title);
  1299. if (!window) {
  1300. return TEST_ABORTED;
  1301. }
  1302. /* Create testdata */
  1303. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1304. referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
  1305. if (!referenceUserdata) {
  1306. returnValue = TEST_ABORTED;
  1307. goto cleanup;
  1308. }
  1309. userdata = SDL_strdup(referenceUserdata);
  1310. if (!userdata) {
  1311. returnValue = TEST_ABORTED;
  1312. goto cleanup;
  1313. }
  1314. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1315. referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
  1316. if (!referenceUserdata2) {
  1317. returnValue = TEST_ABORTED;
  1318. goto cleanup;
  1319. }
  1320. userdata2 = SDL_strdup(referenceUserdata2);
  1321. if (!userdata2) {
  1322. returnValue = TEST_ABORTED;
  1323. goto cleanup;
  1324. }
  1325. /* Get non-existent data */
  1326. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1327. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1328. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1329. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1330. /* Set data */
  1331. SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata);
  1332. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
  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. /* Get data (twice) */
  1336. for (iteration = 1; iteration <= 2; iteration++) {
  1337. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1338. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
  1339. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1340. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1341. }
  1342. /* Set data again twice */
  1343. for (iteration = 1; iteration <= 2; iteration++) {
  1344. SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata);
  1345. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
  1346. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1347. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1348. }
  1349. /* Get data again */
  1350. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1351. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
  1352. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1353. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1354. /* Set data with new data */
  1355. SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata2);
  1356. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
  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. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1360. /* Set data with new data again */
  1361. SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata2);
  1362. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
  1363. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1364. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1365. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1366. /* Get new data */
  1367. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1368. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1369. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1370. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1371. /* Set data with NULL to clear */
  1372. SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1373. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
  1374. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1375. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1376. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1377. /* Set data with NULL to clear again */
  1378. SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1379. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
  1380. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1381. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1382. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1383. /* Get non-existent data */
  1384. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1385. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1386. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1387. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1388. /* Get non-existent data new name */
  1389. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name2, NULL);
  1390. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
  1391. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1392. SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
  1393. /* Set data (again) */
  1394. SDL_SetPointerProperty(SDL_GetWindowProperties(window), name, userdata);
  1395. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
  1396. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1397. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1398. /* Get data (again) */
  1399. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), name, NULL);
  1400. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
  1401. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1402. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1403. /* Set data with NULL name, valid userdata */
  1404. SDL_SetPointerProperty(SDL_GetWindowProperties(window), NULL, userdata);
  1405. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
  1406. checkInvalidParameterError();
  1407. /* Set data with empty name, valid userdata */
  1408. SDL_SetPointerProperty(SDL_GetWindowProperties(window), "", userdata);
  1409. SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
  1410. checkInvalidParameterError();
  1411. /* Set data with NULL name, NULL userdata */
  1412. SDL_SetPointerProperty(SDL_GetWindowProperties(window), NULL, NULL);
  1413. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
  1414. checkInvalidParameterError();
  1415. /* Set data with empty name, NULL userdata */
  1416. SDL_SetPointerProperty(SDL_GetWindowProperties(window), "", NULL);
  1417. SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
  1418. checkInvalidParameterError();
  1419. /* Get data with NULL name */
  1420. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), NULL, NULL);
  1421. SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
  1422. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1423. /* Get data with empty name */
  1424. result = (char *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), "", NULL);
  1425. SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
  1426. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1427. /* Clean up */
  1428. destroyVideoSuiteTestWindow(window);
  1429. cleanup:
  1430. SDL_free(referenceUserdata);
  1431. SDL_free(referenceUserdata2);
  1432. SDL_free(userdata);
  1433. SDL_free(userdata2);
  1434. return returnValue;
  1435. }
  1436. /**
  1437. * Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN.
  1438. *
  1439. * Especially useful when run on a multi-monitor system with different DPI scales per monitor,
  1440. * to test that the window size is maintained when moving between monitors.
  1441. *
  1442. * As the Wayland windowing protocol does not allow application windows to control their position in the
  1443. * desktop space, coupled with the general asynchronous nature of Wayland compositors, the positioning
  1444. * tests don't work in windowed mode and are unreliable in fullscreen mode, thus are disabled when using
  1445. * the Wayland video driver. All that can be done is check that the windows are the expected size.
  1446. */
  1447. static int video_setWindowCenteredOnDisplay(void *arg)
  1448. {
  1449. SDL_DisplayID *displays;
  1450. SDL_Window *window;
  1451. const char *title = "video_setWindowCenteredOnDisplay Test Window";
  1452. int x, y, w, h;
  1453. int xVariation, yVariation;
  1454. int displayNum;
  1455. int result;
  1456. SDL_Rect display0, display1;
  1457. SDL_bool video_driver_is_wayland = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0;
  1458. displays = SDL_GetDisplays(&displayNum);
  1459. if (displays) {
  1460. /* Get display bounds */
  1461. result = SDL_GetDisplayUsableBounds(displays[0 % displayNum], &display0);
  1462. SDLTest_AssertPass("SDL_GetDisplayUsableBounds()");
  1463. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1464. if (result != 0) {
  1465. return TEST_ABORTED;
  1466. }
  1467. result = SDL_GetDisplayUsableBounds(displays[1 % displayNum], &display1);
  1468. SDLTest_AssertPass("SDL_GetDisplayUsableBounds()");
  1469. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1470. if (result != 0) {
  1471. return TEST_ABORTED;
  1472. }
  1473. for (xVariation = 0; xVariation < 2; xVariation++) {
  1474. for (yVariation = 0; yVariation < 2; yVariation++) {
  1475. int currentX = 0, currentY = 0;
  1476. int currentW = 0, currentH = 0;
  1477. int expectedX = 0, expectedY = 0;
  1478. int currentDisplay;
  1479. int expectedDisplay;
  1480. SDL_Rect expectedDisplayRect, expectedFullscreenRect;
  1481. SDL_PropertiesID props;
  1482. /* xVariation is the display we start on */
  1483. expectedDisplay = displays[xVariation % displayNum];
  1484. x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1485. y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1486. w = SDLTest_RandomIntegerInRange(640, 800);
  1487. h = SDLTest_RandomIntegerInRange(400, 600);
  1488. expectedDisplayRect = (xVariation == 0) ? display0 : display1;
  1489. expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
  1490. expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
  1491. props = SDL_CreateProperties();
  1492. SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, title);
  1493. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, x);
  1494. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, y);
  1495. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, w);
  1496. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h);
  1497. SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN, SDL_TRUE);
  1498. window = SDL_CreateWindowWithProperties(props);
  1499. SDL_DestroyProperties(props);
  1500. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
  1501. SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL");
  1502. /* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */
  1503. if (video_driver_is_wayland) {
  1504. SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL);
  1505. if (renderer) {
  1506. SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
  1507. SDL_RenderClear(renderer);
  1508. SDL_RenderPresent(renderer);
  1509. /* Some desktops don't display the window immediately after presentation,
  1510. * so delay to give the window time to actually appear on the desktop.
  1511. */
  1512. SDL_Delay(100);
  1513. } else {
  1514. SDLTest_Log("Unable to create a renderer, tests may fail under Wayland");
  1515. }
  1516. }
  1517. /* Check the window is centered on the requested display */
  1518. currentDisplay = SDL_GetDisplayForWindow(window);
  1519. SDL_GetWindowSize(window, &currentW, &currentH);
  1520. SDL_GetWindowPosition(window, &currentX, &currentY);
  1521. if (!video_driver_is_wayland) {
  1522. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1523. } else {
  1524. SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
  1525. }
  1526. SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
  1527. SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
  1528. if (!video_driver_is_wayland) {
  1529. SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
  1530. SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
  1531. } else {
  1532. SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
  1533. }
  1534. /* Enter fullscreen desktop */
  1535. SDL_SetWindowPosition(window, x, y);
  1536. result = SDL_SetWindowFullscreen(window, SDL_TRUE);
  1537. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1538. result = SDL_SyncWindow(window);
  1539. SDLTest_AssertPass("SDL_SyncWindow()");
  1540. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1541. /* Check we are filling the full display */
  1542. currentDisplay = SDL_GetDisplayForWindow(window);
  1543. SDL_GetWindowSize(window, &currentW, &currentH);
  1544. SDL_GetWindowPosition(window, &currentX, &currentY);
  1545. /* Get the expected fullscreen rect.
  1546. * This needs to be queried after window creation and positioning as some drivers can alter the
  1547. * usable bounds based on the window scaling mode.
  1548. */
  1549. result = SDL_GetDisplayBounds(expectedDisplay, &expectedFullscreenRect);
  1550. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1551. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1552. if (!video_driver_is_wayland) {
  1553. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1554. } else {
  1555. SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
  1556. }
  1557. SDLTest_AssertCheck(currentW == expectedFullscreenRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedFullscreenRect.w);
  1558. SDLTest_AssertCheck(currentH == expectedFullscreenRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedFullscreenRect.h);
  1559. if (!video_driver_is_wayland) {
  1560. SDLTest_AssertCheck(currentX == expectedFullscreenRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedFullscreenRect.x);
  1561. SDLTest_AssertCheck(currentY == expectedFullscreenRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedFullscreenRect.y);
  1562. } else {
  1563. SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
  1564. }
  1565. /* Leave fullscreen desktop */
  1566. result = SDL_SetWindowFullscreen(window, SDL_FALSE);
  1567. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1568. result = SDL_SyncWindow(window);
  1569. SDLTest_AssertPass("SDL_SyncWindow()");
  1570. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1571. /* Check window was restored correctly */
  1572. currentDisplay = SDL_GetDisplayForWindow(window);
  1573. SDL_GetWindowSize(window, &currentW, &currentH);
  1574. SDL_GetWindowPosition(window, &currentX, &currentY);
  1575. if (!video_driver_is_wayland) {
  1576. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1577. } else {
  1578. SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
  1579. }
  1580. SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
  1581. SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
  1582. if (!video_driver_is_wayland) {
  1583. SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
  1584. SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
  1585. } else {
  1586. SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
  1587. }
  1588. /* Center on display yVariation, and check window properties */
  1589. expectedDisplay = displays[yVariation % displayNum];
  1590. x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1591. y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1592. expectedDisplayRect = (yVariation == 0) ? display0 : display1;
  1593. expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
  1594. expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
  1595. SDL_SetWindowPosition(window, x, y);
  1596. result = SDL_SyncWindow(window);
  1597. SDLTest_AssertPass("SDL_SyncWindow()");
  1598. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1599. currentDisplay = SDL_GetDisplayForWindow(window);
  1600. SDL_GetWindowSize(window, &currentW, &currentH);
  1601. SDL_GetWindowPosition(window, &currentX, &currentY);
  1602. if (!video_driver_is_wayland) {
  1603. SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display ID (current: %d, expected: %d)", currentDisplay, expectedDisplay);
  1604. } else {
  1605. SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning");
  1606. }
  1607. SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
  1608. SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
  1609. if (!video_driver_is_wayland) {
  1610. SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
  1611. SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
  1612. } else {
  1613. SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
  1614. }
  1615. /* Clean up */
  1616. destroyVideoSuiteTestWindow(window);
  1617. }
  1618. }
  1619. SDL_free(displays);
  1620. }
  1621. return TEST_COMPLETED;
  1622. }
  1623. /**
  1624. * Tests calls to SDL_MaximizeWindow(), SDL_RestoreWindow(), and SDL_SetWindowFullscreen(),
  1625. * interspersed with calls to set the window size and position, and verifies the flags,
  1626. * sizes, and positions of maximized, fullscreen, and restored windows.
  1627. *
  1628. * NOTE: This test is good on Mac, Win32, GNOME, and KDE (Wayland and X11). Other *nix
  1629. * desktops, particularly tiling desktops, may not support the expected behavior,
  1630. * so don't be surprised if this fails.
  1631. */
  1632. static int video_getSetWindowState(void *arg)
  1633. {
  1634. const char *title = "video_getSetWindowState Test Window";
  1635. SDL_Window *window;
  1636. int result;
  1637. SDL_Rect display;
  1638. SDL_WindowFlags flags;
  1639. int windowedX, windowedY;
  1640. int currentX, currentY;
  1641. int desiredX = 0, desiredY = 0;
  1642. int windowedW, windowedH;
  1643. int currentW, currentH;
  1644. int desiredW = 0, desiredH = 0;
  1645. SDL_WindowFlags skipFlags = 0;
  1646. const SDL_bool restoreHint = SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", SDL_TRUE);
  1647. const SDL_bool skipPos = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0;
  1648. /* This test is known to be good only on GNOME and KDE. At the time of writing, Weston seems to have maximize related bugs
  1649. * that prevent it from running correctly (no configure events are received when unsetting maximize), and tiling window
  1650. * managers such as Sway have fundamental behavioral differences that conflict with it.
  1651. *
  1652. * Other desktops can be enabled in the future as required.
  1653. */
  1654. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0 || SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
  1655. const char *desktop = SDL_getenv("XDG_CURRENT_DESKTOP");
  1656. if (SDL_strcmp(desktop, "GNOME") != 0 && SDL_strcmp(desktop, "KDE") != 0) {
  1657. SDLTest_Log("Skipping test video_getSetWindowState: desktop environment %s not supported", desktop);
  1658. return TEST_SKIPPED;
  1659. }
  1660. }
  1661. /* Win32 borderless windows are not resizable by default and need this undocumented hint */
  1662. SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", "1");
  1663. /* Call against new test window */
  1664. window = createVideoSuiteTestWindow(title);
  1665. if (!window) {
  1666. return TEST_ABORTED;
  1667. }
  1668. SDL_GetWindowSize(window, &windowedW, &windowedH);
  1669. SDLTest_AssertPass("SDL_GetWindowSize()");
  1670. SDL_GetWindowPosition(window, &windowedX, &windowedY);
  1671. SDLTest_AssertPass("SDL_GetWindowPosition()");
  1672. if (skipPos) {
  1673. SDLTest_Log("Skipping positioning tests: %s reports window positioning as unsupported", SDL_GetCurrentVideoDriver());
  1674. }
  1675. /* Maximize and check the dimensions */
  1676. result = SDL_MaximizeWindow(window);
  1677. SDLTest_AssertPass("SDL_MaximizeWindow()");
  1678. if (result < 0) {
  1679. SDLTest_Log("Skipping state transition tests: %s reports window maximizing as unsupported", SDL_GetCurrentVideoDriver());
  1680. skipFlags |= SDL_WINDOW_MAXIMIZED;
  1681. goto minimize_test;
  1682. }
  1683. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1684. result = SDL_SyncWindow(window);
  1685. SDLTest_AssertPass("SDL_SyncWindow()");
  1686. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1687. flags = SDL_GetWindowFlags(window);
  1688. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1689. SDLTest_AssertCheck(flags & SDL_WINDOW_MAXIMIZED, "Verify the `SDL_WINDOW_MAXIMIZED` flag is set: %s", (flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
  1690. /* Check that the maximized window doesn't extend beyond the usable display bounds.
  1691. * FIXME: Maximizing Win32 borderless windows is broken, so this always fails.
  1692. * Skip it for now.
  1693. */
  1694. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") != 0) {
  1695. result = SDL_GetDisplayUsableBounds(SDL_GetDisplayForWindow(window), &display);
  1696. SDLTest_AssertPass("SDL_GetDisplayUsableBounds()");
  1697. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1698. desiredW = display.w;
  1699. desiredH = display.h;
  1700. currentW = windowedW + 1;
  1701. currentH = windowedH + 1;
  1702. SDL_GetWindowSize(window, &currentW, &currentH);
  1703. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1704. SDLTest_AssertCheck(currentW <= desiredW, "Verify returned width; expected: <= %d, got: %d", desiredW,
  1705. currentW);
  1706. SDLTest_AssertCheck(currentH <= desiredH, "Verify returned height; expected: <= %d, got: %d", desiredH,
  1707. currentH);
  1708. }
  1709. /* Restore and check the dimensions */
  1710. result = SDL_RestoreWindow(window);
  1711. SDLTest_AssertPass("SDL_RestoreWindow()");
  1712. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1713. result = SDL_SyncWindow(window);
  1714. SDLTest_AssertPass("SDL_SyncWindow()");
  1715. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1716. flags = SDL_GetWindowFlags(window);
  1717. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1718. SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
  1719. if (!skipPos) {
  1720. currentX = windowedX + 1;
  1721. currentY = windowedY + 1;
  1722. SDL_GetWindowPosition(window, &currentX, &currentY);
  1723. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  1724. SDLTest_AssertCheck(windowedX == currentX, "Verify returned X coordinate; expected: %d, got: %d", windowedX, currentX);
  1725. SDLTest_AssertCheck(windowedY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", windowedY, currentY);
  1726. }
  1727. currentW = windowedW + 1;
  1728. currentH = windowedH + 1;
  1729. SDL_GetWindowSize(window, &currentW, &currentH);
  1730. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1731. SDLTest_AssertCheck(windowedW == currentW, "Verify returned width; expected: %d, got: %d", windowedW, currentW);
  1732. SDLTest_AssertCheck(windowedH == currentH, "Verify returned height; expected: %d, got: %d", windowedH, currentH);
  1733. /* Maximize, then immediately restore */
  1734. result = SDL_MaximizeWindow(window);
  1735. SDLTest_AssertPass("SDL_MaximizeWindow()");
  1736. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1737. result = SDL_RestoreWindow(window);
  1738. SDLTest_AssertPass("SDL_RestoreWindow()");
  1739. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1740. result = SDL_SyncWindow(window);
  1741. SDLTest_AssertPass("SDL_SyncWindow()");
  1742. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1743. flags = SDL_GetWindowFlags(window);
  1744. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1745. SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
  1746. /* Make sure the restored size and position matches the original windowed size and position. */
  1747. if (!skipPos) {
  1748. currentX = windowedX + 1;
  1749. currentY = windowedY + 1;
  1750. SDL_GetWindowPosition(window, &currentX, &currentY);
  1751. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  1752. SDLTest_AssertCheck(windowedX == currentX, "Verify returned X coordinate; expected: %d, got: %d", windowedX, currentX);
  1753. SDLTest_AssertCheck(windowedY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", windowedY, currentY);
  1754. }
  1755. currentW = windowedW + 1;
  1756. currentH = windowedH + 1;
  1757. SDL_GetWindowSize(window, &currentW, &currentH);
  1758. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1759. SDLTest_AssertCheck(windowedW == currentW, "Verify returned width; expected: %d, got: %d", windowedW, currentW);
  1760. SDLTest_AssertCheck(windowedH == currentH, "Verify returned height; expected: %d, got: %d", windowedH, currentH);
  1761. /* Maximize, then enter fullscreen */
  1762. result = SDL_MaximizeWindow(window);
  1763. SDLTest_AssertPass("SDL_MaximizeWindow()");
  1764. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1765. result = SDL_SetWindowFullscreen(window, SDL_TRUE);
  1766. SDLTest_AssertPass("SDL_SetWindowFullscreen(SDL_TRUE)");
  1767. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1768. result = SDL_SyncWindow(window);
  1769. SDLTest_AssertPass("SDL_SyncWindow()");
  1770. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1771. flags = SDL_GetWindowFlags(window);
  1772. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1773. SDLTest_AssertCheck(flags & SDL_WINDOW_FULLSCREEN, "Verify the `SDL_WINDOW_FULLSCREEN` flag is set: %s", (flags & SDL_WINDOW_FULLSCREEN) ? "true" : "false");
  1774. SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
  1775. /* Verify the fullscreen size and position */
  1776. result = SDL_GetDisplayBounds(SDL_GetDisplayForWindow(window), &display);
  1777. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1778. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1779. if (!skipPos) {
  1780. desiredX = display.x;
  1781. desiredY = display.y;
  1782. currentX = windowedX + 1;
  1783. currentY = windowedY + 1;
  1784. SDL_GetWindowPosition(window, &currentX, &currentY);
  1785. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  1786. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX);
  1787. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY);
  1788. }
  1789. desiredW = display.w;
  1790. desiredH = display.h;
  1791. currentW = windowedW + 1;
  1792. currentH = windowedH + 1;
  1793. SDL_GetWindowSize(window, &currentW, &currentH);
  1794. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1795. SDLTest_AssertCheck(currentW == desiredW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1796. SDLTest_AssertCheck(currentH == desiredH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1797. /* Leave fullscreen and restore the window */
  1798. result = SDL_SetWindowFullscreen(window, SDL_FALSE);
  1799. SDLTest_AssertPass("SDL_SetWindowFullscreen(SDL_FALSE)");
  1800. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1801. result = SDL_RestoreWindow(window);
  1802. SDLTest_AssertPass("SDL_RestoreWindow()");
  1803. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1804. result = SDL_SyncWindow(window);
  1805. SDLTest_AssertPass("SDL_SyncWindow()");
  1806. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1807. flags = SDL_GetWindowFlags(window);
  1808. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1809. SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
  1810. /* Make sure the restored size and position matches the original windowed size and position. */
  1811. if (!skipPos) {
  1812. currentX = windowedX + 1;
  1813. currentY = windowedY + 1;
  1814. SDL_GetWindowPosition(window, &currentX, &currentY);
  1815. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  1816. SDLTest_AssertCheck(windowedX == currentX, "Verify returned X coordinate; expected: %d, got: %d", windowedX, currentX);
  1817. SDLTest_AssertCheck(windowedY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", windowedY, currentY);
  1818. }
  1819. currentW = windowedW + 1;
  1820. currentH = windowedH + 1;
  1821. SDL_GetWindowSize(window, &currentW, &currentH);
  1822. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1823. SDLTest_AssertCheck(windowedW == currentW, "Verify returned width; expected: %d, got: %d", windowedW, currentW);
  1824. SDLTest_AssertCheck(windowedH == currentH, "Verify returned height; expected: %d, got: %d", windowedH, currentH);
  1825. /* Maximize, change size, and restore */
  1826. result = SDL_MaximizeWindow(window);
  1827. SDLTest_AssertPass("SDL_MaximizeWindow()");
  1828. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1829. desiredW = windowedW + 10;
  1830. desiredH = windowedH + 10;
  1831. result = SDL_SetWindowSize(window, desiredW, desiredH);
  1832. SDLTest_AssertPass("SDL_SetWindowSize()");
  1833. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1834. if (!skipPos) {
  1835. desiredX = windowedX + 10;
  1836. desiredY = windowedY + 10;
  1837. result = SDL_SetWindowPosition(window, desiredX, desiredY);
  1838. SDLTest_AssertPass("SDL_SetWindowPosition()");
  1839. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1840. }
  1841. result = SDL_RestoreWindow(window);
  1842. SDLTest_AssertPass("SDL_RestoreWindow()");
  1843. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1844. result = SDL_SyncWindow(window);
  1845. SDLTest_AssertPass("SDL_SyncWindow()");
  1846. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1847. flags = SDL_GetWindowFlags(window);
  1848. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1849. SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
  1850. if (!skipPos) {
  1851. currentX = desiredX + 1;
  1852. currentY = desiredY + 1;
  1853. SDL_GetWindowPosition(window, &currentX, &currentY);
  1854. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  1855. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX);
  1856. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY);
  1857. }
  1858. currentW = desiredW + 1;
  1859. currentH = desiredH + 1;
  1860. SDL_GetWindowSize(window, &currentW, &currentH);
  1861. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1862. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1863. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1864. /* Change size and position, maximize and restore */
  1865. desiredW = windowedW - 5;
  1866. desiredH = windowedH - 5;
  1867. result = SDL_SetWindowSize(window, desiredW, desiredH);
  1868. SDLTest_AssertPass("SDL_SetWindowSize()");
  1869. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1870. if (!skipPos) {
  1871. desiredX = windowedX + 5;
  1872. desiredY = windowedY + 5;
  1873. result = SDL_SetWindowPosition(window, desiredX, desiredY);
  1874. SDLTest_AssertPass("SDL_SetWindowPosition()");
  1875. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1876. }
  1877. result = SDL_MaximizeWindow(window);
  1878. SDLTest_AssertPass("SDL_MaximizeWindow()");
  1879. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1880. result = SDL_RestoreWindow(window);
  1881. SDLTest_AssertPass("SDL_RestoreWindow()");
  1882. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1883. result = SDL_SyncWindow(window);
  1884. SDLTest_AssertPass("SDL_SyncWindow()");
  1885. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1886. flags = SDL_GetWindowFlags(window);
  1887. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1888. SDLTest_AssertCheck(!(flags & SDL_WINDOW_MAXIMIZED), "Verify that the `SDL_WINDOW_MAXIMIZED` flag is cleared: %s", !(flags & SDL_WINDOW_MAXIMIZED) ? "true" : "false");
  1889. if (!skipPos) {
  1890. currentX = desiredX + 1;
  1891. currentY = desiredY + 1;
  1892. SDL_GetWindowPosition(window, &currentX, &currentY);
  1893. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  1894. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X coordinate; expected: %d, got: %d", desiredX, currentX);
  1895. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y coordinate; expected: %d, got: %d", desiredY, currentY);
  1896. }
  1897. currentW = desiredW + 1;
  1898. currentH = desiredH + 1;
  1899. SDL_GetWindowSize(window, &currentW, &currentH);
  1900. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1901. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1902. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1903. minimize_test:
  1904. /* Minimize */
  1905. result = SDL_MinimizeWindow(window);
  1906. if (result == 0) {
  1907. SDLTest_AssertPass("SDL_MinimizeWindow()");
  1908. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1909. result = SDL_SyncWindow(window);
  1910. SDLTest_AssertPass("SDL_SyncWindow()");
  1911. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1912. flags = SDL_GetWindowFlags(window);
  1913. SDLTest_AssertPass("SDL_GetWindowFlags()");
  1914. SDLTest_AssertCheck(flags & SDL_WINDOW_MINIMIZED, "Verify that the `SDL_WINDOW_MINIMIZED` flag is set: %s", (flags & SDL_WINDOW_MINIMIZED) ? "true" : "false");
  1915. } else {
  1916. SDLTest_Log("Skipping minimize test: %s reports window minimizing as unsupported", SDL_GetCurrentVideoDriver());
  1917. skipFlags |= SDL_WINDOW_MINIMIZED;
  1918. }
  1919. /* Clean up */
  1920. destroyVideoSuiteTestWindow(window);
  1921. /* Restore the hint to the previous value */
  1922. SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", restoreHint ? "1" : "0");
  1923. return skipFlags != (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED) ? TEST_COMPLETED : TEST_SKIPPED;
  1924. }
  1925. /**
  1926. * Tests window surface functionality
  1927. */
  1928. static int video_getWindowSurface(void *arg)
  1929. {
  1930. const char *title = "video_getWindowSurface Test Window";
  1931. SDL_Window *window;
  1932. SDL_Surface *surface;
  1933. SDL_Renderer *renderer;
  1934. const char *renderer_name = NULL;
  1935. int result;
  1936. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "dummy") == 0) {
  1937. renderer_name = SDL_SOFTWARE_RENDERER;
  1938. }
  1939. /* Make sure we're testing interaction with an accelerated renderer */
  1940. SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1");
  1941. window = SDL_CreateWindow(title, 320, 320, 0);
  1942. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',320,320,0)");
  1943. SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL");
  1944. surface = SDL_GetWindowSurface(window);
  1945. SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)");
  1946. SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL");
  1947. SDLTest_AssertCheck(SDL_WindowHasSurface(window), "Validate that window has a surface");
  1948. result = SDL_UpdateWindowSurface(window);
  1949. SDLTest_AssertPass("Call to SDL_UpdateWindowSurface(window)");
  1950. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1951. /* We shouldn't be able to create a renderer on a window with a surface */
  1952. renderer = SDL_CreateRenderer(window, renderer_name);
  1953. SDLTest_AssertPass("Call to SDL_CreateRenderer(window, %s)", renderer_name);
  1954. SDLTest_AssertCheck(renderer == NULL, "Validate that returned renderer is NULL");
  1955. result = SDL_DestroyWindowSurface(window);
  1956. SDLTest_AssertPass("Call to SDL_DestroyWindowSurface(window)");
  1957. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1958. SDLTest_AssertCheck(!SDL_WindowHasSurface(window), "Validate that window does not have a surface");
  1959. /* We should be able to create a renderer on the window now */
  1960. renderer = SDL_CreateRenderer(window, renderer_name);
  1961. SDLTest_AssertPass("Call to SDL_CreateRenderer(window, %s)", renderer_name);
  1962. SDLTest_AssertCheck(renderer != NULL, "Validate that returned renderer is not NULL");
  1963. /* We should not be able to create a window surface now, unless it was created by the renderer */
  1964. if (!SDL_WindowHasSurface(window)) {
  1965. surface = SDL_GetWindowSurface(window);
  1966. SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)");
  1967. SDLTest_AssertCheck(surface == NULL, "Validate that returned surface is NULL");
  1968. }
  1969. SDL_DestroyRenderer(renderer);
  1970. SDLTest_AssertPass("Call to SDL_DestroyRenderer(renderer)");
  1971. SDLTest_AssertCheck(!SDL_WindowHasSurface(window), "Validate that window does not have a surface");
  1972. /* We should be able to create a window surface again */
  1973. surface = SDL_GetWindowSurface(window);
  1974. SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)");
  1975. SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL");
  1976. SDLTest_AssertCheck(SDL_WindowHasSurface(window), "Validate that window has a surface");
  1977. /* Clean up */
  1978. SDL_DestroyWindow(window);
  1979. return TEST_COMPLETED;
  1980. }
  1981. /* ================= Test References ================== */
  1982. /* Video test cases */
  1983. static const SDLTest_TestCaseReference videoTest1 = {
  1984. (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED
  1985. };
  1986. static const SDLTest_TestCaseReference videoTest2 = {
  1987. (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED
  1988. };
  1989. static const SDLTest_TestCaseReference videoTest3 = {
  1990. (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED
  1991. };
  1992. static const SDLTest_TestCaseReference videoTest4 = {
  1993. (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED
  1994. };
  1995. static const SDLTest_TestCaseReference videoTest5 = {
  1996. (SDLTest_TestCaseFp)video_getFullscreenDisplayModes, "video_getFullscreenDisplayModes", "Use SDL_GetFullscreenDisplayModes function to get number of display modes", TEST_ENABLED
  1997. };
  1998. static const SDLTest_TestCaseReference videoTest6 = {
  1999. (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED
  2000. };
  2001. static const SDLTest_TestCaseReference videoTest7 = {
  2002. (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED
  2003. };
  2004. static const SDLTest_TestCaseReference videoTest8 = {
  2005. (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED
  2006. };
  2007. static const SDLTest_TestCaseReference videoTest9 = {
  2008. (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED
  2009. };
  2010. static const SDLTest_TestCaseReference videoTest10 = {
  2011. (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks input grab positive and negative cases", TEST_ENABLED
  2012. };
  2013. static const SDLTest_TestCaseReference videoTest11 = {
  2014. (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED
  2015. };
  2016. static const SDLTest_TestCaseReference videoTest12 = {
  2017. (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED
  2018. };
  2019. static const SDLTest_TestCaseReference videoTest13 = {
  2020. (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED
  2021. };
  2022. static const SDLTest_TestCaseReference videoTest14 = {
  2023. (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED
  2024. };
  2025. static const SDLTest_TestCaseReference videoTest15 = {
  2026. (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED
  2027. };
  2028. static const SDLTest_TestCaseReference videoTest16 = {
  2029. (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED
  2030. };
  2031. static const SDLTest_TestCaseReference videoTest17 = {
  2032. (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED
  2033. };
  2034. static const SDLTest_TestCaseReference videoTest18 = {
  2035. (SDLTest_TestCaseFp)video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED
  2036. };
  2037. static const SDLTest_TestCaseReference videoTest19 = {
  2038. (SDLTest_TestCaseFp)video_getSetWindowState, "video_getSetWindowState", "Checks transitioning between windowed, minimized, maximized, and fullscreen states", TEST_ENABLED
  2039. };
  2040. static const SDLTest_TestCaseReference videoTest20 = {
  2041. (SDLTest_TestCaseFp)video_getWindowSurface, "video_getWindowSurface", "Checks window surface functionality", TEST_ENABLED
  2042. };
  2043. /* Sequence of Video test cases */
  2044. static const SDLTest_TestCaseReference *videoTests[] = {
  2045. &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
  2046. &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
  2047. &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
  2048. &videoTest18, &videoTest19, &videoTest20, NULL
  2049. };
  2050. /* Video test suite (global) */
  2051. SDLTest_TestSuiteReference videoTestSuite = {
  2052. "Video",
  2053. NULL,
  2054. videoTests,
  2055. NULL
  2056. };