From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/tests/device8.c | 65 ++++++++++++++++++++---------- dlls/dinput/tests/dinput_test.h | 3 ++ dlls/dinput/tests/force_feedback.c | 6 +-- dlls/dinput/tests/joystick8.c | 18 ++------- 4 files changed, 51 insertions(+), 41 deletions(-)
diff --git a/dlls/dinput/tests/device8.c b/dlls/dinput/tests/device8.c index 3a702b8f2fe..7423d6c6ae7 100644 --- a/dlls/dinput/tests/device8.c +++ b/dlls/dinput/tests/device8.c @@ -66,6 +66,41 @@ static void flush_events(void) } }
+HWND create_foreground_window_( const char *file, int line, BOOL fullscreen, UINT retries ) +{ + for (;;) + { + HWND hwnd; + BOOL ret; + + hwnd = CreateWindowW( L"static", NULL, WS_POPUP | (fullscreen ? 0 : WS_VISIBLE), + 100, 100, 200, 200, NULL, NULL, NULL, NULL ); + ok_(file, line)( hwnd != NULL, "CreateWindowW failed, error %lu\n", GetLastError() ); + + if (fullscreen) + { + HMONITOR hmonitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY ); + MONITORINFO mi = {.cbSize = sizeof(MONITORINFO)}; + + ok_(file, line)( hmonitor != NULL, "MonitorFromWindow failed, error %lu\n", GetLastError() ); + ret = GetMonitorInfoW( hmonitor, &mi ); + ok_(file, line)( ret, "GetMonitorInfoW failed, error %lu\n", GetLastError() ); + ret = SetWindowPos( hwnd, 0, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, + mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_FRAMECHANGED | SWP_SHOWWINDOW ); + ok_(file, line)( ret, "SetWindowPos failed, error %lu\n", GetLastError() ); + } + flush_events(); + + if (GetForegroundWindow() == hwnd) return hwnd; + ok_(file, line)( retries > 0, "failed to create foreground window\n" ); + if (!retries--) return hwnd; + + ret = DestroyWindow( hwnd ); + ok_(file, line)( ret, "DestroyWindow failed, error %lu\n", GetLastError() ); + flush_events(); + } +} + static HRESULT create_dinput_device( DWORD version, const GUID *guid, IDirectInputDevice8W **device ) { IDirectInputW *dinput; @@ -294,8 +329,7 @@ void test_overlapped_format( DWORD version )
event = CreateEventW( NULL, FALSE, FALSE, NULL ); ok( !!event, "CreateEventW failed, error %lu\n", GetLastError() ); - hwnd = CreateWindowW( L"static", L"Title", WS_POPUP | WS_VISIBLE, 10, 10, 200, 200, NULL, NULL, NULL, NULL ); - ok( !!hwnd, "CreateWindowW failed, error %lu\n", GetLastError() ); + hwnd = create_foreground_window( FALSE );
hr = IDirectInput_CreateDevice( dinput, &GUID_SysKeyboard, &keyboard, NULL ); ok( hr == DI_OK, "CreateDevice returned %#lx\n", hr ); @@ -556,10 +590,6 @@ static void test_mouse_keyboard(void) UINT raw_devices_count; RAWINPUTDEVICE raw_devices[3];
- hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput", WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "CreateWindowExA failed\n"); - flush_events(); - hr = CoCreateInstance(&CLSID_DirectInput8, 0, CLSCTX_INPROC_SERVER, &IID_IDirectInput8A, (LPVOID*)&di); if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION || @@ -578,6 +608,8 @@ static void test_mouse_keyboard(void) } ok(SUCCEEDED(hr), "IDirectInput8_Initialize failed: %#lx\n", hr);
+ hwnd = create_foreground_window( TRUE ); + hr = IDirectInput8_CreateDevice(di, &GUID_SysMouse, &di_mouse, NULL); ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %#lx\n", hr); hr = IDirectInputDevice8_SetDataFormat(di_mouse, &c_dfDIMouse); @@ -771,8 +803,7 @@ static void test_keyboard_events(void) } ok(SUCCEEDED(hr), "IDirectInput8_Initialize failed: %#lx\n", hr);
- hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput", WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "CreateWindowExA failed\n"); + hwnd = create_foreground_window( FALSE );
hr = IDirectInput8_CreateDevice(di, &GUID_SysKeyboard, &di_keyboard, NULL); ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %#lx\n", hr); @@ -872,9 +903,7 @@ static void test_appdata_property(void) ok(SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%#lx\n", hr); if (FAILED(hr)) return;
- hwnd = CreateWindowExA(WS_EX_TOPMOST, "static", "dinput", - WS_POPUP | WS_VISIBLE, 0, 0, 100, 100, NULL, NULL, NULL, NULL); - ok(hwnd != NULL, "failed to create window\n"); + hwnd = create_foreground_window( TRUE );
hr = IDirectInput8_CreateDevice(pDI, &GUID_SysKeyboard, &di_keyboard, NULL); ok(SUCCEEDED(hr), "IDirectInput8_CreateDevice failed: %#lx\n", hr); @@ -1412,11 +1441,7 @@ static void test_sys_mouse( DWORD version ) check_member( objinst, expect_objects[3], "%u", wReportId );
- SetCursorPos( 60, 60 ); - - hwnd = CreateWindowW( L"static", L"static", WS_POPUP | WS_VISIBLE, - 50, 50, 200, 200, NULL, NULL, NULL, NULL ); - ok( !!hwnd, "CreateWindowW failed, error %lu\n", GetLastError() ); + hwnd = create_foreground_window( TRUE );
hr = IDirectInputDevice8_SetCooperativeLevel( device, NULL, DISCL_FOREGROUND ); ok( hr == DIERR_INVALIDPARAM, "SetCooperativeLevel returned %#lx\n", hr ); @@ -1571,9 +1596,7 @@ static void test_sys_mouse( DWORD version ) ok( hr == DI_OK, "Unacquire returned %#lx\n", hr ); }
- tmp_hwnd = CreateWindowW( L"static", L"static", WS_POPUP | WS_VISIBLE, - 50, 250, 200, 200, NULL, NULL, NULL, NULL ); - ok( !!tmp_hwnd, "CreateWindowW failed, error %lu\n", GetLastError() ); + tmp_hwnd = create_foreground_window( FALSE );
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state ); ok( hr == DIERR_NOTACQUIRED, "GetDeviceState returned %#lx\n", hr ); @@ -2126,9 +2149,7 @@ static void test_sys_keyboard( DWORD version ) check_member( objinst, expect_objects[2], "%u", wReportId );
- hwnd = CreateWindowW( L"static", L"static", WS_POPUP | WS_VISIBLE, - 50, 50, 200, 200, NULL, NULL, NULL, NULL ); - ok( !!hwnd, "CreateWindowW failed, error %lu\n", GetLastError() ); + hwnd = create_foreground_window( FALSE );
hr = IDirectInputDevice8_SetCooperativeLevel( device, NULL, DISCL_FOREGROUND ); ok( hr == DIERR_INVALIDPARAM, "SetCooperativeLevel returned %#lx\n", hr ); diff --git a/dlls/dinput/tests/dinput_test.h b/dlls/dinput/tests/dinput_test.h index a4a133e6384..b53978bbe97 100644 --- a/dlls/dinput/tests/dinput_test.h +++ b/dlls/dinput/tests/dinput_test.h @@ -109,4 +109,7 @@ void send_hid_input_( const char *file, int line, HANDLE device, struct hid_devi #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 );
+#define create_foreground_window( a ) create_foreground_window_( __FILE__, __LINE__, a, 5 ) +HWND create_foreground_window_( const char *file, int line, BOOL fullscreen, UINT retries ); + #endif /* __WINE_DINPUT_TEST_H */ diff --git a/dlls/dinput/tests/force_feedback.c b/dlls/dinput/tests/force_feedback.c index c20125655f4..bb3578e4590 100644 --- a/dlls/dinput/tests/force_feedback.c +++ b/dlls/dinput/tests/force_feedback.c @@ -3079,8 +3079,7 @@ static BOOL test_force_feedback_joystick( DWORD version ) FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, NULL ); ok( file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError() );
- hwnd = CreateWindowW( L"static", L"dinput", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 200, 200, - NULL, NULL, NULL, NULL ); + hwnd = create_foreground_window( FALSE );
hr = IDirectInputDevice8_SetCooperativeLevel( device, hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ); ok( hr == DI_OK, "SetCooperativeLevel returned: %#lx\n", hr ); @@ -4131,8 +4130,7 @@ static void test_device_managed_effect(void) FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, NULL ); ok( file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError() );
- hwnd = CreateWindowW( L"static", L"dinput", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 200, 200, - NULL, NULL, NULL, NULL ); + hwnd = create_foreground_window( FALSE );
event = CreateEventW( NULL, FALSE, FALSE, NULL ); ok( event != NULL, "CreateEventW failed, last error %lu\n", GetLastError() ); diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 88d9e4d9ffe..b4cd4a771de 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -2279,8 +2279,7 @@ static void test_simple_joystick( DWORD version ) hr = IDirectInputDevice8_SetCooperativeLevel( device, NULL, DISCL_FOREGROUND | DISCL_EXCLUSIVE ); ok( hr == E_HANDLE, "SetCooperativeLevel returned: %#lx\n", hr );
- hwnd = CreateWindowW( L"static", L"dinput", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 200, 200, - NULL, NULL, NULL, NULL ); + hwnd = create_foreground_window( FALSE );
hr = IDirectInputDevice8_SetCooperativeLevel( device, hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ); ok( hr == DI_OK, "SetCooperativeLevel returned: %#lx\n", hr ); @@ -5278,13 +5277,6 @@ static void test_rawinput(void) .report_buf = {1,0x10,0x10,0x10,0xee,0x10,0x10,0x10,0x54}, }, }; - WNDCLASSEXW class = - { - .cbSize = sizeof(WNDCLASSEXW), - .hInstance = GetModuleHandleW( NULL ), - .lpszClassName = L"rawinput", - .lpfnWndProc = rawinput_wndproc, - }; RAWINPUT *rawinput = (RAWINPUT *)wm_input_buf; RAWINPUTDEVICELIST raw_device_list[16]; RAWINPUTDEVICE raw_devices[16]; @@ -5295,8 +5287,6 @@ static void test_rawinput(void) HWND hwnd; BOOL ret;
- RegisterClassExW( &class ); - cleanup_registry_keys();
desc.report_descriptor_len = sizeof(report_desc); @@ -5310,9 +5300,8 @@ static void test_rawinput(void) 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() ); + hwnd = create_foreground_window( FALSE ); + SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (ULONG_PTR)rawinput_wndproc );
count = ARRAY_SIZE(raw_devices); res = GetRegisteredRawInputDevices( raw_devices, &count, sizeof(RAWINPUTDEVICE) ); @@ -5464,7 +5453,6 @@ done: cleanup_registry_keys();
DestroyWindow( hwnd ); - UnregisterClassW( class.lpszClassName, class.hInstance ); }
START_TEST( joystick8 )