testautomation_video.c 107 KB

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