[PATCH 2/2] riched20: add tests of ITextDocument_Open.
Jactry Zeng
jactry92 at gmail.com
Wed Jul 31 02:10:59 CDT 2013
-------------- next part --------------
From 37c8389accf53655257a0c8603bc125cbfbd092c Mon Sep 17 00:00:00 2001
From: Jactry Zeng <jactry92 at gmail.com>
Date: Mon, 1 Jul 2013 09:20:34 +0800
Subject: riched20: add tests of ITextDocument_Open.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>
---
dlls/riched20/tests/richole.c | 156 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 156 insertions(+)
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index 6b1b1f4..a733634 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -50,6 +50,31 @@ static HWND new_richedit(HWND parent)
return new_window(RICHEDIT_CLASS, ES_MULTILINE, parent);
}
+static BOOL touch_file(LPCWSTR filename)
+{
+ HANDLE file;
+
+ 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 test_Interfaces(void)
{
IRichEditOle *reOle = NULL;
@@ -107,6 +132,136 @@ static void test_Interfaces(void)
ITextSelection_Release(txtSel);
}
+static void test_ITextDocument(void)
+{
+ IRichEditOle *reOle = NULL;
+ ITextDocument *txtDoc = NULL;
+ ITextSelection *txtSel = NULL;
+ HRESULT hres;
+ HWND w;
+ VARIANT testfile;
+ WCHAR filename[] = {'t', 'e', 's', 't','.','t','x','t', 0};
+
+ static const int tomConstantsSingle[] =
+ {
+ tomReadOnly, tomShareDenyRead, tomShareDenyWrite,
+ tomCreateAlways, tomOpenExisting, tomOpenAlways,
+ tomTruncateExisting, tomRTF, tomText
+ };
+
+ static const int tomConstantsMulti[] =
+ {
+ tomReadOnly|tomShareDenyRead|tomPasteFile, tomReadOnly|tomPasteFile,
+ tomReadOnly|tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyWrite|tomPasteFile,
+ tomShareDenyRead|tomShareDenyWrite|tomPasteFile, tomShareDenyRead|tomPasteFile,
+ tomShareDenyRead|tomShareDenyWrite, tomReadOnly|tomShareDenyRead|tomShareDenyWrite,
+ tomReadOnly|tomShareDenyWrite, tomReadOnly|tomShareDenyRead
+ };
+
+ int tomNunSingle = sizeof(tomConstantsSingle)/sizeof(tomConstantsSingle[0]) - 1;
+ int tomNunMulti = sizeof(tomConstantsMulti)/sizeof(tomConstantsMulti[0]) -1;
+ int i;
+ VariantInit(&testfile);
+ V_VT(&testfile) = VT_BSTR;
+ V_BSTR(&testfile) = SysAllocString(filename);
+
+ w = new_richedit(NULL);
+ if (!w) {
+ skip("Couldn't create window\n");
+ return;
+ }
+ SendMessage(w, EM_GETOLEINTERFACE, 0, (LPARAM) &reOle);
+ IRichEditOle_QueryInterface(reOle, &IID_ITextDocument,
+ (void **) &txtDoc);
+
+ hres = ITextDocument_GetSelection(txtDoc, &txtSel);
+ ok(hres == S_OK, "ITextDocument_GetSelection\n");
+ ok(txtSel != NULL, "ITextDocument_GetSelection\n");
+
+ /* tests for ITextDocument::Open */
+ for(i=0; i<=tomNunSingle; i++)
+ {
+ touch_file(filename);
+ hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_ACP);
+ ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
+ tomConstantsSingle[i], hres);
+ DeleteFileW(filename);
+
+ touch_file(filename);
+ hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_UTF8);
+ ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
+ tomConstantsSingle[i], hres);
+ DeleteFileW(filename);
+ }
+
+ for(i=0; i<=tomNunMulti; i++)
+ {
+ touch_file(filename);
+ hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_ACP);
+ ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%x\n",
+ tomConstantsMulti[i], hres);
+ DeleteFileW(filename);
+
+ touch_file(filename);
+ hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_UTF8);
+ ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%x\n",
+ tomConstantsMulti[i], hres);
+ DeleteFileW(filename);
+ }
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_ACP);
+ ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
+ ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
+ DeleteFileW(filename);
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_UTF8);
+ ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
+ ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
+ DeleteFileW(filename);
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_ACP);
+ ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
+ ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
+ DeleteFileW(filename);
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_UTF8);
+ ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
+ ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
+ DeleteFileW(filename);
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
+ ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
+ ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
+ DeleteFileW(filename);
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
+ ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
+ ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
+ DeleteFileW(filename);
+
+ touch_file(filename);
+ hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
+ ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_ACP\n");
+ DeleteFileW(filename);
+
+ touch_file(filename);
+ hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
+ ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
+ DeleteFileW(filename);
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_ACP);
+ ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_ACP\n");
+
+ hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_UTF8);
+ ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
+
+ ITextDocument_Release(txtDoc);
+ IRichEditOle_Release(reOle);
+ DestroyWindow(w);
+
+ ITextSelection_Release(txtSel);
+}
+
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
@@ -115,4 +270,5 @@ START_TEST(richole)
ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
test_Interfaces();
+ test_ITextDocument();
}
--
1.8.1.2
More information about the wine-patches
mailing list