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
)))
145 static const IDispatchVtbl HTMLEventsVtbl
= {
146 HTMLEvents_QueryInterface
,
149 HTMLEvents_GetTypeInfoCount
,
150 HTMLEvents_GetTypeInfo
,
151 HTMLEvents_GetIDsOfNames
,
155 static IDispatch HTMLEvents
= { &HTMLEventsVtbl
};
157 static void test_QueryInterface(void)
159 IUnknown
*xmlview
, *unk
;
160 IHTMLDocument
*htmldoc
;
163 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
164 &IID_IUnknown
, (void**)&xmlview
);
166 win_skip("Failed to create XMLView instance\n");
169 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
171 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistMoniker
, (void**)&unk
);
172 ok(hres
== S_OK
, "QueryInterface(IID_IPersistMoniker) returned %x, expected S_OK\n", hres
);
173 IUnknown_Release(unk
);
175 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistHistory
, (void**)&unk
);
176 ok(hres
== S_OK
, "QueryInterface(IID_IPersistHistory) returned %x, expected S_OK\n", hres
);
177 IUnknown_Release(unk
);
179 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleCommandTarget
, (void**)&unk
);
180 ok(hres
== S_OK
, "QueryInterface(IID_IOleCommandTarget) returned %x, expected S_OK\n", hres
);
181 IUnknown_Release(unk
);
183 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleObject
, (void**)&unk
);
184 ok(hres
== S_OK
, "QueryInterface(IID_IOleObject) returned %x, expected S_OK\n", hres
);
185 IUnknown_Release(unk
);
187 hres
= IUnknown_QueryInterface(xmlview
, &IID_IHTMLDocument
, (void**)&htmldoc
);
188 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument) returned %x, expected S_OK\n", hres
);
189 hres
= IHTMLDocument_QueryInterface(htmldoc
, &IID_IUnknown
, (void**)&unk
);
190 ok(hres
== S_OK
, "QueryInterface(IID_IUnknown) returned %x, expected S_OK\n", hres
);
191 ok(unk
== xmlview
, "Aggregation is not working as expected\n");
192 IUnknown_Release(unk
);
193 IHTMLDocument_Release(htmldoc
);
195 IUnknown_Release(xmlview
);
198 static void test_Load(void)
200 static const WCHAR xmlview_xmlW
[] = {'/','x','m','l','/','x','m','l','v','i','e','w','.','x','m','l',0};
201 static const WCHAR res
[] = {'r','e','s',':','/','/',0};
204 IPersistMoniker
*pers_mon
;
205 IConnectionPointContainer
*cpc
;
206 IConnectionPoint
*cp
;
215 GetModuleFileNameW(NULL
, buf
+lstrlenW(buf
), (sizeof(buf
)-sizeof(res
))/sizeof(WCHAR
));
216 lstrcatW(buf
, xmlview_xmlW
);
218 if(!pCreateURLMoniker
) {
219 win_skip("CreateURLMoniker not available\n");
223 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
224 &IID_IPersistMoniker
, (void**)&pers_mon
);
226 win_skip("Failed to create XMLView instance\n");
229 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
231 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IHTMLDocument2
, (void**)&html_doc
);
232 ok(hres
== S_OK
, "QueryInterface(HTMLDocument2) returned %x, expected S_OK\n", hres
);
233 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IConnectionPointContainer
, (void**)&cpc
);
234 ok(hres
== S_OK
, "QueryInterface(IConnectionPointContainer) returned %x, expected S_OK\n", hres
);
235 hres
= IConnectionPointContainer_FindConnectionPoint(cpc
, &IID_IDispatch
, &cp
);
236 ok(hres
== S_OK
, "FindConnectionPoint returned %x, expected S_OK\n", hres
);
237 hres
= IConnectionPoint_Advise(cp
, (IUnknown
*)&HTMLEvents
, NULL
);
238 ok(hres
== S_OK
, "Advise returned %x, expected S_OK\n", hres
);
239 IConnectionPoint_Release(cp
);
240 IConnectionPointContainer_Release(cpc
);
242 hres
= CreateBindCtx(0, &bctx
);
243 ok(hres
== S_OK
, "CreateBindCtx returned %x, expected S_OK\n", hres
);
244 hres
= pCreateURLMoniker(NULL
, buf
, &mon
);
245 ok(hres
== S_OK
, "CreateUrlMoniker returned %x, expected S_OK\n", hres
);
247 hres
= IPersistMoniker_Load(pers_mon
, TRUE
, mon
, bctx
, 0);
248 ok(hres
== S_OK
, "Load returned %x, expected S_OK\n", hres
);
249 IBindCtx_Release(bctx
);
250 IMoniker_Release(mon
);
252 while(!loaded
&& GetMessageA(&msg
, NULL
, 0, 0)) {
253 TranslateMessage(&msg
);
254 DispatchMessageA(&msg
);
257 hres
= IHTMLDocument2_get_body(html_doc
, &elem
);
258 ok(hres
== S_OK
, "get_body returned %x, expected S_OK\n", hres
);
259 hres
= IHTMLElement_get_outerHTML(elem
, &source
);
260 ok(hres
== S_OK
, "get_outerHTML returned %x, expected S_OK\n", hres
);
261 ok(!html_src_compare(source
, xmlview_html
), "Incorrect HTML source: %s\n", wine_dbgstr_w(source
));
262 IHTMLElement_Release(elem
);
263 SysFreeString(source
);
265 IHTMLDocument2_Release(html_doc
);
267 IPersistMoniker_Release(pers_mon
);
272 HMODULE urlmon
= LoadLibraryA("urlmon.dll");
273 pCreateURLMoniker
= (void*)GetProcAddress(urlmon
, "CreateURLMoniker");
276 test_QueryInterface();