testautomation_video.c 73 KB

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