diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c index 3d35632da30..e86e0d82be9 100644 --- a/dlls/dinput8/tests/device.c +++ b/dlls/dinput8/tests/device.c @@ -187,6 +187,28 @@ static BOOL CALLBACK enumeration_callback( return DIENUM_CONTINUE; } +/* A simpler callback function used to count and check + the enumeration of devices. +*/ +static BOOL CALLBACK counting_callback( + LPCDIDEVICEINSTANCE lpddi, + LPDIRECTINPUTDEVICE8 lpdid, + DWORD dwFlags, + DWORD dwRemaining, + LPVOID pvRef) +{ + struct enum_data *data = pvRef; + if (!data) return DIENUM_CONTINUE; + + data->ndevices++; + if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard)) + data->keyboard = lpdid; + + if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse)) + data->mouse = lpdid; + + return DIENUM_CONTINUE; +} static void test_action_mapping(void) { @@ -194,7 +216,8 @@ static void test_action_mapping(void) HINSTANCE hinst = GetModuleHandle(NULL); LPDIRECTINPUT8 pDI = NULL; DIACTIONFORMAT af; - struct enum_data data = {pDI, &af, NULL, NULL, 0}; + struct enum_data data = {pDI, &af, NULL, NULL, 0}; + struct enum_data count = {pDI, &af, NULL, NULL, 0}; hr = CoCreateInstance(&CLSID_DirectInput8, 0, 1, &IID_IDirectInput8A, (LPVOID*)&pDI); if (hr == DIERR_OLDDIRECTINPUTVERSION || @@ -226,12 +249,42 @@ static void test_action_mapping(void) af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */ af.dwBufferSize = 32; - hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, 0); - ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr); - ok (data.ndevices > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr); - ok (data.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n"); - ok (data.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n"); + /* Test enumerating all attached and installed devices */ + count.keyboard = NULL; + count.mouse = NULL; + count.ndevices = 0; + hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_ATTACHEDONLY); + ok (count.ndevices > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr); + ok (count.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n"); + ok (count.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n"); + /* Enumerate Force feedback devices. We should get no mouse nor keyboard */ + count.keyboard = NULL; + count.mouse = NULL; + hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_FORCEFEEDBACK); + ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr); + todo_wine ok (count.keyboard == NULL, "Keyboard should not be enumerated when asking for forcefeedback\n"); + todo_wine ok (count.mouse == NULL, "Mouse should not be enumerated when asking for forcefeedback\n"); + + /* Enumerate available devices. That is devices with not owned by any user. + Before setting the action map for all devices we still have them available. + */ + count.ndevices = 0; + hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_AVAILABLEDEVICES); + ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr); + ok (count.ndevices > 0, "There should be devices available before action mapping available=%d\n", count.ndevices); + + /* This enumeration builds and sets the action map for all devices */ + hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY); + ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr); + + /* After a succesfull action mapping we should have no devices available */ + count.ndevices = 0; + hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_AVAILABLEDEVICES); + ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr); + todo_wine ok (count.ndevices == 0, "No device should be available after action mapping available=%d\n", count.ndevices); + + /* Use the devices we collect for some tests */ if (data.keyboard != NULL) { /* Test keyboard BuildActionMap */