On Windows dinput sometimes ignores injected input events, so let's make sure that the event was registered by checking buffered data for the device.
Signed-off-by: Arkadiusz Hiler ahiler@codeweavers.com ---
This series supersedes 210326, 210148, 210147 and 210146.
In this revision I use the _DX3 variant of structure for old dinput tests. Thanks RĂ©mi!
dlls/dinput/tests/device.c | 72 ++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 19 deletions(-)
diff --git a/dlls/dinput/tests/device.c b/dlls/dinput/tests/device.c index 6307957b6e2..b662bc43b27 100644 --- a/dlls/dinput/tests/device.c +++ b/dlls/dinput/tests/device.c @@ -348,6 +348,9 @@ void overlapped_format_tests(IDirectInputA *pDI, HWND hwnd) HRESULT hr; struct overlapped_state state; IDirectInputDeviceA *keyboard = NULL; + DIDEVICEOBJECTDATA_DX3 buffer[10]; + DIPROPDWORD dp; + DWORD cnt;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &keyboard, NULL); ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr); @@ -355,6 +358,15 @@ void overlapped_format_tests(IDirectInputA *pDI, HWND hwnd) /* test overlapped slider - default value 0 */ hr = IDirectInputDevice_SetDataFormat(keyboard, &overlapped_slider_format); ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr); + + dp.diph.dwSize = sizeof(DIPROPDWORD); + dp.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dp.diph.dwHow = DIPH_DEVICE; + dp.diph.dwObj = 0; + dp.dwData = ARRAY_SIZE(buffer); + hr = IDirectInputDevice_SetProperty(keyboard, DIPROP_BUFFERSIZE, &dp.diph); + ok(SUCCEEDED(hr), "IDirectInputDevice_SetProperty() failed: %08x\n", hr); + hr = IDirectInputDevice_Acquire(keyboard); ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
@@ -365,23 +377,34 @@ void overlapped_format_tests(IDirectInputA *pDI, HWND hwnd) keybd_event(0, DIK_D, KEYEVENTF_SCANCODE, 0); pump_messages();
- memset(&state, 0xFF, sizeof(state)); - hr = IDirectInputDevice_GetDeviceState(keyboard, sizeof(state), &state); - ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr); + cnt = ARRAY_SIZE(buffer); + hr = IDirectInputDevice_GetDeviceData(keyboard, sizeof(buffer[0]), (DIDEVICEOBJECTDATA*)buffer, &cnt, 0); + ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceData() failed: %08x\n", hr);
- ok(state.keys[0] == 0x00, "key A should be still up\n"); - ok(state.keys[1] == 0x00, "key S should be still up\n"); - ok(state.keys[2] == 0x80, "keydown for D did not register\n"); - ok(state.keys[3] == 0x00, "key F should be still up\n"); - ok(state.extra_element == 0, "State struct was not memset to zero\n"); + if (cnt != 1) + { + win_skip("We're not able to inject input into Windows dinput with events\n"); + } + else + { + memset(&state, 0xFF, sizeof(state)); + hr = IDirectInputDevice_GetDeviceState(keyboard, sizeof(state), &state); + ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
- /* release D */ - keybd_event(0, DIK_D, KEYEVENTF_SCANCODE|KEYEVENTF_KEYUP, 0); - pump_messages(); + ok(state.keys[0] == 0x00, "key A should be still up\n"); + ok(state.keys[1] == 0x00, "key S should be still up\n"); + ok(state.keys[2] == 0x80, "keydown for D did not register\n"); + ok(state.keys[3] == 0x00, "key F should be still up\n"); + ok(state.extra_element == 0, "State struct was not memset to zero\n"); + }
hr = IDirectInputDevice_Unacquire(keyboard); ok(SUCCEEDED(hr), "IDirectInputDevice_Unacquire() failed: %08x\n", hr);
+ /* release D */ + keybd_event(0, DIK_D, KEYEVENTF_SCANCODE|KEYEVENTF_KEYUP, 0); + pump_messages(); + /* test overlapped pov - default value - 0xFFFFFFFF */ hr = IDirectInputDevice_SetDataFormat(keyboard, &overlapped_pov_format); ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr); @@ -395,15 +418,26 @@ void overlapped_format_tests(IDirectInputA *pDI, HWND hwnd) keybd_event(0, DIK_D, KEYEVENTF_SCANCODE, 0); pump_messages();
- memset(&state, 0xFF, sizeof(state)); - hr = IDirectInputDevice_GetDeviceState(keyboard, sizeof(state), &state); - ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr); + cnt = ARRAY_SIZE(buffer); + hr = IDirectInputDevice_GetDeviceData(keyboard, sizeof(buffer[0]), (DIDEVICEOBJECTDATA*)buffer, &cnt, 0); + ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceData() failed: %08x\n", hr);
- ok(state.keys[0] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); - ok(state.keys[1] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); - ok(state.keys[2] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); - ok(state.keys[3] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); - ok(state.extra_element == 0, "State struct was not memset to zero\n"); + if (cnt != 1) + { + win_skip("We're not able to inject input into Windows dinput with events\n"); + } + else + { + memset(&state, 0xFF, sizeof(state)); + hr = IDirectInputDevice_GetDeviceState(keyboard, sizeof(state), &state); + ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr); + + ok(state.keys[0] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); + ok(state.keys[1] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); + ok(state.keys[2] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); + ok(state.keys[3] == 0xFF, "key state should have been overwritten by the overlapped POV\n"); + ok(state.extra_element == 0, "State struct was not memset to zero\n"); + }
/* release D */ keybd_event(0, DIK_D, KEYEVENTF_SCANCODE|KEYEVENTF_KEYUP, 0);