4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 const CLSID CLSID_DOMDocument2 = {0xf6d90f11, 0x9c73, 0x11d3, {0xb3, 0x2e, 0x00, 0xc0, 0x4f, 0x99, 0x0b, 0xb4}};
35 const IID IID_IXMLDOMDocument2 = {0x2933bf95, 0x7b36, 0x11d2, {0xb2, 0x0e, 0x00, 0xc0, 0x4f, 0x98, 0x3e, 0x60}};
37 static const WCHAR szEmpty[] = { 0 };
38 static const WCHAR szIncomplete[] = {
39 '<','?','x','m','l',' ',
40 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
42 static const WCHAR szComplete1[] = {
43 '<','?','x','m','l',' ',
44 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
45 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
47 static const WCHAR szComplete2[] = {
48 '<','?','x','m','l',' ',
49 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
50 '<','o','>','<','/','o','>','\n',0
52 static const WCHAR szComplete3[] = {
53 '<','?','x','m','l',' ',
54 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
55 '<','a','>','<','/','a','>','\n',0
57 static const WCHAR szComplete4[] = {
58 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
59 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
60 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
61 'f','n','1','.','t','x','t','\n',
62 '<','/','b','s','>','\n',
63 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
64 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
65 'f','n','2','.','t','x','t','\n',
66 '<','/','p','r','>','\n',
67 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
71 '<','/','b','a','>','\n',
72 '<','/','f','o','>','\n',
73 '<','/','l','c','>','\n',0
75 static const WCHAR szComplete5[] = {
76 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
77 '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','"',
78 ' ','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','"','>',
79 '<','S',':','s','c','o','p','e','>',
80 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
81 '<','/','S',':','s','c','o','p','e','>',
82 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
83 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
84 'c','o','m','p','u','t','e','r',
85 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
86 '<','/','S',':','s','e','a','r','c','h','>',0
89 static const CHAR szExampleXML[] =
90 "<?xml version='1.0' encoding='utf-8'?>\n"
91 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
96 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
97 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
98 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
106 " <c type=\"old\">C2 field</c>\n"
109 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
118 " <foo:c>C4 field</foo:c>\n"
122 static const CHAR szTransformXML[] =
123 "<?xml version=\"1.0\"?>\n"
128 static const CHAR szTransformSSXML[] =
129 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
130 " <xsl:output method=\"html\"/>\n"
131 " <xsl:template match=\"/\">\n"
132 " <xsl:apply-templates select=\"greeting\"/>\n"
134 " <xsl:template match=\"greeting\">\n"
138 " <xsl:value-of select=\".\"/>\n"
145 static const CHAR szTransformOutput[] =
148 "</h1></body></html>";
150 static const WCHAR szNonExistentFile[] = {
151 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
153 static const WCHAR szDocument[] = {
154 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
157 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
158 static WCHAR szdl[] = { 'd','l',0 };
159 static const WCHAR szvr[] = { 'v','r',0 };
160 static const WCHAR szlc[] = { 'l','c',0 };
161 static WCHAR szbs[] = { 'b','s',0 };
162 static const WCHAR szstr1[] = { 's','t','r','1',0 };
163 static const WCHAR szstr2[] = { 's','t','r','2',0 };
164 static const WCHAR szstar[] = { '*',0 };
165 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
167 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
168 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
169 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
171 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
172 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
173 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
174 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
175 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
177 static WCHAR szAttribute[] = {'A','t','t','r',0 };
178 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
180 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
181 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
182 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
183 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
185 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
186 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
188 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
189 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
191 #define expect_bstr_eq_and_free(bstr, expect) { \
192 BSTR bstrExp = alloc_str_from_narrow(expect); \
193 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
194 SysFreeString(bstr); \
195 SysFreeString(bstrExp); \
198 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
200 #define ole_check(expr) { \
202 ok(r == S_OK, #expr " returned %x\n", r); \
205 #define ole_expect(expr, expect) { \
207 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
210 static BSTR alloc_str_from_narrow(const char *str)
212 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
213 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
214 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
218 BSTR alloced_bstrs[256];
219 int alloced_bstrs_count = 0;
221 static BSTR _bstr_(const char *str)
223 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
224 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
225 return alloced_bstrs[alloced_bstrs_count++];
228 static void free_bstrs(void)
231 for (i = 0; i < alloced_bstrs_count; i++)
232 SysFreeString(alloced_bstrs[i]);
233 alloced_bstrs_count = 0;
236 static VARIANT _variantbstr_(const char *str)
240 V_BSTR(&v) = _bstr_(str);
244 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
248 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
249 while (*sRight == '\r' || *sRight == '\n') sRight++;
250 if (*sLeft != *sRight) return FALSE;
251 if (!*sLeft) return TRUE;
257 static void get_str_for_type(DOMNodeType type, char *buf)
271 wsprintfA(buf, "[%d]", type);
275 static int get_node_position(IXMLDOMNode *node)
280 IXMLDOMNode_AddRef(node);
283 IXMLDOMNode *new_node;
286 r = IXMLDOMNode_get_previousSibling(node, &new_node);
287 ok(!FAILED(r), "get_previousSibling failed\n");
288 IXMLDOMNode_Release(node);
294 static void node_to_string(IXMLDOMNode *node, char *buf)
301 lstrcpyA(buf, "(null)");
305 IXMLDOMNode_AddRef(node);
308 IXMLDOMNode *new_node;
310 ole_check(IXMLDOMNode_get_nodeType(node, &type));
311 get_str_for_type(type, buf);
314 if (type == NODE_ATTRIBUTE)
317 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
319 wsprintfA(buf, "%ws", bstr);
324 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
328 int pos = get_node_position(node);
329 DOMNodeType parent_type = NODE_INVALID;
330 r = IXMLDOMNode_get_parentNode(node, &new_node);
332 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
333 * results we "fix" it */
335 ole_check(IXMLDOMNode_get_nodeType(node, &parent_type));
336 /* we need also to workaround the no document node problem - see below */
337 if (((r == S_FALSE && type != NODE_DOCUMENT) || parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
339 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
342 wsprintf(buf, "%d", pos);
346 ok(!FAILED(r), "get_parentNode failed (%08x)\n", r);
347 IXMLDOMNode_Release(node);
353 /* currently we can't access document node in wine. All our examples this is the
354 * root node so to be able to test query results we add it */
355 if (type != NODE_DOCUMENT)
357 todo_wine ok(FALSE, "Document node is not the last returned node!\n");
365 static char *list_to_string(IXMLDOMNodeList *list)
367 static char buf[4096];
374 lstrcpyA(buf, "(null)");
377 ole_check(IXMLDOMNodeList_get_length(list, &len));
378 for (i = 0; i < len; i++)
383 ole_check(IXMLDOMNodeList_nextNode(list, &node));
384 node_to_string(node, pos);
386 IXMLDOMNode_Release(node);
392 #define expect_node(node, expstr) { char str[4096]; node_to_string(node, str); ok(strcmp(str, expstr)==0, "Invalid node: %s, exptected %s\n", str, expstr); }
393 #define expect_list_and_release(list, expstr) { char *str = list_to_string(list); ok(strcmp(str, expstr)==0, "Invalid node list: %s, exptected %s\n", str, expstr); if (list) IXMLDOMNodeList_Release(list); }
395 static void test_domdoc( void )
398 IXMLDOMDocument *doc = NULL;
399 IXMLDOMParseError *error;
400 IXMLDOMElement *element = NULL;
402 IXMLDOMText *nodetext = NULL;
403 IXMLDOMComment *node_comment = NULL;
404 IXMLDOMAttribute *node_attr = NULL;
405 IXMLDOMNode *nodeChild = NULL;
406 IXMLDOMProcessingInstruction *nodePI = NULL;
413 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
414 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
418 /* try some stupid things */
419 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
420 ok( r == S_FALSE, "loadXML failed\n");
423 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
424 ok( r == S_FALSE, "loadXML failed\n");
425 ok( b == VARIANT_FALSE, "failed to load XML string\n");
427 /* try to load a document from a nonexistent file */
429 str = SysAllocString( szNonExistentFile );
431 V_VT(&var) = VT_BSTR;
434 r = IXMLDOMDocument_load( doc, var, &b);
435 ok( r == S_FALSE, "load (from file) failed\n");
436 ok( b == VARIANT_FALSE, "failed to load XML file\n");
437 SysFreeString( str );
439 /* try load an empty document */
441 str = SysAllocString( szEmpty );
442 r = IXMLDOMDocument_loadXML( doc, str, &b );
443 ok( r == S_FALSE, "loadXML failed\n");
444 ok( b == VARIANT_FALSE, "failed to load XML string\n");
445 SysFreeString( str );
447 /* check that there's no document element */
449 r = IXMLDOMDocument_get_documentElement( doc, &element );
450 ok( r == S_FALSE, "should be no document element\n");
452 /* try finding a node */
454 str = SysAllocString( szstr1 );
455 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
456 ok( r == S_FALSE, "ret %08x\n", r );
457 SysFreeString( str );
460 str = SysAllocString( szIncomplete );
461 r = IXMLDOMDocument_loadXML( doc, str, &b );
462 ok( r == S_FALSE, "loadXML failed\n");
463 ok( b == VARIANT_FALSE, "failed to load XML string\n");
464 SysFreeString( str );
466 /* check that there's no document element */
467 element = (IXMLDOMElement*)1;
468 r = IXMLDOMDocument_get_documentElement( doc, &element );
469 ok( r == S_FALSE, "should be no document element\n");
470 ok( element == NULL, "Element should be NULL\n");
472 /* try to load something valid */
474 str = SysAllocString( szComplete1 );
475 r = IXMLDOMDocument_loadXML( doc, str, &b );
476 ok( r == S_OK, "loadXML failed\n");
477 ok( b == VARIANT_TRUE, "failed to load XML string\n");
478 SysFreeString( str );
480 /* check if nodename is correct */
481 r = IXMLDOMDocument_get_nodeName( doc, NULL );
482 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
484 /* content doesn't matter here */
486 r = IXMLDOMDocument_get_nodeName( doc, &str );
487 ok ( r == S_OK, "get_nodeName wrong code\n");
488 ok ( str != NULL, "str is null\n");
489 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
490 SysFreeString( str );
493 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
494 ok( r == E_FAIL, "ret %08x\n", r );
496 /* check that there's a document element */
498 r = IXMLDOMDocument_get_documentElement( doc, &element );
499 ok( r == S_OK, "should be a document element\n");
504 /* check if the tag is correct */
505 r = IXMLDOMElement_get_tagName( element, &tag );
506 ok( r == S_OK, "couldn't get tag name\n");
507 ok( tag != NULL, "tag was null\n");
508 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
509 SysFreeString( tag );
511 /* figure out what happens if we try to reload the document */
512 str = SysAllocString( szComplete2 );
513 r = IXMLDOMDocument_loadXML( doc, str, &b );
514 ok( r == S_OK, "loadXML failed\n");
515 ok( b == VARIANT_TRUE, "failed to load XML string\n");
516 SysFreeString( str );
518 /* check if the tag is still correct */
520 r = IXMLDOMElement_get_tagName( element, &tag );
521 ok( r == S_OK, "couldn't get tag name\n");
522 ok( tag != NULL, "tag was null\n");
523 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
524 SysFreeString( tag );
526 IXMLDOMElement_Release( element );
530 /* as soon as we call loadXML again, the document element will disappear */
532 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
533 ok( r == S_FALSE, "loadXML failed\n");
534 ok( b == 2, "variant modified\n");
535 r = IXMLDOMDocument_get_documentElement( doc, &element );
536 ok( r == S_FALSE, "should be no document element\n");
538 /* try to load something else simple and valid */
540 str = SysAllocString( szComplete3 );
541 r = IXMLDOMDocument_loadXML( doc, str, &b );
542 ok( r == S_OK, "loadXML failed\n");
543 ok( b == VARIANT_TRUE, "failed to load XML string\n");
544 SysFreeString( str );
546 /* try something a little more complicated */
548 str = SysAllocString( szComplete4 );
549 r = IXMLDOMDocument_loadXML( doc, str, &b );
550 ok( r == S_OK, "loadXML failed\n");
551 ok( b == VARIANT_TRUE, "failed to load XML string\n");
552 SysFreeString( str );
554 r = IXMLDOMDocument_get_parseError( doc, &error );
555 ok( r == S_OK, "returns %08x\n", r );
557 r = IXMLDOMParseError_get_errorCode( error, &code );
558 ok( r == S_FALSE, "returns %08x\n", r );
559 ok( code == 0, "code %ld\n", code );
560 IXMLDOMParseError_Release( error );
562 /* test createTextNode */
563 str = SysAllocString( szOpen );
564 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
565 ok( r == E_INVALIDARG, "returns %08x\n", r );
566 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
567 ok( r == S_OK, "returns %08x\n", r );
568 SysFreeString( str );
571 IXMLDOMNamedNodeMap *pAttribs;
573 /* Text Last Child Checks */
574 r = IXMLDOMText_get_lastChild(nodetext, NULL);
575 ok(r == E_INVALIDARG, "ret %08x\n", r );
577 nodeChild = (IXMLDOMNode*)0x1;
578 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
579 ok(r == S_FALSE, "ret %08x\n", r );
580 ok(nodeChild == NULL, "nodeChild not NULL\n");
582 /* test get_attributes */
583 r = IXMLDOMText_get_attributes( nodetext, NULL );
584 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
586 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
587 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
588 ok(r == S_FALSE, "ret %08x\n", r );
589 ok( pAttribs == NULL, "pAttribs not NULL\n");
591 /* test get_dataType */
592 r = IXMLDOMText_get_dataType(nodetext, &var);
593 ok(r == S_FALSE, "ret %08x\n", r );
594 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
597 /* test length property */
598 r = IXMLDOMText_get_length(nodetext, NULL);
599 ok(r == E_INVALIDARG, "ret %08x\n", r );
601 r = IXMLDOMText_get_length(nodetext, &nLength);
602 ok(r == S_OK, "ret %08x\n", r );
603 ok(nLength == 4, "expected 4 got %ld\n", nLength);
605 /* test nodeTypeString */
606 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
607 ok(r == S_OK, "ret %08x\n", r );
608 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
612 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
613 ok(r == S_OK, "ret %08x\n", r );
616 r = IXMLDOMText_get_data(nodetext, &str);
617 ok(r == S_OK, "ret %08x\n", r );
618 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
621 /* Confirm XML text is good */
622 r = IXMLDOMText_get_xml(nodetext, &str);
623 ok(r == S_OK, "ret %08x\n", r );
624 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
627 /* Confirm we get the put_data Text back */
628 r = IXMLDOMText_get_text(nodetext, &str);
629 ok(r == S_OK, "ret %08x\n", r );
630 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
633 /* test substringData */
634 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
635 ok(r == E_INVALIDARG, "ret %08x\n", r );
637 /* test substringData - Invalid offset */
638 str = (BSTR)&szElement;
639 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
640 ok(r == E_INVALIDARG, "ret %08x\n", r );
641 ok( str == NULL, "incorrect string\n");
643 /* test substringData - Invalid offset */
644 str = (BSTR)&szElement;
645 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
646 ok(r == S_FALSE, "ret %08x\n", r );
647 ok( str == NULL, "incorrect string\n");
649 /* test substringData - Invalid size */
650 str = (BSTR)&szElement;
651 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
652 ok(r == E_INVALIDARG, "ret %08x\n", r );
653 ok( str == NULL, "incorrect string\n");
655 /* test substringData - Invalid size */
656 str = (BSTR)&szElement;
657 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
658 ok(r == S_FALSE, "ret %08x\n", r );
659 ok( str == NULL, "incorrect string\n");
661 /* test substringData - Start of string */
662 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
663 ok(r == S_OK, "ret %08x\n", r );
664 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
667 /* test substringData - Middle of string */
668 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
669 ok(r == S_OK, "ret %08x\n", r );
670 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
673 /* test substringData - End of string */
674 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
675 ok(r == S_OK, "ret %08x\n", r );
676 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
679 /* test appendData */
680 r = IXMLDOMText_appendData(nodetext, NULL);
681 ok(r == S_OK, "ret %08x\n", r );
683 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
684 ok(r == S_OK, "ret %08x\n", r );
686 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
687 ok(r == S_OK, "ret %08x\n", r );
689 r = IXMLDOMText_get_text(nodetext, &str);
690 ok(r == S_OK, "ret %08x\n", r );
691 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
694 /* test insertData */
695 str = SysAllocStringLen(NULL, 0);
696 r = IXMLDOMText_insertData(nodetext, -1, str);
697 ok(r == S_OK, "ret %08x\n", r );
699 r = IXMLDOMText_insertData(nodetext, -1, NULL);
700 ok(r == S_OK, "ret %08x\n", r );
702 r = IXMLDOMText_insertData(nodetext, 1000, str);
703 ok(r == S_OK, "ret %08x\n", r );
705 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
706 ok(r == S_OK, "ret %08x\n", r );
708 r = IXMLDOMText_insertData(nodetext, 0, NULL);
709 ok(r == S_OK, "ret %08x\n", r );
711 r = IXMLDOMText_insertData(nodetext, 0, str);
712 ok(r == S_OK, "ret %08x\n", r );
715 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
716 ok(r == E_INVALIDARG, "ret %08x\n", r );
718 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
719 ok(r == E_INVALIDARG, "ret %08x\n", r );
721 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
722 ok(r == S_OK, "ret %08x\n", r );
724 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
725 ok(r == S_OK, "ret %08x\n", r );
727 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
728 ok(r == S_OK, "ret %08x\n", r );
730 r = IXMLDOMText_get_text(nodetext, &str);
731 ok(r == S_OK, "ret %08x\n", r );
732 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
735 IXMLDOMText_Release( nodetext );
738 /* test Create Comment */
739 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
740 ok( r == E_INVALIDARG, "returns %08x\n", r );
741 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
742 ok( r == S_OK, "returns %08x\n", r );
745 /* Last Child Checks */
746 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
747 ok(r == E_INVALIDARG, "ret %08x\n", r );
749 nodeChild = (IXMLDOMNode*)0x1;
750 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
751 ok(r == S_FALSE, "ret %08x\n", r );
752 ok(nodeChild == NULL, "pLastChild not NULL\n");
754 IXMLDOMComment_Release( node_comment );
757 /* test Create Attribute */
758 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
759 ok( r == E_INVALIDARG, "returns %08x\n", r );
760 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
761 ok( r == S_OK, "returns %08x\n", r );
762 IXMLDOMText_Release( node_attr);
764 /* test Processing Instruction */
765 str = SysAllocStringLen(NULL, 0);
766 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
767 ok( r == E_INVALIDARG, "returns %08x\n", r );
768 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
769 ok( r == E_FAIL, "returns %08x\n", r );
770 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
771 ok( r == E_FAIL, "returns %08x\n", r );
774 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
775 ok( r == S_OK, "returns %08x\n", r );
778 /* Last Child Checks */
779 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
780 ok(r == E_INVALIDARG, "ret %08x\n", r );
782 nodeChild = (IXMLDOMNode*)0x1;
783 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
784 ok(r == S_FALSE, "ret %08x\n", r );
785 ok(nodeChild == NULL, "nodeChild not NULL\n");
787 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
788 ok(r == S_FALSE, "ret %08x\n", r );
789 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
793 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
794 ok(r == S_OK, "ret %08x\n", r );
795 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
799 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
800 ok(r == S_OK, "ret %08x\n", r );
801 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
804 /* test nodeTypeString */
805 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
806 ok(r == S_OK, "ret %08x\n", r );
807 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
810 /* test get_nodeValue */
811 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
812 ok(r == S_OK, "ret %08x\n", r );
813 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
817 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
818 ok(r == S_OK, "ret %08x\n", r );
819 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
823 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
824 ok(r == E_FAIL, "ret %08x\n", r );
827 V_VT(&var) = VT_BSTR;
828 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
829 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
830 ok(r == E_FAIL, "ret %08x\n", r );
833 /* test get nodeName */
834 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
835 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
836 ok(r == S_OK, "ret %08x\n", r );
839 IXMLDOMProcessingInstruction_Release(nodePI);
842 r = IXMLDOMDocument_Release( doc );
843 ok( r == 0, "document ref count incorrect\n");
848 static void test_domnode( void )
851 IXMLDOMDocument *doc = NULL, *owner = NULL;
852 IXMLDOMElement *element = NULL;
853 IXMLDOMNamedNodeMap *map = NULL;
854 IXMLDOMNode *node = NULL, *next = NULL;
855 IXMLDOMNodeList *list = NULL;
856 DOMNodeType type = NODE_INVALID;
862 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
863 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
868 str = SysAllocString( szComplete4 );
869 r = IXMLDOMDocument_loadXML( doc, str, &b );
870 ok( r == S_OK, "loadXML failed\n");
871 ok( b == VARIANT_TRUE, "failed to load XML string\n");
872 SysFreeString( str );
877 r = IXMLDOMNode_hasChildNodes( doc, &b );
878 ok( r == S_OK, "hasChildNoes bad return\n");
879 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
881 r = IXMLDOMDocument_get_documentElement( doc, &element );
882 ok( r == S_OK, "should be a document element\n");
883 ok( element != NULL, "should be an element\n");
886 ok( FALSE, "no document\n");
889 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
891 r = IXMLDOMNode_get_nodeValue( doc, NULL );
892 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
894 r = IXMLDOMNode_get_nodeValue( doc, &var );
895 ok( r == S_FALSE, "nextNode returned wrong code\n");
896 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
897 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
902 r = IXMLDOMNode_get_ownerDocument( element, &owner );
904 ok( r == S_OK, "get_ownerDocument return code\n");
906 ok( owner != doc, "get_ownerDocument return\n");
909 r = IXMLDOMNode_get_nodeType( element, &type);
910 ok( r == S_OK, "getNamedItem returned wrong code\n");
911 ok( type == NODE_ELEMENT, "node not an element\n");
914 r = IXMLDOMNode_get_baseName( element, &str );
915 ok( r == S_OK, "get_baseName returned wrong code\n");
916 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
919 /* check if nodename is correct */
920 r = IXMLDOMElement_get_nodeName( element, NULL );
921 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
923 /* content doesn't matter here */
925 r = IXMLDOMElement_get_nodeName( element, &str );
926 ok ( r == S_OK, "get_nodeName wrong code\n");
927 ok ( str != NULL, "str is null\n");
928 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
929 SysFreeString( str );
931 str = SysAllocString( szNonExistentFile );
934 r = IXMLDOMElement_getAttribute( element, str, &var );
935 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
936 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
938 SysFreeString( str );
940 str = SysAllocString( szdl );
943 r = IXMLDOMElement_getAttribute( element, str, &var );
944 ok( r == S_OK, "getAttribute ret %08x\n", r );
945 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
946 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
947 VariantClear( &var );
949 r = IXMLDOMElement_getAttribute( element, NULL, &var );
950 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
952 r = IXMLDOMElement_getAttribute( element, str, NULL );
953 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
955 SysFreeString( str );
957 r = IXMLDOMElement_get_attributes( element, &map );
958 ok( r == S_OK, "get_attributes returned wrong code\n");
959 ok( map != NULL, "should be attributes\n");
962 r = IXMLDOMNode_hasChildNodes( element, &b );
963 ok( r == S_OK, "hasChildNoes bad return\n");
964 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
967 ok( FALSE, "no element\n");
971 ISupportErrorInfo *support_error;
972 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
973 ok( r == S_OK, "ret %08x\n", r );
975 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
978 ok( r == S_OK, "ret %08x\n", r );
980 ISupportErrorInfo_Release( support_error );
982 str = SysAllocString( szdl );
983 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
984 ok( r == S_OK, "getNamedItem returned wrong code\n");
985 ok( node != NULL, "should be attributes\n");
986 IXMLDOMNode_Release(node);
987 SysFreeString( str );
989 str = SysAllocString( szdl );
990 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
991 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
992 SysFreeString( str );
994 /* something that isn't in szComplete4 */
995 str = SysAllocString( szOpen );
996 node = (IXMLDOMNode *) 1;
997 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
998 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
999 ok( node == NULL, "getNamedItem should have returned NULL\n");
1000 SysFreeString( str );
1002 /* test indexed access of attributes */
1003 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1004 ok ( r == S_OK, "get_length wrong code\n");
1005 ok ( count == 1, "get_length != 1\n");
1008 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1009 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1010 ok ( node == NULL, "there is no node\n");
1013 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1014 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1015 ok ( node == NULL, "there is no attribute\n");
1018 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1019 ok ( r == S_OK, "get_item (0) wrong code\n");
1020 ok ( node != NULL, "should be attribute\n");
1022 r = IXMLDOMNode_get_nodeName( node, NULL );
1023 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1025 /* content doesn't matter here */
1027 r = IXMLDOMNode_get_nodeName( node, &str );
1028 ok ( r == S_OK, "get_nodeName wrong code\n");
1029 ok ( str != NULL, "str is null\n");
1030 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1031 SysFreeString( str );
1033 /* test sequential access of attributes */
1035 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1036 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1037 ok ( node != NULL, "nextNode, should be attribute\n");
1039 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1040 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1041 ok ( node == NULL, "nextNode, there is no attribute\n");
1043 r = IXMLDOMNamedNodeMap_reset( map );
1044 ok ( r == S_OK, "reset should return S_OK\n");
1046 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1047 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1048 ok ( node != NULL, "nextNode, should be attribute\n");
1051 ok( FALSE, "no map\n");
1055 type = NODE_INVALID;
1056 r = IXMLDOMNode_get_nodeType( node, &type);
1057 ok( r == S_OK, "getNamedItem returned wrong code\n");
1058 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1061 r = IXMLDOMNode_get_baseName( node, NULL );
1062 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1065 r = IXMLDOMNode_get_baseName( node, &str );
1066 ok( r == S_OK, "get_baseName returned wrong code\n");
1067 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1068 SysFreeString( str );
1070 r = IXMLDOMNode_get_nodeValue( node, &var );
1071 ok( r == S_OK, "returns %08x\n", r );
1072 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1073 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1076 r = IXMLDOMNode_get_childNodes( node, NULL );
1077 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1079 r = IXMLDOMNode_get_childNodes( node, &list );
1080 ok( r == S_OK, "get_childNodes returned wrong code\n");
1084 r = IXMLDOMNodeList_nextNode( list, &next );
1085 ok( r == S_OK, "nextNode returned wrong code\n");
1088 ok( FALSE, "no childlist\n");
1093 r = IXMLDOMNode_hasChildNodes( next, &b );
1094 ok( r == S_FALSE, "hasChildNoes bad return\n");
1095 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1097 type = NODE_INVALID;
1098 r = IXMLDOMNode_get_nodeType( next, &type);
1099 ok( r == S_OK, "getNamedItem returned wrong code\n");
1100 ok( type == NODE_TEXT, "node not text\n");
1103 r = IXMLDOMNode_get_baseName( next, &str );
1104 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1105 ok( str == NULL, "basename was wrong\n");
1109 ok( FALSE, "no next\n");
1112 IXMLDOMNode_Release( next );
1115 IXMLDOMNodeList_Release( list );
1118 IXMLDOMNode_Release( node );
1121 ok( FALSE, "no node\n");
1125 IXMLDOMNamedNodeMap_Release( map );
1127 /* now traverse the tree from the root element */
1131 r = IXMLDOMNode_get_childNodes( element, &list );
1132 ok( r == S_OK, "get_childNodes returned wrong code\n");
1134 /* using get_item for child list doesn't advance the position */
1135 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1136 expect_node(node, "E2.E2.D1");
1137 IXMLDOMNode_Release(node);
1138 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1139 expect_node(node, "E1.E2.D1");
1140 IXMLDOMNode_Release(node);
1141 ole_check(IXMLDOMNodeList_reset(list));
1143 IXMLDOMNodeList_AddRef(list);
1144 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1145 ole_check(IXMLDOMNodeList_reset(list));
1148 ok( FALSE, "no element\n");
1150 node = (void*)0xdeadbeef;
1151 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1152 ok( r == S_FALSE, "ret %08x\n", r );
1153 ok( node == NULL, "node %p\n", node );
1154 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1155 ok( r == S_OK, "ret %08x\n", r );
1156 r = IXMLDOMNode_Release( node );
1157 ok( r == 0, "ret %08x\n", r );
1161 r = IXMLDOMNodeList_get_length( list, &count );
1162 ok( r == S_OK, "get_length returns %08x\n", r );
1163 ok( count == 4, "get_length got %ld\n", count );
1165 r = IXMLDOMNodeList_nextNode( list, &node );
1166 ok( r == S_OK, "nextNode returned wrong code\n");
1169 ok( FALSE, "no list\n");
1173 type = NODE_INVALID;
1174 r = IXMLDOMNode_get_nodeType( node, &type);
1175 ok( r == S_OK, "getNamedItem returned wrong code\n");
1176 ok( type == NODE_ELEMENT, "node not text\n");
1179 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1180 r = IXMLDOMNode_get_nodeValue( node, &var );
1181 ok( r == S_FALSE, "nextNode returned wrong code\n");
1182 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1183 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1185 r = IXMLDOMNode_hasChildNodes( node, NULL );
1186 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1189 r = IXMLDOMNode_hasChildNodes( node, &b );
1190 ok( r == S_OK, "hasChildNoes bad return\n");
1191 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1194 r = IXMLDOMNode_get_baseName( node, &str );
1195 ok( r == S_OK, "get_baseName returned wrong code\n");
1196 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1200 ok( FALSE, "no node\n");
1203 IXMLDOMNode_Release( node );
1205 IXMLDOMNodeList_Release( list );
1207 IXMLDOMElement_Release( element );
1210 str = SysAllocString( szComplete5 );
1211 r = IXMLDOMDocument_loadXML( doc, str, &b );
1212 ok( r == S_OK, "loadXML failed\n");
1213 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1214 SysFreeString( str );
1217 r = IXMLDOMNode_hasChildNodes( doc, &b );
1218 ok( r == S_OK, "hasChildNoes bad return\n");
1219 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1221 r = IXMLDOMDocument_get_documentElement( doc, &element );
1222 ok( r == S_OK, "should be a document element\n");
1223 ok( element != NULL, "should be an element\n");
1227 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1230 /* check if the tag is correct */
1231 r = IXMLDOMElement_get_tagName( element, &tag );
1232 ok( r == S_OK, "couldn't get tag name\n");
1233 ok( tag != NULL, "tag was null\n");
1234 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1235 SysFreeString( tag );
1239 IXMLDOMElement_Release( element );
1241 IXMLDOMDocument_Release( doc );
1244 static void test_refs(void)
1249 IXMLDOMDocument *doc = NULL;
1250 IXMLDOMElement *element = NULL;
1251 IXMLDOMNode *node = NULL, *node2;
1252 IXMLDOMNodeList *node_list = NULL;
1254 IUnknown *unk, *unk2;
1256 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1257 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1260 ref = IXMLDOMDocument_Release(doc);
1261 ok( ref == 0, "ref %d\n", ref);
1263 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1264 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1268 str = SysAllocString( szComplete4 );
1269 r = IXMLDOMDocument_loadXML( doc, str, &b );
1270 ok( r == S_OK, "loadXML failed\n");
1271 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1272 SysFreeString( str );
1274 ref = IXMLDOMDocument_AddRef( doc );
1275 ok( ref == 2, "ref %d\n", ref );
1276 ref = IXMLDOMDocument_AddRef( doc );
1277 ok( ref == 3, "ref %d\n", ref );
1278 IXMLDOMDocument_Release( doc );
1279 IXMLDOMDocument_Release( doc );
1281 r = IXMLDOMDocument_get_documentElement( doc, &element );
1282 ok( r == S_OK, "should be a document element\n");
1283 ok( element != NULL, "should be an element\n");
1285 ref = IXMLDOMDocument_AddRef( doc );
1286 ok( ref == 2, "ref %d\n", ref );
1287 IXMLDOMDocument_Release( doc );
1289 r = IXMLDOMElement_get_childNodes( element, &node_list );
1290 ok( r == S_OK, "rets %08x\n", r);
1291 ref = IXMLDOMNodeList_AddRef( node_list );
1292 ok( ref == 2, "ref %d\n", ref );
1293 IXMLDOMNodeList_Release( node_list );
1295 IXMLDOMNodeList_get_item( node_list, 0, &node );
1296 ok( r == S_OK, "rets %08x\n", r);
1298 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1299 ok( r == S_OK, "rets %08x\n", r);
1301 ref = IXMLDOMNode_AddRef( node );
1302 ok( ref == 2, "ref %d\n", ref );
1303 IXMLDOMNode_Release( node );
1305 ref = IXMLDOMNode_Release( node );
1306 ok( ref == 0, "ref %d\n", ref );
1307 ref = IXMLDOMNode_Release( node2 );
1308 ok( ref == 0, "ref %d\n", ref );
1310 ref = IXMLDOMNodeList_Release( node_list );
1311 ok( ref == 0, "ref %d\n", ref );
1313 ok( node != node2, "node %p node2 %p\n", node, node2 );
1315 ref = IXMLDOMDocument_Release( doc );
1316 ok( ref == 0, "ref %d\n", ref );
1318 ref = IXMLDOMElement_AddRef( element );
1320 ok( ref == 3, "ref %d\n", ref );
1322 IXMLDOMElement_Release( element );
1324 /* IUnknown must be unique however we obtain it */
1325 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1326 ok( r == S_OK, "rets %08x\n", r );
1327 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1328 ok( r == S_OK, "rets %08x\n", r );
1329 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1330 ok( r == S_OK, "rets %08x\n", r );
1331 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1333 IUnknown_Release( unk2 );
1334 IUnknown_Release( unk );
1335 IXMLDOMNode_Release( node );
1337 IXMLDOMElement_Release( element );
1341 static void test_create(void)
1346 IXMLDOMDocument *doc;
1347 IXMLDOMElement *element;
1348 IXMLDOMNode *root, *node, *child;
1349 IXMLDOMNamedNodeMap *attr_map;
1354 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1355 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1360 V_I4(&var) = NODE_ELEMENT;
1361 str = SysAllocString( szlc );
1362 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1363 ok( r == S_OK, "returns %08x\n", r );
1364 r = IXMLDOMDocument_appendChild( doc, node, &root );
1365 ok( r == S_OK, "returns %08x\n", r );
1366 ok( node == root, "%p %p\n", node, root );
1368 ref = IXMLDOMNode_AddRef( node );
1369 ok(ref == 3, "ref %d\n", ref);
1370 IXMLDOMNode_Release( node );
1372 ref = IXMLDOMNode_Release( node );
1373 ok(ref == 1, "ref %d\n", ref);
1374 SysFreeString( str );
1377 V_I4(&var) = NODE_ELEMENT;
1378 str = SysAllocString( szbs );
1379 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1380 ok( r == S_OK, "returns %08x\n", r );
1382 ref = IXMLDOMNode_AddRef( node );
1383 ok(ref == 2, "ref = %d\n", ref);
1384 IXMLDOMNode_Release( node );
1386 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1387 ok( r == S_OK, "returns %08x\n", r );
1389 ref = IXMLDOMNode_AddRef( unk );
1390 ok(ref == 3, "ref = %d\n", ref);
1391 IXMLDOMNode_Release( unk );
1393 V_VT(&var) = VT_EMPTY;
1394 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1395 ok( r == S_OK, "returns %08x\n", r );
1396 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1397 IXMLDOMNode_Release( child );
1398 IUnknown_Release( unk );
1401 V_VT(&var) = VT_NULL;
1402 V_DISPATCH(&var) = (IDispatch*)node;
1403 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1404 ok( r == S_OK, "returns %08x\n", r );
1405 ok( node == child, "%p %p\n", node, child );
1406 IXMLDOMNode_Release( child );
1409 V_VT(&var) = VT_NULL;
1410 V_DISPATCH(&var) = (IDispatch*)node;
1411 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1412 ok( r == S_OK, "returns %08x\n", r );
1413 IXMLDOMNode_Release( node );
1415 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1416 ok( r == S_OK, "returns %08x\n", r );
1418 r = IXMLDOMElement_get_attributes( element, &attr_map );
1419 ok( r == S_OK, "returns %08x\n", r );
1420 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1421 ok( r == S_OK, "returns %08x\n", r );
1422 ok( num == 0, "num %ld\n", num );
1423 IXMLDOMNamedNodeMap_Release( attr_map );
1425 V_VT(&var) = VT_BSTR;
1426 V_BSTR(&var) = SysAllocString( szstr1 );
1427 name = SysAllocString( szdl );
1428 r = IXMLDOMElement_setAttribute( element, name, var );
1429 ok( r == S_OK, "returns %08x\n", r );
1430 r = IXMLDOMElement_get_attributes( element, &attr_map );
1431 ok( r == S_OK, "returns %08x\n", r );
1432 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1433 ok( r == S_OK, "returns %08x\n", r );
1434 ok( num == 1, "num %ld\n", num );
1435 IXMLDOMNamedNodeMap_Release( attr_map );
1438 V_VT(&var) = VT_BSTR;
1439 V_BSTR(&var) = SysAllocString( szstr2 );
1440 r = IXMLDOMElement_setAttribute( element, name, var );
1441 ok( r == S_OK, "returns %08x\n", r );
1442 r = IXMLDOMElement_get_attributes( element, &attr_map );
1443 ok( r == S_OK, "returns %08x\n", r );
1444 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1445 ok( r == S_OK, "returns %08x\n", r );
1446 ok( num == 1, "num %ld\n", num );
1447 IXMLDOMNamedNodeMap_Release( attr_map );
1449 r = IXMLDOMElement_getAttribute( element, name, &var );
1450 ok( r == S_OK, "returns %08x\n", r );
1451 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1453 SysFreeString(name);
1455 V_VT(&var) = VT_BSTR;
1456 V_BSTR(&var) = SysAllocString( szstr1 );
1457 name = SysAllocString( szlc );
1458 r = IXMLDOMElement_setAttribute( element, name, var );
1459 ok( r == S_OK, "returns %08x\n", r );
1460 r = IXMLDOMElement_get_attributes( element, &attr_map );
1461 ok( r == S_OK, "returns %08x\n", r );
1462 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1463 ok( r == S_OK, "returns %08x\n", r );
1464 ok( num == 2, "num %ld\n", num );
1465 IXMLDOMNamedNodeMap_Release( attr_map );
1467 SysFreeString(name);
1471 name = SysAllocString( szbs );
1472 r = IXMLDOMElement_setAttribute( element, name, var );
1473 ok( r == S_OK, "returns %08x\n", r );
1475 r = IXMLDOMElement_getAttribute( element, name, &var );
1476 ok( r == S_OK, "returns %08x\n", r );
1477 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1479 SysFreeString(name);
1481 IXMLDOMElement_Release( element );
1482 IXMLDOMNode_Release( root );
1483 IXMLDOMDocument_Release( doc );
1486 static void test_getElementsByTagName(void)
1491 IXMLDOMDocument *doc;
1492 IXMLDOMNodeList *node_list;
1495 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1496 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1500 str = SysAllocString( szComplete4 );
1501 r = IXMLDOMDocument_loadXML( doc, str, &b );
1502 ok( r == S_OK, "loadXML failed\n");
1503 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1504 SysFreeString( str );
1506 str = SysAllocString( szstar );
1507 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1508 ok( r == S_OK, "ret %08x\n", r );
1509 r = IXMLDOMNodeList_get_length( node_list, &len );
1510 ok( r == S_OK, "ret %08x\n", r );
1511 ok( len == 6, "len %ld\n", len );
1512 IXMLDOMNodeList_Release( node_list );
1513 SysFreeString( str );
1515 str = SysAllocString( szbs );
1516 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1517 ok( r == S_OK, "ret %08x\n", r );
1518 r = IXMLDOMNodeList_get_length( node_list, &len );
1519 ok( r == S_OK, "ret %08x\n", r );
1520 ok( len == 1, "len %ld\n", len );
1521 IXMLDOMNodeList_Release( node_list );
1522 SysFreeString( str );
1524 str = SysAllocString( szdl );
1525 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1526 ok( r == S_OK, "ret %08x\n", r );
1527 r = IXMLDOMNodeList_get_length( node_list, &len );
1528 ok( r == S_OK, "ret %08x\n", r );
1529 ok( len == 0, "len %ld\n", len );
1530 IXMLDOMNodeList_Release( node_list );
1531 SysFreeString( str );
1533 str = SysAllocString( szstr1 );
1534 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1535 ok( r == S_OK, "ret %08x\n", r );
1536 r = IXMLDOMNodeList_get_length( node_list, &len );
1537 ok( r == S_OK, "ret %08x\n", r );
1538 ok( len == 0, "len %ld\n", len );
1539 IXMLDOMNodeList_Release( node_list );
1540 SysFreeString( str );
1542 IXMLDOMDocument_Release( doc );
1545 static void test_get_text(void)
1550 IXMLDOMDocument *doc;
1551 IXMLDOMNode *node, *node2, *node3;
1552 IXMLDOMNodeList *node_list;
1553 IXMLDOMNamedNodeMap *node_map;
1555 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1556 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1560 str = SysAllocString( szComplete4 );
1561 r = IXMLDOMDocument_loadXML( doc, str, &b );
1562 ok( r == S_OK, "loadXML failed\n");
1563 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1564 SysFreeString( str );
1566 str = SysAllocString( szbs );
1567 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1568 ok( r == S_OK, "ret %08x\n", r );
1571 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1572 ok( r == S_OK, "ret %08x\n", r );
1573 IXMLDOMNodeList_Release( node_list );
1575 /* Invalid output parameter*/
1576 r = IXMLDOMNode_get_text( node, NULL );
1577 ok( r == E_INVALIDARG, "ret %08x\n", r );
1579 r = IXMLDOMNode_get_text( node, &str );
1580 ok( r == S_OK, "ret %08x\n", r );
1582 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
1584 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
1587 r = IXMLDOMNode_get_attributes( node, &node_map );
1588 ok( r == S_OK, "ret %08x\n", r );
1590 str = SysAllocString( szvr );
1591 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1592 ok( r == S_OK, "ret %08x\n", r );
1595 r = IXMLDOMNode_get_text( node2, &str );
1596 ok( r == S_OK, "ret %08x\n", r );
1597 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1600 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1601 ok( r == S_OK, "ret %08x\n", r );
1603 r = IXMLDOMNode_get_text( node3, &str );
1604 ok( r == S_OK, "ret %08x\n", r );
1605 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1609 IXMLDOMNode_Release( node3 );
1610 IXMLDOMNode_Release( node2 );
1611 IXMLDOMNamedNodeMap_Release( node_map );
1612 IXMLDOMNode_Release( node );
1613 IXMLDOMDocument_Release( doc );
1616 static void test_get_childNodes(void)
1621 IXMLDOMDocument *doc;
1622 IXMLDOMElement *element;
1623 IXMLDOMNode *node, *node2;
1624 IXMLDOMNodeList *node_list, *node_list2;
1627 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1628 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1632 str = SysAllocString( szComplete4 );
1633 r = IXMLDOMDocument_loadXML( doc, str, &b );
1634 ok( r == S_OK, "loadXML failed\n");
1635 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1636 SysFreeString( str );
1638 r = IXMLDOMDocument_get_documentElement( doc, &element );
1639 ok( r == S_OK, "ret %08x\n", r);
1641 r = IXMLDOMElement_get_childNodes( element, &node_list );
1642 ok( r == S_OK, "ret %08x\n", r);
1644 r = IXMLDOMNodeList_get_length( node_list, &len );
1645 ok( r == S_OK, "ret %08x\n", r);
1646 ok( len == 4, "len %ld\n", len);
1648 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1649 ok( r == S_OK, "ret %08x\n", r);
1651 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1652 ok( r == S_OK, "ret %08x\n", r);
1654 r = IXMLDOMNodeList_get_length( node_list2, &len );
1655 ok( r == S_OK, "ret %08x\n", r);
1656 ok( len == 0, "len %ld\n", len);
1658 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1659 ok( r == S_FALSE, "ret %08x\n", r);
1661 IXMLDOMNodeList_Release( node_list2 );
1662 IXMLDOMNode_Release( node );
1663 IXMLDOMNodeList_Release( node_list );
1664 IXMLDOMElement_Release( element );
1665 IXMLDOMDocument_Release( doc );
1668 static void test_removeChild(void)
1673 IXMLDOMDocument *doc;
1674 IXMLDOMElement *element;
1675 IXMLDOMNode *node, *node2, *node3, *node4;
1676 IXMLDOMNodeList *node_list, *node_list2;
1678 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1679 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1683 str = SysAllocString( szComplete4 );
1684 r = IXMLDOMDocument_loadXML( doc, str, &b );
1685 ok( r == S_OK, "loadXML failed\n");
1686 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1687 SysFreeString( str );
1689 r = IXMLDOMDocument_get_documentElement( doc, &element );
1690 ok( r == S_OK, "ret %08x\n", r);
1692 r = IXMLDOMElement_get_childNodes( element, &node_list );
1693 ok( r == S_OK, "ret %08x\n", r);
1695 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1696 ok( r == S_OK, "ret %08x\n", r);
1698 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1699 ok( r == S_OK, "ret %08x\n", r);
1701 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1702 ok( r == S_OK, "ret %08x\n", r);
1704 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1705 ok( r == E_INVALIDARG, "ret %08x\n", r );
1707 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1708 ok( r == S_OK, "ret %08x\n", r);
1709 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1711 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1712 ok( r == S_FALSE, "ret %08x\n", r);
1713 ok( node3 == NULL, "%p\n", node3 );
1715 IXMLDOMNode_Release( node2 );
1716 IXMLDOMNode_Release( node4 );
1717 IXMLDOMNodeList_Release( node_list2 );
1718 IXMLDOMNode_Release( node );
1719 IXMLDOMNodeList_Release( node_list );
1720 IXMLDOMElement_Release( element );
1721 IXMLDOMDocument_Release( doc );
1724 static void test_XMLHTTP(void)
1726 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1727 static WCHAR wszPOST[] = {'P','O','S','T',0};
1728 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1729 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1730 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1731 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1732 IXMLHttpRequest *pXMLHttpRequest;
1737 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1738 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1739 (void **)&pXMLHttpRequest);
1741 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1746 VariantInit(&dummy);
1747 V_VT(&dummy) = VT_ERROR;
1748 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1749 VariantInit(&varfalse);
1750 V_VT(&varfalse) = VT_BOOL;
1751 V_BOOL(&varfalse) = VARIANT_FALSE;
1752 V_VT(&varbody) = VT_BSTR;
1753 V_BSTR(&varbody) = SysAllocString(wszBody);
1755 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1756 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1758 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1759 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1760 VariantClear(&varbody);
1762 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1763 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1764 /* the server currently returns "FAILED" because the Content-Type header is
1765 * not what the server expects */
1766 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1767 SysFreeString(bstrResponse);
1770 static void test_IXMLDOMDocument2(void)
1775 IXMLDOMDocument *doc;
1776 IXMLDOMDocument2 *doc2;
1780 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1781 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1785 str = SysAllocString( szComplete4 );
1786 r = IXMLDOMDocument_loadXML( doc, str, &b );
1787 ok( r == S_OK, "loadXML failed\n");
1788 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1789 SysFreeString( str );
1791 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1792 ok( r == S_OK, "ret %08x\n", r );
1793 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1795 /* we will check if the variant got cleared */
1796 ref = IXMLDOMDocument2_AddRef(doc2);
1797 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1798 V_VT(&var) = VT_UNKNOWN;
1799 V_UNKNOWN(&var) = (IUnknown *)doc2;
1802 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1803 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1804 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1807 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1808 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1809 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1812 /* the variant didn't get cleared*/
1813 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1815 /* setProperty tests */
1816 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1817 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1818 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1819 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1820 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1821 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1823 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
1824 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1825 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1826 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1828 IXMLDOMDocument2_Release( doc2 );
1829 IXMLDOMDocument_Release( doc );
1833 static void test_XPath(void)
1838 IXMLDOMDocument2 *doc;
1839 IXMLDOMNode *rootNode;
1840 IXMLDOMNode *elem1Node;
1842 IXMLDOMNodeList *list;
1844 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1845 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1849 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1850 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1852 /* switch to XPath */
1853 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1855 /* some simple queries*/
1856 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1857 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1858 ole_check(IXMLDOMNodeList_reset(list));
1859 expect_list_and_release(list, "E2.D1");
1860 if (rootNode == NULL)
1863 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1864 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1866 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1867 expect_list_and_release(list, "E3.E2.E2.D1");
1869 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1870 /* using get_item for query results advances the position */
1871 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1872 expect_node(node, "E2.E2.D1");
1873 IXMLDOMNode_Release(node);
1874 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1875 expect_node(node, "E4.E2.D1");
1876 IXMLDOMNode_Release(node);
1877 ole_check(IXMLDOMNodeList_reset(list));
1878 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1880 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
1881 expect_list_and_release(list, "E2.D1");
1883 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
1884 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
1885 ole_check(IXMLDOMNodeList_reset(list));
1886 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1888 /* select an attribute */
1889 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
1890 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
1892 /* would evaluate to a number */
1893 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
1894 /* would evaluate to a boolean */
1895 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
1896 /* would evaluate to a string */
1897 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
1900 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
1901 expect_list_and_release(list, "");
1902 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
1903 expect_list_and_release(list, "");
1904 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
1905 expect_list_and_release(list, "");
1907 /* foo undeclared in document node */
1908 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1909 /* undeclared in <root> node */
1910 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
1911 /* undeclared in <elem> node */
1912 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
1913 /* but this trick can be used */
1914 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
1915 expect_list_and_release(list, "E3.E4.E2.D1");
1917 /* it has to be declared in SelectionNamespaces */
1918 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1919 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
1921 /* now the namespace can be used */
1922 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
1923 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1924 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
1925 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1926 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
1927 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1928 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
1929 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
1931 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
1932 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1933 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
1935 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1938 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
1939 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1940 if (V_VT(&var) == VT_BSTR)
1941 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
1943 /* extra attributes - same thing*/
1944 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1945 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
1946 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1948 IXMLDOMNode_Release(rootNode);
1949 IXMLDOMNode_Release(elem1Node);
1950 IXMLDOMDocument_Release(doc);
1954 static void test_cloneNode(void )
1956 IXMLDOMDocument *doc = NULL;
1958 IXMLDOMNodeList *pList;
1959 IXMLDOMNamedNodeMap *mapAttr;
1960 long nLength = 0, nLength1 = 0;
1961 long nAttrCnt = 0, nAttrCnt1 = 0;
1963 IXMLDOMNode *node_clone;
1966 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
1968 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1972 str = SysAllocString( szComplete4 );
1973 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
1974 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1980 str = SysAllocString( szSearch);
1981 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
1982 ok( r == S_OK, "ret %08x\n", r );
1983 ok( node != NULL, "node %p\n", node );
1988 IXMLDOMDocument_Release(doc);
1992 /* Check invalid parameter */
1993 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
1994 ok( r == E_INVALIDARG, "ret %08x\n", r );
1997 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
1998 ok( r == S_OK, "ret %08x\n", r );
1999 ok( node_clone != NULL, "node %p\n", node );
2003 IXMLDOMDocument_Release(doc);
2004 IXMLDOMNode_Release(node);
2008 r = IXMLDOMNode_get_childNodes(node, &pList);
2009 ok( r == S_OK, "ret %08x\n", r );
2012 IXMLDOMNodeList_get_length(pList, &nLength);
2013 IXMLDOMNodeList_Release(pList);
2016 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2017 ok( r == S_OK, "ret %08x\n", r );
2020 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2021 IXMLDOMNamedNodeMap_Release(mapAttr);
2024 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2025 ok( r == S_OK, "ret %08x\n", r );
2028 IXMLDOMNodeList_get_length(pList, &nLength1);
2029 IXMLDOMNodeList_Release(pList);
2032 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2033 ok( r == S_OK, "ret %08x\n", r );
2036 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2037 IXMLDOMNamedNodeMap_Release(mapAttr);
2040 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2041 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2042 IXMLDOMNode_Release(node_clone);
2045 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2046 ok( r == S_OK, "ret %08x\n", r );
2047 ok( node_clone != NULL, "node %p\n", node );
2051 IXMLDOMDocument_Release(doc);
2052 IXMLDOMNode_Release(node);
2056 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2057 ok( r == S_OK, "ret %08x\n", r );
2060 IXMLDOMNodeList_get_length(pList, &nLength1);
2061 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
2062 IXMLDOMNodeList_Release(pList);
2065 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2066 ok( r == S_OK, "ret %08x\n", r );
2069 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2070 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
2071 IXMLDOMNamedNodeMap_Release(mapAttr);
2074 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2075 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2076 IXMLDOMNode_Release(node_clone);
2079 IXMLDOMNode_Release(node);
2080 IXMLDOMDocument_Release(doc);
2083 static void test_xmlTypes(void)
2085 IXMLDOMDocument *doc = NULL;
2086 IXMLDOMElement *pRoot;
2088 IXMLDOMComment *pComment;
2089 IXMLDOMElement *pElement;
2090 IXMLDOMAttribute *pAttrubute;
2091 IXMLDOMNamedNodeMap *pAttribs;
2092 IXMLDOMCDATASection *pCDataSec;
2093 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2094 IXMLDOMDocumentFragment *pDocFrag = NULL;
2095 IXMLDOMEntityReference *pEntityRef = NULL;
2097 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2101 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2105 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2106 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2108 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2109 ok(hr == S_FALSE, "ret %08x\n", hr );
2110 ok(pNextChild == NULL, "pDocChild not NULL\n");
2112 /* test previous Sibling */
2113 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2114 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2116 pNextChild = (IXMLDOMNode *)0x1;
2117 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2118 ok(hr == S_FALSE, "ret %08x\n", hr );
2119 ok(pNextChild == NULL, "pNextChild not NULL\n");
2121 /* test get_attributes */
2122 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2123 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2125 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2126 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2127 ok(hr == S_FALSE, "ret %08x\n", hr );
2128 ok( pAttribs == NULL, "pAttribs not NULL\n");
2130 /* test get_dataType */
2131 hr = IXMLDOMDocument_get_dataType(doc, &v);
2132 ok(hr == S_FALSE, "ret %08x\n", hr );
2133 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2136 /* test nodeTypeString */
2137 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2138 ok(hr == S_OK, "ret %08x\n", hr );
2139 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2142 /* test implementation */
2143 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2144 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2146 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2147 ok(hr == S_OK, "ret %08x\n", hr );
2150 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2151 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2153 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2154 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2156 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2157 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2159 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2160 ok(hr == S_OK, "ret %08x\n", hr );
2161 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2163 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2164 ok(hr == S_OK, "ret %08x\n", hr );
2165 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2167 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2168 ok(hr == S_OK, "ret %08x\n", hr );
2169 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2171 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2172 ok(hr == S_OK, "ret %08x\n", hr );
2173 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2175 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2176 ok(hr == S_OK, "ret %08x\n", hr );
2177 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2179 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2180 ok(hr == S_OK, "ret %08x\n", hr );
2181 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2183 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2184 ok(hr == S_OK, "ret %08x\n", hr );
2185 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2187 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2188 ok(hr == S_OK, "ret %08x\n", hr );
2189 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2191 SysFreeString(sEmpty);
2192 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2197 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2198 ok(hr == S_OK, "ret %08x\n", hr );
2201 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2202 ok(hr == S_OK, "ret %08x\n", hr );
2206 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2207 ok(hr == S_OK, "ret %08x\n", hr );
2210 /* test get_attributes */
2211 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2212 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2214 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2215 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2216 ok(hr == S_FALSE, "ret %08x\n", hr );
2217 ok( pAttribs == NULL, "pAttribs not NULL\n");
2219 /* test nodeTypeString */
2220 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2221 ok(hr == S_OK, "ret %08x\n", hr );
2222 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2225 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2226 ok(hr == S_OK, "ret %08x\n", hr );
2228 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2229 ok(hr == S_OK, "ret %08x\n", hr );
2230 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2233 hr = IXMLDOMComment_get_xml(pComment, &str);
2234 ok(hr == S_OK, "ret %08x\n", hr );
2235 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2238 hr = IXMLDOMComment_get_dataType(pComment, &v);
2239 ok(hr == S_FALSE, "ret %08x\n", hr );
2240 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2243 /* put data Tests */
2244 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2245 ok(hr == S_OK, "ret %08x\n", hr );
2247 /* get data Tests */
2248 hr = IXMLDOMComment_get_data(pComment, &str);
2249 ok(hr == S_OK, "ret %08x\n", hr );
2250 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2253 /* get data Tests */
2254 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2255 ok(hr == S_OK, "ret %08x\n", hr );
2256 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2257 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2260 /* Confirm XML text is good */
2261 hr = IXMLDOMComment_get_xml(pComment, &str);
2262 ok(hr == S_OK, "ret %08x\n", hr );
2263 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2266 /* Confirm we get the put_data Text back */
2267 hr = IXMLDOMComment_get_text(pComment, &str);
2268 ok(hr == S_OK, "ret %08x\n", hr );
2269 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2272 /* test length property */
2273 hr = IXMLDOMComment_get_length(pComment, &len);
2274 ok(hr == S_OK, "ret %08x\n", hr );
2275 ok(len == 21, "expected 21 got %ld\n", len);
2277 /* test substringData */
2278 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2279 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2281 /* test substringData - Invalid offset */
2282 str = (BSTR)&szElement;
2283 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2284 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2285 ok( str == NULL, "incorrect string\n");
2287 /* test substringData - Invalid offset */
2288 str = (BSTR)&szElement;
2289 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2290 ok(hr == S_FALSE, "ret %08x\n", hr );
2291 ok( str == NULL, "incorrect string\n");
2293 /* test substringData - Invalid size */
2294 str = (BSTR)&szElement;
2295 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2296 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2297 ok( str == NULL, "incorrect string\n");
2299 /* test substringData - Invalid size */
2300 str = (BSTR)&szElement;
2301 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2302 ok(hr == S_FALSE, "ret %08x\n", hr );
2303 ok( str == NULL, "incorrect string\n");
2305 /* test substringData - Start of string */
2306 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2307 ok(hr == S_OK, "ret %08x\n", hr );
2308 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2311 /* test substringData - Middle of string */
2312 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2313 ok(hr == S_OK, "ret %08x\n", hr );
2314 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2317 /* test substringData - End of string */
2318 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2319 ok(hr == S_OK, "ret %08x\n", hr );
2320 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2323 /* test appendData */
2324 hr = IXMLDOMComment_appendData(pComment, NULL);
2325 ok(hr == S_OK, "ret %08x\n", hr );
2327 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2328 ok(hr == S_OK, "ret %08x\n", hr );
2330 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2331 ok(hr == S_OK, "ret %08x\n", hr );
2333 hr = IXMLDOMComment_get_text(pComment, &str);
2334 ok(hr == S_OK, "ret %08x\n", hr );
2335 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2338 /* test insertData */
2339 str = SysAllocStringLen(NULL, 0);
2340 hr = IXMLDOMComment_insertData(pComment, -1, str);
2341 ok(hr == S_OK, "ret %08x\n", hr );
2343 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2344 ok(hr == S_OK, "ret %08x\n", hr );
2346 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2347 ok(hr == S_OK, "ret %08x\n", hr );
2349 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2350 ok(hr == S_OK, "ret %08x\n", hr );
2352 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2353 ok(hr == S_OK, "ret %08x\n", hr );
2355 hr = IXMLDOMComment_insertData(pComment, 0, str);
2356 ok(hr == S_OK, "ret %08x\n", hr );
2359 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2360 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2362 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2363 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2365 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2366 ok(hr == S_OK, "ret %08x\n", hr );
2368 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2369 ok(hr == S_OK, "ret %08x\n", hr );
2371 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2372 ok(hr == S_OK, "ret %08x\n", hr );
2374 hr = IXMLDOMComment_get_text(pComment, &str);
2375 ok(hr == S_OK, "ret %08x\n", hr );
2376 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2379 IXMLDOMComment_Release(pComment);
2383 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2384 ok(hr == S_OK, "ret %08x\n", hr );
2387 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2388 ok(hr == S_OK, "ret %08x\n", hr );
2390 /* test nodeTypeString */
2391 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2392 ok(hr == S_OK, "ret %08x\n", hr );
2393 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2396 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2397 ok(hr == S_OK, "ret %08x\n", hr );
2398 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2401 hr = IXMLDOMElement_get_xml(pElement, &str);
2402 ok(hr == S_OK, "ret %08x\n", hr );
2403 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2406 hr = IXMLDOMElement_get_dataType(pElement, &v);
2407 ok(hr == S_FALSE, "ret %08x\n", hr );
2408 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2412 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2413 ok(hr == S_OK, "ret %08x\n", hr );
2416 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2418 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2419 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2421 pNextChild = (IXMLDOMNode *)0x1;
2422 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2423 ok(hr == S_FALSE, "ret %08x\n", hr );
2424 ok(pNextChild == NULL, "pNextChild not NULL\n");
2426 /* test Previous Sibling*/
2427 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2428 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2430 pNextChild = (IXMLDOMNode *)0x1;
2431 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2432 ok(hr == S_FALSE, "ret %08x\n", hr );
2433 ok(pNextChild == NULL, "pNextChild not NULL\n");
2435 /* test get_attributes */
2436 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2437 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2439 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2440 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2441 ok(hr == S_FALSE, "ret %08x\n", hr );
2442 ok( pAttribs == NULL, "pAttribs not NULL\n");
2444 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2445 ok(hr == E_FAIL, "ret %08x\n", hr );
2446 ok(pNewChild == NULL, "pNewChild not NULL\n");
2448 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2449 ok(hr == S_OK, "ret %08x\n", hr );
2452 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2453 ok(hr == S_OK, "ret %08x\n", hr );
2455 IXMLDOMNamedNodeMap_Release(pAttribs);
2458 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2459 ok(hr == S_OK, "ret %08x\n", hr );
2460 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2463 /* test nodeTypeString */
2464 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2465 ok(hr == S_OK, "ret %08x\n", hr );
2466 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2470 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2471 ok(hr == S_OK, "ret %08x\n", hr );
2472 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
2475 /* test name property */
2476 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
2477 ok(hr == S_OK, "ret %08x\n", hr );
2478 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
2481 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2482 ok(hr == S_OK, "ret %08x\n", hr );
2483 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2486 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2487 ok(hr == S_FALSE, "ret %08x\n", hr );
2488 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2491 IXMLDOMAttribute_Release(pAttrubute);
2493 /* Check Element again with the Add Attribute*/
2494 hr = IXMLDOMElement_get_xml(pElement, &str);
2495 ok(hr == S_OK, "ret %08x\n", hr );
2496 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2500 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2501 ok(hr == S_OK, "ret %08x\n", hr );
2503 hr = IXMLDOMElement_get_xml(pElement, &str);
2504 ok(hr == S_OK, "ret %08x\n", hr );
2505 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2508 IXMLDOMElement_Release(pElement);
2512 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2513 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2515 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2516 ok(hr == S_OK, "ret %08x\n", hr );
2519 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2522 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2523 ok(hr == S_OK, "ret %08x\n", hr );
2525 /* get Attribute Tests */
2526 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2527 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2529 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2530 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2531 ok(hr == S_FALSE, "ret %08x\n", hr );
2532 ok(pAttribs == NULL, "pAttribs != NULL\n");
2534 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2535 ok(hr == S_OK, "ret %08x\n", hr );
2536 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2539 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2540 ok(hr == S_OK, "ret %08x\n", hr );
2541 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2544 /* test lastChild */
2545 pNextChild = (IXMLDOMNode*)0x1;
2546 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2547 ok(hr == S_FALSE, "ret %08x\n", hr );
2548 ok(pNextChild == NULL, "pNextChild not NULL\n");
2550 /* test get_dataType */
2551 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2552 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2554 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2555 ok(hr == S_FALSE, "ret %08x\n", hr );
2556 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2559 /* test nodeTypeString */
2560 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2561 ok(hr == S_OK, "ret %08x\n", hr );
2562 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2565 /* put data Tests */
2566 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
2567 ok(hr == S_OK, "ret %08x\n", hr );
2569 /* Confirm XML text is good */
2570 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2571 ok(hr == S_OK, "ret %08x\n", hr );
2572 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
2575 /* Confirm we get the put_data Text back */
2576 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2577 ok(hr == S_OK, "ret %08x\n", hr );
2578 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2581 /* test length property */
2582 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
2583 ok(hr == S_OK, "ret %08x\n", hr );
2584 ok(len == 21, "expected 21 got %ld\n", len);
2586 /* test get nodeValue */
2587 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
2588 ok(hr == S_OK, "ret %08x\n", hr );
2589 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2593 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
2594 ok(hr == S_OK, "ret %08x\n", hr );
2595 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2598 /* test substringData */
2599 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
2600 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2602 /* test substringData - Invalid offset */
2603 str = (BSTR)&szElement;
2604 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
2605 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2606 ok( str == NULL, "incorrect string\n");
2608 /* test substringData - Invalid offset */
2609 str = (BSTR)&szElement;
2610 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
2611 ok(hr == S_FALSE, "ret %08x\n", hr );
2612 ok( str == NULL, "incorrect string\n");
2614 /* test substringData - Invalid size */
2615 str = (BSTR)&szElement;
2616 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
2617 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2618 ok( str == NULL, "incorrect string\n");
2620 /* test substringData - Invalid size */
2621 str = (BSTR)&szElement;
2622 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
2623 ok(hr == S_FALSE, "ret %08x\n", hr );
2624 ok( str == NULL, "incorrect string\n");
2626 /* test substringData - Start of string */
2627 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
2628 ok(hr == S_OK, "ret %08x\n", hr );
2629 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2632 /* test substringData - Middle of string */
2633 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
2634 ok(hr == S_OK, "ret %08x\n", hr );
2635 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2638 /* test substringData - End of string */
2639 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
2640 ok(hr == S_OK, "ret %08x\n", hr );
2641 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2644 /* test appendData */
2645 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
2646 ok(hr == S_OK, "ret %08x\n", hr );
2648 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
2649 ok(hr == S_OK, "ret %08x\n", hr );
2651 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
2652 ok(hr == S_OK, "ret %08x\n", hr );
2654 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2655 ok(hr == S_OK, "ret %08x\n", hr );
2656 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2659 /* test insertData */
2660 str = SysAllocStringLen(NULL, 0);
2661 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
2662 ok(hr == S_OK, "ret %08x\n", hr );
2664 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
2665 ok(hr == S_OK, "ret %08x\n", hr );
2667 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
2668 ok(hr == S_OK, "ret %08x\n", hr );
2670 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
2671 ok(hr == S_OK, "ret %08x\n", hr );
2673 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
2674 ok(hr == S_OK, "ret %08x\n", hr );
2676 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
2677 ok(hr == S_OK, "ret %08x\n", hr );
2680 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
2681 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2683 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
2684 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2686 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
2687 ok(hr == S_OK, "ret %08x\n", hr );
2689 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
2690 ok(hr == S_OK, "ret %08x\n", hr );
2692 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
2693 ok(hr == S_OK, "ret %08x\n", hr );
2695 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2696 ok(hr == S_OK, "ret %08x\n", hr );
2697 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2700 IXMLDOMCDATASection_Release(pCDataSec);
2703 /* Document Fragments */
2704 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
2705 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2707 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
2708 ok(hr == S_OK, "ret %08x\n", hr );
2711 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2713 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
2714 ok(hr == S_OK, "ret %08x\n", hr );
2716 /* get Attribute Tests */
2717 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
2718 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2720 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2721 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
2722 ok(hr == S_FALSE, "ret %08x\n", hr );
2723 ok(pAttribs == NULL, "pAttribs != NULL\n");
2725 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
2726 ok(hr == S_OK, "ret %08x\n", hr );
2727 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
2730 /* test next Sibling*/
2731 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
2732 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2734 pNextChild = (IXMLDOMNode *)0x1;
2735 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
2736 ok(hr == S_FALSE, "ret %08x\n", hr );
2737 ok(pNextChild == NULL, "pNextChild not NULL\n");
2739 /* test Previous Sibling*/
2740 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
2741 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2743 pNextChild = (IXMLDOMNode *)0x1;
2744 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
2745 ok(hr == S_FALSE, "ret %08x\n", hr );
2746 ok(pNextChild == NULL, "pNextChild not NULL\n");
2748 /* test get_dataType */
2749 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
2750 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2752 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
2753 ok(hr == S_FALSE, "ret %08x\n", hr );
2754 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2757 /* test nodeTypeString */
2758 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
2759 ok(hr == S_OK, "ret %08x\n", hr );
2760 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
2763 IXMLDOMDocumentFragment_Release(pDocFrag);
2766 /* Entity References */
2767 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
2768 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2770 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
2771 ok(hr == S_OK, "ret %08x\n", hr );
2774 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
2775 ok(hr == S_OK, "ret %08x\n", hr );
2777 /* get Attribute Tests */
2778 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
2779 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2781 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2782 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
2783 ok(hr == S_FALSE, "ret %08x\n", hr );
2784 ok(pAttribs == NULL, "pAttribs != NULL\n");
2787 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
2788 ok(hr == S_FALSE, "ret %08x\n", hr );
2789 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2792 /* test nodeTypeString */
2793 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
2794 ok(hr == S_OK, "ret %08x\n", hr );
2795 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
2799 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
2800 ok(hr == S_OK, "ret %08x\n", hr );
2801 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
2804 IXMLDOMEntityReference_Release(pEntityRef);
2807 IXMLDOMElement_Release( pRoot );
2811 IXMLDOMDocument_Release(doc);
2816 static void test_nodeTypeTests( void )
2818 IXMLDOMDocument *doc = NULL;
2819 IXMLDOMElement *pRoot;
2820 IXMLDOMElement *pElement;
2823 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2827 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2828 ok(hr == S_OK, "ret %08x\n", hr );
2831 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2832 ok(hr == S_OK, "ret %08x\n", hr );
2835 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
2836 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2839 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
2840 ok(hr == E_FAIL, "ret %08x\n", hr );
2843 * The name passed into put_dataType is case-insensitive. So many of the names
2844 * have been changed to reflect this.
2847 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
2848 ok(hr == S_OK, "ret %08x\n", hr );
2851 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2853 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
2854 ok(hr == S_OK, "ret %08x\n", hr );
2856 IXMLDOMElement_Release(pElement);
2860 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
2861 ok(hr == S_OK, "ret %08x\n", hr );
2864 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2866 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
2867 ok(hr == S_OK, "ret %08x\n", hr );
2869 IXMLDOMElement_Release(pElement);
2873 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
2874 ok(hr == S_OK, "ret %08x\n", hr );
2877 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2879 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
2880 ok(hr == S_OK, "ret %08x\n", hr );
2882 IXMLDOMElement_Release(pElement);
2886 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
2887 ok(hr == S_OK, "ret %08x\n", hr );
2890 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2892 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
2893 ok(hr == S_OK, "ret %08x\n", hr );
2895 IXMLDOMElement_Release(pElement);
2899 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
2900 ok(hr == S_OK, "ret %08x\n", hr );
2903 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2905 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
2906 ok(hr == S_OK, "ret %08x\n", hr );
2908 IXMLDOMElement_Release(pElement);
2912 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
2913 ok(hr == S_OK, "ret %08x\n", hr );
2916 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2918 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
2919 ok(hr == S_OK, "ret %08x\n", hr );
2921 IXMLDOMElement_Release(pElement);
2925 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
2926 ok(hr == S_OK, "ret %08x\n", hr );
2929 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2931 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
2932 ok(hr == S_OK, "ret %08x\n", hr );
2934 IXMLDOMElement_Release(pElement);
2938 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
2939 ok(hr == S_OK, "ret %08x\n", hr );
2942 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2944 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
2945 ok(hr == S_OK, "ret %08x\n", hr );
2947 IXMLDOMElement_Release(pElement);
2951 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
2952 ok(hr == S_OK, "ret %08x\n", hr );
2955 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2957 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
2958 ok(hr == S_OK, "ret %08x\n", hr );
2960 IXMLDOMElement_Release(pElement);
2964 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
2965 ok(hr == S_OK, "ret %08x\n", hr );
2968 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2970 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
2971 ok(hr == S_OK, "ret %08x\n", hr );
2973 IXMLDOMElement_Release(pElement);
2977 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
2978 ok(hr == S_OK, "ret %08x\n", hr );
2981 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2983 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
2984 ok(hr == S_OK, "ret %08x\n", hr );
2986 IXMLDOMElement_Release(pElement);
2990 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
2991 ok(hr == S_OK, "ret %08x\n", hr );
2994 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2996 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
2997 ok(hr == S_OK, "ret %08x\n", hr );
2999 IXMLDOMElement_Release(pElement);
3003 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3004 ok(hr == S_OK, "ret %08x\n", hr );
3007 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3009 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3010 ok(hr == S_OK, "ret %08x\n", hr );
3012 IXMLDOMElement_Release(pElement);
3016 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3017 ok(hr == S_OK, "ret %08x\n", hr );
3020 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3022 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3023 ok(hr == S_OK, "ret %08x\n", hr );
3025 IXMLDOMElement_Release(pElement);
3029 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3030 ok(hr == S_OK, "ret %08x\n", hr );
3033 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3035 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3036 ok(hr == S_OK, "ret %08x\n", hr );
3038 IXMLDOMElement_Release(pElement);
3042 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3043 ok(hr == S_OK, "ret %08x\n", hr );
3046 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3048 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3049 ok(hr == S_OK, "ret %08x\n", hr );
3051 IXMLDOMElement_Release(pElement);
3055 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3056 ok(hr == S_OK, "ret %08x\n", hr );
3059 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3061 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3062 ok(hr == S_OK, "ret %08x\n", hr );
3064 IXMLDOMElement_Release(pElement);
3068 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3069 ok(hr == S_OK, "ret %08x\n", hr );
3072 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3074 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3075 ok(hr == S_OK, "ret %08x\n", hr );
3077 IXMLDOMElement_Release(pElement);
3081 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3082 ok(hr == S_OK, "ret %08x\n", hr );
3085 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3087 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3088 ok(hr == S_OK, "ret %08x\n", hr );
3090 IXMLDOMElement_Release(pElement);
3094 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3095 ok(hr == S_OK, "ret %08x\n", hr );
3098 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3100 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3101 ok(hr == S_OK, "ret %08x\n", hr );
3103 IXMLDOMElement_Release(pElement);
3107 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3108 ok(hr == S_OK, "ret %08x\n", hr );
3111 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3113 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3114 ok(hr == S_OK, "ret %08x\n", hr );
3116 IXMLDOMElement_Release(pElement);
3120 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3121 ok(hr == S_OK, "ret %08x\n", hr );
3124 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3126 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3127 ok(hr == S_OK, "ret %08x\n", hr );
3129 IXMLDOMElement_Release(pElement);
3132 /* Check changing types */
3133 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3134 ok(hr == S_OK, "ret %08x\n", hr );
3137 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3139 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3140 ok(hr == S_OK, "ret %08x\n", hr );
3142 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3143 ok(hr == S_OK, "ret %08x\n", hr );
3145 IXMLDOMElement_Release(pElement);
3148 IXMLDOMElement_Release(pRoot);
3152 IXMLDOMDocument_Release(doc);
3157 static void test_DocumentSaveToDocument(void)
3159 IXMLDOMDocument *doc = NULL;
3160 IXMLDOMDocument *doc2 = NULL;
3161 IXMLDOMElement *pRoot;
3165 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3169 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3172 IXMLDOMDocument_Release(doc);
3176 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3177 ok(hr == S_OK, "ret %08x\n", hr );
3180 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3181 ok(hr == S_OK, "ret %08x\n", hr );
3188 V_VT(&vDoc) = VT_UNKNOWN;
3189 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3191 hr = IXMLDOMDocument_save(doc, vDoc);
3192 ok(hr == S_OK, "ret %08x\n", hr );
3194 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3195 ok(hr == S_OK, "ret %08x\n", hr );
3197 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3198 ok(hr == S_OK, "ret %08x\n", hr );
3200 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3202 SysFreeString(sOrig);
3203 SysFreeString(sNew);
3207 IXMLDOMDocument_Release(doc2);
3208 IXMLDOMDocument_Release(doc);
3211 static void test_testTransforms(void)
3213 IXMLDOMDocument *doc = NULL;
3214 IXMLDOMDocument *docSS = NULL;
3220 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3224 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3227 IXMLDOMDocument_Release(doc);
3231 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3232 ok(hr == S_OK, "ret %08x\n", hr );
3234 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3235 ok(hr == S_OK, "ret %08x\n", hr );
3237 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3238 ok(hr == S_OK, "ret %08x\n", hr );
3243 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3244 ok(hr == S_OK, "ret %08x\n", hr );
3245 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3247 IXMLDOMNode_Release(pNode);
3250 IXMLDOMDocument_Release(docSS);
3251 IXMLDOMDocument_Release(doc);
3256 static void test_Namespaces(void)
3258 IXMLDOMDocument2 *doc = NULL;
3260 IXMLDOMNode *pNode2 = NULL;
3264 static const CHAR szNamespacesXML[] =
3265 "<?xml version=\"1.0\"?>\n"
3266 "<root xmlns:WEB='http://www.winehq.org'>\n"
3267 "<WEB:Site version=\"1.0\" />\n"
3270 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3274 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3275 ok(hr == S_OK, "ret %08x\n", hr );
3276 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3278 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3279 ok(hr == S_OK, "ret %08x\n", hr );
3282 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3283 ok( hr == S_OK, "ret %08x\n", hr );
3284 ok( pNode2 != NULL, "pNode2 == NULL\n");
3286 /* Test get_prefix */
3287 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3288 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3289 /* NOTE: Need to test that arg2 gets cleared on Error. */
3291 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3292 ok( hr == S_OK, "ret %08x\n", hr );
3293 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3296 /* Test get_namespaceURI */
3297 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3298 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3299 /* NOTE: Need to test that arg2 gets cleared on Error. */
3301 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3302 ok( hr == S_OK, "ret %08x\n", hr );
3303 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3306 IXMLDOMNode_Release(pNode2);
3307 IXMLDOMNode_Release(pNode);
3310 IXMLDOMDocument2_Release(doc);
3319 r = CoInitialize( NULL );
3320 ok( r == S_OK, "failed to init com\n");
3326 test_getElementsByTagName();
3328 test_get_childNodes();
3331 test_IXMLDOMDocument2();
3335 test_nodeTypeTests();
3336 test_DocumentSaveToDocument();
3337 test_testTransforms();