testautomation_video.c 100 KB

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