msxml3: Support IDispatchEx for IXMLDOMParseError.
[wine/multimedia.git] / dlls / msxml3 / tests / domdoc.c
blobe1be91201da8c63f3c8c94345802d85820c20985
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-2011 Nikolay Sivov for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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 DEFINE_GUID(SID_SContainerDispatch, 0xb722be00, 0x4e68, 0x101b, 0xa2, 0xbc, 0x00, 0xaa, 0x00, 0x40, 0x47, 0x70);
45 DEFINE_GUID(SID_UnknownSID, 0x75dd09cb, 0x6c40, 0x11d5, 0x85, 0x43, 0x00, 0xc0, 0x4f, 0xa0, 0xfb, 0xa3);
47 #define DEFINE_EXPECT(func) \
48 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
50 #define SET_EXPECT(func) \
51 expect_ ## func = TRUE
53 #define CHECK_EXPECT2(func) \
54 do { \
55 ok(expect_ ##func, "unexpected call " #func "\n"); \
56 called_ ## func = TRUE; \
57 }while(0)
59 #define CHECK_CALLED(func) \
60 do { \
61 ok(called_ ## func, "expected " #func "\n"); \
62 expect_ ## func = called_ ## func = FALSE; \
63 }while(0)
65 static const char *debugstr_guid(REFIID riid)
67 static char buf[50];
69 if(!riid)
70 return "(null)";
72 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
73 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
74 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
75 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
77 return buf;
80 static int g_unexpectedcall, g_expectedcall;
82 typedef struct
84 IDispatch IDispatch_iface;
85 LONG ref;
86 } dispevent;
88 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
90 return CONTAINING_RECORD(iface, dispevent, IDispatch_iface);
93 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
95 *ppvObject = NULL;
97 if ( IsEqualGUID( riid, &IID_IDispatch) ||
98 IsEqualGUID( riid, &IID_IUnknown) )
100 *ppvObject = iface;
102 else
103 return E_NOINTERFACE;
105 IDispatch_AddRef( iface );
107 return S_OK;
110 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
112 dispevent *This = impl_from_IDispatch( iface );
113 return InterlockedIncrement( &This->ref );
116 static ULONG WINAPI dispevent_Release(IDispatch *iface)
118 dispevent *This = impl_from_IDispatch( iface );
119 ULONG ref = InterlockedDecrement( &This->ref );
121 if (ref == 0)
122 HeapFree(GetProcessHeap(), 0, This);
124 return ref;
127 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
129 g_unexpectedcall++;
130 *pctinfo = 0;
131 return S_OK;
134 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
135 LCID lcid, ITypeInfo **ppTInfo)
137 g_unexpectedcall++;
138 return S_OK;
141 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
142 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
144 g_unexpectedcall++;
145 return S_OK;
148 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
149 LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
150 EXCEPINFO *excepInfo, UINT *argErr)
152 ok(member == 0, "expected 0 member, got %d\n", member);
153 ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
154 ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
156 ok(params->cArgs == 0, "got %d\n", params->cArgs);
157 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
158 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
159 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
161 ok(result == NULL, "got %p\n", result);
162 ok(excepInfo == NULL, "got %p\n", excepInfo);
163 ok(argErr == NULL, "got %p\n", argErr);
165 g_expectedcall++;
166 return E_FAIL;
169 static const IDispatchVtbl dispeventVtbl =
171 dispevent_QueryInterface,
172 dispevent_AddRef,
173 dispevent_Release,
174 dispevent_GetTypeInfoCount,
175 dispevent_GetTypeInfo,
176 dispevent_GetIDsOfNames,
177 dispevent_Invoke
180 static IDispatch* create_dispevent(void)
182 dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
184 event->IDispatch_iface.lpVtbl = &dispeventVtbl;
185 event->ref = 1;
187 return (IDispatch*)&event->IDispatch_iface;
190 /* object site */
191 DEFINE_EXPECT(site_qi_IServiceProvider);
192 DEFINE_EXPECT(site_qi_IXMLDOMDocument);
193 DEFINE_EXPECT(site_qi_IOleClientSite);
195 DEFINE_EXPECT(sp_queryservice_SID_SBindHost);
196 DEFINE_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
197 DEFINE_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
198 DEFINE_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
199 DEFINE_EXPECT(sp_queryservice_SID_secmgr_secmgr);
201 DEFINE_EXPECT(htmldoc2_get_all);
202 DEFINE_EXPECT(htmldoc2_get_url);
203 DEFINE_EXPECT(collection_get_length);
205 typedef struct
207 IServiceProvider IServiceProvider_iface;
208 } testprov_t;
210 testprov_t testprov;
212 static HRESULT WINAPI site_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
214 *ppvObject = NULL;
216 if (IsEqualGUID(riid, &IID_IServiceProvider))
217 CHECK_EXPECT2(site_qi_IServiceProvider);
219 if (IsEqualGUID(riid, &IID_IXMLDOMDocument))
220 CHECK_EXPECT2(site_qi_IXMLDOMDocument);
222 if (IsEqualGUID(riid, &IID_IOleClientSite))
223 CHECK_EXPECT2(site_qi_IOleClientSite);
225 if (IsEqualGUID(riid, &IID_IUnknown))
226 *ppvObject = iface;
227 else if (IsEqualGUID(riid, &IID_IServiceProvider))
228 *ppvObject = &testprov.IServiceProvider_iface;
230 if (*ppvObject) IUnknown_AddRef(iface);
232 return *ppvObject ? S_OK : E_NOINTERFACE;
235 static ULONG WINAPI site_AddRef(IUnknown *iface)
237 return 2;
240 static ULONG WINAPI site_Release(IUnknown *iface)
242 return 1;
245 static const IUnknownVtbl testsiteVtbl =
247 site_QueryInterface,
248 site_AddRef,
249 site_Release
252 typedef struct
254 IUnknown IUnknown_iface;
255 } testsite_t;
257 static testsite_t testsite = { { &testsiteVtbl } };
259 /* test IHTMLElementCollection */
260 static HRESULT WINAPI htmlecoll_QueryInterface(IHTMLElementCollection *iface, REFIID riid, void **ppvObject)
262 ok(0, "unexpected call\n");
263 *ppvObject = NULL;
264 return E_NOINTERFACE;
267 static ULONG WINAPI htmlecoll_AddRef(IHTMLElementCollection *iface)
269 return 2;
272 static ULONG WINAPI htmlecoll_Release(IHTMLElementCollection *iface)
274 return 1;
277 static HRESULT WINAPI htmlecoll_GetTypeInfoCount(IHTMLElementCollection *iface, UINT *pctinfo)
279 ok(0, "unexpected call\n");
280 return E_NOTIMPL;
283 static HRESULT WINAPI htmlecoll_GetTypeInfo(IHTMLElementCollection *iface, UINT iTInfo,
284 LCID lcid, ITypeInfo **ppTInfo)
286 ok(0, "unexpected call\n");
287 return E_NOTIMPL;
290 static HRESULT WINAPI htmlecoll_GetIDsOfNames(IHTMLElementCollection *iface, REFIID riid,
291 LPOLESTR *rgszNames, UINT cNames,
292 LCID lcid, DISPID *rgDispId)
294 ok(0, "unexpected call\n");
295 return E_NOTIMPL;
298 static HRESULT WINAPI htmlecoll_Invoke(IHTMLElementCollection *iface, DISPID dispIdMember,
299 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
300 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
302 ok(0, "unexpected call\n");
303 return E_NOTIMPL;
306 static HRESULT WINAPI htmlecoll_toString(IHTMLElementCollection *iface, BSTR *String)
308 ok(0, "unexpected call\n");
309 return E_NOTIMPL;
312 static HRESULT WINAPI htmlecoll_put_length(IHTMLElementCollection *iface, LONG v)
314 ok(0, "unexpected call\n");
315 return E_NOTIMPL;
318 static HRESULT WINAPI htmlecoll_get_length(IHTMLElementCollection *iface, LONG *v)
320 CHECK_EXPECT2(collection_get_length);
321 return E_NOTIMPL;
324 static HRESULT WINAPI htmlecoll_get__newEnum(IHTMLElementCollection *iface, IUnknown **p)
326 ok(0, "unexpected call\n");
327 return E_NOTIMPL;
330 static HRESULT WINAPI htmlecoll_item(IHTMLElementCollection *iface, VARIANT name, VARIANT index, IDispatch **pdisp)
332 ok(0, "unexpected call\n");
333 return E_NOTIMPL;
336 static HRESULT WINAPI htmlecoll_tags(IHTMLElementCollection *iface, VARIANT tagName, IDispatch **pdisp)
338 ok(0, "unexpected call\n");
339 return E_NOTIMPL;
342 static const IHTMLElementCollectionVtbl TestHTMLECollectionVtbl = {
343 htmlecoll_QueryInterface,
344 htmlecoll_AddRef,
345 htmlecoll_Release,
346 htmlecoll_GetTypeInfoCount,
347 htmlecoll_GetTypeInfo,
348 htmlecoll_GetIDsOfNames,
349 htmlecoll_Invoke,
351 htmlecoll_toString,
352 htmlecoll_put_length,
353 htmlecoll_get_length,
354 htmlecoll_get__newEnum,
355 htmlecoll_item,
356 htmlecoll_tags
359 typedef struct
361 IHTMLElementCollection IHTMLElementCollection_iface;
362 } testhtmlecoll_t;
364 static testhtmlecoll_t htmlecoll = { { &TestHTMLECollectionVtbl } };
366 /* test IHTMLDocument2 */
367 static HRESULT WINAPI htmldoc2_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
369 trace("\n");
370 *ppvObject = NULL;
371 return E_NOINTERFACE;
374 static ULONG WINAPI htmldoc2_AddRef(IHTMLDocument2 *iface)
376 return 2;
379 static ULONG WINAPI htmldoc2_Release(IHTMLDocument2 *iface)
381 return 1;
384 static HRESULT WINAPI htmldoc2_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
386 ok(0, "unexpected call\n");
387 return E_NOTIMPL;
390 static HRESULT WINAPI htmldoc2_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
391 LCID lcid, ITypeInfo **ppTInfo)
393 ok(0, "unexpected call\n");
394 return E_NOTIMPL;
397 static HRESULT WINAPI htmldoc2_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
398 LPOLESTR *rgszNames, UINT cNames,
399 LCID lcid, DISPID *rgDispId)
401 ok(0, "unexpected call\n");
402 return E_NOTIMPL;
405 static HRESULT WINAPI htmldoc2_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
406 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
407 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
409 ok(0, "unexpected call\n");
410 return E_NOTIMPL;
413 static HRESULT WINAPI htmldoc2_get_Script(IHTMLDocument2 *iface, IDispatch **p)
415 ok(0, "unexpected call\n");
416 return E_NOTIMPL;
419 static HRESULT WINAPI htmldoc2_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
421 CHECK_EXPECT2(htmldoc2_get_all);
422 *p = &htmlecoll.IHTMLElementCollection_iface;
423 return S_OK;
426 static HRESULT WINAPI htmldoc2_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
428 ok(0, "unexpected call\n");
429 return E_NOTIMPL;
432 static HRESULT WINAPI htmldoc2_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
434 ok(0, "unexpected call\n");
435 return E_NOTIMPL;
438 static HRESULT WINAPI htmldoc2_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
440 ok(0, "unexpected call\n");
441 return E_NOTIMPL;
444 static HRESULT WINAPI htmldoc2_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
446 ok(0, "unexpected call\n");
447 return E_NOTIMPL;
450 static HRESULT WINAPI htmldoc2_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
452 ok(0, "unexpected call\n");
453 return E_NOTIMPL;
456 static HRESULT WINAPI htmldoc2_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
458 ok(0, "unexpected call\n");
459 return E_NOTIMPL;
462 static HRESULT WINAPI htmldoc2_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
464 ok(0, "unexpected call\n");
465 return E_NOTIMPL;
468 static HRESULT WINAPI htmldoc2_put_title(IHTMLDocument2 *iface, BSTR v)
470 ok(0, "unexpected call\n");
471 return E_NOTIMPL;
474 static HRESULT WINAPI htmldoc2_get_title(IHTMLDocument2 *iface, BSTR *p)
476 ok(0, "unexpected call\n");
477 return E_NOTIMPL;
480 static HRESULT WINAPI htmldoc2_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
482 ok(0, "unexpected call\n");
483 return E_NOTIMPL;
486 static HRESULT WINAPI htmldoc2_put_designMode(IHTMLDocument2 *iface, BSTR v)
488 ok(0, "unexpected call\n");
489 return E_NOTIMPL;
492 static HRESULT WINAPI htmldoc2_get_designMode(IHTMLDocument2 *iface, BSTR *p)
494 ok(0, "unexpected call\n");
495 return E_NOTIMPL;
498 static HRESULT WINAPI htmldoc2_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
500 ok(0, "unexpected call\n");
501 return E_NOTIMPL;
504 static HRESULT WINAPI htmldoc2_get_readyState(IHTMLDocument2 *iface, BSTR *p)
506 ok(0, "unexpected call\n");
507 return E_NOTIMPL;
510 static HRESULT WINAPI htmldoc2_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
512 ok(0, "unexpected call\n");
513 return E_NOTIMPL;
516 static HRESULT WINAPI htmldoc2_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
518 ok(0, "unexpected call\n");
519 return E_NOTIMPL;
522 static HRESULT WINAPI htmldoc2_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
524 ok(0, "unexpected call\n");
525 return E_NOTIMPL;
528 static HRESULT WINAPI htmldoc2_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
530 ok(0, "unexpected call\n");
531 return E_NOTIMPL;
534 static HRESULT WINAPI htmldoc2_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
536 ok(0, "unexpected call\n");
537 return E_NOTIMPL;
540 static HRESULT WINAPI htmldoc2_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
542 ok(0, "unexpected call\n");
543 return E_NOTIMPL;
546 static HRESULT WINAPI htmldoc2_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
548 ok(0, "unexpected call\n");
549 return E_NOTIMPL;
552 static HRESULT WINAPI htmldoc2_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
554 ok(0, "unexpected call\n");
555 return E_NOTIMPL;
558 static HRESULT WINAPI htmldoc2_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
560 ok(0, "unexpected call\n");
561 return E_NOTIMPL;
564 static HRESULT WINAPI htmldoc2_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
566 ok(0, "unexpected call\n");
567 return E_NOTIMPL;
570 static HRESULT WINAPI htmldoc2_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
572 ok(0, "unexpected call\n");
573 return E_NOTIMPL;
576 static HRESULT WINAPI htmldoc2_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
578 ok(0, "unexpected call\n");
579 return E_NOTIMPL;
582 static HRESULT WINAPI htmldoc2_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
584 ok(0, "unexpected call\n");
585 return E_NOTIMPL;
588 static HRESULT WINAPI htmldoc2_get_referrer(IHTMLDocument2 *iface, BSTR *p)
590 ok(0, "unexpected call\n");
591 return E_NOTIMPL;
594 static HRESULT WINAPI htmldoc2_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
596 ok(0, "unexpected call\n");
597 return E_NOTIMPL;
600 static HRESULT WINAPI htmldoc2_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
602 ok(0, "unexpected call\n");
603 return E_NOTIMPL;
606 static HRESULT WINAPI htmldoc2_put_URL(IHTMLDocument2 *iface, BSTR v)
608 ok(0, "unexpected call\n");
609 return E_NOTIMPL;
612 static HRESULT WINAPI htmldoc2_get_URL(IHTMLDocument2 *iface, BSTR *p)
614 CHECK_EXPECT2(htmldoc2_get_url);
615 *p = SysAllocString(NULL);
616 return S_OK;
619 static HRESULT WINAPI htmldoc2_put_domain(IHTMLDocument2 *iface, BSTR v)
621 ok(0, "unexpected call\n");
622 return E_NOTIMPL;
625 static HRESULT WINAPI htmldoc2_get_domain(IHTMLDocument2 *iface, BSTR *p)
627 ok(0, "unexpected call\n");
628 return E_NOTIMPL;
631 static HRESULT WINAPI htmldoc2_put_cookie(IHTMLDocument2 *iface, BSTR v)
633 ok(0, "unexpected call\n");
634 return E_NOTIMPL;
637 static HRESULT WINAPI htmldoc2_get_cookie(IHTMLDocument2 *iface, BSTR *p)
639 ok(0, "unexpected call\n");
640 return E_NOTIMPL;
643 static HRESULT WINAPI htmldoc2_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
645 ok(0, "unexpected call\n");
646 return E_NOTIMPL;
649 static HRESULT WINAPI htmldoc2_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
651 ok(0, "unexpected call\n");
652 return E_NOTIMPL;
655 static HRESULT WINAPI htmldoc2_put_charset(IHTMLDocument2 *iface, BSTR v)
657 ok(0, "unexpected call\n");
658 return E_NOTIMPL;
661 static HRESULT WINAPI htmldoc2_get_charset(IHTMLDocument2 *iface, BSTR *p)
663 ok(0, "unexpected call\n");
664 return E_NOTIMPL;
667 static HRESULT WINAPI htmldoc2_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
669 ok(0, "unexpected call\n");
670 return E_NOTIMPL;
673 static HRESULT WINAPI htmldoc2_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
675 ok(0, "unexpected call\n");
676 return E_NOTIMPL;
679 static HRESULT WINAPI htmldoc2_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
681 ok(0, "unexpected call\n");
682 return E_NOTIMPL;
685 static HRESULT WINAPI htmldoc2_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
687 ok(0, "unexpected call\n");
688 return E_NOTIMPL;
691 static HRESULT WINAPI htmldoc2_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
693 ok(0, "unexpected call\n");
694 return E_NOTIMPL;
697 static HRESULT WINAPI htmldoc2_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
699 ok(0, "unexpected call\n");
700 return E_NOTIMPL;
703 static HRESULT WINAPI htmldoc2_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
705 ok(0, "unexpected call\n");
706 return E_NOTIMPL;
709 static HRESULT WINAPI htmldoc2_get_security(IHTMLDocument2 *iface, BSTR *p)
711 ok(0, "unexpected call\n");
712 return E_NOTIMPL;
715 static HRESULT WINAPI htmldoc2_get_protocol(IHTMLDocument2 *iface, BSTR *p)
717 ok(0, "unexpected call\n");
718 return E_NOTIMPL;
721 static HRESULT WINAPI htmldoc2_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
723 ok(0, "unexpected call\n");
724 return E_NOTIMPL;
727 static HRESULT WINAPI htmldoc2_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
729 ok(0, "unexpected call\n");
730 return E_NOTIMPL;
733 static HRESULT WINAPI htmldoc2_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
735 ok(0, "unexpected call\n");
736 return E_NOTIMPL;
739 static HRESULT WINAPI htmldoc2_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
740 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
742 ok(0, "unexpected call\n");
743 return E_NOTIMPL;
746 static HRESULT WINAPI htmldoc2_close(IHTMLDocument2 *iface)
748 ok(0, "unexpected call\n");
749 return E_NOTIMPL;
752 static HRESULT WINAPI htmldoc2_clear(IHTMLDocument2 *iface)
754 ok(0, "unexpected call\n");
755 return E_NOTIMPL;
758 static HRESULT WINAPI htmldoc2_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
759 VARIANT_BOOL *pfRet)
761 ok(0, "unexpected call\n");
762 return E_NOTIMPL;
765 static HRESULT WINAPI htmldoc2_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
766 VARIANT_BOOL *pfRet)
768 ok(0, "unexpected call\n");
769 return E_NOTIMPL;
772 static HRESULT WINAPI htmldoc2_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
773 VARIANT_BOOL *pfRet)
775 ok(0, "unexpected call\n");
776 return E_NOTIMPL;
779 static HRESULT WINAPI htmldoc2_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
780 VARIANT_BOOL *pfRet)
782 ok(0, "unexpected call\n");
783 return E_NOTIMPL;
786 static HRESULT WINAPI htmldoc2_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
787 BSTR *pfRet)
789 ok(0, "unexpected call\n");
790 return E_NOTIMPL;
793 static HRESULT WINAPI htmldoc2_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
794 VARIANT *pfRet)
796 ok(0, "unexpected call\n");
797 return E_NOTIMPL;
800 static HRESULT WINAPI htmldoc2_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
801 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
803 ok(0, "unexpected call\n");
804 return E_NOTIMPL;
807 static HRESULT WINAPI htmldoc2_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
808 VARIANT_BOOL *pfRet)
810 ok(0, "unexpected call\n");
811 return E_NOTIMPL;
814 static HRESULT WINAPI htmldoc2_createElement(IHTMLDocument2 *iface, BSTR eTag,
815 IHTMLElement **newElem)
817 ok(0, "unexpected call\n");
818 return E_NOTIMPL;
821 static HRESULT WINAPI htmldoc2_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
823 ok(0, "unexpected call\n");
824 return E_NOTIMPL;
827 static HRESULT WINAPI htmldoc2_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
829 ok(0, "unexpected call\n");
830 return E_NOTIMPL;
833 static HRESULT WINAPI htmldoc2_put_onclick(IHTMLDocument2 *iface, VARIANT v)
835 ok(0, "unexpected call\n");
836 return E_NOTIMPL;
839 static HRESULT WINAPI htmldoc2_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
841 ok(0, "unexpected call\n");
842 return E_NOTIMPL;
845 static HRESULT WINAPI htmldoc2_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
847 ok(0, "unexpected call\n");
848 return E_NOTIMPL;
851 static HRESULT WINAPI htmldoc2_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
853 ok(0, "unexpected call\n");
854 return E_NOTIMPL;
857 static HRESULT WINAPI htmldoc2_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
859 ok(0, "unexpected call\n");
860 return E_NOTIMPL;
863 static HRESULT WINAPI htmldoc2_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
865 ok(0, "unexpected call\n");
866 return E_NOTIMPL;
869 static HRESULT WINAPI htmldoc2_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
871 ok(0, "unexpected call\n");
872 return E_NOTIMPL;
875 static HRESULT WINAPI htmldoc2_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
877 ok(0, "unexpected call\n");
878 return E_NOTIMPL;
881 static HRESULT WINAPI htmldoc2_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
883 ok(0, "unexpected call\n");
884 return E_NOTIMPL;
887 static HRESULT WINAPI htmldoc2_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
889 ok(0, "unexpected call\n");
890 return E_NOTIMPL;
893 static HRESULT WINAPI htmldoc2_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
895 ok(0, "unexpected call\n");
896 return E_NOTIMPL;
899 static HRESULT WINAPI htmldoc2_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
901 ok(0, "unexpected call\n");
902 return E_NOTIMPL;
905 static HRESULT WINAPI htmldoc2_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
907 ok(0, "unexpected call\n");
908 return E_NOTIMPL;
911 static HRESULT WINAPI htmldoc2_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
913 ok(0, "unexpected call\n");
914 return E_NOTIMPL;
917 static HRESULT WINAPI htmldoc2_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
919 ok(0, "unexpected call\n");
920 return E_NOTIMPL;
923 static HRESULT WINAPI htmldoc2_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
925 ok(0, "unexpected call\n");
926 return E_NOTIMPL;
929 static HRESULT WINAPI htmldoc2_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
931 ok(0, "unexpected call\n");
932 return E_NOTIMPL;
935 static HRESULT WINAPI htmldoc2_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
937 ok(0, "unexpected call\n");
938 return E_NOTIMPL;
941 static HRESULT WINAPI htmldoc2_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
943 ok(0, "unexpected call\n");
944 return E_NOTIMPL;
947 static HRESULT WINAPI htmldoc2_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
949 ok(0, "unexpected call\n");
950 return E_NOTIMPL;
953 static HRESULT WINAPI htmldoc2_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
955 ok(0, "unexpected call\n");
956 return E_NOTIMPL;
959 static HRESULT WINAPI htmldoc2_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
961 ok(0, "unexpected call\n");
962 return E_NOTIMPL;
965 static HRESULT WINAPI htmldoc2_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
967 ok(0, "unexpected call\n");
968 return E_NOTIMPL;
971 static HRESULT WINAPI htmldoc2_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
973 ok(0, "unexpected call\n");
974 return E_NOTIMPL;
977 static HRESULT WINAPI htmldoc2_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
979 ok(0, "unexpected call\n");
980 return E_NOTIMPL;
983 static HRESULT WINAPI htmldoc2_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
985 ok(0, "unexpected call\n");
986 return E_NOTIMPL;
989 static HRESULT WINAPI htmldoc2_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
991 ok(0, "unexpected call\n");
992 return E_NOTIMPL;
995 static HRESULT WINAPI htmldoc2_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
997 ok(0, "unexpected call\n");
998 return E_NOTIMPL;
1001 static HRESULT WINAPI htmldoc2_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1003 ok(0, "unexpected call\n");
1004 return E_NOTIMPL;
1007 static HRESULT WINAPI htmldoc2_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1009 ok(0, "unexpected call\n");
1010 return E_NOTIMPL;
1013 static HRESULT WINAPI htmldoc2_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1015 ok(0, "unexpected call\n");
1016 return E_NOTIMPL;
1019 static HRESULT WINAPI htmldoc2_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1021 ok(0, "unexpected call\n");
1022 return E_NOTIMPL;
1025 static HRESULT WINAPI htmldoc2_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1026 IHTMLElement **elementHit)
1028 ok(0, "unexpected call\n");
1029 return E_NOTIMPL;
1032 static HRESULT WINAPI htmldoc2_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1034 ok(0, "unexpected call\n");
1035 return E_NOTIMPL;
1038 static HRESULT WINAPI htmldoc2_get_styleSheets(IHTMLDocument2 *iface,
1039 IHTMLStyleSheetsCollection **p)
1041 ok(0, "unexpected call\n");
1042 return E_NOTIMPL;
1045 static HRESULT WINAPI htmldoc2_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1047 ok(0, "unexpected call\n");
1048 return E_NOTIMPL;
1051 static HRESULT WINAPI htmldoc2_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1053 ok(0, "unexpected call\n");
1054 return E_NOTIMPL;
1057 static HRESULT WINAPI htmldoc2_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1059 ok(0, "unexpected call\n");
1060 return E_NOTIMPL;
1063 static HRESULT WINAPI htmldoc2_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1065 ok(0, "unexpected call\n");
1066 return E_NOTIMPL;
1069 static HRESULT WINAPI htmldoc2_toString(IHTMLDocument2 *iface, BSTR *String)
1071 ok(0, "unexpected call\n");
1072 return E_NOTIMPL;
1075 static HRESULT WINAPI htmldoc2_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1076 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1078 ok(0, "unexpected call\n");
1079 return E_NOTIMPL;
1082 static const IHTMLDocument2Vtbl TestHTMLDocumentVtbl = {
1083 htmldoc2_QueryInterface,
1084 htmldoc2_AddRef,
1085 htmldoc2_Release,
1086 htmldoc2_GetTypeInfoCount,
1087 htmldoc2_GetTypeInfo,
1088 htmldoc2_GetIDsOfNames,
1089 htmldoc2_Invoke,
1090 htmldoc2_get_Script,
1091 htmldoc2_get_all,
1092 htmldoc2_get_body,
1093 htmldoc2_get_activeElement,
1094 htmldoc2_get_images,
1095 htmldoc2_get_applets,
1096 htmldoc2_get_links,
1097 htmldoc2_get_forms,
1098 htmldoc2_get_anchors,
1099 htmldoc2_put_title,
1100 htmldoc2_get_title,
1101 htmldoc2_get_scripts,
1102 htmldoc2_put_designMode,
1103 htmldoc2_get_designMode,
1104 htmldoc2_get_selection,
1105 htmldoc2_get_readyState,
1106 htmldoc2_get_frames,
1107 htmldoc2_get_embeds,
1108 htmldoc2_get_plugins,
1109 htmldoc2_put_alinkColor,
1110 htmldoc2_get_alinkColor,
1111 htmldoc2_put_bgColor,
1112 htmldoc2_get_bgColor,
1113 htmldoc2_put_fgColor,
1114 htmldoc2_get_fgColor,
1115 htmldoc2_put_linkColor,
1116 htmldoc2_get_linkColor,
1117 htmldoc2_put_vlinkColor,
1118 htmldoc2_get_vlinkColor,
1119 htmldoc2_get_referrer,
1120 htmldoc2_get_location,
1121 htmldoc2_get_lastModified,
1122 htmldoc2_put_URL,
1123 htmldoc2_get_URL,
1124 htmldoc2_put_domain,
1125 htmldoc2_get_domain,
1126 htmldoc2_put_cookie,
1127 htmldoc2_get_cookie,
1128 htmldoc2_put_expando,
1129 htmldoc2_get_expando,
1130 htmldoc2_put_charset,
1131 htmldoc2_get_charset,
1132 htmldoc2_put_defaultCharset,
1133 htmldoc2_get_defaultCharset,
1134 htmldoc2_get_mimeType,
1135 htmldoc2_get_fileSize,
1136 htmldoc2_get_fileCreatedDate,
1137 htmldoc2_get_fileModifiedDate,
1138 htmldoc2_get_fileUpdatedDate,
1139 htmldoc2_get_security,
1140 htmldoc2_get_protocol,
1141 htmldoc2_get_nameProp,
1142 htmldoc2_write,
1143 htmldoc2_writeln,
1144 htmldoc2_open,
1145 htmldoc2_close,
1146 htmldoc2_clear,
1147 htmldoc2_queryCommandSupported,
1148 htmldoc2_queryCommandEnabled,
1149 htmldoc2_queryCommandState,
1150 htmldoc2_queryCommandIndeterm,
1151 htmldoc2_queryCommandText,
1152 htmldoc2_queryCommandValue,
1153 htmldoc2_execCommand,
1154 htmldoc2_execCommandShowHelp,
1155 htmldoc2_createElement,
1156 htmldoc2_put_onhelp,
1157 htmldoc2_get_onhelp,
1158 htmldoc2_put_onclick,
1159 htmldoc2_get_onclick,
1160 htmldoc2_put_ondblclick,
1161 htmldoc2_get_ondblclick,
1162 htmldoc2_put_onkeyup,
1163 htmldoc2_get_onkeyup,
1164 htmldoc2_put_onkeydown,
1165 htmldoc2_get_onkeydown,
1166 htmldoc2_put_onkeypress,
1167 htmldoc2_get_onkeypress,
1168 htmldoc2_put_onmouseup,
1169 htmldoc2_get_onmouseup,
1170 htmldoc2_put_onmousedown,
1171 htmldoc2_get_onmousedown,
1172 htmldoc2_put_onmousemove,
1173 htmldoc2_get_onmousemove,
1174 htmldoc2_put_onmouseout,
1175 htmldoc2_get_onmouseout,
1176 htmldoc2_put_onmouseover,
1177 htmldoc2_get_onmouseover,
1178 htmldoc2_put_onreadystatechange,
1179 htmldoc2_get_onreadystatechange,
1180 htmldoc2_put_onafterupdate,
1181 htmldoc2_get_onafterupdate,
1182 htmldoc2_put_onrowexit,
1183 htmldoc2_get_onrowexit,
1184 htmldoc2_put_onrowenter,
1185 htmldoc2_get_onrowenter,
1186 htmldoc2_put_ondragstart,
1187 htmldoc2_get_ondragstart,
1188 htmldoc2_put_onselectstart,
1189 htmldoc2_get_onselectstart,
1190 htmldoc2_elementFromPoint,
1191 htmldoc2_get_parentWindow,
1192 htmldoc2_get_styleSheets,
1193 htmldoc2_put_onbeforeupdate,
1194 htmldoc2_get_onbeforeupdate,
1195 htmldoc2_put_onerrorupdate,
1196 htmldoc2_get_onerrorupdate,
1197 htmldoc2_toString,
1198 htmldoc2_createStyleSheet
1201 typedef struct
1203 IHTMLDocument2 IHTMLDocument2_iface;
1204 } testhtmldoc2_t;
1206 static testhtmldoc2_t htmldoc2 = { { &TestHTMLDocumentVtbl } };
1208 static HRESULT WINAPI sp_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppvObject)
1210 *ppvObject = NULL;
1212 if (IsEqualGUID(riid, &IID_IUnknown) ||
1213 IsEqualGUID(riid, &IID_IServiceProvider))
1215 *ppvObject = iface;
1216 IServiceProvider_AddRef(iface);
1217 return S_OK;
1220 ok(0, "unexpected query interface: %s\n", debugstr_guid(riid));
1222 return E_NOINTERFACE;
1225 static ULONG WINAPI sp_AddRef(IServiceProvider *iface)
1227 return 2;
1230 static ULONG WINAPI sp_Release(IServiceProvider *iface)
1232 return 1;
1235 static HRESULT WINAPI sp_QueryService(IServiceProvider *iface, REFGUID service, REFIID riid, void **obj)
1237 *obj = NULL;
1239 if (IsEqualGUID(service, &SID_SBindHost) &&
1240 IsEqualGUID(riid, &IID_IBindHost))
1242 CHECK_EXPECT2(sp_queryservice_SID_SBindHost);
1244 else if (IsEqualGUID(service, &SID_SContainerDispatch) &&
1245 IsEqualGUID(riid, &IID_IHTMLDocument2))
1247 CHECK_EXPECT2(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1249 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1250 IsEqualGUID(riid, &IID_IHTMLDocument2))
1252 CHECK_EXPECT2(sp_queryservice_SID_secmgr_htmldoc2);
1253 *obj = &htmldoc2.IHTMLDocument2_iface;
1254 return S_OK;
1256 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1257 IsEqualGUID(riid, &IID_IXMLDOMDocument))
1259 CHECK_EXPECT2(sp_queryservice_SID_secmgr_xmldomdoc);
1261 else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1262 IsEqualGUID(riid, &IID_IInternetHostSecurityManager))
1264 CHECK_EXPECT2(sp_queryservice_SID_secmgr_secmgr);
1266 else if (IsEqualGUID(service, &SID_UnknownSID) &&
1267 IsEqualGUID(riid, &IID_IStream))
1269 /* FIXME: unidentified service id */
1271 else
1272 ok(0, "unexpected request: sid %s, riid %s\n", debugstr_guid(service), debugstr_guid(riid));
1274 return E_NOTIMPL;
1277 static const IServiceProviderVtbl testprovVtbl =
1279 sp_QueryInterface,
1280 sp_AddRef,
1281 sp_Release,
1282 sp_QueryService
1285 testprov_t testprov = { { &testprovVtbl } };
1287 #define EXPECT_CHILDREN(node) _expect_children((IXMLDOMNode*)node, __LINE__)
1288 static void _expect_children(IXMLDOMNode *node, int line)
1290 VARIANT_BOOL b;
1291 HRESULT hr;
1293 b = VARIANT_FALSE;
1294 hr = IXMLDOMNode_hasChildNodes(node, &b);
1295 ok_(__FILE__,line)(hr == S_OK, "hasChildNodes() failed, 0x%08x\n", hr);
1296 ok_(__FILE__,line)(b == VARIANT_TRUE, "no children, %d\n", b);
1299 #define EXPECT_NO_CHILDREN(node) _expect_no_children((IXMLDOMNode*)node, __LINE__)
1300 static void _expect_no_children(IXMLDOMNode *node, int line)
1302 VARIANT_BOOL b;
1303 HRESULT hr;
1305 b = VARIANT_TRUE;
1306 hr = IXMLDOMNode_hasChildNodes(node, &b);
1307 ok_(__FILE__,line)(hr == S_FALSE, "hasChildNodes() failed, 0x%08x\n", hr);
1308 ok_(__FILE__,line)(b == VARIANT_FALSE, "no children, %d\n", b);
1311 #define EXPECT_REF(node,ref) _expect_ref((IUnknown*)node, ref, __LINE__)
1312 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
1314 ULONG rc = IUnknown_AddRef(obj);
1315 IUnknown_Release(obj);
1316 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
1319 #define EXPECT_LIST_LEN(list,len) _expect_list_len(list, len, __LINE__)
1320 static void _expect_list_len(IXMLDOMNodeList *list, LONG len, int line)
1322 LONG length;
1323 HRESULT hr;
1325 length = 0;
1326 hr = IXMLDOMNodeList_get_length(list, &length);
1327 ok_(__FILE__,line)(hr == S_OK, "got 0x%08x\n", hr);
1328 ok_(__FILE__,line)(length == len, "got %d, expected %d\n", length, len);
1331 #define EXPECT_HR(hr,hr_exp) \
1332 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
1334 static const WCHAR szEmpty[] = { 0 };
1335 static const WCHAR szIncomplete[] = {
1336 '<','?','x','m','l',' ',
1337 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
1339 static const WCHAR szComplete1[] = {
1340 '<','?','x','m','l',' ',
1341 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1342 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
1344 static const WCHAR szComplete2[] = {
1345 '<','?','x','m','l',' ',
1346 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1347 '<','o','>','<','/','o','>','\n',0
1349 static const WCHAR szComplete3[] = {
1350 '<','?','x','m','l',' ',
1351 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1352 '<','a','>','<','/','a','>','\n',0
1354 static const WCHAR szComplete4[] = {
1355 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
1356 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
1357 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
1358 'f','n','1','.','t','x','t','\n',
1359 '<','/','b','s','>','\n',
1360 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
1361 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
1362 'f','n','2','.','t','x','t','\n',
1363 '<','/','p','r','>','\n',
1364 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
1365 '<','f','o','>','\n',
1366 '<','b','a','>','\n',
1367 'f','1','\n',
1368 '<','/','b','a','>','\n',
1369 '<','/','f','o','>','\n',
1370 '<','/','l','c','>','\n',0
1372 static const WCHAR szComplete5[] = {
1373 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
1374 'x','m','l','n','s',':','C','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y','"',
1375 ' ','x','m','l','n','s',':','S','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y',':','s','e','a','r','c','h','"','>',
1376 '<','S',':','s','c','o','p','e','>',
1377 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
1378 '<','/','S',':','s','c','o','p','e','>',
1379 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
1380 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
1381 'c','o','m','p','u','t','e','r',
1382 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
1383 '<','/','S',':','s','e','a','r','c','h','>',0
1386 static const WCHAR szComplete6[] = {
1387 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'',' ',
1388 'e','n','c','o','d','i','n','g','=','\'','W','i','n','d','o','w','s','-','1','2','5','2','\'','?','>','\n',
1389 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
1392 static const CHAR szNonUnicodeXML[] =
1393 "<?xml version='1.0' encoding='Windows-1252'?>\n"
1394 "<open></open>\n";
1396 static const CHAR szExampleXML[] =
1397 "<?xml version='1.0' encoding='utf-8'?>\n"
1398 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1399 " <elem>\n"
1400 " <a>A1 field</a>\n"
1401 " <b>B1 field</b>\n"
1402 " <c>C1 field</c>\n"
1403 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1404 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
1405 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
1406 " </html>\n"
1407 " <html xml:space='preserve' xmlns='http://www.w3.org/1999/xhtml'>\n"
1408 " This is <strong>a</strong> <i>description</i> with preserved whitespace. <bar:x/>\n"
1409 " </html>\n"
1410 " </description>\n"
1411 " </elem>\n"
1412 "\n"
1413 " <elem>\n"
1414 " <a>A2 field</a>\n"
1415 " <b>B2 field</b>\n"
1416 " <c type=\"old\">C2 field</c>\n"
1417 " </elem>\n"
1418 "\n"
1419 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
1420 " <a>A3 field</a>\n"
1421 " <b>B3 field</b>\n"
1422 " <c>C3 field</c>\n"
1423 " </elem>\n"
1424 "\n"
1425 " <elem>\n"
1426 " <a>A4 field</a>\n"
1427 " <b>B4 field</b>\n"
1428 " <foo:c>C4 field</foo:c>\n"
1429 " </elem>\n"
1430 "</root>\n";
1432 static const CHAR szNodeTypesXML[] =
1433 "<?xml version='1.0'?>"
1434 "<!-- comment node 0 -->"
1435 "<root id='0' depth='0'>"
1436 " <!-- comment node 1 -->"
1437 " text node 0"
1438 " <x id='1' depth='1'>"
1439 " <?foo value='PI for x'?>"
1440 " <!-- comment node 2 -->"
1441 " text node 1"
1442 " <a id='3' depth='2'/>"
1443 " <b id='4' depth='2'/>"
1444 " <c id='5' depth='2'/>"
1445 " </x>"
1446 " <y id='2' depth='1'>"
1447 " <?bar value='PI for y'?>"
1448 " <!-- comment node 3 -->"
1449 " text node 2"
1450 " <a id='6' depth='2'/>"
1451 " <b id='7' depth='2'/>"
1452 " <c id='8' depth='2'/>"
1453 " </y>"
1454 "</root>";
1456 static const CHAR szTransformXML[] =
1457 "<?xml version=\"1.0\"?>\n"
1458 "<greeting>\n"
1459 "Hello World\n"
1460 "</greeting>";
1462 static const CHAR szTransformSSXML[] =
1463 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
1464 " <xsl:output method=\"html\"/>\n"
1465 " <xsl:template match=\"/\">\n"
1466 " <xsl:apply-templates select=\"greeting\"/>\n"
1467 " </xsl:template>\n"
1468 " <xsl:template match=\"greeting\">\n"
1469 " <html>\n"
1470 " <body>\n"
1471 " <h1>\n"
1472 " <xsl:value-of select=\".\"/>\n"
1473 " </h1>\n"
1474 " </body>\n"
1475 " </html>\n"
1476 " </xsl:template>\n"
1477 "</xsl:stylesheet>";
1479 static const CHAR szTransformOutput[] =
1480 "<html><body><h1>"
1481 "Hello World"
1482 "</h1></body></html>";
1484 static const CHAR szTypeValueXML[] =
1485 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1486 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
1487 " <string>Wine</string>\n"
1488 " <string2 dt:dt=\"string\">String</string2>\n"
1489 " <number dt:dt=\"number\">12.44</number>\n"
1490 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
1491 " <int dt:dt=\"int\">-13</int>\n"
1492 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
1493 " <bool dt:dt=\"boolean\">1</bool>\n"
1494 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
1495 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
1496 " <date dt:dt=\"date\">3721-11-01</date>\n"
1497 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
1498 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
1499 " <i1 dt:dt=\"i1\">-13</i1>\n"
1500 " <i2 dt:dt=\"i2\">31915</i2>\n"
1501 " <i4 dt:dt=\"i4\">-312232</i4>\n"
1502 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
1503 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
1504 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
1505 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
1506 " <r8 dt:dt=\"r8\">0.412</r8>\n"
1507 " <float dt:dt=\"float\">41221.421</float>\n"
1508 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
1509 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
1510 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
1511 " <binbase64_1 dt:dt=\"bin.base64\">\nYmFzZTY0\nIHRlc3Q=\n</binbase64_1>\n"
1512 " <binbase64_2 dt:dt=\"bin.base64\">\nYmF\r\t z ZTY0\nIHRlc3Q=\n</binbase64_2>\n"
1513 "</root>";
1515 static const CHAR szBasicTransformSSXMLPart1[] =
1516 "<?xml version=\"1.0\"?>"
1517 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
1518 "<xsl:output method=\"html\"/>\n"
1519 "<xsl:template match=\"/\">"
1520 "<HTML><BODY><TABLE>"
1521 " <xsl:apply-templates select='document(\"";
1523 static const CHAR szBasicTransformSSXMLPart2[] =
1524 "\")/bottle/wine'>"
1525 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
1526 " </xsl:apply-templates>"
1527 "</TABLE></BODY></HTML>"
1528 "</xsl:template>"
1529 "<xsl:template match=\"bottle\">"
1530 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
1531 "</xsl:template>"
1532 "<xsl:template match=\"name\">"
1533 " <TD><xsl:apply-templates /></TD>"
1534 "</xsl:template>"
1535 "<xsl:template match=\"cost\">"
1536 " <TD><xsl:apply-templates /></TD>"
1537 "</xsl:template>"
1538 "</xsl:stylesheet>";
1540 static const CHAR szBasicTransformXML[] =
1541 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
1543 static const CHAR szBasicTransformOutput[] =
1544 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
1546 #define SZ_EMAIL_DTD \
1547 "<!DOCTYPE email ["\
1548 " <!ELEMENT email (recipients,from,reply-to?,subject,body,attachment*)>"\
1549 " <!ATTLIST email attachments IDREFS #REQUIRED>"\
1550 " <!ATTLIST email sent (yes|no) \"no\">"\
1551 " <!ELEMENT recipients (to+,cc*)>"\
1552 " <!ELEMENT to (#PCDATA)>"\
1553 " <!ATTLIST to name CDATA #IMPLIED>"\
1554 " <!ELEMENT cc (#PCDATA)>"\
1555 " <!ATTLIST cc name CDATA #IMPLIED>"\
1556 " <!ELEMENT from (#PCDATA)>"\
1557 " <!ATTLIST from name CDATA #IMPLIED>"\
1558 " <!ELEMENT reply-to (#PCDATA)>"\
1559 " <!ATTLIST reply-to name CDATA #IMPLIED>"\
1560 " <!ELEMENT subject ANY>"\
1561 " <!ELEMENT body ANY>"\
1562 " <!ATTLIST body enc CDATA #FIXED \"UTF-8\">"\
1563 " <!ELEMENT attachment (#PCDATA)>"\
1564 " <!ATTLIST attachment id ID #REQUIRED>"\
1565 "]>"
1567 static const CHAR szEmailXML[] =
1568 "<?xml version=\"1.0\"?>"
1569 SZ_EMAIL_DTD
1570 "<email attachments=\"patch1\">"
1571 " <recipients>"
1572 " <to>wine-patches@winehq.org</to>"
1573 " </recipients>"
1574 " <from name=\"Anonymous\">user@localhost</from>"
1575 " <subject>msxml3/tests: DTD validation (try 87)</subject>"
1576 " <body>"
1577 " It no longer causes spontaneous combustion..."
1578 " </body>"
1579 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1580 "</email>";
1582 static const CHAR szEmailXML_0D[] =
1583 "<?xml version=\"1.0\"?>"
1584 SZ_EMAIL_DTD
1585 "<email attachments=\"patch1\">"
1586 " <recipients>"
1587 " <to>wine-patches@winehq.org</to>"
1588 " </recipients>"
1589 " <from name=\"Anonymous\">user@localhost</from>"
1590 " <subject>msxml3/tests: DTD validation (try 88)</subject>"
1591 " <body>"
1592 " <undecl />"
1593 " XML_ELEMENT_UNDECLARED 0xC00CE00D"
1594 " </body>"
1595 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1596 "</email>";
1598 static const CHAR szEmailXML_0E[] =
1599 "<?xml version=\"1.0\"?>"
1600 SZ_EMAIL_DTD
1601 "<email attachments=\"patch1\">"
1602 " <recipients>"
1603 " <to>wine-patches@winehq.org</to>"
1604 " </recipients>"
1605 " <from name=\"Anonymous\">user@localhost</from>"
1606 " <subject>msxml3/tests: DTD validation (try 89)</subject>"
1607 " <body>"
1608 " XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E"
1609 " </body>"
1610 " <attachment id=\"patch\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1611 "</email>";
1613 static const CHAR szEmailXML_11[] =
1614 "<?xml version=\"1.0\"?>"
1615 SZ_EMAIL_DTD
1616 "<email attachments=\"patch1\">"
1617 " <recipients>"
1618 " </recipients>"
1619 " <from name=\"Anonymous\">user@localhost</from>"
1620 " <subject>msxml3/tests: DTD validation (try 90)</subject>"
1621 " <body>"
1622 " XML_EMPTY_NOT_ALLOWED 0xC00CE011"
1623 " </body>"
1624 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1625 "</email>";
1627 static const CHAR szEmailXML_13[] =
1628 "<?xml version=\"1.0\"?>"
1629 SZ_EMAIL_DTD
1630 "<msg attachments=\"patch1\">"
1631 " <recipients>"
1632 " <to>wine-patches@winehq.org</to>"
1633 " </recipients>"
1634 " <from name=\"Anonymous\">user@localhost</from>"
1635 " <subject>msxml3/tests: DTD validation (try 91)</subject>"
1636 " <body>"
1637 " XML_ROOT_NAME_MISMATCH 0xC00CE013"
1638 " </body>"
1639 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1640 "</msg>";
1642 static const CHAR szEmailXML_14[] =
1643 "<?xml version=\"1.0\"?>"
1644 SZ_EMAIL_DTD
1645 "<email attachments=\"patch1\">"
1646 " <to>wine-patches@winehq.org</to>"
1647 " <from name=\"Anonymous\">user@localhost</from>"
1648 " <subject>msxml3/tests: DTD validation (try 92)</subject>"
1649 " <body>"
1650 " XML_INVALID_CONTENT 0xC00CE014"
1651 " </body>"
1652 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1653 "</email>";
1655 static const CHAR szEmailXML_15[] =
1656 "<?xml version=\"1.0\"?>"
1657 SZ_EMAIL_DTD
1658 "<email attachments=\"patch1\" ip=\"127.0.0.1\">"
1659 " <recipients>"
1660 " <to>wine-patches@winehq.org</to>"
1661 " </recipients>"
1662 " <from name=\"Anonymous\">user@localhost</from>"
1663 " <subject>msxml3/tests: DTD validation (try 93)</subject>"
1664 " <body>"
1665 " XML_ATTRIBUTE_NOT_DEFINED 0xC00CE015"
1666 " </body>"
1667 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1668 "</email>";
1670 static const CHAR szEmailXML_16[] =
1671 "<?xml version=\"1.0\"?>"
1672 SZ_EMAIL_DTD
1673 "<email attachments=\"patch1\">"
1674 " <recipients>"
1675 " <to>wine-patches@winehq.org</to>"
1676 " </recipients>"
1677 " <from name=\"Anonymous\">user@localhost</from>"
1678 " <subject>msxml3/tests: DTD validation (try 94)</subject>"
1679 " <body enc=\"ASCII\">"
1680 " XML_ATTRIBUTE_FIXED 0xC00CE016"
1681 " </body>"
1682 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1683 "</email>";
1685 static const CHAR szEmailXML_17[] =
1686 "<?xml version=\"1.0\"?>"
1687 SZ_EMAIL_DTD
1688 "<email attachments=\"patch1\" sent=\"true\">"
1689 " <recipients>"
1690 " <to>wine-patches@winehq.org</to>"
1691 " </recipients>"
1692 " <from name=\"Anonymous\">user@localhost</from>"
1693 " <subject>msxml3/tests: DTD validation (try 95)</subject>"
1694 " <body>"
1695 " XML_ATTRIBUTE_VALUE 0xC00CE017"
1696 " </body>"
1697 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1698 "</email>";
1700 static const CHAR szEmailXML_18[] =
1701 "<?xml version=\"1.0\"?>"
1702 SZ_EMAIL_DTD
1703 "<email attachments=\"patch1\">"
1704 " oops"
1705 " <recipients>"
1706 " <to>wine-patches@winehq.org</to>"
1707 " </recipients>"
1708 " <from name=\"Anonymous\">user@localhost</from>"
1709 " <subject>msxml3/tests: DTD validation (try 96)</subject>"
1710 " <body>"
1711 " XML_ILLEGAL_TEXT 0xC00CE018"
1712 " </body>"
1713 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1714 "</email>";
1716 static const CHAR szEmailXML_20[] =
1717 "<?xml version=\"1.0\"?>"
1718 SZ_EMAIL_DTD
1719 "<email>"
1720 " <recipients>"
1721 " <to>wine-patches@winehq.org</to>"
1722 " </recipients>"
1723 " <from name=\"Anonymous\">user@localhost</from>"
1724 " <subject>msxml3/tests: DTD validation (try 97)</subject>"
1725 " <body>"
1726 " XML_REQUIRED_ATTRIBUTE_MISSING 0xC00CE020"
1727 " </body>"
1728 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
1729 "</email>";
1731 static const char xpath_simple_list[] =
1732 "<?xml version=\"1.0\"?>"
1733 "<root>"
1734 " <a/>"
1735 " <b/>"
1736 " <c/>"
1737 " <d/>"
1738 "</root>";
1740 static const WCHAR szNonExistentFile[] = {
1741 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
1743 static const WCHAR szNonExistentAttribute[] = {
1744 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
1746 static const WCHAR szDocument[] = {
1747 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
1750 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
1751 static WCHAR szdl[] = { 'd','l',0 };
1752 static const WCHAR szvr[] = { 'v','r',0 };
1753 static const WCHAR szlc[] = { 'l','c',0 };
1754 static WCHAR szbs[] = { 'b','s',0 };
1755 static const WCHAR szstr1[] = { 's','t','r','1',0 };
1756 static const WCHAR szstr2[] = { 's','t','r','2',0 };
1757 static const WCHAR szstar[] = { '*',0 };
1758 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
1760 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
1761 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
1762 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
1764 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
1765 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
1766 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
1767 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
1768 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
1769 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
1770 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
1772 static WCHAR szAttribute[] = {'A','t','t','r',0 };
1773 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
1775 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
1776 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
1777 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
1778 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
1779 '!',']',']','>',0};
1780 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
1781 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
1783 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
1784 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
1785 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
1787 #define expect_bstr_eq_and_free(bstr, expect) { \
1788 BSTR bstrExp = alloc_str_from_narrow(expect); \
1789 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
1790 SysFreeString(bstr); \
1791 SysFreeString(bstrExp); \
1794 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
1796 #define ole_check(expr) { \
1797 HRESULT r = expr; \
1798 ok(r == S_OK, #expr " returned %x\n", r); \
1801 #define ole_expect(expr, expect) { \
1802 HRESULT r = expr; \
1803 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
1806 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
1808 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
1810 void *obj = NULL;
1811 HRESULT hr;
1813 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
1814 if (hr != S_OK)
1815 win_skip_(__FILE__,line)("failed to create %s instance: 0x%08x\n", name, hr);
1817 return obj;
1820 #define _create(cls) cls, #cls
1822 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument), iid, __LINE__)
1823 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
1824 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
1825 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
1826 #define create_xsltemplate(iid) _create_object(&_create(CLSID_XSLTemplate), iid, __LINE__)
1828 static BSTR alloc_str_from_narrow(const char *str)
1830 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
1831 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
1832 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
1833 return ret;
1836 static BSTR alloced_bstrs[256];
1837 static int alloced_bstrs_count;
1839 static BSTR _bstr_(const char *str)
1841 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
1842 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
1843 return alloced_bstrs[alloced_bstrs_count++];
1846 static void free_bstrs(void)
1848 int i;
1849 for (i = 0; i < alloced_bstrs_count; i++)
1850 SysFreeString(alloced_bstrs[i]);
1851 alloced_bstrs_count = 0;
1854 static VARIANT _variantbstr_(const char *str)
1856 VARIANT v;
1857 V_VT(&v) = VT_BSTR;
1858 V_BSTR(&v) = _bstr_(str);
1859 return v;
1862 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
1864 for (;;)
1866 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
1867 while (*sRight == '\r' || *sRight == '\n') sRight++;
1868 if (*sLeft != *sRight) return FALSE;
1869 if (!*sLeft) return TRUE;
1870 sLeft++;
1871 sRight++;
1875 static void get_str_for_type(DOMNodeType type, char *buf)
1877 switch (type)
1879 case NODE_ATTRIBUTE:
1880 strcpy(buf, "A");
1881 break;
1882 case NODE_ELEMENT:
1883 strcpy(buf, "E");
1884 break;
1885 case NODE_DOCUMENT:
1886 strcpy(buf, "D");
1887 break;
1888 case NODE_TEXT:
1889 strcpy(buf, "T");
1890 break;
1891 case NODE_COMMENT:
1892 strcpy(buf, "C");
1893 break;
1894 case NODE_PROCESSING_INSTRUCTION:
1895 strcpy(buf, "P");
1896 break;
1897 default:
1898 wsprintfA(buf, "[%d]", type);
1902 static int get_node_position(IXMLDOMNode *node)
1904 HRESULT r;
1905 int pos = 0;
1907 IXMLDOMNode_AddRef(node);
1910 IXMLDOMNode *new_node;
1912 pos++;
1913 r = IXMLDOMNode_get_previousSibling(node, &new_node);
1914 ok(SUCCEEDED(r), "get_previousSibling failed\n");
1915 IXMLDOMNode_Release(node);
1916 node = new_node;
1917 } while (r == S_OK);
1918 return pos;
1921 static void node_to_string(IXMLDOMNode *node, char *buf)
1923 HRESULT r = S_OK;
1924 DOMNodeType type;
1926 if (node == NULL)
1928 lstrcpyA(buf, "(null)");
1929 return;
1932 IXMLDOMNode_AddRef(node);
1933 while (r == S_OK)
1935 IXMLDOMNode *new_node;
1937 ole_check(IXMLDOMNode_get_nodeType(node, &type));
1938 get_str_for_type(type, buf);
1939 buf+=strlen(buf);
1941 if (type == NODE_ATTRIBUTE)
1943 BSTR bstr;
1944 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
1945 *(buf++) = '\'';
1946 wsprintfA(buf, "%ws", bstr);
1947 buf += strlen(buf);
1948 *(buf++) = '\'';
1949 SysFreeString(bstr);
1951 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
1953 else
1955 r = IXMLDOMNode_get_parentNode(node, &new_node);
1956 wsprintf(buf, "%d", get_node_position(node));
1957 buf += strlen(buf);
1960 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
1961 IXMLDOMNode_Release(node);
1962 node = new_node;
1963 if (r == S_OK)
1964 *(buf++) = '.';
1967 *buf = 0;
1970 static char *list_to_string(IXMLDOMNodeList *list)
1972 static char buf[4096];
1973 char *pos = buf;
1974 LONG len = 0;
1975 int i;
1977 if (list == NULL)
1979 lstrcpyA(buf, "(null)");
1980 return buf;
1982 ole_check(IXMLDOMNodeList_get_length(list, &len));
1983 for (i = 0; i < len; i++)
1985 IXMLDOMNode *node;
1986 if (i > 0)
1987 *(pos++) = ' ';
1988 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1989 node_to_string(node, pos);
1990 pos += strlen(pos);
1991 IXMLDOMNode_Release(node);
1993 *pos = 0;
1994 return buf;
1997 #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); }
1998 #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); }
2000 static void test_domdoc( void )
2002 HRESULT r;
2003 IXMLDOMDocument *doc;
2004 IXMLDOMParseError *error;
2005 IXMLDOMElement *element = NULL;
2006 IXMLDOMNode *node;
2007 IXMLDOMText *nodetext = NULL;
2008 IXMLDOMComment *node_comment = NULL;
2009 IXMLDOMAttribute *node_attr = NULL;
2010 IXMLDOMNode *nodeChild = NULL;
2011 IXMLDOMProcessingInstruction *nodePI = NULL;
2012 ISupportErrorInfo *support_error = NULL;
2013 VARIANT_BOOL b;
2014 VARIANT var;
2015 BSTR str;
2016 LONG code;
2017 LONG nLength = 0;
2018 WCHAR buff[100];
2020 doc = create_document(&IID_IXMLDOMDocument);
2021 if (!doc) return;
2023 if (0)
2025 /* crashes on native */
2026 IXMLDOMDocument_loadXML( doc, (BSTR)0x1, NULL );
2029 /* try some stupid things */
2030 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
2031 ok( r == S_FALSE, "loadXML succeeded\n");
2033 b = VARIANT_TRUE;
2034 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
2035 ok( r == S_FALSE, "loadXML succeeded\n");
2036 ok( b == VARIANT_FALSE, "failed to load XML string\n");
2038 /* try to load a document from a nonexistent file */
2039 b = VARIANT_TRUE;
2040 str = SysAllocString( szNonExistentFile );
2041 VariantInit(&var);
2042 V_VT(&var) = VT_BSTR;
2043 V_BSTR(&var) = str;
2045 r = IXMLDOMDocument_load( doc, var, &b);
2046 ok( r == S_FALSE, "loadXML succeeded\n");
2047 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2048 SysFreeString( str );
2050 /* try load an empty document */
2051 b = VARIANT_TRUE;
2052 str = SysAllocString( szEmpty );
2053 r = IXMLDOMDocument_loadXML( doc, str, &b );
2054 ok( r == S_FALSE, "loadXML succeeded\n");
2055 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2056 SysFreeString( str );
2058 r = IXMLDOMDocument_get_async( doc, &b );
2059 ok( r == S_OK, "get_async failed (%08x)\n", r);
2060 ok( b == VARIANT_TRUE, "Wrong default value\n");
2062 /* check that there's no document element */
2063 element = NULL;
2064 r = IXMLDOMDocument_get_documentElement( doc, &element );
2065 ok( r == S_FALSE, "should be no document element\n");
2067 /* try finding a node */
2068 node = NULL;
2069 str = SysAllocString( szstr1 );
2070 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
2071 ok( r == S_FALSE, "ret %08x\n", r );
2072 SysFreeString( str );
2074 b = VARIANT_TRUE;
2075 str = SysAllocString( szIncomplete );
2076 r = IXMLDOMDocument_loadXML( doc, str, &b );
2077 ok( r == S_FALSE, "loadXML succeeded\n");
2078 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2079 SysFreeString( str );
2081 /* check that there's no document element */
2082 element = (IXMLDOMElement*)1;
2083 r = IXMLDOMDocument_get_documentElement( doc, &element );
2084 ok( r == S_FALSE, "should be no document element\n");
2085 ok( element == NULL, "Element should be NULL\n");
2087 /* test for BSTR handling, pass broken BSTR */
2088 memcpy(&buff[2], szComplete1, sizeof(szComplete1));
2089 /* just a big length */
2090 *(DWORD*)buff = 0xf0f0;
2091 b = VARIANT_FALSE;
2092 r = IXMLDOMDocument_loadXML( doc, &buff[2], &b );
2093 ok( r == S_OK, "loadXML failed\n");
2094 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2096 /* loadXML ignores the encoding attribute and always expects Unicode */
2097 b = VARIANT_FALSE;
2098 str = SysAllocString( szComplete6 );
2099 r = IXMLDOMDocument_loadXML( doc, str, &b );
2100 ok( r == S_OK, "loadXML failed\n");
2101 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2102 SysFreeString( str );
2104 /* try a BSTR containing a Windows-1252 document */
2105 b = VARIANT_TRUE;
2106 str = SysAllocStringByteLen( szNonUnicodeXML, sizeof(szNonUnicodeXML) - 1 );
2107 r = IXMLDOMDocument_loadXML( doc, str, &b );
2108 ok( r == S_FALSE, "loadXML succeeded\n");
2109 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
2110 SysFreeString( str );
2112 /* try to load something valid */
2113 b = VARIANT_FALSE;
2114 str = SysAllocString( szComplete1 );
2115 r = IXMLDOMDocument_loadXML( doc, str, &b );
2116 ok( r == S_OK, "loadXML failed\n");
2117 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2118 SysFreeString( str );
2120 /* check if nodename is correct */
2121 r = IXMLDOMDocument_get_nodeName( doc, NULL );
2122 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2124 str = (BSTR)0xdeadbeef;
2125 r = IXMLDOMDocument_get_baseName( doc, &str );
2126 ok ( r == S_FALSE, "got 0x%08x\n", r);
2127 ok (str == NULL, "got %p\n", str);
2129 /* content doesn't matter here */
2130 str = NULL;
2131 r = IXMLDOMDocument_get_nodeName( doc, &str );
2132 ok ( r == S_OK, "get_nodeName wrong code\n");
2133 ok ( str != NULL, "str is null\n");
2134 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
2135 SysFreeString( str );
2137 /* test put_text */
2138 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
2139 ok( r == E_FAIL, "ret %08x\n", r );
2141 /* check that there's a document element */
2142 element = NULL;
2143 r = IXMLDOMDocument_get_documentElement( doc, &element );
2144 ok( r == S_OK, "should be a document element\n");
2145 if( element )
2147 IObjectIdentity *ident;
2149 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (void**)&ident );
2150 ok( r == E_NOINTERFACE, "ret %08x\n", r);
2152 IXMLDOMElement_Release( element );
2153 element = NULL;
2156 /* as soon as we call loadXML again, the document element will disappear */
2157 b = 2;
2158 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
2159 ok( r == S_FALSE, "loadXML failed\n");
2160 ok( b == 2, "variant modified\n");
2161 r = IXMLDOMDocument_get_documentElement( doc, &element );
2162 ok( r == S_FALSE, "should be no document element\n");
2164 /* try to load something else simple and valid */
2165 b = VARIANT_FALSE;
2166 str = SysAllocString( szComplete3 );
2167 r = IXMLDOMDocument_loadXML( doc, str, &b );
2168 ok( r == S_OK, "loadXML failed\n");
2169 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2170 SysFreeString( str );
2172 /* try something a little more complicated */
2173 b = FALSE;
2174 str = SysAllocString( szComplete4 );
2175 r = IXMLDOMDocument_loadXML( doc, str, &b );
2176 ok( r == S_OK, "loadXML failed\n");
2177 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2178 SysFreeString( str );
2180 r = IXMLDOMDocument_get_parseError( doc, &error );
2181 ok( r == S_OK, "returns %08x\n", r );
2183 r = IXMLDOMParseError_get_errorCode( error, &code );
2184 ok( r == S_FALSE, "returns %08x\n", r );
2185 ok( code == 0, "code %d\n", code );
2186 IXMLDOMParseError_Release( error );
2188 /* test createTextNode */
2189 r = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &nodetext);
2190 ok( r == S_OK, "returns %08x\n", r );
2191 IXMLDOMText_Release(nodetext);
2193 str = SysAllocString( szOpen );
2194 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
2195 ok( r == E_INVALIDARG, "returns %08x\n", r );
2196 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
2197 ok( r == S_OK, "returns %08x\n", r );
2198 SysFreeString( str );
2199 if(nodetext)
2201 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element);
2202 ok(r == E_NOINTERFACE, "ret %08x\n", r );
2204 /* Text Last Child Checks */
2205 r = IXMLDOMText_get_lastChild(nodetext, NULL);
2206 ok(r == E_INVALIDARG, "ret %08x\n", r );
2208 nodeChild = (IXMLDOMNode*)0x1;
2209 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
2210 ok(r == S_FALSE, "ret %08x\n", r );
2211 ok(nodeChild == NULL, "nodeChild not NULL\n");
2213 /* test length property */
2214 r = IXMLDOMText_get_length(nodetext, NULL);
2215 ok(r == E_INVALIDARG, "ret %08x\n", r );
2217 r = IXMLDOMText_get_length(nodetext, &nLength);
2218 ok(r == S_OK, "ret %08x\n", r );
2219 ok(nLength == 4, "expected 4 got %d\n", nLength);
2221 /* put data Tests */
2222 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
2223 ok(r == S_OK, "ret %08x\n", r );
2225 /* get data Tests */
2226 r = IXMLDOMText_get_data(nodetext, &str);
2227 ok(r == S_OK, "ret %08x\n", r );
2228 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
2229 SysFreeString(str);
2231 /* Confirm XML text is good */
2232 r = IXMLDOMText_get_xml(nodetext, &str);
2233 ok(r == S_OK, "ret %08x\n", r );
2234 ok( !lstrcmpW( str, _bstr_("This &amp;is a ; test &lt;&gt;\\") ), "incorrect xml string\n");
2235 SysFreeString(str);
2237 /* Confirm we get the put_data Text back */
2238 r = IXMLDOMText_get_text(nodetext, &str);
2239 ok(r == S_OK, "ret %08x\n", r );
2240 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2241 SysFreeString(str);
2243 /* test substringData */
2244 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
2245 ok(r == E_INVALIDARG, "ret %08x\n", r );
2247 /* test substringData - Invalid offset */
2248 str = (BSTR)&szElement;
2249 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
2250 ok(r == E_INVALIDARG, "ret %08x\n", r );
2251 ok( str == NULL, "incorrect string\n");
2253 /* test substringData - Invalid offset */
2254 str = (BSTR)&szElement;
2255 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
2256 ok(r == S_FALSE, "ret %08x\n", r );
2257 ok( str == NULL, "incorrect string\n");
2259 /* test substringData - Invalid size */
2260 str = (BSTR)&szElement;
2261 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
2262 ok(r == E_INVALIDARG, "ret %08x\n", r );
2263 ok( str == NULL, "incorrect string\n");
2265 /* test substringData - Invalid size */
2266 str = (BSTR)&szElement;
2267 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
2268 ok(r == S_FALSE, "ret %08x\n", r );
2269 ok( str == NULL, "incorrect string\n");
2271 /* test substringData - Start of string */
2272 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
2273 ok(r == S_OK, "ret %08x\n", r );
2274 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2275 SysFreeString(str);
2277 /* test substringData - Middle of string */
2278 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
2279 ok(r == S_OK, "ret %08x\n", r );
2280 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2281 SysFreeString(str);
2283 /* test substringData - End of string */
2284 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
2285 ok(r == S_OK, "ret %08x\n", r );
2286 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2287 SysFreeString(str);
2289 /* test appendData */
2290 r = IXMLDOMText_appendData(nodetext, NULL);
2291 ok(r == S_OK, "ret %08x\n", r );
2293 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
2294 ok(r == S_OK, "ret %08x\n", r );
2296 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
2297 ok(r == S_OK, "ret %08x\n", r );
2299 r = IXMLDOMText_get_text(nodetext, &str);
2300 ok(r == S_OK, "ret %08x\n", r );
2301 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2302 SysFreeString(str);
2304 /* test insertData */
2305 str = SysAllocStringLen(NULL, 0);
2306 r = IXMLDOMText_insertData(nodetext, -1, str);
2307 ok(r == S_OK, "ret %08x\n", r );
2309 r = IXMLDOMText_insertData(nodetext, -1, NULL);
2310 ok(r == S_OK, "ret %08x\n", r );
2312 r = IXMLDOMText_insertData(nodetext, 1000, str);
2313 ok(r == S_OK, "ret %08x\n", r );
2315 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
2316 ok(r == S_OK, "ret %08x\n", r );
2318 r = IXMLDOMText_insertData(nodetext, 0, NULL);
2319 ok(r == S_OK, "ret %08x\n", r );
2321 r = IXMLDOMText_insertData(nodetext, 0, str);
2322 ok(r == S_OK, "ret %08x\n", r );
2323 SysFreeString(str);
2325 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
2326 ok(r == E_INVALIDARG, "ret %08x\n", r );
2328 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
2329 ok(r == E_INVALIDARG, "ret %08x\n", r );
2331 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
2332 ok(r == S_OK, "ret %08x\n", r );
2334 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
2335 ok(r == S_OK, "ret %08x\n", r );
2337 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
2338 ok(r == S_OK, "ret %08x\n", r );
2340 r = IXMLDOMText_get_text(nodetext, &str);
2341 ok(r == S_OK, "ret %08x\n", r );
2342 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2343 SysFreeString(str);
2345 /* delete data */
2346 /* invalid arguments */
2347 r = IXMLDOMText_deleteData(nodetext, -1, 1);
2348 ok(r == E_INVALIDARG, "ret %08x\n", r );
2350 r = IXMLDOMText_deleteData(nodetext, 0, 0);
2351 ok(r == S_OK, "ret %08x\n", r );
2353 r = IXMLDOMText_deleteData(nodetext, 0, -1);
2354 ok(r == E_INVALIDARG, "ret %08x\n", r );
2356 r = IXMLDOMText_get_length(nodetext, &nLength);
2357 ok(r == S_OK, "ret %08x\n", r );
2358 ok(nLength == 43, "expected 43 got %d\n", nLength);
2360 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
2361 ok(r == S_OK, "ret %08x\n", r );
2363 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
2364 ok(r == E_INVALIDARG, "ret %08x\n", r );
2366 /* delete from start */
2367 r = IXMLDOMText_deleteData(nodetext, 0, 5);
2368 ok(r == S_OK, "ret %08x\n", r );
2370 r = IXMLDOMText_get_length(nodetext, &nLength);
2371 ok(r == S_OK, "ret %08x\n", r );
2372 ok(nLength == 38, "expected 38 got %d\n", nLength);
2374 r = IXMLDOMText_get_text(nodetext, &str);
2375 ok(r == S_OK, "ret %08x\n", r );
2376 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2377 SysFreeString(str);
2379 /* delete from end */
2380 r = IXMLDOMText_deleteData(nodetext, 35, 3);
2381 ok(r == S_OK, "ret %08x\n", r );
2383 r = IXMLDOMText_get_length(nodetext, &nLength);
2384 ok(r == S_OK, "ret %08x\n", r );
2385 ok(nLength == 35, "expected 35 got %d\n", nLength);
2387 r = IXMLDOMText_get_text(nodetext, &str);
2388 ok(r == S_OK, "ret %08x\n", r );
2389 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2390 SysFreeString(str);
2392 /* delete from inside */
2393 r = IXMLDOMText_deleteData(nodetext, 1, 33);
2394 ok(r == S_OK, "ret %08x\n", r );
2396 r = IXMLDOMText_get_length(nodetext, &nLength);
2397 ok(r == S_OK, "ret %08x\n", r );
2398 ok(nLength == 2, "expected 2 got %d\n", nLength);
2400 r = IXMLDOMText_get_text(nodetext, &str);
2401 ok(r == S_OK, "ret %08x\n", r );
2402 ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2403 SysFreeString(str);
2405 /* delete whole data ... */
2406 r = IXMLDOMText_get_length(nodetext, &nLength);
2407 ok(r == S_OK, "ret %08x\n", r );
2409 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
2410 ok(r == S_OK, "ret %08x\n", r );
2411 /* ... and try again with empty string */
2412 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
2413 ok(r == S_OK, "ret %08x\n", r );
2415 /* test put_data */
2416 V_VT(&var) = VT_BSTR;
2417 V_BSTR(&var) = SysAllocString(szstr1);
2418 r = IXMLDOMText_put_nodeValue(nodetext, var);
2419 ok(r == S_OK, "ret %08x\n", r );
2420 VariantClear(&var);
2422 r = IXMLDOMText_get_text(nodetext, &str);
2423 ok(r == S_OK, "ret %08x\n", r );
2424 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2425 SysFreeString(str);
2427 /* test put_data */
2428 V_VT(&var) = VT_I4;
2429 V_I4(&var) = 99;
2430 r = IXMLDOMText_put_nodeValue(nodetext, var);
2431 ok(r == S_OK, "ret %08x\n", r );
2432 VariantClear(&var);
2434 r = IXMLDOMText_get_text(nodetext, &str);
2435 ok(r == S_OK, "ret %08x\n", r );
2436 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2437 SysFreeString(str);
2439 /* ::replaceData() */
2440 V_VT(&var) = VT_BSTR;
2441 V_BSTR(&var) = SysAllocString(szstr1);
2442 r = IXMLDOMText_put_nodeValue(nodetext, var);
2443 ok(r == S_OK, "ret %08x\n", r );
2444 VariantClear(&var);
2446 r = IXMLDOMText_replaceData(nodetext, 6, 0, NULL);
2447 ok(r == E_INVALIDARG, "ret %08x\n", r );
2448 r = IXMLDOMText_get_text(nodetext, &str);
2449 ok(r == S_OK, "ret %08x\n", r );
2450 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2451 SysFreeString(str);
2453 r = IXMLDOMText_replaceData(nodetext, 0, 0, NULL);
2454 ok(r == S_OK, "ret %08x\n", r );
2455 r = IXMLDOMText_get_text(nodetext, &str);
2456 ok(r == S_OK, "ret %08x\n", r );
2457 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2458 SysFreeString(str);
2460 /* NULL pointer means delete */
2461 r = IXMLDOMText_replaceData(nodetext, 0, 1, NULL);
2462 ok(r == S_OK, "ret %08x\n", r );
2463 r = IXMLDOMText_get_text(nodetext, &str);
2464 ok(r == S_OK, "ret %08x\n", r );
2465 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2466 SysFreeString(str);
2468 /* empty string means delete */
2469 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_(""));
2470 ok(r == S_OK, "ret %08x\n", r );
2471 r = IXMLDOMText_get_text(nodetext, &str);
2472 ok(r == S_OK, "ret %08x\n", r );
2473 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2474 SysFreeString(str);
2476 /* zero count means insert */
2477 r = IXMLDOMText_replaceData(nodetext, 0, 0, _bstr_("a"));
2478 ok(r == S_OK, "ret %08x\n", r );
2479 r = IXMLDOMText_get_text(nodetext, &str);
2480 ok(r == S_OK, "ret %08x\n", r );
2481 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2482 SysFreeString(str);
2484 r = IXMLDOMText_replaceData(nodetext, 0, 2, NULL);
2485 ok(r == S_OK, "ret %08x\n", r );
2487 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("m"));
2488 ok(r == S_OK, "ret %08x\n", r );
2489 r = IXMLDOMText_get_text(nodetext, &str);
2490 ok(r == S_OK, "ret %08x\n", r );
2491 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2492 SysFreeString(str);
2494 /* nonempty string, count greater than its length */
2495 r = IXMLDOMText_replaceData(nodetext, 0, 2, _bstr_("a1.2"));
2496 ok(r == S_OK, "ret %08x\n", r );
2497 r = IXMLDOMText_get_text(nodetext, &str);
2498 ok(r == S_OK, "ret %08x\n", r );
2499 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2500 SysFreeString(str);
2502 /* nonempty string, count less than its length */
2503 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_("wine"));
2504 ok(r == S_OK, "ret %08x\n", r );
2505 r = IXMLDOMText_get_text(nodetext, &str);
2506 ok(r == S_OK, "ret %08x\n", r );
2507 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
2508 SysFreeString(str);
2510 IXMLDOMText_Release( nodetext );
2513 /* test Create Comment */
2514 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
2515 ok( r == E_INVALIDARG, "returns %08x\n", r );
2516 node_comment = (IXMLDOMComment*)0x1;
2518 /* empty comment */
2519 r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
2520 ok( r == S_OK, "returns %08x\n", r );
2521 str = (BSTR)0x1;
2522 r = IXMLDOMComment_get_data(node_comment, &str);
2523 ok( r == S_OK, "returns %08x\n", r );
2524 ok( str && SysStringLen(str) == 0, "expected empty string data\n");
2525 IXMLDOMComment_Release(node_comment);
2526 SysFreeString(str);
2528 r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
2529 ok( r == S_OK, "returns %08x\n", r );
2530 str = (BSTR)0x1;
2531 r = IXMLDOMComment_get_data(node_comment, &str);
2532 ok( r == S_OK, "returns %08x\n", r );
2533 ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
2534 IXMLDOMComment_Release(node_comment);
2535 SysFreeString(str);
2537 str = SysAllocString(szComment);
2538 r = IXMLDOMDocument_createComment(doc, str, &node_comment);
2539 SysFreeString(str);
2540 ok( r == S_OK, "returns %08x\n", r );
2541 if(node_comment)
2543 /* Last Child Checks */
2544 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
2545 ok(r == E_INVALIDARG, "ret %08x\n", r );
2547 nodeChild = (IXMLDOMNode*)0x1;
2548 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
2549 ok(r == S_FALSE, "ret %08x\n", r );
2550 ok(nodeChild == NULL, "pLastChild not NULL\n");
2552 /* baseName */
2553 str = (BSTR)0xdeadbeef;
2554 IXMLDOMComment_get_baseName(node_comment, &str);
2555 ok(r == S_FALSE, "ret %08x\n", r );
2556 ok(str == NULL, "Expected NULL\n");
2558 IXMLDOMComment_Release( node_comment );
2561 /* test Create Attribute */
2562 str = SysAllocString(szAttribute);
2563 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
2564 ok( r == E_INVALIDARG, "returns %08x\n", r );
2565 r = IXMLDOMDocument_createAttribute(doc, str, &node_attr);
2566 ok( r == S_OK, "returns %08x\n", r );
2567 IXMLDOMText_Release( node_attr);
2568 SysFreeString(str);
2570 /* test Processing Instruction */
2571 str = SysAllocStringLen(NULL, 0);
2572 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
2573 ok( r == E_INVALIDARG, "returns %08x\n", r );
2574 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
2575 ok( r == E_FAIL, "returns %08x\n", r );
2576 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
2577 ok( r == E_FAIL, "returns %08x\n", r );
2578 SysFreeString(str);
2580 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
2581 ok( r == S_OK, "returns %08x\n", r );
2582 if(nodePI)
2584 /* Last Child Checks */
2585 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
2586 ok(r == E_INVALIDARG, "ret %08x\n", r );
2588 nodeChild = (IXMLDOMNode*)0x1;
2589 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
2590 ok(r == S_FALSE, "ret %08x\n", r );
2591 ok(nodeChild == NULL, "nodeChild not NULL\n");
2593 /* test nodeName */
2594 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
2595 ok(r == S_OK, "ret %08x\n", r );
2596 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2597 SysFreeString(str);
2599 /* test baseName */
2600 str = (BSTR)0x1;
2601 r = IXMLDOMProcessingInstruction_get_baseName(nodePI, &str);
2602 ok(r == S_OK, "ret %08x\n", r );
2603 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2604 SysFreeString(str);
2606 /* test Target */
2607 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
2608 ok(r == S_OK, "ret %08x\n", r );
2609 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
2610 SysFreeString(str);
2612 /* test get_nodeValue */
2613 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
2614 ok(r == S_OK, "ret %08x\n", r );
2615 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
2616 VariantClear(&var);
2618 /* test get_data */
2619 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
2620 ok(r == S_OK, "ret %08x\n", r );
2621 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
2622 SysFreeString(str);
2624 /* test put_data */
2625 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
2626 ok(r == E_FAIL, "ret %08x\n", r );
2628 /* test put_data */
2629 V_VT(&var) = VT_BSTR;
2630 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
2631 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
2632 ok(r == E_FAIL, "ret %08x\n", r );
2633 VariantClear(&var);
2635 /* test get nodeName */
2636 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
2637 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
2638 ok(r == S_OK, "ret %08x\n", r );
2639 SysFreeString(str);
2641 IXMLDOMProcessingInstruction_Release(nodePI);
2644 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (void**)&support_error );
2645 ok( r == S_OK, "ret %08x\n", r );
2646 if(r == S_OK)
2648 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
2649 todo_wine ok( r == S_OK, "ret %08x\n", r );
2650 ISupportErrorInfo_Release( support_error );
2653 r = IXMLDOMDocument_Release( doc );
2654 ok( r == 0, "document ref count incorrect\n");
2656 free_bstrs();
2659 static void test_persiststreaminit(void)
2661 IXMLDOMDocument *doc;
2662 IPersistStreamInit *streaminit;
2663 HRESULT hr;
2665 doc = create_document(&IID_IXMLDOMDocument);
2666 if (!doc) return;
2668 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&streaminit);
2669 ok( hr == S_OK, "failed with 0x%08x\n", hr );
2671 hr = IPersistStreamInit_InitNew(streaminit);
2672 ok( hr == S_OK, "failed with 0x%08x\n", hr );
2674 IXMLDOMDocument_Release(doc);
2677 static void test_domnode( void )
2679 HRESULT r;
2680 IXMLDOMDocument *doc, *owner = NULL;
2681 IXMLDOMElement *element = NULL;
2682 IXMLDOMNamedNodeMap *map = NULL;
2683 IXMLDOMNode *node = NULL, *next = NULL;
2684 IXMLDOMNodeList *list = NULL;
2685 IXMLDOMAttribute *attr = NULL;
2686 DOMNodeType type = NODE_INVALID;
2687 VARIANT_BOOL b;
2688 BSTR str;
2689 VARIANT var;
2690 LONG count;
2692 doc = create_document(&IID_IXMLDOMDocument);
2693 if (!doc) return;
2695 b = FALSE;
2696 str = SysAllocString( szComplete4 );
2697 r = IXMLDOMDocument_loadXML( doc, str, &b );
2698 ok( r == S_OK, "loadXML failed\n");
2699 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2700 SysFreeString( str );
2702 EXPECT_CHILDREN(doc);
2704 r = IXMLDOMDocument_get_documentElement( doc, &element );
2705 ok( r == S_OK, "should be a document element\n");
2706 ok( element != NULL, "should be an element\n");
2708 VariantInit(&var);
2709 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
2711 r = IXMLDOMNode_get_nodeValue( doc, NULL );
2712 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
2714 r = IXMLDOMNode_get_nodeValue( doc, &var );
2715 ok( r == S_FALSE, "nextNode returned wrong code\n");
2716 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
2717 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
2719 if (element)
2721 owner = NULL;
2722 r = IXMLDOMNode_get_ownerDocument( element, &owner );
2723 ok( r == S_OK, "get_ownerDocument return code\n");
2724 ok( owner != doc, "get_ownerDocument return\n");
2725 IXMLDOMDocument_Release(owner);
2727 type = NODE_INVALID;
2728 r = IXMLDOMNode_get_nodeType( element, &type);
2729 ok( r == S_OK, "got %08x\n", r);
2730 ok( type == NODE_ELEMENT, "node not an element\n");
2732 str = NULL;
2733 r = IXMLDOMNode_get_baseName( element, &str );
2734 ok( r == S_OK, "get_baseName returned wrong code\n");
2735 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
2736 SysFreeString(str);
2738 /* check if nodename is correct */
2739 r = IXMLDOMElement_get_nodeName( element, NULL );
2740 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2742 /* content doesn't matter here */
2743 str = NULL;
2744 r = IXMLDOMElement_get_nodeName( element, &str );
2745 ok ( r == S_OK, "get_nodeName wrong code\n");
2746 ok ( str != NULL, "str is null\n");
2747 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
2748 SysFreeString( str );
2750 str = SysAllocString( szNonExistentFile );
2751 V_VT(&var) = VT_I4;
2752 V_I4(&var) = 0x1234;
2753 r = IXMLDOMElement_getAttribute( element, str, &var );
2754 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
2755 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
2756 VariantClear(&var);
2758 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
2759 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
2761 attr = (IXMLDOMAttribute*)0xdeadbeef;
2762 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
2763 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
2764 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
2765 SysFreeString( str );
2767 attr = (IXMLDOMAttribute*)0xdeadbeef;
2768 str = SysAllocString( szNonExistentAttribute );
2769 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
2770 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
2771 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
2772 SysFreeString( str );
2774 str = SysAllocString( szdl );
2775 V_VT(&var) = VT_I4;
2776 V_I4(&var) = 0x1234;
2777 r = IXMLDOMElement_getAttribute( element, str, &var );
2778 ok( r == S_OK, "getAttribute ret %08x\n", r );
2779 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
2780 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
2781 VariantClear( &var );
2783 r = IXMLDOMElement_getAttribute( element, NULL, &var );
2784 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
2786 r = IXMLDOMElement_getAttribute( element, str, NULL );
2787 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
2789 attr = NULL;
2790 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
2791 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
2792 ok( attr != NULL, "getAttributeNode returned NULL\n" );
2793 if (attr)
2795 r = IXMLDOMAttribute_get_parentNode( attr, NULL );
2796 ok( r == E_INVALIDARG, "Expected E_INVALIDARG, ret %08x\n", r );
2798 /* attribute doesn't have a parent in msxml interpretation */
2799 node = (IXMLDOMNode*)0xdeadbeef;
2800 r = IXMLDOMAttribute_get_parentNode( attr, &node );
2801 ok( r == S_FALSE, "Expected S_FALSE, ret %08x\n", r );
2802 ok( node == NULL, "Expected NULL, got %p\n", node );
2804 IXMLDOMAttribute_Release(attr);
2807 SysFreeString( str );
2809 r = IXMLDOMElement_get_attributes( element, &map );
2810 ok( r == S_OK, "get_attributes returned wrong code\n");
2811 ok( map != NULL, "should be attributes\n");
2813 EXPECT_CHILDREN(element);
2815 else
2816 ok( FALSE, "no element\n");
2818 if (map)
2820 ISupportErrorInfo *support_error;
2821 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (void**)&support_error );
2822 ok( r == S_OK, "ret %08x\n", r );
2824 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
2825 todo_wine
2827 ok( r == S_OK, "ret %08x\n", r );
2829 ISupportErrorInfo_Release( support_error );
2831 str = SysAllocString( szdl );
2832 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
2833 ok( r == S_OK, "getNamedItem returned wrong code\n");
2834 ok( node != NULL, "should be attributes\n");
2835 IXMLDOMNode_Release(node);
2836 SysFreeString( str );
2838 str = SysAllocString( szdl );
2839 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
2840 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
2841 SysFreeString( str );
2843 /* something that isn't in szComplete4 */
2844 str = SysAllocString( szOpen );
2845 node = (IXMLDOMNode *) 1;
2846 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
2847 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
2848 ok( node == NULL, "getNamedItem should have returned NULL\n");
2849 SysFreeString( str );
2851 /* test indexed access of attributes */
2852 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
2853 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
2855 r = IXMLDOMNamedNodeMap_get_length( map, &count );
2856 ok ( r == S_OK, "get_length wrong code\n");
2857 ok ( count == 1, "get_length != 1\n");
2859 node = NULL;
2860 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
2861 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
2862 ok ( node == NULL, "there is no node\n");
2864 node = NULL;
2865 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
2866 ok ( r == S_FALSE, "get_item (1) wrong code\n");
2867 ok ( node == NULL, "there is no attribute\n");
2869 node = NULL;
2870 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
2871 ok ( r == S_OK, "get_item (0) wrong code\n");
2872 ok ( node != NULL, "should be attribute\n");
2874 r = IXMLDOMNode_get_nodeName( node, NULL );
2875 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2877 /* content doesn't matter here */
2878 str = NULL;
2879 r = IXMLDOMNode_get_nodeName( node, &str );
2880 ok ( r == S_OK, "get_nodeName wrong code\n");
2881 ok ( str != NULL, "str is null\n");
2882 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
2883 SysFreeString( str );
2884 IXMLDOMNode_Release( node );
2886 /* test sequential access of attributes */
2887 node = NULL;
2888 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2889 ok ( r == S_OK, "nextNode (first time) wrong code\n");
2890 ok ( node != NULL, "nextNode, should be attribute\n");
2891 IXMLDOMNode_Release( node );
2893 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2894 ok ( r != S_OK, "nextNode (second time) wrong code\n");
2895 ok ( node == NULL, "nextNode, there is no attribute\n");
2897 r = IXMLDOMNamedNodeMap_reset( map );
2898 ok ( r == S_OK, "reset should return S_OK\n");
2900 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2901 ok ( r == S_OK, "nextNode (third time) wrong code\n");
2902 ok ( node != NULL, "nextNode, should be attribute\n");
2904 else
2905 ok( FALSE, "no map\n");
2907 if (node)
2909 type = NODE_INVALID;
2910 r = IXMLDOMNode_get_nodeType( node, &type);
2911 ok( r == S_OK, "getNamedItem returned wrong code\n");
2912 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
2914 str = NULL;
2915 r = IXMLDOMNode_get_baseName( node, NULL );
2916 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
2918 str = NULL;
2919 r = IXMLDOMNode_get_baseName( node, &str );
2920 ok( r == S_OK, "get_baseName returned wrong code\n");
2921 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
2922 SysFreeString( str );
2924 r = IXMLDOMNode_get_nodeValue( node, &var );
2925 ok( r == S_OK, "returns %08x\n", r );
2926 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
2927 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
2928 VariantClear(&var);
2930 r = IXMLDOMNode_get_childNodes( node, NULL );
2931 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
2933 r = IXMLDOMNode_get_childNodes( node, &list );
2934 ok( r == S_OK, "get_childNodes returned wrong code\n");
2936 if (list)
2938 r = IXMLDOMNodeList_nextNode( list, &next );
2939 ok( r == S_OK, "nextNode returned wrong code\n");
2941 else
2942 ok( FALSE, "no childlist\n");
2944 if (next)
2946 EXPECT_NO_CHILDREN(next);
2948 type = NODE_INVALID;
2949 r = IXMLDOMNode_get_nodeType( next, &type);
2950 ok( r == S_OK, "getNamedItem returned wrong code\n");
2951 ok( type == NODE_TEXT, "node not text\n");
2953 str = (BSTR) 1;
2954 r = IXMLDOMNode_get_baseName( next, &str );
2955 ok( r == S_FALSE, "get_baseName returned wrong code\n");
2956 ok( str == NULL, "basename was wrong\n");
2957 SysFreeString(str);
2959 else
2960 ok( FALSE, "no next\n");
2962 if (next)
2963 IXMLDOMNode_Release( next );
2964 next = NULL;
2965 if (list)
2966 IXMLDOMNodeList_Release( list );
2967 list = NULL;
2968 if (node)
2969 IXMLDOMNode_Release( node );
2971 else
2972 ok( FALSE, "no node\n");
2973 node = NULL;
2975 if (map)
2976 IXMLDOMNamedNodeMap_Release( map );
2978 /* now traverse the tree from the root element */
2979 if (element)
2981 r = IXMLDOMNode_get_childNodes( element, &list );
2982 ok( r == S_OK, "get_childNodes returned wrong code\n");
2984 /* using get_item for child list doesn't advance the position */
2985 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2986 expect_node(node, "E2.E2.D1");
2987 IXMLDOMNode_Release(node);
2988 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2989 expect_node(node, "E1.E2.D1");
2990 IXMLDOMNode_Release(node);
2991 ole_check(IXMLDOMNodeList_reset(list));
2993 IXMLDOMNodeList_AddRef(list);
2994 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
2995 ole_check(IXMLDOMNodeList_reset(list));
2997 node = (void*)0xdeadbeef;
2998 str = SysAllocString(szdl);
2999 r = IXMLDOMNode_selectSingleNode( element, str, &node );
3000 SysFreeString(str);
3001 ok( r == S_FALSE, "ret %08x\n", r );
3002 ok( node == NULL, "node %p\n", node );
3004 str = SysAllocString(szbs);
3005 r = IXMLDOMNode_selectSingleNode( element, str, &node );
3006 SysFreeString(str);
3007 ok( r == S_OK, "ret %08x\n", r );
3008 r = IXMLDOMNode_Release( node );
3009 ok( r == 0, "ret %08x\n", r );
3011 else
3012 ok( FALSE, "no element\n");
3014 if (list)
3016 r = IXMLDOMNodeList_get_item(list, 0, NULL);
3017 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3019 r = IXMLDOMNodeList_get_length(list, NULL);
3020 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3022 r = IXMLDOMNodeList_get_length( list, &count );
3023 ok( r == S_OK, "get_length returns %08x\n", r );
3024 ok( count == 4, "get_length got %d\n", count );
3026 r = IXMLDOMNodeList_nextNode(list, NULL);
3027 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
3029 r = IXMLDOMNodeList_nextNode( list, &node );
3030 ok( r == S_OK, "nextNode returned wrong code\n");
3032 else
3033 ok( FALSE, "no list\n");
3035 if (node)
3037 type = NODE_INVALID;
3038 r = IXMLDOMNode_get_nodeType( node, &type);
3039 ok( r == S_OK, "getNamedItem returned wrong code\n");
3040 ok( type == NODE_ELEMENT, "node not text\n");
3042 VariantInit(&var);
3043 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
3044 r = IXMLDOMNode_get_nodeValue( node, &var );
3045 ok( r == S_FALSE, "nextNode returned wrong code\n");
3046 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
3047 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
3049 r = IXMLDOMNode_hasChildNodes( node, NULL );
3050 ok( r == E_INVALIDARG, "hasChildNodes bad return\n");
3052 EXPECT_CHILDREN(node);
3054 str = NULL;
3055 r = IXMLDOMNode_get_baseName( node, &str );
3056 ok( r == S_OK, "get_baseName returned wrong code\n");
3057 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
3058 SysFreeString(str);
3060 else
3061 ok( FALSE, "no node\n");
3063 if (node)
3064 IXMLDOMNode_Release( node );
3065 if (list)
3066 IXMLDOMNodeList_Release( list );
3067 if (element)
3068 IXMLDOMElement_Release( element );
3070 b = FALSE;
3071 str = SysAllocString( szComplete5 );
3072 r = IXMLDOMDocument_loadXML( doc, str, &b );
3073 ok( r == S_OK, "loadXML failed\n");
3074 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3075 SysFreeString( str );
3077 EXPECT_CHILDREN(doc);
3079 r = IXMLDOMDocument_get_documentElement( doc, &element );
3080 ok( r == S_OK, "should be a document element\n");
3081 ok( element != NULL, "should be an element\n");
3083 if (element)
3085 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
3086 BSTR tag = NULL;
3088 /* check if the tag is correct */
3089 r = IXMLDOMElement_get_tagName( element, &tag );
3090 ok( r == S_OK, "couldn't get tag name\n");
3091 ok( tag != NULL, "tag was null\n");
3092 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
3093 SysFreeString( tag );
3096 if (element)
3097 IXMLDOMElement_Release( element );
3098 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
3101 static void test_refs(void)
3103 HRESULT r;
3104 BSTR str;
3105 VARIANT_BOOL b;
3106 IXMLDOMDocument *doc;
3107 IXMLDOMElement *element = NULL;
3108 IXMLDOMNode *node = NULL, *node2;
3109 IXMLDOMNodeList *node_list = NULL;
3110 LONG ref;
3111 IUnknown *unk, *unk2;
3113 doc = create_document(&IID_IXMLDOMDocument);
3114 if (!doc) return;
3116 EXPECT_REF(doc, 1);
3117 ref = IXMLDOMDocument_Release(doc);
3118 ok( ref == 0, "ref %d\n", ref);
3120 doc = create_document(&IID_IXMLDOMDocument);
3121 if (!doc) return;
3123 str = SysAllocString( szComplete4 );
3124 r = IXMLDOMDocument_loadXML( doc, str, &b );
3125 ok( r == S_OK, "loadXML failed\n");
3126 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3127 SysFreeString( str );
3129 EXPECT_REF(doc, 1);
3130 IXMLDOMDocument_AddRef( doc );
3131 EXPECT_REF(doc, 2);
3132 IXMLDOMDocument_AddRef( doc );
3133 EXPECT_REF(doc, 3);
3135 IXMLDOMDocument_Release( doc );
3136 IXMLDOMDocument_Release( doc );
3138 r = IXMLDOMDocument_get_documentElement( doc, &element );
3139 ok( r == S_OK, "should be a document element\n");
3140 ok( element != NULL, "should be an element\n");
3142 EXPECT_REF(doc, 1);
3143 todo_wine EXPECT_REF(element, 2);
3145 IXMLDOMElement_AddRef(element);
3146 todo_wine EXPECT_REF(element, 3);
3147 IXMLDOMElement_Release(element);
3149 r = IXMLDOMElement_get_childNodes( element, &node_list );
3150 ok( r == S_OK, "rets %08x\n", r);
3152 todo_wine EXPECT_REF(element, 2);
3153 EXPECT_REF(node_list, 1);
3155 IXMLDOMNodeList_get_item( node_list, 0, &node );
3156 ok( r == S_OK, "rets %08x\n", r);
3157 EXPECT_REF(node_list, 1);
3158 EXPECT_REF(node, 1);
3160 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
3161 ok( r == S_OK, "rets %08x\n", r);
3162 EXPECT_REF(node_list, 1);
3163 EXPECT_REF(node2, 1);
3165 ref = IXMLDOMNode_Release( node );
3166 ok( ref == 0, "ref %d\n", ref );
3167 ref = IXMLDOMNode_Release( node2 );
3168 ok( ref == 0, "ref %d\n", ref );
3170 ref = IXMLDOMNodeList_Release( node_list );
3171 ok( ref == 0, "ref %d\n", ref );
3173 ok( node != node2, "node %p node2 %p\n", node, node2 );
3175 ref = IXMLDOMDocument_Release( doc );
3176 ok( ref == 0, "ref %d\n", ref );
3178 todo_wine EXPECT_REF(element, 2);
3180 /* IUnknown must be unique however we obtain it */
3181 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (void**)&unk );
3182 ok( r == S_OK, "rets %08x\n", r );
3183 EXPECT_REF(element, 2);
3184 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (void**)&node );
3185 ok( r == S_OK, "rets %08x\n", r );
3186 todo_wine EXPECT_REF(element, 2);
3187 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk2 );
3188 ok( r == S_OK, "rets %08x\n", r );
3189 todo_wine EXPECT_REF(element, 2);
3190 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
3191 todo_wine ok( element != (void*)node, "node %p element %p\n", node, element );
3193 IUnknown_Release( unk2 );
3194 IUnknown_Release( unk );
3195 IXMLDOMNode_Release( node );
3196 todo_wine EXPECT_REF(element, 2);
3198 IXMLDOMElement_Release( element );
3201 static void test_create(void)
3203 static const WCHAR szOne[] = {'1',0};
3204 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
3205 HRESULT r;
3206 VARIANT var;
3207 BSTR str, name;
3208 IXMLDOMDocument *doc;
3209 IXMLDOMElement *element;
3210 IXMLDOMComment *comment;
3211 IXMLDOMText *text;
3212 IXMLDOMCDATASection *cdata;
3213 IXMLDOMNode *root, *node, *child;
3214 IXMLDOMNamedNodeMap *attr_map;
3215 IUnknown *unk;
3216 LONG ref;
3217 LONG num;
3219 doc = create_document(&IID_IXMLDOMDocument);
3220 if (!doc) return;
3222 EXPECT_REF(doc, 1);
3224 /* types not supported for creation */
3225 V_VT(&var) = VT_I1;
3226 V_I1(&var) = NODE_DOCUMENT;
3227 node = (IXMLDOMNode*)0x1;
3228 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3229 ok( r == E_INVALIDARG, "returns %08x\n", r );
3230 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3232 V_VT(&var) = VT_I1;
3233 V_I1(&var) = NODE_DOCUMENT_TYPE;
3234 node = (IXMLDOMNode*)0x1;
3235 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3236 ok( r == E_INVALIDARG, "returns %08x\n", r );
3237 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3239 V_VT(&var) = VT_I1;
3240 V_I1(&var) = NODE_ENTITY;
3241 node = (IXMLDOMNode*)0x1;
3242 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3243 ok( r == E_INVALIDARG, "returns %08x\n", r );
3244 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3246 V_VT(&var) = VT_I1;
3247 V_I1(&var) = NODE_NOTATION;
3248 node = (IXMLDOMNode*)0x1;
3249 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3250 ok( r == E_INVALIDARG, "returns %08x\n", r );
3251 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3253 /* NODE_COMMENT */
3254 V_VT(&var) = VT_I1;
3255 V_I1(&var) = NODE_COMMENT;
3256 node = NULL;
3257 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3258 ok( r == S_OK, "returns %08x\n", r );
3259 ok( node != NULL, "\n");
3261 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3262 ok( r == S_OK, "returns %08x\n", r );
3263 IXMLDOMNode_Release(node);
3265 str = NULL;
3266 r = IXMLDOMComment_get_data(comment, &str);
3267 ok( r == S_OK, "returns %08x\n", r );
3268 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3269 IXMLDOMComment_Release(comment);
3270 SysFreeString(str);
3272 node = (IXMLDOMNode*)0x1;
3273 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3274 ok( r == S_OK, "returns %08x\n", r );
3276 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3277 ok( r == S_OK, "returns %08x\n", r );
3278 IXMLDOMNode_Release(node);
3280 str = NULL;
3281 r = IXMLDOMComment_get_data(comment, &str);
3282 ok( r == S_OK, "returns %08x\n", r );
3283 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3284 IXMLDOMComment_Release(comment);
3285 SysFreeString(str);
3287 node = (IXMLDOMNode*)0x1;
3288 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3289 ok( r == S_OK, "returns %08x\n", r );
3291 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
3292 ok( r == S_OK, "returns %08x\n", r );
3293 IXMLDOMNode_Release(node);
3295 str = NULL;
3296 r = IXMLDOMComment_get_data(comment, &str);
3297 ok( r == S_OK, "returns %08x\n", r );
3298 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3299 IXMLDOMComment_Release(comment);
3300 SysFreeString(str);
3302 /* NODE_TEXT */
3303 V_VT(&var) = VT_I1;
3304 V_I1(&var) = NODE_TEXT;
3305 node = NULL;
3306 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3307 ok( r == S_OK, "returns %08x\n", r );
3308 ok( node != NULL, "\n");
3310 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3311 ok( r == S_OK, "returns %08x\n", r );
3312 IXMLDOMNode_Release(node);
3314 str = NULL;
3315 r = IXMLDOMText_get_data(text, &str);
3316 ok( r == S_OK, "returns %08x\n", r );
3317 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3318 IXMLDOMText_Release(text);
3319 SysFreeString(str);
3321 node = (IXMLDOMNode*)0x1;
3322 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3323 ok( r == S_OK, "returns %08x\n", r );
3325 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3326 ok( r == S_OK, "returns %08x\n", r );
3327 IXMLDOMNode_Release(node);
3329 str = NULL;
3330 r = IXMLDOMText_get_data(text, &str);
3331 ok( r == S_OK, "returns %08x\n", r );
3332 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3333 IXMLDOMText_Release(text);
3334 SysFreeString(str);
3336 node = (IXMLDOMNode*)0x1;
3337 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3338 ok( r == S_OK, "returns %08x\n", r );
3340 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
3341 ok( r == S_OK, "returns %08x\n", r );
3342 IXMLDOMNode_Release(node);
3344 str = NULL;
3345 r = IXMLDOMText_get_data(text, &str);
3346 ok( r == S_OK, "returns %08x\n", r );
3347 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3348 IXMLDOMText_Release(text);
3349 SysFreeString(str);
3351 /* NODE_CDATA_SECTION */
3352 V_VT(&var) = VT_I1;
3353 V_I1(&var) = NODE_CDATA_SECTION;
3354 node = NULL;
3355 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3356 ok( r == S_OK, "returns %08x\n", r );
3357 ok( node != NULL, "\n");
3359 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3360 ok( r == S_OK, "returns %08x\n", r );
3361 IXMLDOMNode_Release(node);
3363 str = NULL;
3364 r = IXMLDOMCDATASection_get_data(cdata, &str);
3365 ok( r == S_OK, "returns %08x\n", r );
3366 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3367 IXMLDOMCDATASection_Release(cdata);
3368 SysFreeString(str);
3370 node = (IXMLDOMNode*)0x1;
3371 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3372 ok( r == S_OK, "returns %08x\n", r );
3374 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3375 ok( r == S_OK, "returns %08x\n", r );
3376 IXMLDOMNode_Release(node);
3378 str = NULL;
3379 r = IXMLDOMCDATASection_get_data(cdata, &str);
3380 ok( r == S_OK, "returns %08x\n", r );
3381 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3382 IXMLDOMCDATASection_Release(cdata);
3383 SysFreeString(str);
3385 node = (IXMLDOMNode*)0x1;
3386 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
3387 ok( r == S_OK, "returns %08x\n", r );
3389 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
3390 ok( r == S_OK, "returns %08x\n", r );
3391 IXMLDOMNode_Release(node);
3393 str = NULL;
3394 r = IXMLDOMCDATASection_get_data(cdata, &str);
3395 ok( r == S_OK, "returns %08x\n", r );
3396 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
3397 IXMLDOMCDATASection_Release(cdata);
3398 SysFreeString(str);
3400 /* NODE_ATTRIBUTE */
3401 V_VT(&var) = VT_I1;
3402 V_I1(&var) = NODE_ATTRIBUTE;
3403 node = (IXMLDOMNode*)0x1;
3404 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3405 ok( r == E_FAIL, "returns %08x\n", r );
3406 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3408 V_VT(&var) = VT_I1;
3409 V_I1(&var) = NODE_ATTRIBUTE;
3410 node = (IXMLDOMNode*)0x1;
3411 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3412 ok( r == E_FAIL, "returns %08x\n", r );
3413 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3415 V_VT(&var) = VT_I1;
3416 V_I1(&var) = NODE_ATTRIBUTE;
3417 str = SysAllocString( szlc );
3418 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3419 ok( r == S_OK, "returns %08x\n", r );
3420 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3421 SysFreeString(str);
3423 /* a name is required for attribute, try a BSTR with first null wchar */
3424 V_VT(&var) = VT_I1;
3425 V_I1(&var) = NODE_ATTRIBUTE;
3426 str = SysAllocString( szstr1 );
3427 str[0] = 0;
3428 node = (IXMLDOMNode*)0x1;
3429 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3430 ok( r == E_FAIL, "returns %08x\n", r );
3431 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3432 SysFreeString(str);
3434 /* NODE_PROCESSING_INSTRUCTION */
3435 V_VT(&var) = VT_I1;
3436 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3437 node = (IXMLDOMNode*)0x1;
3438 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3439 ok( r == E_FAIL, "returns %08x\n", r );
3440 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3442 V_VT(&var) = VT_I1;
3443 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3444 node = (IXMLDOMNode*)0x1;
3445 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3446 ok( r == E_FAIL, "returns %08x\n", r );
3447 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3449 V_VT(&var) = VT_I1;
3450 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
3451 r = IXMLDOMDocument_createNode( doc, var, _bstr_("pi"), NULL, NULL );
3452 ok( r == E_INVALIDARG, "returns %08x\n", r );
3454 /* NODE_ENTITY_REFERENCE */
3455 V_VT(&var) = VT_I1;
3456 V_I1(&var) = NODE_ENTITY_REFERENCE;
3457 node = (IXMLDOMNode*)0x1;
3458 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3459 ok( r == E_FAIL, "returns %08x\n", r );
3460 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3462 V_VT(&var) = VT_I1;
3463 V_I1(&var) = NODE_ENTITY_REFERENCE;
3464 node = (IXMLDOMNode*)0x1;
3465 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3466 ok( r == E_FAIL, "returns %08x\n", r );
3467 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3469 /* NODE_ELEMENT */
3470 V_VT(&var) = VT_I1;
3471 V_I1(&var) = NODE_ELEMENT;
3472 node = (IXMLDOMNode*)0x1;
3473 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
3474 ok( r == E_FAIL, "returns %08x\n", r );
3475 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3477 V_VT(&var) = VT_I1;
3478 V_I1(&var) = NODE_ELEMENT;
3479 node = (IXMLDOMNode*)0x1;
3480 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
3481 ok( r == E_FAIL, "returns %08x\n", r );
3482 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
3484 V_VT(&var) = VT_I1;
3485 V_I1(&var) = NODE_ELEMENT;
3486 str = SysAllocString( szlc );
3487 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3488 ok( r == S_OK, "returns %08x\n", r );
3489 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3491 V_VT(&var) = VT_I1;
3492 V_I1(&var) = NODE_ELEMENT;
3493 r = IXMLDOMDocument_createNode( doc, var, str, NULL, NULL );
3494 ok( r == E_INVALIDARG, "returns %08x\n", r );
3496 V_VT(&var) = VT_R4;
3497 V_R4(&var) = NODE_ELEMENT;
3498 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3499 ok( r == S_OK, "returns %08x\n", r );
3500 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3502 V_VT(&var) = VT_BSTR;
3503 V_BSTR(&var) = SysAllocString( szOne );
3504 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3505 ok( r == S_OK, "returns %08x\n", r );
3506 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3507 VariantClear(&var);
3509 V_VT(&var) = VT_BSTR;
3510 V_BSTR(&var) = SysAllocString( szOneGarbage );
3511 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3512 ok( r == E_INVALIDARG, "returns %08x\n", r );
3513 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
3514 VariantClear(&var);
3516 V_VT(&var) = VT_I4;
3517 V_I4(&var) = NODE_ELEMENT;
3518 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3519 ok( r == S_OK, "returns %08x\n", r );
3521 EXPECT_REF(doc, 1);
3522 r = IXMLDOMDocument_appendChild( doc, node, &root );
3523 ok( r == S_OK, "returns %08x\n", r );
3524 ok( node == root, "%p %p\n", node, root );
3525 EXPECT_REF(doc, 1);
3527 EXPECT_REF(node, 2);
3529 ref = IXMLDOMNode_Release( node );
3530 ok(ref == 1, "ref %d\n", ref);
3531 SysFreeString( str );
3533 V_VT(&var) = VT_I4;
3534 V_I4(&var) = NODE_ELEMENT;
3535 str = SysAllocString( szbs );
3536 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3537 ok( r == S_OK, "returns %08x\n", r );
3538 SysFreeString( str );
3540 EXPECT_REF(node, 1);
3542 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk );
3543 ok( r == S_OK, "returns %08x\n", r );
3545 EXPECT_REF(unk, 2);
3547 V_VT(&var) = VT_EMPTY;
3548 child = NULL;
3549 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
3550 ok( r == S_OK, "returns %08x\n", r );
3551 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
3553 todo_wine EXPECT_REF(unk, 4);
3555 IXMLDOMNode_Release( child );
3556 IUnknown_Release( unk );
3558 V_VT(&var) = VT_NULL;
3559 V_DISPATCH(&var) = (IDispatch*)node;
3560 r = IXMLDOMNode_insertBefore( root, node, var, &child );
3561 ok( r == S_OK, "returns %08x\n", r );
3562 ok( node == child, "%p %p\n", node, child );
3563 IXMLDOMNode_Release( child );
3565 V_VT(&var) = VT_NULL;
3566 V_DISPATCH(&var) = (IDispatch*)node;
3567 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
3568 ok( r == S_OK, "returns %08x\n", r );
3569 IXMLDOMNode_Release( node );
3571 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (void**)&element );
3572 ok( r == S_OK, "returns %08x\n", r );
3574 r = IXMLDOMElement_get_attributes( element, &attr_map );
3575 ok( r == S_OK, "returns %08x\n", r );
3576 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3577 ok( r == S_OK, "returns %08x\n", r );
3578 ok( num == 0, "num %d\n", num );
3579 IXMLDOMNamedNodeMap_Release( attr_map );
3581 V_VT(&var) = VT_BSTR;
3582 V_BSTR(&var) = SysAllocString( szstr1 );
3583 name = SysAllocString( szdl );
3584 r = IXMLDOMElement_setAttribute( element, name, var );
3585 ok( r == S_OK, "returns %08x\n", r );
3586 r = IXMLDOMElement_get_attributes( element, &attr_map );
3587 ok( r == S_OK, "returns %08x\n", r );
3588 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3589 ok( r == S_OK, "returns %08x\n", r );
3590 ok( num == 1, "num %d\n", num );
3591 IXMLDOMNamedNodeMap_Release( attr_map );
3592 VariantClear(&var);
3594 V_VT(&var) = VT_BSTR;
3595 V_BSTR(&var) = SysAllocString( szstr2 );
3596 r = IXMLDOMElement_setAttribute( element, name, var );
3597 ok( r == S_OK, "returns %08x\n", r );
3598 r = IXMLDOMElement_get_attributes( element, &attr_map );
3599 ok( r == S_OK, "returns %08x\n", r );
3600 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3601 ok( r == S_OK, "returns %08x\n", r );
3602 ok( num == 1, "num %d\n", num );
3603 IXMLDOMNamedNodeMap_Release( attr_map );
3604 VariantClear(&var);
3605 r = IXMLDOMElement_getAttribute( element, name, &var );
3606 ok( r == S_OK, "returns %08x\n", r );
3607 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
3608 VariantClear(&var);
3609 SysFreeString(name);
3611 V_VT(&var) = VT_BSTR;
3612 V_BSTR(&var) = SysAllocString( szstr1 );
3613 name = SysAllocString( szlc );
3614 r = IXMLDOMElement_setAttribute( element, name, var );
3615 ok( r == S_OK, "returns %08x\n", r );
3616 r = IXMLDOMElement_get_attributes( element, &attr_map );
3617 ok( r == S_OK, "returns %08x\n", r );
3618 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
3619 ok( r == S_OK, "returns %08x\n", r );
3620 ok( num == 2, "num %d\n", num );
3621 IXMLDOMNamedNodeMap_Release( attr_map );
3622 VariantClear(&var);
3623 SysFreeString(name);
3625 V_VT(&var) = VT_I4;
3626 V_I4(&var) = 10;
3627 name = SysAllocString( szbs );
3628 r = IXMLDOMElement_setAttribute( element, name, var );
3629 ok( r == S_OK, "returns %08x\n", r );
3630 VariantClear(&var);
3631 r = IXMLDOMElement_getAttribute( element, name, &var );
3632 ok( r == S_OK, "returns %08x\n", r );
3633 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
3634 VariantClear(&var);
3635 SysFreeString(name);
3637 /* Create an Attribute */
3638 V_VT(&var) = VT_I4;
3639 V_I4(&var) = NODE_ATTRIBUTE;
3640 str = SysAllocString( szAttribute );
3641 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3642 ok( r == S_OK, "returns %08x\n", r );
3643 ok( node != NULL, "node was null\n");
3644 SysFreeString(str);
3646 IXMLDOMElement_Release( element );
3647 IXMLDOMNode_Release( root );
3648 IXMLDOMDocument_Release( doc );
3651 static void test_getElementsByTagName(void)
3653 IXMLDOMNodeList *node_list;
3654 IXMLDOMDocument *doc;
3655 IXMLDOMElement *elem;
3656 WCHAR buff[100];
3657 VARIANT_BOOL b;
3658 HRESULT r;
3659 LONG len;
3660 BSTR str;
3662 doc = create_document(&IID_IXMLDOMDocument);
3663 if (!doc) return;
3665 str = SysAllocString( szComplete4 );
3666 r = IXMLDOMDocument_loadXML( doc, str, &b );
3667 ok( r == S_OK, "loadXML failed\n");
3668 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3669 SysFreeString( str );
3671 str = SysAllocString( szstar );
3673 /* null arguments cases */
3674 r = IXMLDOMDocument_getElementsByTagName(doc, NULL, &node_list);
3675 ok( r == E_INVALIDARG, "ret %08x\n", r );
3676 r = IXMLDOMDocument_getElementsByTagName(doc, str, NULL);
3677 ok( r == E_INVALIDARG, "ret %08x\n", r );
3679 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3680 ok( r == S_OK, "ret %08x\n", r );
3681 r = IXMLDOMNodeList_get_length( node_list, &len );
3682 ok( r == S_OK, "ret %08x\n", r );
3683 ok( len == 6, "len %d\n", len );
3685 IXMLDOMNodeList_Release( node_list );
3686 SysFreeString( str );
3688 /* broken query BSTR */
3689 memcpy(&buff[2], szstar, sizeof(szstar));
3690 /* just a big length */
3691 *(DWORD*)buff = 0xf0f0;
3692 r = IXMLDOMDocument_getElementsByTagName(doc, &buff[2], &node_list);
3693 ok( r == S_OK, "ret %08x\n", r );
3694 r = IXMLDOMNodeList_get_length( node_list, &len );
3695 ok( r == S_OK, "ret %08x\n", r );
3696 ok( len == 6, "len %d\n", len );
3697 IXMLDOMNodeList_Release( node_list );
3699 str = SysAllocString( szbs );
3700 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3701 ok( r == S_OK, "ret %08x\n", r );
3702 r = IXMLDOMNodeList_get_length( node_list, &len );
3703 ok( r == S_OK, "ret %08x\n", r );
3704 ok( len == 1, "len %d\n", len );
3705 IXMLDOMNodeList_Release( node_list );
3706 SysFreeString( str );
3708 str = SysAllocString( szdl );
3709 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3710 ok( r == S_OK, "ret %08x\n", r );
3711 r = IXMLDOMNodeList_get_length( node_list, &len );
3712 ok( r == S_OK, "ret %08x\n", r );
3713 ok( len == 0, "len %d\n", len );
3714 IXMLDOMNodeList_Release( node_list );
3715 SysFreeString( str );
3717 str = SysAllocString( szstr1 );
3718 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
3719 ok( r == S_OK, "ret %08x\n", r );
3720 r = IXMLDOMNodeList_get_length( node_list, &len );
3721 ok( r == S_OK, "ret %08x\n", r );
3722 ok( len == 0, "len %d\n", len );
3723 IXMLDOMNodeList_Release( node_list );
3724 SysFreeString( str );
3726 /* test for element */
3727 r = IXMLDOMDocument_get_documentElement(doc, &elem);
3728 ok( r == S_OK, "ret %08x\n", r );
3730 str = SysAllocString( szstar );
3732 /* null arguments cases */
3733 r = IXMLDOMElement_getElementsByTagName(elem, NULL, &node_list);
3734 ok( r == E_INVALIDARG, "ret %08x\n", r );
3735 r = IXMLDOMElement_getElementsByTagName(elem, str, NULL);
3736 ok( r == E_INVALIDARG, "ret %08x\n", r );
3738 r = IXMLDOMElement_getElementsByTagName(elem, str, &node_list);
3739 ok( r == S_OK, "ret %08x\n", r );
3740 r = IXMLDOMNodeList_get_length( node_list, &len );
3741 ok( r == S_OK, "ret %08x\n", r );
3742 ok( len == 5, "len %d\n", len );
3743 expect_list_and_release(node_list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1 E1.E4.E2.D1");
3744 SysFreeString( str );
3746 /* broken query BSTR */
3747 memcpy(&buff[2], szstar, sizeof(szstar));
3748 /* just a big length */
3749 *(DWORD*)buff = 0xf0f0;
3750 r = IXMLDOMElement_getElementsByTagName(elem, &buff[2], &node_list);
3751 ok( r == S_OK, "ret %08x\n", r );
3752 r = IXMLDOMNodeList_get_length( node_list, &len );
3753 ok( r == S_OK, "ret %08x\n", r );
3754 ok( len == 5, "len %d\n", len );
3755 IXMLDOMNodeList_Release( node_list );
3757 IXMLDOMElement_Release(elem);
3759 IXMLDOMDocument_Release( doc );
3762 static void test_get_text(void)
3764 HRESULT r;
3765 BSTR str;
3766 VARIANT_BOOL b;
3767 IXMLDOMDocument *doc;
3768 IXMLDOMNode *node, *node2, *node3;
3769 IXMLDOMNode *nodeRoot;
3770 IXMLDOMNodeList *node_list;
3771 IXMLDOMNamedNodeMap *node_map;
3772 LONG len;
3774 doc = create_document(&IID_IXMLDOMDocument);
3775 if (!doc) return;
3777 str = SysAllocString( szComplete4 );
3778 r = IXMLDOMDocument_loadXML( doc, str, &b );
3779 ok( r == S_OK, "loadXML failed\n");
3780 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3781 SysFreeString( str );
3783 str = SysAllocString( szbs );
3784 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
3785 ok( r == S_OK, "ret %08x\n", r );
3786 SysFreeString(str);
3788 /* Test to get all child node text. */
3789 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&nodeRoot);
3790 ok( r == S_OK, "ret %08x\n", r );
3791 if(r == S_OK)
3793 r = IXMLDOMNode_get_text( nodeRoot, &str );
3794 ok( r == S_OK, "ret %08x\n", r );
3795 ok( compareIgnoreReturns(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text: %s\n", wine_dbgstr_w(str));
3796 SysFreeString(str);
3798 IXMLDOMNode_Release(nodeRoot);
3801 r = IXMLDOMNodeList_get_length( node_list, NULL );
3802 ok( r == E_INVALIDARG, "ret %08x\n", r );
3804 r = IXMLDOMNodeList_get_length( node_list, &len );
3805 ok( r == S_OK, "ret %08x\n", r );
3806 ok( len == 1, "expect 1 got %d\n", len );
3808 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
3809 ok( r == E_INVALIDARG, "ret %08x\n", r );
3811 r = IXMLDOMNodeList_nextNode( node_list, NULL );
3812 ok( r == E_INVALIDARG, "ret %08x\n", r );
3814 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
3815 ok( r == S_OK, "ret %08x\n", r );
3816 IXMLDOMNodeList_Release( node_list );
3818 /* Invalid output parameter*/
3819 r = IXMLDOMNode_get_text( node, NULL );
3820 ok( r == E_INVALIDARG, "ret %08x\n", r );
3822 r = IXMLDOMNode_get_text( node, &str );
3823 ok( r == S_OK, "ret %08x\n", r );
3824 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
3825 SysFreeString(str);
3827 r = IXMLDOMNode_get_attributes( node, &node_map );
3828 ok( r == S_OK, "ret %08x\n", r );
3830 str = SysAllocString( szvr );
3831 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
3832 ok( r == S_OK, "ret %08x\n", r );
3833 SysFreeString(str);
3835 r = IXMLDOMNode_get_text( node2, &str );
3836 ok( r == S_OK, "ret %08x\n", r );
3837 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3838 SysFreeString(str);
3840 r = IXMLDOMNode_get_firstChild( node2, &node3 );
3841 ok( r == S_OK, "ret %08x\n", r );
3843 r = IXMLDOMNode_get_text( node3, &str );
3844 ok( r == S_OK, "ret %08x\n", r );
3845 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3846 SysFreeString(str);
3849 IXMLDOMNode_Release( node3 );
3850 IXMLDOMNode_Release( node2 );
3851 IXMLDOMNamedNodeMap_Release( node_map );
3852 IXMLDOMNode_Release( node );
3853 IXMLDOMDocument_Release( doc );
3856 static void test_get_childNodes(void)
3858 BSTR str;
3859 VARIANT_BOOL b;
3860 IXMLDOMDocument *doc;
3861 IXMLDOMElement *element;
3862 IXMLDOMNode *node, *node2;
3863 IXMLDOMNodeList *node_list, *node_list2;
3864 HRESULT hr;
3865 LONG len;
3867 doc = create_document(&IID_IXMLDOMDocument);
3868 if (!doc) return;
3870 str = SysAllocString( szComplete4 );
3871 hr = IXMLDOMDocument_loadXML( doc, str, &b );
3872 EXPECT_HR(hr, S_OK);
3873 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3874 SysFreeString( str );
3876 hr = IXMLDOMDocument_get_documentElement( doc, &element );
3877 EXPECT_HR(hr, S_OK);
3879 hr = IXMLDOMElement_get_childNodes( element, &node_list );
3880 EXPECT_HR(hr, S_OK);
3882 hr = IXMLDOMNodeList_get_length( node_list, &len );
3883 EXPECT_HR(hr, S_OK);
3884 ok( len == 4, "len %d\n", len);
3886 hr = IXMLDOMNodeList_get_item( node_list, 2, &node );
3887 EXPECT_HR(hr, S_OK);
3889 hr = IXMLDOMNode_get_childNodes( node, &node_list2 );
3890 EXPECT_HR(hr, S_OK);
3892 hr = IXMLDOMNodeList_get_length( node_list2, &len );
3893 EXPECT_HR(hr, S_OK);
3894 ok( len == 0, "len %d\n", len);
3896 hr = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
3897 EXPECT_HR(hr, S_FALSE);
3899 IXMLDOMNodeList_Release( node_list2 );
3900 IXMLDOMNode_Release( node );
3901 IXMLDOMNodeList_Release( node_list );
3902 IXMLDOMElement_Release( element );
3904 /* test for children of <?xml ..?> node */
3905 hr = IXMLDOMDocument_get_firstChild(doc, &node);
3906 EXPECT_HR(hr, S_OK);
3908 str = NULL;
3909 hr = IXMLDOMNode_get_nodeName(node, &str);
3910 EXPECT_HR(hr, S_OK);
3911 ok(!lstrcmpW(str, _bstr_("xml")), "got %s\n", wine_dbgstr_w(str));
3912 SysFreeString(str);
3914 /* it returns empty but valid node list */
3915 node_list = (void*)0xdeadbeef;
3916 hr = IXMLDOMNode_get_childNodes(node, &node_list);
3917 EXPECT_HR(hr, S_OK);
3919 len = -1;
3920 hr = IXMLDOMNodeList_get_length(node_list, &len);
3921 EXPECT_HR(hr, S_OK);
3922 ok(len == 0, "got %d\n", len);
3924 IXMLDOMNodeList_Release( node_list );
3925 IXMLDOMNode_Release(node);
3927 IXMLDOMDocument_Release( doc );
3928 free_bstrs();
3931 static void test_get_firstChild(void)
3933 static WCHAR xmlW[] = {'x','m','l',0};
3934 IXMLDOMDocument *doc;
3935 IXMLDOMNode *node;
3936 VARIANT_BOOL b;
3937 HRESULT r;
3938 BSTR str;
3940 doc = create_document(&IID_IXMLDOMDocument);
3941 if (!doc) return;
3943 str = SysAllocString( szComplete4 );
3944 r = IXMLDOMDocument_loadXML( doc, str, &b );
3945 ok( r == S_OK, "loadXML failed\n");
3946 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3947 SysFreeString( str );
3949 r = IXMLDOMDocument_get_firstChild( doc, &node );
3950 ok( r == S_OK, "ret %08x\n", r);
3952 r = IXMLDOMNode_get_nodeName( node, &str );
3953 ok( r == S_OK, "ret %08x\n", r);
3955 ok(!lstrcmpW(str, xmlW), "expected \"xml\" node name, got %s\n", wine_dbgstr_w(str));
3957 SysFreeString(str);
3958 IXMLDOMNode_Release( node );
3959 IXMLDOMDocument_Release( doc );
3962 static void test_get_lastChild(void)
3964 static WCHAR lcW[] = {'l','c',0};
3965 static WCHAR foW[] = {'f','o',0};
3966 IXMLDOMDocument *doc;
3967 IXMLDOMNode *node, *child;
3968 VARIANT_BOOL b;
3969 HRESULT r;
3970 BSTR str;
3972 doc = create_document(&IID_IXMLDOMDocument);
3973 if (!doc) return;
3975 str = SysAllocString( szComplete4 );
3976 r = IXMLDOMDocument_loadXML( doc, str, &b );
3977 ok( r == S_OK, "loadXML failed\n");
3978 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3979 SysFreeString( str );
3981 r = IXMLDOMDocument_get_lastChild( doc, &node );
3982 ok( r == S_OK, "ret %08x\n", r);
3984 r = IXMLDOMNode_get_nodeName( node, &str );
3985 ok( r == S_OK, "ret %08x\n", r);
3987 ok(memcmp(str, lcW, sizeof(lcW)) == 0, "expected \"lc\" node name\n");
3988 SysFreeString(str);
3990 r = IXMLDOMNode_get_lastChild( node, &child );
3991 ok( r == S_OK, "ret %08x\n", r);
3993 r = IXMLDOMNode_get_nodeName( child, &str );
3994 ok( r == S_OK, "ret %08x\n", r);
3996 ok(memcmp(str, foW, sizeof(foW)) == 0, "expected \"fo\" node name\n");
3997 SysFreeString(str);
3999 IXMLDOMNode_Release( child );
4000 IXMLDOMNode_Release( node );
4001 IXMLDOMDocument_Release( doc );
4004 static void test_removeChild(void)
4006 HRESULT r;
4007 BSTR str;
4008 VARIANT_BOOL b;
4009 IXMLDOMDocument *doc;
4010 IXMLDOMElement *element, *lc_element;
4011 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
4012 IXMLDOMNodeList *root_list, *fo_list;
4014 doc = create_document(&IID_IXMLDOMDocument);
4015 if (!doc) return;
4017 str = SysAllocString( szComplete4 );
4018 r = IXMLDOMDocument_loadXML( doc, str, &b );
4019 ok( r == S_OK, "loadXML failed\n");
4020 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4021 SysFreeString( str );
4023 r = IXMLDOMDocument_get_documentElement( doc, &element );
4024 ok( r == S_OK, "ret %08x\n", r);
4025 todo_wine EXPECT_REF(element, 2);
4027 r = IXMLDOMElement_get_childNodes( element, &root_list );
4028 ok( r == S_OK, "ret %08x\n", r);
4029 EXPECT_REF(root_list, 1);
4031 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
4032 ok( r == S_OK, "ret %08x\n", r);
4033 EXPECT_REF(fo_node, 1);
4035 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4036 ok( r == S_OK, "ret %08x\n", r);
4037 EXPECT_REF(fo_list, 1);
4039 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
4040 ok( r == S_OK, "ret %08x\n", r);
4041 EXPECT_REF(ba_node, 1);
4043 /* invalid parameter: NULL ptr */
4044 removed_node = (void*)0xdeadbeef;
4045 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
4046 ok( r == E_INVALIDARG, "ret %08x\n", r );
4047 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4049 /* ba_node is a descendant of element, but not a direct child. */
4050 removed_node = (void*)0xdeadbeef;
4051 EXPECT_REF(ba_node, 1);
4052 EXPECT_CHILDREN(fo_node);
4053 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
4054 ok( r == E_INVALIDARG, "ret %08x\n", r );
4055 ok( removed_node == NULL, "%p\n", removed_node );
4056 EXPECT_REF(ba_node, 1);
4057 EXPECT_CHILDREN(fo_node);
4059 EXPECT_REF(ba_node, 1);
4060 EXPECT_REF(fo_node, 1);
4061 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
4062 ok( r == S_OK, "ret %08x\n", r);
4063 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
4064 EXPECT_REF(fo_node, 2);
4065 EXPECT_REF(ba_node, 1);
4067 /* try removing already removed child */
4068 temp_node = (void*)0xdeadbeef;
4069 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
4070 ok( r == E_INVALIDARG, "ret %08x\n", r);
4071 ok( temp_node == NULL, "%p\n", temp_node );
4072 IXMLDOMNode_Release( fo_node );
4074 /* the removed node has no parent anymore */
4075 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
4076 ok( r == S_FALSE, "ret %08x\n", r);
4077 ok( temp_node == NULL, "%p\n", temp_node );
4079 IXMLDOMNode_Release( removed_node );
4080 IXMLDOMNode_Release( ba_node );
4081 IXMLDOMNodeList_Release( fo_list );
4083 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
4084 ok( r == S_OK, "ret %08x\n", r);
4086 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (void**)&lc_element );
4087 ok( r == S_OK, "ret %08x\n", r);
4089 /* MS quirk: passing wrong interface pointer works, too */
4090 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
4091 ok( r == S_OK, "ret %08x\n", r);
4092 IXMLDOMElement_Release( lc_element );
4094 temp_node = (void*)0xdeadbeef;
4095 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
4096 ok( r == S_FALSE, "ret %08x\n", r);
4097 ok( temp_node == NULL, "%p\n", temp_node );
4099 IXMLDOMNode_Release( lc_node );
4100 IXMLDOMNodeList_Release( root_list );
4101 IXMLDOMElement_Release( element );
4102 IXMLDOMDocument_Release( doc );
4105 static void test_replaceChild(void)
4107 HRESULT r;
4108 BSTR str;
4109 VARIANT_BOOL b;
4110 IXMLDOMDocument *doc;
4111 IXMLDOMElement *element, *ba_element;
4112 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
4113 IXMLDOMNodeList *root_list, *fo_list;
4114 IUnknown * unk1, *unk2;
4115 LONG len;
4117 doc = create_document(&IID_IXMLDOMDocument);
4118 if (!doc) return;
4120 str = SysAllocString( szComplete4 );
4121 r = IXMLDOMDocument_loadXML( doc, str, &b );
4122 ok( r == S_OK, "loadXML failed\n");
4123 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4124 SysFreeString( str );
4126 r = IXMLDOMDocument_get_documentElement( doc, &element );
4127 ok( r == S_OK, "ret %08x\n", r);
4129 r = IXMLDOMElement_get_childNodes( element, &root_list );
4130 ok( r == S_OK, "ret %08x\n", r);
4132 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
4133 ok( r == S_OK, "ret %08x\n", r);
4135 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
4136 ok( r == S_OK, "ret %08x\n", r);
4138 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4139 ok( r == S_OK, "ret %08x\n", r);
4141 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
4142 ok( r == S_OK, "ret %08x\n", r);
4144 IXMLDOMNodeList_Release( fo_list );
4146 /* invalid parameter: NULL ptr for element to remove */
4147 removed_node = (void*)0xdeadbeef;
4148 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
4149 ok( r == E_INVALIDARG, "ret %08x\n", r );
4150 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4152 /* invalid parameter: NULL for replacement element. (Sic!) */
4153 removed_node = (void*)0xdeadbeef;
4154 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
4155 ok( r == E_INVALIDARG, "ret %08x\n", r );
4156 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
4158 /* invalid parameter: OldNode is not a child */
4159 removed_node = (void*)0xdeadbeef;
4160 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
4161 ok( r == E_INVALIDARG, "ret %08x\n", r );
4162 ok( removed_node == NULL, "%p\n", removed_node );
4163 IXMLDOMNode_Release( lc_node );
4165 /* invalid parameter: would create loop */
4166 removed_node = (void*)0xdeadbeef;
4167 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
4168 ok( r == E_FAIL, "ret %08x\n", r );
4169 ok( removed_node == NULL, "%p\n", removed_node );
4171 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
4172 ok( r == S_OK, "ret %08x\n", r );
4174 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
4175 ok( r == S_OK, "ret %08x\n", r );
4177 /* ba_node and temp_node refer to the same node, yet they
4178 are different interface pointers */
4179 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
4180 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
4181 ok( r == S_OK, "ret %08x\n", r );
4182 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
4183 ok( r == S_OK, "ret %08x\n", r );
4184 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
4186 IUnknown_Release( unk1 );
4187 IUnknown_Release( unk2 );
4189 /* ba_node should have been removed from below fo_node */
4190 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
4191 ok( r == S_OK, "ret %08x\n", r );
4193 /* MS quirk: replaceChild also accepts elements instead of nodes */
4194 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
4195 ok( r == S_OK, "ret %08x\n", r );
4196 EXPECT_REF(ba_element, 2);
4198 removed_node = NULL;
4199 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
4200 ok( r == S_OK, "ret %08x\n", r );
4201 ok( removed_node != NULL, "got %p\n", removed_node);
4202 EXPECT_REF(ba_element, 3);
4203 IXMLDOMElement_Release( ba_element );
4205 r = IXMLDOMNodeList_get_length( fo_list, &len);
4206 ok( r == S_OK, "ret %08x\n", r );
4207 ok( len == 0, "len %d\n", len);
4209 IXMLDOMNodeList_Release( fo_list );
4211 IXMLDOMNode_Release(ba_node);
4212 IXMLDOMNode_Release(fo_node);
4213 IXMLDOMNode_Release(temp_node);
4214 IXMLDOMNodeList_Release( root_list );
4215 IXMLDOMElement_Release( element );
4216 IXMLDOMDocument_Release( doc );
4219 static void test_removeNamedItem(void)
4221 IXMLDOMDocument *doc;
4222 IXMLDOMElement *element;
4223 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
4224 IXMLDOMNodeList *root_list;
4225 IXMLDOMNamedNodeMap * pr_attrs;
4226 VARIANT_BOOL b;
4227 BSTR str;
4228 LONG len;
4229 HRESULT r;
4231 doc = create_document(&IID_IXMLDOMDocument);
4232 if (!doc) return;
4234 str = SysAllocString( szComplete4 );
4235 r = IXMLDOMDocument_loadXML( doc, str, &b );
4236 ok( r == S_OK, "loadXML failed\n");
4237 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4238 SysFreeString( str );
4240 r = IXMLDOMDocument_get_documentElement( doc, &element );
4241 ok( r == S_OK, "ret %08x\n", r);
4243 r = IXMLDOMElement_get_childNodes( element, &root_list );
4244 ok( r == S_OK, "ret %08x\n", r);
4246 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
4247 ok( r == S_OK, "ret %08x\n", r);
4249 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
4250 ok( r == S_OK, "ret %08x\n", r);
4252 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4253 ok( r == S_OK, "ret %08x\n", r);
4254 ok( len == 3, "length %d\n", len);
4256 removed_node = (void*)0xdeadbeef;
4257 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
4258 ok ( r == E_INVALIDARG, "ret %08x\n", r);
4259 ok ( removed_node == (void*)0xdeadbeef, "got %p\n", removed_node);
4261 removed_node = (void*)0xdeadbeef;
4262 str = SysAllocString(szvr);
4263 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
4264 ok ( r == S_OK, "ret %08x\n", r);
4266 removed_node2 = (void*)0xdeadbeef;
4267 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
4268 ok ( r == S_FALSE, "ret %08x\n", r);
4269 ok ( removed_node2 == NULL, "got %p\n", removed_node2 );
4271 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4272 ok( r == S_OK, "ret %08x\n", r);
4273 ok( len == 2, "length %d\n", len);
4275 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
4276 ok ( r == S_OK, "ret %08x\n", r);
4277 IXMLDOMNode_Release(removed_node);
4279 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4280 ok( r == S_OK, "ret %08x\n", r);
4281 ok( len == 3, "length %d\n", len);
4283 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
4284 ok ( r == S_OK, "ret %08x\n", r);
4286 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
4287 ok( r == S_OK, "ret %08x\n", r);
4288 ok( len == 2, "length %d\n", len);
4290 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
4291 ok ( r == S_FALSE, "ret %08x\n", r);
4293 SysFreeString(str);
4295 IXMLDOMNamedNodeMap_Release( pr_attrs );
4296 IXMLDOMNode_Release( pr_node );
4297 IXMLDOMNodeList_Release( root_list );
4298 IXMLDOMElement_Release( element );
4299 IXMLDOMDocument_Release( doc );
4302 #define test_IObjectSafety_set(p, r, r2, s, m, e, e2) _test_IObjectSafety_set(__LINE__,p, r, r2, s, m, e, e2)
4303 static void _test_IObjectSafety_set(unsigned line, IObjectSafety *safety, HRESULT result,
4304 HRESULT result2, DWORD set, DWORD mask, DWORD expected,
4305 DWORD expected2)
4307 DWORD enabled, supported;
4308 HRESULT hr;
4310 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL, set, mask);
4311 if (result == result2)
4312 ok_(__FILE__,line)(hr == result, "SetInterfaceSafetyOptions: expected %08x, returned %08x\n", result, hr );
4313 else
4314 ok_(__FILE__,line)(broken(hr == result) || hr == result2,
4315 "SetInterfaceSafetyOptions: expected %08x, got %08x\n", result2, hr );
4317 supported = enabled = 0xCAFECAFE;
4318 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4319 ok(hr == S_OK, "ret %08x\n", hr );
4320 if (expected == expected2)
4321 ok_(__FILE__,line)(enabled == expected, "Expected %08x, got %08x\n", expected, enabled);
4322 else
4323 ok_(__FILE__,line)(broken(enabled == expected) || enabled == expected2,
4324 "Expected %08x, got %08x\n", expected2, enabled);
4326 /* reset the safety options */
4328 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4329 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER,
4331 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4333 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4334 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4335 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
4338 #define test_IObjectSafety_common(s) _test_IObjectSafety_common(__LINE__,s)
4339 static void _test_IObjectSafety_common(unsigned line, IObjectSafety *safety)
4341 DWORD enabled = 0, supported = 0;
4342 HRESULT hr;
4344 /* get */
4345 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, NULL, &enabled);
4346 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
4347 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, NULL);
4348 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
4350 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4351 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4352 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
4353 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4354 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
4355 "got %08x\n", supported);
4356 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
4358 /* set -- individual flags */
4360 test_IObjectSafety_set(safety, S_OK, S_OK,
4361 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4362 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4364 test_IObjectSafety_set(safety, S_OK, S_OK,
4365 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA,
4366 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
4368 test_IObjectSafety_set(safety, S_OK, S_OK,
4369 INTERFACE_USES_SECURITY_MANAGER, INTERFACE_USES_SECURITY_MANAGER,
4370 0, INTERFACE_USES_SECURITY_MANAGER /* msxml3 SP8+ */);
4372 /* set INTERFACE_USES_DISPEX */
4374 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
4375 INTERFACE_USES_DISPEX, INTERFACE_USES_DISPEX,
4376 0, 0);
4378 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
4379 INTERFACE_USES_DISPEX, 0,
4380 0, 0);
4382 test_IObjectSafety_set(safety, S_OK, S_OK /* msxml3 SP8+ */,
4383 0, INTERFACE_USES_DISPEX,
4384 0, 0);
4386 /* set option masking */
4388 test_IObjectSafety_set(safety, S_OK, S_OK,
4389 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4390 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4391 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4392 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4394 test_IObjectSafety_set(safety, S_OK, S_OK,
4395 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4396 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4397 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4398 INTERFACESAFE_FOR_UNTRUSTED_DATA);
4400 test_IObjectSafety_set(safety, S_OK, S_OK,
4401 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
4402 INTERFACE_USES_SECURITY_MANAGER,
4406 /* set -- inheriting previous settings */
4408 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4409 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
4410 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
4411 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4412 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4413 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4414 ok_(__FILE__,line)(enabled == INTERFACESAFE_FOR_UNTRUSTED_CALLER, "Expected INTERFACESAFE_FOR_UNTRUSTED_CALLER got %08x\n", enabled);
4415 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
4416 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4417 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
4418 "got %08x\n", supported);
4420 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
4421 INTERFACESAFE_FOR_UNTRUSTED_DATA,
4422 INTERFACESAFE_FOR_UNTRUSTED_DATA);
4423 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4424 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
4425 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
4426 ok_(__FILE__,line)(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_DATA) ||
4427 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA),
4428 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA) got %08x\n", enabled);
4429 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
4430 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
4431 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
4432 "got %08x\n", supported);
4435 static void test_XMLHTTP(void)
4437 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
4438 static const WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
4439 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
4440 'p','o','s','t','t','e','s','t','.','p','h','p',0};
4441 static const WCHAR xmltestW[] = {'h','t','t','p',':','/','/',
4442 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
4443 'x','m','l','t','e','s','t','.','x','m','l',0};
4444 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
4445 static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
4447 IXMLHttpRequest *xhr;
4448 IObjectSafety *safety;
4449 IObjectWithSite *obj_site, *obj_site2;
4450 BSTR bstrResponse, url;
4451 VARIANT dummy;
4452 VARIANT async;
4453 VARIANT varbody;
4454 LONG state, status, bound;
4455 IDispatch *event;
4456 void *ptr;
4457 HRESULT hr;
4459 hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
4460 &IID_IXMLHttpRequest, (void**)&xhr);
4461 if (FAILED(hr))
4463 win_skip("IXMLHTTPRequest is not available (0x%08x)\n", hr);
4464 return;
4467 VariantInit(&dummy);
4468 V_VT(&dummy) = VT_ERROR;
4469 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
4470 VariantInit(&async);
4471 V_VT(&async) = VT_BOOL;
4472 V_BOOL(&async) = VARIANT_FALSE;
4473 V_VT(&varbody) = VT_BSTR;
4474 V_BSTR(&varbody) = SysAllocString(wszBody);
4476 url = SysAllocString(wszUrl);
4478 hr = IXMLHttpRequest_put_onreadystatechange(xhr, NULL);
4479 EXPECT_HR(hr, S_OK);
4481 hr = IXMLHttpRequest_abort(xhr);
4482 EXPECT_HR(hr, S_OK);
4484 /* send before open */
4485 hr = IXMLHttpRequest_send(xhr, dummy);
4486 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4488 /* initial status code */
4489 hr = IXMLHttpRequest_get_status(xhr, NULL);
4490 EXPECT_HR(hr, E_INVALIDARG);
4492 status = 0xdeadbeef;
4493 hr = IXMLHttpRequest_get_status(xhr, &status);
4494 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4495 ok(status == 0xdeadbeef, "got %d\n", status);
4497 /* invalid parameters */
4498 hr = IXMLHttpRequest_open(xhr, NULL, NULL, async, dummy, dummy);
4499 EXPECT_HR(hr, E_INVALIDARG);
4501 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), NULL, async, dummy, dummy);
4502 EXPECT_HR(hr, E_INVALIDARG);
4504 hr = IXMLHttpRequest_open(xhr, NULL, url, async, dummy, dummy);
4505 EXPECT_HR(hr, E_INVALIDARG);
4507 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, NULL);
4508 EXPECT_HR(hr, E_INVALIDARG);
4510 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), NULL);
4511 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4513 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
4514 EXPECT_HR(hr, E_INVALIDARG);
4516 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
4517 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4519 hr = IXMLHttpRequest_get_readyState(xhr, NULL);
4520 EXPECT_HR(hr, E_INVALIDARG);
4522 state = -1;
4523 hr = IXMLHttpRequest_get_readyState(xhr, &state);
4524 EXPECT_HR(hr, S_OK);
4525 ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state);
4527 event = create_dispevent();
4529 EXPECT_REF(event, 1);
4530 hr = IXMLHttpRequest_put_onreadystatechange(xhr, event);
4531 EXPECT_HR(hr, S_OK);
4532 EXPECT_REF(event, 2);
4534 g_unexpectedcall = g_expectedcall = 0;
4536 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), url, async, dummy, dummy);
4537 EXPECT_HR(hr, S_OK);
4539 ok(g_unexpectedcall == 0, "unexpected disp event call\n");
4540 ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n");
4542 /* status code after ::open() */
4543 status = 0xdeadbeef;
4544 hr = IXMLHttpRequest_get_status(xhr, &status);
4545 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4546 ok(status == 0xdeadbeef, "got %d\n", status);
4548 state = -1;
4549 hr = IXMLHttpRequest_get_readyState(xhr, &state);
4550 EXPECT_HR(hr, S_OK);
4551 ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state);
4553 hr = IXMLHttpRequest_abort(xhr);
4554 EXPECT_HR(hr, S_OK);
4556 state = -1;
4557 hr = IXMLHttpRequest_get_readyState(xhr, &state);
4558 EXPECT_HR(hr, S_OK);
4559 ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win2k */,
4560 "got %d, expected READYSTATE_UNINITIALIZED\n", state);
4562 hr = IXMLHttpRequest_open(xhr, _bstr_("POST"), url, async, dummy, dummy);
4563 EXPECT_HR(hr, S_OK);
4565 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
4566 EXPECT_HR(hr, S_OK);
4568 hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
4569 EXPECT_HR(hr, E_INVALIDARG);
4571 hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_(""), _bstr_("value1"));
4572 EXPECT_HR(hr, E_INVALIDARG);
4574 SysFreeString(url);
4576 hr = IXMLHttpRequest_send(xhr, varbody);
4577 if (hr == INET_E_RESOURCE_NOT_FOUND)
4579 skip("No connection could be made with crossover.codeweavers.com\n");
4580 IXMLHttpRequest_Release(xhr);
4581 return;
4583 EXPECT_HR(hr, S_OK);
4585 /* status code after ::send() */
4586 status = 0xdeadbeef;
4587 hr = IXMLHttpRequest_get_status(xhr, &status);
4588 EXPECT_HR(hr, S_OK);
4589 ok(status == 200, "got %d\n", status);
4591 /* another ::send() after completed request */
4592 hr = IXMLHttpRequest_send(xhr, varbody);
4593 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
4595 VariantClear(&varbody);
4597 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
4598 EXPECT_HR(hr, S_OK);
4599 /* the server currently returns "FAILED" because the Content-Type header is
4600 * not what the server expects */
4601 if(hr == S_OK)
4603 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)),
4604 "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse));
4605 SysFreeString(bstrResponse);
4608 /* GET request */
4609 url = SysAllocString(xmltestW);
4611 hr = IXMLHttpRequest_open(xhr, _bstr_("GET"), url, async, dummy, dummy);
4612 EXPECT_HR(hr, S_OK);
4614 V_VT(&varbody) = VT_EMPTY;
4616 hr = IXMLHttpRequest_send(xhr, varbody);
4617 if (hr == INET_E_RESOURCE_NOT_FOUND)
4619 skip("No connection could be made with crossover.codeweavers.com\n");
4620 IXMLHttpRequest_Release(xhr);
4621 return;
4623 EXPECT_HR(hr, S_OK);
4625 hr = IXMLHttpRequest_get_responseText(xhr, NULL);
4626 EXPECT_HR(hr, E_INVALIDARG);
4628 hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
4629 EXPECT_HR(hr, S_OK);
4630 ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
4631 "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
4632 SysFreeString(bstrResponse);
4634 hr = IXMLHttpRequest_get_responseBody(xhr, NULL);
4635 EXPECT_HR(hr, E_INVALIDARG);
4637 V_VT(&varbody) = VT_EMPTY;
4638 hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
4639 EXPECT_HR(hr, S_OK);
4640 ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
4641 ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
4643 bound = -1;
4644 hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
4645 EXPECT_HR(hr, S_OK);
4646 ok(bound == 0, "got %d, expected zero bound\n", bound);
4648 hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
4649 EXPECT_HR(hr, S_OK);
4650 ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrong body data\n");
4651 SafeArrayUnaccessData(V_ARRAY(&varbody));
4653 VariantClear(&varbody);
4655 SysFreeString(url);
4657 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectSafety, (void**)&safety);
4658 EXPECT_HR(hr, S_OK);
4659 if(hr == S_OK)
4661 test_IObjectSafety_common(safety);
4662 IObjectSafety_Release(safety);
4665 IDispatch_Release(event);
4667 /* interaction with object site */
4668 EXPECT_REF(xhr, 1);
4669 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site);
4670 EXPECT_HR(hr, S_OK);
4671 todo_wine {
4672 EXPECT_REF(xhr, 1);
4673 EXPECT_REF(obj_site, 1);
4676 IObjectWithSite_AddRef(obj_site);
4677 todo_wine {
4678 EXPECT_REF(obj_site, 2);
4679 EXPECT_REF(xhr, 1);
4681 IObjectWithSite_Release(obj_site);
4683 hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site2);
4684 EXPECT_HR(hr, S_OK);
4685 todo_wine {
4686 EXPECT_REF(xhr, 1);
4687 EXPECT_REF(obj_site, 1);
4688 EXPECT_REF(obj_site2, 1);
4689 ok(obj_site != obj_site2, "expected new instance\n");
4691 SET_EXPECT(site_qi_IServiceProvider);
4692 SET_EXPECT(sp_queryservice_SID_SBindHost);
4693 SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
4694 SET_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
4695 SET_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
4696 SET_EXPECT(sp_queryservice_SID_secmgr_secmgr);
4698 /* calls to IHTMLDocument2 */
4699 SET_EXPECT(htmldoc2_get_all);
4700 SET_EXPECT(collection_get_length);
4701 SET_EXPECT(htmldoc2_get_url);
4703 SET_EXPECT(site_qi_IXMLDOMDocument);
4704 SET_EXPECT(site_qi_IOleClientSite);
4706 hr = IObjectWithSite_SetSite(obj_site, &testsite.IUnknown_iface);
4707 EXPECT_HR(hr, S_OK);
4709 todo_wine{
4710 CHECK_CALLED(site_qi_IServiceProvider);
4712 CHECK_CALLED(sp_queryservice_SID_SBindHost);
4713 CHECK_CALLED(sp_queryservice_SID_SContainerDispatch_htmldoc2);
4714 CHECK_CALLED(sp_queryservice_SID_secmgr_htmldoc2);
4715 CHECK_CALLED(sp_queryservice_SID_secmgr_xmldomdoc);
4716 /* this one isn't very reliable
4717 CHECK_CALLED(sp_queryservice_SID_secmgr_secmgr); */
4719 CHECK_CALLED(htmldoc2_get_all);
4720 CHECK_CALLED(collection_get_length);
4721 CHECK_CALLED(htmldoc2_get_url);
4723 CHECK_CALLED(site_qi_IXMLDOMDocument);
4724 CHECK_CALLED(site_qi_IOleClientSite);
4726 IObjectWithSite_Release(obj_site);
4728 todo_wine EXPECT_REF(xhr, 1);
4729 IXMLHttpRequest_Release(xhr);
4731 /* still works after request is released */
4732 SET_EXPECT(site_qi_IServiceProvider);
4734 hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
4735 EXPECT_HR(hr, S_OK);
4736 IObjectWithSite_Release(obj_site2);
4738 free_bstrs();
4741 static void test_IXMLDOMDocument2(void)
4743 static const WCHAR emptyW[] = {0};
4744 IXMLDOMDocument2 *doc2, *dtddoc2;
4745 IXMLDOMDocument *doc;
4746 IXMLDOMParseError* err;
4747 IDispatchEx *dispex;
4748 VARIANT_BOOL b;
4749 VARIANT var;
4750 HRESULT r;
4751 LONG res;
4752 BSTR str;
4754 doc = create_document(&IID_IXMLDOMDocument);
4755 if (!doc) return;
4757 dtddoc2 = create_document(&IID_IXMLDOMDocument2);
4758 if (!dtddoc2)
4760 IXMLDOMDocument_Release(doc);
4761 return;
4764 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
4765 ok( r == S_OK, "ret %08x\n", r );
4766 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
4768 ole_expect(IXMLDOMDocument2_get_readyState(doc2, NULL), E_INVALIDARG);
4769 ole_check(IXMLDOMDocument2_get_readyState(doc2, &res));
4770 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
4772 err = NULL;
4773 ole_expect(IXMLDOMDocument2_validate(doc2, NULL), S_FALSE);
4774 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
4775 ok(err != NULL, "expected a pointer\n");
4776 if (err)
4778 res = 0;
4779 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4780 /* XML_E_NOTWF */
4781 ok(res == E_XML_NOTWF, "got %08x\n", res);
4782 IXMLDOMParseError_Release(err);
4785 str = SysAllocString( szComplete4 );
4786 r = IXMLDOMDocument_loadXML( doc2, str, &b );
4787 ok( r == S_OK, "loadXML failed\n");
4788 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4789 SysFreeString( str );
4791 ole_check(IXMLDOMDocument2_get_readyState(doc, &res));
4792 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
4794 err = NULL;
4795 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
4796 ok(err != NULL, "expected a pointer\n");
4797 if (err)
4799 res = 0;
4800 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4801 /* XML_E_NODTD */
4802 ok(res == E_XML_NODTD, "got %08x\n", res);
4803 IXMLDOMParseError_Release(err);
4806 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
4807 ok( r == S_OK, "ret %08x\n", r );
4808 if(r == S_OK)
4810 IDispatchEx_Release(dispex);
4813 /* we will check if the variant got cleared */
4814 IXMLDOMDocument2_AddRef(doc2);
4815 EXPECT_REF(doc2, 3); /* doc, doc2, AddRef*/
4817 V_VT(&var) = VT_UNKNOWN;
4818 V_UNKNOWN(&var) = (IUnknown *)doc2;
4820 /* invalid calls */
4821 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
4822 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
4823 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
4825 /* valid call */
4826 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
4827 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
4828 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
4829 V_VT(&var) = VT_R4;
4831 /* the variant didn't get cleared*/
4832 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
4834 /* setProperty tests */
4835 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
4836 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
4837 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
4838 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
4839 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4840 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
4842 V_VT(&var) = VT_BSTR;
4843 V_BSTR(&var) = SysAllocString(emptyW);
4844 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
4845 ok(r == S_OK, "got 0x%08x\n", r);
4846 VariantClear(&var);
4848 V_VT(&var) = VT_I2;
4849 V_I2(&var) = 0;
4850 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
4851 ok(r == E_FAIL, "got 0x%08x\n", r);
4853 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
4854 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
4855 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
4856 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
4858 IXMLDOMDocument2_Release( doc2 );
4859 IXMLDOMDocument_Release( doc );
4861 /* DTD validation */
4862 ole_check(IXMLDOMDocument2_put_validateOnParse(dtddoc2, VARIANT_FALSE));
4863 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML), &b));
4864 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4865 err = NULL;
4866 ole_check(IXMLDOMDocument2_validate(dtddoc2, &err));
4867 ok(err != NULL, "expected pointer\n");
4868 if (err)
4870 res = 0;
4871 ole_expect(IXMLDOMParseError_get_errorCode(err, &res), S_FALSE);
4872 ok(res == 0, "got %08x\n", res);
4873 IXMLDOMParseError_Release(err);
4876 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0D), &b));
4877 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4878 err = NULL;
4879 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4880 ok(err != NULL, "expected pointer\n");
4881 if (err)
4883 res = 0;
4884 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4885 /* XML_ELEMENT_UNDECLARED */
4886 todo_wine ok(res == 0xC00CE00D, "got %08x\n", res);
4887 IXMLDOMParseError_Release(err);
4890 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0E), &b));
4891 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4892 err = NULL;
4893 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4894 ok(err != NULL, "expected pointer\n");
4895 if (err)
4897 res = 0;
4898 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4899 /* XML_ELEMENT_ID_NOT_FOUND */
4900 todo_wine ok(res == 0xC00CE00E, "got %08x\n", res);
4901 IXMLDOMParseError_Release(err);
4904 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_11), &b));
4905 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4906 err = NULL;
4907 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4908 ok(err != NULL, "expected pointer\n");
4909 if (err)
4911 res = 0;
4912 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4913 /* XML_EMPTY_NOT_ALLOWED */
4914 todo_wine ok(res == 0xC00CE011, "got %08x\n", res);
4915 IXMLDOMParseError_Release(err);
4918 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_13), &b));
4919 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4920 err = NULL;
4921 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4922 ok(err != NULL, "expected pointer\n");
4923 if (err)
4925 res = 0;
4926 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4927 /* XML_ROOT_NAME_MISMATCH */
4928 todo_wine ok(res == 0xC00CE013, "got %08x\n", res);
4929 IXMLDOMParseError_Release(err);
4932 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_14), &b));
4933 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4934 err = NULL;
4935 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4936 ok(err != NULL, "expected pointer\n");
4937 if (err)
4939 res = 0;
4940 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4941 /* XML_INVALID_CONTENT */
4942 todo_wine ok(res == 0xC00CE014, "got %08x\n", res);
4943 IXMLDOMParseError_Release(err);
4946 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_15), &b));
4947 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4948 err = NULL;
4949 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4950 ok(err != NULL, "expected pointer\n");
4951 if (err)
4953 res = 0;
4954 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4955 /* XML_ATTRIBUTE_NOT_DEFINED */
4956 todo_wine ok(res == 0xC00CE015, "got %08x\n", res);
4957 IXMLDOMParseError_Release(err);
4960 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_16), &b));
4961 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4962 err = NULL;
4963 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4964 ok(err != NULL, "expected pointer\n");
4965 if (err)
4967 res = 0;
4968 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4969 /* XML_ATTRIBUTE_FIXED */
4970 todo_wine ok(res == 0xC00CE016, "got %08x\n", res);
4971 IXMLDOMParseError_Release(err);
4974 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_17), &b));
4975 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4976 err = NULL;
4977 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4978 ok(err != NULL, "expected pointer\n");
4979 if (err)
4981 res = 0;
4982 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4983 /* XML_ATTRIBUTE_VALUE */
4984 todo_wine ok(res == 0xC00CE017, "got %08x\n", res);
4985 IXMLDOMParseError_Release(err);
4988 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_18), &b));
4989 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4990 err = NULL;
4991 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4992 ok(err != NULL, "expected pointer\n");
4993 if (err)
4995 res = 0;
4996 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4997 /* XML_ILLEGAL_TEXT */
4998 todo_wine ok(res == 0xC00CE018, "got %08x\n", res);
4999 IXMLDOMParseError_Release(err);
5002 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_20), &b));
5003 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5004 err = NULL;
5005 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
5006 ok(err != NULL, "expected pointer\n");
5007 if (err)
5009 res = 0;
5010 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
5011 /* XML_REQUIRED_ATTRIBUTE_MISSING */
5012 todo_wine ok(res == 0xC00CE020, "got %08x\n", res);
5013 IXMLDOMParseError_Release(err);
5016 IXMLDOMDocument2_Release( dtddoc2 );
5017 free_bstrs();
5020 #define helper_ole_check(expr) { \
5021 HRESULT r = expr; \
5022 ok_(__FILE__, line)(r == S_OK, "=> %i: " #expr " returned %08x\n", __LINE__, r); \
5025 #define helper_expect_list_and_release(list, expstr) { \
5026 char *str = list_to_string(list); \
5027 ok_(__FILE__, line)(strcmp(str, expstr)==0, "=> %i: Invalid node list: %s, expected %s\n", __LINE__, str, expstr); \
5028 if (list) IXMLDOMNodeList_Release(list); \
5031 #define helper_expect_bstr_and_release(bstr, str) { \
5032 ok_(__FILE__, line)(lstrcmpW(bstr, _bstr_(str)) == 0, \
5033 "=> %i: got %s\n", __LINE__, wine_dbgstr_w(bstr)); \
5034 SysFreeString(bstr); \
5037 #define check_ws_ignored(doc, str) _check_ws_ignored(__LINE__, doc, str)
5038 static inline void _check_ws_ignored(int line, IXMLDOMDocument2* doc, char const* str)
5040 IXMLDOMNode *node1, *node2;
5041 IXMLDOMNodeList *list;
5042 BSTR bstr;
5044 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
5045 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
5046 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
5047 helper_ole_check(IXMLDOMNodeList_reset(list));
5048 helper_expect_list_and_release(list, "E1.E4.E1.E2.D1 E2.E4.E1.E2.D1");
5050 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
5051 helper_expect_list_and_release(list, "T1.E1.E4.E1.E2.D1 E2.E1.E4.E1.E2.D1 E3.E1.E4.E1.E2.D1 T4.E1.E4.E1.E2.D1 E5.E1.E4.E1.E2.D1");
5052 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
5053 if (str)
5055 helper_expect_bstr_and_release(bstr, str);
5057 else
5059 helper_expect_bstr_and_release(bstr, "This is a description.");
5061 IXMLDOMNode_Release(node1);
5063 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
5064 helper_expect_list_and_release(list, "T1.E2.E4.E1.E2.D1 E2.E2.E4.E1.E2.D1 T3.E2.E4.E1.E2.D1 E4.E2.E4.E1.E2.D1 T5.E2.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1 T7.E2.E4.E1.E2.D1");
5065 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
5066 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
5067 IXMLDOMNode_Release(node2);
5070 #define check_ws_preserved(doc, str) _check_ws_preserved(__LINE__, doc, str)
5071 static inline void _check_ws_preserved(int line, IXMLDOMDocument2* doc, char const* str)
5073 IXMLDOMNode *node1, *node2;
5074 IXMLDOMNodeList *list;
5075 BSTR bstr;
5077 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
5078 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
5079 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
5080 helper_ole_check(IXMLDOMNodeList_reset(list));
5081 helper_expect_list_and_release(list, "E2.E8.E2.E2.D1 E4.E8.E2.E2.D1");
5083 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
5084 helper_expect_list_and_release(list, "T1.E2.E8.E2.E2.D1 E2.E2.E8.E2.E2.D1 T3.E2.E8.E2.E2.D1 E4.E2.E8.E2.E2.D1 T5.E2.E8.E2.E2.D1 E6.E2.E8.E2.E2.D1 T7.E2.E8.E2.E2.D1");
5085 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
5086 if (str)
5088 helper_expect_bstr_and_release(bstr, str);
5090 else
5092 helper_expect_bstr_and_release(bstr, "\n This is a description. \n ");
5094 IXMLDOMNode_Release(node1);
5096 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
5097 helper_expect_list_and_release(list, "T1.E4.E8.E2.E2.D1 E2.E4.E8.E2.E2.D1 T3.E4.E8.E2.E2.D1 E4.E4.E8.E2.E2.D1 T5.E4.E8.E2.E2.D1 E6.E4.E8.E2.E2.D1 T7.E4.E8.E2.E2.D1");
5098 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
5099 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
5100 IXMLDOMNode_Release(node2);
5103 static void test_whitespace(void)
5105 VARIANT_BOOL b;
5106 IXMLDOMDocument2 *doc1, *doc2, *doc3, *doc4;
5108 doc1 = create_document(&IID_IXMLDOMDocument2);
5109 doc2 = create_document(&IID_IXMLDOMDocument2);
5110 if (!doc1 || !doc2) return;
5112 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_TRUE));
5113 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
5114 ok(b == VARIANT_FALSE, "expected false\n");
5115 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
5116 ok(b == VARIANT_TRUE, "expected true\n");
5118 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
5119 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5120 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
5121 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5123 /* switch to XPath */
5124 ole_check(IXMLDOMDocument2_setProperty(doc1, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5125 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5127 check_ws_ignored(doc1, NULL);
5128 check_ws_preserved(doc2, NULL);
5130 /* new instances copy the property */
5131 ole_check(IXMLDOMDocument2_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**) &doc3));
5132 ole_check(IXMLDOMDocument2_QueryInterface(doc2, &IID_IXMLDOMDocument2, (void**) &doc4));
5134 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
5135 ok(b == VARIANT_FALSE, "expected false\n");
5136 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
5137 ok(b == VARIANT_TRUE, "expected true\n");
5139 check_ws_ignored(doc3, NULL);
5140 check_ws_preserved(doc4, NULL);
5142 /* setting after loading xml affects trimming of leading/trailing ws only */
5143 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_TRUE));
5144 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_FALSE));
5146 /* the trailing "\n " isn't there, because it was ws-only node */
5147 check_ws_ignored(doc1, "\n This is a description. ");
5148 check_ws_preserved(doc2, "This is a description.");
5150 /* it takes effect on reload */
5151 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
5152 ok(b == VARIANT_TRUE, "expected true\n");
5153 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
5154 ok(b == VARIANT_FALSE, "expected false\n");
5156 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
5157 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5158 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
5159 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5161 check_ws_preserved(doc1, NULL);
5162 check_ws_ignored(doc2, NULL);
5164 /* other instances follow suit */
5165 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
5166 ok(b == VARIANT_TRUE, "expected true\n");
5167 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
5168 ok(b == VARIANT_FALSE, "expected false\n");
5170 check_ws_preserved(doc3, NULL);
5171 check_ws_ignored(doc4, NULL);
5173 IXMLDOMDocument_Release(doc1);
5174 IXMLDOMDocument_Release(doc2);
5175 IXMLDOMDocument_Release(doc3);
5176 IXMLDOMDocument_Release(doc4);
5177 free_bstrs();
5180 static void test_XPath(void)
5182 VARIANT var;
5183 VARIANT_BOOL b;
5184 IXMLDOMDocument2 *doc;
5185 IXMLDOMDocument *doc2;
5186 IXMLDOMNode *rootNode;
5187 IXMLDOMNode *elem1Node;
5188 IXMLDOMNode *node;
5189 IXMLDOMNodeList *list;
5190 IXMLDOMElement *elem;
5191 IXMLDOMAttribute *attr;
5192 HRESULT hr;
5193 BSTR str;
5195 doc = create_document(&IID_IXMLDOMDocument2);
5196 if (!doc) return;
5198 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
5199 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5201 /* switch to XPath */
5202 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
5204 /* some simple queries*/
5205 EXPECT_REF(doc, 1);
5206 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5207 EXPECT_HR(hr, S_OK);
5208 EXPECT_REF(doc, 1);
5209 EXPECT_LIST_LEN(list, 1);
5211 EXPECT_REF(list, 1);
5212 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5213 EXPECT_HR(hr, S_OK);
5214 EXPECT_REF(list, 1);
5215 EXPECT_REF(rootNode, 1);
5217 hr = IXMLDOMNodeList_reset(list);
5218 EXPECT_HR(hr, S_OK);
5219 expect_list_and_release(list, "E2.D1");
5221 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//c"), &list));
5222 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
5224 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//c[@type]"), &list));
5225 expect_list_and_release(list, "E3.E2.E2.D1");
5227 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
5228 /* using get_item for query results advances the position */
5229 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
5230 expect_node(node, "E2.E2.D1");
5231 IXMLDOMNode_Release(node);
5232 ole_check(IXMLDOMNodeList_nextNode(list, &node));
5233 expect_node(node, "E4.E2.D1");
5234 IXMLDOMNode_Release(node);
5235 ole_check(IXMLDOMNodeList_reset(list));
5236 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
5238 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
5239 expect_list_and_release(list, "E2.D1");
5241 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
5242 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
5243 ole_check(IXMLDOMNodeList_reset(list));
5244 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
5246 /* select an attribute */
5247 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
5248 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
5250 /* would evaluate to a number */
5251 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
5252 /* would evaluate to a boolean */
5253 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
5254 /* would evaluate to a string */
5255 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
5257 /* no results */
5258 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
5259 expect_list_and_release(list, "");
5260 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
5261 expect_list_and_release(list, "");
5262 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
5263 expect_list_and_release(list, "");
5264 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//elem[0]"), &list));
5265 expect_list_and_release(list, "");
5267 /* foo undeclared in document node */
5268 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5269 /* undeclared in <root> node */
5270 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
5271 /* undeclared in <elem> node */
5272 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
5273 /* but this trick can be used */
5274 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
5275 expect_list_and_release(list, "E3.E4.E2.D1");
5277 /* it has to be declared in SelectionNamespaces */
5278 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5279 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
5281 /* now the namespace can be used */
5282 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//test:c"), &list));
5283 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5284 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
5285 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5286 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
5287 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
5288 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
5289 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
5291 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
5292 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5293 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
5295 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5297 VariantInit(&var);
5298 ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
5299 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
5300 if (V_VT(&var) == VT_BSTR)
5301 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
5303 /* extra attributes - same thing*/
5304 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
5305 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
5306 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
5308 IXMLDOMNode_Release(rootNode);
5309 IXMLDOMNode_Release(elem1Node);
5311 /* alter document with already built list */
5312 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5313 EXPECT_HR(hr, S_OK);
5314 EXPECT_LIST_LEN(list, 1);
5316 hr = IXMLDOMDocument2_get_lastChild(doc, &rootNode);
5317 EXPECT_HR(hr, S_OK);
5318 EXPECT_REF(rootNode, 1);
5319 EXPECT_REF(doc, 1);
5321 hr = IXMLDOMDocument2_removeChild(doc, rootNode, NULL);
5322 EXPECT_HR(hr, S_OK);
5323 IXMLDOMNode_Release(rootNode);
5325 EXPECT_LIST_LEN(list, 1);
5327 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5328 EXPECT_HR(hr, S_OK);
5329 EXPECT_REF(rootNode, 1);
5331 IXMLDOMNodeList_Release(list);
5333 hr = IXMLDOMNode_get_nodeName(rootNode, &str);
5334 EXPECT_HR(hr, S_OK);
5335 ok(!lstrcmpW(str, _bstr_("root")), "got %s\n", wine_dbgstr_w(str));
5336 SysFreeString(str);
5337 IXMLDOMNode_Release(rootNode);
5339 /* alter node from list and get it another time */
5340 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
5341 EXPECT_HR(hr, S_OK);
5342 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5344 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5345 EXPECT_HR(hr, S_OK);
5346 EXPECT_LIST_LEN(list, 1);
5348 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5349 EXPECT_HR(hr, S_OK);
5351 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
5352 EXPECT_HR(hr, S_OK);
5354 V_VT(&var) = VT_I2;
5355 V_I2(&var) = 1;
5356 hr = IXMLDOMElement_setAttribute(elem, _bstr_("attrtest"), var);
5357 EXPECT_HR(hr, S_OK);
5358 IXMLDOMElement_Release(elem);
5359 IXMLDOMNode_Release(rootNode);
5361 /* now check attribute to be present */
5362 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5363 EXPECT_HR(hr, S_OK);
5365 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
5366 EXPECT_HR(hr, S_OK);
5368 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
5369 EXPECT_HR(hr, S_OK);
5370 IXMLDOMAttribute_Release(attr);
5372 IXMLDOMElement_Release(elem);
5373 IXMLDOMNode_Release(rootNode);
5375 /* and now check for attribute in original document */
5376 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
5377 EXPECT_HR(hr, S_OK);
5379 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
5380 EXPECT_HR(hr, S_OK);
5381 IXMLDOMAttribute_Release(attr);
5383 IXMLDOMElement_Release(elem);
5385 /* attach node from list to another document */
5386 doc2 = create_document(&IID_IXMLDOMDocument);
5388 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
5389 EXPECT_HR(hr, S_OK);
5390 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5392 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
5393 EXPECT_HR(hr, S_OK);
5394 EXPECT_LIST_LEN(list, 1);
5396 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
5397 EXPECT_HR(hr, S_OK);
5398 EXPECT_REF(rootNode, 1);
5400 hr = IXMLDOMDocument_appendChild(doc2, rootNode, NULL);
5401 EXPECT_HR(hr, S_OK);
5402 EXPECT_REF(rootNode, 1);
5403 EXPECT_REF(doc2, 1);
5404 EXPECT_REF(list, 1);
5406 EXPECT_LIST_LEN(list, 1);
5408 IXMLDOMNode_Release(rootNode);
5409 IXMLDOMNodeList_Release(list);
5410 IXMLDOMDocument_Release(doc2);
5412 IXMLDOMDocument2_Release(doc);
5413 free_bstrs();
5416 static void test_cloneNode(void )
5418 IXMLDOMDocument *doc, *doc2;
5419 VARIANT_BOOL b;
5420 IXMLDOMNodeList *pList;
5421 IXMLDOMNamedNodeMap *mapAttr;
5422 LONG length, length1;
5423 LONG attr_cnt, attr_cnt1;
5424 IXMLDOMNode *node;
5425 IXMLDOMNode *node_clone;
5426 IXMLDOMNode *node_first;
5427 HRESULT hr;
5428 BSTR str;
5430 doc = create_document(&IID_IXMLDOMDocument);
5431 if (!doc) return;
5433 str = SysAllocString( szComplete4 );
5434 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
5435 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5436 SysFreeString(str);
5438 hr = IXMLDOMNode_selectSingleNode(doc, _bstr_("lc/pr"), &node);
5439 ok( hr == S_OK, "ret %08x\n", hr );
5440 ok( node != NULL, "node %p\n", node );
5442 /* Check invalid parameter */
5443 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
5444 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
5446 /* All Children */
5447 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
5448 ok( hr == S_OK, "ret %08x\n", hr );
5449 ok( node_clone != NULL, "node %p\n", node );
5451 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
5452 ok( hr == S_OK, "ret %08x\n", hr );
5453 hr = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
5454 ok( hr == S_OK, "ret %08x\n", hr );
5455 IXMLDOMDocument_Release(doc2);
5456 IXMLDOMNode_Release(node_first);
5458 hr = IXMLDOMNode_get_childNodes(node, &pList);
5459 ok( hr == S_OK, "ret %08x\n", hr );
5460 length = 0;
5461 hr = IXMLDOMNodeList_get_length(pList, &length);
5462 ok( hr == S_OK, "ret %08x\n", hr );
5463 ok(length == 1, "got %d\n", length);
5464 IXMLDOMNodeList_Release(pList);
5466 hr = IXMLDOMNode_get_attributes(node, &mapAttr);
5467 ok( hr == S_OK, "ret %08x\n", hr );
5468 attr_cnt = 0;
5469 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt);
5470 ok( hr == S_OK, "ret %08x\n", hr );
5471 ok(attr_cnt == 3, "got %d\n", attr_cnt);
5472 IXMLDOMNamedNodeMap_Release(mapAttr);
5474 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
5475 ok( hr == S_OK, "ret %08x\n", hr );
5476 length1 = 0;
5477 hr = IXMLDOMNodeList_get_length(pList, &length1);
5478 ok(length1 == 1, "got %d\n", length1);
5479 ok( hr == S_OK, "ret %08x\n", hr );
5480 IXMLDOMNodeList_Release(pList);
5482 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
5483 ok( hr == S_OK, "ret %08x\n", hr );
5484 attr_cnt1 = 0;
5485 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
5486 ok( hr == S_OK, "ret %08x\n", hr );
5487 ok(attr_cnt1 == 3, "got %d\n", attr_cnt1);
5488 IXMLDOMNamedNodeMap_Release(mapAttr);
5490 ok(length == length1, "wrong Child count (%d, %d)\n", length, length1);
5491 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
5492 IXMLDOMNode_Release(node_clone);
5494 /* No Children */
5495 hr = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
5496 ok( hr == S_OK, "ret %08x\n", hr );
5497 ok( node_clone != NULL, "node %p\n", node );
5499 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
5500 ok(hr == S_FALSE, "ret %08x\n", hr );
5502 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
5503 ok(hr == S_OK, "ret %08x\n", hr );
5504 hr = IXMLDOMNodeList_get_length(pList, &length1);
5505 ok(hr == S_OK, "ret %08x\n", hr );
5506 ok( length1 == 0, "Length should be 0 (%d)\n", length1);
5507 IXMLDOMNodeList_Release(pList);
5509 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
5510 ok(hr == S_OK, "ret %08x\n", hr );
5511 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
5512 ok(hr == S_OK, "ret %08x\n", hr );
5513 ok(attr_cnt1 == 3, "Attribute count should be 3 (%d)\n", attr_cnt1);
5514 IXMLDOMNamedNodeMap_Release(mapAttr);
5516 ok(length != length1, "wrong Child count (%d, %d)\n", length, length1);
5517 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
5518 IXMLDOMNode_Release(node_clone);
5520 IXMLDOMNode_Release(node);
5521 IXMLDOMDocument_Release(doc);
5522 free_bstrs();
5525 static void test_xmlTypes(void)
5527 IXMLDOMDocument *doc;
5528 IXMLDOMElement *pRoot;
5529 HRESULT hr;
5530 IXMLDOMComment *pComment;
5531 IXMLDOMElement *pElement;
5532 IXMLDOMAttribute *pAttribute;
5533 IXMLDOMNamedNodeMap *pAttribs;
5534 IXMLDOMCDATASection *pCDataSec;
5535 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
5536 IXMLDOMDocumentFragment *pDocFrag = NULL;
5537 IXMLDOMEntityReference *pEntityRef = NULL;
5538 BSTR str;
5539 IXMLDOMNode *pNextChild;
5540 VARIANT v;
5541 LONG len = 0;
5543 doc = create_document(&IID_IXMLDOMDocument);
5544 if (!doc) return;
5546 pNextChild = (void*)0xdeadbeef;
5547 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
5548 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5550 pNextChild = (void*)0xdeadbeef;
5551 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
5552 ok(hr == S_FALSE, "ret %08x\n", hr );
5553 ok(pNextChild == NULL, "pDocChild not NULL\n");
5555 /* test previous Sibling */
5556 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
5557 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5559 pNextChild = (void*)0xdeadbeef;
5560 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
5561 ok(hr == S_FALSE, "ret %08x\n", hr );
5562 ok(pNextChild == NULL, "pNextChild not NULL\n");
5564 /* test get_dataType */
5565 V_VT(&v) = VT_EMPTY;
5566 hr = IXMLDOMDocument_get_dataType(doc, &v);
5567 ok(hr == S_FALSE, "ret %08x\n", hr );
5568 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5569 VariantClear(&v);
5571 /* test implementation */
5572 hr = IXMLDOMDocument_get_implementation(doc, NULL);
5573 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5575 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
5576 ok(hr == S_OK, "ret %08x\n", hr );
5577 if(hr == S_OK)
5579 VARIANT_BOOL hasFeature = VARIANT_TRUE;
5580 BSTR sEmpty = SysAllocStringLen(NULL, 0);
5582 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
5583 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5585 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
5586 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5588 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
5589 ok(hr == S_OK, "ret %08x\n", hr );
5590 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5592 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
5593 ok(hr == S_OK, "ret %08x\n", hr );
5594 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
5596 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
5597 ok(hr == S_OK, "ret %08x\n", hr );
5598 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
5600 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
5601 ok(hr == S_OK, "ret %08x\n", hr );
5602 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5604 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
5605 ok(hr == S_OK, "ret %08x\n", hr );
5606 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5608 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
5609 ok(hr == S_OK, "ret %08x\n", hr );
5610 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5612 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
5613 ok(hr == S_OK, "ret %08x\n", hr );
5614 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
5616 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
5617 ok(hr == S_OK, "ret %08x\n", hr );
5618 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
5620 SysFreeString(sEmpty);
5621 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
5624 pRoot = (IXMLDOMElement*)0x1;
5625 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
5626 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5627 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
5629 pRoot = (IXMLDOMElement*)0x1;
5630 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
5631 ok(hr == E_FAIL, "ret %08x\n", hr );
5632 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
5634 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5635 ok(hr == S_OK, "ret %08x\n", hr );
5636 if(hr == S_OK)
5638 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5639 ok(hr == S_OK, "ret %08x\n", hr );
5640 if(hr == S_OK)
5642 /* Comment */
5643 str = SysAllocString(szComment);
5644 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
5645 SysFreeString(str);
5646 ok(hr == S_OK, "ret %08x\n", hr );
5647 if(hr == S_OK)
5649 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
5650 ok(hr == S_OK, "ret %08x\n", hr );
5652 hr = IXMLDOMComment_get_nodeName(pComment, &str);
5653 ok(hr == S_OK, "ret %08x\n", hr );
5654 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
5655 SysFreeString(str);
5657 hr = IXMLDOMComment_get_xml(pComment, &str);
5658 ok(hr == S_OK, "ret %08x\n", hr );
5659 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
5660 SysFreeString(str);
5662 /* put data Tests */
5663 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
5664 ok(hr == S_OK, "ret %08x\n", hr );
5666 /* get data Tests */
5667 hr = IXMLDOMComment_get_data(pComment, &str);
5668 ok(hr == S_OK, "ret %08x\n", hr );
5669 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
5670 SysFreeString(str);
5672 /* get data Tests */
5673 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
5674 ok(hr == S_OK, "ret %08x\n", hr );
5675 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
5676 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
5677 VariantClear(&v);
5679 /* Confirm XML text is good */
5680 hr = IXMLDOMComment_get_xml(pComment, &str);
5681 ok(hr == S_OK, "ret %08x\n", hr );
5682 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
5683 SysFreeString(str);
5685 /* Confirm we get the put_data Text back */
5686 hr = IXMLDOMComment_get_text(pComment, &str);
5687 ok(hr == S_OK, "ret %08x\n", hr );
5688 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
5689 SysFreeString(str);
5691 /* test length property */
5692 hr = IXMLDOMComment_get_length(pComment, &len);
5693 ok(hr == S_OK, "ret %08x\n", hr );
5694 ok(len == 21, "expected 21 got %d\n", len);
5696 /* test substringData */
5697 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
5698 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5700 /* test substringData - Invalid offset */
5701 str = (BSTR)&szElement;
5702 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
5703 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5704 ok( str == NULL, "incorrect string\n");
5706 /* test substringData - Invalid offset */
5707 str = (BSTR)&szElement;
5708 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
5709 ok(hr == S_FALSE, "ret %08x\n", hr );
5710 ok( str == NULL, "incorrect string\n");
5712 /* test substringData - Invalid size */
5713 str = (BSTR)&szElement;
5714 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
5715 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5716 ok( str == NULL, "incorrect string\n");
5718 /* test substringData - Invalid size */
5719 str = (BSTR)&szElement;
5720 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
5721 ok(hr == S_FALSE, "ret %08x\n", hr );
5722 ok( str == NULL, "incorrect string\n");
5724 /* test substringData - Start of string */
5725 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
5726 ok(hr == S_OK, "ret %08x\n", hr );
5727 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
5728 SysFreeString(str);
5730 /* test substringData - Middle of string */
5731 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
5732 ok(hr == S_OK, "ret %08x\n", hr );
5733 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
5734 SysFreeString(str);
5736 /* test substringData - End of string */
5737 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
5738 ok(hr == S_OK, "ret %08x\n", hr );
5739 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
5740 SysFreeString(str);
5742 /* test appendData */
5743 hr = IXMLDOMComment_appendData(pComment, NULL);
5744 ok(hr == S_OK, "ret %08x\n", hr );
5746 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
5747 ok(hr == S_OK, "ret %08x\n", hr );
5749 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
5750 ok(hr == S_OK, "ret %08x\n", hr );
5752 hr = IXMLDOMComment_get_text(pComment, &str);
5753 ok(hr == S_OK, "ret %08x\n", hr );
5754 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5755 SysFreeString(str);
5757 /* test insertData */
5758 str = SysAllocStringLen(NULL, 0);
5759 hr = IXMLDOMComment_insertData(pComment, -1, str);
5760 ok(hr == S_OK, "ret %08x\n", hr );
5762 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
5763 ok(hr == S_OK, "ret %08x\n", hr );
5765 hr = IXMLDOMComment_insertData(pComment, 1000, str);
5766 ok(hr == S_OK, "ret %08x\n", hr );
5768 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
5769 ok(hr == S_OK, "ret %08x\n", hr );
5771 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
5772 ok(hr == S_OK, "ret %08x\n", hr );
5774 hr = IXMLDOMComment_insertData(pComment, 0, str);
5775 ok(hr == S_OK, "ret %08x\n", hr );
5776 SysFreeString(str);
5778 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
5779 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5781 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
5782 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5784 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
5785 ok(hr == S_OK, "ret %08x\n", hr );
5787 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
5788 ok(hr == S_OK, "ret %08x\n", hr );
5790 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
5791 ok(hr == S_OK, "ret %08x\n", hr );
5793 hr = IXMLDOMComment_get_text(pComment, &str);
5794 ok(hr == S_OK, "ret %08x\n", hr );
5795 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5796 SysFreeString(str);
5798 /* delete data */
5799 /* invalid arguments */
5800 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
5801 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5803 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
5804 ok(hr == S_OK, "ret %08x\n", hr );
5806 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
5807 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5809 hr = IXMLDOMComment_get_length(pComment, &len);
5810 ok(hr == S_OK, "ret %08x\n", hr );
5811 ok(len == 43, "expected 43 got %d\n", len);
5813 hr = IXMLDOMComment_deleteData(pComment, len, 1);
5814 ok(hr == S_OK, "ret %08x\n", hr );
5816 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
5817 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5819 /* delete from start */
5820 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
5821 ok(hr == S_OK, "ret %08x\n", hr );
5823 hr = IXMLDOMComment_get_length(pComment, &len);
5824 ok(hr == S_OK, "ret %08x\n", hr );
5825 ok(len == 38, "expected 38 got %d\n", len);
5827 hr = IXMLDOMComment_get_text(pComment, &str);
5828 ok(hr == S_OK, "ret %08x\n", hr );
5829 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5830 SysFreeString(str);
5832 /* delete from end */
5833 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
5834 ok(hr == S_OK, "ret %08x\n", hr );
5836 hr = IXMLDOMComment_get_length(pComment, &len);
5837 ok(hr == S_OK, "ret %08x\n", hr );
5838 ok(len == 35, "expected 35 got %d\n", len);
5840 hr = IXMLDOMComment_get_text(pComment, &str);
5841 ok(hr == S_OK, "ret %08x\n", hr );
5842 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5843 SysFreeString(str);
5845 /* delete from inside */
5846 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
5847 ok(hr == S_OK, "ret %08x\n", hr );
5849 hr = IXMLDOMComment_get_length(pComment, &len);
5850 ok(hr == S_OK, "ret %08x\n", hr );
5851 ok(len == 2, "expected 2 got %d\n", len);
5853 hr = IXMLDOMComment_get_text(pComment, &str);
5854 ok(hr == S_OK, "ret %08x\n", hr );
5855 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5856 SysFreeString(str);
5858 /* delete whole data ... */
5859 hr = IXMLDOMComment_get_length(pComment, &len);
5860 ok(hr == S_OK, "ret %08x\n", hr );
5862 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5863 ok(hr == S_OK, "ret %08x\n", hr );
5864 /* ... and try again with empty string */
5865 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5866 ok(hr == S_OK, "ret %08x\n", hr );
5868 /* ::replaceData() */
5869 V_VT(&v) = VT_BSTR;
5870 V_BSTR(&v) = SysAllocString(szstr1);
5871 hr = IXMLDOMComment_put_nodeValue(pComment, v);
5872 ok(hr == S_OK, "ret %08x\n", hr );
5873 VariantClear(&v);
5875 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
5876 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5877 hr = IXMLDOMComment_get_text(pComment, &str);
5878 ok(hr == S_OK, "ret %08x\n", hr );
5879 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5880 SysFreeString(str);
5882 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
5883 ok(hr == S_OK, "ret %08x\n", hr );
5884 hr = IXMLDOMComment_get_text(pComment, &str);
5885 ok(hr == S_OK, "ret %08x\n", hr );
5886 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5887 SysFreeString(str);
5889 /* NULL pointer means delete */
5890 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
5891 ok(hr == S_OK, "ret %08x\n", hr );
5892 hr = IXMLDOMComment_get_text(pComment, &str);
5893 ok(hr == S_OK, "ret %08x\n", hr );
5894 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5895 SysFreeString(str);
5897 /* empty string means delete */
5898 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
5899 ok(hr == S_OK, "ret %08x\n", hr );
5900 hr = IXMLDOMComment_get_text(pComment, &str);
5901 ok(hr == S_OK, "ret %08x\n", hr );
5902 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5903 SysFreeString(str);
5905 /* zero count means insert */
5906 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
5907 ok(hr == S_OK, "ret %08x\n", hr );
5908 hr = IXMLDOMComment_get_text(pComment, &str);
5909 ok(hr == S_OK, "ret %08x\n", hr );
5910 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5911 SysFreeString(str);
5913 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
5914 ok(hr == S_OK, "ret %08x\n", hr );
5916 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
5917 ok(hr == S_OK, "ret %08x\n", hr );
5918 hr = IXMLDOMComment_get_text(pComment, &str);
5919 ok(hr == S_OK, "ret %08x\n", hr );
5920 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5921 SysFreeString(str);
5923 /* nonempty string, count greater than its length */
5924 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
5925 ok(hr == S_OK, "ret %08x\n", hr );
5926 hr = IXMLDOMComment_get_text(pComment, &str);
5927 ok(hr == S_OK, "ret %08x\n", hr );
5928 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5929 SysFreeString(str);
5931 /* nonempty string, count less than its length */
5932 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
5933 ok(hr == S_OK, "ret %08x\n", hr );
5934 hr = IXMLDOMComment_get_text(pComment, &str);
5935 ok(hr == S_OK, "ret %08x\n", hr );
5936 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5937 SysFreeString(str);
5939 IXMLDOMComment_Release(pComment);
5942 /* Element */
5943 str = SysAllocString(szElement);
5944 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
5945 SysFreeString(str);
5946 ok(hr == S_OK, "ret %08x\n", hr );
5947 if(hr == S_OK)
5949 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5950 ok(hr == S_OK, "ret %08x\n", hr );
5952 hr = IXMLDOMElement_get_nodeName(pElement, &str);
5953 ok(hr == S_OK, "ret %08x\n", hr );
5954 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
5955 SysFreeString(str);
5957 hr = IXMLDOMElement_get_xml(pElement, &str);
5958 ok(hr == S_OK, "ret %08x\n", hr );
5959 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
5960 SysFreeString(str);
5962 /* Attribute */
5963 pAttribute = (IXMLDOMAttribute*)0x1;
5964 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
5965 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5966 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
5968 pAttribute = (IXMLDOMAttribute*)0x1;
5969 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
5970 ok(hr == E_FAIL, "ret %08x\n", hr );
5971 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
5973 str = SysAllocString(szAttribute);
5974 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
5975 SysFreeString(str);
5976 ok(hr == S_OK, "ret %08x\n", hr );
5977 if(hr == S_OK)
5979 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
5981 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
5982 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5984 pNextChild = (IXMLDOMNode *)0x1;
5985 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
5986 ok(hr == S_FALSE, "ret %08x\n", hr );
5987 ok(pNextChild == NULL, "pNextChild not NULL\n");
5989 /* test Previous Sibling*/
5990 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
5991 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5993 pNextChild = (IXMLDOMNode *)0x1;
5994 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
5995 ok(hr == S_FALSE, "ret %08x\n", hr );
5996 ok(pNextChild == NULL, "pNextChild not NULL\n");
5998 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
5999 ok(hr == E_FAIL, "ret %08x\n", hr );
6000 ok(pNewChild == NULL, "pNewChild not NULL\n");
6002 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
6003 ok(hr == S_OK, "ret %08x\n", hr );
6004 if ( hr == S_OK )
6006 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
6007 ok(hr == S_OK, "ret %08x\n", hr );
6009 IXMLDOMNamedNodeMap_Release(pAttribs);
6012 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6013 ok(hr == S_OK, "ret %08x\n", hr );
6014 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
6015 SysFreeString(str);
6017 /* test nodeName */
6018 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
6019 ok(hr == S_OK, "ret %08x\n", hr );
6020 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
6021 SysFreeString(str);
6023 /* test name property */
6024 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
6025 ok(hr == S_OK, "ret %08x\n", hr );
6026 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
6027 SysFreeString(str);
6029 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
6030 ok(hr == S_OK, "ret %08x\n", hr );
6031 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
6032 SysFreeString(str);
6034 IXMLDOMAttribute_Release(pAttribute);
6036 /* Check Element again with the Add Attribute*/
6037 hr = IXMLDOMElement_get_xml(pElement, &str);
6038 ok(hr == S_OK, "ret %08x\n", hr );
6039 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
6040 SysFreeString(str);
6043 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
6044 ok(hr == S_OK, "ret %08x\n", hr );
6046 hr = IXMLDOMElement_get_xml(pElement, &str);
6047 ok(hr == S_OK, "ret %08x\n", hr );
6048 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
6049 SysFreeString(str);
6051 /* Test for reversible escaping */
6052 str = SysAllocString( szStrangeChars );
6053 hr = IXMLDOMElement_put_text(pElement, str);
6054 ok(hr == S_OK, "ret %08x\n", hr );
6055 SysFreeString( str );
6057 hr = IXMLDOMElement_get_xml(pElement, &str);
6058 ok(hr == S_OK, "ret %08x\n", hr );
6059 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
6060 SysFreeString(str);
6062 hr = IXMLDOMElement_get_text(pElement, &str);
6063 ok(hr == S_OK, "ret %08x\n", hr );
6064 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
6065 SysFreeString(str);
6067 IXMLDOMElement_Release(pElement);
6070 /* CData Section */
6071 str = SysAllocString(szCData);
6072 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
6073 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6075 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
6076 SysFreeString(str);
6077 ok(hr == S_OK, "ret %08x\n", hr );
6078 if(hr == S_OK)
6080 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
6081 VARIANT var;
6083 VariantInit(&var);
6085 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
6086 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
6088 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
6089 ok(hr == S_OK, "ret %08x\n", hr );
6091 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
6092 ok(hr == S_OK, "ret %08x\n", hr );
6093 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
6094 SysFreeString(str);
6096 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6097 ok(hr == S_OK, "ret %08x\n", hr );
6098 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
6099 SysFreeString(str);
6101 /* test lastChild */
6102 pNextChild = (IXMLDOMNode*)0x1;
6103 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
6104 ok(hr == S_FALSE, "ret %08x\n", hr );
6105 ok(pNextChild == NULL, "pNextChild not NULL\n");
6107 /* put data Tests */
6108 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
6109 ok(hr == S_OK, "ret %08x\n", hr );
6111 /* Confirm XML text is good */
6112 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
6113 ok(hr == S_OK, "ret %08x\n", hr );
6114 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
6115 SysFreeString(str);
6117 /* Confirm we get the put_data Text back */
6118 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6119 ok(hr == S_OK, "ret %08x\n", hr );
6120 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6121 SysFreeString(str);
6123 /* test length property */
6124 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6125 ok(hr == S_OK, "ret %08x\n", hr );
6126 ok(len == 21, "expected 21 got %d\n", len);
6128 /* test get nodeValue */
6129 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
6130 ok(hr == S_OK, "ret %08x\n", hr );
6131 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
6132 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6133 VariantClear(&var);
6135 /* test get data */
6136 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
6137 ok(hr == S_OK, "ret %08x\n", hr );
6138 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
6139 SysFreeString(str);
6141 /* test substringData */
6142 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
6143 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6145 /* test substringData - Invalid offset */
6146 str = (BSTR)&szElement;
6147 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
6148 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6149 ok( str == NULL, "incorrect string\n");
6151 /* test substringData - Invalid offset */
6152 str = (BSTR)&szElement;
6153 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
6154 ok(hr == S_FALSE, "ret %08x\n", hr );
6155 ok( str == NULL, "incorrect string\n");
6157 /* test substringData - Invalid size */
6158 str = (BSTR)&szElement;
6159 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
6160 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6161 ok( str == NULL, "incorrect string\n");
6163 /* test substringData - Invalid size */
6164 str = (BSTR)&szElement;
6165 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
6166 ok(hr == S_FALSE, "ret %08x\n", hr );
6167 ok( str == NULL, "incorrect string\n");
6169 /* test substringData - Start of string */
6170 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
6171 ok(hr == S_OK, "ret %08x\n", hr );
6172 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
6173 SysFreeString(str);
6175 /* test substringData - Middle of string */
6176 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
6177 ok(hr == S_OK, "ret %08x\n", hr );
6178 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
6179 SysFreeString(str);
6181 /* test substringData - End of string */
6182 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
6183 ok(hr == S_OK, "ret %08x\n", hr );
6184 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
6185 SysFreeString(str);
6187 /* test appendData */
6188 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
6189 ok(hr == S_OK, "ret %08x\n", hr );
6191 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
6192 ok(hr == S_OK, "ret %08x\n", hr );
6194 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
6195 ok(hr == S_OK, "ret %08x\n", hr );
6197 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6198 ok(hr == S_OK, "ret %08x\n", hr );
6199 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6200 SysFreeString(str);
6202 /* test insertData */
6203 str = SysAllocStringLen(NULL, 0);
6204 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
6205 ok(hr == S_OK, "ret %08x\n", hr );
6207 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
6208 ok(hr == S_OK, "ret %08x\n", hr );
6210 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
6211 ok(hr == S_OK, "ret %08x\n", hr );
6213 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
6214 ok(hr == S_OK, "ret %08x\n", hr );
6216 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
6217 ok(hr == S_OK, "ret %08x\n", hr );
6219 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
6220 ok(hr == S_OK, "ret %08x\n", hr );
6221 SysFreeString(str);
6223 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
6224 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6226 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
6227 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6229 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
6230 ok(hr == S_OK, "ret %08x\n", hr );
6232 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
6233 ok(hr == S_OK, "ret %08x\n", hr );
6235 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
6236 ok(hr == S_OK, "ret %08x\n", hr );
6238 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6239 ok(hr == S_OK, "ret %08x\n", hr );
6240 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6241 SysFreeString(str);
6243 /* delete data */
6244 /* invalid arguments */
6245 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
6246 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6248 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
6249 ok(hr == S_OK, "ret %08x\n", hr );
6251 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
6252 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6254 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6255 ok(hr == S_OK, "ret %08x\n", hr );
6256 ok(len == 43, "expected 43 got %d\n", len);
6258 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
6259 ok(hr == S_OK, "ret %08x\n", hr );
6261 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
6262 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6264 /* delete from start */
6265 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
6266 ok(hr == S_OK, "ret %08x\n", hr );
6268 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6269 ok(hr == S_OK, "ret %08x\n", hr );
6270 ok(len == 38, "expected 38 got %d\n", len);
6272 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6273 ok(hr == S_OK, "ret %08x\n", hr );
6274 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6275 SysFreeString(str);
6277 /* delete from end */
6278 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
6279 ok(hr == S_OK, "ret %08x\n", hr );
6281 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6282 ok(hr == S_OK, "ret %08x\n", hr );
6283 ok(len == 35, "expected 35 got %d\n", len);
6285 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6286 ok(hr == S_OK, "ret %08x\n", hr );
6287 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6288 SysFreeString(str);
6290 /* delete from inside */
6291 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
6292 ok(hr == S_OK, "ret %08x\n", hr );
6294 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6295 ok(hr == S_OK, "ret %08x\n", hr );
6296 ok(len == 2, "expected 2 got %d\n", len);
6298 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6299 ok(hr == S_OK, "ret %08x\n", hr );
6300 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6301 SysFreeString(str);
6303 /* delete whole data ... */
6304 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
6305 ok(hr == S_OK, "ret %08x\n", hr );
6307 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6308 ok(hr == S_OK, "ret %08x\n", hr );
6310 /* ... and try again with empty string */
6311 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
6312 ok(hr == S_OK, "ret %08x\n", hr );
6314 /* ::replaceData() */
6315 V_VT(&v) = VT_BSTR;
6316 V_BSTR(&v) = SysAllocString(szstr1);
6317 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
6318 ok(hr == S_OK, "ret %08x\n", hr );
6319 VariantClear(&v);
6321 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
6322 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6323 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6324 ok(hr == S_OK, "ret %08x\n", hr );
6325 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6326 SysFreeString(str);
6328 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
6329 ok(hr == S_OK, "ret %08x\n", hr );
6330 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6331 ok(hr == S_OK, "ret %08x\n", hr );
6332 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6333 SysFreeString(str);
6335 /* NULL pointer means delete */
6336 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
6337 ok(hr == S_OK, "ret %08x\n", hr );
6338 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6339 ok(hr == S_OK, "ret %08x\n", hr );
6340 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6341 SysFreeString(str);
6343 /* empty string means delete */
6344 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
6345 ok(hr == S_OK, "ret %08x\n", hr );
6346 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6347 ok(hr == S_OK, "ret %08x\n", hr );
6348 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6349 SysFreeString(str);
6351 /* zero count means insert */
6352 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
6353 ok(hr == S_OK, "ret %08x\n", hr );
6354 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6355 ok(hr == S_OK, "ret %08x\n", hr );
6356 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6357 SysFreeString(str);
6359 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
6360 ok(hr == S_OK, "ret %08x\n", hr );
6362 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
6363 ok(hr == S_OK, "ret %08x\n", hr );
6364 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6365 ok(hr == S_OK, "ret %08x\n", hr );
6366 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6367 SysFreeString(str);
6369 /* nonempty string, count greater than its length */
6370 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
6371 ok(hr == S_OK, "ret %08x\n", hr );
6372 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6373 ok(hr == S_OK, "ret %08x\n", hr );
6374 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6375 SysFreeString(str);
6377 /* nonempty string, count less than its length */
6378 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
6379 ok(hr == S_OK, "ret %08x\n", hr );
6380 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
6381 ok(hr == S_OK, "ret %08x\n", hr );
6382 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
6383 SysFreeString(str);
6385 IXMLDOMCDATASection_Release(pCDataSec);
6388 /* Document Fragments */
6389 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
6390 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6392 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
6393 ok(hr == S_OK, "ret %08x\n", hr );
6394 if(hr == S_OK)
6396 IXMLDOMNode *node;
6398 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
6399 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6401 node = (IXMLDOMNode *)0x1;
6402 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
6403 ok(hr == S_FALSE, "ret %08x\n", hr );
6404 ok(node == NULL, "expected NULL, got %p\n", node);
6406 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
6407 ok(hr == S_OK, "ret %08x\n", hr );
6409 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
6410 ok(hr == S_OK, "ret %08x\n", hr );
6411 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
6412 SysFreeString(str);
6414 /* test next Sibling*/
6415 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
6416 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6418 node = (IXMLDOMNode *)0x1;
6419 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
6420 ok(hr == S_FALSE, "ret %08x\n", hr );
6421 ok(node == NULL, "next sibling not NULL\n");
6423 /* test Previous Sibling*/
6424 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
6425 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6427 node = (IXMLDOMNode *)0x1;
6428 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
6429 ok(hr == S_FALSE, "ret %08x\n", hr );
6430 ok(node == NULL, "previous sibling not NULL\n");
6432 IXMLDOMDocumentFragment_Release(pDocFrag);
6435 /* Entity References */
6436 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
6437 ok(hr == E_FAIL, "ret %08x\n", hr );
6438 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
6439 ok(hr == E_FAIL, "ret %08x\n", hr );
6441 str = SysAllocString(szEntityRef);
6442 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
6443 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6445 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
6446 SysFreeString(str);
6447 ok(hr == S_OK, "ret %08x\n", hr );
6448 if(hr == S_OK)
6450 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
6451 ok(hr == S_OK, "ret %08x\n", hr );
6453 /* test get_xml*/
6454 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
6455 ok(hr == S_OK, "ret %08x\n", hr );
6456 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
6457 SysFreeString(str);
6459 IXMLDOMEntityReference_Release(pEntityRef);
6462 IXMLDOMElement_Release( pRoot );
6466 IXMLDOMDocument_Release(doc);
6468 free_bstrs();
6471 static void test_nodeTypeTests( void )
6473 IXMLDOMDocument *doc = NULL;
6474 IXMLDOMElement *pRoot;
6475 IXMLDOMElement *pElement;
6476 HRESULT hr;
6478 doc = create_document(&IID_IXMLDOMDocument);
6479 if (!doc) return;
6481 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
6482 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6484 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
6485 ok(hr == S_OK, "ret %08x\n", hr );
6486 if(hr == S_OK)
6488 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
6489 ok(hr == S_OK, "ret %08x\n", hr );
6490 if(hr == S_OK)
6492 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
6493 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6495 /* Invalid Value */
6496 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
6497 ok(hr == E_FAIL, "ret %08x\n", hr );
6499 /* NOTE:
6500 * The name passed into put_dataType is case-insensitive. So many of the names
6501 * have been changed to reflect this.
6503 /* Boolean */
6504 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
6505 ok(hr == S_OK, "ret %08x\n", hr );
6506 if(hr == S_OK)
6508 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6510 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
6511 ok(hr == S_OK, "ret %08x\n", hr );
6513 IXMLDOMElement_Release(pElement);
6516 /* String */
6517 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
6518 ok(hr == S_OK, "ret %08x\n", hr );
6519 if(hr == S_OK)
6521 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6523 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
6524 ok(hr == S_OK, "ret %08x\n", hr );
6526 IXMLDOMElement_Release(pElement);
6529 /* Number */
6530 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
6531 ok(hr == S_OK, "ret %08x\n", hr );
6532 if(hr == S_OK)
6534 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6536 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
6537 ok(hr == S_OK, "ret %08x\n", hr );
6539 IXMLDOMElement_Release(pElement);
6542 /* Int */
6543 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
6544 ok(hr == S_OK, "ret %08x\n", hr );
6545 if(hr == S_OK)
6547 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6549 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
6550 ok(hr == S_OK, "ret %08x\n", hr );
6552 IXMLDOMElement_Release(pElement);
6555 /* Fixed */
6556 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
6557 ok(hr == S_OK, "ret %08x\n", hr );
6558 if(hr == S_OK)
6560 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6562 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
6563 ok(hr == S_OK, "ret %08x\n", hr );
6565 IXMLDOMElement_Release(pElement);
6568 /* DateTime */
6569 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
6570 ok(hr == S_OK, "ret %08x\n", hr );
6571 if(hr == S_OK)
6573 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6575 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
6576 ok(hr == S_OK, "ret %08x\n", hr );
6578 IXMLDOMElement_Release(pElement);
6581 /* DateTime TZ */
6582 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
6583 ok(hr == S_OK, "ret %08x\n", hr );
6584 if(hr == S_OK)
6586 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6588 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
6589 ok(hr == S_OK, "ret %08x\n", hr );
6591 IXMLDOMElement_Release(pElement);
6594 /* Date */
6595 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
6596 ok(hr == S_OK, "ret %08x\n", hr );
6597 if(hr == S_OK)
6599 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6601 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
6602 ok(hr == S_OK, "ret %08x\n", hr );
6604 IXMLDOMElement_Release(pElement);
6607 /* Time */
6608 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
6609 ok(hr == S_OK, "ret %08x\n", hr );
6610 if(hr == S_OK)
6612 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6614 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
6615 ok(hr == S_OK, "ret %08x\n", hr );
6617 IXMLDOMElement_Release(pElement);
6620 /* Time.tz */
6621 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
6622 ok(hr == S_OK, "ret %08x\n", hr );
6623 if(hr == S_OK)
6625 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6627 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
6628 ok(hr == S_OK, "ret %08x\n", hr );
6630 IXMLDOMElement_Release(pElement);
6633 /* I1 */
6634 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
6635 ok(hr == S_OK, "ret %08x\n", hr );
6636 if(hr == S_OK)
6638 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6640 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
6641 ok(hr == S_OK, "ret %08x\n", hr );
6643 IXMLDOMElement_Release(pElement);
6646 /* I2 */
6647 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
6648 ok(hr == S_OK, "ret %08x\n", hr );
6649 if(hr == S_OK)
6651 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6653 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
6654 ok(hr == S_OK, "ret %08x\n", hr );
6656 IXMLDOMElement_Release(pElement);
6659 /* I4 */
6660 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
6661 ok(hr == S_OK, "ret %08x\n", hr );
6662 if(hr == S_OK)
6664 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6666 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
6667 ok(hr == S_OK, "ret %08x\n", hr );
6669 IXMLDOMElement_Release(pElement);
6672 /* UI1 */
6673 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
6674 ok(hr == S_OK, "ret %08x\n", hr );
6675 if(hr == S_OK)
6677 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6679 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
6680 ok(hr == S_OK, "ret %08x\n", hr );
6682 IXMLDOMElement_Release(pElement);
6685 /* UI2 */
6686 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
6687 ok(hr == S_OK, "ret %08x\n", hr );
6688 if(hr == S_OK)
6690 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6692 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
6693 ok(hr == S_OK, "ret %08x\n", hr );
6695 IXMLDOMElement_Release(pElement);
6698 /* UI4 */
6699 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
6700 ok(hr == S_OK, "ret %08x\n", hr );
6701 if(hr == S_OK)
6703 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6705 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
6706 ok(hr == S_OK, "ret %08x\n", hr );
6708 IXMLDOMElement_Release(pElement);
6711 /* r4 */
6712 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
6713 ok(hr == S_OK, "ret %08x\n", hr );
6714 if(hr == S_OK)
6716 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6718 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
6719 ok(hr == S_OK, "ret %08x\n", hr );
6721 IXMLDOMElement_Release(pElement);
6724 /* r8 */
6725 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
6726 ok(hr == S_OK, "ret %08x\n", hr );
6727 if(hr == S_OK)
6729 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6731 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
6732 ok(hr == S_OK, "ret %08x\n", hr );
6734 IXMLDOMElement_Release(pElement);
6737 /* float */
6738 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
6739 ok(hr == S_OK, "ret %08x\n", hr );
6740 if(hr == S_OK)
6742 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6744 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
6745 ok(hr == S_OK, "ret %08x\n", hr );
6747 IXMLDOMElement_Release(pElement);
6750 /* uuid */
6751 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
6752 ok(hr == S_OK, "ret %08x\n", hr );
6753 if(hr == S_OK)
6755 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6757 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
6758 ok(hr == S_OK, "ret %08x\n", hr );
6760 IXMLDOMElement_Release(pElement);
6763 /* bin.hex */
6764 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
6765 ok(hr == S_OK, "ret %08x\n", hr );
6766 if(hr == S_OK)
6768 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6770 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
6771 ok(hr == S_OK, "ret %08x\n", hr );
6773 IXMLDOMElement_Release(pElement);
6776 /* bin.base64 */
6777 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
6778 ok(hr == S_OK, "ret %08x\n", hr );
6779 if(hr == S_OK)
6781 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6783 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
6784 ok(hr == S_OK, "ret %08x\n", hr );
6786 IXMLDOMElement_Release(pElement);
6789 /* Check changing types */
6790 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
6791 ok(hr == S_OK, "ret %08x\n", hr );
6792 if(hr == S_OK)
6794 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
6796 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
6797 ok(hr == S_OK, "ret %08x\n", hr );
6799 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
6800 ok(hr == S_OK, "ret %08x\n", hr );
6802 IXMLDOMElement_Release(pElement);
6805 IXMLDOMElement_Release(pRoot);
6809 IXMLDOMDocument_Release(doc);
6811 free_bstrs();
6814 static void test_save(void)
6816 IXMLDOMDocument *doc, *doc2;
6817 IXMLDOMElement *root;
6818 VARIANT file, vDoc;
6819 BSTR sOrig, sNew, filename;
6820 char buffer[100];
6821 DWORD read = 0;
6822 HANDLE hfile;
6823 HRESULT hr;
6825 doc = create_document(&IID_IXMLDOMDocument);
6826 if (!doc) return;
6828 doc2 = create_document(&IID_IXMLDOMDocument);
6829 if (!doc2)
6831 IXMLDOMDocument_Release(doc);
6832 return;
6835 /* save to IXMLDOMDocument */
6836 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
6837 EXPECT_HR(hr, S_OK);
6839 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
6840 EXPECT_HR(hr, S_OK);
6842 V_VT(&vDoc) = VT_UNKNOWN;
6843 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
6845 hr = IXMLDOMDocument_save(doc, vDoc);
6846 EXPECT_HR(hr, S_OK);
6848 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
6849 EXPECT_HR(hr, S_OK);
6851 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
6852 EXPECT_HR(hr, S_OK);
6854 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as original\n");
6856 SysFreeString(sOrig);
6857 SysFreeString(sNew);
6859 IXMLDOMElement_Release(root);
6860 IXMLDOMDocument_Release(doc2);
6862 /* save to path */
6863 V_VT(&file) = VT_BSTR;
6864 V_BSTR(&file) = _bstr_("test.xml");
6866 hr = IXMLDOMDocument_save(doc, file);
6867 EXPECT_HR(hr, S_OK);
6869 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
6870 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
6871 if(hfile == INVALID_HANDLE_VALUE) return;
6873 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
6874 ok(read != 0, "could not read file\n");
6875 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
6877 CloseHandle(hfile);
6878 DeleteFile("test.xml");
6880 /* save to path VT_BSTR | VT_BYREF */
6881 filename = _bstr_("test.xml");
6882 V_VT(&file) = VT_BSTR | VT_BYREF;
6883 V_BSTRREF(&file) = &filename;
6885 hr = IXMLDOMDocument_save(doc, file);
6886 EXPECT_HR(hr, S_OK);
6888 IXMLDOMDocument_Release(doc);
6890 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
6891 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
6892 if(hfile == INVALID_HANDLE_VALUE) return;
6894 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
6895 ok(read != 0, "could not read file\n");
6896 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
6898 CloseHandle(hfile);
6899 DeleteFile("test.xml");
6900 free_bstrs();
6903 static void test_testTransforms(void)
6905 IXMLDOMDocument *doc, *docSS;
6906 IXMLDOMNode *pNode;
6907 VARIANT_BOOL bSucc;
6909 HRESULT hr;
6911 doc = create_document(&IID_IXMLDOMDocument);
6912 if (!doc) return;
6914 docSS = create_document(&IID_IXMLDOMDocument);
6915 if (!docSS)
6917 IXMLDOMDocument_Release(doc);
6918 return;
6921 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
6922 ok(hr == S_OK, "ret %08x\n", hr );
6924 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
6925 ok(hr == S_OK, "ret %08x\n", hr );
6927 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
6928 ok(hr == S_OK, "ret %08x\n", hr );
6929 if(hr == S_OK)
6931 BSTR bOut;
6933 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
6934 ok(hr == S_OK, "ret %08x\n", hr );
6935 if(hr == S_OK)
6937 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
6938 SysFreeString(bOut);
6941 IXMLDOMNode_Release(pNode);
6944 IXMLDOMDocument_Release(docSS);
6945 IXMLDOMDocument_Release(doc);
6947 free_bstrs();
6950 static void test_Namespaces(void)
6952 static const CHAR szNamespacesXML[] =
6953 "<?xml version=\"1.0\"?>\n"
6954 "<XMI xmi.version=\"1.1\" xmlns:Model=\"http://omg.org/mof.Model/1.3\">"
6955 " <XMI.content>"
6956 " <Model:Package name=\"WinePackage\" />"
6957 " </XMI.content>"
6958 "</XMI>";
6960 IXMLDOMDocument *doc;
6961 IXMLDOMElement *elem;
6962 IXMLDOMNode *node;
6963 IXMLDOMNode *pNode2 = NULL;
6964 VARIANT_BOOL bSucc;
6965 VARIANT var;
6966 HRESULT hr;
6967 BSTR str;
6969 doc = create_document(&IID_IXMLDOMDocument);
6970 if (!doc) return;
6972 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
6973 ok(hr == S_OK, "ret %08x\n", hr );
6974 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6976 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("//XMI.content"), &node );
6977 ok(hr == S_OK, "ret %08x\n", hr );
6978 if(hr == S_OK)
6980 hr = IXMLDOMNode_get_firstChild( node, &pNode2 );
6981 ok( hr == S_OK, "ret %08x\n", hr );
6982 ok( pNode2 != NULL, "pNode2 == NULL\n");
6984 /* Test get_prefix */
6985 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
6986 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
6987 /* NOTE: Need to test that arg2 gets cleared on Error. */
6989 hr = IXMLDOMNode_get_prefix(pNode2, &str);
6990 ok( hr == S_OK, "ret %08x\n", hr );
6991 ok( !lstrcmpW( str, _bstr_("Model")), "incorrect prefix string\n");
6992 SysFreeString(str);
6994 hr = IXMLDOMNode_get_nodeName(pNode2, &str);
6995 ok( hr == S_OK, "ret %08x\n", hr );
6996 todo_wine ok( !lstrcmpW( str, _bstr_("Model:Package")), "incorrect nodeName string\n");
6997 SysFreeString(str);
6999 /* Test get_namespaceURI */
7000 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
7001 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
7002 /* NOTE: Need to test that arg2 gets cleared on Error. */
7004 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
7005 ok( hr == S_OK, "ret %08x\n", hr );
7006 ok( !lstrcmpW( str, _bstr_("http://omg.org/mof.Model/1.3")), "incorrect namespaceURI string\n");
7007 SysFreeString(str);
7009 IXMLDOMNode_Release(pNode2);
7010 IXMLDOMNode_Release(node);
7013 IXMLDOMDocument_Release(doc);
7015 /* create on element and try to alter namespace after that */
7016 doc = create_document(&IID_IXMLDOMDocument);
7017 if (!doc) return;
7019 V_VT(&var) = VT_I2;
7020 V_I2(&var) = NODE_ELEMENT;
7022 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("ns:elem"), _bstr_("ns/uri"), &node);
7023 EXPECT_HR(hr, S_OK);
7025 hr = IXMLDOMDocument_appendChild(doc, node, NULL);
7026 EXPECT_HR(hr, S_OK);
7028 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7029 EXPECT_HR(hr, S_OK);
7031 V_VT(&var) = VT_BSTR;
7032 V_BSTR(&var) = _bstr_("ns/uri2");
7034 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
7035 EXPECT_HR(hr, E_INVALIDARG);
7037 V_VT(&var) = VT_BSTR;
7038 V_BSTR(&var) = _bstr_("ns/uri");
7040 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
7041 EXPECT_HR(hr, S_OK);
7043 hr = IXMLDOMElement_get_xml(elem, &str);
7044 EXPECT_HR(hr, S_OK);
7045 ok(!lstrcmpW(str, _bstr_("<ns:elem xmlns:ns=\"ns/uri\"/>")), "got element %s\n", wine_dbgstr_w(str));
7046 SysFreeString(str);
7048 IXMLDOMElement_Release(elem);
7049 IXMLDOMDocument_Release(doc);
7051 /* create on element and try to alter namespace after that */
7052 doc = create_document_version(60, &IID_IXMLDOMDocument);
7053 if (!doc) return;
7055 V_VT(&var) = VT_I2;
7056 V_I2(&var) = NODE_ELEMENT;
7058 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("ns:elem"), _bstr_("ns/uri"), &node);
7059 EXPECT_HR(hr, S_OK);
7061 hr = IXMLDOMDocument_appendChild(doc, node, NULL);
7062 EXPECT_HR(hr, S_OK);
7064 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7065 EXPECT_HR(hr, S_OK);
7067 /* try same prefix, different uri */
7068 V_VT(&var) = VT_BSTR;
7069 V_BSTR(&var) = _bstr_("ns/uri2");
7071 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
7072 EXPECT_HR(hr, E_INVALIDARG);
7074 /* try same prefix and uri */
7075 V_VT(&var) = VT_BSTR;
7076 V_BSTR(&var) = _bstr_("ns/uri");
7078 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
7079 EXPECT_HR(hr, S_OK);
7081 hr = IXMLDOMElement_get_xml(elem, &str);
7082 EXPECT_HR(hr, S_OK);
7083 ok(!lstrcmpW(str, _bstr_("<ns:elem xmlns:ns=\"ns/uri\"/>")), "got element %s\n", wine_dbgstr_w(str));
7084 SysFreeString(str);
7086 IXMLDOMElement_Release(elem);
7087 IXMLDOMDocument_Release(doc);
7089 free_bstrs();
7092 static void test_FormattingXML(void)
7094 IXMLDOMDocument *doc;
7095 IXMLDOMElement *pElement;
7096 VARIANT_BOOL bSucc;
7097 HRESULT hr;
7098 BSTR str;
7099 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
7100 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
7102 doc = create_document(&IID_IXMLDOMDocument);
7103 if (!doc) return;
7105 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
7106 ok(hr == S_OK, "ret %08x\n", hr );
7107 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7109 if(bSucc == VARIANT_TRUE)
7111 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
7112 ok(hr == S_OK, "ret %08x\n", hr );
7113 if(hr == S_OK)
7115 hr = IXMLDOMElement_get_xml(pElement, &str);
7116 ok(hr == S_OK, "ret %08x\n", hr );
7117 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
7118 SysFreeString(str);
7120 IXMLDOMElement_Release(pElement);
7124 IXMLDOMDocument_Release(doc);
7126 free_bstrs();
7129 typedef struct _nodetypedvalue_t {
7130 const char *name;
7131 VARTYPE type;
7132 const char *value; /* value in string format */
7133 } nodetypedvalue_t;
7135 static const nodetypedvalue_t get_nodetypedvalue[] = {
7136 { "root/string", VT_BSTR, "Wine" },
7137 { "root/string2", VT_BSTR, "String" },
7138 { "root/number", VT_BSTR, "12.44" },
7139 { "root/number2", VT_BSTR, "-3.71e3" },
7140 { "root/int", VT_I4, "-13" },
7141 { "root/fixed", VT_CY, "7322.9371" },
7142 { "root/bool", VT_BOOL, "-1" },
7143 { "root/datetime", VT_DATE, "40135.14" },
7144 { "root/datetimetz",VT_DATE, "37813.59" },
7145 { "root/date", VT_DATE, "665413" },
7146 { "root/time", VT_DATE, "0.5813889" },
7147 { "root/timetz", VT_DATE, "1.112512" },
7148 { "root/i1", VT_I1, "-13" },
7149 { "root/i2", VT_I2, "31915" },
7150 { "root/i4", VT_I4, "-312232" },
7151 { "root/ui1", VT_UI1, "123" },
7152 { "root/ui2", VT_UI2, "48282" },
7153 { "root/ui4", VT_UI4, "949281" },
7154 { "root/r4", VT_R4, "213124" },
7155 { "root/r8", VT_R8, "0.412" },
7156 { "root/float", VT_R8, "41221.421" },
7157 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
7158 { "root/binbase64", VT_ARRAY|VT_UI1, "base64 test" },
7159 { "root/binbase64_1", VT_ARRAY|VT_UI1, "base64 test" },
7160 { "root/binbase64_2", VT_ARRAY|VT_UI1, "base64 test" },
7161 { 0 }
7164 static void test_nodeTypedValue(void)
7166 const nodetypedvalue_t *entry = get_nodetypedvalue;
7167 IXMLDOMDocumentType *doctype, *doctype2;
7168 IXMLDOMProcessingInstruction *pi;
7169 IXMLDOMDocumentFragment *frag;
7170 IXMLDOMDocument *doc, *doc2;
7171 IXMLDOMCDATASection *cdata;
7172 IXMLDOMComment *comment;
7173 IXMLDOMNode *node;
7174 VARIANT_BOOL b;
7175 VARIANT value;
7176 HRESULT hr;
7178 doc = create_document(&IID_IXMLDOMDocument);
7179 if (!doc) return;
7181 b = VARIANT_FALSE;
7182 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
7183 ok(hr == S_OK, "ret %08x\n", hr );
7184 ok(b == VARIANT_TRUE, "got %d\n", b);
7186 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
7187 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7189 V_VT(&value) = VT_BSTR;
7190 V_BSTR(&value) = NULL;
7191 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
7192 ok(hr == S_FALSE, "ret %08x\n", hr );
7193 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7195 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
7196 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7198 V_VT(&value) = VT_EMPTY;
7199 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
7200 ok(hr == S_FALSE, "ret %08x\n", hr );
7201 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7203 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
7204 ok(hr == S_OK, "ret %08x\n", hr );
7206 V_VT(&value) = VT_BSTR;
7207 V_BSTR(&value) = NULL;
7208 hr = IXMLDOMNode_get_nodeValue(node, &value);
7209 ok(hr == S_FALSE, "ret %08x\n", hr );
7210 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
7212 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
7213 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
7215 IXMLDOMNode_Release(node);
7217 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
7218 ok(hr == S_OK, "ret %08x\n", hr );
7220 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
7222 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7223 ok(hr == S_OK, "ret %08x\n", hr );
7224 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
7225 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
7226 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
7227 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
7228 VariantClear(&value);
7229 IXMLDOMNode_Release(node);
7232 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("foo"), _bstr_("value"), &pi);
7233 ok(hr == S_OK, "ret %08x\n", hr );
7235 V_VT(&value) = VT_NULL;
7236 V_BSTR(&value) = (void*)0xdeadbeef;
7237 hr = IXMLDOMProcessingInstruction_get_nodeTypedValue(pi, &value);
7238 ok(hr == S_OK, "ret %08x\n", hr );
7239 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7240 ok(!lstrcmpW(V_BSTR(&value), _bstr_("value")), "got wrong value\n");
7241 IXMLDOMProcessingInstruction_Release(pi);
7242 VariantClear(&value);
7245 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("[1]*2=3; &gee that's not right!"), &cdata);
7246 ok(hr == S_OK, "ret %08x\n", hr );
7248 V_VT(&value) = VT_NULL;
7249 V_BSTR(&value) = (void*)0xdeadbeef;
7250 hr = IXMLDOMCDATASection_get_nodeTypedValue(cdata, &value);
7251 ok(hr == S_OK, "ret %08x\n", hr );
7252 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7253 ok(!lstrcmpW(V_BSTR(&value), _bstr_("[1]*2=3; &gee that's not right!")), "got wrong value\n");
7254 IXMLDOMCDATASection_Release(cdata);
7255 VariantClear(&value);
7258 hr = IXMLDOMDocument_createComment(doc, _bstr_("comment"), &comment);
7259 ok(hr == S_OK, "ret %08x\n", hr );
7261 V_VT(&value) = VT_NULL;
7262 V_BSTR(&value) = (void*)0xdeadbeef;
7263 hr = IXMLDOMComment_get_nodeTypedValue(comment, &value);
7264 ok(hr == S_OK, "ret %08x\n", hr );
7265 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
7266 ok(!lstrcmpW(V_BSTR(&value), _bstr_("comment")), "got wrong value\n");
7267 IXMLDOMComment_Release(comment);
7268 VariantClear(&value);
7271 hr = IXMLDOMDocument_createDocumentFragment(doc, &frag);
7272 ok(hr == S_OK, "ret %08x\n", hr );
7274 V_VT(&value) = VT_EMPTY;
7275 hr = IXMLDOMDocumentFragment_get_nodeTypedValue(frag, &value);
7276 ok(hr == S_FALSE, "ret %08x\n", hr );
7277 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7278 IXMLDOMDocumentFragment_Release(frag);
7281 doc2 = create_document(&IID_IXMLDOMDocument);
7283 b = VARIANT_FALSE;
7284 hr = IXMLDOMDocument_loadXML(doc2, _bstr_(szEmailXML), &b);
7285 ok(hr == S_OK, "ret %08x\n", hr );
7286 ok(b == VARIANT_TRUE, "got %d\n", b);
7288 EXPECT_REF(doc2, 1);
7290 hr = IXMLDOMDocument_get_doctype(doc2, &doctype);
7291 ok(hr == S_OK, "ret %08x\n", hr );
7293 EXPECT_REF(doc2, 1);
7294 todo_wine EXPECT_REF(doctype, 2);
7297 V_VT(&value) = VT_EMPTY;
7298 hr = IXMLDOMDocumentType_get_nodeTypedValue(doctype, &value);
7299 ok(hr == S_FALSE, "ret %08x\n", hr );
7300 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
7303 hr = IXMLDOMDocument_get_doctype(doc2, &doctype2);
7304 ok(hr == S_OK, "ret %08x\n", hr );
7305 ok(doctype != doctype2, "got %p, was %p\n", doctype2, doctype);
7307 IXMLDOMDocumentType_Release(doctype2);
7308 IXMLDOMDocumentType_Release(doctype);
7310 IXMLDOMDocument_Release(doc2);
7312 while (entry->name)
7314 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
7315 ok(hr == S_OK, "ret %08x\n", hr );
7317 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
7318 ok(hr == S_OK, "ret %08x\n", hr );
7319 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
7321 if (entry->type == (VT_ARRAY|VT_UI1))
7323 ok(V_ARRAY(&value)->rgsabound[0].cElements == strlen(entry->value),
7324 "incorrect array size %d\n", V_ARRAY(&value)->rgsabound[0].cElements);
7327 if (entry->type != VT_BSTR)
7329 if (entry->type == VT_DATE ||
7330 entry->type == VT_R8 ||
7331 entry->type == VT_CY)
7333 if (entry->type == VT_DATE)
7335 hr = VariantChangeType(&value, &value, 0, VT_R4);
7336 ok(hr == S_OK, "ret %08x\n", hr );
7338 hr = VariantChangeTypeEx(&value, &value,
7339 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
7340 VARIANT_NOUSEROVERRIDE, VT_BSTR);
7341 ok(hr == S_OK, "ret %08x\n", hr );
7343 else
7345 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
7346 ok(hr == S_OK, "ret %08x\n", hr );
7349 /* for byte array from VT_ARRAY|VT_UI1 it's not a WCHAR buffer */
7350 if (entry->type == (VT_ARRAY|VT_UI1))
7352 ok(!memcmp( V_BSTR(&value), entry->value, strlen(entry->value)),
7353 "expected %s\n", entry->value);
7355 else
7356 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7357 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7359 else
7360 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
7361 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
7363 VariantClear( &value );
7364 IXMLDOMNode_Release(node);
7366 entry++;
7369 IXMLDOMDocument_Release(doc);
7370 free_bstrs();
7373 static void test_TransformWithLoadingLocalFile(void)
7375 IXMLDOMDocument *doc;
7376 IXMLDOMDocument *xsl;
7377 IXMLDOMNode *pNode;
7378 VARIANT_BOOL bSucc;
7379 HRESULT hr;
7380 HANDLE file;
7381 DWORD dwWritten;
7382 char lpPathBuffer[MAX_PATH];
7383 int i;
7385 /* Create a Temp File. */
7386 GetTempPathA(MAX_PATH, lpPathBuffer);
7387 strcat(lpPathBuffer, "customers.xml" );
7389 file = CreateFileA(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
7390 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
7391 if(file == INVALID_HANDLE_VALUE)
7392 return;
7394 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
7395 CloseHandle(file);
7397 /* Correct path to not include a escape character. */
7398 for(i=0; i < strlen(lpPathBuffer); i++)
7400 if(lpPathBuffer[i] == '\\')
7401 lpPathBuffer[i] = '/';
7404 doc = create_document(&IID_IXMLDOMDocument);
7405 if (!doc) return;
7407 xsl = create_document(&IID_IXMLDOMDocument);
7408 if (!xsl)
7410 IXMLDOMDocument2_Release(doc);
7411 return;
7414 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
7415 ok(hr == S_OK, "ret %08x\n", hr );
7416 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7417 if(bSucc == VARIANT_TRUE)
7419 BSTR sXSL;
7420 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
7421 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
7422 BSTR sFileName = _bstr_(lpPathBuffer);
7423 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
7425 sXSL = SysAllocStringLen(NULL, nLegnth);
7426 lstrcpyW(sXSL, sPart1);
7427 lstrcatW(sXSL, sFileName);
7428 lstrcatW(sXSL, sPart2);
7430 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
7431 ok(hr == S_OK, "ret %08x\n", hr );
7432 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
7433 if(bSucc == VARIANT_TRUE)
7435 BSTR sResult;
7437 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
7438 ok(hr == S_OK, "ret %08x\n", hr );
7439 if(hr == S_OK)
7441 /* This will load the temp file via the XSL */
7442 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
7443 ok(hr == S_OK, "ret %08x\n", hr );
7444 if(hr == S_OK)
7446 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
7447 SysFreeString(sResult);
7450 IXMLDOMNode_Release(pNode);
7454 SysFreeString(sXSL);
7457 IXMLDOMDocument_Release(doc);
7458 IXMLDOMDocument_Release(xsl);
7460 DeleteFile(lpPathBuffer);
7461 free_bstrs();
7464 static void test_put_nodeValue(void)
7466 static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
7467 IXMLDOMDocument *doc;
7468 IXMLDOMText *text;
7469 IXMLDOMEntityReference *entityref;
7470 IXMLDOMAttribute *attr;
7471 IXMLDOMNode *node;
7472 HRESULT hr;
7473 VARIANT data, type;
7475 doc = create_document(&IID_IXMLDOMDocument);
7476 if (!doc) return;
7478 /* test for unsupported types */
7479 /* NODE_DOCUMENT */
7480 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
7481 ok(hr == S_OK, "ret %08x\n", hr );
7482 V_VT(&data) = VT_BSTR;
7483 V_BSTR(&data) = _bstr_("one two three");
7484 hr = IXMLDOMNode_put_nodeValue(node, data);
7485 ok(hr == E_FAIL, "ret %08x\n", hr );
7486 IXMLDOMNode_Release(node);
7488 /* NODE_DOCUMENT_FRAGMENT */
7489 V_VT(&type) = VT_I1;
7490 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
7491 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
7492 ok(hr == S_OK, "ret %08x\n", hr );
7493 V_VT(&data) = VT_BSTR;
7494 V_BSTR(&data) = _bstr_("one two three");
7495 hr = IXMLDOMNode_put_nodeValue(node, data);
7496 ok(hr == E_FAIL, "ret %08x\n", hr );
7497 IXMLDOMNode_Release(node);
7499 /* NODE_ELEMENT */
7500 V_VT(&type) = VT_I1;
7501 V_I1(&type) = NODE_ELEMENT;
7502 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
7503 ok(hr == S_OK, "ret %08x\n", hr );
7504 V_VT(&data) = VT_BSTR;
7505 V_BSTR(&data) = _bstr_("one two three");
7506 hr = IXMLDOMNode_put_nodeValue(node, data);
7507 ok(hr == E_FAIL, "ret %08x\n", hr );
7508 IXMLDOMNode_Release(node);
7510 /* NODE_ENTITY_REFERENCE */
7511 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
7512 ok(hr == S_OK, "ret %08x\n", hr );
7514 V_VT(&data) = VT_BSTR;
7515 V_BSTR(&data) = _bstr_("one two three");
7516 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
7517 ok(hr == E_FAIL, "ret %08x\n", hr );
7519 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
7520 ok(hr == S_OK, "ret %08x\n", hr );
7521 V_VT(&data) = VT_BSTR;
7522 V_BSTR(&data) = _bstr_("one two three");
7523 hr = IXMLDOMNode_put_nodeValue(node, data);
7524 ok(hr == E_FAIL, "ret %08x\n", hr );
7525 IXMLDOMNode_Release(node);
7526 IXMLDOMEntityReference_Release(entityref);
7528 /* supported types */
7529 hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
7530 ok(hr == S_OK, "ret %08x\n", hr );
7531 V_VT(&data) = VT_BSTR;
7532 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
7533 hr = IXMLDOMText_put_nodeValue(text, data);
7534 ok(hr == S_OK, "ret %08x\n", hr );
7535 IXMLDOMText_Release(text);
7537 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7538 ok(hr == S_OK, "ret %08x\n", hr );
7539 V_VT(&data) = VT_BSTR;
7540 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
7541 hr = IXMLDOMAttribute_put_nodeValue(attr, data);
7542 ok(hr == S_OK, "ret %08x\n", hr );
7543 hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
7544 ok(hr == S_OK, "ret %08x\n", hr );
7545 ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
7546 wine_dbgstr_w(V_BSTR(&data)));
7547 VariantClear(&data);
7548 IXMLDOMAttribute_Release(attr);
7550 free_bstrs();
7552 IXMLDOMDocument_Release(doc);
7555 static void test_document_IObjectSafety(void)
7557 IXMLDOMDocument *doc;
7558 IObjectSafety *safety;
7559 HRESULT hr;
7561 doc = create_document(&IID_IXMLDOMDocument);
7562 if (!doc) return;
7564 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
7565 ok(hr == S_OK, "ret %08x\n", hr );
7567 test_IObjectSafety_common(safety);
7569 IObjectSafety_Release(safety);
7571 IXMLDOMDocument_Release(doc);
7574 typedef struct _property_test_t {
7575 const GUID *guid;
7576 const char *clsid;
7577 const char *property;
7578 const char *value;
7579 } property_test_t;
7581 static const property_test_t properties_test_data[] = {
7582 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
7583 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
7584 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
7585 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
7586 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
7587 { 0 }
7590 static void test_default_properties(void)
7592 const property_test_t *entry = properties_test_data;
7593 IXMLDOMDocument2 *doc;
7594 VARIANT var;
7595 HRESULT hr;
7597 while (entry->guid)
7599 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
7600 if (hr != S_OK)
7602 win_skip("can't create %s instance\n", entry->clsid);
7603 entry++;
7604 continue;
7607 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
7608 ok(hr == S_OK, "got 0x%08x\n", hr);
7609 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
7610 entry->value, entry->clsid);
7611 VariantClear(&var);
7613 IXMLDOMDocument2_Release(doc);
7615 entry++;
7619 static void test_XSLPattern(void)
7621 IXMLDOMDocument2 *doc;
7622 IXMLDOMNodeList *list;
7623 VARIANT_BOOL b;
7624 LONG len;
7626 doc = create_document(&IID_IXMLDOMDocument2);
7627 if (!doc) return;
7629 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
7630 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7632 /* switch to XSLPattern */
7633 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
7635 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
7636 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list));
7637 len = 0;
7638 ole_check(IXMLDOMNodeList_get_length(list, &len));
7639 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
7640 ok(len == 3, "expected 3 entries in list, got %d\n", len);
7641 IXMLDOMNodeList_Release(list);
7643 /* for XSLPattern start index is 0, for XPath it's 1 */
7644 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
7645 len = 0;
7646 ole_check(IXMLDOMNodeList_get_length(list, &len));
7647 ok(len != 0, "expected filled list\n");
7648 if (len)
7649 expect_list_and_release(list, "E1.E2.D1");
7651 /* index() */
7652 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=1]"), &list));
7653 len = 0;
7654 ole_check(IXMLDOMNodeList_get_length(list, &len));
7655 ok(len != 0, "expected filled list\n");
7656 if (len)
7657 expect_list_and_release(list, "E2.E2.D1");
7659 /* $eq$ */
7660 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $eq$ 1]"), &list));
7661 len = 0;
7662 ole_check(IXMLDOMNodeList_get_length(list, &len));
7663 ok(len != 0, "expected filled list\n");
7664 if (len)
7665 expect_list_and_release(list, "E2.E2.D1");
7667 /* end() */
7668 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[end()]"), &list));
7669 len = 0;
7670 ole_check(IXMLDOMNodeList_get_length(list, &len));
7671 ok(len != 0, "expected filled list\n");
7672 if (len)
7673 expect_list_and_release(list, "E4.E2.D1");
7675 /* $not$ */
7676 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$not$ end()]"), &list));
7677 len = 0;
7678 ole_check(IXMLDOMNodeList_get_length(list, &len));
7679 ok(len != 0, "expected filled list\n");
7680 if (len)
7681 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
7683 /* !=/$ne$ */
7684 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() != 0]"), &list));
7685 len = 0;
7686 ole_check(IXMLDOMNodeList_get_length(list, &len));
7687 ok(len != 0, "expected filled list\n");
7688 if (len)
7689 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
7690 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ne$ 0]"), &list));
7691 len = 0;
7692 ole_check(IXMLDOMNodeList_get_length(list, &len));
7693 ok(len != 0, "expected filled list\n");
7694 if (len)
7695 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
7697 /* </$lt$ */
7698 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() < 2]"), &list));
7699 len = 0;
7700 ole_check(IXMLDOMNodeList_get_length(list, &len));
7701 ok(len != 0, "expected filled list\n");
7702 if (len)
7703 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7704 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $lt$ 2]"), &list));
7705 len = 0;
7706 ole_check(IXMLDOMNodeList_get_length(list, &len));
7707 ok(len != 0, "expected filled list\n");
7708 if (len)
7709 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7711 /* <=/$le$ */
7712 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() <= 1]"), &list));
7713 len = 0;
7714 ole_check(IXMLDOMNodeList_get_length(list, &len));
7715 ok(len != 0, "expected filled list\n");
7716 if (len)
7717 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7718 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $le$ 1]"), &list));
7719 len = 0;
7720 ole_check(IXMLDOMNodeList_get_length(list, &len));
7721 ok(len != 0, "expected filled list\n");
7722 if (len)
7723 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7725 /* >/$gt$ */
7726 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() > 1]"), &list));
7727 len = 0;
7728 ole_check(IXMLDOMNodeList_get_length(list, &len));
7729 ok(len != 0, "expected filled list\n");
7730 if (len)
7731 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7732 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $gt$ 1]"), &list));
7733 len = 0;
7734 ole_check(IXMLDOMNodeList_get_length(list, &len));
7735 ok(len != 0, "expected filled list\n");
7736 if (len)
7737 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7739 /* >=/$ge$ */
7740 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() >= 2]"), &list));
7741 len = 0;
7742 ole_check(IXMLDOMNodeList_get_length(list, &len));
7743 ok(len != 0, "expected filled list\n");
7744 if (len)
7745 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7746 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ge$ 2]"), &list));
7747 len = 0;
7748 ole_check(IXMLDOMNodeList_get_length(list, &len));
7749 ok(len != 0, "expected filled list\n");
7750 if (len)
7751 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7753 /* $ieq$ */
7754 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ieq$ 'a2 field']"), &list));
7755 len = 0;
7756 ole_check(IXMLDOMNodeList_get_length(list, &len));
7757 ok(len != 0, "expected filled list\n");
7758 if (len)
7759 expect_list_and_release(list, "E2.E2.D1");
7761 /* $ine$ */
7762 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ine$ 'a2 field']"), &list));
7763 len = 0;
7764 ole_check(IXMLDOMNodeList_get_length(list, &len));
7765 ok(len != 0, "expected filled list\n");
7766 if (len)
7767 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
7769 /* $ilt$ */
7770 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ilt$ 'a3 field']"), &list));
7771 len = 0;
7772 ole_check(IXMLDOMNodeList_get_length(list, &len));
7773 ok(len != 0, "expected filled list\n");
7774 if (len)
7775 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7777 /* $ile$ */
7778 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ile$ 'a2 field']"), &list));
7779 len = 0;
7780 ole_check(IXMLDOMNodeList_get_length(list, &len));
7781 ok(len != 0, "expected filled list\n");
7782 if (len)
7783 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
7785 /* $igt$ */
7786 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $igt$ 'a2 field']"), &list));
7787 len = 0;
7788 ole_check(IXMLDOMNodeList_get_length(list, &len));
7789 ok(len != 0, "expected filled list\n");
7790 if (len)
7791 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7793 /* $ige$ */
7794 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ige$ 'a3 field']"), &list));
7795 len = 0;
7796 ole_check(IXMLDOMNodeList_get_length(list, &len));
7797 ok(len != 0, "expected filled list\n");
7798 if (len)
7799 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
7801 /* $any$ */
7802 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$any$ *='B2 field']"), &list));
7803 len = 0;
7804 ole_check(IXMLDOMNodeList_get_length(list, &len));
7805 ok(len != 0, "expected filled list\n");
7806 if (len)
7807 expect_list_and_release(list, "E2.E2.D1");
7809 /* $all$ */
7810 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$all$ *!='B2 field']"), &list));
7811 len = 0;
7812 ole_check(IXMLDOMNodeList_get_length(list, &len));
7813 ok(len != 0, "expected filled list\n");
7814 if (len)
7815 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
7817 /* or/$or$/|| */
7818 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 or end()]"), &list));
7819 len = 0;
7820 ole_check(IXMLDOMNodeList_get_length(list, &len));
7821 ok(len != 0, "expected filled list\n");
7822 if (len)
7823 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7824 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 $or$ end()]"), &list));
7825 len = 0;
7826 ole_check(IXMLDOMNodeList_get_length(list, &len));
7827 ok(len != 0, "expected filled list\n");
7828 if (len)
7829 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7830 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 || end()]"), &list));
7831 len = 0;
7832 ole_check(IXMLDOMNodeList_get_length(list, &len));
7833 ok(len != 0, "expected filled list\n");
7834 if (len)
7835 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
7837 /* and/$and$/&& */
7838 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 and $not$ end()]"), &list));
7839 len = 0;
7840 ole_check(IXMLDOMNodeList_get_length(list, &len));
7841 ok(len != 0, "expected filled list\n");
7842 if (len)
7843 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7844 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 $and$ $not$ end()]"), &list));
7845 len = 0;
7846 ole_check(IXMLDOMNodeList_get_length(list, &len));
7847 ok(len != 0, "expected filled list\n");
7848 if (len)
7849 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7850 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 && $not$ end()]"), &list));
7851 len = 0;
7852 ole_check(IXMLDOMNodeList_get_length(list, &len));
7853 ok(len != 0, "expected filled list\n");
7854 if (len)
7855 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
7857 /* namespace handling */
7858 /* no registered namespaces */
7859 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
7860 list = NULL;
7862 /* prefixes don't need to be registered, you may use them as they are in the doc */
7863 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//bar:x"), &list));
7864 len = 0;
7865 ole_check(IXMLDOMNodeList_get_length(list, &len));
7866 ok(len != 0, "expected filled list\n");
7867 if (len)
7868 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
7870 /* prefixes must be explicitly specified in the name */
7871 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:elem"), &list));
7872 len = 0;
7873 ole_check(IXMLDOMNodeList_get_length(list, &len));
7874 ok(len == 0, "expected empty list\n");
7875 IXMLDOMNodeList_Release(list);
7877 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7878 len = 0;
7879 ole_check(IXMLDOMNodeList_get_length(list, &len));
7880 ok(len != 0, "expected filled list\n");
7881 if (len)
7882 expect_list_and_release(list, "E3.E4.E2.D1");
7884 /* explicitly register prefix foo */
7885 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
7887 /* now we get the same behavior as XPath */
7888 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7889 len = 0;
7890 ole_check(IXMLDOMNodeList_get_length(list, &len));
7891 ok(len != 0, "expected filled list\n");
7892 if (len)
7893 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
7895 /* set prefix foo to some nonexistent namespace */
7896 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:nonexistent-foo'")));
7898 /* the registered prefix takes precedence */
7899 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
7900 len = 0;
7901 ole_check(IXMLDOMNodeList_get_length(list, &len));
7902 ok(len == 0, "expected empty list\n");
7903 IXMLDOMNodeList_Release(list);
7905 IXMLDOMDocument2_Release(doc);
7907 doc = create_document(&IID_IXMLDOMDocument2);
7908 if (!doc) return;
7910 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szNodeTypesXML), &b));
7911 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7912 list = NULL;
7914 /* attribute() */
7915 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute()"), &list));
7916 len = 0;
7917 ole_check(IXMLDOMNodeList_get_length(list, &len));
7918 ok(len == 0, "expected empty list\n");
7919 IXMLDOMNodeList_Release(list);
7921 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute('depth')"), &list));
7922 len = 0;
7923 ole_check(IXMLDOMNodeList_get_length(list, &len));
7924 ok(len == 0, "expected empty list\n");
7925 IXMLDOMNodeList_Release(list);
7927 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/attribute('depth')"), &list));
7928 len = 0;
7929 ole_check(IXMLDOMNodeList_get_length(list, &len));
7930 ok(len != 0, "expected filled list\n");
7931 expect_list_and_release(list, "A'depth'.E3.D1");
7933 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/attribute()"), &list));
7934 len = 0;
7935 ole_check(IXMLDOMNodeList_get_length(list, &len));
7936 ok(len != 0, "expected filled list\n");
7937 expect_list_and_release(list, "A'id'.E3.E3.D1 A'depth'.E3.E3.D1");
7939 list = NULL;
7940 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute(id)"), &list), E_FAIL);
7941 if (list)
7942 IXMLDOMNodeList_Release(list);
7943 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute('id')"), &list));
7944 len = 0;
7945 ole_check(IXMLDOMNodeList_get_length(list, &len));
7946 ok(len != 0, "expected filled list\n");
7947 if (len)
7948 expect_list_and_release(list, "A'id'.E3.E3.D1 A'id'.E4.E3.E3.D1 A'id'.E5.E3.E3.D1 A'id'.E6.E3.E3.D1");
7950 /* comment() */
7951 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("comment()"), &list));
7952 len = 0;
7953 ole_check(IXMLDOMNodeList_get_length(list, &len));
7954 ok(len != 0, "expected filled list\n");
7955 if (len)
7956 expect_list_and_release(list, "C2.D1");
7958 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//comment()"), &list));
7959 len = 0;
7960 ole_check(IXMLDOMNodeList_get_length(list, &len));
7961 ok(len != 0, "expected filled list\n");
7962 if (len)
7963 expect_list_and_release(list, "C2.D1 C1.E3.D1 C2.E3.E3.D1 C2.E4.E3.D1");
7965 /* element() */
7966 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("element()"), &list));
7967 len = 0;
7968 ole_check(IXMLDOMNodeList_get_length(list, &len));
7969 ok(len != 0, "expected filled list\n");
7970 if (len)
7971 expect_list_and_release(list, "E3.D1");
7973 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/y/element()"), &list));
7974 len = 0;
7975 ole_check(IXMLDOMNodeList_get_length(list, &len));
7976 ok(len != 0, "expected filled list\n");
7977 if (len)
7978 expect_list_and_release(list, "E4.E4.E3.D1 E5.E4.E3.D1 E6.E4.E3.D1");
7980 list = NULL;
7981 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element(a)"), &list), E_FAIL);
7982 if (list)
7983 IXMLDOMNodeList_Release(list);
7984 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element('a')"), &list));
7985 len = 0;
7986 ole_check(IXMLDOMNodeList_get_length(list, &len));
7987 ok(len != 0, "expected filled list\n");
7988 if (len)
7989 expect_list_and_release(list, "E4.E3.E3.D1 E4.E4.E3.D1");
7991 /* node() */
7992 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("node()"), &list));
7993 len = 0;
7994 ole_check(IXMLDOMNodeList_get_length(list, &len));
7995 ok(len != 0, "expected filled list\n");
7996 if (len)
7997 expect_list_and_release(list, "P1.D1 C2.D1 E3.D1");
7999 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()"), &list));
8000 len = 0;
8001 ole_check(IXMLDOMNodeList_get_length(list, &len));
8002 ok(len != 0, "expected filled list\n");
8003 if (len)
8004 expect_list_and_release(list, "P1.E3.E3.D1 C2.E3.E3.D1 T3.E3.E3.D1 E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
8006 /* nodeType() */
8007 /* XML_ELEMENT_NODE */
8008 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=1]"), &list));
8009 len = 0;
8010 ole_check(IXMLDOMNodeList_get_length(list, &len));
8011 ok(len != 0, "expected filled list\n");
8012 if (len)
8013 expect_list_and_release(list, "E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
8014 /* XML_TEXT_NODE */
8015 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=3]"), &list));
8016 len = 0;
8017 ole_check(IXMLDOMNodeList_get_length(list, &len));
8018 ok(len != 0, "expected filled list\n");
8019 if (len)
8020 expect_list_and_release(list, "T3.E3.E3.D1");
8021 /* XML_PI_NODE */
8022 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=7]"), &list));
8023 len = 0;
8024 ole_check(IXMLDOMNodeList_get_length(list, &len));
8025 ok(len != 0, "expected filled list\n");
8026 if (len)
8027 expect_list_and_release(list, "P1.E3.E3.D1");
8028 /* XML_COMMENT_NODE */
8029 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=8]"), &list));
8030 len = 0;
8031 ole_check(IXMLDOMNodeList_get_length(list, &len));
8032 ok(len != 0, "expected filled list\n");
8033 if (len)
8034 expect_list_and_release(list, "C2.E3.E3.D1");
8036 /* pi() */
8037 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("pi()"), &list));
8038 if (list)
8040 len = 0;
8041 ole_check(IXMLDOMNodeList_get_length(list, &len));
8042 ok(len != 0, "expected filled list\n");
8043 if (len)
8044 expect_list_and_release(list, "P1.D1");
8047 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//y/pi()"), &list));
8048 len = 0;
8049 ole_check(IXMLDOMNodeList_get_length(list, &len));
8050 ok(len != 0, "expected filled list\n");
8051 if (len)
8052 expect_list_and_release(list, "P1.E4.E3.D1");
8054 /* textnode() */
8055 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/textnode()"), &list));
8056 len = 0;
8057 ole_check(IXMLDOMNodeList_get_length(list, &len));
8058 ok(len != 0, "expected filled list\n");
8059 if (len)
8060 expect_list_and_release(list, "T2.E3.D1");
8062 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/element()/textnode()"), &list));
8063 len = 0;
8064 ole_check(IXMLDOMNodeList_get_length(list, &len));
8065 ok(len != 0, "expected filled list\n");
8066 if (len)
8067 expect_list_and_release(list, "T3.E3.E3.D1 T3.E4.E3.D1");
8069 IXMLDOMDocument2_Release(doc);
8070 free_bstrs();
8073 static void test_splitText(void)
8075 IXMLDOMCDATASection *cdata;
8076 IXMLDOMElement *root;
8077 IXMLDOMDocument *doc;
8078 IXMLDOMText *text, *text2;
8079 IXMLDOMNode *node;
8080 VARIANT var;
8081 VARIANT_BOOL success;
8082 LONG length;
8083 HRESULT hr;
8085 doc = create_document(&IID_IXMLDOMDocument);
8086 if (!doc) return;
8088 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
8089 ok(hr == S_OK, "got 0x%08x\n", hr);
8091 hr = IXMLDOMDocument_get_documentElement(doc, &root);
8092 ok(hr == S_OK, "got 0x%08x\n", hr);
8094 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
8095 ok(hr == S_OK, "got 0x%08x\n", hr);
8097 V_VT(&var) = VT_EMPTY;
8098 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
8099 ok(hr == S_OK, "got 0x%08x\n", hr);
8101 length = 0;
8102 hr = IXMLDOMCDATASection_get_length(cdata, &length);
8103 ok(hr == S_OK, "got 0x%08x\n", hr);
8104 ok(length > 0, "got %d\n", length);
8106 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
8107 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8109 text = (void*)0xdeadbeef;
8110 /* negative offset */
8111 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
8112 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8113 ok(text == (void*)0xdeadbeef, "got %p\n", text);
8115 text = (void*)0xdeadbeef;
8116 /* offset outside data */
8117 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
8118 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8119 ok(text == 0, "got %p\n", text);
8121 text = (void*)0xdeadbeef;
8122 /* offset outside data */
8123 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
8124 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8125 ok(text == 0, "got %p\n", text);
8127 /* no empty node created */
8128 node = (void*)0xdeadbeef;
8129 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8130 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8131 ok(node == 0, "got %p\n", text);
8133 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
8134 ok(hr == S_OK, "got 0x%08x\n", hr);
8136 length = 0;
8137 hr = IXMLDOMText_get_length(text, &length);
8138 ok(hr == S_OK, "got 0x%08x\n", hr);
8139 ok(length == 7, "got %d\n", length);
8141 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
8142 ok(hr == S_OK, "got 0x%08x\n", hr);
8143 IXMLDOMNode_Release(node);
8145 /* split new text node */
8146 hr = IXMLDOMText_get_length(text, &length);
8147 ok(hr == S_OK, "got 0x%08x\n", hr);
8149 node = (void*)0xdeadbeef;
8150 hr = IXMLDOMText_get_nextSibling(text, &node);
8151 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8152 ok(node == 0, "got %p\n", text);
8154 hr = IXMLDOMText_splitText(text, 0, NULL);
8155 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8157 text2 = (void*)0xdeadbeef;
8158 /* negative offset */
8159 hr = IXMLDOMText_splitText(text, -1, &text2);
8160 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8161 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
8163 text2 = (void*)0xdeadbeef;
8164 /* offset outside data */
8165 hr = IXMLDOMText_splitText(text, length + 1, &text2);
8166 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8167 ok(text2 == 0, "got %p\n", text2);
8169 text2 = (void*)0xdeadbeef;
8170 /* offset outside data */
8171 hr = IXMLDOMText_splitText(text, length, &text2);
8172 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8173 ok(text2 == 0, "got %p\n", text);
8175 text2 = 0;
8176 hr = IXMLDOMText_splitText(text, 4, &text2);
8177 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8178 if (text2) IXMLDOMText_Release(text2);
8180 node = 0;
8181 hr = IXMLDOMText_get_nextSibling(text, &node);
8182 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
8183 if (node) IXMLDOMNode_Release(node);
8185 IXMLDOMText_Release(text);
8186 IXMLDOMElement_Release(root);
8187 IXMLDOMCDATASection_Release(cdata);
8188 free_bstrs();
8191 static void test_getQualifiedItem(void)
8193 IXMLDOMDocument *doc;
8194 IXMLDOMElement *element;
8195 IXMLDOMNode *pr_node, *node;
8196 IXMLDOMNodeList *root_list;
8197 IXMLDOMNamedNodeMap *map;
8198 VARIANT_BOOL b;
8199 BSTR str;
8200 LONG len;
8201 HRESULT hr;
8203 doc = create_document(&IID_IXMLDOMDocument);
8204 if (!doc) return;
8206 str = SysAllocString( szComplete4 );
8207 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8208 ok( hr == S_OK, "loadXML failed\n");
8209 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8210 SysFreeString( str );
8212 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8213 ok( hr == S_OK, "ret %08x\n", hr);
8215 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8216 ok( hr == S_OK, "ret %08x\n", hr);
8218 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8219 ok( hr == S_OK, "ret %08x\n", hr);
8220 IXMLDOMNodeList_Release(root_list);
8222 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8223 ok( hr == S_OK, "ret %08x\n", hr);
8224 IXMLDOMNode_Release(pr_node);
8226 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8227 ok( hr == S_OK, "ret %08x\n", hr);
8228 ok( len == 3, "length %d\n", len);
8230 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
8231 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8233 node = (void*)0xdeadbeef;
8234 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
8235 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8236 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8238 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
8239 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8241 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
8242 ok( hr == S_OK, "ret %08x\n", hr);
8243 IXMLDOMNode_Release(node);
8245 IXMLDOMNamedNodeMap_Release( map );
8246 IXMLDOMElement_Release( element );
8247 IXMLDOMDocument_Release( doc );
8248 free_bstrs();
8251 static void test_removeQualifiedItem(void)
8253 IXMLDOMDocument *doc;
8254 IXMLDOMElement *element;
8255 IXMLDOMNode *pr_node, *node;
8256 IXMLDOMNodeList *root_list;
8257 IXMLDOMNamedNodeMap *map;
8258 VARIANT_BOOL b;
8259 BSTR str;
8260 LONG len;
8261 HRESULT hr;
8263 doc = create_document(&IID_IXMLDOMDocument);
8264 if (!doc) return;
8266 str = SysAllocString( szComplete4 );
8267 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8268 ok( hr == S_OK, "loadXML failed\n");
8269 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8270 SysFreeString( str );
8272 hr = IXMLDOMDocument_get_documentElement(doc, &element);
8273 ok( hr == S_OK, "ret %08x\n", hr);
8275 hr = IXMLDOMElement_get_childNodes(element, &root_list);
8276 ok( hr == S_OK, "ret %08x\n", hr);
8278 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
8279 ok( hr == S_OK, "ret %08x\n", hr);
8280 IXMLDOMNodeList_Release(root_list);
8282 hr = IXMLDOMNode_get_attributes(pr_node, &map);
8283 ok( hr == S_OK, "ret %08x\n", hr);
8284 IXMLDOMNode_Release(pr_node);
8286 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
8287 ok( hr == S_OK, "ret %08x\n", hr);
8288 ok( len == 3, "length %d\n", len);
8290 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
8291 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8293 node = (void*)0xdeadbeef;
8294 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
8295 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
8296 ok( node == (void*)0xdeadbeef, "got %p\n", node);
8298 /* out pointer is optional */
8299 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8300 ok( hr == S_OK, "ret %08x\n", hr);
8302 /* already removed */
8303 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
8304 ok( hr == S_FALSE, "ret %08x\n", hr);
8306 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
8307 ok( hr == S_OK, "ret %08x\n", hr);
8308 IXMLDOMNode_Release(node);
8310 IXMLDOMNamedNodeMap_Release( map );
8311 IXMLDOMElement_Release( element );
8312 IXMLDOMDocument_Release( doc );
8313 free_bstrs();
8316 #define check_default_props(doc) _check_default_props(__LINE__, doc)
8317 static inline void _check_default_props(int line, IXMLDOMDocument2* doc)
8319 VARIANT_BOOL b;
8320 VARIANT var;
8321 HRESULT hr;
8323 VariantInit(&var);
8324 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8325 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
8326 VariantClear(&var);
8328 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8329 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("")) == 0, "expected empty string\n");
8330 VariantClear(&var);
8332 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8333 ok_(__FILE__, line)(b == VARIANT_FALSE, "expected FALSE\n");
8335 hr = IXMLDOMDocument2_get_schemas(doc, &var);
8336 ok_(__FILE__, line)(hr == S_FALSE, "got %08x\n", hr);
8337 VariantClear(&var);
8340 #define check_set_props(doc) _check_set_props(__LINE__, doc)
8341 static inline void _check_set_props(int line, IXMLDOMDocument2* doc)
8343 VARIANT_BOOL b;
8344 VARIANT var;
8346 VariantInit(&var);
8347 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
8348 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
8349 VariantClear(&var);
8351 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
8352 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&var)));
8353 VariantClear(&var);
8355 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
8356 ok_(__FILE__, line)(b == VARIANT_TRUE, "expected TRUE\n");
8358 helper_ole_check(IXMLDOMDocument2_get_schemas(doc, &var));
8359 ok_(__FILE__, line)(V_VT(&var) != VT_NULL, "expected pointer\n");
8360 VariantClear(&var);
8363 #define set_props(doc, cache) _set_props(__LINE__, doc, cache)
8364 static inline void _set_props(int line, IXMLDOMDocument2* doc, IXMLDOMSchemaCollection* cache)
8366 VARIANT var;
8368 VariantInit(&var);
8369 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
8370 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'")));
8371 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_TRUE));
8372 V_VT(&var) = VT_DISPATCH;
8373 V_DISPATCH(&var) = NULL;
8374 helper_ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&var)));
8375 ok_(__FILE__, line)(V_DISPATCH(&var) != NULL, "expected pointer\n");
8376 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8377 VariantClear(&var);
8380 #define unset_props(doc) _unset_props(__LINE__, doc)
8381 static inline void _unset_props(int line, IXMLDOMDocument2* doc)
8383 VARIANT var;
8385 VariantInit(&var);
8386 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
8387 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
8388 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_FALSE));
8389 V_VT(&var) = VT_NULL;
8390 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
8391 VariantClear(&var);
8394 static void test_get_ownerDocument(void)
8396 IXMLDOMDocument *doc1, *doc2, *doc3;
8397 IXMLDOMDocument2 *doc, *doc_owner;
8398 IXMLDOMNode *node;
8399 IXMLDOMSchemaCollection *cache;
8400 VARIANT_BOOL b;
8401 VARIANT var;
8402 BSTR str;
8404 doc = create_document(&IID_IXMLDOMDocument2);
8405 cache = create_cache(&IID_IXMLDOMSchemaCollection);
8406 if (!doc || !cache)
8408 if (doc) IXMLDOMDocument2_Release(doc);
8409 if (cache) IXMLDOMSchemaCollection_Release(cache);
8410 return;
8413 VariantInit(&var);
8415 str = SysAllocString(szComplete4);
8416 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
8417 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8418 SysFreeString(str);
8420 check_default_props(doc);
8422 /* set properties and check that new instances use them */
8423 set_props(doc, cache);
8424 check_set_props(doc);
8426 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8427 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc1));
8429 /* new interface keeps props */
8430 ole_check(IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8431 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
8432 check_set_props(doc_owner);
8433 IXMLDOMDocument2_Release(doc_owner);
8435 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc2));
8436 IXMLDOMNode_Release(node);
8438 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
8440 /* reload */
8441 str = SysAllocString(szComplete4);
8442 ole_check(IXMLDOMDocument2_loadXML(doc, str, &b));
8443 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8444 SysFreeString(str);
8446 /* properties retained even after reload */
8447 check_set_props(doc);
8449 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
8450 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc3));
8451 IXMLDOMNode_Release(node);
8453 ole_check(IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner));
8454 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
8455 check_set_props(doc_owner);
8457 /* changing properties for one instance changes them for all */
8458 unset_props(doc_owner);
8459 check_default_props(doc_owner);
8460 check_default_props(doc);
8462 IXMLDOMSchemaCollection_Release(cache);
8463 IXMLDOMDocument_Release(doc1);
8464 IXMLDOMDocument_Release(doc2);
8465 IXMLDOMDocument_Release(doc3);
8466 IXMLDOMDocument2_Release(doc);
8467 IXMLDOMDocument2_Release(doc_owner);
8468 free_bstrs();
8471 static void test_setAttributeNode(void)
8473 IXMLDOMDocument *doc, *doc2;
8474 IXMLDOMElement *elem, *elem2;
8475 IXMLDOMAttribute *attr, *attr2, *ret_attr;
8476 VARIANT_BOOL b;
8477 HRESULT hr;
8478 VARIANT v;
8479 BSTR str;
8480 ULONG ref1, ref2;
8482 doc = create_document(&IID_IXMLDOMDocument);
8483 if (!doc) return;
8485 str = SysAllocString( szComplete4 );
8486 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
8487 ok( hr == S_OK, "loadXML failed\n");
8488 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8489 SysFreeString( str );
8491 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8492 ok( hr == S_OK, "got 0x%08x\n", hr);
8494 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
8495 ok( hr == S_OK, "got 0x%08x\n", hr);
8496 ok( elem2 != elem, "got same instance\n");
8498 ret_attr = (void*)0xdeadbeef;
8499 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
8500 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8501 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8503 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8504 ok( hr == S_OK, "got 0x%08x\n", hr);
8506 ref1 = IXMLDOMElement_AddRef(elem);
8507 IXMLDOMElement_Release(elem);
8509 ret_attr = (void*)0xdeadbeef;
8510 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8511 ok( hr == S_OK, "got 0x%08x\n", hr);
8512 ok( ret_attr == NULL, "got %p\n", ret_attr);
8514 /* no reference added */
8515 ref2 = IXMLDOMElement_AddRef(elem);
8516 IXMLDOMElement_Release(elem);
8517 ok(ref2 == ref1, "got %d, expected %d\n", ref2, ref1);
8519 EXPECT_CHILDREN(elem);
8520 EXPECT_CHILDREN(elem2);
8522 IXMLDOMElement_Release(elem2);
8524 attr2 = NULL;
8525 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
8526 ok( hr == S_OK, "got 0x%08x\n", hr);
8527 ok( attr2 != attr, "got same instance %p\n", attr2);
8528 IXMLDOMAttribute_Release(attr2);
8530 /* try to add it another time */
8531 ret_attr = (void*)0xdeadbeef;
8532 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8533 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8534 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8536 IXMLDOMElement_Release(elem);
8538 /* initially used element is released, attribute still 'has' a container */
8539 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
8540 ok( hr == S_OK, "got 0x%08x\n", hr);
8541 ret_attr = (void*)0xdeadbeef;
8542 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8543 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8544 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
8545 IXMLDOMElement_Release(elem);
8547 /* add attribute already attached to another document */
8548 doc2 = create_document(&IID_IXMLDOMDocument);
8550 str = SysAllocString( szComplete4 );
8551 hr = IXMLDOMDocument_loadXML( doc2, str, &b );
8552 ok( hr == S_OK, "loadXML failed\n");
8553 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8554 SysFreeString( str );
8556 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
8557 ok( hr == S_OK, "got 0x%08x\n", hr);
8558 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
8559 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8560 IXMLDOMElement_Release(elem);
8562 IXMLDOMAttribute_Release(attr);
8564 /* create element, add attribute, see if it's copied or linked */
8565 hr = IXMLDOMDocument_createElement(doc, _bstr_("test"), &elem);
8566 ok( hr == S_OK, "got 0x%08x\n", hr);
8568 attr = NULL;
8569 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8570 ok(hr == S_OK, "got 0x%08x\n", hr);
8571 ok(attr != NULL, "got %p\n", attr);
8573 ref1 = IXMLDOMAttribute_AddRef(attr);
8574 IXMLDOMAttribute_Release(attr);
8576 V_VT(&v) = VT_BSTR;
8577 V_BSTR(&v) = _bstr_("attrvalue1");
8578 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8579 ok( hr == S_OK, "got 0x%08x\n", hr);
8581 str = NULL;
8582 hr = IXMLDOMAttribute_get_xml(attr, &str);
8583 ok( hr == S_OK, "got 0x%08x\n", hr);
8584 ok( lstrcmpW(str, _bstr_("attr=\"attrvalue1\"")) == 0,
8585 "got %s\n", wine_dbgstr_w(str));
8586 SysFreeString(str);
8588 ret_attr = (void*)0xdeadbeef;
8589 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
8590 ok(hr == S_OK, "got 0x%08x\n", hr);
8591 ok(ret_attr == NULL, "got %p\n", ret_attr);
8593 /* attribute reference increased */
8594 ref2 = IXMLDOMAttribute_AddRef(attr);
8595 IXMLDOMAttribute_Release(attr);
8596 ok(ref1 == ref2, "got %d, expected %d\n", ref2, ref1);
8598 hr = IXMLDOMElement_get_xml(elem, &str);
8599 ok( hr == S_OK, "got 0x%08x\n", hr);
8600 ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue1\"/>")) == 0,
8601 "got %s\n", wine_dbgstr_w(str));
8602 SysFreeString(str);
8604 V_VT(&v) = VT_BSTR;
8605 V_BSTR(&v) = _bstr_("attrvalue2");
8606 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
8607 ok( hr == S_OK, "got 0x%08x\n", hr);
8609 hr = IXMLDOMElement_get_xml(elem, &str);
8610 ok( hr == S_OK, "got 0x%08x\n", hr);
8611 todo_wine ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue2\"/>")) == 0,
8612 "got %s\n", wine_dbgstr_w(str));
8613 SysFreeString(str);
8615 IXMLDOMElement_Release(elem);
8616 IXMLDOMAttribute_Release(attr);
8617 IXMLDOMDocument_Release(doc2);
8618 IXMLDOMDocument_Release(doc);
8621 static void test_put_dataType(void)
8623 IXMLDOMCDATASection *cdata;
8624 IXMLDOMDocument *doc;
8625 VARIANT_BOOL b;
8626 HRESULT hr;
8627 BSTR str;
8629 doc = create_document(&IID_IXMLDOMDocument);
8630 if (!doc) return;
8632 str = SysAllocString( szComplete4 );
8633 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8634 ok( hr == S_OK, "loadXML failed\n");
8635 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8636 SysFreeString( str );
8638 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("test"), &cdata);
8639 ok( hr == S_OK, "got 0x%08x\n", hr);
8640 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("number"));
8641 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8642 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("string"));
8643 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8644 IXMLDOMCDATASection_Release(cdata);
8646 IXMLDOMDocument_Release(doc);
8647 free_bstrs();
8650 static void test_createNode(void)
8652 IXMLDOMDocument *doc;
8653 IXMLDOMElement *elem;
8654 IXMLDOMNode *node;
8655 VARIANT v, var;
8656 BSTR prefix, str;
8657 HRESULT hr;
8658 ULONG ref;
8660 doc = create_document(&IID_IXMLDOMDocument);
8661 if (!doc) return;
8663 EXPECT_REF(doc, 1);
8665 /* reference count tests */
8666 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8667 ok( hr == S_OK, "got 0x%08x\n", hr);
8669 /* initial reference is 2 */
8670 todo_wine {
8671 EXPECT_REF(elem, 2);
8672 ref = IXMLDOMElement_Release(elem);
8673 ok(ref == 1, "got %d\n", ref);
8674 /* it's released already, attempt to release now will crash it */
8677 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8678 ok( hr == S_OK, "got 0x%08x\n", hr);
8679 todo_wine EXPECT_REF(elem, 2);
8680 IXMLDOMDocument_Release(doc);
8681 todo_wine EXPECT_REF(elem, 2);
8682 IXMLDOMElement_Release(elem);
8684 doc = create_document(&IID_IXMLDOMDocument);
8686 /* NODE_ELEMENT nodes */
8687 /* 1. specified namespace */
8688 V_VT(&v) = VT_I4;
8689 V_I4(&v) = NODE_ELEMENT;
8691 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
8692 ok( hr == S_OK, "got 0x%08x\n", hr);
8693 prefix = NULL;
8694 hr = IXMLDOMNode_get_prefix(node, &prefix);
8695 ok( hr == S_OK, "got 0x%08x\n", hr);
8696 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
8697 SysFreeString(prefix);
8698 IXMLDOMNode_Release(node);
8700 /* 2. default namespace */
8701 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
8702 ok( hr == S_OK, "got 0x%08x\n", hr);
8703 prefix = (void*)0xdeadbeef;
8704 hr = IXMLDOMNode_get_prefix(node, &prefix);
8705 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8706 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
8707 /* check dump */
8708 hr = IXMLDOMNode_get_xml(node, &str);
8709 ok( hr == S_OK, "got 0x%08x\n", hr);
8710 ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0,
8711 "got %s\n", wine_dbgstr_w(str));
8712 SysFreeString(str);
8714 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
8715 ok( hr == S_OK, "got 0x%08x\n", hr);
8717 V_VT(&var) = VT_BSTR;
8718 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
8719 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8720 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
8722 str = NULL;
8723 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
8724 ok( hr == S_OK, "got 0x%08x\n", hr);
8725 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
8726 SysFreeString(str);
8728 IXMLDOMElement_Release(elem);
8729 IXMLDOMNode_Release(node);
8731 IXMLDOMDocument_Release(doc);
8732 free_bstrs();
8735 static void test_get_prefix(void)
8737 IXMLDOMDocumentFragment *fragment;
8738 IXMLDOMCDATASection *cdata;
8739 IXMLDOMElement *element;
8740 IXMLDOMComment *comment;
8741 IXMLDOMDocument *doc;
8742 HRESULT hr;
8743 BSTR str;
8745 doc = create_document(&IID_IXMLDOMDocument);
8746 if (!doc) return;
8748 /* nodes that can't support prefix */
8749 /* 1. document */
8750 str = (void*)0xdeadbeef;
8751 hr = IXMLDOMDocument_get_prefix(doc, &str);
8752 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8753 ok( str == 0, "got %p\n", str);
8755 hr = IXMLDOMDocument_get_prefix(doc, NULL);
8756 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8758 /* 2. cdata */
8759 hr = IXMLDOMDocument_createCDATASection(doc, NULL, &cdata);
8760 ok(hr == S_OK, "got %08x\n", hr );
8762 str = (void*)0xdeadbeef;
8763 hr = IXMLDOMCDATASection_get_prefix(cdata, &str);
8764 ok(hr == S_FALSE, "got %08x\n", hr);
8765 ok( str == 0, "got %p\n", str);
8767 hr = IXMLDOMCDATASection_get_prefix(cdata, NULL);
8768 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8769 IXMLDOMCDATASection_Release(cdata);
8771 /* 3. comment */
8772 hr = IXMLDOMDocument_createComment(doc, NULL, &comment);
8773 ok(hr == S_OK, "got %08x\n", hr );
8775 str = (void*)0xdeadbeef;
8776 hr = IXMLDOMComment_get_prefix(comment, &str);
8777 ok(hr == S_FALSE, "got %08x\n", hr);
8778 ok( str == 0, "got %p\n", str);
8780 hr = IXMLDOMComment_get_prefix(comment, NULL);
8781 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8782 IXMLDOMComment_Release(comment);
8784 /* 4. fragment */
8785 hr = IXMLDOMDocument_createDocumentFragment(doc, &fragment);
8786 ok(hr == S_OK, "got %08x\n", hr );
8788 str = (void*)0xdeadbeef;
8789 hr = IXMLDOMDocumentFragment_get_prefix(fragment, &str);
8790 ok(hr == S_FALSE, "got %08x\n", hr);
8791 ok( str == 0, "got %p\n", str);
8793 hr = IXMLDOMDocumentFragment_get_prefix(fragment, NULL);
8794 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8795 IXMLDOMDocumentFragment_Release(fragment);
8797 /* no prefix */
8798 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
8799 ok( hr == S_OK, "got 0x%08x\n", hr);
8801 hr = IXMLDOMElement_get_prefix(element, NULL);
8802 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8804 str = (void*)0xdeadbeef;
8805 hr = IXMLDOMElement_get_prefix(element, &str);
8806 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8807 ok( str == 0, "got %p\n", str);
8809 IXMLDOMElement_Release(element);
8811 /* with prefix */
8812 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
8813 ok( hr == S_OK, "got 0x%08x\n", hr);
8815 str = (void*)0xdeadbeef;
8816 hr = IXMLDOMElement_get_prefix(element, &str);
8817 ok( hr == S_OK, "got 0x%08x\n", hr);
8818 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
8819 SysFreeString(str);
8821 str = (void*)0xdeadbeef;
8822 hr = IXMLDOMElement_get_namespaceURI(element, &str);
8823 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8824 ok( str == 0, "got %p\n", str);
8826 IXMLDOMElement_Release(element);
8828 IXMLDOMDocument_Release(doc);
8829 free_bstrs();
8832 static void test_selectSingleNode(void)
8834 IXMLDOMDocument *doc;
8835 IXMLDOMNodeList *list;
8836 IXMLDOMNode *node;
8837 VARIANT_BOOL b;
8838 HRESULT hr;
8839 LONG len;
8840 BSTR str;
8842 doc = create_document(&IID_IXMLDOMDocument);
8843 if (!doc) return;
8845 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8846 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8848 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8849 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8851 str = SysAllocString( szComplete4 );
8852 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8853 ok( hr == S_OK, "loadXML failed\n");
8854 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8855 SysFreeString( str );
8857 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8858 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8860 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8861 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8863 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
8864 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8866 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
8867 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8869 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
8870 ok(hr == S_OK, "got 0x%08x\n", hr);
8871 IXMLDOMNode_Release(node);
8873 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
8874 ok(hr == S_OK, "got 0x%08x\n", hr);
8875 IXMLDOMNodeList_Release(list);
8877 list = (void*)0xdeadbeef;
8878 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
8879 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8880 ok(list == (void*)0xdeadbeef, "got %p\n", list);
8882 node = (void*)0xdeadbeef;
8883 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
8884 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8885 ok(node == 0, "got %p\n", node);
8887 list = (void*)0xdeadbeef;
8888 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
8889 ok(hr == S_OK, "got 0x%08x\n", hr);
8890 len = 1;
8891 hr = IXMLDOMNodeList_get_length(list, &len);
8892 ok(hr == S_OK, "got 0x%08x\n", hr);
8893 ok(len == 0, "got %d\n", len);
8894 IXMLDOMNodeList_Release(list);
8896 IXMLDOMDocument_Release(doc);
8897 free_bstrs();
8900 static void test_events(void)
8902 IConnectionPointContainer *conn;
8903 IConnectionPoint *point;
8904 IXMLDOMDocument *doc;
8905 HRESULT hr;
8906 VARIANT v;
8907 IDispatch *event;
8909 doc = create_document(&IID_IXMLDOMDocument);
8910 if (!doc) return;
8912 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&conn);
8913 ok(hr == S_OK, "got 0x%08x\n", hr);
8915 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IDispatch, &point);
8916 ok(hr == S_OK, "got 0x%08x\n", hr);
8917 IConnectionPoint_Release(point);
8918 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IPropertyNotifySink, &point);
8919 ok(hr == S_OK, "got 0x%08x\n", hr);
8920 IConnectionPoint_Release(point);
8921 hr = IConnectionPointContainer_FindConnectionPoint(conn, &DIID_XMLDOMDocumentEvents, &point);
8922 ok(hr == S_OK, "got 0x%08x\n", hr);
8923 IConnectionPoint_Release(point);
8925 IConnectionPointContainer_Release(conn);
8927 /* ready state callback */
8928 VariantInit(&v);
8929 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8930 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8932 event = create_dispevent();
8933 V_VT(&v) = VT_UNKNOWN;
8934 V_UNKNOWN(&v) = (IUnknown*)event;
8936 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8937 ok(hr == S_OK, "got 0x%08x\n", hr);
8938 EXPECT_REF(event, 2);
8940 V_VT(&v) = VT_DISPATCH;
8941 V_DISPATCH(&v) = event;
8943 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8944 ok(hr == S_OK, "got 0x%08x\n", hr);
8945 EXPECT_REF(event, 2);
8947 /* VT_NULL doesn't reset event handler */
8948 V_VT(&v) = VT_NULL;
8949 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8950 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8951 EXPECT_REF(event, 2);
8953 V_VT(&v) = VT_DISPATCH;
8954 V_DISPATCH(&v) = NULL;
8956 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8957 ok(hr == S_OK, "got 0x%08x\n", hr);
8958 EXPECT_REF(event, 1);
8960 V_VT(&v) = VT_UNKNOWN;
8961 V_DISPATCH(&v) = NULL;
8962 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8963 ok(hr == S_OK, "got 0x%08x\n", hr);
8965 IDispatch_Release(event);
8967 IXMLDOMDocument_Release(doc);
8970 static void test_createProcessingInstruction(void)
8972 static const WCHAR bodyW[] = {'t','e','s','t',0};
8973 IXMLDOMProcessingInstruction *pi;
8974 IXMLDOMDocument *doc;
8975 WCHAR buff[10];
8976 HRESULT hr;
8978 doc = create_document(&IID_IXMLDOMDocument);
8979 if (!doc) return;
8981 /* test for BSTR handling, pass broken BSTR */
8982 memcpy(&buff[2], bodyW, sizeof(bodyW));
8983 /* just a big length */
8984 *(DWORD*)buff = 0xf0f0;
8985 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("test"), &buff[2], &pi);
8986 ok(hr == S_OK, "got 0x%08x\n", hr);
8988 IXMLDOMProcessingInstruction_Release(pi);
8989 IXMLDOMDocument_Release(doc);
8992 static void test_put_nodeTypedValue(void)
8994 IXMLDOMDocument *doc;
8995 IXMLDOMElement *elem;
8996 VARIANT type;
8997 HRESULT hr;
8999 doc = create_document(&IID_IXMLDOMDocument);
9000 if (!doc) return;
9002 hr = IXMLDOMDocument_createElement(doc, _bstr_("Element"), &elem);
9003 ok(hr == S_OK, "got 0x%08x\n", hr);
9005 V_VT(&type) = VT_EMPTY;
9006 hr = IXMLDOMElement_get_dataType(elem, &type);
9007 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9008 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
9010 /* set typed value for untyped node */
9011 V_VT(&type) = VT_I1;
9012 V_I1(&type) = 1;
9013 hr = IXMLDOMElement_put_nodeTypedValue(elem, type);
9014 ok(hr == S_OK, "got 0x%08x\n", hr);
9016 V_VT(&type) = VT_EMPTY;
9017 hr = IXMLDOMElement_get_dataType(elem, &type);
9018 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9019 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
9021 /* no type info stored */
9022 V_VT(&type) = VT_EMPTY;
9023 hr = IXMLDOMElement_get_nodeTypedValue(elem, &type);
9024 ok(hr == S_OK, "got 0x%08x\n", hr);
9025 ok(V_VT(&type) == VT_BSTR, "got %d, expected VT_BSTR\n", V_VT(&type));
9026 ok(memcmp(V_BSTR(&type), _bstr_("1"), 2*sizeof(WCHAR)) == 0,
9027 "got %s, expected \"1\"\n", wine_dbgstr_w(V_BSTR(&type)));
9028 VariantClear(&type);
9030 IXMLDOMElement_Release(elem);
9031 IXMLDOMDocument_Release(doc);
9032 free_bstrs();
9035 static void test_get_xml(void)
9037 static const char xmlA[] = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<a>test</a>\r\n";
9038 static const char fooA[] = "<foo/>";
9039 IXMLDOMProcessingInstruction *pi;
9040 IXMLDOMNode *first;
9041 IXMLDOMElement *elem = NULL;
9042 IXMLDOMDocument *doc;
9043 VARIANT_BOOL b;
9044 VARIANT v;
9045 BSTR xml;
9046 HRESULT hr;
9048 doc = create_document(&IID_IXMLDOMDocument);
9049 if (!doc) return;
9051 b = VARIANT_TRUE;
9052 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
9053 ok(hr == S_OK, "got 0x%08x\n", hr);
9054 ok( b == VARIANT_TRUE, "got %d\n", b);
9056 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"),
9057 _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &pi);
9058 ok(hr == S_OK, "got 0x%08x\n", hr);
9060 hr = IXMLDOMDocument_get_firstChild(doc, &first);
9061 ok(hr == S_OK, "got 0x%08x\n", hr);
9063 V_UNKNOWN(&v) = (IUnknown*)first;
9064 V_VT(&v) = VT_UNKNOWN;
9066 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)pi, v, NULL);
9067 ok(hr == S_OK, "got 0x%08x\n", hr);
9069 IXMLDOMProcessingInstruction_Release(pi);
9070 IXMLDOMNode_Release(first);
9072 hr = IXMLDOMDocument_get_xml(doc, &xml);
9073 ok(hr == S_OK, "got 0x%08x\n", hr);
9075 ok(memcmp(xml, _bstr_(xmlA), sizeof(xmlA)*sizeof(WCHAR)) == 0,
9076 "got %s, expected %s\n", wine_dbgstr_w(xml), xmlA);
9077 SysFreeString(xml);
9079 IXMLDOMDocument_Release(doc);
9081 doc = create_document(&IID_IXMLDOMDocument);
9083 hr = IXMLDOMDocument_createElement(doc, _bstr_("foo"), &elem);
9084 ok(hr == S_OK, "got 0x%08x\n", hr);
9086 hr = IXMLDOMDocument_putref_documentElement(doc, elem);
9087 ok(hr == S_OK, "got 0x%08x\n", hr);
9089 hr = IXMLDOMDocument_get_xml(doc, &xml);
9090 ok(hr == S_OK, "got 0x%08x\n", hr);
9092 ok(memcmp(xml, _bstr_(fooA), (sizeof(fooA)-1)*sizeof(WCHAR)) == 0,
9093 "got %s, expected %s\n", wine_dbgstr_w(xml), fooA);
9094 SysFreeString(xml);
9096 IXMLDOMElement_Release(elem);
9097 IXMLDOMDocument_Release(doc);
9099 free_bstrs();
9102 static void test_xsltemplate(void)
9104 IXSLTemplate *template;
9105 IXSLProcessor *processor;
9106 IXMLDOMDocument *doc, *doc2;
9107 IStream *stream;
9108 VARIANT_BOOL b;
9109 HRESULT hr;
9110 ULONG ref1, ref2;
9111 VARIANT v;
9113 template = create_xsltemplate(&IID_IXSLTemplate);
9114 if (!template) return;
9116 /* works as reset */
9117 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9118 ok(hr == S_OK, "got 0x%08x\n", hr);
9120 doc = create_document(&IID_IXMLDOMDocument);
9122 b = VARIANT_TRUE;
9123 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
9124 ok(hr == S_OK, "got 0x%08x\n", hr);
9125 ok( b == VARIANT_TRUE, "got %d\n", b);
9127 /* putref with non-xsl document */
9128 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9129 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9131 b = VARIANT_TRUE;
9132 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9133 ok(hr == S_OK, "got 0x%08x\n", hr);
9134 ok( b == VARIANT_TRUE, "got %d\n", b);
9136 /* not a freethreaded document */
9137 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9138 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
9140 IXMLDOMDocument_Release(doc);
9142 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
9143 if (hr != S_OK)
9145 win_skip("failed to create free threaded document instance: 0x%08x\n", hr);
9146 IXSLTemplate_Release(template);
9147 return;
9150 b = VARIANT_TRUE;
9151 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
9152 ok(hr == S_OK, "got 0x%08x\n", hr);
9153 ok( b == VARIANT_TRUE, "got %d\n", b);
9155 /* freethreaded document */
9156 ref1 = IXMLDOMDocument_AddRef(doc);
9157 IXMLDOMDocument_Release(doc);
9158 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
9159 ok(hr == S_OK, "got 0x%08x\n", hr);
9160 ref2 = IXMLDOMDocument_AddRef(doc);
9161 IXMLDOMDocument_Release(doc);
9162 ok(ref2 > ref1, "got %d\n", ref2);
9164 /* processor */
9165 hr = IXSLTemplate_createProcessor(template, NULL);
9166 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9168 EXPECT_REF(template, 1);
9169 hr = IXSLTemplate_createProcessor(template, &processor);
9170 ok(hr == S_OK, "got 0x%08x\n", hr);
9171 EXPECT_REF(template, 2);
9173 /* input no set yet */
9174 V_VT(&v) = VT_BSTR;
9175 V_BSTR(&v) = NULL;
9176 hr = IXSLProcessor_get_input(processor, &v);
9177 todo_wine {
9178 ok(hr == S_OK, "got 0x%08x\n", hr);
9179 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
9182 hr = IXSLProcessor_get_output(processor, NULL);
9183 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9185 /* reset before it was set */
9186 V_VT(&v) = VT_EMPTY;
9187 hr = IXSLProcessor_put_output(processor, v);
9188 ok(hr == S_OK, "got 0x%08x\n", hr);
9190 CreateStreamOnHGlobal(NULL, TRUE, &stream);
9191 EXPECT_REF(stream, 1);
9193 V_VT(&v) = VT_UNKNOWN;
9194 V_UNKNOWN(&v) = (IUnknown*)stream;
9195 hr = IXSLProcessor_put_output(processor, v);
9196 ok(hr == S_OK, "got 0x%08x\n", hr);
9198 /* it seems processor grabs 2 references */
9199 todo_wine EXPECT_REF(stream, 3);
9201 V_VT(&v) = VT_EMPTY;
9202 hr = IXSLProcessor_get_output(processor, &v);
9203 ok(hr == S_OK, "got 0x%08x\n", hr);
9204 ok(V_VT(&v) == VT_UNKNOWN, "got type %d\n", V_VT(&v));
9205 ok(V_UNKNOWN(&v) == (IUnknown*)stream, "got %p\n", V_UNKNOWN(&v));
9207 todo_wine EXPECT_REF(stream, 4);
9208 VariantClear(&v);
9210 hr = IXSLProcessor_transform(processor, NULL);
9211 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9213 /* reset and check stream refcount */
9214 V_VT(&v) = VT_EMPTY;
9215 hr = IXSLProcessor_put_output(processor, v);
9216 ok(hr == S_OK, "got 0x%08x\n", hr);
9218 EXPECT_REF(stream, 1);
9220 IStream_Release(stream);
9222 /* no output interface set, check output */
9223 doc2 = create_document(&IID_IXMLDOMDocument);
9225 b = VARIANT_TRUE;
9226 hr = IXMLDOMDocument_loadXML( doc2, _bstr_("<a>test</a>"), &b );
9227 ok(hr == S_OK, "got 0x%08x\n", hr);
9228 ok( b == VARIANT_TRUE, "got %d\n", b);
9230 V_VT(&v) = VT_UNKNOWN;
9231 V_UNKNOWN(&v) = (IUnknown*)doc2;
9232 hr = IXSLProcessor_put_input(processor, v);
9233 ok(hr == S_OK, "got 0x%08x\n", hr);
9235 hr = IXSLProcessor_transform(processor, &b);
9236 ok(hr == S_OK, "got 0x%08x\n", hr);
9238 V_VT(&v) = VT_EMPTY;
9239 hr = IXSLProcessor_get_output(processor, &v);
9240 ok(hr == S_OK, "got 0x%08x\n", hr);
9241 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
9242 /* we currently output one '\n' instead of empty string */
9243 todo_wine ok(lstrcmpW(V_BSTR(&v), _bstr_("")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
9244 IXMLDOMDocument_Release(doc2);
9245 VariantClear(&v);
9247 IXSLProcessor_Release(processor);
9249 /* drop reference */
9250 hr = IXSLTemplate_putref_stylesheet(template, NULL);
9251 ok(hr == S_OK, "got 0x%08x\n", hr);
9252 ref2 = IXMLDOMDocument_AddRef(doc);
9253 IXMLDOMDocument_Release(doc);
9254 ok(ref2 == ref1, "got %d\n", ref2);
9256 IXMLDOMDocument_Release(doc);
9257 IXSLTemplate_Release(template);
9258 free_bstrs();
9261 static void test_insertBefore(void)
9263 IXMLDOMDocument *doc, *doc2;
9264 IXMLDOMAttribute *attr;
9265 IXMLDOMElement *elem1, *elem2, *elem3, *elem4, *elem5;
9266 IXMLDOMNode *node, *newnode;
9267 HRESULT hr;
9268 VARIANT v;
9269 BSTR p;
9271 doc = create_document(&IID_IXMLDOMDocument);
9273 /* insertBefore behaviour for attribute node */
9274 V_VT(&v) = VT_I4;
9275 V_I4(&v) = NODE_ATTRIBUTE;
9277 attr = NULL;
9278 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr"), NULL, (IXMLDOMNode**)&attr);
9279 ok(hr == S_OK, "got 0x%08x\n", hr);
9280 ok(attr != NULL, "got %p\n", attr);
9282 /* attribute to attribute */
9283 V_VT(&v) = VT_I4;
9284 V_I4(&v) = NODE_ATTRIBUTE;
9285 newnode = NULL;
9286 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr2"), NULL, &newnode);
9287 ok(hr == S_OK, "got 0x%08x\n", hr);
9288 ok(newnode != NULL, "got %p\n", newnode);
9290 V_VT(&v) = VT_NULL;
9291 node = (void*)0xdeadbeef;
9292 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9293 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9294 ok(node == NULL, "got %p\n", node);
9296 V_VT(&v) = VT_UNKNOWN;
9297 V_UNKNOWN(&v) = (IUnknown*)attr;
9298 node = (void*)0xdeadbeef;
9299 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9300 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9301 ok(node == NULL, "got %p\n", node);
9302 IXMLDOMNode_Release(newnode);
9304 /* cdata to attribute */
9305 V_VT(&v) = VT_I4;
9306 V_I4(&v) = NODE_CDATA_SECTION;
9307 newnode = NULL;
9308 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9309 ok(hr == S_OK, "got 0x%08x\n", hr);
9310 ok(newnode != NULL, "got %p\n", newnode);
9312 V_VT(&v) = VT_NULL;
9313 node = (void*)0xdeadbeef;
9314 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9315 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9316 ok(node == NULL, "got %p\n", node);
9317 IXMLDOMNode_Release(newnode);
9319 /* comment to attribute */
9320 V_VT(&v) = VT_I4;
9321 V_I4(&v) = NODE_COMMENT;
9322 newnode = NULL;
9323 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9324 ok(hr == S_OK, "got 0x%08x\n", hr);
9325 ok(newnode != NULL, "got %p\n", newnode);
9327 V_VT(&v) = VT_NULL;
9328 node = (void*)0xdeadbeef;
9329 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9330 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9331 ok(node == NULL, "got %p\n", node);
9332 IXMLDOMNode_Release(newnode);
9334 /* element to attribute */
9335 V_VT(&v) = VT_I4;
9336 V_I4(&v) = NODE_ELEMENT;
9337 newnode = NULL;
9338 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9339 ok(hr == S_OK, "got 0x%08x\n", hr);
9340 ok(newnode != NULL, "got %p\n", newnode);
9342 V_VT(&v) = VT_NULL;
9343 node = (void*)0xdeadbeef;
9344 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9345 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9346 ok(node == NULL, "got %p\n", node);
9347 IXMLDOMNode_Release(newnode);
9349 /* pi to attribute */
9350 V_VT(&v) = VT_I4;
9351 V_I4(&v) = NODE_PROCESSING_INSTRUCTION;
9352 newnode = NULL;
9353 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
9354 ok(hr == S_OK, "got 0x%08x\n", hr);
9355 ok(newnode != NULL, "got %p\n", newnode);
9357 V_VT(&v) = VT_NULL;
9358 node = (void*)0xdeadbeef;
9359 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
9360 ok(hr == E_FAIL, "got 0x%08x\n", hr);
9361 ok(node == NULL, "got %p\n", node);
9362 IXMLDOMNode_Release(newnode);
9363 IXMLDOMAttribute_Release(attr);
9365 /* insertBefore for elements */
9366 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem1);
9367 ok(hr == S_OK, "got 0x%08x\n", hr);
9369 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem2"), &elem2);
9370 ok(hr == S_OK, "got 0x%08x\n", hr);
9372 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
9373 ok(hr == S_OK, "got 0x%08x\n", hr);
9375 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
9376 ok(hr == S_OK, "got 0x%08x\n", hr);
9378 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem4"), &elem4);
9379 ok(hr == S_OK, "got 0x%08x\n", hr);
9381 EXPECT_NO_CHILDREN(elem1);
9382 EXPECT_NO_CHILDREN(elem2);
9383 EXPECT_NO_CHILDREN(elem3);
9385 todo_wine EXPECT_REF(elem2, 2);
9387 V_VT(&v) = VT_DISPATCH;
9388 V_DISPATCH(&v) = NULL;
9389 node = NULL;
9390 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem4, v, &node);
9391 ok(hr == S_OK, "got 0x%08x\n", hr);
9392 ok(node == (void*)elem4, "got %p\n", node);
9394 EXPECT_CHILDREN(elem1);
9395 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem4, NULL);
9396 EXPECT_HR(hr, S_OK);
9397 IXMLDOMElement_Release(elem4);
9399 EXPECT_NO_CHILDREN(elem1);
9401 V_VT(&v) = VT_NULL;
9402 node = NULL;
9403 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9404 ok(hr == S_OK, "got 0x%08x\n", hr);
9405 ok(node == (void*)elem2, "got %p\n", node);
9407 EXPECT_CHILDREN(elem1);
9408 todo_wine EXPECT_REF(elem2, 3);
9409 IXMLDOMNode_Release(node);
9411 /* again for already linked node */
9412 V_VT(&v) = VT_NULL;
9413 node = NULL;
9414 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
9415 ok(hr == S_OK, "got 0x%08x\n", hr);
9416 ok(node == (void*)elem2, "got %p\n", node);
9418 EXPECT_CHILDREN(elem1);
9420 /* increments each time */
9421 todo_wine EXPECT_REF(elem2, 3);
9422 IXMLDOMNode_Release(node);
9424 /* try to add to another element */
9425 V_VT(&v) = VT_NULL;
9426 node = (void*)0xdeadbeef;
9427 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem2, v, &node);
9428 ok(hr == S_OK, "got 0x%08x\n", hr);
9429 ok(node == (void*)elem2, "got %p\n", node);
9431 EXPECT_CHILDREN(elem3);
9432 EXPECT_NO_CHILDREN(elem1);
9434 IXMLDOMNode_Release(node);
9436 /* cross document case - try to add as child to a node created with other doc */
9437 doc2 = create_document(&IID_IXMLDOMDocument);
9439 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem4);
9440 ok(hr == S_OK, "got 0x%08x\n", hr);
9441 todo_wine EXPECT_REF(elem4, 2);
9443 /* same name, another instance */
9444 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem5);
9445 ok(hr == S_OK, "got 0x%08x\n", hr);
9446 todo_wine EXPECT_REF(elem5, 2);
9448 todo_wine EXPECT_REF(elem3, 2);
9449 V_VT(&v) = VT_NULL;
9450 node = NULL;
9451 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem4, v, &node);
9452 ok(hr == S_OK, "got 0x%08x\n", hr);
9453 ok(node == (void*)elem4, "got %p\n", node);
9454 todo_wine EXPECT_REF(elem4, 3);
9455 todo_wine EXPECT_REF(elem3, 2);
9456 IXMLDOMNode_Release(node);
9458 V_VT(&v) = VT_NULL;
9459 node = NULL;
9460 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem5, v, &node);
9461 ok(hr == S_OK, "got 0x%08x\n", hr);
9462 ok(node == (void*)elem5, "got %p\n", node);
9463 todo_wine EXPECT_REF(elem4, 2);
9464 todo_wine EXPECT_REF(elem5, 3);
9465 IXMLDOMNode_Release(node);
9467 IXMLDOMDocument_Release(doc2);
9469 IXMLDOMElement_Release(elem1);
9470 IXMLDOMElement_Release(elem2);
9471 IXMLDOMElement_Release(elem3);
9472 IXMLDOMElement_Release(elem4);
9473 IXMLDOMElement_Release(elem5);
9475 /* elements with same default namespace */
9476 V_VT(&v) = VT_I4;
9477 V_I4(&v) = NODE_ELEMENT;
9478 elem1 = NULL;
9479 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
9480 ok(hr == S_OK, "got 0x%08x\n", hr);
9481 ok(elem1 != NULL, "got %p\n", elem1);
9483 V_VT(&v) = VT_I4;
9484 V_I4(&v) = NODE_ELEMENT;
9485 elem2 = NULL;
9486 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem2);
9487 ok(hr == S_OK, "got 0x%08x\n", hr);
9488 ok(elem2 != NULL, "got %p\n", elem2);
9490 /* check contents so far */
9491 p = NULL;
9492 hr = IXMLDOMElement_get_xml(elem1, &p);
9493 ok(hr == S_OK, "got 0x%08x\n", hr);
9494 ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9495 SysFreeString(p);
9497 p = NULL;
9498 hr = IXMLDOMElement_get_xml(elem2, &p);
9499 ok(hr == S_OK, "got 0x%08x\n", hr);
9500 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9501 SysFreeString(p);
9503 V_VT(&v) = VT_NULL;
9504 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
9505 ok(hr == S_OK, "got 0x%08x\n", hr);
9507 /* get_xml depends on context, for top node it omits child namespace attribute,
9508 but at child level it's still returned */
9509 p = NULL;
9510 hr = IXMLDOMElement_get_xml(elem1, &p);
9511 ok(hr == S_OK, "got 0x%08x\n", hr);
9512 todo_wine ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"><elem2/></elem1>")),
9513 "got %s\n", wine_dbgstr_w(p));
9514 SysFreeString(p);
9516 p = NULL;
9517 hr = IXMLDOMElement_get_xml(elem2, &p);
9518 ok(hr == S_OK, "got 0x%08x\n", hr);
9519 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
9520 SysFreeString(p);
9522 IXMLDOMElement_Release(elem1);
9523 IXMLDOMElement_Release(elem2);
9525 /* child without default namespace added to node with default namespace */
9526 V_VT(&v) = VT_I4;
9527 V_I4(&v) = NODE_ELEMENT;
9528 elem1 = NULL;
9529 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
9530 ok(hr == S_OK, "got 0x%08x\n", hr);
9531 ok(elem1 != NULL, "got %p\n", elem1);
9533 V_VT(&v) = VT_I4;
9534 V_I4(&v) = NODE_ELEMENT;
9535 elem2 = NULL;
9536 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), NULL, (IXMLDOMNode**)&elem2);
9537 ok(hr == S_OK, "got 0x%08x\n", hr);
9538 ok(elem2 != NULL, "got %p\n", elem2);
9540 EXPECT_REF(elem2, 1);
9541 V_VT(&v) = VT_NULL;
9542 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
9543 ok(hr == S_OK, "got 0x%08x\n", hr);
9544 EXPECT_REF(elem2, 1);
9546 p = NULL;
9547 hr = IXMLDOMElement_get_xml(elem2, &p);
9548 ok(hr == S_OK, "got 0x%08x\n", hr);
9549 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
9550 SysFreeString(p);
9552 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem2, NULL);
9553 ok(hr == S_OK, "got 0x%08x\n", hr);
9555 p = NULL;
9556 hr = IXMLDOMElement_get_xml(elem2, &p);
9557 ok(hr == S_OK, "got 0x%08x\n", hr);
9558 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
9559 SysFreeString(p);
9561 IXMLDOMElement_Release(elem1);
9562 IXMLDOMElement_Release(elem2);
9563 IXMLDOMDocument_Release(doc);
9566 static void test_appendChild(void)
9568 IXMLDOMDocument *doc, *doc2;
9569 IXMLDOMElement *elem, *elem2;
9570 HRESULT hr;
9572 doc = create_document(&IID_IXMLDOMDocument);
9573 doc2 = create_document(&IID_IXMLDOMDocument);
9575 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
9576 ok(hr == S_OK, "got 0x%08x\n", hr);
9578 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem2"), &elem2);
9579 ok(hr == S_OK, "got 0x%08x\n", hr);
9581 EXPECT_REF(doc, 1);
9582 todo_wine EXPECT_REF(elem, 2);
9583 EXPECT_REF(doc2, 1);
9584 todo_wine EXPECT_REF(elem2, 2);
9585 EXPECT_NO_CHILDREN(doc);
9586 EXPECT_NO_CHILDREN(doc2);
9588 /* append from another document */
9589 hr = IXMLDOMDocument_appendChild(doc2, (IXMLDOMNode*)elem, NULL);
9590 ok(hr == S_OK, "got 0x%08x\n", hr);
9592 EXPECT_REF(doc, 1);
9593 todo_wine EXPECT_REF(elem, 2);
9594 EXPECT_REF(doc2, 1);
9595 todo_wine EXPECT_REF(elem2, 2);
9596 EXPECT_NO_CHILDREN(doc);
9597 EXPECT_CHILDREN(doc2);
9599 IXMLDOMElement_Release(elem);
9600 IXMLDOMElement_Release(elem2);
9601 IXMLDOMDocument_Release(doc);
9602 IXMLDOMDocument_Release(doc2);
9605 static void test_get_doctype(void)
9607 IXMLDOMDocumentType *doctype;
9608 IXMLDOMDocument *doc;
9609 HRESULT hr;
9611 doc = create_document(&IID_IXMLDOMDocument);
9613 hr = IXMLDOMDocument_get_doctype(doc, NULL);
9614 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9616 doctype = (void*)0xdeadbeef;
9617 hr = IXMLDOMDocument_get_doctype(doc, &doctype);
9618 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9619 ok(doctype == NULL, "got %p\n", doctype);
9621 IXMLDOMDocument_Release(doc);
9624 static void test_get_tagName(void)
9626 IXMLDOMDocument *doc;
9627 IXMLDOMElement *elem, *elem2;
9628 HRESULT hr;
9629 BSTR str;
9631 doc = create_document(&IID_IXMLDOMDocument);
9633 hr = IXMLDOMDocument_createElement(doc, _bstr_("element"), &elem);
9634 ok(hr == S_OK, "got 0x%08x\n", hr);
9636 hr = IXMLDOMElement_get_tagName(elem, NULL);
9637 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9639 str = NULL;
9640 hr = IXMLDOMElement_get_tagName(elem, &str);
9641 ok(hr == S_OK, "got 0x%08x\n", hr);
9642 ok(!lstrcmpW(str, _bstr_("element")), "got %s\n", wine_dbgstr_w(str));
9643 SysFreeString(str);
9645 hr = IXMLDOMDocument_createElement(doc, _bstr_("s:element"), &elem2);
9646 ok(hr == S_OK, "got 0x%08x\n", hr);
9648 str = NULL;
9649 hr = IXMLDOMElement_get_tagName(elem2, &str);
9650 ok(hr == S_OK, "got 0x%08x\n", hr);
9651 ok(!lstrcmpW(str, _bstr_("s:element")), "got %s\n", wine_dbgstr_w(str));
9652 SysFreeString(str);
9654 IXMLDOMDocument_Release(elem);
9655 IXMLDOMDocument_Release(elem2);
9656 IXMLDOMDocument_Release(doc);
9657 free_bstrs();
9660 typedef struct _get_datatype_t {
9661 DOMNodeType type;
9662 const char *name;
9663 VARTYPE vt;
9664 HRESULT hr;
9665 } get_datatype_t;
9667 static const get_datatype_t get_datatype[] = {
9668 { NODE_ELEMENT, "element", VT_NULL, S_FALSE },
9669 { NODE_ATTRIBUTE, "attr", VT_NULL, S_FALSE },
9670 { NODE_TEXT, "text", VT_NULL, S_FALSE },
9671 { NODE_CDATA_SECTION , "cdata", VT_NULL, S_FALSE },
9672 { NODE_ENTITY_REFERENCE, "entityref", VT_NULL, S_FALSE },
9673 { NODE_PROCESSING_INSTRUCTION, "pi", VT_NULL, S_FALSE },
9674 { NODE_COMMENT, "comment", VT_NULL, S_FALSE },
9675 { NODE_DOCUMENT_FRAGMENT, "docfrag", VT_NULL, S_FALSE },
9676 { 0 }
9679 static void test_get_dataType(void)
9681 IXMLDOMDocument *doc;
9682 const get_datatype_t *entry = get_datatype;
9684 doc = create_document(&IID_IXMLDOMDocument);
9686 while (entry->type)
9688 IXMLDOMNode *node = NULL;
9689 VARIANT var, type;
9690 HRESULT hr;
9692 V_VT(&var) = VT_I4;
9693 V_I4(&var) = entry->type;
9694 hr = IXMLDOMDocument_createNode(doc, var, _bstr_(entry->name), NULL, &node);
9695 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9697 hr = IXMLDOMNode_get_dataType(node, NULL);
9698 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9700 VariantInit(&type);
9701 hr = IXMLDOMNode_get_dataType(node, &type);
9702 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9703 hr, entry->hr, entry->type);
9704 ok(V_VT(&type) == entry->vt, "got %d, expected %d. node type %d\n",
9705 V_VT(&type), entry->vt, entry->type);
9706 VariantClear(&type);
9708 IXMLDOMNode_Release(node);
9710 entry++;
9713 IXMLDOMDocument_Release(doc);
9714 free_bstrs();
9717 typedef struct _get_node_typestring_t {
9718 DOMNodeType type;
9719 const char *string;
9720 } get_node_typestring_t;
9722 static const get_node_typestring_t get_node_typestring[] = {
9723 { NODE_ELEMENT, "element" },
9724 { NODE_ATTRIBUTE, "attribute" },
9725 { NODE_TEXT, "text" },
9726 { NODE_CDATA_SECTION , "cdatasection" },
9727 { NODE_ENTITY_REFERENCE, "entityreference" },
9728 { NODE_PROCESSING_INSTRUCTION, "processinginstruction" },
9729 { NODE_COMMENT, "comment" },
9730 { NODE_DOCUMENT_FRAGMENT, "documentfragment" },
9731 { 0 }
9734 static void test_get_nodeTypeString(void)
9736 const get_node_typestring_t *entry = get_node_typestring;
9737 IXMLDOMDocument *doc;
9738 HRESULT hr;
9739 BSTR str;
9741 doc = create_document(&IID_IXMLDOMDocument);
9743 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
9744 ok(hr == S_OK, "got 0x%08x\n", hr);
9745 ok(!lstrcmpW(str, _bstr_("document")), "got string %s\n", wine_dbgstr_w(str));
9746 SysFreeString(str);
9748 while (entry->type)
9750 IXMLDOMNode *node = NULL;
9751 VARIANT var;
9753 V_VT(&var) = VT_I4;
9754 V_I4(&var) = entry->type;
9755 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9756 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9758 hr = IXMLDOMNode_get_nodeTypeString(node, NULL);
9759 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9761 hr = IXMLDOMNode_get_nodeTypeString(node, &str);
9762 ok(hr == S_OK, "got 0x%08x\n", hr);
9763 ok(!lstrcmpW(str, _bstr_(entry->string)), "got string %s, expected %s. node type %d\n",
9764 wine_dbgstr_w(str), entry->string, entry->type);
9765 SysFreeString(str);
9766 IXMLDOMNode_Release(node);
9768 entry++;
9771 IXMLDOMDocument_Release(doc);
9772 free_bstrs();
9775 typedef struct _get_attributes_t {
9776 DOMNodeType type;
9777 HRESULT hr;
9778 } get_attributes_t;
9780 static const get_attributes_t get_attributes[] = {
9781 { NODE_ATTRIBUTE, S_FALSE },
9782 { NODE_TEXT, S_FALSE },
9783 { NODE_CDATA_SECTION , S_FALSE },
9784 { NODE_ENTITY_REFERENCE, S_FALSE },
9785 { NODE_PROCESSING_INSTRUCTION, S_FALSE },
9786 { NODE_COMMENT, S_FALSE },
9787 { NODE_DOCUMENT_FRAGMENT, S_FALSE },
9788 { 0 }
9791 static void test_get_attributes(void)
9793 const get_attributes_t *entry = get_attributes;
9794 IXMLDOMNamedNodeMap *map;
9795 IXMLDOMDocument *doc;
9796 IXMLDOMNode *node, *node2;
9797 VARIANT_BOOL b;
9798 HRESULT hr;
9799 BSTR str;
9800 LONG length;
9802 doc = create_document(&IID_IXMLDOMDocument);
9804 str = SysAllocString( szComplete4 );
9805 hr = IXMLDOMDocument_loadXML(doc, str, &b);
9806 ok(hr == S_OK, "got %08x\n", hr);
9807 SysFreeString(str);
9809 hr = IXMLDOMDocument_get_attributes(doc, NULL);
9810 ok(hr == E_INVALIDARG, "got %08x\n", hr);
9812 map = (void*)0xdeadbeef;
9813 hr = IXMLDOMDocument_get_attributes(doc, &map);
9814 ok(hr == S_FALSE, "got %08x\n", hr);
9815 ok(map == NULL, "got %p\n", map);
9817 /* first child is <?xml ?> */
9818 hr = IXMLDOMDocument_get_firstChild(doc, &node);
9819 ok(hr == S_OK, "got %08x\n", hr);
9821 hr = IXMLDOMNode_get_attributes(node, &map);
9822 ok(hr == S_OK, "got %08x\n", hr);
9824 length = -1;
9825 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9826 EXPECT_HR(hr, S_OK);
9827 todo_wine ok(length == 1, "got %d\n", length);
9829 if (hr == S_OK && length == 1)
9831 IXMLDOMAttribute *attr;
9832 DOMNodeType type;
9833 VARIANT v;
9835 node2 = NULL;
9836 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9837 EXPECT_HR(hr, S_OK);
9838 ok(node != NULL, "got %p\n", node2);
9840 hr = IXMLDOMNode_get_nodeName(node2, &str);
9841 EXPECT_HR(hr, S_OK);
9842 ok(!lstrcmpW(str, _bstr_("version")), "got %s\n", wine_dbgstr_w(str));
9843 SysFreeString(str);
9845 length = -1;
9846 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9847 EXPECT_HR(hr, S_OK);
9848 ok(length == 1, "got %d\n", length);
9850 type = -1;
9851 hr = IXMLDOMNode_get_nodeType(node2, &type);
9852 EXPECT_HR(hr, S_OK);
9853 ok(type == NODE_ATTRIBUTE, "got %d\n", type);
9855 hr = IXMLDOMNode_get_xml(node, &str);
9856 EXPECT_HR(hr, S_OK);
9857 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9858 SysFreeString(str);
9860 hr = IXMLDOMNode_get_text(node, &str);
9861 EXPECT_HR(hr, S_OK);
9862 ok(!lstrcmpW(str, _bstr_("version=\"1.0\"")), "got %s\n", wine_dbgstr_w(str));
9863 SysFreeString(str);
9865 hr = IXMLDOMNamedNodeMap_removeNamedItem(map, _bstr_("version"), NULL);
9866 EXPECT_HR(hr, S_OK);
9868 length = -1;
9869 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9870 EXPECT_HR(hr, S_OK);
9871 ok(length == 0, "got %d\n", length);
9873 hr = IXMLDOMNode_get_xml(node, &str);
9874 EXPECT_HR(hr, S_OK);
9875 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9876 SysFreeString(str);
9878 hr = IXMLDOMNode_get_text(node, &str);
9879 EXPECT_HR(hr, S_OK);
9880 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
9881 SysFreeString(str);
9883 IXMLDOMNamedNodeMap_Release(map);
9885 hr = IXMLDOMNode_get_attributes(node, &map);
9886 ok(hr == S_OK, "got %08x\n", hr);
9888 length = -1;
9889 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9890 EXPECT_HR(hr, S_OK);
9891 ok(length == 0, "got %d\n", length);
9893 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("encoding"), &attr);
9894 EXPECT_HR(hr, S_OK);
9896 V_VT(&v) = VT_BSTR;
9897 V_BSTR(&v) = _bstr_("UTF-8");
9898 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
9899 EXPECT_HR(hr, S_OK);
9901 EXPECT_REF(attr, 2);
9902 hr = IXMLDOMNamedNodeMap_setNamedItem(map, (IXMLDOMNode*)attr, NULL);
9903 EXPECT_HR(hr, S_OK);
9904 EXPECT_REF(attr, 2);
9906 hr = IXMLDOMNode_get_attributes(node, &map);
9907 ok(hr == S_OK, "got %08x\n", hr);
9909 length = -1;
9910 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9911 EXPECT_HR(hr, S_OK);
9912 ok(length == 1, "got %d\n", length);
9914 hr = IXMLDOMNode_get_xml(node, &str);
9915 EXPECT_HR(hr, S_OK);
9916 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9917 SysFreeString(str);
9919 hr = IXMLDOMNode_get_text(node, &str);
9920 EXPECT_HR(hr, S_OK);
9921 ok(!lstrcmpW(str, _bstr_("encoding=\"UTF-8\"")), "got %s\n", wine_dbgstr_w(str));
9922 SysFreeString(str);
9924 IXMLDOMNamedNodeMap_Release(map);
9925 IXMLDOMNode_Release(node2);
9928 IXMLDOMNode_Release(node);
9930 /* last child is element */
9931 EXPECT_REF(doc, 1);
9932 hr = IXMLDOMDocument_get_lastChild(doc, &node);
9933 ok(hr == S_OK, "got %08x\n", hr);
9934 EXPECT_REF(doc, 1);
9936 EXPECT_REF(node, 1);
9937 hr = IXMLDOMNode_get_attributes(node, &map);
9938 ok(hr == S_OK, "got %08x\n", hr);
9939 EXPECT_REF(node, 1);
9940 EXPECT_REF(doc, 1);
9942 EXPECT_REF(map, 1);
9943 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9944 ok(hr == S_OK, "got %08x\n", hr);
9945 EXPECT_REF(node, 1);
9946 EXPECT_REF(node2, 1);
9947 EXPECT_REF(map, 1);
9948 EXPECT_REF(doc, 1);
9949 IXMLDOMNode_Release(node2);
9951 /* release node before map release, map still works */
9952 IXMLDOMNode_Release(node);
9954 length = 0;
9955 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9956 ok(hr == S_OK, "got %08x\n", hr);
9957 ok(length == 1, "got %d\n", length);
9959 node2 = NULL;
9960 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9961 ok(hr == S_OK, "got %08x\n", hr);
9962 EXPECT_REF(node2, 1);
9963 IXMLDOMNode_Release(node2);
9965 IXMLDOMNamedNodeMap_Release(map);
9967 while (entry->type)
9969 VARIANT var;
9971 node = NULL;
9973 V_VT(&var) = VT_I4;
9974 V_I4(&var) = entry->type;
9975 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9976 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9978 hr = IXMLDOMNode_get_attributes(node, NULL);
9979 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9981 map = (void*)0xdeadbeef;
9982 hr = IXMLDOMNode_get_attributes(node, &map);
9983 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9984 hr, entry->hr, entry->type);
9985 ok(map == NULL, "got %p\n", map);
9987 IXMLDOMNode_Release(node);
9989 entry++;
9992 IXMLDOMDocument_Release(doc);
9993 free_bstrs();
9996 static void test_selection(void)
9998 IXMLDOMSelection *selection, *selection2;
9999 IEnumVARIANT *enum1, *enum2, *enum3;
10000 IXMLDOMNodeList *list;
10001 IXMLDOMDocument *doc;
10002 IXMLDOMNode *node;
10003 IDispatch *disp;
10004 VARIANT_BOOL b;
10005 HRESULT hr;
10006 VARIANT v;
10007 BSTR name;
10008 ULONG ret;
10009 LONG len;
10011 doc = create_document(&IID_IXMLDOMDocument);
10013 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
10014 EXPECT_HR(hr, S_OK);
10016 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list);
10017 EXPECT_HR(hr, S_OK);
10019 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
10020 EXPECT_HR(hr, S_OK);
10021 IXMLDOMSelection_Release(selection);
10023 /* IEnumVARIANT tests */
10024 enum1 = NULL;
10025 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IEnumVARIANT, (void**)&enum1);
10026 EXPECT_HR(hr, S_OK);
10027 ok(enum1 != NULL, "got %p\n", enum1);
10028 EXPECT_REF(enum1, 2);
10030 enum3 = NULL;
10031 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IEnumVARIANT, (void**)&enum3);
10032 EXPECT_HR(hr, S_OK);
10033 ok(enum3 != NULL, "got %p\n", enum3);
10034 ok(enum1 == enum3, "got %p and %p\n", enum1, enum3);
10035 EXPECT_REF(enum1, 3);
10036 IEnumVARIANT_Release(enum3);
10038 EXPECT_REF(selection, 1);
10039 EXPECT_REF(enum1, 2);
10041 enum2 = NULL;
10042 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum2);
10043 EXPECT_HR(hr, S_OK);
10044 ok(enum2 != NULL, "got %p\n", enum2);
10046 EXPECT_REF(selection, 2);
10047 EXPECT_REF(enum1, 2);
10048 EXPECT_REF(enum2, 1);
10050 ok(enum1 != enum2, "got %p, %p\n", enum1, enum2);
10052 selection2 = NULL;
10053 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IXMLDOMSelection, (void**)&selection2);
10054 EXPECT_HR(hr, S_OK);
10055 ok(selection2 == selection, "got %p and %p\n", selection, selection2);
10056 EXPECT_REF(selection, 3);
10057 EXPECT_REF(enum1, 2);
10059 IXMLDOMSelection_Release(selection2);
10061 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IDispatch, (void**)&disp);
10062 EXPECT_HR(hr, S_OK);
10063 EXPECT_REF(selection, 3);
10064 IDispatch_Release(disp);
10066 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IEnumVARIANT, (void**)&enum3);
10067 EXPECT_HR(hr, S_OK);
10068 ok(enum3 == enum1, "got %p and %p\n", enum3, enum1);
10069 EXPECT_REF(selection, 2);
10070 EXPECT_REF(enum1, 3);
10072 IEnumVARIANT_Release(enum1);
10073 IEnumVARIANT_Release(enum2);
10075 enum1 = NULL;
10076 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum1);
10077 EXPECT_HR(hr, S_OK);
10078 ok(enum1 != NULL, "got %p\n", enum1);
10079 EXPECT_REF(enum1, 1);
10080 EXPECT_REF(selection, 2);
10082 enum2 = NULL;
10083 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum2);
10084 EXPECT_HR(hr, S_OK);
10085 ok(enum2 != NULL, "got %p\n", enum2);
10086 EXPECT_REF(enum2, 1);
10087 EXPECT_REF(selection, 3);
10089 ok(enum1 != enum2, "got %p, %p\n", enum1, enum2);
10091 IEnumVARIANT_AddRef(enum1);
10092 EXPECT_REF(selection, 3);
10093 EXPECT_REF(enum1, 2);
10094 EXPECT_REF(enum2, 1);
10095 IEnumVARIANT_Release(enum1);
10097 IEnumVARIANT_Release(enum1);
10098 IEnumVARIANT_Release(enum2);
10100 EXPECT_REF(selection, 1);
10102 IXMLDOMNodeList_Release(list);
10104 hr = IXMLDOMDocument_get_childNodes(doc, &list);
10105 EXPECT_HR(hr, S_OK);
10107 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
10108 EXPECT_HR(hr, E_NOINTERFACE);
10110 IXMLDOMNodeList_Release(list);
10112 /* test if IEnumVARIANT touches selection context */
10113 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(xpath_simple_list), &b);
10114 EXPECT_HR(hr, S_OK);
10116 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root/*"), &list);
10117 EXPECT_HR(hr, S_OK);
10119 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
10120 EXPECT_HR(hr, S_OK);
10122 len = 0;
10123 hr = IXMLDOMSelection_get_length(selection, &len);
10124 EXPECT_HR(hr, S_OK);
10125 ok(len == 4, "got %d\n", len);
10127 enum1 = NULL;
10128 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum1);
10129 EXPECT_HR(hr, S_OK);
10131 /* no-op if zero count */
10132 V_VT(&v) = VT_I2;
10133 hr = IEnumVARIANT_Next(enum1, 0, &v, NULL);
10134 EXPECT_HR(hr, S_OK);
10135 ok(V_VT(&v) == VT_I2, "got var type %d\n", V_VT(&v));
10137 /* positive count, null array pointer */
10138 hr = IEnumVARIANT_Next(enum1, 1, NULL, NULL);
10139 EXPECT_HR(hr, E_INVALIDARG);
10141 ret = 1;
10142 hr = IEnumVARIANT_Next(enum1, 1, NULL, &ret);
10143 EXPECT_HR(hr, E_INVALIDARG);
10144 ok(ret == 0, "got %d\n", ret);
10146 V_VT(&v) = VT_I2;
10147 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
10148 EXPECT_HR(hr, S_OK);
10149 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
10151 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
10152 EXPECT_HR(hr, S_OK);
10153 hr = IXMLDOMNode_get_nodeName(node, &name);
10154 EXPECT_HR(hr, S_OK);
10155 ok(!lstrcmpW(name, _bstr_("a")), "got node name %s\n", wine_dbgstr_w(name));
10156 SysFreeString(name);
10157 IXMLDOMNode_Release(node);
10158 VariantClear(&v);
10160 /* list cursor is updated */
10161 hr = IXMLDOMSelection_nextNode(selection, &node);
10162 EXPECT_HR(hr, S_OK);
10163 hr = IXMLDOMNode_get_nodeName(node, &name);
10164 EXPECT_HR(hr, S_OK);
10165 ok(!lstrcmpW(name, _bstr_("c")), "got node name %s\n", wine_dbgstr_w(name));
10166 IXMLDOMNode_Release(node);
10168 V_VT(&v) = VT_I2;
10169 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
10170 EXPECT_HR(hr, S_OK);
10171 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
10172 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
10173 EXPECT_HR(hr, S_OK);
10174 hr = IXMLDOMNode_get_nodeName(node, &name);
10175 EXPECT_HR(hr, S_OK);
10176 ok(!lstrcmpW(name, _bstr_("b")), "got node name %s\n", wine_dbgstr_w(name));
10177 SysFreeString(name);
10178 IXMLDOMNode_Release(node);
10179 VariantClear(&v);
10181 hr = IXMLDOMSelection_nextNode(selection, &node);
10182 EXPECT_HR(hr, S_OK);
10183 hr = IXMLDOMNode_get_nodeName(node, &name);
10184 EXPECT_HR(hr, S_OK);
10185 ok(!lstrcmpW(name, _bstr_("d")), "got node name %s\n", wine_dbgstr_w(name));
10186 IXMLDOMNode_Release(node);
10188 IXMLDOMSelection_Release(selection);
10189 IXMLDOMNodeList_Release(list);
10190 IXMLDOMDocument_Release(doc);
10192 free_bstrs();
10195 static void test_load(void)
10197 IXMLDOMDocument *doc;
10198 IXMLDOMNodeList *list;
10199 VARIANT_BOOL b;
10200 HANDLE hfile;
10201 VARIANT src;
10202 HRESULT hr;
10203 BOOL ret;
10204 BSTR path, bstr1, bstr2;
10205 DWORD written;
10206 void* ptr;
10208 /* prepare a file */
10209 hfile = CreateFileA("test.xml", GENERIC_WRITE|GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
10210 ok(hfile != INVALID_HANDLE_VALUE, "failed to create test file\n");
10211 if(hfile == INVALID_HANDLE_VALUE) return;
10213 ret = WriteFile(hfile, szNonUnicodeXML, sizeof(szNonUnicodeXML)-1, &written, NULL);
10214 ok(ret, "WriteFile failed\n");
10216 CloseHandle(hfile);
10218 doc = create_document(&IID_IXMLDOMDocument);
10220 path = _bstr_("test.xml");
10222 /* load from path: VT_BSTR */
10223 V_VT(&src) = VT_BSTR;
10224 V_BSTR(&src) = path;
10225 hr = IXMLDOMDocument_load(doc, src, &b);
10226 EXPECT_HR(hr, S_OK);
10227 ok(b == VARIANT_TRUE, "got %d\n", b);
10229 /* load from a path: VT_BSTR|VT_BYREF */
10230 V_VT(&src) = VT_BSTR | VT_BYREF;
10231 V_BSTRREF(&src) = &path;
10232 hr = IXMLDOMDocument_load(doc, src, &b);
10233 EXPECT_HR(hr, S_OK);
10234 ok(b == VARIANT_TRUE, "got %d\n", b);
10236 /* load from a path: VT_BSTR|VT_BYREF, null ptr */
10237 V_VT(&src) = VT_BSTR | VT_BYREF;
10238 V_BSTRREF(&src) = NULL;
10239 hr = IXMLDOMDocument_load(doc, src, &b);
10240 EXPECT_HR(hr, E_INVALIDARG);
10241 ok(b == VARIANT_FALSE, "got %d\n", b);
10243 IXMLDOMDocument_Release(doc);
10245 DeleteFileA("test.xml");
10247 doc = create_document(&IID_IXMLDOMDocument);
10249 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b);
10250 EXPECT_HR(hr, S_OK);
10251 ok(b == VARIANT_TRUE, "got %d\n", b);
10253 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
10254 EXPECT_HR(hr, S_OK);
10255 bstr1 = _bstr_(list_to_string(list));
10257 hr = IXMLDOMNodeList_reset(list);
10258 EXPECT_HR(hr, S_OK);
10260 IXMLDOMDocument_Release(doc);
10262 doc = create_document(&IID_IXMLDOMDocument);
10264 VariantInit(&src);
10265 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenA(szExampleXML));
10266 V_VT(&src) = VT_ARRAY|VT_UI1;
10267 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10268 ptr = NULL;
10269 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10270 EXPECT_HR(hr, S_OK);
10271 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10273 memcpy(ptr, szExampleXML, lstrlenA(szExampleXML));
10274 hr = SafeArrayUnlock(V_ARRAY(&src));
10275 EXPECT_HR(hr, S_OK);
10277 hr = IXMLDOMDocument_load(doc, src, &b);
10278 EXPECT_HR(hr, S_OK);
10279 ok(b == VARIANT_TRUE, "got %d\n", b);
10281 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
10282 EXPECT_HR(hr, S_OK);
10283 bstr2 = _bstr_(list_to_string(list));
10285 hr = IXMLDOMNodeList_reset(list);
10286 EXPECT_HR(hr, S_OK);
10288 ok(lstrcmpW(bstr1, bstr2) == 0, "strings not equal: %s : %s\n",
10289 wine_dbgstr_w(bstr1), wine_dbgstr_w(bstr2));
10291 IXMLDOMDocument_Release(doc);
10292 IXMLDOMNodeList_Release(list);
10293 VariantClear(&src);
10295 /* UTF-16 isn't accepted */
10296 doc = create_document(&IID_IXMLDOMDocument);
10298 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenW(szComplete1) * sizeof(WCHAR));
10299 V_VT(&src) = VT_ARRAY|VT_UI1;
10300 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10301 ptr = NULL;
10302 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10303 EXPECT_HR(hr, S_OK);
10304 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10306 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
10307 hr = SafeArrayUnlock(V_ARRAY(&src));
10308 EXPECT_HR(hr, S_OK);
10310 hr = IXMLDOMDocument_load(doc, src, &b);
10311 todo_wine EXPECT_HR(hr, S_FALSE);
10312 todo_wine ok(b == VARIANT_FALSE, "got %d\n", b);
10314 VariantClear(&src);
10316 /* it doesn't like it as a VT_ARRAY|VT_UI2 either */
10317 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI2, 0, lstrlenW(szComplete1));
10318 V_VT(&src) = VT_ARRAY|VT_UI2;
10319 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
10320 ptr = NULL;
10321 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
10322 EXPECT_HR(hr, S_OK);
10323 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
10325 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
10326 hr = SafeArrayUnlock(V_ARRAY(&src));
10327 EXPECT_HR(hr, S_OK);
10329 hr = IXMLDOMDocument_load(doc, src, &b);
10330 todo_wine EXPECT_HR(hr, E_INVALIDARG);
10331 ok(b == VARIANT_FALSE, "got %d\n", b);
10333 VariantClear(&src);
10334 IXMLDOMDocument_Release(doc);
10336 free_bstrs();
10339 static void test_nsnamespacemanager(void)
10341 static const char xmluriA[] = "http://www.w3.org/XML/1998/namespace";
10342 IMXNamespaceManager *nsmgr;
10343 IVBMXNamespaceManager *mgr2;
10344 IDispatch *disp;
10345 HRESULT hr;
10346 WCHAR buffW[250];
10347 INT len;
10349 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10350 &IID_IMXNamespaceManager, (void**)&nsmgr);
10351 if (hr != S_OK)
10353 win_skip("MXNamespaceManager is not available\n");
10354 return;
10357 /* IMXNamespaceManager inherits from IUnknown */
10358 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IDispatch, (void**)&disp);
10359 EXPECT_HR(hr, S_OK);
10360 IDispatch_Release(disp);
10362 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IVBMXNamespaceManager, (void**)&mgr2);
10363 EXPECT_HR(hr, S_OK);
10364 IVBMXNamespaceManager_Release(mgr2);
10366 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
10367 EXPECT_HR(hr, S_OK);
10369 /* prefix already added */
10370 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10371 EXPECT_HR(hr, S_FALSE);
10373 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), NULL);
10374 EXPECT_HR(hr, E_INVALIDARG);
10376 /* "xml" and "xmlns" are not allowed here */
10377 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xml"), _bstr_("uri1"));
10378 EXPECT_HR(hr, E_INVALIDARG);
10380 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xmlns"), _bstr_("uri1"));
10381 EXPECT_HR(hr, E_INVALIDARG);
10382 todo_wine {
10383 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, -1, NULL, NULL);
10384 EXPECT_HR(hr, E_FAIL);
10386 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, NULL);
10387 EXPECT_HR(hr, E_POINTER);
10389 len = -1;
10390 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, &len);
10391 EXPECT_HR(hr, S_OK);
10392 ok(len == 3, "got %d\n", len);
10394 len = -1;
10395 buffW[0] = 0x1;
10396 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10397 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
10398 ok(len == -1, "got %d\n", len);
10399 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10401 len = 10;
10402 buffW[0] = 0x1;
10403 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10404 EXPECT_HR(hr, S_OK);
10405 ok(len == 3, "got %d\n", len);
10406 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10408 /* getURI */
10409 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, NULL);
10410 EXPECT_HR(hr, E_INVALIDARG);
10412 len = -1;
10413 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, &len);
10414 EXPECT_HR(hr, E_INVALIDARG);
10415 ok(len == -1, "got %d\n", len);
10417 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, NULL);
10418 EXPECT_HR(hr, E_POINTER);
10420 len = -1;
10421 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, &len);
10422 EXPECT_HR(hr, S_OK);
10423 /* length of "xml" uri is constant */
10424 ok(len == strlen(xmluriA), "got %d\n", len);
10426 len = 100;
10427 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
10428 EXPECT_HR(hr, S_OK);
10429 ok(len == strlen(xmluriA), "got %d\n", len);
10430 ok(!lstrcmpW(buffW, _bstr_(xmluriA)), "got prefix %s\n", wine_dbgstr_w(buffW));
10432 len = strlen(xmluriA)-1;
10433 buffW[0] = 0x1;
10434 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
10435 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
10436 ok(len == strlen(xmluriA)-1, "got %d\n", len);
10437 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10439 /* prefix xml1 not defined */
10440 len = -1;
10441 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, NULL, &len);
10442 EXPECT_HR(hr, S_FALSE);
10443 ok(len == 0, "got %d\n", len);
10445 len = 100;
10446 buffW[0] = 0x1;
10447 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, buffW, &len);
10448 EXPECT_HR(hr, S_FALSE);
10449 ok(buffW[0] == 0, "got %x\n", buffW[0]);
10450 ok(len == 0, "got %d\n", len);
10452 IMXNamespaceManager_Release(nsmgr);
10454 free_bstrs();
10457 static void test_nsnamespacemanager_override(void)
10459 IMXNamespaceManager *nsmgr;
10460 WCHAR buffW[250];
10461 VARIANT_BOOL b;
10462 HRESULT hr;
10463 INT len;
10465 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10466 &IID_IMXNamespaceManager, (void**)&nsmgr);
10467 if (hr != S_OK)
10469 win_skip("MXNamespaceManager is not available\n");
10470 return;
10473 len = sizeof(buffW)/sizeof(WCHAR);
10474 buffW[0] = 0;
10475 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10476 EXPECT_HR(hr, S_OK);
10477 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10479 len = sizeof(buffW)/sizeof(WCHAR);
10480 buffW[0] = 0;
10481 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10482 EXPECT_HR(hr, E_FAIL);
10484 hr = IMXNamespaceManager_getAllowOverride(nsmgr, NULL);
10485 EXPECT_HR(hr, E_POINTER);
10487 b = VARIANT_FALSE;
10488 hr = IMXNamespaceManager_getAllowOverride(nsmgr, &b);
10489 EXPECT_HR(hr, S_OK);
10490 ok(b == VARIANT_TRUE, "got %d\n", b);
10492 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_FALSE);
10493 EXPECT_HR(hr, S_OK);
10495 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10496 EXPECT_HR(hr, S_OK);
10498 len = sizeof(buffW)/sizeof(WCHAR);
10499 buffW[0] = 0;
10500 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
10501 EXPECT_HR(hr, S_OK);
10502 ok(!lstrcmpW(buffW, _bstr_("ns0 uri")), "got uri %s\n", wine_dbgstr_w(buffW));
10504 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), _bstr_("ns0 uri"));
10505 EXPECT_HR(hr, S_OK);
10507 len = sizeof(buffW)/sizeof(WCHAR);
10508 buffW[0] = 0;
10509 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10510 EXPECT_HR(hr, S_OK);
10511 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10513 len = sizeof(buffW)/sizeof(WCHAR);
10514 buffW[0] = 0;
10515 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10516 EXPECT_HR(hr, S_OK);
10517 ok(!lstrcmpW(buffW, _bstr_("ns0")), "got prefix %s\n", wine_dbgstr_w(buffW));
10519 len = sizeof(buffW)/sizeof(WCHAR);
10520 buffW[0] = 0;
10521 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 2, buffW, &len);
10522 EXPECT_HR(hr, S_OK);
10523 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
10525 /* new prefix placed at index 1 always */
10526 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
10527 EXPECT_HR(hr, S_OK);
10529 len = sizeof(buffW)/sizeof(WCHAR);
10530 buffW[0] = 0;
10531 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10532 EXPECT_HR(hr, S_OK);
10533 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got prefix %s\n", wine_dbgstr_w(buffW));
10535 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_(""), NULL);
10536 todo_wine EXPECT_HR(hr, E_FAIL);
10538 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
10539 EXPECT_HR(hr, E_FAIL);
10541 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10542 EXPECT_HR(hr, E_FAIL);
10544 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_TRUE);
10545 EXPECT_HR(hr, S_OK);
10547 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri override"));
10548 EXPECT_HR(hr, S_FALSE);
10550 len = sizeof(buffW)/sizeof(WCHAR);
10551 buffW[0] = 0;
10552 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
10553 EXPECT_HR(hr, S_OK);
10554 ok(!lstrcmpW(buffW, _bstr_("ns0 uri override")), "got uri %s\n", wine_dbgstr_w(buffW));
10556 len = sizeof(buffW)/sizeof(WCHAR);
10557 buffW[0] = 0;
10558 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 3, buffW, &len);
10559 EXPECT_HR(hr, S_OK);
10560 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
10562 IMXNamespaceManager_Release(nsmgr);
10564 free_bstrs();
10567 static void test_domobj_dispex(IUnknown *obj)
10569 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
10570 IDispatchEx *dispex;
10571 IUnknown *unk;
10572 DWORD props;
10573 UINT ticnt;
10574 HRESULT hr;
10575 BSTR name;
10577 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
10578 EXPECT_HR(hr, S_OK);
10579 if (FAILED(hr)) return;
10581 ticnt = 0;
10582 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
10583 EXPECT_HR(hr, S_OK);
10584 ok(ticnt == 1, "ticnt=%u\n", ticnt);
10586 name = SysAllocString(szstar);
10587 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
10588 EXPECT_HR(hr, E_NOTIMPL);
10589 SysFreeString(name);
10591 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
10592 EXPECT_HR(hr, E_NOTIMPL);
10594 props = 0;
10595 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
10596 EXPECT_HR(hr, E_NOTIMPL);
10597 ok(props == 0, "expected 0 got %d\n", props);
10599 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
10600 EXPECT_HR(hr, E_NOTIMPL);
10601 if (SUCCEEDED(hr)) SysFreeString(name);
10603 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
10604 EXPECT_HR(hr, E_NOTIMPL);
10606 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
10607 EXPECT_HR(hr, E_NOTIMPL);
10608 if (hr == S_OK && unk) IUnknown_Release(unk);
10610 IDispatchEx_Release(dispex);
10613 static const DOMNodeType dispex_types_test[] =
10615 NODE_ELEMENT,
10616 NODE_ATTRIBUTE,
10617 NODE_TEXT,
10618 NODE_CDATA_SECTION,
10619 NODE_ENTITY_REFERENCE,
10620 NODE_PROCESSING_INSTRUCTION,
10621 NODE_COMMENT,
10622 NODE_DOCUMENT_FRAGMENT,
10623 NODE_INVALID
10626 static void test_dispex(void)
10628 const DOMNodeType *type = dispex_types_test;
10629 IXMLDOMNodeList *node_list;
10630 IXMLDOMParseError *error;
10631 IXMLDOMDocument *doc;
10632 IUnknown *unk;
10633 HRESULT hr;
10635 doc = create_document(&IID_IXMLDOMDocument);
10637 IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
10638 test_domobj_dispex(unk);
10639 IUnknown_Release(unk);
10641 for(; *type != NODE_INVALID; type++)
10643 IXMLDOMNode *node;
10644 VARIANT v;
10646 V_VT(&v) = VT_I2;
10647 V_I2(&v) = *type;
10649 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("name"), NULL, &node);
10650 ok(hr == S_OK, "failed to create node type %d\n", *type);
10652 IXMLDOMNode_QueryInterface(node, &IID_IUnknown, (void**)&unk);
10654 test_domobj_dispex(unk);
10655 IUnknown_Release(unk);
10656 IXMLDOMNode_Release(node);
10659 /* IXMLDOMNodeList */
10660 hr = IXMLDOMDocument_getElementsByTagName(doc, _bstr_("*"), &node_list);
10661 EXPECT_HR(hr, S_OK);
10662 IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk);
10663 test_domobj_dispex(unk);
10664 IUnknown_Release(unk);
10665 IXMLDOMNodeList_Release(node_list);
10667 /* IXMLDOMParseError */
10668 hr = IXMLDOMDocument_get_parseError(doc, &error);
10669 EXPECT_HR(hr, S_OK);
10670 IXMLDOMParseError_QueryInterface(error, &IID_IUnknown, (void**)&unk);
10671 test_domobj_dispex(unk);
10672 IUnknown_Release(unk);
10673 IXMLDOMParseError_Release(error);
10675 IXMLDOMDocument_Release(doc);
10676 free_bstrs();
10679 START_TEST(domdoc)
10681 IXMLDOMDocument *doc;
10682 HRESULT hr;
10684 hr = CoInitialize( NULL );
10685 ok( hr == S_OK, "failed to init com\n");
10686 if (hr != S_OK) return;
10688 test_XMLHTTP();
10690 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc );
10691 if (hr != S_OK)
10693 win_skip("IXMLDOMDocument is not available (0x%08x)\n", hr);
10694 return;
10697 IXMLDOMDocument_Release(doc);
10699 test_domdoc();
10700 test_persiststreaminit();
10701 test_domnode();
10702 test_refs();
10703 test_create();
10704 test_getElementsByTagName();
10705 test_get_text();
10706 test_get_childNodes();
10707 test_get_firstChild();
10708 test_get_lastChild();
10709 test_removeChild();
10710 test_replaceChild();
10711 test_removeNamedItem();
10712 test_IXMLDOMDocument2();
10713 test_whitespace();
10714 test_XPath();
10715 test_XSLPattern();
10716 test_cloneNode();
10717 test_xmlTypes();
10718 test_nodeTypeTests();
10719 test_save();
10720 test_testTransforms();
10721 test_Namespaces();
10722 test_FormattingXML();
10723 test_nodeTypedValue();
10724 test_TransformWithLoadingLocalFile();
10725 test_put_nodeValue();
10726 test_document_IObjectSafety();
10727 test_splitText();
10728 test_getQualifiedItem();
10729 test_removeQualifiedItem();
10730 test_get_ownerDocument();
10731 test_setAttributeNode();
10732 test_put_dataType();
10733 test_createNode();
10734 test_get_prefix();
10735 test_default_properties();
10736 test_selectSingleNode();
10737 test_events();
10738 test_createProcessingInstruction();
10739 test_put_nodeTypedValue();
10740 test_get_xml();
10741 test_insertBefore();
10742 test_appendChild();
10743 test_get_doctype();
10744 test_get_tagName();
10745 test_get_dataType();
10746 test_get_nodeTypeString();
10747 test_get_attributes();
10748 test_selection();
10749 test_load();
10750 test_dispex();
10752 test_xsltemplate();
10754 test_nsnamespacemanager();
10755 test_nsnamespacemanager_override();
10757 CoUninitialize();