[USER32_WINETEST] Sync everything except win.c with Wine Staging 3.3. CORE-14434

This commit is contained in:
Amine Khaldi 2018-04-03 13:49:56 +01:00
parent 47e04dae50
commit d558fc75a2
24 changed files with 1947 additions and 584 deletions

View file

@ -18,7 +18,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "precomp.h"
#include <assert.h>
#include <windows.h>
#include <commctrl.h>
#include "wine/test.h"
#ifndef ES_COMBO
#define ES_COMBO 0x200
@ -34,17 +38,6 @@ struct edit_notify {
static struct edit_notify notifications;
static BOOL (WINAPI *pEndMenu) (void);
static BOOL (WINAPI *pGetMenuBarInfo)(HWND,LONG,LONG,PMENUBARINFO);
static void init_function_pointers(void)
{
HMODULE hdll = GetModuleHandleA("user32");
pEndMenu = (void*)GetProcAddress(hdll, "EndMenu");
pGetMenuBarInfo = (void*)GetProcAddress(hdll, "GetMenuBarInfo");
}
static INT_PTR CALLBACK multi_edit_dialog_proc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
static int num_ok_commands = 0;
@ -564,6 +557,18 @@ static HWND create_editcontrol (DWORD style, DWORD exstyle)
return handle;
}
static HWND create_editcontrolW(DWORD style, DWORD exstyle)
{
static const WCHAR testtextW[] = {'T','e','s','t',' ','t','e','x','t',0};
static const WCHAR editW[] = {'E','d','i','t',0};
HWND handle;
handle = CreateWindowExW(exstyle, editW, testtextW, style, 10, 10, 300, 300,
NULL, NULL, hinst, NULL);
ok(handle != NULL, "Failed to create Edit control.\n");
return handle;
}
static HWND create_child_editcontrol (DWORD style, DWORD exstyle)
{
HWND parentWnd;
@ -863,7 +868,7 @@ static LRESULT CALLBACK edit3_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPAR
return DefWindowProcA(hWnd, msg, wParam, lParam);
}
/* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notificatisons sent in response
/* Test behaviour of WM_SETTEXT, WM_REPLACESEL and notifications sent in response
* to these messages.
*/
static void test_edit_control_3(void)
@ -965,6 +970,19 @@ static void test_edit_control_3(void)
ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
test_notify(1, 0, 1);
SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
zero_notify();
SendMessageA(hWnd, EM_REPLACESEL, 0, (LPARAM)str2);
len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
test_notify(1, 0, 1);
zero_notify();
SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)str2);
len = SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0);
ok(lstrlenA(str2) == len, "text shouldn't have been truncated\n");
test_notify(1, 0, 1);
SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");
@ -2277,7 +2295,7 @@ static LRESULT CALLBACK edit4_wnd_procA(HWND hWnd, UINT msg, WPARAM wParam, LPAR
if (hWnd != (HWND)lParam)
{
got_wm_capturechanged = TRUE;
pEndMenu();
EndMenu();
}
break;
}
@ -2295,9 +2313,8 @@ static LRESULT CALLBACK edit_proc_proxy(HWND hWnd, UINT msg, WPARAM wParam, LPAR
memset(&mbi, 0, sizeof(mbi));
mbi.cbSize = sizeof(mbi);
SetLastError(0xdeadbeef);
ret = pGetMenuBarInfo(ctx_menu, OBJID_CLIENT, 0, &mbi);
ok(ret || broken(!ret && GetLastError()==ERROR_INVALID_WINDOW_HANDLE) /* NT */,
"GetMenuBarInfo failed\n");
ret = GetMenuBarInfo(ctx_menu, OBJID_CLIENT, 0, &mbi);
ok(ret, "GetMenuBarInfo failed\n");
if (ret)
{
ok(mbi.hMenu != NULL, "mbi.hMenu = NULL\n");
@ -2309,9 +2326,8 @@ static LRESULT CALLBACK edit_proc_proxy(HWND hWnd, UINT msg, WPARAM wParam, LPAR
memset(&mbi, 0, sizeof(mbi));
mbi.cbSize = sizeof(mbi);
SetLastError(0xdeadbeef);
ret = pGetMenuBarInfo(ctx_menu, OBJID_CLIENT, 1, &mbi);
ok(ret || broken(!ret && GetLastError()==ERROR_INVALID_WINDOW_HANDLE) /* NT */,
"GetMenuBarInfo failed\n");
ret = GetMenuBarInfo(ctx_menu, OBJID_CLIENT, 1, &mbi);
ok(ret, "GetMenuBarInfo failed\n");
if (ret)
{
ok(mbi.hMenu != NULL, "mbi.hMenu = NULL\n");
@ -2320,7 +2336,7 @@ static LRESULT CALLBACK edit_proc_proxy(HWND hWnd, UINT msg, WPARAM wParam, LPAR
ok(!mbi.fFocused, "mbi.fFocused = TRUE\n");
}
pEndMenu();
EndMenu();
break;
}
}
@ -2341,7 +2357,7 @@ static LRESULT CALLBACK child_edit_menu_proc(HWND hwnd, UINT msg, WPARAM wParam,
if (wParam == MSGF_MENU) {
HWND hwndMenu = (HWND)lParam;
MENUBARINFO mbi = { sizeof(MENUBARINFO) };
if (pGetMenuBarInfo(hwndMenu, OBJID_CLIENT, 0, &mbi)) {
if (GetMenuBarInfo(hwndMenu, OBJID_CLIENT, 0, &mbi)) {
MENUITEMINFOA mii = { sizeof(MENUITEMINFOA), MIIM_STATE };
if (GetMenuItemInfoA(mbi.hMenu, EM_SETSEL, FALSE, &mii)) {
if (mii.fState & MFS_HILITE) {
@ -2387,11 +2403,8 @@ static void test_contextmenu(void)
ok(got_en_setfocus, "edit box didn't get focused\n");
ok(got_wm_capturechanged, "main window capture did not change\n");
if (pGetMenuBarInfo)
{
p_edit_proc = (void*)SetWindowLongPtrA(hwndEdit, GWLP_WNDPROC, (ULONG_PTR)edit_proc_proxy);
SendMessageA(hwndEdit, WM_CONTEXTMENU, (WPARAM)hwndEdit, MAKEWORD(10, 10));
}
p_edit_proc = (void*)SetWindowLongPtrA(hwndEdit, GWLP_WNDPROC, (ULONG_PTR)edit_proc_proxy);
SendMessageA(hwndEdit, WM_CONTEXTMENU, (WPARAM)hwndEdit, MAKEWORD(10, 10));
DestroyWindow (hwndEdit);
@ -2718,6 +2731,7 @@ static void test_EM_GETHANDLE(void)
{
static const char str0[] = "untouched";
static const char str1[] = "1111+1111+1111#";
static const char str1_1[] = "2111+1111+1111#";
static const char str2[] = "2222-2222-2222-2222#";
static const char str3[] = "3333*3333*3333*3333*3333#";
CHAR current[42];
@ -2766,6 +2780,44 @@ static void test_EM_GETHANDLE(void)
"got %d and \"%s\" (expected %d and \"%s\")\n", len, buffer, lstrlenA(str1), str1);
LocalUnlock(hmem);
/* See if WM_GETTEXTLENGTH/WM_GETTEXT still work. */
len = SendMessageA(hEdit, WM_GETTEXTLENGTH, 0, 0);
ok(len == lstrlenA(str1), "Unexpected text length %d.\n", len);
lstrcpyA(current, str0);
r = SendMessageA(hEdit, WM_GETTEXT, sizeof(current), (LPARAM)current);
ok((r == lstrlenA(str1)) && !lstrcmpA(current, str1),
"Unexpected retval %d and text \"%s\" (expected %d and \"%s\")\n", r, current, lstrlenA(str1), str1);
/* Application altered buffer contents, see if WM_GETTEXTLENGTH/WM_GETTEXT pick that up. */
buffer = LocalLock(hmem);
ok(buffer != NULL, "got %p (expected != NULL)\n", buffer);
buffer[0] = '2';
LocalUnlock(hmem);
len = SendMessageA(hEdit, WM_GETTEXTLENGTH, 0, 0);
ok(len == lstrlenA(str1_1), "Unexpected text length %d.\n", len);
lstrcpyA(current, str0);
r = SendMessageA(hEdit, WM_GETTEXT, sizeof(current), (LPARAM)current);
ok((r == lstrlenA(str1_1)) && !lstrcmpA(current, str1_1),
"Unexpected retval %d and text \"%s\" (expected %d and \"%s\")\n", r, current, lstrlenA(str1_1), str1_1);
/* See if WM_SETTEXT/EM_REPLACESEL work. */
r = SendMessageA(hEdit, WM_SETTEXT, 0, (LPARAM)str1);
ok(r, "Failed to set text.\n");
buffer = LocalLock(hmem);
ok(buffer != NULL && buffer[0] == '1', "Unexpected buffer contents\n");
LocalUnlock(hmem);
r = SendMessageA(hEdit, EM_REPLACESEL, 0, (LPARAM)str1_1);
ok(r, "Failed to replace selection.\n");
buffer = LocalLock(hmem);
ok(buffer != NULL && buffer[0] == '2', "Unexpected buffer contents\n");
LocalUnlock(hmem);
/* use LocalAlloc first to get a different handle */
halloc = LocalAlloc(LMEM_MOVEABLE, 42);
ok(halloc != NULL, "got %p (expected != NULL)\n", halloc);
@ -2827,13 +2879,161 @@ static void test_EM_GETHANDLE(void)
DestroyWindow(hEdit);
}
static void test_paste(void)
{
HWND hEdit, hMultilineEdit;
HANDLE hmem, hmem_ret;
char *buffer;
int r, len;
static const char *str = "this is a simple text";
static const char *str2 = "first line\r\nsecond line";
hEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
hMultilineEdit = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE, 0);
/* Prepare clipboard data with simple text */
hmem = GlobalAlloc(GMEM_MOVEABLE, 255);
ok(hmem != NULL, "got %p (expected != NULL)\n", hmem);
buffer = GlobalLock(hmem);
ok(buffer != NULL, "got %p (expected != NULL)\n", buffer);
strcpy(buffer, str);
GlobalUnlock(hmem);
r = OpenClipboard(hEdit);
ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
r = EmptyClipboard();
ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
hmem_ret = SetClipboardData(CF_TEXT, hmem);
ok(hmem_ret == hmem, "expected %p, got %p\n", hmem, hmem_ret);
r = CloseClipboard();
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);
/* Prepare clipboard data with multiline text */
hmem = GlobalAlloc(GMEM_MOVEABLE, 255);
ok(hmem != NULL, "got %p (expected != NULL)\n", hmem);
buffer = GlobalLock(hmem);
ok(buffer != NULL, "got %p (expected != NULL)\n", buffer);
strcpy(buffer, str2);
GlobalUnlock(hmem);
r = OpenClipboard(hEdit);
ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
r = EmptyClipboard();
ok(r == TRUE, "expected %d, got %d\n", TRUE, r);
hmem_ret = SetClipboardData(CF_TEXT, hmem);
ok(hmem_ret == hmem, "expected %p, got %p\n", hmem, hmem_ret);
r = CloseClipboard();
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);
/* 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);
/* Cleanup */
DestroyWindow(hEdit);
DestroyWindow(hMultilineEdit);
}
static void test_EM_GETLINE(void)
{
HWND hwnd[2];
int i;
hwnd[0] = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
hwnd[1] = create_editcontrolW(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
for (i = 0; i < sizeof(hwnd)/sizeof(hwnd[0]); i++)
{
static const WCHAR strW[] = {'t','e','x','t',0};
static const char *str = "text";
WCHAR buffW[16];
char buff[16];
int r;
if (i == 0)
ok(!IsWindowUnicode(hwnd[i]), "Expected ansi window.\n");
else
ok(IsWindowUnicode(hwnd[i]), "Expected unicode window.\n");
SendMessageA(hwnd[i], WM_SETTEXT, 0, (LPARAM)str);
memset(buff, 0, sizeof(buff));
*(WORD *)buff = sizeof(buff);
r = SendMessageA(hwnd[i], EM_GETLINE, 0, (LPARAM)buff);
ok(r == strlen(str), "Failed to get a line %d.\n", r);
ok(!strcmp(buff, str), "Unexpected line data %s.\n", buff);
memset(buff, 0, sizeof(buff));
*(WORD *)buff = sizeof(buff);
r = SendMessageA(hwnd[i], EM_GETLINE, 1, (LPARAM)buff);
ok(r == strlen(str), "Failed to get a line %d.\n", r);
ok(!strcmp(buff, str), "Unexpected line data %s.\n", buff);
memset(buffW, 0, sizeof(buffW));
*(WORD *)buffW = sizeof(buffW)/sizeof(buffW[0]);
r = SendMessageW(hwnd[i], EM_GETLINE, 0, (LPARAM)buffW);
ok(r == lstrlenW(strW), "Failed to get a line %d.\n", r);
ok(!lstrcmpW(buffW, strW), "Unexpected line data %s.\n", wine_dbgstr_w(buffW));
memset(buffW, 0, sizeof(buffW));
*(WORD *)buffW = sizeof(buffW)/sizeof(buffW[0]);
r = SendMessageW(hwnd[i], EM_GETLINE, 1, (LPARAM)buffW);
ok(r == lstrlenW(strW), "Failed to get a line %d.\n", r);
ok(!lstrcmpW(buffW, strW), "Unexpected line data %s.\n", wine_dbgstr_w(buffW));
DestroyWindow(hwnd[i]);
}
}
static int CALLBACK test_wordbreak_procA(char *text, int current, int length, int code)
{
return -1;
}
static void test_wordbreak_proc(void)
{
EDITWORDBREAKPROCA proc;
LRESULT ret;
HWND hwnd;
hwnd = create_editcontrol(ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0);
proc = (void *)SendMessageA(hwnd, EM_GETWORDBREAKPROC, 0, 0);
ok(proc == NULL, "Unexpected wordbreak proc %p.\n", proc);
ret = SendMessageA(hwnd, EM_SETWORDBREAKPROC, 0, (LPARAM)test_wordbreak_procA);
ok(ret == 1, "Unexpected return value %ld.\n", ret);
proc = (void *)SendMessageA(hwnd, EM_GETWORDBREAKPROC, 0, 0);
ok(proc == test_wordbreak_procA, "Unexpected wordbreak proc %p.\n", proc);
ret = SendMessageA(hwnd, EM_SETWORDBREAKPROC, 0, 0);
ok(ret == 1, "Unexpected return value %ld.\n", ret);
proc = (void *)SendMessageA(hwnd, EM_GETWORDBREAKPROC, 0, 0);
ok(proc == NULL, "Unexpected wordbreak proc %p.\n", proc);
DestroyWindow(hwnd);
}
START_TEST(edit)
{
BOOL b;
init_function_pointers();
hinst = GetModuleHandleA(NULL);
b = RegisterWindowClasses();
ok (b, "RegisterWindowClasses failed\n");
@ -2861,12 +3061,11 @@ START_TEST(edit)
test_child_edit_wmkeydown();
test_fontsize();
test_dialogmode();
if (pEndMenu)
test_contextmenu();
else
win_skip("EndMenu is not available\n");
test_contextmenu();
test_EM_GETHANDLE();
test_paste();
test_EM_GETLINE();
test_wordbreak_proc();
UnregisterWindowClasses();
}