testautomation_mouse.c 21 KB

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