2 * Copyright (c) 2011 Andrew Nguyen
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 0x0800
27 #include "wine/test.h"
31 static BOOL CALLBACK
dummy_callback(const DIDEVICEINSTANCEA
*instance
, void *context
)
33 ok(0, "Callback was invoked with parameters (%p, %p)\n", instance
, context
);
37 static void test_preinitialization(void)
44 } create_device_tests
[] =
46 {NULL
, FALSE
, E_POINTER
},
47 {NULL
, TRUE
, E_POINTER
},
48 {&GUID_Unknown
, FALSE
, E_POINTER
},
49 {&GUID_Unknown
, TRUE
, DIERR_NOTINITIALIZED
},
50 {&GUID_SysMouse
, FALSE
, E_POINTER
},
51 {&GUID_SysMouse
, TRUE
, DIERR_NOTINITIALIZED
},
57 LPDIENUMDEVICESCALLBACKA lpCallback
;
61 } enum_devices_tests
[] =
63 {0, NULL
, 0, DIERR_INVALIDPARAM
},
64 {0, NULL
, ~0u, DIERR_INVALIDPARAM
},
65 {0, dummy_callback
, 0, DIERR_NOTINITIALIZED
},
66 {0, dummy_callback
, ~0u, DIERR_INVALIDPARAM
},
67 {0xdeadbeef, NULL
, 0, DIERR_INVALIDPARAM
},
68 {0xdeadbeef, NULL
, ~0u, DIERR_INVALIDPARAM
},
69 {0xdeadbeef, dummy_callback
, 0, DIERR_INVALIDPARAM
},
70 {0xdeadbeef, dummy_callback
, ~0u, DIERR_INVALIDPARAM
},
76 IDirectInputDevice8A
*pDID
;
78 hr
= CoCreateInstance(&CLSID_DirectInput8
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectInput8A
, (void **)&pDI
);
81 skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
85 for (i
= 0; i
< sizeof(create_device_tests
)/sizeof(create_device_tests
[0]); i
++)
87 if (create_device_tests
[i
].pdev
) pDID
= (void *)0xdeadbeef;
88 hr
= IDirectInput8_CreateDevice(pDI
, create_device_tests
[i
].rguid
,
89 create_device_tests
[i
].pdev
? &pDID
: NULL
,
91 ok(hr
== create_device_tests
[i
].expected_hr
, "[%d] IDirectInput8_CreateDevice returned 0x%08x\n", i
, hr
);
92 if (create_device_tests
[i
].pdev
)
93 ok(pDID
== NULL
, "[%d] Output interface pointer is %p\n", i
, pDID
);
96 for (i
= 0; i
< sizeof(enum_devices_tests
)/sizeof(enum_devices_tests
[0]); i
++)
98 hr
= IDirectInput8_EnumDevices(pDI
, enum_devices_tests
[i
].dwDevType
,
99 enum_devices_tests
[i
].lpCallback
,
101 enum_devices_tests
[i
].dwFlags
);
102 if (enum_devices_tests
[i
].todo
)
105 ok(hr
== enum_devices_tests
[i
].expected_hr
, "[%d] IDirectInput8_EnumDevice returned 0x%08x\n", i
, hr
);
108 ok(hr
== enum_devices_tests
[i
].expected_hr
, "[%d] IDirectInput8_EnumDevice returned 0x%08x\n", i
, hr
);
111 hr
= IDirectInput8_GetDeviceStatus(pDI
, NULL
);
113 ok(hr
== E_POINTER
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
115 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_Unknown
);
116 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
118 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_SysMouse
);
119 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
121 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, 0);
122 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
124 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, ~0u);
125 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
127 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, 0);
128 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
130 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, ~0u);
131 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
133 IDirectInput8_Release(pDI
);
136 static void test_DirectInput8Create(void)
145 } invalid_param_list
[] =
147 {FALSE
, 0, &IID_IDirectInputA
, FALSE
, E_POINTER
},
148 {FALSE
, 0, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
149 {FALSE
, 0, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
150 {FALSE
, 0, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
151 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, FALSE
, E_POINTER
},
152 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
153 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
154 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
155 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
156 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
157 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
158 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
159 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
160 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
161 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
162 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
163 {TRUE
, 0, &IID_IDirectInputA
, FALSE
, E_POINTER
},
164 {TRUE
, 0, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
165 {TRUE
, 0, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
166 {TRUE
, 0, &IID_IDirectInput8A
, TRUE
, DIERR_NOTINITIALIZED
},
167 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, FALSE
, E_POINTER
},
168 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
169 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
170 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
171 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
172 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
173 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, TRUE
, DIERR_BETADIRECTINPUTVERSION
},
174 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
175 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
176 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
177 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, TRUE
, DIERR_OLDDIRECTINPUTVERSION
},
180 static REFIID no_interface_list
[] = {&IID_IDirectInputA
, &IID_IDirectInputW
,
181 &IID_IDirectInput2A
, &IID_IDirectInput2W
,
182 &IID_IDirectInput7A
, &IID_IDirectInput7W
,
183 &IID_IDirectInputDeviceA
, &IID_IDirectInputDeviceW
,
184 &IID_IDirectInputDevice2A
, &IID_IDirectInputDevice2W
,
185 &IID_IDirectInputDevice7A
, &IID_IDirectInputDevice7W
,
186 &IID_IDirectInputDevice8A
, &IID_IDirectInputDevice8W
,
187 &IID_IDirectInputEffect
};
189 static REFIID iid_list
[] = {&IID_IUnknown
, &IID_IDirectInput8A
, &IID_IDirectInput8W
};
195 for (i
= 0; i
< sizeof(invalid_param_list
)/sizeof(invalid_param_list
[0]); i
++)
197 if (invalid_param_list
[i
].ppdi
) pUnk
= (void *)0xdeadbeef;
198 hr
= DirectInput8Create(invalid_param_list
[i
].hinst
? hInstance
: NULL
,
199 invalid_param_list
[i
].dwVersion
,
200 invalid_param_list
[i
].riid
,
201 invalid_param_list
[i
].ppdi
? (void **)&pUnk
: NULL
,
203 ok(hr
== invalid_param_list
[i
].expected_hr
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
204 if (invalid_param_list
[i
].ppdi
)
205 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
208 for (i
= 0; i
< sizeof(no_interface_list
)/sizeof(no_interface_list
[0]); i
++)
210 pUnk
= (void *)0xdeadbeef;
211 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, no_interface_list
[i
], (void **)&pUnk
, NULL
);
212 ok(hr
== DIERR_NOINTERFACE
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
213 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
216 for (i
= 0; i
< sizeof(iid_list
)/sizeof(iid_list
[0]); i
++)
219 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, iid_list
[i
], (void **)&pUnk
, NULL
);
220 ok(hr
== DI_OK
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
221 ok(pUnk
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
223 IUnknown_Release(pUnk
);
227 static void test_QueryInterface(void)
229 static REFIID iid_list
[] = {&IID_IUnknown
, &IID_IDirectInput8A
, &IID_IDirectInput8W
, &IID_IDirectInputJoyConfig8
};
235 } no_interface_list
[] =
237 {&IID_IDirectInputA
, 1},
238 {&IID_IDirectInputW
, 1},
239 {&IID_IDirectInput2A
, 1},
240 {&IID_IDirectInput2W
, 1},
241 {&IID_IDirectInput7A
, 1},
242 {&IID_IDirectInput7W
, 1},
243 {&IID_IDirectInputDeviceA
},
244 {&IID_IDirectInputDeviceW
},
245 {&IID_IDirectInputDevice2A
},
246 {&IID_IDirectInputDevice2W
},
247 {&IID_IDirectInputDevice7A
},
248 {&IID_IDirectInputDevice7W
},
249 {&IID_IDirectInputDevice8A
},
250 {&IID_IDirectInputDevice8W
},
251 {&IID_IDirectInputEffect
},
259 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
262 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
266 hr
= IDirectInput8_QueryInterface(pDI
, NULL
, NULL
);
267 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
269 pUnk
= (void *)0xdeadbeef;
270 hr
= IDirectInput8_QueryInterface(pDI
, NULL
, (void **)&pUnk
);
271 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
272 ok(pUnk
== (void *)0xdeadbeef, "Output interface pointer is %p\n", pUnk
);
274 hr
= IDirectInput8_QueryInterface(pDI
, &IID_IUnknown
, NULL
);
275 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
277 for (i
= 0; i
< sizeof(iid_list
)/sizeof(iid_list
[0]); i
++)
280 hr
= IDirectInput8_QueryInterface(pDI
, iid_list
[i
], (void **)&pUnk
);
281 ok(hr
== S_OK
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
282 ok(pUnk
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
286 for (j
= 0; j
< sizeof(iid_list
)/sizeof(iid_list
[0]); j
++)
288 IUnknown
*pUnk1
= NULL
;
289 hr
= IDirectInput8_QueryInterface(pUnk
, iid_list
[j
], (void **)&pUnk1
);
290 ok(hr
== S_OK
, "[%d] IDirectInput8_QueryInterface(pUnk) returned 0x%08x\n", j
, hr
);
291 ok(pUnk1
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
292 if (pUnk1
) IUnknown_Release(pUnk1
);
294 IUnknown_Release(pUnk
);
298 for (i
= 0; i
< sizeof(no_interface_list
)/sizeof(no_interface_list
[0]); i
++)
300 pUnk
= (void *)0xdeadbeef;
301 hr
= IDirectInput8_QueryInterface(pDI
, no_interface_list
[i
].riid
, (void **)&pUnk
);
302 if (no_interface_list
[i
].test_todo
)
305 ok(hr
== E_NOINTERFACE
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
307 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
309 if (pUnk
) IUnknown_Release(pUnk
);
313 ok(hr
== E_NOINTERFACE
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
314 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
318 IDirectInput8_Release(pDI
);
321 static void test_CreateDevice(void)
325 IDirectInputDevice8A
*pDID
;
327 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
330 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
334 hr
= IDirectInput8_CreateDevice(pDI
, NULL
, NULL
, NULL
);
335 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
337 pDID
= (void *)0xdeadbeef;
338 hr
= IDirectInput8_CreateDevice(pDI
, NULL
, &pDID
, NULL
);
339 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
340 ok(pDID
== NULL
, "Output interface pointer is %p\n", pDID
);
342 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_Unknown
, NULL
, NULL
);
343 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
345 pDID
= (void *)0xdeadbeef;
346 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_Unknown
, &pDID
, NULL
);
347 ok(hr
== DIERR_DEVICENOTREG
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
348 ok(pDID
== NULL
, "Output interface pointer is %p\n", pDID
);
350 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_SysMouse
, NULL
, NULL
);
351 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
353 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_SysMouse
, &pDID
, NULL
);
354 ok(hr
== DI_OK
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
356 IDirectInputDevice_Release(pDID
);
357 IDirectInput8_Release(pDI
);
360 struct enum_devices_test
362 unsigned int device_count
;
366 static BOOL CALLBACK
enum_devices_callback(const DIDEVICEINSTANCEA
*instance
, void *context
)
368 struct enum_devices_test
*enum_test
= context
;
370 enum_test
->device_count
++;
371 return enum_test
->return_value
;
374 static void test_EnumDevices(void)
378 struct enum_devices_test enum_test
, enum_test_return
;
380 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
383 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
387 hr
= IDirectInput8_EnumDevices(pDI
, 0, NULL
, NULL
, 0);
388 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
390 hr
= IDirectInput8_EnumDevices(pDI
, 0, NULL
, NULL
, ~0u);
391 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
393 /* Test crashes on Wine. */
396 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, NULL
, ~0u);
397 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
400 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, NULL
, NULL
, 0);
401 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
403 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, NULL
, NULL
, ~0u);
404 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
406 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, enum_devices_callback
, NULL
, 0);
407 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
409 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, enum_devices_callback
, NULL
, ~0u);
410 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
412 enum_test
.device_count
= 0;
413 enum_test
.return_value
= DIENUM_CONTINUE
;
414 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test
, 0);
415 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
416 ok(enum_test
.device_count
!= 0, "Device count is %u\n", enum_test
.device_count
);
418 /* Enumeration only stops with an explicit DIENUM_STOP. */
419 enum_test_return
.device_count
= 0;
420 enum_test_return
.return_value
= 42;
421 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test_return
, 0);
422 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
423 ok(enum_test_return
.device_count
== enum_test
.device_count
,
424 "Device count is %u vs. %u\n", enum_test_return
.device_count
, enum_test
.device_count
);
426 enum_test
.device_count
= 0;
427 enum_test
.return_value
= DIENUM_STOP
;
428 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test
, 0);
429 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
430 ok(enum_test
.device_count
== 1, "Device count is %u\n", enum_test
.device_count
);
432 IDirectInput8_Release(pDI
);
435 struct enum_semantics_test
437 unsigned int device_count
;
440 LPDIACTIONFORMAT lpdiaf
;
441 const char* username
;
444 static DIACTION actionMapping
[]=
447 { 0, 0x01008A01 /* DIAXIS_DRIVINGR_STEER */, 0, { "Steer" } },
449 { 1, 0x01000C01 /* DIBUTTON_DRIVINGR_SHIFTUP */, 0, { "Upshift" } },
451 { 2, DIKEYBOARD_SPACE
, 0, { "Missile" } },
453 { 3, DIMOUSE_BUTTON0
, 0, { "Select" } },
455 { 4, DIMOUSE_YAXIS
, 0, { "Y Axis" } }
458 static BOOL CALLBACK
enum_semantics_callback(LPCDIDEVICEINSTANCE lpddi
, IDirectInputDevice8A
*lpdid
, DWORD dwFlags
, DWORD dwRemaining
, void *context
)
460 struct enum_semantics_test
*data
= context
;
462 if (context
== NULL
) return DIENUM_STOP
;
464 data
->device_count
++;
466 if (IsEqualGUID(&lpddi
->guidInstance
, &GUID_SysKeyboard
)) data
->keyboard
= TRUE
;
468 if (IsEqualGUID(&lpddi
->guidInstance
, &GUID_SysMouse
)) data
->mouse
= TRUE
;
470 return DIENUM_CONTINUE
;
473 static BOOL CALLBACK
set_action_map_callback(LPCDIDEVICEINSTANCE lpddi
, IDirectInputDevice8A
*lpdid
, DWORD dwFlags
, DWORD dwRemaining
, void *context
)
476 struct enum_semantics_test
*data
= context
;
478 /* Building and setting an action map */
479 /* It should not use any pre-stored mappings so we use DIDBAM_INITIALIZE */
480 hr
= IDirectInputDevice8_BuildActionMap(lpdid
, data
->lpdiaf
, NULL
, DIDBAM_INITIALIZE
);
481 ok (SUCCEEDED(hr
), "BuildActionMap failed hr=%08x\n", hr
);
483 hr
= IDirectInputDevice8_SetActionMap(lpdid
, data
->lpdiaf
, data
->username
, 0);
484 ok (SUCCEEDED(hr
), "SetActionMap failed hr=%08x\n", hr
);
486 return DIENUM_CONTINUE
;
489 static void test_EnumDevicesBySemantics(void)
493 DIACTIONFORMATA diaf
;
494 const GUID ACTION_MAPPING_GUID
= { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
495 struct enum_semantics_test data
= { 0, FALSE
, FALSE
, &diaf
, NULL
};
496 int device_total
= 0;
498 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
501 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
505 memset (&diaf
, 0, sizeof(diaf
));
506 diaf
.dwSize
= sizeof(diaf
);
507 diaf
.dwActionSize
= sizeof(DIACTION
);
508 diaf
.dwNumActions
= sizeof(actionMapping
) / sizeof(actionMapping
[0]);
509 diaf
.dwDataSize
= 4 * diaf
.dwNumActions
;
510 diaf
.rgoAction
= actionMapping
;
511 diaf
.guidActionMap
= ACTION_MAPPING_GUID
;
512 diaf
.dwGenre
= 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
513 diaf
.dwBufferSize
= 32;
515 /* Test enumerating all attached and installed devices */
516 data
.keyboard
= FALSE
;
518 data
.device_count
= 0;
519 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
520 ok (data
.device_count
> 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr
);
521 ok (data
.keyboard
, "EnumDevicesBySemantics should enumerate the keyboard\n");
522 ok (data
.mouse
, "EnumDevicesBySemantics should enumerate the mouse\n");
524 /* Enumerate Force feedback devices. We should get no mouse nor keyboard */
525 data
.keyboard
= FALSE
;
527 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_FORCEFEEDBACK
);
528 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
529 ok (!data
.keyboard
, "Keyboard should not be enumerated when asking for forcefeedback\n");
530 ok (!data
.mouse
, "Mouse should not be enumerated when asking for forcefeedback\n");
532 /* Enumerate available devices. That is devices not owned by any user.
533 Before setting the action map for all devices we still have them available. */
534 data
.device_count
= 0;
535 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_AVAILABLEDEVICES
);
536 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
537 ok (data
.device_count
> 0, "There should be devices available before action mapping available=%d\n", data
.device_count
);
539 /* Keep the device total */
540 device_total
= data
.device_count
;
542 /* This enumeration builds and sets the action map for all devices with a NULL username */
543 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, set_action_map_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
544 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed: hr=%08x\n", hr
);
546 /* After a successful action mapping we should have no devices available */
547 data
.device_count
= 0;
548 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_AVAILABLEDEVICES
);
549 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
550 todo_wine
ok (data
.device_count
== 0, "No device should be available after action mapping available=%d\n", data
.device_count
);
552 /* Now we'll give all the devices to a specific user */
553 data
.username
= "Sh4d0w M4g3";
554 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, set_action_map_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
555 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed: hr=%08x\n", hr
);
557 /* Testing with the default user, DIEDBSFL_THISUSER has no effect */
558 data
.device_count
= 0;
559 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
560 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
561 ok (data
.device_count
== device_total
, "THISUSER has no effect with NULL username owned=%d, expected=%d\n", data
.device_count
, device_total
);
563 /* Using an empty user string is the same as passing NULL, DIEDBSFL_THISUSER has no effect */
564 data
.device_count
= 0;
565 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
566 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
567 ok (data
.device_count
== device_total
, "THISUSER has no effect with \"\" as username owned=%d, expected=%d\n", data
.device_count
, device_total
);
569 /* Testing with a user with no ownership of the devices */
570 data
.device_count
= 0;
571 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "Ninja Brian", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
572 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
573 todo_wine
ok (data
.device_count
== 0, "This user should own no devices owned=%d\n", data
.device_count
);
575 /* Sh4d0w M4g3 has ownership of all devices */
576 data
.device_count
= 0;
577 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "Sh4d0w M4g3", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
578 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
579 ok (data
.device_count
== device_total
, "This user should own %d devices owned=%d\n", device_total
, data
.device_count
);
581 /* The call fails with a zeroed GUID */
582 memset(&diaf
.guidActionMap
, 0, sizeof(GUID
));
583 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, NULL
, 0);
584 todo_wine
ok(FAILED(hr
), "EnumDevicesBySemantics succeeded with invalid GUID hr=%08x\n", hr
);
586 IDirectInput8_Release(pDI
);
589 static void test_GetDeviceStatus(void)
594 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
597 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
601 hr
= IDirectInput8_GetDeviceStatus(pDI
, NULL
);
603 ok(hr
== E_POINTER
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
605 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_Unknown
);
607 ok(hr
== DIERR_DEVICENOTREG
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
609 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_SysMouse
);
610 ok(hr
== DI_OK
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
612 IDirectInput8_Release(pDI
);
615 static void test_RunControlPanel(void)
620 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
623 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
627 if (winetest_interactive
)
629 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, 0);
630 ok(hr
== S_OK
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
632 hr
= IDirectInput8_RunControlPanel(pDI
, GetDesktopWindow(), 0);
633 ok(hr
== S_OK
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
636 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, ~0u);
637 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
639 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, 0);
640 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
642 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, ~0u);
643 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
645 IDirectInput8_Release(pDI
);
648 static void test_Initialize(void)
653 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
656 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
660 hr
= IDirectInput8_Initialize(pDI
, NULL
, 0);
661 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
663 hr
= IDirectInput8_Initialize(pDI
, NULL
, DIRECTINPUT_VERSION
);
664 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
666 hr
= IDirectInput8_Initialize(pDI
, hInstance
, 0);
667 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
669 /* Invalid DirectInput versions less than DIRECTINPUT_VERSION yield DIERR_BETADIRECTINPUTVERSION. */
670 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
- 1);
671 ok(hr
== DIERR_BETADIRECTINPUTVERSION
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
673 /* Invalid DirectInput versions greater than DIRECTINPUT_VERSION yield DIERR_BETADIRECTINPUTVERSION. */
674 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
+ 1);
675 ok(hr
== DIERR_OLDDIRECTINPUTVERSION
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
677 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
);
678 ok(hr
== DI_OK
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
680 /* Parameters are still validated after successful initialization. */
681 hr
= IDirectInput8_Initialize(pDI
, hInstance
, 0);
682 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
684 IDirectInput8_Release(pDI
);
689 hInstance
= GetModuleHandleA(NULL
);
692 test_preinitialization();
693 test_DirectInput8Create();
694 test_QueryInterface();
697 test_EnumDevicesBySemantics();
698 test_GetDeviceStatus();
699 test_RunControlPanel();