[RICHED20_WINETEST]

* Sync with Wine 1.7.17.
CORE-8080

svn path=/trunk/; revision=62983
This commit is contained in:
Amine Khaldi 2014-04-26 16:55:35 +00:00
parent 8552a1297e
commit 4d0266dc20
3 changed files with 1585 additions and 1197 deletions

File diff suppressed because it is too large Load diff

View file

@ -35,23 +35,64 @@
static HMODULE hmoduleRichEdit;
static HWND new_window(LPCTSTR lpClassName, DWORD dwStyle, HWND parent)
static HWND new_window(LPCSTR lpClassName, DWORD dwStyle, HWND parent)
{
HWND hwnd
= CreateWindow(lpClassName, NULL,
dwStyle | WS_POPUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
0, 0, 200, 60, parent, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", lpClassName, (int) GetLastError());
HWND hwnd = CreateWindowA(lpClassName, NULL,
dwStyle | WS_POPUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
0, 0, 200, 60, parent, NULL, hmoduleRichEdit, NULL);
return hwnd;
}
static HWND new_richedit(HWND parent)
{
return new_window(RICHEDIT_CLASS, ES_MULTILINE, parent);
return new_window(RICHEDIT_CLASS20A, ES_MULTILINE, parent);
}
static BOOL touch_file(LPCWSTR filename)
{
HANDLE file;
START_TEST(richole)
file = CreateFileW(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(file == INVALID_HANDLE_VALUE)
return FALSE;
CloseHandle(file);
return TRUE;
}
static BOOL is_existing_file(LPCWSTR filename)
{
HANDLE file;
file = CreateFileW(filename, GENERIC_READ, 0, NULL,
OPEN_EXISTING, 0, NULL);
if(file == INVALID_HANDLE_VALUE)
return FALSE;
CloseHandle(file);
return TRUE;
}
static void create_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc,
ITextSelection **txtSel)
{
*w = new_richedit(NULL);
SendMessageA(*w, EM_GETOLEINTERFACE, 0, (LPARAM)reOle);
IRichEditOle_QueryInterface(*reOle, &IID_ITextDocument,
(void **) txtDoc);
ITextDocument_GetSelection(*txtDoc, txtSel);
}
static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc,
ITextSelection **txtSel)
{
ITextDocument_Release(*txtDoc);
IRichEditOle_Release(*reOle);
DestroyWindow(*w);
ITextSelection_Release(*txtSel);
}
static void test_Interfaces(void)
{
IRichEditOle *reOle = NULL;
ITextDocument *txtDoc = NULL;
@ -61,18 +102,13 @@ START_TEST(richole)
LRESULT res;
HWND w;
/* Must explicitly LoadLibrary(). The test has no references to functions in
* RICHED20.DLL, so the linker doesn't actually link to it. */
hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
w = new_richedit(NULL);
if (!w) {
skip("Couldn't create window\n");
return;
}
res = SendMessage(w, EM_GETOLEINTERFACE, 0, (LPARAM) &reOle);
res = SendMessageA(w, EM_GETOLEINTERFACE, 0, (LPARAM)&reOle);
ok(res, "SendMessage\n");
ok(reOle != NULL, "EM_GETOLEINTERFACE\n");
@ -81,9 +117,10 @@ START_TEST(richole)
ok(hres == S_OK, "IRichEditOle_QueryInterface\n");
ok(txtDoc != NULL, "IRichEditOle_QueryInterface\n");
hres = ITextDocument_GetSelection(txtDoc, &txtSel);
ok(hres == S_OK, "ITextDocument_GetSelection\n");
ok(txtSel != NULL, "ITextDocument_GetSelection\n");
hres = ITextDocument_GetSelection(txtDoc, NULL);
ok(hres == E_INVALIDARG, "ITextDocument_GetSelection: 0x%x\n", hres);
ITextDocument_GetSelection(txtDoc, &txtSel);
punk = NULL;
hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk);
@ -114,3 +151,247 @@ START_TEST(richole)
ITextSelection_Release(txtSel);
}
static void test_ITextDocument_Open(void)
{
IRichEditOle *reOle = NULL;
ITextDocument *txtDoc = NULL;
ITextSelection *txtSel = NULL;
HRESULT hres;
HWND w;
HANDLE hFile;
VARIANT testfile;
WCHAR filename[] = {'t', 'e', 's', 't','.','t','x','t', 0};
int result;
DWORD dw;
static const CHAR chACP[] = "TestSomeText";
static const CHAR chUTF8[] = "\xef\xbb\xbfTextWithUTF8BOM";
static const WCHAR chUTF16[] = {0xfeff, 'T', 'e', 's', 't', 'S', 'o', 'm',
'e', 'T', 'e', 'x', 't', 0};
#define MAX_BUF_LEN 1024
CHAR bufACP[MAX_BUF_LEN];
WCHAR bufUnicode[MAX_BUF_LEN];
static const int tomConstantsSingle[] =
{
tomReadOnly, tomShareDenyRead, tomShareDenyWrite,
tomCreateAlways, tomOpenExisting, tomOpenAlways,
tomTruncateExisting, tomRTF, tomText
};
static const int tomConstantsMulti[] =
{
tomReadOnly|tomShareDenyRead|tomPasteFile, tomReadOnly|tomPasteFile,
tomReadOnly|tomShareDenyWrite|tomPasteFile,
tomReadOnly|tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyWrite|tomPasteFile,
tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyRead|tomPasteFile,
tomShareDenyRead|tomShareDenyWrite, tomReadOnly|tomShareDenyRead|tomShareDenyWrite,
tomReadOnly|tomShareDenyWrite, tomReadOnly|tomShareDenyRead
};
int tomNumSingle = sizeof(tomConstantsSingle)/sizeof(tomConstantsSingle[0]);
int tomNumMulti = sizeof(tomConstantsMulti)/sizeof(tomConstantsMulti[0]);
int i;
V_VT(&testfile) = VT_BSTR;
V_BSTR(&testfile) = SysAllocString(filename);
for(i=0; i < tomNumSingle; i++)
{
touch_file(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_ACP);
todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
tomConstantsSingle[i], hres);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
touch_file(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_UTF8);
todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
tomConstantsSingle[i], hres);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
}
for(i=0; i < tomNumMulti; i++)
{
touch_file(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_ACP);
todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
tomConstantsMulti[i], hres);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
touch_file(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_UTF8);
todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
tomConstantsMulti[i], hres);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
}
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_ACP);
todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_UTF8);
todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_ACP);
todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_UTF8);
todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
touch_file(filename);
hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_ACP\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
touch_file(filename);
hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_ACP);
todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_ACP\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_UTF8);
todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
ITextDocument_Open(txtDoc, &testfile, tomText, CP_ACP);
todo_wine ok(is_existing_file(filename) == TRUE, "a file should be created default\n");
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
/* test of share mode */
touch_file(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
ITextDocument_Open(txtDoc, &testfile, tomShareDenyRead, CP_ACP);
SetLastError(0xdeadbeef);
hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
CloseHandle(hFile);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
touch_file(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite, CP_ACP);
SetLastError(0xdeadbeef);
hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
CloseHandle(hFile);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
touch_file(filename);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
SetLastError(0xdeadbeef);
ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite|tomShareDenyRead, CP_ACP);
hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
CloseHandle(hFile);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
/* tests to check the content */
hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, chACP, sizeof(chACP)-sizeof(CHAR), &dw, NULL);
CloseHandle(hFile);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
ITextDocument_Open(txtDoc, &testfile, tomReadOnly, CP_ACP);
result = SendMessageA(w, WM_GETTEXT, 1024, (LPARAM)bufACP);
todo_wine ok(result == 12, "ITextDocument_Open: Test ASCII returned %d, expected 12\n", result);
result = strcmp(bufACP, chACP);
todo_wine ok(result == 0, "ITextDocument_Open: Test ASCII set wrong text: Result: %s\n", bufACP);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, chUTF8, sizeof(chUTF8)-sizeof(CHAR), &dw, NULL);
CloseHandle(hFile);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
ITextDocument_Open(txtDoc, &testfile, tomReadOnly, CP_UTF8);
result = SendMessageA(w, WM_GETTEXT, 1024, (LPARAM)bufACP);
todo_wine ok(result == 15, "ITextDocument_Open: Test UTF-8 returned %d, expected 15\n", result);
result = strcmp(bufACP, &chUTF8[3]);
todo_wine ok(result == 0, "ITextDocument_Open: Test UTF-8 set wrong text: Result: %s\n", bufACP);
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
hFile = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile, chUTF16, sizeof(chUTF16)-sizeof(WCHAR), &dw, NULL);
CloseHandle(hFile);
create_interfaces(&w, &reOle, &txtDoc, &txtSel);
ITextDocument_Open(txtDoc, &testfile, tomReadOnly, 1200);
result = SendMessageW(w, WM_GETTEXT, 1024, (LPARAM)bufUnicode);
todo_wine ok(result == 12, "ITextDocument_Open: Test UTF-16 returned %d, expected 12\n", result);
result = lstrcmpW(bufUnicode, &chUTF16[1]);
todo_wine ok(result == 0, "ITextDocument_Open: Test UTF-16 set wrong text: Result: %s\n", wine_dbgstr_w(bufUnicode));
release_interfaces(&w, &reOle, &txtDoc, &txtSel);
DeleteFileW(filename);
VariantClear(&testfile);
}
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
* RICHED20.DLL, so the linker doesn't actually link to it. */
hmoduleRichEdit = LoadLibraryA("riched20.dll");
ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
test_Interfaces();
test_ITextDocument_Open();
}

View file

@ -41,21 +41,6 @@ static IID *pIID_ITextHost;
static IID *pIID_ITextHost2;
static PCreateTextServices pCreateTextServices;
static const char *debugstr_guid(REFIID riid)
{
static char buf[50];
if(!riid)
return "(null)";
sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
riid->Data4[5], riid->Data4[6], riid->Data4[7]);
return buf;
}
/* Define C Macros for ITextServices calls. */
/* Use a special table for x86 machines to convert the thiscall
@ -79,7 +64,7 @@ static ITextServicesVtbl itextServicesStdcallVtbl;
#define ITextServices_OnTxUIDeactivate(This) TXTSERV_VTABLE(This)->OnTxUIDeactivate(This)
#define ITextServices_TxGetText(This,a) TXTSERV_VTABLE(This)->TxGetText(This,a)
#define ITextServices_TxSetText(This,a) TXTSERV_VTABLE(This)->TxSetText(This,a)
#define ITextServices_TxGetCurrentTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurrentTargetX(This,a)
#define ITextServices_TxGetCurTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurTargetX(This,a)
#define ITextServices_TxGetBaseLinePos(This,a) TXTSERV_VTABLE(This)->TxGetBaseLinePos(This,a)
#define ITextServices_TxGetNaturalSize(This,a,b,c,d,e,f,g,h) TXTSERV_VTABLE(This)->TxGetNaturalSize(This,a,b,c,d,e,f,g,h)
#define ITextServices_TxGetDropTarget(This,a) TXTSERV_VTABLE(This)->TxGetDropTarget(This,a)
@ -720,7 +705,7 @@ static void test_TxGetNaturalSize(void) {
/* Variables with the text metric information */
INT charwidth_caps_text[26];
TEXTMETRIC tmInfo_text;
TEXTMETRICA tmInfo_text;
if (!init_texthost())
return;
@ -730,9 +715,9 @@ static void test_TxGetNaturalSize(void) {
/* Populate the metric strucs */
SetMapMode(hdcDraw,MM_TEXT);
GetTextMetrics(hdcDraw, &tmInfo_text);
GetTextMetricsA(hdcDraw, &tmInfo_text);
SetLastError(0xdeadbeef);
ret = GetCharWidth32(hdcDraw,'A','Z',charwidth_caps_text);
ret = GetCharWidth32A(hdcDraw,'A','Z',charwidth_caps_text);
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
win_skip("GetCharWidth32 is not available\n");
goto cleanup;
@ -805,11 +790,11 @@ DEFINE_GUID(expected_iid_itexthost2, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xa
static void test_IIDs(void)
{
ok(IsEqualIID(pIID_ITextServices, &expected_iid_itextservices),
"unexpected value for IID_ITextServices: %s\n", debugstr_guid(pIID_ITextServices));
"unexpected value for IID_ITextServices: %s\n", wine_dbgstr_guid(pIID_ITextServices));
ok(IsEqualIID(pIID_ITextHost, &expected_iid_itexthost),
"unexpected value for IID_ITextHost: %s\n", debugstr_guid(pIID_ITextHost));
"unexpected value for IID_ITextHost: %s\n", wine_dbgstr_guid(pIID_ITextHost));
ok(IsEqualIID(pIID_ITextHost2, &expected_iid_itexthost2),
"unexpected value for IID_ITextHost2: %s\n", debugstr_guid(pIID_ITextHost2));
"unexpected value for IID_ITextHost2: %s\n", wine_dbgstr_guid(pIID_ITextHost2));
}
/* Outer IUnknown for COM aggregation tests */
@ -882,7 +867,7 @@ START_TEST( txtsrv )
/* Must explicitly LoadLibrary(). The test has no references to functions in
* RICHED20.DLL, so the linker doesn't actually link to it. */
hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
hmoduleRichEdit = LoadLibraryA("riched20.dll");
ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
pIID_ITextServices = (IID*)GetProcAddress(hmoduleRichEdit, "IID_ITextServices");