testautomation_mouse.c 21 KB

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