testautomation_video.c 108 KB

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