4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
33 const CLSID CLSID_DOMDocument2 = {0xf6d90f11, 0x9c73, 0x11d3, {0xb3, 0x2e, 0x00, 0xc0, 0x4f, 0x99, 0x0b, 0xb4}};
34 const IID IID_IXMLDOMDocument2 = {0x2933bf95, 0x7b36, 0x11d2, {0xb2, 0x0e, 0x00, 0xc0, 0x4f, 0x98, 0x3e, 0x60}};
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 WCHAR szNonExistentFile[] = {
122 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
124 static const WCHAR szDocument[] = {
125 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
128 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
129 static WCHAR szdl[] = { 'd','l',0 };
130 static const WCHAR szvr[] = { 'v','r',0 };
131 static const WCHAR szlc[] = { 'l','c',0 };
132 static WCHAR szbs[] = { 'b','s',0 };
133 static const WCHAR szstr1[] = { 's','t','r','1',0 };
134 static const WCHAR szstr2[] = { 's','t','r','2',0 };
135 static const WCHAR szstar[] = { '*',0 };
136 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
138 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
139 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
140 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
142 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
143 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
144 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
145 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
146 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
148 static WCHAR szAttribute[] = {'A','t','t','r',0 };
149 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
151 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
152 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
153 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
154 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
156 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
157 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
159 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
160 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
162 #define expect_bstr_eq_and_free(bstr, expect) { \
163 BSTR bstrExp = alloc_str_from_narrow(expect); \
164 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
165 SysFreeString(bstr); \
166 SysFreeString(bstrExp); \
169 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
171 #define ole_check(expr) { \
173 ok(r == S_OK, #expr " returned %x\n", r); \
176 #define ole_expect(expr, expect) { \
178 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
181 static BSTR alloc_str_from_narrow(const char *str)
183 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
184 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
185 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
189 BSTR alloced_bstrs[256];
190 int alloced_bstrs_count = 0;
192 static BSTR _bstr_(const char *str)
194 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
195 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
196 return alloced_bstrs[alloced_bstrs_count++];
199 static void free_bstrs(void)
202 for (i = 0; i < alloced_bstrs_count; i++)
203 SysFreeString(alloced_bstrs[i]);
204 alloced_bstrs_count = 0;
207 static VARIANT _variantbstr_(const char *str)
211 V_BSTR(&v) = _bstr_(str);
215 static void get_str_for_type(DOMNodeType type, char *buf)
229 wsprintfA(buf, "[%d]", type);
233 static int get_node_position(IXMLDOMNode *node)
238 IXMLDOMNode_AddRef(node);
241 IXMLDOMNode *new_node;
244 r = IXMLDOMNode_get_previousSibling(node, &new_node);
245 ok(!FAILED(r), "get_previousSibling failed\n");
246 IXMLDOMNode_Release(node);
252 static void node_to_string(IXMLDOMNode *node, char *buf)
259 lstrcpyA(buf, "(null)");
263 IXMLDOMNode_AddRef(node);
266 IXMLDOMNode *new_node;
268 ole_check(IXMLDOMNode_get_nodeType(node, &type));
269 get_str_for_type(type, buf);
272 if (type == NODE_ATTRIBUTE)
275 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
277 wsprintfA(buf, "%ws", bstr);
282 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
286 int pos = get_node_position(node);
287 DOMNodeType parent_type = NODE_INVALID;
288 r = IXMLDOMNode_get_parentNode(node, &new_node);
290 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
291 * results we "fix" it */
293 ole_check(IXMLDOMNode_get_nodeType(node, &parent_type));
294 /* we need also to workaround the no document node problem - see below */
295 if (((r == S_FALSE && type != NODE_DOCUMENT) || parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
297 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
300 wsprintf(buf, "%d", pos);
304 ok(!FAILED(r), "get_parentNode failed (%08x)\n", r);
305 IXMLDOMNode_Release(node);
311 /* currently we can't access document node in wine. All our examples this is the
312 * root node so to be able to test query results we add it */
313 if (type != NODE_DOCUMENT)
315 todo_wine ok(FALSE, "Document node is not the last returned node!\n");
323 static char *list_to_string(IXMLDOMNodeList *list)
325 static char buf[4096];
332 lstrcpyA(buf, "(null)");
335 ole_check(IXMLDOMNodeList_get_length(list, &len));
336 for (i = 0; i < len; i++)
341 ole_check(IXMLDOMNodeList_nextNode(list, &node));
342 node_to_string(node, pos);
344 IXMLDOMNode_Release(node);
350 #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); }
351 #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); }
353 static void test_domdoc( void )
356 IXMLDOMDocument *doc = NULL;
357 IXMLDOMParseError *error;
358 IXMLDOMElement *element = NULL;
360 IXMLDOMText *nodetext = NULL;
361 IXMLDOMComment *node_comment = NULL;
362 IXMLDOMAttribute *node_attr = NULL;
363 IXMLDOMNode *nodeChild = NULL;
364 IXMLDOMProcessingInstruction *nodePI = NULL;
371 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
372 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
376 /* try some stupid things */
377 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
378 ok( r == S_FALSE, "loadXML failed\n");
381 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
382 ok( r == S_FALSE, "loadXML failed\n");
383 ok( b == VARIANT_FALSE, "failed to load XML string\n");
385 /* try to load a document from a nonexistent file */
387 str = SysAllocString( szNonExistentFile );
389 V_VT(&var) = VT_BSTR;
392 r = IXMLDOMDocument_load( doc, var, &b);
393 ok( r == S_FALSE, "load (from file) failed\n");
394 ok( b == VARIANT_FALSE, "failed to load XML file\n");
395 SysFreeString( str );
397 /* try load an empty document */
399 str = SysAllocString( szEmpty );
400 r = IXMLDOMDocument_loadXML( doc, str, &b );
401 ok( r == S_FALSE, "loadXML failed\n");
402 ok( b == VARIANT_FALSE, "failed to load XML string\n");
403 SysFreeString( str );
405 /* check that there's no document element */
407 r = IXMLDOMDocument_get_documentElement( doc, &element );
408 ok( r == S_FALSE, "should be no document element\n");
410 /* try finding a node */
412 str = SysAllocString( szstr1 );
413 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
414 ok( r == S_FALSE, "ret %08x\n", r );
415 SysFreeString( str );
418 str = SysAllocString( szIncomplete );
419 r = IXMLDOMDocument_loadXML( doc, str, &b );
420 ok( r == S_FALSE, "loadXML failed\n");
421 ok( b == VARIANT_FALSE, "failed to load XML string\n");
422 SysFreeString( str );
424 /* check that there's no document element */
425 element = (IXMLDOMElement*)1;
426 r = IXMLDOMDocument_get_documentElement( doc, &element );
427 ok( r == S_FALSE, "should be no document element\n");
428 ok( element == NULL, "Element should be NULL\n");
430 /* try to load something valid */
432 str = SysAllocString( szComplete1 );
433 r = IXMLDOMDocument_loadXML( doc, str, &b );
434 ok( r == S_OK, "loadXML failed\n");
435 ok( b == VARIANT_TRUE, "failed to load XML string\n");
436 SysFreeString( str );
438 /* try with a null out pointer */
439 r = IXMLDOMDocument_get_documentElement( doc, NULL );
440 ok( r == E_INVALIDARG, "should be no document element\n");
442 /* check if nodename is correct */
443 r = IXMLDOMDocument_get_nodeName( doc, NULL );
444 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
446 /* content doesn't matter here */
448 r = IXMLDOMDocument_get_nodeName( doc, &str );
449 ok ( r == S_OK, "get_nodeName wrong code\n");
450 ok ( str != NULL, "str is null\n");
451 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
452 SysFreeString( str );
455 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
456 ok( r == E_FAIL, "ret %08x\n", r );
458 /* check that there's a document element */
460 r = IXMLDOMDocument_get_documentElement( doc, &element );
461 ok( r == S_OK, "should be a document element\n");
466 /* check if the tag is correct */
467 r = IXMLDOMElement_get_tagName( element, &tag );
468 ok( r == S_OK, "couldn't get tag name\n");
469 ok( tag != NULL, "tag was null\n");
470 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
471 SysFreeString( tag );
473 /* figure out what happens if we try to reload the document */
474 str = SysAllocString( szComplete2 );
475 r = IXMLDOMDocument_loadXML( doc, str, &b );
476 ok( r == S_OK, "loadXML failed\n");
477 ok( b == VARIANT_TRUE, "failed to load XML string\n");
478 SysFreeString( str );
480 /* check if the tag is still correct */
482 r = IXMLDOMElement_get_tagName( element, &tag );
483 ok( r == S_OK, "couldn't get tag name\n");
484 ok( tag != NULL, "tag was null\n");
485 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
486 SysFreeString( tag );
488 IXMLDOMElement_Release( element );
492 /* as soon as we call loadXML again, the document element will disappear */
494 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
495 ok( r == S_FALSE, "loadXML failed\n");
496 ok( b == 2, "variant modified\n");
497 r = IXMLDOMDocument_get_documentElement( doc, &element );
498 ok( r == S_FALSE, "should be no document element\n");
500 /* try to load something else simple and valid */
502 str = SysAllocString( szComplete3 );
503 r = IXMLDOMDocument_loadXML( doc, str, &b );
504 ok( r == S_OK, "loadXML failed\n");
505 ok( b == VARIANT_TRUE, "failed to load XML string\n");
506 SysFreeString( str );
508 /* try something a little more complicated */
510 str = SysAllocString( szComplete4 );
511 r = IXMLDOMDocument_loadXML( doc, str, &b );
512 ok( r == S_OK, "loadXML failed\n");
513 ok( b == VARIANT_TRUE, "failed to load XML string\n");
514 SysFreeString( str );
516 r = IXMLDOMDocument_get_parseError( doc, &error );
517 ok( r == S_OK, "returns %08x\n", r );
519 r = IXMLDOMParseError_get_errorCode( error, &code );
520 ok( r == S_FALSE, "returns %08x\n", r );
521 ok( code == 0, "code %ld\n", code );
522 IXMLDOMParseError_Release( error );
524 /* test createTextNode */
525 str = SysAllocString( szOpen );
526 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
527 ok( r == E_INVALIDARG, "returns %08x\n", r );
528 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
529 ok( r == S_OK, "returns %08x\n", r );
532 IXMLDOMNamedNodeMap *pAttribs;
534 /* Text Last Child Checks */
535 r = IXMLDOMText_get_lastChild(nodetext, NULL);
536 ok(r == E_INVALIDARG, "ret %08x\n", r );
538 nodeChild = (IXMLDOMNode*)0x1;
539 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
540 ok(r == S_FALSE, "ret %08x\n", r );
541 ok(nodeChild == NULL, "nodeChild not NULL\n");
543 /* test get_attributes */
544 r = IXMLDOMText_get_attributes( nodetext, NULL );
545 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
547 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
548 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
549 ok(r == S_FALSE, "ret %08x\n", r );
550 ok( pAttribs == NULL, "pAttribs not NULL\n");
552 /* test get_dataType */
553 r = IXMLDOMText_get_dataType(nodetext, &var);
554 ok(r == S_FALSE, "ret %08x\n", r );
555 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
558 /* test length property */
559 r = IXMLDOMText_get_length(nodetext, NULL);
560 ok(r == E_INVALIDARG, "ret %08x\n", r );
562 r = IXMLDOMText_get_length(nodetext, &nLength);
563 ok(r == S_OK, "ret %08x\n", r );
564 ok(nLength == 4, "expected 4 got %ld\n", nLength);
566 /* test nodeTypeString */
567 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
568 ok(r == S_OK, "ret %08x\n", r );
569 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
573 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
574 ok(r == S_OK, "ret %08x\n", r );
576 /* Confirm XML text is good */
577 r = IXMLDOMText_get_xml(nodetext, &str);
578 ok(r == S_OK, "ret %08x\n", r );
579 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
582 /* Confirm we get the put_data Text back */
583 r = IXMLDOMText_get_text(nodetext, &str);
584 ok(r == S_OK, "ret %08x\n", r );
585 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
588 IXMLDOMText_Release( nodetext );
590 SysFreeString( str );
592 /* test Create Comment */
593 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
594 ok( r == E_INVALIDARG, "returns %08x\n", r );
595 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
596 ok( r == S_OK, "returns %08x\n", r );
599 /* Last Child Checks */
600 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
601 ok(r == E_INVALIDARG, "ret %08x\n", r );
603 nodeChild = (IXMLDOMNode*)0x1;
604 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
605 ok(r == S_FALSE, "ret %08x\n", r );
606 ok(nodeChild == NULL, "pLastChild not NULL\n");
608 IXMLDOMComment_Release( node_comment );
611 /* test Create Attribute */
612 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
613 ok( r == E_INVALIDARG, "returns %08x\n", r );
614 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
615 ok( r == S_OK, "returns %08x\n", r );
616 IXMLDOMText_Release( node_attr);
618 /* test Processing Instruction */
619 str = SysAllocStringLen(NULL, 0);
620 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
621 ok( r == E_INVALIDARG, "returns %08x\n", r );
622 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
623 ok( r == E_FAIL, "returns %08x\n", r );
624 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
625 ok( r == E_FAIL, "returns %08x\n", r );
628 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
629 ok( r == S_OK, "returns %08x\n", r );
632 /* Last Child Checks */
633 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
634 ok(r == E_INVALIDARG, "ret %08x\n", r );
636 nodeChild = (IXMLDOMNode*)0x1;
637 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
638 ok(r == S_FALSE, "ret %08x\n", r );
639 ok(nodeChild == NULL, "nodeChild not NULL\n");
641 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
642 ok(r == S_FALSE, "ret %08x\n", r );
643 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
647 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
648 ok(r == S_OK, "ret %08x\n", r );
649 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
653 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
654 ok(r == S_OK, "ret %08x\n", r );
655 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
658 /* test nodeTypeString */
659 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
660 ok(r == S_OK, "ret %08x\n", r );
661 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
664 /* test get_nodeValue */
665 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
666 ok(r == S_OK, "ret %08x\n", r );
667 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
671 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
672 ok(r == S_OK, "ret %08x\n", r );
673 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
677 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
678 ok(r == S_OK, "ret %08x\n", r );
681 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
682 ok(r == S_OK, "ret %08x\n", r );
683 ok( !lstrcmpW( str, _bstr_("version=\"1.0\" encoding=\"UTF-8\"") ), "incorrect data string\n");
686 /* Confirm XML text is good */
687 r = IXMLDOMProcessingInstruction_get_xml(nodePI, &str);
688 ok(r == S_OK, "ret %08x\n", r );
689 ok( !lstrcmpW( str, _bstr_("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") ), "incorrect xml string\n");
692 IXMLDOMProcessingInstruction_Release(nodePI);
695 r = IXMLDOMDocument_Release( doc );
696 ok( r == 0, "document ref count incorrect\n");
701 static void test_domnode( void )
704 IXMLDOMDocument *doc = NULL, *owner = NULL;
705 IXMLDOMElement *element = NULL;
706 IXMLDOMNamedNodeMap *map = NULL;
707 IXMLDOMNode *node = NULL, *next = NULL;
708 IXMLDOMNodeList *list = NULL;
709 DOMNodeType type = NODE_INVALID;
715 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
716 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
721 str = SysAllocString( szComplete4 );
722 r = IXMLDOMDocument_loadXML( doc, str, &b );
723 ok( r == S_OK, "loadXML failed\n");
724 ok( b == VARIANT_TRUE, "failed to load XML string\n");
725 SysFreeString( str );
730 r = IXMLDOMNode_hasChildNodes( doc, &b );
731 ok( r == S_OK, "hasChildNoes bad return\n");
732 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
734 r = IXMLDOMDocument_get_documentElement( doc, &element );
735 ok( r == S_OK, "should be a document element\n");
736 ok( element != NULL, "should be an element\n");
739 ok( FALSE, "no document\n");
742 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
744 r = IXMLDOMNode_get_nodeValue( doc, NULL );
745 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
747 r = IXMLDOMNode_get_nodeValue( doc, &var );
748 ok( r == S_FALSE, "nextNode returned wrong code\n");
749 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
750 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
755 r = IXMLDOMNode_get_ownerDocument( element, &owner );
757 ok( r == S_OK, "get_ownerDocument return code\n");
759 ok( owner != doc, "get_ownerDocument return\n");
762 r = IXMLDOMNode_get_nodeType( element, &type);
763 ok( r == S_OK, "getNamedItem returned wrong code\n");
764 ok( type == NODE_ELEMENT, "node not an element\n");
767 r = IXMLDOMNode_get_baseName( element, &str );
768 ok( r == S_OK, "get_baseName returned wrong code\n");
769 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
772 /* check if nodename is correct */
773 r = IXMLDOMElement_get_nodeName( element, NULL );
774 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
776 /* content doesn't matter here */
778 r = IXMLDOMElement_get_nodeName( element, &str );
779 ok ( r == S_OK, "get_nodeName wrong code\n");
780 ok ( str != NULL, "str is null\n");
781 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
782 SysFreeString( str );
784 str = SysAllocString( szNonExistentFile );
787 r = IXMLDOMElement_getAttribute( element, str, &var );
788 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
789 ok( V_VT(&var) == VT_NULL, "vt = %x\n", V_VT(&var));
791 SysFreeString( str );
793 str = SysAllocString( szdl );
796 r = IXMLDOMElement_getAttribute( element, str, &var );
797 ok( r == S_OK, "getAttribute ret %08x\n", r );
798 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
799 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
800 VariantClear( &var );
802 r = IXMLDOMElement_getAttribute( element, NULL, &var );
803 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
805 r = IXMLDOMElement_getAttribute( element, str, NULL );
806 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
808 SysFreeString( str );
810 r = IXMLDOMElement_get_attributes( element, &map );
811 ok( r == S_OK, "get_attributes returned wrong code\n");
812 ok( map != NULL, "should be attributes\n");
815 r = IXMLDOMNode_hasChildNodes( element, &b );
816 ok( r == S_OK, "hasChildNoes bad return\n");
817 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
820 ok( FALSE, "no element\n");
824 ISupportErrorInfo *support_error;
825 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
826 ok( r == S_OK, "ret %08x\n", r );
828 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
831 ok( r == S_OK, "ret %08x\n", r );
833 ISupportErrorInfo_Release( support_error );
835 str = SysAllocString( szdl );
836 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
837 ok( r == S_OK, "getNamedItem returned wrong code\n");
838 ok( node != NULL, "should be attributes\n");
839 IXMLDOMNode_Release(node);
840 SysFreeString( str );
842 str = SysAllocString( szdl );
843 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
844 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
845 SysFreeString( str );
847 /* something that isn't in szComplete4 */
848 str = SysAllocString( szOpen );
849 node = (IXMLDOMNode *) 1;
850 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
851 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
852 ok( node == NULL, "getNamedItem should have returned NULL\n");
853 SysFreeString( str );
855 /* test indexed access of attributes */
856 r = IXMLDOMNamedNodeMap_get_length( map, &count );
857 ok ( r == S_OK, "get_length wrong code\n");
858 ok ( count == 1, "get_length != 1\n");
861 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
862 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
863 ok ( node == NULL, "there is no node\n");
866 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
867 ok ( r == S_FALSE, "get_item (1) wrong code\n");
868 ok ( node == NULL, "there is no attribute\n");
871 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
872 ok ( r == S_OK, "get_item (0) wrong code\n");
873 ok ( node != NULL, "should be attribute\n");
875 r = IXMLDOMNode_get_nodeName( node, NULL );
876 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
878 /* content doesn't matter here */
880 r = IXMLDOMNode_get_nodeName( node, &str );
881 ok ( r == S_OK, "get_nodeName wrong code\n");
882 ok ( str != NULL, "str is null\n");
883 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
884 SysFreeString( str );
886 /* test sequential access of attributes */
888 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
889 ok ( r == S_OK, "nextNode (first time) wrong code\n");
890 ok ( node != NULL, "nextNode, should be attribute\n");
892 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
893 ok ( r != S_OK, "nextNode (second time) wrong code\n");
894 ok ( node == NULL, "nextNode, there is no attribute\n");
896 r = IXMLDOMNamedNodeMap_reset( map );
897 ok ( r == S_OK, "reset should return S_OK\n");
899 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
900 ok ( r == S_OK, "nextNode (third time) wrong code\n");
901 ok ( node != NULL, "nextNode, should be attribute\n");
904 ok( FALSE, "no map\n");
909 r = IXMLDOMNode_get_nodeType( node, &type);
910 ok( r == S_OK, "getNamedItem returned wrong code\n");
911 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
914 r = IXMLDOMNode_get_baseName( node, NULL );
915 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
918 r = IXMLDOMNode_get_baseName( node, &str );
919 ok( r == S_OK, "get_baseName returned wrong code\n");
920 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
921 SysFreeString( str );
923 r = IXMLDOMNode_get_nodeValue( node, &var );
924 ok( r == S_OK, "returns %08x\n", r );
925 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
926 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
929 r = IXMLDOMNode_get_childNodes( node, NULL );
930 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
932 r = IXMLDOMNode_get_childNodes( node, &list );
933 ok( r == S_OK, "get_childNodes returned wrong code\n");
937 r = IXMLDOMNodeList_nextNode( list, &next );
938 ok( r == S_OK, "nextNode returned wrong code\n");
941 ok( FALSE, "no childlist\n");
946 r = IXMLDOMNode_hasChildNodes( next, &b );
947 ok( r == S_FALSE, "hasChildNoes bad return\n");
948 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
951 r = IXMLDOMNode_get_nodeType( next, &type);
952 ok( r == S_OK, "getNamedItem returned wrong code\n");
953 ok( type == NODE_TEXT, "node not text\n");
956 r = IXMLDOMNode_get_baseName( next, &str );
957 ok( r == S_FALSE, "get_baseName returned wrong code\n");
958 ok( str == NULL, "basename was wrong\n");
962 ok( FALSE, "no next\n");
965 IXMLDOMNode_Release( next );
968 IXMLDOMNodeList_Release( list );
971 IXMLDOMNode_Release( node );
974 ok( FALSE, "no node\n");
978 IXMLDOMNamedNodeMap_Release( map );
980 /* now traverse the tree from the root element */
984 r = IXMLDOMNode_get_childNodes( element, &list );
985 ok( r == S_OK, "get_childNodes returned wrong code\n");
987 /* using get_item for child list doesn't advance the position */
988 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
989 expect_node(node, "E2.E2.D1");
990 IXMLDOMNode_Release(node);
991 ole_check(IXMLDOMNodeList_nextNode(list, &node));
992 expect_node(node, "E1.E2.D1");
993 IXMLDOMNode_Release(node);
994 ole_check(IXMLDOMNodeList_reset(list));
996 IXMLDOMNodeList_AddRef(list);
997 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
998 ole_check(IXMLDOMNodeList_reset(list));
1001 ok( FALSE, "no element\n");
1003 node = (void*)0xdeadbeef;
1004 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1005 ok( r == S_FALSE, "ret %08x\n", r );
1006 ok( node == NULL, "node %p\n", node );
1007 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1008 ok( r == S_OK, "ret %08x\n", r );
1009 r = IXMLDOMNode_Release( node );
1010 ok( r == 0, "ret %08x\n", r );
1014 r = IXMLDOMNodeList_get_length( list, &count );
1015 ok( r == S_OK, "get_length returns %08x\n", r );
1016 ok( count == 4, "get_length got %ld\n", count );
1018 r = IXMLDOMNodeList_nextNode( list, &node );
1019 ok( r == S_OK, "nextNode returned wrong code\n");
1022 ok( FALSE, "no list\n");
1026 type = NODE_INVALID;
1027 r = IXMLDOMNode_get_nodeType( node, &type);
1028 ok( r == S_OK, "getNamedItem returned wrong code\n");
1029 ok( type == NODE_ELEMENT, "node not text\n");
1032 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1033 r = IXMLDOMNode_get_nodeValue( node, &var );
1034 ok( r == S_FALSE, "nextNode returned wrong code\n");
1035 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1036 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1038 r = IXMLDOMNode_hasChildNodes( node, NULL );
1039 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1042 r = IXMLDOMNode_hasChildNodes( node, &b );
1043 ok( r == S_OK, "hasChildNoes bad return\n");
1044 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1047 r = IXMLDOMNode_get_baseName( node, &str );
1048 ok( r == S_OK, "get_baseName returned wrong code\n");
1049 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1053 ok( FALSE, "no node\n");
1056 IXMLDOMNode_Release( node );
1058 IXMLDOMNodeList_Release( list );
1060 IXMLDOMElement_Release( element );
1063 str = SysAllocString( szComplete5 );
1064 r = IXMLDOMDocument_loadXML( doc, str, &b );
1065 ok( r == S_OK, "loadXML failed\n");
1066 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1067 SysFreeString( str );
1070 r = IXMLDOMNode_hasChildNodes( doc, &b );
1071 ok( r == S_OK, "hasChildNoes bad return\n");
1072 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1074 r = IXMLDOMDocument_get_documentElement( doc, &element );
1075 ok( r == S_OK, "should be a document element\n");
1076 ok( element != NULL, "should be an element\n");
1080 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1083 /* check if the tag is correct */
1084 r = IXMLDOMElement_get_tagName( element, &tag );
1085 ok( r == S_OK, "couldn't get tag name\n");
1086 ok( tag != NULL, "tag was null\n");
1087 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1088 SysFreeString( tag );
1092 IXMLDOMElement_Release( element );
1094 IXMLDOMDocument_Release( doc );
1097 static void test_refs(void)
1102 IXMLDOMDocument *doc = NULL;
1103 IXMLDOMElement *element = NULL;
1104 IXMLDOMNode *node = NULL, *node2;
1105 IXMLDOMNodeList *node_list = NULL;
1107 IUnknown *unk, *unk2;
1109 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1110 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1113 ref = IXMLDOMDocument_Release(doc);
1114 ok( ref == 0, "ref %d\n", ref);
1116 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1117 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1121 str = SysAllocString( szComplete4 );
1122 r = IXMLDOMDocument_loadXML( doc, str, &b );
1123 ok( r == S_OK, "loadXML failed\n");
1124 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1125 SysFreeString( str );
1127 ref = IXMLDOMDocument_AddRef( doc );
1128 ok( ref == 2, "ref %d\n", ref );
1129 ref = IXMLDOMDocument_AddRef( doc );
1130 ok( ref == 3, "ref %d\n", ref );
1131 IXMLDOMDocument_Release( doc );
1132 IXMLDOMDocument_Release( doc );
1134 r = IXMLDOMDocument_get_documentElement( doc, &element );
1135 ok( r == S_OK, "should be a document element\n");
1136 ok( element != NULL, "should be an element\n");
1138 ref = IXMLDOMDocument_AddRef( doc );
1139 ok( ref == 2, "ref %d\n", ref );
1140 IXMLDOMDocument_Release( doc );
1142 r = IXMLDOMElement_get_childNodes( element, &node_list );
1143 ok( r == S_OK, "rets %08x\n", r);
1144 ref = IXMLDOMNodeList_AddRef( node_list );
1145 ok( ref == 2, "ref %d\n", ref );
1146 IXMLDOMNodeList_Release( node_list );
1148 IXMLDOMNodeList_get_item( node_list, 0, &node );
1149 ok( r == S_OK, "rets %08x\n", r);
1151 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1152 ok( r == S_OK, "rets %08x\n", r);
1154 ref = IXMLDOMNode_AddRef( node );
1155 ok( ref == 2, "ref %d\n", ref );
1156 IXMLDOMNode_Release( node );
1158 ref = IXMLDOMNode_Release( node );
1159 ok( ref == 0, "ref %d\n", ref );
1160 ref = IXMLDOMNode_Release( node2 );
1161 ok( ref == 0, "ref %d\n", ref );
1163 ref = IXMLDOMNodeList_Release( node_list );
1164 ok( ref == 0, "ref %d\n", ref );
1166 ok( node != node2, "node %p node2 %p\n", node, node2 );
1168 ref = IXMLDOMDocument_Release( doc );
1169 ok( ref == 0, "ref %d\n", ref );
1171 ref = IXMLDOMElement_AddRef( element );
1173 ok( ref == 3, "ref %d\n", ref );
1175 IXMLDOMElement_Release( element );
1177 /* IUnknown must be unique however we obtain it */
1178 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1179 ok( r == S_OK, "rets %08x\n", r );
1180 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1181 ok( r == S_OK, "rets %08x\n", r );
1182 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1183 ok( r == S_OK, "rets %08x\n", r );
1184 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1186 IUnknown_Release( unk2 );
1187 IUnknown_Release( unk );
1188 IXMLDOMNode_Release( node );
1190 IXMLDOMElement_Release( element );
1194 static void test_create(void)
1199 IXMLDOMDocument *doc;
1200 IXMLDOMElement *element;
1201 IXMLDOMNode *root, *node, *child;
1202 IXMLDOMNamedNodeMap *attr_map;
1207 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1208 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1213 V_I4(&var) = NODE_ELEMENT;
1214 str = SysAllocString( szlc );
1215 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1216 ok( r == S_OK, "returns %08x\n", r );
1217 r = IXMLDOMDocument_appendChild( doc, node, &root );
1218 ok( r == S_OK, "returns %08x\n", r );
1219 ok( node == root, "%p %p\n", node, root );
1221 ref = IXMLDOMNode_AddRef( node );
1222 ok(ref == 3, "ref %d\n", ref);
1223 IXMLDOMNode_Release( node );
1225 ref = IXMLDOMNode_Release( node );
1226 ok(ref == 1, "ref %d\n", ref);
1227 SysFreeString( str );
1230 V_I4(&var) = NODE_ELEMENT;
1231 str = SysAllocString( szbs );
1232 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1233 ok( r == S_OK, "returns %08x\n", r );
1235 ref = IXMLDOMNode_AddRef( node );
1236 ok(ref == 2, "ref = %d\n", ref);
1237 IXMLDOMNode_Release( node );
1239 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1240 ok( r == S_OK, "returns %08x\n", r );
1242 ref = IXMLDOMNode_AddRef( unk );
1243 ok(ref == 3, "ref = %d\n", ref);
1244 IXMLDOMNode_Release( unk );
1246 V_VT(&var) = VT_EMPTY;
1247 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1248 ok( r == S_OK, "returns %08x\n", r );
1249 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1250 IXMLDOMNode_Release( child );
1251 IUnknown_Release( unk );
1254 V_VT(&var) = VT_NULL;
1255 V_DISPATCH(&var) = (IDispatch*)node;
1256 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1257 ok( r == S_OK, "returns %08x\n", r );
1258 ok( node == child, "%p %p\n", node, child );
1259 IXMLDOMNode_Release( child );
1262 V_VT(&var) = VT_NULL;
1263 V_DISPATCH(&var) = (IDispatch*)node;
1264 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1265 ok( r == S_OK, "returns %08x\n", r );
1266 IXMLDOMNode_Release( node );
1268 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1269 ok( r == S_OK, "returns %08x\n", r );
1271 r = IXMLDOMElement_get_attributes( element, &attr_map );
1272 ok( r == S_OK, "returns %08x\n", r );
1273 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1274 ok( r == S_OK, "returns %08x\n", r );
1275 ok( num == 0, "num %ld\n", num );
1276 IXMLDOMNamedNodeMap_Release( attr_map );
1278 V_VT(&var) = VT_BSTR;
1279 V_BSTR(&var) = SysAllocString( szstr1 );
1280 name = SysAllocString( szdl );
1281 r = IXMLDOMElement_setAttribute( element, name, var );
1282 ok( r == S_OK, "returns %08x\n", r );
1283 r = IXMLDOMElement_get_attributes( element, &attr_map );
1284 ok( r == S_OK, "returns %08x\n", r );
1285 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1286 ok( r == S_OK, "returns %08x\n", r );
1287 ok( num == 1, "num %ld\n", num );
1288 IXMLDOMNamedNodeMap_Release( attr_map );
1291 V_VT(&var) = VT_BSTR;
1292 V_BSTR(&var) = SysAllocString( szstr2 );
1293 r = IXMLDOMElement_setAttribute( element, name, var );
1294 ok( r == S_OK, "returns %08x\n", r );
1295 r = IXMLDOMElement_get_attributes( element, &attr_map );
1296 ok( r == S_OK, "returns %08x\n", r );
1297 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1298 ok( r == S_OK, "returns %08x\n", r );
1299 ok( num == 1, "num %ld\n", num );
1300 IXMLDOMNamedNodeMap_Release( attr_map );
1302 r = IXMLDOMElement_getAttribute( element, name, &var );
1303 ok( r == S_OK, "returns %08x\n", r );
1304 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1306 SysFreeString(name);
1308 V_VT(&var) = VT_BSTR;
1309 V_BSTR(&var) = SysAllocString( szstr1 );
1310 name = SysAllocString( szlc );
1311 r = IXMLDOMElement_setAttribute( element, name, var );
1312 ok( r == S_OK, "returns %08x\n", r );
1313 r = IXMLDOMElement_get_attributes( element, &attr_map );
1314 ok( r == S_OK, "returns %08x\n", r );
1315 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1316 ok( r == S_OK, "returns %08x\n", r );
1317 ok( num == 2, "num %ld\n", num );
1318 IXMLDOMNamedNodeMap_Release( attr_map );
1320 SysFreeString(name);
1324 name = SysAllocString( szbs );
1325 r = IXMLDOMElement_setAttribute( element, name, var );
1326 ok( r == S_OK, "returns %08x\n", r );
1328 r = IXMLDOMElement_getAttribute( element, name, &var );
1329 ok( r == S_OK, "returns %08x\n", r );
1330 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1332 SysFreeString(name);
1334 IXMLDOMElement_Release( element );
1335 IXMLDOMNode_Release( root );
1336 IXMLDOMDocument_Release( doc );
1339 static void test_getElementsByTagName(void)
1344 IXMLDOMDocument *doc;
1345 IXMLDOMNodeList *node_list;
1348 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1349 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1353 str = SysAllocString( szComplete4 );
1354 r = IXMLDOMDocument_loadXML( doc, str, &b );
1355 ok( r == S_OK, "loadXML failed\n");
1356 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1357 SysFreeString( str );
1359 str = SysAllocString( szstar );
1360 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1361 ok( r == S_OK, "ret %08x\n", r );
1362 r = IXMLDOMNodeList_get_length( node_list, &len );
1363 ok( r == S_OK, "ret %08x\n", r );
1364 ok( len == 6, "len %ld\n", len );
1365 IXMLDOMNodeList_Release( node_list );
1366 SysFreeString( str );
1368 str = SysAllocString( szbs );
1369 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1370 ok( r == S_OK, "ret %08x\n", r );
1371 r = IXMLDOMNodeList_get_length( node_list, &len );
1372 ok( r == S_OK, "ret %08x\n", r );
1373 ok( len == 1, "len %ld\n", len );
1374 IXMLDOMNodeList_Release( node_list );
1375 SysFreeString( str );
1377 str = SysAllocString( szdl );
1378 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1379 ok( r == S_OK, "ret %08x\n", r );
1380 r = IXMLDOMNodeList_get_length( node_list, &len );
1381 ok( r == S_OK, "ret %08x\n", r );
1382 ok( len == 0, "len %ld\n", len );
1383 IXMLDOMNodeList_Release( node_list );
1384 SysFreeString( str );
1386 str = SysAllocString( szstr1 );
1387 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1388 ok( r == S_OK, "ret %08x\n", r );
1389 r = IXMLDOMNodeList_get_length( node_list, &len );
1390 ok( r == S_OK, "ret %08x\n", r );
1391 ok( len == 0, "len %ld\n", len );
1392 IXMLDOMNodeList_Release( node_list );
1393 SysFreeString( str );
1395 IXMLDOMDocument_Release( doc );
1398 static void test_get_text(void)
1403 IXMLDOMDocument *doc;
1404 IXMLDOMNode *node, *node2, *node3;
1405 IXMLDOMNodeList *node_list;
1406 IXMLDOMNamedNodeMap *node_map;
1408 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1409 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1413 str = SysAllocString( szComplete4 );
1414 r = IXMLDOMDocument_loadXML( doc, str, &b );
1415 ok( r == S_OK, "loadXML failed\n");
1416 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1417 SysFreeString( str );
1419 str = SysAllocString( szbs );
1420 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1421 ok( r == S_OK, "ret %08x\n", r );
1424 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1425 ok( r == S_OK, "ret %08x\n", r );
1426 IXMLDOMNodeList_Release( node_list );
1428 /* Invalid output parameter*/
1429 r = IXMLDOMNode_get_text( node, NULL );
1430 ok( r == E_INVALIDARG, "ret %08x\n", r );
1432 r = IXMLDOMNode_get_text( node, &str );
1433 ok( r == S_OK, "ret %08x\n", r );
1435 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
1437 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
1440 r = IXMLDOMNode_get_attributes( node, &node_map );
1441 ok( r == S_OK, "ret %08x\n", r );
1443 str = SysAllocString( szvr );
1444 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1445 ok( r == S_OK, "ret %08x\n", r );
1448 r = IXMLDOMNode_get_text( node2, &str );
1449 ok( r == S_OK, "ret %08x\n", r );
1450 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1453 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1454 ok( r == S_OK, "ret %08x\n", r );
1456 r = IXMLDOMNode_get_text( node3, &str );
1457 ok( r == S_OK, "ret %08x\n", r );
1458 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1462 IXMLDOMNode_Release( node3 );
1463 IXMLDOMNode_Release( node2 );
1464 IXMLDOMNamedNodeMap_Release( node_map );
1465 IXMLDOMNode_Release( node );
1466 IXMLDOMDocument_Release( doc );
1469 static void test_get_childNodes(void)
1474 IXMLDOMDocument *doc;
1475 IXMLDOMElement *element;
1476 IXMLDOMNode *node, *node2;
1477 IXMLDOMNodeList *node_list, *node_list2;
1480 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1481 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1485 str = SysAllocString( szComplete4 );
1486 r = IXMLDOMDocument_loadXML( doc, str, &b );
1487 ok( r == S_OK, "loadXML failed\n");
1488 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1489 SysFreeString( str );
1491 r = IXMLDOMDocument_get_documentElement( doc, &element );
1492 ok( r == S_OK, "ret %08x\n", r);
1494 r = IXMLDOMElement_get_childNodes( element, &node_list );
1495 ok( r == S_OK, "ret %08x\n", r);
1497 r = IXMLDOMNodeList_get_length( node_list, &len );
1498 ok( r == S_OK, "ret %08x\n", r);
1499 ok( len == 4, "len %ld\n", len);
1501 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1502 ok( r == S_OK, "ret %08x\n", r);
1504 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1505 ok( r == S_OK, "ret %08x\n", r);
1507 r = IXMLDOMNodeList_get_length( node_list2, &len );
1508 ok( r == S_OK, "ret %08x\n", r);
1509 ok( len == 0, "len %ld\n", len);
1511 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1512 ok( r == S_FALSE, "ret %08x\n", r);
1514 IXMLDOMNodeList_Release( node_list2 );
1515 IXMLDOMNode_Release( node );
1516 IXMLDOMNodeList_Release( node_list );
1517 IXMLDOMElement_Release( element );
1518 IXMLDOMDocument_Release( doc );
1521 static void test_removeChild(void)
1526 IXMLDOMDocument *doc;
1527 IXMLDOMElement *element;
1528 IXMLDOMNode *node, *node2, *node3, *node4;
1529 IXMLDOMNodeList *node_list, *node_list2;
1531 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1532 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1536 str = SysAllocString( szComplete4 );
1537 r = IXMLDOMDocument_loadXML( doc, str, &b );
1538 ok( r == S_OK, "loadXML failed\n");
1539 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1540 SysFreeString( str );
1542 r = IXMLDOMDocument_get_documentElement( doc, &element );
1543 ok( r == S_OK, "ret %08x\n", r);
1545 r = IXMLDOMElement_get_childNodes( element, &node_list );
1546 ok( r == S_OK, "ret %08x\n", r);
1548 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1549 ok( r == S_OK, "ret %08x\n", r);
1551 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1552 ok( r == S_OK, "ret %08x\n", r);
1554 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1555 ok( r == S_OK, "ret %08x\n", r);
1557 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1558 ok( r == E_INVALIDARG, "ret %08x\n", r );
1560 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1561 ok( r == S_OK, "ret %08x\n", r);
1562 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1564 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1565 ok( r == S_FALSE, "ret %08x\n", r);
1566 ok( node3 == NULL, "%p\n", node3 );
1568 IXMLDOMNode_Release( node2 );
1569 IXMLDOMNode_Release( node4 );
1570 IXMLDOMNodeList_Release( node_list2 );
1571 IXMLDOMNode_Release( node );
1572 IXMLDOMNodeList_Release( node_list );
1573 IXMLDOMElement_Release( element );
1574 IXMLDOMDocument_Release( doc );
1577 static void test_XMLHTTP(void)
1579 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1580 static WCHAR wszPOST[] = {'P','O','S','T',0};
1581 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1582 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1583 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1584 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1585 IXMLHttpRequest *pXMLHttpRequest;
1590 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1591 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1592 (void **)&pXMLHttpRequest);
1594 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1599 VariantInit(&dummy);
1600 V_VT(&dummy) = VT_ERROR;
1601 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1602 VariantInit(&varfalse);
1603 V_VT(&varfalse) = VT_BOOL;
1604 V_BOOL(&varfalse) = VARIANT_FALSE;
1605 V_VT(&varbody) = VT_BSTR;
1606 V_BSTR(&varbody) = SysAllocString(wszBody);
1608 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1609 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1611 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1612 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1613 VariantClear(&varbody);
1615 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1616 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1617 /* the server currently returns "FAILED" because the Content-Type header is
1618 * not what the server expects */
1619 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1620 SysFreeString(bstrResponse);
1623 static void test_IXMLDOMDocument2(void)
1628 IXMLDOMDocument *doc;
1629 IXMLDOMDocument2 *doc2;
1633 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1634 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1638 str = SysAllocString( szComplete4 );
1639 r = IXMLDOMDocument_loadXML( doc, str, &b );
1640 ok( r == S_OK, "loadXML failed\n");
1641 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1642 SysFreeString( str );
1644 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1645 ok( r == S_OK, "ret %08x\n", r );
1646 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1648 /* we will check if the variant got cleared */
1649 ref = IXMLDOMDocument2_AddRef(doc2);
1650 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1651 V_VT(&var) = VT_UNKNOWN;
1652 V_UNKNOWN(&var) = (IUnknown *)doc2;
1655 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1656 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1657 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1660 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1661 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1662 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1665 /* the variant didn't get cleared*/
1666 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1668 /* setProperty tests */
1669 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1670 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1671 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1672 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1673 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1674 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1676 /* contrary to what MSDN calims you can switch back from XPath to XSLPattern */
1677 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1678 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1679 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1681 IXMLDOMDocument2_Release( doc2 );
1682 IXMLDOMDocument_Release( doc );
1686 static void test_XPath(void)
1691 IXMLDOMDocument2 *doc;
1692 IXMLDOMNode *rootNode;
1693 IXMLDOMNode *elem1Node;
1695 IXMLDOMNodeList *list;
1697 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1698 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1702 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1703 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1705 /* switch to XPath */
1706 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1708 /* some simple queries*/
1709 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1710 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1711 ole_check(IXMLDOMNodeList_reset(list));
1712 expect_list_and_release(list, "E2.D1");
1713 if (rootNode == NULL)
1716 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1717 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1719 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1720 expect_list_and_release(list, "E3.E2.E2.D1");
1722 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1723 /* using get_item for query results advances the position */
1724 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1725 expect_node(node, "E2.E2.D1");
1726 IXMLDOMNode_Release(node);
1727 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1728 expect_node(node, "E4.E2.D1");
1729 IXMLDOMNode_Release(node);
1730 ole_check(IXMLDOMNodeList_reset(list));
1731 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1733 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
1734 expect_list_and_release(list, "E2.D1");
1736 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
1737 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
1738 ole_check(IXMLDOMNodeList_reset(list));
1739 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1741 /* select an attribute */
1742 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
1743 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
1745 /* would evaluate to a number */
1746 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
1747 /* would evaluate to a boolean */
1748 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
1749 /* would evaluate to a string */
1750 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
1753 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
1754 expect_list_and_release(list, "");
1755 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
1756 expect_list_and_release(list, "");
1757 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
1758 expect_list_and_release(list, "");
1760 /* foo undeclared in document node */
1761 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1762 /* undeclared in <root> node */
1763 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
1764 /* undeclared in <elem> node */
1765 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
1766 /* but this trick can be used */
1767 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
1768 expect_list_and_release(list, "E3.E4.E2.D1");
1770 /* it has to be declared in SelectionNamespaces */
1771 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1772 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
1774 /* now the namespace can be used */
1775 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
1776 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1777 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
1778 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1779 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
1780 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1781 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
1782 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
1784 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
1785 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1786 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
1788 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1791 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
1792 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1793 if (V_VT(&var) == VT_BSTR)
1794 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
1796 /* extra attributes - same thing*/
1797 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1798 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
1799 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1801 IXMLDOMNode_Release(rootNode);
1802 IXMLDOMNode_Release(elem1Node);
1803 IXMLDOMDocument_Release(doc);
1807 static void test_cloneNode(void )
1809 IXMLDOMDocument *doc = NULL;
1811 IXMLDOMNodeList *pList;
1812 IXMLDOMNamedNodeMap *mapAttr;
1813 long nLength = 0, nLength1 = 0;
1814 long nAttrCnt = 0, nAttrCnt1 = 0;
1816 IXMLDOMNode *node_clone;
1819 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
1821 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1825 str = SysAllocString( szComplete4 );
1826 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
1827 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1833 str = SysAllocString( szSearch);
1834 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
1835 ok( r == S_OK, "ret %08x\n", r );
1836 ok( node != NULL, "node %p\n", node );
1841 IXMLDOMDocument_Release(doc);
1845 /* Check invalid parameter */
1846 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
1847 ok( r == E_INVALIDARG, "ret %08x\n", r );
1850 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
1851 ok( r == S_OK, "ret %08x\n", r );
1852 ok( node_clone != NULL, "node %p\n", node );
1856 IXMLDOMDocument_Release(doc);
1857 IXMLDOMNode_Release(node);
1861 r = IXMLDOMNode_get_childNodes(node, &pList);
1862 ok( r == S_OK, "ret %08x\n", r );
1865 IXMLDOMNodeList_get_length(pList, &nLength);
1866 IXMLDOMNodeList_Release(pList);
1869 r = IXMLDOMNode_get_attributes(node, &mapAttr);
1870 ok( r == S_OK, "ret %08x\n", r );
1873 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
1874 IXMLDOMNamedNodeMap_Release(mapAttr);
1877 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
1878 ok( r == S_OK, "ret %08x\n", r );
1881 IXMLDOMNodeList_get_length(pList, &nLength1);
1882 IXMLDOMNodeList_Release(pList);
1885 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
1886 ok( r == S_OK, "ret %08x\n", r );
1889 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
1890 IXMLDOMNamedNodeMap_Release(mapAttr);
1893 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
1894 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
1895 IXMLDOMNode_Release(node_clone);
1898 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
1899 ok( r == S_OK, "ret %08x\n", r );
1900 ok( node_clone != NULL, "node %p\n", node );
1904 IXMLDOMDocument_Release(doc);
1905 IXMLDOMNode_Release(node);
1909 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
1910 ok( r == S_OK, "ret %08x\n", r );
1913 IXMLDOMNodeList_get_length(pList, &nLength1);
1914 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
1915 IXMLDOMNodeList_Release(pList);
1918 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
1919 ok( r == S_OK, "ret %08x\n", r );
1922 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
1923 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
1924 IXMLDOMNamedNodeMap_Release(mapAttr);
1927 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
1928 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
1929 IXMLDOMNode_Release(node_clone);
1932 IXMLDOMNode_Release(node);
1933 IXMLDOMDocument_Release(doc);
1936 static void test_xmlTypes(void)
1938 IXMLDOMDocument *doc = NULL;
1939 IXMLDOMElement *pRoot;
1941 IXMLDOMComment *pComment;
1942 IXMLDOMElement *pElement;
1943 IXMLDOMAttribute *pAttrubute;
1944 IXMLDOMNamedNodeMap *pAttribs;
1945 IXMLDOMCDATASection *pCDataSec;
1946 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
1947 IXMLDOMDocumentFragment *pDocFrag = NULL;
1948 IXMLDOMEntityReference *pEntityRef = NULL;
1950 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
1953 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1957 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
1958 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1960 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
1961 ok(hr == S_FALSE, "ret %08x\n", hr );
1962 ok(pNextChild == NULL, "pDocChild not NULL\n");
1964 /* test previous Sibling */
1965 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
1966 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1968 pNextChild = (IXMLDOMNode *)0x1;
1969 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
1970 ok(hr == S_FALSE, "ret %08x\n", hr );
1971 ok(pNextChild == NULL, "pNextChild not NULL\n");
1973 /* test get_attributes */
1974 hr = IXMLDOMDocument_get_attributes( doc, NULL );
1975 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
1977 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
1978 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
1979 ok(hr == S_FALSE, "ret %08x\n", hr );
1980 ok( pAttribs == NULL, "pAttribs not NULL\n");
1982 /* test get_dataType */
1983 hr = IXMLDOMDocument_get_dataType(doc, &v);
1984 ok(hr == S_FALSE, "ret %08x\n", hr );
1985 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
1988 /* test nodeTypeString */
1989 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
1990 ok(hr == S_OK, "ret %08x\n", hr );
1991 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
1994 /* test implementation */
1995 hr = IXMLDOMDocument_get_implementation(doc, NULL);
1996 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1998 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
1999 ok(hr == S_OK, "ret %08x\n", hr );
2002 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2003 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2005 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2006 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2008 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2009 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2011 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2012 ok(hr == S_OK, "ret %08x\n", hr );
2013 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2015 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2016 ok(hr == S_OK, "ret %08x\n", hr );
2017 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2019 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2020 ok(hr == S_OK, "ret %08x\n", hr );
2021 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2023 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2024 ok(hr == S_OK, "ret %08x\n", hr );
2025 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2027 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2028 ok(hr == S_OK, "ret %08x\n", hr );
2029 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2031 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2032 ok(hr == S_OK, "ret %08x\n", hr );
2033 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2035 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2036 ok(hr == S_OK, "ret %08x\n", hr );
2037 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2039 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2040 ok(hr == S_OK, "ret %08x\n", hr );
2041 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2043 SysFreeString(sEmpty);
2044 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2049 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2050 ok(hr == S_OK, "ret %08x\n", hr );
2053 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2054 ok(hr == S_OK, "ret %08x\n", hr );
2058 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2059 ok(hr == S_OK, "ret %08x\n", hr );
2062 /* test get_attributes */
2063 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2064 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2066 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2067 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2068 ok(hr == S_FALSE, "ret %08x\n", hr );
2069 ok( pAttribs == NULL, "pAttribs not NULL\n");
2071 /* test nodeTypeString */
2072 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2073 ok(hr == S_OK, "ret %08x\n", hr );
2074 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2077 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2078 ok(hr == S_OK, "ret %08x\n", hr );
2080 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2081 ok(hr == S_OK, "ret %08x\n", hr );
2082 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2085 hr = IXMLDOMComment_get_xml(pComment, &str);
2086 ok(hr == S_OK, "ret %08x\n", hr );
2087 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2090 hr = IXMLDOMComment_get_dataType(pComment, &v);
2091 ok(hr == S_FALSE, "ret %08x\n", hr );
2092 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2095 /* put data Tests */
2096 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2097 ok(hr == S_OK, "ret %08x\n", hr );
2099 /* Confirm XML text is good */
2100 hr = IXMLDOMComment_get_xml(pComment, &str);
2101 ok(hr == S_OK, "ret %08x\n", hr );
2102 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2105 /* Confirm we get the put_data Text back */
2106 hr = IXMLDOMComment_get_text(pComment, &str);
2107 ok(hr == S_OK, "ret %08x\n", hr );
2108 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2111 IXMLDOMComment_Release(pComment);
2115 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2116 ok(hr == S_OK, "ret %08x\n", hr );
2119 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2120 ok(hr == S_OK, "ret %08x\n", hr );
2122 /* test nodeTypeString */
2123 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2124 ok(hr == S_OK, "ret %08x\n", hr );
2125 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2128 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2129 ok(hr == S_OK, "ret %08x\n", hr );
2130 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2133 hr = IXMLDOMElement_get_xml(pElement, &str);
2134 ok(hr == S_OK, "ret %08x\n", hr );
2135 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2138 hr = IXMLDOMElement_get_dataType(pElement, &v);
2139 ok(hr == S_FALSE, "ret %08x\n", hr );
2140 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2144 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2145 ok(hr == S_OK, "ret %08x\n", hr );
2148 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2150 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2151 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2153 pNextChild = (IXMLDOMNode *)0x1;
2154 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2155 ok(hr == S_FALSE, "ret %08x\n", hr );
2156 ok(pNextChild == NULL, "pNextChild not NULL\n");
2158 /* test Previous Sibling*/
2159 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2160 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2162 pNextChild = (IXMLDOMNode *)0x1;
2163 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2164 ok(hr == S_FALSE, "ret %08x\n", hr );
2165 ok(pNextChild == NULL, "pNextChild not NULL\n");
2167 /* test get_attributes */
2168 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2169 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2171 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2172 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2173 ok(hr == S_FALSE, "ret %08x\n", hr );
2174 ok( pAttribs == NULL, "pAttribs not NULL\n");
2176 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2177 ok(hr == E_FAIL, "ret %08x\n", hr );
2178 ok(pNewChild == NULL, "pNewChild not NULL\n");
2180 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2181 ok(hr == S_OK, "ret %08x\n", hr );
2184 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2185 ok(hr == S_OK, "ret %08x\n", hr );
2187 IXMLDOMNamedNodeMap_Release(pAttribs);
2190 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2191 ok(hr == S_OK, "ret %08x\n", hr );
2192 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2195 /* test nodeTypeString */
2196 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2197 ok(hr == S_OK, "ret %08x\n", hr );
2198 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2202 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2203 ok(hr == S_OK, "ret %08x\n", hr );
2204 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
2207 /* test name property */
2208 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
2209 ok(hr == S_OK, "ret %08x\n", hr );
2210 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
2213 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2214 ok(hr == S_OK, "ret %08x\n", hr );
2215 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2218 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2219 ok(hr == S_FALSE, "ret %08x\n", hr );
2220 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2223 IXMLDOMAttribute_Release(pAttrubute);
2225 /* Check Element again with the Add Attribute*/
2226 hr = IXMLDOMElement_get_xml(pElement, &str);
2227 ok(hr == S_OK, "ret %08x\n", hr );
2228 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2232 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2233 ok(hr == S_OK, "ret %08x\n", hr );
2235 hr = IXMLDOMElement_get_xml(pElement, &str);
2236 ok(hr == S_OK, "ret %08x\n", hr );
2237 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2239 IXMLDOMElement_Release(pElement);
2243 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2244 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2246 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2247 ok(hr == S_OK, "ret %08x\n", hr );
2250 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2252 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2253 ok(hr == S_OK, "ret %08x\n", hr );
2255 /* get Attribute Tests */
2256 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2257 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2259 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2260 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2261 ok(hr == S_FALSE, "ret %08x\n", hr );
2262 ok(pAttribs == NULL, "pAttribs != NULL\n");
2264 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2265 ok(hr == S_OK, "ret %08x\n", hr );
2266 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2269 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2270 ok(hr == S_OK, "ret %08x\n", hr );
2271 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2274 /* test lastChild */
2275 pNextChild = (IXMLDOMNode*)0x1;
2276 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2277 ok(hr == S_FALSE, "ret %08x\n", hr );
2278 ok(pNextChild == NULL, "pNextChild not NULL\n");
2280 /* test get_dataType */
2281 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2282 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2284 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2285 ok(hr == S_FALSE, "ret %08x\n", hr );
2286 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2289 /* test nodeTypeString */
2290 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2291 ok(hr == S_OK, "ret %08x\n", hr );
2292 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2295 /* put data Tests */
2296 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
2297 ok(hr == S_OK, "ret %08x\n", hr );
2299 /* Confirm XML text is good */
2300 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2301 ok(hr == S_OK, "ret %08x\n", hr );
2302 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
2305 /* Confirm we get the put_data Text back */
2306 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2307 ok(hr == S_OK, "ret %08x\n", hr );
2308 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2311 IXMLDOMCDATASection_Release(pCDataSec);
2314 /* Document Fragments */
2315 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
2316 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2318 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
2319 ok(hr == S_OK, "ret %08x\n", hr );
2322 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2324 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
2325 ok(hr == S_OK, "ret %08x\n", hr );
2327 /* get Attribute Tests */
2328 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
2329 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2331 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2332 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
2333 ok(hr == S_FALSE, "ret %08x\n", hr );
2334 ok(pAttribs == NULL, "pAttribs != NULL\n");
2336 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
2337 ok(hr == S_OK, "ret %08x\n", hr );
2338 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
2341 /* test next Sibling*/
2342 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
2343 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2345 pNextChild = (IXMLDOMNode *)0x1;
2346 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
2347 ok(hr == S_FALSE, "ret %08x\n", hr );
2348 ok(pNextChild == NULL, "pNextChild not NULL\n");
2350 /* test Previous Sibling*/
2351 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
2352 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2354 pNextChild = (IXMLDOMNode *)0x1;
2355 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
2356 ok(hr == S_FALSE, "ret %08x\n", hr );
2357 ok(pNextChild == NULL, "pNextChild not NULL\n");
2359 /* test get_dataType */
2360 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
2361 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2363 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
2364 ok(hr == S_FALSE, "ret %08x\n", hr );
2365 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2368 /* test nodeTypeString */
2369 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
2370 ok(hr == S_OK, "ret %08x\n", hr );
2371 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
2374 IXMLDOMDocumentFragment_Release(pCDataSec);
2377 /* Entity References */
2378 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
2379 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2381 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
2382 ok(hr == S_OK, "ret %08x\n", hr );
2385 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
2386 ok(hr == S_OK, "ret %08x\n", hr );
2388 /* get Attribute Tests */
2389 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
2390 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2392 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2393 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
2394 ok(hr == S_FALSE, "ret %08x\n", hr );
2395 ok(pAttribs == NULL, "pAttribs != NULL\n");
2398 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
2399 ok(hr == S_FALSE, "ret %08x\n", hr );
2400 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2403 /* test nodeTypeString */
2404 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
2405 ok(hr == S_OK, "ret %08x\n", hr );
2406 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
2410 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
2411 ok(hr == S_OK, "ret %08x\n", hr );
2412 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
2415 IXMLDOMEntityReference_Release(pEntityRef);
2418 IXMLDOMElement_Release( pRoot );
2422 IXMLDOMDocument_Release(doc);
2427 static void test_nodeTypeTests( void )
2429 IXMLDOMDocument *doc = NULL;
2430 IXMLDOMElement *pRoot;
2431 IXMLDOMElement *pElement;
2434 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2438 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2439 ok(hr == S_OK, "ret %08x\n", hr );
2442 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2443 ok(hr == S_OK, "ret %08x\n", hr );
2446 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
2447 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2450 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
2451 ok(hr == E_FAIL, "ret %08x\n", hr );
2454 * The name passed into put_dataType is case-insensitive. So many of the names
2455 * have been changed to reflect this.
2458 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
2459 ok(hr == S_OK, "ret %08x\n", hr );
2462 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2464 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
2465 ok(hr == S_OK, "ret %08x\n", hr );
2467 IXMLDOMElement_Release(pElement);
2471 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
2472 ok(hr == S_OK, "ret %08x\n", hr );
2475 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2477 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
2478 ok(hr == S_OK, "ret %08x\n", hr );
2480 IXMLDOMElement_Release(pElement);
2484 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
2485 ok(hr == S_OK, "ret %08x\n", hr );
2488 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2490 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
2491 ok(hr == S_OK, "ret %08x\n", hr );
2493 IXMLDOMElement_Release(pElement);
2497 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
2498 ok(hr == S_OK, "ret %08x\n", hr );
2501 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2503 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
2504 ok(hr == S_OK, "ret %08x\n", hr );
2506 IXMLDOMElement_Release(pElement);
2510 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
2511 ok(hr == S_OK, "ret %08x\n", hr );
2514 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2516 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
2517 ok(hr == S_OK, "ret %08x\n", hr );
2519 IXMLDOMElement_Release(pElement);
2523 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
2524 ok(hr == S_OK, "ret %08x\n", hr );
2527 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2529 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
2530 ok(hr == S_OK, "ret %08x\n", hr );
2532 IXMLDOMElement_Release(pElement);
2536 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
2537 ok(hr == S_OK, "ret %08x\n", hr );
2540 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2542 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
2543 ok(hr == S_OK, "ret %08x\n", hr );
2545 IXMLDOMElement_Release(pElement);
2549 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
2550 ok(hr == S_OK, "ret %08x\n", hr );
2553 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2555 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
2556 ok(hr == S_OK, "ret %08x\n", hr );
2558 IXMLDOMElement_Release(pElement);
2562 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
2563 ok(hr == S_OK, "ret %08x\n", hr );
2566 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2568 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
2569 ok(hr == S_OK, "ret %08x\n", hr );
2571 IXMLDOMElement_Release(pElement);
2575 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
2576 ok(hr == S_OK, "ret %08x\n", hr );
2579 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2581 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
2582 ok(hr == S_OK, "ret %08x\n", hr );
2584 IXMLDOMElement_Release(pElement);
2588 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
2589 ok(hr == S_OK, "ret %08x\n", hr );
2592 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2594 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
2595 ok(hr == S_OK, "ret %08x\n", hr );
2597 IXMLDOMElement_Release(pElement);
2601 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_byte"), &pElement);
2602 ok(hr == S_OK, "ret %08x\n", hr );
2605 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2607 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("byte") );
2608 ok(hr == S_OK, "ret %08x\n", hr );
2610 IXMLDOMElement_Release(pElement);
2614 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
2615 ok(hr == S_OK, "ret %08x\n", hr );
2618 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2620 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
2621 ok(hr == S_OK, "ret %08x\n", hr );
2623 IXMLDOMElement_Release(pElement);
2627 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
2628 ok(hr == S_OK, "ret %08x\n", hr );
2631 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2633 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
2634 ok(hr == S_OK, "ret %08x\n", hr );
2636 IXMLDOMElement_Release(pElement);
2640 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
2641 ok(hr == S_OK, "ret %08x\n", hr );
2644 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2646 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
2647 ok(hr == S_OK, "ret %08x\n", hr );
2649 IXMLDOMElement_Release(pElement);
2653 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
2654 ok(hr == S_OK, "ret %08x\n", hr );
2657 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2659 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
2660 ok(hr == S_OK, "ret %08x\n", hr );
2662 IXMLDOMElement_Release(pElement);
2666 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
2667 ok(hr == S_OK, "ret %08x\n", hr );
2670 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2672 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
2673 ok(hr == S_OK, "ret %08x\n", hr );
2675 IXMLDOMElement_Release(pElement);
2679 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
2680 ok(hr == S_OK, "ret %08x\n", hr );
2683 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2685 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
2686 ok(hr == S_OK, "ret %08x\n", hr );
2688 IXMLDOMElement_Release(pElement);
2692 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
2693 ok(hr == S_OK, "ret %08x\n", hr );
2696 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2698 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
2699 ok(hr == S_OK, "ret %08x\n", hr );
2701 IXMLDOMElement_Release(pElement);
2705 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
2706 ok(hr == S_OK, "ret %08x\n", hr );
2709 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2711 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
2712 ok(hr == S_OK, "ret %08x\n", hr );
2714 IXMLDOMElement_Release(pElement);
2718 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
2719 ok(hr == S_OK, "ret %08x\n", hr );
2722 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2724 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
2725 ok(hr == S_OK, "ret %08x\n", hr );
2727 IXMLDOMElement_Release(pElement);
2731 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
2732 ok(hr == S_OK, "ret %08x\n", hr );
2735 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2737 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
2738 ok(hr == S_OK, "ret %08x\n", hr );
2740 IXMLDOMElement_Release(pElement);
2744 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
2745 ok(hr == S_OK, "ret %08x\n", hr );
2748 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2750 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
2751 ok(hr == S_OK, "ret %08x\n", hr );
2753 IXMLDOMElement_Release(pElement);
2756 /* Check changing types */
2757 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
2758 ok(hr == S_OK, "ret %08x\n", hr );
2761 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2763 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
2764 ok(hr == S_OK, "ret %08x\n", hr );
2766 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
2767 ok(hr == S_OK, "ret %08x\n", hr );
2769 IXMLDOMElement_Release(pElement);
2772 IXMLDOMElement_Release(pRoot);
2776 IXMLDOMDocument_Release(doc);
2785 r = CoInitialize( NULL );
2786 ok( r == S_OK, "failed to init com\n");
2792 test_getElementsByTagName();
2794 test_get_childNodes();
2797 test_IXMLDOMDocument2();
2801 test_nodeTypeTests();