testautomation_video.c 77 KB

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