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 WCHAR szNonExistentFile[] = {
150 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
152 static const WCHAR szDocument[] = {
153 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
156 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
157 static WCHAR szdl[] = { 'd','l',0 };
158 static const WCHAR szvr[] = { 'v','r',0 };
159 static const WCHAR szlc[] = { 'l','c',0 };
160 static WCHAR szbs[] = { 'b','s',0 };
161 static const WCHAR szstr1[] = { 's','t','r','1',0 };
162 static const WCHAR szstr2[] = { 's','t','r','2',0 };
163 static const WCHAR szstar[] = { '*',0 };
164 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
166 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
167 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
168 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
170 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
171 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
172 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
173 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
174 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
176 static WCHAR szAttribute[] = {'A','t','t','r',0 };
177 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
179 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
180 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
181 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
182 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
184 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
185 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
187 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
188 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
190 #define expect_bstr_eq_and_free(bstr, expect) { \
191 BSTR bstrExp = alloc_str_from_narrow(expect); \
192 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
193 SysFreeString(bstr); \
194 SysFreeString(bstrExp); \
197 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
199 #define ole_check(expr) { \
201 ok(r == S_OK, #expr " returned %x\n", r); \
204 #define ole_expect(expr, expect) { \
206 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
209 static BSTR alloc_str_from_narrow(const char *str)
211 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
212 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
213 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
217 BSTR alloced_bstrs[256];
218 int alloced_bstrs_count = 0;
220 static BSTR _bstr_(const char *str)
222 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
223 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
224 return alloced_bstrs[alloced_bstrs_count++];
227 static void free_bstrs(void)
230 for (i = 0; i < alloced_bstrs_count; i++)
231 SysFreeString(alloced_bstrs[i]);
232 alloced_bstrs_count = 0;
235 static VARIANT _variantbstr_(const char *str)
239 V_BSTR(&v) = _bstr_(str);
243 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
247 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
248 while (*sRight == '\r' || *sRight == '\n') sRight++;
249 if (*sLeft != *sRight) return FALSE;
250 if (!*sLeft) return TRUE;
256 static void get_str_for_type(DOMNodeType type, char *buf)
270 wsprintfA(buf, "[%d]", type);
274 static int get_node_position(IXMLDOMNode *node)
279 IXMLDOMNode_AddRef(node);
282 IXMLDOMNode *new_node;
285 r = IXMLDOMNode_get_previousSibling(node, &new_node);
286 ok(SUCCEEDED(r), "get_previousSibling failed\n");
287 IXMLDOMNode_Release(node);
293 static void node_to_string(IXMLDOMNode *node, char *buf)
300 lstrcpyA(buf, "(null)");
304 IXMLDOMNode_AddRef(node);
307 IXMLDOMNode *new_node;
309 ole_check(IXMLDOMNode_get_nodeType(node, &type));
310 get_str_for_type(type, buf);
313 if (type == NODE_ATTRIBUTE)
316 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
318 wsprintfA(buf, "%ws", bstr);
323 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
327 int pos = get_node_position(node);
328 DOMNodeType parent_type = NODE_INVALID;
329 r = IXMLDOMNode_get_parentNode(node, &new_node);
331 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
332 * results we "fix" it */
334 ole_check(IXMLDOMNode_get_nodeType(new_node, &parent_type));
335 if ((parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
337 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
340 wsprintf(buf, "%d", pos);
344 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
345 IXMLDOMNode_Release(node);
354 static char *list_to_string(IXMLDOMNodeList *list)
356 static char buf[4096];
363 lstrcpyA(buf, "(null)");
366 ole_check(IXMLDOMNodeList_get_length(list, &len));
367 for (i = 0; i < len; i++)
372 ole_check(IXMLDOMNodeList_nextNode(list, &node));
373 node_to_string(node, pos);
375 IXMLDOMNode_Release(node);
381 #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); }
382 #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); }
384 static void test_domdoc( void )
387 IXMLDOMDocument *doc = NULL;
388 IXMLDOMParseError *error;
389 IXMLDOMElement *element = NULL;
391 IXMLDOMText *nodetext = NULL;
392 IXMLDOMComment *node_comment = NULL;
393 IXMLDOMAttribute *node_attr = NULL;
394 IXMLDOMNode *nodeChild = NULL;
395 IXMLDOMProcessingInstruction *nodePI = NULL;
402 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
403 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
407 /* try some stupid things */
408 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
409 ok( r == S_FALSE, "loadXML failed\n");
412 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
413 ok( r == S_FALSE, "loadXML failed\n");
414 ok( b == VARIANT_FALSE, "failed to load XML string\n");
416 /* try to load a document from a nonexistent file */
418 str = SysAllocString( szNonExistentFile );
420 V_VT(&var) = VT_BSTR;
423 r = IXMLDOMDocument_load( doc, var, &b);
424 ok( r == S_FALSE, "load (from file) failed\n");
425 ok( b == VARIANT_FALSE, "failed to load XML file\n");
426 SysFreeString( str );
428 /* try load an empty document */
430 str = SysAllocString( szEmpty );
431 r = IXMLDOMDocument_loadXML( doc, str, &b );
432 ok( r == S_FALSE, "loadXML failed\n");
433 ok( b == VARIANT_FALSE, "failed to load XML string\n");
434 SysFreeString( str );
436 /* check that there's no document element */
438 r = IXMLDOMDocument_get_documentElement( doc, &element );
439 ok( r == S_FALSE, "should be no document element\n");
441 /* try finding a node */
443 str = SysAllocString( szstr1 );
444 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
445 ok( r == S_FALSE, "ret %08x\n", r );
446 SysFreeString( str );
449 str = SysAllocString( szIncomplete );
450 r = IXMLDOMDocument_loadXML( doc, str, &b );
451 ok( r == S_FALSE, "loadXML failed\n");
452 ok( b == VARIANT_FALSE, "failed to load XML string\n");
453 SysFreeString( str );
455 /* check that there's no document element */
456 element = (IXMLDOMElement*)1;
457 r = IXMLDOMDocument_get_documentElement( doc, &element );
458 ok( r == S_FALSE, "should be no document element\n");
459 ok( element == NULL, "Element should be NULL\n");
461 /* try to load something valid */
463 str = SysAllocString( szComplete1 );
464 r = IXMLDOMDocument_loadXML( doc, str, &b );
465 ok( r == S_OK, "loadXML failed\n");
466 ok( b == VARIANT_TRUE, "failed to load XML string\n");
467 SysFreeString( str );
469 /* check if nodename is correct */
470 r = IXMLDOMDocument_get_nodeName( doc, NULL );
471 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
473 /* content doesn't matter here */
475 r = IXMLDOMDocument_get_nodeName( doc, &str );
476 ok ( r == S_OK, "get_nodeName wrong code\n");
477 ok ( str != NULL, "str is null\n");
478 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
479 SysFreeString( str );
482 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
483 ok( r == E_FAIL, "ret %08x\n", r );
485 /* check that there's a document element */
487 r = IXMLDOMDocument_get_documentElement( doc, &element );
488 ok( r == S_OK, "should be a document element\n");
493 /* check if the tag is correct */
494 r = IXMLDOMElement_get_tagName( element, &tag );
495 ok( r == S_OK, "couldn't get tag name\n");
496 ok( tag != NULL, "tag was null\n");
497 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
498 SysFreeString( tag );
500 /* figure out what happens if we try to reload the document */
501 str = SysAllocString( szComplete2 );
502 r = IXMLDOMDocument_loadXML( doc, str, &b );
503 ok( r == S_OK, "loadXML failed\n");
504 ok( b == VARIANT_TRUE, "failed to load XML string\n");
505 SysFreeString( str );
507 /* check if the tag is still correct */
509 r = IXMLDOMElement_get_tagName( element, &tag );
510 ok( r == S_OK, "couldn't get tag name\n");
511 ok( tag != NULL, "tag was null\n");
512 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
513 SysFreeString( tag );
515 IXMLDOMElement_Release( element );
519 /* as soon as we call loadXML again, the document element will disappear */
521 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
522 ok( r == S_FALSE, "loadXML failed\n");
523 ok( b == 2, "variant modified\n");
524 r = IXMLDOMDocument_get_documentElement( doc, &element );
525 ok( r == S_FALSE, "should be no document element\n");
527 /* try to load something else simple and valid */
529 str = SysAllocString( szComplete3 );
530 r = IXMLDOMDocument_loadXML( doc, str, &b );
531 ok( r == S_OK, "loadXML failed\n");
532 ok( b == VARIANT_TRUE, "failed to load XML string\n");
533 SysFreeString( str );
535 /* try something a little more complicated */
537 str = SysAllocString( szComplete4 );
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 r = IXMLDOMDocument_get_parseError( doc, &error );
544 ok( r == S_OK, "returns %08x\n", r );
546 r = IXMLDOMParseError_get_errorCode( error, &code );
547 ok( r == S_FALSE, "returns %08x\n", r );
548 ok( code == 0, "code %ld\n", code );
549 IXMLDOMParseError_Release( error );
551 /* test createTextNode */
552 str = SysAllocString( szOpen );
553 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
554 ok( r == E_INVALIDARG, "returns %08x\n", r );
555 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
556 ok( r == S_OK, "returns %08x\n", r );
557 SysFreeString( str );
560 IXMLDOMNamedNodeMap *pAttribs;
562 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (LPVOID*)&element);
563 ok(r == E_NOINTERFACE, "ret %08x\n", r );
565 /* Text Last Child Checks */
566 r = IXMLDOMText_get_lastChild(nodetext, NULL);
567 ok(r == E_INVALIDARG, "ret %08x\n", r );
569 nodeChild = (IXMLDOMNode*)0x1;
570 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
571 ok(r == S_FALSE, "ret %08x\n", r );
572 ok(nodeChild == NULL, "nodeChild not NULL\n");
574 /* test get_attributes */
575 r = IXMLDOMText_get_attributes( nodetext, NULL );
576 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
578 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
579 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
580 ok(r == S_FALSE, "ret %08x\n", r );
581 ok( pAttribs == NULL, "pAttribs not NULL\n");
583 /* test get_dataType */
584 r = IXMLDOMText_get_dataType(nodetext, &var);
585 ok(r == S_FALSE, "ret %08x\n", r );
586 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
589 /* test length property */
590 r = IXMLDOMText_get_length(nodetext, NULL);
591 ok(r == E_INVALIDARG, "ret %08x\n", r );
593 r = IXMLDOMText_get_length(nodetext, &nLength);
594 ok(r == S_OK, "ret %08x\n", r );
595 ok(nLength == 4, "expected 4 got %ld\n", nLength);
597 /* test nodeTypeString */
598 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
599 ok(r == S_OK, "ret %08x\n", r );
600 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
604 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
605 ok(r == S_OK, "ret %08x\n", r );
608 r = IXMLDOMText_get_data(nodetext, &str);
609 ok(r == S_OK, "ret %08x\n", r );
610 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
613 /* Confirm XML text is good */
614 r = IXMLDOMText_get_xml(nodetext, &str);
615 ok(r == S_OK, "ret %08x\n", r );
616 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
619 /* Confirm we get the put_data Text back */
620 r = IXMLDOMText_get_text(nodetext, &str);
621 ok(r == S_OK, "ret %08x\n", r );
622 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
625 /* test substringData */
626 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
627 ok(r == E_INVALIDARG, "ret %08x\n", r );
629 /* test substringData - Invalid offset */
630 str = (BSTR)&szElement;
631 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
632 ok(r == E_INVALIDARG, "ret %08x\n", r );
633 ok( str == NULL, "incorrect string\n");
635 /* test substringData - Invalid offset */
636 str = (BSTR)&szElement;
637 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
638 ok(r == S_FALSE, "ret %08x\n", r );
639 ok( str == NULL, "incorrect string\n");
641 /* test substringData - Invalid size */
642 str = (BSTR)&szElement;
643 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
644 ok(r == E_INVALIDARG, "ret %08x\n", r );
645 ok( str == NULL, "incorrect string\n");
647 /* test substringData - Invalid size */
648 str = (BSTR)&szElement;
649 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
650 ok(r == S_FALSE, "ret %08x\n", r );
651 ok( str == NULL, "incorrect string\n");
653 /* test substringData - Start of string */
654 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
655 ok(r == S_OK, "ret %08x\n", r );
656 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
659 /* test substringData - Middle of string */
660 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
661 ok(r == S_OK, "ret %08x\n", r );
662 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
665 /* test substringData - End of string */
666 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
667 ok(r == S_OK, "ret %08x\n", r );
668 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
671 /* test appendData */
672 r = IXMLDOMText_appendData(nodetext, NULL);
673 ok(r == S_OK, "ret %08x\n", r );
675 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
676 ok(r == S_OK, "ret %08x\n", r );
678 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
679 ok(r == S_OK, "ret %08x\n", r );
681 r = IXMLDOMText_get_text(nodetext, &str);
682 ok(r == S_OK, "ret %08x\n", r );
683 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
686 /* test insertData */
687 str = SysAllocStringLen(NULL, 0);
688 r = IXMLDOMText_insertData(nodetext, -1, str);
689 ok(r == S_OK, "ret %08x\n", r );
691 r = IXMLDOMText_insertData(nodetext, -1, NULL);
692 ok(r == S_OK, "ret %08x\n", r );
694 r = IXMLDOMText_insertData(nodetext, 1000, str);
695 ok(r == S_OK, "ret %08x\n", r );
697 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
698 ok(r == S_OK, "ret %08x\n", r );
700 r = IXMLDOMText_insertData(nodetext, 0, NULL);
701 ok(r == S_OK, "ret %08x\n", r );
703 r = IXMLDOMText_insertData(nodetext, 0, str);
704 ok(r == S_OK, "ret %08x\n", r );
707 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
708 ok(r == E_INVALIDARG, "ret %08x\n", r );
710 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
711 ok(r == E_INVALIDARG, "ret %08x\n", r );
713 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
714 ok(r == S_OK, "ret %08x\n", r );
716 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
717 ok(r == S_OK, "ret %08x\n", r );
719 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
720 ok(r == S_OK, "ret %08x\n", r );
722 r = IXMLDOMText_get_text(nodetext, &str);
723 ok(r == S_OK, "ret %08x\n", r );
724 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
727 IXMLDOMText_Release( nodetext );
730 /* test Create Comment */
731 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
732 ok( r == E_INVALIDARG, "returns %08x\n", r );
733 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
734 ok( r == S_OK, "returns %08x\n", r );
737 /* Last Child Checks */
738 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
739 ok(r == E_INVALIDARG, "ret %08x\n", r );
741 nodeChild = (IXMLDOMNode*)0x1;
742 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
743 ok(r == S_FALSE, "ret %08x\n", r );
744 ok(nodeChild == NULL, "pLastChild not NULL\n");
746 IXMLDOMComment_Release( node_comment );
749 /* test Create Attribute */
750 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
751 ok( r == E_INVALIDARG, "returns %08x\n", r );
752 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
753 ok( r == S_OK, "returns %08x\n", r );
754 IXMLDOMText_Release( node_attr);
756 /* test Processing Instruction */
757 str = SysAllocStringLen(NULL, 0);
758 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
759 ok( r == E_INVALIDARG, "returns %08x\n", r );
760 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
761 ok( r == E_FAIL, "returns %08x\n", r );
762 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
763 ok( r == E_FAIL, "returns %08x\n", r );
766 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
767 ok( r == S_OK, "returns %08x\n", r );
770 /* Last Child Checks */
771 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
772 ok(r == E_INVALIDARG, "ret %08x\n", r );
774 nodeChild = (IXMLDOMNode*)0x1;
775 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
776 ok(r == S_FALSE, "ret %08x\n", r );
777 ok(nodeChild == NULL, "nodeChild not NULL\n");
779 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
780 ok(r == S_FALSE, "ret %08x\n", r );
781 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
785 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
786 ok(r == S_OK, "ret %08x\n", r );
787 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
791 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
792 ok(r == S_OK, "ret %08x\n", r );
793 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
796 /* test nodeTypeString */
797 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
798 ok(r == S_OK, "ret %08x\n", r );
799 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
802 /* test get_nodeValue */
803 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
804 ok(r == S_OK, "ret %08x\n", r );
805 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
809 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
810 ok(r == S_OK, "ret %08x\n", r );
811 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
815 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
816 ok(r == E_FAIL, "ret %08x\n", r );
819 V_VT(&var) = VT_BSTR;
820 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
821 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
822 ok(r == E_FAIL, "ret %08x\n", r );
825 /* test get nodeName */
826 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
827 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
828 ok(r == S_OK, "ret %08x\n", r );
831 IXMLDOMProcessingInstruction_Release(nodePI);
834 r = IXMLDOMDocument_Release( doc );
835 ok( r == 0, "document ref count incorrect\n");
840 static void test_domnode( void )
843 IXMLDOMDocument *doc = NULL, *owner = NULL;
844 IXMLDOMElement *element = NULL;
845 IXMLDOMNamedNodeMap *map = NULL;
846 IXMLDOMNode *node = NULL, *next = NULL;
847 IXMLDOMNodeList *list = NULL;
848 IXMLDOMAttribute *attr = NULL;
849 DOMNodeType type = NODE_INVALID;
855 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
856 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
861 str = SysAllocString( szComplete4 );
862 r = IXMLDOMDocument_loadXML( doc, str, &b );
863 ok( r == S_OK, "loadXML failed\n");
864 ok( b == VARIANT_TRUE, "failed to load XML string\n");
865 SysFreeString( str );
870 r = IXMLDOMNode_hasChildNodes( doc, &b );
871 ok( r == S_OK, "hasChildNoes bad return\n");
872 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
874 r = IXMLDOMDocument_get_documentElement( doc, &element );
875 ok( r == S_OK, "should be a document element\n");
876 ok( element != NULL, "should be an element\n");
879 ok( FALSE, "no document\n");
882 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
884 r = IXMLDOMNode_get_nodeValue( doc, NULL );
885 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
887 r = IXMLDOMNode_get_nodeValue( doc, &var );
888 ok( r == S_FALSE, "nextNode returned wrong code\n");
889 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
890 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
895 r = IXMLDOMNode_get_ownerDocument( element, &owner );
896 ok( r == S_OK, "get_ownerDocument return code\n");
897 ok( owner != doc, "get_ownerDocument return\n");
900 r = IXMLDOMNode_get_nodeType( element, &type);
901 ok( r == S_OK, "getNamedItem returned wrong code\n");
902 ok( type == NODE_ELEMENT, "node not an element\n");
905 r = IXMLDOMNode_get_baseName( element, &str );
906 ok( r == S_OK, "get_baseName returned wrong code\n");
907 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
910 /* check if nodename is correct */
911 r = IXMLDOMElement_get_nodeName( element, NULL );
912 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
914 /* content doesn't matter here */
916 r = IXMLDOMElement_get_nodeName( element, &str );
917 ok ( r == S_OK, "get_nodeName wrong code\n");
918 ok ( str != NULL, "str is null\n");
919 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
920 SysFreeString( str );
922 str = SysAllocString( szNonExistentFile );
925 r = IXMLDOMElement_getAttribute( element, str, &var );
926 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
927 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
930 attr = (IXMLDOMAttribute*)0xdeadbeef;
931 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
932 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
933 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
934 SysFreeString( str );
936 str = SysAllocString( szdl );
939 r = IXMLDOMElement_getAttribute( element, str, &var );
940 ok( r == S_OK, "getAttribute ret %08x\n", r );
941 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
942 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
943 VariantClear( &var );
945 r = IXMLDOMElement_getAttribute( element, NULL, &var );
946 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
948 r = IXMLDOMElement_getAttribute( element, str, NULL );
949 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
952 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
953 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
954 ok( attr != NULL, "getAttributeNode returned NULL\n" );
956 IXMLDOMAttribute_Release(attr);
958 SysFreeString( str );
960 r = IXMLDOMElement_get_attributes( element, &map );
961 ok( r == S_OK, "get_attributes returned wrong code\n");
962 ok( map != NULL, "should be attributes\n");
965 r = IXMLDOMNode_hasChildNodes( element, &b );
966 ok( r == S_OK, "hasChildNoes bad return\n");
967 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
970 ok( FALSE, "no element\n");
974 ISupportErrorInfo *support_error;
975 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
976 ok( r == S_OK, "ret %08x\n", r );
978 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
981 ok( r == S_OK, "ret %08x\n", r );
983 ISupportErrorInfo_Release( support_error );
985 str = SysAllocString( szdl );
986 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
987 ok( r == S_OK, "getNamedItem returned wrong code\n");
988 ok( node != NULL, "should be attributes\n");
989 IXMLDOMNode_Release(node);
990 SysFreeString( str );
992 str = SysAllocString( szdl );
993 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
994 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
995 SysFreeString( str );
997 /* something that isn't in szComplete4 */
998 str = SysAllocString( szOpen );
999 node = (IXMLDOMNode *) 1;
1000 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1001 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1002 ok( node == NULL, "getNamedItem should have returned NULL\n");
1003 SysFreeString( str );
1005 /* test indexed access of attributes */
1006 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1007 ok ( r == S_OK, "get_length wrong code\n");
1008 ok ( count == 1, "get_length != 1\n");
1011 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1012 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1013 ok ( node == NULL, "there is no node\n");
1016 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1017 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1018 ok ( node == NULL, "there is no attribute\n");
1021 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1022 ok ( r == S_OK, "get_item (0) wrong code\n");
1023 ok ( node != NULL, "should be attribute\n");
1025 r = IXMLDOMNode_get_nodeName( node, NULL );
1026 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1028 /* content doesn't matter here */
1030 r = IXMLDOMNode_get_nodeName( node, &str );
1031 ok ( r == S_OK, "get_nodeName wrong code\n");
1032 ok ( str != NULL, "str is null\n");
1033 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1034 SysFreeString( str );
1036 /* test sequential access of attributes */
1038 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1039 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1040 ok ( node != NULL, "nextNode, should be attribute\n");
1042 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1043 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1044 ok ( node == NULL, "nextNode, there is no attribute\n");
1046 r = IXMLDOMNamedNodeMap_reset( map );
1047 ok ( r == S_OK, "reset should return S_OK\n");
1049 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1050 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1051 ok ( node != NULL, "nextNode, should be attribute\n");
1054 ok( FALSE, "no map\n");
1058 type = NODE_INVALID;
1059 r = IXMLDOMNode_get_nodeType( node, &type);
1060 ok( r == S_OK, "getNamedItem returned wrong code\n");
1061 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1064 r = IXMLDOMNode_get_baseName( node, NULL );
1065 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1068 r = IXMLDOMNode_get_baseName( node, &str );
1069 ok( r == S_OK, "get_baseName returned wrong code\n");
1070 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1071 SysFreeString( str );
1073 r = IXMLDOMNode_get_nodeValue( node, &var );
1074 ok( r == S_OK, "returns %08x\n", r );
1075 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1076 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1079 r = IXMLDOMNode_get_childNodes( node, NULL );
1080 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1082 r = IXMLDOMNode_get_childNodes( node, &list );
1083 ok( r == S_OK, "get_childNodes returned wrong code\n");
1087 r = IXMLDOMNodeList_nextNode( list, &next );
1088 ok( r == S_OK, "nextNode returned wrong code\n");
1091 ok( FALSE, "no childlist\n");
1096 r = IXMLDOMNode_hasChildNodes( next, &b );
1097 ok( r == S_FALSE, "hasChildNoes bad return\n");
1098 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1100 type = NODE_INVALID;
1101 r = IXMLDOMNode_get_nodeType( next, &type);
1102 ok( r == S_OK, "getNamedItem returned wrong code\n");
1103 ok( type == NODE_TEXT, "node not text\n");
1106 r = IXMLDOMNode_get_baseName( next, &str );
1107 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1108 ok( str == NULL, "basename was wrong\n");
1112 ok( FALSE, "no next\n");
1115 IXMLDOMNode_Release( next );
1118 IXMLDOMNodeList_Release( list );
1121 IXMLDOMNode_Release( node );
1124 ok( FALSE, "no node\n");
1128 IXMLDOMNamedNodeMap_Release( map );
1130 /* now traverse the tree from the root element */
1134 r = IXMLDOMNode_get_childNodes( element, &list );
1135 ok( r == S_OK, "get_childNodes returned wrong code\n");
1137 /* using get_item for child list doesn't advance the position */
1138 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1139 expect_node(node, "E2.E2.D1");
1140 IXMLDOMNode_Release(node);
1141 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1142 expect_node(node, "E1.E2.D1");
1143 IXMLDOMNode_Release(node);
1144 ole_check(IXMLDOMNodeList_reset(list));
1146 IXMLDOMNodeList_AddRef(list);
1147 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1148 ole_check(IXMLDOMNodeList_reset(list));
1151 ok( FALSE, "no element\n");
1153 node = (void*)0xdeadbeef;
1154 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1155 ok( r == S_FALSE, "ret %08x\n", r );
1156 ok( node == NULL, "node %p\n", node );
1157 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1158 ok( r == S_OK, "ret %08x\n", r );
1159 r = IXMLDOMNode_Release( node );
1160 ok( r == 0, "ret %08x\n", r );
1164 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1165 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1167 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1168 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1170 r = IXMLDOMNodeList_get_length(list, NULL);
1171 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1173 r = IXMLDOMNodeList_get_length( list, &count );
1174 ok( r == S_OK, "get_length returns %08x\n", r );
1175 ok( count == 4, "get_length got %ld\n", count );
1177 r = IXMLDOMNodeList_nextNode(list, NULL);
1178 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1180 r = IXMLDOMNodeList_nextNode( list, &node );
1181 ok( r == S_OK, "nextNode returned wrong code\n");
1184 ok( FALSE, "no list\n");
1188 type = NODE_INVALID;
1189 r = IXMLDOMNode_get_nodeType( node, &type);
1190 ok( r == S_OK, "getNamedItem returned wrong code\n");
1191 ok( type == NODE_ELEMENT, "node not text\n");
1194 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1195 r = IXMLDOMNode_get_nodeValue( node, &var );
1196 ok( r == S_FALSE, "nextNode returned wrong code\n");
1197 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1198 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1200 r = IXMLDOMNode_hasChildNodes( node, NULL );
1201 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1204 r = IXMLDOMNode_hasChildNodes( node, &b );
1205 ok( r == S_OK, "hasChildNoes bad return\n");
1206 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1209 r = IXMLDOMNode_get_baseName( node, &str );
1210 ok( r == S_OK, "get_baseName returned wrong code\n");
1211 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1215 ok( FALSE, "no node\n");
1218 IXMLDOMNode_Release( node );
1220 IXMLDOMNodeList_Release( list );
1222 IXMLDOMElement_Release( element );
1225 str = SysAllocString( szComplete5 );
1226 r = IXMLDOMDocument_loadXML( doc, str, &b );
1227 ok( r == S_OK, "loadXML failed\n");
1228 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1229 SysFreeString( str );
1232 r = IXMLDOMNode_hasChildNodes( doc, &b );
1233 ok( r == S_OK, "hasChildNoes bad return\n");
1234 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1236 r = IXMLDOMDocument_get_documentElement( doc, &element );
1237 ok( r == S_OK, "should be a document element\n");
1238 ok( element != NULL, "should be an element\n");
1242 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1245 /* check if the tag is correct */
1246 r = IXMLDOMElement_get_tagName( element, &tag );
1247 ok( r == S_OK, "couldn't get tag name\n");
1248 ok( tag != NULL, "tag was null\n");
1249 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1250 SysFreeString( tag );
1254 IXMLDOMElement_Release( element );
1256 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1259 static void test_refs(void)
1264 IXMLDOMDocument *doc = NULL;
1265 IXMLDOMElement *element = NULL;
1266 IXMLDOMNode *node = NULL, *node2;
1267 IXMLDOMNodeList *node_list = NULL;
1269 IUnknown *unk, *unk2;
1271 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1272 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1275 ref = IXMLDOMDocument_Release(doc);
1276 ok( ref == 0, "ref %d\n", ref);
1278 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1279 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1283 str = SysAllocString( szComplete4 );
1284 r = IXMLDOMDocument_loadXML( doc, str, &b );
1285 ok( r == S_OK, "loadXML failed\n");
1286 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1287 SysFreeString( str );
1289 ref = IXMLDOMDocument_AddRef( doc );
1290 ok( ref == 2, "ref %d\n", ref );
1291 ref = IXMLDOMDocument_AddRef( doc );
1292 ok( ref == 3, "ref %d\n", ref );
1293 IXMLDOMDocument_Release( doc );
1294 IXMLDOMDocument_Release( doc );
1296 r = IXMLDOMDocument_get_documentElement( doc, &element );
1297 ok( r == S_OK, "should be a document element\n");
1298 ok( element != NULL, "should be an element\n");
1300 ref = IXMLDOMDocument_AddRef( doc );
1301 ok( ref == 2, "ref %d\n", ref );
1302 IXMLDOMDocument_Release( doc );
1304 r = IXMLDOMElement_get_childNodes( element, &node_list );
1305 ok( r == S_OK, "rets %08x\n", r);
1307 ref = IXMLDOMNodeList_AddRef( node_list );
1308 ok( ref == 2, "ref %d\n", ref );
1309 IXMLDOMNodeList_Release( node_list );
1311 IXMLDOMNodeList_get_item( node_list, 0, &node );
1312 ok( r == S_OK, "rets %08x\n", r);
1314 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1315 ok( r == S_OK, "rets %08x\n", r);
1317 ref = IXMLDOMNode_AddRef( node );
1318 ok( ref == 2, "ref %d\n", ref );
1319 IXMLDOMNode_Release( node );
1321 ref = IXMLDOMNode_Release( node );
1322 ok( ref == 0, "ref %d\n", ref );
1323 ref = IXMLDOMNode_Release( node2 );
1324 ok( ref == 0, "ref %d\n", ref );
1326 ref = IXMLDOMNodeList_Release( node_list );
1327 ok( ref == 0, "ref %d\n", ref );
1329 ok( node != node2, "node %p node2 %p\n", node, node2 );
1331 ref = IXMLDOMDocument_Release( doc );
1332 ok( ref == 0, "ref %d\n", ref );
1334 ref = IXMLDOMElement_AddRef( element );
1336 ok( ref == 3, "ref %d\n", ref );
1338 IXMLDOMElement_Release( element );
1340 /* IUnknown must be unique however we obtain it */
1341 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1342 ok( r == S_OK, "rets %08x\n", r );
1343 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1344 ok( r == S_OK, "rets %08x\n", r );
1345 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1346 ok( r == S_OK, "rets %08x\n", r );
1347 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1349 IUnknown_Release( unk2 );
1350 IUnknown_Release( unk );
1351 IXMLDOMNode_Release( node );
1353 IXMLDOMElement_Release( element );
1357 static void test_create(void)
1359 static const WCHAR szOne[] = {'1',0};
1360 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1364 IXMLDOMDocument *doc;
1365 IXMLDOMElement *element;
1366 IXMLDOMNode *root, *node, *child;
1367 IXMLDOMNamedNodeMap *attr_map;
1372 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1373 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1378 V_I1(&var) = NODE_ELEMENT;
1379 str = SysAllocString( szlc );
1380 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1381 ok( r == S_OK, "returns %08x\n", r );
1382 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1385 V_R4(&var) = NODE_ELEMENT;
1386 str = SysAllocString( szlc );
1387 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1388 ok( r == S_OK, "returns %08x\n", r );
1389 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1391 V_VT(&var) = VT_BSTR;
1392 V_BSTR(&var) = SysAllocString( szOne );
1393 str = SysAllocString( szlc );
1394 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1395 ok( r == S_OK, "returns %08x\n", r );
1396 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1399 V_VT(&var) = VT_BSTR;
1400 V_BSTR(&var) = SysAllocString( szOneGarbage );
1401 str = SysAllocString( szlc );
1402 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1403 ok( r == E_INVALIDARG, "returns %08x\n", r );
1404 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1408 V_I4(&var) = NODE_ELEMENT;
1409 str = SysAllocString( szlc );
1410 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1411 ok( r == S_OK, "returns %08x\n", r );
1412 r = IXMLDOMDocument_appendChild( doc, node, &root );
1413 ok( r == S_OK, "returns %08x\n", r );
1414 ok( node == root, "%p %p\n", node, root );
1416 ref = IXMLDOMNode_AddRef( node );
1417 ok(ref == 3, "ref %d\n", ref);
1418 IXMLDOMNode_Release( node );
1420 ref = IXMLDOMNode_Release( node );
1421 ok(ref == 1, "ref %d\n", ref);
1422 SysFreeString( str );
1425 V_I4(&var) = NODE_ELEMENT;
1426 str = SysAllocString( szbs );
1427 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1428 ok( r == S_OK, "returns %08x\n", r );
1430 ref = IXMLDOMNode_AddRef( node );
1431 ok(ref == 2, "ref = %d\n", ref);
1432 IXMLDOMNode_Release( node );
1434 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1435 ok( r == S_OK, "returns %08x\n", r );
1437 ref = IXMLDOMNode_AddRef( unk );
1438 ok(ref == 3, "ref = %d\n", ref);
1439 IXMLDOMNode_Release( unk );
1441 V_VT(&var) = VT_EMPTY;
1442 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1443 ok( r == S_OK, "returns %08x\n", r );
1444 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1445 IXMLDOMNode_Release( child );
1446 IUnknown_Release( unk );
1449 V_VT(&var) = VT_NULL;
1450 V_DISPATCH(&var) = (IDispatch*)node;
1451 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1452 ok( r == S_OK, "returns %08x\n", r );
1453 ok( node == child, "%p %p\n", node, child );
1454 IXMLDOMNode_Release( child );
1457 V_VT(&var) = VT_NULL;
1458 V_DISPATCH(&var) = (IDispatch*)node;
1459 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1460 ok( r == S_OK, "returns %08x\n", r );
1461 IXMLDOMNode_Release( node );
1463 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1464 ok( r == S_OK, "returns %08x\n", r );
1466 r = IXMLDOMElement_get_attributes( element, &attr_map );
1467 ok( r == S_OK, "returns %08x\n", r );
1468 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1469 ok( r == S_OK, "returns %08x\n", r );
1470 ok( num == 0, "num %ld\n", num );
1471 IXMLDOMNamedNodeMap_Release( attr_map );
1473 V_VT(&var) = VT_BSTR;
1474 V_BSTR(&var) = SysAllocString( szstr1 );
1475 name = SysAllocString( szdl );
1476 r = IXMLDOMElement_setAttribute( element, name, var );
1477 ok( r == S_OK, "returns %08x\n", r );
1478 r = IXMLDOMElement_get_attributes( element, &attr_map );
1479 ok( r == S_OK, "returns %08x\n", r );
1480 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1481 ok( r == S_OK, "returns %08x\n", r );
1482 ok( num == 1, "num %ld\n", num );
1483 IXMLDOMNamedNodeMap_Release( attr_map );
1486 V_VT(&var) = VT_BSTR;
1487 V_BSTR(&var) = SysAllocString( szstr2 );
1488 r = IXMLDOMElement_setAttribute( element, name, var );
1489 ok( r == S_OK, "returns %08x\n", r );
1490 r = IXMLDOMElement_get_attributes( element, &attr_map );
1491 ok( r == S_OK, "returns %08x\n", r );
1492 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1493 ok( r == S_OK, "returns %08x\n", r );
1494 ok( num == 1, "num %ld\n", num );
1495 IXMLDOMNamedNodeMap_Release( attr_map );
1497 r = IXMLDOMElement_getAttribute( element, name, &var );
1498 ok( r == S_OK, "returns %08x\n", r );
1499 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1501 SysFreeString(name);
1503 V_VT(&var) = VT_BSTR;
1504 V_BSTR(&var) = SysAllocString( szstr1 );
1505 name = SysAllocString( szlc );
1506 r = IXMLDOMElement_setAttribute( element, name, var );
1507 ok( r == S_OK, "returns %08x\n", r );
1508 r = IXMLDOMElement_get_attributes( element, &attr_map );
1509 ok( r == S_OK, "returns %08x\n", r );
1510 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1511 ok( r == S_OK, "returns %08x\n", r );
1512 ok( num == 2, "num %ld\n", num );
1513 IXMLDOMNamedNodeMap_Release( attr_map );
1515 SysFreeString(name);
1519 name = SysAllocString( szbs );
1520 r = IXMLDOMElement_setAttribute( element, name, var );
1521 ok( r == S_OK, "returns %08x\n", r );
1523 r = IXMLDOMElement_getAttribute( element, name, &var );
1524 ok( r == S_OK, "returns %08x\n", r );
1525 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1527 SysFreeString(name);
1529 /* Create an Attribute */
1531 V_I4(&var) = NODE_ATTRIBUTE;
1532 str = SysAllocString( szAttribute );
1533 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1534 ok( r == S_OK, "returns %08x\n", r );
1535 ok( node != NULL, "node was null\n");
1540 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1541 ok( r == S_OK, "returns %08x\n", r );
1542 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1544 IXMLDOMNode_Release( node );
1547 IXMLDOMElement_Release( element );
1548 IXMLDOMNode_Release( root );
1549 IXMLDOMDocument_Release( doc );
1552 static void test_getElementsByTagName(void)
1557 IXMLDOMDocument *doc;
1558 IXMLDOMNodeList *node_list;
1559 IDispatchEx *dispex;
1562 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1563 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1567 str = SysAllocString( szComplete4 );
1568 r = IXMLDOMDocument_loadXML( doc, str, &b );
1569 ok( r == S_OK, "loadXML failed\n");
1570 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1571 SysFreeString( str );
1573 str = SysAllocString( szstar );
1574 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1575 ok( r == S_OK, "ret %08x\n", r );
1576 r = IXMLDOMNodeList_get_length( node_list, &len );
1577 ok( r == S_OK, "ret %08x\n", r );
1578 ok( len == 6, "len %ld\n", len );
1580 r = IXMLDOMNodeList_QueryInterface( node_list, &IID_IDispatchEx, (void**)&dispex );
1581 ok( r == S_OK, "rets %08x\n", r);
1584 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
1589 sName = SysAllocString( szstar );
1590 r = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
1591 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1592 SysFreeString( sName );
1594 r = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
1595 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1597 r = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
1598 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1599 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
1601 r = IDispatchEx_GetMemberName(dispex, dispid, &sName);
1602 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1604 SysFreeString(sName);
1606 r = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
1607 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1609 r = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
1610 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1612 IUnknown_Release(pUnk);
1614 IDispatchEx_Release( dispex );
1618 IXMLDOMNodeList_Release( node_list );
1619 SysFreeString( str );
1621 str = SysAllocString( szbs );
1622 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1623 ok( r == S_OK, "ret %08x\n", r );
1624 r = IXMLDOMNodeList_get_length( node_list, &len );
1625 ok( r == S_OK, "ret %08x\n", r );
1626 ok( len == 1, "len %ld\n", len );
1627 IXMLDOMNodeList_Release( node_list );
1628 SysFreeString( str );
1630 str = SysAllocString( szdl );
1631 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1632 ok( r == S_OK, "ret %08x\n", r );
1633 r = IXMLDOMNodeList_get_length( node_list, &len );
1634 ok( r == S_OK, "ret %08x\n", r );
1635 ok( len == 0, "len %ld\n", len );
1636 IXMLDOMNodeList_Release( node_list );
1637 SysFreeString( str );
1639 str = SysAllocString( szstr1 );
1640 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1641 ok( r == S_OK, "ret %08x\n", r );
1642 r = IXMLDOMNodeList_get_length( node_list, &len );
1643 ok( r == S_OK, "ret %08x\n", r );
1644 ok( len == 0, "len %ld\n", len );
1645 IXMLDOMNodeList_Release( node_list );
1646 SysFreeString( str );
1648 IXMLDOMDocument_Release( doc );
1651 static void test_get_text(void)
1656 IXMLDOMDocument *doc;
1657 IXMLDOMNode *node, *node2, *node3;
1658 IXMLDOMNodeList *node_list;
1659 IXMLDOMNamedNodeMap *node_map;
1662 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1663 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1667 str = SysAllocString( szComplete4 );
1668 r = IXMLDOMDocument_loadXML( doc, str, &b );
1669 ok( r == S_OK, "loadXML failed\n");
1670 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1671 SysFreeString( str );
1673 str = SysAllocString( szbs );
1674 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1675 ok( r == S_OK, "ret %08x\n", r );
1679 /* this test crashes on win9x */
1680 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1681 ok( r == E_INVALIDARG, "ret %08x\n", r );
1684 r = IXMLDOMNodeList_get_length( node_list, NULL );
1685 ok( r == E_INVALIDARG, "ret %08x\n", r );
1687 r = IXMLDOMNodeList_get_length( node_list, &len );
1688 ok( r == S_OK, "ret %08x\n", r );
1689 ok( len == 1, "expect 1 got %ld\n", len );
1691 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1692 ok( r == E_INVALIDARG, "ret %08x\n", r );
1694 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1695 ok( r == E_INVALIDARG, "ret %08x\n", r );
1697 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1698 ok( r == S_OK, "ret %08x\n", r );
1699 IXMLDOMNodeList_Release( node_list );
1701 /* Invalid output parameter*/
1702 r = IXMLDOMNode_get_text( node, NULL );
1703 ok( r == E_INVALIDARG, "ret %08x\n", r );
1705 r = IXMLDOMNode_get_text( node, &str );
1706 ok( r == S_OK, "ret %08x\n", r );
1707 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1710 r = IXMLDOMNode_get_attributes( node, &node_map );
1711 ok( r == S_OK, "ret %08x\n", r );
1713 str = SysAllocString( szvr );
1714 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1715 ok( r == S_OK, "ret %08x\n", r );
1718 r = IXMLDOMNode_get_text( node2, &str );
1719 ok( r == S_OK, "ret %08x\n", r );
1720 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1723 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1724 ok( r == S_OK, "ret %08x\n", r );
1726 r = IXMLDOMNode_get_text( node3, &str );
1727 ok( r == S_OK, "ret %08x\n", r );
1728 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1732 IXMLDOMNode_Release( node3 );
1733 IXMLDOMNode_Release( node2 );
1734 IXMLDOMNamedNodeMap_Release( node_map );
1735 IXMLDOMNode_Release( node );
1736 IXMLDOMDocument_Release( doc );
1739 static void test_get_childNodes(void)
1744 IXMLDOMDocument *doc;
1745 IXMLDOMElement *element;
1746 IXMLDOMNode *node, *node2;
1747 IXMLDOMNodeList *node_list, *node_list2;
1750 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1751 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1755 str = SysAllocString( szComplete4 );
1756 r = IXMLDOMDocument_loadXML( doc, str, &b );
1757 ok( r == S_OK, "loadXML failed\n");
1758 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1759 SysFreeString( str );
1761 r = IXMLDOMDocument_get_documentElement( doc, &element );
1762 ok( r == S_OK, "ret %08x\n", r);
1764 r = IXMLDOMElement_get_childNodes( element, &node_list );
1765 ok( r == S_OK, "ret %08x\n", r);
1767 r = IXMLDOMNodeList_get_length( node_list, &len );
1768 ok( r == S_OK, "ret %08x\n", r);
1769 ok( len == 4, "len %ld\n", len);
1771 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1772 ok( r == S_OK, "ret %08x\n", r);
1774 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1775 ok( r == S_OK, "ret %08x\n", r);
1777 r = IXMLDOMNodeList_get_length( node_list2, &len );
1778 ok( r == S_OK, "ret %08x\n", r);
1779 ok( len == 0, "len %ld\n", len);
1781 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1782 ok( r == S_FALSE, "ret %08x\n", r);
1784 IXMLDOMNodeList_Release( node_list2 );
1785 IXMLDOMNode_Release( node );
1786 IXMLDOMNodeList_Release( node_list );
1787 IXMLDOMElement_Release( element );
1788 IXMLDOMDocument_Release( doc );
1791 static void test_removeChild(void)
1796 IXMLDOMDocument *doc;
1797 IXMLDOMElement *element, *lc_element;
1798 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
1799 IXMLDOMNodeList *root_list, *fo_list;
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, &root_list );
1816 ok( r == S_OK, "ret %08x\n", r);
1818 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1819 ok( r == S_OK, "ret %08x\n", r);
1821 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1822 ok( r == S_OK, "ret %08x\n", r);
1824 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1825 ok( r == S_OK, "ret %08x\n", r);
1827 /* invalid parameter: NULL ptr */
1828 removed_node = (void*)0xdeadbeef;
1829 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
1830 ok( r == E_INVALIDARG, "ret %08x\n", r );
1831 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1833 /* ba_node is a descendant of element, but not a direct child. */
1834 removed_node = (void*)0xdeadbeef;
1835 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
1836 ok( r == E_INVALIDARG, "ret %08x\n", r );
1837 ok( removed_node == NULL, "%p\n", removed_node );
1839 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
1840 ok( r == S_OK, "ret %08x\n", r);
1841 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
1843 /* try removing already removed child */
1844 temp_node = (void*)0xdeadbeef;
1845 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
1846 ok( r == E_INVALIDARG, "ret %08x\n", r);
1847 ok( temp_node == NULL, "%p\n", temp_node );
1849 /* the removed node has no parent anymore */
1850 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
1851 ok( r == S_FALSE, "ret %08x\n", r);
1852 ok( temp_node == NULL, "%p\n", temp_node );
1854 IXMLDOMNode_Release( removed_node );
1855 IXMLDOMNode_Release( ba_node );
1856 IXMLDOMNodeList_Release( fo_list );
1858 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
1859 ok( r == S_OK, "ret %08x\n", r);
1861 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (LPVOID*)&lc_element );
1862 ok( r == S_OK, "ret %08x\n", r);
1864 /* MS quirk: passing wrong interface pointer works, too */
1865 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
1866 ok( r == S_OK, "ret %08x\n", r);
1868 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
1869 ok( r == S_FALSE, "ret %08x\n", r);
1870 ok( temp_node == NULL, "%p\n", temp_node );
1872 IXMLDOMNode_Release( lc_node );
1873 IXMLDOMNodeList_Release( root_list );
1874 IXMLDOMElement_Release( element );
1875 IXMLDOMDocument_Release( doc );
1878 static void test_replaceChild(void)
1883 IXMLDOMDocument *doc;
1884 IXMLDOMElement *element, *ba_element;
1885 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
1886 IXMLDOMNodeList *root_list, *fo_list;
1887 IUnknown * unk1, *unk2;
1890 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1891 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1895 str = SysAllocString( szComplete4 );
1896 r = IXMLDOMDocument_loadXML( doc, str, &b );
1897 ok( r == S_OK, "loadXML failed\n");
1898 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1899 SysFreeString( str );
1901 r = IXMLDOMDocument_get_documentElement( doc, &element );
1902 ok( r == S_OK, "ret %08x\n", r);
1904 r = IXMLDOMElement_get_childNodes( element, &root_list );
1905 ok( r == S_OK, "ret %08x\n", r);
1907 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
1908 ok( r == S_OK, "ret %08x\n", r);
1910 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1911 ok( r == S_OK, "ret %08x\n", r);
1913 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1914 ok( r == S_OK, "ret %08x\n", r);
1916 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1917 ok( r == S_OK, "ret %08x\n", r);
1919 IXMLDOMNodeList_Release( fo_list );
1921 /* invalid parameter: NULL ptr for element to remove */
1922 removed_node = (void*)0xdeadbeef;
1923 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
1924 ok( r == E_INVALIDARG, "ret %08x\n", r );
1925 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1927 /* invalid parameter: NULL for replacement element. (Sic!) */
1928 removed_node = (void*)0xdeadbeef;
1929 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
1930 ok( r == E_INVALIDARG, "ret %08x\n", r );
1931 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1933 /* invalid parameter: OldNode is not a child */
1934 removed_node = (void*)0xdeadbeef;
1935 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
1936 ok( r == E_INVALIDARG, "ret %08x\n", r );
1937 ok( removed_node == NULL, "%p\n", removed_node );
1939 /* invalid parameter: would create loop */
1940 removed_node = (void*)0xdeadbeef;
1941 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
1942 ok( r == E_FAIL, "ret %08x\n", r );
1943 ok( removed_node == NULL, "%p\n", removed_node );
1945 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
1946 ok( r == S_OK, "ret %08x\n", r );
1948 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
1949 ok( r == S_OK, "ret %08x\n", r );
1951 /* ba_node and temp_node refer to the same node, yet they
1952 are different interface pointers */
1953 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
1954 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
1955 ok( r == S_OK, "ret %08x\n", r );
1956 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
1957 ok( r == S_OK, "ret %08x\n", r );
1958 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
1960 IUnknown_Release( unk1 );
1961 IUnknown_Release( unk2 );
1963 /* ba_node should have been removed from below fo_node */
1964 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1965 ok( r == S_OK, "ret %08x\n", r );
1967 /* MS quirk: replaceChild also accepts elements instead of nodes */
1968 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
1969 ok( r == S_OK, "ret %08x\n", r );
1971 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
1972 ok( r == S_OK, "ret %08x\n", r );
1974 r = IXMLDOMNodeList_get_length( fo_list, &len);
1975 ok( r == S_OK, "ret %08x\n", r );
1976 ok( len == 0, "len %ld\n", len);
1978 IXMLDOMNodeList_Release( fo_list );
1980 IXMLDOMNode_Release(ba_node);
1981 IXMLDOMNode_Release(fo_node);
1982 IXMLDOMNode_Release(temp_node);
1983 IXMLDOMNodeList_Release( root_list );
1984 IXMLDOMElement_Release( element );
1985 IXMLDOMDocument_Release( doc );
1988 static void test_removeNamedItem(void)
1990 IXMLDOMDocument *doc;
1991 IXMLDOMElement *element;
1992 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
1993 IXMLDOMNodeList *root_list;
1994 IXMLDOMNamedNodeMap * pr_attrs;
2000 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2001 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2005 str = SysAllocString( szComplete4 );
2006 r = IXMLDOMDocument_loadXML( doc, str, &b );
2007 ok( r == S_OK, "loadXML failed\n");
2008 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2009 SysFreeString( str );
2011 r = IXMLDOMDocument_get_documentElement( doc, &element );
2012 ok( r == S_OK, "ret %08x\n", r);
2014 r = IXMLDOMElement_get_childNodes( element, &root_list );
2015 ok( r == S_OK, "ret %08x\n", r);
2017 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2018 ok( r == S_OK, "ret %08x\n", r);
2020 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2021 ok( r == S_OK, "ret %08x\n", r);
2023 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2024 ok( r == S_OK, "ret %08x\n", r);
2025 ok( len == 3, "length %ld\n", len);
2027 removed_node = (void*)0xdeadbeef;
2028 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2029 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2030 ok ( removed_node == (void*)0xdeadbeef, "removed_node == %p\n", removed_node);
2032 removed_node = (void*)0xdeadbeef;
2033 str = SysAllocString(szvr);
2034 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2035 ok ( r == S_OK, "ret %08x\n", r);
2037 removed_node2 = (void*)0xdeadbeef;
2038 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2039 ok ( r == S_FALSE, "ret %08x\n", r);
2040 ok ( removed_node2 == NULL, "removed_node == %p\n", removed_node2 );
2042 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2043 ok( r == S_OK, "ret %08x\n", r);
2044 ok( len == 2, "length %ld\n", len);
2046 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2047 ok ( r == S_OK, "ret %08x\n", r);
2048 IXMLDOMNode_Release(removed_node);
2050 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2051 ok( r == S_OK, "ret %08x\n", r);
2052 ok( len == 3, "length %ld\n", len);
2054 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2055 ok ( r == S_OK, "ret %08x\n", r);
2057 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2058 ok( r == S_OK, "ret %08x\n", r);
2059 ok( len == 2, "length %ld\n", len);
2061 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2062 ok ( r == S_FALSE, "ret %08x\n", r);
2066 IXMLDOMNamedNodeMap_Release( pr_attrs );
2067 IXMLDOMNode_Release( pr_node );
2068 IXMLDOMNodeList_Release( root_list );
2069 IXMLDOMElement_Release( element );
2070 IXMLDOMDocument_Release( doc );
2073 static void test_XMLHTTP(void)
2075 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2076 static WCHAR wszPOST[] = {'P','O','S','T',0};
2077 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2078 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2079 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2080 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2081 IXMLHttpRequest *pXMLHttpRequest;
2086 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2087 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2088 (void **)&pXMLHttpRequest);
2089 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
2093 VariantInit(&dummy);
2094 V_VT(&dummy) = VT_ERROR;
2095 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2096 VariantInit(&varfalse);
2097 V_VT(&varfalse) = VT_BOOL;
2098 V_BOOL(&varfalse) = VARIANT_FALSE;
2099 V_VT(&varbody) = VT_BSTR;
2100 V_BSTR(&varbody) = SysAllocString(wszBody);
2102 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
2103 todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
2105 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2106 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2107 VariantClear(&varbody);
2109 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2110 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2111 /* the server currently returns "FAILED" because the Content-Type header is
2112 * not what the server expects */
2115 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2116 SysFreeString(bstrResponse);
2120 static void test_IXMLDOMDocument2(void)
2125 IXMLDOMDocument *doc;
2126 IXMLDOMDocument2 *doc2;
2127 IDispatchEx *dispex;
2131 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2132 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2136 str = SysAllocString( szComplete4 );
2137 r = IXMLDOMDocument_loadXML( doc, str, &b );
2138 ok( r == S_OK, "loadXML failed\n");
2139 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2140 SysFreeString( str );
2142 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
2143 ok( r == S_OK, "ret %08x\n", r );
2144 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
2146 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
2147 ok( r == S_OK, "ret %08x\n", r );
2150 IDispatchEx_Release(dispex);
2153 /* we will check if the variant got cleared */
2154 ref = IXMLDOMDocument2_AddRef(doc2);
2155 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
2156 V_VT(&var) = VT_UNKNOWN;
2157 V_UNKNOWN(&var) = (IUnknown *)doc2;
2160 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
2161 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
2162 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
2165 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2166 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2167 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2170 /* the variant didn't get cleared*/
2171 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
2173 /* setProperty tests */
2174 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
2175 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
2176 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
2177 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2178 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2179 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2181 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
2182 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2183 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2184 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2186 IXMLDOMDocument2_Release( doc2 );
2187 IXMLDOMDocument_Release( doc );
2191 static void test_XPath(void)
2196 IXMLDOMDocument2 *doc;
2197 IXMLDOMNode *rootNode;
2198 IXMLDOMNode *elem1Node;
2200 IXMLDOMNodeList *list;
2202 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2203 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2207 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
2208 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2210 /* switch to XPath */
2211 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2213 /* some simple queries*/
2214 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
2215 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
2216 ole_check(IXMLDOMNodeList_reset(list));
2217 expect_list_and_release(list, "E2.D1");
2218 if (rootNode == NULL)
2221 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
2222 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
2224 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
2225 expect_list_and_release(list, "E3.E2.E2.D1");
2227 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
2228 /* using get_item for query results advances the position */
2229 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2230 expect_node(node, "E2.E2.D1");
2231 IXMLDOMNode_Release(node);
2232 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2233 expect_node(node, "E4.E2.D1");
2234 IXMLDOMNode_Release(node);
2235 ole_check(IXMLDOMNodeList_reset(list));
2236 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2238 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2239 expect_list_and_release(list, "E2.D1");
2241 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2242 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2243 ole_check(IXMLDOMNodeList_reset(list));
2244 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2246 /* select an attribute */
2247 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2248 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2250 /* would evaluate to a number */
2251 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2252 /* would evaluate to a boolean */
2253 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2254 /* would evaluate to a string */
2255 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2258 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2259 expect_list_and_release(list, "");
2260 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2261 expect_list_and_release(list, "");
2262 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2263 expect_list_and_release(list, "");
2265 /* foo undeclared in document node */
2266 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2267 /* undeclared in <root> node */
2268 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2269 /* undeclared in <elem> node */
2270 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2271 /* but this trick can be used */
2272 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2273 expect_list_and_release(list, "E3.E4.E2.D1");
2275 /* it has to be declared in SelectionNamespaces */
2276 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2277 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2279 /* now the namespace can be used */
2280 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2281 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2282 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2283 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2284 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2285 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2286 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2287 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2289 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2290 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2291 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2293 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2296 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2297 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2298 if (V_VT(&var) == VT_BSTR)
2299 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2301 /* extra attributes - same thing*/
2302 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2303 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2304 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2306 IXMLDOMNode_Release(rootNode);
2307 IXMLDOMNode_Release(elem1Node);
2308 IXMLDOMDocument_Release(doc);
2312 static void test_cloneNode(void )
2314 IXMLDOMDocument *doc = NULL;
2316 IXMLDOMNodeList *pList;
2317 IXMLDOMNamedNodeMap *mapAttr;
2318 long nLength = 0, nLength1 = 0;
2319 long nAttrCnt = 0, nAttrCnt1 = 0;
2321 IXMLDOMNode *node_clone;
2324 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2326 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2330 str = SysAllocString( szComplete4 );
2331 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2332 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2338 str = SysAllocString( szSearch);
2339 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2340 ok( r == S_OK, "ret %08x\n", r );
2341 ok( node != NULL, "node %p\n", node );
2346 IXMLDOMDocument_Release(doc);
2350 /* Check invalid parameter */
2351 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2352 ok( r == E_INVALIDARG, "ret %08x\n", r );
2355 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2356 ok( r == S_OK, "ret %08x\n", r );
2357 ok( node_clone != NULL, "node %p\n", node );
2361 IXMLDOMDocument_Release(doc);
2362 IXMLDOMNode_Release(node);
2366 r = IXMLDOMNode_get_childNodes(node, &pList);
2367 ok( r == S_OK, "ret %08x\n", r );
2370 IXMLDOMNodeList_get_length(pList, &nLength);
2371 IXMLDOMNodeList_Release(pList);
2374 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2375 ok( r == S_OK, "ret %08x\n", r );
2378 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2379 IXMLDOMNamedNodeMap_Release(mapAttr);
2382 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2383 ok( r == S_OK, "ret %08x\n", r );
2386 IXMLDOMNodeList_get_length(pList, &nLength1);
2387 IXMLDOMNodeList_Release(pList);
2390 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2391 ok( r == S_OK, "ret %08x\n", r );
2394 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2395 IXMLDOMNamedNodeMap_Release(mapAttr);
2398 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2399 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2400 IXMLDOMNode_Release(node_clone);
2403 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2404 ok( r == S_OK, "ret %08x\n", r );
2405 ok( node_clone != NULL, "node %p\n", node );
2409 IXMLDOMDocument_Release(doc);
2410 IXMLDOMNode_Release(node);
2414 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2415 ok( r == S_OK, "ret %08x\n", r );
2418 IXMLDOMNodeList_get_length(pList, &nLength1);
2419 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
2420 IXMLDOMNodeList_Release(pList);
2423 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2424 ok( r == S_OK, "ret %08x\n", r );
2427 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2428 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
2429 IXMLDOMNamedNodeMap_Release(mapAttr);
2432 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2433 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2434 IXMLDOMNode_Release(node_clone);
2437 IXMLDOMNode_Release(node);
2438 IXMLDOMDocument_Release(doc);
2441 static void test_xmlTypes(void)
2443 IXMLDOMDocument *doc = NULL;
2444 IXMLDOMElement *pRoot;
2446 IXMLDOMComment *pComment;
2447 IXMLDOMElement *pElement;
2448 IXMLDOMAttribute *pAttrubute;
2449 IXMLDOMNamedNodeMap *pAttribs;
2450 IXMLDOMCDATASection *pCDataSec;
2451 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2452 IXMLDOMDocumentFragment *pDocFrag = NULL;
2453 IXMLDOMEntityReference *pEntityRef = NULL;
2455 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2459 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2463 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2464 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2466 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2467 ok(hr == S_FALSE, "ret %08x\n", hr );
2468 ok(pNextChild == NULL, "pDocChild not NULL\n");
2470 /* test previous Sibling */
2471 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2472 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2474 pNextChild = (IXMLDOMNode *)0x1;
2475 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2476 ok(hr == S_FALSE, "ret %08x\n", hr );
2477 ok(pNextChild == NULL, "pNextChild not NULL\n");
2479 /* test get_attributes */
2480 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2481 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2483 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2484 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2485 ok(hr == S_FALSE, "ret %08x\n", hr );
2486 ok( pAttribs == NULL, "pAttribs not NULL\n");
2488 /* test get_dataType */
2489 hr = IXMLDOMDocument_get_dataType(doc, &v);
2490 ok(hr == S_FALSE, "ret %08x\n", hr );
2491 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2494 /* test nodeTypeString */
2495 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2496 ok(hr == S_OK, "ret %08x\n", hr );
2497 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2500 /* test implementation */
2501 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2502 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2504 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2505 ok(hr == S_OK, "ret %08x\n", hr );
2508 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2509 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2511 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2512 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2514 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2515 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2517 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2518 ok(hr == S_OK, "ret %08x\n", hr );
2519 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2521 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2522 ok(hr == S_OK, "ret %08x\n", hr );
2523 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2525 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2526 ok(hr == S_OK, "ret %08x\n", hr );
2527 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2529 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2530 ok(hr == S_OK, "ret %08x\n", hr );
2531 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2533 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2534 ok(hr == S_OK, "ret %08x\n", hr );
2535 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2537 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2538 ok(hr == S_OK, "ret %08x\n", hr );
2539 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2541 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2542 ok(hr == S_OK, "ret %08x\n", hr );
2543 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2545 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2546 ok(hr == S_OK, "ret %08x\n", hr );
2547 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2549 SysFreeString(sEmpty);
2550 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2555 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2556 ok(hr == S_OK, "ret %08x\n", hr );
2559 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2560 ok(hr == S_OK, "ret %08x\n", hr );
2564 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2565 ok(hr == S_OK, "ret %08x\n", hr );
2568 /* test get_attributes */
2569 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2570 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2572 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2573 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2574 ok(hr == S_FALSE, "ret %08x\n", hr );
2575 ok( pAttribs == NULL, "pAttribs not NULL\n");
2577 /* test nodeTypeString */
2578 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2579 ok(hr == S_OK, "ret %08x\n", hr );
2580 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2583 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2584 ok(hr == S_OK, "ret %08x\n", hr );
2586 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2587 ok(hr == S_OK, "ret %08x\n", hr );
2588 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2591 hr = IXMLDOMComment_get_xml(pComment, &str);
2592 ok(hr == S_OK, "ret %08x\n", hr );
2593 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2596 hr = IXMLDOMComment_get_dataType(pComment, &v);
2597 ok(hr == S_FALSE, "ret %08x\n", hr );
2598 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2601 /* put data Tests */
2602 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2603 ok(hr == S_OK, "ret %08x\n", hr );
2605 /* get data Tests */
2606 hr = IXMLDOMComment_get_data(pComment, &str);
2607 ok(hr == S_OK, "ret %08x\n", hr );
2608 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2611 /* get data Tests */
2612 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2613 ok(hr == S_OK, "ret %08x\n", hr );
2614 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2615 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2618 /* Confirm XML text is good */
2619 hr = IXMLDOMComment_get_xml(pComment, &str);
2620 ok(hr == S_OK, "ret %08x\n", hr );
2621 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2624 /* Confirm we get the put_data Text back */
2625 hr = IXMLDOMComment_get_text(pComment, &str);
2626 ok(hr == S_OK, "ret %08x\n", hr );
2627 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2630 /* test length property */
2631 hr = IXMLDOMComment_get_length(pComment, &len);
2632 ok(hr == S_OK, "ret %08x\n", hr );
2633 ok(len == 21, "expected 21 got %ld\n", len);
2635 /* test substringData */
2636 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2637 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2639 /* test substringData - Invalid offset */
2640 str = (BSTR)&szElement;
2641 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2642 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2643 ok( str == NULL, "incorrect string\n");
2645 /* test substringData - Invalid offset */
2646 str = (BSTR)&szElement;
2647 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2648 ok(hr == S_FALSE, "ret %08x\n", hr );
2649 ok( str == NULL, "incorrect string\n");
2651 /* test substringData - Invalid size */
2652 str = (BSTR)&szElement;
2653 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2654 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2655 ok( str == NULL, "incorrect string\n");
2657 /* test substringData - Invalid size */
2658 str = (BSTR)&szElement;
2659 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2660 ok(hr == S_FALSE, "ret %08x\n", hr );
2661 ok( str == NULL, "incorrect string\n");
2663 /* test substringData - Start of string */
2664 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2665 ok(hr == S_OK, "ret %08x\n", hr );
2666 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2669 /* test substringData - Middle of string */
2670 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2671 ok(hr == S_OK, "ret %08x\n", hr );
2672 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2675 /* test substringData - End of string */
2676 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2677 ok(hr == S_OK, "ret %08x\n", hr );
2678 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2681 /* test appendData */
2682 hr = IXMLDOMComment_appendData(pComment, NULL);
2683 ok(hr == S_OK, "ret %08x\n", hr );
2685 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2686 ok(hr == S_OK, "ret %08x\n", hr );
2688 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2689 ok(hr == S_OK, "ret %08x\n", hr );
2691 hr = IXMLDOMComment_get_text(pComment, &str);
2692 ok(hr == S_OK, "ret %08x\n", hr );
2693 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2696 /* test insertData */
2697 str = SysAllocStringLen(NULL, 0);
2698 hr = IXMLDOMComment_insertData(pComment, -1, str);
2699 ok(hr == S_OK, "ret %08x\n", hr );
2701 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2702 ok(hr == S_OK, "ret %08x\n", hr );
2704 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2705 ok(hr == S_OK, "ret %08x\n", hr );
2707 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2708 ok(hr == S_OK, "ret %08x\n", hr );
2710 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2711 ok(hr == S_OK, "ret %08x\n", hr );
2713 hr = IXMLDOMComment_insertData(pComment, 0, str);
2714 ok(hr == S_OK, "ret %08x\n", hr );
2717 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2718 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2720 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2721 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2723 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2724 ok(hr == S_OK, "ret %08x\n", hr );
2726 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2727 ok(hr == S_OK, "ret %08x\n", hr );
2729 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2730 ok(hr == S_OK, "ret %08x\n", hr );
2732 hr = IXMLDOMComment_get_text(pComment, &str);
2733 ok(hr == S_OK, "ret %08x\n", hr );
2734 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2737 IXMLDOMComment_Release(pComment);
2741 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2742 ok(hr == S_OK, "ret %08x\n", hr );
2745 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2746 ok(hr == S_OK, "ret %08x\n", hr );
2748 /* test nodeTypeString */
2749 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2750 ok(hr == S_OK, "ret %08x\n", hr );
2751 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2754 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2755 ok(hr == S_OK, "ret %08x\n", hr );
2756 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2759 hr = IXMLDOMElement_get_xml(pElement, &str);
2760 ok(hr == S_OK, "ret %08x\n", hr );
2761 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2764 hr = IXMLDOMElement_get_dataType(pElement, &v);
2765 ok(hr == S_FALSE, "ret %08x\n", hr );
2766 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2770 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2771 ok(hr == S_OK, "ret %08x\n", hr );
2774 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2776 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2777 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2779 pNextChild = (IXMLDOMNode *)0x1;
2780 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2781 ok(hr == S_FALSE, "ret %08x\n", hr );
2782 ok(pNextChild == NULL, "pNextChild not NULL\n");
2784 /* test Previous Sibling*/
2785 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2786 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2788 pNextChild = (IXMLDOMNode *)0x1;
2789 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2790 ok(hr == S_FALSE, "ret %08x\n", hr );
2791 ok(pNextChild == NULL, "pNextChild not NULL\n");
2793 /* test get_attributes */
2794 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2795 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2797 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2798 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2799 ok(hr == S_FALSE, "ret %08x\n", hr );
2800 ok( pAttribs == NULL, "pAttribs not NULL\n");
2802 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2803 ok(hr == E_FAIL, "ret %08x\n", hr );
2804 ok(pNewChild == NULL, "pNewChild not NULL\n");
2806 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2807 ok(hr == S_OK, "ret %08x\n", hr );
2810 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2811 ok(hr == S_OK, "ret %08x\n", hr );
2813 IXMLDOMNamedNodeMap_Release(pAttribs);
2816 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2817 ok(hr == S_OK, "ret %08x\n", hr );
2818 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2821 /* test nodeTypeString */
2822 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2823 ok(hr == S_OK, "ret %08x\n", hr );
2824 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2828 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2829 ok(hr == S_OK, "ret %08x\n", hr );
2830 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
2833 /* test name property */
2834 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
2835 ok(hr == S_OK, "ret %08x\n", hr );
2836 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
2839 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2840 ok(hr == S_OK, "ret %08x\n", hr );
2841 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2844 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2845 ok(hr == S_FALSE, "ret %08x\n", hr );
2846 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2849 IXMLDOMAttribute_Release(pAttrubute);
2851 /* Check Element again with the Add Attribute*/
2852 hr = IXMLDOMElement_get_xml(pElement, &str);
2853 ok(hr == S_OK, "ret %08x\n", hr );
2854 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2858 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2859 ok(hr == S_OK, "ret %08x\n", hr );
2861 hr = IXMLDOMElement_get_xml(pElement, &str);
2862 ok(hr == S_OK, "ret %08x\n", hr );
2863 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2866 IXMLDOMElement_Release(pElement);
2870 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2871 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2873 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2874 ok(hr == S_OK, "ret %08x\n", hr );
2877 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2880 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2881 ok(hr == S_OK, "ret %08x\n", hr );
2883 /* get Attribute Tests */
2884 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2885 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2887 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2888 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2889 ok(hr == S_FALSE, "ret %08x\n", hr );
2890 ok(pAttribs == NULL, "pAttribs != NULL\n");
2892 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2893 ok(hr == S_OK, "ret %08x\n", hr );
2894 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2897 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2898 ok(hr == S_OK, "ret %08x\n", hr );
2899 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2902 /* test lastChild */
2903 pNextChild = (IXMLDOMNode*)0x1;
2904 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2905 ok(hr == S_FALSE, "ret %08x\n", hr );
2906 ok(pNextChild == NULL, "pNextChild not NULL\n");
2908 /* test get_dataType */
2909 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2910 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2912 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2913 ok(hr == S_FALSE, "ret %08x\n", hr );
2914 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2917 /* test nodeTypeString */
2918 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2919 ok(hr == S_OK, "ret %08x\n", hr );
2920 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2923 /* put data Tests */
2924 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
2925 ok(hr == S_OK, "ret %08x\n", hr );
2927 /* Confirm XML text is good */
2928 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2929 ok(hr == S_OK, "ret %08x\n", hr );
2930 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
2933 /* Confirm we get the put_data Text back */
2934 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2935 ok(hr == S_OK, "ret %08x\n", hr );
2936 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2939 /* test length property */
2940 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
2941 ok(hr == S_OK, "ret %08x\n", hr );
2942 ok(len == 21, "expected 21 got %ld\n", len);
2944 /* test get nodeValue */
2945 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
2946 ok(hr == S_OK, "ret %08x\n", hr );
2947 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2951 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
2952 ok(hr == S_OK, "ret %08x\n", hr );
2953 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2956 /* test substringData */
2957 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
2958 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2960 /* test substringData - Invalid offset */
2961 str = (BSTR)&szElement;
2962 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
2963 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2964 ok( str == NULL, "incorrect string\n");
2966 /* test substringData - Invalid offset */
2967 str = (BSTR)&szElement;
2968 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
2969 ok(hr == S_FALSE, "ret %08x\n", hr );
2970 ok( str == NULL, "incorrect string\n");
2972 /* test substringData - Invalid size */
2973 str = (BSTR)&szElement;
2974 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
2975 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2976 ok( str == NULL, "incorrect string\n");
2978 /* test substringData - Invalid size */
2979 str = (BSTR)&szElement;
2980 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
2981 ok(hr == S_FALSE, "ret %08x\n", hr );
2982 ok( str == NULL, "incorrect string\n");
2984 /* test substringData - Start of string */
2985 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
2986 ok(hr == S_OK, "ret %08x\n", hr );
2987 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2990 /* test substringData - Middle of string */
2991 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
2992 ok(hr == S_OK, "ret %08x\n", hr );
2993 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2996 /* test substringData - End of string */
2997 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
2998 ok(hr == S_OK, "ret %08x\n", hr );
2999 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
3002 /* test appendData */
3003 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
3004 ok(hr == S_OK, "ret %08x\n", hr );
3006 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
3007 ok(hr == S_OK, "ret %08x\n", hr );
3009 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
3010 ok(hr == S_OK, "ret %08x\n", hr );
3012 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3013 ok(hr == S_OK, "ret %08x\n", hr );
3014 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
3017 /* test insertData */
3018 str = SysAllocStringLen(NULL, 0);
3019 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
3020 ok(hr == S_OK, "ret %08x\n", hr );
3022 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
3023 ok(hr == S_OK, "ret %08x\n", hr );
3025 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
3026 ok(hr == S_OK, "ret %08x\n", hr );
3028 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
3029 ok(hr == S_OK, "ret %08x\n", hr );
3031 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
3032 ok(hr == S_OK, "ret %08x\n", hr );
3034 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
3035 ok(hr == S_OK, "ret %08x\n", hr );
3038 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
3039 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3041 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
3042 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3044 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
3045 ok(hr == S_OK, "ret %08x\n", hr );
3047 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
3048 ok(hr == S_OK, "ret %08x\n", hr );
3050 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
3051 ok(hr == S_OK, "ret %08x\n", hr );
3053 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3054 ok(hr == S_OK, "ret %08x\n", hr );
3055 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
3058 IXMLDOMCDATASection_Release(pCDataSec);
3061 /* Document Fragments */
3062 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
3063 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3065 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
3066 ok(hr == S_OK, "ret %08x\n", hr );
3069 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3071 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
3072 ok(hr == S_OK, "ret %08x\n", hr );
3074 /* get Attribute Tests */
3075 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
3076 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3078 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3079 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
3080 ok(hr == S_FALSE, "ret %08x\n", hr );
3081 ok(pAttribs == NULL, "pAttribs != NULL\n");
3083 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
3084 ok(hr == S_OK, "ret %08x\n", hr );
3085 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
3088 /* test next Sibling*/
3089 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
3090 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3092 pNextChild = (IXMLDOMNode *)0x1;
3093 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
3094 ok(hr == S_FALSE, "ret %08x\n", hr );
3095 ok(pNextChild == NULL, "pNextChild not NULL\n");
3097 /* test Previous Sibling*/
3098 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
3099 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3101 pNextChild = (IXMLDOMNode *)0x1;
3102 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
3103 ok(hr == S_FALSE, "ret %08x\n", hr );
3104 ok(pNextChild == NULL, "pNextChild not NULL\n");
3106 /* test get_dataType */
3107 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
3108 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3110 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
3111 ok(hr == S_FALSE, "ret %08x\n", hr );
3112 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3115 /* test nodeTypeString */
3116 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
3117 ok(hr == S_OK, "ret %08x\n", hr );
3118 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
3121 IXMLDOMDocumentFragment_Release(pDocFrag);
3124 /* Entity References */
3125 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
3126 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3128 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
3129 ok(hr == S_OK, "ret %08x\n", hr );
3132 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
3133 ok(hr == S_OK, "ret %08x\n", hr );
3135 /* get Attribute Tests */
3136 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
3137 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3139 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3140 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
3141 ok(hr == S_FALSE, "ret %08x\n", hr );
3142 ok(pAttribs == NULL, "pAttribs != NULL\n");
3145 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
3146 ok(hr == S_FALSE, "ret %08x\n", hr );
3147 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3150 /* test nodeTypeString */
3151 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
3152 ok(hr == S_OK, "ret %08x\n", hr );
3153 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
3157 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
3158 ok(hr == S_OK, "ret %08x\n", hr );
3159 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
3162 IXMLDOMEntityReference_Release(pEntityRef);
3165 IXMLDOMElement_Release( pRoot );
3169 IXMLDOMDocument_Release(doc);
3174 static void test_nodeTypeTests( void )
3176 IXMLDOMDocument *doc = NULL;
3177 IXMLDOMElement *pRoot;
3178 IXMLDOMElement *pElement;
3181 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3185 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3186 ok(hr == S_OK, "ret %08x\n", hr );
3189 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3190 ok(hr == S_OK, "ret %08x\n", hr );
3193 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
3194 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3197 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
3198 ok(hr == E_FAIL, "ret %08x\n", hr );
3201 * The name passed into put_dataType is case-insensitive. So many of the names
3202 * have been changed to reflect this.
3205 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
3206 ok(hr == S_OK, "ret %08x\n", hr );
3209 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3211 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
3212 ok(hr == S_OK, "ret %08x\n", hr );
3214 IXMLDOMElement_Release(pElement);
3218 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
3219 ok(hr == S_OK, "ret %08x\n", hr );
3222 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3224 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
3225 ok(hr == S_OK, "ret %08x\n", hr );
3227 IXMLDOMElement_Release(pElement);
3231 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
3232 ok(hr == S_OK, "ret %08x\n", hr );
3235 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3237 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
3238 ok(hr == S_OK, "ret %08x\n", hr );
3240 IXMLDOMElement_Release(pElement);
3244 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
3245 ok(hr == S_OK, "ret %08x\n", hr );
3248 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3250 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
3251 ok(hr == S_OK, "ret %08x\n", hr );
3253 IXMLDOMElement_Release(pElement);
3257 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3258 ok(hr == S_OK, "ret %08x\n", hr );
3261 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3263 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3264 ok(hr == S_OK, "ret %08x\n", hr );
3266 IXMLDOMElement_Release(pElement);
3270 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3271 ok(hr == S_OK, "ret %08x\n", hr );
3274 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3276 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3277 ok(hr == S_OK, "ret %08x\n", hr );
3279 IXMLDOMElement_Release(pElement);
3283 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3284 ok(hr == S_OK, "ret %08x\n", hr );
3287 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3289 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3290 ok(hr == S_OK, "ret %08x\n", hr );
3292 IXMLDOMElement_Release(pElement);
3296 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3297 ok(hr == S_OK, "ret %08x\n", hr );
3300 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3302 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3303 ok(hr == S_OK, "ret %08x\n", hr );
3305 IXMLDOMElement_Release(pElement);
3309 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3310 ok(hr == S_OK, "ret %08x\n", hr );
3313 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3315 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3316 ok(hr == S_OK, "ret %08x\n", hr );
3318 IXMLDOMElement_Release(pElement);
3322 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3323 ok(hr == S_OK, "ret %08x\n", hr );
3326 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3328 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3329 ok(hr == S_OK, "ret %08x\n", hr );
3331 IXMLDOMElement_Release(pElement);
3335 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3336 ok(hr == S_OK, "ret %08x\n", hr );
3339 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3341 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3342 ok(hr == S_OK, "ret %08x\n", hr );
3344 IXMLDOMElement_Release(pElement);
3348 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3349 ok(hr == S_OK, "ret %08x\n", hr );
3352 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3354 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3355 ok(hr == S_OK, "ret %08x\n", hr );
3357 IXMLDOMElement_Release(pElement);
3361 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3362 ok(hr == S_OK, "ret %08x\n", hr );
3365 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3367 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3368 ok(hr == S_OK, "ret %08x\n", hr );
3370 IXMLDOMElement_Release(pElement);
3374 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3375 ok(hr == S_OK, "ret %08x\n", hr );
3378 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3380 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3381 ok(hr == S_OK, "ret %08x\n", hr );
3383 IXMLDOMElement_Release(pElement);
3387 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3388 ok(hr == S_OK, "ret %08x\n", hr );
3391 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3393 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3394 ok(hr == S_OK, "ret %08x\n", hr );
3396 IXMLDOMElement_Release(pElement);
3400 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3401 ok(hr == S_OK, "ret %08x\n", hr );
3404 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3406 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3407 ok(hr == S_OK, "ret %08x\n", hr );
3409 IXMLDOMElement_Release(pElement);
3413 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3414 ok(hr == S_OK, "ret %08x\n", hr );
3417 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3419 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3420 ok(hr == S_OK, "ret %08x\n", hr );
3422 IXMLDOMElement_Release(pElement);
3426 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3427 ok(hr == S_OK, "ret %08x\n", hr );
3430 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3432 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3433 ok(hr == S_OK, "ret %08x\n", hr );
3435 IXMLDOMElement_Release(pElement);
3439 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3440 ok(hr == S_OK, "ret %08x\n", hr );
3443 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3445 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3446 ok(hr == S_OK, "ret %08x\n", hr );
3448 IXMLDOMElement_Release(pElement);
3452 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3453 ok(hr == S_OK, "ret %08x\n", hr );
3456 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3458 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3459 ok(hr == S_OK, "ret %08x\n", hr );
3461 IXMLDOMElement_Release(pElement);
3465 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3466 ok(hr == S_OK, "ret %08x\n", hr );
3469 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3471 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3472 ok(hr == S_OK, "ret %08x\n", hr );
3474 IXMLDOMElement_Release(pElement);
3478 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3479 ok(hr == S_OK, "ret %08x\n", hr );
3482 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3484 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3485 ok(hr == S_OK, "ret %08x\n", hr );
3487 IXMLDOMElement_Release(pElement);
3490 /* Check changing types */
3491 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3492 ok(hr == S_OK, "ret %08x\n", hr );
3495 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3497 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3498 ok(hr == S_OK, "ret %08x\n", hr );
3500 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3501 ok(hr == S_OK, "ret %08x\n", hr );
3503 IXMLDOMElement_Release(pElement);
3506 IXMLDOMElement_Release(pRoot);
3510 IXMLDOMDocument_Release(doc);
3515 static void test_DocumentSaveToDocument(void)
3517 IXMLDOMDocument *doc = NULL;
3518 IXMLDOMDocument *doc2 = NULL;
3519 IXMLDOMElement *pRoot;
3523 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3527 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3530 IXMLDOMDocument_Release(doc);
3534 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3535 ok(hr == S_OK, "ret %08x\n", hr );
3538 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3539 ok(hr == S_OK, "ret %08x\n", hr );
3546 V_VT(&vDoc) = VT_UNKNOWN;
3547 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3549 hr = IXMLDOMDocument_save(doc, vDoc);
3550 ok(hr == S_OK, "ret %08x\n", hr );
3552 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3553 ok(hr == S_OK, "ret %08x\n", hr );
3555 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3556 ok(hr == S_OK, "ret %08x\n", hr );
3558 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3560 SysFreeString(sOrig);
3561 SysFreeString(sNew);
3565 IXMLDOMDocument_Release(doc2);
3566 IXMLDOMDocument_Release(doc);
3569 static void test_DocumentSaveToFile(void)
3571 IXMLDOMDocument *doc = NULL;
3572 IXMLDOMElement *pRoot;
3578 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3582 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3583 ok(hr == S_OK, "ret %08x\n", hr );
3586 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3587 ok(hr == S_OK, "ret %08x\n", hr );
3592 V_VT(&vFile) = VT_BSTR;
3593 V_BSTR(&vFile) = _bstr_("test.xml");
3595 hr = IXMLDOMDocument_save(doc, vFile);
3596 ok(hr == S_OK, "ret %08x\n", hr );
3600 IXMLDOMElement_Release(pRoot);
3601 IXMLDOMDocument_Release(doc);
3603 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3604 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3605 if(file == INVALID_HANDLE_VALUE)
3608 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3609 ok(read != 0, "could not read file\n");
3610 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3613 DeleteFile("test.xml");
3616 static void test_testTransforms(void)
3618 IXMLDOMDocument *doc = NULL;
3619 IXMLDOMDocument *docSS = NULL;
3625 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3629 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3632 IXMLDOMDocument_Release(doc);
3636 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3637 ok(hr == S_OK, "ret %08x\n", hr );
3639 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3640 ok(hr == S_OK, "ret %08x\n", hr );
3642 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3643 ok(hr == S_OK, "ret %08x\n", hr );
3648 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3649 ok(hr == S_OK, "ret %08x\n", hr );
3650 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3652 IXMLDOMNode_Release(pNode);
3655 IXMLDOMDocument_Release(docSS);
3656 IXMLDOMDocument_Release(doc);
3661 static void test_Namespaces(void)
3663 IXMLDOMDocument2 *doc = NULL;
3665 IXMLDOMNode *pNode2 = NULL;
3669 static const CHAR szNamespacesXML[] =
3670 "<?xml version=\"1.0\"?>\n"
3671 "<root xmlns:WEB='http://www.winehq.org'>\n"
3672 "<WEB:Site version=\"1.0\" />\n"
3675 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3679 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3680 ok(hr == S_OK, "ret %08x\n", hr );
3681 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3683 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3684 ok(hr == S_OK, "ret %08x\n", hr );
3687 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3688 ok( hr == S_OK, "ret %08x\n", hr );
3689 ok( pNode2 != NULL, "pNode2 == NULL\n");
3691 /* Test get_prefix */
3692 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3693 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3694 /* NOTE: Need to test that arg2 gets cleared on Error. */
3696 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3697 ok( hr == S_OK, "ret %08x\n", hr );
3698 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3701 /* Test get_namespaceURI */
3702 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3703 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3704 /* NOTE: Need to test that arg2 gets cleared on Error. */
3706 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3707 ok( hr == S_OK, "ret %08x\n", hr );
3708 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3711 IXMLDOMNode_Release(pNode2);
3712 IXMLDOMNode_Release(pNode);
3715 IXMLDOMDocument2_Release(doc);
3720 static void test_FormattingXML(void)
3722 IXMLDOMDocument2 *doc = NULL;
3723 IXMLDOMElement *pElement;
3727 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
3728 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
3730 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3734 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
3735 ok(hr == S_OK, "ret %08x\n", hr );
3736 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3738 if(bSucc == VARIANT_TRUE)
3740 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
3741 ok(hr == S_OK, "ret %08x\n", hr );
3744 hr = IXMLDOMElement_get_xml(pElement, &str);
3745 ok(hr == S_OK, "ret %08x\n", hr );
3746 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
3749 IXMLDOMElement_Release(pElement);
3753 IXMLDOMDocument2_Release(doc);
3762 r = CoInitialize( NULL );
3763 ok( r == S_OK, "failed to init com\n");
3769 test_getElementsByTagName();
3771 test_get_childNodes();
3773 test_replaceChild();
3774 test_removeNamedItem();
3776 test_IXMLDOMDocument2();
3780 test_nodeTypeTests();
3781 test_DocumentSaveToDocument();
3782 test_DocumentSaveToFile();
3783 test_testTransforms();
3785 test_FormattingXML();