push 7f8c39dca3a5819e8ef115eebf7abed537de3a22
[wine/hacks.git] / dlls / riched20 / tests / richole.c
blobf6c2928e3d092087244d39933ebd2d4a7180d928
1 /*
2 * Tests for IRichEditOle and friends.
4 * Copyright 2008 Google (Dan Hipschman)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
24 #include <assert.h>
25 #include <windef.h>
26 #include <winbase.h>
27 #include <wingdi.h>
28 #include <winuser.h>
29 #include <ole2.h>
30 #include <richedit.h>
31 #include <richole.h>
32 #include <tom.h>
33 #include <wine/test.h>
35 #include <initguid.h>
36 DEFINE_GUID(IID_ITextDocument, 0x8cc497c0, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
37 DEFINE_GUID(IID_ITextRange, 0x8cc497c2, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
38 DEFINE_GUID(IID_ITextSelection, 0x8cc497c1, 0xa1df, 0x11ce, 0x80, 0x98, 0x00, 0xaa, 0x00, 0x47, 0xbe, 0x5d);
40 static HMODULE hmoduleRichEdit;
42 static HWND new_window(LPCTSTR lpClassName, DWORD dwStyle, HWND parent)
44 HWND hwnd
45 = CreateWindow(lpClassName, NULL,
46 dwStyle | WS_POPUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
47 0, 0, 200, 60, parent, NULL, hmoduleRichEdit, NULL);
48 ok(hwnd != NULL, "class: %s, error: %d\n", lpClassName, (int) GetLastError());
49 return hwnd;
52 static HWND new_richedit(HWND parent)
54 return new_window(RICHEDIT_CLASS, ES_MULTILINE, parent);
58 START_TEST(richole)
60 IRichEditOle *reOle = NULL;
61 ITextDocument *txtDoc = NULL;
62 ITextSelection *txtSel = NULL;
63 IUnknown *punk;
64 HRESULT hres;
65 LRESULT res;
66 HWND w;
68 /* Must explicitly LoadLibrary(). The test has no references to functions in
69 * RICHED20.DLL, so the linker doesn't actually link to it. */
70 hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
71 ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
73 w = new_richedit(NULL);
74 if (!w) {
75 skip("Couldn't create window\n");
76 return;
79 res = SendMessage(w, EM_GETOLEINTERFACE, 0, (LPARAM) &reOle);
80 ok(res, "SendMessage\n");
81 ok(reOle != NULL, "EM_GETOLEINTERFACE\n");
83 hres = IUnknown_QueryInterface(reOle, &IID_ITextDocument,
84 (void **) &txtDoc);
85 ok(hres == S_OK, "IRichEditOle_QueryInterface\n");
86 ok(txtDoc != NULL, "IRichEditOle_QueryInterface\n");
88 hres = ITextDocument_GetSelection(txtDoc, &txtSel);
89 ok(hres == S_OK, "ITextDocument_GetSelection\n");
90 ok(txtSel != NULL, "ITextDocument_GetSelection\n");
92 punk = NULL;
93 hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk);
94 ok(hres == S_OK, "ITextSelection_QueryInterface\n");
95 ok(punk != NULL, "ITextSelection_QueryInterface\n");
96 IUnknown_Release(punk);
98 punk = NULL;
99 hres = ITextSelection_QueryInterface(txtSel, &IID_ITextRange, (void **) &punk);
100 ok(hres == S_OK, "ITextSelection_QueryInterface\n");
101 ok(punk != NULL, "ITextSelection_QueryInterface\n");
102 IUnknown_Release(punk);
104 punk = NULL;
105 hres = ITextSelection_QueryInterface(txtSel, &IID_IDispatch, (void **) &punk);
106 ok(hres == S_OK, "ITextSelection_QueryInterface\n");
107 ok(punk != NULL, "ITextSelection_QueryInterface\n");
108 IUnknown_Release(punk);
110 ITextDocument_Release(txtDoc);
111 IUnknown_Release(reOle);
112 DestroyWindow(w);
114 /* Methods should return CO_E_RELEASED if the backing document has
115 been released. One test should suffice. */
116 hres = ITextSelection_CanEdit(txtSel, NULL);
117 ok(hres == CO_E_RELEASED, "ITextSelection after ITextDocument destroyed\n");
119 ITextSelection_Release(txtSel);