[PATCH v2 3/3] dinput/tests: Merge device.c tests into device8.c.
Rémi Bernon
wine at gitlab.winehq.org
Thu Jun 9 03:13:03 CDT 2022
From: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/dinput/tests/Makefile.in | 1 -
dlls/dinput/tests/device.c | 533 ----------------------------------
dlls/dinput/tests/device8.c | 372 +++++++++++++++++++++++-
3 files changed, 361 insertions(+), 545 deletions(-)
delete mode 100644 dlls/dinput/tests/device.c
diff --git a/dlls/dinput/tests/Makefile.in b/dlls/dinput/tests/Makefile.in
index 73d8a2fc2a6..1556f3cda37 100644
--- a/dlls/dinput/tests/Makefile.in
+++ b/dlls/dinput/tests/Makefile.in
@@ -9,7 +9,6 @@ driver_hid_poll_IMPORTS = winecrt0 ntoskrnl hal hidclass
driver_hid_poll_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native
SOURCES = \
- device.c \
device8.c \
dinput.c \
driver_bus.c \
diff --git a/dlls/dinput/tests/device.c b/dlls/dinput/tests/device.c
deleted file mode 100644
index 6e1e94ba9c2..00000000000
--- a/dlls/dinput/tests/device.c
+++ /dev/null
@@ -1,533 +0,0 @@
-/*
- * Copyright (c) 2006 Vitaliy Margolen
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#define DIRECTINPUT_VERSION 0x0700
-
-#include <stdarg.h>
-#include <stddef.h>
-#include <limits.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-
-#define COBJMACROS
-#include "dinput.h"
-
-#include "dinput_test.h"
-
-static const DIOBJECTDATAFORMAT obj_data_format[] = {
- { &GUID_YAxis, 16, DIDFT_OPTIONAL|DIDFT_AXIS |DIDFT_MAKEINSTANCE(1), 0},
- { &GUID_Button,15, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(3), 0},
- { &GUID_Key, 0, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(16),0},
- { &GUID_Key, 1, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(17),0},
- { &GUID_Key, 2, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(18),0},
- { &GUID_Key, 3, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(19),0},
- { &GUID_Key, 4, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(20),0},
- { &GUID_Key, 5, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(21),0},
- { &GUID_Key, 6, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(22),0},
- { &GUID_Key, 7, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(23),0},
- { &GUID_Key, 8, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(24),0},
- { &GUID_Key, 9, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(25),0},
- { &GUID_Key, 10, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(26),0},
- { &GUID_Key, 11, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(27),0},
- { &GUID_Key, 12, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(28),0},
- { NULL, 13, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(5),0},
-
- { &GUID_Button,14, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(32),0}
-};
-
-static const DIDATAFORMAT data_format = {
- sizeof(DIDATAFORMAT),
- sizeof(DIOBJECTDATAFORMAT),
- DIDF_ABSAXIS,
- 32,
- ARRAY_SIZE(obj_data_format),
- (LPDIOBJECTDATAFORMAT)obj_data_format
-};
-
-static BOOL CALLBACK enum_callback(const DIDEVICEOBJECTINSTANCEA *oi, void *info)
-{
- if (winetest_debug > 1)
- trace(" Type:%#lx Ofs:%3ld Flags:%#lx Name:%s\n",
- oi->dwType, oi->dwOfs, oi->dwFlags, oi->tszName);
- (*(int*)info)++;
- return DIENUM_CONTINUE;
-}
-
-static BOOL CALLBACK enum_type_callback(const DIDEVICEOBJECTINSTANCEA *oi, void *info)
-{
- DWORD expected = *(DWORD*)info;
- ok (expected & DIDFT_GETTYPE(oi->dwType), "EnumObjects() enumerated wrong type for obj %s, expected: %#lx got: %#lx\n", oi->tszName, expected, oi->dwType);
- return DIENUM_CONTINUE;
-}
-
-static void test_object_info(IDirectInputDeviceA *device, HWND hwnd)
-{
- HRESULT hr;
- DIPROPDWORD dp;
- DIDEVICEOBJECTINSTANCEA obj_info;
- DWORD obj_types[] = {DIDFT_BUTTON, DIDFT_AXIS, DIDFT_POV};
- int type_index;
- int cnt1 = 0;
- DWORD cnt = 0;
- DIDEVICEOBJECTDATA buffer[5];
-
- hr = IDirectInputDevice_EnumObjects(device, NULL, &cnt, DIDFT_ALL);
- ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_EnumObjects returned %#lx, expected %#lx\n", hr, DIERR_INVALIDPARAM);
-
- hr = IDirectInputDevice_EnumObjects(device, enum_callback, &cnt, DIDFT_ALL);
- ok(SUCCEEDED(hr), "EnumObjects() failed: %#lx\n", hr);
-
- hr = IDirectInputDevice_SetDataFormat(device, &data_format);
- ok(SUCCEEDED(hr), "SetDataFormat() failed: %#lx\n", hr);
-
- hr = IDirectInputDevice_EnumObjects(device, enum_callback, &cnt1, DIDFT_ALL);
- ok(SUCCEEDED(hr), "EnumObjects() failed: %#lx\n", hr);
- if (0) /* fails for joystick only */
- ok(cnt == cnt1, "Enum count changed from %lu to %u\n", cnt, cnt1);
-
- /* Testing EnumObjects with different types of device objects */
- for (type_index=0; type_index < ARRAY_SIZE(obj_types); type_index++)
- {
- hr = IDirectInputDevice_EnumObjects(device, enum_type_callback, &obj_types[type_index], obj_types[type_index]);
- ok(SUCCEEDED(hr), "EnumObjects() failed: %#lx\n", hr);
- }
-
- /* Test buffered mode */
- memset(&dp, 0, sizeof(dp));
- dp.diph.dwSize = sizeof(DIPROPDWORD);
- dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
- dp.diph.dwHow = DIPH_DEVICE;
- dp.diph.dwObj = 0;
- dp.dwData = UINT_MAX;
-
- hr = IDirectInputDevice_GetProperty(device, DIPROP_BUFFERSIZE, &dp.diph);
- ok(hr == DI_OK, "Failed: %#lx\n", hr);
- ok(dp.dwData == 0, "got %ld\n", dp.dwData);
-
- dp.dwData = UINT_MAX;
- hr = IDirectInputDevice_SetProperty(device, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&dp.diph);
- ok(hr == DI_OK, "SetProperty() failed: %#lx\n", hr);
-
- dp.dwData = 0;
- hr = IDirectInputDevice_GetProperty(device, DIPROP_BUFFERSIZE, &dp.diph);
- ok(hr == DI_OK, "Failed: %#lx\n", hr);
- ok(dp.dwData == UINT_MAX, "got %ld\n", dp.dwData);
-
- dp.dwData = 0;
- hr = IDirectInputDevice_SetProperty(device, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&dp.diph);
- ok(hr == DI_OK, "SetProperty() failed: %#lx\n", hr);
- cnt = 5;
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
- ok(hr == DI_OK && cnt == 5, "GetDeviceData() failed: %#lx cnt: %ld\n", hr, cnt);
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(DIDEVICEOBJECTDATA_DX3), buffer, &cnt, 0);
- ok(hr == DIERR_NOTBUFFERED, "GetDeviceData() should have failed: %#lx\n", hr);
- IDirectInputDevice_Acquire(device);
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(DIDEVICEOBJECTDATA_DX3), buffer, &cnt, 0);
- ok(hr == DIERR_NOTBUFFERED, "GetDeviceData() should have failed: %#lx\n", hr);
- IDirectInputDevice_Unacquire(device);
-
- dp.dwData = 20;
- hr = IDirectInputDevice_SetProperty(device, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&dp.diph);
- ok(hr == DI_OK, "SetProperty() failed: %#lx\n", hr);
- cnt = 5;
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
- ok(hr == DI_OK, "GetDeviceData() failed: %#lx\n", hr);
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(DIDEVICEOBJECTDATA_DX3), buffer, &cnt, 0);
- ok(hr == DIERR_NOTACQUIRED, "GetDeviceData() should have failed: %#lx\n", hr);
- hr = IDirectInputDevice_Acquire(device);
- ok(hr == DI_OK, "Acquire() failed: %#lx\n", hr);
- cnt = 1;
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
- ok(hr == DI_OK, "GetDeviceData() failed: %#lx\n", hr);
- hr = IDirectInputDevice_Unacquire(device);
- ok(hr == DI_OK, "Unacquire() failed: %#lx\n", hr);
- cnt = 1;
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(buffer[0]), buffer, &cnt, 0);
- ok(hr == DI_OK, "GetDeviceData() failed: %#lx\n", hr);
-
- hr = IDirectInputDevice_GetObjectInfo(device, NULL, 16, DIPH_BYOFFSET);
- ok(hr == E_POINTER, "IDirectInputDevice_GetObjectInfo returned %#lx, expected %#lx\n", hr, E_POINTER);
-
- obj_info.dwSize = 1;
- hr = IDirectInputDevice_GetObjectInfo(device, &obj_info, 16, DIPH_BYOFFSET);
- ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetObjectInfo returned %#lx, expected %#lx\n", hr, DIERR_INVALIDPARAM);
- obj_info.dwSize = 0xdeadbeef;
- hr = IDirectInputDevice_GetObjectInfo(device, &obj_info, 16, DIPH_BYOFFSET);
- ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetObjectInfo returned %#lx, expected %#lx\n", hr, DIERR_INVALIDPARAM);
-
- /* No need to test devices without axis */
- obj_info.dwSize = sizeof(obj_info);
- hr = IDirectInputDevice_GetObjectInfo(device, &obj_info, 16, DIPH_BYOFFSET);
- if (SUCCEEDED(hr))
- {
- /* No device supports per axis relative/absolute mode */
- dp.diph.dwHow = DIPH_BYOFFSET;
- dp.diph.dwObj = 16;
- dp.dwData = DIPROPAXISMODE_ABS;
- hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
- ok(hr == DIERR_UNSUPPORTED, "SetProperty() returned: %#lx\n", hr);
- dp.diph.dwHow = DIPH_DEVICE;
- hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
- ok(hr == DIERR_INVALIDPARAM, "SetProperty() returned: %#lx\n", hr);
- dp.diph.dwObj = 0;
- hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
- ok(hr == DI_OK, "SetProperty() failed: %#lx\n", hr);
-
- /* Cannot change mode while acquired */
- hr = IDirectInputDevice_Acquire(device);
- ok(hr == DI_OK, "Acquire() failed: %#lx\n", hr);
-
- hr = IDirectInputDevice_SetProperty(device, DIPROP_AXISMODE, &dp.diph);
- ok(hr == DIERR_ACQUIRED, "SetProperty() returned: %#lx\n", hr);
- hr = IDirectInputDevice_Unacquire(device);
- ok(hr == DI_OK, "Unacquire() failed: %#lx\n", hr);
- }
-
- /* Reset buffer size */
- dp.diph.dwSize = sizeof(DIPROPDWORD);
- dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
- dp.diph.dwHow = DIPH_DEVICE;
- dp.diph.dwObj = 0;
- dp.dwData = 0;
- hr = IDirectInputDevice_SetProperty(device, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&dp.diph);
- ok(hr == DI_OK, "SetProperty() failed: %#lx\n", hr);
-}
-
-struct enum_data
-{
- IDirectInputA *pDI;
- HWND hwnd;
- BOOL tested_product_creation;
-};
-
-static BOOL CALLBACK enum_devices(const DIDEVICEINSTANCEA *lpddi, void *pvRef)
-{
- struct enum_data *data = pvRef;
- IDirectInputDeviceA *device, *obj = NULL;
- DIDEVICEINSTANCEA ddi2;
- HRESULT hr;
- IUnknown *iface, *tmp_iface;
-
- hr = IDirectInput_GetDeviceStatus(data->pDI, &lpddi->guidInstance);
- ok(hr == DI_OK, "IDirectInput_GetDeviceStatus() failed: %#lx\n", hr);
-
- if (hr == DI_OK)
- {
- hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, &device, NULL);
- ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
- trace("Testing device %p \"%s\"\n", device, lpddi->tszInstanceName);
-
- hr = IUnknown_QueryInterface(device, &IID_IDirectInputDevice2A, (LPVOID*)&obj);
- ok(SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice2A) failed: %#lx\n", hr);
- test_object_info(obj, data->hwnd);
- IUnknown_Release(obj);
- obj = NULL;
-
- hr = IUnknown_QueryInterface(device, &IID_IDirectInputDevice2W, (LPVOID*)&obj);
- ok(SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice2W) failed: %#lx\n", hr);
- test_object_info(obj, data->hwnd);
- IUnknown_Release(obj);
-
- hr = IUnknown_QueryInterface( device, &IID_IDirectInputDeviceA, (void **)&iface );
- ok( SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDeviceA) failed: %#lx\n", hr );
- hr = IUnknown_QueryInterface( device, &IID_IDirectInputDevice2A, (void **)&tmp_iface );
- ok( SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice2A) failed: %#lx\n", hr );
- ok( tmp_iface == iface, "IDirectInputDevice2A iface differs from IDirectInputDeviceA\n" );
- IUnknown_Release( tmp_iface );
- hr = IUnknown_QueryInterface( device, &IID_IDirectInputDevice7A, (void **)&tmp_iface );
- ok( SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice7A) failed: %#lx\n", hr );
- ok( tmp_iface == iface, "IDirectInputDevice7A iface differs from IDirectInputDeviceA\n" );
- IUnknown_Release( tmp_iface );
- IUnknown_Release( iface );
-
- hr = IUnknown_QueryInterface( device, &IID_IUnknown, (void **)&iface );
- ok( SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IUnknown) failed: %#lx\n", hr );
- hr = IUnknown_QueryInterface( device, &IID_IDirectInputDeviceW, (void **)&tmp_iface );
- ok( SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDeviceW) failed: %#lx\n", hr );
- ok( tmp_iface == iface, "IDirectInputDeviceW iface differs from IUnknown\n" );
- IUnknown_Release( tmp_iface );
- hr = IUnknown_QueryInterface( device, &IID_IDirectInputDevice2W, (void **)&tmp_iface );
- ok( SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice2W) failed: %#lx\n", hr );
- ok( tmp_iface == iface, "IDirectInputDevice2W iface differs from IUnknown\n" );
- IUnknown_Release( tmp_iface );
- hr = IUnknown_QueryInterface( device, &IID_IDirectInputDevice7W, (void **)&tmp_iface );
- ok( SUCCEEDED(hr), "IUnknown_QueryInterface(IID_IDirectInputDevice7W) failed: %#lx\n", hr );
- ok( tmp_iface == iface, "IDirectInputDevice7W iface differs from IUnknown\n" );
- IUnknown_Release( tmp_iface );
- IUnknown_Release( iface );
-
- IUnknown_Release(device);
-
- if (!IsEqualGUID(&lpddi->guidInstance, &lpddi->guidProduct))
- {
- data->tested_product_creation = TRUE;
- hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidProduct, &device, NULL);
- ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
-
- ddi2.dwSize = sizeof(ddi2);
- hr = IDirectInputDevice_GetDeviceInfo(device, &ddi2);
- ok(SUCCEEDED(hr), "IDirectInput_GetDeviceInfo failed: %#lx\n", hr);
-
- ok(IsEqualGUID(&lpddi->guidProduct, &ddi2.guidProduct), "Product GUIDs do not match. Expected %s, got %s\n", debugstr_guid(&lpddi->guidProduct), debugstr_guid(&ddi2.guidProduct));
- ok(IsEqualGUID(&ddi2.guidProduct, &ddi2.guidInstance), "Instance GUID should equal product GUID. Expected %s, got %s\n", debugstr_guid(&ddi2.guidProduct), debugstr_guid(&ddi2.guidInstance));
- /* we cannot compare guidInstances as we may get a different device */
-
- IUnknown_Release(device);
- }
-
- }
- return DIENUM_CONTINUE;
-}
-
-struct overlapped_state
-{
- BYTE keys[4];
- DWORD extra_element;
-};
-
-static const DIOBJECTDATAFORMAT obj_overlapped_slider_format[] = {
- { &GUID_Key, 0, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_A),0},
- { &GUID_Key, 1, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_S),0},
- { &GUID_Key, 2, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_D),0},
- { &GUID_Key, 3, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_F),0},
- { &GUID_Slider, 0, DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,DIDOI_ASPECTPOSITION},
-};
-
-static const DIDATAFORMAT overlapped_slider_format = {
- sizeof(DIDATAFORMAT),
- sizeof(DIOBJECTDATAFORMAT),
- DIDF_ABSAXIS,
- sizeof(struct overlapped_state),
- ARRAY_SIZE(obj_overlapped_slider_format),
- (LPDIOBJECTDATAFORMAT)obj_overlapped_slider_format
-};
-
-static const DIOBJECTDATAFORMAT obj_overlapped_pov_format[] = {
- { &GUID_Key, 0, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_A),0},
- { &GUID_Key, 1, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_S),0},
- { &GUID_Key, 2, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_D),0},
- { &GUID_Key, 3, DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_MAKEINSTANCE(DIK_F),0},
- { &GUID_POV, 0, DIDFT_OPTIONAL|DIDFT_POV|DIDFT_ANYINSTANCE,0},
-};
-
-static const DIDATAFORMAT overlapped_pov_format = {
- sizeof(DIDATAFORMAT),
- sizeof(DIOBJECTDATAFORMAT),
- DIDF_ABSAXIS,
- sizeof(struct overlapped_state),
- ARRAY_SIZE(obj_overlapped_pov_format),
- (LPDIOBJECTDATAFORMAT)obj_overlapped_pov_format
-};
-
-static void pump_messages(void)
-{
- MSG msg;
-
- while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessageA(&msg);
- }
-}
-
-#define wait_for_device_data_and_discard(device) wait_for_device_data_and_discard_(__LINE__, device)
-static BOOL wait_for_device_data_and_discard_(int line, IDirectInputDeviceA *device)
-{
- DWORD cnt;
- HRESULT hr;
- DWORD start_time;
-
- pump_messages();
-
- start_time = GetTickCount();
- do
- {
- cnt = 10;
- hr = IDirectInputDevice_GetDeviceData(device, sizeof(DIDEVICEOBJECTDATA_DX3), NULL, &cnt, 0);
- ok_(__FILE__, line)(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceData() failed: %#lx\n", hr);
- ok_(__FILE__, line)(cnt == 0 || cnt == 1, "Unexpected number of events: %lu\n", cnt);
- } while (cnt != 1 && (GetTickCount() - start_time < 500));
-
- return cnt == 1;
-}
-
-#define acquire_and_wait(device, valid_dik) acquire_and_wait_(__LINE__, device, valid_dik)
-static void acquire_and_wait_(int line, IDirectInputDeviceA *device, DWORD valid_dik)
-{
- HRESULT hr;
- int tries = 2;
-
- hr = IDirectInputDevice_Acquire(device);
- ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %#lx\n", hr);
-
- do
- {
- keybd_event(0, valid_dik, KEYEVENTF_SCANCODE, 0);
- } while (!wait_for_device_data_and_discard(device) && tries--);
-
- keybd_event(0, valid_dik, KEYEVENTF_SCANCODE|KEYEVENTF_KEYUP, 0);
- ok_(__FILE__, line)(wait_for_device_data_and_discard(device),
- "Timed out while waiting for injected events to be picked up by DirectInput.\n");
-}
-
-void overlapped_format_tests(IDirectInputA *pDI, HWND hwnd)
-{
- HRESULT hr;
- struct overlapped_state state;
- IDirectInputDeviceA *keyboard = NULL;
- DIPROPDWORD dp;
-
- SetFocus(hwnd);
-
- hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &keyboard, NULL);
- ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
-
- /* test overlapped slider - default value 0 */
- hr = IDirectInputDevice_SetDataFormat(keyboard, &overlapped_slider_format);
- ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %#lx\n", hr);
-
- dp.diph.dwSize = sizeof(DIPROPDWORD);
- dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
- dp.diph.dwHow = DIPH_DEVICE;
- dp.diph.dwObj = 0;
- dp.dwData = 10;
- hr = IDirectInputDevice_SetProperty(keyboard, DIPROP_BUFFERSIZE, &dp.diph);
- ok(SUCCEEDED(hr), "IDirectInputDevice_SetProperty() failed: %#lx\n", hr);
-
- acquire_and_wait(keyboard, DIK_F);
-
- /* press D */
- keybd_event(0, DIK_D, KEYEVENTF_SCANCODE, 0);
- ok(wait_for_device_data_and_discard(keyboard),
- "Timed out while waiting for injected events to be picked up by DirectInput.\n");
-
- memset(&state, 0xFF, sizeof(state));
- hr = IDirectInputDevice_GetDeviceState(keyboard, sizeof(state), &state);
- ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %#lx\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");
-
- /* release D */
- keybd_event(0, DIK_D, KEYEVENTF_SCANCODE|KEYEVENTF_KEYUP, 0);
- ok(wait_for_device_data_and_discard(keyboard),
- "Timed out while waiting for injected events to be picked up by DirectInput.\n");
-
- hr = IDirectInputDevice_Unacquire(keyboard);
- ok(SUCCEEDED(hr), "IDirectInputDevice_Unacquire() failed: %#lx\n", hr);
-
- /* test overlapped pov - default value - 0xFFFFFFFF */
- hr = IDirectInputDevice_SetDataFormat(keyboard, &overlapped_pov_format);
- ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %#lx\n", hr);
-
- acquire_and_wait(keyboard, DIK_F);
-
- /* press D */
- keybd_event(0, DIK_D, KEYEVENTF_SCANCODE, 0);
- ok(wait_for_device_data_and_discard(keyboard),
- "Timed out while waiting for injected events to be picked up by DirectInput.\n");
-
- memset(&state, 0xFF, sizeof(state));
- hr = IDirectInputDevice_GetDeviceState(keyboard, sizeof(state), &state);
- ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %#lx\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);
- ok(wait_for_device_data_and_discard(keyboard),
- "Timed out while waiting for injected events to be picked up by DirectInput.\n");
-
- if (keyboard) IUnknown_Release(keyboard);
-}
-
-static void device_tests(void)
-{
- HRESULT hr;
- IDirectInputA *pDI = NULL, *obj = NULL;
- HWND hwnd;
- struct enum_data data;
-
- hr = CoCreateInstance(&CLSID_DirectInput, 0, 1, &IID_IDirectInput2A, (LPVOID*)&pDI);
- if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_DEVICENOTREG)
- {
- skip("Tests require a newer dinput version\n");
- return;
- }
- ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %#lx\n", hr);
- if (FAILED(hr)) return;
-
- hr = IDirectInput_Initialize(pDI, instance, DIRECTINPUT_VERSION);
- ok(SUCCEEDED(hr), "Initialize() failed: %#lx\n", hr);
- if (FAILED(hr)) return;
-
- hr = IUnknown_QueryInterface(pDI, &IID_IDirectInput2W, (LPVOID*)&obj);
- ok(SUCCEEDED(hr), "QueryInterface(IDirectInput7W) failed: %#lx\n", hr);
-
- hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
- NULL, NULL);
- ok(hwnd != NULL, "err: %ld\n", GetLastError());
- if (hwnd)
- {
- ShowWindow(hwnd, SW_SHOW);
-
- data.pDI = pDI;
- data.hwnd = hwnd;
- data.tested_product_creation = FALSE;
- hr = IDirectInput_EnumDevices(pDI, 0, enum_devices, &data, DIEDFL_ALLDEVICES);
- ok(SUCCEEDED(hr), "IDirectInput_EnumDevices() failed: %#lx\n", hr);
-
- if (!data.tested_product_creation) winetest_skip("Device creation using product GUID not tested\n");
-
- /* If GetDeviceStatus returns DI_OK the device must exist */
- hr = IDirectInput_GetDeviceStatus(pDI, &GUID_Joystick);
- if (hr == DI_OK)
- {
- IDirectInputDeviceA *device = NULL;
-
- hr = IDirectInput_CreateDevice(pDI, &GUID_Joystick, &device, NULL);
- ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
- if (device) IUnknown_Release(device);
- }
-
- overlapped_format_tests(pDI, hwnd);
-
- DestroyWindow(hwnd);
- }
- if (obj) IUnknown_Release(obj);
- if (pDI) IUnknown_Release(pDI);
-}
-
-START_TEST(device)
-{
- dinput_test_init();
-
- device_tests();
-
- dinput_test_exit();
-}
diff --git a/dlls/dinput/tests/device8.c b/dlls/dinput/tests/device8.c
index 70c3e516f17..7bd3600df61 100644
--- a/dlls/dinput/tests/device8.c
+++ b/dlls/dinput/tests/device8.c
@@ -21,6 +21,7 @@
#include <stdarg.h>
#include <stddef.h>
+#include <limits.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
@@ -33,13 +34,20 @@
#include "dinput_test.h"
-struct enum_data {
- IDirectInput8A *pDI;
+struct enum_data
+{
+ DWORD version;
+ union
+ {
+ IDirectInput8A *dinput8;
+ IDirectInputA *dinput;
+ };
DIACTIONFORMATA *lpdiaf;
IDirectInputDevice8A *keyboard;
IDirectInputDevice8A *mouse;
- const char* username;
+ const char *username;
int ndevices;
+ HWND hwnd;
};
/* Dummy GUID */
@@ -74,19 +82,343 @@ static DIACTIONA actionMapping[]=
static void flush_events(void)
{
- int diff = 200;
- int min_timeout = 100;
+ int min_timeout = 100, diff = 200;
DWORD time = GetTickCount() + diff;
+ MSG msg;
while (diff > 0)
{
- if (MsgWaitForMultipleObjects(0, NULL, FALSE, min_timeout, QS_ALLINPUT) == WAIT_TIMEOUT)
- break;
+ if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
+ while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ))
+ {
+ TranslateMessage( &msg );
+ DispatchMessageA( &msg );
+ }
diff = time - GetTickCount();
- min_timeout = 50;
}
}
+static HRESULT direct_input_create( DWORD version, IDirectInputA **out )
+{
+ HRESULT hr;
+ if (version < 0x800) hr = DirectInputCreateA( instance, version, out, NULL );
+ else hr = DirectInput8Create( instance, version, &IID_IDirectInput8A, (void **)out, NULL );
+ if (FAILED(hr)) win_skip( "Failed to instantiate a IDirectInput instance, hr %#lx\n", hr );
+ return hr;
+}
+
+#define check_interface( a, b, c ) check_interface_( __LINE__, a, b, c )
+static void check_interface_( unsigned int line, void *iface_ptr, REFIID iid, BOOL supported )
+{
+ IUnknown *iface = iface_ptr;
+ HRESULT hr, expected;
+ IUnknown *unk;
+
+ expected = supported ? S_OK : E_NOINTERFACE;
+ hr = IUnknown_QueryInterface( iface, iid, (void **)&unk );
+ ok_(__FILE__, line)( hr == expected, "got hr %#lx, expected %#lx.\n", hr, expected );
+ if (SUCCEEDED(hr)) IUnknown_Release( unk );
+}
+
+static BOOL CALLBACK check_device_query_interface( const DIDEVICEINSTANCEA *instance, void *context )
+{
+ struct enum_data *data = context;
+ IUnknown *device;
+ HRESULT hr;
+ LONG ref;
+
+ if (data->version < 0x800)
+ {
+ hr = IDirectInput_GetDeviceStatus( data->dinput, &instance->guidInstance );
+ ok( hr == DI_OK, "GetDeviceStatus returned %#lx\n", hr );
+ hr = IDirectInput_GetDeviceStatus( data->dinput, &instance->guidProduct );
+ ok( hr == DI_OK, "GetDeviceStatus returned %#lx\n", hr );
+
+ hr = IDirectInput_CreateDevice( data->dinput, &instance->guidProduct, (IDirectInputDeviceA **)&device, NULL );
+ ok( hr == DI_OK, "CreateDevice returned %#lx\n", hr );
+ ref = IUnknown_Release( device );
+ ok( ref == 0, "Release returned %ld\n", ref );
+
+ hr = IDirectInput_CreateDevice( data->dinput, &instance->guidInstance, (IDirectInputDeviceA **)&device, NULL );
+ ok( hr == DI_OK, "CreateDevice returned %#lx\n", hr );
+ }
+ else
+ {
+ hr = IDirectInput8_GetDeviceStatus( data->dinput8, &instance->guidInstance );
+ ok( hr == DI_OK, "GetDeviceStatus returned %#lx\n", hr );
+ hr = IDirectInput8_GetDeviceStatus( data->dinput8, &instance->guidProduct );
+ ok( hr == DI_OK, "GetDeviceStatus returned %#lx\n", hr );
+
+ hr = IDirectInput8_CreateDevice( data->dinput8, &instance->guidProduct, (IDirectInputDevice8A **)&device, NULL );
+ ok( hr == DI_OK, "CreateDevice returned %#lx\n", hr );
+ ref = IUnknown_Release( device );
+ ok( ref == 0, "Release returned %ld\n", ref );
+
+ hr = IDirectInput8_CreateDevice( data->dinput8, &instance->guidInstance, (IDirectInputDevice8A **)&device, NULL );
+ ok( hr == DI_OK, "CreateDevice returned %#lx\n", hr );
+ }
+
+ todo_wine_if( data->version >= 0x800 )
+ check_interface( device, &IID_IDirectInputDeviceA, data->version < 0x800 );
+ todo_wine_if( data->version >= 0x800 )
+ check_interface( device, &IID_IDirectInputDevice2A, data->version < 0x800 );
+ todo_wine_if( data->version >= 0x800 )
+ check_interface( device, &IID_IDirectInputDevice7A, data->version < 0x800 );
+ todo_wine_if( data->version < 0x800 )
+ check_interface( device, &IID_IDirectInputDevice8A, data->version >= 0x800 );
+
+ todo_wine_if( data->version >= 0x800 )
+ check_interface( device, &IID_IDirectInputDeviceW, data->version < 0x800 );
+ todo_wine_if( data->version >= 0x800 )
+ check_interface( device, &IID_IDirectInputDevice2W, data->version < 0x800 );
+ todo_wine_if( data->version >= 0x800 )
+ check_interface( device, &IID_IDirectInputDevice7W, data->version < 0x800 );
+ todo_wine_if( data->version < 0x800 )
+ check_interface( device, &IID_IDirectInputDevice8W, data->version >= 0x800 );
+
+ ref = IUnknown_Release( device );
+ ok( ref == 0, "Release returned %ld\n", ref );
+
+ return DIENUM_CONTINUE;
+}
+
+static void test_QueryInterface( DWORD version )
+{
+ struct enum_data data = {.version = version};
+ HRESULT hr;
+ ULONG ref;
+
+ if (FAILED(hr = direct_input_create( version, &data.dinput ))) return;
+
+ winetest_push_context( "%#lx", version );
+
+ if (version < 0x800)
+ {
+ hr = IDirectInput_EnumDevices( data.dinput, 0, check_device_query_interface, &data, DIEDFL_ALLDEVICES );
+ ok( hr == DI_OK, "EnumDevices returned %#lx\n", hr );
+ }
+ else
+ {
+ hr = IDirectInput8_EnumDevices( data.dinput8, 0, check_device_query_interface, &data, DIEDFL_ALLDEVICES );
+ ok( hr == DI_OK, "EnumDevices returned %#lx\n", hr );
+ }
+
+ ref = IDirectInput_Release( data.dinput );
+ ok( ref == 0, "Release returned %lu\n", ref );
+
+ winetest_pop_context();
+}
+
+struct overlapped_state
+{
+ BYTE keys[4];
+ DWORD extra_element;
+};
+
+static DIOBJECTDATAFORMAT obj_overlapped_slider_format[] =
+{
+ {&GUID_Key, 0, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_A ), 0},
+ {&GUID_Key, 1, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_S ), 0},
+ {&GUID_Key, 2, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_D ), 0},
+ {&GUID_Key, 3, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_F ), 0},
+ {&GUID_Slider, 0, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, DIDOI_ASPECTPOSITION},
+};
+
+static const DIDATAFORMAT overlapped_slider_format =
+{
+ sizeof(DIDATAFORMAT),
+ sizeof(DIOBJECTDATAFORMAT),
+ DIDF_ABSAXIS,
+ sizeof(struct overlapped_state),
+ ARRAY_SIZE(obj_overlapped_slider_format),
+ obj_overlapped_slider_format,
+};
+
+static DIOBJECTDATAFORMAT obj_overlapped_pov_format[] =
+{
+ {&GUID_Key, 0, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_A ), 0},
+ {&GUID_Key, 1, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_S ), 0},
+ {&GUID_Key, 2, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_D ), 0},
+ {&GUID_Key, 3, DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_MAKEINSTANCE( DIK_F ), 0},
+ {&GUID_POV, 0, DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0},
+};
+
+static const DIDATAFORMAT overlapped_pov_format =
+{
+ sizeof(DIDATAFORMAT),
+ sizeof(DIOBJECTDATAFORMAT),
+ DIDF_ABSAXIS,
+ sizeof(struct overlapped_state),
+ ARRAY_SIZE(obj_overlapped_pov_format),
+ obj_overlapped_pov_format,
+};
+
+void test_overlapped_format( DWORD version )
+{
+ static const DIPROPDWORD buffer_size =
+ {
+ .diph =
+ {
+ .dwSize = sizeof(DIPROPDWORD),
+ .dwHeaderSize = sizeof(DIPROPHEADER),
+ .dwHow = DIPH_DEVICE,
+ },
+ .dwData = 10,
+ };
+ SIZE_T data_size = version < 0x800 ? sizeof(DIDEVICEOBJECTDATA_DX3) : sizeof(DIDEVICEOBJECTDATA);
+ struct overlapped_state state;
+ IDirectInputDeviceA *keyboard;
+ IDirectInputA *dinput;
+ DWORD res, count;
+ HANDLE event;
+ HRESULT hr;
+ HWND hwnd;
+
+ if (FAILED(hr = direct_input_create( version, &dinput ))) return;
+
+ winetest_push_context( "%#lx", version );
+
+ event = CreateEventW( NULL, FALSE, FALSE, NULL );
+ ok( !!event, "CreateEventW failed, error %lu\n", GetLastError() );
+ hwnd = CreateWindowW( L"static", L"Title", WS_POPUP | WS_VISIBLE, 10, 10, 200, 200, NULL, NULL, NULL, NULL );
+ ok( !!hwnd, "CreateWindowW failed, error %lu\n", GetLastError() );
+
+ hr = IDirectInput_CreateDevice( dinput, &GUID_SysKeyboard, &keyboard, NULL );
+ ok( hr == DI_OK, "CreateDevice returned %#lx\n", hr );
+ hr = IDirectInputDevice8_SetCooperativeLevel( keyboard, hwnd, DISCL_FOREGROUND|DISCL_EXCLUSIVE );
+ ok( hr == DI_OK, "SetCooperativeLevel returned %#lx\n", hr );
+ hr = IDirectInputDevice8_SetEventNotification( keyboard, event );
+ ok( hr == DI_OK, "SetEventNotification returned %#lx\n", hr );
+
+ /* test overlapped slider - default value 0 */
+ hr = IDirectInputDevice_SetDataFormat( keyboard, &overlapped_slider_format );
+ ok( hr == DI_OK, "SetDataFormat returned %#lx\n", hr );
+ hr = IDirectInputDevice_SetProperty( keyboard, DIPROP_BUFFERSIZE, &buffer_size.diph );
+ ok( hr == DI_OK, "SetProperty returned %#lx\n", hr );
+
+
+ hr = IDirectInputDevice_Acquire( keyboard );
+ ok( hr == DI_OK, "Acquire returned %#lx\n", hr );
+
+ keybd_event( 0, DIK_F, KEYEVENTF_SCANCODE, 0 );
+ res = WaitForSingleObject( event, 100 );
+ if (res == WAIT_TIMEOUT) /* Acquire is asynchronous */
+ {
+ keybd_event( 0, DIK_F, KEYEVENTF_SCANCODE, 0 );
+ res = WaitForSingleObject( event, 100 );
+ }
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ keybd_event( 0, DIK_F, KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP, 0 );
+ res = WaitForSingleObject( event, 100 );
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ count = 10;
+ hr = IDirectInputDevice_GetDeviceData( keyboard, data_size, NULL, &count, 0 );
+ ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr );
+ ok( count > 0, "got count %lu\n", count );
+
+
+ /* press D */
+ keybd_event( 0, DIK_D, KEYEVENTF_SCANCODE, 0 );
+ res = WaitForSingleObject( event, 100 );
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ count = 10;
+ hr = IDirectInputDevice_GetDeviceData( keyboard, data_size, NULL, &count, 0 );
+ ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr );
+ ok( count == 1, "got count %lu\n", count );
+
+ memset( &state, 0xFF, sizeof(state) );
+ hr = IDirectInputDevice_GetDeviceState( keyboard, sizeof(state), &state );
+ ok( hr == DI_OK, "GetDeviceState returned %#lx\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" );
+
+ /* release D */
+ keybd_event( 0, DIK_D, KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP, 0 );
+ res = WaitForSingleObject( event, 100 );
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ count = 10;
+ hr = IDirectInputDevice_GetDeviceData( keyboard, data_size, NULL, &count, 0 );
+ ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr );
+ ok( count == 1, "got count %lu\n", count );
+
+
+ hr = IDirectInputDevice_Unacquire( keyboard );
+ ok( hr == DI_OK, "Unacquire returned %#lx\n", hr );
+
+ /* test overlapped pov - default value - 0xFFFFFFFF */
+ hr = IDirectInputDevice_SetDataFormat( keyboard, &overlapped_pov_format );
+ ok( hr == DI_OK, "SetDataFormat returned %#lx\n", hr );
+
+
+ hr = IDirectInputDevice_Acquire( keyboard );
+ ok( hr == DI_OK, "Acquire returned %#lx\n", hr );
+
+ keybd_event( 0, DIK_F, KEYEVENTF_SCANCODE, 0 );
+ res = WaitForSingleObject( event, 100 );
+ if (res == WAIT_TIMEOUT) /* Acquire is asynchronous */
+ {
+ keybd_event( 0, DIK_F, KEYEVENTF_SCANCODE, 0 );
+ res = WaitForSingleObject( event, 100 );
+ }
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ keybd_event( 0, DIK_F, KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP, 0 );
+ res = WaitForSingleObject( event, 100 );
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ count = 10;
+ hr = IDirectInputDevice_GetDeviceData( keyboard, data_size, NULL, &count, 0 );
+ ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr );
+ ok( count > 0, "got count %lu\n", count );
+
+
+ /* press D */
+ keybd_event( 0, DIK_D, KEYEVENTF_SCANCODE, 0 );
+ res = WaitForSingleObject( event, 100 );
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ count = 10;
+ hr = IDirectInputDevice_GetDeviceData( keyboard, data_size, NULL, &count, 0 );
+ ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr );
+ ok( count == 1, "got count %lu\n", count );
+
+ memset( &state, 0xFF, sizeof(state) );
+ hr = IDirectInputDevice_GetDeviceState( keyboard, sizeof(state), &state );
+ ok( hr == DI_OK, "GetDeviceState returned %#lx\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 );
+ res = WaitForSingleObject( event, 100 );
+ ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
+
+ count = 10;
+ hr = IDirectInputDevice_GetDeviceData( keyboard, data_size, NULL, &count, 0 );
+ ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr );
+ ok( count == 1, "got count %lu\n", count );
+
+
+ IUnknown_Release( keyboard );
+
+ DestroyWindow( hwnd );
+ CloseHandle( event );
+
+ winetest_pop_context();
+}
+
static void test_device_input( IDirectInputDevice8A *device, DWORD type, DWORD code, UINT_PTR expected )
{
HRESULT hr;
@@ -110,6 +442,11 @@ static void test_device_input( IDirectInputDevice8A *device, DWORD type, DWORD c
{
keybd_event( 0, code, KEYEVENTF_SCANCODE, 0 );
res = WaitForSingleObject( event, 100 );
+ if (res == WAIT_TIMEOUT) /* Acquire is asynchronous */
+ {
+ keybd_event( 0, code, KEYEVENTF_SCANCODE, 0 );
+ res = WaitForSingleObject( event, 100 );
+ }
ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
keybd_event( 0, code, KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP, 0 );
@@ -120,6 +457,11 @@ static void test_device_input( IDirectInputDevice8A *device, DWORD type, DWORD c
{
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
res = WaitForSingleObject( event, 100 );
+ if (res == WAIT_TIMEOUT) /* Acquire is asynchronous */
+ {
+ mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
+ res = WaitForSingleObject( event, 100 );
+ }
ok( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
@@ -255,7 +597,7 @@ static BOOL CALLBACK enumeration_callback(const DIDEVICEINSTANCEA *lpddi, IDirec
}
/* Creating second device object to check if it has the same username */
- hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, &lpdid2, NULL);
+ hr = IDirectInput_CreateDevice(data->dinput8, &lpddi->guidInstance, &lpdid2, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %#lx\n", hr);
/* Building and setting an action map */
@@ -382,7 +724,7 @@ static void test_action_mapping(void)
IDirectInput8A *pDI = NULL;
DIACTIONFORMATA af;
DIPROPSTRING dps;
- struct enum_data data = {pDI, &af, NULL, NULL, NULL, 0};
+ struct enum_data data = {.version = 0x800, .lpdiaf = &af};
HWND hwnd;
hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&pDI);
@@ -416,7 +758,7 @@ static void test_action_mapping(void)
af.dwBufferSize = 32;
/* This enumeration builds and sets the action map for all devices */
- data.pDI = pDI;
+ data.dinput8 = pDI;
hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%#lx\n", hr);
@@ -1816,6 +2158,14 @@ START_TEST(device8)
{
dinput_test_init();
+ test_QueryInterface( 0x300 );
+ test_QueryInterface( 0x500 );
+ test_QueryInterface( 0x700 );
+ test_QueryInterface( 0x800 );
+
+ test_overlapped_format( 0x700 );
+ test_overlapped_format( 0x800 );
+
test_mouse_info();
test_keyboard_info();
test_action_mapping();
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/208
More information about the wine-devel
mailing list