testautomation_mouse.c 21 KB

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