2 * The Wine project - Xinput Joystick Library
3 * Copyright 2008 Andrew Fenn
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 static DWORD (WINAPI
*pXInputGetState
)(DWORD
, XINPUT_STATE
*);
27 static DWORD (WINAPI
*pXInputGetCapabilities
)(DWORD
,DWORD
,XINPUT_CAPABILITIES
*);
28 static DWORD (WINAPI
*pXInputSetState
)(DWORD
, XINPUT_VIBRATION
*);
29 static void (WINAPI
*pXInputEnable
)(BOOL
);
30 static DWORD (WINAPI
*pXInputGetKeystroke
)(DWORD
, DWORD
, PXINPUT_KEYSTROKE
);
32 static void test_set_state(void)
34 XINPUT_VIBRATION vibrator
;
38 for(controllerNum
=0; controllerNum
< XUSER_MAX_COUNT
; controllerNum
++)
40 ZeroMemory(&vibrator
, sizeof(XINPUT_VIBRATION
));
42 vibrator
.wLeftMotorSpeed
= 0;
43 vibrator
.wRightMotorSpeed
= 0;
44 result
= pXInputSetState(controllerNum
, &vibrator
);
45 ok(result
== ERROR_SUCCESS
|| result
== ERROR_DEVICE_NOT_CONNECTED
, "XInputSetState failed with (%d)\n", result
);
49 vibrator
.wLeftMotorSpeed
= 65535;
50 vibrator
.wRightMotorSpeed
= 65535;
51 result
= pXInputSetState(controllerNum
, &vibrator
);
52 ok(result
== ERROR_SUCCESS
|| result
== ERROR_DEVICE_NOT_CONNECTED
, "XInputSetState failed with (%d)\n", result
);
57 result
= pXInputSetState(XUSER_MAX_COUNT
+1, &vibrator
);
58 ok(result
== ERROR_BAD_ARGUMENTS
, "XInputSetState returned (%d)\n", result
);
61 static void test_get_state(void)
64 XINPUT_STATE controllerState
;
68 for(controllerNum
=0; controllerNum
< XUSER_MAX_COUNT
; controllerNum
++)
70 ZeroMemory(&controllerState
, sizeof(XINPUT_STATE
));
72 result
= pXInputGetState(controllerNum
, &controllerState
);
73 ok(result
== ERROR_SUCCESS
|| result
== ERROR_DEVICE_NOT_CONNECTED
, "XInputGetState failed with (%d)\n", result
);
75 if (ERROR_DEVICE_NOT_CONNECTED
== result
)
77 skip("Controller %d is not connected\n", controllerNum
);
81 trace("-- Results for controller %d --\n", controllerNum
);
82 trace("XInputGetState: %d\n", result
);
83 trace("State->dwPacketNumber: %d\n", controllerState
.dwPacketNumber
);
84 trace("Gamepad Variables --\n");
85 trace("Gamepad.wButtons: %#x\n", controllerState
.Gamepad
.wButtons
);
86 trace("Gamepad.bLeftTrigger: 0x%08x\n", controllerState
.Gamepad
.bLeftTrigger
);
87 trace("Gamepad.bRightTrigger: 0x%08x\n", controllerState
.Gamepad
.bRightTrigger
);
88 trace("Gamepad.sThumbLX: %d\n", controllerState
.Gamepad
.sThumbLX
);
89 trace("Gamepad.sThumbLY: %d\n", controllerState
.Gamepad
.sThumbLY
);
90 trace("Gamepad.sThumbRX: %d\n", controllerState
.Gamepad
.sThumbRX
);
91 trace("Gamepad.sThumbRY: %d\n", controllerState
.Gamepad
.sThumbRY
);
95 ZeroMemory(&controllerState
, sizeof(XINPUT_STATE
));
96 result
= pXInputGetState(XUSER_MAX_COUNT
+1, &controllerState
);
97 ok(result
== ERROR_BAD_ARGUMENTS
, "XInputGetState returned (%d)\n", result
);
100 static void test_get_keystroke(void)
102 XINPUT_KEYSTROKE keystroke
;
106 for(controllerNum
=0; controllerNum
< XUSER_MAX_COUNT
; controllerNum
++)
108 ZeroMemory(&keystroke
, sizeof(XINPUT_KEYSTROKE
));
110 result
= pXInputGetKeystroke(controllerNum
, XINPUT_FLAG_GAMEPAD
, &keystroke
);
111 ok(result
== ERROR_SUCCESS
|| result
== ERROR_DEVICE_NOT_CONNECTED
, "XInputGetKeystroke failed with (%d)\n", result
);
113 if (ERROR_DEVICE_NOT_CONNECTED
== result
)
115 skip("Controller %d is not connected\n", controllerNum
);
119 ZeroMemory(&keystroke
, sizeof(XINPUT_KEYSTROKE
));
120 result
= pXInputGetKeystroke(XUSER_MAX_COUNT
+1, XINPUT_FLAG_GAMEPAD
, &keystroke
);
121 ok(result
== ERROR_BAD_ARGUMENTS
, "XInputGetKeystroke returned (%d)\n", result
);
124 static void test_get_capabilities(void)
126 XINPUT_CAPABILITIES capabilities
;
130 for(controllerNum
=0; controllerNum
< XUSER_MAX_COUNT
; controllerNum
++)
132 ZeroMemory(&capabilities
, sizeof(XINPUT_CAPABILITIES
));
134 result
= pXInputGetCapabilities(controllerNum
, XINPUT_FLAG_GAMEPAD
, &capabilities
);
135 ok(result
== ERROR_SUCCESS
|| result
== ERROR_DEVICE_NOT_CONNECTED
, "XInputGetCapabilities failed with (%d)\n", result
);
137 if (ERROR_DEVICE_NOT_CONNECTED
== result
)
139 skip("Controller %d is not connected\n", controllerNum
);
143 ZeroMemory(&capabilities
, sizeof(XINPUT_CAPABILITIES
));
144 result
= pXInputGetCapabilities(XUSER_MAX_COUNT
+1, XINPUT_FLAG_GAMEPAD
, &capabilities
);
145 ok(result
== ERROR_BAD_ARGUMENTS
, "XInputGetCapabilities returned (%d)\n", result
);
151 hXinput
= LoadLibraryA( "xinput1_3.dll" );
155 win_skip("Could not load xinput1_3.dll\n");
159 pXInputEnable
= (void*)GetProcAddress(hXinput
, "XInputEnable");
160 pXInputSetState
= (void*)GetProcAddress(hXinput
, "XInputSetState");
161 pXInputGetState
= (void*)GetProcAddress(hXinput
, "XInputGetState");
162 pXInputGetKeystroke
= (void*)GetProcAddress(hXinput
, "XInputGetKeystroke");
163 pXInputGetCapabilities
= (void*)GetProcAddress(hXinput
, "XInputGetCapabilities");
166 test_get_keystroke();
167 test_get_capabilities();
168 FreeLibrary(hXinput
);