testautomation_video.c 96 KB

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