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
33 #include "wine/test.h"
35 DEFINE_GUID(CLSID_XMLView
, 0x48123bc4, 0x99d9, 0x11d1, 0xa6,0xb3, 0x00,0xc0,0x4f,0xd9,0x15,0x55);
37 HRESULT (WINAPI
*pCreateURLMoniker
)(IMoniker
*, LPCWSTR
, IMoniker
**);
39 static const char xmlview_html
[] =
41 "<BODY><H2>Generated HTML</H2>\r\n"
44 "<TR bgColor=green>\r\n"
46 "<TH>Value</TH></TR>\r\n"
49 "<TD>value1</TD></TR>\r\n"
52 "<TD>value2</TD></TR></TBODY></TABLE></BODY>";
54 IHTMLDocument2
*html_doc
;
57 static int html_src_compare(LPCWSTR strw
, const char *stra
)
62 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
67 while(*p1
=='\r' || *p1
=='\n' || *p1
=='\"') p1
++;
68 while(*p2
=='\r' || *p2
=='\n') p2
++;
70 if(!*p1
|| !*p2
|| tolower(*p1
)!=tolower(*p2
))
80 static HRESULT WINAPI
HTMLEvents_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
82 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
87 ok(0, "Unexpected call\n");
91 static ULONG WINAPI
HTMLEvents_AddRef(IDispatch
*iface
)
96 static ULONG WINAPI
HTMLEvents_Release(IDispatch
*iface
)
101 static HRESULT WINAPI
HTMLEvents_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
103 ok(0, "unexpected call\n");
107 static HRESULT WINAPI
HTMLEvents_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
,
110 ok(0, "unexpected call\n");
114 static HRESULT WINAPI
HTMLEvents_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
115 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
117 ok(0, "unexpected call\n");
121 static HRESULT WINAPI
HTMLEvents_Invoke(IDispatch
*iface
, DISPID dispIdMember
, REFIID riid
,
122 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
123 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
125 if(dispIdMember
== DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE
) {
126 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
129 IHTMLDocument2_get_readyState(html_doc
, &state
);
130 if(!memcmp(state
, completeW
, sizeof(completeW
)))
137 static const IDispatchVtbl HTMLEventsVtbl
= {
138 HTMLEvents_QueryInterface
,
141 HTMLEvents_GetTypeInfoCount
,
142 HTMLEvents_GetTypeInfo
,
143 HTMLEvents_GetIDsOfNames
,
147 static IDispatch HTMLEvents
= { &HTMLEventsVtbl
};
149 static void test_QueryInterface(void)
151 IUnknown
*xmlview
, *unk
;
152 IHTMLDocument
*htmldoc
;
155 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
156 &IID_IUnknown
, (void**)&xmlview
);
158 win_skip("Failed to create XMLView instance\n");
161 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
163 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistMoniker
, (void**)&unk
);
164 ok(hres
== S_OK
, "QueryInterface(IID_IPersistMoniker) returned %x, expected S_OK\n", hres
);
165 IUnknown_Release(unk
);
167 hres
= IUnknown_QueryInterface(xmlview
, &IID_IPersistHistory
, (void**)&unk
);
168 ok(hres
== S_OK
, "QueryInterface(IID_IPersistHistory) returned %x, expected S_OK\n", hres
);
169 IUnknown_Release(unk
);
171 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleCommandTarget
, (void**)&unk
);
172 ok(hres
== S_OK
, "QueryInterface(IID_IOleCommandTarget) returned %x, expected S_OK\n", hres
);
173 IUnknown_Release(unk
);
175 hres
= IUnknown_QueryInterface(xmlview
, &IID_IOleObject
, (void**)&unk
);
176 ok(hres
== S_OK
, "QueryInterface(IID_IOleObject) returned %x, expected S_OK\n", hres
);
177 IUnknown_Release(unk
);
179 hres
= IUnknown_QueryInterface(xmlview
, &IID_IHTMLDocument
, (void**)&htmldoc
);
180 ok(hres
== S_OK
, "QueryInterface(IID_IHTMLDocument) returned %x, expected S_OK\n", hres
);
181 hres
= IHTMLDocument_QueryInterface(htmldoc
, &IID_IUnknown
, (void**)&unk
);
182 ok(hres
== S_OK
, "QueryInterface(IID_IUnknown) returned %x, expected S_OK\n", hres
);
183 todo_wine
ok(unk
== xmlview
, "Aggregation is not working as expected\n");
184 IUnknown_Release(unk
);
185 IHTMLDocument_Release(htmldoc
);
187 IUnknown_Release(xmlview
);
190 static void test_Load(void)
192 static const WCHAR xmlview_xmlW
[] = {'/','x','m','l','/','x','m','l','v','i','e','w','.','x','m','l',0};
193 static const WCHAR res
[] = {'r','e','s',':','/','/',0};
196 IPersistMoniker
*pers_mon
;
197 IConnectionPointContainer
*cpc
;
198 IConnectionPoint
*cp
;
207 GetModuleFileNameW(NULL
, buf
+lstrlenW(buf
), (sizeof(buf
)-sizeof(res
))/sizeof(WCHAR
));
208 lstrcatW(buf
, xmlview_xmlW
);
210 if(!pCreateURLMoniker
) {
211 win_skip("CreateURLMoniker not available\n");
215 hres
= CoCreateInstance(&CLSID_XMLView
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
216 &IID_IPersistMoniker
, (void**)&pers_mon
);
218 win_skip("Failed to create XMLView instance\n");
221 ok(hres
== S_OK
, "CoCreateInstance returned %x, expected S_OK\n", hres
);
223 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IHTMLDocument2
, (void**)&html_doc
);
224 ok(hres
== S_OK
, "QueryInterface(HTMLDocument2) returned %x, expected S_OK\n", hres
);
225 hres
= IPersistMoniker_QueryInterface(pers_mon
, &IID_IConnectionPointContainer
, (void**)&cpc
);
226 ok(hres
== S_OK
, "QueryInterface(IConnectionPointContainer) returned %x, expected S_OK\n", hres
);
227 hres
= IConnectionPointContainer_FindConnectionPoint(cpc
, &IID_IDispatch
, &cp
);
228 ok(hres
== S_OK
, "FindConnectionPoint returned %x, expected S_OK\n", hres
);
229 hres
= IConnectionPoint_Advise(cp
, (IUnknown
*)&HTMLEvents
, NULL
);
230 ok(hres
== S_OK
, "Advise returned %x, expected S_OK\n", hres
);
231 IConnectionPoint_Release(cp
);
232 IConnectionPointContainer_Release(cpc
);
234 hres
= CreateBindCtx(0, &bctx
);
235 ok(hres
== S_OK
, "CreateBindCtx returned %x, expected S_OK\n", hres
);
236 hres
= pCreateURLMoniker(NULL
, buf
, &mon
);
237 ok(hres
== S_OK
, "CreateUrlMoniker returned %x, expected S_OK\n", hres
);
239 hres
= IPersistMoniker_Load(pers_mon
, TRUE
, mon
, bctx
, 0);
240 ok(hres
== S_OK
, "Load returned %x, expected S_OK\n", hres
);
241 IBindCtx_Release(bctx
);
242 IMoniker_Release(mon
);
244 while(!loaded
&& GetMessage(&msg
, NULL
, 0, 0)) {
245 TranslateMessage(&msg
);
246 DispatchMessage(&msg
);
249 hres
= IHTMLDocument2_get_body(html_doc
, &elem
);
250 ok(hres
== S_OK
, "get_body returned %x, expected S_OK\n", hres
);
251 hres
= IHTMLElement_get_outerHTML(elem
, &source
);
252 ok(hres
== S_OK
, "get_outerHTML returned %x, expected S_OK\n", hres
);
253 ok(!html_src_compare(source
, xmlview_html
), "Incorrect HTML source: %s\n", wine_dbgstr_w(source
));
254 IHTMLElement_Release(elem
);
255 SysFreeString(source
);
257 IHTMLDocument2_Release(html_doc
);
259 IPersistMoniker_Release(pers_mon
);
264 HMODULE urlmon
= LoadLibraryA("urlmon.dll");
265 pCreateURLMoniker
= (void*)GetProcAddress(urlmon
, "CreateURLMoniker");
268 test_QueryInterface();