Improve SetActiveWindow test, add SetForegroundWindow test,
make them pass under Wine
Dmitry Timoshkov
dmitry at codeweavers.com
Wed Jul 5 06:44:18 CDT 2006
Hello,
Changelog:
Improve SetActiveWindow test, add SetForegroundWindow test, make them
pass under Wine.
diff -up cvs/hq/wine/dlls/user/focus.c wine/dlls/user/focus.c
--- cvs/hq/wine/dlls/user/focus.c 2006-05-24 13:16:27.000000000 +0900
+++ wine/dlls/user/focus.c 2006-07-05 20:34:15.000000000 +0900
@@ -203,12 +203,17 @@ static BOOL set_foreground_window( HWND
else if (send_msg_new) /* old window belongs to us but new one to other thread */
ret = set_active_window( 0, NULL, mouse, TRUE );
- if (send_msg_new) /* new window belongs to other thread */
- SendNotifyMessageW( hwnd, WM_WINE_SETACTIVEWINDOW, (WPARAM)hwnd, 0 );
- else /* new window belongs to us */
- ret = set_active_window( hwnd, NULL, mouse, TRUE );
+ if (hwnd)
+ {
+ if (send_msg_new) /* new window belongs to other thread */
+ SendNotifyMessageW( hwnd, WM_WINE_SETACTIVEWINDOW, (WPARAM)hwnd, 0 );
+ else /* new window belongs to us */
+ ret = set_active_window( hwnd, NULL, mouse, TRUE );
+
+ return ret;
+ }
}
- return ret;
+ return FALSE;
}
diff -up cvs/hq/wine/dlls/user/tests/win.c wine/dlls/user/tests/win.c
--- cvs/hq/wine/dlls/user/tests/win.c 2006-06-10 18:45:29.000000000 +0900
+++ wine/dlls/user/tests/win.c 2006-07-05 20:00:22.000000000 +0900
@@ -2101,47 +2101,133 @@ static void test_SetFocus(HWND hwnd)
DestroyWindow( child );
}
+static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
+{
+ ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
+ if (foreground)
+ ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
+ ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
+ ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
+}
+
static void test_SetActiveWindow(HWND hwnd)
{
HWND hwnd2;
- ShowWindow(hwnd, SW_SHOW);
+ ShowWindow(hwnd, SW_HIDE);
+ SetFocus(0);
+ SetForegroundWindow(0);
SetActiveWindow(0);
- SetActiveWindow(hwnd);
- ok( GetActiveWindow() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
+ check_wnd_state(0, 0, 0, 0);
+
+ /*trace("testing SetActiveWindow %p\n", hwnd);*/
+
+ ShowWindow(hwnd, SW_SHOW);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
+ hwnd2 = SetActiveWindow(0);
+ ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
+ check_wnd_state(0, 0, 0, 0);
+
+ hwnd2 = SetActiveWindow(hwnd);
+ ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
- ok( GetActiveWindow() == hwnd, "Window %p no longer active\n", hwnd );
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
ShowWindow(hwnd, SW_HIDE);
- ok( GetActiveWindow() != hwnd, "Window %p is still active\n", hwnd );
+ check_wnd_state(0, 0, 0, 0);
- /* trace("**testing an invisible window now\n"); */
+ /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
SetActiveWindow(hwnd);
- ok( GetActiveWindow() == hwnd, "Window %p not active\n", hwnd );
- ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p is visible\n", hwnd );
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
ShowWindow(hwnd, SW_SHOW);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
- ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
+ check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
+
DestroyWindow(hwnd2);
- ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
- ok( GetActiveWindow() == hwnd2, "Window %p is not active\n", hwnd2 );
+ check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
+
SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
- ok( GetActiveWindow() == hwnd2, "Window %p no longer active (%p)\n", hwnd2, GetActiveWindow() );
+ check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
+
DestroyWindow(hwnd2);
- ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
}
-static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
+static void test_SetForegroundWindow(HWND hwnd)
{
- ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
- if (foreground)
- ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
- ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
- ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
+ BOOL ret;
+ HWND hwnd2;
+
+ ShowWindow(hwnd, SW_HIDE);
+ SetFocus(0);
+ SetForegroundWindow(0);
+ SetActiveWindow(0);
+ check_wnd_state(0, 0, 0, 0);
+
+ /*trace("testing SetForegroundWindow %p\n", hwnd);*/
+
+ ShowWindow(hwnd, SW_SHOW);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
+ hwnd2 = SetActiveWindow(0);
+ ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
+ check_wnd_state(0, 0, 0, 0);
+
+ ret = SetForegroundWindow(hwnd);
+ ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
+ check_wnd_state(hwnd, 0, hwnd, 0);
+
+ ret = SetForegroundWindow(0);
+ ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
+ check_wnd_state(hwnd, 0, hwnd, 0);
+
+ ret = SetForegroundWindow(hwnd);
+ ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
+ SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
+ SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
+ ShowWindow(hwnd, SW_HIDE);
+ check_wnd_state(0, 0, 0, 0);
+
+ /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
+ ret = SetForegroundWindow(hwnd);
+ ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
+
+ ShowWindow(hwnd, SW_SHOW);
+ 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);
+
+ DestroyWindow(hwnd2);
+ 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);
+
+ SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
+ check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
+
+ DestroyWindow(hwnd2);
+ check_wnd_state(hwnd, hwnd, hwnd, 0);
}
static WNDPROC old_button_proc;
@@ -3794,6 +3880,7 @@ START_TEST(win)
test_SetMenu(hwndMain);
test_SetFocus(hwndMain);
test_SetActiveWindow(hwndMain);
+ test_SetForegroundWindow(hwndMain);
test_children_zorder(hwndMain);
test_keyboard_input(hwndMain);
diff -up cvs/hq/wine/server/queue.c wine/server/queue.c
--- cvs/hq/wine/server/queue.c 2006-06-10 18:45:32.000000000 +0900
+++ wine/server/queue.c 2006-07-05 19:19:32.000000000 +0900
@@ -2048,6 +2048,7 @@ DECL_HANDLER(set_active_window)
{
reply->previous = queue->input->active;
queue->input->active = get_user_full_handle( req->handle );
+ foreground_input = queue->input;
}
else set_error( STATUS_INVALID_HANDLE );
}
More information about the wine-patches
mailing list