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: