testautomation_video.c 109 KB

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