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
29 #include "msxml2did.h"
34 #include "wine/test.h"
36 static const WCHAR szEmpty[] = { 0 };
37 static const WCHAR szIncomplete[] = {
38 '<','?','x','m','l',' ',
39 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
41 static const WCHAR szComplete1[] = {
42 '<','?','x','m','l',' ',
43 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
44 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
46 static const WCHAR szComplete2[] = {
47 '<','?','x','m','l',' ',
48 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
49 '<','o','>','<','/','o','>','\n',0
51 static const WCHAR szComplete3[] = {
52 '<','?','x','m','l',' ',
53 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
54 '<','a','>','<','/','a','>','\n',0
56 static const WCHAR szComplete4[] = {
57 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
58 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
59 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
60 'f','n','1','.','t','x','t','\n',
61 '<','/','b','s','>','\n',
62 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
63 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
64 'f','n','2','.','t','x','t','\n',
65 '<','/','p','r','>','\n',
66 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
70 '<','/','b','a','>','\n',
71 '<','/','f','o','>','\n',
72 '<','/','l','c','>','\n',0
74 static const WCHAR szComplete5[] = {
75 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
76 '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','"',
77 ' ','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','"','>',
78 '<','S',':','s','c','o','p','e','>',
79 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
80 '<','/','S',':','s','c','o','p','e','>',
81 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
82 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
83 'c','o','m','p','u','t','e','r',
84 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
85 '<','/','S',':','s','e','a','r','c','h','>',0
88 static const CHAR szExampleXML[] =
89 "<?xml version='1.0' encoding='utf-8'?>\n"
90 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
95 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
96 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
97 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
105 " <c type=\"old\">C2 field</c>\n"
108 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
117 " <foo:c>C4 field</foo:c>\n"
121 static const CHAR szTransformXML[] =
122 "<?xml version=\"1.0\"?>\n"
127 static const CHAR szTransformSSXML[] =
128 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
129 " <xsl:output method=\"html\"/>\n"
130 " <xsl:template match=\"/\">\n"
131 " <xsl:apply-templates select=\"greeting\"/>\n"
133 " <xsl:template match=\"greeting\">\n"
137 " <xsl:value-of select=\".\"/>\n"
144 static const CHAR szTransformOutput[] =
147 "</h1></body></html>";
149 static const CHAR szTypeValueXML[] =
150 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
151 "<string>Wine</string>";
153 static const WCHAR szNonExistentFile[] = {
154 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
156 static const WCHAR szDocument[] = {
157 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
160 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
161 static WCHAR szdl[] = { 'd','l',0 };
162 static const WCHAR szvr[] = { 'v','r',0 };
163 static const WCHAR szlc[] = { 'l','c',0 };
164 static WCHAR szbs[] = { 'b','s',0 };
165 static const WCHAR szstr1[] = { 's','t','r','1',0 };
166 static const WCHAR szstr2[] = { 's','t','r','2',0 };
167 static const WCHAR szstar[] = { '*',0 };
168 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
170 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
171 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
172 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
174 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
175 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
176 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
177 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
178 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
179 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
180 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
182 static WCHAR szAttribute[] = {'A','t','t','r',0 };
183 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
185 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
186 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
187 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
188 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
190 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
191 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
193 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
194 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
195 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
197 #define expect_bstr_eq_and_free(bstr, expect) { \
198 BSTR bstrExp = alloc_str_from_narrow(expect); \
199 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
200 SysFreeString(bstr); \
201 SysFreeString(bstrExp); \
204 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
206 #define ole_check(expr) { \
208 ok(r == S_OK, #expr " returned %x\n", r); \
211 #define ole_expect(expr, expect) { \
213 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
216 static BSTR alloc_str_from_narrow(const char *str)
218 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
219 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
220 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
224 BSTR alloced_bstrs[256];
225 int alloced_bstrs_count = 0;
227 static BSTR _bstr_(const char *str)
229 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
230 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
231 return alloced_bstrs[alloced_bstrs_count++];
234 static void free_bstrs(void)
237 for (i = 0; i < alloced_bstrs_count; i++)
238 SysFreeString(alloced_bstrs[i]);
239 alloced_bstrs_count = 0;
242 static VARIANT _variantbstr_(const char *str)
246 V_BSTR(&v) = _bstr_(str);
250 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
254 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
255 while (*sRight == '\r' || *sRight == '\n') sRight++;
256 if (*sLeft != *sRight) return FALSE;
257 if (!*sLeft) return TRUE;
263 static void get_str_for_type(DOMNodeType type, char *buf)
277 wsprintfA(buf, "[%d]", type);
281 static int get_node_position(IXMLDOMNode *node)
286 IXMLDOMNode_AddRef(node);
289 IXMLDOMNode *new_node;
292 r = IXMLDOMNode_get_previousSibling(node, &new_node);
293 ok(SUCCEEDED(r), "get_previousSibling failed\n");
294 IXMLDOMNode_Release(node);
300 static void node_to_string(IXMLDOMNode *node, char *buf)
307 lstrcpyA(buf, "(null)");
311 IXMLDOMNode_AddRef(node);
314 IXMLDOMNode *new_node;
316 ole_check(IXMLDOMNode_get_nodeType(node, &type));
317 get_str_for_type(type, buf);
320 if (type == NODE_ATTRIBUTE)
323 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
325 wsprintfA(buf, "%ws", bstr);
330 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
334 int pos = get_node_position(node);
335 DOMNodeType parent_type = NODE_INVALID;
336 r = IXMLDOMNode_get_parentNode(node, &new_node);
338 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
339 * results we "fix" it */
341 ole_check(IXMLDOMNode_get_nodeType(new_node, &parent_type));
342 if ((parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
344 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
347 wsprintf(buf, "%d", pos);
351 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
352 IXMLDOMNode_Release(node);
361 static char *list_to_string(IXMLDOMNodeList *list)
363 static char buf[4096];
370 lstrcpyA(buf, "(null)");
373 ole_check(IXMLDOMNodeList_get_length(list, &len));
374 for (i = 0; i < len; i++)
379 ole_check(IXMLDOMNodeList_nextNode(list, &node));
380 node_to_string(node, pos);
382 IXMLDOMNode_Release(node);
388 #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); }
389 #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); }
391 static void test_domdoc( void )
394 IXMLDOMDocument *doc = NULL;
395 IXMLDOMParseError *error;
396 IXMLDOMElement *element = NULL;
398 IXMLDOMText *nodetext = NULL;
399 IXMLDOMComment *node_comment = NULL;
400 IXMLDOMAttribute *node_attr = NULL;
401 IXMLDOMNode *nodeChild = NULL;
402 IXMLDOMProcessingInstruction *nodePI = NULL;
403 ISupportErrorInfo *support_error = NULL;
410 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
411 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
415 /* try some stupid things */
416 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
417 ok( r == S_FALSE, "loadXML failed\n");
420 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
421 ok( r == S_FALSE, "loadXML failed\n");
422 ok( b == VARIANT_FALSE, "failed to load XML string\n");
424 /* try to load a document from a nonexistent file */
426 str = SysAllocString( szNonExistentFile );
428 V_VT(&var) = VT_BSTR;
431 r = IXMLDOMDocument_load( doc, var, &b);
432 ok( r == S_FALSE, "load (from file) failed\n");
433 ok( b == VARIANT_FALSE, "failed to load XML file\n");
434 SysFreeString( str );
436 /* try load an empty document */
438 str = SysAllocString( szEmpty );
439 r = IXMLDOMDocument_loadXML( doc, str, &b );
440 ok( r == S_FALSE, "loadXML failed\n");
441 ok( b == VARIANT_FALSE, "failed to load XML string\n");
442 SysFreeString( str );
444 /* check that there's no document element */
446 r = IXMLDOMDocument_get_documentElement( doc, &element );
447 ok( r == S_FALSE, "should be no document element\n");
449 /* try finding a node */
451 str = SysAllocString( szstr1 );
452 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
453 ok( r == S_FALSE, "ret %08x\n", r );
454 SysFreeString( str );
457 str = SysAllocString( szIncomplete );
458 r = IXMLDOMDocument_loadXML( doc, str, &b );
459 ok( r == S_FALSE, "loadXML failed\n");
460 ok( b == VARIANT_FALSE, "failed to load XML string\n");
461 SysFreeString( str );
463 /* check that there's no document element */
464 element = (IXMLDOMElement*)1;
465 r = IXMLDOMDocument_get_documentElement( doc, &element );
466 ok( r == S_FALSE, "should be no document element\n");
467 ok( element == NULL, "Element should be NULL\n");
469 /* try to load something valid */
471 str = SysAllocString( szComplete1 );
472 r = IXMLDOMDocument_loadXML( doc, str, &b );
473 ok( r == S_OK, "loadXML failed\n");
474 ok( b == VARIANT_TRUE, "failed to load XML string\n");
475 SysFreeString( str );
477 /* check if nodename is correct */
478 r = IXMLDOMDocument_get_nodeName( doc, NULL );
479 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
481 /* content doesn't matter here */
483 r = IXMLDOMDocument_get_nodeName( doc, &str );
484 ok ( r == S_OK, "get_nodeName wrong code\n");
485 ok ( str != NULL, "str is null\n");
486 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
487 SysFreeString( str );
490 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
491 ok( r == E_FAIL, "ret %08x\n", r );
493 /* check that there's a document element */
495 r = IXMLDOMDocument_get_documentElement( doc, &element );
496 ok( r == S_OK, "should be a document element\n");
501 /* check if the tag is correct */
502 r = IXMLDOMElement_get_tagName( element, &tag );
503 ok( r == S_OK, "couldn't get tag name\n");
504 ok( tag != NULL, "tag was null\n");
505 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
506 SysFreeString( tag );
508 /* figure out what happens if we try to reload the document */
509 str = SysAllocString( szComplete2 );
510 r = IXMLDOMDocument_loadXML( doc, str, &b );
511 ok( r == S_OK, "loadXML failed\n");
512 ok( b == VARIANT_TRUE, "failed to load XML string\n");
513 SysFreeString( str );
515 /* check if the tag is still correct */
517 r = IXMLDOMElement_get_tagName( element, &tag );
518 ok( r == S_OK, "couldn't get tag name\n");
519 ok( tag != NULL, "tag was null\n");
520 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
521 SysFreeString( tag );
523 IXMLDOMElement_Release( element );
527 /* as soon as we call loadXML again, the document element will disappear */
529 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
530 ok( r == S_FALSE, "loadXML failed\n");
531 ok( b == 2, "variant modified\n");
532 r = IXMLDOMDocument_get_documentElement( doc, &element );
533 ok( r == S_FALSE, "should be no document element\n");
535 /* try to load something else simple and valid */
537 str = SysAllocString( szComplete3 );
538 r = IXMLDOMDocument_loadXML( doc, str, &b );
539 ok( r == S_OK, "loadXML failed\n");
540 ok( b == VARIANT_TRUE, "failed to load XML string\n");
541 SysFreeString( str );
543 /* try something a little more complicated */
545 str = SysAllocString( szComplete4 );
546 r = IXMLDOMDocument_loadXML( doc, str, &b );
547 ok( r == S_OK, "loadXML failed\n");
548 ok( b == VARIANT_TRUE, "failed to load XML string\n");
549 SysFreeString( str );
551 r = IXMLDOMDocument_get_parseError( doc, &error );
552 ok( r == S_OK, "returns %08x\n", r );
554 r = IXMLDOMParseError_get_errorCode( error, &code );
555 ok( r == S_FALSE, "returns %08x\n", r );
556 ok( code == 0, "code %ld\n", code );
557 IXMLDOMParseError_Release( error );
559 /* test createTextNode */
560 str = SysAllocString( szOpen );
561 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
562 ok( r == E_INVALIDARG, "returns %08x\n", r );
563 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
564 ok( r == S_OK, "returns %08x\n", r );
565 SysFreeString( str );
568 IXMLDOMNamedNodeMap *pAttribs;
570 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (LPVOID*)&element);
571 ok(r == E_NOINTERFACE, "ret %08x\n", r );
573 /* Text Last Child Checks */
574 r = IXMLDOMText_get_lastChild(nodetext, NULL);
575 ok(r == E_INVALIDARG, "ret %08x\n", r );
577 nodeChild = (IXMLDOMNode*)0x1;
578 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
579 ok(r == S_FALSE, "ret %08x\n", r );
580 ok(nodeChild == NULL, "nodeChild not NULL\n");
582 /* test get_attributes */
583 r = IXMLDOMText_get_attributes( nodetext, NULL );
584 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
586 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
587 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
588 ok(r == S_FALSE, "ret %08x\n", r );
589 ok( pAttribs == NULL, "pAttribs not NULL\n");
591 /* test get_dataType */
592 r = IXMLDOMText_get_dataType(nodetext, &var);
593 ok(r == S_FALSE, "ret %08x\n", r );
594 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
597 /* test length property */
598 r = IXMLDOMText_get_length(nodetext, NULL);
599 ok(r == E_INVALIDARG, "ret %08x\n", r );
601 r = IXMLDOMText_get_length(nodetext, &nLength);
602 ok(r == S_OK, "ret %08x\n", r );
603 ok(nLength == 4, "expected 4 got %ld\n", nLength);
605 /* test nodeTypeString */
606 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
607 ok(r == S_OK, "ret %08x\n", r );
608 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
612 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
613 ok(r == S_OK, "ret %08x\n", r );
616 r = IXMLDOMText_get_data(nodetext, &str);
617 ok(r == S_OK, "ret %08x\n", r );
618 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
621 /* Confirm XML text is good */
622 r = IXMLDOMText_get_xml(nodetext, &str);
623 ok(r == S_OK, "ret %08x\n", r );
624 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
627 /* Confirm we get the put_data Text back */
628 r = IXMLDOMText_get_text(nodetext, &str);
629 ok(r == S_OK, "ret %08x\n", r );
630 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
633 /* test substringData */
634 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
635 ok(r == E_INVALIDARG, "ret %08x\n", r );
637 /* test substringData - Invalid offset */
638 str = (BSTR)&szElement;
639 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
640 ok(r == E_INVALIDARG, "ret %08x\n", r );
641 ok( str == NULL, "incorrect string\n");
643 /* test substringData - Invalid offset */
644 str = (BSTR)&szElement;
645 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
646 ok(r == S_FALSE, "ret %08x\n", r );
647 ok( str == NULL, "incorrect string\n");
649 /* test substringData - Invalid size */
650 str = (BSTR)&szElement;
651 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
652 ok(r == E_INVALIDARG, "ret %08x\n", r );
653 ok( str == NULL, "incorrect string\n");
655 /* test substringData - Invalid size */
656 str = (BSTR)&szElement;
657 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
658 ok(r == S_FALSE, "ret %08x\n", r );
659 ok( str == NULL, "incorrect string\n");
661 /* test substringData - Start of string */
662 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
663 ok(r == S_OK, "ret %08x\n", r );
664 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
667 /* test substringData - Middle of string */
668 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
669 ok(r == S_OK, "ret %08x\n", r );
670 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
673 /* test substringData - End of string */
674 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
675 ok(r == S_OK, "ret %08x\n", r );
676 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
679 /* test appendData */
680 r = IXMLDOMText_appendData(nodetext, NULL);
681 ok(r == S_OK, "ret %08x\n", r );
683 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
684 ok(r == S_OK, "ret %08x\n", r );
686 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
687 ok(r == S_OK, "ret %08x\n", r );
689 r = IXMLDOMText_get_text(nodetext, &str);
690 ok(r == S_OK, "ret %08x\n", r );
691 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
694 /* test insertData */
695 str = SysAllocStringLen(NULL, 0);
696 r = IXMLDOMText_insertData(nodetext, -1, str);
697 ok(r == S_OK, "ret %08x\n", r );
699 r = IXMLDOMText_insertData(nodetext, -1, NULL);
700 ok(r == S_OK, "ret %08x\n", r );
702 r = IXMLDOMText_insertData(nodetext, 1000, str);
703 ok(r == S_OK, "ret %08x\n", r );
705 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
706 ok(r == S_OK, "ret %08x\n", r );
708 r = IXMLDOMText_insertData(nodetext, 0, NULL);
709 ok(r == S_OK, "ret %08x\n", r );
711 r = IXMLDOMText_insertData(nodetext, 0, str);
712 ok(r == S_OK, "ret %08x\n", r );
715 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
716 ok(r == E_INVALIDARG, "ret %08x\n", r );
718 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
719 ok(r == E_INVALIDARG, "ret %08x\n", r );
721 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
722 ok(r == S_OK, "ret %08x\n", r );
724 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
725 ok(r == S_OK, "ret %08x\n", r );
727 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
728 ok(r == S_OK, "ret %08x\n", r );
730 r = IXMLDOMText_get_text(nodetext, &str);
731 ok(r == S_OK, "ret %08x\n", r );
732 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
736 V_VT(&var) = VT_BSTR;
737 V_BSTR(&var) = SysAllocString(szstr1);
738 r = IXMLDOMText_put_nodeValue(nodetext, var);
739 ok(r == S_OK, "ret %08x\n", r );
742 r = IXMLDOMText_get_text(nodetext, &str);
743 ok(r == S_OK, "ret %08x\n", r );
744 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string\n");
750 r = IXMLDOMText_put_nodeValue(nodetext, var);
751 ok(r == S_OK, "ret %08x\n", r );
754 r = IXMLDOMText_get_text(nodetext, &str);
755 ok(r == S_OK, "ret %08x\n", r );
756 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string\n");
759 IXMLDOMText_Release( nodetext );
762 /* test Create Comment */
763 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
764 ok( r == E_INVALIDARG, "returns %08x\n", r );
765 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
766 ok( r == S_OK, "returns %08x\n", r );
769 /* Last Child Checks */
770 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
771 ok(r == E_INVALIDARG, "ret %08x\n", r );
773 nodeChild = (IXMLDOMNode*)0x1;
774 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
775 ok(r == S_FALSE, "ret %08x\n", r );
776 ok(nodeChild == NULL, "pLastChild not NULL\n");
778 IXMLDOMComment_Release( node_comment );
781 /* test Create Attribute */
782 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
783 ok( r == E_INVALIDARG, "returns %08x\n", r );
784 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
785 ok( r == S_OK, "returns %08x\n", r );
786 IXMLDOMText_Release( node_attr);
788 /* test Processing Instruction */
789 str = SysAllocStringLen(NULL, 0);
790 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
791 ok( r == E_INVALIDARG, "returns %08x\n", r );
792 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
793 ok( r == E_FAIL, "returns %08x\n", r );
794 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
795 ok( r == E_FAIL, "returns %08x\n", r );
798 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
799 ok( r == S_OK, "returns %08x\n", r );
802 /* Last Child Checks */
803 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
804 ok(r == E_INVALIDARG, "ret %08x\n", r );
806 nodeChild = (IXMLDOMNode*)0x1;
807 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
808 ok(r == S_FALSE, "ret %08x\n", r );
809 ok(nodeChild == NULL, "nodeChild not NULL\n");
811 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
812 ok(r == S_FALSE, "ret %08x\n", r );
813 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
817 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
818 ok(r == S_OK, "ret %08x\n", r );
819 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
823 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
824 ok(r == S_OK, "ret %08x\n", r );
825 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
828 /* test nodeTypeString */
829 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
830 ok(r == S_OK, "ret %08x\n", r );
831 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
834 /* test get_nodeValue */
835 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
836 ok(r == S_OK, "ret %08x\n", r );
837 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
841 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
842 ok(r == S_OK, "ret %08x\n", r );
843 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
847 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
848 ok(r == E_FAIL, "ret %08x\n", r );
851 V_VT(&var) = VT_BSTR;
852 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
853 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
854 ok(r == E_FAIL, "ret %08x\n", r );
857 /* test get nodeName */
858 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
859 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
860 ok(r == S_OK, "ret %08x\n", r );
863 IXMLDOMProcessingInstruction_Release(nodePI);
866 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
867 ok( r == S_OK, "ret %08x\n", r );
870 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
871 todo_wine ok( r == S_OK, "ret %08x\n", r );
872 ISupportErrorInfo_Release( support_error );
875 r = IXMLDOMDocument_Release( doc );
876 ok( r == 0, "document ref count incorrect\n");
881 static void test_domnode( void )
884 IXMLDOMDocument *doc = NULL, *owner = NULL;
885 IXMLDOMElement *element = NULL;
886 IXMLDOMNamedNodeMap *map = NULL;
887 IXMLDOMNode *node = NULL, *next = NULL;
888 IXMLDOMNodeList *list = NULL;
889 IXMLDOMAttribute *attr = NULL;
890 DOMNodeType type = NODE_INVALID;
896 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
897 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
902 str = SysAllocString( szComplete4 );
903 r = IXMLDOMDocument_loadXML( doc, str, &b );
904 ok( r == S_OK, "loadXML failed\n");
905 ok( b == VARIANT_TRUE, "failed to load XML string\n");
906 SysFreeString( str );
911 r = IXMLDOMNode_hasChildNodes( doc, &b );
912 ok( r == S_OK, "hasChildNoes bad return\n");
913 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
915 r = IXMLDOMDocument_get_documentElement( doc, &element );
916 ok( r == S_OK, "should be a document element\n");
917 ok( element != NULL, "should be an element\n");
920 ok( FALSE, "no document\n");
923 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
925 r = IXMLDOMNode_get_nodeValue( doc, NULL );
926 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
928 r = IXMLDOMNode_get_nodeValue( doc, &var );
929 ok( r == S_FALSE, "nextNode returned wrong code\n");
930 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
931 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
936 r = IXMLDOMNode_get_ownerDocument( element, &owner );
937 ok( r == S_OK, "get_ownerDocument return code\n");
938 ok( owner != doc, "get_ownerDocument return\n");
941 r = IXMLDOMNode_get_nodeType( element, &type);
942 ok( r == S_OK, "getNamedItem returned wrong code\n");
943 ok( type == NODE_ELEMENT, "node not an element\n");
946 r = IXMLDOMNode_get_baseName( element, &str );
947 ok( r == S_OK, "get_baseName returned wrong code\n");
948 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
951 /* check if nodename is correct */
952 r = IXMLDOMElement_get_nodeName( element, NULL );
953 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
955 /* content doesn't matter here */
957 r = IXMLDOMElement_get_nodeName( element, &str );
958 ok ( r == S_OK, "get_nodeName wrong code\n");
959 ok ( str != NULL, "str is null\n");
960 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
961 SysFreeString( str );
963 str = SysAllocString( szNonExistentFile );
966 r = IXMLDOMElement_getAttribute( element, str, &var );
967 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
968 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
971 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
972 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
974 attr = (IXMLDOMAttribute*)0xdeadbeef;
975 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
976 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
977 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
978 SysFreeString( str );
980 attr = (IXMLDOMAttribute*)0xdeadbeef;
981 str = _bstr_("nonExisitingAttribute");
982 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
983 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
984 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
985 SysFreeString( str );
987 str = SysAllocString( szdl );
990 r = IXMLDOMElement_getAttribute( element, str, &var );
991 ok( r == S_OK, "getAttribute ret %08x\n", r );
992 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
993 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
994 VariantClear( &var );
996 r = IXMLDOMElement_getAttribute( element, NULL, &var );
997 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
999 r = IXMLDOMElement_getAttribute( element, str, NULL );
1000 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1003 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1004 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1005 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1007 IXMLDOMAttribute_Release(attr);
1009 SysFreeString( str );
1011 r = IXMLDOMElement_get_attributes( element, &map );
1012 ok( r == S_OK, "get_attributes returned wrong code\n");
1013 ok( map != NULL, "should be attributes\n");
1016 r = IXMLDOMNode_hasChildNodes( element, &b );
1017 ok( r == S_OK, "hasChildNoes bad return\n");
1018 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1021 ok( FALSE, "no element\n");
1025 ISupportErrorInfo *support_error;
1026 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1027 ok( r == S_OK, "ret %08x\n", r );
1029 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1032 ok( r == S_OK, "ret %08x\n", r );
1034 ISupportErrorInfo_Release( support_error );
1036 str = SysAllocString( szdl );
1037 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1038 ok( r == S_OK, "getNamedItem returned wrong code\n");
1039 ok( node != NULL, "should be attributes\n");
1040 IXMLDOMNode_Release(node);
1041 SysFreeString( str );
1043 str = SysAllocString( szdl );
1044 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1045 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1046 SysFreeString( str );
1048 /* something that isn't in szComplete4 */
1049 str = SysAllocString( szOpen );
1050 node = (IXMLDOMNode *) 1;
1051 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1052 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1053 ok( node == NULL, "getNamedItem should have returned NULL\n");
1054 SysFreeString( str );
1056 /* test indexed access of attributes */
1057 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1058 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1060 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1061 ok ( r == S_OK, "get_length wrong code\n");
1062 ok ( count == 1, "get_length != 1\n");
1065 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1066 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1067 ok ( node == NULL, "there is no node\n");
1070 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1071 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1072 ok ( node == NULL, "there is no attribute\n");
1075 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1076 ok ( r == S_OK, "get_item (0) wrong code\n");
1077 ok ( node != NULL, "should be attribute\n");
1079 r = IXMLDOMNode_get_nodeName( node, NULL );
1080 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1082 /* content doesn't matter here */
1084 r = IXMLDOMNode_get_nodeName( node, &str );
1085 ok ( r == S_OK, "get_nodeName wrong code\n");
1086 ok ( str != NULL, "str is null\n");
1087 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1088 SysFreeString( str );
1090 /* test sequential access of attributes */
1092 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1093 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1094 ok ( node != NULL, "nextNode, should be attribute\n");
1096 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1097 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1098 ok ( node == NULL, "nextNode, there is no attribute\n");
1100 r = IXMLDOMNamedNodeMap_reset( map );
1101 ok ( r == S_OK, "reset should return S_OK\n");
1103 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1104 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1105 ok ( node != NULL, "nextNode, should be attribute\n");
1108 ok( FALSE, "no map\n");
1112 type = NODE_INVALID;
1113 r = IXMLDOMNode_get_nodeType( node, &type);
1114 ok( r == S_OK, "getNamedItem returned wrong code\n");
1115 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1118 r = IXMLDOMNode_get_baseName( node, NULL );
1119 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1122 r = IXMLDOMNode_get_baseName( node, &str );
1123 ok( r == S_OK, "get_baseName returned wrong code\n");
1124 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1125 SysFreeString( str );
1127 r = IXMLDOMNode_get_nodeValue( node, &var );
1128 ok( r == S_OK, "returns %08x\n", r );
1129 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1130 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1133 r = IXMLDOMNode_get_childNodes( node, NULL );
1134 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1136 r = IXMLDOMNode_get_childNodes( node, &list );
1137 ok( r == S_OK, "get_childNodes returned wrong code\n");
1141 r = IXMLDOMNodeList_nextNode( list, &next );
1142 ok( r == S_OK, "nextNode returned wrong code\n");
1145 ok( FALSE, "no childlist\n");
1150 r = IXMLDOMNode_hasChildNodes( next, &b );
1151 ok( r == S_FALSE, "hasChildNoes bad return\n");
1152 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1154 type = NODE_INVALID;
1155 r = IXMLDOMNode_get_nodeType( next, &type);
1156 ok( r == S_OK, "getNamedItem returned wrong code\n");
1157 ok( type == NODE_TEXT, "node not text\n");
1160 r = IXMLDOMNode_get_baseName( next, &str );
1161 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1162 ok( str == NULL, "basename was wrong\n");
1166 ok( FALSE, "no next\n");
1169 IXMLDOMNode_Release( next );
1172 IXMLDOMNodeList_Release( list );
1175 IXMLDOMNode_Release( node );
1178 ok( FALSE, "no node\n");
1182 IXMLDOMNamedNodeMap_Release( map );
1184 /* now traverse the tree from the root element */
1188 r = IXMLDOMNode_get_childNodes( element, &list );
1189 ok( r == S_OK, "get_childNodes returned wrong code\n");
1191 /* using get_item for child list doesn't advance the position */
1192 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1193 expect_node(node, "E2.E2.D1");
1194 IXMLDOMNode_Release(node);
1195 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1196 expect_node(node, "E1.E2.D1");
1197 IXMLDOMNode_Release(node);
1198 ole_check(IXMLDOMNodeList_reset(list));
1200 IXMLDOMNodeList_AddRef(list);
1201 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1202 ole_check(IXMLDOMNodeList_reset(list));
1205 ok( FALSE, "no element\n");
1207 node = (void*)0xdeadbeef;
1208 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1209 ok( r == S_FALSE, "ret %08x\n", r );
1210 ok( node == NULL, "node %p\n", node );
1211 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1212 ok( r == S_OK, "ret %08x\n", r );
1213 r = IXMLDOMNode_Release( node );
1214 ok( r == 0, "ret %08x\n", r );
1218 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1219 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1221 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1222 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1224 r = IXMLDOMNodeList_get_length(list, NULL);
1225 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1227 r = IXMLDOMNodeList_get_length( list, &count );
1228 ok( r == S_OK, "get_length returns %08x\n", r );
1229 ok( count == 4, "get_length got %ld\n", count );
1231 r = IXMLDOMNodeList_nextNode(list, NULL);
1232 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1234 r = IXMLDOMNodeList_nextNode( list, &node );
1235 ok( r == S_OK, "nextNode returned wrong code\n");
1238 ok( FALSE, "no list\n");
1242 type = NODE_INVALID;
1243 r = IXMLDOMNode_get_nodeType( node, &type);
1244 ok( r == S_OK, "getNamedItem returned wrong code\n");
1245 ok( type == NODE_ELEMENT, "node not text\n");
1248 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1249 r = IXMLDOMNode_get_nodeValue( node, &var );
1250 ok( r == S_FALSE, "nextNode returned wrong code\n");
1251 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1252 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1254 r = IXMLDOMNode_hasChildNodes( node, NULL );
1255 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1258 r = IXMLDOMNode_hasChildNodes( node, &b );
1259 ok( r == S_OK, "hasChildNoes bad return\n");
1260 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1263 r = IXMLDOMNode_get_baseName( node, &str );
1264 ok( r == S_OK, "get_baseName returned wrong code\n");
1265 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1269 ok( FALSE, "no node\n");
1272 IXMLDOMNode_Release( node );
1274 IXMLDOMNodeList_Release( list );
1276 IXMLDOMElement_Release( element );
1279 str = SysAllocString( szComplete5 );
1280 r = IXMLDOMDocument_loadXML( doc, str, &b );
1281 ok( r == S_OK, "loadXML failed\n");
1282 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1283 SysFreeString( str );
1286 r = IXMLDOMNode_hasChildNodes( doc, &b );
1287 ok( r == S_OK, "hasChildNoes bad return\n");
1288 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1290 r = IXMLDOMDocument_get_documentElement( doc, &element );
1291 ok( r == S_OK, "should be a document element\n");
1292 ok( element != NULL, "should be an element\n");
1296 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1299 /* check if the tag is correct */
1300 r = IXMLDOMElement_get_tagName( element, &tag );
1301 ok( r == S_OK, "couldn't get tag name\n");
1302 ok( tag != NULL, "tag was null\n");
1303 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1304 SysFreeString( tag );
1308 IXMLDOMElement_Release( element );
1310 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1313 static void test_refs(void)
1318 IXMLDOMDocument *doc = NULL;
1319 IXMLDOMElement *element = NULL;
1320 IXMLDOMNode *node = NULL, *node2;
1321 IXMLDOMNodeList *node_list = NULL;
1323 IUnknown *unk, *unk2;
1325 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1326 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1329 ref = IXMLDOMDocument_Release(doc);
1330 ok( ref == 0, "ref %d\n", ref);
1332 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1333 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1337 str = SysAllocString( szComplete4 );
1338 r = IXMLDOMDocument_loadXML( doc, str, &b );
1339 ok( r == S_OK, "loadXML failed\n");
1340 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1341 SysFreeString( str );
1343 ref = IXMLDOMDocument_AddRef( doc );
1344 ok( ref == 2, "ref %d\n", ref );
1345 ref = IXMLDOMDocument_AddRef( doc );
1346 ok( ref == 3, "ref %d\n", ref );
1347 IXMLDOMDocument_Release( doc );
1348 IXMLDOMDocument_Release( doc );
1350 r = IXMLDOMDocument_get_documentElement( doc, &element );
1351 ok( r == S_OK, "should be a document element\n");
1352 ok( element != NULL, "should be an element\n");
1354 ref = IXMLDOMDocument_AddRef( doc );
1355 ok( ref == 2, "ref %d\n", ref );
1356 IXMLDOMDocument_Release( doc );
1358 r = IXMLDOMElement_get_childNodes( element, &node_list );
1359 ok( r == S_OK, "rets %08x\n", r);
1361 ref = IXMLDOMNodeList_AddRef( node_list );
1362 ok( ref == 2, "ref %d\n", ref );
1363 IXMLDOMNodeList_Release( node_list );
1365 IXMLDOMNodeList_get_item( node_list, 0, &node );
1366 ok( r == S_OK, "rets %08x\n", r);
1368 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1369 ok( r == S_OK, "rets %08x\n", r);
1371 ref = IXMLDOMNode_AddRef( node );
1372 ok( ref == 2, "ref %d\n", ref );
1373 IXMLDOMNode_Release( node );
1375 ref = IXMLDOMNode_Release( node );
1376 ok( ref == 0, "ref %d\n", ref );
1377 ref = IXMLDOMNode_Release( node2 );
1378 ok( ref == 0, "ref %d\n", ref );
1380 ref = IXMLDOMNodeList_Release( node_list );
1381 ok( ref == 0, "ref %d\n", ref );
1383 ok( node != node2, "node %p node2 %p\n", node, node2 );
1385 ref = IXMLDOMDocument_Release( doc );
1386 ok( ref == 0, "ref %d\n", ref );
1388 ref = IXMLDOMElement_AddRef( element );
1390 ok( ref == 3, "ref %d\n", ref );
1392 IXMLDOMElement_Release( element );
1394 /* IUnknown must be unique however we obtain it */
1395 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1396 ok( r == S_OK, "rets %08x\n", r );
1397 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1398 ok( r == S_OK, "rets %08x\n", r );
1399 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1400 ok( r == S_OK, "rets %08x\n", r );
1401 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1403 IUnknown_Release( unk2 );
1404 IUnknown_Release( unk );
1405 IXMLDOMNode_Release( node );
1407 IXMLDOMElement_Release( element );
1411 static void test_create(void)
1413 static const WCHAR szOne[] = {'1',0};
1414 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1418 IXMLDOMDocument *doc;
1419 IXMLDOMElement *element;
1420 IXMLDOMNode *root, *node, *child;
1421 IXMLDOMNamedNodeMap *attr_map;
1426 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1427 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1432 V_I1(&var) = NODE_ELEMENT;
1433 str = SysAllocString( szlc );
1434 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1435 ok( r == S_OK, "returns %08x\n", r );
1436 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1439 V_R4(&var) = NODE_ELEMENT;
1440 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1441 ok( r == S_OK, "returns %08x\n", r );
1442 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1444 V_VT(&var) = VT_BSTR;
1445 V_BSTR(&var) = SysAllocString( szOne );
1446 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1447 ok( r == S_OK, "returns %08x\n", r );
1448 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1451 V_VT(&var) = VT_BSTR;
1452 V_BSTR(&var) = SysAllocString( szOneGarbage );
1453 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1454 ok( r == E_INVALIDARG, "returns %08x\n", r );
1455 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1459 V_I4(&var) = NODE_ELEMENT;
1460 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1461 ok( r == S_OK, "returns %08x\n", r );
1462 r = IXMLDOMDocument_appendChild( doc, node, &root );
1463 ok( r == S_OK, "returns %08x\n", r );
1464 ok( node == root, "%p %p\n", node, root );
1466 ref = IXMLDOMNode_AddRef( node );
1467 ok(ref == 3, "ref %d\n", ref);
1468 IXMLDOMNode_Release( node );
1470 ref = IXMLDOMNode_Release( node );
1471 ok(ref == 1, "ref %d\n", ref);
1472 SysFreeString( str );
1475 V_I4(&var) = NODE_ELEMENT;
1476 str = SysAllocString( szbs );
1477 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1478 ok( r == S_OK, "returns %08x\n", r );
1479 SysFreeString( str );
1481 ref = IXMLDOMNode_AddRef( node );
1482 ok(ref == 2, "ref = %d\n", ref);
1483 IXMLDOMNode_Release( node );
1485 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1486 ok( r == S_OK, "returns %08x\n", r );
1488 ref = IXMLDOMNode_AddRef( unk );
1489 ok(ref == 3, "ref = %d\n", ref);
1490 IXMLDOMNode_Release( unk );
1492 V_VT(&var) = VT_EMPTY;
1493 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1494 ok( r == S_OK, "returns %08x\n", r );
1495 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1496 IXMLDOMNode_Release( child );
1497 IUnknown_Release( unk );
1500 V_VT(&var) = VT_NULL;
1501 V_DISPATCH(&var) = (IDispatch*)node;
1502 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1503 ok( r == S_OK, "returns %08x\n", r );
1504 ok( node == child, "%p %p\n", node, child );
1505 IXMLDOMNode_Release( child );
1508 V_VT(&var) = VT_NULL;
1509 V_DISPATCH(&var) = (IDispatch*)node;
1510 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1511 ok( r == S_OK, "returns %08x\n", r );
1512 IXMLDOMNode_Release( node );
1514 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1515 ok( r == S_OK, "returns %08x\n", r );
1517 r = IXMLDOMElement_get_attributes( element, &attr_map );
1518 ok( r == S_OK, "returns %08x\n", r );
1519 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1520 ok( r == S_OK, "returns %08x\n", r );
1521 ok( num == 0, "num %ld\n", num );
1522 IXMLDOMNamedNodeMap_Release( attr_map );
1524 V_VT(&var) = VT_BSTR;
1525 V_BSTR(&var) = SysAllocString( szstr1 );
1526 name = SysAllocString( szdl );
1527 r = IXMLDOMElement_setAttribute( element, name, var );
1528 ok( r == S_OK, "returns %08x\n", r );
1529 r = IXMLDOMElement_get_attributes( element, &attr_map );
1530 ok( r == S_OK, "returns %08x\n", r );
1531 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1532 ok( r == S_OK, "returns %08x\n", r );
1533 ok( num == 1, "num %ld\n", num );
1534 IXMLDOMNamedNodeMap_Release( attr_map );
1537 V_VT(&var) = VT_BSTR;
1538 V_BSTR(&var) = SysAllocString( szstr2 );
1539 r = IXMLDOMElement_setAttribute( element, name, var );
1540 ok( r == S_OK, "returns %08x\n", r );
1541 r = IXMLDOMElement_get_attributes( element, &attr_map );
1542 ok( r == S_OK, "returns %08x\n", r );
1543 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1544 ok( r == S_OK, "returns %08x\n", r );
1545 ok( num == 1, "num %ld\n", num );
1546 IXMLDOMNamedNodeMap_Release( attr_map );
1548 r = IXMLDOMElement_getAttribute( element, name, &var );
1549 ok( r == S_OK, "returns %08x\n", r );
1550 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1552 SysFreeString(name);
1554 V_VT(&var) = VT_BSTR;
1555 V_BSTR(&var) = SysAllocString( szstr1 );
1556 name = SysAllocString( szlc );
1557 r = IXMLDOMElement_setAttribute( element, name, var );
1558 ok( r == S_OK, "returns %08x\n", r );
1559 r = IXMLDOMElement_get_attributes( element, &attr_map );
1560 ok( r == S_OK, "returns %08x\n", r );
1561 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1562 ok( r == S_OK, "returns %08x\n", r );
1563 ok( num == 2, "num %ld\n", num );
1564 IXMLDOMNamedNodeMap_Release( attr_map );
1566 SysFreeString(name);
1570 name = SysAllocString( szbs );
1571 r = IXMLDOMElement_setAttribute( element, name, var );
1572 ok( r == S_OK, "returns %08x\n", r );
1574 r = IXMLDOMElement_getAttribute( element, name, &var );
1575 ok( r == S_OK, "returns %08x\n", r );
1576 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1578 SysFreeString(name);
1580 /* Create an Attribute */
1582 V_I4(&var) = NODE_ATTRIBUTE;
1583 str = SysAllocString( szAttribute );
1584 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1585 ok( r == S_OK, "returns %08x\n", r );
1586 ok( node != NULL, "node was null\n");
1591 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1592 ok( r == S_OK, "returns %08x\n", r );
1593 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1595 IXMLDOMNode_Release( node );
1598 IXMLDOMElement_Release( element );
1599 IXMLDOMNode_Release( root );
1600 IXMLDOMDocument_Release( doc );
1603 static void test_getElementsByTagName(void)
1608 IXMLDOMDocument *doc;
1609 IXMLDOMNodeList *node_list;
1610 IDispatchEx *dispex;
1613 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1614 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1618 str = SysAllocString( szComplete4 );
1619 r = IXMLDOMDocument_loadXML( doc, str, &b );
1620 ok( r == S_OK, "loadXML failed\n");
1621 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1622 SysFreeString( str );
1624 str = SysAllocString( szstar );
1625 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1626 ok( r == S_OK, "ret %08x\n", r );
1627 r = IXMLDOMNodeList_get_length( node_list, &len );
1628 ok( r == S_OK, "ret %08x\n", r );
1629 ok( len == 6, "len %ld\n", len );
1631 r = IXMLDOMNodeList_QueryInterface( node_list, &IID_IDispatchEx, (void**)&dispex );
1632 ok( r == S_OK, "rets %08x\n", r);
1635 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
1640 sName = SysAllocString( szstar );
1641 r = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
1642 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1643 SysFreeString( sName );
1645 r = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
1646 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1648 r = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
1649 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1650 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
1652 r = IDispatchEx_GetMemberName(dispex, dispid, &sName);
1653 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1655 SysFreeString(sName);
1657 r = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
1658 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1660 r = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
1661 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1663 IUnknown_Release(pUnk);
1665 IDispatchEx_Release( dispex );
1669 IXMLDOMNodeList_Release( node_list );
1670 SysFreeString( str );
1672 str = SysAllocString( szbs );
1673 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1674 ok( r == S_OK, "ret %08x\n", r );
1675 r = IXMLDOMNodeList_get_length( node_list, &len );
1676 ok( r == S_OK, "ret %08x\n", r );
1677 ok( len == 1, "len %ld\n", len );
1678 IXMLDOMNodeList_Release( node_list );
1679 SysFreeString( str );
1681 str = SysAllocString( szdl );
1682 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1683 ok( r == S_OK, "ret %08x\n", r );
1684 r = IXMLDOMNodeList_get_length( node_list, &len );
1685 ok( r == S_OK, "ret %08x\n", r );
1686 ok( len == 0, "len %ld\n", len );
1687 IXMLDOMNodeList_Release( node_list );
1688 SysFreeString( str );
1690 str = SysAllocString( szstr1 );
1691 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1692 ok( r == S_OK, "ret %08x\n", r );
1693 r = IXMLDOMNodeList_get_length( node_list, &len );
1694 ok( r == S_OK, "ret %08x\n", r );
1695 ok( len == 0, "len %ld\n", len );
1696 IXMLDOMNodeList_Release( node_list );
1697 SysFreeString( str );
1699 IXMLDOMDocument_Release( doc );
1702 static void test_get_text(void)
1707 IXMLDOMDocument *doc;
1708 IXMLDOMNode *node, *node2, *node3;
1709 IXMLDOMNodeList *node_list;
1710 IXMLDOMNamedNodeMap *node_map;
1713 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1714 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1718 str = SysAllocString( szComplete4 );
1719 r = IXMLDOMDocument_loadXML( doc, str, &b );
1720 ok( r == S_OK, "loadXML failed\n");
1721 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1722 SysFreeString( str );
1724 str = SysAllocString( szbs );
1725 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1726 ok( r == S_OK, "ret %08x\n", r );
1730 /* this test crashes on win9x */
1731 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1732 ok( r == E_INVALIDARG, "ret %08x\n", r );
1735 r = IXMLDOMNodeList_get_length( node_list, NULL );
1736 ok( r == E_INVALIDARG, "ret %08x\n", r );
1738 r = IXMLDOMNodeList_get_length( node_list, &len );
1739 ok( r == S_OK, "ret %08x\n", r );
1740 ok( len == 1, "expect 1 got %ld\n", len );
1742 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1743 ok( r == E_INVALIDARG, "ret %08x\n", r );
1745 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1746 ok( r == E_INVALIDARG, "ret %08x\n", r );
1748 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1749 ok( r == S_OK, "ret %08x\n", r );
1750 IXMLDOMNodeList_Release( node_list );
1752 /* Invalid output parameter*/
1753 r = IXMLDOMNode_get_text( node, NULL );
1754 ok( r == E_INVALIDARG, "ret %08x\n", r );
1756 r = IXMLDOMNode_get_text( node, &str );
1757 ok( r == S_OK, "ret %08x\n", r );
1758 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1761 r = IXMLDOMNode_get_attributes( node, &node_map );
1762 ok( r == S_OK, "ret %08x\n", r );
1764 str = SysAllocString( szvr );
1765 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1766 ok( r == S_OK, "ret %08x\n", r );
1769 r = IXMLDOMNode_get_text( node2, &str );
1770 ok( r == S_OK, "ret %08x\n", r );
1771 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1774 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1775 ok( r == S_OK, "ret %08x\n", r );
1777 r = IXMLDOMNode_get_text( node3, &str );
1778 ok( r == S_OK, "ret %08x\n", r );
1779 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1783 IXMLDOMNode_Release( node3 );
1784 IXMLDOMNode_Release( node2 );
1785 IXMLDOMNamedNodeMap_Release( node_map );
1786 IXMLDOMNode_Release( node );
1787 IXMLDOMDocument_Release( doc );
1790 static void test_get_childNodes(void)
1795 IXMLDOMDocument *doc;
1796 IXMLDOMElement *element;
1797 IXMLDOMNode *node, *node2;
1798 IXMLDOMNodeList *node_list, *node_list2;
1801 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1802 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1806 str = SysAllocString( szComplete4 );
1807 r = IXMLDOMDocument_loadXML( doc, str, &b );
1808 ok( r == S_OK, "loadXML failed\n");
1809 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1810 SysFreeString( str );
1812 r = IXMLDOMDocument_get_documentElement( doc, &element );
1813 ok( r == S_OK, "ret %08x\n", r);
1815 r = IXMLDOMElement_get_childNodes( element, &node_list );
1816 ok( r == S_OK, "ret %08x\n", r);
1818 r = IXMLDOMNodeList_get_length( node_list, &len );
1819 ok( r == S_OK, "ret %08x\n", r);
1820 ok( len == 4, "len %ld\n", len);
1822 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1823 ok( r == S_OK, "ret %08x\n", r);
1825 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1826 ok( r == S_OK, "ret %08x\n", r);
1828 r = IXMLDOMNodeList_get_length( node_list2, &len );
1829 ok( r == S_OK, "ret %08x\n", r);
1830 ok( len == 0, "len %ld\n", len);
1832 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1833 ok( r == S_FALSE, "ret %08x\n", r);
1835 IXMLDOMNodeList_Release( node_list2 );
1836 IXMLDOMNode_Release( node );
1837 IXMLDOMNodeList_Release( node_list );
1838 IXMLDOMElement_Release( element );
1839 IXMLDOMDocument_Release( doc );
1842 static void test_removeChild(void)
1847 IXMLDOMDocument *doc;
1848 IXMLDOMElement *element, *lc_element;
1849 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
1850 IXMLDOMNodeList *root_list, *fo_list;
1852 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1853 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1857 str = SysAllocString( szComplete4 );
1858 r = IXMLDOMDocument_loadXML( doc, str, &b );
1859 ok( r == S_OK, "loadXML failed\n");
1860 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1861 SysFreeString( str );
1863 r = IXMLDOMDocument_get_documentElement( doc, &element );
1864 ok( r == S_OK, "ret %08x\n", r);
1866 r = IXMLDOMElement_get_childNodes( element, &root_list );
1867 ok( r == S_OK, "ret %08x\n", r);
1869 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1870 ok( r == S_OK, "ret %08x\n", r);
1872 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1873 ok( r == S_OK, "ret %08x\n", r);
1875 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1876 ok( r == S_OK, "ret %08x\n", r);
1878 /* invalid parameter: NULL ptr */
1879 removed_node = (void*)0xdeadbeef;
1880 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
1881 ok( r == E_INVALIDARG, "ret %08x\n", r );
1882 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1884 /* ba_node is a descendant of element, but not a direct child. */
1885 removed_node = (void*)0xdeadbeef;
1886 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
1887 ok( r == E_INVALIDARG, "ret %08x\n", r );
1888 ok( removed_node == NULL, "%p\n", removed_node );
1890 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
1891 ok( r == S_OK, "ret %08x\n", r);
1892 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
1894 /* try removing already removed child */
1895 temp_node = (void*)0xdeadbeef;
1896 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
1897 ok( r == E_INVALIDARG, "ret %08x\n", r);
1898 ok( temp_node == NULL, "%p\n", temp_node );
1900 /* the removed node has no parent anymore */
1901 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
1902 ok( r == S_FALSE, "ret %08x\n", r);
1903 ok( temp_node == NULL, "%p\n", temp_node );
1905 IXMLDOMNode_Release( removed_node );
1906 IXMLDOMNode_Release( ba_node );
1907 IXMLDOMNodeList_Release( fo_list );
1909 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
1910 ok( r == S_OK, "ret %08x\n", r);
1912 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (LPVOID*)&lc_element );
1913 ok( r == S_OK, "ret %08x\n", r);
1915 /* MS quirk: passing wrong interface pointer works, too */
1916 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
1917 ok( r == S_OK, "ret %08x\n", r);
1919 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
1920 ok( r == S_FALSE, "ret %08x\n", r);
1921 ok( temp_node == NULL, "%p\n", temp_node );
1923 IXMLDOMNode_Release( lc_node );
1924 IXMLDOMNodeList_Release( root_list );
1925 IXMLDOMElement_Release( element );
1926 IXMLDOMDocument_Release( doc );
1929 static void test_replaceChild(void)
1934 IXMLDOMDocument *doc;
1935 IXMLDOMElement *element, *ba_element;
1936 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
1937 IXMLDOMNodeList *root_list, *fo_list;
1938 IUnknown * unk1, *unk2;
1941 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1942 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1946 str = SysAllocString( szComplete4 );
1947 r = IXMLDOMDocument_loadXML( doc, str, &b );
1948 ok( r == S_OK, "loadXML failed\n");
1949 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1950 SysFreeString( str );
1952 r = IXMLDOMDocument_get_documentElement( doc, &element );
1953 ok( r == S_OK, "ret %08x\n", r);
1955 r = IXMLDOMElement_get_childNodes( element, &root_list );
1956 ok( r == S_OK, "ret %08x\n", r);
1958 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
1959 ok( r == S_OK, "ret %08x\n", r);
1961 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1962 ok( r == S_OK, "ret %08x\n", r);
1964 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1965 ok( r == S_OK, "ret %08x\n", r);
1967 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1968 ok( r == S_OK, "ret %08x\n", r);
1970 IXMLDOMNodeList_Release( fo_list );
1972 /* invalid parameter: NULL ptr for element to remove */
1973 removed_node = (void*)0xdeadbeef;
1974 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
1975 ok( r == E_INVALIDARG, "ret %08x\n", r );
1976 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1978 /* invalid parameter: NULL for replacement element. (Sic!) */
1979 removed_node = (void*)0xdeadbeef;
1980 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
1981 ok( r == E_INVALIDARG, "ret %08x\n", r );
1982 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1984 /* invalid parameter: OldNode is not a child */
1985 removed_node = (void*)0xdeadbeef;
1986 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
1987 ok( r == E_INVALIDARG, "ret %08x\n", r );
1988 ok( removed_node == NULL, "%p\n", removed_node );
1990 /* invalid parameter: would create loop */
1991 removed_node = (void*)0xdeadbeef;
1992 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
1993 ok( r == E_FAIL, "ret %08x\n", r );
1994 ok( removed_node == NULL, "%p\n", removed_node );
1996 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
1997 ok( r == S_OK, "ret %08x\n", r );
1999 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
2000 ok( r == S_OK, "ret %08x\n", r );
2002 /* ba_node and temp_node refer to the same node, yet they
2003 are different interface pointers */
2004 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
2005 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
2006 ok( r == S_OK, "ret %08x\n", r );
2007 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
2008 ok( r == S_OK, "ret %08x\n", r );
2009 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
2011 IUnknown_Release( unk1 );
2012 IUnknown_Release( unk2 );
2014 /* ba_node should have been removed from below fo_node */
2015 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2016 ok( r == S_OK, "ret %08x\n", r );
2018 /* MS quirk: replaceChild also accepts elements instead of nodes */
2019 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
2020 ok( r == S_OK, "ret %08x\n", r );
2022 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
2023 ok( r == S_OK, "ret %08x\n", r );
2025 r = IXMLDOMNodeList_get_length( fo_list, &len);
2026 ok( r == S_OK, "ret %08x\n", r );
2027 ok( len == 0, "len %ld\n", len);
2029 IXMLDOMNodeList_Release( fo_list );
2031 IXMLDOMNode_Release(ba_node);
2032 IXMLDOMNode_Release(fo_node);
2033 IXMLDOMNode_Release(temp_node);
2034 IXMLDOMNodeList_Release( root_list );
2035 IXMLDOMElement_Release( element );
2036 IXMLDOMDocument_Release( doc );
2039 static void test_removeNamedItem(void)
2041 IXMLDOMDocument *doc;
2042 IXMLDOMElement *element;
2043 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
2044 IXMLDOMNodeList *root_list;
2045 IXMLDOMNamedNodeMap * pr_attrs;
2051 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2052 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2056 str = SysAllocString( szComplete4 );
2057 r = IXMLDOMDocument_loadXML( doc, str, &b );
2058 ok( r == S_OK, "loadXML failed\n");
2059 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2060 SysFreeString( str );
2062 r = IXMLDOMDocument_get_documentElement( doc, &element );
2063 ok( r == S_OK, "ret %08x\n", r);
2065 r = IXMLDOMElement_get_childNodes( element, &root_list );
2066 ok( r == S_OK, "ret %08x\n", r);
2068 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2069 ok( r == S_OK, "ret %08x\n", r);
2071 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2072 ok( r == S_OK, "ret %08x\n", r);
2074 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2075 ok( r == S_OK, "ret %08x\n", r);
2076 ok( len == 3, "length %ld\n", len);
2078 removed_node = (void*)0xdeadbeef;
2079 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2080 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2081 ok ( removed_node == (void*)0xdeadbeef, "removed_node == %p\n", removed_node);
2083 removed_node = (void*)0xdeadbeef;
2084 str = SysAllocString(szvr);
2085 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2086 ok ( r == S_OK, "ret %08x\n", r);
2088 removed_node2 = (void*)0xdeadbeef;
2089 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2090 ok ( r == S_FALSE, "ret %08x\n", r);
2091 ok ( removed_node2 == NULL, "removed_node == %p\n", removed_node2 );
2093 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2094 ok( r == S_OK, "ret %08x\n", r);
2095 ok( len == 2, "length %ld\n", len);
2097 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2098 ok ( r == S_OK, "ret %08x\n", r);
2099 IXMLDOMNode_Release(removed_node);
2101 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2102 ok( r == S_OK, "ret %08x\n", r);
2103 ok( len == 3, "length %ld\n", len);
2105 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2106 ok ( r == S_OK, "ret %08x\n", r);
2108 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2109 ok( r == S_OK, "ret %08x\n", r);
2110 ok( len == 2, "length %ld\n", len);
2112 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2113 ok ( r == S_FALSE, "ret %08x\n", r);
2117 IXMLDOMNamedNodeMap_Release( pr_attrs );
2118 IXMLDOMNode_Release( pr_node );
2119 IXMLDOMNodeList_Release( root_list );
2120 IXMLDOMElement_Release( element );
2121 IXMLDOMDocument_Release( doc );
2124 static void test_XMLHTTP(void)
2126 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2127 static WCHAR wszPOST[] = {'P','O','S','T',0};
2128 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2129 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2130 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2131 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2132 IXMLHttpRequest *pXMLHttpRequest;
2137 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2138 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2139 (void **)&pXMLHttpRequest);
2140 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
2144 VariantInit(&dummy);
2145 V_VT(&dummy) = VT_ERROR;
2146 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2147 VariantInit(&varfalse);
2148 V_VT(&varfalse) = VT_BOOL;
2149 V_BOOL(&varfalse) = VARIANT_FALSE;
2150 V_VT(&varbody) = VT_BSTR;
2151 V_BSTR(&varbody) = SysAllocString(wszBody);
2153 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
2154 todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
2156 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2157 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2158 VariantClear(&varbody);
2160 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2161 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2162 /* the server currently returns "FAILED" because the Content-Type header is
2163 * not what the server expects */
2166 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2167 SysFreeString(bstrResponse);
2170 IXMLHttpRequest_Release(pXMLHttpRequest);
2173 static void test_IXMLDOMDocument2(void)
2178 IXMLDOMDocument *doc;
2179 IXMLDOMDocument2 *doc2;
2180 IDispatchEx *dispex;
2184 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2185 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2189 str = SysAllocString( szComplete4 );
2190 r = IXMLDOMDocument_loadXML( doc, str, &b );
2191 ok( r == S_OK, "loadXML failed\n");
2192 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2193 SysFreeString( str );
2195 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
2196 ok( r == S_OK, "ret %08x\n", r );
2197 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
2199 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
2200 ok( r == S_OK, "ret %08x\n", r );
2203 IDispatchEx_Release(dispex);
2206 /* we will check if the variant got cleared */
2207 ref = IXMLDOMDocument2_AddRef(doc2);
2208 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
2209 V_VT(&var) = VT_UNKNOWN;
2210 V_UNKNOWN(&var) = (IUnknown *)doc2;
2213 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
2214 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
2215 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
2218 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2219 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2220 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2223 /* the variant didn't get cleared*/
2224 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
2226 /* setProperty tests */
2227 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
2228 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
2229 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
2230 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2231 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2232 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2234 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
2235 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2236 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2237 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2239 IXMLDOMDocument2_Release( doc2 );
2240 IXMLDOMDocument_Release( doc );
2244 static void test_XPath(void)
2249 IXMLDOMDocument2 *doc;
2250 IXMLDOMNode *rootNode;
2251 IXMLDOMNode *elem1Node;
2253 IXMLDOMNodeList *list;
2255 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2256 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2260 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
2261 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2263 /* switch to XPath */
2264 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2266 /* some simple queries*/
2267 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
2268 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
2269 ole_check(IXMLDOMNodeList_reset(list));
2270 expect_list_and_release(list, "E2.D1");
2271 if (rootNode == NULL)
2274 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
2275 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
2277 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
2278 expect_list_and_release(list, "E3.E2.E2.D1");
2280 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
2281 /* using get_item for query results advances the position */
2282 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2283 expect_node(node, "E2.E2.D1");
2284 IXMLDOMNode_Release(node);
2285 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2286 expect_node(node, "E4.E2.D1");
2287 IXMLDOMNode_Release(node);
2288 ole_check(IXMLDOMNodeList_reset(list));
2289 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2291 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2292 expect_list_and_release(list, "E2.D1");
2294 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2295 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2296 ole_check(IXMLDOMNodeList_reset(list));
2297 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2299 /* select an attribute */
2300 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2301 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2303 /* would evaluate to a number */
2304 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2305 /* would evaluate to a boolean */
2306 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2307 /* would evaluate to a string */
2308 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2311 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2312 expect_list_and_release(list, "");
2313 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2314 expect_list_and_release(list, "");
2315 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2316 expect_list_and_release(list, "");
2318 /* foo undeclared in document node */
2319 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2320 /* undeclared in <root> node */
2321 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2322 /* undeclared in <elem> node */
2323 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2324 /* but this trick can be used */
2325 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2326 expect_list_and_release(list, "E3.E4.E2.D1");
2328 /* it has to be declared in SelectionNamespaces */
2329 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2330 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2332 /* now the namespace can be used */
2333 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2334 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2335 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2336 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2337 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2338 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2339 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2340 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2342 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2343 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2344 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2346 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2349 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2350 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2351 if (V_VT(&var) == VT_BSTR)
2352 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2354 /* extra attributes - same thing*/
2355 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2356 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2357 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2359 IXMLDOMNode_Release(rootNode);
2360 IXMLDOMNode_Release(elem1Node);
2361 IXMLDOMDocument_Release(doc);
2365 static void test_cloneNode(void )
2367 IXMLDOMDocument *doc = NULL;
2369 IXMLDOMNodeList *pList;
2370 IXMLDOMNamedNodeMap *mapAttr;
2371 long nLength = 0, nLength1 = 0;
2372 long nAttrCnt = 0, nAttrCnt1 = 0;
2374 IXMLDOMNode *node_clone;
2377 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2379 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2383 str = SysAllocString( szComplete4 );
2384 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2385 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2391 str = SysAllocString( szSearch);
2392 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2393 ok( r == S_OK, "ret %08x\n", r );
2394 ok( node != NULL, "node %p\n", node );
2399 IXMLDOMDocument_Release(doc);
2403 /* Check invalid parameter */
2404 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2405 ok( r == E_INVALIDARG, "ret %08x\n", r );
2408 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2409 ok( r == S_OK, "ret %08x\n", r );
2410 ok( node_clone != NULL, "node %p\n", node );
2414 IXMLDOMDocument_Release(doc);
2415 IXMLDOMNode_Release(node);
2419 r = IXMLDOMNode_get_childNodes(node, &pList);
2420 ok( r == S_OK, "ret %08x\n", r );
2423 IXMLDOMNodeList_get_length(pList, &nLength);
2424 IXMLDOMNodeList_Release(pList);
2427 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2428 ok( r == S_OK, "ret %08x\n", r );
2431 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2432 IXMLDOMNamedNodeMap_Release(mapAttr);
2435 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2436 ok( r == S_OK, "ret %08x\n", r );
2439 IXMLDOMNodeList_get_length(pList, &nLength1);
2440 IXMLDOMNodeList_Release(pList);
2443 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2444 ok( r == S_OK, "ret %08x\n", r );
2447 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2448 IXMLDOMNamedNodeMap_Release(mapAttr);
2451 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2452 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2453 IXMLDOMNode_Release(node_clone);
2456 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2457 ok( r == S_OK, "ret %08x\n", r );
2458 ok( node_clone != NULL, "node %p\n", node );
2462 IXMLDOMDocument_Release(doc);
2463 IXMLDOMNode_Release(node);
2467 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2468 ok( r == S_OK, "ret %08x\n", r );
2471 IXMLDOMNodeList_get_length(pList, &nLength1);
2472 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
2473 IXMLDOMNodeList_Release(pList);
2476 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2477 ok( r == S_OK, "ret %08x\n", r );
2480 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2481 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
2482 IXMLDOMNamedNodeMap_Release(mapAttr);
2485 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2486 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2487 IXMLDOMNode_Release(node_clone);
2490 IXMLDOMNode_Release(node);
2491 IXMLDOMDocument_Release(doc);
2494 static void test_xmlTypes(void)
2496 IXMLDOMDocument *doc = NULL;
2497 IXMLDOMElement *pRoot;
2499 IXMLDOMComment *pComment;
2500 IXMLDOMElement *pElement;
2501 IXMLDOMAttribute *pAttrubute;
2502 IXMLDOMNamedNodeMap *pAttribs;
2503 IXMLDOMCDATASection *pCDataSec;
2504 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2505 IXMLDOMDocumentFragment *pDocFrag = NULL;
2506 IXMLDOMEntityReference *pEntityRef = NULL;
2508 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2512 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2516 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2517 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2519 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2520 ok(hr == S_FALSE, "ret %08x\n", hr );
2521 ok(pNextChild == NULL, "pDocChild not NULL\n");
2523 /* test previous Sibling */
2524 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2525 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2527 pNextChild = (IXMLDOMNode *)0x1;
2528 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2529 ok(hr == S_FALSE, "ret %08x\n", hr );
2530 ok(pNextChild == NULL, "pNextChild not NULL\n");
2532 /* test get_attributes */
2533 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2534 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2536 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2537 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2538 ok(hr == S_FALSE, "ret %08x\n", hr );
2539 ok( pAttribs == NULL, "pAttribs not NULL\n");
2541 /* test get_dataType */
2542 hr = IXMLDOMDocument_get_dataType(doc, &v);
2543 ok(hr == S_FALSE, "ret %08x\n", hr );
2544 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2547 /* test nodeTypeString */
2548 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2549 ok(hr == S_OK, "ret %08x\n", hr );
2550 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2553 /* test implementation */
2554 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2555 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2557 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2558 ok(hr == S_OK, "ret %08x\n", hr );
2561 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2562 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2564 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2565 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2567 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2568 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2570 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2571 ok(hr == S_OK, "ret %08x\n", hr );
2572 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2574 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2575 ok(hr == S_OK, "ret %08x\n", hr );
2576 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2578 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2579 ok(hr == S_OK, "ret %08x\n", hr );
2580 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2582 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2583 ok(hr == S_OK, "ret %08x\n", hr );
2584 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2586 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2587 ok(hr == S_OK, "ret %08x\n", hr );
2588 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2590 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2591 ok(hr == S_OK, "ret %08x\n", hr );
2592 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2594 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2595 ok(hr == S_OK, "ret %08x\n", hr );
2596 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2598 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2599 ok(hr == S_OK, "ret %08x\n", hr );
2600 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2602 SysFreeString(sEmpty);
2603 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2608 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2609 ok(hr == S_OK, "ret %08x\n", hr );
2612 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2613 ok(hr == S_OK, "ret %08x\n", hr );
2617 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2618 ok(hr == S_OK, "ret %08x\n", hr );
2621 /* test get_attributes */
2622 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2623 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2625 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2626 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2627 ok(hr == S_FALSE, "ret %08x\n", hr );
2628 ok( pAttribs == NULL, "pAttribs not NULL\n");
2630 /* test nodeTypeString */
2631 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2632 ok(hr == S_OK, "ret %08x\n", hr );
2633 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2636 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2637 ok(hr == S_OK, "ret %08x\n", hr );
2639 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2640 ok(hr == S_OK, "ret %08x\n", hr );
2641 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2644 hr = IXMLDOMComment_get_xml(pComment, &str);
2645 ok(hr == S_OK, "ret %08x\n", hr );
2646 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2649 hr = IXMLDOMComment_get_dataType(pComment, &v);
2650 ok(hr == S_FALSE, "ret %08x\n", hr );
2651 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2654 /* put data Tests */
2655 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2656 ok(hr == S_OK, "ret %08x\n", hr );
2658 /* get data Tests */
2659 hr = IXMLDOMComment_get_data(pComment, &str);
2660 ok(hr == S_OK, "ret %08x\n", hr );
2661 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2664 /* get data Tests */
2665 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2666 ok(hr == S_OK, "ret %08x\n", hr );
2667 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2668 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2671 /* Confirm XML text is good */
2672 hr = IXMLDOMComment_get_xml(pComment, &str);
2673 ok(hr == S_OK, "ret %08x\n", hr );
2674 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2677 /* Confirm we get the put_data Text back */
2678 hr = IXMLDOMComment_get_text(pComment, &str);
2679 ok(hr == S_OK, "ret %08x\n", hr );
2680 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2683 /* test length property */
2684 hr = IXMLDOMComment_get_length(pComment, &len);
2685 ok(hr == S_OK, "ret %08x\n", hr );
2686 ok(len == 21, "expected 21 got %ld\n", len);
2688 /* test substringData */
2689 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2690 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2692 /* test substringData - Invalid offset */
2693 str = (BSTR)&szElement;
2694 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2695 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2696 ok( str == NULL, "incorrect string\n");
2698 /* test substringData - Invalid offset */
2699 str = (BSTR)&szElement;
2700 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2701 ok(hr == S_FALSE, "ret %08x\n", hr );
2702 ok( str == NULL, "incorrect string\n");
2704 /* test substringData - Invalid size */
2705 str = (BSTR)&szElement;
2706 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2707 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2708 ok( str == NULL, "incorrect string\n");
2710 /* test substringData - Invalid size */
2711 str = (BSTR)&szElement;
2712 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2713 ok(hr == S_FALSE, "ret %08x\n", hr );
2714 ok( str == NULL, "incorrect string\n");
2716 /* test substringData - Start of string */
2717 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2718 ok(hr == S_OK, "ret %08x\n", hr );
2719 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2722 /* test substringData - Middle of string */
2723 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2724 ok(hr == S_OK, "ret %08x\n", hr );
2725 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2728 /* test substringData - End of string */
2729 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2730 ok(hr == S_OK, "ret %08x\n", hr );
2731 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2734 /* test appendData */
2735 hr = IXMLDOMComment_appendData(pComment, NULL);
2736 ok(hr == S_OK, "ret %08x\n", hr );
2738 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2739 ok(hr == S_OK, "ret %08x\n", hr );
2741 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2742 ok(hr == S_OK, "ret %08x\n", hr );
2744 hr = IXMLDOMComment_get_text(pComment, &str);
2745 ok(hr == S_OK, "ret %08x\n", hr );
2746 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2749 /* test insertData */
2750 str = SysAllocStringLen(NULL, 0);
2751 hr = IXMLDOMComment_insertData(pComment, -1, str);
2752 ok(hr == S_OK, "ret %08x\n", hr );
2754 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2755 ok(hr == S_OK, "ret %08x\n", hr );
2757 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2758 ok(hr == S_OK, "ret %08x\n", hr );
2760 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2761 ok(hr == S_OK, "ret %08x\n", hr );
2763 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2764 ok(hr == S_OK, "ret %08x\n", hr );
2766 hr = IXMLDOMComment_insertData(pComment, 0, str);
2767 ok(hr == S_OK, "ret %08x\n", hr );
2770 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2771 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2773 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2774 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2776 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2777 ok(hr == S_OK, "ret %08x\n", hr );
2779 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2780 ok(hr == S_OK, "ret %08x\n", hr );
2782 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2783 ok(hr == S_OK, "ret %08x\n", hr );
2785 hr = IXMLDOMComment_get_text(pComment, &str);
2786 ok(hr == S_OK, "ret %08x\n", hr );
2787 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2790 IXMLDOMComment_Release(pComment);
2794 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2795 ok(hr == S_OK, "ret %08x\n", hr );
2798 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2799 ok(hr == S_OK, "ret %08x\n", hr );
2801 /* test nodeTypeString */
2802 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2803 ok(hr == S_OK, "ret %08x\n", hr );
2804 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2807 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2808 ok(hr == S_OK, "ret %08x\n", hr );
2809 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2812 hr = IXMLDOMElement_get_xml(pElement, &str);
2813 ok(hr == S_OK, "ret %08x\n", hr );
2814 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2817 hr = IXMLDOMElement_get_dataType(pElement, &v);
2818 ok(hr == S_FALSE, "ret %08x\n", hr );
2819 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2823 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2824 ok(hr == S_OK, "ret %08x\n", hr );
2827 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2829 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2830 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2832 pNextChild = (IXMLDOMNode *)0x1;
2833 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2834 ok(hr == S_FALSE, "ret %08x\n", hr );
2835 ok(pNextChild == NULL, "pNextChild not NULL\n");
2837 /* test Previous Sibling*/
2838 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2839 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2841 pNextChild = (IXMLDOMNode *)0x1;
2842 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2843 ok(hr == S_FALSE, "ret %08x\n", hr );
2844 ok(pNextChild == NULL, "pNextChild not NULL\n");
2846 /* test get_attributes */
2847 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2848 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2850 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2851 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2852 ok(hr == S_FALSE, "ret %08x\n", hr );
2853 ok( pAttribs == NULL, "pAttribs not NULL\n");
2855 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2856 ok(hr == E_FAIL, "ret %08x\n", hr );
2857 ok(pNewChild == NULL, "pNewChild not NULL\n");
2859 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2860 ok(hr == S_OK, "ret %08x\n", hr );
2863 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2864 ok(hr == S_OK, "ret %08x\n", hr );
2866 IXMLDOMNamedNodeMap_Release(pAttribs);
2869 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2870 ok(hr == S_OK, "ret %08x\n", hr );
2871 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2874 /* test nodeTypeString */
2875 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2876 ok(hr == S_OK, "ret %08x\n", hr );
2877 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2881 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2882 ok(hr == S_OK, "ret %08x\n", hr );
2883 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
2886 /* test name property */
2887 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
2888 ok(hr == S_OK, "ret %08x\n", hr );
2889 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
2892 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2893 ok(hr == S_OK, "ret %08x\n", hr );
2894 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2897 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2898 ok(hr == S_FALSE, "ret %08x\n", hr );
2899 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2902 IXMLDOMAttribute_Release(pAttrubute);
2904 /* Check Element again with the Add Attribute*/
2905 hr = IXMLDOMElement_get_xml(pElement, &str);
2906 ok(hr == S_OK, "ret %08x\n", hr );
2907 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2911 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2912 ok(hr == S_OK, "ret %08x\n", hr );
2914 hr = IXMLDOMElement_get_xml(pElement, &str);
2915 ok(hr == S_OK, "ret %08x\n", hr );
2916 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2919 /* Test for reversible escaping */
2920 str = SysAllocString( szStrangeChars );
2921 hr = IXMLDOMElement_put_text(pElement, str);
2922 ok(hr == S_OK, "ret %08x\n", hr );
2923 SysFreeString( str );
2925 hr = IXMLDOMElement_get_xml(pElement, &str);
2926 ok(hr == S_OK, "ret %08x\n", hr );
2927 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
2930 hr = IXMLDOMElement_get_text(pElement, &str);
2931 ok(hr == S_OK, "ret %08x\n", hr );
2932 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
2935 IXMLDOMElement_Release(pElement);
2939 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2940 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2942 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2943 ok(hr == S_OK, "ret %08x\n", hr );
2946 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2949 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (LPVOID*)&pElement);
2950 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
2952 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2953 ok(hr == S_OK, "ret %08x\n", hr );
2955 /* get Attribute Tests */
2956 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2957 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2959 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2960 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2961 ok(hr == S_FALSE, "ret %08x\n", hr );
2962 ok(pAttribs == NULL, "pAttribs != NULL\n");
2964 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2965 ok(hr == S_OK, "ret %08x\n", hr );
2966 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2969 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2970 ok(hr == S_OK, "ret %08x\n", hr );
2971 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2974 /* test lastChild */
2975 pNextChild = (IXMLDOMNode*)0x1;
2976 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2977 ok(hr == S_FALSE, "ret %08x\n", hr );
2978 ok(pNextChild == NULL, "pNextChild not NULL\n");
2980 /* test get_dataType */
2981 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2982 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2984 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2985 ok(hr == S_FALSE, "ret %08x\n", hr );
2986 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2989 /* test nodeTypeString */
2990 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2991 ok(hr == S_OK, "ret %08x\n", hr );
2992 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2995 /* put data Tests */
2996 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
2997 ok(hr == S_OK, "ret %08x\n", hr );
2999 /* Confirm XML text is good */
3000 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3001 ok(hr == S_OK, "ret %08x\n", hr );
3002 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
3005 /* Confirm we get the put_data Text back */
3006 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3007 ok(hr == S_OK, "ret %08x\n", hr );
3008 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3011 /* test length property */
3012 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
3013 ok(hr == S_OK, "ret %08x\n", hr );
3014 ok(len == 21, "expected 21 got %ld\n", len);
3016 /* test get nodeValue */
3017 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
3018 ok(hr == S_OK, "ret %08x\n", hr );
3019 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3023 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
3024 ok(hr == S_OK, "ret %08x\n", hr );
3025 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3028 /* test substringData */
3029 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
3030 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3032 /* test substringData - Invalid offset */
3033 str = (BSTR)&szElement;
3034 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
3035 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3036 ok( str == NULL, "incorrect string\n");
3038 /* test substringData - Invalid offset */
3039 str = (BSTR)&szElement;
3040 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
3041 ok(hr == S_FALSE, "ret %08x\n", hr );
3042 ok( str == NULL, "incorrect string\n");
3044 /* test substringData - Invalid size */
3045 str = (BSTR)&szElement;
3046 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
3047 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3048 ok( str == NULL, "incorrect string\n");
3050 /* test substringData - Invalid size */
3051 str = (BSTR)&szElement;
3052 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
3053 ok(hr == S_FALSE, "ret %08x\n", hr );
3054 ok( str == NULL, "incorrect string\n");
3056 /* test substringData - Start of string */
3057 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
3058 ok(hr == S_OK, "ret %08x\n", hr );
3059 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
3062 /* test substringData - Middle of string */
3063 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
3064 ok(hr == S_OK, "ret %08x\n", hr );
3065 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
3068 /* test substringData - End of string */
3069 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
3070 ok(hr == S_OK, "ret %08x\n", hr );
3071 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
3074 /* test appendData */
3075 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
3076 ok(hr == S_OK, "ret %08x\n", hr );
3078 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
3079 ok(hr == S_OK, "ret %08x\n", hr );
3081 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
3082 ok(hr == S_OK, "ret %08x\n", hr );
3084 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3085 ok(hr == S_OK, "ret %08x\n", hr );
3086 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
3089 /* test insertData */
3090 str = SysAllocStringLen(NULL, 0);
3091 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
3092 ok(hr == S_OK, "ret %08x\n", hr );
3094 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
3095 ok(hr == S_OK, "ret %08x\n", hr );
3097 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
3098 ok(hr == S_OK, "ret %08x\n", hr );
3100 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
3101 ok(hr == S_OK, "ret %08x\n", hr );
3103 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
3104 ok(hr == S_OK, "ret %08x\n", hr );
3106 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
3107 ok(hr == S_OK, "ret %08x\n", hr );
3110 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
3111 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3113 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
3114 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3116 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
3117 ok(hr == S_OK, "ret %08x\n", hr );
3119 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
3120 ok(hr == S_OK, "ret %08x\n", hr );
3122 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
3123 ok(hr == S_OK, "ret %08x\n", hr );
3125 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3126 ok(hr == S_OK, "ret %08x\n", hr );
3127 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
3130 IXMLDOMCDATASection_Release(pCDataSec);
3133 /* Document Fragments */
3134 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
3135 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3137 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
3138 ok(hr == S_OK, "ret %08x\n", hr );
3141 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3143 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
3144 ok(hr == S_OK, "ret %08x\n", hr );
3146 /* get Attribute Tests */
3147 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
3148 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3150 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3151 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
3152 ok(hr == S_FALSE, "ret %08x\n", hr );
3153 ok(pAttribs == NULL, "pAttribs != NULL\n");
3155 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
3156 ok(hr == S_OK, "ret %08x\n", hr );
3157 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
3160 /* test next Sibling*/
3161 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
3162 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3164 pNextChild = (IXMLDOMNode *)0x1;
3165 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
3166 ok(hr == S_FALSE, "ret %08x\n", hr );
3167 ok(pNextChild == NULL, "pNextChild not NULL\n");
3169 /* test Previous Sibling*/
3170 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
3171 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3173 pNextChild = (IXMLDOMNode *)0x1;
3174 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
3175 ok(hr == S_FALSE, "ret %08x\n", hr );
3176 ok(pNextChild == NULL, "pNextChild not NULL\n");
3178 /* test get_dataType */
3179 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
3180 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3182 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
3183 ok(hr == S_FALSE, "ret %08x\n", hr );
3184 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3187 /* test nodeTypeString */
3188 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
3189 ok(hr == S_OK, "ret %08x\n", hr );
3190 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
3193 IXMLDOMDocumentFragment_Release(pDocFrag);
3196 /* Entity References */
3197 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
3198 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3200 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
3201 ok(hr == S_OK, "ret %08x\n", hr );
3204 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
3205 ok(hr == S_OK, "ret %08x\n", hr );
3207 /* get Attribute Tests */
3208 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
3209 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3211 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3212 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
3213 ok(hr == S_FALSE, "ret %08x\n", hr );
3214 ok(pAttribs == NULL, "pAttribs != NULL\n");
3217 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
3218 ok(hr == S_FALSE, "ret %08x\n", hr );
3219 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3222 /* test nodeTypeString */
3223 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
3224 ok(hr == S_OK, "ret %08x\n", hr );
3225 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
3229 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
3230 ok(hr == S_OK, "ret %08x\n", hr );
3231 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
3234 IXMLDOMEntityReference_Release(pEntityRef);
3237 IXMLDOMElement_Release( pRoot );
3241 IXMLDOMDocument_Release(doc);
3246 static void test_nodeTypeTests( void )
3248 IXMLDOMDocument *doc = NULL;
3249 IXMLDOMElement *pRoot;
3250 IXMLDOMElement *pElement;
3253 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3257 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3258 ok(hr == S_OK, "ret %08x\n", hr );
3261 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3262 ok(hr == S_OK, "ret %08x\n", hr );
3265 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
3266 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3269 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
3270 ok(hr == E_FAIL, "ret %08x\n", hr );
3273 * The name passed into put_dataType is case-insensitive. So many of the names
3274 * have been changed to reflect this.
3277 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
3278 ok(hr == S_OK, "ret %08x\n", hr );
3281 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3283 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
3284 ok(hr == S_OK, "ret %08x\n", hr );
3286 IXMLDOMElement_Release(pElement);
3290 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
3291 ok(hr == S_OK, "ret %08x\n", hr );
3294 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3296 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
3297 ok(hr == S_OK, "ret %08x\n", hr );
3299 IXMLDOMElement_Release(pElement);
3303 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
3304 ok(hr == S_OK, "ret %08x\n", hr );
3307 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3309 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
3310 ok(hr == S_OK, "ret %08x\n", hr );
3312 IXMLDOMElement_Release(pElement);
3316 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
3317 ok(hr == S_OK, "ret %08x\n", hr );
3320 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3322 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
3323 ok(hr == S_OK, "ret %08x\n", hr );
3325 IXMLDOMElement_Release(pElement);
3329 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3330 ok(hr == S_OK, "ret %08x\n", hr );
3333 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3335 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3336 ok(hr == S_OK, "ret %08x\n", hr );
3338 IXMLDOMElement_Release(pElement);
3342 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3343 ok(hr == S_OK, "ret %08x\n", hr );
3346 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3348 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3349 ok(hr == S_OK, "ret %08x\n", hr );
3351 IXMLDOMElement_Release(pElement);
3355 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3356 ok(hr == S_OK, "ret %08x\n", hr );
3359 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3361 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3362 ok(hr == S_OK, "ret %08x\n", hr );
3364 IXMLDOMElement_Release(pElement);
3368 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3369 ok(hr == S_OK, "ret %08x\n", hr );
3372 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3374 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3375 ok(hr == S_OK, "ret %08x\n", hr );
3377 IXMLDOMElement_Release(pElement);
3381 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3382 ok(hr == S_OK, "ret %08x\n", hr );
3385 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3387 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3388 ok(hr == S_OK, "ret %08x\n", hr );
3390 IXMLDOMElement_Release(pElement);
3394 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3395 ok(hr == S_OK, "ret %08x\n", hr );
3398 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3400 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3401 ok(hr == S_OK, "ret %08x\n", hr );
3403 IXMLDOMElement_Release(pElement);
3407 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3408 ok(hr == S_OK, "ret %08x\n", hr );
3411 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3413 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3414 ok(hr == S_OK, "ret %08x\n", hr );
3416 IXMLDOMElement_Release(pElement);
3420 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3421 ok(hr == S_OK, "ret %08x\n", hr );
3424 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3426 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3427 ok(hr == S_OK, "ret %08x\n", hr );
3429 IXMLDOMElement_Release(pElement);
3433 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3434 ok(hr == S_OK, "ret %08x\n", hr );
3437 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3439 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3440 ok(hr == S_OK, "ret %08x\n", hr );
3442 IXMLDOMElement_Release(pElement);
3446 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3447 ok(hr == S_OK, "ret %08x\n", hr );
3450 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3452 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3453 ok(hr == S_OK, "ret %08x\n", hr );
3455 IXMLDOMElement_Release(pElement);
3459 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3460 ok(hr == S_OK, "ret %08x\n", hr );
3463 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3465 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3466 ok(hr == S_OK, "ret %08x\n", hr );
3468 IXMLDOMElement_Release(pElement);
3472 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3473 ok(hr == S_OK, "ret %08x\n", hr );
3476 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3478 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3479 ok(hr == S_OK, "ret %08x\n", hr );
3481 IXMLDOMElement_Release(pElement);
3485 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3486 ok(hr == S_OK, "ret %08x\n", hr );
3489 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3491 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3492 ok(hr == S_OK, "ret %08x\n", hr );
3494 IXMLDOMElement_Release(pElement);
3498 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3499 ok(hr == S_OK, "ret %08x\n", hr );
3502 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3504 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3505 ok(hr == S_OK, "ret %08x\n", hr );
3507 IXMLDOMElement_Release(pElement);
3511 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3512 ok(hr == S_OK, "ret %08x\n", hr );
3515 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3517 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3518 ok(hr == S_OK, "ret %08x\n", hr );
3520 IXMLDOMElement_Release(pElement);
3524 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3525 ok(hr == S_OK, "ret %08x\n", hr );
3528 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3530 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3531 ok(hr == S_OK, "ret %08x\n", hr );
3533 IXMLDOMElement_Release(pElement);
3537 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3538 ok(hr == S_OK, "ret %08x\n", hr );
3541 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3543 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3544 ok(hr == S_OK, "ret %08x\n", hr );
3546 IXMLDOMElement_Release(pElement);
3550 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3551 ok(hr == S_OK, "ret %08x\n", hr );
3554 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3556 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3557 ok(hr == S_OK, "ret %08x\n", hr );
3559 IXMLDOMElement_Release(pElement);
3562 /* Check changing types */
3563 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3564 ok(hr == S_OK, "ret %08x\n", hr );
3567 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3569 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3570 ok(hr == S_OK, "ret %08x\n", hr );
3572 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3573 ok(hr == S_OK, "ret %08x\n", hr );
3575 IXMLDOMElement_Release(pElement);
3578 IXMLDOMElement_Release(pRoot);
3582 IXMLDOMDocument_Release(doc);
3587 static void test_DocumentSaveToDocument(void)
3589 IXMLDOMDocument *doc = NULL;
3590 IXMLDOMDocument *doc2 = NULL;
3591 IXMLDOMElement *pRoot;
3595 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3599 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3602 IXMLDOMDocument_Release(doc);
3606 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3607 ok(hr == S_OK, "ret %08x\n", hr );
3610 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3611 ok(hr == S_OK, "ret %08x\n", hr );
3618 V_VT(&vDoc) = VT_UNKNOWN;
3619 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3621 hr = IXMLDOMDocument_save(doc, vDoc);
3622 ok(hr == S_OK, "ret %08x\n", hr );
3624 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3625 ok(hr == S_OK, "ret %08x\n", hr );
3627 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3628 ok(hr == S_OK, "ret %08x\n", hr );
3630 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3632 SysFreeString(sOrig);
3633 SysFreeString(sNew);
3637 IXMLDOMDocument_Release(doc2);
3638 IXMLDOMDocument_Release(doc);
3641 static void test_DocumentSaveToFile(void)
3643 IXMLDOMDocument *doc = NULL;
3644 IXMLDOMElement *pRoot;
3650 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3654 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3655 ok(hr == S_OK, "ret %08x\n", hr );
3658 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3659 ok(hr == S_OK, "ret %08x\n", hr );
3664 V_VT(&vFile) = VT_BSTR;
3665 V_BSTR(&vFile) = _bstr_("test.xml");
3667 hr = IXMLDOMDocument_save(doc, vFile);
3668 ok(hr == S_OK, "ret %08x\n", hr );
3672 IXMLDOMElement_Release(pRoot);
3673 IXMLDOMDocument_Release(doc);
3675 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3676 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3677 if(file == INVALID_HANDLE_VALUE)
3680 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3681 ok(read != 0, "could not read file\n");
3682 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3685 DeleteFile("test.xml");
3688 static void test_testTransforms(void)
3690 IXMLDOMDocument *doc = NULL;
3691 IXMLDOMDocument *docSS = NULL;
3697 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3701 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3704 IXMLDOMDocument_Release(doc);
3708 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3709 ok(hr == S_OK, "ret %08x\n", hr );
3711 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3712 ok(hr == S_OK, "ret %08x\n", hr );
3714 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3715 ok(hr == S_OK, "ret %08x\n", hr );
3720 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3721 ok(hr == S_OK, "ret %08x\n", hr );
3722 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3723 SysFreeString(bOut);
3725 IXMLDOMNode_Release(pNode);
3728 IXMLDOMDocument_Release(docSS);
3729 IXMLDOMDocument_Release(doc);
3734 static void test_Namespaces(void)
3736 IXMLDOMDocument2 *doc = NULL;
3738 IXMLDOMNode *pNode2 = NULL;
3742 static const CHAR szNamespacesXML[] =
3743 "<?xml version=\"1.0\"?>\n"
3744 "<root xmlns:WEB='http://www.winehq.org'>\n"
3745 "<WEB:Site version=\"1.0\" />\n"
3748 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3752 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3753 ok(hr == S_OK, "ret %08x\n", hr );
3754 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3756 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3757 ok(hr == S_OK, "ret %08x\n", hr );
3760 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3761 ok( hr == S_OK, "ret %08x\n", hr );
3762 ok( pNode2 != NULL, "pNode2 == NULL\n");
3764 /* Test get_prefix */
3765 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3766 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3767 /* NOTE: Need to test that arg2 gets cleared on Error. */
3769 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3770 ok( hr == S_OK, "ret %08x\n", hr );
3771 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3774 /* Test get_namespaceURI */
3775 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3776 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3777 /* NOTE: Need to test that arg2 gets cleared on Error. */
3779 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3780 ok( hr == S_OK, "ret %08x\n", hr );
3781 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3784 IXMLDOMNode_Release(pNode2);
3785 IXMLDOMNode_Release(pNode);
3788 IXMLDOMDocument2_Release(doc);
3793 static void test_FormattingXML(void)
3795 IXMLDOMDocument2 *doc = NULL;
3796 IXMLDOMElement *pElement;
3800 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
3801 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
3803 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3807 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
3808 ok(hr == S_OK, "ret %08x\n", hr );
3809 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3811 if(bSucc == VARIANT_TRUE)
3813 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
3814 ok(hr == S_OK, "ret %08x\n", hr );
3817 hr = IXMLDOMElement_get_xml(pElement, &str);
3818 ok(hr == S_OK, "ret %08x\n", hr );
3819 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
3822 IXMLDOMElement_Release(pElement);
3826 IXMLDOMDocument2_Release(doc);
3831 static void test_NodeTypeValue(void)
3833 IXMLDOMDocument2 *doc = NULL;
3839 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3843 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
3844 ok(hr == S_OK, "ret %08x\n", hr );
3845 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3846 if(bSucc == VARIANT_TRUE)
3848 hr = IXMLDOMDocument2_get_nodeValue(doc, NULL);
3849 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3853 hr = IXMLDOMDocument2_get_nodeValue(doc, &v);
3854 ok(hr == S_FALSE, "ret %08x\n", hr );
3855 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
3857 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, NULL);
3858 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3860 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, &v);
3861 ok(hr == S_FALSE, "ret %08x\n", hr );
3863 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("string"), &pNode);
3864 ok(hr == S_OK, "ret %08x\n", hr );
3869 hr = IXMLDOMNode_get_nodeValue(pNode, &v);
3870 ok(hr == S_FALSE, "ret %08x\n", hr );
3871 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
3873 hr = IXMLDOMNode_get_nodeTypedValue(pNode, NULL);
3874 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3876 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
3877 ok(hr == S_OK, "ret %08x\n", hr );
3878 ok(!lstrcmpW( V_BSTR(&v), _bstr_("Wine") ), "incorrect value\n");
3881 IXMLDOMNode_Release(pNode);
3885 IXMLDOMDocument2_Release(doc);
3894 r = CoInitialize( NULL );
3895 ok( r == S_OK, "failed to init com\n");
3901 test_getElementsByTagName();
3903 test_get_childNodes();
3905 test_replaceChild();
3906 test_removeNamedItem();
3908 test_IXMLDOMDocument2();
3912 test_nodeTypeTests();
3913 test_DocumentSaveToDocument();
3914 test_DocumentSaveToFile();
3915 test_testTransforms();
3917 test_FormattingXML();
3918 test_NodeTypeValue();