Dmitry Timoshkov : user: Improve SetActiveWindow test, add SetForegroundWindow test, make them pass under Wine.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jul 10 07:12:10 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 19e7fab981a75cdf0a339db35d36d9c1a6e64494
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=19e7fab981a75cdf0a339db35d36d9c1a6e64494

Author: Dmitry Timoshkov <dmitry at codeweavers.com>
Date:   Fri Jul  7 23:01:51 2006 +0900

user: Improve SetActiveWindow test, add SetForegroundWindow test, make them pass under Wine.

---

 dlls/user/focus.c     |    3 +
 dlls/user/tests/win.c |  121 +++++++++++++++++++++++++++++++++++++++++--------
 server/queue.c        |   19 +++-----
 server/trace.c        |    1 
 server/window.c       |    2 -
 5 files changed, 113 insertions(+), 33 deletions(-)

diff --git a/dlls/user/focus.c b/dlls/user/focus.c
index 18bd035..efc8b8f 100644
--- a/dlls/user/focus.c
+++ b/dlls/user/focus.c
@@ -299,7 +299,8 @@ HWND WINAPI SetFocus( HWND hwnd )
 BOOL WINAPI SetForegroundWindow( HWND hwnd )
 {
     TRACE( "%p\n", hwnd );
-    if (hwnd) hwnd = WIN_GetFullHandle( hwnd );
+
+    hwnd = WIN_GetFullHandle( hwnd );
     return set_foreground_window( hwnd, FALSE );
 }
 
diff --git a/dlls/user/tests/win.c b/dlls/user/tests/win.c
index f291fff..05a9287 100644
--- a/dlls/user/tests/win.c
+++ b/dlls/user/tests/win.c
@@ -2101,47 +2101,129 @@ 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);
     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);
+    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, hwnd, hwnd, 0);
+
+    SetLastError(0xdeadbeef);
+    ret = SetForegroundWindow(0);
+    ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
+    ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %ld expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
+    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 +3876,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 --git a/server/queue.c b/server/queue.c
index 769895a..607c102 100644
--- a/server/queue.c
+++ b/server/queue.c
@@ -1999,26 +1999,21 @@ DECL_HANDLER(set_key_state)
 /* set the system foreground window */
 DECL_HANDLER(set_foreground_window)
 {
+    struct thread *thread;
     struct msg_queue *queue = get_current_queue();
 
     reply->previous = foreground_input ? foreground_input->active : 0;
     reply->send_msg_old = (reply->previous && foreground_input != queue->input);
     reply->send_msg_new = FALSE;
 
-    if (req->handle)
+    if (is_top_level_window( req->handle ) &&
+        ((thread = get_window_thread( req->handle ))))
     {
-        struct thread *thread;
-
-        if (is_top_level_window( req->handle ) &&
-            ((thread = get_window_thread( req->handle ))))
-        {
-            foreground_input = thread->queue->input;
-            reply->send_msg_new = (foreground_input != queue->input);
-            release_object( thread );
-        }
-        else set_error( STATUS_INVALID_HANDLE );
+        foreground_input = thread->queue->input;
+        reply->send_msg_new = (foreground_input != queue->input);
+        release_object( thread );
     }
-    else foreground_input = NULL;
+    else set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
 }
 
 
diff --git a/server/trace.c b/server/trace.c
index 9b5cc39..6ecdeae 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -3933,6 +3933,7 @@ static const struct
     { "ERROR_CLASS_HAS_WINDOWS",     0xc0010000 | ERROR_CLASS_HAS_WINDOWS },
     { "ERROR_CLIPBOARD_NOT_OPEN",    0xc0010000 | ERROR_CLIPBOARD_NOT_OPEN },
     { "ERROR_INVALID_INDEX",         0xc0010000 | ERROR_INVALID_INDEX },
+    { "ERROR_INVALID_WINDOW_HANDLE", 0xc0010000 | ERROR_INVALID_WINDOW_HANDLE },
     { "ERROR_SEEK",                  0xc0010000 | ERROR_SEEK },
     { "FILE_IS_A_DIRECTORY",         STATUS_FILE_IS_A_DIRECTORY },
     { "FILE_LOCK_CONFLICT",          STATUS_FILE_LOCK_CONFLICT },
diff --git a/server/window.c b/server/window.c
index f2017ec..82d709d 100644
--- a/server/window.c
+++ b/server/window.c
@@ -110,7 +110,7 @@ static struct window *taskman_window;
 inline static struct window *get_window( user_handle_t handle )
 {
     struct window *ret = get_user_object( handle, USER_WINDOW );
-    if (!ret) set_error( STATUS_INVALID_HANDLE );
+    if (!ret) set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
     return ret;
 }
 




More information about the wine-cvs mailing list