testautomation_video.c 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940
  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 < 14; 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_MOUSE_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. case 13:
  279. flags = SDL_WINDOW_KEYBOARD_GRABBED;
  280. break;
  281. }
  282. window = SDL_CreateWindow(title, x, y, w, h, flags);
  283. SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
  284. SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
  285. /* Clean up */
  286. _destroyVideoSuiteTestWindow(window);
  287. }
  288. return TEST_COMPLETED;
  289. }
  290. /**
  291. * @brief Tests the functionality of the SDL_GetWindowFlags function
  292. */
  293. int
  294. video_getWindowFlags(void *arg)
  295. {
  296. SDL_Window* window;
  297. const char* title = "video_getWindowFlags Test Window";
  298. SDL_WindowFlags flags;
  299. Uint32 actualFlags;
  300. /* Reliable flag set always set in test window */
  301. flags = SDL_WINDOW_SHOWN;
  302. /* Call against new test window */
  303. window = _createVideoSuiteTestWindow(title);
  304. if (window != NULL) {
  305. actualFlags = SDL_GetWindowFlags(window);
  306. SDLTest_AssertPass("Call to SDL_GetWindowFlags()");
  307. SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
  308. }
  309. /* Clean up */
  310. _destroyVideoSuiteTestWindow(window);
  311. return TEST_COMPLETED;
  312. }
  313. /**
  314. * @brief Tests the functionality of the SDL_GetNumDisplayModes function
  315. */
  316. int
  317. video_getNumDisplayModes(void *arg)
  318. {
  319. int result;
  320. int displayNum;
  321. int i;
  322. /* Get number of displays */
  323. displayNum = SDL_GetNumVideoDisplays();
  324. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  325. /* Make call for each display */
  326. for (i=0; i<displayNum; i++) {
  327. result = SDL_GetNumDisplayModes(i);
  328. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
  329. SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
  330. }
  331. return TEST_COMPLETED;
  332. }
  333. /**
  334. * @brief Tests negative call to SDL_GetNumDisplayModes function
  335. */
  336. int
  337. video_getNumDisplayModesNegative(void *arg)
  338. {
  339. int result;
  340. int displayNum;
  341. int displayIndex;
  342. /* Get number of displays */
  343. displayNum = SDL_GetNumVideoDisplays();
  344. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  345. /* Invalid boundary values */
  346. displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
  347. result = SDL_GetNumDisplayModes(displayIndex);
  348. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
  349. SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
  350. /* Large (out-of-bounds) display index */
  351. displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
  352. result = SDL_GetNumDisplayModes(displayIndex);
  353. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
  354. SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
  355. displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
  356. result = SDL_GetNumDisplayModes(displayIndex);
  357. SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
  358. SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
  359. return TEST_COMPLETED;
  360. }
  361. /**
  362. * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
  363. */
  364. int
  365. video_getClosestDisplayModeCurrentResolution(void *arg)
  366. {
  367. int result;
  368. SDL_DisplayMode current;
  369. SDL_DisplayMode target;
  370. SDL_DisplayMode closest;
  371. SDL_DisplayMode* dResult;
  372. int displayNum;
  373. int i;
  374. int variation;
  375. /* Get number of displays */
  376. displayNum = SDL_GetNumVideoDisplays();
  377. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  378. /* Make calls for each display */
  379. for (i=0; i<displayNum; i++) {
  380. SDLTest_Log("Testing against display: %d", i);
  381. /* Get first display mode to get a sane resolution; this should always work */
  382. result = SDL_GetDisplayMode(i, 0, &current);
  383. SDLTest_AssertPass("Call to SDL_GetDisplayMode()");
  384. SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
  385. if (result != 0) {
  386. return TEST_ABORTED;
  387. }
  388. /* Set the desired resolution equals to current resolution */
  389. target.w = current.w;
  390. target.h = current.h;
  391. for (variation = 0; variation < 8; variation ++) {
  392. /* Vary constraints on other query parameters */
  393. target.format = (variation & 1) ? current.format : 0;
  394. target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
  395. target.driverdata = (variation & 4) ? current.driverdata : 0;
  396. /* Make call */
  397. dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
  398. SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
  399. SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL");
  400. /* Check that one gets the current resolution back again */
  401. SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
  402. SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
  403. SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
  404. SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
  405. }
  406. }
  407. return TEST_COMPLETED;
  408. }
  409. /**
  410. * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
  411. */
  412. int
  413. video_getClosestDisplayModeRandomResolution(void *arg)
  414. {
  415. SDL_DisplayMode target;
  416. SDL_DisplayMode closest;
  417. SDL_DisplayMode* dResult;
  418. int displayNum;
  419. int i;
  420. int variation;
  421. /* Get number of displays */
  422. displayNum = SDL_GetNumVideoDisplays();
  423. SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()");
  424. /* Make calls for each display */
  425. for (i=0; i<displayNum; i++) {
  426. SDLTest_Log("Testing against display: %d", i);
  427. for (variation = 0; variation < 16; variation ++) {
  428. /* Set random constraints */
  429. target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  430. target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
  431. target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
  432. target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
  433. target.driverdata = 0;
  434. /* Make call; may or may not find anything, so don't validate any further */
  435. dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
  436. SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
  437. }
  438. }
  439. return TEST_COMPLETED;
  440. }
  441. /**
  442. * @brief Tests call to SDL_GetWindowBrightness
  443. *
  444. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowBrightness
  445. */
  446. int
  447. video_getWindowBrightness(void *arg)
  448. {
  449. SDL_Window* window;
  450. const char* title = "video_getWindowBrightness Test Window";
  451. float result;
  452. /* Call against new test window */
  453. window = _createVideoSuiteTestWindow(title);
  454. if (window != NULL) {
  455. result = SDL_GetWindowBrightness(window);
  456. SDLTest_AssertPass("Call to SDL_GetWindowBrightness()");
  457. SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
  458. }
  459. /* Clean up */
  460. _destroyVideoSuiteTestWindow(window);
  461. return TEST_COMPLETED;
  462. }
  463. /**
  464. * @brief Tests call to SDL_GetWindowBrightness with invalid input
  465. *
  466. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowBrightness
  467. */
  468. int
  469. video_getWindowBrightnessNegative(void *arg)
  470. {
  471. const char *invalidWindowError = "Invalid window";
  472. char *lastError;
  473. float result;
  474. /* Call against invalid window */
  475. result = SDL_GetWindowBrightness(NULL);
  476. SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)");
  477. SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result);
  478. lastError = (char *)SDL_GetError();
  479. SDLTest_AssertPass("SDL_GetError()");
  480. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  481. if (lastError != NULL) {
  482. SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
  483. "SDL_GetError(): expected message '%s', was message: '%s'",
  484. invalidWindowError,
  485. lastError);
  486. }
  487. return TEST_COMPLETED;
  488. }
  489. /**
  490. * @brief Tests call to SDL_GetWindowDisplayMode
  491. *
  492. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowDisplayMode
  493. */
  494. int
  495. video_getWindowDisplayMode(void *arg)
  496. {
  497. SDL_Window* window;
  498. const char* title = "video_getWindowDisplayMode Test Window";
  499. SDL_DisplayMode mode;
  500. int result;
  501. /* Invalidate part of the mode content so we can check values later */
  502. mode.w = -1;
  503. mode.h = -1;
  504. mode.refresh_rate = -1;
  505. /* Call against new test window */
  506. window = _createVideoSuiteTestWindow(title);
  507. if (window != NULL) {
  508. result = SDL_GetWindowDisplayMode(window, &mode);
  509. SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()");
  510. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  511. SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w);
  512. SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h);
  513. SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate);
  514. }
  515. /* Clean up */
  516. _destroyVideoSuiteTestWindow(window);
  517. return TEST_COMPLETED;
  518. }
  519. /* Helper function that checks for an 'Invalid window' error */
  520. void _checkInvalidWindowError()
  521. {
  522. const char *invalidWindowError = "Invalid window";
  523. char *lastError;
  524. lastError = (char *)SDL_GetError();
  525. SDLTest_AssertPass("SDL_GetError()");
  526. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  527. if (lastError != NULL) {
  528. SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
  529. "SDL_GetError(): expected message '%s', was message: '%s'",
  530. invalidWindowError,
  531. lastError);
  532. SDL_ClearError();
  533. SDLTest_AssertPass("Call to SDL_ClearError()");
  534. }
  535. }
  536. /**
  537. * @brief Tests call to SDL_GetWindowDisplayMode with invalid input
  538. *
  539. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowDisplayMode
  540. */
  541. int
  542. video_getWindowDisplayModeNegative(void *arg)
  543. {
  544. const char *expectedError = "Parameter 'mode' is invalid";
  545. char *lastError;
  546. SDL_Window* window;
  547. const char* title = "video_getWindowDisplayModeNegative Test Window";
  548. SDL_DisplayMode mode;
  549. int result;
  550. /* Call against new test window */
  551. window = _createVideoSuiteTestWindow(title);
  552. if (window != NULL) {
  553. result = SDL_GetWindowDisplayMode(window, NULL);
  554. SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)");
  555. SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
  556. lastError = (char *)SDL_GetError();
  557. SDLTest_AssertPass("SDL_GetError()");
  558. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  559. if (lastError != NULL) {
  560. SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0,
  561. "SDL_GetError(): expected message '%s', was message: '%s'",
  562. expectedError,
  563. lastError);
  564. }
  565. }
  566. /* Clean up */
  567. _destroyVideoSuiteTestWindow(window);
  568. /* Call against invalid window */
  569. result = SDL_GetWindowDisplayMode(NULL, &mode);
  570. SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)");
  571. SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
  572. _checkInvalidWindowError();
  573. return TEST_COMPLETED;
  574. }
  575. /**
  576. * @brief Tests call to SDL_GetWindowGammaRamp
  577. *
  578. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowGammaRamp
  579. */
  580. int
  581. video_getWindowGammaRamp(void *arg)
  582. {
  583. SDL_Window* window;
  584. const char* title = "video_getWindowGammaRamp Test Window";
  585. Uint16 red[256];
  586. Uint16 green[256];
  587. Uint16 blue[256];
  588. int result;
  589. /* Call against new test window */
  590. window = _createVideoSuiteTestWindow(title);
  591. if (window == NULL) return TEST_ABORTED;
  592. /* Retrieve no channel */
  593. result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL);
  594. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)");
  595. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  596. /* Retrieve single channel */
  597. result = SDL_GetWindowGammaRamp(window, red, NULL, NULL);
  598. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)");
  599. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  600. result = SDL_GetWindowGammaRamp(window, NULL, green, NULL);
  601. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)");
  602. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  603. result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue);
  604. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)");
  605. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  606. /* Retrieve two channels */
  607. result = SDL_GetWindowGammaRamp(window, red, green, NULL);
  608. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)");
  609. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  610. result = SDL_GetWindowGammaRamp(window, NULL, green, blue);
  611. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)");
  612. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  613. result = SDL_GetWindowGammaRamp(window, red, NULL, blue);
  614. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)");
  615. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  616. /* Retrieve all channels */
  617. result = SDL_GetWindowGammaRamp(window, red, green, blue);
  618. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)");
  619. SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
  620. /* Clean up */
  621. _destroyVideoSuiteTestWindow(window);
  622. return TEST_COMPLETED;
  623. }
  624. /**
  625. * @brief Tests call to SDL_GetWindowGammaRamp with invalid input
  626. *
  627. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowGammaRamp
  628. */
  629. int
  630. video_getWindowGammaRampNegative(void *arg)
  631. {
  632. Uint16 red[256];
  633. Uint16 green[256];
  634. Uint16 blue[256];
  635. int result;
  636. SDL_ClearError();
  637. SDLTest_AssertPass("Call to SDL_ClearError()");
  638. /* Call against invalid window */
  639. result = SDL_GetWindowGammaRamp(NULL, red, green, blue);
  640. SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)");
  641. SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %i", result);
  642. _checkInvalidWindowError();
  643. return TEST_COMPLETED;
  644. }
  645. /* Helper for setting and checking the window mouse grab state */
  646. void
  647. _setAndCheckWindowMouseGrabState(SDL_Window* window, SDL_bool desiredState)
  648. {
  649. SDL_bool currentState;
  650. /* Set state */
  651. SDL_SetWindowMouseGrab(window, desiredState);
  652. SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  653. /* Get and check state */
  654. currentState = SDL_GetWindowMouseGrab(window);
  655. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  656. SDLTest_AssertCheck(
  657. currentState == desiredState,
  658. "Validate returned state; expected: %s, got: %s",
  659. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  660. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  661. if (desiredState) {
  662. SDLTest_AssertCheck(
  663. SDL_GetGrabbedWindow() == window,
  664. "Grabbed window should be to our window");
  665. SDLTest_AssertCheck(
  666. SDL_GetWindowGrab(window),
  667. "SDL_GetWindowGrab() should return SDL_TRUE");
  668. SDLTest_AssertCheck(
  669. SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED,
  670. "SDL_WINDOW_MOUSE_GRABBED should be set");
  671. } else {
  672. SDLTest_AssertCheck(
  673. !(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED),
  674. "SDL_WINDOW_MOUSE_GRABBED should be unset");
  675. }
  676. }
  677. /* Helper for setting and checking the window keyboard grab state */
  678. void
  679. _setAndCheckWindowKeyboardGrabState(SDL_Window* window, SDL_bool desiredState)
  680. {
  681. SDL_bool currentState;
  682. /* Set state */
  683. SDL_SetWindowKeyboardGrab(window, desiredState);
  684. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  685. /* Get and check state */
  686. currentState = SDL_GetWindowKeyboardGrab(window);
  687. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  688. SDLTest_AssertCheck(
  689. currentState == desiredState,
  690. "Validate returned state; expected: %s, got: %s",
  691. (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
  692. (currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
  693. if (desiredState) {
  694. SDLTest_AssertCheck(
  695. SDL_GetGrabbedWindow() == window,
  696. "Grabbed window should be set to our window");
  697. SDLTest_AssertCheck(
  698. SDL_GetWindowGrab(window),
  699. "SDL_GetWindowGrab() should return SDL_TRUE");
  700. SDLTest_AssertCheck(
  701. SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED,
  702. "SDL_WINDOW_KEYBOARD_GRABBED should be set");
  703. } else {
  704. SDLTest_AssertCheck(
  705. !(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED),
  706. "SDL_WINDOW_KEYBOARD_GRABBED should be unset");
  707. }
  708. }
  709. /**
  710. * @brief Tests keyboard and mouse grab support
  711. *
  712. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowGrab
  713. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_SetWindowGrab
  714. */
  715. int
  716. video_getSetWindowGrab(void *arg)
  717. {
  718. const char* title = "video_getSetWindowGrab Test Window";
  719. SDL_Window* window;
  720. SDL_bool originalMouseState, originalKeyboardState, dummyState;
  721. /* Call against new test window */
  722. window = _createVideoSuiteTestWindow(title);
  723. if (window == NULL) return TEST_ABORTED;
  724. /* Get state */
  725. originalMouseState = SDL_GetWindowMouseGrab(window);
  726. SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
  727. originalKeyboardState = SDL_GetWindowKeyboardGrab(window);
  728. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
  729. /* F */
  730. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  731. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  732. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  733. "SDL_GetWindowGrab should return SDL_FALSE");
  734. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  735. "Expected NULL grabbed window");
  736. /* F --> F */
  737. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  738. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  739. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  740. "Expected NULL grabbed window");
  741. /* F --> T */
  742. _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  743. _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  744. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  745. "SDL_GetWindowGrab() should return SDL_TRUE");
  746. /* T --> T */
  747. _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  748. _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  749. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  750. "SDL_GetWindowGrab() should return SDL_TRUE");
  751. /* M: T --> F */
  752. /* K: T --> T */
  753. _setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
  754. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  755. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  756. "SDL_GetWindowGrab() should return SDL_TRUE");
  757. /* M: F --> T */
  758. /* K: T --> F */
  759. _setAndCheckWindowMouseGrabState(window, SDL_TRUE);
  760. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  761. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  762. "SDL_GetWindowGrab() should return SDL_TRUE");
  763. /* M: T --> F */
  764. /* K: F --> F */
  765. _setAndCheckWindowMouseGrabState(window, SDL_FALSE);
  766. _setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
  767. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  768. "SDL_GetWindowGrab() should return SDL_FALSE");
  769. SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
  770. "Expected NULL grabbed window");
  771. /* Using the older SDL_SetWindowGrab API should only grab mouse by default */
  772. SDL_SetWindowGrab(window, SDL_TRUE);
  773. SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
  774. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  775. "SDL_GetWindowGrab() should return SDL_TRUE");
  776. SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
  777. "SDL_GetWindowMouseGrab() should return SDL_TRUE");
  778. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  779. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  780. SDL_SetWindowGrab(window, SDL_FALSE);
  781. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  782. "SDL_GetWindowGrab() should return SDL_FALSE");
  783. SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
  784. "SDL_GetWindowMouseGrab() should return SDL_FALSE");
  785. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  786. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  787. /* Now test with SDL_HINT_GRAB_KEYBOARD set. We should get keyboard grab now. */
  788. SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
  789. SDL_SetWindowGrab(window, SDL_TRUE);
  790. SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
  791. SDLTest_AssertCheck(SDL_GetWindowGrab(window),
  792. "SDL_GetWindowGrab() should return SDL_TRUE");
  793. SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
  794. "SDL_GetWindowMouseGrab() should return SDL_TRUE");
  795. SDLTest_AssertCheck(SDL_GetWindowKeyboardGrab(window),
  796. "SDL_GetWindowKeyboardGrab() should return SDL_TRUE");
  797. SDL_SetWindowGrab(window, SDL_FALSE);
  798. SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
  799. "SDL_GetWindowGrab() should return SDL_FALSE");
  800. SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
  801. "SDL_GetWindowMouseGrab() should return SDL_FALSE");
  802. SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
  803. "SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
  804. /* Negative tests */
  805. dummyState = SDL_GetWindowGrab(NULL);
  806. SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
  807. _checkInvalidWindowError();
  808. dummyState = SDL_GetWindowKeyboardGrab(NULL);
  809. SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)");
  810. _checkInvalidWindowError();
  811. SDL_SetWindowGrab(NULL, SDL_FALSE);
  812. SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
  813. _checkInvalidWindowError();
  814. SDL_SetWindowKeyboardGrab(NULL, SDL_FALSE);
  815. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE)");
  816. _checkInvalidWindowError();
  817. SDL_SetWindowGrab(NULL, SDL_TRUE);
  818. SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_TRUE)");
  819. _checkInvalidWindowError();
  820. SDL_SetWindowKeyboardGrab(NULL, SDL_TRUE);
  821. SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE)");
  822. _checkInvalidWindowError();
  823. /* Restore state */
  824. _setAndCheckWindowMouseGrabState(window, originalMouseState);
  825. _setAndCheckWindowKeyboardGrabState(window, originalKeyboardState);
  826. /* Clean up */
  827. _destroyVideoSuiteTestWindow(window);
  828. return TEST_COMPLETED;
  829. }
  830. /**
  831. * @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID
  832. *
  833. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowID
  834. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_SetWindowFromID
  835. */
  836. int
  837. video_getWindowId(void *arg)
  838. {
  839. const char* title = "video_getWindowId Test Window";
  840. SDL_Window* window;
  841. SDL_Window* result;
  842. Uint32 id, randomId;
  843. /* Call against new test window */
  844. window = _createVideoSuiteTestWindow(title);
  845. if (window == NULL) return TEST_ABORTED;
  846. /* Get ID */
  847. id = SDL_GetWindowID(window);
  848. SDLTest_AssertPass("Call to SDL_GetWindowID()");
  849. /* Get window from ID */
  850. result = SDL_GetWindowFromID(id);
  851. SDLTest_AssertPass("Call to SDL_GetWindowID(%d)", id);
  852. SDLTest_AssertCheck(result == window, "Verify result matches window pointer");
  853. /* Get window from random large ID, no result check */
  854. randomId = SDLTest_RandomIntegerInRange(UINT8_MAX,UINT16_MAX);
  855. result = SDL_GetWindowFromID(randomId);
  856. SDLTest_AssertPass("Call to SDL_GetWindowID(%d/random_large)", randomId);
  857. /* Get window from 0 and Uint32 max ID, no result check */
  858. result = SDL_GetWindowFromID(0);
  859. SDLTest_AssertPass("Call to SDL_GetWindowID(0)");
  860. result = SDL_GetWindowFromID(UINT32_MAX);
  861. SDLTest_AssertPass("Call to SDL_GetWindowID(UINT32_MAX)");
  862. /* Clean up */
  863. _destroyVideoSuiteTestWindow(window);
  864. /* Get window from ID for closed window */
  865. result = SDL_GetWindowFromID(id);
  866. SDLTest_AssertPass("Call to SDL_GetWindowID(%d/closed_window)", id);
  867. SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
  868. /* Negative test */
  869. SDL_ClearError();
  870. SDLTest_AssertPass("Call to SDL_ClearError()");
  871. id = SDL_GetWindowID(NULL);
  872. SDLTest_AssertPass("Call to SDL_GetWindowID(window=NULL)");
  873. _checkInvalidWindowError();
  874. return TEST_COMPLETED;
  875. }
  876. /**
  877. * @brief Tests call to SDL_GetWindowPixelFormat
  878. *
  879. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowPixelFormat
  880. */
  881. int
  882. video_getWindowPixelFormat(void *arg)
  883. {
  884. const char* title = "video_getWindowPixelFormat Test Window";
  885. SDL_Window* window;
  886. Uint32 format;
  887. /* Call against new test window */
  888. window = _createVideoSuiteTestWindow(title);
  889. if (window == NULL) return TEST_ABORTED;
  890. /* Get format */
  891. format = SDL_GetWindowPixelFormat(window);
  892. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat()");
  893. SDLTest_AssertCheck(format != SDL_PIXELFORMAT_UNKNOWN, "Verify that returned format is valid; expected: != %d, got: %d", SDL_PIXELFORMAT_UNKNOWN, format);
  894. /* Clean up */
  895. _destroyVideoSuiteTestWindow(window);
  896. /* Negative test */
  897. SDL_ClearError();
  898. SDLTest_AssertPass("Call to SDL_ClearError()");
  899. format = SDL_GetWindowPixelFormat(NULL);
  900. SDLTest_AssertPass("Call to SDL_GetWindowPixelFormat(window=NULL)");
  901. _checkInvalidWindowError();
  902. return TEST_COMPLETED;
  903. }
  904. /**
  905. * @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
  906. *
  907. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowPosition
  908. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_SetWindowPosition
  909. */
  910. int
  911. video_getSetWindowPosition(void *arg)
  912. {
  913. const char* title = "video_getSetWindowPosition Test Window";
  914. SDL_Window* window;
  915. int xVariation, yVariation;
  916. int referenceX, referenceY;
  917. int currentX, currentY;
  918. int desiredX, desiredY;
  919. /* Call against new test window */
  920. window = _createVideoSuiteTestWindow(title);
  921. if (window == NULL) return TEST_ABORTED;
  922. for (xVariation = 0; xVariation < 4; xVariation++) {
  923. for (yVariation = 0; yVariation < 4; yVariation++) {
  924. switch(xVariation) {
  925. case 0:
  926. /* Zero X Position */
  927. desiredX = 0;
  928. break;
  929. case 1:
  930. /* Random X position inside screen */
  931. desiredX = SDLTest_RandomIntegerInRange(1, 100);
  932. break;
  933. case 2:
  934. /* Random X position outside screen (positive) */
  935. desiredX = SDLTest_RandomIntegerInRange(10000, 11000);
  936. break;
  937. case 3:
  938. /* Random X position outside screen (negative) */
  939. desiredX = SDLTest_RandomIntegerInRange(-1000, -100);
  940. break;
  941. }
  942. switch(yVariation) {
  943. case 0:
  944. /* Zero X Position */
  945. desiredY = 0;
  946. break;
  947. case 1:
  948. /* Random X position inside screen */
  949. desiredY = SDLTest_RandomIntegerInRange(1, 100);
  950. break;
  951. case 2:
  952. /* Random X position outside screen (positive) */
  953. desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
  954. break;
  955. case 3:
  956. /* Random Y position outside screen (negative) */
  957. desiredY = SDLTest_RandomIntegerInRange(-1000, -100);
  958. break;
  959. }
  960. /* Set position */
  961. SDL_SetWindowPosition(window, desiredX, desiredY);
  962. SDLTest_AssertPass("Call to SDL_SetWindowPosition(...,%d,%d)", desiredX, desiredY);
  963. /* Get position */
  964. currentX = desiredX + 1;
  965. currentY = desiredY + 1;
  966. SDL_GetWindowPosition(window, &currentX, &currentY);
  967. SDLTest_AssertPass("Call to SDL_GetWindowPosition()");
  968. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  969. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  970. /* Get position X */
  971. currentX = desiredX + 1;
  972. SDL_GetWindowPosition(window, &currentX, NULL);
  973. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&y=NULL)");
  974. SDLTest_AssertCheck(desiredX == currentX, "Verify returned X position; expected: %d, got: %d", desiredX, currentX);
  975. /* Get position Y */
  976. currentY = desiredY + 1;
  977. SDL_GetWindowPosition(window, NULL, &currentY);
  978. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL)");
  979. SDLTest_AssertCheck(desiredY == currentY, "Verify returned Y position; expected: %d, got: %d", desiredY, currentY);
  980. }
  981. }
  982. /* Dummy call with both pointers NULL */
  983. SDL_GetWindowPosition(window, NULL, NULL);
  984. SDLTest_AssertPass("Call to SDL_GetWindowPosition(&x=NULL,&y=NULL)");
  985. /* Clean up */
  986. _destroyVideoSuiteTestWindow(window);
  987. /* Set some 'magic' value for later check that nothing was changed */
  988. referenceX = SDLTest_RandomSint32();
  989. referenceY = SDLTest_RandomSint32();
  990. currentX = referenceX;
  991. currentY = referenceY;
  992. desiredX = SDLTest_RandomSint32();
  993. desiredY = SDLTest_RandomSint32();
  994. /* Negative tests */
  995. SDL_ClearError();
  996. SDLTest_AssertPass("Call to SDL_ClearError()");
  997. SDL_GetWindowPosition(NULL, &currentX, &currentY);
  998. SDLTest_AssertPass("Call to SDL_GetWindowPosition(window=NULL)");
  999. SDLTest_AssertCheck(
  1000. currentX == referenceX && currentY == referenceY,
  1001. "Verify that content of X and Y pointers has not been modified; expected: %d,%d; got: %d,%d",
  1002. referenceX, referenceY,
  1003. currentX, currentY);
  1004. _checkInvalidWindowError();
  1005. SDL_GetWindowPosition(NULL, NULL, NULL);
  1006. SDLTest_AssertPass("Call to SDL_GetWindowPosition(NULL, NULL, NULL)");
  1007. _checkInvalidWindowError();
  1008. SDL_SetWindowPosition(NULL, desiredX, desiredY);
  1009. SDLTest_AssertPass("Call to SDL_SetWindowPosition(window=NULL)");
  1010. _checkInvalidWindowError();
  1011. return TEST_COMPLETED;
  1012. }
  1013. /* Helper function that checks for an 'Invalid parameter' error */
  1014. void _checkInvalidParameterError()
  1015. {
  1016. const char *invalidParameterError = "Parameter";
  1017. char *lastError;
  1018. lastError = (char *)SDL_GetError();
  1019. SDLTest_AssertPass("SDL_GetError()");
  1020. SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
  1021. if (lastError != NULL) {
  1022. SDLTest_AssertCheck(SDL_strncmp(lastError, invalidParameterError, SDL_strlen(invalidParameterError)) == 0,
  1023. "SDL_GetError(): expected message starts with '%s', was message: '%s'",
  1024. invalidParameterError,
  1025. lastError);
  1026. SDL_ClearError();
  1027. SDLTest_AssertPass("Call to SDL_ClearError()");
  1028. }
  1029. }
  1030. /**
  1031. * @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize
  1032. *
  1033. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowSize
  1034. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_SetWindowSize
  1035. */
  1036. int
  1037. video_getSetWindowSize(void *arg)
  1038. {
  1039. const char* title = "video_getSetWindowSize Test Window";
  1040. SDL_Window* window;
  1041. int result;
  1042. SDL_Rect display;
  1043. int maxwVariation, maxhVariation;
  1044. int wVariation, hVariation;
  1045. int referenceW, referenceH;
  1046. int currentW, currentH;
  1047. int desiredW, desiredH;
  1048. /* Get display bounds for size range */
  1049. result = SDL_GetDisplayBounds(0, &display);
  1050. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1051. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1052. if (result != 0) return TEST_ABORTED;
  1053. /* Call against new test window */
  1054. window = _createVideoSuiteTestWindow(title);
  1055. if (window == NULL) return TEST_ABORTED;
  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. case 0:
  1069. /* 1 Pixel Wide */
  1070. desiredW = 1;
  1071. break;
  1072. case 1:
  1073. /* Random width inside screen */
  1074. desiredW = SDLTest_RandomIntegerInRange(1, 100);
  1075. break;
  1076. case 2:
  1077. /* Width 1 pixel smaller than screen */
  1078. desiredW = display.w - 1;
  1079. break;
  1080. case 3:
  1081. /* Width at screen size */
  1082. desiredW = display.w;
  1083. break;
  1084. case 4:
  1085. /* Width 1 pixel larger than screen */
  1086. desiredW = display.w + 1;
  1087. break;
  1088. }
  1089. switch(hVariation) {
  1090. case 0:
  1091. /* 1 Pixel High */
  1092. desiredH = 1;
  1093. break;
  1094. case 1:
  1095. /* Random height inside screen */
  1096. desiredH = SDLTest_RandomIntegerInRange(1, 100);
  1097. break;
  1098. case 2:
  1099. /* Height 1 pixel smaller than screen */
  1100. desiredH = display.h - 1;
  1101. break;
  1102. case 3:
  1103. /* Height at screen size */
  1104. desiredH = display.h;
  1105. break;
  1106. case 4:
  1107. /* Height 1 pixel larger than screen */
  1108. desiredH = display.h + 1;
  1109. break;
  1110. }
  1111. /* Set size */
  1112. SDL_SetWindowSize(window, desiredW, desiredH);
  1113. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  1114. /* Get size */
  1115. currentW = desiredW + 1;
  1116. currentH = desiredH + 1;
  1117. SDL_GetWindowSize(window, &currentW, &currentH);
  1118. SDLTest_AssertPass("Call to SDL_GetWindowSize()");
  1119. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1120. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1121. /* Get just width */
  1122. currentW = desiredW + 1;
  1123. SDL_GetWindowSize(window, &currentW, NULL);
  1124. SDLTest_AssertPass("Call to SDL_GetWindowSize(&h=NULL)");
  1125. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1126. /* Get just height */
  1127. currentH = desiredH + 1;
  1128. SDL_GetWindowSize(window, NULL, &currentH);
  1129. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL)");
  1130. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1131. }
  1132. }
  1133. /* Dummy call with both pointers NULL */
  1134. SDL_GetWindowSize(window, NULL, NULL);
  1135. SDLTest_AssertPass("Call to SDL_GetWindowSize(&w=NULL,&h=NULL)");
  1136. /* Negative tests for parameter input */
  1137. SDL_ClearError();
  1138. SDLTest_AssertPass("Call to SDL_ClearError()");
  1139. for (desiredH = -2; desiredH < 2; desiredH++) {
  1140. for (desiredW = -2; desiredW < 2; desiredW++) {
  1141. if (desiredW <= 0 || desiredH <= 0) {
  1142. SDL_SetWindowSize(window, desiredW, desiredH);
  1143. SDLTest_AssertPass("Call to SDL_SetWindowSize(...,%d,%d)", desiredW, desiredH);
  1144. _checkInvalidParameterError();
  1145. }
  1146. }
  1147. }
  1148. /* Clean up */
  1149. _destroyVideoSuiteTestWindow(window);
  1150. /* Set some 'magic' value for later check that nothing was changed */
  1151. referenceW = SDLTest_RandomSint32();
  1152. referenceH = SDLTest_RandomSint32();
  1153. currentW = referenceW;
  1154. currentH = referenceH;
  1155. desiredW = SDLTest_RandomSint32();
  1156. desiredH = SDLTest_RandomSint32();
  1157. /* Negative tests for window input */
  1158. SDL_ClearError();
  1159. SDLTest_AssertPass("Call to SDL_ClearError()");
  1160. SDL_GetWindowSize(NULL, &currentW, &currentH);
  1161. SDLTest_AssertPass("Call to SDL_GetWindowSize(window=NULL)");
  1162. SDLTest_AssertCheck(
  1163. currentW == referenceW && currentH == referenceH,
  1164. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1165. referenceW, referenceH,
  1166. currentW, currentH);
  1167. _checkInvalidWindowError();
  1168. SDL_GetWindowSize(NULL, NULL, NULL);
  1169. SDLTest_AssertPass("Call to SDL_GetWindowSize(NULL, NULL, NULL)");
  1170. _checkInvalidWindowError();
  1171. SDL_SetWindowSize(NULL, desiredW, desiredH);
  1172. SDLTest_AssertPass("Call to SDL_SetWindowSize(window=NULL)");
  1173. _checkInvalidWindowError();
  1174. return TEST_COMPLETED;
  1175. }
  1176. /**
  1177. * @brief Tests call to SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize
  1178. *
  1179. */
  1180. int
  1181. video_getSetWindowMinimumSize(void *arg)
  1182. {
  1183. const char* title = "video_getSetWindowMinimumSize Test Window";
  1184. SDL_Window* window;
  1185. int result;
  1186. SDL_Rect display;
  1187. int wVariation, hVariation;
  1188. int referenceW, referenceH;
  1189. int currentW, currentH;
  1190. int desiredW, desiredH;
  1191. /* Get display bounds for size range */
  1192. result = SDL_GetDisplayBounds(0, &display);
  1193. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1194. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1195. if (result != 0) return TEST_ABORTED;
  1196. /* Call against new test window */
  1197. window = _createVideoSuiteTestWindow(title);
  1198. if (window == NULL) return TEST_ABORTED;
  1199. for (wVariation = 0; wVariation < 5; wVariation++) {
  1200. for (hVariation = 0; hVariation < 5; hVariation++) {
  1201. switch(wVariation) {
  1202. case 0:
  1203. /* 1 Pixel Wide */
  1204. desiredW = 1;
  1205. break;
  1206. case 1:
  1207. /* Random width inside screen */
  1208. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1209. break;
  1210. case 2:
  1211. /* Width at screen size */
  1212. desiredW = display.w;
  1213. break;
  1214. }
  1215. switch(hVariation) {
  1216. case 0:
  1217. /* 1 Pixel High */
  1218. desiredH = 1;
  1219. break;
  1220. case 1:
  1221. /* Random height inside screen */
  1222. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1223. break;
  1224. case 2:
  1225. /* Height at screen size */
  1226. desiredH = display.h;
  1227. break;
  1228. case 4:
  1229. /* Height 1 pixel larger than screen */
  1230. desiredH = display.h + 1;
  1231. break;
  1232. }
  1233. /* Set size */
  1234. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1235. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1236. /* Get size */
  1237. currentW = desiredW + 1;
  1238. currentH = desiredH + 1;
  1239. SDL_GetWindowMinimumSize(window, &currentW, &currentH);
  1240. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize()");
  1241. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1242. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1243. /* Get just width */
  1244. currentW = desiredW + 1;
  1245. SDL_GetWindowMinimumSize(window, &currentW, NULL);
  1246. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&h=NULL)");
  1247. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1248. /* Get just height */
  1249. currentH = desiredH + 1;
  1250. SDL_GetWindowMinimumSize(window, NULL, &currentH);
  1251. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL)");
  1252. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1253. }
  1254. }
  1255. /* Dummy call with both pointers NULL */
  1256. SDL_GetWindowMinimumSize(window, NULL, NULL);
  1257. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(&w=NULL,&h=NULL)");
  1258. /* Negative tests for parameter input */
  1259. SDL_ClearError();
  1260. SDLTest_AssertPass("Call to SDL_ClearError()");
  1261. for (desiredH = -2; desiredH < 2; desiredH++) {
  1262. for (desiredW = -2; desiredW < 2; desiredW++) {
  1263. if (desiredW <= 0 || desiredH <= 0) {
  1264. SDL_SetWindowMinimumSize(window, desiredW, desiredH);
  1265. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(...,%d,%d)", desiredW, desiredH);
  1266. _checkInvalidParameterError();
  1267. }
  1268. }
  1269. }
  1270. /* Clean up */
  1271. _destroyVideoSuiteTestWindow(window);
  1272. /* Set some 'magic' value for later check that nothing was changed */
  1273. referenceW = SDLTest_RandomSint32();
  1274. referenceH = SDLTest_RandomSint32();
  1275. currentW = referenceW;
  1276. currentH = referenceH;
  1277. desiredW = SDLTest_RandomSint32();
  1278. desiredH = SDLTest_RandomSint32();
  1279. /* Negative tests for window input */
  1280. SDL_ClearError();
  1281. SDLTest_AssertPass("Call to SDL_ClearError()");
  1282. SDL_GetWindowMinimumSize(NULL, &currentW, &currentH);
  1283. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(window=NULL)");
  1284. SDLTest_AssertCheck(
  1285. currentW == referenceW && currentH == referenceH,
  1286. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1287. referenceW, referenceH,
  1288. currentW, currentH);
  1289. _checkInvalidWindowError();
  1290. SDL_GetWindowMinimumSize(NULL, NULL, NULL);
  1291. SDLTest_AssertPass("Call to SDL_GetWindowMinimumSize(NULL, NULL, NULL)");
  1292. _checkInvalidWindowError();
  1293. SDL_SetWindowMinimumSize(NULL, desiredW, desiredH);
  1294. SDLTest_AssertPass("Call to SDL_SetWindowMinimumSize(window=NULL)");
  1295. _checkInvalidWindowError();
  1296. return TEST_COMPLETED;
  1297. }
  1298. /**
  1299. * @brief Tests call to SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize
  1300. *
  1301. */
  1302. int
  1303. video_getSetWindowMaximumSize(void *arg)
  1304. {
  1305. const char* title = "video_getSetWindowMaximumSize Test Window";
  1306. SDL_Window* window;
  1307. int result;
  1308. SDL_Rect display;
  1309. int wVariation, hVariation;
  1310. int referenceW, referenceH;
  1311. int currentW, currentH;
  1312. int desiredW, desiredH;
  1313. /* Get display bounds for size range */
  1314. result = SDL_GetDisplayBounds(0, &display);
  1315. SDLTest_AssertPass("SDL_GetDisplayBounds()");
  1316. SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
  1317. if (result != 0) return TEST_ABORTED;
  1318. /* Call against new test window */
  1319. window = _createVideoSuiteTestWindow(title);
  1320. if (window == NULL) return TEST_ABORTED;
  1321. for (wVariation = 0; wVariation < 3; wVariation++) {
  1322. for (hVariation = 0; hVariation < 3; hVariation++) {
  1323. switch(wVariation) {
  1324. case 0:
  1325. /* 1 Pixel Wide */
  1326. desiredW = 1;
  1327. break;
  1328. case 1:
  1329. /* Random width inside screen */
  1330. desiredW = SDLTest_RandomIntegerInRange(2, display.w - 1);
  1331. break;
  1332. case 2:
  1333. /* Width at screen size */
  1334. desiredW = display.w;
  1335. break;
  1336. }
  1337. switch(hVariation) {
  1338. case 0:
  1339. /* 1 Pixel High */
  1340. desiredH = 1;
  1341. break;
  1342. case 1:
  1343. /* Random height inside screen */
  1344. desiredH = SDLTest_RandomIntegerInRange(2, display.h - 1);
  1345. break;
  1346. case 2:
  1347. /* Height at screen size */
  1348. desiredH = display.h;
  1349. break;
  1350. }
  1351. /* Set size */
  1352. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1353. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1354. /* Get size */
  1355. currentW = desiredW + 1;
  1356. currentH = desiredH + 1;
  1357. SDL_GetWindowMaximumSize(window, &currentW, &currentH);
  1358. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize()");
  1359. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentW);
  1360. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredH, currentH);
  1361. /* Get just width */
  1362. currentW = desiredW + 1;
  1363. SDL_GetWindowMaximumSize(window, &currentW, NULL);
  1364. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&h=NULL)");
  1365. SDLTest_AssertCheck(desiredW == currentW, "Verify returned width; expected: %d, got: %d", desiredW, currentH);
  1366. /* Get just height */
  1367. currentH = desiredH + 1;
  1368. SDL_GetWindowMaximumSize(window, NULL, &currentH);
  1369. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL)");
  1370. SDLTest_AssertCheck(desiredH == currentH, "Verify returned height; expected: %d, got: %d", desiredW, currentH);
  1371. }
  1372. }
  1373. /* Dummy call with both pointers NULL */
  1374. SDL_GetWindowMaximumSize(window, NULL, NULL);
  1375. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(&w=NULL,&h=NULL)");
  1376. /* Negative tests for parameter input */
  1377. SDL_ClearError();
  1378. SDLTest_AssertPass("Call to SDL_ClearError()");
  1379. for (desiredH = -2; desiredH < 2; desiredH++) {
  1380. for (desiredW = -2; desiredW < 2; desiredW++) {
  1381. if (desiredW <= 0 || desiredH <= 0) {
  1382. SDL_SetWindowMaximumSize(window, desiredW, desiredH);
  1383. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(...,%d,%d)", desiredW, desiredH);
  1384. _checkInvalidParameterError();
  1385. }
  1386. }
  1387. }
  1388. /* Clean up */
  1389. _destroyVideoSuiteTestWindow(window);
  1390. /* Set some 'magic' value for later check that nothing was changed */
  1391. referenceW = SDLTest_RandomSint32();
  1392. referenceH = SDLTest_RandomSint32();
  1393. currentW = referenceW;
  1394. currentH = referenceH;
  1395. desiredW = SDLTest_RandomSint32();
  1396. desiredH = SDLTest_RandomSint32();
  1397. /* Negative tests */
  1398. SDL_ClearError();
  1399. SDLTest_AssertPass("Call to SDL_ClearError()");
  1400. SDL_GetWindowMaximumSize(NULL, &currentW, &currentH);
  1401. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(window=NULL)");
  1402. SDLTest_AssertCheck(
  1403. currentW == referenceW && currentH == referenceH,
  1404. "Verify that content of W and H pointers has not been modified; expected: %d,%d; got: %d,%d",
  1405. referenceW, referenceH,
  1406. currentW, currentH);
  1407. _checkInvalidWindowError();
  1408. SDL_GetWindowMaximumSize(NULL, NULL, NULL);
  1409. SDLTest_AssertPass("Call to SDL_GetWindowMaximumSize(NULL, NULL, NULL)");
  1410. _checkInvalidWindowError();
  1411. SDL_SetWindowMaximumSize(NULL, desiredW, desiredH);
  1412. SDLTest_AssertPass("Call to SDL_SetWindowMaximumSize(window=NULL)");
  1413. _checkInvalidWindowError();
  1414. return TEST_COMPLETED;
  1415. }
  1416. /**
  1417. * @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
  1418. *
  1419. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_SetWindowData
  1420. * @sa https://github.com/libsdl-org/SDL/wiki/SDL_GetWindowData
  1421. */
  1422. int
  1423. video_getSetWindowData(void *arg)
  1424. {
  1425. int returnValue = TEST_COMPLETED;
  1426. const char* title = "video_setGetWindowData Test Window";
  1427. SDL_Window* window;
  1428. const char *referenceName = "TestName";
  1429. const char *name = "TestName";
  1430. const char *referenceName2 = "TestName2";
  1431. const char *name2 = "TestName2";
  1432. int datasize;
  1433. char *referenceUserdata = NULL;
  1434. char *userdata = NULL;
  1435. char *referenceUserdata2 = NULL;
  1436. char *userdata2 = NULL;
  1437. char *result;
  1438. int iteration;
  1439. /* Call against new test window */
  1440. window = _createVideoSuiteTestWindow(title);
  1441. if (window == NULL) return TEST_ABORTED;
  1442. /* Create testdata */
  1443. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1444. referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
  1445. if (referenceUserdata == NULL) {
  1446. returnValue = TEST_ABORTED;
  1447. goto cleanup;
  1448. }
  1449. userdata = SDL_strdup(referenceUserdata);
  1450. if (userdata == NULL) {
  1451. returnValue = TEST_ABORTED;
  1452. goto cleanup;
  1453. }
  1454. datasize = SDLTest_RandomIntegerInRange(1, 32);
  1455. referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
  1456. if (referenceUserdata2 == NULL) {
  1457. returnValue = TEST_ABORTED;
  1458. goto cleanup;
  1459. }
  1460. userdata2 = (char *)SDL_strdup(referenceUserdata2);
  1461. if (userdata2 == NULL) {
  1462. returnValue = TEST_ABORTED;
  1463. goto cleanup;
  1464. }
  1465. /* Get non-existent data */
  1466. result = (char *)SDL_GetWindowData(window, name);
  1467. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1468. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1469. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1470. /* Set data */
  1471. result = (char *)SDL_SetWindowData(window, name, userdata);
  1472. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s)", name, userdata);
  1473. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1474. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1475. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1476. /* Get data (twice) */
  1477. for (iteration = 1; iteration <= 2; iteration++) {
  1478. result = (char *)SDL_GetWindowData(window, name);
  1479. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [iteration %d]", name, iteration);
  1480. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1481. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1482. }
  1483. /* Set data again twice */
  1484. for (iteration = 1; iteration <= 2; iteration++) {
  1485. result = (char *)SDL_SetWindowData(window, name, userdata);
  1486. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [iteration %d]", name, userdata, iteration);
  1487. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1488. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1489. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1490. }
  1491. /* Get data again */
  1492. result = (char *)SDL_GetWindowData(window, name);
  1493. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again]", name);
  1494. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1495. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1496. /* Set data with new data */
  1497. result = (char *)SDL_SetWindowData(window, name, userdata2);
  1498. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata]", name, userdata2);
  1499. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1500. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1501. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1502. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1503. /* Set data with new data again */
  1504. result = (char *)SDL_SetWindowData(window, name, userdata2);
  1505. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [new userdata again]", name, userdata2);
  1506. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1507. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1508. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1509. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1510. /* Get new data */
  1511. result = (char *)SDL_GetWindowData(window, name);
  1512. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1513. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1514. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1515. /* Set data with NULL to clear */
  1516. result = (char *)SDL_SetWindowData(window, name, NULL);
  1517. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
  1518. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
  1519. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1520. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1521. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1522. /* Set data with NULL to clear again */
  1523. result = (char *)SDL_SetWindowData(window, name, NULL);
  1524. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
  1525. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1526. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1527. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1528. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);
  1529. /* Get non-existent data */
  1530. result = (char *)SDL_GetWindowData(window, name);
  1531. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name);
  1532. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1533. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1534. /* Get non-existent data new name */
  1535. result = (char *)SDL_GetWindowData(window, name2);
  1536. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s)", name2);
  1537. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1538. SDLTest_AssertCheck(SDL_strcmp(referenceName2, name2) == 0, "Validate that name2 was not changed, expected: %s, got: %s", referenceName2, name2);
  1539. /* Set data (again) */
  1540. result = (char *)SDL_SetWindowData(window, name, userdata);
  1541. SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,%s) [again, after clear]", name, userdata);
  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. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
  1545. /* Get data (again) */
  1546. result = (char *)SDL_GetWindowData(window, name);
  1547. SDLTest_AssertPass("Call to SDL_GetWindowData(..,%s) [again, after clear]", name);
  1548. SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata, result);
  1549. SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
  1550. /* Negative test */
  1551. SDL_ClearError();
  1552. SDLTest_AssertPass("Call to SDL_ClearError()");
  1553. /* Set with invalid window */
  1554. result = (char *)SDL_SetWindowData(NULL, name, userdata);
  1555. SDLTest_AssertPass("Call to SDL_SetWindowData(window=NULL)");
  1556. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1557. _checkInvalidWindowError();
  1558. /* Set data with NULL name, valid userdata */
  1559. result = (char *)SDL_SetWindowData(window, NULL, userdata);
  1560. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL)");
  1561. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1562. _checkInvalidParameterError();
  1563. /* Set data with empty name, valid userdata */
  1564. result = (char *)SDL_SetWindowData(window, "", userdata);
  1565. SDLTest_AssertPass("Call to SDL_SetWindowData(name='')");
  1566. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1567. _checkInvalidParameterError();
  1568. /* Set data with NULL name, NULL userdata */
  1569. result = (char *)SDL_SetWindowData(window, NULL, NULL);
  1570. SDLTest_AssertPass("Call to SDL_SetWindowData(name=NULL,userdata=NULL)");
  1571. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1572. _checkInvalidParameterError();
  1573. /* Set data with empty name, NULL userdata */
  1574. result = (char *)SDL_SetWindowData(window, "", NULL);
  1575. SDLTest_AssertPass("Call to SDL_SetWindowData(name='',userdata=NULL)");
  1576. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1577. _checkInvalidParameterError();
  1578. /* Get with invalid window */
  1579. result = (char *)SDL_GetWindowData(NULL, name);
  1580. SDLTest_AssertPass("Call to SDL_GetWindowData(window=NULL)");
  1581. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1582. _checkInvalidWindowError();
  1583. /* Get data with NULL name */
  1584. result = (char *)SDL_GetWindowData(window, NULL);
  1585. SDLTest_AssertPass("Call to SDL_GetWindowData(name=NULL)");
  1586. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1587. _checkInvalidParameterError();
  1588. /* Get data with empty name */
  1589. result = (char *)SDL_GetWindowData(window, "");
  1590. SDLTest_AssertPass("Call to SDL_GetWindowData(name='')");
  1591. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1592. _checkInvalidParameterError();
  1593. /* Clean up */
  1594. _destroyVideoSuiteTestWindow(window);
  1595. cleanup:
  1596. SDL_free(referenceUserdata);
  1597. SDL_free(referenceUserdata2);
  1598. SDL_free(userdata);
  1599. SDL_free(userdata2);
  1600. return returnValue;
  1601. }
  1602. /* ================= Test References ================== */
  1603. /* Video test cases */
  1604. static const SDLTest_TestCaseReference videoTest1 =
  1605. { (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED };
  1606. static const SDLTest_TestCaseReference videoTest2 =
  1607. { (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions", "Create windows at various locations", TEST_ENABLED };
  1608. static const SDLTest_TestCaseReference videoTest3 =
  1609. { (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED };
  1610. static const SDLTest_TestCaseReference videoTest4 =
  1611. { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED };
  1612. static const SDLTest_TestCaseReference videoTest5 =
  1613. { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
  1614. static const SDLTest_TestCaseReference videoTest6 =
  1615. { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
  1616. static const SDLTest_TestCaseReference videoTest7 =
  1617. { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
  1618. static const SDLTest_TestCaseReference videoTest8 =
  1619. { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
  1620. static const SDLTest_TestCaseReference videoTest9 =
  1621. { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
  1622. static const SDLTest_TestCaseReference videoTest10 =
  1623. { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED };
  1624. static const SDLTest_TestCaseReference videoTest11 =
  1625. { (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative", "Get window brightness with invalid input", TEST_ENABLED };
  1626. static const SDLTest_TestCaseReference videoTest12 =
  1627. { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED };
  1628. static const SDLTest_TestCaseReference videoTest13 =
  1629. { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED };
  1630. static const SDLTest_TestCaseReference videoTest14 =
  1631. { (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp", "Get window gamma ramp", TEST_ENABLED };
  1632. static const SDLTest_TestCaseReference videoTest15 =
  1633. { (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative", "Get window gamma ramp against invalid input", TEST_ENABLED };
  1634. static const SDLTest_TestCaseReference videoTest16 =
  1635. { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED };
  1636. static const SDLTest_TestCaseReference videoTest17 =
  1637. { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED };
  1638. static const SDLTest_TestCaseReference videoTest18 =
  1639. { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED };
  1640. static const SDLTest_TestCaseReference videoTest19 =
  1641. { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED };
  1642. static const SDLTest_TestCaseReference videoTest20 =
  1643. { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED };
  1644. static const SDLTest_TestCaseReference videoTest21 =
  1645. { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED };
  1646. static const SDLTest_TestCaseReference videoTest22 =
  1647. { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED };
  1648. static const SDLTest_TestCaseReference videoTest23 =
  1649. { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
  1650. /* Sequence of Video test cases */
  1651. static const SDLTest_TestCaseReference *videoTests[] = {
  1652. &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
  1653. &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
  1654. &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
  1655. &videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
  1656. &videoTest23, NULL
  1657. };
  1658. /* Video test suite (global) */
  1659. SDLTest_TestSuiteReference videoTestSuite = {
  1660. "Video",
  1661. NULL,
  1662. videoTests,
  1663. NULL
  1664. };