Module: wine Branch: master Commit: ee5cdea92206050776753c6ac49cc156407be7ad URL: https://gitlab.winehq.org/wine/wine/-/commit/ee5cdea92206050776753c6ac49cc15...
Author: Eric Pouech eric.pouech@gmail.com Date: Mon Jan 9 09:31:07 2023 +0100
comctl32/tests: Fix failing WM_PASTE tests for edit control on Win10+.
There are cases in Windows10+ where the WM_PASTE message doesn't paste the content of the clipboard.
This appeared in testing: - almost always just after (for a couple of milliseconds) setting new content into the clipboard and closing it. - in some unrelated rare occasions (like once for 400 runs).
It looks like another (installed) process had opened the clipboard and forbids the paste command. As WM_PASTE doesn't return success/error status, workaround it by wrapping the WM_PASTE command into a helper, and retry when the clipboard's content hasn't been pasted.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53276 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53277 Signed-off-by: Eric Pouech eric.pouech@gmail.com
---
dlls/comctl32/tests/edit.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/dlls/comctl32/tests/edit.c b/dlls/comctl32/tests/edit.c index fae3091533b..f45b898dc12 100644 --- a/dlls/comctl32/tests/edit.c +++ b/dlls/comctl32/tests/edit.c @@ -3246,6 +3246,26 @@ static void test_EM_GETHANDLE(void) DestroyWindow(hEdit); }
+/* In Windows 10+, the WM_PASTE message isn't always successful. + * So retry in case of failure. + */ +#define check_paste(a, b) _check_paste(__LINE__, (a), (b)) +static void _check_paste(unsigned int line, HWND hedit, const char *content) +{ + /* only retry on windows platform */ + int tries = strcmp(winetest_platform, "wine") ? 3 : 1; + int len = 0; + + SendMessageA(hedit, WM_SETTEXT, 0, (LPARAM)""); + do + { + SendMessageA(hedit, WM_PASTE, 0, 0); + if ((len = SendMessageA(hedit, WM_GETTEXTLENGTH, 0, 0))) break; + Sleep(1); + } while (--tries > 0); + ok_(__FILE__, line)(len == strlen(content), "Unexpected len %u in edit\n", len); +} + static void test_paste(void) { static const char *str = "this is a simple text"; @@ -3253,7 +3273,7 @@ static void test_paste(void) HWND hEdit, hMultilineEdit; HANDLE hmem, hmem_ret; char *buffer; - int r, len; + int r;
hEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0); hMultilineEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE, 0); @@ -3276,10 +3296,7 @@ static void test_paste(void) ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
/* Paste single line */ - SendMessageA(hEdit, WM_SETTEXT, 0, (LPARAM)""); - r = SendMessageA(hEdit, WM_PASTE, 0, 0); - len = SendMessageA(hEdit, WM_GETTEXTLENGTH, 0, 0); - ok(strlen(str) == len, "got %d\n", len); + check_paste(hEdit, str);
/* Prepare clipboard data with multiline text */ hmem = GlobalAlloc(GMEM_MOVEABLE, 255); @@ -3300,15 +3317,10 @@ static void test_paste(void)
/* Paste multiline text in singleline edit - should be cut */ SendMessageA(hEdit, WM_SETTEXT, 0, (LPARAM)""); - r = SendMessageA(hEdit, WM_PASTE, 0, 0); - len = SendMessageA(hEdit, WM_GETTEXTLENGTH, 0, 0); - ok(strlen("first line") == len, "got %d\n", len); + check_paste(hEdit, "first line");
/* Paste multiline text in multiline edit */ - SendMessageA(hMultilineEdit, WM_SETTEXT, 0, (LPARAM)""); - r = SendMessageA(hMultilineEdit, WM_PASTE, 0, 0); - len = SendMessageA(hMultilineEdit, WM_GETTEXTLENGTH, 0, 0); - ok(strlen(str2) == len, "got %d\n", len); + check_paste(hMultilineEdit, str2);
/* Cleanup */ DestroyWindow(hEdit);