mirror of https://github.com/encounter/SDL.git
Added a virtual joystick automated test
Useful to verify 4fa2653394
on a big-endian system
This commit is contained in:
parent
06c7d22653
commit
7e2a996958
|
@ -208,6 +208,7 @@
|
||||||
<ClCompile Include="..\..\..\test\testautomation_events.c" />
|
<ClCompile Include="..\..\..\test\testautomation_events.c" />
|
||||||
<ClCompile Include="..\..\..\test\testautomation_guid.c" />
|
<ClCompile Include="..\..\..\test\testautomation_guid.c" />
|
||||||
<ClCompile Include="..\..\..\test\testautomation_hints.c" />
|
<ClCompile Include="..\..\..\test\testautomation_hints.c" />
|
||||||
|
<ClCompile Include="..\..\..\test\testautomation_joystick.c" />
|
||||||
<ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
|
<ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
|
||||||
<ClCompile Include="..\..\..\test\testautomation_main.c" />
|
<ClCompile Include="..\..\..\test\testautomation_main.c" />
|
||||||
<ClCompile Include="..\..\..\test\testautomation_math.c" />
|
<ClCompile Include="..\..\..\test\testautomation_math.c" />
|
||||||
|
|
|
@ -138,8 +138,11 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
|
||||||
$(srcdir)/testautomation_clipboard.c \
|
$(srcdir)/testautomation_clipboard.c \
|
||||||
$(srcdir)/testautomation_events.c \
|
$(srcdir)/testautomation_events.c \
|
||||||
$(srcdir)/testautomation_guid.c \
|
$(srcdir)/testautomation_guid.c \
|
||||||
|
$(srcdir)/testautomation_hints.c \
|
||||||
|
$(srcdir)/testautomation_joystick.c \
|
||||||
$(srcdir)/testautomation_keyboard.c \
|
$(srcdir)/testautomation_keyboard.c \
|
||||||
$(srcdir)/testautomation_main.c \
|
$(srcdir)/testautomation_main.c \
|
||||||
|
$(srcdir)/testautomation_math.c \
|
||||||
$(srcdir)/testautomation_mouse.c \
|
$(srcdir)/testautomation_mouse.c \
|
||||||
$(srcdir)/testautomation_pixels.c \
|
$(srcdir)/testautomation_pixels.c \
|
||||||
$(srcdir)/testautomation_platform.c \
|
$(srcdir)/testautomation_platform.c \
|
||||||
|
@ -151,9 +154,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
|
||||||
$(srcdir)/testautomation_surface.c \
|
$(srcdir)/testautomation_surface.c \
|
||||||
$(srcdir)/testautomation_syswm.c \
|
$(srcdir)/testautomation_syswm.c \
|
||||||
$(srcdir)/testautomation_timer.c \
|
$(srcdir)/testautomation_timer.c \
|
||||||
$(srcdir)/testautomation_video.c \
|
$(srcdir)/testautomation_video.c
|
||||||
$(srcdir)/testautomation_hints.c \
|
|
||||||
$(srcdir)/testautomation_math.c
|
|
||||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||||
|
|
||||||
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c $(srcdir)/testutils.c
|
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c $(srcdir)/testutils.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
|
||||||
|
};
|
|
@ -13,8 +13,11 @@ extern SDLTest_TestSuiteReference audioTestSuite;
|
||||||
extern SDLTest_TestSuiteReference clipboardTestSuite;
|
extern SDLTest_TestSuiteReference clipboardTestSuite;
|
||||||
extern SDLTest_TestSuiteReference eventsTestSuite;
|
extern SDLTest_TestSuiteReference eventsTestSuite;
|
||||||
extern SDLTest_TestSuiteReference guidTestSuite;
|
extern SDLTest_TestSuiteReference guidTestSuite;
|
||||||
|
extern SDLTest_TestSuiteReference hintsTestSuite;
|
||||||
|
extern SDLTest_TestSuiteReference joystickTestSuite;
|
||||||
extern SDLTest_TestSuiteReference keyboardTestSuite;
|
extern SDLTest_TestSuiteReference keyboardTestSuite;
|
||||||
extern SDLTest_TestSuiteReference mainTestSuite;
|
extern SDLTest_TestSuiteReference mainTestSuite;
|
||||||
|
extern SDLTest_TestSuiteReference mathTestSuite;
|
||||||
extern SDLTest_TestSuiteReference mouseTestSuite;
|
extern SDLTest_TestSuiteReference mouseTestSuite;
|
||||||
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
||||||
extern SDLTest_TestSuiteReference platformTestSuite;
|
extern SDLTest_TestSuiteReference platformTestSuite;
|
||||||
|
@ -27,8 +30,6 @@ extern SDLTest_TestSuiteReference surfaceTestSuite;
|
||||||
extern SDLTest_TestSuiteReference syswmTestSuite;
|
extern SDLTest_TestSuiteReference syswmTestSuite;
|
||||||
extern SDLTest_TestSuiteReference timerTestSuite;
|
extern SDLTest_TestSuiteReference timerTestSuite;
|
||||||
extern SDLTest_TestSuiteReference videoTestSuite;
|
extern SDLTest_TestSuiteReference videoTestSuite;
|
||||||
extern SDLTest_TestSuiteReference hintsTestSuite;
|
|
||||||
extern SDLTest_TestSuiteReference mathTestSuite;
|
|
||||||
|
|
||||||
/* All test suites */
|
/* All test suites */
|
||||||
SDLTest_TestSuiteReference *testSuites[] = {
|
SDLTest_TestSuiteReference *testSuites[] = {
|
||||||
|
@ -36,8 +37,11 @@ SDLTest_TestSuiteReference *testSuites[] = {
|
||||||
&clipboardTestSuite,
|
&clipboardTestSuite,
|
||||||
&eventsTestSuite,
|
&eventsTestSuite,
|
||||||
&guidTestSuite,
|
&guidTestSuite,
|
||||||
|
&hintsTestSuite,
|
||||||
|
&joystickTestSuite,
|
||||||
&keyboardTestSuite,
|
&keyboardTestSuite,
|
||||||
&mainTestSuite,
|
&mainTestSuite,
|
||||||
|
&mathTestSuite,
|
||||||
&mouseTestSuite,
|
&mouseTestSuite,
|
||||||
&pixelsTestSuite,
|
&pixelsTestSuite,
|
||||||
&platformTestSuite,
|
&platformTestSuite,
|
||||||
|
@ -50,8 +54,6 @@ SDLTest_TestSuiteReference *testSuites[] = {
|
||||||
&syswmTestSuite,
|
&syswmTestSuite,
|
||||||
&timerTestSuite,
|
&timerTestSuite,
|
||||||
&videoTestSuite,
|
&videoTestSuite,
|
||||||
&hintsTestSuite,
|
|
||||||
&mathTestSuite,
|
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,16 +49,18 @@ needs_display = &
|
||||||
TESTS = $(noninteractive) $(needs_audio) $(needs_display)
|
TESTS = $(noninteractive) $(needs_audio) $(needs_display)
|
||||||
|
|
||||||
# testautomation sources
|
# testautomation sources
|
||||||
TASRCS = testautomation.c testautomation_audio.c testautomation_clipboard.c &
|
TASRCS = testautomation.c &
|
||||||
testautomation_events.c testautomation_hints.c &
|
testautomation_audio.c testautomation_clipboard.c &
|
||||||
testautomation_keyboard.c testautomation_main.c &
|
testautomation_events.c testautomation_guid.c &
|
||||||
testautomation_mouse.c testautomation_pixels.c &
|
testautomation_hints.c testautomation_joystick.c &
|
||||||
testautomation_platform.c testautomation_rect.c &
|
testautomation_keyboard.c testautomation_main.c &
|
||||||
testautomation_render.c testautomation_rwops.c &
|
testautomation_math.c testautomation_mouse.c &
|
||||||
testautomation_sdltest.c testautomation_stdlib.c &
|
testautomation_pixels.c testautomation_platform.c &
|
||||||
testautomation_surface.c testautomation_syswm.c &
|
testautomation_rect.c testautomation_render.c &
|
||||||
testautomation_timer.c testautomation_video.c &
|
testautomation_rwops.c testautomation_sdltest.c &
|
||||||
testautomation_math.c testautomation_guid.c
|
testautomation_stdlib.c testautomation_surface.c &
|
||||||
|
testautomation_syswm.c testautomation_timer.c &
|
||||||
|
testautomation_video.c
|
||||||
|
|
||||||
OBJS = $(TARGETS:.exe=.obj)
|
OBJS = $(TARGETS:.exe=.obj)
|
||||||
COBJS = $(CSRCS:.c=.obj)
|
COBJS = $(CSRCS:.c=.obj)
|
||||||
|
|
Loading…
Reference in New Issue