testautomation_video.c 64 KB

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