testautomation_mouse.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /**
  2. * Mouse test suite
  3. */
  4. #include <limits.h>
  5. #include <SDL3/SDL.h>
  6. #include <SDL3/SDL_test.h>
  7. /* ================= Test Case Implementation ================== */
  8. /* Test case functions */
  9. /* Helper to evaluate state returned from SDL_GetMouseState */
  10. static int mouseStateCheck(Uint32 state)
  11. {
  12. return (state == 0) ||
  13. (state == SDL_BUTTON(SDL_BUTTON_LEFT)) ||
  14. (state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) ||
  15. (state == SDL_BUTTON(SDL_BUTTON_RIGHT)) ||
  16. (state == SDL_BUTTON(SDL_BUTTON_X1)) ||
  17. (state == SDL_BUTTON(SDL_BUTTON_X2));
  18. }
  19. /**
  20. * @brief Check call to SDL_GetMouseState
  21. *
  22. */
  23. int mouse_getMouseState(void *arg)
  24. {
  25. int x;
  26. int y;
  27. Uint32 state;
  28. /* Pump some events to update mouse state */
  29. SDL_PumpEvents();
  30. SDLTest_AssertPass("Call to SDL_PumpEvents()");
  31. /* Case where x, y pointer is NULL */
  32. state = SDL_GetMouseState(NULL, NULL);
  33. SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)");
  34. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  35. /* Case where x pointer is not NULL */
  36. x = INT_MIN;
  37. state = SDL_GetMouseState(&x, NULL);
  38. SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
  39. SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
  40. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  41. /* Case where y pointer is not NULL */
  42. y = INT_MIN;
  43. state = SDL_GetMouseState(NULL, &y);
  44. SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
  45. SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
  46. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  47. /* Case where x and y pointer is not NULL */
  48. x = INT_MIN;
  49. y = INT_MIN;
  50. state = SDL_GetMouseState(&x, &y);
  51. SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)");
  52. SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
  53. SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
  54. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  55. return TEST_COMPLETED;
  56. }
  57. /**
  58. * @brief Check call to SDL_GetRelativeMouseState
  59. *
  60. */
  61. int mouse_getRelativeMouseState(void *arg)
  62. {
  63. int x;
  64. int y;
  65. Uint32 state;
  66. /* Pump some events to update mouse state */
  67. SDL_PumpEvents();
  68. SDLTest_AssertPass("Call to SDL_PumpEvents()");
  69. /* Case where x, y pointer is NULL */
  70. state = SDL_GetRelativeMouseState(NULL, NULL);
  71. SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)");
  72. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  73. /* Case where x pointer is not NULL */
  74. x = INT_MIN;
  75. state = SDL_GetRelativeMouseState(&x, NULL);
  76. SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
  77. SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
  78. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  79. /* Case where y pointer is not NULL */
  80. y = INT_MIN;
  81. state = SDL_GetRelativeMouseState(NULL, &y);
  82. SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
  83. SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
  84. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  85. /* Case where x and y pointer is not NULL */
  86. x = INT_MIN;
  87. y = INT_MIN;
  88. state = SDL_GetRelativeMouseState(&x, &y);
  89. SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)");
  90. SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
  91. SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
  92. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  93. return TEST_COMPLETED;
  94. }
  95. /* XPM definition of mouse Cursor */
  96. static const char *g_mouseArrowData[] = {
  97. /* pixels */
  98. "X ",
  99. "XX ",
  100. "X.X ",
  101. "X..X ",
  102. "X...X ",
  103. "X....X ",
  104. "X.....X ",
  105. "X......X ",
  106. "X.......X ",
  107. "X........X ",
  108. "X.....XXXXX ",
  109. "X..X..X ",
  110. "X.X X..X ",
  111. "XX X..X ",
  112. "X X..X ",
  113. " X..X ",
  114. " X..X ",
  115. " X..X ",
  116. " XX ",
  117. " ",
  118. " ",
  119. " ",
  120. " ",
  121. " ",
  122. " ",
  123. " ",
  124. " ",
  125. " ",
  126. " ",
  127. " ",
  128. " ",
  129. " "
  130. };
  131. /* Helper that creates a new mouse cursor from an XPM */
  132. static SDL_Cursor *initArrowCursor(const char *image[])
  133. {
  134. SDL_Cursor *cursor;
  135. int i, row, col;
  136. Uint8 data[4 * 32];
  137. Uint8 mask[4 * 32];
  138. i = -1;
  139. for (row = 0; row < 32; ++row) {
  140. for (col = 0; col < 32; ++col) {
  141. if (col % 8) {
  142. data[i] <<= 1;
  143. mask[i] <<= 1;
  144. } else {
  145. ++i;
  146. data[i] = mask[i] = 0;
  147. }
  148. switch (image[row][col]) {
  149. case 'X':
  150. data[i] |= 0x01;
  151. mask[i] |= 0x01;
  152. break;
  153. case '.':
  154. mask[i] |= 0x01;
  155. break;
  156. case ' ':
  157. break;
  158. }
  159. }
  160. }
  161. cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
  162. return cursor;
  163. }
  164. /**
  165. * @brief Check call to SDL_CreateCursor and SDL_FreeCursor
  166. *
  167. * @sa http://wiki.libsdl.org/SDL_CreateCursor
  168. * @sa http://wiki.libsdl.org/SDL_FreeCursor
  169. */
  170. int mouse_createFreeCursor(void *arg)
  171. {
  172. SDL_Cursor *cursor;
  173. /* Create a cursor */
  174. cursor = initArrowCursor(g_mouseArrowData);
  175. SDLTest_AssertPass("Call to SDL_CreateCursor()");
  176. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
  177. if (cursor == NULL) {
  178. return TEST_ABORTED;
  179. }
  180. /* Free cursor again */
  181. SDL_FreeCursor(cursor);
  182. SDLTest_AssertPass("Call to SDL_FreeCursor()");
  183. return TEST_COMPLETED;
  184. }
  185. /**
  186. * @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor
  187. *
  188. * @sa http://wiki.libsdl.org/SDL_CreateColorCursor
  189. * @sa http://wiki.libsdl.org/SDL_FreeCursor
  190. */
  191. int mouse_createFreeColorCursor(void *arg)
  192. {
  193. SDL_Surface *face;
  194. SDL_Cursor *cursor;
  195. /* Get sample surface */
  196. face = SDLTest_ImageFace();
  197. SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
  198. if (face == NULL) {
  199. return TEST_ABORTED;
  200. }
  201. /* Create a color cursor from surface */
  202. cursor = SDL_CreateColorCursor(face, 0, 0);
  203. SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
  204. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
  205. if (cursor == NULL) {
  206. SDL_DestroySurface(face);
  207. return TEST_ABORTED;
  208. }
  209. /* Free cursor again */
  210. SDL_FreeCursor(cursor);
  211. SDLTest_AssertPass("Call to SDL_FreeCursor()");
  212. /* Clean up */
  213. SDL_DestroySurface(face);
  214. return TEST_COMPLETED;
  215. }
  216. /* Helper that changes cursor visibility */
  217. static void changeCursorVisibility(SDL_bool state)
  218. {
  219. SDL_bool newState;
  220. if (state) {
  221. SDL_ShowCursor();
  222. } else {
  223. SDL_HideCursor();
  224. }
  225. SDLTest_AssertPass("Call to %s", state ? "SDL_ShowCursor()" : "SDL_HideCursor()");
  226. newState = SDL_CursorVisible();
  227. SDLTest_AssertPass("Call to SDL_CursorVisible()");
  228. SDLTest_AssertCheck(state == newState, "Validate new state, expected: %s, got: %s",
  229. state ? "SDL_TRUE" : "SDL_FALSE",
  230. newState ? "SDL_TRUE" : "SDL_FALSE");
  231. }
  232. /**
  233. * @brief Check call to SDL_ShowCursor
  234. *
  235. * @sa http://wiki.libsdl.org/SDL_ShowCursor
  236. */
  237. int mouse_showCursor(void *arg)
  238. {
  239. SDL_bool currentState;
  240. /* Get current state */
  241. currentState = SDL_CursorVisible();
  242. SDLTest_AssertPass("Call to SDL_CursorVisible()");
  243. if (currentState) {
  244. /* Hide the cursor, then show it again */
  245. changeCursorVisibility(SDL_FALSE);
  246. changeCursorVisibility(SDL_TRUE);
  247. } else {
  248. /* Show the cursor, then hide it again */
  249. changeCursorVisibility(SDL_TRUE);
  250. changeCursorVisibility(SDL_FALSE);
  251. }
  252. return TEST_COMPLETED;
  253. }
  254. /**
  255. * @brief Check call to SDL_SetCursor
  256. *
  257. * @sa http://wiki.libsdl.org/SDL_SetCursor
  258. */
  259. int mouse_setCursor(void *arg)
  260. {
  261. SDL_Cursor *cursor;
  262. /* Create a cursor */
  263. cursor = initArrowCursor(g_mouseArrowData);
  264. SDLTest_AssertPass("Call to SDL_CreateCursor()");
  265. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
  266. if (cursor == NULL) {
  267. return TEST_ABORTED;
  268. }
  269. /* Set the arrow cursor */
  270. SDL_SetCursor(cursor);
  271. SDLTest_AssertPass("Call to SDL_SetCursor(cursor)");
  272. /* Force redraw */
  273. SDL_SetCursor(NULL);
  274. SDLTest_AssertPass("Call to SDL_SetCursor(NULL)");
  275. /* Free cursor again */
  276. SDL_FreeCursor(cursor);
  277. SDLTest_AssertPass("Call to SDL_FreeCursor()");
  278. return TEST_COMPLETED;
  279. }
  280. /**
  281. * @brief Check call to SDL_GetCursor
  282. *
  283. * @sa http://wiki.libsdl.org/SDL_GetCursor
  284. */
  285. int mouse_getCursor(void *arg)
  286. {
  287. SDL_Cursor *cursor;
  288. /* Get current cursor */
  289. cursor = SDL_GetCursor();
  290. SDLTest_AssertPass("Call to SDL_GetCursor()");
  291. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");
  292. return TEST_COMPLETED;
  293. }
  294. /**
  295. * @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode
  296. *
  297. * @sa http://wiki.libsdl.org/SDL_GetRelativeMouseMode
  298. * @sa http://wiki.libsdl.org/SDL_SetRelativeMouseMode
  299. */
  300. int mouse_getSetRelativeMouseMode(void *arg)
  301. {
  302. int result;
  303. int i;
  304. SDL_bool initialState;
  305. SDL_bool currentState;
  306. /* Capture original state so we can revert back to it later */
  307. initialState = SDL_GetRelativeMouseMode();
  308. SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
  309. /* Repeat twice to check D->D transition */
  310. for (i = 0; i < 2; i++) {
  311. /* Disable - should always be supported */
  312. result = SDL_SetRelativeMouseMode(SDL_FALSE);
  313. SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
  314. SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
  315. currentState = SDL_GetRelativeMouseMode();
  316. SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
  317. SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
  318. }
  319. /* Repeat twice to check D->E->E transition */
  320. for (i = 0; i < 2; i++) {
  321. /* Enable - may not be supported */
  322. result = SDL_SetRelativeMouseMode(SDL_TRUE);
  323. SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
  324. if (result != -1) {
  325. SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
  326. currentState = SDL_GetRelativeMouseMode();
  327. SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
  328. SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
  329. }
  330. }
  331. /* Disable to check E->D transition */
  332. result = SDL_SetRelativeMouseMode(SDL_FALSE);
  333. SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
  334. SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
  335. currentState = SDL_GetRelativeMouseMode();
  336. SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
  337. SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
  338. /* Revert to original state - ignore result */
  339. result = SDL_SetRelativeMouseMode(initialState);
  340. return TEST_COMPLETED;
  341. }
  342. #define MOUSE_TESTWINDOW_WIDTH 320
  343. #define MOUSE_TESTWINDOW_HEIGHT 200
  344. /**
  345. * Creates a test window
  346. */
  347. static SDL_Window *createMouseSuiteTestWindow()
  348. {
  349. int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
  350. SDL_Window *window;
  351. window = SDL_CreateWindow("mousecreateMouseSuiteTestWindow", posX, posY, width, height, 0);
  352. SDLTest_AssertPass("SDL_CreateWindow()");
  353. SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
  354. return window;
  355. }
  356. /*
  357. * Destroy test window
  358. */
  359. static void destroyMouseSuiteTestWindow(SDL_Window *window)
  360. {
  361. if (window != NULL) {
  362. SDL_DestroyWindow(window);
  363. window = NULL;
  364. SDLTest_AssertPass("SDL_DestroyWindow()");
  365. }
  366. }
  367. /**
  368. * @brief Check call to SDL_WarpMouseInWindow
  369. *
  370. * @sa http://wiki.libsdl.org/SDL_WarpMouseInWindow
  371. */
  372. int mouse_warpMouseInWindow(void *arg)
  373. {
  374. const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
  375. int numPositions = 6;
  376. int xPositions[6];
  377. int yPositions[6];
  378. int x, y, i, j;
  379. SDL_Window *window;
  380. xPositions[0] = -1;
  381. xPositions[1] = 0;
  382. xPositions[2] = 1;
  383. xPositions[3] = w - 1;
  384. xPositions[4] = w;
  385. xPositions[5] = w + 1;
  386. yPositions[0] = -1;
  387. yPositions[1] = 0;
  388. yPositions[2] = 1;
  389. yPositions[3] = h - 1;
  390. yPositions[4] = h;
  391. yPositions[5] = h + 1;
  392. /* Create test window */
  393. window = createMouseSuiteTestWindow();
  394. if (window == NULL) {
  395. return TEST_ABORTED;
  396. }
  397. /* Mouse to random position inside window */
  398. x = SDLTest_RandomIntegerInRange(1, w - 1);
  399. y = SDLTest_RandomIntegerInRange(1, h - 1);
  400. SDL_WarpMouseInWindow(window, x, y);
  401. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
  402. /* Same position again */
  403. SDL_WarpMouseInWindow(window, x, y);
  404. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
  405. /* Mouse to various boundary positions */
  406. for (i = 0; i < numPositions; i++) {
  407. for (j = 0; j < numPositions; j++) {
  408. x = xPositions[i];
  409. y = yPositions[j];
  410. SDL_WarpMouseInWindow(window, x, y);
  411. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
  412. /* TODO: add tracking of events and check that each call generates a mouse motion event */
  413. SDL_PumpEvents();
  414. SDLTest_AssertPass("SDL_PumpEvents()");
  415. }
  416. }
  417. /* Clean up test window */
  418. destroyMouseSuiteTestWindow(window);
  419. return TEST_COMPLETED;
  420. }
  421. /**
  422. * @brief Check call to SDL_GetMouseFocus
  423. *
  424. * @sa http://wiki.libsdl.org/SDL_GetMouseFocus
  425. */
  426. int mouse_getMouseFocus(void *arg)
  427. {
  428. const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
  429. int x, y;
  430. SDL_Window *window;
  431. SDL_Window *focusWindow;
  432. /* Get focus - focus non-deterministic */
  433. focusWindow = SDL_GetMouseFocus();
  434. SDLTest_AssertPass("SDL_GetMouseFocus()");
  435. /* Create test window */
  436. window = createMouseSuiteTestWindow();
  437. if (window == NULL) {
  438. return TEST_ABORTED;
  439. }
  440. /* Mouse to random position inside window */
  441. x = SDLTest_RandomIntegerInRange(1, w - 1);
  442. y = SDLTest_RandomIntegerInRange(1, h - 1);
  443. SDL_WarpMouseInWindow(window, x, y);
  444. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
  445. /* Pump events to update focus state */
  446. SDL_Delay(100);
  447. SDL_PumpEvents();
  448. SDLTest_AssertPass("SDL_PumpEvents()");
  449. /* Get focus with explicit window setup - focus deterministic */
  450. focusWindow = SDL_GetMouseFocus();
  451. SDLTest_AssertPass("SDL_GetMouseFocus()");
  452. SDLTest_AssertCheck(focusWindow != NULL, "Check returned window value is not NULL");
  453. SDLTest_AssertCheck(focusWindow == window, "Check returned window value is test window");
  454. /* Mouse to random position outside window */
  455. x = SDLTest_RandomIntegerInRange(-9, -1);
  456. y = SDLTest_RandomIntegerInRange(-9, -1);
  457. SDL_WarpMouseInWindow(window, x, y);
  458. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
  459. /* Clean up test window */
  460. destroyMouseSuiteTestWindow(window);
  461. /* Pump events to update focus state */
  462. SDL_PumpEvents();
  463. SDLTest_AssertPass("SDL_PumpEvents()");
  464. /* Get focus for non-existing window */
  465. focusWindow = SDL_GetMouseFocus();
  466. SDLTest_AssertPass("SDL_GetMouseFocus()");
  467. SDLTest_AssertCheck(focusWindow == NULL, "Check returned window value is NULL");
  468. return TEST_COMPLETED;
  469. }
  470. /**
  471. * @brief Check call to SDL_GetDefaultCursor
  472. *
  473. * @sa http://wiki.libsdl.org/SDL_GetDefaultCursor
  474. */
  475. int mouse_getDefaultCursor(void *arg)
  476. {
  477. SDL_Cursor *cursor;
  478. /* Get current cursor */
  479. cursor = SDL_GetDefaultCursor();
  480. SDLTest_AssertPass("Call to SDL_GetDefaultCursor()");
  481. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetDefaultCursor() is not NULL");
  482. return TEST_COMPLETED;
  483. }
  484. /**
  485. * @brief Check call to SDL_GetGlobalMouseState
  486. *
  487. * @sa http://wiki.libsdl.org/SDL_GetGlobalMouseState
  488. */
  489. int mouse_getGlobalMouseState(void *arg)
  490. {
  491. int x;
  492. int y;
  493. Uint32 state;
  494. x = INT_MIN;
  495. y = INT_MIN;
  496. /* Get current cursor */
  497. state = SDL_GetGlobalMouseState(&x, &y);
  498. SDLTest_AssertPass("Call to SDL_GetGlobalMouseState()");
  499. SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
  500. SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
  501. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  502. return TEST_COMPLETED;
  503. }
  504. /* ================= Test References ================== */
  505. /* Mouse test cases */
  506. static const SDLTest_TestCaseReference mouseTest1 = {
  507. (SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED
  508. };
  509. static const SDLTest_TestCaseReference mouseTest2 = {
  510. (SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED
  511. };
  512. static const SDLTest_TestCaseReference mouseTest3 = {
  513. (SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED
  514. };
  515. static const SDLTest_TestCaseReference mouseTest4 = {
  516. (SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED
  517. };
  518. static const SDLTest_TestCaseReference mouseTest5 = {
  519. (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED
  520. };
  521. static const SDLTest_TestCaseReference mouseTest6 = {
  522. (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED
  523. };
  524. static const SDLTest_TestCaseReference mouseTest7 = {
  525. (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED
  526. };
  527. static const SDLTest_TestCaseReference mouseTest8 = {
  528. (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED
  529. };
  530. static const SDLTest_TestCaseReference mouseTest9 = {
  531. (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED
  532. };
  533. static const SDLTest_TestCaseReference mouseTest10 = {
  534. (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED
  535. };
  536. static const SDLTest_TestCaseReference mouseTest11 = {
  537. (SDLTest_TestCaseFp)mouse_getDefaultCursor, "mouse_getDefaultCursor", "Check call to mouse_getDefaultCursor", TEST_ENABLED
  538. };
  539. static const SDLTest_TestCaseReference mouseTest12 = {
  540. (SDLTest_TestCaseFp)mouse_getGlobalMouseState, "mouse_getGlobalMouseState", "Check call to mouse_getGlobalMouseState", TEST_ENABLED
  541. };
  542. /* Sequence of Mouse test cases */
  543. static const SDLTest_TestCaseReference *mouseTests[] = {
  544. &mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6,
  545. &mouseTest7, &mouseTest8, &mouseTest9, &mouseTest10, &mouseTest11, &mouseTest12, NULL
  546. };
  547. /* Mouse test suite (global) */
  548. SDLTest_TestSuiteReference mouseTestSuite = {
  549. "Mouse",
  550. NULL,
  551. mouseTests,
  552. NULL
  553. };