Module: wine Branch: master Commit: e9a32c6a8d472756595b6d07e97364ccc73a84a1 URL: https://gitlab.winehq.org/wine/wine/-/commit/e9a32c6a8d472756595b6d07e97364c...
Author: Eric Pouech eric.pouech@gmail.com Date: Mon Jan 9 09:31:05 2023 +0100
comctl32/tests: Retry when opening the clipboard.
As the clipboard is a shared resource, we cannot expect that no other app hasn't openeded it. So wrap clipboard access with a retry feature in case of failure.
Signed-off-by: Eric Pouech eric.pouech@gmail.com
---
dlls/comctl32/tests/edit.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/dlls/comctl32/tests/edit.c b/dlls/comctl32/tests/edit.c index 23caf877aa5..fae3091533b 100644 --- a/dlls/comctl32/tests/edit.c +++ b/dlls/comctl32/tests/edit.c @@ -72,6 +72,35 @@ static void flush_events(void) } }
+static BOOL open_clipboard(HWND hwnd) +{ + DWORD start = GetTickCount(); + while (1) + { + BOOL ret = OpenClipboard(hwnd); + if (ret || GetLastError() != ERROR_ACCESS_DENIED) + return ret; + if (GetTickCount() - start > 100) + { + char classname[256]; + DWORD le = GetLastError(); + HWND clipwnd = GetOpenClipboardWindow(); + /* Provide a hint as to the source of interference: + * - The class name would typically be CLIPBRDWNDCLASS if the + * clipboard was opened by a Windows application using the + * ole32 API. + * - And it would be __wine_clipboard_manager if it was opened in + * response to a native application. + */ + GetClassNameA(clipwnd, classname, ARRAY_SIZE(classname)); + trace("%p (%s) opened the clipboard\n", clipwnd, classname); + SetLastError(le); + return ret; + } + Sleep(15); + } +} + static INT_PTR CALLBACK multi_edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) { static int num_ok_commands = 0; @@ -2264,7 +2293,7 @@ static void test_espassword(void) ok(r == strlen(password), "Expected: %s, got len %ld\n", password, r); ok(strcmp(buffer, password) == 0, "expected %s, got %s\n", password, buffer);
- r = OpenClipboard(hwEdit); + r = open_clipboard(hwEdit); ok(r == TRUE, "expected %d, got %ld\n", TRUE, r); r = EmptyClipboard(); ok(r == TRUE, "expected %d, got %ld\n", TRUE, r); @@ -3237,7 +3266,7 @@ static void test_paste(void) strcpy(buffer, str); GlobalUnlock(hmem);
- r = OpenClipboard(hEdit); + r = open_clipboard(hEdit); ok(r == TRUE, "expected %d, got %d\n", TRUE, r); r = EmptyClipboard(); ok(r == TRUE, "expected %d, got %d\n", TRUE, r); @@ -3260,7 +3289,7 @@ static void test_paste(void) strcpy(buffer, str2); GlobalUnlock(hmem);
- r = OpenClipboard(hEdit); + r = open_clipboard(hEdit); ok(r == TRUE, "expected %d, got %d\n", TRUE, r); r = EmptyClipboard(); ok(r == TRUE, "expected %d, got %d\n", TRUE, r);