From 8f464b1ffa384ffba25af5041065c23d21ede041 Mon Sep 17 00:00:00 2001 From: Jactry Zeng Date: Wed, 11 Sep 2013 18:06:02 +0800 Subject: riched20/tests: Add tests for ITextDocument_Save. To: wine-patches Reply-To: wine-devel --- dlls/riched20/tests/richole.c | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 1bd0be9..71e456e 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -93,6 +93,22 @@ static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **tx ITextSelection_Release(*txtSel); } +static BOOL compare_text_with_file(LPWSTR filename, const CHAR *str, LPSTR *chBuffer) +{ + int size; + HANDLE hFile; + DWORD dwReadSize; + + hFile = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + size = GetFileSize(hFile, NULL); + *chBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size+2); + ReadFile(hFile, *chBuffer, size+2, &dwReadSize, NULL); + CloseHandle(hFile); + + return strcmp(*chBuffer, str); +} + static void test_Interfaces(void) { IRichEditOle *reOle = NULL; @@ -331,6 +347,91 @@ static void test_ITextDocument_Open(void) DeleteFileW(filename); } +static void test_ITextDocument_Save(void) +{ + IRichEditOle *reOle = NULL; + ITextDocument *txtDoc = NULL; + ITextSelection *txtSel = NULL; + HRESULT hres; + HWND w; + VARIANT testfile; + SETTEXTEX setText; + LPSTR chBuffer; + int result = 0; + WCHAR filename[] = {'t', 'e', 's', 't','.','t','x','t', 0}; + + static const int tomConstantsSingle[] = + { + tomCreateAlways, tomOpenExisting, tomOpenAlways, + tomTruncateExisting + }; + + int tomNumSingle = sizeof(tomConstantsSingle)/sizeof(tomConstantsSingle[0]); + int i; + VariantInit(&testfile); + 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_Save(txtDoc, &testfile, tomConstantsSingle[i], CP_ACP); + todo_wine ok(hres == S_OK, "ITextDocument_Save: 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_Save(txtDoc, &testfile, tomConstantsSingle[i], CP_UTF8); + todo_wine ok(hres == S_OK, "ITextDocument_Save: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n", + tomConstantsSingle[i], hres); + release_interfaces(&w, &reOle, &txtDoc, &txtSel); + DeleteFileW(filename); + } + + create_interfaces(&w, &reOle, &txtDoc, &txtSel); + setText.flags = 0; + setText.codepage = CP_UTF8; + SendMessage(w, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"\xef\xbb\xbfTestUTF8WithBOM"); + ITextDocument_Save(txtDoc, &testfile, tomCreateAlways, CP_ACP); + release_interfaces(&w, &reOle, &txtDoc, &txtSel); + result = compare_text_with_file(filename, "TestUTF8WithBOM", &chBuffer); + todo_wine ok(result == 0, "ITextDocument_Save: Save UTF8 with BOM as ASCII got wrong text: %s\n", chBuffer); + DeleteFileW(filename); + + create_interfaces(&w, &reOle, &txtDoc, &txtSel); + setText.flags = 0; + setText.codepage = CP_UTF8; + SendMessage(w, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"\xef\xbb\xbfTestUTF8WithBOM"); + ITextDocument_Save(txtDoc, &testfile, tomCreateAlways, CP_UTF8); + release_interfaces(&w, &reOle, &txtDoc, &txtSel); + result = compare_text_with_file(filename, "\xef\xbb\xbfTestUTF8WithBOM", &chBuffer); + todo_wine ok(result == 0, "ITextDocument_Save: Save UTF8 with BOM as UTF8 with BOM got wrong text: %s\n", chBuffer); + DeleteFileW(filename); + + create_interfaces(&w, &reOle, &txtDoc, &txtSel); + setText.flags = 0; + setText.codepage = CP_ACP; + SendMessage(w, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"TestUTF8WithBOM"); + ITextDocument_Save(txtDoc, &testfile, tomCreateAlways, CP_ACP); + release_interfaces(&w, &reOle, &txtDoc, &txtSel); + result = compare_text_with_file(filename, "TestUTF8WithBOM", &chBuffer); + todo_wine ok(result == 0, "ITextDocument_Save: Save ASCII as ASCII got wrong text: %s\n", chBuffer); + DeleteFileW(filename); + + create_interfaces(&w, &reOle, &txtDoc, &txtSel); + setText.flags = 0; + setText.codepage = CP_ACP; + SendMessage(w, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"TestUTF8WithBOM"); + ITextDocument_Save(txtDoc, &testfile, tomCreateAlways, CP_UTF8); + release_interfaces(&w, &reOle, &txtDoc, &txtSel); + result = compare_text_with_file(filename, "\xef\xbb\xbfTestUTF8WithBOM", &chBuffer); + todo_wine ok(result == 0, "ITextDocument_Save: Save ASCII as UTF8 with BOM got wrong text: %s\n", chBuffer); + DeleteFileW(filename); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -340,4 +441,5 @@ START_TEST(richole) test_Interfaces(); test_ITextDocument_Open(); + test_ITextDocument_Save(); } -- 1.7.10.4