testautomation_video.c 77 KB

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