testautomation_video.c 96 KB

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