testautomation_video.c 100 KB

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