[DINPUT_WINETEST] Sync with Wine Staging 1.9.23. CORE-12409
[reactos.git] / rostests / winetests / dinput / joystick.c
1 /*
2 * Copyright (c) 2004-2005 Robert Reif
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COM_NO_WINDOWS_H
22
23 #define DIRECTINPUT_VERSION 0x0700
24
25 #define COBJMACROS
26 //#include <windows.h>
27
28 //#include <math.h>
29 #include <stdio.h>
30 //#include <stdlib.h>
31
32 #include <wine/test.h>
33 //#include "windef.h"
34 //#include "wingdi.h"
35 #include <winnls.h>
36 #include <dinput.h>
37
38 #define numObjects(x) (sizeof(x) / sizeof(x[0]))
39
40 typedef struct tagUserData {
41 IDirectInputA *pDI;
42 DWORD version;
43 } UserData;
44
45 static const DIOBJECTDATAFORMAT dfDIJoystickTest[] = {
46 { &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
47 { &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
48 { &GUID_ZAxis,DIJOFS_Z,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
49 { &GUID_RxAxis,DIJOFS_RX,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
50 { &GUID_RyAxis,DIJOFS_RY,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
51 { &GUID_RzAxis,DIJOFS_RZ,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
52 { &GUID_Button,DIJOFS_BUTTON(0),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
53 { &GUID_Button,DIJOFS_BUTTON(1),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
54 { &GUID_Button,DIJOFS_BUTTON(2),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
55 { &GUID_Button,DIJOFS_BUTTON(3),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
56 { &GUID_Button,DIJOFS_BUTTON(4),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
57 { &GUID_Button,DIJOFS_BUTTON(5),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
58 { &GUID_Button,DIJOFS_BUTTON(6),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
59 { &GUID_Button,DIJOFS_BUTTON(7),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
60 { &GUID_Button,DIJOFS_BUTTON(8),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
61 { &GUID_Button,DIJOFS_BUTTON(9),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
62 { &GUID_Button,DIJOFS_BUTTON(10),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
63 };
64
65 static const DIDATAFORMAT c_dfDIJoystickTest = {
66 sizeof(DIDATAFORMAT),
67 sizeof(DIOBJECTDATAFORMAT),
68 DIDF_ABSAXIS,
69 sizeof(DIJOYSTATE2),
70 numObjects(dfDIJoystickTest),
71 (LPDIOBJECTDATAFORMAT)dfDIJoystickTest
72 };
73
74 static HWND get_hwnd(void)
75 {
76 HWND hwnd=GetForegroundWindow();
77 if (!hwnd)
78 hwnd=GetDesktopWindow();
79 return hwnd;
80 }
81
82 typedef struct tagJoystickInfo
83 {
84 IDirectInputDeviceA *pJoystick;
85 DWORD axis;
86 DWORD pov;
87 DWORD button;
88 LONG lMin, lMax;
89 DWORD dZone;
90 } JoystickInfo;
91
92 static int get_refcount(IUnknown *object)
93 {
94 IUnknown_AddRef( object );
95 return IUnknown_Release( object );
96 }
97
98 static BOOL CALLBACK EnumAxes(const DIDEVICEOBJECTINSTANCEA *pdidoi, void *pContext)
99 {
100 HRESULT hr;
101 JoystickInfo * info = pContext;
102
103 if (IsEqualIID(&pdidoi->guidType, &GUID_XAxis) ||
104 IsEqualIID(&pdidoi->guidType, &GUID_YAxis) ||
105 IsEqualIID(&pdidoi->guidType, &GUID_ZAxis) ||
106 IsEqualIID(&pdidoi->guidType, &GUID_RxAxis) ||
107 IsEqualIID(&pdidoi->guidType, &GUID_RyAxis) ||
108 IsEqualIID(&pdidoi->guidType, &GUID_RzAxis) ||
109 IsEqualIID(&pdidoi->guidType, &GUID_Slider))
110 {
111 DIPROPRANGE diprg;
112 DIPROPDWORD dipdw;
113
114 diprg.diph.dwSize = sizeof(DIPROPRANGE);
115 diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
116 diprg.diph.dwHow = DIPH_BYID;
117 diprg.diph.dwObj = pdidoi->dwType;
118
119 dipdw.diph.dwSize = sizeof(dipdw);
120 dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
121 dipdw.diph.dwHow = DIPH_BYID;
122 dipdw.diph.dwObj = pdidoi->dwType;
123
124 hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
125 ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
126 ok(info->lMin == diprg.lMin && info->lMax == diprg.lMax, "Min/Max range invalid: "
127 "expected %d..%d got %d..%d\n", info->lMin, info->lMax, diprg.lMin, diprg.lMax);
128
129 diprg.lMin = -2000;
130 diprg.lMax = +2000;
131
132 hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, NULL);
133 ok(hr==E_INVALIDARG,"IDirectInputDevice_SetProperty() should have returned "
134 "E_INVALIDARG, returned: %08x\n", hr);
135
136 hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
137 ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %08x\n", hr);
138
139 /* dead zone */
140 hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph);
141 ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
142 ok(info->dZone == dipdw.dwData, "deadzone invalid: expected %d got %d\n",
143 info->dZone, dipdw.dwData);
144
145 dipdw.dwData = 123;
146
147 hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph);
148 ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %08x\n", hr);
149
150 /* ensure DIDOI_ASPECTPOSITION is set for axes objects */
151 ok(pdidoi->dwFlags & DIDOI_ASPECTPOSITION, "Missing DIDOI_ASPECTPOSITION, flags are 0x%x\n",
152 pdidoi->dwFlags);
153
154 info->axis++;
155 } else if (IsEqualIID(&pdidoi->guidType, &GUID_POV))
156 info->pov++;
157 else if (IsEqualIID(&pdidoi->guidType, &GUID_Button))
158 info->button++;
159
160 return DIENUM_CONTINUE;
161 }
162
163 static const struct effect_id
164 {
165 const GUID *guid;
166 int dieft;
167 const char *name;
168 } effect_conversion[] = {
169 {&GUID_ConstantForce, DIEFT_CONSTANTFORCE, "Constant"},
170 {&GUID_RampForce, DIEFT_RAMPFORCE, "Ramp"},
171 {&GUID_Square, DIEFT_PERIODIC, "Square"},
172 {&GUID_Sine, DIEFT_PERIODIC, "Sine"},
173 {&GUID_Triangle, DIEFT_PERIODIC, "Triangle"},
174 {&GUID_SawtoothUp, DIEFT_PERIODIC, "Saw Tooth Up"},
175 {&GUID_SawtoothDown, DIEFT_PERIODIC, "Saw Tooth Down"},
176 {&GUID_Spring, DIEFT_CONDITION, "Spring"},
177 {&GUID_Damper, DIEFT_CONDITION, "Damper"},
178 {&GUID_Inertia, DIEFT_CONDITION, "Inertia"},
179 {&GUID_Friction, DIEFT_CONDITION, "Friction"},
180 {&GUID_CustomForce, DIEFT_CUSTOMFORCE, "Custom"}
181 };
182
183 static const struct effect_id* effect_from_guid(const GUID *guid)
184 {
185 unsigned int i;
186 for (i = 0; i < sizeof(effect_conversion) / sizeof(effect_conversion[0]); i++)
187 if (IsEqualGUID(guid, effect_conversion[i].guid))
188 return &effect_conversion[i];
189 return NULL;
190 }
191
192 struct effect_enum
193 {
194 DIEFFECT eff;
195 GUID guid;
196 int effect_count;
197 const char *effect_name;
198 };
199
200 /* The last enumerated effect will be used for force feedback testing */
201 static BOOL CALLBACK EnumEffects(const DIEFFECTINFOA *lpef, void *ref)
202 {
203 const struct effect_id *id = effect_from_guid(&lpef->guid);
204 static union
205 {
206 DICONSTANTFORCE constant;
207 DIPERIODIC periodic;
208 DIRAMPFORCE ramp;
209 DICONDITION condition[2];
210 } specific;
211 struct effect_enum *data = ref;
212 int type = DIDFT_GETTYPE(lpef->dwEffType);
213
214 /* Insanity check */
215 if (!id)
216 {
217 ok(0, "unsupported effect enumerated, GUID %s!\n", wine_dbgstr_guid(&lpef->guid));
218 return DIENUM_CONTINUE;
219 }
220 trace("controller supports '%s' effect\n", id->name);
221 ok(type == id->dieft, "Invalid effect type, expected 0x%x, got 0x%x\n",
222 id->dieft, lpef->dwEffType);
223
224 /* Can't use custom for test as we don't know the data format */
225 if (type == DIEFT_CUSTOMFORCE)
226 return DIENUM_CONTINUE;
227
228 data->effect_count++;
229 data->effect_name = id->name;
230 data->guid = *id->guid;
231
232 ZeroMemory(&specific, sizeof(specific));
233 switch (type)
234 {
235 case DIEFT_PERIODIC:
236 data->eff.cbTypeSpecificParams = sizeof(specific.periodic);
237 data->eff.lpvTypeSpecificParams = &specific.periodic;
238 specific.periodic.dwMagnitude = DI_FFNOMINALMAX / 2;
239 specific.periodic.dwPeriod = DI_SECONDS; /* 1 second */
240 break;
241 case DIEFT_CONSTANTFORCE:
242 data->eff.cbTypeSpecificParams = sizeof(specific.constant);
243 data->eff.lpvTypeSpecificParams = &specific.constant;
244 specific.constant.lMagnitude = DI_FFNOMINALMAX / 2;
245 break;
246 case DIEFT_RAMPFORCE:
247 data->eff.cbTypeSpecificParams = sizeof(specific.ramp);
248 data->eff.lpvTypeSpecificParams = &specific.ramp;
249 specific.ramp.lStart = -DI_FFNOMINALMAX / 2;
250 specific.ramp.lEnd = +DI_FFNOMINALMAX / 2;
251 break;
252 case DIEFT_CONDITION:
253 {
254 int i;
255 data->eff.cbTypeSpecificParams = sizeof(specific.condition);
256 data->eff.lpvTypeSpecificParams = specific.condition;
257 for (i = 0; i < 2; i++)
258 {
259 specific.condition[i].lNegativeCoefficient = -DI_FFNOMINALMAX / 2;
260 specific.condition[i].lPositiveCoefficient = +DI_FFNOMINALMAX / 2;
261 }
262 break;
263 }
264 }
265 return DIENUM_CONTINUE;
266 }
267
268 static const HRESULT SetCoop_null_window[16] = {
269 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
270 E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
271 E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
272 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
273
274 static const HRESULT SetCoop_real_window[16] = {
275 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
276 E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
277 E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
278 E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
279
280 static BOOL CALLBACK EnumJoysticks(const DIDEVICEINSTANCEA *lpddi, void *pvRef)
281 {
282 HRESULT hr;
283 UserData * data = pvRef;
284 IDirectInputDeviceA *pJoystick;
285 DIDATAFORMAT format;
286 DIDEVCAPS caps;
287 DIJOYSTATE2 js;
288 JoystickInfo info;
289 int i, count;
290 ULONG ref;
291 DIDEVICEINSTANCEA inst;
292 DIDEVICEINSTANCE_DX3A inst3;
293 DIPROPDWORD dipw;
294 DIPROPSTRING dps;
295 DIPROPGUIDANDPATH dpg;
296 WCHAR nameBuffer[MAX_PATH];
297 HWND hWnd = get_hwnd();
298 char oldstate[248], curstate[248];
299 DWORD axes[2] = {DIJOFS_X, DIJOFS_Y};
300 LONG direction[2] = {0, 0};
301 LPDIRECTINPUTEFFECT effect = NULL;
302 LONG cnt1, cnt2;
303 HWND real_hWnd;
304 HINSTANCE hInstance = GetModuleHandleW(NULL);
305 DIPROPDWORD dip_gain_set, dip_gain_get;
306 struct effect_enum effect_data;
307
308 ok(data->version > 0x0300, "Joysticks not supported in version 0x%04x\n", data->version);
309
310 hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, NULL, NULL);
311 ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
312 "E_POINTER, returned: %08x\n", hr);
313
314 hr = IDirectInput_CreateDevice(data->pDI, NULL, &pJoystick, NULL);
315 ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
316 "E_POINTER, returned: %08x\n", hr);
317
318 hr = IDirectInput_CreateDevice(data->pDI, NULL, NULL, NULL);
319 ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
320 "E_POINTER, returned: %08x\n", hr);
321
322 hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance,
323 &pJoystick, NULL);
324 ok(hr==DI_OK,"IDirectInput_CreateDevice() failed: %08x\n", hr);
325 if (hr!=DI_OK)
326 goto DONE;
327
328 trace("---- Controller Information ----\n"
329 "Product Name : %s\n"
330 "Instance Name : %s\n"
331 "devType : 0x%08x\n"
332 "GUID Product : %s\n"
333 "GUID Instance : %s\n"
334 "HID Page : 0x%04x\n"
335 "HID Usage : 0x%04x\n",
336 lpddi->tszProductName,
337 lpddi->tszInstanceName,
338 lpddi->dwDevType,
339 wine_dbgstr_guid(&lpddi->guidProduct),
340 wine_dbgstr_guid(&lpddi->guidInstance),
341 lpddi->wUsagePage,
342 lpddi->wUsage);
343
344 /* Check if this is a HID device */
345 if (lpddi->dwDevType & DIDEVTYPE_HID)
346 ok(lpddi->wUsagePage == 0x01 && (lpddi->wUsage == 0x04 || lpddi->wUsage == 0x05),
347 "Expected a game controller HID UsagePage and Usage, got page 0x%x usage 0x%x\n",
348 lpddi->wUsagePage, lpddi->wUsage);
349
350 /* Test for joystick ID property */
351 ZeroMemory(&dipw, sizeof(dipw));
352 dipw.diph.dwSize = sizeof(DIPROPDWORD);
353 dipw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
354 dipw.diph.dwObj = 0;
355 dipw.diph.dwHow = DIPH_DEVICE;
356
357 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_JOYSTICKID, &dipw.diph);
358 ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n");
359
360 /* Test for INSTANCENAME property */
361 memset(&dps, 0, sizeof(dps));
362 dps.diph.dwSize = sizeof(DIPROPSTRING);
363 dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
364 dps.diph.dwHow = DIPH_DEVICE;
365
366 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_INSTANCENAME, &dps.diph);
367 ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %08x\n", hr);
368
369 /* Test if instance name is the same as present in DIDEVICEINSTANCE */
370 MultiByteToWideChar(CP_ACP, 0, lpddi->tszInstanceName, -1, nameBuffer, MAX_PATH);
371 ok(!lstrcmpW(nameBuffer, dps.wsz), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n",
372 wine_dbgstr_w(nameBuffer), wine_dbgstr_w(dps.wsz));
373
374 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_PRODUCTNAME, &dps.diph);
375 ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_PRODUCTNAME failed: %08x\n", hr);
376
377 /* Test if product name is the same as present in DIDEVICEINSTANCE */
378 MultiByteToWideChar(CP_ACP, 0, lpddi->tszProductName, -1, nameBuffer, MAX_PATH);
379 ok(!lstrcmpW(nameBuffer, dps.wsz), "DIPROP_PRODUCTNAME returned is wrong. Expected: %s Got: %s\n",
380 wine_dbgstr_w(nameBuffer), wine_dbgstr_w(dps.wsz));
381
382 /* Test for GUIDPATH properties */
383 memset(&dpg, 0, sizeof(dpg));
384 dpg.diph.dwSize = sizeof(DIPROPGUIDANDPATH);
385 dpg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
386 dpg.diph.dwHow = DIPH_DEVICE;
387
388 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_GUIDANDPATH, &dpg.diph);
389 todo_wine ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %08x\n", hr);
390
391 hr = IDirectInputDevice_SetDataFormat(pJoystick, NULL);
392 ok(hr==E_POINTER,"IDirectInputDevice_SetDataFormat() should have returned "
393 "E_POINTER, returned: %08x\n", hr);
394
395 ZeroMemory(&format, sizeof(format));
396 hr = IDirectInputDevice_SetDataFormat(pJoystick, &format);
397 ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_SetDataFormat() should have "
398 "returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
399
400 /* try the default formats */
401 hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick);
402 ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
403
404 hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
405 ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
406
407 /* try an alternate format */
408 hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystickTest);
409 ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
410
411 hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
412 ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
413 if (hr != DI_OK)
414 goto RELEASE;
415
416 for (i=0; i<16; i++)
417 {
418 hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, NULL, i);
419 ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
420 }
421 for (i=0; i<16; i++)
422 {
423 hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd, i);
424 ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
425 }
426
427 hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd,
428 DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
429 ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
430
431 /* get capabilities */
432 hr = IDirectInputDevice_GetCapabilities(pJoystick, NULL);
433 ok(hr==E_POINTER,"IDirectInputDevice_GetCapabilities() "
434 "should have returned E_POINTER, returned: %08x\n", hr);
435
436 ZeroMemory(&caps, sizeof(caps));
437 hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps);
438 ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_GetCapabilities() "
439 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
440
441 caps.dwSize = sizeof(caps);
442 hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps);
443 ok(hr==DI_OK,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr);
444
445 ZeroMemory(&info, sizeof(info));
446 info.pJoystick = pJoystick;
447
448 /* default min/max limits */
449 info.lMin = 0;
450 info.lMax = 0xffff;
451 /* enumerate objects */
452 hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, &info, DIDFT_ALL);
453 ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
454
455 ok(caps.dwAxes == info.axis, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info.axis, caps.dwAxes);
456 ok(caps.dwButtons == info.button, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info.button, caps.dwButtons);
457 ok(caps.dwPOVs == info.pov, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info.pov, caps.dwPOVs);
458
459 /* Set format and check limits again */
460 hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
461 ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
462 info.lMin = -2000;
463 info.lMax = +2000;
464 info.dZone= 123;
465 hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, &info, DIDFT_ALL);
466 ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
467
468 hr = IDirectInputDevice_GetDeviceInfo(pJoystick, 0);
469 ok(hr==E_POINTER, "IDirectInputDevice_GetDeviceInfo() "
470 "should have returned E_POINTER, returned: %08x\n", hr);
471
472 ZeroMemory(&inst, sizeof(inst));
473 ZeroMemory(&inst3, sizeof(inst3));
474
475 hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst);
476 ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceInfo() "
477 "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
478
479 inst.dwSize = sizeof(inst);
480 hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst);
481 ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr);
482
483 inst3.dwSize = sizeof(inst3);
484 hr = IDirectInputDevice_GetDeviceInfo(pJoystick, (DIDEVICEINSTANCEA*)&inst3);
485 ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr);
486
487 hr = IDirectInputDevice_Unacquire(pJoystick);
488 ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr);
489
490 hr = IDirectInputDevice_Acquire(pJoystick);
491 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
492 if (hr != DI_OK)
493 goto RELEASE;
494
495 hr = IDirectInputDevice_Acquire(pJoystick);
496 ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr);
497
498 if (info.pov < 4)
499 {
500 hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js);
501 ok(hr == DI_OK, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
502 ok(js.rgdwPOV[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js.rgdwPOV[3]);
503 }
504
505 trace("Testing force feedback\n");
506 ZeroMemory(&effect_data, sizeof(effect_data));
507 effect_data.eff.dwSize = sizeof(effect_data.eff);
508 effect_data.eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
509 effect_data.eff.dwDuration = INFINITE;
510 effect_data.eff.dwGain = DI_FFNOMINALMAX;
511 effect_data.eff.dwTriggerButton = DIEB_NOTRIGGER;
512 effect_data.eff.cAxes = sizeof(axes) / sizeof(axes[0]);
513 effect_data.eff.rgdwAxes = axes;
514 effect_data.eff.rglDirection = direction;
515
516 /* Sending effects to joystick requires
517 * calling IDirectInputEffect_Initialize, which requires
518 * having exclusive access to the device, which requires
519 * - not having acquired the joystick when calling
520 * IDirectInputDevice_SetCooperativeLevel
521 * - a visible window
522 */
523 real_hWnd = CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL, NULL,
524 hInstance, NULL);
525 ok(real_hWnd!=0,"CreateWindowExA failed: %p\n", real_hWnd);
526 ShowWindow(real_hWnd, SW_SHOW);
527 hr = IDirectInputDevice_Unacquire(pJoystick);
528 ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
529 hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, real_hWnd,
530 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
531 ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
532 hr = IDirectInputDevice_Acquire(pJoystick);
533 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
534
535 cnt1 = get_refcount((IUnknown*)pJoystick);
536
537 hr = IDirectInputDevice2_EnumEffects((IDirectInputDevice2A*)pJoystick, EnumEffects, &effect_data, DIEFT_ALL);
538 ok(hr==DI_OK,"IDirectInputDevice2_EnumEffects() failed: %08x\n", hr);
539
540 /* If the controller does not support ANY effect use the constant effect to make
541 * CreateEffect fail but with the unsupported reason instead of invalid parameters. */
542 if (!effect_data.effect_count)
543 {
544 static DICONSTANTFORCE constant;
545 effect_data.guid = GUID_ConstantForce;
546 effect_data.eff.cbTypeSpecificParams = sizeof(constant);
547 effect_data.eff.lpvTypeSpecificParams = &constant;
548 effect_data.effect_name = "Constant";
549 constant.lMagnitude = DI_FFNOMINALMAX / 2;
550
551 ok(!(caps.dwFlags & DIDC_FORCEFEEDBACK), "effect count is zero but controller supports force feedback?\n");
552 }
553
554 effect = (void *)0xdeadbeef;
555 hr = IDirectInputDevice2_CreateEffect((IDirectInputDevice2A*)pJoystick, &effect_data.guid,
556 &effect_data.eff, &effect, NULL);
557 if (caps.dwFlags & DIDC_FORCEFEEDBACK)
558 {
559 trace("force feedback supported with %d effects, using '%s' for test\n",
560 effect_data.effect_count, effect_data.effect_name);
561 ok(hr == DI_OK, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr);
562 cnt2 = get_refcount((IUnknown*)pJoystick);
563 ok(cnt1 == cnt2, "Ref count is wrong %d != %d\n", cnt1, cnt2);
564
565 if (effect)
566 {
567 DWORD effect_status;
568 struct DIPROPDWORD diprop_word;
569 GUID guid = {0};
570
571 hr = IDirectInputEffect_Initialize(effect, hInstance, data->version,
572 &effect_data.guid);
573 ok(hr==DI_OK,"IDirectInputEffect_Initialize failed: %08x\n", hr);
574 hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_AXES | DIEP_DIRECTION |
575 DIEP_TYPESPECIFICPARAMS);
576 ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
577 if (hr==DI_OK) {
578 /* Test that upload, unacquire, acquire still permits updating
579 * uploaded effect. */
580 hr = IDirectInputDevice_Unacquire(pJoystick);
581 ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
582 hr = IDirectInputDevice_Acquire(pJoystick);
583 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
584 hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_GAIN);
585 ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
586 }
587
588 /* Check effect status.
589 * State: initially stopped
590 * start
591 * State: started
592 * unacquire, acquire, download
593 * State: stopped
594 * start
595 * State: started
596 *
597 * Shows that:
598 * - effects are stopped after Unacquire + Acquire
599 * - effects are preserved (Download + Start doesn't complain
600 * about incomplete effect)
601 */
602 hr = IDirectInputEffect_GetEffectStatus(effect, NULL);
603 ok(hr==E_POINTER,"IDirectInputEffect_GetEffectStatus() must fail with E_POINTER, got: %08x\n", hr);
604 effect_status = 0xdeadbeef;
605 hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
606 ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
607 ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
608 hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_START);
609 ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
610 hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
611 ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
612 todo_wine ok(effect_status!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
613 hr = IDirectInputDevice_Unacquire(pJoystick);
614 ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
615 hr = IDirectInputDevice_Acquire(pJoystick);
616 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
617 hr = IDirectInputEffect_Download(effect);
618 ok(hr==DI_OK,"IDirectInputEffect_Download() failed: %08x\n", hr);
619 hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
620 ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
621 ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n");
622 hr = IDirectInputEffect_Start(effect, 1, 0);
623 ok(hr==DI_OK,"IDirectInputEffect_Start() failed: %08x\n", hr);
624 hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status);
625 ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %08x\n", hr);
626 Sleep(250); /* feel the magic */
627 todo_wine ok(effect_status!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n");
628 hr = IDirectInputEffect_GetEffectGuid(effect, &guid);
629 ok(hr==DI_OK,"IDirectInputEffect_GetEffectGuid() failed: %08x\n", hr);
630 ok(IsEqualGUID(&effect_data.guid, &guid), "Wrong guid returned\n");
631
632 /* Check autocenter status
633 * State: initially stopped
634 * enable
635 * State: enabled
636 * acquire
637 * State: enabled
638 * unacquire
639 * State: enabled
640 *
641 * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be
642 * executed when the device is released.
643 *
644 * If Executed interactively, user can feel that autocenter is
645 * only disabled when the joystick is acquired.
646 */
647 diprop_word.diph.dwSize = sizeof(diprop_word);
648 diprop_word.diph.dwHeaderSize = sizeof(diprop_word.diph);
649 diprop_word.diph.dwObj = 0;
650 diprop_word.diph.dwHow = DIPH_DEVICE;
651 hr = IDirectInputDevice_Unacquire(pJoystick);
652 ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
653 hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
654 ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
655 ok(diprop_word.dwData==DIPROPAUTOCENTER_ON,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n");
656 diprop_word.dwData = DIPROPAUTOCENTER_OFF;
657 hr = IDirectInputDevice2_SetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
658 ok(hr==DI_OK,"IDirectInputDevice2_SetProperty() failed: %08x\n", hr);
659 hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
660 ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
661 ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
662 if (winetest_interactive) {
663 trace("Acquiring in 2s, autocenter will be disabled.\n");
664 Sleep(2000);
665 }
666 hr = IDirectInputDevice_Acquire(pJoystick);
667 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
668 if (winetest_interactive)
669 trace("Acquired.\n");
670 hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
671 ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
672 ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
673 if (winetest_interactive) {
674 trace("Releasing in 2s, autocenter will be re-enabled.\n");
675 Sleep(2000);
676 }
677 hr = IDirectInputDevice_Unacquire(pJoystick);
678 ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
679 if (winetest_interactive)
680 trace("Released\n");
681 hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
682 ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
683 ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n");
684 hr = IDirectInputDevice_Acquire(pJoystick);
685 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
686 hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph);
687 ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %08x\n", hr);
688
689 /* Device gain (DIPROP_FFGAIN).
690 * From MSDN:
691 * 0..10000 range, otherwise DIERR_INVALIDPARAM.
692 * Can be changed even if device is acquired.
693 * Difference found by tests:
694 * <0 is refused, >10000 is accepted
695 */
696 dip_gain_set.diph.dwSize = sizeof(DIPROPDWORD);
697 dip_gain_set.diph.dwHeaderSize = sizeof(DIPROPHEADER);
698 dip_gain_set.diph.dwObj = 0;
699 dip_gain_set.diph.dwHow = DIPH_DEVICE;
700 dip_gain_get.diph.dwSize = sizeof(DIPROPDWORD);
701 dip_gain_get.diph.dwHeaderSize = sizeof(DIPROPHEADER);
702 dip_gain_get.diph.dwObj = 0;
703 dip_gain_get.diph.dwHow = DIPH_DEVICE;
704 dip_gain_get.dwData = 0;
705
706 /* Test device is acquisition (non)impact. */
707 hr = IDirectInputDevice_Unacquire(pJoystick);
708 ok(hr == DI_OK, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr);
709 dip_gain_set.dwData = 1;
710 hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
711 ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
712 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
713 ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
714 ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
715 hr = IDirectInputDevice_Acquire(pJoystick);
716 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
717 dip_gain_set.dwData = 2;
718 hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
719 ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
720 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
721 ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
722 ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
723 /* Test range and internal clamping. */
724 dip_gain_set.dwData = -1;
725 hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
726 todo_wine ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_SetProperty() should have returned %08x: %08x\n", DIERR_INVALIDPARAM, hr);
727 dip_gain_set.dwData = 0;
728 hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
729 ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
730 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
731 ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
732 ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
733 dip_gain_set.dwData = 10000;
734 hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
735 ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
736 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
737 ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
738 ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
739 /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */
740 dip_gain_set.dwData = 10001;
741 hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph);
742 ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %08x\n", hr);
743 hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph);
744 ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
745 ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %i\n", dip_gain_get.dwData);
746
747 ref = IUnknown_Release(effect);
748 ok(ref == 0, "IDirectInputDevice_Release() reference count = %d\n", ref);
749 }
750 cnt1 = get_refcount((IUnknown*)pJoystick);
751 ok(cnt1 == cnt2, "Ref count is wrong %d != %d\n", cnt1, cnt2);
752 }
753 /* No force feedback support, CreateEffect is supposed to fail. Fairy Bloom Freesia
754 * calls CreateEffect without checking the DIDC_FORCEFEEDBACK. It expects the correct
755 * error return to determine if force feedback is unsupported. */
756 else
757 {
758 trace("No force feedback support\n");
759 ok(hr==DIERR_UNSUPPORTED, "IDirectInputDevice_CreateEffect() must fail with DIERR_UNSUPPORTED, got: %08x\n", hr);
760 ok(effect == NULL, "effect must be NULL, got %p\n", effect);
761 }
762
763 /* Before destroying the window, release joystick to revert to
764 * non-exclusive, background cooperative level. */
765 hr = IDirectInputDevice_Unacquire(pJoystick);
766 ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
767 hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd,
768 DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
769 ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
770 DestroyWindow (real_hWnd);
771 hr = IDirectInputDevice_Acquire(pJoystick);
772 ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
773
774 if (winetest_interactive) {
775 trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
776 count = 300;
777 } else
778 count = 1;
779
780 trace("\n");
781 oldstate[0]='\0';
782 for (i = 0; i < count; i++) {
783 hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js);
784 ok(hr==DI_OK,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
785 if (hr != DI_OK)
786 break;
787 sprintf(curstate, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
788 "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
789 "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
790 js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz,
791 js.rglSlider[0], js.rglSlider[1],
792 js.rgdwPOV[0], js.rgdwPOV[1], js.rgdwPOV[2], js.rgdwPOV[3],
793 js.rgbButtons[0]>>7, js.rgbButtons[1]>>7, js.rgbButtons[2]>>7,
794 js.rgbButtons[3]>>7, js.rgbButtons[4]>>7, js.rgbButtons[5]>>7,
795 js.rgbButtons[6]>>7, js.rgbButtons[7]>>7, js.rgbButtons[8]>>7,
796 js.rgbButtons[9]>>7, js.rgbButtons[10]>>7, js.rgbButtons[11]>>7);
797 if (strcmp(oldstate, curstate) != 0)
798 {
799 trace("%s\n", curstate);
800 strcpy(oldstate, curstate);
801 }
802 Sleep(100);
803 }
804 trace("\n");
805
806 hr = IDirectInputDevice_Unacquire(pJoystick);
807 ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
808
809 RELEASE:
810 ref = IDirectInputDevice_Release(pJoystick);
811 ok(ref==0,"IDirectInputDevice_Release() reference count = %d\n", ref);
812
813 DONE:
814 return DIENUM_CONTINUE;
815 }
816
817 static void joystick_tests(DWORD version)
818 {
819 HRESULT hr;
820 IDirectInputA *pDI;
821 ULONG ref;
822 HINSTANCE hInstance = GetModuleHandleW(NULL);
823
824 trace("-- Testing Direct Input Version 0x%04x --\n", version);
825 hr = DirectInputCreateA(hInstance, version, &pDI, NULL);
826 ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION, "DirectInputCreateA() failed: %08x\n", hr);
827 if (hr==DI_OK && pDI!=0) {
828 UserData data;
829 data.pDI = pDI;
830 data.version = version;
831 hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks,
832 &data, DIEDFL_ALLDEVICES);
833 ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %08x\n", hr);
834 ref = IDirectInput_Release(pDI);
835 ok(ref==0,"IDirectInput_Release() reference count = %d\n", ref);
836 } else if (hr==DIERR_OLDDIRECTINPUTVERSION)
837 trace(" Version Not Supported\n");
838 }
839
840 START_TEST(joystick)
841 {
842 CoInitialize(NULL);
843
844 joystick_tests(0x0700);
845 joystick_tests(0x0500);
846 joystick_tests(0x0300);
847
848 CoUninitialize();
849 }