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 todo_wine_if(enum_devices_tests
[i
].todo
)
103 ok(hr
== enum_devices_tests
[i
].expected_hr
, "[%d] IDirectInput8_EnumDevice returned 0x%08x\n", i
, hr
);
106 hr
= IDirectInput8_GetDeviceStatus(pDI
, NULL
);
107 ok(hr
== E_POINTER
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
109 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_Unknown
);
110 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
112 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_SysMouse
);
113 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
115 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, 0);
116 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
118 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, ~0u);
119 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
121 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, 0);
122 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
124 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, ~0u);
125 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
127 IDirectInput8_Release(pDI
);
130 static void test_DirectInput8Create(void)
139 } invalid_param_list
[] =
141 {FALSE
, 0, &IID_IDirectInputA
, FALSE
, E_POINTER
},
142 {FALSE
, 0, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
143 {FALSE
, 0, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
144 {FALSE
, 0, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
145 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, FALSE
, E_POINTER
},
146 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
147 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
148 {FALSE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
149 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
150 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
151 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
152 {FALSE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
153 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
154 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
155 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
156 {FALSE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, TRUE
, DIERR_INVALIDPARAM
},
157 {TRUE
, 0, &IID_IDirectInputA
, FALSE
, E_POINTER
},
158 {TRUE
, 0, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
159 {TRUE
, 0, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
160 {TRUE
, 0, &IID_IDirectInput8A
, TRUE
, DIERR_NOTINITIALIZED
},
161 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, FALSE
, E_POINTER
},
162 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
163 {TRUE
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
164 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
165 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
166 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
167 {TRUE
, DIRECTINPUT_VERSION
- 1, &IID_IDirectInput8A
, TRUE
, DIERR_BETADIRECTINPUTVERSION
},
168 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, FALSE
, E_POINTER
},
169 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInputA
, TRUE
, DIERR_NOINTERFACE
},
170 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, FALSE
, E_POINTER
},
171 {TRUE
, DIRECTINPUT_VERSION
+ 1, &IID_IDirectInput8A
, TRUE
, DIERR_OLDDIRECTINPUTVERSION
},
174 static REFIID no_interface_list
[] = {&IID_IDirectInputA
, &IID_IDirectInputW
,
175 &IID_IDirectInput2A
, &IID_IDirectInput2W
,
176 &IID_IDirectInput7A
, &IID_IDirectInput7W
,
177 &IID_IDirectInputDeviceA
, &IID_IDirectInputDeviceW
,
178 &IID_IDirectInputDevice2A
, &IID_IDirectInputDevice2W
,
179 &IID_IDirectInputDevice7A
, &IID_IDirectInputDevice7W
,
180 &IID_IDirectInputDevice8A
, &IID_IDirectInputDevice8W
,
181 &IID_IDirectInputEffect
};
183 static REFIID iid_list
[] = {&IID_IUnknown
, &IID_IDirectInput8A
, &IID_IDirectInput8W
};
189 for (i
= 0; i
< sizeof(invalid_param_list
)/sizeof(invalid_param_list
[0]); i
++)
191 if (invalid_param_list
[i
].ppdi
) pUnk
= (void *)0xdeadbeef;
192 hr
= DirectInput8Create(invalid_param_list
[i
].hinst
? hInstance
: NULL
,
193 invalid_param_list
[i
].dwVersion
,
194 invalid_param_list
[i
].riid
,
195 invalid_param_list
[i
].ppdi
? (void **)&pUnk
: NULL
,
197 ok(hr
== invalid_param_list
[i
].expected_hr
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
198 if (invalid_param_list
[i
].ppdi
)
199 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
202 for (i
= 0; i
< sizeof(no_interface_list
)/sizeof(no_interface_list
[0]); i
++)
204 pUnk
= (void *)0xdeadbeef;
205 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, no_interface_list
[i
], (void **)&pUnk
, NULL
);
206 ok(hr
== DIERR_NOINTERFACE
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
207 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
210 for (i
= 0; i
< sizeof(iid_list
)/sizeof(iid_list
[0]); i
++)
213 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, iid_list
[i
], (void **)&pUnk
, NULL
);
214 ok(hr
== DI_OK
, "[%d] DirectInput8Create returned 0x%08x\n", i
, hr
);
215 ok(pUnk
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
217 IUnknown_Release(pUnk
);
221 static void test_QueryInterface(void)
223 static REFIID iid_list
[] = {&IID_IUnknown
, &IID_IDirectInput8A
, &IID_IDirectInput8W
, &IID_IDirectInputJoyConfig8
};
229 } no_interface_list
[] =
231 {&IID_IDirectInputA
, 1},
232 {&IID_IDirectInputW
, 1},
233 {&IID_IDirectInput2A
, 1},
234 {&IID_IDirectInput2W
, 1},
235 {&IID_IDirectInput7A
, 1},
236 {&IID_IDirectInput7W
, 1},
237 {&IID_IDirectInputDeviceA
},
238 {&IID_IDirectInputDeviceW
},
239 {&IID_IDirectInputDevice2A
},
240 {&IID_IDirectInputDevice2W
},
241 {&IID_IDirectInputDevice7A
},
242 {&IID_IDirectInputDevice7W
},
243 {&IID_IDirectInputDevice8A
},
244 {&IID_IDirectInputDevice8W
},
245 {&IID_IDirectInputEffect
},
253 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
256 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
260 hr
= IDirectInput8_QueryInterface(pDI
, NULL
, NULL
);
261 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
263 pUnk
= (void *)0xdeadbeef;
264 hr
= IDirectInput8_QueryInterface(pDI
, NULL
, (void **)&pUnk
);
265 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
266 ok(pUnk
== (void *)0xdeadbeef, "Output interface pointer is %p\n", pUnk
);
268 hr
= IDirectInput8_QueryInterface(pDI
, &IID_IUnknown
, NULL
);
269 ok(hr
== E_POINTER
, "IDirectInput8_QueryInterface returned 0x%08x\n", hr
);
271 for (i
= 0; i
< sizeof(iid_list
)/sizeof(iid_list
[0]); i
++)
274 hr
= IDirectInput8_QueryInterface(pDI
, iid_list
[i
], (void **)&pUnk
);
275 ok(hr
== S_OK
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
276 ok(pUnk
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
280 for (j
= 0; j
< sizeof(iid_list
)/sizeof(iid_list
[0]); j
++)
282 IUnknown
*pUnk1
= NULL
;
283 hr
= IDirectInput8_QueryInterface(pUnk
, iid_list
[j
], (void **)&pUnk1
);
284 ok(hr
== S_OK
, "[%d] IDirectInput8_QueryInterface(pUnk) returned 0x%08x\n", j
, hr
);
285 ok(pUnk1
!= NULL
, "[%d] Output interface pointer is NULL\n", i
);
286 if (pUnk1
) IUnknown_Release(pUnk1
);
288 IUnknown_Release(pUnk
);
292 for (i
= 0; i
< sizeof(no_interface_list
)/sizeof(no_interface_list
[0]); i
++)
294 pUnk
= (void *)0xdeadbeef;
295 hr
= IDirectInput8_QueryInterface(pDI
, no_interface_list
[i
].riid
, (void **)&pUnk
);
296 if (no_interface_list
[i
].test_todo
)
299 ok(hr
== E_NOINTERFACE
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
301 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
303 if (pUnk
) IUnknown_Release(pUnk
);
307 ok(hr
== E_NOINTERFACE
, "[%d] IDirectInput8_QueryInterface returned 0x%08x\n", i
, hr
);
308 ok(pUnk
== NULL
, "[%d] Output interface pointer is %p\n", i
, pUnk
);
312 IDirectInput8_Release(pDI
);
315 static void test_CreateDevice(void)
319 IDirectInputDevice8A
*pDID
;
321 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
324 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
328 hr
= IDirectInput8_CreateDevice(pDI
, NULL
, NULL
, NULL
);
329 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
331 pDID
= (void *)0xdeadbeef;
332 hr
= IDirectInput8_CreateDevice(pDI
, NULL
, &pDID
, NULL
);
333 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
334 ok(pDID
== NULL
, "Output interface pointer is %p\n", pDID
);
336 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_Unknown
, NULL
, NULL
);
337 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
339 pDID
= (void *)0xdeadbeef;
340 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_Unknown
, &pDID
, NULL
);
341 ok(hr
== DIERR_DEVICENOTREG
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
342 ok(pDID
== NULL
, "Output interface pointer is %p\n", pDID
);
344 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_SysMouse
, NULL
, NULL
);
345 ok(hr
== E_POINTER
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
347 hr
= IDirectInput8_CreateDevice(pDI
, &GUID_SysMouse
, &pDID
, NULL
);
348 ok(hr
== DI_OK
, "IDirectInput8_CreateDevice returned 0x%08x\n", hr
);
350 IDirectInputDevice_Release(pDID
);
351 IDirectInput8_Release(pDI
);
354 struct enum_devices_test
356 unsigned int device_count
;
360 static BOOL CALLBACK
enum_devices_callback(const DIDEVICEINSTANCEA
*instance
, void *context
)
362 struct enum_devices_test
*enum_test
= context
;
364 trace("---- Device Information ----\n"
365 "Product Name : %s\n"
366 "Instance Name : %s\n"
368 "GUID Product : %s\n"
369 "GUID Instance : %s\n"
370 "HID Page : 0x%04x\n"
371 "HID Usage : 0x%04x\n",
372 instance
->tszProductName
,
373 instance
->tszInstanceName
,
375 wine_dbgstr_guid(&instance
->guidProduct
),
376 wine_dbgstr_guid(&instance
->guidInstance
),
377 instance
->wUsagePage
,
380 enum_test
->device_count
++;
381 return enum_test
->return_value
;
384 static void test_EnumDevices(void)
388 struct enum_devices_test enum_test
, enum_test_return
;
390 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
393 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
397 hr
= IDirectInput8_EnumDevices(pDI
, 0, NULL
, NULL
, 0);
398 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
400 hr
= IDirectInput8_EnumDevices(pDI
, 0, NULL
, NULL
, ~0u);
401 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
403 /* Test crashes on Wine. */
406 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, NULL
, ~0u);
407 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
410 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, NULL
, NULL
, 0);
411 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
413 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, NULL
, NULL
, ~0u);
414 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
416 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, enum_devices_callback
, NULL
, 0);
417 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
419 hr
= IDirectInput8_EnumDevices(pDI
, 0xdeadbeef, enum_devices_callback
, NULL
, ~0u);
420 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
422 enum_test
.device_count
= 0;
423 enum_test
.return_value
= DIENUM_CONTINUE
;
424 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test
, 0);
425 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
426 ok(enum_test
.device_count
!= 0, "Device count is %u\n", enum_test
.device_count
);
428 /* Enumeration only stops with an explicit DIENUM_STOP. */
429 enum_test_return
.device_count
= 0;
430 enum_test_return
.return_value
= 42;
431 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test_return
, 0);
432 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
433 ok(enum_test_return
.device_count
== enum_test
.device_count
,
434 "Device count is %u vs. %u\n", enum_test_return
.device_count
, enum_test
.device_count
);
436 enum_test
.device_count
= 0;
437 enum_test
.return_value
= DIENUM_STOP
;
438 hr
= IDirectInput8_EnumDevices(pDI
, 0, enum_devices_callback
, &enum_test
, 0);
439 ok(hr
== DI_OK
, "IDirectInput8_EnumDevices returned 0x%08x\n", hr
);
440 ok(enum_test
.device_count
== 1, "Device count is %u\n", enum_test
.device_count
);
442 IDirectInput8_Release(pDI
);
445 struct enum_semantics_test
447 unsigned int device_count
;
450 DIACTIONFORMATA
*lpdiaf
;
451 const char* username
;
454 static DIACTIONA actionMapping
[]=
457 { 0, 0x01008A01 /* DIAXIS_DRIVINGR_STEER */, 0, { "Steer.\0" } },
459 { 1, 0x01000C01 /* DIBUTTON_DRIVINGR_SHIFTUP */, 0, { "Upshift.\0" } },
461 { 2, DIKEYBOARD_SPACE
, 0, { "Missile.\0" } },
463 { 3, DIMOUSE_BUTTON0
, 0, { "Select\0" } },
465 { 4, DIMOUSE_YAXIS
, 0, { "Y Axis\0" } }
467 /* By placing the memory pointed to by lptszActionName right before memory with PAGE_NOACCESS
468 * one can find out that the regular ansi string termination is not respected by EnumDevicesBySemantics.
469 * Adding a double termination, making it a valid wide string termination, made the test succeed.
470 * Therefore it looks like ansi version of EnumDevicesBySemantics forwards the string to
471 * the wide variant without conversation. */
473 static BOOL CALLBACK
enum_semantics_callback(const DIDEVICEINSTANCEA
*lpddi
, IDirectInputDevice8A
*lpdid
, DWORD dwFlags
, DWORD dwRemaining
, void *context
)
475 struct enum_semantics_test
*data
= context
;
477 if (context
== NULL
) return DIENUM_STOP
;
479 data
->device_count
++;
481 if (IsEqualGUID(&lpddi
->guidInstance
, &GUID_SysKeyboard
)) data
->keyboard
= TRUE
;
483 if (IsEqualGUID(&lpddi
->guidInstance
, &GUID_SysMouse
)) data
->mouse
= TRUE
;
485 return DIENUM_CONTINUE
;
488 static BOOL CALLBACK
set_action_map_callback(const DIDEVICEINSTANCEA
*lpddi
, IDirectInputDevice8A
*lpdid
, DWORD dwFlags
, DWORD dwRemaining
, void *context
)
491 struct enum_semantics_test
*data
= context
;
493 /* Building and setting an action map */
494 /* It should not use any pre-stored mappings so we use DIDBAM_INITIALIZE */
495 hr
= IDirectInputDevice8_BuildActionMap(lpdid
, data
->lpdiaf
, NULL
, DIDBAM_INITIALIZE
);
496 ok (SUCCEEDED(hr
), "BuildActionMap failed hr=%08x\n", hr
);
498 hr
= IDirectInputDevice8_SetActionMap(lpdid
, data
->lpdiaf
, data
->username
, 0);
499 ok (SUCCEEDED(hr
), "SetActionMap failed hr=%08x\n", hr
);
501 return DIENUM_CONTINUE
;
504 static void test_EnumDevicesBySemantics(void)
508 DIACTIONFORMATA diaf
;
509 const GUID ACTION_MAPPING_GUID
= { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
510 struct enum_semantics_test data
= { 0, FALSE
, FALSE
, &diaf
, NULL
};
511 int device_total
= 0;
513 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
516 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
520 memset (&diaf
, 0, sizeof(diaf
));
521 diaf
.dwSize
= sizeof(diaf
);
522 diaf
.dwActionSize
= sizeof(DIACTIONA
);
523 diaf
.dwNumActions
= sizeof(actionMapping
) / sizeof(actionMapping
[0]);
524 diaf
.dwDataSize
= 4 * diaf
.dwNumActions
;
525 diaf
.rgoAction
= actionMapping
;
526 diaf
.guidActionMap
= ACTION_MAPPING_GUID
;
527 diaf
.dwGenre
= 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
528 diaf
.dwBufferSize
= 32;
530 /* Test enumerating all attached and installed devices */
531 data
.keyboard
= FALSE
;
533 data
.device_count
= 0;
534 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
535 ok (data
.device_count
> 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr
);
536 ok (data
.keyboard
, "EnumDevicesBySemantics should enumerate the keyboard\n");
537 ok (data
.mouse
, "EnumDevicesBySemantics should enumerate the mouse\n");
539 /* Enumerate Force feedback devices. We should get no mouse nor keyboard */
540 data
.keyboard
= FALSE
;
542 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_FORCEFEEDBACK
);
543 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
544 ok (!data
.keyboard
, "Keyboard should not be enumerated when asking for forcefeedback\n");
545 ok (!data
.mouse
, "Mouse should not be enumerated when asking for forcefeedback\n");
547 /* Enumerate available devices. That is devices not owned by any user.
548 Before setting the action map for all devices we still have them available. */
549 data
.device_count
= 0;
550 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_AVAILABLEDEVICES
);
551 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
552 ok (data
.device_count
> 0, "There should be devices available before action mapping available=%d\n", data
.device_count
);
554 /* Keep the device total */
555 device_total
= data
.device_count
;
557 /* This enumeration builds and sets the action map for all devices with a NULL username */
558 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, set_action_map_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
559 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed: hr=%08x\n", hr
);
561 /* After a successful action mapping we should have no devices available */
562 data
.device_count
= 0;
563 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_AVAILABLEDEVICES
);
564 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
565 todo_wine
ok (data
.device_count
== 0, "No device should be available after action mapping available=%d\n", data
.device_count
);
567 /* Now we'll give all the devices to a specific user */
568 data
.username
= "Sh4d0w M4g3";
569 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, set_action_map_callback
, &data
, DIEDBSFL_ATTACHEDONLY
);
570 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed: hr=%08x\n", hr
);
572 /* Testing with the default user, DIEDBSFL_THISUSER has no effect */
573 data
.device_count
= 0;
574 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
575 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
576 ok (data
.device_count
== device_total
, "THISUSER has no effect with NULL username owned=%d, expected=%d\n", data
.device_count
, device_total
);
578 /* Using an empty user string is the same as passing NULL, DIEDBSFL_THISUSER has no effect */
579 data
.device_count
= 0;
580 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
581 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
582 ok (data
.device_count
== device_total
, "THISUSER has no effect with \"\" as username owned=%d, expected=%d\n", data
.device_count
, device_total
);
584 /* Testing with a user with no ownership of the devices */
585 data
.device_count
= 0;
586 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "Ninja Brian", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
587 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
588 todo_wine
ok (data
.device_count
== 0, "This user should own no devices owned=%d\n", data
.device_count
);
590 /* Sh4d0w M4g3 has ownership of all devices */
591 data
.device_count
= 0;
592 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, "Sh4d0w M4g3", &diaf
, enum_semantics_callback
, &data
, DIEDBSFL_THISUSER
);
593 ok (SUCCEEDED(hr
), "EnumDevicesBySemantics failed hr=%08x\n", hr
);
594 ok (data
.device_count
== device_total
, "This user should own %d devices owned=%d\n", device_total
, data
.device_count
);
596 /* The call fails with a zeroed GUID */
597 memset(&diaf
.guidActionMap
, 0, sizeof(GUID
));
598 hr
= IDirectInput8_EnumDevicesBySemantics(pDI
, NULL
, &diaf
, enum_semantics_callback
, NULL
, 0);
599 todo_wine
ok(FAILED(hr
), "EnumDevicesBySemantics succeeded with invalid GUID hr=%08x\n", hr
);
601 IDirectInput8_Release(pDI
);
604 static void test_GetDeviceStatus(void)
609 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
612 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
616 hr
= IDirectInput8_GetDeviceStatus(pDI
, NULL
);
617 ok(hr
== E_POINTER
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
619 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_Unknown
);
621 ok(hr
== DIERR_DEVICENOTREG
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
623 hr
= IDirectInput8_GetDeviceStatus(pDI
, &GUID_SysMouse
);
624 ok(hr
== DI_OK
, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr
);
626 IDirectInput8_Release(pDI
);
629 static void test_RunControlPanel(void)
634 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
637 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
641 if (winetest_interactive
)
643 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, 0);
644 ok(hr
== S_OK
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
646 hr
= IDirectInput8_RunControlPanel(pDI
, GetDesktopWindow(), 0);
647 ok(hr
== S_OK
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
650 hr
= IDirectInput8_RunControlPanel(pDI
, NULL
, ~0u);
651 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
653 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, 0);
654 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
656 hr
= IDirectInput8_RunControlPanel(pDI
, (HWND
)0xdeadbeef, ~0u);
657 ok(hr
== E_HANDLE
, "IDirectInput8_RunControlPanel returned 0x%08x\n", hr
);
659 IDirectInput8_Release(pDI
);
662 static void test_Initialize(void)
667 hr
= DirectInput8Create(hInstance
, DIRECTINPUT_VERSION
, &IID_IDirectInput8A
, (void **)&pDI
, NULL
);
670 win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr
);
674 hr
= IDirectInput8_Initialize(pDI
, NULL
, 0);
675 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
677 hr
= IDirectInput8_Initialize(pDI
, NULL
, DIRECTINPUT_VERSION
);
678 ok(hr
== DIERR_INVALIDPARAM
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
680 hr
= IDirectInput8_Initialize(pDI
, hInstance
, 0);
681 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
683 /* Invalid DirectInput versions less than DIRECTINPUT_VERSION yield DIERR_BETADIRECTINPUTVERSION. */
684 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
- 1);
685 ok(hr
== DIERR_BETADIRECTINPUTVERSION
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
687 /* Invalid DirectInput versions greater than DIRECTINPUT_VERSION yield DIERR_BETADIRECTINPUTVERSION. */
688 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
+ 1);
689 ok(hr
== DIERR_OLDDIRECTINPUTVERSION
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
691 hr
= IDirectInput8_Initialize(pDI
, hInstance
, DIRECTINPUT_VERSION
);
692 ok(hr
== DI_OK
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
694 /* Parameters are still validated after successful initialization. */
695 hr
= IDirectInput8_Initialize(pDI
, hInstance
, 0);
696 ok(hr
== DIERR_NOTINITIALIZED
, "IDirectInput8_Initialize returned 0x%08x\n", hr
);
698 IDirectInput8_Release(pDI
);
703 hInstance
= GetModuleHandleA(NULL
);
706 test_preinitialization();
707 test_DirectInput8Create();
708 test_QueryInterface();
711 test_EnumDevicesBySemantics();
712 test_GetDeviceStatus();
713 test_RunControlPanel();