testautomation_video.c 90 KB

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