4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
6 * Copyright 2010 Adam Martinson for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "msxml2did.h"
35 #include "wine/test.h"
39 DEFINE_GUID(IID_IObjectSafety, 0xcb5bdc81, 0x93c1, 0x11cf, 0x8f,0x20, 0x00,0x80,0x5f,0x2c,0xd0,0x64);
41 static int g_unexpectedcall, g_expectedcall;
45 const struct IDispatchVtbl *lpVtbl;
49 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
51 return (dispevent *)((char*)iface - FIELD_OFFSET(dispevent, lpVtbl));
54 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
58 if ( IsEqualGUID( riid, &IID_IDispatch) ||
59 IsEqualGUID( riid, &IID_IUnknown) )
66 IDispatch_AddRef( iface );
71 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
73 dispevent *This = impl_from_IDispatch( iface );
74 return InterlockedIncrement( &This->ref );
77 static ULONG WINAPI dispevent_Release(IDispatch *iface)
79 dispevent *This = impl_from_IDispatch( iface );
80 ULONG ref = InterlockedDecrement( &This->ref );
83 HeapFree(GetProcessHeap(), 0, This);
88 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
95 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
96 LCID lcid, ITypeInfo **ppTInfo)
102 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
103 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
109 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
110 LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
111 EXCEPINFO *excepInfo, UINT *argErr)
113 ok(member == 0, "expected 0 member, got %d\n", member);
114 ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
115 ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
117 ok(params->cArgs == 0, "got %d\n", params->cArgs);
118 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
119 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
120 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
122 ok(result == NULL, "got %p\n", result);
123 ok(excepInfo == NULL, "got %p\n", excepInfo);
124 ok(argErr == NULL, "got %p\n", argErr);
130 static const IDispatchVtbl dispeventVtbl =
132 dispevent_QueryInterface,
135 dispevent_GetTypeInfoCount,
136 dispevent_GetTypeInfo,
137 dispevent_GetIDsOfNames,
141 static IDispatch* create_dispevent(void)
143 dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
145 event->lpVtbl = &dispeventVtbl;
148 return (IDispatch*)&event->lpVtbl;
151 #define EXPECT_CHILDREN(node) _expect_children((IXMLDOMNode*)node, __LINE__)
152 static void _expect_children(IXMLDOMNode *node, int line)
158 hr = IXMLDOMNode_hasChildNodes(node, &b);
159 ok_(__FILE__,line)(hr == S_OK, "hasChildNodes() failed, 0x%08x\n", hr);
160 ok_(__FILE__,line)(b == VARIANT_TRUE, "no children, %d\n", b);
163 #define EXPECT_NO_CHILDREN(node) _expect_no_children((IXMLDOMNode*)node, __LINE__)
164 static void _expect_no_children(IXMLDOMNode *node, int line)
170 hr = IXMLDOMNode_hasChildNodes(node, &b);
171 ok_(__FILE__,line)(hr == S_FALSE, "hasChildNodes() failed, 0x%08x\n", hr);
172 ok_(__FILE__,line)(b == VARIANT_FALSE, "no children, %d\n", b);
175 #define EXPECT_REF(node,ref) _expect_ref((IUnknown*)node, ref, __LINE__)
176 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
178 ULONG rc = IUnknown_AddRef(obj);
179 IUnknown_Release(obj);
180 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
183 static const WCHAR szEmpty[] = { 0 };
184 static const WCHAR szIncomplete[] = {
185 '<','?','x','m','l',' ',
186 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
188 static const WCHAR szComplete1[] = {
189 '<','?','x','m','l',' ',
190 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
191 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
193 static const WCHAR szComplete2[] = {
194 '<','?','x','m','l',' ',
195 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
196 '<','o','>','<','/','o','>','\n',0
198 static const WCHAR szComplete3[] = {
199 '<','?','x','m','l',' ',
200 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
201 '<','a','>','<','/','a','>','\n',0
203 static const WCHAR szComplete4[] = {
204 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
205 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
206 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
207 'f','n','1','.','t','x','t','\n',
208 '<','/','b','s','>','\n',
209 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
210 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
211 'f','n','2','.','t','x','t','\n',
212 '<','/','p','r','>','\n',
213 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
214 '<','f','o','>','\n',
215 '<','b','a','>','\n',
217 '<','/','b','a','>','\n',
218 '<','/','f','o','>','\n',
219 '<','/','l','c','>','\n',0
221 static const WCHAR szComplete5[] = {
222 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
223 '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','"',
224 ' ','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','"','>',
225 '<','S',':','s','c','o','p','e','>',
226 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
227 '<','/','S',':','s','c','o','p','e','>',
228 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
229 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
230 'c','o','m','p','u','t','e','r',
231 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
232 '<','/','S',':','s','e','a','r','c','h','>',0
235 static const WCHAR szComplete6[] = {
236 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'',' ',
237 'e','n','c','o','d','i','n','g','=','\'','W','i','n','d','o','w','s','-','1','2','5','2','\'','?','>','\n',
238 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
241 static const CHAR szNonUnicodeXML[] =
242 "<?xml version='1.0' encoding='Windows-1252'?>\n"
245 static const CHAR szExampleXML[] =
246 "<?xml version='1.0' encoding='utf-8'?>\n"
247 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
252 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
253 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
254 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
256 " <html xml:space='preserve' xmlns='http://www.w3.org/1999/xhtml'>\n"
257 " This is <strong>a</strong> <i>description</i> with preserved whitespace. <bar:x/>\n"
265 " <c type=\"old\">C2 field</c>\n"
268 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
277 " <foo:c>C4 field</foo:c>\n"
281 static const CHAR szNodeTypesXML[] =
282 "<?xml version='1.0'?>"
283 "<!-- comment node 0 -->"
284 "<root id='0' depth='0'>"
285 " <!-- comment node 1 -->"
287 " <x id='1' depth='1'>"
288 " <?foo value='PI for x'?>"
289 " <!-- comment node 2 -->"
291 " <a id='3' depth='2'/>"
292 " <b id='4' depth='2'/>"
293 " <c id='5' depth='2'/>"
295 " <y id='2' depth='1'>"
296 " <?bar value='PI for y'?>"
297 " <!-- comment node 3 -->"
299 " <a id='6' depth='2'/>"
300 " <b id='7' depth='2'/>"
301 " <c id='8' depth='2'/>"
305 static const CHAR szTransformXML[] =
306 "<?xml version=\"1.0\"?>\n"
311 static const CHAR szTransformSSXML[] =
312 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
313 " <xsl:output method=\"html\"/>\n"
314 " <xsl:template match=\"/\">\n"
315 " <xsl:apply-templates select=\"greeting\"/>\n"
317 " <xsl:template match=\"greeting\">\n"
321 " <xsl:value-of select=\".\"/>\n"
328 static const CHAR szTransformOutput[] =
331 "</h1></body></html>";
333 static const CHAR szTypeValueXML[] =
334 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
335 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
336 " <string>Wine</string>\n"
337 " <string2 dt:dt=\"string\">String</string2>\n"
338 " <number dt:dt=\"number\">12.44</number>\n"
339 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
340 " <int dt:dt=\"int\">-13</int>\n"
341 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
342 " <bool dt:dt=\"boolean\">1</bool>\n"
343 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
344 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
345 " <date dt:dt=\"date\">3721-11-01</date>\n"
346 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
347 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
348 " <i1 dt:dt=\"i1\">-13</i1>\n"
349 " <i2 dt:dt=\"i2\">31915</i2>\n"
350 " <i4 dt:dt=\"i4\">-312232</i4>\n"
351 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
352 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
353 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
354 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
355 " <r8 dt:dt=\"r8\">0.412</r8>\n"
356 " <float dt:dt=\"float\">41221.421</float>\n"
357 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
358 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
359 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
362 static const CHAR szBasicTransformSSXMLPart1[] =
363 "<?xml version=\"1.0\"?>"
364 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
365 "<xsl:output method=\"html\"/>\n"
366 "<xsl:template match=\"/\">"
367 "<HTML><BODY><TABLE>"
368 " <xsl:apply-templates select='document(\"";
370 static const CHAR szBasicTransformSSXMLPart2[] =
372 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
373 " </xsl:apply-templates>"
374 "</TABLE></BODY></HTML>"
376 "<xsl:template match=\"bottle\">"
377 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
379 "<xsl:template match=\"name\">"
380 " <TD><xsl:apply-templates /></TD>"
382 "<xsl:template match=\"cost\">"
383 " <TD><xsl:apply-templates /></TD>"
387 static const CHAR szBasicTransformXML[] =
388 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
390 static const CHAR szBasicTransformOutput[] =
391 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
393 #define SZ_EMAIL_DTD \
395 " <!ELEMENT email (recipients,from,reply-to?,subject,body,attachment*)>"\
396 " <!ATTLIST email attachments IDREFS #REQUIRED>"\
397 " <!ATTLIST email sent (yes|no) \"no\">"\
398 " <!ELEMENT recipients (to+,cc*)>"\
399 " <!ELEMENT to (#PCDATA)>"\
400 " <!ATTLIST to name CDATA #IMPLIED>"\
401 " <!ELEMENT cc (#PCDATA)>"\
402 " <!ATTLIST cc name CDATA #IMPLIED>"\
403 " <!ELEMENT from (#PCDATA)>"\
404 " <!ATTLIST from name CDATA #IMPLIED>"\
405 " <!ELEMENT reply-to (#PCDATA)>"\
406 " <!ATTLIST reply-to name CDATA #IMPLIED>"\
407 " <!ELEMENT subject ANY>"\
408 " <!ELEMENT body ANY>"\
409 " <!ATTLIST body enc CDATA #FIXED \"UTF-8\">"\
410 " <!ELEMENT attachment (#PCDATA)>"\
411 " <!ATTLIST attachment id ID #REQUIRED>"\
414 static const CHAR szEmailXML[] =
415 "<?xml version=\"1.0\"?>"
417 "<email attachments=\"patch1\">"
419 " <to>wine-patches@winehq.org</to>"
421 " <from name=\"Anonymous\">user@localhost</from>"
422 " <subject>msxml3/tests: DTD validation (try 87)</subject>"
424 " It no longer causes spontaneous combustion..."
426 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
429 static const CHAR szEmailXML_0D[] =
430 "<?xml version=\"1.0\"?>"
432 "<email attachments=\"patch1\">"
434 " <to>wine-patches@winehq.org</to>"
436 " <from name=\"Anonymous\">user@localhost</from>"
437 " <subject>msxml3/tests: DTD validation (try 88)</subject>"
440 " XML_ELEMENT_UNDECLARED 0xC00CE00D"
442 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
445 static const CHAR szEmailXML_0E[] =
446 "<?xml version=\"1.0\"?>"
448 "<email attachments=\"patch1\">"
450 " <to>wine-patches@winehq.org</to>"
452 " <from name=\"Anonymous\">user@localhost</from>"
453 " <subject>msxml3/tests: DTD validation (try 89)</subject>"
455 " XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E"
457 " <attachment id=\"patch\">0001-msxml3-tests-DTD-validation.patch</attachment>"
460 static const CHAR szEmailXML_11[] =
461 "<?xml version=\"1.0\"?>"
463 "<email attachments=\"patch1\">"
466 " <from name=\"Anonymous\">user@localhost</from>"
467 " <subject>msxml3/tests: DTD validation (try 90)</subject>"
469 " XML_EMPTY_NOT_ALLOWED 0xC00CE011"
471 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
474 static const CHAR szEmailXML_13[] =
475 "<?xml version=\"1.0\"?>"
477 "<msg attachments=\"patch1\">"
479 " <to>wine-patches@winehq.org</to>"
481 " <from name=\"Anonymous\">user@localhost</from>"
482 " <subject>msxml3/tests: DTD validation (try 91)</subject>"
484 " XML_ROOT_NAME_MISMATCH 0xC00CE013"
486 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
489 static const CHAR szEmailXML_14[] =
490 "<?xml version=\"1.0\"?>"
492 "<email attachments=\"patch1\">"
493 " <to>wine-patches@winehq.org</to>"
494 " <from name=\"Anonymous\">user@localhost</from>"
495 " <subject>msxml3/tests: DTD validation (try 92)</subject>"
497 " XML_INVALID_CONTENT 0xC00CE014"
499 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
502 static const CHAR szEmailXML_15[] =
503 "<?xml version=\"1.0\"?>"
505 "<email attachments=\"patch1\" ip=\"127.0.0.1\">"
507 " <to>wine-patches@winehq.org</to>"
509 " <from name=\"Anonymous\">user@localhost</from>"
510 " <subject>msxml3/tests: DTD validation (try 93)</subject>"
512 " XML_ATTRIBUTE_NOT_DEFINED 0xC00CE015"
514 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
517 static const CHAR szEmailXML_16[] =
518 "<?xml version=\"1.0\"?>"
520 "<email attachments=\"patch1\">"
522 " <to>wine-patches@winehq.org</to>"
524 " <from name=\"Anonymous\">user@localhost</from>"
525 " <subject>msxml3/tests: DTD validation (try 94)</subject>"
526 " <body enc=\"ASCII\">"
527 " XML_ATTRIBUTE_FIXED 0xC00CE016"
529 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
532 static const CHAR szEmailXML_17[] =
533 "<?xml version=\"1.0\"?>"
535 "<email attachments=\"patch1\" sent=\"true\">"
537 " <to>wine-patches@winehq.org</to>"
539 " <from name=\"Anonymous\">user@localhost</from>"
540 " <subject>msxml3/tests: DTD validation (try 95)</subject>"
542 " XML_ATTRIBUTE_VALUE 0xC00CE017"
544 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
547 static const CHAR szEmailXML_18[] =
548 "<?xml version=\"1.0\"?>"
550 "<email attachments=\"patch1\">"
553 " <to>wine-patches@winehq.org</to>"
555 " <from name=\"Anonymous\">user@localhost</from>"
556 " <subject>msxml3/tests: DTD validation (try 96)</subject>"
558 " XML_ILLEGAL_TEXT 0xC00CE018"
560 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
563 static const CHAR szEmailXML_20[] =
564 "<?xml version=\"1.0\"?>"
568 " <to>wine-patches@winehq.org</to>"
570 " <from name=\"Anonymous\">user@localhost</from>"
571 " <subject>msxml3/tests: DTD validation (try 97)</subject>"
573 " XML_REQUIRED_ATTRIBUTE_MISSING 0xC00CE020"
575 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
578 static const WCHAR szNonExistentFile[] = {
579 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
581 static const WCHAR szNonExistentAttribute[] = {
582 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
584 static const WCHAR szDocument[] = {
585 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
588 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
589 static WCHAR szdl[] = { 'd','l',0 };
590 static const WCHAR szvr[] = { 'v','r',0 };
591 static const WCHAR szlc[] = { 'l','c',0 };
592 static WCHAR szbs[] = { 'b','s',0 };
593 static const WCHAR szstr1[] = { 's','t','r','1',0 };
594 static const WCHAR szstr2[] = { 's','t','r','2',0 };
595 static const WCHAR szstar[] = { '*',0 };
596 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
598 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
599 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
600 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
602 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
603 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
604 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
605 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
606 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
607 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
608 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
610 static WCHAR szAttribute[] = {'A','t','t','r',0 };
611 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
613 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
614 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
615 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
616 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
618 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
619 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
621 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
622 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
623 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
625 #define expect_bstr_eq_and_free(bstr, expect) { \
626 BSTR bstrExp = alloc_str_from_narrow(expect); \
627 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
628 SysFreeString(bstr); \
629 SysFreeString(bstrExp); \
632 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
634 #define ole_check(expr) { \
636 ok(r == S_OK, #expr " returned %x\n", r); \
639 #define ole_expect(expr, expect) { \
641 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
644 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
646 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
651 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
653 win_skip_(__FILE__,line)("failed to create %s instance: 0x%08x\n", name, hr);
658 #define _create(cls) cls, #cls
660 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument), iid, __LINE__)
661 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
662 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
663 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
664 #define create_xsltemplate(iid) _create_object(&_create(CLSID_XSLTemplate), iid, __LINE__)
666 static BSTR alloc_str_from_narrow(const char *str)
668 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
669 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
670 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
674 static BSTR alloced_bstrs[256];
675 static int alloced_bstrs_count;
677 static BSTR _bstr_(const char *str)
679 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
680 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
681 return alloced_bstrs[alloced_bstrs_count++];
684 static void free_bstrs(void)
687 for (i = 0; i < alloced_bstrs_count; i++)
688 SysFreeString(alloced_bstrs[i]);
689 alloced_bstrs_count = 0;
692 static VARIANT _variantbstr_(const char *str)
696 V_BSTR(&v) = _bstr_(str);
700 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
704 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
705 while (*sRight == '\r' || *sRight == '\n') sRight++;
706 if (*sLeft != *sRight) return FALSE;
707 if (!*sLeft) return TRUE;
713 static void get_str_for_type(DOMNodeType type, char *buf)
732 case NODE_PROCESSING_INSTRUCTION:
736 wsprintfA(buf, "[%d]", type);
740 #define test_disp(u) _test_disp(__LINE__,u)
741 static void _test_disp(unsigned line, IUnknown *unk)
743 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
751 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
752 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
757 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
758 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
759 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
761 sName = SysAllocString( szstar );
762 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
763 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
764 SysFreeString( sName );
766 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
767 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
769 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
770 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
771 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
773 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
774 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
776 SysFreeString(sName);
778 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
779 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
781 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
782 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
783 if(hres == S_OK && pUnk)
784 IUnknown_Release(pUnk);
786 IDispatchEx_Release(dispex);
789 static int get_node_position(IXMLDOMNode *node)
794 IXMLDOMNode_AddRef(node);
797 IXMLDOMNode *new_node;
800 r = IXMLDOMNode_get_previousSibling(node, &new_node);
801 ok(SUCCEEDED(r), "get_previousSibling failed\n");
802 IXMLDOMNode_Release(node);
808 static void node_to_string(IXMLDOMNode *node, char *buf)
815 lstrcpyA(buf, "(null)");
819 IXMLDOMNode_AddRef(node);
822 IXMLDOMNode *new_node;
824 ole_check(IXMLDOMNode_get_nodeType(node, &type));
825 get_str_for_type(type, buf);
828 if (type == NODE_ATTRIBUTE)
831 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
833 wsprintfA(buf, "%ws", bstr);
838 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
842 r = IXMLDOMNode_get_parentNode(node, &new_node);
843 wsprintf(buf, "%d", get_node_position(node));
847 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
848 IXMLDOMNode_Release(node);
857 static char *list_to_string(IXMLDOMNodeList *list)
859 static char buf[4096];
866 lstrcpyA(buf, "(null)");
869 ole_check(IXMLDOMNodeList_get_length(list, &len));
870 for (i = 0; i < len; i++)
875 ole_check(IXMLDOMNodeList_nextNode(list, &node));
876 node_to_string(node, pos);
878 IXMLDOMNode_Release(node);
884 #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); }
885 #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); }
887 static void test_domdoc( void )
890 IXMLDOMDocument *doc;
891 IXMLDOMParseError *error;
892 IXMLDOMElement *element = NULL;
894 IXMLDOMText *nodetext = NULL;
895 IXMLDOMComment *node_comment = NULL;
896 IXMLDOMAttribute *node_attr = NULL;
897 IXMLDOMNode *nodeChild = NULL;
898 IXMLDOMProcessingInstruction *nodePI = NULL;
899 ISupportErrorInfo *support_error = NULL;
907 doc = create_document(&IID_IXMLDOMDocument);
910 test_disp((IUnknown*)doc);
914 /* crashes on native */
915 IXMLDOMDocument_loadXML( doc, (BSTR)0x1, NULL );
918 /* try some stupid things */
919 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
920 ok( r == S_FALSE, "loadXML succeeded\n");
923 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
924 ok( r == S_FALSE, "loadXML succeeded\n");
925 ok( b == VARIANT_FALSE, "failed to load XML string\n");
927 /* try to load a document from a nonexistent file */
929 str = SysAllocString( szNonExistentFile );
931 V_VT(&var) = VT_BSTR;
934 r = IXMLDOMDocument_load( doc, var, &b);
935 ok( r == S_FALSE, "loadXML succeeded\n");
936 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
937 SysFreeString( str );
939 /* try load an empty document */
941 str = SysAllocString( szEmpty );
942 r = IXMLDOMDocument_loadXML( doc, str, &b );
943 ok( r == S_FALSE, "loadXML succeeded\n");
944 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
945 SysFreeString( str );
947 r = IXMLDOMDocument_get_async( doc, &b );
948 ok( r == S_OK, "get_async failed (%08x)\n", r);
949 ok( b == VARIANT_TRUE, "Wrong default value\n");
951 /* check that there's no document element */
953 r = IXMLDOMDocument_get_documentElement( doc, &element );
954 ok( r == S_FALSE, "should be no document element\n");
956 /* try finding a node */
958 str = SysAllocString( szstr1 );
959 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
960 ok( r == S_FALSE, "ret %08x\n", r );
961 SysFreeString( str );
964 str = SysAllocString( szIncomplete );
965 r = IXMLDOMDocument_loadXML( doc, str, &b );
966 ok( r == S_FALSE, "loadXML succeeded\n");
967 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
968 SysFreeString( str );
970 /* check that there's no document element */
971 element = (IXMLDOMElement*)1;
972 r = IXMLDOMDocument_get_documentElement( doc, &element );
973 ok( r == S_FALSE, "should be no document element\n");
974 ok( element == NULL, "Element should be NULL\n");
976 /* test for BSTR handling, pass broken BSTR */
977 memcpy(&buff[2], szComplete1, sizeof(szComplete1));
978 /* just a big length */
979 *(DWORD*)buff = 0xf0f0;
981 r = IXMLDOMDocument_loadXML( doc, &buff[2], &b );
982 ok( r == S_OK, "loadXML failed\n");
983 ok( b == VARIANT_TRUE, "failed to load XML string\n");
985 /* loadXML ignores the encoding attribute and always expects Unicode */
987 str = SysAllocString( szComplete6 );
988 r = IXMLDOMDocument_loadXML( doc, str, &b );
989 ok( r == S_OK, "loadXML failed\n");
990 ok( b == VARIANT_TRUE, "failed to load XML string\n");
991 SysFreeString( str );
993 /* try a BSTR containing a Windows-1252 document */
995 str = SysAllocStringByteLen( szNonUnicodeXML, sizeof(szNonUnicodeXML) - 1 );
996 r = IXMLDOMDocument_loadXML( doc, str, &b );
997 ok( r == S_FALSE, "loadXML succeeded\n");
998 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
999 SysFreeString( str );
1001 /* try to load something valid */
1003 str = SysAllocString( szComplete1 );
1004 r = IXMLDOMDocument_loadXML( doc, str, &b );
1005 ok( r == S_OK, "loadXML failed\n");
1006 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1007 SysFreeString( str );
1009 /* check if nodename is correct */
1010 r = IXMLDOMDocument_get_nodeName( doc, NULL );
1011 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1013 str = (BSTR)0xdeadbeef;
1014 r = IXMLDOMDocument_get_baseName( doc, &str );
1015 ok ( r == S_FALSE, "got 0x%08x\n", r);
1016 ok (str == NULL, "got %p\n", str);
1018 /* content doesn't matter here */
1020 r = IXMLDOMDocument_get_nodeName( doc, &str );
1021 ok ( r == S_OK, "get_nodeName wrong code\n");
1022 ok ( str != NULL, "str is null\n");
1023 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
1024 SysFreeString( str );
1027 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
1028 ok( r == E_FAIL, "ret %08x\n", r );
1030 /* check that there's a document element */
1032 r = IXMLDOMDocument_get_documentElement( doc, &element );
1033 ok( r == S_OK, "should be a document element\n");
1036 IObjectIdentity *ident;
1039 test_disp((IUnknown*)element);
1041 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (void**)&ident );
1042 ok( r == E_NOINTERFACE, "ret %08x\n", r);
1044 r = IXMLDOMElement_get_tagName( element, NULL );
1045 ok( r == E_INVALIDARG, "ret %08x\n", r);
1047 /* check if the tag is correct */
1048 r = IXMLDOMElement_get_tagName( element, &tag );
1049 ok( r == S_OK, "couldn't get tag name\n");
1050 ok( tag != NULL, "tag was null\n");
1051 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
1052 SysFreeString( tag );
1054 /* figure out what happens if we try to reload the document */
1055 str = SysAllocString( szComplete2 );
1056 r = IXMLDOMDocument_loadXML( doc, str, &b );
1057 ok( r == S_OK, "loadXML failed\n");
1058 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1059 SysFreeString( str );
1061 /* check if the tag is still correct */
1063 r = IXMLDOMElement_get_tagName( element, &tag );
1064 ok( r == S_OK, "couldn't get tag name\n");
1065 ok( tag != NULL, "tag was null\n");
1066 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
1067 SysFreeString( tag );
1069 IXMLDOMElement_Release( element );
1073 /* as soon as we call loadXML again, the document element will disappear */
1075 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
1076 ok( r == S_FALSE, "loadXML failed\n");
1077 ok( b == 2, "variant modified\n");
1078 r = IXMLDOMDocument_get_documentElement( doc, &element );
1079 ok( r == S_FALSE, "should be no document element\n");
1081 /* try to load something else simple and valid */
1083 str = SysAllocString( szComplete3 );
1084 r = IXMLDOMDocument_loadXML( doc, str, &b );
1085 ok( r == S_OK, "loadXML failed\n");
1086 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1087 SysFreeString( str );
1089 /* try something a little more complicated */
1091 str = SysAllocString( szComplete4 );
1092 r = IXMLDOMDocument_loadXML( doc, str, &b );
1093 ok( r == S_OK, "loadXML failed\n");
1094 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1095 SysFreeString( str );
1097 r = IXMLDOMDocument_get_parseError( doc, &error );
1098 ok( r == S_OK, "returns %08x\n", r );
1100 r = IXMLDOMParseError_get_errorCode( error, &code );
1101 ok( r == S_FALSE, "returns %08x\n", r );
1102 ok( code == 0, "code %d\n", code );
1103 IXMLDOMParseError_Release( error );
1105 /* test createTextNode */
1106 r = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &nodetext);
1107 ok( r == S_OK, "returns %08x\n", r );
1108 IXMLDOMText_Release(nodetext);
1110 str = SysAllocString( szOpen );
1111 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
1112 ok( r == E_INVALIDARG, "returns %08x\n", r );
1113 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
1114 ok( r == S_OK, "returns %08x\n", r );
1115 SysFreeString( str );
1118 IXMLDOMNamedNodeMap *pAttribs;
1120 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element);
1121 ok(r == E_NOINTERFACE, "ret %08x\n", r );
1123 /* Text Last Child Checks */
1124 r = IXMLDOMText_get_lastChild(nodetext, NULL);
1125 ok(r == E_INVALIDARG, "ret %08x\n", r );
1127 nodeChild = (IXMLDOMNode*)0x1;
1128 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
1129 ok(r == S_FALSE, "ret %08x\n", r );
1130 ok(nodeChild == NULL, "nodeChild not NULL\n");
1132 /* test get_attributes */
1133 r = IXMLDOMText_get_attributes( nodetext, NULL );
1134 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
1136 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
1137 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
1138 ok(r == S_FALSE, "ret %08x\n", r );
1139 ok( pAttribs == NULL, "pAttribs not NULL\n");
1141 /* test get_dataType */
1142 r = IXMLDOMText_get_dataType(nodetext, &var);
1143 ok(r == S_FALSE, "ret %08x\n", r );
1144 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
1147 /* test length property */
1148 r = IXMLDOMText_get_length(nodetext, NULL);
1149 ok(r == E_INVALIDARG, "ret %08x\n", r );
1151 r = IXMLDOMText_get_length(nodetext, &nLength);
1152 ok(r == S_OK, "ret %08x\n", r );
1153 ok(nLength == 4, "expected 4 got %d\n", nLength);
1155 /* test nodeTypeString */
1156 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
1157 ok(r == S_OK, "ret %08x\n", r );
1158 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
1161 /* put data Tests */
1162 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
1163 ok(r == S_OK, "ret %08x\n", r );
1165 /* get data Tests */
1166 r = IXMLDOMText_get_data(nodetext, &str);
1167 ok(r == S_OK, "ret %08x\n", r );
1168 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
1171 /* Confirm XML text is good */
1172 r = IXMLDOMText_get_xml(nodetext, &str);
1173 ok(r == S_OK, "ret %08x\n", r );
1174 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
1177 /* Confirm we get the put_data Text back */
1178 r = IXMLDOMText_get_text(nodetext, &str);
1179 ok(r == S_OK, "ret %08x\n", r );
1180 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
1183 /* test substringData */
1184 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
1185 ok(r == E_INVALIDARG, "ret %08x\n", r );
1187 /* test substringData - Invalid offset */
1188 str = (BSTR)&szElement;
1189 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
1190 ok(r == E_INVALIDARG, "ret %08x\n", r );
1191 ok( str == NULL, "incorrect string\n");
1193 /* test substringData - Invalid offset */
1194 str = (BSTR)&szElement;
1195 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
1196 ok(r == S_FALSE, "ret %08x\n", r );
1197 ok( str == NULL, "incorrect string\n");
1199 /* test substringData - Invalid size */
1200 str = (BSTR)&szElement;
1201 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
1202 ok(r == E_INVALIDARG, "ret %08x\n", r );
1203 ok( str == NULL, "incorrect string\n");
1205 /* test substringData - Invalid size */
1206 str = (BSTR)&szElement;
1207 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
1208 ok(r == S_FALSE, "ret %08x\n", r );
1209 ok( str == NULL, "incorrect string\n");
1211 /* test substringData - Start of string */
1212 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
1213 ok(r == S_OK, "ret %08x\n", r );
1214 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
1217 /* test substringData - Middle of string */
1218 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
1219 ok(r == S_OK, "ret %08x\n", r );
1220 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
1223 /* test substringData - End of string */
1224 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
1225 ok(r == S_OK, "ret %08x\n", r );
1226 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
1229 /* test appendData */
1230 r = IXMLDOMText_appendData(nodetext, NULL);
1231 ok(r == S_OK, "ret %08x\n", r );
1233 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
1234 ok(r == S_OK, "ret %08x\n", r );
1236 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
1237 ok(r == S_OK, "ret %08x\n", r );
1239 r = IXMLDOMText_get_text(nodetext, &str);
1240 ok(r == S_OK, "ret %08x\n", r );
1241 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1244 /* test insertData */
1245 str = SysAllocStringLen(NULL, 0);
1246 r = IXMLDOMText_insertData(nodetext, -1, str);
1247 ok(r == S_OK, "ret %08x\n", r );
1249 r = IXMLDOMText_insertData(nodetext, -1, NULL);
1250 ok(r == S_OK, "ret %08x\n", r );
1252 r = IXMLDOMText_insertData(nodetext, 1000, str);
1253 ok(r == S_OK, "ret %08x\n", r );
1255 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
1256 ok(r == S_OK, "ret %08x\n", r );
1258 r = IXMLDOMText_insertData(nodetext, 0, NULL);
1259 ok(r == S_OK, "ret %08x\n", r );
1261 r = IXMLDOMText_insertData(nodetext, 0, str);
1262 ok(r == S_OK, "ret %08x\n", r );
1265 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
1266 ok(r == E_INVALIDARG, "ret %08x\n", r );
1268 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
1269 ok(r == E_INVALIDARG, "ret %08x\n", r );
1271 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
1272 ok(r == S_OK, "ret %08x\n", r );
1274 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
1275 ok(r == S_OK, "ret %08x\n", r );
1277 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
1278 ok(r == S_OK, "ret %08x\n", r );
1280 r = IXMLDOMText_get_text(nodetext, &str);
1281 ok(r == S_OK, "ret %08x\n", r );
1282 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1286 /* invalid arguments */
1287 r = IXMLDOMText_deleteData(nodetext, -1, 1);
1288 ok(r == E_INVALIDARG, "ret %08x\n", r );
1290 r = IXMLDOMText_deleteData(nodetext, 0, 0);
1291 ok(r == S_OK, "ret %08x\n", r );
1293 r = IXMLDOMText_deleteData(nodetext, 0, -1);
1294 ok(r == E_INVALIDARG, "ret %08x\n", r );
1296 r = IXMLDOMText_get_length(nodetext, &nLength);
1297 ok(r == S_OK, "ret %08x\n", r );
1298 ok(nLength == 43, "expected 43 got %d\n", nLength);
1300 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
1301 ok(r == S_OK, "ret %08x\n", r );
1303 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
1304 ok(r == E_INVALIDARG, "ret %08x\n", r );
1306 /* delete from start */
1307 r = IXMLDOMText_deleteData(nodetext, 0, 5);
1308 ok(r == S_OK, "ret %08x\n", r );
1310 r = IXMLDOMText_get_length(nodetext, &nLength);
1311 ok(r == S_OK, "ret %08x\n", r );
1312 ok(nLength == 38, "expected 38 got %d\n", nLength);
1314 r = IXMLDOMText_get_text(nodetext, &str);
1315 ok(r == S_OK, "ret %08x\n", r );
1316 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1319 /* delete from end */
1320 r = IXMLDOMText_deleteData(nodetext, 35, 3);
1321 ok(r == S_OK, "ret %08x\n", r );
1323 r = IXMLDOMText_get_length(nodetext, &nLength);
1324 ok(r == S_OK, "ret %08x\n", r );
1325 ok(nLength == 35, "expected 35 got %d\n", nLength);
1327 r = IXMLDOMText_get_text(nodetext, &str);
1328 ok(r == S_OK, "ret %08x\n", r );
1329 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1332 /* delete from inside */
1333 r = IXMLDOMText_deleteData(nodetext, 1, 33);
1334 ok(r == S_OK, "ret %08x\n", r );
1336 r = IXMLDOMText_get_length(nodetext, &nLength);
1337 ok(r == S_OK, "ret %08x\n", r );
1338 ok(nLength == 2, "expected 2 got %d\n", nLength);
1340 r = IXMLDOMText_get_text(nodetext, &str);
1341 ok(r == S_OK, "ret %08x\n", r );
1342 ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1345 /* delete whole data ... */
1346 r = IXMLDOMText_get_length(nodetext, &nLength);
1347 ok(r == S_OK, "ret %08x\n", r );
1349 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1350 ok(r == S_OK, "ret %08x\n", r );
1351 /* ... and try again with empty string */
1352 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1353 ok(r == S_OK, "ret %08x\n", r );
1356 V_VT(&var) = VT_BSTR;
1357 V_BSTR(&var) = SysAllocString(szstr1);
1358 r = IXMLDOMText_put_nodeValue(nodetext, var);
1359 ok(r == S_OK, "ret %08x\n", r );
1362 r = IXMLDOMText_get_text(nodetext, &str);
1363 ok(r == S_OK, "ret %08x\n", r );
1364 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1370 r = IXMLDOMText_put_nodeValue(nodetext, var);
1371 ok(r == S_OK, "ret %08x\n", r );
1374 r = IXMLDOMText_get_text(nodetext, &str);
1375 ok(r == S_OK, "ret %08x\n", r );
1376 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1379 /* ::replaceData() */
1380 V_VT(&var) = VT_BSTR;
1381 V_BSTR(&var) = SysAllocString(szstr1);
1382 r = IXMLDOMText_put_nodeValue(nodetext, var);
1383 ok(r == S_OK, "ret %08x\n", r );
1386 r = IXMLDOMText_replaceData(nodetext, 6, 0, NULL);
1387 ok(r == E_INVALIDARG, "ret %08x\n", r );
1388 r = IXMLDOMText_get_text(nodetext, &str);
1389 ok(r == S_OK, "ret %08x\n", r );
1390 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1393 r = IXMLDOMText_replaceData(nodetext, 0, 0, NULL);
1394 ok(r == S_OK, "ret %08x\n", r );
1395 r = IXMLDOMText_get_text(nodetext, &str);
1396 ok(r == S_OK, "ret %08x\n", r );
1397 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1400 /* NULL pointer means delete */
1401 r = IXMLDOMText_replaceData(nodetext, 0, 1, NULL);
1402 ok(r == S_OK, "ret %08x\n", r );
1403 r = IXMLDOMText_get_text(nodetext, &str);
1404 ok(r == S_OK, "ret %08x\n", r );
1405 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1408 /* empty string means delete */
1409 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_(""));
1410 ok(r == S_OK, "ret %08x\n", r );
1411 r = IXMLDOMText_get_text(nodetext, &str);
1412 ok(r == S_OK, "ret %08x\n", r );
1413 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1416 /* zero count means insert */
1417 r = IXMLDOMText_replaceData(nodetext, 0, 0, _bstr_("a"));
1418 ok(r == S_OK, "ret %08x\n", r );
1419 r = IXMLDOMText_get_text(nodetext, &str);
1420 ok(r == S_OK, "ret %08x\n", r );
1421 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1424 r = IXMLDOMText_replaceData(nodetext, 0, 2, NULL);
1425 ok(r == S_OK, "ret %08x\n", r );
1427 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("m"));
1428 ok(r == S_OK, "ret %08x\n", r );
1429 r = IXMLDOMText_get_text(nodetext, &str);
1430 ok(r == S_OK, "ret %08x\n", r );
1431 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1434 /* nonempty string, count greater than its length */
1435 r = IXMLDOMText_replaceData(nodetext, 0, 2, _bstr_("a1.2"));
1436 ok(r == S_OK, "ret %08x\n", r );
1437 r = IXMLDOMText_get_text(nodetext, &str);
1438 ok(r == S_OK, "ret %08x\n", r );
1439 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1442 /* nonempty string, count less than its length */
1443 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_("wine"));
1444 ok(r == S_OK, "ret %08x\n", r );
1445 r = IXMLDOMText_get_text(nodetext, &str);
1446 ok(r == S_OK, "ret %08x\n", r );
1447 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1450 IXMLDOMText_Release( nodetext );
1453 /* test Create Comment */
1454 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
1455 ok( r == E_INVALIDARG, "returns %08x\n", r );
1456 node_comment = (IXMLDOMComment*)0x1;
1459 r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
1460 ok( r == S_OK, "returns %08x\n", r );
1462 r = IXMLDOMComment_get_data(node_comment, &str);
1463 ok( r == S_OK, "returns %08x\n", r );
1464 ok( str && SysStringLen(str) == 0, "expected empty string data\n");
1465 IXMLDOMComment_Release(node_comment);
1468 r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
1469 ok( r == S_OK, "returns %08x\n", r );
1471 r = IXMLDOMComment_get_data(node_comment, &str);
1472 ok( r == S_OK, "returns %08x\n", r );
1473 ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
1474 IXMLDOMComment_Release(node_comment);
1477 str = SysAllocString(szComment);
1478 r = IXMLDOMDocument_createComment(doc, str, &node_comment);
1480 ok( r == S_OK, "returns %08x\n", r );
1483 /* Last Child Checks */
1484 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
1485 ok(r == E_INVALIDARG, "ret %08x\n", r );
1487 nodeChild = (IXMLDOMNode*)0x1;
1488 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
1489 ok(r == S_FALSE, "ret %08x\n", r );
1490 ok(nodeChild == NULL, "pLastChild not NULL\n");
1493 str = (BSTR)0xdeadbeef;
1494 IXMLDOMComment_get_baseName(node_comment, &str);
1495 ok(r == S_FALSE, "ret %08x\n", r );
1496 ok(str == NULL, "Expected NULL\n");
1498 IXMLDOMComment_Release( node_comment );
1501 /* test Create Attribute */
1502 str = SysAllocString(szAttribute);
1503 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
1504 ok( r == E_INVALIDARG, "returns %08x\n", r );
1505 r = IXMLDOMDocument_createAttribute(doc, str, &node_attr);
1506 ok( r == S_OK, "returns %08x\n", r );
1507 IXMLDOMText_Release( node_attr);
1510 /* test Processing Instruction */
1511 str = SysAllocStringLen(NULL, 0);
1512 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
1513 ok( r == E_INVALIDARG, "returns %08x\n", r );
1514 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
1515 ok( r == E_FAIL, "returns %08x\n", r );
1516 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
1517 ok( r == E_FAIL, "returns %08x\n", r );
1520 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
1521 ok( r == S_OK, "returns %08x\n", r );
1524 /* Last Child Checks */
1525 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
1526 ok(r == E_INVALIDARG, "ret %08x\n", r );
1528 nodeChild = (IXMLDOMNode*)0x1;
1529 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
1530 ok(r == S_FALSE, "ret %08x\n", r );
1531 ok(nodeChild == NULL, "nodeChild not NULL\n");
1533 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
1534 ok(r == S_FALSE, "ret %08x\n", r );
1535 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
1539 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1540 ok(r == S_OK, "ret %08x\n", r );
1541 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1546 r = IXMLDOMProcessingInstruction_get_baseName(nodePI, &str);
1547 ok(r == S_OK, "ret %08x\n", r );
1548 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1552 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
1553 ok(r == S_OK, "ret %08x\n", r );
1554 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
1557 /* test nodeTypeString */
1558 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
1559 ok(r == S_OK, "ret %08x\n", r );
1560 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
1563 /* test get_nodeValue */
1564 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
1565 ok(r == S_OK, "ret %08x\n", r );
1566 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1570 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
1571 ok(r == S_OK, "ret %08x\n", r );
1572 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1576 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
1577 ok(r == E_FAIL, "ret %08x\n", r );
1580 V_VT(&var) = VT_BSTR;
1581 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
1582 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
1583 ok(r == E_FAIL, "ret %08x\n", r );
1586 /* test get nodeName */
1587 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1588 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1589 ok(r == S_OK, "ret %08x\n", r );
1592 IXMLDOMProcessingInstruction_Release(nodePI);
1595 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (void**)&support_error );
1596 ok( r == S_OK, "ret %08x\n", r );
1599 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
1600 todo_wine ok( r == S_OK, "ret %08x\n", r );
1601 ISupportErrorInfo_Release( support_error );
1604 r = IXMLDOMDocument_Release( doc );
1605 ok( r == 0, "document ref count incorrect\n");
1610 static void test_persiststreaminit(void)
1612 IXMLDOMDocument *doc;
1613 IPersistStreamInit *streaminit;
1616 doc = create_document(&IID_IXMLDOMDocument);
1619 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&streaminit);
1620 ok( hr == S_OK, "failed with 0x%08x\n", hr );
1622 hr = IPersistStreamInit_InitNew(streaminit);
1623 ok( hr == S_OK, "failed with 0x%08x\n", hr );
1625 IXMLDOMDocument_Release(doc);
1628 static void test_domnode( void )
1631 IXMLDOMDocument *doc, *owner = NULL;
1632 IXMLDOMElement *element = NULL;
1633 IXMLDOMNamedNodeMap *map = NULL;
1634 IXMLDOMNode *node = NULL, *next = NULL;
1635 IXMLDOMNodeList *list = NULL;
1636 IXMLDOMAttribute *attr = NULL;
1637 DOMNodeType type = NODE_INVALID;
1643 doc = create_document(&IID_IXMLDOMDocument);
1647 str = SysAllocString( szComplete4 );
1648 r = IXMLDOMDocument_loadXML( doc, str, &b );
1649 ok( r == S_OK, "loadXML failed\n");
1650 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1651 SysFreeString( str );
1653 EXPECT_CHILDREN(doc);
1655 r = IXMLDOMDocument_get_documentElement( doc, &element );
1656 ok( r == S_OK, "should be a document element\n");
1657 ok( element != NULL, "should be an element\n");
1660 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1662 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1663 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1665 r = IXMLDOMNode_get_nodeValue( doc, &var );
1666 ok( r == S_FALSE, "nextNode returned wrong code\n");
1667 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1668 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1673 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1674 ok( r == S_OK, "get_ownerDocument return code\n");
1675 ok( owner != doc, "get_ownerDocument return\n");
1676 IXMLDOMDocument_Release(owner);
1678 type = NODE_INVALID;
1679 r = IXMLDOMNode_get_nodeType( element, &type);
1680 ok( r == S_OK, "got %08x\n", r);
1681 ok( type == NODE_ELEMENT, "node not an element\n");
1684 r = IXMLDOMNode_get_baseName( element, &str );
1685 ok( r == S_OK, "get_baseName returned wrong code\n");
1686 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1689 /* check if nodename is correct */
1690 r = IXMLDOMElement_get_nodeName( element, NULL );
1691 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1693 /* content doesn't matter here */
1695 r = IXMLDOMElement_get_nodeName( element, &str );
1696 ok ( r == S_OK, "get_nodeName wrong code\n");
1697 ok ( str != NULL, "str is null\n");
1698 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1699 SysFreeString( str );
1701 str = SysAllocString( szNonExistentFile );
1703 V_I4(&var) = 0x1234;
1704 r = IXMLDOMElement_getAttribute( element, str, &var );
1705 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1706 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1709 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1710 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1712 attr = (IXMLDOMAttribute*)0xdeadbeef;
1713 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1714 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1715 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1716 SysFreeString( str );
1718 attr = (IXMLDOMAttribute*)0xdeadbeef;
1719 str = SysAllocString( szNonExistentAttribute );
1720 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1721 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1722 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1723 SysFreeString( str );
1725 str = SysAllocString( szdl );
1727 V_I4(&var) = 0x1234;
1728 r = IXMLDOMElement_getAttribute( element, str, &var );
1729 ok( r == S_OK, "getAttribute ret %08x\n", r );
1730 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1731 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1732 VariantClear( &var );
1734 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1735 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1737 r = IXMLDOMElement_getAttribute( element, str, NULL );
1738 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1741 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1742 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1743 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1746 r = IXMLDOMAttribute_get_parentNode( attr, NULL );
1747 ok( r == E_INVALIDARG, "Expected E_INVALIDARG, ret %08x\n", r );
1749 /* attribute doesn't have a parent in msxml interpretation */
1750 node = (IXMLDOMNode*)0xdeadbeef;
1751 r = IXMLDOMAttribute_get_parentNode( attr, &node );
1752 ok( r == S_FALSE, "Expected S_FALSE, ret %08x\n", r );
1753 ok( node == NULL, "Expected NULL, got %p\n", node );
1755 IXMLDOMAttribute_Release(attr);
1758 SysFreeString( str );
1760 r = IXMLDOMElement_get_attributes( element, &map );
1761 ok( r == S_OK, "get_attributes returned wrong code\n");
1762 ok( map != NULL, "should be attributes\n");
1764 EXPECT_CHILDREN(element);
1767 ok( FALSE, "no element\n");
1771 ISupportErrorInfo *support_error;
1772 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (void**)&support_error );
1773 ok( r == S_OK, "ret %08x\n", r );
1775 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1778 ok( r == S_OK, "ret %08x\n", r );
1780 ISupportErrorInfo_Release( support_error );
1782 str = SysAllocString( szdl );
1783 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1784 ok( r == S_OK, "getNamedItem returned wrong code\n");
1785 ok( node != NULL, "should be attributes\n");
1786 IXMLDOMNode_Release(node);
1787 SysFreeString( str );
1789 str = SysAllocString( szdl );
1790 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1791 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1792 SysFreeString( str );
1794 /* something that isn't in szComplete4 */
1795 str = SysAllocString( szOpen );
1796 node = (IXMLDOMNode *) 1;
1797 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1798 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1799 ok( node == NULL, "getNamedItem should have returned NULL\n");
1800 SysFreeString( str );
1802 /* test indexed access of attributes */
1803 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1804 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1806 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1807 ok ( r == S_OK, "get_length wrong code\n");
1808 ok ( count == 1, "get_length != 1\n");
1811 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1812 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1813 ok ( node == NULL, "there is no node\n");
1816 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1817 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1818 ok ( node == NULL, "there is no attribute\n");
1821 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1822 ok ( r == S_OK, "get_item (0) wrong code\n");
1823 ok ( node != NULL, "should be attribute\n");
1825 r = IXMLDOMNode_get_nodeName( node, NULL );
1826 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1828 /* content doesn't matter here */
1830 r = IXMLDOMNode_get_nodeName( node, &str );
1831 ok ( r == S_OK, "get_nodeName wrong code\n");
1832 ok ( str != NULL, "str is null\n");
1833 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1834 SysFreeString( str );
1835 IXMLDOMNode_Release( node );
1837 /* test sequential access of attributes */
1839 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1840 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1841 ok ( node != NULL, "nextNode, should be attribute\n");
1842 IXMLDOMNode_Release( node );
1844 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1845 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1846 ok ( node == NULL, "nextNode, there is no attribute\n");
1848 r = IXMLDOMNamedNodeMap_reset( map );
1849 ok ( r == S_OK, "reset should return S_OK\n");
1851 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1852 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1853 ok ( node != NULL, "nextNode, should be attribute\n");
1856 ok( FALSE, "no map\n");
1860 type = NODE_INVALID;
1861 r = IXMLDOMNode_get_nodeType( node, &type);
1862 ok( r == S_OK, "getNamedItem returned wrong code\n");
1863 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1866 r = IXMLDOMNode_get_baseName( node, NULL );
1867 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1870 r = IXMLDOMNode_get_baseName( node, &str );
1871 ok( r == S_OK, "get_baseName returned wrong code\n");
1872 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1873 SysFreeString( str );
1875 r = IXMLDOMNode_get_nodeValue( node, &var );
1876 ok( r == S_OK, "returns %08x\n", r );
1877 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1878 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1881 r = IXMLDOMNode_get_childNodes( node, NULL );
1882 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1884 r = IXMLDOMNode_get_childNodes( node, &list );
1885 ok( r == S_OK, "get_childNodes returned wrong code\n");
1889 r = IXMLDOMNodeList_nextNode( list, &next );
1890 ok( r == S_OK, "nextNode returned wrong code\n");
1893 ok( FALSE, "no childlist\n");
1897 EXPECT_NO_CHILDREN(next);
1899 type = NODE_INVALID;
1900 r = IXMLDOMNode_get_nodeType( next, &type);
1901 ok( r == S_OK, "getNamedItem returned wrong code\n");
1902 ok( type == NODE_TEXT, "node not text\n");
1905 r = IXMLDOMNode_get_baseName( next, &str );
1906 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1907 ok( str == NULL, "basename was wrong\n");
1911 ok( FALSE, "no next\n");
1914 IXMLDOMNode_Release( next );
1917 IXMLDOMNodeList_Release( list );
1920 IXMLDOMNode_Release( node );
1923 ok( FALSE, "no node\n");
1927 IXMLDOMNamedNodeMap_Release( map );
1929 /* now traverse the tree from the root element */
1932 r = IXMLDOMNode_get_childNodes( element, &list );
1933 ok( r == S_OK, "get_childNodes returned wrong code\n");
1935 /* using get_item for child list doesn't advance the position */
1936 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1937 expect_node(node, "E2.E2.D1");
1938 IXMLDOMNode_Release(node);
1939 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1940 expect_node(node, "E1.E2.D1");
1941 IXMLDOMNode_Release(node);
1942 ole_check(IXMLDOMNodeList_reset(list));
1944 IXMLDOMNodeList_AddRef(list);
1945 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1946 ole_check(IXMLDOMNodeList_reset(list));
1948 node = (void*)0xdeadbeef;
1949 str = SysAllocString(szdl);
1950 r = IXMLDOMNode_selectSingleNode( element, str, &node );
1952 ok( r == S_FALSE, "ret %08x\n", r );
1953 ok( node == NULL, "node %p\n", node );
1955 str = SysAllocString(szbs);
1956 r = IXMLDOMNode_selectSingleNode( element, str, &node );
1958 ok( r == S_OK, "ret %08x\n", r );
1959 r = IXMLDOMNode_Release( node );
1960 ok( r == 0, "ret %08x\n", r );
1963 ok( FALSE, "no element\n");
1967 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1968 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1970 r = IXMLDOMNodeList_get_length(list, NULL);
1971 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1973 r = IXMLDOMNodeList_get_length( list, &count );
1974 ok( r == S_OK, "get_length returns %08x\n", r );
1975 ok( count == 4, "get_length got %d\n", count );
1977 r = IXMLDOMNodeList_nextNode(list, NULL);
1978 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1980 r = IXMLDOMNodeList_nextNode( list, &node );
1981 ok( r == S_OK, "nextNode returned wrong code\n");
1984 ok( FALSE, "no list\n");
1988 type = NODE_INVALID;
1989 r = IXMLDOMNode_get_nodeType( node, &type);
1990 ok( r == S_OK, "getNamedItem returned wrong code\n");
1991 ok( type == NODE_ELEMENT, "node not text\n");
1994 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1995 r = IXMLDOMNode_get_nodeValue( node, &var );
1996 ok( r == S_FALSE, "nextNode returned wrong code\n");
1997 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1998 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
2000 r = IXMLDOMNode_hasChildNodes( node, NULL );
2001 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
2003 EXPECT_CHILDREN(node);
2006 r = IXMLDOMNode_get_baseName( node, &str );
2007 ok( r == S_OK, "get_baseName returned wrong code\n");
2008 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
2012 ok( FALSE, "no node\n");
2015 IXMLDOMNode_Release( node );
2017 IXMLDOMNodeList_Release( list );
2019 IXMLDOMElement_Release( element );
2022 str = SysAllocString( szComplete5 );
2023 r = IXMLDOMDocument_loadXML( doc, str, &b );
2024 ok( r == S_OK, "loadXML failed\n");
2025 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2026 SysFreeString( str );
2028 EXPECT_CHILDREN(doc);
2030 r = IXMLDOMDocument_get_documentElement( doc, &element );
2031 ok( r == S_OK, "should be a document element\n");
2032 ok( element != NULL, "should be an element\n");
2036 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
2039 /* check if the tag is correct */
2040 r = IXMLDOMElement_get_tagName( element, &tag );
2041 ok( r == S_OK, "couldn't get tag name\n");
2042 ok( tag != NULL, "tag was null\n");
2043 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
2044 SysFreeString( tag );
2048 IXMLDOMElement_Release( element );
2049 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
2052 static void test_refs(void)
2057 IXMLDOMDocument *doc;
2058 IXMLDOMElement *element = NULL;
2059 IXMLDOMNode *node = NULL, *node2;
2060 IXMLDOMNodeList *node_list = NULL;
2062 IUnknown *unk, *unk2;
2064 doc = create_document(&IID_IXMLDOMDocument);
2068 ref = IXMLDOMDocument_Release(doc);
2069 ok( ref == 0, "ref %d\n", ref);
2071 doc = create_document(&IID_IXMLDOMDocument);
2074 str = SysAllocString( szComplete4 );
2075 r = IXMLDOMDocument_loadXML( doc, str, &b );
2076 ok( r == S_OK, "loadXML failed\n");
2077 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2078 SysFreeString( str );
2081 IXMLDOMDocument_AddRef( doc );
2083 IXMLDOMDocument_AddRef( doc );
2086 IXMLDOMDocument_Release( doc );
2087 IXMLDOMDocument_Release( doc );
2089 r = IXMLDOMDocument_get_documentElement( doc, &element );
2090 ok( r == S_OK, "should be a document element\n");
2091 ok( element != NULL, "should be an element\n");
2094 todo_wine EXPECT_REF(element, 2);
2096 IXMLDOMElement_AddRef(element);
2097 todo_wine EXPECT_REF(element, 3);
2098 IXMLDOMElement_Release(element);
2100 r = IXMLDOMElement_get_childNodes( element, &node_list );
2101 ok( r == S_OK, "rets %08x\n", r);
2103 todo_wine EXPECT_REF(element, 2);
2104 EXPECT_REF(node_list, 1);
2106 IXMLDOMNodeList_get_item( node_list, 0, &node );
2107 ok( r == S_OK, "rets %08x\n", r);
2108 EXPECT_REF(node_list, 1);
2109 EXPECT_REF(node, 1);
2111 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
2112 ok( r == S_OK, "rets %08x\n", r);
2113 EXPECT_REF(node_list, 1);
2114 EXPECT_REF(node2, 1);
2116 ref = IXMLDOMNode_Release( node );
2117 ok( ref == 0, "ref %d\n", ref );
2118 ref = IXMLDOMNode_Release( node2 );
2119 ok( ref == 0, "ref %d\n", ref );
2121 ref = IXMLDOMNodeList_Release( node_list );
2122 ok( ref == 0, "ref %d\n", ref );
2124 ok( node != node2, "node %p node2 %p\n", node, node2 );
2126 ref = IXMLDOMDocument_Release( doc );
2127 ok( ref == 0, "ref %d\n", ref );
2129 todo_wine EXPECT_REF(element, 2);
2131 /* IUnknown must be unique however we obtain it */
2132 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (void**)&unk );
2133 ok( r == S_OK, "rets %08x\n", r );
2134 EXPECT_REF(element, 2);
2135 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (void**)&node );
2136 ok( r == S_OK, "rets %08x\n", r );
2137 todo_wine EXPECT_REF(element, 2);
2138 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk2 );
2139 ok( r == S_OK, "rets %08x\n", r );
2140 todo_wine EXPECT_REF(element, 2);
2141 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
2142 todo_wine ok( element != (void*)node, "node %p element %p\n", node, element );
2144 IUnknown_Release( unk2 );
2145 IUnknown_Release( unk );
2146 IXMLDOMNode_Release( node );
2147 todo_wine EXPECT_REF(element, 2);
2149 IXMLDOMElement_Release( element );
2152 static void test_create(void)
2154 static const WCHAR szOne[] = {'1',0};
2155 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
2159 IXMLDOMDocument *doc;
2160 IXMLDOMElement *element;
2161 IXMLDOMComment *comment;
2163 IXMLDOMCDATASection *cdata;
2164 IXMLDOMNode *root, *node, *child;
2165 IXMLDOMNamedNodeMap *attr_map;
2170 doc = create_document(&IID_IXMLDOMDocument);
2175 /* types not supported for creation */
2177 V_I1(&var) = NODE_DOCUMENT;
2178 node = (IXMLDOMNode*)0x1;
2179 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2180 ok( r == E_INVALIDARG, "returns %08x\n", r );
2181 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2184 V_I1(&var) = NODE_DOCUMENT_TYPE;
2185 node = (IXMLDOMNode*)0x1;
2186 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2187 ok( r == E_INVALIDARG, "returns %08x\n", r );
2188 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2191 V_I1(&var) = NODE_ENTITY;
2192 node = (IXMLDOMNode*)0x1;
2193 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2194 ok( r == E_INVALIDARG, "returns %08x\n", r );
2195 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2198 V_I1(&var) = NODE_NOTATION;
2199 node = (IXMLDOMNode*)0x1;
2200 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2201 ok( r == E_INVALIDARG, "returns %08x\n", r );
2202 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2206 V_I1(&var) = NODE_COMMENT;
2208 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2209 ok( r == S_OK, "returns %08x\n", r );
2210 ok( node != NULL, "\n");
2212 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2213 ok( r == S_OK, "returns %08x\n", r );
2214 IXMLDOMNode_Release(node);
2217 r = IXMLDOMComment_get_data(comment, &str);
2218 ok( r == S_OK, "returns %08x\n", r );
2219 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2220 IXMLDOMComment_Release(comment);
2223 node = (IXMLDOMNode*)0x1;
2224 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2225 ok( r == S_OK, "returns %08x\n", r );
2227 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2228 ok( r == S_OK, "returns %08x\n", r );
2229 IXMLDOMNode_Release(node);
2232 r = IXMLDOMComment_get_data(comment, &str);
2233 ok( r == S_OK, "returns %08x\n", r );
2234 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2235 IXMLDOMComment_Release(comment);
2238 node = (IXMLDOMNode*)0x1;
2239 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2240 ok( r == S_OK, "returns %08x\n", r );
2242 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2243 ok( r == S_OK, "returns %08x\n", r );
2244 IXMLDOMNode_Release(node);
2247 r = IXMLDOMComment_get_data(comment, &str);
2248 ok( r == S_OK, "returns %08x\n", r );
2249 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2250 IXMLDOMComment_Release(comment);
2255 V_I1(&var) = NODE_TEXT;
2257 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2258 ok( r == S_OK, "returns %08x\n", r );
2259 ok( node != NULL, "\n");
2261 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2262 ok( r == S_OK, "returns %08x\n", r );
2263 IXMLDOMNode_Release(node);
2266 r = IXMLDOMText_get_data(text, &str);
2267 ok( r == S_OK, "returns %08x\n", r );
2268 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2269 IXMLDOMText_Release(text);
2272 node = (IXMLDOMNode*)0x1;
2273 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2274 ok( r == S_OK, "returns %08x\n", r );
2276 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2277 ok( r == S_OK, "returns %08x\n", r );
2278 IXMLDOMNode_Release(node);
2281 r = IXMLDOMText_get_data(text, &str);
2282 ok( r == S_OK, "returns %08x\n", r );
2283 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2284 IXMLDOMText_Release(text);
2287 node = (IXMLDOMNode*)0x1;
2288 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2289 ok( r == S_OK, "returns %08x\n", r );
2291 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2292 ok( r == S_OK, "returns %08x\n", r );
2293 IXMLDOMNode_Release(node);
2296 r = IXMLDOMText_get_data(text, &str);
2297 ok( r == S_OK, "returns %08x\n", r );
2298 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2299 IXMLDOMText_Release(text);
2302 /* NODE_CDATA_SECTION */
2304 V_I1(&var) = NODE_CDATA_SECTION;
2306 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2307 ok( r == S_OK, "returns %08x\n", r );
2308 ok( node != NULL, "\n");
2310 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2311 ok( r == S_OK, "returns %08x\n", r );
2312 IXMLDOMNode_Release(node);
2315 r = IXMLDOMCDATASection_get_data(cdata, &str);
2316 ok( r == S_OK, "returns %08x\n", r );
2317 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2318 IXMLDOMCDATASection_Release(cdata);
2321 node = (IXMLDOMNode*)0x1;
2322 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2323 ok( r == S_OK, "returns %08x\n", r );
2325 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2326 ok( r == S_OK, "returns %08x\n", r );
2327 IXMLDOMNode_Release(node);
2330 r = IXMLDOMCDATASection_get_data(cdata, &str);
2331 ok( r == S_OK, "returns %08x\n", r );
2332 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2333 IXMLDOMCDATASection_Release(cdata);
2336 node = (IXMLDOMNode*)0x1;
2337 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2338 ok( r == S_OK, "returns %08x\n", r );
2340 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2341 ok( r == S_OK, "returns %08x\n", r );
2342 IXMLDOMNode_Release(node);
2345 r = IXMLDOMCDATASection_get_data(cdata, &str);
2346 ok( r == S_OK, "returns %08x\n", r );
2347 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2348 IXMLDOMCDATASection_Release(cdata);
2351 /* NODE_ATTRIBUTE */
2353 V_I1(&var) = NODE_ATTRIBUTE;
2354 node = (IXMLDOMNode*)0x1;
2355 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2356 ok( r == E_FAIL, "returns %08x\n", r );
2357 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2360 V_I1(&var) = NODE_ATTRIBUTE;
2361 node = (IXMLDOMNode*)0x1;
2362 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2363 ok( r == E_FAIL, "returns %08x\n", r );
2364 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2367 V_I1(&var) = NODE_ATTRIBUTE;
2368 str = SysAllocString( szlc );
2369 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2370 ok( r == S_OK, "returns %08x\n", r );
2371 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2374 /* a name is required for attribute, try a BSTR with first null wchar */
2376 V_I1(&var) = NODE_ATTRIBUTE;
2377 str = SysAllocString( szstr1 );
2379 node = (IXMLDOMNode*)0x1;
2380 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2381 ok( r == E_FAIL, "returns %08x\n", r );
2382 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2385 /* NODE_PROCESSING_INSTRUCTION */
2387 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2388 node = (IXMLDOMNode*)0x1;
2389 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2390 ok( r == E_FAIL, "returns %08x\n", r );
2391 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2394 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2395 node = (IXMLDOMNode*)0x1;
2396 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2397 ok( r == E_FAIL, "returns %08x\n", r );
2398 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2401 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2402 r = IXMLDOMDocument_createNode( doc, var, _bstr_("pi"), NULL, NULL );
2403 ok( r == E_INVALIDARG, "returns %08x\n", r );
2405 /* NODE_ENTITY_REFERENCE */
2407 V_I1(&var) = NODE_ENTITY_REFERENCE;
2408 node = (IXMLDOMNode*)0x1;
2409 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2410 ok( r == E_FAIL, "returns %08x\n", r );
2411 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2414 V_I1(&var) = NODE_ENTITY_REFERENCE;
2415 node = (IXMLDOMNode*)0x1;
2416 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2417 ok( r == E_FAIL, "returns %08x\n", r );
2418 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2422 V_I1(&var) = NODE_ELEMENT;
2423 node = (IXMLDOMNode*)0x1;
2424 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2425 ok( r == E_FAIL, "returns %08x\n", r );
2426 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2429 V_I1(&var) = NODE_ELEMENT;
2430 node = (IXMLDOMNode*)0x1;
2431 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2432 ok( r == E_FAIL, "returns %08x\n", r );
2433 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2436 V_I1(&var) = NODE_ELEMENT;
2437 str = SysAllocString( szlc );
2438 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2439 ok( r == S_OK, "returns %08x\n", r );
2440 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2443 V_I1(&var) = NODE_ELEMENT;
2444 r = IXMLDOMDocument_createNode( doc, var, str, NULL, NULL );
2445 ok( r == E_INVALIDARG, "returns %08x\n", r );
2448 V_R4(&var) = NODE_ELEMENT;
2449 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2450 ok( r == S_OK, "returns %08x\n", r );
2451 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2453 V_VT(&var) = VT_BSTR;
2454 V_BSTR(&var) = SysAllocString( szOne );
2455 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2456 ok( r == S_OK, "returns %08x\n", r );
2457 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2460 V_VT(&var) = VT_BSTR;
2461 V_BSTR(&var) = SysAllocString( szOneGarbage );
2462 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2463 ok( r == E_INVALIDARG, "returns %08x\n", r );
2464 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2468 V_I4(&var) = NODE_ELEMENT;
2469 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2470 ok( r == S_OK, "returns %08x\n", r );
2473 r = IXMLDOMDocument_appendChild( doc, node, &root );
2474 ok( r == S_OK, "returns %08x\n", r );
2475 ok( node == root, "%p %p\n", node, root );
2478 EXPECT_REF(node, 2);
2480 ref = IXMLDOMNode_Release( node );
2481 ok(ref == 1, "ref %d\n", ref);
2482 SysFreeString( str );
2485 V_I4(&var) = NODE_ELEMENT;
2486 str = SysAllocString( szbs );
2487 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2488 ok( r == S_OK, "returns %08x\n", r );
2489 SysFreeString( str );
2491 EXPECT_REF(node, 1);
2493 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk );
2494 ok( r == S_OK, "returns %08x\n", r );
2498 V_VT(&var) = VT_EMPTY;
2500 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
2501 ok( r == S_OK, "returns %08x\n", r );
2502 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
2504 todo_wine EXPECT_REF(unk, 4);
2506 IXMLDOMNode_Release( child );
2507 IUnknown_Release( unk );
2509 V_VT(&var) = VT_NULL;
2510 V_DISPATCH(&var) = (IDispatch*)node;
2511 r = IXMLDOMNode_insertBefore( root, node, var, &child );
2512 ok( r == S_OK, "returns %08x\n", r );
2513 ok( node == child, "%p %p\n", node, child );
2514 IXMLDOMNode_Release( child );
2516 V_VT(&var) = VT_NULL;
2517 V_DISPATCH(&var) = (IDispatch*)node;
2518 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
2519 ok( r == S_OK, "returns %08x\n", r );
2520 IXMLDOMNode_Release( node );
2522 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (void**)&element );
2523 ok( r == S_OK, "returns %08x\n", r );
2525 r = IXMLDOMElement_get_attributes( element, &attr_map );
2526 ok( r == S_OK, "returns %08x\n", r );
2527 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2528 ok( r == S_OK, "returns %08x\n", r );
2529 ok( num == 0, "num %d\n", num );
2530 IXMLDOMNamedNodeMap_Release( attr_map );
2532 V_VT(&var) = VT_BSTR;
2533 V_BSTR(&var) = SysAllocString( szstr1 );
2534 name = SysAllocString( szdl );
2535 r = IXMLDOMElement_setAttribute( element, name, var );
2536 ok( r == S_OK, "returns %08x\n", r );
2537 r = IXMLDOMElement_get_attributes( element, &attr_map );
2538 ok( r == S_OK, "returns %08x\n", r );
2539 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2540 ok( r == S_OK, "returns %08x\n", r );
2541 ok( num == 1, "num %d\n", num );
2542 IXMLDOMNamedNodeMap_Release( attr_map );
2545 V_VT(&var) = VT_BSTR;
2546 V_BSTR(&var) = SysAllocString( szstr2 );
2547 r = IXMLDOMElement_setAttribute( element, name, var );
2548 ok( r == S_OK, "returns %08x\n", r );
2549 r = IXMLDOMElement_get_attributes( element, &attr_map );
2550 ok( r == S_OK, "returns %08x\n", r );
2551 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2552 ok( r == S_OK, "returns %08x\n", r );
2553 ok( num == 1, "num %d\n", num );
2554 IXMLDOMNamedNodeMap_Release( attr_map );
2556 r = IXMLDOMElement_getAttribute( element, name, &var );
2557 ok( r == S_OK, "returns %08x\n", r );
2558 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
2560 SysFreeString(name);
2562 V_VT(&var) = VT_BSTR;
2563 V_BSTR(&var) = SysAllocString( szstr1 );
2564 name = SysAllocString( szlc );
2565 r = IXMLDOMElement_setAttribute( element, name, var );
2566 ok( r == S_OK, "returns %08x\n", r );
2567 r = IXMLDOMElement_get_attributes( element, &attr_map );
2568 ok( r == S_OK, "returns %08x\n", r );
2569 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2570 ok( r == S_OK, "returns %08x\n", r );
2571 ok( num == 2, "num %d\n", num );
2572 IXMLDOMNamedNodeMap_Release( attr_map );
2574 SysFreeString(name);
2578 name = SysAllocString( szbs );
2579 r = IXMLDOMElement_setAttribute( element, name, var );
2580 ok( r == S_OK, "returns %08x\n", r );
2582 r = IXMLDOMElement_getAttribute( element, name, &var );
2583 ok( r == S_OK, "returns %08x\n", r );
2584 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
2586 SysFreeString(name);
2588 /* Create an Attribute */
2590 V_I4(&var) = NODE_ATTRIBUTE;
2591 str = SysAllocString( szAttribute );
2592 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2593 ok( r == S_OK, "returns %08x\n", r );
2594 ok( node != NULL, "node was null\n");
2597 r = IXMLDOMNode_get_nodeTypeString(node, &str);
2598 ok( r == S_OK, "returns %08x\n", r );
2599 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2601 IXMLDOMNode_Release( node );
2603 IXMLDOMElement_Release( element );
2604 IXMLDOMNode_Release( root );
2605 IXMLDOMDocument_Release( doc );
2608 static void test_getElementsByTagName(void)
2610 IXMLDOMNodeList *node_list;
2611 IXMLDOMDocument *doc;
2612 IXMLDOMElement *elem;
2619 doc = create_document(&IID_IXMLDOMDocument);
2622 str = SysAllocString( szComplete4 );
2623 r = IXMLDOMDocument_loadXML( doc, str, &b );
2624 ok( r == S_OK, "loadXML failed\n");
2625 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2626 SysFreeString( str );
2628 str = SysAllocString( szstar );
2630 /* null arguments cases */
2631 r = IXMLDOMDocument_getElementsByTagName(doc, NULL, &node_list);
2632 ok( r == E_INVALIDARG, "ret %08x\n", r );
2633 r = IXMLDOMDocument_getElementsByTagName(doc, str, NULL);
2634 ok( r == E_INVALIDARG, "ret %08x\n", r );
2636 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2637 ok( r == S_OK, "ret %08x\n", r );
2638 r = IXMLDOMNodeList_get_length( node_list, &len );
2639 ok( r == S_OK, "ret %08x\n", r );
2640 ok( len == 6, "len %d\n", len );
2642 test_disp((IUnknown*)node_list);
2644 IXMLDOMNodeList_Release( node_list );
2645 SysFreeString( str );
2647 /* broken query BSTR */
2648 memcpy(&buff[2], szstar, sizeof(szstar));
2649 /* just a big length */
2650 *(DWORD*)buff = 0xf0f0;
2651 r = IXMLDOMDocument_getElementsByTagName(doc, &buff[2], &node_list);
2652 ok( r == S_OK, "ret %08x\n", r );
2653 r = IXMLDOMNodeList_get_length( node_list, &len );
2654 ok( r == S_OK, "ret %08x\n", r );
2655 ok( len == 6, "len %d\n", len );
2656 IXMLDOMNodeList_Release( node_list );
2658 str = SysAllocString( szbs );
2659 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2660 ok( r == S_OK, "ret %08x\n", r );
2661 r = IXMLDOMNodeList_get_length( node_list, &len );
2662 ok( r == S_OK, "ret %08x\n", r );
2663 ok( len == 1, "len %d\n", len );
2664 IXMLDOMNodeList_Release( node_list );
2665 SysFreeString( str );
2667 str = SysAllocString( szdl );
2668 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2669 ok( r == S_OK, "ret %08x\n", r );
2670 r = IXMLDOMNodeList_get_length( node_list, &len );
2671 ok( r == S_OK, "ret %08x\n", r );
2672 ok( len == 0, "len %d\n", len );
2673 IXMLDOMNodeList_Release( node_list );
2674 SysFreeString( str );
2676 str = SysAllocString( szstr1 );
2677 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2678 ok( r == S_OK, "ret %08x\n", r );
2679 r = IXMLDOMNodeList_get_length( node_list, &len );
2680 ok( r == S_OK, "ret %08x\n", r );
2681 ok( len == 0, "len %d\n", len );
2682 IXMLDOMNodeList_Release( node_list );
2683 SysFreeString( str );
2685 /* test for element */
2686 r = IXMLDOMDocument_get_documentElement(doc, &elem);
2687 ok( r == S_OK, "ret %08x\n", r );
2689 str = SysAllocString( szstar );
2691 /* null arguments cases */
2692 r = IXMLDOMElement_getElementsByTagName(elem, NULL, &node_list);
2693 ok( r == E_INVALIDARG, "ret %08x\n", r );
2694 r = IXMLDOMElement_getElementsByTagName(elem, str, NULL);
2695 ok( r == E_INVALIDARG, "ret %08x\n", r );
2697 r = IXMLDOMElement_getElementsByTagName(elem, str, &node_list);
2698 ok( r == S_OK, "ret %08x\n", r );
2699 r = IXMLDOMNodeList_get_length( node_list, &len );
2700 ok( r == S_OK, "ret %08x\n", r );
2701 ok( len == 5, "len %d\n", len );
2702 expect_list_and_release(node_list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1 E1.E4.E2.D1");
2703 SysFreeString( str );
2705 /* broken query BSTR */
2706 memcpy(&buff[2], szstar, sizeof(szstar));
2707 /* just a big length */
2708 *(DWORD*)buff = 0xf0f0;
2709 r = IXMLDOMElement_getElementsByTagName(elem, &buff[2], &node_list);
2710 ok( r == S_OK, "ret %08x\n", r );
2711 r = IXMLDOMNodeList_get_length( node_list, &len );
2712 ok( r == S_OK, "ret %08x\n", r );
2713 ok( len == 5, "len %d\n", len );
2714 IXMLDOMNodeList_Release( node_list );
2716 IXMLDOMElement_Release(elem);
2718 IXMLDOMDocument_Release( doc );
2721 static void test_get_text(void)
2726 IXMLDOMDocument *doc;
2727 IXMLDOMNode *node, *node2, *node3;
2728 IXMLDOMNode *nodeRoot;
2729 IXMLDOMNodeList *node_list;
2730 IXMLDOMNamedNodeMap *node_map;
2733 doc = create_document(&IID_IXMLDOMDocument);
2736 str = SysAllocString( szComplete4 );
2737 r = IXMLDOMDocument_loadXML( doc, str, &b );
2738 ok( r == S_OK, "loadXML failed\n");
2739 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2740 SysFreeString( str );
2742 str = SysAllocString( szbs );
2743 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
2744 ok( r == S_OK, "ret %08x\n", r );
2747 /* Test to get all child node text. */
2748 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&nodeRoot);
2749 ok( r == S_OK, "ret %08x\n", r );
2752 r = IXMLDOMNode_get_text( nodeRoot, &str );
2753 ok( r == S_OK, "ret %08x\n", r );
2754 ok( compareIgnoreReturns(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text: %s\n", wine_dbgstr_w(str));
2757 IXMLDOMNode_Release(nodeRoot);
2760 r = IXMLDOMNodeList_get_length( node_list, NULL );
2761 ok( r == E_INVALIDARG, "ret %08x\n", r );
2763 r = IXMLDOMNodeList_get_length( node_list, &len );
2764 ok( r == S_OK, "ret %08x\n", r );
2765 ok( len == 1, "expect 1 got %d\n", len );
2767 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
2768 ok( r == E_INVALIDARG, "ret %08x\n", r );
2770 r = IXMLDOMNodeList_nextNode( node_list, NULL );
2771 ok( r == E_INVALIDARG, "ret %08x\n", r );
2773 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
2774 ok( r == S_OK, "ret %08x\n", r );
2775 IXMLDOMNodeList_Release( node_list );
2777 /* Invalid output parameter*/
2778 r = IXMLDOMNode_get_text( node, NULL );
2779 ok( r == E_INVALIDARG, "ret %08x\n", r );
2781 r = IXMLDOMNode_get_text( node, &str );
2782 ok( r == S_OK, "ret %08x\n", r );
2783 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
2786 r = IXMLDOMNode_get_attributes( node, &node_map );
2787 ok( r == S_OK, "ret %08x\n", r );
2789 str = SysAllocString( szvr );
2790 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
2791 ok( r == S_OK, "ret %08x\n", r );
2794 r = IXMLDOMNode_get_text( node2, &str );
2795 ok( r == S_OK, "ret %08x\n", r );
2796 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
2799 r = IXMLDOMNode_get_firstChild( node2, &node3 );
2800 ok( r == S_OK, "ret %08x\n", r );
2802 r = IXMLDOMNode_get_text( node3, &str );
2803 ok( r == S_OK, "ret %08x\n", r );
2804 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
2808 IXMLDOMNode_Release( node3 );
2809 IXMLDOMNode_Release( node2 );
2810 IXMLDOMNamedNodeMap_Release( node_map );
2811 IXMLDOMNode_Release( node );
2812 IXMLDOMDocument_Release( doc );
2815 static void test_get_childNodes(void)
2820 IXMLDOMDocument *doc;
2821 IXMLDOMElement *element;
2822 IXMLDOMNode *node, *node2;
2823 IXMLDOMNodeList *node_list, *node_list2;
2826 doc = create_document(&IID_IXMLDOMDocument);
2829 str = SysAllocString( szComplete4 );
2830 r = IXMLDOMDocument_loadXML( doc, str, &b );
2831 ok( r == S_OK, "loadXML failed\n");
2832 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2833 SysFreeString( str );
2835 r = IXMLDOMDocument_get_documentElement( doc, &element );
2836 ok( r == S_OK, "ret %08x\n", r);
2838 r = IXMLDOMElement_get_childNodes( element, &node_list );
2839 ok( r == S_OK, "ret %08x\n", r);
2841 r = IXMLDOMNodeList_get_length( node_list, &len );
2842 ok( r == S_OK, "ret %08x\n", r);
2843 ok( len == 4, "len %d\n", len);
2845 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
2846 ok( r == S_OK, "ret %08x\n", r);
2848 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
2849 ok( r == S_OK, "ret %08x\n", r);
2851 r = IXMLDOMNodeList_get_length( node_list2, &len );
2852 ok( r == S_OK, "ret %08x\n", r);
2853 ok( len == 0, "len %d\n", len);
2855 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
2856 ok( r == S_FALSE, "ret %08x\n", r);
2858 IXMLDOMNodeList_Release( node_list2 );
2859 IXMLDOMNode_Release( node );
2860 IXMLDOMNodeList_Release( node_list );
2861 IXMLDOMElement_Release( element );
2862 IXMLDOMDocument_Release( doc );
2865 static void test_get_firstChild(void)
2867 static WCHAR xmlW[] = {'x','m','l',0};
2868 IXMLDOMDocument *doc;
2874 doc = create_document(&IID_IXMLDOMDocument);
2877 str = SysAllocString( szComplete4 );
2878 r = IXMLDOMDocument_loadXML( doc, str, &b );
2879 ok( r == S_OK, "loadXML failed\n");
2880 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2881 SysFreeString( str );
2883 r = IXMLDOMDocument_get_firstChild( doc, &node );
2884 ok( r == S_OK, "ret %08x\n", r);
2886 r = IXMLDOMNode_get_nodeName( node, &str );
2887 ok( r == S_OK, "ret %08x\n", r);
2889 ok(memcmp(str, xmlW, sizeof(xmlW)) == 0, "expected \"xml\" node name\n");
2892 IXMLDOMNode_Release( node );
2893 IXMLDOMDocument_Release( doc );
2896 static void test_get_lastChild(void)
2898 static WCHAR lcW[] = {'l','c',0};
2899 static WCHAR foW[] = {'f','o',0};
2900 IXMLDOMDocument *doc;
2901 IXMLDOMNode *node, *child;
2906 doc = create_document(&IID_IXMLDOMDocument);
2909 str = SysAllocString( szComplete4 );
2910 r = IXMLDOMDocument_loadXML( doc, str, &b );
2911 ok( r == S_OK, "loadXML failed\n");
2912 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2913 SysFreeString( str );
2915 r = IXMLDOMDocument_get_lastChild( doc, &node );
2916 ok( r == S_OK, "ret %08x\n", r);
2918 r = IXMLDOMNode_get_nodeName( node, &str );
2919 ok( r == S_OK, "ret %08x\n", r);
2921 ok(memcmp(str, lcW, sizeof(lcW)) == 0, "expected \"lc\" node name\n");
2924 r = IXMLDOMNode_get_lastChild( node, &child );
2925 ok( r == S_OK, "ret %08x\n", r);
2927 r = IXMLDOMNode_get_nodeName( child, &str );
2928 ok( r == S_OK, "ret %08x\n", r);
2930 ok(memcmp(str, foW, sizeof(foW)) == 0, "expected \"fo\" node name\n");
2933 IXMLDOMNode_Release( child );
2934 IXMLDOMNode_Release( node );
2935 IXMLDOMDocument_Release( doc );
2938 static void test_removeChild(void)
2943 IXMLDOMDocument *doc;
2944 IXMLDOMElement *element, *lc_element;
2945 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
2946 IXMLDOMNodeList *root_list, *fo_list;
2948 doc = create_document(&IID_IXMLDOMDocument);
2951 str = SysAllocString( szComplete4 );
2952 r = IXMLDOMDocument_loadXML( doc, str, &b );
2953 ok( r == S_OK, "loadXML failed\n");
2954 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2955 SysFreeString( str );
2957 r = IXMLDOMDocument_get_documentElement( doc, &element );
2958 ok( r == S_OK, "ret %08x\n", r);
2959 todo_wine EXPECT_REF(element, 2);
2961 r = IXMLDOMElement_get_childNodes( element, &root_list );
2962 ok( r == S_OK, "ret %08x\n", r);
2963 EXPECT_REF(root_list, 1);
2965 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2966 ok( r == S_OK, "ret %08x\n", r);
2967 EXPECT_REF(fo_node, 1);
2969 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2970 ok( r == S_OK, "ret %08x\n", r);
2971 EXPECT_REF(fo_list, 1);
2973 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2974 ok( r == S_OK, "ret %08x\n", r);
2975 EXPECT_REF(ba_node, 1);
2977 /* invalid parameter: NULL ptr */
2978 removed_node = (void*)0xdeadbeef;
2979 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
2980 ok( r == E_INVALIDARG, "ret %08x\n", r );
2981 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2983 /* ba_node is a descendant of element, but not a direct child. */
2984 removed_node = (void*)0xdeadbeef;
2985 EXPECT_REF(ba_node, 1);
2986 EXPECT_CHILDREN(fo_node);
2987 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
2988 ok( r == E_INVALIDARG, "ret %08x\n", r );
2989 ok( removed_node == NULL, "%p\n", removed_node );
2990 EXPECT_REF(ba_node, 1);
2991 EXPECT_CHILDREN(fo_node);
2993 EXPECT_REF(ba_node, 1);
2994 EXPECT_REF(fo_node, 1);
2995 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
2996 ok( r == S_OK, "ret %08x\n", r);
2997 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
2998 EXPECT_REF(fo_node, 2);
2999 EXPECT_REF(ba_node, 1);
3001 /* try removing already removed child */
3002 temp_node = (void*)0xdeadbeef;
3003 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
3004 ok( r == E_INVALIDARG, "ret %08x\n", r);
3005 ok( temp_node == NULL, "%p\n", temp_node );
3006 IXMLDOMNode_Release( fo_node );
3008 /* the removed node has no parent anymore */
3009 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
3010 ok( r == S_FALSE, "ret %08x\n", r);
3011 ok( temp_node == NULL, "%p\n", temp_node );
3013 IXMLDOMNode_Release( removed_node );
3014 IXMLDOMNode_Release( ba_node );
3015 IXMLDOMNodeList_Release( fo_list );
3017 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
3018 ok( r == S_OK, "ret %08x\n", r);
3020 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (void**)&lc_element );
3021 ok( r == S_OK, "ret %08x\n", r);
3023 /* MS quirk: passing wrong interface pointer works, too */
3024 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
3025 ok( r == S_OK, "ret %08x\n", r);
3026 IXMLDOMElement_Release( lc_element );
3028 temp_node = (void*)0xdeadbeef;
3029 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
3030 ok( r == S_FALSE, "ret %08x\n", r);
3031 ok( temp_node == NULL, "%p\n", temp_node );
3033 IXMLDOMNode_Release( lc_node );
3034 IXMLDOMNodeList_Release( root_list );
3035 IXMLDOMElement_Release( element );
3036 IXMLDOMDocument_Release( doc );
3039 static void test_replaceChild(void)
3044 IXMLDOMDocument *doc;
3045 IXMLDOMElement *element, *ba_element;
3046 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
3047 IXMLDOMNodeList *root_list, *fo_list;
3048 IUnknown * unk1, *unk2;
3051 doc = create_document(&IID_IXMLDOMDocument);
3054 str = SysAllocString( szComplete4 );
3055 r = IXMLDOMDocument_loadXML( doc, str, &b );
3056 ok( r == S_OK, "loadXML failed\n");
3057 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3058 SysFreeString( str );
3060 r = IXMLDOMDocument_get_documentElement( doc, &element );
3061 ok( r == S_OK, "ret %08x\n", r);
3063 r = IXMLDOMElement_get_childNodes( element, &root_list );
3064 ok( r == S_OK, "ret %08x\n", r);
3066 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
3067 ok( r == S_OK, "ret %08x\n", r);
3069 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
3070 ok( r == S_OK, "ret %08x\n", r);
3072 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3073 ok( r == S_OK, "ret %08x\n", r);
3075 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
3076 ok( r == S_OK, "ret %08x\n", r);
3078 IXMLDOMNodeList_Release( fo_list );
3080 /* invalid parameter: NULL ptr for element to remove */
3081 removed_node = (void*)0xdeadbeef;
3082 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
3083 ok( r == E_INVALIDARG, "ret %08x\n", r );
3084 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3086 /* invalid parameter: NULL for replacement element. (Sic!) */
3087 removed_node = (void*)0xdeadbeef;
3088 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
3089 ok( r == E_INVALIDARG, "ret %08x\n", r );
3090 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3092 /* invalid parameter: OldNode is not a child */
3093 removed_node = (void*)0xdeadbeef;
3094 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
3095 ok( r == E_INVALIDARG, "ret %08x\n", r );
3096 ok( removed_node == NULL, "%p\n", removed_node );
3097 IXMLDOMNode_Release( lc_node );
3099 /* invalid parameter: would create loop */
3100 removed_node = (void*)0xdeadbeef;
3101 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
3102 ok( r == E_FAIL, "ret %08x\n", r );
3103 ok( removed_node == NULL, "%p\n", removed_node );
3105 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
3106 ok( r == S_OK, "ret %08x\n", r );
3108 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
3109 ok( r == S_OK, "ret %08x\n", r );
3111 /* ba_node and temp_node refer to the same node, yet they
3112 are different interface pointers */
3113 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
3114 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
3115 ok( r == S_OK, "ret %08x\n", r );
3116 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
3117 ok( r == S_OK, "ret %08x\n", r );
3118 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
3120 IUnknown_Release( unk1 );
3121 IUnknown_Release( unk2 );
3123 /* ba_node should have been removed from below fo_node */
3124 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3125 ok( r == S_OK, "ret %08x\n", r );
3127 /* MS quirk: replaceChild also accepts elements instead of nodes */
3128 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
3129 ok( r == S_OK, "ret %08x\n", r );
3130 EXPECT_REF(ba_element, 2);
3132 removed_node = NULL;
3133 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
3134 ok( r == S_OK, "ret %08x\n", r );
3135 ok( removed_node != NULL, "got %p\n", removed_node);
3136 EXPECT_REF(ba_element, 3);
3137 IXMLDOMElement_Release( ba_element );
3139 r = IXMLDOMNodeList_get_length( fo_list, &len);
3140 ok( r == S_OK, "ret %08x\n", r );
3141 ok( len == 0, "len %d\n", len);
3143 IXMLDOMNodeList_Release( fo_list );
3145 IXMLDOMNode_Release(ba_node);
3146 IXMLDOMNode_Release(fo_node);
3147 IXMLDOMNode_Release(temp_node);
3148 IXMLDOMNodeList_Release( root_list );
3149 IXMLDOMElement_Release( element );
3150 IXMLDOMDocument_Release( doc );
3153 static void test_removeNamedItem(void)
3155 IXMLDOMDocument *doc;
3156 IXMLDOMElement *element;
3157 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
3158 IXMLDOMNodeList *root_list;
3159 IXMLDOMNamedNodeMap * pr_attrs;
3165 doc = create_document(&IID_IXMLDOMDocument);
3168 str = SysAllocString( szComplete4 );
3169 r = IXMLDOMDocument_loadXML( doc, str, &b );
3170 ok( r == S_OK, "loadXML failed\n");
3171 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3172 SysFreeString( str );
3174 r = IXMLDOMDocument_get_documentElement( doc, &element );
3175 ok( r == S_OK, "ret %08x\n", r);
3177 r = IXMLDOMElement_get_childNodes( element, &root_list );
3178 ok( r == S_OK, "ret %08x\n", r);
3180 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
3181 ok( r == S_OK, "ret %08x\n", r);
3183 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
3184 ok( r == S_OK, "ret %08x\n", r);
3186 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3187 ok( r == S_OK, "ret %08x\n", r);
3188 ok( len == 3, "length %d\n", len);
3190 removed_node = (void*)0xdeadbeef;
3191 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
3192 ok ( r == E_INVALIDARG, "ret %08x\n", r);
3193 ok ( removed_node == (void*)0xdeadbeef, "got %p\n", removed_node);
3195 removed_node = (void*)0xdeadbeef;
3196 str = SysAllocString(szvr);
3197 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
3198 ok ( r == S_OK, "ret %08x\n", r);
3200 removed_node2 = (void*)0xdeadbeef;
3201 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
3202 ok ( r == S_FALSE, "ret %08x\n", r);
3203 ok ( removed_node2 == NULL, "got %p\n", removed_node2 );
3205 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3206 ok( r == S_OK, "ret %08x\n", r);
3207 ok( len == 2, "length %d\n", len);
3209 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
3210 ok ( r == S_OK, "ret %08x\n", r);
3211 IXMLDOMNode_Release(removed_node);
3213 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3214 ok( r == S_OK, "ret %08x\n", r);
3215 ok( len == 3, "length %d\n", len);
3217 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
3218 ok ( r == S_OK, "ret %08x\n", r);
3220 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3221 ok( r == S_OK, "ret %08x\n", r);
3222 ok( len == 2, "length %d\n", len);
3224 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
3225 ok ( r == S_FALSE, "ret %08x\n", r);
3229 IXMLDOMNamedNodeMap_Release( pr_attrs );
3230 IXMLDOMNode_Release( pr_node );
3231 IXMLDOMNodeList_Release( root_list );
3232 IXMLDOMElement_Release( element );
3233 IXMLDOMDocument_Release( doc );
3236 #define test_IObjectSafety_set(p, r, r2, s, m, e, e2) _test_IObjectSafety_set(__LINE__,p, r, r2, s, m, e, e2)
3237 static void _test_IObjectSafety_set(unsigned line, IObjectSafety *safety, HRESULT result,
3238 HRESULT result2, DWORD set, DWORD mask, DWORD expected,
3241 DWORD enabled, supported;
3244 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL, set, mask);
3245 if (result == result2)
3246 ok_(__FILE__,line)(hr == result, "SetInterfaceSafetyOptions: expected %08x, returned %08x\n", result, hr );
3248 ok_(__FILE__,line)(broken(hr == result) || hr == result2,
3249 "SetInterfaceSafetyOptions: expected %08x, got %08x\n", result2, hr );
3251 supported = enabled = 0xCAFECAFE;
3252 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3253 ok(hr == S_OK, "ret %08x\n", hr );
3254 if (expected == expected2)
3255 ok_(__FILE__,line)(enabled == expected, "Expected %08x, got %08x\n", expected, enabled);
3257 ok_(__FILE__,line)(broken(enabled == expected) || enabled == expected2,
3258 "Expected %08x, got %08x\n", expected2, enabled);
3260 /* reset the safety options */
3262 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
3263 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER,
3265 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3267 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3268 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3269 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
3272 #define test_IObjectSafety_common(s) _test_IObjectSafety_common(__LINE__,s)
3273 static void _test_IObjectSafety_common(unsigned line, IObjectSafety *safety)
3275 DWORD enabled = 0, supported = 0;
3279 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, NULL, &enabled);
3280 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
3281 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, NULL);
3282 ok_(__FILE__,line)(hr == E_POINTER, "ret %08x\n", hr );
3284 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3285 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3286 ok_(__FILE__,line)(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
3287 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
3288 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
3289 "got %08x\n", supported);
3290 ok_(__FILE__,line)(enabled == 0, "Expected 0, got %08x\n", enabled);
3292 /* set -- individual flags */
3294 test_IObjectSafety_set(safety, S_OK, S_OK,
3295 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3296 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER);
3298 test_IObjectSafety_set(safety, S_OK, S_OK,
3299 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA,
3300 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
3302 test_IObjectSafety_set(safety, S_OK, S_OK,
3303 INTERFACE_USES_SECURITY_MANAGER, INTERFACE_USES_SECURITY_MANAGER,
3304 0, INTERFACE_USES_SECURITY_MANAGER /* msxml3 SP8+ */);
3306 /* set INTERFACE_USES_DISPEX */
3308 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
3309 INTERFACE_USES_DISPEX, INTERFACE_USES_DISPEX,
3312 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
3313 INTERFACE_USES_DISPEX, 0,
3316 test_IObjectSafety_set(safety, S_OK, S_OK /* msxml3 SP8+ */,
3317 0, INTERFACE_USES_DISPEX,
3320 /* set option masking */
3322 test_IObjectSafety_set(safety, S_OK, S_OK,
3323 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
3324 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3325 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3326 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
3328 test_IObjectSafety_set(safety, S_OK, S_OK,
3329 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
3330 INTERFACESAFE_FOR_UNTRUSTED_DATA,
3331 INTERFACESAFE_FOR_UNTRUSTED_DATA,
3332 INTERFACESAFE_FOR_UNTRUSTED_DATA);
3334 test_IObjectSafety_set(safety, S_OK, S_OK,
3335 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
3336 INTERFACE_USES_SECURITY_MANAGER,
3340 /* set -- inheriting previous settings */
3342 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
3343 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
3344 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
3345 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3346 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3347 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3349 ok_(__FILE__,line)(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_CALLER) ||
3350 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
3351 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER), "
3352 "got %08x\n", enabled);
3354 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
3355 INTERFACESAFE_FOR_UNTRUSTED_DATA,
3356 INTERFACESAFE_FOR_UNTRUSTED_DATA);
3357 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3358 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
3359 ok_(__FILE__,line)(hr == S_OK, "ret %08x\n", hr );
3361 ok_(__FILE__,line)(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_DATA) ||
3362 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA) /* msxml3 SP8+ */,
3363 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA), "
3364 "got %08x\n", enabled);
3367 static void test_XMLHTTP(void)
3369 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
3370 static const WCHAR wszPOST[] = {'P','O','S','T',0};
3371 static const WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
3372 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
3373 'p','o','s','t','t','e','s','t','.','p','h','p',0};
3374 static const WCHAR xmltestW[] = {'h','t','t','p',':','/','/',
3375 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
3376 'x','m','l','t','e','s','t','.','x','m','l',0};
3377 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
3378 static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
3380 IXMLHttpRequest *pXMLHttpRequest;
3381 IObjectSafety *safety;
3382 IObjectWithSite *pSite;
3383 BSTR bstrResponse, method, url;
3387 LONG state, status, bound;
3390 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
3391 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
3392 (void **)&pXMLHttpRequest);
3395 win_skip("IXMLHTTPRequest is not available (0x%08x)\n", hr);
3399 hr = IXMLHttpRequest_QueryInterface(pXMLHttpRequest, &IID_IObjectWithSite, (void**)&pSite);
3400 ok(hr == S_OK, "got 0x%08x\n", hr);
3401 if(hr == S_OK) IObjectWithSite_Release(pSite);
3403 VariantInit(&dummy);
3404 V_VT(&dummy) = VT_ERROR;
3405 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
3406 VariantInit(&async);
3407 V_VT(&async) = VT_BOOL;
3408 V_BOOL(&async) = VARIANT_FALSE;
3409 V_VT(&varbody) = VT_BSTR;
3410 V_BSTR(&varbody) = SysAllocString(wszBody);
3412 method = SysAllocString(wszPOST);
3413 url = SysAllocString(wszUrl);
3415 hr = IXMLHttpRequest_put_onreadystatechange(pXMLHttpRequest, NULL);
3416 ok(hr == S_OK, "got 0x%08x\n", hr);
3418 hr = IXMLHttpRequest_abort(pXMLHttpRequest);
3419 ok(hr == S_OK, "got 0x%08x\n", hr);
3421 /* send before open */
3422 hr = IXMLHttpRequest_send(pXMLHttpRequest, dummy);
3423 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
3425 /* initial status code */
3426 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, NULL);
3427 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3429 status = 0xdeadbeef;
3430 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, &status);
3431 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
3432 ok(status == 0xdeadbeef, "got %d\n", status);
3434 /* invalid parameters */
3435 hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, NULL, async, dummy, dummy);
3436 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3438 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, NULL, async, dummy, dummy);
3439 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3441 hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, url, async, dummy, dummy);
3442 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3444 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, NULL);
3445 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3447 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), NULL);
3448 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
3450 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, _bstr_("value1"));
3451 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3453 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), _bstr_("value1"));
3454 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
3456 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, NULL);
3457 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3460 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
3461 ok(hr == S_OK, "got 0x%08x\n", hr);
3462 ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state);
3464 event = create_dispevent();
3466 EXPECT_REF(event, 1);
3467 hr = IXMLHttpRequest_put_onreadystatechange(pXMLHttpRequest, event);
3468 ok(hr == S_OK, "got 0x%08x\n", hr);
3469 EXPECT_REF(event, 2);
3471 g_unexpectedcall = g_expectedcall = 0;
3473 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, url, async, dummy, dummy);
3474 ok(hr == S_OK, "got 0x%08x\n", hr);
3476 ok(g_unexpectedcall == 0, "unexpected disp event call\n");
3477 ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n");
3479 /* status code after ::open() */
3480 status = 0xdeadbeef;
3481 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, &status);
3482 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
3483 ok(status == 0xdeadbeef, "got %d\n", status);
3486 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
3487 ok(hr == S_OK, "got 0x%08x\n", hr);
3488 ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state);
3490 hr = IXMLHttpRequest_abort(pXMLHttpRequest);
3491 ok(hr == S_OK, "got 0x%08x\n", hr);
3494 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
3495 ok(hr == S_OK, "got 0x%08x\n", hr);
3496 ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win2k */,
3497 "got %d, expected READYSTATE_UNINITIALIZED\n", state);
3499 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, url, async, dummy, dummy);
3500 ok(hr == S_OK, "got 0x%08x\n", hr);
3502 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), _bstr_("value1"));
3503 ok(hr == S_OK, "got 0x%08x\n", hr);
3505 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, _bstr_("value1"));
3506 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3508 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_(""), _bstr_("value1"));
3509 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3511 SysFreeString(method);
3514 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
3515 if (hr == INET_E_RESOURCE_NOT_FOUND)
3517 skip("No connection could be made with crossover.codeweavers.com\n");
3518 IXMLHttpRequest_Release(pXMLHttpRequest);
3521 ok(hr == S_OK, "got 0x%08x\n", hr);
3523 /* status code after ::send() */
3524 status = 0xdeadbeef;
3525 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, &status);
3526 ok(hr == S_OK, "got 0x%08x\n", hr);
3527 ok(status == 200, "got %d\n", status);
3529 /* another ::send() after completed request */
3530 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
3531 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
3533 VariantClear(&varbody);
3535 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
3536 ok(hr == S_OK, "got 0x%08x\n", hr);
3537 /* the server currently returns "FAILED" because the Content-Type header is
3538 * not what the server expects */
3541 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)),
3542 "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse));
3543 SysFreeString(bstrResponse);
3547 url = SysAllocString(xmltestW);
3549 hr = IXMLHttpRequest_open(pXMLHttpRequest, _bstr_("GET"), url, async, dummy, dummy);
3550 ok(hr == S_OK, "got 0x%08x\n", hr);
3552 V_VT(&varbody) = VT_EMPTY;
3554 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
3555 if (hr == INET_E_RESOURCE_NOT_FOUND)
3557 skip("No connection could be made with crossover.codeweavers.com\n");
3558 IXMLHttpRequest_Release(pXMLHttpRequest);
3561 ok(hr == S_OK, "got 0x%08x\n", hr);
3563 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, NULL);
3564 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3566 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
3567 ok(hr == S_OK, "got 0x%08x\n", hr);
3570 ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
3571 "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
3572 SysFreeString(bstrResponse);
3575 hr = IXMLHttpRequest_get_responseBody(pXMLHttpRequest, NULL);
3576 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3578 V_VT(&varbody) = VT_EMPTY;
3579 hr = IXMLHttpRequest_get_responseBody(pXMLHttpRequest, &varbody);
3580 ok(hr == S_OK, "got 0x%08x\n", hr);
3581 ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
3582 ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
3585 hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
3586 ok(hr == S_OK, "got 0x%08x\n", hr);
3587 ok(bound == 0, "got %d, expected zero bound\n", bound);
3589 hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
3590 ok(hr == S_OK, "got 0x%08x\n", hr);
3591 ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrond body data\n");
3592 SafeArrayUnaccessData(V_ARRAY(&varbody));
3594 VariantClear(&varbody);
3598 hr = IXMLHttpRequest_QueryInterface(pXMLHttpRequest, &IID_IObjectSafety, (void**)&safety);
3599 ok(hr == S_OK, "ret %08x\n", hr );
3602 test_IObjectSafety_common(safety);
3604 IObjectSafety_Release(safety);
3608 IDispatch_Release(event);
3609 IXMLHttpRequest_Release(pXMLHttpRequest);
3613 static void test_IXMLDOMDocument2(void)
3615 static const WCHAR emptyW[] = {0};
3616 IXMLDOMDocument2 *doc2, *dtddoc2;
3617 IXMLDOMDocument *doc;
3618 IXMLDOMParseError* err;
3619 IDispatchEx *dispex;
3626 doc = create_document(&IID_IXMLDOMDocument);
3629 dtddoc2 = create_document(&IID_IXMLDOMDocument2);
3632 IXMLDOMDocument_Release(doc);
3636 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
3637 ok( r == S_OK, "ret %08x\n", r );
3638 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
3640 ole_expect(IXMLDOMDocument2_get_readyState(doc2, NULL), E_INVALIDARG);
3641 ole_check(IXMLDOMDocument2_get_readyState(doc2, &res));
3642 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
3645 ole_expect(IXMLDOMDocument2_validate(doc2, NULL), S_FALSE);
3646 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
3647 ok(err != NULL, "expected a pointer\n");
3651 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3653 ok(res == E_XML_NOTWF, "got %08x\n", res);
3654 IXMLDOMParseError_Release(err);
3657 str = SysAllocString( szComplete4 );
3658 r = IXMLDOMDocument_loadXML( doc2, str, &b );
3659 ok( r == S_OK, "loadXML failed\n");
3660 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3661 SysFreeString( str );
3663 ole_check(IXMLDOMDocument2_get_readyState(doc, &res));
3664 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
3667 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
3668 ok(err != NULL, "expected a pointer\n");
3672 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3674 ok(res == E_XML_NODTD, "got %08x\n", res);
3675 IXMLDOMParseError_Release(err);
3678 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
3679 ok( r == S_OK, "ret %08x\n", r );
3682 IDispatchEx_Release(dispex);
3685 /* we will check if the variant got cleared */
3686 IXMLDOMDocument2_AddRef(doc2);
3687 EXPECT_REF(doc2, 3); /* doc, doc2, AddRef*/
3689 V_VT(&var) = VT_UNKNOWN;
3690 V_UNKNOWN(&var) = (IUnknown *)doc2;
3693 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
3694 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
3695 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
3698 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3699 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3700 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3703 /* the variant didn't get cleared*/
3704 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
3706 /* setProperty tests */
3707 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
3708 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
3709 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
3710 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3711 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3712 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3714 V_VT(&var) = VT_BSTR;
3715 V_BSTR(&var) = SysAllocString(emptyW);
3716 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3717 ok(r == S_OK, "got 0x%08x\n", r);
3722 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3723 ok(r == E_FAIL, "got 0x%08x\n", r);
3725 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
3726 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3727 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3728 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3730 IXMLDOMDocument2_Release( doc2 );
3731 IXMLDOMDocument_Release( doc );
3733 /* DTD validation */
3734 ole_check(IXMLDOMDocument2_put_validateOnParse(dtddoc2, VARIANT_FALSE));
3735 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML), &b));
3736 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3738 ole_check(IXMLDOMDocument2_validate(dtddoc2, &err));
3739 ok(err != NULL, "expected pointer\n");
3743 ole_expect(IXMLDOMParseError_get_errorCode(err, &res), S_FALSE);
3744 ok(res == 0, "got %08x\n", res);
3745 IXMLDOMParseError_Release(err);
3748 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0D), &b));
3749 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3751 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3752 ok(err != NULL, "expected pointer\n");
3756 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3757 /* XML_ELEMENT_UNDECLARED */
3758 todo_wine ok(res == 0xC00CE00D, "got %08x\n", res);
3759 IXMLDOMParseError_Release(err);
3762 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0E), &b));
3763 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3765 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3766 ok(err != NULL, "expected pointer\n");
3770 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3771 /* XML_ELEMENT_ID_NOT_FOUND */
3772 todo_wine ok(res == 0xC00CE00E, "got %08x\n", res);
3773 IXMLDOMParseError_Release(err);
3776 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_11), &b));
3777 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3779 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3780 ok(err != NULL, "expected pointer\n");
3784 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3785 /* XML_EMPTY_NOT_ALLOWED */
3786 todo_wine ok(res == 0xC00CE011, "got %08x\n", res);
3787 IXMLDOMParseError_Release(err);
3790 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_13), &b));
3791 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3793 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3794 ok(err != NULL, "expected pointer\n");
3798 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3799 /* XML_ROOT_NAME_MISMATCH */
3800 todo_wine ok(res == 0xC00CE013, "got %08x\n", res);
3801 IXMLDOMParseError_Release(err);
3804 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_14), &b));
3805 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3807 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3808 ok(err != NULL, "expected pointer\n");
3812 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3813 /* XML_INVALID_CONTENT */
3814 todo_wine ok(res == 0xC00CE014, "got %08x\n", res);
3815 IXMLDOMParseError_Release(err);
3818 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_15), &b));
3819 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3821 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3822 ok(err != NULL, "expected pointer\n");
3826 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3827 /* XML_ATTRIBUTE_NOT_DEFINED */
3828 todo_wine ok(res == 0xC00CE015, "got %08x\n", res);
3829 IXMLDOMParseError_Release(err);
3832 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_16), &b));
3833 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3835 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3836 ok(err != NULL, "expected pointer\n");
3840 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3841 /* XML_ATTRIBUTE_FIXED */
3842 todo_wine ok(res == 0xC00CE016, "got %08x\n", res);
3843 IXMLDOMParseError_Release(err);
3846 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_17), &b));
3847 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3849 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3850 ok(err != NULL, "expected pointer\n");
3854 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3855 /* XML_ATTRIBUTE_VALUE */
3856 todo_wine ok(res == 0xC00CE017, "got %08x\n", res);
3857 IXMLDOMParseError_Release(err);
3860 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_18), &b));
3861 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3863 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3864 ok(err != NULL, "expected pointer\n");
3868 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3869 /* XML_ILLEGAL_TEXT */
3870 todo_wine ok(res == 0xC00CE018, "got %08x\n", res);
3871 IXMLDOMParseError_Release(err);
3874 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_20), &b));
3875 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3877 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3878 ok(err != NULL, "expected pointer\n");
3882 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3883 /* XML_REQUIRED_ATTRIBUTE_MISSING */
3884 todo_wine ok(res == 0xC00CE020, "got %08x\n", res);
3885 IXMLDOMParseError_Release(err);
3888 IXMLDOMDocument2_Release( dtddoc2 );
3892 #define helper_ole_check(expr) { \
3894 ok_(__FILE__, line)(r == S_OK, "=> %i: " #expr " returned %08x\n", __LINE__, r); \
3897 #define helper_expect_list_and_release(list, expstr) { \
3898 char *str = list_to_string(list); \
3899 ok_(__FILE__, line)(strcmp(str, expstr)==0, "=> %i: Invalid node list: %s, expected %s\n", __LINE__, str, expstr); \
3900 if (list) IXMLDOMNodeList_Release(list); \
3903 #define helper_expect_bstr_and_release(bstr, str) { \
3904 ok_(__FILE__, line)(lstrcmpW(bstr, _bstr_(str)) == 0, \
3905 "=> %i: got %s\n", __LINE__, wine_dbgstr_w(bstr)); \
3906 SysFreeString(bstr); \
3909 #define check_ws_ignored(doc, str) _check_ws_ignored(__LINE__, doc, str)
3910 static inline void _check_ws_ignored(int line, IXMLDOMDocument2* doc, char const* str)
3912 IXMLDOMNode *node1, *node2;
3913 IXMLDOMNodeList *list;
3916 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
3917 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
3918 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
3919 helper_ole_check(IXMLDOMNodeList_reset(list));
3920 helper_expect_list_and_release(list, "E1.E4.E1.E2.D1 E2.E4.E1.E2.D1");
3922 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
3923 helper_expect_list_and_release(list, "T1.E1.E4.E1.E2.D1 E2.E1.E4.E1.E2.D1 E3.E1.E4.E1.E2.D1 T4.E1.E4.E1.E2.D1 E5.E1.E4.E1.E2.D1");
3924 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
3927 helper_expect_bstr_and_release(bstr, str);
3931 helper_expect_bstr_and_release(bstr, "This is a description.");
3933 IXMLDOMNode_Release(node1);
3935 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
3936 helper_expect_list_and_release(list, "T1.E2.E4.E1.E2.D1 E2.E2.E4.E1.E2.D1 T3.E2.E4.E1.E2.D1 E4.E2.E4.E1.E2.D1 T5.E2.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1 T7.E2.E4.E1.E2.D1");
3937 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
3938 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
3939 IXMLDOMNode_Release(node2);
3942 #define check_ws_preserved(doc, str) _check_ws_preserved(__LINE__, doc, str)
3943 static inline void _check_ws_preserved(int line, IXMLDOMDocument2* doc, char const* str)
3945 IXMLDOMNode *node1, *node2;
3946 IXMLDOMNodeList *list;
3949 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
3950 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
3951 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
3952 helper_ole_check(IXMLDOMNodeList_reset(list));
3953 helper_expect_list_and_release(list, "E2.E8.E2.E2.D1 E4.E8.E2.E2.D1");
3955 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
3956 helper_expect_list_and_release(list, "T1.E2.E8.E2.E2.D1 E2.E2.E8.E2.E2.D1 T3.E2.E8.E2.E2.D1 E4.E2.E8.E2.E2.D1 T5.E2.E8.E2.E2.D1 E6.E2.E8.E2.E2.D1 T7.E2.E8.E2.E2.D1");
3957 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
3960 helper_expect_bstr_and_release(bstr, str);
3964 helper_expect_bstr_and_release(bstr, "\n This is a description. \n ");
3966 IXMLDOMNode_Release(node1);
3968 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
3969 helper_expect_list_and_release(list, "T1.E4.E8.E2.E2.D1 E2.E4.E8.E2.E2.D1 T3.E4.E8.E2.E2.D1 E4.E4.E8.E2.E2.D1 T5.E4.E8.E2.E2.D1 E6.E4.E8.E2.E2.D1 T7.E4.E8.E2.E2.D1");
3970 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
3971 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
3972 IXMLDOMNode_Release(node2);
3975 static void test_whitespace(void)
3978 IXMLDOMDocument2 *doc1, *doc2, *doc3, *doc4;
3980 doc1 = create_document(&IID_IXMLDOMDocument2);
3981 doc2 = create_document(&IID_IXMLDOMDocument2);
3982 if (!doc1 || !doc2) return;
3984 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_TRUE));
3985 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
3986 ok(b == VARIANT_FALSE, "expected false\n");
3987 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
3988 ok(b == VARIANT_TRUE, "expected true\n");
3990 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
3991 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3992 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
3993 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3995 /* switch to XPath */
3996 ole_check(IXMLDOMDocument2_setProperty(doc1, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3997 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3999 check_ws_ignored(doc1, NULL);
4000 check_ws_preserved(doc2, NULL);
4002 /* new instances copy the property */
4003 ole_check(IXMLDOMDocument2_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**) &doc3));
4004 ole_check(IXMLDOMDocument2_QueryInterface(doc2, &IID_IXMLDOMDocument2, (void**) &doc4));
4006 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
4007 ok(b == VARIANT_FALSE, "expected false\n");
4008 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
4009 ok(b == VARIANT_TRUE, "expected true\n");
4011 check_ws_ignored(doc3, NULL);
4012 check_ws_preserved(doc4, NULL);
4014 /* setting after loading xml affects trimming of leading/trailing ws only */
4015 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_TRUE));
4016 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_FALSE));
4018 /* the trailing "\n " isn't there, because it was ws-only node */
4019 check_ws_ignored(doc1, "\n This is a description. ");
4020 check_ws_preserved(doc2, "This is a description.");
4022 /* it takes effect on reload */
4023 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
4024 ok(b == VARIANT_TRUE, "expected true\n");
4025 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
4026 ok(b == VARIANT_FALSE, "expected false\n");
4028 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
4029 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4030 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
4031 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4033 check_ws_preserved(doc1, NULL);
4034 check_ws_ignored(doc2, NULL);
4036 /* other instances follow suit */
4037 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
4038 ok(b == VARIANT_TRUE, "expected true\n");
4039 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
4040 ok(b == VARIANT_FALSE, "expected false\n");
4042 check_ws_preserved(doc3, NULL);
4043 check_ws_ignored(doc4, NULL);
4045 IXMLDOMDocument_Release(doc1);
4046 IXMLDOMDocument_Release(doc2);
4047 IXMLDOMDocument_Release(doc3);
4048 IXMLDOMDocument_Release(doc4);
4052 static void test_XPath(void)
4056 IXMLDOMDocument2 *doc;
4057 IXMLDOMNode *rootNode;
4058 IXMLDOMNode *elem1Node;
4060 IXMLDOMNodeList *list;
4062 doc = create_document(&IID_IXMLDOMDocument2);
4065 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
4066 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4068 /* switch to XPath */
4069 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4071 /* some simple queries*/
4072 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
4073 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
4074 ole_check(IXMLDOMNodeList_reset(list));
4075 expect_list_and_release(list, "E2.D1");
4076 if (rootNode == NULL)
4079 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
4080 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
4082 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
4083 expect_list_and_release(list, "E3.E2.E2.D1");
4085 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
4086 /* using get_item for query results advances the position */
4087 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
4088 expect_node(node, "E2.E2.D1");
4089 IXMLDOMNode_Release(node);
4090 ole_check(IXMLDOMNodeList_nextNode(list, &node));
4091 expect_node(node, "E4.E2.D1");
4092 IXMLDOMNode_Release(node);
4093 ole_check(IXMLDOMNodeList_reset(list));
4094 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
4096 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
4097 expect_list_and_release(list, "E2.D1");
4099 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
4100 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
4101 ole_check(IXMLDOMNodeList_reset(list));
4102 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
4104 /* select an attribute */
4105 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
4106 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
4108 /* would evaluate to a number */
4109 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
4110 /* would evaluate to a boolean */
4111 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
4112 /* would evaluate to a string */
4113 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
4116 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
4117 expect_list_and_release(list, "");
4118 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
4119 expect_list_and_release(list, "");
4120 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
4121 expect_list_and_release(list, "");
4122 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//elem[0]"), &list));
4123 expect_list_and_release(list, "");
4125 /* foo undeclared in document node */
4126 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4127 /* undeclared in <root> node */
4128 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
4129 /* undeclared in <elem> node */
4130 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
4131 /* but this trick can be used */
4132 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
4133 expect_list_and_release(list, "E3.E4.E2.D1");
4135 /* it has to be declared in SelectionNamespaces */
4136 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4137 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
4139 /* now the namespace can be used */
4140 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
4141 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4142 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
4143 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4144 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
4145 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4146 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
4147 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
4149 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
4150 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4151 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
4153 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4156 ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
4157 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
4158 if (V_VT(&var) == VT_BSTR)
4159 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
4161 /* extra attributes - same thing*/
4162 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4163 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
4164 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4166 IXMLDOMNode_Release(rootNode);
4167 IXMLDOMNode_Release(elem1Node);
4168 IXMLDOMDocument_Release(doc);
4172 static void test_cloneNode(void )
4174 IXMLDOMDocument *doc;
4176 IXMLDOMNodeList *pList;
4177 IXMLDOMNamedNodeMap *mapAttr;
4178 LONG nLength = 0, nLength1 = 0;
4179 LONG nAttrCnt = 0, nAttrCnt1 = 0;
4181 IXMLDOMNode *node_clone;
4182 IXMLDOMNode *node_first;
4185 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
4187 doc = create_document(&IID_IXMLDOMDocument);
4190 str = SysAllocString( szComplete4 );
4191 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
4192 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4198 str = SysAllocString( szSearch);
4199 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
4200 ok( r == S_OK, "ret %08x\n", r );
4201 ok( node != NULL, "node %p\n", node );
4206 IXMLDOMDocument_Release(doc);
4210 /* Check invalid parameter */
4211 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
4212 ok( r == E_INVALIDARG, "ret %08x\n", r );
4215 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
4216 ok( r == S_OK, "ret %08x\n", r );
4217 ok( node_clone != NULL, "node %p\n", node );
4221 IXMLDOMDocument_Release(doc);
4222 IXMLDOMNode_Release(node);
4226 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
4227 ok( r == S_OK, "ret %08x\n", r );
4230 IXMLDOMDocument *doc2;
4232 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
4233 ok( r == S_OK, "ret %08x\n", r );
4235 IXMLDOMDocument_Release(doc2);
4237 IXMLDOMNode_Release(node_first);
4240 r = IXMLDOMNode_get_childNodes(node, &pList);
4241 ok( r == S_OK, "ret %08x\n", r );
4244 IXMLDOMNodeList_get_length(pList, &nLength);
4245 IXMLDOMNodeList_Release(pList);
4248 r = IXMLDOMNode_get_attributes(node, &mapAttr);
4249 ok( r == S_OK, "ret %08x\n", r );
4252 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
4253 IXMLDOMNamedNodeMap_Release(mapAttr);
4256 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
4257 ok( r == S_OK, "ret %08x\n", r );
4260 IXMLDOMNodeList_get_length(pList, &nLength1);
4261 IXMLDOMNodeList_Release(pList);
4264 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
4265 ok( r == S_OK, "ret %08x\n", r );
4268 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
4269 IXMLDOMNamedNodeMap_Release(mapAttr);
4272 ok(nLength == nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
4273 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
4274 IXMLDOMNode_Release(node_clone);
4277 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
4278 ok( r == S_OK, "ret %08x\n", r );
4279 ok( node_clone != NULL, "node %p\n", node );
4283 IXMLDOMDocument_Release(doc);
4284 IXMLDOMNode_Release(node);
4288 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
4289 ok( r == S_FALSE, "ret %08x\n", r );
4292 IXMLDOMDocument *doc2;
4294 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
4295 ok( r == S_OK, "ret %08x\n", r );
4297 IXMLDOMDocument_Release(doc2);
4299 IXMLDOMNode_Release(node_first);
4302 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
4303 ok( r == S_OK, "ret %08x\n", r );
4306 IXMLDOMNodeList_get_length(pList, &nLength1);
4307 ok( nLength1 == 0, "Length should be 0 (%d)\n", nLength1);
4308 IXMLDOMNodeList_Release(pList);
4311 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
4312 ok( r == S_OK, "ret %08x\n", r );
4315 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
4316 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%d)\n", nAttrCnt1);
4317 IXMLDOMNamedNodeMap_Release(mapAttr);
4320 ok(nLength != nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
4321 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
4322 IXMLDOMNode_Release(node_clone);
4325 IXMLDOMNode_Release(node);
4326 IXMLDOMDocument_Release(doc);
4329 static void test_xmlTypes(void)
4331 IXMLDOMDocument *doc;
4332 IXMLDOMElement *pRoot;
4334 IXMLDOMComment *pComment;
4335 IXMLDOMElement *pElement;
4336 IXMLDOMAttribute *pAttribute;
4337 IXMLDOMNamedNodeMap *pAttribs;
4338 IXMLDOMCDATASection *pCDataSec;
4339 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
4340 IXMLDOMDocumentFragment *pDocFrag = NULL;
4341 IXMLDOMEntityReference *pEntityRef = NULL;
4343 IXMLDOMNode *pNextChild;
4347 doc = create_document(&IID_IXMLDOMDocument);
4350 pNextChild = (void*)0xdeadbeef;
4351 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
4352 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4354 pNextChild = (void*)0xdeadbeef;
4355 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
4356 ok(hr == S_FALSE, "ret %08x\n", hr );
4357 ok(pNextChild == NULL, "pDocChild not NULL\n");
4359 /* test previous Sibling */
4360 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
4361 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4363 pNextChild = (void*)0xdeadbeef;
4364 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
4365 ok(hr == S_FALSE, "ret %08x\n", hr );
4366 ok(pNextChild == NULL, "pNextChild not NULL\n");
4368 /* test get_attributes */
4369 hr = IXMLDOMDocument_get_attributes( doc, NULL );
4370 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
4372 pAttribs = (void*)0xdeadbeef;
4373 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
4374 ok(hr == S_FALSE, "ret %08x\n", hr );
4375 ok( pAttribs == NULL, "pAttribs not NULL\n");
4377 /* test get_dataType */
4378 V_VT(&v) = VT_EMPTY;
4379 hr = IXMLDOMDocument_get_dataType(doc, &v);
4380 ok(hr == S_FALSE, "ret %08x\n", hr );
4381 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4384 /* test nodeTypeString */
4386 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
4387 ok(hr == S_OK, "ret %08x\n", hr );
4388 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
4391 /* test implementation */
4392 hr = IXMLDOMDocument_get_implementation(doc, NULL);
4393 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4395 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
4396 ok(hr == S_OK, "ret %08x\n", hr );
4399 VARIANT_BOOL hasFeature = VARIANT_TRUE;
4400 BSTR sEmpty = SysAllocStringLen(NULL, 0);
4402 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
4403 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4405 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
4406 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4408 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
4409 ok(hr == S_OK, "ret %08x\n", hr );
4410 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4412 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
4413 ok(hr == S_OK, "ret %08x\n", hr );
4414 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
4416 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
4417 ok(hr == S_OK, "ret %08x\n", hr );
4418 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
4420 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
4421 ok(hr == S_OK, "ret %08x\n", hr );
4422 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4424 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
4425 ok(hr == S_OK, "ret %08x\n", hr );
4426 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4428 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
4429 ok(hr == S_OK, "ret %08x\n", hr );
4430 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4432 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
4433 ok(hr == S_OK, "ret %08x\n", hr );
4434 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4436 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
4437 ok(hr == S_OK, "ret %08x\n", hr );
4438 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4440 SysFreeString(sEmpty);
4441 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
4444 pRoot = (IXMLDOMElement*)0x1;
4445 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
4446 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4447 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
4449 pRoot = (IXMLDOMElement*)0x1;
4450 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
4451 ok(hr == E_FAIL, "ret %08x\n", hr );
4452 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
4454 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
4455 ok(hr == S_OK, "ret %08x\n", hr );
4458 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
4459 ok(hr == S_OK, "ret %08x\n", hr );
4463 str = SysAllocString(szComment);
4464 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
4466 ok(hr == S_OK, "ret %08x\n", hr );
4469 /* test get_attributes */
4470 hr = IXMLDOMComment_get_attributes( pComment, NULL );
4471 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
4473 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4474 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
4475 ok(hr == S_FALSE, "ret %08x\n", hr );
4476 ok( pAttribs == NULL, "pAttribs not NULL\n");
4478 /* test nodeTypeString */
4479 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
4480 ok(hr == S_OK, "ret %08x\n", hr );
4481 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
4484 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
4485 ok(hr == S_OK, "ret %08x\n", hr );
4487 hr = IXMLDOMComment_get_nodeName(pComment, &str);
4488 ok(hr == S_OK, "ret %08x\n", hr );
4489 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
4492 hr = IXMLDOMComment_get_xml(pComment, &str);
4493 ok(hr == S_OK, "ret %08x\n", hr );
4494 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
4497 hr = IXMLDOMComment_get_dataType(pComment, &v);
4498 ok(hr == S_FALSE, "ret %08x\n", hr );
4499 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4502 /* put data Tests */
4503 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
4504 ok(hr == S_OK, "ret %08x\n", hr );
4506 /* get data Tests */
4507 hr = IXMLDOMComment_get_data(pComment, &str);
4508 ok(hr == S_OK, "ret %08x\n", hr );
4509 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
4512 /* get data Tests */
4513 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
4514 ok(hr == S_OK, "ret %08x\n", hr );
4515 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
4516 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
4519 /* Confirm XML text is good */
4520 hr = IXMLDOMComment_get_xml(pComment, &str);
4521 ok(hr == S_OK, "ret %08x\n", hr );
4522 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
4525 /* Confirm we get the put_data Text back */
4526 hr = IXMLDOMComment_get_text(pComment, &str);
4527 ok(hr == S_OK, "ret %08x\n", hr );
4528 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
4531 /* test length property */
4532 hr = IXMLDOMComment_get_length(pComment, &len);
4533 ok(hr == S_OK, "ret %08x\n", hr );
4534 ok(len == 21, "expected 21 got %d\n", len);
4536 /* test substringData */
4537 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
4538 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4540 /* test substringData - Invalid offset */
4541 str = (BSTR)&szElement;
4542 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
4543 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4544 ok( str == NULL, "incorrect string\n");
4546 /* test substringData - Invalid offset */
4547 str = (BSTR)&szElement;
4548 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
4549 ok(hr == S_FALSE, "ret %08x\n", hr );
4550 ok( str == NULL, "incorrect string\n");
4552 /* test substringData - Invalid size */
4553 str = (BSTR)&szElement;
4554 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
4555 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4556 ok( str == NULL, "incorrect string\n");
4558 /* test substringData - Invalid size */
4559 str = (BSTR)&szElement;
4560 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
4561 ok(hr == S_FALSE, "ret %08x\n", hr );
4562 ok( str == NULL, "incorrect string\n");
4564 /* test substringData - Start of string */
4565 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
4566 ok(hr == S_OK, "ret %08x\n", hr );
4567 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
4570 /* test substringData - Middle of string */
4571 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
4572 ok(hr == S_OK, "ret %08x\n", hr );
4573 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
4576 /* test substringData - End of string */
4577 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
4578 ok(hr == S_OK, "ret %08x\n", hr );
4579 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
4582 /* test appendData */
4583 hr = IXMLDOMComment_appendData(pComment, NULL);
4584 ok(hr == S_OK, "ret %08x\n", hr );
4586 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
4587 ok(hr == S_OK, "ret %08x\n", hr );
4589 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
4590 ok(hr == S_OK, "ret %08x\n", hr );
4592 hr = IXMLDOMComment_get_text(pComment, &str);
4593 ok(hr == S_OK, "ret %08x\n", hr );
4594 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4597 /* test insertData */
4598 str = SysAllocStringLen(NULL, 0);
4599 hr = IXMLDOMComment_insertData(pComment, -1, str);
4600 ok(hr == S_OK, "ret %08x\n", hr );
4602 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
4603 ok(hr == S_OK, "ret %08x\n", hr );
4605 hr = IXMLDOMComment_insertData(pComment, 1000, str);
4606 ok(hr == S_OK, "ret %08x\n", hr );
4608 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
4609 ok(hr == S_OK, "ret %08x\n", hr );
4611 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
4612 ok(hr == S_OK, "ret %08x\n", hr );
4614 hr = IXMLDOMComment_insertData(pComment, 0, str);
4615 ok(hr == S_OK, "ret %08x\n", hr );
4618 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
4619 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4621 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
4622 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4624 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
4625 ok(hr == S_OK, "ret %08x\n", hr );
4627 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
4628 ok(hr == S_OK, "ret %08x\n", hr );
4630 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
4631 ok(hr == S_OK, "ret %08x\n", hr );
4633 hr = IXMLDOMComment_get_text(pComment, &str);
4634 ok(hr == S_OK, "ret %08x\n", hr );
4635 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4639 /* invalid arguments */
4640 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
4641 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4643 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
4644 ok(hr == S_OK, "ret %08x\n", hr );
4646 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
4647 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4649 hr = IXMLDOMComment_get_length(pComment, &len);
4650 ok(hr == S_OK, "ret %08x\n", hr );
4651 ok(len == 43, "expected 43 got %d\n", len);
4653 hr = IXMLDOMComment_deleteData(pComment, len, 1);
4654 ok(hr == S_OK, "ret %08x\n", hr );
4656 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
4657 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4659 /* delete from start */
4660 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
4661 ok(hr == S_OK, "ret %08x\n", hr );
4663 hr = IXMLDOMComment_get_length(pComment, &len);
4664 ok(hr == S_OK, "ret %08x\n", hr );
4665 ok(len == 38, "expected 38 got %d\n", len);
4667 hr = IXMLDOMComment_get_text(pComment, &str);
4668 ok(hr == S_OK, "ret %08x\n", hr );
4669 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4672 /* delete from end */
4673 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
4674 ok(hr == S_OK, "ret %08x\n", hr );
4676 hr = IXMLDOMComment_get_length(pComment, &len);
4677 ok(hr == S_OK, "ret %08x\n", hr );
4678 ok(len == 35, "expected 35 got %d\n", len);
4680 hr = IXMLDOMComment_get_text(pComment, &str);
4681 ok(hr == S_OK, "ret %08x\n", hr );
4682 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4685 /* delete from inside */
4686 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
4687 ok(hr == S_OK, "ret %08x\n", hr );
4689 hr = IXMLDOMComment_get_length(pComment, &len);
4690 ok(hr == S_OK, "ret %08x\n", hr );
4691 ok(len == 2, "expected 2 got %d\n", len);
4693 hr = IXMLDOMComment_get_text(pComment, &str);
4694 ok(hr == S_OK, "ret %08x\n", hr );
4695 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4698 /* delete whole data ... */
4699 hr = IXMLDOMComment_get_length(pComment, &len);
4700 ok(hr == S_OK, "ret %08x\n", hr );
4702 hr = IXMLDOMComment_deleteData(pComment, 0, len);
4703 ok(hr == S_OK, "ret %08x\n", hr );
4704 /* ... and try again with empty string */
4705 hr = IXMLDOMComment_deleteData(pComment, 0, len);
4706 ok(hr == S_OK, "ret %08x\n", hr );
4708 /* ::replaceData() */
4710 V_BSTR(&v) = SysAllocString(szstr1);
4711 hr = IXMLDOMComment_put_nodeValue(pComment, v);
4712 ok(hr == S_OK, "ret %08x\n", hr );
4715 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
4716 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4717 hr = IXMLDOMComment_get_text(pComment, &str);
4718 ok(hr == S_OK, "ret %08x\n", hr );
4719 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4722 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
4723 ok(hr == S_OK, "ret %08x\n", hr );
4724 hr = IXMLDOMComment_get_text(pComment, &str);
4725 ok(hr == S_OK, "ret %08x\n", hr );
4726 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4729 /* NULL pointer means delete */
4730 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
4731 ok(hr == S_OK, "ret %08x\n", hr );
4732 hr = IXMLDOMComment_get_text(pComment, &str);
4733 ok(hr == S_OK, "ret %08x\n", hr );
4734 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4737 /* empty string means delete */
4738 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
4739 ok(hr == S_OK, "ret %08x\n", hr );
4740 hr = IXMLDOMComment_get_text(pComment, &str);
4741 ok(hr == S_OK, "ret %08x\n", hr );
4742 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4745 /* zero count means insert */
4746 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
4747 ok(hr == S_OK, "ret %08x\n", hr );
4748 hr = IXMLDOMComment_get_text(pComment, &str);
4749 ok(hr == S_OK, "ret %08x\n", hr );
4750 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4753 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
4754 ok(hr == S_OK, "ret %08x\n", hr );
4756 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
4757 ok(hr == S_OK, "ret %08x\n", hr );
4758 hr = IXMLDOMComment_get_text(pComment, &str);
4759 ok(hr == S_OK, "ret %08x\n", hr );
4760 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4763 /* nonempty string, count greater than its length */
4764 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
4765 ok(hr == S_OK, "ret %08x\n", hr );
4766 hr = IXMLDOMComment_get_text(pComment, &str);
4767 ok(hr == S_OK, "ret %08x\n", hr );
4768 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4771 /* nonempty string, count less than its length */
4772 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
4773 ok(hr == S_OK, "ret %08x\n", hr );
4774 hr = IXMLDOMComment_get_text(pComment, &str);
4775 ok(hr == S_OK, "ret %08x\n", hr );
4776 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4779 IXMLDOMComment_Release(pComment);
4783 str = SysAllocString(szElement);
4784 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
4786 ok(hr == S_OK, "ret %08x\n", hr );
4789 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4790 ok(hr == S_OK, "ret %08x\n", hr );
4792 /* test nodeTypeString */
4793 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
4794 ok(hr == S_OK, "ret %08x\n", hr );
4795 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
4798 hr = IXMLDOMElement_get_nodeName(pElement, &str);
4799 ok(hr == S_OK, "ret %08x\n", hr );
4800 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
4803 hr = IXMLDOMElement_get_xml(pElement, &str);
4804 ok(hr == S_OK, "ret %08x\n", hr );
4805 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
4808 hr = IXMLDOMElement_get_dataType(pElement, &v);
4809 ok(hr == S_FALSE, "ret %08x\n", hr );
4810 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4814 pAttribute = (IXMLDOMAttribute*)0x1;
4815 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
4816 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4817 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
4819 pAttribute = (IXMLDOMAttribute*)0x1;
4820 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
4821 ok(hr == E_FAIL, "ret %08x\n", hr );
4822 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
4824 str = SysAllocString(szAttribute);
4825 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
4827 ok(hr == S_OK, "ret %08x\n", hr );
4830 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
4832 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
4833 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4835 pNextChild = (IXMLDOMNode *)0x1;
4836 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
4837 ok(hr == S_FALSE, "ret %08x\n", hr );
4838 ok(pNextChild == NULL, "pNextChild not NULL\n");
4840 /* test Previous Sibling*/
4841 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
4842 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4844 pNextChild = (IXMLDOMNode *)0x1;
4845 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
4846 ok(hr == S_FALSE, "ret %08x\n", hr );
4847 ok(pNextChild == NULL, "pNextChild not NULL\n");
4849 /* test get_attributes */
4850 hr = IXMLDOMAttribute_get_attributes( pAttribute, NULL );
4851 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
4853 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4854 hr = IXMLDOMAttribute_get_attributes( pAttribute, &pAttribs);
4855 ok(hr == S_FALSE, "ret %08x\n", hr );
4856 ok( pAttribs == NULL, "pAttribs not NULL\n");
4858 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
4859 ok(hr == E_FAIL, "ret %08x\n", hr );
4860 ok(pNewChild == NULL, "pNewChild not NULL\n");
4862 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
4863 ok(hr == S_OK, "ret %08x\n", hr );
4866 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
4867 ok(hr == S_OK, "ret %08x\n", hr );
4869 IXMLDOMNamedNodeMap_Release(pAttribs);
4872 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
4873 ok(hr == S_OK, "ret %08x\n", hr );
4874 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
4877 /* test nodeTypeString */
4878 hr = IXMLDOMAttribute_get_nodeTypeString(pAttribute, &str);
4879 ok(hr == S_OK, "ret %08x\n", hr );
4880 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
4884 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
4885 ok(hr == S_OK, "ret %08x\n", hr );
4886 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
4889 /* test name property */
4890 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
4891 ok(hr == S_OK, "ret %08x\n", hr );
4892 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
4895 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
4896 ok(hr == S_OK, "ret %08x\n", hr );
4897 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
4900 hr = IXMLDOMAttribute_get_dataType(pAttribute, &v);
4901 ok(hr == S_FALSE, "ret %08x\n", hr );
4902 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4905 IXMLDOMAttribute_Release(pAttribute);
4907 /* Check Element again with the Add Attribute*/
4908 hr = IXMLDOMElement_get_xml(pElement, &str);
4909 ok(hr == S_OK, "ret %08x\n", hr );
4910 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
4914 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
4915 ok(hr == S_OK, "ret %08x\n", hr );
4917 hr = IXMLDOMElement_get_xml(pElement, &str);
4918 ok(hr == S_OK, "ret %08x\n", hr );
4919 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
4922 /* Test for reversible escaping */
4923 str = SysAllocString( szStrangeChars );
4924 hr = IXMLDOMElement_put_text(pElement, str);
4925 ok(hr == S_OK, "ret %08x\n", hr );
4926 SysFreeString( str );
4928 hr = IXMLDOMElement_get_xml(pElement, &str);
4929 ok(hr == S_OK, "ret %08x\n", hr );
4930 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
4933 hr = IXMLDOMElement_get_text(pElement, &str);
4934 ok(hr == S_OK, "ret %08x\n", hr );
4935 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
4938 IXMLDOMElement_Release(pElement);
4942 str = SysAllocString(szCData);
4943 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
4944 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4946 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
4948 ok(hr == S_OK, "ret %08x\n", hr );
4951 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
4956 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
4957 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
4959 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
4960 ok(hr == S_OK, "ret %08x\n", hr );
4962 /* get Attribute Tests */
4963 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
4964 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4966 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4967 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
4968 ok(hr == S_FALSE, "ret %08x\n", hr );
4969 ok(pAttribs == NULL, "pAttribs != NULL\n");
4971 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
4972 ok(hr == S_OK, "ret %08x\n", hr );
4973 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
4976 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
4977 ok(hr == S_OK, "ret %08x\n", hr );
4978 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
4981 /* test lastChild */
4982 pNextChild = (IXMLDOMNode*)0x1;
4983 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
4984 ok(hr == S_FALSE, "ret %08x\n", hr );
4985 ok(pNextChild == NULL, "pNextChild not NULL\n");
4987 /* test get_dataType */
4988 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
4989 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4991 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
4992 ok(hr == S_FALSE, "ret %08x\n", hr );
4993 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4996 /* test nodeTypeString */
4997 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
4998 ok(hr == S_OK, "ret %08x\n", hr );
4999 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
5002 /* put data Tests */
5003 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
5004 ok(hr == S_OK, "ret %08x\n", hr );
5006 /* Confirm XML text is good */
5007 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
5008 ok(hr == S_OK, "ret %08x\n", hr );
5009 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
5012 /* Confirm we get the put_data Text back */
5013 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5014 ok(hr == S_OK, "ret %08x\n", hr );
5015 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5018 /* test length property */
5019 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5020 ok(hr == S_OK, "ret %08x\n", hr );
5021 ok(len == 21, "expected 21 got %d\n", len);
5023 /* test get nodeValue */
5024 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
5025 ok(hr == S_OK, "ret %08x\n", hr );
5026 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
5027 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5031 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
5032 ok(hr == S_OK, "ret %08x\n", hr );
5033 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5036 /* test substringData */
5037 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
5038 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5040 /* test substringData - Invalid offset */
5041 str = (BSTR)&szElement;
5042 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
5043 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5044 ok( str == NULL, "incorrect string\n");
5046 /* test substringData - Invalid offset */
5047 str = (BSTR)&szElement;
5048 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
5049 ok(hr == S_FALSE, "ret %08x\n", hr );
5050 ok( str == NULL, "incorrect string\n");
5052 /* test substringData - Invalid size */
5053 str = (BSTR)&szElement;
5054 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
5055 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5056 ok( str == NULL, "incorrect string\n");
5058 /* test substringData - Invalid size */
5059 str = (BSTR)&szElement;
5060 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
5061 ok(hr == S_FALSE, "ret %08x\n", hr );
5062 ok( str == NULL, "incorrect string\n");
5064 /* test substringData - Start of string */
5065 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
5066 ok(hr == S_OK, "ret %08x\n", hr );
5067 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
5070 /* test substringData - Middle of string */
5071 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
5072 ok(hr == S_OK, "ret %08x\n", hr );
5073 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
5076 /* test substringData - End of string */
5077 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
5078 ok(hr == S_OK, "ret %08x\n", hr );
5079 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
5082 /* test appendData */
5083 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
5084 ok(hr == S_OK, "ret %08x\n", hr );
5086 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
5087 ok(hr == S_OK, "ret %08x\n", hr );
5089 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
5090 ok(hr == S_OK, "ret %08x\n", hr );
5092 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5093 ok(hr == S_OK, "ret %08x\n", hr );
5094 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5097 /* test insertData */
5098 str = SysAllocStringLen(NULL, 0);
5099 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
5100 ok(hr == S_OK, "ret %08x\n", hr );
5102 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
5103 ok(hr == S_OK, "ret %08x\n", hr );
5105 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
5106 ok(hr == S_OK, "ret %08x\n", hr );
5108 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
5109 ok(hr == S_OK, "ret %08x\n", hr );
5111 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
5112 ok(hr == S_OK, "ret %08x\n", hr );
5114 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
5115 ok(hr == S_OK, "ret %08x\n", hr );
5118 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
5119 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5121 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
5122 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5124 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
5125 ok(hr == S_OK, "ret %08x\n", hr );
5127 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
5128 ok(hr == S_OK, "ret %08x\n", hr );
5130 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
5131 ok(hr == S_OK, "ret %08x\n", hr );
5133 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5134 ok(hr == S_OK, "ret %08x\n", hr );
5135 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5139 /* invalid arguments */
5140 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
5141 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5143 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
5144 ok(hr == S_OK, "ret %08x\n", hr );
5146 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
5147 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5149 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5150 ok(hr == S_OK, "ret %08x\n", hr );
5151 ok(len == 43, "expected 43 got %d\n", len);
5153 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
5154 ok(hr == S_OK, "ret %08x\n", hr );
5156 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
5157 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5159 /* delete from start */
5160 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
5161 ok(hr == S_OK, "ret %08x\n", hr );
5163 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5164 ok(hr == S_OK, "ret %08x\n", hr );
5165 ok(len == 38, "expected 38 got %d\n", len);
5167 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5168 ok(hr == S_OK, "ret %08x\n", hr );
5169 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5172 /* delete from end */
5173 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
5174 ok(hr == S_OK, "ret %08x\n", hr );
5176 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5177 ok(hr == S_OK, "ret %08x\n", hr );
5178 ok(len == 35, "expected 35 got %d\n", len);
5180 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5181 ok(hr == S_OK, "ret %08x\n", hr );
5182 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5185 /* delete from inside */
5186 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
5187 ok(hr == S_OK, "ret %08x\n", hr );
5189 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5190 ok(hr == S_OK, "ret %08x\n", hr );
5191 ok(len == 2, "expected 2 got %d\n", len);
5193 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5194 ok(hr == S_OK, "ret %08x\n", hr );
5195 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5198 /* delete whole data ... */
5199 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5200 ok(hr == S_OK, "ret %08x\n", hr );
5202 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
5203 ok(hr == S_OK, "ret %08x\n", hr );
5205 /* ... and try again with empty string */
5206 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
5207 ok(hr == S_OK, "ret %08x\n", hr );
5209 /* ::replaceData() */
5211 V_BSTR(&v) = SysAllocString(szstr1);
5212 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
5213 ok(hr == S_OK, "ret %08x\n", hr );
5216 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
5217 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5218 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5219 ok(hr == S_OK, "ret %08x\n", hr );
5220 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5223 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
5224 ok(hr == S_OK, "ret %08x\n", hr );
5225 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5226 ok(hr == S_OK, "ret %08x\n", hr );
5227 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5230 /* NULL pointer means delete */
5231 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
5232 ok(hr == S_OK, "ret %08x\n", hr );
5233 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5234 ok(hr == S_OK, "ret %08x\n", hr );
5235 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5238 /* empty string means delete */
5239 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
5240 ok(hr == S_OK, "ret %08x\n", hr );
5241 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5242 ok(hr == S_OK, "ret %08x\n", hr );
5243 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5246 /* zero count means insert */
5247 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
5248 ok(hr == S_OK, "ret %08x\n", hr );
5249 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5250 ok(hr == S_OK, "ret %08x\n", hr );
5251 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5254 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
5255 ok(hr == S_OK, "ret %08x\n", hr );
5257 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
5258 ok(hr == S_OK, "ret %08x\n", hr );
5259 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5260 ok(hr == S_OK, "ret %08x\n", hr );
5261 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5264 /* nonempty string, count greater than its length */
5265 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
5266 ok(hr == S_OK, "ret %08x\n", hr );
5267 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5268 ok(hr == S_OK, "ret %08x\n", hr );
5269 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5272 /* nonempty string, count less than its length */
5273 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
5274 ok(hr == S_OK, "ret %08x\n", hr );
5275 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5276 ok(hr == S_OK, "ret %08x\n", hr );
5277 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5280 IXMLDOMCDATASection_Release(pCDataSec);
5283 /* Document Fragments */
5284 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
5285 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5287 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
5288 ok(hr == S_OK, "ret %08x\n", hr );
5293 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
5294 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5296 node = (IXMLDOMNode *)0x1;
5297 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
5298 ok(hr == S_FALSE, "ret %08x\n", hr );
5299 ok(node == NULL, "expected NULL, got %p\n", node);
5301 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
5302 ok(hr == S_OK, "ret %08x\n", hr );
5304 /* get Attribute Tests */
5305 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
5306 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5308 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
5309 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
5310 ok(hr == S_FALSE, "ret %08x\n", hr );
5311 ok(pAttribs == NULL, "pAttribs != NULL\n");
5313 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
5314 ok(hr == S_OK, "ret %08x\n", hr );
5315 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
5318 /* test next Sibling*/
5319 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
5320 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5322 node = (IXMLDOMNode *)0x1;
5323 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
5324 ok(hr == S_FALSE, "ret %08x\n", hr );
5325 ok(node == NULL, "next sibling not NULL\n");
5327 /* test Previous Sibling*/
5328 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
5329 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5331 node = (IXMLDOMNode *)0x1;
5332 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
5333 ok(hr == S_FALSE, "ret %08x\n", hr );
5334 ok(node == NULL, "previous sibling not NULL\n");
5336 /* test get_dataType */
5337 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
5338 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5340 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
5341 ok(hr == S_FALSE, "ret %08x\n", hr );
5342 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5345 /* test nodeTypeString */
5346 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
5347 ok(hr == S_OK, "ret %08x\n", hr );
5348 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
5351 IXMLDOMDocumentFragment_Release(pDocFrag);
5354 /* Entity References */
5355 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
5356 ok(hr == E_FAIL, "ret %08x\n", hr );
5357 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
5358 ok(hr == E_FAIL, "ret %08x\n", hr );
5360 str = SysAllocString(szEntityRef);
5361 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
5362 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5364 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
5366 ok(hr == S_OK, "ret %08x\n", hr );
5369 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
5370 ok(hr == S_OK, "ret %08x\n", hr );
5372 /* get Attribute Tests */
5373 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
5374 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5376 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
5377 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
5378 ok(hr == S_FALSE, "ret %08x\n", hr );
5379 ok(pAttribs == NULL, "pAttribs != NULL\n");
5382 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
5383 ok(hr == S_FALSE, "ret %08x\n", hr );
5384 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5387 /* test nodeTypeString */
5388 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
5389 ok(hr == S_OK, "ret %08x\n", hr );
5390 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
5394 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
5395 ok(hr == S_OK, "ret %08x\n", hr );
5396 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
5399 IXMLDOMEntityReference_Release(pEntityRef);
5402 IXMLDOMElement_Release( pRoot );
5406 IXMLDOMDocument_Release(doc);
5411 static void test_nodeTypeTests( void )
5413 IXMLDOMDocument *doc = NULL;
5414 IXMLDOMElement *pRoot;
5415 IXMLDOMElement *pElement;
5418 doc = create_document(&IID_IXMLDOMDocument);
5421 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
5422 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5424 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5425 ok(hr == S_OK, "ret %08x\n", hr );
5428 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5429 ok(hr == S_OK, "ret %08x\n", hr );
5432 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
5433 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5436 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
5437 ok(hr == E_FAIL, "ret %08x\n", hr );
5440 * The name passed into put_dataType is case-insensitive. So many of the names
5441 * have been changed to reflect this.
5444 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
5445 ok(hr == S_OK, "ret %08x\n", hr );
5448 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5450 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
5451 ok(hr == S_OK, "ret %08x\n", hr );
5453 IXMLDOMElement_Release(pElement);
5457 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
5458 ok(hr == S_OK, "ret %08x\n", hr );
5461 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5463 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
5464 ok(hr == S_OK, "ret %08x\n", hr );
5466 IXMLDOMElement_Release(pElement);
5470 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
5471 ok(hr == S_OK, "ret %08x\n", hr );
5474 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5476 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
5477 ok(hr == S_OK, "ret %08x\n", hr );
5479 IXMLDOMElement_Release(pElement);
5483 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
5484 ok(hr == S_OK, "ret %08x\n", hr );
5487 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5489 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
5490 ok(hr == S_OK, "ret %08x\n", hr );
5492 IXMLDOMElement_Release(pElement);
5496 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
5497 ok(hr == S_OK, "ret %08x\n", hr );
5500 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5502 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
5503 ok(hr == S_OK, "ret %08x\n", hr );
5505 IXMLDOMElement_Release(pElement);
5509 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
5510 ok(hr == S_OK, "ret %08x\n", hr );
5513 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5515 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
5516 ok(hr == S_OK, "ret %08x\n", hr );
5518 IXMLDOMElement_Release(pElement);
5522 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
5523 ok(hr == S_OK, "ret %08x\n", hr );
5526 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5528 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
5529 ok(hr == S_OK, "ret %08x\n", hr );
5531 IXMLDOMElement_Release(pElement);
5535 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
5536 ok(hr == S_OK, "ret %08x\n", hr );
5539 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5541 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
5542 ok(hr == S_OK, "ret %08x\n", hr );
5544 IXMLDOMElement_Release(pElement);
5548 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
5549 ok(hr == S_OK, "ret %08x\n", hr );
5552 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5554 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
5555 ok(hr == S_OK, "ret %08x\n", hr );
5557 IXMLDOMElement_Release(pElement);
5561 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
5562 ok(hr == S_OK, "ret %08x\n", hr );
5565 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5567 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
5568 ok(hr == S_OK, "ret %08x\n", hr );
5570 IXMLDOMElement_Release(pElement);
5574 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
5575 ok(hr == S_OK, "ret %08x\n", hr );
5578 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5580 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
5581 ok(hr == S_OK, "ret %08x\n", hr );
5583 IXMLDOMElement_Release(pElement);
5587 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
5588 ok(hr == S_OK, "ret %08x\n", hr );
5591 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5593 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
5594 ok(hr == S_OK, "ret %08x\n", hr );
5596 IXMLDOMElement_Release(pElement);
5600 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
5601 ok(hr == S_OK, "ret %08x\n", hr );
5604 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5606 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
5607 ok(hr == S_OK, "ret %08x\n", hr );
5609 IXMLDOMElement_Release(pElement);
5613 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
5614 ok(hr == S_OK, "ret %08x\n", hr );
5617 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5619 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
5620 ok(hr == S_OK, "ret %08x\n", hr );
5622 IXMLDOMElement_Release(pElement);
5626 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
5627 ok(hr == S_OK, "ret %08x\n", hr );
5630 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5632 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
5633 ok(hr == S_OK, "ret %08x\n", hr );
5635 IXMLDOMElement_Release(pElement);
5639 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
5640 ok(hr == S_OK, "ret %08x\n", hr );
5643 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5645 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
5646 ok(hr == S_OK, "ret %08x\n", hr );
5648 IXMLDOMElement_Release(pElement);
5652 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
5653 ok(hr == S_OK, "ret %08x\n", hr );
5656 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5658 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
5659 ok(hr == S_OK, "ret %08x\n", hr );
5661 IXMLDOMElement_Release(pElement);
5665 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
5666 ok(hr == S_OK, "ret %08x\n", hr );
5669 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5671 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
5672 ok(hr == S_OK, "ret %08x\n", hr );
5674 IXMLDOMElement_Release(pElement);
5678 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
5679 ok(hr == S_OK, "ret %08x\n", hr );
5682 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5684 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
5685 ok(hr == S_OK, "ret %08x\n", hr );
5687 IXMLDOMElement_Release(pElement);
5691 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
5692 ok(hr == S_OK, "ret %08x\n", hr );
5695 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5697 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
5698 ok(hr == S_OK, "ret %08x\n", hr );
5700 IXMLDOMElement_Release(pElement);
5704 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
5705 ok(hr == S_OK, "ret %08x\n", hr );
5708 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5710 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
5711 ok(hr == S_OK, "ret %08x\n", hr );
5713 IXMLDOMElement_Release(pElement);
5717 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
5718 ok(hr == S_OK, "ret %08x\n", hr );
5721 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5723 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
5724 ok(hr == S_OK, "ret %08x\n", hr );
5726 IXMLDOMElement_Release(pElement);
5729 /* Check changing types */
5730 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
5731 ok(hr == S_OK, "ret %08x\n", hr );
5734 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5736 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
5737 ok(hr == S_OK, "ret %08x\n", hr );
5739 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
5740 ok(hr == S_OK, "ret %08x\n", hr );
5742 IXMLDOMElement_Release(pElement);
5745 IXMLDOMElement_Release(pRoot);
5749 IXMLDOMDocument_Release(doc);
5754 static void test_DocumentSaveToDocument(void)
5756 IXMLDOMDocument *doc, *doc2;
5757 IXMLDOMElement *pRoot;
5760 doc = create_document(&IID_IXMLDOMDocument);
5763 doc2 = create_document(&IID_IXMLDOMDocument);
5766 IXMLDOMDocument_Release(doc);
5770 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5771 ok(hr == S_OK, "ret %08x\n", hr );
5774 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5775 ok(hr == S_OK, "ret %08x\n", hr );
5782 V_VT(&vDoc) = VT_UNKNOWN;
5783 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
5785 hr = IXMLDOMDocument_save(doc, vDoc);
5786 ok(hr == S_OK, "ret %08x\n", hr );
5788 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
5789 ok(hr == S_OK, "ret %08x\n", hr );
5791 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
5792 ok(hr == S_OK, "ret %08x\n", hr );
5794 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
5796 SysFreeString(sOrig);
5797 SysFreeString(sNew);
5799 IXMLDOMElement_Release(pRoot);
5802 IXMLDOMDocument_Release(doc2);
5803 IXMLDOMDocument_Release(doc);
5806 static void test_DocumentSaveToFile(void)
5808 IXMLDOMDocument *doc;
5809 IXMLDOMElement *pRoot;
5815 doc = create_document(&IID_IXMLDOMDocument);
5818 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5819 ok(hr == S_OK, "ret %08x\n", hr );
5822 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5823 ok(hr == S_OK, "ret %08x\n", hr );
5828 V_VT(&vFile) = VT_BSTR;
5829 V_BSTR(&vFile) = _bstr_("test.xml");
5831 hr = IXMLDOMDocument_save(doc, vFile);
5832 ok(hr == S_OK, "ret %08x\n", hr );
5836 IXMLDOMElement_Release(pRoot);
5837 IXMLDOMDocument_Release(doc);
5839 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
5840 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
5841 if(file == INVALID_HANDLE_VALUE)
5844 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
5845 ok(read != 0, "could not read file\n");
5846 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
5849 DeleteFile("test.xml");
5852 static void test_testTransforms(void)
5854 IXMLDOMDocument *doc, *docSS;
5860 doc = create_document(&IID_IXMLDOMDocument);
5863 docSS = create_document(&IID_IXMLDOMDocument);
5866 IXMLDOMDocument_Release(doc);
5870 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
5871 ok(hr == S_OK, "ret %08x\n", hr );
5873 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
5874 ok(hr == S_OK, "ret %08x\n", hr );
5876 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
5877 ok(hr == S_OK, "ret %08x\n", hr );
5882 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
5883 ok(hr == S_OK, "ret %08x\n", hr );
5884 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
5885 SysFreeString(bOut);
5887 IXMLDOMNode_Release(pNode);
5890 IXMLDOMDocument_Release(docSS);
5891 IXMLDOMDocument_Release(doc);
5896 static void test_Namespaces(void)
5898 IXMLDOMDocument *doc;
5900 IXMLDOMNode *pNode2 = NULL;
5904 static const CHAR szNamespacesXML[] =
5905 "<?xml version=\"1.0\"?>\n"
5906 "<root xmlns:WEB='http://www.winehq.org'>\n"
5907 "<WEB:Site version=\"1.0\" />\n"
5910 doc = create_document(&IID_IXMLDOMDocument);
5913 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
5914 ok(hr == S_OK, "ret %08x\n", hr );
5915 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
5917 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
5918 ok(hr == S_OK, "ret %08x\n", hr );
5921 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
5922 ok( hr == S_OK, "ret %08x\n", hr );
5923 ok( pNode2 != NULL, "pNode2 == NULL\n");
5925 /* Test get_prefix */
5926 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
5927 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
5928 /* NOTE: Need to test that arg2 gets cleared on Error. */
5930 hr = IXMLDOMNode_get_prefix(pNode2, &str);
5931 ok( hr == S_OK, "ret %08x\n", hr );
5932 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
5935 /* Test get_namespaceURI */
5936 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
5937 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
5938 /* NOTE: Need to test that arg2 gets cleared on Error. */
5940 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
5941 ok( hr == S_OK, "ret %08x\n", hr );
5942 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
5945 IXMLDOMNode_Release(pNode2);
5946 IXMLDOMNode_Release(pNode);
5949 IXMLDOMDocument_Release(doc);
5954 static void test_FormattingXML(void)
5956 IXMLDOMDocument *doc;
5957 IXMLDOMElement *pElement;
5961 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
5962 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
5964 doc = create_document(&IID_IXMLDOMDocument);
5967 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
5968 ok(hr == S_OK, "ret %08x\n", hr );
5969 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
5971 if(bSucc == VARIANT_TRUE)
5973 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
5974 ok(hr == S_OK, "ret %08x\n", hr );
5977 hr = IXMLDOMElement_get_xml(pElement, &str);
5978 ok(hr == S_OK, "ret %08x\n", hr );
5979 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
5982 IXMLDOMElement_Release(pElement);
5986 IXMLDOMDocument_Release(doc);
5991 typedef struct _nodetypedvalue_t {
5994 const char *value; /* value in string format */
5997 static const nodetypedvalue_t get_nodetypedvalue[] = {
5998 { "root/string", VT_BSTR, "Wine" },
5999 { "root/string2", VT_BSTR, "String" },
6000 { "root/number", VT_BSTR, "12.44" },
6001 { "root/number2", VT_BSTR, "-3.71e3" },
6002 { "root/int", VT_I4, "-13" },
6003 { "root/fixed", VT_CY, "7322.9371" },
6004 { "root/bool", VT_BOOL, "-1" },
6005 { "root/datetime", VT_DATE, "40135.14" },
6006 { "root/datetimetz",VT_DATE, "37813.59" },
6007 { "root/date", VT_DATE, "665413" },
6008 { "root/time", VT_DATE, "0.5813889" },
6009 { "root/timetz", VT_DATE, "1.112512" },
6010 { "root/i1", VT_I1, "-13" },
6011 { "root/i2", VT_I2, "31915" },
6012 { "root/i4", VT_I4, "-312232" },
6013 { "root/ui1", VT_UI1, "123" },
6014 { "root/ui2", VT_UI2, "48282" },
6015 { "root/ui4", VT_UI4, "949281" },
6016 { "root/r4", VT_R4, "213124" },
6017 { "root/r8", VT_R8, "0.412" },
6018 { "root/float", VT_R8, "41221.421" },
6019 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
6023 static void test_nodeTypedValue(void)
6025 const nodetypedvalue_t *entry = get_nodetypedvalue;
6026 IXMLDOMDocumentType *doctype, *doctype2;
6027 IXMLDOMProcessingInstruction *pi;
6028 IXMLDOMDocumentFragment *frag;
6029 IXMLDOMDocument *doc, *doc2;
6030 IXMLDOMCDATASection *cdata;
6031 IXMLDOMComment *comment;
6037 doc = create_document(&IID_IXMLDOMDocument);
6041 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
6042 ok(hr == S_OK, "ret %08x\n", hr );
6043 ok(b == VARIANT_TRUE, "got %d\n", b);
6045 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
6046 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6048 V_VT(&value) = VT_BSTR;
6049 V_BSTR(&value) = NULL;
6050 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
6051 ok(hr == S_FALSE, "ret %08x\n", hr );
6052 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
6054 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
6055 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6057 V_VT(&value) = VT_EMPTY;
6058 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
6059 ok(hr == S_FALSE, "ret %08x\n", hr );
6060 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
6062 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
6063 ok(hr == S_OK, "ret %08x\n", hr );
6065 V_VT(&value) = VT_BSTR;
6066 V_BSTR(&value) = NULL;
6067 hr = IXMLDOMNode_get_nodeValue(node, &value);
6068 ok(hr == S_FALSE, "ret %08x\n", hr );
6069 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
6071 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
6072 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6074 IXMLDOMNode_Release(node);
6076 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
6077 ok(hr == S_OK, "ret %08x\n", hr );
6079 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
6081 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6082 ok(hr == S_OK, "ret %08x\n", hr );
6083 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
6084 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
6085 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
6086 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
6087 VariantClear(&value);
6088 IXMLDOMNode_Release(node);
6091 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binbase64"), &node);
6092 ok(hr == S_OK, "ret %08x\n", hr );
6094 BYTE bytes[] = {0x62,0x61,0x73,0x65,0x36,0x34,0x20,0x74,0x65,0x73,0x74};
6096 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6097 ok(hr == S_OK, "ret %08x\n", hr );
6098 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
6099 ok(V_ARRAY(&value)->rgsabound[0].cElements == 11, "incorrect array size\n");
6100 if(V_ARRAY(&value)->rgsabound[0].cElements == 11)
6101 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
6102 VariantClear(&value);
6103 IXMLDOMNode_Release(node);
6106 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("foo"), _bstr_("value"), &pi);
6107 ok(hr == S_OK, "ret %08x\n", hr );
6109 V_VT(&value) = VT_NULL;
6110 V_BSTR(&value) = (void*)0xdeadbeef;
6111 hr = IXMLDOMProcessingInstruction_get_nodeTypedValue(pi, &value);
6112 ok(hr == S_OK, "ret %08x\n", hr );
6113 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
6114 ok(!lstrcmpW(V_BSTR(&value), _bstr_("value")), "got wrong value\n");
6115 IXMLDOMProcessingInstruction_Release(pi);
6116 VariantClear(&value);
6119 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("[1]*2=3; &gee thats not right!"), &cdata);
6120 ok(hr == S_OK, "ret %08x\n", hr );
6122 V_VT(&value) = VT_NULL;
6123 V_BSTR(&value) = (void*)0xdeadbeef;
6124 hr = IXMLDOMCDATASection_get_nodeTypedValue(cdata, &value);
6125 ok(hr == S_OK, "ret %08x\n", hr );
6126 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
6127 ok(!lstrcmpW(V_BSTR(&value), _bstr_("[1]*2=3; &gee thats not right!")), "got wrong value\n");
6128 IXMLDOMCDATASection_Release(cdata);
6129 VariantClear(&value);
6132 hr = IXMLDOMDocument_createComment(doc, _bstr_("comment"), &comment);
6133 ok(hr == S_OK, "ret %08x\n", hr );
6135 V_VT(&value) = VT_NULL;
6136 V_BSTR(&value) = (void*)0xdeadbeef;
6137 hr = IXMLDOMComment_get_nodeTypedValue(comment, &value);
6138 ok(hr == S_OK, "ret %08x\n", hr );
6139 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
6140 ok(!lstrcmpW(V_BSTR(&value), _bstr_("comment")), "got wrong value\n");
6141 IXMLDOMComment_Release(comment);
6142 VariantClear(&value);
6145 hr = IXMLDOMDocument_createDocumentFragment(doc, &frag);
6146 ok(hr == S_OK, "ret %08x\n", hr );
6148 V_VT(&value) = VT_EMPTY;
6149 hr = IXMLDOMDocumentFragment_get_nodeTypedValue(frag, &value);
6150 ok(hr == S_FALSE, "ret %08x\n", hr );
6151 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
6152 IXMLDOMDocumentFragment_Release(frag);
6155 doc2 = create_document(&IID_IXMLDOMDocument);
6158 hr = IXMLDOMDocument_loadXML(doc2, _bstr_(szEmailXML), &b);
6159 ok(hr == S_OK, "ret %08x\n", hr );
6160 ok(b == VARIANT_TRUE, "got %d\n", b);
6162 EXPECT_REF(doc2, 1);
6164 hr = IXMLDOMDocument_get_doctype(doc2, &doctype);
6165 ok(hr == S_OK, "ret %08x\n", hr );
6167 EXPECT_REF(doc2, 1);
6168 todo_wine EXPECT_REF(doctype, 2);
6171 V_VT(&value) = VT_EMPTY;
6172 hr = IXMLDOMDocumentType_get_nodeTypedValue(doctype, &value);
6173 ok(hr == S_FALSE, "ret %08x\n", hr );
6174 ok(V_VT(&value) == VT_NULL, "got %d\n", V_VT(&value));
6177 hr = IXMLDOMDocument_get_doctype(doc2, &doctype2);
6178 ok(hr == S_OK, "ret %08x\n", hr );
6179 ok(doctype != doctype2, "got %p, was %p\n", doctype2, doctype);
6181 IXMLDOMDocumentType_Release(doctype2);
6182 IXMLDOMDocumentType_Release(doctype);
6184 IXMLDOMDocument_Release(doc2);
6188 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
6189 ok(hr == S_OK, "ret %08x\n", hr );
6191 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6192 ok(hr == S_OK, "ret %08x\n", hr );
6193 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
6195 if (entry->type != VT_BSTR)
6197 if (entry->type == VT_DATE ||
6198 entry->type == VT_R8 ||
6199 entry->type == VT_CY)
6201 if (entry->type == VT_DATE)
6203 hr = VariantChangeType(&value, &value, 0, VT_R4);
6204 ok(hr == S_OK, "ret %08x\n", hr );
6206 hr = VariantChangeTypeEx(&value, &value,
6207 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
6208 VARIANT_NOUSEROVERRIDE, VT_BSTR);
6209 ok(hr == S_OK, "ret %08x\n", hr );
6213 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
6214 ok(hr == S_OK, "ret %08x\n", hr );
6217 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
6218 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
6221 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
6222 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
6224 VariantClear( &value );
6225 IXMLDOMNode_Release(node);
6230 IXMLDOMDocument_Release(doc);
6234 static void test_TransformWithLoadingLocalFile(void)
6236 IXMLDOMDocument *doc;
6237 IXMLDOMDocument *xsl;
6243 char lpPathBuffer[MAX_PATH];
6246 /* Create a Temp File. */
6247 GetTempPathA(MAX_PATH, lpPathBuffer);
6248 strcat(lpPathBuffer, "customers.xml" );
6250 file = CreateFile(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
6251 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
6252 if(file == INVALID_HANDLE_VALUE)
6255 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
6258 /* Correct path to not include a escape character. */
6259 for(i=0; i < strlen(lpPathBuffer); i++)
6261 if(lpPathBuffer[i] == '\\')
6262 lpPathBuffer[i] = '/';
6265 doc = create_document(&IID_IXMLDOMDocument);
6268 xsl = create_document(&IID_IXMLDOMDocument);
6271 IXMLDOMDocument2_Release(doc);
6275 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
6276 ok(hr == S_OK, "ret %08x\n", hr );
6277 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6278 if(bSucc == VARIANT_TRUE)
6281 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
6282 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
6283 BSTR sFileName = _bstr_(lpPathBuffer);
6284 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
6286 sXSL = SysAllocStringLen(NULL, nLegnth);
6287 lstrcpyW(sXSL, sPart1);
6288 lstrcatW(sXSL, sFileName);
6289 lstrcatW(sXSL, sPart2);
6291 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
6292 ok(hr == S_OK, "ret %08x\n", hr );
6293 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6294 if(bSucc == VARIANT_TRUE)
6298 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
6299 ok(hr == S_OK, "ret %08x\n", hr );
6302 /* This will load the temp file via the XSL */
6303 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
6304 ok(hr == S_OK, "ret %08x\n", hr );
6307 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
6308 SysFreeString(sResult);
6311 IXMLDOMNode_Release(pNode);
6315 SysFreeString(sXSL);
6318 IXMLDOMDocument_Release(doc);
6319 IXMLDOMDocument_Release(xsl);
6321 DeleteFile(lpPathBuffer);
6325 static void test_put_nodeValue(void)
6327 static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
6328 IXMLDOMDocument *doc;
6330 IXMLDOMEntityReference *entityref;
6331 IXMLDOMAttribute *attr;
6336 doc = create_document(&IID_IXMLDOMDocument);
6339 /* test for unsupported types */
6341 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
6342 ok(hr == S_OK, "ret %08x\n", hr );
6343 V_VT(&data) = VT_BSTR;
6344 V_BSTR(&data) = _bstr_("one two three");
6345 hr = IXMLDOMNode_put_nodeValue(node, data);
6346 ok(hr == E_FAIL, "ret %08x\n", hr );
6347 IXMLDOMNode_Release(node);
6349 /* NODE_DOCUMENT_FRAGMENT */
6350 V_VT(&type) = VT_I1;
6351 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
6352 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
6353 ok(hr == S_OK, "ret %08x\n", hr );
6354 V_VT(&data) = VT_BSTR;
6355 V_BSTR(&data) = _bstr_("one two three");
6356 hr = IXMLDOMNode_put_nodeValue(node, data);
6357 ok(hr == E_FAIL, "ret %08x\n", hr );
6358 IXMLDOMNode_Release(node);
6361 V_VT(&type) = VT_I1;
6362 V_I1(&type) = NODE_ELEMENT;
6363 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
6364 ok(hr == S_OK, "ret %08x\n", hr );
6365 V_VT(&data) = VT_BSTR;
6366 V_BSTR(&data) = _bstr_("one two three");
6367 hr = IXMLDOMNode_put_nodeValue(node, data);
6368 ok(hr == E_FAIL, "ret %08x\n", hr );
6369 IXMLDOMNode_Release(node);
6371 /* NODE_ENTITY_REFERENCE */
6372 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
6373 ok(hr == S_OK, "ret %08x\n", hr );
6375 V_VT(&data) = VT_BSTR;
6376 V_BSTR(&data) = _bstr_("one two three");
6377 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
6378 ok(hr == E_FAIL, "ret %08x\n", hr );
6380 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
6381 ok(hr == S_OK, "ret %08x\n", hr );
6382 V_VT(&data) = VT_BSTR;
6383 V_BSTR(&data) = _bstr_("one two three");
6384 hr = IXMLDOMNode_put_nodeValue(node, data);
6385 ok(hr == E_FAIL, "ret %08x\n", hr );
6386 IXMLDOMNode_Release(node);
6387 IXMLDOMEntityReference_Release(entityref);
6389 /* supported types */
6390 hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
6391 ok(hr == S_OK, "ret %08x\n", hr );
6392 V_VT(&data) = VT_BSTR;
6393 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
6394 hr = IXMLDOMText_put_nodeValue(text, data);
6395 ok(hr == S_OK, "ret %08x\n", hr );
6396 IXMLDOMText_Release(text);
6398 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
6399 ok(hr == S_OK, "ret %08x\n", hr );
6400 V_VT(&data) = VT_BSTR;
6401 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
6402 hr = IXMLDOMAttribute_put_nodeValue(attr, data);
6403 ok(hr == S_OK, "ret %08x\n", hr );
6404 hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
6405 ok(hr == S_OK, "ret %08x\n", hr );
6406 ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
6407 wine_dbgstr_w(V_BSTR(&data)));
6408 VariantClear(&data);
6409 IXMLDOMAttribute_Release(attr);
6413 IXMLDOMDocument_Release(doc);
6416 static void test_document_IObjectSafety(void)
6418 IXMLDOMDocument *doc;
6419 IObjectSafety *safety;
6422 doc = create_document(&IID_IXMLDOMDocument);
6425 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
6426 ok(hr == S_OK, "ret %08x\n", hr );
6428 test_IObjectSafety_common(safety);
6430 IObjectSafety_Release(safety);
6432 IXMLDOMDocument_Release(doc);
6435 typedef struct _property_test_t {
6438 const char *property;
6442 static const property_test_t properties_test_data[] = {
6443 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
6444 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
6445 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
6446 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
6447 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
6451 static void test_default_properties(void)
6453 const property_test_t *entry = properties_test_data;
6454 IXMLDOMDocument2 *doc;
6460 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
6463 win_skip("can't create %s instance\n", entry->clsid);
6468 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
6469 ok(hr == S_OK, "got 0x%08x\n", hr);
6470 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
6471 entry->value, entry->clsid);
6474 IXMLDOMDocument2_Release(doc);
6480 static void test_XSLPattern(void)
6482 IXMLDOMDocument2 *doc;
6483 IXMLDOMNodeList *list;
6487 doc = create_document(&IID_IXMLDOMDocument2);
6490 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
6491 ok(b == VARIANT_TRUE, "failed to load XML string\n");
6493 /* switch to XSLPattern */
6494 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
6496 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
6497 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list));
6499 ole_check(IXMLDOMNodeList_get_length(list, &len));
6500 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
6501 ok(len == 3, "expected 3 entries in list, got %d\n", len);
6502 IXMLDOMNodeList_Release(list);
6504 /* for XSLPattern start index is 0, for XPath it's 1 */
6505 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
6507 ole_check(IXMLDOMNodeList_get_length(list, &len));
6508 ok(len != 0, "expected filled list\n");
6510 expect_list_and_release(list, "E1.E2.D1");
6513 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=1]"), &list));
6515 ole_check(IXMLDOMNodeList_get_length(list, &len));
6516 ok(len != 0, "expected filled list\n");
6518 expect_list_and_release(list, "E2.E2.D1");
6521 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $eq$ 1]"), &list));
6523 ole_check(IXMLDOMNodeList_get_length(list, &len));
6524 ok(len != 0, "expected filled list\n");
6526 expect_list_and_release(list, "E2.E2.D1");
6529 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[end()]"), &list));
6531 ole_check(IXMLDOMNodeList_get_length(list, &len));
6532 ok(len != 0, "expected filled list\n");
6534 expect_list_and_release(list, "E4.E2.D1");
6537 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$not$ end()]"), &list));
6539 ole_check(IXMLDOMNodeList_get_length(list, &len));
6540 ok(len != 0, "expected filled list\n");
6542 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
6545 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() != 0]"), &list));
6547 ole_check(IXMLDOMNodeList_get_length(list, &len));
6548 ok(len != 0, "expected filled list\n");
6550 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
6551 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ne$ 0]"), &list));
6553 ole_check(IXMLDOMNodeList_get_length(list, &len));
6554 ok(len != 0, "expected filled list\n");
6556 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
6559 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() < 2]"), &list));
6561 ole_check(IXMLDOMNodeList_get_length(list, &len));
6562 ok(len != 0, "expected filled list\n");
6564 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6565 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $lt$ 2]"), &list));
6567 ole_check(IXMLDOMNodeList_get_length(list, &len));
6568 ok(len != 0, "expected filled list\n");
6570 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6573 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() <= 1]"), &list));
6575 ole_check(IXMLDOMNodeList_get_length(list, &len));
6576 ok(len != 0, "expected filled list\n");
6578 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6579 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $le$ 1]"), &list));
6581 ole_check(IXMLDOMNodeList_get_length(list, &len));
6582 ok(len != 0, "expected filled list\n");
6584 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6587 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() > 1]"), &list));
6589 ole_check(IXMLDOMNodeList_get_length(list, &len));
6590 ok(len != 0, "expected filled list\n");
6592 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6593 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $gt$ 1]"), &list));
6595 ole_check(IXMLDOMNodeList_get_length(list, &len));
6596 ok(len != 0, "expected filled list\n");
6598 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6601 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() >= 2]"), &list));
6603 ole_check(IXMLDOMNodeList_get_length(list, &len));
6604 ok(len != 0, "expected filled list\n");
6606 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6607 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ge$ 2]"), &list));
6609 ole_check(IXMLDOMNodeList_get_length(list, &len));
6610 ok(len != 0, "expected filled list\n");
6612 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6615 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ieq$ 'a2 field']"), &list));
6617 ole_check(IXMLDOMNodeList_get_length(list, &len));
6618 ok(len != 0, "expected filled list\n");
6620 expect_list_and_release(list, "E2.E2.D1");
6623 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ine$ 'a2 field']"), &list));
6625 ole_check(IXMLDOMNodeList_get_length(list, &len));
6626 ok(len != 0, "expected filled list\n");
6628 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
6631 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ilt$ 'a3 field']"), &list));
6633 ole_check(IXMLDOMNodeList_get_length(list, &len));
6634 ok(len != 0, "expected filled list\n");
6636 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6639 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ile$ 'a2 field']"), &list));
6641 ole_check(IXMLDOMNodeList_get_length(list, &len));
6642 ok(len != 0, "expected filled list\n");
6644 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6647 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $igt$ 'a2 field']"), &list));
6649 ole_check(IXMLDOMNodeList_get_length(list, &len));
6650 ok(len != 0, "expected filled list\n");
6652 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6655 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ige$ 'a3 field']"), &list));
6657 ole_check(IXMLDOMNodeList_get_length(list, &len));
6658 ok(len != 0, "expected filled list\n");
6660 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6663 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$any$ *='B2 field']"), &list));
6665 ole_check(IXMLDOMNodeList_get_length(list, &len));
6666 ok(len != 0, "expected filled list\n");
6668 expect_list_and_release(list, "E2.E2.D1");
6671 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$all$ *!='B2 field']"), &list));
6673 ole_check(IXMLDOMNodeList_get_length(list, &len));
6674 ok(len != 0, "expected filled list\n");
6676 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
6679 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 or end()]"), &list));
6681 ole_check(IXMLDOMNodeList_get_length(list, &len));
6682 ok(len != 0, "expected filled list\n");
6684 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
6685 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 $or$ end()]"), &list));
6687 ole_check(IXMLDOMNodeList_get_length(list, &len));
6688 ok(len != 0, "expected filled list\n");
6690 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
6691 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 || end()]"), &list));
6693 ole_check(IXMLDOMNodeList_get_length(list, &len));
6694 ok(len != 0, "expected filled list\n");
6696 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
6699 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 and $not$ end()]"), &list));
6701 ole_check(IXMLDOMNodeList_get_length(list, &len));
6702 ok(len != 0, "expected filled list\n");
6704 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
6705 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 $and$ $not$ end()]"), &list));
6707 ole_check(IXMLDOMNodeList_get_length(list, &len));
6708 ok(len != 0, "expected filled list\n");
6710 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
6711 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 && $not$ end()]"), &list));
6713 ole_check(IXMLDOMNodeList_get_length(list, &len));
6714 ok(len != 0, "expected filled list\n");
6716 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
6718 /* namespace handling */
6719 /* no registered namespaces */
6720 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
6723 /* prefixes don't need to be registered, you may use them as they are in the doc */
6724 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//bar:x"), &list));
6726 ole_check(IXMLDOMNodeList_get_length(list, &len));
6727 ok(len != 0, "expected filled list\n");
6729 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
6731 /* prefixes must be explicitly specified in the name */
6732 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:elem"), &list));
6734 ole_check(IXMLDOMNodeList_get_length(list, &len));
6735 ok(len == 0, "expected empty list\n");
6736 IXMLDOMNodeList_Release(list);
6738 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
6740 ole_check(IXMLDOMNodeList_get_length(list, &len));
6741 ok(len != 0, "expected filled list\n");
6743 expect_list_and_release(list, "E3.E4.E2.D1");
6745 /* explicitly register prefix foo */
6746 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
6748 /* now we get the same behavior as XPath */
6749 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
6751 ole_check(IXMLDOMNodeList_get_length(list, &len));
6752 ok(len != 0, "expected filled list\n");
6754 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
6756 /* set prefix foo to some nonexistent namespace */
6757 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:nonexistent-foo'")));
6759 /* the registered prefix takes precedence */
6760 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
6762 ole_check(IXMLDOMNodeList_get_length(list, &len));
6763 ok(len == 0, "expected empty list\n");
6764 IXMLDOMNodeList_Release(list);
6766 IXMLDOMDocument2_Release(doc);
6768 doc = create_document(&IID_IXMLDOMDocument2);
6771 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szNodeTypesXML), &b));
6772 ok(b == VARIANT_TRUE, "failed to load XML string\n");
6776 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute()"), &list));
6778 ole_check(IXMLDOMNodeList_get_length(list, &len));
6779 ok(len == 0, "expected empty list\n");
6780 IXMLDOMNodeList_Release(list);
6782 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute('depth')"), &list));
6784 ole_check(IXMLDOMNodeList_get_length(list, &len));
6785 ok(len == 0, "expected empty list\n");
6786 IXMLDOMNodeList_Release(list);
6788 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/attribute('depth')"), &list));
6790 ole_check(IXMLDOMNodeList_get_length(list, &len));
6791 ok(len != 0, "expected filled list\n");
6792 expect_list_and_release(list, "A'depth'.E3.D1");
6794 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/attribute()"), &list));
6796 ole_check(IXMLDOMNodeList_get_length(list, &len));
6797 ok(len != 0, "expected filled list\n");
6798 expect_list_and_release(list, "A'id'.E3.E3.D1 A'depth'.E3.E3.D1");
6801 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute(id)"), &list), E_FAIL);
6803 IXMLDOMNodeList_Release(list);
6804 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute('id')"), &list));
6806 ole_check(IXMLDOMNodeList_get_length(list, &len));
6807 ok(len != 0, "expected filled list\n");
6809 expect_list_and_release(list, "A'id'.E3.E3.D1 A'id'.E4.E3.E3.D1 A'id'.E5.E3.E3.D1 A'id'.E6.E3.E3.D1");
6812 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("comment()"), &list));
6814 ole_check(IXMLDOMNodeList_get_length(list, &len));
6815 ok(len != 0, "expected filled list\n");
6817 expect_list_and_release(list, "C2.D1");
6819 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//comment()"), &list));
6821 ole_check(IXMLDOMNodeList_get_length(list, &len));
6822 ok(len != 0, "expected filled list\n");
6824 expect_list_and_release(list, "C2.D1 C1.E3.D1 C2.E3.E3.D1 C2.E4.E3.D1");
6827 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("element()"), &list));
6829 ole_check(IXMLDOMNodeList_get_length(list, &len));
6830 ok(len != 0, "expected filled list\n");
6832 expect_list_and_release(list, "E3.D1");
6834 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/y/element()"), &list));
6836 ole_check(IXMLDOMNodeList_get_length(list, &len));
6837 ok(len != 0, "expected filled list\n");
6839 expect_list_and_release(list, "E4.E4.E3.D1 E5.E4.E3.D1 E6.E4.E3.D1");
6842 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element(a)"), &list), E_FAIL);
6844 IXMLDOMNodeList_Release(list);
6845 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element('a')"), &list));
6847 ole_check(IXMLDOMNodeList_get_length(list, &len));
6848 ok(len != 0, "expected filled list\n");
6850 expect_list_and_release(list, "E4.E3.E3.D1 E4.E4.E3.D1");
6853 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("node()"), &list));
6855 ole_check(IXMLDOMNodeList_get_length(list, &len));
6856 ok(len != 0, "expected filled list\n");
6858 expect_list_and_release(list, "P1.D1 C2.D1 E3.D1");
6860 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()"), &list));
6862 ole_check(IXMLDOMNodeList_get_length(list, &len));
6863 ok(len != 0, "expected filled list\n");
6865 expect_list_and_release(list, "P1.E3.E3.D1 C2.E3.E3.D1 T3.E3.E3.D1 E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
6868 /* XML_ELEMENT_NODE */
6869 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=1]"), &list));
6871 ole_check(IXMLDOMNodeList_get_length(list, &len));
6872 ok(len != 0, "expected filled list\n");
6874 expect_list_and_release(list, "E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
6876 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=3]"), &list));
6878 ole_check(IXMLDOMNodeList_get_length(list, &len));
6879 ok(len != 0, "expected filled list\n");
6881 expect_list_and_release(list, "T3.E3.E3.D1");
6883 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=7]"), &list));
6885 ole_check(IXMLDOMNodeList_get_length(list, &len));
6886 ok(len != 0, "expected filled list\n");
6888 expect_list_and_release(list, "P1.E3.E3.D1");
6889 /* XML_COMMENT_NODE */
6890 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=8]"), &list));
6892 ole_check(IXMLDOMNodeList_get_length(list, &len));
6893 ok(len != 0, "expected filled list\n");
6895 expect_list_and_release(list, "C2.E3.E3.D1");
6898 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("pi()"), &list));
6902 ole_check(IXMLDOMNodeList_get_length(list, &len));
6903 ok(len != 0, "expected filled list\n");
6905 expect_list_and_release(list, "P1.D1");
6908 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//y/pi()"), &list));
6910 ole_check(IXMLDOMNodeList_get_length(list, &len));
6911 ok(len != 0, "expected filled list\n");
6913 expect_list_and_release(list, "P1.E4.E3.D1");
6916 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/textnode()"), &list));
6918 ole_check(IXMLDOMNodeList_get_length(list, &len));
6919 ok(len != 0, "expected filled list\n");
6921 expect_list_and_release(list, "T2.E3.D1");
6923 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/element()/textnode()"), &list));
6925 ole_check(IXMLDOMNodeList_get_length(list, &len));
6926 ok(len != 0, "expected filled list\n");
6928 expect_list_and_release(list, "T3.E3.E3.D1 T3.E4.E3.D1");
6930 IXMLDOMDocument2_Release(doc);
6934 static void test_splitText(void)
6936 IXMLDOMCDATASection *cdata;
6937 IXMLDOMElement *root;
6938 IXMLDOMDocument *doc;
6939 IXMLDOMText *text, *text2;
6942 VARIANT_BOOL success;
6946 doc = create_document(&IID_IXMLDOMDocument);
6949 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
6950 ok(hr == S_OK, "got 0x%08x\n", hr);
6952 hr = IXMLDOMDocument_get_documentElement(doc, &root);
6953 ok(hr == S_OK, "got 0x%08x\n", hr);
6955 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
6956 ok(hr == S_OK, "got 0x%08x\n", hr);
6958 V_VT(&var) = VT_EMPTY;
6959 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
6960 ok(hr == S_OK, "got 0x%08x\n", hr);
6963 hr = IXMLDOMCDATASection_get_length(cdata, &length);
6964 ok(hr == S_OK, "got 0x%08x\n", hr);
6965 ok(length > 0, "got %d\n", length);
6967 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
6968 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6970 text = (void*)0xdeadbeef;
6971 /* negative offset */
6972 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
6973 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6974 ok(text == (void*)0xdeadbeef, "got %p\n", text);
6976 text = (void*)0xdeadbeef;
6977 /* offset outside data */
6978 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
6979 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6980 ok(text == 0, "got %p\n", text);
6982 text = (void*)0xdeadbeef;
6983 /* offset outside data */
6984 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
6985 ok(hr == S_FALSE, "got 0x%08x\n", hr);
6986 ok(text == 0, "got %p\n", text);
6988 /* no empty node created */
6989 node = (void*)0xdeadbeef;
6990 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
6991 ok(hr == S_FALSE, "got 0x%08x\n", hr);
6992 ok(node == 0, "got %p\n", text);
6994 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
6995 ok(hr == S_OK, "got 0x%08x\n", hr);
6998 hr = IXMLDOMText_get_length(text, &length);
6999 ok(hr == S_OK, "got 0x%08x\n", hr);
7000 ok(length == 7, "got %d\n", length);
7002 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
7003 ok(hr == S_OK, "got 0x%08x\n", hr);
7004 IXMLDOMNode_Release(node);
7006 /* split new text node */
7007 hr = IXMLDOMText_get_length(text, &length);
7008 ok(hr == S_OK, "got 0x%08x\n", hr);
7010 node = (void*)0xdeadbeef;
7011 hr = IXMLDOMText_get_nextSibling(text, &node);
7012 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7013 ok(node == 0, "got %p\n", text);
7015 hr = IXMLDOMText_splitText(text, 0, NULL);
7016 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7018 text2 = (void*)0xdeadbeef;
7019 /* negative offset */
7020 hr = IXMLDOMText_splitText(text, -1, &text2);
7021 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7022 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
7024 text2 = (void*)0xdeadbeef;
7025 /* offset outside data */
7026 hr = IXMLDOMText_splitText(text, length + 1, &text2);
7027 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7028 ok(text2 == 0, "got %p\n", text2);
7030 text2 = (void*)0xdeadbeef;
7031 /* offset outside data */
7032 hr = IXMLDOMText_splitText(text, length, &text2);
7033 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7034 ok(text2 == 0, "got %p\n", text);
7037 hr = IXMLDOMText_splitText(text, 4, &text2);
7038 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
7039 if (text2) IXMLDOMText_Release(text2);
7042 hr = IXMLDOMText_get_nextSibling(text, &node);
7043 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
7044 if (node) IXMLDOMNode_Release(node);
7046 IXMLDOMText_Release(text);
7047 IXMLDOMElement_Release(root);
7048 IXMLDOMCDATASection_Release(cdata);
7052 static void test_getQualifiedItem(void)
7054 IXMLDOMDocument *doc;
7055 IXMLDOMElement *element;
7056 IXMLDOMNode *pr_node, *node;
7057 IXMLDOMNodeList *root_list;
7058 IXMLDOMNamedNodeMap *map;
7064 doc = create_document(&IID_IXMLDOMDocument);
7067 str = SysAllocString( szComplete4 );
7068 hr = IXMLDOMDocument_loadXML( doc, str, &b );
7069 ok( hr == S_OK, "loadXML failed\n");
7070 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7071 SysFreeString( str );
7073 hr = IXMLDOMDocument_get_documentElement(doc, &element);
7074 ok( hr == S_OK, "ret %08x\n", hr);
7076 hr = IXMLDOMElement_get_childNodes(element, &root_list);
7077 ok( hr == S_OK, "ret %08x\n", hr);
7079 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
7080 ok( hr == S_OK, "ret %08x\n", hr);
7081 IXMLDOMNodeList_Release(root_list);
7083 hr = IXMLDOMNode_get_attributes(pr_node, &map);
7084 ok( hr == S_OK, "ret %08x\n", hr);
7085 IXMLDOMNode_Release(pr_node);
7087 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
7088 ok( hr == S_OK, "ret %08x\n", hr);
7089 ok( len == 3, "length %d\n", len);
7091 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
7092 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7094 node = (void*)0xdeadbeef;
7095 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
7096 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7097 ok( node == (void*)0xdeadbeef, "got %p\n", node);
7099 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
7100 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7102 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
7103 ok( hr == S_OK, "ret %08x\n", hr);
7104 IXMLDOMNode_Release(node);
7106 IXMLDOMNamedNodeMap_Release( map );
7107 IXMLDOMElement_Release( element );
7108 IXMLDOMDocument_Release( doc );
7112 static void test_removeQualifiedItem(void)
7114 IXMLDOMDocument *doc;
7115 IXMLDOMElement *element;
7116 IXMLDOMNode *pr_node, *node;
7117 IXMLDOMNodeList *root_list;
7118 IXMLDOMNamedNodeMap *map;
7124 doc = create_document(&IID_IXMLDOMDocument);
7127 str = SysAllocString( szComplete4 );
7128 hr = IXMLDOMDocument_loadXML( doc, str, &b );
7129 ok( hr == S_OK, "loadXML failed\n");
7130 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7131 SysFreeString( str );
7133 hr = IXMLDOMDocument_get_documentElement(doc, &element);
7134 ok( hr == S_OK, "ret %08x\n", hr);
7136 hr = IXMLDOMElement_get_childNodes(element, &root_list);
7137 ok( hr == S_OK, "ret %08x\n", hr);
7139 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
7140 ok( hr == S_OK, "ret %08x\n", hr);
7141 IXMLDOMNodeList_Release(root_list);
7143 hr = IXMLDOMNode_get_attributes(pr_node, &map);
7144 ok( hr == S_OK, "ret %08x\n", hr);
7145 IXMLDOMNode_Release(pr_node);
7147 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
7148 ok( hr == S_OK, "ret %08x\n", hr);
7149 ok( len == 3, "length %d\n", len);
7151 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
7152 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7154 node = (void*)0xdeadbeef;
7155 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
7156 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7157 ok( node == (void*)0xdeadbeef, "got %p\n", node);
7159 /* out pointer is optional */
7160 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
7161 ok( hr == S_OK, "ret %08x\n", hr);
7163 /* already removed */
7164 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
7165 ok( hr == S_FALSE, "ret %08x\n", hr);
7167 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
7168 ok( hr == S_OK, "ret %08x\n", hr);
7169 IXMLDOMNode_Release(node);
7171 IXMLDOMNamedNodeMap_Release( map );
7172 IXMLDOMElement_Release( element );
7173 IXMLDOMDocument_Release( doc );
7177 #define check_default_props(doc) _check_default_props(__LINE__, doc)
7178 static inline void _check_default_props(int line, IXMLDOMDocument2* doc)
7185 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
7186 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
7189 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
7190 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("")) == 0, "expected empty string\n");
7193 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
7194 ok_(__FILE__, line)(b == VARIANT_FALSE, "expected FALSE\n");
7196 hr = IXMLDOMDocument2_get_schemas(doc, &var);
7197 ok_(__FILE__, line)(hr == S_FALSE, "got %08x\n", hr);
7201 #define check_set_props(doc) _check_set_props(__LINE__, doc)
7202 static inline void _check_set_props(int line, IXMLDOMDocument2* doc)
7208 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var));
7209 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
7212 helper_ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
7213 ok_(__FILE__, line)(lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&var)));
7216 helper_ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc, &b));
7217 ok_(__FILE__, line)(b == VARIANT_TRUE, "expected TRUE\n");
7219 helper_ole_check(IXMLDOMDocument2_get_schemas(doc, &var));
7220 ok_(__FILE__, line)(V_VT(&var) != VT_NULL, "expected pointer\n");
7224 #define set_props(doc, cache) _set_props(__LINE__, doc, cache)
7225 static inline void _set_props(int line, IXMLDOMDocument2* doc, IXMLDOMSchemaCollection* cache)
7230 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
7231 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'")));
7232 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_TRUE));
7233 V_VT(&var) = VT_DISPATCH;
7234 V_DISPATCH(&var) = NULL;
7235 helper_ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&var)));
7236 ok_(__FILE__, line)(V_DISPATCH(&var) != NULL, "expected pointer\n");
7237 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
7241 #define unset_props(doc) _unset_props(__LINE__, doc)
7242 static inline void _unset_props(int line, IXMLDOMDocument2* doc)
7247 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
7248 helper_ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
7249 helper_ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc, VARIANT_FALSE));
7250 V_VT(&var) = VT_NULL;
7251 helper_ole_check(IXMLDOMDocument2_putref_schemas(doc, var));
7255 static void test_get_ownerDocument(void)
7257 IXMLDOMDocument *doc1, *doc2, *doc3;
7258 IXMLDOMDocument2 *doc, *doc_owner;
7260 IXMLDOMSchemaCollection *cache;
7265 doc = create_document(&IID_IXMLDOMDocument2);
7266 cache = create_cache(&IID_IXMLDOMSchemaCollection);
7269 if (doc) IXMLDOMDocument2_Release(doc);
7270 if (cache) IXMLDOMSchemaCollection_Release(cache);
7276 str = SysAllocString(szComplete4);
7277 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
7278 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7281 check_default_props(doc);
7283 /* set properties and check that new instances use them */
7284 set_props(doc, cache);
7285 check_set_props(doc);
7287 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
7288 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc1));
7290 /* new interface keeps props */
7291 ole_check(IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner));
7292 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
7293 check_set_props(doc_owner);
7294 IXMLDOMDocument2_Release(doc_owner);
7296 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc2));
7297 IXMLDOMNode_Release(node);
7299 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
7302 str = SysAllocString(szComplete4);
7303 ole_check(IXMLDOMDocument2_loadXML(doc, str, &b));
7304 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7307 /* properties retained even after reload */
7308 check_set_props(doc);
7310 ole_check(IXMLDOMDocument2_get_firstChild(doc, &node));
7311 ole_check(IXMLDOMNode_get_ownerDocument(node, &doc3));
7312 IXMLDOMNode_Release(node);
7314 ole_check(IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner));
7315 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
7316 check_set_props(doc_owner);
7318 /* changing properties for one instance changes them for all */
7319 unset_props(doc_owner);
7320 check_default_props(doc_owner);
7321 check_default_props(doc);
7323 IXMLDOMSchemaCollection_Release(cache);
7324 IXMLDOMDocument_Release(doc1);
7325 IXMLDOMDocument_Release(doc2);
7326 IXMLDOMDocument_Release(doc3);
7327 IXMLDOMDocument2_Release(doc);
7328 IXMLDOMDocument2_Release(doc_owner);
7332 static void test_setAttributeNode(void)
7334 IXMLDOMDocument *doc, *doc2;
7335 IXMLDOMElement *elem, *elem2;
7336 IXMLDOMAttribute *attr, *attr2, *ret_attr;
7343 doc = create_document(&IID_IXMLDOMDocument);
7346 str = SysAllocString( szComplete4 );
7347 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
7348 ok( hr == S_OK, "loadXML failed\n");
7349 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7350 SysFreeString( str );
7352 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7353 ok( hr == S_OK, "got 0x%08x\n", hr);
7355 hr = IXMLDOMDocument_get_documentElement(doc, &elem2);
7356 ok( hr == S_OK, "got 0x%08x\n", hr);
7357 ok( elem2 != elem, "got same instance\n");
7359 ret_attr = (void*)0xdeadbeef;
7360 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
7361 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
7362 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7364 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7365 ok( hr == S_OK, "got 0x%08x\n", hr);
7367 ref1 = IXMLDOMElement_AddRef(elem);
7368 IXMLDOMElement_Release(elem);
7370 ret_attr = (void*)0xdeadbeef;
7371 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7372 ok( hr == S_OK, "got 0x%08x\n", hr);
7373 ok( ret_attr == NULL, "got %p\n", ret_attr);
7375 /* no reference added */
7376 ref2 = IXMLDOMElement_AddRef(elem);
7377 IXMLDOMElement_Release(elem);
7378 ok(ref2 == ref1, "got %d, expected %d\n", ref2, ref1);
7380 EXPECT_CHILDREN(elem);
7381 EXPECT_CHILDREN(elem2);
7383 IXMLDOMElement_Release(elem2);
7386 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
7387 ok( hr == S_OK, "got 0x%08x\n", hr);
7388 ok( attr2 != attr, "got same instance %p\n", attr2);
7389 IXMLDOMAttribute_Release(attr2);
7391 /* try to add it another time */
7392 ret_attr = (void*)0xdeadbeef;
7393 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7394 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7395 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7397 IXMLDOMElement_Release(elem);
7399 /* initialy used element is released, attribute still 'has' a container */
7400 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7401 ok( hr == S_OK, "got 0x%08x\n", hr);
7402 ret_attr = (void*)0xdeadbeef;
7403 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7404 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7405 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7406 IXMLDOMElement_Release(elem);
7408 /* add attribute already attached to another document */
7409 doc2 = create_document(&IID_IXMLDOMDocument);
7411 str = SysAllocString( szComplete4 );
7412 hr = IXMLDOMDocument_loadXML( doc2, str, &b );
7413 ok( hr == S_OK, "loadXML failed\n");
7414 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7415 SysFreeString( str );
7417 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
7418 ok( hr == S_OK, "got 0x%08x\n", hr);
7419 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
7420 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7421 IXMLDOMElement_Release(elem);
7423 IXMLDOMAttribute_Release(attr);
7425 /* create element, add attribute, see if it's copied or linked */
7426 hr = IXMLDOMDocument_createElement(doc, _bstr_("test"), &elem);
7427 ok( hr == S_OK, "got 0x%08x\n", hr);
7430 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7431 ok(hr == S_OK, "got 0x%08x\n", hr);
7432 ok(attr != NULL, "got %p\n", attr);
7434 ref1 = IXMLDOMAttribute_AddRef(attr);
7435 IXMLDOMAttribute_Release(attr);
7438 V_BSTR(&v) = _bstr_("attrvalue1");
7439 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
7440 ok( hr == S_OK, "got 0x%08x\n", hr);
7443 hr = IXMLDOMAttribute_get_xml(attr, &str);
7444 ok( hr == S_OK, "got 0x%08x\n", hr);
7445 ok( lstrcmpW(str, _bstr_("attr=\"attrvalue1\"")) == 0,
7446 "got %s\n", wine_dbgstr_w(str));
7449 ret_attr = (void*)0xdeadbeef;
7450 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7451 ok(hr == S_OK, "got 0x%08x\n", hr);
7452 ok(ret_attr == NULL, "got %p\n", ret_attr);
7454 /* attribute reference increased */
7455 ref2 = IXMLDOMAttribute_AddRef(attr);
7456 IXMLDOMAttribute_Release(attr);
7457 ok(ref1 == ref2, "got %d, expected %d\n", ref2, ref1);
7459 hr = IXMLDOMElement_get_xml(elem, &str);
7460 ok( hr == S_OK, "got 0x%08x\n", hr);
7461 ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue1\"/>")) == 0,
7462 "got %s\n", wine_dbgstr_w(str));
7466 V_BSTR(&v) = _bstr_("attrvalue2");
7467 hr = IXMLDOMAttribute_put_nodeValue(attr, v);
7468 ok( hr == S_OK, "got 0x%08x\n", hr);
7470 hr = IXMLDOMElement_get_xml(elem, &str);
7471 ok( hr == S_OK, "got 0x%08x\n", hr);
7472 todo_wine ok( lstrcmpW(str, _bstr_("<test attr=\"attrvalue2\"/>")) == 0,
7473 "got %s\n", wine_dbgstr_w(str));
7476 IXMLDOMElement_Release(elem);
7477 IXMLDOMAttribute_Release(attr);
7478 IXMLDOMDocument_Release(doc2);
7479 IXMLDOMDocument_Release(doc);
7482 static void test_put_dataType(void)
7484 IXMLDOMCDATASection *cdata;
7485 IXMLDOMDocument *doc;
7490 doc = create_document(&IID_IXMLDOMDocument);
7493 str = SysAllocString( szComplete4 );
7494 hr = IXMLDOMDocument_loadXML( doc, str, &b );
7495 ok( hr == S_OK, "loadXML failed\n");
7496 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7497 SysFreeString( str );
7499 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("test"), &cdata);
7500 ok( hr == S_OK, "got 0x%08x\n", hr);
7501 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("number"));
7502 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7503 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("string"));
7504 ok( hr == E_FAIL, "got 0x%08x\n", hr);
7505 IXMLDOMCDATASection_Release(cdata);
7507 IXMLDOMDocument_Release(doc);
7511 static void test_createNode(void)
7513 IXMLDOMDocument *doc;
7514 IXMLDOMElement *elem;
7521 doc = create_document(&IID_IXMLDOMDocument);
7526 /* reference count tests */
7527 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
7528 ok( hr == S_OK, "got 0x%08x\n", hr);
7530 /* initial reference is 2 */
7532 EXPECT_REF(elem, 2);
7533 ref = IXMLDOMElement_Release(elem);
7534 ok(ref == 1, "got %d\n", ref);
7535 /* it's released already, attempt to release now will crash it */
7538 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
7539 ok( hr == S_OK, "got 0x%08x\n", hr);
7540 todo_wine EXPECT_REF(elem, 2);
7541 IXMLDOMDocument_Release(doc);
7542 todo_wine EXPECT_REF(elem, 2);
7543 IXMLDOMElement_Release(elem);
7545 doc = create_document(&IID_IXMLDOMDocument);
7547 /* NODE_ELEMENT nodes */
7548 /* 1. specified namespace */
7550 V_I4(&v) = NODE_ELEMENT;
7552 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
7553 ok( hr == S_OK, "got 0x%08x\n", hr);
7555 hr = IXMLDOMNode_get_prefix(node, &prefix);
7556 ok( hr == S_OK, "got 0x%08x\n", hr);
7557 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
7558 SysFreeString(prefix);
7559 IXMLDOMNode_Release(node);
7561 /* 2. default namespace */
7562 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
7563 ok( hr == S_OK, "got 0x%08x\n", hr);
7564 prefix = (void*)0xdeadbeef;
7565 hr = IXMLDOMNode_get_prefix(node, &prefix);
7566 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7567 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
7569 hr = IXMLDOMNode_get_xml(node, &str);
7570 ok( hr == S_OK, "got 0x%08x\n", hr);
7571 ok( lstrcmpW(str, _bstr_("<test xmlns=\"http://winehq.org/default\"/>")) == 0,
7572 "got %s\n", wine_dbgstr_w(str));
7575 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
7576 ok( hr == S_OK, "got 0x%08x\n", hr);
7578 V_VT(&var) = VT_BSTR;
7579 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
7580 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7581 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
7584 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
7585 ok( hr == S_OK, "got 0x%08x\n", hr);
7586 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
7589 IXMLDOMElement_Release(elem);
7590 IXMLDOMNode_Release(node);
7592 IXMLDOMDocument_Release(doc);
7596 static void test_get_prefix(void)
7598 IXMLDOMDocumentFragment *fragment;
7599 IXMLDOMCDATASection *cdata;
7600 IXMLDOMElement *element;
7601 IXMLDOMComment *comment;
7602 IXMLDOMDocument *doc;
7606 doc = create_document(&IID_IXMLDOMDocument);
7609 /* nodes that can't support prefix */
7611 str = (void*)0xdeadbeef;
7612 hr = IXMLDOMDocument_get_prefix(doc, &str);
7613 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7614 ok( str == 0, "got %p\n", str);
7616 hr = IXMLDOMDocument_get_prefix(doc, NULL);
7617 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
7620 hr = IXMLDOMDocument_createCDATASection(doc, NULL, &cdata);
7621 ok(hr == S_OK, "got %08x\n", hr );
7623 str = (void*)0xdeadbeef;
7624 hr = IXMLDOMCDATASection_get_prefix(cdata, &str);
7625 ok(hr == S_FALSE, "got %08x\n", hr);
7626 ok( str == 0, "got %p\n", str);
7628 hr = IXMLDOMCDATASection_get_prefix(cdata, NULL);
7629 ok(hr == E_INVALIDARG, "got %08x\n", hr);
7630 IXMLDOMCDATASection_Release(cdata);
7633 hr = IXMLDOMDocument_createComment(doc, NULL, &comment);
7634 ok(hr == S_OK, "got %08x\n", hr );
7636 str = (void*)0xdeadbeef;
7637 hr = IXMLDOMComment_get_prefix(comment, &str);
7638 ok(hr == S_FALSE, "got %08x\n", hr);
7639 ok( str == 0, "got %p\n", str);
7641 hr = IXMLDOMComment_get_prefix(comment, NULL);
7642 ok(hr == E_INVALIDARG, "got %08x\n", hr);
7643 IXMLDOMComment_Release(comment);
7646 hr = IXMLDOMDocument_createDocumentFragment(doc, &fragment);
7647 ok(hr == S_OK, "got %08x\n", hr );
7649 str = (void*)0xdeadbeef;
7650 hr = IXMLDOMDocumentFragment_get_prefix(fragment, &str);
7651 ok(hr == S_FALSE, "got %08x\n", hr);
7652 ok( str == 0, "got %p\n", str);
7654 hr = IXMLDOMDocumentFragment_get_prefix(fragment, NULL);
7655 ok(hr == E_INVALIDARG, "got %08x\n", hr);
7656 IXMLDOMDocumentFragment_Release(fragment);
7659 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
7660 ok( hr == S_OK, "got 0x%08x\n", hr);
7662 hr = IXMLDOMElement_get_prefix(element, NULL);
7663 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
7665 str = (void*)0xdeadbeef;
7666 hr = IXMLDOMElement_get_prefix(element, &str);
7667 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7668 ok( str == 0, "got %p\n", str);
7670 IXMLDOMElement_Release(element);
7673 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
7674 ok( hr == S_OK, "got 0x%08x\n", hr);
7676 str = (void*)0xdeadbeef;
7677 hr = IXMLDOMElement_get_prefix(element, &str);
7678 ok( hr == S_OK, "got 0x%08x\n", hr);
7679 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
7682 str = (void*)0xdeadbeef;
7683 hr = IXMLDOMElement_get_namespaceURI(element, &str);
7684 ok( hr == S_FALSE, "got 0x%08x\n", hr);
7685 ok( str == 0, "got %p\n", str);
7687 IXMLDOMElement_Release(element);
7689 IXMLDOMDocument_Release(doc);
7693 static void test_selectSingleNode(void)
7695 IXMLDOMDocument *doc;
7696 IXMLDOMNodeList *list;
7703 doc = create_document(&IID_IXMLDOMDocument);
7706 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
7707 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7709 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
7710 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7712 str = SysAllocString( szComplete4 );
7713 hr = IXMLDOMDocument_loadXML( doc, str, &b );
7714 ok( hr == S_OK, "loadXML failed\n");
7715 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7716 SysFreeString( str );
7718 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
7719 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7721 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
7722 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7724 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
7725 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7727 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
7728 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7730 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
7731 ok(hr == S_OK, "got 0x%08x\n", hr);
7732 IXMLDOMNode_Release(node);
7734 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
7735 ok(hr == S_OK, "got 0x%08x\n", hr);
7736 IXMLDOMNodeList_Release(list);
7738 list = (void*)0xdeadbeef;
7739 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
7740 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7741 ok(list == (void*)0xdeadbeef, "got %p\n", list);
7743 node = (void*)0xdeadbeef;
7744 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
7745 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7746 ok(node == 0, "got %p\n", node);
7748 list = (void*)0xdeadbeef;
7749 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
7750 ok(hr == S_OK, "got 0x%08x\n", hr);
7752 hr = IXMLDOMNodeList_get_length(list, &len);
7753 ok(hr == S_OK, "got 0x%08x\n", hr);
7754 ok(len == 0, "got %d\n", len);
7755 IXMLDOMNodeList_Release(list);
7757 IXMLDOMDocument_Release(doc);
7761 static void test_events(void)
7763 IConnectionPointContainer *conn;
7764 IConnectionPoint *point;
7765 IXMLDOMDocument *doc;
7770 doc = create_document(&IID_IXMLDOMDocument);
7773 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&conn);
7774 ok(hr == S_OK, "got 0x%08x\n", hr);
7776 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IDispatch, &point);
7777 ok(hr == S_OK, "got 0x%08x\n", hr);
7778 IConnectionPoint_Release(point);
7779 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IPropertyNotifySink, &point);
7780 ok(hr == S_OK, "got 0x%08x\n", hr);
7781 IConnectionPoint_Release(point);
7782 hr = IConnectionPointContainer_FindConnectionPoint(conn, &DIID_XMLDOMDocumentEvents, &point);
7783 ok(hr == S_OK, "got 0x%08x\n", hr);
7784 IConnectionPoint_Release(point);
7786 IConnectionPointContainer_Release(conn);
7788 /* ready state callback */
7790 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
7791 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
7793 event = create_dispevent();
7794 V_VT(&v) = VT_UNKNOWN;
7795 V_UNKNOWN(&v) = (IUnknown*)event;
7797 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
7798 ok(hr == S_OK, "got 0x%08x\n", hr);
7799 EXPECT_REF(event, 2);
7801 V_VT(&v) = VT_DISPATCH;
7802 V_DISPATCH(&v) = event;
7804 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
7805 ok(hr == S_OK, "got 0x%08x\n", hr);
7806 EXPECT_REF(event, 2);
7808 /* VT_NULL doesn't reset event handler */
7810 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
7811 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
7812 EXPECT_REF(event, 2);
7814 V_VT(&v) = VT_DISPATCH;
7815 V_DISPATCH(&v) = NULL;
7817 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
7818 ok(hr == S_OK, "got 0x%08x\n", hr);
7819 EXPECT_REF(event, 1);
7821 V_VT(&v) = VT_UNKNOWN;
7822 V_DISPATCH(&v) = NULL;
7823 hr = IXMLDOMDocument_put_onreadystatechange(doc, v);
7824 ok(hr == S_OK, "got 0x%08x\n", hr);
7826 IDispatch_Release(event);
7828 IXMLDOMDocument_Release(doc);
7831 static void test_createProcessingInstruction(void)
7833 static const WCHAR bodyW[] = {'t','e','s','t',0};
7834 IXMLDOMProcessingInstruction *pi;
7835 IXMLDOMDocument *doc;
7839 doc = create_document(&IID_IXMLDOMDocument);
7842 /* test for BSTR handling, pass broken BSTR */
7843 memcpy(&buff[2], bodyW, sizeof(bodyW));
7844 /* just a big length */
7845 *(DWORD*)buff = 0xf0f0;
7846 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("test"), &buff[2], &pi);
7847 ok(hr == S_OK, "got 0x%08x\n", hr);
7849 IXMLDOMProcessingInstruction_Release(pi);
7850 IXMLDOMDocument_Release(doc);
7853 static void test_put_nodeTypedValue(void)
7855 IXMLDOMDocument *doc;
7856 IXMLDOMElement *elem;
7860 doc = create_document(&IID_IXMLDOMDocument);
7863 hr = IXMLDOMDocument_createElement(doc, _bstr_("Element"), &elem);
7864 ok(hr == S_OK, "got 0x%08x\n", hr);
7866 V_VT(&type) = VT_EMPTY;
7867 hr = IXMLDOMElement_get_dataType(elem, &type);
7868 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7869 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
7871 /* set typed value for untyped node */
7872 V_VT(&type) = VT_I1;
7874 hr = IXMLDOMElement_put_nodeTypedValue(elem, type);
7875 ok(hr == S_OK, "got 0x%08x\n", hr);
7877 V_VT(&type) = VT_EMPTY;
7878 hr = IXMLDOMElement_get_dataType(elem, &type);
7879 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7880 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
7882 /* no type info stored */
7883 V_VT(&type) = VT_EMPTY;
7884 hr = IXMLDOMElement_get_nodeTypedValue(elem, &type);
7885 ok(hr == S_OK, "got 0x%08x\n", hr);
7886 ok(V_VT(&type) == VT_BSTR, "got %d, expected VT_BSTR\n", V_VT(&type));
7887 ok(memcmp(V_BSTR(&type), _bstr_("1"), 2*sizeof(WCHAR)) == 0,
7888 "got %s, expected \"1\"\n", wine_dbgstr_w(V_BSTR(&type)));
7889 VariantClear(&type);
7891 IXMLDOMElement_Release(elem);
7892 IXMLDOMDocument_Release(doc);
7896 static void test_get_xml(void)
7898 static const char xmlA[] = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<a>test</a>\r\n";
7899 IXMLDOMProcessingInstruction *pi;
7901 IXMLDOMDocument *doc;
7907 doc = create_document(&IID_IXMLDOMDocument);
7911 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
7912 ok(hr == S_OK, "got 0x%08x\n", hr);
7913 ok( b == VARIANT_TRUE, "got %d\n", b);
7915 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"),
7916 _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &pi);
7917 ok(hr == S_OK, "got 0x%08x\n", hr);
7919 hr = IXMLDOMDocument_get_firstChild(doc, &first);
7920 ok(hr == S_OK, "got 0x%08x\n", hr);
7922 V_UNKNOWN(&v) = (IUnknown*)first;
7923 V_VT(&v) = VT_UNKNOWN;
7925 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)pi, v, NULL);
7926 ok(hr == S_OK, "got 0x%08x\n", hr);
7928 IXMLDOMProcessingInstruction_Release(pi);
7929 IXMLDOMNode_Release(first);
7931 hr = IXMLDOMDocument_get_xml(doc, &xml);
7932 ok(hr == S_OK, "got 0x%08x\n", hr);
7934 ok(memcmp(xml, _bstr_(xmlA), sizeof(xmlA)*sizeof(WCHAR)) == 0,
7935 "got %s, expected %s\n", wine_dbgstr_w(xml), xmlA);
7938 IXMLDOMDocument_Release(doc);
7942 static void test_xsltemplate(void)
7944 IXSLTemplate *template;
7945 IXSLProcessor *processor;
7946 IXMLDOMDocument *doc, *doc2;
7953 template = create_xsltemplate(&IID_IXSLTemplate);
7954 if (!template) return;
7956 /* works as reset */
7957 hr = IXSLTemplate_putref_stylesheet(template, NULL);
7958 ok(hr == S_OK, "got 0x%08x\n", hr);
7960 doc = create_document(&IID_IXMLDOMDocument);
7963 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
7964 ok(hr == S_OK, "got 0x%08x\n", hr);
7965 ok( b == VARIANT_TRUE, "got %d\n", b);
7967 /* putref with non-xsl document */
7968 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
7969 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
7972 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
7973 ok(hr == S_OK, "got 0x%08x\n", hr);
7974 ok( b == VARIANT_TRUE, "got %d\n", b);
7976 /* not a freethreaded document */
7977 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
7978 todo_wine ok(hr == E_FAIL, "got 0x%08x\n", hr);
7980 IXMLDOMDocument_Release(doc);
7982 hr = CoCreateInstance(&CLSID_FreeThreadedDOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc);
7985 win_skip("failed to create free threaded document instance: 0x%08x\n", hr);
7986 IXSLTemplate_Release(template);
7991 hr = IXMLDOMDocument_loadXML( doc, _bstr_(szTransformSSXML), &b );
7992 ok(hr == S_OK, "got 0x%08x\n", hr);
7993 ok( b == VARIANT_TRUE, "got %d\n", b);
7995 /* freethreaded document */
7996 ref1 = IXMLDOMDocument_AddRef(doc);
7997 IXMLDOMDocument_Release(doc);
7998 hr = IXSLTemplate_putref_stylesheet(template, (IXMLDOMNode*)doc);
7999 ok(hr == S_OK, "got 0x%08x\n", hr);
8000 ref2 = IXMLDOMDocument_AddRef(doc);
8001 IXMLDOMDocument_Release(doc);
8002 ok(ref2 > ref1, "got %d\n", ref2);
8005 hr = IXSLTemplate_createProcessor(template, NULL);
8006 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8008 EXPECT_REF(template, 1);
8009 hr = IXSLTemplate_createProcessor(template, &processor);
8010 ok(hr == S_OK, "got 0x%08x\n", hr);
8011 EXPECT_REF(template, 2);
8013 /* input no set yet */
8016 hr = IXSLProcessor_get_input(processor, &v);
8018 ok(hr == S_OK, "got 0x%08x\n", hr);
8019 ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
8022 hr = IXSLProcessor_get_output(processor, NULL);
8023 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8025 /* reset before it was set */
8026 V_VT(&v) = VT_EMPTY;
8027 hr = IXSLProcessor_put_output(processor, v);
8028 ok(hr == S_OK, "got 0x%08x\n", hr);
8030 CreateStreamOnHGlobal(NULL, TRUE, &stream);
8031 EXPECT_REF(stream, 1);
8033 V_VT(&v) = VT_UNKNOWN;
8034 V_UNKNOWN(&v) = (IUnknown*)stream;
8035 hr = IXSLProcessor_put_output(processor, v);
8036 ok(hr == S_OK, "got 0x%08x\n", hr);
8038 /* it seems processor grabs 2 references */
8039 todo_wine EXPECT_REF(stream, 3);
8041 V_VT(&v) = VT_EMPTY;
8042 hr = IXSLProcessor_get_output(processor, &v);
8043 ok(hr == S_OK, "got 0x%08x\n", hr);
8044 ok(V_VT(&v) == VT_UNKNOWN, "got type %d\n", V_VT(&v));
8045 ok(V_UNKNOWN(&v) == (IUnknown*)stream, "got %p\n", V_UNKNOWN(&v));
8047 todo_wine EXPECT_REF(stream, 4);
8050 hr = IXSLProcessor_transform(processor, NULL);
8051 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8053 /* reset and check stream refcount */
8054 V_VT(&v) = VT_EMPTY;
8055 hr = IXSLProcessor_put_output(processor, v);
8056 ok(hr == S_OK, "got 0x%08x\n", hr);
8058 EXPECT_REF(stream, 1);
8060 IStream_Release(stream);
8062 /* no output interface set, check output */
8063 doc2 = create_document(&IID_IXMLDOMDocument);
8066 hr = IXMLDOMDocument_loadXML( doc2, _bstr_("<a>test</a>"), &b );
8067 ok(hr == S_OK, "got 0x%08x\n", hr);
8068 ok( b == VARIANT_TRUE, "got %d\n", b);
8070 V_VT(&v) = VT_UNKNOWN;
8071 V_UNKNOWN(&v) = (IUnknown*)doc2;
8072 hr = IXSLProcessor_put_input(processor, v);
8073 ok(hr == S_OK, "got 0x%08x\n", hr);
8075 hr = IXSLProcessor_transform(processor, &b);
8076 ok(hr == S_OK, "got 0x%08x\n", hr);
8078 V_VT(&v) = VT_EMPTY;
8079 hr = IXSLProcessor_get_output(processor, &v);
8080 ok(hr == S_OK, "got 0x%08x\n", hr);
8081 ok(V_VT(&v) == VT_BSTR, "got type %d\n", V_VT(&v));
8082 /* we currently output one '\n' instead of empty string */
8083 todo_wine ok(lstrcmpW(V_BSTR(&v), _bstr_("")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8084 IXMLDOMDocument_Release(doc2);
8087 IXSLProcessor_Release(processor);
8089 /* drop reference */
8090 hr = IXSLTemplate_putref_stylesheet(template, NULL);
8091 ok(hr == S_OK, "got 0x%08x\n", hr);
8092 ref2 = IXMLDOMDocument_AddRef(doc);
8093 IXMLDOMDocument_Release(doc);
8094 ok(ref2 == ref1, "got %d\n", ref2);
8096 IXMLDOMDocument_Release(doc);
8097 IXSLTemplate_Release(template);
8101 static void test_insertBefore(void)
8103 IXMLDOMDocument *doc, *doc2;
8104 IXMLDOMAttribute *attr;
8105 IXMLDOMElement *elem1, *elem2, *elem3, *elem4, *elem5;
8106 IXMLDOMNode *node, *newnode;
8111 doc = create_document(&IID_IXMLDOMDocument);
8113 /* insertBefore behaviour for attribute node */
8115 V_I4(&v) = NODE_ATTRIBUTE;
8118 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr"), NULL, (IXMLDOMNode**)&attr);
8119 ok(hr == S_OK, "got 0x%08x\n", hr);
8120 ok(attr != NULL, "got %p\n", attr);
8122 /* attribute to attribute */
8124 V_I4(&v) = NODE_ATTRIBUTE;
8126 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("attr2"), NULL, &newnode);
8127 ok(hr == S_OK, "got 0x%08x\n", hr);
8128 ok(newnode != NULL, "got %p\n", newnode);
8131 node = (void*)0xdeadbeef;
8132 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8133 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8134 ok(node == NULL, "got %p\n", node);
8136 V_VT(&v) = VT_UNKNOWN;
8137 V_UNKNOWN(&v) = (IUnknown*)attr;
8138 node = (void*)0xdeadbeef;
8139 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8140 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8141 ok(node == NULL, "got %p\n", node);
8142 IXMLDOMNode_Release(newnode);
8144 /* cdata to attribute */
8146 V_I4(&v) = NODE_CDATA_SECTION;
8148 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8149 ok(hr == S_OK, "got 0x%08x\n", hr);
8150 ok(newnode != NULL, "got %p\n", newnode);
8153 node = (void*)0xdeadbeef;
8154 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8155 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8156 ok(node == NULL, "got %p\n", node);
8157 IXMLDOMNode_Release(newnode);
8159 /* comment to attribute */
8161 V_I4(&v) = NODE_COMMENT;
8163 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8164 ok(hr == S_OK, "got 0x%08x\n", hr);
8165 ok(newnode != NULL, "got %p\n", newnode);
8168 node = (void*)0xdeadbeef;
8169 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8170 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8171 ok(node == NULL, "got %p\n", node);
8172 IXMLDOMNode_Release(newnode);
8174 /* element to attribute */
8176 V_I4(&v) = NODE_ELEMENT;
8178 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8179 ok(hr == S_OK, "got 0x%08x\n", hr);
8180 ok(newnode != NULL, "got %p\n", newnode);
8183 node = (void*)0xdeadbeef;
8184 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8185 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8186 ok(node == NULL, "got %p\n", node);
8187 IXMLDOMNode_Release(newnode);
8189 /* pi to attribute */
8191 V_I4(&v) = NODE_PROCESSING_INSTRUCTION;
8193 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("cdata"), NULL, &newnode);
8194 ok(hr == S_OK, "got 0x%08x\n", hr);
8195 ok(newnode != NULL, "got %p\n", newnode);
8198 node = (void*)0xdeadbeef;
8199 hr = IXMLDOMAttribute_insertBefore(attr, newnode, v, &node);
8200 ok(hr == E_FAIL, "got 0x%08x\n", hr);
8201 ok(node == NULL, "got %p\n", node);
8202 IXMLDOMNode_Release(newnode);
8203 IXMLDOMAttribute_Release(attr);
8205 /* insertBefore for elements */
8206 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem1);
8207 ok(hr == S_OK, "got 0x%08x\n", hr);
8209 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem2"), &elem2);
8210 ok(hr == S_OK, "got 0x%08x\n", hr);
8212 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem3"), &elem3);
8213 ok(hr == S_OK, "got 0x%08x\n", hr);
8215 EXPECT_NO_CHILDREN(elem1);
8216 EXPECT_NO_CHILDREN(elem2);
8217 EXPECT_NO_CHILDREN(elem3);
8219 todo_wine EXPECT_REF(elem2, 2);
8223 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
8224 ok(hr == S_OK, "got 0x%08x\n", hr);
8225 ok(node == (void*)elem2, "got %p\n", node);
8227 EXPECT_CHILDREN(elem1);
8228 todo_wine EXPECT_REF(elem2, 3);
8229 IXMLDOMNode_Release(node);
8231 /* again for already linked node */
8234 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, &node);
8235 ok(hr == S_OK, "got 0x%08x\n", hr);
8236 ok(node == (void*)elem2, "got %p\n", node);
8238 EXPECT_CHILDREN(elem1);
8240 /* increments each time */
8241 todo_wine EXPECT_REF(elem2, 3);
8242 IXMLDOMNode_Release(node);
8244 /* try to add to another element */
8246 node = (void*)0xdeadbeef;
8247 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem2, v, &node);
8248 ok(hr == S_OK, "got 0x%08x\n", hr);
8249 ok(node == (void*)elem2, "got %p\n", node);
8251 EXPECT_CHILDREN(elem3);
8252 EXPECT_NO_CHILDREN(elem1);
8254 IXMLDOMNode_Release(node);
8256 /* cross document case - try to add as child to a node created with other doc */
8257 doc2 = create_document(&IID_IXMLDOMDocument);
8259 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem4);
8260 ok(hr == S_OK, "got 0x%08x\n", hr);
8261 todo_wine EXPECT_REF(elem4, 2);
8263 /* same name, another instance */
8264 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem4"), &elem5);
8265 ok(hr == S_OK, "got 0x%08x\n", hr);
8266 todo_wine EXPECT_REF(elem5, 2);
8268 todo_wine EXPECT_REF(elem3, 2);
8271 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem4, v, &node);
8272 ok(hr == S_OK, "got 0x%08x\n", hr);
8273 ok(node == (void*)elem4, "got %p\n", node);
8274 todo_wine EXPECT_REF(elem4, 3);
8275 todo_wine EXPECT_REF(elem3, 2);
8276 IXMLDOMNode_Release(node);
8280 hr = IXMLDOMElement_insertBefore(elem3, (IXMLDOMNode*)elem5, v, &node);
8281 ok(hr == S_OK, "got 0x%08x\n", hr);
8282 ok(node == (void*)elem5, "got %p\n", node);
8283 todo_wine EXPECT_REF(elem4, 2);
8284 todo_wine EXPECT_REF(elem5, 3);
8285 IXMLDOMNode_Release(node);
8287 IXMLDOMDocument_Release(doc2);
8289 IXMLDOMElement_Release(elem1);
8290 IXMLDOMElement_Release(elem2);
8291 IXMLDOMElement_Release(elem3);
8292 IXMLDOMElement_Release(elem4);
8293 IXMLDOMElement_Release(elem5);
8295 /* elements with same default namespace */
8297 V_I4(&v) = NODE_ELEMENT;
8299 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
8300 ok(hr == S_OK, "got 0x%08x\n", hr);
8301 ok(elem1 != NULL, "got %p\n", elem1);
8304 V_I4(&v) = NODE_ELEMENT;
8306 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem2);
8307 ok(hr == S_OK, "got 0x%08x\n", hr);
8308 ok(elem2 != NULL, "got %p\n", elem2);
8310 /* check contents so far */
8312 hr = IXMLDOMElement_get_xml(elem1, &p);
8313 ok(hr == S_OK, "got 0x%08x\n", hr);
8314 ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
8318 hr = IXMLDOMElement_get_xml(elem2, &p);
8319 ok(hr == S_OK, "got 0x%08x\n", hr);
8320 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
8324 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
8325 ok(hr == S_OK, "got 0x%08x\n", hr);
8327 /* get_xml depends on context, for top node it omits child namespace attribute,
8328 but at child level it's still returned */
8330 hr = IXMLDOMElement_get_xml(elem1, &p);
8331 ok(hr == S_OK, "got 0x%08x\n", hr);
8332 todo_wine ok(!lstrcmpW(p, _bstr_("<elem1 xmlns=\"http://winehq.org/default\"><elem2/></elem1>")),
8333 "got %s\n", wine_dbgstr_w(p));
8337 hr = IXMLDOMElement_get_xml(elem2, &p);
8338 ok(hr == S_OK, "got 0x%08x\n", hr);
8339 ok(!lstrcmpW(p, _bstr_("<elem2 xmlns=\"http://winehq.org/default\"/>")), "got %s\n", wine_dbgstr_w(p));
8342 IXMLDOMElement_Release(elem1);
8343 IXMLDOMElement_Release(elem2);
8345 /* child without default namespace added to node with default namespace */
8347 V_I4(&v) = NODE_ELEMENT;
8349 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem1"), _bstr_("http://winehq.org/default"), (IXMLDOMNode**)&elem1);
8350 ok(hr == S_OK, "got 0x%08x\n", hr);
8351 ok(elem1 != NULL, "got %p\n", elem1);
8354 V_I4(&v) = NODE_ELEMENT;
8356 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("elem2"), NULL, (IXMLDOMNode**)&elem2);
8357 ok(hr == S_OK, "got 0x%08x\n", hr);
8358 ok(elem2 != NULL, "got %p\n", elem2);
8360 EXPECT_REF(elem2, 1);
8362 hr = IXMLDOMElement_insertBefore(elem1, (IXMLDOMNode*)elem2, v, NULL);
8363 ok(hr == S_OK, "got 0x%08x\n", hr);
8364 EXPECT_REF(elem2, 1);
8367 hr = IXMLDOMElement_get_xml(elem2, &p);
8368 ok(hr == S_OK, "got 0x%08x\n", hr);
8369 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
8372 hr = IXMLDOMElement_removeChild(elem1, (IXMLDOMNode*)elem2, NULL);
8373 ok(hr == S_OK, "got 0x%08x\n", hr);
8376 hr = IXMLDOMElement_get_xml(elem2, &p);
8377 ok(hr == S_OK, "got 0x%08x\n", hr);
8378 ok(!lstrcmpW(p, _bstr_("<elem2/>")), "got %s\n", wine_dbgstr_w(p));
8381 IXMLDOMElement_Release(elem1);
8382 IXMLDOMElement_Release(elem2);
8383 IXMLDOMDocument_Release(doc);
8386 static void test_appendChild(void)
8388 IXMLDOMDocument *doc, *doc2;
8389 IXMLDOMElement *elem, *elem2;
8392 doc = create_document(&IID_IXMLDOMDocument);
8393 doc2 = create_document(&IID_IXMLDOMDocument);
8395 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &elem);
8396 ok(hr == S_OK, "got 0x%08x\n", hr);
8398 hr = IXMLDOMDocument_createElement(doc2, _bstr_("elem2"), &elem2);
8399 ok(hr == S_OK, "got 0x%08x\n", hr);
8402 todo_wine EXPECT_REF(elem, 2);
8403 EXPECT_REF(doc2, 1);
8404 todo_wine EXPECT_REF(elem2, 2);
8405 EXPECT_NO_CHILDREN(doc);
8406 EXPECT_NO_CHILDREN(doc2);
8408 /* append from another document */
8409 hr = IXMLDOMDocument_appendChild(doc2, (IXMLDOMNode*)elem, NULL);
8410 ok(hr == S_OK, "got 0x%08x\n", hr);
8413 todo_wine EXPECT_REF(elem, 2);
8414 EXPECT_REF(doc2, 1);
8415 todo_wine EXPECT_REF(elem2, 2);
8416 EXPECT_NO_CHILDREN(doc);
8417 EXPECT_CHILDREN(doc2);
8419 IXMLDOMElement_Release(elem);
8420 IXMLDOMElement_Release(elem2);
8421 IXMLDOMDocument_Release(doc);
8422 IXMLDOMDocument_Release(doc2);
8425 static void test_get_doctype(void)
8427 IXMLDOMDocumentType *doctype;
8428 IXMLDOMDocument *doc;
8431 doc = create_document(&IID_IXMLDOMDocument);
8433 hr = IXMLDOMDocument_get_doctype(doc, NULL);
8434 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8436 doctype = (void*)0xdeadbeef;
8437 hr = IXMLDOMDocument_get_doctype(doc, &doctype);
8438 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8439 ok(doctype == NULL, "got %p\n", doctype);
8441 IXMLDOMDocument_Release(doc);
8446 IXMLDOMDocument *doc;
8449 hr = CoInitialize( NULL );
8450 ok( hr == S_OK, "failed to init com\n");
8456 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc );
8459 win_skip("IXMLDOMDocument is not available (0x%08x)\n", hr);
8463 IXMLDOMDocument_Release(doc);
8466 test_persiststreaminit();
8470 test_getElementsByTagName();
8472 test_get_childNodes();
8473 test_get_firstChild();
8474 test_get_lastChild();
8476 test_replaceChild();
8477 test_removeNamedItem();
8478 test_IXMLDOMDocument2();
8484 test_nodeTypeTests();
8485 test_DocumentSaveToDocument();
8486 test_DocumentSaveToFile();
8487 test_testTransforms();
8489 test_FormattingXML();
8490 test_nodeTypedValue();
8491 test_TransformWithLoadingLocalFile();
8492 test_put_nodeValue();
8493 test_document_IObjectSafety();
8495 test_getQualifiedItem();
8496 test_removeQualifiedItem();
8497 test_get_ownerDocument();
8498 test_setAttributeNode();
8499 test_put_dataType();
8502 test_default_properties();
8503 test_selectSingleNode();
8505 test_createProcessingInstruction();
8506 test_put_nodeTypedValue();
8508 test_insertBefore();