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
;
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 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, NULL
);
209 ok(hr
==E_POINTER
,"IDirectInputDevice_SetDataFormat() should have returned "
210 "E_POINTER, returned: %08x\n", hr
);
212 ZeroMemory(&format
, sizeof(format
));
213 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &format
);
214 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_SetDataFormat() should have "
215 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
217 /* try the default formats */
218 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick
);
219 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
221 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
222 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
224 /* try an alternate format */
225 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystickTest
);
226 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
228 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
229 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
235 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, NULL
, i
);
236 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
240 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
, i
);
241 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
244 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
245 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
246 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
248 /* get capabilities */
249 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, NULL
);
250 ok(hr
==E_POINTER
,"IDirectInputDevice_GetCapabilities() "
251 "should have returned E_POINTER, returned: %08x\n", hr
);
253 ZeroMemory(&caps
, sizeof(caps
));
254 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
255 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_GetCapabilities() "
256 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
258 caps
.dwSize
= sizeof(caps
);
259 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
260 ok(hr
==DI_OK
,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr
);
262 ZeroMemory(&info
, sizeof(info
));
263 info
.pJoystick
= pJoystick
;
265 /* default min/max limits */
268 /* enumerate objects */
269 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
270 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
272 ok(caps
.dwAxes
== info
.axis
, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info
.axis
, caps
.dwAxes
);
273 ok(caps
.dwButtons
== info
.button
, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info
.button
, caps
.dwButtons
);
274 ok(caps
.dwPOVs
== info
.pov
, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info
.pov
, caps
.dwPOVs
);
276 /* Set format and check limits again */
277 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
278 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
282 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
283 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
285 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, 0);
286 ok(hr
==E_POINTER
, "IDirectInputDevice_GetDeviceInfo() "
287 "should have returned E_POINTER, returned: %08x\n", hr
);
289 ZeroMemory(&inst
, sizeof(inst
));
290 ZeroMemory(&inst3
, sizeof(inst3
));
292 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
293 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_GetDeviceInfo() "
294 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
296 inst
.dwSize
= sizeof(inst
);
297 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
298 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
300 inst3
.dwSize
= sizeof(inst3
);
301 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, (LPDIDEVICEINSTANCE
)&inst3
);
302 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
304 hr
= IDirectInputDevice_Unacquire(pJoystick
);
305 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
307 hr
= IDirectInputDevice_Acquire(pJoystick
);
308 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
312 hr
= IDirectInputDevice_Acquire(pJoystick
);
313 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr
);
317 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
318 ok(hr
== DI_OK
, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
319 ok(js
.rgdwPOV
[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js
.rgdwPOV
[3]);
322 if (caps
.dwFlags
& DIDC_FORCEFEEDBACK
)
324 DWORD axes
[2] = {DIJOFS_X
, DIJOFS_Y
};
325 LONG direction
[2] = {0, 0};
326 DICONSTANTFORCE force
= {0};
328 LPDIRECTINPUTEFFECT effect
= NULL
;
331 HINSTANCE hInstance
= GetModuleHandle(NULL
);
332 DIPROPDWORD dip_gain_set
, dip_gain_get
;
334 trace("Testing force-feedback\n");
335 memset(&eff
, 0, sizeof(eff
));
336 eff
.dwSize
= sizeof(eff
);
337 eff
.dwFlags
= DIEFF_CARTESIAN
| DIEFF_OBJECTOFFSETS
;
338 eff
.dwDuration
= INFINITE
;
339 eff
.dwGain
= DI_FFNOMINALMAX
;
340 eff
.dwTriggerButton
= DIEB_NOTRIGGER
;
341 eff
.cAxes
= sizeof(axes
) / sizeof(axes
[0]);
343 eff
.rglDirection
= direction
;
344 eff
.cbTypeSpecificParams
= sizeof(force
);
345 eff
.lpvTypeSpecificParams
= &force
;
347 /* Sending effects to joystick requires
348 * calling IDirectInputEffect_Initialize, which requires
349 * having exclusive access to the device, which requires
350 * - not having acquired the joystick when calling
351 * IDirectInputDevice_SetCooperativeLevel
354 real_hWnd
= CreateWindowEx(0, "EDIT", "Test text", 0, 10, 10, 300,
355 300, NULL
, NULL
, hInstance
, NULL
);
356 ok(real_hWnd
!=0,"CreateWindowEx failed: %p\n", real_hWnd
);
357 ShowWindow(real_hWnd
, SW_SHOW
);
358 hr
= IDirectInputDevice_Unacquire(pJoystick
);
359 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
360 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, real_hWnd
,
361 DISCL_EXCLUSIVE
| DISCL_FOREGROUND
);
362 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
363 hr
= IDirectInputDevice_Acquire(pJoystick
);
364 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
366 cnt1
= get_refcount((IUnknown
*)pJoystick
);
368 hr
= IDirectInputDevice2_CreateEffect((LPDIRECTINPUTDEVICE2
)pJoystick
, &GUID_ConstantForce
,
369 &eff
, &effect
, NULL
);
370 ok(hr
== DI_OK
, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr
);
371 cnt2
= get_refcount((IUnknown
*)pJoystick
);
372 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
377 struct DIPROPDWORD diprop_word
;
379 hr
= IDirectInputEffect_Initialize(effect
, hInstance
, data
->version
,
380 &GUID_ConstantForce
);
381 ok(hr
==DI_OK
,"IDirectInputEffect_Initialize failed: %08x\n", hr
);
382 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_AXES
| DIEP_DIRECTION
|
383 DIEP_TYPESPECIFICPARAMS
);
384 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
386 /* Test that upload, unacquire, acquire still permits updating
387 * uploaded effect. */
388 hr
= IDirectInputDevice_Unacquire(pJoystick
);
389 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
390 hr
= IDirectInputDevice_Acquire(pJoystick
);
391 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
392 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_GAIN
);
393 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
396 /* Check effect status.
397 * State: initialy stopped
400 * unacquire, acquire, download
406 * - effects are stopped after Unacquire + Acquire
407 * - effects are preserved (Download + Start doesn't complain
408 * about incomplete effect)
410 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
411 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
412 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
413 hr
= IDirectInputEffect_SetParameters(effect
, &eff
, DIEP_START
);
414 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
415 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
416 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
417 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
418 hr
= IDirectInputDevice_Unacquire(pJoystick
);
419 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
420 hr
= IDirectInputDevice_Acquire(pJoystick
);
421 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
422 hr
= IDirectInputEffect_Download(effect
);
423 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
424 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
425 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
426 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
427 hr
= IDirectInputEffect_Start(effect
, 1, 0);
428 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
429 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
430 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
431 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
433 /* Check autocenter status
434 * State: initialy stopped
442 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
443 * executed when devide is released.
445 * If Executed interactively, user can feel that autocenter is
446 * only disabled when joystick is acquired.
448 diprop_word
.diph
.dwSize
= sizeof(diprop_word
);
449 diprop_word
.diph
.dwHeaderSize
= sizeof(diprop_word
.diph
);
450 diprop_word
.diph
.dwObj
= 0;
451 diprop_word
.diph
.dwHow
= DIPH_DEVICE
;
452 hr
= IDirectInputDevice_Unacquire(pJoystick
);
453 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
454 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
455 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
456 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_ON
,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
457 diprop_word
.dwData
= DIPROPAUTOCENTER_OFF
;
458 hr
= IDirectInputDevice2_SetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
459 ok(hr
==DI_OK
,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr
);
460 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
461 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
462 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
463 if (winetest_interactive
) {
464 trace("Acquiring in 2s, autocenter will be disabled.\n");
467 hr
= IDirectInputDevice_Acquire(pJoystick
);
468 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
469 if (winetest_interactive
)
470 trace("Acquired.\n");
471 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
472 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
473 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
474 if (winetest_interactive
) {
475 trace("Releasing in 2s, autocenter will be re-enabled.\n");
478 hr
= IDirectInputDevice_Unacquire(pJoystick
);
479 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
480 if (winetest_interactive
)
482 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
483 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
484 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
485 hr
= IDirectInputDevice_Acquire(pJoystick
);
486 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
487 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
489 /* Device gain (DIPROP_FFGAIN).
491 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
492 * Can be changed even if device is acquired.
493 * Difference found by tests:
494 * <0 is refused, >10000 is accepted
496 dip_gain_set
.diph
.dwSize
= sizeof(DIPROPDWORD
);
497 dip_gain_set
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
498 dip_gain_set
.diph
.dwObj
= 0;
499 dip_gain_set
.diph
.dwHow
= DIPH_DEVICE
;
500 dip_gain_set
.dwData
= 10000;
501 dip_gain_get
.diph
.dwSize
= sizeof(DIPROPDWORD
);
502 dip_gain_get
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
503 dip_gain_get
.diph
.dwObj
= 0;
504 dip_gain_get
.diph
.dwHow
= DIPH_DEVICE
;
505 dip_gain_get
.dwData
= 0;
507 /* Test device is acquisition (non)impact. */
508 hr
= IDirectInputDevice_Unacquire(pJoystick
);
509 ok(hr
== DI_OK
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
510 dip_gain_set
.dwData
= 1;
511 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
512 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
513 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
514 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
515 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not udated: %i\n", dip_gain_get
.dwData
);
516 hr
= IDirectInputDevice_Acquire(pJoystick
);
517 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
518 dip_gain_set
.dwData
= 2;
519 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
520 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
521 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
522 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
523 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not udated: %i\n", dip_gain_get
.dwData
);
524 /* Test range and internal clamping. */
525 dip_gain_set
.dwData
= -1;
526 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
527 todo_wine
ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM
, hr
);
528 dip_gain_set
.dwData
= 0;
529 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
530 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
531 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
532 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
533 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
534 dip_gain_set
.dwData
= 10000;
535 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
536 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
537 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
538 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
539 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
540 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
541 dip_gain_set
.dwData
= 10001;
542 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
543 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
544 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
545 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
546 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
548 ref
= IUnknown_Release(effect
);
549 ok(ref
== 0, "IDirectInputDevice_Release() reference count = %d\n", ref
);
551 cnt1
= get_refcount((IUnknown
*)pJoystick
);
552 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
554 /* Before destroying the window, release joystick to revert to
555 * non-exclusive, background cooperative level. */
556 hr
= IDirectInputDevice_Unacquire(pJoystick
);
557 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
558 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
559 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
560 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
561 DestroyWindow (real_hWnd
);
562 hr
= IDirectInputDevice_Acquire(pJoystick
);
563 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
566 if (winetest_interactive
) {
567 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
574 for (i
= 0; i
< count
; i
++) {
575 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
576 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
579 sprintf(curstate
, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
580 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
581 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
582 js
.lX
, js
.lY
, js
.lZ
, js
.lRx
, js
.lRy
, js
.lRz
,
583 js
.rglSlider
[0], js
.rglSlider
[1],
584 js
.rgdwPOV
[0], js
.rgdwPOV
[1], js
.rgdwPOV
[2], js
.rgdwPOV
[3],
585 js
.rgbButtons
[0]>>7, js
.rgbButtons
[1]>>7, js
.rgbButtons
[2]>>7,
586 js
.rgbButtons
[3]>>7, js
.rgbButtons
[4]>>7, js
.rgbButtons
[5]>>7,
587 js
.rgbButtons
[6]>>7, js
.rgbButtons
[7]>>7, js
.rgbButtons
[8]>>7,
588 js
.rgbButtons
[9]>>7, js
.rgbButtons
[10]>>7, js
.rgbButtons
[11]>>7);
589 if (strcmp(oldstate
, curstate
) != 0)
591 trace("%s\n", curstate
);
592 strcpy(oldstate
, curstate
);
598 hr
= IDirectInputDevice_Unacquire(pJoystick
);
599 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
602 ref
= IDirectInputDevice_Release(pJoystick
);
603 ok(ref
==0,"IDirectInputDevice_Release() reference count = %d\n", ref
);
606 return DIENUM_CONTINUE
;
609 static void joystick_tests(DWORD version
)
614 HINSTANCE hInstance
= GetModuleHandle(NULL
);
616 trace("-- Testing Direct Input Version 0x%04x --\n", version
);
617 hr
= DirectInputCreate(hInstance
, version
, &pDI
, NULL
);
618 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
,
619 "DirectInputCreate() failed: %08x\n", hr
);
620 if (hr
==DI_OK
&& pDI
!=0) {
623 data
.version
= version
;
624 hr
= IDirectInput_EnumDevices(pDI
, DIDEVTYPE_JOYSTICK
, EnumJoysticks
,
625 &data
, DIEDFL_ALLDEVICES
);
626 ok(hr
==DI_OK
,"IDirectInput_EnumDevices() failed: %08x\n", hr
);
627 ref
= IDirectInput_Release(pDI
);
628 ok(ref
==0,"IDirectInput_Release() reference count = %d\n", ref
);
629 } else if (hr
==DIERR_OLDDIRECTINPUTVERSION
)
630 trace(" Version Not Supported\n");
637 joystick_tests(0x0700);
638 joystick_tests(0x0500);
639 joystick_tests(0x0300);