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, "Exected E_INVALIDARG got %08x\n", r);
3063 r = IXMLDOMNodeList_get_length(list, NULL);
3064 ok(r == E_INVALIDARG, "Exected 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, "Exected 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, "hasChildNoes 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 wrond 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(attr_cnt1 == 3, "Attribute count should be 3 (%d)\n", attr_cnt1);
5557 IXMLDOMNamedNodeMap_Release(mapAttr);
5559 ok(length != length1, "wrong Child count (%d, %d)\n", length, length1);
5560 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
5561 IXMLDOMNode_Release(node_clone);
5563 IXMLDOMNode_Release(node);
5564 IXMLDOMDocument_Release(doc);
5568 static void test_xmlTypes(void)
5570 IXMLDOMDocument *doc;
5571 IXMLDOMElement *pRoot;
5573 IXMLDOMComment *pComment;
5574 IXMLDOMElement *pElement;
5575 IXMLDOMAttribute *pAttribute;
5576 IXMLDOMNamedNodeMap *pAttribs;
5577 IXMLDOMCDATASection *pCDataSec;
5578 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
5579 IXMLDOMDocumentFragment *pDocFrag = NULL;
5580 IXMLDOMEntityReference *pEntityRef = NULL;
5582 IXMLDOMNode *pNextChild;
5586 doc = create_document(&IID_IXMLDOMDocument);
5589 pNextChild = (void*)0xdeadbeef;
5590 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
5591 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5593 pNextChild = (void*)0xdeadbeef;
5594 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
5595 ok(hr == S_FALSE, "ret %08x\n", hr );
5596 ok(pNextChild == NULL, "pDocChild not NULL\n");
5598 /* test previous Sibling */
5599 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
5600 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5602 pNextChild = (void*)0xdeadbeef;
5603 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
5604 ok(hr == S_FALSE, "ret %08x\n", hr );
5605 ok(pNextChild == NULL, "pNextChild not NULL\n");
5607 /* test get_dataType */
5608 V_VT(&v) = VT_EMPTY;
5609 hr = IXMLDOMDocument_get_dataType(doc, &v);
5610 ok(hr == S_FALSE, "ret %08x\n", hr );
5611 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5614 /* test implementation */
5615 hr = IXMLDOMDocument_get_implementation(doc, NULL);
5616 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5618 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
5619 ok(hr == S_OK, "ret %08x\n", hr );
5622 VARIANT_BOOL hasFeature = VARIANT_TRUE;
5623 BSTR sEmpty = SysAllocStringLen(NULL, 0);
5625 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
5626 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5628 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
5629 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5631 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
5632 ok(hr == S_OK, "ret %08x\n", hr );
5633 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5635 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
5636 ok(hr == S_OK, "ret %08x\n", hr );
5637 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
5639 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
5640 ok(hr == S_OK, "ret %08x\n", hr );
5641 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
5643 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
5644 ok(hr == S_OK, "ret %08x\n", hr );
5645 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5647 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
5648 ok(hr == S_OK, "ret %08x\n", hr );
5649 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5651 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
5652 ok(hr == S_OK, "ret %08x\n", hr );
5653 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5655 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
5656 ok(hr == S_OK, "ret %08x\n", hr );
5657 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5659 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
5660 ok(hr == S_OK, "ret %08x\n", hr );
5661 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5663 SysFreeString(sEmpty);
5664 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
5667 pRoot = (IXMLDOMElement*)0x1;
5668 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
5669 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5670 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
5672 pRoot = (IXMLDOMElement*)0x1;
5673 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
5674 ok(hr == E_FAIL, "ret %08x\n", hr );
5675 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
5677 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5678 ok(hr == S_OK, "ret %08x\n", hr );
5681 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5682 ok(hr == S_OK, "ret %08x\n", hr );
5686 str = SysAllocString(szComment);
5687 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
5689 ok(hr == S_OK, "ret %08x\n", hr );
5692 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
5693 ok(hr == S_OK, "ret %08x\n", hr );
5695 hr = IXMLDOMComment_get_nodeName(pComment, &str);
5696 ok(hr == S_OK, "ret %08x\n", hr );
5697 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
5700 hr = IXMLDOMComment_get_xml(pComment, &str);
5701 ok(hr == S_OK, "ret %08x\n", hr );
5702 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
5705 /* put data Tests */
5706 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
5707 ok(hr == S_OK, "ret %08x\n", hr );
5709 /* get data Tests */
5710 hr = IXMLDOMComment_get_data(pComment, &str);
5711 ok(hr == S_OK, "ret %08x\n", hr );
5712 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
5715 /* get data Tests */
5716 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
5717 ok(hr == S_OK, "ret %08x\n", hr );
5718 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
5719 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
5722 /* Confirm XML text is good */
5723 hr = IXMLDOMComment_get_xml(pComment, &str);
5724 ok(hr == S_OK, "ret %08x\n", hr );
5725 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
5728 /* Confirm we get the put_data Text back */
5729 hr = IXMLDOMComment_get_text(pComment, &str);
5730 ok(hr == S_OK, "ret %08x\n", hr );
5731 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
5734 /* test length property */
5735 hr = IXMLDOMComment_get_length(pComment, &len);
5736 ok(hr == S_OK, "ret %08x\n", hr );
5737 ok(len == 21, "expected 21 got %d\n", len);
5739 /* test substringData */
5740 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
5741 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5743 /* test substringData - Invalid offset */
5744 str = (BSTR)&szElement;
5745 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
5746 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5747 ok( str == NULL, "incorrect string\n");
5749 /* test substringData - Invalid offset */
5750 str = (BSTR)&szElement;
5751 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
5752 ok(hr == S_FALSE, "ret %08x\n", hr );
5753 ok( str == NULL, "incorrect string\n");
5755 /* test substringData - Invalid size */
5756 str = (BSTR)&szElement;
5757 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
5758 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5759 ok( str == NULL, "incorrect string\n");
5761 /* test substringData - Invalid size */
5762 str = (BSTR)&szElement;
5763 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
5764 ok(hr == S_FALSE, "ret %08x\n", hr );
5765 ok( str == NULL, "incorrect string\n");
5767 /* test substringData - Start of string */
5768 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
5769 ok(hr == S_OK, "ret %08x\n", hr );
5770 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
5773 /* test substringData - Middle of string */
5774 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
5775 ok(hr == S_OK, "ret %08x\n", hr );
5776 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
5779 /* test substringData - End of string */
5780 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
5781 ok(hr == S_OK, "ret %08x\n", hr );
5782 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
5785 /* test appendData */
5786 hr = IXMLDOMComment_appendData(pComment, NULL);
5787 ok(hr == S_OK, "ret %08x\n", hr );
5789 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
5790 ok(hr == S_OK, "ret %08x\n", hr );
5792 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
5793 ok(hr == S_OK, "ret %08x\n", hr );
5795 hr = IXMLDOMComment_get_text(pComment, &str);
5796 ok(hr == S_OK, "ret %08x\n", hr );
5797 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5800 /* test insertData */
5801 str = SysAllocStringLen(NULL, 0);
5802 hr = IXMLDOMComment_insertData(pComment, -1, str);
5803 ok(hr == S_OK, "ret %08x\n", hr );
5805 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
5806 ok(hr == S_OK, "ret %08x\n", hr );
5808 hr = IXMLDOMComment_insertData(pComment, 1000, str);
5809 ok(hr == S_OK, "ret %08x\n", hr );
5811 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
5812 ok(hr == S_OK, "ret %08x\n", hr );
5814 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
5815 ok(hr == S_OK, "ret %08x\n", hr );
5817 hr = IXMLDOMComment_insertData(pComment, 0, str);
5818 ok(hr == S_OK, "ret %08x\n", hr );
5821 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
5822 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5824 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
5825 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5827 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
5828 ok(hr == S_OK, "ret %08x\n", hr );
5830 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
5831 ok(hr == S_OK, "ret %08x\n", hr );
5833 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
5834 ok(hr == S_OK, "ret %08x\n", hr );
5836 hr = IXMLDOMComment_get_text(pComment, &str);
5837 ok(hr == S_OK, "ret %08x\n", hr );
5838 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5842 /* invalid arguments */
5843 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
5844 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5846 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
5847 ok(hr == S_OK, "ret %08x\n", hr );
5849 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
5850 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5852 hr = IXMLDOMComment_get_length(pComment, &len);
5853 ok(hr == S_OK, "ret %08x\n", hr );
5854 ok(len == 43, "expected 43 got %d\n", len);
5856 hr = IXMLDOMComment_deleteData(pComment, len, 1);
5857 ok(hr == S_OK, "ret %08x\n", hr );
5859 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
5860 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5862 /* delete from start */
5863 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
5864 ok(hr == S_OK, "ret %08x\n", hr );
5866 hr = IXMLDOMComment_get_length(pComment, &len);
5867 ok(hr == S_OK, "ret %08x\n", hr );
5868 ok(len == 38, "expected 38 got %d\n", len);
5870 hr = IXMLDOMComment_get_text(pComment, &str);
5871 ok(hr == S_OK, "ret %08x\n", hr );
5872 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5875 /* delete from end */
5876 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
5877 ok(hr == S_OK, "ret %08x\n", hr );
5879 hr = IXMLDOMComment_get_length(pComment, &len);
5880 ok(hr == S_OK, "ret %08x\n", hr );
5881 ok(len == 35, "expected 35 got %d\n", len);
5883 hr = IXMLDOMComment_get_text(pComment, &str);
5884 ok(hr == S_OK, "ret %08x\n", hr );
5885 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5888 /* delete from inside */
5889 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
5890 ok(hr == S_OK, "ret %08x\n", hr );
5892 hr = IXMLDOMComment_get_length(pComment, &len);
5893 ok(hr == S_OK, "ret %08x\n", hr );
5894 ok(len == 2, "expected 2 got %d\n", len);
5896 hr = IXMLDOMComment_get_text(pComment, &str);
5897 ok(hr == S_OK, "ret %08x\n", hr );
5898 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5901 /* delete whole data ... */
5902 hr = IXMLDOMComment_get_length(pComment, &len);
5903 ok(hr == S_OK, "ret %08x\n", hr );
5905 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5906 ok(hr == S_OK, "ret %08x\n", hr );
5907 /* ... and try again with empty string */
5908 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5909 ok(hr == S_OK, "ret %08x\n", hr );
5911 /* ::replaceData() */
5913 V_BSTR(&v) = SysAllocString(szstr1);
5914 hr = IXMLDOMComment_put_nodeValue(pComment, v);
5915 ok(hr == S_OK, "ret %08x\n", hr );
5918 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
5919 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5920 hr = IXMLDOMComment_get_text(pComment, &str);
5921 ok(hr == S_OK, "ret %08x\n", hr );
5922 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5925 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
5926 ok(hr == S_OK, "ret %08x\n", hr );
5927 hr = IXMLDOMComment_get_text(pComment, &str);
5928 ok(hr == S_OK, "ret %08x\n", hr );
5929 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5932 /* NULL pointer means delete */
5933 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
5934 ok(hr == S_OK, "ret %08x\n", hr );
5935 hr = IXMLDOMComment_get_text(pComment, &str);
5936 ok(hr == S_OK, "ret %08x\n", hr );
5937 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5940 /* empty string means delete */
5941 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
5942 ok(hr == S_OK, "ret %08x\n", hr );
5943 hr = IXMLDOMComment_get_text(pComment, &str);
5944 ok(hr == S_OK, "ret %08x\n", hr );
5945 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5948 /* zero count means insert */
5949 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
5950 ok(hr == S_OK, "ret %08x\n", hr );
5951 hr = IXMLDOMComment_get_text(pComment, &str);
5952 ok(hr == S_OK, "ret %08x\n", hr );
5953 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5956 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
5957 ok(hr == S_OK, "ret %08x\n", hr );
5959 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
5960 ok(hr == S_OK, "ret %08x\n", hr );
5961 hr = IXMLDOMComment_get_text(pComment, &str);
5962 ok(hr == S_OK, "ret %08x\n", hr );
5963 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5966 /* nonempty string, count greater than its length */
5967 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
5968 ok(hr == S_OK, "ret %08x\n", hr );
5969 hr = IXMLDOMComment_get_text(pComment, &str);
5970 ok(hr == S_OK, "ret %08x\n", hr );
5971 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5974 /* nonempty string, count less than its length */
5975 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
5976 ok(hr == S_OK, "ret %08x\n", hr );
5977 hr = IXMLDOMComment_get_text(pComment, &str);
5978 ok(hr == S_OK, "ret %08x\n", hr );
5979 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5982 IXMLDOMComment_Release(pComment);
5986 str = SysAllocString(szElement);
5987 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
5989 ok(hr == S_OK, "ret %08x\n", hr );
5992 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5993 ok(hr == S_OK, "ret %08x\n", hr );
5995 hr = IXMLDOMElement_get_nodeName(pElement, &str);
5996 ok(hr == S_OK, "ret %08x\n", hr );
5997 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
6000 hr = IXMLDOMElement_get_xml(pElement, &str);
6001 ok(hr == S_OK, "ret %08x\n", hr );
6002 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
6006 pAttribute = (IXMLDOMAttribute*)0x1;
6007 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
6008 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6009 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
6011 pAttribute = (IXMLDOMAttribute*)0x1;
6012 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
6013 ok(hr == E_FAIL, "ret %08x\n", hr );
6014 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
6016 str = SysAllocString(szAttribute);
6017 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
6019 ok(hr == S_OK, "ret %08x\n", hr );
6022 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
6024 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
6025 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6027 pNextChild = (IXMLDOMNode *)0x1;
6028 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
6029 ok(hr == S_FALSE, "ret %08x\n", hr );
6030 ok(pNextChild == NULL, "pNextChild not NULL\n");
6032 /* test Previous Sibling*/
6033 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
6034 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6036 pNextChild = (IXMLDOMNode *)0x1;
6037 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
6038 ok(hr == S_FALSE, "ret %08x\n", hr );
6039 ok(pNextChild == NULL, "pNextChild not NULL\n");
6041 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
6042 ok(hr == E_FAIL, "ret %08x\n", hr );
6043 ok(pNewChild == NULL, "pNewChild not NULL\n");
6045 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
6046 ok(hr == S_OK, "ret %08x\n", hr );
6049 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
6050 ok(hr == S_OK, "ret %08x\n", hr );
6052 IXMLDOMNamedNodeMap_Release(pAttribs);
6055 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6056 ok(hr == S_OK, "ret %08x\n", hr );
6057 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
6061 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6062 ok(hr == S_OK, "ret %08x\n", hr );
6063 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
6066 /* test name property */
6067 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
6068 ok(hr == S_OK, "ret %08x\n", hr );
6069 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
6072 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
6073 ok(hr == S_OK, "ret %08x\n", hr );
6074 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
6077 IXMLDOMAttribute_Release(pAttribute);
6079 /* Check Element again with the Add Attribute*/
6080 hr = IXMLDOMElement_get_xml(pElement, &str);
6081 ok(hr == S_OK, "ret %08x\n", hr );
6082 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
6086 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
6087 ok(hr == S_OK, "ret %08x\n", hr );
6089 hr = IXMLDOMElement_get_xml(pElement, &str);
6090 ok(hr == S_OK, "ret %08x\n", hr );
6091 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
6094 /* Test for reversible escaping */
6095 str = SysAllocString( szStrangeChars );
6096 hr = IXMLDOMElement_put_text(pElement, str);
6097 ok(hr == S_OK, "ret %08x\n", hr );
6098 SysFreeString( str );
6100 hr = IXMLDOMElement_get_xml(pElement, &str);
6101 ok(hr == S_OK, "ret %08x\n", hr );
6102 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
6105 hr = IXMLDOMElement_get_text(pElement, &str);
6106 ok(hr == S_OK, "ret %08x\n", hr );
6107 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
6110 IXMLDOMElement_Release(pElement);
6114 str = SysAllocString(szCData);
6115 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
6116 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6118 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
6120 ok(hr == S_OK, "ret %08x\n", hr );
6123 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
6128 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
6129 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
6131 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
6132 ok(hr == S_OK, "ret %08x\n", hr );
6134 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
6135 ok(hr == S_OK, "ret %08x\n", hr );
6136 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
6139 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6140 ok(hr == S_OK, "ret %08x\n", hr );
6141 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
6144 /* test lastChild */
6145 pNextChild = (IXMLDOMNode*)0x1;
6146 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
6147 ok(hr == S_FALSE, "ret %08x\n", hr );
6148 ok(pNextChild == NULL, "pNextChild not NULL\n");
6150 /* put data Tests */
6151 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
6152 ok(hr == S_OK, "ret %08x\n", hr );
6154 /* Confirm XML text is good */
6155 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6156 ok(hr == S_OK, "ret %08x\n", hr );
6157 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
6160 /* Confirm we get the put_data Text back */
6161 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6162 ok(hr == S_OK, "ret %08x\n", hr );
6163 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6166 /* test length property */
6167 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6168 ok(hr == S_OK, "ret %08x\n", hr );
6169 ok(len == 21, "expected 21 got %d\n", len);
6171 /* test get nodeValue */
6172 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
6173 ok(hr == S_OK, "ret %08x\n", hr );
6174 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
6175 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6179 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
6180 ok(hr == S_OK, "ret %08x\n", hr );
6181 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6184 /* test substringData */
6185 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
6186 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6188 /* test substringData - Invalid offset */
6189 str = (BSTR)&szElement;
6190 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
6191 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6192 ok( str == NULL, "incorrect string\n");
6194 /* test substringData - Invalid offset */
6195 str = (BSTR)&szElement;
6196 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
6197 ok(hr == S_FALSE, "ret %08x\n", hr );
6198 ok( str == NULL, "incorrect string\n");
6200 /* test substringData - Invalid size */
6201 str = (BSTR)&szElement;
6202 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
6203 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6204 ok( str == NULL, "incorrect string\n");
6206 /* test substringData - Invalid size */
6207 str = (BSTR)&szElement;
6208 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
6209 ok(hr == S_FALSE, "ret %08x\n", hr );
6210 ok( str == NULL, "incorrect string\n");
6212 /* test substringData - Start of string */
6213 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
6214 ok(hr == S_OK, "ret %08x\n", hr );
6215 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
6218 /* test substringData - Middle of string */
6219 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
6220 ok(hr == S_OK, "ret %08x\n", hr );
6221 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
6224 /* test substringData - End of string */
6225 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
6226 ok(hr == S_OK, "ret %08x\n", hr );
6227 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
6230 /* test appendData */
6231 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
6232 ok(hr == S_OK, "ret %08x\n", hr );
6234 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
6235 ok(hr == S_OK, "ret %08x\n", hr );
6237 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
6238 ok(hr == S_OK, "ret %08x\n", hr );
6240 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6241 ok(hr == S_OK, "ret %08x\n", hr );
6242 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6245 /* test insertData */
6246 str = SysAllocStringLen(NULL, 0);
6247 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
6248 ok(hr == S_OK, "ret %08x\n", hr );
6250 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
6251 ok(hr == S_OK, "ret %08x\n", hr );
6253 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
6254 ok(hr == S_OK, "ret %08x\n", hr );
6256 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
6257 ok(hr == S_OK, "ret %08x\n", hr );
6259 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
6260 ok(hr == S_OK, "ret %08x\n", hr );
6262 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
6263 ok(hr == S_OK, "ret %08x\n", hr );
6266 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
6267 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6269 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
6270 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6272 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
6273 ok(hr == S_OK, "ret %08x\n", hr );
6275 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
6276 ok(hr == S_OK, "ret %08x\n", hr );
6278 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
6279 ok(hr == S_OK, "ret %08x\n", hr );
6281 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6282 ok(hr == S_OK, "ret %08x\n", hr );
6283 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6287 /* invalid arguments */
6288 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
6289 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6291 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
6292 ok(hr == S_OK, "ret %08x\n", hr );
6294 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
6295 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6297 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6298 ok(hr == S_OK, "ret %08x\n", hr );
6299 ok(len == 43, "expected 43 got %d\n", len);
6301 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
6302 ok(hr == S_OK, "ret %08x\n", hr );
6304 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
6305 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6307 /* delete from start */
6308 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
6309 ok(hr == S_OK, "ret %08x\n", hr );
6311 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6312 ok(hr == S_OK, "ret %08x\n", hr );
6313 ok(len == 38, "expected 38 got %d\n", len);
6315 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6316 ok(hr == S_OK, "ret %08x\n", hr );
6317 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6320 /* delete from end */
6321 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
6322 ok(hr == S_OK, "ret %08x\n", hr );
6324 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6325 ok(hr == S_OK, "ret %08x\n", hr );
6326 ok(len == 35, "expected 35 got %d\n", len);
6328 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6329 ok(hr == S_OK, "ret %08x\n", hr );
6330 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6333 /* delete from inside */
6334 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
6335 ok(hr == S_OK, "ret %08x\n", hr );
6337 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6338 ok(hr == S_OK, "ret %08x\n", hr );
6339 ok(len == 2, "expected 2 got %d\n", len);
6341 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6342 ok(hr == S_OK, "ret %08x\n", hr );
6343 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6346 /* delete whole data ... */
6347 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6348 ok(hr == S_OK, "ret %08x\n", hr );
6350 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6351 ok(hr == S_OK, "ret %08x\n", hr );
6353 /* ... and try again with empty string */
6354 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6355 ok(hr == S_OK, "ret %08x\n", hr );
6357 /* ::replaceData() */
6359 V_BSTR(&v) = SysAllocString(szstr1);
6360 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
6361 ok(hr == S_OK, "ret %08x\n", hr );
6364 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
6365 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6366 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6367 ok(hr == S_OK, "ret %08x\n", hr );
6368 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6371 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
6372 ok(hr == S_OK, "ret %08x\n", hr );
6373 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6374 ok(hr == S_OK, "ret %08x\n", hr );
6375 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6378 /* NULL pointer means delete */
6379 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
6380 ok(hr == S_OK, "ret %08x\n", hr );
6381 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6382 ok(hr == S_OK, "ret %08x\n", hr );
6383 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6386 /* empty string means delete */
6387 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
6388 ok(hr == S_OK, "ret %08x\n", hr );
6389 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6390 ok(hr == S_OK, "ret %08x\n", hr );
6391 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6394 /* zero count means insert */
6395 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
6396 ok(hr == S_OK, "ret %08x\n", hr );
6397 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6398 ok(hr == S_OK, "ret %08x\n", hr );
6399 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6402 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
6403 ok(hr == S_OK, "ret %08x\n", hr );
6405 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
6406 ok(hr == S_OK, "ret %08x\n", hr );
6407 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6408 ok(hr == S_OK, "ret %08x\n", hr );
6409 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6412 /* nonempty string, count greater than its length */
6413 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
6414 ok(hr == S_OK, "ret %08x\n", hr );
6415 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6416 ok(hr == S_OK, "ret %08x\n", hr );
6417 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6420 /* nonempty string, count less than its length */
6421 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
6422 ok(hr == S_OK, "ret %08x\n", hr );
6423 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6424 ok(hr == S_OK, "ret %08x\n", hr );
6425 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6428 IXMLDOMCDATASection_Release(pCDataSec);
6431 /* Document Fragments */
6432 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
6433 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6435 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
6436 ok(hr == S_OK, "ret %08x\n", hr );
6441 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
6442 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6444 node = (IXMLDOMNode *)0x1;
6445 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
6446 ok(hr == S_FALSE, "ret %08x\n", hr );
6447 ok(node == NULL, "expected NULL, got %p\n", node);
6449 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
6450 ok(hr == S_OK, "ret %08x\n", hr );
6452 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
6453 ok(hr == S_OK, "ret %08x\n", hr );
6454 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
6457 /* test next Sibling*/
6458 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
6459 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6461 node = (IXMLDOMNode *)0x1;
6462 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
6463 ok(hr == S_FALSE, "ret %08x\n", hr );
6464 ok(node == NULL, "next sibling not NULL\n");
6466 /* test Previous Sibling*/
6467 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
6468 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6470 node = (IXMLDOMNode *)0x1;
6471 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
6472 ok(hr == S_FALSE, "ret %08x\n", hr );
6473 ok(node == NULL, "previous sibling not NULL\n");
6475 IXMLDOMDocumentFragment_Release(pDocFrag);
6478 /* Entity References */
6479 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
6480 ok(hr == E_FAIL, "ret %08x\n", hr );
6481 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
6482 ok(hr == E_FAIL, "ret %08x\n", hr );
6484 str = SysAllocString(szEntityRef);
6485 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
6486 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6488 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
6490 ok(hr == S_OK, "ret %08x\n", hr );
6493 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
6494 ok(hr == S_OK, "ret %08x\n", hr );
6497 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
6498 ok(hr == S_OK, "ret %08x\n", hr );
6499 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
6502 IXMLDOMEntityReference_Release(pEntityRef);
6505 IXMLDOMElement_Release( pRoot );
6509 IXMLDOMDocument_Release(doc);
6514 static void test_nodeTypeTests( void )
6516 IXMLDOMDocument *doc = NULL;
6517 IXMLDOMElement *pRoot;
6518 IXMLDOMElement *pElement;
6521 doc = create_document(&IID_IXMLDOMDocument);
6524 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
6525 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6527 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
6528 ok(hr == S_OK, "ret %08x\n", hr );
6531 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
6532 ok(hr == S_OK, "ret %08x\n", hr );
6535 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
6536 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6539 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
6540 ok(hr == E_FAIL, "ret %08x\n", hr );
6543 * The name passed into put_dataType is case-insensitive. So many of the names
6544 * have been changed to reflect this.
6547 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
6548 ok(hr == S_OK, "ret %08x\n", hr );
6551 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6553 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
6554 ok(hr == S_OK, "ret %08x\n", hr );
6556 IXMLDOMElement_Release(pElement);
6560 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
6561 ok(hr == S_OK, "ret %08x\n", hr );
6564 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6566 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
6567 ok(hr == S_OK, "ret %08x\n", hr );
6569 IXMLDOMElement_Release(pElement);
6573 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
6574 ok(hr == S_OK, "ret %08x\n", hr );
6577 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6579 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
6580 ok(hr == S_OK, "ret %08x\n", hr );
6582 IXMLDOMElement_Release(pElement);
6586 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
6587 ok(hr == S_OK, "ret %08x\n", hr );
6590 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6592 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
6593 ok(hr == S_OK, "ret %08x\n", hr );
6595 IXMLDOMElement_Release(pElement);
6599 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
6600 ok(hr == S_OK, "ret %08x\n", hr );
6603 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6605 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
6606 ok(hr == S_OK, "ret %08x\n", hr );
6608 IXMLDOMElement_Release(pElement);
6612 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
6613 ok(hr == S_OK, "ret %08x\n", hr );
6616 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6618 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
6619 ok(hr == S_OK, "ret %08x\n", hr );
6621 IXMLDOMElement_Release(pElement);
6625 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
6626 ok(hr == S_OK, "ret %08x\n", hr );
6629 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6631 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
6632 ok(hr == S_OK, "ret %08x\n", hr );
6634 IXMLDOMElement_Release(pElement);
6638 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
6639 ok(hr == S_OK, "ret %08x\n", hr );
6642 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6644 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
6645 ok(hr == S_OK, "ret %08x\n", hr );
6647 IXMLDOMElement_Release(pElement);
6651 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
6652 ok(hr == S_OK, "ret %08x\n", hr );
6655 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6657 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
6658 ok(hr == S_OK, "ret %08x\n", hr );
6660 IXMLDOMElement_Release(pElement);
6664 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
6665 ok(hr == S_OK, "ret %08x\n", hr );
6668 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6670 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
6671 ok(hr == S_OK, "ret %08x\n", hr );
6673 IXMLDOMElement_Release(pElement);
6677 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
6678 ok(hr == S_OK, "ret %08x\n", hr );
6681 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6683 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
6684 ok(hr == S_OK, "ret %08x\n", hr );
6686 IXMLDOMElement_Release(pElement);
6690 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
6691 ok(hr == S_OK, "ret %08x\n", hr );
6694 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6696 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
6697 ok(hr == S_OK, "ret %08x\n", hr );
6699 IXMLDOMElement_Release(pElement);
6703 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
6704 ok(hr == S_OK, "ret %08x\n", hr );
6707 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6709 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
6710 ok(hr == S_OK, "ret %08x\n", hr );
6712 IXMLDOMElement_Release(pElement);
6716 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
6717 ok(hr == S_OK, "ret %08x\n", hr );
6720 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6722 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
6723 ok(hr == S_OK, "ret %08x\n", hr );
6725 IXMLDOMElement_Release(pElement);
6729 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
6730 ok(hr == S_OK, "ret %08x\n", hr );
6733 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6735 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
6736 ok(hr == S_OK, "ret %08x\n", hr );
6738 IXMLDOMElement_Release(pElement);
6742 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
6743 ok(hr == S_OK, "ret %08x\n", hr );
6746 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6748 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
6749 ok(hr == S_OK, "ret %08x\n", hr );
6751 IXMLDOMElement_Release(pElement);
6755 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
6756 ok(hr == S_OK, "ret %08x\n", hr );
6759 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6761 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
6762 ok(hr == S_OK, "ret %08x\n", hr );
6764 IXMLDOMElement_Release(pElement);
6768 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
6769 ok(hr == S_OK, "ret %08x\n", hr );
6772 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6774 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
6775 ok(hr == S_OK, "ret %08x\n", hr );
6777 IXMLDOMElement_Release(pElement);
6781 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
6782 ok(hr == S_OK, "ret %08x\n", hr );
6785 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6787 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
6788 ok(hr == S_OK, "ret %08x\n", hr );
6790 IXMLDOMElement_Release(pElement);
6794 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
6795 ok(hr == S_OK, "ret %08x\n", hr );
6798 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6800 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
6801 ok(hr == S_OK, "ret %08x\n", hr );
6803 IXMLDOMElement_Release(pElement);
6807 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
6808 ok(hr == S_OK, "ret %08x\n", hr );
6811 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6813 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
6814 ok(hr == S_OK, "ret %08x\n", hr );
6816 IXMLDOMElement_Release(pElement);
6820 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
6821 ok(hr == S_OK, "ret %08x\n", hr );
6824 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6826 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
6827 ok(hr == S_OK, "ret %08x\n", hr );
6829 IXMLDOMElement_Release(pElement);
6832 /* Check changing types */
6833 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
6834 ok(hr == S_OK, "ret %08x\n", hr );
6837 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6839 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
6840 ok(hr == S_OK, "ret %08x\n", hr );
6842 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
6843 ok(hr == S_OK, "ret %08x\n", hr );
6845 IXMLDOMElement_Release(pElement);
6848 IXMLDOMElement_Release(pRoot);
6852 IXMLDOMDocument_Release(doc);
6857 static void test_save(void)
6859 IXMLDOMDocument *doc, *doc2;
6860 IXMLDOMElement *root;
6868 doc = create_document(&IID_IXMLDOMDocument);
6871 doc2 = create_document(&IID_IXMLDOMDocument);
6874 IXMLDOMDocument_Release(doc);
6878 /* save to IXMLDOMDocument */
6879 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
6880 EXPECT_HR(hr, S_OK);
6882 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
6883 EXPECT_HR(hr, S_OK);
6885 V_VT(&vDoc) = VT_UNKNOWN;
6886 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
6888 hr = IXMLDOMDocument_save(doc, vDoc);
6889 EXPECT_HR(hr, S_OK);
6891 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
6892 EXPECT_HR(hr, S_OK);
6894 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
6895 EXPECT_HR(hr, S_OK);
6897 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
6899 SysFreeString(sOrig);
6900 SysFreeString(sNew);
6902 IXMLDOMElement_Release(root);
6903 IXMLDOMDocument_Release(doc2);
6906 V_VT(&file) = VT_BSTR;
6907 V_BSTR(&file) = _bstr_("test.xml");
6909 hr = IXMLDOMDocument_save(doc, file);
6910 EXPECT_HR(hr, S_OK);
6912 IXMLDOMDocument_Release(doc);
6914 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
6915 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
6916 if(hfile == INVALID_HANDLE_VALUE) return;
6918 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
6919 ok(read != 0, "could not read file\n");
6920 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
6923 DeleteFile("test.xml");
6927 static void test_testTransforms(void)
6929 IXMLDOMDocument *doc, *docSS;
6935 doc = create_document(&IID_IXMLDOMDocument);
6938 docSS = create_document(&IID_IXMLDOMDocument);
6941 IXMLDOMDocument_Release(doc);
6945 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
6946 ok(hr == S_OK, "ret %08x\n", hr );
6948 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
6949 ok(hr == S_OK, "ret %08x\n", hr );
6951 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
6952 ok(hr == S_OK, "ret %08x\n", hr );
6957 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
6958 ok(hr == S_OK, "ret %08x\n", hr );
6959 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
6960 SysFreeString(bOut);
6962 IXMLDOMNode_Release(pNode);
6965 IXMLDOMDocument_Release(docSS);
6966 IXMLDOMDocument_Release(doc);
6971 static void test_Namespaces(void)
6973 IXMLDOMDocument *doc;
6975 IXMLDOMNode *pNode2 = NULL;
6979 static const CHAR szNamespacesXML[] =
6980 "<?xml version=\"1.0\"?>\n"
6981 "<root xmlns:WEB='http://www.winehq.org'>\n"
6982 "<WEB:Site version=\"1.0\" />\n"
6985 doc = create_document(&IID_IXMLDOMDocument);
6988 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
6989 ok(hr == S_OK, "ret %08x\n", hr );
6990 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6992 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
6993 ok(hr == S_OK, "ret %08x\n", hr );
6996 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
6997 ok( hr == S_OK, "ret %08x\n", hr );
6998 ok( pNode2 != NULL, "pNode2 == NULL\n");
7000 /* Test get_prefix */
7001 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
7002 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
7003 /* NOTE: Need to test that arg2 gets cleared on Error. */
7005 hr = IXMLDOMNode_get_prefix(pNode2, &str);
7006 ok( hr == S_OK, "ret %08x\n", hr );
7007 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
7010 /* Test get_namespaceURI */
7011 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
7012 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
7013 /* NOTE: Need to test that arg2 gets cleared on Error. */
7015 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
7016 ok( hr == S_OK, "ret %08x\n", hr );
7017 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
7020 IXMLDOMNode_Release(pNode2);
7021 IXMLDOMNode_Release(pNode);
7024 IXMLDOMDocument_Release(doc);
7029 static void test_FormattingXML(void)
7031 IXMLDOMDocument *doc;
7032 IXMLDOMElement *pElement;
7036 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
7037 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
7039 doc = create_document(&IID_IXMLDOMDocument);
7042 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
7043 ok(hr == S_OK, "ret %08x\n", hr );
7044 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7046 if(bSucc == VARIANT_TRUE)
7048 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
7049 ok(hr == S_OK, "ret %08x\n", hr );
7052 hr = IXMLDOMElement_get_xml(pElement, &str);
7053 ok(hr == S_OK, "ret %08x\n", hr );
7054 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
7057 IXMLDOMElement_Release(pElement);
7061 IXMLDOMDocument_Release(doc);
7066 typedef struct _nodetypedvalue_t {
7069 const char *value; /* value in string format */
7072 static const nodetypedvalue_t get_nodetypedvalue[] = {
7073 { "root/string", VT_BSTR, "Wine" },
7074 { "root/string2", VT_BSTR, "String" },
7075 { "root/number", VT_BSTR, "12.44" },
7076 { "root/number2", VT_BSTR, "-3.71e3" },
7077 { "root/int", VT_I4, "-13" },
7078 { "root/fixed", VT_CY, "7322.9371" },
7079 { "root/bool", VT_BOOL, "-1" },
7080 { "root/datetime", VT_DATE, "40135.14" },
7081 { "root/datetimetz",VT_DATE, "37813.59" },
7082 { "root/date", VT_DATE, "665413" },
7083 { "root/time", VT_DATE, "0.5813889" },
7084 { "root/timetz", VT_DATE, "1.112512" },
7085 { "root/i1", VT_I1, "-13" },
7086 { "root/i2", VT_I2, "31915" },
7087 { "root/i4", VT_I4, "-312232" },
7088 { "root/ui1", VT_UI1, "123" },
7089 { "root/ui2", VT_UI2, "48282" },
7090 { "root/ui4", VT_UI4, "949281" },
7091 { "root/r4", VT_R4, "213124" },
7092 { "root/r8", VT_R8, "0.412" },
7093 { "root/float", VT_R8, "41221.421" },
7094 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
7095 { "root/binbase64", VT_ARRAY|VT_UI1, "base64 test" },
7096 { "root/binbase64_1", VT_ARRAY|VT_UI1, "base64 test" },
7097 { "root/binbase64_2", VT_ARRAY|VT_UI1, "base64 test" },
7101 static void test_nodeTypedValue(void)
7103 const nodetypedvalue_t *entry = get_nodetypedvalue;
7104 IXMLDOMDocumentType *doctype, *doctype2;
7105 IXMLDOMProcessingInstruction *pi;
7106 IXMLDOMDocumentFragment *frag;
7107 IXMLDOMDocument *doc, *doc2;
7108 IXMLDOMCDATASection *cdata;
7109 IXMLDOMComment *comment;
7115 doc = create_document(&IID_IXMLDOMDocument);
7119 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
7120 ok(hr == S_OK, "ret %08x\n", hr );
7121 ok(b == VARIANT_TRUE, "got %d\n", b);
7123 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
7124 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7126 V_VT(&value) = VT_BSTR;
7127 V_BSTR(&value) = NULL;
7128 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
7129 ok(hr == S_FALSE, "ret %08x\n", hr );
7130 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7132 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
7133 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7135 V_VT(&value) = VT_EMPTY;
7136 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
7137 ok(hr == S_FALSE, "ret %08x\n", hr );
7138 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7140 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
7141 ok(hr == S_OK, "ret %08x\n", hr );
7143 V_VT(&value) = VT_BSTR;
7144 V_BSTR(&value) = NULL;
7145 hr = IXMLDOMNode_get_nodeValue(node, &value);
7146 ok(hr == S_FALSE, "ret %08x\n", hr );
7147 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7149 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
7150 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7152 IXMLDOMNode_Release(node);
7154 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
7155 ok(hr == S_OK, "ret %08x\n", hr );
7157 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
7159 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7160 ok(hr == S_OK, "ret %08x\n", hr );
7161 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
7162 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
7163 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
7164 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
7165 VariantClear(&value);
7166 IXMLDOMNode_Release(node);
7169 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("foo"), _bstr_("value"), &pi);
7170 ok(hr == S_OK, "ret %08x\n", hr );
7172 V_VT(&value) = VT_NULL;
7173 V_BSTR(&value) = (void*)0xdeadbeef;
7174 hr = IXMLDOMProcessingInstruction_get_nodeTypedValue(pi, &value);
7175 ok(hr == S_OK, "ret %08x\n", hr );
7176 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7177 ok(!lstrcmpW(V_BSTR(&value), _bstr_("value")), "got wrong value\n");
7178 IXMLDOMProcessingInstruction_Release(pi);
7179 VariantClear(&value);
7182 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("[1]*2=3; &gee thats not right!"), &cdata);
7183 ok(hr == S_OK, "ret %08x\n", hr );
7185 V_VT(&value) = VT_NULL;
7186 V_BSTR(&value) = (void*)0xdeadbeef;
7187 hr = IXMLDOMCDATASection_get_nodeTypedValue(cdata, &value);
7188 ok(hr == S_OK, "ret %08x\n", hr );
7189 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7190 ok(!lstrcmpW(V_BSTR(&value), _bstr_("[1]*2=3; &gee thats not right!")), "got wrong value\n");
7191 IXMLDOMCDATASection_Release(cdata);
7192 VariantClear(&value);
7195 hr = IXMLDOMDocument_createComment(doc, _bstr_("comment"), &comment);
7196 ok(hr == S_OK, "ret %08x\n", hr );
7198 V_VT(&value) = VT_NULL;
7199 V_BSTR(&value) = (void*)0xdeadbeef;
7200 hr = IXMLDOMComment_get_nodeTypedValue(comment, &value);
7201 ok(hr == S_OK, "ret %08x\n", hr );
7202 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7203 ok(!lstrcmpW(V_BSTR(&value), _bstr_("comment")), "got wrong value\n");
7204 IXMLDOMComment_Release(comment);
7205 VariantClear(&value);
7208 hr = IXMLDOMDocument_createDocumentFragment(doc, &frag);
7209 ok(hr == S_OK, "ret %08x\n", hr );
7211 V_VT(&value) = VT_EMPTY;
7212 hr = IXMLDOMDocumentFragment_get_nodeTypedValue(frag, &value);
7213 ok(hr == S_FALSE, "ret %08x\n", hr );
7214 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7215 IXMLDOMDocumentFragment_Release(frag);
7218 doc2 = create_document(&IID_IXMLDOMDocument);
7221 hr = IXMLDOMDocument_loadXML(doc2, _bstr_(szEmailXML), &b);
7222 ok(hr == S_OK, "ret %08x\n", hr );
7223 ok(b == VARIANT_TRUE, "got %d\n", b);
7225 EXPECT_REF(doc2, 1);
7227 hr = IXMLDOMDocument_get_doctype(doc2, &doctype);
7228 ok(hr == S_OK, "ret %08x\n", hr );
7230 EXPECT_REF(doc2, 1);
7231 todo_wine EXPECT_REF(doctype, 2);
7234 V_VT(&value) = VT_EMPTY;
7235 hr = IXMLDOMDocumentType_get_nodeTypedValue(doctype, &value);
7236 ok(hr == S_FALSE, "ret %08x\n", hr );
7237 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7240 hr = IXMLDOMDocument_get_doctype(doc2, &doctype2);
7241 ok(hr == S_OK, "ret %08x\n", hr );
7242 ok(doctype != doctype2, "got %p, was %p\n", doctype2, doctype);
7244 IXMLDOMDocumentType_Release(doctype2);
7245 IXMLDOMDocumentType_Release(doctype);
7247 IXMLDOMDocument_Release(doc2);
7251 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
7252 ok(hr == S_OK, "ret %08x\n", hr );
7254 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7255 ok(hr == S_OK, "ret %08x\n", hr );
7256 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
7258 if (entry->type == (VT_ARRAY|VT_UI1))
7260 ok(V_ARRAY(&value)->rgsabound[0].cElements == strlen(entry->value),
7261 "incorrect array size %d\n", V_ARRAY(&value)->rgsabound[0].cElements);
7264 if (entry->type != VT_BSTR)
7266 if (entry->type == VT_DATE ||
7267 entry->type == VT_R8 ||
7268 entry->type == VT_CY)
7270 if (entry->type == VT_DATE)
7272 hr = VariantChangeType(&value, &value, 0, VT_R4);
7273 ok(hr == S_OK, "ret %08x\n", hr );
7275 hr = VariantChangeTypeEx(&value, &value,
7276 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
7277 VARIANT_NOUSEROVERRIDE, VT_BSTR);
7278 ok(hr == S_OK, "ret %08x\n", hr );
7282 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
7283 ok(hr == S_OK, "ret %08x\n", hr );
7286 /* for byte array from VT_ARRAY|VT_UI1 it's not a WCHAR buffer */
7287 if (entry->type == (VT_ARRAY|VT_UI1))
7289 ok(!memcmp( V_BSTR(&value), entry->value, strlen(entry->value)),
7290 "expected %s\n", entry->value);
7293 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7294 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7297 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7298 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7300 VariantClear( &value );
7301 IXMLDOMNode_Release(node);
7306 IXMLDOMDocument_Release(doc);
7310 static void test_TransformWithLoadingLocalFile(void)
7312 IXMLDOMDocument *doc;
7313 IXMLDOMDocument *xsl;
7319 char lpPathBuffer[MAX_PATH];
7322 /* Create a Temp File. */
7323 GetTempPathA(MAX_PATH, lpPathBuffer);
7324 strcat(lpPathBuffer, "customers.xml" );
7326 file = CreateFileA(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
7327 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
7328 if(file == INVALID_HANDLE_VALUE)
7331 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
7334 /* Correct path to not include a escape character. */
7335 for(i=0; i < strlen(lpPathBuffer); i++)
7337 if(lpPathBuffer[i] == '\\')
7338 lpPathBuffer[i] = '/';
7341 doc = create_document(&IID_IXMLDOMDocument);
7344 xsl = create_document(&IID_IXMLDOMDocument);
7347 IXMLDOMDocument2_Release(doc);
7351 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
7352 ok(hr == S_OK, "ret %08x\n", hr );
7353 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7354 if(bSucc == VARIANT_TRUE)
7357 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
7358 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
7359 BSTR sFileName = _bstr_(lpPathBuffer);
7360 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
7362 sXSL = SysAllocStringLen(NULL, nLegnth);
7363 lstrcpyW(sXSL, sPart1);
7364 lstrcatW(sXSL, sFileName);
7365 lstrcatW(sXSL, sPart2);
7367 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
7368 ok(hr == S_OK, "ret %08x\n", hr );
7369 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7370 if(bSucc == VARIANT_TRUE)
7374 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
7375 ok(hr == S_OK, "ret %08x\n", hr );
7378 /* This will load the temp file via the XSL */
7379 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
7380 ok(hr == S_OK, "ret %08x\n", hr );
7383 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
7384 SysFreeString(sResult);
7387 IXMLDOMNode_Release(pNode);
7391 SysFreeString(sXSL);
7394 IXMLDOMDocument_Release(doc);
7395 IXMLDOMDocument_Release(xsl);
7397 DeleteFile(lpPathBuffer);
7401 static void test_put_nodeValue(void)
7403 static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
7404 IXMLDOMDocument *doc;
7406 IXMLDOMEntityReference *entityref;
7407 IXMLDOMAttribute *attr;
7412 doc = create_document(&IID_IXMLDOMDocument);
7415 /* test for unsupported types */
7417 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
7418 ok(hr == S_OK, "ret %08x\n", hr );
7419 V_VT(&data) = VT_BSTR;
7420 V_BSTR(&data) = _bstr_("one two three");
7421 hr = IXMLDOMNode_put_nodeValue(node, data);
7422 ok(hr == E_FAIL, "ret %08x\n", hr );
7423 IXMLDOMNode_Release(node);
7425 /* NODE_DOCUMENT_FRAGMENT */
7426 V_VT(&type) = VT_I1;
7427 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
7428 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
7429 ok(hr == S_OK, "ret %08x\n", hr );
7430 V_VT(&data) = VT_BSTR;
7431 V_BSTR(&data) = _bstr_("one two three");
7432 hr = IXMLDOMNode_put_nodeValue(node, data);
7433 ok(hr == E_FAIL, "ret %08x\n", hr );
7434 IXMLDOMNode_Release(node);
7437 V_VT(&type) = VT_I1;
7438 V_I1(&type) = NODE_ELEMENT;
7439 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
7440 ok(hr == S_OK, "ret %08x\n", hr );
7441 V_VT(&data) = VT_BSTR;
7442 V_BSTR(&data) = _bstr_("one two three");
7443 hr = IXMLDOMNode_put_nodeValue(node, data);
7444 ok(hr == E_FAIL, "ret %08x\n", hr );
7445 IXMLDOMNode_Release(node);
7447 /* NODE_ENTITY_REFERENCE */
7448 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
7449 ok(hr == S_OK, "ret %08x\n", hr );
7451 V_VT(&data) = VT_BSTR;
7452 V_BSTR(&data) = _bstr_("one two three");
7453 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
7454 ok(hr == E_FAIL, "ret %08x\n", hr );
7456 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
7457 ok(hr == S_OK, "ret %08x\n", hr );
7458 V_VT(&data) = VT_BSTR;
7459 V_BSTR(&data) = _bstr_("one two three");
7460 hr = IXMLDOMNode_put_nodeValue(node, data);
7461 ok(hr == E_FAIL, "ret %08x\n", hr );
7462 IXMLDOMNode_Release(node);
7463 IXMLDOMEntityReference_Release(entityref);
7465 /* supported types */
7466 hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
7467 ok(hr == S_OK, "ret %08x\n", hr );
7468 V_VT(&data) = VT_BSTR;
7469 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
7470 hr = IXMLDOMText_put_nodeValue(text, data);
7471 ok(hr == S_OK, "ret %08x\n", hr );
7472 IXMLDOMText_Release(text);
7474 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7475 ok(hr == S_OK, "ret %08x\n", hr );
7476 V_VT(&data) = VT_BSTR;
7477 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
7478 hr = IXMLDOMAttribute_put_nodeValue(attr, data);
7479 ok(hr == S_OK, "ret %08x\n", hr );
7480 hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
7481 ok(hr == S_OK, "ret %08x\n", hr );
7482 ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
7483 wine_dbgstr_w(V_BSTR(&data)));
7484 VariantClear(&data);
7485 IXMLDOMAttribute_Release(attr);
7489 IXMLDOMDocument_Release(doc);
7492 static void test_document_IObjectSafety(void)
7494 IXMLDOMDocument *doc;
7495 IObjectSafety *safety;
7498 doc = create_document(&IID_IXMLDOMDocument);
7501 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
7502 ok(hr == S_OK, "ret %08x\n", hr );
7504 test_IObjectSafety_common(safety);
7506 IObjectSafety_Release(safety);
7508 IXMLDOMDocument_Release(doc);
7511 typedef struct _property_test_t {
7514 const char *property;
7518 static const property_test_t properties_test_data[] = {
7519 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
7520 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
7521 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
7522 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
7523 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
7527 static void test_default_properties(void)
7529 const property_test_t *entry = properties_test_data;
7530 IXMLDOMDocument2 *doc;
7536 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
7539 win_skip("can't create %s instance\n", entry->clsid);
7544 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
7545 ok(hr == S_OK, "got 0x%08x\n", hr);
7546 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
7547 entry->value, entry->clsid);
7550 IXMLDOMDocument2_Release(doc);
7556 static void test_XSLPattern(void)
7558 IXMLDOMDocument2 *doc;
7559 IXMLDOMNodeList *list;
7563 doc = create_document(&IID_IXMLDOMDocument2);
7566 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
7567 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7569 /* switch to XSLPattern */
7570 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
7572 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
7573 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list));
7575 ole_check(IXMLDOMNodeList_get_length(list, &len));
7576 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
7577 ok(len == 3, "expected 3 entries in list, got %d\n", len);
7578 IXMLDOMNodeList_Release(list);
7580 /* for XSLPattern start index is 0, for XPath it's 1 */
7581 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
7583 ole_check(IXMLDOMNodeList_get_length(list, &len));
7584 ok(len != 0, "expected filled list\n");
7586 expect_list_and_release(list, "E1.E2.D1");
7589 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=1]"), &list));
7591 ole_check(IXMLDOMNodeList_get_length(list, &len));
7592 ok(len != 0, "expected filled list\n");
7594 expect_list_and_release(list, "E2.E2.D1");
7597 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $eq$ 1]"), &list));
7599 ole_check(IXMLDOMNodeList_get_length(list, &len));
7600 ok(len != 0, "expected filled list\n");
7602 expect_list_and_release(list, "E2.E2.D1");
7605 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[end()]"), &list));
7607 ole_check(IXMLDOMNodeList_get_length(list, &len));
7608 ok(len != 0, "expected filled list\n");
7610 expect_list_and_release(list, "E4.E2.D1");
7613 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$not$ end()]"), &list));
7615 ole_check(IXMLDOMNodeList_get_length(list, &len));
7616 ok(len != 0, "expected filled list\n");
7618 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
7621 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() != 0]"), &list));
7623 ole_check(IXMLDOMNodeList_get_length(list, &len));
7624 ok(len != 0, "expected filled list\n");
7626 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
7627 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ne$ 0]"), &list));
7629 ole_check(IXMLDOMNodeList_get_length(list, &len));
7630 ok(len != 0, "expected filled list\n");
7632 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
7635 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() < 2]"), &list));
7637 ole_check(IXMLDOMNodeList_get_length(list, &len));
7638 ok(len != 0, "expected filled list\n");
7640 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7641 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $lt$ 2]"), &list));
7643 ole_check(IXMLDOMNodeList_get_length(list, &len));
7644 ok(len != 0, "expected filled list\n");
7646 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7649 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() <= 1]"), &list));
7651 ole_check(IXMLDOMNodeList_get_length(list, &len));
7652 ok(len != 0, "expected filled list\n");
7654 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7655 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $le$ 1]"), &list));
7657 ole_check(IXMLDOMNodeList_get_length(list, &len));
7658 ok(len != 0, "expected filled list\n");
7660 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7663 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() > 1]"), &list));
7665 ole_check(IXMLDOMNodeList_get_length(list, &len));
7666 ok(len != 0, "expected filled list\n");
7668 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7669 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $gt$ 1]"), &list));
7671 ole_check(IXMLDOMNodeList_get_length(list, &len));
7672 ok(len != 0, "expected filled list\n");
7674 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7677 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() >= 2]"), &list));
7679 ole_check(IXMLDOMNodeList_get_length(list, &len));
7680 ok(len != 0, "expected filled list\n");
7682 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7683 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ge$ 2]"), &list));
7685 ole_check(IXMLDOMNodeList_get_length(list, &len));
7686 ok(len != 0, "expected filled list\n");
7688 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7691 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ieq$ 'a2 field']"), &list));
7693 ole_check(IXMLDOMNodeList_get_length(list, &len));
7694 ok(len != 0, "expected filled list\n");
7696 expect_list_and_release(list, "E2.E2.D1");
7699 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ine$ 'a2 field']"), &list));
7701 ole_check(IXMLDOMNodeList_get_length(list, &len));
7702 ok(len != 0, "expected filled list\n");
7704 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
7707 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ilt$ 'a3 field']"), &list));
7709 ole_check(IXMLDOMNodeList_get_length(list, &len));
7710 ok(len != 0, "expected filled list\n");
7712 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7715 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ile$ 'a2 field']"), &list));
7717 ole_check(IXMLDOMNodeList_get_length(list, &len));
7718 ok(len != 0, "expected filled list\n");
7720 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7723 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $igt$ 'a2 field']"), &list));
7725 ole_check(IXMLDOMNodeList_get_length(list, &len));
7726 ok(len != 0, "expected filled list\n");
7728 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7731 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ige$ 'a3 field']"), &list));
7733 ole_check(IXMLDOMNodeList_get_length(list, &len));
7734 ok(len != 0, "expected filled list\n");
7736 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7739 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$any$ *='B2 field']"), &list));
7741 ole_check(IXMLDOMNodeList_get_length(list, &len));
7742 ok(len != 0, "expected filled list\n");
7744 expect_list_and_release(list, "E2.E2.D1");
7747 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$all$ *!='B2 field']"), &list));
7749 ole_check(IXMLDOMNodeList_get_length(list, &len));
7750 ok(len != 0, "expected filled list\n");
7752 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
7755 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 or end()]"), &list));
7757 ole_check(IXMLDOMNodeList_get_length(list, &len));
7758 ok(len != 0, "expected filled list\n");
7760 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7761 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 $or$ end()]"), &list));
7763 ole_check(IXMLDOMNodeList_get_length(list, &len));
7764 ok(len != 0, "expected filled list\n");
7766 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7767 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 || end()]"), &list));
7769 ole_check(IXMLDOMNodeList_get_length(list, &len));
7770 ok(len != 0, "expected filled list\n");
7772 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7775 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 and $not$ end()]"), &list));
7777 ole_check(IXMLDOMNodeList_get_length(list, &len));
7778 ok(len != 0, "expected filled list\n");
7780 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7781 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 $and$ $not$ end()]"), &list));
7783 ole_check(IXMLDOMNodeList_get_length(list, &len));
7784 ok(len != 0, "expected filled list\n");
7786 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7787 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 && $not$ end()]"), &list));
7789 ole_check(IXMLDOMNodeList_get_length(list, &len));
7790 ok(len != 0, "expected filled list\n");
7792 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7794 /* namespace handling */
7795 /* no registered namespaces */
7796 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
7799 /* prefixes don't need to be registered, you may use them as they are in the doc */
7800 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//bar:x"), &list));
7802 ole_check(IXMLDOMNodeList_get_length(list, &len));
7803 ok(len != 0, "expected filled list\n");
7805 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
7807 /* prefixes must be explicitly specified in the name */
7808 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:elem"), &list));
7810 ole_check(IXMLDOMNodeList_get_length(list, &len));
7811 ok(len == 0, "expected empty list\n");
7812 IXMLDOMNodeList_Release(list);
7814 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7816 ole_check(IXMLDOMNodeList_get_length(list, &len));
7817 ok(len != 0, "expected filled list\n");
7819 expect_list_and_release(list, "E3.E4.E2.D1");
7821 /* explicitly register prefix foo */
7822 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
7824 /* now we get the same behavior as XPath */
7825 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7827 ole_check(IXMLDOMNodeList_get_length(list, &len));
7828 ok(len != 0, "expected filled list\n");
7830 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
7832 /* set prefix foo to some nonexistent namespace */
7833 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:nonexistent-foo'")));
7835 /* the registered prefix takes precedence */
7836 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7838 ole_check(IXMLDOMNodeList_get_length(list, &len));
7839 ok(len == 0, "expected empty list\n");
7840 IXMLDOMNodeList_Release(list);
7842 IXMLDOMDocument2_Release(doc);
7844 doc = create_document(&IID_IXMLDOMDocument2);
7847 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szNodeTypesXML), &b));
7848 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7852 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute()"), &list));
7854 ole_check(IXMLDOMNodeList_get_length(list, &len));
7855 ok(len == 0, "expected empty list\n");
7856 IXMLDOMNodeList_Release(list);
7858 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute('depth')"), &list));
7860 ole_check(IXMLDOMNodeList_get_length(list, &len));
7861 ok(len == 0, "expected empty list\n");
7862 IXMLDOMNodeList_Release(list);
7864 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/attribute('depth')"), &list));
7866 ole_check(IXMLDOMNodeList_get_length(list, &len));
7867 ok(len != 0, "expected filled list\n");
7868 expect_list_and_release(list, "A'depth'.E3.D1");
7870 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/attribute()"), &list));
7872 ole_check(IXMLDOMNodeList_get_length(list, &len));
7873 ok(len != 0, "expected filled list\n");
7874 expect_list_and_release(list, "A'id'.E3.E3.D1 A'depth'.E3.E3.D1");
7877 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute(id)"), &list), E_FAIL);
7879 IXMLDOMNodeList_Release(list);
7880 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute('id')"), &list));
7882 ole_check(IXMLDOMNodeList_get_length(list, &len));
7883 ok(len != 0, "expected filled list\n");
7885 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");
7888 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("comment()"), &list));
7890 ole_check(IXMLDOMNodeList_get_length(list, &len));
7891 ok(len != 0, "expected filled list\n");
7893 expect_list_and_release(list, "C2.D1");
7895 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//comment()"), &list));
7897 ole_check(IXMLDOMNodeList_get_length(list, &len));
7898 ok(len != 0, "expected filled list\n");
7900 expect_list_and_release(list, "C2.D1 C1.E3.D1 C2.E3.E3.D1 C2.E4.E3.D1");
7903 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("element()"), &list));
7905 ole_check(IXMLDOMNodeList_get_length(list, &len));
7906 ok(len != 0, "expected filled list\n");
7908 expect_list_and_release(list, "E3.D1");
7910 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/y/element()"), &list));
7912 ole_check(IXMLDOMNodeList_get_length(list, &len));
7913 ok(len != 0, "expected filled list\n");
7915 expect_list_and_release(list, "E4.E4.E3.D1 E5.E4.E3.D1 E6.E4.E3.D1");
7918 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element(a)"), &list), E_FAIL);
7920 IXMLDOMNodeList_Release(list);
7921 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element('a')"), &list));
7923 ole_check(IXMLDOMNodeList_get_length(list, &len));
7924 ok(len != 0, "expected filled list\n");
7926 expect_list_and_release(list, "E4.E3.E3.D1 E4.E4.E3.D1");
7929 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("node()"), &list));
7931 ole_check(IXMLDOMNodeList_get_length(list, &len));
7932 ok(len != 0, "expected filled list\n");
7934 expect_list_and_release(list, "P1.D1 C2.D1 E3.D1");
7936 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()"), &list));
7938 ole_check(IXMLDOMNodeList_get_length(list, &len));
7939 ok(len != 0, "expected filled list\n");
7941 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");
7944 /* XML_ELEMENT_NODE */
7945 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=1]"), &list));
7947 ole_check(IXMLDOMNodeList_get_length(list, &len));
7948 ok(len != 0, "expected filled list\n");
7950 expect_list_and_release(list, "E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
7952 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=3]"), &list));
7954 ole_check(IXMLDOMNodeList_get_length(list, &len));
7955 ok(len != 0, "expected filled list\n");
7957 expect_list_and_release(list, "T3.E3.E3.D1");
7959 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=7]"), &list));
7961 ole_check(IXMLDOMNodeList_get_length(list, &len));
7962 ok(len != 0, "expected filled list\n");
7964 expect_list_and_release(list, "P1.E3.E3.D1");
7965 /* XML_COMMENT_NODE */
7966 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=8]"), &list));
7968 ole_check(IXMLDOMNodeList_get_length(list, &len));
7969 ok(len != 0, "expected filled list\n");
7971 expect_list_and_release(list, "C2.E3.E3.D1");
7974 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("pi()"), &list));
7978 ole_check(IXMLDOMNodeList_get_length(list, &len));
7979 ok(len != 0, "expected filled list\n");
7981 expect_list_and_release(list, "P1.D1");
7984 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//y/pi()"), &list));
7986 ole_check(IXMLDOMNodeList_get_length(list, &len));
7987 ok(len != 0, "expected filled list\n");
7989 expect_list_and_release(list, "P1.E4.E3.D1");
7992 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/textnode()"), &list));
7994 ole_check(IXMLDOMNodeList_get_length(list, &len));
7995 ok(len != 0, "expected filled list\n");
7997 expect_list_and_release(list, "T2.E3.D1");
7999 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/element()/textnode()"), &list));
8001 ole_check(IXMLDOMNodeList_get_length(list, &len));
8002 ok(len != 0, "expected filled list\n");
8004 expect_list_and_release(list, "T3.E3.E3.D1 T3.E4.E3.D1");
8006 IXMLDOMDocument2_Release(doc);
8010 static void test_splitText(void)
8012 IXMLDOMCDATASection *cdata;
8013 IXMLDOMElement *root;
8014 IXMLDOMDocument *doc;
8015 IXMLDOMText *text, *text2;
8018 VARIANT_BOOL success;
8022 doc = create_document(&IID_IXMLDOMDocument);
8025 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
8026 ok(hr == S_OK, "got 0x%08x\n", hr);
8028 hr = IXMLDOMDocument_get_documentElement(doc, &root);
8029 ok(hr == S_OK, "got 0x%08x\n", hr);
8031 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
8032 ok(hr == S_OK, "got 0x%08x\n", hr);
8034 V_VT(&var) = VT_EMPTY;
8035 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
8036 ok(hr == S_OK, "got 0x%08x\n", hr);
8039 hr = IXMLDOMCDATASection_get_length(cdata, &length);
8040 ok(hr == S_OK, "got 0x%08x\n", hr);
8041 ok(length > 0, "got %d\n", length);
8043 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
8044 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8046 text = (void*)0xdeadbeef;
8047 /* negative offset */
8048 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
8049 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8050 ok(text == (void*)0xdeadbeef, "got %p\n", text);
8052 text = (void*)0xdeadbeef;
8053 /* offset outside data */
8054 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
8055 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8056 ok(text == 0, "got %p\n", text);
8058 text = (void*)0xdeadbeef;
8059 /* offset outside data */
8060 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
8061 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8062 ok(text == 0, "got %p\n", text);
8064 /* no empty node created */
8065 node = (void*)0xdeadbeef;
8066 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8067 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8068 ok(node == 0, "got %p\n", text);
8070 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
8071 ok(hr == S_OK, "got 0x%08x\n", hr);
8074 hr = IXMLDOMText_get_length(text, &length);
8075 ok(hr == S_OK, "got 0x%08x\n", hr);
8076 ok(length == 7, "got %d\n", length);
8078 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8079 ok(hr == S_OK, "got 0x%08x\n", hr);
8080 IXMLDOMNode_Release(node);
8082 /* split new text node */
8083 hr = IXMLDOMText_get_length(text, &length);
8084 ok(hr == S_OK, "got 0x%08x\n", hr);
8086 node = (void*)0xdeadbeef;
8087 hr = IXMLDOMText_get_nextSibling(text, &node);
8088 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8089 ok(node == 0, "got %p\n", text);
8091 hr = IXMLDOMText_splitText(text, 0, NULL);
8092 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8094 text2 = (void*)0xdeadbeef;
8095 /* negative offset */
8096 hr = IXMLDOMText_splitText(text, -1, &text2);
8097 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8098 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
8100 text2 = (void*)0xdeadbeef;
8101 /* offset outside data */
8102 hr = IXMLDOMText_splitText(text, length + 1, &text2);
8103 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8104 ok(text2 == 0, "got %p\n", text2);
8106 text2 = (void*)0xdeadbeef;
8107 /* offset outside data */
8108 hr = IXMLDOMText_splitText(text, length, &text2);
8109 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8110 ok(text2 == 0, "got %p\n", text);
8113 hr = IXMLDOMText_splitText(text, 4, &text2);
8114 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8115 if (text2) IXMLDOMText_Release(text2);
8118 hr = IXMLDOMText_get_nextSibling(text, &node);
8119 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8120 if (node) IXMLDOMNode_Release(node);
8122 IXMLDOMText_Release(text);
8123 IXMLDOMElement_Release(root);
8124 IXMLDOMCDATASection_Release(cdata);
8128 static void test_getQualifiedItem(void)
8130 IXMLDOMDocument *doc;
8131 IXMLDOMElement *element;
8132 IXMLDOMNode *pr_node, *node;
8133 IXMLDOMNodeList *root_list;
8134 IXMLDOMNamedNodeMap *map;
8140 doc = create_document(&IID_IXMLDOMDocument);
8143 str = SysAllocString( szComplete4 );
8144 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8145 ok( hr == S_OK, "loadXML failed\n");
8146 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8147 SysFreeString( str );
8149 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8150 ok( hr == S_OK, "ret %08x\n", hr);
8152 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8153 ok( hr == S_OK, "ret %08x\n", hr);
8155 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8156 ok( hr == S_OK, "ret %08x\n", hr);
8157 IXMLDOMNodeList_Release(root_list);
8159 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8160 ok( hr == S_OK, "ret %08x\n", hr);
8161 IXMLDOMNode_Release(pr_node);
8163 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8164 ok( hr == S_OK, "ret %08x\n", hr);
8165 ok( len == 3, "length %d\n", len);
8167 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
8168 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8170 node = (void*)0xdeadbeef;
8171 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
8172 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8173 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8175 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
8176 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8178 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
8179 ok( hr == S_OK, "ret %08x\n", hr);
8180 IXMLDOMNode_Release(node);
8182 IXMLDOMNamedNodeMap_Release( map );
8183 IXMLDOMElement_Release( element );
8184 IXMLDOMDocument_Release( doc );
8188 static void test_removeQualifiedItem(void)
8190 IXMLDOMDocument *doc;
8191 IXMLDOMElement *element;
8192 IXMLDOMNode *pr_node, *node;
8193 IXMLDOMNodeList *root_list;
8194 IXMLDOMNamedNodeMap *map;
8200 doc = create_document(&IID_IXMLDOMDocument);
8203 str = SysAllocString( szComplete4 );
8204 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8205 ok( hr == S_OK, "loadXML failed\n");
8206 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8207 SysFreeString( str );
8209 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8210 ok( hr == S_OK, "ret %08x\n", hr);
8212 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8213 ok( hr == S_OK, "ret %08x\n", hr);
8215 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8216 ok( hr == S_OK, "ret %08x\n", hr);
8217 IXMLDOMNodeList_Release(root_list);
8219 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8220 ok( hr == S_OK, "ret %08x\n", hr);
8221 IXMLDOMNode_Release(pr_node);
8223 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8224 ok( hr == S_OK, "ret %08x\n", hr);
8225 ok( len == 3, "length %d\n", len);
8227 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
8228 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8230 node = (void*)0xdeadbeef;
8231 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
8232 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8233 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8235 /* out pointer is optional */
8236 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8237 ok( hr == S_OK, "ret %08x\n", hr);
8239 /* already removed */
8240 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8241 ok( hr == S_FALSE, "ret %08x\n", hr);
8243 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
8244 ok( hr == S_OK, "ret %08x\n", hr);
8245 IXMLDOMNode_Release(node);
8247 IXMLDOMNamedNodeMap_Release( map );
8248 IXMLDOMElement_Release( element );
8249 IXMLDOMDocument_Release( doc );
8253 #define check_default_props(doc) _check_default_props(__LINE__, doc)
8254 static inline void _check_default_props(int line, IXMLDOMDocument2* doc)
8261 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8262 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
8265 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8266 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("")) == 0, "expected empty string\n");
8269 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8270 ok_(__FILE__, line)(b == VARIANT_FALSE, "expected FALSE\n");
8272 hr = IXMLDOMDocument2_get_schemas(doc, &var);
8273 ok_(__FILE__, line)(hr == S_FALSE, "got %08x\n", hr);
8277 #define check_set_props(doc) _check_set_props(__LINE__, doc)
8278 static inline void _check_set_props(int line, IXMLDOMDocument2* doc)
8284 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8285 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
8288 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8289 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&var)));
8292 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8293 ok_(__FILE__, line)(b == VARIANT_TRUE, "expected TRUE\n");
8295 helper_ole_check(IXMLDOMDocument2_get_schemas(doc, &var));
8296 ok_(__FILE__, line)(V_VT(&var) != VT_NULL, "expected pointer\n");
8300 #define set_props(doc, cache) _set_props(__LINE__, doc, cache)
8301 static inline void _set_props(int line, IXMLDOMDocument2* doc, IXMLDOMSchemaCollection* cache)
8306 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
8307 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'")));
8308 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_TRUE));
8309 V_VT(&var) = VT_DISPATCH;
8310 V_DISPATCH(&var) = NULL;
8311 helper_ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&var)));
8312 ok_(__FILE__, line)(V_DISPATCH(&var) != NULL, "expected pointer\n");
8313 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8317 #define unset_props(doc) _unset_props(__LINE__, doc)
8318 static inline void _unset_props(int line, IXMLDOMDocument2* doc)
8323 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
8324 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
8325 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_FALSE));
8326 V_VT(&var) = VT_NULL;
8327 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8331 static void test_get_ownerDocument(void)
8333 IXMLDOMDocument *doc1, *doc2, *doc3;
8334 IXMLDOMDocument2 *doc, *doc_owner;
8336 IXMLDOMSchemaCollection *cache;
8341 doc = create_document(&IID_IXMLDOMDocument2);
8342 cache = create_cache(&IID_IXMLDOMSchemaCollection);
8345 if (doc) IXMLDOMDocument2_Release(doc);
8346 if (cache) IXMLDOMSchemaCollection_Release(cache);
8352 str = SysAllocString(szComplete4);
8353 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
8354 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8357 check_default_props(doc);
8359 /* set properties and check that new instances use them */
8360 set_props(doc, cache);
8361 check_set_props(doc);
8363 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8364 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc1));
8366 /* new interface keeps props */
8367 ole_check(IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8368 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
8369 check_set_props(doc_owner);
8370 IXMLDOMDocument2_Release(doc_owner);
8372 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc2));
8373 IXMLDOMNode_Release(node);
8375 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
8378 str = SysAllocString(szComplete4);
8379 ole_check(IXMLDOMDocument2_loadXML(doc, str, &b));
8380 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8383 /* properties retained even after reload */
8384 check_set_props(doc);
8386 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8387 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc3));
8388 IXMLDOMNode_Release(node);
8390 ole_check(IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8391 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
8392 check_set_props(doc_owner);
8394 /* changing properties for one instance changes them for all */
8395 unset_props(doc_owner);
8396 check_default_props(doc_owner);
8397 check_default_props(doc);
8399 IXMLDOMSchemaCollection_Release(cache);
8400 IXMLDOMDocument_Release(doc1);
8401 IXMLDOMDocument_Release(doc2);
8402 IXMLDOMDocument_Release(doc3);
8403 IXMLDOMDocument2_Release(doc);
8404 IXMLDOMDocument2_Release(doc_owner);
8408 static void test_setAttributeNode(void)
8410 IXMLDOMDocument *doc, *doc2;
8411 IXMLDOMElement *elem, *elem2;
8412 IXMLDOMAttribute *attr, *attr2, *ret_attr;
8419 doc = create_document(&IID_IXMLDOMDocument);
8422 str = SysAllocString( szComplete4 );
8423 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
8424 ok( hr == S_OK, "loadXML failed\n");
8425 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8426 SysFreeString( str );
8428 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8429 ok( hr == S_OK, "got 0x%08x\n", hr);
8431 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
8432 ok( hr == S_OK, "got 0x%08x\n", hr);
8433 ok( elem2 != elem, "got same instance\n");
8435 ret_attr = (void*)0xdeadbeef;
8436 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
8437 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8438 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8440 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8441 ok( hr == S_OK, "got 0x%08x\n", hr);
8443 ref1 = IXMLDOMElement_AddRef(elem);
8444 IXMLDOMElement_Release(elem);
8446 ret_attr = (void*)0xdeadbeef;
8447 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8448 ok( hr == S_OK, "got 0x%08x\n", hr);
8449 ok( ret_attr == NULL, "got %p\n", ret_attr);
8451 /* no reference added */
8452 ref2 = IXMLDOMElement_AddRef(elem);
8453 IXMLDOMElement_Release(elem);
8454 ok(ref2 == ref1, "got %d, expected %d\n", ref2, ref1);
8456 EXPECT_CHILDREN(elem);
8457 EXPECT_CHILDREN(elem2);
8459 IXMLDOMElement_Release(elem2);
8462 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
8463 ok( hr == S_OK, "got 0x%08x\n", hr);
8464 ok( attr2 != attr, "got same instance %p\n", attr2);
8465 IXMLDOMAttribute_Release(attr2);
8467 /* try to add it another time */
8468 ret_attr = (void*)0xdeadbeef;
8469 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8470 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8471 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8473 IXMLDOMElement_Release(elem);
8475 /* initialy used element is released, attribute still 'has' a container */
8476 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8477 ok( hr == S_OK, "got 0x%08x\n", hr);
8478 ret_attr = (void*)0xdeadbeef;
8479 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8480 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8481 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8482 IXMLDOMElement_Release(elem);
8484 /* add attribute already attached to another document */
8485 doc2 = create_document(&IID_IXMLDOMDocument);
8487 str = SysAllocString( szComplete4 );
8488 hr = IXMLDOMDocument_loadXML( doc2, str, &b );
8489 ok( hr == S_OK, "loadXML failed\n");
8490 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8491 SysFreeString( str );
8493 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
8494 ok( hr == S_OK, "got 0x%08x\n", hr);
8495 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
8496 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8497 IXMLDOMElement_Release(elem);
8499 IXMLDOMAttribute_Release(attr);
8501 /* create element, add attribute, see if it's copied or linked */
8502 hr = IXMLDOMDocument_createElement(doc, _bstr_("test"), &elem);
8503 ok( hr == S_OK, "got 0x%08x\n", hr);
8506 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8507 ok(hr == S_OK, "got 0x%08x\n", hr);
8508 ok(attr != NULL, "got %p\n", attr);
8510 ref1 = IXMLDOMAttribute_AddRef(attr);
8511 IXMLDOMAttribute_Release(attr);
8514 V_BSTR(&v) = _bstr_("attrvalue1");
8515 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8516 ok( hr == S_OK, "got 0x%08x\n", hr);
8519 hr = IXMLDOMAttribute_get_xml(attr, &str);
8520 ok( hr == S_OK, "got 0x%08x\n", hr);
8521 ok( lstrcmpW(str, _bstr_("attr=\"attrvalue1\"")) == 0,
8522 "got %s\n", wine_dbgstr_w(str));
8525 ret_attr = (void*)0xdeadbeef;
8526 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8527 ok(hr == S_OK, "got 0x%08x\n", hr);
8528 ok(ret_attr == NULL, "got %p\n", ret_attr);
8530 /* attribute reference increased */
8531 ref2 = IXMLDOMAttribute_AddRef(attr);
8532 IXMLDOMAttribute_Release(attr);
8533 ok(ref1 == ref2, "got %d, expected %d\n", ref2, ref1);
8535 hr = IXMLDOMElement_get_xml(elem, &str);
8536 ok( hr == S_OK, "got 0x%08x\n", hr);
8537 ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue1\"/>")) == 0,
8538 "got %s\n", wine_dbgstr_w(str));
8542 V_BSTR(&v) = _bstr_("attrvalue2");
8543 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8544 ok( hr == S_OK, "got 0x%08x\n", hr);
8546 hr = IXMLDOMElement_get_xml(elem, &str);
8547 ok( hr == S_OK, "got 0x%08x\n", hr);
8548 todo_wine ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue2\"/>")) == 0,
8549 "got %s\n", wine_dbgstr_w(str));
8552 IXMLDOMElement_Release(elem);
8553 IXMLDOMAttribute_Release(attr);
8554 IXMLDOMDocument_Release(doc2);
8555 IXMLDOMDocument_Release(doc);
8558 static void test_put_dataType(void)
8560 IXMLDOMCDATASection *cdata;
8561 IXMLDOMDocument *doc;
8566 doc = create_document(&IID_IXMLDOMDocument);
8569 str = SysAllocString( szComplete4 );
8570 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8571 ok( hr == S_OK, "loadXML failed\n");
8572 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8573 SysFreeString( str );
8575 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("test"), &cdata);
8576 ok( hr == S_OK, "got 0x%08x\n", hr);
8577 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("number"));
8578 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8579 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("string"));
8580 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8581 IXMLDOMCDATASection_Release(cdata);
8583 IXMLDOMDocument_Release(doc);
8587 static void test_createNode(void)
8589 IXMLDOMDocument *doc;
8590 IXMLDOMElement *elem;
8597 doc = create_document(&IID_IXMLDOMDocument);
8602 /* reference count tests */
8603 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8604 ok( hr == S_OK, "got 0x%08x\n", hr);
8606 /* initial reference is 2 */
8608 EXPECT_REF(elem, 2);
8609 ref = IXMLDOMElement_Release(elem);
8610 ok(ref == 1, "got %d\n", ref);
8611 /* it's released already, attempt to release now will crash it */
8614 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8615 ok( hr == S_OK, "got 0x%08x\n", hr);
8616 todo_wine EXPECT_REF(elem, 2);
8617 IXMLDOMDocument_Release(doc);
8618 todo_wine EXPECT_REF(elem, 2);
8619 IXMLDOMElement_Release(elem);
8621 doc = create_document(&IID_IXMLDOMDocument);
8623 /* NODE_ELEMENT nodes */
8624 /* 1. specified namespace */
8626 V_I4(&v) = NODE_ELEMENT;
8628 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
8629 ok( hr == S_OK, "got 0x%08x\n", hr);
8631 hr = IXMLDOMNode_get_prefix(node, &prefix);
8632 ok( hr == S_OK, "got 0x%08x\n", hr);
8633 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
8634 SysFreeString(prefix);
8635 IXMLDOMNode_Release(node);
8637 /* 2. default namespace */
8638 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
8639 ok( hr == S_OK, "got 0x%08x\n", hr);
8640 prefix = (void*)0xdeadbeef;
8641 hr = IXMLDOMNode_get_prefix(node, &prefix);
8642 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8643 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
8645 hr = IXMLDOMNode_get_xml(node, &str);
8646 ok( hr == S_OK, "got 0x%08x\n", hr);
8647 ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0,
8648 "got %s\n", wine_dbgstr_w(str));
8651 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
8652 ok( hr == S_OK, "got 0x%08x\n", hr);
8654 V_VT(&var) = VT_BSTR;
8655 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
8656 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8657 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
8660 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
8661 ok( hr == S_OK, "got 0x%08x\n", hr);
8662 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
8665 IXMLDOMElement_Release(elem);
8666 IXMLDOMNode_Release(node);
8668 IXMLDOMDocument_Release(doc);
8672 static void test_get_prefix(void)
8674 IXMLDOMDocumentFragment *fragment;
8675 IXMLDOMCDATASection *cdata;
8676 IXMLDOMElement *element;
8677 IXMLDOMComment *comment;
8678 IXMLDOMDocument *doc;
8682 doc = create_document(&IID_IXMLDOMDocument);
8685 /* nodes that can't support prefix */
8687 str = (void*)0xdeadbeef;
8688 hr = IXMLDOMDocument_get_prefix(doc, &str);
8689 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8690 ok( str == 0, "got %p\n", str);
8692 hr = IXMLDOMDocument_get_prefix(doc, NULL);
8693 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8696 hr = IXMLDOMDocument_createCDATASection(doc, NULL, &cdata);
8697 ok(hr == S_OK, "got %08x\n", hr );
8699 str = (void*)0xdeadbeef;
8700 hr = IXMLDOMCDATASection_get_prefix(cdata, &str);
8701 ok(hr == S_FALSE, "got %08x\n", hr);
8702 ok( str == 0, "got %p\n", str);
8704 hr = IXMLDOMCDATASection_get_prefix(cdata, NULL);
8705 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8706 IXMLDOMCDATASection_Release(cdata);
8709 hr = IXMLDOMDocument_createComment(doc, NULL, &comment);
8710 ok(hr == S_OK, "got %08x\n", hr );
8712 str = (void*)0xdeadbeef;
8713 hr = IXMLDOMComment_get_prefix(comment, &str);
8714 ok(hr == S_FALSE, "got %08x\n", hr);
8715 ok( str == 0, "got %p\n", str);
8717 hr = IXMLDOMComment_get_prefix(comment, NULL);
8718 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8719 IXMLDOMComment_Release(comment);
8722 hr = IXMLDOMDocument_createDocumentFragment(doc, &fragment);
8723 ok(hr == S_OK, "got %08x\n", hr );
8725 str = (void*)0xdeadbeef;
8726 hr = IXMLDOMDocumentFragment_get_prefix(fragment, &str);
8727 ok(hr == S_FALSE, "got %08x\n", hr);
8728 ok( str == 0, "got %p\n", str);
8730 hr = IXMLDOMDocumentFragment_get_prefix(fragment, NULL);
8731 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8732 IXMLDOMDocumentFragment_Release(fragment);
8735 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
8736 ok( hr == S_OK, "got 0x%08x\n", hr);
8738 hr = IXMLDOMElement_get_prefix(element, NULL);
8739 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8741 str = (void*)0xdeadbeef;
8742 hr = IXMLDOMElement_get_prefix(element, &str);
8743 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8744 ok( str == 0, "got %p\n", str);
8746 IXMLDOMElement_Release(element);
8749 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
8750 ok( hr == S_OK, "got 0x%08x\n", hr);
8752 str = (void*)0xdeadbeef;
8753 hr = IXMLDOMElement_get_prefix(element, &str);
8754 ok( hr == S_OK, "got 0x%08x\n", hr);
8755 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
8758 str = (void*)0xdeadbeef;
8759 hr = IXMLDOMElement_get_namespaceURI(element, &str);
8760 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8761 ok( str == 0, "got %p\n", str);
8763 IXMLDOMElement_Release(element);
8765 IXMLDOMDocument_Release(doc);
8769 static void test_selectSingleNode(void)
8771 IXMLDOMDocument *doc;
8772 IXMLDOMNodeList *list;
8779 doc = create_document(&IID_IXMLDOMDocument);
8782 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8783 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8785 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8786 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8788 str = SysAllocString( szComplete4 );
8789 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8790 ok( hr == S_OK, "loadXML failed\n");
8791 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8792 SysFreeString( str );
8794 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8795 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8797 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8798 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8800 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
8801 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8803 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
8804 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8806 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
8807 ok(hr == S_OK, "got 0x%08x\n", hr);
8808 IXMLDOMNode_Release(node);
8810 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
8811 ok(hr == S_OK, "got 0x%08x\n", hr);
8812 IXMLDOMNodeList_Release(list);
8814 list = (void*)0xdeadbeef;
8815 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
8816 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8817 ok(list == (void*)0xdeadbeef, "got %p\n", list);
8819 node = (void*)0xdeadbeef;
8820 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
8821 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8822 ok(node == 0, "got %p\n", node);
8824 list = (void*)0xdeadbeef;
8825 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
8826 ok(hr == S_OK, "got 0x%08x\n", hr);
8828 hr = IXMLDOMNodeList_get_length(list, &len);
8829 ok(hr == S_OK, "got 0x%08x\n", hr);
8830 ok(len == 0, "got %d\n", len);
8831 IXMLDOMNodeList_Release(list);
8833 IXMLDOMDocument_Release(doc);
8837 static void test_events(void)
8839 IConnectionPointContainer *conn;
8840 IConnectionPoint *point;
8841 IXMLDOMDocument *doc;
8846 doc = create_document(&IID_IXMLDOMDocument);
8849 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&conn);
8850 ok(hr == S_OK, "got 0x%08x\n", hr);
8852 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IDispatch, &point);
8853 ok(hr == S_OK, "got 0x%08x\n", hr);
8854 IConnectionPoint_Release(point);
8855 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IPropertyNotifySink, &point);
8856 ok(hr == S_OK, "got 0x%08x\n", hr);
8857 IConnectionPoint_Release(point);
8858 hr = IConnectionPointContainer_FindConnectionPoint(conn, &DIID_XMLDOMDocumentEvents, &point);
8859 ok(hr == S_OK, "got 0x%08x\n", hr);
8860 IConnectionPoint_Release(point);
8862 IConnectionPointContainer_Release(conn);
8864 /* ready state callback */
8866 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8867 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8869 event = create_dispevent();
8870 V_VT(&v) = VT_UNKNOWN;
8871 V_UNKNOWN(&v) = (IUnknown*)event;
8873 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8874 ok(hr == S_OK, "got 0x%08x\n", hr);
8875 EXPECT_REF(event, 2);
8877 V_VT(&v) = VT_DISPATCH;
8878 V_DISPATCH(&v) = event;
8880 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8881 ok(hr == S_OK, "got 0x%08x\n", hr);
8882 EXPECT_REF(event, 2);
8884 /* VT_NULL doesn't reset event handler */
8886 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8887 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8888 EXPECT_REF(event, 2);
8890 V_VT(&v) = VT_DISPATCH;
8891 V_DISPATCH(&v) = NULL;
8893 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8894 ok(hr == S_OK, "got 0x%08x\n", hr);
8895 EXPECT_REF(event, 1);
8897 V_VT(&v) = VT_UNKNOWN;
8898 V_DISPATCH(&v) = NULL;
8899 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8900 ok(hr == S_OK, "got 0x%08x\n", hr);
8902 IDispatch_Release(event);
8904 IXMLDOMDocument_Release(doc);
8907 static void test_createProcessingInstruction(void)
8909 static const WCHAR bodyW[] = {'t','e','s','t',0};
8910 IXMLDOMProcessingInstruction *pi;
8911 IXMLDOMDocument *doc;
8915 doc = create_document(&IID_IXMLDOMDocument);
8918 /* test for BSTR handling, pass broken BSTR */
8919 memcpy(&buff[2], bodyW, sizeof(bodyW));
8920 /* just a big length */
8921 *(DWORD*)buff = 0xf0f0;
8922 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("test"), &buff[2], &pi);
8923 ok(hr == S_OK, "got 0x%08x\n", hr);
8925 IXMLDOMProcessingInstruction_Release(pi);
8926 IXMLDOMDocument_Release(doc);
8929 static void test_put_nodeTypedValue(void)
8931 IXMLDOMDocument *doc;
8932 IXMLDOMElement *elem;
8936 doc = create_document(&IID_IXMLDOMDocument);
8939 hr = IXMLDOMDocument_createElement(doc, _bstr_("Element"), &elem);
8940 ok(hr == S_OK, "got 0x%08x\n", hr);
8942 V_VT(&type) = VT_EMPTY;
8943 hr = IXMLDOMElement_get_dataType(elem, &type);
8944 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8945 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8947 /* set typed value for untyped node */
8948 V_VT(&type) = VT_I1;
8950 hr = IXMLDOMElement_put_nodeTypedValue(elem, type);
8951 ok(hr == S_OK, "got 0x%08x\n", hr);
8953 V_VT(&type) = VT_EMPTY;
8954 hr = IXMLDOMElement_get_dataType(elem, &type);
8955 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8956 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8958 /* no type info stored */
8959 V_VT(&type) = VT_EMPTY;
8960 hr = IXMLDOMElement_get_nodeTypedValue(elem, &type);
8961 ok(hr == S_OK, "got 0x%08x\n", hr);
8962 ok(V_VT(&type) == VT_BSTR, "got %d, expected VT_BSTR\n", V_VT(&type));
8963 ok(memcmp(V_BSTR(&type), _bstr_("1"), 2*sizeof(WCHAR)) == 0,
8964 "got %s, expected \"1\"\n", wine_dbgstr_w(V_BSTR(&type)));
8965 VariantClear(&type);
8967 IXMLDOMElement_Release(elem);
8968 IXMLDOMDocument_Release(doc);
8972 static void test_get_xml(void)
8974 static const char xmlA[] = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<a>test</a>\r\n";
8975 static const char fooA[] = "<foo/>";
8976 IXMLDOMProcessingInstruction *pi;
8978 IXMLDOMElement *elem = NULL;
8979 IXMLDOMDocument *doc;
8985 doc = create_document(&IID_IXMLDOMDocument);
8989 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
8990 ok(hr == S_OK, "got 0x%08x\n", hr);
8991 ok( b == VARIANT_TRUE, "got %d\n", b);
8993 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"),
8994 _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &pi);
8995 ok(hr == S_OK, "got 0x%08x\n", hr);
8997 hr = IXMLDOMDocument_get_firstChild(doc, &first);
8998 ok(hr == S_OK, "got 0x%08x\n", hr);
9000 V_UNKNOWN(&v) = (IUnknown*)first;
9001 V_VT(&v) = VT_UNKNOWN;
9003 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)pi, v, NULL);
9004 ok(hr == S_OK, "got 0x%08x\n", hr);
9006 IXMLDOMProcessingInstruction_Release(pi);
9007 IXMLDOMNode_Release(first);
9009 hr = IXMLDOMDocument_get_xml(doc, &xml);
9010 ok(hr == S_OK, "got 0x%08x\n", hr);
9012 ok(memcmp(xml, _bstr_(xmlA), sizeof(xmlA)*sizeof(WCHAR)) == 0,
9013 "got %s, expected %s\n", wine_dbgstr_w(xml), xmlA);
9016 IXMLDOMDocument_Release(doc);
9018 doc = create_document(&IID_IXMLDOMDocument);
9020 hr = IXMLDOMDocument_createElement(doc, _bstr_("foo"), &elem);
9021 ok(hr == S_OK, "got 0x%08x\n", hr);
9023 hr = IXMLDOMDocument_putref_documentElement(doc, elem);
9024 ok(hr == S_OK, "got 0x%08x\n", hr);
9026 hr = IXMLDOMDocument_get_xml(doc, &xml);
9027 ok(hr == S_OK, "got 0x%08x\n", hr);
9029 ok(memcmp(xml, _bstr_(fooA), (sizeof(fooA)-1)*sizeof(WCHAR)) == 0,
9030 "got %s, expected %s\n", wine_dbgstr_w(xml), fooA);
9033 IXMLDOMElement_Release(elem);
9034 IXMLDOMDocument_Release(doc);
9039 static void test_xsltemplate(void)
9041 IXSLTemplate *template;
9042 IXSLProcessor *processor;
9043 IXMLDOMDocument *doc, *doc2;
9050 template = create_xsltemplate(&IID_IXSLTemplate);
9051 if (!template) return;
9053 /* works as reset */
9054 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9055 ok(hr == S_OK, "got 0x%08x\n", hr);
9057 doc = create_document(&IID_IXMLDOMDocument);
9060 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
9061 ok(hr == S_OK, "got 0x%08x\n", hr);
9062 ok( b == VARIANT_TRUE, "got %d\n", b);
9064 /* putref with non-xsl document */
9065 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9066 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9069 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9070 ok(hr == S_OK, "got 0x%08x\n", hr);
9071 ok( b == VARIANT_TRUE, "got %d\n", b);
9073 /* not a freethreaded document */
9074 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9075 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9077 IXMLDOMDocument_Release(doc);
9079 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
9082 win_skip("failed to create free threaded document instance: 0x%08x\n", hr);
9083 IXSLTemplate_Release(template);
9088 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9089 ok(hr == S_OK, "got 0x%08x\n", hr);
9090 ok( b == VARIANT_TRUE, "got %d\n", b);
9092 /* freethreaded document */
9093 ref1 = IXMLDOMDocument_AddRef(doc);
9094 IXMLDOMDocument_Release(doc);
9095 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9096 ok(hr == S_OK, "got 0x%08x\n", hr);
9097 ref2 = IXMLDOMDocument_AddRef(doc);
9098 IXMLDOMDocument_Release(doc);
9099 ok(ref2 > ref1, "got %d\n", ref2);
9102 hr = IXSLTemplate_createProcessor(template, NULL);
9103 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9105 EXPECT_REF(template, 1);
9106 hr = IXSLTemplate_createProcessor(template, &processor);
9107 ok(hr == S_OK, "got 0x%08x\n", hr);
9108 EXPECT_REF(template, 2);
9110 /* input no set yet */
9113 hr = IXSLProcessor_get_input(processor, &v);
9115 ok(hr == S_OK, "got 0x%08x\n", hr);
9116 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
9119 hr = IXSLProcessor_get_output(processor, NULL);
9120 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9122 /* reset before it was set */
9123 V_VT(&v) = VT_EMPTY;
9124 hr = IXSLProcessor_put_output(processor, v);
9125 ok(hr == S_OK, "got 0x%08x\n", hr);
9127 CreateStreamOnHGlobal(NULL, TRUE, &stream);
9128 EXPECT_REF(stream, 1);
9130 V_VT(&v) = VT_UNKNOWN;
9131 V_UNKNOWN(&v) = (IUnknown*)stream;
9132 hr = IXSLProcessor_put_output(processor, v);
9133 ok(hr == S_OK, "got 0x%08x\n", hr);
9135 /* it seems processor grabs 2 references */
9136 todo_wine EXPECT_REF(stream, 3);
9138 V_VT(&v) = VT_EMPTY;
9139 hr = IXSLProcessor_get_output(processor, &v);
9140 ok(hr == S_OK, "got 0x%08x\n", hr);
9141 ok(V_VT(&v) == VT_UNKNOWN, "got type %d\n", V_VT(&v));
9142 ok(V_UNKNOWN(&v) == (IUnknown*)stream, "got %p\n", V_UNKNOWN(&v));
9144 todo_wine EXPECT_REF(stream, 4);
9147 hr = IXSLProcessor_transform(processor, NULL);
9148 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9150 /* reset and check stream refcount */
9151 V_VT(&v) = VT_EMPTY;
9152 hr = IXSLProcessor_put_output(processor, v);
9153 ok(hr == S_OK, "got 0x%08x\n", hr);
9155 EXPECT_REF(stream, 1);
9157 IStream_Release(stream);
9159 /* no output interface set, check output */
9160 doc2 = create_document(&IID_IXMLDOMDocument);
9163 hr = IXMLDOMDocument_loadXML( doc2, _bstr_("<a>test</a>"), &b );
9164 ok(hr == S_OK, "got 0x%08x\n", hr);
9165 ok( b == VARIANT_TRUE, "got %d\n", b);
9167 V_VT(&v) = VT_UNKNOWN;
9168 V_UNKNOWN(&v) = (IUnknown*)doc2;
9169 hr = IXSLProcessor_put_input(processor, v);
9170 ok(hr == S_OK, "got 0x%08x\n", hr);
9172 hr = IXSLProcessor_transform(processor, &b);
9173 ok(hr == S_OK, "got 0x%08x\n", hr);
9175 V_VT(&v) = VT_EMPTY;
9176 hr = IXSLProcessor_get_output(processor, &v);
9177 ok(hr == S_OK, "got 0x%08x\n", hr);
9178 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
9179 /* we currently output one '\n' instead of empty string */
9180 todo_wine ok(lstrcmpW(V_BSTR(&v), _bstr_("")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
9181 IXMLDOMDocument_Release(doc2);
9184 IXSLProcessor_Release(processor);
9186 /* drop reference */
9187 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9188 ok(hr == S_OK, "got 0x%08x\n", hr);
9189 ref2 = IXMLDOMDocument_AddRef(doc);
9190 IXMLDOMDocument_Release(doc);
9191 ok(ref2 == ref1, "got %d\n", ref2);
9193 IXMLDOMDocument_Release(doc);
9194 IXSLTemplate_Release(template);
9198 static void test_insertBefore(void)
9200 IXMLDOMDocument *doc, *doc2;
9201 IXMLDOMAttribute *attr;
9202 IXMLDOMElement *elem1, *elem2, *elem3, *elem4, *elem5;
9203 IXMLDOMNode *node, *newnode;
9208 doc = create_document(&IID_IXMLDOMDocument);
9210 /* insertBefore behaviour for attribute node */
9212 V_I4(&v) = NODE_ATTRIBUTE;
9215 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr"), NULL, (IXMLDOMNode**)&attr);
9216 ok(hr == S_OK, "got 0x%08x\n", hr);
9217 ok(attr != NULL, "got %p\n", attr);
9219 /* attribute to attribute */
9221 V_I4(&v) = NODE_ATTRIBUTE;
9223 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr2"), NULL, &newnode);
9224 ok(hr == S_OK, "got 0x%08x\n", hr);
9225 ok(newnode != NULL, "got %p\n", newnode);
9228 node = (void*)0xdeadbeef;
9229 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9230 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9231 ok(node == NULL, "got %p\n", node);
9233 V_VT(&v) = VT_UNKNOWN;
9234 V_UNKNOWN(&v) = (IUnknown*)attr;
9235 node = (void*)0xdeadbeef;
9236 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9237 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9238 ok(node == NULL, "got %p\n", node);
9239 IXMLDOMNode_Release(newnode);
9241 /* cdata to attribute */
9243 V_I4(&v) = NODE_CDATA_SECTION;
9245 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9246 ok(hr == S_OK, "got 0x%08x\n", hr);
9247 ok(newnode != NULL, "got %p\n", newnode);
9250 node = (void*)0xdeadbeef;
9251 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9252 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9253 ok(node == NULL, "got %p\n", node);
9254 IXMLDOMNode_Release(newnode);
9256 /* comment to attribute */
9258 V_I4(&v) = NODE_COMMENT;
9260 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9261 ok(hr == S_OK, "got 0x%08x\n", hr);
9262 ok(newnode != NULL, "got %p\n", newnode);
9265 node = (void*)0xdeadbeef;
9266 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9267 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9268 ok(node == NULL, "got %p\n", node);
9269 IXMLDOMNode_Release(newnode);
9271 /* element to attribute */
9273 V_I4(&v) = NODE_ELEMENT;
9275 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9276 ok(hr == S_OK, "got 0x%08x\n", hr);
9277 ok(newnode != NULL, "got %p\n", newnode);
9280 node = (void*)0xdeadbeef;
9281 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9282 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9283 ok(node == NULL, "got %p\n", node);
9284 IXMLDOMNode_Release(newnode);
9286 /* pi to attribute */
9288 V_I4(&v) = NODE_PROCESSING_INSTRUCTION;
9290 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9291 ok(hr == S_OK, "got 0x%08x\n", hr);
9292 ok(newnode != NULL, "got %p\n", newnode);
9295 node = (void*)0xdeadbeef;
9296 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9297 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9298 ok(node == NULL, "got %p\n", node);
9299 IXMLDOMNode_Release(newnode);
9300 IXMLDOMAttribute_Release(attr);
9302 /* insertBefore for elements */
9303 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem1);
9304 ok(hr == S_OK, "got 0x%08x\n", hr);
9306 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem2"), &elem2);
9307 ok(hr == S_OK, "got 0x%08x\n", hr);
9309 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
9310 ok(hr == S_OK, "got 0x%08x\n", hr);
9312 EXPECT_NO_CHILDREN(elem1);
9313 EXPECT_NO_CHILDREN(elem2);
9314 EXPECT_NO_CHILDREN(elem3);
9316 todo_wine EXPECT_REF(elem2, 2);
9320 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9321 ok(hr == S_OK, "got 0x%08x\n", hr);
9322 ok(node == (void*)elem2, "got %p\n", node);
9324 EXPECT_CHILDREN(elem1);
9325 todo_wine EXPECT_REF(elem2, 3);
9326 IXMLDOMNode_Release(node);
9328 /* again for already linked node */
9331 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9332 ok(hr == S_OK, "got 0x%08x\n", hr);
9333 ok(node == (void*)elem2, "got %p\n", node);
9335 EXPECT_CHILDREN(elem1);
9337 /* increments each time */
9338 todo_wine EXPECT_REF(elem2, 3);
9339 IXMLDOMNode_Release(node);
9341 /* try to add to another element */
9343 node = (void*)0xdeadbeef;
9344 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem2, v, &node);
9345 ok(hr == S_OK, "got 0x%08x\n", hr);
9346 ok(node == (void*)elem2, "got %p\n", node);
9348 EXPECT_CHILDREN(elem3);
9349 EXPECT_NO_CHILDREN(elem1);
9351 IXMLDOMNode_Release(node);
9353 /* cross document case - try to add as child to a node created with other doc */
9354 doc2 = create_document(&IID_IXMLDOMDocument);
9356 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem4);
9357 ok(hr == S_OK, "got 0x%08x\n", hr);
9358 todo_wine EXPECT_REF(elem4, 2);
9360 /* same name, another instance */
9361 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem5);
9362 ok(hr == S_OK, "got 0x%08x\n", hr);
9363 todo_wine EXPECT_REF(elem5, 2);
9365 todo_wine EXPECT_REF(elem3, 2);
9368 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem4, v, &node);
9369 ok(hr == S_OK, "got 0x%08x\n", hr);
9370 ok(node == (void*)elem4, "got %p\n", node);
9371 todo_wine EXPECT_REF(elem4, 3);
9372 todo_wine EXPECT_REF(elem3, 2);
9373 IXMLDOMNode_Release(node);
9377 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem5, v, &node);
9378 ok(hr == S_OK, "got 0x%08x\n", hr);
9379 ok(node == (void*)elem5, "got %p\n", node);
9380 todo_wine EXPECT_REF(elem4, 2);
9381 todo_wine EXPECT_REF(elem5, 3);
9382 IXMLDOMNode_Release(node);
9384 IXMLDOMDocument_Release(doc2);
9386 IXMLDOMElement_Release(elem1);
9387 IXMLDOMElement_Release(elem2);
9388 IXMLDOMElement_Release(elem3);
9389 IXMLDOMElement_Release(elem4);
9390 IXMLDOMElement_Release(elem5);
9392 /* elements with same default namespace */
9394 V_I4(&v) = NODE_ELEMENT;
9396 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
9397 ok(hr == S_OK, "got 0x%08x\n", hr);
9398 ok(elem1 != NULL, "got %p\n", elem1);
9401 V_I4(&v) = NODE_ELEMENT;
9403 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem2);
9404 ok(hr == S_OK, "got 0x%08x\n", hr);
9405 ok(elem2 != NULL, "got %p\n", elem2);
9407 /* check contents so far */
9409 hr = IXMLDOMElement_get_xml(elem1, &p);
9410 ok(hr == S_OK, "got 0x%08x\n", hr);
9411 ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9415 hr = IXMLDOMElement_get_xml(elem2, &p);
9416 ok(hr == S_OK, "got 0x%08x\n", hr);
9417 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9421 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
9422 ok(hr == S_OK, "got 0x%08x\n", hr);
9424 /* get_xml depends on context, for top node it omits child namespace attribute,
9425 but at child level it's still returned */
9427 hr = IXMLDOMElement_get_xml(elem1, &p);
9428 ok(hr == S_OK, "got 0x%08x\n", hr);
9429 todo_wine ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"><elem2/></elem1>")),
9430 "got %s\n", wine_dbgstr_w(p));
9434 hr = IXMLDOMElement_get_xml(elem2, &p);
9435 ok(hr == S_OK, "got 0x%08x\n", hr);
9436 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9439 IXMLDOMElement_Release(elem1);
9440 IXMLDOMElement_Release(elem2);
9442 /* child without default namespace added to node with default namespace */
9444 V_I4(&v) = NODE_ELEMENT;
9446 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
9447 ok(hr == S_OK, "got 0x%08x\n", hr);
9448 ok(elem1 != NULL, "got %p\n", elem1);
9451 V_I4(&v) = NODE_ELEMENT;
9453 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), NULL, (IXMLDOMNode**)&elem2);
9454 ok(hr == S_OK, "got 0x%08x\n", hr);
9455 ok(elem2 != NULL, "got %p\n", elem2);
9457 EXPECT_REF(elem2, 1);
9459 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
9460 ok(hr == S_OK, "got 0x%08x\n", hr);
9461 EXPECT_REF(elem2, 1);
9464 hr = IXMLDOMElement_get_xml(elem2, &p);
9465 ok(hr == S_OK, "got 0x%08x\n", hr);
9466 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
9469 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem2, NULL);
9470 ok(hr == S_OK, "got 0x%08x\n", hr);
9473 hr = IXMLDOMElement_get_xml(elem2, &p);
9474 ok(hr == S_OK, "got 0x%08x\n", hr);
9475 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
9478 IXMLDOMElement_Release(elem1);
9479 IXMLDOMElement_Release(elem2);
9480 IXMLDOMDocument_Release(doc);
9483 static void test_appendChild(void)
9485 IXMLDOMDocument *doc, *doc2;
9486 IXMLDOMElement *elem, *elem2;
9489 doc = create_document(&IID_IXMLDOMDocument);
9490 doc2 = create_document(&IID_IXMLDOMDocument);
9492 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
9493 ok(hr == S_OK, "got 0x%08x\n", hr);
9495 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem2"), &elem2);
9496 ok(hr == S_OK, "got 0x%08x\n", hr);
9499 todo_wine EXPECT_REF(elem, 2);
9500 EXPECT_REF(doc2, 1);
9501 todo_wine EXPECT_REF(elem2, 2);
9502 EXPECT_NO_CHILDREN(doc);
9503 EXPECT_NO_CHILDREN(doc2);
9505 /* append from another document */
9506 hr = IXMLDOMDocument_appendChild(doc2, (IXMLDOMNode*)elem, NULL);
9507 ok(hr == S_OK, "got 0x%08x\n", hr);
9510 todo_wine EXPECT_REF(elem, 2);
9511 EXPECT_REF(doc2, 1);
9512 todo_wine EXPECT_REF(elem2, 2);
9513 EXPECT_NO_CHILDREN(doc);
9514 EXPECT_CHILDREN(doc2);
9516 IXMLDOMElement_Release(elem);
9517 IXMLDOMElement_Release(elem2);
9518 IXMLDOMDocument_Release(doc);
9519 IXMLDOMDocument_Release(doc2);
9522 static void test_get_doctype(void)
9524 IXMLDOMDocumentType *doctype;
9525 IXMLDOMDocument *doc;
9528 doc = create_document(&IID_IXMLDOMDocument);
9530 hr = IXMLDOMDocument_get_doctype(doc, NULL);
9531 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9533 doctype = (void*)0xdeadbeef;
9534 hr = IXMLDOMDocument_get_doctype(doc, &doctype);
9535 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9536 ok(doctype == NULL, "got %p\n", doctype);
9538 IXMLDOMDocument_Release(doc);
9541 static void test_get_tagName(void)
9543 IXMLDOMDocument *doc;
9544 IXMLDOMElement *elem, *elem2;
9548 doc = create_document(&IID_IXMLDOMDocument);
9550 hr = IXMLDOMDocument_createElement(doc, _bstr_("element"), &elem);
9551 ok(hr == S_OK, "got 0x%08x\n", hr);
9553 hr = IXMLDOMElement_get_tagName(elem, NULL);
9554 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9557 hr = IXMLDOMElement_get_tagName(elem, &str);
9558 ok(hr == S_OK, "got 0x%08x\n", hr);
9559 ok(!lstrcmpW(str, _bstr_("element")), "got %s\n", wine_dbgstr_w(str));
9562 hr = IXMLDOMDocument_createElement(doc, _bstr_("s:element"), &elem2);
9563 ok(hr == S_OK, "got 0x%08x\n", hr);
9566 hr = IXMLDOMElement_get_tagName(elem2, &str);
9567 ok(hr == S_OK, "got 0x%08x\n", hr);
9568 ok(!lstrcmpW(str, _bstr_("s:element")), "got %s\n", wine_dbgstr_w(str));
9571 IXMLDOMDocument_Release(elem);
9572 IXMLDOMDocument_Release(elem2);
9573 IXMLDOMDocument_Release(doc);
9577 typedef struct _get_datatype_t {
9584 static const get_datatype_t get_datatype[] = {
9585 { NODE_ELEMENT, "element", VT_NULL, S_FALSE },
9586 { NODE_ATTRIBUTE, "attr", VT_NULL, S_FALSE },
9587 { NODE_TEXT, "text", VT_NULL, S_FALSE },
9588 { NODE_CDATA_SECTION , "cdata", VT_NULL, S_FALSE },
9589 { NODE_ENTITY_REFERENCE, "entityref", VT_NULL, S_FALSE },
9590 { NODE_PROCESSING_INSTRUCTION, "pi", VT_NULL, S_FALSE },
9591 { NODE_COMMENT, "comment", VT_NULL, S_FALSE },
9592 { NODE_DOCUMENT_FRAGMENT, "docfrag", VT_NULL, S_FALSE },
9596 static void test_get_dataType(void)
9598 IXMLDOMDocument *doc;
9599 const get_datatype_t *entry = get_datatype;
9601 doc = create_document(&IID_IXMLDOMDocument);
9605 IXMLDOMNode *node = NULL;
9610 V_I4(&var) = entry->type;
9611 hr = IXMLDOMDocument_createNode(doc, var, _bstr_(entry->name), NULL, &node);
9612 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9614 hr = IXMLDOMNode_get_dataType(node, NULL);
9615 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9618 hr = IXMLDOMNode_get_dataType(node, &type);
9619 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9620 hr, entry->hr, entry->type);
9621 ok(V_VT(&type) == entry->vt, "got %d, expected %d. node type %d\n",
9622 V_VT(&type), entry->vt, entry->type);
9623 VariantClear(&type);
9625 IXMLDOMNode_Release(node);
9630 IXMLDOMDocument_Release(doc);
9634 typedef struct _get_node_typestring_t {
9637 } get_node_typestring_t;
9639 static const get_node_typestring_t get_node_typestring[] = {
9640 { NODE_ELEMENT, "element" },
9641 { NODE_ATTRIBUTE, "attribute" },
9642 { NODE_TEXT, "text" },
9643 { NODE_CDATA_SECTION , "cdatasection" },
9644 { NODE_ENTITY_REFERENCE, "entityreference" },
9645 { NODE_PROCESSING_INSTRUCTION, "processinginstruction" },
9646 { NODE_COMMENT, "comment" },
9647 { NODE_DOCUMENT_FRAGMENT, "documentfragment" },
9651 static void test_get_nodeTypeString(void)
9653 const get_node_typestring_t *entry = get_node_typestring;
9654 IXMLDOMDocument *doc;
9658 doc = create_document(&IID_IXMLDOMDocument);
9660 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
9661 ok(hr == S_OK, "got 0x%08x\n", hr);
9662 ok(!lstrcmpW(str, _bstr_("document")), "got string %s\n", wine_dbgstr_w(str));
9667 IXMLDOMNode *node = NULL;
9671 V_I4(&var) = entry->type;
9672 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9673 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9675 hr = IXMLDOMNode_get_nodeTypeString(node, NULL);
9676 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9678 hr = IXMLDOMNode_get_nodeTypeString(node, &str);
9679 ok(hr == S_OK, "got 0x%08x\n", hr);
9680 ok(!lstrcmpW(str, _bstr_(entry->string)), "got string %s, expected %s. node type %d\n",
9681 wine_dbgstr_w(str), entry->string, entry->type);
9683 IXMLDOMNode_Release(node);
9688 IXMLDOMDocument_Release(doc);
9692 typedef struct _get_attributes_t {
9697 static const get_attributes_t get_attributes[] = {
9698 { NODE_ATTRIBUTE, S_FALSE },
9699 { NODE_TEXT, S_FALSE },
9700 { NODE_CDATA_SECTION , S_FALSE },
9701 { NODE_ENTITY_REFERENCE, S_FALSE },
9702 { NODE_PROCESSING_INSTRUCTION, S_FALSE },
9703 { NODE_COMMENT, S_FALSE },
9704 { NODE_DOCUMENT_FRAGMENT, S_FALSE },
9708 static void test_get_attributes(void)
9710 const get_attributes_t *entry = get_attributes;
9711 IXMLDOMNamedNodeMap *map;
9712 IXMLDOMDocument *doc;
9713 IXMLDOMNode *node, *node2;
9719 doc = create_document(&IID_IXMLDOMDocument);
9721 str = SysAllocString( szComplete4 );
9722 hr = IXMLDOMDocument_loadXML(doc, str, &b);
9725 hr = IXMLDOMDocument_get_attributes(doc, NULL);
9726 ok(hr == E_INVALIDARG, "got %08x\n", hr);
9728 map = (void*)0xdeadbeef;
9729 hr = IXMLDOMDocument_get_attributes(doc, &map);
9730 ok(hr == S_FALSE, "got %08x\n", hr);
9731 ok(map == NULL, "got %p\n", map);
9733 /* first child is <?xml ?> */
9734 hr = IXMLDOMDocument_get_firstChild(doc, &node);
9735 ok(hr == S_OK, "got %08x\n", hr);
9737 hr = IXMLDOMNode_get_attributes(node, &map);
9738 ok(hr == S_OK, "got %08x\n", hr);
9741 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9742 EXPECT_HR(hr, S_OK);
9743 todo_wine ok(length == 1, "got %d\n", length);
9745 if (hr == S_OK && length == 1)
9747 IXMLDOMAttribute *attr;
9752 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9753 EXPECT_HR(hr, S_OK);
9754 ok(node != NULL, "got %p\n", node2);
9756 hr = IXMLDOMNode_get_nodeName(node2, &str);
9757 EXPECT_HR(hr, S_OK);
9758 ok(!lstrcmpW(str, _bstr_("version")), "got %s\n", wine_dbgstr_w(str));
9762 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9763 EXPECT_HR(hr, S_OK);
9764 ok(length == 1, "got %d\n", length);
9767 hr = IXMLDOMNode_get_nodeType(node2, &type);
9768 EXPECT_HR(hr, S_OK);
9769 ok(type == NODE_ATTRIBUTE, "got %d\n", type);
9771 hr = IXMLDOMNode_get_xml(node, &str);
9772 EXPECT_HR(hr, S_OK);
9773 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9776 hr = IXMLDOMNode_get_text(node, &str);
9777 EXPECT_HR(hr, S_OK);
9778 ok(!lstrcmpW(str, _bstr_("version=\"1.0\"")), "got %s\n", wine_dbgstr_w(str));
9781 hr = IXMLDOMNamedNodeMap_removeNamedItem(map, _bstr_("version"), NULL);
9782 EXPECT_HR(hr, S_OK);
9785 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9786 EXPECT_HR(hr, S_OK);
9787 ok(length == 0, "got %d\n", length);
9789 hr = IXMLDOMNode_get_xml(node, &str);
9790 EXPECT_HR(hr, S_OK);
9791 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9794 hr = IXMLDOMNode_get_text(node, &str);
9795 EXPECT_HR(hr, S_OK);
9796 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
9799 IXMLDOMNamedNodeMap_Release(map);
9801 hr = IXMLDOMNode_get_attributes(node, &map);
9802 ok(hr == S_OK, "got %08x\n", hr);
9805 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9806 EXPECT_HR(hr, S_OK);
9807 ok(length == 0, "got %d\n", length);
9809 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("encoding"), &attr);
9810 EXPECT_HR(hr, S_OK);
9813 V_BSTR(&v) = _bstr_("UTF-8");
9814 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
9815 EXPECT_HR(hr, S_OK);
9817 EXPECT_REF(attr, 2);
9818 hr = IXMLDOMNamedNodeMap_setNamedItem(map, (IXMLDOMNode*)attr, NULL);
9819 EXPECT_HR(hr, S_OK);
9820 EXPECT_REF(attr, 2);
9822 hr = IXMLDOMNode_get_attributes(node, &map);
9823 ok(hr == S_OK, "got %08x\n", hr);
9826 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9827 EXPECT_HR(hr, S_OK);
9828 ok(length == 1, "got %d\n", length);
9830 hr = IXMLDOMNode_get_xml(node, &str);
9831 EXPECT_HR(hr, S_OK);
9832 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9835 hr = IXMLDOMNode_get_text(node, &str);
9836 EXPECT_HR(hr, S_OK);
9837 ok(!lstrcmpW(str, _bstr_("encoding=\"UTF-8\"")), "got %s\n", wine_dbgstr_w(str));
9840 IXMLDOMNamedNodeMap_Release(map);
9841 IXMLDOMNode_Release(node2);
9844 IXMLDOMNode_Release(node);
9846 /* last child is element */
9848 hr = IXMLDOMDocument_get_lastChild(doc, &node);
9849 ok(hr == S_OK, "got %08x\n", hr);
9852 EXPECT_REF(node, 1);
9853 hr = IXMLDOMNode_get_attributes(node, &map);
9854 ok(hr == S_OK, "got %08x\n", hr);
9855 EXPECT_REF(node, 1);
9859 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9860 ok(hr == S_OK, "got %08x\n", hr);
9861 EXPECT_REF(node, 1);
9862 EXPECT_REF(node2, 1);
9865 IXMLDOMNode_Release(node2);
9867 /* release node before map release, map still works */
9868 IXMLDOMNode_Release(node);
9871 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9872 ok(hr == S_OK, "got %08x\n", hr);
9873 ok(length == 1, "got %d\n", length);
9876 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9877 ok(hr == S_OK, "got %08x\n", hr);
9878 EXPECT_REF(node2, 1);
9879 IXMLDOMNode_Release(node2);
9881 IXMLDOMNamedNodeMap_Release(map);
9890 V_I4(&var) = entry->type;
9891 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9892 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9894 hr = IXMLDOMNode_get_attributes(node, NULL);
9895 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9897 map = (void*)0xdeadbeef;
9898 hr = IXMLDOMNode_get_attributes(node, &map);
9899 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9900 hr, entry->hr, entry->type);
9901 ok(map == NULL, "got %p\n", map);
9903 IXMLDOMNode_Release(node);
9908 IXMLDOMDocument_Release(doc);
9912 static void test_selection(void)
9914 IXMLDOMSelection *selection;
9915 IXMLDOMNodeList *list;
9916 IXMLDOMDocument *doc;
9920 doc = create_document(&IID_IXMLDOMDocument);
9922 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
9923 EXPECT_HR(hr, S_OK);
9925 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list);
9926 EXPECT_HR(hr, S_OK);
9928 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
9929 EXPECT_HR(hr, S_OK);
9930 IXMLDOMSelection_Release(selection);
9932 IXMLDOMNodeList_Release(list);
9934 hr = IXMLDOMDocument_get_childNodes(doc, &list);
9935 EXPECT_HR(hr, S_OK);
9937 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
9938 EXPECT_HR(hr, E_NOINTERFACE);
9940 IXMLDOMNodeList_Release(list);
9942 IXMLDOMDocument_Release(doc);
9946 static void test_load(void)
9948 IXMLDOMDocument *doc;
9957 /* prepare a file */
9958 hfile = CreateFileA("test.xml", GENERIC_WRITE|GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
9959 ok(hfile != INVALID_HANDLE_VALUE, "failed to create test file\n");
9960 if(hfile == INVALID_HANDLE_VALUE) return;
9962 ret = WriteFile(hfile, szNonUnicodeXML, sizeof(szNonUnicodeXML)-1, &written, NULL);
9963 ok(ret, "WriteFile failed\n");
9967 doc = create_document(&IID_IXMLDOMDocument);
9969 path = _bstr_("test.xml");
9971 /* load from path: VT_BSTR */
9972 V_VT(&src) = VT_BSTR;
9973 V_BSTR(&src) = path;
9974 hr = IXMLDOMDocument_load(doc, src, &b);
9975 EXPECT_HR(hr, S_OK);
9976 ok(b == VARIANT_TRUE, "got %d\n", b);
9978 /* load from a path: VT_BSTR|VT_BYREF */
9979 V_VT(&src) = VT_BSTR | VT_BYREF;
9980 V_BSTRREF(&src) = &path;
9981 hr = IXMLDOMDocument_load(doc, src, &b);
9982 EXPECT_HR(hr, S_OK);
9983 ok(b == VARIANT_TRUE, "got %d\n", b);
9985 /* load from a path: VT_BSTR|VT_BYREF, null ptr */
9986 V_VT(&src) = VT_BSTR | VT_BYREF;
9987 V_BSTRREF(&src) = NULL;
9988 hr = IXMLDOMDocument_load(doc, src, &b);
9989 EXPECT_HR(hr, E_INVALIDARG);
9990 ok(b == VARIANT_FALSE, "got %d\n", b);
9992 IXMLDOMDocument_Release(doc);
9994 DeleteFileA("test.xml");
10000 IXMLDOMDocument *doc;
10003 hr = CoInitialize( NULL );
10004 ok( hr == S_OK, "failed to init com\n");
10005 if (hr != S_OK) return;
10009 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc );
10012 win_skip("IXMLDOMDocument is not available (0x%08x)\n", hr);
10016 IXMLDOMDocument_Release(doc);
10019 test_persiststreaminit();
10023 test_getElementsByTagName();
10025 test_get_childNodes();
10026 test_get_firstChild();
10027 test_get_lastChild();
10028 test_removeChild();
10029 test_replaceChild();
10030 test_removeNamedItem();
10031 test_IXMLDOMDocument2();
10037 test_nodeTypeTests();
10039 test_testTransforms();
10041 test_FormattingXML();
10042 test_nodeTypedValue();
10043 test_TransformWithLoadingLocalFile();
10044 test_put_nodeValue();
10045 test_document_IObjectSafety();
10047 test_getQualifiedItem();
10048 test_removeQualifiedItem();
10049 test_get_ownerDocument();
10050 test_setAttributeNode();
10051 test_put_dataType();
10054 test_default_properties();
10055 test_selectSingleNode();
10057 test_createProcessingInstruction();
10058 test_put_nodeTypedValue();
10060 test_insertBefore();
10061 test_appendChild();
10062 test_get_doctype();
10063 test_get_tagName();
10064 test_get_dataType();
10065 test_get_nodeTypeString();
10066 test_get_attributes();
10070 test_xsltemplate();