testautomation_mouse.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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_MASK(SDL_BUTTON_LEFT)) ||
  17. (state == SDL_BUTTON_MASK(SDL_BUTTON_MIDDLE)) ||
  18. (state == SDL_BUTTON_MASK(SDL_BUTTON_RIGHT)) ||
  19. (state == SDL_BUTTON_MASK(SDL_BUTTON_X1)) ||
  20. (state == SDL_BUTTON_MASK(SDL_BUTTON_X2));
  21. }
  22. /**
  23. * Check call to SDL_GetMouseState
  24. *
  25. */
  26. static int SDLCALL 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 SDLCALL 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 SDLCALL 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. SDLTest_AssertPass("About to call SDL_DestroyCursor()");
  185. SDL_DestroyCursor(cursor);
  186. SDLTest_AssertPass("Call to SDL_DestroyCursor()");
  187. return TEST_COMPLETED;
  188. }
  189. /**
  190. * Check call to SDL_CreateColorCursor and SDL_DestroyCursor
  191. *
  192. * \sa SDL_CreateColorCursor
  193. * \sa SDL_DestroyCursor
  194. */
  195. static int SDLCALL mouse_createFreeColorCursor(void *arg)
  196. {
  197. SDL_Surface *face;
  198. SDL_Cursor *cursor;
  199. /* Get sample surface */
  200. face = SDLTest_ImageFace();
  201. SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
  202. if (face == NULL) {
  203. return TEST_ABORTED;
  204. }
  205. /* Create a color cursor from surface */
  206. cursor = SDL_CreateColorCursor(face, 0, 0);
  207. SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
  208. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
  209. if (cursor == NULL) {
  210. SDL_DestroySurface(face);
  211. return TEST_ABORTED;
  212. }
  213. /* Free cursor again */
  214. SDLTest_AssertPass("About to call SDL_DestroyCursor()");
  215. SDL_DestroyCursor(cursor);
  216. SDLTest_AssertPass("Call to SDL_DestroyCursor()");
  217. /* Clean up */
  218. SDL_DestroySurface(face);
  219. return TEST_COMPLETED;
  220. }
  221. /* Helper that changes cursor visibility */
  222. static void changeCursorVisibility(bool state)
  223. {
  224. bool newState;
  225. if (state) {
  226. SDL_ShowCursor();
  227. } else {
  228. SDL_HideCursor();
  229. }
  230. SDLTest_AssertPass("Call to %s", state ? "SDL_ShowCursor()" : "SDL_HideCursor()");
  231. newState = SDL_CursorVisible();
  232. SDLTest_AssertPass("Call to SDL_CursorVisible()");
  233. SDLTest_AssertCheck(state == newState, "Validate new state, expected: %s, got: %s",
  234. state ? "true" : "false",
  235. newState ? "true" : "false");
  236. }
  237. /**
  238. * Check call to SDL_ShowCursor
  239. *
  240. * \sa SDL_ShowCursor
  241. */
  242. static int SDLCALL mouse_showCursor(void *arg)
  243. {
  244. bool currentState;
  245. /* Get current state */
  246. currentState = SDL_CursorVisible();
  247. SDLTest_AssertPass("Call to SDL_CursorVisible()");
  248. if (currentState) {
  249. /* Hide the cursor, then show it again */
  250. changeCursorVisibility(false);
  251. changeCursorVisibility(true);
  252. } else {
  253. /* Show the cursor, then hide it again */
  254. changeCursorVisibility(true);
  255. changeCursorVisibility(false);
  256. }
  257. return TEST_COMPLETED;
  258. }
  259. /**
  260. * Check call to SDL_SetCursor
  261. *
  262. * \sa SDL_SetCursor
  263. */
  264. static int SDLCALL mouse_setCursor(void *arg)
  265. {
  266. SDL_Cursor *cursor;
  267. /* Create a cursor */
  268. cursor = initArrowCursor(g_mouseArrowData);
  269. SDLTest_AssertPass("Call to SDL_CreateCursor()");
  270. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
  271. if (cursor == NULL) {
  272. return TEST_ABORTED;
  273. }
  274. /* Set the arrow cursor */
  275. SDL_SetCursor(cursor);
  276. SDLTest_AssertPass("Call to SDL_SetCursor(cursor)");
  277. /* Force redraw */
  278. SDL_SetCursor(NULL);
  279. SDLTest_AssertPass("Call to SDL_SetCursor(NULL)");
  280. /* Free cursor again */
  281. SDLTest_AssertPass("About to call SDL_DestroyCursor()");
  282. SDL_DestroyCursor(cursor);
  283. SDLTest_AssertPass("Call to SDL_DestroyCursor()");
  284. return TEST_COMPLETED;
  285. }
  286. /**
  287. * Check call to SDL_GetCursor
  288. *
  289. * \sa SDL_GetCursor
  290. */
  291. static int SDLCALL mouse_getCursor(void *arg)
  292. {
  293. SDL_Cursor *cursor;
  294. /* Get current cursor */
  295. cursor = SDL_GetCursor();
  296. SDLTest_AssertPass("Call to SDL_GetCursor()");
  297. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");
  298. return TEST_COMPLETED;
  299. }
  300. #define MOUSE_TESTWINDOW_WIDTH 320
  301. #define MOUSE_TESTWINDOW_HEIGHT 200
  302. /**
  303. * Creates a test window
  304. */
  305. static SDL_Window *createMouseSuiteTestWindow(void)
  306. {
  307. int width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
  308. SDL_Window *window;
  309. window = SDL_CreateWindow("mousecreateMouseSuiteTestWindow", width, height, 0);
  310. SDLTest_AssertPass("SDL_CreateWindow()");
  311. SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
  312. return window;
  313. }
  314. /**
  315. * Destroy test window
  316. */
  317. static void destroyMouseSuiteTestWindow(SDL_Window *window)
  318. {
  319. if (window) {
  320. SDL_DestroyWindow(window);
  321. window = NULL;
  322. SDLTest_AssertPass("SDL_DestroyWindow()");
  323. }
  324. }
  325. /**
  326. * Check call to SDL_GetWindowRelativeMouseMode and SDL_SetWindowRelativeMouseMode
  327. *
  328. * \sa SDL_GetWindowRelativeMouseMode
  329. * \sa SDL_SetWindowRelativeMouseMode
  330. */
  331. static int SDLCALL mouse_getSetRelativeMouseMode(void *arg)
  332. {
  333. SDL_Window *window;
  334. int result;
  335. int i;
  336. bool initialState;
  337. bool currentState;
  338. /* Create test window */
  339. window = createMouseSuiteTestWindow();
  340. if (!window) {
  341. return TEST_ABORTED;
  342. }
  343. /* Capture original state so we can revert back to it later */
  344. initialState = SDL_GetWindowRelativeMouseMode(window);
  345. SDLTest_AssertPass("Call to SDL_GetWindowRelativeMouseMode(window)");
  346. /* Repeat twice to check D->D transition */
  347. for (i = 0; i < 2; i++) {
  348. /* Disable - should always be supported */
  349. result = SDL_SetWindowRelativeMouseMode(window, false);
  350. SDLTest_AssertPass("Call to SDL_SetWindowRelativeMouseMode(window, FALSE)");
  351. SDLTest_AssertCheck(result == true, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: true, got: %i", result);
  352. currentState = SDL_GetWindowRelativeMouseMode(window);
  353. SDLTest_AssertPass("Call to SDL_GetWindowRelativeMouseMode(window)");
  354. SDLTest_AssertCheck(currentState == false, "Validate current state is FALSE, got: %i", currentState);
  355. }
  356. /* Repeat twice to check D->E->E transition */
  357. for (i = 0; i < 2; i++) {
  358. /* Enable - may not be supported */
  359. result = SDL_SetWindowRelativeMouseMode(window, true);
  360. SDLTest_AssertPass("Call to SDL_SetWindowRelativeMouseMode(window, TRUE)");
  361. if (result != -1) {
  362. SDLTest_AssertCheck(result == true, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: true, got: %i", result);
  363. currentState = SDL_GetWindowRelativeMouseMode(window);
  364. SDLTest_AssertPass("Call to SDL_GetWindowRelativeMouseMode(window)");
  365. SDLTest_AssertCheck(currentState == true, "Validate current state is TRUE, got: %i", currentState);
  366. }
  367. }
  368. /* Disable to check E->D transition */
  369. result = SDL_SetWindowRelativeMouseMode(window, false);
  370. SDLTest_AssertPass("Call to SDL_SetWindowRelativeMouseMode(window, FALSE)");
  371. SDLTest_AssertCheck(result == true, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: true, got: %i", result);
  372. currentState = SDL_GetWindowRelativeMouseMode(window);
  373. SDLTest_AssertPass("Call to SDL_GetWindowRelativeMouseMode(window)");
  374. SDLTest_AssertCheck(currentState == false, "Validate current state is FALSE, got: %i", currentState);
  375. /* Revert to original state - ignore result */
  376. result = SDL_SetWindowRelativeMouseMode(window, initialState);
  377. /* Clean up test window */
  378. destroyMouseSuiteTestWindow(window);
  379. return TEST_COMPLETED;
  380. }
  381. /**
  382. * Check call to SDL_WarpMouseInWindow
  383. *
  384. * \sa SDL_WarpMouseInWindow
  385. */
  386. static int SDLCALL mouse_warpMouseInWindow(void *arg)
  387. {
  388. const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
  389. int numPositions = 6;
  390. float xPositions[6];
  391. float yPositions[6];
  392. float x, y;
  393. int i, j;
  394. SDL_Window *window;
  395. xPositions[0] = -1;
  396. xPositions[1] = 0;
  397. xPositions[2] = 1;
  398. xPositions[3] = (float)w - 1;
  399. xPositions[4] = (float)w;
  400. xPositions[5] = (float)w + 1;
  401. yPositions[0] = -1;
  402. yPositions[1] = 0;
  403. yPositions[2] = 1;
  404. yPositions[3] = (float)h - 1;
  405. yPositions[4] = (float)h;
  406. yPositions[5] = (float)h + 1;
  407. /* Create test window */
  408. window = createMouseSuiteTestWindow();
  409. if (!window) {
  410. return TEST_ABORTED;
  411. }
  412. /* Mouse to random position inside window */
  413. x = (float)SDLTest_RandomIntegerInRange(1, w - 1);
  414. y = (float)SDLTest_RandomIntegerInRange(1, h - 1);
  415. SDL_WarpMouseInWindow(window, x, y);
  416. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
  417. /* Same position again */
  418. SDL_WarpMouseInWindow(window, x, y);
  419. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
  420. /* Mouse to various boundary positions */
  421. for (i = 0; i < numPositions; i++) {
  422. for (j = 0; j < numPositions; j++) {
  423. x = xPositions[i];
  424. y = yPositions[j];
  425. SDL_WarpMouseInWindow(window, x, y);
  426. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
  427. /* TODO: add tracking of events and check that each call generates a mouse motion event */
  428. SDL_PumpEvents();
  429. SDLTest_AssertPass("SDL_PumpEvents()");
  430. }
  431. }
  432. /* Clean up test window */
  433. destroyMouseSuiteTestWindow(window);
  434. return TEST_COMPLETED;
  435. }
  436. /**
  437. * Check call to SDL_GetMouseFocus
  438. *
  439. * \sa SDL_GetMouseFocus
  440. */
  441. static int SDLCALL mouse_getMouseFocus(void *arg)
  442. {
  443. const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
  444. float x, y;
  445. SDL_Window *window;
  446. SDL_Window *focusWindow;
  447. const bool video_driver_is_wayland = !SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland");
  448. /* Get focus - focus non-deterministic */
  449. focusWindow = SDL_GetMouseFocus();
  450. SDLTest_AssertPass("SDL_GetMouseFocus()");
  451. /* Create test window */
  452. window = createMouseSuiteTestWindow();
  453. if (!window) {
  454. return TEST_ABORTED;
  455. }
  456. /* Wayland explicitly disallows warping the mouse pointer, so this test must be skipped. */
  457. if (!video_driver_is_wayland) {
  458. /* Mouse to random position inside window */
  459. x = (float)SDLTest_RandomIntegerInRange(1, w - 1);
  460. y = (float)SDLTest_RandomIntegerInRange(1, h - 1);
  461. SDL_WarpMouseInWindow(window, x, y);
  462. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
  463. /* Pump events to update focus state */
  464. SDL_Delay(100);
  465. SDL_PumpEvents();
  466. SDLTest_AssertPass("SDL_PumpEvents()");
  467. /* Get focus with explicit window setup - focus deterministic */
  468. focusWindow = SDL_GetMouseFocus();
  469. SDLTest_AssertPass("SDL_GetMouseFocus()");
  470. SDLTest_AssertCheck(focusWindow != NULL, "Check returned window value is not NULL");
  471. SDLTest_AssertCheck(focusWindow == window, "Check returned window value is test window");
  472. /* Mouse to random position outside window */
  473. x = (float)SDLTest_RandomIntegerInRange(-9, -1);
  474. y = (float)SDLTest_RandomIntegerInRange(-9, -1);
  475. SDL_WarpMouseInWindow(window, x, y);
  476. SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
  477. } else {
  478. SDLTest_Log("Skipping mouse warp focus tests: Wayland does not support warping the mouse pointer");
  479. }
  480. /* Clean up test window */
  481. destroyMouseSuiteTestWindow(window);
  482. /* Pump events to update focus state */
  483. SDL_PumpEvents();
  484. SDLTest_AssertPass("SDL_PumpEvents()");
  485. /* Get focus for non-existing window */
  486. focusWindow = SDL_GetMouseFocus();
  487. SDLTest_AssertPass("SDL_GetMouseFocus()");
  488. SDLTest_AssertCheck(focusWindow == NULL, "Check returned window value is NULL");
  489. return TEST_COMPLETED;
  490. }
  491. /**
  492. * Check call to SDL_GetDefaultCursor
  493. *
  494. * \sa SDL_GetDefaultCursor
  495. */
  496. static int SDLCALL mouse_getDefaultCursor(void *arg)
  497. {
  498. SDL_Cursor *cursor;
  499. /* Get current cursor */
  500. cursor = SDL_GetDefaultCursor();
  501. SDLTest_AssertPass("Call to SDL_GetDefaultCursor()");
  502. SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetDefaultCursor() is not NULL");
  503. return TEST_COMPLETED;
  504. }
  505. /**
  506. * Check call to SDL_GetGlobalMouseState
  507. *
  508. * \sa SDL_GetGlobalMouseState
  509. */
  510. static int SDLCALL mouse_getGlobalMouseState(void *arg)
  511. {
  512. float x;
  513. float y;
  514. SDL_MouseButtonFlags state;
  515. x = -FLT_MAX;
  516. y = -FLT_MAX;
  517. /* Get current cursor */
  518. state = SDL_GetGlobalMouseState(&x, &y);
  519. SDLTest_AssertPass("Call to SDL_GetGlobalMouseState()");
  520. SDLTest_AssertCheck(x > -FLT_MAX, "Validate that value of x is > -FLT_MAX, got: %.f", x);
  521. SDLTest_AssertCheck(y > -FLT_MAX, "Validate that value of y is > -FLT_MAX, got: %.f", y);
  522. SDLTest_AssertCheck(mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
  523. return TEST_COMPLETED;
  524. }
  525. /* ================= Test References ================== */
  526. /* Mouse test cases */
  527. static const SDLTest_TestCaseReference mouseTestGetMouseState = {
  528. mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED
  529. };
  530. static const SDLTest_TestCaseReference mouseTestGetRelativeMouseState = {
  531. mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED
  532. };
  533. static const SDLTest_TestCaseReference mouseTestCreateFreeCursor = {
  534. mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_DestroyCursor", TEST_ENABLED
  535. };
  536. static const SDLTest_TestCaseReference mouseTestShowCursor = {
  537. mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED
  538. };
  539. static const SDLTest_TestCaseReference mouseTestSetCursor = {
  540. mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED
  541. };
  542. static const SDLTest_TestCaseReference mouseTestGetCursor = {
  543. mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED
  544. };
  545. static const SDLTest_TestCaseReference mouseTestWarpMouseInWindow = {
  546. mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED
  547. };
  548. static const SDLTest_TestCaseReference mouseTestGetMouseFocus = {
  549. mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_GetMouseFocus", TEST_ENABLED
  550. };
  551. static const SDLTest_TestCaseReference mouseTestCreateFreeColorCursor = {
  552. mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_DestroyCursor", TEST_ENABLED
  553. };
  554. static const SDLTest_TestCaseReference mouseTestGetSetRelativeMouseMode = {
  555. mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetWindowRelativeMouseMode and SDL_SetWindowRelativeMouseMode", TEST_ENABLED
  556. };
  557. static const SDLTest_TestCaseReference mouseTestGetDefaultCursor = {
  558. mouse_getDefaultCursor, "mouse_getDefaultCursor", "Check call to SDL_GetDefaultCursor", TEST_ENABLED
  559. };
  560. static const SDLTest_TestCaseReference mouseTestGetGlobalMouseState = {
  561. mouse_getGlobalMouseState, "mouse_getGlobalMouseState", "Check call to SDL_GetGlobalMouseState", TEST_ENABLED
  562. };
  563. /* Sequence of Mouse test cases */
  564. static const SDLTest_TestCaseReference *mouseTests[] = {
  565. &mouseTestGetMouseState,
  566. &mouseTestGetRelativeMouseState,
  567. &mouseTestCreateFreeCursor,
  568. &mouseTestShowCursor,
  569. &mouseTestSetCursor,
  570. &mouseTestGetCursor,
  571. &mouseTestWarpMouseInWindow,
  572. &mouseTestGetMouseFocus,
  573. &mouseTestCreateFreeColorCursor,
  574. &mouseTestGetSetRelativeMouseMode,
  575. &mouseTestGetDefaultCursor,
  576. &mouseTestGetGlobalMouseState,
  577. NULL
  578. };
  579. /* Mouse test suite (global) */
  580. SDLTest_TestSuiteReference mouseTestSuite = {
  581. "Mouse",
  582. NULL,
  583. mouseTests,
  584. NULL
  585. };