testautomation_video.c 105 KB

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