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 DIRECTINPUT_VERSION 0x0700
28 #include "wine/test.h"
33 #define numObjects(x) (sizeof(x) / sizeof(x[0]))
35 typedef struct tagUserData
{
40 static const DIOBJECTDATAFORMAT dfDIJoystickTest
[] = {
41 { &GUID_XAxis
,DIJOFS_X
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
42 { &GUID_YAxis
,DIJOFS_Y
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
43 { &GUID_ZAxis
,DIJOFS_Z
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
44 { &GUID_RxAxis
,DIJOFS_RX
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
45 { &GUID_RyAxis
,DIJOFS_RY
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
46 { &GUID_RzAxis
,DIJOFS_RZ
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
47 { &GUID_Button
,DIJOFS_BUTTON(0),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
48 { &GUID_Button
,DIJOFS_BUTTON(1),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
49 { &GUID_Button
,DIJOFS_BUTTON(2),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
50 { &GUID_Button
,DIJOFS_BUTTON(3),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
51 { &GUID_Button
,DIJOFS_BUTTON(4),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
52 { &GUID_Button
,DIJOFS_BUTTON(5),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
53 { &GUID_Button
,DIJOFS_BUTTON(6),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
54 { &GUID_Button
,DIJOFS_BUTTON(7),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
55 { &GUID_Button
,DIJOFS_BUTTON(8),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
56 { &GUID_Button
,DIJOFS_BUTTON(9),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
57 { &GUID_Button
,DIJOFS_BUTTON(10),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
60 static const DIDATAFORMAT c_dfDIJoystickTest
= {
62 sizeof(DIOBJECTDATAFORMAT
),
65 numObjects(dfDIJoystickTest
),
66 (LPDIOBJECTDATAFORMAT
)dfDIJoystickTest
69 static HWND
get_hwnd(void)
71 HWND hwnd
=GetForegroundWindow();
73 hwnd
=GetDesktopWindow();
77 typedef struct tagJoystickInfo
79 IDirectInputDeviceA
*pJoystick
;
87 static int get_refcount(IUnknown
*object
)
89 IUnknown_AddRef( object
);
90 return IUnknown_Release( object
);
93 static BOOL CALLBACK
EnumAxes(const DIDEVICEOBJECTINSTANCEA
*pdidoi
, void *pContext
)
96 JoystickInfo
* info
= pContext
;
98 if (IsEqualIID(&pdidoi
->guidType
, &GUID_XAxis
) ||
99 IsEqualIID(&pdidoi
->guidType
, &GUID_YAxis
) ||
100 IsEqualIID(&pdidoi
->guidType
, &GUID_ZAxis
) ||
101 IsEqualIID(&pdidoi
->guidType
, &GUID_RxAxis
) ||
102 IsEqualIID(&pdidoi
->guidType
, &GUID_RyAxis
) ||
103 IsEqualIID(&pdidoi
->guidType
, &GUID_RzAxis
) ||
104 IsEqualIID(&pdidoi
->guidType
, &GUID_Slider
))
109 diprg
.diph
.dwSize
= sizeof(DIPROPRANGE
);
110 diprg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
111 diprg
.diph
.dwHow
= DIPH_BYID
;
112 diprg
.diph
.dwObj
= pdidoi
->dwType
;
114 dipdw
.diph
.dwSize
= sizeof(dipdw
);
115 dipdw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
116 dipdw
.diph
.dwHow
= DIPH_BYID
;
117 dipdw
.diph
.dwObj
= pdidoi
->dwType
;
119 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
120 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
121 ok(info
->lMin
== diprg
.lMin
&& info
->lMax
== diprg
.lMax
, "Min/Max range invalid: "
122 "expected %d..%d got %d..%d\n", info
->lMin
, info
->lMax
, diprg
.lMin
, diprg
.lMax
);
127 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, NULL
);
128 ok(hr
==E_INVALIDARG
,"IDirectInputDevice_SetProperty() should have returned "
129 "E_INVALIDARG, returned: %08x\n", hr
);
131 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
132 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
135 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
136 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
137 ok(info
->dZone
== dipdw
.dwData
, "deadzone invalid: expected %d got %d\n",
138 info
->dZone
, dipdw
.dwData
);
142 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
143 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
146 } else if (IsEqualIID(&pdidoi
->guidType
, &GUID_POV
))
148 else if (IsEqualIID(&pdidoi
->guidType
, &GUID_Button
))
151 return DIENUM_CONTINUE
;
154 static const HRESULT SetCoop_null_window
[16] = {
155 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
156 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
157 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
158 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
160 static const HRESULT SetCoop_real_window
[16] = {
161 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
162 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
163 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
164 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
166 static BOOL CALLBACK
EnumJoysticks(const DIDEVICEINSTANCEA
*lpddi
, void *pvRef
)
169 UserData
* data
= pvRef
;
170 IDirectInputDeviceA
*pJoystick
;
177 DIDEVICEINSTANCEA inst
;
178 DIDEVICEINSTANCE_DX3A inst3
;
181 DIPROPGUIDANDPATH dpg
;
182 WCHAR nameBuffer
[MAX_PATH
];
183 HWND hWnd
= get_hwnd();
184 char oldstate
[248], curstate
[248];
186 ok(data
->version
> 0x0300, "Joysticks not supported in version 0x%04x\n", data
->version
);
188 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
, NULL
, NULL
);
189 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
190 "E_POINTER, returned: %08x\n", hr
);
192 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, &pJoystick
, NULL
);
193 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
194 "E_POINTER, returned: %08x\n", hr
);
196 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, NULL
, NULL
);
197 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
198 "E_POINTER, returned: %08x\n", hr
);
200 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
,
202 ok(hr
==DI_OK
,"IDirectInput_CreateDevice() failed: %08x\n", hr
);
206 trace("---- %s ----\n", lpddi
->tszProductName
);
208 /* Test for joystick ID property */
209 ZeroMemory(&dipw
, sizeof(dipw
));
210 dipw
.diph
.dwSize
= sizeof(DIPROPDWORD
);
211 dipw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
213 dipw
.diph
.dwHow
= DIPH_DEVICE
;
215 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_JOYSTICKID
, &dipw
.diph
);
216 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
218 /* Test for INSTANCENAME property */
219 memset(&dps
, 0, sizeof(dps
));
220 dps
.diph
.dwSize
= sizeof(DIPROPSTRING
);
221 dps
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
222 dps
.diph
.dwHow
= DIPH_DEVICE
;
224 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_INSTANCENAME
, &dps
.diph
);
225 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr
);
227 /* Test if instance name is the same as present in DIDEVICEINSTANCE */
228 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszInstanceName
, -1, nameBuffer
, MAX_PATH
);
229 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
230 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
232 /* Test for GUIDPATH properties */
233 memset(&dpg
, 0, sizeof(dpg
));
234 dpg
.diph
.dwSize
= sizeof(DIPROPGUIDANDPATH
);
235 dpg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
236 dpg
.diph
.dwHow
= DIPH_DEVICE
;
238 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_GUIDANDPATH
, &dpg
.diph
);
239 todo_wine
ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr
);
241 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, NULL
);
242 ok(hr
==E_POINTER
,"IDirectInputDevice_SetDataFormat() should have returned "
243 "E_POINTER, returned: %08x\n", hr
);
245 ZeroMemory(&format
, sizeof(format
));
246 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &format
);
247 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_SetDataFormat() should have "
248 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
250 /* try the default formats */
251 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick
);
252 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
254 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
255 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
257 /* try an alternate format */
258 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystickTest
);
259 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
261 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
262 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
268 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, NULL
, i
);
269 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
273 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
, i
);
274 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
277 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
278 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
279 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
281 /* get capabilities */
282 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, NULL
);
283 ok(hr
==E_POINTER
,"IDirectInputDevice_GetCapabilities() "
284 "should have returned E_POINTER, returned: %08x\n", hr
);
286 ZeroMemory(&caps
, sizeof(caps
));
287 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
288 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_GetCapabilities() "
289 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
291 caps
.dwSize
= sizeof(caps
);
292 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
293 ok(hr
==DI_OK
,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr
);
295 ZeroMemory(&info
, sizeof(info
));
296 info
.pJoystick
= pJoystick
;
298 /* default min/max limits */
301 /* enumerate objects */
302 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
303 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
305 ok(caps
.dwAxes
== info
.axis
, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info
.axis
, caps
.dwAxes
);
306 ok(caps
.dwButtons
== info
.button
, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info
.button
, caps
.dwButtons
);
307 ok(caps
.dwPOVs
== info
.pov
, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info
.pov
, caps
.dwPOVs
);
309 /* Set format and check limits again */
310 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
311 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
315 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
316 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
318 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, 0);
319 ok(hr
==E_POINTER
, "IDirectInputDevice_GetDeviceInfo() "
320 "should have returned E_POINTER, returned: %08x\n", hr
);
322 ZeroMemory(&inst
, sizeof(inst
));
323 ZeroMemory(&inst3
, sizeof(inst3
));
325 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
326 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_GetDeviceInfo() "
327 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
329 inst
.dwSize
= sizeof(inst
);
330 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
331 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
333 inst3
.dwSize
= sizeof(inst3
);
334 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, (DIDEVICEINSTANCEA
*)&inst3
);
335 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
337 hr
= IDirectInputDevice_Unacquire(pJoystick
);
338 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
340 hr
= IDirectInputDevice_Acquire(pJoystick
);
341 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
345 hr
= IDirectInputDevice_Acquire(pJoystick
);
346 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr
);
350 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
351 ok(hr
== DI_OK
, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
352 ok(js
.rgdwPOV
[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js
.rgdwPOV
[3]);
355 if (caps
.dwFlags
& DIDC_FORCEFEEDBACK
)
357 DWORD axes
[2] = {DIJOFS_X
, DIJOFS_Y
};
358 LONG direction
[2] = {0, 0};
359 DICONSTANTFORCE force
= {0};
361 LPDIRECTINPUTEFFECT effect
= NULL
;
364 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
365 DIPROPDWORD dip_gain_set
, dip_gain_get
;
367 trace("Testing force-feedback\n");
368 memset(&eff
, 0, sizeof(eff
));
369 eff
.dwSize
= sizeof(eff
);
370 eff
.dwFlags
= DIEFF_CARTESIAN
| DIEFF_OBJECTOFFSETS
;
371 eff
.dwDuration
= INFINITE
;
372 eff
.dwGain
= DI_FFNOMINALMAX
;
373 eff
.dwTriggerButton
= DIEB_NOTRIGGER
;
374 eff
.cAxes
= sizeof(axes
) / sizeof(axes
[0]);
376 eff
.rglDirection
= direction
;
377 eff
.cbTypeSpecificParams
= sizeof(force
);
378 eff
.lpvTypeSpecificParams
= &force
;
380 /* Sending effects to joystick requires
381 * calling IDirectInputEffect_Initialize, which requires
382 * having exclusive access to the device, which requires
383 * - not having acquired the joystick when calling
384 * IDirectInputDevice_SetCooperativeLevel
387 real_hWnd
= CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL
, NULL
,
389 ok(real_hWnd
!=0,"CreateWindowExA failed: %p\n", real_hWnd
);
390 ShowWindow(real_hWnd
, SW_SHOW
);
391 hr
= IDirectInputDevice_Unacquire(pJoystick
);
392 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
393 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, real_hWnd
,
394 DISCL_EXCLUSIVE
| DISCL_FOREGROUND
);
395 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
396 hr
= IDirectInputDevice_Acquire(pJoystick
);
397 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
399 cnt1
= get_refcount((IUnknown
*)pJoystick
);
401 hr
= IDirectInputDevice2_CreateEffect((IDirectInputDevice2A
*)pJoystick
, &GUID_ConstantForce
,
402 &eff
, &effect
, NULL
);
403 ok(hr
== DI_OK
, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr
);
404 cnt2
= get_refcount((IUnknown
*)pJoystick
);
405 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
410 struct DIPROPDWORD diprop_word
;
413 hr
= IDirectInputEffect_Initialize(effect
, hInstance
, data
->version
,
414 &GUID_ConstantForce
);
415 ok(hr
==DI_OK
,"IDirectInputEffect_Initialize failed: %08x\n", hr
);
416 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_AXES
| DIEP_DIRECTION
|
417 DIEP_TYPESPECIFICPARAMS
);
418 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
420 /* Test that upload, unacquire, acquire still permits updating
421 * uploaded effect. */
422 hr
= IDirectInputDevice_Unacquire(pJoystick
);
423 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
424 hr
= IDirectInputDevice_Acquire(pJoystick
);
425 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
426 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_GAIN
);
427 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
430 /* Check effect status.
431 * State: initially stopped
434 * unacquire, acquire, download
440 * - effects are stopped after Unacquire + Acquire
441 * - effects are preserved (Download + Start doesn't complain
442 * about incomplete effect)
444 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
445 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
446 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
447 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_START
);
448 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
449 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
450 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
451 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
452 hr
= IDirectInputDevice_Unacquire(pJoystick
);
453 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
454 hr
= IDirectInputDevice_Acquire(pJoystick
);
455 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
456 hr
= IDirectInputEffect_Download(effect
);
457 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
458 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
459 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
460 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
461 hr
= IDirectInputEffect_Start(effect
, 1, 0);
462 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
463 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
464 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
465 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
466 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
467 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
468 ok(IsEqualGUID(&GUID_ConstantForce
, &guid
), "Wrong guid returned\n");
470 /* Check autocenter status
471 * State: initially stopped
479 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
480 * executed when the device is released.
482 * If Executed interactively, user can feel that autocenter is
483 * only disabled when the joystick is acquired.
485 diprop_word
.diph
.dwSize
= sizeof(diprop_word
);
486 diprop_word
.diph
.dwHeaderSize
= sizeof(diprop_word
.diph
);
487 diprop_word
.diph
.dwObj
= 0;
488 diprop_word
.diph
.dwHow
= DIPH_DEVICE
;
489 hr
= IDirectInputDevice_Unacquire(pJoystick
);
490 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
491 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
492 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
493 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_ON
,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
494 diprop_word
.dwData
= DIPROPAUTOCENTER_OFF
;
495 hr
= IDirectInputDevice2_SetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
496 ok(hr
==DI_OK
,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr
);
497 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
498 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
499 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
500 if (winetest_interactive
) {
501 trace("Acquiring in 2s, autocenter will be disabled.\n");
504 hr
= IDirectInputDevice_Acquire(pJoystick
);
505 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
506 if (winetest_interactive
)
507 trace("Acquired.\n");
508 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
509 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
510 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
511 if (winetest_interactive
) {
512 trace("Releasing in 2s, autocenter will be re-enabled.\n");
515 hr
= IDirectInputDevice_Unacquire(pJoystick
);
516 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
517 if (winetest_interactive
)
519 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
520 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
521 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
522 hr
= IDirectInputDevice_Acquire(pJoystick
);
523 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
524 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
525 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
527 /* Device gain (DIPROP_FFGAIN).
529 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
530 * Can be changed even if device is acquired.
531 * Difference found by tests:
532 * <0 is refused, >10000 is accepted
534 dip_gain_set
.diph
.dwSize
= sizeof(DIPROPDWORD
);
535 dip_gain_set
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
536 dip_gain_set
.diph
.dwObj
= 0;
537 dip_gain_set
.diph
.dwHow
= DIPH_DEVICE
;
538 dip_gain_set
.dwData
= 10000;
539 dip_gain_get
.diph
.dwSize
= sizeof(DIPROPDWORD
);
540 dip_gain_get
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
541 dip_gain_get
.diph
.dwObj
= 0;
542 dip_gain_get
.diph
.dwHow
= DIPH_DEVICE
;
543 dip_gain_get
.dwData
= 0;
545 /* Test device is acquisition (non)impact. */
546 hr
= IDirectInputDevice_Unacquire(pJoystick
);
547 ok(hr
== DI_OK
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
548 dip_gain_set
.dwData
= 1;
549 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
550 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
551 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
552 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
553 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
554 hr
= IDirectInputDevice_Acquire(pJoystick
);
555 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
556 dip_gain_set
.dwData
= 2;
557 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
558 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
559 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
560 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
561 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
562 /* Test range and internal clamping. */
563 dip_gain_set
.dwData
= -1;
564 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
565 todo_wine
ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM
, hr
);
566 dip_gain_set
.dwData
= 0;
567 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
568 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
569 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
570 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
571 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
572 dip_gain_set
.dwData
= 10000;
573 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
574 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
575 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
576 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
577 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
578 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
579 dip_gain_set
.dwData
= 10001;
580 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
581 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
582 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
583 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
584 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
586 ref
= IUnknown_Release(effect
);
587 ok(ref
== 0, "IDirectInputDevice_Release() reference count = %d\n", ref
);
589 cnt1
= get_refcount((IUnknown
*)pJoystick
);
590 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
592 /* Before destroying the window, release joystick to revert to
593 * non-exclusive, background cooperative level. */
594 hr
= IDirectInputDevice_Unacquire(pJoystick
);
595 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
596 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
597 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
598 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
599 DestroyWindow (real_hWnd
);
600 hr
= IDirectInputDevice_Acquire(pJoystick
);
601 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
604 if (winetest_interactive
) {
605 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
612 for (i
= 0; i
< count
; i
++) {
613 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
614 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
617 sprintf(curstate
, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
618 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
619 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
620 js
.lX
, js
.lY
, js
.lZ
, js
.lRx
, js
.lRy
, js
.lRz
,
621 js
.rglSlider
[0], js
.rglSlider
[1],
622 js
.rgdwPOV
[0], js
.rgdwPOV
[1], js
.rgdwPOV
[2], js
.rgdwPOV
[3],
623 js
.rgbButtons
[0]>>7, js
.rgbButtons
[1]>>7, js
.rgbButtons
[2]>>7,
624 js
.rgbButtons
[3]>>7, js
.rgbButtons
[4]>>7, js
.rgbButtons
[5]>>7,
625 js
.rgbButtons
[6]>>7, js
.rgbButtons
[7]>>7, js
.rgbButtons
[8]>>7,
626 js
.rgbButtons
[9]>>7, js
.rgbButtons
[10]>>7, js
.rgbButtons
[11]>>7);
627 if (strcmp(oldstate
, curstate
) != 0)
629 trace("%s\n", curstate
);
630 strcpy(oldstate
, curstate
);
636 hr
= IDirectInputDevice_Unacquire(pJoystick
);
637 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
640 ref
= IDirectInputDevice_Release(pJoystick
);
641 ok(ref
==0,"IDirectInputDevice_Release() reference count = %d\n", ref
);
644 return DIENUM_CONTINUE
;
647 static void joystick_tests(DWORD version
)
652 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
654 trace("-- Testing Direct Input Version 0x%04x --\n", version
);
655 hr
= DirectInputCreateA(hInstance
, version
, &pDI
, NULL
);
656 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
, "DirectInputCreateA() failed: %08x\n", hr
);
657 if (hr
==DI_OK
&& pDI
!=0) {
660 data
.version
= version
;
661 hr
= IDirectInput_EnumDevices(pDI
, DIDEVTYPE_JOYSTICK
, EnumJoysticks
,
662 &data
, DIEDFL_ALLDEVICES
);
663 ok(hr
==DI_OK
,"IDirectInput_EnumDevices() failed: %08x\n", hr
);
664 ref
= IDirectInput_Release(pDI
);
665 ok(ref
==0,"IDirectInput_Release() reference count = %d\n", ref
);
666 } else if (hr
==DIERR_OLDDIRECTINPUTVERSION
)
667 trace(" Version Not Supported\n");
674 joystick_tests(0x0700);
675 joystick_tests(0x0500);
676 joystick_tests(0x0300);