[Patch 1/2] user32/tests: Added test to show EnableWindow cause wrong ReleaseCapture

orzhvs orzhvs at gmail.com
Wed May 8 12:51:59 CDT 2013


A window will lose capture if it's disabled, but it's children should
not. Related to bug 33542.
It has been tested fine with newtestbot.

This is my first patch to wine, could you please have a review on
this? I'd like write better patches in the future.

---
 dlls/user32/tests/win.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 37d210e..b176177 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -3105,6 +3105,84 @@ static void test_capture_4(void)
     DestroyWindow(hwnd);
 }

+/* test for that disabling a window should not release capture of
child window */
+static void test_capture_5(void)
+{
+    HWND hwnd, child, cap;
+    POINT pnt;
+    MSG msg;
+    BOOL received_lbuttonup_flag;
+    WNDCLASS class;
+
+    class.style         = CS_HREDRAW | CS_VREDRAW;
+    class.lpfnWndProc   = DefWindowProcA;
+    class.cbClsExtra    = 0;
+    class.cbWndExtra    = 0;
+    class.hInstance     = 0;
+    class.hIcon         = NULL;
+    class.hCursor       = NULL;
+    class.hbrBackground = GetStockObject(WHITE_BRUSH);
+    class.lpszMenuName  = 0;
+    class.lpszClassName = "test_capture_5_class";
+
+    if (!RegisterClass (&class))
+    {
+        ok(FALSE, "RegisterClass failed\n");
+        return;
+    }
+
+    hwnd = CreateWindowEx(0, "test_capture_5_class", "test_capture_5 parent",
+                          WS_OVERLAPPEDWINDOW,
+                          100, 100, 200, 200,
+                          0, 0, GetModuleHandle(0), NULL);
+    assert(hwnd);
+    trace("hwnd %p\n", hwnd);
+    child = CreateWindowExA(0, "Edit", "child", WS_BORDER | WS_CHILD
| WS_VISIBLE, 10, 10, 50, 50, hwnd, 0, GetModuleHandle(0), NULL);
+    assert(child);
+    trace("child %p\n", child);
+
+    ShowWindow(hwnd, SW_SHOW);
+    UpdateWindow(hwnd);
+    ShowWindow(child, SW_SHOW);
+    UpdateWindow(child);
+
+    /* hold left mouse button down in child */
+    pnt.x = pnt.y = 30;
+    ClientToScreen(hwnd, &pnt);
+    SetCursorPos(pnt.x, pnt.y);
+    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
+
+    /* set capture to child */
+    ReleaseCapture();
+    SetCapture(child);
+    cap = GetCapture();
+    ok(cap == child, "SetCapture failed.\n");
+    /* disable the parent window */
+    EnableWindow(hwnd, FALSE);
+    cap = GetCapture();
+    todo_wine ok(cap != NULL, "Capture in child should not be released.\n");
+
+    /* move mouse out and release */
+    SetCursorPos(20, 20);
+    received_lbuttonup_flag = FALSE;
+    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
+    flush_events(FALSE);
+
+    /* should receive BUTTONUP message when captured */
+    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
+    {
+        if (msg.message == WM_LBUTTONUP)
+            if (msg.hwnd == child) received_lbuttonup_flag = TRUE;
+        DispatchMessage(&msg);
+    }
+    todo_wine ok(received_lbuttonup_flag, "WM_LBUTTONUP should have
been received in child\n");
+    ReleaseCapture();
+
+    /* clean up */
+    DestroyWindow(child);
+    DestroyWindow(hwnd);
+}
+
 /* PeekMessage wrapper that ignores the messages we don't care about */
 static BOOL peek_message( MSG *msg )
 {
@@ -7455,6 +7533,7 @@ START_TEST(win)
     test_capture_2();
     test_capture_3(hwndMain, hwndMain2);
     test_capture_4();
+    test_capture_5();
     test_rtl_layout();
     test_FlashWindowEx();

-- 
1.8.1.5



More information about the wine-patches mailing list