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 #define expect_bstr_eq_and_free(bstr, expect) { \
139 BSTR bstrExp = alloc_str_from_narrow(expect); \
140 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
141 SysFreeString(bstr); \
142 SysFreeString(bstrExp); \
145 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
147 #define ole_check(expr) { \
149 ok(r == S_OK, #expr " returned %x\n", r); \
152 #define ole_expect(expr, expect) { \
154 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
157 static BSTR alloc_str_from_narrow(const char *str)
159 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
160 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
161 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
165 BSTR alloced_bstrs[256];
166 int alloced_bstrs_count = 0;
168 static BSTR _bstr_(const char *str)
170 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
171 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
172 return alloced_bstrs[alloced_bstrs_count++];
175 static void free_bstrs()
178 for (i = 0; i < alloced_bstrs_count; i++)
179 SysFreeString(alloced_bstrs[i]);
180 alloced_bstrs_count = 0;
183 static VARIANT _variantbstr_(const char *str)
187 V_BSTR(&v) = _bstr_(str);
191 static void get_str_for_type(DOMNodeType type, char *buf)
205 wsprintfA(buf, "[%d]", type);
209 static int get_node_position(IXMLDOMNode *node)
214 IXMLDOMNode_AddRef(node);
217 IXMLDOMNode *new_node;
220 r = IXMLDOMNode_get_previousSibling(node, &new_node);
221 ok(!FAILED(r), "get_previousSibling failed\n");
222 IXMLDOMNode_Release(node);
228 static void node_to_string(IXMLDOMNode *node, char *buf)
235 lstrcpyA(buf, "(null)");
239 IXMLDOMNode_AddRef(node);
242 IXMLDOMNode *new_node;
244 ole_check(IXMLDOMNode_get_nodeType(node, &type));
245 get_str_for_type(type, buf);
248 if (type == NODE_ATTRIBUTE)
251 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
253 wsprintfA(buf, "%ws", bstr);
258 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
262 int pos = get_node_position(node);
263 DOMNodeType parent_type = NODE_INVALID;
264 r = IXMLDOMNode_get_parentNode(node, &new_node);
266 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
267 * results we "fix" it */
269 ole_check(IXMLDOMNode_get_nodeType(node, &parent_type));
270 /* we need also to workaround the no document node problem - see below */
271 if (((r == S_FALSE && type != NODE_DOCUMENT) || parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
273 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
276 wsprintf(buf, "%d", pos);
280 ok(!FAILED(r), "get_parentNode failed (%08x)\n", r);
281 IXMLDOMNode_Release(node);
287 /* currently we can't access document node in wine. All our examples this is the
288 * root node so to be able to test query results we add it */
289 if (type != NODE_DOCUMENT)
291 todo_wine ok(FALSE, "Document node is not the last returned node!\n");
299 static char *list_to_string(IXMLDOMNodeList *list)
301 static char buf[4096];
308 lstrcpyA(buf, "(null)");
311 ole_check(IXMLDOMNodeList_get_length(list, &len));
312 for (i = 0; i < len; i++)
317 ole_check(IXMLDOMNodeList_nextNode(list, &node));
318 node_to_string(node, pos);
320 IXMLDOMNode_Release(node);
326 #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); }
327 #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); }
329 static void test_domdoc( void )
332 IXMLDOMDocument *doc = NULL;
333 IXMLDOMParseError *error;
334 IXMLDOMElement *element = NULL;
341 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
342 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
346 /* try some stupid things */
347 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
348 ok( r == S_FALSE, "loadXML failed\n");
351 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
352 ok( r == S_FALSE, "loadXML failed\n");
353 ok( b == VARIANT_FALSE, "failed to load XML string\n");
355 /* try to load a document from a nonexistent file */
357 str = SysAllocString( szNonExistentFile );
359 V_VT(&var) = VT_BSTR;
362 r = IXMLDOMDocument_load( doc, var, &b);
363 ok( r == S_FALSE, "load (from file) failed\n");
364 ok( b == VARIANT_FALSE, "failed to load XML file\n");
365 SysFreeString( str );
367 /* try load an empty document */
369 str = SysAllocString( szEmpty );
370 r = IXMLDOMDocument_loadXML( doc, str, &b );
371 ok( r == S_FALSE, "loadXML failed\n");
372 ok( b == VARIANT_FALSE, "failed to load XML string\n");
373 SysFreeString( str );
375 /* check that there's no document element */
377 r = IXMLDOMDocument_get_documentElement( doc, &element );
378 ok( r == S_FALSE, "should be no document element\n");
380 /* try finding a node */
382 str = SysAllocString( szstr1 );
383 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
384 ok( r == S_FALSE, "ret %08x\n", r );
385 SysFreeString( str );
388 str = SysAllocString( szIncomplete );
389 r = IXMLDOMDocument_loadXML( doc, str, &b );
390 ok( r == S_FALSE, "loadXML failed\n");
391 ok( b == VARIANT_FALSE, "failed to load XML string\n");
392 SysFreeString( str );
394 /* check that there's no document element */
395 element = (IXMLDOMElement*)1;
396 r = IXMLDOMDocument_get_documentElement( doc, &element );
397 ok( r == S_FALSE, "should be no document element\n");
398 ok( element == NULL, "Element should be NULL\n");
400 /* try to load something valid */
402 str = SysAllocString( szComplete1 );
403 r = IXMLDOMDocument_loadXML( doc, str, &b );
404 ok( r == S_OK, "loadXML failed\n");
405 ok( b == VARIANT_TRUE, "failed to load XML string\n");
406 SysFreeString( str );
408 /* try with a null out pointer - crashes */
411 r = IXMLDOMDocument_get_documentElement( doc, NULL );
412 ok( r == S_OK, "should be no document element\n");
415 /* check if nodename is correct */
416 r = IXMLDOMDocument_get_nodeName( doc, NULL );
417 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
419 /* content doesn't matter here */
420 str = SysAllocString( szNonExistentFile );
421 r = IXMLDOMDocument_get_nodeName( doc, &str );
422 ok ( r == S_OK, "get_nodeName wrong code\n");
423 ok ( str != NULL, "str is null\n");
424 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
425 SysFreeString( str );
428 /* check that there's a document element */
430 r = IXMLDOMDocument_get_documentElement( doc, &element );
431 ok( r == S_OK, "should be a document element\n");
436 /* check if the tag is correct */
437 r = IXMLDOMElement_get_tagName( element, &tag );
438 ok( r == S_OK, "couldn't get tag name\n");
439 ok( tag != NULL, "tag was null\n");
440 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
441 SysFreeString( tag );
443 /* figure out what happens if we try to reload the document */
444 str = SysAllocString( szComplete2 );
445 r = IXMLDOMDocument_loadXML( doc, str, &b );
446 ok( r == S_OK, "loadXML failed\n");
447 ok( b == VARIANT_TRUE, "failed to load XML string\n");
448 SysFreeString( str );
450 /* check if the tag is still correct */
452 r = IXMLDOMElement_get_tagName( element, &tag );
453 ok( r == S_OK, "couldn't get tag name\n");
454 ok( tag != NULL, "tag was null\n");
455 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
456 SysFreeString( tag );
458 IXMLDOMElement_Release( element );
462 /* as soon as we call loadXML again, the document element will disappear */
464 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
465 ok( r == S_FALSE, "loadXML failed\n");
466 ok( b == 2, "variant modified\n");
467 r = IXMLDOMDocument_get_documentElement( doc, &element );
468 ok( r == S_FALSE, "should be no document element\n");
470 /* try to load something else simple and valid */
472 str = SysAllocString( szComplete3 );
473 r = IXMLDOMDocument_loadXML( doc, str, &b );
474 ok( r == S_OK, "loadXML failed\n");
475 ok( b == VARIANT_TRUE, "failed to load XML string\n");
476 SysFreeString( str );
478 /* try something a little more complicated */
480 str = SysAllocString( szComplete4 );
481 r = IXMLDOMDocument_loadXML( doc, str, &b );
482 ok( r == S_OK, "loadXML failed\n");
483 ok( b == VARIANT_TRUE, "failed to load XML string\n");
484 SysFreeString( str );
486 r = IXMLDOMDocument_get_parseError( doc, &error );
487 ok( r == S_OK, "returns %08x\n", r );
489 r = IXMLDOMParseError_get_errorCode( error, &code );
490 ok( r == S_FALSE, "returns %08x\n", r );
491 ok( code == 0, "code %ld\n", code );
492 IXMLDOMParseError_Release( error );
494 r = IXMLDOMDocument_Release( doc );
495 ok( r == 0, "document ref count incorrect\n");
499 static void test_domnode( void )
502 IXMLDOMDocument *doc = NULL, *owner = NULL;
503 IXMLDOMElement *element = NULL;
504 IXMLDOMNamedNodeMap *map = NULL;
505 IXMLDOMNode *node = NULL, *next = NULL;
506 IXMLDOMNodeList *list = NULL;
507 DOMNodeType type = NODE_INVALID;
513 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
514 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
519 str = SysAllocString( szComplete4 );
520 r = IXMLDOMDocument_loadXML( doc, str, &b );
521 ok( r == S_OK, "loadXML failed\n");
522 ok( b == VARIANT_TRUE, "failed to load XML string\n");
523 SysFreeString( str );
528 r = IXMLDOMNode_hasChildNodes( doc, &b );
529 ok( r == S_OK, "hasChildNoes bad return\n");
530 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
532 r = IXMLDOMDocument_get_documentElement( doc, &element );
533 ok( r == S_OK, "should be a document element\n");
534 ok( element != NULL, "should be an element\n");
537 ok( FALSE, "no document\n");
540 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
541 r = IXMLDOMNode_get_nodeValue( doc, &var );
542 ok( r == S_FALSE, "nextNode returned wrong code\n");
543 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
544 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
549 r = IXMLDOMNode_get_ownerDocument( element, &owner );
551 ok( r == S_OK, "get_ownerDocument return code\n");
553 ok( owner != doc, "get_ownerDocument return\n");
556 r = IXMLDOMNode_get_nodeType( element, &type);
557 ok( r == S_OK, "getNamedItem returned wrong code\n");
558 ok( type == NODE_ELEMENT, "node not an element\n");
561 r = IXMLDOMNode_get_baseName( element, &str );
562 ok( r == S_OK, "get_baseName returned wrong code\n");
563 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
565 /* check if nodename is correct */
566 r = IXMLDOMElement_get_nodeName( element, NULL );
567 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
569 /* content doesn't matter here */
570 str = SysAllocString( szNonExistentFile );
571 r = IXMLDOMElement_get_nodeName( element, &str );
572 ok ( r == S_OK, "get_nodeName wrong code\n");
573 ok ( str != NULL, "str is null\n");
574 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
575 SysFreeString( str );
577 str = SysAllocString( szNonExistentFile );
580 r = IXMLDOMElement_getAttribute( element, str, &var );
581 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
582 ok( V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
584 SysFreeString( str );
586 str = SysAllocString( szdl );
589 r = IXMLDOMElement_getAttribute( element, str, &var );
590 ok( r == S_OK, "getAttribute ret %08x\n", r );
591 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
592 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
593 VariantClear( &var );
594 SysFreeString( str );
596 r = IXMLDOMElement_get_attributes( element, &map );
597 ok( r == S_OK, "get_attributes returned wrong code\n");
598 ok( map != NULL, "should be attributes\n");
601 r = IXMLDOMNode_hasChildNodes( element, &b );
602 ok( r == S_OK, "hasChildNoes bad return\n");
603 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
606 ok( FALSE, "no element\n");
610 ISupportErrorInfo *support_error;
611 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
612 ok( r == S_OK, "ret %08x\n", r );
614 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
617 ok( r == S_OK, "ret %08x\n", r );
619 ISupportErrorInfo_Release( support_error );
621 str = SysAllocString( szdl );
622 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
623 ok( r == S_OK, "getNamedItem returned wrong code\n");
624 ok( node != NULL, "should be attributes\n");
625 IXMLDOMNode_Release(node);
626 SysFreeString( str );
628 str = SysAllocString( szdl );
629 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
630 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
631 SysFreeString( str );
633 /* something that isn't in szComplete4 */
634 str = SysAllocString( szOpen );
635 node = (IXMLDOMNode *) 1;
636 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
637 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
638 ok( node == NULL, "getNamedItem should have returned NULL\n");
639 SysFreeString( str );
641 /* test indexed access of attributes */
642 r = IXMLDOMNamedNodeMap_get_length( map, &count );
643 ok ( r == S_OK, "get_length wrong code\n");
644 ok ( count == 1, "get_length != 1\n");
647 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
648 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
649 ok ( node == NULL, "there is no node\n");
652 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
653 ok ( r == S_FALSE, "get_item (1) wrong code\n");
654 ok ( node == NULL, "there is no attribute\n");
657 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
658 ok ( r == S_OK, "get_item (0) wrong code\n");
659 ok ( node != NULL, "should be attribute\n");
661 r = IXMLDOMNode_get_nodeName( node, NULL );
662 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
664 /* content doesn't matter here */
665 str = SysAllocString( szNonExistentFile );
666 r = IXMLDOMNode_get_nodeName( node, &str );
667 ok ( r == S_OK, "get_nodeName wrong code\n");
668 ok ( str != NULL, "str is null\n");
669 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
670 SysFreeString( str );
672 /* test sequential access of attributes */
674 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
675 ok ( r == S_OK, "nextNode (first time) wrong code\n");
676 ok ( node != NULL, "nextNode, should be attribute\n");
678 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
679 ok ( r != S_OK, "nextNode (second time) wrong code\n");
680 ok ( node == NULL, "nextNode, there is no attribute\n");
682 r = IXMLDOMNamedNodeMap_reset( map );
683 ok ( r == S_OK, "reset should return S_OK\n");
685 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
686 ok ( r == S_OK, "nextNode (third time) wrong code\n");
687 ok ( node != NULL, "nextNode, should be attribute\n");
690 ok( FALSE, "no map\n");
695 r = IXMLDOMNode_get_nodeType( node, &type);
696 ok( r == S_OK, "getNamedItem returned wrong code\n");
697 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
700 r = IXMLDOMNode_get_baseName( node, NULL );
701 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
704 r = IXMLDOMNode_get_baseName( node, &str );
705 ok( r == S_OK, "get_baseName returned wrong code\n");
706 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
708 r = IXMLDOMNode_get_nodeValue( node, &var );
709 ok( r == S_OK, "returns %08x\n", r );
710 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
711 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
714 r = IXMLDOMNode_get_childNodes( node, NULL );
715 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
717 r = IXMLDOMNode_get_childNodes( node, &list );
718 ok( r == S_OK, "get_childNodes returned wrong code\n");
722 r = IXMLDOMNodeList_nextNode( list, &next );
723 ok( r == S_OK, "nextNode returned wrong code\n");
726 ok( FALSE, "no childlist\n");
731 r = IXMLDOMNode_hasChildNodes( next, &b );
732 ok( r == S_FALSE, "hasChildNoes bad return\n");
733 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
736 r = IXMLDOMNode_get_nodeType( next, &type);
737 ok( r == S_OK, "getNamedItem returned wrong code\n");
738 ok( type == NODE_TEXT, "node not text\n");
741 r = IXMLDOMNode_get_baseName( next, &str );
742 ok( r == S_FALSE, "get_baseName returned wrong code\n");
743 ok( str == NULL, "basename was wrong\n");
746 ok( FALSE, "no next\n");
749 IXMLDOMNode_Release( next );
752 IXMLDOMNodeList_Release( list );
755 IXMLDOMNode_Release( node );
758 ok( FALSE, "no node\n");
762 IXMLDOMNamedNodeMap_Release( map );
764 /* now traverse the tree from the root element */
768 r = IXMLDOMNode_get_childNodes( element, &list );
769 ok( r == S_OK, "get_childNodes returned wrong code\n");
771 /* using get_item for child list doesn't advance the position */
772 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
773 expect_node(node, "E2.E2.D1");
774 IXMLDOMNode_Release(node);
775 ole_check(IXMLDOMNodeList_nextNode(list, &node));
776 expect_node(node, "E1.E2.D1");
777 IXMLDOMNode_Release(node);
778 ole_check(IXMLDOMNodeList_reset(list));
780 IXMLDOMNodeList_AddRef(list);
781 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
782 ole_check(IXMLDOMNodeList_reset(list));
785 ok( FALSE, "no element\n");
787 node = (void*)0xdeadbeef;
788 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
789 ok( r == S_FALSE, "ret %08x\n", r );
790 ok( node == NULL, "node %p\n", node );
791 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
792 ok( r == S_OK, "ret %08x\n", r );
793 r = IXMLDOMNode_Release( node );
794 ok( r == 0, "ret %08x\n", r );
798 r = IXMLDOMNodeList_get_length( list, &count );
799 ok( r == S_OK, "get_length returns %08x\n", r );
800 ok( count == 4, "get_length got %ld\n", count );
802 r = IXMLDOMNodeList_nextNode( list, &node );
803 ok( r == S_OK, "nextNode returned wrong code\n");
806 ok( FALSE, "no list\n");
811 r = IXMLDOMNode_get_nodeType( node, &type);
812 ok( r == S_OK, "getNamedItem returned wrong code\n");
813 ok( type == NODE_ELEMENT, "node not text\n");
816 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
817 r = IXMLDOMNode_get_nodeValue( node, &var );
818 ok( r == S_FALSE, "nextNode returned wrong code\n");
819 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
820 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
822 r = IXMLDOMNode_hasChildNodes( node, NULL );
823 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
826 r = IXMLDOMNode_hasChildNodes( node, &b );
827 ok( r == S_OK, "hasChildNoes bad return\n");
828 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
831 r = IXMLDOMNode_get_baseName( node, &str );
832 ok( r == S_OK, "get_baseName returned wrong code\n");
833 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
836 ok( FALSE, "no node\n");
839 IXMLDOMNode_Release( node );
841 IXMLDOMNodeList_Release( list );
843 IXMLDOMElement_Release( element );
846 str = SysAllocString( szComplete5 );
847 r = IXMLDOMDocument_loadXML( doc, str, &b );
848 ok( r == S_OK, "loadXML failed\n");
849 ok( b == VARIANT_TRUE, "failed to load XML string\n");
850 SysFreeString( str );
853 r = IXMLDOMNode_hasChildNodes( doc, &b );
854 ok( r == S_OK, "hasChildNoes bad return\n");
855 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
857 r = IXMLDOMDocument_get_documentElement( doc, &element );
858 ok( r == S_OK, "should be a document element\n");
859 ok( element != NULL, "should be an element\n");
863 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
866 /* check if the tag is correct */
867 r = IXMLDOMElement_get_tagName( element, &tag );
868 ok( r == S_OK, "couldn't get tag name\n");
869 ok( tag != NULL, "tag was null\n");
870 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
871 SysFreeString( tag );
875 IXMLDOMElement_Release( element );
877 IXMLDOMDocument_Release( doc );
880 static void test_refs(void)
885 IXMLDOMDocument *doc = NULL;
886 IXMLDOMElement *element = NULL;
887 IXMLDOMNode *node = NULL, *node2;
888 IXMLDOMNodeList *node_list = NULL;
890 IUnknown *unk, *unk2;
892 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
893 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
896 ref = IXMLDOMDocument_Release(doc);
897 ok( ref == 0, "ref %d\n", ref);
899 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
900 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
904 str = SysAllocString( szComplete4 );
905 r = IXMLDOMDocument_loadXML( doc, str, &b );
906 ok( r == S_OK, "loadXML failed\n");
907 ok( b == VARIANT_TRUE, "failed to load XML string\n");
908 SysFreeString( str );
910 ref = IXMLDOMDocument_AddRef( doc );
911 ok( ref == 2, "ref %d\n", ref );
912 ref = IXMLDOMDocument_AddRef( doc );
913 ok( ref == 3, "ref %d\n", ref );
914 IXMLDOMDocument_Release( doc );
915 IXMLDOMDocument_Release( doc );
917 r = IXMLDOMDocument_get_documentElement( doc, &element );
918 ok( r == S_OK, "should be a document element\n");
919 ok( element != NULL, "should be an element\n");
921 ref = IXMLDOMDocument_AddRef( doc );
922 ok( ref == 2, "ref %d\n", ref );
923 IXMLDOMDocument_Release( doc );
925 r = IXMLDOMElement_get_childNodes( element, &node_list );
926 ok( r == S_OK, "rets %08x\n", r);
927 ref = IXMLDOMNodeList_AddRef( node_list );
928 ok( ref == 2, "ref %d\n", ref );
929 IXMLDOMNodeList_Release( node_list );
931 IXMLDOMNodeList_get_item( node_list, 0, &node );
932 ok( r == S_OK, "rets %08x\n", r);
934 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
935 ok( r == S_OK, "rets %08x\n", r);
937 ref = IXMLDOMNode_AddRef( node );
938 ok( ref == 2, "ref %d\n", ref );
939 IXMLDOMNode_Release( node );
941 ref = IXMLDOMNode_Release( node );
942 ok( ref == 0, "ref %d\n", ref );
943 ref = IXMLDOMNode_Release( node2 );
944 ok( ref == 0, "ref %d\n", ref );
946 ref = IXMLDOMNodeList_Release( node_list );
947 ok( ref == 0, "ref %d\n", ref );
949 ok( node != node2, "node %p node2 %p\n", node, node2 );
951 ref = IXMLDOMDocument_Release( doc );
952 ok( ref == 0, "ref %d\n", ref );
954 ref = IXMLDOMElement_AddRef( element );
956 ok( ref == 3, "ref %d\n", ref );
958 IXMLDOMElement_Release( element );
960 /* IUnknown must be unique however we obtain it */
961 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
962 ok( r == S_OK, "rets %08x\n", r );
963 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
964 ok( r == S_OK, "rets %08x\n", r );
965 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
966 ok( r == S_OK, "rets %08x\n", r );
967 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
969 IUnknown_Release( unk2 );
970 IUnknown_Release( unk );
971 IXMLDOMNode_Release( node );
973 IXMLDOMElement_Release( element );
977 static void test_create(void)
982 IXMLDOMDocument *doc;
983 IXMLDOMElement *element;
984 IXMLDOMNode *root, *node, *child;
985 IXMLDOMNamedNodeMap *attr_map;
990 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
991 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
996 V_I4(&var) = NODE_ELEMENT;
997 str = SysAllocString( szlc );
998 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
999 ok( r == S_OK, "returns %08x\n", r );
1000 r = IXMLDOMDocument_appendChild( doc, node, &root );
1001 ok( r == S_OK, "returns %08x\n", r );
1002 ok( node == root, "%p %p\n", node, root );
1004 ref = IXMLDOMNode_AddRef( node );
1005 ok(ref == 3, "ref %d\n", ref);
1006 IXMLDOMNode_Release( node );
1008 ref = IXMLDOMNode_Release( node );
1009 ok(ref == 1, "ref %d\n", ref);
1010 SysFreeString( str );
1013 V_I4(&var) = NODE_ELEMENT;
1014 str = SysAllocString( szbs );
1015 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1016 ok( r == S_OK, "returns %08x\n", r );
1018 ref = IXMLDOMNode_AddRef( node );
1019 ok(ref == 2, "ref = %d\n", ref);
1020 IXMLDOMNode_Release( node );
1022 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1023 ok( r == S_OK, "returns %08x\n", r );
1025 ref = IXMLDOMNode_AddRef( unk );
1026 ok(ref == 3, "ref = %d\n", ref);
1027 IXMLDOMNode_Release( unk );
1029 V_VT(&var) = VT_EMPTY;
1030 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1031 ok( r == S_OK, "returns %08x\n", r );
1032 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1033 IXMLDOMNode_Release( child );
1034 IUnknown_Release( unk );
1037 V_VT(&var) = VT_NULL;
1038 V_DISPATCH(&var) = (IDispatch*)node;
1039 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1040 ok( r == S_OK, "returns %08x\n", r );
1041 ok( node == child, "%p %p\n", node, child );
1042 IXMLDOMNode_Release( child );
1043 IXMLDOMNode_Release( node );
1046 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1047 ok( r == S_OK, "returns %08x\n", r );
1049 r = IXMLDOMElement_get_attributes( element, &attr_map );
1050 ok( r == S_OK, "returns %08x\n", r );
1051 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1052 ok( r == S_OK, "returns %08x\n", r );
1053 ok( num == 0, "num %ld\n", num );
1054 IXMLDOMNamedNodeMap_Release( attr_map );
1056 V_VT(&var) = VT_BSTR;
1057 V_BSTR(&var) = SysAllocString( szstr1 );
1058 name = SysAllocString( szdl );
1059 r = IXMLDOMElement_setAttribute( element, name, var );
1060 ok( r == S_OK, "returns %08x\n", r );
1061 r = IXMLDOMElement_get_attributes( element, &attr_map );
1062 ok( r == S_OK, "returns %08x\n", r );
1063 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1064 ok( r == S_OK, "returns %08x\n", r );
1065 ok( num == 1, "num %ld\n", num );
1066 IXMLDOMNamedNodeMap_Release( attr_map );
1069 V_VT(&var) = VT_BSTR;
1070 V_BSTR(&var) = SysAllocString( szstr2 );
1071 r = IXMLDOMElement_setAttribute( element, name, var );
1072 ok( r == S_OK, "returns %08x\n", r );
1073 r = IXMLDOMElement_get_attributes( element, &attr_map );
1074 ok( r == S_OK, "returns %08x\n", r );
1075 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1076 ok( r == S_OK, "returns %08x\n", r );
1077 ok( num == 1, "num %ld\n", num );
1078 IXMLDOMNamedNodeMap_Release( attr_map );
1080 r = IXMLDOMElement_getAttribute( element, name, &var );
1081 ok( r == S_OK, "returns %08x\n", r );
1082 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1084 SysFreeString(name);
1086 V_VT(&var) = VT_BSTR;
1087 V_BSTR(&var) = SysAllocString( szstr1 );
1088 name = SysAllocString( szlc );
1089 r = IXMLDOMElement_setAttribute( element, name, var );
1090 ok( r == S_OK, "returns %08x\n", r );
1091 r = IXMLDOMElement_get_attributes( element, &attr_map );
1092 ok( r == S_OK, "returns %08x\n", r );
1093 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1094 ok( r == S_OK, "returns %08x\n", r );
1095 ok( num == 2, "num %ld\n", num );
1096 IXMLDOMNamedNodeMap_Release( attr_map );
1098 SysFreeString(name);
1102 name = SysAllocString( szbs );
1103 r = IXMLDOMElement_setAttribute( element, name, var );
1104 ok( r == S_OK, "returns %08x\n", r );
1106 r = IXMLDOMElement_getAttribute( element, name, &var );
1107 ok( r == S_OK, "returns %08x\n", r );
1108 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1110 SysFreeString(name);
1112 IXMLDOMElement_Release( element );
1113 IXMLDOMNode_Release( root );
1114 IXMLDOMDocument_Release( doc );
1117 static void test_getElementsByTagName(void)
1122 IXMLDOMDocument *doc;
1123 IXMLDOMNodeList *node_list;
1126 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1127 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1131 str = SysAllocString( szComplete4 );
1132 r = IXMLDOMDocument_loadXML( doc, str, &b );
1133 ok( r == S_OK, "loadXML failed\n");
1134 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1135 SysFreeString( str );
1137 str = SysAllocString( szstar );
1138 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1139 ok( r == S_OK, "ret %08x\n", r );
1140 r = IXMLDOMNodeList_get_length( node_list, &len );
1141 ok( r == S_OK, "ret %08x\n", r );
1142 ok( len == 6, "len %ld\n", len );
1143 IXMLDOMNodeList_Release( node_list );
1144 SysFreeString( str );
1146 str = SysAllocString( szbs );
1147 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1148 ok( r == S_OK, "ret %08x\n", r );
1149 r = IXMLDOMNodeList_get_length( node_list, &len );
1150 ok( r == S_OK, "ret %08x\n", r );
1151 ok( len == 1, "len %ld\n", len );
1152 IXMLDOMNodeList_Release( node_list );
1153 SysFreeString( str );
1155 str = SysAllocString( szdl );
1156 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1157 ok( r == S_OK, "ret %08x\n", r );
1158 r = IXMLDOMNodeList_get_length( node_list, &len );
1159 ok( r == S_OK, "ret %08x\n", r );
1160 ok( len == 0, "len %ld\n", len );
1161 IXMLDOMNodeList_Release( node_list );
1162 SysFreeString( str );
1164 str = SysAllocString( szstr1 );
1165 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1166 ok( r == S_OK, "ret %08x\n", r );
1167 r = IXMLDOMNodeList_get_length( node_list, &len );
1168 ok( r == S_OK, "ret %08x\n", r );
1169 ok( len == 0, "len %ld\n", len );
1170 IXMLDOMNodeList_Release( node_list );
1171 SysFreeString( str );
1173 IXMLDOMDocument_Release( doc );
1176 static void test_get_text(void)
1181 IXMLDOMDocument *doc;
1182 IXMLDOMNode *node, *node2, *node3;
1183 IXMLDOMNodeList *node_list;
1184 IXMLDOMNamedNodeMap *node_map;
1186 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1187 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1191 str = SysAllocString( szComplete4 );
1192 r = IXMLDOMDocument_loadXML( doc, str, &b );
1193 ok( r == S_OK, "loadXML failed\n");
1194 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1195 SysFreeString( str );
1197 str = SysAllocString( szbs );
1198 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1199 ok( r == S_OK, "ret %08x\n", r );
1202 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1203 ok( r == S_OK, "ret %08x\n", r );
1204 IXMLDOMNodeList_Release( node_list );
1206 r = IXMLDOMNode_get_text( node, &str );
1207 ok( r == S_OK, "ret %08x\n", r );
1209 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
1211 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
1214 r = IXMLDOMNode_get_attributes( node, &node_map );
1215 ok( r == S_OK, "ret %08x\n", r );
1217 str = SysAllocString( szvr );
1218 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1219 ok( r == S_OK, "ret %08x\n", r );
1222 r = IXMLDOMNode_get_text( node2, &str );
1223 ok( r == S_OK, "ret %08x\n", r );
1224 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1227 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1228 ok( r == S_OK, "ret %08x\n", r );
1230 r = IXMLDOMNode_get_text( node3, &str );
1231 ok( r == S_OK, "ret %08x\n", r );
1232 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1236 IXMLDOMNode_Release( node3 );
1237 IXMLDOMNode_Release( node2 );
1238 IXMLDOMNamedNodeMap_Release( node_map );
1239 IXMLDOMNode_Release( node );
1240 IXMLDOMDocument_Release( doc );
1243 static void test_get_childNodes(void)
1248 IXMLDOMDocument *doc;
1249 IXMLDOMElement *element;
1250 IXMLDOMNode *node, *node2;
1251 IXMLDOMNodeList *node_list, *node_list2;
1254 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1255 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1259 str = SysAllocString( szComplete4 );
1260 r = IXMLDOMDocument_loadXML( doc, str, &b );
1261 ok( r == S_OK, "loadXML failed\n");
1262 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1263 SysFreeString( str );
1265 r = IXMLDOMDocument_get_documentElement( doc, &element );
1266 ok( r == S_OK, "ret %08x\n", r);
1268 r = IXMLDOMElement_get_childNodes( element, &node_list );
1269 ok( r == S_OK, "ret %08x\n", r);
1271 r = IXMLDOMNodeList_get_length( node_list, &len );
1272 ok( r == S_OK, "ret %08x\n", r);
1273 ok( len == 4, "len %ld\n", len);
1275 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1276 ok( r == S_OK, "ret %08x\n", r);
1278 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1279 ok( r == S_OK, "ret %08x\n", r);
1281 r = IXMLDOMNodeList_get_length( node_list2, &len );
1282 ok( r == S_OK, "ret %08x\n", r);
1283 ok( len == 0, "len %ld\n", len);
1285 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1286 ok( r == S_FALSE, "ret %08x\n", r);
1288 IXMLDOMNodeList_Release( node_list2 );
1289 IXMLDOMNode_Release( node );
1290 IXMLDOMNodeList_Release( node_list );
1291 IXMLDOMElement_Release( element );
1292 IXMLDOMDocument_Release( doc );
1295 static void test_removeChild(void)
1300 IXMLDOMDocument *doc;
1301 IXMLDOMElement *element;
1302 IXMLDOMNode *node, *node2, *node3, *node4;
1303 IXMLDOMNodeList *node_list, *node_list2;
1305 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1306 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1310 str = SysAllocString( szComplete4 );
1311 r = IXMLDOMDocument_loadXML( doc, str, &b );
1312 ok( r == S_OK, "loadXML failed\n");
1313 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1314 SysFreeString( str );
1316 r = IXMLDOMDocument_get_documentElement( doc, &element );
1317 ok( r == S_OK, "ret %08x\n", r);
1319 r = IXMLDOMElement_get_childNodes( element, &node_list );
1320 ok( r == S_OK, "ret %08x\n", r);
1322 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1323 ok( r == S_OK, "ret %08x\n", r);
1325 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1326 ok( r == S_OK, "ret %08x\n", r);
1328 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1329 ok( r == S_OK, "ret %08x\n", r);
1331 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1332 ok( r == E_INVALIDARG, "ret %08x\n", r );
1334 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1335 ok( r == S_OK, "ret %08x\n", r);
1336 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1338 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1339 ok( r == S_FALSE, "ret %08x\n", r);
1340 ok( node3 == NULL, "%p\n", node3 );
1342 IXMLDOMNode_Release( node2 );
1343 IXMLDOMNode_Release( node4 );
1344 IXMLDOMNodeList_Release( node_list2 );
1345 IXMLDOMNode_Release( node );
1346 IXMLDOMNodeList_Release( node_list );
1347 IXMLDOMElement_Release( element );
1348 IXMLDOMDocument_Release( doc );
1351 static void test_XMLHTTP(void)
1353 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1354 static WCHAR wszPOST[] = {'P','O','S','T',0};
1355 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1356 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1357 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1358 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1359 IXMLHttpRequest *pXMLHttpRequest;
1364 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1365 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1366 (void **)&pXMLHttpRequest);
1368 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1373 VariantInit(&dummy);
1374 V_VT(&dummy) = VT_ERROR;
1375 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1376 VariantInit(&varfalse);
1377 V_VT(&varfalse) = VT_BOOL;
1378 V_BOOL(&varfalse) = VARIANT_FALSE;
1379 V_VT(&varbody) = VT_BSTR;
1380 V_BSTR(&varbody) = SysAllocString(wszBody);
1382 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1383 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1385 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1386 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1387 VariantClear(&varbody);
1389 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1390 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1391 /* the server currently returns "FAILED" because the Content-Type header is
1392 * not what the server expects */
1393 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1394 SysFreeString(bstrResponse);
1397 static void test_IXMLDOMDocument2(void)
1402 IXMLDOMDocument *doc;
1403 IXMLDOMDocument2 *doc2;
1407 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1408 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1412 str = SysAllocString( szComplete4 );
1413 r = IXMLDOMDocument_loadXML( doc, str, &b );
1414 ok( r == S_OK, "loadXML failed\n");
1415 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1416 SysFreeString( str );
1418 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1419 ok( r == S_OK, "ret %08x\n", r );
1420 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1422 /* we will check if the variant got cleared */
1423 ref = IXMLDOMDocument2_AddRef(doc2);
1424 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1425 V_VT(&var) = VT_UNKNOWN;
1426 V_UNKNOWN(&var) = (IUnknown *)doc2;
1429 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1430 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1431 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1434 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1435 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1436 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1439 /* the variant didn't get cleared*/
1440 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1442 /* setProperty tests */
1443 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1444 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1445 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1446 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1447 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1448 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1450 /* contrary to what MSDN calims you can switch back from XPath to XSLPattern */
1451 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1452 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1453 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1455 IXMLDOMDocument2_Release( doc2 );
1456 IXMLDOMDocument_Release( doc );
1460 static void test_XPath()
1465 IXMLDOMDocument2 *doc;
1466 IXMLDOMNode *rootNode;
1467 IXMLDOMNode *elem1Node;
1469 IXMLDOMNodeList *list;
1471 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1472 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1476 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1477 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1479 /* switch to XPath */
1480 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1482 /* some simple queries*/
1483 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1484 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1485 ole_check(IXMLDOMNodeList_reset(list));
1486 expect_list_and_release(list, "E2.D1");
1487 if (rootNode == NULL)
1490 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1491 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1493 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1494 expect_list_and_release(list, "E3.E2.E2.D1");
1496 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1497 /* using get_item for query results advances the position */
1498 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1499 expect_node(node, "E2.E2.D1");
1500 IXMLDOMNode_Release(node);
1501 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1502 expect_node(node, "E4.E2.D1");
1503 IXMLDOMNode_Release(node);
1504 ole_check(IXMLDOMNodeList_reset(list));
1505 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1507 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
1508 expect_list_and_release(list, "E2.D1");
1510 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
1511 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
1512 ole_check(IXMLDOMNodeList_reset(list));
1513 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1515 /* select an attribute */
1516 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
1517 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
1519 /* would evaluate to a number */
1520 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
1521 /* would evaluate to a boolean */
1522 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
1523 /* would evaluate to a string */
1524 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
1527 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
1528 expect_list_and_release(list, "");
1529 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
1530 expect_list_and_release(list, "");
1531 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
1532 expect_list_and_release(list, "");
1534 /* foo undeclared in document node */
1535 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1536 /* undeclared in <root> node */
1537 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
1538 /* undeclared in <elem> node */
1539 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
1540 /* but this trick can be used */
1541 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
1542 expect_list_and_release(list, "E3.E4.E2.D1");
1544 /* it has to be declared in SelectionNamespaces */
1545 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1546 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
1548 /* now the namespace can be used */
1549 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
1550 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1551 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
1552 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1553 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
1554 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1555 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
1556 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
1558 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
1559 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1560 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
1562 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1564 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
1565 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1566 if (V_VT(&var) == VT_BSTR)
1567 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
1569 /* extra attributes - same thing*/
1570 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1571 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
1572 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1574 IXMLDOMNode_Release(rootNode);
1575 IXMLDOMNode_Release(elem1Node);
1576 IXMLDOMDocument_Release(doc);
1584 r = CoInitialize( NULL );
1585 ok( r == S_OK, "failed to init com\n");
1591 test_getElementsByTagName();
1593 test_get_childNodes();
1596 test_IXMLDOMDocument2();