[PATCH] comctl32/tests: Add tests for mouse right-click in a treeview control

Hugh McMaster hugh.mcmaster at outlook.com
Mon Mar 13 06:01:08 CDT 2017


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 dlls/comctl32/tests/treeview.c | 119 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)

diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index 9031a83..41168b5 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -51,6 +51,21 @@ static BOOL g_v6;
 
 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
 
+static void flush_events(void)
+{
+    MSG msg;
+    int diff = 200;
+    int min_timeout = 100;
+    DWORD time = GetTickCount() + diff;
+
+    while (diff > 0)
+    {
+        if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
+        while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
+        diff = time - GetTickCount();
+    }
+}
+
 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
 static struct msg_sequence *item_sequence[1];
 
@@ -342,6 +357,49 @@ static const struct message parent_vk_return_seq[] = {
     { 0 }
 };
 
+static const struct message right_click_treeview_seq[] = {
+    { 0x2100, sent|optional },
+    { 0x2100, sent|optional },
+    { WM_NCHITTEST, sent },
+    { WM_SETCURSOR, sent },
+    { WM_MOUSEFIRST, sent },
+    { WM_NCHITTEST, sent },
+    { WM_MOUSEACTIVATE, sent },
+    { WM_SETCURSOR, sent },
+    { WM_RBUTTONDOWN, sent },
+    { WM_CAPTURECHANGED, sent|defwinproc },
+    { TVM_GETNEXTITEM, sent|defwinproc },
+    { WM_NCHITTEST, sent },
+    { WM_SETCURSOR, sent },
+    { WM_MOUSEFIRST, sent },
+    { WM_PAINT, sent },
+    { 0 }
+};
+
+static const struct message right_click_parent_seq[] = {
+    { WM_NCACTIVATE, sent|optional },
+    { WM_WINDOWPOSCHANGING, sent|optional },
+    { WM_WINDOWPOSCHANGED, sent|optional },
+    { WM_NOTIFY, sent|id, 0, 0, NM_SETCURSOR },
+    { WM_SETCURSOR, sent },
+    { WM_PARENTNOTIFY, sent },
+    { WM_MOUSEACTIVATE, sent },
+    { WM_NOTIFY, sent|id, 0, 0, NM_SETCURSOR },
+    { WM_SETCURSOR, sent },
+    { WM_NOTIFY, sent|id, 0, 0, NM_RCLICK },
+    { WM_CONTEXTMENU, sent },
+    { WM_NOTIFY, sent|id, 0, 0, NM_SETCURSOR },
+    { WM_SETCURSOR, sent },
+    { WM_CTLCOLOREDIT, sent },
+    { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
+    { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
+    { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
+    { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
+    { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
+    { WM_NOTIFY, sent|id, 0, 0, NM_CUSTOMDRAW },
+    { 0 }
+};
+
 static HWND hMainWnd;
 
 static HTREEITEM hRoot, hChild;
@@ -1299,6 +1357,13 @@ static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam,
                 }
                 break;
             }
+            case NM_RCLICK:
+            {
+                HTREEITEM selected = (HTREEITEM)SendMessageA(((NMHDR *)lParam)->hwndFrom,
+                                                             TVM_GETNEXTITEM, TVGN_CARET, 0);
+                ok(selected == hChild, "child item should still be selected\n");
+                break;
+            }
             }
         }
         break;
@@ -2397,6 +2462,59 @@ static void test_TVS_FULLROWSELECT(void)
     DestroyWindow(hwnd);
 }
 
+static void test_right_click(void)
+{
+    HWND hTree;
+    HTREEITEM selected;
+    RECT rc;
+    LRESULT result;
+    POINT pt;
+    INPUT ip[2];
+
+    flush_sequences(sequences, NUM_MSG_SEQUENCES);
+
+    hTree = create_treeview_control(0);
+    fill_tree(hTree);
+
+    SendMessageA(hTree, TVM_ENSUREVISIBLE, 0, (LPARAM)hChild);
+    SendMessageA(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
+    selected = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CARET, 0);
+    ok(selected == hChild, "child item not selected\n");
+
+    *(HTREEITEM *)&rc = hRoot;
+    result = SendMessageA(hTree, TVM_GETITEMRECT, TRUE, (LPARAM)&rc);
+    ok(result, "TVM_GETITEMRECT failed\n");
+
+    pt.x = rc.left + (rc.right - rc.left)/2;
+    pt.y = rc.top + (rc.bottom - rc.top)/2;
+    ClientToScreen(hMainWnd, &pt);
+
+    ShowWindow(hMainWnd, SW_SHOW);
+    UpdateWindow(hMainWnd);
+    SetCursorPos(pt.x, pt.y);
+
+    flush_events();
+    flush_sequences(sequences, NUM_MSG_SEQUENCES);
+
+    ZeroMemory(ip, sizeof(ip));
+    ip[0].type = INPUT_MOUSE;
+    ip[0].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
+    ip[1].type = INPUT_MOUSE;
+    ip[1].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
+    SendInput(2, ip, sizeof(INPUT));
+
+    flush_events();
+    ok_sequence(sequences, TREEVIEW_SEQ_INDEX, right_click_treeview_seq,
+                "right click treeview sequence", TRUE);
+    ok_sequence(sequences, PARENT_SEQ_INDEX, right_click_parent_seq,
+                "right click parent sequence", TRUE);
+
+    selected = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CARET, 0);
+    ok(selected == hChild, "child item should still be selected\n");
+
+    DestroyWindow(hTree);
+}
+
 START_TEST(treeview)
 {
     HMODULE hComctl32;
@@ -2473,6 +2591,7 @@ START_TEST(treeview)
     test_customdraw();
     test_WM_KEYDOWN();
     test_TVS_FULLROWSELECT();
+    test_right_click();
 
     if (!load_v6_module(&ctx_cookie, &hCtx))
     {
-- 
2.7.4




More information about the wine-patches mailing list