testautomation_mouse.c 21 KB

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