4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
6 * Copyright 2010-2011 Adam Martinson for CodeWeavers
7 * Copyright 2010-2011 Nikolay Sivov for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #include "msxml2did.h"
42 #include "wine/test.h"
44 DEFINE_GUID(SID_SContainerDispatch, 0xb722be00, 0x4e68, 0x101b, 0xa2, 0xbc, 0x00, 0xaa, 0x00, 0x40, 0x47, 0x70);
45 DEFINE_GUID(SID_UnknownSID, 0x75dd09cb, 0x6c40, 0x11d5, 0x85, 0x43, 0x00, 0xc0, 0x4f, 0xa0, 0xfb, 0xa3);
47 #define DEFINE_EXPECT(func) \
48 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
50 #define SET_EXPECT(func) \
51 expect_ ## func = TRUE
53 #define CHECK_EXPECT2(func) \
55 ok(expect_ ##func, "unexpected call " #func "\n"); \
56 called_ ## func = TRUE; \
59 #define CHECK_CALLED(func) \
61 ok(called_ ## func, "expected " #func "\n"); \
62 expect_ ## func = called_ ## func = FALSE; \
65 static const char *debugstr_guid(REFIID riid)
72 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
73 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
74 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
75 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
80 static int g_unexpectedcall, g_expectedcall;
84 IDispatch IDispatch_iface;
88 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
90 return CONTAINING_RECORD(iface, dispevent, IDispatch_iface);
93 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
97 if ( IsEqualGUID( riid, &IID_IDispatch) ||
98 IsEqualGUID( riid, &IID_IUnknown) )
103 return E_NOINTERFACE;
105 IDispatch_AddRef( iface );
110 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
112 dispevent *This = impl_from_IDispatch( iface );
113 return InterlockedIncrement( &This->ref );
116 static ULONG WINAPI dispevent_Release(IDispatch *iface)
118 dispevent *This = impl_from_IDispatch( iface );
119 ULONG ref = InterlockedDecrement( &This->ref );
122 HeapFree(GetProcessHeap(), 0, This);
127 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
134 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
135 LCID lcid, ITypeInfo **ppTInfo)
141 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
142 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
148 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
149 LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
150 EXCEPINFO *excepInfo, UINT *argErr)
152 ok(member == 0, "expected 0 member, got %d\n", member);
153 ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
154 ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
156 ok(params->cArgs == 0, "got %d\n", params->cArgs);
157 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
158 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
159 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
161 ok(result == NULL, "got %p\n", result);
162 ok(excepInfo == NULL, "got %p\n", excepInfo);
163 ok(argErr == NULL, "got %p\n", argErr);
169 static const IDispatchVtbl dispeventVtbl =
171 dispevent_QueryInterface,
174 dispevent_GetTypeInfoCount,
175 dispevent_GetTypeInfo,
176 dispevent_GetIDsOfNames,
180 static IDispatch* create_dispevent(void)
182 dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
184 event->IDispatch_iface.lpVtbl = &dispeventVtbl;
187 return (IDispatch*)&event->IDispatch_iface;
191 DEFINE_EXPECT(site_qi_IServiceProvider);
192 DEFINE_EXPECT(site_qi_IXMLDOMDocument);
193 DEFINE_EXPECT(site_qi_IOleClientSite);
195 DEFINE_EXPECT(sp_queryservice_SID_SBindHost);
196 DEFINE_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
197 DEFINE_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
198 DEFINE_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
199 DEFINE_EXPECT(sp_queryservice_SID_secmgr_secmgr);
201 DEFINE_EXPECT(htmldoc2_get_all);
202 DEFINE_EXPECT(htmldoc2_get_url);
203 DEFINE_EXPECT(collection_get_length);
207 IServiceProvider IServiceProvider_iface;
212 static HRESULT WINAPI site_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
216 if (IsEqualGUID(riid, &IID_IServiceProvider))
217 CHECK_EXPECT2(site_qi_IServiceProvider);
219 if (IsEqualGUID(riid, &IID_IXMLDOMDocument))
220 CHECK_EXPECT2(site_qi_IXMLDOMDocument);
222 if (IsEqualGUID(riid, &IID_IOleClientSite))
223 CHECK_EXPECT2(site_qi_IOleClientSite);
225 if (IsEqualGUID(riid, &IID_IUnknown))
227 else if (IsEqualGUID(riid, &IID_IServiceProvider))
228 *ppvObject = &testprov.IServiceProvider_iface;
230 if (*ppvObject) IUnknown_AddRef(iface);
232 return *ppvObject ? S_OK : E_NOINTERFACE;
235 static ULONG WINAPI site_AddRef(IUnknown *iface)
240 static ULONG WINAPI site_Release(IUnknown *iface)
245 static const IUnknownVtbl testsiteVtbl =
254 IUnknown IUnknown_iface;
257 static testsite_t testsite = { { &testsiteVtbl } };
259 /* test IHTMLElementCollection */
260 static HRESULT WINAPI htmlecoll_QueryInterface(IHTMLElementCollection *iface, REFIID riid, void **ppvObject)
262 ok(0, "unexpected call\n");
264 return E_NOINTERFACE;
267 static ULONG WINAPI htmlecoll_AddRef(IHTMLElementCollection *iface)
272 static ULONG WINAPI htmlecoll_Release(IHTMLElementCollection *iface)
277 static HRESULT WINAPI htmlecoll_GetTypeInfoCount(IHTMLElementCollection *iface, UINT *pctinfo)
279 ok(0, "unexpected call\n");
283 static HRESULT WINAPI htmlecoll_GetTypeInfo(IHTMLElementCollection *iface, UINT iTInfo,
284 LCID lcid, ITypeInfo **ppTInfo)
286 ok(0, "unexpected call\n");
290 static HRESULT WINAPI htmlecoll_GetIDsOfNames(IHTMLElementCollection *iface, REFIID riid,
291 LPOLESTR *rgszNames, UINT cNames,
292 LCID lcid, DISPID *rgDispId)
294 ok(0, "unexpected call\n");
298 static HRESULT WINAPI htmlecoll_Invoke(IHTMLElementCollection *iface, DISPID dispIdMember,
299 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
300 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
302 ok(0, "unexpected call\n");
306 static HRESULT WINAPI htmlecoll_toString(IHTMLElementCollection *iface, BSTR *String)
308 ok(0, "unexpected call\n");
312 static HRESULT WINAPI htmlecoll_put_length(IHTMLElementCollection *iface, LONG v)
314 ok(0, "unexpected call\n");
318 static HRESULT WINAPI htmlecoll_get_length(IHTMLElementCollection *iface, LONG *v)
320 CHECK_EXPECT2(collection_get_length);
324 static HRESULT WINAPI htmlecoll_get__newEnum(IHTMLElementCollection *iface, IUnknown **p)
326 ok(0, "unexpected call\n");
330 static HRESULT WINAPI htmlecoll_item(IHTMLElementCollection *iface, VARIANT name, VARIANT index, IDispatch **pdisp)
332 ok(0, "unexpected call\n");
336 static HRESULT WINAPI htmlecoll_tags(IHTMLElementCollection *iface, VARIANT tagName, IDispatch **pdisp)
338 ok(0, "unexpected call\n");
342 static const IHTMLElementCollectionVtbl TestHTMLECollectionVtbl = {
343 htmlecoll_QueryInterface,
346 htmlecoll_GetTypeInfoCount,
347 htmlecoll_GetTypeInfo,
348 htmlecoll_GetIDsOfNames,
352 htmlecoll_put_length,
353 htmlecoll_get_length,
354 htmlecoll_get__newEnum,
361 IHTMLElementCollection IHTMLElementCollection_iface;
364 static testhtmlecoll_t htmlecoll = { { &TestHTMLECollectionVtbl } };
366 /* test IHTMLDocument2 */
367 static HRESULT WINAPI htmldoc2_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
371 return E_NOINTERFACE;
374 static ULONG WINAPI htmldoc2_AddRef(IHTMLDocument2 *iface)
379 static ULONG WINAPI htmldoc2_Release(IHTMLDocument2 *iface)
384 static HRESULT WINAPI htmldoc2_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
386 ok(0, "unexpected call\n");
390 static HRESULT WINAPI htmldoc2_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
391 LCID lcid, ITypeInfo **ppTInfo)
393 ok(0, "unexpected call\n");
397 static HRESULT WINAPI htmldoc2_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
398 LPOLESTR *rgszNames, UINT cNames,
399 LCID lcid, DISPID *rgDispId)
401 ok(0, "unexpected call\n");
405 static HRESULT WINAPI htmldoc2_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
406 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
407 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
409 ok(0, "unexpected call\n");
413 static HRESULT WINAPI htmldoc2_get_Script(IHTMLDocument2 *iface, IDispatch **p)
415 ok(0, "unexpected call\n");
419 static HRESULT WINAPI htmldoc2_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
421 CHECK_EXPECT2(htmldoc2_get_all);
422 *p = &htmlecoll.IHTMLElementCollection_iface;
426 static HRESULT WINAPI htmldoc2_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
428 ok(0, "unexpected call\n");
432 static HRESULT WINAPI htmldoc2_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
434 ok(0, "unexpected call\n");
438 static HRESULT WINAPI htmldoc2_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
440 ok(0, "unexpected call\n");
444 static HRESULT WINAPI htmldoc2_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
446 ok(0, "unexpected call\n");
450 static HRESULT WINAPI htmldoc2_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
452 ok(0, "unexpected call\n");
456 static HRESULT WINAPI htmldoc2_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
458 ok(0, "unexpected call\n");
462 static HRESULT WINAPI htmldoc2_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
464 ok(0, "unexpected call\n");
468 static HRESULT WINAPI htmldoc2_put_title(IHTMLDocument2 *iface, BSTR v)
470 ok(0, "unexpected call\n");
474 static HRESULT WINAPI htmldoc2_get_title(IHTMLDocument2 *iface, BSTR *p)
476 ok(0, "unexpected call\n");
480 static HRESULT WINAPI htmldoc2_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
482 ok(0, "unexpected call\n");
486 static HRESULT WINAPI htmldoc2_put_designMode(IHTMLDocument2 *iface, BSTR v)
488 ok(0, "unexpected call\n");
492 static HRESULT WINAPI htmldoc2_get_designMode(IHTMLDocument2 *iface, BSTR *p)
494 ok(0, "unexpected call\n");
498 static HRESULT WINAPI htmldoc2_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
500 ok(0, "unexpected call\n");
504 static HRESULT WINAPI htmldoc2_get_readyState(IHTMLDocument2 *iface, BSTR *p)
506 ok(0, "unexpected call\n");
510 static HRESULT WINAPI htmldoc2_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
512 ok(0, "unexpected call\n");
516 static HRESULT WINAPI htmldoc2_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
518 ok(0, "unexpected call\n");
522 static HRESULT WINAPI htmldoc2_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
524 ok(0, "unexpected call\n");
528 static HRESULT WINAPI htmldoc2_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
530 ok(0, "unexpected call\n");
534 static HRESULT WINAPI htmldoc2_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
536 ok(0, "unexpected call\n");
540 static HRESULT WINAPI htmldoc2_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
542 ok(0, "unexpected call\n");
546 static HRESULT WINAPI htmldoc2_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
548 ok(0, "unexpected call\n");
552 static HRESULT WINAPI htmldoc2_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
554 ok(0, "unexpected call\n");
558 static HRESULT WINAPI htmldoc2_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
560 ok(0, "unexpected call\n");
564 static HRESULT WINAPI htmldoc2_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
566 ok(0, "unexpected call\n");
570 static HRESULT WINAPI htmldoc2_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
572 ok(0, "unexpected call\n");
576 static HRESULT WINAPI htmldoc2_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
578 ok(0, "unexpected call\n");
582 static HRESULT WINAPI htmldoc2_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
584 ok(0, "unexpected call\n");
588 static HRESULT WINAPI htmldoc2_get_referrer(IHTMLDocument2 *iface, BSTR *p)
590 ok(0, "unexpected call\n");
594 static HRESULT WINAPI htmldoc2_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
596 ok(0, "unexpected call\n");
600 static HRESULT WINAPI htmldoc2_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
602 ok(0, "unexpected call\n");
606 static HRESULT WINAPI htmldoc2_put_URL(IHTMLDocument2 *iface, BSTR v)
608 ok(0, "unexpected call\n");
612 static HRESULT WINAPI htmldoc2_get_URL(IHTMLDocument2 *iface, BSTR *p)
614 CHECK_EXPECT2(htmldoc2_get_url);
615 *p = SysAllocString(NULL);
619 static HRESULT WINAPI htmldoc2_put_domain(IHTMLDocument2 *iface, BSTR v)
621 ok(0, "unexpected call\n");
625 static HRESULT WINAPI htmldoc2_get_domain(IHTMLDocument2 *iface, BSTR *p)
627 ok(0, "unexpected call\n");
631 static HRESULT WINAPI htmldoc2_put_cookie(IHTMLDocument2 *iface, BSTR v)
633 ok(0, "unexpected call\n");
637 static HRESULT WINAPI htmldoc2_get_cookie(IHTMLDocument2 *iface, BSTR *p)
639 ok(0, "unexpected call\n");
643 static HRESULT WINAPI htmldoc2_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
645 ok(0, "unexpected call\n");
649 static HRESULT WINAPI htmldoc2_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
651 ok(0, "unexpected call\n");
655 static HRESULT WINAPI htmldoc2_put_charset(IHTMLDocument2 *iface, BSTR v)
657 ok(0, "unexpected call\n");
661 static HRESULT WINAPI htmldoc2_get_charset(IHTMLDocument2 *iface, BSTR *p)
663 ok(0, "unexpected call\n");
667 static HRESULT WINAPI htmldoc2_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
669 ok(0, "unexpected call\n");
673 static HRESULT WINAPI htmldoc2_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
675 ok(0, "unexpected call\n");
679 static HRESULT WINAPI htmldoc2_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
681 ok(0, "unexpected call\n");
685 static HRESULT WINAPI htmldoc2_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
687 ok(0, "unexpected call\n");
691 static HRESULT WINAPI htmldoc2_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
693 ok(0, "unexpected call\n");
697 static HRESULT WINAPI htmldoc2_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
699 ok(0, "unexpected call\n");
703 static HRESULT WINAPI htmldoc2_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
705 ok(0, "unexpected call\n");
709 static HRESULT WINAPI htmldoc2_get_security(IHTMLDocument2 *iface, BSTR *p)
711 ok(0, "unexpected call\n");
715 static HRESULT WINAPI htmldoc2_get_protocol(IHTMLDocument2 *iface, BSTR *p)
717 ok(0, "unexpected call\n");
721 static HRESULT WINAPI htmldoc2_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
723 ok(0, "unexpected call\n");
727 static HRESULT WINAPI htmldoc2_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
729 ok(0, "unexpected call\n");
733 static HRESULT WINAPI htmldoc2_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
735 ok(0, "unexpected call\n");
739 static HRESULT WINAPI htmldoc2_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
740 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
742 ok(0, "unexpected call\n");
746 static HRESULT WINAPI htmldoc2_close(IHTMLDocument2 *iface)
748 ok(0, "unexpected call\n");
752 static HRESULT WINAPI htmldoc2_clear(IHTMLDocument2 *iface)
754 ok(0, "unexpected call\n");
758 static HRESULT WINAPI htmldoc2_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
761 ok(0, "unexpected call\n");
765 static HRESULT WINAPI htmldoc2_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
768 ok(0, "unexpected call\n");
772 static HRESULT WINAPI htmldoc2_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
775 ok(0, "unexpected call\n");
779 static HRESULT WINAPI htmldoc2_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
782 ok(0, "unexpected call\n");
786 static HRESULT WINAPI htmldoc2_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
789 ok(0, "unexpected call\n");
793 static HRESULT WINAPI htmldoc2_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
796 ok(0, "unexpected call\n");
800 static HRESULT WINAPI htmldoc2_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
801 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
803 ok(0, "unexpected call\n");
807 static HRESULT WINAPI htmldoc2_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
810 ok(0, "unexpected call\n");
814 static HRESULT WINAPI htmldoc2_createElement(IHTMLDocument2 *iface, BSTR eTag,
815 IHTMLElement **newElem)
817 ok(0, "unexpected call\n");
821 static HRESULT WINAPI htmldoc2_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
823 ok(0, "unexpected call\n");
827 static HRESULT WINAPI htmldoc2_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
829 ok(0, "unexpected call\n");
833 static HRESULT WINAPI htmldoc2_put_onclick(IHTMLDocument2 *iface, VARIANT v)
835 ok(0, "unexpected call\n");
839 static HRESULT WINAPI htmldoc2_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
841 ok(0, "unexpected call\n");
845 static HRESULT WINAPI htmldoc2_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
847 ok(0, "unexpected call\n");
851 static HRESULT WINAPI htmldoc2_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
853 ok(0, "unexpected call\n");
857 static HRESULT WINAPI htmldoc2_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
859 ok(0, "unexpected call\n");
863 static HRESULT WINAPI htmldoc2_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
865 ok(0, "unexpected call\n");
869 static HRESULT WINAPI htmldoc2_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
871 ok(0, "unexpected call\n");
875 static HRESULT WINAPI htmldoc2_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
877 ok(0, "unexpected call\n");
881 static HRESULT WINAPI htmldoc2_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
883 ok(0, "unexpected call\n");
887 static HRESULT WINAPI htmldoc2_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
889 ok(0, "unexpected call\n");
893 static HRESULT WINAPI htmldoc2_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
895 ok(0, "unexpected call\n");
899 static HRESULT WINAPI htmldoc2_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
901 ok(0, "unexpected call\n");
905 static HRESULT WINAPI htmldoc2_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
907 ok(0, "unexpected call\n");
911 static HRESULT WINAPI htmldoc2_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
913 ok(0, "unexpected call\n");
917 static HRESULT WINAPI htmldoc2_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
919 ok(0, "unexpected call\n");
923 static HRESULT WINAPI htmldoc2_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
925 ok(0, "unexpected call\n");
929 static HRESULT WINAPI htmldoc2_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
931 ok(0, "unexpected call\n");
935 static HRESULT WINAPI htmldoc2_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
937 ok(0, "unexpected call\n");
941 static HRESULT WINAPI htmldoc2_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
943 ok(0, "unexpected call\n");
947 static HRESULT WINAPI htmldoc2_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
949 ok(0, "unexpected call\n");
953 static HRESULT WINAPI htmldoc2_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
955 ok(0, "unexpected call\n");
959 static HRESULT WINAPI htmldoc2_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
961 ok(0, "unexpected call\n");
965 static HRESULT WINAPI htmldoc2_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
967 ok(0, "unexpected call\n");
971 static HRESULT WINAPI htmldoc2_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
973 ok(0, "unexpected call\n");
977 static HRESULT WINAPI htmldoc2_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
979 ok(0, "unexpected call\n");
983 static HRESULT WINAPI htmldoc2_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
985 ok(0, "unexpected call\n");
989 static HRESULT WINAPI htmldoc2_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
991 ok(0, "unexpected call\n");
995 static HRESULT WINAPI htmldoc2_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
997 ok(0, "unexpected call\n");
1001 static HRESULT WINAPI htmldoc2_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1003 ok(0, "unexpected call\n");
1007 static HRESULT WINAPI htmldoc2_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1009 ok(0, "unexpected call\n");
1013 static HRESULT WINAPI htmldoc2_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1015 ok(0, "unexpected call\n");
1019 static HRESULT WINAPI htmldoc2_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1021 ok(0, "unexpected call\n");
1025 static HRESULT WINAPI htmldoc2_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1026 IHTMLElement **elementHit)
1028 ok(0, "unexpected call\n");
1032 static HRESULT WINAPI htmldoc2_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1034 ok(0, "unexpected call\n");
1038 static HRESULT WINAPI htmldoc2_get_styleSheets(IHTMLDocument2 *iface,
1039 IHTMLStyleSheetsCollection **p)
1041 ok(0, "unexpected call\n");
1045 static HRESULT WINAPI htmldoc2_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1047 ok(0, "unexpected call\n");
1051 static HRESULT WINAPI htmldoc2_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1053 ok(0, "unexpected call\n");
1057 static HRESULT WINAPI htmldoc2_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1059 ok(0, "unexpected call\n");
1063 static HRESULT WINAPI htmldoc2_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1065 ok(0, "unexpected call\n");
1069 static HRESULT WINAPI htmldoc2_toString(IHTMLDocument2 *iface, BSTR *String)
1071 ok(0, "unexpected call\n");
1075 static HRESULT WINAPI htmldoc2_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1076 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1078 ok(0, "unexpected call\n");
1082 static const IHTMLDocument2Vtbl TestHTMLDocumentVtbl = {
1083 htmldoc2_QueryInterface,
1086 htmldoc2_GetTypeInfoCount,
1087 htmldoc2_GetTypeInfo,
1088 htmldoc2_GetIDsOfNames,
1090 htmldoc2_get_Script,
1093 htmldoc2_get_activeElement,
1094 htmldoc2_get_images,
1095 htmldoc2_get_applets,
1098 htmldoc2_get_anchors,
1101 htmldoc2_get_scripts,
1102 htmldoc2_put_designMode,
1103 htmldoc2_get_designMode,
1104 htmldoc2_get_selection,
1105 htmldoc2_get_readyState,
1106 htmldoc2_get_frames,
1107 htmldoc2_get_embeds,
1108 htmldoc2_get_plugins,
1109 htmldoc2_put_alinkColor,
1110 htmldoc2_get_alinkColor,
1111 htmldoc2_put_bgColor,
1112 htmldoc2_get_bgColor,
1113 htmldoc2_put_fgColor,
1114 htmldoc2_get_fgColor,
1115 htmldoc2_put_linkColor,
1116 htmldoc2_get_linkColor,
1117 htmldoc2_put_vlinkColor,
1118 htmldoc2_get_vlinkColor,
1119 htmldoc2_get_referrer,
1120 htmldoc2_get_location,
1121 htmldoc2_get_lastModified,
1124 htmldoc2_put_domain,
1125 htmldoc2_get_domain,
1126 htmldoc2_put_cookie,
1127 htmldoc2_get_cookie,
1128 htmldoc2_put_expando,
1129 htmldoc2_get_expando,
1130 htmldoc2_put_charset,
1131 htmldoc2_get_charset,
1132 htmldoc2_put_defaultCharset,
1133 htmldoc2_get_defaultCharset,
1134 htmldoc2_get_mimeType,
1135 htmldoc2_get_fileSize,
1136 htmldoc2_get_fileCreatedDate,
1137 htmldoc2_get_fileModifiedDate,
1138 htmldoc2_get_fileUpdatedDate,
1139 htmldoc2_get_security,
1140 htmldoc2_get_protocol,
1141 htmldoc2_get_nameProp,
1147 htmldoc2_queryCommandSupported,
1148 htmldoc2_queryCommandEnabled,
1149 htmldoc2_queryCommandState,
1150 htmldoc2_queryCommandIndeterm,
1151 htmldoc2_queryCommandText,
1152 htmldoc2_queryCommandValue,
1153 htmldoc2_execCommand,
1154 htmldoc2_execCommandShowHelp,
1155 htmldoc2_createElement,
1156 htmldoc2_put_onhelp,
1157 htmldoc2_get_onhelp,
1158 htmldoc2_put_onclick,
1159 htmldoc2_get_onclick,
1160 htmldoc2_put_ondblclick,
1161 htmldoc2_get_ondblclick,
1162 htmldoc2_put_onkeyup,
1163 htmldoc2_get_onkeyup,
1164 htmldoc2_put_onkeydown,
1165 htmldoc2_get_onkeydown,
1166 htmldoc2_put_onkeypress,
1167 htmldoc2_get_onkeypress,
1168 htmldoc2_put_onmouseup,
1169 htmldoc2_get_onmouseup,
1170 htmldoc2_put_onmousedown,
1171 htmldoc2_get_onmousedown,
1172 htmldoc2_put_onmousemove,
1173 htmldoc2_get_onmousemove,
1174 htmldoc2_put_onmouseout,
1175 htmldoc2_get_onmouseout,
1176 htmldoc2_put_onmouseover,
1177 htmldoc2_get_onmouseover,
1178 htmldoc2_put_onreadystatechange,
1179 htmldoc2_get_onreadystatechange,
1180 htmldoc2_put_onafterupdate,
1181 htmldoc2_get_onafterupdate,
1182 htmldoc2_put_onrowexit,
1183 htmldoc2_get_onrowexit,
1184 htmldoc2_put_onrowenter,
1185 htmldoc2_get_onrowenter,
1186 htmldoc2_put_ondragstart,
1187 htmldoc2_get_ondragstart,
1188 htmldoc2_put_onselectstart,
1189 htmldoc2_get_onselectstart,
1190 htmldoc2_elementFromPoint,
1191 htmldoc2_get_parentWindow,
1192 htmldoc2_get_styleSheets,
1193 htmldoc2_put_onbeforeupdate,
1194 htmldoc2_get_onbeforeupdate,
1195 htmldoc2_put_onerrorupdate,
1196 htmldoc2_get_onerrorupdate,
1198 htmldoc2_createStyleSheet
1203 IHTMLDocument2 IHTMLDocument2_iface;
1206 static testhtmldoc2_t htmldoc2 = { { &TestHTMLDocumentVtbl } };
1208 static HRESULT WINAPI sp_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppvObject)
1212 if (IsEqualGUID(riid, &IID_IUnknown) ||
1213 IsEqualGUID(riid, &IID_IServiceProvider))
1216 IServiceProvider_AddRef(iface);
1220 ok(0, "unexpected query interface: %s\n", debugstr_guid(riid));
1222 return E_NOINTERFACE;
1225 static ULONG WINAPI sp_AddRef(IServiceProvider *iface)
1230 static ULONG WINAPI sp_Release(IServiceProvider *iface)
1235 static HRESULT WINAPI sp_QueryService(IServiceProvider *iface, REFGUID service, REFIID riid, void **obj)
1239 if (IsEqualGUID(service, &SID_SBindHost) &&
1240 IsEqualGUID(riid, &IID_IBindHost))
1242 CHECK_EXPECT2(sp_queryservice_SID_SBindHost);
1244 else if (IsEqualGUID(service, &SID_SContainerDispatch) &&
1245 IsEqualGUID(riid, &IID_IHTMLDocument2))
1247 CHECK_EXPECT2(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1249 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1250 IsEqualGUID(riid, &IID_IHTMLDocument2))
1252 CHECK_EXPECT2(sp_queryservice_SID_secmgr_htmldoc2);
1253 *obj = &htmldoc2.IHTMLDocument2_iface;
1256 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1257 IsEqualGUID(riid, &IID_IXMLDOMDocument))
1259 CHECK_EXPECT2(sp_queryservice_SID_secmgr_xmldomdoc);
1261 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1262 IsEqualGUID(riid, &IID_IInternetHostSecurityManager))
1264 CHECK_EXPECT2(sp_queryservice_SID_secmgr_secmgr);
1266 else if (IsEqualGUID(service, &SID_UnknownSID) &&
1267 IsEqualGUID(riid, &IID_IStream))
1269 /* FIXME: unidentified service id */
1272 ok(0, "unexpected request: sid %s, riid %s\n", debugstr_guid(service), debugstr_guid(riid));
1277 static const IServiceProviderVtbl testprovVtbl =
1285 testprov_t testprov = { { &testprovVtbl } };
1287 #define EXPECT_CHILDREN(node) _expect_children((IXMLDOMNode*)node, __LINE__)
1288 static void _expect_children(IXMLDOMNode *node, int line)
1294 hr = IXMLDOMNode_hasChildNodes(node, &b);
1295 ok_(__FILE__,line)(hr == S_OK, "hasChildNodes() failed, 0x%08x\n", hr);
1296 ok_(__FILE__,line)(b == VARIANT_TRUE, "no children, %d\n", b);
1299 #define EXPECT_NO_CHILDREN(node) _expect_no_children((IXMLDOMNode*)node, __LINE__)
1300 static void _expect_no_children(IXMLDOMNode *node, int line)
1306 hr = IXMLDOMNode_hasChildNodes(node, &b);
1307 ok_(__FILE__,line)(hr == S_FALSE, "hasChildNodes() failed, 0x%08x\n", hr);
1308 ok_(__FILE__,line)(b == VARIANT_FALSE, "no children, %d\n", b);
1311 #define EXPECT_REF(node,ref) _expect_ref((IUnknown*)node, ref, __LINE__)
1312 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
1314 ULONG rc = IUnknown_AddRef(obj);
1315 IUnknown_Release(obj);
1316 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
1319 #define EXPECT_LIST_LEN(list,len) _expect_list_len(list, len, __LINE__)
1320 static void _expect_list_len(IXMLDOMNodeList *list, LONG len, int line)
1326 hr = IXMLDOMNodeList_get_length(list, &length);
1327 ok_(__FILE__,line)(hr == S_OK, "got 0x%08x\n", hr);
1328 ok_(__FILE__,line)(length == len, "got %d, expected %d\n", length, len);
1331 #define EXPECT_HR(hr,hr_exp) \
1332 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
1334 static const WCHAR szEmpty[] = { 0 };
1335 static const WCHAR szIncomplete[] = {
1336 '<','?','x','m','l',' ',
1337 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
1339 static const WCHAR szComplete1[] = {
1340 '<','?','x','m','l',' ',
1341 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1342 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
1344 static const WCHAR szComplete2[] = {
1345 '<','?','x','m','l',' ',
1346 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1347 '<','o','>','<','/','o','>','\n',0
1349 static const WCHAR szComplete3[] = {
1350 '<','?','x','m','l',' ',
1351 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1352 '<','a','>','<','/','a','>','\n',0
1354 static const WCHAR szComplete4[] = {
1355 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1356 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
1357 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
1358 'f','n','1','.','t','x','t','\n',
1359 '<','/','b','s','>','\n',
1360 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
1361 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
1362 'f','n','2','.','t','x','t','\n',
1363 '<','/','p','r','>','\n',
1364 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
1365 '<','f','o','>','\n',
1366 '<','b','a','>','\n',
1368 '<','/','b','a','>','\n',
1369 '<','/','f','o','>','\n',
1370 '<','/','l','c','>','\n',0
1372 static const WCHAR szComplete5[] = {
1373 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
1374 'x','m','l','n','s',':','C','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y','"',
1375 ' ','x','m','l','n','s',':','S','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y',':','s','e','a','r','c','h','"','>',
1376 '<','S',':','s','c','o','p','e','>',
1377 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
1378 '<','/','S',':','s','c','o','p','e','>',
1379 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
1380 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
1381 'c','o','m','p','u','t','e','r',
1382 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
1383 '<','/','S',':','s','e','a','r','c','h','>',0
1386 static const WCHAR szComplete6[] = {
1387 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'',' ',
1388 'e','n','c','o','d','i','n','g','=','\'','W','i','n','d','o','w','s','-','1','2','5','2','\'','?','>','\n',
1389 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
1392 static const CHAR szNonUnicodeXML[] =
1393 "<?xml version='1.0' encoding='Windows-1252'?>\n"
1396 static const CHAR szExampleXML[] =
1397 "<?xml version='1.0' encoding='utf-8'?>\n"
1398 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1400 " <a>A1 field</a>\n"
1401 " <b>B1 field</b>\n"
1402 " <c>C1 field</c>\n"
1403 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1404 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
1405 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
1407 " <html xml:space='preserve' xmlns='http://www.w3.org/1999/xhtml'>\n"
1408 " This is <strong>a</strong> <i>description</i> with preserved whitespace. <bar:x/>\n"
1414 " <a>A2 field</a>\n"
1415 " <b>B2 field</b>\n"
1416 " <c type=\"old\">C2 field</c>\n"
1419 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1420 " <a>A3 field</a>\n"
1421 " <b>B3 field</b>\n"
1422 " <c>C3 field</c>\n"
1426 " <a>A4 field</a>\n"
1427 " <b>B4 field</b>\n"
1428 " <foo:c>C4 field</foo:c>\n"
1432 static const CHAR szNodeTypesXML[] =
1433 "<?xml version='1.0'?>"
1434 "<!-- comment node 0 -->"
1435 "<root id='0' depth='0'>"
1436 " <!-- comment node 1 -->"
1438 " <x id='1' depth='1'>"
1439 " <?foo value='PI for x'?>"
1440 " <!-- comment node 2 -->"
1442 " <a id='3' depth='2'/>"
1443 " <b id='4' depth='2'/>"
1444 " <c id='5' depth='2'/>"
1446 " <y id='2' depth='1'>"
1447 " <?bar value='PI for y'?>"
1448 " <!-- comment node 3 -->"
1450 " <a id='6' depth='2'/>"
1451 " <b id='7' depth='2'/>"
1452 " <c id='8' depth='2'/>"
1456 static const CHAR szTransformXML[] =
1457 "<?xml version=\"1.0\"?>\n"
1462 static const CHAR szTransformSSXML[] =
1463 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
1464 " <xsl:output method=\"html\"/>\n"
1465 " <xsl:template match=\"/\">\n"
1466 " <xsl:apply-templates select=\"greeting\"/>\n"
1467 " </xsl:template>\n"
1468 " <xsl:template match=\"greeting\">\n"
1472 " <xsl:value-of select=\".\"/>\n"
1476 " </xsl:template>\n"
1477 "</xsl:stylesheet>";
1479 static const CHAR szTransformOutput[] =
1482 "</h1></body></html>";
1484 static const CHAR szTypeValueXML[] =
1485 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1486 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
1487 " <string>Wine</string>\n"
1488 " <string2 dt:dt=\"string\">String</string2>\n"
1489 " <number dt:dt=\"number\">12.44</number>\n"
1490 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
1491 " <int dt:dt=\"int\">-13</int>\n"
1492 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
1493 " <bool dt:dt=\"boolean\">1</bool>\n"
1494 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
1495 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
1496 " <date dt:dt=\"date\">3721-11-01</date>\n"
1497 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
1498 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
1499 " <i1 dt:dt=\"i1\">-13</i1>\n"
1500 " <i2 dt:dt=\"i2\">31915</i2>\n"
1501 " <i4 dt:dt=\"i4\">-312232</i4>\n"
1502 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
1503 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
1504 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
1505 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
1506 " <r8 dt:dt=\"r8\">0.412</r8>\n"
1507 " <float dt:dt=\"float\">41221.421</float>\n"
1508 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
1509 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
1510 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
1511 " <binbase64_1 dt:dt=\"bin.base64\">\nYmFzZTY0\nIHRlc3Q=\n</binbase64_1>\n"
1512 " <binbase64_2 dt:dt=\"bin.base64\">\nYmF\r\t z ZTY0\nIHRlc3Q=\n</binbase64_2>\n"
1515 static const CHAR szBasicTransformSSXMLPart1[] =
1516 "<?xml version=\"1.0\"?>"
1517 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
1518 "<xsl:output method=\"html\"/>\n"
1519 "<xsl:template match=\"/\">"
1520 "<HTML><BODY><TABLE>"
1521 " <xsl:apply-templates select='document(\"";
1523 static const CHAR szBasicTransformSSXMLPart2[] =
1525 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
1526 " </xsl:apply-templates>"
1527 "</TABLE></BODY></HTML>"
1529 "<xsl:template match=\"bottle\">"
1530 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
1532 "<xsl:template match=\"name\">"
1533 " <TD><xsl:apply-templates /></TD>"
1535 "<xsl:template match=\"cost\">"
1536 " <TD><xsl:apply-templates /></TD>"
1538 "</xsl:stylesheet>";
1540 static const CHAR szBasicTransformXML[] =
1541 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
1543 static const CHAR szBasicTransformOutput[] =
1544 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
1546 #define SZ_EMAIL_DTD \
1547 "<!DOCTYPE email ["\
1548 " <!ELEMENT email (recipients,from,reply-to?,subject,body,attachment*)>"\
1549 " <!ATTLIST email attachments IDREFS #REQUIRED>"\
1550 " <!ATTLIST email sent (yes|no) \"no\">"\
1551 " <!ELEMENT recipients (to+,cc*)>"\
1552 " <!ELEMENT to (#PCDATA)>"\
1553 " <!ATTLIST to name CDATA #IMPLIED>"\
1554 " <!ELEMENT cc (#PCDATA)>"\
1555 " <!ATTLIST cc name CDATA #IMPLIED>"\
1556 " <!ELEMENT from (#PCDATA)>"\
1557 " <!ATTLIST from name CDATA #IMPLIED>"\
1558 " <!ELEMENT reply-to (#PCDATA)>"\
1559 " <!ATTLIST reply-to name CDATA #IMPLIED>"\
1560 " <!ELEMENT subject ANY>"\
1561 " <!ELEMENT body ANY>"\
1562 " <!ATTLIST body enc CDATA #FIXED \"UTF-8\">"\
1563 " <!ELEMENT attachment (#PCDATA)>"\
1564 " <!ATTLIST attachment id ID #REQUIRED>"\
1567 static const CHAR szEmailXML[] =
1568 "<?xml version=\"1.0\"?>"
1570 "<email attachments=\"patch1\">"
1572 " <to>wine-patches@winehq.org</to>"
1574 " <from name=\"Anonymous\">user@localhost</from>"
1575 " <subject>msxml3/tests: DTD validation (try 87)</subject>"
1577 " It no longer causes spontaneous combustion..."
1579 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1582 static const CHAR szEmailXML_0D[] =
1583 "<?xml version=\"1.0\"?>"
1585 "<email attachments=\"patch1\">"
1587 " <to>wine-patches@winehq.org</to>"
1589 " <from name=\"Anonymous\">user@localhost</from>"
1590 " <subject>msxml3/tests: DTD validation (try 88)</subject>"
1593 " XML_ELEMENT_UNDECLARED 0xC00CE00D"
1595 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1598 static const CHAR szEmailXML_0E[] =
1599 "<?xml version=\"1.0\"?>"
1601 "<email attachments=\"patch1\">"
1603 " <to>wine-patches@winehq.org</to>"
1605 " <from name=\"Anonymous\">user@localhost</from>"
1606 " <subject>msxml3/tests: DTD validation (try 89)</subject>"
1608 " XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E"
1610 " <attachment id=\"patch\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1613 static const CHAR szEmailXML_11[] =
1614 "<?xml version=\"1.0\"?>"
1616 "<email attachments=\"patch1\">"
1619 " <from name=\"Anonymous\">user@localhost</from>"
1620 " <subject>msxml3/tests: DTD validation (try 90)</subject>"
1622 " XML_EMPTY_NOT_ALLOWED 0xC00CE011"
1624 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1627 static const CHAR szEmailXML_13[] =
1628 "<?xml version=\"1.0\"?>"
1630 "<msg attachments=\"patch1\">"
1632 " <to>wine-patches@winehq.org</to>"
1634 " <from name=\"Anonymous\">user@localhost</from>"
1635 " <subject>msxml3/tests: DTD validation (try 91)</subject>"
1637 " XML_ROOT_NAME_MISMATCH 0xC00CE013"
1639 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1642 static const CHAR szEmailXML_14[] =
1643 "<?xml version=\"1.0\"?>"
1645 "<email attachments=\"patch1\">"
1646 " <to>wine-patches@winehq.org</to>"
1647 " <from name=\"Anonymous\">user@localhost</from>"
1648 " <subject>msxml3/tests: DTD validation (try 92)</subject>"
1650 " XML_INVALID_CONTENT 0xC00CE014"
1652 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1655 static const CHAR szEmailXML_15[] =
1656 "<?xml version=\"1.0\"?>"
1658 "<email attachments=\"patch1\" ip=\"127.0.0.1\">"
1660 " <to>wine-patches@winehq.org</to>"
1662 " <from name=\"Anonymous\">user@localhost</from>"
1663 " <subject>msxml3/tests: DTD validation (try 93)</subject>"
1665 " XML_ATTRIBUTE_NOT_DEFINED 0xC00CE015"
1667 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1670 static const CHAR szEmailXML_16[] =
1671 "<?xml version=\"1.0\"?>"
1673 "<email attachments=\"patch1\">"
1675 " <to>wine-patches@winehq.org</to>"
1677 " <from name=\"Anonymous\">user@localhost</from>"
1678 " <subject>msxml3/tests: DTD validation (try 94)</subject>"
1679 " <body enc=\"ASCII\">"
1680 " XML_ATTRIBUTE_FIXED 0xC00CE016"
1682 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1685 static const CHAR szEmailXML_17[] =
1686 "<?xml version=\"1.0\"?>"
1688 "<email attachments=\"patch1\" sent=\"true\">"
1690 " <to>wine-patches@winehq.org</to>"
1692 " <from name=\"Anonymous\">user@localhost</from>"
1693 " <subject>msxml3/tests: DTD validation (try 95)</subject>"
1695 " XML_ATTRIBUTE_VALUE 0xC00CE017"
1697 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1700 static const CHAR szEmailXML_18[] =
1701 "<?xml version=\"1.0\"?>"
1703 "<email attachments=\"patch1\">"
1706 " <to>wine-patches@winehq.org</to>"
1708 " <from name=\"Anonymous\">user@localhost</from>"
1709 " <subject>msxml3/tests: DTD validation (try 96)</subject>"
1711 " XML_ILLEGAL_TEXT 0xC00CE018"
1713 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1716 static const CHAR szEmailXML_20[] =
1717 "<?xml version=\"1.0\"?>"
1721 " <to>wine-patches@winehq.org</to>"
1723 " <from name=\"Anonymous\">user@localhost</from>"
1724 " <subject>msxml3/tests: DTD validation (try 97)</subject>"
1726 " XML_REQUIRED_ATTRIBUTE_MISSING 0xC00CE020"
1728 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1731 static const WCHAR szNonExistentFile[] = {
1732 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
1734 static const WCHAR szNonExistentAttribute[] = {
1735 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
1737 static const WCHAR szDocument[] = {
1738 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
1741 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
1742 static WCHAR szdl[] = { 'd','l',0 };
1743 static const WCHAR szvr[] = { 'v','r',0 };
1744 static const WCHAR szlc[] = { 'l','c',0 };
1745 static WCHAR szbs[] = { 'b','s',0 };
1746 static const WCHAR szstr1[] = { 's','t','r','1',0 };
1747 static const WCHAR szstr2[] = { 's','t','r','2',0 };
1748 static const WCHAR szstar[] = { '*',0 };
1749 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
1751 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
1752 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
1753 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
1755 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
1756 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
1757 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
1758 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
1759 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
1760 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
1761 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
1763 static WCHAR szAttribute[] = {'A','t','t','r',0 };
1764 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
1766 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
1767 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
1768 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
1769 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
1771 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
1772 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
1774 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
1775 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
1776 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
1778 #define expect_bstr_eq_and_free(bstr, expect) { \
1779 BSTR bstrExp = alloc_str_from_narrow(expect); \
1780 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
1781 SysFreeString(bstr); \
1782 SysFreeString(bstrExp); \
1785 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
1787 #define ole_check(expr) { \
1789 ok(r == S_OK, #expr " returned %x\n", r); \
1792 #define ole_expect(expr, expect) { \
1794 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
1797 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
1799 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
1804 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
1806 win_skip_(__FILE__,line)("failed to create %s instance: 0x%08x\n", name, hr);
1811 #define _create(cls) cls, #cls
1813 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument), iid, __LINE__)
1814 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
1815 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
1816 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
1817 #define create_xsltemplate(iid) _create_object(&_create(CLSID_XSLTemplate), iid, __LINE__)
1819 static BSTR alloc_str_from_narrow(const char *str)
1821 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
1822 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
1823 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
1827 static BSTR alloced_bstrs[256];
1828 static int alloced_bstrs_count;
1830 static BSTR _bstr_(const char *str)
1832 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
1833 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
1834 return alloced_bstrs[alloced_bstrs_count++];
1837 static void free_bstrs(void)
1840 for (i = 0; i < alloced_bstrs_count; i++)
1841 SysFreeString(alloced_bstrs[i]);
1842 alloced_bstrs_count = 0;
1845 static VARIANT _variantbstr_(const char *str)
1849 V_BSTR(&v) = _bstr_(str);
1853 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
1857 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
1858 while (*sRight == '\r' || *sRight == '\n') sRight++;
1859 if (*sLeft != *sRight) return FALSE;
1860 if (!*sLeft) return TRUE;
1866 static void get_str_for_type(DOMNodeType type, char *buf)
1870 case NODE_ATTRIBUTE:
1885 case NODE_PROCESSING_INSTRUCTION:
1889 wsprintfA(buf, "[%d]", type);
1893 #define test_disp(u) _test_disp(__LINE__,u)
1894 static void _test_disp(unsigned line, IUnknown *unk)
1896 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
1897 IDispatchEx *dispex;
1904 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
1905 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
1910 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
1911 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
1912 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
1914 sName = SysAllocString( szstar );
1915 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
1916 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1917 SysFreeString( sName );
1919 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
1920 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1922 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
1923 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1924 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
1926 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
1927 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1929 SysFreeString(sName);
1931 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
1932 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1934 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
1935 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1936 if(hres == S_OK && pUnk)
1937 IUnknown_Release(pUnk);
1939 IDispatchEx_Release(dispex);
1942 static int get_node_position(IXMLDOMNode *node)
1947 IXMLDOMNode_AddRef(node);
1950 IXMLDOMNode *new_node;
1953 r = IXMLDOMNode_get_previousSibling(node, &new_node);
1954 ok(SUCCEEDED(r), "get_previousSibling failed\n");
1955 IXMLDOMNode_Release(node);
1957 } while (r == S_OK);
1961 static void node_to_string(IXMLDOMNode *node, char *buf)
1968 lstrcpyA(buf, "(null)");
1972 IXMLDOMNode_AddRef(node);
1975 IXMLDOMNode *new_node;
1977 ole_check(IXMLDOMNode_get_nodeType(node, &type));
1978 get_str_for_type(type, buf);
1981 if (type == NODE_ATTRIBUTE)
1984 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
1986 wsprintfA(buf, "%ws", bstr);
1989 SysFreeString(bstr);
1991 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
1995 r = IXMLDOMNode_get_parentNode(node, &new_node);
1996 wsprintf(buf, "%d", get_node_position(node));
2000 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
2001 IXMLDOMNode_Release(node);
2010 static char *list_to_string(IXMLDOMNodeList *list)
2012 static char buf[4096];
2019 lstrcpyA(buf, "(null)");
2022 ole_check(IXMLDOMNodeList_get_length(list, &len));
2023 for (i = 0; i < len; i++)
2028 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2029 node_to_string(node, pos);
2031 IXMLDOMNode_Release(node);
2037 #define expect_node(node, expstr) { char str[4096]; node_to_string(node, str); ok(strcmp(str, expstr)==0, "Invalid node: %s, expected %s\n", str, expstr); }
2038 #define expect_list_and_release(list, expstr) { char *str = list_to_string(list); ok(strcmp(str, expstr)==0, "Invalid node list: %s, expected %s\n", str, expstr); if (list) IXMLDOMNodeList_Release(list); }
2040 static void test_domdoc( void )
2043 IXMLDOMDocument *doc;
2044 IXMLDOMParseError *error;
2045 IXMLDOMElement *element = NULL;
2047 IXMLDOMText *nodetext = NULL;
2048 IXMLDOMComment *node_comment = NULL;
2049 IXMLDOMAttribute *node_attr = NULL;
2050 IXMLDOMNode *nodeChild = NULL;
2051 IXMLDOMProcessingInstruction *nodePI = NULL;
2052 ISupportErrorInfo *support_error = NULL;
2060 doc = create_document(&IID_IXMLDOMDocument);
2063 test_disp((IUnknown*)doc);
2067 /* crashes on native */
2068 IXMLDOMDocument_loadXML( doc, (BSTR)0x1, NULL );
2071 /* try some stupid things */
2072 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
2073 ok( r == S_FALSE, "loadXML succeeded\n");
2076 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
2077 ok( r == S_FALSE, "loadXML succeeded\n");
2078 ok( b == VARIANT_FALSE, "failed to load XML string\n");
2080 /* try to load a document from a nonexistent file */
2082 str = SysAllocString( szNonExistentFile );
2084 V_VT(&var) = VT_BSTR;
2087 r = IXMLDOMDocument_load( doc, var, &b);
2088 ok( r == S_FALSE, "loadXML succeeded\n");
2089 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2090 SysFreeString( str );
2092 /* try load an empty document */
2094 str = SysAllocString( szEmpty );
2095 r = IXMLDOMDocument_loadXML( doc, str, &b );
2096 ok( r == S_FALSE, "loadXML succeeded\n");
2097 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2098 SysFreeString( str );
2100 r = IXMLDOMDocument_get_async( doc, &b );
2101 ok( r == S_OK, "get_async failed (%08x)\n", r);
2102 ok( b == VARIANT_TRUE, "Wrong default value\n");
2104 /* check that there's no document element */
2106 r = IXMLDOMDocument_get_documentElement( doc, &element );
2107 ok( r == S_FALSE, "should be no document element\n");
2109 /* try finding a node */
2111 str = SysAllocString( szstr1 );
2112 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
2113 ok( r == S_FALSE, "ret %08x\n", r );
2114 SysFreeString( str );
2117 str = SysAllocString( szIncomplete );
2118 r = IXMLDOMDocument_loadXML( doc, str, &b );
2119 ok( r == S_FALSE, "loadXML succeeded\n");
2120 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2121 SysFreeString( str );
2123 /* check that there's no document element */
2124 element = (IXMLDOMElement*)1;
2125 r = IXMLDOMDocument_get_documentElement( doc, &element );
2126 ok( r == S_FALSE, "should be no document element\n");
2127 ok( element == NULL, "Element should be NULL\n");
2129 /* test for BSTR handling, pass broken BSTR */
2130 memcpy(&buff[2], szComplete1, sizeof(szComplete1));
2131 /* just a big length */
2132 *(DWORD*)buff = 0xf0f0;
2134 r = IXMLDOMDocument_loadXML( doc, &buff[2], &b );
2135 ok( r == S_OK, "loadXML failed\n");
2136 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2138 /* loadXML ignores the encoding attribute and always expects Unicode */
2140 str = SysAllocString( szComplete6 );
2141 r = IXMLDOMDocument_loadXML( doc, str, &b );
2142 ok( r == S_OK, "loadXML failed\n");
2143 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2144 SysFreeString( str );
2146 /* try a BSTR containing a Windows-1252 document */
2148 str = SysAllocStringByteLen( szNonUnicodeXML, sizeof(szNonUnicodeXML) - 1 );
2149 r = IXMLDOMDocument_loadXML( doc, str, &b );
2150 ok( r == S_FALSE, "loadXML succeeded\n");
2151 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2152 SysFreeString( str );
2154 /* try to load something valid */
2156 str = SysAllocString( szComplete1 );
2157 r = IXMLDOMDocument_loadXML( doc, str, &b );
2158 ok( r == S_OK, "loadXML failed\n");
2159 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2160 SysFreeString( str );
2162 /* check if nodename is correct */
2163 r = IXMLDOMDocument_get_nodeName( doc, NULL );
2164 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2166 str = (BSTR)0xdeadbeef;
2167 r = IXMLDOMDocument_get_baseName( doc, &str );
2168 ok ( r == S_FALSE, "got 0x%08x\n", r);
2169 ok (str == NULL, "got %p\n", str);
2171 /* content doesn't matter here */
2173 r = IXMLDOMDocument_get_nodeName( doc, &str );
2174 ok ( r == S_OK, "get_nodeName wrong code\n");
2175 ok ( str != NULL, "str is null\n");
2176 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
2177 SysFreeString( str );
2180 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
2181 ok( r == E_FAIL, "ret %08x\n", r );
2183 /* check that there's a document element */
2185 r = IXMLDOMDocument_get_documentElement( doc, &element );
2186 ok( r == S_OK, "should be a document element\n");
2189 IObjectIdentity *ident;
2191 test_disp((IUnknown*)element);
2193 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (void**)&ident );
2194 ok( r == E_NOINTERFACE, "ret %08x\n", r);
2196 IXMLDOMElement_Release( element );
2200 /* as soon as we call loadXML again, the document element will disappear */
2202 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
2203 ok( r == S_FALSE, "loadXML failed\n");
2204 ok( b == 2, "variant modified\n");
2205 r = IXMLDOMDocument_get_documentElement( doc, &element );
2206 ok( r == S_FALSE, "should be no document element\n");
2208 /* try to load something else simple and valid */
2210 str = SysAllocString( szComplete3 );
2211 r = IXMLDOMDocument_loadXML( doc, str, &b );
2212 ok( r == S_OK, "loadXML failed\n");
2213 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2214 SysFreeString( str );
2216 /* try something a little more complicated */
2218 str = SysAllocString( szComplete4 );
2219 r = IXMLDOMDocument_loadXML( doc, str, &b );
2220 ok( r == S_OK, "loadXML failed\n");
2221 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2222 SysFreeString( str );
2224 r = IXMLDOMDocument_get_parseError( doc, &error );
2225 ok( r == S_OK, "returns %08x\n", r );
2227 r = IXMLDOMParseError_get_errorCode( error, &code );
2228 ok( r == S_FALSE, "returns %08x\n", r );
2229 ok( code == 0, "code %d\n", code );
2230 IXMLDOMParseError_Release( error );
2232 /* test createTextNode */
2233 r = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &nodetext);
2234 ok( r == S_OK, "returns %08x\n", r );
2235 IXMLDOMText_Release(nodetext);
2237 str = SysAllocString( szOpen );
2238 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
2239 ok( r == E_INVALIDARG, "returns %08x\n", r );
2240 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
2241 ok( r == S_OK, "returns %08x\n", r );
2242 SysFreeString( str );
2245 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element);
2246 ok(r == E_NOINTERFACE, "ret %08x\n", r );
2248 /* Text Last Child Checks */
2249 r = IXMLDOMText_get_lastChild(nodetext, NULL);
2250 ok(r == E_INVALIDARG, "ret %08x\n", r );
2252 nodeChild = (IXMLDOMNode*)0x1;
2253 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
2254 ok(r == S_FALSE, "ret %08x\n", r );
2255 ok(nodeChild == NULL, "nodeChild not NULL\n");
2257 /* test length property */
2258 r = IXMLDOMText_get_length(nodetext, NULL);
2259 ok(r == E_INVALIDARG, "ret %08x\n", r );
2261 r = IXMLDOMText_get_length(nodetext, &nLength);
2262 ok(r == S_OK, "ret %08x\n", r );
2263 ok(nLength == 4, "expected 4 got %d\n", nLength);
2265 /* put data Tests */
2266 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
2267 ok(r == S_OK, "ret %08x\n", r );
2269 /* get data Tests */
2270 r = IXMLDOMText_get_data(nodetext, &str);
2271 ok(r == S_OK, "ret %08x\n", r );
2272 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
2275 /* Confirm XML text is good */
2276 r = IXMLDOMText_get_xml(nodetext, &str);
2277 ok(r == S_OK, "ret %08x\n", r );
2278 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2281 /* Confirm we get the put_data Text back */
2282 r = IXMLDOMText_get_text(nodetext, &str);
2283 ok(r == S_OK, "ret %08x\n", r );
2284 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2287 /* test substringData */
2288 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
2289 ok(r == E_INVALIDARG, "ret %08x\n", r );
2291 /* test substringData - Invalid offset */
2292 str = (BSTR)&szElement;
2293 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
2294 ok(r == E_INVALIDARG, "ret %08x\n", r );
2295 ok( str == NULL, "incorrect string\n");
2297 /* test substringData - Invalid offset */
2298 str = (BSTR)&szElement;
2299 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
2300 ok(r == S_FALSE, "ret %08x\n", r );
2301 ok( str == NULL, "incorrect string\n");
2303 /* test substringData - Invalid size */
2304 str = (BSTR)&szElement;
2305 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
2306 ok(r == E_INVALIDARG, "ret %08x\n", r );
2307 ok( str == NULL, "incorrect string\n");
2309 /* test substringData - Invalid size */
2310 str = (BSTR)&szElement;
2311 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
2312 ok(r == S_FALSE, "ret %08x\n", r );
2313 ok( str == NULL, "incorrect string\n");
2315 /* test substringData - Start of string */
2316 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
2317 ok(r == S_OK, "ret %08x\n", r );
2318 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2321 /* test substringData - Middle of string */
2322 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
2323 ok(r == S_OK, "ret %08x\n", r );
2324 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2327 /* test substringData - End of string */
2328 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
2329 ok(r == S_OK, "ret %08x\n", r );
2330 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2333 /* test appendData */
2334 r = IXMLDOMText_appendData(nodetext, NULL);
2335 ok(r == S_OK, "ret %08x\n", r );
2337 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
2338 ok(r == S_OK, "ret %08x\n", r );
2340 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
2341 ok(r == S_OK, "ret %08x\n", r );
2343 r = IXMLDOMText_get_text(nodetext, &str);
2344 ok(r == S_OK, "ret %08x\n", r );
2345 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2348 /* test insertData */
2349 str = SysAllocStringLen(NULL, 0);
2350 r = IXMLDOMText_insertData(nodetext, -1, str);
2351 ok(r == S_OK, "ret %08x\n", r );
2353 r = IXMLDOMText_insertData(nodetext, -1, NULL);
2354 ok(r == S_OK, "ret %08x\n", r );
2356 r = IXMLDOMText_insertData(nodetext, 1000, str);
2357 ok(r == S_OK, "ret %08x\n", r );
2359 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
2360 ok(r == S_OK, "ret %08x\n", r );
2362 r = IXMLDOMText_insertData(nodetext, 0, NULL);
2363 ok(r == S_OK, "ret %08x\n", r );
2365 r = IXMLDOMText_insertData(nodetext, 0, str);
2366 ok(r == S_OK, "ret %08x\n", r );
2369 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
2370 ok(r == E_INVALIDARG, "ret %08x\n", r );
2372 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
2373 ok(r == E_INVALIDARG, "ret %08x\n", r );
2375 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
2376 ok(r == S_OK, "ret %08x\n", r );
2378 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
2379 ok(r == S_OK, "ret %08x\n", r );
2381 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
2382 ok(r == S_OK, "ret %08x\n", r );
2384 r = IXMLDOMText_get_text(nodetext, &str);
2385 ok(r == S_OK, "ret %08x\n", r );
2386 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2390 /* invalid arguments */
2391 r = IXMLDOMText_deleteData(nodetext, -1, 1);
2392 ok(r == E_INVALIDARG, "ret %08x\n", r );
2394 r = IXMLDOMText_deleteData(nodetext, 0, 0);
2395 ok(r == S_OK, "ret %08x\n", r );
2397 r = IXMLDOMText_deleteData(nodetext, 0, -1);
2398 ok(r == E_INVALIDARG, "ret %08x\n", r );
2400 r = IXMLDOMText_get_length(nodetext, &nLength);
2401 ok(r == S_OK, "ret %08x\n", r );
2402 ok(nLength == 43, "expected 43 got %d\n", nLength);
2404 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
2405 ok(r == S_OK, "ret %08x\n", r );
2407 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
2408 ok(r == E_INVALIDARG, "ret %08x\n", r );
2410 /* delete from start */
2411 r = IXMLDOMText_deleteData(nodetext, 0, 5);
2412 ok(r == S_OK, "ret %08x\n", r );
2414 r = IXMLDOMText_get_length(nodetext, &nLength);
2415 ok(r == S_OK, "ret %08x\n", r );
2416 ok(nLength == 38, "expected 38 got %d\n", nLength);
2418 r = IXMLDOMText_get_text(nodetext, &str);
2419 ok(r == S_OK, "ret %08x\n", r );
2420 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2423 /* delete from end */
2424 r = IXMLDOMText_deleteData(nodetext, 35, 3);
2425 ok(r == S_OK, "ret %08x\n", r );
2427 r = IXMLDOMText_get_length(nodetext, &nLength);
2428 ok(r == S_OK, "ret %08x\n", r );
2429 ok(nLength == 35, "expected 35 got %d\n", nLength);
2431 r = IXMLDOMText_get_text(nodetext, &str);
2432 ok(r == S_OK, "ret %08x\n", r );
2433 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2436 /* delete from inside */
2437 r = IXMLDOMText_deleteData(nodetext, 1, 33);
2438 ok(r == S_OK, "ret %08x\n", r );
2440 r = IXMLDOMText_get_length(nodetext, &nLength);
2441 ok(r == S_OK, "ret %08x\n", r );
2442 ok(nLength == 2, "expected 2 got %d\n", nLength);
2444 r = IXMLDOMText_get_text(nodetext, &str);
2445 ok(r == S_OK, "ret %08x\n", r );
2446 ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2449 /* delete whole data ... */
2450 r = IXMLDOMText_get_length(nodetext, &nLength);
2451 ok(r == S_OK, "ret %08x\n", r );
2453 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
2454 ok(r == S_OK, "ret %08x\n", r );
2455 /* ... and try again with empty string */
2456 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
2457 ok(r == S_OK, "ret %08x\n", r );
2460 V_VT(&var) = VT_BSTR;
2461 V_BSTR(&var) = SysAllocString(szstr1);
2462 r = IXMLDOMText_put_nodeValue(nodetext, var);
2463 ok(r == S_OK, "ret %08x\n", r );
2466 r = IXMLDOMText_get_text(nodetext, &str);
2467 ok(r == S_OK, "ret %08x\n", r );
2468 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2474 r = IXMLDOMText_put_nodeValue(nodetext, var);
2475 ok(r == S_OK, "ret %08x\n", r );
2478 r = IXMLDOMText_get_text(nodetext, &str);
2479 ok(r == S_OK, "ret %08x\n", r );
2480 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2483 /* ::replaceData() */
2484 V_VT(&var) = VT_BSTR;
2485 V_BSTR(&var) = SysAllocString(szstr1);
2486 r = IXMLDOMText_put_nodeValue(nodetext, var);
2487 ok(r == S_OK, "ret %08x\n", r );
2490 r = IXMLDOMText_replaceData(nodetext, 6, 0, NULL);
2491 ok(r == E_INVALIDARG, "ret %08x\n", r );
2492 r = IXMLDOMText_get_text(nodetext, &str);
2493 ok(r == S_OK, "ret %08x\n", r );
2494 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2497 r = IXMLDOMText_replaceData(nodetext, 0, 0, NULL);
2498 ok(r == S_OK, "ret %08x\n", r );
2499 r = IXMLDOMText_get_text(nodetext, &str);
2500 ok(r == S_OK, "ret %08x\n", r );
2501 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2504 /* NULL pointer means delete */
2505 r = IXMLDOMText_replaceData(nodetext, 0, 1, NULL);
2506 ok(r == S_OK, "ret %08x\n", r );
2507 r = IXMLDOMText_get_text(nodetext, &str);
2508 ok(r == S_OK, "ret %08x\n", r );
2509 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2512 /* empty string means delete */
2513 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_(""));
2514 ok(r == S_OK, "ret %08x\n", r );
2515 r = IXMLDOMText_get_text(nodetext, &str);
2516 ok(r == S_OK, "ret %08x\n", r );
2517 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2520 /* zero count means insert */
2521 r = IXMLDOMText_replaceData(nodetext, 0, 0, _bstr_("a"));
2522 ok(r == S_OK, "ret %08x\n", r );
2523 r = IXMLDOMText_get_text(nodetext, &str);
2524 ok(r == S_OK, "ret %08x\n", r );
2525 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2528 r = IXMLDOMText_replaceData(nodetext, 0, 2, NULL);
2529 ok(r == S_OK, "ret %08x\n", r );
2531 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("m"));
2532 ok(r == S_OK, "ret %08x\n", r );
2533 r = IXMLDOMText_get_text(nodetext, &str);
2534 ok(r == S_OK, "ret %08x\n", r );
2535 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2538 /* nonempty string, count greater than its length */
2539 r = IXMLDOMText_replaceData(nodetext, 0, 2, _bstr_("a1.2"));
2540 ok(r == S_OK, "ret %08x\n", r );
2541 r = IXMLDOMText_get_text(nodetext, &str);
2542 ok(r == S_OK, "ret %08x\n", r );
2543 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2546 /* nonempty string, count less than its length */
2547 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_("wine"));
2548 ok(r == S_OK, "ret %08x\n", r );
2549 r = IXMLDOMText_get_text(nodetext, &str);
2550 ok(r == S_OK, "ret %08x\n", r );
2551 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2554 IXMLDOMText_Release( nodetext );
2557 /* test Create Comment */
2558 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
2559 ok( r == E_INVALIDARG, "returns %08x\n", r );
2560 node_comment = (IXMLDOMComment*)0x1;
2563 r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
2564 ok( r == S_OK, "returns %08x\n", r );
2566 r = IXMLDOMComment_get_data(node_comment, &str);
2567 ok( r == S_OK, "returns %08x\n", r );
2568 ok( str && SysStringLen(str) == 0, "expected empty string data\n");
2569 IXMLDOMComment_Release(node_comment);
2572 r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
2573 ok( r == S_OK, "returns %08x\n", r );
2575 r = IXMLDOMComment_get_data(node_comment, &str);
2576 ok( r == S_OK, "returns %08x\n", r );
2577 ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
2578 IXMLDOMComment_Release(node_comment);
2581 str = SysAllocString(szComment);
2582 r = IXMLDOMDocument_createComment(doc, str, &node_comment);
2584 ok( r == S_OK, "returns %08x\n", r );
2587 /* Last Child Checks */
2588 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
2589 ok(r == E_INVALIDARG, "ret %08x\n", r );
2591 nodeChild = (IXMLDOMNode*)0x1;
2592 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
2593 ok(r == S_FALSE, "ret %08x\n", r );
2594 ok(nodeChild == NULL, "pLastChild not NULL\n");
2597 str = (BSTR)0xdeadbeef;
2598 IXMLDOMComment_get_baseName(node_comment, &str);
2599 ok(r == S_FALSE, "ret %08x\n", r );
2600 ok(str == NULL, "Expected NULL\n");
2602 IXMLDOMComment_Release( node_comment );
2605 /* test Create Attribute */
2606 str = SysAllocString(szAttribute);
2607 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
2608 ok( r == E_INVALIDARG, "returns %08x\n", r );
2609 r = IXMLDOMDocument_createAttribute(doc, str, &node_attr);
2610 ok( r == S_OK, "returns %08x\n", r );
2611 IXMLDOMText_Release( node_attr);
2614 /* test Processing Instruction */
2615 str = SysAllocStringLen(NULL, 0);
2616 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
2617 ok( r == E_INVALIDARG, "returns %08x\n", r );
2618 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
2619 ok( r == E_FAIL, "returns %08x\n", r );
2620 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
2621 ok( r == E_FAIL, "returns %08x\n", r );
2624 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
2625 ok( r == S_OK, "returns %08x\n", r );
2628 /* Last Child Checks */
2629 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
2630 ok(r == E_INVALIDARG, "ret %08x\n", r );
2632 nodeChild = (IXMLDOMNode*)0x1;
2633 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
2634 ok(r == S_FALSE, "ret %08x\n", r );
2635 ok(nodeChild == NULL, "nodeChild not NULL\n");
2638 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
2639 ok(r == S_OK, "ret %08x\n", r );
2640 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2645 r = IXMLDOMProcessingInstruction_get_baseName(nodePI, &str);
2646 ok(r == S_OK, "ret %08x\n", r );
2647 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2651 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
2652 ok(r == S_OK, "ret %08x\n", r );
2653 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
2656 /* test get_nodeValue */
2657 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
2658 ok(r == S_OK, "ret %08x\n", r );
2659 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
2663 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
2664 ok(r == S_OK, "ret %08x\n", r );
2665 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
2669 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
2670 ok(r == E_FAIL, "ret %08x\n", r );
2673 V_VT(&var) = VT_BSTR;
2674 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
2675 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
2676 ok(r == E_FAIL, "ret %08x\n", r );
2679 /* test get nodeName */
2680 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
2681 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2682 ok(r == S_OK, "ret %08x\n", r );
2685 IXMLDOMProcessingInstruction_Release(nodePI);
2688 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (void**)&support_error );
2689 ok( r == S_OK, "ret %08x\n", r );
2692 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
2693 todo_wine ok( r == S_OK, "ret %08x\n", r );
2694 ISupportErrorInfo_Release( support_error );
2697 r = IXMLDOMDocument_Release( doc );
2698 ok( r == 0, "document ref count incorrect\n");
2703 static void test_persiststreaminit(void)
2705 IXMLDOMDocument *doc;
2706 IPersistStreamInit *streaminit;
2709 doc = create_document(&IID_IXMLDOMDocument);
2712 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&streaminit);
2713 ok( hr == S_OK, "failed with 0x%08x\n", hr );
2715 hr = IPersistStreamInit_InitNew(streaminit);
2716 ok( hr == S_OK, "failed with 0x%08x\n", hr );
2718 IXMLDOMDocument_Release(doc);
2721 static void test_domnode( void )
2724 IXMLDOMDocument *doc, *owner = NULL;
2725 IXMLDOMElement *element = NULL;
2726 IXMLDOMNamedNodeMap *map = NULL;
2727 IXMLDOMNode *node = NULL, *next = NULL;
2728 IXMLDOMNodeList *list = NULL;
2729 IXMLDOMAttribute *attr = NULL;
2730 DOMNodeType type = NODE_INVALID;
2736 doc = create_document(&IID_IXMLDOMDocument);
2740 str = SysAllocString( szComplete4 );
2741 r = IXMLDOMDocument_loadXML( doc, str, &b );
2742 ok( r == S_OK, "loadXML failed\n");
2743 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2744 SysFreeString( str );
2746 EXPECT_CHILDREN(doc);
2748 r = IXMLDOMDocument_get_documentElement( doc, &element );
2749 ok( r == S_OK, "should be a document element\n");
2750 ok( element != NULL, "should be an element\n");
2753 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
2755 r = IXMLDOMNode_get_nodeValue( doc, NULL );
2756 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
2758 r = IXMLDOMNode_get_nodeValue( doc, &var );
2759 ok( r == S_FALSE, "nextNode returned wrong code\n");
2760 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
2761 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
2766 r = IXMLDOMNode_get_ownerDocument( element, &owner );
2767 ok( r == S_OK, "get_ownerDocument return code\n");
2768 ok( owner != doc, "get_ownerDocument return\n");
2769 IXMLDOMDocument_Release(owner);
2771 type = NODE_INVALID;
2772 r = IXMLDOMNode_get_nodeType( element, &type);
2773 ok( r == S_OK, "got %08x\n", r);
2774 ok( type == NODE_ELEMENT, "node not an element\n");
2777 r = IXMLDOMNode_get_baseName( element, &str );
2778 ok( r == S_OK, "get_baseName returned wrong code\n");
2779 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
2782 /* check if nodename is correct */
2783 r = IXMLDOMElement_get_nodeName( element, NULL );
2784 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2786 /* content doesn't matter here */
2788 r = IXMLDOMElement_get_nodeName( element, &str );
2789 ok ( r == S_OK, "get_nodeName wrong code\n");
2790 ok ( str != NULL, "str is null\n");
2791 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
2792 SysFreeString( str );
2794 str = SysAllocString( szNonExistentFile );
2796 V_I4(&var) = 0x1234;
2797 r = IXMLDOMElement_getAttribute( element, str, &var );
2798 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
2799 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
2802 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
2803 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
2805 attr = (IXMLDOMAttribute*)0xdeadbeef;
2806 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
2807 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
2808 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
2809 SysFreeString( str );
2811 attr = (IXMLDOMAttribute*)0xdeadbeef;
2812 str = SysAllocString( szNonExistentAttribute );
2813 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
2814 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
2815 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
2816 SysFreeString( str );
2818 str = SysAllocString( szdl );
2820 V_I4(&var) = 0x1234;
2821 r = IXMLDOMElement_getAttribute( element, str, &var );
2822 ok( r == S_OK, "getAttribute ret %08x\n", r );
2823 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
2824 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
2825 VariantClear( &var );
2827 r = IXMLDOMElement_getAttribute( element, NULL, &var );
2828 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
2830 r = IXMLDOMElement_getAttribute( element, str, NULL );
2831 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
2834 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
2835 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
2836 ok( attr != NULL, "getAttributeNode returned NULL\n" );
2839 r = IXMLDOMAttribute_get_parentNode( attr, NULL );
2840 ok( r == E_INVALIDARG, "Expected E_INVALIDARG, ret %08x\n", r );
2842 /* attribute doesn't have a parent in msxml interpretation */
2843 node = (IXMLDOMNode*)0xdeadbeef;
2844 r = IXMLDOMAttribute_get_parentNode( attr, &node );
2845 ok( r == S_FALSE, "Expected S_FALSE, ret %08x\n", r );
2846 ok( node == NULL, "Expected NULL, got %p\n", node );
2848 IXMLDOMAttribute_Release(attr);
2851 SysFreeString( str );
2853 r = IXMLDOMElement_get_attributes( element, &map );
2854 ok( r == S_OK, "get_attributes returned wrong code\n");
2855 ok( map != NULL, "should be attributes\n");
2857 EXPECT_CHILDREN(element);
2860 ok( FALSE, "no element\n");
2864 ISupportErrorInfo *support_error;
2865 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (void**)&support_error );
2866 ok( r == S_OK, "ret %08x\n", r );
2868 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
2871 ok( r == S_OK, "ret %08x\n", r );
2873 ISupportErrorInfo_Release( support_error );
2875 str = SysAllocString( szdl );
2876 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
2877 ok( r == S_OK, "getNamedItem returned wrong code\n");
2878 ok( node != NULL, "should be attributes\n");
2879 IXMLDOMNode_Release(node);
2880 SysFreeString( str );
2882 str = SysAllocString( szdl );
2883 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
2884 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
2885 SysFreeString( str );
2887 /* something that isn't in szComplete4 */
2888 str = SysAllocString( szOpen );
2889 node = (IXMLDOMNode *) 1;
2890 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
2891 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
2892 ok( node == NULL, "getNamedItem should have returned NULL\n");
2893 SysFreeString( str );
2895 /* test indexed access of attributes */
2896 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
2897 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
2899 r = IXMLDOMNamedNodeMap_get_length( map, &count );
2900 ok ( r == S_OK, "get_length wrong code\n");
2901 ok ( count == 1, "get_length != 1\n");
2904 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
2905 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
2906 ok ( node == NULL, "there is no node\n");
2909 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
2910 ok ( r == S_FALSE, "get_item (1) wrong code\n");
2911 ok ( node == NULL, "there is no attribute\n");
2914 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
2915 ok ( r == S_OK, "get_item (0) wrong code\n");
2916 ok ( node != NULL, "should be attribute\n");
2918 r = IXMLDOMNode_get_nodeName( node, NULL );
2919 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2921 /* content doesn't matter here */
2923 r = IXMLDOMNode_get_nodeName( node, &str );
2924 ok ( r == S_OK, "get_nodeName wrong code\n");
2925 ok ( str != NULL, "str is null\n");
2926 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
2927 SysFreeString( str );
2928 IXMLDOMNode_Release( node );
2930 /* test sequential access of attributes */
2932 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2933 ok ( r == S_OK, "nextNode (first time) wrong code\n");
2934 ok ( node != NULL, "nextNode, should be attribute\n");
2935 IXMLDOMNode_Release( node );
2937 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2938 ok ( r != S_OK, "nextNode (second time) wrong code\n");
2939 ok ( node == NULL, "nextNode, there is no attribute\n");
2941 r = IXMLDOMNamedNodeMap_reset( map );
2942 ok ( r == S_OK, "reset should return S_OK\n");
2944 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2945 ok ( r == S_OK, "nextNode (third time) wrong code\n");
2946 ok ( node != NULL, "nextNode, should be attribute\n");
2949 ok( FALSE, "no map\n");
2953 type = NODE_INVALID;
2954 r = IXMLDOMNode_get_nodeType( node, &type);
2955 ok( r == S_OK, "getNamedItem returned wrong code\n");
2956 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
2959 r = IXMLDOMNode_get_baseName( node, NULL );
2960 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
2963 r = IXMLDOMNode_get_baseName( node, &str );
2964 ok( r == S_OK, "get_baseName returned wrong code\n");
2965 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
2966 SysFreeString( str );
2968 r = IXMLDOMNode_get_nodeValue( node, &var );
2969 ok( r == S_OK, "returns %08x\n", r );
2970 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
2971 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
2974 r = IXMLDOMNode_get_childNodes( node, NULL );
2975 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
2977 r = IXMLDOMNode_get_childNodes( node, &list );
2978 ok( r == S_OK, "get_childNodes returned wrong code\n");
2982 r = IXMLDOMNodeList_nextNode( list, &next );
2983 ok( r == S_OK, "nextNode returned wrong code\n");
2986 ok( FALSE, "no childlist\n");
2990 EXPECT_NO_CHILDREN(next);
2992 type = NODE_INVALID;
2993 r = IXMLDOMNode_get_nodeType( next, &type);
2994 ok( r == S_OK, "getNamedItem returned wrong code\n");
2995 ok( type == NODE_TEXT, "node not text\n");
2998 r = IXMLDOMNode_get_baseName( next, &str );
2999 ok( r == S_FALSE, "get_baseName returned wrong code\n");
3000 ok( str == NULL, "basename was wrong\n");
3004 ok( FALSE, "no next\n");
3007 IXMLDOMNode_Release( next );
3010 IXMLDOMNodeList_Release( list );
3013 IXMLDOMNode_Release( node );
3016 ok( FALSE, "no node\n");
3020 IXMLDOMNamedNodeMap_Release( map );
3022 /* now traverse the tree from the root element */
3025 r = IXMLDOMNode_get_childNodes( element, &list );
3026 ok( r == S_OK, "get_childNodes returned wrong code\n");
3028 /* using get_item for child list doesn't advance the position */
3029 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
3030 expect_node(node, "E2.E2.D1");
3031 IXMLDOMNode_Release(node);
3032 ole_check(IXMLDOMNodeList_nextNode(list, &node));
3033 expect_node(node, "E1.E2.D1");
3034 IXMLDOMNode_Release(node);
3035 ole_check(IXMLDOMNodeList_reset(list));
3037 IXMLDOMNodeList_AddRef(list);
3038 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
3039 ole_check(IXMLDOMNodeList_reset(list));
3041 node = (void*)0xdeadbeef;
3042 str = SysAllocString(szdl);
3043 r = IXMLDOMNode_selectSingleNode( element, str, &node );
3045 ok( r == S_FALSE, "ret %08x\n", r );
3046 ok( node == NULL, "node %p\n", node );
3048 str = SysAllocString(szbs);
3049 r = IXMLDOMNode_selectSingleNode( element, str, &node );
3051 ok( r == S_OK, "ret %08x\n", r );
3052 r = IXMLDOMNode_Release( node );
3053 ok( r == 0, "ret %08x\n", r );
3056 ok( FALSE, "no element\n");
3060 r = IXMLDOMNodeList_get_item(list, 0, NULL);
3061 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3063 r = IXMLDOMNodeList_get_length(list, NULL);
3064 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3066 r = IXMLDOMNodeList_get_length( list, &count );
3067 ok( r == S_OK, "get_length returns %08x\n", r );
3068 ok( count == 4, "get_length got %d\n", count );
3070 r = IXMLDOMNodeList_nextNode(list, NULL);
3071 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3073 r = IXMLDOMNodeList_nextNode( list, &node );
3074 ok( r == S_OK, "nextNode returned wrong code\n");
3077 ok( FALSE, "no list\n");
3081 type = NODE_INVALID;
3082 r = IXMLDOMNode_get_nodeType( node, &type);
3083 ok( r == S_OK, "getNamedItem returned wrong code\n");
3084 ok( type == NODE_ELEMENT, "node not text\n");
3087 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
3088 r = IXMLDOMNode_get_nodeValue( node, &var );
3089 ok( r == S_FALSE, "nextNode returned wrong code\n");
3090 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
3091 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
3093 r = IXMLDOMNode_hasChildNodes( node, NULL );
3094 ok( r == E_INVALIDARG, "hasChildNodes bad return\n");
3096 EXPECT_CHILDREN(node);
3099 r = IXMLDOMNode_get_baseName( node, &str );
3100 ok( r == S_OK, "get_baseName returned wrong code\n");
3101 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
3105 ok( FALSE, "no node\n");
3108 IXMLDOMNode_Release( node );
3110 IXMLDOMNodeList_Release( list );
3112 IXMLDOMElement_Release( element );
3115 str = SysAllocString( szComplete5 );
3116 r = IXMLDOMDocument_loadXML( doc, str, &b );
3117 ok( r == S_OK, "loadXML failed\n");
3118 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3119 SysFreeString( str );
3121 EXPECT_CHILDREN(doc);
3123 r = IXMLDOMDocument_get_documentElement( doc, &element );
3124 ok( r == S_OK, "should be a document element\n");
3125 ok( element != NULL, "should be an element\n");
3129 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
3132 /* check if the tag is correct */
3133 r = IXMLDOMElement_get_tagName( element, &tag );
3134 ok( r == S_OK, "couldn't get tag name\n");
3135 ok( tag != NULL, "tag was null\n");
3136 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
3137 SysFreeString( tag );
3141 IXMLDOMElement_Release( element );
3142 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
3145 static void test_refs(void)
3150 IXMLDOMDocument *doc;
3151 IXMLDOMElement *element = NULL;
3152 IXMLDOMNode *node = NULL, *node2;
3153 IXMLDOMNodeList *node_list = NULL;
3155 IUnknown *unk, *unk2;
3157 doc = create_document(&IID_IXMLDOMDocument);
3161 ref = IXMLDOMDocument_Release(doc);
3162 ok( ref == 0, "ref %d\n", ref);
3164 doc = create_document(&IID_IXMLDOMDocument);
3167 str = SysAllocString( szComplete4 );
3168 r = IXMLDOMDocument_loadXML( doc, str, &b );
3169 ok( r == S_OK, "loadXML failed\n");
3170 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3171 SysFreeString( str );
3174 IXMLDOMDocument_AddRef( doc );
3176 IXMLDOMDocument_AddRef( doc );
3179 IXMLDOMDocument_Release( doc );
3180 IXMLDOMDocument_Release( doc );
3182 r = IXMLDOMDocument_get_documentElement( doc, &element );
3183 ok( r == S_OK, "should be a document element\n");
3184 ok( element != NULL, "should be an element\n");
3187 todo_wine EXPECT_REF(element, 2);
3189 IXMLDOMElement_AddRef(element);
3190 todo_wine EXPECT_REF(element, 3);
3191 IXMLDOMElement_Release(element);
3193 r = IXMLDOMElement_get_childNodes( element, &node_list );
3194 ok( r == S_OK, "rets %08x\n", r);
3196 todo_wine EXPECT_REF(element, 2);
3197 EXPECT_REF(node_list, 1);
3199 IXMLDOMNodeList_get_item( node_list, 0, &node );
3200 ok( r == S_OK, "rets %08x\n", r);
3201 EXPECT_REF(node_list, 1);
3202 EXPECT_REF(node, 1);
3204 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
3205 ok( r == S_OK, "rets %08x\n", r);
3206 EXPECT_REF(node_list, 1);
3207 EXPECT_REF(node2, 1);
3209 ref = IXMLDOMNode_Release( node );
3210 ok( ref == 0, "ref %d\n", ref );
3211 ref = IXMLDOMNode_Release( node2 );
3212 ok( ref == 0, "ref %d\n", ref );
3214 ref = IXMLDOMNodeList_Release( node_list );
3215 ok( ref == 0, "ref %d\n", ref );
3217 ok( node != node2, "node %p node2 %p\n", node, node2 );
3219 ref = IXMLDOMDocument_Release( doc );
3220 ok( ref == 0, "ref %d\n", ref );
3222 todo_wine EXPECT_REF(element, 2);
3224 /* IUnknown must be unique however we obtain it */
3225 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (void**)&unk );
3226 ok( r == S_OK, "rets %08x\n", r );
3227 EXPECT_REF(element, 2);
3228 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (void**)&node );
3229 ok( r == S_OK, "rets %08x\n", r );
3230 todo_wine EXPECT_REF(element, 2);
3231 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk2 );
3232 ok( r == S_OK, "rets %08x\n", r );
3233 todo_wine EXPECT_REF(element, 2);
3234 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
3235 todo_wine ok( element != (void*)node, "node %p element %p\n", node, element );
3237 IUnknown_Release( unk2 );
3238 IUnknown_Release( unk );
3239 IXMLDOMNode_Release( node );
3240 todo_wine EXPECT_REF(element, 2);
3242 IXMLDOMElement_Release( element );
3245 static void test_create(void)
3247 static const WCHAR szOne[] = {'1',0};
3248 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
3252 IXMLDOMDocument *doc;
3253 IXMLDOMElement *element;
3254 IXMLDOMComment *comment;
3256 IXMLDOMCDATASection *cdata;
3257 IXMLDOMNode *root, *node, *child;
3258 IXMLDOMNamedNodeMap *attr_map;
3263 doc = create_document(&IID_IXMLDOMDocument);
3268 /* types not supported for creation */
3270 V_I1(&var) = NODE_DOCUMENT;
3271 node = (IXMLDOMNode*)0x1;
3272 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3273 ok( r == E_INVALIDARG, "returns %08x\n", r );
3274 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3277 V_I1(&var) = NODE_DOCUMENT_TYPE;
3278 node = (IXMLDOMNode*)0x1;
3279 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3280 ok( r == E_INVALIDARG, "returns %08x\n", r );
3281 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3284 V_I1(&var) = NODE_ENTITY;
3285 node = (IXMLDOMNode*)0x1;
3286 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3287 ok( r == E_INVALIDARG, "returns %08x\n", r );
3288 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3291 V_I1(&var) = NODE_NOTATION;
3292 node = (IXMLDOMNode*)0x1;
3293 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3294 ok( r == E_INVALIDARG, "returns %08x\n", r );
3295 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3299 V_I1(&var) = NODE_COMMENT;
3301 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3302 ok( r == S_OK, "returns %08x\n", r );
3303 ok( node != NULL, "\n");
3305 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3306 ok( r == S_OK, "returns %08x\n", r );
3307 IXMLDOMNode_Release(node);
3310 r = IXMLDOMComment_get_data(comment, &str);
3311 ok( r == S_OK, "returns %08x\n", r );
3312 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3313 IXMLDOMComment_Release(comment);
3316 node = (IXMLDOMNode*)0x1;
3317 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3318 ok( r == S_OK, "returns %08x\n", r );
3320 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3321 ok( r == S_OK, "returns %08x\n", r );
3322 IXMLDOMNode_Release(node);
3325 r = IXMLDOMComment_get_data(comment, &str);
3326 ok( r == S_OK, "returns %08x\n", r );
3327 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3328 IXMLDOMComment_Release(comment);
3331 node = (IXMLDOMNode*)0x1;
3332 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3333 ok( r == S_OK, "returns %08x\n", r );
3335 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3336 ok( r == S_OK, "returns %08x\n", r );
3337 IXMLDOMNode_Release(node);
3340 r = IXMLDOMComment_get_data(comment, &str);
3341 ok( r == S_OK, "returns %08x\n", r );
3342 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3343 IXMLDOMComment_Release(comment);
3348 V_I1(&var) = NODE_TEXT;
3350 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3351 ok( r == S_OK, "returns %08x\n", r );
3352 ok( node != NULL, "\n");
3354 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3355 ok( r == S_OK, "returns %08x\n", r );
3356 IXMLDOMNode_Release(node);
3359 r = IXMLDOMText_get_data(text, &str);
3360 ok( r == S_OK, "returns %08x\n", r );
3361 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3362 IXMLDOMText_Release(text);
3365 node = (IXMLDOMNode*)0x1;
3366 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3367 ok( r == S_OK, "returns %08x\n", r );
3369 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3370 ok( r == S_OK, "returns %08x\n", r );
3371 IXMLDOMNode_Release(node);
3374 r = IXMLDOMText_get_data(text, &str);
3375 ok( r == S_OK, "returns %08x\n", r );
3376 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3377 IXMLDOMText_Release(text);
3380 node = (IXMLDOMNode*)0x1;
3381 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3382 ok( r == S_OK, "returns %08x\n", r );
3384 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3385 ok( r == S_OK, "returns %08x\n", r );
3386 IXMLDOMNode_Release(node);
3389 r = IXMLDOMText_get_data(text, &str);
3390 ok( r == S_OK, "returns %08x\n", r );
3391 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3392 IXMLDOMText_Release(text);
3395 /* NODE_CDATA_SECTION */
3397 V_I1(&var) = NODE_CDATA_SECTION;
3399 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3400 ok( r == S_OK, "returns %08x\n", r );
3401 ok( node != NULL, "\n");
3403 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3404 ok( r == S_OK, "returns %08x\n", r );
3405 IXMLDOMNode_Release(node);
3408 r = IXMLDOMCDATASection_get_data(cdata, &str);
3409 ok( r == S_OK, "returns %08x\n", r );
3410 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3411 IXMLDOMCDATASection_Release(cdata);
3414 node = (IXMLDOMNode*)0x1;
3415 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3416 ok( r == S_OK, "returns %08x\n", r );
3418 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3419 ok( r == S_OK, "returns %08x\n", r );
3420 IXMLDOMNode_Release(node);
3423 r = IXMLDOMCDATASection_get_data(cdata, &str);
3424 ok( r == S_OK, "returns %08x\n", r );
3425 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3426 IXMLDOMCDATASection_Release(cdata);
3429 node = (IXMLDOMNode*)0x1;
3430 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3431 ok( r == S_OK, "returns %08x\n", r );
3433 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3434 ok( r == S_OK, "returns %08x\n", r );
3435 IXMLDOMNode_Release(node);
3438 r = IXMLDOMCDATASection_get_data(cdata, &str);
3439 ok( r == S_OK, "returns %08x\n", r );
3440 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3441 IXMLDOMCDATASection_Release(cdata);
3444 /* NODE_ATTRIBUTE */
3446 V_I1(&var) = NODE_ATTRIBUTE;
3447 node = (IXMLDOMNode*)0x1;
3448 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3449 ok( r == E_FAIL, "returns %08x\n", r );
3450 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3453 V_I1(&var) = NODE_ATTRIBUTE;
3454 node = (IXMLDOMNode*)0x1;
3455 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3456 ok( r == E_FAIL, "returns %08x\n", r );
3457 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3460 V_I1(&var) = NODE_ATTRIBUTE;
3461 str = SysAllocString( szlc );
3462 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3463 ok( r == S_OK, "returns %08x\n", r );
3464 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3467 /* a name is required for attribute, try a BSTR with first null wchar */
3469 V_I1(&var) = NODE_ATTRIBUTE;
3470 str = SysAllocString( szstr1 );
3472 node = (IXMLDOMNode*)0x1;
3473 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3474 ok( r == E_FAIL, "returns %08x\n", r );
3475 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3478 /* NODE_PROCESSING_INSTRUCTION */
3480 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3481 node = (IXMLDOMNode*)0x1;
3482 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3483 ok( r == E_FAIL, "returns %08x\n", r );
3484 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3487 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3488 node = (IXMLDOMNode*)0x1;
3489 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3490 ok( r == E_FAIL, "returns %08x\n", r );
3491 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3494 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3495 r = IXMLDOMDocument_createNode( doc, var, _bstr_("pi"), NULL, NULL );
3496 ok( r == E_INVALIDARG, "returns %08x\n", r );
3498 /* NODE_ENTITY_REFERENCE */
3500 V_I1(&var) = NODE_ENTITY_REFERENCE;
3501 node = (IXMLDOMNode*)0x1;
3502 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3503 ok( r == E_FAIL, "returns %08x\n", r );
3504 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3507 V_I1(&var) = NODE_ENTITY_REFERENCE;
3508 node = (IXMLDOMNode*)0x1;
3509 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3510 ok( r == E_FAIL, "returns %08x\n", r );
3511 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3515 V_I1(&var) = NODE_ELEMENT;
3516 node = (IXMLDOMNode*)0x1;
3517 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3518 ok( r == E_FAIL, "returns %08x\n", r );
3519 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3522 V_I1(&var) = NODE_ELEMENT;
3523 node = (IXMLDOMNode*)0x1;
3524 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3525 ok( r == E_FAIL, "returns %08x\n", r );
3526 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3529 V_I1(&var) = NODE_ELEMENT;
3530 str = SysAllocString( szlc );
3531 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3532 ok( r == S_OK, "returns %08x\n", r );
3533 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3536 V_I1(&var) = NODE_ELEMENT;
3537 r = IXMLDOMDocument_createNode( doc, var, str, NULL, NULL );
3538 ok( r == E_INVALIDARG, "returns %08x\n", r );
3541 V_R4(&var) = NODE_ELEMENT;
3542 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3543 ok( r == S_OK, "returns %08x\n", r );
3544 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3546 V_VT(&var) = VT_BSTR;
3547 V_BSTR(&var) = SysAllocString( szOne );
3548 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3549 ok( r == S_OK, "returns %08x\n", r );
3550 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3553 V_VT(&var) = VT_BSTR;
3554 V_BSTR(&var) = SysAllocString( szOneGarbage );
3555 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3556 ok( r == E_INVALIDARG, "returns %08x\n", r );
3557 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3561 V_I4(&var) = NODE_ELEMENT;
3562 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3563 ok( r == S_OK, "returns %08x\n", r );
3566 r = IXMLDOMDocument_appendChild( doc, node, &root );
3567 ok( r == S_OK, "returns %08x\n", r );
3568 ok( node == root, "%p %p\n", node, root );
3571 EXPECT_REF(node, 2);
3573 ref = IXMLDOMNode_Release( node );
3574 ok(ref == 1, "ref %d\n", ref);
3575 SysFreeString( str );
3578 V_I4(&var) = NODE_ELEMENT;
3579 str = SysAllocString( szbs );
3580 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3581 ok( r == S_OK, "returns %08x\n", r );
3582 SysFreeString( str );
3584 EXPECT_REF(node, 1);
3586 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk );
3587 ok( r == S_OK, "returns %08x\n", r );
3591 V_VT(&var) = VT_EMPTY;
3593 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
3594 ok( r == S_OK, "returns %08x\n", r );
3595 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
3597 todo_wine EXPECT_REF(unk, 4);
3599 IXMLDOMNode_Release( child );
3600 IUnknown_Release( unk );
3602 V_VT(&var) = VT_NULL;
3603 V_DISPATCH(&var) = (IDispatch*)node;
3604 r = IXMLDOMNode_insertBefore( root, node, var, &child );
3605 ok( r == S_OK, "returns %08x\n", r );
3606 ok( node == child, "%p %p\n", node, child );
3607 IXMLDOMNode_Release( child );
3609 V_VT(&var) = VT_NULL;
3610 V_DISPATCH(&var) = (IDispatch*)node;
3611 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
3612 ok( r == S_OK, "returns %08x\n", r );
3613 IXMLDOMNode_Release( node );
3615 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (void**)&element );
3616 ok( r == S_OK, "returns %08x\n", r );
3618 r = IXMLDOMElement_get_attributes( element, &attr_map );
3619 ok( r == S_OK, "returns %08x\n", r );
3620 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3621 ok( r == S_OK, "returns %08x\n", r );
3622 ok( num == 0, "num %d\n", num );
3623 IXMLDOMNamedNodeMap_Release( attr_map );
3625 V_VT(&var) = VT_BSTR;
3626 V_BSTR(&var) = SysAllocString( szstr1 );
3627 name = SysAllocString( szdl );
3628 r = IXMLDOMElement_setAttribute( element, name, var );
3629 ok( r == S_OK, "returns %08x\n", r );
3630 r = IXMLDOMElement_get_attributes( element, &attr_map );
3631 ok( r == S_OK, "returns %08x\n", r );
3632 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3633 ok( r == S_OK, "returns %08x\n", r );
3634 ok( num == 1, "num %d\n", num );
3635 IXMLDOMNamedNodeMap_Release( attr_map );
3638 V_VT(&var) = VT_BSTR;
3639 V_BSTR(&var) = SysAllocString( szstr2 );
3640 r = IXMLDOMElement_setAttribute( element, name, var );
3641 ok( r == S_OK, "returns %08x\n", r );
3642 r = IXMLDOMElement_get_attributes( element, &attr_map );
3643 ok( r == S_OK, "returns %08x\n", r );
3644 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3645 ok( r == S_OK, "returns %08x\n", r );
3646 ok( num == 1, "num %d\n", num );
3647 IXMLDOMNamedNodeMap_Release( attr_map );
3649 r = IXMLDOMElement_getAttribute( element, name, &var );
3650 ok( r == S_OK, "returns %08x\n", r );
3651 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
3653 SysFreeString(name);
3655 V_VT(&var) = VT_BSTR;
3656 V_BSTR(&var) = SysAllocString( szstr1 );
3657 name = SysAllocString( szlc );
3658 r = IXMLDOMElement_setAttribute( element, name, var );
3659 ok( r == S_OK, "returns %08x\n", r );
3660 r = IXMLDOMElement_get_attributes( element, &attr_map );
3661 ok( r == S_OK, "returns %08x\n", r );
3662 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3663 ok( r == S_OK, "returns %08x\n", r );
3664 ok( num == 2, "num %d\n", num );
3665 IXMLDOMNamedNodeMap_Release( attr_map );
3667 SysFreeString(name);
3671 name = SysAllocString( szbs );
3672 r = IXMLDOMElement_setAttribute( element, name, var );
3673 ok( r == S_OK, "returns %08x\n", r );
3675 r = IXMLDOMElement_getAttribute( element, name, &var );
3676 ok( r == S_OK, "returns %08x\n", r );
3677 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
3679 SysFreeString(name);
3681 /* Create an Attribute */
3683 V_I4(&var) = NODE_ATTRIBUTE;
3684 str = SysAllocString( szAttribute );
3685 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3686 ok( r == S_OK, "returns %08x\n", r );
3687 ok( node != NULL, "node was null\n");
3690 IXMLDOMElement_Release( element );
3691 IXMLDOMNode_Release( root );
3692 IXMLDOMDocument_Release( doc );
3695 static void test_getElementsByTagName(void)
3697 IXMLDOMNodeList *node_list;
3698 IXMLDOMDocument *doc;
3699 IXMLDOMElement *elem;
3706 doc = create_document(&IID_IXMLDOMDocument);
3709 str = SysAllocString( szComplete4 );
3710 r = IXMLDOMDocument_loadXML( doc, str, &b );
3711 ok( r == S_OK, "loadXML failed\n");
3712 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3713 SysFreeString( str );
3715 str = SysAllocString( szstar );
3717 /* null arguments cases */
3718 r = IXMLDOMDocument_getElementsByTagName(doc, NULL, &node_list);
3719 ok( r == E_INVALIDARG, "ret %08x\n", r );
3720 r = IXMLDOMDocument_getElementsByTagName(doc, str, NULL);
3721 ok( r == E_INVALIDARG, "ret %08x\n", r );
3723 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3724 ok( r == S_OK, "ret %08x\n", r );
3725 r = IXMLDOMNodeList_get_length( node_list, &len );
3726 ok( r == S_OK, "ret %08x\n", r );
3727 ok( len == 6, "len %d\n", len );
3729 test_disp((IUnknown*)node_list);
3731 IXMLDOMNodeList_Release( node_list );
3732 SysFreeString( str );
3734 /* broken query BSTR */
3735 memcpy(&buff[2], szstar, sizeof(szstar));
3736 /* just a big length */
3737 *(DWORD*)buff = 0xf0f0;
3738 r = IXMLDOMDocument_getElementsByTagName(doc, &buff[2], &node_list);
3739 ok( r == S_OK, "ret %08x\n", r );
3740 r = IXMLDOMNodeList_get_length( node_list, &len );
3741 ok( r == S_OK, "ret %08x\n", r );
3742 ok( len == 6, "len %d\n", len );
3743 IXMLDOMNodeList_Release( node_list );
3745 str = SysAllocString( szbs );
3746 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3747 ok( r == S_OK, "ret %08x\n", r );
3748 r = IXMLDOMNodeList_get_length( node_list, &len );
3749 ok( r == S_OK, "ret %08x\n", r );
3750 ok( len == 1, "len %d\n", len );
3751 IXMLDOMNodeList_Release( node_list );
3752 SysFreeString( str );
3754 str = SysAllocString( szdl );
3755 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3756 ok( r == S_OK, "ret %08x\n", r );
3757 r = IXMLDOMNodeList_get_length( node_list, &len );
3758 ok( r == S_OK, "ret %08x\n", r );
3759 ok( len == 0, "len %d\n", len );
3760 IXMLDOMNodeList_Release( node_list );
3761 SysFreeString( str );
3763 str = SysAllocString( szstr1 );
3764 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3765 ok( r == S_OK, "ret %08x\n", r );
3766 r = IXMLDOMNodeList_get_length( node_list, &len );
3767 ok( r == S_OK, "ret %08x\n", r );
3768 ok( len == 0, "len %d\n", len );
3769 IXMLDOMNodeList_Release( node_list );
3770 SysFreeString( str );
3772 /* test for element */
3773 r = IXMLDOMDocument_get_documentElement(doc, &elem);
3774 ok( r == S_OK, "ret %08x\n", r );
3776 str = SysAllocString( szstar );
3778 /* null arguments cases */
3779 r = IXMLDOMElement_getElementsByTagName(elem, NULL, &node_list);
3780 ok( r == E_INVALIDARG, "ret %08x\n", r );
3781 r = IXMLDOMElement_getElementsByTagName(elem, str, NULL);
3782 ok( r == E_INVALIDARG, "ret %08x\n", r );
3784 r = IXMLDOMElement_getElementsByTagName(elem, str, &node_list);
3785 ok( r == S_OK, "ret %08x\n", r );
3786 r = IXMLDOMNodeList_get_length( node_list, &len );
3787 ok( r == S_OK, "ret %08x\n", r );
3788 ok( len == 5, "len %d\n", len );
3789 expect_list_and_release(node_list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1 E1.E4.E2.D1");
3790 SysFreeString( str );
3792 /* broken query BSTR */
3793 memcpy(&buff[2], szstar, sizeof(szstar));
3794 /* just a big length */
3795 *(DWORD*)buff = 0xf0f0;
3796 r = IXMLDOMElement_getElementsByTagName(elem, &buff[2], &node_list);
3797 ok( r == S_OK, "ret %08x\n", r );
3798 r = IXMLDOMNodeList_get_length( node_list, &len );
3799 ok( r == S_OK, "ret %08x\n", r );
3800 ok( len == 5, "len %d\n", len );
3801 IXMLDOMNodeList_Release( node_list );
3803 IXMLDOMElement_Release(elem);
3805 IXMLDOMDocument_Release( doc );
3808 static void test_get_text(void)
3813 IXMLDOMDocument *doc;
3814 IXMLDOMNode *node, *node2, *node3;
3815 IXMLDOMNode *nodeRoot;
3816 IXMLDOMNodeList *node_list;
3817 IXMLDOMNamedNodeMap *node_map;
3820 doc = create_document(&IID_IXMLDOMDocument);
3823 str = SysAllocString( szComplete4 );
3824 r = IXMLDOMDocument_loadXML( doc, str, &b );
3825 ok( r == S_OK, "loadXML failed\n");
3826 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3827 SysFreeString( str );
3829 str = SysAllocString( szbs );
3830 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
3831 ok( r == S_OK, "ret %08x\n", r );
3834 /* Test to get all child node text. */
3835 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&nodeRoot);
3836 ok( r == S_OK, "ret %08x\n", r );
3839 r = IXMLDOMNode_get_text( nodeRoot, &str );
3840 ok( r == S_OK, "ret %08x\n", r );
3841 ok( compareIgnoreReturns(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text: %s\n", wine_dbgstr_w(str));
3844 IXMLDOMNode_Release(nodeRoot);
3847 r = IXMLDOMNodeList_get_length( node_list, NULL );
3848 ok( r == E_INVALIDARG, "ret %08x\n", r );
3850 r = IXMLDOMNodeList_get_length( node_list, &len );
3851 ok( r == S_OK, "ret %08x\n", r );
3852 ok( len == 1, "expect 1 got %d\n", len );
3854 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
3855 ok( r == E_INVALIDARG, "ret %08x\n", r );
3857 r = IXMLDOMNodeList_nextNode( node_list, NULL );
3858 ok( r == E_INVALIDARG, "ret %08x\n", r );
3860 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
3861 ok( r == S_OK, "ret %08x\n", r );
3862 IXMLDOMNodeList_Release( node_list );
3864 /* Invalid output parameter*/
3865 r = IXMLDOMNode_get_text( node, NULL );
3866 ok( r == E_INVALIDARG, "ret %08x\n", r );
3868 r = IXMLDOMNode_get_text( node, &str );
3869 ok( r == S_OK, "ret %08x\n", r );
3870 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
3873 r = IXMLDOMNode_get_attributes( node, &node_map );
3874 ok( r == S_OK, "ret %08x\n", r );
3876 str = SysAllocString( szvr );
3877 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
3878 ok( r == S_OK, "ret %08x\n", r );
3881 r = IXMLDOMNode_get_text( node2, &str );
3882 ok( r == S_OK, "ret %08x\n", r );
3883 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3886 r = IXMLDOMNode_get_firstChild( node2, &node3 );
3887 ok( r == S_OK, "ret %08x\n", r );
3889 r = IXMLDOMNode_get_text( node3, &str );
3890 ok( r == S_OK, "ret %08x\n", r );
3891 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3895 IXMLDOMNode_Release( node3 );
3896 IXMLDOMNode_Release( node2 );
3897 IXMLDOMNamedNodeMap_Release( node_map );
3898 IXMLDOMNode_Release( node );
3899 IXMLDOMDocument_Release( doc );
3902 static void test_get_childNodes(void)
3906 IXMLDOMDocument *doc;
3907 IXMLDOMElement *element;
3908 IXMLDOMNode *node, *node2;
3909 IXMLDOMNodeList *node_list, *node_list2;
3913 doc = create_document(&IID_IXMLDOMDocument);
3916 str = SysAllocString( szComplete4 );
3917 hr = IXMLDOMDocument_loadXML( doc, str, &b );
3918 EXPECT_HR(hr, S_OK);
3919 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3920 SysFreeString( str );
3922 hr = IXMLDOMDocument_get_documentElement( doc, &element );
3923 EXPECT_HR(hr, S_OK);
3925 hr = IXMLDOMElement_get_childNodes( element, &node_list );
3926 EXPECT_HR(hr, S_OK);
3928 hr = IXMLDOMNodeList_get_length( node_list, &len );
3929 EXPECT_HR(hr, S_OK);
3930 ok( len == 4, "len %d\n", len);
3932 hr = IXMLDOMNodeList_get_item( node_list, 2, &node );
3933 EXPECT_HR(hr, S_OK);
3935 hr = IXMLDOMNode_get_childNodes( node, &node_list2 );
3936 EXPECT_HR(hr, S_OK);
3938 hr = IXMLDOMNodeList_get_length( node_list2, &len );
3939 EXPECT_HR(hr, S_OK);
3940 ok( len == 0, "len %d\n", len);
3942 hr = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
3943 EXPECT_HR(hr, S_FALSE);
3945 IXMLDOMNodeList_Release( node_list2 );
3946 IXMLDOMNode_Release( node );
3947 IXMLDOMNodeList_Release( node_list );
3948 IXMLDOMElement_Release( element );
3950 /* test for children of <?xml ..?> node */
3951 hr = IXMLDOMDocument_get_firstChild(doc, &node);
3952 EXPECT_HR(hr, S_OK);
3955 hr = IXMLDOMNode_get_nodeName(node, &str);
3956 EXPECT_HR(hr, S_OK);
3957 ok(!lstrcmpW(str, _bstr_("xml")), "got %s\n", wine_dbgstr_w(str));
3960 /* it returns empty but valid node list */
3961 node_list = (void*)0xdeadbeef;
3962 hr = IXMLDOMNode_get_childNodes(node, &node_list);
3963 EXPECT_HR(hr, S_OK);
3966 hr = IXMLDOMNodeList_get_length(node_list, &len);
3967 EXPECT_HR(hr, S_OK);
3968 ok(len == 0, "got %d\n", len);
3970 IXMLDOMNodeList_Release( node_list );
3971 IXMLDOMNode_Release(node);
3973 IXMLDOMDocument_Release( doc );
3977 static void test_get_firstChild(void)
3979 static WCHAR xmlW[] = {'x','m','l',0};
3980 IXMLDOMDocument *doc;
3986 doc = create_document(&IID_IXMLDOMDocument);
3989 str = SysAllocString( szComplete4 );
3990 r = IXMLDOMDocument_loadXML( doc, str, &b );
3991 ok( r == S_OK, "loadXML failed\n");
3992 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3993 SysFreeString( str );
3995 r = IXMLDOMDocument_get_firstChild( doc, &node );
3996 ok( r == S_OK, "ret %08x\n", r);
3998 r = IXMLDOMNode_get_nodeName( node, &str );
3999 ok( r == S_OK, "ret %08x\n", r);
4001 ok(!lstrcmpW(str, xmlW), "expected \"xml\" node name, got %s\n", wine_dbgstr_w(str));
4004 IXMLDOMNode_Release( node );
4005 IXMLDOMDocument_Release( doc );
4008 static void test_get_lastChild(void)
4010 static WCHAR lcW[] = {'l','c',0};
4011 static WCHAR foW[] = {'f','o',0};
4012 IXMLDOMDocument *doc;
4013 IXMLDOMNode *node, *child;
4018 doc = create_document(&IID_IXMLDOMDocument);
4021 str = SysAllocString( szComplete4 );
4022 r = IXMLDOMDocument_loadXML( doc, str, &b );
4023 ok( r == S_OK, "loadXML failed\n");
4024 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4025 SysFreeString( str );
4027 r = IXMLDOMDocument_get_lastChild( doc, &node );
4028 ok( r == S_OK, "ret %08x\n", r);
4030 r = IXMLDOMNode_get_nodeName( node, &str );
4031 ok( r == S_OK, "ret %08x\n", r);
4033 ok(memcmp(str, lcW, sizeof(lcW)) == 0, "expected \"lc\" node name\n");
4036 r = IXMLDOMNode_get_lastChild( node, &child );
4037 ok( r == S_OK, "ret %08x\n", r);
4039 r = IXMLDOMNode_get_nodeName( child, &str );
4040 ok( r == S_OK, "ret %08x\n", r);
4042 ok(memcmp(str, foW, sizeof(foW)) == 0, "expected \"fo\" node name\n");
4045 IXMLDOMNode_Release( child );
4046 IXMLDOMNode_Release( node );
4047 IXMLDOMDocument_Release( doc );
4050 static void test_removeChild(void)
4055 IXMLDOMDocument *doc;
4056 IXMLDOMElement *element, *lc_element;
4057 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
4058 IXMLDOMNodeList *root_list, *fo_list;
4060 doc = create_document(&IID_IXMLDOMDocument);
4063 str = SysAllocString( szComplete4 );
4064 r = IXMLDOMDocument_loadXML( doc, str, &b );
4065 ok( r == S_OK, "loadXML failed\n");
4066 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4067 SysFreeString( str );
4069 r = IXMLDOMDocument_get_documentElement( doc, &element );
4070 ok( r == S_OK, "ret %08x\n", r);
4071 todo_wine EXPECT_REF(element, 2);
4073 r = IXMLDOMElement_get_childNodes( element, &root_list );
4074 ok( r == S_OK, "ret %08x\n", r);
4075 EXPECT_REF(root_list, 1);
4077 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
4078 ok( r == S_OK, "ret %08x\n", r);
4079 EXPECT_REF(fo_node, 1);
4081 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4082 ok( r == S_OK, "ret %08x\n", r);
4083 EXPECT_REF(fo_list, 1);
4085 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
4086 ok( r == S_OK, "ret %08x\n", r);
4087 EXPECT_REF(ba_node, 1);
4089 /* invalid parameter: NULL ptr */
4090 removed_node = (void*)0xdeadbeef;
4091 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
4092 ok( r == E_INVALIDARG, "ret %08x\n", r );
4093 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4095 /* ba_node is a descendant of element, but not a direct child. */
4096 removed_node = (void*)0xdeadbeef;
4097 EXPECT_REF(ba_node, 1);
4098 EXPECT_CHILDREN(fo_node);
4099 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
4100 ok( r == E_INVALIDARG, "ret %08x\n", r );
4101 ok( removed_node == NULL, "%p\n", removed_node );
4102 EXPECT_REF(ba_node, 1);
4103 EXPECT_CHILDREN(fo_node);
4105 EXPECT_REF(ba_node, 1);
4106 EXPECT_REF(fo_node, 1);
4107 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
4108 ok( r == S_OK, "ret %08x\n", r);
4109 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
4110 EXPECT_REF(fo_node, 2);
4111 EXPECT_REF(ba_node, 1);
4113 /* try removing already removed child */
4114 temp_node = (void*)0xdeadbeef;
4115 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
4116 ok( r == E_INVALIDARG, "ret %08x\n", r);
4117 ok( temp_node == NULL, "%p\n", temp_node );
4118 IXMLDOMNode_Release( fo_node );
4120 /* the removed node has no parent anymore */
4121 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
4122 ok( r == S_FALSE, "ret %08x\n", r);
4123 ok( temp_node == NULL, "%p\n", temp_node );
4125 IXMLDOMNode_Release( removed_node );
4126 IXMLDOMNode_Release( ba_node );
4127 IXMLDOMNodeList_Release( fo_list );
4129 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
4130 ok( r == S_OK, "ret %08x\n", r);
4132 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (void**)&lc_element );
4133 ok( r == S_OK, "ret %08x\n", r);
4135 /* MS quirk: passing wrong interface pointer works, too */
4136 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
4137 ok( r == S_OK, "ret %08x\n", r);
4138 IXMLDOMElement_Release( lc_element );
4140 temp_node = (void*)0xdeadbeef;
4141 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
4142 ok( r == S_FALSE, "ret %08x\n", r);
4143 ok( temp_node == NULL, "%p\n", temp_node );
4145 IXMLDOMNode_Release( lc_node );
4146 IXMLDOMNodeList_Release( root_list );
4147 IXMLDOMElement_Release( element );
4148 IXMLDOMDocument_Release( doc );
4151 static void test_replaceChild(void)
4156 IXMLDOMDocument *doc;
4157 IXMLDOMElement *element, *ba_element;
4158 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
4159 IXMLDOMNodeList *root_list, *fo_list;
4160 IUnknown * unk1, *unk2;
4163 doc = create_document(&IID_IXMLDOMDocument);
4166 str = SysAllocString( szComplete4 );
4167 r = IXMLDOMDocument_loadXML( doc, str, &b );
4168 ok( r == S_OK, "loadXML failed\n");
4169 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4170 SysFreeString( str );
4172 r = IXMLDOMDocument_get_documentElement( doc, &element );
4173 ok( r == S_OK, "ret %08x\n", r);
4175 r = IXMLDOMElement_get_childNodes( element, &root_list );
4176 ok( r == S_OK, "ret %08x\n", r);
4178 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
4179 ok( r == S_OK, "ret %08x\n", r);
4181 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
4182 ok( r == S_OK, "ret %08x\n", r);
4184 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4185 ok( r == S_OK, "ret %08x\n", r);
4187 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
4188 ok( r == S_OK, "ret %08x\n", r);
4190 IXMLDOMNodeList_Release( fo_list );
4192 /* invalid parameter: NULL ptr for element to remove */
4193 removed_node = (void*)0xdeadbeef;
4194 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
4195 ok( r == E_INVALIDARG, "ret %08x\n", r );
4196 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4198 /* invalid parameter: NULL for replacement element. (Sic!) */
4199 removed_node = (void*)0xdeadbeef;
4200 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
4201 ok( r == E_INVALIDARG, "ret %08x\n", r );
4202 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4204 /* invalid parameter: OldNode is not a child */
4205 removed_node = (void*)0xdeadbeef;
4206 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
4207 ok( r == E_INVALIDARG, "ret %08x\n", r );
4208 ok( removed_node == NULL, "%p\n", removed_node );
4209 IXMLDOMNode_Release( lc_node );
4211 /* invalid parameter: would create loop */
4212 removed_node = (void*)0xdeadbeef;
4213 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
4214 ok( r == E_FAIL, "ret %08x\n", r );
4215 ok( removed_node == NULL, "%p\n", removed_node );
4217 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
4218 ok( r == S_OK, "ret %08x\n", r );
4220 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
4221 ok( r == S_OK, "ret %08x\n", r );
4223 /* ba_node and temp_node refer to the same node, yet they
4224 are different interface pointers */
4225 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
4226 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
4227 ok( r == S_OK, "ret %08x\n", r );
4228 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
4229 ok( r == S_OK, "ret %08x\n", r );
4230 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
4232 IUnknown_Release( unk1 );
4233 IUnknown_Release( unk2 );
4235 /* ba_node should have been removed from below fo_node */
4236 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4237 ok( r == S_OK, "ret %08x\n", r );
4239 /* MS quirk: replaceChild also accepts elements instead of nodes */
4240 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
4241 ok( r == S_OK, "ret %08x\n", r );
4242 EXPECT_REF(ba_element, 2);
4244 removed_node = NULL;
4245 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
4246 ok( r == S_OK, "ret %08x\n", r );
4247 ok( removed_node != NULL, "got %p\n", removed_node);
4248 EXPECT_REF(ba_element, 3);
4249 IXMLDOMElement_Release( ba_element );
4251 r = IXMLDOMNodeList_get_length( fo_list, &len);
4252 ok( r == S_OK, "ret %08x\n", r );
4253 ok( len == 0, "len %d\n", len);
4255 IXMLDOMNodeList_Release( fo_list );
4257 IXMLDOMNode_Release(ba_node);
4258 IXMLDOMNode_Release(fo_node);
4259 IXMLDOMNode_Release(temp_node);
4260 IXMLDOMNodeList_Release( root_list );
4261 IXMLDOMElement_Release( element );
4262 IXMLDOMDocument_Release( doc );
4265 static void test_removeNamedItem(void)
4267 IXMLDOMDocument *doc;
4268 IXMLDOMElement *element;
4269 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
4270 IXMLDOMNodeList *root_list;
4271 IXMLDOMNamedNodeMap * pr_attrs;
4277 doc = create_document(&IID_IXMLDOMDocument);
4280 str = SysAllocString( szComplete4 );
4281 r = IXMLDOMDocument_loadXML( doc, str, &b );
4282 ok( r == S_OK, "loadXML failed\n");
4283 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4284 SysFreeString( str );
4286 r = IXMLDOMDocument_get_documentElement( doc, &element );
4287 ok( r == S_OK, "ret %08x\n", r);
4289 r = IXMLDOMElement_get_childNodes( element, &root_list );
4290 ok( r == S_OK, "ret %08x\n", r);
4292 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
4293 ok( r == S_OK, "ret %08x\n", r);
4295 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
4296 ok( r == S_OK, "ret %08x\n", r);
4298 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4299 ok( r == S_OK, "ret %08x\n", r);
4300 ok( len == 3, "length %d\n", len);
4302 removed_node = (void*)0xdeadbeef;
4303 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
4304 ok ( r == E_INVALIDARG, "ret %08x\n", r);
4305 ok ( removed_node == (void*)0xdeadbeef, "got %p\n", removed_node);
4307 removed_node = (void*)0xdeadbeef;
4308 str = SysAllocString(szvr);
4309 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
4310 ok ( r == S_OK, "ret %08x\n", r);
4312 removed_node2 = (void*)0xdeadbeef;
4313 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
4314 ok ( r == S_FALSE, "ret %08x\n", r);
4315 ok ( removed_node2 == NULL, "got %p\n", removed_node2 );
4317 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4318 ok( r == S_OK, "ret %08x\n", r);
4319 ok( len == 2, "length %d\n", len);
4321 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
4322 ok ( r == S_OK, "ret %08x\n", r);
4323 IXMLDOMNode_Release(removed_node);
4325 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4326 ok( r == S_OK, "ret %08x\n", r);
4327 ok( len == 3, "length %d\n", len);
4329 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
4330 ok ( r == S_OK, "ret %08x\n", r);
4332 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4333 ok( r == S_OK, "ret %08x\n", r);
4334 ok( len == 2, "length %d\n", len);
4336 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
4337 ok ( r == S_FALSE, "ret %08x\n", r);
4341 IXMLDOMNamedNodeMap_Release( pr_attrs );
4342 IXMLDOMNode_Release( pr_node );
4343 IXMLDOMNodeList_Release( root_list );
4344 IXMLDOMElement_Release( element );
4345 IXMLDOMDocument_Release( doc );
4348 #define test_IObjectSafety_set(p, r, r2, s, m, e, e2) _test_IObjectSafety_set(__LINE__,p, r, r2, s, m, e, e2)
4349 static void _test_IObjectSafety_set(unsigned line, IObjectSafety *safety, HRESULT result,
4350 HRESULT result2, DWORD set, DWORD mask, DWORD expected,
4353 DWORD enabled, supported;
4356 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL, set, mask);
4357 if (result == result2)
4358 ok_(__FILE__,line)(hr == result, "SetInterfaceSafetyOptions: expected %08x, returned %08x\n", result, hr );
4360 ok_(__FILE__,line)(broken(hr == result) || hr == result2,
4361 "SetInterfaceSafetyOptions: expected %08x, got %08x\n", result2, hr );
4363 supported = enabled = 0xCAFECAFE;
4364 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4365 ok(hr == S_OK, "ret %08x\n", hr );
4366 if (expected == expected2)
4367 ok_(__FILE__,line)(enabled == expected, "Expected %08x, got %08x\n", expected, enabled);
4369 ok_(__FILE__,line)(broken(enabled == expected) || enabled == expected2,
4370 "Expected %08x, got %08x\n", expected2, enabled);
4372 /* reset the safety options */
4374 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4375 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER,
4377 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4379 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4380 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4381 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
4384 #define test_IObjectSafety_common(s) _test_IObjectSafety_common(__LINE__,s)
4385 static void _test_IObjectSafety_common(unsigned line, IObjectSafety *safety)
4387 DWORD enabled = 0, supported = 0;
4391 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, NULL, &enabled);
4392 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
4393 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, NULL);
4394 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
4396 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4397 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4398 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
4399 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4400 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
4401 "got %08x\n", supported);
4402 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
4404 /* set -- individual flags */
4406 test_IObjectSafety_set(safety, S_OK, S_OK,
4407 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4408 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4410 test_IObjectSafety_set(safety, S_OK, S_OK,
4411 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA,
4412 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
4414 test_IObjectSafety_set(safety, S_OK, S_OK,
4415 INTERFACE_USES_SECURITY_MANAGER, INTERFACE_USES_SECURITY_MANAGER,
4416 0, INTERFACE_USES_SECURITY_MANAGER /* msxml3 SP8+ */);
4418 /* set INTERFACE_USES_DISPEX */
4420 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
4421 INTERFACE_USES_DISPEX, INTERFACE_USES_DISPEX,
4424 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
4425 INTERFACE_USES_DISPEX, 0,
4428 test_IObjectSafety_set(safety, S_OK, S_OK /* msxml3 SP8+ */,
4429 0, INTERFACE_USES_DISPEX,
4432 /* set option masking */
4434 test_IObjectSafety_set(safety, S_OK, S_OK,
4435 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4436 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4437 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4438 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4440 test_IObjectSafety_set(safety, S_OK, S_OK,
4441 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4442 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4443 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4444 INTERFACESAFE_FOR_UNTRUSTED_DATA);
4446 test_IObjectSafety_set(safety, S_OK, S_OK,
4447 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4448 INTERFACE_USES_SECURITY_MANAGER,
4452 /* set -- inheriting previous settings */
4454 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4455 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4456 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4457 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4458 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4459 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4461 ok_(__FILE__,line)(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_CALLER) ||
4462 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4463 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER), "
4464 "got %08x\n", enabled);
4466 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4467 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4468 INTERFACESAFE_FOR_UNTRUSTED_DATA);
4469 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4470 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4471 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4473 ok_(__FILE__,line)(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_DATA) ||
4474 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA) /* msxml3 SP8+ */,
4475 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA), "
4476 "got %08x\n", enabled);
4479 static void test_XMLHTTP(void)
4481 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
4482 static const WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
4483 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
4484 'p','o','s','t','t','e','s','t','.','p','h','p',0};
4485 static const WCHAR xmltestW[] = {'h','t','t','p',':','/','/',
4486 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
4487 'x','m','l','t','e','s','t','.','x','m','l',0};
4488 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
4489 static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
4491 IXMLHttpRequest *xhr;
4492 IObjectSafety *safety;
4493 IObjectWithSite *obj_site, *obj_site2;
4494 BSTR bstrResponse, url;
4498 LONG state, status, bound;
4503 hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
4504 &IID_IXMLHttpRequest, (void**)&xhr);
4507 win_skip("IXMLHTTPRequest is not available (0x%08x)\n", hr);
4511 VariantInit(&dummy);
4512 V_VT(&dummy) = VT_ERROR;
4513 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
4514 VariantInit(&async);
4515 V_VT(&async) = VT_BOOL;
4516 V_BOOL(&async) = VARIANT_FALSE;
4517 V_VT(&varbody) = VT_BSTR;
4518 V_BSTR(&varbody) = SysAllocString(wszBody);
4520 url = SysAllocString(wszUrl);
4522 hr = IXMLHttpRequest_put_onreadystatechange(xhr, NULL);
4523 EXPECT_HR(hr, S_OK);
4525 hr = IXMLHttpRequest_abort(xhr);
4526 EXPECT_HR(hr, S_OK);
4528 /* send before open */
4529 hr = IXMLHttpRequest_send(xhr, dummy);
4530 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4532 /* initial status code */
4533 hr = IXMLHttpRequest_get_status(xhr, NULL);
4534 EXPECT_HR(hr, E_INVALIDARG);
4536 status = 0xdeadbeef;
4537 hr = IXMLHttpRequest_get_status(xhr, &status);
4538 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4539 ok(status == 0xdeadbeef, "got %d\n", status);
4541 /* invalid parameters */
4542 hr = IXMLHttpRequest_open(xhr, NULL, NULL, async, dummy, dummy);
4543 EXPECT_HR(hr, E_INVALIDARG);
4545 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), NULL, async, dummy, dummy);
4546 EXPECT_HR(hr, E_INVALIDARG);
4548 hr = IXMLHttpRequest_open(xhr, NULL, url, async, dummy, dummy);
4549 EXPECT_HR(hr, E_INVALIDARG);
4551 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, NULL);
4552 EXPECT_HR(hr, E_INVALIDARG);
4554 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), NULL);
4555 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4557 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
4558 EXPECT_HR(hr, E_INVALIDARG);
4560 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
4561 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4563 hr = IXMLHttpRequest_get_readyState(xhr, NULL);
4564 EXPECT_HR(hr, E_INVALIDARG);
4567 hr = IXMLHttpRequest_get_readyState(xhr, &state);
4568 EXPECT_HR(hr, S_OK);
4569 ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state);
4571 event = create_dispevent();
4573 EXPECT_REF(event, 1);
4574 hr = IXMLHttpRequest_put_onreadystatechange(xhr, event);
4575 EXPECT_HR(hr, S_OK);
4576 EXPECT_REF(event, 2);
4578 g_unexpectedcall = g_expectedcall = 0;
4580 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), url, async, dummy, dummy);
4581 EXPECT_HR(hr, S_OK);
4583 ok(g_unexpectedcall == 0, "unexpected disp event call\n");
4584 ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n");
4586 /* status code after ::open() */
4587 status = 0xdeadbeef;
4588 hr = IXMLHttpRequest_get_status(xhr, &status);
4589 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4590 ok(status == 0xdeadbeef, "got %d\n", status);
4593 hr = IXMLHttpRequest_get_readyState(xhr, &state);
4594 EXPECT_HR(hr, S_OK);
4595 ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state);
4597 hr = IXMLHttpRequest_abort(xhr);
4598 EXPECT_HR(hr, S_OK);
4601 hr = IXMLHttpRequest_get_readyState(xhr, &state);
4602 EXPECT_HR(hr, S_OK);
4603 ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win2k */,
4604 "got %d, expected READYSTATE_UNINITIALIZED\n", state);
4606 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), url, async, dummy, dummy);
4607 EXPECT_HR(hr, S_OK);
4609 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
4610 EXPECT_HR(hr, S_OK);
4612 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
4613 EXPECT_HR(hr, E_INVALIDARG);
4615 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_(""), _bstr_("value1"));
4616 EXPECT_HR(hr, E_INVALIDARG);
4620 hr = IXMLHttpRequest_send(xhr, varbody);
4621 if (hr == INET_E_RESOURCE_NOT_FOUND)
4623 skip("No connection could be made with crossover.codeweavers.com\n");
4624 IXMLHttpRequest_Release(xhr);
4627 EXPECT_HR(hr, S_OK);
4629 /* status code after ::send() */
4630 status = 0xdeadbeef;
4631 hr = IXMLHttpRequest_get_status(xhr, &status);
4632 EXPECT_HR(hr, S_OK);
4633 ok(status == 200, "got %d\n", status);
4635 /* another ::send() after completed request */
4636 hr = IXMLHttpRequest_send(xhr, varbody);
4637 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4639 VariantClear(&varbody);
4641 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
4642 EXPECT_HR(hr, S_OK);
4643 /* the server currently returns "FAILED" because the Content-Type header is
4644 * not what the server expects */
4647 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)),
4648 "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse));
4649 SysFreeString(bstrResponse);
4653 url = SysAllocString(xmltestW);
4655 hr = IXMLHttpRequest_open(xhr, _bstr_("GET"), url, async, dummy, dummy);
4656 EXPECT_HR(hr, S_OK);
4658 V_VT(&varbody) = VT_EMPTY;
4660 hr = IXMLHttpRequest_send(xhr, varbody);
4661 if (hr == INET_E_RESOURCE_NOT_FOUND)
4663 skip("No connection could be made with crossover.codeweavers.com\n");
4664 IXMLHttpRequest_Release(xhr);
4667 EXPECT_HR(hr, S_OK);
4669 hr = IXMLHttpRequest_get_responseText(xhr, NULL);
4670 EXPECT_HR(hr, E_INVALIDARG);
4672 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
4673 EXPECT_HR(hr, S_OK);
4674 ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
4675 "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
4676 SysFreeString(bstrResponse);
4678 hr = IXMLHttpRequest_get_responseBody(xhr, NULL);
4679 EXPECT_HR(hr, E_INVALIDARG);
4681 V_VT(&varbody) = VT_EMPTY;
4682 hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
4683 EXPECT_HR(hr, S_OK);
4684 ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
4685 ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
4688 hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
4689 EXPECT_HR(hr, S_OK);
4690 ok(bound == 0, "got %d, expected zero bound\n", bound);
4692 hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
4693 EXPECT_HR(hr, S_OK);
4694 ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrong body data\n");
4695 SafeArrayUnaccessData(V_ARRAY(&varbody));
4697 VariantClear(&varbody);
4701 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectSafety, (void**)&safety);
4702 EXPECT_HR(hr, S_OK);
4705 test_IObjectSafety_common(safety);
4706 IObjectSafety_Release(safety);
4709 IDispatch_Release(event);
4711 /* interaction with object site */
4713 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site);
4714 EXPECT_HR(hr, S_OK);
4717 EXPECT_REF(obj_site, 1);
4720 IObjectWithSite_AddRef(obj_site);
4722 EXPECT_REF(obj_site, 2);
4725 IObjectWithSite_Release(obj_site);
4727 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site2);
4728 EXPECT_HR(hr, S_OK);
4731 EXPECT_REF(obj_site, 1);
4732 EXPECT_REF(obj_site2, 1);
4733 ok(obj_site != obj_site2, "expected new instance\n");
4735 SET_EXPECT(site_qi_IServiceProvider);
4736 SET_EXPECT(sp_queryservice_SID_SBindHost);
4737 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
4738 SET_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
4739 SET_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
4740 SET_EXPECT(sp_queryservice_SID_secmgr_secmgr);
4742 /* calls to IHTMLDocument2 */
4743 SET_EXPECT(htmldoc2_get_all);
4744 SET_EXPECT(collection_get_length);
4745 SET_EXPECT(htmldoc2_get_url);
4747 SET_EXPECT(site_qi_IXMLDOMDocument);
4748 SET_EXPECT(site_qi_IOleClientSite);
4750 hr = IObjectWithSite_SetSite(obj_site, &testsite.IUnknown_iface);
4751 EXPECT_HR(hr, S_OK);
4754 CHECK_CALLED(site_qi_IServiceProvider);
4756 CHECK_CALLED(sp_queryservice_SID_SBindHost);
4757 CHECK_CALLED(sp_queryservice_SID_SContainerDispatch_htmldoc2);
4758 CHECK_CALLED(sp_queryservice_SID_secmgr_htmldoc2);
4759 CHECK_CALLED(sp_queryservice_SID_secmgr_xmldomdoc);
4760 /* this one isn't very reliable
4761 CHECK_CALLED(sp_queryservice_SID_secmgr_secmgr); */
4763 CHECK_CALLED(htmldoc2_get_all);
4764 CHECK_CALLED(collection_get_length);
4765 CHECK_CALLED(htmldoc2_get_url);
4767 CHECK_CALLED(site_qi_IXMLDOMDocument);
4768 CHECK_CALLED(site_qi_IOleClientSite);
4770 IObjectWithSite_Release(obj_site);
4772 todo_wine EXPECT_REF(xhr, 1);
4773 IXMLHttpRequest_Release(xhr);
4775 /* still works after request is released */
4776 SET_EXPECT(site_qi_IServiceProvider);
4778 hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
4779 EXPECT_HR(hr, S_OK);
4780 IObjectWithSite_Release(obj_site2);
4785 static void test_IXMLDOMDocument2(void)
4787 static const WCHAR emptyW[] = {0};
4788 IXMLDOMDocument2 *doc2, *dtddoc2;
4789 IXMLDOMDocument *doc;
4790 IXMLDOMParseError* err;
4791 IDispatchEx *dispex;
4798 doc = create_document(&IID_IXMLDOMDocument);
4801 dtddoc2 = create_document(&IID_IXMLDOMDocument2);
4804 IXMLDOMDocument_Release(doc);
4808 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
4809 ok( r == S_OK, "ret %08x\n", r );
4810 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
4812 ole_expect(IXMLDOMDocument2_get_readyState(doc2, NULL), E_INVALIDARG);
4813 ole_check(IXMLDOMDocument2_get_readyState(doc2, &res));
4814 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
4817 ole_expect(IXMLDOMDocument2_validate(doc2, NULL), S_FALSE);
4818 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
4819 ok(err != NULL, "expected a pointer\n");
4823 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4825 ok(res == E_XML_NOTWF, "got %08x\n", res);
4826 IXMLDOMParseError_Release(err);
4829 str = SysAllocString( szComplete4 );
4830 r = IXMLDOMDocument_loadXML( doc2, str, &b );
4831 ok( r == S_OK, "loadXML failed\n");
4832 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4833 SysFreeString( str );
4835 ole_check(IXMLDOMDocument2_get_readyState(doc, &res));
4836 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
4839 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
4840 ok(err != NULL, "expected a pointer\n");
4844 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4846 ok(res == E_XML_NODTD, "got %08x\n", res);
4847 IXMLDOMParseError_Release(err);
4850 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
4851 ok( r == S_OK, "ret %08x\n", r );
4854 IDispatchEx_Release(dispex);
4857 /* we will check if the variant got cleared */
4858 IXMLDOMDocument2_AddRef(doc2);
4859 EXPECT_REF(doc2, 3); /* doc, doc2, AddRef*/
4861 V_VT(&var) = VT_UNKNOWN;
4862 V_UNKNOWN(&var) = (IUnknown *)doc2;
4865 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
4866 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
4867 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
4870 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
4871 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
4872 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
4875 /* the variant didn't get cleared*/
4876 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
4878 /* setProperty tests */
4879 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
4880 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
4881 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
4882 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
4883 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4884 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
4886 V_VT(&var) = VT_BSTR;
4887 V_BSTR(&var) = SysAllocString(emptyW);
4888 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
4889 ok(r == S_OK, "got 0x%08x\n", r);
4894 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
4895 ok(r == E_FAIL, "got 0x%08x\n", r);
4897 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
4898 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
4899 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
4900 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
4902 IXMLDOMDocument2_Release( doc2 );
4903 IXMLDOMDocument_Release( doc );
4905 /* DTD validation */
4906 ole_check(IXMLDOMDocument2_put_validateOnParse(dtddoc2, VARIANT_FALSE));
4907 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML), &b));
4908 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4910 ole_check(IXMLDOMDocument2_validate(dtddoc2, &err));
4911 ok(err != NULL, "expected pointer\n");
4915 ole_expect(IXMLDOMParseError_get_errorCode(err, &res), S_FALSE);
4916 ok(res == 0, "got %08x\n", res);
4917 IXMLDOMParseError_Release(err);
4920 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0D), &b));
4921 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4923 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4924 ok(err != NULL, "expected pointer\n");
4928 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4929 /* XML_ELEMENT_UNDECLARED */
4930 todo_wine ok(res == 0xC00CE00D, "got %08x\n", res);
4931 IXMLDOMParseError_Release(err);
4934 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0E), &b));
4935 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4937 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4938 ok(err != NULL, "expected pointer\n");
4942 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4943 /* XML_ELEMENT_ID_NOT_FOUND */
4944 todo_wine ok(res == 0xC00CE00E, "got %08x\n", res);
4945 IXMLDOMParseError_Release(err);
4948 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_11), &b));
4949 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4951 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4952 ok(err != NULL, "expected pointer\n");
4956 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4957 /* XML_EMPTY_NOT_ALLOWED */
4958 todo_wine ok(res == 0xC00CE011, "got %08x\n", res);
4959 IXMLDOMParseError_Release(err);
4962 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_13), &b));
4963 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4965 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4966 ok(err != NULL, "expected pointer\n");
4970 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4971 /* XML_ROOT_NAME_MISMATCH */
4972 todo_wine ok(res == 0xC00CE013, "got %08x\n", res);
4973 IXMLDOMParseError_Release(err);
4976 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_14), &b));
4977 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4979 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4980 ok(err != NULL, "expected pointer\n");
4984 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4985 /* XML_INVALID_CONTENT */
4986 todo_wine ok(res == 0xC00CE014, "got %08x\n", res);
4987 IXMLDOMParseError_Release(err);
4990 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_15), &b));
4991 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4993 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4994 ok(err != NULL, "expected pointer\n");
4998 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4999 /* XML_ATTRIBUTE_NOT_DEFINED */
5000 todo_wine ok(res == 0xC00CE015, "got %08x\n", res);
5001 IXMLDOMParseError_Release(err);
5004 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_16), &b));
5005 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5007 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5008 ok(err != NULL, "expected pointer\n");
5012 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5013 /* XML_ATTRIBUTE_FIXED */
5014 todo_wine ok(res == 0xC00CE016, "got %08x\n", res);
5015 IXMLDOMParseError_Release(err);
5018 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_17), &b));
5019 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5021 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5022 ok(err != NULL, "expected pointer\n");
5026 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5027 /* XML_ATTRIBUTE_VALUE */
5028 todo_wine ok(res == 0xC00CE017, "got %08x\n", res);
5029 IXMLDOMParseError_Release(err);
5032 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_18), &b));
5033 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5035 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5036 ok(err != NULL, "expected pointer\n");
5040 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5041 /* XML_ILLEGAL_TEXT */
5042 todo_wine ok(res == 0xC00CE018, "got %08x\n", res);
5043 IXMLDOMParseError_Release(err);
5046 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_20), &b));
5047 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5049 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5050 ok(err != NULL, "expected pointer\n");
5054 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5055 /* XML_REQUIRED_ATTRIBUTE_MISSING */
5056 todo_wine ok(res == 0xC00CE020, "got %08x\n", res);
5057 IXMLDOMParseError_Release(err);
5060 IXMLDOMDocument2_Release( dtddoc2 );
5064 #define helper_ole_check(expr) { \
5066 ok_(__FILE__, line)(r == S_OK, "=> %i: " #expr " returned %08x\n", __LINE__, r); \
5069 #define helper_expect_list_and_release(list, expstr) { \
5070 char *str = list_to_string(list); \
5071 ok_(__FILE__, line)(strcmp(str, expstr)==0, "=> %i: Invalid node list: %s, expected %s\n", __LINE__, str, expstr); \
5072 if (list) IXMLDOMNodeList_Release(list); \
5075 #define helper_expect_bstr_and_release(bstr, str) { \
5076 ok_(__FILE__, line)(lstrcmpW(bstr, _bstr_(str)) == 0, \
5077 "=> %i: got %s\n", __LINE__, wine_dbgstr_w(bstr)); \
5078 SysFreeString(bstr); \
5081 #define check_ws_ignored(doc, str) _check_ws_ignored(__LINE__, doc, str)
5082 static inline void _check_ws_ignored(int line, IXMLDOMDocument2* doc, char const* str)
5084 IXMLDOMNode *node1, *node2;
5085 IXMLDOMNodeList *list;
5088 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
5089 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
5090 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
5091 helper_ole_check(IXMLDOMNodeList_reset(list));
5092 helper_expect_list_and_release(list, "E1.E4.E1.E2.D1 E2.E4.E1.E2.D1");
5094 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
5095 helper_expect_list_and_release(list, "T1.E1.E4.E1.E2.D1 E2.E1.E4.E1.E2.D1 E3.E1.E4.E1.E2.D1 T4.E1.E4.E1.E2.D1 E5.E1.E4.E1.E2.D1");
5096 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
5099 helper_expect_bstr_and_release(bstr, str);
5103 helper_expect_bstr_and_release(bstr, "This is a description.");
5105 IXMLDOMNode_Release(node1);
5107 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
5108 helper_expect_list_and_release(list, "T1.E2.E4.E1.E2.D1 E2.E2.E4.E1.E2.D1 T3.E2.E4.E1.E2.D1 E4.E2.E4.E1.E2.D1 T5.E2.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1 T7.E2.E4.E1.E2.D1");
5109 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
5110 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
5111 IXMLDOMNode_Release(node2);
5114 #define check_ws_preserved(doc, str) _check_ws_preserved(__LINE__, doc, str)
5115 static inline void _check_ws_preserved(int line, IXMLDOMDocument2* doc, char const* str)
5117 IXMLDOMNode *node1, *node2;
5118 IXMLDOMNodeList *list;
5121 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
5122 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
5123 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
5124 helper_ole_check(IXMLDOMNodeList_reset(list));
5125 helper_expect_list_and_release(list, "E2.E8.E2.E2.D1 E4.E8.E2.E2.D1");
5127 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
5128 helper_expect_list_and_release(list, "T1.E2.E8.E2.E2.D1 E2.E2.E8.E2.E2.D1 T3.E2.E8.E2.E2.D1 E4.E2.E8.E2.E2.D1 T5.E2.E8.E2.E2.D1 E6.E2.E8.E2.E2.D1 T7.E2.E8.E2.E2.D1");
5129 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
5132 helper_expect_bstr_and_release(bstr, str);
5136 helper_expect_bstr_and_release(bstr, "\n This is a description. \n ");
5138 IXMLDOMNode_Release(node1);
5140 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
5141 helper_expect_list_and_release(list, "T1.E4.E8.E2.E2.D1 E2.E4.E8.E2.E2.D1 T3.E4.E8.E2.E2.D1 E4.E4.E8.E2.E2.D1 T5.E4.E8.E2.E2.D1 E6.E4.E8.E2.E2.D1 T7.E4.E8.E2.E2.D1");
5142 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
5143 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
5144 IXMLDOMNode_Release(node2);
5147 static void test_whitespace(void)
5150 IXMLDOMDocument2 *doc1, *doc2, *doc3, *doc4;
5152 doc1 = create_document(&IID_IXMLDOMDocument2);
5153 doc2 = create_document(&IID_IXMLDOMDocument2);
5154 if (!doc1 || !doc2) return;
5156 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_TRUE));
5157 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
5158 ok(b == VARIANT_FALSE, "expected false\n");
5159 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
5160 ok(b == VARIANT_TRUE, "expected true\n");
5162 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
5163 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5164 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
5165 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5167 /* switch to XPath */
5168 ole_check(IXMLDOMDocument2_setProperty(doc1, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5169 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5171 check_ws_ignored(doc1, NULL);
5172 check_ws_preserved(doc2, NULL);
5174 /* new instances copy the property */
5175 ole_check(IXMLDOMDocument2_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**) &doc3));
5176 ole_check(IXMLDOMDocument2_QueryInterface(doc2, &IID_IXMLDOMDocument2, (void**) &doc4));
5178 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
5179 ok(b == VARIANT_FALSE, "expected false\n");
5180 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
5181 ok(b == VARIANT_TRUE, "expected true\n");
5183 check_ws_ignored(doc3, NULL);
5184 check_ws_preserved(doc4, NULL);
5186 /* setting after loading xml affects trimming of leading/trailing ws only */
5187 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_TRUE));
5188 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_FALSE));
5190 /* the trailing "\n " isn't there, because it was ws-only node */
5191 check_ws_ignored(doc1, "\n This is a description. ");
5192 check_ws_preserved(doc2, "This is a description.");
5194 /* it takes effect on reload */
5195 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
5196 ok(b == VARIANT_TRUE, "expected true\n");
5197 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
5198 ok(b == VARIANT_FALSE, "expected false\n");
5200 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
5201 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5202 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
5203 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5205 check_ws_preserved(doc1, NULL);
5206 check_ws_ignored(doc2, NULL);
5208 /* other instances follow suit */
5209 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
5210 ok(b == VARIANT_TRUE, "expected true\n");
5211 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
5212 ok(b == VARIANT_FALSE, "expected false\n");
5214 check_ws_preserved(doc3, NULL);
5215 check_ws_ignored(doc4, NULL);
5217 IXMLDOMDocument_Release(doc1);
5218 IXMLDOMDocument_Release(doc2);
5219 IXMLDOMDocument_Release(doc3);
5220 IXMLDOMDocument_Release(doc4);
5224 static void test_XPath(void)
5228 IXMLDOMDocument2 *doc;
5229 IXMLDOMDocument *doc2;
5230 IXMLDOMNode *rootNode;
5231 IXMLDOMNode *elem1Node;
5233 IXMLDOMNodeList *list;
5234 IXMLDOMElement *elem;
5235 IXMLDOMAttribute *attr;
5239 doc = create_document(&IID_IXMLDOMDocument2);
5242 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
5243 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5245 /* switch to XPath */
5246 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5248 /* some simple queries*/
5250 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5251 EXPECT_HR(hr, S_OK);
5253 EXPECT_LIST_LEN(list, 1);
5255 EXPECT_REF(list, 1);
5256 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5257 EXPECT_HR(hr, S_OK);
5258 EXPECT_REF(list, 1);
5259 EXPECT_REF(rootNode, 1);
5261 hr = IXMLDOMNodeList_reset(list);
5262 EXPECT_HR(hr, S_OK);
5263 expect_list_and_release(list, "E2.D1");
5265 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//c"), &list));
5266 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
5268 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//c[@type]"), &list));
5269 expect_list_and_release(list, "E3.E2.E2.D1");
5271 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
5272 /* using get_item for query results advances the position */
5273 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
5274 expect_node(node, "E2.E2.D1");
5275 IXMLDOMNode_Release(node);
5276 ole_check(IXMLDOMNodeList_nextNode(list, &node));
5277 expect_node(node, "E4.E2.D1");
5278 IXMLDOMNode_Release(node);
5279 ole_check(IXMLDOMNodeList_reset(list));
5280 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
5282 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
5283 expect_list_and_release(list, "E2.D1");
5285 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
5286 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
5287 ole_check(IXMLDOMNodeList_reset(list));
5288 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
5290 /* select an attribute */
5291 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
5292 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
5294 /* would evaluate to a number */
5295 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
5296 /* would evaluate to a boolean */
5297 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
5298 /* would evaluate to a string */
5299 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
5302 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
5303 expect_list_and_release(list, "");
5304 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
5305 expect_list_and_release(list, "");
5306 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
5307 expect_list_and_release(list, "");
5308 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//elem[0]"), &list));
5309 expect_list_and_release(list, "");
5311 /* foo undeclared in document node */
5312 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5313 /* undeclared in <root> node */
5314 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
5315 /* undeclared in <elem> node */
5316 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
5317 /* but this trick can be used */
5318 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
5319 expect_list_and_release(list, "E3.E4.E2.D1");
5321 /* it has to be declared in SelectionNamespaces */
5322 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5323 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
5325 /* now the namespace can be used */
5326 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//test:c"), &list));
5327 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5328 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
5329 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5330 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
5331 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5332 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
5333 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
5335 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
5336 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5337 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
5339 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5342 ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
5343 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
5344 if (V_VT(&var) == VT_BSTR)
5345 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
5347 /* extra attributes - same thing*/
5348 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5349 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
5350 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5352 IXMLDOMNode_Release(rootNode);
5353 IXMLDOMNode_Release(elem1Node);
5355 /* alter document with already built list */
5356 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5357 EXPECT_HR(hr, S_OK);
5358 EXPECT_LIST_LEN(list, 1);
5360 hr = IXMLDOMDocument2_get_lastChild(doc, &rootNode);
5361 EXPECT_HR(hr, S_OK);
5362 EXPECT_REF(rootNode, 1);
5365 hr = IXMLDOMDocument2_removeChild(doc, rootNode, NULL);
5366 EXPECT_HR(hr, S_OK);
5367 IXMLDOMNode_Release(rootNode);
5369 EXPECT_LIST_LEN(list, 1);
5371 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5372 EXPECT_HR(hr, S_OK);
5373 EXPECT_REF(rootNode, 1);
5375 IXMLDOMNodeList_Release(list);
5377 hr = IXMLDOMNode_get_nodeName(rootNode, &str);
5378 EXPECT_HR(hr, S_OK);
5379 ok(!lstrcmpW(str, _bstr_("root")), "got %s\n", wine_dbgstr_w(str));
5381 IXMLDOMNode_Release(rootNode);
5383 /* alter node from list and get it another time */
5384 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
5385 EXPECT_HR(hr, S_OK);
5386 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5388 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5389 EXPECT_HR(hr, S_OK);
5390 EXPECT_LIST_LEN(list, 1);
5392 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5393 EXPECT_HR(hr, S_OK);
5395 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
5396 EXPECT_HR(hr, S_OK);
5400 hr = IXMLDOMElement_setAttribute(elem, _bstr_("attrtest"), var);
5401 EXPECT_HR(hr, S_OK);
5402 IXMLDOMElement_Release(elem);
5403 IXMLDOMNode_Release(rootNode);
5405 /* now check attribute to be present */
5406 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5407 EXPECT_HR(hr, S_OK);
5409 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
5410 EXPECT_HR(hr, S_OK);
5412 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
5413 EXPECT_HR(hr, S_OK);
5414 IXMLDOMAttribute_Release(attr);
5416 IXMLDOMElement_Release(elem);
5417 IXMLDOMNode_Release(rootNode);
5419 /* and now check for attribute in original document */
5420 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
5421 EXPECT_HR(hr, S_OK);
5423 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
5424 EXPECT_HR(hr, S_OK);
5425 IXMLDOMAttribute_Release(attr);
5427 IXMLDOMElement_Release(elem);
5429 /* attach node from list to another document */
5430 doc2 = create_document(&IID_IXMLDOMDocument);
5432 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
5433 EXPECT_HR(hr, S_OK);
5434 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5436 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5437 EXPECT_HR(hr, S_OK);
5438 EXPECT_LIST_LEN(list, 1);
5440 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5441 EXPECT_HR(hr, S_OK);
5442 EXPECT_REF(rootNode, 1);
5444 hr = IXMLDOMDocument_appendChild(doc2, rootNode, NULL);
5445 EXPECT_HR(hr, S_OK);
5446 EXPECT_REF(rootNode, 1);
5447 EXPECT_REF(doc2, 1);
5448 EXPECT_REF(list, 1);
5450 EXPECT_LIST_LEN(list, 1);
5452 IXMLDOMNode_Release(rootNode);
5453 IXMLDOMNodeList_Release(list);
5454 IXMLDOMDocument_Release(doc2);
5456 IXMLDOMDocument2_Release(doc);
5460 static void test_cloneNode(void )
5462 IXMLDOMDocument *doc, *doc2;
5464 IXMLDOMNodeList *pList;
5465 IXMLDOMNamedNodeMap *mapAttr;
5466 LONG length, length1;
5467 LONG attr_cnt, attr_cnt1;
5469 IXMLDOMNode *node_clone;
5470 IXMLDOMNode *node_first;
5474 doc = create_document(&IID_IXMLDOMDocument);
5477 str = SysAllocString( szComplete4 );
5478 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
5479 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5482 hr = IXMLDOMNode_selectSingleNode(doc, _bstr_("lc/pr"), &node);
5483 ok( hr == S_OK, "ret %08x\n", hr );
5484 ok( node != NULL, "node %p\n", node );
5486 /* Check invalid parameter */
5487 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
5488 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
5491 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
5492 ok( hr == S_OK, "ret %08x\n", hr );
5493 ok( node_clone != NULL, "node %p\n", node );
5495 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
5496 ok( hr == S_OK, "ret %08x\n", hr );
5497 hr = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
5498 ok( hr == S_OK, "ret %08x\n", hr );
5499 IXMLDOMDocument_Release(doc2);
5500 IXMLDOMNode_Release(node_first);
5502 hr = IXMLDOMNode_get_childNodes(node, &pList);
5503 ok( hr == S_OK, "ret %08x\n", hr );
5505 hr = IXMLDOMNodeList_get_length(pList, &length);
5506 ok( hr == S_OK, "ret %08x\n", hr );
5507 ok(length == 1, "got %d\n", length);
5508 IXMLDOMNodeList_Release(pList);
5510 hr = IXMLDOMNode_get_attributes(node, &mapAttr);
5511 ok( hr == S_OK, "ret %08x\n", hr );
5513 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt);
5514 ok( hr == S_OK, "ret %08x\n", hr );
5515 ok(attr_cnt == 3, "got %d\n", attr_cnt);
5516 IXMLDOMNamedNodeMap_Release(mapAttr);
5518 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
5519 ok( hr == S_OK, "ret %08x\n", hr );
5521 hr = IXMLDOMNodeList_get_length(pList, &length1);
5522 ok(length1 == 1, "got %d\n", length1);
5523 ok( hr == S_OK, "ret %08x\n", hr );
5524 IXMLDOMNodeList_Release(pList);
5526 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
5527 ok( hr == S_OK, "ret %08x\n", hr );
5529 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
5530 ok( hr == S_OK, "ret %08x\n", hr );
5531 ok(attr_cnt1 == 3, "got %d\n", attr_cnt1);
5532 IXMLDOMNamedNodeMap_Release(mapAttr);
5534 ok(length == length1, "wrong Child count (%d, %d)\n", length, length1);
5535 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
5536 IXMLDOMNode_Release(node_clone);
5539 hr = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
5540 ok( hr == S_OK, "ret %08x\n", hr );
5541 ok( node_clone != NULL, "node %p\n", node );
5543 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
5544 ok(hr == S_FALSE, "ret %08x\n", hr );
5546 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
5547 ok(hr == S_OK, "ret %08x\n", hr );
5548 hr = IXMLDOMNodeList_get_length(pList, &length1);
5549 ok(hr == S_OK, "ret %08x\n", hr );
5550 ok( length1 == 0, "Length should be 0 (%d)\n", length1);
5551 IXMLDOMNodeList_Release(pList);
5553 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
5554 ok(hr == S_OK, "ret %08x\n", hr );
5555 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
5556 ok(hr == S_OK, "ret %08x\n", hr );
5557 ok(attr_cnt1 == 3, "Attribute count should be 3 (%d)\n", attr_cnt1);
5558 IXMLDOMNamedNodeMap_Release(mapAttr);
5560 ok(length != length1, "wrong Child count (%d, %d)\n", length, length1);
5561 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
5562 IXMLDOMNode_Release(node_clone);
5564 IXMLDOMNode_Release(node);
5565 IXMLDOMDocument_Release(doc);
5569 static void test_xmlTypes(void)
5571 IXMLDOMDocument *doc;
5572 IXMLDOMElement *pRoot;
5574 IXMLDOMComment *pComment;
5575 IXMLDOMElement *pElement;
5576 IXMLDOMAttribute *pAttribute;
5577 IXMLDOMNamedNodeMap *pAttribs;
5578 IXMLDOMCDATASection *pCDataSec;
5579 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
5580 IXMLDOMDocumentFragment *pDocFrag = NULL;
5581 IXMLDOMEntityReference *pEntityRef = NULL;
5583 IXMLDOMNode *pNextChild;
5587 doc = create_document(&IID_IXMLDOMDocument);
5590 pNextChild = (void*)0xdeadbeef;
5591 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
5592 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5594 pNextChild = (void*)0xdeadbeef;
5595 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
5596 ok(hr == S_FALSE, "ret %08x\n", hr );
5597 ok(pNextChild == NULL, "pDocChild not NULL\n");
5599 /* test previous Sibling */
5600 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
5601 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5603 pNextChild = (void*)0xdeadbeef;
5604 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
5605 ok(hr == S_FALSE, "ret %08x\n", hr );
5606 ok(pNextChild == NULL, "pNextChild not NULL\n");
5608 /* test get_dataType */
5609 V_VT(&v) = VT_EMPTY;
5610 hr = IXMLDOMDocument_get_dataType(doc, &v);
5611 ok(hr == S_FALSE, "ret %08x\n", hr );
5612 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5615 /* test implementation */
5616 hr = IXMLDOMDocument_get_implementation(doc, NULL);
5617 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5619 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
5620 ok(hr == S_OK, "ret %08x\n", hr );
5623 VARIANT_BOOL hasFeature = VARIANT_TRUE;
5624 BSTR sEmpty = SysAllocStringLen(NULL, 0);
5626 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
5627 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5629 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
5630 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5632 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
5633 ok(hr == S_OK, "ret %08x\n", hr );
5634 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5636 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
5637 ok(hr == S_OK, "ret %08x\n", hr );
5638 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
5640 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
5641 ok(hr == S_OK, "ret %08x\n", hr );
5642 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
5644 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
5645 ok(hr == S_OK, "ret %08x\n", hr );
5646 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5648 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
5649 ok(hr == S_OK, "ret %08x\n", hr );
5650 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5652 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
5653 ok(hr == S_OK, "ret %08x\n", hr );
5654 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5656 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
5657 ok(hr == S_OK, "ret %08x\n", hr );
5658 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5660 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
5661 ok(hr == S_OK, "ret %08x\n", hr );
5662 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5664 SysFreeString(sEmpty);
5665 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
5668 pRoot = (IXMLDOMElement*)0x1;
5669 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
5670 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5671 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
5673 pRoot = (IXMLDOMElement*)0x1;
5674 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
5675 ok(hr == E_FAIL, "ret %08x\n", hr );
5676 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
5678 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5679 ok(hr == S_OK, "ret %08x\n", hr );
5682 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5683 ok(hr == S_OK, "ret %08x\n", hr );
5687 str = SysAllocString(szComment);
5688 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
5690 ok(hr == S_OK, "ret %08x\n", hr );
5693 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
5694 ok(hr == S_OK, "ret %08x\n", hr );
5696 hr = IXMLDOMComment_get_nodeName(pComment, &str);
5697 ok(hr == S_OK, "ret %08x\n", hr );
5698 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
5701 hr = IXMLDOMComment_get_xml(pComment, &str);
5702 ok(hr == S_OK, "ret %08x\n", hr );
5703 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
5706 /* put data Tests */
5707 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
5708 ok(hr == S_OK, "ret %08x\n", hr );
5710 /* get data Tests */
5711 hr = IXMLDOMComment_get_data(pComment, &str);
5712 ok(hr == S_OK, "ret %08x\n", hr );
5713 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
5716 /* get data Tests */
5717 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
5718 ok(hr == S_OK, "ret %08x\n", hr );
5719 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
5720 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
5723 /* Confirm XML text is good */
5724 hr = IXMLDOMComment_get_xml(pComment, &str);
5725 ok(hr == S_OK, "ret %08x\n", hr );
5726 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
5729 /* Confirm we get the put_data Text back */
5730 hr = IXMLDOMComment_get_text(pComment, &str);
5731 ok(hr == S_OK, "ret %08x\n", hr );
5732 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
5735 /* test length property */
5736 hr = IXMLDOMComment_get_length(pComment, &len);
5737 ok(hr == S_OK, "ret %08x\n", hr );
5738 ok(len == 21, "expected 21 got %d\n", len);
5740 /* test substringData */
5741 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
5742 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5744 /* test substringData - Invalid offset */
5745 str = (BSTR)&szElement;
5746 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
5747 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5748 ok( str == NULL, "incorrect string\n");
5750 /* test substringData - Invalid offset */
5751 str = (BSTR)&szElement;
5752 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
5753 ok(hr == S_FALSE, "ret %08x\n", hr );
5754 ok( str == NULL, "incorrect string\n");
5756 /* test substringData - Invalid size */
5757 str = (BSTR)&szElement;
5758 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
5759 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5760 ok( str == NULL, "incorrect string\n");
5762 /* test substringData - Invalid size */
5763 str = (BSTR)&szElement;
5764 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
5765 ok(hr == S_FALSE, "ret %08x\n", hr );
5766 ok( str == NULL, "incorrect string\n");
5768 /* test substringData - Start of string */
5769 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
5770 ok(hr == S_OK, "ret %08x\n", hr );
5771 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
5774 /* test substringData - Middle of string */
5775 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
5776 ok(hr == S_OK, "ret %08x\n", hr );
5777 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
5780 /* test substringData - End of string */
5781 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
5782 ok(hr == S_OK, "ret %08x\n", hr );
5783 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
5786 /* test appendData */
5787 hr = IXMLDOMComment_appendData(pComment, NULL);
5788 ok(hr == S_OK, "ret %08x\n", hr );
5790 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
5791 ok(hr == S_OK, "ret %08x\n", hr );
5793 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
5794 ok(hr == S_OK, "ret %08x\n", hr );
5796 hr = IXMLDOMComment_get_text(pComment, &str);
5797 ok(hr == S_OK, "ret %08x\n", hr );
5798 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5801 /* test insertData */
5802 str = SysAllocStringLen(NULL, 0);
5803 hr = IXMLDOMComment_insertData(pComment, -1, str);
5804 ok(hr == S_OK, "ret %08x\n", hr );
5806 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
5807 ok(hr == S_OK, "ret %08x\n", hr );
5809 hr = IXMLDOMComment_insertData(pComment, 1000, str);
5810 ok(hr == S_OK, "ret %08x\n", hr );
5812 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
5813 ok(hr == S_OK, "ret %08x\n", hr );
5815 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
5816 ok(hr == S_OK, "ret %08x\n", hr );
5818 hr = IXMLDOMComment_insertData(pComment, 0, str);
5819 ok(hr == S_OK, "ret %08x\n", hr );
5822 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
5823 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5825 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
5826 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5828 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
5829 ok(hr == S_OK, "ret %08x\n", hr );
5831 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
5832 ok(hr == S_OK, "ret %08x\n", hr );
5834 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
5835 ok(hr == S_OK, "ret %08x\n", hr );
5837 hr = IXMLDOMComment_get_text(pComment, &str);
5838 ok(hr == S_OK, "ret %08x\n", hr );
5839 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5843 /* invalid arguments */
5844 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
5845 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5847 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
5848 ok(hr == S_OK, "ret %08x\n", hr );
5850 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
5851 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5853 hr = IXMLDOMComment_get_length(pComment, &len);
5854 ok(hr == S_OK, "ret %08x\n", hr );
5855 ok(len == 43, "expected 43 got %d\n", len);
5857 hr = IXMLDOMComment_deleteData(pComment, len, 1);
5858 ok(hr == S_OK, "ret %08x\n", hr );
5860 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
5861 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5863 /* delete from start */
5864 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
5865 ok(hr == S_OK, "ret %08x\n", hr );
5867 hr = IXMLDOMComment_get_length(pComment, &len);
5868 ok(hr == S_OK, "ret %08x\n", hr );
5869 ok(len == 38, "expected 38 got %d\n", len);
5871 hr = IXMLDOMComment_get_text(pComment, &str);
5872 ok(hr == S_OK, "ret %08x\n", hr );
5873 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5876 /* delete from end */
5877 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
5878 ok(hr == S_OK, "ret %08x\n", hr );
5880 hr = IXMLDOMComment_get_length(pComment, &len);
5881 ok(hr == S_OK, "ret %08x\n", hr );
5882 ok(len == 35, "expected 35 got %d\n", len);
5884 hr = IXMLDOMComment_get_text(pComment, &str);
5885 ok(hr == S_OK, "ret %08x\n", hr );
5886 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5889 /* delete from inside */
5890 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
5891 ok(hr == S_OK, "ret %08x\n", hr );
5893 hr = IXMLDOMComment_get_length(pComment, &len);
5894 ok(hr == S_OK, "ret %08x\n", hr );
5895 ok(len == 2, "expected 2 got %d\n", len);
5897 hr = IXMLDOMComment_get_text(pComment, &str);
5898 ok(hr == S_OK, "ret %08x\n", hr );
5899 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5902 /* delete whole data ... */
5903 hr = IXMLDOMComment_get_length(pComment, &len);
5904 ok(hr == S_OK, "ret %08x\n", hr );
5906 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5907 ok(hr == S_OK, "ret %08x\n", hr );
5908 /* ... and try again with empty string */
5909 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5910 ok(hr == S_OK, "ret %08x\n", hr );
5912 /* ::replaceData() */
5914 V_BSTR(&v) = SysAllocString(szstr1);
5915 hr = IXMLDOMComment_put_nodeValue(pComment, v);
5916 ok(hr == S_OK, "ret %08x\n", hr );
5919 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
5920 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5921 hr = IXMLDOMComment_get_text(pComment, &str);
5922 ok(hr == S_OK, "ret %08x\n", hr );
5923 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5926 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
5927 ok(hr == S_OK, "ret %08x\n", hr );
5928 hr = IXMLDOMComment_get_text(pComment, &str);
5929 ok(hr == S_OK, "ret %08x\n", hr );
5930 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5933 /* NULL pointer means delete */
5934 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
5935 ok(hr == S_OK, "ret %08x\n", hr );
5936 hr = IXMLDOMComment_get_text(pComment, &str);
5937 ok(hr == S_OK, "ret %08x\n", hr );
5938 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5941 /* empty string means delete */
5942 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
5943 ok(hr == S_OK, "ret %08x\n", hr );
5944 hr = IXMLDOMComment_get_text(pComment, &str);
5945 ok(hr == S_OK, "ret %08x\n", hr );
5946 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5949 /* zero count means insert */
5950 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
5951 ok(hr == S_OK, "ret %08x\n", hr );
5952 hr = IXMLDOMComment_get_text(pComment, &str);
5953 ok(hr == S_OK, "ret %08x\n", hr );
5954 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5957 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
5958 ok(hr == S_OK, "ret %08x\n", hr );
5960 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
5961 ok(hr == S_OK, "ret %08x\n", hr );
5962 hr = IXMLDOMComment_get_text(pComment, &str);
5963 ok(hr == S_OK, "ret %08x\n", hr );
5964 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5967 /* nonempty string, count greater than its length */
5968 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
5969 ok(hr == S_OK, "ret %08x\n", hr );
5970 hr = IXMLDOMComment_get_text(pComment, &str);
5971 ok(hr == S_OK, "ret %08x\n", hr );
5972 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5975 /* nonempty string, count less than its length */
5976 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
5977 ok(hr == S_OK, "ret %08x\n", hr );
5978 hr = IXMLDOMComment_get_text(pComment, &str);
5979 ok(hr == S_OK, "ret %08x\n", hr );
5980 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5983 IXMLDOMComment_Release(pComment);
5987 str = SysAllocString(szElement);
5988 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
5990 ok(hr == S_OK, "ret %08x\n", hr );
5993 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5994 ok(hr == S_OK, "ret %08x\n", hr );
5996 hr = IXMLDOMElement_get_nodeName(pElement, &str);
5997 ok(hr == S_OK, "ret %08x\n", hr );
5998 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
6001 hr = IXMLDOMElement_get_xml(pElement, &str);
6002 ok(hr == S_OK, "ret %08x\n", hr );
6003 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
6007 pAttribute = (IXMLDOMAttribute*)0x1;
6008 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
6009 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6010 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
6012 pAttribute = (IXMLDOMAttribute*)0x1;
6013 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
6014 ok(hr == E_FAIL, "ret %08x\n", hr );
6015 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
6017 str = SysAllocString(szAttribute);
6018 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
6020 ok(hr == S_OK, "ret %08x\n", hr );
6023 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
6025 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
6026 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6028 pNextChild = (IXMLDOMNode *)0x1;
6029 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
6030 ok(hr == S_FALSE, "ret %08x\n", hr );
6031 ok(pNextChild == NULL, "pNextChild not NULL\n");
6033 /* test Previous Sibling*/
6034 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
6035 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6037 pNextChild = (IXMLDOMNode *)0x1;
6038 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
6039 ok(hr == S_FALSE, "ret %08x\n", hr );
6040 ok(pNextChild == NULL, "pNextChild not NULL\n");
6042 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
6043 ok(hr == E_FAIL, "ret %08x\n", hr );
6044 ok(pNewChild == NULL, "pNewChild not NULL\n");
6046 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
6047 ok(hr == S_OK, "ret %08x\n", hr );
6050 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
6051 ok(hr == S_OK, "ret %08x\n", hr );
6053 IXMLDOMNamedNodeMap_Release(pAttribs);
6056 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6057 ok(hr == S_OK, "ret %08x\n", hr );
6058 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
6062 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6063 ok(hr == S_OK, "ret %08x\n", hr );
6064 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
6067 /* test name property */
6068 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
6069 ok(hr == S_OK, "ret %08x\n", hr );
6070 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
6073 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
6074 ok(hr == S_OK, "ret %08x\n", hr );
6075 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
6078 IXMLDOMAttribute_Release(pAttribute);
6080 /* Check Element again with the Add Attribute*/
6081 hr = IXMLDOMElement_get_xml(pElement, &str);
6082 ok(hr == S_OK, "ret %08x\n", hr );
6083 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
6087 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
6088 ok(hr == S_OK, "ret %08x\n", hr );
6090 hr = IXMLDOMElement_get_xml(pElement, &str);
6091 ok(hr == S_OK, "ret %08x\n", hr );
6092 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
6095 /* Test for reversible escaping */
6096 str = SysAllocString( szStrangeChars );
6097 hr = IXMLDOMElement_put_text(pElement, str);
6098 ok(hr == S_OK, "ret %08x\n", hr );
6099 SysFreeString( str );
6101 hr = IXMLDOMElement_get_xml(pElement, &str);
6102 ok(hr == S_OK, "ret %08x\n", hr );
6103 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
6106 hr = IXMLDOMElement_get_text(pElement, &str);
6107 ok(hr == S_OK, "ret %08x\n", hr );
6108 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
6111 IXMLDOMElement_Release(pElement);
6115 str = SysAllocString(szCData);
6116 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
6117 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6119 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
6121 ok(hr == S_OK, "ret %08x\n", hr );
6124 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
6129 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
6130 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
6132 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
6133 ok(hr == S_OK, "ret %08x\n", hr );
6135 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
6136 ok(hr == S_OK, "ret %08x\n", hr );
6137 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
6140 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6141 ok(hr == S_OK, "ret %08x\n", hr );
6142 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
6145 /* test lastChild */
6146 pNextChild = (IXMLDOMNode*)0x1;
6147 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
6148 ok(hr == S_FALSE, "ret %08x\n", hr );
6149 ok(pNextChild == NULL, "pNextChild not NULL\n");
6151 /* put data Tests */
6152 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
6153 ok(hr == S_OK, "ret %08x\n", hr );
6155 /* Confirm XML text is good */
6156 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6157 ok(hr == S_OK, "ret %08x\n", hr );
6158 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
6161 /* Confirm we get the put_data Text back */
6162 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6163 ok(hr == S_OK, "ret %08x\n", hr );
6164 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6167 /* test length property */
6168 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6169 ok(hr == S_OK, "ret %08x\n", hr );
6170 ok(len == 21, "expected 21 got %d\n", len);
6172 /* test get nodeValue */
6173 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
6174 ok(hr == S_OK, "ret %08x\n", hr );
6175 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
6176 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6180 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
6181 ok(hr == S_OK, "ret %08x\n", hr );
6182 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6185 /* test substringData */
6186 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
6187 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6189 /* test substringData - Invalid offset */
6190 str = (BSTR)&szElement;
6191 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
6192 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6193 ok( str == NULL, "incorrect string\n");
6195 /* test substringData - Invalid offset */
6196 str = (BSTR)&szElement;
6197 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
6198 ok(hr == S_FALSE, "ret %08x\n", hr );
6199 ok( str == NULL, "incorrect string\n");
6201 /* test substringData - Invalid size */
6202 str = (BSTR)&szElement;
6203 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
6204 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6205 ok( str == NULL, "incorrect string\n");
6207 /* test substringData - Invalid size */
6208 str = (BSTR)&szElement;
6209 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
6210 ok(hr == S_FALSE, "ret %08x\n", hr );
6211 ok( str == NULL, "incorrect string\n");
6213 /* test substringData - Start of string */
6214 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
6215 ok(hr == S_OK, "ret %08x\n", hr );
6216 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
6219 /* test substringData - Middle of string */
6220 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
6221 ok(hr == S_OK, "ret %08x\n", hr );
6222 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
6225 /* test substringData - End of string */
6226 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
6227 ok(hr == S_OK, "ret %08x\n", hr );
6228 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
6231 /* test appendData */
6232 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
6233 ok(hr == S_OK, "ret %08x\n", hr );
6235 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
6236 ok(hr == S_OK, "ret %08x\n", hr );
6238 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
6239 ok(hr == S_OK, "ret %08x\n", hr );
6241 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6242 ok(hr == S_OK, "ret %08x\n", hr );
6243 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6246 /* test insertData */
6247 str = SysAllocStringLen(NULL, 0);
6248 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
6249 ok(hr == S_OK, "ret %08x\n", hr );
6251 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
6252 ok(hr == S_OK, "ret %08x\n", hr );
6254 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
6255 ok(hr == S_OK, "ret %08x\n", hr );
6257 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
6258 ok(hr == S_OK, "ret %08x\n", hr );
6260 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
6261 ok(hr == S_OK, "ret %08x\n", hr );
6263 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
6264 ok(hr == S_OK, "ret %08x\n", hr );
6267 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
6268 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6270 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
6271 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6273 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
6274 ok(hr == S_OK, "ret %08x\n", hr );
6276 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
6277 ok(hr == S_OK, "ret %08x\n", hr );
6279 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
6280 ok(hr == S_OK, "ret %08x\n", hr );
6282 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6283 ok(hr == S_OK, "ret %08x\n", hr );
6284 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6288 /* invalid arguments */
6289 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
6290 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6292 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
6293 ok(hr == S_OK, "ret %08x\n", hr );
6295 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
6296 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6298 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6299 ok(hr == S_OK, "ret %08x\n", hr );
6300 ok(len == 43, "expected 43 got %d\n", len);
6302 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
6303 ok(hr == S_OK, "ret %08x\n", hr );
6305 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
6306 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6308 /* delete from start */
6309 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
6310 ok(hr == S_OK, "ret %08x\n", hr );
6312 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6313 ok(hr == S_OK, "ret %08x\n", hr );
6314 ok(len == 38, "expected 38 got %d\n", len);
6316 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6317 ok(hr == S_OK, "ret %08x\n", hr );
6318 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6321 /* delete from end */
6322 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
6323 ok(hr == S_OK, "ret %08x\n", hr );
6325 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6326 ok(hr == S_OK, "ret %08x\n", hr );
6327 ok(len == 35, "expected 35 got %d\n", len);
6329 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6330 ok(hr == S_OK, "ret %08x\n", hr );
6331 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6334 /* delete from inside */
6335 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
6336 ok(hr == S_OK, "ret %08x\n", hr );
6338 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6339 ok(hr == S_OK, "ret %08x\n", hr );
6340 ok(len == 2, "expected 2 got %d\n", len);
6342 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6343 ok(hr == S_OK, "ret %08x\n", hr );
6344 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6347 /* delete whole data ... */
6348 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6349 ok(hr == S_OK, "ret %08x\n", hr );
6351 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6352 ok(hr == S_OK, "ret %08x\n", hr );
6354 /* ... and try again with empty string */
6355 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6356 ok(hr == S_OK, "ret %08x\n", hr );
6358 /* ::replaceData() */
6360 V_BSTR(&v) = SysAllocString(szstr1);
6361 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
6362 ok(hr == S_OK, "ret %08x\n", hr );
6365 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
6366 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6367 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6368 ok(hr == S_OK, "ret %08x\n", hr );
6369 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6372 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
6373 ok(hr == S_OK, "ret %08x\n", hr );
6374 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6375 ok(hr == S_OK, "ret %08x\n", hr );
6376 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6379 /* NULL pointer means delete */
6380 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
6381 ok(hr == S_OK, "ret %08x\n", hr );
6382 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6383 ok(hr == S_OK, "ret %08x\n", hr );
6384 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6387 /* empty string means delete */
6388 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
6389 ok(hr == S_OK, "ret %08x\n", hr );
6390 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6391 ok(hr == S_OK, "ret %08x\n", hr );
6392 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6395 /* zero count means insert */
6396 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
6397 ok(hr == S_OK, "ret %08x\n", hr );
6398 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6399 ok(hr == S_OK, "ret %08x\n", hr );
6400 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6403 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
6404 ok(hr == S_OK, "ret %08x\n", hr );
6406 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
6407 ok(hr == S_OK, "ret %08x\n", hr );
6408 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6409 ok(hr == S_OK, "ret %08x\n", hr );
6410 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6413 /* nonempty string, count greater than its length */
6414 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
6415 ok(hr == S_OK, "ret %08x\n", hr );
6416 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6417 ok(hr == S_OK, "ret %08x\n", hr );
6418 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6421 /* nonempty string, count less than its length */
6422 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
6423 ok(hr == S_OK, "ret %08x\n", hr );
6424 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6425 ok(hr == S_OK, "ret %08x\n", hr );
6426 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6429 IXMLDOMCDATASection_Release(pCDataSec);
6432 /* Document Fragments */
6433 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
6434 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6436 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
6437 ok(hr == S_OK, "ret %08x\n", hr );
6442 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
6443 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6445 node = (IXMLDOMNode *)0x1;
6446 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
6447 ok(hr == S_FALSE, "ret %08x\n", hr );
6448 ok(node == NULL, "expected NULL, got %p\n", node);
6450 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
6451 ok(hr == S_OK, "ret %08x\n", hr );
6453 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
6454 ok(hr == S_OK, "ret %08x\n", hr );
6455 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
6458 /* test next Sibling*/
6459 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
6460 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6462 node = (IXMLDOMNode *)0x1;
6463 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
6464 ok(hr == S_FALSE, "ret %08x\n", hr );
6465 ok(node == NULL, "next sibling not NULL\n");
6467 /* test Previous Sibling*/
6468 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
6469 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6471 node = (IXMLDOMNode *)0x1;
6472 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
6473 ok(hr == S_FALSE, "ret %08x\n", hr );
6474 ok(node == NULL, "previous sibling not NULL\n");
6476 IXMLDOMDocumentFragment_Release(pDocFrag);
6479 /* Entity References */
6480 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
6481 ok(hr == E_FAIL, "ret %08x\n", hr );
6482 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
6483 ok(hr == E_FAIL, "ret %08x\n", hr );
6485 str = SysAllocString(szEntityRef);
6486 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
6487 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6489 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
6491 ok(hr == S_OK, "ret %08x\n", hr );
6494 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
6495 ok(hr == S_OK, "ret %08x\n", hr );
6498 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
6499 ok(hr == S_OK, "ret %08x\n", hr );
6500 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
6503 IXMLDOMEntityReference_Release(pEntityRef);
6506 IXMLDOMElement_Release( pRoot );
6510 IXMLDOMDocument_Release(doc);
6515 static void test_nodeTypeTests( void )
6517 IXMLDOMDocument *doc = NULL;
6518 IXMLDOMElement *pRoot;
6519 IXMLDOMElement *pElement;
6522 doc = create_document(&IID_IXMLDOMDocument);
6525 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
6526 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6528 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
6529 ok(hr == S_OK, "ret %08x\n", hr );
6532 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
6533 ok(hr == S_OK, "ret %08x\n", hr );
6536 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
6537 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6540 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
6541 ok(hr == E_FAIL, "ret %08x\n", hr );
6544 * The name passed into put_dataType is case-insensitive. So many of the names
6545 * have been changed to reflect this.
6548 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
6549 ok(hr == S_OK, "ret %08x\n", hr );
6552 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6554 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
6555 ok(hr == S_OK, "ret %08x\n", hr );
6557 IXMLDOMElement_Release(pElement);
6561 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
6562 ok(hr == S_OK, "ret %08x\n", hr );
6565 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6567 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
6568 ok(hr == S_OK, "ret %08x\n", hr );
6570 IXMLDOMElement_Release(pElement);
6574 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
6575 ok(hr == S_OK, "ret %08x\n", hr );
6578 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6580 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
6581 ok(hr == S_OK, "ret %08x\n", hr );
6583 IXMLDOMElement_Release(pElement);
6587 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
6588 ok(hr == S_OK, "ret %08x\n", hr );
6591 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6593 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
6594 ok(hr == S_OK, "ret %08x\n", hr );
6596 IXMLDOMElement_Release(pElement);
6600 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
6601 ok(hr == S_OK, "ret %08x\n", hr );
6604 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6606 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
6607 ok(hr == S_OK, "ret %08x\n", hr );
6609 IXMLDOMElement_Release(pElement);
6613 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
6614 ok(hr == S_OK, "ret %08x\n", hr );
6617 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6619 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
6620 ok(hr == S_OK, "ret %08x\n", hr );
6622 IXMLDOMElement_Release(pElement);
6626 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
6627 ok(hr == S_OK, "ret %08x\n", hr );
6630 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6632 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
6633 ok(hr == S_OK, "ret %08x\n", hr );
6635 IXMLDOMElement_Release(pElement);
6639 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
6640 ok(hr == S_OK, "ret %08x\n", hr );
6643 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6645 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
6646 ok(hr == S_OK, "ret %08x\n", hr );
6648 IXMLDOMElement_Release(pElement);
6652 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
6653 ok(hr == S_OK, "ret %08x\n", hr );
6656 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6658 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
6659 ok(hr == S_OK, "ret %08x\n", hr );
6661 IXMLDOMElement_Release(pElement);
6665 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
6666 ok(hr == S_OK, "ret %08x\n", hr );
6669 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6671 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
6672 ok(hr == S_OK, "ret %08x\n", hr );
6674 IXMLDOMElement_Release(pElement);
6678 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
6679 ok(hr == S_OK, "ret %08x\n", hr );
6682 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6684 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
6685 ok(hr == S_OK, "ret %08x\n", hr );
6687 IXMLDOMElement_Release(pElement);
6691 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
6692 ok(hr == S_OK, "ret %08x\n", hr );
6695 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6697 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
6698 ok(hr == S_OK, "ret %08x\n", hr );
6700 IXMLDOMElement_Release(pElement);
6704 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
6705 ok(hr == S_OK, "ret %08x\n", hr );
6708 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6710 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
6711 ok(hr == S_OK, "ret %08x\n", hr );
6713 IXMLDOMElement_Release(pElement);
6717 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
6718 ok(hr == S_OK, "ret %08x\n", hr );
6721 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6723 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
6724 ok(hr == S_OK, "ret %08x\n", hr );
6726 IXMLDOMElement_Release(pElement);
6730 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
6731 ok(hr == S_OK, "ret %08x\n", hr );
6734 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6736 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
6737 ok(hr == S_OK, "ret %08x\n", hr );
6739 IXMLDOMElement_Release(pElement);
6743 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
6744 ok(hr == S_OK, "ret %08x\n", hr );
6747 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6749 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
6750 ok(hr == S_OK, "ret %08x\n", hr );
6752 IXMLDOMElement_Release(pElement);
6756 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
6757 ok(hr == S_OK, "ret %08x\n", hr );
6760 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6762 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
6763 ok(hr == S_OK, "ret %08x\n", hr );
6765 IXMLDOMElement_Release(pElement);
6769 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
6770 ok(hr == S_OK, "ret %08x\n", hr );
6773 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6775 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
6776 ok(hr == S_OK, "ret %08x\n", hr );
6778 IXMLDOMElement_Release(pElement);
6782 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
6783 ok(hr == S_OK, "ret %08x\n", hr );
6786 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6788 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
6789 ok(hr == S_OK, "ret %08x\n", hr );
6791 IXMLDOMElement_Release(pElement);
6795 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
6796 ok(hr == S_OK, "ret %08x\n", hr );
6799 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6801 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
6802 ok(hr == S_OK, "ret %08x\n", hr );
6804 IXMLDOMElement_Release(pElement);
6808 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
6809 ok(hr == S_OK, "ret %08x\n", hr );
6812 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6814 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
6815 ok(hr == S_OK, "ret %08x\n", hr );
6817 IXMLDOMElement_Release(pElement);
6821 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
6822 ok(hr == S_OK, "ret %08x\n", hr );
6825 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6827 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
6828 ok(hr == S_OK, "ret %08x\n", hr );
6830 IXMLDOMElement_Release(pElement);
6833 /* Check changing types */
6834 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
6835 ok(hr == S_OK, "ret %08x\n", hr );
6838 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6840 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
6841 ok(hr == S_OK, "ret %08x\n", hr );
6843 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
6844 ok(hr == S_OK, "ret %08x\n", hr );
6846 IXMLDOMElement_Release(pElement);
6849 IXMLDOMElement_Release(pRoot);
6853 IXMLDOMDocument_Release(doc);
6858 static void test_save(void)
6860 IXMLDOMDocument *doc, *doc2;
6861 IXMLDOMElement *root;
6863 BSTR sOrig, sNew, filename;
6869 doc = create_document(&IID_IXMLDOMDocument);
6872 doc2 = create_document(&IID_IXMLDOMDocument);
6875 IXMLDOMDocument_Release(doc);
6879 /* save to IXMLDOMDocument */
6880 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
6881 EXPECT_HR(hr, S_OK);
6883 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
6884 EXPECT_HR(hr, S_OK);
6886 V_VT(&vDoc) = VT_UNKNOWN;
6887 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
6889 hr = IXMLDOMDocument_save(doc, vDoc);
6890 EXPECT_HR(hr, S_OK);
6892 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
6893 EXPECT_HR(hr, S_OK);
6895 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
6896 EXPECT_HR(hr, S_OK);
6898 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as original\n");
6900 SysFreeString(sOrig);
6901 SysFreeString(sNew);
6903 IXMLDOMElement_Release(root);
6904 IXMLDOMDocument_Release(doc2);
6907 V_VT(&file) = VT_BSTR;
6908 V_BSTR(&file) = _bstr_("test.xml");
6910 hr = IXMLDOMDocument_save(doc, file);
6911 EXPECT_HR(hr, S_OK);
6913 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
6914 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
6915 if(hfile == INVALID_HANDLE_VALUE) return;
6917 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
6918 ok(read != 0, "could not read file\n");
6919 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
6922 DeleteFile("test.xml");
6924 /* save to path VT_BSTR | VT_BYREF */
6925 filename = _bstr_("test.xml");
6926 V_VT(&file) = VT_BSTR | VT_BYREF;
6927 V_BSTRREF(&file) = &filename;
6929 hr = IXMLDOMDocument_save(doc, file);
6930 EXPECT_HR(hr, S_OK);
6932 IXMLDOMDocument_Release(doc);
6934 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
6935 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
6936 if(hfile == INVALID_HANDLE_VALUE) return;
6938 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
6939 ok(read != 0, "could not read file\n");
6940 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
6943 DeleteFile("test.xml");
6947 static void test_testTransforms(void)
6949 IXMLDOMDocument *doc, *docSS;
6955 doc = create_document(&IID_IXMLDOMDocument);
6958 docSS = create_document(&IID_IXMLDOMDocument);
6961 IXMLDOMDocument_Release(doc);
6965 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
6966 ok(hr == S_OK, "ret %08x\n", hr );
6968 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
6969 ok(hr == S_OK, "ret %08x\n", hr );
6971 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
6972 ok(hr == S_OK, "ret %08x\n", hr );
6977 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
6978 ok(hr == S_OK, "ret %08x\n", hr );
6979 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
6980 SysFreeString(bOut);
6982 IXMLDOMNode_Release(pNode);
6985 IXMLDOMDocument_Release(docSS);
6986 IXMLDOMDocument_Release(doc);
6991 static void test_Namespaces(void)
6993 IXMLDOMDocument *doc;
6995 IXMLDOMNode *pNode2 = NULL;
6999 static const CHAR szNamespacesXML[] =
7000 "<?xml version=\"1.0\"?>\n"
7001 "<XMI xmi.version=\"1.1\" xmlns:Model=\"http://omg.org/mof.Model/1.3\">"
7003 " <Model:Package name=\"WinePackage\" />"
7007 doc = create_document(&IID_IXMLDOMDocument);
7010 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
7011 ok(hr == S_OK, "ret %08x\n", hr );
7012 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7014 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("//XMI.content"), &pNode );
7015 ok(hr == S_OK, "ret %08x\n", hr );
7018 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
7019 ok( hr == S_OK, "ret %08x\n", hr );
7020 ok( pNode2 != NULL, "pNode2 == NULL\n");
7022 /* Test get_prefix */
7023 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
7024 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
7025 /* NOTE: Need to test that arg2 gets cleared on Error. */
7027 hr = IXMLDOMNode_get_prefix(pNode2, &str);
7028 ok( hr == S_OK, "ret %08x\n", hr );
7029 ok( !lstrcmpW( str, _bstr_("Model")), "incorrect prefix string\n");
7032 hr = IXMLDOMNode_get_nodeName(pNode2, &str);
7033 ok( hr == S_OK, "ret %08x\n", hr );
7034 todo_wine ok( !lstrcmpW( str, _bstr_("Model:Package")), "incorrect nodeName string\n");
7037 /* Test get_namespaceURI */
7038 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
7039 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
7040 /* NOTE: Need to test that arg2 gets cleared on Error. */
7042 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
7043 ok( hr == S_OK, "ret %08x\n", hr );
7044 ok( !lstrcmpW( str, _bstr_("http://omg.org/mof.Model/1.3")), "incorrect namespaceURI string\n");
7047 IXMLDOMNode_Release(pNode2);
7048 IXMLDOMNode_Release(pNode);
7051 IXMLDOMDocument_Release(doc);
7056 static void test_FormattingXML(void)
7058 IXMLDOMDocument *doc;
7059 IXMLDOMElement *pElement;
7063 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
7064 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
7066 doc = create_document(&IID_IXMLDOMDocument);
7069 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
7070 ok(hr == S_OK, "ret %08x\n", hr );
7071 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7073 if(bSucc == VARIANT_TRUE)
7075 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
7076 ok(hr == S_OK, "ret %08x\n", hr );
7079 hr = IXMLDOMElement_get_xml(pElement, &str);
7080 ok(hr == S_OK, "ret %08x\n", hr );
7081 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
7084 IXMLDOMElement_Release(pElement);
7088 IXMLDOMDocument_Release(doc);
7093 typedef struct _nodetypedvalue_t {
7096 const char *value; /* value in string format */
7099 static const nodetypedvalue_t get_nodetypedvalue[] = {
7100 { "root/string", VT_BSTR, "Wine" },
7101 { "root/string2", VT_BSTR, "String" },
7102 { "root/number", VT_BSTR, "12.44" },
7103 { "root/number2", VT_BSTR, "-3.71e3" },
7104 { "root/int", VT_I4, "-13" },
7105 { "root/fixed", VT_CY, "7322.9371" },
7106 { "root/bool", VT_BOOL, "-1" },
7107 { "root/datetime", VT_DATE, "40135.14" },
7108 { "root/datetimetz",VT_DATE, "37813.59" },
7109 { "root/date", VT_DATE, "665413" },
7110 { "root/time", VT_DATE, "0.5813889" },
7111 { "root/timetz", VT_DATE, "1.112512" },
7112 { "root/i1", VT_I1, "-13" },
7113 { "root/i2", VT_I2, "31915" },
7114 { "root/i4", VT_I4, "-312232" },
7115 { "root/ui1", VT_UI1, "123" },
7116 { "root/ui2", VT_UI2, "48282" },
7117 { "root/ui4", VT_UI4, "949281" },
7118 { "root/r4", VT_R4, "213124" },
7119 { "root/r8", VT_R8, "0.412" },
7120 { "root/float", VT_R8, "41221.421" },
7121 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
7122 { "root/binbase64", VT_ARRAY|VT_UI1, "base64 test" },
7123 { "root/binbase64_1", VT_ARRAY|VT_UI1, "base64 test" },
7124 { "root/binbase64_2", VT_ARRAY|VT_UI1, "base64 test" },
7128 static void test_nodeTypedValue(void)
7130 const nodetypedvalue_t *entry = get_nodetypedvalue;
7131 IXMLDOMDocumentType *doctype, *doctype2;
7132 IXMLDOMProcessingInstruction *pi;
7133 IXMLDOMDocumentFragment *frag;
7134 IXMLDOMDocument *doc, *doc2;
7135 IXMLDOMCDATASection *cdata;
7136 IXMLDOMComment *comment;
7142 doc = create_document(&IID_IXMLDOMDocument);
7146 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
7147 ok(hr == S_OK, "ret %08x\n", hr );
7148 ok(b == VARIANT_TRUE, "got %d\n", b);
7150 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
7151 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7153 V_VT(&value) = VT_BSTR;
7154 V_BSTR(&value) = NULL;
7155 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
7156 ok(hr == S_FALSE, "ret %08x\n", hr );
7157 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7159 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
7160 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7162 V_VT(&value) = VT_EMPTY;
7163 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
7164 ok(hr == S_FALSE, "ret %08x\n", hr );
7165 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7167 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
7168 ok(hr == S_OK, "ret %08x\n", hr );
7170 V_VT(&value) = VT_BSTR;
7171 V_BSTR(&value) = NULL;
7172 hr = IXMLDOMNode_get_nodeValue(node, &value);
7173 ok(hr == S_FALSE, "ret %08x\n", hr );
7174 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7176 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
7177 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7179 IXMLDOMNode_Release(node);
7181 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
7182 ok(hr == S_OK, "ret %08x\n", hr );
7184 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
7186 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7187 ok(hr == S_OK, "ret %08x\n", hr );
7188 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
7189 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
7190 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
7191 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
7192 VariantClear(&value);
7193 IXMLDOMNode_Release(node);
7196 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("foo"), _bstr_("value"), &pi);
7197 ok(hr == S_OK, "ret %08x\n", hr );
7199 V_VT(&value) = VT_NULL;
7200 V_BSTR(&value) = (void*)0xdeadbeef;
7201 hr = IXMLDOMProcessingInstruction_get_nodeTypedValue(pi, &value);
7202 ok(hr == S_OK, "ret %08x\n", hr );
7203 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7204 ok(!lstrcmpW(V_BSTR(&value), _bstr_("value")), "got wrong value\n");
7205 IXMLDOMProcessingInstruction_Release(pi);
7206 VariantClear(&value);
7209 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("[1]*2=3; &gee that's not right!"), &cdata);
7210 ok(hr == S_OK, "ret %08x\n", hr );
7212 V_VT(&value) = VT_NULL;
7213 V_BSTR(&value) = (void*)0xdeadbeef;
7214 hr = IXMLDOMCDATASection_get_nodeTypedValue(cdata, &value);
7215 ok(hr == S_OK, "ret %08x\n", hr );
7216 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7217 ok(!lstrcmpW(V_BSTR(&value), _bstr_("[1]*2=3; &gee that's not right!")), "got wrong value\n");
7218 IXMLDOMCDATASection_Release(cdata);
7219 VariantClear(&value);
7222 hr = IXMLDOMDocument_createComment(doc, _bstr_("comment"), &comment);
7223 ok(hr == S_OK, "ret %08x\n", hr );
7225 V_VT(&value) = VT_NULL;
7226 V_BSTR(&value) = (void*)0xdeadbeef;
7227 hr = IXMLDOMComment_get_nodeTypedValue(comment, &value);
7228 ok(hr == S_OK, "ret %08x\n", hr );
7229 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7230 ok(!lstrcmpW(V_BSTR(&value), _bstr_("comment")), "got wrong value\n");
7231 IXMLDOMComment_Release(comment);
7232 VariantClear(&value);
7235 hr = IXMLDOMDocument_createDocumentFragment(doc, &frag);
7236 ok(hr == S_OK, "ret %08x\n", hr );
7238 V_VT(&value) = VT_EMPTY;
7239 hr = IXMLDOMDocumentFragment_get_nodeTypedValue(frag, &value);
7240 ok(hr == S_FALSE, "ret %08x\n", hr );
7241 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7242 IXMLDOMDocumentFragment_Release(frag);
7245 doc2 = create_document(&IID_IXMLDOMDocument);
7248 hr = IXMLDOMDocument_loadXML(doc2, _bstr_(szEmailXML), &b);
7249 ok(hr == S_OK, "ret %08x\n", hr );
7250 ok(b == VARIANT_TRUE, "got %d\n", b);
7252 EXPECT_REF(doc2, 1);
7254 hr = IXMLDOMDocument_get_doctype(doc2, &doctype);
7255 ok(hr == S_OK, "ret %08x\n", hr );
7257 EXPECT_REF(doc2, 1);
7258 todo_wine EXPECT_REF(doctype, 2);
7261 V_VT(&value) = VT_EMPTY;
7262 hr = IXMLDOMDocumentType_get_nodeTypedValue(doctype, &value);
7263 ok(hr == S_FALSE, "ret %08x\n", hr );
7264 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7267 hr = IXMLDOMDocument_get_doctype(doc2, &doctype2);
7268 ok(hr == S_OK, "ret %08x\n", hr );
7269 ok(doctype != doctype2, "got %p, was %p\n", doctype2, doctype);
7271 IXMLDOMDocumentType_Release(doctype2);
7272 IXMLDOMDocumentType_Release(doctype);
7274 IXMLDOMDocument_Release(doc2);
7278 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
7279 ok(hr == S_OK, "ret %08x\n", hr );
7281 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7282 ok(hr == S_OK, "ret %08x\n", hr );
7283 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
7285 if (entry->type == (VT_ARRAY|VT_UI1))
7287 ok(V_ARRAY(&value)->rgsabound[0].cElements == strlen(entry->value),
7288 "incorrect array size %d\n", V_ARRAY(&value)->rgsabound[0].cElements);
7291 if (entry->type != VT_BSTR)
7293 if (entry->type == VT_DATE ||
7294 entry->type == VT_R8 ||
7295 entry->type == VT_CY)
7297 if (entry->type == VT_DATE)
7299 hr = VariantChangeType(&value, &value, 0, VT_R4);
7300 ok(hr == S_OK, "ret %08x\n", hr );
7302 hr = VariantChangeTypeEx(&value, &value,
7303 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
7304 VARIANT_NOUSEROVERRIDE, VT_BSTR);
7305 ok(hr == S_OK, "ret %08x\n", hr );
7309 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
7310 ok(hr == S_OK, "ret %08x\n", hr );
7313 /* for byte array from VT_ARRAY|VT_UI1 it's not a WCHAR buffer */
7314 if (entry->type == (VT_ARRAY|VT_UI1))
7316 ok(!memcmp( V_BSTR(&value), entry->value, strlen(entry->value)),
7317 "expected %s\n", entry->value);
7320 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7321 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7324 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7325 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7327 VariantClear( &value );
7328 IXMLDOMNode_Release(node);
7333 IXMLDOMDocument_Release(doc);
7337 static void test_TransformWithLoadingLocalFile(void)
7339 IXMLDOMDocument *doc;
7340 IXMLDOMDocument *xsl;
7346 char lpPathBuffer[MAX_PATH];
7349 /* Create a Temp File. */
7350 GetTempPathA(MAX_PATH, lpPathBuffer);
7351 strcat(lpPathBuffer, "customers.xml" );
7353 file = CreateFileA(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
7354 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
7355 if(file == INVALID_HANDLE_VALUE)
7358 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
7361 /* Correct path to not include a escape character. */
7362 for(i=0; i < strlen(lpPathBuffer); i++)
7364 if(lpPathBuffer[i] == '\\')
7365 lpPathBuffer[i] = '/';
7368 doc = create_document(&IID_IXMLDOMDocument);
7371 xsl = create_document(&IID_IXMLDOMDocument);
7374 IXMLDOMDocument2_Release(doc);
7378 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
7379 ok(hr == S_OK, "ret %08x\n", hr );
7380 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7381 if(bSucc == VARIANT_TRUE)
7384 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
7385 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
7386 BSTR sFileName = _bstr_(lpPathBuffer);
7387 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
7389 sXSL = SysAllocStringLen(NULL, nLegnth);
7390 lstrcpyW(sXSL, sPart1);
7391 lstrcatW(sXSL, sFileName);
7392 lstrcatW(sXSL, sPart2);
7394 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
7395 ok(hr == S_OK, "ret %08x\n", hr );
7396 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7397 if(bSucc == VARIANT_TRUE)
7401 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
7402 ok(hr == S_OK, "ret %08x\n", hr );
7405 /* This will load the temp file via the XSL */
7406 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
7407 ok(hr == S_OK, "ret %08x\n", hr );
7410 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
7411 SysFreeString(sResult);
7414 IXMLDOMNode_Release(pNode);
7418 SysFreeString(sXSL);
7421 IXMLDOMDocument_Release(doc);
7422 IXMLDOMDocument_Release(xsl);
7424 DeleteFile(lpPathBuffer);
7428 static void test_put_nodeValue(void)
7430 static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
7431 IXMLDOMDocument *doc;
7433 IXMLDOMEntityReference *entityref;
7434 IXMLDOMAttribute *attr;
7439 doc = create_document(&IID_IXMLDOMDocument);
7442 /* test for unsupported types */
7444 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
7445 ok(hr == S_OK, "ret %08x\n", hr );
7446 V_VT(&data) = VT_BSTR;
7447 V_BSTR(&data) = _bstr_("one two three");
7448 hr = IXMLDOMNode_put_nodeValue(node, data);
7449 ok(hr == E_FAIL, "ret %08x\n", hr );
7450 IXMLDOMNode_Release(node);
7452 /* NODE_DOCUMENT_FRAGMENT */
7453 V_VT(&type) = VT_I1;
7454 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
7455 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
7456 ok(hr == S_OK, "ret %08x\n", hr );
7457 V_VT(&data) = VT_BSTR;
7458 V_BSTR(&data) = _bstr_("one two three");
7459 hr = IXMLDOMNode_put_nodeValue(node, data);
7460 ok(hr == E_FAIL, "ret %08x\n", hr );
7461 IXMLDOMNode_Release(node);
7464 V_VT(&type) = VT_I1;
7465 V_I1(&type) = NODE_ELEMENT;
7466 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
7467 ok(hr == S_OK, "ret %08x\n", hr );
7468 V_VT(&data) = VT_BSTR;
7469 V_BSTR(&data) = _bstr_("one two three");
7470 hr = IXMLDOMNode_put_nodeValue(node, data);
7471 ok(hr == E_FAIL, "ret %08x\n", hr );
7472 IXMLDOMNode_Release(node);
7474 /* NODE_ENTITY_REFERENCE */
7475 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
7476 ok(hr == S_OK, "ret %08x\n", hr );
7478 V_VT(&data) = VT_BSTR;
7479 V_BSTR(&data) = _bstr_("one two three");
7480 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
7481 ok(hr == E_FAIL, "ret %08x\n", hr );
7483 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
7484 ok(hr == S_OK, "ret %08x\n", hr );
7485 V_VT(&data) = VT_BSTR;
7486 V_BSTR(&data) = _bstr_("one two three");
7487 hr = IXMLDOMNode_put_nodeValue(node, data);
7488 ok(hr == E_FAIL, "ret %08x\n", hr );
7489 IXMLDOMNode_Release(node);
7490 IXMLDOMEntityReference_Release(entityref);
7492 /* supported types */
7493 hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
7494 ok(hr == S_OK, "ret %08x\n", hr );
7495 V_VT(&data) = VT_BSTR;
7496 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
7497 hr = IXMLDOMText_put_nodeValue(text, data);
7498 ok(hr == S_OK, "ret %08x\n", hr );
7499 IXMLDOMText_Release(text);
7501 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7502 ok(hr == S_OK, "ret %08x\n", hr );
7503 V_VT(&data) = VT_BSTR;
7504 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
7505 hr = IXMLDOMAttribute_put_nodeValue(attr, data);
7506 ok(hr == S_OK, "ret %08x\n", hr );
7507 hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
7508 ok(hr == S_OK, "ret %08x\n", hr );
7509 ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
7510 wine_dbgstr_w(V_BSTR(&data)));
7511 VariantClear(&data);
7512 IXMLDOMAttribute_Release(attr);
7516 IXMLDOMDocument_Release(doc);
7519 static void test_document_IObjectSafety(void)
7521 IXMLDOMDocument *doc;
7522 IObjectSafety *safety;
7525 doc = create_document(&IID_IXMLDOMDocument);
7528 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
7529 ok(hr == S_OK, "ret %08x\n", hr );
7531 test_IObjectSafety_common(safety);
7533 IObjectSafety_Release(safety);
7535 IXMLDOMDocument_Release(doc);
7538 typedef struct _property_test_t {
7541 const char *property;
7545 static const property_test_t properties_test_data[] = {
7546 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
7547 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
7548 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
7549 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
7550 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
7554 static void test_default_properties(void)
7556 const property_test_t *entry = properties_test_data;
7557 IXMLDOMDocument2 *doc;
7563 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
7566 win_skip("can't create %s instance\n", entry->clsid);
7571 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
7572 ok(hr == S_OK, "got 0x%08x\n", hr);
7573 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
7574 entry->value, entry->clsid);
7577 IXMLDOMDocument2_Release(doc);
7583 static void test_XSLPattern(void)
7585 IXMLDOMDocument2 *doc;
7586 IXMLDOMNodeList *list;
7590 doc = create_document(&IID_IXMLDOMDocument2);
7593 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
7594 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7596 /* switch to XSLPattern */
7597 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
7599 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
7600 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list));
7602 ole_check(IXMLDOMNodeList_get_length(list, &len));
7603 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
7604 ok(len == 3, "expected 3 entries in list, got %d\n", len);
7605 IXMLDOMNodeList_Release(list);
7607 /* for XSLPattern start index is 0, for XPath it's 1 */
7608 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
7610 ole_check(IXMLDOMNodeList_get_length(list, &len));
7611 ok(len != 0, "expected filled list\n");
7613 expect_list_and_release(list, "E1.E2.D1");
7616 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=1]"), &list));
7618 ole_check(IXMLDOMNodeList_get_length(list, &len));
7619 ok(len != 0, "expected filled list\n");
7621 expect_list_and_release(list, "E2.E2.D1");
7624 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $eq$ 1]"), &list));
7626 ole_check(IXMLDOMNodeList_get_length(list, &len));
7627 ok(len != 0, "expected filled list\n");
7629 expect_list_and_release(list, "E2.E2.D1");
7632 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[end()]"), &list));
7634 ole_check(IXMLDOMNodeList_get_length(list, &len));
7635 ok(len != 0, "expected filled list\n");
7637 expect_list_and_release(list, "E4.E2.D1");
7640 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$not$ end()]"), &list));
7642 ole_check(IXMLDOMNodeList_get_length(list, &len));
7643 ok(len != 0, "expected filled list\n");
7645 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
7648 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() != 0]"), &list));
7650 ole_check(IXMLDOMNodeList_get_length(list, &len));
7651 ok(len != 0, "expected filled list\n");
7653 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
7654 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ne$ 0]"), &list));
7656 ole_check(IXMLDOMNodeList_get_length(list, &len));
7657 ok(len != 0, "expected filled list\n");
7659 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
7662 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() < 2]"), &list));
7664 ole_check(IXMLDOMNodeList_get_length(list, &len));
7665 ok(len != 0, "expected filled list\n");
7667 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7668 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $lt$ 2]"), &list));
7670 ole_check(IXMLDOMNodeList_get_length(list, &len));
7671 ok(len != 0, "expected filled list\n");
7673 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7676 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() <= 1]"), &list));
7678 ole_check(IXMLDOMNodeList_get_length(list, &len));
7679 ok(len != 0, "expected filled list\n");
7681 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7682 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $le$ 1]"), &list));
7684 ole_check(IXMLDOMNodeList_get_length(list, &len));
7685 ok(len != 0, "expected filled list\n");
7687 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7690 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() > 1]"), &list));
7692 ole_check(IXMLDOMNodeList_get_length(list, &len));
7693 ok(len != 0, "expected filled list\n");
7695 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7696 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $gt$ 1]"), &list));
7698 ole_check(IXMLDOMNodeList_get_length(list, &len));
7699 ok(len != 0, "expected filled list\n");
7701 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7704 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() >= 2]"), &list));
7706 ole_check(IXMLDOMNodeList_get_length(list, &len));
7707 ok(len != 0, "expected filled list\n");
7709 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7710 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ge$ 2]"), &list));
7712 ole_check(IXMLDOMNodeList_get_length(list, &len));
7713 ok(len != 0, "expected filled list\n");
7715 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7718 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ieq$ 'a2 field']"), &list));
7720 ole_check(IXMLDOMNodeList_get_length(list, &len));
7721 ok(len != 0, "expected filled list\n");
7723 expect_list_and_release(list, "E2.E2.D1");
7726 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ine$ 'a2 field']"), &list));
7728 ole_check(IXMLDOMNodeList_get_length(list, &len));
7729 ok(len != 0, "expected filled list\n");
7731 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
7734 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ilt$ 'a3 field']"), &list));
7736 ole_check(IXMLDOMNodeList_get_length(list, &len));
7737 ok(len != 0, "expected filled list\n");
7739 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7742 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ile$ 'a2 field']"), &list));
7744 ole_check(IXMLDOMNodeList_get_length(list, &len));
7745 ok(len != 0, "expected filled list\n");
7747 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7750 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $igt$ 'a2 field']"), &list));
7752 ole_check(IXMLDOMNodeList_get_length(list, &len));
7753 ok(len != 0, "expected filled list\n");
7755 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7758 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ige$ 'a3 field']"), &list));
7760 ole_check(IXMLDOMNodeList_get_length(list, &len));
7761 ok(len != 0, "expected filled list\n");
7763 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7766 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$any$ *='B2 field']"), &list));
7768 ole_check(IXMLDOMNodeList_get_length(list, &len));
7769 ok(len != 0, "expected filled list\n");
7771 expect_list_and_release(list, "E2.E2.D1");
7774 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$all$ *!='B2 field']"), &list));
7776 ole_check(IXMLDOMNodeList_get_length(list, &len));
7777 ok(len != 0, "expected filled list\n");
7779 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
7782 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 or end()]"), &list));
7784 ole_check(IXMLDOMNodeList_get_length(list, &len));
7785 ok(len != 0, "expected filled list\n");
7787 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7788 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 $or$ end()]"), &list));
7790 ole_check(IXMLDOMNodeList_get_length(list, &len));
7791 ok(len != 0, "expected filled list\n");
7793 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7794 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 || end()]"), &list));
7796 ole_check(IXMLDOMNodeList_get_length(list, &len));
7797 ok(len != 0, "expected filled list\n");
7799 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7802 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 and $not$ end()]"), &list));
7804 ole_check(IXMLDOMNodeList_get_length(list, &len));
7805 ok(len != 0, "expected filled list\n");
7807 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7808 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 $and$ $not$ end()]"), &list));
7810 ole_check(IXMLDOMNodeList_get_length(list, &len));
7811 ok(len != 0, "expected filled list\n");
7813 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7814 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 && $not$ end()]"), &list));
7816 ole_check(IXMLDOMNodeList_get_length(list, &len));
7817 ok(len != 0, "expected filled list\n");
7819 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7821 /* namespace handling */
7822 /* no registered namespaces */
7823 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
7826 /* prefixes don't need to be registered, you may use them as they are in the doc */
7827 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//bar:x"), &list));
7829 ole_check(IXMLDOMNodeList_get_length(list, &len));
7830 ok(len != 0, "expected filled list\n");
7832 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
7834 /* prefixes must be explicitly specified in the name */
7835 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:elem"), &list));
7837 ole_check(IXMLDOMNodeList_get_length(list, &len));
7838 ok(len == 0, "expected empty list\n");
7839 IXMLDOMNodeList_Release(list);
7841 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7843 ole_check(IXMLDOMNodeList_get_length(list, &len));
7844 ok(len != 0, "expected filled list\n");
7846 expect_list_and_release(list, "E3.E4.E2.D1");
7848 /* explicitly register prefix foo */
7849 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
7851 /* now we get the same behavior as XPath */
7852 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7854 ole_check(IXMLDOMNodeList_get_length(list, &len));
7855 ok(len != 0, "expected filled list\n");
7857 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
7859 /* set prefix foo to some nonexistent namespace */
7860 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:nonexistent-foo'")));
7862 /* the registered prefix takes precedence */
7863 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7865 ole_check(IXMLDOMNodeList_get_length(list, &len));
7866 ok(len == 0, "expected empty list\n");
7867 IXMLDOMNodeList_Release(list);
7869 IXMLDOMDocument2_Release(doc);
7871 doc = create_document(&IID_IXMLDOMDocument2);
7874 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szNodeTypesXML), &b));
7875 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7879 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute()"), &list));
7881 ole_check(IXMLDOMNodeList_get_length(list, &len));
7882 ok(len == 0, "expected empty list\n");
7883 IXMLDOMNodeList_Release(list);
7885 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute('depth')"), &list));
7887 ole_check(IXMLDOMNodeList_get_length(list, &len));
7888 ok(len == 0, "expected empty list\n");
7889 IXMLDOMNodeList_Release(list);
7891 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/attribute('depth')"), &list));
7893 ole_check(IXMLDOMNodeList_get_length(list, &len));
7894 ok(len != 0, "expected filled list\n");
7895 expect_list_and_release(list, "A'depth'.E3.D1");
7897 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/attribute()"), &list));
7899 ole_check(IXMLDOMNodeList_get_length(list, &len));
7900 ok(len != 0, "expected filled list\n");
7901 expect_list_and_release(list, "A'id'.E3.E3.D1 A'depth'.E3.E3.D1");
7904 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute(id)"), &list), E_FAIL);
7906 IXMLDOMNodeList_Release(list);
7907 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute('id')"), &list));
7909 ole_check(IXMLDOMNodeList_get_length(list, &len));
7910 ok(len != 0, "expected filled list\n");
7912 expect_list_and_release(list, "A'id'.E3.E3.D1 A'id'.E4.E3.E3.D1 A'id'.E5.E3.E3.D1 A'id'.E6.E3.E3.D1");
7915 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("comment()"), &list));
7917 ole_check(IXMLDOMNodeList_get_length(list, &len));
7918 ok(len != 0, "expected filled list\n");
7920 expect_list_and_release(list, "C2.D1");
7922 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//comment()"), &list));
7924 ole_check(IXMLDOMNodeList_get_length(list, &len));
7925 ok(len != 0, "expected filled list\n");
7927 expect_list_and_release(list, "C2.D1 C1.E3.D1 C2.E3.E3.D1 C2.E4.E3.D1");
7930 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("element()"), &list));
7932 ole_check(IXMLDOMNodeList_get_length(list, &len));
7933 ok(len != 0, "expected filled list\n");
7935 expect_list_and_release(list, "E3.D1");
7937 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/y/element()"), &list));
7939 ole_check(IXMLDOMNodeList_get_length(list, &len));
7940 ok(len != 0, "expected filled list\n");
7942 expect_list_and_release(list, "E4.E4.E3.D1 E5.E4.E3.D1 E6.E4.E3.D1");
7945 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element(a)"), &list), E_FAIL);
7947 IXMLDOMNodeList_Release(list);
7948 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element('a')"), &list));
7950 ole_check(IXMLDOMNodeList_get_length(list, &len));
7951 ok(len != 0, "expected filled list\n");
7953 expect_list_and_release(list, "E4.E3.E3.D1 E4.E4.E3.D1");
7956 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("node()"), &list));
7958 ole_check(IXMLDOMNodeList_get_length(list, &len));
7959 ok(len != 0, "expected filled list\n");
7961 expect_list_and_release(list, "P1.D1 C2.D1 E3.D1");
7963 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()"), &list));
7965 ole_check(IXMLDOMNodeList_get_length(list, &len));
7966 ok(len != 0, "expected filled list\n");
7968 expect_list_and_release(list, "P1.E3.E3.D1 C2.E3.E3.D1 T3.E3.E3.D1 E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
7971 /* XML_ELEMENT_NODE */
7972 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=1]"), &list));
7974 ole_check(IXMLDOMNodeList_get_length(list, &len));
7975 ok(len != 0, "expected filled list\n");
7977 expect_list_and_release(list, "E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
7979 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=3]"), &list));
7981 ole_check(IXMLDOMNodeList_get_length(list, &len));
7982 ok(len != 0, "expected filled list\n");
7984 expect_list_and_release(list, "T3.E3.E3.D1");
7986 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=7]"), &list));
7988 ole_check(IXMLDOMNodeList_get_length(list, &len));
7989 ok(len != 0, "expected filled list\n");
7991 expect_list_and_release(list, "P1.E3.E3.D1");
7992 /* XML_COMMENT_NODE */
7993 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=8]"), &list));
7995 ole_check(IXMLDOMNodeList_get_length(list, &len));
7996 ok(len != 0, "expected filled list\n");
7998 expect_list_and_release(list, "C2.E3.E3.D1");
8001 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("pi()"), &list));
8005 ole_check(IXMLDOMNodeList_get_length(list, &len));
8006 ok(len != 0, "expected filled list\n");
8008 expect_list_and_release(list, "P1.D1");
8011 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//y/pi()"), &list));
8013 ole_check(IXMLDOMNodeList_get_length(list, &len));
8014 ok(len != 0, "expected filled list\n");
8016 expect_list_and_release(list, "P1.E4.E3.D1");
8019 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/textnode()"), &list));
8021 ole_check(IXMLDOMNodeList_get_length(list, &len));
8022 ok(len != 0, "expected filled list\n");
8024 expect_list_and_release(list, "T2.E3.D1");
8026 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/element()/textnode()"), &list));
8028 ole_check(IXMLDOMNodeList_get_length(list, &len));
8029 ok(len != 0, "expected filled list\n");
8031 expect_list_and_release(list, "T3.E3.E3.D1 T3.E4.E3.D1");
8033 IXMLDOMDocument2_Release(doc);
8037 static void test_splitText(void)
8039 IXMLDOMCDATASection *cdata;
8040 IXMLDOMElement *root;
8041 IXMLDOMDocument *doc;
8042 IXMLDOMText *text, *text2;
8045 VARIANT_BOOL success;
8049 doc = create_document(&IID_IXMLDOMDocument);
8052 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
8053 ok(hr == S_OK, "got 0x%08x\n", hr);
8055 hr = IXMLDOMDocument_get_documentElement(doc, &root);
8056 ok(hr == S_OK, "got 0x%08x\n", hr);
8058 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
8059 ok(hr == S_OK, "got 0x%08x\n", hr);
8061 V_VT(&var) = VT_EMPTY;
8062 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
8063 ok(hr == S_OK, "got 0x%08x\n", hr);
8066 hr = IXMLDOMCDATASection_get_length(cdata, &length);
8067 ok(hr == S_OK, "got 0x%08x\n", hr);
8068 ok(length > 0, "got %d\n", length);
8070 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
8071 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8073 text = (void*)0xdeadbeef;
8074 /* negative offset */
8075 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
8076 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8077 ok(text == (void*)0xdeadbeef, "got %p\n", text);
8079 text = (void*)0xdeadbeef;
8080 /* offset outside data */
8081 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
8082 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8083 ok(text == 0, "got %p\n", text);
8085 text = (void*)0xdeadbeef;
8086 /* offset outside data */
8087 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
8088 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8089 ok(text == 0, "got %p\n", text);
8091 /* no empty node created */
8092 node = (void*)0xdeadbeef;
8093 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8094 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8095 ok(node == 0, "got %p\n", text);
8097 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
8098 ok(hr == S_OK, "got 0x%08x\n", hr);
8101 hr = IXMLDOMText_get_length(text, &length);
8102 ok(hr == S_OK, "got 0x%08x\n", hr);
8103 ok(length == 7, "got %d\n", length);
8105 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8106 ok(hr == S_OK, "got 0x%08x\n", hr);
8107 IXMLDOMNode_Release(node);
8109 /* split new text node */
8110 hr = IXMLDOMText_get_length(text, &length);
8111 ok(hr == S_OK, "got 0x%08x\n", hr);
8113 node = (void*)0xdeadbeef;
8114 hr = IXMLDOMText_get_nextSibling(text, &node);
8115 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8116 ok(node == 0, "got %p\n", text);
8118 hr = IXMLDOMText_splitText(text, 0, NULL);
8119 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8121 text2 = (void*)0xdeadbeef;
8122 /* negative offset */
8123 hr = IXMLDOMText_splitText(text, -1, &text2);
8124 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8125 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
8127 text2 = (void*)0xdeadbeef;
8128 /* offset outside data */
8129 hr = IXMLDOMText_splitText(text, length + 1, &text2);
8130 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8131 ok(text2 == 0, "got %p\n", text2);
8133 text2 = (void*)0xdeadbeef;
8134 /* offset outside data */
8135 hr = IXMLDOMText_splitText(text, length, &text2);
8136 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8137 ok(text2 == 0, "got %p\n", text);
8140 hr = IXMLDOMText_splitText(text, 4, &text2);
8141 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8142 if (text2) IXMLDOMText_Release(text2);
8145 hr = IXMLDOMText_get_nextSibling(text, &node);
8146 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8147 if (node) IXMLDOMNode_Release(node);
8149 IXMLDOMText_Release(text);
8150 IXMLDOMElement_Release(root);
8151 IXMLDOMCDATASection_Release(cdata);
8155 static void test_getQualifiedItem(void)
8157 IXMLDOMDocument *doc;
8158 IXMLDOMElement *element;
8159 IXMLDOMNode *pr_node, *node;
8160 IXMLDOMNodeList *root_list;
8161 IXMLDOMNamedNodeMap *map;
8167 doc = create_document(&IID_IXMLDOMDocument);
8170 str = SysAllocString( szComplete4 );
8171 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8172 ok( hr == S_OK, "loadXML failed\n");
8173 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8174 SysFreeString( str );
8176 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8177 ok( hr == S_OK, "ret %08x\n", hr);
8179 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8180 ok( hr == S_OK, "ret %08x\n", hr);
8182 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8183 ok( hr == S_OK, "ret %08x\n", hr);
8184 IXMLDOMNodeList_Release(root_list);
8186 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8187 ok( hr == S_OK, "ret %08x\n", hr);
8188 IXMLDOMNode_Release(pr_node);
8190 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8191 ok( hr == S_OK, "ret %08x\n", hr);
8192 ok( len == 3, "length %d\n", len);
8194 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
8195 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8197 node = (void*)0xdeadbeef;
8198 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
8199 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8200 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8202 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
8203 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8205 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
8206 ok( hr == S_OK, "ret %08x\n", hr);
8207 IXMLDOMNode_Release(node);
8209 IXMLDOMNamedNodeMap_Release( map );
8210 IXMLDOMElement_Release( element );
8211 IXMLDOMDocument_Release( doc );
8215 static void test_removeQualifiedItem(void)
8217 IXMLDOMDocument *doc;
8218 IXMLDOMElement *element;
8219 IXMLDOMNode *pr_node, *node;
8220 IXMLDOMNodeList *root_list;
8221 IXMLDOMNamedNodeMap *map;
8227 doc = create_document(&IID_IXMLDOMDocument);
8230 str = SysAllocString( szComplete4 );
8231 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8232 ok( hr == S_OK, "loadXML failed\n");
8233 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8234 SysFreeString( str );
8236 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8237 ok( hr == S_OK, "ret %08x\n", hr);
8239 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8240 ok( hr == S_OK, "ret %08x\n", hr);
8242 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8243 ok( hr == S_OK, "ret %08x\n", hr);
8244 IXMLDOMNodeList_Release(root_list);
8246 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8247 ok( hr == S_OK, "ret %08x\n", hr);
8248 IXMLDOMNode_Release(pr_node);
8250 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8251 ok( hr == S_OK, "ret %08x\n", hr);
8252 ok( len == 3, "length %d\n", len);
8254 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
8255 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8257 node = (void*)0xdeadbeef;
8258 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
8259 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8260 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8262 /* out pointer is optional */
8263 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8264 ok( hr == S_OK, "ret %08x\n", hr);
8266 /* already removed */
8267 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8268 ok( hr == S_FALSE, "ret %08x\n", hr);
8270 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
8271 ok( hr == S_OK, "ret %08x\n", hr);
8272 IXMLDOMNode_Release(node);
8274 IXMLDOMNamedNodeMap_Release( map );
8275 IXMLDOMElement_Release( element );
8276 IXMLDOMDocument_Release( doc );
8280 #define check_default_props(doc) _check_default_props(__LINE__, doc)
8281 static inline void _check_default_props(int line, IXMLDOMDocument2* doc)
8288 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8289 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
8292 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8293 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("")) == 0, "expected empty string\n");
8296 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8297 ok_(__FILE__, line)(b == VARIANT_FALSE, "expected FALSE\n");
8299 hr = IXMLDOMDocument2_get_schemas(doc, &var);
8300 ok_(__FILE__, line)(hr == S_FALSE, "got %08x\n", hr);
8304 #define check_set_props(doc) _check_set_props(__LINE__, doc)
8305 static inline void _check_set_props(int line, IXMLDOMDocument2* doc)
8311 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8312 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
8315 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8316 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&var)));
8319 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8320 ok_(__FILE__, line)(b == VARIANT_TRUE, "expected TRUE\n");
8322 helper_ole_check(IXMLDOMDocument2_get_schemas(doc, &var));
8323 ok_(__FILE__, line)(V_VT(&var) != VT_NULL, "expected pointer\n");
8327 #define set_props(doc, cache) _set_props(__LINE__, doc, cache)
8328 static inline void _set_props(int line, IXMLDOMDocument2* doc, IXMLDOMSchemaCollection* cache)
8333 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
8334 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'")));
8335 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_TRUE));
8336 V_VT(&var) = VT_DISPATCH;
8337 V_DISPATCH(&var) = NULL;
8338 helper_ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&var)));
8339 ok_(__FILE__, line)(V_DISPATCH(&var) != NULL, "expected pointer\n");
8340 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8344 #define unset_props(doc) _unset_props(__LINE__, doc)
8345 static inline void _unset_props(int line, IXMLDOMDocument2* doc)
8350 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
8351 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
8352 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_FALSE));
8353 V_VT(&var) = VT_NULL;
8354 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8358 static void test_get_ownerDocument(void)
8360 IXMLDOMDocument *doc1, *doc2, *doc3;
8361 IXMLDOMDocument2 *doc, *doc_owner;
8363 IXMLDOMSchemaCollection *cache;
8368 doc = create_document(&IID_IXMLDOMDocument2);
8369 cache = create_cache(&IID_IXMLDOMSchemaCollection);
8372 if (doc) IXMLDOMDocument2_Release(doc);
8373 if (cache) IXMLDOMSchemaCollection_Release(cache);
8379 str = SysAllocString(szComplete4);
8380 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
8381 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8384 check_default_props(doc);
8386 /* set properties and check that new instances use them */
8387 set_props(doc, cache);
8388 check_set_props(doc);
8390 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8391 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc1));
8393 /* new interface keeps props */
8394 ole_check(IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8395 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
8396 check_set_props(doc_owner);
8397 IXMLDOMDocument2_Release(doc_owner);
8399 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc2));
8400 IXMLDOMNode_Release(node);
8402 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
8405 str = SysAllocString(szComplete4);
8406 ole_check(IXMLDOMDocument2_loadXML(doc, str, &b));
8407 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8410 /* properties retained even after reload */
8411 check_set_props(doc);
8413 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8414 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc3));
8415 IXMLDOMNode_Release(node);
8417 ole_check(IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8418 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
8419 check_set_props(doc_owner);
8421 /* changing properties for one instance changes them for all */
8422 unset_props(doc_owner);
8423 check_default_props(doc_owner);
8424 check_default_props(doc);
8426 IXMLDOMSchemaCollection_Release(cache);
8427 IXMLDOMDocument_Release(doc1);
8428 IXMLDOMDocument_Release(doc2);
8429 IXMLDOMDocument_Release(doc3);
8430 IXMLDOMDocument2_Release(doc);
8431 IXMLDOMDocument2_Release(doc_owner);
8435 static void test_setAttributeNode(void)
8437 IXMLDOMDocument *doc, *doc2;
8438 IXMLDOMElement *elem, *elem2;
8439 IXMLDOMAttribute *attr, *attr2, *ret_attr;
8446 doc = create_document(&IID_IXMLDOMDocument);
8449 str = SysAllocString( szComplete4 );
8450 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
8451 ok( hr == S_OK, "loadXML failed\n");
8452 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8453 SysFreeString( str );
8455 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8456 ok( hr == S_OK, "got 0x%08x\n", hr);
8458 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
8459 ok( hr == S_OK, "got 0x%08x\n", hr);
8460 ok( elem2 != elem, "got same instance\n");
8462 ret_attr = (void*)0xdeadbeef;
8463 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
8464 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8465 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8467 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8468 ok( hr == S_OK, "got 0x%08x\n", hr);
8470 ref1 = IXMLDOMElement_AddRef(elem);
8471 IXMLDOMElement_Release(elem);
8473 ret_attr = (void*)0xdeadbeef;
8474 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8475 ok( hr == S_OK, "got 0x%08x\n", hr);
8476 ok( ret_attr == NULL, "got %p\n", ret_attr);
8478 /* no reference added */
8479 ref2 = IXMLDOMElement_AddRef(elem);
8480 IXMLDOMElement_Release(elem);
8481 ok(ref2 == ref1, "got %d, expected %d\n", ref2, ref1);
8483 EXPECT_CHILDREN(elem);
8484 EXPECT_CHILDREN(elem2);
8486 IXMLDOMElement_Release(elem2);
8489 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
8490 ok( hr == S_OK, "got 0x%08x\n", hr);
8491 ok( attr2 != attr, "got same instance %p\n", attr2);
8492 IXMLDOMAttribute_Release(attr2);
8494 /* try to add it another time */
8495 ret_attr = (void*)0xdeadbeef;
8496 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8497 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8498 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8500 IXMLDOMElement_Release(elem);
8502 /* initially used element is released, attribute still 'has' a container */
8503 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8504 ok( hr == S_OK, "got 0x%08x\n", hr);
8505 ret_attr = (void*)0xdeadbeef;
8506 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8507 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8508 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8509 IXMLDOMElement_Release(elem);
8511 /* add attribute already attached to another document */
8512 doc2 = create_document(&IID_IXMLDOMDocument);
8514 str = SysAllocString( szComplete4 );
8515 hr = IXMLDOMDocument_loadXML( doc2, str, &b );
8516 ok( hr == S_OK, "loadXML failed\n");
8517 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8518 SysFreeString( str );
8520 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
8521 ok( hr == S_OK, "got 0x%08x\n", hr);
8522 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
8523 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8524 IXMLDOMElement_Release(elem);
8526 IXMLDOMAttribute_Release(attr);
8528 /* create element, add attribute, see if it's copied or linked */
8529 hr = IXMLDOMDocument_createElement(doc, _bstr_("test"), &elem);
8530 ok( hr == S_OK, "got 0x%08x\n", hr);
8533 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8534 ok(hr == S_OK, "got 0x%08x\n", hr);
8535 ok(attr != NULL, "got %p\n", attr);
8537 ref1 = IXMLDOMAttribute_AddRef(attr);
8538 IXMLDOMAttribute_Release(attr);
8541 V_BSTR(&v) = _bstr_("attrvalue1");
8542 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8543 ok( hr == S_OK, "got 0x%08x\n", hr);
8546 hr = IXMLDOMAttribute_get_xml(attr, &str);
8547 ok( hr == S_OK, "got 0x%08x\n", hr);
8548 ok( lstrcmpW(str, _bstr_("attr=\"attrvalue1\"")) == 0,
8549 "got %s\n", wine_dbgstr_w(str));
8552 ret_attr = (void*)0xdeadbeef;
8553 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8554 ok(hr == S_OK, "got 0x%08x\n", hr);
8555 ok(ret_attr == NULL, "got %p\n", ret_attr);
8557 /* attribute reference increased */
8558 ref2 = IXMLDOMAttribute_AddRef(attr);
8559 IXMLDOMAttribute_Release(attr);
8560 ok(ref1 == ref2, "got %d, expected %d\n", ref2, ref1);
8562 hr = IXMLDOMElement_get_xml(elem, &str);
8563 ok( hr == S_OK, "got 0x%08x\n", hr);
8564 ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue1\"/>")) == 0,
8565 "got %s\n", wine_dbgstr_w(str));
8569 V_BSTR(&v) = _bstr_("attrvalue2");
8570 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8571 ok( hr == S_OK, "got 0x%08x\n", hr);
8573 hr = IXMLDOMElement_get_xml(elem, &str);
8574 ok( hr == S_OK, "got 0x%08x\n", hr);
8575 todo_wine ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue2\"/>")) == 0,
8576 "got %s\n", wine_dbgstr_w(str));
8579 IXMLDOMElement_Release(elem);
8580 IXMLDOMAttribute_Release(attr);
8581 IXMLDOMDocument_Release(doc2);
8582 IXMLDOMDocument_Release(doc);
8585 static void test_put_dataType(void)
8587 IXMLDOMCDATASection *cdata;
8588 IXMLDOMDocument *doc;
8593 doc = create_document(&IID_IXMLDOMDocument);
8596 str = SysAllocString( szComplete4 );
8597 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8598 ok( hr == S_OK, "loadXML failed\n");
8599 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8600 SysFreeString( str );
8602 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("test"), &cdata);
8603 ok( hr == S_OK, "got 0x%08x\n", hr);
8604 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("number"));
8605 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8606 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("string"));
8607 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8608 IXMLDOMCDATASection_Release(cdata);
8610 IXMLDOMDocument_Release(doc);
8614 static void test_createNode(void)
8616 IXMLDOMDocument *doc;
8617 IXMLDOMElement *elem;
8624 doc = create_document(&IID_IXMLDOMDocument);
8629 /* reference count tests */
8630 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8631 ok( hr == S_OK, "got 0x%08x\n", hr);
8633 /* initial reference is 2 */
8635 EXPECT_REF(elem, 2);
8636 ref = IXMLDOMElement_Release(elem);
8637 ok(ref == 1, "got %d\n", ref);
8638 /* it's released already, attempt to release now will crash it */
8641 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8642 ok( hr == S_OK, "got 0x%08x\n", hr);
8643 todo_wine EXPECT_REF(elem, 2);
8644 IXMLDOMDocument_Release(doc);
8645 todo_wine EXPECT_REF(elem, 2);
8646 IXMLDOMElement_Release(elem);
8648 doc = create_document(&IID_IXMLDOMDocument);
8650 /* NODE_ELEMENT nodes */
8651 /* 1. specified namespace */
8653 V_I4(&v) = NODE_ELEMENT;
8655 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
8656 ok( hr == S_OK, "got 0x%08x\n", hr);
8658 hr = IXMLDOMNode_get_prefix(node, &prefix);
8659 ok( hr == S_OK, "got 0x%08x\n", hr);
8660 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
8661 SysFreeString(prefix);
8662 IXMLDOMNode_Release(node);
8664 /* 2. default namespace */
8665 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
8666 ok( hr == S_OK, "got 0x%08x\n", hr);
8667 prefix = (void*)0xdeadbeef;
8668 hr = IXMLDOMNode_get_prefix(node, &prefix);
8669 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8670 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
8672 hr = IXMLDOMNode_get_xml(node, &str);
8673 ok( hr == S_OK, "got 0x%08x\n", hr);
8674 ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0,
8675 "got %s\n", wine_dbgstr_w(str));
8678 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
8679 ok( hr == S_OK, "got 0x%08x\n", hr);
8681 V_VT(&var) = VT_BSTR;
8682 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
8683 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8684 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
8687 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
8688 ok( hr == S_OK, "got 0x%08x\n", hr);
8689 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
8692 IXMLDOMElement_Release(elem);
8693 IXMLDOMNode_Release(node);
8695 IXMLDOMDocument_Release(doc);
8699 static void test_get_prefix(void)
8701 IXMLDOMDocumentFragment *fragment;
8702 IXMLDOMCDATASection *cdata;
8703 IXMLDOMElement *element;
8704 IXMLDOMComment *comment;
8705 IXMLDOMDocument *doc;
8709 doc = create_document(&IID_IXMLDOMDocument);
8712 /* nodes that can't support prefix */
8714 str = (void*)0xdeadbeef;
8715 hr = IXMLDOMDocument_get_prefix(doc, &str);
8716 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8717 ok( str == 0, "got %p\n", str);
8719 hr = IXMLDOMDocument_get_prefix(doc, NULL);
8720 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8723 hr = IXMLDOMDocument_createCDATASection(doc, NULL, &cdata);
8724 ok(hr == S_OK, "got %08x\n", hr );
8726 str = (void*)0xdeadbeef;
8727 hr = IXMLDOMCDATASection_get_prefix(cdata, &str);
8728 ok(hr == S_FALSE, "got %08x\n", hr);
8729 ok( str == 0, "got %p\n", str);
8731 hr = IXMLDOMCDATASection_get_prefix(cdata, NULL);
8732 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8733 IXMLDOMCDATASection_Release(cdata);
8736 hr = IXMLDOMDocument_createComment(doc, NULL, &comment);
8737 ok(hr == S_OK, "got %08x\n", hr );
8739 str = (void*)0xdeadbeef;
8740 hr = IXMLDOMComment_get_prefix(comment, &str);
8741 ok(hr == S_FALSE, "got %08x\n", hr);
8742 ok( str == 0, "got %p\n", str);
8744 hr = IXMLDOMComment_get_prefix(comment, NULL);
8745 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8746 IXMLDOMComment_Release(comment);
8749 hr = IXMLDOMDocument_createDocumentFragment(doc, &fragment);
8750 ok(hr == S_OK, "got %08x\n", hr );
8752 str = (void*)0xdeadbeef;
8753 hr = IXMLDOMDocumentFragment_get_prefix(fragment, &str);
8754 ok(hr == S_FALSE, "got %08x\n", hr);
8755 ok( str == 0, "got %p\n", str);
8757 hr = IXMLDOMDocumentFragment_get_prefix(fragment, NULL);
8758 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8759 IXMLDOMDocumentFragment_Release(fragment);
8762 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
8763 ok( hr == S_OK, "got 0x%08x\n", hr);
8765 hr = IXMLDOMElement_get_prefix(element, NULL);
8766 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8768 str = (void*)0xdeadbeef;
8769 hr = IXMLDOMElement_get_prefix(element, &str);
8770 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8771 ok( str == 0, "got %p\n", str);
8773 IXMLDOMElement_Release(element);
8776 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
8777 ok( hr == S_OK, "got 0x%08x\n", hr);
8779 str = (void*)0xdeadbeef;
8780 hr = IXMLDOMElement_get_prefix(element, &str);
8781 ok( hr == S_OK, "got 0x%08x\n", hr);
8782 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
8785 str = (void*)0xdeadbeef;
8786 hr = IXMLDOMElement_get_namespaceURI(element, &str);
8787 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8788 ok( str == 0, "got %p\n", str);
8790 IXMLDOMElement_Release(element);
8792 IXMLDOMDocument_Release(doc);
8796 static void test_selectSingleNode(void)
8798 IXMLDOMDocument *doc;
8799 IXMLDOMNodeList *list;
8806 doc = create_document(&IID_IXMLDOMDocument);
8809 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8810 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8812 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8813 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8815 str = SysAllocString( szComplete4 );
8816 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8817 ok( hr == S_OK, "loadXML failed\n");
8818 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8819 SysFreeString( str );
8821 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8822 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8824 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8825 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8827 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
8828 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8830 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
8831 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8833 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
8834 ok(hr == S_OK, "got 0x%08x\n", hr);
8835 IXMLDOMNode_Release(node);
8837 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
8838 ok(hr == S_OK, "got 0x%08x\n", hr);
8839 IXMLDOMNodeList_Release(list);
8841 list = (void*)0xdeadbeef;
8842 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
8843 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8844 ok(list == (void*)0xdeadbeef, "got %p\n", list);
8846 node = (void*)0xdeadbeef;
8847 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
8848 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8849 ok(node == 0, "got %p\n", node);
8851 list = (void*)0xdeadbeef;
8852 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
8853 ok(hr == S_OK, "got 0x%08x\n", hr);
8855 hr = IXMLDOMNodeList_get_length(list, &len);
8856 ok(hr == S_OK, "got 0x%08x\n", hr);
8857 ok(len == 0, "got %d\n", len);
8858 IXMLDOMNodeList_Release(list);
8860 IXMLDOMDocument_Release(doc);
8864 static void test_events(void)
8866 IConnectionPointContainer *conn;
8867 IConnectionPoint *point;
8868 IXMLDOMDocument *doc;
8873 doc = create_document(&IID_IXMLDOMDocument);
8876 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&conn);
8877 ok(hr == S_OK, "got 0x%08x\n", hr);
8879 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IDispatch, &point);
8880 ok(hr == S_OK, "got 0x%08x\n", hr);
8881 IConnectionPoint_Release(point);
8882 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IPropertyNotifySink, &point);
8883 ok(hr == S_OK, "got 0x%08x\n", hr);
8884 IConnectionPoint_Release(point);
8885 hr = IConnectionPointContainer_FindConnectionPoint(conn, &DIID_XMLDOMDocumentEvents, &point);
8886 ok(hr == S_OK, "got 0x%08x\n", hr);
8887 IConnectionPoint_Release(point);
8889 IConnectionPointContainer_Release(conn);
8891 /* ready state callback */
8893 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8894 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8896 event = create_dispevent();
8897 V_VT(&v) = VT_UNKNOWN;
8898 V_UNKNOWN(&v) = (IUnknown*)event;
8900 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8901 ok(hr == S_OK, "got 0x%08x\n", hr);
8902 EXPECT_REF(event, 2);
8904 V_VT(&v) = VT_DISPATCH;
8905 V_DISPATCH(&v) = event;
8907 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8908 ok(hr == S_OK, "got 0x%08x\n", hr);
8909 EXPECT_REF(event, 2);
8911 /* VT_NULL doesn't reset event handler */
8913 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8914 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8915 EXPECT_REF(event, 2);
8917 V_VT(&v) = VT_DISPATCH;
8918 V_DISPATCH(&v) = NULL;
8920 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8921 ok(hr == S_OK, "got 0x%08x\n", hr);
8922 EXPECT_REF(event, 1);
8924 V_VT(&v) = VT_UNKNOWN;
8925 V_DISPATCH(&v) = NULL;
8926 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8927 ok(hr == S_OK, "got 0x%08x\n", hr);
8929 IDispatch_Release(event);
8931 IXMLDOMDocument_Release(doc);
8934 static void test_createProcessingInstruction(void)
8936 static const WCHAR bodyW[] = {'t','e','s','t',0};
8937 IXMLDOMProcessingInstruction *pi;
8938 IXMLDOMDocument *doc;
8942 doc = create_document(&IID_IXMLDOMDocument);
8945 /* test for BSTR handling, pass broken BSTR */
8946 memcpy(&buff[2], bodyW, sizeof(bodyW));
8947 /* just a big length */
8948 *(DWORD*)buff = 0xf0f0;
8949 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("test"), &buff[2], &pi);
8950 ok(hr == S_OK, "got 0x%08x\n", hr);
8952 IXMLDOMProcessingInstruction_Release(pi);
8953 IXMLDOMDocument_Release(doc);
8956 static void test_put_nodeTypedValue(void)
8958 IXMLDOMDocument *doc;
8959 IXMLDOMElement *elem;
8963 doc = create_document(&IID_IXMLDOMDocument);
8966 hr = IXMLDOMDocument_createElement(doc, _bstr_("Element"), &elem);
8967 ok(hr == S_OK, "got 0x%08x\n", hr);
8969 V_VT(&type) = VT_EMPTY;
8970 hr = IXMLDOMElement_get_dataType(elem, &type);
8971 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8972 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8974 /* set typed value for untyped node */
8975 V_VT(&type) = VT_I1;
8977 hr = IXMLDOMElement_put_nodeTypedValue(elem, type);
8978 ok(hr == S_OK, "got 0x%08x\n", hr);
8980 V_VT(&type) = VT_EMPTY;
8981 hr = IXMLDOMElement_get_dataType(elem, &type);
8982 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8983 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8985 /* no type info stored */
8986 V_VT(&type) = VT_EMPTY;
8987 hr = IXMLDOMElement_get_nodeTypedValue(elem, &type);
8988 ok(hr == S_OK, "got 0x%08x\n", hr);
8989 ok(V_VT(&type) == VT_BSTR, "got %d, expected VT_BSTR\n", V_VT(&type));
8990 ok(memcmp(V_BSTR(&type), _bstr_("1"), 2*sizeof(WCHAR)) == 0,
8991 "got %s, expected \"1\"\n", wine_dbgstr_w(V_BSTR(&type)));
8992 VariantClear(&type);
8994 IXMLDOMElement_Release(elem);
8995 IXMLDOMDocument_Release(doc);
8999 static void test_get_xml(void)
9001 static const char xmlA[] = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<a>test</a>\r\n";
9002 static const char fooA[] = "<foo/>";
9003 IXMLDOMProcessingInstruction *pi;
9005 IXMLDOMElement *elem = NULL;
9006 IXMLDOMDocument *doc;
9012 doc = create_document(&IID_IXMLDOMDocument);
9016 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
9017 ok(hr == S_OK, "got 0x%08x\n", hr);
9018 ok( b == VARIANT_TRUE, "got %d\n", b);
9020 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"),
9021 _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &pi);
9022 ok(hr == S_OK, "got 0x%08x\n", hr);
9024 hr = IXMLDOMDocument_get_firstChild(doc, &first);
9025 ok(hr == S_OK, "got 0x%08x\n", hr);
9027 V_UNKNOWN(&v) = (IUnknown*)first;
9028 V_VT(&v) = VT_UNKNOWN;
9030 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)pi, v, NULL);
9031 ok(hr == S_OK, "got 0x%08x\n", hr);
9033 IXMLDOMProcessingInstruction_Release(pi);
9034 IXMLDOMNode_Release(first);
9036 hr = IXMLDOMDocument_get_xml(doc, &xml);
9037 ok(hr == S_OK, "got 0x%08x\n", hr);
9039 ok(memcmp(xml, _bstr_(xmlA), sizeof(xmlA)*sizeof(WCHAR)) == 0,
9040 "got %s, expected %s\n", wine_dbgstr_w(xml), xmlA);
9043 IXMLDOMDocument_Release(doc);
9045 doc = create_document(&IID_IXMLDOMDocument);
9047 hr = IXMLDOMDocument_createElement(doc, _bstr_("foo"), &elem);
9048 ok(hr == S_OK, "got 0x%08x\n", hr);
9050 hr = IXMLDOMDocument_putref_documentElement(doc, elem);
9051 ok(hr == S_OK, "got 0x%08x\n", hr);
9053 hr = IXMLDOMDocument_get_xml(doc, &xml);
9054 ok(hr == S_OK, "got 0x%08x\n", hr);
9056 ok(memcmp(xml, _bstr_(fooA), (sizeof(fooA)-1)*sizeof(WCHAR)) == 0,
9057 "got %s, expected %s\n", wine_dbgstr_w(xml), fooA);
9060 IXMLDOMElement_Release(elem);
9061 IXMLDOMDocument_Release(doc);
9066 static void test_xsltemplate(void)
9068 IXSLTemplate *template;
9069 IXSLProcessor *processor;
9070 IXMLDOMDocument *doc, *doc2;
9077 template = create_xsltemplate(&IID_IXSLTemplate);
9078 if (!template) return;
9080 /* works as reset */
9081 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9082 ok(hr == S_OK, "got 0x%08x\n", hr);
9084 doc = create_document(&IID_IXMLDOMDocument);
9087 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
9088 ok(hr == S_OK, "got 0x%08x\n", hr);
9089 ok( b == VARIANT_TRUE, "got %d\n", b);
9091 /* putref with non-xsl document */
9092 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9093 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9096 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9097 ok(hr == S_OK, "got 0x%08x\n", hr);
9098 ok( b == VARIANT_TRUE, "got %d\n", b);
9100 /* not a freethreaded document */
9101 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9102 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9104 IXMLDOMDocument_Release(doc);
9106 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
9109 win_skip("failed to create free threaded document instance: 0x%08x\n", hr);
9110 IXSLTemplate_Release(template);
9115 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9116 ok(hr == S_OK, "got 0x%08x\n", hr);
9117 ok( b == VARIANT_TRUE, "got %d\n", b);
9119 /* freethreaded document */
9120 ref1 = IXMLDOMDocument_AddRef(doc);
9121 IXMLDOMDocument_Release(doc);
9122 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9123 ok(hr == S_OK, "got 0x%08x\n", hr);
9124 ref2 = IXMLDOMDocument_AddRef(doc);
9125 IXMLDOMDocument_Release(doc);
9126 ok(ref2 > ref1, "got %d\n", ref2);
9129 hr = IXSLTemplate_createProcessor(template, NULL);
9130 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9132 EXPECT_REF(template, 1);
9133 hr = IXSLTemplate_createProcessor(template, &processor);
9134 ok(hr == S_OK, "got 0x%08x\n", hr);
9135 EXPECT_REF(template, 2);
9137 /* input no set yet */
9140 hr = IXSLProcessor_get_input(processor, &v);
9142 ok(hr == S_OK, "got 0x%08x\n", hr);
9143 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
9146 hr = IXSLProcessor_get_output(processor, NULL);
9147 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9149 /* reset before it was set */
9150 V_VT(&v) = VT_EMPTY;
9151 hr = IXSLProcessor_put_output(processor, v);
9152 ok(hr == S_OK, "got 0x%08x\n", hr);
9154 CreateStreamOnHGlobal(NULL, TRUE, &stream);
9155 EXPECT_REF(stream, 1);
9157 V_VT(&v) = VT_UNKNOWN;
9158 V_UNKNOWN(&v) = (IUnknown*)stream;
9159 hr = IXSLProcessor_put_output(processor, v);
9160 ok(hr == S_OK, "got 0x%08x\n", hr);
9162 /* it seems processor grabs 2 references */
9163 todo_wine EXPECT_REF(stream, 3);
9165 V_VT(&v) = VT_EMPTY;
9166 hr = IXSLProcessor_get_output(processor, &v);
9167 ok(hr == S_OK, "got 0x%08x\n", hr);
9168 ok(V_VT(&v) == VT_UNKNOWN, "got type %d\n", V_VT(&v));
9169 ok(V_UNKNOWN(&v) == (IUnknown*)stream, "got %p\n", V_UNKNOWN(&v));
9171 todo_wine EXPECT_REF(stream, 4);
9174 hr = IXSLProcessor_transform(processor, NULL);
9175 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9177 /* reset and check stream refcount */
9178 V_VT(&v) = VT_EMPTY;
9179 hr = IXSLProcessor_put_output(processor, v);
9180 ok(hr == S_OK, "got 0x%08x\n", hr);
9182 EXPECT_REF(stream, 1);
9184 IStream_Release(stream);
9186 /* no output interface set, check output */
9187 doc2 = create_document(&IID_IXMLDOMDocument);
9190 hr = IXMLDOMDocument_loadXML( doc2, _bstr_("<a>test</a>"), &b );
9191 ok(hr == S_OK, "got 0x%08x\n", hr);
9192 ok( b == VARIANT_TRUE, "got %d\n", b);
9194 V_VT(&v) = VT_UNKNOWN;
9195 V_UNKNOWN(&v) = (IUnknown*)doc2;
9196 hr = IXSLProcessor_put_input(processor, v);
9197 ok(hr == S_OK, "got 0x%08x\n", hr);
9199 hr = IXSLProcessor_transform(processor, &b);
9200 ok(hr == S_OK, "got 0x%08x\n", hr);
9202 V_VT(&v) = VT_EMPTY;
9203 hr = IXSLProcessor_get_output(processor, &v);
9204 ok(hr == S_OK, "got 0x%08x\n", hr);
9205 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
9206 /* we currently output one '\n' instead of empty string */
9207 todo_wine ok(lstrcmpW(V_BSTR(&v), _bstr_("")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
9208 IXMLDOMDocument_Release(doc2);
9211 IXSLProcessor_Release(processor);
9213 /* drop reference */
9214 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9215 ok(hr == S_OK, "got 0x%08x\n", hr);
9216 ref2 = IXMLDOMDocument_AddRef(doc);
9217 IXMLDOMDocument_Release(doc);
9218 ok(ref2 == ref1, "got %d\n", ref2);
9220 IXMLDOMDocument_Release(doc);
9221 IXSLTemplate_Release(template);
9225 static void test_insertBefore(void)
9227 IXMLDOMDocument *doc, *doc2;
9228 IXMLDOMAttribute *attr;
9229 IXMLDOMElement *elem1, *elem2, *elem3, *elem4, *elem5;
9230 IXMLDOMNode *node, *newnode;
9235 doc = create_document(&IID_IXMLDOMDocument);
9237 /* insertBefore behaviour for attribute node */
9239 V_I4(&v) = NODE_ATTRIBUTE;
9242 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr"), NULL, (IXMLDOMNode**)&attr);
9243 ok(hr == S_OK, "got 0x%08x\n", hr);
9244 ok(attr != NULL, "got %p\n", attr);
9246 /* attribute to attribute */
9248 V_I4(&v) = NODE_ATTRIBUTE;
9250 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr2"), NULL, &newnode);
9251 ok(hr == S_OK, "got 0x%08x\n", hr);
9252 ok(newnode != NULL, "got %p\n", newnode);
9255 node = (void*)0xdeadbeef;
9256 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9257 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9258 ok(node == NULL, "got %p\n", node);
9260 V_VT(&v) = VT_UNKNOWN;
9261 V_UNKNOWN(&v) = (IUnknown*)attr;
9262 node = (void*)0xdeadbeef;
9263 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9264 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9265 ok(node == NULL, "got %p\n", node);
9266 IXMLDOMNode_Release(newnode);
9268 /* cdata to attribute */
9270 V_I4(&v) = NODE_CDATA_SECTION;
9272 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9273 ok(hr == S_OK, "got 0x%08x\n", hr);
9274 ok(newnode != NULL, "got %p\n", newnode);
9277 node = (void*)0xdeadbeef;
9278 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9279 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9280 ok(node == NULL, "got %p\n", node);
9281 IXMLDOMNode_Release(newnode);
9283 /* comment to attribute */
9285 V_I4(&v) = NODE_COMMENT;
9287 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9288 ok(hr == S_OK, "got 0x%08x\n", hr);
9289 ok(newnode != NULL, "got %p\n", newnode);
9292 node = (void*)0xdeadbeef;
9293 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9294 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9295 ok(node == NULL, "got %p\n", node);
9296 IXMLDOMNode_Release(newnode);
9298 /* element to attribute */
9300 V_I4(&v) = NODE_ELEMENT;
9302 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9303 ok(hr == S_OK, "got 0x%08x\n", hr);
9304 ok(newnode != NULL, "got %p\n", newnode);
9307 node = (void*)0xdeadbeef;
9308 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9309 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9310 ok(node == NULL, "got %p\n", node);
9311 IXMLDOMNode_Release(newnode);
9313 /* pi to attribute */
9315 V_I4(&v) = NODE_PROCESSING_INSTRUCTION;
9317 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9318 ok(hr == S_OK, "got 0x%08x\n", hr);
9319 ok(newnode != NULL, "got %p\n", newnode);
9322 node = (void*)0xdeadbeef;
9323 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9324 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9325 ok(node == NULL, "got %p\n", node);
9326 IXMLDOMNode_Release(newnode);
9327 IXMLDOMAttribute_Release(attr);
9329 /* insertBefore for elements */
9330 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem1);
9331 ok(hr == S_OK, "got 0x%08x\n", hr);
9333 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem2"), &elem2);
9334 ok(hr == S_OK, "got 0x%08x\n", hr);
9336 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
9337 ok(hr == S_OK, "got 0x%08x\n", hr);
9339 EXPECT_NO_CHILDREN(elem1);
9340 EXPECT_NO_CHILDREN(elem2);
9341 EXPECT_NO_CHILDREN(elem3);
9343 todo_wine EXPECT_REF(elem2, 2);
9347 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9348 ok(hr == S_OK, "got 0x%08x\n", hr);
9349 ok(node == (void*)elem2, "got %p\n", node);
9351 EXPECT_CHILDREN(elem1);
9352 todo_wine EXPECT_REF(elem2, 3);
9353 IXMLDOMNode_Release(node);
9355 /* again for already linked node */
9358 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9359 ok(hr == S_OK, "got 0x%08x\n", hr);
9360 ok(node == (void*)elem2, "got %p\n", node);
9362 EXPECT_CHILDREN(elem1);
9364 /* increments each time */
9365 todo_wine EXPECT_REF(elem2, 3);
9366 IXMLDOMNode_Release(node);
9368 /* try to add to another element */
9370 node = (void*)0xdeadbeef;
9371 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem2, v, &node);
9372 ok(hr == S_OK, "got 0x%08x\n", hr);
9373 ok(node == (void*)elem2, "got %p\n", node);
9375 EXPECT_CHILDREN(elem3);
9376 EXPECT_NO_CHILDREN(elem1);
9378 IXMLDOMNode_Release(node);
9380 /* cross document case - try to add as child to a node created with other doc */
9381 doc2 = create_document(&IID_IXMLDOMDocument);
9383 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem4);
9384 ok(hr == S_OK, "got 0x%08x\n", hr);
9385 todo_wine EXPECT_REF(elem4, 2);
9387 /* same name, another instance */
9388 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem5);
9389 ok(hr == S_OK, "got 0x%08x\n", hr);
9390 todo_wine EXPECT_REF(elem5, 2);
9392 todo_wine EXPECT_REF(elem3, 2);
9395 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem4, v, &node);
9396 ok(hr == S_OK, "got 0x%08x\n", hr);
9397 ok(node == (void*)elem4, "got %p\n", node);
9398 todo_wine EXPECT_REF(elem4, 3);
9399 todo_wine EXPECT_REF(elem3, 2);
9400 IXMLDOMNode_Release(node);
9404 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem5, v, &node);
9405 ok(hr == S_OK, "got 0x%08x\n", hr);
9406 ok(node == (void*)elem5, "got %p\n", node);
9407 todo_wine EXPECT_REF(elem4, 2);
9408 todo_wine EXPECT_REF(elem5, 3);
9409 IXMLDOMNode_Release(node);
9411 IXMLDOMDocument_Release(doc2);
9413 IXMLDOMElement_Release(elem1);
9414 IXMLDOMElement_Release(elem2);
9415 IXMLDOMElement_Release(elem3);
9416 IXMLDOMElement_Release(elem4);
9417 IXMLDOMElement_Release(elem5);
9419 /* elements with same default namespace */
9421 V_I4(&v) = NODE_ELEMENT;
9423 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
9424 ok(hr == S_OK, "got 0x%08x\n", hr);
9425 ok(elem1 != NULL, "got %p\n", elem1);
9428 V_I4(&v) = NODE_ELEMENT;
9430 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem2);
9431 ok(hr == S_OK, "got 0x%08x\n", hr);
9432 ok(elem2 != NULL, "got %p\n", elem2);
9434 /* check contents so far */
9436 hr = IXMLDOMElement_get_xml(elem1, &p);
9437 ok(hr == S_OK, "got 0x%08x\n", hr);
9438 ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9442 hr = IXMLDOMElement_get_xml(elem2, &p);
9443 ok(hr == S_OK, "got 0x%08x\n", hr);
9444 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9448 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
9449 ok(hr == S_OK, "got 0x%08x\n", hr);
9451 /* get_xml depends on context, for top node it omits child namespace attribute,
9452 but at child level it's still returned */
9454 hr = IXMLDOMElement_get_xml(elem1, &p);
9455 ok(hr == S_OK, "got 0x%08x\n", hr);
9456 todo_wine ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"><elem2/></elem1>")),
9457 "got %s\n", wine_dbgstr_w(p));
9461 hr = IXMLDOMElement_get_xml(elem2, &p);
9462 ok(hr == S_OK, "got 0x%08x\n", hr);
9463 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9466 IXMLDOMElement_Release(elem1);
9467 IXMLDOMElement_Release(elem2);
9469 /* child without default namespace added to node with default namespace */
9471 V_I4(&v) = NODE_ELEMENT;
9473 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
9474 ok(hr == S_OK, "got 0x%08x\n", hr);
9475 ok(elem1 != NULL, "got %p\n", elem1);
9478 V_I4(&v) = NODE_ELEMENT;
9480 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), NULL, (IXMLDOMNode**)&elem2);
9481 ok(hr == S_OK, "got 0x%08x\n", hr);
9482 ok(elem2 != NULL, "got %p\n", elem2);
9484 EXPECT_REF(elem2, 1);
9486 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
9487 ok(hr == S_OK, "got 0x%08x\n", hr);
9488 EXPECT_REF(elem2, 1);
9491 hr = IXMLDOMElement_get_xml(elem2, &p);
9492 ok(hr == S_OK, "got 0x%08x\n", hr);
9493 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
9496 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem2, NULL);
9497 ok(hr == S_OK, "got 0x%08x\n", hr);
9500 hr = IXMLDOMElement_get_xml(elem2, &p);
9501 ok(hr == S_OK, "got 0x%08x\n", hr);
9502 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
9505 IXMLDOMElement_Release(elem1);
9506 IXMLDOMElement_Release(elem2);
9507 IXMLDOMDocument_Release(doc);
9510 static void test_appendChild(void)
9512 IXMLDOMDocument *doc, *doc2;
9513 IXMLDOMElement *elem, *elem2;
9516 doc = create_document(&IID_IXMLDOMDocument);
9517 doc2 = create_document(&IID_IXMLDOMDocument);
9519 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
9520 ok(hr == S_OK, "got 0x%08x\n", hr);
9522 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem2"), &elem2);
9523 ok(hr == S_OK, "got 0x%08x\n", hr);
9526 todo_wine EXPECT_REF(elem, 2);
9527 EXPECT_REF(doc2, 1);
9528 todo_wine EXPECT_REF(elem2, 2);
9529 EXPECT_NO_CHILDREN(doc);
9530 EXPECT_NO_CHILDREN(doc2);
9532 /* append from another document */
9533 hr = IXMLDOMDocument_appendChild(doc2, (IXMLDOMNode*)elem, NULL);
9534 ok(hr == S_OK, "got 0x%08x\n", hr);
9537 todo_wine EXPECT_REF(elem, 2);
9538 EXPECT_REF(doc2, 1);
9539 todo_wine EXPECT_REF(elem2, 2);
9540 EXPECT_NO_CHILDREN(doc);
9541 EXPECT_CHILDREN(doc2);
9543 IXMLDOMElement_Release(elem);
9544 IXMLDOMElement_Release(elem2);
9545 IXMLDOMDocument_Release(doc);
9546 IXMLDOMDocument_Release(doc2);
9549 static void test_get_doctype(void)
9551 IXMLDOMDocumentType *doctype;
9552 IXMLDOMDocument *doc;
9555 doc = create_document(&IID_IXMLDOMDocument);
9557 hr = IXMLDOMDocument_get_doctype(doc, NULL);
9558 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9560 doctype = (void*)0xdeadbeef;
9561 hr = IXMLDOMDocument_get_doctype(doc, &doctype);
9562 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9563 ok(doctype == NULL, "got %p\n", doctype);
9565 IXMLDOMDocument_Release(doc);
9568 static void test_get_tagName(void)
9570 IXMLDOMDocument *doc;
9571 IXMLDOMElement *elem, *elem2;
9575 doc = create_document(&IID_IXMLDOMDocument);
9577 hr = IXMLDOMDocument_createElement(doc, _bstr_("element"), &elem);
9578 ok(hr == S_OK, "got 0x%08x\n", hr);
9580 hr = IXMLDOMElement_get_tagName(elem, NULL);
9581 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9584 hr = IXMLDOMElement_get_tagName(elem, &str);
9585 ok(hr == S_OK, "got 0x%08x\n", hr);
9586 ok(!lstrcmpW(str, _bstr_("element")), "got %s\n", wine_dbgstr_w(str));
9589 hr = IXMLDOMDocument_createElement(doc, _bstr_("s:element"), &elem2);
9590 ok(hr == S_OK, "got 0x%08x\n", hr);
9593 hr = IXMLDOMElement_get_tagName(elem2, &str);
9594 ok(hr == S_OK, "got 0x%08x\n", hr);
9595 ok(!lstrcmpW(str, _bstr_("s:element")), "got %s\n", wine_dbgstr_w(str));
9598 IXMLDOMDocument_Release(elem);
9599 IXMLDOMDocument_Release(elem2);
9600 IXMLDOMDocument_Release(doc);
9604 typedef struct _get_datatype_t {
9611 static const get_datatype_t get_datatype[] = {
9612 { NODE_ELEMENT, "element", VT_NULL, S_FALSE },
9613 { NODE_ATTRIBUTE, "attr", VT_NULL, S_FALSE },
9614 { NODE_TEXT, "text", VT_NULL, S_FALSE },
9615 { NODE_CDATA_SECTION , "cdata", VT_NULL, S_FALSE },
9616 { NODE_ENTITY_REFERENCE, "entityref", VT_NULL, S_FALSE },
9617 { NODE_PROCESSING_INSTRUCTION, "pi", VT_NULL, S_FALSE },
9618 { NODE_COMMENT, "comment", VT_NULL, S_FALSE },
9619 { NODE_DOCUMENT_FRAGMENT, "docfrag", VT_NULL, S_FALSE },
9623 static void test_get_dataType(void)
9625 IXMLDOMDocument *doc;
9626 const get_datatype_t *entry = get_datatype;
9628 doc = create_document(&IID_IXMLDOMDocument);
9632 IXMLDOMNode *node = NULL;
9637 V_I4(&var) = entry->type;
9638 hr = IXMLDOMDocument_createNode(doc, var, _bstr_(entry->name), NULL, &node);
9639 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9641 hr = IXMLDOMNode_get_dataType(node, NULL);
9642 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9645 hr = IXMLDOMNode_get_dataType(node, &type);
9646 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9647 hr, entry->hr, entry->type);
9648 ok(V_VT(&type) == entry->vt, "got %d, expected %d. node type %d\n",
9649 V_VT(&type), entry->vt, entry->type);
9650 VariantClear(&type);
9652 IXMLDOMNode_Release(node);
9657 IXMLDOMDocument_Release(doc);
9661 typedef struct _get_node_typestring_t {
9664 } get_node_typestring_t;
9666 static const get_node_typestring_t get_node_typestring[] = {
9667 { NODE_ELEMENT, "element" },
9668 { NODE_ATTRIBUTE, "attribute" },
9669 { NODE_TEXT, "text" },
9670 { NODE_CDATA_SECTION , "cdatasection" },
9671 { NODE_ENTITY_REFERENCE, "entityreference" },
9672 { NODE_PROCESSING_INSTRUCTION, "processinginstruction" },
9673 { NODE_COMMENT, "comment" },
9674 { NODE_DOCUMENT_FRAGMENT, "documentfragment" },
9678 static void test_get_nodeTypeString(void)
9680 const get_node_typestring_t *entry = get_node_typestring;
9681 IXMLDOMDocument *doc;
9685 doc = create_document(&IID_IXMLDOMDocument);
9687 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
9688 ok(hr == S_OK, "got 0x%08x\n", hr);
9689 ok(!lstrcmpW(str, _bstr_("document")), "got string %s\n", wine_dbgstr_w(str));
9694 IXMLDOMNode *node = NULL;
9698 V_I4(&var) = entry->type;
9699 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9700 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9702 hr = IXMLDOMNode_get_nodeTypeString(node, NULL);
9703 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9705 hr = IXMLDOMNode_get_nodeTypeString(node, &str);
9706 ok(hr == S_OK, "got 0x%08x\n", hr);
9707 ok(!lstrcmpW(str, _bstr_(entry->string)), "got string %s, expected %s. node type %d\n",
9708 wine_dbgstr_w(str), entry->string, entry->type);
9710 IXMLDOMNode_Release(node);
9715 IXMLDOMDocument_Release(doc);
9719 typedef struct _get_attributes_t {
9724 static const get_attributes_t get_attributes[] = {
9725 { NODE_ATTRIBUTE, S_FALSE },
9726 { NODE_TEXT, S_FALSE },
9727 { NODE_CDATA_SECTION , S_FALSE },
9728 { NODE_ENTITY_REFERENCE, S_FALSE },
9729 { NODE_PROCESSING_INSTRUCTION, S_FALSE },
9730 { NODE_COMMENT, S_FALSE },
9731 { NODE_DOCUMENT_FRAGMENT, S_FALSE },
9735 static void test_get_attributes(void)
9737 const get_attributes_t *entry = get_attributes;
9738 IXMLDOMNamedNodeMap *map;
9739 IXMLDOMDocument *doc;
9740 IXMLDOMNode *node, *node2;
9746 doc = create_document(&IID_IXMLDOMDocument);
9748 str = SysAllocString( szComplete4 );
9749 hr = IXMLDOMDocument_loadXML(doc, str, &b);
9750 ok(hr == S_OK, "got %08x\n", hr);
9753 hr = IXMLDOMDocument_get_attributes(doc, NULL);
9754 ok(hr == E_INVALIDARG, "got %08x\n", hr);
9756 map = (void*)0xdeadbeef;
9757 hr = IXMLDOMDocument_get_attributes(doc, &map);
9758 ok(hr == S_FALSE, "got %08x\n", hr);
9759 ok(map == NULL, "got %p\n", map);
9761 /* first child is <?xml ?> */
9762 hr = IXMLDOMDocument_get_firstChild(doc, &node);
9763 ok(hr == S_OK, "got %08x\n", hr);
9765 hr = IXMLDOMNode_get_attributes(node, &map);
9766 ok(hr == S_OK, "got %08x\n", hr);
9769 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9770 EXPECT_HR(hr, S_OK);
9771 todo_wine ok(length == 1, "got %d\n", length);
9773 if (hr == S_OK && length == 1)
9775 IXMLDOMAttribute *attr;
9780 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9781 EXPECT_HR(hr, S_OK);
9782 ok(node != NULL, "got %p\n", node2);
9784 hr = IXMLDOMNode_get_nodeName(node2, &str);
9785 EXPECT_HR(hr, S_OK);
9786 ok(!lstrcmpW(str, _bstr_("version")), "got %s\n", wine_dbgstr_w(str));
9790 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9791 EXPECT_HR(hr, S_OK);
9792 ok(length == 1, "got %d\n", length);
9795 hr = IXMLDOMNode_get_nodeType(node2, &type);
9796 EXPECT_HR(hr, S_OK);
9797 ok(type == NODE_ATTRIBUTE, "got %d\n", type);
9799 hr = IXMLDOMNode_get_xml(node, &str);
9800 EXPECT_HR(hr, S_OK);
9801 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9804 hr = IXMLDOMNode_get_text(node, &str);
9805 EXPECT_HR(hr, S_OK);
9806 ok(!lstrcmpW(str, _bstr_("version=\"1.0\"")), "got %s\n", wine_dbgstr_w(str));
9809 hr = IXMLDOMNamedNodeMap_removeNamedItem(map, _bstr_("version"), NULL);
9810 EXPECT_HR(hr, S_OK);
9813 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9814 EXPECT_HR(hr, S_OK);
9815 ok(length == 0, "got %d\n", length);
9817 hr = IXMLDOMNode_get_xml(node, &str);
9818 EXPECT_HR(hr, S_OK);
9819 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9822 hr = IXMLDOMNode_get_text(node, &str);
9823 EXPECT_HR(hr, S_OK);
9824 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
9827 IXMLDOMNamedNodeMap_Release(map);
9829 hr = IXMLDOMNode_get_attributes(node, &map);
9830 ok(hr == S_OK, "got %08x\n", hr);
9833 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9834 EXPECT_HR(hr, S_OK);
9835 ok(length == 0, "got %d\n", length);
9837 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("encoding"), &attr);
9838 EXPECT_HR(hr, S_OK);
9841 V_BSTR(&v) = _bstr_("UTF-8");
9842 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
9843 EXPECT_HR(hr, S_OK);
9845 EXPECT_REF(attr, 2);
9846 hr = IXMLDOMNamedNodeMap_setNamedItem(map, (IXMLDOMNode*)attr, NULL);
9847 EXPECT_HR(hr, S_OK);
9848 EXPECT_REF(attr, 2);
9850 hr = IXMLDOMNode_get_attributes(node, &map);
9851 ok(hr == S_OK, "got %08x\n", hr);
9854 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9855 EXPECT_HR(hr, S_OK);
9856 ok(length == 1, "got %d\n", length);
9858 hr = IXMLDOMNode_get_xml(node, &str);
9859 EXPECT_HR(hr, S_OK);
9860 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9863 hr = IXMLDOMNode_get_text(node, &str);
9864 EXPECT_HR(hr, S_OK);
9865 ok(!lstrcmpW(str, _bstr_("encoding=\"UTF-8\"")), "got %s\n", wine_dbgstr_w(str));
9868 IXMLDOMNamedNodeMap_Release(map);
9869 IXMLDOMNode_Release(node2);
9872 IXMLDOMNode_Release(node);
9874 /* last child is element */
9876 hr = IXMLDOMDocument_get_lastChild(doc, &node);
9877 ok(hr == S_OK, "got %08x\n", hr);
9880 EXPECT_REF(node, 1);
9881 hr = IXMLDOMNode_get_attributes(node, &map);
9882 ok(hr == S_OK, "got %08x\n", hr);
9883 EXPECT_REF(node, 1);
9887 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9888 ok(hr == S_OK, "got %08x\n", hr);
9889 EXPECT_REF(node, 1);
9890 EXPECT_REF(node2, 1);
9893 IXMLDOMNode_Release(node2);
9895 /* release node before map release, map still works */
9896 IXMLDOMNode_Release(node);
9899 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9900 ok(hr == S_OK, "got %08x\n", hr);
9901 ok(length == 1, "got %d\n", length);
9904 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9905 ok(hr == S_OK, "got %08x\n", hr);
9906 EXPECT_REF(node2, 1);
9907 IXMLDOMNode_Release(node2);
9909 IXMLDOMNamedNodeMap_Release(map);
9918 V_I4(&var) = entry->type;
9919 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9920 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9922 hr = IXMLDOMNode_get_attributes(node, NULL);
9923 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9925 map = (void*)0xdeadbeef;
9926 hr = IXMLDOMNode_get_attributes(node, &map);
9927 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9928 hr, entry->hr, entry->type);
9929 ok(map == NULL, "got %p\n", map);
9931 IXMLDOMNode_Release(node);
9936 IXMLDOMDocument_Release(doc);
9940 static void test_selection(void)
9942 IXMLDOMSelection *selection;
9943 IXMLDOMNodeList *list;
9944 IXMLDOMDocument *doc;
9948 doc = create_document(&IID_IXMLDOMDocument);
9950 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
9951 EXPECT_HR(hr, S_OK);
9953 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list);
9954 EXPECT_HR(hr, S_OK);
9956 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
9957 EXPECT_HR(hr, S_OK);
9958 IXMLDOMSelection_Release(selection);
9960 IXMLDOMNodeList_Release(list);
9962 hr = IXMLDOMDocument_get_childNodes(doc, &list);
9963 EXPECT_HR(hr, S_OK);
9965 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
9966 EXPECT_HR(hr, E_NOINTERFACE);
9968 IXMLDOMNodeList_Release(list);
9970 IXMLDOMDocument_Release(doc);
9974 static void test_load(void)
9976 IXMLDOMDocument *doc;
9977 IXMLDOMNodeList *list;
9983 BSTR path, bstr1, bstr2;
9987 /* prepare a file */
9988 hfile = CreateFileA("test.xml", GENERIC_WRITE|GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
9989 ok(hfile != INVALID_HANDLE_VALUE, "failed to create test file\n");
9990 if(hfile == INVALID_HANDLE_VALUE) return;
9992 ret = WriteFile(hfile, szNonUnicodeXML, sizeof(szNonUnicodeXML)-1, &written, NULL);
9993 ok(ret, "WriteFile failed\n");
9997 doc = create_document(&IID_IXMLDOMDocument);
9999 path = _bstr_("test.xml");
10001 /* load from path: VT_BSTR */
10002 V_VT(&src) = VT_BSTR;
10003 V_BSTR(&src) = path;
10004 hr = IXMLDOMDocument_load(doc, src, &b);
10005 EXPECT_HR(hr, S_OK);
10006 ok(b == VARIANT_TRUE, "got %d\n", b);
10008 /* load from a path: VT_BSTR|VT_BYREF */
10009 V_VT(&src) = VT_BSTR | VT_BYREF;
10010 V_BSTRREF(&src) = &path;
10011 hr = IXMLDOMDocument_load(doc, src, &b);
10012 EXPECT_HR(hr, S_OK);
10013 ok(b == VARIANT_TRUE, "got %d\n", b);
10015 /* load from a path: VT_BSTR|VT_BYREF, null ptr */
10016 V_VT(&src) = VT_BSTR | VT_BYREF;
10017 V_BSTRREF(&src) = NULL;
10018 hr = IXMLDOMDocument_load(doc, src, &b);
10019 EXPECT_HR(hr, E_INVALIDARG);
10020 ok(b == VARIANT_FALSE, "got %d\n", b);
10022 IXMLDOMDocument_Release(doc);
10024 DeleteFileA("test.xml");
10026 doc = create_document(&IID_IXMLDOMDocument);
10028 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b);
10029 EXPECT_HR(hr, S_OK);
10030 ok(b == VARIANT_TRUE, "got %d\n", b);
10032 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
10033 EXPECT_HR(hr, S_OK);
10034 bstr1 = _bstr_(list_to_string(list));
10036 hr = IXMLDOMNodeList_reset(list);
10037 EXPECT_HR(hr, S_OK);
10039 IXMLDOMDocument_Release(doc);
10041 doc = create_document(&IID_IXMLDOMDocument);
10044 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenA(szExampleXML));
10045 V_VT(&src) = VT_ARRAY|VT_UI1;
10046 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10048 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10049 EXPECT_HR(hr, S_OK);
10050 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10052 memcpy(ptr, szExampleXML, lstrlenA(szExampleXML));
10053 hr = SafeArrayUnlock(V_ARRAY(&src));
10054 EXPECT_HR(hr, S_OK);
10056 hr = IXMLDOMDocument_load(doc, src, &b);
10057 EXPECT_HR(hr, S_OK);
10058 ok(b == VARIANT_TRUE, "got %d\n", b);
10060 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
10061 EXPECT_HR(hr, S_OK);
10062 bstr2 = _bstr_(list_to_string(list));
10064 hr = IXMLDOMNodeList_reset(list);
10065 EXPECT_HR(hr, S_OK);
10067 ok(lstrcmpW(bstr1, bstr2) == 0, "strings not equal: %s : %s\n",
10068 wine_dbgstr_w(bstr1), wine_dbgstr_w(bstr2));
10070 IXMLDOMDocument_Release(doc);
10071 IXMLDOMNodeList_Release(list);
10072 VariantClear(&src);
10074 /* UTF-16 isn't accepted */
10075 doc = create_document(&IID_IXMLDOMDocument);
10077 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenW(szComplete1) * sizeof(WCHAR));
10078 V_VT(&src) = VT_ARRAY|VT_UI1;
10079 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10081 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10082 EXPECT_HR(hr, S_OK);
10083 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10085 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
10086 hr = SafeArrayUnlock(V_ARRAY(&src));
10087 EXPECT_HR(hr, S_OK);
10089 hr = IXMLDOMDocument_load(doc, src, &b);
10090 todo_wine EXPECT_HR(hr, S_FALSE);
10091 todo_wine ok(b == VARIANT_FALSE, "got %d\n", b);
10093 VariantClear(&src);
10095 /* it doesn't like it as a VT_ARRAY|VT_UI2 either */
10096 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI2, 0, lstrlenW(szComplete1));
10097 V_VT(&src) = VT_ARRAY|VT_UI2;
10098 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10100 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10101 EXPECT_HR(hr, S_OK);
10102 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10104 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
10105 hr = SafeArrayUnlock(V_ARRAY(&src));
10106 EXPECT_HR(hr, S_OK);
10108 hr = IXMLDOMDocument_load(doc, src, &b);
10109 todo_wine EXPECT_HR(hr, E_INVALIDARG);
10110 ok(b == VARIANT_FALSE, "got %d\n", b);
10112 VariantClear(&src);
10113 IXMLDOMDocument_Release(doc);
10118 static void test_nsnamespacemanager(void)
10120 static const char xmluriA[] = "http://www.w3.org/XML/1998/namespace";
10121 IMXNamespaceManager *nsmgr;
10122 IVBMXNamespaceManager *mgr2;
10128 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10129 &IID_IMXNamespaceManager, (void**)&nsmgr);
10132 win_skip("MXNamespaceManager is not available\n");
10136 /* IMXNamespaceManager inherits from IUnknown */
10137 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IDispatch, (void**)&disp);
10138 EXPECT_HR(hr, S_OK);
10139 IDispatch_Release(disp);
10141 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IVBMXNamespaceManager, (void**)&mgr2);
10142 EXPECT_HR(hr, S_OK);
10143 IVBMXNamespaceManager_Release(mgr2);
10145 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
10146 EXPECT_HR(hr, S_OK);
10148 /* prefix already added */
10149 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10150 EXPECT_HR(hr, S_FALSE);
10152 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), NULL);
10153 EXPECT_HR(hr, E_INVALIDARG);
10155 /* "xml" and "xmlns" are not allowed here */
10156 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xml"), _bstr_("uri1"));
10157 EXPECT_HR(hr, E_INVALIDARG);
10159 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xmlns"), _bstr_("uri1"));
10160 EXPECT_HR(hr, E_INVALIDARG);
10162 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, -1, NULL, NULL);
10163 EXPECT_HR(hr, E_FAIL);
10165 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, NULL);
10166 EXPECT_HR(hr, E_POINTER);
10169 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, &len);
10170 EXPECT_HR(hr, S_OK);
10171 ok(len == 3, "got %d\n", len);
10175 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10176 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
10177 ok(len == -1, "got %d\n", len);
10178 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10182 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10183 EXPECT_HR(hr, S_OK);
10184 ok(len == 3, "got %d\n", len);
10185 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10188 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, NULL);
10189 EXPECT_HR(hr, E_INVALIDARG);
10192 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, &len);
10193 EXPECT_HR(hr, E_INVALIDARG);
10194 ok(len == -1, "got %d\n", len);
10196 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, NULL);
10197 EXPECT_HR(hr, E_POINTER);
10200 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, &len);
10201 EXPECT_HR(hr, S_OK);
10202 /* length of "xml" uri is constant */
10203 ok(len == strlen(xmluriA), "got %d\n", len);
10206 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
10207 EXPECT_HR(hr, S_OK);
10208 ok(len == strlen(xmluriA), "got %d\n", len);
10209 ok(!lstrcmpW(buffW, _bstr_(xmluriA)), "got prefix %s\n", wine_dbgstr_w(buffW));
10211 len = strlen(xmluriA)-1;
10213 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
10214 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
10215 ok(len == strlen(xmluriA)-1, "got %d\n", len);
10216 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10218 /* prefix xml1 not defined */
10220 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, NULL, &len);
10221 EXPECT_HR(hr, S_FALSE);
10222 ok(len == 0, "got %d\n", len);
10226 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, buffW, &len);
10227 EXPECT_HR(hr, S_FALSE);
10228 ok(buffW[0] == 0, "got %x\n", buffW[0]);
10229 ok(len == 0, "got %d\n", len);
10231 IMXNamespaceManager_Release(nsmgr);
10236 static void test_nsnamespacemanager_override(void)
10238 IMXNamespaceManager *nsmgr;
10244 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10245 &IID_IMXNamespaceManager, (void**)&nsmgr);
10248 win_skip("MXNamespaceManager is not available\n");
10252 len = sizeof(buffW)/sizeof(WCHAR);
10254 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10255 EXPECT_HR(hr, S_OK);
10256 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10258 len = sizeof(buffW)/sizeof(WCHAR);
10260 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10261 EXPECT_HR(hr, E_FAIL);
10263 hr = IMXNamespaceManager_getAllowOverride(nsmgr, NULL);
10264 EXPECT_HR(hr, E_POINTER);
10267 hr = IMXNamespaceManager_getAllowOverride(nsmgr, &b);
10268 EXPECT_HR(hr, S_OK);
10269 ok(b == VARIANT_TRUE, "got %d\n", b);
10271 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_FALSE);
10272 EXPECT_HR(hr, S_OK);
10274 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10275 EXPECT_HR(hr, S_OK);
10277 len = sizeof(buffW)/sizeof(WCHAR);
10279 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
10280 EXPECT_HR(hr, S_OK);
10281 ok(!lstrcmpW(buffW, _bstr_("ns0 uri")), "got uri %s\n", wine_dbgstr_w(buffW));
10283 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), _bstr_("ns0 uri"));
10284 EXPECT_HR(hr, S_OK);
10286 len = sizeof(buffW)/sizeof(WCHAR);
10288 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10289 EXPECT_HR(hr, S_OK);
10290 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10292 len = sizeof(buffW)/sizeof(WCHAR);
10294 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10295 EXPECT_HR(hr, S_OK);
10296 ok(!lstrcmpW(buffW, _bstr_("ns0")), "got prefix %s\n", wine_dbgstr_w(buffW));
10298 len = sizeof(buffW)/sizeof(WCHAR);
10300 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 2, buffW, &len);
10301 EXPECT_HR(hr, S_OK);
10302 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
10304 /* new prefix placed at index 1 always */
10305 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
10306 EXPECT_HR(hr, S_OK);
10308 len = sizeof(buffW)/sizeof(WCHAR);
10310 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10311 EXPECT_HR(hr, S_OK);
10312 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got prefix %s\n", wine_dbgstr_w(buffW));
10314 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_(""), NULL);
10315 todo_wine EXPECT_HR(hr, E_FAIL);
10317 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
10318 EXPECT_HR(hr, E_FAIL);
10320 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10321 EXPECT_HR(hr, E_FAIL);
10323 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_TRUE);
10324 EXPECT_HR(hr, S_OK);
10326 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri override"));
10327 EXPECT_HR(hr, S_FALSE);
10329 len = sizeof(buffW)/sizeof(WCHAR);
10331 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
10332 EXPECT_HR(hr, S_OK);
10333 ok(!lstrcmpW(buffW, _bstr_("ns0 uri override")), "got uri %s\n", wine_dbgstr_w(buffW));
10335 len = sizeof(buffW)/sizeof(WCHAR);
10337 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 3, buffW, &len);
10338 EXPECT_HR(hr, S_OK);
10339 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
10341 IMXNamespaceManager_Release(nsmgr);
10348 IXMLDOMDocument *doc;
10351 hr = CoInitialize( NULL );
10352 ok( hr == S_OK, "failed to init com\n");
10353 if (hr != S_OK) return;
10357 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc );
10360 win_skip("IXMLDOMDocument is not available (0x%08x)\n", hr);
10364 IXMLDOMDocument_Release(doc);
10367 test_persiststreaminit();
10371 test_getElementsByTagName();
10373 test_get_childNodes();
10374 test_get_firstChild();
10375 test_get_lastChild();
10376 test_removeChild();
10377 test_replaceChild();
10378 test_removeNamedItem();
10379 test_IXMLDOMDocument2();
10385 test_nodeTypeTests();
10387 test_testTransforms();
10389 test_FormattingXML();
10390 test_nodeTypedValue();
10391 test_TransformWithLoadingLocalFile();
10392 test_put_nodeValue();
10393 test_document_IObjectSafety();
10395 test_getQualifiedItem();
10396 test_removeQualifiedItem();
10397 test_get_ownerDocument();
10398 test_setAttributeNode();
10399 test_put_dataType();
10402 test_default_properties();
10403 test_selectSingleNode();
10405 test_createProcessingInstruction();
10406 test_put_nodeTypedValue();
10408 test_insertBefore();
10409 test_appendChild();
10410 test_get_doctype();
10411 test_get_tagName();
10412 test_get_dataType();
10413 test_get_nodeTypeString();
10414 test_get_attributes();
10418 test_xsltemplate();
10420 test_nsnamespacemanager();
10421 test_nsnamespacemanager_override();