testautomation_video.c 92 KB

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