testautomation_video.c 105 KB

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