From: Rémi Bernon rbernon@codeweavers.com
This causes a foreground window race condition and will cause spurious failures depending on how pending X11 events are processed concurrenly.
Some tests now fail consistently and more todo_wine are needed. --- dlls/d3d9/tests/d3d9ex.c | 81 +++++++++++++++------------------------- dlls/d3d9/tests/device.c | 48 ++++++++++-------------- 2 files changed, 50 insertions(+), 79 deletions(-)
diff --git a/dlls/d3d9/tests/d3d9ex.c b/dlls/d3d9/tests/d3d9ex.c index e946b960055..cb4ae92df52 100644 --- a/dlls/d3d9/tests/d3d9ex.c +++ b/dlls/d3d9/tests/d3d9ex.c @@ -2508,7 +2508,6 @@ struct wndproc_thread_param HWND dummy_window; HANDLE window_created; HANDLE test_finished; - BOOL running_in_foreground; };
static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -2584,7 +2583,7 @@ static DWORD WINAPI wndproc_thread(void *param) p->dummy_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, 0, 0, 0, 0); - p->running_in_foreground = SetForegroundWindow(p->dummy_window); + flush_events();
ret = SetEvent(p->window_created); ok(ret, "SetEvent failed, last error %#lx.\n", GetLastError()); @@ -2868,11 +2867,14 @@ static void test_wndproc(void) WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, user32_width, user32_height, 0, 0, 0, 0); device_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, user32_width, user32_height, 0, 0, 0, 0); + flush_events(); + thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid); ok(!!thread, "Failed to create thread, last error %#lx.\n", GetLastError());
res = WaitForSingleObject(thread_params.window_created, INFINITE); ok(res == WAIT_OBJECT_0, "Wait failed (%#lx), last error %#lx.\n", res, GetLastError()); + flush_events();
proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC); ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n", @@ -2885,15 +2887,10 @@ static void test_wndproc(void) device_window, focus_window, thread_params.dummy_window);
tmp = GetFocus(); - ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp); - if (thread_params.running_in_foreground) - { - tmp = GetForegroundWindow(); - ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", - thread_params.dummy_window, tmp); - } - else - skip("Not running in foreground, skip foreground window test\n"); + ok(tmp == NULL, "Expected focus %p, got %p.\n", NULL, tmp); + tmp = GetForegroundWindow(); + ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", + thread_params.dummy_window, tmp);
flush_events();
@@ -2913,13 +2910,10 @@ static void test_wndproc(void) expect_messages->message, expect_messages->window, i); expect_messages = NULL;
- if (0) /* Disabled until we can make this work in a reliable way on Wine. */ - { - tmp = GetFocus(); - ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp); - tmp = GetForegroundWindow(); - ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp); - } + tmp = GetFocus(); + ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp); + tmp = GetForegroundWindow(); + ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp); SetForegroundWindow(focus_window); flush_events();
@@ -3027,28 +3021,12 @@ static void test_wndproc(void)
flush_events();
- /* Openbox accidentally sets focus to the device window, causing WM_ACTIVATEAPP to be sent to the focus - * window. d3d9ex then restores the screen mode. This only happens in the D3DCREATE_NOWINDOWCHANGES case. - * - * This appears to be a race condition - it goes away if openbox is started with --sync. d3d9:device and - * d3d8:device are affected too, but because in their case d3d does not automatically restore the screen - * mode (it needs a call to device::Reset), the EnumDisplaySettings check succeeds regardless. - * - * Note that this is not a case of focus follows mouse. This happens when Openbox is configured to use - * click to focus too. */ - if (GetForegroundWindow() == device_window) - { - skip("WM set focus to the device window, not checking screen mode.\n"); - } - else - { - ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode); - ok(ret, "Failed to get display mode.\n"); - ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, - "Got unexpected width %lu.\n", devmode.dmPelsWidth); - ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, - "Got unexpected height %lu.\n", devmode.dmPelsHeight); - } + ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode); + ok(ret, "Failed to get display mode.\n"); + ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, + "Got unexpected width %lu.\n", devmode.dmPelsWidth); + ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, + "Got unexpected height %lu.\n", devmode.dmPelsHeight);
/* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */ @@ -3165,6 +3143,7 @@ static void test_wndproc(void)
expect_messages = sc_maximize_messages; SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0); + todo_wine_if(tests[i].create_flags & CREATE_DEVICE_NOWINDOWCHANGES) ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n", expect_messages->message, expect_messages->window, i); expect_messages = NULL; @@ -3207,6 +3186,7 @@ static void test_wndproc(void) * it is clear that the window has not been resized. In previous Windows version the window is resized. */
flush_events(); + todo_wine_if(!(tests[i].create_flags & CREATE_DEVICE_NOWINDOWCHANGES)) ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n", expect_messages->message, expect_messages->window, i); expect_messages = NULL; @@ -3227,12 +3207,14 @@ static void test_wndproc(void) filter_messages = NULL;
flush_events(); + todo_wine_if(!(tests[i].create_flags & CREATE_DEVICE_NOWINDOWCHANGES)) ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n", expect_messages->message, expect_messages->window, i); expect_messages = NULL;
if (!(tests[i].create_flags & CREATE_DEVICE_NOWINDOWCHANGES)) { + todo_wine_if(!(tests[i].create_flags & CREATE_DEVICE_NOWINDOWCHANGES)) ok(windowpos.hwnd == device_window && !windowpos.x && !windowpos.y && !windowpos.cx && !windowpos.cy && windowpos.flags == (SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE), @@ -3311,11 +3293,14 @@ static void test_wndproc_windowed(void) device_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, 0, 0, 0, 0); + flush_events(); + thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid); ok(!!thread, "Failed to create thread, last error %#lx.\n", GetLastError());
res = WaitForSingleObject(thread_params.window_created, INFINITE); ok(res == WAIT_OBJECT_0, "Wait failed (%#lx), last error %#lx.\n", res, GetLastError()); + flush_events();
proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC); ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n", @@ -3328,16 +3313,10 @@ static void test_wndproc_windowed(void) device_window, focus_window, thread_params.dummy_window);
tmp = GetFocus(); - ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp); - if (thread_params.running_in_foreground) - { - tmp = GetForegroundWindow(); - flaky - ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", - thread_params.dummy_window, tmp); - } - else - skip("Not running in foreground, skip foreground window test\n"); + ok(tmp == NULL, "Expected focus %p, got %p.\n", NULL, tmp); + tmp = GetForegroundWindow(); + ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", + thread_params.dummy_window, tmp);
filter_messages = focus_window;
@@ -3352,7 +3331,7 @@ static void test_wndproc_windowed(void) }
tmp = GetFocus(); - ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp); + ok(tmp == NULL, "Expected focus %p, got %p.\n", NULL, tmp); tmp = GetForegroundWindow(); ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", thread_params.dummy_window, tmp); diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 62f308e0734..431cd3ba76e 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -3762,7 +3762,6 @@ struct wndproc_thread_param HWND dummy_window; HANDLE window_created; HANDLE test_finished; - BOOL running_in_foreground; };
static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) @@ -3843,7 +3842,7 @@ static DWORD WINAPI wndproc_thread(void *param) p->dummy_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, 0, 0, 0, 0); - p->running_in_foreground = SetForegroundWindow(p->dummy_window); + flush_events();
ret = SetEvent(p->window_created); ok(ret, "SetEvent failed, last error %#lx.\n", GetLastError()); @@ -4147,11 +4146,14 @@ static void test_wndproc(void) WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, user32_width, user32_height, 0, 0, 0, 0); device_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, user32_width, user32_height, 0, 0, 0, 0); + flush_events(); + thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid); ok(!!thread, "Failed to create thread, last error %#lx.\n", GetLastError());
res = WaitForSingleObject(thread_params.window_created, INFINITE); ok(res == WAIT_OBJECT_0, "Wait failed (%#lx), last error %#lx.\n", res, GetLastError()); + flush_events();
proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC); ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n", @@ -4164,15 +4166,10 @@ static void test_wndproc(void) device_window, focus_window, thread_params.dummy_window);
tmp = GetFocus(); - ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp); - if (thread_params.running_in_foreground) - { - tmp = GetForegroundWindow(); - ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", - thread_params.dummy_window, tmp); - } - else - skip("Not running in foreground, skip foreground window test\n"); + ok(tmp == NULL, "Expected focus %p, got %p.\n", NULL, tmp); + tmp = GetForegroundWindow(); + ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", + thread_params.dummy_window, tmp);
flush_events();
@@ -4193,13 +4190,10 @@ static void test_wndproc(void) expect_messages->message, expect_messages->window, i); expect_messages = NULL;
- if (0) /* Disabled until we can make this work in a reliable way on Wine. */ - { - tmp = GetFocus(); - ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp); - tmp = GetForegroundWindow(); - ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp); - } + tmp = GetFocus(); + ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp); + tmp = GetForegroundWindow(); + ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp); SetForegroundWindow(focus_window); flush_events();
@@ -4614,11 +4608,14 @@ static void test_wndproc_windowed(void) device_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, 0, 0, 0, 0); + flush_events(); + thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid); ok(!!thread, "Failed to create thread, last error %#lx.\n", GetLastError());
res = WaitForSingleObject(thread_params.window_created, INFINITE); ok(res == WAIT_OBJECT_0, "Wait failed (%#lx), last error %#lx.\n", res, GetLastError()); + flush_events();
proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC); ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#Ix, got %#Ix.\n", @@ -4631,15 +4628,10 @@ static void test_wndproc_windowed(void) device_window, focus_window, thread_params.dummy_window);
tmp = GetFocus(); - ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp); - if (thread_params.running_in_foreground) - { - tmp = GetForegroundWindow(); - ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", - thread_params.dummy_window, tmp); - } - else - skip("Not running in foreground, skip foreground window test\n"); + ok(tmp == NULL, "Expected focus %p, got %p.\n", NULL, tmp); + tmp = GetForegroundWindow(); + ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", + thread_params.dummy_window, tmp);
filter_messages = focus_window;
@@ -4655,7 +4647,7 @@ static void test_wndproc_windowed(void) }
tmp = GetFocus(); - ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp); + ok(tmp == NULL, "Expected focus %p, got %p.\n", NULL, tmp); tmp = GetForegroundWindow(); ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n", thread_params.dummy_window, tmp);