testautomation_video.c 95 KB

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