From: Eric Pouech eric.pouech@gmail.com
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 91d16e044a0..00ef54dea01 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; @@ -2226,7 +2255,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); @@ -3199,7 +3228,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); @@ -3222,7 +3251,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);