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 LPDIRECTINPUTDEVICE pJoystick
;
87 static int get_refcount(IUnknown
*object
)
89 IUnknown_AddRef( object
);
90 return IUnknown_Release( object
);
93 static BOOL CALLBACK
EnumAxes(
94 const DIDEVICEOBJECTINSTANCE
* pdidoi
,
98 JoystickInfo
* info
= pContext
;
100 if (IsEqualIID(&pdidoi
->guidType
, &GUID_XAxis
) ||
101 IsEqualIID(&pdidoi
->guidType
, &GUID_YAxis
) ||
102 IsEqualIID(&pdidoi
->guidType
, &GUID_ZAxis
) ||
103 IsEqualIID(&pdidoi
->guidType
, &GUID_RxAxis
) ||
104 IsEqualIID(&pdidoi
->guidType
, &GUID_RyAxis
) ||
105 IsEqualIID(&pdidoi
->guidType
, &GUID_RzAxis
) ||
106 IsEqualIID(&pdidoi
->guidType
, &GUID_Slider
))
111 diprg
.diph
.dwSize
= sizeof(DIPROPRANGE
);
112 diprg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
113 diprg
.diph
.dwHow
= DIPH_BYID
;
114 diprg
.diph
.dwObj
= pdidoi
->dwType
;
116 dipdw
.diph
.dwSize
= sizeof(dipdw
);
117 dipdw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
118 dipdw
.diph
.dwHow
= DIPH_BYID
;
119 dipdw
.diph
.dwObj
= pdidoi
->dwType
;
121 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
122 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
123 ok(info
->lMin
== diprg
.lMin
&& info
->lMax
== diprg
.lMax
, "Min/Max range invalid: "
124 "expected %d..%d got %d..%d\n", info
->lMin
, info
->lMax
, diprg
.lMin
, diprg
.lMax
);
129 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, NULL
);
130 ok(hr
==E_INVALIDARG
,"IDirectInputDevice_SetProperty() should have returned "
131 "E_INVALIDARG, returned: %08x\n", hr
);
133 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
134 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
137 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
138 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
139 ok(info
->dZone
== dipdw
.dwData
, "deadzone invalid: expected %d got %d\n",
140 info
->dZone
, dipdw
.dwData
);
144 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
145 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
148 } else if (IsEqualIID(&pdidoi
->guidType
, &GUID_POV
))
150 else if (IsEqualIID(&pdidoi
->guidType
, &GUID_Button
))
153 return DIENUM_CONTINUE
;
156 static const HRESULT SetCoop_null_window
[16] = {
157 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
158 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
159 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
160 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
162 static const HRESULT SetCoop_real_window
[16] = {
163 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
164 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
165 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
166 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
168 static BOOL CALLBACK
EnumJoysticks(
169 LPCDIDEVICEINSTANCE lpddi
,
173 UserData
* data
= pvRef
;
174 LPDIRECTINPUTDEVICE pJoystick
;
181 DIDEVICEINSTANCE inst
;
182 DIDEVICEINSTANCE_DX3 inst3
;
185 DIPROPGUIDANDPATH dpg
;
186 WCHAR nameBuffer
[MAX_PATH
];
187 HWND hWnd
= get_hwnd();
188 char oldstate
[248], curstate
[248];
190 ok(data
->version
> 0x0300, "Joysticks not supported in version 0x%04x\n", data
->version
);
192 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
, NULL
, 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
, &pJoystick
, NULL
);
197 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
198 "E_POINTER, returned: %08x\n", hr
);
200 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, NULL
, NULL
);
201 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
202 "E_POINTER, returned: %08x\n", hr
);
204 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
,
206 ok(hr
==DI_OK
,"IDirectInput_CreateDevice() failed: %08x\n", hr
);
210 trace("---- %s ----\n", lpddi
->tszProductName
);
212 /* Test for joystick ID property */
213 ZeroMemory(&dipw
, sizeof(dipw
));
214 dipw
.diph
.dwSize
= sizeof(DIPROPDWORD
);
215 dipw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
217 dipw
.diph
.dwHow
= DIPH_DEVICE
;
219 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_JOYSTICKID
, &dipw
.diph
);
220 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
222 /* Test for INSTANCENAME property */
223 memset(&dps
, 0, sizeof(dps
));
224 dps
.diph
.dwSize
= sizeof(DIPROPSTRING
);
225 dps
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
226 dps
.diph
.dwHow
= DIPH_DEVICE
;
228 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_INSTANCENAME
, &dps
.diph
);
229 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr
);
231 /* Test if instance name is the same as present in DIDEVICEINSTANCE */
232 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszInstanceName
, -1, nameBuffer
, MAX_PATH
);
233 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
234 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
236 /* Test for GUIDPATH properties */
237 memset(&dpg
, 0, sizeof(dpg
));
238 dpg
.diph
.dwSize
= sizeof(DIPROPGUIDANDPATH
);
239 dpg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
240 dpg
.diph
.dwHow
= DIPH_DEVICE
;
242 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_GUIDANDPATH
, &dpg
.diph
);
243 todo_wine
ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr
);
245 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, NULL
);
246 ok(hr
==E_POINTER
,"IDirectInputDevice_SetDataFormat() should have returned "
247 "E_POINTER, returned: %08x\n", hr
);
249 ZeroMemory(&format
, sizeof(format
));
250 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &format
);
251 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_SetDataFormat() should have "
252 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
254 /* try the default formats */
255 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick
);
256 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
258 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
259 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
261 /* try an alternate format */
262 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystickTest
);
263 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
265 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
266 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
272 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, NULL
, i
);
273 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
277 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
, i
);
278 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
281 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
282 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
283 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
285 /* get capabilities */
286 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, NULL
);
287 ok(hr
==E_POINTER
,"IDirectInputDevice_GetCapabilities() "
288 "should have returned E_POINTER, returned: %08x\n", hr
);
290 ZeroMemory(&caps
, sizeof(caps
));
291 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
292 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_GetCapabilities() "
293 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
295 caps
.dwSize
= sizeof(caps
);
296 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
297 ok(hr
==DI_OK
,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr
);
299 ZeroMemory(&info
, sizeof(info
));
300 info
.pJoystick
= pJoystick
;
302 /* default min/max limits */
305 /* enumerate objects */
306 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
307 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
309 ok(caps
.dwAxes
== info
.axis
, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info
.axis
, caps
.dwAxes
);
310 ok(caps
.dwButtons
== info
.button
, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info
.button
, caps
.dwButtons
);
311 ok(caps
.dwPOVs
== info
.pov
, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info
.pov
, caps
.dwPOVs
);
313 /* Set format and check limits again */
314 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
315 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
319 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
320 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
322 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, 0);
323 ok(hr
==E_POINTER
, "IDirectInputDevice_GetDeviceInfo() "
324 "should have returned E_POINTER, returned: %08x\n", hr
);
326 ZeroMemory(&inst
, sizeof(inst
));
327 ZeroMemory(&inst3
, sizeof(inst3
));
329 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
330 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_GetDeviceInfo() "
331 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
333 inst
.dwSize
= sizeof(inst
);
334 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
335 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
337 inst3
.dwSize
= sizeof(inst3
);
338 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, (LPDIDEVICEINSTANCE
)&inst3
);
339 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
341 hr
= IDirectInputDevice_Unacquire(pJoystick
);
342 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
344 hr
= IDirectInputDevice_Acquire(pJoystick
);
345 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
349 hr
= IDirectInputDevice_Acquire(pJoystick
);
350 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr
);
354 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
355 ok(hr
== DI_OK
, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
356 ok(js
.rgdwPOV
[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js
.rgdwPOV
[3]);
359 if (caps
.dwFlags
& DIDC_FORCEFEEDBACK
)
361 DWORD axes
[2] = {DIJOFS_X
, DIJOFS_Y
};
362 LONG direction
[2] = {0, 0};
363 DICONSTANTFORCE force
= {0};
365 LPDIRECTINPUTEFFECT effect
= NULL
;
368 HINSTANCE hInstance
= GetModuleHandle(NULL
);
369 DIPROPDWORD dip_gain_set
, dip_gain_get
;
371 trace("Testing force-feedback\n");
372 memset(&eff
, 0, sizeof(eff
));
373 eff
.dwSize
= sizeof(eff
);
374 eff
.dwFlags
= DIEFF_CARTESIAN
| DIEFF_OBJECTOFFSETS
;
375 eff
.dwDuration
= INFINITE
;
376 eff
.dwGain
= DI_FFNOMINALMAX
;
377 eff
.dwTriggerButton
= DIEB_NOTRIGGER
;
378 eff
.cAxes
= sizeof(axes
) / sizeof(axes
[0]);
380 eff
.rglDirection
= direction
;
381 eff
.cbTypeSpecificParams
= sizeof(force
);
382 eff
.lpvTypeSpecificParams
= &force
;
384 /* Sending effects to joystick requires
385 * calling IDirectInputEffect_Initialize, which requires
386 * having exclusive access to the device, which requires
387 * - not having acquired the joystick when calling
388 * IDirectInputDevice_SetCooperativeLevel
391 real_hWnd
= CreateWindowEx(0, "EDIT", "Test text", 0, 10, 10, 300,
392 300, NULL
, NULL
, hInstance
, NULL
);
393 ok(real_hWnd
!=0,"CreateWindowEx failed: %p\n", real_hWnd
);
394 ShowWindow(real_hWnd
, SW_SHOW
);
395 hr
= IDirectInputDevice_Unacquire(pJoystick
);
396 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
397 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, real_hWnd
,
398 DISCL_EXCLUSIVE
| DISCL_FOREGROUND
);
399 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
400 hr
= IDirectInputDevice_Acquire(pJoystick
);
401 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
403 cnt1
= get_refcount((IUnknown
*)pJoystick
);
405 hr
= IDirectInputDevice2_CreateEffect((LPDIRECTINPUTDEVICE2
)pJoystick
, &GUID_ConstantForce
,
406 &eff
, &effect
, NULL
);
407 ok(hr
== DI_OK
, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr
);
408 cnt2
= get_refcount((IUnknown
*)pJoystick
);
409 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
414 struct DIPROPDWORD diprop_word
;
417 hr
= IDirectInputEffect_Initialize(effect
, hInstance
, data
->version
,
418 &GUID_ConstantForce
);
419 ok(hr
==DI_OK
,"IDirectInputEffect_Initialize failed: %08x\n", hr
);
420 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_AXES
| DIEP_DIRECTION
|
421 DIEP_TYPESPECIFICPARAMS
);
422 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
424 /* Test that upload, unacquire, acquire still permits updating
425 * uploaded effect. */
426 hr
= IDirectInputDevice_Unacquire(pJoystick
);
427 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
428 hr
= IDirectInputDevice_Acquire(pJoystick
);
429 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
430 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_GAIN
);
431 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
434 /* Check effect status.
435 * State: initially stopped
438 * unacquire, acquire, download
444 * - effects are stopped after Unacquire + Acquire
445 * - effects are preserved (Download + Start doesn't complain
446 * about incomplete effect)
448 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
449 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
450 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
451 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_START
);
452 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
453 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
454 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
455 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
456 hr
= IDirectInputDevice_Unacquire(pJoystick
);
457 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
458 hr
= IDirectInputDevice_Acquire(pJoystick
);
459 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
460 hr
= IDirectInputEffect_Download(effect
);
461 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
462 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
463 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
464 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
465 hr
= IDirectInputEffect_Start(effect
, 1, 0);
466 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
467 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
468 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
469 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
470 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
471 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
472 ok(IsEqualGUID(&GUID_ConstantForce
, &guid
), "Wrong guid returned\n");
474 /* Check autocenter status
475 * State: initially stopped
483 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
484 * executed when the device is released.
486 * If Executed interactively, user can feel that autocenter is
487 * only disabled when the joystick is acquired.
489 diprop_word
.diph
.dwSize
= sizeof(diprop_word
);
490 diprop_word
.diph
.dwHeaderSize
= sizeof(diprop_word
.diph
);
491 diprop_word
.diph
.dwObj
= 0;
492 diprop_word
.diph
.dwHow
= DIPH_DEVICE
;
493 hr
= IDirectInputDevice_Unacquire(pJoystick
);
494 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
495 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
496 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
497 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_ON
,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
498 diprop_word
.dwData
= DIPROPAUTOCENTER_OFF
;
499 hr
= IDirectInputDevice2_SetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
500 ok(hr
==DI_OK
,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr
);
501 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
502 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
503 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
504 if (winetest_interactive
) {
505 trace("Acquiring in 2s, autocenter will be disabled.\n");
508 hr
= IDirectInputDevice_Acquire(pJoystick
);
509 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
510 if (winetest_interactive
)
511 trace("Acquired.\n");
512 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
513 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
514 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
515 if (winetest_interactive
) {
516 trace("Releasing in 2s, autocenter will be re-enabled.\n");
519 hr
= IDirectInputDevice_Unacquire(pJoystick
);
520 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
521 if (winetest_interactive
)
523 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
524 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
525 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
526 hr
= IDirectInputDevice_Acquire(pJoystick
);
527 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
528 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
529 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
531 /* Device gain (DIPROP_FFGAIN).
533 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
534 * Can be changed even if device is acquired.
535 * Difference found by tests:
536 * <0 is refused, >10000 is accepted
538 dip_gain_set
.diph
.dwSize
= sizeof(DIPROPDWORD
);
539 dip_gain_set
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
540 dip_gain_set
.diph
.dwObj
= 0;
541 dip_gain_set
.diph
.dwHow
= DIPH_DEVICE
;
542 dip_gain_set
.dwData
= 10000;
543 dip_gain_get
.diph
.dwSize
= sizeof(DIPROPDWORD
);
544 dip_gain_get
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
545 dip_gain_get
.diph
.dwObj
= 0;
546 dip_gain_get
.diph
.dwHow
= DIPH_DEVICE
;
547 dip_gain_get
.dwData
= 0;
549 /* Test device is acquisition (non)impact. */
550 hr
= IDirectInputDevice_Unacquire(pJoystick
);
551 ok(hr
== DI_OK
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
552 dip_gain_set
.dwData
= 1;
553 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
554 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
555 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
556 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
557 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not udated: %i\n", dip_gain_get
.dwData
);
558 hr
= IDirectInputDevice_Acquire(pJoystick
);
559 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
560 dip_gain_set
.dwData
= 2;
561 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
562 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
563 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
564 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
565 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not udated: %i\n", dip_gain_get
.dwData
);
566 /* Test range and internal clamping. */
567 dip_gain_set
.dwData
= -1;
568 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
569 todo_wine
ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM
, hr
);
570 dip_gain_set
.dwData
= 0;
571 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
572 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
573 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
574 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
575 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
576 dip_gain_set
.dwData
= 10000;
577 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
578 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
579 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
580 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
581 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
582 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
583 dip_gain_set
.dwData
= 10001;
584 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
585 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
586 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
587 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
588 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
590 ref
= IUnknown_Release(effect
);
591 ok(ref
== 0, "IDirectInputDevice_Release() reference count = %d\n", ref
);
593 cnt1
= get_refcount((IUnknown
*)pJoystick
);
594 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
596 /* Before destroying the window, release joystick to revert to
597 * non-exclusive, background cooperative level. */
598 hr
= IDirectInputDevice_Unacquire(pJoystick
);
599 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
600 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
601 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
602 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
603 DestroyWindow (real_hWnd
);
604 hr
= IDirectInputDevice_Acquire(pJoystick
);
605 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
608 if (winetest_interactive
) {
609 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
616 for (i
= 0; i
< count
; i
++) {
617 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
618 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
621 sprintf(curstate
, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
622 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
623 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
624 js
.lX
, js
.lY
, js
.lZ
, js
.lRx
, js
.lRy
, js
.lRz
,
625 js
.rglSlider
[0], js
.rglSlider
[1],
626 js
.rgdwPOV
[0], js
.rgdwPOV
[1], js
.rgdwPOV
[2], js
.rgdwPOV
[3],
627 js
.rgbButtons
[0]>>7, js
.rgbButtons
[1]>>7, js
.rgbButtons
[2]>>7,
628 js
.rgbButtons
[3]>>7, js
.rgbButtons
[4]>>7, js
.rgbButtons
[5]>>7,
629 js
.rgbButtons
[6]>>7, js
.rgbButtons
[7]>>7, js
.rgbButtons
[8]>>7,
630 js
.rgbButtons
[9]>>7, js
.rgbButtons
[10]>>7, js
.rgbButtons
[11]>>7);
631 if (strcmp(oldstate
, curstate
) != 0)
633 trace("%s\n", curstate
);
634 strcpy(oldstate
, curstate
);
640 hr
= IDirectInputDevice_Unacquire(pJoystick
);
641 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
644 ref
= IDirectInputDevice_Release(pJoystick
);
645 ok(ref
==0,"IDirectInputDevice_Release() reference count = %d\n", ref
);
648 return DIENUM_CONTINUE
;
651 static void joystick_tests(DWORD version
)
656 HINSTANCE hInstance
= GetModuleHandle(NULL
);
658 trace("-- Testing Direct Input Version 0x%04x --\n", version
);
659 hr
= DirectInputCreate(hInstance
, version
, &pDI
, NULL
);
660 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
,
661 "DirectInputCreate() 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);