From: Amine Khaldi Date: Thu, 17 May 2012 16:52:25 +0000 (+0000) Subject: [RICHED20_WINETEST] X-Git-Tag: backups/ros-csrss@57560~940 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=755ed9d608798f428b3cc29263e535b05af096fb;hp=5356fc09852da9d9613e5ba2c3256f316203a8a9 [RICHED20_WINETEST] * Sync to Wine 1.5.4. svn path=/trunk/; revision=56603 --- diff --git a/rostests/winetests/riched20/editor.c b/rostests/winetests/riched20/editor.c index 827f35dffe4..9347ed7c489 100644 --- a/rostests/winetests/riched20/editor.c +++ b/rostests/winetests/riched20/editor.c @@ -6366,7 +6366,7 @@ static void test_format_rect(void) /* Reset to default rect and check how the format rect adjusts to window * resize and how it copes with very small windows */ - SendMessageA(hwnd, EM_SETRECT, 0, (LPARAM)NULL); + SendMessageA(hwnd, EM_SETRECT, 0, 0); MoveWindow(hwnd, 0, 0, 100, 30, FALSE); GetClientRect(hwnd, &clientRect); @@ -7172,6 +7172,114 @@ static void test_EM_FINDWORDBREAK_A(void) DestroyWindow(hwndRichEdit); } +/* + * This test attempts to show the effect of enter on a richedit + * control v1.0 inserts CRLF whereas for higher versions it only + * inserts CR. If shows that EM_GETTEXTEX with GT_USECRLF == WM_GETTEXT + * and also shows that GT_USECRLF has no effect in richedit 1.0, but + * does for higher. The same test is cloned in riched32 and riched20. + */ +static void test_enter(void) +{ + static const struct { + const char *initialtext; + const int cursor; + const char *expectedwmtext; + const char *expectedemtext; + const char *expectedemtextcrlf; + } testenteritems[] = { + { "aaabbb\r\n", 3, "aaa\r\nbbb\r\n", "aaa\rbbb\r", "aaa\r\nbbb\r\n"}, + { "aaabbb\r\n", 6, "aaabbb\r\n\r\n", "aaabbb\r\r", "aaabbb\r\n\r\n"}, + { "aa\rabbb\r\n", 7, "aa\r\nabbb\r\n\r\n", "aa\rabbb\r\r", "aa\r\nabbb\r\n\r\n"}, + { "aa\rabbb\r\n", 3, "aa\r\n\r\nabbb\r\n", "aa\r\rabbb\r", "aa\r\n\r\nabbb\r\n"}, + { "aa\rabbb\r\n", 2, "aa\r\n\r\nabbb\r\n", "aa\r\rabbb\r", "aa\r\n\r\nabbb\r\n"} + }; + + char expectedbuf[1024]; + char resultbuf[1024]; + HWND hwndRichEdit = new_richedit(NULL); + UINT i,j; + + for (i = 0; i < sizeof(testenteritems)/sizeof(testenteritems[0]); i++) { + + char buf[1024] = {0}; + LRESULT result; + GETTEXTEX getText; + const char *expected; + + /* Set the text to the initial text */ + result = SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) testenteritems[i].initialtext); + ok (result == 1, "[%d] WM_SETTEXT returned %ld instead of 1\n", i, result); + + /* Send Enter */ + SendMessage(hwndRichEdit, EM_SETSEL, testenteritems[i].cursor, testenteritems[i].cursor); + simulate_typing_characters(hwndRichEdit, "\r"); + + /* 1. Retrieve with WM_GETTEXT */ + buf[0] = 0x00; + result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buf); + expected = testenteritems[i].expectedwmtext; + + resultbuf[0]=0x00; + for (j = 0; j < (UINT)result; j++) + sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); + expectedbuf[0] = '\0'; + for (j = 0; j < strlen(expected); j++) + sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + + result = strcmp(expected, buf); + ok (result == 0, + "[%d] WM_GETTEXT unexpected '%s' expected '%s'\n", + i, resultbuf, expectedbuf); + + /* 2. Retrieve with EM_GETTEXTEX, GT_DEFAULT */ + getText.cb = sizeof(buf); + getText.flags = GT_DEFAULT; + getText.codepage = CP_ACP; + getText.lpDefaultChar = NULL; + getText.lpUsedDefChar = NULL; + buf[0] = 0x00; + result = SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf); + expected = testenteritems[i].expectedemtext; + + resultbuf[0]=0x00; + for (j = 0; j < (UINT)result; j++) + sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); + expectedbuf[0] = '\0'; + for (j = 0; j < strlen(expected); j++) + sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + + result = strcmp(expected, buf); + ok (result == 0, + "[%d] EM_GETTEXTEX, GT_DEFAULT unexpected '%s', expected '%s'\n", + i, resultbuf, expectedbuf); + + /* 3. Retrieve with EM_GETTEXTEX, GT_USECRLF */ + getText.cb = sizeof(buf); + getText.flags = GT_USECRLF; + getText.codepage = CP_ACP; + getText.lpDefaultChar = NULL; + getText.lpUsedDefChar = NULL; + buf[0] = 0x00; + result = SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf); + expected = testenteritems[i].expectedemtextcrlf; + + resultbuf[0]=0x00; + for (j = 0; j < (UINT)result; j++) + sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF); + expectedbuf[0] = '\0'; + for (j = 0; j < strlen(expected); j++) + sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF); + + result = strcmp(expected, buf); + ok (result == 0, + "[%d] EM_GETTEXTEX, GT_USECRLF unexpected '%s', expected '%s'\n", + i, resultbuf, expectedbuf); + } + + DestroyWindow(hwndRichEdit); +} + START_TEST( editor ) { BOOL ret; @@ -7230,6 +7338,7 @@ START_TEST( editor ) test_dialogmode(); test_EM_FINDWORDBREAK_W(); test_EM_FINDWORDBREAK_A(); + test_enter(); /* Set the environment variable WINETEST_RICHED20 to keep windows * responsive and open for 30 seconds. This is useful for debugging. diff --git a/rostests/winetests/riched20/txtsrv.c b/rostests/winetests/riched20/txtsrv.c index 8d126ea4a95..fbd1f6bba61 100644 --- a/rostests/winetests/riched20/txtsrv.c +++ b/rostests/winetests/riched20/txtsrv.c @@ -21,6 +21,7 @@ */ #define COBJMACROS +#define CONST_VTABLE #include #include @@ -38,6 +39,7 @@ static HMODULE hmoduleRichEdit; static IID *pIID_ITextServices; static IID *pIID_ITextHost; static IID *pIID_ITextHost2; +static PCreateTextServices pCreateTextServices; static const char *debugstr_guid(REFIID riid) { @@ -620,7 +622,6 @@ static BOOL init_texthost(void) { IUnknown *init; HRESULT result; - PCreateTextServices pCreateTextServices; dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost)); if (dummyTextHost == NULL) { @@ -633,7 +634,6 @@ static BOOL init_texthost(void) /* MSDN states that an IUnknown object is returned by CreateTextServices which is then queried to obtain a ITextServices object. */ - pCreateTextServices = (void*)GetProcAddress(hmoduleRichEdit, "CreateTextServices"); result = (*pCreateTextServices)(NULL, &dummyTextHost->ITextHost_iface, &init); ok(result == S_OK, "Did not return S_OK when created (result = %x)\n", result); if (result != S_OK) { @@ -812,6 +812,69 @@ static void test_IIDs(void) "unexpected value for IID_ITextHost2: %s\n", debugstr_guid(pIID_ITextHost2)); } +/* Outer IUnknown for COM aggregation tests */ +struct unk_impl { + IUnknown IUnknown_iface; + LONG ref; + IUnknown *inner_unk; +}; + +static inline struct unk_impl *impl_from_IUnknown(IUnknown *iface) +{ + return CONTAINING_RECORD(iface, struct unk_impl, IUnknown_iface); +} + +static HRESULT WINAPI unk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv) +{ + struct unk_impl *This = impl_from_IUnknown(iface); + + return IUnknown_QueryInterface(This->inner_unk, riid, ppv); +} + +static ULONG WINAPI unk_AddRef(IUnknown *iface) +{ + struct unk_impl *This = impl_from_IUnknown(iface); + + return InterlockedIncrement(&This->ref); +} + +static ULONG WINAPI unk_Release(IUnknown *iface) +{ + struct unk_impl *This = impl_from_IUnknown(iface); + + return InterlockedDecrement(&This->ref); +} + +static const IUnknownVtbl unk_vtbl = +{ + unk_QueryInterface, + unk_AddRef, + unk_Release +}; + +static void test_COM(void) +{ + struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL}; + struct ITextHostTestImpl texthost = {{&itextHostVtbl}, 1}; + ITextServices *textsrv; + ULONG refcount; + HRESULT hr; + + /* COM aggregation */ + hr = pCreateTextServices(&unk_obj.IUnknown_iface, &texthost.ITextHost_iface, + &unk_obj.inner_unk); + ok(hr == S_OK, "CreateTextServices failed: %08x\n", hr); + hr = IUnknown_QueryInterface(unk_obj.inner_unk, pIID_ITextServices, (void**)&textsrv); + ok(hr == S_OK, "QueryInterface for IID_ITextServices failed: %08x\n", hr); + refcount = ITextServices_AddRef(textsrv); + ok(refcount == unk_obj.ref, "CreateTextServices just pretends to support COM aggregation\n"); + refcount = ITextServices_Release(textsrv); + ok(refcount == unk_obj.ref, "CreateTextServices just pretends to support COM aggregation\n"); + refcount = ITextServices_Release(textsrv); + ok(refcount == 19, "Refcount should be back at 19 but is %u\n", refcount); + + IUnknown_Release(unk_obj.inner_unk); +} START_TEST( txtsrv ) { @@ -825,7 +888,10 @@ START_TEST( txtsrv ) pIID_ITextServices = (IID*)GetProcAddress(hmoduleRichEdit, "IID_ITextServices"); pIID_ITextHost = (IID*)GetProcAddress(hmoduleRichEdit, "IID_ITextHost"); pIID_ITextHost2 = (IID*)GetProcAddress(hmoduleRichEdit, "IID_ITextHost2"); + pCreateTextServices = (void*)GetProcAddress(hmoduleRichEdit, "CreateTextServices"); + test_IIDs(); + test_COM(); if (init_texthost()) {