From: Vibhav Pant vibhavp@gmail.com
--- dlls/dinput/tests/Makefile.in | 2 +- dlls/dinput/tests/hotplug.c | 200 ++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 1 deletion(-)
diff --git a/dlls/dinput/tests/Makefile.in b/dlls/dinput/tests/Makefile.in index 608b817e0f4..c40300e619b 100644 --- a/dlls/dinput/tests/Makefile.in +++ b/dlls/dinput/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = dinput.dll -IMPORTS = dinput dinput8 ole32 version user32 advapi32 hid uuid crypt32 newdev setupapi wintrust winmm +IMPORTS = dinput dinput8 ole32 version user32 advapi32 hid uuid crypt32 newdev setupapi wintrust winmm cfgmgr32
driver_bus_IMPORTS = winecrt0 ntoskrnl hal driver_bus_EXTRADLLFLAGS = -nodefaultlibs -nostartfiles -Wl,--subsystem,native diff --git a/dlls/dinput/tests/hotplug.c b/dlls/dinput/tests/hotplug.c index f7199d2b17e..28b7cee71c1 100644 --- a/dlls/dinput/tests/hotplug.c +++ b/dlls/dinput/tests/hotplug.c @@ -34,6 +34,7 @@ #include "dbt.h" #include "unknwn.h" #include "winstring.h" +#include "cfgmgr32.h"
#include "wine/hid.h"
@@ -279,6 +280,7 @@ static const union device_change_event static const union device_change_event *device_change_expect_event; static HANDLE device_change_expect_handle; static HDEVNOTIFY handle_devnotify; +static HCMNOTIFICATION handle_cmnotify;
static LRESULT CALLBACK devnotify_wndproc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { @@ -365,6 +367,110 @@ static LRESULT CALLBACK devnotify_wndproc( HWND hwnd, UINT msg, WPARAM wparam, L return DefWindowProcW( hwnd, msg, wparam, lparam ); }
+struct cm_notify_callback_data +{ + HCMNOTIFICATION hnotify; + DWORD device_change_expect; + DWORD device_change_expect_custom; + BOOL device_change_all; + + DWORD device_change_count; + HANDLE device_change_sem; + + BOOL received_deviceremovalcomplete; +}; + +static CALLBACK DWORD cm_notify_callback( HCMNOTIFICATION hnotify, void *ctx, CM_NOTIFY_ACTION action, + CM_NOTIFY_EVENT_DATA *data, DWORD size ) +{ + struct cm_notify_callback_data *cb_data = ctx; + + switch (action) + { + case CM_NOTIFY_ACTION_DEVICECUSTOMEVENT: + { + const union device_change_event *event; + SIZE_T idx; + + ok( hnotify == handle_cmnotify, "%p != %p\n", hnotify, handle_cmnotify ); + ok( !!cb_data->device_change_expect_custom, "unexpected event\n" ); + idx = (ARRAY_SIZE(device_change_events) + 1) - cb_data->device_change_expect_custom; + event = &device_change_events[idx]; + + winetest_push_context("%Id", idx); + ok( IsEqualGUID( &data->u.DeviceHandle.EventGuid, &event->Event ), "got DeviceHandle.EventGuid %s\n", + debugstr_guid( &data->u.DeviceHandle.EventGuid )); + ok( data->u.DeviceHandle.NameOffset == event->NameBufferOffset, "got DeviceHandle.NameOffset %ld\n", + data->u.DeviceHandle.NameOffset ); + ok( data->u.DeviceHandle.DataSize == + event->Size - offsetof(TARGET_DEVICE_CUSTOM_NOTIFICATION, CustomDataBuffer[0]), + "got DeviceHandle.DataSize %ld\n", data->u.DeviceHandle.DataSize ); + ok( !memcmp( data->u.DeviceHandle.Data, event->CustomDataBuffer, data->u.DeviceHandle.DataSize ), + "Unexpected DeviceHandle.Data\n" ); + winetest_pop_context(); + ok( ReleaseSemaphore( cb_data->device_change_sem, 1, NULL ), "ReleaseSemaphore failed, error %lu\n", + GetLastError() ); + cb_data->device_change_expect_custom--; + cb_data->device_change_count++; + break; + } + case CM_NOTIFY_ACTION_DEVICEREMOVECOMPLETE: + ok( cb_data->device_change_expect_custom, "Unexpected CM_NOTIFY_ACTION_DEVICEREMOVECOMPLETE\n" ); + cb_data->received_deviceremovalcomplete = TRUE; + ok( ReleaseSemaphore( cb_data->device_change_sem, 1, NULL ), "ReleaseSemaphore failed, error %lu\n", + GetLastError() ); + break; + case CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL: + case CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL: + { + GUID expect_guid; + const WCHAR *expect_prefix, *name, *upper_end, *name_end; + + ok( hnotify == cb_data->hnotify, "%p != %p\n", hnotify, cb_data->hnotify ); + name = data->u.DeviceInterface.SymbolicLink; + if (cb_data->device_change_all && (!cb_data->device_change_count || cb_data->device_change_count == 3)) + { + expect_guid = control_class; + expect_prefix = L"\\?\WINETEST#"; + } + else + { + expect_guid = GUID_DEVINTERFACE_HID; + expect_prefix = L"\\?\HID#"; + } + + winetest_push_context( "%lu", cb_data->device_change_count ); + ok( IsEqualGUID( &data->u.DeviceInterface.ClassGuid, &expect_guid ), + "got u.DeviceInterface.ClassGuid %s\n", debugstr_guid( &data->u.DeviceInterface.ClassGuid )); + ok( !wcsncmp( name, expect_prefix, wcslen( expect_prefix ) ), "got u.DeviceInterface.SymbolicLink %s\n", + debugstr_w( name )); + upper_end = wcschr( name + wcslen( expect_prefix ), '#' ); + name_end = name + wcslen( name ) + 1; + ok( !!upper_end, "got u.DeviceInterface.SymbolicLink %s\n", debugstr_w( name ) ); + ok( all_upper( name, upper_end ), "got u.DeviceInterface.SymbolicLink %s\n", debugstr_w( name ) ); + ok( all_lower( upper_end, name_end ), "got u.DeviceInterface.SymbolicLink %s\n", debugstr_w( name ) ); + + if (cb_data->device_change_count++ >= cb_data->device_change_expect / 2) + ok( action == CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL, "got action %d\n", action ); + else + { + CM_NOTIFY_ACTION exp = cb_data->device_change_expect_custom ? CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL + : CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL; + ok( action == exp, "got action %d\n", action ); + } + + winetest_pop_context(); + ok( ReleaseSemaphore( cb_data->device_change_sem, 1, NULL ), "ReleaseSemaphore failed, error %lu\n", + GetLastError() ); + break; + } + default: + ok( FALSE, "Unexpected CM_NOTIFY_ACTION %d\n", action ); + } + + return ERROR_SUCCESS; +} + static void test_RegisterDeviceNotification(void) { DEV_BROADCAST_DEVICEINTERFACE_A iface_filter_a = @@ -385,10 +491,33 @@ static void test_RegisterDeviceNotification(void) .lpszClassName = L"devnotify", .lpfnWndProc = devnotify_wndproc, }; + CM_NOTIFY_FILTER cm_iface_filter = + { + .cbSize = sizeof(CM_NOTIFY_FILTER), + .Flags = 0, + .FilterType = CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE, + .Reserved = 0, + .u = {.DeviceInterface = {.ClassGuid = GUID_DEVINTERFACE_HID}} + }; + CM_NOTIFY_FILTER cm_all_ifaces_filter = + { + .cbSize = sizeof(CM_NOTIFY_FILTER), + .Flags = CM_NOTIFY_FILTER_FLAG_ALL_INTERFACE_CLASSES, + .FilterType = CM_NOTIFY_FILTER_TYPE_DEVICEINTERFACE, + .Reserved = 0, + }; + CM_NOTIFY_FILTER cm_handle_filter = + { + .cbSize = sizeof(CM_NOTIFY_FILTER), + .Flags = 0, + .FilterType = CM_NOTIFY_FILTER_TYPE_DEVICEHANDLE, + .Reserved = 0, + }; char buffer[1024] = {0}; DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)buffer; HANDLE hwnd, thread, stop_event; HDEVNOTIFY devnotify; + struct cm_notify_callback_data notify_ctx = {0}; DWORD ret; MSG msg;
@@ -461,6 +590,16 @@ static void test_RegisterDeviceNotification(void) ok( !!devnotify, "RegisterDeviceNotificationA failed, error %lu\n", GetLastError() ); while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
+ notify_ctx.device_change_sem = CreateSemaphoreA( NULL, 0, 6, NULL ); + ok( !!notify_ctx.device_change_sem, "CreateSemaphoreA failed, error %lu\n", GetLastError() ); + + notify_ctx.device_change_all = FALSE; + notify_ctx.device_change_expect = 2; + notify_ctx.device_change_count = 0; + + ret = CM_Register_Notification( &cm_iface_filter, ¬ify_ctx, cm_notify_callback, ¬ify_ctx.hnotify ); + todo_wine ok( !ret, "CM_Register_Notification failed, error %lu\n", ret ); + device_change_count = 0; device_change_expect = 2; device_change_hwnd = hwnd; @@ -482,7 +621,14 @@ static void test_RegisterDeviceNotification(void) DispatchMessageW( &msg ); } if (device_change_count == device_change_expect / 2) SetEvent( stop_event ); + if (notify_ctx.hnotify) + { + ret = WaitForSingleObject( notify_ctx.device_change_sem, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + } } + todo_wine ok( notify_ctx.device_change_count == notify_ctx.device_change_expect, "%lu != %lu\n", + notify_ctx.device_change_count, notify_ctx.device_change_expect );
ret = WaitForSingleObject( thread, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); @@ -490,6 +636,7 @@ static void test_RegisterDeviceNotification(void) CloseHandle( stop_event );
UnregisterDeviceNotification( devnotify ); + CM_Unregister_Notification( notify_ctx.hnotify );
memcpy( buffer, &iface_filter_a, sizeof(iface_filter_a) ); strcpy( ((DEV_BROADCAST_DEVICEINTERFACE_A *)buffer)->dbcc_name, "device name" ); @@ -498,6 +645,13 @@ static void test_RegisterDeviceNotification(void) ok( !!devnotify, "RegisterDeviceNotificationA failed, error %lu\n", GetLastError() ); while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
+ notify_ctx.device_change_all = FALSE; + notify_ctx.device_change_expect = 2; + notify_ctx.device_change_count = 0; + + ret = CM_Register_Notification( &cm_iface_filter, ¬ify_ctx, cm_notify_callback, ¬ify_ctx.hnotify ); + todo_wine ok( !ret, "CM_Register_Notification failed, error %lu\n", ret ); + device_change_count = 0; device_change_expect = 2; device_change_hwnd = hwnd; @@ -519,7 +673,14 @@ static void test_RegisterDeviceNotification(void) DispatchMessageW( &msg ); } if (device_change_count == device_change_expect / 2) SetEvent( stop_event ); + if (notify_ctx.hnotify) + { + ret = WaitForSingleObject( notify_ctx.device_change_sem, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + } } + todo_wine ok( notify_ctx.device_change_count == notify_ctx.device_change_expect, "%lu != %lu\n", + notify_ctx.device_change_count, notify_ctx.device_change_expect );
ret = WaitForSingleObject( thread, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); @@ -527,11 +688,18 @@ static void test_RegisterDeviceNotification(void) CloseHandle( stop_event );
UnregisterDeviceNotification( devnotify ); + CM_Unregister_Notification( notify_ctx.hnotify );
devnotify = RegisterDeviceNotificationA( hwnd, &iface_filter_a, DEVICE_NOTIFY_ALL_INTERFACE_CLASSES ); ok( !!devnotify, "RegisterDeviceNotificationA failed, error %lu\n", GetLastError() ); while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
+ notify_ctx.device_change_all = TRUE; + notify_ctx.device_change_expect = 4; + notify_ctx.device_change_count = 0; + ret = CM_Register_Notification( &cm_all_ifaces_filter, ¬ify_ctx, cm_notify_callback, ¬ify_ctx.hnotify ); + todo_wine ok( !ret, "CM_Register_Notification failed, error %lu\n", ret ); + device_change_count = 0; device_change_expect = 4; device_change_hwnd = hwnd; @@ -553,7 +721,14 @@ static void test_RegisterDeviceNotification(void) DispatchMessageW( &msg ); } if (device_change_count == device_change_expect / 2) SetEvent( stop_event ); + if (notify_ctx.hnotify) + { + ret = WaitForSingleObject( notify_ctx.device_change_sem, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + } } + todo_wine ok( notify_ctx.device_change_count == notify_ctx.device_change_expect, "%lu != %lu\n", + notify_ctx.device_change_count, notify_ctx.device_change_expect );
ret = WaitForSingleObject( thread, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); @@ -561,11 +736,19 @@ static void test_RegisterDeviceNotification(void) CloseHandle( stop_event );
UnregisterDeviceNotification( devnotify ); + CM_Unregister_Notification( notify_ctx.hnotify );
devnotify = RegisterDeviceNotificationA( hwnd, &iface_filter_a, DEVICE_NOTIFY_WINDOW_HANDLE ); ok( !!devnotify, "RegisterDeviceNotificationA failed, error %lu\n", GetLastError() ); while (PeekMessageW( &msg, hwnd, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
+ notify_ctx.device_change_all = FALSE; + notify_ctx.device_change_expect = 6; + notify_ctx.device_change_count = 0; + cm_iface_filter.Flags = 0; + ret = CM_Register_Notification( &cm_iface_filter, ¬ify_ctx, cm_notify_callback, ¬ify_ctx.hnotify ); + todo_wine ok( !ret, "CM_Register_Notification failed, error %lu\n", ret ); + device_change_count = 0; device_change_expect = 2; device_change_hwnd = hwnd; @@ -586,6 +769,12 @@ static void test_RegisterDeviceNotification(void) ok( msg.message != WM_DEVICECHANGE, "got WM_DEVICECHANGE\n" ); DispatchMessageW( &msg ); } + if (notify_ctx.hnotify) + { + ret = WaitForSingleObject( notify_ctx.device_change_sem, 5000 ); + ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); + } + if (device_change_count == 1 && !device_change_expect_event) { WCHAR device_path[MAX_PATH]; @@ -604,8 +793,13 @@ static void test_RegisterDeviceNotification(void) handle_devnotify = RegisterDeviceNotificationA( hwnd, &handle_filter_a, DEVICE_NOTIFY_WINDOW_HANDLE ); ok( !!handle_devnotify, "RegisterDeviceNotificationA failed, error %lu\n", GetLastError() );
+ cm_handle_filter.u.DeviceHandle.hTarget = file; + ret = CM_Register_Notification( &cm_handle_filter, ¬ify_ctx, cm_notify_callback, &handle_cmnotify ); + todo_wine ok( !ret, "CM_Register_Notification failed, error %lu\n", ret ); + device_change_expect_handle = file; device_change_expect_event = device_change_events; + notify_ctx.device_change_expect_custom = ARRAY_SIZE(device_change_events) + 1; for (i = 0; i < ARRAY_SIZE(device_change_events) - 1; i++) { ret = sync_ioctl( file, IOCTL_WINETEST_DEVICE_CHANGE, (BYTE *)&device_change_events[i].notif, @@ -619,6 +813,9 @@ static void test_RegisterDeviceNotification(void) } if (device_change_count == 1 && device_change_expect_custom == 1) SetEvent( stop_event ); } + ok( notify_ctx.device_change_count == notify_ctx.device_change_expect, "%lu != %lu\n", + notify_ctx.device_change_count, notify_ctx.device_change_expect ); + todo_wine ok( notify_ctx.received_deviceremovalcomplete, "%d != 1\n", notify_ctx.received_deviceremovalcomplete );
ret = WaitForSingleObject( thread, 5000 ); ok( !ret, "WaitForSingleObject returned %#lx\n", ret ); @@ -626,9 +823,12 @@ static void test_RegisterDeviceNotification(void) CloseHandle( stop_event );
if (handle_devnotify) UnregisterDeviceNotification( handle_devnotify ); + if (handle_cmnotify) CM_Unregister_Notification( handle_cmnotify ); UnregisterDeviceNotification( devnotify ); + CM_Unregister_Notification( notify_ctx.hnotify ); device_change_expect_event = NULL; handle_devnotify = 0; + CloseHandle( notify_ctx.device_change_sem );
DestroyWindow( hwnd ); UnregisterClassW( class.lpszClassName, class.hInstance );