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
);
112 ok(hr
== E_POINTER
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
114 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_Unknown
);
115 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
117 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_SysMouse
);
118 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
120 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, 0);
121 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
123 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, ~0u);
124 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
126 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, 0);
127 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
129 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, ~0u);
130 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
132 IDirectInput8_Release(pDI
);
135 static void test_DirectInput8Create(void)
144 } invalid_param_list
[] =
146 {FALSE
, 0, &IID_IDirectInputA
, FALSE
, E_POINTER
},
147 {FALSE
, 0, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
148 {FALSE
, 0, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
149 {FALSE
, 0, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
150 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, FALSE
, E_POINTER
},
151 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
152 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
153 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
154 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
155 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
156 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
157 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
158 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
159 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
160 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
161 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
162 {TRUE
, 0, &IID_IDirectInputA
, FALSE
, E_POINTER
},
163 {TRUE
, 0, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
164 {TRUE
, 0, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
165 {TRUE
, 0, &IID_IDirectInput8A
, TRUE
, DIERR_NOTINITIALIZED
},
166 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, FALSE
, E_POINTER
},
167 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
168 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
169 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
170 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
171 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
172 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, TRUE
, DIERR_BETADIRECTINPUTVERSION
},
173 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
174 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
175 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
176 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, TRUE
, DIERR_OLDDIRECTINPUTVERSION
},
179 static REFIID no_interface_list
[] = {&IID_IDirectInputA
, &IID_IDirectInputW
,
180 &IID_IDirectInput2A
, &IID_IDirectInput2W
,
181 &IID_IDirectInput7A
, &IID_IDirectInput7W
,
182 &IID_IDirectInputDeviceA
, &IID_IDirectInputDeviceW
,
183 &IID_IDirectInputDevice2A
, &IID_IDirectInputDevice2W
,
184 &IID_IDirectInputDevice7A
, &IID_IDirectInputDevice7W
,
185 &IID_IDirectInputDevice8A
, &IID_IDirectInputDevice8W
,
186 &IID_IDirectInputEffect
};
188 static REFIID iid_list
[] = {&IID_IUnknown
, &IID_IDirectInput8A
, &IID_IDirectInput8W
};
194 for (i
= 0; i
< sizeof(invalid_param_list
)/sizeof(invalid_param_list
[0]); i
++)
196 if (invalid_param_list
[i
].ppdi
) pUnk
= (void *)0xdeadbeef;
197 hr
= DirectInput8Create(invalid_param_list
[i
].hinst
? hInstance
: NULL
,
198 invalid_param_list
[i
].dwVersion
,
199 invalid_param_list
[i
].riid
,
200 invalid_param_list
[i
].ppdi
? (void **)&pUnk
: NULL
,
202 ok(hr
== invalid_param_list
[i
].expected_hr
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
203 if (invalid_param_list
[i
].ppdi
)
204 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
207 for (i
= 0; i
< sizeof(no_interface_list
)/sizeof(no_interface_list
[0]); i
++)
209 pUnk
= (void *)0xdeadbeef;
210 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, no_interface_list
[i
], (void **)&pUnk
, NULL
);
211 ok(hr
== DIERR_NOINTERFACE
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
212 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
215 for (i
= 0; i
< sizeof(iid_list
)/sizeof(iid_list
[0]); i
++)
218 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, iid_list
[i
], (void **)&pUnk
, NULL
);
219 ok(hr
== DI_OK
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
220 ok(pUnk
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
222 IUnknown_Release(pUnk
);
226 static void test_QueryInterface(void)
228 static REFIID iid_list
[] = {&IID_IUnknown
, &IID_IDirectInput8A
, &IID_IDirectInput8W
, &IID_IDirectInputJoyConfig8
};
234 } no_interface_list
[] =
236 {&IID_IDirectInputA
, 1},
237 {&IID_IDirectInputW
, 1},
238 {&IID_IDirectInput2A
, 1},
239 {&IID_IDirectInput2W
, 1},
240 {&IID_IDirectInput7A
, 1},
241 {&IID_IDirectInput7W
, 1},
242 {&IID_IDirectInputDeviceA
},
243 {&IID_IDirectInputDeviceW
},
244 {&IID_IDirectInputDevice2A
},
245 {&IID_IDirectInputDevice2W
},
246 {&IID_IDirectInputDevice7A
},
247 {&IID_IDirectInputDevice7W
},
248 {&IID_IDirectInputDevice8A
},
249 {&IID_IDirectInputDevice8W
},
250 {&IID_IDirectInputEffect
},
258 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
261 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
265 hr
= IDirectInput8_QueryInterface(pDI
, NULL
, NULL
);
266 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
268 pUnk
= (void *)0xdeadbeef;
269 hr
= IDirectInput8_QueryInterface(pDI
, NULL
, (void **)&pUnk
);
270 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
271 ok(pUnk
== (void *)0xdeadbeef, "Output interface pointer is %p\n", pUnk
);
273 hr
= IDirectInput8_QueryInterface(pDI
, &IID_IUnknown
, NULL
);
274 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
276 for (i
= 0; i
< sizeof(iid_list
)/sizeof(iid_list
[0]); i
++)
279 hr
= IDirectInput8_QueryInterface(pDI
, iid_list
[i
], (void **)&pUnk
);
280 ok(hr
== S_OK
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
281 ok(pUnk
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
285 for (j
= 0; j
< sizeof(iid_list
)/sizeof(iid_list
[0]); j
++)
287 IUnknown
*pUnk1
= NULL
;
288 hr
= IDirectInput8_QueryInterface(pUnk
, iid_list
[j
], (void **)&pUnk1
);
289 ok(hr
== S_OK
, "[%d] IDirectInput8_QueryInterface(pUnk) returned 0x%08x\n", j
, hr
);
290 ok(pUnk1
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
291 if (pUnk1
) IUnknown_Release(pUnk1
);
293 IUnknown_Release(pUnk
);
297 for (i
= 0; i
< sizeof(no_interface_list
)/sizeof(no_interface_list
[0]); i
++)
299 pUnk
= (void *)0xdeadbeef;
300 hr
= IDirectInput8_QueryInterface(pDI
, no_interface_list
[i
].riid
, (void **)&pUnk
);
301 if (no_interface_list
[i
].test_todo
)
304 ok(hr
== E_NOINTERFACE
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
306 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
308 if (pUnk
) IUnknown_Release(pUnk
);
312 ok(hr
== E_NOINTERFACE
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
313 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
317 IDirectInput8_Release(pDI
);
320 static void test_CreateDevice(void)
324 IDirectInputDevice8A
*pDID
;
326 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
329 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
333 hr
= IDirectInput8_CreateDevice(pDI
, NULL
, NULL
, NULL
);
334 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
336 pDID
= (void *)0xdeadbeef;
337 hr
= IDirectInput8_CreateDevice(pDI
, NULL
, &pDID
, NULL
);
338 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
339 ok(pDID
== NULL
, "Output interface pointer is %p\n", pDID
);
341 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_Unknown
, NULL
, NULL
);
342 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
344 pDID
= (void *)0xdeadbeef;
345 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_Unknown
, &pDID
, NULL
);
346 ok(hr
== DIERR_DEVICENOTREG
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
347 ok(pDID
== NULL
, "Output interface pointer is %p\n", pDID
);
349 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_SysMouse
, NULL
, NULL
);
350 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
352 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_SysMouse
, &pDID
, NULL
);
353 ok(hr
== DI_OK
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
355 IDirectInputDevice_Release(pDID
);
356 IDirectInput8_Release(pDI
);
359 struct enum_devices_test
361 unsigned int device_count
;
365 static BOOL CALLBACK
enum_devices_callback(const DIDEVICEINSTANCEA
*instance
, void *context
)
367 struct enum_devices_test
*enum_test
= context
;
369 enum_test
->device_count
++;
370 return enum_test
->return_value
;
373 static void test_EnumDevices(void)
377 struct enum_devices_test enum_test
, enum_test_return
;
379 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
382 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
386 hr
= IDirectInput8_EnumDevices(pDI
, 0, NULL
, NULL
, 0);
387 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
389 hr
= IDirectInput8_EnumDevices(pDI
, 0, NULL
, NULL
, ~0u);
390 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
392 /* Test crashes on Wine. */
395 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, NULL
, ~0u);
396 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
399 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, NULL
, NULL
, 0);
400 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
402 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, NULL
, NULL
, ~0u);
403 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
405 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, enum_devices_callback
, NULL
, 0);
406 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
408 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, enum_devices_callback
, NULL
, ~0u);
409 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
411 enum_test
.device_count
= 0;
412 enum_test
.return_value
= DIENUM_CONTINUE
;
413 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test
, 0);
414 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
415 ok(enum_test
.device_count
!= 0, "Device count is %u\n", enum_test
.device_count
);
417 /* Enumeration only stops with an explicit DIENUM_STOP. */
418 enum_test_return
.device_count
= 0;
419 enum_test_return
.return_value
= 42;
420 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test_return
, 0);
421 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
422 ok(enum_test_return
.device_count
== enum_test
.device_count
,
423 "Device count is %u vs. %u\n", enum_test_return
.device_count
, enum_test
.device_count
);
425 enum_test
.device_count
= 0;
426 enum_test
.return_value
= DIENUM_STOP
;
427 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test
, 0);
428 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
429 ok(enum_test
.device_count
== 1, "Device count is %u\n", enum_test
.device_count
);
431 IDirectInput8_Release(pDI
);
434 struct enum_semantics_test
436 unsigned int device_count
;
439 DIACTIONFORMATA
*lpdiaf
;
440 const char* username
;
443 static DIACTIONA actionMapping
[]=
446 { 0, 0x01008A01 /* DIAXIS_DRIVINGR_STEER */, 0, { "Steer" } },
448 { 1, 0x01000C01 /* DIBUTTON_DRIVINGR_SHIFTUP */, 0, { "Upshift" } },
450 { 2, DIKEYBOARD_SPACE
, 0, { "Missile" } },
452 { 3, DIMOUSE_BUTTON0
, 0, { "Select" } },
454 { 4, DIMOUSE_YAXIS
, 0, { "Y Axis" } }
457 static BOOL CALLBACK
enum_semantics_callback(const DIDEVICEINSTANCEA
*lpddi
, IDirectInputDevice8A
*lpdid
, DWORD dwFlags
, DWORD dwRemaining
, void *context
)
459 struct enum_semantics_test
*data
= context
;
461 if (context
== NULL
) return DIENUM_STOP
;
463 data
->device_count
++;
465 if (IsEqualGUID(&lpddi
->guidInstance
, &GUID_SysKeyboard
)) data
->keyboard
= TRUE
;
467 if (IsEqualGUID(&lpddi
->guidInstance
, &GUID_SysMouse
)) data
->mouse
= TRUE
;
469 return DIENUM_CONTINUE
;
472 static BOOL CALLBACK
set_action_map_callback(const DIDEVICEINSTANCEA
*lpddi
, IDirectInputDevice8A
*lpdid
, DWORD dwFlags
, DWORD dwRemaining
, void *context
)
475 struct enum_semantics_test
*data
= context
;
477 /* Building and setting an action map */
478 /* It should not use any pre-stored mappings so we use DIDBAM_INITIALIZE */
479 hr
= IDirectInputDevice8_BuildActionMap(lpdid
, data
->lpdiaf
, NULL
, DIDBAM_INITIALIZE
);
480 ok (SUCCEEDED(hr
), "BuildActionMap failed hr=%08x\n", hr
);
482 hr
= IDirectInputDevice8_SetActionMap(lpdid
, data
->lpdiaf
, data
->username
, 0);
483 ok (SUCCEEDED(hr
), "SetActionMap failed hr=%08x\n", hr
);
485 return DIENUM_CONTINUE
;
488 static void test_EnumDevicesBySemantics(void)
492 DIACTIONFORMATA diaf
;
493 const GUID ACTION_MAPPING_GUID
= { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
494 struct enum_semantics_test data
= { 0, FALSE
, FALSE
, &diaf
, NULL
};
495 int device_total
= 0;
497 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
500 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
504 memset (&diaf
, 0, sizeof(diaf
));
505 diaf
.dwSize
= sizeof(diaf
);
506 diaf
.dwActionSize
= sizeof(DIACTIONA
);
507 diaf
.dwNumActions
= sizeof(actionMapping
) / sizeof(actionMapping
[0]);
508 diaf
.dwDataSize
= 4 * diaf
.dwNumActions
;
509 diaf
.rgoAction
= actionMapping
;
510 diaf
.guidActionMap
= ACTION_MAPPING_GUID
;
511 diaf
.dwGenre
= 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
512 diaf
.dwBufferSize
= 32;
514 /* Test enumerating all attached and installed devices */
515 data
.keyboard
= FALSE
;
517 data
.device_count
= 0;
518 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
519 ok (data
.device_count
> 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr
);
520 ok (data
.keyboard
, "EnumDevicesBySemantics should enumerate the keyboard\n");
521 ok (data
.mouse
, "EnumDevicesBySemantics should enumerate the mouse\n");
523 /* Enumerate Force feedback devices. We should get no mouse nor keyboard */
524 data
.keyboard
= FALSE
;
526 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_FORCEFEEDBACK
);
527 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
528 ok (!data
.keyboard
, "Keyboard should not be enumerated when asking for forcefeedback\n");
529 ok (!data
.mouse
, "Mouse should not be enumerated when asking for forcefeedback\n");
531 /* Enumerate available devices. That is devices not owned by any user.
532 Before setting the action map for all devices we still have them available. */
533 data
.device_count
= 0;
534 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_AVAILABLEDEVICES
);
535 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
536 ok (data
.device_count
> 0, "There should be devices available before action mapping available=%d\n", data
.device_count
);
538 /* Keep the device total */
539 device_total
= data
.device_count
;
541 /* This enumeration builds and sets the action map for all devices with a NULL username */
542 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, set_action_map_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
543 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed: hr=%08x\n", hr
);
545 /* After a successful action mapping we should have no devices available */
546 data
.device_count
= 0;
547 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_AVAILABLEDEVICES
);
548 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
549 todo_wine
ok (data
.device_count
== 0, "No device should be available after action mapping available=%d\n", data
.device_count
);
551 /* Now we'll give all the devices to a specific user */
552 data
.username
= "Sh4d0w M4g3";
553 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, set_action_map_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
554 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed: hr=%08x\n", hr
);
556 /* Testing with the default user, DIEDBSFL_THISUSER has no effect */
557 data
.device_count
= 0;
558 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
559 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
560 ok (data
.device_count
== device_total
, "THISUSER has no effect with NULL username owned=%d, expected=%d\n", data
.device_count
, device_total
);
562 /* Using an empty user string is the same as passing NULL, DIEDBSFL_THISUSER has no effect */
563 data
.device_count
= 0;
564 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
565 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
566 ok (data
.device_count
== device_total
, "THISUSER has no effect with \"\" as username owned=%d, expected=%d\n", data
.device_count
, device_total
);
568 /* Testing with a user with no ownership of the devices */
569 data
.device_count
= 0;
570 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "Ninja Brian", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
571 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
572 todo_wine
ok (data
.device_count
== 0, "This user should own no devices owned=%d\n", data
.device_count
);
574 /* Sh4d0w M4g3 has ownership of all devices */
575 data
.device_count
= 0;
576 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "Sh4d0w M4g3", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
577 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
578 ok (data
.device_count
== device_total
, "This user should own %d devices owned=%d\n", device_total
, data
.device_count
);
580 /* The call fails with a zeroed GUID */
581 memset(&diaf
.guidActionMap
, 0, sizeof(GUID
));
582 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, NULL
, 0);
583 todo_wine
ok(FAILED(hr
), "EnumDevicesBySemantics succeeded with invalid GUID hr=%08x\n", hr
);
585 IDirectInput8_Release(pDI
);
588 static void test_GetDeviceStatus(void)
593 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
596 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
600 hr
= IDirectInput8_GetDeviceStatus(pDI
, NULL
);
601 ok(hr
== E_POINTER
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
603 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_Unknown
);
605 ok(hr
== DIERR_DEVICENOTREG
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
607 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_SysMouse
);
608 ok(hr
== DI_OK
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
610 IDirectInput8_Release(pDI
);
613 static void test_RunControlPanel(void)
618 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
621 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
625 if (winetest_interactive
)
627 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, 0);
628 ok(hr
== S_OK
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
630 hr
= IDirectInput8_RunControlPanel(pDI
, GetDesktopWindow(), 0);
631 ok(hr
== S_OK
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
634 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, ~0u);
635 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
637 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, 0);
638 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
640 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, ~0u);
641 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
643 IDirectInput8_Release(pDI
);
646 static void test_Initialize(void)
651 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
654 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
658 hr
= IDirectInput8_Initialize(pDI
, NULL
, 0);
659 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
661 hr
= IDirectInput8_Initialize(pDI
, NULL
, DIRECTINPUT_VERSION
);
662 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
664 hr
= IDirectInput8_Initialize(pDI
, hInstance
, 0);
665 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
667 /* Invalid DirectInput versions less than DIRECTINPUT_VERSION yield DIERR_BETADIRECTINPUTVERSION. */
668 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
- 1);
669 ok(hr
== DIERR_BETADIRECTINPUTVERSION
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
671 /* Invalid DirectInput versions greater than DIRECTINPUT_VERSION yield DIERR_BETADIRECTINPUTVERSION. */
672 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
+ 1);
673 ok(hr
== DIERR_OLDDIRECTINPUTVERSION
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
675 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
);
676 ok(hr
== DI_OK
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
678 /* Parameters are still validated after successful initialization. */
679 hr
= IDirectInput8_Initialize(pDI
, hInstance
, 0);
680 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
682 IDirectInput8_Release(pDI
);
687 hInstance
= GetModuleHandleA(NULL
);
690 test_preinitialization();
691 test_DirectInput8Create();
692 test_QueryInterface();
695 test_EnumDevicesBySemantics();
696 test_GetDeviceStatus();
697 test_RunControlPanel();