Wine-Bug: https://bugs.winehq.org//show_bug.cgi?id=53525
-- v4: https://gitlab.winehq.org/wine/wine/-/merge_requests/1842
From: Rémi Bernon rbernon@codeweavers.com
This was previously automatically done when user32 was loaded, but since the move of __wine_send_input to win32u, we do not need to load it any more. Make sure we have a desktop or WM_INPUT messages won't be sent by wineserver. --- dlls/hidclass.sys/pnp.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/dlls/hidclass.sys/pnp.c b/dlls/hidclass.sys/pnp.c index 46b6e803465..c0e2a874788 100644 --- a/dlls/hidclass.sys/pnp.c +++ b/dlls/hidclass.sys/pnp.c @@ -599,6 +599,10 @@ NTSTATUS WINAPI HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION *registration) { minidriver *driver;
+ /* make sure we have a window station and a desktop, we need one to send input */ + if (!GetProcessWindowStation()) + return STATUS_INVALID_PARAMETER; + if (!(driver = calloc(1, sizeof(*driver)))) return STATUS_NO_MEMORY;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/tests/device8.c | 52 ++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 18 deletions(-)
diff --git a/dlls/dinput/tests/device8.c b/dlls/dinput/tests/device8.c index e779b56092a..b98a24df080 100644 --- a/dlls/dinput/tests/device8.c +++ b/dlls/dinput/tests/device8.c @@ -1103,9 +1103,9 @@ static void test_mouse_keyboard(void) todo_wine ok(hr == 1, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count); todo_wine - ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage); + ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage); todo_wine - ok(raw_devices[0].usUsage == 6, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage); + ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_KEYBOARD, "got usUsage: %x\n", raw_devices[0].usUsage); todo_wine ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags); todo_wine @@ -1137,8 +1137,8 @@ static void test_mouse_keyboard(void) memset(raw_devices, 0, sizeof(raw_devices)); hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE)); ok(hr == 1, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count); - ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage); - ok(raw_devices[0].usUsage == 2, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage); + ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage); + ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_MOUSE, "got usUsage: %x\n", raw_devices[0].usUsage); ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags); todo_wine ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget); @@ -1152,16 +1152,16 @@ static void test_mouse_keyboard(void) di_hwnd = raw_devices[0].hwndTarget;
/* expect dinput8 to take over any activated raw input devices */ - raw_devices[0].usUsagePage = 0x01; - raw_devices[0].usUsage = 0x05; + raw_devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; + raw_devices[0].usUsage = HID_USAGE_GENERIC_GAMEPAD; raw_devices[0].dwFlags = 0; raw_devices[0].hwndTarget = hwnd; - raw_devices[1].usUsagePage = 0x01; - raw_devices[1].usUsage = 0x06; + raw_devices[1].usUsagePage = HID_USAGE_PAGE_GENERIC; + raw_devices[1].usUsage = HID_USAGE_GENERIC_KEYBOARD; raw_devices[1].dwFlags = 0; raw_devices[1].hwndTarget = hwnd; - raw_devices[2].usUsagePage = 0x01; - raw_devices[2].usUsage = 0x02; + raw_devices[2].usUsagePage = HID_USAGE_PAGE_GENERIC; + raw_devices[2].usUsage = HID_USAGE_GENERIC_MOUSE; raw_devices[2].dwFlags = 0; raw_devices[2].hwndTarget = hwnd; raw_devices_count = ARRAY_SIZE(raw_devices); @@ -1176,16 +1176,16 @@ static void test_mouse_keyboard(void) memset(raw_devices, 0, sizeof(raw_devices)); hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE)); ok(hr == 3, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count); - ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage); - ok(raw_devices[0].usUsage == 2, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage); + ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage); + ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_MOUSE, "got usUsage: %x\n", raw_devices[0].usUsage); ok(raw_devices[0].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags); ok(raw_devices[0].hwndTarget == di_hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget); - ok(raw_devices[1].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage); - ok(raw_devices[1].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage); + ok(raw_devices[1].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[1].usUsagePage); + ok(raw_devices[1].usUsage == HID_USAGE_GENERIC_GAMEPAD, "got usUsage: %x\n", raw_devices[1].usUsage); ok(raw_devices[1].dwFlags == 0, "Unexpected raw device flags: %#lx\n", raw_devices[1].dwFlags); ok(raw_devices[1].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[1].hwndTarget); - ok(raw_devices[2].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[1].usUsagePage); - ok(raw_devices[2].usUsage == 6, "Unexpected raw device usage: %x\n", raw_devices[1].usUsage); + ok(raw_devices[2].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[1].usUsagePage); + ok(raw_devices[2].usUsage == HID_USAGE_GENERIC_KEYBOARD, "got usUsage: %x\n", raw_devices[1].usUsage); todo_wine ok(raw_devices[2].dwFlags == RIDEV_INPUTSINK, "Unexpected raw device flags: %#lx\n", raw_devices[1].dwFlags); todo_wine @@ -1222,11 +1222,27 @@ static void test_mouse_keyboard(void) hr = GetRegisteredRawInputDevices(raw_devices, &raw_devices_count, sizeof(RAWINPUTDEVICE)); todo_wine ok(hr == 1, "GetRegisteredRawInputDevices returned %ld, raw_devices_count: %d\n", hr, raw_devices_count); - ok(raw_devices[0].usUsagePage == 1, "Unexpected raw device usage page: %x\n", raw_devices[0].usUsagePage); - ok(raw_devices[0].usUsage == 5, "Unexpected raw device usage: %x\n", raw_devices[0].usUsage); + ok(raw_devices[0].usUsagePage == HID_USAGE_PAGE_GENERIC, "got usUsagePage: %x\n", raw_devices[0].usUsagePage); + ok(raw_devices[0].usUsage == HID_USAGE_GENERIC_GAMEPAD, "got usUsage: %x\n", raw_devices[0].usUsage); ok(raw_devices[0].dwFlags == 0, "Unexpected raw device flags: %#lx\n", raw_devices[0].dwFlags); ok(raw_devices[0].hwndTarget == hwnd, "Unexpected raw device target: %p\n", raw_devices[0].hwndTarget);
+ raw_devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; + raw_devices[0].usUsage = HID_USAGE_GENERIC_GAMEPAD; + raw_devices[0].dwFlags = RIDEV_REMOVE; + raw_devices[0].hwndTarget = 0; + raw_devices[1].usUsagePage = HID_USAGE_PAGE_GENERIC; + raw_devices[1].usUsage = HID_USAGE_GENERIC_KEYBOARD; + raw_devices[1].dwFlags = RIDEV_REMOVE; + raw_devices[1].hwndTarget = 0; + raw_devices[2].usUsagePage = HID_USAGE_PAGE_GENERIC; + raw_devices[2].usUsage = HID_USAGE_GENERIC_MOUSE; + raw_devices[2].dwFlags = RIDEV_REMOVE; + raw_devices[2].hwndTarget = 0; + raw_devices_count = ARRAY_SIZE(raw_devices); + hr = RegisterRawInputDevices(raw_devices, raw_devices_count, sizeof(RAWINPUTDEVICE)); + ok(hr == TRUE, "RegisterRawInputDevices failed\n"); + IDirectInputDevice8_Release(di_mouse); IDirectInputDevice8_Release(di_keyboard); IDirectInput8_Release(di);
From: Rémi Bernon rbernon@codeweavers.com
They are now pretty much superseded by the more extensive tests in joystick8.c, using virtual devices. --- dlls/dinput/tests/Makefile.in | 1 - dlls/dinput/tests/joystick.c | 963 ---------------------------------- 2 files changed, 964 deletions(-) delete mode 100644 dlls/dinput/tests/joystick.c
diff --git a/dlls/dinput/tests/Makefile.in b/dlls/dinput/tests/Makefile.in index 87522c12abf..0123f86cb04 100644 --- a/dlls/dinput/tests/Makefile.in +++ b/dlls/dinput/tests/Makefile.in @@ -20,5 +20,4 @@ SOURCES = \ force_feedback.c \ hid.c \ hotplug.c \ - joystick.c \ joystick8.c diff --git a/dlls/dinput/tests/joystick.c b/dlls/dinput/tests/joystick.c deleted file mode 100644 index 1b85f13f9a7..00000000000 --- a/dlls/dinput/tests/joystick.c +++ /dev/null @@ -1,963 +0,0 @@ -/* - * Copyright (c) 2004-2005 Robert Reif - * - * 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 "ntstatus.h" -#define WIN32_NO_STATUS -#include "windef.h" -#include "winbase.h" - -#define COBJMACROS -#include "dinput.h" - -#include "dinput_test.h" - -typedef struct tagUserData { - IDirectInputA *pDI; - DWORD version; -} UserData; - -static const DIOBJECTDATAFORMAT dfDIJoystickTest[] = { - { &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_ZAxis,DIJOFS_Z,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RxAxis,DIJOFS_RX,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RyAxis,DIJOFS_RY,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_RzAxis,DIJOFS_RZ,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(0),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(1),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(2),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(3),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(4),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(5),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(6),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(7),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(8),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(9),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, - { &GUID_Button,DIJOFS_BUTTON(10),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0}, -}; - -static const DIDATAFORMAT c_dfDIJoystickTest = { - sizeof(DIDATAFORMAT), - sizeof(DIOBJECTDATAFORMAT), - DIDF_ABSAXIS, - sizeof(DIJOYSTATE2), - ARRAY_SIZE(dfDIJoystickTest), - (LPDIOBJECTDATAFORMAT)dfDIJoystickTest -}; - -static HWND get_hwnd(void) -{ - HWND hwnd=GetForegroundWindow(); - if (!hwnd) - hwnd=GetDesktopWindow(); - return hwnd; -} - -typedef struct tagJoystickInfo -{ - IDirectInputDeviceA *pJoystick; - DWORD axis; - DWORD pov; - DWORD button; - LONG lMin, lMax; - DWORD dZone; -} JoystickInfo; - -static int get_refcount(IUnknown *object) -{ - IUnknown_AddRef( object ); - return IUnknown_Release( object ); -} - -static BOOL CALLBACK EnumAxes(const DIDEVICEOBJECTINSTANCEA *pdidoi, void *pContext) -{ - HRESULT hr; - JoystickInfo * info = pContext; - - if (IsEqualIID(&pdidoi->guidType, &GUID_XAxis) || - IsEqualIID(&pdidoi->guidType, &GUID_YAxis) || - IsEqualIID(&pdidoi->guidType, &GUID_ZAxis) || - IsEqualIID(&pdidoi->guidType, &GUID_RxAxis) || - IsEqualIID(&pdidoi->guidType, &GUID_RyAxis) || - IsEqualIID(&pdidoi->guidType, &GUID_RzAxis) || - IsEqualIID(&pdidoi->guidType, &GUID_Slider)) - { - DIPROPRANGE diprg; - DIPROPDWORD dipdw; - - diprg.diph.dwSize = sizeof(DIPROPRANGE); - diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); - diprg.diph.dwHow = DIPH_BYID; - diprg.diph.dwObj = pdidoi->dwType; - - dipdw.diph.dwSize = sizeof(dipdw); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwHow = DIPH_BYID; - dipdw.diph.dwObj = pdidoi->dwType; - - hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph); - ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %#lx\n", hr); - ok(info->lMin == diprg.lMin && info->lMax == diprg.lMax, "Min/Max range invalid: " - "expected %ld..%ld got %ld..%ld\n", info->lMin, info->lMax, diprg.lMin, diprg.lMax); - - diprg.lMin = -2000; - diprg.lMax = +2000; - - hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, NULL); - ok(hr==E_INVALIDARG,"IDirectInputDevice_SetProperty() should have returned " - "E_INVALIDARG, returned: %#lx\n", hr); - - hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph); - ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %#lx\n", hr); - - /* dead zone */ - hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph); - ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %#lx\n", hr); - ok(info->dZone == dipdw.dwData, "deadzone invalid: expected %lu got %lu\n", - info->dZone, dipdw.dwData); - - dipdw.dwData = 123; - - hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph); - ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %#lx\n", hr); - - /* ensure DIDOI_ASPECTPOSITION is set for axes objects */ - ok(pdidoi->dwFlags & DIDOI_ASPECTPOSITION, "Missing DIDOI_ASPECTPOSITION, flags are %#lx\n", - pdidoi->dwFlags); - - info->axis++; - } else if (IsEqualIID(&pdidoi->guidType, &GUID_POV)) - info->pov++; - else if (IsEqualIID(&pdidoi->guidType, &GUID_Button)) - info->button++; - - return DIENUM_CONTINUE; -} - -static const struct effect_id -{ - const GUID *guid; - int dieft; - const char *name; -} effect_conversion[] = { - {&GUID_ConstantForce, DIEFT_CONSTANTFORCE, "Constant"}, - {&GUID_RampForce, DIEFT_RAMPFORCE, "Ramp"}, - {&GUID_Square, DIEFT_PERIODIC, "Square"}, - {&GUID_Sine, DIEFT_PERIODIC, "Sine"}, - {&GUID_Triangle, DIEFT_PERIODIC, "Triangle"}, - {&GUID_SawtoothUp, DIEFT_PERIODIC, "Saw Tooth Up"}, - {&GUID_SawtoothDown, DIEFT_PERIODIC, "Saw Tooth Down"}, - {&GUID_Spring, DIEFT_CONDITION, "Spring"}, - {&GUID_Damper, DIEFT_CONDITION, "Damper"}, - {&GUID_Inertia, DIEFT_CONDITION, "Inertia"}, - {&GUID_Friction, DIEFT_CONDITION, "Friction"}, - {&GUID_CustomForce, DIEFT_CUSTOMFORCE, "Custom"} -}; - -static const struct effect_id* effect_from_guid(const GUID *guid) -{ - unsigned int i; - for (i = 0; i < ARRAY_SIZE(effect_conversion); i++) - if (IsEqualGUID(guid, effect_conversion[i].guid)) - return &effect_conversion[i]; - return NULL; -} - -struct effect_enum -{ - DIEFFECT eff; - GUID guid; - int effect_count; - const char *effect_name; -}; - -/* The last enumerated effect will be used for force feedback testing */ -static BOOL CALLBACK EnumEffects(const DIEFFECTINFOA *lpef, void *ref) -{ - const struct effect_id *id = effect_from_guid(&lpef->guid); - static union - { - DICONSTANTFORCE constant; - DIPERIODIC periodic; - DIRAMPFORCE ramp; - DICONDITION condition[2]; - } specific; - struct effect_enum *data = ref; - int type = DIDFT_GETTYPE(lpef->dwEffType); - - /* Insanity check */ - if (!id) - { - ok(0, "unsupported effect enumerated, GUID %s!\n", wine_dbgstr_guid(&lpef->guid)); - return DIENUM_CONTINUE; - } - trace("controller supports '%s' effect\n", id->name); - ok(type == id->dieft, "Invalid effect type, expected %#x, got %#lx\n", - id->dieft, lpef->dwEffType); - - /* Can't use custom for test as we don't know the data format */ - if (type == DIEFT_CUSTOMFORCE) - return DIENUM_CONTINUE; - - data->effect_count++; - data->effect_name = id->name; - data->guid = *id->guid; - - ZeroMemory(&specific, sizeof(specific)); - switch (type) - { - case DIEFT_PERIODIC: - data->eff.cbTypeSpecificParams = sizeof(specific.periodic); - data->eff.lpvTypeSpecificParams = &specific.periodic; - specific.periodic.dwMagnitude = DI_FFNOMINALMAX / 2; - specific.periodic.dwPeriod = DI_SECONDS; /* 1 second */ - break; - case DIEFT_CONSTANTFORCE: - data->eff.cbTypeSpecificParams = sizeof(specific.constant); - data->eff.lpvTypeSpecificParams = &specific.constant; - specific.constant.lMagnitude = DI_FFNOMINALMAX / 2; - break; - case DIEFT_RAMPFORCE: - data->eff.cbTypeSpecificParams = sizeof(specific.ramp); - data->eff.lpvTypeSpecificParams = &specific.ramp; - specific.ramp.lStart = -DI_FFNOMINALMAX / 2; - specific.ramp.lEnd = +DI_FFNOMINALMAX / 2; - break; - case DIEFT_CONDITION: - { - int i; - data->eff.cbTypeSpecificParams = sizeof(specific.condition); - data->eff.lpvTypeSpecificParams = specific.condition; - for (i = 0; i < 2; i++) - { - specific.condition[i].lNegativeCoefficient = -DI_FFNOMINALMAX / 2; - specific.condition[i].lPositiveCoefficient = +DI_FFNOMINALMAX / 2; - } - break; - } - } - return DIENUM_CONTINUE; -} - -static const HRESULT SetCoop_null_window[16] = { - E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, - E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG, - E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG, - E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG}; - -static const HRESULT SetCoop_real_window[16] = { - E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, - E_INVALIDARG, S_OK, S_OK, E_INVALIDARG, - E_INVALIDARG, S_OK, S_OK, E_INVALIDARG, - E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG}; - -static BOOL CALLBACK EnumAllFeedback(const DIDEVICEINSTANCEA *lpddi, void *pvRef) -{ - trace("---- Device Information ----\n" - "Product Name : %s\n" - "Instance Name : %s\n" - "devType : 0x%#lx\n" - "GUID Product : %s\n" - "GUID Instance : %s\n" - "HID Page : %#04x\n" - "HID Usage : %#04x\n", - lpddi->tszProductName, - lpddi->tszInstanceName, - lpddi->dwDevType, - wine_dbgstr_guid(&lpddi->guidProduct), - wine_dbgstr_guid(&lpddi->guidInstance), - lpddi->wUsagePage, - lpddi->wUsage); - - ok(!(IsEqualGUID(&GUID_SysMouse, &lpddi->guidProduct) || IsEqualGUID(&GUID_SysKeyboard, &lpddi->guidProduct)), "Invalid device returned.\n"); - - return DIENUM_CONTINUE; -} - -static BOOL CALLBACK EnumJoysticks(const DIDEVICEINSTANCEA *lpddi, void *pvRef) -{ - HRESULT hr; - UserData * data = pvRef; - IDirectInputDeviceA *pJoystick; - DIDATAFORMAT format; - DIDEVCAPS caps; - DIJOYSTATE2 js; - JoystickInfo info; - int i, count; - ULONG ref; - DIDEVICEINSTANCEA inst; - DIDEVICEINSTANCE_DX3A inst3; - DIPROPDWORD dipw; - DIPROPSTRING dps; - DIPROPGUIDANDPATH dpg; - WCHAR nameBuffer[MAX_PATH]; - HWND hWnd = get_hwnd(); - char oldstate[248], curstate[248]; - DWORD axes[2] = {DIJOFS_X, DIJOFS_Y}; - LONG direction[2] = {0, 0}; - LPDIRECTINPUTEFFECT effect = NULL; - LONG cnt1, cnt2; - HWND real_hWnd; - DIPROPDWORD dip_gain_set, dip_gain_get; - struct effect_enum effect_data; - - ok(data->version >= 0x0300, "Joysticks not supported in version %#lx\n", data->version); - - hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, NULL, NULL); - ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned " - "E_POINTER, returned: %#lx\n", hr); - - hr = IDirectInput_CreateDevice(data->pDI, NULL, &pJoystick, NULL); - ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned " - "E_POINTER, returned: %#lx\n", hr); - - hr = IDirectInput_CreateDevice(data->pDI, NULL, NULL, NULL); - ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned " - "E_POINTER, returned: %#lx\n", hr); - - hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, - &pJoystick, NULL); - ok(hr==DI_OK,"IDirectInput_CreateDevice() failed: %#lx\n", hr); - if (hr!=DI_OK) - goto DONE; - - trace("---- Controller Information ----\n" - "Product Name : %s\n" - "Instance Name : %s\n" - "devType : 0x%#lx\n" - "GUID Product : %s\n" - "GUID Instance : %s\n" - "HID Page : %#04x\n" - "HID Usage : %#04x\n", - lpddi->tszProductName, - lpddi->tszInstanceName, - lpddi->dwDevType, - wine_dbgstr_guid(&lpddi->guidProduct), - wine_dbgstr_guid(&lpddi->guidInstance), - lpddi->wUsagePage, - lpddi->wUsage); - - /* Check if this is a HID device */ - if (lpddi->dwDevType & DIDEVTYPE_HID) - ok(lpddi->wUsagePage == 0x01 && (lpddi->wUsage == 0x04 || lpddi->wUsage == 0x05), - "Expected a game controller HID UsagePage and Usage, got page %#x usage %#x\n", - lpddi->wUsagePage, lpddi->wUsage); - - /* Test for joystick ID property */ - ZeroMemory(&dipw, sizeof(dipw)); - dipw.diph.dwSize = sizeof(DIPROPDWORD); - dipw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipw.diph.dwObj = 0; - dipw.diph.dwHow = DIPH_DEVICE; - - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_JOYSTICKID, &dipw.diph); - ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() for DIPROP_JOYSTICKID failed\n"); - - /* Test for INSTANCENAME property */ - memset(&dps, 0, sizeof(dps)); - dps.diph.dwSize = sizeof(DIPROPSTRING); - dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dps.diph.dwHow = DIPH_DEVICE; - - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_INSTANCENAME, &dps.diph); - ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_INSTANCENAME failed: %#lx\n", hr); - - /* Test if instance name is the same as present in DIDEVICEINSTANCE */ - MultiByteToWideChar(CP_ACP, 0, lpddi->tszInstanceName, -1, nameBuffer, MAX_PATH); - ok(!lstrcmpW(nameBuffer, dps.wsz), "DIPROP_INSTANCENAME returned is wrong. Expected: %s Got: %s\n", - wine_dbgstr_w(nameBuffer), wine_dbgstr_w(dps.wsz)); - - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_PRODUCTNAME, &dps.diph); - ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_PRODUCTNAME failed: %#lx\n", hr); - - /* Test if product name is the same as present in DIDEVICEINSTANCE */ - MultiByteToWideChar(CP_ACP, 0, lpddi->tszProductName, -1, nameBuffer, MAX_PATH); - ok(!lstrcmpW(nameBuffer, dps.wsz), "DIPROP_PRODUCTNAME returned is wrong. Expected: %s Got: %s\n", - wine_dbgstr_w(nameBuffer), wine_dbgstr_w(dps.wsz)); - - /* Test for GUIDPATH properties */ - memset(&dpg, 0, sizeof(dpg)); - dpg.diph.dwSize = sizeof(DIPROPGUIDANDPATH); - dpg.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dpg.diph.dwHow = DIPH_DEVICE; - - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_GUIDANDPATH, &dpg.diph); - ok(SUCCEEDED(hr), "IDirectInput_GetProperty() for DIPROP_GUIDANDPATH failed: %#lx\n", hr); - - { - int vid, pid; - - _wcslwr(dpg.wszPath); - count = swscanf(dpg.wszPath, L"\\?\%*[^#]#vid_%04x&pid_%04x", &vid, &pid); - ok(count == 2, "DIPROP_GUIDANDPATH path has wrong format. Expected count: 2 Got: %i Path: %s\n", - count, wine_dbgstr_w(dpg.wszPath)); - ok(wcsstr(dpg.wszPath, L"mi_") != 0 || wcsstr(dpg.wszPath, L"ig_") != 0, - "DIPROP_GUIDANDPATH path should contain either 'ig_' or 'mi_' substring. Path: %s\n", - wine_dbgstr_w(dpg.wszPath)); - } - - hr = IDirectInputDevice_SetDataFormat(pJoystick, NULL); - ok(hr==E_POINTER,"IDirectInputDevice_SetDataFormat() should have returned " - "E_POINTER, returned: %#lx\n", hr); - - ZeroMemory(&format, sizeof(format)); - hr = IDirectInputDevice_SetDataFormat(pJoystick, &format); - ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_SetDataFormat() should have " - "returned DIERR_INVALIDPARAM, returned: %#lx\n", hr); - - /* try the default formats */ - hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick); - ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %#lx\n", hr); - - hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2); - ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %#lx\n", hr); - - /* try an alternate format */ - hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystickTest); - ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %#lx\n", hr); - - hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2); - ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %#lx\n", hr); - if (hr != DI_OK) - goto RELEASE; - - for (i=0; i<16; i++) - { - hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, NULL, i); - ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %#lx\n", i, hr); - } - for (i=0; i<16; i++) - { - hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd, i); - ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %#lx\n", i, hr); - } - - hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd, - DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); - ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %#lx\n", hr); - - /* get capabilities */ - hr = IDirectInputDevice_GetCapabilities(pJoystick, NULL); - ok(hr==E_POINTER,"IDirectInputDevice_GetCapabilities() " - "should have returned E_POINTER, returned: %#lx\n", hr); - - ZeroMemory(&caps, sizeof(caps)); - hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps); - ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_GetCapabilities() " - "should have returned DIERR_INVALIDPARAM, returned: %#lx\n", hr); - - caps.dwSize = sizeof(caps); - hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps); - ok(hr==DI_OK,"IDirectInputDevice_GetCapabilities() failed: %#lx\n", hr); - - ZeroMemory(&info, sizeof(info)); - info.pJoystick = pJoystick; - - /* default min/max limits */ - info.lMin = 0; - info.lMax = 0xffff; - /* enumerate objects */ - hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, &info, DIDFT_ALL); - ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %#lx\n", hr); - - ok(caps.dwAxes == info.axis, "Number of enumerated axes (%ld) doesn't match capabilities (%ld)\n", info.axis, caps.dwAxes); - ok(caps.dwButtons == info.button, "Number of enumerated buttons (%ld) doesn't match capabilities (%ld)\n", info.button, caps.dwButtons); - ok(caps.dwPOVs == info.pov, "Number of enumerated POVs (%ld) doesn't match capabilities (%ld)\n", info.pov, caps.dwPOVs); - - /* Set format and check limits again */ - hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2); - ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %#lx\n", hr); - info.lMin = -2000; - info.lMax = +2000; - info.dZone= 123; - hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, &info, DIDFT_ALL); - ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %#lx\n", hr); - - hr = IDirectInputDevice_GetDeviceInfo(pJoystick, 0); - ok(hr==E_POINTER, "IDirectInputDevice_GetDeviceInfo() " - "should have returned E_POINTER, returned: %#lx\n", hr); - - ZeroMemory(&inst, sizeof(inst)); - ZeroMemory(&inst3, sizeof(inst3)); - - hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst); - ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceInfo() " - "should have returned DIERR_INVALIDPARAM, returned: %#lx\n", hr); - - inst.dwSize = sizeof(inst); - hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst); - ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %#lx\n", hr); - - inst3.dwSize = sizeof(inst3); - hr = IDirectInputDevice_GetDeviceInfo(pJoystick, (DIDEVICEINSTANCEA*)&inst3); - ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %#lx\n", hr); - - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %#lx\n", hr); - - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - if (hr != DI_OK) - goto RELEASE; - - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %#lx\n", hr); - - if (info.pov < 4) - { - hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js); - ok(hr == DI_OK, "IDirectInputDevice_GetDeviceState() failed: %#lx\n", hr); - ok(js.rgdwPOV[3] == -1, "Default for unassigned POV should be -1 not: %ld\n", js.rgdwPOV[3]); - } - - trace("Testing force feedback\n"); - ZeroMemory(&effect_data, sizeof(effect_data)); - effect_data.eff.dwSize = sizeof(effect_data.eff); - effect_data.eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; - effect_data.eff.dwDuration = INFINITE; - effect_data.eff.dwGain = DI_FFNOMINALMAX; - effect_data.eff.dwTriggerButton = DIEB_NOTRIGGER; - effect_data.eff.cAxes = ARRAY_SIZE(axes); - effect_data.eff.rgdwAxes = axes; - effect_data.eff.rglDirection = direction; - - /* Sending effects to joystick requires - * calling IDirectInputEffect_Initialize, which requires - * having exclusive access to the device, which requires - * - not having acquired the joystick when calling - * IDirectInputDevice_SetCooperativeLevel - * - a visible window - */ - real_hWnd = CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL, NULL, - instance, NULL); - ok(real_hWnd!=0,"CreateWindowExA failed: %p\n", real_hWnd); - ShowWindow(real_hWnd, SW_SHOW); - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %#lx\n", hr); - hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, real_hWnd, - DISCL_EXCLUSIVE | DISCL_FOREGROUND); - ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %#lx\n", hr); - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - - cnt1 = get_refcount((IUnknown*)pJoystick); - - hr = IDirectInputDevice2_EnumEffects((IDirectInputDevice2A*)pJoystick, EnumEffects, &effect_data, DIEFT_ALL); - ok(hr==DI_OK,"IDirectInputDevice2_EnumEffects() failed: %#lx\n", hr); - - /* If the controller does not support ANY effect use the constant effect to make - * CreateEffect fail but with the unsupported reason instead of invalid parameters. */ - if (!effect_data.effect_count) - { - static DICONSTANTFORCE constant; - effect_data.guid = GUID_ConstantForce; - effect_data.eff.cbTypeSpecificParams = sizeof(constant); - effect_data.eff.lpvTypeSpecificParams = &constant; - effect_data.effect_name = "Constant"; - constant.lMagnitude = DI_FFNOMINALMAX / 2; - - ok(!(caps.dwFlags & DIDC_FORCEFEEDBACK), "effect count is zero but controller supports force feedback?\n"); - } - - effect = (void *)0xdeadbeef; - hr = IDirectInputDevice2_CreateEffect((IDirectInputDevice2A*)pJoystick, &effect_data.guid, - &effect_data.eff, &effect, NULL); - if (caps.dwFlags & DIDC_FORCEFEEDBACK) - { - trace("force feedback supported with %d effects, using '%s' for test\n", - effect_data.effect_count, effect_data.effect_name); - ok(hr == DI_OK, "IDirectInputDevice_CreateEffect() failed: %#lx\n", hr); - cnt2 = get_refcount((IUnknown*)pJoystick); - ok(cnt1 == cnt2, "Ref count is wrong %ld != %ld\n", cnt1, cnt2); - - if (effect) - { - DWORD effect_status; - struct DIPROPDWORD diprop_word; - void *tmp; - GUID guid = {0}; - DIEFFECT effect_empty; - - hr = IDirectInputEffect_Initialize(effect, instance, data->version, - &effect_data.guid); - ok(hr==DI_OK,"IDirectInputEffect_Initialize failed: %#lx\n", hr); - - /* Test SetParameters with NULL pointers */ - tmp = effect_data.eff.rgdwAxes; - effect_data.eff.rgdwAxes = NULL; - hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_AXES); - ok(hr==DIERR_INVALIDPARAM,"IDirectInputEffect_SetParameters should fail with INVALIDPARAM, got: %#lx\n", hr); - effect_data.eff.rgdwAxes = tmp; - - tmp = effect_data.eff.rglDirection; - effect_data.eff.rglDirection = NULL; - hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_DIRECTION); - ok(hr==DIERR_INVALIDPARAM,"IDirectInputEffect_SetParameters should fail with INVALIDPARAM, got: %#lx\n", hr); - effect_data.eff.rglDirection = tmp; - - tmp = effect_data.eff.lpvTypeSpecificParams; - effect_data.eff.lpvTypeSpecificParams = NULL; - hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_TYPESPECIFICPARAMS); - ok(hr==DIERR_INVALIDPARAM,"IDirectInputEffect_SetParameters should fail with INVALIDPARAM, got: %#lx\n", hr); - effect_data.eff.lpvTypeSpecificParams = tmp; - - hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_AXES | DIEP_DIRECTION | - DIEP_TYPESPECIFICPARAMS); - ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %#lx\n", hr); - if (hr==DI_OK) { - /* Test that upload, unacquire, acquire still permits updating - * uploaded effect. */ - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %#lx\n", hr); - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - hr = IDirectInputEffect_SetParameters(effect, &effect_data.eff, DIEP_GAIN); - ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %#lx\n", hr); - } - - /* Check effect status. - * State: initially stopped - * start - * State: started - * unacquire, acquire, download - * State: stopped - * start - * State: started - * - * Shows that: - * - effects are stopped after Unacquire + Acquire - * - effects are preserved (Download + Start doesn't complain - * about incomplete effect) - */ - hr = IDirectInputEffect_GetEffectStatus(effect, NULL); - ok(hr==E_POINTER,"IDirectInputEffect_GetEffectStatus() must fail with E_POINTER, got: %#lx\n", hr); - effect_status = 0xdeadbeef; - hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %#lx\n", hr); - ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n"); - /* SetParameters with a zeroed-out DIEFFECT and flags=0 should do nothing. */ - memset(&effect_empty, 0, sizeof(effect_empty)); - effect_empty.dwSize = sizeof(effect_empty); - hr = IDirectInputEffect_SetParameters(effect, &effect_empty, 0); - ok(hr==DI_NOEFFECT,"IDirectInputEffect_SetParameters failed: %#lx\n", hr); - /* Start effect with SetParameters and a zeroed-out DIEFFECT. */ - hr = IDirectInputEffect_SetParameters(effect, &effect_empty, DIEP_START); - ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %#lx\n", hr); - todo_wine ok(effect_status!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n"); - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %#lx\n", hr); - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - hr = IDirectInputEffect_Download(effect); - ok(hr==DI_OK,"IDirectInputEffect_Download() failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %#lx\n", hr); - ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n"); - hr = IDirectInputEffect_Start(effect, 1, 0); - ok(hr==DI_OK,"IDirectInputEffect_Start() failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %#lx\n", hr); - Sleep(250); /* feel the magic */ - todo_wine ok(effect_status!=0,"IDirectInputEffect_GetEffectStatus() reported effect as stopped\n"); - hr = IDirectInputEffect_GetEffectGuid(effect, &guid); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectGuid() failed: %#lx\n", hr); - ok(IsEqualGUID(&effect_data.guid, &guid), "Wrong guid returned\n"); - - /* Check autocenter status - * State: initially stopped - * enable - * State: enabled - * acquire - * State: enabled - * unacquire - * State: enabled - * - * IDirectInputDevice2_SetProperty(DIPROP_AUTOCENTER) can only be - * executed when the device is released. - * - * If Executed interactively, user can feel that autocenter is - * only disabled when the joystick is acquired. - */ - diprop_word.diph.dwSize = sizeof(diprop_word); - diprop_word.diph.dwHeaderSize = sizeof(diprop_word.diph); - diprop_word.diph.dwObj = 0; - diprop_word.diph.dwHow = DIPH_DEVICE; - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %#lx\n", hr); - hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph); - ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %#lx\n", hr); - ok(diprop_word.dwData==DIPROPAUTOCENTER_ON,"IDirectInputDevice2_GetProperty() reported autocenter as disabled\n"); - diprop_word.dwData = DIPROPAUTOCENTER_OFF; - hr = IDirectInputDevice2_SetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph); - ok(hr==DI_OK,"IDirectInputDevice2_SetProperty() failed: %#lx\n", hr); - hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph); - ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %#lx\n", hr); - ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n"); - if (winetest_interactive) { - trace("Acquiring in 2s, autocenter will be disabled.\n"); - Sleep(2000); - } - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - if (winetest_interactive) - trace("Acquired.\n"); - hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph); - ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %#lx\n", hr); - ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n"); - if (winetest_interactive) { - trace("Releasing in 2s, autocenter will be re-enabled.\n"); - Sleep(2000); - } - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %#lx\n", hr); - if (winetest_interactive) - trace("Released\n"); - hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph); - ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %#lx\n", hr); - ok(diprop_word.dwData==DIPROPAUTOCENTER_OFF,"IDirectInputDevice2_GetProperty() reported autocenter as enabled\n"); - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - hr = IDirectInputDevice2_GetProperty(pJoystick, DIPROP_AUTOCENTER, &diprop_word.diph); - ok(hr==DI_OK,"IDirectInputDevice2_GetProperty() failed: %#lx\n", hr); - - /* Device gain (DIPROP_FFGAIN). - * From MSDN: - * 0..10000 range, otherwise DIERR_INVALIDPARAM. - * Can be changed even if device is acquired. - * Difference found by tests: - * <0 is refused, >10000 is accepted - */ - dip_gain_set.diph.dwSize = sizeof(DIPROPDWORD); - dip_gain_set.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dip_gain_set.diph.dwObj = 0; - dip_gain_set.diph.dwHow = DIPH_DEVICE; - dip_gain_get.diph.dwSize = sizeof(DIPROPDWORD); - dip_gain_get.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dip_gain_get.diph.dwObj = 0; - dip_gain_get.diph.dwHow = DIPH_DEVICE; - dip_gain_get.dwData = 0; - - /* Test device is acquisition (non)impact. */ - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr == DI_OK, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %#lx\n", hr); - dip_gain_set.dwData = 1; - hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph); - ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %#lx\n", hr); - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph); - ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %#lx\n", hr); - ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %lu\n", dip_gain_get.dwData); - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - dip_gain_set.dwData = 2; - hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph); - ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %#lx\n", hr); - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph); - ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %#lx\n", hr); - ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %lu\n", dip_gain_get.dwData); - /* Test range and internal clamping. */ - dip_gain_set.dwData = -1; - hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph); - todo_wine ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_SetProperty() should have returned %#lx: %#lx\n", DIERR_INVALIDPARAM, hr); - dip_gain_set.dwData = 0; - hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph); - ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %#lx\n", hr); - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph); - ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %#lx\n", hr); - ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %lu\n", dip_gain_get.dwData); - dip_gain_set.dwData = 10000; - hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph); - ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %#lx\n", hr); - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph); - ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %#lx\n", hr); - ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %lu\n", dip_gain_get.dwData); - /* WARNING: This call succeeds, on the contrary of what is stated on MSDN. */ - dip_gain_set.dwData = 10001; - hr = IDirectInputDevice_SetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_set.diph); - ok(hr==DI_OK, "IDirectInputDevice_SetProperty() failed: %#lx\n", hr); - hr = IDirectInputDevice_GetProperty(pJoystick, DIPROP_FFGAIN, &dip_gain_get.diph); - ok(hr==DI_OK, "IDirectInputDevice_GetProperty() failed: %#lx\n", hr); - ok(dip_gain_get.dwData==dip_gain_set.dwData, "Gain not updated: %lu\n", dip_gain_get.dwData); - - /* Test SendForceFeedbackCommand - * DISFFC_STOPALL - Should stop effects only - * DISFFC_RESET - Should stop effects and unload them (NOT release them) - * Tests for game Odallus (bug 41623) */ - hr = IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A*)pJoystick, 0); - ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_SendForceFeedbackCommand() failed: %#lx\n", hr); - hr = IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A*)pJoystick, 0xFF); - ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_SendForceFeedbackCommand() failed: %#lx\n", hr); - - hr = IDirectInputEffect_Download(effect); - ok(hr==DI_OK,"IDirectInputEffect_Download() failed: %#lx\n", hr); - - /* Send STOPALL and prove that the effect can still be started */ - hr = IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A*)pJoystick, DISFFC_STOPALL); - ok(hr==DI_OK, "IDirectInputDevice_SendForceFeedbackCommand() failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %#lx\n", hr); - ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n"); - hr = IDirectInputEffect_Start(effect, 1, 0); - ok(hr==DI_OK,"IDirectInputEffect_Start() failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectGuid(effect, &guid); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectGuid() failed: %#lx\n", hr); - ok(IsEqualGUID(&effect_data.guid, &guid), "Wrong guid returned\n"); - - /* Send RESET and prove that we can still manipulate the effect, thus not released */ - hr = IDirectInputDevice2_SendForceFeedbackCommand((IDirectInputDevice2A*)pJoystick, DISFFC_RESET); - ok(hr==DI_OK, "IDirectInputDevice_SendForceFeedbackCommand() failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status); - ok(hr==DIERR_NOTDOWNLOADED,"IDirectInputEffect_GetEffectStatus() failed: %#lx\n", hr); - hr = IDirectInputEffect_Download(effect); - ok(hr==DI_OK,"IDirectInputEffect_Download() failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectStatus(effect, &effect_status); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectStatus() failed: %#lx\n", hr); - ok(effect_status==0,"IDirectInputEffect_GetEffectStatus() reported effect as started\n"); - hr = IDirectInputEffect_Start(effect, 1, 0); - ok(hr==DI_OK,"IDirectInputEffect_Start() failed: %#lx\n", hr); - hr = IDirectInputEffect_GetEffectGuid(effect, &guid); - ok(hr==DI_OK,"IDirectInputEffect_GetEffectGuid() failed: %#lx\n", hr); - ok(IsEqualGUID(&effect_data.guid, &guid), "Wrong guid returned\n"); - - ref = IUnknown_Release(effect); - ok(ref == 0, "IDirectInputDevice_Release() reference count = %ld\n", ref); - } - cnt1 = get_refcount((IUnknown*)pJoystick); - ok(cnt1 == cnt2, "Ref count is wrong %ld != %ld\n", cnt1, cnt2); - } - /* No force feedback support, CreateEffect is supposed to fail. Fairy Bloom Freesia - * calls CreateEffect without checking the DIDC_FORCEFEEDBACK. It expects the correct - * error return to determine if force feedback is unsupported. */ - else - { - trace("No force feedback support\n"); - ok(hr==DIERR_UNSUPPORTED, "IDirectInputDevice_CreateEffect() must fail with DIERR_UNSUPPORTED, got: %#lx\n", hr); - ok(effect == NULL, "effect must be NULL, got %p\n", effect); - } - - /* Before destroying the window, release joystick to revert to - * non-exclusive, background cooperative level. */ - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %#lx\n", hr); - hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd, - DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); - ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %#lx\n", hr); - DestroyWindow (real_hWnd); - hr = IDirectInputDevice_Acquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %#lx\n", hr); - - if (winetest_interactive) { - trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n"); - count = 300; - } else - count = 1; - - trace("\n"); - oldstate[0]='\0'; - for (i = 0; i < count; i++) { - hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js); - ok(hr==DI_OK,"IDirectInputDevice_GetDeviceState() failed: %#lx\n", hr); - if (hr != DI_OK) - break; - sprintf(curstate, "X%5ld Y%5ld Z%5ld Rx%5ld Ry%5ld Rz%5ld " - "S0%5ld S1%5ld POV0%5ld POV1%5ld POV2%5ld POV3%5ld " - "B %d %d %d %d %d %d %d %d %d %d %d %d\n", - js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz, - js.rglSlider[0], js.rglSlider[1], - js.rgdwPOV[0], js.rgdwPOV[1], js.rgdwPOV[2], js.rgdwPOV[3], - js.rgbButtons[0]>>7, js.rgbButtons[1]>>7, js.rgbButtons[2]>>7, - js.rgbButtons[3]>>7, js.rgbButtons[4]>>7, js.rgbButtons[5]>>7, - js.rgbButtons[6]>>7, js.rgbButtons[7]>>7, js.rgbButtons[8]>>7, - js.rgbButtons[9]>>7, js.rgbButtons[10]>>7, js.rgbButtons[11]>>7); - if (strcmp(oldstate, curstate) != 0) - { - trace("%s\n", curstate); - strcpy(oldstate, curstate); - } - Sleep(100); - } - trace("\n"); - - hr = IDirectInputDevice_Unacquire(pJoystick); - ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %#lx\n", hr); - -RELEASE: - ref = IDirectInputDevice_Release(pJoystick); - ok(ref==0,"IDirectInputDevice_Release() reference count = %ld\n", ref); - -DONE: - return DIENUM_CONTINUE; -} - -static void joystick_tests(DWORD version) -{ - HRESULT hr; - IDirectInputA *pDI; - ULONG ref; - - trace("-- Testing Direct Input Version %#lx --\n", version); - hr = DirectInputCreateA(instance, version, &pDI, NULL); - ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION, "DirectInputCreateA() failed: %#lx\n", hr); - if (hr==DI_OK && pDI!=0) { - UserData data; - data.pDI = pDI; - data.version = version; - hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks, - &data, DIEDFL_ALLDEVICES); - ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %#lx\n", hr); - ref = IDirectInput_Release(pDI); - ok(ref==0,"IDirectInput_Release() reference count = %ld\n", ref); - } else if (hr==DIERR_OLDDIRECTINPUTVERSION) - trace(" Version Not Supported\n"); -} - -static void test_enum_feedback(void) -{ - HRESULT hr; - IDirectInputA *pDI; - ULONG ref; - - hr = DirectInputCreateA(instance, 0x0700, &pDI, NULL); - ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION, "DirectInputCreateA() failed: %#lx\n", hr); - if (hr==DI_OK && pDI!=0) { - hr = IDirectInput_EnumDevices(pDI, 0, EnumAllFeedback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK); - ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %#lx\n", hr); - ref = IDirectInput_Release(pDI); - ok(ref==0,"IDirectInput_Release() reference count = %ld\n", ref); - } else if (hr==DIERR_OLDDIRECTINPUTVERSION) - trace(" Version Not Supported\n"); -} - -START_TEST(joystick) -{ - dinput_test_init(); - - joystick_tests(0x0700); - joystick_tests(0x0500); - joystick_tests(0x0300); - - test_enum_feedback(); - - dinput_test_exit(); -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/tests/force_feedback.c | 3 +- dlls/dinput/tests/hid.c | 87 ++++++++++++++++++------------ dlls/dinput/tests/hotplug.c | 45 ++++++++++------ dlls/dinput/tests/joystick8.c | 10 ++-- 4 files changed, 90 insertions(+), 55 deletions(-)
diff --git a/dlls/dinput/tests/force_feedback.c b/dlls/dinput/tests/force_feedback.c index b841e4bb8c7..120324a41a9 100644 --- a/dlls/dinput/tests/force_feedback.c +++ b/dlls/dinput/tests/force_feedback.c @@ -5793,7 +5793,8 @@ static void test_windows_gaming_input(void) fill_context( desc.context, ARRAY_SIZE(desc.context) );
if (!hid_device_start( &desc )) goto done; - WaitForSingleObject( controller_added.event, INFINITE ); + ret = WaitForSingleObject( controller_added.event, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); CloseHandle( controller_added.event );
if (FAILED(hr = dinput_test_create_device( 0x800, &devinst, &device ))) goto done; diff --git a/dlls/dinput/tests/hid.c b/dlls/dinput/tests/hid.c index 667e335c631..6bb69d195cd 100644 --- a/dlls/dinput/tests/hid.c +++ b/dlls/dinput/tests/hid.c @@ -710,35 +710,40 @@ BOOL bus_device_start(void) void hid_device_stop( struct hid_device_desc *desc ) { HANDLE control; - BOOL ret; + DWORD ret;
ResetEvent( device_removed );
control = CreateFileW( L"\\?\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}", 0, 0, NULL, OPEN_EXISTING, 0, NULL ); ok( control != INVALID_HANDLE_VALUE, "CreateFile failed, error %lu\n", GetLastError() ); - ret = sync_ioctl( control, IOCTL_WINETEST_REMOVE_DEVICE, desc, sizeof(*desc), NULL, 0, INFINITE ); + ret = sync_ioctl( control, IOCTL_WINETEST_REMOVE_DEVICE, desc, sizeof(*desc), NULL, 0, 5000 ); ok( ret || GetLastError() == ERROR_FILE_NOT_FOUND, "IOCTL_WINETEST_REMOVE_DEVICE failed, last error %lu\n", GetLastError() ); CloseHandle( control );
- if (ret) WaitForSingleObject( device_removed, INFINITE ); + if (ret) + { + ret = WaitForSingleObject( device_removed, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + } }
BOOL hid_device_start( struct hid_device_desc *desc ) { HANDLE control; - BOOL ret; + DWORD ret;
ResetEvent( device_added );
control = CreateFileW( L"\\?\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}", 0, 0, NULL, OPEN_EXISTING, 0, NULL ); ok( control != INVALID_HANDLE_VALUE, "CreateFile failed, error %lu\n", GetLastError() ); - ret = sync_ioctl( control, IOCTL_WINETEST_CREATE_DEVICE, desc, sizeof(*desc), NULL, 0, INFINITE ); + ret = sync_ioctl( control, IOCTL_WINETEST_CREATE_DEVICE, desc, sizeof(*desc), NULL, 0, 5000 ); ok( ret, "IOCTL_WINETEST_CREATE_DEVICE failed, last error %lu\n", GetLastError() ); CloseHandle( control );
- WaitForSingleObject( device_added, INFINITE ); + ret = WaitForSingleObject( device_added, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret );
return TRUE; } @@ -889,13 +894,14 @@ BOOL sync_ioctl_( const char *file, int line, HANDLE device, DWORD code, void *i if (!ret && GetLastError() == ERROR_IO_PENDING) { res = WaitForSingleObject( ovl.hEvent, timeout ); - ok_(file, line)( res == WAIT_OBJECT_0, "WaitForSingleObject returned %#lx\n", res ); + ok_(file, line)( !res, "WaitForSingleObject returned %#lx\n", res ); ret = GetOverlappedResult( device, &ovl, &out_len, FALSE ); ok_(file, line)( ret, "GetOverlappedResult returned %lu\n", GetLastError() ); if (!ret) { CancelIoEx( device, &ovl ); - WaitForSingleObject( ovl.hEvent, timeout ); + res = WaitForSingleObject( ovl.hEvent, timeout ); + ok_(file, line)( !res, "WaitForSingleObject returned %#lx\n", res ); } } CloseHandle( ovl.hEvent ); @@ -926,14 +932,14 @@ void set_hid_expect_( const char *file, int line, HANDLE device, struct hid_devi
fill_context_( file, line, buffer + sizeof(*desc), ARRAY_SIZE(buffer) - sizeof(*desc) ); size = sizeof(*desc) + strlen( buffer + sizeof(*desc) ) + 1; - ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, buffer, size, NULL, 0, INFINITE ); + ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, buffer, size, NULL, 0, 5000 ); ok_(file, line)( ret, "IOCTL_WINETEST_HID_SET_CONTEXT failed, last error %lu\n", GetLastError() );
if (expect) memcpy( buffer + sizeof(*desc), expect, expect_size ); else memset( buffer + sizeof(*desc), 0, expect_size );
size = sizeof(*desc) + expect_size; - ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_EXPECT, buffer, size, NULL, 0, INFINITE ); + ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_EXPECT, buffer, size, NULL, 0, 5000 ); ok_(file, line)( ret, "IOCTL_WINETEST_HID_SET_EXPECT failed, last error %lu\n", GetLastError() ); }
@@ -970,14 +976,14 @@ void send_hid_input_( const char *file, int line, HANDLE device, struct hid_devi
fill_context_( file, line, buffer + sizeof(*desc), ARRAY_SIZE(buffer) - sizeof(*desc) ); size = sizeof(*desc) + strlen( buffer + sizeof(*desc) ) + 1; - ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, buffer, size, NULL, 0, INFINITE ); + ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SET_CONTEXT, buffer, size, NULL, 0, 5000 ); ok_(file, line)( ret, "IOCTL_WINETEST_HID_SET_CONTEXT failed, last error %lu\n", GetLastError() );
if (expect) memcpy( buffer + sizeof(*desc), expect, expect_size ); else memset( buffer + sizeof(*desc), 0, expect_size );
size = sizeof(*desc) + expect_size; - ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SEND_INPUT, buffer, size, NULL, 0, INFINITE ); + ret = sync_ioctl_( file, line, device, IOCTL_WINETEST_HID_SEND_INPUT, buffer, size, NULL, 0, 5000 ); ok_(file, line)( ret, "IOCTL_WINETEST_HID_SEND_INPUT failed, last error %lu\n", GetLastError() ); }
@@ -1067,7 +1073,7 @@ static void test_hidp_get_input( HANDLE file, int report_id, ULONG report_len, P
SetLastError( 0xdeadbeef ); length = report_len * 2; - ret = sync_ioctl( file, IOCTL_HID_GET_INPUT_REPORT, NULL, 0, report, &length, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_GET_INPUT_REPORT, NULL, 0, report, &length, 5000 ); ok( ret, "IOCTL_HID_GET_INPUT_REPORT failed, last error %lu\n", GetLastError() ); ok( length == 3, "got length %lu, expected 3\n", length ); ok( report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id ); @@ -1161,7 +1167,7 @@ static void test_hidp_get_feature( HANDLE file, int report_id, ULONG report_len,
length = report_len * 2; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_GET_FEATURE, NULL, 0, report, &length, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_GET_FEATURE, NULL, 0, report, &length, 5000 ); ok( ret, "IOCTL_HID_GET_FEATURE failed, last error %lu\n", GetLastError() ); ok( length == 3, "got length %lu, expected 3\n", length ); ok( report[0] == report_id, "got report[0] %02x, expected %02x\n", report[0], report_id ); @@ -1258,13 +1264,13 @@ static void test_hidp_set_feature( HANDLE file, int report_id, ULONG report_len,
length = report_len * 2; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_FEATURE, NULL, 0, report, &length, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_FEATURE, NULL, 0, report, &length, 5000 ); ok( !ret, "IOCTL_HID_SET_FEATURE succeeded\n" ); ok( GetLastError() == ERROR_INVALID_USER_BUFFER, "IOCTL_HID_SET_FEATURE returned error %lu\n", GetLastError() ); length = 0; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_FEATURE, report, report_len * 2, NULL, &length, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_FEATURE, report, report_len * 2, NULL, &length, 5000 ); ok( ret, "IOCTL_HID_SET_FEATURE failed, last error %lu\n", GetLastError() ); ok( length == 3, "got length %lu, expected 3\n", length );
@@ -1353,13 +1359,13 @@ static void test_hidp_set_output( HANDLE file, int report_id, ULONG report_len,
length = report_len * 2; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_OUTPUT_REPORT, NULL, 0, report, &length, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_OUTPUT_REPORT, NULL, 0, report, &length, 5000 ); ok( !ret, "IOCTL_HID_SET_OUTPUT_REPORT succeeded\n" ); ok( GetLastError() == ERROR_INVALID_USER_BUFFER, "IOCTL_HID_SET_OUTPUT_REPORT returned error %lu\n", GetLastError() ); length = 0; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_OUTPUT_REPORT, report, report_len * 2, NULL, &length, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_OUTPUT_REPORT, report, report_len * 2, NULL, &length, 5000 ); ok( ret, "IOCTL_HID_SET_OUTPUT_REPORT failed, last error %lu\n", GetLastError() ); ok( length == 3, "got length %lu, expected 3\n", length );
@@ -2443,7 +2449,7 @@ static void test_hidp( HANDLE file, HANDLE async_file, int report_id, BOOL polle
value = 10; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &value, sizeof(ULONG), NULL, NULL, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &value, sizeof(ULONG), NULL, NULL, 5000 ); ok( ret, "IOCTL_HID_SET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() );
Sleep( 600 ); @@ -2597,14 +2603,18 @@ static void test_hid_device( DWORD report_id, DWORD polled, const HIDP_CAPS *exp ULONG count, poll_freq, out_len; WCHAR device_path[MAX_PATH]; HANDLE file, async_file; - BOOL ret; + DWORD ret;
winetest_push_context( "id %ld%s", report_id, polled ? " poll" : "" );
/* Win7 has a spurious device removal event with polled HID devices */ if (!polled || !strcmp(winetest_platform, "wine")) ret = WAIT_TIMEOUT; else ret = WaitForSingleObject( device_removed, 2000 ); - if (!ret && InterlockedOr( &device_added_count, 0 ) == 1) WaitForSingleObject( device_added, INFINITE ); + if (!ret && InterlockedOr( &device_added_count, 0 ) == 1) + { + ret = WaitForSingleObject( device_added, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + }
swprintf( device_path, MAX_PATH, L"\\?\hid#vid_%04x&pid_%04x", vid, pid ); ret = find_hid_device_path( device_path ); @@ -2671,7 +2681,7 @@ static void test_hid_device( DWORD report_id, DWORD polled, const HIDP_CAPS *exp { out_len = sizeof(ULONG); SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_GET_POLL_FREQUENCY_MSEC, NULL, 0, &poll_freq, &out_len, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_GET_POLL_FREQUENCY_MSEC, NULL, 0, &poll_freq, &out_len, 5000 ); ok( ret, "IOCTL_HID_GET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() ); ok( out_len == sizeof(ULONG), "got out_len %lu, expected sizeof(ULONG)\n", out_len ); todo_wine @@ -2680,27 +2690,27 @@ static void test_hid_device( DWORD report_id, DWORD polled, const HIDP_CAPS *exp out_len = 0; poll_freq = 500; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, 5000 ); ok( ret, "IOCTL_HID_SET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() ); ok( out_len == 0, "got out_len %lu, expected 0\n", out_len );
out_len = 0; poll_freq = 10001; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, 5000 ); ok( ret, "IOCTL_HID_SET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() ); ok( out_len == 0, "got out_len %lu, expected 0\n", out_len );
out_len = 0; poll_freq = 0; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, 5000 ); ok( ret, "IOCTL_HID_SET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() ); ok( out_len == 0, "got out_len %lu, expected 0\n", out_len );
out_len = sizeof(ULONG); SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_GET_POLL_FREQUENCY_MSEC, NULL, 0, &poll_freq, &out_len, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_GET_POLL_FREQUENCY_MSEC, NULL, 0, &poll_freq, &out_len, 5000 ); ok( ret, "IOCTL_HID_GET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() ); ok( out_len == sizeof(ULONG), "got out_len %lu, expected sizeof(ULONG)\n", out_len ); ok( poll_freq == 10000, "got poll_freq %lu, expected 10000\n", poll_freq ); @@ -2708,13 +2718,13 @@ static void test_hid_device( DWORD report_id, DWORD polled, const HIDP_CAPS *exp out_len = 0; poll_freq = 500; SetLastError( 0xdeadbeef ); - ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, INFINITE ); + ret = sync_ioctl( file, IOCTL_HID_SET_POLL_FREQUENCY_MSEC, &poll_freq, sizeof(ULONG), NULL, &out_len, 5000 ); ok( ret, "IOCTL_HID_SET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() ); ok( out_len == 0, "got out_len %lu, expected 0\n", out_len );
out_len = sizeof(ULONG); SetLastError( 0xdeadbeef ); - ret = sync_ioctl( async_file, IOCTL_HID_GET_POLL_FREQUENCY_MSEC, NULL, 0, &poll_freq, &out_len, INFINITE ); + ret = sync_ioctl( async_file, IOCTL_HID_GET_POLL_FREQUENCY_MSEC, NULL, 0, &poll_freq, &out_len, 5000 ); ok( ret, "IOCTL_HID_GET_POLL_FREQUENCY_MSEC failed last error %lu\n", GetLastError() ); ok( out_len == sizeof(ULONG), "got out_len %lu, expected sizeof(ULONG)\n", out_len ); ok( poll_freq == 500, "got poll_freq %lu, expected 500\n", poll_freq ); @@ -3609,13 +3619,16 @@ void dinput_test_init_( const char *file, int line )
void dinput_test_exit(void) { + DWORD ret; + UnmapViewOfFile( test_data ); CloseHandle( test_data_mapping ); CloseHandle( okfile ); DeleteFileW( L"C:\windows\winetest_dinput_okfile" );
SetEvent( monitor_stop ); - WaitForSingleObject( monitor_thread, INFINITE ); + ret = WaitForSingleObject( monitor_thread, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); CloseHandle( monitor_thread ); CloseHandle( monitor_stop ); CloseHandle( device_removed ); @@ -3747,13 +3760,15 @@ DWORD WINAPI dinput_test_device_thread( void *stop_event ) .caps = caps, .attributes = attributes, }; + DWORD ret;
desc.report_descriptor_len = sizeof(gamepad_desc); memcpy( desc.report_descriptor_buf, gamepad_desc, sizeof(gamepad_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
hid_device_start( &desc ); - WaitForSingleObject( stop_event, INFINITE ); + ret = WaitForSingleObject( stop_event, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); hid_device_stop( &desc );
return 0; @@ -3796,7 +3811,7 @@ static void test_bus_driver(void)
WCHAR device_path[MAX_PATH]; HANDLE control; - BOOL ret; + DWORD ret;
if (!bus_device_start()) goto done;
@@ -3821,10 +3836,11 @@ static void test_bus_driver(void) control = CreateFileW( L"\\?\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}", 0, 0, NULL, OPEN_EXISTING, 0, NULL ); ok( control != INVALID_HANDLE_VALUE, "CreateFile failed, error %lu\n", GetLastError() ); - ret = sync_ioctl( control, IOCTL_WINETEST_CREATE_DEVICE, &desc, sizeof(desc), NULL, 0, INFINITE ); + ret = sync_ioctl( control, IOCTL_WINETEST_CREATE_DEVICE, &desc, sizeof(desc), NULL, 0, 5000 ); ok( ret, "IOCTL_WINETEST_CREATE_DEVICE failed, last error %lu\n", GetLastError() );
- WaitForSingleObject( device_added, INFINITE ); + ret = WaitForSingleObject( device_added, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret );
swprintf( device_path, MAX_PATH, L"\\?\hid#vid_%04x&pid_%04x", LOWORD(EXPECT_VIDPID), HIWORD(EXPECT_VIDPID) ); ret = find_hid_device_path( device_path ); @@ -3832,11 +3848,12 @@ static void test_bus_driver(void)
ResetEvent( device_removed );
- ret = sync_ioctl( control, IOCTL_WINETEST_REMOVE_DEVICE, &desc, sizeof(desc), NULL, 0, INFINITE ); + ret = sync_ioctl( control, IOCTL_WINETEST_REMOVE_DEVICE, &desc, sizeof(desc), NULL, 0, 5000 ); ok( ret, "IOCTL_WINETEST_REMOVE_DEVICE failed, last error %lu\n", GetLastError() ); CloseHandle( control );
- WaitForSingleObject( device_removed, INFINITE ); + ret = WaitForSingleObject( device_removed, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret );
done: bus_device_stop(); diff --git a/dlls/dinput/tests/hotplug.c b/dlls/dinput/tests/hotplug.c index 78e38b1e285..e9231be26f3 100644 --- a/dlls/dinput/tests/hotplug.c +++ b/dlls/dinput/tests/hotplug.c @@ -75,10 +75,10 @@ failed:
static DWORD wait_for_events( DWORD count, HANDLE *events, DWORD timeout ) { - DWORD ret, end = GetTickCount() + timeout; + DWORD ret, end = GetTickCount() + min( timeout, 5000 ); MSG msg;
- while ((ret = MsgWaitForMultipleObjects( count, events, FALSE, timeout, QS_ALLINPUT )) <= count) + while ((ret = MsgWaitForMultipleObjects( count, events, FALSE, min( timeout, 5000 ), QS_ALLINPUT )) <= count) { while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) { @@ -86,12 +86,13 @@ static DWORD wait_for_events( DWORD count, HANDLE *events, DWORD timeout ) DispatchMessageW( &msg ); } if (ret < count) return ret; - if (timeout == INFINITE) continue; + if (timeout >= 5000) continue; if (end <= GetTickCount()) timeout = 0; else timeout = end - GetTickCount(); }
- ok( ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %#lx\n", ret ); + if (timeout >= 5000) ok( 0, "MsgWaitForMultipleObjects returned %#lx\n", ret ); + else ok( ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %#lx\n", ret ); return ret; }
@@ -312,6 +313,7 @@ static void test_RegisterDeviceNotification(void) DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)buffer; HANDLE hwnd, thread, stop_event; HDEVNOTIFY devnotify; + DWORD ret; MSG msg;
RegisterClassExW( &class ); @@ -394,7 +396,9 @@ static void test_RegisterDeviceNotification(void)
while (device_change_count < device_change_expect) { - MsgWaitForMultipleObjects( 0, NULL, FALSE, INFINITE, QS_ALLINPUT ); + ret = MsgWaitForMultipleObjects( 0, NULL, FALSE, 5000, QS_ALLINPUT ); + ok( !ret, "MsgWaitForMultipleObjects returned %#lx\n", ret ); + if (ret) break; while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) { TranslateMessage( &msg ); @@ -404,7 +408,8 @@ static void test_RegisterDeviceNotification(void) if (device_change_count == device_change_expect / 2) SetEvent( stop_event ); }
- WaitForSingleObject( thread, INFINITE ); + ret = WaitForSingleObject( thread, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); CloseHandle( thread ); CloseHandle( stop_event );
@@ -428,7 +433,9 @@ static void test_RegisterDeviceNotification(void)
while (device_change_count < device_change_expect) { - MsgWaitForMultipleObjects( 0, NULL, FALSE, INFINITE, QS_ALLINPUT ); + ret = MsgWaitForMultipleObjects( 0, NULL, FALSE, 5000, QS_ALLINPUT ); + ok( !ret, "MsgWaitForMultipleObjects returned %#lx\n", ret ); + if (ret) break; while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) { TranslateMessage( &msg ); @@ -438,7 +445,8 @@ static void test_RegisterDeviceNotification(void) if (device_change_count == device_change_expect / 2) SetEvent( stop_event ); }
- WaitForSingleObject( thread, INFINITE ); + ret = WaitForSingleObject( thread, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); CloseHandle( thread ); CloseHandle( stop_event );
@@ -459,7 +467,9 @@ static void test_RegisterDeviceNotification(void)
while (device_change_count < device_change_expect) { - MsgWaitForMultipleObjects( 0, NULL, FALSE, INFINITE, QS_ALLINPUT ); + ret = MsgWaitForMultipleObjects( 0, NULL, FALSE, 5000, QS_ALLINPUT ); + ok( !ret, "MsgWaitForMultipleObjects returned %#lx\n", ret ); + if (ret) break; while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) { TranslateMessage( &msg ); @@ -469,7 +479,8 @@ static void test_RegisterDeviceNotification(void) if (device_change_count == device_change_expect / 2) SetEvent( stop_event ); }
- WaitForSingleObject( thread, INFINITE ); + ret = WaitForSingleObject( thread, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); CloseHandle( thread ); CloseHandle( stop_event );
@@ -1036,7 +1047,7 @@ static void test_windows_gaming_input(void) thread = CreateThread( NULL, 0, dinput_test_device_thread, stop_event, 0, NULL ); ok( !!thread, "CreateThread failed, error %lu\n", GetLastError() );
- wait_for_events( 1, &controller_added.event, INFINITE ); + wait_for_events( 1, &controller_added.event, 5000 );
ok( controller_added.invoked, "controller added handler not invoked\n" ); ok( !controller_removed.invoked, "controller removed handler invoked\n" ); @@ -1073,7 +1084,7 @@ static void test_windows_gaming_input(void) IRawGameController_Release( raw_controller );
SetEvent( stop_event ); - wait_for_events( 1, &controller_removed.event, INFINITE ); + wait_for_events( 1, &controller_removed.event, 5000 );
ok( controller_added.invoked, "controller added handler not invoked\n" ); ok( controller_removed.invoked, "controller removed handler not invoked\n" ); @@ -1113,7 +1124,8 @@ static void test_windows_gaming_input(void)
IVectorView_RawGameController_Release( controller_view );
- WaitForSingleObject( thread, INFINITE ); + res = WaitForSingleObject( thread, 5000 ); + ok( !res, "WaitForSingleObject returned %#lx\n", res ); CloseHandle( thread ); while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
@@ -1134,7 +1146,7 @@ static void test_windows_gaming_input(void)
thread = CreateThread( NULL, 0, dinput_test_device_thread, stop_event, 0, NULL ); ok( !!thread, "CreateThread failed, error %lu\n", GetLastError() ); - wait_for_events( 1, &controller_added.event, INFINITE ); + wait_for_events( 1, &controller_added.event, 5000 ); res = wait_for_events( 1, &custom_factory.added_event, 500 ); todo_wine ok( !res, "wait_for_events returned %#lx\n", res ); @@ -1185,7 +1197,7 @@ next: res = wait_for_events( 1, &custom_factory.removed_event, 500 ); todo_wine ok( !res, "wait_for_events returned %#lx\n", res ); - wait_for_events( 1, &controller_removed.event, INFINITE ); + wait_for_events( 1, &controller_removed.event, 5000 );
hr = IRawGameControllerStatics_remove_RawGameControllerAdded( statics, controller_added_token ); ok( hr == S_OK, "remove_RawGameControllerAdded returned %#lx\n", hr ); @@ -1199,7 +1211,8 @@ next: IGameControllerFactoryManagerStatics2_Release( manager_statics2 ); IGameControllerFactoryManagerStatics_Release( manager_statics ); IRawGameControllerStatics_Release( statics ); - WaitForSingleObject( thread, INFINITE ); + res = WaitForSingleObject( thread, 5000 ); + ok( !res, "WaitForSingleObject returned %#lx\n", res ); CloseHandle( thread ); CloseHandle( stop_event );
diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 49f7c1a201e..f62fe3f1925 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -3925,6 +3925,7 @@ static void test_windows_gaming_input(void) UINT32 size; HSTRING str; HRESULT hr; + DWORD res;
if (!load_combase_functions()) return;
@@ -3964,7 +3965,8 @@ static void test_windows_gaming_input(void) fill_context( desc.context, ARRAY_SIZE(desc.context) );
if (!hid_device_start( &desc )) goto done; - WaitForSingleObject( controller_added.event, INFINITE ); + res = WaitForSingleObject( controller_added.event, 5000 ); + ok( !res, "WaitForSingleObject returned %#lx\n", res ); CloseHandle( controller_added.event );
hr = IVectorView_RawGameController_get_Size( controllers_view, &size ); @@ -4047,7 +4049,8 @@ static void test_windows_gaming_input(void) ok( controller_added_token.value, "got token %I64u\n", controller_added_token.value );
if (!hid_device_start( &desc )) goto done; - WaitForSingleObject( controller_added.event, INFINITE ); + res = WaitForSingleObject( controller_added.event, 5000 ); + ok( !res, "WaitForSingleObject returned %#lx\n", res ); CloseHandle( controller_added.event );
hr = IRawGameControllerStatics_get_RawGameControllers( controller_statics, &controllers_view ); @@ -4343,7 +4346,8 @@ static void test_rawinput(void)
send_hid_input( file, &injected_input[i], sizeof(*injected_input) );
- MsgWaitForMultipleObjects( 0, NULL, FALSE, INFINITE, QS_ALLINPUT ); + res = MsgWaitForMultipleObjects( 0, NULL, FALSE, 5000, QS_ALLINPUT ); + ok( !res, "MsgWaitForMultipleObjects returned %#lx\n", res ); while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
ok( !wm_input_device_change_count, "got %u WM_INPUT_DEVICE_CHANGE\n", wm_input_device_change_count );
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/tests/dinput_test.h | 3 ++ dlls/dinput/tests/hotplug.c | 22 +++++----- dlls/dinput/tests/joystick8.c | 78 ++++++++++++++++++++++----------- 3 files changed, 67 insertions(+), 36 deletions(-)
diff --git a/dlls/dinput/tests/dinput_test.h b/dlls/dinput/tests/dinput_test.h index 94c3df3710c..eb01d473f01 100644 --- a/dlls/dinput/tests/dinput_test.h +++ b/dlls/dinput/tests/dinput_test.h @@ -109,4 +109,7 @@ void wait_hid_expect_( const char *file, int line, HANDLE device, struct hid_dev void send_hid_input_( const char *file, int line, HANDLE device, struct hid_device_desc *desc, struct hid_expect *expect, DWORD expect_size );
+#define msg_wait_for_events( a, b, c ) msg_wait_for_events_( __FILE__, __LINE__, a, b, c ) +DWORD msg_wait_for_events_( const char *file, int line, DWORD count, HANDLE *events, DWORD timeout ); + #endif /* __WINE_DINPUT_TEST_H */ diff --git a/dlls/dinput/tests/hotplug.c b/dlls/dinput/tests/hotplug.c index e9231be26f3..bfef5d119ad 100644 --- a/dlls/dinput/tests/hotplug.c +++ b/dlls/dinput/tests/hotplug.c @@ -73,7 +73,7 @@ failed: return FALSE; }
-static DWORD wait_for_events( DWORD count, HANDLE *events, DWORD timeout ) +DWORD msg_wait_for_events_( const char *file, int line, DWORD count, HANDLE *events, DWORD timeout ) { DWORD ret, end = GetTickCount() + min( timeout, 5000 ); MSG msg; @@ -91,8 +91,8 @@ static DWORD wait_for_events( DWORD count, HANDLE *events, DWORD timeout ) else timeout = end - GetTickCount(); }
- if (timeout >= 5000) ok( 0, "MsgWaitForMultipleObjects returned %#lx\n", ret ); - else ok( ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %#lx\n", ret ); + if (timeout >= 5000) ok_(file, line)( 0, "MsgWaitForMultipleObjects returned %#lx\n", ret ); + else ok_(file, line)( ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %#lx\n", ret ); return ret; }
@@ -1047,7 +1047,7 @@ static void test_windows_gaming_input(void) thread = CreateThread( NULL, 0, dinput_test_device_thread, stop_event, 0, NULL ); ok( !!thread, "CreateThread failed, error %lu\n", GetLastError() );
- wait_for_events( 1, &controller_added.event, 5000 ); + msg_wait_for_events( 1, &controller_added.event, 5000 );
ok( controller_added.invoked, "controller added handler not invoked\n" ); ok( !controller_removed.invoked, "controller removed handler invoked\n" ); @@ -1084,7 +1084,7 @@ static void test_windows_gaming_input(void) IRawGameController_Release( raw_controller );
SetEvent( stop_event ); - wait_for_events( 1, &controller_removed.event, 5000 ); + msg_wait_for_events( 1, &controller_removed.event, 5000 );
ok( controller_added.invoked, "controller added handler not invoked\n" ); ok( controller_removed.invoked, "controller removed handler not invoked\n" ); @@ -1146,10 +1146,10 @@ static void test_windows_gaming_input(void)
thread = CreateThread( NULL, 0, dinput_test_device_thread, stop_event, 0, NULL ); ok( !!thread, "CreateThread failed, error %lu\n", GetLastError() ); - wait_for_events( 1, &controller_added.event, 5000 ); - res = wait_for_events( 1, &custom_factory.added_event, 500 ); + msg_wait_for_events( 1, &controller_added.event, 5000 ); + res = msg_wait_for_events( 1, &custom_factory.added_event, 500 ); todo_wine - ok( !res, "wait_for_events returned %#lx\n", res ); + ok( !res, "msg_wait_for_events returned %#lx\n", res ); hr = IRawGameControllerStatics_get_RawGameControllers( statics, &controller_view ); ok( hr == S_OK, "get_RawGameControllers returned %#lx\n", hr ); hr = IVectorView_RawGameController_GetAt( controller_view, 0, &raw_controller ); @@ -1194,10 +1194,10 @@ next: IGameController_Release( game_controller ); IRawGameController_Release( raw_controller ); SetEvent( stop_event ); - res = wait_for_events( 1, &custom_factory.removed_event, 500 ); + res = msg_wait_for_events( 1, &custom_factory.removed_event, 500 ); todo_wine - ok( !res, "wait_for_events returned %#lx\n", res ); - wait_for_events( 1, &controller_removed.event, 5000 ); + ok( !res, "msg_wait_for_events returned %#lx\n", res ); + msg_wait_for_events( 1, &controller_removed.event, 5000 );
hr = IRawGameControllerStatics_remove_RawGameControllerAdded( statics, controller_added_token ); ok( hr == S_OK, "remove_RawGameControllerAdded returned %#lx\n", hr ); diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index f62fe3f1925..999da74a406 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -4102,8 +4102,7 @@ done: cleanup_registry_keys(); }
-static BOOL wm_input_device_change_count; -static BOOL wm_input_count; +static HANDLE rawinput_device_added, rawinput_device_removed, rawinput_event; static char wm_input_buf[1024]; static UINT wm_input_len;
@@ -4111,12 +4110,16 @@ static LRESULT CALLBACK rawinput_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LP { UINT size = sizeof(wm_input_buf);
- if (msg == WM_INPUT_DEVICE_CHANGE) wm_input_device_change_count++; + if (msg == WM_INPUT_DEVICE_CHANGE) + { + if (wparam == GIDC_ARRIVAL) ReleaseSemaphore( rawinput_device_added, 1, NULL ); + else ReleaseSemaphore( rawinput_device_removed, 1, NULL ); + } if (msg == WM_INPUT) { - wm_input_count++; wm_input_len = GetRawInputData( (HRAWINPUT)lparam, RID_INPUT, (RAWINPUT *)wm_input_buf, &size, sizeof(RAWINPUTHEADER) ); + ReleaseSemaphore( rawinput_event, 1, NULL ); }
return DefWindowProcW( hwnd, msg, wparam, lparam ); @@ -4223,7 +4226,6 @@ static void test_rawinput(void) UINT count; HWND hwnd; BOOL ret; - MSG msg;
RegisterClassExW( &class );
@@ -4233,6 +4235,13 @@ static void test_rawinput(void) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
+ rawinput_device_added = CreateSemaphoreW( NULL, 0, LONG_MAX, NULL ); + ok( !!rawinput_device_added, "CreateSemaphoreW failed, error %lu\n", GetLastError() ); + rawinput_device_removed = CreateSemaphoreW( NULL, 0, LONG_MAX, NULL ); + ok( !!rawinput_device_removed, "CreateSemaphoreW failed, error %lu\n", GetLastError() ); + rawinput_event = CreateSemaphoreW( NULL, 0, LONG_MAX, NULL ); + ok( !!rawinput_event, "CreateSemaphoreW failed, error %lu\n", GetLastError() ); + hwnd = CreateWindowW( class.lpszClassName, L"dinput", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 200, 200, NULL, NULL, NULL, NULL ); ok( !!hwnd, "CreateWindowW failed, error %lu\n", GetLastError() ); @@ -4257,10 +4266,12 @@ static void test_rawinput(void) todo_wine ok( count == ARRAY_SIZE(raw_devices), "got count %u\n", count );
- - while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg ); - ok( !wm_input_device_change_count, "got %u WM_INPUT_DEVICE_CHANGE\n", wm_input_device_change_count ); - ok( !wm_input_count, "got %u WM_INPUT\n", wm_input_count ); + res = msg_wait_for_events( 1, &rawinput_device_added, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_device_removed, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_event, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res );
raw_devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; raw_devices[0].usUsage = HID_USAGE_GENERIC_GAMEPAD; @@ -4272,9 +4283,12 @@ static void test_rawinput(void)
hid_device_stop( &desc );
- while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg ); - ok( !wm_input_device_change_count, "got %u WM_INPUT_DEVICE_CHANGE\n", wm_input_device_change_count ); - ok( !wm_input_count, "got %u WM_INPUT\n", wm_input_count ); + res = msg_wait_for_events( 1, &rawinput_device_added, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_device_removed, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_event, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res );
raw_devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; raw_devices[0].usUsage = HID_USAGE_GENERIC_JOYSTICK; @@ -4286,10 +4300,15 @@ static void test_rawinput(void)
hid_device_start( &desc );
- while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg ); - ok( wm_input_device_change_count == 1, "got %u WM_INPUT_DEVICE_CHANGE\n", wm_input_device_change_count ); - ok( !wm_input_count, "got %u WM_INPUT\n", wm_input_count ); - wm_input_device_change_count = 0; + res = msg_wait_for_events( 1, &rawinput_device_added, 1000 ); + ok( !res, "WaitForSingleObject returned %#lx\n", res ); + + res = msg_wait_for_events( 1, &rawinput_device_added, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_device_removed, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_event, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res );
raw_devices[0].usUsagePage = HID_USAGE_PAGE_GENERIC; raw_devices[0].usUsage = HID_USAGE_GENERIC_JOYSTICK; @@ -4302,9 +4321,12 @@ static void test_rawinput(void) hid_device_stop( &desc ); hid_device_start( &desc );
- while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg ); - ok( !wm_input_device_change_count, "got %u WM_INPUT_DEVICE_CHANGE\n", wm_input_device_change_count ); - ok( !wm_input_count, "got %u WM_INPUT\n", wm_input_count ); + res = msg_wait_for_events( 1, &rawinput_device_added, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_device_removed, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_event, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res );
count = ARRAY_SIZE(raw_device_list); @@ -4346,21 +4368,27 @@ static void test_rawinput(void)
send_hid_input( file, &injected_input[i], sizeof(*injected_input) );
- res = MsgWaitForMultipleObjects( 0, NULL, FALSE, 5000, QS_ALLINPUT ); - ok( !res, "MsgWaitForMultipleObjects returned %#lx\n", res ); - while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg ); + res = msg_wait_for_events( 1, &rawinput_event, 1000 ); + ok( !res, "WaitForSingleObject returned %#lx\n", res ); + + res = msg_wait_for_events( 1, &rawinput_device_added, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_device_removed, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); + res = msg_wait_for_events( 1, &rawinput_event, 10 ); + ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res );
- ok( !wm_input_device_change_count, "got %u WM_INPUT_DEVICE_CHANGE\n", wm_input_device_change_count ); - ok( wm_input_count == 1, "got %u WM_INPUT\n", wm_input_count ); ok( wm_input_len == offsetof(RAWINPUT, data.hid.bRawData[desc.caps.InputReportByteLength]), "got wm_input_len %u\n", wm_input_len ); ok( !memcmp( rawinput->data.hid.bRawData, injected_input[i].report_buf, desc.caps.InputReportByteLength ), "got unexpected report data\n" ); - wm_input_count = 0;
winetest_pop_context(); }
+ CloseHandle( rawinput_device_added ); + CloseHandle( rawinput_device_removed ); + CloseHandle( rawinput_event ); CloseHandle( file );
done:
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/tests/dinput_test.h | 4 +-- dlls/dinput/tests/force_feedback.c | 12 ++++----- dlls/dinput/tests/hid.c | 20 +++++++-------- dlls/dinput/tests/hotplug.c | 8 +++--- dlls/dinput/tests/joystick8.c | 40 +++++++++++++++--------------- 5 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/dlls/dinput/tests/dinput_test.h b/dlls/dinput/tests/dinput_test.h index eb01d473f01..a5b02b98a3e 100644 --- a/dlls/dinput/tests/dinput_test.h +++ b/dlls/dinput/tests/dinput_test.h @@ -54,8 +54,8 @@ extern HANDLE device_added, device_removed; extern HINSTANCE instance; extern BOOL localized; /* object names get translated */
-BOOL hid_device_start( struct hid_device_desc *desc ); -void hid_device_stop( struct hid_device_desc *desc ); +BOOL hid_device_start( struct hid_device_desc *desc, UINT count ); +void hid_device_stop( struct hid_device_desc *desc, UINT count ); BOOL bus_device_start(void); void bus_device_stop(void);
diff --git a/dlls/dinput/tests/force_feedback.c b/dlls/dinput/tests/force_feedback.c index 120324a41a9..4e6f8dfc8d4 100644 --- a/dlls/dinput/tests/force_feedback.c +++ b/dlls/dinput/tests/force_feedback.c @@ -2926,7 +2926,7 @@ static BOOL test_force_feedback_joystick( DWORD version ) memcpy( desc.report_descriptor_buf, report_descriptor, sizeof(report_descriptor) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; if (FAILED(hr = dinput_test_create_device( version, &devinst, &device ))) goto done;
check_dinput_devices( version, &devinst ); @@ -3130,7 +3130,7 @@ static BOOL test_force_feedback_joystick( DWORD version ) CloseHandle( file );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); winetest_pop_context();
@@ -4047,7 +4047,7 @@ static void test_device_managed_effect(void) memcpy( desc.expect, expect_pool, sizeof(expect_pool) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; if (FAILED(hr = dinput_test_create_device( DIRECTINPUT_VERSION, &devinst, &device ))) goto done;
hr = IDirectInputDevice8_GetProperty( device, DIPROP_GUIDANDPATH, &prop_guid_path.diph ); @@ -4456,7 +4456,7 @@ static void test_device_managed_effect(void) CloseHandle( file );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); winetest_pop_context(); } @@ -5792,7 +5792,7 @@ static void test_windows_gaming_input(void) memcpy( desc.expect, expect_init, sizeof(expect_init) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; ret = WaitForSingleObject( controller_added.event, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); CloseHandle( controller_added.event ); @@ -6491,7 +6491,7 @@ static void test_windows_gaming_input(void) IRawGameControllerStatics_Release( controller_statics );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); }
diff --git a/dlls/dinput/tests/hid.c b/dlls/dinput/tests/hid.c index 6bb69d195cd..a2b76953596 100644 --- a/dlls/dinput/tests/hid.c +++ b/dlls/dinput/tests/hid.c @@ -707,7 +707,7 @@ BOOL bus_device_start(void) return ret || GetLastError() == ERROR_SERVICE_ALREADY_RUNNING; }
-void hid_device_stop( struct hid_device_desc *desc ) +void hid_device_stop( struct hid_device_desc *desc, UINT count ) { HANDLE control; DWORD ret; @@ -728,7 +728,7 @@ void hid_device_stop( struct hid_device_desc *desc ) } }
-BOOL hid_device_start( struct hid_device_desc *desc ) +BOOL hid_device_start( struct hid_device_desc *desc, UINT count ) { HANDLE control; DWORD ret; @@ -3044,8 +3044,8 @@ static void test_hid_driver( DWORD report_id, DWORD polled ) memcpy( desc.input, &expect_in, sizeof(expect_in) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (hid_device_start( &desc )) test_hid_device( report_id, polled, &caps, desc.attributes.VendorID, desc.attributes.ProductID ); - hid_device_stop( &desc ); + if (hid_device_start( &desc, 1 )) test_hid_device( report_id, polled, &caps, desc.attributes.VendorID, desc.attributes.ProductID ); + hid_device_stop( &desc, 1 ); }
/* undocumented HID internal preparsed data structure */ @@ -3455,7 +3455,7 @@ static void test_hidp_kdr(void) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done;
swprintf( device_path, MAX_PATH, L"\\?\hid#vid_%04x&pid_%04x", desc.attributes.VendorID, desc.attributes.ProductID ); @@ -3472,7 +3472,7 @@ static void test_hidp_kdr(void) CloseHandle( file );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); }
void cleanup_registry_keys(void) @@ -3766,10 +3766,10 @@ DWORD WINAPI dinput_test_device_thread( void *stop_event ) memcpy( desc.report_descriptor_buf, gamepad_desc, sizeof(gamepad_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- hid_device_start( &desc ); + hid_device_start( &desc, 1 ); ret = WaitForSingleObject( stop_event, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 );
return 0; } @@ -4011,7 +4011,7 @@ static void test_hid_multiple_tlc(void) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 2 )) goto done;
swprintf( device_path, MAX_PATH, L"\\?\hid#vid_%04x&pid_%04x&col01", desc.attributes.VendorID, desc.attributes.ProductID ); @@ -4045,7 +4045,7 @@ static void test_hid_multiple_tlc(void) ok( !ret, "Failed to find HID device matching %s\n", debugstr_w( device_path ) );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 2 ); }
START_TEST( hid ) diff --git a/dlls/dinput/tests/hotplug.c b/dlls/dinput/tests/hotplug.c index bfef5d119ad..63cc152fa20 100644 --- a/dlls/dinput/tests/hotplug.c +++ b/dlls/dinput/tests/hotplug.c @@ -168,7 +168,7 @@ static BOOL test_input_lost( DWORD version ) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; if (FAILED(hr = dinput_test_create_device( version, &devinst, &device ))) goto done;
hr = IDirectInputDevice8_SetDataFormat( device, &c_dfDIJoystick2 ); @@ -188,7 +188,7 @@ static BOOL test_input_lost( DWORD version ) ok( hr == DI_OK, "GetDeviceData returned %#lx\n", hr ); ok( count == 0, "got %lu expected 0\n", count );
- hid_device_stop( &desc ); + hid_device_stop( &desc, 1 );
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state ); ok( hr == DIERR_INPUTLOST, "GetDeviceState returned %#lx\n", hr ); @@ -209,7 +209,7 @@ static BOOL test_input_lost( DWORD version ) ok( hr == DI_NOEFFECT, "Unacquire returned: %#lx\n", hr );
fill_context( desc.context, ARRAY_SIZE(desc.context) ); - hid_device_start( &desc ); + hid_device_start( &desc, 1 );
hr = IDirectInputDevice8_Acquire( device ); ok( hr == S_OK, "Acquire returned %#lx\n", hr ); @@ -220,7 +220,7 @@ static BOOL test_input_lost( DWORD version ) ok( ref == 0, "Release returned %ld\n", ref );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys();
winetest_pop_context(); diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 999da74a406..5232c7da0fd 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -814,7 +814,7 @@ static void test_simple_joystick( DWORD version ) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; if (FAILED(hr = dinput_test_create_device( version, &devinst, &device ))) goto done;
check_dinput_devices( version, &devinst ); @@ -2064,7 +2064,7 @@ static void test_simple_joystick( DWORD version ) CloseHandle( file );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); winetest_pop_context(); } @@ -2566,7 +2566,7 @@ static BOOL test_device_types( DWORD version ) memcpy( desc.report_descriptor_buf, device_desc[i].report_desc_buf, device_desc[i].report_desc_len ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) + if (!hid_device_start( &desc, 1 )) { success = FALSE; goto done; @@ -2607,7 +2607,7 @@ static BOOL test_device_types( DWORD version ) ok( ref == 0, "Release returned %ld\n", ref );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); winetest_pop_context(); } @@ -3036,7 +3036,7 @@ static void test_many_axes_joystick(void) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; if (FAILED(hr = dinput_test_create_device( DIRECTINPUT_VERSION, &devinst, &device ))) goto done;
check_dinput_devices( DIRECTINPUT_VERSION, &devinst ); @@ -3133,7 +3133,7 @@ static void test_many_axes_joystick(void) ok( ref == 0, "Release returned %ld\n", ref );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); winetest_pop_context(); } @@ -3305,7 +3305,7 @@ static void test_driving_wheel_axes(void) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; if (FAILED(hr = dinput_test_create_device( DIRECTINPUT_VERSION, &devinst, &device ))) goto done;
check_dinput_devices( DIRECTINPUT_VERSION, &devinst ); @@ -3353,7 +3353,7 @@ static void test_driving_wheel_axes(void) ok( ref == 0, "Release returned %ld\n", ref );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); winetest_pop_context(); } @@ -3541,7 +3541,7 @@ static BOOL test_winmm_joystick(void) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done;
ret = joyGetNumDevs(); ok( ret == 16, "joyGetNumDevs returned %u\n", ret ); @@ -3713,7 +3713,7 @@ static BOOL test_winmm_joystick(void) CloseHandle( file );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys();
return device != NULL; @@ -3964,7 +3964,7 @@ static void test_windows_gaming_input(void) memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) ); fill_context( desc.context, ARRAY_SIZE(desc.context) );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; res = WaitForSingleObject( controller_added.event, 5000 ); ok( !res, "WaitForSingleObject returned %#lx\n", res ); CloseHandle( controller_added.event ); @@ -4033,7 +4033,7 @@ static void test_windows_gaming_input(void) hr = IRawGameControllerStatics_remove_RawGameControllerAdded( controller_statics, controller_added_token ); ok( hr == S_OK, "remove_RawGameControllerAdded returned %#lx\n", hr );
- hid_device_stop( &desc ); + hid_device_stop( &desc, 1 );
desc.report_descriptor_len = sizeof(wheel_threepedals_desc); @@ -4048,7 +4048,7 @@ static void test_windows_gaming_input(void) ok( hr == S_OK, "add_RawGameControllerAdded returned %#lx\n", hr ); ok( controller_added_token.value, "got token %I64u\n", controller_added_token.value );
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done; res = WaitForSingleObject( controller_added.event, 5000 ); ok( !res, "WaitForSingleObject returned %#lx\n", res ); CloseHandle( controller_added.event ); @@ -4098,7 +4098,7 @@ static void test_windows_gaming_input(void) IRawGameControllerStatics_Release( controller_statics );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys(); }
@@ -4258,7 +4258,7 @@ static void test_rawinput(void) ok( count == ARRAY_SIZE(raw_device_list), "got count %u\n", count ); device_count = res;
- if (!hid_device_start( &desc )) goto done; + if (!hid_device_start( &desc, 1 )) goto done;
count = ARRAY_SIZE(raw_devices); res = GetRegisteredRawInputDevices( raw_devices, &count, sizeof(RAWINPUTDEVICE) ); @@ -4281,7 +4281,7 @@ static void test_rawinput(void) ret = RegisterRawInputDevices( raw_devices, 1, sizeof(RAWINPUTDEVICE) ); ok( ret, "RegisterRawInputDevices failed, error %lu\n", GetLastError() );
- hid_device_stop( &desc ); + hid_device_stop( &desc, 1 );
res = msg_wait_for_events( 1, &rawinput_device_added, 10 ); ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); @@ -4298,7 +4298,7 @@ static void test_rawinput(void) ret = RegisterRawInputDevices( raw_devices, 1, sizeof(RAWINPUTDEVICE) ); ok( ret, "RegisterRawInputDevices failed, error %lu\n", GetLastError() );
- hid_device_start( &desc ); + hid_device_start( &desc, 1 );
res = msg_wait_for_events( 1, &rawinput_device_added, 1000 ); ok( !res, "WaitForSingleObject returned %#lx\n", res ); @@ -4318,8 +4318,8 @@ static void test_rawinput(void) ret = RegisterRawInputDevices( raw_devices, 1, sizeof(RAWINPUTDEVICE) ); ok( ret, "RegisterRawInputDevices failed, error %lu\n", GetLastError() );
- hid_device_stop( &desc ); - hid_device_start( &desc ); + hid_device_stop( &desc, 1 ); + hid_device_start( &desc, 1 );
res = msg_wait_for_events( 1, &rawinput_device_added, 10 ); ok( res == WAIT_TIMEOUT, "WaitForSingleObject returned %#lx\n", res ); @@ -4392,7 +4392,7 @@ static void test_rawinput(void) CloseHandle( file );
done: - hid_device_stop( &desc ); + hid_device_stop( &desc, 1 ); cleanup_registry_keys();
DestroyWindow( hwnd );
From: Rémi Bernon rbernon@codeweavers.com
Wine-Bug: https://bugs.winehq.org//show_bug.cgi?id=53525 --- dlls/dinput/tests/dinput_test.h | 1 - dlls/dinput/tests/hid.c | 64 +++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/dlls/dinput/tests/dinput_test.h b/dlls/dinput/tests/dinput_test.h index a5b02b98a3e..e25314f6224 100644 --- a/dlls/dinput/tests/dinput_test.h +++ b/dlls/dinput/tests/dinput_test.h @@ -50,7 +50,6 @@ extern const GUID expect_guid_product; extern const WCHAR expect_path[]; extern const WCHAR expect_path_end[];
-extern HANDLE device_added, device_removed; extern HINSTANCE instance; extern BOOL localized; /* object names get translated */
diff --git a/dlls/dinput/tests/hid.c b/dlls/dinput/tests/hid.c index a2b76953596..5200892e95b 100644 --- a/dlls/dinput/tests/hid.c +++ b/dlls/dinput/tests/hid.c @@ -74,8 +74,7 @@ const WCHAR expect_vidpid_str[] = L"VID_1209&PID_0001"; const GUID expect_guid_product = {EXPECT_VIDPID, 0x0000, 0x0000, {0x00, 0x00, 'P', 'I', 'D', 'V', 'I', 'D'}}; const WCHAR expect_path[] = L"\\?\hid#vid_1209&pid_0001#2&"; const WCHAR expect_path_end[] = L"&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"; -HANDLE device_added, device_removed; -static LONG device_added_count; +static HANDLE device_added, device_removed;
static struct winetest_shared_data *test_data; static HANDLE monitor_thread, monitor_stop; @@ -710,9 +709,7 @@ BOOL bus_device_start(void) void hid_device_stop( struct hid_device_desc *desc, UINT count ) { HANDLE control; - DWORD ret; - - ResetEvent( device_removed ); + DWORD ret, i;
control = CreateFileW( L"\\?\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}", 0, 0, NULL, OPEN_EXISTING, 0, NULL ); @@ -721,9 +718,15 @@ void hid_device_stop( struct hid_device_desc *desc, UINT count ) ok( ret || GetLastError() == ERROR_FILE_NOT_FOUND, "IOCTL_WINETEST_REMOVE_DEVICE failed, last error %lu\n", GetLastError() ); CloseHandle( control );
- if (ret) + if (!ret) return; + + ret = WaitForSingleObject( device_removed, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + + for (i = 0; i < count; ++i) { - ret = WaitForSingleObject( device_removed, 5000 ); + ret = WaitForSingleObject( device_removed, i > 0 ? 500 : 5000 ); + todo_wine_if(i > 0) ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); } } @@ -731,9 +734,7 @@ void hid_device_stop( struct hid_device_desc *desc, UINT count ) BOOL hid_device_start( struct hid_device_desc *desc, UINT count ) { HANDLE control; - DWORD ret; - - ResetEvent( device_added ); + DWORD ret, i;
control = CreateFileW( L"\\?\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}", 0, 0, NULL, OPEN_EXISTING, 0, NULL ); @@ -745,6 +746,15 @@ BOOL hid_device_start( struct hid_device_desc *desc, UINT count ) ret = WaitForSingleObject( device_added, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret );
+ if (ret) return FALSE; + + for (i = 0; i < count; ++i) + { + ret = WaitForSingleObject( device_added, 1000 ); + todo_wine_if(i > 0) + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + } + return TRUE; }
@@ -2609,8 +2619,7 @@ static void test_hid_device( DWORD report_id, DWORD polled, const HIDP_CAPS *exp
/* Win7 has a spurious device removal event with polled HID devices */ if (!polled || !strcmp(winetest_platform, "wine")) ret = WAIT_TIMEOUT; - else ret = WaitForSingleObject( device_removed, 2000 ); - if (!ret && InterlockedOr( &device_added_count, 0 ) == 1) + else if (!(ret = WaitForSingleObject( device_removed, 2000 ))) { ret = WaitForSingleObject( device_added, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); @@ -3513,13 +3522,14 @@ static LRESULT CALLBACK monitor_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LPA if (msg == WM_DEVICECHANGE) { DEV_BROADCAST_DEVICEINTERFACE_W *iface = (DEV_BROADCAST_DEVICEINTERFACE_W *)lparam; - if (wparam == DBT_DEVICEREMOVECOMPLETE && IsEqualGUID( &iface->dbcc_classguid, &control_class )) - SetEvent( device_removed ); - if (wparam == DBT_DEVICEARRIVAL && IsEqualGUID( &iface->dbcc_classguid, &GUID_DEVINTERFACE_HID )) - { - InterlockedIncrement( &device_added_count ); - SetEvent( device_added ); - } + + if (!IsEqualGUID( &iface->dbcc_classguid, &control_class ) && !IsEqualGUID( &iface->dbcc_classguid, &GUID_DEVINTERFACE_HID )) + return DefWindowProcW( hwnd, msg, wparam, lparam ); + if (!wcsnicmp( iface->dbcc_name, L"\\?\root#winetest", 17 )) + return DefWindowProcW( hwnd, msg, wparam, lparam ); + + if (wparam == DBT_DEVICEREMOVECOMPLETE) ReleaseSemaphore( device_removed, 1, NULL ); + if (wparam == DBT_DEVICEARRIVAL) ReleaseSemaphore( device_added, 1, NULL ); }
return DefWindowProcW( hwnd, msg, wparam, lparam ); @@ -3572,10 +3582,10 @@ void dinput_test_init_( const char *file, int line )
monitor_stop = CreateEventW( NULL, FALSE, FALSE, NULL ); ok_(file, line)( !!monitor_stop, "CreateEventW failed, error %lu\n", GetLastError() ); - device_added = CreateEventW( NULL, FALSE, FALSE, NULL ); - ok_(file, line)( !!device_added, "CreateEventW failed, error %lu\n", GetLastError() ); - device_removed = CreateEventW( NULL, FALSE, FALSE, NULL ); - ok_(file, line)( !!device_removed, "CreateEventW failed, error %lu\n", GetLastError() ); + device_added = CreateSemaphoreW( NULL, 0, LONG_MAX, NULL ); + ok_(file, line)( !!device_added, "CreateSemaphoreW failed, error %lu\n", GetLastError() ); + device_removed = CreateSemaphoreW( NULL, 0, LONG_MAX, NULL ); + ok_(file, line)( !!device_removed, "CreateSemaphoreW failed, error %lu\n", GetLastError() ); monitor_thread = CreateThread( NULL, 0, monitor_thread_proc, monitor_stop, 0, NULL ); ok_(file, line)( !!monitor_thread, "CreateThread failed, error %lu\n", GetLastError() );
@@ -3831,8 +3841,6 @@ static void test_bus_driver(void) desc.report_descriptor_len = sizeof(report_desc); memcpy( desc.report_descriptor_buf, report_desc, sizeof(report_desc) );
- ResetEvent( device_added ); - control = CreateFileW( L"\\?\root#winetest#0#{deadbeef-29ef-4538-a5fd-b69573a362c0}", 0, 0, NULL, OPEN_EXISTING, 0, NULL ); ok( control != INVALID_HANDLE_VALUE, "CreateFile failed, error %lu\n", GetLastError() ); @@ -3841,19 +3849,21 @@ static void test_bus_driver(void)
ret = WaitForSingleObject( device_added, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + ret = WaitForSingleObject( device_added, 1000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret );
swprintf( device_path, MAX_PATH, L"\\?\hid#vid_%04x&pid_%04x", LOWORD(EXPECT_VIDPID), HIWORD(EXPECT_VIDPID) ); ret = find_hid_device_path( device_path ); ok( ret, "Failed to find HID device matching %s\n", debugstr_w(device_path) );
- ResetEvent( device_removed ); - ret = sync_ioctl( control, IOCTL_WINETEST_REMOVE_DEVICE, &desc, sizeof(desc), NULL, 0, 5000 ); ok( ret, "IOCTL_WINETEST_REMOVE_DEVICE failed, last error %lu\n", GetLastError() ); CloseHandle( control );
ret = WaitForSingleObject( device_removed, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + ret = WaitForSingleObject( device_removed, 1000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret );
done: bus_device_stop();
v5: Welp, goto / label weren't unnecessary, let's keep them. Sorry for the noise.