2 * Tests for IRichEditOle and friends.
4 * Copyright 2008 Google (Dan Hipschman)
5 * Copyright 2018 Jactry Zeng for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include <wine/test.h>
35 static HMODULE msftedit_hmodule
;
37 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
38 static void _expect_ref(IUnknown
* obj
, ULONG ref
, int line
)
42 rc
= IUnknown_Release(obj
);
43 ok_(__FILE__
,line
)(rc
== ref
, "expected refcount %d, got %d.\n", ref
, rc
);
46 static HWND
new_window(LPCWSTR classname
, DWORD dwstyle
, HWND parent
)
48 HWND hwnd
= CreateWindowW(classname
, NULL
,
49 dwstyle
| WS_POPUP
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
,
50 0, 0, 200, 60, parent
, NULL
, msftedit_hmodule
, NULL
);
51 ok(hwnd
!= NULL
, "class: %s, error: %d.\n", wine_dbgstr_w(classname
), (int) GetLastError());
55 static void test_Interfaces(void)
57 IRichEditOle
*reole
= NULL
, *reole1
= NULL
;
58 ITextDocument
*txtdoc
= NULL
;
59 ITextDocument2Old
*txtdoc2old
= NULL
;
60 ITextDocument2
*txtdoc2
= NULL
;
61 ITextSelection
*txtsel
= NULL
, *txtsel2
;
68 hwnd
= new_window(MSFTEDIT_CLASS
, ES_MULTILINE
, NULL
);
71 skip("Couldn't create window.\n");
75 res
= SendMessageA(hwnd
, EM_GETOLEINTERFACE
, 0, (LPARAM
)&reole
);
76 ok(res
, "SendMessage\n");
77 ok(reole
!= NULL
, "EM_GETOLEINTERFACE\n");
80 res
= SendMessageA(hwnd
, EM_GETOLEINTERFACE
, 0, (LPARAM
)&reole1
);
81 ok(res
== 1, "SendMessage\n");
82 ok(reole1
== reole
, "Should not return a new IRichEditOle interface.\n");
85 hres
= IRichEditOle_QueryInterface(reole
, &IID_ITextDocument
, (void **)&txtdoc
);
86 ok(hres
== S_OK
, "IRichEditOle_QueryInterface failed: 0x%08x.\n", hres
);
87 ok(txtdoc
!= NULL
, "IRichEditOle_QueryInterface\n");
89 hres
= ITextDocument_GetSelection(txtdoc
, NULL
);
90 ok(hres
== E_INVALIDARG
, "ITextDocument_GetSelection: 0x%08x.\n", hres
);
92 EXPECT_REF(txtdoc
, 4);
94 hres
= ITextDocument_GetSelection(txtdoc
, &txtsel
);
95 ok(hres
== S_OK
, "ITextDocument_GetSelection failed 0x%08x.\n", hres
);
97 EXPECT_REF(txtdoc
, 4);
98 EXPECT_REF(txtsel
, 2);
100 hres
= ITextDocument_GetSelection(txtdoc
, &txtsel2
);
101 ok(hres
== S_OK
, "ITextDocument_GetSelection failed: 0x%08x.\n", hres
);
102 ok(txtsel2
== txtsel
, "got %p, %p\n", txtsel
, txtsel2
);
104 EXPECT_REF(txtdoc
, 4);
105 EXPECT_REF(txtsel
, 3);
107 ITextSelection_Release(txtsel2
);
110 hres
= ITextSelection_QueryInterface(txtsel
, &IID_ITextSelection
, (void **)&punk
);
111 ok(hres
== S_OK
, "ITextSelection_QueryInterface failed: 0x%08x.\n", hres
);
112 ok(punk
!= NULL
, "ITextSelection_QueryInterface\n");
113 IUnknown_Release(punk
);
116 hres
= ITextSelection_QueryInterface(txtsel
, &IID_ITextRange
, (void **)&punk
);
117 ok(hres
== S_OK
, "ITextSelection_QueryInterface failed: 0x%08x.\n", hres
);
118 ok(punk
!= NULL
, "ITextSelection_QueryInterface\n");
119 IUnknown_Release(punk
);
122 hres
= ITextSelection_QueryInterface(txtsel
, &IID_IDispatch
, (void **)&punk
);
123 ok(hres
== S_OK
, "ITextSelection_QueryInterface failed: 0x%08x.\n", hres
);
124 ok(punk
!= NULL
, "ITextSelection_QueryInterface\n");
125 IUnknown_Release(punk
);
128 hres
= IRichEditOle_QueryInterface(reole
, &IID_IOleClientSite
, (void **)&punk
);
129 ok(hres
== E_NOINTERFACE
, "IRichEditOle_QueryInterface: 0x%08x.\n", hres
);
132 hres
= IRichEditOle_QueryInterface(reole
, &IID_IOleWindow
, (void **)&punk
);
133 ok(hres
== E_NOINTERFACE
, "IRichEditOle_QueryInterface: 0x%08x.\n", hres
);
136 hres
= IRichEditOle_QueryInterface(reole
, &IID_IOleInPlaceSite
, (void **)&punk
);
137 ok(hres
== E_NOINTERFACE
, "IRichEditOle_QueryInterface: 0x%08x.\n", hres
);
139 /* ITextDocument2 is implemented on msftedit after win8 for superseding ITextDocument2Old */
140 hres
= IRichEditOle_QueryInterface(reole
, &IID_ITextDocument2
, (void **)&txtdoc2
);
142 hres
== E_NOINTERFACE
/* before win8 */, "IRichEditOle_QueryInterface: 0x%08x.\n", hres
);
143 if (hres
!= E_NOINTERFACE
)
145 ok(txtdoc2
!= NULL
, "IRichEditOle_QueryInterface\n");
146 ok((ITextDocument
*)txtdoc2
== txtdoc
, "Interface pointer isn't equal.\n");
147 EXPECT_REF(txtdoc2
, 5);
148 EXPECT_REF(reole
, 5);
150 hres
= ITextDocument2_QueryInterface(txtdoc2
, &IID_ITextDocument2Old
, (void **)&txtdoc2old
);
151 ok(hres
== S_OK
, "ITextDocument2_QueryInterface failed: 0x%08x.\n", hres
);
152 ok((ITextDocument
*)txtdoc2old
!= txtdoc
, "Interface pointer is equal.\n");
153 EXPECT_REF(txtdoc2
, 5);
154 EXPECT_REF(reole
, 5);
155 EXPECT_REF(txtdoc2old
, 1);
156 ITextDocument2Old_Release(txtdoc2old
);
157 ITextDocument2_Release(txtdoc2
);
161 hres
= IRichEditOle_QueryInterface(reole
, &IID_ITextDocument2Old
, (void **)&txtdoc2old
);
162 ok(hres
== S_OK
, "IRichEditOle_QueryInterface failed: 0x%08x.\n", hres
);
163 ok(txtdoc2old
!= NULL
, "IRichEditOle_QueryInterface\n");
164 ok((ITextDocument
*)txtdoc2old
== txtdoc
, "Interface pointer is equal.\n");
165 EXPECT_REF(txtdoc2old
, 5);
166 EXPECT_REF(reole
, 5);
167 ITextDocument2Old_Release(txtdoc2old
);
170 ITextDocument_Release(txtdoc
);
171 IRichEditOle_Release(reole
);
172 refcount
= IRichEditOle_Release(reole
);
173 ok(refcount
== 1, "Got wrong ref count: %d.\n", refcount
);
176 /* Methods should return CO_E_RELEASED if the backing document has
177 been released. One test should suffice. */
178 hres
= ITextSelection_CanEdit(txtsel
, NULL
);
179 ok(hres
== CO_E_RELEASED
, "ITextSelection after ITextDocument destroyed\n");
181 ITextSelection_Release(txtsel
);
186 msftedit_hmodule
= LoadLibraryA("msftedit.dll");
187 ok(msftedit_hmodule
!= NULL
, "error: %d\n", (int) GetLastError());