testautomation_video.c 70 KB

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