riched20/tests: Check the correct return value.
[wine] / dlls / riched20 / tests / richole.c
1 /*
2  * Tests for IRichEditOle and friends.
3  *
4  * Copyright 2008 Google (Dan Hipschman)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22
23 #include <stdarg.h>
24
25 #include <windef.h>
26 #include <winbase.h>
27 #include <wingdi.h>
28 #include <winuser.h>
29 #include <initguid.h>
30 #include <ole2.h>
31 #include <richedit.h>
32 #include <richole.h>
33 #include <tom.h>
34 #include <wine/test.h>
35
36 static HMODULE hmoduleRichEdit;
37
38 static HWND new_window(LPCTSTR lpClassName, DWORD dwStyle, HWND parent)
39 {
40   HWND hwnd
41     = CreateWindow(lpClassName, NULL,
42                    dwStyle | WS_POPUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
43                    0, 0, 200, 60, parent, NULL, hmoduleRichEdit, NULL);
44   ok(hwnd != NULL, "class: %s, error: %d\n", lpClassName, (int) GetLastError());
45   return hwnd;
46 }
47
48 static HWND new_richedit(HWND parent)
49 {
50   return new_window(RICHEDIT_CLASS, ES_MULTILINE, parent);
51 }
52
53
54 START_TEST(richole)
55 {
56   IRichEditOle *reOle = NULL;
57   ITextDocument *txtDoc = NULL;
58   ITextSelection *txtSel = NULL;
59   IUnknown *punk;
60   HRESULT hres;
61   LRESULT res;
62   HWND w;
63
64   /* Must explicitly LoadLibrary(). The test has no references to functions in
65    * RICHED20.DLL, so the linker doesn't actually link to it. */
66   hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
67   ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
68
69   w = new_richedit(NULL);
70   if (!w) {
71     skip("Couldn't create window\n");
72     return;
73   }
74
75   res = SendMessage(w, EM_GETOLEINTERFACE, 0, (LPARAM) &reOle);
76   ok(res, "SendMessage\n");
77   ok(reOle != NULL, "EM_GETOLEINTERFACE\n");
78
79   hres = IUnknown_QueryInterface(reOle, &IID_ITextDocument,
80                                  (void **) &txtDoc);
81   ok(hres == S_OK, "IRichEditOle_QueryInterface\n");
82   ok(txtDoc != NULL, "IRichEditOle_QueryInterface\n");
83
84   hres = ITextDocument_GetSelection(txtDoc, &txtSel);
85   ok(hres == S_OK, "ITextDocument_GetSelection\n");
86   ok(txtSel != NULL, "ITextDocument_GetSelection\n");
87
88   punk = NULL;
89   hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk);
90   ok(hres == S_OK, "ITextSelection_QueryInterface\n");
91   ok(punk != NULL, "ITextSelection_QueryInterface\n");
92   IUnknown_Release(punk);
93
94   punk = NULL;
95   hres = ITextSelection_QueryInterface(txtSel, &IID_ITextRange, (void **) &punk);
96   ok(hres == S_OK, "ITextSelection_QueryInterface\n");
97   ok(punk != NULL, "ITextSelection_QueryInterface\n");
98   IUnknown_Release(punk);
99
100   punk = NULL;
101   hres = ITextSelection_QueryInterface(txtSel, &IID_IDispatch, (void **) &punk);
102   ok(hres == S_OK, "ITextSelection_QueryInterface\n");
103   ok(punk != NULL, "ITextSelection_QueryInterface\n");
104   IUnknown_Release(punk);
105
106   ITextDocument_Release(txtDoc);
107   IUnknown_Release(reOle);
108   DestroyWindow(w);
109
110   /* Methods should return CO_E_RELEASED if the backing document has
111      been released.  One test should suffice.  */
112   hres = ITextSelection_CanEdit(txtSel, NULL);
113   ok(hres == CO_E_RELEASED, "ITextSelection after ITextDocument destroyed\n");
114
115   ITextSelection_Release(txtSel);
116 }