testautomation_video.c 64 KB

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