Added a virtual joystick automated test Useful to verify https://github.com/libsdl-org/SDL/commit/4fa2653394150140c4d69cf66a78cd83e1175f99 on a big-endian system
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
diff --git a/VisualC/tests/testautomation/testautomation.vcxproj b/VisualC/tests/testautomation/testautomation.vcxproj
index 0acc54a..d58dc0b 100644
--- a/VisualC/tests/testautomation/testautomation.vcxproj
+++ b/VisualC/tests/testautomation/testautomation.vcxproj
@@ -208,6 +208,7 @@
<ClCompile Include="..\..\..\test\testautomation_events.c" />
<ClCompile Include="..\..\..\test\testautomation_guid.c" />
<ClCompile Include="..\..\..\test\testautomation_hints.c" />
+ <ClCompile Include="..\..\..\test\testautomation_joystick.c" />
<ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
<ClCompile Include="..\..\..\test\testautomation_main.c" />
<ClCompile Include="..\..\..\test\testautomation_math.c" />
@@ -230,4 +231,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/test/Makefile.in b/test/Makefile.in
index 435e50f..93df636 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -138,8 +138,11 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_clipboard.c \
$(srcdir)/testautomation_events.c \
$(srcdir)/testautomation_guid.c \
+ $(srcdir)/testautomation_hints.c \
+ $(srcdir)/testautomation_joystick.c \
$(srcdir)/testautomation_keyboard.c \
$(srcdir)/testautomation_main.c \
+ $(srcdir)/testautomation_math.c \
$(srcdir)/testautomation_mouse.c \
$(srcdir)/testautomation_pixels.c \
$(srcdir)/testautomation_platform.c \
@@ -151,9 +154,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_surface.c \
$(srcdir)/testautomation_syswm.c \
$(srcdir)/testautomation_timer.c \
- $(srcdir)/testautomation_video.c \
- $(srcdir)/testautomation_hints.c \
- $(srcdir)/testautomation_math.c
+ $(srcdir)/testautomation_video.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c $(srcdir)/testutils.c
diff --git a/test/testautomation_joystick.c b/test/testautomation_joystick.c
new file mode 100644
index 0000000..198128e
--- /dev/null
+++ b/test/testautomation_joystick.c
@@ -0,0 +1,90 @@
+/**
+ * Joystick test suite
+ */
+
+#include "SDL.h"
+#include "SDL_test.h"
+#include "../src/joystick/usb_ids.h"
+
+/* ================= Test Case Implementation ================== */
+
+/* Test case functions */
+
+/**
+ * @brief Check virtual joystick creation
+ *
+ * @sa SDL_JoystickAttachVirtualEx
+ */
+static int
+TestVirtualJoystick(void *arg)
+{
+ SDL_VirtualJoystickDesc desc;
+ SDL_Joystick *joystick = NULL;
+ int device_index;
+
+ SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
+
+ SDL_zero(desc);
+ desc.version = SDL_VIRTUAL_JOYSTICK_DESC_VERSION;
+ desc.type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
+ desc.naxes = SDL_CONTROLLER_AXIS_MAX;
+ desc.nbuttons = SDL_CONTROLLER_BUTTON_MAX;
+ desc.vendor_id = USB_VENDOR_NVIDIA;
+ desc.product_id = USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER;
+ desc.name = "Virtual NVIDIA SHIELD Controller";
+ device_index = SDL_JoystickAttachVirtualEx(&desc);
+ SDLTest_AssertCheck(device_index >= 0, "SDL_JoystickAttachVirtualEx()");
+ SDLTest_AssertCheck(SDL_JoystickIsVirtual(device_index), "SDL_JoystickIsVirtual()");
+ if (device_index >= 0) {
+ joystick = SDL_JoystickOpen(device_index);
+ SDLTest_AssertCheck(joystick != NULL, "SDL_JoystickOpen()");
+ if (joystick) {
+ SDLTest_AssertCheck(SDL_strcmp(SDL_JoystickName(joystick), desc.name) == 0, "SDL_JoystickName()");
+ SDLTest_AssertCheck(SDL_JoystickGetVendor(joystick) == desc.vendor_id, "SDL_JoystickGetVendor()");
+ SDLTest_AssertCheck(SDL_JoystickGetProduct(joystick) == desc.product_id, "SDL_JoystickGetProduct()");
+ SDLTest_AssertCheck(SDL_JoystickGetProductVersion(joystick) == 0, "SDL_JoystickGetProductVersion()");
+ SDLTest_AssertCheck(SDL_JoystickGetFirmwareVersion(joystick) == 0, "SDL_JoystickGetFirmwareVersion()");
+ SDLTest_AssertCheck(SDL_JoystickGetSerial(joystick) == NULL, "SDL_JoystickGetSerial()");
+ SDLTest_AssertCheck(SDL_JoystickGetType(joystick) == desc.type, "SDL_JoystickGetType()");
+ SDLTest_AssertCheck(SDL_JoystickNumAxes(joystick) == desc.naxes, "SDL_JoystickNumAxes()");
+ SDLTest_AssertCheck(SDL_JoystickNumBalls(joystick) == 0, "SDL_JoystickNumBalls()");
+ SDLTest_AssertCheck(SDL_JoystickNumHats(joystick) == desc.nhats, "SDL_JoystickNumHats()");
+ SDLTest_AssertCheck(SDL_JoystickNumButtons(joystick) == desc.nbuttons, "SDL_JoystickNumButtons()");
+
+ SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_PRESSED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_PRESSED)");
+ SDL_JoystickUpdate();
+ SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED");
+ SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_RELEASED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_RELEASED)");
+ SDL_JoystickUpdate();
+ SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED");
+
+ SDL_JoystickClose(joystick);
+ }
+ SDLTest_AssertCheck(SDL_JoystickDetachVirtual(device_index) == 0, "SDL_JoystickDetachVirtual()");
+ }
+ SDLTest_AssertCheck(!SDL_JoystickIsVirtual(device_index), "!SDL_JoystickIsVirtual()");
+
+ SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
+
+ return TEST_COMPLETED;
+}
+
+/* ================= Test References ================== */
+
+/* Joystick routine test cases */
+static const SDLTest_TestCaseReference joystickTest1 =
+ { (SDLTest_TestCaseFp)TestVirtualJoystick, "TestVirtualJoystick", "Test virtual joystick functionality", TEST_ENABLED };
+
+/* Sequence of Joystick routine test cases */
+static const SDLTest_TestCaseReference *joystickTests[] = {
+ &joystickTest1,
+ NULL
+};
+
+/* Joystick routine test suite (global) */
+SDLTest_TestSuiteReference joystickTestSuite = {
+ "Joystick",
+ NULL,
+ joystickTests,
+ NULL
+};
diff --git a/test/testautomation_suites.h b/test/testautomation_suites.h
index a03cdbc..7fcce1b 100644
--- a/test/testautomation_suites.h
+++ b/test/testautomation_suites.h
@@ -13,8 +13,11 @@ extern SDLTest_TestSuiteReference audioTestSuite;
extern SDLTest_TestSuiteReference clipboardTestSuite;
extern SDLTest_TestSuiteReference eventsTestSuite;
extern SDLTest_TestSuiteReference guidTestSuite;
+extern SDLTest_TestSuiteReference hintsTestSuite;
+extern SDLTest_TestSuiteReference joystickTestSuite;
extern SDLTest_TestSuiteReference keyboardTestSuite;
extern SDLTest_TestSuiteReference mainTestSuite;
+extern SDLTest_TestSuiteReference mathTestSuite;
extern SDLTest_TestSuiteReference mouseTestSuite;
extern SDLTest_TestSuiteReference pixelsTestSuite;
extern SDLTest_TestSuiteReference platformTestSuite;
@@ -27,8 +30,6 @@ extern SDLTest_TestSuiteReference surfaceTestSuite;
extern SDLTest_TestSuiteReference syswmTestSuite;
extern SDLTest_TestSuiteReference timerTestSuite;
extern SDLTest_TestSuiteReference videoTestSuite;
-extern SDLTest_TestSuiteReference hintsTestSuite;
-extern SDLTest_TestSuiteReference mathTestSuite;
/* All test suites */
SDLTest_TestSuiteReference *testSuites[] = {
@@ -36,8 +37,11 @@ SDLTest_TestSuiteReference *testSuites[] = {
&clipboardTestSuite,
&eventsTestSuite,
&guidTestSuite,
+ &hintsTestSuite,
+ &joystickTestSuite,
&keyboardTestSuite,
&mainTestSuite,
+ &mathTestSuite,
&mouseTestSuite,
&pixelsTestSuite,
&platformTestSuite,
@@ -50,8 +54,6 @@ SDLTest_TestSuiteReference *testSuites[] = {
&syswmTestSuite,
&timerTestSuite,
&videoTestSuite,
- &hintsTestSuite,
- &mathTestSuite,
NULL
};
diff --git a/test/watcom.mif b/test/watcom.mif
index 91036f9..6ddab0e 100644
--- a/test/watcom.mif
+++ b/test/watcom.mif
@@ -49,16 +49,18 @@ needs_display = &
TESTS = $(noninteractive) $(needs_audio) $(needs_display)
# testautomation sources
-TASRCS = testautomation.c testautomation_audio.c testautomation_clipboard.c &
- testautomation_events.c testautomation_hints.c &
- testautomation_keyboard.c testautomation_main.c &
- testautomation_mouse.c testautomation_pixels.c &
- testautomation_platform.c testautomation_rect.c &
- testautomation_render.c testautomation_rwops.c &
- testautomation_sdltest.c testautomation_stdlib.c &
- testautomation_surface.c testautomation_syswm.c &
- testautomation_timer.c testautomation_video.c &
- testautomation_math.c testautomation_guid.c
+TASRCS = testautomation.c &
+ testautomation_audio.c testautomation_clipboard.c &
+ testautomation_events.c testautomation_guid.c &
+ testautomation_hints.c testautomation_joystick.c &
+ testautomation_keyboard.c testautomation_main.c &
+ testautomation_math.c testautomation_mouse.c &
+ testautomation_pixels.c testautomation_platform.c &
+ testautomation_rect.c testautomation_render.c &
+ testautomation_rwops.c testautomation_sdltest.c &
+ testautomation_stdlib.c testautomation_surface.c &
+ testautomation_syswm.c testautomation_timer.c &
+ testautomation_video.c
OBJS = $(TARGETS:.exe=.obj)
COBJS = $(CSRCS:.c=.obj)