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 /* try with a null out pointer */
481 r = IXMLDOMDocument_get_documentElement( doc, NULL );
482 ok( r == E_INVALIDARG, "should be no document element\n");
484 /* check if nodename is correct */
485 r = IXMLDOMDocument_get_nodeName( doc, NULL );
486 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
488 /* content doesn't matter here */
490 r = IXMLDOMDocument_get_nodeName( doc, &str );
491 ok ( r == S_OK, "get_nodeName wrong code\n");
492 ok ( str != NULL, "str is null\n");
493 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
494 SysFreeString( str );
497 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
498 ok( r == E_FAIL, "ret %08x\n", r );
500 /* check that there's a document element */
502 r = IXMLDOMDocument_get_documentElement( doc, &element );
503 ok( r == S_OK, "should be a document element\n");
508 /* check if the tag is correct */
509 r = IXMLDOMElement_get_tagName( element, &tag );
510 ok( r == S_OK, "couldn't get tag name\n");
511 ok( tag != NULL, "tag was null\n");
512 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
513 SysFreeString( tag );
515 /* figure out what happens if we try to reload the document */
516 str = SysAllocString( szComplete2 );
517 r = IXMLDOMDocument_loadXML( doc, str, &b );
518 ok( r == S_OK, "loadXML failed\n");
519 ok( b == VARIANT_TRUE, "failed to load XML string\n");
520 SysFreeString( str );
522 /* check if the tag is still correct */
524 r = IXMLDOMElement_get_tagName( element, &tag );
525 ok( r == S_OK, "couldn't get tag name\n");
526 ok( tag != NULL, "tag was null\n");
527 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
528 SysFreeString( tag );
530 IXMLDOMElement_Release( element );
534 /* as soon as we call loadXML again, the document element will disappear */
536 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
537 ok( r == S_FALSE, "loadXML failed\n");
538 ok( b == 2, "variant modified\n");
539 r = IXMLDOMDocument_get_documentElement( doc, &element );
540 ok( r == S_FALSE, "should be no document element\n");
542 /* try to load something else simple and valid */
544 str = SysAllocString( szComplete3 );
545 r = IXMLDOMDocument_loadXML( doc, str, &b );
546 ok( r == S_OK, "loadXML failed\n");
547 ok( b == VARIANT_TRUE, "failed to load XML string\n");
548 SysFreeString( str );
550 /* try something a little more complicated */
552 str = SysAllocString( szComplete4 );
553 r = IXMLDOMDocument_loadXML( doc, str, &b );
554 ok( r == S_OK, "loadXML failed\n");
555 ok( b == VARIANT_TRUE, "failed to load XML string\n");
556 SysFreeString( str );
558 r = IXMLDOMDocument_get_parseError( doc, &error );
559 ok( r == S_OK, "returns %08x\n", r );
561 r = IXMLDOMParseError_get_errorCode( error, &code );
562 ok( r == S_FALSE, "returns %08x\n", r );
563 ok( code == 0, "code %ld\n", code );
564 IXMLDOMParseError_Release( error );
566 /* test createTextNode */
567 str = SysAllocString( szOpen );
568 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
569 ok( r == E_INVALIDARG, "returns %08x\n", r );
570 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
571 ok( r == S_OK, "returns %08x\n", r );
572 SysFreeString( str );
575 IXMLDOMNamedNodeMap *pAttribs;
577 /* Text Last Child Checks */
578 r = IXMLDOMText_get_lastChild(nodetext, NULL);
579 ok(r == E_INVALIDARG, "ret %08x\n", r );
581 nodeChild = (IXMLDOMNode*)0x1;
582 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
583 ok(r == S_FALSE, "ret %08x\n", r );
584 ok(nodeChild == NULL, "nodeChild not NULL\n");
586 /* test get_attributes */
587 r = IXMLDOMText_get_attributes( nodetext, NULL );
588 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
590 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
591 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
592 ok(r == S_FALSE, "ret %08x\n", r );
593 ok( pAttribs == NULL, "pAttribs not NULL\n");
595 /* test get_dataType */
596 r = IXMLDOMText_get_dataType(nodetext, &var);
597 ok(r == S_FALSE, "ret %08x\n", r );
598 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
601 /* test length property */
602 r = IXMLDOMText_get_length(nodetext, NULL);
603 ok(r == E_INVALIDARG, "ret %08x\n", r );
605 r = IXMLDOMText_get_length(nodetext, &nLength);
606 ok(r == S_OK, "ret %08x\n", r );
607 ok(nLength == 4, "expected 4 got %ld\n", nLength);
609 /* test nodeTypeString */
610 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
611 ok(r == S_OK, "ret %08x\n", r );
612 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
616 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
617 ok(r == S_OK, "ret %08x\n", r );
620 r = IXMLDOMText_get_data(nodetext, &str);
621 ok(r == S_OK, "ret %08x\n", r );
622 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
625 /* Confirm XML text is good */
626 r = IXMLDOMText_get_xml(nodetext, &str);
627 ok(r == S_OK, "ret %08x\n", r );
628 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
631 /* Confirm we get the put_data Text back */
632 r = IXMLDOMText_get_text(nodetext, &str);
633 ok(r == S_OK, "ret %08x\n", r );
634 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
637 /* test substringData */
638 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
639 ok(r == E_INVALIDARG, "ret %08x\n", r );
641 /* test substringData - Invalid offset */
642 str = (BSTR)&szElement;
643 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
644 ok(r == E_INVALIDARG, "ret %08x\n", r );
645 ok( str == NULL, "incorrect string\n");
647 /* test substringData - Invalid offset */
648 str = (BSTR)&szElement;
649 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
650 ok(r == S_FALSE, "ret %08x\n", r );
651 ok( str == NULL, "incorrect string\n");
653 /* test substringData - Invalid size */
654 str = (BSTR)&szElement;
655 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
656 ok(r == E_INVALIDARG, "ret %08x\n", r );
657 ok( str == NULL, "incorrect string\n");
659 /* test substringData - Invalid size */
660 str = (BSTR)&szElement;
661 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
662 ok(r == S_FALSE, "ret %08x\n", r );
663 ok( str == NULL, "incorrect string\n");
665 /* test substringData - Start of string */
666 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
667 ok(r == S_OK, "ret %08x\n", r );
668 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
671 /* test substringData - Middle of string */
672 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
673 ok(r == S_OK, "ret %08x\n", r );
674 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
677 /* test substringData - End of string */
678 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
679 ok(r == S_OK, "ret %08x\n", r );
680 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
683 /* test appendData */
684 r = IXMLDOMText_appendData(nodetext, NULL);
685 ok(r == S_OK, "ret %08x\n", r );
687 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
688 ok(r == S_OK, "ret %08x\n", r );
690 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
691 ok(r == S_OK, "ret %08x\n", r );
693 r = IXMLDOMText_get_text(nodetext, &str);
694 ok(r == S_OK, "ret %08x\n", r );
695 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
698 /* test insertData */
699 str = SysAllocStringLen(NULL, 0);
700 r = IXMLDOMText_insertData(nodetext, -1, str);
701 ok(r == S_OK, "ret %08x\n", r );
703 r = IXMLDOMText_insertData(nodetext, -1, NULL);
704 ok(r == S_OK, "ret %08x\n", r );
706 r = IXMLDOMText_insertData(nodetext, 1000, str);
707 ok(r == S_OK, "ret %08x\n", r );
709 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
710 ok(r == S_OK, "ret %08x\n", r );
712 r = IXMLDOMText_insertData(nodetext, 0, NULL);
713 ok(r == S_OK, "ret %08x\n", r );
715 r = IXMLDOMText_insertData(nodetext, 0, str);
716 ok(r == S_OK, "ret %08x\n", r );
719 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
720 ok(r == E_INVALIDARG, "ret %08x\n", r );
722 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
723 ok(r == E_INVALIDARG, "ret %08x\n", r );
725 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
726 ok(r == S_OK, "ret %08x\n", r );
728 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
729 ok(r == S_OK, "ret %08x\n", r );
731 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
732 ok(r == S_OK, "ret %08x\n", r );
734 r = IXMLDOMText_get_text(nodetext, &str);
735 ok(r == S_OK, "ret %08x\n", r );
736 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
739 IXMLDOMText_Release( nodetext );
742 /* test Create Comment */
743 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
744 ok( r == E_INVALIDARG, "returns %08x\n", r );
745 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
746 ok( r == S_OK, "returns %08x\n", r );
749 /* Last Child Checks */
750 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
751 ok(r == E_INVALIDARG, "ret %08x\n", r );
753 nodeChild = (IXMLDOMNode*)0x1;
754 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
755 ok(r == S_FALSE, "ret %08x\n", r );
756 ok(nodeChild == NULL, "pLastChild not NULL\n");
758 IXMLDOMComment_Release( node_comment );
761 /* test Create Attribute */
762 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
763 ok( r == E_INVALIDARG, "returns %08x\n", r );
764 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
765 ok( r == S_OK, "returns %08x\n", r );
766 IXMLDOMText_Release( node_attr);
768 /* test Processing Instruction */
769 str = SysAllocStringLen(NULL, 0);
770 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
771 ok( r == E_INVALIDARG, "returns %08x\n", r );
772 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
773 ok( r == E_FAIL, "returns %08x\n", r );
774 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
775 ok( r == E_FAIL, "returns %08x\n", r );
778 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
779 ok( r == S_OK, "returns %08x\n", r );
782 /* Last Child Checks */
783 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
784 ok(r == E_INVALIDARG, "ret %08x\n", r );
786 nodeChild = (IXMLDOMNode*)0x1;
787 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
788 ok(r == S_FALSE, "ret %08x\n", r );
789 ok(nodeChild == NULL, "nodeChild not NULL\n");
791 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
792 ok(r == S_FALSE, "ret %08x\n", r );
793 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
797 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
798 ok(r == S_OK, "ret %08x\n", r );
799 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
803 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
804 ok(r == S_OK, "ret %08x\n", r );
805 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
808 /* test nodeTypeString */
809 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
810 ok(r == S_OK, "ret %08x\n", r );
811 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
814 /* test get_nodeValue */
815 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
816 ok(r == S_OK, "ret %08x\n", r );
817 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
821 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
822 ok(r == S_OK, "ret %08x\n", r );
823 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
827 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
828 ok(r == E_FAIL, "ret %08x\n", r );
831 V_VT(&var) = VT_BSTR;
832 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
833 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
834 ok(r == E_FAIL, "ret %08x\n", r );
837 /* test get nodeName */
838 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
839 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
840 ok(r == S_OK, "ret %08x\n", r );
843 IXMLDOMProcessingInstruction_Release(nodePI);
846 r = IXMLDOMDocument_Release( doc );
847 ok( r == 0, "document ref count incorrect\n");
852 static void test_domnode( void )
855 IXMLDOMDocument *doc = NULL, *owner = NULL;
856 IXMLDOMElement *element = NULL;
857 IXMLDOMNamedNodeMap *map = NULL;
858 IXMLDOMNode *node = NULL, *next = NULL;
859 IXMLDOMNodeList *list = NULL;
860 DOMNodeType type = NODE_INVALID;
866 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
867 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
872 str = SysAllocString( szComplete4 );
873 r = IXMLDOMDocument_loadXML( doc, str, &b );
874 ok( r == S_OK, "loadXML failed\n");
875 ok( b == VARIANT_TRUE, "failed to load XML string\n");
876 SysFreeString( str );
881 r = IXMLDOMNode_hasChildNodes( doc, &b );
882 ok( r == S_OK, "hasChildNoes bad return\n");
883 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
885 r = IXMLDOMDocument_get_documentElement( doc, &element );
886 ok( r == S_OK, "should be a document element\n");
887 ok( element != NULL, "should be an element\n");
890 ok( FALSE, "no document\n");
893 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
895 r = IXMLDOMNode_get_nodeValue( doc, NULL );
896 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
898 r = IXMLDOMNode_get_nodeValue( doc, &var );
899 ok( r == S_FALSE, "nextNode returned wrong code\n");
900 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
901 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
906 r = IXMLDOMNode_get_ownerDocument( element, &owner );
908 ok( r == S_OK, "get_ownerDocument return code\n");
910 ok( owner != doc, "get_ownerDocument return\n");
913 r = IXMLDOMNode_get_nodeType( element, &type);
914 ok( r == S_OK, "getNamedItem returned wrong code\n");
915 ok( type == NODE_ELEMENT, "node not an element\n");
918 r = IXMLDOMNode_get_baseName( element, &str );
919 ok( r == S_OK, "get_baseName returned wrong code\n");
920 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
923 /* check if nodename is correct */
924 r = IXMLDOMElement_get_nodeName( element, NULL );
925 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
927 /* content doesn't matter here */
929 r = IXMLDOMElement_get_nodeName( element, &str );
930 ok ( r == S_OK, "get_nodeName wrong code\n");
931 ok ( str != NULL, "str is null\n");
932 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
933 SysFreeString( str );
935 str = SysAllocString( szNonExistentFile );
938 r = IXMLDOMElement_getAttribute( element, str, &var );
939 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
940 ok( V_VT(&var) == VT_NULL, "vt = %x\n", V_VT(&var));
942 SysFreeString( str );
944 str = SysAllocString( szdl );
947 r = IXMLDOMElement_getAttribute( element, str, &var );
948 ok( r == S_OK, "getAttribute ret %08x\n", r );
949 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
950 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
951 VariantClear( &var );
953 r = IXMLDOMElement_getAttribute( element, NULL, &var );
954 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
956 r = IXMLDOMElement_getAttribute( element, str, NULL );
957 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
959 SysFreeString( str );
961 r = IXMLDOMElement_get_attributes( element, &map );
962 ok( r == S_OK, "get_attributes returned wrong code\n");
963 ok( map != NULL, "should be attributes\n");
966 r = IXMLDOMNode_hasChildNodes( element, &b );
967 ok( r == S_OK, "hasChildNoes bad return\n");
968 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
971 ok( FALSE, "no element\n");
975 ISupportErrorInfo *support_error;
976 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
977 ok( r == S_OK, "ret %08x\n", r );
979 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
982 ok( r == S_OK, "ret %08x\n", r );
984 ISupportErrorInfo_Release( support_error );
986 str = SysAllocString( szdl );
987 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
988 ok( r == S_OK, "getNamedItem returned wrong code\n");
989 ok( node != NULL, "should be attributes\n");
990 IXMLDOMNode_Release(node);
991 SysFreeString( str );
993 str = SysAllocString( szdl );
994 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
995 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
996 SysFreeString( str );
998 /* something that isn't in szComplete4 */
999 str = SysAllocString( szOpen );
1000 node = (IXMLDOMNode *) 1;
1001 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1002 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
1003 ok( node == NULL, "getNamedItem should have returned NULL\n");
1004 SysFreeString( str );
1006 /* test indexed access of attributes */
1007 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1008 ok ( r == S_OK, "get_length wrong code\n");
1009 ok ( count == 1, "get_length != 1\n");
1012 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1013 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1014 ok ( node == NULL, "there is no node\n");
1017 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1018 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1019 ok ( node == NULL, "there is no attribute\n");
1022 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1023 ok ( r == S_OK, "get_item (0) wrong code\n");
1024 ok ( node != NULL, "should be attribute\n");
1026 r = IXMLDOMNode_get_nodeName( node, NULL );
1027 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1029 /* content doesn't matter here */
1031 r = IXMLDOMNode_get_nodeName( node, &str );
1032 ok ( r == S_OK, "get_nodeName wrong code\n");
1033 ok ( str != NULL, "str is null\n");
1034 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1035 SysFreeString( str );
1037 /* test sequential access of attributes */
1039 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1040 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1041 ok ( node != NULL, "nextNode, should be attribute\n");
1043 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1044 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1045 ok ( node == NULL, "nextNode, there is no attribute\n");
1047 r = IXMLDOMNamedNodeMap_reset( map );
1048 ok ( r == S_OK, "reset should return S_OK\n");
1050 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1051 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1052 ok ( node != NULL, "nextNode, should be attribute\n");
1055 ok( FALSE, "no map\n");
1059 type = NODE_INVALID;
1060 r = IXMLDOMNode_get_nodeType( node, &type);
1061 ok( r == S_OK, "getNamedItem returned wrong code\n");
1062 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1065 r = IXMLDOMNode_get_baseName( node, NULL );
1066 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1069 r = IXMLDOMNode_get_baseName( node, &str );
1070 ok( r == S_OK, "get_baseName returned wrong code\n");
1071 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1072 SysFreeString( str );
1074 r = IXMLDOMNode_get_nodeValue( node, &var );
1075 ok( r == S_OK, "returns %08x\n", r );
1076 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1077 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1080 r = IXMLDOMNode_get_childNodes( node, NULL );
1081 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1083 r = IXMLDOMNode_get_childNodes( node, &list );
1084 ok( r == S_OK, "get_childNodes returned wrong code\n");
1088 r = IXMLDOMNodeList_nextNode( list, &next );
1089 ok( r == S_OK, "nextNode returned wrong code\n");
1092 ok( FALSE, "no childlist\n");
1097 r = IXMLDOMNode_hasChildNodes( next, &b );
1098 ok( r == S_FALSE, "hasChildNoes bad return\n");
1099 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1101 type = NODE_INVALID;
1102 r = IXMLDOMNode_get_nodeType( next, &type);
1103 ok( r == S_OK, "getNamedItem returned wrong code\n");
1104 ok( type == NODE_TEXT, "node not text\n");
1107 r = IXMLDOMNode_get_baseName( next, &str );
1108 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1109 ok( str == NULL, "basename was wrong\n");
1113 ok( FALSE, "no next\n");
1116 IXMLDOMNode_Release( next );
1119 IXMLDOMNodeList_Release( list );
1122 IXMLDOMNode_Release( node );
1125 ok( FALSE, "no node\n");
1129 IXMLDOMNamedNodeMap_Release( map );
1131 /* now traverse the tree from the root element */
1135 r = IXMLDOMNode_get_childNodes( element, &list );
1136 ok( r == S_OK, "get_childNodes returned wrong code\n");
1138 /* using get_item for child list doesn't advance the position */
1139 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1140 expect_node(node, "E2.E2.D1");
1141 IXMLDOMNode_Release(node);
1142 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1143 expect_node(node, "E1.E2.D1");
1144 IXMLDOMNode_Release(node);
1145 ole_check(IXMLDOMNodeList_reset(list));
1147 IXMLDOMNodeList_AddRef(list);
1148 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1149 ole_check(IXMLDOMNodeList_reset(list));
1152 ok( FALSE, "no element\n");
1154 node = (void*)0xdeadbeef;
1155 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1156 ok( r == S_FALSE, "ret %08x\n", r );
1157 ok( node == NULL, "node %p\n", node );
1158 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1159 ok( r == S_OK, "ret %08x\n", r );
1160 r = IXMLDOMNode_Release( node );
1161 ok( r == 0, "ret %08x\n", r );
1165 r = IXMLDOMNodeList_get_length( list, &count );
1166 ok( r == S_OK, "get_length returns %08x\n", r );
1167 ok( count == 4, "get_length got %ld\n", count );
1169 r = IXMLDOMNodeList_nextNode( list, &node );
1170 ok( r == S_OK, "nextNode returned wrong code\n");
1173 ok( FALSE, "no list\n");
1177 type = NODE_INVALID;
1178 r = IXMLDOMNode_get_nodeType( node, &type);
1179 ok( r == S_OK, "getNamedItem returned wrong code\n");
1180 ok( type == NODE_ELEMENT, "node not text\n");
1183 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1184 r = IXMLDOMNode_get_nodeValue( node, &var );
1185 ok( r == S_FALSE, "nextNode returned wrong code\n");
1186 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1187 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1189 r = IXMLDOMNode_hasChildNodes( node, NULL );
1190 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1193 r = IXMLDOMNode_hasChildNodes( node, &b );
1194 ok( r == S_OK, "hasChildNoes bad return\n");
1195 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1198 r = IXMLDOMNode_get_baseName( node, &str );
1199 ok( r == S_OK, "get_baseName returned wrong code\n");
1200 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1204 ok( FALSE, "no node\n");
1207 IXMLDOMNode_Release( node );
1209 IXMLDOMNodeList_Release( list );
1211 IXMLDOMElement_Release( element );
1214 str = SysAllocString( szComplete5 );
1215 r = IXMLDOMDocument_loadXML( doc, str, &b );
1216 ok( r == S_OK, "loadXML failed\n");
1217 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1218 SysFreeString( str );
1221 r = IXMLDOMNode_hasChildNodes( doc, &b );
1222 ok( r == S_OK, "hasChildNoes bad return\n");
1223 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1225 r = IXMLDOMDocument_get_documentElement( doc, &element );
1226 ok( r == S_OK, "should be a document element\n");
1227 ok( element != NULL, "should be an element\n");
1231 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1234 /* check if the tag is correct */
1235 r = IXMLDOMElement_get_tagName( element, &tag );
1236 ok( r == S_OK, "couldn't get tag name\n");
1237 ok( tag != NULL, "tag was null\n");
1238 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1239 SysFreeString( tag );
1243 IXMLDOMElement_Release( element );
1245 IXMLDOMDocument_Release( doc );
1248 static void test_refs(void)
1253 IXMLDOMDocument *doc = NULL;
1254 IXMLDOMElement *element = NULL;
1255 IXMLDOMNode *node = NULL, *node2;
1256 IXMLDOMNodeList *node_list = NULL;
1258 IUnknown *unk, *unk2;
1260 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1261 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1264 ref = IXMLDOMDocument_Release(doc);
1265 ok( ref == 0, "ref %d\n", ref);
1267 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1268 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1272 str = SysAllocString( szComplete4 );
1273 r = IXMLDOMDocument_loadXML( doc, str, &b );
1274 ok( r == S_OK, "loadXML failed\n");
1275 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1276 SysFreeString( str );
1278 ref = IXMLDOMDocument_AddRef( doc );
1279 ok( ref == 2, "ref %d\n", ref );
1280 ref = IXMLDOMDocument_AddRef( doc );
1281 ok( ref == 3, "ref %d\n", ref );
1282 IXMLDOMDocument_Release( doc );
1283 IXMLDOMDocument_Release( doc );
1285 r = IXMLDOMDocument_get_documentElement( doc, &element );
1286 ok( r == S_OK, "should be a document element\n");
1287 ok( element != NULL, "should be an element\n");
1289 ref = IXMLDOMDocument_AddRef( doc );
1290 ok( ref == 2, "ref %d\n", ref );
1291 IXMLDOMDocument_Release( doc );
1293 r = IXMLDOMElement_get_childNodes( element, &node_list );
1294 ok( r == S_OK, "rets %08x\n", r);
1295 ref = IXMLDOMNodeList_AddRef( node_list );
1296 ok( ref == 2, "ref %d\n", ref );
1297 IXMLDOMNodeList_Release( node_list );
1299 IXMLDOMNodeList_get_item( node_list, 0, &node );
1300 ok( r == S_OK, "rets %08x\n", r);
1302 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1303 ok( r == S_OK, "rets %08x\n", r);
1305 ref = IXMLDOMNode_AddRef( node );
1306 ok( ref == 2, "ref %d\n", ref );
1307 IXMLDOMNode_Release( node );
1309 ref = IXMLDOMNode_Release( node );
1310 ok( ref == 0, "ref %d\n", ref );
1311 ref = IXMLDOMNode_Release( node2 );
1312 ok( ref == 0, "ref %d\n", ref );
1314 ref = IXMLDOMNodeList_Release( node_list );
1315 ok( ref == 0, "ref %d\n", ref );
1317 ok( node != node2, "node %p node2 %p\n", node, node2 );
1319 ref = IXMLDOMDocument_Release( doc );
1320 ok( ref == 0, "ref %d\n", ref );
1322 ref = IXMLDOMElement_AddRef( element );
1324 ok( ref == 3, "ref %d\n", ref );
1326 IXMLDOMElement_Release( element );
1328 /* IUnknown must be unique however we obtain it */
1329 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1330 ok( r == S_OK, "rets %08x\n", r );
1331 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1332 ok( r == S_OK, "rets %08x\n", r );
1333 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1334 ok( r == S_OK, "rets %08x\n", r );
1335 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1337 IUnknown_Release( unk2 );
1338 IUnknown_Release( unk );
1339 IXMLDOMNode_Release( node );
1341 IXMLDOMElement_Release( element );
1345 static void test_create(void)
1350 IXMLDOMDocument *doc;
1351 IXMLDOMElement *element;
1352 IXMLDOMNode *root, *node, *child;
1353 IXMLDOMNamedNodeMap *attr_map;
1358 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1359 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1364 V_I4(&var) = NODE_ELEMENT;
1365 str = SysAllocString( szlc );
1366 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1367 ok( r == S_OK, "returns %08x\n", r );
1368 r = IXMLDOMDocument_appendChild( doc, node, &root );
1369 ok( r == S_OK, "returns %08x\n", r );
1370 ok( node == root, "%p %p\n", node, root );
1372 ref = IXMLDOMNode_AddRef( node );
1373 ok(ref == 3, "ref %d\n", ref);
1374 IXMLDOMNode_Release( node );
1376 ref = IXMLDOMNode_Release( node );
1377 ok(ref == 1, "ref %d\n", ref);
1378 SysFreeString( str );
1381 V_I4(&var) = NODE_ELEMENT;
1382 str = SysAllocString( szbs );
1383 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1384 ok( r == S_OK, "returns %08x\n", r );
1386 ref = IXMLDOMNode_AddRef( node );
1387 ok(ref == 2, "ref = %d\n", ref);
1388 IXMLDOMNode_Release( node );
1390 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1391 ok( r == S_OK, "returns %08x\n", r );
1393 ref = IXMLDOMNode_AddRef( unk );
1394 ok(ref == 3, "ref = %d\n", ref);
1395 IXMLDOMNode_Release( unk );
1397 V_VT(&var) = VT_EMPTY;
1398 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1399 ok( r == S_OK, "returns %08x\n", r );
1400 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1401 IXMLDOMNode_Release( child );
1402 IUnknown_Release( unk );
1405 V_VT(&var) = VT_NULL;
1406 V_DISPATCH(&var) = (IDispatch*)node;
1407 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1408 ok( r == S_OK, "returns %08x\n", r );
1409 ok( node == child, "%p %p\n", node, child );
1410 IXMLDOMNode_Release( child );
1413 V_VT(&var) = VT_NULL;
1414 V_DISPATCH(&var) = (IDispatch*)node;
1415 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1416 ok( r == S_OK, "returns %08x\n", r );
1417 IXMLDOMNode_Release( node );
1419 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1420 ok( r == S_OK, "returns %08x\n", r );
1422 r = IXMLDOMElement_get_attributes( element, &attr_map );
1423 ok( r == S_OK, "returns %08x\n", r );
1424 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1425 ok( r == S_OK, "returns %08x\n", r );
1426 ok( num == 0, "num %ld\n", num );
1427 IXMLDOMNamedNodeMap_Release( attr_map );
1429 V_VT(&var) = VT_BSTR;
1430 V_BSTR(&var) = SysAllocString( szstr1 );
1431 name = SysAllocString( szdl );
1432 r = IXMLDOMElement_setAttribute( element, name, var );
1433 ok( r == S_OK, "returns %08x\n", r );
1434 r = IXMLDOMElement_get_attributes( element, &attr_map );
1435 ok( r == S_OK, "returns %08x\n", r );
1436 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1437 ok( r == S_OK, "returns %08x\n", r );
1438 ok( num == 1, "num %ld\n", num );
1439 IXMLDOMNamedNodeMap_Release( attr_map );
1442 V_VT(&var) = VT_BSTR;
1443 V_BSTR(&var) = SysAllocString( szstr2 );
1444 r = IXMLDOMElement_setAttribute( element, name, var );
1445 ok( r == S_OK, "returns %08x\n", r );
1446 r = IXMLDOMElement_get_attributes( element, &attr_map );
1447 ok( r == S_OK, "returns %08x\n", r );
1448 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1449 ok( r == S_OK, "returns %08x\n", r );
1450 ok( num == 1, "num %ld\n", num );
1451 IXMLDOMNamedNodeMap_Release( attr_map );
1453 r = IXMLDOMElement_getAttribute( element, name, &var );
1454 ok( r == S_OK, "returns %08x\n", r );
1455 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1457 SysFreeString(name);
1459 V_VT(&var) = VT_BSTR;
1460 V_BSTR(&var) = SysAllocString( szstr1 );
1461 name = SysAllocString( szlc );
1462 r = IXMLDOMElement_setAttribute( element, name, var );
1463 ok( r == S_OK, "returns %08x\n", r );
1464 r = IXMLDOMElement_get_attributes( element, &attr_map );
1465 ok( r == S_OK, "returns %08x\n", r );
1466 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1467 ok( r == S_OK, "returns %08x\n", r );
1468 ok( num == 2, "num %ld\n", num );
1469 IXMLDOMNamedNodeMap_Release( attr_map );
1471 SysFreeString(name);
1475 name = SysAllocString( szbs );
1476 r = IXMLDOMElement_setAttribute( element, name, var );
1477 ok( r == S_OK, "returns %08x\n", r );
1479 r = IXMLDOMElement_getAttribute( element, name, &var );
1480 ok( r == S_OK, "returns %08x\n", r );
1481 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1483 SysFreeString(name);
1485 IXMLDOMElement_Release( element );
1486 IXMLDOMNode_Release( root );
1487 IXMLDOMDocument_Release( doc );
1490 static void test_getElementsByTagName(void)
1495 IXMLDOMDocument *doc;
1496 IXMLDOMNodeList *node_list;
1499 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1500 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1504 str = SysAllocString( szComplete4 );
1505 r = IXMLDOMDocument_loadXML( doc, str, &b );
1506 ok( r == S_OK, "loadXML failed\n");
1507 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1508 SysFreeString( str );
1510 str = SysAllocString( szstar );
1511 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1512 ok( r == S_OK, "ret %08x\n", r );
1513 r = IXMLDOMNodeList_get_length( node_list, &len );
1514 ok( r == S_OK, "ret %08x\n", r );
1515 ok( len == 6, "len %ld\n", len );
1516 IXMLDOMNodeList_Release( node_list );
1517 SysFreeString( str );
1519 str = SysAllocString( szbs );
1520 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1521 ok( r == S_OK, "ret %08x\n", r );
1522 r = IXMLDOMNodeList_get_length( node_list, &len );
1523 ok( r == S_OK, "ret %08x\n", r );
1524 ok( len == 1, "len %ld\n", len );
1525 IXMLDOMNodeList_Release( node_list );
1526 SysFreeString( str );
1528 str = SysAllocString( szdl );
1529 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1530 ok( r == S_OK, "ret %08x\n", r );
1531 r = IXMLDOMNodeList_get_length( node_list, &len );
1532 ok( r == S_OK, "ret %08x\n", r );
1533 ok( len == 0, "len %ld\n", len );
1534 IXMLDOMNodeList_Release( node_list );
1535 SysFreeString( str );
1537 str = SysAllocString( szstr1 );
1538 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1539 ok( r == S_OK, "ret %08x\n", r );
1540 r = IXMLDOMNodeList_get_length( node_list, &len );
1541 ok( r == S_OK, "ret %08x\n", r );
1542 ok( len == 0, "len %ld\n", len );
1543 IXMLDOMNodeList_Release( node_list );
1544 SysFreeString( str );
1546 IXMLDOMDocument_Release( doc );
1549 static void test_get_text(void)
1554 IXMLDOMDocument *doc;
1555 IXMLDOMNode *node, *node2, *node3;
1556 IXMLDOMNodeList *node_list;
1557 IXMLDOMNamedNodeMap *node_map;
1559 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1560 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1564 str = SysAllocString( szComplete4 );
1565 r = IXMLDOMDocument_loadXML( doc, str, &b );
1566 ok( r == S_OK, "loadXML failed\n");
1567 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1568 SysFreeString( str );
1570 str = SysAllocString( szbs );
1571 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1572 ok( r == S_OK, "ret %08x\n", r );
1575 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1576 ok( r == S_OK, "ret %08x\n", r );
1577 IXMLDOMNodeList_Release( node_list );
1579 /* Invalid output parameter*/
1580 r = IXMLDOMNode_get_text( node, NULL );
1581 ok( r == E_INVALIDARG, "ret %08x\n", r );
1583 r = IXMLDOMNode_get_text( node, &str );
1584 ok( r == S_OK, "ret %08x\n", r );
1586 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
1588 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
1591 r = IXMLDOMNode_get_attributes( node, &node_map );
1592 ok( r == S_OK, "ret %08x\n", r );
1594 str = SysAllocString( szvr );
1595 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1596 ok( r == S_OK, "ret %08x\n", r );
1599 r = IXMLDOMNode_get_text( node2, &str );
1600 ok( r == S_OK, "ret %08x\n", r );
1601 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1604 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1605 ok( r == S_OK, "ret %08x\n", r );
1607 r = IXMLDOMNode_get_text( node3, &str );
1608 ok( r == S_OK, "ret %08x\n", r );
1609 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1613 IXMLDOMNode_Release( node3 );
1614 IXMLDOMNode_Release( node2 );
1615 IXMLDOMNamedNodeMap_Release( node_map );
1616 IXMLDOMNode_Release( node );
1617 IXMLDOMDocument_Release( doc );
1620 static void test_get_childNodes(void)
1625 IXMLDOMDocument *doc;
1626 IXMLDOMElement *element;
1627 IXMLDOMNode *node, *node2;
1628 IXMLDOMNodeList *node_list, *node_list2;
1631 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1632 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1636 str = SysAllocString( szComplete4 );
1637 r = IXMLDOMDocument_loadXML( doc, str, &b );
1638 ok( r == S_OK, "loadXML failed\n");
1639 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1640 SysFreeString( str );
1642 r = IXMLDOMDocument_get_documentElement( doc, &element );
1643 ok( r == S_OK, "ret %08x\n", r);
1645 r = IXMLDOMElement_get_childNodes( element, &node_list );
1646 ok( r == S_OK, "ret %08x\n", r);
1648 r = IXMLDOMNodeList_get_length( node_list, &len );
1649 ok( r == S_OK, "ret %08x\n", r);
1650 ok( len == 4, "len %ld\n", len);
1652 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1653 ok( r == S_OK, "ret %08x\n", r);
1655 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1656 ok( r == S_OK, "ret %08x\n", r);
1658 r = IXMLDOMNodeList_get_length( node_list2, &len );
1659 ok( r == S_OK, "ret %08x\n", r);
1660 ok( len == 0, "len %ld\n", len);
1662 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1663 ok( r == S_FALSE, "ret %08x\n", r);
1665 IXMLDOMNodeList_Release( node_list2 );
1666 IXMLDOMNode_Release( node );
1667 IXMLDOMNodeList_Release( node_list );
1668 IXMLDOMElement_Release( element );
1669 IXMLDOMDocument_Release( doc );
1672 static void test_removeChild(void)
1677 IXMLDOMDocument *doc;
1678 IXMLDOMElement *element;
1679 IXMLDOMNode *node, *node2, *node3, *node4;
1680 IXMLDOMNodeList *node_list, *node_list2;
1682 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1683 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1687 str = SysAllocString( szComplete4 );
1688 r = IXMLDOMDocument_loadXML( doc, str, &b );
1689 ok( r == S_OK, "loadXML failed\n");
1690 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1691 SysFreeString( str );
1693 r = IXMLDOMDocument_get_documentElement( doc, &element );
1694 ok( r == S_OK, "ret %08x\n", r);
1696 r = IXMLDOMElement_get_childNodes( element, &node_list );
1697 ok( r == S_OK, "ret %08x\n", r);
1699 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1700 ok( r == S_OK, "ret %08x\n", r);
1702 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1703 ok( r == S_OK, "ret %08x\n", r);
1705 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1706 ok( r == S_OK, "ret %08x\n", r);
1708 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1709 ok( r == E_INVALIDARG, "ret %08x\n", r );
1711 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1712 ok( r == S_OK, "ret %08x\n", r);
1713 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1715 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1716 ok( r == S_FALSE, "ret %08x\n", r);
1717 ok( node3 == NULL, "%p\n", node3 );
1719 IXMLDOMNode_Release( node2 );
1720 IXMLDOMNode_Release( node4 );
1721 IXMLDOMNodeList_Release( node_list2 );
1722 IXMLDOMNode_Release( node );
1723 IXMLDOMNodeList_Release( node_list );
1724 IXMLDOMElement_Release( element );
1725 IXMLDOMDocument_Release( doc );
1728 static void test_XMLHTTP(void)
1730 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1731 static WCHAR wszPOST[] = {'P','O','S','T',0};
1732 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1733 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1734 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1735 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1736 IXMLHttpRequest *pXMLHttpRequest;
1741 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1742 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1743 (void **)&pXMLHttpRequest);
1745 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1750 VariantInit(&dummy);
1751 V_VT(&dummy) = VT_ERROR;
1752 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1753 VariantInit(&varfalse);
1754 V_VT(&varfalse) = VT_BOOL;
1755 V_BOOL(&varfalse) = VARIANT_FALSE;
1756 V_VT(&varbody) = VT_BSTR;
1757 V_BSTR(&varbody) = SysAllocString(wszBody);
1759 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1760 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1762 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1763 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1764 VariantClear(&varbody);
1766 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1767 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1768 /* the server currently returns "FAILED" because the Content-Type header is
1769 * not what the server expects */
1770 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1771 SysFreeString(bstrResponse);
1774 static void test_IXMLDOMDocument2(void)
1779 IXMLDOMDocument *doc;
1780 IXMLDOMDocument2 *doc2;
1784 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1785 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1789 str = SysAllocString( szComplete4 );
1790 r = IXMLDOMDocument_loadXML( doc, str, &b );
1791 ok( r == S_OK, "loadXML failed\n");
1792 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1793 SysFreeString( str );
1795 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1796 ok( r == S_OK, "ret %08x\n", r );
1797 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1799 /* we will check if the variant got cleared */
1800 ref = IXMLDOMDocument2_AddRef(doc2);
1801 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1802 V_VT(&var) = VT_UNKNOWN;
1803 V_UNKNOWN(&var) = (IUnknown *)doc2;
1806 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1807 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1808 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1811 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1812 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1813 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1816 /* the variant didn't get cleared*/
1817 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1819 /* setProperty tests */
1820 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1821 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1822 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1823 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1824 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1825 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1827 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
1828 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1829 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1830 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1832 IXMLDOMDocument2_Release( doc2 );
1833 IXMLDOMDocument_Release( doc );
1837 static void test_XPath(void)
1842 IXMLDOMDocument2 *doc;
1843 IXMLDOMNode *rootNode;
1844 IXMLDOMNode *elem1Node;
1846 IXMLDOMNodeList *list;
1848 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1849 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1853 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1854 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1856 /* switch to XPath */
1857 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1859 /* some simple queries*/
1860 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1861 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1862 ole_check(IXMLDOMNodeList_reset(list));
1863 expect_list_and_release(list, "E2.D1");
1864 if (rootNode == NULL)
1867 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1868 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1870 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1871 expect_list_and_release(list, "E3.E2.E2.D1");
1873 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1874 /* using get_item for query results advances the position */
1875 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1876 expect_node(node, "E2.E2.D1");
1877 IXMLDOMNode_Release(node);
1878 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1879 expect_node(node, "E4.E2.D1");
1880 IXMLDOMNode_Release(node);
1881 ole_check(IXMLDOMNodeList_reset(list));
1882 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1884 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
1885 expect_list_and_release(list, "E2.D1");
1887 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
1888 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
1889 ole_check(IXMLDOMNodeList_reset(list));
1890 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1892 /* select an attribute */
1893 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
1894 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
1896 /* would evaluate to a number */
1897 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
1898 /* would evaluate to a boolean */
1899 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
1900 /* would evaluate to a string */
1901 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
1904 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
1905 expect_list_and_release(list, "");
1906 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
1907 expect_list_and_release(list, "");
1908 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
1909 expect_list_and_release(list, "");
1911 /* foo undeclared in document node */
1912 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1913 /* undeclared in <root> node */
1914 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
1915 /* undeclared in <elem> node */
1916 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
1917 /* but this trick can be used */
1918 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
1919 expect_list_and_release(list, "E3.E4.E2.D1");
1921 /* it has to be declared in SelectionNamespaces */
1922 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1923 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
1925 /* now the namespace can be used */
1926 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//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(rootNode, _bstr_(".//test:c"), &list));
1929 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1930 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
1931 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1932 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
1933 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
1935 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
1936 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1937 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
1939 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1942 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
1943 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1944 if (V_VT(&var) == VT_BSTR)
1945 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
1947 /* extra attributes - same thing*/
1948 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1949 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
1950 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1952 IXMLDOMNode_Release(rootNode);
1953 IXMLDOMNode_Release(elem1Node);
1954 IXMLDOMDocument_Release(doc);
1958 static void test_cloneNode(void )
1960 IXMLDOMDocument *doc = NULL;
1962 IXMLDOMNodeList *pList;
1963 IXMLDOMNamedNodeMap *mapAttr;
1964 long nLength = 0, nLength1 = 0;
1965 long nAttrCnt = 0, nAttrCnt1 = 0;
1967 IXMLDOMNode *node_clone;
1970 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
1972 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1976 str = SysAllocString( szComplete4 );
1977 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
1978 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1984 str = SysAllocString( szSearch);
1985 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
1986 ok( r == S_OK, "ret %08x\n", r );
1987 ok( node != NULL, "node %p\n", node );
1992 IXMLDOMDocument_Release(doc);
1996 /* Check invalid parameter */
1997 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
1998 ok( r == E_INVALIDARG, "ret %08x\n", r );
2001 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2002 ok( r == S_OK, "ret %08x\n", r );
2003 ok( node_clone != NULL, "node %p\n", node );
2007 IXMLDOMDocument_Release(doc);
2008 IXMLDOMNode_Release(node);
2012 r = IXMLDOMNode_get_childNodes(node, &pList);
2013 ok( r == S_OK, "ret %08x\n", r );
2016 IXMLDOMNodeList_get_length(pList, &nLength);
2017 IXMLDOMNodeList_Release(pList);
2020 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2021 ok( r == S_OK, "ret %08x\n", r );
2024 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2025 IXMLDOMNamedNodeMap_Release(mapAttr);
2028 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2029 ok( r == S_OK, "ret %08x\n", r );
2032 IXMLDOMNodeList_get_length(pList, &nLength1);
2033 IXMLDOMNodeList_Release(pList);
2036 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2037 ok( r == S_OK, "ret %08x\n", r );
2040 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2041 IXMLDOMNamedNodeMap_Release(mapAttr);
2044 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2045 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2046 IXMLDOMNode_Release(node_clone);
2049 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2050 ok( r == S_OK, "ret %08x\n", r );
2051 ok( node_clone != NULL, "node %p\n", node );
2055 IXMLDOMDocument_Release(doc);
2056 IXMLDOMNode_Release(node);
2060 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2061 ok( r == S_OK, "ret %08x\n", r );
2064 IXMLDOMNodeList_get_length(pList, &nLength1);
2065 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
2066 IXMLDOMNodeList_Release(pList);
2069 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2070 ok( r == S_OK, "ret %08x\n", r );
2073 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2074 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
2075 IXMLDOMNamedNodeMap_Release(mapAttr);
2078 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2079 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2080 IXMLDOMNode_Release(node_clone);
2083 IXMLDOMNode_Release(node);
2084 IXMLDOMDocument_Release(doc);
2087 static void test_xmlTypes(void)
2089 IXMLDOMDocument *doc = NULL;
2090 IXMLDOMElement *pRoot;
2092 IXMLDOMComment *pComment;
2093 IXMLDOMElement *pElement;
2094 IXMLDOMAttribute *pAttrubute;
2095 IXMLDOMNamedNodeMap *pAttribs;
2096 IXMLDOMCDATASection *pCDataSec;
2097 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2098 IXMLDOMDocumentFragment *pDocFrag = NULL;
2099 IXMLDOMEntityReference *pEntityRef = NULL;
2101 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2105 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2109 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2110 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2112 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2113 ok(hr == S_FALSE, "ret %08x\n", hr );
2114 ok(pNextChild == NULL, "pDocChild not NULL\n");
2116 /* test previous Sibling */
2117 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2118 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2120 pNextChild = (IXMLDOMNode *)0x1;
2121 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2122 ok(hr == S_FALSE, "ret %08x\n", hr );
2123 ok(pNextChild == NULL, "pNextChild not NULL\n");
2125 /* test get_attributes */
2126 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2127 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2129 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2130 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2131 ok(hr == S_FALSE, "ret %08x\n", hr );
2132 ok( pAttribs == NULL, "pAttribs not NULL\n");
2134 /* test get_dataType */
2135 hr = IXMLDOMDocument_get_dataType(doc, &v);
2136 ok(hr == S_FALSE, "ret %08x\n", hr );
2137 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2140 /* test nodeTypeString */
2141 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2142 ok(hr == S_OK, "ret %08x\n", hr );
2143 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2146 /* test implementation */
2147 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2148 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2150 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2151 ok(hr == S_OK, "ret %08x\n", hr );
2154 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2155 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2157 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2158 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2160 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2161 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2163 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2164 ok(hr == S_OK, "ret %08x\n", hr );
2165 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2167 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2168 ok(hr == S_OK, "ret %08x\n", hr );
2169 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2171 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2172 ok(hr == S_OK, "ret %08x\n", hr );
2173 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2175 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2176 ok(hr == S_OK, "ret %08x\n", hr );
2177 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2179 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _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_("XML"), _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_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2188 ok(hr == S_OK, "ret %08x\n", hr );
2189 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2191 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2192 ok(hr == S_OK, "ret %08x\n", hr );
2193 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2195 SysFreeString(sEmpty);
2196 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2201 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2202 ok(hr == S_OK, "ret %08x\n", hr );
2205 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2206 ok(hr == S_OK, "ret %08x\n", hr );
2210 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2211 ok(hr == S_OK, "ret %08x\n", hr );
2214 /* test get_attributes */
2215 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2216 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2218 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2219 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2220 ok(hr == S_FALSE, "ret %08x\n", hr );
2221 ok( pAttribs == NULL, "pAttribs not NULL\n");
2223 /* test nodeTypeString */
2224 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2225 ok(hr == S_OK, "ret %08x\n", hr );
2226 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2229 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2230 ok(hr == S_OK, "ret %08x\n", hr );
2232 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2233 ok(hr == S_OK, "ret %08x\n", hr );
2234 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2237 hr = IXMLDOMComment_get_xml(pComment, &str);
2238 ok(hr == S_OK, "ret %08x\n", hr );
2239 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2242 hr = IXMLDOMComment_get_dataType(pComment, &v);
2243 ok(hr == S_FALSE, "ret %08x\n", hr );
2244 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2247 /* put data Tests */
2248 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2249 ok(hr == S_OK, "ret %08x\n", hr );
2251 /* get data Tests */
2252 hr = IXMLDOMComment_get_data(pComment, &str);
2253 ok(hr == S_OK, "ret %08x\n", hr );
2254 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2257 /* get data Tests */
2258 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2259 ok(hr == S_OK, "ret %08x\n", hr );
2260 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2261 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2264 /* Confirm XML text is good */
2265 hr = IXMLDOMComment_get_xml(pComment, &str);
2266 ok(hr == S_OK, "ret %08x\n", hr );
2267 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2270 /* Confirm we get the put_data Text back */
2271 hr = IXMLDOMComment_get_text(pComment, &str);
2272 ok(hr == S_OK, "ret %08x\n", hr );
2273 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2276 /* test length property */
2277 hr = IXMLDOMComment_get_length(pComment, &len);
2278 ok(hr == S_OK, "ret %08x\n", hr );
2279 ok(len == 21, "expected 21 got %ld\n", len);
2281 /* test substringData */
2282 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2283 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2285 /* test substringData - Invalid offset */
2286 str = (BSTR)&szElement;
2287 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2288 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2289 ok( str == NULL, "incorrect string\n");
2291 /* test substringData - Invalid offset */
2292 str = (BSTR)&szElement;
2293 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2294 ok(hr == S_FALSE, "ret %08x\n", hr );
2295 ok( str == NULL, "incorrect string\n");
2297 /* test substringData - Invalid size */
2298 str = (BSTR)&szElement;
2299 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2300 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2301 ok( str == NULL, "incorrect string\n");
2303 /* test substringData - Invalid size */
2304 str = (BSTR)&szElement;
2305 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2306 ok(hr == S_FALSE, "ret %08x\n", hr );
2307 ok( str == NULL, "incorrect string\n");
2309 /* test substringData - Start of string */
2310 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2311 ok(hr == S_OK, "ret %08x\n", hr );
2312 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2315 /* test substringData - Middle of string */
2316 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2317 ok(hr == S_OK, "ret %08x\n", hr );
2318 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2321 /* test substringData - End of string */
2322 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2323 ok(hr == S_OK, "ret %08x\n", hr );
2324 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2327 /* test appendData */
2328 hr = IXMLDOMComment_appendData(pComment, NULL);
2329 ok(hr == S_OK, "ret %08x\n", hr );
2331 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2332 ok(hr == S_OK, "ret %08x\n", hr );
2334 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2335 ok(hr == S_OK, "ret %08x\n", hr );
2337 hr = IXMLDOMComment_get_text(pComment, &str);
2338 ok(hr == S_OK, "ret %08x\n", hr );
2339 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2342 IXMLDOMComment_Release(pComment);
2346 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2347 ok(hr == S_OK, "ret %08x\n", hr );
2350 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2351 ok(hr == S_OK, "ret %08x\n", hr );
2353 /* test nodeTypeString */
2354 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2355 ok(hr == S_OK, "ret %08x\n", hr );
2356 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2359 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2360 ok(hr == S_OK, "ret %08x\n", hr );
2361 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2364 hr = IXMLDOMElement_get_xml(pElement, &str);
2365 ok(hr == S_OK, "ret %08x\n", hr );
2366 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2369 hr = IXMLDOMElement_get_dataType(pElement, &v);
2370 ok(hr == S_FALSE, "ret %08x\n", hr );
2371 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2375 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2376 ok(hr == S_OK, "ret %08x\n", hr );
2379 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2381 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2382 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2384 pNextChild = (IXMLDOMNode *)0x1;
2385 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2386 ok(hr == S_FALSE, "ret %08x\n", hr );
2387 ok(pNextChild == NULL, "pNextChild not NULL\n");
2389 /* test Previous Sibling*/
2390 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2391 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2393 pNextChild = (IXMLDOMNode *)0x1;
2394 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2395 ok(hr == S_FALSE, "ret %08x\n", hr );
2396 ok(pNextChild == NULL, "pNextChild not NULL\n");
2398 /* test get_attributes */
2399 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2400 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2402 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2403 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2404 ok(hr == S_FALSE, "ret %08x\n", hr );
2405 ok( pAttribs == NULL, "pAttribs not NULL\n");
2407 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2408 ok(hr == E_FAIL, "ret %08x\n", hr );
2409 ok(pNewChild == NULL, "pNewChild not NULL\n");
2411 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2412 ok(hr == S_OK, "ret %08x\n", hr );
2415 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2416 ok(hr == S_OK, "ret %08x\n", hr );
2418 IXMLDOMNamedNodeMap_Release(pAttribs);
2421 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2422 ok(hr == S_OK, "ret %08x\n", hr );
2423 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2426 /* test nodeTypeString */
2427 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2428 ok(hr == S_OK, "ret %08x\n", hr );
2429 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2433 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2434 ok(hr == S_OK, "ret %08x\n", hr );
2435 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
2438 /* test name property */
2439 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
2440 ok(hr == S_OK, "ret %08x\n", hr );
2441 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
2444 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2445 ok(hr == S_OK, "ret %08x\n", hr );
2446 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2449 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2450 ok(hr == S_FALSE, "ret %08x\n", hr );
2451 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2454 IXMLDOMAttribute_Release(pAttrubute);
2456 /* Check Element again with the Add Attribute*/
2457 hr = IXMLDOMElement_get_xml(pElement, &str);
2458 ok(hr == S_OK, "ret %08x\n", hr );
2459 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2463 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2464 ok(hr == S_OK, "ret %08x\n", hr );
2466 hr = IXMLDOMElement_get_xml(pElement, &str);
2467 ok(hr == S_OK, "ret %08x\n", hr );
2468 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2471 IXMLDOMElement_Release(pElement);
2475 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2476 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2478 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2479 ok(hr == S_OK, "ret %08x\n", hr );
2482 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2485 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2486 ok(hr == S_OK, "ret %08x\n", hr );
2488 /* get Attribute Tests */
2489 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2490 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2492 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2493 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2494 ok(hr == S_FALSE, "ret %08x\n", hr );
2495 ok(pAttribs == NULL, "pAttribs != NULL\n");
2497 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2498 ok(hr == S_OK, "ret %08x\n", hr );
2499 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2502 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2503 ok(hr == S_OK, "ret %08x\n", hr );
2504 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2507 /* test lastChild */
2508 pNextChild = (IXMLDOMNode*)0x1;
2509 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2510 ok(hr == S_FALSE, "ret %08x\n", hr );
2511 ok(pNextChild == NULL, "pNextChild not NULL\n");
2513 /* test get_dataType */
2514 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2515 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2517 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2518 ok(hr == S_FALSE, "ret %08x\n", hr );
2519 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2522 /* test nodeTypeString */
2523 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2524 ok(hr == S_OK, "ret %08x\n", hr );
2525 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2528 /* put data Tests */
2529 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
2530 ok(hr == S_OK, "ret %08x\n", hr );
2532 /* Confirm XML text is good */
2533 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2534 ok(hr == S_OK, "ret %08x\n", hr );
2535 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
2538 /* Confirm we get the put_data Text back */
2539 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2540 ok(hr == S_OK, "ret %08x\n", hr );
2541 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2544 /* test length property */
2545 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
2546 ok(hr == S_OK, "ret %08x\n", hr );
2547 ok(len == 21, "expected 21 got %ld\n", len);
2549 /* test get nodeValue */
2550 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
2551 ok(hr == S_OK, "ret %08x\n", hr );
2552 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2556 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
2557 ok(hr == S_OK, "ret %08x\n", hr );
2558 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2561 /* test substringData */
2562 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
2563 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2565 /* test substringData - Invalid offset */
2566 str = (BSTR)&szElement;
2567 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
2568 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2569 ok( str == NULL, "incorrect string\n");
2571 /* test substringData - Invalid offset */
2572 str = (BSTR)&szElement;
2573 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
2574 ok(hr == S_FALSE, "ret %08x\n", hr );
2575 ok( str == NULL, "incorrect string\n");
2577 /* test substringData - Invalid size */
2578 str = (BSTR)&szElement;
2579 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
2580 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2581 ok( str == NULL, "incorrect string\n");
2583 /* test substringData - Invalid size */
2584 str = (BSTR)&szElement;
2585 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
2586 ok(hr == S_FALSE, "ret %08x\n", hr );
2587 ok( str == NULL, "incorrect string\n");
2589 /* test substringData - Start of string */
2590 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
2591 ok(hr == S_OK, "ret %08x\n", hr );
2592 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2595 /* test substringData - Middle of string */
2596 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
2597 ok(hr == S_OK, "ret %08x\n", hr );
2598 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2601 /* test substringData - End of string */
2602 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
2603 ok(hr == S_OK, "ret %08x\n", hr );
2604 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2607 /* test appendData */
2608 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
2609 ok(hr == S_OK, "ret %08x\n", hr );
2611 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
2612 ok(hr == S_OK, "ret %08x\n", hr );
2614 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
2615 ok(hr == S_OK, "ret %08x\n", hr );
2617 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2618 ok(hr == S_OK, "ret %08x\n", hr );
2619 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2622 /* test insertData */
2623 str = SysAllocStringLen(NULL, 0);
2624 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
2625 ok(hr == S_OK, "ret %08x\n", hr );
2627 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
2628 ok(hr == S_OK, "ret %08x\n", hr );
2630 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
2631 ok(hr == S_OK, "ret %08x\n", hr );
2633 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
2634 ok(hr == S_OK, "ret %08x\n", hr );
2636 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
2637 ok(hr == S_OK, "ret %08x\n", hr );
2639 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
2640 ok(hr == S_OK, "ret %08x\n", hr );
2643 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
2644 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2646 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
2647 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2649 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
2650 ok(hr == S_OK, "ret %08x\n", hr );
2652 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
2653 ok(hr == S_OK, "ret %08x\n", hr );
2655 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
2656 ok(hr == S_OK, "ret %08x\n", hr );
2658 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2659 ok(hr == S_OK, "ret %08x\n", hr );
2660 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2663 IXMLDOMCDATASection_Release(pCDataSec);
2666 /* Document Fragments */
2667 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
2668 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2670 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
2671 ok(hr == S_OK, "ret %08x\n", hr );
2674 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2676 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
2677 ok(hr == S_OK, "ret %08x\n", hr );
2679 /* get Attribute Tests */
2680 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
2681 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2683 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2684 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
2685 ok(hr == S_FALSE, "ret %08x\n", hr );
2686 ok(pAttribs == NULL, "pAttribs != NULL\n");
2688 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
2689 ok(hr == S_OK, "ret %08x\n", hr );
2690 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
2693 /* test next Sibling*/
2694 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
2695 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2697 pNextChild = (IXMLDOMNode *)0x1;
2698 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
2699 ok(hr == S_FALSE, "ret %08x\n", hr );
2700 ok(pNextChild == NULL, "pNextChild not NULL\n");
2702 /* test Previous Sibling*/
2703 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
2704 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2706 pNextChild = (IXMLDOMNode *)0x1;
2707 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
2708 ok(hr == S_FALSE, "ret %08x\n", hr );
2709 ok(pNextChild == NULL, "pNextChild not NULL\n");
2711 /* test get_dataType */
2712 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
2713 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2715 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
2716 ok(hr == S_FALSE, "ret %08x\n", hr );
2717 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2720 /* test nodeTypeString */
2721 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
2722 ok(hr == S_OK, "ret %08x\n", hr );
2723 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
2726 IXMLDOMDocumentFragment_Release(pDocFrag);
2729 /* Entity References */
2730 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
2731 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2733 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
2734 ok(hr == S_OK, "ret %08x\n", hr );
2737 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
2738 ok(hr == S_OK, "ret %08x\n", hr );
2740 /* get Attribute Tests */
2741 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
2742 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2744 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2745 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
2746 ok(hr == S_FALSE, "ret %08x\n", hr );
2747 ok(pAttribs == NULL, "pAttribs != NULL\n");
2750 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
2751 ok(hr == S_FALSE, "ret %08x\n", hr );
2752 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2755 /* test nodeTypeString */
2756 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
2757 ok(hr == S_OK, "ret %08x\n", hr );
2758 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
2762 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
2763 ok(hr == S_OK, "ret %08x\n", hr );
2764 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
2767 IXMLDOMEntityReference_Release(pEntityRef);
2770 IXMLDOMElement_Release( pRoot );
2774 IXMLDOMDocument_Release(doc);
2779 static void test_nodeTypeTests( void )
2781 IXMLDOMDocument *doc = NULL;
2782 IXMLDOMElement *pRoot;
2783 IXMLDOMElement *pElement;
2786 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2790 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2791 ok(hr == S_OK, "ret %08x\n", hr );
2794 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2795 ok(hr == S_OK, "ret %08x\n", hr );
2798 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
2799 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2802 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
2803 ok(hr == E_FAIL, "ret %08x\n", hr );
2806 * The name passed into put_dataType is case-insensitive. So many of the names
2807 * have been changed to reflect this.
2810 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
2811 ok(hr == S_OK, "ret %08x\n", hr );
2814 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2816 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
2817 ok(hr == S_OK, "ret %08x\n", hr );
2819 IXMLDOMElement_Release(pElement);
2823 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
2824 ok(hr == S_OK, "ret %08x\n", hr );
2827 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2829 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
2830 ok(hr == S_OK, "ret %08x\n", hr );
2832 IXMLDOMElement_Release(pElement);
2836 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
2837 ok(hr == S_OK, "ret %08x\n", hr );
2840 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2842 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
2843 ok(hr == S_OK, "ret %08x\n", hr );
2845 IXMLDOMElement_Release(pElement);
2849 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
2850 ok(hr == S_OK, "ret %08x\n", hr );
2853 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2855 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
2856 ok(hr == S_OK, "ret %08x\n", hr );
2858 IXMLDOMElement_Release(pElement);
2862 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
2863 ok(hr == S_OK, "ret %08x\n", hr );
2866 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2868 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
2869 ok(hr == S_OK, "ret %08x\n", hr );
2871 IXMLDOMElement_Release(pElement);
2875 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
2876 ok(hr == S_OK, "ret %08x\n", hr );
2879 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2881 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
2882 ok(hr == S_OK, "ret %08x\n", hr );
2884 IXMLDOMElement_Release(pElement);
2888 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
2889 ok(hr == S_OK, "ret %08x\n", hr );
2892 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2894 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
2895 ok(hr == S_OK, "ret %08x\n", hr );
2897 IXMLDOMElement_Release(pElement);
2901 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
2902 ok(hr == S_OK, "ret %08x\n", hr );
2905 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2907 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
2908 ok(hr == S_OK, "ret %08x\n", hr );
2910 IXMLDOMElement_Release(pElement);
2914 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
2915 ok(hr == S_OK, "ret %08x\n", hr );
2918 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2920 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
2921 ok(hr == S_OK, "ret %08x\n", hr );
2923 IXMLDOMElement_Release(pElement);
2927 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
2928 ok(hr == S_OK, "ret %08x\n", hr );
2931 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2933 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
2934 ok(hr == S_OK, "ret %08x\n", hr );
2936 IXMLDOMElement_Release(pElement);
2940 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
2941 ok(hr == S_OK, "ret %08x\n", hr );
2944 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2946 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
2947 ok(hr == S_OK, "ret %08x\n", hr );
2949 IXMLDOMElement_Release(pElement);
2953 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
2954 ok(hr == S_OK, "ret %08x\n", hr );
2957 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2959 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
2960 ok(hr == S_OK, "ret %08x\n", hr );
2962 IXMLDOMElement_Release(pElement);
2966 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
2967 ok(hr == S_OK, "ret %08x\n", hr );
2970 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2972 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
2973 ok(hr == S_OK, "ret %08x\n", hr );
2975 IXMLDOMElement_Release(pElement);
2979 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
2980 ok(hr == S_OK, "ret %08x\n", hr );
2983 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2985 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
2986 ok(hr == S_OK, "ret %08x\n", hr );
2988 IXMLDOMElement_Release(pElement);
2992 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
2993 ok(hr == S_OK, "ret %08x\n", hr );
2996 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2998 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
2999 ok(hr == S_OK, "ret %08x\n", hr );
3001 IXMLDOMElement_Release(pElement);
3005 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3006 ok(hr == S_OK, "ret %08x\n", hr );
3009 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3011 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3012 ok(hr == S_OK, "ret %08x\n", hr );
3014 IXMLDOMElement_Release(pElement);
3018 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3019 ok(hr == S_OK, "ret %08x\n", hr );
3022 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3024 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3025 ok(hr == S_OK, "ret %08x\n", hr );
3027 IXMLDOMElement_Release(pElement);
3031 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3032 ok(hr == S_OK, "ret %08x\n", hr );
3035 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3037 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3038 ok(hr == S_OK, "ret %08x\n", hr );
3040 IXMLDOMElement_Release(pElement);
3044 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3045 ok(hr == S_OK, "ret %08x\n", hr );
3048 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3050 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3051 ok(hr == S_OK, "ret %08x\n", hr );
3053 IXMLDOMElement_Release(pElement);
3057 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3058 ok(hr == S_OK, "ret %08x\n", hr );
3061 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3063 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3064 ok(hr == S_OK, "ret %08x\n", hr );
3066 IXMLDOMElement_Release(pElement);
3070 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3071 ok(hr == S_OK, "ret %08x\n", hr );
3074 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3076 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3077 ok(hr == S_OK, "ret %08x\n", hr );
3079 IXMLDOMElement_Release(pElement);
3083 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3084 ok(hr == S_OK, "ret %08x\n", hr );
3087 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3089 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3090 ok(hr == S_OK, "ret %08x\n", hr );
3092 IXMLDOMElement_Release(pElement);
3095 /* Check changing types */
3096 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3097 ok(hr == S_OK, "ret %08x\n", hr );
3100 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3102 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3103 ok(hr == S_OK, "ret %08x\n", hr );
3105 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3106 ok(hr == S_OK, "ret %08x\n", hr );
3108 IXMLDOMElement_Release(pElement);
3111 IXMLDOMElement_Release(pRoot);
3115 IXMLDOMDocument_Release(doc);
3120 static void test_DocumentSaveToDocument(void)
3122 IXMLDOMDocument *doc = NULL;
3123 IXMLDOMDocument *doc2 = NULL;
3124 IXMLDOMElement *pRoot;
3128 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3132 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3135 IXMLDOMDocument_Release(doc);
3139 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3140 ok(hr == S_OK, "ret %08x\n", hr );
3143 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3144 ok(hr == S_OK, "ret %08x\n", hr );
3151 V_VT(&vDoc) = VT_UNKNOWN;
3152 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3154 hr = IXMLDOMDocument_save(doc, vDoc);
3155 ok(hr == S_OK, "ret %08x\n", hr );
3157 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3158 ok(hr == S_OK, "ret %08x\n", hr );
3160 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3161 ok(hr == S_OK, "ret %08x\n", hr );
3163 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3165 SysFreeString(sOrig);
3166 SysFreeString(sNew);
3170 IXMLDOMDocument_Release(doc2);
3171 IXMLDOMDocument_Release(doc);
3174 static void test_testTransforms(void)
3176 IXMLDOMDocument *doc = NULL;
3177 IXMLDOMDocument *docSS = NULL;
3183 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3187 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3190 IXMLDOMDocument_Release(doc);
3194 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3195 ok(hr == S_OK, "ret %08x\n", hr );
3197 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3198 ok(hr == S_OK, "ret %08x\n", hr );
3200 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3201 ok(hr == S_OK, "ret %08x\n", hr );
3206 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3207 ok(hr == S_OK, "ret %08x\n", hr );
3208 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3210 IXMLDOMNode_Release(pNode);
3213 IXMLDOMDocument_Release(docSS);
3214 IXMLDOMDocument_Release(doc);
3219 static void test_Namespaces(void)
3221 IXMLDOMDocument2 *doc = NULL;
3223 IXMLDOMNode *pNode2 = NULL;
3227 static const CHAR szNamespacesXML[] =
3228 "<?xml version=\"1.0\"?>\n"
3229 "<root xmlns:WEB='http://www.winehq.org'>\n"
3230 "<WEB:Site version=\"1.0\" />\n"
3233 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3237 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3238 ok(hr == S_OK, "ret %08x\n", hr );
3239 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE");
3241 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3242 ok(hr == S_OK, "ret %08x\n", hr );
3245 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3246 ok( hr == S_OK, "ret %08x\n", hr );
3247 ok( pNode2 != NULL, "pNode2 == NULL\n");
3249 /* Test get_prefix */
3250 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3251 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3252 /* NOTE: Need to test that arg2 gets cleared on Error. */
3254 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3255 ok( hr == S_OK, "ret %08x\n", hr );
3256 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3259 /* Test get_namespaceURI */
3260 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3261 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3262 /* NOTE: Need to test that arg2 gets cleared on Error. */
3264 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3265 ok( hr == S_OK, "ret %08x\n", hr );
3266 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3269 IXMLDOMNode_Release(pNode2);
3270 IXMLDOMNode_Release(pNode);
3273 IXMLDOMDocument2_Release(doc);
3282 r = CoInitialize( NULL );
3283 ok( r == S_OK, "failed to init com\n");
3289 test_getElementsByTagName();
3291 test_get_childNodes();
3294 test_IXMLDOMDocument2();
3298 test_nodeTypeTests();
3299 test_DocumentSaveToDocument();
3300 test_testTransforms();