Module: wine Branch: master Commit: 386e9fef2bdba38e5e5b564c1ac5ec14c73a85b5 URL: https://gitlab.winehq.org/wine/wine/-/commit/386e9fef2bdba38e5e5b564c1ac5ec1...
Author: Zhiyi Zhang zzhang@codeweavers.com Date: Thu Dec 14 16:07:40 2023 +0800
user32/tests: Add recursive WM_SETCURSOR message tests.
This test show that WM_SETCURSOR gets handled recursively, so in process_mouse_message(), accept_hardware_message() can be called after sending WM_SETCURSOR and no changes are needed there.
---
dlls/user32/tests/msg.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c index 55967286092..2dba792a2a7 100644 --- a/dlls/user32/tests/msg.c +++ b/dlls/user32/tests/msg.c @@ -12637,6 +12637,52 @@ static void test_recursive_hook(void) DestroyWindow(hook_hwnd); }
+static int max_msg_depth; + +static LRESULT WINAPI recursive_messages_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp) +{ + static int msg_depth; + MSG msg; + + if (message == WM_SETCURSOR && max_msg_depth < 25) + { + msg_depth++; + max_msg_depth = max(max_msg_depth, msg_depth); + PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE); + msg_depth--; + } + return DefWindowProcA(hwnd, message, wp, lp); +} + +static void test_recursive_messages(void) +{ + WNDCLASSA cls = {0}; + HWND hwnd; + + cls.lpfnWndProc = recursive_messages_proc; + cls.hInstance = GetModuleHandleA(0); + cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW); + cls.hbrBackground = GetStockObject(WHITE_BRUSH); + cls.lpszClassName = "TestRecursiveMsgClass"; + register_class(&cls); + + hwnd = CreateWindowExA(WS_EX_TOPMOST, "TestRecursiveMsgClass", NULL, WS_POPUP | WS_DISABLED | WS_VISIBLE, 0, 0, + 100, 100, NULL, NULL, NULL, NULL); + ok(hwnd != NULL, "CreateWindowExA failed, error %ld.\n", GetLastError()); + SetForegroundWindow(hwnd); + flush_events(); + + max_msg_depth = 0; + simulate_click(FALSE, 50, 50); + flush_events(); + + /* Expect recursive_messages_proc() gets called recursively for WM_SETCURSOR */ + ok(max_msg_depth == 25, "Got expected %d.\n", max_msg_depth); + + DestroyWindow(hwnd); + UnregisterClassA(cls.lpszClassName, cls.hInstance); +} + static const struct message ScrollWindowPaint1[] = { { WM_PAINT, sent }, { WM_ERASEBKGND, sent|beginpaint }, @@ -20464,6 +20510,7 @@ START_TEST(msg) test_set_hook(); test_recursive_hook(); } + test_recursive_messages(); test_DestroyWindow(); test_DispatchMessage(); test_SendMessageTimeout();