testautomation_video.c 99 KB

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