ReactOS  0.4.14-dev-293-g2b39b42
xinput.c File Reference
#include <windows.h>
#include <stdio.h>
#include "xinput.h"
#include "wine/test.h"
Include dependency graph for xinput.c:

Go to the source code of this file.

Functions

static DWORD (WINAPI *pXInputGetState)(DWORD
 
static XINPUT_STATE *static XINPUT_STATE *static XINPUT_CAPABILITIES *static XINPUT_VIBRATION *static void (WINAPI *pXInputEnable)(BOOL)
 
static GUID GUID *static XINPUT_BATTERY_INFORMATION *static void dump_gamepad (XINPUT_GAMEPAD *data)
 
static void test_set_state (void)
 
static void test_get_state (void)
 
static void test_get_keystroke (void)
 
static void test_get_capabilities (void)
 
static void test_get_dsoundaudiodevice (void)
 
static void test_get_batteryinformation (void)
 
 START_TEST (xinput)
 

Variables

static XINPUT_STATE *static XINPUT_STATE *static DWORD
 
static PXINPUT_KEYSTROKE
 
static GUID GUID *static BYTE
 

Function Documentation

◆ dump_gamepad()

static GUID GUID* static XINPUT_BATTERY_INFORMATION* static void dump_gamepad ( XINPUT_GAMEPAD data)
static

Definition at line 35 of file xinput.c.

36 {
37  trace("-- Gamepad Variables --\n");
38  trace("Gamepad.wButtons: %#x\n", data->wButtons);
39  trace("Gamepad.bLeftTrigger: %d\n", data->bLeftTrigger);
40  trace("Gamepad.bRightTrigger: %d\n", data->bRightTrigger);
41  trace("Gamepad.sThumbLX: %d\n", data->sThumbLX);
42  trace("Gamepad.sThumbLY: %d\n", data->sThumbLY);
43  trace("Gamepad.sThumbRX: %d\n", data->sThumbRX);
44  trace("Gamepad.sThumbRY: %d\n\n", data->sThumbRY);
45 }
#define trace
Definition: atltest.h:70
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by test_get_capabilities(), and test_get_state().

◆ DWORD()

static DWORD ( WINAPI pXInputGetState)
static

◆ START_TEST()

START_TEST ( xinput  )

Definition at line 278 of file xinput.c.

279 {
280  struct
281  {
282  const char *name;
283  int version;
284  } libs[] = {
285  { "xinput1_1.dll", 1 },
286  { "xinput1_2.dll", 2 },
287  { "xinput1_3.dll", 3 },
288  { "xinput1_4.dll", 4 },
289  { "xinput9_1_0.dll", 0 } /* legacy for XP/Vista */
290  };
291  HMODULE hXinput;
292  void *pXInputGetStateEx_Ordinal;
293  int i;
294 
295  for (i = 0; i < sizeof(libs) / sizeof(libs[0]); i++)
296  {
297  hXinput = LoadLibraryA( libs[i].name );
298 
299  if (!hXinput)
300  {
301  win_skip("Could not load %s\n", libs[i].name);
302  continue;
303  }
304  trace("Testing %s\n", libs[i].name);
305 
306  pXInputEnable = (void*)GetProcAddress(hXinput, "XInputEnable");
307  pXInputSetState = (void*)GetProcAddress(hXinput, "XInputSetState");
308  pXInputGetState = (void*)GetProcAddress(hXinput, "XInputGetState");
309  pXInputGetStateEx = (void*)GetProcAddress(hXinput, "XInputGetStateEx"); /* Win >= 8 */
310  pXInputGetStateEx_Ordinal = (void*)GetProcAddress(hXinput, (LPCSTR) 100);
311  pXInputGetKeystroke = (void*)GetProcAddress(hXinput, "XInputGetKeystroke");
312  pXInputGetCapabilities = (void*)GetProcAddress(hXinput, "XInputGetCapabilities");
313  pXInputGetDSoundAudioDeviceGuids = (void*)GetProcAddress(hXinput, "XInputGetDSoundAudioDeviceGuids");
314  pXInputGetBatteryInformation = (void*)GetProcAddress(hXinput, "XInputGetBatteryInformation");
315 
316  /* XInputGetStateEx may not be present by name, use ordinal in this case */
317  if (!pXInputGetStateEx)
318  pXInputGetStateEx = pXInputGetStateEx_Ordinal;
319 
320  test_set_state();
321  test_get_state();
323 
324  if (libs[i].version != 4)
326  else
327  ok(!pXInputGetDSoundAudioDeviceGuids, "XInputGetDSoundAudioDeviceGuids exists in %s\n", libs[i].name);
328 
329  if (libs[i].version > 2)
330  {
333  ok(pXInputGetStateEx != NULL, "XInputGetStateEx not found in %s\n", libs[i].name);
334  }
335  else
336  {
337  ok(!pXInputGetKeystroke, "XInputGetKeystroke exists in %s\n", libs[i].name);
338  ok(!pXInputGetStateEx, "XInputGetStateEx exists in %s\n", libs[i].name);
339  ok(!pXInputGetBatteryInformation, "XInputGetBatteryInformation exists in %s\n", libs[i].name);
340  if (libs[i].version == 0)
341  ok(!pXInputEnable, "XInputEnable exists in %s\n", libs[i].name);
342  }
343 
344  FreeLibrary(hXinput);
345  }
346 }
static void test_get_keystroke(void)
Definition: xinput.c:166
static void test_get_state(void)
Definition: xinput.c:92
static void test_get_dsoundaudiodevice(void)
Definition: xinput.c:219
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR version[]
Definition: asmname.c:66
static void test_get_batteryinformation(void)
Definition: xinput.c:254
const char * LPCSTR
Definition: xmlstorage.h:183
#define FreeLibrary(x)
Definition: compat.h:405
#define trace
Definition: atltest.h:70
static void test_get_capabilities(void)
Definition: xinput.c:191
#define ok(value,...)
Definition: atltest.h:57
static void test_set_state(void)
Definition: xinput.c:47
Definition: name.c:36
#define GetProcAddress(x, y)
Definition: compat.h:410
#define win_skip
Definition: test.h:141
GLuint const GLchar * name
Definition: glext.h:6031

◆ test_get_batteryinformation()

static void test_get_batteryinformation ( void  )
static

Definition at line 254 of file xinput.c.

255 {
256  DWORD controllerNum;
257  DWORD result;
258  XINPUT_BATTERY_INFORMATION batteryInfo;
259 
260  for(controllerNum = 0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
261  {
262  ZeroMemory(&batteryInfo, sizeof(XINPUT_BATTERY_INFORMATION));
263 
264  result = pXInputGetBatteryInformation(controllerNum, BATTERY_DEVTYPE_GAMEPAD, &batteryInfo);
265  ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetBatteryInformation failed with (%d)\n", result);
266 
268  {
269  ok(batteryInfo.BatteryLevel == BATTERY_TYPE_DISCONNECTED, "Failed to report device as being disconnected.\n");
270  skip("Controller %d is not connected\n", controllerNum);
271  }
272  }
273 
274  result = pXInputGetBatteryInformation(XUSER_MAX_COUNT+1, BATTERY_DEVTYPE_GAMEPAD, &batteryInfo);
275  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetBatteryInformation returned (%d)\n", result);
276 }
#define XUSER_MAX_COUNT
Definition: xinput.h:156
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_BAD_ARGUMENTS
Definition: winerror.h:232
#define ZeroMemory
Definition: winbase.h:1642
#define ERROR_DEVICE_NOT_CONNECTED
Definition: winerror.h:689
#define BATTERY_DEVTYPE_GAMEPAD
Definition: xinput.h:139
unsigned long DWORD
Definition: ntddk_ex.h:95
#define BATTERY_TYPE_DISCONNECTED
Definition: xinput.h:141
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
GLuint64EXT * result
Definition: glext.h:11304

Referenced by START_TEST().

◆ test_get_capabilities()

static void test_get_capabilities ( void  )
static

Definition at line 191 of file xinput.c.

192 {
193  XINPUT_CAPABILITIES capabilities;
194  DWORD controllerNum;
195  DWORD result;
196 
197  for(controllerNum = 0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
198  {
199  ZeroMemory(&capabilities, sizeof(XINPUT_CAPABILITIES));
200 
201  result = pXInputGetCapabilities(controllerNum, XINPUT_FLAG_GAMEPAD, &capabilities);
202  ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetCapabilities failed with (%d)\n", result);
203 
205  {
206  skip("Controller %d is not connected\n", controllerNum);
207  continue;
208  }
209 
210  /* Important to show that the results changed between 1.3 and 1.4 XInput version */
211  dump_gamepad(&capabilities.Gamepad);
212  }
213 
214  ZeroMemory(&capabilities, sizeof(XINPUT_CAPABILITIES));
215  result = pXInputGetCapabilities(XUSER_MAX_COUNT+1, XINPUT_FLAG_GAMEPAD, &capabilities);
216  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetCapabilities returned (%d)\n", result);
217 }
#define XUSER_MAX_COUNT
Definition: xinput.h:156
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_BAD_ARGUMENTS
Definition: winerror.h:232
#define ZeroMemory
Definition: winbase.h:1642
#define ERROR_DEVICE_NOT_CONNECTED
Definition: winerror.h:689
XINPUT_GAMEPAD Gamepad
Definition: xinput.h:217
static GUID GUID *static XINPUT_BATTERY_INFORMATION *static void dump_gamepad(XINPUT_GAMEPAD *data)
Definition: xinput.c:35
#define XINPUT_FLAG_GAMEPAD
Definition: xinput.h:129
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
GLuint64EXT * result
Definition: glext.h:11304

Referenced by START_TEST().

◆ test_get_dsoundaudiodevice()

static void test_get_dsoundaudiodevice ( void  )
static

Definition at line 219 of file xinput.c.

220 {
221  DWORD controllerNum;
222  DWORD result;
223  GUID soundRender, soundCapture;
224  GUID testGuid = {0xFFFFFFFF, 0xFFFF, 0xFFFF, {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
225  GUID emptyGuid = {0x0, 0x0, 0x0, {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}};
226 
227  for(controllerNum = 0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
228  {
229  soundRender = soundCapture = testGuid;
230  result = pXInputGetDSoundAudioDeviceGuids(controllerNum, &soundRender, &soundCapture);
231  ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetDSoundAudioDeviceGuids failed with (%d)\n", result);
232 
234  {
235  skip("Controller %d is not connected\n", controllerNum);
236  continue;
237  }
238 
239  if (!IsEqualGUID(&soundRender, &emptyGuid))
240  ok(!IsEqualGUID(&soundRender, &testGuid), "Broken GUID returned for sound render device\n");
241  else
242  trace("Headset phone not attached\n");
243 
244  if (!IsEqualGUID(&soundCapture, &emptyGuid))
245  ok(!IsEqualGUID(&soundCapture, &testGuid), "Broken GUID returned for sound capture device\n");
246  else
247  trace("Headset microphone not attached\n");
248  }
249 
250  result = pXInputGetDSoundAudioDeviceGuids(XUSER_MAX_COUNT+1, &soundRender, &soundCapture);
251  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetDSoundAudioDeviceGuids returned (%d)\n", result);
252 }
#define XUSER_MAX_COUNT
Definition: xinput.h:156
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_BAD_ARGUMENTS
Definition: winerror.h:232
#define ERROR_DEVICE_NOT_CONNECTED
Definition: winerror.h:689
#define trace
Definition: atltest.h:70
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
#define skip(...)
Definition: atltest.h:64
GLuint64EXT * result
Definition: glext.h:11304

Referenced by START_TEST().

◆ test_get_keystroke()

static void test_get_keystroke ( void  )
static

Definition at line 166 of file xinput.c.

167 {
168  XINPUT_KEYSTROKE keystroke;
169  DWORD controllerNum;
170  DWORD result;
171 
172  for(controllerNum = 0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
173  {
174  ZeroMemory(&keystroke, sizeof(XINPUT_KEYSTROKE));
175 
176  result = pXInputGetKeystroke(controllerNum, XINPUT_FLAG_GAMEPAD, &keystroke);
178  "XInputGetKeystroke failed with (%d)\n", result);
179 
181  {
182  skip("Controller %d is not connected\n", controllerNum);
183  }
184  }
185 
186  ZeroMemory(&keystroke, sizeof(XINPUT_KEYSTROKE));
187  result = pXInputGetKeystroke(XUSER_MAX_COUNT+1, XINPUT_FLAG_GAMEPAD, &keystroke);
188  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetKeystroke returned (%d)\n", result);
189 }
#define XUSER_MAX_COUNT
Definition: xinput.h:156
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_BAD_ARGUMENTS
Definition: winerror.h:232
#define ZeroMemory
Definition: winbase.h:1642
#define ERROR_DEVICE_NOT_CONNECTED
Definition: winerror.h:689
#define XINPUT_FLAG_GAMEPAD
Definition: xinput.h:129
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_EMPTY
Definition: winerror.h:1250
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
GLuint64EXT * result
Definition: glext.h:11304

Referenced by START_TEST().

◆ test_get_state()

static void test_get_state ( void  )
static

Definition at line 92 of file xinput.c.

93 {
95  DWORD controllerNum, i, result, good = XUSER_MAX_COUNT;
96 
97  for (i = 0; i < (pXInputGetStateEx ? 2 : 1); i++)
98  {
99  for (controllerNum = 0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
100  {
101  ZeroMemory(&state, sizeof(state));
102 
103  if (i == 0)
104  result = pXInputGetState(controllerNum, &state);
105  else
106  result = pXInputGetStateEx(controllerNum, &state);
108  "%s failed with (%d)\n", i == 0 ? "XInputGetState" : "XInputGetStateEx", result);
109 
111  {
112  skip("Controller %d is not connected\n", controllerNum);
113  continue;
114  }
115 
116  trace("-- Results for controller %d --\n", controllerNum);
117  if (i == 0)
118  {
119  good = controllerNum;
120  trace("XInputGetState: %d\n", result);
121  }
122  else
123  trace("XInputGetStateEx: %d\n", result);
124  trace("State->dwPacketNumber: %d\n", state.dwPacketNumber);
125  dump_gamepad(&state.Gamepad);
126  }
127  }
128 
129  result = pXInputGetState(XUSER_MAX_COUNT, &state);
130  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
131 
132  result = pXInputGetState(XUSER_MAX_COUNT+1, &state);
133  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
134  if (pXInputGetStateEx)
135  {
136  result = pXInputGetStateEx(XUSER_MAX_COUNT, &state);
137  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
138 
139  result = pXInputGetStateEx(XUSER_MAX_COUNT+1, &state);
140  ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
141  }
142 
144  {
145  DWORD now = GetTickCount(), packet = 0;
146  XINPUT_GAMEPAD *game = &state.Gamepad;
147 
148  trace("You have 20 seconds to test the joystick freely\n");
149  do
150  {
151  Sleep(100);
152  pXInputGetState(good, &state);
153  if (state.dwPacketNumber == packet)
154  continue;
155 
156  packet = state.dwPacketNumber;
157  trace("Buttons 0x%04X Triggers %3d/%3d LT %6d/%6d RT %6d/%6d\n",
158  game->wButtons, game->bLeftTrigger, game->bRightTrigger,
159  game->sThumbLX, game->sThumbLY, game->sThumbRX, game->sThumbRY);
160  }
161  while(GetTickCount() - now < 20000);
162  trace("Test over...\n");
163  }
164 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define XUSER_MAX_COUNT
Definition: xinput.h:156
SHORT sThumbLX
Definition: xinput.h:167
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_BAD_ARGUMENTS
Definition: winerror.h:232
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
#define ZeroMemory
Definition: winbase.h:1642
int winetest_interactive
#define ERROR_DEVICE_NOT_CONNECTED
Definition: winerror.h:689
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
time_t now
Definition: finger.c:65
BYTE bRightTrigger
Definition: xinput.h:166
static GUID GUID *static XINPUT_BATTERY_INFORMATION *static void dump_gamepad(XINPUT_GAMEPAD *data)
Definition: xinput.c:35
Definition: dhcpd.h:135
WORD wButtons
Definition: xinput.h:164
#define trace
Definition: atltest.h:70
unsigned long DWORD
Definition: ntddk_ex.h:95
static int state
Definition: maze.c:121
SHORT sThumbRY
Definition: xinput.h:170
SHORT sThumbLY
Definition: xinput.h:168
#define ok(value,...)
Definition: atltest.h:57
SHORT sThumbRX
Definition: xinput.h:169
#define skip(...)
Definition: atltest.h:64
GLuint64EXT * result
Definition: glext.h:11304
BYTE bLeftTrigger
Definition: xinput.h:165

Referenced by START_TEST().

◆ test_set_state()

static void test_set_state ( void  )
static

Definition at line 47 of file xinput.c.

48 {
49  XINPUT_VIBRATION vibrator;
50  DWORD controllerNum;
51  DWORD result;
52 
53  for(controllerNum = 0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
54  {
55  ZeroMemory(&vibrator, sizeof(XINPUT_VIBRATION));
56 
57  vibrator.wLeftMotorSpeed = 32767;
58  vibrator.wRightMotorSpeed = 32767;
59  result = pXInputSetState(controllerNum, &vibrator);
60  if (result == ERROR_DEVICE_NOT_CONNECTED) continue;
61 
62  Sleep(250);
63  vibrator.wLeftMotorSpeed = 0;
64  vibrator.wRightMotorSpeed = 0;
65  result = pXInputSetState(controllerNum, &vibrator);
66  ok(result == ERROR_SUCCESS, "XInputSetState failed with (%d)\n", result);
67 
68  /* Disabling XInput here, queueing a vibration and then re-enabling XInput
69  * is used to prove that vibrations are auto enabled when resuming XInput.
70  * If XInputEnable(1) is removed below the vibration will never play. */
71  if (pXInputEnable) pXInputEnable(0);
72 
73  Sleep(250);
74  vibrator.wLeftMotorSpeed = 65535;
75  vibrator.wRightMotorSpeed = 65535;
76  result = pXInputSetState(controllerNum, &vibrator);
77  ok(result == ERROR_SUCCESS, "XInputSetState failed with (%d)\n", result);
78 
79  if (pXInputEnable) pXInputEnable(1);
80  Sleep(250);
81 
82  vibrator.wLeftMotorSpeed = 0;
83  vibrator.wRightMotorSpeed = 0;
84  result = pXInputSetState(controllerNum, &vibrator);
85  ok(result == ERROR_SUCCESS, "XInputSetState failed with (%d)\n", result);
86  }
87 
88  result = pXInputSetState(XUSER_MAX_COUNT+1, &vibrator);
89  ok(result == ERROR_BAD_ARGUMENTS, "XInputSetState returned (%d)\n", result);
90 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define XUSER_MAX_COUNT
Definition: xinput.h:156
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_BAD_ARGUMENTS
Definition: winerror.h:232
#define ZeroMemory
Definition: winbase.h:1642
#define ERROR_DEVICE_NOT_CONNECTED
Definition: winerror.h:689
WORD wRightMotorSpeed
Definition: xinput.h:202
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ok(value,...)
Definition: atltest.h:57
GLuint64EXT * result
Definition: glext.h:11304
WORD wLeftMotorSpeed
Definition: xinput.h:201

Referenced by START_TEST().

◆ void()

static XINPUT_STATE* static XINPUT_STATE* static XINPUT_CAPABILITIES* static XINPUT_VIBRATION* static void ( WINAPI pXInputEnable)
static

Variable Documentation

◆ BYTE

GUID GUID* static BYTE

Definition at line 33 of file xinput.c.

◆ DWORD

Definition at line 28 of file xinput.c.

◆ PXINPUT_KEYSTROKE

Definition at line 31 of file xinput.c.