testautomation_video.c 74 KB

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