testautomation_video.c 110 KB

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