From adf77c1abe6af1dfa746a5299c772947c575070a Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Tue, 29 Aug 2023 19:13:56 -0600 Subject: [PATCH] user32/tests: Test more flags for MessageBox. --- dlls/user32/tests/dialog.c | 72 ++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index 21958ddb193..99f52769e73 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -2123,15 +2123,36 @@ static void test_timer_message(void) DialogBoxA(g_hinst, "RADIO_TEST_DIALOG", NULL, timer_message_dlg_proc); } +static unsigned int msgbox_hook_proc_called; +static UINT msgbox_type; + static LRESULT CALLBACK msgbox_hook_proc(INT code, WPARAM wParam, LPARAM lParam) { + static const LONG considered_ex_styles = WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME | WS_EX_TOPMOST; + if (code == HCBT_ACTIVATE) { HWND msgbox = (HWND)wParam, msghwnd; + LONG exstyles, expected_exstyles; + BOOL system_modal; char text[64]; if (msgbox) { + exstyles = GetWindowLongA(msgbox, GWL_EXSTYLE) & considered_ex_styles; + + ++msgbox_hook_proc_called; + system_modal = msgbox_type & MB_SYSTEMMODAL && !(msgbox_type & MB_TASKMODAL); + expected_exstyles = WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE; + if ((msgbox_type & MB_TOPMOST) || system_modal) + expected_exstyles |= WS_EX_TOPMOST; + if (!system_modal) + expected_exstyles |= WS_EX_DLGMODALFRAME; + + todo_wine_if((system_modal && exstyles == (expected_exstyles | WS_EX_DLGMODALFRAME)) + || (!system_modal && msgbox_type & MB_TOPMOST)) + ok(exstyles == expected_exstyles, "got %#lx, expected %#lx\n", exstyles, expected_exstyles); + text[0] = 0; GetWindowTextA(msgbox, text, sizeof(text)); ok(!strcmp(text, "MSGBOX caption"), "Unexpected window text \"%s\"\n", text); @@ -2141,26 +2162,9 @@ static LRESULT CALLBACK msgbox_hook_proc(INT code, WPARAM wParam, LPARAM lParam) text[0] = 0; GetWindowTextA(msghwnd, text, sizeof(text)); - ok(!strcmp(text, "Text"), "Unexpected window text \"%s\"\n", text); - - SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONDOWN, 0, 0); - SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONUP, 0, 0); - } - } - - return CallNextHookEx(NULL, code, wParam, lParam); -} - -static LRESULT CALLBACK msgbox_sysmodal_hook_proc(INT code, WPARAM wParam, LPARAM lParam) -{ - if (code == HCBT_ACTIVATE) - { - HWND msgbox = (HWND)wParam; - LONG exstyles = GetWindowLongA(msgbox, GWL_EXSTYLE); - if (msgbox) - { - ok(exstyles & WS_EX_TOPMOST, "expected message box to have topmost exstyle set\n"); + todo_wine_if(msgbox_type != MB_OKCANCEL && !*text) + ok(!strcmp(text, "Text"), "Unexpected window text \"%s\"\n", text); SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONDOWN, 0, 0); SendDlgItemMessageA(msgbox, IDCANCEL, WM_LBUTTONUP, 0, 0); @@ -2172,20 +2176,32 @@ static LRESULT CALLBACK msgbox_sysmodal_hook_proc(INT code, WPARAM wParam, LPARA static void test_MessageBox(void) { + static const UINT tests[] = + { + MB_OKCANCEL, + MB_OKCANCEL | MB_SYSTEMMODAL, + MB_OKCANCEL | MB_TASKMODAL | MB_SYSTEMMODAL, + MB_OKCANCEL | MB_TOPMOST, + MB_OKCANCEL | MB_TOPMOST | MB_SYSTEMMODAL, + MB_OKCANCEL | MB_TASKMODAL | MB_TOPMOST, + MB_OKCANCEL | MB_TASKMODAL | MB_SYSTEMMODAL | MB_TOPMOST, + }; + unsigned int i; HHOOK hook; int ret; hook = SetWindowsHookExA(WH_CBT, msgbox_hook_proc, NULL, GetCurrentThreadId()); - ret = MessageBoxA(NULL, "Text", "MSGBOX caption", MB_OKCANCEL); - ok(ret == IDCANCEL, "got %d\n", ret); - - UnhookWindowsHookEx(hook); - - /* Test for MB_SYSTEMMODAL */ - hook = SetWindowsHookExA(WH_CBT, msgbox_sysmodal_hook_proc, NULL, GetCurrentThreadId()); - - MessageBoxA(NULL, NULL, "system modal", MB_OKCANCEL | MB_SYSTEMMODAL); + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + msgbox_type = tests[i]; + winetest_push_context("type %#x", msgbox_type); + msgbox_hook_proc_called = 0; + ret = MessageBoxA(NULL, "Text", "MSGBOX caption", msgbox_type); + ok(ret == IDCANCEL, "got %d\n", ret); + ok(msgbox_hook_proc_called, "got %u.\n", msgbox_hook_proc_called); + winetest_pop_context(); + } UnhookWindowsHookEx(hook); } -- 2.11.4.GIT