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