Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/riched20/tests/richole.c | 180 +++++++++++++++++++++++++++++++++- 1 file changed, 177 insertions(+), 3 deletions(-)
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 9f463fd69e0..c2457ae5146 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -3252,9 +3252,22 @@ static void test_InsertObject(void) REOBJECT reo1, reo2, reo3, received_reo; HRESULT hr; HWND hwnd; - LONG count; + const WCHAR *expected_string; + const CHAR *expected_stringA; + ITextSelection *selection; + IDataObject *dataobject; + TEXTRANGEA textrange; + FORMATETC formatetc; + CHARRANGE charrange; + GETTEXTEX gettextex; + STGMEDIUM stgmedium; + WCHAR buffer[1024]; + CHAR bufferA[1024]; + LONG count, result; + ITextRange *range; + BSTR bstr;
- create_interfaces(&hwnd, &reole, &doc, NULL); + create_interfaces(&hwnd, &reole, &doc, &selection); SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
hr = IRichEditOle_InsertObject(reole, NULL); @@ -3352,7 +3365,168 @@ static void test_InsertObject(void) hr = IRichEditOle_GetObject(reole, REO_IOB_SELECTION, &received_reo, REO_GETOBJ_ALL_INTERFACES); ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08x\n", hr);
- release_interfaces(&hwnd, &reole, &doc, NULL); + SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1); + + /* "abc|d|efg" */ + INSERT_REOBJECT(reole, &reo1, 3, 1); + INSERT_REOBJECT(reole, &reo2, 5, 2); + + SendMessageW(hwnd, EM_SETSEL, 2, 3); + result = SendMessageW(hwnd, EM_SELECTIONTYPE, 0, 0); + ok(result == SEL_TEXT, "Got selection type: %x.\n", result); + + SendMessageW(hwnd, EM_SETSEL, 3, 4); + result = SendMessageW(hwnd, EM_SELECTIONTYPE, 0, 0); + todo_wine ok(result == SEL_OBJECT, "Got selection type: %x.\n", result); + todo_wine CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 1, NULL, NULL, reo1.polesite, 1); + + SendMessageW(hwnd, EM_SETSEL, 2, 4); + result = SendMessageW(hwnd, EM_SELECTIONTYPE, 0, 0); + todo_wine ok(result == (SEL_TEXT | SEL_OBJECT), "Got selection type: %x.\n", result); + + SendMessageW(hwnd, EM_SETSEL, 5, 6); + todo_wine CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 1, NULL, NULL, reo2.polesite, 2); + + expected_string = L"abc\xfffc""d\xfffc""efg"; + gettextex.cb = sizeof(buffer); + gettextex.flags = GT_DEFAULT; + gettextex.codepage = 1200; + gettextex.lpDefaultChar = NULL; + gettextex.lpUsedDefChar = NULL; + result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer); + ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result); + todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer)); + + gettextex.flags = GT_RAWTEXT; + memset(buffer, 0, sizeof(buffer)); + result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer); + ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result); + todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer)); + + expected_stringA = "abc d efg"; + memset(bufferA, 0, sizeof(bufferA)); + SendMessageA(hwnd, EM_SETSEL, 0, -1); + result = SendMessageA(hwnd, EM_GETSELTEXT, (WPARAM)sizeof(bufferA), (LPARAM)bufferA); + ok(result == strlen(expected_stringA), "Got wrong length: %d.\n", result); + todo_wine ok(!strcmp(bufferA, expected_stringA), "Got wrong content: %s.\n", bufferA); + + memset(bufferA, 0, sizeof(bufferA)); + textrange.lpstrText = bufferA; + textrange.chrg.cpMin = 0; + textrange.chrg.cpMax = 11; + result = SendMessageA(hwnd, EM_GETTEXTRANGE, 0, (LPARAM)&textrange); + ok(result == strlen(expected_stringA), "Got wrong length: %d.\n", result); + todo_wine ok(!strcmp(bufferA, expected_stringA), "Got wrong content: %s.\n", bufferA); + + expected_string = L"abc\xfffc""d\xfffc""efg\r"; + hr = ITextDocument_Range(doc, 0, 11, &range); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = ITextRange_GetText(range, &bstr); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr)); + todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr)); + SysFreeString(bstr); + hr = ITextRange_SetRange(range, 3, 4); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = ITextRange_GetChar(range, &result); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(result == 0xfffc, "Got char: %c\n", result); + ITextRange_Release(range); + + SendMessageW(hwnd, EM_SETSEL, 0, -1); + hr = ITextSelection_GetText(selection, &bstr); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr)); + todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr)); + SysFreeString(bstr); + SendMessageW(hwnd, EM_SETSEL, 3, 4); + result = 0; + hr = ITextSelection_GetChar(selection, &result); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(result == 0xfffc, "Got char: %c\n", result); + + SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)""); + result = SendMessageW(hwnd, EM_SETTEXTMODE, (WPARAM)TM_PLAINTEXT, 0); + ok(!result, "Got result %x.\n", result); + /* "abc|d|efg" */ + SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1); + INSERT_REOBJECT(reole, &reo1, 3, 1); + INSERT_REOBJECT(reole, &reo2, 5, 2); + + expected_string = L"abc d efg"; + charrange.cpMin = 0; + charrange.cpMax = 11; + hr = IRichEditOle_GetClipboardData(reole, &charrange, 1, &dataobject); + ok(hr == S_OK, "Got hr %#x.\n", hr); + formatetc.cfFormat = CF_UNICODETEXT; + formatetc.dwAspect = DVASPECT_CONTENT; + formatetc.ptd = NULL; + formatetc.tymed = TYMED_HGLOBAL; + formatetc.lindex = -1; + hr = IDataObject_GetData(dataobject, &formatetc, &stgmedium); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(lstrlenW(stgmedium.hGlobal) == lstrlenW(expected_string), "Got wrong length: %d.\n", result); + todo_wine ok(!lstrcmpW(stgmedium.hGlobal, expected_string), "Got wrong content: %s.\n", debugstr_w(stgmedium.hGlobal)); + + expected_string = L"abc\xfffc""d\xfffc""efg"; + gettextex.cb = sizeof(buffer); + gettextex.flags = GT_DEFAULT; + gettextex.codepage = 1200; + gettextex.lpDefaultChar = NULL; + gettextex.lpUsedDefChar = NULL; + result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer); + ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result); + todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer)); + + gettextex.flags = GT_RAWTEXT; + memset(buffer, 0, sizeof(buffer)); + result = SendMessageW(hwnd, EM_GETTEXTEX, (WPARAM)&gettextex, (LPARAM)buffer); + ok(result == lstrlenW(expected_string), "Got wrong length: %d.\n", result); + todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer)); + + expected_stringA = "abc d efg"; + memset(bufferA, 0, sizeof(bufferA)); + SendMessageA(hwnd, EM_SETSEL, 0, -1); + result = SendMessageA(hwnd, EM_GETSELTEXT, (WPARAM)sizeof(bufferA), (LPARAM)bufferA); + ok(result == strlen(expected_stringA), "Got wrong length: %d.\n", result); + todo_wine ok(!strcmp(bufferA, expected_stringA), "Got wrong content: %s.\n", bufferA); + + memset(bufferA, 0, sizeof(bufferA)); + textrange.lpstrText = bufferA; + textrange.chrg.cpMin = 0; + textrange.chrg.cpMax = 11; + result = SendMessageA(hwnd, EM_GETTEXTRANGE, 0, (LPARAM)&textrange); + ok(result == strlen(expected_stringA), "Got wrong length: %d.\n", result); + todo_wine ok(!strcmp(bufferA, expected_stringA), "Got wrong content: %s.\n", bufferA); + + expected_string = L"abc\xfffc""d\xfffc""efg"; + hr = ITextDocument_Range(doc, 0, 11, &range); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = ITextRange_GetText(range, &bstr); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr)); + todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr)); + SysFreeString(bstr); + hr = ITextRange_SetRange(range, 3, 4); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = ITextRange_GetChar(range, &result); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(result == 0xfffc, "Got char: %c\n", result); + ITextRange_Release(range); + + SendMessageW(hwnd, EM_SETSEL, 0, -1); + hr = ITextSelection_GetText(selection, &bstr); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr)); + todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr)); + SysFreeString(bstr); + SendMessageW(hwnd, EM_SETSEL, 3, 4); + result = 0; + hr = ITextSelection_GetChar(selection, &result); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine ok(result == 0xfffc, "Got char: %c\n", result); + + release_interfaces(&hwnd, &reole, &doc, &selection); }
static void test_GetStoryLength(void)