testautomation_joystick.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /**
  2. * Joystick test suite
  3. */
  4. #include <SDL3/SDL.h>
  5. #include <SDL3/SDL_test.h>
  6. #include "../src/joystick/usb_ids.h"
  7. #include "testautomation_suites.h"
  8. /* ================= Test Case Implementation ================== */
  9. /* Fixture */
  10. /* Create a 32-bit writable surface for blitting tests */
  11. static void SDLCALL joystickSetUp(void **arg)
  12. {
  13. SDL_InitSubSystem(SDL_INIT_GAMEPAD);
  14. SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
  15. }
  16. static void SDLCALL joystickTearDown(void *arg)
  17. {
  18. SDL_ResetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);
  19. SDL_QuitSubSystem(SDL_INIT_GAMEPAD);
  20. }
  21. /* Test case functions */
  22. /**
  23. * Check virtual joystick creation
  24. *
  25. * \sa SDL_AttachVirtualJoystick
  26. */
  27. static int SDLCALL joystick_testVirtual(void *arg)
  28. {
  29. SDL_VirtualJoystickDesc desc;
  30. SDL_Joystick *joystick = NULL;
  31. SDL_Gamepad *gamepad = NULL;
  32. SDL_JoystickID device_id;
  33. SDL_INIT_INTERFACE(&desc);
  34. desc.type = SDL_JOYSTICK_TYPE_GAMEPAD;
  35. desc.naxes = SDL_GAMEPAD_AXIS_COUNT;
  36. desc.nbuttons = SDL_GAMEPAD_BUTTON_COUNT;
  37. desc.vendor_id = USB_VENDOR_NVIDIA;
  38. desc.product_id = USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V103;
  39. desc.name = "Virtual NVIDIA SHIELD Controller";
  40. device_id = SDL_AttachVirtualJoystick(&desc);
  41. SDLTest_AssertCheck(device_id > 0, "SDL_AttachVirtualJoystick() -> %" SDL_PRIs32 " (expected > 0)", device_id);
  42. SDLTest_AssertCheck(SDL_IsJoystickVirtual(device_id), "SDL_IsJoystickVirtual()");
  43. if (device_id > 0) {
  44. joystick = SDL_OpenJoystick(device_id);
  45. SDLTest_AssertCheck(joystick != NULL, "SDL_OpenJoystick()");
  46. if (joystick) {
  47. {
  48. const char *dname = SDL_GetJoystickName(joystick);
  49. SDLTest_AssertCheck(SDL_strcmp(dname, desc.name) == 0, "SDL_GetJoystickName() -> \"%s\" (expected \"%s\")", dname, desc.name);
  50. }
  51. {
  52. Uint16 vendor_id = SDL_GetJoystickVendor(joystick);
  53. SDLTest_AssertCheck(vendor_id == desc.vendor_id, "SDL_GetJoystickVendor() -> 0x%04x (expected 0x%04x)", vendor_id, desc.vendor_id);
  54. }
  55. {
  56. Uint16 product_id = SDL_GetJoystickProduct(joystick);
  57. SDLTest_AssertCheck(product_id == desc.product_id, "SDL_GetJoystickProduct() -> 0x%04x (expected 0x%04x)", product_id, desc.product_id);
  58. }
  59. {
  60. Uint16 product_version = SDL_GetJoystickProductVersion(joystick);
  61. SDLTest_AssertCheck(product_version == 0, "SDL_GetJoystickProductVersion() -> 0x%04x (expected 0x%04x)", product_version, 0);
  62. }
  63. {
  64. Uint16 firmware_Version = SDL_GetJoystickFirmwareVersion(joystick);
  65. SDLTest_AssertCheck(firmware_Version == 0, "SDL_GetJoystickFirmwareVersion() -> 0x%04x (expected 0x%04x)", firmware_Version, 0);
  66. }
  67. {
  68. const char *serial = SDL_GetJoystickSerial(joystick);
  69. SDLTest_AssertCheck(serial == NULL, "SDL_GetJoystickSerial() -> %s (expected %s)", serial, "(null)");
  70. }
  71. {
  72. SDL_JoystickType type = SDL_GetJoystickType(joystick);
  73. SDLTest_AssertCheck(type == desc.type, "SDL_GetJoystickType() -> %d (expected %d)", type, desc.type);
  74. }
  75. {
  76. Uint16 naxes = SDL_GetNumJoystickAxes(joystick);
  77. SDLTest_AssertCheck(naxes == desc.naxes, "SDL_GetNumJoystickAxes() -> 0x%04x (expected 0x%04x)", naxes, desc.naxes);
  78. }
  79. {
  80. int nballs = SDL_GetNumJoystickBalls(joystick);
  81. SDLTest_AssertCheck(nballs == 0, "SDL_GetNumJoystickBalls() -> %d (expected %d)", nballs, 0);
  82. }
  83. {
  84. int nhats = SDL_GetNumJoystickHats(joystick);
  85. SDLTest_AssertCheck(nhats == desc.nhats, "SDL_GetNumJoystickHats() -> %d (expected %d)", nhats, desc.nhats);
  86. }
  87. {
  88. int nbuttons = SDL_GetNumJoystickButtons(joystick);
  89. SDLTest_AssertCheck(nbuttons == desc.nbuttons, "SDL_GetNumJoystickButtons() -> %d (expected %d)", nbuttons, desc.nbuttons);
  90. }
  91. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, true), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, true)");
  92. SDL_UpdateJoysticks();
  93. SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == true, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == true");
  94. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, false), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, false)");
  95. SDL_UpdateJoysticks();
  96. SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == false, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == false");
  97. gamepad = SDL_OpenGamepad(SDL_GetJoystickID(joystick));
  98. SDLTest_AssertCheck(gamepad != NULL, "SDL_OpenGamepad() succeeded");
  99. if (gamepad) {
  100. {
  101. const char *name = SDL_GetGamepadName(gamepad);
  102. SDLTest_AssertCheck(name && SDL_strcmp(name, desc.name) == 0, "SDL_GetGamepadName() -> \"%s\" (expected \"%s\")", name, desc.name);
  103. }
  104. {
  105. Uint16 vendor_id = SDL_GetGamepadVendor(gamepad);
  106. SDLTest_AssertCheck(vendor_id == desc.vendor_id, "SDL_GetGamepadVendor() -> 0x%04x (expected 0x%04x)", vendor_id, desc.vendor_id);
  107. }
  108. {
  109. Uint16 product_id = SDL_GetGamepadProduct(gamepad);
  110. SDLTest_AssertCheck(product_id == desc.product_id, "SDL_GetGamepadProduct() -> 0x%04x (expected 0x%04x)", product_id, desc.product_id);
  111. }
  112. /* Set an explicit mapping with a different name */
  113. SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff008316550900001072000000007601,Virtual Gamepad,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
  114. {
  115. const char *name = SDL_GetGamepadName(gamepad);
  116. SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Gamepad") == 0, "SDL_GetGamepadName() ->\"%s\" (expected \"%s\")", name, "Virtual Gamepad");
  117. }
  118. {
  119. SDL_GamepadButtonLabel label = SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH);
  120. SDLTest_AssertCheck(label == SDL_GAMEPAD_BUTTON_LABEL_A, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) -> %d (expected %d [%s])",
  121. label, SDL_GAMEPAD_BUTTON_LABEL_A, "SDL_GAMEPAD_BUTTON_LABEL_A");
  122. }
  123. SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A");
  124. /* Set the south button and verify that the gamepad responds */
  125. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, true), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, true)");
  126. SDL_UpdateJoysticks();
  127. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == true, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == true");
  128. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, false), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, false)");
  129. SDL_UpdateJoysticks();
  130. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == false, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == false");
  131. /* Set an explicit mapping with legacy GameCube style buttons */
  132. SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff008316550900001072000000007601,Virtual Nintendo GameCube,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,hint:SDL_GAMECONTROLLER_USE_GAMECUBE_LABELS:=1,");
  133. {
  134. const char *name = SDL_GetGamepadName(gamepad);
  135. SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Nintendo GameCube") == 0, "SDL_GetGamepadName() -> \"%s\" (expected \"%s\")", name, "Virtual Nintendo GameCube");
  136. }
  137. SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_EAST) == SDL_GAMEPAD_BUTTON_LABEL_X, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_EAST) == SDL_GAMEPAD_BUTTON_LABEL_X");
  138. /* Set the east button and verify that the gamepad responds, mapping "B" to the west button */
  139. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_EAST, true), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_EAST, true)");
  140. SDL_UpdateJoysticks();
  141. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_WEST) == true, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_WEST) == true");
  142. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_EAST, false), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_EAST, false)");
  143. SDL_UpdateJoysticks();
  144. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_WEST) == false, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_WEST) == false");
  145. /* Set an explicit mapping with legacy Nintendo style buttons */
  146. SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff008316550900001072000000007601,Virtual Nintendo Gamepad,a:b1,b:b0,x:b3,y:b2,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,");
  147. {
  148. const char *name = SDL_GetGamepadName(gamepad);
  149. SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Nintendo Gamepad") == 0, "SDL_GetGamepadName() -> \"%s\" (expected \"%s\")", name, "Virtual Nintendo Gamepad");
  150. }
  151. SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B");
  152. /* Set the south button and verify that the gamepad responds */
  153. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, true), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, true)");
  154. SDL_UpdateJoysticks();
  155. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == true, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == true");
  156. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, false), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, false)");
  157. SDL_UpdateJoysticks();
  158. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == false, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == false");
  159. /* Set an explicit mapping with PS4 style buttons */
  160. SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff008316550900001072000000007601,Virtual PS4 Gamepad,type:ps4,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
  161. {
  162. const char *name = SDL_GetGamepadName(gamepad);
  163. SDLTest_AssertCheck(SDL_strcmp(name, "Virtual PS4 Gamepad") == 0, "SDL_GetGamepadName() -> \"%s\" (expected \"%s\")", name, "Virtual PS4 Gamepad");
  164. }
  165. SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS");
  166. /* Set the south button and verify that the gamepad responds */
  167. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, true), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, true)");
  168. SDL_UpdateJoysticks();
  169. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == true, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == true");
  170. SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, false), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, false)");
  171. SDL_UpdateJoysticks();
  172. SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == false, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == false");
  173. SDL_CloseGamepad(gamepad);
  174. }
  175. SDL_CloseJoystick(joystick);
  176. }
  177. SDLTest_AssertCheck(SDL_DetachVirtualJoystick(device_id), "SDL_DetachVirtualJoystick()");
  178. }
  179. SDLTest_AssertCheck(!SDL_IsJoystickVirtual(device_id), "!SDL_IsJoystickVirtual()");
  180. return TEST_COMPLETED;
  181. }
  182. /**
  183. * Check gamepad mappings
  184. */
  185. static int SDLCALL joystick_testMappings(void *arg)
  186. {
  187. SDL_VirtualJoystickDesc desc;
  188. SDL_Gamepad *gamepad = NULL;
  189. SDL_JoystickID device_id;
  190. /* Add a mapping for the virtual controller in advance */
  191. SDL_AddGamepadMapping("ff000000550900001472000000007601,Virtual Gamepad,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
  192. SDL_INIT_INTERFACE(&desc);
  193. desc.type = SDL_JOYSTICK_TYPE_GAMEPAD;
  194. desc.naxes = SDL_GAMEPAD_AXIS_COUNT;
  195. desc.nbuttons = SDL_GAMEPAD_BUTTON_COUNT;
  196. desc.vendor_id = USB_VENDOR_NVIDIA;
  197. desc.product_id = USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104;
  198. desc.name = "Virtual NVIDIA SHIELD Controller";
  199. device_id = SDL_AttachVirtualJoystick(&desc);
  200. SDLTest_AssertCheck(device_id > 0, "SDL_AttachVirtualJoystick() -> %" SDL_PRIs32 " (expected > 0)", device_id);
  201. SDLTest_AssertCheck(SDL_IsJoystickVirtual(device_id), "SDL_IsJoystickVirtual()");
  202. gamepad = SDL_OpenGamepad(device_id);
  203. SDLTest_AssertCheck(gamepad != NULL, "SDL_OpenGamepad() succeeded");
  204. if (gamepad) {
  205. /* Verify that the gamepad picked up the predefined mapping */
  206. {
  207. const char *name = SDL_GetGamepadName(gamepad);
  208. SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Gamepad") == 0, "SDL_GetGamepadName() ->\"%s\" (expected \"%s\")", name, "Virtual Gamepad");
  209. }
  210. /* Verify that the gamepad picks up a new mapping with no CRC */
  211. SDL_AddGamepadMapping("ff000000550900001472000000007601,Virtual Gamepad V2,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
  212. {
  213. const char *name = SDL_GetGamepadName(gamepad);
  214. SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Gamepad V2") == 0, "SDL_GetGamepadName() ->\"%s\" (expected \"%s\")", name, "Virtual Gamepad V2");
  215. }
  216. /* Verify that the gamepad picks up a new mapping with valid CRC */
  217. SDL_AddGamepadMapping("ff008316550900001472000000007601,Virtual Gamepad V3,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
  218. {
  219. const char *name = SDL_GetGamepadName(gamepad);
  220. SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Gamepad V3") == 0, "SDL_GetGamepadName() ->\"%s\" (expected \"%s\")", name, "Virtual Gamepad V3");
  221. }
  222. SDL_CloseGamepad(gamepad);
  223. }
  224. SDLTest_AssertCheck(SDL_DetachVirtualJoystick(device_id), "SDL_DetachVirtualJoystick()");
  225. /* Try matching mappings with a new CRC */
  226. desc.name = "Virtual NVIDIA SHIELD Controller V2";
  227. device_id = SDL_AttachVirtualJoystick(&desc);
  228. SDLTest_AssertCheck(device_id > 0, "SDL_AttachVirtualJoystick() -> %" SDL_PRIs32 " (expected > 0)", device_id);
  229. SDLTest_AssertCheck(SDL_IsJoystickVirtual(device_id), "SDL_IsJoystickVirtual()");
  230. gamepad = SDL_OpenGamepad(device_id);
  231. SDLTest_AssertCheck(gamepad != NULL, "SDL_OpenGamepad() succeeded");
  232. if (gamepad) {
  233. {
  234. const char *name = SDL_GetGamepadName(gamepad);
  235. SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Gamepad V2") == 0, "SDL_GetGamepadName() ->\"%s\" (expected \"%s\")", name, "Virtual Gamepad V2");
  236. }
  237. SDL_CloseGamepad(gamepad);
  238. }
  239. SDLTest_AssertCheck(SDL_DetachVirtualJoystick(device_id), "SDL_DetachVirtualJoystick()");
  240. return TEST_COMPLETED;
  241. }
  242. /* ================= Test References ================== */
  243. /* Joystick routine test cases */
  244. static const SDLTest_TestCaseReference joystickTest1 = {
  245. joystick_testVirtual, "joystick_testVirtual", "Test virtual joystick functionality", TEST_ENABLED
  246. };
  247. static const SDLTest_TestCaseReference joystickTest2 = {
  248. joystick_testMappings, "joystick_testMappings", "Test gamepad mapping functionality", TEST_ENABLED
  249. };
  250. /* Sequence of Joystick routine test cases */
  251. static const SDLTest_TestCaseReference *joystickTests[] = {
  252. &joystickTest1,
  253. &joystickTest2,
  254. NULL
  255. };
  256. /* Joystick routine test suite (global) */
  257. SDLTest_TestSuiteReference joystickTestSuite = {
  258. "Joystick",
  259. joystickSetUp,
  260. joystickTests,
  261. joystickTearDown
  262. };