2 * Copyright 2012 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define WIN32_NO_STATUS
21 #define COM_NO_WINDOWS_H
29 #include <wine/test.h>
31 //#include "windows.h"
41 #include <xmlparser.h>
43 HRESULT (WINAPI
*pCreateURLMoniker
)(IMoniker
*, LPCWSTR
, IMoniker
**);
45 static const char xmlview_html
[] =
47 "<BODY><H2>Generated HTML</H2>\r\n"
50 "<TR bgColor=green>\r\n"
52 "<TH>Value</TH></TR>\r\n"
55 "<TD>value1</TD></TR>\r\n"
58 "<TD>value2</TD></TR></TBODY></TABLE></BODY>";
60 IHTMLDocument2
*html_doc
;
63 static int html_src_compare(LPCWSTR strw
, const char *stra
)
68 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
73 while(*p1
=='\r' || *p1
=='\n' || *p1
=='\"') p1
++;
74 while(*p2
=='\r' || *p2
=='\n') p2
++;
76 if(!*p1
|| !*p2
|| tolower(*p1
)!=tolower(*p2
))
86 static HRESULT WINAPI
HTMLEvents_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
88 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
93 ok(0, "Unexpected call\n");
97 static ULONG WINAPI
HTMLEvents_AddRef(IDispatch
*iface
)
102 static ULONG WINAPI
HTMLEvents_Release(IDispatch
*iface
)
107 static HRESULT WINAPI
HTMLEvents_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
109 ok(0, "unexpected call\n");
113 static HRESULT WINAPI
HTMLEvents_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
,
116 ok(0, "unexpected call\n");
120 static HRESULT WINAPI
HTMLEvents_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
121 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
123 ok(0, "unexpected call\n");
127 static HRESULT WINAPI
HTMLEvents_Invoke(IDispatch
*iface
, DISPID dispIdMember
, REFIID riid
,
128 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
129 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
131 if(dispIdMember
== DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE
) {
132 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
136 hr
= IHTMLDocument2_get_readyState(html_doc
, &state
);
137 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
138 if(!memcmp(state
, completeW
, sizeof(completeW
)))
140 SysFreeString(state
);
146 static const IDispatchVtbl HTMLEventsVtbl
= {
147 HTMLEvents_QueryInterface
,
150 HTMLEvents_GetTypeInfoCount
,
151 HTMLEvents_GetTypeInfo
,
152 HTMLEvents_GetIDsOfNames
,
156 static IDispatch HTMLEvents
= { &HTMLEventsVtbl
};
158 static void test_QueryInterface(void)
160 IUnknown
*xmlview
, *unk
;
161 IHTMLDocument
*htmldoc
;
164 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
165 &IID_IUnknown
, (void**)&xmlview
);
167 win_skip("Failed to create XMLView instance\n");
170 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
172 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistMoniker
, (void**)&unk
);
173 ok(hres
== S_OK
, "QueryInterface(IID_IPersistMoniker) returned %x, expected S_OK\n", hres
);
174 IUnknown_Release(unk
);
176 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistHistory
, (void**)&unk
);
177 ok(hres
== S_OK
, "QueryInterface(IID_IPersistHistory) returned %x, expected S_OK\n", hres
);
178 IUnknown_Release(unk
);
180 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleCommandTarget
, (void**)&unk
);
181 ok(hres
== S_OK
, "QueryInterface(IID_IOleCommandTarget) returned %x, expected S_OK\n", hres
);
182 IUnknown_Release(unk
);
184 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleObject
, (void**)&unk
);
185 ok(hres
== S_OK
, "QueryInterface(IID_IOleObject) returned %x, expected S_OK\n", hres
);
186 IUnknown_Release(unk
);
188 hres
= IUnknown_QueryInterface(xmlview
, &IID_IHTMLDocument
, (void**)&htmldoc
);
189 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument) returned %x, expected S_OK\n", hres
);
190 hres
= IHTMLDocument_QueryInterface(htmldoc
, &IID_IUnknown
, (void**)&unk
);
191 ok(hres
== S_OK
, "QueryInterface(IID_IUnknown) returned %x, expected S_OK\n", hres
);
192 ok(unk
== xmlview
, "Aggregation is not working as expected\n");
193 IUnknown_Release(unk
);
194 IHTMLDocument_Release(htmldoc
);
196 IUnknown_Release(xmlview
);
199 static void test_Load(void)
201 static const WCHAR xmlview_xmlW
[] = {'/','x','m','l','/','x','m','l','v','i','e','w','.','x','m','l',0};
202 static const WCHAR res
[] = {'r','e','s',':','/','/',0};
205 IPersistMoniker
*pers_mon
;
206 IConnectionPointContainer
*cpc
;
207 IConnectionPoint
*cp
;
216 GetModuleFileNameW(NULL
, buf
+lstrlenW(buf
), (sizeof(buf
)-sizeof(res
))/sizeof(WCHAR
));
217 lstrcatW(buf
, xmlview_xmlW
);
219 if(!pCreateURLMoniker
) {
220 win_skip("CreateURLMoniker not available\n");
224 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
225 &IID_IPersistMoniker
, (void**)&pers_mon
);
227 win_skip("Failed to create XMLView instance\n");
230 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
232 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IHTMLDocument2
, (void**)&html_doc
);
233 ok(hres
== S_OK
, "QueryInterface(HTMLDocument2) returned %x, expected S_OK\n", hres
);
234 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IConnectionPointContainer
, (void**)&cpc
);
235 ok(hres
== S_OK
, "QueryInterface(IConnectionPointContainer) returned %x, expected S_OK\n", hres
);
236 hres
= IConnectionPointContainer_FindConnectionPoint(cpc
, &IID_IDispatch
, &cp
);
237 ok(hres
== S_OK
, "FindConnectionPoint returned %x, expected S_OK\n", hres
);
238 hres
= IConnectionPoint_Advise(cp
, (IUnknown
*)&HTMLEvents
, NULL
);
239 ok(hres
== S_OK
, "Advise returned %x, expected S_OK\n", hres
);
240 IConnectionPoint_Release(cp
);
241 IConnectionPointContainer_Release(cpc
);
243 hres
= CreateBindCtx(0, &bctx
);
244 ok(hres
== S_OK
, "CreateBindCtx returned %x, expected S_OK\n", hres
);
245 hres
= pCreateURLMoniker(NULL
, buf
, &mon
);
246 ok(hres
== S_OK
, "CreateUrlMoniker returned %x, expected S_OK\n", hres
);
248 hres
= IPersistMoniker_Load(pers_mon
, TRUE
, mon
, bctx
, 0);
249 ok(hres
== S_OK
, "Load returned %x, expected S_OK\n", hres
);
250 IBindCtx_Release(bctx
);
251 IMoniker_Release(mon
);
253 while(!loaded
&& GetMessageA(&msg
, NULL
, 0, 0)) {
254 TranslateMessage(&msg
);
255 DispatchMessageA(&msg
);
258 hres
= IHTMLDocument2_get_body(html_doc
, &elem
);
259 ok(hres
== S_OK
, "get_body returned %x, expected S_OK\n", hres
);
260 hres
= IHTMLElement_get_outerHTML(elem
, &source
);
261 ok(hres
== S_OK
, "get_outerHTML returned %x, expected S_OK\n", hres
);
262 ok(!html_src_compare(source
, xmlview_html
), "Incorrect HTML source: %s\n", wine_dbgstr_w(source
));
263 IHTMLElement_Release(elem
);
264 SysFreeString(source
);
266 IHTMLDocument2_Release(html_doc
);
268 IPersistMoniker_Release(pers_mon
);
273 HMODULE urlmon
= LoadLibraryA("urlmon.dll");
274 pCreateURLMoniker
= (void*)GetProcAddress(urlmon
, "CreateURLMoniker");
277 test_QueryInterface();