Commit ce78e293 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

user32/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=53276Signed-off-by: 's avatarEric Pouech <eric.pouech@gmail.com>
parent e439611d
......@@ -3204,12 +3204,32 @@ 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)
{
HWND hEdit, hMultilineEdit;
HANDLE hmem, hmem_ret;
char *buffer;
int r, len;
int r;
static const char *str = "this is a simple text";
static const char *str2 = "first line\r\nsecond line";
......@@ -3234,10 +3254,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);
......@@ -3257,16 +3274,10 @@ static void test_paste(void)
ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
/* 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment