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. Uint32 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. } else {
  51. SDLTest_Log("Unable to create a renderer, some tests may fail on Wayland/XWayland");
  52. }
  53. }
  54. if (needs_events_pumped) {
  55. /* Pump out the event queue */
  56. while (SDL_PollEvent(&event)) {
  57. }
  58. }
  59. return window;
  60. }
  61. /**
  62. * Destroy test window
  63. */
  64. static void destroyVideoSuiteTestWindow(SDL_Window *window)
  65. {
  66. if (window != NULL) {
  67. SDL_DestroyWindow(window);
  68. window = NULL;
  69. SDLTest_AssertPass("Call to SDL_DestroyWindow()");
  70. }
  71. }
  72. /* Test case functions */
  73. /**
  74. * Enable and disable screensaver while checking state
  75. */
  76. static int video_enableDisableScreensaver(void *arg)
  77. {
  78. SDL_bool initialResult;
  79. SDL_bool result;
  80. /* Get current state and proceed according to current state */
  81. initialResult = SDL_ScreenSaverEnabled();
  82. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  83. if (initialResult == SDL_TRUE) {
  84. /* Currently enabled: disable first, then enable again */
  85. /* Disable screensaver and check */
  86. SDL_DisableScreenSaver();
  87. SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
  88. result = SDL_ScreenSaverEnabled();
  89. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  90. SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
  91. /* Enable screensaver and check */
  92. SDL_EnableScreenSaver();
  93. SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
  94. result = SDL_ScreenSaverEnabled();
  95. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  96. SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
  97. } else {
  98. /* Currently disabled: enable first, then disable again */
  99. /* Enable screensaver and check */
  100. SDL_EnableScreenSaver();
  101. SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
  102. result = SDL_ScreenSaverEnabled();
  103. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  104. SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
  105. /* Disable screensaver and check */
  106. SDL_DisableScreenSaver();
  107. SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
  108. result = SDL_ScreenSaverEnabled();
  109. SDLTest_AssertPass("Call to SDL_ScreenSaverEnabled()");
  110. SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_ScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
  111. }
  112. return TEST_COMPLETED;
  113. }
  114. /**
  115. * Tests the functionality of the SDL_CreateWindow function using different sizes
  116. */
  117. static int video_createWindowVariousSizes(void *arg)
  118. {
  119. SDL_Window *window;
  120. const char *title = "video_createWindowVariousSizes Test Window";
  121. int w = 0, h = 0;
  122. int wVariation, hVariation;
  123. for (wVariation = 0; wVariation < 3; wVariation++) {
  124. for (hVariation = 0; hVariation < 3; hVariation++) {
  125. switch (wVariation) {
  126. case 0:
  127. /* Width of 1 */
  128. w = 1;
  129. break;
  130. case 1:
  131. /* Random "normal" width */
  132. w = SDLTest_RandomIntegerInRange(320, 1920);
  133. break;
  134. case 2:
  135. /* Random "large" width */
  136. w = SDLTest_RandomIntegerInRange(2048, 4095);
  137. break;
  138. }
  139. switch (hVariation) {
  140. case 0:
  141. /* Height of 1 */
  142. h = 1;
  143. break;
  144. case 1:
  145. /* Random "normal" height */
  146. h = SDLTest_RandomIntegerInRange(320, 1080);
  147. break;
  148. case 2:
  149. /* Random "large" height */
  150. h = SDLTest_RandomIntegerInRange(2048, 4095);
  151. break;
  152. }
  153. window = SDL_CreateWindow(title, w, h, 0);
  154. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,SHOWN)", w, h);
  155. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  156. /* Clean up */
  157. destroyVideoSuiteTestWindow(window);
  158. }
  159. }
  160. return TEST_COMPLETED;
  161. }
  162. /**
  163. * Tests the functionality of the SDL_CreateWindow function using different flags
  164. */
  165. static int video_createWindowVariousFlags(void *arg)
  166. {
  167. SDL_Window *window;
  168. const char *title = "video_createWindowVariousFlags Test Window";
  169. int w, h;
  170. int fVariation;
  171. Uint32 flags;
  172. /* Standard window */
  173. w = SDLTest_RandomIntegerInRange(320, 1024);
  174. h = SDLTest_RandomIntegerInRange(320, 768);
  175. for (fVariation = 1; fVariation < 14; fVariation++) {
  176. switch (fVariation) {
  177. default:
  178. case 1:
  179. flags = SDL_WINDOW_FULLSCREEN;
  180. /* Skip - blanks screen; comment out next line to run test */
  181. continue;
  182. break;
  183. case 2:
  184. flags = SDL_WINDOW_OPENGL;
  185. /* Skip - not every video driver supports OpenGL; comment out next line to run test */
  186. continue;
  187. break;
  188. case 3:
  189. flags = 0;
  190. break;
  191. case 4:
  192. flags = SDL_WINDOW_HIDDEN;
  193. break;
  194. case 5:
  195. flags = SDL_WINDOW_BORDERLESS;
  196. break;
  197. case 6:
  198. flags = SDL_WINDOW_RESIZABLE;
  199. break;
  200. case 7:
  201. flags = SDL_WINDOW_MINIMIZED;
  202. break;
  203. case 8:
  204. flags = SDL_WINDOW_MAXIMIZED;
  205. break;
  206. case 9:
  207. flags = SDL_WINDOW_MOUSE_GRABBED;
  208. break;
  209. case 10:
  210. flags = SDL_WINDOW_INPUT_FOCUS;
  211. break;
  212. case 11:
  213. flags = SDL_WINDOW_MOUSE_FOCUS;
  214. break;
  215. case 12:
  216. flags = SDL_WINDOW_EXTERNAL;
  217. break;
  218. case 13:
  219. flags = SDL_WINDOW_KEYBOARD_GRABBED;
  220. break;
  221. }
  222. window = SDL_CreateWindow(title, w, h, flags);
  223. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%" SDL_PRIu32 ")", w, h, flags);
  224. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  225. /* Clean up */
  226. destroyVideoSuiteTestWindow(window);
  227. }
  228. return TEST_COMPLETED;
  229. }
  230. /**
  231. * Tests the functionality of the SDL_GetWindowFlags function
  232. */
  233. static int video_getWindowFlags(void *arg)
  234. {
  235. SDL_Window *window;
  236. const char *title = "video_getWindowFlags Test Window";
  237. Uint32 flags;
  238. Uint32 actualFlags;
  239. /* Reliable flag set always set in test window */
  240. flags = 0;
  241. /* Call against new test window */
  242. window = createVideoSuiteTestWindow(title);
  243. if (window != NULL) {
  244. actualFlags = SDL_GetWindowFlags(window);
  245. SDLTest_AssertPass("Call to SDL_GetWindowFlags()");
  246. SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %" SDL_PRIu32 " set, got: %" SDL_PRIu32, flags, actualFlags);
  247. }
  248. /* Clean up */
  249. destroyVideoSuiteTestWindow(window);
  250. return TEST_COMPLETED;
  251. }
  252. /**
  253. * Tests the functionality of the SDL_GetFullscreenDisplayModes function
  254. */
  255. static int video_getFullscreenDisplayModes(void *arg)
  256. {
  257. SDL_DisplayID *displays;
  258. const SDL_DisplayMode **modes;
  259. int count;
  260. int i;
  261. /* Get number of displays */
  262. displays = SDL_GetDisplays(NULL);
  263. if (displays) {
  264. SDLTest_AssertPass("Call to SDL_GetDisplays()");
  265. /* Make call for each display */
  266. for (i = 0; displays[i]; ++i) {
  267. modes = SDL_GetFullscreenDisplayModes(displays[i], &count);
  268. SDLTest_AssertPass("Call to SDL_GetFullscreenDisplayModes(%" SDL_PRIu32 ")", displays[i]);
  269. SDLTest_AssertCheck(modes != NULL, "Validate returned value from function; expected != NULL; got: %p", modes);
  270. SDLTest_AssertCheck(count >= 0, "Validate number of modes; expected: >= 0; got: %d", count);
  271. SDL_free((void *)modes);
  272. }
  273. SDL_free(displays);
  274. }
  275. return TEST_COMPLETED;
  276. }
  277. /**
  278. * Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against current resolution
  279. */
  280. static int video_getClosestDisplayModeCurrentResolution(void *arg)
  281. {
  282. SDL_DisplayID *displays;
  283. const SDL_DisplayMode **modes;
  284. SDL_DisplayMode current;
  285. const SDL_DisplayMode *closest;
  286. int i, num_modes;
  287. /* Get number of displays */
  288. displays = SDL_GetDisplays(NULL);
  289. if (displays) {
  290. SDLTest_AssertPass("Call to SDL_GetDisplays()");
  291. /* Make calls for each display */
  292. for (i = 0; displays[i]; ++i) {
  293. SDLTest_Log("Testing against display: %" SDL_PRIu32, displays[i]);
  294. /* Get first display mode to get a sane resolution; this should always work */
  295. modes = SDL_GetFullscreenDisplayModes(displays[i], &num_modes);
  296. SDLTest_AssertPass("Call to SDL_GetDisplayModes()");
  297. SDLTest_Assert(modes != NULL, "Verify returned value is not NULL");
  298. if (num_modes > 0) {
  299. SDL_memcpy(&current, modes[0], sizeof(current));
  300. /* Make call */
  301. closest = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, SDL_FALSE);
  302. SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)");
  303. SDLTest_Assert(closest != NULL, "Verify returned value is not NULL");
  304. /* Check that one gets the current resolution back again */
  305. if (closest) {
  306. SDLTest_AssertCheck(closest->w == current.w,
  307. "Verify returned width matches current width; expected: %d, got: %d",
  308. current.w, closest->w);
  309. SDLTest_AssertCheck(closest->h == current.h,
  310. "Verify returned height matches current height; expected: %d, got: %d",
  311. current.h, closest->h);
  312. }
  313. }
  314. SDL_free((void *)modes);
  315. }
  316. SDL_free(displays);
  317. }
  318. return TEST_COMPLETED;
  319. }
  320. /**
  321. * Tests the functionality of the SDL_GetClosestFullscreenDisplayMode function against random resolution
  322. */
  323. static int video_getClosestDisplayModeRandomResolution(void *arg)
  324. {
  325. SDL_DisplayID *displays;
  326. SDL_DisplayMode target;
  327. int i;
  328. int variation;
  329. /* Get number of displays */
  330. displays = SDL_GetDisplays(NULL);
  331. if (displays) {
  332. SDLTest_AssertPass("Call to SDL_GetDisplays()");
  333. /* Make calls for each display */
  334. for (i = 0; displays[i]; ++i) {
  335. SDLTest_Log("Testing against display: %" SDL_PRIu32, displays[i]);
  336. for (variation = 0; variation < 16; variation++) {
  337. /* Set random constraints */
  338. SDL_zero(target);
  339. target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  340. target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  341. target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
  342. /* Make call; may or may not find anything, so don't validate any further */
  343. SDL_GetClosestFullscreenDisplayMode(displays[i], target.w, target.h, target.refresh_rate, SDL_FALSE);
  344. SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d)", variation);
  345. }
  346. }
  347. SDL_free(displays);
  348. }
  349. return TEST_COMPLETED;
  350. }
  351. /**
  352. * Tests call to SDL_GetWindowFullscreenMode
  353. *
  354. * \sa SDL_GetWindowFullscreenMode
  355. */
  356. static int video_getWindowDisplayMode(void *arg)
  357. {
  358. SDL_Window *window;
  359. const char *title = "video_getWindowDisplayMode Test Window";
  360. const SDL_DisplayMode *mode;
  361. /* Call against new test window */
  362. window = createVideoSuiteTestWindow(title);
  363. if (window != NULL) {
  364. mode = SDL_GetWindowFullscreenMode(window);
  365. SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode()");
  366. SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode);
  367. }
  368. /* Clean up */
  369. destroyVideoSuiteTestWindow(window);
  370. return TEST_COMPLETED;
  371. }
  372. /* Helper function that checks for an 'Invalid window' error */
  373. static void checkInvalidWindowError(void)
  374. {
  375. const char *invalidWindowError = "Invalid window";
  376. const char *lastError;
  377. lastError = SDL_GetError();
  378. SDLTest_AssertPass("SDL_GetError()");
  379. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  380. if (lastError != NULL) {
  381. SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
  382. "SDL_GetError(): expected message '%s', was message: '%s'",
  383. invalidWindowError,
  384. lastError);
  385. SDL_ClearError();
  386. SDLTest_AssertPass("Call to SDL_ClearError()");
  387. }
  388. }
  389. /**
  390. * Tests call to SDL_GetWindowFullscreenMode with invalid input
  391. *
  392. * \sa SDL_GetWindowFullscreenMode
  393. */
  394. static int video_getWindowDisplayModeNegative(void *arg)
  395. {
  396. const SDL_DisplayMode *mode;
  397. /* Call against invalid window */
  398. mode = SDL_GetWindowFullscreenMode(NULL);
  399. SDLTest_AssertPass("Call to SDL_GetWindowFullscreenMode(window=NULL)");
  400. SDLTest_AssertCheck(mode == NULL, "Validate result value; expected: NULL, got: %p", mode);
  401. checkInvalidWindowError();
  402. return TEST_COMPLETED;
  403. }
  404. /* Helper for setting and checking the window mouse grab state */
  405. static void setAndCheckWindowMouseGrabState(SDL_Window *window, SDL_bool desiredState)
  406. {
  407. SDL_bool currentState;
  408. /* Set state */
  409. SDL_SetWindowMouseGrab(window, desiredState);
  410. SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  411. /* Get and check state */
  412. currentState = SDL_GetWindowMouseGrab(window);
  413. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  414. SDLTest_AssertCheck(
  415. currentState == desiredState,
  416. "Validate returned state; expected: %s, got: %s",
  417. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  418. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  419. if (desiredState) {
  420. SDLTest_AssertCheck(
  421. SDL_GetGrabbedWindow() == window,
  422. "Grabbed window should be to our window");
  423. SDLTest_AssertCheck(
  424. SDL_GetWindowGrab(window),
  425. "SDL_GetWindowGrab() should return SDL_TRUE");
  426. SDLTest_AssertCheck(
  427. SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED,
  428. "SDL_WINDOW_MOUSE_GRABBED should be set");
  429. } else {
  430. SDLTest_AssertCheck(
  431. !(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED),
  432. "SDL_WINDOW_MOUSE_GRABBED should be unset");
  433. }
  434. }
  435. /* Helper for setting and checking the window keyboard grab state */
  436. static void setAndCheckWindowKeyboardGrabState(SDL_Window *window, SDL_bool desiredState)
  437. {
  438. SDL_bool currentState;
  439. /* Set state */
  440. SDL_SetWindowKeyboardGrab(window, desiredState);
  441. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  442. /* Get and check state */
  443. currentState = SDL_GetWindowKeyboardGrab(window);
  444. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  445. SDLTest_AssertCheck(
  446. currentState == desiredState,
  447. "Validate returned state; expected: %s, got: %s",
  448. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  449. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  450. if (desiredState) {
  451. SDLTest_AssertCheck(
  452. SDL_GetGrabbedWindow() == window,
  453. "Grabbed window should be set to our window");
  454. SDLTest_AssertCheck(
  455. SDL_GetWindowGrab(window),
  456. "SDL_GetWindowGrab() should return SDL_TRUE");
  457. SDLTest_AssertCheck(
  458. SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED,
  459. "SDL_WINDOW_KEYBOARD_GRABBED should be set");
  460. } else {
  461. SDLTest_AssertCheck(
  462. !(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED),
  463. "SDL_WINDOW_KEYBOARD_GRABBED should be unset");
  464. }
  465. }
  466. /**
  467. * Tests keyboard and mouse grab support
  468. *
  469. * \sa SDL_GetWindowGrab
  470. * \sa SDL_SetWindowGrab
  471. */
  472. static int video_getSetWindowGrab(void *arg)
  473. {
  474. const char *title = "video_getSetWindowGrab Test Window";
  475. SDL_Window *window;
  476. SDL_bool originalMouseState, originalKeyboardState;
  477. SDL_bool hasFocusGained = SDL_FALSE;
  478. /* Call against new test window */
  479. window = createVideoSuiteTestWindow(title);
  480. if (!window) {
  481. return TEST_ABORTED;
  482. }
  483. /* Need to raise the window to have and SDL_EVENT_WINDOW_FOCUS_GAINED,
  484. * so that the window gets the flags SDL_WINDOW_INPUT_FOCUS,
  485. * so that it can be "grabbed" */
  486. SDL_RaiseWindow(window);
  487. if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS)) {
  488. int count = 0;
  489. SDL_Event evt;
  490. SDL_zero(evt);
  491. while (!hasFocusGained && count++ < 3) {
  492. while (SDL_PollEvent(&evt)) {
  493. if (evt.type == SDL_EVENT_WINDOW_FOCUS_GAINED) {
  494. hasFocusGained = SDL_TRUE;
  495. }
  496. }
  497. }
  498. } else {
  499. hasFocusGained = SDL_TRUE;
  500. }
  501. SDLTest_AssertCheck(hasFocusGained == SDL_TRUE, "Expectded window with focus");
  502. /* Get state */
  503. originalMouseState = SDL_GetWindowMouseGrab(window);
  504. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  505. originalKeyboardState = SDL_GetWindowKeyboardGrab(window);
  506. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  507. /* F */
  508. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  509. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  510. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  511. "SDL_GetWindowGrab should return SDL_FALSE");
  512. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  513. "Expected NULL grabbed window");
  514. /* F --> F */
  515. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  516. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  517. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  518. "Expected NULL grabbed window");
  519. /* F --> T */
  520. setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  521. setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  522. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  523. "SDL_GetWindowGrab() should return SDL_TRUE");
  524. /* T --> T */
  525. setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  526. setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  527. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  528. "SDL_GetWindowGrab() should return SDL_TRUE");
  529. /* M: T --> F */
  530. /* K: T --> T */
  531. setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  532. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  533. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  534. "SDL_GetWindowGrab() should return SDL_TRUE");
  535. /* M: F --> T */
  536. /* K: T --> F */
  537. setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  538. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  539. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  540. "SDL_GetWindowGrab() should return SDL_TRUE");
  541. /* M: T --> F */
  542. /* K: F --> F */
  543. setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  544. setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  545. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  546. "SDL_GetWindowGrab() should return SDL_FALSE");
  547. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  548. "Expected NULL grabbed window");
  549. /* Using the older SDL_SetWindowGrab API should only grab mouse by default */
  550. SDL_SetWindowGrab(window, SDL_TRUE);
  551. SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
  552. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  553. "SDL_GetWindowGrab() should return SDL_TRUE");
  554. SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
  555. "SDL_GetWindowMouseGrab() should return SDL_TRUE");
  556. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  557. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  558. SDL_SetWindowGrab(window, SDL_FALSE);
  559. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  560. "SDL_GetWindowGrab() should return SDL_FALSE");
  561. SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
  562. "SDL_GetWindowMouseGrab() should return SDL_FALSE");
  563. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  564. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  565. /* Now test with SDL_HINT_GRAB_KEYBOARD set. We should get keyboard grab now. */
  566. SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
  567. SDL_SetWindowGrab(window, SDL_TRUE);
  568. SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
  569. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  570. "SDL_GetWindowGrab() should return SDL_TRUE");
  571. SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
  572. "SDL_GetWindowMouseGrab() should return SDL_TRUE");
  573. SDLTest_AssertCheck(SDL_GetWindowKeyboardGrab(window),
  574. "SDL_GetWindowKeyboardGrab() should return SDL_TRUE");
  575. SDL_SetWindowGrab(window, SDL_FALSE);
  576. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  577. "SDL_GetWindowGrab() should return SDL_FALSE");
  578. SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
  579. "SDL_GetWindowMouseGrab() should return SDL_FALSE");
  580. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  581. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  582. /* Negative tests */
  583. SDL_GetWindowGrab(NULL);
  584. SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
  585. checkInvalidWindowError();
  586. SDL_GetWindowKeyboardGrab(NULL);
  587. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)");
  588. checkInvalidWindowError();
  589. SDL_SetWindowGrab(NULL, SDL_FALSE);
  590. SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
  591. checkInvalidWindowError();
  592. SDL_SetWindowKeyboardGrab(NULL, SDL_FALSE);
  593. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE)");
  594. checkInvalidWindowError();
  595. SDL_SetWindowGrab(NULL, SDL_TRUE);
  596. SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_TRUE)");
  597. checkInvalidWindowError();
  598. SDL_SetWindowKeyboardGrab(NULL, SDL_TRUE);
  599. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE)");
  600. checkInvalidWindowError();
  601. /* Restore state */
  602. setAndCheckWindowMouseGrabState(window, originalMouseState);
  603. setAndCheckWindowKeyboardGrabState(window, originalKeyboardState);
  604. /* Clean up */
  605. destroyVideoSuiteTestWindow(window);
  606. return TEST_COMPLETED;
  607. }
  608. /**
  609. * Tests call to SDL_GetWindowID and SDL_GetWindowFromID
  610. *
  611. * \sa SDL_GetWindowID
  612. * \sa SDL_SetWindowFromID
  613. */
  614. static int video_getWindowId(void *arg)
  615. {
  616. const char *title = "video_getWindowId Test Window";
  617. SDL_Window *window;
  618. SDL_Window *result;
  619. Uint32 id, randomId;
  620. /* Call against new test window */
  621. window = createVideoSuiteTestWindow(title);
  622. if (!window) {
  623. return TEST_ABORTED;
  624. }
  625. /* Get ID */
  626. id = SDL_GetWindowID(window);
  627. SDLTest_AssertPass("Call to SDL_GetWindowID()");
  628. /* Get window from ID */
  629. result = SDL_GetWindowFromID(id);
  630. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 ")", id);
  631. SDLTest_AssertCheck(result == window, "Verify result matches window pointer");
  632. /* Get window from random large ID, no result check */
  633. randomId = SDLTest_RandomIntegerInRange(UINT8_MAX, UINT16_MAX);
  634. result = SDL_GetWindowFromID(randomId);
  635. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/random_large)", randomId);
  636. /* Get window from 0 and Uint32 max ID, no result check */
  637. result = SDL_GetWindowFromID(0);
  638. SDLTest_AssertPass("Call to SDL_GetWindowID(0)");
  639. result = SDL_GetWindowFromID(UINT32_MAX);
  640. SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)");
  641. /* Clean up */
  642. destroyVideoSuiteTestWindow(window);
  643. /* Get window from ID for closed window */
  644. result = SDL_GetWindowFromID(id);
  645. SDLTest_AssertPass("Call to SDL_GetWindowID(%" SDL_PRIu32 "/closed_window)", id);
  646. SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
  647. /* Negative test */
  648. SDL_ClearError();
  649. SDLTest_AssertPass("Call to SDL_ClearError()");
  650. id = SDL_GetWindowID(NULL);
  651. SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
  652. checkInvalidWindowError();
  653. return TEST_COMPLETED;
  654. }
  655. /**
  656. * Tests call to SDL_GetWindowPixelFormat
  657. *
  658. * \sa SDL_GetWindowPixelFormat
  659. */
  660. static int video_getWindowPixelFormat(void *arg)
  661. {
  662. const char *title = "video_getWindowPixelFormat Test Window";
  663. SDL_Window *window;
  664. Uint32 format;
  665. /* Call against new test window */
  666. window = createVideoSuiteTestWindow(title);
  667. if (!window) {
  668. return TEST_ABORTED;
  669. }
  670. /* Get format */
  671. format = SDL_GetWindowPixelFormat(window);
  672. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
  673. SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %" SDL_PRIu32, SDL_PIXELFORMAT_UNKNOWN, format);
  674. /* Clean up */
  675. destroyVideoSuiteTestWindow(window);
  676. /* Negative test */
  677. SDL_ClearError();
  678. SDLTest_AssertPass("Call to SDL_ClearError()");
  679. format = SDL_GetWindowPixelFormat(NULL);
  680. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
  681. checkInvalidWindowError();
  682. return TEST_COMPLETED;
  683. }
  684. static SDL_bool getPositionFromEvent(int *x, int *y)
  685. {
  686. SDL_bool ret = SDL_FALSE;
  687. SDL_Event evt;
  688. SDL_zero(evt);
  689. while (SDL_PollEvent(&evt)) {
  690. if (evt.type == SDL_EVENT_WINDOW_MOVED) {
  691. *x = evt.window.data1;
  692. *y = evt.window.data2;
  693. ret = SDL_TRUE;
  694. }
  695. }
  696. return ret;
  697. }
  698. static SDL_bool getSizeFromEvent(int *w, int *h)
  699. {
  700. SDL_bool ret = SDL_FALSE;
  701. SDL_Event evt;
  702. SDL_zero(evt);
  703. while (SDL_PollEvent(&evt)) {
  704. if (evt.type == SDL_EVENT_WINDOW_RESIZED) {
  705. *w = evt.window.data1;
  706. *h = evt.window.data2;
  707. ret = SDL_TRUE;
  708. }
  709. }
  710. return ret;
  711. }
  712. /**
  713. * Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
  714. *
  715. * \sa SDL_GetWindowPosition
  716. * \sa SDL_SetWindowPosition
  717. */
  718. static int video_getSetWindowPosition(void *arg)
  719. {
  720. const char *title = "video_getSetWindowPosition Test Window";
  721. SDL_Window *window;
  722. int result;
  723. int maxxVariation, maxyVariation;
  724. int xVariation, yVariation;
  725. int referenceX, referenceY;
  726. int currentX, currentY;
  727. int desiredX, desiredY;
  728. SDL_Rect display_bounds;
  729. /* Call against new test window */
  730. window = createVideoSuiteTestWindow(title);
  731. if (!window) {
  732. return TEST_ABORTED;
  733. }
  734. /* Sanity check */
  735. SDL_GetWindowPosition(window, &currentX, &currentY);
  736. if (SDL_SetWindowPosition(window, currentX, currentY) < 0) {
  737. SDLTest_Log("Skipping window positioning tests: %s reports window positioning as unsupported", SDL_GetCurrentVideoDriver());
  738. goto null_tests;
  739. }
  740. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
  741. /* The X11 server allows arbitrary window placement, but compositing
  742. * window managers such as GNOME and KDE force windows to be within
  743. * desktop bounds.
  744. */
  745. maxxVariation = 2;
  746. maxyVariation = 2;
  747. SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display_bounds);
  748. } else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "cocoa") == 0) {
  749. /* Platform doesn't allow windows with negative Y desktop bounds */
  750. maxxVariation = 4;
  751. maxyVariation = 3;
  752. SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display_bounds);
  753. } else {
  754. /* Platform allows windows to be placed out of bounds */
  755. maxxVariation = 4;
  756. maxyVariation = 4;
  757. SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display_bounds);
  758. }
  759. for (xVariation = 0; xVariation < maxxVariation; xVariation++) {
  760. for (yVariation = 0; yVariation < maxyVariation; yVariation++) {
  761. switch (xVariation) {
  762. default:
  763. case 0:
  764. /* Zero X Position */
  765. desiredX = display_bounds.x > 0 ? display_bounds.x : 0;
  766. break;
  767. case 1:
  768. /* Random X position inside screen */
  769. desiredX = SDLTest_RandomIntegerInRange(display_bounds.x + 1, display_bounds.x + 100);
  770. break;
  771. case 2:
  772. /* Random X position outside screen (positive) */
  773. desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
  774. break;
  775. case 3:
  776. /* Random X position outside screen (negative) */
  777. desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
  778. break;
  779. }
  780. switch (yVariation) {
  781. default:
  782. case 0:
  783. /* Zero Y Position */
  784. desiredY = display_bounds.y > 0 ? display_bounds.y : 0;
  785. break;
  786. case 1:
  787. /* Random Y position inside screen */
  788. desiredY = SDLTest_RandomIntegerInRange(display_bounds.y + 1, display_bounds.y + 100);
  789. break;
  790. case 2:
  791. /* Random Y position outside screen (positive) */
  792. desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
  793. break;
  794. case 3:
  795. /* Random Y position outside screen (negative) */
  796. desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
  797. break;
  798. }
  799. /* Set position */
  800. SDL_SetWindowPosition(window, desiredX, desiredY);
  801. SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
  802. result = SDL_SyncWindow(window);
  803. SDLTest_AssertPass("SDL_SyncWindow()");
  804. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  805. /* Get position */
  806. currentX = desiredX + 1;
  807. currentY = desiredY + 1;
  808. SDL_GetWindowPosition(window, &currentX, &currentY);
  809. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  810. if (desiredX == currentX && desiredY == currentY) {
  811. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  812. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  813. } else {
  814. SDL_bool hasEvent;
  815. /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
  816. * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */
  817. currentX = desiredX + 1;
  818. currentY = desiredY + 1;
  819. hasEvent = getPositionFromEvent(&currentX, &currentY);
  820. SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing position was not honored by WM, checking present of SDL_EVENT_WINDOW_MOVED");
  821. if (hasEvent) {
  822. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position is the position from SDL event; expected: %d, got: %d", desiredX, currentX);
  823. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position is the position from SDL event; expected: %d, got: %d", desiredY, currentY);
  824. }
  825. }
  826. /* Get position X */
  827. currentX = desiredX + 1;
  828. SDL_GetWindowPosition(window, &currentX, NULL);
  829. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
  830. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  831. /* Get position Y */
  832. currentY = desiredY + 1;
  833. SDL_GetWindowPosition(window, NULL, &currentY);
  834. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
  835. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  836. }
  837. }
  838. null_tests:
  839. /* Dummy call with both pointers NULL */
  840. SDL_GetWindowPosition(window, NULL, NULL);
  841. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
  842. /* Clean up */
  843. destroyVideoSuiteTestWindow(window);
  844. /* Set some 'magic' value for later check that nothing was changed */
  845. referenceX = SDLTest_RandomSint32();
  846. referenceY = SDLTest_RandomSint32();
  847. currentX = referenceX;
  848. currentY = referenceY;
  849. desiredX = SDLTest_RandomSint32();
  850. desiredY = SDLTest_RandomSint32();
  851. /* Negative tests */
  852. SDL_ClearError();
  853. SDLTest_AssertPass("Call to SDL_ClearError()");
  854. SDL_GetWindowPosition(NULL, &currentX, &currentY);
  855. SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
  856. SDLTest_AssertCheck(
  857. currentX == referenceX && currentY == referenceY,
  858. "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
  859. referenceX, referenceY,
  860. currentX, currentY);
  861. checkInvalidWindowError();
  862. SDL_GetWindowPosition(NULL, NULL, NULL);
  863. SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
  864. checkInvalidWindowError();
  865. SDL_SetWindowPosition(NULL, desiredX, desiredY);
  866. SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
  867. checkInvalidWindowError();
  868. return TEST_COMPLETED;
  869. }
  870. /* Helper function that checks for an 'Invalid parameter' error */
  871. static void checkInvalidParameterError(void)
  872. {
  873. const char *invalidParameterError = "Parameter";
  874. const char *lastError;
  875. lastError = SDL_GetError();
  876. SDLTest_AssertPass("SDL_GetError()");
  877. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  878. if (lastError != NULL) {
  879. SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
  880. "SDL_GetError(): expected message starts with '%s', was message: '%s'",
  881. invalidParameterError,
  882. lastError);
  883. SDL_ClearError();
  884. SDLTest_AssertPass("Call to SDL_ClearError()");
  885. }
  886. }
  887. /**
  888. * Tests call to SDL_GetWindowSize and SDL_SetWindowSize
  889. *
  890. * \sa SDL_GetWindowSize
  891. * \sa SDL_SetWindowSize
  892. */
  893. static int video_getSetWindowSize(void *arg)
  894. {
  895. const char *title = "video_getSetWindowSize Test Window";
  896. SDL_Window *window;
  897. int result;
  898. SDL_Rect display;
  899. int maxwVariation, maxhVariation;
  900. int wVariation, hVariation;
  901. int referenceW, referenceH;
  902. int currentW, currentH;
  903. int desiredW, desiredH;
  904. const SDL_bool restoreHint = SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", SDL_TRUE);
  905. /* Win32 borderless windows are not resizable by default and need this undocumented hint */
  906. SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", "1");
  907. /* Get display bounds for size range */
  908. result = SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display);
  909. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  910. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  911. if (result != 0) {
  912. return TEST_ABORTED;
  913. }
  914. /* Call against new test window */
  915. window = createVideoSuiteTestWindow(title);
  916. if (!window) {
  917. return TEST_ABORTED;
  918. }
  919. SDL_GetWindowSize(window, &currentW, &currentH);
  920. if (SDL_SetWindowSize(window, currentW, currentH)) {
  921. SDLTest_Log("Skipping window resize tests: %s reports window resizing as unsupported", SDL_GetCurrentVideoDriver());
  922. goto null_tests;
  923. }
  924. if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") == 0 ||
  925. SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
  926. /* Platform clips window size to screen size */
  927. maxwVariation = 4;
  928. maxhVariation = 4;
  929. } else {
  930. /* Platform allows window size >= screen size */
  931. maxwVariation = 5;
  932. maxhVariation = 5;
  933. }
  934. for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
  935. for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
  936. switch (wVariation) {
  937. default:
  938. case 0:
  939. /* 1 Pixel Wide */
  940. desiredW = 1;
  941. break;
  942. case 1:
  943. /* Random width inside screen */
  944. desiredW = SDLTest_RandomIntegerInRange(1, 100);
  945. break;
  946. case 2:
  947. /* Width 1 pixel smaller than screen */
  948. desiredW = display.w - 1;
  949. break;
  950. case 3:
  951. /* Width at screen size */
  952. desiredW = display.w;
  953. break;
  954. case 4:
  955. /* Width 1 pixel larger than screen */
  956. desiredW = display.w + 1;
  957. break;
  958. }
  959. switch (hVariation) {
  960. default:
  961. case 0:
  962. /* 1 Pixel High */
  963. desiredH = 1;
  964. break;
  965. case 1:
  966. /* Random height inside screen */
  967. desiredH = SDLTest_RandomIntegerInRange(1, 100);
  968. break;
  969. case 2:
  970. /* Height 1 pixel smaller than screen */
  971. desiredH = display.h - 1;
  972. break;
  973. case 3:
  974. /* Height at screen size */
  975. desiredH = display.h;
  976. break;
  977. case 4:
  978. /* Height 1 pixel larger than screen */
  979. desiredH = display.h + 1;
  980. break;
  981. }
  982. /* Set size */
  983. SDL_SetWindowSize(window, desiredW, desiredH);
  984. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  985. result = SDL_SyncWindow(window);
  986. SDLTest_AssertPass("SDL_SyncWindow()");
  987. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  988. /* Get size */
  989. currentW = desiredW + 1;
  990. currentH = desiredH + 1;
  991. SDL_GetWindowSize(window, &currentW, &currentH);
  992. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  993. if (desiredW == currentW && desiredH == currentH) {
  994. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  995. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  996. } else {
  997. SDL_bool hasEvent;
  998. /* SDL_SetWindowPosition() and SDL_SetWindowSize() will make requests of the window manager and set the internal position and size,
  999. * and then we get events signaling what actually happened, and they get passed on to the application if they're not what we expect. */
  1000. currentW = desiredW + 1;
  1001. currentH = desiredH + 1;
  1002. hasEvent = getSizeFromEvent(&currentW, &currentH);
  1003. SDLTest_AssertCheck(hasEvent == SDL_TRUE, "Changing size was not honored by WM, checking presence of SDL_EVENT_WINDOW_RESIZED");
  1004. if (hasEvent) {
  1005. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width is the one from SDL event; expected: %d, got: %d", desiredW, currentW);
  1006. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height is the one from SDL event; expected: %d, got: %d", desiredH, currentH);
  1007. }
  1008. }
  1009. /* Get just width */
  1010. currentW = desiredW + 1;
  1011. SDL_GetWindowSize(window, &currentW, NULL);
  1012. SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
  1013. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1014. /* Get just height */
  1015. currentH = desiredH + 1;
  1016. SDL_GetWindowSize(window, NULL, &currentH);
  1017. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
  1018. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1019. }
  1020. }
  1021. null_tests:
  1022. /* Dummy call with both pointers NULL */
  1023. SDL_GetWindowSize(window, NULL, NULL);
  1024. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
  1025. /* Negative tests for parameter input */
  1026. SDL_ClearError();
  1027. SDLTest_AssertPass("Call to SDL_ClearError()");
  1028. for (desiredH = -2; desiredH < 2; desiredH++) {
  1029. for (desiredW = -2; desiredW < 2; desiredW++) {
  1030. if (desiredW <= 0 || desiredH <= 0) {
  1031. SDL_SetWindowSize(window, desiredW, desiredH);
  1032. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  1033. checkInvalidParameterError();
  1034. }
  1035. }
  1036. }
  1037. /* Clean up */
  1038. destroyVideoSuiteTestWindow(window);
  1039. /* Set some 'magic' value for later check that nothing was changed */
  1040. referenceW = SDLTest_RandomSint32();
  1041. referenceH = SDLTest_RandomSint32();
  1042. currentW = referenceW;
  1043. currentH = referenceH;
  1044. desiredW = SDLTest_RandomSint32();
  1045. desiredH = SDLTest_RandomSint32();
  1046. /* Negative tests for window input */
  1047. SDL_ClearError();
  1048. SDLTest_AssertPass("Call to SDL_ClearError()");
  1049. SDL_GetWindowSize(NULL, &currentW, &currentH);
  1050. SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
  1051. SDLTest_AssertCheck(
  1052. currentW == referenceW && currentH == referenceH,
  1053. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1054. referenceW, referenceH,
  1055. currentW, currentH);
  1056. checkInvalidWindowError();
  1057. SDL_GetWindowSize(NULL, NULL, NULL);
  1058. SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
  1059. checkInvalidWindowError();
  1060. SDL_SetWindowSize(NULL, desiredW, desiredH);
  1061. SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
  1062. checkInvalidWindowError();
  1063. /* Restore the hint to the previous value */
  1064. SDL_SetHint("SDL_BORDERLESS_RESIZABLE_STYLE", restoreHint ? "1" : "0");
  1065. return TEST_COMPLETED;
  1066. }
  1067. /**
  1068. * Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
  1069. *
  1070. */
  1071. static int video_getSetWindowMinimumSize(void *arg)
  1072. {
  1073. const char *title = "video_getSetWindowMinimumSize Test Window";
  1074. SDL_Window *window;
  1075. int result;
  1076. SDL_Rect display;
  1077. int wVariation, hVariation;
  1078. int referenceW, referenceH;
  1079. int currentW, currentH;
  1080. int desiredW = 1;
  1081. int desiredH = 1;
  1082. /* Get display bounds for size range */
  1083. result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display);
  1084. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1085. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1086. if (result != 0) {
  1087. return TEST_ABORTED;
  1088. }
  1089. /* Call against new test window */
  1090. window = createVideoSuiteTestWindow(title);
  1091. if (!window) {
  1092. return TEST_ABORTED;
  1093. }
  1094. for (wVariation = 0; wVariation < 5; wVariation++) {
  1095. for (hVariation = 0; hVariation < 5; hVariation++) {
  1096. switch (wVariation) {
  1097. case 0:
  1098. /* 1 Pixel Wide */
  1099. desiredW = 1;
  1100. break;
  1101. case 1:
  1102. /* Random width inside screen */
  1103. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1104. break;
  1105. case 2:
  1106. /* Width at screen size */
  1107. desiredW = display.w;
  1108. break;
  1109. }
  1110. switch (hVariation) {
  1111. case 0:
  1112. /* 1 Pixel High */
  1113. desiredH = 1;
  1114. break;
  1115. case 1:
  1116. /* Random height inside screen */
  1117. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1118. break;
  1119. case 2:
  1120. /* Height at screen size */
  1121. desiredH = display.h;
  1122. break;
  1123. case 4:
  1124. /* Height 1 pixel larger than screen */
  1125. desiredH = display.h + 1;
  1126. break;
  1127. }
  1128. /* Set size */
  1129. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1130. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1131. /* Get size */
  1132. currentW = desiredW + 1;
  1133. currentH = desiredH + 1;
  1134. SDL_GetWindowMinimumSize(window, &currentW, &currentH);
  1135. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
  1136. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1137. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1138. /* Get just width */
  1139. currentW = desiredW + 1;
  1140. SDL_GetWindowMinimumSize(window, &currentW, NULL);
  1141. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
  1142. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1143. /* Get just height */
  1144. currentH = desiredH + 1;
  1145. SDL_GetWindowMinimumSize(window, NULL, &currentH);
  1146. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
  1147. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1148. }
  1149. }
  1150. /* Dummy call with both pointers NULL */
  1151. SDL_GetWindowMinimumSize(window, NULL, NULL);
  1152. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
  1153. /* Negative tests for parameter input */
  1154. SDL_ClearError();
  1155. SDLTest_AssertPass("Call to SDL_ClearError()");
  1156. for (desiredH = -2; desiredH < 2; desiredH++) {
  1157. for (desiredW = -2; desiredW < 2; desiredW++) {
  1158. if (desiredW < 0 || desiredH < 0) {
  1159. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1160. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1161. checkInvalidParameterError();
  1162. }
  1163. }
  1164. }
  1165. /* Clean up */
  1166. destroyVideoSuiteTestWindow(window);
  1167. /* Set some 'magic' value for later check that nothing was changed */
  1168. referenceW = SDLTest_RandomSint32();
  1169. referenceH = SDLTest_RandomSint32();
  1170. currentW = referenceW;
  1171. currentH = referenceH;
  1172. desiredW = SDLTest_RandomSint32();
  1173. desiredH = SDLTest_RandomSint32();
  1174. /* Negative tests for window input */
  1175. SDL_ClearError();
  1176. SDLTest_AssertPass("Call to SDL_ClearError()");
  1177. SDL_GetWindowMinimumSize(NULL, &currentW, &currentH);
  1178. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
  1179. SDLTest_AssertCheck(
  1180. currentW == referenceW && currentH == referenceH,
  1181. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1182. referenceW, referenceH,
  1183. currentW, currentH);
  1184. checkInvalidWindowError();
  1185. SDL_GetWindowMinimumSize(NULL, NULL, NULL);
  1186. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
  1187. checkInvalidWindowError();
  1188. SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
  1189. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
  1190. checkInvalidWindowError();
  1191. return TEST_COMPLETED;
  1192. }
  1193. /**
  1194. * Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
  1195. *
  1196. */
  1197. static int video_getSetWindowMaximumSize(void *arg)
  1198. {
  1199. const char *title = "video_getSetWindowMaximumSize Test Window";
  1200. SDL_Window *window;
  1201. int result;
  1202. SDL_Rect display;
  1203. int wVariation, hVariation;
  1204. int referenceW, referenceH;
  1205. int currentW, currentH;
  1206. int desiredW = 0, desiredH = 0;
  1207. /* Get display bounds for size range */
  1208. result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display);
  1209. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1210. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1211. if (result != 0) {
  1212. return TEST_ABORTED;
  1213. }
  1214. /* Call against new test window */
  1215. window = createVideoSuiteTestWindow(title);
  1216. if (!window) {
  1217. return TEST_ABORTED;
  1218. }
  1219. for (wVariation = 0; wVariation < 3; wVariation++) {
  1220. for (hVariation = 0; hVariation < 3; hVariation++) {
  1221. switch (wVariation) {
  1222. case 0:
  1223. /* 1 Pixel Wide */
  1224. desiredW = 1;
  1225. break;
  1226. case 1:
  1227. /* Random width inside screen */
  1228. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1229. break;
  1230. case 2:
  1231. /* Width at screen size */
  1232. desiredW = display.w;
  1233. break;
  1234. }
  1235. switch (hVariation) {
  1236. case 0:
  1237. /* 1 Pixel High */
  1238. desiredH = 1;
  1239. break;
  1240. case 1:
  1241. /* Random height inside screen */
  1242. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1243. break;
  1244. case 2:
  1245. /* Height at screen size */
  1246. desiredH = display.h;
  1247. break;
  1248. }
  1249. /* Set size */
  1250. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1251. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1252. /* Get size */
  1253. currentW = desiredW + 1;
  1254. currentH = desiredH + 1;
  1255. SDL_GetWindowMaximumSize(window, &currentW, &currentH);
  1256. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
  1257. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1258. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1259. /* Get just width */
  1260. currentW = desiredW + 1;
  1261. SDL_GetWindowMaximumSize(window, &currentW, NULL);
  1262. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
  1263. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1264. /* Get just height */
  1265. currentH = desiredH + 1;
  1266. SDL_GetWindowMaximumSize(window, NULL, &currentH);
  1267. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
  1268. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1269. }
  1270. }
  1271. /* Dummy call with both pointers NULL */
  1272. SDL_GetWindowMaximumSize(window, NULL, NULL);
  1273. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
  1274. /* Negative tests for parameter input */
  1275. SDL_ClearError();
  1276. SDLTest_AssertPass("Call to SDL_ClearError()");
  1277. for (desiredH = -2; desiredH < 2; desiredH++) {
  1278. for (desiredW = -2; desiredW < 2; desiredW++) {
  1279. if (desiredW < 0 || desiredH < 0) {
  1280. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1281. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1282. checkInvalidParameterError();
  1283. }
  1284. }
  1285. }
  1286. /* Clean up */
  1287. destroyVideoSuiteTestWindow(window);
  1288. /* Set some 'magic' value for later check that nothing was changed */
  1289. referenceW = SDLTest_RandomSint32();
  1290. referenceH = SDLTest_RandomSint32();
  1291. currentW = referenceW;
  1292. currentH = referenceH;
  1293. desiredW = SDLTest_RandomSint32();
  1294. desiredH = SDLTest_RandomSint32();
  1295. /* Negative tests */
  1296. SDL_ClearError();
  1297. SDLTest_AssertPass("Call to SDL_ClearError()");
  1298. SDL_GetWindowMaximumSize(NULL, &currentW, &currentH);
  1299. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
  1300. SDLTest_AssertCheck(
  1301. currentW == referenceW && currentH == referenceH,
  1302. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1303. referenceW, referenceH,
  1304. currentW, currentH);
  1305. checkInvalidWindowError();
  1306. SDL_GetWindowMaximumSize(NULL, NULL, NULL);
  1307. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
  1308. checkInvalidWindowError();
  1309. SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
  1310. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
  1311. checkInvalidWindowError();
  1312. return TEST_COMPLETED;
  1313. }
  1314. /**
  1315. * Tests call to SDL_SetWindowData and SDL_GetWindowData
  1316. *
  1317. * \sa SDL_SetWindowData
  1318. * \sa SDL_GetWindowData
  1319. */
  1320. static int video_getSetWindowData(void *arg)
  1321. {
  1322. int returnValue = TEST_COMPLETED;
  1323. const char *title = "video_setGetWindowData Test Window";
  1324. SDL_Window *window;
  1325. const char *referenceName = "TestName";
  1326. const char *name = "TestName";
  1327. const char *referenceName2 = "TestName2";
  1328. const char *name2 = "TestName2";
  1329. int datasize;
  1330. char *referenceUserdata = NULL;
  1331. char *userdata = NULL;
  1332. char *referenceUserdata2 = NULL;
  1333. char *userdata2 = NULL;
  1334. char *result;
  1335. int iteration;
  1336. /* Call against new test window */
  1337. window = createVideoSuiteTestWindow(title);
  1338. if (!window) {
  1339. return TEST_ABORTED;
  1340. }
  1341. /* Create testdata */
  1342. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1343. referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
  1344. if (!referenceUserdata) {
  1345. returnValue = TEST_ABORTED;
  1346. goto cleanup;
  1347. }
  1348. userdata = SDL_strdup(referenceUserdata);
  1349. if (!userdata) {
  1350. returnValue = TEST_ABORTED;
  1351. goto cleanup;
  1352. }
  1353. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1354. referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
  1355. if (!referenceUserdata2) {
  1356. returnValue = TEST_ABORTED;
  1357. goto cleanup;
  1358. }
  1359. userdata2 = SDL_strdup(referenceUserdata2);
  1360. if (!userdata2) {
  1361. returnValue = TEST_ABORTED;
  1362. goto cleanup;
  1363. }
  1364. /* Get non-existent data */
  1365. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
  1366. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1367. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1368. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1369. /* Set data */
  1370. SDL_SetProperty(SDL_GetWindowProperties(window), name, userdata);
  1371. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
  1372. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1373. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1374. /* Get data (twice) */
  1375. for (iteration = 1; iteration <= 2; iteration++) {
  1376. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
  1377. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
  1378. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1379. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1380. }
  1381. /* Set data again twice */
  1382. for (iteration = 1; iteration <= 2; iteration++) {
  1383. SDL_SetProperty(SDL_GetWindowProperties(window), name, userdata);
  1384. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
  1385. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1386. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1387. }
  1388. /* Get data again */
  1389. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
  1390. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
  1391. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1392. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1393. /* Set data with new data */
  1394. SDL_SetProperty(SDL_GetWindowProperties(window), name, userdata2);
  1395. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
  1396. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1397. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1398. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1399. /* Set data with new data again */
  1400. SDL_SetProperty(SDL_GetWindowProperties(window), name, userdata2);
  1401. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
  1402. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1403. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1404. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1405. /* Get new data */
  1406. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
  1407. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1408. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1409. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1410. /* Set data with NULL to clear */
  1411. SDL_SetProperty(SDL_GetWindowProperties(window), name, NULL);
  1412. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
  1413. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1414. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1415. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1416. /* Set data with NULL to clear again */
  1417. SDL_SetProperty(SDL_GetWindowProperties(window), name, NULL);
  1418. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
  1419. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1420. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1421. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1422. /* Get non-existent data */
  1423. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
  1424. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1425. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1426. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1427. /* Get non-existent data new name */
  1428. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name2, NULL);
  1429. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
  1430. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1431. SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
  1432. /* Set data (again) */
  1433. SDL_SetProperty(SDL_GetWindowProperties(window), name, userdata);
  1434. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
  1435. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1436. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1437. /* Get data (again) */
  1438. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), name, NULL);
  1439. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
  1440. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1441. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1442. /* Set data with NULL name, valid userdata */
  1443. SDL_SetProperty(SDL_GetWindowProperties(window), NULL, userdata);
  1444. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
  1445. checkInvalidParameterError();
  1446. /* Set data with empty name, valid userdata */
  1447. SDL_SetProperty(SDL_GetWindowProperties(window), "", userdata);
  1448. SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
  1449. checkInvalidParameterError();
  1450. /* Set data with NULL name, NULL userdata */
  1451. SDL_SetProperty(SDL_GetWindowProperties(window), NULL, NULL);
  1452. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
  1453. checkInvalidParameterError();
  1454. /* Set data with empty name, NULL userdata */
  1455. SDL_SetProperty(SDL_GetWindowProperties(window), "", NULL);
  1456. SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
  1457. checkInvalidParameterError();
  1458. /* Get data with NULL name */
  1459. result = (char *)SDL_GetProperty(SDL_GetWindowProperties(window), NULL, NULL);
  1460. SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
  1461. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1462. checkInvalidParameterError();
  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. checkInvalidParameterError();
  1468. /* Clean up */
  1469. destroyVideoSuiteTestWindow(window);
  1470. cleanup:
  1471. SDL_free(referenceUserdata);
  1472. SDL_free(referenceUserdata2);
  1473. SDL_free(userdata);
  1474. SDL_free(userdata2);
  1475. return returnValue;
  1476. }
  1477. /**
  1478. * Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN.
  1479. *
  1480. * Especially useful when run on a multi-monitor system with different DPI scales per monitor,
  1481. * to test that the window size is maintained when moving between monitors.
  1482. *
  1483. * As the Wayland windowing protocol does not allow application windows to control their position in the
  1484. * desktop space, coupled with the general asynchronous nature of Wayland compositors, the positioning
  1485. * tests don't work in windowed mode and are unreliable in fullscreen mode, thus are disabled when using
  1486. * the Wayland video driver. All that can be done is check that the windows are the expected size.
  1487. */
  1488. static int video_setWindowCenteredOnDisplay(void *arg)
  1489. {
  1490. SDL_DisplayID *displays;
  1491. SDL_Window *window;
  1492. const char *title = "video_setWindowCenteredOnDisplay Test Window";
  1493. int x, y, w, h;
  1494. int xVariation, yVariation;
  1495. int displayNum;
  1496. int result;
  1497. SDL_Rect display0, display1;
  1498. SDL_bool video_driver_is_wayland = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0;
  1499. displays = SDL_GetDisplays(&displayNum);
  1500. if (displays) {
  1501. /* Get display bounds */
  1502. result = SDL_GetDisplayBounds(displays[0 % displayNum], &display0);
  1503. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1504. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1505. if (result != 0) {
  1506. return TEST_ABORTED;
  1507. }
  1508. result = SDL_GetDisplayBounds(displays[1 % displayNum], &display1);
  1509. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1510. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1511. if (result != 0) {
  1512. return TEST_ABORTED;
  1513. }
  1514. for (xVariation = 0; xVariation < 2; xVariation++) {
  1515. for (yVariation = 0; yVariation < 2; yVariation++) {
  1516. int currentX = 0, currentY = 0;
  1517. int currentW = 0, currentH = 0;
  1518. int expectedX = 0, expectedY = 0;
  1519. int currentDisplay;
  1520. int expectedDisplay;
  1521. SDL_Rect expectedDisplayRect, expectedFullscreenRect;
  1522. SDL_PropertiesID props;
  1523. /* xVariation is the display we start on */
  1524. expectedDisplay = displays[xVariation % displayNum];
  1525. x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1526. y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
  1527. w = SDLTest_RandomIntegerInRange(640, 800);
  1528. h = SDLTest_RandomIntegerInRange(400, 600);
  1529. expectedDisplayRect = (xVariation == 0) ? display0 : display1;
  1530. expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
  1531. expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
  1532. props = SDL_CreateProperties();
  1533. SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, title);
  1534. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, x);
  1535. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, y);
  1536. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, w);
  1537. SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h);
  1538. SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN, SDL_TRUE);
  1539. window = SDL_CreateWindowWithProperties(props);
  1540. SDL_DestroyProperties(props);
  1541. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
  1542. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  1543. /* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */
  1544. if (video_driver_is_wayland) {
  1545. SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL, 0);
  1546. if (renderer) {
  1547. SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
  1548. SDL_RenderClear(renderer);
  1549. SDL_RenderPresent(renderer);
  1550. /* Some desktops don't display the window immediately after presentation,
  1551. * so delay to give the window time to actually appear on the desktop.
  1552. */
  1553. SDL_Delay(100);
  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. Uint32 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. Uint32 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. };