testautomation_video.c 83 KB

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