testautomation_video.c 91 KB

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