d3d11: Implement d3d11_device_CreateDepthStencilView().
[wine/multimedia.git] / dlls / msxml3 / tests / domdoc.c
blobff6783b3a57e28cc23772852602b41aea819063f
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-2013 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 "msxml.h"
34 #include "msxml2.h"
35 #include "msxml2did.h"
36 #include "ole2.h"
37 #include "dispex.h"
38 #include "objsafe.h"
39 #include "initguid.h"
41 #include "wine/test.h"
43 /* undef the #define in msxml2 so that we can access all versions */
44 #undef CLSID_DOMDocument
46 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
48 static int g_unexpectedcall, g_expectedcall;
50 struct msxmlsupported_data_t
52 const GUID *clsid;
53 const char *name;
54 const IID *ifaces[3];
55 BOOL supported[3];
58 static struct msxmlsupported_data_t domdoc_support_data[] =
60 { &CLSID_DOMDocument, "DOMDocument", {&IID_IXMLDOMDocument, &IID_IXMLDOMDocument2} },
61 { &CLSID_DOMDocument2, "DOMDocument2", {&IID_IXMLDOMDocument, &IID_IXMLDOMDocument2} },
62 { &CLSID_DOMDocument30, "DOMDocument30", {&IID_IXMLDOMDocument, &IID_IXMLDOMDocument2} },
63 { &CLSID_DOMDocument40, "DOMDocument40", {&IID_IXMLDOMDocument, &IID_IXMLDOMDocument2} },
64 { &CLSID_DOMDocument60, "DOMDocument60", {&IID_IXMLDOMDocument, &IID_IXMLDOMDocument2, &IID_IXMLDOMDocument3} },
65 { &CLSID_FreeThreadedDOMDocument, "FreeThreadedDOMDocument", {&IID_IXMLDOMDocument, &IID_IXMLDOMDocument2} },
66 { &CLSID_XMLSchemaCache, "XMLSchemaCache", {&IID_IXMLDOMSchemaCollection} },
67 { &CLSID_XSLTemplate, "XSLTemplate", {&IID_IXSLTemplate} },
68 { &CLSID_MXNamespaceManager40, "MXNamespaceManager40", {&IID_IMXNamespaceManager} },
69 { NULL }
72 static const char *debugstr_msxml_guid(REFIID riid)
74 if(!riid)
75 return "(null)";
77 if (IsEqualIID(&IID_IXMLDOMDocument, riid))
78 return "IXMLDOMDocument";
79 else if (IsEqualIID(&IID_IXMLDOMDocument2, riid))
80 return "IXMLDOMDocument2";
81 else if (IsEqualIID(&IID_IXMLDOMDocument3, riid))
82 return "IXMLDOMDocument3";
83 else if (IsEqualIID(&IID_IXMLDOMSchemaCollection, riid))
84 return "IXMLDOMSchemaCollection";
85 else if (IsEqualIID(&IID_IXSLTemplate, riid))
86 return "IXSLTemplate";
87 else if (IsEqualIID(&IID_IMXNamespaceManager, riid))
88 return "IMXNamespaceManager";
89 else
90 return wine_dbgstr_guid(riid);
93 static void get_class_support_data(struct msxmlsupported_data_t *table)
95 while (table->clsid)
97 IUnknown *unk;
98 HRESULT hr;
99 int i;
101 for (i = 0; i < sizeof(table->ifaces)/sizeof(table->ifaces[0]) && table->ifaces[i] != NULL; i++)
103 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER, table->ifaces[i], (void**)&unk);
104 if (hr == S_OK) IUnknown_Release(unk);
106 table->supported[i] = hr == S_OK;
107 if (hr != S_OK) win_skip("class %s, iface %s not supported\n", table->name, debugstr_msxml_guid(table->ifaces[i]));
110 table++;
114 static BOOL is_clsid_supported(const GUID *clsid, REFIID riid)
116 const struct msxmlsupported_data_t *table = domdoc_support_data;
117 while (table->clsid)
119 if (table->clsid == clsid)
121 int i;
123 for (i = 0; i < sizeof(table->ifaces)/sizeof(table->ifaces[0]) && table->ifaces[i] != NULL; i++)
124 if (table->ifaces[i] == riid) return table->supported[i];
127 table++;
129 return FALSE;
132 typedef struct
134 IDispatch IDispatch_iface;
135 LONG ref;
136 } dispevent;
138 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
140 return CONTAINING_RECORD(iface, dispevent, IDispatch_iface);
143 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
145 *ppvObject = NULL;
147 if ( IsEqualGUID( riid, &IID_IDispatch) ||
148 IsEqualGUID( riid, &IID_IUnknown) )
150 *ppvObject = iface;
152 else
153 return E_NOINTERFACE;
155 IDispatch_AddRef( iface );
157 return S_OK;
160 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
162 dispevent *This = impl_from_IDispatch( iface );
163 return InterlockedIncrement( &This->ref );
166 static ULONG WINAPI dispevent_Release(IDispatch *iface)
168 dispevent *This = impl_from_IDispatch( iface );
169 ULONG ref = InterlockedDecrement( &This->ref );
171 if (ref == 0)
172 HeapFree(GetProcessHeap(), 0, This);
174 return ref;
177 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
179 g_unexpectedcall++;
180 *pctinfo = 0;
181 return S_OK;
184 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
185 LCID lcid, ITypeInfo **ppTInfo)
187 g_unexpectedcall++;
188 return S_OK;
191 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
192 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
194 g_unexpectedcall++;
195 return S_OK;
198 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
199 LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
200 EXCEPINFO *excepInfo, UINT *argErr)
202 ok(member == 0, "expected 0 member, got %d\n", member);
203 ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
204 ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
206 ok(params->cArgs == 0, "got %d\n", params->cArgs);
207 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
208 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
209 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
211 ok(result == NULL, "got %p\n", result);
212 ok(excepInfo == NULL, "got %p\n", excepInfo);
213 ok(argErr == NULL, "got %p\n", argErr);
215 g_expectedcall++;
216 return E_FAIL;
219 static const IDispatchVtbl dispeventVtbl =
221 dispevent_QueryInterface,
222 dispevent_AddRef,
223 dispevent_Release,
224 dispevent_GetTypeInfoCount,
225 dispevent_GetTypeInfo,
226 dispevent_GetIDsOfNames,
227 dispevent_Invoke
230 static IDispatch* create_dispevent(void)
232 dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
234 event->IDispatch_iface.lpVtbl = &dispeventVtbl;
235 event->ref = 1;
237 return (IDispatch*)&event->IDispatch_iface;
240 /* IStream */
241 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
243 *ppvObject = NULL;
245 if (IsEqualGUID(riid, &IID_IStream) ||
246 IsEqualGUID(riid, &IID_IUnknown))
247 *ppvObject = iface;
248 else
249 return E_NOINTERFACE;
251 return S_OK;
254 static ULONG WINAPI istream_AddRef(IStream *iface)
256 return 2;
259 static ULONG WINAPI istream_Release(IStream *iface)
261 return 1;
264 static HRESULT WINAPI istream_Read(IStream *iface, void *ptr, ULONG len, ULONG *pread)
266 ok(0, "unexpected call\n");
267 return E_NOTIMPL;
270 static HRESULT WINAPI istream_Write(IStream *iface, const void *ptr, ULONG len, ULONG *written)
272 *written = len/2;
273 return S_OK;
276 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER move, DWORD origin, ULARGE_INTEGER *new_pos)
278 ok(0, "unexpected call\n");
279 return E_NOTIMPL;
282 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER size)
284 ok(0, "unexpected call\n");
285 return E_NOTIMPL;
288 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *stream, ULARGE_INTEGER len,
289 ULARGE_INTEGER *pread, ULARGE_INTEGER *written)
291 ok(0, "unexpected call\n");
292 return E_NOTIMPL;
295 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD flags)
297 ok(0, "unexpected call\n");
298 return E_NOTIMPL;
301 static HRESULT WINAPI istream_Revert(IStream *iface)
303 ok(0, "unexpected call\n");
304 return E_NOTIMPL;
307 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER offset,
308 ULARGE_INTEGER len, DWORD locktype)
310 ok(0, "unexpected call\n");
311 return E_NOTIMPL;
314 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER offset,
315 ULARGE_INTEGER len, DWORD locktype)
317 ok(0, "unexpected call\n");
318 return E_NOTIMPL;
321 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD flag)
323 ok(0, "unexpected call\n");
324 return E_NOTIMPL;
327 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **stream)
329 ok(0, "unexpected call\n");
330 return E_NOTIMPL;
333 static const IStreamVtbl StreamVtbl = {
334 istream_QueryInterface,
335 istream_AddRef,
336 istream_Release,
337 istream_Read,
338 istream_Write,
339 istream_Seek,
340 istream_SetSize,
341 istream_CopyTo,
342 istream_Commit,
343 istream_Revert,
344 istream_LockRegion,
345 istream_UnlockRegion,
346 istream_Stat,
347 istream_Clone
350 static IStream savestream = { &StreamVtbl };
352 #define EXPECT_CHILDREN(node) _expect_children((IXMLDOMNode*)node, __LINE__)
353 static void _expect_children(IXMLDOMNode *node, int line)
355 VARIANT_BOOL b;
356 HRESULT hr;
358 b = VARIANT_FALSE;
359 hr = IXMLDOMNode_hasChildNodes(node, &b);
360 ok_(__FILE__,line)(hr == S_OK, "hasChildNodes() failed, 0x%08x\n", hr);
361 ok_(__FILE__,line)(b == VARIANT_TRUE, "no children, %d\n", b);
364 #define EXPECT_NO_CHILDREN(node) _expect_no_children((IXMLDOMNode*)node, __LINE__)
365 static void _expect_no_children(IXMLDOMNode *node, int line)
367 VARIANT_BOOL b;
368 HRESULT hr;
370 b = VARIANT_TRUE;
371 hr = IXMLDOMNode_hasChildNodes(node, &b);
372 ok_(__FILE__,line)(hr == S_FALSE, "hasChildNodes() failed, 0x%08x\n", hr);
373 ok_(__FILE__,line)(b == VARIANT_FALSE, "no children, %d\n", b);
376 #define EXPECT_REF(node,ref) _expect_ref((IUnknown*)node, ref, __LINE__)
377 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
379 ULONG rc;
380 IUnknown_AddRef(obj);
381 rc = IUnknown_Release(obj);
382 ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc);
385 #define EXPECT_LIST_LEN(list,len) _expect_list_len(list, len, __LINE__)
386 static void _expect_list_len(IXMLDOMNodeList *list, LONG len, int line)
388 LONG length;
389 HRESULT hr;
391 length = 0;
392 hr = IXMLDOMNodeList_get_length(list, &length);
393 ok_(__FILE__,line)(hr == S_OK, "got 0x%08x\n", hr);
394 ok_(__FILE__,line)(length == len, "got %d, expected %d\n", length, len);
397 #define EXPECT_HR(hr,hr_exp) \
398 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
400 static const WCHAR szEmpty[] = { 0 };
401 static const WCHAR szIncomplete[] = {
402 '<','?','x','m','l',' ',
403 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
405 static const WCHAR szComplete1[] = {
406 '<','?','x','m','l',' ',
407 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
408 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
410 static const WCHAR szComplete2[] = {
411 '<','?','x','m','l',' ',
412 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
413 '<','a','>','<','/','a','>','\n',0
415 static const char complete4A[] =
416 "<?xml version=\'1.0\'?>\n"
417 "<lc dl=\'str1\'>\n"
418 "<bs vr=\'str2\' sz=\'1234\'>"
419 "fn1.txt\n"
420 "</bs>\n"
421 "<pr id=\'str3\' vr=\'1.2.3\' pn=\'wine 20050804\'>\n"
422 "fn2.txt\n"
423 "</pr>\n"
424 "<empty></empty>\n"
425 "<fo>\n"
426 "<ba>\n"
427 "f1\n"
428 "</ba>\n"
429 "</fo>\n"
430 "</lc>\n";
432 static const WCHAR szComplete5[] = {
433 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
434 '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','"',
435 ' ','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','"','>',
436 '<','S',':','s','c','o','p','e','>',
437 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
438 '<','/','S',':','s','c','o','p','e','>',
439 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
440 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
441 'c','o','m','p','u','t','e','r',
442 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
443 '<','/','S',':','s','e','a','r','c','h','>',0
446 static const WCHAR szComplete6[] = {
447 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'',' ',
448 'e','n','c','o','d','i','n','g','=','\'','W','i','n','d','o','w','s','-','1','2','5','2','\'','?','>','\n',
449 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
452 static const char complete7[] = {
453 "<?xml version=\"1.0\"?>\n\t"
454 "<root>\n"
455 "\t<a/>\n"
456 "\t<b/>\n"
457 "\t<c/>\n"
458 "</root>"
461 #define DECL_WIN_1252 \
462 "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
464 static const char win1252xml[] =
465 DECL_WIN_1252
466 "<open></open>";
468 static const char win1252decl[] =
469 DECL_WIN_1252
472 static const char nocontent[] = "no xml content here";
474 static const char szExampleXML[] =
475 "<?xml version='1.0' encoding='utf-8'?>\n"
476 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' a=\"attr a\" foo:b=\"attr b\" >\n"
477 " <elem>\n"
478 " <a>A1 field</a>\n"
479 " <b>B1 field</b>\n"
480 " <c>C1 field</c>\n"
481 " <d>D1 field</d>\n"
482 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
483 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
484 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
485 " </html>\n"
486 " <html xml:space='preserve' xmlns='http://www.w3.org/1999/xhtml'>\n"
487 " This is <strong>a</strong> <i>description</i> with preserved whitespace. <bar:x/>\n"
488 " </html>\n"
489 " </description>\n"
490 " </elem>\n"
491 "\n"
492 " <elem a='a'>\n"
493 " <a>A2 field</a>\n"
494 " <b>B2 field</b>\n"
495 " <c type=\"old\">C2 field</c>\n"
496 " <d>D2 field</d>\n"
497 " </elem>\n"
498 "\n"
499 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
500 " <a>A3 field</a>\n"
501 " <b>B3 field</b>\n"
502 " <c>C3 field</c>\n"
503 " </elem>\n"
504 "\n"
505 " <elem>\n"
506 " <a>A4 field</a>\n"
507 " <b>B4 field</b>\n"
508 " <foo:c>C4 field</foo:c>\n"
509 " <d>D4 field</d>\n"
510 " </elem>\n"
511 "</root>\n";
513 static const char charrefsxml[] =
514 "<?xml version='1.0'?>"
515 "<a>"
516 "<b1> Text &#65; end </b1>"
517 "<b2>&#65;&#66; &#67; </b2>"
518 "</a>";
520 static const CHAR szNodeTypesXML[] =
521 "<?xml version='1.0'?>"
522 "<!-- comment node 0 -->"
523 "<root id='0' depth='0'>"
524 " <!-- comment node 1 -->"
525 " text node 0"
526 " <x id='1' depth='1'>"
527 " <?foo value='PI for x'?>"
528 " <!-- comment node 2 -->"
529 " text node 1"
530 " <a id='3' depth='2'/>"
531 " <b id='4' depth='2'/>"
532 " <c id='5' depth='2'/>"
533 " </x>"
534 " <y id='2' depth='1'>"
535 " <?bar value='PI for y'?>"
536 " <!-- comment node 3 -->"
537 " text node 2"
538 " <a id='6' depth='2'/>"
539 " <b id='7' depth='2'/>"
540 " <c id='8' depth='2'/>"
541 " </y>"
542 "</root>";
544 static const CHAR szTransformXML[] =
545 "<?xml version=\"1.0\"?>\n"
546 "<greeting>\n"
547 "Hello World\n"
548 "</greeting>";
550 static const CHAR szTransformSSXML[] =
551 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
552 " <xsl:output method=\"html\"/>\n"
553 " <xsl:template match=\"/\">\n"
554 " <xsl:apply-templates select=\"greeting\"/>\n"
555 " </xsl:template>\n"
556 " <xsl:template match=\"greeting\">\n"
557 " <html>\n"
558 " <body>\n"
559 " <h1>\n"
560 " <xsl:value-of select=\".\"/>\n"
561 " </h1>\n"
562 " </body>\n"
563 " </html>\n"
564 " </xsl:template>\n"
565 "</xsl:stylesheet>";
567 static const CHAR szTransformOutput[] =
568 "<html><body><h1>"
569 "Hello World"
570 "</h1></body></html>";
572 static const CHAR szTypeValueXML[] =
573 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
574 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
575 " <string>Wine</string>\n"
576 " <string2 dt:dt=\"string\">String</string2>\n"
577 " <number dt:dt=\"number\">12.44</number>\n"
578 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
579 " <int dt:dt=\"int\">-13</int>\n"
580 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
581 " <bool dt:dt=\"boolean\">1</bool>\n"
582 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
583 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
584 " <date dt:dt=\"date\">3721-11-01</date>\n"
585 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
586 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
587 " <i1 dt:dt=\"i1\">-13</i1>\n"
588 " <i2 dt:dt=\"i2\">31915</i2>\n"
589 " <i4 dt:dt=\"i4\">-312232</i4>\n"
590 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
591 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
592 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
593 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
594 " <r8 dt:dt=\"r8\">0.412</r8>\n"
595 " <float dt:dt=\"float\">41221.421</float>\n"
596 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
597 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
598 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
599 " <binbase64_1 dt:dt=\"bin.base64\">\nYmFzZTY0\nIHRlc3Q=\n</binbase64_1>\n"
600 " <binbase64_2 dt:dt=\"bin.base64\">\nYmF\r\t z ZTY0\nIHRlc3Q=\n</binbase64_2>\n"
601 "</root>";
603 static const CHAR szBasicTransformSSXMLPart1[] =
604 "<?xml version=\"1.0\"?>"
605 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
606 "<xsl:output method=\"html\"/>\n"
607 "<xsl:template match=\"/\">"
608 "<HTML><BODY><TABLE>"
609 " <xsl:apply-templates select='document(\"";
611 static const CHAR szBasicTransformSSXMLPart2[] =
612 "\")/bottle/wine'>"
613 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
614 " </xsl:apply-templates>"
615 "</TABLE></BODY></HTML>"
616 "</xsl:template>"
617 "<xsl:template match=\"bottle\">"
618 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
619 "</xsl:template>"
620 "<xsl:template match=\"name\">"
621 " <TD><xsl:apply-templates /></TD>"
622 "</xsl:template>"
623 "<xsl:template match=\"cost\">"
624 " <TD><xsl:apply-templates /></TD>"
625 "</xsl:template>"
626 "</xsl:stylesheet>";
628 static const CHAR szBasicTransformXML[] =
629 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
631 static const CHAR szBasicTransformOutput[] =
632 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
634 #define SZ_EMAIL_DTD \
635 "<!DOCTYPE email ["\
636 " <!ELEMENT email (recipients,from,reply-to?,subject,body,attachment*)>"\
637 " <!ATTLIST email attachments IDREFS #REQUIRED>"\
638 " <!ATTLIST email sent (yes|no) \"no\">"\
639 " <!ELEMENT recipients (to+,cc*)>"\
640 " <!ELEMENT to (#PCDATA)>"\
641 " <!ATTLIST to name CDATA #IMPLIED>"\
642 " <!ELEMENT cc (#PCDATA)>"\
643 " <!ATTLIST cc name CDATA #IMPLIED>"\
644 " <!ELEMENT from (#PCDATA)>"\
645 " <!ATTLIST from name CDATA #IMPLIED>"\
646 " <!ELEMENT reply-to (#PCDATA)>"\
647 " <!ATTLIST reply-to name CDATA #IMPLIED>"\
648 " <!ELEMENT subject ANY>"\
649 " <!ELEMENT body ANY>"\
650 " <!ATTLIST body enc CDATA #FIXED \"UTF-8\">"\
651 " <!ELEMENT attachment (#PCDATA)>"\
652 " <!ATTLIST attachment id ID #REQUIRED>"\
653 "]>"
655 static const CHAR szEmailXML[] =
656 "<?xml version=\"1.0\"?>"
657 SZ_EMAIL_DTD
658 "<email attachments=\"patch1\">"
659 " <recipients>"
660 " <to>wine-patches@winehq.org</to>"
661 " </recipients>"
662 " <from name=\"Anonymous\">user@localhost</from>"
663 " <subject>msxml3/tests: DTD validation (try 87)</subject>"
664 " <body>"
665 " It no longer causes spontaneous combustion..."
666 " </body>"
667 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
668 "</email>";
670 static const CHAR szEmailXML_0D[] =
671 "<?xml version=\"1.0\"?>"
672 SZ_EMAIL_DTD
673 "<email attachments=\"patch1\">"
674 " <recipients>"
675 " <to>wine-patches@winehq.org</to>"
676 " </recipients>"
677 " <from name=\"Anonymous\">user@localhost</from>"
678 " <subject>msxml3/tests: DTD validation (try 88)</subject>"
679 " <body>"
680 " <undecl />"
681 " XML_ELEMENT_UNDECLARED 0xC00CE00D"
682 " </body>"
683 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
684 "</email>";
686 static const CHAR szEmailXML_0E[] =
687 "<?xml version=\"1.0\"?>"
688 SZ_EMAIL_DTD
689 "<email attachments=\"patch1\">"
690 " <recipients>"
691 " <to>wine-patches@winehq.org</to>"
692 " </recipients>"
693 " <from name=\"Anonymous\">user@localhost</from>"
694 " <subject>msxml3/tests: DTD validation (try 89)</subject>"
695 " <body>"
696 " XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E"
697 " </body>"
698 " <attachment id=\"patch\">0001-msxml3-tests-DTD-validation.patch</attachment>"
699 "</email>";
701 static const CHAR szEmailXML_11[] =
702 "<?xml version=\"1.0\"?>"
703 SZ_EMAIL_DTD
704 "<email attachments=\"patch1\">"
705 " <recipients>"
706 " </recipients>"
707 " <from name=\"Anonymous\">user@localhost</from>"
708 " <subject>msxml3/tests: DTD validation (try 90)</subject>"
709 " <body>"
710 " XML_EMPTY_NOT_ALLOWED 0xC00CE011"
711 " </body>"
712 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
713 "</email>";
715 static const CHAR szEmailXML_13[] =
716 "<?xml version=\"1.0\"?>"
717 SZ_EMAIL_DTD
718 "<msg attachments=\"patch1\">"
719 " <recipients>"
720 " <to>wine-patches@winehq.org</to>"
721 " </recipients>"
722 " <from name=\"Anonymous\">user@localhost</from>"
723 " <subject>msxml3/tests: DTD validation (try 91)</subject>"
724 " <body>"
725 " XML_ROOT_NAME_MISMATCH 0xC00CE013"
726 " </body>"
727 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
728 "</msg>";
730 static const CHAR szEmailXML_14[] =
731 "<?xml version=\"1.0\"?>"
732 SZ_EMAIL_DTD
733 "<email attachments=\"patch1\">"
734 " <to>wine-patches@winehq.org</to>"
735 " <from name=\"Anonymous\">user@localhost</from>"
736 " <subject>msxml3/tests: DTD validation (try 92)</subject>"
737 " <body>"
738 " XML_INVALID_CONTENT 0xC00CE014"
739 " </body>"
740 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
741 "</email>";
743 static const CHAR szEmailXML_15[] =
744 "<?xml version=\"1.0\"?>"
745 SZ_EMAIL_DTD
746 "<email attachments=\"patch1\" ip=\"127.0.0.1\">"
747 " <recipients>"
748 " <to>wine-patches@winehq.org</to>"
749 " </recipients>"
750 " <from name=\"Anonymous\">user@localhost</from>"
751 " <subject>msxml3/tests: DTD validation (try 93)</subject>"
752 " <body>"
753 " XML_ATTRIBUTE_NOT_DEFINED 0xC00CE015"
754 " </body>"
755 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
756 "</email>";
758 static const CHAR szEmailXML_16[] =
759 "<?xml version=\"1.0\"?>"
760 SZ_EMAIL_DTD
761 "<email attachments=\"patch1\">"
762 " <recipients>"
763 " <to>wine-patches@winehq.org</to>"
764 " </recipients>"
765 " <from name=\"Anonymous\">user@localhost</from>"
766 " <subject>msxml3/tests: DTD validation (try 94)</subject>"
767 " <body enc=\"ASCII\">"
768 " XML_ATTRIBUTE_FIXED 0xC00CE016"
769 " </body>"
770 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
771 "</email>";
773 static const CHAR szEmailXML_17[] =
774 "<?xml version=\"1.0\"?>"
775 SZ_EMAIL_DTD
776 "<email attachments=\"patch1\" sent=\"true\">"
777 " <recipients>"
778 " <to>wine-patches@winehq.org</to>"
779 " </recipients>"
780 " <from name=\"Anonymous\">user@localhost</from>"
781 " <subject>msxml3/tests: DTD validation (try 95)</subject>"
782 " <body>"
783 " XML_ATTRIBUTE_VALUE 0xC00CE017"
784 " </body>"
785 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
786 "</email>";
788 static const CHAR szEmailXML_18[] =
789 "<?xml version=\"1.0\"?>"
790 SZ_EMAIL_DTD
791 "<email attachments=\"patch1\">"
792 " oops"
793 " <recipients>"
794 " <to>wine-patches@winehq.org</to>"
795 " </recipients>"
796 " <from name=\"Anonymous\">user@localhost</from>"
797 " <subject>msxml3/tests: DTD validation (try 96)</subject>"
798 " <body>"
799 " XML_ILLEGAL_TEXT 0xC00CE018"
800 " </body>"
801 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
802 "</email>";
804 static const CHAR szEmailXML_20[] =
805 "<?xml version=\"1.0\"?>"
806 SZ_EMAIL_DTD
807 "<email>"
808 " <recipients>"
809 " <to>wine-patches@winehq.org</to>"
810 " </recipients>"
811 " <from name=\"Anonymous\">user@localhost</from>"
812 " <subject>msxml3/tests: DTD validation (try 97)</subject>"
813 " <body>"
814 " XML_REQUIRED_ATTRIBUTE_MISSING 0xC00CE020"
815 " </body>"
816 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
817 "</email>";
819 static const char xpath_simple_list[] =
820 "<?xml version=\"1.0\"?>"
821 "<root>"
822 " <a attr1=\"1\" attr2=\"2\" />"
823 " <b/>"
824 " <c/>"
825 " <d/>"
826 "</root>";
828 static const char default_ns_doc[] = {
829 "<?xml version=\"1.0\"?>"
830 "<a xmlns:ns=\"nshref\" xml:lang=\"ru\" ns:b=\"b attr\" xml:c=\"c attr\" "
831 " d=\"d attr\" />"
834 static const char attributes_map[] = {
835 "<?xml version=\"1.0\"?>"
836 "<a attr1=\"value1\" attr2=\"value2\" attr3=\"value3\" attr4=\"value4\" />"
839 static const WCHAR nonexistent_fileW[] = {
840 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
842 static const WCHAR nonexistent_attrW[] = {
843 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
845 static const WCHAR szDocument[] = {
846 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
849 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
850 static const WCHAR szdl[] = { 'd','l',0 };
851 static const WCHAR szvr[] = { 'v','r',0 };
852 static const WCHAR szlc[] = { 'l','c',0 };
853 static const WCHAR szbs[] = { 'b','s',0 };
854 static const WCHAR szstr1[] = { 's','t','r','1',0 };
855 static const WCHAR szstr2[] = { 's','t','r','2',0 };
856 static const WCHAR szstar[] = { '*',0 };
857 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
859 static const WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
860 static const WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
861 static const WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
863 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
864 static const WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
865 static const WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
866 static const WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
867 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
868 static const WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
869 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
871 static const WCHAR szAttribute[] = {'A','t','t','r',0 };
872 static const WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
874 static const WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
875 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
876 static const WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
877 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
878 '!',']',']','>',0};
879 static const WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
880 static const WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
882 static const WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
883 static const WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
884 static const WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
886 #define expect_bstr_eq_and_free(bstr, expect) { \
887 BSTR bstrExp = alloc_str_from_narrow(expect); \
888 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
889 SysFreeString(bstr); \
890 SysFreeString(bstrExp); \
893 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
895 #define ole_check(expr) { \
896 HRESULT r = expr; \
897 ok(r == S_OK, #expr " returned %x\n", r); \
900 #define ole_expect(expr, expect) { \
901 HRESULT r = expr; \
902 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
905 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
907 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
909 void *obj = NULL;
910 HRESULT hr;
912 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
913 ok(hr == S_OK, "failed to create %s instance: 0x%08x\n", name, hr);
915 return obj;
918 #define _create(cls) cls, #cls
920 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument2), iid, __LINE__)
921 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
922 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
923 #define create_xsltemplate(iid) _create_object(&_create(CLSID_XSLTemplate), iid, __LINE__)
925 static BSTR alloc_str_from_narrow(const char *str)
927 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
928 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
929 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
930 return ret;
933 static BSTR alloced_bstrs[256];
934 static int alloced_bstrs_count;
936 static BSTR _bstr_(const char *str)
938 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
939 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
940 return alloced_bstrs[alloced_bstrs_count++];
943 static void free_bstrs(void)
945 int i;
946 for (i = 0; i < alloced_bstrs_count; i++)
947 SysFreeString(alloced_bstrs[i]);
948 alloced_bstrs_count = 0;
951 static VARIANT _variantbstr_(const char *str)
953 VARIANT v;
954 V_VT(&v) = VT_BSTR;
955 V_BSTR(&v) = _bstr_(str);
956 return v;
959 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
961 for (;;)
963 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
964 while (*sRight == '\r' || *sRight == '\n') sRight++;
965 if (*sLeft != *sRight) return FALSE;
966 if (!*sLeft) return TRUE;
967 sLeft++;
968 sRight++;
972 static void get_str_for_type(DOMNodeType type, char *buf)
974 switch (type)
976 case NODE_ATTRIBUTE:
977 strcpy(buf, "A");
978 break;
979 case NODE_ELEMENT:
980 strcpy(buf, "E");
981 break;
982 case NODE_DOCUMENT:
983 strcpy(buf, "D");
984 break;
985 case NODE_TEXT:
986 strcpy(buf, "T");
987 break;
988 case NODE_COMMENT:
989 strcpy(buf, "C");
990 break;
991 case NODE_PROCESSING_INSTRUCTION:
992 strcpy(buf, "P");
993 break;
994 default:
995 wsprintfA(buf, "[%d]", type);
999 static int get_node_position(IXMLDOMNode *node)
1001 HRESULT r;
1002 int pos = 0;
1004 IXMLDOMNode_AddRef(node);
1007 IXMLDOMNode *new_node;
1009 pos++;
1010 r = IXMLDOMNode_get_previousSibling(node, &new_node);
1011 ok(SUCCEEDED(r), "get_previousSibling failed\n");
1012 IXMLDOMNode_Release(node);
1013 node = new_node;
1014 } while (r == S_OK);
1015 return pos;
1018 static void node_to_string(IXMLDOMNode *node, char *buf)
1020 HRESULT r = S_OK;
1021 DOMNodeType type;
1023 if (node == NULL)
1025 lstrcpyA(buf, "(null)");
1026 return;
1029 IXMLDOMNode_AddRef(node);
1030 while (r == S_OK)
1032 IXMLDOMNode *new_node;
1034 ole_check(IXMLDOMNode_get_nodeType(node, &type));
1035 get_str_for_type(type, buf);
1036 buf+=strlen(buf);
1038 if (type == NODE_ATTRIBUTE)
1040 BSTR bstr;
1041 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
1042 *(buf++) = '\'';
1043 wsprintfA(buf, "%ws", bstr);
1044 buf += strlen(buf);
1045 *(buf++) = '\'';
1046 SysFreeString(bstr);
1048 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
1050 else
1052 r = IXMLDOMNode_get_parentNode(node, &new_node);
1053 sprintf(buf, "%d", get_node_position(node));
1054 buf += strlen(buf);
1057 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
1058 IXMLDOMNode_Release(node);
1059 node = new_node;
1060 if (r == S_OK)
1061 *(buf++) = '.';
1064 *buf = 0;
1067 static char *list_to_string(IXMLDOMNodeList *list)
1069 static char buf[4096];
1070 char *pos = buf;
1071 LONG len = 0;
1072 HRESULT hr;
1073 int i;
1075 if (list == NULL)
1077 strcpy(buf, "(null)");
1078 return buf;
1080 hr = IXMLDOMNodeList_get_length(list, &len);
1081 ok(hr == S_OK, "got 0x%08x\n", hr);
1082 for (i = 0; i < len; i++)
1084 IXMLDOMNode *node;
1085 if (i > 0)
1086 *(pos++) = ' ';
1087 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1088 node_to_string(node, pos);
1089 pos += strlen(pos);
1090 IXMLDOMNode_Release(node);
1092 *pos = 0;
1093 return buf;
1096 #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); }
1097 #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); }
1099 struct docload_ret_t {
1100 VARIANT_BOOL b;
1101 HRESULT hr;
1104 struct leading_spaces_t {
1105 const CLSID *clsid;
1106 const char *name;
1107 struct docload_ret_t ret[2]; /* 0 - ::load(), 1 - ::loadXML() */
1110 static const struct leading_spaces_t leading_spaces_classdata[] = {
1111 { &CLSID_DOMDocument, "CLSID_DOMDocument", {{VARIANT_FALSE, S_FALSE }, {VARIANT_TRUE, S_OK } }},
1112 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
1113 { &CLSID_DOMDocument26, "CLSID_DOMDocument26", {{VARIANT_FALSE, S_FALSE }, {VARIANT_TRUE, S_OK } }},
1114 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
1115 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
1116 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", {{VARIANT_FALSE, S_FALSE }, {VARIANT_FALSE, S_FALSE } }},
1117 { NULL }
1120 static const char* leading_spaces_xmldata[] = {
1121 "\n<?xml version=\"1.0\" encoding=\"UTF-16\" ?><root/>",
1122 " <?xml version=\"1.0\"?><root/>",
1123 "\n<?xml version=\"1.0\"?><root/>",
1124 "\t<?xml version=\"1.0\"?><root/>",
1125 "\r\n<?xml version=\"1.0\"?><root/>",
1126 "\r<?xml version=\"1.0\"?><root/>",
1127 "\r\r\r\r\t\t \n\n <?xml version=\"1.0\"?><root/>",
1131 static void test_domdoc( void )
1133 HRESULT r, hr;
1134 IXMLDOMDocument *doc;
1135 IXMLDOMParseError *error;
1136 IXMLDOMElement *element = NULL;
1137 IXMLDOMNode *node;
1138 IXMLDOMText *nodetext = NULL;
1139 IXMLDOMComment *node_comment = NULL;
1140 IXMLDOMAttribute *node_attr = NULL;
1141 IXMLDOMNode *nodeChild = NULL;
1142 IXMLDOMProcessingInstruction *nodePI = NULL;
1143 const struct leading_spaces_t *class_ptr;
1144 const char **data_ptr;
1145 VARIANT_BOOL b;
1146 VARIANT var;
1147 BSTR str;
1148 LONG code, ref;
1149 LONG nLength = 0;
1150 WCHAR buff[100];
1151 char path[MAX_PATH];
1152 int index;
1154 GetTempPathA(MAX_PATH, path);
1155 strcat(path, "leading_spaces.xml");
1157 /* Load document with leading spaces
1159 * Test all CLSIDs with all test data XML strings
1161 class_ptr = leading_spaces_classdata;
1162 index = 0;
1163 while (class_ptr->clsid)
1165 HRESULT hr;
1166 int i;
1168 if (is_clsid_supported(class_ptr->clsid, &IID_IXMLDOMDocument))
1170 hr = CoCreateInstance(class_ptr->clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
1172 else
1174 class_ptr++;
1175 index++;
1176 continue;
1179 data_ptr = leading_spaces_xmldata;
1180 i = 0;
1181 while (*data_ptr) {
1182 BSTR data = _bstr_(*data_ptr);
1183 DWORD written;
1184 HANDLE file;
1186 file = CreateFileA(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1187 ok(file != INVALID_HANDLE_VALUE, "can't create file %s: %u\n", path, GetLastError());
1189 WriteFile(file, data, lstrlenW(data)*sizeof(WCHAR), &written, NULL);
1190 CloseHandle(file);
1192 b = 0xc;
1193 V_VT(&var) = VT_BSTR;
1194 V_BSTR(&var) = _bstr_(path);
1195 hr = IXMLDOMDocument_load(doc, var, &b);
1196 EXPECT_HR(hr, class_ptr->ret[0].hr);
1197 ok(b == class_ptr->ret[0].b, "%d:%d, got %d, expected %d\n", index, i, b, class_ptr->ret[0].b);
1199 DeleteFileA(path);
1201 b = 0xc;
1202 hr = IXMLDOMDocument_loadXML(doc, data, &b);
1203 EXPECT_HR(hr, class_ptr->ret[1].hr);
1204 ok(b == class_ptr->ret[1].b, "%d:%d, got %d, expected %d\n", index, i, b, class_ptr->ret[1].b);
1206 data_ptr++;
1207 i++;
1210 class_ptr++;
1211 index++;
1212 free_bstrs();
1215 doc = create_document(&IID_IXMLDOMDocument);
1216 if (!doc) return;
1218 if (0)
1220 /* crashes on native */
1221 IXMLDOMDocument_loadXML( doc, (BSTR)0x1, NULL );
1224 /* try some stupid things */
1225 hr = IXMLDOMDocument_loadXML( doc, NULL, NULL );
1226 EXPECT_HR(hr, S_FALSE);
1228 b = VARIANT_TRUE;
1229 hr = IXMLDOMDocument_loadXML( doc, NULL, &b );
1230 EXPECT_HR(hr, S_FALSE);
1231 ok( b == VARIANT_FALSE, "failed to load XML string\n");
1233 /* try to load a document from a nonexistent file */
1234 b = VARIANT_TRUE;
1235 str = SysAllocString( nonexistent_fileW );
1236 VariantInit(&var);
1237 V_VT(&var) = VT_BSTR;
1238 V_BSTR(&var) = str;
1240 r = IXMLDOMDocument_load( doc, var, &b);
1241 ok( r == S_FALSE, "loadXML succeeded\n");
1242 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1243 SysFreeString( str );
1245 str = (BSTR)0x1;
1246 hr = IXMLDOMDocument_get_url(doc, &str);
1247 ok(hr == S_FALSE, "got 0x%08x\n", hr);
1248 ok(str == NULL, "got %p\n", str);
1250 /* try load an empty document */
1251 b = VARIANT_TRUE;
1252 str = SysAllocString( szEmpty );
1253 r = IXMLDOMDocument_loadXML( doc, str, &b );
1254 ok( r == S_FALSE, "loadXML succeeded\n");
1255 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1256 SysFreeString( str );
1258 r = IXMLDOMDocument_get_async( doc, &b );
1259 ok( r == S_OK, "get_async failed (%08x)\n", r);
1260 ok( b == VARIANT_TRUE, "Wrong default value\n");
1262 /* check that there's no document element */
1263 element = NULL;
1264 r = IXMLDOMDocument_get_documentElement( doc, &element );
1265 ok( r == S_FALSE, "should be no document element\n");
1267 /* try finding a node */
1268 node = NULL;
1269 str = SysAllocString( szstr1 );
1270 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
1271 ok( r == S_FALSE, "ret %08x\n", r );
1272 SysFreeString( str );
1274 b = VARIANT_TRUE;
1275 str = SysAllocString( szIncomplete );
1276 r = IXMLDOMDocument_loadXML( doc, str, &b );
1277 ok( r == S_FALSE, "loadXML succeeded\n");
1278 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1279 SysFreeString( str );
1281 /* check that there's no document element */
1282 element = (IXMLDOMElement*)1;
1283 r = IXMLDOMDocument_get_documentElement( doc, &element );
1284 ok( r == S_FALSE, "should be no document element\n");
1285 ok( element == NULL, "Element should be NULL\n");
1287 /* test for BSTR handling, pass broken BSTR */
1288 memcpy(&buff[2], szComplete1, sizeof(szComplete1));
1289 /* just a big length */
1290 *(DWORD*)buff = 0xf0f0;
1291 b = VARIANT_FALSE;
1292 r = IXMLDOMDocument_loadXML( doc, &buff[2], &b );
1293 ok( r == S_OK, "loadXML failed\n");
1294 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1296 /* loadXML ignores the encoding attribute and always expects Unicode */
1297 b = VARIANT_FALSE;
1298 str = SysAllocString( szComplete6 );
1299 r = IXMLDOMDocument_loadXML( doc, str, &b );
1300 ok( r == S_OK, "loadXML failed\n");
1301 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1302 SysFreeString( str );
1304 /* try a BSTR containing a Windows-1252 document */
1305 b = VARIANT_TRUE;
1306 str = SysAllocStringByteLen( win1252xml, strlen(win1252xml) );
1307 r = IXMLDOMDocument_loadXML( doc, str, &b );
1308 ok( r == S_FALSE, "loadXML succeeded\n");
1309 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1310 SysFreeString( str );
1312 /* try to load something valid */
1313 b = VARIANT_FALSE;
1314 str = SysAllocString( szComplete1 );
1315 r = IXMLDOMDocument_loadXML( doc, str, &b );
1316 ok( r == S_OK, "loadXML failed\n");
1317 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1318 SysFreeString( str );
1320 /* check if nodename is correct */
1321 r = IXMLDOMDocument_get_nodeName( doc, NULL );
1322 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1324 str = (BSTR)0xdeadbeef;
1325 r = IXMLDOMDocument_get_baseName( doc, &str );
1326 ok ( r == S_FALSE, "got 0x%08x\n", r);
1327 ok (str == NULL, "got %p\n", str);
1329 /* content doesn't matter here */
1330 str = NULL;
1331 r = IXMLDOMDocument_get_nodeName( doc, &str );
1332 ok ( r == S_OK, "get_nodeName wrong code\n");
1333 ok ( str != NULL, "str is null\n");
1334 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
1335 SysFreeString( str );
1337 /* test put_text */
1338 r = IXMLDOMDocument_put_text( doc, _bstr_("Should fail") );
1339 ok( r == E_FAIL, "ret %08x\n", r );
1341 /* check that there's a document element */
1342 element = NULL;
1343 r = IXMLDOMDocument_get_documentElement( doc, &element );
1344 ok( r == S_OK, "should be a document element\n");
1345 if( element )
1347 IObjectIdentity *ident;
1349 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (void**)&ident );
1350 ok( r == E_NOINTERFACE, "ret %08x\n", r);
1352 IXMLDOMElement_Release( element );
1353 element = NULL;
1356 /* as soon as we call loadXML again, the document element will disappear */
1357 b = 2;
1358 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
1359 ok( r == S_FALSE, "loadXML failed\n");
1360 ok( b == 2, "variant modified\n");
1361 r = IXMLDOMDocument_get_documentElement( doc, &element );
1362 ok( r == S_FALSE, "should be no document element\n");
1364 /* try to load something else simple and valid */
1365 b = VARIANT_FALSE;
1366 str = SysAllocString( szComplete2 );
1367 r = IXMLDOMDocument_loadXML( doc, str, &b );
1368 ok( r == S_OK, "loadXML failed\n");
1369 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1370 SysFreeString( str );
1372 /* try something a little more complicated */
1373 b = FALSE;
1374 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
1375 ok( r == S_OK, "loadXML failed\n");
1376 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1378 r = IXMLDOMDocument_get_parseError( doc, &error );
1379 ok( r == S_OK, "returns %08x\n", r );
1381 r = IXMLDOMParseError_get_errorCode( error, &code );
1382 ok( r == S_FALSE, "returns %08x\n", r );
1383 ok( code == 0, "code %d\n", code );
1384 IXMLDOMParseError_Release( error );
1386 /* test createTextNode */
1387 r = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &nodetext);
1388 ok( r == S_OK, "returns %08x\n", r );
1389 IXMLDOMText_Release(nodetext);
1391 str = SysAllocString( szOpen );
1392 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
1393 ok( r == E_INVALIDARG, "returns %08x\n", r );
1394 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
1395 ok( r == S_OK, "returns %08x\n", r );
1396 SysFreeString( str );
1397 if(nodetext)
1399 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element);
1400 ok(r == E_NOINTERFACE, "ret %08x\n", r );
1402 /* Text Last Child Checks */
1403 r = IXMLDOMText_get_lastChild(nodetext, NULL);
1404 ok(r == E_INVALIDARG, "ret %08x\n", r );
1406 nodeChild = (IXMLDOMNode*)0x1;
1407 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
1408 ok(r == S_FALSE, "ret %08x\n", r );
1409 ok(nodeChild == NULL, "nodeChild not NULL\n");
1411 /* test length property */
1412 r = IXMLDOMText_get_length(nodetext, NULL);
1413 ok(r == E_INVALIDARG, "ret %08x\n", r );
1415 r = IXMLDOMText_get_length(nodetext, &nLength);
1416 ok(r == S_OK, "ret %08x\n", r );
1417 ok(nLength == 4, "expected 4 got %d\n", nLength);
1419 /* put data Tests */
1420 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
1421 ok(r == S_OK, "ret %08x\n", r );
1423 /* get data Tests */
1424 r = IXMLDOMText_get_data(nodetext, &str);
1425 ok(r == S_OK, "ret %08x\n", r );
1426 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
1427 SysFreeString(str);
1429 /* Confirm XML text is good */
1430 r = IXMLDOMText_get_xml(nodetext, &str);
1431 ok(r == S_OK, "ret %08x\n", r );
1432 ok( !lstrcmpW( str, _bstr_("This &amp;is a ; test &lt;&gt;\\") ), "incorrect xml string\n");
1433 SysFreeString(str);
1435 /* Confirm we get the put_data Text back */
1436 r = IXMLDOMText_get_text(nodetext, &str);
1437 ok(r == S_OK, "ret %08x\n", r );
1438 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
1439 SysFreeString(str);
1441 /* test substringData */
1442 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
1443 ok(r == E_INVALIDARG, "ret %08x\n", r );
1445 /* test substringData - Invalid offset */
1446 str = (BSTR)&szElement;
1447 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
1448 ok(r == E_INVALIDARG, "ret %08x\n", r );
1449 ok( str == NULL, "incorrect string\n");
1451 /* test substringData - Invalid offset */
1452 str = (BSTR)&szElement;
1453 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
1454 ok(r == S_FALSE, "ret %08x\n", r );
1455 ok( str == NULL, "incorrect string\n");
1457 /* test substringData - Invalid size */
1458 str = (BSTR)&szElement;
1459 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
1460 ok(r == E_INVALIDARG, "ret %08x\n", r );
1461 ok( str == NULL, "incorrect string\n");
1463 /* test substringData - Invalid size */
1464 str = (BSTR)&szElement;
1465 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
1466 ok(r == S_FALSE, "ret %08x\n", r );
1467 ok( str == NULL, "incorrect string\n");
1469 /* test substringData - Start of string */
1470 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
1471 ok(r == S_OK, "ret %08x\n", r );
1472 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
1473 SysFreeString(str);
1475 /* test substringData - Middle of string */
1476 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
1477 ok(r == S_OK, "ret %08x\n", r );
1478 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
1479 SysFreeString(str);
1481 /* test substringData - End of string */
1482 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
1483 ok(r == S_OK, "ret %08x\n", r );
1484 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
1485 SysFreeString(str);
1487 /* test appendData */
1488 r = IXMLDOMText_appendData(nodetext, NULL);
1489 ok(r == S_OK, "ret %08x\n", r );
1491 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
1492 ok(r == S_OK, "ret %08x\n", r );
1494 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
1495 ok(r == S_OK, "ret %08x\n", r );
1497 r = IXMLDOMText_get_text(nodetext, &str);
1498 ok(r == S_OK, "ret %08x\n", r );
1499 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1500 SysFreeString(str);
1502 /* test insertData */
1503 str = SysAllocStringLen(NULL, 0);
1504 r = IXMLDOMText_insertData(nodetext, -1, str);
1505 ok(r == S_OK, "ret %08x\n", r );
1507 r = IXMLDOMText_insertData(nodetext, -1, NULL);
1508 ok(r == S_OK, "ret %08x\n", r );
1510 r = IXMLDOMText_insertData(nodetext, 1000, str);
1511 ok(r == S_OK, "ret %08x\n", r );
1513 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
1514 ok(r == S_OK, "ret %08x\n", r );
1516 r = IXMLDOMText_insertData(nodetext, 0, NULL);
1517 ok(r == S_OK, "ret %08x\n", r );
1519 r = IXMLDOMText_insertData(nodetext, 0, str);
1520 ok(r == S_OK, "ret %08x\n", r );
1521 SysFreeString(str);
1523 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
1524 ok(r == E_INVALIDARG, "ret %08x\n", r );
1526 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
1527 ok(r == E_INVALIDARG, "ret %08x\n", r );
1529 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
1530 ok(r == S_OK, "ret %08x\n", r );
1532 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
1533 ok(r == S_OK, "ret %08x\n", r );
1535 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
1536 ok(r == S_OK, "ret %08x\n", r );
1538 r = IXMLDOMText_get_text(nodetext, &str);
1539 ok(r == S_OK, "ret %08x\n", r );
1540 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1541 SysFreeString(str);
1543 /* delete data */
1544 /* invalid arguments */
1545 r = IXMLDOMText_deleteData(nodetext, -1, 1);
1546 ok(r == E_INVALIDARG, "ret %08x\n", r );
1548 r = IXMLDOMText_deleteData(nodetext, 0, 0);
1549 ok(r == S_OK, "ret %08x\n", r );
1551 r = IXMLDOMText_deleteData(nodetext, 0, -1);
1552 ok(r == E_INVALIDARG, "ret %08x\n", r );
1554 r = IXMLDOMText_get_length(nodetext, &nLength);
1555 ok(r == S_OK, "ret %08x\n", r );
1556 ok(nLength == 43, "expected 43 got %d\n", nLength);
1558 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
1559 ok(r == S_OK, "ret %08x\n", r );
1561 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
1562 ok(r == E_INVALIDARG, "ret %08x\n", r );
1564 /* delete from start */
1565 r = IXMLDOMText_deleteData(nodetext, 0, 5);
1566 ok(r == S_OK, "ret %08x\n", r );
1568 r = IXMLDOMText_get_length(nodetext, &nLength);
1569 ok(r == S_OK, "ret %08x\n", r );
1570 ok(nLength == 38, "expected 38 got %d\n", nLength);
1572 r = IXMLDOMText_get_text(nodetext, &str);
1573 ok(r == S_OK, "ret %08x\n", r );
1574 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1575 SysFreeString(str);
1577 /* delete from end */
1578 r = IXMLDOMText_deleteData(nodetext, 35, 3);
1579 ok(r == S_OK, "ret %08x\n", r );
1581 r = IXMLDOMText_get_length(nodetext, &nLength);
1582 ok(r == S_OK, "ret %08x\n", r );
1583 ok(nLength == 35, "expected 35 got %d\n", nLength);
1585 r = IXMLDOMText_get_text(nodetext, &str);
1586 ok(r == S_OK, "ret %08x\n", r );
1587 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1588 SysFreeString(str);
1590 /* delete from inside */
1591 r = IXMLDOMText_deleteData(nodetext, 1, 33);
1592 ok(r == S_OK, "ret %08x\n", r );
1594 r = IXMLDOMText_get_length(nodetext, &nLength);
1595 ok(r == S_OK, "ret %08x\n", r );
1596 ok(nLength == 2, "expected 2 got %d\n", nLength);
1598 r = IXMLDOMText_get_text(nodetext, &str);
1599 ok(r == S_OK, "ret %08x\n", r );
1600 ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1601 SysFreeString(str);
1603 /* delete whole data ... */
1604 r = IXMLDOMText_get_length(nodetext, &nLength);
1605 ok(r == S_OK, "ret %08x\n", r );
1607 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1608 ok(r == S_OK, "ret %08x\n", r );
1609 /* ... and try again with empty string */
1610 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1611 ok(r == S_OK, "ret %08x\n", r );
1613 /* test put_data */
1614 V_VT(&var) = VT_BSTR;
1615 V_BSTR(&var) = SysAllocString(szstr1);
1616 r = IXMLDOMText_put_nodeValue(nodetext, var);
1617 ok(r == S_OK, "ret %08x\n", r );
1618 VariantClear(&var);
1620 r = IXMLDOMText_get_text(nodetext, &str);
1621 ok(r == S_OK, "ret %08x\n", r );
1622 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1623 SysFreeString(str);
1625 /* test put_data */
1626 V_VT(&var) = VT_I4;
1627 V_I4(&var) = 99;
1628 r = IXMLDOMText_put_nodeValue(nodetext, var);
1629 ok(r == S_OK, "ret %08x\n", r );
1630 VariantClear(&var);
1632 r = IXMLDOMText_get_text(nodetext, &str);
1633 ok(r == S_OK, "ret %08x\n", r );
1634 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1635 SysFreeString(str);
1637 /* ::replaceData() */
1638 V_VT(&var) = VT_BSTR;
1639 V_BSTR(&var) = SysAllocString(szstr1);
1640 r = IXMLDOMText_put_nodeValue(nodetext, var);
1641 ok(r == S_OK, "ret %08x\n", r );
1642 VariantClear(&var);
1644 r = IXMLDOMText_replaceData(nodetext, 6, 0, NULL);
1645 ok(r == E_INVALIDARG, "ret %08x\n", r );
1646 r = IXMLDOMText_get_text(nodetext, &str);
1647 ok(r == S_OK, "ret %08x\n", r );
1648 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1649 SysFreeString(str);
1651 r = IXMLDOMText_replaceData(nodetext, 0, 0, NULL);
1652 ok(r == S_OK, "ret %08x\n", r );
1653 r = IXMLDOMText_get_text(nodetext, &str);
1654 ok(r == S_OK, "ret %08x\n", r );
1655 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1656 SysFreeString(str);
1658 /* NULL pointer means delete */
1659 r = IXMLDOMText_replaceData(nodetext, 0, 1, NULL);
1660 ok(r == S_OK, "ret %08x\n", r );
1661 r = IXMLDOMText_get_text(nodetext, &str);
1662 ok(r == S_OK, "ret %08x\n", r );
1663 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1664 SysFreeString(str);
1666 /* empty string means delete */
1667 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_(""));
1668 ok(r == S_OK, "ret %08x\n", r );
1669 r = IXMLDOMText_get_text(nodetext, &str);
1670 ok(r == S_OK, "ret %08x\n", r );
1671 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1672 SysFreeString(str);
1674 /* zero count means insert */
1675 r = IXMLDOMText_replaceData(nodetext, 0, 0, _bstr_("a"));
1676 ok(r == S_OK, "ret %08x\n", r );
1677 r = IXMLDOMText_get_text(nodetext, &str);
1678 ok(r == S_OK, "ret %08x\n", r );
1679 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1680 SysFreeString(str);
1682 r = IXMLDOMText_replaceData(nodetext, 0, 2, NULL);
1683 ok(r == S_OK, "ret %08x\n", r );
1685 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("m"));
1686 ok(r == S_OK, "ret %08x\n", r );
1687 r = IXMLDOMText_get_text(nodetext, &str);
1688 ok(r == S_OK, "ret %08x\n", r );
1689 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1690 SysFreeString(str);
1692 /* nonempty string, count greater than its length */
1693 r = IXMLDOMText_replaceData(nodetext, 0, 2, _bstr_("a1.2"));
1694 ok(r == S_OK, "ret %08x\n", r );
1695 r = IXMLDOMText_get_text(nodetext, &str);
1696 ok(r == S_OK, "ret %08x\n", r );
1697 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1698 SysFreeString(str);
1700 /* nonempty string, count less than its length */
1701 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_("wine"));
1702 ok(r == S_OK, "ret %08x\n", r );
1703 r = IXMLDOMText_get_text(nodetext, &str);
1704 ok(r == S_OK, "ret %08x\n", r );
1705 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1706 SysFreeString(str);
1708 IXMLDOMText_Release( nodetext );
1711 /* test Create Comment */
1712 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
1713 ok( r == E_INVALIDARG, "returns %08x\n", r );
1714 node_comment = (IXMLDOMComment*)0x1;
1716 /* empty comment */
1717 r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
1718 ok( r == S_OK, "returns %08x\n", r );
1719 str = (BSTR)0x1;
1720 r = IXMLDOMComment_get_data(node_comment, &str);
1721 ok( r == S_OK, "returns %08x\n", r );
1722 ok( str && SysStringLen(str) == 0, "expected empty string data\n");
1723 IXMLDOMComment_Release(node_comment);
1724 SysFreeString(str);
1726 r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
1727 ok( r == S_OK, "returns %08x\n", r );
1728 str = (BSTR)0x1;
1729 r = IXMLDOMComment_get_data(node_comment, &str);
1730 ok( r == S_OK, "returns %08x\n", r );
1731 ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
1732 IXMLDOMComment_Release(node_comment);
1733 SysFreeString(str);
1735 str = SysAllocString(szComment);
1736 r = IXMLDOMDocument_createComment(doc, str, &node_comment);
1737 SysFreeString(str);
1738 ok( r == S_OK, "returns %08x\n", r );
1739 if(node_comment)
1741 /* Last Child Checks */
1742 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
1743 ok(r == E_INVALIDARG, "ret %08x\n", r );
1745 nodeChild = (IXMLDOMNode*)0x1;
1746 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
1747 ok(r == S_FALSE, "ret %08x\n", r );
1748 ok(nodeChild == NULL, "pLastChild not NULL\n");
1750 /* baseName */
1751 str = (BSTR)0xdeadbeef;
1752 r = IXMLDOMComment_get_baseName(node_comment, &str);
1753 ok(r == S_FALSE, "ret %08x\n", r );
1754 ok(str == NULL, "Expected NULL\n");
1756 IXMLDOMComment_Release( node_comment );
1759 /* test Create Attribute */
1760 str = SysAllocString(szAttribute);
1761 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
1762 ok( r == E_INVALIDARG, "returns %08x\n", r );
1763 r = IXMLDOMDocument_createAttribute(doc, str, &node_attr);
1764 ok( r == S_OK, "returns %08x\n", r );
1765 IXMLDOMAttribute_Release( node_attr);
1766 SysFreeString(str);
1768 /* test Processing Instruction */
1769 str = SysAllocStringLen(NULL, 0);
1770 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
1771 ok( r == E_INVALIDARG, "returns %08x\n", r );
1772 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
1773 ok( r == E_FAIL, "returns %08x\n", r );
1774 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
1775 ok( r == E_FAIL, "returns %08x\n", r );
1776 SysFreeString(str);
1778 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
1779 ok( r == S_OK, "returns %08x\n", r );
1780 if(nodePI)
1782 /* Last Child Checks */
1783 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
1784 ok(r == E_INVALIDARG, "ret %08x\n", r );
1786 nodeChild = (IXMLDOMNode*)0x1;
1787 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
1788 ok(r == S_FALSE, "ret %08x\n", r );
1789 ok(nodeChild == NULL, "nodeChild not NULL\n");
1791 /* test nodeName */
1792 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1793 ok(r == S_OK, "ret %08x\n", r );
1794 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1795 SysFreeString(str);
1797 /* test baseName */
1798 str = (BSTR)0x1;
1799 r = IXMLDOMProcessingInstruction_get_baseName(nodePI, &str);
1800 ok(r == S_OK, "ret %08x\n", r );
1801 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1802 SysFreeString(str);
1804 /* test Target */
1805 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
1806 ok(r == S_OK, "ret %08x\n", r );
1807 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
1808 SysFreeString(str);
1810 /* test get_data */
1811 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
1812 ok(r == S_OK, "ret %08x\n", r );
1813 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1814 SysFreeString(str);
1816 /* test put_data */
1817 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
1818 ok(r == E_FAIL, "ret %08x\n", r );
1820 /* test put_data */
1821 V_VT(&var) = VT_BSTR;
1822 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
1823 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
1824 ok(r == E_FAIL, "ret %08x\n", r );
1825 VariantClear(&var);
1827 /* test get nodeName */
1828 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1829 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1830 ok(r == S_OK, "ret %08x\n", r );
1831 SysFreeString(str);
1833 IXMLDOMProcessingInstruction_Release(nodePI);
1836 ref = IXMLDOMDocument_Release( doc );
1837 ok( ref == 0, "got %d\n", ref);
1839 free_bstrs();
1842 static void test_persiststreaminit(void)
1844 IXMLDOMDocument *doc;
1845 IPersistStreamInit *streaminit;
1846 ULARGE_INTEGER size;
1847 HRESULT hr;
1849 doc = create_document(&IID_IXMLDOMDocument);
1851 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&streaminit);
1852 ok(hr == S_OK, "got 0x%08x\n", hr);
1854 hr = IPersistStreamInit_InitNew(streaminit);
1855 ok(hr == S_OK, "got 0x%08x\n", hr);
1857 hr = IPersistStreamInit_GetSizeMax(streaminit, &size);
1858 ok(hr == E_NOTIMPL, "got 0x%08x\n", hr);
1860 IXMLDOMDocument_Release(doc);
1863 static void test_domnode( void )
1865 HRESULT r;
1866 IXMLDOMDocument *doc, *owner = NULL;
1867 IXMLDOMElement *element = NULL;
1868 IXMLDOMNamedNodeMap *map = NULL;
1869 IXMLDOMNode *node = NULL, *next = NULL;
1870 IXMLDOMNodeList *list = NULL;
1871 IXMLDOMAttribute *attr = NULL;
1872 DOMNodeType type = NODE_INVALID;
1873 VARIANT_BOOL b;
1874 BSTR str;
1875 VARIANT var;
1876 LONG count;
1878 doc = create_document(&IID_IXMLDOMDocument);
1880 b = FALSE;
1881 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
1882 ok( r == S_OK, "loadXML failed\n");
1883 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1885 EXPECT_CHILDREN(doc);
1887 r = IXMLDOMDocument_get_documentElement( doc, &element );
1888 ok( r == S_OK, "should be a document element\n");
1889 ok( element != NULL, "should be an element\n");
1891 VariantInit(&var);
1892 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1894 r = IXMLDOMDocument_get_nodeValue( doc, NULL );
1895 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1897 r = IXMLDOMDocument_get_nodeValue( doc, &var );
1898 ok( r == S_FALSE, "nextNode returned wrong code\n");
1899 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1900 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1902 if (element)
1904 owner = NULL;
1905 r = IXMLDOMElement_get_ownerDocument( element, &owner );
1906 ok( r == S_OK, "get_ownerDocument return code\n");
1907 ok( owner != doc, "get_ownerDocument return\n");
1908 IXMLDOMDocument_Release(owner);
1910 type = NODE_INVALID;
1911 r = IXMLDOMElement_get_nodeType( element, &type);
1912 ok( r == S_OK, "got %08x\n", r);
1913 ok( type == NODE_ELEMENT, "node not an element\n");
1915 str = NULL;
1916 r = IXMLDOMElement_get_baseName( element, &str );
1917 ok( r == S_OK, "get_baseName returned wrong code\n");
1918 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1919 SysFreeString(str);
1921 /* check if nodename is correct */
1922 r = IXMLDOMElement_get_nodeName( element, NULL );
1923 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1925 /* content doesn't matter here */
1926 str = NULL;
1927 r = IXMLDOMElement_get_nodeName( element, &str );
1928 ok ( r == S_OK, "get_nodeName wrong code\n");
1929 ok ( str != NULL, "str is null\n");
1930 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1931 SysFreeString( str );
1933 str = SysAllocString( nonexistent_fileW );
1934 V_VT(&var) = VT_I4;
1935 V_I4(&var) = 0x1234;
1936 r = IXMLDOMElement_getAttribute( element, str, &var );
1937 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1938 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1939 VariantClear(&var);
1940 SysFreeString(str);
1942 str = SysAllocString( szdl );
1943 V_VT(&var) = VT_I4;
1944 V_I4(&var) = 0x1234;
1945 r = IXMLDOMElement_getAttribute( element, str, &var );
1946 ok( r == S_OK, "getAttribute ret %08x\n", r );
1947 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1948 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1949 VariantClear( &var );
1951 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1952 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1954 r = IXMLDOMElement_getAttribute( element, str, NULL );
1955 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1957 attr = NULL;
1958 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1959 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1960 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1961 if (attr)
1963 r = IXMLDOMAttribute_get_parentNode( attr, NULL );
1964 ok( r == E_INVALIDARG, "Expected E_INVALIDARG, ret %08x\n", r );
1966 /* attribute doesn't have a parent in msxml interpretation */
1967 node = (IXMLDOMNode*)0xdeadbeef;
1968 r = IXMLDOMAttribute_get_parentNode( attr, &node );
1969 ok( r == S_FALSE, "Expected S_FALSE, ret %08x\n", r );
1970 ok( node == NULL, "Expected NULL, got %p\n", node );
1972 IXMLDOMAttribute_Release(attr);
1975 SysFreeString( str );
1977 r = IXMLDOMElement_get_attributes( element, &map );
1978 ok( r == S_OK, "get_attributes returned wrong code\n");
1979 ok( map != NULL, "should be attributes\n");
1981 EXPECT_CHILDREN(element);
1983 else
1984 ok( FALSE, "no element\n");
1986 if (map)
1988 str = SysAllocString( szdl );
1989 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1990 ok( r == S_OK, "getNamedItem returned wrong code\n");
1991 ok( node != NULL, "should be attributes\n");
1992 IXMLDOMNode_Release(node);
1993 SysFreeString( str );
1995 str = SysAllocString( szdl );
1996 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1997 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1998 SysFreeString( str );
2000 /* something that isn't in complete4A */
2001 str = SysAllocString( szOpen );
2002 node = (IXMLDOMNode *) 1;
2003 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
2004 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
2005 ok( node == NULL, "getNamedItem should have returned NULL\n");
2006 SysFreeString( str );
2008 /* test indexed access of attributes */
2009 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
2010 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
2012 r = IXMLDOMNamedNodeMap_get_length( map, &count );
2013 ok ( r == S_OK, "get_length wrong code\n");
2014 ok ( count == 1, "get_length != 1\n");
2016 node = NULL;
2017 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
2018 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
2019 ok ( node == NULL, "there is no node\n");
2021 node = NULL;
2022 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
2023 ok ( r == S_FALSE, "get_item (1) wrong code\n");
2024 ok ( node == NULL, "there is no attribute\n");
2026 node = NULL;
2027 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
2028 ok ( r == S_OK, "get_item (0) wrong code\n");
2029 ok ( node != NULL, "should be attribute\n");
2031 r = IXMLDOMNode_get_nodeName( node, NULL );
2032 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2034 /* content doesn't matter here */
2035 str = NULL;
2036 r = IXMLDOMNode_get_nodeName( node, &str );
2037 ok ( r == S_OK, "get_nodeName wrong code\n");
2038 ok ( str != NULL, "str is null\n");
2039 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
2040 SysFreeString( str );
2041 IXMLDOMNode_Release( node );
2043 /* test sequential access of attributes */
2044 node = NULL;
2045 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2046 ok ( r == S_OK, "nextNode (first time) wrong code\n");
2047 ok ( node != NULL, "nextNode, should be attribute\n");
2048 IXMLDOMNode_Release( node );
2050 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2051 ok ( r != S_OK, "nextNode (second time) wrong code\n");
2052 ok ( node == NULL, "nextNode, there is no attribute\n");
2054 r = IXMLDOMNamedNodeMap_reset( map );
2055 ok ( r == S_OK, "reset should return S_OK\n");
2057 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2058 ok ( r == S_OK, "nextNode (third time) wrong code\n");
2059 ok ( node != NULL, "nextNode, should be attribute\n");
2061 else
2062 ok( FALSE, "no map\n");
2064 if (node)
2066 type = NODE_INVALID;
2067 r = IXMLDOMNode_get_nodeType( node, &type);
2068 ok( r == S_OK, "getNamedItem returned wrong code\n");
2069 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
2071 str = NULL;
2072 r = IXMLDOMNode_get_baseName( node, NULL );
2073 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
2075 str = NULL;
2076 r = IXMLDOMNode_get_baseName( node, &str );
2077 ok( r == S_OK, "get_baseName returned wrong code\n");
2078 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
2079 SysFreeString( str );
2081 r = IXMLDOMNode_get_childNodes( node, NULL );
2082 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
2084 r = IXMLDOMNode_get_childNodes( node, &list );
2085 ok( r == S_OK, "get_childNodes returned wrong code\n");
2087 if (list)
2089 r = IXMLDOMNodeList_nextNode( list, &next );
2090 ok( r == S_OK, "nextNode returned wrong code\n");
2092 else
2093 ok( FALSE, "no childlist\n");
2095 if (next)
2097 EXPECT_NO_CHILDREN(next);
2099 type = NODE_INVALID;
2100 r = IXMLDOMNode_get_nodeType( next, &type);
2101 ok( r == S_OK, "getNamedItem returned wrong code\n");
2102 ok( type == NODE_TEXT, "node not text\n");
2104 str = (BSTR) 1;
2105 r = IXMLDOMNode_get_baseName( next, &str );
2106 ok( r == S_FALSE, "get_baseName returned wrong code\n");
2107 ok( str == NULL, "basename was wrong\n");
2108 SysFreeString(str);
2110 else
2111 ok( FALSE, "no next\n");
2113 if (next)
2114 IXMLDOMNode_Release( next );
2115 next = NULL;
2116 if (list)
2117 IXMLDOMNodeList_Release( list );
2118 list = NULL;
2119 if (node)
2120 IXMLDOMNode_Release( node );
2122 else
2123 ok( FALSE, "no node\n");
2124 node = NULL;
2126 if (map)
2127 IXMLDOMNamedNodeMap_Release( map );
2129 /* now traverse the tree from the root element */
2130 if (element)
2132 r = IXMLDOMElement_get_childNodes( element, &list );
2133 ok( r == S_OK, "get_childNodes returned wrong code\n");
2135 /* using get_item for child list doesn't advance the position */
2136 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2137 expect_node(node, "E2.E2.D1");
2138 IXMLDOMNode_Release(node);
2139 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2140 expect_node(node, "E1.E2.D1");
2141 IXMLDOMNode_Release(node);
2142 ole_check(IXMLDOMNodeList_reset(list));
2144 IXMLDOMNodeList_AddRef(list);
2145 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
2146 ole_check(IXMLDOMNodeList_reset(list));
2148 node = (void*)0xdeadbeef;
2149 str = SysAllocString(szdl);
2150 r = IXMLDOMElement_selectSingleNode( element, str, &node );
2151 SysFreeString(str);
2152 ok( r == S_FALSE, "ret %08x\n", r );
2153 ok( node == NULL, "node %p\n", node );
2155 str = SysAllocString(szbs);
2156 r = IXMLDOMElement_selectSingleNode( element, str, &node );
2157 SysFreeString(str);
2158 ok( r == S_OK, "ret %08x\n", r );
2159 r = IXMLDOMNode_Release( node );
2160 ok( r == 0, "ret %08x\n", r );
2162 else
2163 ok( FALSE, "no element\n");
2165 if (list)
2167 r = IXMLDOMNodeList_get_item(list, 0, NULL);
2168 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
2170 r = IXMLDOMNodeList_get_length(list, NULL);
2171 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
2173 r = IXMLDOMNodeList_get_length( list, &count );
2174 ok( r == S_OK, "get_length returns %08x\n", r );
2175 ok( count == 4, "get_length got %d\n", count );
2177 r = IXMLDOMNodeList_nextNode(list, NULL);
2178 ok(r == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", r);
2180 r = IXMLDOMNodeList_nextNode( list, &node );
2181 ok( r == S_OK, "nextNode returned wrong code\n");
2183 else
2184 ok( FALSE, "no list\n");
2186 if (node)
2188 type = NODE_INVALID;
2189 r = IXMLDOMNode_get_nodeType( node, &type);
2190 ok( r == S_OK, "getNamedItem returned wrong code\n");
2191 ok( type == NODE_ELEMENT, "node not text\n");
2193 r = IXMLDOMNode_hasChildNodes( node, NULL );
2194 ok( r == E_INVALIDARG, "hasChildNodes bad return\n");
2196 EXPECT_CHILDREN(node);
2198 str = NULL;
2199 r = IXMLDOMNode_get_baseName( node, &str );
2200 ok( r == S_OK, "get_baseName returned wrong code\n");
2201 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
2202 SysFreeString(str);
2204 else
2205 ok( FALSE, "no node\n");
2207 if (node)
2208 IXMLDOMNode_Release( node );
2209 if (list)
2210 IXMLDOMNodeList_Release( list );
2211 if (element)
2212 IXMLDOMElement_Release( element );
2214 b = FALSE;
2215 str = SysAllocString( szComplete5 );
2216 r = IXMLDOMDocument_loadXML( doc, str, &b );
2217 ok( r == S_OK, "loadXML failed\n");
2218 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2219 SysFreeString( str );
2221 EXPECT_CHILDREN(doc);
2223 r = IXMLDOMDocument_get_documentElement( doc, &element );
2224 ok( r == S_OK, "should be a document element\n");
2225 ok( element != NULL, "should be an element\n");
2227 if (element)
2229 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
2230 BSTR tag = NULL;
2232 /* check if the tag is correct */
2233 r = IXMLDOMElement_get_tagName( element, &tag );
2234 ok( r == S_OK, "couldn't get tag name\n");
2235 ok( tag != NULL, "tag was null\n");
2236 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
2237 SysFreeString( tag );
2239 IXMLDOMElement_Release( element );
2241 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
2243 free_bstrs();
2246 typedef struct {
2247 DOMNodeType type;
2248 REFIID iid;
2249 } refcount_test_t;
2251 static const refcount_test_t refcount_test[] = {
2252 { NODE_ELEMENT, &IID_IXMLDOMElement },
2253 { NODE_ATTRIBUTE, &IID_IXMLDOMAttribute },
2254 { NODE_TEXT, &IID_IXMLDOMText },
2255 { NODE_CDATA_SECTION, &IID_IXMLDOMCDATASection },
2256 { NODE_ENTITY_REFERENCE, &IID_IXMLDOMEntityReference },
2257 { NODE_PROCESSING_INSTRUCTION, &IID_IXMLDOMProcessingInstruction },
2258 { NODE_COMMENT, &IID_IXMLDOMComment },
2259 { NODE_DOCUMENT_FRAGMENT, &IID_IXMLDOMDocumentFragment },
2260 { NODE_INVALID, &IID_NULL }
2263 static void test_refs(void)
2265 IXMLDOMImplementation *impl, *impl2;
2266 IXMLDOMElement *element, *elem2;
2267 IXMLDOMNodeList *node_list = NULL;
2268 IXMLDOMNode *node, *node2, *node3;
2269 const refcount_test_t *ptr;
2270 IXMLDOMDocument *doc;
2271 IUnknown *unk, *unk2;
2272 VARIANT_BOOL b;
2273 HRESULT hr;
2274 LONG ref;
2276 doc = create_document(&IID_IXMLDOMDocument);
2278 ptr = refcount_test;
2279 while (ptr->type != NODE_INVALID)
2281 IUnknown *node_typed, *node_typed2;
2282 IDispatchEx *dispex, *dispex2;
2283 IDispatch *disp, *disp2;
2284 VARIANT type;
2286 V_VT(&type) = VT_I1;
2287 V_I1(&type) = ptr->type;
2289 EXPECT_REF(doc, 1);
2290 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("name"), NULL, &node);
2291 EXPECT_HR(hr, S_OK);
2292 EXPECT_REF(doc, 1);
2293 EXPECT_REF(node, 1);
2295 /* try IDispatch and IUnknown from IXMLDOMNode */
2296 hr = IXMLDOMNode_QueryInterface(node, &IID_IUnknown, (void**)&unk);
2297 EXPECT_HR(hr, S_OK);
2298 EXPECT_REF(unk, 2);
2299 todo_wine {
2300 EXPECT_REF(node, 1);
2301 ok(unk != (IUnknown*)node, "%d: got %p and %p\n", ptr->type, unk, node);
2303 EXPECT_REF(unk, 2);
2304 hr = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
2305 EXPECT_HR(hr, S_OK);
2306 todo_wine ok(unk != (IUnknown*)disp, "%d: got %p and %p\n", ptr->type, unk, disp);
2307 EXPECT_REF(unk, 3);
2308 todo_wine EXPECT_REF(disp, 1);
2310 EXPECT_REF(unk, 3);
2311 hr = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp2);
2312 EXPECT_HR(hr, S_OK);
2313 todo_wine ok(disp != disp2, "%d: got %p and %p\n", ptr->type, disp, disp2);
2314 EXPECT_REF(unk, 4);
2315 todo_wine EXPECT_REF(disp2, 1);
2317 IDispatch_Release(disp);
2318 IDispatch_Release(disp2);
2320 /* get IXMLDOMNode from this IUnknown */
2321 EXPECT_REF(unk, 2);
2322 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMNode, (void**)&node2);
2323 EXPECT_HR(hr, S_OK);
2324 todo_wine ok(unk != (IUnknown*)node2, "%d: got %p and %p\n", ptr->type, unk, node2);
2325 EXPECT_REF(unk, 3);
2326 todo_wine EXPECT_REF(node2, 1);
2328 EXPECT_REF(unk, 3);
2329 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMNode, (void**)&node3);
2330 EXPECT_HR(hr, S_OK);
2331 todo_wine ok(node2 != node3, "%d: got %p and %p\n", ptr->type, node2, node3);
2332 EXPECT_REF(unk, 4);
2333 todo_wine EXPECT_REF(node3, 1);
2335 IXMLDOMNode_Release(node2);
2336 IXMLDOMNode_Release(node3);
2338 /* try IDispatchEx from IUnknown */
2339 EXPECT_REF(unk, 2);
2340 hr = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
2341 EXPECT_HR(hr, S_OK);
2342 ok(unk != (IUnknown*)dispex, "%d: got %p and %p\n", ptr->type, unk, dispex);
2343 EXPECT_REF(unk, 3);
2344 todo_wine EXPECT_REF(dispex, 1);
2346 EXPECT_REF(unk, 3);
2347 hr = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex2);
2348 EXPECT_HR(hr, S_OK);
2349 todo_wine ok(dispex != dispex2, "%d: got %p and %p\n", ptr->type, dispex, dispex2);
2350 EXPECT_REF(unk, 4);
2351 todo_wine EXPECT_REF(dispex2, 1);
2353 IDispatchEx_Release(dispex);
2354 IDispatchEx_Release(dispex2);
2356 /* try corresponding IXMLDOM* */
2357 EXPECT_REF(unk, 2);
2358 hr = IUnknown_QueryInterface(unk, ptr->iid, (void**)&node_typed);
2359 EXPECT_HR(hr, S_OK);
2360 EXPECT_REF(unk, 3);
2361 hr = IUnknown_QueryInterface(unk, ptr->iid, (void**)&node_typed2);
2362 EXPECT_HR(hr, S_OK);
2363 EXPECT_REF(unk, 4);
2364 todo_wine ok(node_typed != node_typed2, "%d: got %p and %p\n", ptr->type, node_typed, node_typed2);
2365 IUnknown_Release(node_typed);
2366 IUnknown_Release(node_typed2);
2368 /* try invalid IXMLDOM* */
2369 hr = IUnknown_QueryInterface(unk, (ptr+1)->iid, (void**)&node_typed);
2370 EXPECT_HR(hr, E_NOINTERFACE);
2372 IUnknown_Release(unk);
2374 EXPECT_REF(node, 1);
2375 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMNode, (void**)&node2);
2376 EXPECT_HR(hr, S_OK);
2377 EXPECT_REF(node, 2);
2378 ok(node == node2, "%d: got %p and %p\n", ptr->type, node, node2);
2380 EXPECT_REF(node, 2);
2381 hr = IXMLDOMNode_QueryInterface(node, ptr->iid, (void**)&node_typed);
2382 EXPECT_HR(hr, S_OK);
2383 EXPECT_REF(node, 3);
2384 todo_wine {
2385 EXPECT_REF(node_typed, 2);
2386 ok((IUnknown*)node != node_typed, "%d: got %p and %p\n", ptr->type, node, node_typed);
2388 IUnknown_Release(node_typed);
2390 IXMLDOMNode_Release(node2);
2391 IXMLDOMNode_Release(node);
2393 ptr++;
2396 EXPECT_REF(doc, 1);
2397 ref = IXMLDOMDocument_Release(doc);
2398 ok( ref == 0, "ref %d\n", ref);
2400 /* check IUnknown after releasing DOM iface */
2401 doc = create_document(&IID_IXMLDOMDocument);
2402 EXPECT_REF(doc, 1);
2403 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
2404 EXPECT_HR(hr, S_OK);
2405 todo_wine {
2406 EXPECT_REF(unk, 3);
2407 EXPECT_REF(doc, 1);
2409 IXMLDOMDocument_Release(doc);
2410 EXPECT_REF(unk, 1);
2411 IUnknown_Release(unk);
2413 doc = create_document(&IID_IXMLDOMDocument);
2415 EXPECT_REF(doc, 1);
2416 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
2417 EXPECT_HR(hr, S_OK);
2418 todo_wine {
2419 EXPECT_REF(unk, 3);
2420 EXPECT_REF(doc, 1);
2422 IUnknown_Release(unk);
2424 /* IXMLDOMImplementation */
2425 EXPECT_REF(doc, 1);
2426 hr = IXMLDOMDocument_get_implementation(doc, &impl);
2427 EXPECT_HR(hr, S_OK);
2428 EXPECT_REF(doc, 1);
2429 EXPECT_REF(impl, 1);
2430 hr = IXMLDOMDocument_get_implementation(doc, &impl2);
2431 EXPECT_HR(hr, S_OK);
2432 EXPECT_REF(doc, 1);
2433 EXPECT_REF(impl2, 1);
2434 ok(impl != impl2, "got %p, %p\n", impl, impl2);
2435 IXMLDOMImplementation_Release(impl);
2436 IXMLDOMImplementation_Release(impl2);
2438 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
2439 EXPECT_HR(hr, S_OK);
2440 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2442 EXPECT_REF(doc, 1);
2443 IXMLDOMDocument_AddRef( doc );
2444 EXPECT_REF(doc, 2);
2445 IXMLDOMDocument_AddRef( doc );
2446 EXPECT_REF(doc, 3);
2448 IXMLDOMDocument_Release( doc );
2449 IXMLDOMDocument_Release( doc );
2451 EXPECT_REF(doc, 1);
2452 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
2453 EXPECT_HR(hr, S_OK);
2454 todo_wine {
2455 EXPECT_REF(unk, 3);
2456 EXPECT_REF(doc, 1);
2458 hr = IXMLDOMDocument_get_documentElement(doc, &element);
2459 EXPECT_HR(hr, S_OK);
2460 todo_wine {
2461 EXPECT_REF(doc, 1);
2462 EXPECT_REF(element, 2);
2464 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
2465 EXPECT_HR(hr, S_OK);
2467 todo_wine {
2468 EXPECT_REF(doc, 1);
2469 EXPECT_REF(element, 2);
2470 EXPECT_REF(elem2, 2);
2472 IXMLDOMElement_AddRef(element);
2473 todo_wine EXPECT_REF(element, 3);
2474 IXMLDOMElement_Release(element);
2476 /* get IUnknown from a node doesn't touch node instance refcount */
2477 hr = IXMLDOMElement_QueryInterface(element, &IID_IUnknown, (void**)&unk);
2478 EXPECT_HR(hr, S_OK);
2479 EXPECT_REF(element, 2);
2480 todo_wine {
2481 EXPECT_REF(unk, 4);
2482 EXPECT_REF(elem2, 2);
2484 hr = IXMLDOMElement_QueryInterface(elem2, &IID_IUnknown, (void**)&unk2);
2485 EXPECT_HR(hr, S_OK);
2486 todo_wine {
2487 EXPECT_REF(unk, 5);
2488 EXPECT_REF(unk2, 5);
2490 EXPECT_REF(element, 2);
2491 EXPECT_REF(elem2, 2);
2493 todo_wine ok(unk == unk2, "got %p and %p\n", unk, unk2);
2494 IUnknown_Release(unk);
2496 /* IUnknown refcount is not affected by node refcount */
2497 todo_wine EXPECT_REF(unk2, 4);
2498 IXMLDOMElement_AddRef(elem2);
2499 todo_wine EXPECT_REF(unk2, 4);
2500 IXMLDOMElement_Release(elem2);
2502 IXMLDOMElement_Release(elem2);
2503 todo_wine EXPECT_REF(unk2, 3);
2505 IUnknown_Release(unk2);
2507 hr = IXMLDOMElement_get_childNodes( element, &node_list );
2508 EXPECT_HR(hr, S_OK);
2510 todo_wine EXPECT_REF(element, 2);
2511 EXPECT_REF(node_list, 1);
2513 hr = IXMLDOMNodeList_get_item( node_list, 0, &node );
2514 EXPECT_HR(hr, S_OK);
2515 EXPECT_REF(node_list, 1);
2516 EXPECT_REF(node, 1);
2518 hr = IXMLDOMNodeList_get_item( node_list, 0, &node2 );
2519 EXPECT_HR(hr, S_OK);
2520 EXPECT_REF(node_list, 1);
2521 EXPECT_REF(node2, 1);
2523 ref = IXMLDOMNode_Release( node );
2524 ok( ref == 0, "ref %d\n", ref );
2525 ref = IXMLDOMNode_Release( node2 );
2526 ok( ref == 0, "ref %d\n", ref );
2528 ref = IXMLDOMNodeList_Release( node_list );
2529 ok( ref == 0, "ref %d\n", ref );
2531 ok( node != node2, "node %p node2 %p\n", node, node2 );
2533 ref = IXMLDOMDocument_Release( doc );
2534 todo_wine ok( ref == 0, "ref %d\n", ref );
2536 todo_wine EXPECT_REF(element, 2);
2538 /* IUnknown must be unique however we obtain it */
2539 hr = IXMLDOMElement_QueryInterface(element, &IID_IUnknown, (void**)&unk);
2540 EXPECT_HR(hr, S_OK);
2541 EXPECT_REF(element, 2);
2542 hr = IXMLDOMElement_QueryInterface(element, &IID_IXMLDOMNode, (void**)&node);
2543 EXPECT_HR(hr, S_OK);
2544 todo_wine EXPECT_REF(element, 2);
2545 hr = IXMLDOMNode_QueryInterface(node, &IID_IUnknown, (void**)&unk2);
2546 EXPECT_HR(hr, S_OK);
2547 todo_wine EXPECT_REF(element, 2);
2548 ok(unk == unk2, "unk %p unk2 %p\n", unk, unk2);
2549 todo_wine ok(element != (void*)node, "node %p element %p\n", node, element);
2551 IUnknown_Release( unk2 );
2552 IUnknown_Release( unk );
2553 IXMLDOMNode_Release( node );
2554 todo_wine EXPECT_REF(element, 2);
2556 IXMLDOMElement_Release( element );
2558 free_bstrs();
2561 static void test_create(void)
2563 static const WCHAR szOne[] = {'1',0};
2564 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
2565 HRESULT r;
2566 VARIANT var;
2567 BSTR str, name;
2568 IXMLDOMDocument *doc;
2569 IXMLDOMElement *element;
2570 IXMLDOMComment *comment;
2571 IXMLDOMText *text;
2572 IXMLDOMCDATASection *cdata;
2573 IXMLDOMNode *root, *node, *child;
2574 IXMLDOMNamedNodeMap *attr_map;
2575 IUnknown *unk;
2576 LONG ref;
2577 LONG num;
2579 doc = create_document(&IID_IXMLDOMDocument);
2581 EXPECT_REF(doc, 1);
2583 /* types not supported for creation */
2584 V_VT(&var) = VT_I1;
2585 V_I1(&var) = NODE_DOCUMENT;
2586 node = (IXMLDOMNode*)0x1;
2587 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2588 ok( r == E_INVALIDARG, "returns %08x\n", r );
2589 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2591 V_VT(&var) = VT_I1;
2592 V_I1(&var) = NODE_DOCUMENT_TYPE;
2593 node = (IXMLDOMNode*)0x1;
2594 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2595 ok( r == E_INVALIDARG, "returns %08x\n", r );
2596 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2598 V_VT(&var) = VT_I1;
2599 V_I1(&var) = NODE_ENTITY;
2600 node = (IXMLDOMNode*)0x1;
2601 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2602 ok( r == E_INVALIDARG, "returns %08x\n", r );
2603 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2605 V_VT(&var) = VT_I1;
2606 V_I1(&var) = NODE_NOTATION;
2607 node = (IXMLDOMNode*)0x1;
2608 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2609 ok( r == E_INVALIDARG, "returns %08x\n", r );
2610 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2612 /* NODE_COMMENT */
2613 V_VT(&var) = VT_I1;
2614 V_I1(&var) = NODE_COMMENT;
2615 node = NULL;
2616 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2617 ok( r == S_OK, "returns %08x\n", r );
2618 ok( node != NULL, "\n");
2620 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2621 ok( r == S_OK, "returns %08x\n", r );
2622 IXMLDOMNode_Release(node);
2624 str = NULL;
2625 r = IXMLDOMComment_get_data(comment, &str);
2626 ok( r == S_OK, "returns %08x\n", r );
2627 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2628 IXMLDOMComment_Release(comment);
2629 SysFreeString(str);
2631 node = (IXMLDOMNode*)0x1;
2632 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2633 ok( r == S_OK, "returns %08x\n", r );
2635 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2636 ok( r == S_OK, "returns %08x\n", r );
2637 IXMLDOMNode_Release(node);
2639 str = NULL;
2640 r = IXMLDOMComment_get_data(comment, &str);
2641 ok( r == S_OK, "returns %08x\n", r );
2642 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2643 IXMLDOMComment_Release(comment);
2644 SysFreeString(str);
2646 node = (IXMLDOMNode*)0x1;
2647 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2648 ok( r == S_OK, "returns %08x\n", r );
2650 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2651 ok( r == S_OK, "returns %08x\n", r );
2652 IXMLDOMNode_Release(node);
2654 str = NULL;
2655 r = IXMLDOMComment_get_data(comment, &str);
2656 ok( r == S_OK, "returns %08x\n", r );
2657 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2658 IXMLDOMComment_Release(comment);
2659 SysFreeString(str);
2661 /* NODE_TEXT */
2662 V_VT(&var) = VT_I1;
2663 V_I1(&var) = NODE_TEXT;
2664 node = NULL;
2665 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2666 ok( r == S_OK, "returns %08x\n", r );
2667 ok( node != NULL, "\n");
2669 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2670 ok( r == S_OK, "returns %08x\n", r );
2671 IXMLDOMNode_Release(node);
2673 str = NULL;
2674 r = IXMLDOMText_get_data(text, &str);
2675 ok( r == S_OK, "returns %08x\n", r );
2676 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2677 IXMLDOMText_Release(text);
2678 SysFreeString(str);
2680 node = (IXMLDOMNode*)0x1;
2681 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2682 ok( r == S_OK, "returns %08x\n", r );
2684 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2685 ok( r == S_OK, "returns %08x\n", r );
2686 IXMLDOMNode_Release(node);
2688 str = NULL;
2689 r = IXMLDOMText_get_data(text, &str);
2690 ok( r == S_OK, "returns %08x\n", r );
2691 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2692 IXMLDOMText_Release(text);
2693 SysFreeString(str);
2695 node = (IXMLDOMNode*)0x1;
2696 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2697 ok( r == S_OK, "returns %08x\n", r );
2699 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2700 ok( r == S_OK, "returns %08x\n", r );
2701 IXMLDOMNode_Release(node);
2703 str = NULL;
2704 r = IXMLDOMText_get_data(text, &str);
2705 ok( r == S_OK, "returns %08x\n", r );
2706 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2707 IXMLDOMText_Release(text);
2708 SysFreeString(str);
2710 /* NODE_CDATA_SECTION */
2711 V_VT(&var) = VT_I1;
2712 V_I1(&var) = NODE_CDATA_SECTION;
2713 node = NULL;
2714 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2715 ok( r == S_OK, "returns %08x\n", r );
2716 ok( node != NULL, "\n");
2718 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2719 ok( r == S_OK, "returns %08x\n", r );
2720 IXMLDOMNode_Release(node);
2722 str = NULL;
2723 r = IXMLDOMCDATASection_get_data(cdata, &str);
2724 ok( r == S_OK, "returns %08x\n", r );
2725 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2726 IXMLDOMCDATASection_Release(cdata);
2727 SysFreeString(str);
2729 node = (IXMLDOMNode*)0x1;
2730 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2731 ok( r == S_OK, "returns %08x\n", r );
2733 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2734 ok( r == S_OK, "returns %08x\n", r );
2735 IXMLDOMNode_Release(node);
2737 str = NULL;
2738 r = IXMLDOMCDATASection_get_data(cdata, &str);
2739 ok( r == S_OK, "returns %08x\n", r );
2740 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2741 IXMLDOMCDATASection_Release(cdata);
2742 SysFreeString(str);
2744 node = (IXMLDOMNode*)0x1;
2745 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2746 ok( r == S_OK, "returns %08x\n", r );
2748 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2749 ok( r == S_OK, "returns %08x\n", r );
2750 IXMLDOMNode_Release(node);
2752 str = NULL;
2753 r = IXMLDOMCDATASection_get_data(cdata, &str);
2754 ok( r == S_OK, "returns %08x\n", r );
2755 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2756 IXMLDOMCDATASection_Release(cdata);
2757 SysFreeString(str);
2759 /* NODE_ATTRIBUTE */
2760 V_VT(&var) = VT_I1;
2761 V_I1(&var) = NODE_ATTRIBUTE;
2762 node = (IXMLDOMNode*)0x1;
2763 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2764 ok( r == E_FAIL, "returns %08x\n", r );
2765 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2767 V_VT(&var) = VT_I1;
2768 V_I1(&var) = NODE_ATTRIBUTE;
2769 node = (IXMLDOMNode*)0x1;
2770 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2771 ok( r == E_FAIL, "returns %08x\n", r );
2772 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2774 V_VT(&var) = VT_I1;
2775 V_I1(&var) = NODE_ATTRIBUTE;
2776 str = SysAllocString( szlc );
2777 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2778 ok( r == S_OK, "returns %08x\n", r );
2779 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2780 SysFreeString(str);
2782 /* a name is required for attribute, try a BSTR with first null wchar */
2783 V_VT(&var) = VT_I1;
2784 V_I1(&var) = NODE_ATTRIBUTE;
2785 str = SysAllocString( szstr1 );
2786 str[0] = 0;
2787 node = (IXMLDOMNode*)0x1;
2788 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2789 ok( r == E_FAIL, "returns %08x\n", r );
2790 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2791 SysFreeString(str);
2793 /* NODE_PROCESSING_INSTRUCTION */
2794 V_VT(&var) = VT_I1;
2795 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2796 node = (IXMLDOMNode*)0x1;
2797 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2798 ok( r == E_FAIL, "returns %08x\n", r );
2799 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2801 V_VT(&var) = VT_I1;
2802 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2803 node = (IXMLDOMNode*)0x1;
2804 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2805 ok( r == E_FAIL, "returns %08x\n", r );
2806 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2808 V_VT(&var) = VT_I1;
2809 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2810 r = IXMLDOMDocument_createNode( doc, var, _bstr_("pi"), NULL, NULL );
2811 ok( r == E_INVALIDARG, "returns %08x\n", r );
2813 /* NODE_ENTITY_REFERENCE */
2814 V_VT(&var) = VT_I1;
2815 V_I1(&var) = NODE_ENTITY_REFERENCE;
2816 node = (IXMLDOMNode*)0x1;
2817 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2818 ok( r == E_FAIL, "returns %08x\n", r );
2819 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2821 V_VT(&var) = VT_I1;
2822 V_I1(&var) = NODE_ENTITY_REFERENCE;
2823 node = (IXMLDOMNode*)0x1;
2824 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2825 ok( r == E_FAIL, "returns %08x\n", r );
2826 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2828 /* NODE_ELEMENT */
2829 V_VT(&var) = VT_I1;
2830 V_I1(&var) = NODE_ELEMENT;
2831 node = (IXMLDOMNode*)0x1;
2832 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2833 ok( r == E_FAIL, "returns %08x\n", r );
2834 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2836 V_VT(&var) = VT_I1;
2837 V_I1(&var) = NODE_ELEMENT;
2838 node = (IXMLDOMNode*)0x1;
2839 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2840 ok( r == E_FAIL, "returns %08x\n", r );
2841 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2843 V_VT(&var) = VT_I1;
2844 V_I1(&var) = NODE_ELEMENT;
2845 str = SysAllocString( szlc );
2846 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2847 ok( r == S_OK, "returns %08x\n", r );
2848 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2850 V_VT(&var) = VT_I1;
2851 V_I1(&var) = NODE_ELEMENT;
2852 r = IXMLDOMDocument_createNode( doc, var, str, NULL, NULL );
2853 ok( r == E_INVALIDARG, "returns %08x\n", r );
2855 V_VT(&var) = VT_R4;
2856 V_R4(&var) = NODE_ELEMENT;
2857 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2858 ok( r == S_OK, "returns %08x\n", r );
2859 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2861 V_VT(&var) = VT_BSTR;
2862 V_BSTR(&var) = SysAllocString( szOne );
2863 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2864 ok( r == S_OK, "returns %08x\n", r );
2865 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2866 VariantClear(&var);
2868 V_VT(&var) = VT_BSTR;
2869 V_BSTR(&var) = SysAllocString( szOneGarbage );
2870 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2871 ok( r == E_INVALIDARG, "returns %08x\n", r );
2872 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2873 VariantClear(&var);
2875 V_VT(&var) = VT_I4;
2876 V_I4(&var) = NODE_ELEMENT;
2877 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2878 ok( r == S_OK, "returns %08x\n", r );
2880 EXPECT_REF(doc, 1);
2881 r = IXMLDOMDocument_appendChild( doc, node, &root );
2882 ok( r == S_OK, "returns %08x\n", r );
2883 ok( node == root, "%p %p\n", node, root );
2884 EXPECT_REF(doc, 1);
2886 EXPECT_REF(node, 2);
2888 ref = IXMLDOMNode_Release( node );
2889 ok(ref == 1, "ref %d\n", ref);
2890 SysFreeString( str );
2892 V_VT(&var) = VT_I4;
2893 V_I4(&var) = NODE_ELEMENT;
2894 str = SysAllocString( szbs );
2895 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2896 ok( r == S_OK, "returns %08x\n", r );
2897 SysFreeString( str );
2899 EXPECT_REF(node, 1);
2901 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk );
2902 ok( r == S_OK, "returns %08x\n", r );
2904 EXPECT_REF(unk, 2);
2906 V_VT(&var) = VT_EMPTY;
2907 child = NULL;
2908 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
2909 ok( r == S_OK, "returns %08x\n", r );
2910 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
2912 todo_wine EXPECT_REF(unk, 4);
2914 IXMLDOMNode_Release( child );
2915 IUnknown_Release( unk );
2917 V_VT(&var) = VT_NULL;
2918 V_DISPATCH(&var) = (IDispatch*)node;
2919 r = IXMLDOMNode_insertBefore( root, node, var, &child );
2920 ok( r == S_OK, "returns %08x\n", r );
2921 ok( node == child, "%p %p\n", node, child );
2922 IXMLDOMNode_Release( child );
2924 V_VT(&var) = VT_NULL;
2925 V_DISPATCH(&var) = (IDispatch*)node;
2926 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
2927 ok( r == S_OK, "returns %08x\n", r );
2928 IXMLDOMNode_Release( node );
2930 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (void**)&element );
2931 ok( r == S_OK, "returns %08x\n", r );
2933 r = IXMLDOMElement_get_attributes( element, &attr_map );
2934 ok( r == S_OK, "returns %08x\n", r );
2935 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2936 ok( r == S_OK, "returns %08x\n", r );
2937 ok( num == 0, "num %d\n", num );
2938 IXMLDOMNamedNodeMap_Release( attr_map );
2940 V_VT(&var) = VT_BSTR;
2941 V_BSTR(&var) = SysAllocString( szstr1 );
2942 name = SysAllocString( szdl );
2943 r = IXMLDOMElement_setAttribute( element, name, var );
2944 ok( r == S_OK, "returns %08x\n", r );
2945 r = IXMLDOMElement_get_attributes( element, &attr_map );
2946 ok( r == S_OK, "returns %08x\n", r );
2947 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2948 ok( r == S_OK, "returns %08x\n", r );
2949 ok( num == 1, "num %d\n", num );
2950 IXMLDOMNamedNodeMap_Release( attr_map );
2951 VariantClear(&var);
2953 V_VT(&var) = VT_BSTR;
2954 V_BSTR(&var) = SysAllocString( szstr2 );
2955 r = IXMLDOMElement_setAttribute( element, name, var );
2956 ok( r == S_OK, "returns %08x\n", r );
2957 r = IXMLDOMElement_get_attributes( element, &attr_map );
2958 ok( r == S_OK, "returns %08x\n", r );
2959 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2960 ok( r == S_OK, "returns %08x\n", r );
2961 ok( num == 1, "num %d\n", num );
2962 IXMLDOMNamedNodeMap_Release( attr_map );
2963 VariantClear(&var);
2964 r = IXMLDOMElement_getAttribute( element, name, &var );
2965 ok( r == S_OK, "returns %08x\n", r );
2966 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
2967 VariantClear(&var);
2968 SysFreeString(name);
2970 V_VT(&var) = VT_BSTR;
2971 V_BSTR(&var) = SysAllocString( szstr1 );
2972 name = SysAllocString( szlc );
2973 r = IXMLDOMElement_setAttribute( element, name, var );
2974 ok( r == S_OK, "returns %08x\n", r );
2975 r = IXMLDOMElement_get_attributes( element, &attr_map );
2976 ok( r == S_OK, "returns %08x\n", r );
2977 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2978 ok( r == S_OK, "returns %08x\n", r );
2979 ok( num == 2, "num %d\n", num );
2980 IXMLDOMNamedNodeMap_Release( attr_map );
2981 VariantClear(&var);
2982 SysFreeString(name);
2984 V_VT(&var) = VT_I4;
2985 V_I4(&var) = 10;
2986 name = SysAllocString( szbs );
2987 r = IXMLDOMElement_setAttribute( element, name, var );
2988 ok( r == S_OK, "returns %08x\n", r );
2989 VariantClear(&var);
2990 r = IXMLDOMElement_getAttribute( element, name, &var );
2991 ok( r == S_OK, "returns %08x\n", r );
2992 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
2993 VariantClear(&var);
2994 SysFreeString(name);
2996 /* Create an Attribute */
2997 V_VT(&var) = VT_I4;
2998 V_I4(&var) = NODE_ATTRIBUTE;
2999 str = SysAllocString( szAttribute );
3000 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
3001 ok( r == S_OK, "returns %08x\n", r );
3002 ok( node != NULL, "node was null\n");
3003 SysFreeString(str);
3005 IXMLDOMElement_Release( element );
3006 IXMLDOMNode_Release( root );
3007 IXMLDOMDocument_Release( doc );
3010 struct queryresult_t {
3011 const char *query;
3012 const char *result;
3013 int len;
3016 static const struct queryresult_t elementsbytagname[] = {
3017 { "", "P1.D1 E2.D1 E1.E2.D1 T1.E1.E2.D1 E2.E2.D1 T1.E2.E2.D1 E3.E2.D1 E4.E2.D1 E1.E4.E2.D1 T1.E1.E4.E2.D1", 10 },
3018 { "*", "E2.D1 E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1 E1.E4.E2.D1", 6 },
3019 { "bs", "E1.E2.D1", 1 },
3020 { "dl", "", 0 },
3021 { "str1","", 0 },
3022 { NULL }
3025 static void test_getElementsByTagName(void)
3027 const struct queryresult_t *ptr = elementsbytagname;
3028 IXMLDOMNodeList *node_list;
3029 IXMLDOMDocument *doc;
3030 IXMLDOMElement *elem;
3031 WCHAR buff[100];
3032 VARIANT_BOOL b;
3033 HRESULT r;
3034 LONG len;
3035 BSTR str;
3037 doc = create_document(&IID_IXMLDOMDocument);
3039 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3040 ok( r == S_OK, "loadXML failed\n");
3041 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3043 /* null arguments cases */
3044 r = IXMLDOMDocument_getElementsByTagName(doc, NULL, &node_list);
3045 ok( r == E_INVALIDARG, "ret %08x\n", r );
3046 r = IXMLDOMDocument_getElementsByTagName(doc, _bstr_("*"), NULL);
3047 ok( r == E_INVALIDARG, "ret %08x\n", r );
3049 while (ptr->query)
3051 r = IXMLDOMDocument_getElementsByTagName(doc, _bstr_(ptr->query), &node_list);
3052 ok(r == S_OK, "ret %08x\n", r);
3053 r = IXMLDOMNodeList_get_length(node_list, &len);
3054 ok(r == S_OK, "ret %08x\n", r);
3055 ok(len == ptr->len, "%s: got len %d, expected %d\n", ptr->query, len, ptr->len);
3056 expect_list_and_release(node_list, ptr->result);
3058 free_bstrs();
3059 ptr++;
3062 /* broken query BSTR */
3063 memcpy(&buff[2], szstar, sizeof(szstar));
3064 /* just a big length */
3065 *(DWORD*)buff = 0xf0f0;
3066 r = IXMLDOMDocument_getElementsByTagName(doc, &buff[2], &node_list);
3067 ok( r == S_OK, "ret %08x\n", r );
3068 r = IXMLDOMNodeList_get_length( node_list, &len );
3069 ok( r == S_OK, "ret %08x\n", r );
3070 ok( len == 6, "len %d\n", len );
3071 IXMLDOMNodeList_Release( node_list );
3073 /* test for element */
3074 r = IXMLDOMDocument_get_documentElement(doc, &elem);
3075 ok( r == S_OK, "ret %08x\n", r );
3077 str = SysAllocString( szstar );
3079 /* null arguments cases */
3080 r = IXMLDOMElement_getElementsByTagName(elem, NULL, &node_list);
3081 ok( r == E_INVALIDARG, "ret %08x\n", r );
3082 r = IXMLDOMElement_getElementsByTagName(elem, str, NULL);
3083 ok( r == E_INVALIDARG, "ret %08x\n", r );
3085 r = IXMLDOMElement_getElementsByTagName(elem, str, &node_list);
3086 ok( r == S_OK, "ret %08x\n", r );
3087 r = IXMLDOMNodeList_get_length( node_list, &len );
3088 ok( r == S_OK, "ret %08x\n", r );
3089 ok( len == 5, "len %d\n", len );
3090 expect_list_and_release(node_list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1 E1.E4.E2.D1");
3091 SysFreeString( str );
3093 /* broken query BSTR */
3094 memcpy(&buff[2], szstar, sizeof(szstar));
3095 /* just a big length */
3096 *(DWORD*)buff = 0xf0f0;
3097 r = IXMLDOMElement_getElementsByTagName(elem, &buff[2], &node_list);
3098 ok( r == S_OK, "ret %08x\n", r );
3099 r = IXMLDOMNodeList_get_length( node_list, &len );
3100 ok( r == S_OK, "ret %08x\n", r );
3101 ok( len == 5, "len %d\n", len );
3102 IXMLDOMNodeList_Release( node_list );
3104 IXMLDOMElement_Release(elem);
3106 IXMLDOMDocument_Release( doc );
3108 free_bstrs();
3111 static void test_get_text(void)
3113 HRESULT r;
3114 BSTR str;
3115 VARIANT_BOOL b;
3116 IXMLDOMDocument *doc;
3117 IXMLDOMNode *node, *node2, *node3;
3118 IXMLDOMNode *nodeRoot;
3119 IXMLDOMNodeList *node_list;
3120 IXMLDOMNamedNodeMap *node_map;
3121 LONG len;
3123 doc = create_document(&IID_IXMLDOMDocument);
3125 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3126 ok( r == S_OK, "loadXML failed\n");
3127 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3129 str = SysAllocString( szbs );
3130 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
3131 ok( r == S_OK, "ret %08x\n", r );
3132 SysFreeString(str);
3134 /* Test to get all child node text. */
3135 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&nodeRoot);
3136 ok( r == S_OK, "ret %08x\n", r );
3137 if(r == S_OK)
3139 r = IXMLDOMNode_get_text( nodeRoot, &str );
3140 ok( r == S_OK, "ret %08x\n", r );
3141 ok( compareIgnoreReturns(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text: %s\n", wine_dbgstr_w(str));
3142 SysFreeString(str);
3144 IXMLDOMNode_Release(nodeRoot);
3147 r = IXMLDOMNodeList_get_length( node_list, NULL );
3148 ok( r == E_INVALIDARG, "ret %08x\n", r );
3150 r = IXMLDOMNodeList_get_length( node_list, &len );
3151 ok( r == S_OK, "ret %08x\n", r );
3152 ok( len == 1, "expect 1 got %d\n", len );
3154 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
3155 ok( r == E_INVALIDARG, "ret %08x\n", r );
3157 r = IXMLDOMNodeList_nextNode( node_list, NULL );
3158 ok( r == E_INVALIDARG, "ret %08x\n", r );
3160 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
3161 ok( r == S_OK, "ret %08x\n", r );
3162 IXMLDOMNodeList_Release( node_list );
3164 /* Invalid output parameter*/
3165 r = IXMLDOMNode_get_text( node, NULL );
3166 ok( r == E_INVALIDARG, "ret %08x\n", r );
3168 r = IXMLDOMNode_get_text( node, &str );
3169 ok( r == S_OK, "ret %08x\n", r );
3170 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
3171 SysFreeString(str);
3173 r = IXMLDOMNode_get_attributes( node, &node_map );
3174 ok( r == S_OK, "ret %08x\n", r );
3176 str = SysAllocString( szvr );
3177 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
3178 ok( r == S_OK, "ret %08x\n", r );
3179 SysFreeString(str);
3181 r = IXMLDOMNode_get_text( node2, &str );
3182 ok( r == S_OK, "ret %08x\n", r );
3183 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3184 SysFreeString(str);
3186 r = IXMLDOMNode_get_firstChild( node2, &node3 );
3187 ok( r == S_OK, "ret %08x\n", r );
3189 r = IXMLDOMNode_get_text( node3, &str );
3190 ok( r == S_OK, "ret %08x\n", r );
3191 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3192 SysFreeString(str);
3195 IXMLDOMNode_Release( node3 );
3196 IXMLDOMNode_Release( node2 );
3197 IXMLDOMNamedNodeMap_Release( node_map );
3198 IXMLDOMNode_Release( node );
3199 IXMLDOMDocument_Release( doc );
3201 free_bstrs();
3204 static void test_get_childNodes(void)
3206 IXMLDOMNodeList *node_list, *node_list2;
3207 IEnumVARIANT *enum1, *enum2, *enum3;
3208 VARIANT_BOOL b;
3209 IXMLDOMDocument *doc;
3210 IXMLDOMNode *node, *node2;
3211 IXMLDOMElement *element;
3212 IUnknown *unk1, *unk2;
3213 HRESULT hr;
3214 VARIANT v;
3215 BSTR str;
3216 LONG len;
3218 doc = create_document(&IID_IXMLDOMDocument);
3220 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3221 EXPECT_HR(hr, S_OK);
3222 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3224 hr = IXMLDOMDocument_get_documentElement( doc, &element );
3225 EXPECT_HR(hr, S_OK);
3227 hr = IXMLDOMElement_get_childNodes( element, &node_list );
3228 EXPECT_HR(hr, S_OK);
3230 hr = IXMLDOMNodeList_get_length( node_list, &len );
3231 EXPECT_HR(hr, S_OK);
3232 ok( len == 4, "len %d\n", len);
3234 /* refcount tests for IEnumVARIANT support */
3235 EXPECT_REF(node_list, 1);
3236 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IEnumVARIANT, (void**)&enum1);
3237 EXPECT_HR(hr, S_OK);
3238 EXPECT_REF(node_list, 1);
3239 EXPECT_REF(enum1, 2);
3241 EXPECT_REF(node_list, 1);
3242 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IEnumVARIANT, (void**)&enum2);
3243 EXPECT_HR(hr, S_OK);
3244 EXPECT_REF(node_list, 1);
3245 ok(enum2 == enum1, "got %p, %p\n", enum2, enum1);
3246 IEnumVARIANT_Release(enum2);
3248 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk1);
3249 EXPECT_HR(hr, S_OK);
3250 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IUnknown, (void**)&unk2);
3251 EXPECT_HR(hr, S_OK);
3252 EXPECT_REF(node_list, 3);
3253 EXPECT_REF(enum1, 2);
3254 ok(unk1 == unk2, "got %p, %p\n", unk1, unk2);
3255 IUnknown_Release(unk1);
3256 IUnknown_Release(unk2);
3258 EXPECT_REF(node_list, 1);
3259 hr = IXMLDOMNodeList__newEnum(node_list, (IUnknown**)&enum2);
3260 EXPECT_HR(hr, S_OK);
3261 EXPECT_REF(node_list, 2);
3262 EXPECT_REF(enum2, 1);
3263 ok(enum2 != enum1, "got %p, %p\n", enum2, enum1);
3265 /* enumerator created with _newEnum() doesn't share IUnknown* with main object */
3266 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk1);
3267 EXPECT_HR(hr, S_OK);
3268 hr = IEnumVARIANT_QueryInterface(enum2, &IID_IUnknown, (void**)&unk2);
3269 EXPECT_HR(hr, S_OK);
3270 EXPECT_REF(node_list, 3);
3271 EXPECT_REF(enum2, 2);
3272 ok(unk1 != unk2, "got %p, %p\n", unk1, unk2);
3273 IUnknown_Release(unk1);
3274 IUnknown_Release(unk2);
3276 hr = IXMLDOMNodeList__newEnum(node_list, (IUnknown**)&enum3);
3277 EXPECT_HR(hr, S_OK);
3278 ok(enum2 != enum3, "got %p, %p\n", enum2, enum3);
3279 IEnumVARIANT_Release(enum3);
3280 IEnumVARIANT_Release(enum2);
3282 /* iteration tests */
3283 hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
3284 EXPECT_HR(hr, S_OK);
3285 hr = IXMLDOMNode_get_nodeName(node, &str);
3286 EXPECT_HR(hr, S_OK);
3287 ok(!lstrcmpW(str, _bstr_("bs")), "got %s\n", wine_dbgstr_w(str));
3288 SysFreeString(str);
3289 IXMLDOMNode_Release(node);
3291 hr = IXMLDOMNodeList_nextNode(node_list, &node);
3292 EXPECT_HR(hr, S_OK);
3293 hr = IXMLDOMNode_get_nodeName(node, &str);
3294 EXPECT_HR(hr, S_OK);
3295 ok(!lstrcmpW(str, _bstr_("bs")), "got %s\n", wine_dbgstr_w(str));
3296 SysFreeString(str);
3297 IXMLDOMNode_Release(node);
3299 V_VT(&v) = VT_EMPTY;
3300 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
3301 EXPECT_HR(hr, S_OK);
3302 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
3303 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
3304 EXPECT_HR(hr, S_OK);
3305 hr = IXMLDOMNode_get_nodeName(node, &str);
3306 EXPECT_HR(hr, S_OK);
3307 ok(!lstrcmpW(str, _bstr_("bs")), "got node name %s\n", wine_dbgstr_w(str));
3308 SysFreeString(str);
3309 IXMLDOMNode_Release(node);
3310 VariantClear(&v);
3312 hr = IXMLDOMNodeList_nextNode(node_list, &node);
3313 EXPECT_HR(hr, S_OK);
3314 hr = IXMLDOMNode_get_nodeName(node, &str);
3315 EXPECT_HR(hr, S_OK);
3316 ok(!lstrcmpW(str, _bstr_("pr")), "got %s\n", wine_dbgstr_w(str));
3317 SysFreeString(str);
3318 IXMLDOMNode_Release(node);
3320 IEnumVARIANT_Release(enum1);
3322 hr = IXMLDOMNodeList_get_item( node_list, 2, &node );
3323 EXPECT_HR(hr, S_OK);
3325 hr = IXMLDOMNode_get_childNodes( node, &node_list2 );
3326 EXPECT_HR(hr, S_OK);
3328 hr = IXMLDOMNodeList_get_length( node_list2, &len );
3329 EXPECT_HR(hr, S_OK);
3330 ok( len == 0, "len %d\n", len);
3332 hr = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
3333 EXPECT_HR(hr, S_FALSE);
3335 IXMLDOMNodeList_Release( node_list2 );
3336 IXMLDOMNode_Release( node );
3337 IXMLDOMNodeList_Release( node_list );
3338 IXMLDOMElement_Release( element );
3340 /* test for children of <?xml ..?> node */
3341 hr = IXMLDOMDocument_get_firstChild(doc, &node);
3342 EXPECT_HR(hr, S_OK);
3344 str = NULL;
3345 hr = IXMLDOMNode_get_nodeName(node, &str);
3346 EXPECT_HR(hr, S_OK);
3347 ok(!lstrcmpW(str, _bstr_("xml")), "got %s\n", wine_dbgstr_w(str));
3348 SysFreeString(str);
3350 /* it returns empty but valid node list */
3351 node_list = (void*)0xdeadbeef;
3352 hr = IXMLDOMNode_get_childNodes(node, &node_list);
3353 EXPECT_HR(hr, S_OK);
3355 len = -1;
3356 hr = IXMLDOMNodeList_get_length(node_list, &len);
3357 EXPECT_HR(hr, S_OK);
3358 ok(len == 0, "got %d\n", len);
3360 IXMLDOMNodeList_Release( node_list );
3361 IXMLDOMNode_Release(node);
3363 IXMLDOMDocument_Release( doc );
3364 free_bstrs();
3367 static void test_get_firstChild(void)
3369 static const WCHAR xmlW[] = {'x','m','l',0};
3370 IXMLDOMDocument *doc;
3371 IXMLDOMNode *node;
3372 VARIANT_BOOL b;
3373 HRESULT r;
3374 BSTR str;
3376 doc = create_document(&IID_IXMLDOMDocument);
3378 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3379 ok( r == S_OK, "loadXML failed\n");
3380 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3382 r = IXMLDOMDocument_get_firstChild( doc, &node );
3383 ok( r == S_OK, "ret %08x\n", r);
3385 r = IXMLDOMNode_get_nodeName( node, &str );
3386 ok( r == S_OK, "ret %08x\n", r);
3388 ok(!lstrcmpW(str, xmlW), "expected \"xml\" node name, got %s\n", wine_dbgstr_w(str));
3390 SysFreeString(str);
3391 IXMLDOMNode_Release( node );
3392 IXMLDOMDocument_Release( doc );
3394 free_bstrs();
3397 static void test_get_lastChild(void)
3399 static const WCHAR lcW[] = {'l','c',0};
3400 static const WCHAR foW[] = {'f','o',0};
3401 IXMLDOMDocument *doc;
3402 IXMLDOMNode *node, *child;
3403 VARIANT_BOOL b;
3404 HRESULT r;
3405 BSTR str;
3407 doc = create_document(&IID_IXMLDOMDocument);
3409 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3410 ok( r == S_OK, "loadXML failed\n");
3411 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3413 r = IXMLDOMDocument_get_lastChild( doc, &node );
3414 ok( r == S_OK, "ret %08x\n", r);
3416 r = IXMLDOMNode_get_nodeName( node, &str );
3417 ok( r == S_OK, "ret %08x\n", r);
3419 ok(memcmp(str, lcW, sizeof(lcW)) == 0, "expected \"lc\" node name\n");
3420 SysFreeString(str);
3422 r = IXMLDOMNode_get_lastChild( node, &child );
3423 ok( r == S_OK, "ret %08x\n", r);
3425 r = IXMLDOMNode_get_nodeName( child, &str );
3426 ok( r == S_OK, "ret %08x\n", r);
3428 ok(memcmp(str, foW, sizeof(foW)) == 0, "expected \"fo\" node name\n");
3429 SysFreeString(str);
3431 IXMLDOMNode_Release( child );
3432 IXMLDOMNode_Release( node );
3433 IXMLDOMDocument_Release( doc );
3435 free_bstrs();
3438 static void test_removeChild(void)
3440 HRESULT r;
3441 VARIANT_BOOL b;
3442 IXMLDOMDocument *doc;
3443 IXMLDOMElement *element, *lc_element;
3444 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
3445 IXMLDOMNodeList *root_list, *fo_list;
3447 doc = create_document(&IID_IXMLDOMDocument);
3449 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3450 ok( r == S_OK, "loadXML failed\n");
3451 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3453 r = IXMLDOMDocument_get_documentElement( doc, &element );
3454 ok( r == S_OK, "ret %08x\n", r);
3455 todo_wine EXPECT_REF(element, 2);
3457 r = IXMLDOMElement_get_childNodes( element, &root_list );
3458 ok( r == S_OK, "ret %08x\n", r);
3459 EXPECT_REF(root_list, 1);
3461 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
3462 ok( r == S_OK, "ret %08x\n", r);
3463 EXPECT_REF(fo_node, 1);
3465 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3466 ok( r == S_OK, "ret %08x\n", r);
3467 EXPECT_REF(fo_list, 1);
3469 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
3470 ok( r == S_OK, "ret %08x\n", r);
3471 EXPECT_REF(ba_node, 1);
3473 /* invalid parameter: NULL ptr */
3474 removed_node = (void*)0xdeadbeef;
3475 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
3476 ok( r == E_INVALIDARG, "ret %08x\n", r );
3477 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3479 /* ba_node is a descendant of element, but not a direct child. */
3480 removed_node = (void*)0xdeadbeef;
3481 EXPECT_REF(ba_node, 1);
3482 EXPECT_CHILDREN(fo_node);
3483 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
3484 ok( r == E_INVALIDARG, "ret %08x\n", r );
3485 ok( removed_node == NULL, "%p\n", removed_node );
3486 EXPECT_REF(ba_node, 1);
3487 EXPECT_CHILDREN(fo_node);
3489 EXPECT_REF(ba_node, 1);
3490 EXPECT_REF(fo_node, 1);
3491 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
3492 ok( r == S_OK, "ret %08x\n", r);
3493 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
3494 EXPECT_REF(fo_node, 2);
3495 EXPECT_REF(ba_node, 1);
3497 /* try removing already removed child */
3498 temp_node = (void*)0xdeadbeef;
3499 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
3500 ok( r == E_INVALIDARG, "ret %08x\n", r);
3501 ok( temp_node == NULL, "%p\n", temp_node );
3502 IXMLDOMNode_Release( fo_node );
3504 /* the removed node has no parent anymore */
3505 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
3506 ok( r == S_FALSE, "ret %08x\n", r);
3507 ok( temp_node == NULL, "%p\n", temp_node );
3509 IXMLDOMNode_Release( removed_node );
3510 IXMLDOMNode_Release( ba_node );
3511 IXMLDOMNodeList_Release( fo_list );
3513 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
3514 ok( r == S_OK, "ret %08x\n", r);
3516 r = IXMLDOMNode_QueryInterface( lc_node, &IID_IXMLDOMElement, (void**)&lc_element );
3517 ok( r == S_OK, "ret %08x\n", r);
3519 /* MS quirk: passing wrong interface pointer works, too */
3520 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
3521 ok( r == S_OK, "ret %08x\n", r);
3522 IXMLDOMElement_Release( lc_element );
3524 temp_node = (void*)0xdeadbeef;
3525 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
3526 ok( r == S_FALSE, "ret %08x\n", r);
3527 ok( temp_node == NULL, "%p\n", temp_node );
3529 IXMLDOMNode_Release( lc_node );
3530 IXMLDOMNodeList_Release( root_list );
3531 IXMLDOMElement_Release( element );
3532 IXMLDOMDocument_Release( doc );
3534 free_bstrs();
3537 static void test_replaceChild(void)
3539 HRESULT r;
3540 VARIANT_BOOL b;
3541 IXMLDOMDocument *doc;
3542 IXMLDOMElement *element, *ba_element;
3543 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
3544 IXMLDOMNodeList *root_list, *fo_list;
3545 IUnknown * unk1, *unk2;
3546 LONG len;
3548 doc = create_document(&IID_IXMLDOMDocument);
3550 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3551 ok( r == S_OK, "loadXML failed\n");
3552 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3554 r = IXMLDOMDocument_get_documentElement( doc, &element );
3555 ok( r == S_OK, "ret %08x\n", r);
3557 r = IXMLDOMElement_get_childNodes( element, &root_list );
3558 ok( r == S_OK, "ret %08x\n", r);
3560 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
3561 ok( r == S_OK, "ret %08x\n", r);
3563 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
3564 ok( r == S_OK, "ret %08x\n", r);
3566 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3567 ok( r == S_OK, "ret %08x\n", r);
3569 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
3570 ok( r == S_OK, "ret %08x\n", r);
3572 IXMLDOMNodeList_Release( fo_list );
3574 /* invalid parameter: NULL ptr for element to remove */
3575 removed_node = (void*)0xdeadbeef;
3576 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
3577 ok( r == E_INVALIDARG, "ret %08x\n", r );
3578 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3580 /* invalid parameter: NULL for replacement element. (Sic!) */
3581 removed_node = (void*)0xdeadbeef;
3582 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
3583 ok( r == E_INVALIDARG, "ret %08x\n", r );
3584 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3586 /* invalid parameter: OldNode is not a child */
3587 removed_node = (void*)0xdeadbeef;
3588 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
3589 ok( r == E_INVALIDARG, "ret %08x\n", r );
3590 ok( removed_node == NULL, "%p\n", removed_node );
3591 IXMLDOMNode_Release( lc_node );
3593 /* invalid parameter: would create loop */
3594 removed_node = (void*)0xdeadbeef;
3595 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
3596 ok( r == E_FAIL, "ret %08x\n", r );
3597 ok( removed_node == NULL, "%p\n", removed_node );
3599 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
3600 ok( r == S_OK, "ret %08x\n", r );
3602 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
3603 ok( r == S_OK, "ret %08x\n", r );
3605 /* ba_node and temp_node refer to the same node, yet they
3606 are different interface pointers */
3607 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
3608 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
3609 ok( r == S_OK, "ret %08x\n", r );
3610 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
3611 ok( r == S_OK, "ret %08x\n", r );
3612 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
3614 IUnknown_Release( unk1 );
3615 IUnknown_Release( unk2 );
3617 /* ba_node should have been removed from below fo_node */
3618 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3619 ok( r == S_OK, "ret %08x\n", r );
3621 /* MS quirk: replaceChild also accepts elements instead of nodes */
3622 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
3623 ok( r == S_OK, "ret %08x\n", r );
3624 EXPECT_REF(ba_element, 2);
3626 removed_node = NULL;
3627 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
3628 ok( r == S_OK, "ret %08x\n", r );
3629 ok( removed_node != NULL, "got %p\n", removed_node);
3630 EXPECT_REF(ba_element, 3);
3631 IXMLDOMElement_Release( ba_element );
3633 r = IXMLDOMNodeList_get_length( fo_list, &len);
3634 ok( r == S_OK, "ret %08x\n", r );
3635 ok( len == 0, "len %d\n", len);
3637 IXMLDOMNodeList_Release( fo_list );
3639 IXMLDOMNode_Release(ba_node);
3640 IXMLDOMNode_Release(fo_node);
3641 IXMLDOMNode_Release(temp_node);
3642 IXMLDOMNodeList_Release( root_list );
3643 IXMLDOMElement_Release( element );
3644 IXMLDOMDocument_Release( doc );
3646 free_bstrs();
3649 static void test_removeNamedItem(void)
3651 IXMLDOMDocument *doc;
3652 IXMLDOMElement *element;
3653 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
3654 IXMLDOMNodeList *root_list;
3655 IXMLDOMNamedNodeMap * pr_attrs;
3656 VARIANT_BOOL b;
3657 BSTR str;
3658 LONG len;
3659 HRESULT r;
3661 doc = create_document(&IID_IXMLDOMDocument);
3663 r = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
3664 ok( r == S_OK, "loadXML failed\n");
3665 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3667 r = IXMLDOMDocument_get_documentElement( doc, &element );
3668 ok( r == S_OK, "ret %08x\n", r);
3670 r = IXMLDOMElement_get_childNodes( element, &root_list );
3671 ok( r == S_OK, "ret %08x\n", r);
3673 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
3674 ok( r == S_OK, "ret %08x\n", r);
3676 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
3677 ok( r == S_OK, "ret %08x\n", r);
3679 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3680 ok( r == S_OK, "ret %08x\n", r);
3681 ok( len == 3, "length %d\n", len);
3683 removed_node = (void*)0xdeadbeef;
3684 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
3685 ok ( r == E_INVALIDARG, "ret %08x\n", r);
3686 ok ( removed_node == (void*)0xdeadbeef, "got %p\n", removed_node);
3688 removed_node = (void*)0xdeadbeef;
3689 str = SysAllocString(szvr);
3690 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
3691 ok ( r == S_OK, "ret %08x\n", r);
3693 removed_node2 = (void*)0xdeadbeef;
3694 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
3695 ok ( r == S_FALSE, "ret %08x\n", r);
3696 ok ( removed_node2 == NULL, "got %p\n", removed_node2 );
3698 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3699 ok( r == S_OK, "ret %08x\n", r);
3700 ok( len == 2, "length %d\n", len);
3702 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
3703 ok ( r == S_OK, "ret %08x\n", r);
3704 IXMLDOMNode_Release(removed_node);
3706 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3707 ok( r == S_OK, "ret %08x\n", r);
3708 ok( len == 3, "length %d\n", len);
3710 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
3711 ok ( r == S_OK, "ret %08x\n", r);
3713 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3714 ok( r == S_OK, "ret %08x\n", r);
3715 ok( len == 2, "length %d\n", len);
3717 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
3718 ok ( r == S_FALSE, "ret %08x\n", r);
3720 SysFreeString(str);
3722 IXMLDOMNamedNodeMap_Release( pr_attrs );
3723 IXMLDOMNode_Release( pr_node );
3724 IXMLDOMNodeList_Release( root_list );
3725 IXMLDOMElement_Release( element );
3726 IXMLDOMDocument_Release( doc );
3728 free_bstrs();
3731 #define test_IObjectSafety_set(p, r, r2, s, m, e, e2) _test_IObjectSafety_set(__LINE__,p, r, r2, s, m, e, e2)
3732 static void _test_IObjectSafety_set(unsigned line, IObjectSafety *safety, HRESULT result,
3733 HRESULT result2, DWORD set, DWORD mask, DWORD expected,
3734 DWORD expected2)
3736 DWORD enabled, supported;
3737 HRESULT hr;
3739 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL, set, mask);
3740 if (result == result2)
3741 ok_(__FILE__,line)(hr == result, "SetInterfaceSafetyOptions: expected %08x, returned %08x\n", result, hr );
3742 else
3743 ok_(__FILE__,line)(broken(hr == result) || hr == result2,
3744 "SetInterfaceSafetyOptions: expected %08x, got %08x\n", result2, hr );
3746 supported = enabled = 0xCAFECAFE;
3747 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3748 ok(hr == S_OK, "ret %08x\n", hr );
3749 if (expected == expected2)
3750 ok_(__FILE__,line)(enabled == expected, "Expected %08x, got %08x\n", expected, enabled);
3751 else
3752 ok_(__FILE__,line)(broken(enabled == expected) || enabled == expected2,
3753 "Expected %08x, got %08x\n", expected2, enabled);
3755 /* reset the safety options */
3757 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
3758 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER,
3760 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3762 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3763 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3764 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
3767 #define test_IObjectSafety_common(s) _test_IObjectSafety_common(__LINE__,s)
3768 static void _test_IObjectSafety_common(unsigned line, IObjectSafety *safety)
3770 DWORD enabled = 0, supported = 0;
3771 HRESULT hr;
3773 /* get */
3774 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, NULL, &enabled);
3775 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
3776 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, NULL);
3777 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
3779 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3780 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3781 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
3782 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
3783 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
3784 "got %08x\n", supported);
3785 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
3787 /* set -- individual flags */
3789 test_IObjectSafety_set(safety, S_OK, S_OK,
3790 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3791 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER);
3793 test_IObjectSafety_set(safety, S_OK, S_OK,
3794 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA,
3795 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
3797 test_IObjectSafety_set(safety, S_OK, S_OK,
3798 INTERFACE_USES_SECURITY_MANAGER, INTERFACE_USES_SECURITY_MANAGER,
3799 0, INTERFACE_USES_SECURITY_MANAGER /* msxml3 SP8+ */);
3801 /* set INTERFACE_USES_DISPEX */
3803 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
3804 INTERFACE_USES_DISPEX, INTERFACE_USES_DISPEX,
3805 0, 0);
3807 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
3808 INTERFACE_USES_DISPEX, 0,
3809 0, 0);
3811 test_IObjectSafety_set(safety, S_OK, S_OK /* msxml3 SP8+ */,
3812 0, INTERFACE_USES_DISPEX,
3813 0, 0);
3815 /* set option masking */
3817 test_IObjectSafety_set(safety, S_OK, S_OK,
3818 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
3819 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3820 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3821 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
3823 test_IObjectSafety_set(safety, S_OK, S_OK,
3824 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
3825 INTERFACESAFE_FOR_UNTRUSTED_DATA,
3826 INTERFACESAFE_FOR_UNTRUSTED_DATA,
3827 INTERFACESAFE_FOR_UNTRUSTED_DATA);
3829 test_IObjectSafety_set(safety, S_OK, S_OK,
3830 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
3831 INTERFACE_USES_SECURITY_MANAGER,
3835 /* set -- inheriting previous settings */
3837 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
3838 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3839 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
3840 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3841 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3842 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3843 ok_(__FILE__,line)(enabled == INTERFACESAFE_FOR_UNTRUSTED_CALLER, "Expected INTERFACESAFE_FOR_UNTRUSTED_CALLER got %08x\n", enabled);
3844 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
3845 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
3846 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
3847 "got %08x\n", supported);
3849 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
3850 INTERFACESAFE_FOR_UNTRUSTED_DATA,
3851 INTERFACESAFE_FOR_UNTRUSTED_DATA);
3852 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3853 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3854 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3855 ok_(__FILE__,line)(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_DATA) ||
3856 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA),
3857 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA) got %08x\n", enabled);
3858 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
3859 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
3860 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
3861 "got %08x\n", supported);
3864 static void test_IXMLDOMDocument2(void)
3866 static const WCHAR emptyW[] = {0};
3867 IXMLDOMDocument2 *doc2, *dtddoc2;
3868 IXMLDOMDocument *doc;
3869 IXMLDOMParseError* err;
3870 IDispatchEx *dispex;
3871 VARIANT_BOOL b;
3872 VARIANT var;
3873 HRESULT r;
3874 LONG res;
3876 if (!is_clsid_supported(&CLSID_DOMDocument2, &IID_IXMLDOMDocument2)) return;
3878 doc = create_document(&IID_IXMLDOMDocument);
3879 dtddoc2 = create_document(&IID_IXMLDOMDocument2);
3881 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
3882 ok( r == S_OK, "ret %08x\n", r );
3883 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
3885 ole_expect(IXMLDOMDocument2_get_readyState(doc2, NULL), E_INVALIDARG);
3886 ole_check(IXMLDOMDocument2_get_readyState(doc2, &res));
3887 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
3889 err = NULL;
3890 ole_expect(IXMLDOMDocument2_validate(doc2, NULL), S_FALSE);
3891 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
3892 ok(err != NULL, "expected a pointer\n");
3893 if (err)
3895 res = 0;
3896 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3897 /* XML_E_NOTWF */
3898 ok(res == E_XML_NOTWF, "got %08x\n", res);
3899 IXMLDOMParseError_Release(err);
3902 r = IXMLDOMDocument2_loadXML( doc2, _bstr_(complete4A), &b );
3903 ok( r == S_OK, "loadXML failed\n");
3904 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3906 ole_check(IXMLDOMDocument_get_readyState(doc, &res));
3907 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
3909 err = NULL;
3910 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
3911 ok(err != NULL, "expected a pointer\n");
3912 if (err)
3914 res = 0;
3915 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3916 /* XML_E_NODTD */
3917 ok(res == E_XML_NODTD, "got %08x\n", res);
3918 IXMLDOMParseError_Release(err);
3921 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
3922 ok( r == S_OK, "ret %08x\n", r );
3923 if(r == S_OK)
3925 IDispatchEx_Release(dispex);
3928 /* we will check if the variant got cleared */
3929 IXMLDOMDocument2_AddRef(doc2);
3930 EXPECT_REF(doc2, 3); /* doc, doc2, AddRef*/
3932 V_VT(&var) = VT_UNKNOWN;
3933 V_UNKNOWN(&var) = (IUnknown *)doc2;
3935 /* invalid calls */
3936 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
3937 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
3938 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
3940 /* valid call */
3941 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3942 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3943 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3944 V_VT(&var) = VT_R4;
3946 /* the variant didn't get cleared*/
3947 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
3949 /* setProperty tests */
3950 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
3951 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
3952 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
3953 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3954 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3955 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3957 V_VT(&var) = VT_BSTR;
3958 V_BSTR(&var) = SysAllocString(emptyW);
3959 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3960 ok(r == S_OK, "got 0x%08x\n", r);
3961 VariantClear(&var);
3963 V_VT(&var) = VT_I2;
3964 V_I2(&var) = 0;
3965 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3966 ok(r == E_FAIL, "got 0x%08x\n", r);
3968 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
3969 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3970 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3971 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3973 IXMLDOMDocument2_Release( doc2 );
3974 IXMLDOMDocument_Release( doc );
3976 /* DTD validation */
3977 ole_check(IXMLDOMDocument2_put_validateOnParse(dtddoc2, VARIANT_FALSE));
3978 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML), &b));
3979 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3980 err = NULL;
3981 ole_check(IXMLDOMDocument2_validate(dtddoc2, &err));
3982 ok(err != NULL, "expected pointer\n");
3983 if (err)
3985 res = 0;
3986 ole_expect(IXMLDOMParseError_get_errorCode(err, &res), S_FALSE);
3987 ok(res == 0, "got %08x\n", res);
3988 IXMLDOMParseError_Release(err);
3991 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0D), &b));
3992 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3993 err = NULL;
3994 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3995 ok(err != NULL, "expected pointer\n");
3996 if (err)
3998 res = 0;
3999 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4000 /* XML_ELEMENT_UNDECLARED */
4001 todo_wine ok(res == 0xC00CE00D, "got %08x\n", res);
4002 IXMLDOMParseError_Release(err);
4005 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0E), &b));
4006 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4007 err = NULL;
4008 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4009 ok(err != NULL, "expected pointer\n");
4010 if (err)
4012 res = 0;
4013 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4014 /* XML_ELEMENT_ID_NOT_FOUND */
4015 todo_wine ok(res == 0xC00CE00E, "got %08x\n", res);
4016 IXMLDOMParseError_Release(err);
4019 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_11), &b));
4020 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4021 err = NULL;
4022 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4023 ok(err != NULL, "expected pointer\n");
4024 if (err)
4026 res = 0;
4027 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4028 /* XML_EMPTY_NOT_ALLOWED */
4029 todo_wine ok(res == 0xC00CE011, "got %08x\n", res);
4030 IXMLDOMParseError_Release(err);
4033 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_13), &b));
4034 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4035 err = NULL;
4036 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4037 ok(err != NULL, "expected pointer\n");
4038 if (err)
4040 res = 0;
4041 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4042 /* XML_ROOT_NAME_MISMATCH */
4043 todo_wine ok(res == 0xC00CE013, "got %08x\n", res);
4044 IXMLDOMParseError_Release(err);
4047 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_14), &b));
4048 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4049 err = NULL;
4050 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4051 ok(err != NULL, "expected pointer\n");
4052 if (err)
4054 res = 0;
4055 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4056 /* XML_INVALID_CONTENT */
4057 todo_wine ok(res == 0xC00CE014, "got %08x\n", res);
4058 IXMLDOMParseError_Release(err);
4061 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_15), &b));
4062 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4063 err = NULL;
4064 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4065 ok(err != NULL, "expected pointer\n");
4066 if (err)
4068 res = 0;
4069 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4070 /* XML_ATTRIBUTE_NOT_DEFINED */
4071 todo_wine ok(res == 0xC00CE015, "got %08x\n", res);
4072 IXMLDOMParseError_Release(err);
4075 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_16), &b));
4076 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4077 err = NULL;
4078 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4079 ok(err != NULL, "expected pointer\n");
4080 if (err)
4082 res = 0;
4083 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4084 /* XML_ATTRIBUTE_FIXED */
4085 todo_wine ok(res == 0xC00CE016, "got %08x\n", res);
4086 IXMLDOMParseError_Release(err);
4089 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_17), &b));
4090 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4091 err = NULL;
4092 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4093 ok(err != NULL, "expected pointer\n");
4094 if (err)
4096 res = 0;
4097 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4098 /* XML_ATTRIBUTE_VALUE */
4099 todo_wine ok(res == 0xC00CE017, "got %08x\n", res);
4100 IXMLDOMParseError_Release(err);
4103 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_18), &b));
4104 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4105 err = NULL;
4106 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4107 ok(err != NULL, "expected pointer\n");
4108 if (err)
4110 res = 0;
4111 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4112 /* XML_ILLEGAL_TEXT */
4113 todo_wine ok(res == 0xC00CE018, "got %08x\n", res);
4114 IXMLDOMParseError_Release(err);
4117 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_20), &b));
4118 ok( b == VARIANT_TRUE, "failed to load XML string\n");
4119 err = NULL;
4120 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
4121 ok(err != NULL, "expected pointer\n");
4122 if (err)
4124 res = 0;
4125 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
4126 /* XML_REQUIRED_ATTRIBUTE_MISSING */
4127 todo_wine ok(res == 0xC00CE020, "got %08x\n", res);
4128 IXMLDOMParseError_Release(err);
4131 IXMLDOMDocument2_Release( dtddoc2 );
4132 free_bstrs();
4135 #define helper_ole_check(expr) { \
4136 HRESULT r = expr; \
4137 ok_(__FILE__, line)(r == S_OK, "=> %i: " #expr " returned %08x\n", __LINE__, r); \
4140 #define helper_expect_list_and_release(list, expstr) { \
4141 char *str = list_to_string(list); \
4142 ok_(__FILE__, line)(strcmp(str, expstr)==0, "=> %i: Invalid node list: %s, expected %s\n", __LINE__, str, expstr); \
4143 if (list) IXMLDOMNodeList_Release(list); \
4146 #define helper_expect_bstr_and_release(bstr, str) { \
4147 ok_(__FILE__, line)(lstrcmpW(bstr, _bstr_(str)) == 0, \
4148 "=> %i: got %s\n", __LINE__, wine_dbgstr_w(bstr)); \
4149 SysFreeString(bstr); \
4152 #define check_ws_ignored(doc, str) _check_ws_ignored(__LINE__, doc, str)
4153 static inline void _check_ws_ignored(int line, IXMLDOMDocument2* doc, char const* str)
4155 IXMLDOMNode *node1, *node2;
4156 IXMLDOMNodeList *list;
4157 BSTR bstr;
4159 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
4160 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
4161 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
4162 helper_ole_check(IXMLDOMNodeList_reset(list));
4163 helper_expect_list_and_release(list, "E1.E5.E1.E2.D1 E2.E5.E1.E2.D1");
4165 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
4166 helper_expect_list_and_release(list, "T1.E1.E5.E1.E2.D1 E2.E1.E5.E1.E2.D1 E3.E1.E5.E1.E2.D1 T4.E1.E5.E1.E2.D1 E5.E1.E5.E1.E2.D1");
4167 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
4168 if (str)
4170 helper_expect_bstr_and_release(bstr, str);
4172 else
4174 helper_expect_bstr_and_release(bstr, "This is a description.");
4176 IXMLDOMNode_Release(node1);
4178 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
4179 helper_expect_list_and_release(list, "T1.E2.E5.E1.E2.D1 E2.E2.E5.E1.E2.D1 T3.E2.E5.E1.E2.D1 E4.E2.E5.E1.E2.D1 T5.E2.E5.E1.E2.D1 E6.E2.E5.E1.E2.D1 T7.E2.E5.E1.E2.D1");
4180 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
4181 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
4182 IXMLDOMNode_Release(node2);
4185 #define check_ws_preserved(doc, str) _check_ws_preserved(__LINE__, doc, str)
4186 static inline void _check_ws_preserved(int line, IXMLDOMDocument2* doc, char const* str)
4188 IXMLDOMNode *node1, *node2;
4189 IXMLDOMNodeList *list;
4190 BSTR bstr;
4192 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
4193 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
4194 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
4195 helper_ole_check(IXMLDOMNodeList_reset(list));
4196 helper_expect_list_and_release(list, "E2.E10.E2.E2.D1 E4.E10.E2.E2.D1");
4198 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
4199 helper_expect_list_and_release(list, "T1.E2.E10.E2.E2.D1 E2.E2.E10.E2.E2.D1 T3.E2.E10.E2.E2.D1 E4.E2.E10.E2.E2.D1 T5.E2.E10.E2.E2.D1 E6.E2.E10.E2.E2.D1 T7.E2.E10.E2.E2.D1");
4200 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
4201 if (str)
4203 helper_expect_bstr_and_release(bstr, str);
4205 else
4207 helper_expect_bstr_and_release(bstr, "\n This is a description. \n ");
4209 IXMLDOMNode_Release(node1);
4211 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
4212 helper_expect_list_and_release(list, "T1.E4.E10.E2.E2.D1 E2.E4.E10.E2.E2.D1 T3.E4.E10.E2.E2.D1 E4.E4.E10.E2.E2.D1 T5.E4.E10.E2.E2.D1 E6.E4.E10.E2.E2.D1 T7.E4.E10.E2.E2.D1");
4213 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
4214 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
4215 IXMLDOMNode_Release(node2);
4218 static void test_preserve_charref(IXMLDOMDocument2 *doc, VARIANT_BOOL preserve)
4220 static const WCHAR b1_p[] = {' ','T','e','x','t',' ','A',' ','e','n','d',' ',0};
4221 static const WCHAR b1_i[] = {'T','e','x','t',' ','A',' ','e','n','d',0};
4222 static const WCHAR b2_p[] = {'A','B',' ','C',' ',0};
4223 static const WCHAR b2_i[] = {'A','B',' ','C',0};
4224 IXMLDOMNodeList *list;
4225 IXMLDOMElement *root;
4226 IXMLDOMNode *node;
4227 const WCHAR *text;
4228 VARIANT_BOOL b;
4229 HRESULT hr;
4230 BSTR s;
4232 hr = IXMLDOMDocument2_put_preserveWhiteSpace(doc, preserve);
4233 ok(hr == S_OK, "got 0x%08x\n", hr);
4235 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(charrefsxml), &b);
4236 ok(hr == S_OK, "got 0x%08x\n", hr);
4238 hr = IXMLDOMDocument2_get_documentElement(doc, &root);
4239 ok(hr == S_OK, "got 0x%08x\n", hr);
4241 hr = IXMLDOMElement_get_childNodes(root, &list);
4242 ok(hr == S_OK, "got 0x%08x\n", hr);
4243 IXMLDOMElement_Release(root);
4245 text = preserve == VARIANT_TRUE ? b1_p : b1_i;
4246 hr = IXMLDOMNodeList_get_item(list, 0, &node);
4247 ok(hr == S_OK, "got 0x%08x\n", hr);
4248 hr = IXMLDOMNode_get_text(node, &s);
4249 ok(hr == S_OK, "got 0x%08x\n", hr);
4250 ok(!lstrcmpW(s, text), "0x%x, got %s\n", preserve, wine_dbgstr_w(s));
4251 SysFreeString(s);
4252 IXMLDOMNode_Release(node);
4254 text = preserve == VARIANT_TRUE ? b2_p : b2_i;
4255 hr = IXMLDOMNodeList_get_item(list, 1, &node);
4256 ok(hr == S_OK, "got 0x%08x\n", hr);
4257 hr = IXMLDOMNode_get_text(node, &s);
4258 ok(hr == S_OK, "got 0x%08x\n", hr);
4259 ok(!lstrcmpW(s, text), "0x%x, got %s\n", preserve, wine_dbgstr_w(s));
4260 SysFreeString(s);
4261 IXMLDOMNode_Release(node);
4263 IXMLDOMNodeList_Release(list);
4266 static void test_whitespace(void)
4268 IXMLDOMDocument2 *doc1, *doc2, *doc3, *doc4;
4269 IXMLDOMNodeList *list;
4270 IXMLDOMElement *root;
4271 VARIANT_BOOL b;
4272 HRESULT hr;
4273 LONG len;
4275 if (!is_clsid_supported(&CLSID_DOMDocument2, &IID_IXMLDOMDocument2)) return;
4276 doc1 = create_document(&IID_IXMLDOMDocument2);
4277 doc2 = create_document(&IID_IXMLDOMDocument2);
4279 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_TRUE));
4280 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
4281 ok(b == VARIANT_FALSE, "expected false\n");
4282 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
4283 ok(b == VARIANT_TRUE, "expected true\n");
4285 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
4286 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4287 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
4288 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4290 /* switch to XPath */
4291 ole_check(IXMLDOMDocument2_setProperty(doc1, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4292 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4294 check_ws_ignored(doc1, NULL);
4295 check_ws_preserved(doc2, NULL);
4297 /* new instances copy the property */
4298 ole_check(IXMLDOMDocument2_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**) &doc3));
4299 ole_check(IXMLDOMDocument2_QueryInterface(doc2, &IID_IXMLDOMDocument2, (void**) &doc4));
4301 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
4302 ok(b == VARIANT_FALSE, "expected false\n");
4303 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
4304 ok(b == VARIANT_TRUE, "expected true\n");
4306 check_ws_ignored(doc3, NULL);
4307 check_ws_preserved(doc4, NULL);
4309 /* setting after loading xml affects trimming of leading/trailing ws only */
4310 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_TRUE));
4311 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_FALSE));
4313 /* the trailing "\n " isn't there, because it was ws-only node */
4314 check_ws_ignored(doc1, "\n This is a description. ");
4315 check_ws_preserved(doc2, "This is a description.");
4317 /* it takes effect on reload */
4318 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
4319 ok(b == VARIANT_TRUE, "expected true\n");
4320 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
4321 ok(b == VARIANT_FALSE, "expected false\n");
4323 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
4324 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4325 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
4326 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4328 check_ws_preserved(doc1, NULL);
4329 check_ws_ignored(doc2, NULL);
4331 /* other instances follow suit */
4332 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
4333 ok(b == VARIANT_TRUE, "expected true\n");
4334 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
4335 ok(b == VARIANT_FALSE, "expected false\n");
4337 check_ws_preserved(doc3, NULL);
4338 check_ws_ignored(doc4, NULL);
4340 IXMLDOMDocument2_Release(doc2);
4341 IXMLDOMDocument2_Release(doc3);
4342 IXMLDOMDocument2_Release(doc4);
4344 /* text with char references */
4345 test_preserve_charref(doc1, VARIANT_TRUE);
4346 test_preserve_charref(doc1, VARIANT_FALSE);
4348 /* formatting whitespaces */
4349 hr = IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_FALSE);
4350 ok(hr == S_OK, "got 0x%08x\n", hr);
4352 hr = IXMLDOMDocument2_loadXML(doc1, _bstr_(complete7), &b);
4353 ok(hr == S_OK, "got 0x%08x\n", hr);
4354 ok(b == VARIANT_TRUE, "for %x\n", b);
4356 hr = IXMLDOMDocument2_get_documentElement(doc1, &root);
4357 ok(hr == S_OK, "got 0x%08x\n", hr);
4358 hr = IXMLDOMElement_get_childNodes(root, &list);
4359 ok(hr == S_OK, "got 0x%08x\n", hr);
4360 len = 0;
4361 hr = IXMLDOMNodeList_get_length(list, &len);
4362 ok(hr == S_OK, "got 0x%08x\n", hr);
4363 ok(len == 3, "got %d\n", len);
4364 IXMLDOMNodeList_Release(list);
4365 IXMLDOMElement_Release(root);
4367 IXMLDOMDocument2_Release(doc1);
4369 free_bstrs();
4372 typedef struct {
4373 const GUID *clsid;
4374 const char *name;
4375 const char *ns;
4376 HRESULT hr;
4377 } selection_ns_t;
4379 /* supposed to be tested with szExampleXML */
4380 static const selection_ns_t selection_ns_data[] = {
4381 { &CLSID_DOMDocument, "CLSID_DOMDocument", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4382 { &CLSID_DOMDocument, "CLSID_DOMDocument", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4383 { &CLSID_DOMDocument, "CLSID_DOMDocument", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4384 { &CLSID_DOMDocument, "CLSID_DOMDocument", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
4386 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4387 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4388 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4389 { &CLSID_DOMDocument2, "CLSID_DOMDocument2", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
4391 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4392 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4393 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4394 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
4396 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4397 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4398 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4399 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
4401 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "\txmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4402 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "\n\rxmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4403 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", " xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'", S_OK },
4404 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' ", S_OK },
4406 { NULL }
4409 typedef struct {
4410 const char *query;
4411 const char *list;
4412 } xpath_test_t;
4414 static const xpath_test_t xpath_test[] = {
4415 { "*/a", "E1.E1.E2.D1 E1.E2.E2.D1 E1.E4.E2.D1" },
4416 { "*/b", "E2.E1.E2.D1 E2.E2.E2.D1 E2.E4.E2.D1" },
4417 { "*/c", "E3.E1.E2.D1 E3.E2.E2.D1" },
4418 { "*/d", "E4.E1.E2.D1 E4.E2.E2.D1 E4.E4.E2.D1" },
4419 { "//a", "E1.E1.E2.D1 E1.E2.E2.D1 E1.E4.E2.D1" },
4420 { "//b", "E2.E1.E2.D1 E2.E2.E2.D1 E2.E4.E2.D1" },
4421 { "//c", "E3.E1.E2.D1 E3.E2.E2.D1" },
4422 { "//d", "E4.E1.E2.D1 E4.E2.E2.D1 E4.E4.E2.D1" },
4423 { "//c[@type]", "E3.E2.E2.D1" },
4424 { "//c[@type]/ancestor::node()[1]", "E2.E2.D1" },
4425 { "//c[@type]/ancestor-or-self::node()[1]", "E3.E2.E2.D1" },
4426 { "//c[@type]/attribute::node()[1]", "A'type'.E3.E2.E2.D1" },
4427 { "//c[@type]/child::node()[1]", "T1.E3.E2.E2.D1" },
4428 { "//c[@type]/descendant::node()[1]", "T1.E3.E2.E2.D1" },
4429 { "//c[@type]/descendant-or-self::node()[1]", "E3.E2.E2.D1" },
4430 { "//c[@type]/following::node()[1]", "E4.E2.E2.D1" },
4431 { "//c[@type]/following-sibling::node()[1]", "E4.E2.E2.D1" },
4432 { "//c[@type]/parent::node()[1]", "E2.E2.D1" },
4433 { "//c[@type]/preceding::node()[1]", "T1.E2.E2.E2.D1" },
4434 { "//c[@type]/self::node()[1]", "E3.E2.E2.D1" },
4435 { "child::*", "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1" },
4436 { "child::node()", "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1" },
4437 { "child::text()", "" },
4438 { "child::*/..", "E2.D1" },
4439 { "child::*//@*/..", "E2.E5.E1.E2.D1 E2.E2.D1 E3.E2.E2.D1" },
4440 { "self::node()", "E2.D1" },
4441 { "ancestor::node()", "D1" },
4442 { "elem[c][last()]/a", "E1.E2.E2.D1"},
4443 { "ancestor-or-self::node()[1]", "E2.D1" },
4444 { "((//a)[1])[last()]", "E1.E1.E2.D1" },
4445 { "//elem[@*]", "E2.E2.D1" },
4446 { NULL }
4449 static void test_XPath(void)
4451 const selection_ns_t *ptr = selection_ns_data;
4452 const xpath_test_t *xptest = xpath_test;
4453 VARIANT var;
4454 VARIANT_BOOL b;
4455 IXMLDOMDocument2 *doc;
4456 IXMLDOMDocument *doc2;
4457 IXMLDOMNode *rootNode;
4458 IXMLDOMNode *elem1Node;
4459 IXMLDOMNode *node;
4460 IXMLDOMNodeList *list;
4461 IXMLDOMElement *elem;
4462 IXMLDOMAttribute *attr;
4463 DOMNodeType type;
4464 HRESULT hr;
4465 LONG len;
4466 BSTR str;
4468 if (!is_clsid_supported(&CLSID_DOMDocument2, &IID_IXMLDOMDocument2)) return;
4469 doc = create_document(&IID_IXMLDOMDocument2);
4471 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
4472 EXPECT_HR(hr, S_OK);
4473 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4475 /* switch to XPath */
4476 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4478 /* some simple queries*/
4479 EXPECT_REF(doc, 1);
4480 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
4481 EXPECT_HR(hr, S_OK);
4482 EXPECT_REF(doc, 1);
4483 EXPECT_LIST_LEN(list, 1);
4485 EXPECT_REF(list, 1);
4486 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
4487 EXPECT_HR(hr, S_OK);
4488 EXPECT_REF(list, 1);
4489 EXPECT_REF(rootNode, 1);
4491 hr = IXMLDOMNodeList_reset(list);
4492 EXPECT_HR(hr, S_OK);
4493 expect_list_and_release(list, "E2.D1");
4495 /* peform xpath tests */
4496 for ( ; xptest->query ; xptest++ )
4498 char *str;
4500 hr = IXMLDOMNode_selectNodes(rootNode, _bstr_(xptest->query), &list);
4501 ok(hr == S_OK, "query evaluation failed for query=%s\n", xptest->query);
4503 if (hr != S_OK)
4504 continue;
4506 str = list_to_string(list);
4508 ok(!strcmp(str, xptest->list), "query=%s, invalid node list: \"%s\", expected \"%s\"\n",
4509 xptest->query, str, xptest->list);
4511 if (list)
4512 IXMLDOMNodeList_Release(list);
4515 if (0)
4517 /* namespace:: axis test is disabled until namespace definitions
4518 are supported as attribute nodes, currently it's another node type */
4519 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("/root/namespace::*"), &list);
4520 EXPECT_HR(hr, S_OK);
4521 len = -1;
4522 hr = IXMLDOMNodeList_get_length(list, &len);
4523 EXPECT_HR(hr, S_OK);
4524 ok(len == 2, "got %d\n", len);
4526 hr = IXMLDOMNodeList_nextNode(list, &node);
4527 EXPECT_HR(hr, S_OK);
4528 type = NODE_INVALID;
4529 hr = IXMLDOMNode_get_nodeType(node, &type);
4530 EXPECT_HR(hr, S_OK);
4531 ok(type == NODE_ATTRIBUTE, "got %d\n", type);
4532 IXMLDOMNode_Release(node);
4534 IXMLDOMNodeList_Release(list);
4537 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//c"), &list));
4538 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
4540 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//c[@type]"), &list));
4541 expect_list_and_release(list, "E3.E2.E2.D1");
4543 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
4544 /* using get_item for query results advances the position */
4545 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
4546 expect_node(node, "E2.E2.D1");
4547 IXMLDOMNode_Release(node);
4548 ole_check(IXMLDOMNodeList_nextNode(list, &node));
4549 expect_node(node, "E4.E2.D1");
4550 IXMLDOMNode_Release(node);
4551 ole_check(IXMLDOMNodeList_reset(list));
4552 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
4554 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
4555 expect_list_and_release(list, "E2.D1");
4557 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
4558 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
4559 ole_check(IXMLDOMNodeList_reset(list));
4560 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
4562 /* select an attribute */
4563 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
4564 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
4566 /* would evaluate to a number */
4567 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
4568 /* would evaluate to a boolean */
4569 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
4570 /* would evaluate to a string */
4571 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
4573 /* no results */
4574 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
4575 expect_list_and_release(list, "");
4576 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("elem//c"), &list));
4577 expect_list_and_release(list, "");
4578 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem[4]"), &list));
4579 expect_list_and_release(list, "");
4580 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
4581 expect_list_and_release(list, "");
4583 /* foo undeclared in document node */
4584 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4585 /* undeclared in <root> node */
4586 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
4587 /* undeclared in <elem> node */
4588 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
4589 /* but this trick can be used */
4590 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
4591 expect_list_and_release(list, "E3.E4.E2.D1");
4593 /* it has to be declared in SelectionNamespaces */
4594 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4595 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
4597 /* now the namespace can be used */
4598 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//test:c"), &list));
4599 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4600 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
4601 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4602 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
4603 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4604 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
4605 expect_list_and_release(list, "E5.E1.E5.E1.E2.D1 E6.E2.E5.E1.E2.D1");
4607 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
4608 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4609 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
4611 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4613 VariantInit(&var);
4614 ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
4615 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
4616 if (V_VT(&var) == VT_BSTR)
4617 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
4619 /* extra attributes - same thing*/
4620 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4621 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
4622 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4624 IXMLDOMNode_Release(rootNode);
4625 IXMLDOMNode_Release(elem1Node);
4627 /* alter document with already built list */
4628 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
4629 EXPECT_HR(hr, S_OK);
4630 EXPECT_LIST_LEN(list, 1);
4632 hr = IXMLDOMDocument2_get_lastChild(doc, &rootNode);
4633 EXPECT_HR(hr, S_OK);
4634 EXPECT_REF(rootNode, 1);
4635 EXPECT_REF(doc, 1);
4637 hr = IXMLDOMDocument2_removeChild(doc, rootNode, NULL);
4638 EXPECT_HR(hr, S_OK);
4639 IXMLDOMNode_Release(rootNode);
4641 EXPECT_LIST_LEN(list, 1);
4643 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
4644 EXPECT_HR(hr, S_OK);
4645 EXPECT_REF(rootNode, 1);
4647 IXMLDOMNodeList_Release(list);
4649 hr = IXMLDOMNode_get_nodeName(rootNode, &str);
4650 EXPECT_HR(hr, S_OK);
4651 ok(!lstrcmpW(str, _bstr_("root")), "got %s\n", wine_dbgstr_w(str));
4652 SysFreeString(str);
4653 IXMLDOMNode_Release(rootNode);
4655 /* alter node from list and get it another time */
4656 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
4657 EXPECT_HR(hr, S_OK);
4658 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4660 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
4661 EXPECT_HR(hr, S_OK);
4662 EXPECT_LIST_LEN(list, 1);
4664 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
4665 EXPECT_HR(hr, S_OK);
4667 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
4668 EXPECT_HR(hr, S_OK);
4670 V_VT(&var) = VT_I2;
4671 V_I2(&var) = 1;
4672 hr = IXMLDOMElement_setAttribute(elem, _bstr_("attrtest"), var);
4673 EXPECT_HR(hr, S_OK);
4674 IXMLDOMElement_Release(elem);
4675 IXMLDOMNode_Release(rootNode);
4677 /* now check attribute to be present */
4678 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
4679 EXPECT_HR(hr, S_OK);
4681 hr = IXMLDOMNode_QueryInterface(rootNode, &IID_IXMLDOMElement, (void**)&elem);
4682 EXPECT_HR(hr, S_OK);
4684 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
4685 EXPECT_HR(hr, S_OK);
4686 IXMLDOMAttribute_Release(attr);
4688 IXMLDOMElement_Release(elem);
4689 IXMLDOMNode_Release(rootNode);
4691 /* and now check for attribute in original document */
4692 hr = IXMLDOMDocument2_get_documentElement(doc, &elem);
4693 EXPECT_HR(hr, S_OK);
4695 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attrtest"), &attr);
4696 EXPECT_HR(hr, S_OK);
4697 IXMLDOMAttribute_Release(attr);
4699 IXMLDOMElement_Release(elem);
4701 /* attach node from list to another document */
4702 doc2 = create_document(&IID_IXMLDOMDocument);
4704 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
4705 EXPECT_HR(hr, S_OK);
4706 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4708 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root"), &list);
4709 EXPECT_HR(hr, S_OK);
4710 EXPECT_LIST_LEN(list, 1);
4712 hr = IXMLDOMNodeList_get_item(list, 0, &rootNode);
4713 EXPECT_HR(hr, S_OK);
4714 EXPECT_REF(rootNode, 1);
4716 hr = IXMLDOMDocument_appendChild(doc2, rootNode, NULL);
4717 EXPECT_HR(hr, S_OK);
4718 EXPECT_REF(rootNode, 1);
4719 EXPECT_REF(doc2, 1);
4720 EXPECT_REF(list, 1);
4722 EXPECT_LIST_LEN(list, 1);
4724 IXMLDOMNode_Release(rootNode);
4725 IXMLDOMNodeList_Release(list);
4726 IXMLDOMDocument_Release(doc2);
4727 IXMLDOMDocument2_Release(doc);
4729 while (ptr->clsid)
4731 if (is_clsid_supported(ptr->clsid, &IID_IXMLDOMDocument2))
4733 hr = CoCreateInstance(ptr->clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
4734 ok(hr == S_OK, "got 0x%08x\n", hr);
4736 else
4738 ptr++;
4739 continue;
4742 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
4743 EXPECT_HR(hr, S_OK);
4744 ok(b == VARIANT_TRUE, "failed to load, %s\n", ptr->name);
4746 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath"));
4747 EXPECT_HR(hr, S_OK);
4749 V_VT(&var) = VT_BSTR;
4750 V_BSTR(&var) = _bstr_(ptr->ns);
4752 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), var);
4753 ok(hr == ptr->hr, "got 0x%08x, for %s, %s\n", hr, ptr->name, ptr->ns);
4755 V_VT(&var) = VT_EMPTY;
4756 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var);
4757 EXPECT_HR(hr, S_OK);
4758 ok(V_VT(&var) == VT_BSTR, "got wrong property type %d\n", V_VT(&var));
4759 ok(!lstrcmpW(V_BSTR(&var), _bstr_(ptr->ns)), "got wrong value %s\n", wine_dbgstr_w(V_BSTR(&var)));
4760 VariantClear(&var);
4762 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("root//test:c"), &list);
4763 EXPECT_HR(hr, S_OK);
4764 if (hr == S_OK)
4765 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4767 IXMLDOMDocument2_Release(doc);
4768 ptr++;
4769 free_bstrs();
4772 free_bstrs();
4775 static void test_cloneNode(void )
4777 IXMLDOMDocument *doc, *doc2;
4778 VARIANT_BOOL b;
4779 IXMLDOMNodeList *pList;
4780 IXMLDOMNamedNodeMap *mapAttr;
4781 LONG length, length1;
4782 LONG attr_cnt, attr_cnt1;
4783 IXMLDOMNode *node, *attr;
4784 IXMLDOMNode *node_clone;
4785 IXMLDOMNode *node_first;
4786 HRESULT hr;
4788 doc = create_document(&IID_IXMLDOMDocument);
4790 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(complete4A), &b));
4791 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4793 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc/pr"), &node);
4794 ok( hr == S_OK, "ret %08x\n", hr );
4795 ok( node != NULL, "node %p\n", node );
4797 /* Check invalid parameter */
4798 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
4799 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
4801 /* All Children */
4802 hr = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
4803 ok( hr == S_OK, "ret %08x\n", hr );
4804 ok( node_clone != NULL, "node %p\n", node );
4806 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
4807 ok( hr == S_OK, "ret %08x\n", hr );
4808 hr = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
4809 ok( hr == S_OK, "ret %08x\n", hr );
4810 IXMLDOMDocument_Release(doc2);
4811 IXMLDOMNode_Release(node_first);
4813 hr = IXMLDOMNode_get_childNodes(node, &pList);
4814 ok( hr == S_OK, "ret %08x\n", hr );
4815 length = 0;
4816 hr = IXMLDOMNodeList_get_length(pList, &length);
4817 ok( hr == S_OK, "ret %08x\n", hr );
4818 ok(length == 1, "got %d\n", length);
4819 IXMLDOMNodeList_Release(pList);
4821 hr = IXMLDOMNode_get_attributes(node, &mapAttr);
4822 ok( hr == S_OK, "ret %08x\n", hr );
4823 attr_cnt = 0;
4824 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt);
4825 ok( hr == S_OK, "ret %08x\n", hr );
4826 ok(attr_cnt == 3, "got %d\n", attr_cnt);
4827 IXMLDOMNamedNodeMap_Release(mapAttr);
4829 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
4830 ok( hr == S_OK, "ret %08x\n", hr );
4831 length1 = 0;
4832 hr = IXMLDOMNodeList_get_length(pList, &length1);
4833 ok(length1 == 1, "got %d\n", length1);
4834 ok( hr == S_OK, "ret %08x\n", hr );
4835 IXMLDOMNodeList_Release(pList);
4837 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
4838 ok( hr == S_OK, "ret %08x\n", hr );
4839 attr_cnt1 = 0;
4840 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
4841 ok( hr == S_OK, "ret %08x\n", hr );
4842 ok(attr_cnt1 == 3, "got %d\n", attr_cnt1);
4843 /* now really get some attributes from cloned element */
4844 attr = NULL;
4845 hr = IXMLDOMNamedNodeMap_getNamedItem(mapAttr, _bstr_("id"), &attr);
4846 ok(hr == S_OK, "ret %08x\n", hr);
4847 IXMLDOMNode_Release(attr);
4848 IXMLDOMNamedNodeMap_Release(mapAttr);
4850 ok(length == length1, "wrong Child count (%d, %d)\n", length, length1);
4851 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
4852 IXMLDOMNode_Release(node_clone);
4854 /* No Children */
4855 hr = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
4856 ok( hr == S_OK, "ret %08x\n", hr );
4857 ok( node_clone != NULL, "node %p\n", node );
4859 hr = IXMLDOMNode_get_firstChild(node_clone, &node_first);
4860 ok(hr == S_FALSE, "ret %08x\n", hr );
4862 hr = IXMLDOMNode_get_childNodes(node_clone, &pList);
4863 ok(hr == S_OK, "ret %08x\n", hr );
4864 hr = IXMLDOMNodeList_get_length(pList, &length1);
4865 ok(hr == S_OK, "ret %08x\n", hr );
4866 ok( length1 == 0, "Length should be 0 (%d)\n", length1);
4867 IXMLDOMNodeList_Release(pList);
4869 hr = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
4870 ok(hr == S_OK, "ret %08x\n", hr );
4871 hr = IXMLDOMNamedNodeMap_get_length(mapAttr, &attr_cnt1);
4872 ok(hr == S_OK, "ret %08x\n", hr );
4873 ok(attr_cnt1 == 3, "Attribute count should be 3 (%d)\n", attr_cnt1);
4874 IXMLDOMNamedNodeMap_Release(mapAttr);
4876 ok(length != length1, "wrong Child count (%d, %d)\n", length, length1);
4877 ok(attr_cnt == attr_cnt1, "wrong Attribute count (%d, %d)\n", attr_cnt, attr_cnt1);
4878 IXMLDOMNode_Release(node_clone);
4880 IXMLDOMNode_Release(node);
4881 IXMLDOMDocument_Release(doc);
4882 free_bstrs();
4885 static void test_xmlTypes(void)
4887 IXMLDOMDocument *doc;
4888 IXMLDOMElement *pRoot;
4889 HRESULT hr;
4890 IXMLDOMComment *pComment;
4891 IXMLDOMElement *pElement;
4892 IXMLDOMAttribute *pAttribute;
4893 IXMLDOMNamedNodeMap *pAttribs;
4894 IXMLDOMCDATASection *pCDataSec;
4895 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
4896 IXMLDOMDocumentFragment *pDocFrag = NULL;
4897 IXMLDOMEntityReference *pEntityRef = NULL;
4898 BSTR str;
4899 IXMLDOMNode *pNextChild;
4900 VARIANT v;
4901 LONG len = 0;
4903 doc = create_document(&IID_IXMLDOMDocument);
4905 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
4906 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4908 pNextChild = (void*)0xdeadbeef;
4909 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
4910 ok(hr == S_FALSE, "ret %08x\n", hr );
4911 ok(pNextChild == NULL, "pDocChild not NULL\n");
4913 /* test previous Sibling */
4914 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
4915 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4917 pNextChild = (void*)0xdeadbeef;
4918 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
4919 ok(hr == S_FALSE, "ret %08x\n", hr );
4920 ok(pNextChild == NULL, "pNextChild not NULL\n");
4922 /* test get_dataType */
4923 V_VT(&v) = VT_EMPTY;
4924 hr = IXMLDOMDocument_get_dataType(doc, &v);
4925 ok(hr == S_FALSE, "ret %08x\n", hr );
4926 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4927 VariantClear(&v);
4929 /* test implementation */
4930 hr = IXMLDOMDocument_get_implementation(doc, NULL);
4931 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4933 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
4934 ok(hr == S_OK, "ret %08x\n", hr );
4935 if(hr == S_OK)
4937 VARIANT_BOOL hasFeature = VARIANT_TRUE;
4938 BSTR sEmpty = SysAllocStringLen(NULL, 0);
4940 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
4941 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4943 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
4944 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4946 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
4947 ok(hr == S_OK, "ret %08x\n", hr );
4948 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4950 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
4951 ok(hr == S_OK, "ret %08x\n", hr );
4952 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
4954 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
4955 ok(hr == S_OK, "ret %08x\n", hr );
4956 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
4958 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
4959 ok(hr == S_OK, "ret %08x\n", hr );
4960 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4962 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
4963 ok(hr == S_OK, "ret %08x\n", hr );
4964 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4966 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
4967 ok(hr == S_OK, "ret %08x\n", hr );
4968 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4970 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
4971 ok(hr == S_OK, "ret %08x\n", hr );
4972 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4974 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
4975 ok(hr == S_OK, "ret %08x\n", hr );
4976 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4978 SysFreeString(sEmpty);
4979 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
4982 pRoot = (IXMLDOMElement*)0x1;
4983 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
4984 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4985 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
4987 pRoot = (IXMLDOMElement*)0x1;
4988 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
4989 ok(hr == E_FAIL, "ret %08x\n", hr );
4990 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
4992 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
4993 ok(hr == S_OK, "ret %08x\n", hr );
4994 if(hr == S_OK)
4996 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
4997 ok(hr == S_OK, "ret %08x\n", hr );
4998 if(hr == S_OK)
5000 /* Comment */
5001 str = SysAllocString(szComment);
5002 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
5003 SysFreeString(str);
5004 ok(hr == S_OK, "ret %08x\n", hr );
5005 if(hr == S_OK)
5007 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
5008 ok(hr == S_OK, "ret %08x\n", hr );
5010 hr = IXMLDOMComment_get_nodeName(pComment, &str);
5011 ok(hr == S_OK, "ret %08x\n", hr );
5012 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
5013 SysFreeString(str);
5015 hr = IXMLDOMComment_get_xml(pComment, &str);
5016 ok(hr == S_OK, "ret %08x\n", hr );
5017 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
5018 SysFreeString(str);
5020 /* put data Tests */
5021 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
5022 ok(hr == S_OK, "ret %08x\n", hr );
5024 /* get data Tests */
5025 hr = IXMLDOMComment_get_data(pComment, &str);
5026 ok(hr == S_OK, "ret %08x\n", hr );
5027 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
5028 SysFreeString(str);
5030 /* Confirm XML text is good */
5031 hr = IXMLDOMComment_get_xml(pComment, &str);
5032 ok(hr == S_OK, "ret %08x\n", hr );
5033 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
5034 SysFreeString(str);
5036 /* Confirm we get the put_data Text back */
5037 hr = IXMLDOMComment_get_text(pComment, &str);
5038 ok(hr == S_OK, "ret %08x\n", hr );
5039 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
5040 SysFreeString(str);
5042 /* test length property */
5043 hr = IXMLDOMComment_get_length(pComment, &len);
5044 ok(hr == S_OK, "ret %08x\n", hr );
5045 ok(len == 21, "expected 21 got %d\n", len);
5047 /* test substringData */
5048 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
5049 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5051 /* test substringData - Invalid offset */
5052 str = (BSTR)&szElement;
5053 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
5054 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5055 ok( str == NULL, "incorrect string\n");
5057 /* test substringData - Invalid offset */
5058 str = (BSTR)&szElement;
5059 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
5060 ok(hr == S_FALSE, "ret %08x\n", hr );
5061 ok( str == NULL, "incorrect string\n");
5063 /* test substringData - Invalid size */
5064 str = (BSTR)&szElement;
5065 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
5066 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5067 ok( str == NULL, "incorrect string\n");
5069 /* test substringData - Invalid size */
5070 str = (BSTR)&szElement;
5071 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
5072 ok(hr == S_FALSE, "ret %08x\n", hr );
5073 ok( str == NULL, "incorrect string\n");
5075 /* test substringData - Start of string */
5076 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
5077 ok(hr == S_OK, "ret %08x\n", hr );
5078 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
5079 SysFreeString(str);
5081 /* test substringData - Middle of string */
5082 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
5083 ok(hr == S_OK, "ret %08x\n", hr );
5084 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
5085 SysFreeString(str);
5087 /* test substringData - End of string */
5088 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
5089 ok(hr == S_OK, "ret %08x\n", hr );
5090 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
5091 SysFreeString(str);
5093 /* test appendData */
5094 hr = IXMLDOMComment_appendData(pComment, NULL);
5095 ok(hr == S_OK, "ret %08x\n", hr );
5097 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
5098 ok(hr == S_OK, "ret %08x\n", hr );
5100 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
5101 ok(hr == S_OK, "ret %08x\n", hr );
5103 hr = IXMLDOMComment_get_text(pComment, &str);
5104 ok(hr == S_OK, "ret %08x\n", hr );
5105 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5106 SysFreeString(str);
5108 /* test insertData */
5109 str = SysAllocStringLen(NULL, 0);
5110 hr = IXMLDOMComment_insertData(pComment, -1, str);
5111 ok(hr == S_OK, "ret %08x\n", hr );
5113 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
5114 ok(hr == S_OK, "ret %08x\n", hr );
5116 hr = IXMLDOMComment_insertData(pComment, 1000, str);
5117 ok(hr == S_OK, "ret %08x\n", hr );
5119 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
5120 ok(hr == S_OK, "ret %08x\n", hr );
5122 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
5123 ok(hr == S_OK, "ret %08x\n", hr );
5125 hr = IXMLDOMComment_insertData(pComment, 0, str);
5126 ok(hr == S_OK, "ret %08x\n", hr );
5127 SysFreeString(str);
5129 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
5130 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5132 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
5133 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5135 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
5136 ok(hr == S_OK, "ret %08x\n", hr );
5138 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
5139 ok(hr == S_OK, "ret %08x\n", hr );
5141 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
5142 ok(hr == S_OK, "ret %08x\n", hr );
5144 hr = IXMLDOMComment_get_text(pComment, &str);
5145 ok(hr == S_OK, "ret %08x\n", hr );
5146 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5147 SysFreeString(str);
5149 /* delete data */
5150 /* invalid arguments */
5151 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
5152 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5154 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
5155 ok(hr == S_OK, "ret %08x\n", hr );
5157 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
5158 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5160 hr = IXMLDOMComment_get_length(pComment, &len);
5161 ok(hr == S_OK, "ret %08x\n", hr );
5162 ok(len == 43, "expected 43 got %d\n", len);
5164 hr = IXMLDOMComment_deleteData(pComment, len, 1);
5165 ok(hr == S_OK, "ret %08x\n", hr );
5167 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
5168 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5170 /* delete from start */
5171 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
5172 ok(hr == S_OK, "ret %08x\n", hr );
5174 hr = IXMLDOMComment_get_length(pComment, &len);
5175 ok(hr == S_OK, "ret %08x\n", hr );
5176 ok(len == 38, "expected 38 got %d\n", len);
5178 hr = IXMLDOMComment_get_text(pComment, &str);
5179 ok(hr == S_OK, "ret %08x\n", hr );
5180 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5181 SysFreeString(str);
5183 /* delete from end */
5184 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
5185 ok(hr == S_OK, "ret %08x\n", hr );
5187 hr = IXMLDOMComment_get_length(pComment, &len);
5188 ok(hr == S_OK, "ret %08x\n", hr );
5189 ok(len == 35, "expected 35 got %d\n", len);
5191 hr = IXMLDOMComment_get_text(pComment, &str);
5192 ok(hr == S_OK, "ret %08x\n", hr );
5193 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5194 SysFreeString(str);
5196 /* delete from inside */
5197 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
5198 ok(hr == S_OK, "ret %08x\n", hr );
5200 hr = IXMLDOMComment_get_length(pComment, &len);
5201 ok(hr == S_OK, "ret %08x\n", hr );
5202 ok(len == 2, "expected 2 got %d\n", len);
5204 hr = IXMLDOMComment_get_text(pComment, &str);
5205 ok(hr == S_OK, "ret %08x\n", hr );
5206 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5207 SysFreeString(str);
5209 /* delete whole data ... */
5210 hr = IXMLDOMComment_get_length(pComment, &len);
5211 ok(hr == S_OK, "ret %08x\n", hr );
5213 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5214 ok(hr == S_OK, "ret %08x\n", hr );
5215 /* ... and try again with empty string */
5216 hr = IXMLDOMComment_deleteData(pComment, 0, len);
5217 ok(hr == S_OK, "ret %08x\n", hr );
5219 /* ::replaceData() */
5220 V_VT(&v) = VT_BSTR;
5221 V_BSTR(&v) = SysAllocString(szstr1);
5222 hr = IXMLDOMComment_put_nodeValue(pComment, v);
5223 ok(hr == S_OK, "ret %08x\n", hr );
5224 VariantClear(&v);
5226 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
5227 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5228 hr = IXMLDOMComment_get_text(pComment, &str);
5229 ok(hr == S_OK, "ret %08x\n", hr );
5230 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5231 SysFreeString(str);
5233 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
5234 ok(hr == S_OK, "ret %08x\n", hr );
5235 hr = IXMLDOMComment_get_text(pComment, &str);
5236 ok(hr == S_OK, "ret %08x\n", hr );
5237 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5238 SysFreeString(str);
5240 /* NULL pointer means delete */
5241 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
5242 ok(hr == S_OK, "ret %08x\n", hr );
5243 hr = IXMLDOMComment_get_text(pComment, &str);
5244 ok(hr == S_OK, "ret %08x\n", hr );
5245 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5246 SysFreeString(str);
5248 /* empty string means delete */
5249 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
5250 ok(hr == S_OK, "ret %08x\n", hr );
5251 hr = IXMLDOMComment_get_text(pComment, &str);
5252 ok(hr == S_OK, "ret %08x\n", hr );
5253 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5254 SysFreeString(str);
5256 /* zero count means insert */
5257 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
5258 ok(hr == S_OK, "ret %08x\n", hr );
5259 hr = IXMLDOMComment_get_text(pComment, &str);
5260 ok(hr == S_OK, "ret %08x\n", hr );
5261 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5262 SysFreeString(str);
5264 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
5265 ok(hr == S_OK, "ret %08x\n", hr );
5267 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
5268 ok(hr == S_OK, "ret %08x\n", hr );
5269 hr = IXMLDOMComment_get_text(pComment, &str);
5270 ok(hr == S_OK, "ret %08x\n", hr );
5271 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5272 SysFreeString(str);
5274 /* nonempty string, count greater than its length */
5275 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
5276 ok(hr == S_OK, "ret %08x\n", hr );
5277 hr = IXMLDOMComment_get_text(pComment, &str);
5278 ok(hr == S_OK, "ret %08x\n", hr );
5279 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5280 SysFreeString(str);
5282 /* nonempty string, count less than its length */
5283 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
5284 ok(hr == S_OK, "ret %08x\n", hr );
5285 hr = IXMLDOMComment_get_text(pComment, &str);
5286 ok(hr == S_OK, "ret %08x\n", hr );
5287 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5288 SysFreeString(str);
5290 IXMLDOMComment_Release(pComment);
5293 /* Element */
5294 str = SysAllocString(szElement);
5295 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
5296 SysFreeString(str);
5297 ok(hr == S_OK, "ret %08x\n", hr );
5298 if(hr == S_OK)
5300 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5301 ok(hr == S_OK, "ret %08x\n", hr );
5303 hr = IXMLDOMElement_get_nodeName(pElement, &str);
5304 ok(hr == S_OK, "ret %08x\n", hr );
5305 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
5306 SysFreeString(str);
5308 hr = IXMLDOMElement_get_xml(pElement, &str);
5309 ok(hr == S_OK, "ret %08x\n", hr );
5310 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
5311 SysFreeString(str);
5313 /* Attribute */
5314 pAttribute = (IXMLDOMAttribute*)0x1;
5315 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
5316 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5317 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
5319 pAttribute = (IXMLDOMAttribute*)0x1;
5320 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
5321 ok(hr == E_FAIL, "ret %08x\n", hr );
5322 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
5324 str = SysAllocString(szAttribute);
5325 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
5326 SysFreeString(str);
5327 ok(hr == S_OK, "ret %08x\n", hr );
5328 if(hr == S_OK)
5330 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
5332 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
5333 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5335 pNextChild = (IXMLDOMNode *)0x1;
5336 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
5337 ok(hr == S_FALSE, "ret %08x\n", hr );
5338 ok(pNextChild == NULL, "pNextChild not NULL\n");
5340 /* test Previous Sibling*/
5341 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
5342 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5344 pNextChild = (IXMLDOMNode *)0x1;
5345 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
5346 ok(hr == S_FALSE, "ret %08x\n", hr );
5347 ok(pNextChild == NULL, "pNextChild not NULL\n");
5349 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
5350 ok(hr == E_FAIL, "ret %08x\n", hr );
5351 ok(pNewChild == NULL, "pNewChild not NULL\n");
5353 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
5354 ok(hr == S_OK, "ret %08x\n", hr );
5355 if ( hr == S_OK )
5357 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
5358 ok(hr == S_OK, "ret %08x\n", hr );
5360 IXMLDOMNamedNodeMap_Release(pAttribs);
5363 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
5364 ok(hr == S_OK, "ret %08x\n", hr );
5365 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
5366 SysFreeString(str);
5368 /* test nodeName */
5369 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
5370 ok(hr == S_OK, "ret %08x\n", hr );
5371 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
5372 SysFreeString(str);
5374 /* test name property */
5375 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
5376 ok(hr == S_OK, "ret %08x\n", hr );
5377 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
5378 SysFreeString(str);
5380 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
5381 ok(hr == S_OK, "ret %08x\n", hr );
5382 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
5383 SysFreeString(str);
5385 IXMLDOMAttribute_Release(pAttribute);
5387 /* Check Element again with the Add Attribute*/
5388 hr = IXMLDOMElement_get_xml(pElement, &str);
5389 ok(hr == S_OK, "ret %08x\n", hr );
5390 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
5391 SysFreeString(str);
5394 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
5395 ok(hr == S_OK, "ret %08x\n", hr );
5397 hr = IXMLDOMElement_get_xml(pElement, &str);
5398 ok(hr == S_OK, "ret %08x\n", hr );
5399 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
5400 SysFreeString(str);
5402 /* Test for reversible escaping */
5403 str = SysAllocString( szStrangeChars );
5404 hr = IXMLDOMElement_put_text(pElement, str);
5405 ok(hr == S_OK, "ret %08x\n", hr );
5406 SysFreeString( str );
5408 hr = IXMLDOMElement_get_xml(pElement, &str);
5409 ok(hr == S_OK, "ret %08x\n", hr );
5410 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
5411 SysFreeString(str);
5413 hr = IXMLDOMElement_get_text(pElement, &str);
5414 ok(hr == S_OK, "ret %08x\n", hr );
5415 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
5416 SysFreeString(str);
5418 IXMLDOMElement_Release(pElement);
5421 /* CData Section */
5422 str = SysAllocString(szCData);
5423 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
5424 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5426 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
5427 SysFreeString(str);
5428 ok(hr == S_OK, "ret %08x\n", hr );
5429 if(hr == S_OK)
5431 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
5432 VARIANT var;
5434 VariantInit(&var);
5436 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
5437 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
5439 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
5440 ok(hr == S_OK, "ret %08x\n", hr );
5442 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
5443 ok(hr == S_OK, "ret %08x\n", hr );
5444 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
5445 SysFreeString(str);
5447 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
5448 ok(hr == S_OK, "ret %08x\n", hr );
5449 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
5450 SysFreeString(str);
5452 /* test lastChild */
5453 pNextChild = (IXMLDOMNode*)0x1;
5454 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
5455 ok(hr == S_FALSE, "ret %08x\n", hr );
5456 ok(pNextChild == NULL, "pNextChild not NULL\n");
5458 /* put data Tests */
5459 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
5460 ok(hr == S_OK, "ret %08x\n", hr );
5462 /* Confirm XML text is good */
5463 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
5464 ok(hr == S_OK, "ret %08x\n", hr );
5465 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
5466 SysFreeString(str);
5468 /* Confirm we get the put_data Text back */
5469 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5470 ok(hr == S_OK, "ret %08x\n", hr );
5471 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5472 SysFreeString(str);
5474 /* test length property */
5475 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5476 ok(hr == S_OK, "ret %08x\n", hr );
5477 ok(len == 21, "expected 21 got %d\n", len);
5479 /* test get data */
5480 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
5481 ok(hr == S_OK, "ret %08x\n", hr );
5482 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5483 SysFreeString(str);
5485 /* test substringData */
5486 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
5487 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5489 /* test substringData - Invalid offset */
5490 str = (BSTR)&szElement;
5491 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
5492 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5493 ok( str == NULL, "incorrect string\n");
5495 /* test substringData - Invalid offset */
5496 str = (BSTR)&szElement;
5497 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
5498 ok(hr == S_FALSE, "ret %08x\n", hr );
5499 ok( str == NULL, "incorrect string\n");
5501 /* test substringData - Invalid size */
5502 str = (BSTR)&szElement;
5503 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
5504 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5505 ok( str == NULL, "incorrect string\n");
5507 /* test substringData - Invalid size */
5508 str = (BSTR)&szElement;
5509 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
5510 ok(hr == S_FALSE, "ret %08x\n", hr );
5511 ok( str == NULL, "incorrect string\n");
5513 /* test substringData - Start of string */
5514 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
5515 ok(hr == S_OK, "ret %08x\n", hr );
5516 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
5517 SysFreeString(str);
5519 /* test substringData - Middle of string */
5520 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
5521 ok(hr == S_OK, "ret %08x\n", hr );
5522 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
5523 SysFreeString(str);
5525 /* test substringData - End of string */
5526 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
5527 ok(hr == S_OK, "ret %08x\n", hr );
5528 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
5529 SysFreeString(str);
5531 /* test appendData */
5532 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
5533 ok(hr == S_OK, "ret %08x\n", hr );
5535 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
5536 ok(hr == S_OK, "ret %08x\n", hr );
5538 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
5539 ok(hr == S_OK, "ret %08x\n", hr );
5541 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5542 ok(hr == S_OK, "ret %08x\n", hr );
5543 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5544 SysFreeString(str);
5546 /* test insertData */
5547 str = SysAllocStringLen(NULL, 0);
5548 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
5549 ok(hr == S_OK, "ret %08x\n", hr );
5551 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
5552 ok(hr == S_OK, "ret %08x\n", hr );
5554 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
5555 ok(hr == S_OK, "ret %08x\n", hr );
5557 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
5558 ok(hr == S_OK, "ret %08x\n", hr );
5560 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
5561 ok(hr == S_OK, "ret %08x\n", hr );
5563 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
5564 ok(hr == S_OK, "ret %08x\n", hr );
5565 SysFreeString(str);
5567 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
5568 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5570 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
5571 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5573 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
5574 ok(hr == S_OK, "ret %08x\n", hr );
5576 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
5577 ok(hr == S_OK, "ret %08x\n", hr );
5579 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
5580 ok(hr == S_OK, "ret %08x\n", hr );
5582 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5583 ok(hr == S_OK, "ret %08x\n", hr );
5584 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5585 SysFreeString(str);
5587 /* delete data */
5588 /* invalid arguments */
5589 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
5590 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5592 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
5593 ok(hr == S_OK, "ret %08x\n", hr );
5595 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
5596 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5598 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5599 ok(hr == S_OK, "ret %08x\n", hr );
5600 ok(len == 43, "expected 43 got %d\n", len);
5602 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
5603 ok(hr == S_OK, "ret %08x\n", hr );
5605 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
5606 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5608 /* delete from start */
5609 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
5610 ok(hr == S_OK, "ret %08x\n", hr );
5612 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5613 ok(hr == S_OK, "ret %08x\n", hr );
5614 ok(len == 38, "expected 38 got %d\n", len);
5616 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5617 ok(hr == S_OK, "ret %08x\n", hr );
5618 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5619 SysFreeString(str);
5621 /* delete from end */
5622 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
5623 ok(hr == S_OK, "ret %08x\n", hr );
5625 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5626 ok(hr == S_OK, "ret %08x\n", hr );
5627 ok(len == 35, "expected 35 got %d\n", len);
5629 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5630 ok(hr == S_OK, "ret %08x\n", hr );
5631 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5632 SysFreeString(str);
5634 /* delete from inside */
5635 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
5636 ok(hr == S_OK, "ret %08x\n", hr );
5638 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5639 ok(hr == S_OK, "ret %08x\n", hr );
5640 ok(len == 2, "expected 2 got %d\n", len);
5642 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5643 ok(hr == S_OK, "ret %08x\n", hr );
5644 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5645 SysFreeString(str);
5647 /* delete whole data ... */
5648 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5649 ok(hr == S_OK, "ret %08x\n", hr );
5651 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
5652 ok(hr == S_OK, "ret %08x\n", hr );
5654 /* ... and try again with empty string */
5655 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
5656 ok(hr == S_OK, "ret %08x\n", hr );
5658 /* ::replaceData() */
5659 V_VT(&v) = VT_BSTR;
5660 V_BSTR(&v) = SysAllocString(szstr1);
5661 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
5662 ok(hr == S_OK, "ret %08x\n", hr );
5663 VariantClear(&v);
5665 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
5666 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5667 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5668 ok(hr == S_OK, "ret %08x\n", hr );
5669 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5670 SysFreeString(str);
5672 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
5673 ok(hr == S_OK, "ret %08x\n", hr );
5674 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5675 ok(hr == S_OK, "ret %08x\n", hr );
5676 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5677 SysFreeString(str);
5679 /* NULL pointer means delete */
5680 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
5681 ok(hr == S_OK, "ret %08x\n", hr );
5682 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5683 ok(hr == S_OK, "ret %08x\n", hr );
5684 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5685 SysFreeString(str);
5687 /* empty string means delete */
5688 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
5689 ok(hr == S_OK, "ret %08x\n", hr );
5690 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5691 ok(hr == S_OK, "ret %08x\n", hr );
5692 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5693 SysFreeString(str);
5695 /* zero count means insert */
5696 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
5697 ok(hr == S_OK, "ret %08x\n", hr );
5698 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5699 ok(hr == S_OK, "ret %08x\n", hr );
5700 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5701 SysFreeString(str);
5703 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
5704 ok(hr == S_OK, "ret %08x\n", hr );
5706 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
5707 ok(hr == S_OK, "ret %08x\n", hr );
5708 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5709 ok(hr == S_OK, "ret %08x\n", hr );
5710 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5711 SysFreeString(str);
5713 /* nonempty string, count greater than its length */
5714 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
5715 ok(hr == S_OK, "ret %08x\n", hr );
5716 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5717 ok(hr == S_OK, "ret %08x\n", hr );
5718 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5719 SysFreeString(str);
5721 /* nonempty string, count less than its length */
5722 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
5723 ok(hr == S_OK, "ret %08x\n", hr );
5724 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5725 ok(hr == S_OK, "ret %08x\n", hr );
5726 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5727 SysFreeString(str);
5729 IXMLDOMCDATASection_Release(pCDataSec);
5732 /* Document Fragments */
5733 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
5734 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5736 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
5737 ok(hr == S_OK, "ret %08x\n", hr );
5738 if(hr == S_OK)
5740 IXMLDOMNode *node;
5742 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
5743 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5745 node = (IXMLDOMNode *)0x1;
5746 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
5747 ok(hr == S_FALSE, "ret %08x\n", hr );
5748 ok(node == NULL, "expected NULL, got %p\n", node);
5750 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
5751 ok(hr == S_OK, "ret %08x\n", hr );
5753 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
5754 ok(hr == S_OK, "ret %08x\n", hr );
5755 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
5756 SysFreeString(str);
5758 /* test next Sibling*/
5759 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
5760 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5762 node = (IXMLDOMNode *)0x1;
5763 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
5764 ok(hr == S_FALSE, "ret %08x\n", hr );
5765 ok(node == NULL, "next sibling not NULL\n");
5767 /* test Previous Sibling*/
5768 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
5769 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5771 node = (IXMLDOMNode *)0x1;
5772 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
5773 ok(hr == S_FALSE, "ret %08x\n", hr );
5774 ok(node == NULL, "previous sibling not NULL\n");
5776 IXMLDOMDocumentFragment_Release(pDocFrag);
5779 /* Entity References */
5780 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
5781 ok(hr == E_FAIL, "ret %08x\n", hr );
5782 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
5783 ok(hr == E_FAIL, "ret %08x\n", hr );
5785 str = SysAllocString(szEntityRef);
5786 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
5787 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5789 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
5790 SysFreeString(str);
5791 ok(hr == S_OK, "ret %08x\n", hr );
5792 if(hr == S_OK)
5794 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
5795 ok(hr == S_OK, "ret %08x\n", hr );
5797 /* test get_xml*/
5798 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
5799 ok(hr == S_OK, "ret %08x\n", hr );
5800 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
5801 SysFreeString(str);
5803 IXMLDOMEntityReference_Release(pEntityRef);
5806 IXMLDOMElement_Release( pRoot );
5810 IXMLDOMDocument_Release(doc);
5812 free_bstrs();
5815 typedef struct {
5816 const char *name;
5817 const char *type;
5818 HRESULT hr;
5819 } put_datatype_t;
5821 /* Type test for elements only. Name passed into put_dataType is case-insensitive.
5822 So many of the names have been changed to reflect this. */
5823 static put_datatype_t put_datatype_data[] = {
5824 { "test_inval", "abcdefg", E_FAIL },
5825 { "test_bool", "Boolean", S_OK },
5826 { "test_string", "String", S_OK },
5827 { "test_number", "number", S_OK },
5828 { "test_int", "InT", S_OK },
5829 { "test_fixed", "fixed.14.4", S_OK },
5830 { "test_datetime", "DateTime", S_OK },
5831 { "test_datetimetz", "DateTime.tz", S_OK },
5832 { "test_date", "Date", S_OK },
5833 { "test_time", "Time", S_OK },
5834 { "test_timetz", "Time.tz", S_OK },
5835 { "test_I1", "I1", S_OK },
5836 { "test_I2", "I2", S_OK },
5837 { "test_I4", "I4", S_OK },
5838 { "test_UI1", "UI1", S_OK },
5839 { "test_UI2", "UI2", S_OK },
5840 { "test_UI4", "UI4", S_OK },
5841 { "test_r4", "r4", S_OK },
5842 { "test_r8", "r8", S_OK },
5843 { "test_float", "float", S_OK },
5844 { "test_uuid", "UuId", S_OK },
5845 { "test_binhex", "bin.hex", S_OK },
5846 { "test_binbase64", "bin.base64", S_OK },
5847 { NULL }
5850 typedef struct {
5851 DOMNodeType type;
5852 HRESULT hr;
5853 } put_datatype_notype_t;
5855 static put_datatype_notype_t put_dt_notype[] = {
5856 { NODE_PROCESSING_INSTRUCTION, E_FAIL },
5857 { NODE_DOCUMENT_FRAGMENT, E_FAIL },
5858 { NODE_ENTITY_REFERENCE, E_FAIL },
5859 { NODE_CDATA_SECTION, E_FAIL },
5860 { NODE_COMMENT, E_FAIL },
5861 { NODE_INVALID }
5864 static void test_put_dataType( void )
5866 const put_datatype_notype_t *ptr2 = put_dt_notype;
5867 const put_datatype_t *ptr = put_datatype_data;
5868 IXMLDOMElement *root, *element;
5869 BSTR nameW, type1W, type2W;
5870 IXMLDOMDocument *doc;
5871 HRESULT hr;
5873 doc = create_document(&IID_IXMLDOMDocument);
5875 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
5876 EXPECT_HR(hr, E_INVALIDARG);
5878 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
5879 EXPECT_HR(hr, S_OK);
5881 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
5882 EXPECT_HR(hr, S_OK);
5884 hr = IXMLDOMElement_put_dataType(root, NULL);
5885 EXPECT_HR(hr, E_INVALIDARG);
5887 while (ptr->name)
5889 hr = IXMLDOMDocument_createElement(doc, _bstr_(ptr->name), &element);
5890 EXPECT_HR(hr, S_OK);
5891 if(hr == S_OK)
5893 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)element, NULL);
5894 EXPECT_HR(hr, S_OK);
5896 hr = IXMLDOMElement_put_dataType(element, _bstr_(ptr->type));
5897 ok(hr == ptr->hr, "failed for %s:%s, 0x%08x\n", ptr->name, ptr->type, ptr->hr);
5899 IXMLDOMElement_Release(element);
5901 ptr++;
5904 /* check changing types */
5905 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &element);
5906 EXPECT_HR(hr, S_OK);
5908 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)element, NULL);
5909 EXPECT_HR(hr, S_OK);
5911 hr = IXMLDOMElement_put_dataType(element, _bstr_("DateTime.tz"));
5912 EXPECT_HR(hr, S_OK);
5914 hr = IXMLDOMElement_put_dataType(element, _bstr_("string"));
5915 EXPECT_HR(hr, S_OK);
5917 IXMLDOMElement_Release(element);
5919 /* try to set type for node without a type */
5920 nameW = _bstr_("testname");
5921 type1W = _bstr_("string");
5922 type2W = _bstr_("number");
5923 while (ptr2->type != NODE_INVALID)
5925 IXMLDOMNode *node;
5926 VARIANT type;
5928 V_VT(&type) = VT_I2;
5929 V_I2(&type) = ptr2->type;
5931 hr = IXMLDOMDocument_createNode(doc, type, nameW, NULL, &node);
5932 EXPECT_HR(hr, S_OK);
5933 if(hr == S_OK)
5935 hr = IXMLDOMElement_appendChild(root, node, NULL);
5936 EXPECT_HR(hr, S_OK);
5938 hr = IXMLDOMNode_put_dataType(node, NULL);
5939 EXPECT_HR(hr, E_INVALIDARG);
5941 hr = IXMLDOMNode_put_dataType(node, type1W);
5942 ok(hr == ptr2->hr, "failed for type %d, 0x%08x\n", ptr2->type, ptr->hr);
5943 hr = IXMLDOMNode_put_dataType(node, type2W);
5944 ok(hr == ptr2->hr, "failed for type %d, 0x%08x\n", ptr2->type, ptr->hr);
5946 IXMLDOMNode_Release(node);
5948 ptr2++;
5951 IXMLDOMElement_Release(root);
5952 IXMLDOMDocument_Release(doc);
5953 free_bstrs();
5956 static void test_save(void)
5958 IXMLDOMDocument *doc, *doc2;
5959 IXMLDOMElement *root;
5960 BSTR sOrig, sNew, filename;
5961 char buffer[100];
5962 IStream *stream;
5963 HGLOBAL global;
5964 VARIANT_BOOL b;
5965 DWORD read = 0;
5966 VARIANT dest;
5967 HANDLE hfile;
5968 HRESULT hr;
5969 char *ptr;
5971 doc = create_document(&IID_IXMLDOMDocument);
5972 doc2 = create_document(&IID_IXMLDOMDocument);
5974 /* save to IXMLDOMDocument */
5975 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
5976 EXPECT_HR(hr, S_OK);
5978 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
5979 EXPECT_HR(hr, S_OK);
5981 V_VT(&dest) = VT_UNKNOWN;
5982 V_UNKNOWN(&dest) = (IUnknown*)doc2;
5984 hr = IXMLDOMDocument_save(doc, dest);
5985 EXPECT_HR(hr, S_OK);
5987 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
5988 EXPECT_HR(hr, S_OK);
5990 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
5991 EXPECT_HR(hr, S_OK);
5993 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as original\n");
5995 SysFreeString(sOrig);
5996 SysFreeString(sNew);
5998 IXMLDOMElement_Release(root);
5999 IXMLDOMDocument_Release(doc2);
6001 /* save to path */
6002 V_VT(&dest) = VT_BSTR;
6003 V_BSTR(&dest) = _bstr_("test.xml");
6005 hr = IXMLDOMDocument_save(doc, dest);
6006 EXPECT_HR(hr, S_OK);
6008 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
6009 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
6010 if(hfile == INVALID_HANDLE_VALUE) return;
6012 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
6013 ok(read != 0, "could not read file\n");
6014 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
6016 CloseHandle(hfile);
6017 DeleteFileA("test.xml");
6019 /* save to path VT_BSTR | VT_BYREF */
6020 filename = _bstr_("test.xml");
6021 V_VT(&dest) = VT_BSTR | VT_BYREF;
6022 V_BSTRREF(&dest) = &filename;
6024 hr = IXMLDOMDocument_save(doc, dest);
6025 EXPECT_HR(hr, S_OK);
6027 hfile = CreateFileA("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
6028 ok(hfile != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
6029 if(hfile == INVALID_HANDLE_VALUE) return;
6031 if (hfile != INVALID_HANDLE_VALUE)
6033 ReadFile(hfile, buffer, sizeof(buffer), &read, NULL);
6034 ok(read != 0, "could not read file\n");
6035 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
6037 CloseHandle(hfile);
6038 DeleteFileA("test.xml");
6041 /* save to stream */
6042 V_VT(&dest) = VT_UNKNOWN;
6043 V_UNKNOWN(&dest) = (IUnknown*)&savestream;
6045 hr = IXMLDOMDocument_save(doc, dest);
6046 EXPECT_HR(hr, S_OK);
6048 /* loaded data contains xml declaration */
6049 hr = IXMLDOMDocument_loadXML(doc, _bstr_(win1252xml), &b);
6050 EXPECT_HR(hr, S_OK);
6052 CreateStreamOnHGlobal(NULL, TRUE, &stream);
6053 V_VT(&dest) = VT_UNKNOWN;
6054 V_UNKNOWN(&dest) = (IUnknown*)stream;
6055 hr = IXMLDOMDocument_save(doc, dest);
6056 EXPECT_HR(hr, S_OK);
6058 hr = GetHGlobalFromStream(stream, &global);
6059 EXPECT_HR(hr, S_OK);
6060 ptr = GlobalLock(global);
6061 ok(!memcmp(ptr, win1252decl, strlen(win1252decl)), "got wrong xml declaration\n");
6062 GlobalUnlock(global);
6063 IStream_Release(stream);
6065 /* loaded data without xml declaration */
6066 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<a/>"), &b);
6067 EXPECT_HR(hr, S_OK);
6069 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
6070 ok(hr == S_OK, "got 0x%08x\n", hr);
6071 V_VT(&dest) = VT_UNKNOWN;
6072 V_UNKNOWN(&dest) = (IUnknown*)stream;
6073 hr = IXMLDOMDocument_save(doc, dest);
6074 EXPECT_HR(hr, S_OK);
6076 hr = GetHGlobalFromStream(stream, &global);
6077 EXPECT_HR(hr, S_OK);
6078 ptr = GlobalLock(global);
6079 ok(ptr[0] == '<' && ptr[1] != '?', "got wrong start tag %c%c\n", ptr[0], ptr[1]);
6080 GlobalUnlock(global);
6081 IStream_Release(stream);
6083 IXMLDOMDocument_Release(doc);
6084 free_bstrs();
6087 static void test_testTransforms(void)
6089 IXMLDOMDocument *doc, *docSS;
6090 IXMLDOMNode *pNode;
6091 VARIANT_BOOL bSucc;
6092 HRESULT hr;
6094 doc = create_document(&IID_IXMLDOMDocument);
6095 docSS = create_document(&IID_IXMLDOMDocument);
6097 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
6098 ok(hr == S_OK, "ret %08x\n", hr );
6100 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
6101 ok(hr == S_OK, "ret %08x\n", hr );
6103 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
6104 ok(hr == S_OK, "ret %08x\n", hr );
6105 if(hr == S_OK)
6107 BSTR bOut;
6109 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
6110 ok(hr == S_OK, "ret %08x\n", hr );
6111 if(hr == S_OK)
6113 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "got output %s\n", wine_dbgstr_w(bOut));
6114 SysFreeString(bOut);
6117 IXMLDOMNode_Release(pNode);
6120 IXMLDOMDocument_Release(docSS);
6121 IXMLDOMDocument_Release(doc);
6123 free_bstrs();
6126 struct namespaces_change_t {
6127 const CLSID *clsid;
6128 const char *name;
6131 static const struct namespaces_change_t namespaces_change_test_data[] = {
6132 { &CLSID_DOMDocument, "CLSID_DOMDocument" },
6133 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" },
6134 { &CLSID_DOMDocument26, "CLSID_DOMDocument26" },
6135 { &CLSID_DOMDocument30, "CLSID_DOMDocument30" },
6136 { &CLSID_DOMDocument40, "CLSID_DOMDocument40" },
6137 { &CLSID_DOMDocument60, "CLSID_DOMDocument60" },
6138 { 0 }
6141 static void test_namespaces_change(void)
6143 const struct namespaces_change_t *class_ptr = namespaces_change_test_data;
6145 while (class_ptr->clsid)
6147 IXMLDOMDocument *doc = NULL;
6148 IXMLDOMElement *elem = NULL;
6149 IXMLDOMNode *node = NULL;
6151 VARIANT var;
6152 HRESULT hr;
6153 BSTR str;
6155 if (!is_clsid_supported(class_ptr->clsid, &IID_IXMLDOMDocument))
6157 class_ptr++;
6158 continue;
6161 hr = CoCreateInstance(class_ptr->clsid, NULL, CLSCTX_INPROC_SERVER,
6162 &IID_IXMLDOMDocument, (void**)&doc);
6163 ok(hr == S_OK, "got 0x%08x\n", hr);
6165 V_VT(&var) = VT_I2;
6166 V_I2(&var) = NODE_ELEMENT;
6168 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("ns:elem"), _bstr_("ns/uri"), &node);
6169 EXPECT_HR(hr, S_OK);
6171 hr = IXMLDOMDocument_appendChild(doc, node, NULL);
6172 EXPECT_HR(hr, S_OK);
6174 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
6175 EXPECT_HR(hr, S_OK);
6177 /* try same prefix, different uri */
6178 V_VT(&var) = VT_BSTR;
6179 V_BSTR(&var) = _bstr_("ns/uri2");
6181 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
6182 EXPECT_HR(hr, E_INVALIDARG);
6184 /* try same prefix and uri */
6185 V_VT(&var) = VT_BSTR;
6186 V_BSTR(&var) = _bstr_("ns/uri");
6188 hr = IXMLDOMElement_setAttribute(elem, _bstr_("xmlns:ns"), var);
6189 EXPECT_HR(hr, S_OK);
6191 hr = IXMLDOMElement_get_xml(elem, &str);
6192 EXPECT_HR(hr, S_OK);
6193 ok(!lstrcmpW(str, _bstr_("<ns:elem xmlns:ns=\"ns/uri\"/>")), "got element %s for %s\n",
6194 wine_dbgstr_w(str), class_ptr->name);
6195 SysFreeString(str);
6197 IXMLDOMElement_Release(elem);
6198 IXMLDOMDocument_Release(doc);
6200 free_bstrs();
6202 class_ptr++;
6206 static void test_namespaces_basic(void)
6208 static const CHAR namespaces_xmlA[] =
6209 "<?xml version=\"1.0\"?>\n"
6210 "<XMI xmi.version=\"1.1\" xmlns:Model=\"http://omg.org/mof.Model/1.3\">"
6211 " <XMI.content>"
6212 " <Model:Package name=\"WinePackage\" Model:name2=\"name2 attr\" />"
6213 " </XMI.content>"
6214 "</XMI>";
6216 IXMLDOMDocument *doc;
6217 IXMLDOMElement *elem;
6218 IXMLDOMNode *node;
6220 VARIANT_BOOL b;
6221 HRESULT hr;
6222 BSTR str;
6224 doc = create_document(&IID_IXMLDOMDocument);
6226 hr = IXMLDOMDocument_loadXML(doc, _bstr_(namespaces_xmlA), &b);
6227 EXPECT_HR(hr, S_OK);
6228 ok(b == VARIANT_TRUE, "got %d\n", b);
6230 str = (BSTR)0xdeadbeef;
6231 hr = IXMLDOMDocument_get_namespaceURI(doc, &str);
6232 EXPECT_HR(hr, S_FALSE);
6233 ok(str == NULL, "got %p\n", str);
6235 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("//XMI.content"), &node );
6236 EXPECT_HR(hr, S_OK);
6237 if(hr == S_OK)
6239 IXMLDOMAttribute *attr;
6240 IXMLDOMNode *node2;
6242 hr = IXMLDOMNode_get_firstChild(node, &node2);
6243 EXPECT_HR(hr, S_OK);
6244 ok(node2 != NULL, "got %p\n", node2);
6246 /* Test get_prefix */
6247 hr = IXMLDOMNode_get_prefix(node2, NULL);
6248 EXPECT_HR(hr, E_INVALIDARG);
6249 /* NOTE: Need to test that arg2 gets cleared on Error. */
6251 hr = IXMLDOMNode_get_prefix(node2, &str);
6252 EXPECT_HR(hr, S_OK);
6253 ok( !lstrcmpW( str, _bstr_("Model")), "got %s\n", wine_dbgstr_w(str));
6254 SysFreeString(str);
6256 hr = IXMLDOMNode_get_nodeName(node2, &str);
6257 EXPECT_HR(hr, S_OK);
6258 ok(!lstrcmpW( str, _bstr_("Model:Package")), "got %s\n", wine_dbgstr_w(str));
6259 SysFreeString(str);
6261 /* Test get_namespaceURI */
6262 hr = IXMLDOMNode_get_namespaceURI(node2, NULL);
6263 EXPECT_HR(hr, E_INVALIDARG);
6264 /* NOTE: Need to test that arg2 gets cleared on Error. */
6266 hr = IXMLDOMNode_get_namespaceURI(node2, &str);
6267 EXPECT_HR(hr, S_OK);
6268 ok(!lstrcmpW( str, _bstr_("http://omg.org/mof.Model/1.3")), "got %s\n", wine_dbgstr_w(str));
6269 SysFreeString(str);
6271 hr = IXMLDOMNode_QueryInterface(node2, &IID_IXMLDOMElement, (void**)&elem);
6272 EXPECT_HR(hr, S_OK);
6274 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("Model:name2"), &attr);
6275 EXPECT_HR(hr, S_OK);
6277 hr = IXMLDOMAttribute_get_nodeName(attr, &str);
6278 EXPECT_HR(hr, S_OK);
6279 ok(!lstrcmpW( str, _bstr_("Model:name2")), "got %s\n", wine_dbgstr_w(str));
6280 SysFreeString(str);
6282 hr = IXMLDOMAttribute_get_prefix(attr, &str);
6283 EXPECT_HR(hr, S_OK);
6284 ok(!lstrcmpW( str, _bstr_("Model")), "got %s\n", wine_dbgstr_w(str));
6285 SysFreeString(str);
6287 IXMLDOMAttribute_Release(attr);
6288 IXMLDOMElement_Release(elem);
6290 IXMLDOMNode_Release(node2);
6291 IXMLDOMNode_Release(node);
6294 IXMLDOMDocument_Release(doc);
6296 free_bstrs();
6299 static void test_FormattingXML(void)
6301 IXMLDOMDocument *doc;
6302 IXMLDOMElement *pElement;
6303 VARIANT_BOOL bSucc;
6304 HRESULT hr;
6305 BSTR str;
6306 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
6307 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
6309 doc = create_document(&IID_IXMLDOMDocument);
6311 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
6312 ok(hr == S_OK, "ret %08x\n", hr );
6313 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6315 if(bSucc == VARIANT_TRUE)
6317 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
6318 ok(hr == S_OK, "ret %08x\n", hr );
6319 if(hr == S_OK)
6321 hr = IXMLDOMElement_get_xml(pElement, &str);
6322 ok(hr == S_OK, "ret %08x\n", hr );
6323 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
6324 SysFreeString(str);
6326 IXMLDOMElement_Release(pElement);
6330 IXMLDOMDocument_Release(doc);
6332 free_bstrs();
6335 typedef struct _nodetypedvalue_t {
6336 const char *name;
6337 VARTYPE type;
6338 const char *value; /* value in string format */
6339 } nodetypedvalue_t;
6341 static const nodetypedvalue_t get_nodetypedvalue[] = {
6342 { "root/string", VT_BSTR, "Wine" },
6343 { "root/string2", VT_BSTR, "String" },
6344 { "root/number", VT_BSTR, "12.44" },
6345 { "root/number2", VT_BSTR, "-3.71e3" },
6346 { "root/int", VT_I4, "-13" },
6347 { "root/fixed", VT_CY, "7322.9371" },
6348 { "root/bool", VT_BOOL, "-1" },
6349 { "root/datetime", VT_DATE, "40135.14" },
6350 { "root/datetimetz",VT_DATE, "37813.59" },
6351 { "root/date", VT_DATE, "665413" },
6352 { "root/time", VT_DATE, "0.5813889" },
6353 { "root/timetz", VT_DATE, "1.112512" },
6354 { "root/i1", VT_I1, "-13" },
6355 { "root/i2", VT_I2, "31915" },
6356 { "root/i4", VT_I4, "-312232" },
6357 { "root/ui1", VT_UI1, "123" },
6358 { "root/ui2", VT_UI2, "48282" },
6359 { "root/ui4", VT_UI4, "949281" },
6360 { "root/r4", VT_R4, "213124" },
6361 { "root/r8", VT_R8, "0.412" },
6362 { "root/float", VT_R8, "41221.421" },
6363 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
6364 { "root/binbase64", VT_ARRAY|VT_UI1, "base64 test" },
6365 { "root/binbase64_1", VT_ARRAY|VT_UI1, "base64 test" },
6366 { "root/binbase64_2", VT_ARRAY|VT_UI1, "base64 test" },
6367 { 0 }
6370 static void test_nodeTypedValue(void)
6372 const nodetypedvalue_t *entry = get_nodetypedvalue;
6373 IXMLDOMDocumentType *doctype, *doctype2;
6374 IXMLDOMProcessingInstruction *pi;
6375 IXMLDOMDocumentFragment *frag;
6376 IXMLDOMDocument *doc, *doc2;
6377 IXMLDOMCDATASection *cdata;
6378 IXMLDOMComment *comment;
6379 IXMLDOMNode *node;
6380 VARIANT_BOOL b;
6381 VARIANT value;
6382 HRESULT hr;
6384 doc = create_document(&IID_IXMLDOMDocument);
6386 b = VARIANT_FALSE;
6387 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
6388 ok(hr == S_OK, "ret %08x\n", hr );
6389 ok(b == VARIANT_TRUE, "got %d\n", b);
6391 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
6392 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6394 V_VT(&value) = VT_BSTR;
6395 V_BSTR(&value) = NULL;
6396 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
6397 ok(hr == S_FALSE, "ret %08x\n", hr );
6398 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
6400 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
6401 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6403 V_VT(&value) = VT_EMPTY;
6404 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
6405 ok(hr == S_FALSE, "ret %08x\n", hr );
6406 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
6408 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
6409 ok(hr == S_OK, "ret %08x\n", hr );
6411 V_VT(&value) = VT_BSTR;
6412 V_BSTR(&value) = NULL;
6413 hr = IXMLDOMNode_get_nodeValue(node, &value);
6414 ok(hr == S_FALSE, "ret %08x\n", hr );
6415 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
6417 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
6418 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6420 IXMLDOMNode_Release(node);
6422 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
6423 ok(hr == S_OK, "ret %08x\n", hr );
6425 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
6427 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6428 ok(hr == S_OK, "ret %08x\n", hr );
6429 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
6430 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
6431 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
6432 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
6433 VariantClear(&value);
6434 IXMLDOMNode_Release(node);
6437 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("foo"), _bstr_("value"), &pi);
6438 ok(hr == S_OK, "ret %08x\n", hr );
6440 V_VT(&value) = VT_NULL;
6441 V_BSTR(&value) = (void*)0xdeadbeef;
6442 hr = IXMLDOMProcessingInstruction_get_nodeTypedValue(pi, &value);
6443 ok(hr == S_OK, "ret %08x\n", hr );
6444 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
6445 ok(!lstrcmpW(V_BSTR(&value), _bstr_("value")), "got wrong value\n");
6446 IXMLDOMProcessingInstruction_Release(pi);
6447 VariantClear(&value);
6450 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("[1]*2=3; &gee that's not right!"), &cdata);
6451 ok(hr == S_OK, "ret %08x\n", hr );
6453 V_VT(&value) = VT_NULL;
6454 V_BSTR(&value) = (void*)0xdeadbeef;
6455 hr = IXMLDOMCDATASection_get_nodeTypedValue(cdata, &value);
6456 ok(hr == S_OK, "ret %08x\n", hr );
6457 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
6458 ok(!lstrcmpW(V_BSTR(&value), _bstr_("[1]*2=3; &gee that's not right!")), "got wrong value\n");
6459 IXMLDOMCDATASection_Release(cdata);
6460 VariantClear(&value);
6463 hr = IXMLDOMDocument_createComment(doc, _bstr_("comment"), &comment);
6464 ok(hr == S_OK, "ret %08x\n", hr );
6466 V_VT(&value) = VT_NULL;
6467 V_BSTR(&value) = (void*)0xdeadbeef;
6468 hr = IXMLDOMComment_get_nodeTypedValue(comment, &value);
6469 ok(hr == S_OK, "ret %08x\n", hr );
6470 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
6471 ok(!lstrcmpW(V_BSTR(&value), _bstr_("comment")), "got wrong value\n");
6472 IXMLDOMComment_Release(comment);
6473 VariantClear(&value);
6476 hr = IXMLDOMDocument_createDocumentFragment(doc, &frag);
6477 ok(hr == S_OK, "ret %08x\n", hr );
6479 V_VT(&value) = VT_EMPTY;
6480 hr = IXMLDOMDocumentFragment_get_nodeTypedValue(frag, &value);
6481 ok(hr == S_FALSE, "ret %08x\n", hr );
6482 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
6483 IXMLDOMDocumentFragment_Release(frag);
6486 doc2 = create_document(&IID_IXMLDOMDocument);
6488 b = VARIANT_FALSE;
6489 hr = IXMLDOMDocument_loadXML(doc2, _bstr_(szEmailXML), &b);
6490 ok(hr == S_OK, "ret %08x\n", hr );
6491 ok(b == VARIANT_TRUE, "got %d\n", b);
6493 EXPECT_REF(doc2, 1);
6495 hr = IXMLDOMDocument_get_doctype(doc2, &doctype);
6496 ok(hr == S_OK, "ret %08x\n", hr );
6498 EXPECT_REF(doc2, 1);
6499 todo_wine EXPECT_REF(doctype, 2);
6502 V_VT(&value) = VT_EMPTY;
6503 hr = IXMLDOMDocumentType_get_nodeTypedValue(doctype, &value);
6504 ok(hr == S_FALSE, "ret %08x\n", hr );
6505 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
6508 hr = IXMLDOMDocument_get_doctype(doc2, &doctype2);
6509 ok(hr == S_OK, "ret %08x\n", hr );
6510 ok(doctype != doctype2, "got %p, was %p\n", doctype2, doctype);
6512 IXMLDOMDocumentType_Release(doctype2);
6513 IXMLDOMDocumentType_Release(doctype);
6515 IXMLDOMDocument_Release(doc2);
6517 while (entry->name)
6519 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
6520 ok(hr == S_OK, "ret %08x\n", hr );
6522 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6523 ok(hr == S_OK, "ret %08x\n", hr );
6524 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
6526 if (entry->type == (VT_ARRAY|VT_UI1))
6528 ok(V_ARRAY(&value)->rgsabound[0].cElements == strlen(entry->value),
6529 "incorrect array size %d\n", V_ARRAY(&value)->rgsabound[0].cElements);
6532 if (entry->type != VT_BSTR)
6534 if (entry->type == VT_DATE ||
6535 entry->type == VT_R8 ||
6536 entry->type == VT_CY)
6538 if (entry->type == VT_DATE)
6540 hr = VariantChangeType(&value, &value, 0, VT_R4);
6541 ok(hr == S_OK, "ret %08x\n", hr );
6543 hr = VariantChangeTypeEx(&value, &value,
6544 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
6545 VARIANT_NOUSEROVERRIDE, VT_BSTR);
6546 ok(hr == S_OK, "ret %08x\n", hr );
6548 else
6550 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
6551 ok(hr == S_OK, "ret %08x\n", hr );
6554 /* for byte array from VT_ARRAY|VT_UI1 it's not a WCHAR buffer */
6555 if (entry->type == (VT_ARRAY|VT_UI1))
6557 ok(!memcmp( V_BSTR(&value), entry->value, strlen(entry->value)),
6558 "expected %s\n", entry->value);
6560 else
6561 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
6562 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
6564 else
6565 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
6566 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
6568 VariantClear( &value );
6569 IXMLDOMNode_Release(node);
6571 entry++;
6574 IXMLDOMDocument_Release(doc);
6575 free_bstrs();
6578 static void test_TransformWithLoadingLocalFile(void)
6580 IXMLDOMDocument *doc;
6581 IXMLDOMDocument *xsl;
6582 IXMLDOMNode *pNode;
6583 VARIANT_BOOL bSucc;
6584 HRESULT hr;
6585 HANDLE file;
6586 DWORD dwWritten;
6587 char lpPathBuffer[MAX_PATH];
6588 int i;
6590 /* Create a Temp File. */
6591 GetTempPathA(MAX_PATH, lpPathBuffer);
6592 strcat(lpPathBuffer, "customers.xml" );
6594 file = CreateFileA(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
6595 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
6596 if(file == INVALID_HANDLE_VALUE)
6597 return;
6599 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
6600 CloseHandle(file);
6602 /* Correct path to not include an escape character. */
6603 for(i=0; i < strlen(lpPathBuffer); i++)
6605 if(lpPathBuffer[i] == '\\')
6606 lpPathBuffer[i] = '/';
6609 doc = create_document(&IID_IXMLDOMDocument);
6610 xsl = create_document(&IID_IXMLDOMDocument);
6612 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
6613 ok(hr == S_OK, "ret %08x\n", hr );
6614 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6615 if(bSucc == VARIANT_TRUE)
6617 BSTR sXSL;
6618 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
6619 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
6620 BSTR sFileName = _bstr_(lpPathBuffer);
6621 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
6623 sXSL = SysAllocStringLen(NULL, nLegnth);
6624 lstrcpyW(sXSL, sPart1);
6625 lstrcatW(sXSL, sFileName);
6626 lstrcatW(sXSL, sPart2);
6628 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
6629 ok(hr == S_OK, "ret %08x\n", hr );
6630 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6631 if(bSucc == VARIANT_TRUE)
6633 BSTR sResult;
6635 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
6636 ok(hr == S_OK, "ret %08x\n", hr );
6637 if(hr == S_OK)
6639 /* This will load the temp file via the XSL */
6640 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
6641 ok(hr == S_OK, "ret %08x\n", hr );
6642 if(hr == S_OK)
6644 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
6645 SysFreeString(sResult);
6648 IXMLDOMNode_Release(pNode);
6652 SysFreeString(sXSL);
6655 IXMLDOMDocument_Release(doc);
6656 IXMLDOMDocument_Release(xsl);
6658 DeleteFileA(lpPathBuffer);
6659 free_bstrs();
6662 static void test_put_nodeValue(void)
6664 static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
6665 IXMLDOMDocument *doc;
6666 IXMLDOMText *text;
6667 IXMLDOMEntityReference *entityref;
6668 IXMLDOMAttribute *attr;
6669 IXMLDOMNode *node;
6670 HRESULT hr;
6671 VARIANT data, type;
6673 doc = create_document(&IID_IXMLDOMDocument);
6675 /* test for unsupported types */
6676 /* NODE_DOCUMENT */
6677 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
6678 ok(hr == S_OK, "ret %08x\n", hr );
6679 V_VT(&data) = VT_BSTR;
6680 V_BSTR(&data) = _bstr_("one two three");
6681 hr = IXMLDOMNode_put_nodeValue(node, data);
6682 ok(hr == E_FAIL, "ret %08x\n", hr );
6683 IXMLDOMNode_Release(node);
6685 /* NODE_DOCUMENT_FRAGMENT */
6686 V_VT(&type) = VT_I1;
6687 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
6688 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
6689 ok(hr == S_OK, "ret %08x\n", hr );
6690 V_VT(&data) = VT_BSTR;
6691 V_BSTR(&data) = _bstr_("one two three");
6692 hr = IXMLDOMNode_put_nodeValue(node, data);
6693 ok(hr == E_FAIL, "ret %08x\n", hr );
6694 IXMLDOMNode_Release(node);
6696 /* NODE_ELEMENT */
6697 V_VT(&type) = VT_I1;
6698 V_I1(&type) = NODE_ELEMENT;
6699 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
6700 ok(hr == S_OK, "ret %08x\n", hr );
6701 V_VT(&data) = VT_BSTR;
6702 V_BSTR(&data) = _bstr_("one two three");
6703 hr = IXMLDOMNode_put_nodeValue(node, data);
6704 ok(hr == E_FAIL, "ret %08x\n", hr );
6705 IXMLDOMNode_Release(node);
6707 /* NODE_ENTITY_REFERENCE */
6708 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
6709 ok(hr == S_OK, "ret %08x\n", hr );
6711 V_VT(&data) = VT_BSTR;
6712 V_BSTR(&data) = _bstr_("one two three");
6713 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
6714 ok(hr == E_FAIL, "ret %08x\n", hr );
6716 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
6717 ok(hr == S_OK, "ret %08x\n", hr );
6718 V_VT(&data) = VT_BSTR;
6719 V_BSTR(&data) = _bstr_("one two three");
6720 hr = IXMLDOMNode_put_nodeValue(node, data);
6721 ok(hr == E_FAIL, "ret %08x\n", hr );
6722 IXMLDOMNode_Release(node);
6723 IXMLDOMEntityReference_Release(entityref);
6725 /* supported types */
6726 hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
6727 ok(hr == S_OK, "ret %08x\n", hr );
6728 V_VT(&data) = VT_BSTR;
6729 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
6730 hr = IXMLDOMText_put_nodeValue(text, data);
6731 ok(hr == S_OK, "ret %08x\n", hr );
6732 IXMLDOMText_Release(text);
6734 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
6735 ok(hr == S_OK, "ret %08x\n", hr );
6736 V_VT(&data) = VT_BSTR;
6737 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
6738 hr = IXMLDOMAttribute_put_nodeValue(attr, data);
6739 ok(hr == S_OK, "ret %08x\n", hr );
6740 hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
6741 ok(hr == S_OK, "ret %08x\n", hr );
6742 ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
6743 wine_dbgstr_w(V_BSTR(&data)));
6744 VariantClear(&data);
6745 IXMLDOMAttribute_Release(attr);
6747 free_bstrs();
6749 IXMLDOMDocument_Release(doc);
6752 static void test_IObjectSafety(void)
6754 IXMLDOMDocument *doc;
6755 IObjectSafety *safety;
6756 HRESULT hr;
6758 doc = create_document(&IID_IXMLDOMDocument);
6760 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
6761 ok(hr == S_OK, "ret %08x\n", hr );
6763 test_IObjectSafety_common(safety);
6765 IObjectSafety_Release(safety);
6766 IXMLDOMDocument_Release(doc);
6768 hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
6769 &IID_IObjectSafety, (void**)&safety);
6770 ok(hr == S_OK, "Could not create XMLHTTPRequest instance: %08x\n", hr);
6772 test_IObjectSafety_common(safety);
6774 IObjectSafety_Release(safety);
6778 typedef struct _property_test_t {
6779 const GUID *guid;
6780 const char *clsid;
6781 const char *property;
6782 const char *value;
6783 } property_test_t;
6785 static const property_test_t properties_test_data[] = {
6786 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
6787 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
6788 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
6789 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
6790 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
6791 { 0 }
6794 static void test_default_properties(void)
6796 const property_test_t *entry = properties_test_data;
6798 while (entry->guid)
6800 IXMLDOMDocument2 *doc;
6801 VARIANT var;
6802 HRESULT hr;
6804 if (!is_clsid_supported(entry->guid, &IID_IXMLDOMDocument2))
6806 entry++;
6807 continue;
6810 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
6811 ok(hr == S_OK, "got 0x%08x\n", hr);
6813 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
6814 ok(hr == S_OK, "got 0x%08x\n", hr);
6815 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
6816 entry->value, entry->clsid);
6817 VariantClear(&var);
6819 IXMLDOMDocument2_Release(doc);
6821 entry++;
6825 typedef struct {
6826 const char *query;
6827 const char *list;
6828 BOOL todo;
6829 } xslpattern_test_t;
6831 static const xslpattern_test_t xslpattern_test[] = {
6832 { "root//elem[0]", "E1.E2.D1" },
6833 { "root//elem[index()=1]", "E2.E2.D1" },
6834 { "root//elem[index() $eq$ 1]", "E2.E2.D1" },
6835 { "root//elem[end()]", "E4.E2.D1" },
6836 { "root//elem[$not$ end()]", "E1.E2.D1 E2.E2.D1 E3.E2.D1" },
6837 { "root//elem[index() != 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
6838 { "root//elem[index() $ne$ 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
6839 { "root//elem[index() < 2]", "E1.E2.D1 E2.E2.D1" },
6840 { "root//elem[index() $lt$ 2]", "E1.E2.D1 E2.E2.D1" },
6841 { "root//elem[index() <= 1]", "E1.E2.D1 E2.E2.D1" },
6842 { "root//elem[index() $le$ 1]", "E1.E2.D1 E2.E2.D1" },
6843 { "root//elem[index() > 1]", "E3.E2.D1 E4.E2.D1" },
6844 { "root//elem[index() $gt$ 1]", "E3.E2.D1 E4.E2.D1" },
6845 { "root//elem[index() >= 2]", "E3.E2.D1 E4.E2.D1" },
6846 { "root//elem[index() $ge$ 2]", "E3.E2.D1 E4.E2.D1" },
6847 { "root//elem[a $ieq$ 'a2 field']", "E2.E2.D1" },
6848 { "root//elem[a $ine$ 'a2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
6849 { "root//elem[a $ilt$ 'a3 field']", "E1.E2.D1 E2.E2.D1" },
6850 { "root//elem[a $ile$ 'a2 field']", "E1.E2.D1 E2.E2.D1" },
6851 { "root//elem[a $igt$ 'a2 field']", "E3.E2.D1 E4.E2.D1" },
6852 { "root//elem[a $ige$ 'a3 field']", "E3.E2.D1 E4.E2.D1" },
6853 { "root//elem[$any$ *='B2 field']", "E2.E2.D1" },
6854 { "root//elem[$all$ *!='B2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
6855 { "root//elem[index()=0 or end()]", "E1.E2.D1 E4.E2.D1" },
6856 { "root//elem[index()=0 $or$ end()]", "E1.E2.D1 E4.E2.D1" },
6857 { "root//elem[index()=0 || end()]", "E1.E2.D1 E4.E2.D1" },
6858 { "root//elem[index()>0 and $not$ end()]", "E2.E2.D1 E3.E2.D1" },
6859 { "root//elem[index()>0 $and$ $not$ end()]", "E2.E2.D1 E3.E2.D1" },
6860 { "root//elem[index()>0 && $not$ end()]", "E2.E2.D1 E3.E2.D1" },
6861 { "root/elem[0]", "E1.E2.D1" },
6862 { "root/elem[index()=1]", "E2.E2.D1" },
6863 { "root/elem[index() $eq$ 1]", "E2.E2.D1" },
6864 { "root/elem[end()]", "E4.E2.D1" },
6865 { "root/elem[$not$ end()]", "E1.E2.D1 E2.E2.D1 E3.E2.D1" },
6866 { "root/elem[index() != 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
6867 { "root/elem[index() $ne$ 0]", "E2.E2.D1 E3.E2.D1 E4.E2.D1" },
6868 { "root/elem[index() < 2]", "E1.E2.D1 E2.E2.D1" },
6869 { "root/elem[index() $lt$ 2]", "E1.E2.D1 E2.E2.D1" },
6870 { "root/elem[index() <= 1]", "E1.E2.D1 E2.E2.D1" },
6871 { "root/elem[index() $le$ 1]", "E1.E2.D1 E2.E2.D1" },
6872 { "root/elem[index() > 1]", "E3.E2.D1 E4.E2.D1" },
6873 { "root/elem[index() $gt$ 1]", "E3.E2.D1 E4.E2.D1" },
6874 { "root/elem[index() >= 2]", "E3.E2.D1 E4.E2.D1" },
6875 { "root/elem[index() $ge$ 2]", "E3.E2.D1 E4.E2.D1" },
6876 { "root/elem[a $ieq$ 'a2 field']", "E2.E2.D1" },
6877 { "root/elem[a $ine$ 'a2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
6878 { "root/elem[a $ilt$ 'a3 field']", "E1.E2.D1 E2.E2.D1" },
6879 { "root/elem[a $ile$ 'a2 field']", "E1.E2.D1 E2.E2.D1" },
6880 { "root/elem[a $igt$ 'a2 field']", "E3.E2.D1 E4.E2.D1" },
6881 { "root/elem[a $ige$ 'a3 field']", "E3.E2.D1 E4.E2.D1" },
6882 { "root/elem[$any$ *='B2 field']", "E2.E2.D1" },
6883 { "root/elem[$all$ *!='B2 field']", "E1.E2.D1 E3.E2.D1 E4.E2.D1" },
6884 { "root/elem[index()=0 or end()]", "E1.E2.D1 E4.E2.D1" },
6885 { "root/elem[index()=0 $or$ end()]", "E1.E2.D1 E4.E2.D1" },
6886 { "root/elem[index()=0 || end()]", "E1.E2.D1 E4.E2.D1" },
6887 { "root/elem[index()>0 and $not$ end()]", "E2.E2.D1 E3.E2.D1" },
6888 { "root/elem[index()>0 $and$ $not$ end()]", "E2.E2.D1 E3.E2.D1" },
6889 { "root/elem[index()>0 && $not$ end()]", "E2.E2.D1 E3.E2.D1" },
6890 { "root/elem[d]", "E1.E2.D1 E2.E2.D1 E4.E2.D1" },
6891 { "root/elem[@*]", "E2.E2.D1 E3.E2.D1", TRUE },
6892 { NULL }
6895 static const xslpattern_test_t xslpattern_test_no_ns[] = {
6896 /* prefixes don't need to be registered, you may use them as they are in the doc */
6897 { "//bar:x", "E5.E1.E5.E1.E2.D1 E6.E2.E5.E1.E2.D1" },
6898 /* prefixes must be explicitly specified in the name */
6899 { "//foo:elem", "" },
6900 { "//foo:c", "E3.E4.E2.D1" },
6901 { NULL }
6904 static const xslpattern_test_t xslpattern_test_func[] = {
6905 { "attribute()", "" },
6906 { "attribute('depth')", "" },
6907 { "root/attribute('depth')", "A'depth'.E3.D1" },
6908 { "//x/attribute()", "A'id'.E3.E3.D1 A'depth'.E3.E3.D1" },
6909 { "//x//attribute(id)", NULL },
6910 { "//x//attribute('id')", "A'id'.E3.E3.D1 A'id'.E4.E3.E3.D1 A'id'.E5.E3.E3.D1 A'id'.E6.E3.E3.D1" },
6911 { "comment()", "C2.D1" },
6912 { "//comment()", "C2.D1 C1.E3.D1 C2.E3.E3.D1 C2.E4.E3.D1" },
6913 { "element()", "E3.D1" },
6914 { "root/y/element()", "E4.E4.E3.D1 E5.E4.E3.D1 E6.E4.E3.D1" },
6915 { "//element(a)", NULL },
6916 { "//element('a')", "E4.E3.E3.D1 E4.E4.E3.D1" },
6917 { "node()", "P1.D1 C2.D1 E3.D1" },
6918 { "//x/node()", "P1.E3.E3.D1 C2.E3.E3.D1 T3.E3.E3.D1 E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1" },
6919 { "//x/node()[nodeType()=1]", "E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1" },
6920 { "//x/node()[nodeType()=3]", "T3.E3.E3.D1" },
6921 { "//x/node()[nodeType()=7]", "P1.E3.E3.D1" },
6922 { "//x/node()[nodeType()=8]", "C2.E3.E3.D1" },
6923 { "pi()", "P1.D1" },
6924 { "//y/pi()", "P1.E4.E3.D1" },
6925 { "root/textnode()", "T2.E3.D1" },
6926 { "root/element()/textnode()", "T3.E3.E3.D1 T3.E4.E3.D1" },
6927 { NULL }
6930 static void test_XSLPattern(void)
6932 const xslpattern_test_t *ptr = xslpattern_test;
6933 IXMLDOMDocument2 *doc;
6934 IXMLDOMNodeList *list;
6935 VARIANT_BOOL b;
6936 HRESULT hr;
6937 LONG len;
6939 doc = create_document(&IID_IXMLDOMDocument2);
6941 b = VARIANT_FALSE;
6942 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b);
6943 EXPECT_HR(hr, S_OK);
6944 ok(b == VARIANT_TRUE, "failed to load XML string\n");
6946 /* switch to XSLPattern */
6947 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern"));
6948 EXPECT_HR(hr, S_OK);
6950 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
6951 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list);
6952 EXPECT_HR(hr, S_OK);
6954 len = 0;
6955 hr = IXMLDOMNodeList_get_length(list, &len);
6956 EXPECT_HR(hr, S_OK);
6957 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
6958 ok(len == 3, "expected 3 entries in list, got %d\n", len);
6959 IXMLDOMNodeList_Release(list);
6961 while (ptr->query)
6963 list = NULL;
6964 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_(ptr->query), &list);
6965 ok(hr == S_OK, "query=%s, failed with 0x%08x\n", ptr->query, hr);
6966 len = 0;
6967 hr = IXMLDOMNodeList_get_length(list, &len);
6968 ok(len != 0, "query=%s, empty list\n", ptr->query);
6969 if (len) {
6970 if (ptr->todo) {
6971 char *str = list_to_string(list);
6972 todo_wine
6973 ok(!strcmp(str, ptr->list), "Invalid node list: %s, expected %s\n", str, ptr->list);
6974 IXMLDOMNodeList_Release(list);
6976 else
6977 expect_list_and_release(list, ptr->list);
6980 ptr++;
6983 /* namespace handling */
6984 /* no registered namespaces */
6985 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_(""));
6986 EXPECT_HR(hr, S_OK);
6988 ptr = xslpattern_test_no_ns;
6989 while (ptr->query)
6991 list = NULL;
6992 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_(ptr->query), &list);
6993 ok(hr == S_OK, "query=%s, failed with 0x%08x\n", ptr->query, hr);
6995 if (*ptr->list)
6997 len = 0;
6998 hr = IXMLDOMNodeList_get_length(list, &len);
6999 EXPECT_HR(hr, S_OK);
7000 ok(len != 0, "query=%s, empty list\n", ptr->query);
7002 else
7004 len = 1;
7005 hr = IXMLDOMNodeList_get_length(list, &len);
7006 EXPECT_HR(hr, S_OK);
7007 ok(len == 0, "query=%s, empty list\n", ptr->query);
7009 if (len)
7010 expect_list_and_release(list, ptr->list);
7012 ptr++;
7015 /* explicitly register prefix foo */
7016 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
7018 /* now we get the same behavior as XPath */
7019 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list);
7020 EXPECT_HR(hr, S_OK);
7021 len = 0;
7022 hr = IXMLDOMNodeList_get_length(list, &len);
7023 EXPECT_HR(hr, S_OK);
7024 ok(len != 0, "expected filled list\n");
7025 if (len)
7026 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
7028 /* set prefix foo to some nonexistent namespace */
7029 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:nonexistent-foo'"));
7030 EXPECT_HR(hr, S_OK);
7032 /* the registered prefix takes precedence */
7033 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list);
7034 EXPECT_HR(hr, S_OK);
7035 len = 0;
7036 hr = IXMLDOMNodeList_get_length(list, &len);
7037 EXPECT_HR(hr, S_OK);
7038 ok(len == 0, "expected empty list\n");
7039 IXMLDOMNodeList_Release(list);
7041 IXMLDOMDocument2_Release(doc);
7043 doc = create_document(&IID_IXMLDOMDocument2);
7045 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNodeTypesXML), &b);
7046 EXPECT_HR(hr, S_OK);
7047 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7049 ptr = xslpattern_test_func;
7050 while (ptr->query)
7052 list = NULL;
7053 hr = IXMLDOMDocument2_selectNodes(doc, _bstr_(ptr->query), &list);
7054 if (ptr->list)
7056 ok(hr == S_OK, "query=%s, failed with 0x%08x\n", ptr->query, hr);
7057 len = 0;
7058 hr = IXMLDOMNodeList_get_length(list, &len);
7059 if (*ptr->list)
7061 ok(len != 0, "query=%s, empty list\n", ptr->query);
7062 if (len)
7063 expect_list_and_release(list, ptr->list);
7065 else
7066 ok(len == 0, "query=%s, filled list\n", ptr->query);
7068 else
7069 ok(hr == E_FAIL, "query=%s, failed with 0x%08x\n", ptr->query, hr);
7071 ptr++;
7074 IXMLDOMDocument2_Release(doc);
7075 free_bstrs();
7078 static void test_splitText(void)
7080 IXMLDOMCDATASection *cdata;
7081 IXMLDOMElement *root;
7082 IXMLDOMDocument *doc;
7083 IXMLDOMText *text, *text2;
7084 IXMLDOMNode *node;
7085 VARIANT var;
7086 VARIANT_BOOL success;
7087 LONG length;
7088 HRESULT hr;
7090 doc = create_document(&IID_IXMLDOMDocument);
7092 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
7093 ok(hr == S_OK, "got 0x%08x\n", hr);
7095 hr = IXMLDOMDocument_get_documentElement(doc, &root);
7096 ok(hr == S_OK, "got 0x%08x\n", hr);
7098 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
7099 ok(hr == S_OK, "got 0x%08x\n", hr);
7101 V_VT(&var) = VT_EMPTY;
7102 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
7103 ok(hr == S_OK, "got 0x%08x\n", hr);
7105 length = 0;
7106 hr = IXMLDOMCDATASection_get_length(cdata, &length);
7107 ok(hr == S_OK, "got 0x%08x\n", hr);
7108 ok(length > 0, "got %d\n", length);
7110 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
7111 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7113 text = (void*)0xdeadbeef;
7114 /* negative offset */
7115 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
7116 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7117 ok(text == (void*)0xdeadbeef, "got %p\n", text);
7119 text = (void*)0xdeadbeef;
7120 /* offset outside data */
7121 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
7122 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7123 ok(text == 0, "got %p\n", text);
7125 text = (void*)0xdeadbeef;
7126 /* offset outside data */
7127 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
7128 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7129 ok(text == 0, "got %p\n", text);
7131 /* no empty node created */
7132 node = (void*)0xdeadbeef;
7133 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
7134 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7135 ok(node == 0, "got %p\n", text);
7137 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
7138 ok(hr == S_OK, "got 0x%08x\n", hr);
7140 length = 0;
7141 hr = IXMLDOMText_get_length(text, &length);
7142 ok(hr == S_OK, "got 0x%08x\n", hr);
7143 ok(length == 7, "got %d\n", length);
7145 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
7146 ok(hr == S_OK, "got 0x%08x\n", hr);
7147 IXMLDOMNode_Release(node);
7149 /* split new text node */
7150 hr = IXMLDOMText_get_length(text, &length);
7151 ok(hr == S_OK, "got 0x%08x\n", hr);
7153 node = (void*)0xdeadbeef;
7154 hr = IXMLDOMText_get_nextSibling(text, &node);
7155 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7156 ok(node == 0, "got %p\n", text);
7158 hr = IXMLDOMText_splitText(text, 0, NULL);
7159 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7161 text2 = (void*)0xdeadbeef;
7162 /* negative offset */
7163 hr = IXMLDOMText_splitText(text, -1, &text2);
7164 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7165 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
7167 text2 = (void*)0xdeadbeef;
7168 /* offset outside data */
7169 hr = IXMLDOMText_splitText(text, length + 1, &text2);
7170 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7171 ok(text2 == 0, "got %p\n", text2);
7173 text2 = (void*)0xdeadbeef;
7174 /* offset outside data */
7175 hr = IXMLDOMText_splitText(text, length, &text2);
7176 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7177 ok(text2 == 0, "got %p\n", text);
7179 text2 = 0;
7180 hr = IXMLDOMText_splitText(text, 4, &text2);
7181 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
7182 if (text2) IXMLDOMText_Release(text2);
7184 node = 0;
7185 hr = IXMLDOMText_get_nextSibling(text, &node);
7186 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
7187 if (node) IXMLDOMNode_Release(node);
7189 IXMLDOMText_Release(text);
7190 IXMLDOMElement_Release(root);
7191 IXMLDOMCDATASection_Release(cdata);
7192 free_bstrs();
7195 typedef struct {
7196 const char *name;
7197 const char *uri;
7198 HRESULT hr;
7199 } ns_item_t;
7201 /* default_ns_doc used */
7202 static const ns_item_t qualified_item_tests[] = {
7203 { "xml:lang", NULL, S_FALSE },
7204 { "xml:lang", "http://www.w3.org/XML/1998/namespace", S_FALSE },
7205 { "lang", "http://www.w3.org/XML/1998/namespace", S_OK },
7206 { "ns:b", NULL, S_FALSE },
7207 { "ns:b", "nshref", S_FALSE },
7208 { "b", "nshref", S_OK },
7209 { "d", NULL, S_OK },
7210 { NULL }
7213 static const ns_item_t named_item_tests[] = {
7214 { "xml:lang", NULL, S_OK },
7215 { "lang", NULL, S_FALSE },
7216 { "ns:b", NULL, S_OK },
7217 { "b", NULL, S_FALSE },
7218 { "d", NULL, S_OK },
7219 { NULL }
7222 static void test_getQualifiedItem(void)
7224 IXMLDOMNode *pr_node, *node;
7225 IXMLDOMNodeList *root_list;
7226 IXMLDOMNamedNodeMap *map;
7227 IXMLDOMElement *element;
7228 const ns_item_t* ptr;
7229 IXMLDOMDocument *doc;
7230 VARIANT_BOOL b;
7231 HRESULT hr;
7232 LONG len;
7234 doc = create_document(&IID_IXMLDOMDocument);
7236 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
7237 EXPECT_HR(hr, S_OK);
7238 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7240 hr = IXMLDOMDocument_get_documentElement(doc, &element);
7241 EXPECT_HR(hr, S_OK);
7243 hr = IXMLDOMElement_get_childNodes(element, &root_list);
7244 EXPECT_HR(hr, S_OK);
7246 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
7247 EXPECT_HR(hr, S_OK);
7248 IXMLDOMNodeList_Release(root_list);
7250 hr = IXMLDOMNode_get_attributes(pr_node, &map);
7251 EXPECT_HR(hr, S_OK);
7252 IXMLDOMNode_Release(pr_node);
7254 len = 0;
7255 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
7256 EXPECT_HR(hr, S_OK);
7257 ok( len == 3, "length %d\n", len);
7259 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
7260 EXPECT_HR(hr, E_INVALIDARG);
7262 node = (void*)0xdeadbeef;
7263 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
7264 EXPECT_HR(hr, E_INVALIDARG);
7265 ok( node == (void*)0xdeadbeef, "got %p\n", node);
7267 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
7268 EXPECT_HR(hr, E_INVALIDARG);
7270 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
7271 EXPECT_HR(hr, S_OK);
7273 IXMLDOMNode_Release(node);
7274 IXMLDOMNamedNodeMap_Release(map);
7275 IXMLDOMElement_Release(element);
7277 hr = IXMLDOMDocument_loadXML(doc, _bstr_(default_ns_doc), &b);
7278 EXPECT_HR(hr, S_OK);
7280 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("a"), &node);
7281 EXPECT_HR(hr, S_OK);
7283 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&element);
7284 EXPECT_HR(hr, S_OK);
7285 IXMLDOMNode_Release(node);
7287 hr = IXMLDOMElement_get_attributes(element, &map);
7288 EXPECT_HR(hr, S_OK);
7290 ptr = qualified_item_tests;
7291 while (ptr->name)
7293 node = (void*)0xdeadbeef;
7294 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_(ptr->name), _bstr_(ptr->uri), &node);
7295 ok(hr == ptr->hr, "%s, %s: got 0x%08x, expected 0x%08x\n", ptr->name, ptr->uri, hr, ptr->hr);
7296 if (hr == S_OK)
7297 IXMLDOMNode_Release(node);
7298 else
7299 ok(node == NULL, "%s, %s: got %p\n", ptr->name, ptr->uri, node);
7300 ptr++;
7303 ptr = named_item_tests;
7304 while (ptr->name)
7306 node = (void*)0xdeadbeef;
7307 hr = IXMLDOMNamedNodeMap_getNamedItem(map, _bstr_(ptr->name), &node);
7308 ok(hr == ptr->hr, "%s: got 0x%08x, expected 0x%08x\n", ptr->name, hr, ptr->hr);
7309 if (hr == S_OK)
7310 IXMLDOMNode_Release(node);
7311 else
7312 ok(node == NULL, "%s: got %p\n", ptr->name, node);
7313 ptr++;
7316 IXMLDOMNamedNodeMap_Release(map);
7318 IXMLDOMElement_Release(element);
7319 IXMLDOMDocument_Release(doc);
7320 free_bstrs();
7323 static void test_removeQualifiedItem(void)
7325 IXMLDOMDocument *doc;
7326 IXMLDOMElement *element;
7327 IXMLDOMNode *pr_node, *node;
7328 IXMLDOMNodeList *root_list;
7329 IXMLDOMNamedNodeMap *map;
7330 VARIANT_BOOL b;
7331 LONG len;
7332 HRESULT hr;
7334 doc = create_document(&IID_IXMLDOMDocument);
7336 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
7337 ok( hr == S_OK, "loadXML failed\n");
7338 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7340 hr = IXMLDOMDocument_get_documentElement(doc, &element);
7341 ok( hr == S_OK, "ret %08x\n", hr);
7343 hr = IXMLDOMElement_get_childNodes(element, &root_list);
7344 ok( hr == S_OK, "ret %08x\n", hr);
7346 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
7347 ok( hr == S_OK, "ret %08x\n", hr);
7348 IXMLDOMNodeList_Release(root_list);
7350 hr = IXMLDOMNode_get_attributes(pr_node, &map);
7351 ok( hr == S_OK, "ret %08x\n", hr);
7352 IXMLDOMNode_Release(pr_node);
7354 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
7355 ok( hr == S_OK, "ret %08x\n", hr);
7356 ok( len == 3, "length %d\n", len);
7358 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
7359 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7361 node = (void*)0xdeadbeef;
7362 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
7363 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7364 ok( node == (void*)0xdeadbeef, "got %p\n", node);
7366 /* out pointer is optional */
7367 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
7368 ok( hr == S_OK, "ret %08x\n", hr);
7370 /* already removed */
7371 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
7372 ok( hr == S_FALSE, "ret %08x\n", hr);
7374 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
7375 ok( hr == S_OK, "ret %08x\n", hr);
7376 IXMLDOMNode_Release(node);
7378 IXMLDOMNamedNodeMap_Release( map );
7379 IXMLDOMElement_Release( element );
7380 IXMLDOMDocument_Release( doc );
7381 free_bstrs();
7384 #define check_default_props(doc) _check_default_props(__LINE__, doc)
7385 static inline void _check_default_props(int line, IXMLDOMDocument2* doc)
7387 VARIANT_BOOL b;
7388 VARIANT var;
7389 HRESULT hr;
7391 VariantInit(&var);
7392 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
7393 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
7394 VariantClear(&var);
7396 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
7397 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("")) == 0, "expected empty string\n");
7398 VariantClear(&var);
7400 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
7401 ok_(__FILE__, line)(b == VARIANT_FALSE, "expected FALSE\n");
7403 hr = IXMLDOMDocument2_get_schemas(doc, &var);
7404 ok_(__FILE__, line)(hr == S_FALSE, "got %08x\n", hr);
7405 VariantClear(&var);
7408 #define check_set_props(doc) _check_set_props(__LINE__, doc)
7409 static inline void _check_set_props(int line, IXMLDOMDocument2* doc)
7411 VARIANT_BOOL b;
7412 VARIANT var;
7414 VariantInit(&var);
7415 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
7416 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
7417 VariantClear(&var);
7419 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
7420 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&var)));
7421 VariantClear(&var);
7423 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
7424 ok_(__FILE__, line)(b == VARIANT_TRUE, "expected TRUE\n");
7426 helper_ole_check(IXMLDOMDocument2_get_schemas(doc, &var));
7427 ok_(__FILE__, line)(V_VT(&var) != VT_NULL, "expected pointer\n");
7428 VariantClear(&var);
7431 #define set_props(doc, cache) _set_props(__LINE__, doc, cache)
7432 static inline void _set_props(int line, IXMLDOMDocument2* doc, IXMLDOMSchemaCollection* cache)
7434 VARIANT var;
7436 VariantInit(&var);
7437 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
7438 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'")));
7439 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_TRUE));
7440 V_VT(&var) = VT_DISPATCH;
7441 V_DISPATCH(&var) = NULL;
7442 helper_ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&var)));
7443 ok_(__FILE__, line)(V_DISPATCH(&var) != NULL, "expected pointer\n");
7444 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
7445 VariantClear(&var);
7448 #define unset_props(doc) _unset_props(__LINE__, doc)
7449 static inline void _unset_props(int line, IXMLDOMDocument2* doc)
7451 VARIANT var;
7453 VariantInit(&var);
7454 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
7455 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
7456 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_FALSE));
7457 V_VT(&var) = VT_NULL;
7458 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
7459 VariantClear(&var);
7462 static void test_get_ownerDocument(void)
7464 IXMLDOMDocument *doc1, *doc2, *doc3;
7465 IXMLDOMDocument2 *doc, *doc_owner;
7466 IXMLDOMNode *node;
7467 IXMLDOMSchemaCollection *cache;
7468 VARIANT_BOOL b;
7469 VARIANT var;
7470 IXMLDOMElement *element;
7471 IXMLDOMNodeList *node_list;
7472 IXMLDOMAttribute *attr;
7473 LONG i, len;
7474 HRESULT hr;
7475 const CHAR nodeXML[] =
7476 "<root id='0'>"
7477 " <!-- comment node 0 -->"
7478 " text node 0"
7479 " <x attr='val'></x>"
7480 " <?foo value='PI for x'?>"
7481 " <![CDATA[ cdata ]]>"
7482 "</root>";
7484 if (!is_clsid_supported(&CLSID_DOMDocument2, &IID_IXMLDOMDocument2)) return;
7485 if (!is_clsid_supported(&CLSID_XMLSchemaCache, &IID_IXMLDOMSchemaCollection)) return;
7487 doc = create_document(&IID_IXMLDOMDocument2);
7488 cache = create_cache(&IID_IXMLDOMSchemaCollection);
7490 VariantInit(&var);
7492 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(complete4A), &b));
7493 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7495 check_default_props(doc);
7497 /* set properties and check that new instances use them */
7498 set_props(doc, cache);
7499 check_set_props(doc);
7501 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
7502 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc1));
7504 /* new interface keeps props */
7505 ole_check(IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner));
7506 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
7507 check_set_props(doc_owner);
7508 IXMLDOMDocument2_Release(doc_owner);
7510 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc2));
7511 IXMLDOMNode_Release(node);
7513 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
7515 /* reload */
7516 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(complete4A), &b));
7517 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7519 /* properties retained even after reload */
7520 check_set_props(doc);
7522 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
7523 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc3));
7524 IXMLDOMNode_Release(node);
7526 ole_check(IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner));
7527 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
7528 check_set_props(doc_owner);
7530 /* changing properties for one instance changes them for all */
7531 unset_props(doc_owner);
7532 check_default_props(doc_owner);
7533 check_default_props(doc);
7535 /* NULL check */
7536 hr = IXMLDOMDocument_loadXML(doc1, _bstr_(nodeXML), &b);
7537 EXPECT_HR(hr, S_OK);
7538 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7540 hr = IXMLDOMDocument_get_documentElement(doc1, &element);
7541 EXPECT_HR(hr, S_OK);
7543 hr = IXMLDOMElement_get_childNodes(element, &node_list);
7544 EXPECT_HR(hr, S_OK);
7546 hr = IXMLDOMNodeList_get_length(node_list, &len);
7547 EXPECT_HR(hr, S_OK);
7549 for(i = 0; i < len; i++) {
7550 hr = IXMLDOMNodeList_get_item(node_list, i, &node);
7551 EXPECT_HR(hr, S_OK);
7553 hr = IXMLDOMNode_get_ownerDocument(node, NULL);
7554 EXPECT_HR(hr, E_INVALIDARG);
7556 IXMLDOMNode_Release(node);
7558 IXMLDOMElement_Release(element);
7560 /* Test Attribute Node */
7561 hr = IXMLDOMNodeList_get_item(node_list, 2, &node);
7562 EXPECT_HR(hr, S_OK);
7563 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&element);
7564 EXPECT_HR(hr, S_OK);
7565 IXMLDOMNode_Release(node);
7567 hr = IXMLDOMElement_getAttributeNode(element, _bstr_("attr"), &attr);
7568 EXPECT_HR(hr, S_OK);
7569 ok(attr != NULL, "attr == NULL\n");
7570 IXMLDOMElement_Release(element);
7571 hr = IXMLDOMAttribute_get_ownerDocument(attr, NULL);
7572 EXPECT_HR(hr, E_INVALIDARG);
7573 IXMLDOMAttribute_Release(attr);
7574 IXMLDOMNodeList_Release(node_list);
7576 IXMLDOMSchemaCollection_Release(cache);
7577 IXMLDOMDocument_Release(doc1);
7578 IXMLDOMDocument_Release(doc2);
7579 IXMLDOMDocument_Release(doc3);
7580 IXMLDOMDocument2_Release(doc);
7581 IXMLDOMDocument2_Release(doc_owner);
7582 free_bstrs();
7585 static void test_setAttributeNode(void)
7587 IXMLDOMDocument *doc, *doc2;
7588 IXMLDOMElement *elem, *elem2;
7589 IXMLDOMAttribute *attr, *attr2, *ret_attr;
7590 VARIANT_BOOL b;
7591 HRESULT hr;
7592 VARIANT v;
7593 BSTR str;
7594 ULONG ref1, ref2;
7596 doc = create_document(&IID_IXMLDOMDocument);
7598 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
7599 ok( hr == S_OK, "loadXML failed\n");
7600 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7602 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7603 ok( hr == S_OK, "got 0x%08x\n", hr);
7605 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
7606 ok( hr == S_OK, "got 0x%08x\n", hr);
7607 ok( elem2 != elem, "got same instance\n");
7609 ret_attr = (void*)0xdeadbeef;
7610 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
7611 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
7612 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7614 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7615 ok( hr == S_OK, "got 0x%08x\n", hr);
7617 ref1 = IXMLDOMElement_AddRef(elem);
7618 IXMLDOMElement_Release(elem);
7620 ret_attr = (void*)0xdeadbeef;
7621 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7622 ok( hr == S_OK, "got 0x%08x\n", hr);
7623 ok( ret_attr == NULL, "got %p\n", ret_attr);
7625 /* no reference added */
7626 ref2 = IXMLDOMElement_AddRef(elem);
7627 IXMLDOMElement_Release(elem);
7628 ok(ref2 == ref1, "got %d, expected %d\n", ref2, ref1);
7630 EXPECT_CHILDREN(elem);
7631 EXPECT_CHILDREN(elem2);
7633 IXMLDOMElement_Release(elem2);
7635 attr2 = NULL;
7636 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
7637 ok( hr == S_OK, "got 0x%08x\n", hr);
7638 ok( attr2 != attr, "got same instance %p\n", attr2);
7639 IXMLDOMAttribute_Release(attr2);
7641 /* try to add it another time */
7642 ret_attr = (void*)0xdeadbeef;
7643 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7644 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7645 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7647 IXMLDOMElement_Release(elem);
7649 /* initially used element is released, attribute still 'has' a container */
7650 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7651 ok( hr == S_OK, "got 0x%08x\n", hr);
7652 ret_attr = (void*)0xdeadbeef;
7653 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7654 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7655 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7656 IXMLDOMElement_Release(elem);
7658 /* add attribute already attached to another document */
7659 doc2 = create_document(&IID_IXMLDOMDocument);
7661 hr = IXMLDOMDocument_loadXML( doc2, _bstr_(complete4A), &b );
7662 ok( hr == S_OK, "loadXML failed\n");
7663 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7665 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
7666 ok( hr == S_OK, "got 0x%08x\n", hr);
7667 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
7668 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7669 IXMLDOMElement_Release(elem);
7671 IXMLDOMAttribute_Release(attr);
7673 /* create element, add attribute, see if it's copied or linked */
7674 hr = IXMLDOMDocument_createElement(doc, _bstr_("test"), &elem);
7675 ok( hr == S_OK, "got 0x%08x\n", hr);
7677 attr = NULL;
7678 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7679 ok(hr == S_OK, "got 0x%08x\n", hr);
7680 ok(attr != NULL, "got %p\n", attr);
7682 ref1 = IXMLDOMAttribute_AddRef(attr);
7683 IXMLDOMAttribute_Release(attr);
7685 V_VT(&v) = VT_BSTR;
7686 V_BSTR(&v) = _bstr_("attrvalue1");
7687 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
7688 ok( hr == S_OK, "got 0x%08x\n", hr);
7690 str = NULL;
7691 hr = IXMLDOMAttribute_get_xml(attr, &str);
7692 ok( hr == S_OK, "got 0x%08x\n", hr);
7693 ok( lstrcmpW(str, _bstr_("attr=\"attrvalue1\"")) == 0,
7694 "got %s\n", wine_dbgstr_w(str));
7695 SysFreeString(str);
7697 ret_attr = (void*)0xdeadbeef;
7698 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7699 ok(hr == S_OK, "got 0x%08x\n", hr);
7700 ok(ret_attr == NULL, "got %p\n", ret_attr);
7702 /* attribute reference increased */
7703 ref2 = IXMLDOMAttribute_AddRef(attr);
7704 IXMLDOMAttribute_Release(attr);
7705 ok(ref1 == ref2, "got %d, expected %d\n", ref2, ref1);
7707 hr = IXMLDOMElement_get_xml(elem, &str);
7708 ok( hr == S_OK, "got 0x%08x\n", hr);
7709 ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue1\"/>")) == 0,
7710 "got %s\n", wine_dbgstr_w(str));
7711 SysFreeString(str);
7713 V_VT(&v) = VT_BSTR;
7714 V_BSTR(&v) = _bstr_("attrvalue2");
7715 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
7716 ok( hr == S_OK, "got 0x%08x\n", hr);
7718 hr = IXMLDOMElement_get_xml(elem, &str);
7719 ok( hr == S_OK, "got 0x%08x\n", hr);
7720 todo_wine ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue2\"/>")) == 0,
7721 "got %s\n", wine_dbgstr_w(str));
7722 SysFreeString(str);
7724 IXMLDOMElement_Release(elem);
7725 IXMLDOMAttribute_Release(attr);
7726 IXMLDOMDocument_Release(doc2);
7727 IXMLDOMDocument_Release(doc);
7728 free_bstrs();
7731 static void test_createNode(void)
7733 IXMLDOMDocument *doc;
7734 IXMLDOMElement *elem;
7735 IXMLDOMNode *node;
7736 VARIANT v, var;
7737 BSTR prefix, str;
7738 HRESULT hr;
7739 ULONG ref;
7741 doc = create_document(&IID_IXMLDOMDocument);
7743 EXPECT_REF(doc, 1);
7745 /* reference count tests */
7746 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
7747 ok( hr == S_OK, "got 0x%08x\n", hr);
7749 /* initial reference is 2 */
7750 todo_wine {
7751 EXPECT_REF(elem, 2);
7752 ref = IXMLDOMElement_Release(elem);
7753 ok(ref == 1, "got %d\n", ref);
7754 /* it's released already, attempt to release now will crash it */
7757 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
7758 ok( hr == S_OK, "got 0x%08x\n", hr);
7759 todo_wine EXPECT_REF(elem, 2);
7760 IXMLDOMDocument_Release(doc);
7761 todo_wine EXPECT_REF(elem, 2);
7762 IXMLDOMElement_Release(elem);
7764 doc = create_document(&IID_IXMLDOMDocument);
7766 /* NODE_ELEMENT nodes */
7767 /* 1. specified namespace */
7768 V_VT(&v) = VT_I4;
7769 V_I4(&v) = NODE_ELEMENT;
7771 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
7772 ok( hr == S_OK, "got 0x%08x\n", hr);
7773 prefix = NULL;
7774 hr = IXMLDOMNode_get_prefix(node, &prefix);
7775 ok( hr == S_OK, "got 0x%08x\n", hr);
7776 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
7777 SysFreeString(prefix);
7778 IXMLDOMNode_Release(node);
7780 /* 2. default namespace */
7781 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
7782 ok( hr == S_OK, "got 0x%08x\n", hr);
7783 prefix = (void*)0xdeadbeef;
7784 hr = IXMLDOMNode_get_prefix(node, &prefix);
7785 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7786 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
7787 /* check dump */
7788 hr = IXMLDOMNode_get_xml(node, &str);
7789 ok( hr == S_OK, "got 0x%08x\n", hr);
7790 ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0,
7791 "got %s\n", wine_dbgstr_w(str));
7792 SysFreeString(str);
7794 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
7795 ok( hr == S_OK, "got 0x%08x\n", hr);
7797 V_VT(&var) = VT_BSTR;
7798 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
7799 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7800 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
7802 str = NULL;
7803 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
7804 ok( hr == S_OK, "got 0x%08x\n", hr);
7805 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
7806 SysFreeString(str);
7808 IXMLDOMElement_Release(elem);
7809 IXMLDOMNode_Release(node);
7811 IXMLDOMDocument_Release(doc);
7812 free_bstrs();
7815 static const char get_prefix_doc[] =
7816 "<?xml version=\"1.0\" ?>"
7817 "<a xmlns:ns1=\"ns1 href\" />";
7819 static void test_get_prefix(void)
7821 IXMLDOMDocumentFragment *fragment;
7822 IXMLDOMCDATASection *cdata;
7823 IXMLDOMElement *element;
7824 IXMLDOMComment *comment;
7825 IXMLDOMDocument *doc;
7826 VARIANT_BOOL b;
7827 HRESULT hr;
7828 BSTR str;
7830 doc = create_document(&IID_IXMLDOMDocument);
7832 /* nodes that can't support prefix */
7833 /* 1. document */
7834 str = (void*)0xdeadbeef;
7835 hr = IXMLDOMDocument_get_prefix(doc, &str);
7836 EXPECT_HR(hr, S_FALSE);
7837 ok(str == NULL, "got %p\n", str);
7839 hr = IXMLDOMDocument_get_prefix(doc, NULL);
7840 EXPECT_HR(hr, E_INVALIDARG);
7842 /* 2. cdata */
7843 hr = IXMLDOMDocument_createCDATASection(doc, NULL, &cdata);
7844 ok(hr == S_OK, "got %08x\n", hr );
7846 str = (void*)0xdeadbeef;
7847 hr = IXMLDOMCDATASection_get_prefix(cdata, &str);
7848 ok(hr == S_FALSE, "got %08x\n", hr);
7849 ok( str == 0, "got %p\n", str);
7851 hr = IXMLDOMCDATASection_get_prefix(cdata, NULL);
7852 ok(hr == E_INVALIDARG, "got %08x\n", hr);
7853 IXMLDOMCDATASection_Release(cdata);
7855 /* 3. comment */
7856 hr = IXMLDOMDocument_createComment(doc, NULL, &comment);
7857 ok(hr == S_OK, "got %08x\n", hr );
7859 str = (void*)0xdeadbeef;
7860 hr = IXMLDOMComment_get_prefix(comment, &str);
7861 ok(hr == S_FALSE, "got %08x\n", hr);
7862 ok( str == 0, "got %p\n", str);
7864 hr = IXMLDOMComment_get_prefix(comment, NULL);
7865 ok(hr == E_INVALIDARG, "got %08x\n", hr);
7866 IXMLDOMComment_Release(comment);
7868 /* 4. fragment */
7869 hr = IXMLDOMDocument_createDocumentFragment(doc, &fragment);
7870 ok(hr == S_OK, "got %08x\n", hr );
7872 str = (void*)0xdeadbeef;
7873 hr = IXMLDOMDocumentFragment_get_prefix(fragment, &str);
7874 ok(hr == S_FALSE, "got %08x\n", hr);
7875 ok( str == 0, "got %p\n", str);
7877 hr = IXMLDOMDocumentFragment_get_prefix(fragment, NULL);
7878 ok(hr == E_INVALIDARG, "got %08x\n", hr);
7879 IXMLDOMDocumentFragment_Release(fragment);
7881 /* no prefix */
7882 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
7883 ok( hr == S_OK, "got 0x%08x\n", hr);
7885 hr = IXMLDOMElement_get_prefix(element, NULL);
7886 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
7888 str = (void*)0xdeadbeef;
7889 hr = IXMLDOMElement_get_prefix(element, &str);
7890 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7891 ok( str == 0, "got %p\n", str);
7893 IXMLDOMElement_Release(element);
7895 /* with prefix */
7896 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
7897 ok( hr == S_OK, "got 0x%08x\n", hr);
7899 str = (void*)0xdeadbeef;
7900 hr = IXMLDOMElement_get_prefix(element, &str);
7901 ok( hr == S_OK, "got 0x%08x\n", hr);
7902 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
7903 SysFreeString(str);
7905 str = (void*)0xdeadbeef;
7906 hr = IXMLDOMElement_get_namespaceURI(element, &str);
7907 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7908 ok( str == 0, "got %p\n", str);
7910 IXMLDOMElement_Release(element);
7912 hr = IXMLDOMDocument_loadXML(doc, _bstr_(get_prefix_doc), &b);
7913 EXPECT_HR(hr, S_OK);
7915 hr = IXMLDOMDocument_get_documentElement(doc, &element);
7916 EXPECT_HR(hr, S_OK);
7918 str = (void*)0xdeadbeef;
7919 hr = IXMLDOMElement_get_prefix(element, &str);
7920 EXPECT_HR(hr, S_FALSE);
7921 ok(str == NULL, "got %p\n", str);
7923 str = (void*)0xdeadbeef;
7924 hr = IXMLDOMElement_get_namespaceURI(element, &str);
7925 EXPECT_HR(hr, S_FALSE);
7926 ok(str == NULL, "got %s\n", wine_dbgstr_w(str));
7928 IXMLDOMDocument_Release(doc);
7929 free_bstrs();
7932 static void test_selectSingleNode(void)
7934 IXMLDOMDocument *doc;
7935 IXMLDOMNodeList *list;
7936 IXMLDOMNode *node;
7937 VARIANT_BOOL b;
7938 HRESULT hr;
7939 LONG len;
7941 doc = create_document(&IID_IXMLDOMDocument);
7943 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
7944 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7946 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
7947 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7949 hr = IXMLDOMDocument_loadXML( doc, _bstr_(complete4A), &b );
7950 ok( hr == S_OK, "loadXML failed\n");
7951 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7953 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
7954 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7956 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
7957 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7959 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
7960 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7962 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
7963 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7965 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
7966 ok(hr == S_OK, "got 0x%08x\n", hr);
7967 IXMLDOMNode_Release(node);
7969 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
7970 ok(hr == S_OK, "got 0x%08x\n", hr);
7971 IXMLDOMNodeList_Release(list);
7973 list = (void*)0xdeadbeef;
7974 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
7975 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7976 ok(list == (void*)0xdeadbeef, "got %p\n", list);
7978 node = (void*)0xdeadbeef;
7979 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
7980 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7981 ok(node == 0, "got %p\n", node);
7983 list = (void*)0xdeadbeef;
7984 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
7985 ok(hr == S_OK, "got 0x%08x\n", hr);
7986 len = 1;
7987 hr = IXMLDOMNodeList_get_length(list, &len);
7988 ok(hr == S_OK, "got 0x%08x\n", hr);
7989 ok(len == 0, "got %d\n", len);
7990 IXMLDOMNodeList_Release(list);
7992 IXMLDOMDocument_Release(doc);
7993 free_bstrs();
7996 static void test_events(void)
7998 IConnectionPointContainer *conn;
7999 IConnectionPoint *point;
8000 IXMLDOMDocument *doc;
8001 HRESULT hr;
8002 VARIANT v;
8003 IDispatch *event;
8005 doc = create_document(&IID_IXMLDOMDocument);
8007 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&conn);
8008 ok(hr == S_OK, "got 0x%08x\n", hr);
8010 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IDispatch, &point);
8011 ok(hr == S_OK, "got 0x%08x\n", hr);
8012 IConnectionPoint_Release(point);
8013 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IPropertyNotifySink, &point);
8014 ok(hr == S_OK, "got 0x%08x\n", hr);
8015 IConnectionPoint_Release(point);
8016 hr = IConnectionPointContainer_FindConnectionPoint(conn, &DIID_XMLDOMDocumentEvents, &point);
8017 ok(hr == S_OK, "got 0x%08x\n", hr);
8018 IConnectionPoint_Release(point);
8020 IConnectionPointContainer_Release(conn);
8022 /* ready state callback */
8023 VariantInit(&v);
8024 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8025 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8027 event = create_dispevent();
8028 V_VT(&v) = VT_UNKNOWN;
8029 V_UNKNOWN(&v) = (IUnknown*)event;
8031 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8032 ok(hr == S_OK, "got 0x%08x\n", hr);
8033 EXPECT_REF(event, 2);
8035 V_VT(&v) = VT_DISPATCH;
8036 V_DISPATCH(&v) = event;
8038 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8039 ok(hr == S_OK, "got 0x%08x\n", hr);
8040 EXPECT_REF(event, 2);
8042 /* VT_NULL doesn't reset event handler */
8043 V_VT(&v) = VT_NULL;
8044 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8045 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
8046 EXPECT_REF(event, 2);
8048 V_VT(&v) = VT_DISPATCH;
8049 V_DISPATCH(&v) = NULL;
8051 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8052 ok(hr == S_OK, "got 0x%08x\n", hr);
8053 EXPECT_REF(event, 1);
8055 V_VT(&v) = VT_UNKNOWN;
8056 V_DISPATCH(&v) = NULL;
8057 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
8058 ok(hr == S_OK, "got 0x%08x\n", hr);
8060 IDispatch_Release(event);
8062 IXMLDOMDocument_Release(doc);
8065 static void test_createProcessingInstruction(void)
8067 static const WCHAR bodyW[] = {'t','e','s','t',0};
8068 IXMLDOMProcessingInstruction *pi;
8069 IXMLDOMDocument *doc;
8070 WCHAR buff[10];
8071 HRESULT hr;
8073 doc = create_document(&IID_IXMLDOMDocument);
8075 /* test for BSTR handling, pass broken BSTR */
8076 memcpy(&buff[2], bodyW, sizeof(bodyW));
8077 /* just a big length */
8078 *(DWORD*)buff = 0xf0f0;
8079 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("test"), &buff[2], &pi);
8080 ok(hr == S_OK, "got 0x%08x\n", hr);
8082 IXMLDOMProcessingInstruction_Release(pi);
8083 IXMLDOMDocument_Release(doc);
8086 static void test_put_nodeTypedValue(void)
8088 static const BYTE binhexdata[16] =
8089 {0,1,2,3,4,5,6,7,8,9,0xa,0xb,0xc,0xd,0xe,0xf};
8090 IXMLDOMDocument *doc;
8091 IXMLDOMElement *elem;
8092 VARIANT type, value;
8093 LONG ubound, lbound;
8094 IXMLDOMNode *node;
8095 SAFEARRAY *array;
8096 HRESULT hr;
8097 BYTE *ptr;
8098 BSTR str;
8100 doc = create_document(&IID_IXMLDOMDocument);
8102 hr = IXMLDOMDocument_createElement(doc, _bstr_("Element"), &elem);
8103 EXPECT_HR(hr, S_OK);
8105 V_VT(&type) = VT_EMPTY;
8106 hr = IXMLDOMElement_get_dataType(elem, &type);
8107 EXPECT_HR(hr, S_FALSE);
8108 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8110 /* set typed value for untyped node */
8111 V_VT(&type) = VT_I1;
8112 V_I1(&type) = 1;
8113 hr = IXMLDOMElement_put_nodeTypedValue(elem, type);
8114 EXPECT_HR(hr, S_OK);
8116 V_VT(&type) = VT_EMPTY;
8117 hr = IXMLDOMElement_get_dataType(elem, &type);
8118 EXPECT_HR(hr, S_FALSE);
8119 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8121 /* no type info stored */
8122 V_VT(&type) = VT_EMPTY;
8123 hr = IXMLDOMElement_get_nodeTypedValue(elem, &type);
8124 EXPECT_HR(hr, S_OK);
8125 ok(V_VT(&type) == VT_BSTR, "got %d, expected VT_BSTR\n", V_VT(&type));
8126 ok(memcmp(V_BSTR(&type), _bstr_("1"), 2*sizeof(WCHAR)) == 0,
8127 "got %s, expected \"1\"\n", wine_dbgstr_w(V_BSTR(&type)));
8128 VariantClear(&type);
8130 hr = IXMLDOMElement_get_firstChild(elem, &node);
8131 EXPECT_HR(hr, S_OK);
8132 hr = IXMLDOMElement_removeChild(elem, node, NULL);
8133 EXPECT_HR(hr, S_OK);
8134 IXMLDOMNode_Release(node);
8136 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)elem, NULL);
8137 EXPECT_HR(hr, S_OK);
8139 /* bin.base64 */
8140 hr = IXMLDOMElement_put_dataType(elem, _bstr_("bin.base64"));
8141 EXPECT_HR(hr, S_OK);
8143 V_VT(&value) = VT_BSTR;
8144 V_BSTR(&value) = _bstr_("ABCD");
8145 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
8146 EXPECT_HR(hr, S_OK);
8148 V_VT(&value) = VT_EMPTY;
8149 hr = IXMLDOMElement_get_nodeTypedValue(elem, &value);
8150 EXPECT_HR(hr, S_OK);
8151 ok(V_VT(&value) == (VT_UI1|VT_ARRAY), "got %d\n", V_VT(&value));
8152 ok(SafeArrayGetDim(V_ARRAY(&value)) == 1, "got wrong dimension\n");
8153 ubound = 0;
8154 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
8155 EXPECT_HR(hr, S_OK);
8156 ok(ubound == 2, "got %d\n", ubound);
8157 lbound = 0;
8158 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
8159 EXPECT_HR(hr, S_OK);
8160 ok(lbound == 0, "got %d\n", lbound);
8161 hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
8162 EXPECT_HR(hr, S_OK);
8163 ok(ptr[0] == 0, "got %x\n", ptr[0]);
8164 ok(ptr[1] == 0x10, "got %x\n", ptr[1]);
8165 ok(ptr[2] == 0x83, "got %x\n", ptr[2]);
8166 SafeArrayUnaccessData(V_ARRAY(&value));
8167 VariantClear(&value);
8169 /* when set as VT_BSTR it's stored as is */
8170 hr = IXMLDOMElement_get_firstChild(elem, &node);
8171 EXPECT_HR(hr, S_OK);
8172 hr = IXMLDOMNode_get_text(node, &str);
8173 EXPECT_HR(hr, S_OK);
8174 ok(!lstrcmpW(str, _bstr_("ABCD")), "%s\n", wine_dbgstr_w(str));
8175 IXMLDOMNode_Release(node);
8176 SysFreeString(str);
8178 array = SafeArrayCreateVector(VT_UI1, 0, 7);
8179 hr = SafeArrayAccessData(array, (void*)&ptr);
8180 EXPECT_HR(hr, S_OK);
8181 memcpy(ptr, "dGVzdA=", strlen("dGVzdA="));
8182 SafeArrayUnaccessData(array);
8184 V_VT(&value) = VT_UI1|VT_ARRAY;
8185 V_ARRAY(&value) = array;
8186 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
8187 EXPECT_HR(hr, S_OK);
8189 V_VT(&value) = VT_EMPTY;
8190 hr = IXMLDOMElement_get_nodeTypedValue(elem, &value);
8191 EXPECT_HR(hr, S_OK);
8192 ok(V_VT(&value) == (VT_UI1|VT_ARRAY), "got %d\n", V_VT(&value));
8193 ok(SafeArrayGetDim(V_ARRAY(&value)) == 1, "got wrong dimension\n");
8194 ubound = 0;
8195 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
8196 EXPECT_HR(hr, S_OK);
8197 ok(ubound == 6, "got %d\n", ubound);
8198 lbound = 0;
8199 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
8200 EXPECT_HR(hr, S_OK);
8201 ok(lbound == 0, "got %d\n", lbound);
8202 hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
8203 EXPECT_HR(hr, S_OK);
8204 ok(!memcmp(ptr, "dGVzdA=", strlen("dGVzdA=")), "got wrong data, %s\n", ptr);
8205 SafeArrayUnaccessData(V_ARRAY(&value));
8206 VariantClear(&value);
8208 /* if set with VT_UI1|VT_ARRAY it's encoded */
8209 hr = IXMLDOMElement_get_firstChild(elem, &node);
8210 EXPECT_HR(hr, S_OK);
8211 hr = IXMLDOMNode_get_text(node, &str);
8212 EXPECT_HR(hr, S_OK);
8213 ok(!lstrcmpW(str, _bstr_("ZEdWemRBPQ==")), "%s\n", wine_dbgstr_w(str));
8214 IXMLDOMNode_Release(node);
8215 SafeArrayDestroyData(array);
8216 SysFreeString(str);
8218 /* bin.hex */
8219 V_VT(&value) = VT_BSTR;
8220 V_BSTR(&value) = _bstr_("");
8221 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
8222 EXPECT_HR(hr, S_OK);
8224 hr = IXMLDOMElement_put_dataType(elem, _bstr_("bin.hex"));
8225 EXPECT_HR(hr, S_OK);
8227 array = SafeArrayCreateVector(VT_UI1, 0, 16);
8228 hr = SafeArrayAccessData(array, (void*)&ptr);
8229 EXPECT_HR(hr, S_OK);
8230 memcpy(ptr, binhexdata, sizeof(binhexdata));
8231 SafeArrayUnaccessData(array);
8233 V_VT(&value) = VT_UI1|VT_ARRAY;
8234 V_ARRAY(&value) = array;
8235 hr = IXMLDOMElement_put_nodeTypedValue(elem, value);
8236 EXPECT_HR(hr, S_OK);
8238 V_VT(&value) = VT_EMPTY;
8239 hr = IXMLDOMElement_get_nodeTypedValue(elem, &value);
8240 EXPECT_HR(hr, S_OK);
8241 ok(V_VT(&value) == (VT_UI1|VT_ARRAY), "got %d\n", V_VT(&value));
8242 ok(SafeArrayGetDim(V_ARRAY(&value)) == 1, "got wrong dimension\n");
8243 ubound = 0;
8244 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
8245 EXPECT_HR(hr, S_OK);
8246 ok(ubound == 15, "got %d\n", ubound);
8247 lbound = 0;
8248 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
8249 EXPECT_HR(hr, S_OK);
8250 ok(lbound == 0, "got %d\n", lbound);
8251 hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
8252 EXPECT_HR(hr, S_OK);
8253 ok(!memcmp(ptr, binhexdata, sizeof(binhexdata)), "got wrong data\n");
8254 SafeArrayUnaccessData(V_ARRAY(&value));
8255 VariantClear(&value);
8257 /* if set with VT_UI1|VT_ARRAY it's encoded */
8258 hr = IXMLDOMElement_get_firstChild(elem, &node);
8259 EXPECT_HR(hr, S_OK);
8260 hr = IXMLDOMNode_get_text(node, &str);
8261 EXPECT_HR(hr, S_OK);
8262 ok(!lstrcmpW(str, _bstr_("000102030405060708090a0b0c0d0e0f")), "%s\n", wine_dbgstr_w(str));
8263 IXMLDOMNode_Release(node);
8264 SafeArrayDestroyData(array);
8265 SysFreeString(str);
8267 IXMLDOMElement_Release(elem);
8268 IXMLDOMDocument_Release(doc);
8269 free_bstrs();
8272 static void test_get_xml(void)
8274 static const char xmlA[] = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<a>test</a>\r\n";
8275 static const char attrA[] = "attr=\"&quot;a &amp; b&quot;\"";
8276 static const char attr2A[] = "\"a & b\"";
8277 static const char attr3A[] = "attr=\"&amp;quot;a\"";
8278 static const char attr4A[] = "&quot;a";
8279 static const char fooA[] = "<foo/>";
8280 IXMLDOMProcessingInstruction *pi;
8281 IXMLDOMNode *first;
8282 IXMLDOMElement *elem = NULL;
8283 IXMLDOMAttribute *attr;
8284 IXMLDOMDocument *doc;
8285 VARIANT_BOOL b;
8286 VARIANT v;
8287 BSTR xml;
8288 HRESULT hr;
8290 doc = create_document(&IID_IXMLDOMDocument);
8292 b = VARIANT_TRUE;
8293 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
8294 ok(hr == S_OK, "got 0x%08x\n", hr);
8295 ok( b == VARIANT_TRUE, "got %d\n", b);
8297 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"),
8298 _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &pi);
8299 ok(hr == S_OK, "got 0x%08x\n", hr);
8301 hr = IXMLDOMDocument_get_firstChild(doc, &first);
8302 ok(hr == S_OK, "got 0x%08x\n", hr);
8304 V_UNKNOWN(&v) = (IUnknown*)first;
8305 V_VT(&v) = VT_UNKNOWN;
8307 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)pi, v, NULL);
8308 ok(hr == S_OK, "got 0x%08x\n", hr);
8310 IXMLDOMProcessingInstruction_Release(pi);
8311 IXMLDOMNode_Release(first);
8313 hr = IXMLDOMDocument_get_xml(doc, &xml);
8314 ok(hr == S_OK, "got 0x%08x\n", hr);
8316 ok(memcmp(xml, _bstr_(xmlA), sizeof(xmlA)*sizeof(WCHAR)) == 0,
8317 "got %s, expected %s\n", wine_dbgstr_w(xml), xmlA);
8318 SysFreeString(xml);
8320 IXMLDOMDocument_Release(doc);
8322 doc = create_document(&IID_IXMLDOMDocument);
8324 hr = IXMLDOMDocument_createElement(doc, _bstr_("foo"), &elem);
8325 ok(hr == S_OK, "got 0x%08x\n", hr);
8327 hr = IXMLDOMDocument_putref_documentElement(doc, elem);
8328 ok(hr == S_OK, "got 0x%08x\n", hr);
8330 hr = IXMLDOMDocument_get_xml(doc, &xml);
8331 ok(hr == S_OK, "got 0x%08x\n", hr);
8333 ok(memcmp(xml, _bstr_(fooA), (sizeof(fooA)-1)*sizeof(WCHAR)) == 0,
8334 "got %s, expected %s\n", wine_dbgstr_w(xml), fooA);
8335 SysFreeString(xml);
8337 IXMLDOMElement_Release(elem);
8339 /* attribute node */
8340 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
8341 ok(hr == S_OK, "got 0x%08x\n", hr);
8343 V_VT(&v) = VT_BSTR;
8344 V_BSTR(&v) = _bstr_("\"a & b\"");
8345 hr = IXMLDOMAttribute_put_value(attr, v);
8346 ok(hr == S_OK, "got 0x%08x\n", hr);
8348 xml = NULL;
8349 hr = IXMLDOMAttribute_get_xml(attr, &xml);
8350 ok(hr == S_OK, "got 0x%08x\n", hr);
8351 ok(!memcmp(xml, _bstr_(attrA), (sizeof(attrA)-1)*sizeof(WCHAR)), "got %s\n", wine_dbgstr_w(xml));
8352 SysFreeString(xml);
8354 VariantInit(&v);
8355 hr = IXMLDOMAttribute_get_value(attr, &v);
8356 ok(hr == S_OK, "got 0x%08x\n", hr);
8357 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
8358 ok(!memcmp(V_BSTR(&v), _bstr_(attr2A), (sizeof(attr2A)-1)*sizeof(WCHAR)),
8359 "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8360 VariantClear(&v);
8362 V_VT(&v) = VT_BSTR;
8363 V_BSTR(&v) = _bstr_("&quot;a");
8364 hr = IXMLDOMAttribute_put_value(attr, v);
8365 ok(hr == S_OK, "got 0x%08x\n", hr);
8367 xml = NULL;
8368 hr = IXMLDOMAttribute_get_xml(attr, &xml);
8369 ok(hr == S_OK, "got 0x%08x\n", hr);
8370 ok(!memcmp(xml, _bstr_(attr3A), (sizeof(attr3A)-1)*sizeof(WCHAR)), "got %s\n", wine_dbgstr_w(xml));
8371 SysFreeString(xml);
8373 VariantInit(&v);
8374 hr = IXMLDOMAttribute_get_value(attr, &v);
8375 ok(hr == S_OK, "got 0x%08x\n", hr);
8376 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
8377 ok(!memcmp(V_BSTR(&v), _bstr_(attr4A), (sizeof(attr4A)-1)*sizeof(WCHAR)),
8378 "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8379 VariantClear(&v);
8381 IXMLDOMAttribute_Release(attr);
8383 IXMLDOMDocument_Release(doc);
8385 free_bstrs();
8388 static void test_xsltemplate(void)
8390 IXSLTemplate *template;
8391 IXSLProcessor *processor;
8392 IXMLDOMDocument *doc, *doc2;
8393 IStream *stream;
8394 VARIANT_BOOL b;
8395 HRESULT hr;
8396 ULONG ref1, ref2;
8397 VARIANT v;
8399 if (!is_clsid_supported(&CLSID_XSLTemplate, &IID_IXSLTemplate)) return;
8400 template = create_xsltemplate(&IID_IXSLTemplate);
8402 /* works as reset */
8403 hr = IXSLTemplate_putref_stylesheet(template, NULL);
8404 ok(hr == S_OK, "got 0x%08x\n", hr);
8406 doc = create_document(&IID_IXMLDOMDocument);
8408 b = VARIANT_TRUE;
8409 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
8410 ok(hr == S_OK, "got 0x%08x\n", hr);
8411 ok( b == VARIANT_TRUE, "got %d\n", b);
8413 /* putref with non-xsl document */
8414 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
8415 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
8417 b = VARIANT_TRUE;
8418 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
8419 ok(hr == S_OK, "got 0x%08x\n", hr);
8420 ok( b == VARIANT_TRUE, "got %d\n", b);
8422 /* not a freethreaded document */
8423 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
8424 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
8426 IXMLDOMDocument_Release(doc);
8428 if (!is_clsid_supported(&CLSID_FreeThreadedDOMDocument, &IID_IXMLDOMDocument))
8430 IXSLTemplate_Release(template);
8431 return;
8434 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
8435 ok(hr == S_OK, "got 0x%08x\n", hr);
8437 b = VARIANT_TRUE;
8438 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
8439 ok(hr == S_OK, "got 0x%08x\n", hr);
8440 ok( b == VARIANT_TRUE, "got %d\n", b);
8442 /* freethreaded document */
8443 ref1 = IXMLDOMDocument_AddRef(doc);
8444 IXMLDOMDocument_Release(doc);
8445 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
8446 ok(hr == S_OK, "got 0x%08x\n", hr);
8447 ref2 = IXMLDOMDocument_AddRef(doc);
8448 IXMLDOMDocument_Release(doc);
8449 ok(ref2 > ref1, "got %d\n", ref2);
8451 /* processor */
8452 hr = IXSLTemplate_createProcessor(template, NULL);
8453 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8455 EXPECT_REF(template, 1);
8456 hr = IXSLTemplate_createProcessor(template, &processor);
8457 ok(hr == S_OK, "got 0x%08x\n", hr);
8458 EXPECT_REF(template, 2);
8460 /* input no set yet */
8461 V_VT(&v) = VT_BSTR;
8462 V_BSTR(&v) = NULL;
8463 hr = IXSLProcessor_get_input(processor, &v);
8464 todo_wine {
8465 ok(hr == S_OK, "got 0x%08x\n", hr);
8466 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
8469 hr = IXSLProcessor_get_output(processor, NULL);
8470 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8472 /* reset before it was set */
8473 V_VT(&v) = VT_EMPTY;
8474 hr = IXSLProcessor_put_output(processor, v);
8475 ok(hr == S_OK, "got 0x%08x\n", hr);
8477 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
8478 ok(hr == S_OK, "got 0x%08x\n", hr);
8479 EXPECT_REF(stream, 1);
8481 V_VT(&v) = VT_UNKNOWN;
8482 V_UNKNOWN(&v) = (IUnknown*)stream;
8483 hr = IXSLProcessor_put_output(processor, v);
8484 ok(hr == S_OK, "got 0x%08x\n", hr);
8486 /* it seems processor grabs 2 references */
8487 todo_wine EXPECT_REF(stream, 3);
8489 V_VT(&v) = VT_EMPTY;
8490 hr = IXSLProcessor_get_output(processor, &v);
8491 ok(hr == S_OK, "got 0x%08x\n", hr);
8492 ok(V_VT(&v) == VT_UNKNOWN, "got type %d\n", V_VT(&v));
8493 ok(V_UNKNOWN(&v) == (IUnknown*)stream, "got %p\n", V_UNKNOWN(&v));
8495 todo_wine EXPECT_REF(stream, 4);
8496 VariantClear(&v);
8498 hr = IXSLProcessor_transform(processor, NULL);
8499 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8501 /* reset and check stream refcount */
8502 V_VT(&v) = VT_EMPTY;
8503 hr = IXSLProcessor_put_output(processor, v);
8504 ok(hr == S_OK, "got 0x%08x\n", hr);
8506 EXPECT_REF(stream, 1);
8508 IStream_Release(stream);
8510 /* no output interface set, check output */
8511 doc2 = create_document(&IID_IXMLDOMDocument);
8513 b = VARIANT_TRUE;
8514 hr = IXMLDOMDocument_loadXML( doc2, _bstr_("<a>test</a>"), &b );
8515 ok(hr == S_OK, "got 0x%08x\n", hr);
8516 ok( b == VARIANT_TRUE, "got %d\n", b);
8518 V_VT(&v) = VT_UNKNOWN;
8519 V_UNKNOWN(&v) = (IUnknown*)doc2;
8520 hr = IXSLProcessor_put_input(processor, v);
8521 ok(hr == S_OK, "got 0x%08x\n", hr);
8523 hr = IXSLProcessor_transform(processor, &b);
8524 ok(hr == S_OK, "got 0x%08x\n", hr);
8526 V_VT(&v) = VT_EMPTY;
8527 hr = IXSLProcessor_get_output(processor, &v);
8528 ok(hr == S_OK, "got 0x%08x\n", hr);
8529 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
8530 ok(*V_BSTR(&v) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8531 IXMLDOMDocument_Release(doc2);
8532 VariantClear(&v);
8534 IXSLProcessor_Release(processor);
8536 /* drop reference */
8537 hr = IXSLTemplate_putref_stylesheet(template, NULL);
8538 ok(hr == S_OK, "got 0x%08x\n", hr);
8539 ref2 = IXMLDOMDocument_AddRef(doc);
8540 IXMLDOMDocument_Release(doc);
8541 ok(ref2 == ref1, "got %d\n", ref2);
8543 IXMLDOMDocument_Release(doc);
8544 IXSLTemplate_Release(template);
8545 free_bstrs();
8548 static void test_insertBefore(void)
8550 IXMLDOMDocument *doc, *doc2, *doc3;
8551 IXMLDOMAttribute *attr;
8552 IXMLDOMElement *elem1, *elem2, *elem3, *elem4, *elem5;
8553 IXMLDOMNode *node, *newnode, *cdata;
8554 HRESULT hr;
8555 VARIANT v;
8556 BSTR p;
8558 doc = create_document(&IID_IXMLDOMDocument);
8559 doc3 = create_document(&IID_IXMLDOMDocument);
8561 /* document to document */
8562 V_VT(&v) = VT_NULL;
8563 node = (void*)0xdeadbeef;
8564 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)doc3, v, &node);
8565 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8566 ok(node == NULL, "got %p\n", node);
8568 /* document to itself */
8569 V_VT(&v) = VT_NULL;
8570 node = (void*)0xdeadbeef;
8571 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)doc, v, &node);
8572 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8573 ok(node == NULL, "got %p\n", node);
8575 /* insertBefore behaviour for attribute node */
8576 V_VT(&v) = VT_I4;
8577 V_I4(&v) = NODE_ATTRIBUTE;
8579 attr = NULL;
8580 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr"), NULL, (IXMLDOMNode**)&attr);
8581 ok(hr == S_OK, "got 0x%08x\n", hr);
8582 ok(attr != NULL, "got %p\n", attr);
8584 /* attribute to document */
8585 V_VT(&v) = VT_NULL;
8586 node = (void*)0xdeadbeef;
8587 hr = IXMLDOMDocument_insertBefore(doc3, (IXMLDOMNode*)attr, v, &node);
8588 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8589 ok(node == NULL, "got %p\n", node);
8591 /* cdata to document */
8592 V_VT(&v) = VT_I4;
8593 V_I4(&v) = NODE_CDATA_SECTION;
8595 cdata = NULL;
8596 hr = IXMLDOMDocument_createNode(doc3, v, _bstr_("cdata"), NULL, &cdata);
8597 ok(hr == S_OK, "got 0x%08x\n", hr);
8598 ok(cdata != NULL, "got %p\n", cdata);
8600 EXPECT_NO_CHILDREN(cdata);
8602 /* attribute to cdata */
8603 V_VT(&v) = VT_NULL;
8604 node = (void*)0xdeadbeef;
8605 hr = IXMLDOMNode_insertBefore(cdata, (IXMLDOMNode*)attr, v, &node);
8606 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8607 ok(node == NULL, "got %p\n", node);
8609 /* document to cdata */
8610 V_VT(&v) = VT_NULL;
8611 node = (void*)0xdeadbeef;
8612 hr = IXMLDOMNode_insertBefore(cdata, (IXMLDOMNode*)doc, v, &node);
8613 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8614 ok(node == NULL, "got %p\n", node);
8616 V_VT(&v) = VT_NULL;
8617 node = (void*)0xdeadbeef;
8618 hr = IXMLDOMDocument_insertBefore(doc3, cdata, v, &node);
8619 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8620 ok(node == NULL, "got %p\n", node);
8622 IXMLDOMNode_Release(cdata);
8623 IXMLDOMDocument_Release(doc3);
8625 /* attribute to attribute */
8626 V_VT(&v) = VT_I4;
8627 V_I4(&v) = NODE_ATTRIBUTE;
8628 newnode = NULL;
8629 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr2"), NULL, &newnode);
8630 ok(hr == S_OK, "got 0x%08x\n", hr);
8631 ok(newnode != NULL, "got %p\n", newnode);
8633 V_VT(&v) = VT_NULL;
8634 node = (void*)0xdeadbeef;
8635 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8636 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8637 ok(node == NULL, "got %p\n", node);
8639 V_VT(&v) = VT_UNKNOWN;
8640 V_UNKNOWN(&v) = (IUnknown*)attr;
8641 node = (void*)0xdeadbeef;
8642 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8643 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8644 ok(node == NULL, "got %p\n", node);
8645 IXMLDOMNode_Release(newnode);
8647 /* cdata to attribute */
8648 V_VT(&v) = VT_I4;
8649 V_I4(&v) = NODE_CDATA_SECTION;
8650 newnode = NULL;
8651 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8652 ok(hr == S_OK, "got 0x%08x\n", hr);
8653 ok(newnode != NULL, "got %p\n", newnode);
8655 V_VT(&v) = VT_NULL;
8656 node = (void*)0xdeadbeef;
8657 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8658 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8659 ok(node == NULL, "got %p\n", node);
8660 IXMLDOMNode_Release(newnode);
8662 /* comment to attribute */
8663 V_VT(&v) = VT_I4;
8664 V_I4(&v) = NODE_COMMENT;
8665 newnode = NULL;
8666 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8667 ok(hr == S_OK, "got 0x%08x\n", hr);
8668 ok(newnode != NULL, "got %p\n", newnode);
8670 V_VT(&v) = VT_NULL;
8671 node = (void*)0xdeadbeef;
8672 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8673 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8674 ok(node == NULL, "got %p\n", node);
8675 IXMLDOMNode_Release(newnode);
8677 /* element to attribute */
8678 V_VT(&v) = VT_I4;
8679 V_I4(&v) = NODE_ELEMENT;
8680 newnode = NULL;
8681 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8682 ok(hr == S_OK, "got 0x%08x\n", hr);
8683 ok(newnode != NULL, "got %p\n", newnode);
8685 V_VT(&v) = VT_NULL;
8686 node = (void*)0xdeadbeef;
8687 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8688 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8689 ok(node == NULL, "got %p\n", node);
8690 IXMLDOMNode_Release(newnode);
8692 /* pi to attribute */
8693 V_VT(&v) = VT_I4;
8694 V_I4(&v) = NODE_PROCESSING_INSTRUCTION;
8695 newnode = NULL;
8696 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8697 ok(hr == S_OK, "got 0x%08x\n", hr);
8698 ok(newnode != NULL, "got %p\n", newnode);
8700 V_VT(&v) = VT_NULL;
8701 node = (void*)0xdeadbeef;
8702 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8703 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8704 ok(node == NULL, "got %p\n", node);
8705 IXMLDOMNode_Release(newnode);
8706 IXMLDOMAttribute_Release(attr);
8708 /* insertBefore for elements */
8709 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem1);
8710 ok(hr == S_OK, "got 0x%08x\n", hr);
8712 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem2"), &elem2);
8713 ok(hr == S_OK, "got 0x%08x\n", hr);
8715 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
8716 ok(hr == S_OK, "got 0x%08x\n", hr);
8718 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
8719 ok(hr == S_OK, "got 0x%08x\n", hr);
8721 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem4"), &elem4);
8722 ok(hr == S_OK, "got 0x%08x\n", hr);
8724 EXPECT_NO_CHILDREN(elem1);
8725 EXPECT_NO_CHILDREN(elem2);
8726 EXPECT_NO_CHILDREN(elem3);
8728 todo_wine EXPECT_REF(elem2, 2);
8730 /* document to element */
8731 V_VT(&v) = VT_DISPATCH;
8732 V_DISPATCH(&v) = NULL;
8733 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)doc, v, NULL);
8734 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8736 V_VT(&v) = VT_DISPATCH;
8737 V_DISPATCH(&v) = NULL;
8738 node = NULL;
8739 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem4, v, &node);
8740 ok(hr == S_OK, "got 0x%08x\n", hr);
8741 ok(node == (void*)elem4, "got %p\n", node);
8743 EXPECT_CHILDREN(elem1);
8744 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem4, NULL);
8745 EXPECT_HR(hr, S_OK);
8746 IXMLDOMElement_Release(elem4);
8748 EXPECT_NO_CHILDREN(elem1);
8750 V_VT(&v) = VT_NULL;
8751 node = NULL;
8752 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
8753 ok(hr == S_OK, "got 0x%08x\n", hr);
8754 ok(node == (void*)elem2, "got %p\n", node);
8756 EXPECT_CHILDREN(elem1);
8757 todo_wine EXPECT_REF(elem2, 3);
8758 IXMLDOMNode_Release(node);
8760 /* again for already linked node */
8761 V_VT(&v) = VT_NULL;
8762 node = NULL;
8763 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
8764 ok(hr == S_OK, "got 0x%08x\n", hr);
8765 ok(node == (void*)elem2, "got %p\n", node);
8767 EXPECT_CHILDREN(elem1);
8769 /* increments each time */
8770 todo_wine EXPECT_REF(elem2, 3);
8771 IXMLDOMNode_Release(node);
8773 /* try to add to another element */
8774 V_VT(&v) = VT_NULL;
8775 node = (void*)0xdeadbeef;
8776 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem2, v, &node);
8777 ok(hr == S_OK, "got 0x%08x\n", hr);
8778 ok(node == (void*)elem2, "got %p\n", node);
8780 EXPECT_CHILDREN(elem3);
8781 EXPECT_NO_CHILDREN(elem1);
8783 IXMLDOMNode_Release(node);
8785 /* cross document case - try to add as child to a node created with other doc */
8786 doc2 = create_document(&IID_IXMLDOMDocument);
8788 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem4);
8789 ok(hr == S_OK, "got 0x%08x\n", hr);
8790 todo_wine EXPECT_REF(elem4, 2);
8792 /* same name, another instance */
8793 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem5);
8794 ok(hr == S_OK, "got 0x%08x\n", hr);
8795 todo_wine EXPECT_REF(elem5, 2);
8797 todo_wine EXPECT_REF(elem3, 2);
8798 V_VT(&v) = VT_NULL;
8799 node = NULL;
8800 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem4, v, &node);
8801 ok(hr == S_OK, "got 0x%08x\n", hr);
8802 ok(node == (void*)elem4, "got %p\n", node);
8803 todo_wine EXPECT_REF(elem4, 3);
8804 todo_wine EXPECT_REF(elem3, 2);
8805 IXMLDOMNode_Release(node);
8807 V_VT(&v) = VT_NULL;
8808 node = NULL;
8809 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem5, v, &node);
8810 ok(hr == S_OK, "got 0x%08x\n", hr);
8811 ok(node == (void*)elem5, "got %p\n", node);
8812 todo_wine EXPECT_REF(elem4, 2);
8813 todo_wine EXPECT_REF(elem5, 3);
8814 IXMLDOMNode_Release(node);
8816 IXMLDOMDocument_Release(doc2);
8818 IXMLDOMElement_Release(elem1);
8819 IXMLDOMElement_Release(elem2);
8820 IXMLDOMElement_Release(elem3);
8821 IXMLDOMElement_Release(elem4);
8822 IXMLDOMElement_Release(elem5);
8824 /* elements with same default namespace */
8825 V_VT(&v) = VT_I4;
8826 V_I4(&v) = NODE_ELEMENT;
8827 elem1 = NULL;
8828 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
8829 ok(hr == S_OK, "got 0x%08x\n", hr);
8830 ok(elem1 != NULL, "got %p\n", elem1);
8832 V_VT(&v) = VT_I4;
8833 V_I4(&v) = NODE_ELEMENT;
8834 elem2 = NULL;
8835 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem2);
8836 ok(hr == S_OK, "got 0x%08x\n", hr);
8837 ok(elem2 != NULL, "got %p\n", elem2);
8839 /* check contents so far */
8840 p = NULL;
8841 hr = IXMLDOMElement_get_xml(elem1, &p);
8842 ok(hr == S_OK, "got 0x%08x\n", hr);
8843 ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
8844 SysFreeString(p);
8846 p = NULL;
8847 hr = IXMLDOMElement_get_xml(elem2, &p);
8848 ok(hr == S_OK, "got 0x%08x\n", hr);
8849 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
8850 SysFreeString(p);
8852 V_VT(&v) = VT_NULL;
8853 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
8854 ok(hr == S_OK, "got 0x%08x\n", hr);
8856 /* get_xml depends on context, for top node it omits child namespace attribute,
8857 but at child level it's still returned */
8858 p = NULL;
8859 hr = IXMLDOMElement_get_xml(elem1, &p);
8860 ok(hr == S_OK, "got 0x%08x\n", hr);
8861 todo_wine ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"><elem2/></elem1>")),
8862 "got %s\n", wine_dbgstr_w(p));
8863 SysFreeString(p);
8865 p = NULL;
8866 hr = IXMLDOMElement_get_xml(elem2, &p);
8867 ok(hr == S_OK, "got 0x%08x\n", hr);
8868 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
8869 SysFreeString(p);
8871 IXMLDOMElement_Release(elem1);
8872 IXMLDOMElement_Release(elem2);
8874 /* child without default namespace added to node with default namespace */
8875 V_VT(&v) = VT_I4;
8876 V_I4(&v) = NODE_ELEMENT;
8877 elem1 = NULL;
8878 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
8879 ok(hr == S_OK, "got 0x%08x\n", hr);
8880 ok(elem1 != NULL, "got %p\n", elem1);
8882 V_VT(&v) = VT_I4;
8883 V_I4(&v) = NODE_ELEMENT;
8884 elem2 = NULL;
8885 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), NULL, (IXMLDOMNode**)&elem2);
8886 ok(hr == S_OK, "got 0x%08x\n", hr);
8887 ok(elem2 != NULL, "got %p\n", elem2);
8889 EXPECT_REF(elem2, 1);
8890 V_VT(&v) = VT_NULL;
8891 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
8892 ok(hr == S_OK, "got 0x%08x\n", hr);
8893 EXPECT_REF(elem2, 1);
8895 p = NULL;
8896 hr = IXMLDOMElement_get_xml(elem2, &p);
8897 ok(hr == S_OK, "got 0x%08x\n", hr);
8898 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
8899 SysFreeString(p);
8901 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem2, NULL);
8902 ok(hr == S_OK, "got 0x%08x\n", hr);
8904 p = NULL;
8905 hr = IXMLDOMElement_get_xml(elem2, &p);
8906 ok(hr == S_OK, "got 0x%08x\n", hr);
8907 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
8908 SysFreeString(p);
8910 IXMLDOMElement_Release(elem1);
8911 IXMLDOMElement_Release(elem2);
8912 IXMLDOMDocument_Release(doc);
8915 static void test_appendChild(void)
8917 IXMLDOMDocument *doc, *doc2;
8918 IXMLDOMElement *elem, *elem2;
8919 HRESULT hr;
8921 doc = create_document(&IID_IXMLDOMDocument);
8922 doc2 = create_document(&IID_IXMLDOMDocument);
8924 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8925 ok(hr == S_OK, "got 0x%08x\n", hr);
8927 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem2"), &elem2);
8928 ok(hr == S_OK, "got 0x%08x\n", hr);
8930 EXPECT_REF(doc, 1);
8931 todo_wine EXPECT_REF(elem, 2);
8932 EXPECT_REF(doc2, 1);
8933 todo_wine EXPECT_REF(elem2, 2);
8934 EXPECT_NO_CHILDREN(doc);
8935 EXPECT_NO_CHILDREN(doc2);
8937 hr = IXMLDOMDocument_appendChild(doc2, NULL, NULL);
8938 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8940 hr = IXMLDOMElement_appendChild(elem, NULL, NULL);
8941 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8943 /* append from another document */
8944 hr = IXMLDOMDocument_appendChild(doc2, (IXMLDOMNode*)elem, NULL);
8945 ok(hr == S_OK, "got 0x%08x\n", hr);
8947 EXPECT_REF(doc, 1);
8948 todo_wine EXPECT_REF(elem, 2);
8949 EXPECT_REF(doc2, 1);
8950 todo_wine EXPECT_REF(elem2, 2);
8951 EXPECT_NO_CHILDREN(doc);
8952 EXPECT_CHILDREN(doc2);
8954 IXMLDOMElement_Release(elem);
8955 IXMLDOMElement_Release(elem2);
8956 IXMLDOMDocument_Release(doc);
8957 IXMLDOMDocument_Release(doc2);
8960 static void test_get_doctype(void)
8962 static const WCHAR emailW[] = {'e','m','a','i','l',0};
8963 IXMLDOMDocumentType *doctype;
8964 IXMLDOMDocument *doc;
8965 VARIANT_BOOL b;
8966 HRESULT hr;
8967 BSTR s;
8969 doc = create_document(&IID_IXMLDOMDocument);
8971 hr = IXMLDOMDocument_get_doctype(doc, NULL);
8972 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8974 doctype = (void*)0xdeadbeef;
8975 hr = IXMLDOMDocument_get_doctype(doc, &doctype);
8976 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8977 ok(doctype == NULL, "got %p\n", doctype);
8979 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szEmailXML), &b);
8980 ok(b == VARIANT_TRUE, "failed to load XML string\n");
8982 doctype = NULL;
8983 hr = IXMLDOMDocument_get_doctype(doc, &doctype);
8984 ok(hr == S_OK, "got 0x%08x\n", hr);
8985 ok(doctype != NULL, "got %p\n", doctype);
8987 hr = IXMLDOMDocumentType_get_name(doctype, NULL);
8988 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8990 hr = IXMLDOMDocumentType_get_name(doctype, &s);
8991 ok(hr == S_OK, "got 0x%08x\n", hr);
8992 ok(!lstrcmpW(emailW, s), "got name %s\n", wine_dbgstr_w(s));
8993 SysFreeString(s);
8995 hr = IXMLDOMDocumentType_get_nodeName(doctype, &s);
8996 ok(hr == S_OK, "got 0x%08x\n", hr);
8997 ok(!lstrcmpW(emailW, s), "got name %s\n", wine_dbgstr_w(s));
8998 SysFreeString(s);
9000 IXMLDOMDocumentType_Release(doctype);
9001 IXMLDOMDocument_Release(doc);
9004 static void test_get_tagName(void)
9006 IXMLDOMDocument *doc;
9007 IXMLDOMElement *elem, *elem2;
9008 HRESULT hr;
9009 BSTR str;
9011 doc = create_document(&IID_IXMLDOMDocument);
9013 hr = IXMLDOMDocument_createElement(doc, _bstr_("element"), &elem);
9014 ok(hr == S_OK, "got 0x%08x\n", hr);
9016 hr = IXMLDOMElement_get_tagName(elem, NULL);
9017 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9019 str = NULL;
9020 hr = IXMLDOMElement_get_tagName(elem, &str);
9021 ok(hr == S_OK, "got 0x%08x\n", hr);
9022 ok(!lstrcmpW(str, _bstr_("element")), "got %s\n", wine_dbgstr_w(str));
9023 SysFreeString(str);
9025 hr = IXMLDOMDocument_createElement(doc, _bstr_("s:element"), &elem2);
9026 ok(hr == S_OK, "got 0x%08x\n", hr);
9028 str = NULL;
9029 hr = IXMLDOMElement_get_tagName(elem2, &str);
9030 ok(hr == S_OK, "got 0x%08x\n", hr);
9031 ok(!lstrcmpW(str, _bstr_("s:element")), "got %s\n", wine_dbgstr_w(str));
9032 SysFreeString(str);
9034 IXMLDOMElement_Release(elem);
9035 IXMLDOMElement_Release(elem2);
9036 IXMLDOMDocument_Release(doc);
9037 free_bstrs();
9040 typedef struct {
9041 DOMNodeType type;
9042 const char *name;
9043 VARTYPE vt;
9044 HRESULT hr;
9045 } node_type_t;
9047 static const node_type_t get_datatype[] = {
9048 { NODE_ELEMENT, "element", VT_NULL, S_FALSE },
9049 { NODE_ATTRIBUTE, "attr", VT_NULL, S_FALSE },
9050 { NODE_TEXT, "text", VT_NULL, S_FALSE },
9051 { NODE_CDATA_SECTION , "cdata", VT_NULL, S_FALSE },
9052 { NODE_ENTITY_REFERENCE, "entityref", VT_NULL, S_FALSE },
9053 { NODE_PROCESSING_INSTRUCTION, "pi", VT_NULL, S_FALSE },
9054 { NODE_COMMENT, "comment", VT_NULL, S_FALSE },
9055 { NODE_DOCUMENT_FRAGMENT, "docfrag", VT_NULL, S_FALSE },
9056 { 0 }
9059 static void test_get_dataType(void)
9061 const node_type_t *entry = get_datatype;
9062 IXMLDOMDocument *doc;
9064 doc = create_document(&IID_IXMLDOMDocument);
9066 while (entry->type)
9068 IXMLDOMNode *node = NULL;
9069 VARIANT var, type;
9070 HRESULT hr;
9072 V_VT(&var) = VT_I4;
9073 V_I4(&var) = entry->type;
9074 hr = IXMLDOMDocument_createNode(doc, var, _bstr_(entry->name), NULL, &node);
9075 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9077 hr = IXMLDOMNode_get_dataType(node, NULL);
9078 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9080 VariantInit(&type);
9081 hr = IXMLDOMNode_get_dataType(node, &type);
9082 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9083 hr, entry->hr, entry->type);
9084 ok(V_VT(&type) == entry->vt, "got %d, expected %d. node type %d\n",
9085 V_VT(&type), entry->vt, entry->type);
9086 VariantClear(&type);
9088 IXMLDOMNode_Release(node);
9090 entry++;
9093 IXMLDOMDocument_Release(doc);
9094 free_bstrs();
9097 typedef struct _get_node_typestring_t {
9098 DOMNodeType type;
9099 const char *string;
9100 } get_node_typestring_t;
9102 static const get_node_typestring_t get_node_typestring[] = {
9103 { NODE_ELEMENT, "element" },
9104 { NODE_ATTRIBUTE, "attribute" },
9105 { NODE_TEXT, "text" },
9106 { NODE_CDATA_SECTION , "cdatasection" },
9107 { NODE_ENTITY_REFERENCE, "entityreference" },
9108 { NODE_PROCESSING_INSTRUCTION, "processinginstruction" },
9109 { NODE_COMMENT, "comment" },
9110 { NODE_DOCUMENT_FRAGMENT, "documentfragment" },
9111 { 0 }
9114 static void test_get_nodeTypeString(void)
9116 const get_node_typestring_t *entry = get_node_typestring;
9117 IXMLDOMDocument *doc;
9118 HRESULT hr;
9119 BSTR str;
9121 doc = create_document(&IID_IXMLDOMDocument);
9123 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
9124 ok(hr == S_OK, "got 0x%08x\n", hr);
9125 ok(!lstrcmpW(str, _bstr_("document")), "got string %s\n", wine_dbgstr_w(str));
9126 SysFreeString(str);
9128 while (entry->type)
9130 IXMLDOMNode *node = NULL;
9131 VARIANT var;
9133 V_VT(&var) = VT_I4;
9134 V_I4(&var) = entry->type;
9135 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9136 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9138 hr = IXMLDOMNode_get_nodeTypeString(node, NULL);
9139 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9141 hr = IXMLDOMNode_get_nodeTypeString(node, &str);
9142 ok(hr == S_OK, "got 0x%08x\n", hr);
9143 ok(!lstrcmpW(str, _bstr_(entry->string)), "got string %s, expected %s. node type %d\n",
9144 wine_dbgstr_w(str), entry->string, entry->type);
9145 SysFreeString(str);
9146 IXMLDOMNode_Release(node);
9148 entry++;
9151 IXMLDOMDocument_Release(doc);
9152 free_bstrs();
9155 typedef struct _get_attributes_t {
9156 DOMNodeType type;
9157 HRESULT hr;
9158 } get_attributes_t;
9160 static const get_attributes_t get_attributes[] = {
9161 { NODE_ATTRIBUTE, S_FALSE },
9162 { NODE_TEXT, S_FALSE },
9163 { NODE_CDATA_SECTION , S_FALSE },
9164 { NODE_ENTITY_REFERENCE, S_FALSE },
9165 { NODE_PROCESSING_INSTRUCTION, S_FALSE },
9166 { NODE_COMMENT, S_FALSE },
9167 { NODE_DOCUMENT_FRAGMENT, S_FALSE },
9168 { 0 }
9171 static void test_get_attributes(void)
9173 const get_attributes_t *entry = get_attributes;
9174 IXMLDOMNamedNodeMap *map;
9175 IXMLDOMDocument *doc;
9176 IXMLDOMNode *node, *node2;
9177 VARIANT_BOOL b;
9178 HRESULT hr;
9179 BSTR str;
9180 LONG length;
9182 doc = create_document(&IID_IXMLDOMDocument);
9184 hr = IXMLDOMDocument_loadXML(doc, _bstr_(complete4A), &b);
9185 ok(hr == S_OK, "got %08x\n", hr);
9187 hr = IXMLDOMDocument_get_attributes(doc, NULL);
9188 ok(hr == E_INVALIDARG, "got %08x\n", hr);
9190 map = (void*)0xdeadbeef;
9191 hr = IXMLDOMDocument_get_attributes(doc, &map);
9192 ok(hr == S_FALSE, "got %08x\n", hr);
9193 ok(map == NULL, "got %p\n", map);
9195 /* first child is <?xml ?> */
9196 hr = IXMLDOMDocument_get_firstChild(doc, &node);
9197 ok(hr == S_OK, "got %08x\n", hr);
9199 hr = IXMLDOMNode_get_attributes(node, &map);
9200 ok(hr == S_OK, "got %08x\n", hr);
9202 node2 = (void*)0xdeadbeef;
9203 hr = IXMLDOMNamedNodeMap_getNamedItem(map, _bstr_("attr"), &node2);
9204 ok(hr == S_FALSE, "got %08x\n", hr);
9205 ok(node2 == NULL, "got %p\n", node2);
9207 length = -1;
9208 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9209 EXPECT_HR(hr, S_OK);
9210 todo_wine ok(length == 1, "got %d\n", length);
9212 if (hr == S_OK && length == 1)
9214 IXMLDOMAttribute *attr;
9215 DOMNodeType type;
9216 VARIANT v;
9218 node2 = NULL;
9219 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9220 EXPECT_HR(hr, S_OK);
9221 ok(node != NULL, "got %p\n", node2);
9223 hr = IXMLDOMNode_get_nodeName(node2, &str);
9224 EXPECT_HR(hr, S_OK);
9225 ok(!lstrcmpW(str, _bstr_("version")), "got %s\n", wine_dbgstr_w(str));
9226 SysFreeString(str);
9228 length = -1;
9229 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9230 EXPECT_HR(hr, S_OK);
9231 ok(length == 1, "got %d\n", length);
9233 type = -1;
9234 hr = IXMLDOMNode_get_nodeType(node2, &type);
9235 EXPECT_HR(hr, S_OK);
9236 ok(type == NODE_ATTRIBUTE, "got %d\n", type);
9238 hr = IXMLDOMNode_get_xml(node, &str);
9239 EXPECT_HR(hr, S_OK);
9240 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9241 SysFreeString(str);
9243 hr = IXMLDOMNode_get_text(node, &str);
9244 EXPECT_HR(hr, S_OK);
9245 ok(!lstrcmpW(str, _bstr_("version=\"1.0\"")), "got %s\n", wine_dbgstr_w(str));
9246 SysFreeString(str);
9248 hr = IXMLDOMNamedNodeMap_removeNamedItem(map, _bstr_("version"), NULL);
9249 EXPECT_HR(hr, S_OK);
9251 length = -1;
9252 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9253 EXPECT_HR(hr, S_OK);
9254 ok(length == 0, "got %d\n", length);
9256 hr = IXMLDOMNode_get_xml(node, &str);
9257 EXPECT_HR(hr, S_OK);
9258 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9259 SysFreeString(str);
9261 hr = IXMLDOMNode_get_text(node, &str);
9262 EXPECT_HR(hr, S_OK);
9263 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
9264 SysFreeString(str);
9266 IXMLDOMNamedNodeMap_Release(map);
9268 hr = IXMLDOMNode_get_attributes(node, &map);
9269 ok(hr == S_OK, "got %08x\n", hr);
9271 length = -1;
9272 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9273 EXPECT_HR(hr, S_OK);
9274 ok(length == 0, "got %d\n", length);
9276 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("encoding"), &attr);
9277 EXPECT_HR(hr, S_OK);
9279 V_VT(&v) = VT_BSTR;
9280 V_BSTR(&v) = _bstr_("UTF-8");
9281 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
9282 EXPECT_HR(hr, S_OK);
9284 EXPECT_REF(attr, 2);
9285 hr = IXMLDOMNamedNodeMap_setNamedItem(map, (IXMLDOMNode*)attr, NULL);
9286 EXPECT_HR(hr, S_OK);
9287 EXPECT_REF(attr, 2);
9289 hr = IXMLDOMNode_get_attributes(node, &map);
9290 ok(hr == S_OK, "got %08x\n", hr);
9292 length = -1;
9293 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9294 EXPECT_HR(hr, S_OK);
9295 ok(length == 1, "got %d\n", length);
9297 hr = IXMLDOMNode_get_xml(node, &str);
9298 EXPECT_HR(hr, S_OK);
9299 ok(!lstrcmpW(str, _bstr_("<?xml version=\"1.0\"?>")), "got %s\n", wine_dbgstr_w(str));
9300 SysFreeString(str);
9302 hr = IXMLDOMNode_get_text(node, &str);
9303 EXPECT_HR(hr, S_OK);
9304 ok(!lstrcmpW(str, _bstr_("encoding=\"UTF-8\"")), "got %s\n", wine_dbgstr_w(str));
9305 SysFreeString(str);
9307 IXMLDOMNamedNodeMap_Release(map);
9308 IXMLDOMNode_Release(node2);
9311 IXMLDOMNode_Release(node);
9313 /* last child is element */
9314 EXPECT_REF(doc, 1);
9315 hr = IXMLDOMDocument_get_lastChild(doc, &node);
9316 ok(hr == S_OK, "got %08x\n", hr);
9317 EXPECT_REF(doc, 1);
9319 EXPECT_REF(node, 1);
9320 hr = IXMLDOMNode_get_attributes(node, &map);
9321 ok(hr == S_OK, "got %08x\n", hr);
9322 EXPECT_REF(node, 1);
9323 EXPECT_REF(doc, 1);
9325 EXPECT_REF(map, 1);
9326 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9327 ok(hr == S_OK, "got %08x\n", hr);
9328 EXPECT_REF(node, 1);
9329 EXPECT_REF(node2, 1);
9330 EXPECT_REF(map, 1);
9331 EXPECT_REF(doc, 1);
9332 IXMLDOMNode_Release(node2);
9334 /* release node before map release, map still works */
9335 IXMLDOMNode_Release(node);
9337 length = 0;
9338 hr = IXMLDOMNamedNodeMap_get_length(map, &length);
9339 ok(hr == S_OK, "got %08x\n", hr);
9340 ok(length == 1, "got %d\n", length);
9342 node2 = NULL;
9343 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node2);
9344 ok(hr == S_OK, "got %08x\n", hr);
9345 EXPECT_REF(node2, 1);
9346 IXMLDOMNode_Release(node2);
9348 IXMLDOMNamedNodeMap_Release(map);
9350 while (entry->type)
9352 VARIANT var;
9354 node = NULL;
9356 V_VT(&var) = VT_I4;
9357 V_I4(&var) = entry->type;
9358 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("node"), NULL, &node);
9359 ok(hr == S_OK, "failed to create node, type %d\n", entry->type);
9361 hr = IXMLDOMNode_get_attributes(node, NULL);
9362 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
9364 map = (void*)0xdeadbeef;
9365 hr = IXMLDOMNode_get_attributes(node, &map);
9366 ok(hr == entry->hr, "got 0x%08x, expected 0x%08x. node type %d\n",
9367 hr, entry->hr, entry->type);
9368 ok(map == NULL, "got %p\n", map);
9370 IXMLDOMNode_Release(node);
9372 entry++;
9375 IXMLDOMDocument_Release(doc);
9376 free_bstrs();
9379 static void test_selection(void)
9381 IXMLDOMSelection *selection, *selection2;
9382 IEnumVARIANT *enum1, *enum2, *enum3;
9383 IXMLDOMNodeList *list;
9384 IUnknown *unk1, *unk2;
9385 IXMLDOMDocument *doc;
9386 IDispatchEx *dispex;
9387 IXMLDOMNode *node;
9388 IDispatch *disp;
9389 VARIANT_BOOL b;
9390 HRESULT hr;
9391 DISPID did;
9392 VARIANT v;
9393 BSTR name;
9394 ULONG ret;
9395 LONG len;
9397 doc = create_document(&IID_IXMLDOMDocument);
9399 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b);
9400 EXPECT_HR(hr, S_OK);
9402 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list);
9403 EXPECT_HR(hr, S_OK);
9405 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
9406 EXPECT_HR(hr, S_OK);
9407 IXMLDOMSelection_Release(selection);
9409 /* collection disp id */
9410 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IDispatchEx, (void**)&dispex);
9411 EXPECT_HR(hr, S_OK);
9412 did = 0;
9413 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
9414 EXPECT_HR(hr, S_OK);
9415 ok(did == DISPID_DOM_COLLECTION_BASE, "got %d\n", did);
9416 len = 0;
9417 hr = IXMLDOMSelection_get_length(selection, &len);
9418 EXPECT_HR(hr, S_OK);
9419 ok(len == 1, "got %d\n", len);
9420 hr = IDispatchEx_GetDispID(dispex, _bstr_("10"), 0, &did);
9421 EXPECT_HR(hr, S_OK);
9422 ok(did == DISPID_DOM_COLLECTION_BASE+10, "got %d\n", did);
9423 IDispatchEx_Release(dispex);
9425 /* IEnumVARIANT tests */
9426 enum1 = NULL;
9427 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IEnumVARIANT, (void**)&enum1);
9428 EXPECT_HR(hr, S_OK);
9429 ok(enum1 != NULL, "got %p\n", enum1);
9430 EXPECT_REF(enum1, 2);
9432 EXPECT_REF(selection, 1);
9433 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IUnknown, (void**)&unk1);
9434 EXPECT_HR(hr, S_OK);
9435 EXPECT_REF(selection, 2);
9436 EXPECT_REF(enum1, 2);
9438 /* enumerator and selection object return same IUnknown* */
9439 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IUnknown, (void**)&unk2);
9440 EXPECT_HR(hr, S_OK);
9441 EXPECT_REF(selection, 3);
9442 EXPECT_REF(enum1, 2);
9443 ok(unk2 == unk1, "got %p, %p\n", unk1, unk2);
9444 IUnknown_Release(unk2);
9446 EXPECT_REF(selection, 2);
9447 IEnumVARIANT_AddRef(enum1);
9448 EXPECT_REF(selection, 2);
9449 IEnumVARIANT_Release(enum1);
9451 enum3 = NULL;
9452 hr = IXMLDOMSelection_QueryInterface(selection, &IID_IEnumVARIANT, (void**)&enum3);
9453 EXPECT_HR(hr, S_OK);
9454 ok(enum3 != NULL, "got %p\n", enum3);
9455 ok(enum1 == enum3, "got %p and %p\n", enum1, enum3);
9456 EXPECT_REF(enum1, 3);
9457 IEnumVARIANT_Release(enum3);
9459 EXPECT_REF(selection, 2);
9460 EXPECT_REF(enum1, 2);
9462 enum2 = NULL;
9463 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum2);
9464 EXPECT_HR(hr, S_OK);
9465 ok(enum2 != NULL, "got %p\n", enum2);
9467 EXPECT_REF(selection, 3);
9468 EXPECT_REF(enum1, 2);
9469 EXPECT_REF(enum2, 1);
9471 ok(enum1 != enum2, "got %p, %p\n", enum1, enum2);
9473 hr = IEnumVARIANT_QueryInterface(enum2, &IID_IUnknown, (void**)&unk2);
9474 EXPECT_HR(hr, S_OK);
9475 EXPECT_REF(selection, 3);
9476 EXPECT_REF(enum2, 2);
9477 ok(unk2 != unk1, "got %p, %p\n", unk1, unk2);
9478 IUnknown_Release(unk2);
9479 IUnknown_Release(unk1);
9481 selection2 = NULL;
9482 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IXMLDOMSelection, (void**)&selection2);
9483 EXPECT_HR(hr, S_OK);
9484 ok(selection2 == selection, "got %p and %p\n", selection, selection2);
9485 EXPECT_REF(selection, 3);
9486 EXPECT_REF(enum1, 2);
9488 IXMLDOMSelection_Release(selection2);
9490 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IDispatch, (void**)&disp);
9491 EXPECT_HR(hr, S_OK);
9492 EXPECT_REF(selection, 3);
9493 IDispatch_Release(disp);
9495 hr = IEnumVARIANT_QueryInterface(enum1, &IID_IEnumVARIANT, (void**)&enum3);
9496 EXPECT_HR(hr, S_OK);
9497 ok(enum3 == enum1, "got %p and %p\n", enum3, enum1);
9498 EXPECT_REF(selection, 2);
9499 EXPECT_REF(enum1, 3);
9501 IEnumVARIANT_Release(enum1);
9502 IEnumVARIANT_Release(enum2);
9503 IEnumVARIANT_Release(enum3);
9505 enum1 = NULL;
9506 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum1);
9507 EXPECT_HR(hr, S_OK);
9508 ok(enum1 != NULL, "got %p\n", enum1);
9509 EXPECT_REF(enum1, 1);
9510 EXPECT_REF(selection, 2);
9512 enum2 = NULL;
9513 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum2);
9514 EXPECT_HR(hr, S_OK);
9515 ok(enum2 != NULL, "got %p\n", enum2);
9516 EXPECT_REF(enum2, 1);
9517 EXPECT_REF(selection, 3);
9519 ok(enum1 != enum2, "got %p, %p\n", enum1, enum2);
9521 IEnumVARIANT_AddRef(enum1);
9522 EXPECT_REF(selection, 3);
9523 EXPECT_REF(enum1, 2);
9524 EXPECT_REF(enum2, 1);
9525 IEnumVARIANT_Release(enum1);
9527 IEnumVARIANT_Release(enum1);
9528 IEnumVARIANT_Release(enum2);
9530 EXPECT_REF(selection, 1);
9532 IXMLDOMNodeList_Release(list);
9534 hr = IXMLDOMDocument_get_childNodes(doc, &list);
9535 EXPECT_HR(hr, S_OK);
9537 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
9538 EXPECT_HR(hr, E_NOINTERFACE);
9540 IXMLDOMNodeList_Release(list);
9542 /* test if IEnumVARIANT touches selection context */
9543 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xpath_simple_list), &b);
9544 EXPECT_HR(hr, S_OK);
9546 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root/*"), &list);
9547 EXPECT_HR(hr, S_OK);
9549 hr = IXMLDOMNodeList_QueryInterface(list, &IID_IXMLDOMSelection, (void**)&selection);
9550 EXPECT_HR(hr, S_OK);
9552 len = 0;
9553 hr = IXMLDOMSelection_get_length(selection, &len);
9554 EXPECT_HR(hr, S_OK);
9555 ok(len == 4, "got %d\n", len);
9557 enum1 = NULL;
9558 hr = IXMLDOMSelection_get__newEnum(selection, (IUnknown**)&enum1);
9559 EXPECT_HR(hr, S_OK);
9561 /* no-op if zero count */
9562 V_VT(&v) = VT_I2;
9563 hr = IEnumVARIANT_Next(enum1, 0, &v, NULL);
9564 EXPECT_HR(hr, S_OK);
9565 ok(V_VT(&v) == VT_I2, "got var type %d\n", V_VT(&v));
9567 /* positive count, null array pointer */
9568 hr = IEnumVARIANT_Next(enum1, 1, NULL, NULL);
9569 EXPECT_HR(hr, E_INVALIDARG);
9571 ret = 1;
9572 hr = IEnumVARIANT_Next(enum1, 1, NULL, &ret);
9573 EXPECT_HR(hr, E_INVALIDARG);
9574 ok(ret == 0, "got %d\n", ret);
9576 V_VT(&v) = VT_I2;
9577 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
9578 EXPECT_HR(hr, S_OK);
9579 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
9581 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
9582 EXPECT_HR(hr, S_OK);
9583 hr = IXMLDOMNode_get_nodeName(node, &name);
9584 EXPECT_HR(hr, S_OK);
9585 ok(!lstrcmpW(name, _bstr_("a")), "got node name %s\n", wine_dbgstr_w(name));
9586 SysFreeString(name);
9587 IXMLDOMNode_Release(node);
9588 VariantClear(&v);
9590 /* list cursor is updated */
9591 hr = IXMLDOMSelection_nextNode(selection, &node);
9592 EXPECT_HR(hr, S_OK);
9593 hr = IXMLDOMNode_get_nodeName(node, &name);
9594 EXPECT_HR(hr, S_OK);
9595 ok(!lstrcmpW(name, _bstr_("c")), "got node name %s\n", wine_dbgstr_w(name));
9596 IXMLDOMNode_Release(node);
9597 SysFreeString(name);
9599 V_VT(&v) = VT_I2;
9600 hr = IEnumVARIANT_Next(enum1, 1, &v, NULL);
9601 EXPECT_HR(hr, S_OK);
9602 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
9603 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
9604 EXPECT_HR(hr, S_OK);
9605 hr = IXMLDOMNode_get_nodeName(node, &name);
9606 EXPECT_HR(hr, S_OK);
9607 ok(!lstrcmpW(name, _bstr_("b")), "got node name %s\n", wine_dbgstr_w(name));
9608 SysFreeString(name);
9609 IXMLDOMNode_Release(node);
9610 VariantClear(&v);
9611 IEnumVARIANT_Release(enum1);
9613 hr = IXMLDOMSelection_nextNode(selection, &node);
9614 EXPECT_HR(hr, S_OK);
9615 hr = IXMLDOMNode_get_nodeName(node, &name);
9616 EXPECT_HR(hr, S_OK);
9617 ok(!lstrcmpW(name, _bstr_("d")), "got node name %s\n", wine_dbgstr_w(name));
9618 IXMLDOMNode_Release(node);
9619 SysFreeString(name);
9621 IXMLDOMSelection_Release(selection);
9622 IXMLDOMNodeList_Release(list);
9623 IXMLDOMDocument_Release(doc);
9625 free_bstrs();
9628 static void write_to_file(const char *name, const char *data)
9630 DWORD written;
9631 HANDLE hfile;
9632 BOOL ret;
9634 hfile = CreateFileA(name, GENERIC_WRITE|GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
9635 ok(hfile != INVALID_HANDLE_VALUE, "failed to create test file: %s\n", name);
9637 ret = WriteFile(hfile, data, strlen(data), &written, NULL);
9638 ok(ret, "WriteFile failed: %s, %d\n", name, GetLastError());
9640 CloseHandle(hfile);
9643 static void test_load(void)
9645 IXMLDOMDocument *doc, *doc2;
9646 IXMLDOMNodeList *list;
9647 IXMLDOMElement *elem;
9648 VARIANT_BOOL b;
9649 VARIANT src;
9650 HRESULT hr;
9651 BSTR path, bstr1, bstr2;
9652 void* ptr;
9654 /* prepare a file */
9655 write_to_file("test.xml", win1252xml);
9657 doc = create_document(&IID_IXMLDOMDocument);
9659 /* null pointer as input */
9660 V_VT(&src) = VT_UNKNOWN;
9661 V_UNKNOWN(&src) = NULL;
9662 hr = IXMLDOMDocument_load(doc, src, &b);
9663 EXPECT_HR(hr, E_INVALIDARG);
9664 ok(b == VARIANT_FALSE, "got %d\n", b);
9666 path = _bstr_("test.xml");
9668 /* load from path: VT_BSTR */
9669 V_VT(&src) = VT_BSTR;
9670 V_BSTR(&src) = path;
9671 hr = IXMLDOMDocument_load(doc, src, &b);
9672 EXPECT_HR(hr, S_OK);
9673 ok(b == VARIANT_TRUE, "got %d\n", b);
9675 bstr1 = NULL;
9676 hr = IXMLDOMDocument_get_url(doc, &bstr1);
9677 ok(hr == S_OK, "got 0x%08x\n", hr);
9678 SysFreeString(bstr1);
9680 /* load from a path: VT_BSTR|VT_BYREF */
9681 V_VT(&src) = VT_BSTR | VT_BYREF;
9682 V_BSTRREF(&src) = &path;
9683 hr = IXMLDOMDocument_load(doc, src, &b);
9684 EXPECT_HR(hr, S_OK);
9685 ok(b == VARIANT_TRUE, "got %d\n", b);
9687 bstr1 = NULL;
9688 hr = IXMLDOMDocument_get_url(doc, &bstr1);
9689 ok(hr == S_OK, "got 0x%08x\n", hr);
9691 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
9692 ok(hr == S_OK, "got 0x%08x\n", hr);
9694 /* create another instance for the same document, check url */
9695 hr = IXMLDOMElement_get_ownerDocument(elem, &doc2);
9696 ok(hr == S_OK, "got 0x%08x\n", hr);
9698 hr = IXMLDOMDocument_get_url(doc, &bstr2);
9699 ok(hr == S_OK, "got 0x%08x\n", hr);
9700 ok(!lstrcmpW(bstr1, bstr2), "got %s\n", wine_dbgstr_w(bstr2));
9702 IXMLDOMDocument_Release(doc2);
9703 IXMLDOMElement_Release(elem);
9705 SysFreeString(bstr1);
9706 SysFreeString(bstr2);
9708 /* load from a path: VT_BSTR|VT_BYREF, null ptr */
9709 V_VT(&src) = VT_BSTR | VT_BYREF;
9710 V_BSTRREF(&src) = NULL;
9711 hr = IXMLDOMDocument_load(doc, src, &b);
9712 EXPECT_HR(hr, E_INVALIDARG);
9713 ok(b == VARIANT_FALSE, "got %d\n", b);
9715 bstr1 = NULL;
9716 hr = IXMLDOMDocument_get_url(doc, &bstr1);
9717 ok(hr == S_OK, "got 0x%08x\n", hr);
9718 SysFreeString(bstr1);
9720 DeleteFileA("test.xml");
9722 /* load from existing path, no xml content */
9723 write_to_file("test.xml", nocontent);
9725 V_VT(&src) = VT_BSTR;
9726 V_BSTR(&src) = path;
9727 b = VARIANT_TRUE;
9728 hr = IXMLDOMDocument_load(doc, src, &b);
9729 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9730 ok(b == VARIANT_FALSE, "got %d\n", b);
9732 bstr1 = (BSTR)0x1;
9733 hr = IXMLDOMDocument_get_url(doc, &bstr1);
9734 ok(hr == S_FALSE, "got 0x%08x\n", hr);
9735 ok(bstr1 == NULL, "got %p\n", bstr1);
9737 DeleteFileA("test.xml");
9738 IXMLDOMDocument_Release(doc);
9740 doc = create_document(&IID_IXMLDOMDocument);
9742 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b);
9743 EXPECT_HR(hr, S_OK);
9744 ok(b == VARIANT_TRUE, "got %d\n", b);
9746 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
9747 EXPECT_HR(hr, S_OK);
9748 bstr1 = _bstr_(list_to_string(list));
9750 hr = IXMLDOMNodeList_reset(list);
9751 EXPECT_HR(hr, S_OK);
9753 IXMLDOMDocument_Release(doc);
9755 doc = create_document(&IID_IXMLDOMDocument);
9757 VariantInit(&src);
9758 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenA(szExampleXML));
9759 V_VT(&src) = VT_ARRAY|VT_UI1;
9760 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
9761 ptr = NULL;
9762 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
9763 EXPECT_HR(hr, S_OK);
9764 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
9766 memcpy(ptr, szExampleXML, lstrlenA(szExampleXML));
9767 hr = SafeArrayUnlock(V_ARRAY(&src));
9768 EXPECT_HR(hr, S_OK);
9770 hr = IXMLDOMDocument_load(doc, src, &b);
9771 EXPECT_HR(hr, S_OK);
9772 ok(b == VARIANT_TRUE, "got %d\n", b);
9774 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("//*"), &list);
9775 EXPECT_HR(hr, S_OK);
9776 bstr2 = _bstr_(list_to_string(list));
9778 hr = IXMLDOMNodeList_reset(list);
9779 EXPECT_HR(hr, S_OK);
9781 ok(lstrcmpW(bstr1, bstr2) == 0, "strings not equal: %s : %s\n",
9782 wine_dbgstr_w(bstr1), wine_dbgstr_w(bstr2));
9784 IXMLDOMDocument_Release(doc);
9785 IXMLDOMNodeList_Release(list);
9786 VariantClear(&src);
9788 /* UTF-16 isn't accepted */
9789 doc = create_document(&IID_IXMLDOMDocument);
9791 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI1, 0, lstrlenW(szComplete1) * sizeof(WCHAR));
9792 V_VT(&src) = VT_ARRAY|VT_UI1;
9793 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
9794 ptr = NULL;
9795 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
9796 EXPECT_HR(hr, S_OK);
9797 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
9799 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
9800 hr = SafeArrayUnlock(V_ARRAY(&src));
9801 EXPECT_HR(hr, S_OK);
9803 hr = IXMLDOMDocument_load(doc, src, &b);
9804 todo_wine EXPECT_HR(hr, S_FALSE);
9805 todo_wine ok(b == VARIANT_FALSE, "got %d\n", b);
9807 VariantClear(&src);
9809 /* it doesn't like it as a VT_ARRAY|VT_UI2 either */
9810 V_ARRAY(&src) = SafeArrayCreateVector(VT_UI2, 0, lstrlenW(szComplete1));
9811 V_VT(&src) = VT_ARRAY|VT_UI2;
9812 ok(V_ARRAY(&src) != NULL, "SafeArrayCreateVector() returned NULL\n");
9813 ptr = NULL;
9814 hr = SafeArrayAccessData(V_ARRAY(&src), &ptr);
9815 EXPECT_HR(hr, S_OK);
9816 ok(ptr != NULL, "SafeArrayAccessData() returned NULL\n");
9818 memcpy(ptr, szComplete1, lstrlenW(szComplete1) * sizeof(WCHAR));
9819 hr = SafeArrayUnlock(V_ARRAY(&src));
9820 EXPECT_HR(hr, S_OK);
9822 hr = IXMLDOMDocument_load(doc, src, &b);
9823 todo_wine EXPECT_HR(hr, E_INVALIDARG);
9824 ok(b == VARIANT_FALSE, "got %d\n", b);
9826 VariantClear(&src);
9827 IXMLDOMDocument_Release(doc);
9829 free_bstrs();
9832 static void test_domobj_dispex(IUnknown *obj)
9834 static const WCHAR testW[] = {'t','e','s','t','p','r','o','p',0};
9835 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
9836 IDispatchEx *dispex;
9837 IUnknown *unk;
9838 DWORD props;
9839 UINT ticnt;
9840 HRESULT hr;
9841 BSTR name;
9843 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
9844 EXPECT_HR(hr, S_OK);
9845 if (FAILED(hr)) return;
9847 ticnt = 0;
9848 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
9849 EXPECT_HR(hr, S_OK);
9850 ok(ticnt == 1, "ticnt=%u\n", ticnt);
9852 name = SysAllocString(szstar);
9853 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
9854 EXPECT_HR(hr, E_NOTIMPL);
9855 SysFreeString(name);
9857 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
9858 EXPECT_HR(hr, E_NOTIMPL);
9860 props = 0;
9861 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
9862 EXPECT_HR(hr, E_NOTIMPL);
9863 ok(props == 0, "expected 0 got %d\n", props);
9865 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
9866 EXPECT_HR(hr, E_NOTIMPL);
9867 if (SUCCEEDED(hr)) SysFreeString(name);
9869 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
9870 EXPECT_HR(hr, E_NOTIMPL);
9872 unk = (IUnknown*)0xdeadbeef;
9873 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
9874 EXPECT_HR(hr, E_NOTIMPL);
9875 ok(unk == (IUnknown*)0xdeadbeef, "got %p\n", unk);
9877 name = SysAllocString(testW);
9878 hr = IDispatchEx_GetDispID(dispex, name, fdexNameEnsure, &dispid);
9879 ok(hr == DISP_E_UNKNOWNNAME, "got 0x%08x\n", hr);
9880 SysFreeString(name);
9882 IDispatchEx_Release(dispex);
9885 static void test_mxnamespacemanager(void)
9887 static const char xmluriA[] = "http://www.w3.org/XML/1998/namespace";
9888 IMXNamespacePrefixes *prefixes;
9889 IVBMXNamespaceManager *mgr2;
9890 IMXNamespaceManager *nsmgr;
9891 IUnknown *unk1, *unk2;
9892 WCHAR buffW[250];
9893 IDispatch *disp;
9894 IUnknown *unk;
9895 HRESULT hr;
9896 INT len;
9898 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
9899 &IID_IMXNamespaceManager, (void**)&nsmgr);
9900 EXPECT_HR(hr, S_OK);
9902 /* IMXNamespaceManager inherits from IUnknown */
9903 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IDispatch, (void**)&disp);
9904 EXPECT_HR(hr, S_OK);
9905 IDispatch_Release(disp);
9907 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IVBMXNamespaceManager, (void**)&mgr2);
9908 EXPECT_HR(hr, S_OK);
9910 EXPECT_REF(nsmgr, 2);
9911 EXPECT_REF(mgr2, 2);
9912 prefixes = NULL;
9913 hr = IVBMXNamespaceManager_getDeclaredPrefixes(mgr2, &prefixes);
9914 todo_wine
9915 ok(hr == S_OK, "got 0x%08x\n", hr);
9916 if (hr == S_OK)
9918 IDispatchEx *dispex;
9919 VARIANT arg, ret;
9920 DISPPARAMS dispparams;
9922 ok(prefixes != NULL, "got %p\n", prefixes);
9923 EXPECT_REF(nsmgr, 2);
9924 EXPECT_REF(mgr2, 2);
9925 EXPECT_REF(prefixes, 1);
9927 IVBMXNamespaceManager_QueryInterface(mgr2, &IID_IUnknown, (void**)&unk1);
9928 IMXNamespacePrefixes_QueryInterface(prefixes, &IID_IUnknown, (void**)&unk2);
9930 EXPECT_REF(mgr2, 3);
9931 EXPECT_REF(prefixes, 2);
9933 IUnknown_Release(unk1);
9934 IUnknown_Release(unk2);
9936 hr = IMXNamespacePrefixes_QueryInterface(prefixes, &IID_IDispatchEx, (void**)&dispex);
9937 ok(hr == S_OK, "got 0x%08x\n", hr);
9939 V_VT(&arg) = VT_I4;
9940 V_I4(&arg) = 0;
9941 dispparams.cArgs = 1;
9942 dispparams.cNamedArgs = 0;
9943 dispparams.rgdispidNamedArgs = NULL;
9944 dispparams.rgvarg = &arg;
9946 V_VT(&ret) = VT_EMPTY;
9947 V_DISPATCH(&ret) = (void*)0x1;
9948 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
9949 ok(hr == S_OK, "got 0x%08x\n", hr);
9950 ok(V_VT(&ret) == VT_BSTR, "got %d\n", V_VT(&ret));
9951 ok(V_BSTR(&ret) != NULL, "got %p\n", V_BSTR(&ret));
9952 VariantClear(&ret);
9954 IDispatchEx_Release(dispex);
9955 IMXNamespacePrefixes_Release(prefixes);
9957 IVBMXNamespaceManager_Release(mgr2);
9959 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
9960 EXPECT_HR(hr, S_OK);
9962 /* prefix already added */
9963 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
9964 EXPECT_HR(hr, S_FALSE);
9966 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), NULL);
9967 EXPECT_HR(hr, E_INVALIDARG);
9969 /* "xml" and "xmlns" are not allowed here */
9970 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xml"), _bstr_("uri1"));
9971 EXPECT_HR(hr, E_INVALIDARG);
9973 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("xmlns"), _bstr_("uri1"));
9974 EXPECT_HR(hr, E_INVALIDARG);
9975 todo_wine {
9976 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, -1, NULL, NULL);
9977 EXPECT_HR(hr, E_FAIL);
9979 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, NULL);
9980 EXPECT_HR(hr, E_POINTER);
9982 len = -1;
9983 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, NULL, &len);
9984 EXPECT_HR(hr, S_OK);
9985 ok(len == 3, "got %d\n", len);
9987 len = -1;
9988 buffW[0] = 0x1;
9989 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
9990 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
9991 ok(len == -1, "got %d\n", len);
9992 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
9994 len = 10;
9995 buffW[0] = 0x1;
9996 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
9997 EXPECT_HR(hr, S_OK);
9998 ok(len == 3, "got %d\n", len);
9999 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10001 /* getURI */
10002 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, NULL);
10003 EXPECT_HR(hr, E_INVALIDARG);
10005 len = -1;
10006 hr = IMXNamespaceManager_getURI(nsmgr, NULL, NULL, NULL, &len);
10007 EXPECT_HR(hr, E_INVALIDARG);
10008 ok(len == -1, "got %d\n", len);
10010 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, NULL);
10011 EXPECT_HR(hr, E_POINTER);
10013 len = -1;
10014 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, NULL, &len);
10015 EXPECT_HR(hr, S_OK);
10016 /* length of "xml" uri is constant */
10017 ok(len == strlen(xmluriA), "got %d\n", len);
10019 len = 100;
10020 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
10021 EXPECT_HR(hr, S_OK);
10022 ok(len == strlen(xmluriA), "got %d\n", len);
10023 ok(!lstrcmpW(buffW, _bstr_(xmluriA)), "got prefix %s\n", wine_dbgstr_w(buffW));
10025 len = strlen(xmluriA)-1;
10026 buffW[0] = 0x1;
10027 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml"), NULL, buffW, &len);
10028 EXPECT_HR(hr, E_XML_BUFFERTOOSMALL);
10029 ok(len == strlen(xmluriA)-1, "got %d\n", len);
10030 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10032 /* prefix xml1 not defined */
10033 len = -1;
10034 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, NULL, &len);
10035 EXPECT_HR(hr, S_FALSE);
10036 ok(len == 0, "got %d\n", len);
10038 len = 100;
10039 buffW[0] = 0x1;
10040 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_("xml1"), NULL, buffW, &len);
10041 EXPECT_HR(hr, S_FALSE);
10042 ok(buffW[0] == 0, "got %x\n", buffW[0]);
10043 ok(len == 0, "got %d\n", len);
10045 /* IDispatchEx tests */
10046 hr = IMXNamespaceManager_QueryInterface(nsmgr, &IID_IUnknown, (void**)&unk);
10047 EXPECT_HR(hr, S_OK);
10048 test_domobj_dispex(unk);
10049 IUnknown_Release(unk);
10051 IMXNamespaceManager_Release(nsmgr);
10053 /* ::getPrefix() */
10054 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10055 &IID_IMXNamespaceManager, (void**)&nsmgr);
10056 EXPECT_HR(hr, S_OK);
10058 hr = IMXNamespaceManager_getPrefix(nsmgr, NULL, 0, NULL, NULL);
10059 EXPECT_HR(hr, E_INVALIDARG);
10061 len = -1;
10062 hr = IMXNamespaceManager_getPrefix(nsmgr, NULL, 0, NULL, &len);
10063 EXPECT_HR(hr, E_INVALIDARG);
10064 ok(len == -1, "got %d\n", len);
10066 len = 100;
10067 buffW[0] = 0x1;
10068 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns0 uri"), 0, buffW, &len);
10069 EXPECT_HR(hr, E_FAIL);
10070 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10071 ok(len == 100, "got %d\n", len);
10073 len = 0;
10074 buffW[0] = 0x1;
10075 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns0 uri"), 0, buffW, &len);
10076 EXPECT_HR(hr, E_FAIL);
10077 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10078 ok(len == 0, "got %d\n", len);
10080 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
10081 EXPECT_HR(hr, S_OK);
10083 len = 100;
10084 buffW[0] = 0x1;
10085 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
10086 EXPECT_HR(hr, S_OK);
10087 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
10088 ok(len == 3, "got %d\n", len);
10090 len = 100;
10091 buffW[0] = 0x1;
10092 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("http://www.w3.org/XML/1998/namespace"), 0, buffW, &len);
10093 EXPECT_HR(hr, S_OK);
10094 ok(!lstrcmpW(buffW, _bstr_("xml")), "got %s\n", wine_dbgstr_w(buffW));
10095 ok(len == 3, "got %d\n", len);
10097 /* with null buffer it's possible to get required length */
10098 len = 100;
10099 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("http://www.w3.org/XML/1998/namespace"), 0, NULL, &len);
10100 EXPECT_HR(hr, S_OK);
10101 ok(len == 3, "got %d\n", len);
10103 len = 0;
10104 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("http://www.w3.org/XML/1998/namespace"), 0, NULL, &len);
10105 EXPECT_HR(hr, S_OK);
10106 ok(len == 3, "got %d\n", len);
10108 len = 100;
10109 buffW[0] = 0x1;
10110 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 1, buffW, &len);
10111 EXPECT_HR(hr, E_FAIL);
10112 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10113 ok(len == 100, "got %d\n", len);
10115 len = 100;
10116 buffW[0] = 0x1;
10117 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 2, buffW, &len);
10118 EXPECT_HR(hr, E_FAIL);
10119 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10120 ok(len == 100, "got %d\n", len);
10122 len = 100;
10123 buffW[0] = 0x1;
10124 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 0, buffW, &len);
10125 EXPECT_HR(hr, E_INVALIDARG);
10126 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10127 ok(len == 100, "got %d\n", len);
10129 len = 100;
10130 buffW[0] = 0x1;
10131 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 1, buffW, &len);
10132 EXPECT_HR(hr, E_INVALIDARG);
10133 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10134 ok(len == 100, "got %d\n", len);
10136 len = 100;
10137 buffW[0] = 0x1;
10138 hr = IMXNamespaceManager_getPrefix(nsmgr, NULL, 0, buffW, &len);
10139 EXPECT_HR(hr, E_INVALIDARG);
10140 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10141 ok(len == 100, "got %d\n", len);
10143 len = 100;
10144 buffW[0] = 0x1;
10145 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns0 uri"), 1, buffW, &len);
10146 EXPECT_HR(hr, E_FAIL);
10147 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10148 ok(len == 100, "got %d\n", len);
10150 len = 100;
10151 buffW[0] = 0x1;
10152 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 1, buffW, &len);
10153 EXPECT_HR(hr, E_INVALIDARG);
10154 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10155 ok(len == 100, "got %d\n", len);
10157 /* declare another one, indices are shifted */
10158 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns2"), _bstr_("ns2 uri"));
10159 EXPECT_HR(hr, S_OK);
10161 len = 100;
10162 buffW[0] = 0x1;
10163 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
10164 EXPECT_HR(hr, S_OK);
10165 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
10166 ok(len == 3, "got %d\n", len);
10168 len = 100;
10169 buffW[0] = 0x1;
10170 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
10171 EXPECT_HR(hr, S_OK);
10172 ok(!lstrcmpW(buffW, _bstr_("ns2")), "got %s\n", wine_dbgstr_w(buffW));
10173 ok(len == 3, "got %d\n", len);
10175 len = 100;
10176 buffW[0] = 0x1;
10177 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 1, buffW, &len);
10178 EXPECT_HR(hr, E_FAIL);
10179 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10180 ok(len == 100, "got %d\n", len);
10182 len = 100;
10183 buffW[0] = 0x1;
10184 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_(""), 1, buffW, &len);
10185 EXPECT_HR(hr, E_INVALIDARG);
10186 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10187 ok(len == 100, "got %d\n", len);
10189 IMXNamespaceManager_Release(nsmgr);
10191 /* push/pop tests */
10192 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10193 &IID_IMXNamespaceManager, (void**)&nsmgr);
10194 EXPECT_HR(hr, S_OK);
10196 /* pop with empty stack */
10197 hr = IMXNamespaceManager_popContext(nsmgr);
10198 EXPECT_HR(hr, E_FAIL);
10200 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
10201 EXPECT_HR(hr, S_OK);
10203 len = 100;
10204 buffW[0] = 0x1;
10205 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
10206 EXPECT_HR(hr, S_OK);
10207 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
10208 ok(len == 3, "got %d\n", len);
10210 hr = IMXNamespaceManager_pushContext(nsmgr);
10211 EXPECT_HR(hr, S_OK);
10213 len = 100;
10214 buffW[0] = 0x1;
10215 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
10216 EXPECT_HR(hr, S_OK);
10217 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
10218 ok(len == 3, "got %d\n", len);
10220 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns2"), _bstr_("ns2 uri"));
10221 EXPECT_HR(hr, S_OK);
10223 len = 100;
10224 buffW[0] = 0x1;
10225 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
10226 EXPECT_HR(hr, S_OK);
10227 ok(!lstrcmpW(buffW, _bstr_("ns2")), "got %s\n", wine_dbgstr_w(buffW));
10228 ok(len == 3, "got %d\n", len);
10230 hr = IMXNamespaceManager_pushContext(nsmgr);
10231 EXPECT_HR(hr, S_OK);
10232 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns3"), _bstr_("ns3 uri"));
10233 EXPECT_HR(hr, S_OK);
10235 len = 100;
10236 buffW[0] = 0x1;
10237 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
10238 EXPECT_HR(hr, S_OK);
10239 ok(!lstrcmpW(buffW, _bstr_("ns2")), "got %s\n", wine_dbgstr_w(buffW));
10240 ok(len == 3, "got %d\n", len);
10242 len = 100;
10243 buffW[0] = 0x1;
10244 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
10245 EXPECT_HR(hr, S_OK);
10246 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
10247 ok(len == 3, "got %d\n", len);
10249 hr = IMXNamespaceManager_popContext(nsmgr);
10250 EXPECT_HR(hr, S_OK);
10252 hr = IMXNamespaceManager_popContext(nsmgr);
10253 EXPECT_HR(hr, S_OK);
10255 len = 100;
10256 buffW[0] = 0x1;
10257 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns2 uri"), 0, buffW, &len);
10258 EXPECT_HR(hr, E_FAIL);
10259 ok(buffW[0] == 0x1, "got %x\n", buffW[0]);
10260 ok(len == 100, "got %d\n", len);
10262 len = 100;
10263 buffW[0] = 0x1;
10264 hr = IMXNamespaceManager_getPrefix(nsmgr, _bstr_("ns1 uri"), 0, buffW, &len);
10265 EXPECT_HR(hr, S_OK);
10266 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got %s\n", wine_dbgstr_w(buffW));
10267 ok(len == 3, "got %d\n", len);
10269 IMXNamespaceManager_Release(nsmgr);
10271 free_bstrs();
10274 static void test_mxnamespacemanager_override(void)
10276 IMXNamespaceManager *nsmgr;
10277 WCHAR buffW[250];
10278 VARIANT_BOOL b;
10279 HRESULT hr;
10280 INT len;
10282 hr = CoCreateInstance(&CLSID_MXNamespaceManager40, NULL, CLSCTX_INPROC_SERVER,
10283 &IID_IMXNamespaceManager, (void**)&nsmgr);
10284 EXPECT_HR(hr, S_OK);
10286 len = sizeof(buffW)/sizeof(WCHAR);
10287 buffW[0] = 0;
10288 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10289 EXPECT_HR(hr, S_OK);
10290 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10292 len = sizeof(buffW)/sizeof(WCHAR);
10293 buffW[0] = 0;
10294 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10295 EXPECT_HR(hr, E_FAIL);
10297 hr = IMXNamespaceManager_getAllowOverride(nsmgr, NULL);
10298 EXPECT_HR(hr, E_POINTER);
10300 b = VARIANT_FALSE;
10301 hr = IMXNamespaceManager_getAllowOverride(nsmgr, &b);
10302 EXPECT_HR(hr, S_OK);
10303 ok(b == VARIANT_TRUE, "got %d\n", b);
10305 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_FALSE);
10306 EXPECT_HR(hr, S_OK);
10308 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10309 EXPECT_HR(hr, S_OK);
10311 len = sizeof(buffW)/sizeof(WCHAR);
10312 buffW[0] = 0;
10313 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
10314 EXPECT_HR(hr, S_OK);
10315 ok(!lstrcmpW(buffW, _bstr_("ns0 uri")), "got uri %s\n", wine_dbgstr_w(buffW));
10317 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns0"), _bstr_("ns0 uri"));
10318 EXPECT_HR(hr, S_OK);
10320 len = sizeof(buffW)/sizeof(WCHAR);
10321 buffW[0] = 0;
10322 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 0, buffW, &len);
10323 EXPECT_HR(hr, S_OK);
10324 ok(!lstrcmpW(buffW, _bstr_("xml")), "got prefix %s\n", wine_dbgstr_w(buffW));
10326 len = sizeof(buffW)/sizeof(WCHAR);
10327 buffW[0] = 0;
10328 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10329 EXPECT_HR(hr, S_OK);
10330 ok(!lstrcmpW(buffW, _bstr_("ns0")), "got prefix %s\n", wine_dbgstr_w(buffW));
10332 len = sizeof(buffW)/sizeof(WCHAR);
10333 buffW[0] = 0;
10334 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 2, buffW, &len);
10335 EXPECT_HR(hr, S_OK);
10336 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
10338 /* new prefix placed at index 1 always */
10339 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_("ns1"), _bstr_("ns1 uri"));
10340 EXPECT_HR(hr, S_OK);
10342 len = sizeof(buffW)/sizeof(WCHAR);
10343 buffW[0] = 0;
10344 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 1, buffW, &len);
10345 EXPECT_HR(hr, S_OK);
10346 ok(!lstrcmpW(buffW, _bstr_("ns1")), "got prefix %s\n", wine_dbgstr_w(buffW));
10348 hr = IMXNamespaceManager_declarePrefix(nsmgr, _bstr_(""), NULL);
10349 todo_wine EXPECT_HR(hr, E_FAIL);
10351 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, NULL);
10352 EXPECT_HR(hr, E_FAIL);
10354 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri"));
10355 EXPECT_HR(hr, E_FAIL);
10357 hr = IMXNamespaceManager_putAllowOverride(nsmgr, VARIANT_TRUE);
10358 EXPECT_HR(hr, S_OK);
10360 hr = IMXNamespaceManager_declarePrefix(nsmgr, NULL, _bstr_("ns0 uri override"));
10361 EXPECT_HR(hr, S_FALSE);
10363 len = sizeof(buffW)/sizeof(WCHAR);
10364 buffW[0] = 0;
10365 hr = IMXNamespaceManager_getURI(nsmgr, _bstr_(""), NULL, buffW, &len);
10366 EXPECT_HR(hr, S_OK);
10367 ok(!lstrcmpW(buffW, _bstr_("ns0 uri override")), "got uri %s\n", wine_dbgstr_w(buffW));
10369 len = sizeof(buffW)/sizeof(WCHAR);
10370 buffW[0] = 0;
10371 hr = IMXNamespaceManager_getDeclaredPrefix(nsmgr, 3, buffW, &len);
10372 EXPECT_HR(hr, S_OK);
10373 ok(!lstrcmpW(buffW, _bstr_("")), "got prefix %s\n", wine_dbgstr_w(buffW));
10375 IMXNamespaceManager_Release(nsmgr);
10377 free_bstrs();
10380 static const DOMNodeType nodetypes_test[] =
10382 NODE_ELEMENT,
10383 NODE_ATTRIBUTE,
10384 NODE_TEXT,
10385 NODE_CDATA_SECTION,
10386 NODE_ENTITY_REFERENCE,
10387 NODE_PROCESSING_INSTRUCTION,
10388 NODE_COMMENT,
10389 NODE_DOCUMENT_FRAGMENT,
10390 NODE_INVALID
10393 static void test_dispex(void)
10395 const DOMNodeType *type = nodetypes_test;
10396 IXMLDOMImplementation *impl;
10397 IXMLDOMNodeList *node_list;
10398 IXMLDOMParseError *error;
10399 IXMLDOMNamedNodeMap *map;
10400 IXSLProcessor *processor;
10401 IXSLTemplate *template;
10402 IXMLDOMDocument *doc;
10403 IXMLHTTPRequest *req;
10404 IXMLDOMElement *elem;
10405 IDispatchEx *dispex;
10406 DISPPARAMS dispparams;
10407 IXMLDOMNode *node;
10408 VARIANT arg, ret;
10409 VARIANT_BOOL b;
10410 IUnknown *unk;
10411 HRESULT hr;
10412 DISPID did;
10414 doc = create_document(&IID_IXMLDOMDocument);
10416 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
10417 ok(hr == S_OK, "got 0x%08x\n", hr);
10418 test_domobj_dispex(unk);
10419 IUnknown_Release(unk);
10421 for(; *type != NODE_INVALID; type++)
10423 IXMLDOMNode *node;
10424 VARIANT v;
10426 V_VT(&v) = VT_I2;
10427 V_I2(&v) = *type;
10429 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("name"), NULL, &node);
10430 ok(hr == S_OK, "failed to create node type %d\n", *type);
10432 IXMLDOMNode_QueryInterface(node, &IID_IUnknown, (void**)&unk);
10434 test_domobj_dispex(unk);
10435 IUnknown_Release(unk);
10436 IXMLDOMNode_Release(node);
10439 /* IXMLDOMNodeList */
10440 hr = IXMLDOMDocument_getElementsByTagName(doc, _bstr_("*"), &node_list);
10441 EXPECT_HR(hr, S_OK);
10442 IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk);
10443 test_domobj_dispex(unk);
10444 IUnknown_Release(unk);
10445 IXMLDOMNodeList_Release(node_list);
10447 /* IXMLDOMNodeList for children list */
10448 hr = IXMLDOMDocument_get_childNodes(doc, &node_list);
10449 EXPECT_HR(hr, S_OK);
10450 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IUnknown, (void**)&unk);
10451 ok(hr == S_OK, "got 0x%08x\n", hr);
10452 test_domobj_dispex(unk);
10453 IUnknown_Release(unk);
10455 /* collection dispex test, empty collection */
10456 hr = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatchEx, (void**)&dispex);
10457 EXPECT_HR(hr, S_OK);
10458 did = 0;
10459 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
10460 EXPECT_HR(hr, S_OK);
10461 ok(did == DISPID_DOM_COLLECTION_BASE, "got 0x%08x\n", did);
10462 hr = IDispatchEx_GetDispID(dispex, _bstr_("1"), 0, &did);
10463 EXPECT_HR(hr, S_OK);
10464 ok(did == DISPID_DOM_COLLECTION_BASE+1, "got 0x%08x\n", did);
10465 IDispatchEx_Release(dispex);
10467 did = -1;
10468 hr = IDispatchEx_GetDispID(dispex, _bstr_("item"), 0, &did);
10469 ok(hr == S_OK, "got 0x%08x\n", hr);
10470 ok(did == DISPID_VALUE, "got %d\n", did);
10472 V_VT(&arg) = VT_I4;
10473 V_I4(&arg) = 0;
10474 dispparams.cArgs = 0;
10475 dispparams.cNamedArgs = 0;
10476 dispparams.rgdispidNamedArgs = NULL;
10477 dispparams.rgvarg = &arg;
10479 V_VT(&ret) = VT_EMPTY;
10480 V_DISPATCH(&ret) = (void*)0x1;
10481 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10482 ok(hr == DISP_E_BADPARAMCOUNT, "got 0x%08x\n", hr);
10483 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
10484 todo_wine
10485 ok(broken(V_DISPATCH(&ret) == (void*)0x1) || (V_DISPATCH(&ret) == NULL), "got %p\n", V_DISPATCH(&ret));
10487 V_VT(&arg) = VT_I4;
10488 V_I4(&arg) = 0;
10489 dispparams.cArgs = 2;
10490 dispparams.cNamedArgs = 0;
10491 dispparams.rgdispidNamedArgs = NULL;
10492 dispparams.rgvarg = &arg;
10494 V_VT(&ret) = VT_EMPTY;
10495 V_DISPATCH(&ret) = (void*)0x1;
10496 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10497 ok(hr == DISP_E_BADPARAMCOUNT, "got 0x%08x\n", hr);
10498 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
10499 todo_wine
10500 ok(broken(V_DISPATCH(&ret) == (void*)0x1) || (V_DISPATCH(&ret) == NULL), "got %p\n", V_DISPATCH(&ret));
10502 V_VT(&arg) = VT_I4;
10503 V_I4(&arg) = 0;
10504 dispparams.cArgs = 1;
10505 dispparams.cNamedArgs = 0;
10506 dispparams.rgdispidNamedArgs = NULL;
10507 dispparams.rgvarg = &arg;
10509 V_VT(&ret) = VT_EMPTY;
10510 V_DISPATCH(&ret) = (void*)0x1;
10511 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10512 ok(hr == S_OK, "got 0x%08x\n", hr);
10513 ok(V_VT(&ret) == VT_DISPATCH, "got %d\n", V_VT(&ret));
10514 ok(V_DISPATCH(&ret) == NULL, "got %p\n", V_DISPATCH(&ret));
10516 V_VT(&ret) = VT_EMPTY;
10517 V_DISPATCH(&ret) = (void*)0x1;
10518 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &ret, NULL, NULL);
10519 ok(hr == S_OK, "got 0x%08x\n", hr);
10520 ok(V_VT(&ret) == VT_DISPATCH, "got %d\n", V_VT(&ret));
10521 ok(V_DISPATCH(&ret) == NULL, "got %p\n", V_DISPATCH(&ret));
10523 V_VT(&ret) = VT_EMPTY;
10524 V_DISPATCH(&ret) = (void*)0x1;
10525 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10526 ok(hr == S_OK, "got 0x%08x\n", hr);
10527 ok(V_VT(&ret) == VT_DISPATCH, "got %d\n", V_VT(&ret));
10528 ok(V_DISPATCH(&ret) == NULL, "got %p\n", V_DISPATCH(&ret));
10530 dispparams.cArgs = 0;
10531 dispparams.cNamedArgs = 0;
10532 dispparams.rgdispidNamedArgs = NULL;
10533 dispparams.rgvarg = NULL;
10535 V_VT(&ret) = VT_EMPTY;
10536 V_I4(&ret) = 1;
10537 hr = IDispatchEx_Invoke(dispex, DISPID_DOM_NODELIST_LENGTH, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &ret, NULL, NULL);
10538 ok(hr == S_OK, "got 0x%08x\n", hr);
10539 ok(V_VT(&ret) == VT_I4, "got %d\n", V_VT(&ret));
10540 ok(V_I4(&ret) == 0, "got %d\n", V_I4(&ret));
10542 dispparams.cArgs = 0;
10543 dispparams.cNamedArgs = 0;
10544 dispparams.rgdispidNamedArgs = NULL;
10545 dispparams.rgvarg = NULL;
10547 V_VT(&ret) = VT_EMPTY;
10548 V_I4(&ret) = 1;
10549 hr = IDispatchEx_Invoke(dispex, DISPID_DOM_NODELIST_LENGTH, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10550 ok(hr == DISP_E_MEMBERNOTFOUND, "got 0x%08x\n", hr);
10551 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
10552 todo_wine
10553 ok(broken(V_I4(&ret) == 1) || (V_I4(&ret) == 0), "got %d\n", V_I4(&ret));
10555 IXMLDOMNodeList_Release(node_list);
10557 /* IXMLDOMParseError */
10558 hr = IXMLDOMDocument_get_parseError(doc, &error);
10559 EXPECT_HR(hr, S_OK);
10560 IXMLDOMParseError_QueryInterface(error, &IID_IUnknown, (void**)&unk);
10561 test_domobj_dispex(unk);
10563 hr = IXMLDOMParseError_QueryInterface(error, &IID_IDispatchEx, (void**)&dispex);
10564 ok(hr == S_OK, "got 0x%08x\n", hr);
10566 V_VT(&arg) = VT_I4;
10567 V_I4(&arg) = 0;
10568 dispparams.cArgs = 1;
10569 dispparams.cNamedArgs = 0;
10570 dispparams.rgdispidNamedArgs = NULL;
10571 dispparams.rgvarg = &arg;
10573 V_VT(&ret) = VT_EMPTY;
10574 V_DISPATCH(&ret) = (void*)0x1;
10575 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10576 ok(hr == DISP_E_MEMBERNOTFOUND, "got 0x%08x\n", hr);
10577 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
10578 todo_wine
10579 ok(broken(V_DISPATCH(&ret) == (void*)0x1) || (V_DISPATCH(&ret) == NULL), "got %p\n", V_DISPATCH(&ret));
10581 IDispatchEx_Release(dispex);
10583 IUnknown_Release(unk);
10584 IXMLDOMParseError_Release(error);
10586 /* IXMLDOMNamedNodeMap */
10587 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xpath_simple_list), &b);
10588 EXPECT_HR(hr, S_OK);
10590 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root/a"), &node_list);
10591 EXPECT_HR(hr, S_OK);
10592 hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
10593 EXPECT_HR(hr, S_OK);
10594 IXMLDOMNodeList_Release(node_list);
10596 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
10597 EXPECT_HR(hr, S_OK);
10598 IXMLDOMNode_Release(node);
10599 hr = IXMLDOMElement_get_attributes(elem, &map);
10600 EXPECT_HR(hr, S_OK);
10601 IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IUnknown, (void**)&unk);
10602 test_domobj_dispex(unk);
10603 IUnknown_Release(unk);
10604 /* collection dispex test */
10605 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IDispatchEx, (void**)&dispex);
10606 EXPECT_HR(hr, S_OK);
10607 did = 0;
10608 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
10609 EXPECT_HR(hr, S_OK);
10610 ok(did == DISPID_DOM_COLLECTION_BASE, "got 0x%08x\n", did);
10611 IDispatchEx_Release(dispex);
10612 IXMLDOMNamedNodeMap_Release(map);
10614 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("root/b"), &node_list);
10615 EXPECT_HR(hr, S_OK);
10616 hr = IXMLDOMNodeList_get_item(node_list, 0, &node);
10617 EXPECT_HR(hr, S_OK);
10618 IXMLDOMNodeList_Release(node_list);
10619 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
10620 EXPECT_HR(hr, S_OK);
10621 IXMLDOMNode_Release(node);
10622 hr = IXMLDOMElement_get_attributes(elem, &map);
10623 EXPECT_HR(hr, S_OK);
10624 /* collection dispex test, empty collection */
10625 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IDispatchEx, (void**)&dispex);
10626 EXPECT_HR(hr, S_OK);
10627 did = 0;
10628 hr = IDispatchEx_GetDispID(dispex, _bstr_("0"), 0, &did);
10629 EXPECT_HR(hr, S_OK);
10630 ok(did == DISPID_DOM_COLLECTION_BASE, "got 0x%08x\n", did);
10631 hr = IDispatchEx_GetDispID(dispex, _bstr_("1"), 0, &did);
10632 EXPECT_HR(hr, S_OK);
10633 ok(did == DISPID_DOM_COLLECTION_BASE+1, "got 0x%08x\n", did);
10634 IXMLDOMNamedNodeMap_Release(map);
10636 did = -1;
10637 hr = IDispatchEx_GetDispID(dispex, _bstr_("item"), 0, &did);
10638 ok(hr == S_OK, "got 0x%08x\n", hr);
10639 ok(did == DISPID_VALUE, "got %d\n", did);
10641 V_VT(&arg) = VT_I4;
10642 V_I4(&arg) = 0;
10643 dispparams.cArgs = 0;
10644 dispparams.cNamedArgs = 0;
10645 dispparams.rgdispidNamedArgs = NULL;
10646 dispparams.rgvarg = &arg;
10648 V_VT(&ret) = VT_EMPTY;
10649 V_DISPATCH(&ret) = (void*)0x1;
10650 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10651 todo_wine {
10652 ok(hr == DISP_E_BADPARAMCOUNT, "got 0x%08x\n", hr);
10653 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
10655 ok(broken(V_DISPATCH(&ret) == (void*)0x1) || (V_DISPATCH(&ret) == NULL), "got %p\n", V_DISPATCH(&ret));
10657 V_VT(&arg) = VT_I4;
10658 V_I4(&arg) = 0;
10659 dispparams.cArgs = 2;
10660 dispparams.cNamedArgs = 0;
10661 dispparams.rgdispidNamedArgs = NULL;
10662 dispparams.rgvarg = &arg;
10664 V_VT(&ret) = VT_EMPTY;
10665 V_DISPATCH(&ret) = (void*)0x1;
10666 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10667 todo_wine {
10668 ok(hr == DISP_E_BADPARAMCOUNT, "got 0x%08x\n", hr);
10669 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
10671 ok(broken(V_DISPATCH(&ret) == (void*)0x1) || (V_DISPATCH(&ret) == NULL), "got %p\n", V_DISPATCH(&ret));
10673 V_VT(&arg) = VT_I4;
10674 V_I4(&arg) = 0;
10675 dispparams.cArgs = 1;
10676 dispparams.cNamedArgs = 0;
10677 dispparams.rgdispidNamedArgs = NULL;
10678 dispparams.rgvarg = &arg;
10680 V_VT(&ret) = VT_EMPTY;
10681 V_DISPATCH(&ret) = (void*)0x1;
10682 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10683 todo_wine
10684 ok(hr == S_OK, "got 0x%08x\n", hr);
10685 ok(V_VT(&ret) == VT_DISPATCH, "got %d\n", V_VT(&ret));
10686 ok(V_DISPATCH(&ret) == NULL, "got %p\n", V_DISPATCH(&ret));
10688 V_VT(&ret) = VT_EMPTY;
10689 V_DISPATCH(&ret) = (void*)0x1;
10690 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &ret, NULL, NULL);
10691 ok(hr == S_OK, "got 0x%08x\n", hr);
10692 ok(V_VT(&ret) == VT_DISPATCH, "got %d\n", V_VT(&ret));
10693 ok(V_DISPATCH(&ret) == NULL, "got %p\n", V_DISPATCH(&ret));
10695 V_VT(&ret) = VT_EMPTY;
10696 V_DISPATCH(&ret) = (void*)0x1;
10697 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_PROPERTYGET|DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10698 ok(hr == S_OK, "got 0x%08x\n", hr);
10699 ok(V_VT(&ret) == VT_DISPATCH, "got %d\n", V_VT(&ret));
10700 ok(V_DISPATCH(&ret) == NULL, "got %p\n", V_DISPATCH(&ret));
10702 dispparams.cArgs = 0;
10703 dispparams.cNamedArgs = 0;
10704 dispparams.rgdispidNamedArgs = NULL;
10705 dispparams.rgvarg = NULL;
10707 V_VT(&ret) = VT_EMPTY;
10708 V_I4(&ret) = 1;
10709 hr = IDispatchEx_Invoke(dispex, DISPID_DOM_NODELIST_LENGTH, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &ret, NULL, NULL);
10710 ok(hr == S_OK, "got 0x%08x\n", hr);
10711 ok(V_VT(&ret) == VT_I4, "got %d\n", V_VT(&ret));
10712 ok(V_I4(&ret) == 0, "got %d\n", V_I4(&ret));
10714 dispparams.cArgs = 0;
10715 dispparams.cNamedArgs = 0;
10716 dispparams.rgdispidNamedArgs = NULL;
10717 dispparams.rgvarg = NULL;
10719 V_VT(&ret) = VT_EMPTY;
10720 V_I4(&ret) = 1;
10721 hr = IDispatchEx_Invoke(dispex, DISPID_DOM_NODELIST_LENGTH, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
10722 ok(hr == DISP_E_MEMBERNOTFOUND, "got 0x%08x\n", hr);
10723 todo_wine
10724 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
10725 ok(broken(V_I4(&ret) == 1) || (V_I4(&ret) == 0), "got %d\n", V_I4(&ret));
10727 IDispatchEx_Release(dispex);
10728 IXMLDOMElement_Release(elem);
10730 /* IXMLDOMImplementation */
10731 hr = IXMLDOMDocument_get_implementation(doc, &impl);
10732 EXPECT_HR(hr, S_OK);
10734 hr = IXMLDOMImplementation_QueryInterface(impl, &IID_IDispatchEx, (void**)&dispex);
10735 EXPECT_HR(hr, S_OK);
10736 IDispatchEx_Release(dispex);
10737 IXMLDOMImplementation_Release(impl);
10739 IXMLDOMDocument_Release(doc);
10741 /* IXMLHTTPRequest */
10742 hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
10743 &IID_IXMLHttpRequest, (void**)&req);
10744 if (hr == S_OK)
10746 hr = IXMLHTTPRequest_QueryInterface(req, &IID_IDispatchEx, (void**)&dispex);
10747 EXPECT_HR(hr, E_NOINTERFACE);
10748 IXMLHTTPRequest_Release(req);
10751 /* IXSLTemplate */
10752 template = create_xsltemplate(&IID_IXSLTemplate);
10753 hr = IXSLTemplate_QueryInterface(template, &IID_IDispatchEx, (void**)&dispex);
10754 EXPECT_HR(hr, S_OK);
10755 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
10756 EXPECT_HR(hr, S_OK);
10757 test_domobj_dispex(unk);
10758 IUnknown_Release(unk);
10759 IDispatchEx_Release(dispex);
10761 /* IXSLProcessor */
10762 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
10763 EXPECT_HR(hr, S_OK);
10764 b = VARIANT_FALSE;
10765 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformSSXML), &b);
10766 EXPECT_HR(hr, S_OK);
10767 ok(b == VARIANT_TRUE, "got %d\n", b);
10769 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
10770 EXPECT_HR(hr, S_OK);
10771 IXMLDOMDocument_Release(doc);
10773 hr = IXSLTemplate_createProcessor(template, &processor);
10774 EXPECT_HR(hr, S_OK);
10775 hr = IXSLProcessor_QueryInterface(processor, &IID_IDispatchEx, (void**)&dispex);
10776 EXPECT_HR(hr, S_OK);
10777 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
10778 EXPECT_HR(hr, S_OK);
10779 test_domobj_dispex(unk);
10780 IUnknown_Release(unk);
10781 IDispatchEx_Release(dispex);
10783 IXSLProcessor_Release(processor);
10784 IXSLTemplate_Release(template);
10786 if (is_clsid_supported(&CLSID_DOMDocument60, &IID_IXMLDOMDocument))
10788 doc = create_document_version(60, &IID_IXMLDOMDocument);
10789 test_domobj_dispex((IUnknown*)doc);
10790 IXMLDOMDocument_Release(doc);
10793 free_bstrs();
10796 static void test_parseerror(void)
10798 IXMLDOMParseError2 *error2;
10799 IXMLDOMParseError *error;
10800 IXMLDOMDocument *doc;
10801 HRESULT hr;
10803 doc = create_document(&IID_IXMLDOMDocument);
10805 hr = IXMLDOMDocument_get_parseError(doc, &error);
10806 EXPECT_HR(hr, S_OK);
10808 hr = IXMLDOMParseError_get_line(error, NULL);
10809 EXPECT_HR(hr, E_INVALIDARG);
10811 hr = IXMLDOMParseError_get_srcText(error, NULL);
10812 EXPECT_HR(hr, E_INVALIDARG);
10814 hr = IXMLDOMParseError_get_linepos(error, NULL);
10815 EXPECT_HR(hr, E_INVALIDARG);
10817 IXMLDOMParseError_Release(error);
10818 IXMLDOMDocument_Release(doc);
10820 if (!is_clsid_supported(&CLSID_DOMDocument60, &IID_IXMLDOMDocument)) return;
10821 doc = create_document_version(60, &IID_IXMLDOMDocument);
10823 hr = IXMLDOMDocument_get_parseError(doc, &error);
10824 EXPECT_HR(hr, S_OK);
10825 hr = IXMLDOMParseError_QueryInterface(error, &IID_IXMLDOMParseError2, (void**)&error2);
10826 EXPECT_HR(hr, S_OK);
10827 IXMLDOMParseError2_Release(error2);
10828 IXMLDOMParseError_Release(error);
10829 IXMLDOMDocument_Release(doc);
10832 static void test_getAttributeNode(void)
10834 IXMLDOMAttribute *attr;
10835 IXMLDOMDocument *doc;
10836 IXMLDOMElement *elem;
10837 VARIANT_BOOL v;
10838 HRESULT hr;
10839 BSTR str;
10841 doc = create_document(&IID_IXMLDOMDocument);
10843 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &v);
10844 EXPECT_HR(hr, S_OK);
10846 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
10847 EXPECT_HR(hr, S_OK);
10849 str = SysAllocString(nonexistent_fileW);
10850 hr = IXMLDOMElement_getAttributeNode(elem, str, NULL);
10851 EXPECT_HR(hr, E_FAIL);
10853 attr = (IXMLDOMAttribute*)0xdeadbeef;
10854 hr = IXMLDOMElement_getAttributeNode(elem, str, &attr);
10855 EXPECT_HR(hr, E_FAIL);
10856 ok(attr == NULL, "got %p\n", attr);
10857 SysFreeString(str);
10859 str = SysAllocString(nonexistent_attrW);
10860 hr = IXMLDOMElement_getAttributeNode(elem, str, NULL);
10861 EXPECT_HR(hr, S_FALSE);
10863 attr = (IXMLDOMAttribute*)0xdeadbeef;
10864 hr = IXMLDOMElement_getAttributeNode(elem, str, &attr);
10865 EXPECT_HR(hr, S_FALSE);
10866 ok(attr == NULL, "got %p\n", attr);
10867 SysFreeString(str);
10869 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("foo:b"), &attr);
10870 EXPECT_HR(hr, S_OK);
10871 IXMLDOMAttribute_Release(attr);
10873 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("b"), &attr);
10874 EXPECT_HR(hr, S_FALSE);
10876 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("a"), &attr);
10877 EXPECT_HR(hr, S_OK);
10878 IXMLDOMAttribute_Release(attr);
10880 IXMLDOMElement_Release(elem);
10881 IXMLDOMDocument_Release(doc);
10882 free_bstrs();
10885 typedef struct {
10886 DOMNodeType type;
10887 const char *name;
10888 REFIID iids[3];
10889 } supporterror_t;
10891 static const supporterror_t supporterror_test[] = {
10892 { NODE_ELEMENT, "element", { &IID_IXMLDOMNode, &IID_IXMLDOMElement } },
10893 { NODE_ATTRIBUTE, "attribute", { &IID_IXMLDOMNode, &IID_IXMLDOMAttribute } },
10894 { NODE_CDATA_SECTION, "cdata", { &IID_IXMLDOMNode, &IID_IXMLDOMCDATASection } },
10895 { NODE_ENTITY_REFERENCE, "entityref", { &IID_IXMLDOMNode, &IID_IXMLDOMEntityReference } },
10896 { NODE_PROCESSING_INSTRUCTION, "pi", { &IID_IXMLDOMNode, &IID_IXMLDOMProcessingInstruction } },
10897 { NODE_COMMENT, "comment", { &IID_IXMLDOMNode, &IID_IXMLDOMComment } },
10898 { NODE_DOCUMENT_FRAGMENT, "fragment", { &IID_IXMLDOMNode, &IID_IXMLDOMDocumentFragment } },
10899 { NODE_INVALID }
10902 static void test_supporterrorinfo(void)
10904 static REFIID iids[5] = { &IID_IXMLDOMNode, &IID_IXMLDOMDocument,
10905 &IID_IXMLDOMDocument2, &IID_IXMLDOMDocument3 };
10906 const supporterror_t *ptr = supporterror_test;
10907 ISupportErrorInfo *errorinfo, *info2;
10908 IXMLDOMSchemaCollection *schemacache;
10909 IXMLDOMNamedNodeMap *map, *map2;
10910 IXMLDOMDocument *doc;
10911 IXMLDOMElement *elem;
10912 VARIANT_BOOL b;
10913 IUnknown *unk;
10914 REFIID *iid;
10915 void *dummy;
10916 HRESULT hr;
10918 if (!is_clsid_supported(&CLSID_DOMDocument60, &IID_IXMLDOMDocument3)) return;
10919 doc = create_document_version(60, &IID_IXMLDOMDocument3);
10921 EXPECT_REF(doc, 1);
10922 hr = IXMLDOMDocument_QueryInterface(doc, &IID_ISupportErrorInfo, (void**)&errorinfo);
10923 EXPECT_HR(hr, S_OK);
10924 EXPECT_REF(doc, 1);
10925 ISupportErrorInfo_AddRef(errorinfo);
10926 EXPECT_REF(errorinfo, 2);
10927 EXPECT_REF(doc, 1);
10928 ISupportErrorInfo_Release(errorinfo);
10930 hr = IXMLDOMDocument_QueryInterface(doc, &IID_ISupportErrorInfo, (void**)&info2);
10931 EXPECT_HR(hr, S_OK);
10932 ok(errorinfo != info2, "got %p, %p\n", info2, errorinfo);
10934 /* error interface can't be queried back for DOM interface */
10935 hr = ISupportErrorInfo_QueryInterface(info2, &IID_IXMLDOMDocument, &dummy);
10936 EXPECT_HR(hr, E_NOINTERFACE);
10937 hr = ISupportErrorInfo_QueryInterface(info2, &IID_IXMLDOMNode, &dummy);
10938 EXPECT_HR(hr, E_NOINTERFACE);
10940 ISupportErrorInfo_Release(info2);
10942 iid = iids;
10943 while (*iid)
10945 hr = IXMLDOMDocument_QueryInterface(doc, *iid, (void**)&unk);
10946 EXPECT_HR(hr, S_OK);
10947 if (hr == S_OK)
10949 hr = ISupportErrorInfo_InterfaceSupportsErrorInfo(errorinfo, *iid);
10950 ok(hr == S_OK, "got 0x%08x for %s\n", hr, wine_dbgstr_guid(*iid));
10951 IUnknown_Release(unk);
10954 iid++;
10957 ISupportErrorInfo_Release(errorinfo);
10959 while (ptr->type != NODE_INVALID)
10961 IXMLDOMNode *node;
10962 VARIANT type;
10964 V_VT(&type) = VT_I1;
10965 V_I1(&type) = ptr->type;
10967 hr = IXMLDOMDocument_createNode(doc, type, _bstr_(ptr->name), NULL, &node);
10968 ok(hr == S_OK, "%d: got 0x%08x\n", ptr->type, hr);
10970 EXPECT_REF(node, 1);
10971 hr = IXMLDOMNode_QueryInterface(node, &IID_ISupportErrorInfo, (void**)&errorinfo);
10972 ok(hr == S_OK, "%d: got 0x%08x\n", ptr->type, hr);
10973 EXPECT_REF(node, 1);
10975 hr = ISupportErrorInfo_QueryInterface(errorinfo, &IID_IXMLDOMNode, &dummy);
10976 ok(hr == E_NOINTERFACE, "%d: got 0x%08x\n", ptr->type, hr);
10978 iid = ptr->iids;
10980 while (*iid)
10982 hr = IXMLDOMNode_QueryInterface(node, *iid, (void**)&unk);
10983 if (hr == S_OK)
10985 hr = ISupportErrorInfo_InterfaceSupportsErrorInfo(errorinfo, *iid);
10986 ok(hr == S_OK, "%d: got 0x%08x for %s\n", ptr->type, hr, wine_dbgstr_guid(*iid));
10987 IUnknown_Release(unk);
10990 iid++;
10993 ISupportErrorInfo_Release(errorinfo);
10994 IXMLDOMNode_Release(node);
10995 ptr++;
10998 /* IXMLDOMNamedNodeMap */
10999 b = VARIANT_FALSE;
11000 hr = IXMLDOMDocument_loadXML(doc, _bstr_(complete4A), &b);
11001 EXPECT_HR(hr, S_OK);
11002 ok(b == VARIANT_TRUE, "got %d\n", b);
11004 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
11005 EXPECT_HR(hr, S_OK);
11007 hr = IXMLDOMElement_get_attributes(elem, &map);
11008 EXPECT_HR(hr, S_OK);
11010 EXPECT_REF(map, 1);
11011 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_ISupportErrorInfo, (void**)&errorinfo);
11012 EXPECT_HR(hr, S_OK);
11013 EXPECT_REF(map, 2);
11015 hr = ISupportErrorInfo_InterfaceSupportsErrorInfo(errorinfo, &IID_IXMLDOMNamedNodeMap);
11016 EXPECT_HR(hr, S_OK);
11018 hr = ISupportErrorInfo_QueryInterface(errorinfo, &IID_IXMLDOMNamedNodeMap, (void**)&map2);
11019 EXPECT_HR(hr, S_OK);
11020 ok(map == map2, "got %p\n", map2);
11021 IXMLDOMNamedNodeMap_Release(map2);
11023 EXPECT_REF(errorinfo, 2);
11024 hr = ISupportErrorInfo_QueryInterface(errorinfo, &IID_IUnknown, (void**)&unk);
11025 EXPECT_HR(hr, S_OK);
11026 EXPECT_REF(errorinfo, 3);
11027 EXPECT_REF(map, 3);
11028 IUnknown_Release(unk);
11030 ISupportErrorInfo_Release(errorinfo);
11031 IXMLDOMNamedNodeMap_Release(map);
11032 IXMLDOMElement_Release(elem);
11034 IXMLDOMDocument_Release(doc);
11036 /* IXMLDOMSchemaCollection */
11037 hr = CoCreateInstance(&CLSID_XMLSchemaCache, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMSchemaCollection, (void**)&schemacache);
11038 ok(hr == S_OK, "failed to create schema collection, 0x%08x\n", hr);
11040 hr = IXMLDOMSchemaCollection_QueryInterface(schemacache, &IID_ISupportErrorInfo, (void**)&errorinfo);
11041 ok(hr == S_OK, "got 0x%08x\n", hr);
11043 hr = ISupportErrorInfo_InterfaceSupportsErrorInfo(errorinfo, &IID_IXMLDOMSchemaCollection);
11044 ok(hr == S_OK, "got 0x%08x\n", hr);
11046 ISupportErrorInfo_Release(errorinfo);
11047 IXMLDOMSchemaCollection_Release(schemacache);
11049 free_bstrs();
11052 typedef struct {
11053 DOMNodeType type;
11054 const char *name;
11055 const char *put_content;
11056 HRESULT put_hr;
11057 VARTYPE get_vt;
11058 HRESULT get_hr;
11059 } node_value_t;
11061 static const node_value_t nodevalue_test[] = {
11062 { NODE_ELEMENT, "element", "", E_FAIL, VT_NULL, S_FALSE },
11063 { NODE_ATTRIBUTE, "attr", "value", S_OK, VT_BSTR, S_OK },
11064 { NODE_TEXT, "text", "textdata", S_OK, VT_BSTR, S_OK },
11065 { NODE_CDATA_SECTION , "cdata", "cdata data", S_OK, VT_BSTR, S_OK },
11066 { NODE_ENTITY_REFERENCE, "entityref", "ref", E_FAIL, VT_NULL, S_FALSE },
11067 { NODE_PROCESSING_INSTRUCTION, "pi", "instr", S_OK, VT_BSTR, S_OK },
11068 { NODE_COMMENT, "comment", "comment data", S_OK, VT_BSTR, S_OK },
11069 { NODE_DOCUMENT_FRAGMENT, "docfrag", "", E_FAIL, VT_NULL, S_FALSE },
11070 { NODE_INVALID }
11073 static void test_nodeValue(void)
11075 const node_value_t *ptr = nodevalue_test;
11076 IXMLDOMDocument *doc;
11077 HRESULT hr;
11079 doc = create_document(&IID_IXMLDOMDocument);
11081 while (ptr->type != NODE_INVALID)
11083 IXMLDOMNode *node;
11084 VARIANT v;
11086 V_VT(&v) = VT_I2;
11087 V_I2(&v) = ptr->type;
11089 hr = IXMLDOMDocument_createNode(doc, v, _bstr_(ptr->name), NULL, &node);
11090 ok(hr == S_OK, "failed to create node type %d\n", ptr->type);
11092 hr = IXMLDOMNode_get_nodeValue(node, NULL);
11093 ok(hr == E_INVALIDARG, "%d: got 0x%08x\n", ptr->type, hr);
11095 V_VT(&v) = VT_BSTR;
11096 V_BSTR(&v) = _bstr_(ptr->put_content);
11097 hr = IXMLDOMNode_put_nodeValue(node, v);
11098 ok(hr == ptr->put_hr, "%d: got 0x%08x\n", ptr->type, hr);
11100 V_VT(&v) = VT_EMPTY;
11101 hr = IXMLDOMNode_get_nodeValue(node, &v);
11102 ok(hr == ptr->get_hr, "%d: got 0x%08x, expected 0x%08x\n", ptr->type, hr, ptr->get_hr);
11103 ok(V_VT(&v) == ptr->get_vt, "%d: got %d, expected %d\n", ptr->type, V_VT(&v), ptr->get_vt);
11104 if (hr == S_OK)
11105 ok(!lstrcmpW(V_BSTR(&v), _bstr_(ptr->put_content)), "%d: got %s\n", ptr->type,
11106 wine_dbgstr_w(V_BSTR(&v)));
11107 VariantClear(&v);
11109 IXMLDOMNode_Release(node);
11111 ptr++;
11114 IXMLDOMDocument_Release(doc);
11117 static void test_xmlns_attribute(void)
11119 BSTR str;
11120 IXMLDOMDocument *doc;
11121 IXMLDOMElement *root;
11122 IXMLDOMAttribute *pAttribute;
11123 IXMLDOMElement *elem;
11124 HRESULT hr;
11125 VARIANT v;
11127 doc = create_document(&IID_IXMLDOMDocument);
11129 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
11130 EXPECT_HR(hr, S_OK);
11132 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
11133 EXPECT_HR(hr, S_OK);
11135 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("xmlns:dt"), &pAttribute);
11136 ok( hr == S_OK, "returns %08x\n", hr );
11138 V_VT(&v) = VT_BSTR;
11139 V_BSTR(&v) = _bstr_("urn:schemas-microsoft-com:datatypes");
11140 hr = IXMLDOMAttribute_put_nodeValue(pAttribute, v);
11141 ok(hr == S_OK, "ret %08x\n", hr );
11143 hr = IXMLDOMElement_setAttributeNode(root, pAttribute, NULL);
11144 ok(hr == S_OK, "ret %08x\n", hr );
11146 hr = IXMLDOMNode_put_dataType((IXMLDOMNode*)root, _bstr_("bin.base64"));
11147 ok(hr == S_OK, "ret %08x\n", hr );
11149 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
11150 EXPECT_HR(hr, S_OK);
11152 str = NULL;
11153 hr = IXMLDOMElement_get_xml(elem, &str);
11154 ok( hr == S_OK, "got 0x%08x\n", hr);
11155 todo_wine ok( lstrcmpW(str, _bstr_("<Testing xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"bin.base64\"/>")) == 0,
11156 "got %s\n", wine_dbgstr_w(str));
11157 SysFreeString(str);
11159 IXMLDOMElement_Release(elem);
11160 IXMLDOMAttribute_Release( pAttribute);
11162 IXMLDOMDocument_Release(doc);
11164 free_bstrs();
11167 static const char namespacesA[] =
11168 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
11169 " <ns1:elem1 xmlns:ns1=\"http://blah.org\" b='1' >"
11170 " <ns2:elem2 xmlns:ns2=\"http://blah.org\"/>"
11171 " <ns1:elem3/>"
11172 " <ns1:elem4/>"
11173 " <elem5 xmlns=\"http://blahblah.org\"/>"
11174 " <ns1:elem6>true</ns1:elem6>"
11175 " </ns1:elem1>";
11177 static const char xsd_schema1_uri[] = "x-schema:test1.xsd";
11178 static const char xsd_schema1_xml[] =
11179 "<?xml version='1.0'?>"
11180 "<schema xmlns='http://www.w3.org/2001/XMLSchema'"
11181 " targetNamespace='x-schema:test1.xsd'>"
11182 " <element name='root'>"
11183 " <complexType>"
11184 " <sequence maxOccurs='unbounded'>"
11185 " <any/>"
11186 " </sequence>"
11187 " </complexType>"
11188 " </element>"
11189 "</schema>";
11191 static void test_get_namespaces(void)
11193 IXMLDOMSchemaCollection *collection, *collection2;
11194 IXMLDOMDocument2 *doc, *doc2;
11195 IEnumVARIANT *enumv, *enum2;
11196 IUnknown *unk1, *unk2;
11197 IXMLDOMNode *node;
11198 VARIANT_BOOL b;
11199 HRESULT hr;
11200 VARIANT v;
11201 LONG len;
11202 BSTR s;
11204 if (!is_clsid_supported(&CLSID_DOMDocument2, &IID_IXMLDOMDocument2)) return;
11205 doc = create_document(&IID_IXMLDOMDocument2);
11207 /* null pointer */
11208 hr = IXMLDOMDocument2_get_namespaces(doc, NULL);
11209 EXPECT_HR(hr, E_POINTER);
11211 /* no document loaded */
11212 collection = (void*)0xdeadbeef;
11213 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
11214 EXPECT_HR(hr, S_OK);
11215 if (hr != S_OK)
11217 IXMLDOMDocument2_Release(doc);
11218 return;
11220 EXPECT_REF(collection, 2);
11222 collection2 = (void*)0xdeadbeef;
11223 hr = IXMLDOMDocument2_get_namespaces(doc, &collection2);
11224 EXPECT_HR(hr, S_OK);
11225 ok(collection == collection2, "got %p\n", collection2);
11226 EXPECT_REF(collection, 3);
11227 IXMLDOMSchemaCollection_Release(collection);
11229 len = -1;
11230 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
11231 EXPECT_HR(hr, S_OK);
11232 ok(len == 0, "got %d\n", len);
11233 IXMLDOMSchemaCollection_Release(collection);
11235 /* now with document */
11236 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(namespacesA), &b);
11237 EXPECT_HR(hr, S_OK);
11239 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
11240 EXPECT_HR(hr, S_OK);
11242 len = -1;
11243 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
11244 EXPECT_HR(hr, S_OK);
11245 ok(len == 2, "got %d\n", len);
11247 /* try to lookup some uris */
11248 node = (void*)0xdeadbeef;
11249 hr = IXMLDOMSchemaCollection_get(collection, _bstr_("http://blah.org"), &node);
11250 EXPECT_HR(hr, S_OK);
11251 ok(node == NULL, "got %p\n", node);
11253 node = (void*)0xdeadbeef;
11254 hr = IXMLDOMSchemaCollection_get(collection, _bstr_("http://blah1.org"), &node);
11255 EXPECT_HR(hr, S_OK);
11256 ok(node == NULL, "got %p\n", node);
11258 /* load schema and try to add it */
11259 doc2 = create_document(&IID_IXMLDOMDocument2);
11260 hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(xsd_schema1_xml), &b);
11261 EXPECT_HR(hr, S_OK);
11263 V_VT(&v) = VT_DISPATCH;
11264 V_DISPATCH(&v) = (IDispatch*)doc2;
11265 hr = IXMLDOMSchemaCollection_add(collection, _bstr_(xsd_schema1_uri), v);
11266 EXPECT_HR(hr, E_FAIL);
11268 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 0, &s);
11269 EXPECT_HR(hr, S_OK);
11270 ok(!lstrcmpW(s, _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(s));
11271 SysFreeString(s);
11273 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 1, &s);
11274 EXPECT_HR(hr, S_OK);
11275 ok(!lstrcmpW(s, _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(s));
11276 SysFreeString(s);
11278 s = (void*)0xdeadbeef;
11279 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 2, &s);
11280 EXPECT_HR(hr, E_FAIL);
11281 ok(s == (void*)0xdeadbeef, "got %p\n", s);
11283 /* enumerate */
11284 enumv = (void*)0xdeadbeef;
11285 EXPECT_REF(collection, 2);
11286 hr = IXMLDOMSchemaCollection_get__newEnum(collection, (IUnknown**)&enumv);
11287 EXPECT_HR(hr, S_OK);
11288 EXPECT_REF(collection, 3);
11289 ok(enumv != NULL, "got %p\n", enumv);
11291 hr = IXMLDOMSchemaCollection_QueryInterface(collection, &IID_IUnknown, (void**)&unk1);
11292 EXPECT_HR(hr, S_OK);
11293 hr = IEnumVARIANT_QueryInterface(enumv, &IID_IUnknown, (void**)&unk2);
11294 EXPECT_HR(hr, S_OK);
11295 ok(unk1 != unk2, "got %p, %p\n", unk1, unk2);
11296 IUnknown_Release(unk1);
11297 IUnknown_Release(unk2);
11299 hr = IXMLDOMSchemaCollection_QueryInterface(collection, &IID_IEnumVARIANT, (void**)&enum2);
11300 EXPECT_HR(hr, E_NOINTERFACE);
11302 V_VT(&v) = VT_EMPTY;
11303 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
11304 EXPECT_HR(hr, S_OK);
11305 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
11306 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
11307 VariantClear(&v);
11309 V_VT(&v) = VT_EMPTY;
11310 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
11311 EXPECT_HR(hr, S_OK);
11312 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
11313 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
11314 VariantClear(&v);
11316 V_VT(&v) = VT_NULL;
11317 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
11318 EXPECT_HR(hr, S_FALSE);
11319 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
11321 IEnumVARIANT_Release(enumv);
11322 IXMLDOMSchemaCollection_Release(collection);
11324 IXMLDOMDocument2_Release(doc);
11326 /* now with CLSID_DOMDocument60 */
11327 if (!is_clsid_supported(&CLSID_DOMDocument60, &IID_IXMLDOMDocument2)) return;
11328 doc = create_document_version(60, &IID_IXMLDOMDocument2);
11330 /* null pointer */
11331 hr = IXMLDOMDocument2_get_namespaces(doc, NULL);
11332 EXPECT_HR(hr, E_POINTER);
11334 /* no document loaded */
11335 collection = (void*)0xdeadbeef;
11336 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
11337 EXPECT_HR(hr, S_OK);
11338 if (hr != S_OK)
11340 IXMLDOMDocument2_Release(doc);
11341 return;
11343 EXPECT_REF(collection, 2);
11345 collection2 = (void*)0xdeadbeef;
11346 hr = IXMLDOMDocument2_get_namespaces(doc, &collection2);
11347 EXPECT_HR(hr, S_OK);
11348 ok(collection == collection2, "got %p\n", collection2);
11349 EXPECT_REF(collection, 3);
11350 IXMLDOMSchemaCollection_Release(collection);
11352 len = -1;
11353 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
11354 EXPECT_HR(hr, S_OK);
11355 ok(len == 0, "got %d\n", len);
11356 IXMLDOMSchemaCollection_Release(collection);
11358 /* now with document */
11359 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(namespacesA), &b);
11360 EXPECT_HR(hr, S_OK);
11362 hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
11363 EXPECT_HR(hr, S_OK);
11365 len = -1;
11366 hr = IXMLDOMSchemaCollection_get_length(collection, &len);
11367 EXPECT_HR(hr, S_OK);
11368 ok(len == 2, "got %d\n", len);
11370 /* try to lookup some uris */
11371 node = (void*)0xdeadbeef;
11372 hr = IXMLDOMSchemaCollection_get(collection, _bstr_("http://blah.org"), &node);
11373 EXPECT_HR(hr, E_NOTIMPL);
11374 ok(broken(node == (void*)0xdeadbeef) || (node == NULL), "got %p\n", node);
11376 /* load schema and try to add it */
11377 doc2 = create_document(&IID_IXMLDOMDocument2);
11378 hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(xsd_schema1_xml), &b);
11379 EXPECT_HR(hr, S_OK);
11381 V_VT(&v) = VT_DISPATCH;
11382 V_DISPATCH(&v) = (IDispatch*)doc2;
11383 hr = IXMLDOMSchemaCollection_add(collection, _bstr_(xsd_schema1_uri), v);
11384 EXPECT_HR(hr, E_FAIL);
11385 IXMLDOMDocument2_Release(doc2);
11387 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 0, &s);
11388 EXPECT_HR(hr, S_OK);
11389 ok(!lstrcmpW(s, _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(s));
11390 SysFreeString(s);
11392 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 1, &s);
11393 EXPECT_HR(hr, S_OK);
11394 ok(!lstrcmpW(s, _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(s));
11395 SysFreeString(s);
11397 s = (void*)0xdeadbeef;
11398 hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 2, &s);
11399 EXPECT_HR(hr, E_FAIL);
11400 ok(broken(s == (void*)0xdeadbeef) || (s == NULL), "got %p\n", s);
11402 /* enumerate */
11403 enumv = (void*)0xdeadbeef;
11404 hr = IXMLDOMSchemaCollection_get__newEnum(collection, (IUnknown**)&enumv);
11405 EXPECT_HR(hr, S_OK);
11406 ok(enumv != NULL, "got %p\n", enumv);
11408 V_VT(&v) = VT_EMPTY;
11409 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
11410 EXPECT_HR(hr, S_OK);
11411 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
11412 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
11413 VariantClear(&v);
11415 V_VT(&v) = VT_EMPTY;
11416 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
11417 EXPECT_HR(hr, S_OK);
11418 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
11419 ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
11420 VariantClear(&v);
11422 V_VT(&v) = VT_NULL;
11423 hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
11424 EXPECT_HR(hr, S_FALSE);
11425 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
11427 IEnumVARIANT_Release(enumv);
11428 IXMLDOMSchemaCollection_Release(collection);
11429 IXMLDOMDocument2_Release(doc);
11430 free_bstrs();
11433 static DOMNodeType put_data_types[] = {
11434 NODE_TEXT,
11435 NODE_CDATA_SECTION,
11436 NODE_PROCESSING_INSTRUCTION,
11437 NODE_COMMENT,
11438 NODE_INVALID
11441 static void test_put_data(void)
11443 static const WCHAR test_data[] = {'t','e','s','t',' ','n','o','d','e',' ','d','a','t','a',0};
11444 WCHAR buff[100], *data;
11445 IXMLDOMDocument *doc;
11446 DOMNodeType *type;
11447 IXMLDOMText *text;
11448 IXMLDOMNode *node;
11449 VARIANT v;
11450 BSTR get_data;
11451 HRESULT hr;
11453 doc = create_document(&IID_IXMLDOMDocument);
11455 memcpy(&buff[2], test_data, sizeof(test_data));
11456 /* just a big length */
11457 *(DWORD*)buff = 0xf0f0;
11458 data = &buff[2];
11460 type = put_data_types;
11461 while (*type != NODE_INVALID)
11463 V_VT(&v) = VT_I2;
11464 V_I2(&v) = *type;
11466 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("name"), NULL, &node);
11467 EXPECT_HR(hr, S_OK);
11469 /* put_data() is interface-specific */
11470 switch (*type)
11472 case NODE_TEXT:
11474 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
11475 EXPECT_HR(hr, S_OK);
11476 hr = IXMLDOMText_put_data(text, data);
11477 EXPECT_HR(hr, S_OK);
11479 hr = IXMLDOMText_get_data(text, &get_data);
11480 EXPECT_HR(hr, S_OK);
11482 IXMLDOMText_Release(text);
11483 break;
11485 case NODE_CDATA_SECTION:
11487 IXMLDOMCDATASection *cdata;
11489 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
11490 EXPECT_HR(hr, S_OK);
11491 hr = IXMLDOMCDATASection_put_data(cdata, data);
11492 EXPECT_HR(hr, S_OK);
11494 hr = IXMLDOMCDATASection_get_data(cdata, &get_data);
11495 EXPECT_HR(hr, S_OK);
11497 IXMLDOMCDATASection_Release(cdata);
11498 break;
11500 case NODE_PROCESSING_INSTRUCTION:
11502 IXMLDOMProcessingInstruction *pi;
11504 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMProcessingInstruction, (void**)&pi);
11505 EXPECT_HR(hr, S_OK);
11506 hr = IXMLDOMProcessingInstruction_put_data(pi, data);
11507 EXPECT_HR(hr, S_OK);
11509 hr = IXMLDOMProcessingInstruction_get_data(pi, &get_data);
11510 EXPECT_HR(hr, S_OK);
11512 IXMLDOMProcessingInstruction_Release(pi);
11513 break;
11515 case NODE_COMMENT:
11517 IXMLDOMComment *comment;
11519 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
11520 EXPECT_HR(hr, S_OK);
11521 hr = IXMLDOMComment_put_data(comment, data);
11522 EXPECT_HR(hr, S_OK);
11524 hr = IXMLDOMComment_get_data(comment, &get_data);
11525 EXPECT_HR(hr, S_OK);
11527 IXMLDOMComment_Release(comment);
11528 break;
11530 default:
11531 break;
11534 /* compare */
11535 ok(!lstrcmpW(data, get_data), "%d: got wrong data %s, expected %s\n", *type, wine_dbgstr_w(get_data),
11536 wine_dbgstr_w(data));
11537 SysFreeString(get_data);
11539 IXMLDOMNode_Release(node);
11540 type++;
11543 /* \r\n sequence is never escaped */
11544 V_VT(&v) = VT_I2;
11545 V_I2(&v) = NODE_TEXT;
11547 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("name"), NULL, &node);
11548 ok(hr == S_OK, "got 0x%08x\n", hr);
11550 IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
11552 hr = IXMLDOMText_put_data(text, _bstr_("\r\n"));
11553 ok(hr == S_OK, "got 0x%08x\n", hr);
11555 hr = IXMLDOMText_get_data(text, &get_data);
11556 ok(hr == S_OK, "got 0x%08x\n", hr);
11557 todo_wine
11558 ok(!lstrcmpW(get_data, _bstr_("\n")), "got %s\n", wine_dbgstr_w(get_data));
11559 SysFreeString(get_data);
11561 hr = IXMLDOMText_get_xml(text, &get_data);
11562 ok(hr == S_OK, "got 0x%08x\n", hr);
11563 ok(!lstrcmpW(get_data, _bstr_("\r\n")), "got %s\n", wine_dbgstr_w(get_data));
11564 SysFreeString(get_data);
11566 IXMLDOMText_Release(text);
11567 IXMLDOMNode_Release(node);
11569 IXMLDOMDocument_Release(doc);
11570 free_bstrs();
11573 static void test_putref_schemas(void)
11575 IXMLDOMSchemaCollection *cache;
11576 IXMLDOMDocument2 *doc;
11577 VARIANT schema;
11578 HRESULT hr;
11580 if (!is_clsid_supported(&CLSID_DOMDocument2, &IID_IXMLDOMDocument2)) return;
11581 if (!is_clsid_supported(&CLSID_XMLSchemaCache, &IID_IXMLDOMSchemaCollection)) return;
11583 doc = create_document(&IID_IXMLDOMDocument2);
11584 cache = create_cache(&IID_IXMLDOMSchemaCollection);
11586 /* set to NULL iface when no schema is set */
11587 V_VT(&schema) = VT_DISPATCH;
11588 V_DISPATCH(&schema) = NULL;
11589 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
11590 EXPECT_HR(hr, S_OK);
11592 V_VT(&schema) = VT_UNKNOWN;
11593 V_UNKNOWN(&schema) = NULL;
11594 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
11595 EXPECT_HR(hr, S_OK);
11597 /* set as VT_DISPATCH, reset with it */
11598 V_VT(&schema) = VT_DISPATCH;
11599 V_DISPATCH(&schema) = (IDispatch*)cache;
11600 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
11601 EXPECT_HR(hr, S_OK);
11603 V_DISPATCH(&schema) = NULL;
11604 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
11605 EXPECT_HR(hr, S_OK);
11606 ok(V_DISPATCH(&schema) == (IDispatch*)cache, "got %p\n", V_DISPATCH(&schema));
11608 V_VT(&schema) = VT_DISPATCH;
11609 V_DISPATCH(&schema) = NULL;
11610 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
11611 EXPECT_HR(hr, S_OK);
11613 V_DISPATCH(&schema) = (IDispatch*)0xdeadbeef;
11614 V_VT(&schema) = VT_I2;
11615 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
11616 EXPECT_HR(hr, S_FALSE);
11617 ok(V_DISPATCH(&schema) == NULL, "got %p\n", V_DISPATCH(&schema));
11618 ok(V_VT(&schema) == VT_NULL, "got %d\n", V_VT(&schema));
11620 /* set as VT_UNKNOWN, reset with it */
11621 V_VT(&schema) = VT_UNKNOWN;
11622 V_UNKNOWN(&schema) = (IUnknown*)cache;
11623 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
11624 EXPECT_HR(hr, S_OK);
11626 V_DISPATCH(&schema) = NULL;
11627 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
11628 EXPECT_HR(hr, S_OK);
11629 ok(V_DISPATCH(&schema) == (IDispatch*)cache, "got %p\n", V_DISPATCH(&schema));
11631 V_VT(&schema) = VT_UNKNOWN;
11632 V_UNKNOWN(&schema) = NULL;
11633 hr = IXMLDOMDocument2_putref_schemas(doc, schema);
11634 EXPECT_HR(hr, S_OK);
11636 V_DISPATCH(&schema) = (IDispatch*)0xdeadbeef;
11637 V_VT(&schema) = VT_I2;
11638 hr = IXMLDOMDocument2_get_schemas(doc, &schema);
11639 EXPECT_HR(hr, S_FALSE);
11640 ok(V_DISPATCH(&schema) == NULL, "got %p\n", V_DISPATCH(&schema));
11641 ok(V_VT(&schema) == VT_NULL, "got %d\n", V_VT(&schema));
11643 IXMLDOMSchemaCollection_Release(cache);
11644 IXMLDOMDocument2_Release(doc);
11647 static void test_namedmap_newenum(void)
11649 IEnumVARIANT *enum1, *enum2, *enum3;
11650 IXMLDOMNamedNodeMap *map;
11651 IUnknown *unk1, *unk2;
11652 IXMLDOMDocument *doc;
11653 IXMLDOMElement *elem;
11654 IXMLDOMNode *node;
11655 VARIANT_BOOL b;
11656 HRESULT hr;
11657 VARIANT v;
11658 BSTR str;
11660 doc = create_document(&IID_IXMLDOMDocument);
11662 hr = IXMLDOMDocument_loadXML(doc, _bstr_(attributes_map), &b);
11663 EXPECT_HR(hr, S_OK);
11665 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
11666 EXPECT_HR(hr, S_OK);
11668 hr = IXMLDOMElement_get_attributes(elem, &map);
11669 EXPECT_HR(hr, S_OK);
11670 IXMLDOMElement_Release(elem);
11672 enum1 = NULL;
11673 EXPECT_REF(map, 1);
11674 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IEnumVARIANT, (void**)&enum1);
11675 EXPECT_HR(hr, S_OK);
11676 ok(enum1 != NULL, "got %p\n", enum1);
11677 EXPECT_REF(map, 1);
11678 EXPECT_REF(enum1, 2);
11680 enum2 = NULL;
11681 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IEnumVARIANT, (void**)&enum2);
11682 EXPECT_HR(hr, S_OK);
11683 ok(enum2 == enum1, "got %p\n", enum2);
11685 IEnumVARIANT_Release(enum2);
11687 EXPECT_REF(map, 1);
11688 hr = IXMLDOMNamedNodeMap__newEnum(map, (IUnknown**)&enum2);
11689 EXPECT_HR(hr, S_OK);
11690 EXPECT_REF(map, 2);
11691 EXPECT_REF(enum2, 1);
11692 ok(enum2 != enum1, "got %p, %p\n", enum2, enum1);
11694 IEnumVARIANT_Release(enum1);
11696 /* enumerator created with _newEnum() doesn't share IUnknown* with main object */
11697 hr = IXMLDOMNamedNodeMap_QueryInterface(map, &IID_IUnknown, (void**)&unk1);
11698 EXPECT_HR(hr, S_OK);
11699 hr = IEnumVARIANT_QueryInterface(enum2, &IID_IUnknown, (void**)&unk2);
11700 EXPECT_HR(hr, S_OK);
11701 EXPECT_REF(map, 3);
11702 EXPECT_REF(enum2, 2);
11703 ok(unk1 != unk2, "got %p, %p\n", unk1, unk2);
11704 IUnknown_Release(unk1);
11705 IUnknown_Release(unk2);
11707 hr = IXMLDOMNamedNodeMap__newEnum(map, (IUnknown**)&enum3);
11708 EXPECT_HR(hr, S_OK);
11709 ok(enum2 != enum3, "got %p, %p\n", enum2, enum3);
11710 IEnumVARIANT_Release(enum3);
11712 /* iteration tests */
11713 hr = IXMLDOMNamedNodeMap_get_item(map, 0, &node);
11714 EXPECT_HR(hr, S_OK);
11715 hr = IXMLDOMNode_get_nodeName(node, &str);
11716 EXPECT_HR(hr, S_OK);
11717 ok(!lstrcmpW(str, _bstr_("attr1")), "got %s\n", wine_dbgstr_w(str));
11718 SysFreeString(str);
11719 IXMLDOMNode_Release(node);
11721 hr = IXMLDOMNamedNodeMap_nextNode(map, &node);
11722 EXPECT_HR(hr, S_OK);
11723 hr = IXMLDOMNode_get_nodeName(node, &str);
11724 EXPECT_HR(hr, S_OK);
11725 ok(!lstrcmpW(str, _bstr_("attr1")), "got %s\n", wine_dbgstr_w(str));
11726 SysFreeString(str);
11727 IXMLDOMNode_Release(node);
11729 V_VT(&v) = VT_EMPTY;
11730 hr = IEnumVARIANT_Next(enum2, 1, &v, NULL);
11731 EXPECT_HR(hr, S_OK);
11732 ok(V_VT(&v) == VT_DISPATCH, "got var type %d\n", V_VT(&v));
11733 hr = IDispatch_QueryInterface(V_DISPATCH(&v), &IID_IXMLDOMNode, (void**)&node);
11734 EXPECT_HR(hr, S_OK);
11735 hr = IXMLDOMNode_get_nodeName(node, &str);
11736 EXPECT_HR(hr, S_OK);
11737 ok(!lstrcmpW(str, _bstr_("attr1")), "got node name %s\n", wine_dbgstr_w(str));
11738 SysFreeString(str);
11739 IXMLDOMNode_Release(node);
11740 VariantClear(&v);
11742 hr = IXMLDOMNamedNodeMap_nextNode(map, &node);
11743 EXPECT_HR(hr, S_OK);
11744 hr = IXMLDOMNode_get_nodeName(node, &str);
11745 EXPECT_HR(hr, S_OK);
11746 ok(!lstrcmpW(str, _bstr_("attr2")), "got %s\n", wine_dbgstr_w(str));
11747 SysFreeString(str);
11748 IXMLDOMNode_Release(node);
11750 IEnumVARIANT_Release(enum2);
11751 IXMLDOMNamedNodeMap_Release(map);
11752 IXMLDOMDocument_Release(doc);
11755 static const char xsltext_xsl[] =
11756 "<?xml version=\"1.0\"?>"
11757 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
11758 "<xsl:output method=\"html\" encoding=\"us-ascii\"/>"
11759 "<xsl:template match=\"/\">"
11760 " <xsl:choose>"
11761 " <xsl:when test=\"testkey\">"
11762 " <xsl:text>testdata</xsl:text>"
11763 " </xsl:when>"
11764 " </xsl:choose>"
11765 "</xsl:template>"
11766 "</xsl:stylesheet>";
11768 static const char omitxmldecl_xsl[] =
11769 "<?xml version=\"1.0\"?>"
11770 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
11771 "<xsl:output method=\"xml\" omit-xml-declaration=\"yes\"/>"
11772 "<xsl:template match=\"/\">"
11773 " <xsl:for-each select=\"/a/item\">"
11774 " <xsl:element name=\"node\">"
11775 " <xsl:value-of select=\"@name\"/>"
11776 " </xsl:element>"
11777 " </xsl:for-each>"
11778 "</xsl:template>"
11779 "</xsl:stylesheet>";
11781 static const char omitxmldecl_doc[] =
11782 "<?xml version=\"1.0\"?>"
11783 "<a>"
11784 " <item name=\"item1\"/>"
11785 " <item name=\"item2\"/>"
11786 "</a>";
11788 static void test_xsltext(void)
11790 IXMLDOMDocument *doc, *doc2;
11791 VARIANT_BOOL b;
11792 HRESULT hr;
11793 BSTR ret;
11795 doc = create_document(&IID_IXMLDOMDocument);
11796 doc2 = create_document(&IID_IXMLDOMDocument);
11798 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsltext_xsl), &b);
11799 EXPECT_HR(hr, S_OK);
11801 hr = IXMLDOMDocument_loadXML(doc2, _bstr_("<testkey/>"), &b);
11802 EXPECT_HR(hr, S_OK);
11804 hr = IXMLDOMDocument_transformNode(doc2, (IXMLDOMNode*)doc, &ret);
11805 EXPECT_HR(hr, S_OK);
11806 ok(!lstrcmpW(ret, _bstr_("testdata")), "transform result %s\n", wine_dbgstr_w(ret));
11807 SysFreeString(ret);
11809 /* omit-xml-declaration */
11810 hr = IXMLDOMDocument_loadXML(doc, _bstr_(omitxmldecl_xsl), &b);
11811 ok(hr == S_OK, "got 0x%08x\n", hr);
11812 hr = IXMLDOMDocument_loadXML(doc2, _bstr_(omitxmldecl_doc), &b);
11813 ok(hr == S_OK, "got 0x%08x\n", hr);
11815 hr = IXMLDOMDocument_transformNode(doc2, (IXMLDOMNode*)doc, &ret);
11816 ok(hr == S_OK, "got 0x%08x\n", hr);
11817 ok(!lstrcmpW(ret, _bstr_("<node>item1</node><node>item2</node>")), "transform result %s\n", wine_dbgstr_w(ret));
11818 SysFreeString(ret);
11820 IXMLDOMDocument_Release(doc2);
11821 IXMLDOMDocument_Release(doc);
11822 free_bstrs();
11825 struct attrtest_t {
11826 const char *name;
11827 const char *uri;
11828 const char *prefix;
11829 const char *href;
11832 static struct attrtest_t attrtests[] = {
11833 { "xmlns", "http://www.w3.org/2000/xmlns/", "xmlns", "xmlns" },
11834 { "xmlns", "nondefaulturi", "xmlns", "xmlns" },
11835 { "c", "http://www.w3.org/2000/xmlns/", NULL, "http://www.w3.org/2000/xmlns/" },
11836 { "c", "nsref1", NULL, "nsref1" },
11837 { "ns:c", "nsref1", "ns", "nsref1" },
11838 { "xmlns:c", "http://www.w3.org/2000/xmlns/", "xmlns", "" },
11839 { "xmlns:c", "nondefaulturi", "xmlns", "" },
11840 { 0 }
11843 static void test_create_attribute(void)
11845 struct attrtest_t *ptr = attrtests;
11846 IXMLDOMElement *el;
11847 IXMLDOMDocument *doc;
11848 IXMLDOMNode *node, *node2;
11849 VARIANT var;
11850 HRESULT hr;
11851 int i = 0;
11852 BSTR str;
11854 doc = create_document(&IID_IXMLDOMDocument);
11856 while (ptr->name)
11858 V_VT(&var) = VT_I1;
11859 V_I1(&var) = NODE_ATTRIBUTE;
11860 hr = IXMLDOMDocument_createNode(doc, var, _bstr_(ptr->name), _bstr_(ptr->uri), &node);
11861 ok(hr == S_OK, "got 0x%08x\n", hr);
11863 str = NULL;
11864 hr = IXMLDOMNode_get_prefix(node, &str);
11865 if (ptr->prefix)
11867 ok(hr == S_OK, "%d: got 0x%08x\n", i, hr);
11868 ok(!lstrcmpW(str, _bstr_(ptr->prefix)), "%d: got prefix %s, expected %s\n", i, wine_dbgstr_w(str), ptr->prefix);
11870 else
11872 ok(hr == S_FALSE, "%d: got 0x%08x\n", i, hr);
11873 ok(str == NULL, "%d: got prefix %s\n", i, wine_dbgstr_w(str));
11875 SysFreeString(str);
11877 str = NULL;
11878 hr = IXMLDOMNode_get_namespaceURI(node, &str);
11879 ok(hr == S_OK, "%d: got 0x%08x\n", i, hr);
11880 ok(!lstrcmpW(str, _bstr_(ptr->href)), "%d: got uri %s, expected %s\n", i, wine_dbgstr_w(str), ptr->href);
11881 SysFreeString(str);
11883 IXMLDOMNode_Release(node);
11884 free_bstrs();
11886 i++;
11887 ptr++;
11890 V_VT(&var) = VT_I1;
11891 V_I1(&var) = NODE_ELEMENT;
11892 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("e"), NULL, &node2);
11893 ok(hr == S_OK, "got 0x%08x\n", hr);
11895 hr = IXMLDOMNode_QueryInterface(node2, &IID_IXMLDOMElement, (void**)&el);
11896 ok(hr == S_OK, "got 0x%08x\n", hr);
11897 IXMLDOMNode_Release(node2);
11899 V_VT(&var) = VT_I1;
11900 V_I1(&var) = NODE_ATTRIBUTE;
11901 hr = IXMLDOMDocument_createNode(doc, var, _bstr_("xmlns:a"), _bstr_("http://www.w3.org/2000/xmlns/"), &node);
11902 ok(hr == S_OK, "got 0x%08x\n", hr);
11904 hr = IXMLDOMElement_setAttributeNode(el, (IXMLDOMAttribute*)node, NULL);
11905 ok(hr == S_OK, "got 0x%08x\n", hr);
11907 /* for some reason default namespace uri is not reported */
11908 hr = IXMLDOMNode_get_namespaceURI(node, &str);
11909 ok(hr == S_OK, "got 0x%08x\n", hr);
11910 ok(!lstrcmpW(str, _bstr_("")), "got uri %s\n", wine_dbgstr_w(str));
11911 SysFreeString(str);
11913 IXMLDOMNode_Release(node);
11914 IXMLDOMElement_Release(el);
11915 IXMLDOMDocument_Release(doc);
11916 free_bstrs();
11919 static void test_url(void)
11921 IXMLDOMDocument *doc;
11922 HRESULT hr;
11923 BSTR s;
11925 doc = create_document(&IID_IXMLDOMDocument);
11927 hr = IXMLDOMDocument_get_url(doc, NULL);
11928 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
11930 s = (BSTR)0x1;
11931 hr = IXMLDOMDocument_get_url(doc, &s);
11932 ok(hr == S_FALSE, "got 0x%08x\n", hr);
11933 ok(s == NULL, "got %s\n", wine_dbgstr_w(s));
11935 IXMLDOMDocument_Release(doc);
11938 static void test_merging_text(void)
11940 IXMLDOMText *nodetext;
11941 IXMLDOMText *newtext;
11942 IXMLDOMElement *root;
11943 IXMLDOMDocument *doc;
11944 IXMLDOMNode *first;
11945 HRESULT hr;
11946 VARIANT v;
11947 BSTR str;
11948 int i;
11950 doc = create_document(&IID_IXMLDOMDocument);
11952 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &root);
11953 EXPECT_HR(hr, S_OK);
11955 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)root, NULL);
11956 EXPECT_HR(hr, S_OK);
11958 /* test xmlAddChild */
11959 for (i = 0; i < 10; i++)
11961 str = SysAllocString(szstr1);
11962 hr = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
11963 SysFreeString(str);
11964 EXPECT_HR(hr, S_OK);
11966 newtext = NULL;
11967 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)nodetext, (IXMLDOMNode**)&newtext);
11968 EXPECT_HR(hr, S_OK);
11969 ok(nodetext == newtext, "expected %p, got %p\n", nodetext, newtext);
11971 IXMLDOMText_Release(newtext);
11972 IXMLDOMText_Release(nodetext);
11975 /* test xmlAddPrevSibling */
11976 hr = IXMLDOMElement_get_firstChild(root, &first);
11977 EXPECT_HR(hr, S_OK);
11978 V_VT(&v) = VT_UNKNOWN;
11979 V_UNKNOWN(&v) = (IUnknown*)first;
11980 for (i = 0; i < 10; i++)
11982 str = SysAllocString(szstr2);
11983 hr = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
11984 SysFreeString(str);
11985 EXPECT_HR(hr, S_OK);
11987 newtext = NULL;
11988 hr = IXMLDOMElement_insertBefore(root, (IXMLDOMNode*)nodetext, v, (IXMLDOMNode**)&newtext);
11989 EXPECT_HR(hr, S_OK);
11990 ok(nodetext == newtext, "expected %p, got %p\n", nodetext, newtext);
11992 IXMLDOMText_Release(newtext);
11993 IXMLDOMText_Release(nodetext);
11996 IXMLDOMNode_Release(first);
11997 IXMLDOMElement_Release(root);
11998 IXMLDOMDocument_Release(doc);
12000 free_bstrs();
12003 START_TEST(domdoc)
12005 HRESULT hr;
12007 hr = CoInitialize( NULL );
12008 ok( hr == S_OK, "failed to init com\n");
12009 if (hr != S_OK) return;
12011 get_class_support_data(domdoc_support_data);
12012 if (!is_clsid_supported(&CLSID_DOMDocument2, &IID_IXMLDOMDocument))
12014 win_skip("DOMDocument2 is not supported. Skipping all tests.\n");
12015 CoUninitialize();
12016 return;
12019 test_domdoc();
12020 test_persiststreaminit();
12021 test_domnode();
12022 test_refs();
12023 test_create();
12024 test_getElementsByTagName();
12025 test_get_text();
12026 test_get_childNodes();
12027 test_get_firstChild();
12028 test_get_lastChild();
12029 test_removeChild();
12030 test_replaceChild();
12031 test_removeNamedItem();
12032 test_IXMLDOMDocument2();
12033 test_whitespace();
12034 test_XPath();
12035 test_XSLPattern();
12036 test_cloneNode();
12037 test_xmlTypes();
12038 test_save();
12039 test_testTransforms();
12040 test_namespaces_basic();
12041 test_namespaces_change();
12042 test_FormattingXML();
12043 test_nodeTypedValue();
12044 test_TransformWithLoadingLocalFile();
12045 test_put_nodeValue();
12046 test_IObjectSafety();
12047 test_splitText();
12048 test_getQualifiedItem();
12049 test_removeQualifiedItem();
12050 test_get_ownerDocument();
12051 test_setAttributeNode();
12052 test_put_dataType();
12053 test_createNode();
12054 test_create_attribute();
12055 test_get_prefix();
12056 test_default_properties();
12057 test_selectSingleNode();
12058 test_events();
12059 test_createProcessingInstruction();
12060 test_put_nodeTypedValue();
12061 test_get_xml();
12062 test_insertBefore();
12063 test_appendChild();
12064 test_get_doctype();
12065 test_get_tagName();
12066 test_get_dataType();
12067 test_get_nodeTypeString();
12068 test_get_attributes();
12069 test_selection();
12070 test_load();
12071 test_dispex();
12072 test_parseerror();
12073 test_getAttributeNode();
12074 test_supporterrorinfo();
12075 test_nodeValue();
12076 test_get_namespaces();
12077 test_put_data();
12078 test_putref_schemas();
12079 test_namedmap_newenum();
12080 test_xmlns_attribute();
12081 test_url();
12082 test_merging_text();
12084 test_xsltemplate();
12085 test_xsltext();
12087 if (is_clsid_supported(&CLSID_MXNamespaceManager40, &IID_IMXNamespaceManager))
12089 test_mxnamespacemanager();
12090 test_mxnamespacemanager_override();
12093 CoUninitialize();