user32/tests: Add test for nested default Button in Dialogs

André Hentschel nerv at dawncrow.de
Thu Feb 10 13:22:48 CST 2011


somehow related to http://bugs.winehq.org/show_bug.cgi?id=12804 (winecfg: pressing enter in library override closes winecfg)
---
 dlls/user32/tests/dialog.c |   73 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c
index 736c99d..cf799e3 100644
--- a/dlls/user32/tests/dialog.c
+++ b/dlls/user32/tests/dialog.c
@@ -50,7 +50,7 @@ static HWND g_hwndTestDlg, g_hwndTestDlgBut1, g_hwndTestDlgBut2, g_hwndTestDlgEd
 static HWND g_hwndInitialFocusT1, g_hwndInitialFocusT2, g_hwndInitialFocusGroupBox;
 
 static LONG g_styleInitialFocusT1, g_styleInitialFocusT2;
-static BOOL g_bInitialFocusInitDlgResult;
+static BOOL g_bInitialFocusInitDlgResult, g_bReceivedCommand;
 
 static int g_terminated;
 
@@ -544,6 +544,27 @@ static LRESULT CALLBACK testDlgWinProc (HWND hwnd, UINT uiMsg, WPARAM wParam,
     return DefDlgProcA (hwnd, uiMsg, wParam, lParam);
 }
 
+static LRESULT CALLBACK TestNestedDefButtonDlgProc (HWND hwnd, UINT uiMsg, WPARAM wParam,
+        LPARAM lParam)
+{
+    switch (uiMsg)
+    {
+        /* Add blank case statements for these to ensure we don't use them
+         * by mistake.
+         */
+        case DM_GETDEFID: break;
+        case DM_SETDEFID: break;
+
+        case WM_CREATE:
+            return TRUE;
+        case WM_COMMAND:
+            if(LOWORD(wParam) == 300) g_bReceivedCommand = TRUE;
+            break;
+    }
+
+    return DefDlgProcA (hwnd, uiMsg, wParam, lParam);
+}
+
 static BOOL RegisterWindowClasses (void)
 {
     WNDCLASSA cls;
@@ -571,6 +592,10 @@ static BOOL RegisterWindowClasses (void)
     cls.lpszClassName = "WM_NEXTDLGCTLWndClass";
     if (!RegisterClassA (&cls)) return FALSE;
 
+    cls.lpfnWndProc = TestNestedDefButtonDlgProc;
+    cls.lpszClassName = "NestedDefButtonWndClass";
+    if (!RegisterClassA (&cls)) return FALSE;
+
     return TRUE;
 }
 
@@ -943,6 +968,51 @@ static void test_GetDlgItem(void)
     DestroyWindow(hwnd);
 }
 
+static void test_NestedDefButton(void)
+{
+    HWND hwnd, child1, child2, child3;
+    DWORD dw;
+    MSG msg;
+
+    hwnd = CreateWindowEx( WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR
+              | WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW,
+              "NestedDefButtonWndClass",
+              "NestedDefButtonWndClass test window",
+              WS_POPUPWINDOW | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_OVERLAPPED |
+              WS_MINIMIZEBOX | WS_MAXIMIZEBOX | DS_3DLOOK | DS_SETFONT | DS_MODALFRAME,
+              0, 0, 100, 100,
+              NULL, NULL, g_hinst, 0);
+    ok(hwnd != NULL, "failed to create window\n");
+
+    child1 = CreateWindowA("button", "child1", WS_VISIBLE|WS_CHILD, 0, 0, 50, 50, hwnd, (HMENU)100, g_hinst, NULL);
+    ok(child1 != NULL, "failed to create first child\n");
+    child2 = CreateWindowA("button", "child2", WS_VISIBLE|WS_CHILD, 60, 60, 30, 30, hwnd, (HMENU)200, g_hinst, NULL);
+    ok(child2 != NULL, "failed to create second child\n");
+    /* create nested child */
+    child3 = CreateWindowA("button", "child3", WS_VISIBLE|WS_CHILD, 10, 10, 10, 10, child1, (HMENU)300, g_hinst, NULL);
+    ok(child3 != NULL, "failed to create subchild\n");
+
+    DefDlgProcA( hwnd, DM_SETDEFID, 200, 0);
+    dw = DefDlgProcA( hwnd, DM_GETDEFID, 0, 0);
+    ok(LOWORD(dw) == 200, "expected 200, got %x\n", dw);
+
+    DefDlgProcA( hwnd, DM_SETDEFID, 300, 0);
+    dw = DefDlgProcA( hwnd, DM_GETDEFID, 0, 0);
+    ok(LOWORD(dw) == 300, "expected 300, got %x\n", dw);
+    ok(SendMessageW( child3, WM_GETDLGCODE, 0, 0) != DLGC_DEFPUSHBUTTON,
+       "expected child3 not to be marked as DLGC_DEFPUSHBUTTON\n");
+
+    g_bReceivedCommand = FALSE;
+    FormEnterMsg (&msg, child3);
+    ok(IsDialogMessage (hwnd, &msg), "Did not handle the ENTER\n");
+    todo_wine ok(g_bReceivedCommand, "Did not triggered the default Button action\n");
+
+    DestroyWindow(child3);
+    DestroyWindow(child2);
+    DestroyWindow(child1);
+    DestroyWindow(hwnd);
+}
+
 static INT_PTR CALLBACK DestroyDlgWinProc (HWND hDlg, UINT uiMsg,
         WPARAM wParam, LPARAM lParam)
 {
@@ -1288,6 +1358,7 @@ START_TEST(dialog)
     test_initial_focus();
     test_GetDlgItem();
     test_GetDlgItemText();
+    test_NestedDefButton();
     test_DialogBoxParamA();
     test_DisabledDialogTest();
     test_MessageBoxFontTest();
-- 

Best Regards, André Hentschel



More information about the wine-patches mailing list