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
19 #define WIN32_NO_STATUS
21 #define COM_NO_WINDOWS_H
23 #define DIRECTINPUT_VERSION 0x0700
26 //#include <windows.h>
32 #include <wine/test.h>
38 #define numObjects(x) (sizeof(x) / sizeof(x[0]))
40 typedef struct tagUserData
{
45 static const DIOBJECTDATAFORMAT dfDIJoystickTest
[] = {
46 { &GUID_XAxis
,DIJOFS_X
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
47 { &GUID_YAxis
,DIJOFS_Y
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
48 { &GUID_ZAxis
,DIJOFS_Z
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
49 { &GUID_RxAxis
,DIJOFS_RX
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
50 { &GUID_RyAxis
,DIJOFS_RY
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
51 { &GUID_RzAxis
,DIJOFS_RZ
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
52 { &GUID_Button
,DIJOFS_BUTTON(0),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
53 { &GUID_Button
,DIJOFS_BUTTON(1),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
54 { &GUID_Button
,DIJOFS_BUTTON(2),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
55 { &GUID_Button
,DIJOFS_BUTTON(3),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
56 { &GUID_Button
,DIJOFS_BUTTON(4),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
57 { &GUID_Button
,DIJOFS_BUTTON(5),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
58 { &GUID_Button
,DIJOFS_BUTTON(6),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
59 { &GUID_Button
,DIJOFS_BUTTON(7),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
60 { &GUID_Button
,DIJOFS_BUTTON(8),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
61 { &GUID_Button
,DIJOFS_BUTTON(9),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
62 { &GUID_Button
,DIJOFS_BUTTON(10),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
65 static const DIDATAFORMAT c_dfDIJoystickTest
= {
67 sizeof(DIOBJECTDATAFORMAT
),
70 numObjects(dfDIJoystickTest
),
71 (LPDIOBJECTDATAFORMAT
)dfDIJoystickTest
74 static HWND
get_hwnd(void)
76 HWND hwnd
=GetForegroundWindow();
78 hwnd
=GetDesktopWindow();
82 typedef struct tagJoystickInfo
84 IDirectInputDeviceA
*pJoystick
;
92 static int get_refcount(IUnknown
*object
)
94 IUnknown_AddRef( object
);
95 return IUnknown_Release( object
);
98 static BOOL CALLBACK
EnumAxes(const DIDEVICEOBJECTINSTANCEA
*pdidoi
, void *pContext
)
101 JoystickInfo
* info
= pContext
;
103 if (IsEqualIID(&pdidoi
->guidType
, &GUID_XAxis
) ||
104 IsEqualIID(&pdidoi
->guidType
, &GUID_YAxis
) ||
105 IsEqualIID(&pdidoi
->guidType
, &GUID_ZAxis
) ||
106 IsEqualIID(&pdidoi
->guidType
, &GUID_RxAxis
) ||
107 IsEqualIID(&pdidoi
->guidType
, &GUID_RyAxis
) ||
108 IsEqualIID(&pdidoi
->guidType
, &GUID_RzAxis
) ||
109 IsEqualIID(&pdidoi
->guidType
, &GUID_Slider
))
114 diprg
.diph
.dwSize
= sizeof(DIPROPRANGE
);
115 diprg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
116 diprg
.diph
.dwHow
= DIPH_BYID
;
117 diprg
.diph
.dwObj
= pdidoi
->dwType
;
119 dipdw
.diph
.dwSize
= sizeof(dipdw
);
120 dipdw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
121 dipdw
.diph
.dwHow
= DIPH_BYID
;
122 dipdw
.diph
.dwObj
= pdidoi
->dwType
;
124 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
125 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
126 ok(info
->lMin
== diprg
.lMin
&& info
->lMax
== diprg
.lMax
, "Min/Max range invalid: "
127 "expected %d..%d got %d..%d\n", info
->lMin
, info
->lMax
, diprg
.lMin
, diprg
.lMax
);
132 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, NULL
);
133 ok(hr
==E_INVALIDARG
,"IDirectInputDevice_SetProperty() should have returned "
134 "E_INVALIDARG, returned: %08x\n", hr
);
136 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
137 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
140 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
141 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
142 ok(info
->dZone
== dipdw
.dwData
, "deadzone invalid: expected %d got %d\n",
143 info
->dZone
, dipdw
.dwData
);
147 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
148 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
150 /* ensure DIDOI_ASPECTPOSITION is set for axes objects */
151 ok(pdidoi
->dwFlags
& DIDOI_ASPECTPOSITION
, "Missing DIDOI_ASPECTPOSITION, flags are 0x%x\n",
155 } else if (IsEqualIID(&pdidoi
->guidType
, &GUID_POV
))
157 else if (IsEqualIID(&pdidoi
->guidType
, &GUID_Button
))
160 return DIENUM_CONTINUE
;
163 static const struct effect_id
168 } effect_conversion
[] = {
169 {&GUID_ConstantForce
, DIEFT_CONSTANTFORCE
, "Constant"},
170 {&GUID_RampForce
, DIEFT_RAMPFORCE
, "Ramp"},
171 {&GUID_Square
, DIEFT_PERIODIC
, "Square"},
172 {&GUID_Sine
, DIEFT_PERIODIC
, "Sine"},
173 {&GUID_Triangle
, DIEFT_PERIODIC
, "Triangle"},
174 {&GUID_SawtoothUp
, DIEFT_PERIODIC
, "Saw Tooth Up"},
175 {&GUID_SawtoothDown
, DIEFT_PERIODIC
, "Saw Tooth Down"},
176 {&GUID_Spring
, DIEFT_CONDITION
, "Spring"},
177 {&GUID_Damper
, DIEFT_CONDITION
, "Damper"},
178 {&GUID_Inertia
, DIEFT_CONDITION
, "Inertia"},
179 {&GUID_Friction
, DIEFT_CONDITION
, "Friction"},
180 {&GUID_CustomForce
, DIEFT_CUSTOMFORCE
, "Custom"}
183 static const struct effect_id
* effect_from_guid(const GUID
*guid
)
186 for (i
= 0; i
< sizeof(effect_conversion
) / sizeof(effect_conversion
[0]); i
++)
187 if (IsEqualGUID(guid
, effect_conversion
[i
].guid
))
188 return &effect_conversion
[i
];
197 const char *effect_name
;
200 /* The last enumerated effect will be used for force feedback testing */
201 static BOOL CALLBACK
EnumEffects(const DIEFFECTINFOA
*lpef
, void *ref
)
203 const struct effect_id
*id
= effect_from_guid(&lpef
->guid
);
206 DICONSTANTFORCE constant
;
209 DICONDITION condition
[2];
211 struct effect_enum
*data
= ref
;
212 int type
= DIDFT_GETTYPE(lpef
->dwEffType
);
217 ok(0, "unsupported effect enumerated, GUID %s!\n", wine_dbgstr_guid(&lpef
->guid
));
218 return DIENUM_CONTINUE
;
220 trace("controller supports '%s' effect\n", id
->name
);
221 ok(type
== id
->dieft
, "Invalid effect type, expected 0x%x, got 0x%x\n",
222 id
->dieft
, lpef
->dwEffType
);
224 /* Can't use custom for test as we don't know the data format */
225 if (type
== DIEFT_CUSTOMFORCE
)
226 return DIENUM_CONTINUE
;
228 data
->effect_count
++;
229 data
->effect_name
= id
->name
;
230 data
->guid
= *id
->guid
;
232 ZeroMemory(&specific
, sizeof(specific
));
236 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.periodic
);
237 data
->eff
.lpvTypeSpecificParams
= &specific
.periodic
;
238 specific
.periodic
.dwMagnitude
= DI_FFNOMINALMAX
/ 2;
239 specific
.periodic
.dwPeriod
= DI_SECONDS
; /* 1 second */
241 case DIEFT_CONSTANTFORCE
:
242 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.constant
);
243 data
->eff
.lpvTypeSpecificParams
= &specific
.constant
;
244 specific
.constant
.lMagnitude
= DI_FFNOMINALMAX
/ 2;
246 case DIEFT_RAMPFORCE
:
247 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.ramp
);
248 data
->eff
.lpvTypeSpecificParams
= &specific
.ramp
;
249 specific
.ramp
.lStart
= -DI_FFNOMINALMAX
/ 2;
250 specific
.ramp
.lEnd
= +DI_FFNOMINALMAX
/ 2;
252 case DIEFT_CONDITION
:
255 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.condition
);
256 data
->eff
.lpvTypeSpecificParams
= specific
.condition
;
257 for (i
= 0; i
< 2; i
++)
259 specific
.condition
[i
].lNegativeCoefficient
= -DI_FFNOMINALMAX
/ 2;
260 specific
.condition
[i
].lPositiveCoefficient
= +DI_FFNOMINALMAX
/ 2;
265 return DIENUM_CONTINUE
;
268 static const HRESULT SetCoop_null_window
[16] = {
269 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
270 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
271 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
272 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
274 static const HRESULT SetCoop_real_window
[16] = {
275 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
276 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
277 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
278 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
280 static BOOL CALLBACK
EnumJoysticks(const DIDEVICEINSTANCEA
*lpddi
, void *pvRef
)
283 UserData
* data
= pvRef
;
284 IDirectInputDeviceA
*pJoystick
;
291 DIDEVICEINSTANCEA inst
;
292 DIDEVICEINSTANCE_DX3A inst3
;
295 DIPROPGUIDANDPATH dpg
;
296 WCHAR nameBuffer
[MAX_PATH
];
297 HWND hWnd
= get_hwnd();
298 char oldstate
[248], curstate
[248];
299 DWORD axes
[2] = {DIJOFS_X
, DIJOFS_Y
};
300 LONG direction
[2] = {0, 0};
301 LPDIRECTINPUTEFFECT effect
= NULL
;
304 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
305 DIPROPDWORD dip_gain_set
, dip_gain_get
;
306 struct effect_enum effect_data
;
308 ok(data
->version
> 0x0300, "Joysticks not supported in version 0x%04x\n", data
->version
);
310 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
, NULL
, NULL
);
311 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
312 "E_POINTER, returned: %08x\n", hr
);
314 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, &pJoystick
, NULL
);
315 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
316 "E_POINTER, returned: %08x\n", hr
);
318 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, NULL
, NULL
);
319 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
320 "E_POINTER, returned: %08x\n", hr
);
322 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
,
324 ok(hr
==DI_OK
,"IDirectInput_CreateDevice() failed: %08x\n", hr
);
328 trace("---- Controller Information ----\n"
329 "Product Name : %s\n"
330 "Instance Name : %s\n"
332 "GUID Product : %s\n"
333 "GUID Instance : %s\n"
334 "HID Page : 0x%04x\n"
335 "HID Usage : 0x%04x\n",
336 lpddi
->tszProductName
,
337 lpddi
->tszInstanceName
,
339 wine_dbgstr_guid(&lpddi
->guidProduct
),
340 wine_dbgstr_guid(&lpddi
->guidInstance
),
344 /* Check if this is a HID device */
345 if (lpddi
->dwDevType
& DIDEVTYPE_HID
)
346 ok(lpddi
->wUsagePage
== 0x01 && (lpddi
->wUsage
== 0x04 || lpddi
->wUsage
== 0x05),
347 "Expected a game controller HID UsagePage and Usage, got page 0x%x usage 0x%x\n",
348 lpddi
->wUsagePage
, lpddi
->wUsage
);
350 /* Test for joystick ID property */
351 ZeroMemory(&dipw
, sizeof(dipw
));
352 dipw
.diph
.dwSize
= sizeof(DIPROPDWORD
);
353 dipw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
355 dipw
.diph
.dwHow
= DIPH_DEVICE
;
357 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_JOYSTICKID
, &dipw
.diph
);
358 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
360 /* Test for INSTANCENAME property */
361 memset(&dps
, 0, sizeof(dps
));
362 dps
.diph
.dwSize
= sizeof(DIPROPSTRING
);
363 dps
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
364 dps
.diph
.dwHow
= DIPH_DEVICE
;
366 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_INSTANCENAME
, &dps
.diph
);
367 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr
);
369 /* Test if instance name is the same as present in DIDEVICEINSTANCE */
370 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszInstanceName
, -1, nameBuffer
, MAX_PATH
);
371 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
372 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
374 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_PRODUCTNAME
, &dps
.diph
);
375 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_PRODUCTNAME failed: %08x\n", hr
);
377 /* Test if product name is the same as present in DIDEVICEINSTANCE */
378 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszProductName
, -1, nameBuffer
, MAX_PATH
);
379 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_PRODUCTNAME returned is wrong. Expected: %s Got: %s\n",
380 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
382 /* Test for GUIDPATH properties */
383 memset(&dpg
, 0, sizeof(dpg
));
384 dpg
.diph
.dwSize
= sizeof(DIPROPGUIDANDPATH
);
385 dpg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
386 dpg
.diph
.dwHow
= DIPH_DEVICE
;
388 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_GUIDANDPATH
, &dpg
.diph
);
389 todo_wine
ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr
);
391 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, NULL
);
392 ok(hr
==E_POINTER
,"IDirectInputDevice_SetDataFormat() should have returned "
393 "E_POINTER, returned: %08x\n", hr
);
395 ZeroMemory(&format
, sizeof(format
));
396 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &format
);
397 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_SetDataFormat() should have "
398 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
400 /* try the default formats */
401 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick
);
402 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
404 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
405 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
407 /* try an alternate format */
408 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystickTest
);
409 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
411 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
412 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
418 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, NULL
, i
);
419 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
423 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
, i
);
424 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
427 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
428 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
429 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
431 /* get capabilities */
432 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, NULL
);
433 ok(hr
==E_POINTER
,"IDirectInputDevice_GetCapabilities() "
434 "should have returned E_POINTER, returned: %08x\n", hr
);
436 ZeroMemory(&caps
, sizeof(caps
));
437 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
438 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_GetCapabilities() "
439 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
441 caps
.dwSize
= sizeof(caps
);
442 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
443 ok(hr
==DI_OK
,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr
);
445 ZeroMemory(&info
, sizeof(info
));
446 info
.pJoystick
= pJoystick
;
448 /* default min/max limits */
451 /* enumerate objects */
452 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
453 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
455 ok(caps
.dwAxes
== info
.axis
, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info
.axis
, caps
.dwAxes
);
456 ok(caps
.dwButtons
== info
.button
, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info
.button
, caps
.dwButtons
);
457 ok(caps
.dwPOVs
== info
.pov
, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info
.pov
, caps
.dwPOVs
);
459 /* Set format and check limits again */
460 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
461 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
465 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
466 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
468 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, 0);
469 ok(hr
==E_POINTER
, "IDirectInputDevice_GetDeviceInfo() "
470 "should have returned E_POINTER, returned: %08x\n", hr
);
472 ZeroMemory(&inst
, sizeof(inst
));
473 ZeroMemory(&inst3
, sizeof(inst3
));
475 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
476 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_GetDeviceInfo() "
477 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
479 inst
.dwSize
= sizeof(inst
);
480 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
481 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
483 inst3
.dwSize
= sizeof(inst3
);
484 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, (DIDEVICEINSTANCEA
*)&inst3
);
485 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
487 hr
= IDirectInputDevice_Unacquire(pJoystick
);
488 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
490 hr
= IDirectInputDevice_Acquire(pJoystick
);
491 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
495 hr
= IDirectInputDevice_Acquire(pJoystick
);
496 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr
);
500 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
501 ok(hr
== DI_OK
, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
502 ok(js
.rgdwPOV
[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js
.rgdwPOV
[3]);
505 trace("Testing force feedback\n");
506 ZeroMemory(&effect_data
, sizeof(effect_data
));
507 effect_data
.eff
.dwSize
= sizeof(effect_data
.eff
);
508 effect_data
.eff
.dwFlags
= DIEFF_CARTESIAN
| DIEFF_OBJECTOFFSETS
;
509 effect_data
.eff
.dwDuration
= INFINITE
;
510 effect_data
.eff
.dwGain
= DI_FFNOMINALMAX
;
511 effect_data
.eff
.dwTriggerButton
= DIEB_NOTRIGGER
;
512 effect_data
.eff
.cAxes
= sizeof(axes
) / sizeof(axes
[0]);
513 effect_data
.eff
.rgdwAxes
= axes
;
514 effect_data
.eff
.rglDirection
= direction
;
516 /* Sending effects to joystick requires
517 * calling IDirectInputEffect_Initialize, which requires
518 * having exclusive access to the device, which requires
519 * - not having acquired the joystick when calling
520 * IDirectInputDevice_SetCooperativeLevel
523 real_hWnd
= CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL
, NULL
,
525 ok(real_hWnd
!=0,"CreateWindowExA failed: %p\n", real_hWnd
);
526 ShowWindow(real_hWnd
, SW_SHOW
);
527 hr
= IDirectInputDevice_Unacquire(pJoystick
);
528 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
529 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, real_hWnd
,
530 DISCL_EXCLUSIVE
| DISCL_FOREGROUND
);
531 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
532 hr
= IDirectInputDevice_Acquire(pJoystick
);
533 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
535 cnt1
= get_refcount((IUnknown
*)pJoystick
);
537 hr
= IDirectInputDevice2_EnumEffects((IDirectInputDevice2A
*)pJoystick
, EnumEffects
, &effect_data
, DIEFT_ALL
);
538 ok(hr
==DI_OK
,"IDirectInputDevice2_EnumEffects() failed: %08x\n", hr
);
540 /* If the controller does not support ANY effect use the constant effect to make
541 * CreateEffect fail but with the unsupported reason instead of invalid parameters. */
542 if (!effect_data
.effect_count
)
544 static DICONSTANTFORCE constant
;
545 effect_data
.guid
= GUID_ConstantForce
;
546 effect_data
.eff
.cbTypeSpecificParams
= sizeof(constant
);
547 effect_data
.eff
.lpvTypeSpecificParams
= &constant
;
548 effect_data
.effect_name
= "Constant";
549 constant
.lMagnitude
= DI_FFNOMINALMAX
/ 2;
551 ok(!(caps
.dwFlags
& DIDC_FORCEFEEDBACK
), "effect count is zero but controller supports force feedback?\n");
554 effect
= (void *)0xdeadbeef;
555 hr
= IDirectInputDevice2_CreateEffect((IDirectInputDevice2A
*)pJoystick
, &effect_data
.guid
,
556 &effect_data
.eff
, &effect
, NULL
);
557 if (caps
.dwFlags
& DIDC_FORCEFEEDBACK
)
559 trace("force feedback supported with %d effects, using '%s' for test\n",
560 effect_data
.effect_count
, effect_data
.effect_name
);
561 ok(hr
== DI_OK
, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr
);
562 cnt2
= get_refcount((IUnknown
*)pJoystick
);
563 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
568 struct DIPROPDWORD diprop_word
;
571 hr
= IDirectInputEffect_Initialize(effect
, hInstance
, data
->version
,
573 ok(hr
==DI_OK
,"IDirectInputEffect_Initialize failed: %08x\n", hr
);
574 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_AXES
| DIEP_DIRECTION
|
575 DIEP_TYPESPECIFICPARAMS
);
576 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
578 /* Test that upload, unacquire, acquire still permits updating
579 * uploaded effect. */
580 hr
= IDirectInputDevice_Unacquire(pJoystick
);
581 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
582 hr
= IDirectInputDevice_Acquire(pJoystick
);
583 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
584 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_GAIN
);
585 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
588 /* Check effect status.
589 * State: initially stopped
592 * unacquire, acquire, download
598 * - effects are stopped after Unacquire + Acquire
599 * - effects are preserved (Download + Start doesn't complain
600 * about incomplete effect)
602 hr
= IDirectInputEffect_GetEffectStatus(effect
, NULL
);
603 ok(hr
==E_POINTER
,"IDirectInputEffect_GetEffectStatus() must fail with E_POINTER, got: %08x\n", hr
);
604 effect_status
= 0xdeadbeef;
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_SetParameters(effect
, &effect_data
.eff
, DIEP_START
);
609 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
610 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
611 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
612 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
613 hr
= IDirectInputDevice_Unacquire(pJoystick
);
614 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
615 hr
= IDirectInputDevice_Acquire(pJoystick
);
616 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
617 hr
= IDirectInputEffect_Download(effect
);
618 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
619 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
620 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
621 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
622 hr
= IDirectInputEffect_Start(effect
, 1, 0);
623 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
624 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
625 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
626 Sleep(250); /* feel the magic */
627 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
628 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
629 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
630 ok(IsEqualGUID(&effect_data
.guid
, &guid
), "Wrong guid returned\n");
632 /* Check autocenter status
633 * State: initially stopped
641 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
642 * executed when the device is released.
644 * If Executed interactively, user can feel that autocenter is
645 * only disabled when the joystick is acquired.
647 diprop_word
.diph
.dwSize
= sizeof(diprop_word
);
648 diprop_word
.diph
.dwHeaderSize
= sizeof(diprop_word
.diph
);
649 diprop_word
.diph
.dwObj
= 0;
650 diprop_word
.diph
.dwHow
= DIPH_DEVICE
;
651 hr
= IDirectInputDevice_Unacquire(pJoystick
);
652 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
653 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
654 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
655 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_ON
,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
656 diprop_word
.dwData
= DIPROPAUTOCENTER_OFF
;
657 hr
= IDirectInputDevice2_SetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
658 ok(hr
==DI_OK
,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr
);
659 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
660 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
661 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
662 if (winetest_interactive
) {
663 trace("Acquiring in 2s, autocenter will be disabled.\n");
666 hr
= IDirectInputDevice_Acquire(pJoystick
);
667 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
668 if (winetest_interactive
)
669 trace("Acquired.\n");
670 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
671 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
672 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
673 if (winetest_interactive
) {
674 trace("Releasing in 2s, autocenter will be re-enabled.\n");
677 hr
= IDirectInputDevice_Unacquire(pJoystick
);
678 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
679 if (winetest_interactive
)
681 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
682 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
683 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
684 hr
= IDirectInputDevice_Acquire(pJoystick
);
685 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
686 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
687 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
689 /* Device gain (DIPROP_FFGAIN).
691 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
692 * Can be changed even if device is acquired.
693 * Difference found by tests:
694 * <0 is refused, >10000 is accepted
696 dip_gain_set
.diph
.dwSize
= sizeof(DIPROPDWORD
);
697 dip_gain_set
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
698 dip_gain_set
.diph
.dwObj
= 0;
699 dip_gain_set
.diph
.dwHow
= DIPH_DEVICE
;
700 dip_gain_get
.diph
.dwSize
= sizeof(DIPROPDWORD
);
701 dip_gain_get
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
702 dip_gain_get
.diph
.dwObj
= 0;
703 dip_gain_get
.diph
.dwHow
= DIPH_DEVICE
;
704 dip_gain_get
.dwData
= 0;
706 /* Test device is acquisition (non)impact. */
707 hr
= IDirectInputDevice_Unacquire(pJoystick
);
708 ok(hr
== DI_OK
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
709 dip_gain_set
.dwData
= 1;
710 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
711 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
712 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
713 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
714 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
715 hr
= IDirectInputDevice_Acquire(pJoystick
);
716 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
717 dip_gain_set
.dwData
= 2;
718 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
719 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
720 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
721 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
722 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
723 /* Test range and internal clamping. */
724 dip_gain_set
.dwData
= -1;
725 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
726 todo_wine
ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM
, hr
);
727 dip_gain_set
.dwData
= 0;
728 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
729 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
730 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
731 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
732 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
733 dip_gain_set
.dwData
= 10000;
734 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
735 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
736 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
737 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
738 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
739 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
740 dip_gain_set
.dwData
= 10001;
741 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
742 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
743 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
744 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
745 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
747 ref
= IUnknown_Release(effect
);
748 ok(ref
== 0, "IDirectInputDevice_Release() reference count = %d\n", ref
);
750 cnt1
= get_refcount((IUnknown
*)pJoystick
);
751 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
753 /* No force feedback support, CreateEffect is supposed to fail. Fairy Bloom Freesia
754 * calls CreateEffect without checking the DIDC_FORCEFEEDBACK. It expects the correct
755 * error return to determine if force feedback is unsupported. */
758 trace("No force feedback support\n");
759 ok(hr
==DIERR_UNSUPPORTED
, "IDirectInputDevice_CreateEffect() must fail with DIERR_UNSUPPORTED, got: %08x\n", hr
);
760 ok(effect
== NULL
, "effect must be NULL, got %p\n", effect
);
763 /* Before destroying the window, release joystick to revert to
764 * non-exclusive, background cooperative level. */
765 hr
= IDirectInputDevice_Unacquire(pJoystick
);
766 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
767 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
768 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
769 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
770 DestroyWindow (real_hWnd
);
771 hr
= IDirectInputDevice_Acquire(pJoystick
);
772 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
774 if (winetest_interactive
) {
775 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
782 for (i
= 0; i
< count
; i
++) {
783 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
784 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
787 sprintf(curstate
, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
788 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
789 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
790 js
.lX
, js
.lY
, js
.lZ
, js
.lRx
, js
.lRy
, js
.lRz
,
791 js
.rglSlider
[0], js
.rglSlider
[1],
792 js
.rgdwPOV
[0], js
.rgdwPOV
[1], js
.rgdwPOV
[2], js
.rgdwPOV
[3],
793 js
.rgbButtons
[0]>>7, js
.rgbButtons
[1]>>7, js
.rgbButtons
[2]>>7,
794 js
.rgbButtons
[3]>>7, js
.rgbButtons
[4]>>7, js
.rgbButtons
[5]>>7,
795 js
.rgbButtons
[6]>>7, js
.rgbButtons
[7]>>7, js
.rgbButtons
[8]>>7,
796 js
.rgbButtons
[9]>>7, js
.rgbButtons
[10]>>7, js
.rgbButtons
[11]>>7);
797 if (strcmp(oldstate
, curstate
) != 0)
799 trace("%s\n", curstate
);
800 strcpy(oldstate
, curstate
);
806 hr
= IDirectInputDevice_Unacquire(pJoystick
);
807 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
810 ref
= IDirectInputDevice_Release(pJoystick
);
811 ok(ref
==0,"IDirectInputDevice_Release() reference count = %d\n", ref
);
814 return DIENUM_CONTINUE
;
817 static void joystick_tests(DWORD version
)
822 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
824 trace("-- Testing Direct Input Version 0x%04x --\n", version
);
825 hr
= DirectInputCreateA(hInstance
, version
, &pDI
, NULL
);
826 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
, "DirectInputCreateA() failed: %08x\n", hr
);
827 if (hr
==DI_OK
&& pDI
!=0) {
830 data
.version
= version
;
831 hr
= IDirectInput_EnumDevices(pDI
, DIDEVTYPE_JOYSTICK
, EnumJoysticks
,
832 &data
, DIEDFL_ALLDEVICES
);
833 ok(hr
==DI_OK
,"IDirectInput_EnumDevices() failed: %08x\n", hr
);
834 ref
= IDirectInput_Release(pDI
);
835 ok(ref
==0,"IDirectInput_Release() reference count = %d\n", ref
);
836 } else if (hr
==DIERR_OLDDIRECTINPUTVERSION
)
837 trace(" Version Not Supported\n");
844 joystick_tests(0x0700);
845 joystick_tests(0x0500);
846 joystick_tests(0x0300);