testautomation_video.c 109 KB

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