testautomation_mouse.c 21 KB

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