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
);
151 } else if (IsEqualIID(&pdidoi
->guidType
, &GUID_POV
))
153 else if (IsEqualIID(&pdidoi
->guidType
, &GUID_Button
))
156 return DIENUM_CONTINUE
;
159 static const HRESULT SetCoop_null_window
[16] = {
160 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
161 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
162 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
163 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
165 static const HRESULT SetCoop_real_window
[16] = {
166 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
167 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
168 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
169 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
171 static BOOL CALLBACK
EnumJoysticks(const DIDEVICEINSTANCEA
*lpddi
, void *pvRef
)
174 UserData
* data
= pvRef
;
175 IDirectInputDeviceA
*pJoystick
;
182 DIDEVICEINSTANCEA inst
;
183 DIDEVICEINSTANCE_DX3A inst3
;
186 DIPROPGUIDANDPATH dpg
;
187 WCHAR nameBuffer
[MAX_PATH
];
188 HWND hWnd
= get_hwnd();
189 char oldstate
[248], curstate
[248];
191 ok(data
->version
> 0x0300, "Joysticks not supported in version 0x%04x\n", data
->version
);
193 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
, NULL
, NULL
);
194 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
195 "E_POINTER, returned: %08x\n", hr
);
197 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, &pJoystick
, NULL
);
198 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
199 "E_POINTER, returned: %08x\n", hr
);
201 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, NULL
, NULL
);
202 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
203 "E_POINTER, returned: %08x\n", hr
);
205 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
,
207 ok(hr
==DI_OK
,"IDirectInput_CreateDevice() failed: %08x\n", hr
);
211 trace("---- %s ----\n", lpddi
->tszProductName
);
213 /* Test for joystick ID property */
214 ZeroMemory(&dipw
, sizeof(dipw
));
215 dipw
.diph
.dwSize
= sizeof(DIPROPDWORD
);
216 dipw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
218 dipw
.diph
.dwHow
= DIPH_DEVICE
;
220 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_JOYSTICKID
, &dipw
.diph
);
221 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
223 /* Test for INSTANCENAME property */
224 memset(&dps
, 0, sizeof(dps
));
225 dps
.diph
.dwSize
= sizeof(DIPROPSTRING
);
226 dps
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
227 dps
.diph
.dwHow
= DIPH_DEVICE
;
229 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_INSTANCENAME
, &dps
.diph
);
230 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr
);
232 /* Test if instance name is the same as present in DIDEVICEINSTANCE */
233 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszInstanceName
, -1, nameBuffer
, MAX_PATH
);
234 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
235 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
237 /* Test for GUIDPATH properties */
238 memset(&dpg
, 0, sizeof(dpg
));
239 dpg
.diph
.dwSize
= sizeof(DIPROPGUIDANDPATH
);
240 dpg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
241 dpg
.diph
.dwHow
= DIPH_DEVICE
;
243 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_GUIDANDPATH
, &dpg
.diph
);
244 todo_wine
ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr
);
246 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, NULL
);
247 ok(hr
==E_POINTER
,"IDirectInputDevice_SetDataFormat() should have returned "
248 "E_POINTER, returned: %08x\n", hr
);
250 ZeroMemory(&format
, sizeof(format
));
251 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &format
);
252 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_SetDataFormat() should have "
253 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
255 /* try the default formats */
256 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick
);
257 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
259 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
260 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
262 /* try an alternate format */
263 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystickTest
);
264 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
266 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
267 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
273 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, NULL
, i
);
274 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
278 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
, i
);
279 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
282 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
283 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
284 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
286 /* get capabilities */
287 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, NULL
);
288 ok(hr
==E_POINTER
,"IDirectInputDevice_GetCapabilities() "
289 "should have returned E_POINTER, returned: %08x\n", hr
);
291 ZeroMemory(&caps
, sizeof(caps
));
292 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
293 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_GetCapabilities() "
294 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
296 caps
.dwSize
= sizeof(caps
);
297 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
298 ok(hr
==DI_OK
,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr
);
300 ZeroMemory(&info
, sizeof(info
));
301 info
.pJoystick
= pJoystick
;
303 /* default min/max limits */
306 /* enumerate objects */
307 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
308 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
310 ok(caps
.dwAxes
== info
.axis
, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info
.axis
, caps
.dwAxes
);
311 ok(caps
.dwButtons
== info
.button
, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info
.button
, caps
.dwButtons
);
312 ok(caps
.dwPOVs
== info
.pov
, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info
.pov
, caps
.dwPOVs
);
314 /* Set format and check limits again */
315 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
316 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
320 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
321 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
323 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, 0);
324 ok(hr
==E_POINTER
, "IDirectInputDevice_GetDeviceInfo() "
325 "should have returned E_POINTER, returned: %08x\n", hr
);
327 ZeroMemory(&inst
, sizeof(inst
));
328 ZeroMemory(&inst3
, sizeof(inst3
));
330 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
331 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_GetDeviceInfo() "
332 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
334 inst
.dwSize
= sizeof(inst
);
335 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
336 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
338 inst3
.dwSize
= sizeof(inst3
);
339 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, (DIDEVICEINSTANCEA
*)&inst3
);
340 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
342 hr
= IDirectInputDevice_Unacquire(pJoystick
);
343 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
345 hr
= IDirectInputDevice_Acquire(pJoystick
);
346 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
350 hr
= IDirectInputDevice_Acquire(pJoystick
);
351 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr
);
355 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
356 ok(hr
== DI_OK
, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
357 ok(js
.rgdwPOV
[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js
.rgdwPOV
[3]);
360 if (caps
.dwFlags
& DIDC_FORCEFEEDBACK
)
362 DWORD axes
[2] = {DIJOFS_X
, DIJOFS_Y
};
363 LONG direction
[2] = {0, 0};
364 DICONSTANTFORCE force
= {0};
366 LPDIRECTINPUTEFFECT effect
= NULL
;
369 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
370 DIPROPDWORD dip_gain_set
, dip_gain_get
;
372 trace("Testing force-feedback\n");
373 memset(&eff
, 0, sizeof(eff
));
374 eff
.dwSize
= sizeof(eff
);
375 eff
.dwFlags
= DIEFF_CARTESIAN
| DIEFF_OBJECTOFFSETS
;
376 eff
.dwDuration
= INFINITE
;
377 eff
.dwGain
= DI_FFNOMINALMAX
;
378 eff
.dwTriggerButton
= DIEB_NOTRIGGER
;
379 eff
.cAxes
= sizeof(axes
) / sizeof(axes
[0]);
381 eff
.rglDirection
= direction
;
382 eff
.cbTypeSpecificParams
= sizeof(force
);
383 eff
.lpvTypeSpecificParams
= &force
;
385 /* Sending effects to joystick requires
386 * calling IDirectInputEffect_Initialize, which requires
387 * having exclusive access to the device, which requires
388 * - not having acquired the joystick when calling
389 * IDirectInputDevice_SetCooperativeLevel
392 real_hWnd
= CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL
, NULL
,
394 ok(real_hWnd
!=0,"CreateWindowExA failed: %p\n", real_hWnd
);
395 ShowWindow(real_hWnd
, SW_SHOW
);
396 hr
= IDirectInputDevice_Unacquire(pJoystick
);
397 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
398 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, real_hWnd
,
399 DISCL_EXCLUSIVE
| DISCL_FOREGROUND
);
400 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
401 hr
= IDirectInputDevice_Acquire(pJoystick
);
402 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
404 cnt1
= get_refcount((IUnknown
*)pJoystick
);
406 hr
= IDirectInputDevice2_CreateEffect((IDirectInputDevice2A
*)pJoystick
, &GUID_ConstantForce
,
407 &eff
, &effect
, NULL
);
408 ok(hr
== DI_OK
, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr
);
409 cnt2
= get_refcount((IUnknown
*)pJoystick
);
410 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
415 struct DIPROPDWORD diprop_word
;
418 hr
= IDirectInputEffect_Initialize(effect
, hInstance
, data
->version
,
419 &GUID_ConstantForce
);
420 ok(hr
==DI_OK
,"IDirectInputEffect_Initialize failed: %08x\n", hr
);
421 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_AXES
| DIEP_DIRECTION
|
422 DIEP_TYPESPECIFICPARAMS
);
423 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
425 /* Test that upload, unacquire, acquire still permits updating
426 * uploaded effect. */
427 hr
= IDirectInputDevice_Unacquire(pJoystick
);
428 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
429 hr
= IDirectInputDevice_Acquire(pJoystick
);
430 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
431 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_GAIN
);
432 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
435 /* Check effect status.
436 * State: initially stopped
439 * unacquire, acquire, download
445 * - effects are stopped after Unacquire + Acquire
446 * - effects are preserved (Download + Start doesn't complain
447 * about incomplete effect)
449 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
450 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
451 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
452 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_START
);
453 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
454 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
455 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
456 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
457 hr
= IDirectInputDevice_Unacquire(pJoystick
);
458 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
459 hr
= IDirectInputDevice_Acquire(pJoystick
);
460 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
461 hr
= IDirectInputEffect_Download(effect
);
462 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
463 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
464 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
465 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
466 hr
= IDirectInputEffect_Start(effect
, 1, 0);
467 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
468 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
469 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
470 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
471 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
472 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
473 ok(IsEqualGUID(&GUID_ConstantForce
, &guid
), "Wrong guid returned\n");
475 /* Check autocenter status
476 * State: initially stopped
484 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
485 * executed when the device is released.
487 * If Executed interactively, user can feel that autocenter is
488 * only disabled when the joystick is acquired.
490 diprop_word
.diph
.dwSize
= sizeof(diprop_word
);
491 diprop_word
.diph
.dwHeaderSize
= sizeof(diprop_word
.diph
);
492 diprop_word
.diph
.dwObj
= 0;
493 diprop_word
.diph
.dwHow
= DIPH_DEVICE
;
494 hr
= IDirectInputDevice_Unacquire(pJoystick
);
495 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
496 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
497 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
498 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_ON
,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
499 diprop_word
.dwData
= DIPROPAUTOCENTER_OFF
;
500 hr
= IDirectInputDevice2_SetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
501 ok(hr
==DI_OK
,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr
);
502 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
503 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
504 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
505 if (winetest_interactive
) {
506 trace("Acquiring in 2s, autocenter will be disabled.\n");
509 hr
= IDirectInputDevice_Acquire(pJoystick
);
510 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
511 if (winetest_interactive
)
512 trace("Acquired.\n");
513 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
514 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
515 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
516 if (winetest_interactive
) {
517 trace("Releasing in 2s, autocenter will be re-enabled.\n");
520 hr
= IDirectInputDevice_Unacquire(pJoystick
);
521 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
522 if (winetest_interactive
)
524 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
525 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
526 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
527 hr
= IDirectInputDevice_Acquire(pJoystick
);
528 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
529 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
530 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
532 /* Device gain (DIPROP_FFGAIN).
534 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
535 * Can be changed even if device is acquired.
536 * Difference found by tests:
537 * <0 is refused, >10000 is accepted
539 dip_gain_set
.diph
.dwSize
= sizeof(DIPROPDWORD
);
540 dip_gain_set
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
541 dip_gain_set
.diph
.dwObj
= 0;
542 dip_gain_set
.diph
.dwHow
= DIPH_DEVICE
;
543 dip_gain_set
.dwData
= 10000;
544 dip_gain_get
.diph
.dwSize
= sizeof(DIPROPDWORD
);
545 dip_gain_get
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
546 dip_gain_get
.diph
.dwObj
= 0;
547 dip_gain_get
.diph
.dwHow
= DIPH_DEVICE
;
548 dip_gain_get
.dwData
= 0;
550 /* Test device is acquisition (non)impact. */
551 hr
= IDirectInputDevice_Unacquire(pJoystick
);
552 ok(hr
== DI_OK
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
553 dip_gain_set
.dwData
= 1;
554 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
555 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
556 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
557 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
558 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
559 hr
= IDirectInputDevice_Acquire(pJoystick
);
560 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
561 dip_gain_set
.dwData
= 2;
562 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
563 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
564 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
565 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
566 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
567 /* Test range and internal clamping. */
568 dip_gain_set
.dwData
= -1;
569 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
570 todo_wine
ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM
, hr
);
571 dip_gain_set
.dwData
= 0;
572 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
573 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
574 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
575 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
576 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
577 dip_gain_set
.dwData
= 10000;
578 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
579 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
580 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
581 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
582 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
583 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
584 dip_gain_set
.dwData
= 10001;
585 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
586 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
587 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
588 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
589 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
591 ref
= IUnknown_Release(effect
);
592 ok(ref
== 0, "IDirectInputDevice_Release() reference count = %d\n", ref
);
594 cnt1
= get_refcount((IUnknown
*)pJoystick
);
595 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
597 /* Before destroying the window, release joystick to revert to
598 * non-exclusive, background cooperative level. */
599 hr
= IDirectInputDevice_Unacquire(pJoystick
);
600 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
601 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
602 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
603 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
604 DestroyWindow (real_hWnd
);
605 hr
= IDirectInputDevice_Acquire(pJoystick
);
606 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
609 if (winetest_interactive
) {
610 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
617 for (i
= 0; i
< count
; i
++) {
618 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
619 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
622 sprintf(curstate
, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
623 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
624 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
625 js
.lX
, js
.lY
, js
.lZ
, js
.lRx
, js
.lRy
, js
.lRz
,
626 js
.rglSlider
[0], js
.rglSlider
[1],
627 js
.rgdwPOV
[0], js
.rgdwPOV
[1], js
.rgdwPOV
[2], js
.rgdwPOV
[3],
628 js
.rgbButtons
[0]>>7, js
.rgbButtons
[1]>>7, js
.rgbButtons
[2]>>7,
629 js
.rgbButtons
[3]>>7, js
.rgbButtons
[4]>>7, js
.rgbButtons
[5]>>7,
630 js
.rgbButtons
[6]>>7, js
.rgbButtons
[7]>>7, js
.rgbButtons
[8]>>7,
631 js
.rgbButtons
[9]>>7, js
.rgbButtons
[10]>>7, js
.rgbButtons
[11]>>7);
632 if (strcmp(oldstate
, curstate
) != 0)
634 trace("%s\n", curstate
);
635 strcpy(oldstate
, curstate
);
641 hr
= IDirectInputDevice_Unacquire(pJoystick
);
642 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
645 ref
= IDirectInputDevice_Release(pJoystick
);
646 ok(ref
==0,"IDirectInputDevice_Release() reference count = %d\n", ref
);
649 return DIENUM_CONTINUE
;
652 static void joystick_tests(DWORD version
)
657 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
659 trace("-- Testing Direct Input Version 0x%04x --\n", version
);
660 hr
= DirectInputCreateA(hInstance
, version
, &pDI
, NULL
);
661 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
, "DirectInputCreateA() failed: %08x\n", hr
);
662 if (hr
==DI_OK
&& pDI
!=0) {
665 data
.version
= version
;
666 hr
= IDirectInput_EnumDevices(pDI
, DIDEVTYPE_JOYSTICK
, EnumJoysticks
,
667 &data
, DIEDFL_ALLDEVICES
);
668 ok(hr
==DI_OK
,"IDirectInput_EnumDevices() failed: %08x\n", hr
);
669 ref
= IDirectInput_Release(pDI
);
670 ok(ref
==0,"IDirectInput_Release() reference count = %d\n", ref
);
671 } else if (hr
==DIERR_OLDDIRECTINPUTVERSION
)
672 trace(" Version Not Supported\n");
679 joystick_tests(0x0700);
680 joystick_tests(0x0500);
681 joystick_tests(0x0300);