[PATCH 2/2] user32/tests: Stop depending on existing window for SetActiveWindow tests.

Rémi Bernon rbernon at codeweavers.com
Tue Feb 1 04:24:38 CST 2022


Also try to make some sense in the failures this change introduces.
Looks like from [1] that there's a SW_HIDE behavior change in Win10.

As the failures were more inconsistent when we were using the existing
windows, and as the first SW_HIDE seems consistent, it likely also
depends on the events the window previously received, probably similar
to the user input time on X11.

[1] https://testbot.winehq.org/JobDetails.pl?Key=106683

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/user32/tests/win.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 289b2c5a276..7192e737b00 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -3568,9 +3568,13 @@ static void test_SetActiveWindow_0( char **argv )
     DestroyWindow( hwnd );
 }
 
-static void test_SetActiveWindow(HWND hwnd)
+static void test_SetActiveWindow(void)
 {
-    HWND hwnd2, ret;
+    DWORD style = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE;
+    HWND hwnd, hwnd2, active, ret;
+
+    hwnd = CreateWindowExA( 0, "MainWindowClass", "Main window", style, 100, 100, 200, 200, 0, 0, NULL, NULL);
+    ok( !!hwnd, "CreateWindowExA failed, error %u\n", GetLastError() );
 
     flush_events( TRUE );
     ShowWindow(hwnd, SW_HIDE);
@@ -3586,14 +3590,22 @@ static void test_SetActiveWindow(HWND hwnd)
     check_wnd_state(hwnd, hwnd, hwnd, 0);
 
     ShowWindow(hwnd, SW_HIDE);
-    check_wnd_state(0, 0, 0, 0);
+    active = GetActiveWindow();
+    /* SW_HIDE only sometimes deactivates the window, consistently on Win10 >= 1809 */
+    ok(active == hwnd || active == 0, "got active window %p\n", active);
+    check_wnd_state(active, 0, 0, 0);
+
+    SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
+    check_wnd_state(active, 0, 0, 0);
 
     /* Invisible window. */
     SetActiveWindow(hwnd);
-    check_wnd_state(hwnd, hwnd, hwnd, 0);
-    
+    if (active == hwnd) check_wnd_state(hwnd, hwnd, 0, 0); /* not de-activated, focus isn't restored */
+    else check_wnd_state(hwnd, hwnd, hwnd, 0);
+
     ShowWindow(hwnd, SW_SHOW);
-    check_wnd_state(hwnd, hwnd, hwnd, 0);
+    if (active == hwnd) check_wnd_state(hwnd, hwnd, 0, 0); /* not de-activated, focus isn't restored */
+    else check_wnd_state(hwnd, hwnd, hwnd, 0);
 
     hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
     check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
@@ -3629,6 +3641,7 @@ static void test_SetActiveWindow(HWND hwnd)
     check_wnd_state(hwnd, hwnd, hwnd, 0);
 
     DestroyWindow(hwnd2);
+    DestroyWindow(hwnd);
 }
 
 struct create_window_thread_params
@@ -12674,8 +12687,6 @@ START_TEST(win)
     test_SetWindowPos(hwndMain, hwndMain2);
     test_SetMenu(hwndMain);
     test_SetFocus(hwndMain);
-    test_SetActiveWindow_0( argv );
-    test_SetActiveWindow(hwndMain);
     test_NCRedraw();
 
     test_children_zorder(hwndMain);
@@ -12742,6 +12753,9 @@ START_TEST(win)
     DestroyWindow(hwndMain2);
     DestroyWindow(hwndMain);
 
+    test_SetActiveWindow_0( argv );
+    test_SetActiveWindow();
+
     /* Make sure that following tests are executed last, under Windows they
      * tend to break the tests which are sensitive to z-order and activation
      * state of hwndMain and hwndMain2 windows.
-- 
2.34.1




More information about the wine-devel mailing list