2 * Copyright (c) 2004-2005 Robert Reif
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define numObjects(x) (sizeof(x) / sizeof(x[0]))
26 typedef struct tagUserData
{
31 static const DIOBJECTDATAFORMAT dfDIJoystickTest
[] = {
32 { &GUID_XAxis
,DIJOFS_X
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
33 { &GUID_YAxis
,DIJOFS_Y
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
34 { &GUID_ZAxis
,DIJOFS_Z
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
35 { &GUID_RxAxis
,DIJOFS_RX
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
36 { &GUID_RyAxis
,DIJOFS_RY
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
37 { &GUID_RzAxis
,DIJOFS_RZ
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
38 { &GUID_Button
,DIJOFS_BUTTON(0),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
39 { &GUID_Button
,DIJOFS_BUTTON(1),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
40 { &GUID_Button
,DIJOFS_BUTTON(2),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
41 { &GUID_Button
,DIJOFS_BUTTON(3),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
42 { &GUID_Button
,DIJOFS_BUTTON(4),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
43 { &GUID_Button
,DIJOFS_BUTTON(5),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
44 { &GUID_Button
,DIJOFS_BUTTON(6),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
45 { &GUID_Button
,DIJOFS_BUTTON(7),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
46 { &GUID_Button
,DIJOFS_BUTTON(8),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
47 { &GUID_Button
,DIJOFS_BUTTON(9),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
48 { &GUID_Button
,DIJOFS_BUTTON(10),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
51 static const DIDATAFORMAT c_dfDIJoystickTest
= {
53 sizeof(DIOBJECTDATAFORMAT
),
56 numObjects(dfDIJoystickTest
),
57 (LPDIOBJECTDATAFORMAT
)dfDIJoystickTest
60 static HWND
get_hwnd(void)
62 HWND hwnd
=GetForegroundWindow();
64 hwnd
=GetDesktopWindow();
68 typedef struct tagJoystickInfo
70 IDirectInputDeviceA
*pJoystick
;
78 static int get_refcount(IUnknown
*object
)
80 IUnknown_AddRef( object
);
81 return IUnknown_Release( object
);
84 static BOOL CALLBACK
EnumAxes(const DIDEVICEOBJECTINSTANCEA
*pdidoi
, void *pContext
)
87 JoystickInfo
* info
= pContext
;
89 if (IsEqualIID(&pdidoi
->guidType
, &GUID_XAxis
) ||
90 IsEqualIID(&pdidoi
->guidType
, &GUID_YAxis
) ||
91 IsEqualIID(&pdidoi
->guidType
, &GUID_ZAxis
) ||
92 IsEqualIID(&pdidoi
->guidType
, &GUID_RxAxis
) ||
93 IsEqualIID(&pdidoi
->guidType
, &GUID_RyAxis
) ||
94 IsEqualIID(&pdidoi
->guidType
, &GUID_RzAxis
) ||
95 IsEqualIID(&pdidoi
->guidType
, &GUID_Slider
))
100 diprg
.diph
.dwSize
= sizeof(DIPROPRANGE
);
101 diprg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
102 diprg
.diph
.dwHow
= DIPH_BYID
;
103 diprg
.diph
.dwObj
= pdidoi
->dwType
;
105 dipdw
.diph
.dwSize
= sizeof(dipdw
);
106 dipdw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
107 dipdw
.diph
.dwHow
= DIPH_BYID
;
108 dipdw
.diph
.dwObj
= pdidoi
->dwType
;
110 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
111 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
112 ok(info
->lMin
== diprg
.lMin
&& info
->lMax
== diprg
.lMax
, "Min/Max range invalid: "
113 "expected %d..%d got %d..%d\n", info
->lMin
, info
->lMax
, diprg
.lMin
, diprg
.lMax
);
118 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, NULL
);
119 ok(hr
==E_INVALIDARG
,"IDirectInputDevice_SetProperty() should have returned "
120 "E_INVALIDARG, returned: %08x\n", hr
);
122 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
123 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
126 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
127 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
128 ok(info
->dZone
== dipdw
.dwData
, "deadzone invalid: expected %d got %d\n",
129 info
->dZone
, dipdw
.dwData
);
133 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
134 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
136 /* ensure DIDOI_ASPECTPOSITION is set for axes objects */
137 ok(pdidoi
->dwFlags
& DIDOI_ASPECTPOSITION
, "Missing DIDOI_ASPECTPOSITION, flags are 0x%x\n",
141 } else if (IsEqualIID(&pdidoi
->guidType
, &GUID_POV
))
143 else if (IsEqualIID(&pdidoi
->guidType
, &GUID_Button
))
146 return DIENUM_CONTINUE
;
149 static const struct effect_id
154 } effect_conversion
[] = {
155 {&GUID_ConstantForce
, DIEFT_CONSTANTFORCE
, "Constant"},
156 {&GUID_RampForce
, DIEFT_RAMPFORCE
, "Ramp"},
157 {&GUID_Square
, DIEFT_PERIODIC
, "Square"},
158 {&GUID_Sine
, DIEFT_PERIODIC
, "Sine"},
159 {&GUID_Triangle
, DIEFT_PERIODIC
, "Triangle"},
160 {&GUID_SawtoothUp
, DIEFT_PERIODIC
, "Saw Tooth Up"},
161 {&GUID_SawtoothDown
, DIEFT_PERIODIC
, "Saw Tooth Down"},
162 {&GUID_Spring
, DIEFT_CONDITION
, "Spring"},
163 {&GUID_Damper
, DIEFT_CONDITION
, "Damper"},
164 {&GUID_Inertia
, DIEFT_CONDITION
, "Inertia"},
165 {&GUID_Friction
, DIEFT_CONDITION
, "Friction"},
166 {&GUID_CustomForce
, DIEFT_CUSTOMFORCE
, "Custom"}
169 static const struct effect_id
* effect_from_guid(const GUID
*guid
)
172 for (i
= 0; i
< sizeof(effect_conversion
) / sizeof(effect_conversion
[0]); i
++)
173 if (IsEqualGUID(guid
, effect_conversion
[i
].guid
))
174 return &effect_conversion
[i
];
183 const char *effect_name
;
186 /* The last enumerated effect will be used for force feedback testing */
187 static BOOL CALLBACK
EnumEffects(const DIEFFECTINFOA
*lpef
, void *ref
)
189 const struct effect_id
*id
= effect_from_guid(&lpef
->guid
);
192 DICONSTANTFORCE constant
;
195 DICONDITION condition
[2];
197 struct effect_enum
*data
= ref
;
198 int type
= DIDFT_GETTYPE(lpef
->dwEffType
);
203 ok(0, "unsupported effect enumerated, GUID %s!\n", wine_dbgstr_guid(&lpef
->guid
));
204 return DIENUM_CONTINUE
;
206 trace("controller supports '%s' effect\n", id
->name
);
207 ok(type
== id
->dieft
, "Invalid effect type, expected 0x%x, got 0x%x\n",
208 id
->dieft
, lpef
->dwEffType
);
210 /* Can't use custom for test as we don't know the data format */
211 if (type
== DIEFT_CUSTOMFORCE
)
212 return DIENUM_CONTINUE
;
214 data
->effect_count
++;
215 data
->effect_name
= id
->name
;
216 data
->guid
= *id
->guid
;
218 ZeroMemory(&specific
, sizeof(specific
));
222 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.periodic
);
223 data
->eff
.lpvTypeSpecificParams
= &specific
.periodic
;
224 specific
.periodic
.dwMagnitude
= DI_FFNOMINALMAX
/ 2;
225 specific
.periodic
.dwPeriod
= DI_SECONDS
; /* 1 second */
227 case DIEFT_CONSTANTFORCE
:
228 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.constant
);
229 data
->eff
.lpvTypeSpecificParams
= &specific
.constant
;
230 specific
.constant
.lMagnitude
= DI_FFNOMINALMAX
/ 2;
232 case DIEFT_RAMPFORCE
:
233 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.ramp
);
234 data
->eff
.lpvTypeSpecificParams
= &specific
.ramp
;
235 specific
.ramp
.lStart
= -DI_FFNOMINALMAX
/ 2;
236 specific
.ramp
.lEnd
= +DI_FFNOMINALMAX
/ 2;
238 case DIEFT_CONDITION
:
241 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.condition
);
242 data
->eff
.lpvTypeSpecificParams
= specific
.condition
;
243 for (i
= 0; i
< 2; i
++)
245 specific
.condition
[i
].lNegativeCoefficient
= -DI_FFNOMINALMAX
/ 2;
246 specific
.condition
[i
].lPositiveCoefficient
= +DI_FFNOMINALMAX
/ 2;
251 return DIENUM_CONTINUE
;
254 static const HRESULT SetCoop_null_window
[16] = {
255 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
256 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
257 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
258 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
260 static const HRESULT SetCoop_real_window
[16] = {
261 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
262 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
263 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
264 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
266 static BOOL CALLBACK
EnumJoysticks(const DIDEVICEINSTANCEA
*lpddi
, void *pvRef
)
269 UserData
* data
= pvRef
;
270 IDirectInputDeviceA
*pJoystick
;
277 DIDEVICEINSTANCEA inst
;
278 DIDEVICEINSTANCE_DX3A inst3
;
281 DIPROPGUIDANDPATH dpg
;
282 WCHAR nameBuffer
[MAX_PATH
];
283 HWND hWnd
= get_hwnd();
284 char oldstate
[248], curstate
[248];
285 DWORD axes
[2] = {DIJOFS_X
, DIJOFS_Y
};
286 LONG direction
[2] = {0, 0};
287 LPDIRECTINPUTEFFECT effect
= NULL
;
290 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
291 DIPROPDWORD dip_gain_set
, dip_gain_get
;
292 struct effect_enum effect_data
;
294 ok(data
->version
> 0x0300, "Joysticks not supported in version 0x%04x\n", data
->version
);
296 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
, NULL
, NULL
);
297 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
298 "E_POINTER, returned: %08x\n", hr
);
300 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, &pJoystick
, NULL
);
301 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
302 "E_POINTER, returned: %08x\n", hr
);
304 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, NULL
, NULL
);
305 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
306 "E_POINTER, returned: %08x\n", hr
);
308 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
,
310 ok(hr
==DI_OK
,"IDirectInput_CreateDevice() failed: %08x\n", hr
);
314 trace("---- Controller Information ----\n"
315 "Product Name : %s\n"
316 "Instance Name : %s\n"
318 "GUID Product : %s\n"
319 "GUID Instance : %s\n"
320 "HID Page : 0x%04x\n"
321 "HID Usage : 0x%04x\n",
322 lpddi
->tszProductName
,
323 lpddi
->tszInstanceName
,
325 wine_dbgstr_guid(&lpddi
->guidProduct
),
326 wine_dbgstr_guid(&lpddi
->guidInstance
),
330 /* Check if this is a HID device */
331 if (lpddi
->dwDevType
& DIDEVTYPE_HID
)
332 ok(lpddi
->wUsagePage
== 0x01 && (lpddi
->wUsage
== 0x04 || lpddi
->wUsage
== 0x05),
333 "Expected a game controller HID UsagePage and Usage, got page 0x%x usage 0x%x\n",
334 lpddi
->wUsagePage
, lpddi
->wUsage
);
336 /* Test for joystick ID property */
337 ZeroMemory(&dipw
, sizeof(dipw
));
338 dipw
.diph
.dwSize
= sizeof(DIPROPDWORD
);
339 dipw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
341 dipw
.diph
.dwHow
= DIPH_DEVICE
;
343 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_JOYSTICKID
, &dipw
.diph
);
344 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
346 /* Test for INSTANCENAME property */
347 memset(&dps
, 0, sizeof(dps
));
348 dps
.diph
.dwSize
= sizeof(DIPROPSTRING
);
349 dps
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
350 dps
.diph
.dwHow
= DIPH_DEVICE
;
352 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_INSTANCENAME
, &dps
.diph
);
353 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr
);
355 /* Test if instance name is the same as present in DIDEVICEINSTANCE */
356 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszInstanceName
, -1, nameBuffer
, MAX_PATH
);
357 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
358 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
360 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_PRODUCTNAME
, &dps
.diph
);
361 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_PRODUCTNAME failed: %08x\n", hr
);
363 /* Test if product name is the same as present in DIDEVICEINSTANCE */
364 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszProductName
, -1, nameBuffer
, MAX_PATH
);
365 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_PRODUCTNAME returned is wrong. Expected: %s Got: %s\n",
366 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
368 /* Test for GUIDPATH properties */
369 memset(&dpg
, 0, sizeof(dpg
));
370 dpg
.diph
.dwSize
= sizeof(DIPROPGUIDANDPATH
);
371 dpg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
372 dpg
.diph
.dwHow
= DIPH_DEVICE
;
374 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_GUIDANDPATH
, &dpg
.diph
);
375 todo_wine
ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr
);
377 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, NULL
);
378 ok(hr
==E_POINTER
,"IDirectInputDevice_SetDataFormat() should have returned "
379 "E_POINTER, returned: %08x\n", hr
);
381 ZeroMemory(&format
, sizeof(format
));
382 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &format
);
383 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_SetDataFormat() should have "
384 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
386 /* try the default formats */
387 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick
);
388 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
390 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
391 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
393 /* try an alternate format */
394 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystickTest
);
395 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
397 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
398 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
404 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, NULL
, i
);
405 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
409 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
, i
);
410 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
413 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
414 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
415 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
417 /* get capabilities */
418 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, NULL
);
419 ok(hr
==E_POINTER
,"IDirectInputDevice_GetCapabilities() "
420 "should have returned E_POINTER, returned: %08x\n", hr
);
422 ZeroMemory(&caps
, sizeof(caps
));
423 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
424 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_GetCapabilities() "
425 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
427 caps
.dwSize
= sizeof(caps
);
428 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
429 ok(hr
==DI_OK
,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr
);
431 ZeroMemory(&info
, sizeof(info
));
432 info
.pJoystick
= pJoystick
;
434 /* default min/max limits */
437 /* enumerate objects */
438 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
439 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
441 ok(caps
.dwAxes
== info
.axis
, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info
.axis
, caps
.dwAxes
);
442 ok(caps
.dwButtons
== info
.button
, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info
.button
, caps
.dwButtons
);
443 ok(caps
.dwPOVs
== info
.pov
, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info
.pov
, caps
.dwPOVs
);
445 /* Set format and check limits again */
446 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
447 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
451 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
452 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
454 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, 0);
455 ok(hr
==E_POINTER
, "IDirectInputDevice_GetDeviceInfo() "
456 "should have returned E_POINTER, returned: %08x\n", hr
);
458 ZeroMemory(&inst
, sizeof(inst
));
459 ZeroMemory(&inst3
, sizeof(inst3
));
461 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
462 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_GetDeviceInfo() "
463 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
465 inst
.dwSize
= sizeof(inst
);
466 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
467 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
469 inst3
.dwSize
= sizeof(inst3
);
470 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, (DIDEVICEINSTANCEA
*)&inst3
);
471 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
473 hr
= IDirectInputDevice_Unacquire(pJoystick
);
474 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
476 hr
= IDirectInputDevice_Acquire(pJoystick
);
477 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
481 hr
= IDirectInputDevice_Acquire(pJoystick
);
482 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr
);
486 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
487 ok(hr
== DI_OK
, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
488 ok(js
.rgdwPOV
[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js
.rgdwPOV
[3]);
491 trace("Testing force feedback\n");
492 ZeroMemory(&effect_data
, sizeof(effect_data
));
493 effect_data
.eff
.dwSize
= sizeof(effect_data
.eff
);
494 effect_data
.eff
.dwFlags
= DIEFF_CARTESIAN
| DIEFF_OBJECTOFFSETS
;
495 effect_data
.eff
.dwDuration
= INFINITE
;
496 effect_data
.eff
.dwGain
= DI_FFNOMINALMAX
;
497 effect_data
.eff
.dwTriggerButton
= DIEB_NOTRIGGER
;
498 effect_data
.eff
.cAxes
= sizeof(axes
) / sizeof(axes
[0]);
499 effect_data
.eff
.rgdwAxes
= axes
;
500 effect_data
.eff
.rglDirection
= direction
;
502 /* Sending effects to joystick requires
503 * calling IDirectInputEffect_Initialize, which requires
504 * having exclusive access to the device, which requires
505 * - not having acquired the joystick when calling
506 * IDirectInputDevice_SetCooperativeLevel
509 real_hWnd
= CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL
, NULL
,
511 ok(real_hWnd
!=0,"CreateWindowExA failed: %p\n", real_hWnd
);
512 ShowWindow(real_hWnd
, SW_SHOW
);
513 hr
= IDirectInputDevice_Unacquire(pJoystick
);
514 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
515 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, real_hWnd
,
516 DISCL_EXCLUSIVE
| DISCL_FOREGROUND
);
517 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
518 hr
= IDirectInputDevice_Acquire(pJoystick
);
519 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
521 cnt1
= get_refcount((IUnknown
*)pJoystick
);
523 hr
= IDirectInputDevice2_EnumEffects((IDirectInputDevice2A
*)pJoystick
, EnumEffects
, &effect_data
, DIEFT_ALL
);
524 ok(hr
==DI_OK
,"IDirectInputDevice2_EnumEffects() failed: %08x\n", hr
);
526 /* If the controller does not support ANY effect use the constant effect to make
527 * CreateEffect fail but with the unsupported reason instead of invalid parameters. */
528 if (!effect_data
.effect_count
)
530 static DICONSTANTFORCE constant
;
531 effect_data
.guid
= GUID_ConstantForce
;
532 effect_data
.eff
.cbTypeSpecificParams
= sizeof(constant
);
533 effect_data
.eff
.lpvTypeSpecificParams
= &constant
;
534 effect_data
.effect_name
= "Constant";
535 constant
.lMagnitude
= DI_FFNOMINALMAX
/ 2;
537 ok(!(caps
.dwFlags
& DIDC_FORCEFEEDBACK
), "effect count is zero but controller supports force feedback?\n");
540 effect
= (void *)0xdeadbeef;
541 hr
= IDirectInputDevice2_CreateEffect((IDirectInputDevice2A
*)pJoystick
, &effect_data
.guid
,
542 &effect_data
.eff
, &effect
, NULL
);
543 if (caps
.dwFlags
& DIDC_FORCEFEEDBACK
)
545 trace("force feedback supported with %d effects, using '%s' for test\n",
546 effect_data
.effect_count
, effect_data
.effect_name
);
547 ok(hr
== DI_OK
, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr
);
548 cnt2
= get_refcount((IUnknown
*)pJoystick
);
549 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
554 struct DIPROPDWORD diprop_word
;
557 hr
= IDirectInputEffect_Initialize(effect
, hInstance
, data
->version
,
559 ok(hr
==DI_OK
,"IDirectInputEffect_Initialize failed: %08x\n", hr
);
560 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_AXES
| DIEP_DIRECTION
|
561 DIEP_TYPESPECIFICPARAMS
);
562 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
564 /* Test that upload, unacquire, acquire still permits updating
565 * uploaded effect. */
566 hr
= IDirectInputDevice_Unacquire(pJoystick
);
567 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
568 hr
= IDirectInputDevice_Acquire(pJoystick
);
569 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
570 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_GAIN
);
571 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
574 /* Check effect status.
575 * State: initially stopped
578 * unacquire, acquire, download
584 * - effects are stopped after Unacquire + Acquire
585 * - effects are preserved (Download + Start doesn't complain
586 * about incomplete effect)
588 hr
= IDirectInputEffect_GetEffectStatus(effect
, NULL
);
589 ok(hr
==E_POINTER
,"IDirectInputEffect_GetEffectStatus() must fail with E_POINTER, got: %08x\n", hr
);
590 effect_status
= 0xdeadbeef;
591 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
592 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
593 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
594 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_START
);
595 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
596 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
597 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
598 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
599 hr
= IDirectInputDevice_Unacquire(pJoystick
);
600 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
601 hr
= IDirectInputDevice_Acquire(pJoystick
);
602 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
603 hr
= IDirectInputEffect_Download(effect
);
604 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
605 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
606 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
607 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
608 hr
= IDirectInputEffect_Start(effect
, 1, 0);
609 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
610 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
611 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
612 Sleep(250); /* feel the magic */
613 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
614 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
615 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
616 ok(IsEqualGUID(&effect_data
.guid
, &guid
), "Wrong guid returned\n");
618 /* Check autocenter status
619 * State: initially stopped
627 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
628 * executed when the device is released.
630 * If Executed interactively, user can feel that autocenter is
631 * only disabled when the joystick is acquired.
633 diprop_word
.diph
.dwSize
= sizeof(diprop_word
);
634 diprop_word
.diph
.dwHeaderSize
= sizeof(diprop_word
.diph
);
635 diprop_word
.diph
.dwObj
= 0;
636 diprop_word
.diph
.dwHow
= DIPH_DEVICE
;
637 hr
= IDirectInputDevice_Unacquire(pJoystick
);
638 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
639 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
640 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
641 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_ON
,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
642 diprop_word
.dwData
= DIPROPAUTOCENTER_OFF
;
643 hr
= IDirectInputDevice2_SetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
644 ok(hr
==DI_OK
,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr
);
645 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
646 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
647 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
648 if (winetest_interactive
) {
649 trace("Acquiring in 2s, autocenter will be disabled.\n");
652 hr
= IDirectInputDevice_Acquire(pJoystick
);
653 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
654 if (winetest_interactive
)
655 trace("Acquired.\n");
656 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
657 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
658 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
659 if (winetest_interactive
) {
660 trace("Releasing in 2s, autocenter will be re-enabled.\n");
663 hr
= IDirectInputDevice_Unacquire(pJoystick
);
664 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
665 if (winetest_interactive
)
667 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
668 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
669 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
670 hr
= IDirectInputDevice_Acquire(pJoystick
);
671 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
672 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
673 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
675 /* Device gain (DIPROP_FFGAIN).
677 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
678 * Can be changed even if device is acquired.
679 * Difference found by tests:
680 * <0 is refused, >10000 is accepted
682 dip_gain_set
.diph
.dwSize
= sizeof(DIPROPDWORD
);
683 dip_gain_set
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
684 dip_gain_set
.diph
.dwObj
= 0;
685 dip_gain_set
.diph
.dwHow
= DIPH_DEVICE
;
686 dip_gain_get
.diph
.dwSize
= sizeof(DIPROPDWORD
);
687 dip_gain_get
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
688 dip_gain_get
.diph
.dwObj
= 0;
689 dip_gain_get
.diph
.dwHow
= DIPH_DEVICE
;
690 dip_gain_get
.dwData
= 0;
692 /* Test device is acquisition (non)impact. */
693 hr
= IDirectInputDevice_Unacquire(pJoystick
);
694 ok(hr
== DI_OK
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
695 dip_gain_set
.dwData
= 1;
696 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
697 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
698 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
699 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
700 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
701 hr
= IDirectInputDevice_Acquire(pJoystick
);
702 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
703 dip_gain_set
.dwData
= 2;
704 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
705 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
706 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
707 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
708 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
709 /* Test range and internal clamping. */
710 dip_gain_set
.dwData
= -1;
711 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
712 todo_wine
ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM
, hr
);
713 dip_gain_set
.dwData
= 0;
714 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
715 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
716 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
717 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
718 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
719 dip_gain_set
.dwData
= 10000;
720 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
721 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
722 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
723 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
724 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
725 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
726 dip_gain_set
.dwData
= 10001;
727 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
728 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
729 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
730 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
731 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
733 /* Test SendForceFeedbackCommand
734 * DISFFC_STOPALL - Should stop effects only
735 * DISFFC_RESET - Should stop effects and unload them (NOT release them)
736 * Tests for game Odallus (bug 41623) */
737 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, 0);
738 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
739 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, 0xFF);
740 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
742 hr
= IDirectInputEffect_Download(effect
);
743 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
745 /* Send STOPALL and prove that the effect can still be started */
746 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, DISFFC_STOPALL
);
747 ok(hr
==DI_OK
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
748 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
749 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
750 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
751 hr
= IDirectInputEffect_Start(effect
, 1, 0);
752 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
753 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
754 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
755 ok(IsEqualGUID(&effect_data
.guid
, &guid
), "Wrong guid returned\n");
757 /* Send RESET and prove that we can still manipulate the effect, thus not released */
758 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, DISFFC_RESET
);
759 ok(hr
==DI_OK
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
760 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
761 ok(hr
==DIERR_NOTDOWNLOADED
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
762 hr
= IDirectInputEffect_Download(effect
);
763 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
764 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
765 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
766 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
767 hr
= IDirectInputEffect_Start(effect
, 1, 0);
768 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
769 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
770 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
771 ok(IsEqualGUID(&effect_data
.guid
, &guid
), "Wrong guid returned\n");
773 ref
= IUnknown_Release(effect
);
774 ok(ref
== 0, "IDirectInputDevice_Release() reference count = %d\n", ref
);
776 cnt1
= get_refcount((IUnknown
*)pJoystick
);
777 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
779 /* No force feedback support, CreateEffect is supposed to fail. Fairy Bloom Freesia
780 * calls CreateEffect without checking the DIDC_FORCEFEEDBACK. It expects the correct
781 * error return to determine if force feedback is unsupported. */
784 trace("No force feedback support\n");
785 ok(hr
==DIERR_UNSUPPORTED
, "IDirectInputDevice_CreateEffect() must fail with DIERR_UNSUPPORTED, got: %08x\n", hr
);
786 ok(effect
== NULL
, "effect must be NULL, got %p\n", effect
);
789 /* Before destroying the window, release joystick to revert to
790 * non-exclusive, background cooperative level. */
791 hr
= IDirectInputDevice_Unacquire(pJoystick
);
792 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
793 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
794 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
795 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
796 DestroyWindow (real_hWnd
);
797 hr
= IDirectInputDevice_Acquire(pJoystick
);
798 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
800 if (winetest_interactive
) {
801 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
808 for (i
= 0; i
< count
; i
++) {
809 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
810 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
813 sprintf(curstate
, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
814 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
815 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
816 js
.lX
, js
.lY
, js
.lZ
, js
.lRx
, js
.lRy
, js
.lRz
,
817 js
.rglSlider
[0], js
.rglSlider
[1],
818 js
.rgdwPOV
[0], js
.rgdwPOV
[1], js
.rgdwPOV
[2], js
.rgdwPOV
[3],
819 js
.rgbButtons
[0]>>7, js
.rgbButtons
[1]>>7, js
.rgbButtons
[2]>>7,
820 js
.rgbButtons
[3]>>7, js
.rgbButtons
[4]>>7, js
.rgbButtons
[5]>>7,
821 js
.rgbButtons
[6]>>7, js
.rgbButtons
[7]>>7, js
.rgbButtons
[8]>>7,
822 js
.rgbButtons
[9]>>7, js
.rgbButtons
[10]>>7, js
.rgbButtons
[11]>>7);
823 if (strcmp(oldstate
, curstate
) != 0)
825 trace("%s\n", curstate
);
826 strcpy(oldstate
, curstate
);
832 hr
= IDirectInputDevice_Unacquire(pJoystick
);
833 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
836 ref
= IDirectInputDevice_Release(pJoystick
);
837 ok(ref
==0,"IDirectInputDevice_Release() reference count = %d\n", ref
);
840 return DIENUM_CONTINUE
;
843 static void joystick_tests(DWORD version
)
848 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
850 trace("-- Testing Direct Input Version 0x%04x --\n", version
);
851 hr
= DirectInputCreateA(hInstance
, version
, &pDI
, NULL
);
852 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
, "DirectInputCreateA() failed: %08x\n", hr
);
853 if (hr
==DI_OK
&& pDI
!=0) {
856 data
.version
= version
;
857 hr
= IDirectInput_EnumDevices(pDI
, DIDEVTYPE_JOYSTICK
, EnumJoysticks
,
858 &data
, DIEDFL_ALLDEVICES
);
859 ok(hr
==DI_OK
,"IDirectInput_EnumDevices() failed: %08x\n", hr
);
860 ref
= IDirectInput_Release(pDI
);
861 ok(ref
==0,"IDirectInput_Release() reference count = %d\n", ref
);
862 } else if (hr
==DIERR_OLDDIRECTINPUTVERSION
)
863 trace(" Version Not Supported\n");
870 joystick_tests(0x0700);
871 joystick_tests(0x0500);
872 joystick_tests(0x0300);