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
32 #include "xmlparser.h"
34 #include "wine/test.h"
36 HRESULT (WINAPI
*pCreateURLMoniker
)(IMoniker
*, LPCWSTR
, IMoniker
**);
38 static const char xmlview_html
[] =
40 "<BODY><H2>Generated HTML</H2>\r\n"
43 "<TR bgColor=green>\r\n"
45 "<TH>Value</TH></TR>\r\n"
48 "<TD>value1</TD></TR>\r\n"
51 "<TD>value2</TD></TR></TBODY></TABLE></BODY>";
53 IHTMLDocument2
*html_doc
;
56 static int html_src_compare(LPCWSTR strw
, const char *stra
)
61 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
66 while(*p1
=='\r' || *p1
=='\n' || *p1
=='\"') p1
++;
67 while(*p2
=='\r' || *p2
=='\n') p2
++;
69 if(!*p1
|| !*p2
|| tolower(*p1
)!=tolower(*p2
))
79 static HRESULT WINAPI
HTMLEvents_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
81 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
86 ok(0, "Unexpected call\n");
90 static ULONG WINAPI
HTMLEvents_AddRef(IDispatch
*iface
)
95 static ULONG WINAPI
HTMLEvents_Release(IDispatch
*iface
)
100 static HRESULT WINAPI
HTMLEvents_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
102 ok(0, "unexpected call\n");
106 static HRESULT WINAPI
HTMLEvents_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
,
109 ok(0, "unexpected call\n");
113 static HRESULT WINAPI
HTMLEvents_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
114 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
116 ok(0, "unexpected call\n");
120 static HRESULT WINAPI
HTMLEvents_Invoke(IDispatch
*iface
, DISPID dispIdMember
, REFIID riid
,
121 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
122 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
124 if(dispIdMember
== DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE
) {
125 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
129 hr
= IHTMLDocument2_get_readyState(html_doc
, &state
);
130 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
131 if(!memcmp(state
, completeW
, sizeof(completeW
)))
138 static const IDispatchVtbl HTMLEventsVtbl
= {
139 HTMLEvents_QueryInterface
,
142 HTMLEvents_GetTypeInfoCount
,
143 HTMLEvents_GetTypeInfo
,
144 HTMLEvents_GetIDsOfNames
,
148 static IDispatch HTMLEvents
= { &HTMLEventsVtbl
};
150 static void test_QueryInterface(void)
152 IUnknown
*xmlview
, *unk
;
153 IHTMLDocument
*htmldoc
;
156 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
157 &IID_IUnknown
, (void**)&xmlview
);
159 win_skip("Failed to create XMLView instance\n");
162 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
164 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistMoniker
, (void**)&unk
);
165 ok(hres
== S_OK
, "QueryInterface(IID_IPersistMoniker) returned %x, expected S_OK\n", hres
);
166 IUnknown_Release(unk
);
168 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistHistory
, (void**)&unk
);
169 ok(hres
== S_OK
, "QueryInterface(IID_IPersistHistory) returned %x, expected S_OK\n", hres
);
170 IUnknown_Release(unk
);
172 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleCommandTarget
, (void**)&unk
);
173 ok(hres
== S_OK
, "QueryInterface(IID_IOleCommandTarget) returned %x, expected S_OK\n", hres
);
174 IUnknown_Release(unk
);
176 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleObject
, (void**)&unk
);
177 ok(hres
== S_OK
, "QueryInterface(IID_IOleObject) returned %x, expected S_OK\n", hres
);
178 IUnknown_Release(unk
);
180 hres
= IUnknown_QueryInterface(xmlview
, &IID_IHTMLDocument
, (void**)&htmldoc
);
181 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument) returned %x, expected S_OK\n", hres
);
182 hres
= IHTMLDocument_QueryInterface(htmldoc
, &IID_IUnknown
, (void**)&unk
);
183 ok(hres
== S_OK
, "QueryInterface(IID_IUnknown) returned %x, expected S_OK\n", hres
);
184 todo_wine
ok(unk
== xmlview
, "Aggregation is not working as expected\n");
185 IUnknown_Release(unk
);
186 IHTMLDocument_Release(htmldoc
);
188 IUnknown_Release(xmlview
);
191 static void test_Load(void)
193 static const WCHAR xmlview_xmlW
[] = {'/','x','m','l','/','x','m','l','v','i','e','w','.','x','m','l',0};
194 static const WCHAR res
[] = {'r','e','s',':','/','/',0};
197 IPersistMoniker
*pers_mon
;
198 IConnectionPointContainer
*cpc
;
199 IConnectionPoint
*cp
;
208 GetModuleFileNameW(NULL
, buf
+lstrlenW(buf
), (sizeof(buf
)-sizeof(res
))/sizeof(WCHAR
));
209 lstrcatW(buf
, xmlview_xmlW
);
211 if(!pCreateURLMoniker
) {
212 win_skip("CreateURLMoniker not available\n");
216 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
217 &IID_IPersistMoniker
, (void**)&pers_mon
);
219 win_skip("Failed to create XMLView instance\n");
222 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
224 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IHTMLDocument2
, (void**)&html_doc
);
225 ok(hres
== S_OK
, "QueryInterface(HTMLDocument2) returned %x, expected S_OK\n", hres
);
226 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IConnectionPointContainer
, (void**)&cpc
);
227 ok(hres
== S_OK
, "QueryInterface(IConnectionPointContainer) returned %x, expected S_OK\n", hres
);
228 hres
= IConnectionPointContainer_FindConnectionPoint(cpc
, &IID_IDispatch
, &cp
);
229 ok(hres
== S_OK
, "FindConnectionPoint returned %x, expected S_OK\n", hres
);
230 hres
= IConnectionPoint_Advise(cp
, (IUnknown
*)&HTMLEvents
, NULL
);
231 ok(hres
== S_OK
, "Advise returned %x, expected S_OK\n", hres
);
232 IConnectionPoint_Release(cp
);
233 IConnectionPointContainer_Release(cpc
);
235 hres
= CreateBindCtx(0, &bctx
);
236 ok(hres
== S_OK
, "CreateBindCtx returned %x, expected S_OK\n", hres
);
237 hres
= pCreateURLMoniker(NULL
, buf
, &mon
);
238 ok(hres
== S_OK
, "CreateUrlMoniker returned %x, expected S_OK\n", hres
);
240 hres
= IPersistMoniker_Load(pers_mon
, TRUE
, mon
, bctx
, 0);
241 ok(hres
== S_OK
, "Load returned %x, expected S_OK\n", hres
);
242 IBindCtx_Release(bctx
);
243 IMoniker_Release(mon
);
245 while(!loaded
&& GetMessageA(&msg
, NULL
, 0, 0)) {
246 TranslateMessage(&msg
);
247 DispatchMessageA(&msg
);
250 hres
= IHTMLDocument2_get_body(html_doc
, &elem
);
251 ok(hres
== S_OK
, "get_body returned %x, expected S_OK\n", hres
);
252 hres
= IHTMLElement_get_outerHTML(elem
, &source
);
253 ok(hres
== S_OK
, "get_outerHTML returned %x, expected S_OK\n", hres
);
254 ok(!html_src_compare(source
, xmlview_html
), "Incorrect HTML source: %s\n", wine_dbgstr_w(source
));
255 IHTMLElement_Release(elem
);
256 SysFreeString(source
);
258 IHTMLDocument2_Release(html_doc
);
260 IPersistMoniker_Release(pers_mon
);
265 HMODULE urlmon
= LoadLibraryA("urlmon.dll");
266 pCreateURLMoniker
= (void*)GetProcAddress(urlmon
, "CreateURLMoniker");
269 test_QueryInterface();