Added a virtual joystick automated test

Useful to verify 4fa2653394 on a big-endian system
This commit is contained in:
Sam Lantinga 2022-07-13 08:57:40 -07:00
parent 06c7d22653
commit 7e2a996958
5 changed files with 114 additions and 18 deletions

View File

@ -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>
</Project>

View File

@ -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

View File

@ -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
};

View File

@ -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
};

View File

@ -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)