msvcp71: Added iterator based basic_string::replace implementation.
[wine/multimedia.git] / dlls / msxml3 / tests / domdoc.c
blob817cf97da7d0da01b25ba1af90932d3493d0bab9
1 /*
2 * XML test
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-2012 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
25 #define COBJMACROS
26 #define CONST_VTABLE
28 #include <stdio.h>
29 #include <assert.h>
31 #include "windows.h"
33 #include "msxml2.h"
34 #include "msxml2did.h"
35 #include "ole2.h"
36 #include "dispex.h"
38 #include "initguid.h"
39 #include "objsafe.h"
40 #include "mshtml.h"
42 #include "wine/test.h"
44 /* undef the #define in msxml2 so that we can access all versions */
45 #undef CLSID_DOMDocument
47 DEFINE_GUID(SID_SContainerDispatch, 0xb722be00, 0x4e68, 0x101b, 0xa2, 0xbc, 0x00, 0xaa, 0x00, 0x40, 0x47, 0x70);
48 DEFINE_GUID(SID_UnknownSID, 0x75dd09cb, 0x6c40, 0x11d5, 0x85, 0x43, 0x00, 0xc0, 0x4f, 0xa0, 0xfb, 0xa3);
49 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
51 #define DEFINE_EXPECT(func) \
52 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
54 #define SET_EXPECT(func) \
55 expect_ ## func = TRUE
57 #define CHECK_EXPECT2(func) \
58 do { \
59 ok(expect_ ##func, "unexpected call " #func "\n"); \
60 called_ ## func = TRUE; \
61 }while(0)
63 #define CHECK_CALLED(func) \
64 do { \
65 ok(called_ ## func, "expected " #func "\n"); \
66 expect_ ## func = called_ ## func = FALSE; \
67 }while(0)
69 static const char *debugstr_guid(REFIID riid)
71 static char buf[50];
73 if(!riid)
74 return "(null)";
76 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
77 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
78 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
79 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
81 return buf;
84 static int g_unexpectedcall, g_expectedcall;
86 typedef struct
88 IDispatch IDispatch_iface;
89 LONG ref;
90 } dispevent;
92 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
94 return CONTAINING_RECORD(iface, dispevent, IDispatch_iface);
97 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
99 *ppvObject = NULL;
101 if ( IsEqualGUID( riid, &IID_IDispatch) ||
102 IsEqualGUID( riid, &IID_IUnknown) )
104 *ppvObject = iface;
106 else
107 return E_NOINTERFACE;
109 IDispatch_AddRef( iface );
111 return S_OK;
114 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
116 dispevent *This = impl_from_IDispatch( iface );
117 return InterlockedIncrement( &This->ref );
120 static ULONG WINAPI dispevent_Release(IDispatch *iface)
122 dispevent *This = impl_from_IDispatch( iface );
123 ULONG ref = InterlockedDecrement( &This->ref );
125 if (ref == 0)
126 HeapFree(GetProcessHeap(), 0, This);
128 return ref;
131 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
133 g_unexpectedcall++;
134 *pctinfo = 0;
135 return S_OK;
138 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
139 LCID lcid, ITypeInfo **ppTInfo)
141 g_unexpectedcall++;
142 return S_OK;
145 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
146 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
148 g_unexpectedcall++;
149 return S_OK;
152 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
153 LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
154 EXCEPINFO *excepInfo, UINT *argErr)
156 ok(member == 0, "expected 0 member, got %d\n", member);
157 ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
158 ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
160 ok(params->cArgs == 0, "got %d\n", params->cArgs);
161 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
162 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
163 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
165 ok(result == NULL, "got %p\n", result);
166 ok(excepInfo == NULL, "got %p\n", excepInfo);
167 ok(argErr == NULL, "got %p\n", argErr);
169 g_expectedcall++;
170 return E_FAIL;
173 static const IDispatchVtbl dispeventVtbl =
175 dispevent_QueryInterface,
176 dispevent_AddRef,
177 dispevent_Release,
178 dispevent_GetTypeInfoCount,
179 dispevent_GetTypeInfo,
180 dispevent_GetIDsOfNames,
181 dispevent_Invoke
184 static IDispatch* create_dispevent(void)
186 dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
188 event->IDispatch_iface.lpVtbl = &dispeventVtbl;
189 event->ref = 1;
191 return (IDispatch*)&event->IDispatch_iface;
194 /* object site */
195 DEFINE_EXPECT(site_qi_IServiceProvider);
196 DEFINE_EXPECT(site_qi_IXMLDOMDocument);
197 DEFINE_EXPECT(site_qi_IOleClientSite);
199 DEFINE_EXPECT(sp_queryservice_SID_SBindHost);
200 DEFINE_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
201 DEFINE_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
202 DEFINE_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
203 DEFINE_EXPECT(sp_queryservice_SID_secmgr_secmgr);
205 DEFINE_EXPECT(htmldoc2_get_all);
206 DEFINE_EXPECT(htmldoc2_get_url);
207 DEFINE_EXPECT(collection_get_length);
209 typedef struct
211 IServiceProvider IServiceProvider_iface;
212 } testprov_t;
214 testprov_t testprov;
216 static HRESULT WINAPI site_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
218 *ppvObject = NULL;
220 if (IsEqualGUID(riid, &IID_IServiceProvider))
221 CHECK_EXPECT2(site_qi_IServiceProvider);
223 if (IsEqualGUID(riid, &IID_IXMLDOMDocument))
224 CHECK_EXPECT2(site_qi_IXMLDOMDocument);
226 if (IsEqualGUID(riid, &IID_IOleClientSite))
227 CHECK_EXPECT2(site_qi_IOleClientSite);
229 if (IsEqualGUID(riid, &IID_IUnknown))
230 *ppvObject = iface;
231 else if (IsEqualGUID(riid, &IID_IServiceProvider))
232 *ppvObject = &testprov.IServiceProvider_iface;
234 if (*ppvObject) IUnknown_AddRef(iface);
236 return *ppvObject ? S_OK : E_NOINTERFACE;
239 static ULONG WINAPI site_AddRef(IUnknown *iface)
241 return 2;
244 static ULONG WINAPI site_Release(IUnknown *iface)
246 return 1;
249 static const IUnknownVtbl testsiteVtbl =
251 site_QueryInterface,
252 site_AddRef,
253 site_Release
256 typedef struct
258 IUnknown IUnknown_iface;
259 } testsite_t;
261 static testsite_t testsite = { { &testsiteVtbl } };
263 /* test IHTMLElementCollection */
264 static HRESULT WINAPI htmlecoll_QueryInterface(IHTMLElementCollection *iface, REFIID riid, void **ppvObject)
266 ok(0, "unexpected call\n");
267 *ppvObject = NULL;
268 return E_NOINTERFACE;
271 static ULONG WINAPI htmlecoll_AddRef(IHTMLElementCollection *iface)
273 return 2;
276 static ULONG WINAPI htmlecoll_Release(IHTMLElementCollection *iface)
278 return 1;
281 static HRESULT WINAPI htmlecoll_GetTypeInfoCount(IHTMLElementCollection *iface, UINT *pctinfo)
283 ok(0, "unexpected call\n");
284 return E_NOTIMPL;
287 static HRESULT WINAPI htmlecoll_GetTypeInfo(IHTMLElementCollection *iface, UINT iTInfo,
288 LCID lcid, ITypeInfo **ppTInfo)
290 ok(0, "unexpected call\n");
291 return E_NOTIMPL;
294 static HRESULT WINAPI htmlecoll_GetIDsOfNames(IHTMLElementCollection *iface, REFIID riid,
295 LPOLESTR *rgszNames, UINT cNames,
296 LCID lcid, DISPID *rgDispId)
298 ok(0, "unexpected call\n");
299 return E_NOTIMPL;
302 static HRESULT WINAPI htmlecoll_Invoke(IHTMLElementCollection *iface, DISPID dispIdMember,
303 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
304 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
306 ok(0, "unexpected call\n");
307 return E_NOTIMPL;
310 static HRESULT WINAPI htmlecoll_toString(IHTMLElementCollection *iface, BSTR *String)
312 ok(0, "unexpected call\n");
313 return E_NOTIMPL;
316 static HRESULT WINAPI htmlecoll_put_length(IHTMLElementCollection *iface, LONG v)
318 ok(0, "unexpected call\n");
319 return E_NOTIMPL;
322 static HRESULT WINAPI htmlecoll_get_length(IHTMLElementCollection *iface, LONG *v)
324 CHECK_EXPECT2(collection_get_length);
325 return E_NOTIMPL;
328 static HRESULT WINAPI htmlecoll_get__newEnum(IHTMLElementCollection *iface, IUnknown **p)
330 ok(0, "unexpected call\n");
331 return E_NOTIMPL;
334 static HRESULT WINAPI htmlecoll_item(IHTMLElementCollection *iface, VARIANT name, VARIANT index, IDispatch **pdisp)
336 ok(0, "unexpected call\n");
337 return E_NOTIMPL;
340 static HRESULT WINAPI htmlecoll_tags(IHTMLElementCollection *iface, VARIANT tagName, IDispatch **pdisp)
342 ok(0, "unexpected call\n");
343 return E_NOTIMPL;
346 static const IHTMLElementCollectionVtbl TestHTMLECollectionVtbl = {
347 htmlecoll_QueryInterface,
348 htmlecoll_AddRef,
349 htmlecoll_Release,
350 htmlecoll_GetTypeInfoCount,
351 htmlecoll_GetTypeInfo,
352 htmlecoll_GetIDsOfNames,
353 htmlecoll_Invoke,
355 htmlecoll_toString,
356 htmlecoll_put_length,
357 htmlecoll_get_length,
358 htmlecoll_get__newEnum,
359 htmlecoll_item,
360 htmlecoll_tags
363 typedef struct
365 IHTMLElementCollection IHTMLElementCollection_iface;
366 } testhtmlecoll_t;
368 static testhtmlecoll_t htmlecoll = { { &TestHTMLECollectionVtbl } };
370 /* test IHTMLDocument2 */
371 static HRESULT WINAPI htmldoc2_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
373 trace("\n");
374 *ppvObject = NULL;
375 return E_NOINTERFACE;
378 static ULONG WINAPI htmldoc2_AddRef(IHTMLDocument2 *iface)
380 return 2;
383 static ULONG WINAPI htmldoc2_Release(IHTMLDocument2 *iface)
385 return 1;
388 static HRESULT WINAPI htmldoc2_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
390 ok(0, "unexpected call\n");
391 return E_NOTIMPL;
394 static HRESULT WINAPI htmldoc2_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
395 LCID lcid, ITypeInfo **ppTInfo)
397 ok(0, "unexpected call\n");
398 return E_NOTIMPL;
401 static HRESULT WINAPI htmldoc2_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
402 LPOLESTR *rgszNames, UINT cNames,
403 LCID lcid, DISPID *rgDispId)
405 ok(0, "unexpected call\n");
406 return E_NOTIMPL;
409 static HRESULT WINAPI htmldoc2_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
410 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
411 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
413 ok(0, "unexpected call\n");
414 return E_NOTIMPL;
417 static HRESULT WINAPI htmldoc2_get_Script(IHTMLDocument2 *iface, IDispatch **p)
419 ok(0, "unexpected call\n");
420 return E_NOTIMPL;
423 static HRESULT WINAPI htmldoc2_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
425 CHECK_EXPECT2(htmldoc2_get_all);
426 *p = &htmlecoll.IHTMLElementCollection_iface;
427 return S_OK;
430 static HRESULT WINAPI htmldoc2_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
432 ok(0, "unexpected call\n");
433 return E_NOTIMPL;
436 static HRESULT WINAPI htmldoc2_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
438 ok(0, "unexpected call\n");
439 return E_NOTIMPL;
442 static HRESULT WINAPI htmldoc2_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
444 ok(0, "unexpected call\n");
445 return E_NOTIMPL;
448 static HRESULT WINAPI htmldoc2_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
450 ok(0, "unexpected call\n");
451 return E_NOTIMPL;
454 static HRESULT WINAPI htmldoc2_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
456 ok(0, "unexpected call\n");
457 return E_NOTIMPL;
460 static HRESULT WINAPI htmldoc2_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
462 ok(0, "unexpected call\n");
463 return E_NOTIMPL;
466 static HRESULT WINAPI htmldoc2_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
468 ok(0, "unexpected call\n");
469 return E_NOTIMPL;
472 static HRESULT WINAPI htmldoc2_put_title(IHTMLDocument2 *iface, BSTR v)
474 ok(0, "unexpected call\n");
475 return E_NOTIMPL;
478 static HRESULT WINAPI htmldoc2_get_title(IHTMLDocument2 *iface, BSTR *p)
480 ok(0, "unexpected call\n");
481 return E_NOTIMPL;
484 static HRESULT WINAPI htmldoc2_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
486 ok(0, "unexpected call\n");
487 return E_NOTIMPL;
490 static HRESULT WINAPI htmldoc2_put_designMode(IHTMLDocument2 *iface, BSTR v)
492 ok(0, "unexpected call\n");
493 return E_NOTIMPL;
496 static HRESULT WINAPI htmldoc2_get_designMode(IHTMLDocument2 *iface, BSTR *p)
498 ok(0, "unexpected call\n");
499 return E_NOTIMPL;
502 static HRESULT WINAPI htmldoc2_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
504 ok(0, "unexpected call\n");
505 return E_NOTIMPL;
508 static HRESULT WINAPI htmldoc2_get_readyState(IHTMLDocument2 *iface, BSTR *p)
510 ok(0, "unexpected call\n");
511 return E_NOTIMPL;
514 static HRESULT WINAPI htmldoc2_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
516 ok(0, "unexpected call\n");
517 return E_NOTIMPL;
520 static HRESULT WINAPI htmldoc2_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
522 ok(0, "unexpected call\n");
523 return E_NOTIMPL;
526 static HRESULT WINAPI htmldoc2_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
528 ok(0, "unexpected call\n");
529 return E_NOTIMPL;
532 static HRESULT WINAPI htmldoc2_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
534 ok(0, "unexpected call\n");
535 return E_NOTIMPL;
538 static HRESULT WINAPI htmldoc2_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
540 ok(0, "unexpected call\n");
541 return E_NOTIMPL;
544 static HRESULT WINAPI htmldoc2_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
546 ok(0, "unexpected call\n");
547 return E_NOTIMPL;
550 static HRESULT WINAPI htmldoc2_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
552 ok(0, "unexpected call\n");
553 return E_NOTIMPL;
556 static HRESULT WINAPI htmldoc2_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
558 ok(0, "unexpected call\n");
559 return E_NOTIMPL;
562 static HRESULT WINAPI htmldoc2_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
564 ok(0, "unexpected call\n");
565 return E_NOTIMPL;
568 static HRESULT WINAPI htmldoc2_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
570 ok(0, "unexpected call\n");
571 return E_NOTIMPL;
574 static HRESULT WINAPI htmldoc2_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
576 ok(0, "unexpected call\n");
577 return E_NOTIMPL;
580 static HRESULT WINAPI htmldoc2_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
582 ok(0, "unexpected call\n");
583 return E_NOTIMPL;
586 static HRESULT WINAPI htmldoc2_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
588 ok(0, "unexpected call\n");
589 return E_NOTIMPL;
592 static HRESULT WINAPI htmldoc2_get_referrer(IHTMLDocument2 *iface, BSTR *p)
594 ok(0, "unexpected call\n");
595 return E_NOTIMPL;
598 static HRESULT WINAPI htmldoc2_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
600 ok(0, "unexpected call\n");
601 return E_NOTIMPL;
604 static HRESULT WINAPI htmldoc2_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
606 ok(0, "unexpected call\n");
607 return E_NOTIMPL;
610 static HRESULT WINAPI htmldoc2_put_URL(IHTMLDocument2 *iface, BSTR v)
612 ok(0, "unexpected call\n");
613 return E_NOTIMPL;
616 static HRESULT WINAPI htmldoc2_get_URL(IHTMLDocument2 *iface, BSTR *p)
618 CHECK_EXPECT2(htmldoc2_get_url);
619 *p = SysAllocString(NULL);
620 return S_OK;
623 static HRESULT WINAPI htmldoc2_put_domain(IHTMLDocument2 *iface, BSTR v)
625 ok(0, "unexpected call\n");
626 return E_NOTIMPL;
629 static HRESULT WINAPI htmldoc2_get_domain(IHTMLDocument2 *iface, BSTR *p)
631 ok(0, "unexpected call\n");
632 return E_NOTIMPL;
635 static HRESULT WINAPI htmldoc2_put_cookie(IHTMLDocument2 *iface, BSTR v)
637 ok(0, "unexpected call\n");
638 return E_NOTIMPL;
641 static HRESULT WINAPI htmldoc2_get_cookie(IHTMLDocument2 *iface, BSTR *p)
643 ok(0, "unexpected call\n");
644 return E_NOTIMPL;
647 static HRESULT WINAPI htmldoc2_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
649 ok(0, "unexpected call\n");
650 return E_NOTIMPL;
653 static HRESULT WINAPI htmldoc2_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
655 ok(0, "unexpected call\n");
656 return E_NOTIMPL;
659 static HRESULT WINAPI htmldoc2_put_charset(IHTMLDocument2 *iface, BSTR v)
661 ok(0, "unexpected call\n");
662 return E_NOTIMPL;
665 static HRESULT WINAPI htmldoc2_get_charset(IHTMLDocument2 *iface, BSTR *p)
667 ok(0, "unexpected call\n");
668 return E_NOTIMPL;
671 static HRESULT WINAPI htmldoc2_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
673 ok(0, "unexpected call\n");
674 return E_NOTIMPL;
677 static HRESULT WINAPI htmldoc2_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
679 ok(0, "unexpected call\n");
680 return E_NOTIMPL;
683 static HRESULT WINAPI htmldoc2_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
685 ok(0, "unexpected call\n");
686 return E_NOTIMPL;
689 static HRESULT WINAPI htmldoc2_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
691 ok(0, "unexpected call\n");
692 return E_NOTIMPL;
695 static HRESULT WINAPI htmldoc2_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
697 ok(0, "unexpected call\n");
698 return E_NOTIMPL;
701 static HRESULT WINAPI htmldoc2_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
703 ok(0, "unexpected call\n");
704 return E_NOTIMPL;
707 static HRESULT WINAPI htmldoc2_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
709 ok(0, "unexpected call\n");
710 return E_NOTIMPL;
713 static HRESULT WINAPI htmldoc2_get_security(IHTMLDocument2 *iface, BSTR *p)
715 ok(0, "unexpected call\n");
716 return E_NOTIMPL;
719 static HRESULT WINAPI htmldoc2_get_protocol(IHTMLDocument2 *iface, BSTR *p)
721 ok(0, "unexpected call\n");
722 return E_NOTIMPL;
725 static HRESULT WINAPI htmldoc2_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
727 ok(0, "unexpected call\n");
728 return E_NOTIMPL;
731 static HRESULT WINAPI htmldoc2_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
733 ok(0, "unexpected call\n");
734 return E_NOTIMPL;
737 static HRESULT WINAPI htmldoc2_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
739 ok(0, "unexpected call\n");
740 return E_NOTIMPL;
743 static HRESULT WINAPI htmldoc2_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
744 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
746 ok(0, "unexpected call\n");
747 return E_NOTIMPL;
750 static HRESULT WINAPI htmldoc2_close(IHTMLDocument2 *iface)
752 ok(0, "unexpected call\n");
753 return E_NOTIMPL;
756 static HRESULT WINAPI htmldoc2_clear(IHTMLDocument2 *iface)
758 ok(0, "unexpected call\n");
759 return E_NOTIMPL;
762 static HRESULT WINAPI htmldoc2_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
763 VARIANT_BOOL *pfRet)
765 ok(0, "unexpected call\n");
766 return E_NOTIMPL;
769 static HRESULT WINAPI htmldoc2_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
770 VARIANT_BOOL *pfRet)
772 ok(0, "unexpected call\n");
773 return E_NOTIMPL;
776 static HRESULT WINAPI htmldoc2_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
777 VARIANT_BOOL *pfRet)
779 ok(0, "unexpected call\n");
780 return E_NOTIMPL;
783 static HRESULT WINAPI htmldoc2_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
784 VARIANT_BOOL *pfRet)
786 ok(0, "unexpected call\n");
787 return E_NOTIMPL;
790 static HRESULT WINAPI htmldoc2_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
791 BSTR *pfRet)
793 ok(0, "unexpected call\n");
794 return E_NOTIMPL;
797 static HRESULT WINAPI htmldoc2_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
798 VARIANT *pfRet)
800 ok(0, "unexpected call\n");
801 return E_NOTIMPL;
804 static HRESULT WINAPI htmldoc2_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
805 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
807 ok(0, "unexpected call\n");
808 return E_NOTIMPL;
811 static HRESULT WINAPI htmldoc2_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
812 VARIANT_BOOL *pfRet)
814 ok(0, "unexpected call\n");
815 return E_NOTIMPL;
818 static HRESULT WINAPI htmldoc2_createElement(IHTMLDocument2 *iface, BSTR eTag,
819 IHTMLElement **newElem)
821 ok(0, "unexpected call\n");
822 return E_NOTIMPL;
825 static HRESULT WINAPI htmldoc2_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
827 ok(0, "unexpected call\n");
828 return E_NOTIMPL;
831 static HRESULT WINAPI htmldoc2_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
833 ok(0, "unexpected call\n");
834 return E_NOTIMPL;
837 static HRESULT WINAPI htmldoc2_put_onclick(IHTMLDocument2 *iface, VARIANT v)
839 ok(0, "unexpected call\n");
840 return E_NOTIMPL;
843 static HRESULT WINAPI htmldoc2_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
845 ok(0, "unexpected call\n");
846 return E_NOTIMPL;
849 static HRESULT WINAPI htmldoc2_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
851 ok(0, "unexpected call\n");
852 return E_NOTIMPL;
855 static HRESULT WINAPI htmldoc2_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
857 ok(0, "unexpected call\n");
858 return E_NOTIMPL;
861 static HRESULT WINAPI htmldoc2_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
863 ok(0, "unexpected call\n");
864 return E_NOTIMPL;
867 static HRESULT WINAPI htmldoc2_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
869 ok(0, "unexpected call\n");
870 return E_NOTIMPL;
873 static HRESULT WINAPI htmldoc2_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
875 ok(0, "unexpected call\n");
876 return E_NOTIMPL;
879 static HRESULT WINAPI htmldoc2_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
881 ok(0, "unexpected call\n");
882 return E_NOTIMPL;
885 static HRESULT WINAPI htmldoc2_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
887 ok(0, "unexpected call\n");
888 return E_NOTIMPL;
891 static HRESULT WINAPI htmldoc2_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
893 ok(0, "unexpected call\n");
894 return E_NOTIMPL;
897 static HRESULT WINAPI htmldoc2_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
899 ok(0, "unexpected call\n");
900 return E_NOTIMPL;
903 static HRESULT WINAPI htmldoc2_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
905 ok(0, "unexpected call\n");
906 return E_NOTIMPL;
909 static HRESULT WINAPI htmldoc2_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
911 ok(0, "unexpected call\n");
912 return E_NOTIMPL;
915 static HRESULT WINAPI htmldoc2_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
917 ok(0, "unexpected call\n");
918 return E_NOTIMPL;
921 static HRESULT WINAPI htmldoc2_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
923 ok(0, "unexpected call\n");
924 return E_NOTIMPL;
927 static HRESULT WINAPI htmldoc2_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
929 ok(0, "unexpected call\n");
930 return E_NOTIMPL;
933 static HRESULT WINAPI htmldoc2_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
935 ok(0, "unexpected call\n");
936 return E_NOTIMPL;
939 static HRESULT WINAPI htmldoc2_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
941 ok(0, "unexpected call\n");
942 return E_NOTIMPL;
945 static HRESULT WINAPI htmldoc2_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
947 ok(0, "unexpected call\n");
948 return E_NOTIMPL;
951 static HRESULT WINAPI htmldoc2_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
953 ok(0, "unexpected call\n");
954 return E_NOTIMPL;
957 static HRESULT WINAPI htmldoc2_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
959 ok(0, "unexpected call\n");
960 return E_NOTIMPL;
963 static HRESULT WINAPI htmldoc2_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
965 ok(0, "unexpected call\n");
966 return E_NOTIMPL;
969 static HRESULT WINAPI htmldoc2_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
971 ok(0, "unexpected call\n");
972 return E_NOTIMPL;
975 static HRESULT WINAPI htmldoc2_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
977 ok(0, "unexpected call\n");
978 return E_NOTIMPL;
981 static HRESULT WINAPI htmldoc2_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
983 ok(0, "unexpected call\n");
984 return E_NOTIMPL;
987 static HRESULT WINAPI htmldoc2_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
989 ok(0, "unexpected call\n");
990 return E_NOTIMPL;
993 static HRESULT WINAPI htmldoc2_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
995 ok(0, "unexpected call\n");
996 return E_NOTIMPL;
999 static HRESULT WINAPI htmldoc2_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1001 ok(0, "unexpected call\n");
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI htmldoc2_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1007 ok(0, "unexpected call\n");
1008 return E_NOTIMPL;
1011 static HRESULT WINAPI htmldoc2_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1013 ok(0, "unexpected call\n");
1014 return E_NOTIMPL;
1017 static HRESULT WINAPI htmldoc2_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1019 ok(0, "unexpected call\n");
1020 return E_NOTIMPL;
1023 static HRESULT WINAPI htmldoc2_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1025 ok(0, "unexpected call\n");
1026 return E_NOTIMPL;
1029 static HRESULT WINAPI htmldoc2_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1030 IHTMLElement **elementHit)
1032 ok(0, "unexpected call\n");
1033 return E_NOTIMPL;
1036 static HRESULT WINAPI htmldoc2_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1038 ok(0, "unexpected call\n");
1039 return E_NOTIMPL;
1042 static HRESULT WINAPI htmldoc2_get_styleSheets(IHTMLDocument2 *iface,
1043 IHTMLStyleSheetsCollection **p)
1045 ok(0, "unexpected call\n");
1046 return E_NOTIMPL;
1049 static HRESULT WINAPI htmldoc2_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1051 ok(0, "unexpected call\n");
1052 return E_NOTIMPL;
1055 static HRESULT WINAPI htmldoc2_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1057 ok(0, "unexpected call\n");
1058 return E_NOTIMPL;
1061 static HRESULT WINAPI htmldoc2_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1063 ok(0, "unexpected call\n");
1064 return E_NOTIMPL;
1067 static HRESULT WINAPI htmldoc2_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1069 ok(0, "unexpected call\n");
1070 return E_NOTIMPL;
1073 static HRESULT WINAPI htmldoc2_toString(IHTMLDocument2 *iface, BSTR *String)
1075 ok(0, "unexpected call\n");
1076 return E_NOTIMPL;
1079 static HRESULT WINAPI htmldoc2_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1080 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1082 ok(0, "unexpected call\n");
1083 return E_NOTIMPL;
1086 static const IHTMLDocument2Vtbl TestHTMLDocumentVtbl = {
1087 htmldoc2_QueryInterface,
1088 htmldoc2_AddRef,
1089 htmldoc2_Release,
1090 htmldoc2_GetTypeInfoCount,
1091 htmldoc2_GetTypeInfo,
1092 htmldoc2_GetIDsOfNames,
1093 htmldoc2_Invoke,
1094 htmldoc2_get_Script,
1095 htmldoc2_get_all,
1096 htmldoc2_get_body,
1097 htmldoc2_get_activeElement,
1098 htmldoc2_get_images,
1099 htmldoc2_get_applets,
1100 htmldoc2_get_links,
1101 htmldoc2_get_forms,
1102 htmldoc2_get_anchors,
1103 htmldoc2_put_title,
1104 htmldoc2_get_title,
1105 htmldoc2_get_scripts,
1106 htmldoc2_put_designMode,
1107 htmldoc2_get_designMode,
1108 htmldoc2_get_selection,
1109 htmldoc2_get_readyState,
1110 htmldoc2_get_frames,
1111 htmldoc2_get_embeds,
1112 htmldoc2_get_plugins,
1113 htmldoc2_put_alinkColor,
1114 htmldoc2_get_alinkColor,
1115 htmldoc2_put_bgColor,
1116 htmldoc2_get_bgColor,
1117 htmldoc2_put_fgColor,
1118 htmldoc2_get_fgColor,
1119 htmldoc2_put_linkColor,
1120 htmldoc2_get_linkColor,
1121 htmldoc2_put_vlinkColor,
1122 htmldoc2_get_vlinkColor,
1123 htmldoc2_get_referrer,
1124 htmldoc2_get_location,
1125 htmldoc2_get_lastModified,
1126 htmldoc2_put_URL,
1127 htmldoc2_get_URL,
1128 htmldoc2_put_domain,
1129 htmldoc2_get_domain,
1130 htmldoc2_put_cookie,
1131 htmldoc2_get_cookie,
1132 htmldoc2_put_expando,
1133 htmldoc2_get_expando,
1134 htmldoc2_put_charset,
1135 htmldoc2_get_charset,
1136 htmldoc2_put_defaultCharset,
1137 htmldoc2_get_defaultCharset,
1138 htmldoc2_get_mimeType,
1139 htmldoc2_get_fileSize,
1140 htmldoc2_get_fileCreatedDate,
1141 htmldoc2_get_fileModifiedDate,
1142 htmldoc2_get_fileUpdatedDate,
1143 htmldoc2_get_security,
1144 htmldoc2_get_protocol,
1145 htmldoc2_get_nameProp,
1146 htmldoc2_write,
1147 htmldoc2_writeln,
1148 htmldoc2_open,
1149 htmldoc2_close,
1150 htmldoc2_clear,
1151 htmldoc2_queryCommandSupported,
1152 htmldoc2_queryCommandEnabled,
1153 htmldoc2_queryCommandState,
1154 htmldoc2_queryCommandIndeterm,
1155 htmldoc2_queryCommandText,
1156 htmldoc2_queryCommandValue,
1157 htmldoc2_execCommand,
1158 htmldoc2_execCommandShowHelp,
1159 htmldoc2_createElement,
1160 htmldoc2_put_onhelp,
1161 htmldoc2_get_onhelp,
1162 htmldoc2_put_onclick,
1163 htmldoc2_get_onclick,
1164 htmldoc2_put_ondblclick,
1165 htmldoc2_get_ondblclick,
1166 htmldoc2_put_onkeyup,
1167 htmldoc2_get_onkeyup,
1168 htmldoc2_put_onkeydown,
1169 htmldoc2_get_onkeydown,
1170 htmldoc2_put_onkeypress,
1171 htmldoc2_get_onkeypress,
1172 htmldoc2_put_onmouseup,
1173 htmldoc2_get_onmouseup,
1174 htmldoc2_put_onmousedown,
1175 htmldoc2_get_onmousedown,
1176 htmldoc2_put_onmousemove,
1177 htmldoc2_get_onmousemove,
1178 htmldoc2_put_onmouseout,
1179 htmldoc2_get_onmouseout,
1180 htmldoc2_put_onmouseover,
1181 htmldoc2_get_onmouseover,
1182 htmldoc2_put_onreadystatechange,
1183 htmldoc2_get_onreadystatechange,
1184 htmldoc2_put_onafterupdate,
1185 htmldoc2_get_onafterupdate,
1186 htmldoc2_put_onrowexit,
1187 htmldoc2_get_onrowexit,
1188 htmldoc2_put_onrowenter,
1189 htmldoc2_get_onrowenter,
1190 htmldoc2_put_ondragstart,
1191 htmldoc2_get_ondragstart,
1192 htmldoc2_put_onselectstart,
1193 htmldoc2_get_onselectstart,
1194 htmldoc2_elementFromPoint,
1195 htmldoc2_get_parentWindow,
1196 htmldoc2_get_styleSheets,
1197 htmldoc2_put_onbeforeupdate,
1198 htmldoc2_get_onbeforeupdate,
1199 htmldoc2_put_onerrorupdate,
1200 htmldoc2_get_onerrorupdate,
1201 htmldoc2_toString,
1202 htmldoc2_createStyleSheet
1205 typedef struct
1207 IHTMLDocument2 IHTMLDocument2_iface;
1208 } testhtmldoc2_t;
1210 static testhtmldoc2_t htmldoc2 = { { &TestHTMLDocumentVtbl } };
1212 static HRESULT WINAPI sp_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppvObject)
1214 *ppvObject = NULL;
1216 if (IsEqualGUID(riid, &IID_IUnknown) ||
1217 IsEqualGUID(riid, &IID_IServiceProvider))
1219 *ppvObject = iface;
1220 IServiceProvider_AddRef(iface);
1221 return S_OK;
1224 ok(0, "unexpected query interface: %s\n", debugstr_guid(riid));
1226 return E_NOINTERFACE;
1229 static ULONG WINAPI sp_AddRef(IServiceProvider *iface)
1231 return 2;
1234 static ULONG WINAPI sp_Release(IServiceProvider *iface)
1236 return 1;
1239 static HRESULT WINAPI sp_QueryService(IServiceProvider *iface, REFGUID service, REFIID riid, void **obj)
1241 *obj = NULL;
1243 if (IsEqualGUID(service, &SID_SBindHost) &&
1244 IsEqualGUID(riid, &IID_IBindHost))
1246 CHECK_EXPECT2(sp_queryservice_SID_SBindHost);
1248 else if (IsEqualGUID(service, &SID_SContainerDispatch) &&
1249 IsEqualGUID(riid, &IID_IHTMLDocument2))
1251 CHECK_EXPECT2(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1253 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1254 IsEqualGUID(riid, &IID_IHTMLDocument2))
1256 CHECK_EXPECT2(sp_queryservice_SID_secmgr_htmldoc2);
1257 *obj = &htmldoc2.IHTMLDocument2_iface;
1258 return S_OK;
1260 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1261 IsEqualGUID(riid, &IID_IXMLDOMDocument))
1263 CHECK_EXPECT2(sp_queryservice_SID_secmgr_xmldomdoc);
1265 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1266 IsEqualGUID(riid, &IID_IInternetHostSecurityManager))
1268 CHECK_EXPECT2(sp_queryservice_SID_secmgr_secmgr);
1270 else if (IsEqualGUID(service, &SID_UnknownSID) &&
1271 IsEqualGUID(riid, &IID_IStream))
1273 /* FIXME: unidentified service id */
1275 else
1276 ok(0, "unexpected request: sid %s, riid %s\n", debugstr_guid(service), debugstr_guid(riid));
1278 return E_NOTIMPL;
1281 static const IServiceProviderVtbl testprovVtbl =
1283 sp_QueryInterface,
1284 sp_AddRef,
1285 sp_Release,
1286 sp_QueryService
1289 testprov_t testprov = { { &testprovVtbl } };
1291 /* IStream */
1292 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
1294 *ppvObject = NULL;
1296 if (IsEqualGUID(riid, &IID_IStream) ||
1297 IsEqualGUID(riid, &IID_IUnknown))
1298 *ppvObject = iface;
1299 else
1300 return E_NOINTERFACE;
1302 return S_OK;
1305 static ULONG WINAPI istream_AddRef(IStream *iface)
1307 return 2;
1310 static ULONG WINAPI istream_Release(IStream *iface)
1312 return 1;
1315 static HRESULT WINAPI istream_Read(IStream *iface, void *ptr, ULONG len, ULONG *pread)
1317 ok(0, "unexpected call\n");
1318 return E_NOTIMPL;
1321 static HRESULT WINAPI istream_Write(IStream *iface, const void *ptr, ULONG len, ULONG *written)
1323 *written = len/2;
1324 return S_OK;
1327 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER move, DWORD origin, ULARGE_INTEGER *new_pos)
1329 ok(0, "unexpected call\n");
1330 return E_NOTIMPL;
1333 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER size)
1335 ok(0, "unexpected call\n");
1336 return E_NOTIMPL;
1339 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *stream, ULARGE_INTEGER len,
1340 ULARGE_INTEGER *pread, ULARGE_INTEGER *written)
1342 ok(0, "unexpected call\n");
1343 return E_NOTIMPL;
1346 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD flags)
1348 ok(0, "unexpected call\n");
1349 return E_NOTIMPL;
1352 static HRESULT WINAPI istream_Revert(IStream *iface)
1354 ok(0, "unexpected call\n");
1355 return E_NOTIMPL;
1358 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER offset,
1359 ULARGE_INTEGER len, DWORD locktype)
1361 ok(0, "unexpected call\n");
1362 return E_NOTIMPL;
1365 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER offset,
1366 ULARGE_INTEGER len, DWORD locktype)
1368 ok(0, "unexpected call\n");
1369 return E_NOTIMPL;
1372 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD flag)
1374 ok(0, "unexpected call\n");
1375 return E_NOTIMPL;
1378 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **stream)
1380 ok(0, "unexpected call\n");
1381 return E_NOTIMPL;
1384 static const IStreamVtbl StreamVtbl = {
1385 istream_QueryInterface,
1386 istream_AddRef,
1387 istream_Release,
1388 istream_Read,
1389 istream_Write,
1390 istream_Seek,
1391 istream_SetSize,
1392 istream_CopyTo,
1393 istream_Commit,
1394 istream_Revert,
1395 istream_LockRegion,
1396 istream_UnlockRegion,
1397 istream_Stat,
1398 istream_Clone
1401 static IStream savestream = { &StreamVtbl };
1403 #define EXPECT_CHILDREN(node) _expect_children((IXMLDOMNode*)node, __LINE__)
1404 static void _expect_children(IXMLDOMNode *node, int line)
1406 VARIANT_BOOL b;
1407 HRESULT hr;
1409 b = VARIANT_FALSE;
1410 hr = IXMLDOMNode_hasChildNodes(node, &b);
1411 ok_(__FILE__,line)(hr == S_OK, "hasChildNodes() failed, 0x%08x\n", hr);
1412 ok_(__FILE__,line)(b == VARIANT_TRUE, "no children, %d\n", b);
1415 #define EXPECT_NO_CHILDREN(node) _expect_no_children((IXMLDOMNode*)node, __LINE__)
1416 static void _expect_no_children(IXMLDOMNode *node, int line)
1418 VARIANT_BOOL b;
1419 HRESULT hr;
1421 b = VARIANT_TRUE;
1422 hr = IXMLDOMNode_hasChildNodes(node, &b);
1423 ok_(__FILE__,line)(hr == S_FALSE, "hasChildNodes() failed, 0x%08x\n", hr);
1424 ok_(__FILE__,line)(b == VARIANT_FALSE, "no children, %d\n", b);
1427 #define EXPECT_REF(node,ref) _expect_ref((IUnknown*)node, ref, __LINE__)
1428 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
1430 ULONG rc = IUnknown_AddRef(obj);
1431 IUnknown_Release(obj);
1432 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
1435 #define EXPECT_LIST_LEN(list,len) _expect_list_len(list, len, __LINE__)
1436 static void _expect_list_len(IXMLDOMNodeList *list, LONG len, int line)
1438 LONG length;
1439 HRESULT hr;
1441 length = 0;
1442 hr = IXMLDOMNodeList_get_length(list, &length);
1443 ok_(__FILE__,line)(hr == S_OK, "got 0x%08x\n", hr);
1444 ok_(__FILE__,line)(length == len, "got %d, expected %d\n", length, len);
1447 #define EXPECT_HR(hr,hr_exp) \
1448 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
1450 static const WCHAR szEmpty[] = { 0 };
1451 static const WCHAR szIncomplete[] = {
1452 '<','?','x','m','l',' ',
1453 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
1455 static const WCHAR szComplete1[] = {
1456 '<','?','x','m','l',' ',
1457 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1458 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
1460 static const WCHAR szComplete2[] = {
1461 '<','?','x','m','l',' ',
1462 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1463 '<','o','>','<','/','o','>','\n',0
1465 static const WCHAR szComplete3[] = {
1466 '<','?','x','m','l',' ',
1467 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1468 '<','a','>','<','/','a','>','\n',0
1470 static const char complete4A[] =
1471 "<?xml version=\'1.0\'?>\n"
1472 "<lc dl=\'str1\'>\n"
1473 "<bs vr=\'str2\' sz=\'1234\'>"
1474 "fn1.txt\n"
1475 "</bs>\n"
1476 "<pr id=\'str3\' vr=\'1.2.3\' pn=\'wine 20050804\'>\n"
1477 "fn2.txt\n"
1478 "</pr>\n"
1479 "<empty></empty>\n"
1480 "<fo>\n"
1481 "<ba>\n"
1482 "f1\n"
1483 "</ba>\n"
1484 "</fo>\n"
1485 "</lc>\n";
1487 static const WCHAR szComplete5[] = {
1488 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
1489 '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','"',
1490 ' ','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','"','>',
1491 '<','S',':','s','c','o','p','e','>',
1492 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
1493 '<','/','S',':','s','c','o','p','e','>',
1494 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
1495 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
1496 'c','o','m','p','u','t','e','r',
1497 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
1498 '<','/','S',':','s','e','a','r','c','h','>',0
1501 static const WCHAR szComplete6[] = {
1502 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'',' ',
1503 'e','n','c','o','d','i','n','g','=','\'','W','i','n','d','o','w','s','-','1','2','5','2','\'','?','>','\n',
1504 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
1507 #define DECL_WIN_1252 \
1508 "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
1510 static const char win1252xml[] =
1511 DECL_WIN_1252
1512 "<open></open>";
1514 static const char win1252decl[] =
1515 DECL_WIN_1252
1518 static const char szExampleXML[] =
1519 "<?xml version='1.0' encoding='utf-8'?>\n"
1520 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' a=\"attr a\" foo:b=\"attr b\" >\n"
1521 " <elem>\n"
1522 " <a>A1 field</a>\n"
1523 " <b>B1 field</b>\n"
1524 " <c>C1 field</c>\n"
1525 " <d>D1 field</d>\n"
1526 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1527 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
1528 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
1529 " </html>\n"
1530 " <html xml:space='preserve' xmlns='http://www.w3.org/1999/xhtml'>\n"
1531 " This is <strong>a</strong> <i>description</i> with preserved whitespace. <bar:x/>\n"
1532 " </html>\n"
1533 " </description>\n"
1534 " </elem>\n"
1535 "\n"
1536 " <elem>\n"
1537 " <a>A2 field</a>\n"
1538 " <b>B2 field</b>\n"
1539 " <c type=\"old\">C2 field</c>\n"
1540 " <d>D2 field</d>\n"
1541 " </elem>\n"
1542 "\n"
1543 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1544 " <a>A3 field</a>\n"
1545 " <b>B3 field</b>\n"
1546 " <c>C3 field</c>\n"
1547 " </elem>\n"
1548 "\n"
1549 " <elem>\n"
1550 " <a>A4 field</a>\n"
1551 " <b>B4 field</b>\n"
1552 " <foo:c>C4 field</foo:c>\n"
1553 " <d>D4 field</d>\n"
1554 " </elem>\n"
1555 "</root>\n";
1557 static const CHAR szNodeTypesXML[] =
1558 "<?xml version='1.0'?>"
1559 "<!-- comment node 0 -->"
1560 "<root id='0' depth='0'>"
1561 " <!-- comment node 1 -->"
1562 " text node 0"
1563 " <x id='1' depth='1'>"
1564 " <?foo value='PI for x'?>"
1565 " <!-- comment node 2 -->"
1566 " text node 1"
1567 " <a id='3' depth='2'/>"
1568 " <b id='4' depth='2'/>"
1569 " <c id='5' depth='2'/>"
1570 " </x>"
1571 " <y id='2' depth='1'>"
1572 " <?bar value='PI for y'?>"
1573 " <!-- comment node 3 -->"
1574 " text node 2"
1575 " <a id='6' depth='2'/>"
1576 " <b id='7' depth='2'/>"
1577 " <c id='8' depth='2'/>"
1578 " </y>"
1579 "</root>";
1581 static const CHAR szTransformXML[] =
1582 "<?xml version=\"1.0\"?>\n"
1583 "<greeting>\n"
1584 "Hello World\n"
1585 "</greeting>";
1587 static const CHAR szTransformSSXML[] =
1588 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
1589 " <xsl:output method=\"html\"/>\n"
1590 " <xsl:template match=\"/\">\n"
1591 " <xsl:apply-templates select=\"greeting\"/>\n"
1592 " </xsl:template>\n"
1593 " <xsl:template match=\"greeting\">\n"
1594 " <html>\n"
1595 " <body>\n"
1596 " <h1>\n"
1597 " <xsl:value-of select=\".\"/>\n"
1598 " </h1>\n"
1599 " </body>\n"
1600 " </html>\n"
1601 " </xsl:template>\n"
1602 "</xsl:stylesheet>";
1604 static const CHAR szTransformOutput[] =
1605 "<html><body><h1>"
1606 "Hello World"
1607 "</h1></body></html>";
1609 static const CHAR szTypeValueXML[] =
1610 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1611 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
1612 " <string>Wine</string>\n"
1613 " <string2 dt:dt=\"string\">String</string2>\n"
1614 " <number dt:dt=\"number\">12.44</number>\n"
1615 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
1616 " <int dt:dt=\"int\">-13</int>\n"
1617 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
1618 " <bool dt:dt=\"boolean\">1</bool>\n"
1619 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
1620 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
1621 " <date dt:dt=\"date\">3721-11-01</date>\n"
1622 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
1623 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
1624 " <i1 dt:dt=\"i1\">-13</i1>\n"
1625 " <i2 dt:dt=\"i2\">31915</i2>\n"
1626 " <i4 dt:dt=\"i4\">-312232</i4>\n"
1627 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
1628 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
1629 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
1630 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
1631 " <r8 dt:dt=\"r8\">0.412</r8>\n"
1632 " <float dt:dt=\"float\">41221.421</float>\n"
1633 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
1634 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
1635 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
1636 " <binbase64_1 dt:dt=\"bin.base64\">\nYmFzZTY0\nIHRlc3Q=\n</binbase64_1>\n"
1637 " <binbase64_2 dt:dt=\"bin.base64\">\nYmF\r\t z ZTY0\nIHRlc3Q=\n</binbase64_2>\n"
1638 "</root>";
1640 static const CHAR szBasicTransformSSXMLPart1[] =
1641 "<?xml version=\"1.0\"?>"
1642 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
1643 "<xsl:output method=\"html\"/>\n"
1644 "<xsl:template match=\"/\">"
1645 "<HTML><BODY><TABLE>"
1646 " <xsl:apply-templates select='document(\"";
1648 static const CHAR szBasicTransformSSXMLPart2[] =
1649 "\")/bottle/wine'>"
1650 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
1651 " </xsl:apply-templates>"
1652 "</TABLE></BODY></HTML>"
1653 "</xsl:template>"
1654 "<xsl:template match=\"bottle\">"
1655 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
1656 "</xsl:template>"
1657 "<xsl:template match=\"name\">"
1658 " <TD><xsl:apply-templates /></TD>"
1659 "</xsl:template>"
1660 "<xsl:template match=\"cost\">"
1661 " <TD><xsl:apply-templates /></TD>"
1662 "</xsl:template>"
1663 "</xsl:stylesheet>";
1665 static const CHAR szBasicTransformXML[] =
1666 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
1668 static const CHAR szBasicTransformOutput[] =
1669 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
1671 #define SZ_EMAIL_DTD \
1672 "<!DOCTYPE email ["\
1673 " <!ELEMENT email (recipients,from,reply-to?,subject,body,attachment*)>"\
1674 " <!ATTLIST email attachments IDREFS #REQUIRED>"\
1675 " <!ATTLIST email sent (yes|no) \"no\">"\
1676 " <!ELEMENT recipients (to+,cc*)>"\
1677 " <!ELEMENT to (#PCDATA)>"\
1678 " <!ATTLIST to name CDATA #IMPLIED>"\
1679 " <!ELEMENT cc (#PCDATA)>"\
1680 " <!ATTLIST cc name CDATA #IMPLIED>"\
1681 " <!ELEMENT from (#PCDATA)>"\
1682 " <!ATTLIST from name CDATA #IMPLIED>"\
1683 " <!ELEMENT reply-to (#PCDATA)>"\
1684 " <!ATTLIST reply-to name CDATA #IMPLIED>"\
1685 " <!ELEMENT subject ANY>"\
1686 " <!ELEMENT body ANY>"\
1687 " <!ATTLIST body enc CDATA #FIXED \"UTF-8\">"\
1688 " <!ELEMENT attachment (#PCDATA)>"\
1689 " <!ATTLIST attachment id ID #REQUIRED>"\
1690 "]>"
1692 static const CHAR szEmailXML[] =
1693 "<?xml version=\"1.0\"?>"
1694 SZ_EMAIL_DTD
1695 "<email attachments=\"patch1\">"
1696 " <recipients>"
1697 " <to>wine-patches@winehq.org</to>"
1698 " </recipients>"
1699 " <from name=\"Anonymous\">user@localhost</from>"
1700 " <subject>msxml3/tests: DTD validation (try 87)</subject>"
1701 " <body>"
1702 " It no longer causes spontaneous combustion..."
1703 " </body>"
1704 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1705 "</email>";
1707 static const CHAR szEmailXML_0D[] =
1708 "<?xml version=\"1.0\"?>"
1709 SZ_EMAIL_DTD
1710 "<email attachments=\"patch1\">"
1711 " <recipients>"
1712 " <to>wine-patches@winehq.org</to>"
1713 " </recipients>"
1714 " <from name=\"Anonymous\">user@localhost</from>"
1715 " <subject>msxml3/tests: DTD validation (try 88)</subject>"
1716 " <body>"
1717 " <undecl />"
1718 " XML_ELEMENT_UNDECLARED 0xC00CE00D"
1719 " </body>"
1720 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1721 "</email>";
1723 static const CHAR szEmailXML_0E[] =
1724 "<?xml version=\"1.0\"?>"
1725 SZ_EMAIL_DTD
1726 "<email attachments=\"patch1\">"
1727 " <recipients>"
1728 " <to>wine-patches@winehq.org</to>"
1729 " </recipients>"
1730 " <from name=\"Anonymous\">user@localhost</from>"
1731 " <subject>msxml3/tests: DTD validation (try 89)</subject>"
1732 " <body>"
1733 " XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E"
1734 " </body>"
1735 " <attachment id=\"patch\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1736 "</email>";
1738 static const CHAR szEmailXML_11[] =
1739 "<?xml version=\"1.0\"?>"
1740 SZ_EMAIL_DTD
1741 "<email attachments=\"patch1\">"
1742 " <recipients>"
1743 " </recipients>"
1744 " <from name=\"Anonymous\">user@localhost</from>"
1745 " <subject>msxml3/tests: DTD validation (try 90)</subject>"
1746 " <body>"
1747 " XML_EMPTY_NOT_ALLOWED 0xC00CE011"
1748 " </body>"
1749 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1750 "</email>";
1752 static const CHAR szEmailXML_13[] =
1753 "<?xml version=\"1.0\"?>"
1754 SZ_EMAIL_DTD
1755 "<msg attachments=\"patch1\">"
1756 " <recipients>"
1757 " <to>wine-patches@winehq.org</to>"
1758 " </recipients>"
1759 " <from name=\"Anonymous\">user@localhost</from>"
1760 " <subject>msxml3/tests: DTD validation (try 91)</subject>"
1761 " <body>"
1762 " XML_ROOT_NAME_MISMATCH 0xC00CE013"
1763 " </body>"
1764 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1765 "</msg>";
1767 static const CHAR szEmailXML_14[] =
1768 "<?xml version=\"1.0\"?>"
1769 SZ_EMAIL_DTD
1770 "<email attachments=\"patch1\">"
1771 " <to>wine-patches@winehq.org</to>"
1772 " <from name=\"Anonymous\">user@localhost</from>"
1773 " <subject>msxml3/tests: DTD validation (try 92)</subject>"
1774 " <body>"
1775 " XML_INVALID_CONTENT 0xC00CE014"
1776 " </body>"
1777 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1778 "</email>";
1780 static const CHAR szEmailXML_15[] =
1781 "<?xml version=\"1.0\"?>"
1782 SZ_EMAIL_DTD
1783 "<email attachments=\"patch1\" ip=\"127.0.0.1\">"
1784 " <recipients>"
1785 " <to>wine-patches@winehq.org</to>"
1786 " </recipients>"
1787 " <from name=\"Anonymous\">user@localhost</from>"
1788 " <subject>msxml3/tests: DTD validation (try 93)</subject>"
1789 " <body>"
1790 " XML_ATTRIBUTE_NOT_DEFINED 0xC00CE015"
1791 " </body>"
1792 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1793 "</email>";
1795 static const CHAR szEmailXML_16[] =
1796 "<?xml version=\"1.0\"?>"
1797 SZ_EMAIL_DTD
1798 "<email attachments=\"patch1\">"
1799 " <recipients>"
1800 " <to>wine-patches@winehq.org</to>"
1801 " </recipients>"
1802 " <from name=\"Anonymous\">user@localhost</from>"
1803 " <subject>msxml3/tests: DTD validation (try 94)</subject>"
1804 " <body enc=\"ASCII\">"
1805 " XML_ATTRIBUTE_FIXED 0xC00CE016"
1806 " </body>"
1807 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1808 "</email>";
1810 static const CHAR szEmailXML_17[] =
1811 "<?xml version=\"1.0\"?>"
1812 SZ_EMAIL_DTD
1813 "<email attachments=\"patch1\" sent=\"true\">"
1814 " <recipients>"
1815 " <to>wine-patches@winehq.org</to>"
1816 " </recipients>"
1817 " <from name=\"Anonymous\">user@localhost</from>"
1818 " <subject>msxml3/tests: DTD validation (try 95)</subject>"
1819 " <body>"
1820 " XML_ATTRIBUTE_VALUE 0xC00CE017"
1821 " </body>"
1822 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1823 "</email>";
1825 static const CHAR szEmailXML_18[] =
1826 "<?xml version=\"1.0\"?>"
1827 SZ_EMAIL_DTD
1828 "<email attachments=\"patch1\">"
1829 " oops"
1830 " <recipients>"
1831 " <to>wine-patches@winehq.org</to>"
1832 " </recipients>"
1833 " <from name=\"Anonymous\">user@localhost</from>"
1834 " <subject>msxml3/tests: DTD validation (try 96)</subject>"
1835 " <body>"
1836 " XML_ILLEGAL_TEXT 0xC00CE018"
1837 " </body>"
1838 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1839 "</email>";
1841 static const CHAR szEmailXML_20[] =
1842 "<?xml version=\"1.0\"?>"
1843 SZ_EMAIL_DTD
1844 "<email>"
1845 " <recipients>"
1846 " <to>wine-patches@winehq.org</to>"
1847 " </recipients>"
1848 " <from name=\"Anonymous\">user@localhost</from>"
1849 " <subject>msxml3/tests: DTD validation (try 97)</subject>"
1850 " <body>"
1851 " XML_REQUIRED_ATTRIBUTE_MISSING 0xC00CE020"
1852 " </body>"
1853 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1854 "</email>";
1856 static const char xpath_simple_list[] =
1857 "<?xml version=\"1.0\"?>"
1858 "<root>"
1859 " <a attr1=\"1\" attr2=\"2\" />"
1860 " <b/>"
1861 " <c/>"
1862 " <d/>"
1863 "</root>";
1865 static const char default_ns_doc[] = {
1866 "<?xml version=\"1.0\"?>"
1867 "<a xmlns:ns=\"nshref\" xml:lang=\"ru\" ns:b=\"b attr\" xml:c=\"c attr\" "
1868 " d=\"d attr\" />"
1871 static const char attributes_map[] = {
1872 "<?xml version=\"1.0\"?>"
1873 "<a attr1=\"value1\" attr2=\"value2\" attr3=\"value3\" attr4=\"value4\" />"
1876 static const WCHAR nonexistent_fileW[] = {
1877 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
1879 static const WCHAR nonexistent_attrW[] = {
1880 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
1882 static const WCHAR szDocument[] = {
1883 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
1886 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
1887 static WCHAR szdl[] = { 'd','l',0 };
1888 static const WCHAR szvr[] = { 'v','r',0 };
1889 static const WCHAR szlc[] = { 'l','c',0 };
1890 static WCHAR szbs[] = { 'b','s',0 };
1891 static const WCHAR szstr1[] = { 's','t','r','1',0 };
1892 static const WCHAR szstr2[] = { 's','t','r','2',0 };
1893 static const WCHAR szstar[] = { '*',0 };
1894 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
1896 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
1897 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
1898 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
1900 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
1901 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
1902 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
1903 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
1904 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
1905 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
1906 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
1908 static WCHAR szAttribute[] = {'A','t','t','r',0 };
1909 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
1911 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
1912 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
1913 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
1914 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
1915 '!',']',']','>',0};
1916 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
1917 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
1919 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
1920 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
1921 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
1923 #define expect_bstr_eq_and_free(bstr, expect) { \
1924 BSTR bstrExp = alloc_str_from_narrow(expect); \
1925 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
1926 SysFreeString(bstr); \
1927 SysFreeString(bstrExp); \
1930 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
1932 #define ole_check(expr) { \
1933 HRESULT r = expr; \
1934 ok(r == S_OK, #expr " returned %x\n", r); \
1937 #define ole_expect(expr, expect) { \
1938 HRESULT r = expr; \
1939 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
1942 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
1944 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
1946 void *obj = NULL;
1947 HRESULT hr;
1949 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
1950 if (hr != S_OK)
1951 win_skip_(__FILE__,line)("failed to create %s instance: 0x%08x\n", name, hr);
1953 return obj;
1956 #define _create(cls) cls, #cls
1958 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument2), iid, __LINE__)
1959 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
1960 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
1961 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
1962 #define create_xsltemplate(iid) _create_object(&_create(CLSID_XSLTemplate), iid, __LINE__)
1964 static BSTR alloc_str_from_narrow(const char *str)
1966 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
1967 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
1968 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
1969 return ret;
1972 static BSTR alloced_bstrs[256];
1973 static int alloced_bstrs_count;
1975 static BSTR _bstr_(const char *str)
1977 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
1978 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
1979 return alloced_bstrs[alloced_bstrs_count++];
1982 static void free_bstrs(void)
1984 int i;
1985 for (i = 0; i < alloced_bstrs_count; i++)
1986 SysFreeString(alloced_bstrs[i]);
1987 alloced_bstrs_count = 0;
1990 static VARIANT _variantbstr_(const char *str)
1992 VARIANT v;
1993 V_VT(&v) = VT_BSTR;
1994 V_BSTR(&v) = _bstr_(str);
1995 return v;
1998 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
2000 for (;;)
2002 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
2003 while (*sRight == '\r' || *sRight == '\n') sRight++;
2004 if (*sLeft != *sRight) return FALSE;
2005 if (!*sLeft) return TRUE;
2006 sLeft++;
2007 sRight++;
2011 static void get_str_for_type(DOMNodeType type, char *buf)
2013 switch (type)
2015 case NODE_ATTRIBUTE:
2016 strcpy(buf, "A");
2017 break;
2018 case NODE_ELEMENT:
2019 strcpy(buf, "E");
2020 break;
2021 case NODE_DOCUMENT:
2022 strcpy(buf, "D");
2023 break;
2024 case NODE_TEXT:
2025 strcpy(buf, "T");
2026 break;
2027 case NODE_COMMENT:
2028 strcpy(buf, "C");
2029 break;
2030 case NODE_PROCESSING_INSTRUCTION:
2031 strcpy(buf, "P");
2032 break;
2033 default:
2034 wsprintfA(buf, "[%d]", type);
2038 static int get_node_position(IXMLDOMNode *node)
2040 HRESULT r;
2041 int pos = 0;
2043 IXMLDOMNode_AddRef(node);
2046 IXMLDOMNode *new_node;
2048 pos++;
2049 r = IXMLDOMNode_get_previousSibling(node, &new_node);
2050 ok(SUCCEEDED(r), "get_previousSibling failed\n");
2051 IXMLDOMNode_Release(node);
2052 node = new_node;
2053 } while (r == S_OK);
2054 return pos;
2057 static void node_to_string(IXMLDOMNode *node, char *buf)
2059 HRESULT r = S_OK;
2060 DOMNodeType type;
2062 if (node == NULL)
2064 lstrcpyA(buf, "(null)");
2065 return;
2068 IXMLDOMNode_AddRef(node);
2069 while (r == S_OK)
2071 IXMLDOMNode *new_node;
2073 ole_check(IXMLDOMNode_get_nodeType(node, &type));
2074 get_str_for_type(type, buf);
2075 buf+=strlen(buf);
2077 if (type == NODE_ATTRIBUTE)
2079 BSTR bstr;
2080 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
2081 *(buf++) = '\'';
2082 wsprintfA(buf, "%ws", bstr);
2083 buf += strlen(buf);
2084 *(buf++) = '\'';
2085 SysFreeString(bstr);
2087 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
2089 else
2091 r = IXMLDOMNode_get_parentNode(node, &new_node);
2092 wsprintf(buf, "%d", get_node_position(node));
2093 buf += strlen(buf);
2096 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
2097 IXMLDOMNode_Release(node);
2098 node = new_node;
2099 if (r == S_OK)
2100 *(buf++) = '.';
2103 *buf = 0;
2106 static char *list_to_string(IXMLDOMNodeList *list)
2108 static char buf[4096];
2109 char *pos = buf;
2110 LONG len = 0;
2111 int i;
2113 if (list == NULL)
2115 lstrcpyA(buf, "(null)");
2116 return buf;
2118 ole_check(IXMLDOMNodeList_get_length(list, &len));
2119 for (i = 0; i < len; i++)
2121 IXMLDOMNode *node;
2122 if (i > 0)
2123 *(pos++) = ' ';
2124 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2125 node_to_string(node, pos);
2126 pos += strlen(pos);
2127 IXMLDOMNode_Release(node);
2129 *pos = 0;
2130 return buf;
2133 #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); }
2134 #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); }
2136 struct docload_ret_t {
2137 VARIANT_BOOL b;
2138 HRESULT hr;
2141 struct leading_spaces_t {
2142 const CLSID *clsid;
2143 const char *name;
2144 struct docload_ret_t ret[2]; /* 0 - ::load(), 1 - ::loadXML() */
2147 static const struct leading_spaces_t leading_spaces_classdata[] = {
2148 { &CLSID_DOMDocument, "CLSID_DOMDocument", {{VARIANT_FALSE, S_FALSE }, {VARIANT_TRUE, S_OK } }},
2149 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
2150 { &CLSID_DOMDocument26, "CLSID_DOMDocument26", {{VARIANT_FALSE, S_FALSE }, {VARIANT_TRUE, S_OK } }},
2151 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
2152 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
2153 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
2154 { NULL }
2157 static const char* leading_spaces_xmldata[] = {
2158 "\n<?xml version=\"1.0\" encoding=\"UTF-16\" ?><root/>",
2159 " <?xml version=\"1.0\"?><root/>",
2160 "\n<?xml version=\"1.0\"?><root/>",
2161 "\t<?xml version=\"1.0\"?><root/>",
2162 "\r\n<?xml version=\"1.0\"?><root/>",
2163 "\r<?xml version=\"1.0\"?><root/>",
2164 "\r\r\r\r\t\t \n\n <?xml version=\"1.0\"?><root/>",
2168 static void test_domdoc( void )
2170 HRESULT r, hr;
2171 IXMLDOMDocument *doc;
2172 IXMLDOMParseError *error;
2173 IXMLDOMElement *element = NULL;
2174 IXMLDOMNode *node;
2175 IXMLDOMText *nodetext = NULL;
2176 IXMLDOMComment *node_comment = NULL;
2177 IXMLDOMAttribute *node_attr = NULL;
2178 IXMLDOMNode *nodeChild = NULL;
2179 IXMLDOMProcessingInstruction *nodePI = NULL;
2180 const struct leading_spaces_t *class_ptr;
2181 const char **data_ptr;
2182 VARIANT_BOOL b;
2183 VARIANT var;
2184 BSTR str;
2185 LONG code, ref;
2186 LONG nLength = 0;
2187 WCHAR buff[100];
2188 char path[MAX_PATH];
2189 int index;
2191 GetTempPathA(MAX_PATH, path);
2192 strcat(path, "leading_spaces.xml");
2194 /* Load document with leading spaces
2196 * Test all CLSIDs with all test data XML strings
2198 class_ptr = leading_spaces_classdata;
2199 index = 0;
2200 while (class_ptr->clsid)
2202 HRESULT hr;
2203 int i;
2205 hr = CoCreateInstance(class_ptr->clsid, NULL, CLSCTX_INPROC_SERVER,
2206 &IID_IXMLDOMDocument, (void**)&doc);
2207 if (hr != S_OK) {
2208 win_skip("%d: failed to create class instance for %s\n", index, class_ptr->name);
2209 class_ptr++;
2210 index++;
2211 continue;
2214 data_ptr = leading_spaces_xmldata;
2215 i = 0;
2216 while (*data_ptr) {
2217 BSTR data = _bstr_(*data_ptr);
2218 DWORD written;
2219 HANDLE file;
2221 file = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
2222 ok(file != INVALID_HANDLE_VALUE, "can't create file %s: %u\n", path, GetLastError());
2224 WriteFile(file, data, lstrlenW(data)*sizeof(WCHAR), &written, NULL);
2225 CloseHandle(file);
2227 b = 0xc;
2228 V_VT(&var) = VT_BSTR;
2229 V_BSTR(&var) = _bstr_(path);
2230 hr = IXMLDOMDocument_load(doc, var, &b);
2231 todo_wine {
2232 EXPECT_HR(hr, class_ptr->ret[0].hr);
2233 ok(b == class_ptr->ret[0].b, "%d:%d, got %d, expected %d\n", index, i, b, class_ptr->ret[0].b);
2235 DeleteFileA(path);
2237 b = 0xc;
2238 hr = IXMLDOMDocument_loadXML(doc, data, &b);
2239 EXPECT_HR(hr, class_ptr->ret[1].hr);
2240 ok(b == class_ptr->ret[1].b, "%d:%d, got %d, expected %d\n", index, i, b, class_ptr->ret[1].b);
2242 data_ptr++;
2243 i++;
2246 class_ptr++;
2247 index++;
2248 free_bstrs();
2251 doc = create_document(&IID_IXMLDOMDocument);
2252 if (!doc) return;
2254 if (0)
2256 /* crashes on native */
2257 IXMLDOMDocument_loadXML( doc, (BSTR)0x1, NULL );
2260 /* try some stupid things */
2261 hr = IXMLDOMDocument_loadXML( doc, NULL, NULL );
2262 EXPECT_HR(hr, S_FALSE);
2264 b = VARIANT_TRUE;
2265 hr = IXMLDOMDocument_loadXML( doc, NULL, &b );
2266 EXPECT_HR(hr, S_FALSE);
2267 ok( b == VARIANT_FALSE, "failed to load XML string\n");
2269 /* try to load a document from a nonexistent file */
2270 b = VARIANT_TRUE;
2271 str = SysAllocString( nonexistent_fileW );
2272 VariantInit(&var);
2273 V_VT(&var) = VT_BSTR;
2274 V_BSTR(&var) = str;
2276 r = IXMLDOMDocument_load( doc, var, &b);
2277 ok( r == S_FALSE, "loadXML succeeded\n");
2278 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2279 SysFreeString( str );
2281 /* try load an empty document */
2282 b = VARIANT_TRUE;
2283 str = SysAllocString( szEmpty );
2284 r = IXMLDOMDocument_loadXML( doc, str, &b );
2285 ok( r == S_FALSE, "loadXML succeeded\n");
2286 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2287 SysFreeString( str );
2289 r = IXMLDOMDocument_get_async( doc, &b );
2290 ok( r == S_OK, "get_async failed (%08x)\n", r);
2291 ok( b == VARIANT_TRUE, "Wrong default value\n");
2293 /* check that there's no document element */
2294 element = NULL;
2295 r = IXMLDOMDocument_get_documentElement( doc, &element );
2296 ok( r == S_FALSE, "should be no document element\n");
2298 /* try finding a node */
2299 node = NULL;
2300 str = SysAllocString( szstr1 );
2301 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
2302 ok( r == S_FALSE, "ret %08x\n", r );
2303 SysFreeString( str );
2305 b = VARIANT_TRUE;
2306 str = SysAllocString( szIncomplete );
2307 r = IXMLDOMDocument_loadXML( doc, str, &b );
2308 ok( r == S_FALSE, "loadXML succeeded\n");
2309 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2310 SysFreeString( str );
2312 /* check that there's no document element */
2313 element = (IXMLDOMElement*)1;
2314 r = IXMLDOMDocument_get_documentElement( doc, &element );
2315 ok( r == S_FALSE, "should be no document element\n");
2316 ok( element == NULL, "Element should be NULL\n");
2318 /* test for BSTR handling, pass broken BSTR */
2319 memcpy(&buff[2], szComplete1, sizeof(szComplete1));
2320 /* just a big length */
2321 *(DWORD*)buff = 0xf0f0;
2322 b = VARIANT_FALSE;
2323 r = IXMLDOMDocument_loadXML( doc, &buff[2], &b );
2324 ok( r == S_OK, "loadXML failed\n");
2325 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2327 /* loadXML ignores the encoding attribute and always expects Unicode */
2328 b = VARIANT_FALSE;
2329 str = SysAllocString( szComplete6 );
2330 r = IXMLDOMDocument_loadXML( doc, str, &b );
2331 ok( r == S_OK, "loadXML failed\n");
2332 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2333 SysFreeString( str );
2335 /* try a BSTR containing a Windows-1252 document */
2336 b = VARIANT_TRUE;
2337 str = SysAllocStringByteLen( win1252xml, strlen(win1252xml) );
2338 r = IXMLDOMDocument_loadXML( doc, str, &b );
2339 ok( r == S_FALSE, "loadXML succeeded\n");
2340 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2341 SysFreeString( str );
2343 /* try to load something valid */
2344 b = VARIANT_FALSE;
2345 str = SysAllocString( szComplete1 );
2346 r = IXMLDOMDocument_loadXML( doc, str, &b );
2347 ok( r == S_OK, "loadXML failed\n");
2348 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2349 SysFreeString( str );
2351 /* check if nodename is correct */
2352 r = IXMLDOMDocument_get_nodeName( doc, NULL );
2353 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2355 str = (BSTR)0xdeadbeef;
2356 r = IXMLDOMDocument_get_baseName( doc, &str );
2357 ok ( r == S_FALSE, "got 0x%08x\n", r);
2358 ok (str == NULL, "got %p\n", str);
2360 /* content doesn't matter here */
2361 str = NULL;
2362 r = IXMLDOMDocument_get_nodeName( doc, &str );
2363 ok ( r == S_OK, "get_nodeName wrong code\n");
2364 ok ( str != NULL, "str is null\n");
2365 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
2366 SysFreeString( str );
2368 /* test put_text */
2369 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
2370 ok( r == E_FAIL, "ret %08x\n", r );
2372 /* check that there's a document element */
2373 element = NULL;
2374 r = IXMLDOMDocument_get_documentElement( doc, &element );
2375 ok( r == S_OK, "should be a document element\n");
2376 if( element )
2378 IObjectIdentity *ident;
2380 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (void**)&ident );
2381 ok( r == E_NOINTERFACE, "ret %08x\n", r);
2383 IXMLDOMElement_Release( element );
2384 element = NULL;
2387 /* as soon as we call loadXML again, the document element will disappear */
2388 b = 2;
2389 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
2390 ok( r == S_FALSE, "loadXML failed\n");
2391 ok( b == 2, "variant modified\n");
2392 r = IXMLDOMDocument_get_documentElement( doc, &element );
2393 ok( r == S_FALSE, "should be no document element\n");
2395 /* try to load something else simple and valid */
2396 b = VARIANT_FALSE;
2397 str = SysAllocString( szComplete3 );
2398 r = IXMLDOMDocument_loadXML( doc, str, &b );
2399 ok( r == S_OK, "loadXML failed\n");
2400 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2401 SysFreeString( str );
2403 /* try something a little more complicated */
2404 b = FALSE;
2405 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
2406 ok( r == S_OK, "loadXML failed\n");
2407 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2409 r = IXMLDOMDocument_get_parseError( doc, &error );
2410 ok( r == S_OK, "returns %08x\n", r );
2412 r = IXMLDOMParseError_get_errorCode( error, &code );
2413 ok( r == S_FALSE, "returns %08x\n", r );
2414 ok( code == 0, "code %d\n", code );
2415 IXMLDOMParseError_Release( error );
2417 /* test createTextNode */
2418 r = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &nodetext);
2419 ok( r == S_OK, "returns %08x\n", r );
2420 IXMLDOMText_Release(nodetext);
2422 str = SysAllocString( szOpen );
2423 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
2424 ok( r == E_INVALIDARG, "returns %08x\n", r );
2425 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
2426 ok( r == S_OK, "returns %08x\n", r );
2427 SysFreeString( str );
2428 if(nodetext)
2430 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element);
2431 ok(r == E_NOINTERFACE, "ret %08x\n", r );
2433 /* Text Last Child Checks */
2434 r = IXMLDOMText_get_lastChild(nodetext, NULL);
2435 ok(r == E_INVALIDARG, "ret %08x\n", r );
2437 nodeChild = (IXMLDOMNode*)0x1;
2438 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
2439 ok(r == S_FALSE, "ret %08x\n", r );
2440 ok(nodeChild == NULL, "nodeChild not NULL\n");
2442 /* test length property */
2443 r = IXMLDOMText_get_length(nodetext, NULL);
2444 ok(r == E_INVALIDARG, "ret %08x\n", r );
2446 r = IXMLDOMText_get_length(nodetext, &nLength);
2447 ok(r == S_OK, "ret %08x\n", r );
2448 ok(nLength == 4, "expected 4 got %d\n", nLength);
2450 /* put data Tests */
2451 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
2452 ok(r == S_OK, "ret %08x\n", r );
2454 /* get data Tests */
2455 r = IXMLDOMText_get_data(nodetext, &str);
2456 ok(r == S_OK, "ret %08x\n", r );
2457 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
2458 SysFreeString(str);
2460 /* Confirm XML text is good */
2461 r = IXMLDOMText_get_xml(nodetext, &str);
2462 ok(r == S_OK, "ret %08x\n", r );
2463 ok( !lstrcmpW( str, _bstr_("This &amp;is a ; test &lt;&gt;\\") ), "incorrect xml string\n");
2464 SysFreeString(str);
2466 /* Confirm we get the put_data Text back */
2467 r = IXMLDOMText_get_text(nodetext, &str);
2468 ok(r == S_OK, "ret %08x\n", r );
2469 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2470 SysFreeString(str);
2472 /* test substringData */
2473 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
2474 ok(r == E_INVALIDARG, "ret %08x\n", r );
2476 /* test substringData - Invalid offset */
2477 str = (BSTR)&szElement;
2478 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
2479 ok(r == E_INVALIDARG, "ret %08x\n", r );
2480 ok( str == NULL, "incorrect string\n");
2482 /* test substringData - Invalid offset */
2483 str = (BSTR)&szElement;
2484 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
2485 ok(r == S_FALSE, "ret %08x\n", r );
2486 ok( str == NULL, "incorrect string\n");
2488 /* test substringData - Invalid size */
2489 str = (BSTR)&szElement;
2490 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
2491 ok(r == E_INVALIDARG, "ret %08x\n", r );
2492 ok( str == NULL, "incorrect string\n");
2494 /* test substringData - Invalid size */
2495 str = (BSTR)&szElement;
2496 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
2497 ok(r == S_FALSE, "ret %08x\n", r );
2498 ok( str == NULL, "incorrect string\n");
2500 /* test substringData - Start of string */
2501 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
2502 ok(r == S_OK, "ret %08x\n", r );
2503 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2504 SysFreeString(str);
2506 /* test substringData - Middle of string */
2507 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
2508 ok(r == S_OK, "ret %08x\n", r );
2509 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2510 SysFreeString(str);
2512 /* test substringData - End of string */
2513 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
2514 ok(r == S_OK, "ret %08x\n", r );
2515 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2516 SysFreeString(str);
2518 /* test appendData */
2519 r = IXMLDOMText_appendData(nodetext, NULL);
2520 ok(r == S_OK, "ret %08x\n", r );
2522 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
2523 ok(r == S_OK, "ret %08x\n", r );
2525 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
2526 ok(r == S_OK, "ret %08x\n", r );
2528 r = IXMLDOMText_get_text(nodetext, &str);
2529 ok(r == S_OK, "ret %08x\n", r );
2530 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2531 SysFreeString(str);
2533 /* test insertData */
2534 str = SysAllocStringLen(NULL, 0);
2535 r = IXMLDOMText_insertData(nodetext, -1, str);
2536 ok(r == S_OK, "ret %08x\n", r );
2538 r = IXMLDOMText_insertData(nodetext, -1, NULL);
2539 ok(r == S_OK, "ret %08x\n", r );
2541 r = IXMLDOMText_insertData(nodetext, 1000, str);
2542 ok(r == S_OK, "ret %08x\n", r );
2544 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
2545 ok(r == S_OK, "ret %08x\n", r );
2547 r = IXMLDOMText_insertData(nodetext, 0, NULL);
2548 ok(r == S_OK, "ret %08x\n", r );
2550 r = IXMLDOMText_insertData(nodetext, 0, str);
2551 ok(r == S_OK, "ret %08x\n", r );
2552 SysFreeString(str);
2554 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
2555 ok(r == E_INVALIDARG, "ret %08x\n", r );
2557 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
2558 ok(r == E_INVALIDARG, "ret %08x\n", r );
2560 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
2561 ok(r == S_OK, "ret %08x\n", r );
2563 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
2564 ok(r == S_OK, "ret %08x\n", r );
2566 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
2567 ok(r == S_OK, "ret %08x\n", r );
2569 r = IXMLDOMText_get_text(nodetext, &str);
2570 ok(r == S_OK, "ret %08x\n", r );
2571 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2572 SysFreeString(str);
2574 /* delete data */
2575 /* invalid arguments */
2576 r = IXMLDOMText_deleteData(nodetext, -1, 1);
2577 ok(r == E_INVALIDARG, "ret %08x\n", r );
2579 r = IXMLDOMText_deleteData(nodetext, 0, 0);
2580 ok(r == S_OK, "ret %08x\n", r );
2582 r = IXMLDOMText_deleteData(nodetext, 0, -1);
2583 ok(r == E_INVALIDARG, "ret %08x\n", r );
2585 r = IXMLDOMText_get_length(nodetext, &nLength);
2586 ok(r == S_OK, "ret %08x\n", r );
2587 ok(nLength == 43, "expected 43 got %d\n", nLength);
2589 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
2590 ok(r == S_OK, "ret %08x\n", r );
2592 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
2593 ok(r == E_INVALIDARG, "ret %08x\n", r );
2595 /* delete from start */
2596 r = IXMLDOMText_deleteData(nodetext, 0, 5);
2597 ok(r == S_OK, "ret %08x\n", r );
2599 r = IXMLDOMText_get_length(nodetext, &nLength);
2600 ok(r == S_OK, "ret %08x\n", r );
2601 ok(nLength == 38, "expected 38 got %d\n", nLength);
2603 r = IXMLDOMText_get_text(nodetext, &str);
2604 ok(r == S_OK, "ret %08x\n", r );
2605 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2606 SysFreeString(str);
2608 /* delete from end */
2609 r = IXMLDOMText_deleteData(nodetext, 35, 3);
2610 ok(r == S_OK, "ret %08x\n", r );
2612 r = IXMLDOMText_get_length(nodetext, &nLength);
2613 ok(r == S_OK, "ret %08x\n", r );
2614 ok(nLength == 35, "expected 35 got %d\n", nLength);
2616 r = IXMLDOMText_get_text(nodetext, &str);
2617 ok(r == S_OK, "ret %08x\n", r );
2618 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2619 SysFreeString(str);
2621 /* delete from inside */
2622 r = IXMLDOMText_deleteData(nodetext, 1, 33);
2623 ok(r == S_OK, "ret %08x\n", r );
2625 r = IXMLDOMText_get_length(nodetext, &nLength);
2626 ok(r == S_OK, "ret %08x\n", r );
2627 ok(nLength == 2, "expected 2 got %d\n", nLength);
2629 r = IXMLDOMText_get_text(nodetext, &str);
2630 ok(r == S_OK, "ret %08x\n", r );
2631 ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2632 SysFreeString(str);
2634 /* delete whole data ... */
2635 r = IXMLDOMText_get_length(nodetext, &nLength);
2636 ok(r == S_OK, "ret %08x\n", r );
2638 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
2639 ok(r == S_OK, "ret %08x\n", r );
2640 /* ... and try again with empty string */
2641 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
2642 ok(r == S_OK, "ret %08x\n", r );
2644 /* test put_data */
2645 V_VT(&var) = VT_BSTR;
2646 V_BSTR(&var) = SysAllocString(szstr1);
2647 r = IXMLDOMText_put_nodeValue(nodetext, var);
2648 ok(r == S_OK, "ret %08x\n", r );
2649 VariantClear(&var);
2651 r = IXMLDOMText_get_text(nodetext, &str);
2652 ok(r == S_OK, "ret %08x\n", r );
2653 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2654 SysFreeString(str);
2656 /* test put_data */
2657 V_VT(&var) = VT_I4;
2658 V_I4(&var) = 99;
2659 r = IXMLDOMText_put_nodeValue(nodetext, var);
2660 ok(r == S_OK, "ret %08x\n", r );
2661 VariantClear(&var);
2663 r = IXMLDOMText_get_text(nodetext, &str);
2664 ok(r == S_OK, "ret %08x\n", r );
2665 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2666 SysFreeString(str);
2668 /* ::replaceData() */
2669 V_VT(&var) = VT_BSTR;
2670 V_BSTR(&var) = SysAllocString(szstr1);
2671 r = IXMLDOMText_put_nodeValue(nodetext, var);
2672 ok(r == S_OK, "ret %08x\n", r );
2673 VariantClear(&var);
2675 r = IXMLDOMText_replaceData(nodetext, 6, 0, NULL);
2676 ok(r == E_INVALIDARG, "ret %08x\n", r );
2677 r = IXMLDOMText_get_text(nodetext, &str);
2678 ok(r == S_OK, "ret %08x\n", r );
2679 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2680 SysFreeString(str);
2682 r = IXMLDOMText_replaceData(nodetext, 0, 0, NULL);
2683 ok(r == S_OK, "ret %08x\n", r );
2684 r = IXMLDOMText_get_text(nodetext, &str);
2685 ok(r == S_OK, "ret %08x\n", r );
2686 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2687 SysFreeString(str);
2689 /* NULL pointer means delete */
2690 r = IXMLDOMText_replaceData(nodetext, 0, 1, NULL);
2691 ok(r == S_OK, "ret %08x\n", r );
2692 r = IXMLDOMText_get_text(nodetext, &str);
2693 ok(r == S_OK, "ret %08x\n", r );
2694 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2695 SysFreeString(str);
2697 /* empty string means delete */
2698 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_(""));
2699 ok(r == S_OK, "ret %08x\n", r );
2700 r = IXMLDOMText_get_text(nodetext, &str);
2701 ok(r == S_OK, "ret %08x\n", r );
2702 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2703 SysFreeString(str);
2705 /* zero count means insert */
2706 r = IXMLDOMText_replaceData(nodetext, 0, 0, _bstr_("a"));
2707 ok(r == S_OK, "ret %08x\n", r );
2708 r = IXMLDOMText_get_text(nodetext, &str);
2709 ok(r == S_OK, "ret %08x\n", r );
2710 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2711 SysFreeString(str);
2713 r = IXMLDOMText_replaceData(nodetext, 0, 2, NULL);
2714 ok(r == S_OK, "ret %08x\n", r );
2716 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("m"));
2717 ok(r == S_OK, "ret %08x\n", r );
2718 r = IXMLDOMText_get_text(nodetext, &str);
2719 ok(r == S_OK, "ret %08x\n", r );
2720 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2721 SysFreeString(str);
2723 /* nonempty string, count greater than its length */
2724 r = IXMLDOMText_replaceData(nodetext, 0, 2, _bstr_("a1.2"));
2725 ok(r == S_OK, "ret %08x\n", r );
2726 r = IXMLDOMText_get_text(nodetext, &str);
2727 ok(r == S_OK, "ret %08x\n", r );
2728 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2729 SysFreeString(str);
2731 /* nonempty string, count less than its length */
2732 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_("wine"));
2733 ok(r == S_OK, "ret %08x\n", r );
2734 r = IXMLDOMText_get_text(nodetext, &str);
2735 ok(r == S_OK, "ret %08x\n", r );
2736 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2737 SysFreeString(str);
2739 IXMLDOMText_Release( nodetext );
2742 /* test Create Comment */
2743 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
2744 ok( r == E_INVALIDARG, "returns %08x\n", r );
2745 node_comment = (IXMLDOMComment*)0x1;
2747 /* empty comment */
2748 r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
2749 ok( r == S_OK, "returns %08x\n", r );
2750 str = (BSTR)0x1;
2751 r = IXMLDOMComment_get_data(node_comment, &str);
2752 ok( r == S_OK, "returns %08x\n", r );
2753 ok( str && SysStringLen(str) == 0, "expected empty string data\n");
2754 IXMLDOMComment_Release(node_comment);
2755 SysFreeString(str);
2757 r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
2758 ok( r == S_OK, "returns %08x\n", r );
2759 str = (BSTR)0x1;
2760 r = IXMLDOMComment_get_data(node_comment, &str);
2761 ok( r == S_OK, "returns %08x\n", r );
2762 ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
2763 IXMLDOMComment_Release(node_comment);
2764 SysFreeString(str);
2766 str = SysAllocString(szComment);
2767 r = IXMLDOMDocument_createComment(doc, str, &node_comment);
2768 SysFreeString(str);
2769 ok( r == S_OK, "returns %08x\n", r );
2770 if(node_comment)
2772 /* Last Child Checks */
2773 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
2774 ok(r == E_INVALIDARG, "ret %08x\n", r );
2776 nodeChild = (IXMLDOMNode*)0x1;
2777 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
2778 ok(r == S_FALSE, "ret %08x\n", r );
2779 ok(nodeChild == NULL, "pLastChild not NULL\n");
2781 /* baseName */
2782 str = (BSTR)0xdeadbeef;
2783 r = IXMLDOMComment_get_baseName(node_comment, &str);
2784 ok(r == S_FALSE, "ret %08x\n", r );
2785 ok(str == NULL, "Expected NULL\n");
2787 IXMLDOMComment_Release( node_comment );
2790 /* test Create Attribute */
2791 str = SysAllocString(szAttribute);
2792 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
2793 ok( r == E_INVALIDARG, "returns %08x\n", r );
2794 r = IXMLDOMDocument_createAttribute(doc, str, &node_attr);
2795 ok( r == S_OK, "returns %08x\n", r );
2796 IXMLDOMText_Release( node_attr);
2797 SysFreeString(str);
2799 /* test Processing Instruction */
2800 str = SysAllocStringLen(NULL, 0);
2801 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
2802 ok( r == E_INVALIDARG, "returns %08x\n", r );
2803 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
2804 ok( r == E_FAIL, "returns %08x\n", r );
2805 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
2806 ok( r == E_FAIL, "returns %08x\n", r );
2807 SysFreeString(str);
2809 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
2810 ok( r == S_OK, "returns %08x\n", r );
2811 if(nodePI)
2813 /* Last Child Checks */
2814 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
2815 ok(r == E_INVALIDARG, "ret %08x\n", r );
2817 nodeChild = (IXMLDOMNode*)0x1;
2818 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
2819 ok(r == S_FALSE, "ret %08x\n", r );
2820 ok(nodeChild == NULL, "nodeChild not NULL\n");
2822 /* test nodeName */
2823 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
2824 ok(r == S_OK, "ret %08x\n", r );
2825 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2826 SysFreeString(str);
2828 /* test baseName */
2829 str = (BSTR)0x1;
2830 r = IXMLDOMProcessingInstruction_get_baseName(nodePI, &str);
2831 ok(r == S_OK, "ret %08x\n", r );
2832 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2833 SysFreeString(str);
2835 /* test Target */
2836 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
2837 ok(r == S_OK, "ret %08x\n", r );
2838 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
2839 SysFreeString(str);
2841 /* test get_data */
2842 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
2843 ok(r == S_OK, "ret %08x\n", r );
2844 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
2845 SysFreeString(str);
2847 /* test put_data */
2848 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
2849 ok(r == E_FAIL, "ret %08x\n", r );
2851 /* test put_data */
2852 V_VT(&var) = VT_BSTR;
2853 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
2854 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
2855 ok(r == E_FAIL, "ret %08x\n", r );
2856 VariantClear(&var);
2858 /* test get nodeName */
2859 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
2860 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2861 ok(r == S_OK, "ret %08x\n", r );
2862 SysFreeString(str);
2864 IXMLDOMProcessingInstruction_Release(nodePI);
2867 ref = IXMLDOMDocument_Release( doc );
2868 ok( ref == 0, "got %d\n", ref);
2870 free_bstrs();
2873 static void test_persiststreaminit(void)
2875 IXMLDOMDocument *doc;
2876 IPersistStreamInit *streaminit;
2877 HRESULT hr;
2879 doc = create_document(&IID_IXMLDOMDocument);
2880 if (!doc) return;
2882 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&streaminit);
2883 ok( hr == S_OK, "failed with 0x%08x\n", hr );
2885 hr = IPersistStreamInit_InitNew(streaminit);
2886 ok( hr == S_OK, "failed with 0x%08x\n", hr );
2888 IXMLDOMDocument_Release(doc);
2891 static void test_domnode( void )
2893 HRESULT r;
2894 IXMLDOMDocument *doc, *owner = NULL;
2895 IXMLDOMElement *element = NULL;
2896 IXMLDOMNamedNodeMap *map = NULL;
2897 IXMLDOMNode *node = NULL, *next = NULL;
2898 IXMLDOMNodeList *list = NULL;
2899 IXMLDOMAttribute *attr = NULL;
2900 DOMNodeType type = NODE_INVALID;
2901 VARIANT_BOOL b;
2902 BSTR str;
2903 VARIANT var;
2904 LONG count;
2906 doc = create_document(&IID_IXMLDOMDocument);
2907 if (!doc) return;
2909 b = FALSE;
2910 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
2911 ok( r == S_OK, "loadXML failed\n");
2912 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2914 EXPECT_CHILDREN(doc);
2916 r = IXMLDOMDocument_get_documentElement( doc, &element );
2917 ok( r == S_OK, "should be a document element\n");
2918 ok( element != NULL, "should be an element\n");
2920 VariantInit(&var);
2921 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
2923 r = IXMLDOMNode_get_nodeValue( doc, NULL );
2924 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
2926 r = IXMLDOMNode_get_nodeValue( doc, &var );
2927 ok( r == S_FALSE, "nextNode returned wrong code\n");
2928 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
2929 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
2931 if (element)
2933 owner = NULL;
2934 r = IXMLDOMNode_get_ownerDocument( element, &owner );
2935 ok( r == S_OK, "get_ownerDocument return code\n");
2936 ok( owner != doc, "get_ownerDocument return\n");
2937 IXMLDOMDocument_Release(owner);
2939 type = NODE_INVALID;
2940 r = IXMLDOMNode_get_nodeType( element, &type);
2941 ok( r == S_OK, "got %08x\n", r);
2942 ok( type == NODE_ELEMENT, "node not an element\n");
2944 str = NULL;
2945 r = IXMLDOMNode_get_baseName( element, &str );
2946 ok( r == S_OK, "get_baseName returned wrong code\n");
2947 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
2948 SysFreeString(str);
2950 /* check if nodename is correct */
2951 r = IXMLDOMElement_get_nodeName( element, NULL );
2952 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2954 /* content doesn't matter here */
2955 str = NULL;
2956 r = IXMLDOMElement_get_nodeName( element, &str );
2957 ok ( r == S_OK, "get_nodeName wrong code\n");
2958 ok ( str != NULL, "str is null\n");
2959 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
2960 SysFreeString( str );
2962 str = SysAllocString( nonexistent_fileW );
2963 V_VT(&var) = VT_I4;
2964 V_I4(&var) = 0x1234;
2965 r = IXMLDOMElement_getAttribute( element, str, &var );
2966 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
2967 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
2968 VariantClear(&var);
2970 str = SysAllocString( szdl );
2971 V_VT(&var) = VT_I4;
2972 V_I4(&var) = 0x1234;
2973 r = IXMLDOMElement_getAttribute( element, str, &var );
2974 ok( r == S_OK, "getAttribute ret %08x\n", r );
2975 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
2976 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
2977 VariantClear( &var );
2979 r = IXMLDOMElement_getAttribute( element, NULL, &var );
2980 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
2982 r = IXMLDOMElement_getAttribute( element, str, NULL );
2983 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
2985 attr = NULL;
2986 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
2987 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
2988 ok( attr != NULL, "getAttributeNode returned NULL\n" );
2989 if (attr)
2991 r = IXMLDOMAttribute_get_parentNode( attr, NULL );
2992 ok( r == E_INVALIDARG, "Expected E_INVALIDARG, ret %08x\n", r );
2994 /* attribute doesn't have a parent in msxml interpretation */
2995 node = (IXMLDOMNode*)0xdeadbeef;
2996 r = IXMLDOMAttribute_get_parentNode( attr, &node );
2997 ok( r == S_FALSE, "Expected S_FALSE, ret %08x\n", r );
2998 ok( node == NULL, "Expected NULL, got %p\n", node );
3000 IXMLDOMAttribute_Release(attr);
3003 SysFreeString( str );
3005 r = IXMLDOMElement_get_attributes( element, &map );
3006 ok( r == S_OK, "get_attributes returned wrong code\n");
3007 ok( map != NULL, "should be attributes\n");
3009 EXPECT_CHILDREN(element);
3011 else
3012 ok( FALSE, "no element\n");
3014 if (map)
3016 str = SysAllocString( szdl );
3017 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
3018 ok( r == S_OK, "getNamedItem returned wrong code\n");
3019 ok( node != NULL, "should be attributes\n");
3020 IXMLDOMNode_Release(node);
3021 SysFreeString( str );
3023 str = SysAllocString( szdl );
3024 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
3025 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
3026 SysFreeString( str );
3028 /* something that isn't in complete4A */
3029 str = SysAllocString( szOpen );
3030 node = (IXMLDOMNode *) 1;
3031 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
3032 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
3033 ok( node == NULL, "getNamedItem should have returned NULL\n");
3034 SysFreeString( str );
3036 /* test indexed access of attributes */
3037 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
3038 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
3040 r = IXMLDOMNamedNodeMap_get_length( map, &count );
3041 ok ( r == S_OK, "get_length wrong code\n");
3042 ok ( count == 1, "get_length != 1\n");
3044 node = NULL;
3045 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
3046 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
3047 ok ( node == NULL, "there is no node\n");
3049 node = NULL;
3050 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
3051 ok ( r == S_FALSE, "get_item (1) wrong code\n");
3052 ok ( node == NULL, "there is no attribute\n");
3054 node = NULL;
3055 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
3056 ok ( r == S_OK, "get_item (0) wrong code\n");
3057 ok ( node != NULL, "should be attribute\n");
3059 r = IXMLDOMNode_get_nodeName( node, NULL );
3060 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
3062 /* content doesn't matter here */
3063 str = NULL;
3064 r = IXMLDOMNode_get_nodeName( node, &str );
3065 ok ( r == S_OK, "get_nodeName wrong code\n");
3066 ok ( str != NULL, "str is null\n");
3067 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
3068 SysFreeString( str );
3069 IXMLDOMNode_Release( node );
3071 /* test sequential access of attributes */
3072 node = NULL;
3073 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
3074 ok ( r == S_OK, "nextNode (first time) wrong code\n");
3075 ok ( node != NULL, "nextNode, should be attribute\n");
3076 IXMLDOMNode_Release( node );
3078 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
3079 ok ( r != S_OK, "nextNode (second time) wrong code\n");
3080 ok ( node == NULL, "nextNode, there is no attribute\n");
3082 r = IXMLDOMNamedNodeMap_reset( map );
3083 ok ( r == S_OK, "reset should return S_OK\n");
3085 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
3086 ok ( r == S_OK, "nextNode (third time) wrong code\n");
3087 ok ( node != NULL, "nextNode, should be attribute\n");
3089 else
3090 ok( FALSE, "no map\n");
3092 if (node)
3094 type = NODE_INVALID;
3095 r = IXMLDOMNode_get_nodeType( node, &type);
3096 ok( r == S_OK, "getNamedItem returned wrong code\n");
3097 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
3099 str = NULL;
3100 r = IXMLDOMNode_get_baseName( node, NULL );
3101 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
3103 str = NULL;
3104 r = IXMLDOMNode_get_baseName( node, &str );
3105 ok( r == S_OK, "get_baseName returned wrong code\n");
3106 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
3107 SysFreeString( str );
3109 r = IXMLDOMNode_get_childNodes( node, NULL );
3110 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
3112 r = IXMLDOMNode_get_childNodes( node, &list );
3113 ok( r == S_OK, "get_childNodes returned wrong code\n");
3115 if (list)
3117 r = IXMLDOMNodeList_nextNode( list, &next );
3118 ok( r == S_OK, "nextNode returned wrong code\n");
3120 else
3121 ok( FALSE, "no childlist\n");
3123 if (next)
3125 EXPECT_NO_CHILDREN(next);
3127 type = NODE_INVALID;
3128 r = IXMLDOMNode_get_nodeType( next, &type);
3129 ok( r == S_OK, "getNamedItem returned wrong code\n");
3130 ok( type == NODE_TEXT, "node not text\n");
3132 str = (BSTR) 1;
3133 r = IXMLDOMNode_get_baseName( next, &str );
3134 ok( r == S_FALSE, "get_baseName returned wrong code\n");
3135 ok( str == NULL, "basename was wrong\n");
3136 SysFreeString(str);
3138 else
3139 ok( FALSE, "no next\n");
3141 if (next)
3142 IXMLDOMNode_Release( next );
3143 next = NULL;
3144 if (list)
3145 IXMLDOMNodeList_Release( list );
3146 list = NULL;
3147 if (node)
3148 IXMLDOMNode_Release( node );
3150 else
3151 ok( FALSE, "no node\n");
3152 node = NULL;
3154 if (map)
3155 IXMLDOMNamedNodeMap_Release( map );
3157 /* now traverse the tree from the root element */
3158 if (element)
3160 r = IXMLDOMNode_get_childNodes( element, &list );
3161 ok( r == S_OK, "get_childNodes returned wrong code\n");
3163 /* using get_item for child list doesn't advance the position */
3164 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
3165 expect_node(node, "E2.E2.D1");
3166 IXMLDOMNode_Release(node);
3167 ole_check(IXMLDOMNodeList_nextNode(list, &node));
3168 expect_node(node, "E1.E2.D1");
3169 IXMLDOMNode_Release(node);
3170 ole_check(IXMLDOMNodeList_reset(list));
3172 IXMLDOMNodeList_AddRef(list);
3173 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
3174 ole_check(IXMLDOMNodeList_reset(list));
3176 node = (void*)0xdeadbeef;
3177 str = SysAllocString(szdl);
3178 r = IXMLDOMNode_selectSingleNode( element, str, &node );
3179 SysFreeString(str);
3180 ok( r == S_FALSE, "ret %08x\n", r );
3181 ok( node == NULL, "node %p\n", node );
3183 str = SysAllocString(szbs);
3184 r = IXMLDOMNode_selectSingleNode( element, str, &node );
3185 SysFreeString(str);
3186 ok( r == S_OK, "ret %08x\n", r );
3187 r = IXMLDOMNode_Release( node );
3188 ok( r == 0, "ret %08x\n", r );
3190 else
3191 ok( FALSE, "no element\n");
3193 if (list)
3195 r = IXMLDOMNodeList_get_item(list, 0, NULL);
3196 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3198 r = IXMLDOMNodeList_get_length(list, NULL);
3199 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3201 r = IXMLDOMNodeList_get_length( list, &count );
3202 ok( r == S_OK, "get_length returns %08x\n", r );
3203 ok( count == 4, "get_length got %d\n", count );
3205 r = IXMLDOMNodeList_nextNode(list, NULL);
3206 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3208 r = IXMLDOMNodeList_nextNode( list, &node );
3209 ok( r == S_OK, "nextNode returned wrong code\n");
3211 else
3212 ok( FALSE, "no list\n");
3214 if (node)
3216 type = NODE_INVALID;
3217 r = IXMLDOMNode_get_nodeType( node, &type);
3218 ok( r == S_OK, "getNamedItem returned wrong code\n");
3219 ok( type == NODE_ELEMENT, "node not text\n");
3221 r = IXMLDOMNode_hasChildNodes( node, NULL );
3222 ok( r == E_INVALIDARG, "hasChildNodes bad return\n");
3224 EXPECT_CHILDREN(node);
3226 str = NULL;
3227 r = IXMLDOMNode_get_baseName( node, &str );
3228 ok( r == S_OK, "get_baseName returned wrong code\n");
3229 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
3230 SysFreeString(str);
3232 else
3233 ok( FALSE, "no node\n");
3235 if (node)
3236 IXMLDOMNode_Release( node );
3237 if (list)
3238 IXMLDOMNodeList_Release( list );
3239 if (element)
3240 IXMLDOMElement_Release( element );
3242 b = FALSE;
3243 str = SysAllocString( szComplete5 );
3244 r = IXMLDOMDocument_loadXML( doc, str, &b );
3245 ok( r == S_OK, "loadXML failed\n");
3246 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3247 SysFreeString( str );
3249 EXPECT_CHILDREN(doc);
3251 r = IXMLDOMDocument_get_documentElement( doc, &element );
3252 ok( r == S_OK, "should be a document element\n");
3253 ok( element != NULL, "should be an element\n");
3255 if (element)
3257 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
3258 BSTR tag = NULL;
3260 /* check if the tag is correct */
3261 r = IXMLDOMElement_get_tagName( element, &tag );
3262 ok( r == S_OK, "couldn't get tag name\n");
3263 ok( tag != NULL, "tag was null\n");
3264 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
3265 SysFreeString( tag );
3268 if (element)
3269 IXMLDOMElement_Release( element );
3270 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
3272 free_bstrs();
3275 typedef struct {
3276 DOMNodeType type;
3277 REFIID iid;
3278 } refcount_test_t;
3280 static const refcount_test_t refcount_test[] = {
3281 { NODE_ELEMENT, &IID_IXMLDOMElement },
3282 { NODE_ATTRIBUTE, &IID_IXMLDOMAttribute },
3283 { NODE_TEXT, &IID_IXMLDOMText },
3284 { NODE_CDATA_SECTION, &IID_IXMLDOMCDATASection },
3285 { NODE_ENTITY_REFERENCE, &IID_IXMLDOMEntityReference },
3286 { NODE_PROCESSING_INSTRUCTION, &IID_IXMLDOMProcessingInstruction },
3287 { NODE_COMMENT, &IID_IXMLDOMComment },
3288 { NODE_DOCUMENT_FRAGMENT, &IID_IXMLDOMDocumentFragment },
3289 { NODE_INVALID, &IID_NULL }
3292 static void test_refs(void)
3294 IXMLDOMImplementation *impl, *impl2;
3295 IXMLDOMElement *element, *elem2;
3296 IXMLDOMNodeList *node_list = NULL;
3297 IXMLDOMNode *node, *node2, *node3;
3298 const refcount_test_t *ptr;
3299 IXMLDOMDocument *doc;
3300 IUnknown *unk, *unk2;
3301 VARIANT_BOOL b;
3302 HRESULT hr;
3303 LONG ref;
3305 doc = create_document(&IID_IXMLDOMDocument);
3306 if (!doc) return;
3308 ptr = refcount_test;
3309 while (ptr->type != NODE_INVALID)
3311 IUnknown *node_typed, *node_typed2;
3312 IDispatchEx *dispex, *dispex2;
3313 IDispatch *disp, *disp2;
3314 VARIANT type;
3316 V_VT(&type) = VT_I1;
3317 V_I1(&type) = ptr->type;
3319 EXPECT_REF(doc, 1);
3320 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("name"), NULL, &node);
3321 EXPECT_HR(hr, S_OK);
3322 EXPECT_REF(doc, 1);
3323 EXPECT_REF(node, 1);
3325 /* try IDispatch and IUnknown from IXMLDOMNode */
3326 hr = IXMLDOMNode_QueryInterface(node, &IID_IUnknown, (void**)&unk);
3327 EXPECT_HR(hr, S_OK);
3328 EXPECT_REF(unk, 2);
3329 todo_wine {
3330 EXPECT_REF(node, 1);
3331 ok(unk != (IUnknown*)node, "%d: got %p and %p\n", ptr->type, unk, node);
3333 EXPECT_REF(unk, 2);
3334 hr = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
3335 EXPECT_HR(hr, S_OK);
3336 todo_wine ok(unk != (IUnknown*)disp, "%d: got %p and %p\n", ptr->type, unk, disp);
3337 EXPECT_REF(unk, 3);
3338 todo_wine EXPECT_REF(disp, 1);
3340 EXPECT_REF(unk, 3);
3341 hr = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp2);
3342 EXPECT_HR(hr, S_OK);
3343 todo_wine ok(disp != disp2, "%d: got %p and %p\n", ptr->type, disp, disp2);
3344 EXPECT_REF(unk, 4);
3345 todo_wine EXPECT_REF(disp2, 1);
3347 IDispatch_Release(disp);
3348 IDispatch_Release(disp2);
3350 /* get IXMLDOMNode from this IUnknown */
3351 EXPECT_REF(unk, 2);
3352 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMNode, (void**)&node2);
3353 EXPECT_HR(hr, S_OK);
3354 todo_wine ok(unk != (IUnknown*)node2, "%d: got %p and %p\n", ptr->type, unk, node2);
3355 EXPECT_REF(unk, 3);
3356 todo_wine EXPECT_REF(node2, 1);
3358 EXPECT_REF(unk, 3);
3359 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMNode, (void**)&node3);
3360 EXPECT_HR(hr, S_OK);
3361 todo_wine ok(node2 != node3, "%d: got %p and %p\n", ptr->type, node2, node3);
3362 EXPECT_REF(unk, 4);
3363 todo_wine EXPECT_REF(node3, 1);
3365 IXMLDOMNode_Release(node2);
3366 IXMLDOMNode_Release(node3);
3368 /* try IDispatchEx from IUnknown */
3369 EXPECT_REF(unk, 2);
3370 hr = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
3371 EXPECT_HR(hr, S_OK);
3372 ok(unk != (IUnknown*)dispex, "%d: got %p and %p\n", ptr->type, unk, dispex);
3373 EXPECT_REF(unk, 3);
3374 todo_wine EXPECT_REF(dispex, 1);
3376 EXPECT_REF(unk, 3);
3377 hr = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex2);
3378 EXPECT_HR(hr, S_OK);
3379 todo_wine ok(dispex != dispex2, "%d: got %p and %p\n", ptr->type, dispex, dispex2);
3380 EXPECT_REF(unk, 4);
3381 todo_wine EXPECT_REF(dispex2, 1);
3383 IDispatch_Release(dispex);
3384 IDispatch_Release(dispex2);
3386 /* try corresponding IXMLDOM* */
3387 EXPECT_REF(unk, 2);
3388 hr = IUnknown_QueryInterface(unk, ptr->iid, (void**)&node_typed);
3389 EXPECT_HR(hr, S_OK);
3390 EXPECT_REF(unk, 3);
3391 hr = IUnknown_QueryInterface(unk, ptr->iid, (void**)&node_typed2);
3392 EXPECT_HR(hr, S_OK);
3393 EXPECT_REF(unk, 4);
3394 todo_wine ok(node_typed != node_typed2, "%d: got %p and %p\n", ptr->type, node_typed, node_typed2);
3395 IUnknown_Release(node_typed);
3396 IUnknown_Release(node_typed2);
3398 /* try invalid IXMLDOM* */
3399 hr = IUnknown_QueryInterface(unk, (ptr+1)->iid, (void**)&node_typed);
3400 EXPECT_HR(hr, E_NOINTERFACE);
3402 IUnknown_Release(unk);
3404 EXPECT_REF(node, 1);
3405 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMNode, (void**)&node2);
3406 EXPECT_HR(hr, S_OK);
3407 EXPECT_REF(node, 2);
3408 ok(node == node2, "%d: got %p and %p\n", ptr->type, node, node2);
3410 EXPECT_REF(node, 2);
3411 hr = IXMLDOMNode_QueryInterface(node, ptr->iid, (void**)&node_typed);
3412 EXPECT_HR(hr, S_OK);
3413 EXPECT_REF(node, 3);
3414 todo_wine {
3415 EXPECT_REF(node_typed, 2);
3416 ok((IUnknown*)node != node_typed, "%d: got %p and %p\n", ptr->type, node, node_typed);
3418 IUnknown_Release(node_typed);
3420 IXMLDOMNode_Release(node2);
3421 IXMLDOMNode_Release(node);
3423 ptr++;
3426 EXPECT_REF(doc, 1);
3427 ref = IXMLDOMDocument_Release(doc);
3428 ok( ref == 0, "ref %d\n", ref);
3430 /* check IUnknown after releasing DOM iface */
3431 doc = create_document(&IID_IXMLDOMDocument);
3432 EXPECT_REF(doc, 1);
3433 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
3434 EXPECT_HR(hr, S_OK);
3435 todo_wine {
3436 EXPECT_REF(unk, 3);
3437 EXPECT_REF(doc, 1);
3439 IXMLDOMDocument_Release(doc);
3440 EXPECT_REF(unk, 1);
3441 IUnknown_Release(unk);
3443 doc = create_document(&IID_IXMLDOMDocument);
3444 if (!doc) return;
3446 EXPECT_REF(doc, 1);
3447 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
3448 EXPECT_HR(hr, S_OK);
3449 todo_wine {
3450 EXPECT_REF(unk, 3);
3451 EXPECT_REF(doc, 1);
3453 IUnknown_Release(unk);
3455 /* IXMLDOMImplementation */
3456 EXPECT_REF(doc, 1);
3457 hr = IXMLDOMDocument_get_implementation(doc, &impl);
3458 EXPECT_HR(hr, S_OK);
3459 EXPECT_REF(doc, 1);
3460 EXPECT_REF(impl, 1);
3461 hr = IXMLDOMDocument_get_implementation(doc, &impl2);
3462 EXPECT_HR(hr, S_OK);
3463 EXPECT_REF(doc, 1);
3464 EXPECT_REF(impl2, 1);
3465 ok(impl != impl2, "got %p, %p\n", impl, impl2);
3466 IXMLDOMImplementation_Release(impl);
3467 IXMLDOMImplementation_Release(impl2);
3469 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3470 EXPECT_HR(hr, S_OK);
3471 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3473 EXPECT_REF(doc, 1);
3474 IXMLDOMDocument_AddRef( doc );
3475 EXPECT_REF(doc, 2);
3476 IXMLDOMDocument_AddRef( doc );
3477 EXPECT_REF(doc, 3);
3479 IXMLDOMDocument_Release( doc );
3480 IXMLDOMDocument_Release( doc );
3482 EXPECT_REF(doc, 1);
3483 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
3484 EXPECT_HR(hr, S_OK);
3485 todo_wine {
3486 EXPECT_REF(unk, 3);
3487 EXPECT_REF(doc, 1);
3489 hr = IXMLDOMDocument_get_documentElement(doc, &element);
3490 EXPECT_HR(hr, S_OK);
3491 todo_wine {
3492 EXPECT_REF(doc, 1);
3493 EXPECT_REF(element, 2);
3495 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
3496 EXPECT_HR(hr, S_OK);
3498 todo_wine {
3499 EXPECT_REF(doc, 1);
3500 EXPECT_REF(element, 2);
3501 EXPECT_REF(elem2, 2);
3503 IXMLDOMElement_AddRef(element);
3504 todo_wine EXPECT_REF(element, 3);
3505 IXMLDOMElement_Release(element);
3507 /* get IUnknown from a node doesn't touch node instance refcount */
3508 hr = IXMLDOMElement_QueryInterface(element, &IID_IUnknown, (void**)&unk);
3509 EXPECT_HR(hr, S_OK);
3510 EXPECT_REF(element, 2);
3511 todo_wine {
3512 EXPECT_REF(unk, 4);
3513 EXPECT_REF(elem2, 2);
3515 hr = IXMLDOMElement_QueryInterface(elem2, &IID_IUnknown, (void**)&unk2);
3516 EXPECT_HR(hr, S_OK);
3517 todo_wine {
3518 EXPECT_REF(unk, 5);
3519 EXPECT_REF(unk2, 5);
3521 EXPECT_REF(element, 2);
3522 EXPECT_REF(elem2, 2);
3524 todo_wine ok(unk == unk2, "got %p and %p\n", unk, unk2);
3526 IUnknown_Release(unk);
3527 IUnknown_Release(unk2);
3529 /* IUnknown refcount is not affected by node refcount */
3530 todo_wine EXPECT_REF(unk2, 3);
3531 IXMLDOMElement_AddRef(elem2);
3532 todo_wine EXPECT_REF(unk2, 3);
3533 IXMLDOMElement_Release(elem2);
3535 IXMLDOMElement_Release(elem2);
3536 todo_wine EXPECT_REF(unk2, 2);
3538 hr = IXMLDOMElement_get_childNodes( element, &node_list );
3539 EXPECT_HR(hr, S_OK);
3541 todo_wine EXPECT_REF(element, 2);
3542 EXPECT_REF(node_list, 1);
3544 hr = IXMLDOMNodeList_get_item( node_list, 0, &node );
3545 EXPECT_HR(hr, S_OK);
3546 EXPECT_REF(node_list, 1);
3547 EXPECT_REF(node, 1);
3549 hr = IXMLDOMNodeList_get_item( node_list, 0, &node2 );
3550 EXPECT_HR(hr, S_OK);
3551 EXPECT_REF(node_list, 1);
3552 EXPECT_REF(node2, 1);
3554 ref = IXMLDOMNode_Release( node );
3555 ok( ref == 0, "ref %d\n", ref );
3556 ref = IXMLDOMNode_Release( node2 );
3557 ok( ref == 0, "ref %d\n", ref );
3559 ref = IXMLDOMNodeList_Release( node_list );
3560 ok( ref == 0, "ref %d\n", ref );
3562 ok( node != node2, "node %p node2 %p\n", node, node2 );
3564 ref = IXMLDOMDocument_Release( doc );
3565 todo_wine ok( ref == 0, "ref %d\n", ref );
3567 todo_wine EXPECT_REF(element, 2);
3569 /* IUnknown must be unique however we obtain it */
3570 hr = IXMLDOMElement_QueryInterface(element, &IID_IUnknown, (void**)&unk);
3571 EXPECT_HR(hr, S_OK);
3572 EXPECT_REF(element, 2);
3573 hr = IXMLDOMElement_QueryInterface(element, &IID_IXMLDOMNode, (void**)&node);
3574 EXPECT_HR(hr, S_OK);
3575 todo_wine EXPECT_REF(element, 2);
3576 hr = IXMLDOMNode_QueryInterface(node, &IID_IUnknown, (void**)&unk2);
3577 EXPECT_HR(hr, S_OK);
3578 todo_wine EXPECT_REF(element, 2);
3579 ok(unk == unk2, "unk %p unk2 %p\n", unk, unk2);
3580 todo_wine ok(element != (void*)node, "node %p element %p\n", node, element);
3582 IUnknown_Release( unk2 );
3583 IUnknown_Release( unk );
3584 IXMLDOMNode_Release( node );
3585 todo_wine EXPECT_REF(element, 2);
3587 IXMLDOMElement_Release( element );
3589 free_bstrs();
3592 static void test_create(void)
3594 static const WCHAR szOne[] = {'1',0};
3595 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
3596 HRESULT r;
3597 VARIANT var;
3598 BSTR str, name;
3599 IXMLDOMDocument *doc;
3600 IXMLDOMElement *element;
3601 IXMLDOMComment *comment;
3602 IXMLDOMText *text;
3603 IXMLDOMCDATASection *cdata;
3604 IXMLDOMNode *root, *node, *child;
3605 IXMLDOMNamedNodeMap *attr_map;
3606 IUnknown *unk;
3607 LONG ref;
3608 LONG num;
3610 doc = create_document(&IID_IXMLDOMDocument);
3611 if (!doc) return;
3613 EXPECT_REF(doc, 1);
3615 /* types not supported for creation */
3616 V_VT(&var) = VT_I1;
3617 V_I1(&var) = NODE_DOCUMENT;
3618 node = (IXMLDOMNode*)0x1;
3619 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3620 ok( r == E_INVALIDARG, "returns %08x\n", r );
3621 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3623 V_VT(&var) = VT_I1;
3624 V_I1(&var) = NODE_DOCUMENT_TYPE;
3625 node = (IXMLDOMNode*)0x1;
3626 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3627 ok( r == E_INVALIDARG, "returns %08x\n", r );
3628 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3630 V_VT(&var) = VT_I1;
3631 V_I1(&var) = NODE_ENTITY;
3632 node = (IXMLDOMNode*)0x1;
3633 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3634 ok( r == E_INVALIDARG, "returns %08x\n", r );
3635 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3637 V_VT(&var) = VT_I1;
3638 V_I1(&var) = NODE_NOTATION;
3639 node = (IXMLDOMNode*)0x1;
3640 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3641 ok( r == E_INVALIDARG, "returns %08x\n", r );
3642 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3644 /* NODE_COMMENT */
3645 V_VT(&var) = VT_I1;
3646 V_I1(&var) = NODE_COMMENT;
3647 node = NULL;
3648 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3649 ok( r == S_OK, "returns %08x\n", r );
3650 ok( node != NULL, "\n");
3652 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3653 ok( r == S_OK, "returns %08x\n", r );
3654 IXMLDOMNode_Release(node);
3656 str = NULL;
3657 r = IXMLDOMComment_get_data(comment, &str);
3658 ok( r == S_OK, "returns %08x\n", r );
3659 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3660 IXMLDOMComment_Release(comment);
3661 SysFreeString(str);
3663 node = (IXMLDOMNode*)0x1;
3664 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3665 ok( r == S_OK, "returns %08x\n", r );
3667 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3668 ok( r == S_OK, "returns %08x\n", r );
3669 IXMLDOMNode_Release(node);
3671 str = NULL;
3672 r = IXMLDOMComment_get_data(comment, &str);
3673 ok( r == S_OK, "returns %08x\n", r );
3674 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3675 IXMLDOMComment_Release(comment);
3676 SysFreeString(str);
3678 node = (IXMLDOMNode*)0x1;
3679 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3680 ok( r == S_OK, "returns %08x\n", r );
3682 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3683 ok( r == S_OK, "returns %08x\n", r );
3684 IXMLDOMNode_Release(node);
3686 str = NULL;
3687 r = IXMLDOMComment_get_data(comment, &str);
3688 ok( r == S_OK, "returns %08x\n", r );
3689 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3690 IXMLDOMComment_Release(comment);
3691 SysFreeString(str);
3693 /* NODE_TEXT */
3694 V_VT(&var) = VT_I1;
3695 V_I1(&var) = NODE_TEXT;
3696 node = NULL;
3697 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3698 ok( r == S_OK, "returns %08x\n", r );
3699 ok( node != NULL, "\n");
3701 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3702 ok( r == S_OK, "returns %08x\n", r );
3703 IXMLDOMNode_Release(node);
3705 str = NULL;
3706 r = IXMLDOMText_get_data(text, &str);
3707 ok( r == S_OK, "returns %08x\n", r );
3708 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3709 IXMLDOMText_Release(text);
3710 SysFreeString(str);
3712 node = (IXMLDOMNode*)0x1;
3713 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3714 ok( r == S_OK, "returns %08x\n", r );
3716 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3717 ok( r == S_OK, "returns %08x\n", r );
3718 IXMLDOMNode_Release(node);
3720 str = NULL;
3721 r = IXMLDOMText_get_data(text, &str);
3722 ok( r == S_OK, "returns %08x\n", r );
3723 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3724 IXMLDOMText_Release(text);
3725 SysFreeString(str);
3727 node = (IXMLDOMNode*)0x1;
3728 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3729 ok( r == S_OK, "returns %08x\n", r );
3731 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3732 ok( r == S_OK, "returns %08x\n", r );
3733 IXMLDOMNode_Release(node);
3735 str = NULL;
3736 r = IXMLDOMText_get_data(text, &str);
3737 ok( r == S_OK, "returns %08x\n", r );
3738 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3739 IXMLDOMText_Release(text);
3740 SysFreeString(str);
3742 /* NODE_CDATA_SECTION */
3743 V_VT(&var) = VT_I1;
3744 V_I1(&var) = NODE_CDATA_SECTION;
3745 node = NULL;
3746 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3747 ok( r == S_OK, "returns %08x\n", r );
3748 ok( node != NULL, "\n");
3750 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3751 ok( r == S_OK, "returns %08x\n", r );
3752 IXMLDOMNode_Release(node);
3754 str = NULL;
3755 r = IXMLDOMCDATASection_get_data(cdata, &str);
3756 ok( r == S_OK, "returns %08x\n", r );
3757 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3758 IXMLDOMCDATASection_Release(cdata);
3759 SysFreeString(str);
3761 node = (IXMLDOMNode*)0x1;
3762 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3763 ok( r == S_OK, "returns %08x\n", r );
3765 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3766 ok( r == S_OK, "returns %08x\n", r );
3767 IXMLDOMNode_Release(node);
3769 str = NULL;
3770 r = IXMLDOMCDATASection_get_data(cdata, &str);
3771 ok( r == S_OK, "returns %08x\n", r );
3772 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3773 IXMLDOMCDATASection_Release(cdata);
3774 SysFreeString(str);
3776 node = (IXMLDOMNode*)0x1;
3777 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3778 ok( r == S_OK, "returns %08x\n", r );
3780 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3781 ok( r == S_OK, "returns %08x\n", r );
3782 IXMLDOMNode_Release(node);
3784 str = NULL;
3785 r = IXMLDOMCDATASection_get_data(cdata, &str);
3786 ok( r == S_OK, "returns %08x\n", r );
3787 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3788 IXMLDOMCDATASection_Release(cdata);
3789 SysFreeString(str);
3791 /* NODE_ATTRIBUTE */
3792 V_VT(&var) = VT_I1;
3793 V_I1(&var) = NODE_ATTRIBUTE;
3794 node = (IXMLDOMNode*)0x1;
3795 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3796 ok( r == E_FAIL, "returns %08x\n", r );
3797 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3799 V_VT(&var) = VT_I1;
3800 V_I1(&var) = NODE_ATTRIBUTE;
3801 node = (IXMLDOMNode*)0x1;
3802 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3803 ok( r == E_FAIL, "returns %08x\n", r );
3804 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3806 V_VT(&var) = VT_I1;
3807 V_I1(&var) = NODE_ATTRIBUTE;
3808 str = SysAllocString( szlc );
3809 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3810 ok( r == S_OK, "returns %08x\n", r );
3811 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3812 SysFreeString(str);
3814 /* a name is required for attribute, try a BSTR with first null wchar */
3815 V_VT(&var) = VT_I1;
3816 V_I1(&var) = NODE_ATTRIBUTE;
3817 str = SysAllocString( szstr1 );
3818 str[0] = 0;
3819 node = (IXMLDOMNode*)0x1;
3820 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3821 ok( r == E_FAIL, "returns %08x\n", r );
3822 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3823 SysFreeString(str);
3825 /* NODE_PROCESSING_INSTRUCTION */
3826 V_VT(&var) = VT_I1;
3827 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3828 node = (IXMLDOMNode*)0x1;
3829 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3830 ok( r == E_FAIL, "returns %08x\n", r );
3831 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3833 V_VT(&var) = VT_I1;
3834 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3835 node = (IXMLDOMNode*)0x1;
3836 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3837 ok( r == E_FAIL, "returns %08x\n", r );
3838 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3840 V_VT(&var) = VT_I1;
3841 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3842 r = IXMLDOMDocument_createNode( doc, var, _bstr_("pi"), NULL, NULL );
3843 ok( r == E_INVALIDARG, "returns %08x\n", r );
3845 /* NODE_ENTITY_REFERENCE */
3846 V_VT(&var) = VT_I1;
3847 V_I1(&var) = NODE_ENTITY_REFERENCE;
3848 node = (IXMLDOMNode*)0x1;
3849 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3850 ok( r == E_FAIL, "returns %08x\n", r );
3851 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3853 V_VT(&var) = VT_I1;
3854 V_I1(&var) = NODE_ENTITY_REFERENCE;
3855 node = (IXMLDOMNode*)0x1;
3856 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3857 ok( r == E_FAIL, "returns %08x\n", r );
3858 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3860 /* NODE_ELEMENT */
3861 V_VT(&var) = VT_I1;
3862 V_I1(&var) = NODE_ELEMENT;
3863 node = (IXMLDOMNode*)0x1;
3864 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3865 ok( r == E_FAIL, "returns %08x\n", r );
3866 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3868 V_VT(&var) = VT_I1;
3869 V_I1(&var) = NODE_ELEMENT;
3870 node = (IXMLDOMNode*)0x1;
3871 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3872 ok( r == E_FAIL, "returns %08x\n", r );
3873 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3875 V_VT(&var) = VT_I1;
3876 V_I1(&var) = NODE_ELEMENT;
3877 str = SysAllocString( szlc );
3878 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3879 ok( r == S_OK, "returns %08x\n", r );
3880 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3882 V_VT(&var) = VT_I1;
3883 V_I1(&var) = NODE_ELEMENT;
3884 r = IXMLDOMDocument_createNode( doc, var, str, NULL, NULL );
3885 ok( r == E_INVALIDARG, "returns %08x\n", r );
3887 V_VT(&var) = VT_R4;
3888 V_R4(&var) = NODE_ELEMENT;
3889 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3890 ok( r == S_OK, "returns %08x\n", r );
3891 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3893 V_VT(&var) = VT_BSTR;
3894 V_BSTR(&var) = SysAllocString( szOne );
3895 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3896 ok( r == S_OK, "returns %08x\n", r );
3897 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3898 VariantClear(&var);
3900 V_VT(&var) = VT_BSTR;
3901 V_BSTR(&var) = SysAllocString( szOneGarbage );
3902 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3903 ok( r == E_INVALIDARG, "returns %08x\n", r );
3904 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3905 VariantClear(&var);
3907 V_VT(&var) = VT_I4;
3908 V_I4(&var) = NODE_ELEMENT;
3909 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3910 ok( r == S_OK, "returns %08x\n", r );
3912 EXPECT_REF(doc, 1);
3913 r = IXMLDOMDocument_appendChild( doc, node, &root );
3914 ok( r == S_OK, "returns %08x\n", r );
3915 ok( node == root, "%p %p\n", node, root );
3916 EXPECT_REF(doc, 1);
3918 EXPECT_REF(node, 2);
3920 ref = IXMLDOMNode_Release( node );
3921 ok(ref == 1, "ref %d\n", ref);
3922 SysFreeString( str );
3924 V_VT(&var) = VT_I4;
3925 V_I4(&var) = NODE_ELEMENT;
3926 str = SysAllocString( szbs );
3927 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3928 ok( r == S_OK, "returns %08x\n", r );
3929 SysFreeString( str );
3931 EXPECT_REF(node, 1);
3933 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk );
3934 ok( r == S_OK, "returns %08x\n", r );
3936 EXPECT_REF(unk, 2);
3938 V_VT(&var) = VT_EMPTY;
3939 child = NULL;
3940 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
3941 ok( r == S_OK, "returns %08x\n", r );
3942 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
3944 todo_wine EXPECT_REF(unk, 4);
3946 IXMLDOMNode_Release( child );
3947 IUnknown_Release( unk );
3949 V_VT(&var) = VT_NULL;
3950 V_DISPATCH(&var) = (IDispatch*)node;
3951 r = IXMLDOMNode_insertBefore( root, node, var, &child );
3952 ok( r == S_OK, "returns %08x\n", r );
3953 ok( node == child, "%p %p\n", node, child );
3954 IXMLDOMNode_Release( child );
3956 V_VT(&var) = VT_NULL;
3957 V_DISPATCH(&var) = (IDispatch*)node;
3958 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
3959 ok( r == S_OK, "returns %08x\n", r );
3960 IXMLDOMNode_Release( node );
3962 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (void**)&element );
3963 ok( r == S_OK, "returns %08x\n", r );
3965 r = IXMLDOMElement_get_attributes( element, &attr_map );
3966 ok( r == S_OK, "returns %08x\n", r );
3967 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3968 ok( r == S_OK, "returns %08x\n", r );
3969 ok( num == 0, "num %d\n", num );
3970 IXMLDOMNamedNodeMap_Release( attr_map );
3972 V_VT(&var) = VT_BSTR;
3973 V_BSTR(&var) = SysAllocString( szstr1 );
3974 name = SysAllocString( szdl );
3975 r = IXMLDOMElement_setAttribute( element, name, var );
3976 ok( r == S_OK, "returns %08x\n", r );
3977 r = IXMLDOMElement_get_attributes( element, &attr_map );
3978 ok( r == S_OK, "returns %08x\n", r );
3979 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3980 ok( r == S_OK, "returns %08x\n", r );
3981 ok( num == 1, "num %d\n", num );
3982 IXMLDOMNamedNodeMap_Release( attr_map );
3983 VariantClear(&var);
3985 V_VT(&var) = VT_BSTR;
3986 V_BSTR(&var) = SysAllocString( szstr2 );
3987 r = IXMLDOMElement_setAttribute( element, name, var );
3988 ok( r == S_OK, "returns %08x\n", r );
3989 r = IXMLDOMElement_get_attributes( element, &attr_map );
3990 ok( r == S_OK, "returns %08x\n", r );
3991 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3992 ok( r == S_OK, "returns %08x\n", r );
3993 ok( num == 1, "num %d\n", num );
3994 IXMLDOMNamedNodeMap_Release( attr_map );
3995 VariantClear(&var);
3996 r = IXMLDOMElement_getAttribute( element, name, &var );
3997 ok( r == S_OK, "returns %08x\n", r );
3998 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
3999 VariantClear(&var);
4000 SysFreeString(name);
4002 V_VT(&var) = VT_BSTR;
4003 V_BSTR(&var) = SysAllocString( szstr1 );
4004 name = SysAllocString( szlc );
4005 r = IXMLDOMElement_setAttribute( element, name, var );
4006 ok( r == S_OK, "returns %08x\n", r );
4007 r = IXMLDOMElement_get_attributes( element, &attr_map );
4008 ok( r == S_OK, "returns %08x\n", r );
4009 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
4010 ok( r == S_OK, "returns %08x\n", r );
4011 ok( num == 2, "num %d\n", num );
4012 IXMLDOMNamedNodeMap_Release( attr_map );
4013 VariantClear(&var);
4014 SysFreeString(name);
4016 V_VT(&var) = VT_I4;
4017 V_I4(&var) = 10;
4018 name = SysAllocString( szbs );
4019 r = IXMLDOMElement_setAttribute( element, name, var );
4020 ok( r == S_OK, "returns %08x\n", r );
4021 VariantClear(&var);
4022 r = IXMLDOMElement_getAttribute( element, name, &var );
4023 ok( r == S_OK, "returns %08x\n", r );
4024 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
4025 VariantClear(&var);
4026 SysFreeString(name);
4028 /* Create an Attribute */
4029 V_VT(&var) = VT_I4;
4030 V_I4(&var) = NODE_ATTRIBUTE;
4031 str = SysAllocString( szAttribute );
4032 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
4033 ok( r == S_OK, "returns %08x\n", r );
4034 ok( node != NULL, "node was null\n");
4035 SysFreeString(str);
4037 IXMLDOMElement_Release( element );
4038 IXMLDOMNode_Release( root );
4039 IXMLDOMDocument_Release( doc );
4042 static void test_getElementsByTagName(void)
4044 IXMLDOMNodeList *node_list;
4045 IXMLDOMDocument *doc;
4046 IXMLDOMElement *elem;
4047 WCHAR buff[100];
4048 VARIANT_BOOL b;
4049 HRESULT r;
4050 LONG len;
4051 BSTR str;
4053 doc = create_document(&IID_IXMLDOMDocument);
4054 if (!doc) return;
4056 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4057 ok( r == S_OK, "loadXML failed\n");
4058 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4060 str = SysAllocString( szstar );
4062 /* null arguments cases */
4063 r = IXMLDOMDocument_getElementsByTagName(doc, NULL, &node_list);
4064 ok( r == E_INVALIDARG, "ret %08x\n", r );
4065 r = IXMLDOMDocument_getElementsByTagName(doc, str, NULL);
4066 ok( r == E_INVALIDARG, "ret %08x\n", r );
4068 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
4069 ok( r == S_OK, "ret %08x\n", r );
4070 r = IXMLDOMNodeList_get_length( node_list, &len );
4071 ok( r == S_OK, "ret %08x\n", r );
4072 ok( len == 6, "len %d\n", len );
4074 IXMLDOMNodeList_Release( node_list );
4075 SysFreeString( str );
4077 /* broken query BSTR */
4078 memcpy(&buff[2], szstar, sizeof(szstar));
4079 /* just a big length */
4080 *(DWORD*)buff = 0xf0f0;
4081 r = IXMLDOMDocument_getElementsByTagName(doc, &buff[2], &node_list);
4082 ok( r == S_OK, "ret %08x\n", r );
4083 r = IXMLDOMNodeList_get_length( node_list, &len );
4084 ok( r == S_OK, "ret %08x\n", r );
4085 ok( len == 6, "len %d\n", len );
4086 IXMLDOMNodeList_Release( node_list );
4088 str = SysAllocString( szbs );
4089 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
4090 ok( r == S_OK, "ret %08x\n", r );
4091 r = IXMLDOMNodeList_get_length( node_list, &len );
4092 ok( r == S_OK, "ret %08x\n", r );
4093 ok( len == 1, "len %d\n", len );
4094 IXMLDOMNodeList_Release( node_list );
4095 SysFreeString( str );
4097 str = SysAllocString( szdl );
4098 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
4099 ok( r == S_OK, "ret %08x\n", r );
4100 r = IXMLDOMNodeList_get_length( node_list, &len );
4101 ok( r == S_OK, "ret %08x\n", r );
4102 ok( len == 0, "len %d\n", len );
4103 IXMLDOMNodeList_Release( node_list );
4104 SysFreeString( str );
4106 str = SysAllocString( szstr1 );
4107 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
4108 ok( r == S_OK, "ret %08x\n", r );
4109 r = IXMLDOMNodeList_get_length( node_list, &len );
4110 ok( r == S_OK, "ret %08x\n", r );
4111 ok( len == 0, "len %d\n", len );
4112 IXMLDOMNodeList_Release( node_list );
4113 SysFreeString( str );
4115 /* test for element */
4116 r = IXMLDOMDocument_get_documentElement(doc, &elem);
4117 ok( r == S_OK, "ret %08x\n", r );
4119 str = SysAllocString( szstar );
4121 /* null arguments cases */
4122 r = IXMLDOMElement_getElementsByTagName(elem, NULL, &node_list);
4123 ok( r == E_INVALIDARG, "ret %08x\n", r );
4124 r = IXMLDOMElement_getElementsByTagName(elem, str, NULL);
4125 ok( r == E_INVALIDARG, "ret %08x\n", r );
4127 r = IXMLDOMElement_getElementsByTagName(elem, str, &node_list);
4128 ok( r == S_OK, "ret %08x\n", r );
4129 r = IXMLDOMNodeList_get_length( node_list, &len );
4130 ok( r == S_OK, "ret %08x\n", r );
4131 ok( len == 5, "len %d\n", len );
4132 expect_list_and_release(node_list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1 E1.E4.E2.D1");
4133 SysFreeString( str );
4135 /* broken query BSTR */
4136 memcpy(&buff[2], szstar, sizeof(szstar));
4137 /* just a big length */
4138 *(DWORD*)buff = 0xf0f0;
4139 r = IXMLDOMElement_getElementsByTagName(elem, &buff[2], &node_list);
4140 ok( r == S_OK, "ret %08x\n", r );
4141 r = IXMLDOMNodeList_get_length( node_list, &len );
4142 ok( r == S_OK, "ret %08x\n", r );
4143 ok( len == 5, "len %d\n", len );
4144 IXMLDOMNodeList_Release( node_list );
4146 IXMLDOMElement_Release(elem);
4148 IXMLDOMDocument_Release( doc );
4150 free_bstrs();
4153 static void test_get_text(void)
4155 HRESULT r;
4156 BSTR str;
4157 VARIANT_BOOL b;
4158 IXMLDOMDocument *doc;
4159 IXMLDOMNode *node, *node2, *node3;
4160 IXMLDOMNode *nodeRoot;
4161 IXMLDOMNodeList *node_list;
4162 IXMLDOMNamedNodeMap *node_map;
4163 LONG len;
4165 doc = create_document(&IID_IXMLDOMDocument);
4166 if (!doc) return;
4168 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4169 ok( r == S_OK, "loadXML failed\n");
4170 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4172 str = SysAllocString( szbs );
4173 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
4174 ok( r == S_OK, "ret %08x\n", r );
4175 SysFreeString(str);
4177 /* Test to get all child node text. */
4178 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&nodeRoot);
4179 ok( r == S_OK, "ret %08x\n", r );
4180 if(r == S_OK)
4182 r = IXMLDOMNode_get_text( nodeRoot, &str );
4183 ok( r == S_OK, "ret %08x\n", r );
4184 ok( compareIgnoreReturns(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text: %s\n", wine_dbgstr_w(str));
4185 SysFreeString(str);
4187 IXMLDOMNode_Release(nodeRoot);
4190 r = IXMLDOMNodeList_get_length( node_list, NULL );
4191 ok( r == E_INVALIDARG, "ret %08x\n", r );
4193 r = IXMLDOMNodeList_get_length( node_list, &len );
4194 ok( r == S_OK, "ret %08x\n", r );
4195 ok( len == 1, "expect 1 got %d\n", len );
4197 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
4198 ok( r == E_INVALIDARG, "ret %08x\n", r );
4200 r = IXMLDOMNodeList_nextNode( node_list, NULL );
4201 ok( r == E_INVALIDARG, "ret %08x\n", r );
4203 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
4204 ok( r == S_OK, "ret %08x\n", r );
4205 IXMLDOMNodeList_Release( node_list );
4207 /* Invalid output parameter*/
4208 r = IXMLDOMNode_get_text( node, NULL );
4209 ok( r == E_INVALIDARG, "ret %08x\n", r );
4211 r = IXMLDOMNode_get_text( node, &str );
4212 ok( r == S_OK, "ret %08x\n", r );
4213 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
4214 SysFreeString(str);
4216 r = IXMLDOMNode_get_attributes( node, &node_map );
4217 ok( r == S_OK, "ret %08x\n", r );
4219 str = SysAllocString( szvr );
4220 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
4221 ok( r == S_OK, "ret %08x\n", r );
4222 SysFreeString(str);
4224 r = IXMLDOMNode_get_text( node2, &str );
4225 ok( r == S_OK, "ret %08x\n", r );
4226 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
4227 SysFreeString(str);
4229 r = IXMLDOMNode_get_firstChild( node2, &node3 );
4230 ok( r == S_OK, "ret %08x\n", r );
4232 r = IXMLDOMNode_get_text( node3, &str );
4233 ok( r == S_OK, "ret %08x\n", r );
4234 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
4235 SysFreeString(str);
4238 IXMLDOMNode_Release( node3 );
4239 IXMLDOMNode_Release( node2 );
4240 IXMLDOMNamedNodeMap_Release( node_map );
4241 IXMLDOMNode_Release( node );
4242 IXMLDOMDocument_Release( doc );
4244 free_bstrs();
4247 static void test_get_childNodes(void)
4249 IXMLDOMNodeList *node_list, *node_list2;
4250 IEnumVARIANT *enum1, *enum2, *enum3;
4251 VARIANT_BOOL b;
4252 IXMLDOMDocument *doc;
4253 IXMLDOMNode *node, *node2;
4254 IXMLDOMElement *element;
4255 IUnknown *unk1, *unk2;
4256 HRESULT hr;
4257 VARIANT v;
4258 BSTR str;
4259 LONG len;
4261 doc = create_document(&IID_IXMLDOMDocument);
4262 if (!doc) return;
4264 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4265 EXPECT_HR(hr, S_OK);
4266 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4268 hr = IXMLDOMDocument_get_documentElement( doc, &element );
4269 EXPECT_HR(hr, S_OK);
4271 hr = IXMLDOMElement_get_childNodes( element, &node_list );
4272 EXPECT_HR(hr, S_OK);
4274 hr = IXMLDOMNodeList_get_length( node_list, &len );
4275 EXPECT_HR(hr, S_OK);
4276 ok( len == 4, "len %d\n", len);
4278 /* refcount tests for IEnumVARIANT support */
4279 EXPECT_REF(node_list, 1);
4280 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IEnumVARIANT, (void**)&enum1);
4281 EXPECT_HR(hr, S_OK);
4282 EXPECT_REF(node_list, 1);
4283 EXPECT_REF(enum1, 2);
4285 EXPECT_REF(node_list, 1);
4286 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IEnumVARIANT, (void**)&enum2);
4287 EXPECT_HR(hr, S_OK);
4288 EXPECT_REF(node_list, 1);
4289 ok(enum2 == enum1, "got %p, %p\n", enum2, enum1);
4290 IEnumVARIANT_Release(enum2);
4292 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk1);
4293 EXPECT_HR(hr, S_OK);
4294 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IUnknown, (void**)&unk2);
4295 EXPECT_HR(hr, S_OK);
4296 EXPECT_REF(node_list, 3);
4297 EXPECT_REF(enum1, 2);
4298 ok(unk1 == unk2, "got %p, %p\n", unk1, unk2);
4299 IUnknown_Release(unk1);
4300 IUnknown_Release(unk2);
4302 EXPECT_REF(node_list, 1);
4303 hr = IXMLDOMNodeList__newEnum(node_list, (IUnknown**)&enum2);
4304 EXPECT_HR(hr, S_OK);
4305 EXPECT_REF(node_list, 2);
4306 EXPECT_REF(enum2, 1);
4307 ok(enum2 != enum1, "got %p, %p\n", enum2, enum1);
4309 /* enumerator created with _newEnum() doesn't share IUnknown* with main object */
4310 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk1);
4311 EXPECT_HR(hr, S_OK);
4312 hr = IEnumVARIANT_QueryInterface(enum2, &IID_IUnknown, (void**)&unk2);
4313 EXPECT_HR(hr, S_OK);
4314 EXPECT_REF(node_list, 3);
4315 EXPECT_REF(enum2, 2);
4316 ok(unk1 != unk2, "got %p, %p\n", unk1, unk2);
4317 IUnknown_Release(unk1);
4318 IUnknown_Release(unk2);
4320 hr = IXMLDOMNodeList__newEnum(node_list, (IUnknown**)&enum3);
4321 EXPECT_HR(hr, S_OK);
4322 ok(enum2 != enum3, "got %p, %p\n", enum2, enum3);
4323 IEnumVARIANT_Release(enum3);
4324 IEnumVARIANT_Release(enum2);
4326 /* iteration tests */
4327 hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
4328 EXPECT_HR(hr, S_OK);
4329 hr = IXMLDOMNode_get_nodeName(node, &str);
4330 EXPECT_HR(hr, S_OK);
4331 ok(!lstrcmpW(str, _bstr_("bs")), "got %s\n", wine_dbgstr_w(str));
4332 SysFreeString(str);
4333 IXMLDOMNode_Release(node);
4335 hr = IXMLDOMNodeList_nextNode(node_list, &node);
4336 EXPECT_HR(hr, S_OK);
4337 hr = IXMLDOMNode_get_nodeName(node, &str);
4338 EXPECT_HR(hr, S_OK);
4339 ok(!lstrcmpW(str, _bstr_("bs")), "got %s\n", wine_dbgstr_w(str));
4340 SysFreeString(str);
4341 IXMLDOMNode_Release(node);
4343 V_VT(&v) = VT_EMPTY;
4344 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
4345 EXPECT_HR(hr, S_OK);
4346 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
4347 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
4348 EXPECT_HR(hr, S_OK);
4349 hr = IXMLDOMNode_get_nodeName(node, &str);
4350 EXPECT_HR(hr, S_OK);
4351 ok(!lstrcmpW(str, _bstr_("bs")), "got node name %s\n", wine_dbgstr_w(str));
4352 SysFreeString(str);
4353 IXMLDOMNode_Release(node);
4354 VariantClear(&v);
4356 hr = IXMLDOMNodeList_nextNode(node_list, &node);
4357 EXPECT_HR(hr, S_OK);
4358 hr = IXMLDOMNode_get_nodeName(node, &str);
4359 EXPECT_HR(hr, S_OK);
4360 ok(!lstrcmpW(str, _bstr_("pr")), "got %s\n", wine_dbgstr_w(str));
4361 SysFreeString(str);
4362 IXMLDOMNode_Release(node);
4364 IEnumVARIANT_Release(enum1);
4366 hr = IXMLDOMNodeList_get_item( node_list, 2, &node );
4367 EXPECT_HR(hr, S_OK);
4369 hr = IXMLDOMNode_get_childNodes( node, &node_list2 );
4370 EXPECT_HR(hr, S_OK);
4372 hr = IXMLDOMNodeList_get_length( node_list2, &len );
4373 EXPECT_HR(hr, S_OK);
4374 ok( len == 0, "len %d\n", len);
4376 hr = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
4377 EXPECT_HR(hr, S_FALSE);
4379 IXMLDOMNodeList_Release( node_list2 );
4380 IXMLDOMNode_Release( node );
4381 IXMLDOMNodeList_Release( node_list );
4382 IXMLDOMElement_Release( element );
4384 /* test for children of <?xml ..?> node */
4385 hr = IXMLDOMDocument_get_firstChild(doc, &node);
4386 EXPECT_HR(hr, S_OK);
4388 str = NULL;
4389 hr = IXMLDOMNode_get_nodeName(node, &str);
4390 EXPECT_HR(hr, S_OK);
4391 ok(!lstrcmpW(str, _bstr_("xml")), "got %s\n", wine_dbgstr_w(str));
4392 SysFreeString(str);
4394 /* it returns empty but valid node list */
4395 node_list = (void*)0xdeadbeef;
4396 hr = IXMLDOMNode_get_childNodes(node, &node_list);
4397 EXPECT_HR(hr, S_OK);
4399 len = -1;
4400 hr = IXMLDOMNodeList_get_length(node_list, &len);
4401 EXPECT_HR(hr, S_OK);
4402 ok(len == 0, "got %d\n", len);
4404 IXMLDOMNodeList_Release( node_list );
4405 IXMLDOMNode_Release(node);
4407 IXMLDOMDocument_Release( doc );
4408 free_bstrs();
4411 static void test_get_firstChild(void)
4413 static WCHAR xmlW[] = {'x','m','l',0};
4414 IXMLDOMDocument *doc;
4415 IXMLDOMNode *node;
4416 VARIANT_BOOL b;
4417 HRESULT r;
4418 BSTR str;
4420 doc = create_document(&IID_IXMLDOMDocument);
4421 if (!doc) return;
4423 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4424 ok( r == S_OK, "loadXML failed\n");
4425 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4427 r = IXMLDOMDocument_get_firstChild( doc, &node );
4428 ok( r == S_OK, "ret %08x\n", r);
4430 r = IXMLDOMNode_get_nodeName( node, &str );
4431 ok( r == S_OK, "ret %08x\n", r);
4433 ok(!lstrcmpW(str, xmlW), "expected \"xml\" node name, got %s\n", wine_dbgstr_w(str));
4435 SysFreeString(str);
4436 IXMLDOMNode_Release( node );
4437 IXMLDOMDocument_Release( doc );
4439 free_bstrs();
4442 static void test_get_lastChild(void)
4444 static WCHAR lcW[] = {'l','c',0};
4445 static WCHAR foW[] = {'f','o',0};
4446 IXMLDOMDocument *doc;
4447 IXMLDOMNode *node, *child;
4448 VARIANT_BOOL b;
4449 HRESULT r;
4450 BSTR str;
4452 doc = create_document(&IID_IXMLDOMDocument);
4453 if (!doc) return;
4455 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4456 ok( r == S_OK, "loadXML failed\n");
4457 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4459 r = IXMLDOMDocument_get_lastChild( doc, &node );
4460 ok( r == S_OK, "ret %08x\n", r);
4462 r = IXMLDOMNode_get_nodeName( node, &str );
4463 ok( r == S_OK, "ret %08x\n", r);
4465 ok(memcmp(str, lcW, sizeof(lcW)) == 0, "expected \"lc\" node name\n");
4466 SysFreeString(str);
4468 r = IXMLDOMNode_get_lastChild( node, &child );
4469 ok( r == S_OK, "ret %08x\n", r);
4471 r = IXMLDOMNode_get_nodeName( child, &str );
4472 ok( r == S_OK, "ret %08x\n", r);
4474 ok(memcmp(str, foW, sizeof(foW)) == 0, "expected \"fo\" node name\n");
4475 SysFreeString(str);
4477 IXMLDOMNode_Release( child );
4478 IXMLDOMNode_Release( node );
4479 IXMLDOMDocument_Release( doc );
4481 free_bstrs();
4484 static void test_removeChild(void)
4486 HRESULT r;
4487 VARIANT_BOOL b;
4488 IXMLDOMDocument *doc;
4489 IXMLDOMElement *element, *lc_element;
4490 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
4491 IXMLDOMNodeList *root_list, *fo_list;
4493 doc = create_document(&IID_IXMLDOMDocument);
4494 if (!doc) return;
4496 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4497 ok( r == S_OK, "loadXML failed\n");
4498 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4500 r = IXMLDOMDocument_get_documentElement( doc, &element );
4501 ok( r == S_OK, "ret %08x\n", r);
4502 todo_wine EXPECT_REF(element, 2);
4504 r = IXMLDOMElement_get_childNodes( element, &root_list );
4505 ok( r == S_OK, "ret %08x\n", r);
4506 EXPECT_REF(root_list, 1);
4508 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
4509 ok( r == S_OK, "ret %08x\n", r);
4510 EXPECT_REF(fo_node, 1);
4512 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4513 ok( r == S_OK, "ret %08x\n", r);
4514 EXPECT_REF(fo_list, 1);
4516 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
4517 ok( r == S_OK, "ret %08x\n", r);
4518 EXPECT_REF(ba_node, 1);
4520 /* invalid parameter: NULL ptr */
4521 removed_node = (void*)0xdeadbeef;
4522 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
4523 ok( r == E_INVALIDARG, "ret %08x\n", r );
4524 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4526 /* ba_node is a descendant of element, but not a direct child. */
4527 removed_node = (void*)0xdeadbeef;
4528 EXPECT_REF(ba_node, 1);
4529 EXPECT_CHILDREN(fo_node);
4530 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
4531 ok( r == E_INVALIDARG, "ret %08x\n", r );
4532 ok( removed_node == NULL, "%p\n", removed_node );
4533 EXPECT_REF(ba_node, 1);
4534 EXPECT_CHILDREN(fo_node);
4536 EXPECT_REF(ba_node, 1);
4537 EXPECT_REF(fo_node, 1);
4538 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
4539 ok( r == S_OK, "ret %08x\n", r);
4540 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
4541 EXPECT_REF(fo_node, 2);
4542 EXPECT_REF(ba_node, 1);
4544 /* try removing already removed child */
4545 temp_node = (void*)0xdeadbeef;
4546 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
4547 ok( r == E_INVALIDARG, "ret %08x\n", r);
4548 ok( temp_node == NULL, "%p\n", temp_node );
4549 IXMLDOMNode_Release( fo_node );
4551 /* the removed node has no parent anymore */
4552 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
4553 ok( r == S_FALSE, "ret %08x\n", r);
4554 ok( temp_node == NULL, "%p\n", temp_node );
4556 IXMLDOMNode_Release( removed_node );
4557 IXMLDOMNode_Release( ba_node );
4558 IXMLDOMNodeList_Release( fo_list );
4560 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
4561 ok( r == S_OK, "ret %08x\n", r);
4563 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (void**)&lc_element );
4564 ok( r == S_OK, "ret %08x\n", r);
4566 /* MS quirk: passing wrong interface pointer works, too */
4567 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
4568 ok( r == S_OK, "ret %08x\n", r);
4569 IXMLDOMElement_Release( lc_element );
4571 temp_node = (void*)0xdeadbeef;
4572 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
4573 ok( r == S_FALSE, "ret %08x\n", r);
4574 ok( temp_node == NULL, "%p\n", temp_node );
4576 IXMLDOMNode_Release( lc_node );
4577 IXMLDOMNodeList_Release( root_list );
4578 IXMLDOMElement_Release( element );
4579 IXMLDOMDocument_Release( doc );
4581 free_bstrs();
4584 static void test_replaceChild(void)
4586 HRESULT r;
4587 VARIANT_BOOL b;
4588 IXMLDOMDocument *doc;
4589 IXMLDOMElement *element, *ba_element;
4590 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
4591 IXMLDOMNodeList *root_list, *fo_list;
4592 IUnknown * unk1, *unk2;
4593 LONG len;
4595 doc = create_document(&IID_IXMLDOMDocument);
4596 if (!doc) return;
4598 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4599 ok( r == S_OK, "loadXML failed\n");
4600 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4602 r = IXMLDOMDocument_get_documentElement( doc, &element );
4603 ok( r == S_OK, "ret %08x\n", r);
4605 r = IXMLDOMElement_get_childNodes( element, &root_list );
4606 ok( r == S_OK, "ret %08x\n", r);
4608 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
4609 ok( r == S_OK, "ret %08x\n", r);
4611 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
4612 ok( r == S_OK, "ret %08x\n", r);
4614 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4615 ok( r == S_OK, "ret %08x\n", r);
4617 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
4618 ok( r == S_OK, "ret %08x\n", r);
4620 IXMLDOMNodeList_Release( fo_list );
4622 /* invalid parameter: NULL ptr for element to remove */
4623 removed_node = (void*)0xdeadbeef;
4624 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
4625 ok( r == E_INVALIDARG, "ret %08x\n", r );
4626 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4628 /* invalid parameter: NULL for replacement element. (Sic!) */
4629 removed_node = (void*)0xdeadbeef;
4630 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
4631 ok( r == E_INVALIDARG, "ret %08x\n", r );
4632 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4634 /* invalid parameter: OldNode is not a child */
4635 removed_node = (void*)0xdeadbeef;
4636 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
4637 ok( r == E_INVALIDARG, "ret %08x\n", r );
4638 ok( removed_node == NULL, "%p\n", removed_node );
4639 IXMLDOMNode_Release( lc_node );
4641 /* invalid parameter: would create loop */
4642 removed_node = (void*)0xdeadbeef;
4643 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
4644 ok( r == E_FAIL, "ret %08x\n", r );
4645 ok( removed_node == NULL, "%p\n", removed_node );
4647 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
4648 ok( r == S_OK, "ret %08x\n", r );
4650 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
4651 ok( r == S_OK, "ret %08x\n", r );
4653 /* ba_node and temp_node refer to the same node, yet they
4654 are different interface pointers */
4655 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
4656 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
4657 ok( r == S_OK, "ret %08x\n", r );
4658 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
4659 ok( r == S_OK, "ret %08x\n", r );
4660 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
4662 IUnknown_Release( unk1 );
4663 IUnknown_Release( unk2 );
4665 /* ba_node should have been removed from below fo_node */
4666 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4667 ok( r == S_OK, "ret %08x\n", r );
4669 /* MS quirk: replaceChild also accepts elements instead of nodes */
4670 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
4671 ok( r == S_OK, "ret %08x\n", r );
4672 EXPECT_REF(ba_element, 2);
4674 removed_node = NULL;
4675 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
4676 ok( r == S_OK, "ret %08x\n", r );
4677 ok( removed_node != NULL, "got %p\n", removed_node);
4678 EXPECT_REF(ba_element, 3);
4679 IXMLDOMElement_Release( ba_element );
4681 r = IXMLDOMNodeList_get_length( fo_list, &len);
4682 ok( r == S_OK, "ret %08x\n", r );
4683 ok( len == 0, "len %d\n", len);
4685 IXMLDOMNodeList_Release( fo_list );
4687 IXMLDOMNode_Release(ba_node);
4688 IXMLDOMNode_Release(fo_node);
4689 IXMLDOMNode_Release(temp_node);
4690 IXMLDOMNodeList_Release( root_list );
4691 IXMLDOMElement_Release( element );
4692 IXMLDOMDocument_Release( doc );
4694 free_bstrs();
4697 static void test_removeNamedItem(void)
4699 IXMLDOMDocument *doc;
4700 IXMLDOMElement *element;
4701 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
4702 IXMLDOMNodeList *root_list;
4703 IXMLDOMNamedNodeMap * pr_attrs;
4704 VARIANT_BOOL b;
4705 BSTR str;
4706 LONG len;
4707 HRESULT r;
4709 doc = create_document(&IID_IXMLDOMDocument);
4710 if (!doc) return;
4712 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
4713 ok( r == S_OK, "loadXML failed\n");
4714 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4716 r = IXMLDOMDocument_get_documentElement( doc, &element );
4717 ok( r == S_OK, "ret %08x\n", r);
4719 r = IXMLDOMElement_get_childNodes( element, &root_list );
4720 ok( r == S_OK, "ret %08x\n", r);
4722 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
4723 ok( r == S_OK, "ret %08x\n", r);
4725 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
4726 ok( r == S_OK, "ret %08x\n", r);
4728 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4729 ok( r == S_OK, "ret %08x\n", r);
4730 ok( len == 3, "length %d\n", len);
4732 removed_node = (void*)0xdeadbeef;
4733 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
4734 ok ( r == E_INVALIDARG, "ret %08x\n", r);
4735 ok ( removed_node == (void*)0xdeadbeef, "got %p\n", removed_node);
4737 removed_node = (void*)0xdeadbeef;
4738 str = SysAllocString(szvr);
4739 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
4740 ok ( r == S_OK, "ret %08x\n", r);
4742 removed_node2 = (void*)0xdeadbeef;
4743 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
4744 ok ( r == S_FALSE, "ret %08x\n", r);
4745 ok ( removed_node2 == NULL, "got %p\n", removed_node2 );
4747 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4748 ok( r == S_OK, "ret %08x\n", r);
4749 ok( len == 2, "length %d\n", len);
4751 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
4752 ok ( r == S_OK, "ret %08x\n", r);
4753 IXMLDOMNode_Release(removed_node);
4755 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4756 ok( r == S_OK, "ret %08x\n", r);
4757 ok( len == 3, "length %d\n", len);
4759 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
4760 ok ( r == S_OK, "ret %08x\n", r);
4762 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4763 ok( r == S_OK, "ret %08x\n", r);
4764 ok( len == 2, "length %d\n", len);
4766 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
4767 ok ( r == S_FALSE, "ret %08x\n", r);
4769 SysFreeString(str);
4771 IXMLDOMNamedNodeMap_Release( pr_attrs );
4772 IXMLDOMNode_Release( pr_node );
4773 IXMLDOMNodeList_Release( root_list );
4774 IXMLDOMElement_Release( element );
4775 IXMLDOMDocument_Release( doc );
4777 free_bstrs();
4780 #define test_IObjectSafety_set(p, r, r2, s, m, e, e2) _test_IObjectSafety_set(__LINE__,p, r, r2, s, m, e, e2)
4781 static void _test_IObjectSafety_set(unsigned line, IObjectSafety *safety, HRESULT result,
4782 HRESULT result2, DWORD set, DWORD mask, DWORD expected,
4783 DWORD expected2)
4785 DWORD enabled, supported;
4786 HRESULT hr;
4788 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL, set, mask);
4789 if (result == result2)
4790 ok_(__FILE__,line)(hr == result, "SetInterfaceSafetyOptions: expected %08x, returned %08x\n", result, hr );
4791 else
4792 ok_(__FILE__,line)(broken(hr == result) || hr == result2,
4793 "SetInterfaceSafetyOptions: expected %08x, got %08x\n", result2, hr );
4795 supported = enabled = 0xCAFECAFE;
4796 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4797 ok(hr == S_OK, "ret %08x\n", hr );
4798 if (expected == expected2)
4799 ok_(__FILE__,line)(enabled == expected, "Expected %08x, got %08x\n", expected, enabled);
4800 else
4801 ok_(__FILE__,line)(broken(enabled == expected) || enabled == expected2,
4802 "Expected %08x, got %08x\n", expected2, enabled);
4804 /* reset the safety options */
4806 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4807 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER,
4809 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4811 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4812 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4813 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
4816 #define test_IObjectSafety_common(s) _test_IObjectSafety_common(__LINE__,s)
4817 static void _test_IObjectSafety_common(unsigned line, IObjectSafety *safety)
4819 DWORD enabled = 0, supported = 0;
4820 HRESULT hr;
4822 /* get */
4823 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, NULL, &enabled);
4824 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
4825 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, NULL);
4826 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
4828 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4829 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4830 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
4831 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4832 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
4833 "got %08x\n", supported);
4834 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
4836 /* set -- individual flags */
4838 test_IObjectSafety_set(safety, S_OK, S_OK,
4839 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4840 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4842 test_IObjectSafety_set(safety, S_OK, S_OK,
4843 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA,
4844 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
4846 test_IObjectSafety_set(safety, S_OK, S_OK,
4847 INTERFACE_USES_SECURITY_MANAGER, INTERFACE_USES_SECURITY_MANAGER,
4848 0, INTERFACE_USES_SECURITY_MANAGER /* msxml3 SP8+ */);
4850 /* set INTERFACE_USES_DISPEX */
4852 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
4853 INTERFACE_USES_DISPEX, INTERFACE_USES_DISPEX,
4854 0, 0);
4856 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
4857 INTERFACE_USES_DISPEX, 0,
4858 0, 0);
4860 test_IObjectSafety_set(safety, S_OK, S_OK /* msxml3 SP8+ */,
4861 0, INTERFACE_USES_DISPEX,
4862 0, 0);
4864 /* set option masking */
4866 test_IObjectSafety_set(safety, S_OK, S_OK,
4867 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4868 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4869 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4870 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4872 test_IObjectSafety_set(safety, S_OK, S_OK,
4873 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4874 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4875 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4876 INTERFACESAFE_FOR_UNTRUSTED_DATA);
4878 test_IObjectSafety_set(safety, S_OK, S_OK,
4879 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4880 INTERFACE_USES_SECURITY_MANAGER,
4884 /* set -- inheriting previous settings */
4886 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4887 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4888 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4889 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4890 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4891 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4892 ok_(__FILE__,line)(enabled == INTERFACESAFE_FOR_UNTRUSTED_CALLER, "Expected INTERFACESAFE_FOR_UNTRUSTED_CALLER got %08x\n", enabled);
4893 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
4894 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4895 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
4896 "got %08x\n", supported);
4898 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4899 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4900 INTERFACESAFE_FOR_UNTRUSTED_DATA);
4901 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4902 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4903 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4904 ok_(__FILE__,line)(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_DATA) ||
4905 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA),
4906 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA) got %08x\n", enabled);
4907 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
4908 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4909 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
4910 "got %08x\n", supported);
4913 static void test_XMLHTTP(void)
4915 static const char bodyA[] = "mode=Test";
4916 static const char urlA[] = "http://crossover.codeweavers.com/posttest.php";
4917 static const char xmltestA[] = "http://crossover.codeweavers.com/xmltest.xml";
4918 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
4919 static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
4921 IXMLHttpRequest *xhr;
4922 IObjectSafety *safety;
4923 IObjectWithSite *obj_site, *obj_site2;
4924 BSTR bstrResponse, str, str1;
4925 VARIANT varbody, varbody_ref;
4926 VARIANT dummy;
4927 VARIANT async;
4928 LONG state, status, bound;
4929 IDispatch *event;
4930 void *ptr;
4931 HRESULT hr;
4932 HGLOBAL g;
4934 hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
4935 &IID_IXMLHttpRequest, (void**)&xhr);
4936 if (FAILED(hr))
4938 win_skip("IXMLHTTPRequest is not available (0x%08x)\n", hr);
4939 return;
4942 VariantInit(&dummy);
4943 V_VT(&dummy) = VT_ERROR;
4944 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
4945 VariantInit(&async);
4946 V_VT(&async) = VT_BOOL;
4947 V_BOOL(&async) = VARIANT_FALSE;
4949 hr = IXMLHttpRequest_put_onreadystatechange(xhr, NULL);
4950 EXPECT_HR(hr, S_OK);
4952 hr = IXMLHttpRequest_abort(xhr);
4953 EXPECT_HR(hr, S_OK);
4955 V_VT(&varbody) = VT_I2;
4956 V_I2(&varbody) = 1;
4957 hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
4958 EXPECT_HR(hr, E_PENDING);
4959 ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody));
4960 ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody));
4962 V_VT(&varbody) = VT_I2;
4963 V_I2(&varbody) = 1;
4964 hr = IXMLHttpRequest_get_responseStream(xhr, &varbody);
4965 EXPECT_HR(hr, E_PENDING);
4966 ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody));
4967 ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody));
4969 /* send before open */
4970 hr = IXMLHttpRequest_send(xhr, dummy);
4971 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4973 /* initial status code */
4974 hr = IXMLHttpRequest_get_status(xhr, NULL);
4975 EXPECT_HR(hr, E_INVALIDARG);
4977 status = 0xdeadbeef;
4978 hr = IXMLHttpRequest_get_status(xhr, &status);
4979 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4980 ok(status == 0xdeadbeef, "got %d\n", status);
4982 hr = IXMLHttpRequest_get_statusText(xhr, &str);
4983 ok(hr == E_FAIL, "got 0x%08x\n", hr);
4985 /* invalid parameters */
4986 hr = IXMLHttpRequest_open(xhr, NULL, NULL, async, dummy, dummy);
4987 EXPECT_HR(hr, E_INVALIDARG);
4989 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), NULL, async, dummy, dummy);
4990 EXPECT_HR(hr, E_INVALIDARG);
4992 hr = IXMLHttpRequest_open(xhr, NULL, _bstr_(urlA), async, dummy, dummy);
4993 EXPECT_HR(hr, E_INVALIDARG);
4995 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, NULL);
4996 EXPECT_HR(hr, E_INVALIDARG);
4998 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), NULL);
4999 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
5001 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
5002 EXPECT_HR(hr, E_INVALIDARG);
5004 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
5005 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
5007 hr = IXMLHttpRequest_get_readyState(xhr, NULL);
5008 EXPECT_HR(hr, E_INVALIDARG);
5010 state = -1;
5011 hr = IXMLHttpRequest_get_readyState(xhr, &state);
5012 EXPECT_HR(hr, S_OK);
5013 ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state);
5015 event = create_dispevent();
5017 EXPECT_REF(event, 1);
5018 hr = IXMLHttpRequest_put_onreadystatechange(xhr, event);
5019 EXPECT_HR(hr, S_OK);
5020 EXPECT_REF(event, 2);
5022 g_unexpectedcall = g_expectedcall = 0;
5024 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), _bstr_(urlA), async, dummy, dummy);
5025 EXPECT_HR(hr, S_OK);
5027 ok(g_unexpectedcall == 0, "unexpected disp event call\n");
5028 ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n");
5030 /* status code after ::open() */
5031 status = 0xdeadbeef;
5032 hr = IXMLHttpRequest_get_status(xhr, &status);
5033 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
5034 ok(status == 0xdeadbeef, "got %d\n", status);
5036 state = -1;
5037 hr = IXMLHttpRequest_get_readyState(xhr, &state);
5038 EXPECT_HR(hr, S_OK);
5039 ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state);
5041 hr = IXMLHttpRequest_abort(xhr);
5042 EXPECT_HR(hr, S_OK);
5044 state = -1;
5045 hr = IXMLHttpRequest_get_readyState(xhr, &state);
5046 EXPECT_HR(hr, S_OK);
5047 ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win2k */,
5048 "got %d, expected READYSTATE_UNINITIALIZED\n", state);
5050 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), _bstr_(urlA), async, dummy, dummy);
5051 EXPECT_HR(hr, S_OK);
5053 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
5054 EXPECT_HR(hr, S_OK);
5056 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
5057 EXPECT_HR(hr, E_INVALIDARG);
5059 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_(""), _bstr_("value1"));
5060 EXPECT_HR(hr, E_INVALIDARG);
5062 V_VT(&varbody) = VT_BSTR;
5063 V_BSTR(&varbody) = _bstr_(bodyA);
5065 hr = IXMLHttpRequest_send(xhr, varbody);
5066 if (hr == INET_E_RESOURCE_NOT_FOUND)
5068 skip("No connection could be made with crossover.codeweavers.com\n");
5069 IXMLHttpRequest_Release(xhr);
5070 return;
5072 EXPECT_HR(hr, S_OK);
5074 /* response headers */
5075 hr = IXMLHttpRequest_getAllResponseHeaders(xhr, NULL);
5076 EXPECT_HR(hr, E_INVALIDARG);
5077 hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str);
5078 EXPECT_HR(hr, S_OK);
5079 /* status line is stripped already */
5080 ok(memcmp(str, _bstr_("HTTP"), 4*sizeof(WCHAR)), "got response headers %s\n", wine_dbgstr_w(str));
5081 ok(*str, "got empty headers\n");
5082 hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str1);
5083 EXPECT_HR(hr, S_OK);
5084 ok(str1 != str, "got %p\n", str1);
5085 SysFreeString(str1);
5086 SysFreeString(str);
5088 hr = IXMLHttpRequest_getResponseHeader(xhr, NULL, NULL);
5089 EXPECT_HR(hr, E_INVALIDARG);
5090 hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), NULL);
5091 EXPECT_HR(hr, E_INVALIDARG);
5092 hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), &str);
5093 EXPECT_HR(hr, S_OK);
5094 ok(*str != ' ', "got leading space in header %s\n", wine_dbgstr_w(str));
5095 SysFreeString(str);
5097 /* status code after ::send() */
5098 status = 0xdeadbeef;
5099 hr = IXMLHttpRequest_get_status(xhr, &status);
5100 EXPECT_HR(hr, S_OK);
5101 ok(status == 200, "got %d\n", status);
5103 hr = IXMLHttpRequest_get_statusText(xhr, NULL);
5104 EXPECT_HR(hr, E_INVALIDARG);
5106 hr = IXMLHttpRequest_get_statusText(xhr, &str);
5107 EXPECT_HR(hr, S_OK);
5108 ok(!lstrcmpW(str, _bstr_("OK")), "got status %s\n", wine_dbgstr_w(str));
5109 SysFreeString(str);
5111 /* another ::send() after completed request */
5112 V_VT(&varbody) = VT_BSTR;
5113 V_BSTR(&varbody) = _bstr_(bodyA);
5115 hr = IXMLHttpRequest_send(xhr, varbody);
5116 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
5118 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
5119 EXPECT_HR(hr, S_OK);
5120 /* the server currently returns "FAILED" because the Content-Type header is
5121 * not what the server expects */
5122 if(hr == S_OK)
5124 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)),
5125 "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse));
5126 SysFreeString(bstrResponse);
5129 /* POST: VT_VARIANT|VT_BYREF body */
5130 V_VT(&varbody_ref) = VT_VARIANT|VT_BYREF;
5131 V_VARIANTREF(&varbody_ref) = &varbody;
5132 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), _bstr_(urlA), async, dummy, dummy);
5133 EXPECT_HR(hr, S_OK);
5134 hr = IXMLHttpRequest_send(xhr, varbody_ref);
5135 EXPECT_HR(hr, S_OK);
5137 /* GET request */
5138 hr = IXMLHttpRequest_open(xhr, _bstr_("GET"), _bstr_(xmltestA), async, dummy, dummy);
5139 EXPECT_HR(hr, S_OK);
5141 V_VT(&varbody) = VT_EMPTY;
5143 hr = IXMLHttpRequest_send(xhr, varbody);
5144 if (hr == INET_E_RESOURCE_NOT_FOUND)
5146 skip("No connection could be made with crossover.codeweavers.com\n");
5147 IXMLHttpRequest_Release(xhr);
5148 return;
5150 EXPECT_HR(hr, S_OK);
5152 hr = IXMLHttpRequest_get_responseText(xhr, NULL);
5153 EXPECT_HR(hr, E_INVALIDARG);
5155 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
5156 EXPECT_HR(hr, S_OK);
5157 ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
5158 "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
5159 SysFreeString(bstrResponse);
5161 hr = IXMLHttpRequest_get_responseBody(xhr, NULL);
5162 EXPECT_HR(hr, E_INVALIDARG);
5164 V_VT(&varbody) = VT_EMPTY;
5165 hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
5166 EXPECT_HR(hr, S_OK);
5167 ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
5168 ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
5170 bound = -1;
5171 hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
5172 EXPECT_HR(hr, S_OK);
5173 ok(bound == 0, "got %d, expected zero bound\n", bound);
5175 hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
5176 EXPECT_HR(hr, S_OK);
5177 ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrong body data\n");
5178 SafeArrayUnaccessData(V_ARRAY(&varbody));
5180 VariantClear(&varbody);
5182 /* get_responseStream */
5183 hr = IXMLHttpRequest_get_responseStream(xhr, NULL);
5184 EXPECT_HR(hr, E_INVALIDARG);
5186 V_VT(&varbody) = VT_EMPTY;
5187 hr = IXMLHttpRequest_get_responseStream(xhr, &varbody);
5188 ok(V_VT(&varbody) == VT_UNKNOWN, "got type %d\n", V_VT(&varbody));
5189 EXPECT_HR(hr, S_OK);
5190 EXPECT_REF(V_UNKNOWN(&varbody), 1);
5192 g = NULL;
5193 hr = GetHGlobalFromStream((IStream*)V_UNKNOWN(&varbody), &g);
5194 EXPECT_HR(hr, S_OK);
5195 ok(g != NULL, "got %p\n", g);
5197 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectSafety, (void**)&safety);
5198 EXPECT_HR(hr, S_OK);
5199 if(hr == S_OK)
5201 test_IObjectSafety_common(safety);
5202 IObjectSafety_Release(safety);
5205 IDispatch_Release(event);
5207 /* interaction with object site */
5208 EXPECT_REF(xhr, 1);
5209 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site);
5210 EXPECT_HR(hr, S_OK);
5211 todo_wine {
5212 EXPECT_REF(xhr, 1);
5213 EXPECT_REF(obj_site, 1);
5216 IObjectWithSite_AddRef(obj_site);
5217 todo_wine {
5218 EXPECT_REF(obj_site, 2);
5219 EXPECT_REF(xhr, 1);
5221 IObjectWithSite_Release(obj_site);
5223 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site2);
5224 EXPECT_HR(hr, S_OK);
5225 todo_wine {
5226 EXPECT_REF(xhr, 1);
5227 EXPECT_REF(obj_site, 1);
5228 EXPECT_REF(obj_site2, 1);
5229 ok(obj_site != obj_site2, "expected new instance\n");
5231 SET_EXPECT(site_qi_IServiceProvider);
5232 SET_EXPECT(sp_queryservice_SID_SBindHost);
5233 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
5234 SET_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
5235 SET_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
5236 SET_EXPECT(sp_queryservice_SID_secmgr_secmgr);
5238 /* calls to IHTMLDocument2 */
5239 SET_EXPECT(htmldoc2_get_all);
5240 SET_EXPECT(collection_get_length);
5241 SET_EXPECT(htmldoc2_get_url);
5243 SET_EXPECT(site_qi_IXMLDOMDocument);
5244 SET_EXPECT(site_qi_IOleClientSite);
5246 hr = IObjectWithSite_SetSite(obj_site, &testsite.IUnknown_iface);
5247 EXPECT_HR(hr, S_OK);
5249 CHECK_CALLED(site_qi_IServiceProvider);
5250 todo_wine
5251 CHECK_CALLED(sp_queryservice_SID_SBindHost);
5252 CHECK_CALLED(sp_queryservice_SID_SContainerDispatch_htmldoc2);
5253 todo_wine {
5254 CHECK_CALLED(sp_queryservice_SID_secmgr_htmldoc2);
5255 CHECK_CALLED(sp_queryservice_SID_secmgr_xmldomdoc);
5256 /* this one isn't very reliable
5257 CHECK_CALLED(sp_queryservice_SID_secmgr_secmgr); */
5259 CHECK_CALLED(htmldoc2_get_all);
5260 CHECK_CALLED(collection_get_length);
5261 CHECK_CALLED(htmldoc2_get_url);
5263 CHECK_CALLED(site_qi_IXMLDOMDocument);
5264 CHECK_CALLED(site_qi_IOleClientSite);
5266 IObjectWithSite_Release(obj_site);
5268 /* try to set site another time */
5270 /* to be removed once IObjectWithSite is properly separated */
5271 SET_EXPECT(site_qi_IServiceProvider);
5272 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
5274 hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
5275 EXPECT_HR(hr, S_OK);
5277 todo_wine EXPECT_REF(xhr, 1);
5278 IXMLHttpRequest_Release(xhr);
5280 /* still works after request is released */
5282 /* to be removed once IObjectWithSite is properly separated */
5283 SET_EXPECT(site_qi_IServiceProvider);
5284 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
5286 hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
5287 EXPECT_HR(hr, S_OK);
5288 IObjectWithSite_Release(obj_site2);
5290 free_bstrs();
5293 static void test_IXMLDOMDocument2(void)
5295 static const WCHAR emptyW[] = {0};
5296 IXMLDOMDocument2 *doc2, *dtddoc2;
5297 IXMLDOMDocument *doc;
5298 IXMLDOMParseError* err;
5299 IDispatchEx *dispex;
5300 VARIANT_BOOL b;
5301 VARIANT var;
5302 HRESULT r;
5303 LONG res;
5305 doc = create_document(&IID_IXMLDOMDocument);
5306 if (!doc) return;
5308 dtddoc2 = create_document(&IID_IXMLDOMDocument2);
5309 if (!dtddoc2)
5311 IXMLDOMDocument_Release(doc);
5312 return;
5315 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
5316 ok( r == S_OK, "ret %08x\n", r );
5317 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
5319 ole_expect(IXMLDOMDocument2_get_readyState(doc2, NULL), E_INVALIDARG);
5320 ole_check(IXMLDOMDocument2_get_readyState(doc2, &res));
5321 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
5323 err = NULL;
5324 ole_expect(IXMLDOMDocument2_validate(doc2, NULL), S_FALSE);
5325 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
5326 ok(err != NULL, "expected a pointer\n");
5327 if (err)
5329 res = 0;
5330 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5331 /* XML_E_NOTWF */
5332 ok(res == E_XML_NOTWF, "got %08x\n", res);
5333 IXMLDOMParseError_Release(err);
5336 r = IXMLDOMDocument_loadXML( doc2, _bstr_(complete4A), &b );
5337 ok( r == S_OK, "loadXML failed\n");
5338 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5340 ole_check(IXMLDOMDocument2_get_readyState(doc, &res));
5341 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
5343 err = NULL;
5344 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
5345 ok(err != NULL, "expected a pointer\n");
5346 if (err)
5348 res = 0;
5349 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5350 /* XML_E_NODTD */
5351 ok(res == E_XML_NODTD, "got %08x\n", res);
5352 IXMLDOMParseError_Release(err);
5355 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
5356 ok( r == S_OK, "ret %08x\n", r );
5357 if(r == S_OK)
5359 IDispatchEx_Release(dispex);
5362 /* we will check if the variant got cleared */
5363 IXMLDOMDocument2_AddRef(doc2);
5364 EXPECT_REF(doc2, 3); /* doc, doc2, AddRef*/
5366 V_VT(&var) = VT_UNKNOWN;
5367 V_UNKNOWN(&var) = (IUnknown *)doc2;
5369 /* invalid calls */
5370 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
5371 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
5372 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
5374 /* valid call */
5375 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
5376 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
5377 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
5378 V_VT(&var) = VT_R4;
5380 /* the variant didn't get cleared*/
5381 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
5383 /* setProperty tests */
5384 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
5385 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
5386 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
5387 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
5388 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5389 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
5391 V_VT(&var) = VT_BSTR;
5392 V_BSTR(&var) = SysAllocString(emptyW);
5393 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
5394 ok(r == S_OK, "got 0x%08x\n", r);
5395 VariantClear(&var);
5397 V_VT(&var) = VT_I2;
5398 V_I2(&var) = 0;
5399 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
5400 ok(r == E_FAIL, "got 0x%08x\n", r);
5402 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
5403 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
5404 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
5405 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
5407 IXMLDOMDocument2_Release( doc2 );
5408 IXMLDOMDocument_Release( doc );
5410 /* DTD validation */
5411 ole_check(IXMLDOMDocument2_put_validateOnParse(dtddoc2, VARIANT_FALSE));
5412 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML), &b));
5413 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5414 err = NULL;
5415 ole_check(IXMLDOMDocument2_validate(dtddoc2, &err));
5416 ok(err != NULL, "expected pointer\n");
5417 if (err)
5419 res = 0;
5420 ole_expect(IXMLDOMParseError_get_errorCode(err, &res), S_FALSE);
5421 ok(res == 0, "got %08x\n", res);
5422 IXMLDOMParseError_Release(err);
5425 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0D), &b));
5426 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5427 err = NULL;
5428 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5429 ok(err != NULL, "expected pointer\n");
5430 if (err)
5432 res = 0;
5433 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5434 /* XML_ELEMENT_UNDECLARED */
5435 todo_wine ok(res == 0xC00CE00D, "got %08x\n", res);
5436 IXMLDOMParseError_Release(err);
5439 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0E), &b));
5440 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5441 err = NULL;
5442 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5443 ok(err != NULL, "expected pointer\n");
5444 if (err)
5446 res = 0;
5447 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5448 /* XML_ELEMENT_ID_NOT_FOUND */
5449 todo_wine ok(res == 0xC00CE00E, "got %08x\n", res);
5450 IXMLDOMParseError_Release(err);
5453 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_11), &b));
5454 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5455 err = NULL;
5456 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5457 ok(err != NULL, "expected pointer\n");
5458 if (err)
5460 res = 0;
5461 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5462 /* XML_EMPTY_NOT_ALLOWED */
5463 todo_wine ok(res == 0xC00CE011, "got %08x\n", res);
5464 IXMLDOMParseError_Release(err);
5467 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_13), &b));
5468 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5469 err = NULL;
5470 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5471 ok(err != NULL, "expected pointer\n");
5472 if (err)
5474 res = 0;
5475 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5476 /* XML_ROOT_NAME_MISMATCH */
5477 todo_wine ok(res == 0xC00CE013, "got %08x\n", res);
5478 IXMLDOMParseError_Release(err);
5481 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_14), &b));
5482 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5483 err = NULL;
5484 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5485 ok(err != NULL, "expected pointer\n");
5486 if (err)
5488 res = 0;
5489 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5490 /* XML_INVALID_CONTENT */
5491 todo_wine ok(res == 0xC00CE014, "got %08x\n", res);
5492 IXMLDOMParseError_Release(err);
5495 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_15), &b));
5496 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5497 err = NULL;
5498 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5499 ok(err != NULL, "expected pointer\n");
5500 if (err)
5502 res = 0;
5503 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5504 /* XML_ATTRIBUTE_NOT_DEFINED */
5505 todo_wine ok(res == 0xC00CE015, "got %08x\n", res);
5506 IXMLDOMParseError_Release(err);
5509 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_16), &b));
5510 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5511 err = NULL;
5512 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5513 ok(err != NULL, "expected pointer\n");
5514 if (err)
5516 res = 0;
5517 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5518 /* XML_ATTRIBUTE_FIXED */
5519 todo_wine ok(res == 0xC00CE016, "got %08x\n", res);
5520 IXMLDOMParseError_Release(err);
5523 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_17), &b));
5524 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5525 err = NULL;
5526 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5527 ok(err != NULL, "expected pointer\n");
5528 if (err)
5530 res = 0;
5531 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5532 /* XML_ATTRIBUTE_VALUE */
5533 todo_wine ok(res == 0xC00CE017, "got %08x\n", res);
5534 IXMLDOMParseError_Release(err);
5537 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_18), &b));
5538 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5539 err = NULL;
5540 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5541 ok(err != NULL, "expected pointer\n");
5542 if (err)
5544 res = 0;
5545 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5546 /* XML_ILLEGAL_TEXT */
5547 todo_wine ok(res == 0xC00CE018, "got %08x\n", res);
5548 IXMLDOMParseError_Release(err);
5551 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_20), &b));
5552 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5553 err = NULL;
5554 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5555 ok(err != NULL, "expected pointer\n");
5556 if (err)
5558 res = 0;
5559 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5560 /* XML_REQUIRED_ATTRIBUTE_MISSING */
5561 todo_wine ok(res == 0xC00CE020, "got %08x\n", res);
5562 IXMLDOMParseError_Release(err);
5565 IXMLDOMDocument2_Release( dtddoc2 );
5566 free_bstrs();
5569 #define helper_ole_check(expr) { \
5570 HRESULT r = expr; \
5571 ok_(__FILE__, line)(r == S_OK, "=> %i: " #expr " returned %08x\n", __LINE__, r); \
5574 #define helper_expect_list_and_release(list, expstr) { \
5575 char *str = list_to_string(list); \
5576 ok_(__FILE__, line)(strcmp(str, expstr)==0, "=> %i: Invalid node list: %s, expected %s\n", __LINE__, str, expstr); \
5577 if (list) IXMLDOMNodeList_Release(list); \
5580 #define helper_expect_bstr_and_release(bstr, str) { \
5581 ok_(__FILE__, line)(lstrcmpW(bstr, _bstr_(str)) == 0, \
5582 "=> %i: got %s\n", __LINE__, wine_dbgstr_w(bstr)); \
5583 SysFreeString(bstr); \
5586 #define check_ws_ignored(doc, str) _check_ws_ignored(__LINE__, doc, str)
5587 static inline void _check_ws_ignored(int line, IXMLDOMDocument2* doc, char const* str)
5589 IXMLDOMNode *node1, *node2;
5590 IXMLDOMNodeList *list;
5591 BSTR bstr;
5593 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
5594 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
5595 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
5596 helper_ole_check(IXMLDOMNodeList_reset(list));
5597 helper_expect_list_and_release(list, "E1.E5.E1.E2.D1 E2.E5.E1.E2.D1");
5599 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
5600 helper_expect_list_and_release(list, "T1.E1.E5.E1.E2.D1 E2.E1.E5.E1.E2.D1 E3.E1.E5.E1.E2.D1 T4.E1.E5.E1.E2.D1 E5.E1.E5.E1.E2.D1");
5601 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
5602 if (str)
5604 helper_expect_bstr_and_release(bstr, str);
5606 else
5608 helper_expect_bstr_and_release(bstr, "This is a description.");
5610 IXMLDOMNode_Release(node1);
5612 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
5613 helper_expect_list_and_release(list, "T1.E2.E5.E1.E2.D1 E2.E2.E5.E1.E2.D1 T3.E2.E5.E1.E2.D1 E4.E2.E5.E1.E2.D1 T5.E2.E5.E1.E2.D1 E6.E2.E5.E1.E2.D1 T7.E2.E5.E1.E2.D1");
5614 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
5615 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
5616 IXMLDOMNode_Release(node2);
5619 #define check_ws_preserved(doc, str) _check_ws_preserved(__LINE__, doc, str)
5620 static inline void _check_ws_preserved(int line, IXMLDOMDocument2* doc, char const* str)
5622 IXMLDOMNode *node1, *node2;
5623 IXMLDOMNodeList *list;
5624 BSTR bstr;
5626 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
5627 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
5628 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
5629 helper_ole_check(IXMLDOMNodeList_reset(list));
5630 helper_expect_list_and_release(list, "E2.E10.E2.E2.D1 E4.E10.E2.E2.D1");
5632 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
5633 helper_expect_list_and_release(list, "T1.E2.E10.E2.E2.D1 E2.E2.E10.E2.E2.D1 T3.E2.E10.E2.E2.D1 E4.E2.E10.E2.E2.D1 T5.E2.E10.E2.E2.D1 E6.E2.E10.E2.E2.D1 T7.E2.E10.E2.E2.D1");
5634 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
5635 if (str)
5637 helper_expect_bstr_and_release(bstr, str);
5639 else
5641 helper_expect_bstr_and_release(bstr, "\n This is a description. \n ");
5643 IXMLDOMNode_Release(node1);
5645 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
5646 helper_expect_list_and_release(list, "T1.E4.E10.E2.E2.D1 E2.E4.E10.E2.E2.D1 T3.E4.E10.E2.E2.D1 E4.E4.E10.E2.E2.D1 T5.E4.E10.E2.E2.D1 E6.E4.E10.E2.E2.D1 T7.E4.E10.E2.E2.D1");
5647 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
5648 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
5649 IXMLDOMNode_Release(node2);
5652 static void test_whitespace(void)
5654 VARIANT_BOOL b;
5655 IXMLDOMDocument2 *doc1, *doc2, *doc3, *doc4;
5657 doc1 = create_document(&IID_IXMLDOMDocument2);
5658 doc2 = create_document(&IID_IXMLDOMDocument2);
5659 if (!doc1 || !doc2) return;
5661 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_TRUE));
5662 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
5663 ok(b == VARIANT_FALSE, "expected false\n");
5664 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
5665 ok(b == VARIANT_TRUE, "expected true\n");
5667 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
5668 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5669 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
5670 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5672 /* switch to XPath */
5673 ole_check(IXMLDOMDocument2_setProperty(doc1, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5674 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5676 check_ws_ignored(doc1, NULL);
5677 check_ws_preserved(doc2, NULL);
5679 /* new instances copy the property */
5680 ole_check(IXMLDOMDocument2_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**) &doc3));
5681 ole_check(IXMLDOMDocument2_QueryInterface(doc2, &IID_IXMLDOMDocument2, (void**) &doc4));
5683 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
5684 ok(b == VARIANT_FALSE, "expected false\n");
5685 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
5686 ok(b == VARIANT_TRUE, "expected true\n");
5688 check_ws_ignored(doc3, NULL);
5689 check_ws_preserved(doc4, NULL);
5691 /* setting after loading xml affects trimming of leading/trailing ws only */
5692 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_TRUE));
5693 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_FALSE));
5695 /* the trailing "\n " isn't there, because it was ws-only node */
5696 check_ws_ignored(doc1, "\n This is a description. ");
5697 check_ws_preserved(doc2, "This is a description.");
5699 /* it takes effect on reload */
5700 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
5701 ok(b == VARIANT_TRUE, "expected true\n");
5702 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
5703 ok(b == VARIANT_FALSE, "expected false\n");
5705 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
5706 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5707 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
5708 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5710 check_ws_preserved(doc1, NULL);
5711 check_ws_ignored(doc2, NULL);
5713 /* other instances follow suit */
5714 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
5715 ok(b == VARIANT_TRUE, "expected true\n");
5716 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
5717 ok(b == VARIANT_FALSE, "expected false\n");
5719 check_ws_preserved(doc3, NULL);
5720 check_ws_ignored(doc4, NULL);
5722 IXMLDOMDocument_Release(doc1);
5723 IXMLDOMDocument_Release(doc2);
5724 IXMLDOMDocument_Release(doc3);
5725 IXMLDOMDocument_Release(doc4);
5726 free_bstrs();
5729 typedef struct {
5730 const GUID *clsid;
5731 const char *name;
5732 const char *ns;
5733 HRESULT hr;
5734 } selection_ns_t;
5736 /* supposed to be tested with szExampleXML */
5737 static const selection_ns_t selection_ns_data[] = {
5738 { &CLSID_DOMDocument, "CLSID_DOMDocument", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5739 { &CLSID_DOMDocument, "CLSID_DOMDocument", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5740 { &CLSID_DOMDocument, "CLSID_DOMDocument", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5741 { &CLSID_DOMDocument, "CLSID_DOMDocument", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
5743 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5744 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5745 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5746 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
5748 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5749 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5750 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5751 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
5753 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5754 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5755 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5756 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
5758 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5759 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5760 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
5761 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
5763 { NULL }
5766 static void test_XPath(void)
5768 const selection_ns_t *ptr = selection_ns_data;
5769 VARIANT var;
5770 VARIANT_BOOL b;
5771 IXMLDOMDocument2 *doc;
5772 IXMLDOMDocument *doc2;
5773 IXMLDOMNode *rootNode;
5774 IXMLDOMNode *elem1Node;
5775 IXMLDOMNode *node;
5776 IXMLDOMNodeList *list;
5777 IXMLDOMElement *elem;
5778 IXMLDOMAttribute *attr;
5779 DOMNodeType type;
5780 HRESULT hr;
5781 LONG len;
5782 BSTR str;
5784 doc = create_document(&IID_IXMLDOMDocument2);
5785 if (!doc) return;
5787 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
5788 EXPECT_HR(hr, S_OK);
5789 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5791 /* switch to XPath */
5792 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5794 /* some simple queries*/
5795 EXPECT_REF(doc, 1);
5796 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5797 EXPECT_HR(hr, S_OK);
5798 EXPECT_REF(doc, 1);
5799 EXPECT_LIST_LEN(list, 1);
5801 EXPECT_REF(list, 1);
5802 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5803 EXPECT_HR(hr, S_OK);
5804 EXPECT_REF(list, 1);
5805 EXPECT_REF(rootNode, 1);
5807 hr = IXMLDOMNodeList_reset(list);
5808 EXPECT_HR(hr, S_OK);
5809 expect_list_and_release(list, "E2.D1");
5811 if (0)
5813 /* namespace:: axis test is disabled until namespace definitions
5814 are supported as attribute nodes, currently it's another node type */
5815 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("/root/namespace::*"), &list);
5816 EXPECT_HR(hr, S_OK);
5817 len = -1;
5818 hr = IXMLDOMNodeList_get_length(list, &len);
5819 EXPECT_HR(hr, S_OK);
5820 ok(len == 2, "got %d\n", len);
5822 hr = IXMLDOMNodeList_nextNode(list, &node);
5823 EXPECT_HR(hr, S_OK);
5824 type = NODE_INVALID;
5825 hr = IXMLDOMNode_get_nodeType(node, &type);
5826 EXPECT_HR(hr, S_OK);
5827 ok(type == NODE_ATTRIBUTE, "got %d\n", type);
5828 IXMLDOMNode_Release(node);
5830 IXMLDOMNodeList_Release(list);
5833 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//c"), &list));
5834 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
5836 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//c[@type]"), &list));
5837 expect_list_and_release(list, "E3.E2.E2.D1");
5839 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
5840 /* using get_item for query results advances the position */
5841 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
5842 expect_node(node, "E2.E2.D1");
5843 IXMLDOMNode_Release(node);
5844 ole_check(IXMLDOMNodeList_nextNode(list, &node));
5845 expect_node(node, "E4.E2.D1");
5846 IXMLDOMNode_Release(node);
5847 ole_check(IXMLDOMNodeList_reset(list));
5848 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
5850 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
5851 expect_list_and_release(list, "E2.D1");
5853 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
5854 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
5855 ole_check(IXMLDOMNodeList_reset(list));
5856 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
5858 /* select an attribute */
5859 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
5860 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
5862 /* would evaluate to a number */
5863 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
5864 /* would evaluate to a boolean */
5865 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
5866 /* would evaluate to a string */
5867 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
5869 /* no results */
5870 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
5871 expect_list_and_release(list, "");
5872 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
5873 expect_list_and_release(list, "");
5874 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
5875 expect_list_and_release(list, "");
5876 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//elem[0]"), &list));
5877 expect_list_and_release(list, "");
5879 /* foo undeclared in document node */
5880 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5881 /* undeclared in <root> node */
5882 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
5883 /* undeclared in <elem> node */
5884 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
5885 /* but this trick can be used */
5886 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
5887 expect_list_and_release(list, "E3.E4.E2.D1");
5889 /* it has to be declared in SelectionNamespaces */
5890 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5891 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
5893 /* now the namespace can be used */
5894 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//test:c"), &list));
5895 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5896 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
5897 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5898 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
5899 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5900 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
5901 expect_list_and_release(list, "E5.E1.E5.E1.E2.D1 E6.E2.E5.E1.E2.D1");
5903 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
5904 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5905 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
5907 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5909 VariantInit(&var);
5910 ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
5911 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
5912 if (V_VT(&var) == VT_BSTR)
5913 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
5915 /* extra attributes - same thing*/
5916 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5917 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
5918 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5920 IXMLDOMNode_Release(rootNode);
5921 IXMLDOMNode_Release(elem1Node);
5923 /* alter document with already built list */
5924 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5925 EXPECT_HR(hr, S_OK);
5926 EXPECT_LIST_LEN(list, 1);
5928 hr = IXMLDOMDocument2_get_lastChild(doc, &rootNode);
5929 EXPECT_HR(hr, S_OK);
5930 EXPECT_REF(rootNode, 1);
5931 EXPECT_REF(doc, 1);
5933 hr = IXMLDOMDocument2_removeChild(doc, rootNode, NULL);
5934 EXPECT_HR(hr, S_OK);
5935 IXMLDOMNode_Release(rootNode);
5937 EXPECT_LIST_LEN(list, 1);
5939 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5940 EXPECT_HR(hr, S_OK);
5941 EXPECT_REF(rootNode, 1);
5943 IXMLDOMNodeList_Release(list);
5945 hr = IXMLDOMNode_get_nodeName(rootNode, &str);
5946 EXPECT_HR(hr, S_OK);
5947 ok(!lstrcmpW(str, _bstr_("root")), "got %s\n", wine_dbgstr_w(str));
5948 SysFreeString(str);
5949 IXMLDOMNode_Release(rootNode);
5951 /* alter node from list and get it another time */
5952 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
5953 EXPECT_HR(hr, S_OK);
5954 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5956 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5957 EXPECT_HR(hr, S_OK);
5958 EXPECT_LIST_LEN(list, 1);
5960 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5961 EXPECT_HR(hr, S_OK);
5963 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
5964 EXPECT_HR(hr, S_OK);
5966 V_VT(&var) = VT_I2;
5967 V_I2(&var) = 1;
5968 hr = IXMLDOMElement_setAttribute(elem, _bstr_("attrtest"), var);
5969 EXPECT_HR(hr, S_OK);
5970 IXMLDOMElement_Release(elem);
5971 IXMLDOMNode_Release(rootNode);
5973 /* now check attribute to be present */
5974 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5975 EXPECT_HR(hr, S_OK);
5977 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
5978 EXPECT_HR(hr, S_OK);
5980 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
5981 EXPECT_HR(hr, S_OK);
5982 IXMLDOMAttribute_Release(attr);
5984 IXMLDOMElement_Release(elem);
5985 IXMLDOMNode_Release(rootNode);
5987 /* and now check for attribute in original document */
5988 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
5989 EXPECT_HR(hr, S_OK);
5991 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
5992 EXPECT_HR(hr, S_OK);
5993 IXMLDOMAttribute_Release(attr);
5995 IXMLDOMElement_Release(elem);
5997 /* attach node from list to another document */
5998 doc2 = create_document(&IID_IXMLDOMDocument);
6000 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
6001 EXPECT_HR(hr, S_OK);
6002 ok(b == VARIANT_TRUE, "failed to load XML string\n");
6004 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
6005 EXPECT_HR(hr, S_OK);
6006 EXPECT_LIST_LEN(list, 1);
6008 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
6009 EXPECT_HR(hr, S_OK);
6010 EXPECT_REF(rootNode, 1);
6012 hr = IXMLDOMDocument_appendChild(doc2, rootNode, NULL);
6013 EXPECT_HR(hr, S_OK);
6014 EXPECT_REF(rootNode, 1);
6015 EXPECT_REF(doc2, 1);
6016 EXPECT_REF(list, 1);
6018 EXPECT_LIST_LEN(list, 1);
6020 IXMLDOMNode_Release(rootNode);
6021 IXMLDOMNodeList_Release(list);
6022 IXMLDOMDocument_Release(doc2);
6023 IXMLDOMDocument2_Release(doc);
6025 while (ptr->clsid)
6027 hr = CoCreateInstance(ptr->clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
6028 if (hr != S_OK)
6030 win_skip("can't create instance of %s\n", ptr->name);
6031 ptr++;
6032 continue;
6035 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
6036 EXPECT_HR(hr, S_OK);
6037 ok(b == VARIANT_TRUE, "failed to load, %s\n", ptr->name);
6039 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath"));
6040 EXPECT_HR(hr, S_OK);
6042 V_VT(&var) = VT_BSTR;
6043 V_BSTR(&var) = _bstr_(ptr->ns);
6045 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), var);
6046 ok(hr == ptr->hr, "got 0x%08x, for %s, %s\n", hr, ptr->name, ptr->ns);
6048 V_VT(&var) = VT_EMPTY;
6049 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var);
6050 EXPECT_HR(hr, S_OK);
6051 ok(V_VT(&var) == VT_BSTR, "got wrong property type %d\n", V_VT(&var));
6052 ok(!lstrcmpW(V_BSTR(&var), _bstr_(ptr->ns)), "got wrong value %s\n", wine_dbgstr_w(V_BSTR(&var)));
6053 VariantClear(&var);
6055 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root//test:c"), &list);
6056 EXPECT_HR(hr, S_OK);
6057 if (hr == S_OK)
6058 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
6060 IXMLDOMDocument2_Release(doc);
6061 ptr++;
6062 free_bstrs();
6065 free_bstrs();
6068 static void test_cloneNode(void )
6070 IXMLDOMDocument *doc, *doc2;
6071 VARIANT_BOOL b;
6072 IXMLDOMNodeList *pList;
6073 IXMLDOMNamedNodeMap *mapAttr;
6074 LONG length, length1;
6075 LONG attr_cnt, attr_cnt1;
6076 IXMLDOMNode *node;
6077 IXMLDOMNode *node_clone;
6078 IXMLDOMNode *node_first;
6079 HRESULT hr;
6081 doc = create_document(&IID_IXMLDOMDocument);
6082 if (!doc) return;
6084 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(complete4A), &b));
6085 ok(b == VARIANT_TRUE, "failed to load XML string\n");
6087 hr = IXMLDOMNode_selectSingleNode(doc, _bstr_("lc/pr"), &node);
6088 ok( hr == S_OK, "ret %08x\n", hr );
6089 ok( node != NULL, "node %p\n", node );
6091 /* Check invalid parameter */
6092 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
6093 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
6095 /* All Children */
6096 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
6097 ok( hr == S_OK, "ret %08x\n", hr );
6098 ok( node_clone != NULL, "node %p\n", node );
6100 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
6101 ok( hr == S_OK, "ret %08x\n", hr );
6102 hr = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
6103 ok( hr == S_OK, "ret %08x\n", hr );
6104 IXMLDOMDocument_Release(doc2);
6105 IXMLDOMNode_Release(node_first);
6107 hr = IXMLDOMNode_get_childNodes(node, &pList);
6108 ok( hr == S_OK, "ret %08x\n", hr );
6109 length = 0;
6110 hr = IXMLDOMNodeList_get_length(pList, &length);
6111 ok( hr == S_OK, "ret %08x\n", hr );
6112 ok(length == 1, "got %d\n", length);
6113 IXMLDOMNodeList_Release(pList);
6115 hr = IXMLDOMNode_get_attributes(node, &mapAttr);
6116 ok( hr == S_OK, "ret %08x\n", hr );
6117 attr_cnt = 0;
6118 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt);
6119 ok( hr == S_OK, "ret %08x\n", hr );
6120 ok(attr_cnt == 3, "got %d\n", attr_cnt);
6121 IXMLDOMNamedNodeMap_Release(mapAttr);
6123 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
6124 ok( hr == S_OK, "ret %08x\n", hr );
6125 length1 = 0;
6126 hr = IXMLDOMNodeList_get_length(pList, &length1);
6127 ok(length1 == 1, "got %d\n", length1);
6128 ok( hr == S_OK, "ret %08x\n", hr );
6129 IXMLDOMNodeList_Release(pList);
6131 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
6132 ok( hr == S_OK, "ret %08x\n", hr );
6133 attr_cnt1 = 0;
6134 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
6135 ok( hr == S_OK, "ret %08x\n", hr );
6136 ok(attr_cnt1 == 3, "got %d\n", attr_cnt1);
6137 IXMLDOMNamedNodeMap_Release(mapAttr);
6139 ok(length == length1, "wrong Child count (%d, %d)\n", length, length1);
6140 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
6141 IXMLDOMNode_Release(node_clone);
6143 /* No Children */
6144 hr = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
6145 ok( hr == S_OK, "ret %08x\n", hr );
6146 ok( node_clone != NULL, "node %p\n", node );
6148 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
6149 ok(hr == S_FALSE, "ret %08x\n", hr );
6151 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
6152 ok(hr == S_OK, "ret %08x\n", hr );
6153 hr = IXMLDOMNodeList_get_length(pList, &length1);
6154 ok(hr == S_OK, "ret %08x\n", hr );
6155 ok( length1 == 0, "Length should be 0 (%d)\n", length1);
6156 IXMLDOMNodeList_Release(pList);
6158 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
6159 ok(hr == S_OK, "ret %08x\n", hr );
6160 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
6161 ok(hr == S_OK, "ret %08x\n", hr );
6162 ok(attr_cnt1 == 3, "Attribute count should be 3 (%d)\n", attr_cnt1);
6163 IXMLDOMNamedNodeMap_Release(mapAttr);
6165 ok(length != length1, "wrong Child count (%d, %d)\n", length, length1);
6166 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
6167 IXMLDOMNode_Release(node_clone);
6169 IXMLDOMNode_Release(node);
6170 IXMLDOMDocument_Release(doc);
6171 free_bstrs();
6174 static void test_xmlTypes(void)
6176 IXMLDOMDocument *doc;
6177 IXMLDOMElement *pRoot;
6178 HRESULT hr;
6179 IXMLDOMComment *pComment;
6180 IXMLDOMElement *pElement;
6181 IXMLDOMAttribute *pAttribute;
6182 IXMLDOMNamedNodeMap *pAttribs;
6183 IXMLDOMCDATASection *pCDataSec;
6184 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
6185 IXMLDOMDocumentFragment *pDocFrag = NULL;
6186 IXMLDOMEntityReference *pEntityRef = NULL;
6187 BSTR str;
6188 IXMLDOMNode *pNextChild;
6189 VARIANT v;
6190 LONG len = 0;
6192 doc = create_document(&IID_IXMLDOMDocument);
6193 if (!doc) return;
6195 pNextChild = (void*)0xdeadbeef;
6196 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
6197 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6199 pNextChild = (void*)0xdeadbeef;
6200 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
6201 ok(hr == S_FALSE, "ret %08x\n", hr );
6202 ok(pNextChild == NULL, "pDocChild not NULL\n");
6204 /* test previous Sibling */
6205 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
6206 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6208 pNextChild = (void*)0xdeadbeef;
6209 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
6210 ok(hr == S_FALSE, "ret %08x\n", hr );
6211 ok(pNextChild == NULL, "pNextChild not NULL\n");
6213 /* test get_dataType */
6214 V_VT(&v) = VT_EMPTY;
6215 hr = IXMLDOMDocument_get_dataType(doc, &v);
6216 ok(hr == S_FALSE, "ret %08x\n", hr );
6217 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
6218 VariantClear(&v);
6220 /* test implementation */
6221 hr = IXMLDOMDocument_get_implementation(doc, NULL);
6222 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6224 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
6225 ok(hr == S_OK, "ret %08x\n", hr );
6226 if(hr == S_OK)
6228 VARIANT_BOOL hasFeature = VARIANT_TRUE;
6229 BSTR sEmpty = SysAllocStringLen(NULL, 0);
6231 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
6232 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6234 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
6235 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6237 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
6238 ok(hr == S_OK, "ret %08x\n", hr );
6239 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
6241 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
6242 ok(hr == S_OK, "ret %08x\n", hr );
6243 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
6245 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
6246 ok(hr == S_OK, "ret %08x\n", hr );
6247 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
6249 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
6250 ok(hr == S_OK, "ret %08x\n", hr );
6251 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
6253 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
6254 ok(hr == S_OK, "ret %08x\n", hr );
6255 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
6257 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
6258 ok(hr == S_OK, "ret %08x\n", hr );
6259 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
6261 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
6262 ok(hr == S_OK, "ret %08x\n", hr );
6263 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
6265 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
6266 ok(hr == S_OK, "ret %08x\n", hr );
6267 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
6269 SysFreeString(sEmpty);
6270 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
6273 pRoot = (IXMLDOMElement*)0x1;
6274 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
6275 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6276 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
6278 pRoot = (IXMLDOMElement*)0x1;
6279 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
6280 ok(hr == E_FAIL, "ret %08x\n", hr );
6281 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
6283 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
6284 ok(hr == S_OK, "ret %08x\n", hr );
6285 if(hr == S_OK)
6287 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
6288 ok(hr == S_OK, "ret %08x\n", hr );
6289 if(hr == S_OK)
6291 /* Comment */
6292 str = SysAllocString(szComment);
6293 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
6294 SysFreeString(str);
6295 ok(hr == S_OK, "ret %08x\n", hr );
6296 if(hr == S_OK)
6298 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
6299 ok(hr == S_OK, "ret %08x\n", hr );
6301 hr = IXMLDOMComment_get_nodeName(pComment, &str);
6302 ok(hr == S_OK, "ret %08x\n", hr );
6303 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
6304 SysFreeString(str);
6306 hr = IXMLDOMComment_get_xml(pComment, &str);
6307 ok(hr == S_OK, "ret %08x\n", hr );
6308 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
6309 SysFreeString(str);
6311 /* put data Tests */
6312 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
6313 ok(hr == S_OK, "ret %08x\n", hr );
6315 /* get data Tests */
6316 hr = IXMLDOMComment_get_data(pComment, &str);
6317 ok(hr == S_OK, "ret %08x\n", hr );
6318 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
6319 SysFreeString(str);
6321 /* Confirm XML text is good */
6322 hr = IXMLDOMComment_get_xml(pComment, &str);
6323 ok(hr == S_OK, "ret %08x\n", hr );
6324 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
6325 SysFreeString(str);
6327 /* Confirm we get the put_data Text back */
6328 hr = IXMLDOMComment_get_text(pComment, &str);
6329 ok(hr == S_OK, "ret %08x\n", hr );
6330 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
6331 SysFreeString(str);
6333 /* test length property */
6334 hr = IXMLDOMComment_get_length(pComment, &len);
6335 ok(hr == S_OK, "ret %08x\n", hr );
6336 ok(len == 21, "expected 21 got %d\n", len);
6338 /* test substringData */
6339 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
6340 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6342 /* test substringData - Invalid offset */
6343 str = (BSTR)&szElement;
6344 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
6345 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6346 ok( str == NULL, "incorrect string\n");
6348 /* test substringData - Invalid offset */
6349 str = (BSTR)&szElement;
6350 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
6351 ok(hr == S_FALSE, "ret %08x\n", hr );
6352 ok( str == NULL, "incorrect string\n");
6354 /* test substringData - Invalid size */
6355 str = (BSTR)&szElement;
6356 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
6357 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6358 ok( str == NULL, "incorrect string\n");
6360 /* test substringData - Invalid size */
6361 str = (BSTR)&szElement;
6362 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
6363 ok(hr == S_FALSE, "ret %08x\n", hr );
6364 ok( str == NULL, "incorrect string\n");
6366 /* test substringData - Start of string */
6367 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
6368 ok(hr == S_OK, "ret %08x\n", hr );
6369 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
6370 SysFreeString(str);
6372 /* test substringData - Middle of string */
6373 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
6374 ok(hr == S_OK, "ret %08x\n", hr );
6375 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
6376 SysFreeString(str);
6378 /* test substringData - End of string */
6379 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
6380 ok(hr == S_OK, "ret %08x\n", hr );
6381 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
6382 SysFreeString(str);
6384 /* test appendData */
6385 hr = IXMLDOMComment_appendData(pComment, NULL);
6386 ok(hr == S_OK, "ret %08x\n", hr );
6388 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
6389 ok(hr == S_OK, "ret %08x\n", hr );
6391 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
6392 ok(hr == S_OK, "ret %08x\n", hr );
6394 hr = IXMLDOMComment_get_text(pComment, &str);
6395 ok(hr == S_OK, "ret %08x\n", hr );
6396 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6397 SysFreeString(str);
6399 /* test insertData */
6400 str = SysAllocStringLen(NULL, 0);
6401 hr = IXMLDOMComment_insertData(pComment, -1, str);
6402 ok(hr == S_OK, "ret %08x\n", hr );
6404 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
6405 ok(hr == S_OK, "ret %08x\n", hr );
6407 hr = IXMLDOMComment_insertData(pComment, 1000, str);
6408 ok(hr == S_OK, "ret %08x\n", hr );
6410 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
6411 ok(hr == S_OK, "ret %08x\n", hr );
6413 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
6414 ok(hr == S_OK, "ret %08x\n", hr );
6416 hr = IXMLDOMComment_insertData(pComment, 0, str);
6417 ok(hr == S_OK, "ret %08x\n", hr );
6418 SysFreeString(str);
6420 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
6421 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6423 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
6424 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6426 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
6427 ok(hr == S_OK, "ret %08x\n", hr );
6429 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
6430 ok(hr == S_OK, "ret %08x\n", hr );
6432 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
6433 ok(hr == S_OK, "ret %08x\n", hr );
6435 hr = IXMLDOMComment_get_text(pComment, &str);
6436 ok(hr == S_OK, "ret %08x\n", hr );
6437 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6438 SysFreeString(str);
6440 /* delete data */
6441 /* invalid arguments */
6442 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
6443 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6445 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
6446 ok(hr == S_OK, "ret %08x\n", hr );
6448 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
6449 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6451 hr = IXMLDOMComment_get_length(pComment, &len);
6452 ok(hr == S_OK, "ret %08x\n", hr );
6453 ok(len == 43, "expected 43 got %d\n", len);
6455 hr = IXMLDOMComment_deleteData(pComment, len, 1);
6456 ok(hr == S_OK, "ret %08x\n", hr );
6458 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
6459 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6461 /* delete from start */
6462 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
6463 ok(hr == S_OK, "ret %08x\n", hr );
6465 hr = IXMLDOMComment_get_length(pComment, &len);
6466 ok(hr == S_OK, "ret %08x\n", hr );
6467 ok(len == 38, "expected 38 got %d\n", len);
6469 hr = IXMLDOMComment_get_text(pComment, &str);
6470 ok(hr == S_OK, "ret %08x\n", hr );
6471 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6472 SysFreeString(str);
6474 /* delete from end */
6475 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
6476 ok(hr == S_OK, "ret %08x\n", hr );
6478 hr = IXMLDOMComment_get_length(pComment, &len);
6479 ok(hr == S_OK, "ret %08x\n", hr );
6480 ok(len == 35, "expected 35 got %d\n", len);
6482 hr = IXMLDOMComment_get_text(pComment, &str);
6483 ok(hr == S_OK, "ret %08x\n", hr );
6484 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6485 SysFreeString(str);
6487 /* delete from inside */
6488 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
6489 ok(hr == S_OK, "ret %08x\n", hr );
6491 hr = IXMLDOMComment_get_length(pComment, &len);
6492 ok(hr == S_OK, "ret %08x\n", hr );
6493 ok(len == 2, "expected 2 got %d\n", len);
6495 hr = IXMLDOMComment_get_text(pComment, &str);
6496 ok(hr == S_OK, "ret %08x\n", hr );
6497 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6498 SysFreeString(str);
6500 /* delete whole data ... */
6501 hr = IXMLDOMComment_get_length(pComment, &len);
6502 ok(hr == S_OK, "ret %08x\n", hr );
6504 hr = IXMLDOMComment_deleteData(pComment, 0, len);
6505 ok(hr == S_OK, "ret %08x\n", hr );
6506 /* ... and try again with empty string */
6507 hr = IXMLDOMComment_deleteData(pComment, 0, len);
6508 ok(hr == S_OK, "ret %08x\n", hr );
6510 /* ::replaceData() */
6511 V_VT(&v) = VT_BSTR;
6512 V_BSTR(&v) = SysAllocString(szstr1);
6513 hr = IXMLDOMComment_put_nodeValue(pComment, v);
6514 ok(hr == S_OK, "ret %08x\n", hr );
6515 VariantClear(&v);
6517 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
6518 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6519 hr = IXMLDOMComment_get_text(pComment, &str);
6520 ok(hr == S_OK, "ret %08x\n", hr );
6521 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6522 SysFreeString(str);
6524 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
6525 ok(hr == S_OK, "ret %08x\n", hr );
6526 hr = IXMLDOMComment_get_text(pComment, &str);
6527 ok(hr == S_OK, "ret %08x\n", hr );
6528 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6529 SysFreeString(str);
6531 /* NULL pointer means delete */
6532 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
6533 ok(hr == S_OK, "ret %08x\n", hr );
6534 hr = IXMLDOMComment_get_text(pComment, &str);
6535 ok(hr == S_OK, "ret %08x\n", hr );
6536 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6537 SysFreeString(str);
6539 /* empty string means delete */
6540 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
6541 ok(hr == S_OK, "ret %08x\n", hr );
6542 hr = IXMLDOMComment_get_text(pComment, &str);
6543 ok(hr == S_OK, "ret %08x\n", hr );
6544 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6545 SysFreeString(str);
6547 /* zero count means insert */
6548 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
6549 ok(hr == S_OK, "ret %08x\n", hr );
6550 hr = IXMLDOMComment_get_text(pComment, &str);
6551 ok(hr == S_OK, "ret %08x\n", hr );
6552 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6553 SysFreeString(str);
6555 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
6556 ok(hr == S_OK, "ret %08x\n", hr );
6558 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
6559 ok(hr == S_OK, "ret %08x\n", hr );
6560 hr = IXMLDOMComment_get_text(pComment, &str);
6561 ok(hr == S_OK, "ret %08x\n", hr );
6562 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6563 SysFreeString(str);
6565 /* nonempty string, count greater than its length */
6566 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
6567 ok(hr == S_OK, "ret %08x\n", hr );
6568 hr = IXMLDOMComment_get_text(pComment, &str);
6569 ok(hr == S_OK, "ret %08x\n", hr );
6570 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6571 SysFreeString(str);
6573 /* nonempty string, count less than its length */
6574 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
6575 ok(hr == S_OK, "ret %08x\n", hr );
6576 hr = IXMLDOMComment_get_text(pComment, &str);
6577 ok(hr == S_OK, "ret %08x\n", hr );
6578 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6579 SysFreeString(str);
6581 IXMLDOMComment_Release(pComment);
6584 /* Element */
6585 str = SysAllocString(szElement);
6586 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
6587 SysFreeString(str);
6588 ok(hr == S_OK, "ret %08x\n", hr );
6589 if(hr == S_OK)
6591 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6592 ok(hr == S_OK, "ret %08x\n", hr );
6594 hr = IXMLDOMElement_get_nodeName(pElement, &str);
6595 ok(hr == S_OK, "ret %08x\n", hr );
6596 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
6597 SysFreeString(str);
6599 hr = IXMLDOMElement_get_xml(pElement, &str);
6600 ok(hr == S_OK, "ret %08x\n", hr );
6601 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
6602 SysFreeString(str);
6604 /* Attribute */
6605 pAttribute = (IXMLDOMAttribute*)0x1;
6606 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
6607 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6608 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
6610 pAttribute = (IXMLDOMAttribute*)0x1;
6611 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
6612 ok(hr == E_FAIL, "ret %08x\n", hr );
6613 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
6615 str = SysAllocString(szAttribute);
6616 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
6617 SysFreeString(str);
6618 ok(hr == S_OK, "ret %08x\n", hr );
6619 if(hr == S_OK)
6621 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
6623 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
6624 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6626 pNextChild = (IXMLDOMNode *)0x1;
6627 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
6628 ok(hr == S_FALSE, "ret %08x\n", hr );
6629 ok(pNextChild == NULL, "pNextChild not NULL\n");
6631 /* test Previous Sibling*/
6632 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
6633 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6635 pNextChild = (IXMLDOMNode *)0x1;
6636 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
6637 ok(hr == S_FALSE, "ret %08x\n", hr );
6638 ok(pNextChild == NULL, "pNextChild not NULL\n");
6640 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
6641 ok(hr == E_FAIL, "ret %08x\n", hr );
6642 ok(pNewChild == NULL, "pNewChild not NULL\n");
6644 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
6645 ok(hr == S_OK, "ret %08x\n", hr );
6646 if ( hr == S_OK )
6648 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
6649 ok(hr == S_OK, "ret %08x\n", hr );
6651 IXMLDOMNamedNodeMap_Release(pAttribs);
6654 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6655 ok(hr == S_OK, "ret %08x\n", hr );
6656 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
6657 SysFreeString(str);
6659 /* test nodeName */
6660 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6661 ok(hr == S_OK, "ret %08x\n", hr );
6662 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
6663 SysFreeString(str);
6665 /* test name property */
6666 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
6667 ok(hr == S_OK, "ret %08x\n", hr );
6668 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
6669 SysFreeString(str);
6671 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
6672 ok(hr == S_OK, "ret %08x\n", hr );
6673 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
6674 SysFreeString(str);
6676 IXMLDOMAttribute_Release(pAttribute);
6678 /* Check Element again with the Add Attribute*/
6679 hr = IXMLDOMElement_get_xml(pElement, &str);
6680 ok(hr == S_OK, "ret %08x\n", hr );
6681 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
6682 SysFreeString(str);
6685 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
6686 ok(hr == S_OK, "ret %08x\n", hr );
6688 hr = IXMLDOMElement_get_xml(pElement, &str);
6689 ok(hr == S_OK, "ret %08x\n", hr );
6690 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
6691 SysFreeString(str);
6693 /* Test for reversible escaping */
6694 str = SysAllocString( szStrangeChars );
6695 hr = IXMLDOMElement_put_text(pElement, str);
6696 ok(hr == S_OK, "ret %08x\n", hr );
6697 SysFreeString( str );
6699 hr = IXMLDOMElement_get_xml(pElement, &str);
6700 ok(hr == S_OK, "ret %08x\n", hr );
6701 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
6702 SysFreeString(str);
6704 hr = IXMLDOMElement_get_text(pElement, &str);
6705 ok(hr == S_OK, "ret %08x\n", hr );
6706 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
6707 SysFreeString(str);
6709 IXMLDOMElement_Release(pElement);
6712 /* CData Section */
6713 str = SysAllocString(szCData);
6714 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
6715 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6717 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
6718 SysFreeString(str);
6719 ok(hr == S_OK, "ret %08x\n", hr );
6720 if(hr == S_OK)
6722 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
6723 VARIANT var;
6725 VariantInit(&var);
6727 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
6728 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
6730 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
6731 ok(hr == S_OK, "ret %08x\n", hr );
6733 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
6734 ok(hr == S_OK, "ret %08x\n", hr );
6735 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
6736 SysFreeString(str);
6738 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6739 ok(hr == S_OK, "ret %08x\n", hr );
6740 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
6741 SysFreeString(str);
6743 /* test lastChild */
6744 pNextChild = (IXMLDOMNode*)0x1;
6745 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
6746 ok(hr == S_FALSE, "ret %08x\n", hr );
6747 ok(pNextChild == NULL, "pNextChild not NULL\n");
6749 /* put data Tests */
6750 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
6751 ok(hr == S_OK, "ret %08x\n", hr );
6753 /* Confirm XML text is good */
6754 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6755 ok(hr == S_OK, "ret %08x\n", hr );
6756 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
6757 SysFreeString(str);
6759 /* Confirm we get the put_data Text back */
6760 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6761 ok(hr == S_OK, "ret %08x\n", hr );
6762 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6763 SysFreeString(str);
6765 /* test length property */
6766 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6767 ok(hr == S_OK, "ret %08x\n", hr );
6768 ok(len == 21, "expected 21 got %d\n", len);
6770 /* test get data */
6771 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
6772 ok(hr == S_OK, "ret %08x\n", hr );
6773 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6774 SysFreeString(str);
6776 /* test substringData */
6777 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
6778 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6780 /* test substringData - Invalid offset */
6781 str = (BSTR)&szElement;
6782 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
6783 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6784 ok( str == NULL, "incorrect string\n");
6786 /* test substringData - Invalid offset */
6787 str = (BSTR)&szElement;
6788 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
6789 ok(hr == S_FALSE, "ret %08x\n", hr );
6790 ok( str == NULL, "incorrect string\n");
6792 /* test substringData - Invalid size */
6793 str = (BSTR)&szElement;
6794 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
6795 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6796 ok( str == NULL, "incorrect string\n");
6798 /* test substringData - Invalid size */
6799 str = (BSTR)&szElement;
6800 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
6801 ok(hr == S_FALSE, "ret %08x\n", hr );
6802 ok( str == NULL, "incorrect string\n");
6804 /* test substringData - Start of string */
6805 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
6806 ok(hr == S_OK, "ret %08x\n", hr );
6807 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
6808 SysFreeString(str);
6810 /* test substringData - Middle of string */
6811 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
6812 ok(hr == S_OK, "ret %08x\n", hr );
6813 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
6814 SysFreeString(str);
6816 /* test substringData - End of string */
6817 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
6818 ok(hr == S_OK, "ret %08x\n", hr );
6819 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
6820 SysFreeString(str);
6822 /* test appendData */
6823 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
6824 ok(hr == S_OK, "ret %08x\n", hr );
6826 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
6827 ok(hr == S_OK, "ret %08x\n", hr );
6829 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
6830 ok(hr == S_OK, "ret %08x\n", hr );
6832 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6833 ok(hr == S_OK, "ret %08x\n", hr );
6834 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6835 SysFreeString(str);
6837 /* test insertData */
6838 str = SysAllocStringLen(NULL, 0);
6839 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
6840 ok(hr == S_OK, "ret %08x\n", hr );
6842 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
6843 ok(hr == S_OK, "ret %08x\n", hr );
6845 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
6846 ok(hr == S_OK, "ret %08x\n", hr );
6848 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
6849 ok(hr == S_OK, "ret %08x\n", hr );
6851 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
6852 ok(hr == S_OK, "ret %08x\n", hr );
6854 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
6855 ok(hr == S_OK, "ret %08x\n", hr );
6856 SysFreeString(str);
6858 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
6859 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6861 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
6862 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6864 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
6865 ok(hr == S_OK, "ret %08x\n", hr );
6867 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
6868 ok(hr == S_OK, "ret %08x\n", hr );
6870 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
6871 ok(hr == S_OK, "ret %08x\n", hr );
6873 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6874 ok(hr == S_OK, "ret %08x\n", hr );
6875 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6876 SysFreeString(str);
6878 /* delete data */
6879 /* invalid arguments */
6880 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
6881 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6883 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
6884 ok(hr == S_OK, "ret %08x\n", hr );
6886 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
6887 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6889 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6890 ok(hr == S_OK, "ret %08x\n", hr );
6891 ok(len == 43, "expected 43 got %d\n", len);
6893 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
6894 ok(hr == S_OK, "ret %08x\n", hr );
6896 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
6897 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6899 /* delete from start */
6900 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
6901 ok(hr == S_OK, "ret %08x\n", hr );
6903 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6904 ok(hr == S_OK, "ret %08x\n", hr );
6905 ok(len == 38, "expected 38 got %d\n", len);
6907 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6908 ok(hr == S_OK, "ret %08x\n", hr );
6909 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6910 SysFreeString(str);
6912 /* delete from end */
6913 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
6914 ok(hr == S_OK, "ret %08x\n", hr );
6916 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6917 ok(hr == S_OK, "ret %08x\n", hr );
6918 ok(len == 35, "expected 35 got %d\n", len);
6920 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6921 ok(hr == S_OK, "ret %08x\n", hr );
6922 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6923 SysFreeString(str);
6925 /* delete from inside */
6926 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
6927 ok(hr == S_OK, "ret %08x\n", hr );
6929 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6930 ok(hr == S_OK, "ret %08x\n", hr );
6931 ok(len == 2, "expected 2 got %d\n", len);
6933 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6934 ok(hr == S_OK, "ret %08x\n", hr );
6935 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6936 SysFreeString(str);
6938 /* delete whole data ... */
6939 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6940 ok(hr == S_OK, "ret %08x\n", hr );
6942 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6943 ok(hr == S_OK, "ret %08x\n", hr );
6945 /* ... and try again with empty string */
6946 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6947 ok(hr == S_OK, "ret %08x\n", hr );
6949 /* ::replaceData() */
6950 V_VT(&v) = VT_BSTR;
6951 V_BSTR(&v) = SysAllocString(szstr1);
6952 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
6953 ok(hr == S_OK, "ret %08x\n", hr );
6954 VariantClear(&v);
6956 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
6957 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6958 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6959 ok(hr == S_OK, "ret %08x\n", hr );
6960 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6961 SysFreeString(str);
6963 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
6964 ok(hr == S_OK, "ret %08x\n", hr );
6965 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6966 ok(hr == S_OK, "ret %08x\n", hr );
6967 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6968 SysFreeString(str);
6970 /* NULL pointer means delete */
6971 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
6972 ok(hr == S_OK, "ret %08x\n", hr );
6973 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6974 ok(hr == S_OK, "ret %08x\n", hr );
6975 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6976 SysFreeString(str);
6978 /* empty string means delete */
6979 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
6980 ok(hr == S_OK, "ret %08x\n", hr );
6981 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6982 ok(hr == S_OK, "ret %08x\n", hr );
6983 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6984 SysFreeString(str);
6986 /* zero count means insert */
6987 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
6988 ok(hr == S_OK, "ret %08x\n", hr );
6989 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6990 ok(hr == S_OK, "ret %08x\n", hr );
6991 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6992 SysFreeString(str);
6994 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
6995 ok(hr == S_OK, "ret %08x\n", hr );
6997 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
6998 ok(hr == S_OK, "ret %08x\n", hr );
6999 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
7000 ok(hr == S_OK, "ret %08x\n", hr );
7001 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
7002 SysFreeString(str);
7004 /* nonempty string, count greater than its length */
7005 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
7006 ok(hr == S_OK, "ret %08x\n", hr );
7007 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
7008 ok(hr == S_OK, "ret %08x\n", hr );
7009 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
7010 SysFreeString(str);
7012 /* nonempty string, count less than its length */
7013 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
7014 ok(hr == S_OK, "ret %08x\n", hr );
7015 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
7016 ok(hr == S_OK, "ret %08x\n", hr );
7017 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
7018 SysFreeString(str);
7020 IXMLDOMCDATASection_Release(pCDataSec);
7023 /* Document Fragments */
7024 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
7025 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7027 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
7028 ok(hr == S_OK, "ret %08x\n", hr );
7029 if(hr == S_OK)
7031 IXMLDOMNode *node;
7033 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
7034 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7036 node = (IXMLDOMNode *)0x1;
7037 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
7038 ok(hr == S_FALSE, "ret %08x\n", hr );
7039 ok(node == NULL, "expected NULL, got %p\n", node);
7041 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
7042 ok(hr == S_OK, "ret %08x\n", hr );
7044 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
7045 ok(hr == S_OK, "ret %08x\n", hr );
7046 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
7047 SysFreeString(str);
7049 /* test next Sibling*/
7050 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
7051 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7053 node = (IXMLDOMNode *)0x1;
7054 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
7055 ok(hr == S_FALSE, "ret %08x\n", hr );
7056 ok(node == NULL, "next sibling not NULL\n");
7058 /* test Previous Sibling*/
7059 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
7060 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7062 node = (IXMLDOMNode *)0x1;
7063 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
7064 ok(hr == S_FALSE, "ret %08x\n", hr );
7065 ok(node == NULL, "previous sibling not NULL\n");
7067 IXMLDOMDocumentFragment_Release(pDocFrag);
7070 /* Entity References */
7071 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
7072 ok(hr == E_FAIL, "ret %08x\n", hr );
7073 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
7074 ok(hr == E_FAIL, "ret %08x\n", hr );
7076 str = SysAllocString(szEntityRef);
7077 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
7078 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7080 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
7081 SysFreeString(str);
7082 ok(hr == S_OK, "ret %08x\n", hr );
7083 if(hr == S_OK)
7085 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
7086 ok(hr == S_OK, "ret %08x\n", hr );
7088 /* test get_xml*/
7089 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
7090 ok(hr == S_OK, "ret %08x\n", hr );
7091 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
7092 SysFreeString(str);
7094 IXMLDOMEntityReference_Release(pEntityRef);
7097 IXMLDOMElement_Release( pRoot );
7101 IXMLDOMDocument_Release(doc);
7103 free_bstrs();
7106 typedef struct {
7107 const char *name;
7108 const char *type;
7109 HRESULT hr;
7110 } put_datatype_t;
7112 /* Type test for elements only. Name passed into put_dataType is case-insensitive.
7113 So many of the names have been changed to reflect this. */
7114 static put_datatype_t put_datatype_data[] = {
7115 { "test_inval", "abcdefg", E_FAIL },
7116 { "test_bool", "Boolean", S_OK },
7117 { "test_string", "String", S_OK },
7118 { "test_number", "number", S_OK },
7119 { "test_int", "InT", S_OK },
7120 { "test_fixed", "fixed.14.4", S_OK },
7121 { "test_datetime", "DateTime", S_OK },
7122 { "test_datetimetz", "DateTime.tz", S_OK },
7123 { "test_date", "Date", S_OK },
7124 { "test_time", "Time", S_OK },
7125 { "test_timetz", "Time.tz", S_OK },
7126 { "test_I1", "I1", S_OK },
7127 { "test_I2", "I2", S_OK },
7128 { "test_I4", "I4", S_OK },
7129 { "test_UI1", "UI1", S_OK },
7130 { "test_UI2", "UI2", S_OK },
7131 { "test_UI4", "UI4", S_OK },
7132 { "test_r4", "r4", S_OK },
7133 { "test_r8", "r8", S_OK },
7134 { "test_float", "float", S_OK },
7135 { "test_uuid", "UuId", S_OK },
7136 { "test_binhex", "bin.hex", S_OK },
7137 { "test_binbase64", "bin.base64", S_OK },
7138 { NULL }
7141 typedef struct {
7142 DOMNodeType type;
7143 HRESULT hr;
7144 } put_datatype_notype_t;
7146 static put_datatype_notype_t put_dt_notype[] = {
7147 { NODE_PROCESSING_INSTRUCTION, E_FAIL },
7148 { NODE_DOCUMENT_FRAGMENT, E_FAIL },
7149 { NODE_ENTITY_REFERENCE, E_FAIL },
7150 { NODE_CDATA_SECTION, E_FAIL },
7151 { NODE_COMMENT, E_FAIL },
7152 { NODE_INVALID }
7155 static void test_put_dataType( void )
7157 const put_datatype_notype_t *ptr2 = put_dt_notype;
7158 const put_datatype_t *ptr = put_datatype_data;
7159 IXMLDOMElement *root, *element;
7160 BSTR nameW, type1W, type2W;
7161 IXMLDOMDocument *doc;
7162 HRESULT hr;
7164 doc = create_document(&IID_IXMLDOMDocument);
7165 if (!doc) return;
7167 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
7168 EXPECT_HR(hr, E_INVALIDARG);
7170 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
7171 EXPECT_HR(hr, S_OK);
7173 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
7174 EXPECT_HR(hr, S_OK);
7176 hr = IXMLDOMElement_put_dataType(root, NULL);
7177 EXPECT_HR(hr, E_INVALIDARG);
7179 while (ptr->name)
7181 hr = IXMLDOMDocument_createElement(doc, _bstr_(ptr->name), &element);
7182 EXPECT_HR(hr, S_OK);
7183 if(hr == S_OK)
7185 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)element, NULL);
7186 EXPECT_HR(hr, S_OK);
7188 hr = IXMLDOMElement_put_dataType(element, _bstr_(ptr->type));
7189 ok(hr == ptr->hr, "failed for %s:%s, 0x%08x\n", ptr->name, ptr->type, ptr->hr);
7191 IXMLDOMElement_Release(element);
7193 ptr++;
7196 /* check changing types */
7197 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &element);
7198 EXPECT_HR(hr, S_OK);
7200 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)element, NULL);
7201 EXPECT_HR(hr, S_OK);
7203 hr = IXMLDOMElement_put_dataType(element, _bstr_("DateTime.tz"));
7204 EXPECT_HR(hr, S_OK);
7206 hr = IXMLDOMElement_put_dataType(element, _bstr_("string"));
7207 EXPECT_HR(hr, S_OK);
7209 IXMLDOMElement_Release(element);
7211 /* try to set type for node without a type */
7212 nameW = _bstr_("testname");
7213 type1W = _bstr_("string");
7214 type2W = _bstr_("number");
7215 while (ptr2->type != NODE_INVALID)
7217 IXMLDOMNode *node;
7218 VARIANT type;
7220 V_VT(&type) = VT_I2;
7221 V_I2(&type) = ptr2->type;
7223 hr = IXMLDOMDocument_createNode(doc, type, nameW, NULL, &node);
7224 EXPECT_HR(hr, S_OK);
7225 if(hr == S_OK)
7227 hr = IXMLDOMElement_appendChild(root, node, NULL);
7228 EXPECT_HR(hr, S_OK);
7230 hr = IXMLDOMNode_put_dataType(node, NULL);
7231 EXPECT_HR(hr, E_INVALIDARG);
7233 hr = IXMLDOMNode_put_dataType(node, type1W);
7234 ok(hr == ptr2->hr, "failed for type %d, 0x%08x\n", ptr2->type, ptr->hr);
7235 hr = IXMLDOMNode_put_dataType(node, type2W);
7236 ok(hr == ptr2->hr, "failed for type %d, 0x%08x\n", ptr2->type, ptr->hr);
7238 IXMLDOMNode_Release(node);
7240 ptr2++;
7243 IXMLDOMElement_Release(root);
7244 IXMLDOMDocument_Release(doc);
7245 free_bstrs();
7248 static void test_save(void)
7250 IXMLDOMDocument *doc, *doc2;
7251 IXMLDOMElement *root;
7252 BSTR sOrig, sNew, filename;
7253 char buffer[100];
7254 IStream *stream;
7255 HGLOBAL global;
7256 VARIANT_BOOL b;
7257 DWORD read = 0;
7258 VARIANT dest;
7259 HANDLE hfile;
7260 HRESULT hr;
7261 char *ptr;
7263 doc = create_document(&IID_IXMLDOMDocument);
7264 if (!doc) return;
7266 doc2 = create_document(&IID_IXMLDOMDocument);
7267 if (!doc2)
7269 IXMLDOMDocument_Release(doc);
7270 return;
7273 /* save to IXMLDOMDocument */
7274 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
7275 EXPECT_HR(hr, S_OK);
7277 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
7278 EXPECT_HR(hr, S_OK);
7280 V_VT(&dest) = VT_UNKNOWN;
7281 V_UNKNOWN(&dest) = (IUnknown*)doc2;
7283 hr = IXMLDOMDocument_save(doc, dest);
7284 EXPECT_HR(hr, S_OK);
7286 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
7287 EXPECT_HR(hr, S_OK);
7289 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
7290 EXPECT_HR(hr, S_OK);
7292 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as original\n");
7294 SysFreeString(sOrig);
7295 SysFreeString(sNew);
7297 IXMLDOMElement_Release(root);
7298 IXMLDOMDocument_Release(doc2);
7300 /* save to path */
7301 V_VT(&dest) = VT_BSTR;
7302 V_BSTR(&dest) = _bstr_("test.xml");
7304 hr = IXMLDOMDocument_save(doc, dest);
7305 EXPECT_HR(hr, S_OK);
7307 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
7308 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
7309 if(hfile == INVALID_HANDLE_VALUE) return;
7311 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
7312 ok(read != 0, "could not read file\n");
7313 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
7315 CloseHandle(hfile);
7316 DeleteFile("test.xml");
7318 /* save to path VT_BSTR | VT_BYREF */
7319 filename = _bstr_("test.xml");
7320 V_VT(&dest) = VT_BSTR | VT_BYREF;
7321 V_BSTRREF(&dest) = &filename;
7323 hr = IXMLDOMDocument_save(doc, dest);
7324 EXPECT_HR(hr, S_OK);
7326 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
7327 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
7328 if(hfile == INVALID_HANDLE_VALUE) return;
7330 if (hfile != INVALID_HANDLE_VALUE)
7332 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
7333 ok(read != 0, "could not read file\n");
7334 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
7336 CloseHandle(hfile);
7337 DeleteFile("test.xml");
7340 /* save to stream */
7341 V_VT(&dest) = VT_UNKNOWN;
7342 V_UNKNOWN(&dest) = (IUnknown*)&savestream;
7344 hr = IXMLDOMDocument_save(doc, dest);
7345 EXPECT_HR(hr, S_OK);
7347 /* loaded data contains xml declaration */
7348 hr = IXMLDOMDocument_loadXML(doc, _bstr_(win1252xml), &b);
7349 EXPECT_HR(hr, S_OK);
7351 CreateStreamOnHGlobal(NULL, TRUE, &stream);
7352 V_VT(&dest) = VT_UNKNOWN;
7353 V_UNKNOWN(&dest) = (IUnknown*)stream;
7354 hr = IXMLDOMDocument_save(doc, dest);
7355 EXPECT_HR(hr, S_OK);
7357 hr = GetHGlobalFromStream(stream, &global);
7358 EXPECT_HR(hr, S_OK);
7359 ptr = GlobalLock(global);
7360 ok(!memcmp(ptr, win1252decl, strlen(win1252decl)), "got wrong xml declaration\n");
7361 GlobalUnlock(global);
7362 IStream_Release(stream);
7364 /* loaded data without xml declaration */
7365 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<a/>"), &b);
7366 EXPECT_HR(hr, S_OK);
7368 CreateStreamOnHGlobal(NULL, TRUE, &stream);
7369 V_VT(&dest) = VT_UNKNOWN;
7370 V_UNKNOWN(&dest) = (IUnknown*)stream;
7371 hr = IXMLDOMDocument_save(doc, dest);
7372 EXPECT_HR(hr, S_OK);
7374 hr = GetHGlobalFromStream(stream, &global);
7375 EXPECT_HR(hr, S_OK);
7376 ptr = GlobalLock(global);
7377 ok(ptr[0] == '<' && ptr[1] != '?', "got wrong start tag %c%c\n", ptr[0], ptr[1]);
7378 GlobalUnlock(global);
7379 IStream_Release(stream);
7381 IXMLDOMDocument_Release(doc);
7382 free_bstrs();
7385 static void test_testTransforms(void)
7387 IXMLDOMDocument *doc, *docSS;
7388 IXMLDOMNode *pNode;
7389 VARIANT_BOOL bSucc;
7391 HRESULT hr;
7393 doc = create_document(&IID_IXMLDOMDocument);
7394 if (!doc) return;
7396 docSS = create_document(&IID_IXMLDOMDocument);
7397 if (!docSS)
7399 IXMLDOMDocument_Release(doc);
7400 return;
7403 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
7404 ok(hr == S_OK, "ret %08x\n", hr );
7406 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
7407 ok(hr == S_OK, "ret %08x\n", hr );
7409 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
7410 ok(hr == S_OK, "ret %08x\n", hr );
7411 if(hr == S_OK)
7413 BSTR bOut;
7415 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
7416 ok(hr == S_OK, "ret %08x\n", hr );
7417 if(hr == S_OK)
7419 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
7420 SysFreeString(bOut);
7423 IXMLDOMNode_Release(pNode);
7426 IXMLDOMDocument_Release(docSS);
7427 IXMLDOMDocument_Release(doc);
7429 free_bstrs();
7432 struct namespaces_change_t {
7433 const CLSID *clsid;
7434 const char *name;
7437 static const struct namespaces_change_t namespaces_change_test_data[] = {
7438 { &CLSID_DOMDocument, "CLSID_DOMDocument" },
7439 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" },
7440 { &CLSID_DOMDocument26, "CLSID_DOMDocument26" },
7441 { &CLSID_DOMDocument30, "CLSID_DOMDocument30" },
7442 { &CLSID_DOMDocument40, "CLSID_DOMDocument40" },
7443 { &CLSID_DOMDocument60, "CLSID_DOMDocument60" },
7444 { 0 }
7447 static void test_namespaces_change(void)
7449 const struct namespaces_change_t *class_ptr = namespaces_change_test_data;
7451 while (class_ptr->clsid)
7453 IXMLDOMDocument *doc = NULL;
7454 IXMLDOMElement *elem = NULL;
7455 IXMLDOMNode *node = NULL;
7457 VARIANT var;
7458 HRESULT hr;
7459 BSTR str;
7461 hr = CoCreateInstance(class_ptr->clsid, NULL, CLSCTX_INPROC_SERVER,
7462 &IID_IXMLDOMDocument, (void**)&doc);
7463 if (hr != S_OK)
7465 win_skip("failed to create class instance for %s\n", class_ptr->name);
7466 class_ptr++;
7467 continue;
7470 V_VT(&var) = VT_I2;
7471 V_I2(&var) = NODE_ELEMENT;
7473 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("ns:elem"), _bstr_("ns/uri"), &node);
7474 EXPECT_HR(hr, S_OK);
7476 hr = IXMLDOMDocument_appendChild(doc, node, NULL);
7477 EXPECT_HR(hr, S_OK);
7479 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7480 EXPECT_HR(hr, S_OK);
7482 /* try same prefix, different uri */
7483 V_VT(&var) = VT_BSTR;
7484 V_BSTR(&var) = _bstr_("ns/uri2");
7486 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
7487 EXPECT_HR(hr, E_INVALIDARG);
7489 /* try same prefix and uri */
7490 V_VT(&var) = VT_BSTR;
7491 V_BSTR(&var) = _bstr_("ns/uri");
7493 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
7494 EXPECT_HR(hr, S_OK);
7496 hr = IXMLDOMElement_get_xml(elem, &str);
7497 EXPECT_HR(hr, S_OK);
7498 ok(!lstrcmpW(str, _bstr_("<ns:elem xmlns:ns=\"ns/uri\"/>")), "got element %s for %s\n",
7499 wine_dbgstr_w(str), class_ptr->name);
7500 SysFreeString(str);
7502 IXMLDOMElement_Release(elem);
7503 IXMLDOMDocument_Release(doc);
7505 free_bstrs();
7507 class_ptr++;
7511 static void test_namespaces_basic(void)
7513 static const CHAR namespaces_xmlA[] =
7514 "<?xml version=\"1.0\"?>\n"
7515 "<XMI xmi.version=\"1.1\" xmlns:Model=\"http://omg.org/mof.Model/1.3\">"
7516 " <XMI.content>"
7517 " <Model:Package name=\"WinePackage\" Model:name2=\"name2 attr\" />"
7518 " </XMI.content>"
7519 "</XMI>";
7521 IXMLDOMDocument *doc;
7522 IXMLDOMElement *elem;
7523 IXMLDOMNode *node;
7525 VARIANT_BOOL b;
7526 HRESULT hr;
7527 BSTR str;
7529 doc = create_document(&IID_IXMLDOMDocument);
7530 if (!doc) return;
7532 hr = IXMLDOMDocument_loadXML(doc, _bstr_(namespaces_xmlA), &b);
7533 EXPECT_HR(hr, S_OK);
7534 ok(b == VARIANT_TRUE, "got %d\n", b);
7536 str = (BSTR)0xdeadbeef;
7537 hr = IXMLDOMDocument_get_namespaceURI(doc, &str);
7538 EXPECT_HR(hr, S_FALSE);
7539 ok(str == NULL, "got %p\n", str);
7541 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("//XMI.content"), &node );
7542 EXPECT_HR(hr, S_OK);
7543 if(hr == S_OK)
7545 IXMLDOMAttribute *attr;
7546 IXMLDOMNode *node2;
7548 hr = IXMLDOMNode_get_firstChild(node, &node2);
7549 EXPECT_HR(hr, S_OK);
7550 ok(node2 != NULL, "got %p\n", node2);
7552 /* Test get_prefix */
7553 hr = IXMLDOMNode_get_prefix(node2, NULL);
7554 EXPECT_HR(hr, E_INVALIDARG);
7555 /* NOTE: Need to test that arg2 gets cleared on Error. */
7557 hr = IXMLDOMNode_get_prefix(node2, &str);
7558 EXPECT_HR(hr, S_OK);
7559 ok( !lstrcmpW( str, _bstr_("Model")), "got %s\n", wine_dbgstr_w(str));
7560 SysFreeString(str);
7562 hr = IXMLDOMNode_get_nodeName(node2, &str);
7563 EXPECT_HR(hr, S_OK);
7564 ok(!lstrcmpW( str, _bstr_("Model:Package")), "got %s\n", wine_dbgstr_w(str));
7565 SysFreeString(str);
7567 /* Test get_namespaceURI */
7568 hr = IXMLDOMNode_get_namespaceURI(node2, NULL);
7569 EXPECT_HR(hr, E_INVALIDARG);
7570 /* NOTE: Need to test that arg2 gets cleared on Error. */
7572 hr = IXMLDOMNode_get_namespaceURI(node2, &str);
7573 EXPECT_HR(hr, S_OK);
7574 ok(!lstrcmpW( str, _bstr_("http://omg.org/mof.Model/1.3")), "got %s\n", wine_dbgstr_w(str));
7575 SysFreeString(str);
7577 hr = IXMLDOMNode_QueryInterface(node2, &IID_IXMLDOMElement, (void**)&elem);
7578 EXPECT_HR(hr, S_OK);
7580 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("Model:name2"), &attr);
7581 EXPECT_HR(hr, S_OK);
7583 hr = IXMLDOMAttribute_get_nodeName(attr, &str);
7584 EXPECT_HR(hr, S_OK);
7585 ok(!lstrcmpW( str, _bstr_("Model:name2")), "got %s\n", wine_dbgstr_w(str));
7586 SysFreeString(str);
7588 hr = IXMLDOMAttribute_get_prefix(attr, &str);
7589 EXPECT_HR(hr, S_OK);
7590 ok(!lstrcmpW( str, _bstr_("Model")), "got %s\n", wine_dbgstr_w(str));
7591 SysFreeString(str);
7593 IXMLDOMAttribute_Release(attr);
7594 IXMLDOMElement_Release(elem);
7596 IXMLDOMNode_Release(node2);
7597 IXMLDOMNode_Release(node);
7600 IXMLDOMDocument_Release(doc);
7602 free_bstrs();
7605 static void test_FormattingXML(void)
7607 IXMLDOMDocument *doc;
7608 IXMLDOMElement *pElement;
7609 VARIANT_BOOL bSucc;
7610 HRESULT hr;
7611 BSTR str;
7612 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
7613 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
7615 doc = create_document(&IID_IXMLDOMDocument);
7616 if (!doc) return;
7618 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
7619 ok(hr == S_OK, "ret %08x\n", hr );
7620 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7622 if(bSucc == VARIANT_TRUE)
7624 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
7625 ok(hr == S_OK, "ret %08x\n", hr );
7626 if(hr == S_OK)
7628 hr = IXMLDOMElement_get_xml(pElement, &str);
7629 ok(hr == S_OK, "ret %08x\n", hr );
7630 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
7631 SysFreeString(str);
7633 IXMLDOMElement_Release(pElement);
7637 IXMLDOMDocument_Release(doc);
7639 free_bstrs();
7642 typedef struct _nodetypedvalue_t {
7643 const char *name;
7644 VARTYPE type;
7645 const char *value; /* value in string format */
7646 } nodetypedvalue_t;
7648 static const nodetypedvalue_t get_nodetypedvalue[] = {
7649 { "root/string", VT_BSTR, "Wine" },
7650 { "root/string2", VT_BSTR, "String" },
7651 { "root/number", VT_BSTR, "12.44" },
7652 { "root/number2", VT_BSTR, "-3.71e3" },
7653 { "root/int", VT_I4, "-13" },
7654 { "root/fixed", VT_CY, "7322.9371" },
7655 { "root/bool", VT_BOOL, "-1" },
7656 { "root/datetime", VT_DATE, "40135.14" },
7657 { "root/datetimetz",VT_DATE, "37813.59" },
7658 { "root/date", VT_DATE, "665413" },
7659 { "root/time", VT_DATE, "0.5813889" },
7660 { "root/timetz", VT_DATE, "1.112512" },
7661 { "root/i1", VT_I1, "-13" },
7662 { "root/i2", VT_I2, "31915" },
7663 { "root/i4", VT_I4, "-312232" },
7664 { "root/ui1", VT_UI1, "123" },
7665 { "root/ui2", VT_UI2, "48282" },
7666 { "root/ui4", VT_UI4, "949281" },
7667 { "root/r4", VT_R4, "213124" },
7668 { "root/r8", VT_R8, "0.412" },
7669 { "root/float", VT_R8, "41221.421" },
7670 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
7671 { "root/binbase64", VT_ARRAY|VT_UI1, "base64 test" },
7672 { "root/binbase64_1", VT_ARRAY|VT_UI1, "base64 test" },
7673 { "root/binbase64_2", VT_ARRAY|VT_UI1, "base64 test" },
7674 { 0 }
7677 static void test_nodeTypedValue(void)
7679 const nodetypedvalue_t *entry = get_nodetypedvalue;
7680 IXMLDOMDocumentType *doctype, *doctype2;
7681 IXMLDOMProcessingInstruction *pi;
7682 IXMLDOMDocumentFragment *frag;
7683 IXMLDOMDocument *doc, *doc2;
7684 IXMLDOMCDATASection *cdata;
7685 IXMLDOMComment *comment;
7686 IXMLDOMNode *node;
7687 VARIANT_BOOL b;
7688 VARIANT value;
7689 HRESULT hr;
7691 doc = create_document(&IID_IXMLDOMDocument);
7692 if (!doc) return;
7694 b = VARIANT_FALSE;
7695 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
7696 ok(hr == S_OK, "ret %08x\n", hr );
7697 ok(b == VARIANT_TRUE, "got %d\n", b);
7699 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
7700 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7702 V_VT(&value) = VT_BSTR;
7703 V_BSTR(&value) = NULL;
7704 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
7705 ok(hr == S_FALSE, "ret %08x\n", hr );
7706 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7708 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
7709 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7711 V_VT(&value) = VT_EMPTY;
7712 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
7713 ok(hr == S_FALSE, "ret %08x\n", hr );
7714 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7716 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
7717 ok(hr == S_OK, "ret %08x\n", hr );
7719 V_VT(&value) = VT_BSTR;
7720 V_BSTR(&value) = NULL;
7721 hr = IXMLDOMNode_get_nodeValue(node, &value);
7722 ok(hr == S_FALSE, "ret %08x\n", hr );
7723 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7725 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
7726 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7728 IXMLDOMNode_Release(node);
7730 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
7731 ok(hr == S_OK, "ret %08x\n", hr );
7733 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
7735 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7736 ok(hr == S_OK, "ret %08x\n", hr );
7737 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
7738 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
7739 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
7740 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
7741 VariantClear(&value);
7742 IXMLDOMNode_Release(node);
7745 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("foo"), _bstr_("value"), &pi);
7746 ok(hr == S_OK, "ret %08x\n", hr );
7748 V_VT(&value) = VT_NULL;
7749 V_BSTR(&value) = (void*)0xdeadbeef;
7750 hr = IXMLDOMProcessingInstruction_get_nodeTypedValue(pi, &value);
7751 ok(hr == S_OK, "ret %08x\n", hr );
7752 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7753 ok(!lstrcmpW(V_BSTR(&value), _bstr_("value")), "got wrong value\n");
7754 IXMLDOMProcessingInstruction_Release(pi);
7755 VariantClear(&value);
7758 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("[1]*2=3; &gee that's not right!"), &cdata);
7759 ok(hr == S_OK, "ret %08x\n", hr );
7761 V_VT(&value) = VT_NULL;
7762 V_BSTR(&value) = (void*)0xdeadbeef;
7763 hr = IXMLDOMCDATASection_get_nodeTypedValue(cdata, &value);
7764 ok(hr == S_OK, "ret %08x\n", hr );
7765 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7766 ok(!lstrcmpW(V_BSTR(&value), _bstr_("[1]*2=3; &gee that's not right!")), "got wrong value\n");
7767 IXMLDOMCDATASection_Release(cdata);
7768 VariantClear(&value);
7771 hr = IXMLDOMDocument_createComment(doc, _bstr_("comment"), &comment);
7772 ok(hr == S_OK, "ret %08x\n", hr );
7774 V_VT(&value) = VT_NULL;
7775 V_BSTR(&value) = (void*)0xdeadbeef;
7776 hr = IXMLDOMComment_get_nodeTypedValue(comment, &value);
7777 ok(hr == S_OK, "ret %08x\n", hr );
7778 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7779 ok(!lstrcmpW(V_BSTR(&value), _bstr_("comment")), "got wrong value\n");
7780 IXMLDOMComment_Release(comment);
7781 VariantClear(&value);
7784 hr = IXMLDOMDocument_createDocumentFragment(doc, &frag);
7785 ok(hr == S_OK, "ret %08x\n", hr );
7787 V_VT(&value) = VT_EMPTY;
7788 hr = IXMLDOMDocumentFragment_get_nodeTypedValue(frag, &value);
7789 ok(hr == S_FALSE, "ret %08x\n", hr );
7790 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7791 IXMLDOMDocumentFragment_Release(frag);
7794 doc2 = create_document(&IID_IXMLDOMDocument);
7796 b = VARIANT_FALSE;
7797 hr = IXMLDOMDocument_loadXML(doc2, _bstr_(szEmailXML), &b);
7798 ok(hr == S_OK, "ret %08x\n", hr );
7799 ok(b == VARIANT_TRUE, "got %d\n", b);
7801 EXPECT_REF(doc2, 1);
7803 hr = IXMLDOMDocument_get_doctype(doc2, &doctype);
7804 ok(hr == S_OK, "ret %08x\n", hr );
7806 EXPECT_REF(doc2, 1);
7807 todo_wine EXPECT_REF(doctype, 2);
7810 V_VT(&value) = VT_EMPTY;
7811 hr = IXMLDOMDocumentType_get_nodeTypedValue(doctype, &value);
7812 ok(hr == S_FALSE, "ret %08x\n", hr );
7813 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7816 hr = IXMLDOMDocument_get_doctype(doc2, &doctype2);
7817 ok(hr == S_OK, "ret %08x\n", hr );
7818 ok(doctype != doctype2, "got %p, was %p\n", doctype2, doctype);
7820 IXMLDOMDocumentType_Release(doctype2);
7821 IXMLDOMDocumentType_Release(doctype);
7823 IXMLDOMDocument_Release(doc2);
7825 while (entry->name)
7827 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
7828 ok(hr == S_OK, "ret %08x\n", hr );
7830 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7831 ok(hr == S_OK, "ret %08x\n", hr );
7832 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
7834 if (entry->type == (VT_ARRAY|VT_UI1))
7836 ok(V_ARRAY(&value)->rgsabound[0].cElements == strlen(entry->value),
7837 "incorrect array size %d\n", V_ARRAY(&value)->rgsabound[0].cElements);
7840 if (entry->type != VT_BSTR)
7842 if (entry->type == VT_DATE ||
7843 entry->type == VT_R8 ||
7844 entry->type == VT_CY)
7846 if (entry->type == VT_DATE)
7848 hr = VariantChangeType(&value, &value, 0, VT_R4);
7849 ok(hr == S_OK, "ret %08x\n", hr );
7851 hr = VariantChangeTypeEx(&value, &value,
7852 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
7853 VARIANT_NOUSEROVERRIDE, VT_BSTR);
7854 ok(hr == S_OK, "ret %08x\n", hr );
7856 else
7858 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
7859 ok(hr == S_OK, "ret %08x\n", hr );
7862 /* for byte array from VT_ARRAY|VT_UI1 it's not a WCHAR buffer */
7863 if (entry->type == (VT_ARRAY|VT_UI1))
7865 ok(!memcmp( V_BSTR(&value), entry->value, strlen(entry->value)),
7866 "expected %s\n", entry->value);
7868 else
7869 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7870 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7872 else
7873 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7874 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7876 VariantClear( &value );
7877 IXMLDOMNode_Release(node);
7879 entry++;
7882 IXMLDOMDocument_Release(doc);
7883 free_bstrs();
7886 static void test_TransformWithLoadingLocalFile(void)
7888 IXMLDOMDocument *doc;
7889 IXMLDOMDocument *xsl;
7890 IXMLDOMNode *pNode;
7891 VARIANT_BOOL bSucc;
7892 HRESULT hr;
7893 HANDLE file;
7894 DWORD dwWritten;
7895 char lpPathBuffer[MAX_PATH];
7896 int i;
7898 /* Create a Temp File. */
7899 GetTempPathA(MAX_PATH, lpPathBuffer);
7900 strcat(lpPathBuffer, "customers.xml" );
7902 file = CreateFileA(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
7903 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
7904 if(file == INVALID_HANDLE_VALUE)
7905 return;
7907 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
7908 CloseHandle(file);
7910 /* Correct path to not include a escape character. */
7911 for(i=0; i < strlen(lpPathBuffer); i++)
7913 if(lpPathBuffer[i] == '\\')
7914 lpPathBuffer[i] = '/';
7917 doc = create_document(&IID_IXMLDOMDocument);
7918 if (!doc) return;
7920 xsl = create_document(&IID_IXMLDOMDocument);
7921 if (!xsl)
7923 IXMLDOMDocument2_Release(doc);
7924 return;
7927 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
7928 ok(hr == S_OK, "ret %08x\n", hr );
7929 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7930 if(bSucc == VARIANT_TRUE)
7932 BSTR sXSL;
7933 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
7934 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
7935 BSTR sFileName = _bstr_(lpPathBuffer);
7936 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
7938 sXSL = SysAllocStringLen(NULL, nLegnth);
7939 lstrcpyW(sXSL, sPart1);
7940 lstrcatW(sXSL, sFileName);
7941 lstrcatW(sXSL, sPart2);
7943 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
7944 ok(hr == S_OK, "ret %08x\n", hr );
7945 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7946 if(bSucc == VARIANT_TRUE)
7948 BSTR sResult;
7950 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
7951 ok(hr == S_OK, "ret %08x\n", hr );
7952 if(hr == S_OK)
7954 /* This will load the temp file via the XSL */
7955 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
7956 ok(hr == S_OK, "ret %08x\n", hr );
7957 if(hr == S_OK)
7959 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
7960 SysFreeString(sResult);
7963 IXMLDOMNode_Release(pNode);
7967 SysFreeString(sXSL);
7970 IXMLDOMDocument_Release(doc);
7971 IXMLDOMDocument_Release(xsl);
7973 DeleteFile(lpPathBuffer);
7974 free_bstrs();
7977 static void test_put_nodeValue(void)
7979 static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
7980 IXMLDOMDocument *doc;
7981 IXMLDOMText *text;
7982 IXMLDOMEntityReference *entityref;
7983 IXMLDOMAttribute *attr;
7984 IXMLDOMNode *node;
7985 HRESULT hr;
7986 VARIANT data, type;
7988 doc = create_document(&IID_IXMLDOMDocument);
7989 if (!doc) return;
7991 /* test for unsupported types */
7992 /* NODE_DOCUMENT */
7993 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
7994 ok(hr == S_OK, "ret %08x\n", hr );
7995 V_VT(&data) = VT_BSTR;
7996 V_BSTR(&data) = _bstr_("one two three");
7997 hr = IXMLDOMNode_put_nodeValue(node, data);
7998 ok(hr == E_FAIL, "ret %08x\n", hr );
7999 IXMLDOMNode_Release(node);
8001 /* NODE_DOCUMENT_FRAGMENT */
8002 V_VT(&type) = VT_I1;
8003 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
8004 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
8005 ok(hr == S_OK, "ret %08x\n", hr );
8006 V_VT(&data) = VT_BSTR;
8007 V_BSTR(&data) = _bstr_("one two three");
8008 hr = IXMLDOMNode_put_nodeValue(node, data);
8009 ok(hr == E_FAIL, "ret %08x\n", hr );
8010 IXMLDOMNode_Release(node);
8012 /* NODE_ELEMENT */
8013 V_VT(&type) = VT_I1;
8014 V_I1(&type) = NODE_ELEMENT;
8015 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
8016 ok(hr == S_OK, "ret %08x\n", hr );
8017 V_VT(&data) = VT_BSTR;
8018 V_BSTR(&data) = _bstr_("one two three");
8019 hr = IXMLDOMNode_put_nodeValue(node, data);
8020 ok(hr == E_FAIL, "ret %08x\n", hr );
8021 IXMLDOMNode_Release(node);
8023 /* NODE_ENTITY_REFERENCE */
8024 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
8025 ok(hr == S_OK, "ret %08x\n", hr );
8027 V_VT(&data) = VT_BSTR;
8028 V_BSTR(&data) = _bstr_("one two three");
8029 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
8030 ok(hr == E_FAIL, "ret %08x\n", hr );
8032 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
8033 ok(hr == S_OK, "ret %08x\n", hr );
8034 V_VT(&data) = VT_BSTR;
8035 V_BSTR(&data) = _bstr_("one two three");
8036 hr = IXMLDOMNode_put_nodeValue(node, data);
8037 ok(hr == E_FAIL, "ret %08x\n", hr );
8038 IXMLDOMNode_Release(node);
8039 IXMLDOMEntityReference_Release(entityref);
8041 /* supported types */
8042 hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
8043 ok(hr == S_OK, "ret %08x\n", hr );
8044 V_VT(&data) = VT_BSTR;
8045 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
8046 hr = IXMLDOMText_put_nodeValue(text, data);
8047 ok(hr == S_OK, "ret %08x\n", hr );
8048 IXMLDOMText_Release(text);
8050 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8051 ok(hr == S_OK, "ret %08x\n", hr );
8052 V_VT(&data) = VT_BSTR;
8053 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
8054 hr = IXMLDOMAttribute_put_nodeValue(attr, data);
8055 ok(hr == S_OK, "ret %08x\n", hr );
8056 hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
8057 ok(hr == S_OK, "ret %08x\n", hr );
8058 ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
8059 wine_dbgstr_w(V_BSTR(&data)));
8060 VariantClear(&data);
8061 IXMLDOMAttribute_Release(attr);
8063 free_bstrs();
8065 IXMLDOMDocument_Release(doc);
8068 static void test_document_IObjectSafety(void)
8070 IXMLDOMDocument *doc;
8071 IObjectSafety *safety;
8072 HRESULT hr;
8074 doc = create_document(&IID_IXMLDOMDocument);
8075 if (!doc) return;
8077 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
8078 ok(hr == S_OK, "ret %08x\n", hr );
8080 test_IObjectSafety_common(safety);
8082 IObjectSafety_Release(safety);
8084 IXMLDOMDocument_Release(doc);
8087 typedef struct _property_test_t {
8088 const GUID *guid;
8089 const char *clsid;
8090 const char *property;
8091 const char *value;
8092 } property_test_t;
8094 static const property_test_t properties_test_data[] = {
8095 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
8096 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
8097 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
8098 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
8099 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
8100 { 0 }
8103 static void test_default_properties(void)
8105 const property_test_t *entry = properties_test_data;
8107 while (entry->guid)
8109 IXMLDOMDocument2 *doc;
8110 VARIANT var;
8111 HRESULT hr;
8113 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
8114 if (hr != S_OK)
8116 win_skip("can't create %s instance\n", entry->clsid);
8117 entry++;
8118 continue;
8121 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
8122 ok(hr == S_OK, "got 0x%08x\n", hr);
8123 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
8124 entry->value, entry->clsid);
8125 VariantClear(&var);
8127 IXMLDOMDocument2_Release(doc);
8129 entry++;
8133 typedef struct {
8134 const char *query;
8135 const char *list;
8136 } xslpattern_test_t;
8138 static const xslpattern_test_t xslpattern_test[] = {
8139 { "root//elem[0]", "E1.E2.D1" },
8140 { "root//elem[index()=1]", "E2.E2.D1" },
8141 { "root//elem[index() $eq$ 1]", "E2.E2.D1" },
8142 { "root//elem[end()]", "E4.E2.D1" },
8143 { "root//elem[$not$ end()]", "E1.E2.D1 E2.E2.D1 E3.E2.D1" },
8144 { "root//elem[index() != 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
8145 { "root//elem[index() $ne$ 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
8146 { "root//elem[index() < 2]", "E1.E2.D1 E2.E2.D1" },
8147 { "root//elem[index() $lt$ 2]", "E1.E2.D1 E2.E2.D1" },
8148 { "root//elem[index() <= 1]", "E1.E2.D1 E2.E2.D1" },
8149 { "root//elem[index() $le$ 1]", "E1.E2.D1 E2.E2.D1" },
8150 { "root//elem[index() > 1]", "E3.E2.D1 E4.E2.D1" },
8151 { "root//elem[index() $gt$ 1]", "E3.E2.D1 E4.E2.D1" },
8152 { "root//elem[index() >= 2]", "E3.E2.D1 E4.E2.D1" },
8153 { "root//elem[index() $ge$ 2]", "E3.E2.D1 E4.E2.D1" },
8154 { "root//elem[a $ieq$ 'a2 field']", "E2.E2.D1" },
8155 { "root//elem[a $ine$ 'a2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
8156 { "root//elem[a $ilt$ 'a3 field']", "E1.E2.D1 E2.E2.D1" },
8157 { "root//elem[a $ile$ 'a2 field']", "E1.E2.D1 E2.E2.D1" },
8158 { "root//elem[a $igt$ 'a2 field']", "E3.E2.D1 E4.E2.D1" },
8159 { "root//elem[a $ige$ 'a3 field']", "E3.E2.D1 E4.E2.D1" },
8160 { "root//elem[$any$ *='B2 field']", "E2.E2.D1" },
8161 { "root//elem[$all$ *!='B2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
8162 { "root//elem[index()=0 or end()]", "E1.E2.D1 E4.E2.D1" },
8163 { "root//elem[index()=0 $or$ end()]", "E1.E2.D1 E4.E2.D1" },
8164 { "root//elem[index()=0 || end()]", "E1.E2.D1 E4.E2.D1" },
8165 { "root//elem[index()>0 and $not$ end()]", "E2.E2.D1 E3.E2.D1" },
8166 { "root//elem[index()>0 $and$ $not$ end()]", "E2.E2.D1 E3.E2.D1" },
8167 { "root//elem[index()>0 && $not$ end()]", "E2.E2.D1 E3.E2.D1" },
8168 { "root/elem[0]", "E1.E2.D1" },
8169 { "root/elem[index()=1]", "E2.E2.D1" },
8170 { "root/elem[index() $eq$ 1]", "E2.E2.D1" },
8171 { "root/elem[end()]", "E4.E2.D1" },
8172 { "root/elem[$not$ end()]", "E1.E2.D1 E2.E2.D1 E3.E2.D1" },
8173 { "root/elem[index() != 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
8174 { "root/elem[index() $ne$ 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
8175 { "root/elem[index() < 2]", "E1.E2.D1 E2.E2.D1" },
8176 { "root/elem[index() $lt$ 2]", "E1.E2.D1 E2.E2.D1" },
8177 { "root/elem[index() <= 1]", "E1.E2.D1 E2.E2.D1" },
8178 { "root/elem[index() $le$ 1]", "E1.E2.D1 E2.E2.D1" },
8179 { "root/elem[index() > 1]", "E3.E2.D1 E4.E2.D1" },
8180 { "root/elem[index() $gt$ 1]", "E3.E2.D1 E4.E2.D1" },
8181 { "root/elem[index() >= 2]", "E3.E2.D1 E4.E2.D1" },
8182 { "root/elem[index() $ge$ 2]", "E3.E2.D1 E4.E2.D1" },
8183 { "root/elem[a $ieq$ 'a2 field']", "E2.E2.D1" },
8184 { "root/elem[a $ine$ 'a2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
8185 { "root/elem[a $ilt$ 'a3 field']", "E1.E2.D1 E2.E2.D1" },
8186 { "root/elem[a $ile$ 'a2 field']", "E1.E2.D1 E2.E2.D1" },
8187 { "root/elem[a $igt$ 'a2 field']", "E3.E2.D1 E4.E2.D1" },
8188 { "root/elem[a $ige$ 'a3 field']", "E3.E2.D1 E4.E2.D1" },
8189 { "root/elem[$any$ *='B2 field']", "E2.E2.D1" },
8190 { "root/elem[$all$ *!='B2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
8191 { "root/elem[index()=0 or end()]", "E1.E2.D1 E4.E2.D1" },
8192 { "root/elem[index()=0 $or$ end()]", "E1.E2.D1 E4.E2.D1" },
8193 { "root/elem[index()=0 || end()]", "E1.E2.D1 E4.E2.D1" },
8194 { "root/elem[index()>0 and $not$ end()]", "E2.E2.D1 E3.E2.D1" },
8195 { "root/elem[index()>0 $and$ $not$ end()]", "E2.E2.D1 E3.E2.D1" },
8196 { "root/elem[index()>0 && $not$ end()]", "E2.E2.D1 E3.E2.D1" },
8197 { "root/elem[d]", "E1.E2.D1 E2.E2.D1 E4.E2.D1" },
8198 { NULL }
8201 static const xslpattern_test_t xslpattern_test_no_ns[] = {
8202 /* prefixes don't need to be registered, you may use them as they are in the doc */
8203 { "//bar:x", "E5.E1.E5.E1.E2.D1 E6.E2.E5.E1.E2.D1" },
8204 /* prefixes must be explicitly specified in the name */
8205 { "//foo:elem", "" },
8206 { "//foo:c", "E3.E4.E2.D1" },
8207 { NULL }
8210 static const xslpattern_test_t xslpattern_test_func[] = {
8211 { "attribute()", "" },
8212 { "attribute('depth')", "" },
8213 { "root/attribute('depth')", "A'depth'.E3.D1" },
8214 { "//x/attribute()", "A'id'.E3.E3.D1 A'depth'.E3.E3.D1" },
8215 { "//x//attribute(id)", NULL },
8216 { "//x//attribute('id')", "A'id'.E3.E3.D1 A'id'.E4.E3.E3.D1 A'id'.E5.E3.E3.D1 A'id'.E6.E3.E3.D1" },
8217 { "comment()", "C2.D1" },
8218 { "//comment()", "C2.D1 C1.E3.D1 C2.E3.E3.D1 C2.E4.E3.D1" },
8219 { "element()", "E3.D1" },
8220 { "root/y/element()", "E4.E4.E3.D1 E5.E4.E3.D1 E6.E4.E3.D1" },
8221 { "//element(a)", NULL },
8222 { "//element('a')", "E4.E3.E3.D1 E4.E4.E3.D1" },
8223 { "node()", "P1.D1 C2.D1 E3.D1" },
8224 { "//x/node()", "P1.E3.E3.D1 C2.E3.E3.D1 T3.E3.E3.D1 E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1" },
8225 { "//x/node()[nodeType()=1]", "E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1" },
8226 { "//x/node()[nodeType()=3]", "T3.E3.E3.D1" },
8227 { "//x/node()[nodeType()=7]", "P1.E3.E3.D1" },
8228 { "//x/node()[nodeType()=8]", "C2.E3.E3.D1" },
8229 { "pi()", "P1.D1" },
8230 { "//y/pi()", "P1.E4.E3.D1" },
8231 { "root/textnode()", "T2.E3.D1" },
8232 { "root/element()/textnode()", "T3.E3.E3.D1 T3.E4.E3.D1" },
8233 { NULL }
8236 static void test_XSLPattern(void)
8238 const xslpattern_test_t *ptr = xslpattern_test;
8239 IXMLDOMDocument2 *doc;
8240 IXMLDOMNodeList *list;
8241 VARIANT_BOOL b;
8242 HRESULT hr;
8243 LONG len;
8245 doc = create_document(&IID_IXMLDOMDocument2);
8246 if (!doc) return;
8248 b = VARIANT_FALSE;
8249 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
8250 EXPECT_HR(hr, S_OK);
8251 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8253 /* switch to XSLPattern */
8254 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern"));
8255 EXPECT_HR(hr, S_OK);
8257 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
8258 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list);
8259 EXPECT_HR(hr, S_OK);
8261 len = 0;
8262 hr = IXMLDOMNodeList_get_length(list, &len);
8263 EXPECT_HR(hr, S_OK);
8264 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
8265 ok(len == 3, "expected 3 entries in list, got %d\n", len);
8266 IXMLDOMNodeList_Release(list);
8268 while (ptr->query)
8270 list = NULL;
8271 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_(ptr->query), &list);
8272 ok(hr == S_OK, "query=%s, failed with 0x%08x\n", ptr->query, hr);
8273 len = 0;
8274 hr = IXMLDOMNodeList_get_length(list, &len);
8275 ok(len != 0, "query=%s, empty list\n", ptr->query);
8276 if (len)
8277 expect_list_and_release(list, ptr->list);
8279 ptr++;
8282 /* namespace handling */
8283 /* no registered namespaces */
8284 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_(""));
8285 EXPECT_HR(hr, S_OK);
8287 ptr = xslpattern_test_no_ns;
8288 while (ptr->query)
8290 list = NULL;
8291 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_(ptr->query), &list);
8292 ok(hr == S_OK, "query=%s, failed with 0x%08x\n", ptr->query, hr);
8294 if (*ptr->list)
8296 len = 0;
8297 hr = IXMLDOMNodeList_get_length(list, &len);
8298 EXPECT_HR(hr, S_OK);
8299 ok(len != 0, "query=%s, empty list\n", ptr->query);
8301 else
8303 len = 1;
8304 hr = IXMLDOMNodeList_get_length(list, &len);
8305 EXPECT_HR(hr, S_OK);
8306 ok(len == 0, "query=%s, empty list\n", ptr->query);
8308 if (len)
8309 expect_list_and_release(list, ptr->list);
8311 ptr++;
8314 /* explicitly register prefix foo */
8315 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
8317 /* now we get the same behavior as XPath */
8318 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list);
8319 EXPECT_HR(hr, S_OK);
8320 len = 0;
8321 hr = IXMLDOMNodeList_get_length(list, &len);
8322 EXPECT_HR(hr, S_OK);
8323 ok(len != 0, "expected filled list\n");
8324 if (len)
8325 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
8327 /* set prefix foo to some nonexistent namespace */
8328 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:nonexistent-foo'"));
8329 EXPECT_HR(hr, S_OK);
8331 /* the registered prefix takes precedence */
8332 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list);
8333 EXPECT_HR(hr, S_OK);
8334 len = 0;
8335 hr = IXMLDOMNodeList_get_length(list, &len);
8336 EXPECT_HR(hr, S_OK);
8337 ok(len == 0, "expected empty list\n");
8338 IXMLDOMNodeList_Release(list);
8340 IXMLDOMDocument2_Release(doc);
8342 doc = create_document(&IID_IXMLDOMDocument2);
8343 if (!doc) return;
8345 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNodeTypesXML), &b);
8346 EXPECT_HR(hr, S_OK);
8347 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8349 ptr = xslpattern_test_func;
8350 while (ptr->query)
8352 list = NULL;
8353 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_(ptr->query), &list);
8354 if (ptr->list)
8356 ok(hr == S_OK, "query=%s, failed with 0x%08x\n", ptr->query, hr);
8357 len = 0;
8358 hr = IXMLDOMNodeList_get_length(list, &len);
8359 if (*ptr->list)
8361 ok(len != 0, "query=%s, empty list\n", ptr->query);
8362 if (len)
8363 expect_list_and_release(list, ptr->list);
8365 else
8366 ok(len == 0, "query=%s, filled list\n", ptr->query);
8368 else
8369 ok(hr == E_FAIL, "query=%s, failed with 0x%08x\n", ptr->query, hr);
8371 ptr++;
8374 IXMLDOMDocument2_Release(doc);
8375 free_bstrs();
8378 static void test_splitText(void)
8380 IXMLDOMCDATASection *cdata;
8381 IXMLDOMElement *root;
8382 IXMLDOMDocument *doc;
8383 IXMLDOMText *text, *text2;
8384 IXMLDOMNode *node;
8385 VARIANT var;
8386 VARIANT_BOOL success;
8387 LONG length;
8388 HRESULT hr;
8390 doc = create_document(&IID_IXMLDOMDocument);
8391 if (!doc) return;
8393 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
8394 ok(hr == S_OK, "got 0x%08x\n", hr);
8396 hr = IXMLDOMDocument_get_documentElement(doc, &root);
8397 ok(hr == S_OK, "got 0x%08x\n", hr);
8399 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
8400 ok(hr == S_OK, "got 0x%08x\n", hr);
8402 V_VT(&var) = VT_EMPTY;
8403 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
8404 ok(hr == S_OK, "got 0x%08x\n", hr);
8406 length = 0;
8407 hr = IXMLDOMCDATASection_get_length(cdata, &length);
8408 ok(hr == S_OK, "got 0x%08x\n", hr);
8409 ok(length > 0, "got %d\n", length);
8411 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
8412 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8414 text = (void*)0xdeadbeef;
8415 /* negative offset */
8416 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
8417 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8418 ok(text == (void*)0xdeadbeef, "got %p\n", text);
8420 text = (void*)0xdeadbeef;
8421 /* offset outside data */
8422 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
8423 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8424 ok(text == 0, "got %p\n", text);
8426 text = (void*)0xdeadbeef;
8427 /* offset outside data */
8428 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
8429 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8430 ok(text == 0, "got %p\n", text);
8432 /* no empty node created */
8433 node = (void*)0xdeadbeef;
8434 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8435 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8436 ok(node == 0, "got %p\n", text);
8438 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
8439 ok(hr == S_OK, "got 0x%08x\n", hr);
8441 length = 0;
8442 hr = IXMLDOMText_get_length(text, &length);
8443 ok(hr == S_OK, "got 0x%08x\n", hr);
8444 ok(length == 7, "got %d\n", length);
8446 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8447 ok(hr == S_OK, "got 0x%08x\n", hr);
8448 IXMLDOMNode_Release(node);
8450 /* split new text node */
8451 hr = IXMLDOMText_get_length(text, &length);
8452 ok(hr == S_OK, "got 0x%08x\n", hr);
8454 node = (void*)0xdeadbeef;
8455 hr = IXMLDOMText_get_nextSibling(text, &node);
8456 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8457 ok(node == 0, "got %p\n", text);
8459 hr = IXMLDOMText_splitText(text, 0, NULL);
8460 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8462 text2 = (void*)0xdeadbeef;
8463 /* negative offset */
8464 hr = IXMLDOMText_splitText(text, -1, &text2);
8465 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8466 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
8468 text2 = (void*)0xdeadbeef;
8469 /* offset outside data */
8470 hr = IXMLDOMText_splitText(text, length + 1, &text2);
8471 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8472 ok(text2 == 0, "got %p\n", text2);
8474 text2 = (void*)0xdeadbeef;
8475 /* offset outside data */
8476 hr = IXMLDOMText_splitText(text, length, &text2);
8477 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8478 ok(text2 == 0, "got %p\n", text);
8480 text2 = 0;
8481 hr = IXMLDOMText_splitText(text, 4, &text2);
8482 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8483 if (text2) IXMLDOMText_Release(text2);
8485 node = 0;
8486 hr = IXMLDOMText_get_nextSibling(text, &node);
8487 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8488 if (node) IXMLDOMNode_Release(node);
8490 IXMLDOMText_Release(text);
8491 IXMLDOMElement_Release(root);
8492 IXMLDOMCDATASection_Release(cdata);
8493 free_bstrs();
8496 typedef struct {
8497 const char *name;
8498 const char *uri;
8499 HRESULT hr;
8500 } ns_item_t;
8502 /* default_ns_doc used */
8503 static const ns_item_t qualified_item_tests[] = {
8504 { "xml:lang", NULL, S_FALSE },
8505 { "xml:lang", "http://www.w3.org/XML/1998/namespace", S_FALSE },
8506 { "lang", "http://www.w3.org/XML/1998/namespace", S_OK },
8507 { "ns:b", NULL, S_FALSE },
8508 { "ns:b", "nshref", S_FALSE },
8509 { "b", "nshref", S_OK },
8510 { "d", NULL, S_OK },
8511 { NULL }
8514 static const ns_item_t named_item_tests[] = {
8515 { "xml:lang", NULL, S_OK },
8516 { "lang", NULL, S_FALSE },
8517 { "ns:b", NULL, S_OK },
8518 { "b", NULL, S_FALSE },
8519 { "d", NULL, S_OK },
8520 { NULL }
8523 static void test_getQualifiedItem(void)
8525 IXMLDOMNode *pr_node, *node;
8526 IXMLDOMNodeList *root_list;
8527 IXMLDOMNamedNodeMap *map;
8528 IXMLDOMElement *element;
8529 const ns_item_t* ptr;
8530 IXMLDOMDocument *doc;
8531 VARIANT_BOOL b;
8532 HRESULT hr;
8533 LONG len;
8535 doc = create_document(&IID_IXMLDOMDocument);
8536 if (!doc) return;
8538 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
8539 EXPECT_HR(hr, S_OK);
8540 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8542 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8543 EXPECT_HR(hr, S_OK);
8545 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8546 EXPECT_HR(hr, S_OK);
8548 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8549 EXPECT_HR(hr, S_OK);
8550 IXMLDOMNodeList_Release(root_list);
8552 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8553 EXPECT_HR(hr, S_OK);
8554 IXMLDOMNode_Release(pr_node);
8556 len = 0;
8557 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8558 EXPECT_HR(hr, S_OK);
8559 ok( len == 3, "length %d\n", len);
8561 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
8562 EXPECT_HR(hr, E_INVALIDARG);
8564 node = (void*)0xdeadbeef;
8565 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
8566 EXPECT_HR(hr, E_INVALIDARG);
8567 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8569 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
8570 EXPECT_HR(hr, E_INVALIDARG);
8572 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
8573 EXPECT_HR(hr, S_OK);
8575 IXMLDOMNode_Release(node);
8576 IXMLDOMNamedNodeMap_Release(map);
8577 IXMLDOMElement_Release(element);
8579 hr = IXMLDOMDocument_loadXML(doc, _bstr_(default_ns_doc), &b);
8580 EXPECT_HR(hr, S_OK);
8582 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("a"), &node);
8583 EXPECT_HR(hr, S_OK);
8585 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&element);
8586 EXPECT_HR(hr, S_OK);
8587 IXMLDOMNode_Release(node);
8589 hr = IXMLDOMElement_get_attributes(element, &map);
8590 EXPECT_HR(hr, S_OK);
8592 ptr = qualified_item_tests;
8593 while (ptr->name)
8595 node = (void*)0xdeadbeef;
8596 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_(ptr->name), _bstr_(ptr->uri), &node);
8597 ok(hr == ptr->hr, "%s, %s: got 0x%08x, expected 0x%08x\n", ptr->name, ptr->uri, hr, ptr->hr);
8598 if (hr == S_OK)
8599 IXMLDOMNode_Release(node);
8600 else
8601 ok(node == NULL, "%s, %s: got %p\n", ptr->name, ptr->uri, node);
8602 ptr++;
8605 ptr = named_item_tests;
8606 while (ptr->name)
8608 node = (void*)0xdeadbeef;
8609 hr = IXMLDOMNamedNodeMap_getNamedItem(map, _bstr_(ptr->name), &node);
8610 ok(hr == ptr->hr, "%s: got 0x%08x, expected 0x%08x\n", ptr->name, hr, ptr->hr);
8611 if (hr == S_OK)
8612 IXMLDOMNode_Release(node);
8613 else
8614 ok(node == NULL, "%s: got %p\n", ptr->name, node);
8615 ptr++;
8618 IXMLDOMNamedNodeMap_Release(map);
8620 IXMLDOMElement_Release(element);
8621 IXMLDOMDocument_Release(doc);
8622 free_bstrs();
8625 static void test_removeQualifiedItem(void)
8627 IXMLDOMDocument *doc;
8628 IXMLDOMElement *element;
8629 IXMLDOMNode *pr_node, *node;
8630 IXMLDOMNodeList *root_list;
8631 IXMLDOMNamedNodeMap *map;
8632 VARIANT_BOOL b;
8633 LONG len;
8634 HRESULT hr;
8636 doc = create_document(&IID_IXMLDOMDocument);
8637 if (!doc) return;
8639 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
8640 ok( hr == S_OK, "loadXML failed\n");
8641 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8643 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8644 ok( hr == S_OK, "ret %08x\n", hr);
8646 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8647 ok( hr == S_OK, "ret %08x\n", hr);
8649 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8650 ok( hr == S_OK, "ret %08x\n", hr);
8651 IXMLDOMNodeList_Release(root_list);
8653 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8654 ok( hr == S_OK, "ret %08x\n", hr);
8655 IXMLDOMNode_Release(pr_node);
8657 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8658 ok( hr == S_OK, "ret %08x\n", hr);
8659 ok( len == 3, "length %d\n", len);
8661 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
8662 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8664 node = (void*)0xdeadbeef;
8665 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
8666 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8667 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8669 /* out pointer is optional */
8670 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8671 ok( hr == S_OK, "ret %08x\n", hr);
8673 /* already removed */
8674 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8675 ok( hr == S_FALSE, "ret %08x\n", hr);
8677 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
8678 ok( hr == S_OK, "ret %08x\n", hr);
8679 IXMLDOMNode_Release(node);
8681 IXMLDOMNamedNodeMap_Release( map );
8682 IXMLDOMElement_Release( element );
8683 IXMLDOMDocument_Release( doc );
8684 free_bstrs();
8687 #define check_default_props(doc) _check_default_props(__LINE__, doc)
8688 static inline void _check_default_props(int line, IXMLDOMDocument2* doc)
8690 VARIANT_BOOL b;
8691 VARIANT var;
8692 HRESULT hr;
8694 VariantInit(&var);
8695 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8696 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
8697 VariantClear(&var);
8699 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8700 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("")) == 0, "expected empty string\n");
8701 VariantClear(&var);
8703 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8704 ok_(__FILE__, line)(b == VARIANT_FALSE, "expected FALSE\n");
8706 hr = IXMLDOMDocument2_get_schemas(doc, &var);
8707 ok_(__FILE__, line)(hr == S_FALSE, "got %08x\n", hr);
8708 VariantClear(&var);
8711 #define check_set_props(doc) _check_set_props(__LINE__, doc)
8712 static inline void _check_set_props(int line, IXMLDOMDocument2* doc)
8714 VARIANT_BOOL b;
8715 VARIANT var;
8717 VariantInit(&var);
8718 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8719 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
8720 VariantClear(&var);
8722 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8723 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&var)));
8724 VariantClear(&var);
8726 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8727 ok_(__FILE__, line)(b == VARIANT_TRUE, "expected TRUE\n");
8729 helper_ole_check(IXMLDOMDocument2_get_schemas(doc, &var));
8730 ok_(__FILE__, line)(V_VT(&var) != VT_NULL, "expected pointer\n");
8731 VariantClear(&var);
8734 #define set_props(doc, cache) _set_props(__LINE__, doc, cache)
8735 static inline void _set_props(int line, IXMLDOMDocument2* doc, IXMLDOMSchemaCollection* cache)
8737 VARIANT var;
8739 VariantInit(&var);
8740 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
8741 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'")));
8742 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_TRUE));
8743 V_VT(&var) = VT_DISPATCH;
8744 V_DISPATCH(&var) = NULL;
8745 helper_ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&var)));
8746 ok_(__FILE__, line)(V_DISPATCH(&var) != NULL, "expected pointer\n");
8747 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8748 VariantClear(&var);
8751 #define unset_props(doc) _unset_props(__LINE__, doc)
8752 static inline void _unset_props(int line, IXMLDOMDocument2* doc)
8754 VARIANT var;
8756 VariantInit(&var);
8757 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
8758 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
8759 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_FALSE));
8760 V_VT(&var) = VT_NULL;
8761 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8762 VariantClear(&var);
8765 static void test_get_ownerDocument(void)
8767 IXMLDOMDocument *doc1, *doc2, *doc3;
8768 IXMLDOMDocument2 *doc, *doc_owner;
8769 IXMLDOMNode *node;
8770 IXMLDOMSchemaCollection *cache;
8771 VARIANT_BOOL b;
8772 VARIANT var;
8774 doc = create_document(&IID_IXMLDOMDocument2);
8775 cache = create_cache(&IID_IXMLDOMSchemaCollection);
8776 if (!doc || !cache)
8778 if (doc) IXMLDOMDocument2_Release(doc);
8779 if (cache) IXMLDOMSchemaCollection_Release(cache);
8780 return;
8783 VariantInit(&var);
8785 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(complete4A), &b));
8786 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8788 check_default_props(doc);
8790 /* set properties and check that new instances use them */
8791 set_props(doc, cache);
8792 check_set_props(doc);
8794 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8795 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc1));
8797 /* new interface keeps props */
8798 ole_check(IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8799 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
8800 check_set_props(doc_owner);
8801 IXMLDOMDocument2_Release(doc_owner);
8803 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc2));
8804 IXMLDOMNode_Release(node);
8806 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
8808 /* reload */
8809 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(complete4A), &b));
8810 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8812 /* properties retained even after reload */
8813 check_set_props(doc);
8815 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8816 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc3));
8817 IXMLDOMNode_Release(node);
8819 ole_check(IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8820 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
8821 check_set_props(doc_owner);
8823 /* changing properties for one instance changes them for all */
8824 unset_props(doc_owner);
8825 check_default_props(doc_owner);
8826 check_default_props(doc);
8828 IXMLDOMSchemaCollection_Release(cache);
8829 IXMLDOMDocument_Release(doc1);
8830 IXMLDOMDocument_Release(doc2);
8831 IXMLDOMDocument_Release(doc3);
8832 IXMLDOMDocument2_Release(doc);
8833 IXMLDOMDocument2_Release(doc_owner);
8834 free_bstrs();
8837 static void test_setAttributeNode(void)
8839 IXMLDOMDocument *doc, *doc2;
8840 IXMLDOMElement *elem, *elem2;
8841 IXMLDOMAttribute *attr, *attr2, *ret_attr;
8842 VARIANT_BOOL b;
8843 HRESULT hr;
8844 VARIANT v;
8845 BSTR str;
8846 ULONG ref1, ref2;
8848 doc = create_document(&IID_IXMLDOMDocument);
8849 if (!doc) return;
8851 hr = IXMLDOMDocument2_loadXML( doc, _bstr_(complete4A), &b );
8852 ok( hr == S_OK, "loadXML failed\n");
8853 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8855 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8856 ok( hr == S_OK, "got 0x%08x\n", hr);
8858 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
8859 ok( hr == S_OK, "got 0x%08x\n", hr);
8860 ok( elem2 != elem, "got same instance\n");
8862 ret_attr = (void*)0xdeadbeef;
8863 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
8864 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8865 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8867 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8868 ok( hr == S_OK, "got 0x%08x\n", hr);
8870 ref1 = IXMLDOMElement_AddRef(elem);
8871 IXMLDOMElement_Release(elem);
8873 ret_attr = (void*)0xdeadbeef;
8874 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8875 ok( hr == S_OK, "got 0x%08x\n", hr);
8876 ok( ret_attr == NULL, "got %p\n", ret_attr);
8878 /* no reference added */
8879 ref2 = IXMLDOMElement_AddRef(elem);
8880 IXMLDOMElement_Release(elem);
8881 ok(ref2 == ref1, "got %d, expected %d\n", ref2, ref1);
8883 EXPECT_CHILDREN(elem);
8884 EXPECT_CHILDREN(elem2);
8886 IXMLDOMElement_Release(elem2);
8888 attr2 = NULL;
8889 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
8890 ok( hr == S_OK, "got 0x%08x\n", hr);
8891 ok( attr2 != attr, "got same instance %p\n", attr2);
8892 IXMLDOMAttribute_Release(attr2);
8894 /* try to add it another time */
8895 ret_attr = (void*)0xdeadbeef;
8896 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8897 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8898 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8900 IXMLDOMElement_Release(elem);
8902 /* initially used element is released, attribute still 'has' a container */
8903 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8904 ok( hr == S_OK, "got 0x%08x\n", hr);
8905 ret_attr = (void*)0xdeadbeef;
8906 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8907 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8908 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8909 IXMLDOMElement_Release(elem);
8911 /* add attribute already attached to another document */
8912 doc2 = create_document(&IID_IXMLDOMDocument);
8914 hr = IXMLDOMDocument_loadXML( doc2, _bstr_(complete4A), &b );
8915 ok( hr == S_OK, "loadXML failed\n");
8916 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8918 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
8919 ok( hr == S_OK, "got 0x%08x\n", hr);
8920 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
8921 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8922 IXMLDOMElement_Release(elem);
8924 IXMLDOMAttribute_Release(attr);
8926 /* create element, add attribute, see if it's copied or linked */
8927 hr = IXMLDOMDocument_createElement(doc, _bstr_("test"), &elem);
8928 ok( hr == S_OK, "got 0x%08x\n", hr);
8930 attr = NULL;
8931 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8932 ok(hr == S_OK, "got 0x%08x\n", hr);
8933 ok(attr != NULL, "got %p\n", attr);
8935 ref1 = IXMLDOMAttribute_AddRef(attr);
8936 IXMLDOMAttribute_Release(attr);
8938 V_VT(&v) = VT_BSTR;
8939 V_BSTR(&v) = _bstr_("attrvalue1");
8940 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8941 ok( hr == S_OK, "got 0x%08x\n", hr);
8943 str = NULL;
8944 hr = IXMLDOMAttribute_get_xml(attr, &str);
8945 ok( hr == S_OK, "got 0x%08x\n", hr);
8946 ok( lstrcmpW(str, _bstr_("attr=\"attrvalue1\"")) == 0,
8947 "got %s\n", wine_dbgstr_w(str));
8948 SysFreeString(str);
8950 ret_attr = (void*)0xdeadbeef;
8951 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8952 ok(hr == S_OK, "got 0x%08x\n", hr);
8953 ok(ret_attr == NULL, "got %p\n", ret_attr);
8955 /* attribute reference increased */
8956 ref2 = IXMLDOMAttribute_AddRef(attr);
8957 IXMLDOMAttribute_Release(attr);
8958 ok(ref1 == ref2, "got %d, expected %d\n", ref2, ref1);
8960 hr = IXMLDOMElement_get_xml(elem, &str);
8961 ok( hr == S_OK, "got 0x%08x\n", hr);
8962 ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue1\"/>")) == 0,
8963 "got %s\n", wine_dbgstr_w(str));
8964 SysFreeString(str);
8966 V_VT(&v) = VT_BSTR;
8967 V_BSTR(&v) = _bstr_("attrvalue2");
8968 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8969 ok( hr == S_OK, "got 0x%08x\n", hr);
8971 hr = IXMLDOMElement_get_xml(elem, &str);
8972 ok( hr == S_OK, "got 0x%08x\n", hr);
8973 todo_wine ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue2\"/>")) == 0,
8974 "got %s\n", wine_dbgstr_w(str));
8975 SysFreeString(str);
8977 IXMLDOMElement_Release(elem);
8978 IXMLDOMAttribute_Release(attr);
8979 IXMLDOMDocument_Release(doc2);
8980 IXMLDOMDocument_Release(doc);
8981 free_bstrs();
8984 static void test_createNode(void)
8986 IXMLDOMDocument *doc;
8987 IXMLDOMElement *elem;
8988 IXMLDOMNode *node;
8989 VARIANT v, var;
8990 BSTR prefix, str;
8991 HRESULT hr;
8992 ULONG ref;
8994 doc = create_document(&IID_IXMLDOMDocument);
8995 if (!doc) return;
8997 EXPECT_REF(doc, 1);
8999 /* reference count tests */
9000 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
9001 ok( hr == S_OK, "got 0x%08x\n", hr);
9003 /* initial reference is 2 */
9004 todo_wine {
9005 EXPECT_REF(elem, 2);
9006 ref = IXMLDOMElement_Release(elem);
9007 ok(ref == 1, "got %d\n", ref);
9008 /* it's released already, attempt to release now will crash it */
9011 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
9012 ok( hr == S_OK, "got 0x%08x\n", hr);
9013 todo_wine EXPECT_REF(elem, 2);
9014 IXMLDOMDocument_Release(doc);
9015 todo_wine EXPECT_REF(elem, 2);
9016 IXMLDOMElement_Release(elem);
9018 doc = create_document(&IID_IXMLDOMDocument);
9020 /* NODE_ELEMENT nodes */
9021 /* 1. specified namespace */
9022 V_VT(&v) = VT_I4;
9023 V_I4(&v) = NODE_ELEMENT;
9025 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
9026 ok( hr == S_OK, "got 0x%08x\n", hr);
9027 prefix = NULL;
9028 hr = IXMLDOMNode_get_prefix(node, &prefix);
9029 ok( hr == S_OK, "got 0x%08x\n", hr);
9030 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
9031 SysFreeString(prefix);
9032 IXMLDOMNode_Release(node);
9034 /* 2. default namespace */
9035 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
9036 ok( hr == S_OK, "got 0x%08x\n", hr);
9037 prefix = (void*)0xdeadbeef;
9038 hr = IXMLDOMNode_get_prefix(node, &prefix);
9039 ok( hr == S_FALSE, "got 0x%08x\n", hr);
9040 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
9041 /* check dump */
9042 hr = IXMLDOMNode_get_xml(node, &str);
9043 ok( hr == S_OK, "got 0x%08x\n", hr);
9044 ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0,
9045 "got %s\n", wine_dbgstr_w(str));
9046 SysFreeString(str);
9048 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
9049 ok( hr == S_OK, "got 0x%08x\n", hr);
9051 V_VT(&var) = VT_BSTR;
9052 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
9053 ok( hr == S_FALSE, "got 0x%08x\n", hr);
9054 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
9056 str = NULL;
9057 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
9058 ok( hr == S_OK, "got 0x%08x\n", hr);
9059 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
9060 SysFreeString(str);
9062 IXMLDOMElement_Release(elem);
9063 IXMLDOMNode_Release(node);
9065 IXMLDOMDocument_Release(doc);
9066 free_bstrs();
9069 static const char get_prefix_doc[] =
9070 "<?xml version=\"1.0\" ?>"
9071 "<a xmlns:ns1=\"ns1 href\" />";
9073 static void test_get_prefix(void)
9075 IXMLDOMDocumentFragment *fragment;
9076 IXMLDOMCDATASection *cdata;
9077 IXMLDOMElement *element;
9078 IXMLDOMComment *comment;
9079 IXMLDOMDocument *doc;
9080 VARIANT_BOOL b;
9081 HRESULT hr;
9082 BSTR str;
9084 doc = create_document(&IID_IXMLDOMDocument);
9085 if (!doc) return;
9087 /* nodes that can't support prefix */
9088 /* 1. document */
9089 str = (void*)0xdeadbeef;
9090 hr = IXMLDOMDocument_get_prefix(doc, &str);
9091 EXPECT_HR(hr, S_FALSE);
9092 ok(str == NULL, "got %p\n", str);
9094 hr = IXMLDOMDocument_get_prefix(doc, NULL);
9095 EXPECT_HR(hr, E_INVALIDARG);
9097 /* 2. cdata */
9098 hr = IXMLDOMDocument_createCDATASection(doc, NULL, &cdata);
9099 ok(hr == S_OK, "got %08x\n", hr );
9101 str = (void*)0xdeadbeef;
9102 hr = IXMLDOMCDATASection_get_prefix(cdata, &str);
9103 ok(hr == S_FALSE, "got %08x\n", hr);
9104 ok( str == 0, "got %p\n", str);
9106 hr = IXMLDOMCDATASection_get_prefix(cdata, NULL);
9107 ok(hr == E_INVALIDARG, "got %08x\n", hr);
9108 IXMLDOMCDATASection_Release(cdata);
9110 /* 3. comment */
9111 hr = IXMLDOMDocument_createComment(doc, NULL, &comment);
9112 ok(hr == S_OK, "got %08x\n", hr );
9114 str = (void*)0xdeadbeef;
9115 hr = IXMLDOMComment_get_prefix(comment, &str);
9116 ok(hr == S_FALSE, "got %08x\n", hr);
9117 ok( str == 0, "got %p\n", str);
9119 hr = IXMLDOMComment_get_prefix(comment, NULL);
9120 ok(hr == E_INVALIDARG, "got %08x\n", hr);
9121 IXMLDOMComment_Release(comment);
9123 /* 4. fragment */
9124 hr = IXMLDOMDocument_createDocumentFragment(doc, &fragment);
9125 ok(hr == S_OK, "got %08x\n", hr );
9127 str = (void*)0xdeadbeef;
9128 hr = IXMLDOMDocumentFragment_get_prefix(fragment, &str);
9129 ok(hr == S_FALSE, "got %08x\n", hr);
9130 ok( str == 0, "got %p\n", str);
9132 hr = IXMLDOMDocumentFragment_get_prefix(fragment, NULL);
9133 ok(hr == E_INVALIDARG, "got %08x\n", hr);
9134 IXMLDOMDocumentFragment_Release(fragment);
9136 /* no prefix */
9137 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
9138 ok( hr == S_OK, "got 0x%08x\n", hr);
9140 hr = IXMLDOMElement_get_prefix(element, NULL);
9141 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
9143 str = (void*)0xdeadbeef;
9144 hr = IXMLDOMElement_get_prefix(element, &str);
9145 ok( hr == S_FALSE, "got 0x%08x\n", hr);
9146 ok( str == 0, "got %p\n", str);
9148 IXMLDOMElement_Release(element);
9150 /* with prefix */
9151 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
9152 ok( hr == S_OK, "got 0x%08x\n", hr);
9154 str = (void*)0xdeadbeef;
9155 hr = IXMLDOMElement_get_prefix(element, &str);
9156 ok( hr == S_OK, "got 0x%08x\n", hr);
9157 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
9158 SysFreeString(str);
9160 str = (void*)0xdeadbeef;
9161 hr = IXMLDOMElement_get_namespaceURI(element, &str);
9162 ok( hr == S_FALSE, "got 0x%08x\n", hr);
9163 ok( str == 0, "got %p\n", str);
9165 IXMLDOMElement_Release(element);
9167 hr = IXMLDOMDocument_loadXML(doc, _bstr_(get_prefix_doc), &b);
9168 EXPECT_HR(hr, S_OK);
9170 hr = IXMLDOMDocument_get_documentElement(doc, &element);
9171 EXPECT_HR(hr, S_OK);
9173 str = (void*)0xdeadbeef;
9174 hr = IXMLDOMElement_get_prefix(element, &str);
9175 EXPECT_HR(hr, S_FALSE);
9176 ok(str == NULL, "got %p\n", str);
9178 str = (void*)0xdeadbeef;
9179 hr = IXMLDOMElement_get_namespaceURI(element, &str);
9180 EXPECT_HR(hr, S_FALSE);
9181 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
9183 IXMLDOMDocument_Release(doc);
9184 free_bstrs();
9187 static void test_selectSingleNode(void)
9189 IXMLDOMDocument *doc;
9190 IXMLDOMNodeList *list;
9191 IXMLDOMNode *node;
9192 VARIANT_BOOL b;
9193 HRESULT hr;
9194 LONG len;
9196 doc = create_document(&IID_IXMLDOMDocument);
9197 if (!doc) return;
9199 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
9200 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9202 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
9203 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9205 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
9206 ok( hr == S_OK, "loadXML failed\n");
9207 ok( b == VARIANT_TRUE, "failed to load XML string\n");
9209 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
9210 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9212 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
9213 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9215 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
9216 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9218 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
9219 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9221 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
9222 ok(hr == S_OK, "got 0x%08x\n", hr);
9223 IXMLDOMNode_Release(node);
9225 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
9226 ok(hr == S_OK, "got 0x%08x\n", hr);
9227 IXMLDOMNodeList_Release(list);
9229 list = (void*)0xdeadbeef;
9230 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
9231 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9232 ok(list == (void*)0xdeadbeef, "got %p\n", list);
9234 node = (void*)0xdeadbeef;
9235 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
9236 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9237 ok(node == 0, "got %p\n", node);
9239 list = (void*)0xdeadbeef;
9240 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
9241 ok(hr == S_OK, "got 0x%08x\n", hr);
9242 len = 1;
9243 hr = IXMLDOMNodeList_get_length(list, &len);
9244 ok(hr == S_OK, "got 0x%08x\n", hr);
9245 ok(len == 0, "got %d\n", len);
9246 IXMLDOMNodeList_Release(list);
9248 IXMLDOMDocument_Release(doc);
9249 free_bstrs();
9252 static void test_events(void)
9254 IConnectionPointContainer *conn;
9255 IConnectionPoint *point;
9256 IXMLDOMDocument *doc;
9257 HRESULT hr;
9258 VARIANT v;
9259 IDispatch *event;
9261 doc = create_document(&IID_IXMLDOMDocument);
9262 if (!doc) return;
9264 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&conn);
9265 ok(hr == S_OK, "got 0x%08x\n", hr);
9267 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IDispatch, &point);
9268 ok(hr == S_OK, "got 0x%08x\n", hr);
9269 IConnectionPoint_Release(point);
9270 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IPropertyNotifySink, &point);
9271 ok(hr == S_OK, "got 0x%08x\n", hr);
9272 IConnectionPoint_Release(point);
9273 hr = IConnectionPointContainer_FindConnectionPoint(conn, &DIID_XMLDOMDocumentEvents, &point);
9274 ok(hr == S_OK, "got 0x%08x\n", hr);
9275 IConnectionPoint_Release(point);
9277 IConnectionPointContainer_Release(conn);
9279 /* ready state callback */
9280 VariantInit(&v);
9281 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
9282 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
9284 event = create_dispevent();
9285 V_VT(&v) = VT_UNKNOWN;
9286 V_UNKNOWN(&v) = (IUnknown*)event;
9288 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
9289 ok(hr == S_OK, "got 0x%08x\n", hr);
9290 EXPECT_REF(event, 2);
9292 V_VT(&v) = VT_DISPATCH;
9293 V_DISPATCH(&v) = event;
9295 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
9296 ok(hr == S_OK, "got 0x%08x\n", hr);
9297 EXPECT_REF(event, 2);
9299 /* VT_NULL doesn't reset event handler */
9300 V_VT(&v) = VT_NULL;
9301 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
9302 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
9303 EXPECT_REF(event, 2);
9305 V_VT(&v) = VT_DISPATCH;
9306 V_DISPATCH(&v) = NULL;
9308 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
9309 ok(hr == S_OK, "got 0x%08x\n", hr);
9310 EXPECT_REF(event, 1);
9312 V_VT(&v) = VT_UNKNOWN;
9313 V_DISPATCH(&v) = NULL;
9314 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
9315 ok(hr == S_OK, "got 0x%08x\n", hr);
9317 IDispatch_Release(event);
9319 IXMLDOMDocument_Release(doc);
9322 static void test_createProcessingInstruction(void)
9324 static const WCHAR bodyW[] = {'t','e','s','t',0};
9325 IXMLDOMProcessingInstruction *pi;
9326 IXMLDOMDocument *doc;
9327 WCHAR buff[10];
9328 HRESULT hr;
9330 doc = create_document(&IID_IXMLDOMDocument);
9331 if (!doc) return;
9333 /* test for BSTR handling, pass broken BSTR */
9334 memcpy(&buff[2], bodyW, sizeof(bodyW));
9335 /* just a big length */
9336 *(DWORD*)buff = 0xf0f0;
9337 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("test"), &buff[2], &pi);
9338 ok(hr == S_OK, "got 0x%08x\n", hr);
9340 IXMLDOMProcessingInstruction_Release(pi);
9341 IXMLDOMDocument_Release(doc);
9344 static void test_put_nodeTypedValue(void)
9346 static const BYTE binhexdata[16] =
9347 {0,1,2,3,4,5,6,7,8,9,0xa,0xb,0xc,0xd,0xe,0xf};
9348 IXMLDOMDocument *doc;
9349 IXMLDOMElement *elem;
9350 VARIANT type, value;
9351 LONG ubound, lbound;
9352 IXMLDOMNode *node;
9353 SAFEARRAY *array;
9354 HRESULT hr;
9355 BYTE *ptr;
9356 BSTR str;
9358 doc = create_document(&IID_IXMLDOMDocument);
9359 if (!doc) return;
9361 hr = IXMLDOMDocument_createElement(doc, _bstr_("Element"), &elem);
9362 EXPECT_HR(hr, S_OK);
9364 V_VT(&type) = VT_EMPTY;
9365 hr = IXMLDOMElement_get_dataType(elem, &type);
9366 EXPECT_HR(hr, S_FALSE);
9367 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
9369 /* set typed value for untyped node */
9370 V_VT(&type) = VT_I1;
9371 V_I1(&type) = 1;
9372 hr = IXMLDOMElement_put_nodeTypedValue(elem, type);
9373 EXPECT_HR(hr, S_OK);
9375 V_VT(&type) = VT_EMPTY;
9376 hr = IXMLDOMElement_get_dataType(elem, &type);
9377 EXPECT_HR(hr, S_FALSE);
9378 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
9380 /* no type info stored */
9381 V_VT(&type) = VT_EMPTY;
9382 hr = IXMLDOMElement_get_nodeTypedValue(elem, &type);
9383 EXPECT_HR(hr, S_OK);
9384 ok(V_VT(&type) == VT_BSTR, "got %d, expected VT_BSTR\n", V_VT(&type));
9385 ok(memcmp(V_BSTR(&type), _bstr_("1"), 2*sizeof(WCHAR)) == 0,
9386 "got %s, expected \"1\"\n", wine_dbgstr_w(V_BSTR(&type)));
9387 VariantClear(&type);
9389 hr = IXMLDOMElement_get_firstChild(elem, &node);
9390 EXPECT_HR(hr, S_OK);
9391 hr = IXMLDOMElement_removeChild(elem, node, NULL);
9392 EXPECT_HR(hr, S_OK);
9393 IXMLDOMNode_Release(node);
9395 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)elem, NULL);
9396 EXPECT_HR(hr, S_OK);
9398 /* bin.base64 */
9399 hr = IXMLDOMElement_put_dataType(elem, _bstr_("bin.base64"));
9400 EXPECT_HR(hr, S_OK);
9402 V_VT(&value) = VT_BSTR;
9403 V_BSTR(&value) = _bstr_("ABCD");
9404 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
9405 EXPECT_HR(hr, S_OK);
9407 V_VT(&value) = VT_EMPTY;
9408 hr = IXMLDOMElement_get_nodeTypedValue(elem, &value);
9409 EXPECT_HR(hr, S_OK);
9410 ok(V_VT(&value) == (VT_UI1|VT_ARRAY), "got %d\n", V_VT(&value));
9411 ok(SafeArrayGetDim(V_ARRAY(&value)) == 1, "got wrong dimension\n");
9412 ubound = 0;
9413 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
9414 EXPECT_HR(hr, S_OK);
9415 ok(ubound == 2, "got %d\n", ubound);
9416 lbound = 0;
9417 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
9418 EXPECT_HR(hr, S_OK);
9419 ok(lbound == 0, "got %d\n", lbound);
9420 hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
9421 EXPECT_HR(hr, S_OK);
9422 ok(ptr[0] == 0, "got %x\n", ptr[0]);
9423 ok(ptr[1] == 0x10, "got %x\n", ptr[1]);
9424 ok(ptr[2] == 0x83, "got %x\n", ptr[2]);
9425 SafeArrayUnaccessData(V_ARRAY(&value));
9426 VariantClear(&value);
9428 /* when set as VT_BSTR it's stored as is */
9429 hr = IXMLDOMElement_get_firstChild(elem, &node);
9430 EXPECT_HR(hr, S_OK);
9431 hr = IXMLDOMNode_get_text(node, &str);
9432 EXPECT_HR(hr, S_OK);
9433 ok(!lstrcmpW(str, _bstr_("ABCD")), "%s\n", wine_dbgstr_w(str));
9434 IXMLDOMNode_Release(node);
9436 array = SafeArrayCreateVector(VT_UI1, 0, 7);
9437 hr = SafeArrayAccessData(array, (void*)&ptr);
9438 EXPECT_HR(hr, S_OK);
9439 memcpy(ptr, "dGVzdA=", strlen("dGVzdA="));
9440 SafeArrayUnaccessData(array);
9442 V_VT(&value) = VT_UI1|VT_ARRAY;
9443 V_ARRAY(&value) = array;
9444 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
9445 EXPECT_HR(hr, S_OK);
9447 V_VT(&value) = VT_EMPTY;
9448 hr = IXMLDOMElement_get_nodeTypedValue(elem, &value);
9449 EXPECT_HR(hr, S_OK);
9450 ok(V_VT(&value) == (VT_UI1|VT_ARRAY), "got %d\n", V_VT(&value));
9451 ok(SafeArrayGetDim(V_ARRAY(&value)) == 1, "got wrong dimension\n");
9452 ubound = 0;
9453 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
9454 EXPECT_HR(hr, S_OK);
9455 ok(ubound == 6, "got %d\n", ubound);
9456 lbound = 0;
9457 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
9458 EXPECT_HR(hr, S_OK);
9459 ok(lbound == 0, "got %d\n", lbound);
9460 hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
9461 EXPECT_HR(hr, S_OK);
9462 ok(!memcmp(ptr, "dGVzdA=", strlen("dGVzdA=")), "got wrong data, %s\n", ptr);
9463 SafeArrayUnaccessData(V_ARRAY(&value));
9464 VariantClear(&value);
9466 /* if set with VT_UI1|VT_ARRAY it's encoded */
9467 hr = IXMLDOMElement_get_firstChild(elem, &node);
9468 EXPECT_HR(hr, S_OK);
9469 hr = IXMLDOMNode_get_text(node, &str);
9470 EXPECT_HR(hr, S_OK);
9471 ok(!lstrcmpW(str, _bstr_("ZEdWemRBPQ==")), "%s\n", wine_dbgstr_w(str));
9472 IXMLDOMNode_Release(node);
9473 SafeArrayDestroyData(array);
9475 /* bin.hex */
9476 V_VT(&value) = VT_BSTR;
9477 V_BSTR(&value) = _bstr_("");
9478 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
9479 EXPECT_HR(hr, S_OK);
9481 hr = IXMLDOMElement_put_dataType(elem, _bstr_("bin.hex"));
9482 EXPECT_HR(hr, S_OK);
9484 array = SafeArrayCreateVector(VT_UI1, 0, 16);
9485 hr = SafeArrayAccessData(array, (void*)&ptr);
9486 EXPECT_HR(hr, S_OK);
9487 memcpy(ptr, binhexdata, sizeof(binhexdata));
9488 SafeArrayUnaccessData(array);
9490 V_VT(&value) = VT_UI1|VT_ARRAY;
9491 V_ARRAY(&value) = array;
9492 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
9493 EXPECT_HR(hr, S_OK);
9495 V_VT(&value) = VT_EMPTY;
9496 hr = IXMLDOMElement_get_nodeTypedValue(elem, &value);
9497 EXPECT_HR(hr, S_OK);
9498 ok(V_VT(&value) == (VT_UI1|VT_ARRAY), "got %d\n", V_VT(&value));
9499 ok(SafeArrayGetDim(V_ARRAY(&value)) == 1, "got wrong dimension\n");
9500 ubound = 0;
9501 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
9502 EXPECT_HR(hr, S_OK);
9503 ok(ubound == 15, "got %d\n", ubound);
9504 lbound = 0;
9505 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
9506 EXPECT_HR(hr, S_OK);
9507 ok(lbound == 0, "got %d\n", lbound);
9508 hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
9509 EXPECT_HR(hr, S_OK);
9510 ok(!memcmp(ptr, binhexdata, sizeof(binhexdata)), "got wrong data\n");
9511 SafeArrayUnaccessData(V_ARRAY(&value));
9512 VariantClear(&value);
9514 /* if set with VT_UI1|VT_ARRAY it's encoded */
9515 hr = IXMLDOMElement_get_firstChild(elem, &node);
9516 EXPECT_HR(hr, S_OK);
9517 hr = IXMLDOMNode_get_text(node, &str);
9518 EXPECT_HR(hr, S_OK);
9519 ok(!lstrcmpW(str, _bstr_("000102030405060708090a0b0c0d0e0f")), "%s\n", wine_dbgstr_w(str));
9520 IXMLDOMNode_Release(node);
9521 SafeArrayDestroyData(array);
9523 IXMLDOMElement_Release(elem);
9524 IXMLDOMDocument_Release(doc);
9525 free_bstrs();
9528 static void test_get_xml(void)
9530 static const char xmlA[] = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<a>test</a>\r\n";
9531 static const char fooA[] = "<foo/>";
9532 IXMLDOMProcessingInstruction *pi;
9533 IXMLDOMNode *first;
9534 IXMLDOMElement *elem = NULL;
9535 IXMLDOMDocument *doc;
9536 VARIANT_BOOL b;
9537 VARIANT v;
9538 BSTR xml;
9539 HRESULT hr;
9541 doc = create_document(&IID_IXMLDOMDocument);
9542 if (!doc) return;
9544 b = VARIANT_TRUE;
9545 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
9546 ok(hr == S_OK, "got 0x%08x\n", hr);
9547 ok( b == VARIANT_TRUE, "got %d\n", b);
9549 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"),
9550 _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &pi);
9551 ok(hr == S_OK, "got 0x%08x\n", hr);
9553 hr = IXMLDOMDocument_get_firstChild(doc, &first);
9554 ok(hr == S_OK, "got 0x%08x\n", hr);
9556 V_UNKNOWN(&v) = (IUnknown*)first;
9557 V_VT(&v) = VT_UNKNOWN;
9559 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)pi, v, NULL);
9560 ok(hr == S_OK, "got 0x%08x\n", hr);
9562 IXMLDOMProcessingInstruction_Release(pi);
9563 IXMLDOMNode_Release(first);
9565 hr = IXMLDOMDocument_get_xml(doc, &xml);
9566 ok(hr == S_OK, "got 0x%08x\n", hr);
9568 ok(memcmp(xml, _bstr_(xmlA), sizeof(xmlA)*sizeof(WCHAR)) == 0,
9569 "got %s, expected %s\n", wine_dbgstr_w(xml), xmlA);
9570 SysFreeString(xml);
9572 IXMLDOMDocument_Release(doc);
9574 doc = create_document(&IID_IXMLDOMDocument);
9576 hr = IXMLDOMDocument_createElement(doc, _bstr_("foo"), &elem);
9577 ok(hr == S_OK, "got 0x%08x\n", hr);
9579 hr = IXMLDOMDocument_putref_documentElement(doc, elem);
9580 ok(hr == S_OK, "got 0x%08x\n", hr);
9582 hr = IXMLDOMDocument_get_xml(doc, &xml);
9583 ok(hr == S_OK, "got 0x%08x\n", hr);
9585 ok(memcmp(xml, _bstr_(fooA), (sizeof(fooA)-1)*sizeof(WCHAR)) == 0,
9586 "got %s, expected %s\n", wine_dbgstr_w(xml), fooA);
9587 SysFreeString(xml);
9589 IXMLDOMElement_Release(elem);
9590 IXMLDOMDocument_Release(doc);
9592 free_bstrs();
9595 static void test_xsltemplate(void)
9597 IXSLTemplate *template;
9598 IXSLProcessor *processor;
9599 IXMLDOMDocument *doc, *doc2;
9600 IStream *stream;
9601 VARIANT_BOOL b;
9602 HRESULT hr;
9603 ULONG ref1, ref2;
9604 VARIANT v;
9606 template = create_xsltemplate(&IID_IXSLTemplate);
9607 if (!template) return;
9609 /* works as reset */
9610 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9611 ok(hr == S_OK, "got 0x%08x\n", hr);
9613 doc = create_document(&IID_IXMLDOMDocument);
9615 b = VARIANT_TRUE;
9616 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
9617 ok(hr == S_OK, "got 0x%08x\n", hr);
9618 ok( b == VARIANT_TRUE, "got %d\n", b);
9620 /* putref with non-xsl document */
9621 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9622 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9624 b = VARIANT_TRUE;
9625 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9626 ok(hr == S_OK, "got 0x%08x\n", hr);
9627 ok( b == VARIANT_TRUE, "got %d\n", b);
9629 /* not a freethreaded document */
9630 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9631 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9633 IXMLDOMDocument_Release(doc);
9635 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
9636 if (hr != S_OK)
9638 win_skip("failed to create free threaded document instance: 0x%08x\n", hr);
9639 IXSLTemplate_Release(template);
9640 return;
9643 b = VARIANT_TRUE;
9644 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9645 ok(hr == S_OK, "got 0x%08x\n", hr);
9646 ok( b == VARIANT_TRUE, "got %d\n", b);
9648 /* freethreaded document */
9649 ref1 = IXMLDOMDocument_AddRef(doc);
9650 IXMLDOMDocument_Release(doc);
9651 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9652 ok(hr == S_OK, "got 0x%08x\n", hr);
9653 ref2 = IXMLDOMDocument_AddRef(doc);
9654 IXMLDOMDocument_Release(doc);
9655 ok(ref2 > ref1, "got %d\n", ref2);
9657 /* processor */
9658 hr = IXSLTemplate_createProcessor(template, NULL);
9659 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9661 EXPECT_REF(template, 1);
9662 hr = IXSLTemplate_createProcessor(template, &processor);
9663 ok(hr == S_OK, "got 0x%08x\n", hr);
9664 EXPECT_REF(template, 2);
9666 /* input no set yet */
9667 V_VT(&v) = VT_BSTR;
9668 V_BSTR(&v) = NULL;
9669 hr = IXSLProcessor_get_input(processor, &v);
9670 todo_wine {
9671 ok(hr == S_OK, "got 0x%08x\n", hr);
9672 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
9675 hr = IXSLProcessor_get_output(processor, NULL);
9676 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9678 /* reset before it was set */
9679 V_VT(&v) = VT_EMPTY;
9680 hr = IXSLProcessor_put_output(processor, v);
9681 ok(hr == S_OK, "got 0x%08x\n", hr);
9683 CreateStreamOnHGlobal(NULL, TRUE, &stream);
9684 EXPECT_REF(stream, 1);
9686 V_VT(&v) = VT_UNKNOWN;
9687 V_UNKNOWN(&v) = (IUnknown*)stream;
9688 hr = IXSLProcessor_put_output(processor, v);
9689 ok(hr == S_OK, "got 0x%08x\n", hr);
9691 /* it seems processor grabs 2 references */
9692 todo_wine EXPECT_REF(stream, 3);
9694 V_VT(&v) = VT_EMPTY;
9695 hr = IXSLProcessor_get_output(processor, &v);
9696 ok(hr == S_OK, "got 0x%08x\n", hr);
9697 ok(V_VT(&v) == VT_UNKNOWN, "got type %d\n", V_VT(&v));
9698 ok(V_UNKNOWN(&v) == (IUnknown*)stream, "got %p\n", V_UNKNOWN(&v));
9700 todo_wine EXPECT_REF(stream, 4);
9701 VariantClear(&v);
9703 hr = IXSLProcessor_transform(processor, NULL);
9704 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9706 /* reset and check stream refcount */
9707 V_VT(&v) = VT_EMPTY;
9708 hr = IXSLProcessor_put_output(processor, v);
9709 ok(hr == S_OK, "got 0x%08x\n", hr);
9711 EXPECT_REF(stream, 1);
9713 IStream_Release(stream);
9715 /* no output interface set, check output */
9716 doc2 = create_document(&IID_IXMLDOMDocument);
9718 b = VARIANT_TRUE;
9719 hr = IXMLDOMDocument_loadXML( doc2, _bstr_("<a>test</a>"), &b );
9720 ok(hr == S_OK, "got 0x%08x\n", hr);
9721 ok( b == VARIANT_TRUE, "got %d\n", b);
9723 V_VT(&v) = VT_UNKNOWN;
9724 V_UNKNOWN(&v) = (IUnknown*)doc2;
9725 hr = IXSLProcessor_put_input(processor, v);
9726 ok(hr == S_OK, "got 0x%08x\n", hr);
9728 hr = IXSLProcessor_transform(processor, &b);
9729 ok(hr == S_OK, "got 0x%08x\n", hr);
9731 V_VT(&v) = VT_EMPTY;
9732 hr = IXSLProcessor_get_output(processor, &v);
9733 ok(hr == S_OK, "got 0x%08x\n", hr);
9734 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
9735 /* we currently output one '\n' instead of empty string */
9736 todo_wine ok(lstrcmpW(V_BSTR(&v), _bstr_("")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
9737 IXMLDOMDocument_Release(doc2);
9738 VariantClear(&v);
9740 IXSLProcessor_Release(processor);
9742 /* drop reference */
9743 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9744 ok(hr == S_OK, "got 0x%08x\n", hr);
9745 ref2 = IXMLDOMDocument_AddRef(doc);
9746 IXMLDOMDocument_Release(doc);
9747 ok(ref2 == ref1, "got %d\n", ref2);
9749 IXMLDOMDocument_Release(doc);
9750 IXSLTemplate_Release(template);
9751 free_bstrs();
9754 static void test_insertBefore(void)
9756 IXMLDOMDocument *doc, *doc2;
9757 IXMLDOMAttribute *attr;
9758 IXMLDOMElement *elem1, *elem2, *elem3, *elem4, *elem5;
9759 IXMLDOMNode *node, *newnode;
9760 HRESULT hr;
9761 VARIANT v;
9762 BSTR p;
9764 doc = create_document(&IID_IXMLDOMDocument);
9766 /* insertBefore behaviour for attribute node */
9767 V_VT(&v) = VT_I4;
9768 V_I4(&v) = NODE_ATTRIBUTE;
9770 attr = NULL;
9771 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr"), NULL, (IXMLDOMNode**)&attr);
9772 ok(hr == S_OK, "got 0x%08x\n", hr);
9773 ok(attr != NULL, "got %p\n", attr);
9775 /* attribute to attribute */
9776 V_VT(&v) = VT_I4;
9777 V_I4(&v) = NODE_ATTRIBUTE;
9778 newnode = NULL;
9779 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr2"), NULL, &newnode);
9780 ok(hr == S_OK, "got 0x%08x\n", hr);
9781 ok(newnode != NULL, "got %p\n", newnode);
9783 V_VT(&v) = VT_NULL;
9784 node = (void*)0xdeadbeef;
9785 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9786 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9787 ok(node == NULL, "got %p\n", node);
9789 V_VT(&v) = VT_UNKNOWN;
9790 V_UNKNOWN(&v) = (IUnknown*)attr;
9791 node = (void*)0xdeadbeef;
9792 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9793 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9794 ok(node == NULL, "got %p\n", node);
9795 IXMLDOMNode_Release(newnode);
9797 /* cdata to attribute */
9798 V_VT(&v) = VT_I4;
9799 V_I4(&v) = NODE_CDATA_SECTION;
9800 newnode = NULL;
9801 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9802 ok(hr == S_OK, "got 0x%08x\n", hr);
9803 ok(newnode != NULL, "got %p\n", newnode);
9805 V_VT(&v) = VT_NULL;
9806 node = (void*)0xdeadbeef;
9807 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9808 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9809 ok(node == NULL, "got %p\n", node);
9810 IXMLDOMNode_Release(newnode);
9812 /* comment to attribute */
9813 V_VT(&v) = VT_I4;
9814 V_I4(&v) = NODE_COMMENT;
9815 newnode = NULL;
9816 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9817 ok(hr == S_OK, "got 0x%08x\n", hr);
9818 ok(newnode != NULL, "got %p\n", newnode);
9820 V_VT(&v) = VT_NULL;
9821 node = (void*)0xdeadbeef;
9822 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9823 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9824 ok(node == NULL, "got %p\n", node);
9825 IXMLDOMNode_Release(newnode);
9827 /* element to attribute */
9828 V_VT(&v) = VT_I4;
9829 V_I4(&v) = NODE_ELEMENT;
9830 newnode = NULL;
9831 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9832 ok(hr == S_OK, "got 0x%08x\n", hr);
9833 ok(newnode != NULL, "got %p\n", newnode);
9835 V_VT(&v) = VT_NULL;
9836 node = (void*)0xdeadbeef;
9837 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9838 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9839 ok(node == NULL, "got %p\n", node);
9840 IXMLDOMNode_Release(newnode);
9842 /* pi to attribute */
9843 V_VT(&v) = VT_I4;
9844 V_I4(&v) = NODE_PROCESSING_INSTRUCTION;
9845 newnode = NULL;
9846 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9847 ok(hr == S_OK, "got 0x%08x\n", hr);
9848 ok(newnode != NULL, "got %p\n", newnode);
9850 V_VT(&v) = VT_NULL;
9851 node = (void*)0xdeadbeef;
9852 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9853 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9854 ok(node == NULL, "got %p\n", node);
9855 IXMLDOMNode_Release(newnode);
9856 IXMLDOMAttribute_Release(attr);
9858 /* insertBefore for elements */
9859 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem1);
9860 ok(hr == S_OK, "got 0x%08x\n", hr);
9862 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem2"), &elem2);
9863 ok(hr == S_OK, "got 0x%08x\n", hr);
9865 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
9866 ok(hr == S_OK, "got 0x%08x\n", hr);
9868 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
9869 ok(hr == S_OK, "got 0x%08x\n", hr);
9871 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem4"), &elem4);
9872 ok(hr == S_OK, "got 0x%08x\n", hr);
9874 EXPECT_NO_CHILDREN(elem1);
9875 EXPECT_NO_CHILDREN(elem2);
9876 EXPECT_NO_CHILDREN(elem3);
9878 todo_wine EXPECT_REF(elem2, 2);
9880 V_VT(&v) = VT_DISPATCH;
9881 V_DISPATCH(&v) = NULL;
9882 node = NULL;
9883 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem4, v, &node);
9884 ok(hr == S_OK, "got 0x%08x\n", hr);
9885 ok(node == (void*)elem4, "got %p\n", node);
9887 EXPECT_CHILDREN(elem1);
9888 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem4, NULL);
9889 EXPECT_HR(hr, S_OK);
9890 IXMLDOMElement_Release(elem4);
9892 EXPECT_NO_CHILDREN(elem1);
9894 V_VT(&v) = VT_NULL;
9895 node = NULL;
9896 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9897 ok(hr == S_OK, "got 0x%08x\n", hr);
9898 ok(node == (void*)elem2, "got %p\n", node);
9900 EXPECT_CHILDREN(elem1);
9901 todo_wine EXPECT_REF(elem2, 3);
9902 IXMLDOMNode_Release(node);
9904 /* again for already linked node */
9905 V_VT(&v) = VT_NULL;
9906 node = NULL;
9907 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9908 ok(hr == S_OK, "got 0x%08x\n", hr);
9909 ok(node == (void*)elem2, "got %p\n", node);
9911 EXPECT_CHILDREN(elem1);
9913 /* increments each time */
9914 todo_wine EXPECT_REF(elem2, 3);
9915 IXMLDOMNode_Release(node);
9917 /* try to add to another element */
9918 V_VT(&v) = VT_NULL;
9919 node = (void*)0xdeadbeef;
9920 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem2, v, &node);
9921 ok(hr == S_OK, "got 0x%08x\n", hr);
9922 ok(node == (void*)elem2, "got %p\n", node);
9924 EXPECT_CHILDREN(elem3);
9925 EXPECT_NO_CHILDREN(elem1);
9927 IXMLDOMNode_Release(node);
9929 /* cross document case - try to add as child to a node created with other doc */
9930 doc2 = create_document(&IID_IXMLDOMDocument);
9932 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem4);
9933 ok(hr == S_OK, "got 0x%08x\n", hr);
9934 todo_wine EXPECT_REF(elem4, 2);
9936 /* same name, another instance */
9937 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem5);
9938 ok(hr == S_OK, "got 0x%08x\n", hr);
9939 todo_wine EXPECT_REF(elem5, 2);
9941 todo_wine EXPECT_REF(elem3, 2);
9942 V_VT(&v) = VT_NULL;
9943 node = NULL;
9944 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem4, v, &node);
9945 ok(hr == S_OK, "got 0x%08x\n", hr);
9946 ok(node == (void*)elem4, "got %p\n", node);
9947 todo_wine EXPECT_REF(elem4, 3);
9948 todo_wine EXPECT_REF(elem3, 2);
9949 IXMLDOMNode_Release(node);
9951 V_VT(&v) = VT_NULL;
9952 node = NULL;
9953 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem5, v, &node);
9954 ok(hr == S_OK, "got 0x%08x\n", hr);
9955 ok(node == (void*)elem5, "got %p\n", node);
9956 todo_wine EXPECT_REF(elem4, 2);
9957 todo_wine EXPECT_REF(elem5, 3);
9958 IXMLDOMNode_Release(node);
9960 IXMLDOMDocument_Release(doc2);
9962 IXMLDOMElement_Release(elem1);
9963 IXMLDOMElement_Release(elem2);
9964 IXMLDOMElement_Release(elem3);
9965 IXMLDOMElement_Release(elem4);
9966 IXMLDOMElement_Release(elem5);
9968 /* elements with same default namespace */
9969 V_VT(&v) = VT_I4;
9970 V_I4(&v) = NODE_ELEMENT;
9971 elem1 = NULL;
9972 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
9973 ok(hr == S_OK, "got 0x%08x\n", hr);
9974 ok(elem1 != NULL, "got %p\n", elem1);
9976 V_VT(&v) = VT_I4;
9977 V_I4(&v) = NODE_ELEMENT;
9978 elem2 = NULL;
9979 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem2);
9980 ok(hr == S_OK, "got 0x%08x\n", hr);
9981 ok(elem2 != NULL, "got %p\n", elem2);
9983 /* check contents so far */
9984 p = NULL;
9985 hr = IXMLDOMElement_get_xml(elem1, &p);
9986 ok(hr == S_OK, "got 0x%08x\n", hr);
9987 ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9988 SysFreeString(p);
9990 p = NULL;
9991 hr = IXMLDOMElement_get_xml(elem2, &p);
9992 ok(hr == S_OK, "got 0x%08x\n", hr);
9993 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9994 SysFreeString(p);
9996 V_VT(&v) = VT_NULL;
9997 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
9998 ok(hr == S_OK, "got 0x%08x\n", hr);
10000 /* get_xml depends on context, for top node it omits child namespace attribute,
10001 but at child level it's still returned */
10002 p = NULL;
10003 hr = IXMLDOMElement_get_xml(elem1, &p);
10004 ok(hr == S_OK, "got 0x%08x\n", hr);
10005 todo_wine ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"><elem2/></elem1>")),
10006 "got %s\n", wine_dbgstr_w(p));
10007 SysFreeString(p);
10009 p = NULL;
10010 hr = IXMLDOMElement_get_xml(elem2, &p);
10011 ok(hr == S_OK, "got 0x%08x\n", hr);
10012 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
10013 SysFreeString(p);
10015 IXMLDOMElement_Release(elem1);
10016 IXMLDOMElement_Release(elem2);
10018 /* child without default namespace added to node with default namespace */
10019 V_VT(&v) = VT_I4;
10020 V_I4(&v) = NODE_ELEMENT;
10021 elem1 = NULL;
10022 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
10023 ok(hr == S_OK, "got 0x%08x\n", hr);
10024 ok(elem1 != NULL, "got %p\n", elem1);
10026 V_VT(&v) = VT_I4;
10027 V_I4(&v) = NODE_ELEMENT;
10028 elem2 = NULL;
10029 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), NULL, (IXMLDOMNode**)&elem2);
10030 ok(hr == S_OK, "got 0x%08x\n", hr);
10031 ok(elem2 != NULL, "got %p\n", elem2);
10033 EXPECT_REF(elem2, 1);
10034 V_VT(&v) = VT_NULL;
10035 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
10036 ok(hr == S_OK, "got 0x%08x\n", hr);
10037 EXPECT_REF(elem2, 1);
10039 p = NULL;
10040 hr = IXMLDOMElement_get_xml(elem2, &p);
10041 ok(hr == S_OK, "got 0x%08x\n", hr);
10042 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
10043 SysFreeString(p);
10045 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem2, NULL);
10046 ok(hr == S_OK, "got 0x%08x\n", hr);
10048 p = NULL;
10049 hr = IXMLDOMElement_get_xml(elem2, &p);
10050 ok(hr == S_OK, "got 0x%08x\n", hr);
10051 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
10052 SysFreeString(p);
10054 IXMLDOMElement_Release(elem1);
10055 IXMLDOMElement_Release(elem2);
10056 IXMLDOMDocument_Release(doc);
10059 static void test_appendChild(void)
10061 IXMLDOMDocument *doc, *doc2;
10062 IXMLDOMElement *elem, *elem2;
10063 HRESULT hr;
10065 doc = create_document(&IID_IXMLDOMDocument);
10066 doc2 = create_document(&IID_IXMLDOMDocument);
10068 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
10069 ok(hr == S_OK, "got 0x%08x\n", hr);
10071 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem2"), &elem2);
10072 ok(hr == S_OK, "got 0x%08x\n", hr);
10074 EXPECT_REF(doc, 1);
10075 todo_wine EXPECT_REF(elem, 2);
10076 EXPECT_REF(doc2, 1);
10077 todo_wine EXPECT_REF(elem2, 2);
10078 EXPECT_NO_CHILDREN(doc);
10079 EXPECT_NO_CHILDREN(doc2);
10081 /* append from another document */
10082 hr = IXMLDOMDocument_appendChild(doc2, (IXMLDOMNode*)elem, NULL);
10083 ok(hr == S_OK, "got 0x%08x\n", hr);
10085 EXPECT_REF(doc, 1);
10086 todo_wine EXPECT_REF(elem, 2);
10087 EXPECT_REF(doc2, 1);
10088 todo_wine EXPECT_REF(elem2, 2);
10089 EXPECT_NO_CHILDREN(doc);
10090 EXPECT_CHILDREN(doc2);
10092 IXMLDOMElement_Release(elem);
10093 IXMLDOMElement_Release(elem2);
10094 IXMLDOMDocument_Release(doc);
10095 IXMLDOMDocument_Release(doc2);
10098 static void test_get_doctype(void)
10100 IXMLDOMDocumentType *doctype;
10101 IXMLDOMDocument *doc;
10102 HRESULT hr;
10104 doc = create_document(&IID_IXMLDOMDocument);
10106 hr = IXMLDOMDocument_get_doctype(doc, NULL);
10107 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
10109 doctype = (void*)0xdeadbeef;
10110 hr = IXMLDOMDocument_get_doctype(doc, &doctype);
10111 ok(hr == S_FALSE, "got 0x%08x\n", hr);
10112 ok(doctype == NULL, "got %p\n", doctype);
10114 IXMLDOMDocument_Release(doc);
10117 static void test_get_tagName(void)
10119 IXMLDOMDocument *doc;
10120 IXMLDOMElement *elem, *elem2;
10121 HRESULT hr;
10122 BSTR str;
10124 doc = create_document(&IID_IXMLDOMDocument);
10126 hr = IXMLDOMDocument_createElement(doc, _bstr_("element"), &elem);
10127 ok(hr == S_OK, "got 0x%08x\n", hr);
10129 hr = IXMLDOMElement_get_tagName(elem, NULL);
10130 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
10132 str = NULL;
10133 hr = IXMLDOMElement_get_tagName(elem, &str);
10134 ok(hr == S_OK, "got 0x%08x\n", hr);
10135 ok(!lstrcmpW(str, _bstr_("element")), "got %s\n", wine_dbgstr_w(str));
10136 SysFreeString(str);
10138 hr = IXMLDOMDocument_createElement(doc, _bstr_("s:element"), &elem2);
10139 ok(hr == S_OK, "got 0x%08x\n", hr);
10141 str = NULL;
10142 hr = IXMLDOMElement_get_tagName(elem2, &str);
10143 ok(hr == S_OK, "got 0x%08x\n", hr);
10144 ok(!lstrcmpW(str, _bstr_("s:element")), "got %s\n", wine_dbgstr_w(str));
10145 SysFreeString(str);
10147 IXMLDOMDocument_Release(elem);
10148 IXMLDOMDocument_Release(elem2);
10149 IXMLDOMDocument_Release(doc);
10150 free_bstrs();
10153 typedef struct {
10154 DOMNodeType type;
10155 const char *name;
10156 VARTYPE vt;
10157 HRESULT hr;
10158 } node_type_t;
10160 static const node_type_t get_datatype[] = {
10161 { NODE_ELEMENT, "element", VT_NULL, S_FALSE },
10162 { NODE_ATTRIBUTE, "attr", VT_NULL, S_FALSE },
10163 { NODE_TEXT, "text", VT_NULL, S_FALSE },
10164 { NODE_CDATA_SECTION , "cdata", VT_NULL, S_FALSE },
10165 { NODE_ENTITY_REFERENCE, "entityref", VT_NULL, S_FALSE },
10166 { NODE_PROCESSING_INSTRUCTION, "pi", VT_NULL, S_FALSE },
10167 { NODE_COMMENT, "comment", VT_NULL, S_FALSE },
10168 { NODE_DOCUMENT_FRAGMENT, "docfrag", VT_NULL, S_FALSE },
10169 { 0 }
10172 static void test_get_dataType(void)
10174 const node_type_t *entry = get_datatype;
10175 IXMLDOMDocument *doc;
10177 doc = create_document(&IID_IXMLDOMDocument);
10179 while (entry->type)
10181 IXMLDOMNode *node = NULL;
10182 VARIANT var, type;
10183 HRESULT hr;
10185 V_VT(&var) = VT_I4;
10186 V_I4(&var) = entry->type;
10187 hr = IXMLDOMDocument_createNode(doc, var, _bstr_(entry->name), NULL, &node);
10188 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
10190 hr = IXMLDOMNode_get_dataType(node, NULL);
10191 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
10193 VariantInit(&type);
10194 hr = IXMLDOMNode_get_dataType(node, &type);
10195 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
10196 hr, entry->hr, entry->type);
10197 ok(V_VT(&type) == entry->vt, "got %d, expected %d. node type %d\n",
10198 V_VT(&type), entry->vt, entry->type);
10199 VariantClear(&type);
10201 IXMLDOMNode_Release(node);
10203 entry++;
10206 IXMLDOMDocument_Release(doc);
10207 free_bstrs();
10210 typedef struct _get_node_typestring_t {
10211 DOMNodeType type;
10212 const char *string;
10213 } get_node_typestring_t;
10215 static const get_node_typestring_t get_node_typestring[] = {
10216 { NODE_ELEMENT, "element" },
10217 { NODE_ATTRIBUTE, "attribute" },
10218 { NODE_TEXT, "text" },
10219 { NODE_CDATA_SECTION , "cdatasection" },
10220 { NODE_ENTITY_REFERENCE, "entityreference" },
10221 { NODE_PROCESSING_INSTRUCTION, "processinginstruction" },
10222 { NODE_COMMENT, "comment" },
10223 { NODE_DOCUMENT_FRAGMENT, "documentfragment" },
10224 { 0 }
10227 static void test_get_nodeTypeString(void)
10229 const get_node_typestring_t *entry = get_node_typestring;
10230 IXMLDOMDocument *doc;
10231 HRESULT hr;
10232 BSTR str;
10234 doc = create_document(&IID_IXMLDOMDocument);
10236 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
10237 ok(hr == S_OK, "got 0x%08x\n", hr);
10238 ok(!lstrcmpW(str, _bstr_("document")), "got string %s\n", wine_dbgstr_w(str));
10239 SysFreeString(str);
10241 while (entry->type)
10243 IXMLDOMNode *node = NULL;
10244 VARIANT var;
10246 V_VT(&var) = VT_I4;
10247 V_I4(&var) = entry->type;
10248 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
10249 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
10251 hr = IXMLDOMNode_get_nodeTypeString(node, NULL);
10252 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
10254 hr = IXMLDOMNode_get_nodeTypeString(node, &str);
10255 ok(hr == S_OK, "got 0x%08x\n", hr);
10256 ok(!lstrcmpW(str, _bstr_(entry->string)), "got string %s, expected %s. node type %d\n",
10257 wine_dbgstr_w(str), entry->string, entry->type);
10258 SysFreeString(str);
10259 IXMLDOMNode_Release(node);
10261 entry++;
10264 IXMLDOMDocument_Release(doc);
10265 free_bstrs();
10268 typedef struct _get_attributes_t {
10269 DOMNodeType type;
10270 HRESULT hr;
10271 } get_attributes_t;
10273 static const get_attributes_t get_attributes[] = {
10274 { NODE_ATTRIBUTE, S_FALSE },
10275 { NODE_TEXT, S_FALSE },
10276 { NODE_CDATA_SECTION , S_FALSE },
10277 { NODE_ENTITY_REFERENCE, S_FALSE },
10278 { NODE_PROCESSING_INSTRUCTION, S_FALSE },
10279 { NODE_COMMENT, S_FALSE },
10280 { NODE_DOCUMENT_FRAGMENT, S_FALSE },
10281 { 0 }
10284 static void test_get_attributes(void)
10286 const get_attributes_t *entry = get_attributes;
10287 IXMLDOMNamedNodeMap *map;
10288 IXMLDOMDocument *doc;
10289 IXMLDOMNode *node, *node2;
10290 VARIANT_BOOL b;
10291 HRESULT hr;
10292 BSTR str;
10293 LONG length;
10295 doc = create_document(&IID_IXMLDOMDocument);
10297 hr = IXMLDOMDocument_loadXML(doc, _bstr_(complete4A), &b);
10298 ok(hr == S_OK, "got %08x\n", hr);
10300 hr = IXMLDOMDocument_get_attributes(doc, NULL);
10301 ok(hr == E_INVALIDARG, "got %08x\n", hr);
10303 map = (void*)0xdeadbeef;
10304 hr = IXMLDOMDocument_get_attributes(doc, &map);
10305 ok(hr == S_FALSE, "got %08x\n", hr);
10306 ok(map == NULL, "got %p\n", map);
10308 /* first child is <?xml ?> */
10309 hr = IXMLDOMDocument_get_firstChild(doc, &node);
10310 ok(hr == S_OK, "got %08x\n", hr);
10312 hr = IXMLDOMNode_get_attributes(node, &map);
10313 ok(hr == S_OK, "got %08x\n", hr);
10315 length = -1;
10316 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
10317 EXPECT_HR(hr, S_OK);
10318 todo_wine ok(length == 1, "got %d\n", length);
10320 if (hr == S_OK && length == 1)
10322 IXMLDOMAttribute *attr;
10323 DOMNodeType type;
10324 VARIANT v;
10326 node2 = NULL;
10327 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
10328 EXPECT_HR(hr, S_OK);
10329 ok(node != NULL, "got %p\n", node2);
10331 hr = IXMLDOMNode_get_nodeName(node2, &str);
10332 EXPECT_HR(hr, S_OK);
10333 ok(!lstrcmpW(str, _bstr_("version")), "got %s\n", wine_dbgstr_w(str));
10334 SysFreeString(str);
10336 length = -1;
10337 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
10338 EXPECT_HR(hr, S_OK);
10339 ok(length == 1, "got %d\n", length);
10341 type = -1;
10342 hr = IXMLDOMNode_get_nodeType(node2, &type);
10343 EXPECT_HR(hr, S_OK);
10344 ok(type == NODE_ATTRIBUTE, "got %d\n", type);
10346 hr = IXMLDOMNode_get_xml(node, &str);
10347 EXPECT_HR(hr, S_OK);
10348 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
10349 SysFreeString(str);
10351 hr = IXMLDOMNode_get_text(node, &str);
10352 EXPECT_HR(hr, S_OK);
10353 ok(!lstrcmpW(str, _bstr_("version=\"1.0\"")), "got %s\n", wine_dbgstr_w(str));
10354 SysFreeString(str);
10356 hr = IXMLDOMNamedNodeMap_removeNamedItem(map, _bstr_("version"), NULL);
10357 EXPECT_HR(hr, S_OK);
10359 length = -1;
10360 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
10361 EXPECT_HR(hr, S_OK);
10362 ok(length == 0, "got %d\n", length);
10364 hr = IXMLDOMNode_get_xml(node, &str);
10365 EXPECT_HR(hr, S_OK);
10366 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
10367 SysFreeString(str);
10369 hr = IXMLDOMNode_get_text(node, &str);
10370 EXPECT_HR(hr, S_OK);
10371 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
10372 SysFreeString(str);
10374 IXMLDOMNamedNodeMap_Release(map);
10376 hr = IXMLDOMNode_get_attributes(node, &map);
10377 ok(hr == S_OK, "got %08x\n", hr);
10379 length = -1;
10380 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
10381 EXPECT_HR(hr, S_OK);
10382 ok(length == 0, "got %d\n", length);
10384 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("encoding"), &attr);
10385 EXPECT_HR(hr, S_OK);
10387 V_VT(&v) = VT_BSTR;
10388 V_BSTR(&v) = _bstr_("UTF-8");
10389 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
10390 EXPECT_HR(hr, S_OK);
10392 EXPECT_REF(attr, 2);
10393 hr = IXMLDOMNamedNodeMap_setNamedItem(map, (IXMLDOMNode*)attr, NULL);
10394 EXPECT_HR(hr, S_OK);
10395 EXPECT_REF(attr, 2);
10397 hr = IXMLDOMNode_get_attributes(node, &map);
10398 ok(hr == S_OK, "got %08x\n", hr);
10400 length = -1;
10401 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
10402 EXPECT_HR(hr, S_OK);
10403 ok(length == 1, "got %d\n", length);
10405 hr = IXMLDOMNode_get_xml(node, &str);
10406 EXPECT_HR(hr, S_OK);
10407 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
10408 SysFreeString(str);
10410 hr = IXMLDOMNode_get_text(node, &str);
10411 EXPECT_HR(hr, S_OK);
10412 ok(!lstrcmpW(str, _bstr_("encoding=\"UTF-8\"")), "got %s\n", wine_dbgstr_w(str));
10413 SysFreeString(str);
10415 IXMLDOMNamedNodeMap_Release(map);
10416 IXMLDOMNode_Release(node2);
10419 IXMLDOMNode_Release(node);
10421 /* last child is element */
10422 EXPECT_REF(doc, 1);
10423 hr = IXMLDOMDocument_get_lastChild(doc, &node);
10424 ok(hr == S_OK, "got %08x\n", hr);
10425 EXPECT_REF(doc, 1);
10427 EXPECT_REF(node, 1);
10428 hr = IXMLDOMNode_get_attributes(node, &map);
10429 ok(hr == S_OK, "got %08x\n", hr);
10430 EXPECT_REF(node, 1);
10431 EXPECT_REF(doc, 1);
10433 EXPECT_REF(map, 1);
10434 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
10435 ok(hr == S_OK, "got %08x\n", hr);
10436 EXPECT_REF(node, 1);
10437 EXPECT_REF(node2, 1);
10438 EXPECT_REF(map, 1);
10439 EXPECT_REF(doc, 1);
10440 IXMLDOMNode_Release(node2);
10442 /* release node before map release, map still works */
10443 IXMLDOMNode_Release(node);
10445 length = 0;
10446 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
10447 ok(hr == S_OK, "got %08x\n", hr);
10448 ok(length == 1, "got %d\n", length);
10450 node2 = NULL;
10451 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
10452 ok(hr == S_OK, "got %08x\n", hr);
10453 EXPECT_REF(node2, 1);
10454 IXMLDOMNode_Release(node2);
10456 IXMLDOMNamedNodeMap_Release(map);
10458 while (entry->type)
10460 VARIANT var;
10462 node = NULL;
10464 V_VT(&var) = VT_I4;
10465 V_I4(&var) = entry->type;
10466 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
10467 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
10469 hr = IXMLDOMNode_get_attributes(node, NULL);
10470 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
10472 map = (void*)0xdeadbeef;
10473 hr = IXMLDOMNode_get_attributes(node, &map);
10474 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
10475 hr, entry->hr, entry->type);
10476 ok(map == NULL, "got %p\n", map);
10478 IXMLDOMNode_Release(node);
10480 entry++;
10483 IXMLDOMDocument_Release(doc);
10484 free_bstrs();
10487 static void test_selection(void)
10489 IXMLDOMSelection *selection, *selection2;
10490 IEnumVARIANT *enum1, *enum2, *enum3;
10491 IXMLDOMNodeList *list;
10492 IUnknown *unk1, *unk2;
10493 IXMLDOMDocument *doc;
10494 IDispatchEx *dispex;
10495 IXMLDOMNode *node;
10496 IDispatch *disp;
10497 VARIANT_BOOL b;
10498 HRESULT hr;
10499 DISPID did;
10500 VARIANT v;
10501 BSTR name;
10502 ULONG ret;
10503 LONG len;
10505 doc = create_document(&IID_IXMLDOMDocument);
10507 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
10508 EXPECT_HR(hr, S_OK);
10510 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list);
10511 EXPECT_HR(hr, S_OK);
10513 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
10514 EXPECT_HR(hr, S_OK);
10515 IXMLDOMSelection_Release(selection);
10517 /* collection disp id */
10518 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IDispatchEx, (void**)&dispex);
10519 EXPECT_HR(hr, S_OK);
10520 did = 0;
10521 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
10522 EXPECT_HR(hr, S_OK);
10523 ok(did == DISPID_DOM_COLLECTION_BASE, "got %d\n", did);
10524 len = 0;
10525 hr = IXMLDOMSelection_get_length(selection, &len);
10526 EXPECT_HR(hr, S_OK);
10527 ok(len == 1, "got %d\n", len);
10528 hr = IDispatchEx_GetDispID(dispex, _bstr_("10"), 0, &did);
10529 EXPECT_HR(hr, S_OK);
10530 ok(did == DISPID_DOM_COLLECTION_BASE+10, "got %d\n", did);
10531 IDispatchEx_Release(dispex);
10533 /* IEnumVARIANT tests */
10534 enum1 = NULL;
10535 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IEnumVARIANT, (void**)&enum1);
10536 EXPECT_HR(hr, S_OK);
10537 ok(enum1 != NULL, "got %p\n", enum1);
10538 EXPECT_REF(enum1, 2);
10540 EXPECT_REF(selection, 1);
10541 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IUnknown, (void**)&unk1);
10542 EXPECT_HR(hr, S_OK);
10543 EXPECT_REF(selection, 2);
10544 EXPECT_REF(enum1, 2);
10546 /* enumerator and selection object return same IUnknown* */
10547 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IUnknown, (void**)&unk2);
10548 EXPECT_HR(hr, S_OK);
10549 EXPECT_REF(selection, 3);
10550 EXPECT_REF(enum1, 2);
10551 ok(unk2 == unk1, "got %p, %p\n", unk1, unk2);
10552 IUnknown_Release(unk2);
10554 EXPECT_REF(selection, 2);
10555 IEnumVARIANT_AddRef(enum1);
10556 EXPECT_REF(selection, 2);
10557 IEnumVARIANT_Release(enum1);
10559 enum3 = NULL;
10560 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IEnumVARIANT, (void**)&enum3);
10561 EXPECT_HR(hr, S_OK);
10562 ok(enum3 != NULL, "got %p\n", enum3);
10563 ok(enum1 == enum3, "got %p and %p\n", enum1, enum3);
10564 EXPECT_REF(enum1, 3);
10565 IEnumVARIANT_Release(enum3);
10567 EXPECT_REF(selection, 2);
10568 EXPECT_REF(enum1, 2);
10570 enum2 = NULL;
10571 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum2);
10572 EXPECT_HR(hr, S_OK);
10573 ok(enum2 != NULL, "got %p\n", enum2);
10575 EXPECT_REF(selection, 3);
10576 EXPECT_REF(enum1, 2);
10577 EXPECT_REF(enum2, 1);
10579 ok(enum1 != enum2, "got %p, %p\n", enum1, enum2);
10581 hr = IEnumVARIANT_QueryInterface(enum2, &IID_IUnknown, (void**)&unk2);
10582 EXPECT_HR(hr, S_OK);
10583 EXPECT_REF(selection, 3);
10584 EXPECT_REF(enum2, 2);
10585 ok(unk2 != unk1, "got %p, %p\n", unk1, unk2);
10586 IUnknown_Release(unk2);
10587 IUnknown_Release(unk1);
10589 selection2 = NULL;
10590 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IXMLDOMSelection, (void**)&selection2);
10591 EXPECT_HR(hr, S_OK);
10592 ok(selection2 == selection, "got %p and %p\n", selection, selection2);
10593 EXPECT_REF(selection, 3);
10594 EXPECT_REF(enum1, 2);
10596 IXMLDOMSelection_Release(selection2);
10598 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IDispatch, (void**)&disp);
10599 EXPECT_HR(hr, S_OK);
10600 EXPECT_REF(selection, 3);
10601 IDispatch_Release(disp);
10603 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IEnumVARIANT, (void**)&enum3);
10604 EXPECT_HR(hr, S_OK);
10605 ok(enum3 == enum1, "got %p and %p\n", enum3, enum1);
10606 EXPECT_REF(selection, 2);
10607 EXPECT_REF(enum1, 3);
10609 IEnumVARIANT_Release(enum1);
10610 IEnumVARIANT_Release(enum2);
10612 enum1 = NULL;
10613 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum1);
10614 EXPECT_HR(hr, S_OK);
10615 ok(enum1 != NULL, "got %p\n", enum1);
10616 EXPECT_REF(enum1, 1);
10617 EXPECT_REF(selection, 2);
10619 enum2 = NULL;
10620 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum2);
10621 EXPECT_HR(hr, S_OK);
10622 ok(enum2 != NULL, "got %p\n", enum2);
10623 EXPECT_REF(enum2, 1);
10624 EXPECT_REF(selection, 3);
10626 ok(enum1 != enum2, "got %p, %p\n", enum1, enum2);
10628 IEnumVARIANT_AddRef(enum1);
10629 EXPECT_REF(selection, 3);
10630 EXPECT_REF(enum1, 2);
10631 EXPECT_REF(enum2, 1);
10632 IEnumVARIANT_Release(enum1);
10634 IEnumVARIANT_Release(enum1);
10635 IEnumVARIANT_Release(enum2);
10637 EXPECT_REF(selection, 1);
10639 IXMLDOMNodeList_Release(list);
10641 hr = IXMLDOMDocument_get_childNodes(doc, &list);
10642 EXPECT_HR(hr, S_OK);
10644 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
10645 EXPECT_HR(hr, E_NOINTERFACE);
10647 IXMLDOMNodeList_Release(list);
10649 /* test if IEnumVARIANT touches selection context */
10650 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(xpath_simple_list), &b);
10651 EXPECT_HR(hr, S_OK);
10653 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root/*"), &list);
10654 EXPECT_HR(hr, S_OK);
10656 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
10657 EXPECT_HR(hr, S_OK);
10659 len = 0;
10660 hr = IXMLDOMSelection_get_length(selection, &len);
10661 EXPECT_HR(hr, S_OK);
10662 ok(len == 4, "got %d\n", len);
10664 enum1 = NULL;
10665 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum1);
10666 EXPECT_HR(hr, S_OK);
10668 /* no-op if zero count */
10669 V_VT(&v) = VT_I2;
10670 hr = IEnumVARIANT_Next(enum1, 0, &v, NULL);
10671 EXPECT_HR(hr, S_OK);
10672 ok(V_VT(&v) == VT_I2, "got var type %d\n", V_VT(&v));
10674 /* positive count, null array pointer */
10675 hr = IEnumVARIANT_Next(enum1, 1, NULL, NULL);
10676 EXPECT_HR(hr, E_INVALIDARG);
10678 ret = 1;
10679 hr = IEnumVARIANT_Next(enum1, 1, NULL, &ret);
10680 EXPECT_HR(hr, E_INVALIDARG);
10681 ok(ret == 0, "got %d\n", ret);
10683 V_VT(&v) = VT_I2;
10684 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
10685 EXPECT_HR(hr, S_OK);
10686 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
10688 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
10689 EXPECT_HR(hr, S_OK);
10690 hr = IXMLDOMNode_get_nodeName(node, &name);
10691 EXPECT_HR(hr, S_OK);
10692 ok(!lstrcmpW(name, _bstr_("a")), "got node name %s\n", wine_dbgstr_w(name));
10693 SysFreeString(name);
10694 IXMLDOMNode_Release(node);
10695 VariantClear(&v);
10697 /* list cursor is updated */
10698 hr = IXMLDOMSelection_nextNode(selection, &node);
10699 EXPECT_HR(hr, S_OK);
10700 hr = IXMLDOMNode_get_nodeName(node, &name);
10701 EXPECT_HR(hr, S_OK);
10702 ok(!lstrcmpW(name, _bstr_("c")), "got node name %s\n", wine_dbgstr_w(name));
10703 IXMLDOMNode_Release(node);
10705 V_VT(&v) = VT_I2;
10706 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
10707 EXPECT_HR(hr, S_OK);
10708 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
10709 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
10710 EXPECT_HR(hr, S_OK);
10711 hr = IXMLDOMNode_get_nodeName(node, &name);
10712 EXPECT_HR(hr, S_OK);
10713 ok(!lstrcmpW(name, _bstr_("b")), "got node name %s\n", wine_dbgstr_w(name));
10714 SysFreeString(name);
10715 IXMLDOMNode_Release(node);
10716 VariantClear(&v);
10717 IEnumVARIANT_Release(enum1);
10719 hr = IXMLDOMSelection_nextNode(selection, &node);
10720 EXPECT_HR(hr, S_OK);
10721 hr = IXMLDOMNode_get_nodeName(node, &name);
10722 EXPECT_HR(hr, S_OK);
10723 ok(!lstrcmpW(name, _bstr_("d")), "got node name %s\n", wine_dbgstr_w(name));
10724 IXMLDOMNode_Release(node);
10726 IXMLDOMSelection_Release(selection);
10727 IXMLDOMNodeList_Release(list);
10728 IXMLDOMDocument_Release(doc);
10730 free_bstrs();
10733 static void test_load(void)
10735 IXMLDOMDocument *doc;
10736 IXMLDOMNodeList *list;
10737 VARIANT_BOOL b;
10738 HANDLE hfile;
10739 VARIANT src;
10740 HRESULT hr;
10741 BOOL ret;
10742 BSTR path, bstr1, bstr2;
10743 DWORD written;
10744 void* ptr;
10746 /* prepare a file */
10747 hfile = CreateFileA("test.xml", GENERIC_WRITE|GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
10748 ok(hfile != INVALID_HANDLE_VALUE, "failed to create test file\n");
10749 if(hfile == INVALID_HANDLE_VALUE) return;
10751 ret = WriteFile(hfile, win1252xml, strlen(win1252xml), &written, NULL);
10752 ok(ret, "WriteFile failed\n");
10754 CloseHandle(hfile);
10756 doc = create_document(&IID_IXMLDOMDocument);
10758 /* null pointer as input */
10759 V_VT(&src) = VT_UNKNOWN;
10760 V_UNKNOWN(&src) = NULL;
10761 hr = IXMLDOMDocument_load(doc, src, &b);
10762 EXPECT_HR(hr, E_INVALIDARG);
10763 ok(b == VARIANT_FALSE, "got %d\n", b);
10765 path = _bstr_("test.xml");
10767 /* load from path: VT_BSTR */
10768 V_VT(&src) = VT_BSTR;
10769 V_BSTR(&src) = path;
10770 hr = IXMLDOMDocument_load(doc, src, &b);
10771 EXPECT_HR(hr, S_OK);
10772 ok(b == VARIANT_TRUE, "got %d\n", b);
10774 /* load from a path: VT_BSTR|VT_BYREF */
10775 V_VT(&src) = VT_BSTR | VT_BYREF;
10776 V_BSTRREF(&src) = &path;
10777 hr = IXMLDOMDocument_load(doc, src, &b);
10778 EXPECT_HR(hr, S_OK);
10779 ok(b == VARIANT_TRUE, "got %d\n", b);
10781 /* load from a path: VT_BSTR|VT_BYREF, null ptr */
10782 V_VT(&src) = VT_BSTR | VT_BYREF;
10783 V_BSTRREF(&src) = NULL;
10784 hr = IXMLDOMDocument_load(doc, src, &b);
10785 EXPECT_HR(hr, E_INVALIDARG);
10786 ok(b == VARIANT_FALSE, "got %d\n", b);
10788 IXMLDOMDocument_Release(doc);
10790 DeleteFileA("test.xml");
10792 doc = create_document(&IID_IXMLDOMDocument);
10794 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b);
10795 EXPECT_HR(hr, S_OK);
10796 ok(b == VARIANT_TRUE, "got %d\n", b);
10798 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
10799 EXPECT_HR(hr, S_OK);
10800 bstr1 = _bstr_(list_to_string(list));
10802 hr = IXMLDOMNodeList_reset(list);
10803 EXPECT_HR(hr, S_OK);
10805 IXMLDOMDocument_Release(doc);
10807 doc = create_document(&IID_IXMLDOMDocument);
10809 VariantInit(&src);
10810 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenA(szExampleXML));
10811 V_VT(&src) = VT_ARRAY|VT_UI1;
10812 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10813 ptr = NULL;
10814 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10815 EXPECT_HR(hr, S_OK);
10816 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10818 memcpy(ptr, szExampleXML, lstrlenA(szExampleXML));
10819 hr = SafeArrayUnlock(V_ARRAY(&src));
10820 EXPECT_HR(hr, S_OK);
10822 hr = IXMLDOMDocument_load(doc, src, &b);
10823 EXPECT_HR(hr, S_OK);
10824 ok(b == VARIANT_TRUE, "got %d\n", b);
10826 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
10827 EXPECT_HR(hr, S_OK);
10828 bstr2 = _bstr_(list_to_string(list));
10830 hr = IXMLDOMNodeList_reset(list);
10831 EXPECT_HR(hr, S_OK);
10833 ok(lstrcmpW(bstr1, bstr2) == 0, "strings not equal: %s : %s\n",
10834 wine_dbgstr_w(bstr1), wine_dbgstr_w(bstr2));
10836 IXMLDOMDocument_Release(doc);
10837 IXMLDOMNodeList_Release(list);
10838 VariantClear(&src);
10840 /* UTF-16 isn't accepted */
10841 doc = create_document(&IID_IXMLDOMDocument);
10843 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenW(szComplete1) * sizeof(WCHAR));
10844 V_VT(&src) = VT_ARRAY|VT_UI1;
10845 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10846 ptr = NULL;
10847 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10848 EXPECT_HR(hr, S_OK);
10849 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10851 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
10852 hr = SafeArrayUnlock(V_ARRAY(&src));
10853 EXPECT_HR(hr, S_OK);
10855 hr = IXMLDOMDocument_load(doc, src, &b);
10856 todo_wine EXPECT_HR(hr, S_FALSE);
10857 todo_wine ok(b == VARIANT_FALSE, "got %d\n", b);
10859 VariantClear(&src);
10861 /* it doesn't like it as a VT_ARRAY|VT_UI2 either */
10862 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI2, 0, lstrlenW(szComplete1));
10863 V_VT(&src) = VT_ARRAY|VT_UI2;
10864 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10865 ptr = NULL;
10866 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10867 EXPECT_HR(hr, S_OK);
10868 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10870 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
10871 hr = SafeArrayUnlock(V_ARRAY(&src));
10872 EXPECT_HR(hr, S_OK);
10874 hr = IXMLDOMDocument_load(doc, src, &b);
10875 todo_wine EXPECT_HR(hr, E_INVALIDARG);
10876 ok(b == VARIANT_FALSE, "got %d\n", b);
10878 VariantClear(&src);
10879 IXMLDOMDocument_Release(doc);
10881 free_bstrs();
10884 static void test_domobj_dispex(IUnknown *obj)
10886 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
10887 IDispatchEx *dispex;
10888 IUnknown *unk;
10889 DWORD props;
10890 UINT ticnt;
10891 HRESULT hr;
10892 BSTR name;
10894 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
10895 EXPECT_HR(hr, S_OK);
10896 if (FAILED(hr)) return;
10898 ticnt = 0;
10899 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
10900 EXPECT_HR(hr, S_OK);
10901 ok(ticnt == 1, "ticnt=%u\n", ticnt);
10903 name = SysAllocString(szstar);
10904 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
10905 EXPECT_HR(hr, E_NOTIMPL);
10906 SysFreeString(name);
10908 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
10909 EXPECT_HR(hr, E_NOTIMPL);
10911 props = 0;
10912 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
10913 EXPECT_HR(hr, E_NOTIMPL);
10914 ok(props == 0, "expected 0 got %d\n", props);
10916 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
10917 EXPECT_HR(hr, E_NOTIMPL);
10918 if (SUCCEEDED(hr)) SysFreeString(name);
10920 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
10921 EXPECT_HR(hr, E_NOTIMPL);
10923 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
10924 EXPECT_HR(hr, E_NOTIMPL);
10925 if (hr == S_OK && unk) IUnknown_Release(unk);
10927 IDispatchEx_Release(dispex);
10930 static void test_mxnamespacemanager(void)
10932 static const char xmluriA[] = "http://www.w3.org/XML/1998/namespace";
10933 IMXNamespacePrefixes *prefixes;
10934 IVBMXNamespaceManager *mgr2;
10935 IMXNamespaceManager *nsmgr;
10936 IUnknown *unk1, *unk2;
10937 WCHAR buffW[250];
10938 IDispatch *disp;
10939 IUnknown *unk;
10940 HRESULT hr;
10941 INT len;
10943 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10944 &IID_IMXNamespaceManager, (void**)&nsmgr);
10945 EXPECT_HR(hr, S_OK);
10947 /* IMXNamespaceManager inherits from IUnknown */
10948 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IDispatch, (void**)&disp);
10949 EXPECT_HR(hr, S_OK);
10950 IDispatch_Release(disp);
10952 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IVBMXNamespaceManager, (void**)&mgr2);
10953 EXPECT_HR(hr, S_OK);
10955 EXPECT_REF(nsmgr, 2);
10956 EXPECT_REF(mgr2, 2);
10957 prefixes = NULL;
10958 hr = IVBMXNamespaceManager_getDeclaredPrefixes(mgr2, &prefixes);
10959 if (hr == S_OK)
10961 ok(prefixes != NULL, "got %p\n", prefixes);
10962 EXPECT_REF(nsmgr, 2);
10963 EXPECT_REF(mgr2, 2);
10964 EXPECT_REF(prefixes, 1);
10966 IVBMXNamespaceManager_QueryInterface(mgr2, &IID_IUnknown, (void**)&unk1);
10967 IMXNamespacePrefixes_QueryInterface(prefixes, &IID_IUnknown, (void**)&unk2);
10969 EXPECT_REF(mgr2, 3);
10970 EXPECT_REF(prefixes, 2);
10972 IUnknown_Release(unk1);
10973 IUnknown_Release(unk2);
10974 IMXNamespacePrefixes_Release(prefixes);
10976 IVBMXNamespaceManager_Release(mgr2);
10978 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
10979 EXPECT_HR(hr, S_OK);
10981 /* prefix already added */
10982 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10983 EXPECT_HR(hr, S_FALSE);
10985 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), NULL);
10986 EXPECT_HR(hr, E_INVALIDARG);
10988 /* "xml" and "xmlns" are not allowed here */
10989 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xml"), _bstr_("uri1"));
10990 EXPECT_HR(hr, E_INVALIDARG);
10992 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xmlns"), _bstr_("uri1"));
10993 EXPECT_HR(hr, E_INVALIDARG);
10994 todo_wine {
10995 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, -1, NULL, NULL);
10996 EXPECT_HR(hr, E_FAIL);
10998 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, NULL);
10999 EXPECT_HR(hr, E_POINTER);
11001 len = -1;
11002 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, &len);
11003 EXPECT_HR(hr, S_OK);
11004 ok(len == 3, "got %d\n", len);
11006 len = -1;
11007 buffW[0] = 0x1;
11008 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
11009 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
11010 ok(len == -1, "got %d\n", len);
11011 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11013 len = 10;
11014 buffW[0] = 0x1;
11015 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
11016 EXPECT_HR(hr, S_OK);
11017 ok(len == 3, "got %d\n", len);
11018 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
11020 /* getURI */
11021 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, NULL);
11022 EXPECT_HR(hr, E_INVALIDARG);
11024 len = -1;
11025 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, &len);
11026 EXPECT_HR(hr, E_INVALIDARG);
11027 ok(len == -1, "got %d\n", len);
11029 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, NULL);
11030 EXPECT_HR(hr, E_POINTER);
11032 len = -1;
11033 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, &len);
11034 EXPECT_HR(hr, S_OK);
11035 /* length of "xml" uri is constant */
11036 ok(len == strlen(xmluriA), "got %d\n", len);
11038 len = 100;
11039 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
11040 EXPECT_HR(hr, S_OK);
11041 ok(len == strlen(xmluriA), "got %d\n", len);
11042 ok(!lstrcmpW(buffW, _bstr_(xmluriA)), "got prefix %s\n", wine_dbgstr_w(buffW));
11044 len = strlen(xmluriA)-1;
11045 buffW[0] = 0x1;
11046 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
11047 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
11048 ok(len == strlen(xmluriA)-1, "got %d\n", len);
11049 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11051 /* prefix xml1 not defined */
11052 len = -1;
11053 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, NULL, &len);
11054 EXPECT_HR(hr, S_FALSE);
11055 ok(len == 0, "got %d\n", len);
11057 len = 100;
11058 buffW[0] = 0x1;
11059 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, buffW, &len);
11060 EXPECT_HR(hr, S_FALSE);
11061 ok(buffW[0] == 0, "got %x\n", buffW[0]);
11062 ok(len == 0, "got %d\n", len);
11064 /* IDispatchEx tests */
11065 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IUnknown, (void**)&unk);
11066 EXPECT_HR(hr, S_OK);
11067 test_domobj_dispex(unk);
11068 IUnknown_Release(unk);
11070 IMXNamespaceManager_Release(nsmgr);
11072 /* ::getPrefix() */
11073 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
11074 &IID_IMXNamespaceManager, (void**)&nsmgr);
11075 EXPECT_HR(hr, S_OK);
11077 hr = IMXNamespaceManager_getPrefix(nsmgr, NULL, 0, NULL, NULL);
11078 EXPECT_HR(hr, E_INVALIDARG);
11080 len = -1;
11081 hr = IMXNamespaceManager_getPrefix(nsmgr, NULL, 0, NULL, &len);
11082 EXPECT_HR(hr, E_INVALIDARG);
11083 ok(len == -1, "got %d\n", len);
11085 len = 100;
11086 buffW[0] = 0x1;
11087 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns0 uri"), 0, buffW, &len);
11088 EXPECT_HR(hr, E_FAIL);
11089 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11090 ok(len == 100, "got %d\n", len);
11092 len = 0;
11093 buffW[0] = 0x1;
11094 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns0 uri"), 0, buffW, &len);
11095 EXPECT_HR(hr, E_FAIL);
11096 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11097 ok(len == 0, "got %d\n", len);
11099 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
11100 EXPECT_HR(hr, S_OK);
11102 len = 100;
11103 buffW[0] = 0x1;
11104 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
11105 EXPECT_HR(hr, S_OK);
11106 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
11107 ok(len == 3, "got %d\n", len);
11109 len = 100;
11110 buffW[0] = 0x1;
11111 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("http://www.w3.org/XML/1998/namespace"), 0, buffW, &len);
11112 EXPECT_HR(hr, S_OK);
11113 ok(!lstrcmpW(buffW, _bstr_("xml")), "got %s\n", wine_dbgstr_w(buffW));
11114 ok(len == 3, "got %d\n", len);
11116 /* with null buffer it's possible to get required length */
11117 len = 100;
11118 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("http://www.w3.org/XML/1998/namespace"), 0, NULL, &len);
11119 EXPECT_HR(hr, S_OK);
11120 ok(len == 3, "got %d\n", len);
11122 len = 0;
11123 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("http://www.w3.org/XML/1998/namespace"), 0, NULL, &len);
11124 EXPECT_HR(hr, S_OK);
11125 ok(len == 3, "got %d\n", len);
11127 len = 100;
11128 buffW[0] = 0x1;
11129 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 1, buffW, &len);
11130 EXPECT_HR(hr, E_FAIL);
11131 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11132 ok(len == 100, "got %d\n", len);
11134 len = 100;
11135 buffW[0] = 0x1;
11136 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 2, buffW, &len);
11137 EXPECT_HR(hr, E_FAIL);
11138 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11139 ok(len == 100, "got %d\n", len);
11141 len = 100;
11142 buffW[0] = 0x1;
11143 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 0, buffW, &len);
11144 EXPECT_HR(hr, E_INVALIDARG);
11145 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11146 ok(len == 100, "got %d\n", len);
11148 len = 100;
11149 buffW[0] = 0x1;
11150 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 1, buffW, &len);
11151 EXPECT_HR(hr, E_INVALIDARG);
11152 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11153 ok(len == 100, "got %d\n", len);
11155 len = 100;
11156 buffW[0] = 0x1;
11157 hr = IMXNamespaceManager_getPrefix(nsmgr, NULL, 0, buffW, &len);
11158 EXPECT_HR(hr, E_INVALIDARG);
11159 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11160 ok(len == 100, "got %d\n", len);
11162 len = 100;
11163 buffW[0] = 0x1;
11164 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns0 uri"), 1, buffW, &len);
11165 EXPECT_HR(hr, E_FAIL);
11166 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11167 ok(len == 100, "got %d\n", len);
11169 len = 100;
11170 buffW[0] = 0x1;
11171 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 1, buffW, &len);
11172 EXPECT_HR(hr, E_INVALIDARG);
11173 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11174 ok(len == 100, "got %d\n", len);
11176 /* declare another one, indices are shifted */
11177 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns2"), _bstr_("ns2 uri"));
11178 EXPECT_HR(hr, S_OK);
11180 len = 100;
11181 buffW[0] = 0x1;
11182 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
11183 EXPECT_HR(hr, S_OK);
11184 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
11185 ok(len == 3, "got %d\n", len);
11187 len = 100;
11188 buffW[0] = 0x1;
11189 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
11190 EXPECT_HR(hr, S_OK);
11191 ok(!lstrcmpW(buffW, _bstr_("ns2")), "got %s\n", wine_dbgstr_w(buffW));
11192 ok(len == 3, "got %d\n", len);
11194 len = 100;
11195 buffW[0] = 0x1;
11196 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 1, buffW, &len);
11197 EXPECT_HR(hr, E_FAIL);
11198 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11199 ok(len == 100, "got %d\n", len);
11201 len = 100;
11202 buffW[0] = 0x1;
11203 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 1, buffW, &len);
11204 EXPECT_HR(hr, E_INVALIDARG);
11205 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11206 ok(len == 100, "got %d\n", len);
11208 IMXNamespaceManager_Release(nsmgr);
11210 /* push/pop tests */
11211 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
11212 &IID_IMXNamespaceManager, (void**)&nsmgr);
11213 EXPECT_HR(hr, S_OK);
11215 /* pop with empty stack */
11216 hr = IMXNamespaceManager_popContext(nsmgr);
11217 EXPECT_HR(hr, E_FAIL);
11219 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
11220 EXPECT_HR(hr, S_OK);
11222 len = 100;
11223 buffW[0] = 0x1;
11224 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
11225 EXPECT_HR(hr, S_OK);
11226 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
11227 ok(len == 3, "got %d\n", len);
11229 hr = IMXNamespaceManager_pushContext(nsmgr);
11230 EXPECT_HR(hr, S_OK);
11232 len = 100;
11233 buffW[0] = 0x1;
11234 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
11235 EXPECT_HR(hr, S_OK);
11236 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
11237 ok(len == 3, "got %d\n", len);
11239 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns2"), _bstr_("ns2 uri"));
11240 EXPECT_HR(hr, S_OK);
11242 len = 100;
11243 buffW[0] = 0x1;
11244 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
11245 EXPECT_HR(hr, S_OK);
11246 ok(!lstrcmpW(buffW, _bstr_("ns2")), "got %s\n", wine_dbgstr_w(buffW));
11247 ok(len == 3, "got %d\n", len);
11249 hr = IMXNamespaceManager_pushContext(nsmgr);
11250 EXPECT_HR(hr, S_OK);
11251 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns3"), _bstr_("ns3 uri"));
11252 EXPECT_HR(hr, S_OK);
11254 len = 100;
11255 buffW[0] = 0x1;
11256 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
11257 EXPECT_HR(hr, S_OK);
11258 ok(!lstrcmpW(buffW, _bstr_("ns2")), "got %s\n", wine_dbgstr_w(buffW));
11259 ok(len == 3, "got %d\n", len);
11261 len = 100;
11262 buffW[0] = 0x1;
11263 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
11264 EXPECT_HR(hr, S_OK);
11265 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
11266 ok(len == 3, "got %d\n", len);
11268 hr = IMXNamespaceManager_popContext(nsmgr);
11269 EXPECT_HR(hr, S_OK);
11271 hr = IMXNamespaceManager_popContext(nsmgr);
11272 EXPECT_HR(hr, S_OK);
11274 len = 100;
11275 buffW[0] = 0x1;
11276 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
11277 EXPECT_HR(hr, E_FAIL);
11278 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
11279 ok(len == 100, "got %d\n", len);
11281 len = 100;
11282 buffW[0] = 0x1;
11283 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
11284 EXPECT_HR(hr, S_OK);
11285 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
11286 ok(len == 3, "got %d\n", len);
11288 IMXNamespaceManager_Release(nsmgr);
11290 free_bstrs();
11293 static void test_mxnamespacemanager_override(void)
11295 IMXNamespaceManager *nsmgr;
11296 WCHAR buffW[250];
11297 VARIANT_BOOL b;
11298 HRESULT hr;
11299 INT len;
11301 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
11302 &IID_IMXNamespaceManager, (void**)&nsmgr);
11303 EXPECT_HR(hr, S_OK);
11305 len = sizeof(buffW)/sizeof(WCHAR);
11306 buffW[0] = 0;
11307 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
11308 EXPECT_HR(hr, S_OK);
11309 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
11311 len = sizeof(buffW)/sizeof(WCHAR);
11312 buffW[0] = 0;
11313 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
11314 EXPECT_HR(hr, E_FAIL);
11316 hr = IMXNamespaceManager_getAllowOverride(nsmgr, NULL);
11317 EXPECT_HR(hr, E_POINTER);
11319 b = VARIANT_FALSE;
11320 hr = IMXNamespaceManager_getAllowOverride(nsmgr, &b);
11321 EXPECT_HR(hr, S_OK);
11322 ok(b == VARIANT_TRUE, "got %d\n", b);
11324 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_FALSE);
11325 EXPECT_HR(hr, S_OK);
11327 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
11328 EXPECT_HR(hr, S_OK);
11330 len = sizeof(buffW)/sizeof(WCHAR);
11331 buffW[0] = 0;
11332 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
11333 EXPECT_HR(hr, S_OK);
11334 ok(!lstrcmpW(buffW, _bstr_("ns0 uri")), "got uri %s\n", wine_dbgstr_w(buffW));
11336 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), _bstr_("ns0 uri"));
11337 EXPECT_HR(hr, S_OK);
11339 len = sizeof(buffW)/sizeof(WCHAR);
11340 buffW[0] = 0;
11341 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
11342 EXPECT_HR(hr, S_OK);
11343 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
11345 len = sizeof(buffW)/sizeof(WCHAR);
11346 buffW[0] = 0;
11347 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
11348 EXPECT_HR(hr, S_OK);
11349 ok(!lstrcmpW(buffW, _bstr_("ns0")), "got prefix %s\n", wine_dbgstr_w(buffW));
11351 len = sizeof(buffW)/sizeof(WCHAR);
11352 buffW[0] = 0;
11353 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 2, buffW, &len);
11354 EXPECT_HR(hr, S_OK);
11355 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
11357 /* new prefix placed at index 1 always */
11358 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
11359 EXPECT_HR(hr, S_OK);
11361 len = sizeof(buffW)/sizeof(WCHAR);
11362 buffW[0] = 0;
11363 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
11364 EXPECT_HR(hr, S_OK);
11365 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got prefix %s\n", wine_dbgstr_w(buffW));
11367 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_(""), NULL);
11368 todo_wine EXPECT_HR(hr, E_FAIL);
11370 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
11371 EXPECT_HR(hr, E_FAIL);
11373 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
11374 EXPECT_HR(hr, E_FAIL);
11376 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_TRUE);
11377 EXPECT_HR(hr, S_OK);
11379 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri override"));
11380 EXPECT_HR(hr, S_FALSE);
11382 len = sizeof(buffW)/sizeof(WCHAR);
11383 buffW[0] = 0;
11384 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
11385 EXPECT_HR(hr, S_OK);
11386 ok(!lstrcmpW(buffW, _bstr_("ns0 uri override")), "got uri %s\n", wine_dbgstr_w(buffW));
11388 len = sizeof(buffW)/sizeof(WCHAR);
11389 buffW[0] = 0;
11390 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 3, buffW, &len);
11391 EXPECT_HR(hr, S_OK);
11392 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
11394 IMXNamespaceManager_Release(nsmgr);
11396 free_bstrs();
11399 static const DOMNodeType nodetypes_test[] =
11401 NODE_ELEMENT,
11402 NODE_ATTRIBUTE,
11403 NODE_TEXT,
11404 NODE_CDATA_SECTION,
11405 NODE_ENTITY_REFERENCE,
11406 NODE_PROCESSING_INSTRUCTION,
11407 NODE_COMMENT,
11408 NODE_DOCUMENT_FRAGMENT,
11409 NODE_INVALID
11412 static void test_dispex(void)
11414 const DOMNodeType *type = nodetypes_test;
11415 IXMLDOMImplementation *impl;
11416 IXMLDOMNodeList *node_list;
11417 IXMLDOMParseError *error;
11418 IXMLDOMNamedNodeMap *map;
11419 IXSLProcessor *processor;
11420 IXSLTemplate *template;
11421 IXMLDOMDocument *doc;
11422 IXMLHTTPRequest *req;
11423 IXMLDOMElement *elem;
11424 IDispatchEx *dispex;
11425 IXMLDOMNode *node;
11426 VARIANT_BOOL b;
11427 IUnknown *unk;
11428 HRESULT hr;
11429 DISPID did;
11431 doc = create_document(&IID_IXMLDOMDocument);
11433 IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
11434 test_domobj_dispex(unk);
11435 IUnknown_Release(unk);
11437 for(; *type != NODE_INVALID; type++)
11439 IXMLDOMNode *node;
11440 VARIANT v;
11442 V_VT(&v) = VT_I2;
11443 V_I2(&v) = *type;
11445 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("name"), NULL, &node);
11446 ok(hr == S_OK, "failed to create node type %d\n", *type);
11448 IXMLDOMNode_QueryInterface(node, &IID_IUnknown, (void**)&unk);
11450 test_domobj_dispex(unk);
11451 IUnknown_Release(unk);
11452 IXMLDOMNode_Release(node);
11455 /* IXMLDOMNodeList */
11456 hr = IXMLDOMDocument_getElementsByTagName(doc, _bstr_("*"), &node_list);
11457 EXPECT_HR(hr, S_OK);
11458 IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk);
11459 test_domobj_dispex(unk);
11460 IUnknown_Release(unk);
11461 IXMLDOMNodeList_Release(node_list);
11463 /* IXMLDOMNodeList for children list */
11464 hr = IXMLDOMDocument_get_childNodes(doc, &node_list);
11465 EXPECT_HR(hr, S_OK);
11466 IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk);
11467 test_domobj_dispex(unk);
11468 IUnknown_Release(unk);
11470 /* collection dispex test, empty collection */
11471 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatchEx, (void**)&dispex);
11472 EXPECT_HR(hr, S_OK);
11473 did = 0;
11474 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
11475 EXPECT_HR(hr, S_OK);
11476 ok(did == DISPID_DOM_COLLECTION_BASE, "got 0x%08x\n", did);
11477 hr = IDispatchEx_GetDispID(dispex, _bstr_("1"), 0, &did);
11478 EXPECT_HR(hr, S_OK);
11479 ok(did == DISPID_DOM_COLLECTION_BASE+1, "got 0x%08x\n", did);
11480 IDispatchEx_Release(dispex);
11482 IXMLDOMNodeList_Release(node_list);
11484 /* IXMLDOMParseError */
11485 hr = IXMLDOMDocument_get_parseError(doc, &error);
11486 EXPECT_HR(hr, S_OK);
11487 IXMLDOMParseError_QueryInterface(error, &IID_IUnknown, (void**)&unk);
11488 test_domobj_dispex(unk);
11489 IUnknown_Release(unk);
11490 IXMLDOMParseError_Release(error);
11492 /* IXMLDOMNamedNodeMap */
11493 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(xpath_simple_list), &b);
11494 EXPECT_HR(hr, S_OK);
11496 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root/a"), &node_list);
11497 EXPECT_HR(hr, S_OK);
11498 hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
11499 EXPECT_HR(hr, S_OK);
11500 IXMLDOMNodeList_Release(node_list);
11502 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
11503 EXPECT_HR(hr, S_OK);
11504 IXMLDOMNode_Release(node);
11505 hr = IXMLDOMElement_get_attributes(elem, &map);
11506 EXPECT_HR(hr, S_OK);
11507 IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IUnknown, (void**)&unk);
11508 test_domobj_dispex(unk);
11509 IUnknown_Release(unk);
11510 /* collection dispex test */
11511 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IDispatchEx, (void**)&dispex);
11512 EXPECT_HR(hr, S_OK);
11513 did = 0;
11514 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
11515 EXPECT_HR(hr, S_OK);
11516 ok(did == DISPID_DOM_COLLECTION_BASE, "got 0x%08x\n", did);
11517 IDispatchEx_Release(dispex);
11519 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root/b"), &node_list);
11520 EXPECT_HR(hr, S_OK);
11521 hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
11522 EXPECT_HR(hr, S_OK);
11523 IXMLDOMNodeList_Release(node_list);
11524 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
11525 EXPECT_HR(hr, S_OK);
11526 IXMLDOMNode_Release(node);
11527 hr = IXMLDOMElement_get_attributes(elem, &map);
11528 EXPECT_HR(hr, S_OK);
11529 /* collection dispex test, empty collection */
11530 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IDispatchEx, (void**)&dispex);
11531 EXPECT_HR(hr, S_OK);
11532 did = 0;
11533 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
11534 EXPECT_HR(hr, S_OK);
11535 ok(did == DISPID_DOM_COLLECTION_BASE, "got 0x%08x\n", did);
11536 hr = IDispatchEx_GetDispID(dispex, _bstr_("1"), 0, &did);
11537 EXPECT_HR(hr, S_OK);
11538 ok(did == DISPID_DOM_COLLECTION_BASE+1, "got 0x%08x\n", did);
11539 IDispatchEx_Release(dispex);
11541 IXMLDOMNamedNodeMap_Release(map);
11542 IXMLDOMElement_Release(elem);
11544 /* IXMLDOMImplementation */
11545 hr = IXMLDOMDocument_get_implementation(doc, &impl);
11546 EXPECT_HR(hr, S_OK);
11548 hr = IXMLDOMImplementation_QueryInterface(impl, &IID_IDispatchEx, (void**)&dispex);
11549 EXPECT_HR(hr, S_OK);
11550 IDispatchEx_Release(dispex);
11551 IXMLDOMImplementation_Release(impl);
11553 IXMLDOMDocument_Release(doc);
11555 /* IXMLHTTPRequest */
11556 hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
11557 &IID_IXMLHttpRequest, (void**)&req);
11558 if (hr == S_OK)
11560 hr = IXMLHTTPRequest_QueryInterface(req, &IID_IDispatchEx, (void**)&dispex);
11561 EXPECT_HR(hr, E_NOINTERFACE);
11562 IXMLHTTPRequest_Release(req);
11565 /* IXSLTemplate */
11566 template = create_xsltemplate(&IID_IXSLTemplate);
11567 hr = IXSLTemplate_QueryInterface(template, &IID_IDispatchEx, (void**)&dispex);
11568 EXPECT_HR(hr, S_OK);
11569 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
11570 EXPECT_HR(hr, S_OK);
11571 test_domobj_dispex(unk);
11572 IUnknown_Release(unk);
11573 IDispatchEx_Release(dispex);
11575 /* IXSLProcessor */
11576 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
11577 EXPECT_HR(hr, S_OK);
11578 b = VARIANT_FALSE;
11579 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformSSXML), &b);
11580 EXPECT_HR(hr, S_OK);
11581 ok(b == VARIANT_TRUE, "got %d\n", b);
11583 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
11584 EXPECT_HR(hr, S_OK);
11585 IXMLDOMDocument_Release(doc);
11587 hr = IXSLTemplate_createProcessor(template, &processor);
11588 EXPECT_HR(hr, S_OK);
11589 hr = IXSLProcessor_QueryInterface(processor, &IID_IDispatchEx, (void**)&dispex);
11590 EXPECT_HR(hr, S_OK);
11591 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
11592 EXPECT_HR(hr, S_OK);
11593 test_domobj_dispex(unk);
11594 IUnknown_Release(unk);
11595 IDispatchEx_Release(dispex);
11597 IXSLProcessor_Release(processor);
11598 IXSLTemplate_Release(template);
11600 free_bstrs();
11603 static void test_parseerror(void)
11605 IXMLDOMParseError2 *error2;
11606 IXMLDOMParseError *error;
11607 IXMLDOMDocument *doc;
11608 HRESULT hr;
11610 doc = create_document(&IID_IXMLDOMDocument);
11612 hr = IXMLDOMDocument_get_parseError(doc, &error);
11613 EXPECT_HR(hr, S_OK);
11615 hr = IXMLDOMParseError_get_line(error, NULL);
11616 EXPECT_HR(hr, E_INVALIDARG);
11618 hr = IXMLDOMParseError_get_srcText(error, NULL);
11619 EXPECT_HR(hr, E_INVALIDARG);
11621 hr = IXMLDOMParseError_get_linepos(error, NULL);
11622 EXPECT_HR(hr, E_INVALIDARG);
11624 IXMLDOMParseError_Release(error);
11625 IXMLDOMDocument_Release(doc);
11627 doc = create_document_version(60, &IID_IXMLDOMDocument);
11628 if (!doc) return;
11629 hr = IXMLDOMDocument_get_parseError(doc, &error);
11630 EXPECT_HR(hr, S_OK);
11631 hr = IXMLDOMParseError_QueryInterface(error, &IID_IXMLDOMParseError2, (void**)&error2);
11632 EXPECT_HR(hr, S_OK);
11633 IXMLDOMParseError2_Release(error2);
11634 IXMLDOMParseError_Release(error);
11635 IXMLDOMDocument_Release(doc);
11638 static void test_getAttributeNode(void)
11640 IXMLDOMAttribute *attr;
11641 IXMLDOMDocument *doc;
11642 IXMLDOMElement *elem;
11643 VARIANT_BOOL v;
11644 HRESULT hr;
11645 BSTR str;
11647 doc = create_document(&IID_IXMLDOMDocument);
11649 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &v);
11650 EXPECT_HR(hr, S_OK);
11652 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
11653 EXPECT_HR(hr, S_OK);
11655 str = SysAllocString(nonexistent_fileW);
11656 hr = IXMLDOMElement_getAttributeNode(elem, str, NULL);
11657 EXPECT_HR(hr, E_FAIL);
11659 attr = (IXMLDOMAttribute*)0xdeadbeef;
11660 hr = IXMLDOMElement_getAttributeNode(elem, str, &attr);
11661 EXPECT_HR(hr, E_FAIL);
11662 ok(attr == NULL, "got %p\n", attr);
11663 SysFreeString(str);
11665 str = SysAllocString(nonexistent_attrW);
11666 hr = IXMLDOMElement_getAttributeNode(elem, str, NULL);
11667 EXPECT_HR(hr, S_FALSE);
11669 attr = (IXMLDOMAttribute*)0xdeadbeef;
11670 hr = IXMLDOMElement_getAttributeNode(elem, str, &attr);
11671 EXPECT_HR(hr, S_FALSE);
11672 ok(attr == NULL, "got %p\n", attr);
11673 SysFreeString(str);
11675 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("foo:b"), &attr);
11676 EXPECT_HR(hr, S_OK);
11677 IXMLDOMAttribute_Release(attr);
11679 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("b"), &attr);
11680 EXPECT_HR(hr, S_FALSE);
11682 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("a"), &attr);
11683 EXPECT_HR(hr, S_OK);
11684 IXMLDOMAttribute_Release(attr);
11686 IXMLDOMElement_Release(elem);
11687 IXMLDOMDocument_Release(doc);
11688 free_bstrs();
11691 typedef struct {
11692 DOMNodeType type;
11693 const char *name;
11694 REFIID iids[3];
11695 } supporterror_t;
11697 static const supporterror_t supporterror_test[] = {
11698 { NODE_ELEMENT, "element", { &IID_IXMLDOMNode, &IID_IXMLDOMElement } },
11699 { NODE_ATTRIBUTE, "attribute", { &IID_IXMLDOMNode, &IID_IXMLDOMAttribute } },
11700 { NODE_CDATA_SECTION, "cdata", { &IID_IXMLDOMNode, &IID_IXMLDOMCDATASection } },
11701 { NODE_ENTITY_REFERENCE, "entityref", { &IID_IXMLDOMNode, &IID_IXMLDOMEntityReference } },
11702 { NODE_PROCESSING_INSTRUCTION, "pi", { &IID_IXMLDOMNode, &IID_IXMLDOMProcessingInstruction } },
11703 { NODE_COMMENT, "comment", { &IID_IXMLDOMNode, &IID_IXMLDOMComment } },
11704 { NODE_DOCUMENT_FRAGMENT, "fragment", { &IID_IXMLDOMNode, &IID_IXMLDOMDocumentFragment } },
11705 { NODE_INVALID }
11708 static void test_supporterrorinfo(void)
11710 static REFIID iids[5] = { &IID_IXMLDOMNode, &IID_IXMLDOMDocument,
11711 &IID_IXMLDOMDocument2, &IID_IXMLDOMDocument3 };
11712 const supporterror_t *ptr = supporterror_test;
11713 ISupportErrorInfo *errorinfo, *info2;
11714 IXMLDOMNamedNodeMap *map, *map2;
11715 IXMLDOMDocument *doc;
11716 IXMLDOMElement *elem;
11717 VARIANT_BOOL b;
11718 IUnknown *unk;
11719 REFIID *iid;
11720 void *dummy;
11721 HRESULT hr;
11723 doc = create_document_version(60, &IID_IXMLDOMDocument3);
11724 if (!doc) return;
11726 EXPECT_REF(doc, 1);
11727 hr = IXMLDOMDocument_QueryInterface(doc, &IID_ISupportErrorInfo, (void**)&errorinfo);
11728 EXPECT_HR(hr, S_OK);
11729 EXPECT_REF(doc, 1);
11730 ISupportErrorInfo_AddRef(errorinfo);
11731 EXPECT_REF(errorinfo, 2);
11732 EXPECT_REF(doc, 1);
11733 ISupportErrorInfo_Release(errorinfo);
11735 hr = IXMLDOMDocument_QueryInterface(doc, &IID_ISupportErrorInfo, (void**)&info2);
11736 EXPECT_HR(hr, S_OK);
11737 ok(errorinfo != info2, "got %p, %p\n", info2, errorinfo);
11739 /* error interface can't be queried back for DOM interface */
11740 hr = ISupportErrorInfo_QueryInterface(info2, &IID_IXMLDOMDocument, &dummy);
11741 EXPECT_HR(hr, E_NOINTERFACE);
11742 hr = ISupportErrorInfo_QueryInterface(info2, &IID_IXMLDOMNode, &dummy);
11743 EXPECT_HR(hr, E_NOINTERFACE);
11745 ISupportErrorInfo_Release(info2);
11747 iid = iids;
11748 while (*iid)
11750 hr = IXMLDOMDocument_QueryInterface(doc, *iid, (void**)&unk);
11751 EXPECT_HR(hr, S_OK);
11752 if (hr == S_OK)
11754 hr = ISupportErrorInfo_InterfaceSupportsErrorInfo(errorinfo, *iid);
11755 ok(hr == S_OK, "got 0x%08x for %s\n", hr, debugstr_guid(*iid));
11756 IUnknown_Release(unk);
11759 iid++;
11762 ISupportErrorInfo_Release(errorinfo);
11764 while (ptr->type != NODE_INVALID)
11766 IXMLDOMNode *node;
11767 VARIANT type;
11769 V_VT(&type) = VT_I1;
11770 V_I1(&type) = ptr->type;
11772 hr = IXMLDOMDocument_createNode(doc, type, _bstr_(ptr->name), NULL, &node);
11773 ok(hr == S_OK, "%d: got 0x%08x\n", ptr->type, hr);
11775 EXPECT_REF(node, 1);
11776 hr = IXMLDOMNode_QueryInterface(node, &IID_ISupportErrorInfo, (void**)&errorinfo);
11777 ok(hr == S_OK, "%d: got 0x%08x\n", ptr->type, hr);
11778 EXPECT_REF(node, 1);
11780 hr = ISupportErrorInfo_QueryInterface(errorinfo, &IID_IXMLDOMNode, &dummy);
11781 ok(hr == E_NOINTERFACE, "%d: got 0x%08x\n", ptr->type, hr);
11783 iid = ptr->iids;
11785 while (*iid)
11787 hr = IXMLDOMNode_QueryInterface(node, *iid, (void**)&unk);
11788 if (hr == S_OK)
11790 hr = ISupportErrorInfo_InterfaceSupportsErrorInfo(errorinfo, *iid);
11791 ok(hr == S_OK, "%d: got 0x%08x for %s\n", ptr->type, hr, debugstr_guid(*iid));
11792 IUnknown_Release(unk);
11795 iid++;
11798 ISupportErrorInfo_Release(errorinfo);
11799 IXMLDOMNode_Release(node);
11800 ptr++;
11803 /* IXMLDOMNamedNodeMap */
11804 b = VARIANT_FALSE;
11805 hr = IXMLDOMDocument_loadXML(doc, _bstr_(complete4A), &b);
11806 EXPECT_HR(hr, S_OK);
11807 ok(b == VARIANT_TRUE, "got %d\n", b);
11809 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
11810 EXPECT_HR(hr, S_OK);
11812 hr = IXMLDOMElement_get_attributes(elem, &map);
11813 EXPECT_HR(hr, S_OK);
11815 EXPECT_REF(map, 1);
11816 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_ISupportErrorInfo, (void**)&errorinfo);
11817 EXPECT_HR(hr, S_OK);
11818 EXPECT_REF(map, 2);
11820 hr = ISupportErrorInfo_InterfaceSupportsErrorInfo(errorinfo, &IID_IXMLDOMNamedNodeMap);
11821 EXPECT_HR(hr, S_OK);
11823 hr = ISupportErrorInfo_QueryInterface(errorinfo, &IID_IXMLDOMNamedNodeMap, (void**)&map2);
11824 EXPECT_HR(hr, S_OK);
11825 ok(map == map2, "got %p\n", map2);
11826 IXMLDOMNamedNodeMap_Release(map2);
11828 EXPECT_REF(errorinfo, 2);
11829 hr = ISupportErrorInfo_QueryInterface(errorinfo, &IID_IUnknown, (void**)&unk);
11830 EXPECT_HR(hr, S_OK);
11831 EXPECT_REF(errorinfo, 3);
11832 EXPECT_REF(map, 3);
11833 IUnknown_Release(unk);
11835 ISupportErrorInfo_Release(errorinfo);
11836 IXMLDOMNamedNodeMap_Release(map);
11837 IXMLDOMElement_Release(elem);
11839 IXMLDOMDocument_Release(doc);
11840 free_bstrs();
11843 typedef struct {
11844 DOMNodeType type;
11845 const char *name;
11846 const char *put_content;
11847 HRESULT put_hr;
11848 VARTYPE get_vt;
11849 HRESULT get_hr;
11850 } node_value_t;
11852 static const node_value_t nodevalue_test[] = {
11853 { NODE_ELEMENT, "element", "", E_FAIL, VT_NULL, S_FALSE },
11854 { NODE_ATTRIBUTE, "attr", "value", S_OK, VT_BSTR, S_OK },
11855 { NODE_TEXT, "text", "textdata", S_OK, VT_BSTR, S_OK },
11856 { NODE_CDATA_SECTION , "cdata", "cdata data", S_OK, VT_BSTR, S_OK },
11857 { NODE_ENTITY_REFERENCE, "entityref", "ref", E_FAIL, VT_NULL, S_FALSE },
11858 { NODE_PROCESSING_INSTRUCTION, "pi", "instr", S_OK, VT_BSTR, S_OK },
11859 { NODE_COMMENT, "comment", "comment data", S_OK, VT_BSTR, S_OK },
11860 { NODE_DOCUMENT_FRAGMENT, "docfrag", "", E_FAIL, VT_NULL, S_FALSE },
11861 { NODE_INVALID }
11864 static void test_nodeValue(void)
11866 const node_value_t *ptr = nodevalue_test;
11867 IXMLDOMDocument *doc;
11868 HRESULT hr;
11870 doc = create_document(&IID_IXMLDOMDocument);
11871 if (!doc) return;
11873 while (ptr->type != NODE_INVALID)
11875 IXMLDOMNode *node;
11876 VARIANT v;
11878 V_VT(&v) = VT_I2;
11879 V_I2(&v) = ptr->type;
11881 hr = IXMLDOMDocument_createNode(doc, v, _bstr_(ptr->name), NULL, &node);
11882 ok(hr == S_OK, "failed to create node type %d\n", ptr->type);
11884 hr = IXMLDOMNode_get_nodeValue(node, NULL);
11885 ok(hr == E_INVALIDARG, "%d: got 0x%08x\n", ptr->type, hr);
11887 V_VT(&v) = VT_BSTR;
11888 V_BSTR(&v) = _bstr_(ptr->put_content);
11889 hr = IXMLDOMNode_put_nodeValue(node, v);
11890 ok(hr == ptr->put_hr, "%d: got 0x%08x\n", ptr->type, hr);
11892 V_VT(&v) = VT_EMPTY;
11893 hr = IXMLDOMNode_get_nodeValue(node, &v);
11894 ok(hr == ptr->get_hr, "%d: got 0x%08x, expected 0x%08x\n", ptr->type, hr, ptr->get_hr);
11895 ok(V_VT(&v) == ptr->get_vt, "%d: got %d, expected %d\n", ptr->type, V_VT(&v), ptr->get_vt);
11896 if (hr == S_OK)
11897 ok(!lstrcmpW(V_BSTR(&v), _bstr_(ptr->put_content)), "%d: got %s\n", ptr->type,
11898 wine_dbgstr_w(V_BSTR(&v)));
11899 VariantClear(&v);
11901 IXMLDOMNode_Release(node);
11903 ptr++;
11906 IXMLDOMDocument_Release(doc);
11909 static const char namespacesA[] =
11910 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
11911 " <ns1:elem1 xmlns:ns1=\"http://blah.org\" b='1' >"
11912 " <ns2:elem2 xmlns:ns2=\"http://blah.org\"/>"
11913 " <ns1:elem3/>"
11914 " <ns1:elem4/>"
11915 " <elem5 xmlns=\"http://blahblah.org\"/>"
11916 " <ns1:elem6>true</ns1:elem6>"
11917 " </ns1:elem1>";
11919 static const char xsd_schema1_uri[] = "x-schema:test1.xsd";
11920 static const char xsd_schema1_xml[] =
11921 "<?xml version='1.0'?>"
11922 "<schema xmlns='http://www.w3.org/2001/XMLSchema'"
11923 " targetNamespace='x-schema:test1.xsd'>"
11924 " <element name='root'>"
11925 " <complexType>"
11926 " <sequence maxOccurs='unbounded'>"
11927 " <any/>"
11928 " </sequence>"
11929 " </complexType>"
11930 " </element>"
11931 "</schema>";
11933 static void test_get_namespaces(void)
11935 IXMLDOMSchemaCollection *collection, *collection2;
11936 IXMLDOMDocument2 *doc, *doc2;
11937 IEnumVARIANT *enumv, *enum2;
11938 IUnknown *unk1, *unk2;
11939 IXMLDOMNode *node;
11940 VARIANT_BOOL b;
11941 HRESULT hr;
11942 VARIANT v;
11943 LONG len;
11944 BSTR s;
11946 doc = create_document(&IID_IXMLDOMDocument2);
11947 if (!doc) return;
11949 /* null pointer */
11950 hr = IXMLDOMDocument2_get_namespaces(doc, NULL);
11951 EXPECT_HR(hr, E_POINTER);
11953 /* no document loaded */
11954 collection = (void*)0xdeadbeef;
11955 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
11956 EXPECT_HR(hr, S_OK);
11957 if (hr != S_OK)
11959 IXMLDOMDocument_Release(doc);
11960 return;
11962 EXPECT_REF(collection, 2);
11964 collection2 = (void*)0xdeadbeef;
11965 hr = IXMLDOMDocument2_get_namespaces(doc, &collection2);
11966 EXPECT_HR(hr, S_OK);
11967 ok(collection == collection2, "got %p\n", collection2);
11968 EXPECT_REF(collection, 3);
11969 IXMLDOMSchemaCollection_Release(collection);
11971 len = -1;
11972 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
11973 EXPECT_HR(hr, S_OK);
11974 ok(len == 0, "got %d\n", len);
11975 IXMLDOMSchemaCollection_Release(collection);
11977 /* now with document */
11978 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(namespacesA), &b);
11979 EXPECT_HR(hr, S_OK);
11981 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
11982 EXPECT_HR(hr, S_OK);
11984 len = -1;
11985 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
11986 EXPECT_HR(hr, S_OK);
11987 ok(len == 2, "got %d\n", len);
11989 /* try to lookup some uris */
11990 node = (void*)0xdeadbeef;
11991 hr = IXMLDOMSchemaCollection_get(collection, _bstr_("http://blah.org"), &node);
11992 EXPECT_HR(hr, S_OK);
11993 ok(node == NULL, "got %p\n", node);
11995 node = (void*)0xdeadbeef;
11996 hr = IXMLDOMSchemaCollection_get(collection, _bstr_("http://blah1.org"), &node);
11997 EXPECT_HR(hr, S_OK);
11998 ok(node == NULL, "got %p\n", node);
12000 /* load schema and try to add it */
12001 doc2 = create_document(&IID_IXMLDOMDocument2);
12002 hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(xsd_schema1_xml), &b);
12003 EXPECT_HR(hr, S_OK);
12005 V_VT(&v) = VT_DISPATCH;
12006 V_DISPATCH(&v) = (IDispatch*)doc2;
12007 hr = IXMLDOMSchemaCollection_add(collection, _bstr_(xsd_schema1_uri), v);
12008 EXPECT_HR(hr, E_FAIL);
12010 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 0, &s);
12011 EXPECT_HR(hr, S_OK);
12012 ok(!lstrcmpW(s, _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(s));
12013 SysFreeString(s);
12015 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 1, &s);
12016 EXPECT_HR(hr, S_OK);
12017 ok(!lstrcmpW(s, _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(s));
12018 SysFreeString(s);
12020 s = (void*)0xdeadbeef;
12021 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 2, &s);
12022 EXPECT_HR(hr, E_FAIL);
12023 ok(s == (void*)0xdeadbeef, "got %p\n", s);
12025 /* enumerate */
12026 enumv = (void*)0xdeadbeef;
12027 EXPECT_REF(collection, 2);
12028 hr = IXMLDOMSchemaCollection_get__newEnum(collection, (IUnknown**)&enumv);
12029 EXPECT_HR(hr, S_OK);
12030 EXPECT_REF(collection, 3);
12031 ok(enumv != NULL, "got %p\n", enumv);
12033 hr = IXMLDOMSchemaCollection_QueryInterface(collection, &IID_IUnknown, (void**)&unk1);
12034 EXPECT_HR(hr, S_OK);
12035 hr = IEnumVARIANT_QueryInterface(enumv, &IID_IUnknown, (void**)&unk2);
12036 EXPECT_HR(hr, S_OK);
12037 ok(unk1 != unk2, "got %p, %p\n", unk1, unk2);
12038 IUnknown_Release(unk1);
12039 IUnknown_Release(unk2);
12041 hr = IXMLDOMSchemaCollection_QueryInterface(collection, &IID_IEnumVARIANT, (void**)&enum2);
12042 EXPECT_HR(hr, E_NOINTERFACE);
12044 V_VT(&v) = VT_EMPTY;
12045 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
12046 EXPECT_HR(hr, S_OK);
12047 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
12048 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
12049 VariantClear(&v);
12051 V_VT(&v) = VT_EMPTY;
12052 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
12053 EXPECT_HR(hr, S_OK);
12054 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
12055 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
12056 VariantClear(&v);
12058 V_VT(&v) = VT_NULL;
12059 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
12060 EXPECT_HR(hr, S_FALSE);
12061 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
12063 IEnumVARIANT_Release(enumv);
12064 IXMLDOMSchemaCollection_Release(collection);
12066 IXMLDOMDocument2_Release(doc);
12068 /* now with CLSID_DOMDocument60 */
12069 doc = create_document_version(60, &IID_IXMLDOMDocument2);
12070 if (!doc) return;
12072 /* null pointer */
12073 hr = IXMLDOMDocument2_get_namespaces(doc, NULL);
12074 EXPECT_HR(hr, E_POINTER);
12076 /* no document loaded */
12077 collection = (void*)0xdeadbeef;
12078 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
12079 EXPECT_HR(hr, S_OK);
12080 if (hr != S_OK)
12082 IXMLDOMDocument_Release(doc);
12083 return;
12085 EXPECT_REF(collection, 2);
12087 collection2 = (void*)0xdeadbeef;
12088 hr = IXMLDOMDocument2_get_namespaces(doc, &collection2);
12089 EXPECT_HR(hr, S_OK);
12090 ok(collection == collection2, "got %p\n", collection2);
12091 EXPECT_REF(collection, 3);
12092 IXMLDOMSchemaCollection_Release(collection);
12094 len = -1;
12095 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
12096 EXPECT_HR(hr, S_OK);
12097 ok(len == 0, "got %d\n", len);
12098 IXMLDOMSchemaCollection_Release(collection);
12100 /* now with document */
12101 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(namespacesA), &b);
12102 EXPECT_HR(hr, S_OK);
12104 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
12105 EXPECT_HR(hr, S_OK);
12107 len = -1;
12108 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
12109 EXPECT_HR(hr, S_OK);
12110 ok(len == 2, "got %d\n", len);
12112 /* try to lookup some uris */
12113 node = (void*)0xdeadbeef;
12114 hr = IXMLDOMSchemaCollection_get(collection, _bstr_("http://blah.org"), &node);
12115 EXPECT_HR(hr, E_NOTIMPL);
12116 ok(node == (void*)0xdeadbeef, "got %p\n", node);
12118 /* load schema and try to add it */
12119 doc2 = create_document(&IID_IXMLDOMDocument2);
12120 hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(xsd_schema1_xml), &b);
12121 EXPECT_HR(hr, S_OK);
12123 V_VT(&v) = VT_DISPATCH;
12124 V_DISPATCH(&v) = (IDispatch*)doc2;
12125 hr = IXMLDOMSchemaCollection_add(collection, _bstr_(xsd_schema1_uri), v);
12126 EXPECT_HR(hr, E_FAIL);
12127 IXMLDOMSchemaCollection_Release(doc2);
12129 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 0, &s);
12130 EXPECT_HR(hr, S_OK);
12131 ok(!lstrcmpW(s, _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(s));
12132 SysFreeString(s);
12134 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 1, &s);
12135 EXPECT_HR(hr, S_OK);
12136 ok(!lstrcmpW(s, _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(s));
12137 SysFreeString(s);
12139 s = (void*)0xdeadbeef;
12140 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 2, &s);
12141 EXPECT_HR(hr, E_FAIL);
12142 ok(s == (void*)0xdeadbeef, "got %p\n", s);
12144 /* enumerate */
12145 enumv = (void*)0xdeadbeef;
12146 hr = IXMLDOMSchemaCollection_get__newEnum(collection, (IUnknown**)&enumv);
12147 EXPECT_HR(hr, S_OK);
12148 ok(enumv != NULL, "got %p\n", enumv);
12150 V_VT(&v) = VT_EMPTY;
12151 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
12152 EXPECT_HR(hr, S_OK);
12153 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
12154 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
12155 VariantClear(&v);
12157 V_VT(&v) = VT_EMPTY;
12158 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
12159 EXPECT_HR(hr, S_OK);
12160 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
12161 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
12162 VariantClear(&v);
12164 V_VT(&v) = VT_NULL;
12165 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
12166 EXPECT_HR(hr, S_FALSE);
12167 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
12169 IEnumVARIANT_Release(enumv);
12170 IXMLDOMSchemaCollection_Release(collection);
12171 IXMLDOMDocument2_Release(doc);
12172 free_bstrs();
12175 static DOMNodeType put_data_types[] = {
12176 NODE_TEXT,
12177 NODE_CDATA_SECTION,
12178 NODE_PROCESSING_INSTRUCTION,
12179 NODE_COMMENT,
12180 NODE_INVALID
12183 static void test_put_data(void)
12185 static const WCHAR test_data[] = {'t','e','s','t',' ','n','o','d','e',' ','d','a','t','a',0};
12186 WCHAR buff[100], *data;
12187 IXMLDOMDocument *doc;
12188 DOMNodeType *type;
12189 BSTR get_data;
12190 HRESULT hr;
12192 doc = create_document(&IID_IXMLDOMDocument);
12193 if (!doc) return;
12195 memcpy(&buff[2], test_data, sizeof(test_data));
12196 /* just a big length */
12197 *(DWORD*)buff = 0xf0f0;
12198 data = &buff[2];
12200 type = put_data_types;
12201 while (*type != NODE_INVALID)
12203 IXMLDOMNode *node;
12204 VARIANT v;
12206 V_VT(&v) = VT_I2;
12207 V_I2(&v) = *type;
12209 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("name"), NULL, &node);
12210 EXPECT_HR(hr, S_OK);
12212 /* put_data() is interface-specific */
12213 switch (*type)
12215 case NODE_TEXT:
12217 IXMLDOMText *text;
12219 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
12220 EXPECT_HR(hr, S_OK);
12221 hr = IXMLDOMText_put_data(text, data);
12222 EXPECT_HR(hr, S_OK);
12224 hr = IXMLDOMText_get_data(text, &get_data);
12225 EXPECT_HR(hr, S_OK);
12227 IXMLDOMText_Release(text);
12228 break;
12230 case NODE_CDATA_SECTION:
12232 IXMLDOMCDATASection *cdata;
12234 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
12235 EXPECT_HR(hr, S_OK);
12236 hr = IXMLDOMCDATASection_put_data(cdata, data);
12237 EXPECT_HR(hr, S_OK);
12239 hr = IXMLDOMCDATASection_get_data(cdata, &get_data);
12240 EXPECT_HR(hr, S_OK);
12242 IXMLDOMCDATASection_Release(cdata);
12243 break;
12245 case NODE_PROCESSING_INSTRUCTION:
12247 IXMLDOMProcessingInstruction *pi;
12249 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMProcessingInstruction, (void**)&pi);
12250 EXPECT_HR(hr, S_OK);
12251 hr = IXMLDOMProcessingInstruction_put_data(pi, data);
12252 EXPECT_HR(hr, S_OK);
12254 hr = IXMLDOMProcessingInstruction_get_data(pi, &get_data);
12255 EXPECT_HR(hr, S_OK);
12257 IXMLDOMProcessingInstruction_Release(pi);
12258 break;
12260 case NODE_COMMENT:
12262 IXMLDOMComment *comment;
12264 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
12265 EXPECT_HR(hr, S_OK);
12266 hr = IXMLDOMComment_put_data(comment, data);
12267 EXPECT_HR(hr, S_OK);
12269 hr = IXMLDOMComment_get_data(comment, &get_data);
12270 EXPECT_HR(hr, S_OK);
12272 IXMLDOMComment_Release(comment);
12273 break;
12275 default:
12276 break;
12279 /* compare */
12280 ok(!lstrcmpW(data, get_data), "%d: got wrong data %s, expected %s\n", *type, wine_dbgstr_w(get_data),
12281 wine_dbgstr_w(data));
12282 SysFreeString(get_data);
12284 IXMLDOMNode_Release(node);
12285 type++;
12288 IXMLDOMDocument_Release(doc);
12289 free_bstrs();
12292 static void test_putref_schemas(void)
12294 IXMLDOMSchemaCollection *cache;
12295 IXMLDOMDocument2 *doc;
12296 VARIANT schema;
12297 HRESULT hr;
12299 doc = create_document(&IID_IXMLDOMDocument2);
12300 if (!doc) return;
12301 cache = create_cache(&IID_IXMLDOMSchemaCollection);
12303 /* set to NULL iface when no schema is set */
12304 V_VT(&schema) = VT_DISPATCH;
12305 V_DISPATCH(&schema) = NULL;
12306 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
12307 EXPECT_HR(hr, S_OK);
12309 V_VT(&schema) = VT_UNKNOWN;
12310 V_UNKNOWN(&schema) = NULL;
12311 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
12312 EXPECT_HR(hr, S_OK);
12314 /* set as VT_DISPATCH, reset with it */
12315 V_VT(&schema) = VT_DISPATCH;
12316 V_DISPATCH(&schema) = (IDispatch*)cache;
12317 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
12318 EXPECT_HR(hr, S_OK);
12320 V_DISPATCH(&schema) = NULL;
12321 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
12322 EXPECT_HR(hr, S_OK);
12323 ok(V_DISPATCH(&schema) == (IDispatch*)cache, "got %p\n", V_DISPATCH(&schema));
12325 V_VT(&schema) = VT_DISPATCH;
12326 V_DISPATCH(&schema) = NULL;
12327 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
12328 EXPECT_HR(hr, S_OK);
12330 V_DISPATCH(&schema) = (IDispatch*)0xdeadbeef;
12331 V_VT(&schema) = VT_I2;
12332 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
12333 EXPECT_HR(hr, S_FALSE);
12334 ok(V_DISPATCH(&schema) == NULL, "got %p\n", V_DISPATCH(&schema));
12335 ok(V_VT(&schema) == VT_NULL, "got %d\n", V_VT(&schema));
12337 /* set as VT_UNKNOWN, reset with it */
12338 V_VT(&schema) = VT_UNKNOWN;
12339 V_UNKNOWN(&schema) = (IUnknown*)cache;
12340 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
12341 EXPECT_HR(hr, S_OK);
12343 V_DISPATCH(&schema) = NULL;
12344 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
12345 EXPECT_HR(hr, S_OK);
12346 ok(V_DISPATCH(&schema) == (IDispatch*)cache, "got %p\n", V_DISPATCH(&schema));
12348 V_VT(&schema) = VT_UNKNOWN;
12349 V_UNKNOWN(&schema) = NULL;
12350 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
12351 EXPECT_HR(hr, S_OK);
12353 V_DISPATCH(&schema) = (IDispatch*)0xdeadbeef;
12354 V_VT(&schema) = VT_I2;
12355 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
12356 EXPECT_HR(hr, S_FALSE);
12357 ok(V_DISPATCH(&schema) == NULL, "got %p\n", V_DISPATCH(&schema));
12358 ok(V_VT(&schema) == VT_NULL, "got %d\n", V_VT(&schema));
12360 IXMLDOMSchemaCollection_Release(cache);
12361 IXMLDOMDocument2_Release(doc);
12364 static void test_namedmap_newenum(void)
12366 IEnumVARIANT *enum1, *enum2, *enum3;
12367 IXMLDOMNamedNodeMap *map;
12368 IUnknown *unk1, *unk2;
12369 IXMLDOMDocument *doc;
12370 IXMLDOMElement *elem;
12371 IXMLDOMNode *node;
12372 VARIANT_BOOL b;
12373 HRESULT hr;
12374 VARIANT v;
12375 BSTR str;
12377 doc = create_document(&IID_IXMLDOMDocument);
12379 hr = IXMLDOMDocument_loadXML(doc, _bstr_(attributes_map), &b);
12380 EXPECT_HR(hr, S_OK);
12382 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
12383 EXPECT_HR(hr, S_OK);
12385 hr = IXMLDOMElement_get_attributes(elem, &map);
12386 EXPECT_HR(hr, S_OK);
12387 IXMLDOMElement_Release(elem);
12389 enum1 = NULL;
12390 EXPECT_REF(map, 1);
12391 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IEnumVARIANT, (void**)&enum1);
12392 EXPECT_HR(hr, S_OK);
12393 ok(enum1 != NULL, "got %p\n", enum1);
12394 EXPECT_REF(map, 1);
12395 EXPECT_REF(enum1, 2);
12397 enum2 = NULL;
12398 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IEnumVARIANT, (void**)&enum2);
12399 EXPECT_HR(hr, S_OK);
12400 ok(enum2 == enum1, "got %p\n", enum2);
12402 IEnumVARIANT_Release(enum2);
12404 EXPECT_REF(map, 1);
12405 hr = IXMLDOMNamedNodeMap__newEnum(map, (IUnknown**)&enum2);
12406 EXPECT_HR(hr, S_OK);
12407 EXPECT_REF(map, 2);
12408 EXPECT_REF(enum2, 1);
12409 ok(enum2 != enum1, "got %p, %p\n", enum2, enum1);
12411 IEnumVARIANT_Release(enum1);
12413 /* enumerator created with _newEnum() doesn't share IUnknown* with main object */
12414 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IUnknown, (void**)&unk1);
12415 EXPECT_HR(hr, S_OK);
12416 hr = IEnumVARIANT_QueryInterface(enum2, &IID_IUnknown, (void**)&unk2);
12417 EXPECT_HR(hr, S_OK);
12418 EXPECT_REF(map, 3);
12419 EXPECT_REF(enum2, 2);
12420 ok(unk1 != unk2, "got %p, %p\n", unk1, unk2);
12421 IUnknown_Release(unk1);
12422 IUnknown_Release(unk2);
12424 hr = IXMLDOMNamedNodeMap__newEnum(map, (IUnknown**)&enum3);
12425 EXPECT_HR(hr, S_OK);
12426 ok(enum2 != enum3, "got %p, %p\n", enum2, enum3);
12427 IEnumVARIANT_Release(enum3);
12429 /* iteration tests */
12430 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node);
12431 EXPECT_HR(hr, S_OK);
12432 hr = IXMLDOMNode_get_nodeName(node, &str);
12433 EXPECT_HR(hr, S_OK);
12434 ok(!lstrcmpW(str, _bstr_("attr1")), "got %s\n", wine_dbgstr_w(str));
12435 SysFreeString(str);
12436 IXMLDOMNode_Release(node);
12438 hr = IXMLDOMNamedNodeMap_nextNode(map, &node);
12439 EXPECT_HR(hr, S_OK);
12440 hr = IXMLDOMNode_get_nodeName(node, &str);
12441 EXPECT_HR(hr, S_OK);
12442 ok(!lstrcmpW(str, _bstr_("attr1")), "got %s\n", wine_dbgstr_w(str));
12443 SysFreeString(str);
12444 IXMLDOMNode_Release(node);
12446 V_VT(&v) = VT_EMPTY;
12447 hr = IEnumVARIANT_Next(enum2, 1, &v, NULL);
12448 EXPECT_HR(hr, S_OK);
12449 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
12450 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
12451 EXPECT_HR(hr, S_OK);
12452 hr = IXMLDOMNode_get_nodeName(node, &str);
12453 EXPECT_HR(hr, S_OK);
12454 ok(!lstrcmpW(str, _bstr_("attr1")), "got node name %s\n", wine_dbgstr_w(str));
12455 SysFreeString(str);
12456 IXMLDOMNode_Release(node);
12457 VariantClear(&v);
12459 hr = IXMLDOMNamedNodeMap_nextNode(map, &node);
12460 EXPECT_HR(hr, S_OK);
12461 hr = IXMLDOMNode_get_nodeName(node, &str);
12462 EXPECT_HR(hr, S_OK);
12463 ok(!lstrcmpW(str, _bstr_("attr2")), "got %s\n", wine_dbgstr_w(str));
12464 SysFreeString(str);
12465 IXMLDOMNode_Release(node);
12467 IEnumVARIANT_Release(enum2);
12468 IXMLDOMNamedNodeMap_Release(map);
12469 IXMLDOMDocument_Release(doc);
12472 START_TEST(domdoc)
12474 IXMLDOMDocument *doc;
12475 IUnknown *unk;
12476 HRESULT hr;
12478 hr = CoInitialize( NULL );
12479 ok( hr == S_OK, "failed to init com\n");
12480 if (hr != S_OK) return;
12482 test_XMLHTTP();
12484 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc );
12485 if (hr != S_OK)
12487 win_skip("IXMLDOMDocument is not available (0x%08x)\n", hr);
12488 return;
12491 IXMLDOMDocument_Release(doc);
12493 test_domdoc();
12494 test_persiststreaminit();
12495 test_domnode();
12496 test_refs();
12497 test_create();
12498 test_getElementsByTagName();
12499 test_get_text();
12500 test_get_childNodes();
12501 test_get_firstChild();
12502 test_get_lastChild();
12503 test_removeChild();
12504 test_replaceChild();
12505 test_removeNamedItem();
12506 test_IXMLDOMDocument2();
12507 test_whitespace();
12508 test_XPath();
12509 test_XSLPattern();
12510 test_cloneNode();
12511 test_xmlTypes();
12512 test_save();
12513 test_testTransforms();
12514 test_namespaces_basic();
12515 test_namespaces_change();
12516 test_FormattingXML();
12517 test_nodeTypedValue();
12518 test_TransformWithLoadingLocalFile();
12519 test_put_nodeValue();
12520 test_document_IObjectSafety();
12521 test_splitText();
12522 test_getQualifiedItem();
12523 test_removeQualifiedItem();
12524 test_get_ownerDocument();
12525 test_setAttributeNode();
12526 test_put_dataType();
12527 test_createNode();
12528 test_get_prefix();
12529 test_default_properties();
12530 test_selectSingleNode();
12531 test_events();
12532 test_createProcessingInstruction();
12533 test_put_nodeTypedValue();
12534 test_get_xml();
12535 test_insertBefore();
12536 test_appendChild();
12537 test_get_doctype();
12538 test_get_tagName();
12539 test_get_dataType();
12540 test_get_nodeTypeString();
12541 test_get_attributes();
12542 test_selection();
12543 test_load();
12544 test_dispex();
12545 test_parseerror();
12546 test_getAttributeNode();
12547 test_supporterrorinfo();
12548 test_nodeValue();
12549 test_get_namespaces();
12550 test_put_data();
12551 test_putref_schemas();
12552 test_namedmap_newenum();
12554 test_xsltemplate();
12556 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
12557 &IID_IMXNamespaceManager, (void**)&unk);
12558 if (hr == S_OK)
12560 test_mxnamespacemanager();
12561 test_mxnamespacemanager_override();
12563 IUnknown_Release(unk);
12565 else
12566 win_skip("MXNamespaceManager is not available\n");
12568 CoUninitialize();