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 typedef struct tagUserData
{
38 static const DIOBJECTDATAFORMAT dfDIJoystickTest
[] = {
39 { &GUID_XAxis
,DIJOFS_X
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
40 { &GUID_YAxis
,DIJOFS_Y
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
41 { &GUID_ZAxis
,DIJOFS_Z
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
42 { &GUID_RxAxis
,DIJOFS_RX
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
43 { &GUID_RyAxis
,DIJOFS_RY
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
44 { &GUID_RzAxis
,DIJOFS_RZ
,DIDFT_OPTIONAL
|DIDFT_AXIS
|DIDFT_ANYINSTANCE
,0},
45 { &GUID_Button
,DIJOFS_BUTTON(0),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
46 { &GUID_Button
,DIJOFS_BUTTON(1),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
47 { &GUID_Button
,DIJOFS_BUTTON(2),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
48 { &GUID_Button
,DIJOFS_BUTTON(3),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
49 { &GUID_Button
,DIJOFS_BUTTON(4),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
50 { &GUID_Button
,DIJOFS_BUTTON(5),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
51 { &GUID_Button
,DIJOFS_BUTTON(6),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
52 { &GUID_Button
,DIJOFS_BUTTON(7),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
53 { &GUID_Button
,DIJOFS_BUTTON(8),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
54 { &GUID_Button
,DIJOFS_BUTTON(9),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
55 { &GUID_Button
,DIJOFS_BUTTON(10),DIDFT_OPTIONAL
|DIDFT_BUTTON
|DIDFT_ANYINSTANCE
,0},
58 static const DIDATAFORMAT c_dfDIJoystickTest
= {
60 sizeof(DIOBJECTDATAFORMAT
),
63 ARRAY_SIZE(dfDIJoystickTest
),
64 (LPDIOBJECTDATAFORMAT
)dfDIJoystickTest
67 static HWND
get_hwnd(void)
69 HWND hwnd
=GetForegroundWindow();
71 hwnd
=GetDesktopWindow();
75 typedef struct tagJoystickInfo
77 IDirectInputDeviceA
*pJoystick
;
85 static int get_refcount(IUnknown
*object
)
87 IUnknown_AddRef( object
);
88 return IUnknown_Release( object
);
91 static BOOL CALLBACK
EnumAxes(const DIDEVICEOBJECTINSTANCEA
*pdidoi
, void *pContext
)
94 JoystickInfo
* info
= pContext
;
96 if (IsEqualIID(&pdidoi
->guidType
, &GUID_XAxis
) ||
97 IsEqualIID(&pdidoi
->guidType
, &GUID_YAxis
) ||
98 IsEqualIID(&pdidoi
->guidType
, &GUID_ZAxis
) ||
99 IsEqualIID(&pdidoi
->guidType
, &GUID_RxAxis
) ||
100 IsEqualIID(&pdidoi
->guidType
, &GUID_RyAxis
) ||
101 IsEqualIID(&pdidoi
->guidType
, &GUID_RzAxis
) ||
102 IsEqualIID(&pdidoi
->guidType
, &GUID_Slider
))
107 diprg
.diph
.dwSize
= sizeof(DIPROPRANGE
);
108 diprg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
109 diprg
.diph
.dwHow
= DIPH_BYID
;
110 diprg
.diph
.dwObj
= pdidoi
->dwType
;
112 dipdw
.diph
.dwSize
= sizeof(dipdw
);
113 dipdw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
114 dipdw
.diph
.dwHow
= DIPH_BYID
;
115 dipdw
.diph
.dwObj
= pdidoi
->dwType
;
117 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
118 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
119 ok(info
->lMin
== diprg
.lMin
&& info
->lMax
== diprg
.lMax
, "Min/Max range invalid: "
120 "expected %d..%d got %d..%d\n", info
->lMin
, info
->lMax
, diprg
.lMin
, diprg
.lMax
);
125 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, NULL
);
126 ok(hr
==E_INVALIDARG
,"IDirectInputDevice_SetProperty() should have returned "
127 "E_INVALIDARG, returned: %08x\n", hr
);
129 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_RANGE
, &diprg
.diph
);
130 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
133 hr
= IDirectInputDevice_GetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
134 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
135 ok(info
->dZone
== dipdw
.dwData
, "deadzone invalid: expected %d got %d\n",
136 info
->dZone
, dipdw
.dwData
);
140 hr
= IDirectInputDevice_SetProperty(info
->pJoystick
, DIPROP_DEADZONE
, &dipdw
.diph
);
141 ok(hr
==DI_OK
,"IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
143 /* ensure DIDOI_ASPECTPOSITION is set for axes objects */
144 ok(pdidoi
->dwFlags
& DIDOI_ASPECTPOSITION
, "Missing DIDOI_ASPECTPOSITION, flags are 0x%x\n",
148 } else if (IsEqualIID(&pdidoi
->guidType
, &GUID_POV
))
150 else if (IsEqualIID(&pdidoi
->guidType
, &GUID_Button
))
153 return DIENUM_CONTINUE
;
156 static const struct effect_id
161 } effect_conversion
[] = {
162 {&GUID_ConstantForce
, DIEFT_CONSTANTFORCE
, "Constant"},
163 {&GUID_RampForce
, DIEFT_RAMPFORCE
, "Ramp"},
164 {&GUID_Square
, DIEFT_PERIODIC
, "Square"},
165 {&GUID_Sine
, DIEFT_PERIODIC
, "Sine"},
166 {&GUID_Triangle
, DIEFT_PERIODIC
, "Triangle"},
167 {&GUID_SawtoothUp
, DIEFT_PERIODIC
, "Saw Tooth Up"},
168 {&GUID_SawtoothDown
, DIEFT_PERIODIC
, "Saw Tooth Down"},
169 {&GUID_Spring
, DIEFT_CONDITION
, "Spring"},
170 {&GUID_Damper
, DIEFT_CONDITION
, "Damper"},
171 {&GUID_Inertia
, DIEFT_CONDITION
, "Inertia"},
172 {&GUID_Friction
, DIEFT_CONDITION
, "Friction"},
173 {&GUID_CustomForce
, DIEFT_CUSTOMFORCE
, "Custom"}
176 static const struct effect_id
* effect_from_guid(const GUID
*guid
)
179 for (i
= 0; i
< ARRAY_SIZE(effect_conversion
); i
++)
180 if (IsEqualGUID(guid
, effect_conversion
[i
].guid
))
181 return &effect_conversion
[i
];
190 const char *effect_name
;
193 /* The last enumerated effect will be used for force feedback testing */
194 static BOOL CALLBACK
EnumEffects(const DIEFFECTINFOA
*lpef
, void *ref
)
196 const struct effect_id
*id
= effect_from_guid(&lpef
->guid
);
199 DICONSTANTFORCE constant
;
202 DICONDITION condition
[2];
204 struct effect_enum
*data
= ref
;
205 int type
= DIDFT_GETTYPE(lpef
->dwEffType
);
210 ok(0, "unsupported effect enumerated, GUID %s!\n", wine_dbgstr_guid(&lpef
->guid
));
211 return DIENUM_CONTINUE
;
213 trace("controller supports '%s' effect\n", id
->name
);
214 ok(type
== id
->dieft
, "Invalid effect type, expected 0x%x, got 0x%x\n",
215 id
->dieft
, lpef
->dwEffType
);
217 /* Can't use custom for test as we don't know the data format */
218 if (type
== DIEFT_CUSTOMFORCE
)
219 return DIENUM_CONTINUE
;
221 data
->effect_count
++;
222 data
->effect_name
= id
->name
;
223 data
->guid
= *id
->guid
;
225 ZeroMemory(&specific
, sizeof(specific
));
229 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.periodic
);
230 data
->eff
.lpvTypeSpecificParams
= &specific
.periodic
;
231 specific
.periodic
.dwMagnitude
= DI_FFNOMINALMAX
/ 2;
232 specific
.periodic
.dwPeriod
= DI_SECONDS
; /* 1 second */
234 case DIEFT_CONSTANTFORCE
:
235 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.constant
);
236 data
->eff
.lpvTypeSpecificParams
= &specific
.constant
;
237 specific
.constant
.lMagnitude
= DI_FFNOMINALMAX
/ 2;
239 case DIEFT_RAMPFORCE
:
240 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.ramp
);
241 data
->eff
.lpvTypeSpecificParams
= &specific
.ramp
;
242 specific
.ramp
.lStart
= -DI_FFNOMINALMAX
/ 2;
243 specific
.ramp
.lEnd
= +DI_FFNOMINALMAX
/ 2;
245 case DIEFT_CONDITION
:
248 data
->eff
.cbTypeSpecificParams
= sizeof(specific
.condition
);
249 data
->eff
.lpvTypeSpecificParams
= specific
.condition
;
250 for (i
= 0; i
< 2; i
++)
252 specific
.condition
[i
].lNegativeCoefficient
= -DI_FFNOMINALMAX
/ 2;
253 specific
.condition
[i
].lPositiveCoefficient
= +DI_FFNOMINALMAX
/ 2;
258 return DIENUM_CONTINUE
;
261 static const HRESULT SetCoop_null_window
[16] = {
262 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
263 E_INVALIDARG
, E_HANDLE
, E_HANDLE
, E_INVALIDARG
,
264 E_INVALIDARG
, E_HANDLE
, S_OK
, E_INVALIDARG
,
265 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
267 static const HRESULT SetCoop_real_window
[16] = {
268 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
,
269 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
270 E_INVALIDARG
, S_OK
, S_OK
, E_INVALIDARG
,
271 E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
, E_INVALIDARG
};
273 static BOOL CALLBACK
EnumAllFeedback(const DIDEVICEINSTANCEA
*lpddi
, void *pvRef
)
275 trace("---- Device Information ----\n"
276 "Product Name : %s\n"
277 "Instance Name : %s\n"
279 "GUID Product : %s\n"
280 "GUID Instance : %s\n"
281 "HID Page : 0x%04x\n"
282 "HID Usage : 0x%04x\n",
283 lpddi
->tszProductName
,
284 lpddi
->tszInstanceName
,
286 wine_dbgstr_guid(&lpddi
->guidProduct
),
287 wine_dbgstr_guid(&lpddi
->guidInstance
),
291 ok(!(IsEqualGUID(&GUID_SysMouse
, &lpddi
->guidProduct
) || IsEqualGUID(&GUID_SysKeyboard
, &lpddi
->guidProduct
)), "Invalid device returned.\n");
293 return DIENUM_CONTINUE
;
296 static BOOL CALLBACK
EnumJoysticks(const DIDEVICEINSTANCEA
*lpddi
, void *pvRef
)
299 UserData
* data
= pvRef
;
300 IDirectInputDeviceA
*pJoystick
;
307 DIDEVICEINSTANCEA inst
;
308 DIDEVICEINSTANCE_DX3A inst3
;
311 DIPROPGUIDANDPATH dpg
;
312 WCHAR nameBuffer
[MAX_PATH
];
313 HWND hWnd
= get_hwnd();
314 char oldstate
[248], curstate
[248];
315 DWORD axes
[2] = {DIJOFS_X
, DIJOFS_Y
};
316 LONG direction
[2] = {0, 0};
317 LPDIRECTINPUTEFFECT effect
= NULL
;
320 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
321 DIPROPDWORD dip_gain_set
, dip_gain_get
;
322 struct effect_enum effect_data
;
324 ok(data
->version
>= 0x0300, "Joysticks not supported in version 0x%04x\n", data
->version
);
326 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
, NULL
, NULL
);
327 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
328 "E_POINTER, returned: %08x\n", hr
);
330 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, &pJoystick
, NULL
);
331 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
332 "E_POINTER, returned: %08x\n", hr
);
334 hr
= IDirectInput_CreateDevice(data
->pDI
, NULL
, NULL
, NULL
);
335 ok(hr
==E_POINTER
,"IDirectInput_CreateDevice() should have returned "
336 "E_POINTER, returned: %08x\n", hr
);
338 hr
= IDirectInput_CreateDevice(data
->pDI
, &lpddi
->guidInstance
,
340 ok(hr
==DI_OK
,"IDirectInput_CreateDevice() failed: %08x\n", hr
);
344 trace("---- Controller Information ----\n"
345 "Product Name : %s\n"
346 "Instance Name : %s\n"
348 "GUID Product : %s\n"
349 "GUID Instance : %s\n"
350 "HID Page : 0x%04x\n"
351 "HID Usage : 0x%04x\n",
352 lpddi
->tszProductName
,
353 lpddi
->tszInstanceName
,
355 wine_dbgstr_guid(&lpddi
->guidProduct
),
356 wine_dbgstr_guid(&lpddi
->guidInstance
),
360 /* Check if this is a HID device */
361 if (lpddi
->dwDevType
& DIDEVTYPE_HID
)
362 ok(lpddi
->wUsagePage
== 0x01 && (lpddi
->wUsage
== 0x04 || lpddi
->wUsage
== 0x05),
363 "Expected a game controller HID UsagePage and Usage, got page 0x%x usage 0x%x\n",
364 lpddi
->wUsagePage
, lpddi
->wUsage
);
366 /* Test for joystick ID property */
367 ZeroMemory(&dipw
, sizeof(dipw
));
368 dipw
.diph
.dwSize
= sizeof(DIPROPDWORD
);
369 dipw
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
371 dipw
.diph
.dwHow
= DIPH_DEVICE
;
373 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_JOYSTICKID
, &dipw
.diph
);
374 ok(SUCCEEDED(hr
), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
376 /* Test for INSTANCENAME property */
377 memset(&dps
, 0, sizeof(dps
));
378 dps
.diph
.dwSize
= sizeof(DIPROPSTRING
);
379 dps
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
380 dps
.diph
.dwHow
= DIPH_DEVICE
;
382 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_INSTANCENAME
, &dps
.diph
);
383 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr
);
385 /* Test if instance name is the same as present in DIDEVICEINSTANCE */
386 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszInstanceName
, -1, nameBuffer
, MAX_PATH
);
387 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
388 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
390 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_PRODUCTNAME
, &dps
.diph
);
391 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_PRODUCTNAME failed: %08x\n", hr
);
393 /* Test if product name is the same as present in DIDEVICEINSTANCE */
394 MultiByteToWideChar(CP_ACP
, 0, lpddi
->tszProductName
, -1, nameBuffer
, MAX_PATH
);
395 ok(!lstrcmpW(nameBuffer
, dps
.wsz
), "DIPROP_PRODUCTNAME returned is wrong. Expected: %s Got: %s\n",
396 wine_dbgstr_w(nameBuffer
), wine_dbgstr_w(dps
.wsz
));
398 /* Test for GUIDPATH properties */
399 memset(&dpg
, 0, sizeof(dpg
));
400 dpg
.diph
.dwSize
= sizeof(DIPROPGUIDANDPATH
);
401 dpg
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
402 dpg
.diph
.dwHow
= DIPH_DEVICE
;
404 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_GUIDANDPATH
, &dpg
.diph
);
405 ok(SUCCEEDED(hr
), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr
);
410 _wcslwr(dpg
.wszPath
);
411 count
= swscanf(dpg
.wszPath
, L
"\\\\?\\%*[^#]#vid_%04x&pid_%04x", &vid
, &pid
);
412 ok(count
== 2, "DIPROP_GUIDANDPATH path has wrong format. Expected count: 2 Got: %i Path: %s\n",
413 count
, wine_dbgstr_w(dpg
.wszPath
));
414 ok(wcsstr(dpg
.wszPath
, L
"mi_") != 0 || wcsstr(dpg
.wszPath
, L
"ig_") != 0,
415 "DIPROP_GUIDANDPATH path should contain either 'ig_' or 'mi_' substring. Path: %s\n",
416 wine_dbgstr_w(dpg
.wszPath
));
419 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, NULL
);
420 ok(hr
==E_POINTER
,"IDirectInputDevice_SetDataFormat() should have returned "
421 "E_POINTER, returned: %08x\n", hr
);
423 ZeroMemory(&format
, sizeof(format
));
424 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &format
);
425 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_SetDataFormat() should have "
426 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
428 /* try the default formats */
429 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick
);
430 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
432 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
433 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
435 /* try an alternate format */
436 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystickTest
);
437 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
439 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
440 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
446 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, NULL
, i
);
447 ok(hr
== SetCoop_null_window
[i
], "SetCooperativeLevel(NULL, %d): %08x\n", i
, hr
);
451 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
, i
);
452 ok(hr
== SetCoop_real_window
[i
], "SetCooperativeLevel(hwnd, %d): %08x\n", i
, hr
);
455 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
456 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
457 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
459 /* get capabilities */
460 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, NULL
);
461 ok(hr
==E_POINTER
,"IDirectInputDevice_GetCapabilities() "
462 "should have returned E_POINTER, returned: %08x\n", hr
);
464 ZeroMemory(&caps
, sizeof(caps
));
465 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
466 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputDevice_GetCapabilities() "
467 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
469 caps
.dwSize
= sizeof(caps
);
470 hr
= IDirectInputDevice_GetCapabilities(pJoystick
, &caps
);
471 ok(hr
==DI_OK
,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr
);
473 ZeroMemory(&info
, sizeof(info
));
474 info
.pJoystick
= pJoystick
;
476 /* default min/max limits */
479 /* enumerate objects */
480 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
481 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
483 ok(caps
.dwAxes
== info
.axis
, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info
.axis
, caps
.dwAxes
);
484 ok(caps
.dwButtons
== info
.button
, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info
.button
, caps
.dwButtons
);
485 ok(caps
.dwPOVs
== info
.pov
, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info
.pov
, caps
.dwPOVs
);
487 /* Set format and check limits again */
488 hr
= IDirectInputDevice_SetDataFormat(pJoystick
, &c_dfDIJoystick2
);
489 ok(hr
==DI_OK
,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr
);
493 hr
= IDirectInputDevice_EnumObjects(pJoystick
, EnumAxes
, &info
, DIDFT_ALL
);
494 ok(hr
==DI_OK
,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr
);
496 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, 0);
497 ok(hr
==E_POINTER
, "IDirectInputDevice_GetDeviceInfo() "
498 "should have returned E_POINTER, returned: %08x\n", hr
);
500 ZeroMemory(&inst
, sizeof(inst
));
501 ZeroMemory(&inst3
, sizeof(inst3
));
503 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
504 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_GetDeviceInfo() "
505 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr
);
507 inst
.dwSize
= sizeof(inst
);
508 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, &inst
);
509 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
511 inst3
.dwSize
= sizeof(inst3
);
512 hr
= IDirectInputDevice_GetDeviceInfo(pJoystick
, (DIDEVICEINSTANCEA
*)&inst3
);
513 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr
);
515 hr
= IDirectInputDevice_Unacquire(pJoystick
);
516 ok(hr
== S_FALSE
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
518 hr
= IDirectInputDevice_Acquire(pJoystick
);
519 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
523 hr
= IDirectInputDevice_Acquire(pJoystick
);
524 ok(hr
== S_FALSE
, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr
);
528 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
529 ok(hr
== DI_OK
, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
530 ok(js
.rgdwPOV
[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js
.rgdwPOV
[3]);
533 trace("Testing force feedback\n");
534 ZeroMemory(&effect_data
, sizeof(effect_data
));
535 effect_data
.eff
.dwSize
= sizeof(effect_data
.eff
);
536 effect_data
.eff
.dwFlags
= DIEFF_CARTESIAN
| DIEFF_OBJECTOFFSETS
;
537 effect_data
.eff
.dwDuration
= INFINITE
;
538 effect_data
.eff
.dwGain
= DI_FFNOMINALMAX
;
539 effect_data
.eff
.dwTriggerButton
= DIEB_NOTRIGGER
;
540 effect_data
.eff
.cAxes
= ARRAY_SIZE(axes
);
541 effect_data
.eff
.rgdwAxes
= axes
;
542 effect_data
.eff
.rglDirection
= direction
;
544 /* Sending effects to joystick requires
545 * calling IDirectInputEffect_Initialize, which requires
546 * having exclusive access to the device, which requires
547 * - not having acquired the joystick when calling
548 * IDirectInputDevice_SetCooperativeLevel
551 real_hWnd
= CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL
, NULL
,
553 ok(real_hWnd
!=0,"CreateWindowExA failed: %p\n", real_hWnd
);
554 ShowWindow(real_hWnd
, SW_SHOW
);
555 hr
= IDirectInputDevice_Unacquire(pJoystick
);
556 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
557 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, real_hWnd
,
558 DISCL_EXCLUSIVE
| DISCL_FOREGROUND
);
559 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
560 hr
= IDirectInputDevice_Acquire(pJoystick
);
561 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
563 cnt1
= get_refcount((IUnknown
*)pJoystick
);
565 hr
= IDirectInputDevice2_EnumEffects((IDirectInputDevice2A
*)pJoystick
, EnumEffects
, &effect_data
, DIEFT_ALL
);
566 ok(hr
==DI_OK
,"IDirectInputDevice2_EnumEffects() failed: %08x\n", hr
);
568 /* If the controller does not support ANY effect use the constant effect to make
569 * CreateEffect fail but with the unsupported reason instead of invalid parameters. */
570 if (!effect_data
.effect_count
)
572 static DICONSTANTFORCE constant
;
573 effect_data
.guid
= GUID_ConstantForce
;
574 effect_data
.eff
.cbTypeSpecificParams
= sizeof(constant
);
575 effect_data
.eff
.lpvTypeSpecificParams
= &constant
;
576 effect_data
.effect_name
= "Constant";
577 constant
.lMagnitude
= DI_FFNOMINALMAX
/ 2;
579 ok(!(caps
.dwFlags
& DIDC_FORCEFEEDBACK
), "effect count is zero but controller supports force feedback?\n");
582 effect
= (void *)0xdeadbeef;
583 hr
= IDirectInputDevice2_CreateEffect((IDirectInputDevice2A
*)pJoystick
, &effect_data
.guid
,
584 &effect_data
.eff
, &effect
, NULL
);
585 if (caps
.dwFlags
& DIDC_FORCEFEEDBACK
)
587 trace("force feedback supported with %d effects, using '%s' for test\n",
588 effect_data
.effect_count
, effect_data
.effect_name
);
589 ok(hr
== DI_OK
, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr
);
590 cnt2
= get_refcount((IUnknown
*)pJoystick
);
591 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
596 struct DIPROPDWORD diprop_word
;
599 DIEFFECT effect_empty
;
601 hr
= IDirectInputEffect_Initialize(effect
, hInstance
, data
->version
,
603 ok(hr
==DI_OK
,"IDirectInputEffect_Initialize failed: %08x\n", hr
);
605 /* Test SetParameters with NULL pointers */
606 tmp
= effect_data
.eff
.rgdwAxes
;
607 effect_data
.eff
.rgdwAxes
= NULL
;
608 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_AXES
);
609 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputEffect_SetParameters should fail with INVALIDPARAM, got: %08x\n", hr
);
610 effect_data
.eff
.rgdwAxes
= tmp
;
612 tmp
= effect_data
.eff
.rglDirection
;
613 effect_data
.eff
.rglDirection
= NULL
;
614 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_DIRECTION
);
615 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputEffect_SetParameters should fail with INVALIDPARAM, got: %08x\n", hr
);
616 effect_data
.eff
.rglDirection
= tmp
;
618 tmp
= effect_data
.eff
.lpvTypeSpecificParams
;
619 effect_data
.eff
.lpvTypeSpecificParams
= NULL
;
620 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_TYPESPECIFICPARAMS
);
621 ok(hr
==DIERR_INVALIDPARAM
,"IDirectInputEffect_SetParameters should fail with INVALIDPARAM, got: %08x\n", hr
);
622 effect_data
.eff
.lpvTypeSpecificParams
= tmp
;
624 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_AXES
| DIEP_DIRECTION
|
625 DIEP_TYPESPECIFICPARAMS
);
626 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
628 /* Test that upload, unacquire, acquire still permits updating
629 * uploaded effect. */
630 hr
= IDirectInputDevice_Unacquire(pJoystick
);
631 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
632 hr
= IDirectInputDevice_Acquire(pJoystick
);
633 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
634 hr
= IDirectInputEffect_SetParameters(effect
, &effect_data
.eff
, DIEP_GAIN
);
635 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
638 /* Check effect status.
639 * State: initially stopped
642 * unacquire, acquire, download
648 * - effects are stopped after Unacquire + Acquire
649 * - effects are preserved (Download + Start doesn't complain
650 * about incomplete effect)
652 hr
= IDirectInputEffect_GetEffectStatus(effect
, NULL
);
653 ok(hr
==E_POINTER
,"IDirectInputEffect_GetEffectStatus() must fail with E_POINTER, got: %08x\n", hr
);
654 effect_status
= 0xdeadbeef;
655 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
656 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
657 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
658 /* SetParameters with a zeroed-out DIEFFECT and flags=0 should do nothing. */
659 memset(&effect_empty
, 0, sizeof(effect_empty
));
660 effect_empty
.dwSize
= sizeof(effect_empty
);
661 hr
= IDirectInputEffect_SetParameters(effect
, &effect_empty
, 0);
662 ok(hr
==DI_NOEFFECT
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
663 /* Start effect with SetParameters and a zeroed-out DIEFFECT. */
664 hr
= IDirectInputEffect_SetParameters(effect
, &effect_empty
, DIEP_START
);
665 ok(hr
==DI_OK
,"IDirectInputEffect_SetParameters failed: %08x\n", hr
);
666 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
667 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
668 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
669 hr
= IDirectInputDevice_Unacquire(pJoystick
);
670 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
671 hr
= IDirectInputDevice_Acquire(pJoystick
);
672 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
673 hr
= IDirectInputEffect_Download(effect
);
674 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
675 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
676 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
677 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
678 hr
= IDirectInputEffect_Start(effect
, 1, 0);
679 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
680 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
681 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
682 Sleep(250); /* feel the magic */
683 todo_wine
ok(effect_status
!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
684 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
685 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
686 ok(IsEqualGUID(&effect_data
.guid
, &guid
), "Wrong guid returned\n");
688 /* Check autocenter status
689 * State: initially stopped
697 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
698 * executed when the device is released.
700 * If Executed interactively, user can feel that autocenter is
701 * only disabled when the joystick is acquired.
703 diprop_word
.diph
.dwSize
= sizeof(diprop_word
);
704 diprop_word
.diph
.dwHeaderSize
= sizeof(diprop_word
.diph
);
705 diprop_word
.diph
.dwObj
= 0;
706 diprop_word
.diph
.dwHow
= DIPH_DEVICE
;
707 hr
= IDirectInputDevice_Unacquire(pJoystick
);
708 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
709 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
710 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
711 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_ON
,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
712 diprop_word
.dwData
= DIPROPAUTOCENTER_OFF
;
713 hr
= IDirectInputDevice2_SetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
714 ok(hr
==DI_OK
,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr
);
715 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
716 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
717 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
718 if (winetest_interactive
) {
719 trace("Acquiring in 2s, autocenter will be disabled.\n");
722 hr
= IDirectInputDevice_Acquire(pJoystick
);
723 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
724 if (winetest_interactive
)
725 trace("Acquired.\n");
726 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
727 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
728 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
729 if (winetest_interactive
) {
730 trace("Releasing in 2s, autocenter will be re-enabled.\n");
733 hr
= IDirectInputDevice_Unacquire(pJoystick
);
734 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
735 if (winetest_interactive
)
737 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
738 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
739 ok(diprop_word
.dwData
==DIPROPAUTOCENTER_OFF
,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
740 hr
= IDirectInputDevice_Acquire(pJoystick
);
741 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
742 hr
= IDirectInputDevice2_GetProperty(pJoystick
, DIPROP_AUTOCENTER
, &diprop_word
.diph
);
743 ok(hr
==DI_OK
,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr
);
745 /* Device gain (DIPROP_FFGAIN).
747 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
748 * Can be changed even if device is acquired.
749 * Difference found by tests:
750 * <0 is refused, >10000 is accepted
752 dip_gain_set
.diph
.dwSize
= sizeof(DIPROPDWORD
);
753 dip_gain_set
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
754 dip_gain_set
.diph
.dwObj
= 0;
755 dip_gain_set
.diph
.dwHow
= DIPH_DEVICE
;
756 dip_gain_get
.diph
.dwSize
= sizeof(DIPROPDWORD
);
757 dip_gain_get
.diph
.dwHeaderSize
= sizeof(DIPROPHEADER
);
758 dip_gain_get
.diph
.dwObj
= 0;
759 dip_gain_get
.diph
.dwHow
= DIPH_DEVICE
;
760 dip_gain_get
.dwData
= 0;
762 /* Test device is acquisition (non)impact. */
763 hr
= IDirectInputDevice_Unacquire(pJoystick
);
764 ok(hr
== DI_OK
, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr
);
765 dip_gain_set
.dwData
= 1;
766 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
767 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
768 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
769 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
770 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
771 hr
= IDirectInputDevice_Acquire(pJoystick
);
772 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
773 dip_gain_set
.dwData
= 2;
774 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
775 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
776 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
777 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
778 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
779 /* Test range and internal clamping. */
780 dip_gain_set
.dwData
= -1;
781 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
782 todo_wine
ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM
, hr
);
783 dip_gain_set
.dwData
= 0;
784 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
785 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
786 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
787 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
788 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
789 dip_gain_set
.dwData
= 10000;
790 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
791 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
792 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
793 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
794 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
795 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
796 dip_gain_set
.dwData
= 10001;
797 hr
= IDirectInputDevice_SetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_set
.diph
);
798 ok(hr
==DI_OK
, "IDirectInputDevice_SetProperty() failed: %08x\n", hr
);
799 hr
= IDirectInputDevice_GetProperty(pJoystick
, DIPROP_FFGAIN
, &dip_gain_get
.diph
);
800 ok(hr
==DI_OK
, "IDirectInputDevice_GetProperty() failed: %08x\n", hr
);
801 ok(dip_gain_get
.dwData
==dip_gain_set
.dwData
, "Gain not updated: %i\n", dip_gain_get
.dwData
);
803 /* Test SendForceFeedbackCommand
804 * DISFFC_STOPALL - Should stop effects only
805 * DISFFC_RESET - Should stop effects and unload them (NOT release them)
806 * Tests for game Odallus (bug 41623) */
807 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, 0);
808 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
809 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, 0xFF);
810 ok(hr
==DIERR_INVALIDPARAM
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
812 hr
= IDirectInputEffect_Download(effect
);
813 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
815 /* Send STOPALL and prove that the effect can still be started */
816 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, DISFFC_STOPALL
);
817 ok(hr
==DI_OK
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
818 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
819 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
820 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
821 hr
= IDirectInputEffect_Start(effect
, 1, 0);
822 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
823 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
824 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
825 ok(IsEqualGUID(&effect_data
.guid
, &guid
), "Wrong guid returned\n");
827 /* Send RESET and prove that we can still manipulate the effect, thus not released */
828 hr
= IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A
*)pJoystick
, DISFFC_RESET
);
829 ok(hr
==DI_OK
, "IDirectInputDevice_SendForceFeedbackCommand() failed: %08x\n", hr
);
830 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
831 ok(hr
==DIERR_NOTDOWNLOADED
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
832 hr
= IDirectInputEffect_Download(effect
);
833 ok(hr
==DI_OK
,"IDirectInputEffect_Download() failed: %08x\n", hr
);
834 hr
= IDirectInputEffect_GetEffectStatus(effect
, &effect_status
);
835 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr
);
836 ok(effect_status
==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
837 hr
= IDirectInputEffect_Start(effect
, 1, 0);
838 ok(hr
==DI_OK
,"IDirectInputEffect_Start() failed: %08x\n", hr
);
839 hr
= IDirectInputEffect_GetEffectGuid(effect
, &guid
);
840 ok(hr
==DI_OK
,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr
);
841 ok(IsEqualGUID(&effect_data
.guid
, &guid
), "Wrong guid returned\n");
843 ref
= IUnknown_Release(effect
);
844 ok(ref
== 0, "IDirectInputDevice_Release() reference count = %d\n", ref
);
846 cnt1
= get_refcount((IUnknown
*)pJoystick
);
847 ok(cnt1
== cnt2
, "Ref count is wrong %d != %d\n", cnt1
, cnt2
);
849 /* No force feedback support, CreateEffect is supposed to fail. Fairy Bloom Freesia
850 * calls CreateEffect without checking the DIDC_FORCEFEEDBACK. It expects the correct
851 * error return to determine if force feedback is unsupported. */
854 trace("No force feedback support\n");
855 ok(hr
==DIERR_UNSUPPORTED
, "IDirectInputDevice_CreateEffect() must fail with DIERR_UNSUPPORTED, got: %08x\n", hr
);
856 ok(effect
== NULL
, "effect must be NULL, got %p\n", effect
);
859 /* Before destroying the window, release joystick to revert to
860 * non-exclusive, background cooperative level. */
861 hr
= IDirectInputDevice_Unacquire(pJoystick
);
862 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
863 hr
= IDirectInputDevice_SetCooperativeLevel(pJoystick
, hWnd
,
864 DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
);
865 ok(hr
==DI_OK
,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr
);
866 DestroyWindow (real_hWnd
);
867 hr
= IDirectInputDevice_Acquire(pJoystick
);
868 ok(hr
==DI_OK
,"IDirectInputDevice_Acquire() failed: %08x\n", hr
);
870 if (winetest_interactive
) {
871 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
878 for (i
= 0; i
< count
; i
++) {
879 hr
= IDirectInputDevice_GetDeviceState(pJoystick
, sizeof(DIJOYSTATE2
), &js
);
880 ok(hr
==DI_OK
,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr
);
883 sprintf(curstate
, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
884 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
885 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
886 js
.lX
, js
.lY
, js
.lZ
, js
.lRx
, js
.lRy
, js
.lRz
,
887 js
.rglSlider
[0], js
.rglSlider
[1],
888 js
.rgdwPOV
[0], js
.rgdwPOV
[1], js
.rgdwPOV
[2], js
.rgdwPOV
[3],
889 js
.rgbButtons
[0]>>7, js
.rgbButtons
[1]>>7, js
.rgbButtons
[2]>>7,
890 js
.rgbButtons
[3]>>7, js
.rgbButtons
[4]>>7, js
.rgbButtons
[5]>>7,
891 js
.rgbButtons
[6]>>7, js
.rgbButtons
[7]>>7, js
.rgbButtons
[8]>>7,
892 js
.rgbButtons
[9]>>7, js
.rgbButtons
[10]>>7, js
.rgbButtons
[11]>>7);
893 if (strcmp(oldstate
, curstate
) != 0)
895 trace("%s\n", curstate
);
896 strcpy(oldstate
, curstate
);
902 hr
= IDirectInputDevice_Unacquire(pJoystick
);
903 ok(hr
==DI_OK
,"IDirectInputDevice_Unacquire() failed: %08x\n", hr
);
906 ref
= IDirectInputDevice_Release(pJoystick
);
907 ok(ref
==0,"IDirectInputDevice_Release() reference count = %d\n", ref
);
910 return DIENUM_CONTINUE
;
913 static void joystick_tests(DWORD version
)
918 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
920 trace("-- Testing Direct Input Version 0x%04x --\n", version
);
921 hr
= DirectInputCreateA(hInstance
, version
, &pDI
, NULL
);
922 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
, "DirectInputCreateA() failed: %08x\n", hr
);
923 if (hr
==DI_OK
&& pDI
!=0) {
926 data
.version
= version
;
927 hr
= IDirectInput_EnumDevices(pDI
, DIDEVTYPE_JOYSTICK
, EnumJoysticks
,
928 &data
, DIEDFL_ALLDEVICES
);
929 ok(hr
==DI_OK
,"IDirectInput_EnumDevices() failed: %08x\n", hr
);
930 ref
= IDirectInput_Release(pDI
);
931 ok(ref
==0,"IDirectInput_Release() reference count = %d\n", ref
);
932 } else if (hr
==DIERR_OLDDIRECTINPUTVERSION
)
933 trace(" Version Not Supported\n");
936 static void test_enum_feedback(void)
941 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
943 hr
= DirectInputCreateA(hInstance
, 0x0700, &pDI
, NULL
);
944 ok(hr
==DI_OK
||hr
==DIERR_OLDDIRECTINPUTVERSION
, "DirectInputCreateA() failed: %08x\n", hr
);
945 if (hr
==DI_OK
&& pDI
!=0) {
946 hr
= IDirectInput_EnumDevices(pDI
, 0, EnumAllFeedback
, NULL
, DIEDFL_ATTACHEDONLY
| DIEDFL_FORCEFEEDBACK
);
947 ok(hr
==DI_OK
,"IDirectInput_EnumDevices() failed: %08x\n", hr
);
948 ref
= IDirectInput_Release(pDI
);
949 ok(ref
==0,"IDirectInput_Release() reference count = %d\n", ref
);
950 } else if (hr
==DIERR_OLDDIRECTINPUTVERSION
)
951 trace(" Version Not Supported\n");
958 joystick_tests(0x0700);
959 joystick_tests(0x0500);
960 joystick_tests(0x0300);
962 test_enum_feedback();