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 };
146 static WCHAR szAttribute
[] = {'A','t','t','r',0 };
147 static WCHAR szAttributeXML
[] = {'A','t','t','r','=','"','"',0 };
149 #define expect_bstr_eq_and_free(bstr, expect) { \
150 BSTR bstrExp = alloc_str_from_narrow(expect); \
151 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
152 SysFreeString(bstr); \
153 SysFreeString(bstrExp); \
156 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
158 #define ole_check(expr) { \
160 ok(r == S_OK, #expr " returned %x\n", r); \
163 #define ole_expect(expr, expect) { \
165 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
168 static BSTR
alloc_str_from_narrow(const char *str
)
170 int len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
171 BSTR ret
= SysAllocStringLen(NULL
, len
- 1); /* NUL character added automatically */
172 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
176 BSTR alloced_bstrs
[256];
177 int alloced_bstrs_count
= 0;
179 static BSTR
_bstr_(const char *str
)
181 assert(alloced_bstrs_count
< sizeof(alloced_bstrs
)/sizeof(alloced_bstrs
[0]));
182 alloced_bstrs
[alloced_bstrs_count
] = alloc_str_from_narrow(str
);
183 return alloced_bstrs
[alloced_bstrs_count
++];
186 static void free_bstrs(void)
189 for (i
= 0; i
< alloced_bstrs_count
; i
++)
190 SysFreeString(alloced_bstrs
[i
]);
191 alloced_bstrs_count
= 0;
194 static VARIANT
_variantbstr_(const char *str
)
198 V_BSTR(&v
) = _bstr_(str
);
202 static void get_str_for_type(DOMNodeType type
, char *buf
)
216 wsprintfA(buf
, "[%d]", type
);
220 static int get_node_position(IXMLDOMNode
*node
)
225 IXMLDOMNode_AddRef(node
);
228 IXMLDOMNode
*new_node
;
231 r
= IXMLDOMNode_get_previousSibling(node
, &new_node
);
232 ok(!FAILED(r
), "get_previousSibling failed\n");
233 IXMLDOMNode_Release(node
);
239 static void node_to_string(IXMLDOMNode
*node
, char *buf
)
246 lstrcpyA(buf
, "(null)");
250 IXMLDOMNode_AddRef(node
);
253 IXMLDOMNode
*new_node
;
255 ole_check(IXMLDOMNode_get_nodeType(node
, &type
));
256 get_str_for_type(type
, buf
);
259 if (type
== NODE_ATTRIBUTE
)
262 ole_check(IXMLDOMNode_get_nodeName(node
, &bstr
));
264 wsprintfA(buf
, "%ws", bstr
);
269 r
= IXMLDOMNode_selectSingleNode(node
, _bstr_(".."), &new_node
);
273 int pos
= get_node_position(node
);
274 DOMNodeType parent_type
= NODE_INVALID
;
275 r
= IXMLDOMNode_get_parentNode(node
, &new_node
);
277 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
278 * results we "fix" it */
280 ole_check(IXMLDOMNode_get_nodeType(node
, &parent_type
));
281 /* we need also to workaround the no document node problem - see below */
282 if (((r
== S_FALSE
&& type
!= NODE_DOCUMENT
) || parent_type
== NODE_DOCUMENT
) && type
!= NODE_PROCESSING_INSTRUCTION
&& pos
==1)
284 todo_wine
ok(FALSE
, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
287 wsprintf(buf
, "%d", pos
);
291 ok(!FAILED(r
), "get_parentNode failed (%08x)\n", r
);
292 IXMLDOMNode_Release(node
);
298 /* currently we can't access document node in wine. All our examples this is the
299 * root node so to be able to test query results we add it */
300 if (type
!= NODE_DOCUMENT
)
302 todo_wine
ok(FALSE
, "Document node is not the last returned node!\n");
310 static char *list_to_string(IXMLDOMNodeList
*list
)
312 static char buf
[4096];
319 lstrcpyA(buf
, "(null)");
322 ole_check(IXMLDOMNodeList_get_length(list
, &len
));
323 for (i
= 0; i
< len
; i
++)
328 ole_check(IXMLDOMNodeList_nextNode(list
, &node
));
329 node_to_string(node
, pos
);
331 IXMLDOMNode_Release(node
);
337 #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); }
338 #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); }
340 static void test_domdoc( void )
343 IXMLDOMDocument
*doc
= NULL
;
344 IXMLDOMParseError
*error
;
345 IXMLDOMElement
*element
= NULL
;
347 IXMLDOMText
*nodetext
= NULL
;
348 IXMLDOMComment
*node_comment
= NULL
;
349 IXMLDOMAttribute
*node_attr
= NULL
;
350 IXMLDOMNode
*nodeChild
= NULL
;
351 IXMLDOMProcessingInstruction
*nodePI
= NULL
;
357 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
358 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
362 /* try some stupid things */
363 r
= IXMLDOMDocument_loadXML( doc
, NULL
, NULL
);
364 ok( r
== S_FALSE
, "loadXML failed\n");
367 r
= IXMLDOMDocument_loadXML( doc
, NULL
, &b
);
368 ok( r
== S_FALSE
, "loadXML failed\n");
369 ok( b
== VARIANT_FALSE
, "failed to load XML string\n");
371 /* try to load a document from a nonexistent file */
373 str
= SysAllocString( szNonExistentFile
);
375 V_VT(&var
) = VT_BSTR
;
378 r
= IXMLDOMDocument_load( doc
, var
, &b
);
379 ok( r
== S_FALSE
, "load (from file) failed\n");
380 ok( b
== VARIANT_FALSE
, "failed to load XML file\n");
381 SysFreeString( str
);
383 /* try load an empty document */
385 str
= SysAllocString( szEmpty
);
386 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
387 ok( r
== S_FALSE
, "loadXML failed\n");
388 ok( b
== VARIANT_FALSE
, "failed to load XML string\n");
389 SysFreeString( str
);
391 /* check that there's no document element */
393 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
394 ok( r
== S_FALSE
, "should be no document element\n");
396 /* try finding a node */
398 str
= SysAllocString( szstr1
);
399 r
= IXMLDOMDocument_selectSingleNode( doc
, str
, &node
);
400 ok( r
== S_FALSE
, "ret %08x\n", r
);
401 SysFreeString( str
);
404 str
= SysAllocString( szIncomplete
);
405 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
406 ok( r
== S_FALSE
, "loadXML failed\n");
407 ok( b
== VARIANT_FALSE
, "failed to load XML string\n");
408 SysFreeString( str
);
410 /* check that there's no document element */
411 element
= (IXMLDOMElement
*)1;
412 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
413 ok( r
== S_FALSE
, "should be no document element\n");
414 ok( element
== NULL
, "Element should be NULL\n");
416 /* try to load something valid */
418 str
= SysAllocString( szComplete1
);
419 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
420 ok( r
== S_OK
, "loadXML failed\n");
421 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
422 SysFreeString( str
);
424 /* try with a null out pointer */
425 r
= IXMLDOMDocument_get_documentElement( doc
, NULL
);
426 ok( r
== E_INVALIDARG
, "should be no document element\n");
428 /* check if nodename is correct */
429 r
= IXMLDOMDocument_get_nodeName( doc
, NULL
);
430 ok ( r
== E_INVALIDARG
, "get_nodeName (NULL) wrong code\n");
432 /* content doesn't matter here */
434 r
= IXMLDOMDocument_get_nodeName( doc
, &str
);
435 ok ( r
== S_OK
, "get_nodeName wrong code\n");
436 ok ( str
!= NULL
, "str is null\n");
437 ok( !lstrcmpW( str
, szDocument
), "incorrect nodeName\n");
438 SysFreeString( str
);
441 /* check that there's a document element */
443 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
444 ok( r
== S_OK
, "should be a document element\n");
449 /* check if the tag is correct */
450 r
= IXMLDOMElement_get_tagName( element
, &tag
);
451 ok( r
== S_OK
, "couldn't get tag name\n");
452 ok( tag
!= NULL
, "tag was null\n");
453 ok( !lstrcmpW( tag
, szOpen
), "incorrect tag name\n");
454 SysFreeString( tag
);
456 /* figure out what happens if we try to reload the document */
457 str
= SysAllocString( szComplete2
);
458 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
459 ok( r
== S_OK
, "loadXML failed\n");
460 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
461 SysFreeString( str
);
463 /* check if the tag is still correct */
465 r
= IXMLDOMElement_get_tagName( element
, &tag
);
466 ok( r
== S_OK
, "couldn't get tag name\n");
467 ok( tag
!= NULL
, "tag was null\n");
468 ok( !lstrcmpW( tag
, szOpen
), "incorrect tag name\n");
469 SysFreeString( tag
);
471 IXMLDOMElement_Release( element
);
475 /* as soon as we call loadXML again, the document element will disappear */
477 r
= IXMLDOMDocument_loadXML( doc
, NULL
, NULL
);
478 ok( r
== S_FALSE
, "loadXML failed\n");
479 ok( b
== 2, "variant modified\n");
480 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
481 ok( r
== S_FALSE
, "should be no document element\n");
483 /* try to load something else simple and valid */
485 str
= SysAllocString( szComplete3
);
486 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
487 ok( r
== S_OK
, "loadXML failed\n");
488 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
489 SysFreeString( str
);
491 /* try something a little more complicated */
493 str
= SysAllocString( szComplete4
);
494 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
495 ok( r
== S_OK
, "loadXML failed\n");
496 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
497 SysFreeString( str
);
499 r
= IXMLDOMDocument_get_parseError( doc
, &error
);
500 ok( r
== S_OK
, "returns %08x\n", r
);
502 r
= IXMLDOMParseError_get_errorCode( error
, &code
);
503 ok( r
== S_FALSE
, "returns %08x\n", r
);
504 ok( code
== 0, "code %ld\n", code
);
505 IXMLDOMParseError_Release( error
);
507 /* test createTextNode */
508 str
= SysAllocString( szOpen
);
509 r
= IXMLDOMDocument_createTextNode(doc
, str
, NULL
);
510 ok( r
== E_INVALIDARG
, "returns %08x\n", r
);
511 r
= IXMLDOMDocument_createTextNode(doc
, str
, &nodetext
);
512 ok( r
== S_OK
, "returns %08x\n", r
);
515 IXMLDOMNamedNodeMap
*pAttribs
;
517 /* Text Last Child Checks */
518 r
= IXMLDOMText_get_lastChild(nodetext
, NULL
);
519 ok(r
== E_INVALIDARG
, "ret %08x\n", r
);
521 nodeChild
= (IXMLDOMNode
*)0x1;
522 r
= IXMLDOMText_get_lastChild(nodetext
, &nodeChild
);
523 ok(r
== S_FALSE
, "ret %08x\n", r
);
524 ok(nodeChild
== NULL
, "nodeChild not NULL\n");
526 /* test get_attributes */
527 r
= IXMLDOMText_get_attributes( nodetext
, NULL
);
528 ok( r
== E_INVALIDARG
, "get_attributes returned wrong code\n");
530 pAttribs
= (IXMLDOMNamedNodeMap
*)0x1;
531 r
= IXMLDOMText_get_attributes( nodetext
, &pAttribs
);
532 ok(r
== S_FALSE
, "ret %08x\n", r
);
533 ok( pAttribs
== NULL
, "pAttribs not NULL\n");
535 IXMLDOMText_Release( nodetext
);
536 SysFreeString( str
);
538 /* test Create Comment */
539 r
= IXMLDOMDocument_createComment(doc
, NULL
, NULL
);
540 ok( r
== E_INVALIDARG
, "returns %08x\n", r
);
541 r
= IXMLDOMDocument_createComment(doc
, szComment
, &node_comment
);
542 ok( r
== S_OK
, "returns %08x\n", r
);
545 /* Last Child Checks */
546 r
= IXMLDOMComment_get_lastChild(node_comment
, NULL
);
547 ok(r
== E_INVALIDARG
, "ret %08x\n", r
);
549 nodeChild
= (IXMLDOMNode
*)0x1;
550 r
= IXMLDOMComment_get_lastChild(node_comment
, &nodeChild
);
551 ok(r
== S_FALSE
, "ret %08x\n", r
);
552 ok(nodeChild
== NULL
, "pLastChild not NULL\n");
554 IXMLDOMText_Release( node_comment
);
556 /* test Create Attribute */
557 r
= IXMLDOMDocument_createAttribute(doc
, NULL
, NULL
);
558 ok( r
== E_INVALIDARG
, "returns %08x\n", r
);
559 r
= IXMLDOMDocument_createAttribute(doc
, szAttribute
, &node_attr
);
560 ok( r
== S_OK
, "returns %08x\n", r
);
561 IXMLDOMText_Release( node_attr
);
563 /* test Processing Instruction */
564 str
= SysAllocStringLen(NULL
, 0);
565 r
= IXMLDOMDocument_createProcessingInstruction(doc
, str
, str
, NULL
);
566 ok( r
== E_INVALIDARG
, "returns %08x\n", r
);
567 r
= IXMLDOMDocument_createProcessingInstruction(doc
, NULL
, str
, &nodePI
);
568 ok( r
== E_FAIL
, "returns %08x\n", r
);
569 r
= IXMLDOMDocument_createProcessingInstruction(doc
, str
, str
, &nodePI
);
570 ok( r
== E_FAIL
, "returns %08x\n", r
);
573 r
= IXMLDOMDocument_createProcessingInstruction(doc
, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI
);
574 ok( r
== S_OK
, "returns %08x\n", r
);
577 /* Last Child Checks */
578 r
= IXMLDOMProcessingInstruction_get_lastChild(nodePI
, NULL
);
579 ok(r
== E_INVALIDARG
, "ret %08x\n", r
);
581 nodeChild
= (IXMLDOMNode
*)0x1;
582 r
= IXMLDOMProcessingInstruction_get_lastChild(nodePI
, &nodeChild
);
583 ok(r
== S_FALSE
, "ret %08x\n", r
);
584 ok(nodeChild
== NULL
, "nodeChild not NULL\n");
586 IXMLDOMProcessingInstruction_Release(nodePI
);
588 r
= IXMLDOMDocument_Release( doc
);
589 ok( r
== 0, "document ref count incorrect\n");
593 static void test_domnode( void )
596 IXMLDOMDocument
*doc
= NULL
, *owner
= NULL
;
597 IXMLDOMElement
*element
= NULL
;
598 IXMLDOMNamedNodeMap
*map
= NULL
;
599 IXMLDOMNode
*node
= NULL
, *next
= NULL
;
600 IXMLDOMNodeList
*list
= NULL
;
601 DOMNodeType type
= NODE_INVALID
;
607 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
608 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
613 str
= SysAllocString( szComplete4
);
614 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
615 ok( r
== S_OK
, "loadXML failed\n");
616 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
617 SysFreeString( str
);
622 r
= IXMLDOMNode_hasChildNodes( doc
, &b
);
623 ok( r
== S_OK
, "hasChildNoes bad return\n");
624 ok( b
== VARIANT_TRUE
, "hasChildNoes wrong result\n");
626 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
627 ok( r
== S_OK
, "should be a document element\n");
628 ok( element
!= NULL
, "should be an element\n");
631 ok( FALSE
, "no document\n");
634 ok( V_VT(&var
) == VT_EMPTY
, "variant init failed\n");
636 r
= IXMLDOMNode_get_nodeValue( doc
, NULL
);
637 ok(r
== E_INVALIDARG
, "get_nodeValue ret %08x\n", r
);
639 r
= IXMLDOMNode_get_nodeValue( doc
, &var
);
640 ok( r
== S_FALSE
, "nextNode returned wrong code\n");
641 ok( V_VT(&var
) == VT_NULL
, "variant wasn't empty\n");
642 ok( V_BSTR(&var
) == NULL
, "variant value wasn't null\n");
647 r
= IXMLDOMNode_get_ownerDocument( element
, &owner
);
649 ok( r
== S_OK
, "get_ownerDocument return code\n");
651 ok( owner
!= doc
, "get_ownerDocument return\n");
654 r
= IXMLDOMNode_get_nodeType( element
, &type
);
655 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
656 ok( type
== NODE_ELEMENT
, "node not an element\n");
659 r
= IXMLDOMNode_get_baseName( element
, &str
);
660 ok( r
== S_OK
, "get_baseName returned wrong code\n");
661 ok( lstrcmpW(str
,szlc
) == 0, "basename was wrong\n");
664 /* check if nodename is correct */
665 r
= IXMLDOMElement_get_nodeName( element
, NULL
);
666 ok ( r
== E_INVALIDARG
, "get_nodeName (NULL) wrong code\n");
668 /* content doesn't matter here */
670 r
= IXMLDOMElement_get_nodeName( element
, &str
);
671 ok ( r
== S_OK
, "get_nodeName wrong code\n");
672 ok ( str
!= NULL
, "str is null\n");
673 ok( !lstrcmpW( str
, szlc
), "incorrect nodeName\n");
674 SysFreeString( str
);
676 str
= SysAllocString( szNonExistentFile
);
679 r
= IXMLDOMElement_getAttribute( element
, str
, &var
);
680 ok( r
== E_FAIL
, "getAttribute ret %08x\n", r
);
681 ok( V_VT(&var
) == VT_EMPTY
, "vt = %x\n", V_VT(&var
));
683 SysFreeString( str
);
685 str
= SysAllocString( szdl
);
688 r
= IXMLDOMElement_getAttribute( element
, str
, &var
);
689 ok( r
== S_OK
, "getAttribute ret %08x\n", r
);
690 ok( V_VT(&var
) == VT_BSTR
, "vt = %x\n", V_VT(&var
));
691 ok( !lstrcmpW(V_BSTR(&var
), szstr1
), "wrong attr value\n");
692 VariantClear( &var
);
693 SysFreeString( str
);
695 r
= IXMLDOMElement_get_attributes( element
, &map
);
696 ok( r
== S_OK
, "get_attributes returned wrong code\n");
697 ok( map
!= NULL
, "should be attributes\n");
700 r
= IXMLDOMNode_hasChildNodes( element
, &b
);
701 ok( r
== S_OK
, "hasChildNoes bad return\n");
702 ok( b
== VARIANT_TRUE
, "hasChildNoes wrong result\n");
705 ok( FALSE
, "no element\n");
709 ISupportErrorInfo
*support_error
;
710 r
= IXMLDOMNamedNodeMap_QueryInterface( map
, &IID_ISupportErrorInfo
, (LPVOID
*)&support_error
);
711 ok( r
== S_OK
, "ret %08x\n", r
);
713 r
= ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error
, &IID_IXMLDOMNamedNodeMap
);
716 ok( r
== S_OK
, "ret %08x\n", r
);
718 ISupportErrorInfo_Release( support_error
);
720 str
= SysAllocString( szdl
);
721 r
= IXMLDOMNamedNodeMap_getNamedItem( map
, str
, &node
);
722 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
723 ok( node
!= NULL
, "should be attributes\n");
724 IXMLDOMNode_Release(node
);
725 SysFreeString( str
);
727 str
= SysAllocString( szdl
);
728 r
= IXMLDOMNamedNodeMap_getNamedItem( map
, str
, NULL
);
729 ok( r
== E_INVALIDARG
, "getNamedItem should return E_INVALIDARG\n");
730 SysFreeString( str
);
732 /* something that isn't in szComplete4 */
733 str
= SysAllocString( szOpen
);
734 node
= (IXMLDOMNode
*) 1;
735 r
= IXMLDOMNamedNodeMap_getNamedItem( map
, str
, &node
);
736 ok( r
= S_FALSE
, "getNamedItem found a node that wasn't there\n");
737 ok( node
== NULL
, "getNamedItem should have returned NULL\n");
738 SysFreeString( str
);
740 /* test indexed access of attributes */
741 r
= IXMLDOMNamedNodeMap_get_length( map
, &count
);
742 ok ( r
== S_OK
, "get_length wrong code\n");
743 ok ( count
== 1, "get_length != 1\n");
746 r
= IXMLDOMNamedNodeMap_get_item( map
, -1, &node
);
747 ok ( r
== S_FALSE
, "get_item (-1) wrong code\n");
748 ok ( node
== NULL
, "there is no node\n");
751 r
= IXMLDOMNamedNodeMap_get_item( map
, 1, &node
);
752 ok ( r
== S_FALSE
, "get_item (1) wrong code\n");
753 ok ( node
== NULL
, "there is no attribute\n");
756 r
= IXMLDOMNamedNodeMap_get_item( map
, 0, &node
);
757 ok ( r
== S_OK
, "get_item (0) wrong code\n");
758 ok ( node
!= NULL
, "should be attribute\n");
760 r
= IXMLDOMNode_get_nodeName( node
, NULL
);
761 ok ( r
== E_INVALIDARG
, "get_nodeName (NULL) wrong code\n");
763 /* content doesn't matter here */
765 r
= IXMLDOMNode_get_nodeName( node
, &str
);
766 ok ( r
== S_OK
, "get_nodeName wrong code\n");
767 ok ( str
!= NULL
, "str is null\n");
768 ok( !lstrcmpW( str
, szdl
), "incorrect node name\n");
769 SysFreeString( str
);
771 /* test sequential access of attributes */
773 r
= IXMLDOMNamedNodeMap_nextNode( map
, &node
);
774 ok ( r
== S_OK
, "nextNode (first time) wrong code\n");
775 ok ( node
!= NULL
, "nextNode, should be attribute\n");
777 r
= IXMLDOMNamedNodeMap_nextNode( map
, &node
);
778 ok ( r
!= S_OK
, "nextNode (second time) wrong code\n");
779 ok ( node
== NULL
, "nextNode, there is no attribute\n");
781 r
= IXMLDOMNamedNodeMap_reset( map
);
782 ok ( r
== S_OK
, "reset should return S_OK\n");
784 r
= IXMLDOMNamedNodeMap_nextNode( map
, &node
);
785 ok ( r
== S_OK
, "nextNode (third time) wrong code\n");
786 ok ( node
!= NULL
, "nextNode, should be attribute\n");
789 ok( FALSE
, "no map\n");
794 r
= IXMLDOMNode_get_nodeType( node
, &type
);
795 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
796 ok( type
== NODE_ATTRIBUTE
, "node not an attribute\n");
799 r
= IXMLDOMNode_get_baseName( node
, NULL
);
800 ok( r
== E_INVALIDARG
, "get_baseName returned wrong code\n");
803 r
= IXMLDOMNode_get_baseName( node
, &str
);
804 ok( r
== S_OK
, "get_baseName returned wrong code\n");
805 ok( lstrcmpW(str
,szdl
) == 0, "basename was wrong\n");
806 SysFreeString( str
);
808 r
= IXMLDOMNode_get_nodeValue( node
, &var
);
809 ok( r
== S_OK
, "returns %08x\n", r
);
810 ok( V_VT(&var
) == VT_BSTR
, "vt %x\n", V_VT(&var
));
811 ok( !lstrcmpW(V_BSTR(&var
), szstr1
), "nodeValue incorrect\n");
814 r
= IXMLDOMNode_get_childNodes( node
, NULL
);
815 ok( r
== E_INVALIDARG
, "get_childNodes returned wrong code\n");
817 r
= IXMLDOMNode_get_childNodes( node
, &list
);
818 ok( r
== S_OK
, "get_childNodes returned wrong code\n");
822 r
= IXMLDOMNodeList_nextNode( list
, &next
);
823 ok( r
== S_OK
, "nextNode returned wrong code\n");
826 ok( FALSE
, "no childlist\n");
831 r
= IXMLDOMNode_hasChildNodes( next
, &b
);
832 ok( r
== S_FALSE
, "hasChildNoes bad return\n");
833 ok( b
== VARIANT_FALSE
, "hasChildNoes wrong result\n");
836 r
= IXMLDOMNode_get_nodeType( next
, &type
);
837 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
838 ok( type
== NODE_TEXT
, "node not text\n");
841 r
= IXMLDOMNode_get_baseName( next
, &str
);
842 ok( r
== S_FALSE
, "get_baseName returned wrong code\n");
843 ok( str
== NULL
, "basename was wrong\n");
847 ok( FALSE
, "no next\n");
850 IXMLDOMNode_Release( next
);
853 IXMLDOMNodeList_Release( list
);
856 IXMLDOMNode_Release( node
);
859 ok( FALSE
, "no node\n");
863 IXMLDOMNamedNodeMap_Release( map
);
865 /* now traverse the tree from the root element */
869 r
= IXMLDOMNode_get_childNodes( element
, &list
);
870 ok( r
== S_OK
, "get_childNodes returned wrong code\n");
872 /* using get_item for child list doesn't advance the position */
873 ole_check(IXMLDOMNodeList_get_item(list
, 1, &node
));
874 expect_node(node
, "E2.E2.D1");
875 IXMLDOMNode_Release(node
);
876 ole_check(IXMLDOMNodeList_nextNode(list
, &node
));
877 expect_node(node
, "E1.E2.D1");
878 IXMLDOMNode_Release(node
);
879 ole_check(IXMLDOMNodeList_reset(list
));
881 IXMLDOMNodeList_AddRef(list
);
882 expect_list_and_release(list
, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
883 ole_check(IXMLDOMNodeList_reset(list
));
886 ok( FALSE
, "no element\n");
888 node
= (void*)0xdeadbeef;
889 r
= IXMLDOMNode_selectSingleNode( element
, szdl
, &node
);
890 ok( r
== S_FALSE
, "ret %08x\n", r
);
891 ok( node
== NULL
, "node %p\n", node
);
892 r
= IXMLDOMNode_selectSingleNode( element
, szbs
, &node
);
893 ok( r
== S_OK
, "ret %08x\n", r
);
894 r
= IXMLDOMNode_Release( node
);
895 ok( r
== 0, "ret %08x\n", r
);
899 r
= IXMLDOMNodeList_get_length( list
, &count
);
900 ok( r
== S_OK
, "get_length returns %08x\n", r
);
901 ok( count
== 4, "get_length got %ld\n", count
);
903 r
= IXMLDOMNodeList_nextNode( list
, &node
);
904 ok( r
== S_OK
, "nextNode returned wrong code\n");
907 ok( FALSE
, "no list\n");
912 r
= IXMLDOMNode_get_nodeType( node
, &type
);
913 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
914 ok( type
== NODE_ELEMENT
, "node not text\n");
917 ok( V_VT(&var
) == VT_EMPTY
, "variant init failed\n");
918 r
= IXMLDOMNode_get_nodeValue( node
, &var
);
919 ok( r
== S_FALSE
, "nextNode returned wrong code\n");
920 ok( V_VT(&var
) == VT_NULL
, "variant wasn't empty\n");
921 ok( V_BSTR(&var
) == NULL
, "variant value wasn't null\n");
923 r
= IXMLDOMNode_hasChildNodes( node
, NULL
);
924 ok( r
== E_INVALIDARG
, "hasChildNoes bad return\n");
927 r
= IXMLDOMNode_hasChildNodes( node
, &b
);
928 ok( r
== S_OK
, "hasChildNoes bad return\n");
929 ok( b
== VARIANT_TRUE
, "hasChildNoes wrong result\n");
932 r
= IXMLDOMNode_get_baseName( node
, &str
);
933 ok( r
== S_OK
, "get_baseName returned wrong code\n");
934 ok( lstrcmpW(str
,szbs
) == 0, "basename was wrong\n");
938 ok( FALSE
, "no node\n");
941 IXMLDOMNode_Release( node
);
943 IXMLDOMNodeList_Release( list
);
945 IXMLDOMElement_Release( element
);
948 str
= SysAllocString( szComplete5
);
949 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
950 ok( r
== S_OK
, "loadXML failed\n");
951 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
952 SysFreeString( str
);
955 r
= IXMLDOMNode_hasChildNodes( doc
, &b
);
956 ok( r
== S_OK
, "hasChildNoes bad return\n");
957 ok( b
== VARIANT_TRUE
, "hasChildNoes wrong result\n");
959 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
960 ok( r
== S_OK
, "should be a document element\n");
961 ok( element
!= NULL
, "should be an element\n");
965 static const WCHAR szSSearch
[] = {'S',':','s','e','a','r','c','h',0};
968 /* check if the tag is correct */
969 r
= IXMLDOMElement_get_tagName( element
, &tag
);
970 ok( r
== S_OK
, "couldn't get tag name\n");
971 ok( tag
!= NULL
, "tag was null\n");
972 ok( !lstrcmpW( tag
, szSSearch
), "incorrect tag name\n");
973 SysFreeString( tag
);
977 IXMLDOMElement_Release( element
);
979 IXMLDOMDocument_Release( doc
);
982 static void test_refs(void)
987 IXMLDOMDocument
*doc
= NULL
;
988 IXMLDOMElement
*element
= NULL
;
989 IXMLDOMNode
*node
= NULL
, *node2
;
990 IXMLDOMNodeList
*node_list
= NULL
;
992 IUnknown
*unk
, *unk2
;
994 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
995 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
998 ref
= IXMLDOMDocument_Release(doc
);
999 ok( ref
== 0, "ref %d\n", ref
);
1001 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1002 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
1006 str
= SysAllocString( szComplete4
);
1007 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
1008 ok( r
== S_OK
, "loadXML failed\n");
1009 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
1010 SysFreeString( str
);
1012 ref
= IXMLDOMDocument_AddRef( doc
);
1013 ok( ref
== 2, "ref %d\n", ref
);
1014 ref
= IXMLDOMDocument_AddRef( doc
);
1015 ok( ref
== 3, "ref %d\n", ref
);
1016 IXMLDOMDocument_Release( doc
);
1017 IXMLDOMDocument_Release( doc
);
1019 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
1020 ok( r
== S_OK
, "should be a document element\n");
1021 ok( element
!= NULL
, "should be an element\n");
1023 ref
= IXMLDOMDocument_AddRef( doc
);
1024 ok( ref
== 2, "ref %d\n", ref
);
1025 IXMLDOMDocument_Release( doc
);
1027 r
= IXMLDOMElement_get_childNodes( element
, &node_list
);
1028 ok( r
== S_OK
, "rets %08x\n", r
);
1029 ref
= IXMLDOMNodeList_AddRef( node_list
);
1030 ok( ref
== 2, "ref %d\n", ref
);
1031 IXMLDOMNodeList_Release( node_list
);
1033 IXMLDOMNodeList_get_item( node_list
, 0, &node
);
1034 ok( r
== S_OK
, "rets %08x\n", r
);
1036 IXMLDOMNodeList_get_item( node_list
, 0, &node2
);
1037 ok( r
== S_OK
, "rets %08x\n", r
);
1039 ref
= IXMLDOMNode_AddRef( node
);
1040 ok( ref
== 2, "ref %d\n", ref
);
1041 IXMLDOMNode_Release( node
);
1043 ref
= IXMLDOMNode_Release( node
);
1044 ok( ref
== 0, "ref %d\n", ref
);
1045 ref
= IXMLDOMNode_Release( node2
);
1046 ok( ref
== 0, "ref %d\n", ref
);
1048 ref
= IXMLDOMNodeList_Release( node_list
);
1049 ok( ref
== 0, "ref %d\n", ref
);
1051 ok( node
!= node2
, "node %p node2 %p\n", node
, node2
);
1053 ref
= IXMLDOMDocument_Release( doc
);
1054 ok( ref
== 0, "ref %d\n", ref
);
1056 ref
= IXMLDOMElement_AddRef( element
);
1058 ok( ref
== 3, "ref %d\n", ref
);
1060 IXMLDOMElement_Release( element
);
1062 /* IUnknown must be unique however we obtain it */
1063 r
= IXMLDOMElement_QueryInterface( element
, &IID_IUnknown
, (LPVOID
*)&unk
);
1064 ok( r
== S_OK
, "rets %08x\n", r
);
1065 r
= IXMLDOMElement_QueryInterface( element
, &IID_IXMLDOMNode
, (LPVOID
*)&node
);
1066 ok( r
== S_OK
, "rets %08x\n", r
);
1067 r
= IXMLDOMNode_QueryInterface( node
, &IID_IUnknown
, (LPVOID
*)&unk2
);
1068 ok( r
== S_OK
, "rets %08x\n", r
);
1069 ok( unk
== unk2
, "unk %p unk2 %p\n", unk
, unk2
);
1071 IUnknown_Release( unk2
);
1072 IUnknown_Release( unk
);
1073 IXMLDOMNode_Release( node
);
1075 IXMLDOMElement_Release( element
);
1079 static void test_create(void)
1084 IXMLDOMDocument
*doc
;
1085 IXMLDOMElement
*element
;
1086 IXMLDOMNode
*root
, *node
, *child
;
1087 IXMLDOMNamedNodeMap
*attr_map
;
1092 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1093 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
1098 V_I4(&var
) = NODE_ELEMENT
;
1099 str
= SysAllocString( szlc
);
1100 r
= IXMLDOMDocument_createNode( doc
, var
, str
, NULL
, &node
);
1101 ok( r
== S_OK
, "returns %08x\n", r
);
1102 r
= IXMLDOMDocument_appendChild( doc
, node
, &root
);
1103 ok( r
== S_OK
, "returns %08x\n", r
);
1104 ok( node
== root
, "%p %p\n", node
, root
);
1106 ref
= IXMLDOMNode_AddRef( node
);
1107 ok(ref
== 3, "ref %d\n", ref
);
1108 IXMLDOMNode_Release( node
);
1110 ref
= IXMLDOMNode_Release( node
);
1111 ok(ref
== 1, "ref %d\n", ref
);
1112 SysFreeString( str
);
1115 V_I4(&var
) = NODE_ELEMENT
;
1116 str
= SysAllocString( szbs
);
1117 r
= IXMLDOMDocument_createNode( doc
, var
, str
, NULL
, &node
);
1118 ok( r
== S_OK
, "returns %08x\n", r
);
1120 ref
= IXMLDOMNode_AddRef( node
);
1121 ok(ref
== 2, "ref = %d\n", ref
);
1122 IXMLDOMNode_Release( node
);
1124 r
= IXMLDOMNode_QueryInterface( node
, &IID_IUnknown
, (LPVOID
*)&unk
);
1125 ok( r
== S_OK
, "returns %08x\n", r
);
1127 ref
= IXMLDOMNode_AddRef( unk
);
1128 ok(ref
== 3, "ref = %d\n", ref
);
1129 IXMLDOMNode_Release( unk
);
1131 V_VT(&var
) = VT_EMPTY
;
1132 r
= IXMLDOMNode_insertBefore( root
, (IXMLDOMNode
*)unk
, var
, &child
);
1133 ok( r
== S_OK
, "returns %08x\n", r
);
1134 ok( unk
== (IUnknown
*)child
, "%p %p\n", unk
, child
);
1135 IXMLDOMNode_Release( child
);
1136 IUnknown_Release( unk
);
1139 V_VT(&var
) = VT_NULL
;
1140 V_DISPATCH(&var
) = (IDispatch
*)node
;
1141 r
= IXMLDOMNode_insertBefore( root
, node
, var
, &child
);
1142 ok( r
== S_OK
, "returns %08x\n", r
);
1143 ok( node
== child
, "%p %p\n", node
, child
);
1144 IXMLDOMNode_Release( child
);
1147 V_VT(&var
) = VT_NULL
;
1148 V_DISPATCH(&var
) = (IDispatch
*)node
;
1149 r
= IXMLDOMNode_insertBefore( root
, node
, var
, NULL
);
1150 ok( r
== S_OK
, "returns %08x\n", r
);
1151 IXMLDOMNode_Release( node
);
1153 r
= IXMLDOMNode_QueryInterface( root
, &IID_IXMLDOMElement
, (LPVOID
*)&element
);
1154 ok( r
== S_OK
, "returns %08x\n", r
);
1156 r
= IXMLDOMElement_get_attributes( element
, &attr_map
);
1157 ok( r
== S_OK
, "returns %08x\n", r
);
1158 r
= IXMLDOMNamedNodeMap_get_length( attr_map
, &num
);
1159 ok( r
== S_OK
, "returns %08x\n", r
);
1160 ok( num
== 0, "num %ld\n", num
);
1161 IXMLDOMNamedNodeMap_Release( attr_map
);
1163 V_VT(&var
) = VT_BSTR
;
1164 V_BSTR(&var
) = SysAllocString( szstr1
);
1165 name
= SysAllocString( szdl
);
1166 r
= IXMLDOMElement_setAttribute( element
, name
, var
);
1167 ok( r
== S_OK
, "returns %08x\n", r
);
1168 r
= IXMLDOMElement_get_attributes( element
, &attr_map
);
1169 ok( r
== S_OK
, "returns %08x\n", r
);
1170 r
= IXMLDOMNamedNodeMap_get_length( attr_map
, &num
);
1171 ok( r
== S_OK
, "returns %08x\n", r
);
1172 ok( num
== 1, "num %ld\n", num
);
1173 IXMLDOMNamedNodeMap_Release( attr_map
);
1176 V_VT(&var
) = VT_BSTR
;
1177 V_BSTR(&var
) = SysAllocString( szstr2
);
1178 r
= IXMLDOMElement_setAttribute( element
, name
, var
);
1179 ok( r
== S_OK
, "returns %08x\n", r
);
1180 r
= IXMLDOMElement_get_attributes( element
, &attr_map
);
1181 ok( r
== S_OK
, "returns %08x\n", r
);
1182 r
= IXMLDOMNamedNodeMap_get_length( attr_map
, &num
);
1183 ok( r
== S_OK
, "returns %08x\n", r
);
1184 ok( num
== 1, "num %ld\n", num
);
1185 IXMLDOMNamedNodeMap_Release( attr_map
);
1187 r
= IXMLDOMElement_getAttribute( element
, name
, &var
);
1188 ok( r
== S_OK
, "returns %08x\n", r
);
1189 ok( !lstrcmpW(V_BSTR(&var
), szstr2
), "wrong attr value\n");
1191 SysFreeString(name
);
1193 V_VT(&var
) = VT_BSTR
;
1194 V_BSTR(&var
) = SysAllocString( szstr1
);
1195 name
= SysAllocString( szlc
);
1196 r
= IXMLDOMElement_setAttribute( element
, name
, var
);
1197 ok( r
== S_OK
, "returns %08x\n", r
);
1198 r
= IXMLDOMElement_get_attributes( element
, &attr_map
);
1199 ok( r
== S_OK
, "returns %08x\n", r
);
1200 r
= IXMLDOMNamedNodeMap_get_length( attr_map
, &num
);
1201 ok( r
== S_OK
, "returns %08x\n", r
);
1202 ok( num
== 2, "num %ld\n", num
);
1203 IXMLDOMNamedNodeMap_Release( attr_map
);
1205 SysFreeString(name
);
1209 name
= SysAllocString( szbs
);
1210 r
= IXMLDOMElement_setAttribute( element
, name
, var
);
1211 ok( r
== S_OK
, "returns %08x\n", r
);
1213 r
= IXMLDOMElement_getAttribute( element
, name
, &var
);
1214 ok( r
== S_OK
, "returns %08x\n", r
);
1215 ok( V_VT(&var
) == VT_BSTR
, "variant type %x\n", V_VT(&var
));
1217 SysFreeString(name
);
1219 IXMLDOMElement_Release( element
);
1220 IXMLDOMNode_Release( root
);
1221 IXMLDOMDocument_Release( doc
);
1224 static void test_getElementsByTagName(void)
1229 IXMLDOMDocument
*doc
;
1230 IXMLDOMNodeList
*node_list
;
1233 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1234 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
1238 str
= SysAllocString( szComplete4
);
1239 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
1240 ok( r
== S_OK
, "loadXML failed\n");
1241 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
1242 SysFreeString( str
);
1244 str
= SysAllocString( szstar
);
1245 r
= IXMLDOMDocument_getElementsByTagName(doc
, str
, &node_list
);
1246 ok( r
== S_OK
, "ret %08x\n", r
);
1247 r
= IXMLDOMNodeList_get_length( node_list
, &len
);
1248 ok( r
== S_OK
, "ret %08x\n", r
);
1249 ok( len
== 6, "len %ld\n", len
);
1250 IXMLDOMNodeList_Release( node_list
);
1251 SysFreeString( str
);
1253 str
= SysAllocString( szbs
);
1254 r
= IXMLDOMDocument_getElementsByTagName(doc
, str
, &node_list
);
1255 ok( r
== S_OK
, "ret %08x\n", r
);
1256 r
= IXMLDOMNodeList_get_length( node_list
, &len
);
1257 ok( r
== S_OK
, "ret %08x\n", r
);
1258 ok( len
== 1, "len %ld\n", len
);
1259 IXMLDOMNodeList_Release( node_list
);
1260 SysFreeString( str
);
1262 str
= SysAllocString( szdl
);
1263 r
= IXMLDOMDocument_getElementsByTagName(doc
, str
, &node_list
);
1264 ok( r
== S_OK
, "ret %08x\n", r
);
1265 r
= IXMLDOMNodeList_get_length( node_list
, &len
);
1266 ok( r
== S_OK
, "ret %08x\n", r
);
1267 ok( len
== 0, "len %ld\n", len
);
1268 IXMLDOMNodeList_Release( node_list
);
1269 SysFreeString( str
);
1271 str
= SysAllocString( szstr1
);
1272 r
= IXMLDOMDocument_getElementsByTagName(doc
, str
, &node_list
);
1273 ok( r
== S_OK
, "ret %08x\n", r
);
1274 r
= IXMLDOMNodeList_get_length( node_list
, &len
);
1275 ok( r
== S_OK
, "ret %08x\n", r
);
1276 ok( len
== 0, "len %ld\n", len
);
1277 IXMLDOMNodeList_Release( node_list
);
1278 SysFreeString( str
);
1280 IXMLDOMDocument_Release( doc
);
1283 static void test_get_text(void)
1288 IXMLDOMDocument
*doc
;
1289 IXMLDOMNode
*node
, *node2
, *node3
;
1290 IXMLDOMNodeList
*node_list
;
1291 IXMLDOMNamedNodeMap
*node_map
;
1293 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1294 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
1298 str
= SysAllocString( szComplete4
);
1299 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
1300 ok( r
== S_OK
, "loadXML failed\n");
1301 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
1302 SysFreeString( str
);
1304 str
= SysAllocString( szbs
);
1305 r
= IXMLDOMDocument_getElementsByTagName( doc
, str
, &node_list
);
1306 ok( r
== S_OK
, "ret %08x\n", r
);
1309 r
= IXMLDOMNodeList_get_item( node_list
, 0, &node
);
1310 ok( r
== S_OK
, "ret %08x\n", r
);
1311 IXMLDOMNodeList_Release( node_list
);
1313 /* Invalid output parameter*/
1314 r
= IXMLDOMNode_get_text( node
, NULL
);
1315 ok( r
== E_INVALIDARG
, "ret %08x\n", r
);
1317 r
= IXMLDOMNode_get_text( node
, &str
);
1318 ok( r
== S_OK
, "ret %08x\n", r
);
1320 ok( !memcmp(str
, szfn1_txt
, sizeof(szfn1_txt
)), "wrong string\n" );
1322 ok( !memcmp(str
, szfn1_txt
, sizeof(szfn1_txt
)-4), "wrong string\n" );
1325 r
= IXMLDOMNode_get_attributes( node
, &node_map
);
1326 ok( r
== S_OK
, "ret %08x\n", r
);
1328 str
= SysAllocString( szvr
);
1329 r
= IXMLDOMNamedNodeMap_getNamedItem( node_map
, str
, &node2
);
1330 ok( r
== S_OK
, "ret %08x\n", r
);
1333 r
= IXMLDOMNode_get_text( node2
, &str
);
1334 ok( r
== S_OK
, "ret %08x\n", r
);
1335 ok( !memcmp(str
, szstr2
, sizeof(szstr2
)), "wrong string\n" );
1338 r
= IXMLDOMNode_get_firstChild( node2
, &node3
);
1339 ok( r
== S_OK
, "ret %08x\n", r
);
1341 r
= IXMLDOMNode_get_text( node3
, &str
);
1342 ok( r
== S_OK
, "ret %08x\n", r
);
1343 ok( !memcmp(str
, szstr2
, sizeof(szstr2
)), "wrong string\n" );
1347 IXMLDOMNode_Release( node3
);
1348 IXMLDOMNode_Release( node2
);
1349 IXMLDOMNamedNodeMap_Release( node_map
);
1350 IXMLDOMNode_Release( node
);
1351 IXMLDOMDocument_Release( doc
);
1354 static void test_get_childNodes(void)
1359 IXMLDOMDocument
*doc
;
1360 IXMLDOMElement
*element
;
1361 IXMLDOMNode
*node
, *node2
;
1362 IXMLDOMNodeList
*node_list
, *node_list2
;
1365 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1366 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
1370 str
= SysAllocString( szComplete4
);
1371 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
1372 ok( r
== S_OK
, "loadXML failed\n");
1373 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
1374 SysFreeString( str
);
1376 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
1377 ok( r
== S_OK
, "ret %08x\n", r
);
1379 r
= IXMLDOMElement_get_childNodes( element
, &node_list
);
1380 ok( r
== S_OK
, "ret %08x\n", r
);
1382 r
= IXMLDOMNodeList_get_length( node_list
, &len
);
1383 ok( r
== S_OK
, "ret %08x\n", r
);
1384 ok( len
== 4, "len %ld\n", len
);
1386 r
= IXMLDOMNodeList_get_item( node_list
, 2, &node
);
1387 ok( r
== S_OK
, "ret %08x\n", r
);
1389 r
= IXMLDOMNode_get_childNodes( node
, &node_list2
);
1390 ok( r
== S_OK
, "ret %08x\n", r
);
1392 r
= IXMLDOMNodeList_get_length( node_list2
, &len
);
1393 ok( r
== S_OK
, "ret %08x\n", r
);
1394 ok( len
== 0, "len %ld\n", len
);
1396 r
= IXMLDOMNodeList_get_item( node_list2
, 0, &node2
);
1397 ok( r
== S_FALSE
, "ret %08x\n", r
);
1399 IXMLDOMNodeList_Release( node_list2
);
1400 IXMLDOMNode_Release( node
);
1401 IXMLDOMNodeList_Release( node_list
);
1402 IXMLDOMElement_Release( element
);
1403 IXMLDOMDocument_Release( doc
);
1406 static void test_removeChild(void)
1411 IXMLDOMDocument
*doc
;
1412 IXMLDOMElement
*element
;
1413 IXMLDOMNode
*node
, *node2
, *node3
, *node4
;
1414 IXMLDOMNodeList
*node_list
, *node_list2
;
1416 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1417 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
1421 str
= SysAllocString( szComplete4
);
1422 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
1423 ok( r
== S_OK
, "loadXML failed\n");
1424 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
1425 SysFreeString( str
);
1427 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
1428 ok( r
== S_OK
, "ret %08x\n", r
);
1430 r
= IXMLDOMElement_get_childNodes( element
, &node_list
);
1431 ok( r
== S_OK
, "ret %08x\n", r
);
1433 r
= IXMLDOMNodeList_get_item( node_list
, 3, &node
);
1434 ok( r
== S_OK
, "ret %08x\n", r
);
1436 r
= IXMLDOMNode_get_childNodes( node
, &node_list2
);
1437 ok( r
== S_OK
, "ret %08x\n", r
);
1439 r
= IXMLDOMNodeList_get_item( node_list
, 0, &node4
);
1440 ok( r
== S_OK
, "ret %08x\n", r
);
1442 r
= IXMLDOMElement_removeChild( element
, NULL
, &node2
);
1443 ok( r
== E_INVALIDARG
, "ret %08x\n", r
);
1445 r
= IXMLDOMElement_removeChild( element
, node4
, &node2
);
1446 ok( r
== S_OK
, "ret %08x\n", r
);
1447 ok( node4
== node2
, "node %p node2 %p\n", node4
, node2
);
1449 r
= IXMLDOMNode_get_parentNode( node4
, &node3
);
1450 ok( r
== S_FALSE
, "ret %08x\n", r
);
1451 ok( node3
== NULL
, "%p\n", node3
);
1453 IXMLDOMNode_Release( node2
);
1454 IXMLDOMNode_Release( node4
);
1455 IXMLDOMNodeList_Release( node_list2
);
1456 IXMLDOMNode_Release( node
);
1457 IXMLDOMNodeList_Release( node_list
);
1458 IXMLDOMElement_Release( element
);
1459 IXMLDOMDocument_Release( doc
);
1462 static void test_XMLHTTP(void)
1464 static const WCHAR wszBody
[] = {'m','o','d','e','=','T','e','s','t',0};
1465 static WCHAR wszPOST
[] = {'P','O','S','T',0};
1466 static WCHAR wszUrl
[] = {'h','t','t','p',':','/','/',
1467 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1468 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1469 static const WCHAR wszExpectedResponse
[] = {'F','A','I','L','E','D',0};
1470 IXMLHttpRequest
*pXMLHttpRequest
;
1475 HRESULT hr
= CoCreateInstance(&CLSID_XMLHTTPRequest
, NULL
,
1476 CLSCTX_INPROC_SERVER
, &IID_IXMLHttpRequest
,
1477 (void **)&pXMLHttpRequest
);
1479 ok(hr
== S_OK
, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr
);
1484 VariantInit(&dummy
);
1485 V_VT(&dummy
) = VT_ERROR
;
1486 V_ERROR(&dummy
) = DISP_E_MEMBERNOTFOUND
;
1487 VariantInit(&varfalse
);
1488 V_VT(&varfalse
) = VT_BOOL
;
1489 V_BOOL(&varfalse
) = VARIANT_FALSE
;
1490 V_VT(&varbody
) = VT_BSTR
;
1491 V_BSTR(&varbody
) = SysAllocString(wszBody
);
1493 hr
= IXMLHttpRequest_open(pXMLHttpRequest
, wszPOST
, wszUrl
, varfalse
, dummy
, dummy
);
1494 ok(hr
== S_OK
, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr
);
1496 hr
= IXMLHttpRequest_send(pXMLHttpRequest
, varbody
);
1497 ok(hr
== S_OK
, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr
);
1498 VariantClear(&varbody
);
1500 hr
= IXMLHttpRequest_get_responseText(pXMLHttpRequest
, &bstrResponse
);
1501 ok(hr
== S_OK
, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr
);
1502 /* the server currently returns "FAILED" because the Content-Type header is
1503 * not what the server expects */
1504 ok(!memcmp(bstrResponse
, wszExpectedResponse
, sizeof(wszExpectedResponse
)), "bstrResponse differs from what was expected\n");
1505 SysFreeString(bstrResponse
);
1508 static void test_IXMLDOMDocument2(void)
1513 IXMLDOMDocument
*doc
;
1514 IXMLDOMDocument2
*doc2
;
1518 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1519 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
1523 str
= SysAllocString( szComplete4
);
1524 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
1525 ok( r
== S_OK
, "loadXML failed\n");
1526 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
1527 SysFreeString( str
);
1529 r
= IXMLDOMDocument_QueryInterface( doc
, &IID_IXMLDOMDocument2
, (void**)&doc2
);
1530 ok( r
== S_OK
, "ret %08x\n", r
);
1531 ok( doc
== (IXMLDOMDocument
*)doc2
, "interfaces differ\n");
1533 /* we will check if the variant got cleared */
1534 ref
= IXMLDOMDocument2_AddRef(doc2
);
1535 expect_eq(ref
, 3, int, "%d"); /* doc, doc2, AddRef*/
1536 V_VT(&var
) = VT_UNKNOWN
;
1537 V_UNKNOWN(&var
) = (IUnknown
*)doc2
;
1540 ole_expect(IXMLDOMDocument2_getProperty(doc2
, _bstr_("askldhfaklsdf"), &var
), E_FAIL
);
1541 expect_eq(V_VT(&var
), VT_UNKNOWN
, int, "%x");
1542 ole_expect(IXMLDOMDocument2_getProperty(doc2
, _bstr_("SelectionLanguage"), NULL
), E_INVALIDARG
);
1545 ole_check(IXMLDOMDocument2_getProperty(doc2
, _bstr_("SelectionLanguage"), &var
));
1546 expect_eq(V_VT(&var
), VT_BSTR
, int, "%x");
1547 expect_bstr_eq_and_free(V_BSTR(&var
), "XSLPattern");
1550 /* the variant didn't get cleared*/
1551 expect_eq(IXMLDOMDocument2_Release(doc2
), 2, int, "%d");
1553 /* setProperty tests */
1554 ole_expect(IXMLDOMDocument2_setProperty(doc2
, _bstr_("askldhfaklsdf"), var
), E_FAIL
);
1555 ole_expect(IXMLDOMDocument2_setProperty(doc2
, _bstr_("SelectionLanguage"), var
), E_FAIL
);
1556 ole_expect(IXMLDOMDocument2_setProperty(doc2
, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL
);
1557 ole_check(IXMLDOMDocument2_setProperty(doc2
, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1558 ole_check(IXMLDOMDocument2_setProperty(doc2
, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1559 ole_check(IXMLDOMDocument2_setProperty(doc2
, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1561 /* contrary to what MSDN calims you can switch back from XPath to XSLPattern */
1562 ole_check(IXMLDOMDocument2_getProperty(doc2
, _bstr_("SelectionLanguage"), &var
));
1563 expect_eq(V_VT(&var
), VT_BSTR
, int, "%x");
1564 expect_bstr_eq_and_free(V_BSTR(&var
), "XSLPattern");
1566 IXMLDOMDocument2_Release( doc2
);
1567 IXMLDOMDocument_Release( doc
);
1571 static void test_XPath(void)
1576 IXMLDOMDocument2
*doc
;
1577 IXMLDOMNode
*rootNode
;
1578 IXMLDOMNode
*elem1Node
;
1580 IXMLDOMNodeList
*list
;
1582 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
1583 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument2
, (LPVOID
*)&doc
);
1587 ole_check(IXMLDOMDocument_loadXML(doc
, _bstr_(szExampleXML
), &b
));
1588 ok(b
== VARIANT_TRUE
, "failed to load XML string\n");
1590 /* switch to XPath */
1591 ole_check(IXMLDOMDocument2_setProperty(doc
, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1593 /* some simple queries*/
1594 ole_check(IXMLDOMDocument_selectNodes(doc
, _bstr_("root"), &list
));
1595 ole_check(IXMLDOMNodeList_get_item(list
, 0, &rootNode
));
1596 ole_check(IXMLDOMNodeList_reset(list
));
1597 expect_list_and_release(list
, "E2.D1");
1598 if (rootNode
== NULL
)
1601 ole_check(IXMLDOMDocument_selectNodes(doc
, _bstr_("root//c"), &list
));
1602 expect_list_and_release(list
, "E3.E1.E2.D1 E3.E2.E2.D1");
1604 ole_check(IXMLDOMDocument_selectNodes(doc
, _bstr_("//c[@type]"), &list
));
1605 expect_list_and_release(list
, "E3.E2.E2.D1");
1607 ole_check(IXMLDOMNode_selectNodes(rootNode
, _bstr_("elem"), &list
));
1608 /* using get_item for query results advances the position */
1609 ole_check(IXMLDOMNodeList_get_item(list
, 1, &node
));
1610 expect_node(node
, "E2.E2.D1");
1611 IXMLDOMNode_Release(node
);
1612 ole_check(IXMLDOMNodeList_nextNode(list
, &node
));
1613 expect_node(node
, "E4.E2.D1");
1614 IXMLDOMNode_Release(node
);
1615 ole_check(IXMLDOMNodeList_reset(list
));
1616 expect_list_and_release(list
, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1618 ole_check(IXMLDOMNode_selectNodes(rootNode
, _bstr_("."), &list
));
1619 expect_list_and_release(list
, "E2.D1");
1621 ole_check(IXMLDOMNode_selectNodes(rootNode
, _bstr_("elem[3]/preceding-sibling::*"), &list
));
1622 ole_check(IXMLDOMNodeList_get_item(list
, 0, &elem1Node
));
1623 ole_check(IXMLDOMNodeList_reset(list
));
1624 expect_list_and_release(list
, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1626 /* select an attribute */
1627 ole_check(IXMLDOMNode_selectNodes(rootNode
, _bstr_(".//@type"), &list
));
1628 expect_list_and_release(list
, "A'type'.E3.E2.E2.D1");
1630 /* would evaluate to a number */
1631 ole_expect(IXMLDOMNode_selectNodes(rootNode
, _bstr_("count(*)"), &list
), E_FAIL
);
1632 /* would evaluate to a boolean */
1633 ole_expect(IXMLDOMNode_selectNodes(rootNode
, _bstr_("position()>0"), &list
), E_FAIL
);
1634 /* would evaluate to a string */
1635 ole_expect(IXMLDOMNode_selectNodes(rootNode
, _bstr_("name()"), &list
), E_FAIL
);
1638 ole_check(IXMLDOMNode_selectNodes(rootNode
, _bstr_("c"), &list
));
1639 expect_list_and_release(list
, "");
1640 ole_check(IXMLDOMDocument_selectNodes(doc
, _bstr_("elem//c"), &list
));
1641 expect_list_and_release(list
, "");
1642 ole_check(IXMLDOMDocument_selectNodes(doc
, _bstr_("//elem[4]"), &list
));
1643 expect_list_and_release(list
, "");
1645 /* foo undeclared in document node */
1646 ole_expect(IXMLDOMDocument_selectNodes(doc
, _bstr_("root//foo:c"), &list
), E_FAIL
);
1647 /* undeclared in <root> node */
1648 ole_expect(IXMLDOMNode_selectNodes(rootNode
, _bstr_(".//foo:c"), &list
), E_FAIL
);
1649 /* undeclared in <elem> node */
1650 ole_expect(IXMLDOMNode_selectNodes(elem1Node
, _bstr_("//foo:c"), &list
), E_FAIL
);
1651 /* but this trick can be used */
1652 ole_check(IXMLDOMNode_selectNodes(elem1Node
, _bstr_("//*[name()='foo:c']"), &list
));
1653 expect_list_and_release(list
, "E3.E4.E2.D1");
1655 /* it has to be declared in SelectionNamespaces */
1656 todo_wine
ole_check(IXMLDOMDocument2_setProperty(doc
, _bstr_("SelectionNamespaces"),
1657 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
1659 /* now the namespace can be used */
1660 todo_wine
ole_check(IXMLDOMDocument_selectNodes(doc
, _bstr_("root//test:c"), &list
));
1661 todo_wine
expect_list_and_release(list
, "E3.E3.E2.D1 E3.E4.E2.D1");
1662 todo_wine
ole_check(IXMLDOMNode_selectNodes(rootNode
, _bstr_(".//test:c"), &list
));
1663 todo_wine
expect_list_and_release(list
, "E3.E3.E2.D1 E3.E4.E2.D1");
1664 todo_wine
ole_check(IXMLDOMNode_selectNodes(elem1Node
, _bstr_("//test:c"), &list
));
1665 todo_wine
expect_list_and_release(list
, "E3.E3.E2.D1 E3.E4.E2.D1");
1666 todo_wine
ole_check(IXMLDOMNode_selectNodes(elem1Node
, _bstr_(".//test:x"), &list
));
1667 todo_wine
expect_list_and_release(list
, "E5.E1.E4.E1.E2.D1");
1669 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
1670 ole_expect(IXMLDOMDocument2_setProperty(doc
, _bstr_("SelectionNamespaces"),
1671 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL
);
1673 ole_expect(IXMLDOMDocument_selectNodes(doc
, _bstr_("root//foo:c"), &list
), E_FAIL
);
1675 todo_wine
ole_check(IXMLDOMDocument2_getProperty(doc
, _bstr_("SelectionNamespaces"), &var
));
1676 todo_wine
expect_eq(V_VT(&var
), VT_BSTR
, int, "%x");
1677 if (V_VT(&var
) == VT_BSTR
)
1678 expect_bstr_eq_and_free(V_BSTR(&var
), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
1680 /* extra attributes - same thing*/
1681 ole_expect(IXMLDOMDocument2_setProperty(doc
, _bstr_("SelectionNamespaces"),
1682 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL
);
1683 ole_expect(IXMLDOMDocument_selectNodes(doc
, _bstr_("root//foo:c"), &list
), E_FAIL
);
1685 IXMLDOMNode_Release(rootNode
);
1686 IXMLDOMNode_Release(elem1Node
);
1687 IXMLDOMDocument_Release(doc
);
1691 static void test_cloneNode(void )
1693 IXMLDOMDocument
*doc
= NULL
;
1695 IXMLDOMNodeList
*pList
;
1696 IXMLDOMNamedNodeMap
*mapAttr
;
1697 long nLength
= 0, nLength1
= 0;
1698 long nAttrCnt
= 0, nAttrCnt1
= 0;
1700 IXMLDOMNode
*node_clone
;
1703 static const WCHAR szSearch
[] = { 'l', 'c', '/', 'p', 'r', 0 };
1705 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument2
, (LPVOID
*)&doc
);
1709 str
= SysAllocString( szComplete4
);
1710 ole_check(IXMLDOMDocument_loadXML(doc
, str
, &b
));
1711 ok(b
== VARIANT_TRUE
, "failed to load XML string\n");
1717 str
= SysAllocString( szSearch
);
1718 r
= IXMLDOMNode_selectSingleNode(doc
, str
, &node
);
1719 ok( r
== S_OK
, "ret %08x\n", r
);
1720 ok( node
!= NULL
, "node %p\n", node
);
1725 IXMLDOMDocument_Release(doc
);
1729 /* Check invalid parameter */
1730 r
= IXMLDOMNode_cloneNode(node
, VARIANT_TRUE
, NULL
);
1731 ok( r
== E_INVALIDARG
, "ret %08x\n", r
);
1734 r
= IXMLDOMNode_cloneNode(node
, VARIANT_TRUE
, &node_clone
);
1735 ok( r
== S_OK
, "ret %08x\n", r
);
1736 ok( node_clone
!= NULL
, "node %p\n", node
);
1740 IXMLDOMDocument_Release(doc
);
1741 IXMLDOMNode_Release(node
);
1745 r
= IXMLDOMNode_get_childNodes(node
, &pList
);
1746 ok( r
== S_OK
, "ret %08x\n", r
);
1749 IXMLDOMNodeList_get_length(pList
, &nLength
);
1750 IXMLDOMNodeList_Release(pList
);
1753 r
= IXMLDOMNode_get_attributes(node
, &mapAttr
);
1754 ok( r
== S_OK
, "ret %08x\n", r
);
1757 IXMLDOMNamedNodeMap_get_length(mapAttr
, &nAttrCnt
);
1758 IXMLDOMNamedNodeMap_Release(mapAttr
);
1761 r
= IXMLDOMNode_get_childNodes(node_clone
, &pList
);
1762 ok( r
== S_OK
, "ret %08x\n", r
);
1765 IXMLDOMNodeList_get_length(pList
, &nLength1
);
1766 IXMLDOMNodeList_Release(pList
);
1769 r
= IXMLDOMNode_get_attributes(node_clone
, &mapAttr
);
1770 ok( r
== S_OK
, "ret %08x\n", r
);
1773 IXMLDOMNamedNodeMap_get_length(mapAttr
, &nAttrCnt1
);
1774 IXMLDOMNamedNodeMap_Release(mapAttr
);
1777 ok(nLength
== nLength1
, "wrong Child count (%ld, %ld)\n", nLength
, nLength1
);
1778 ok(nAttrCnt
== nAttrCnt1
, "wrong Attribute count (%ld, %ld)\n", nAttrCnt
, nAttrCnt1
);
1779 IXMLDOMNode_Release(node_clone
);
1782 r
= IXMLDOMNode_cloneNode(node
, VARIANT_FALSE
, &node_clone
);
1783 ok( r
== S_OK
, "ret %08x\n", r
);
1784 ok( node_clone
!= NULL
, "node %p\n", node
);
1788 IXMLDOMDocument_Release(doc
);
1789 IXMLDOMNode_Release(node
);
1793 r
= IXMLDOMNode_get_childNodes(node_clone
, &pList
);
1794 ok( r
== S_OK
, "ret %08x\n", r
);
1797 IXMLDOMNodeList_get_length(pList
, &nLength1
);
1798 ok( nLength1
== 0, "Length should be 0 (%ld)\n", nLength1
);
1799 IXMLDOMNodeList_Release(pList
);
1802 r
= IXMLDOMNode_get_attributes(node_clone
, &mapAttr
);
1803 ok( r
== S_OK
, "ret %08x\n", r
);
1806 IXMLDOMNamedNodeMap_get_length(mapAttr
, &nAttrCnt1
);
1807 ok( nAttrCnt1
== 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1
);
1808 IXMLDOMNamedNodeMap_Release(mapAttr
);
1811 ok(nLength
!= nLength1
, "wrong Child count (%ld, %ld)\n", nLength
, nLength1
);
1812 ok(nAttrCnt
== nAttrCnt1
, "wrong Attribute count (%ld, %ld)\n", nAttrCnt
, nAttrCnt1
);
1813 IXMLDOMNode_Release(node_clone
);
1816 IXMLDOMNode_Release(node
);
1817 IXMLDOMDocument_Release(doc
);
1820 static void test_xmlTypes(void)
1822 IXMLDOMDocument
*doc
= NULL
;
1823 IXMLDOMElement
*pRoot
;
1825 IXMLDOMComment
*pComment
;
1826 IXMLDOMElement
*pElement
;
1827 IXMLDOMAttribute
*pAttrubute
;
1828 IXMLDOMNamedNodeMap
*pAttribs
;
1830 IXMLDOMNode
*pNextChild
= (IXMLDOMNode
*)0x1; /* Used for testing Siblings */
1832 hr
= CoCreateInstance( &CLSID_DOMDocument
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument2
, (LPVOID
*)&doc
);
1836 hr
= IXMLDOMDocument_get_nextSibling(doc
, NULL
);
1837 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
1839 hr
= IXMLDOMDocument_get_nextSibling(doc
, &pNextChild
);
1840 ok(hr
== S_FALSE
, "ret %08x\n", hr
);
1841 ok(pNextChild
== NULL
, "pDocChild not NULL\n");
1843 /* test previous Sibling */
1844 hr
= IXMLDOMDocument_get_previousSibling(doc
, NULL
);
1845 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
1847 pNextChild
= (IXMLDOMNode
*)0x1;
1848 hr
= IXMLDOMDocument_get_previousSibling(doc
, &pNextChild
);
1849 ok(hr
== S_FALSE
, "ret %08x\n", hr
);
1850 ok(pNextChild
== NULL
, "pNextChild not NULL\n");
1852 /* test get_attributes */
1853 hr
= IXMLDOMDocument_get_attributes( doc
, NULL
);
1854 ok( hr
== E_INVALIDARG
, "get_attributes returned wrong code\n");
1856 pAttribs
= (IXMLDOMNamedNodeMap
*)0x1;
1857 hr
= IXMLDOMDocument_get_attributes( doc
, &pAttribs
);
1858 ok(hr
== S_FALSE
, "ret %08x\n", hr
);
1859 ok( pAttribs
== NULL
, "pAttribs not NULL\n");
1861 hr
= IXMLDOMDocument_createElement(doc
, _bstr_("Testing"), &pRoot
);
1862 ok(hr
== S_OK
, "ret %08x\n", hr
);
1865 hr
= IXMLDOMDocument_appendChild(doc
, (IXMLDOMNode
*)pRoot
, NULL
);
1866 ok(hr
== S_OK
, "ret %08x\n", hr
);
1870 hr
= IXMLDOMDocument_createComment(doc
, szComment
, &pComment
);
1871 ok(hr
== S_OK
, "ret %08x\n", hr
);
1874 /* test get_attributes */
1875 hr
= IXMLDOMComment_get_attributes( pComment
, NULL
);
1876 ok( hr
== E_INVALIDARG
, "get_attributes returned wrong code\n");
1878 pAttribs
= (IXMLDOMNamedNodeMap
*)0x1;
1879 hr
= IXMLDOMComment_get_attributes( pComment
, &pAttribs
);
1880 ok(hr
== S_FALSE
, "ret %08x\n", hr
);
1881 ok( pAttribs
== NULL
, "pAttribs not NULL\n");
1883 hr
= IXMLDOMElement_appendChild(pRoot
, (IXMLDOMNode
*)pComment
, NULL
);
1884 ok(hr
== S_OK
, "ret %08x\n", hr
);
1886 hr
= IXMLDOMComment_get_nodeName(pComment
, &str
);
1887 ok(hr
== S_OK
, "ret %08x\n", hr
);
1888 ok( !lstrcmpW( str
, szCommentNodeText
), "incorrect comment node Name\n");
1891 hr
= IXMLDOMComment_get_xml(pComment
, &str
);
1892 ok(hr
== S_OK
, "ret %08x\n", hr
);
1893 ok( !lstrcmpW( str
, szCommentXML
), "incorrect comment xml\n");
1896 IXMLDOMComment_Release(pComment
);
1900 hr
= IXMLDOMDocument_createElement(doc
, szElement
, &pElement
);
1901 ok(hr
== S_OK
, "ret %08x\n", hr
);
1904 hr
= IXMLDOMElement_appendChild(pRoot
, (IXMLDOMNode
*)pElement
, NULL
);
1905 ok(hr
== S_OK
, "ret %08x\n", hr
);
1907 hr
= IXMLDOMElement_get_nodeName(pElement
, &str
);
1908 ok(hr
== S_OK
, "ret %08x\n", hr
);
1909 ok( !lstrcmpW( str
, szElement
), "incorrect element node Name\n");
1912 hr
= IXMLDOMElement_get_xml(pElement
, &str
);
1913 ok(hr
== S_OK
, "ret %08x\n", hr
);
1914 ok( !lstrcmpW( str
, szElementXML
), "incorrect element xml\n");
1918 hr
= IXMLDOMDocument_createAttribute(doc
, szAttribute
, &pAttrubute
);
1919 ok(hr
== S_OK
, "ret %08x\n", hr
);
1922 IXMLDOMNode
*pNewChild
= (IXMLDOMNode
*)0x1;
1924 hr
= IXMLDOMAttribute_get_nextSibling(pAttrubute
, NULL
);
1925 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
1927 pNextChild
= (IXMLDOMNode
*)0x1;
1928 hr
= IXMLDOMAttribute_get_nextSibling(pAttrubute
, &pNextChild
);
1929 ok(hr
== S_FALSE
, "ret %08x\n", hr
);
1930 ok(pNextChild
== NULL
, "pNextChild not NULL\n");
1932 /* test Previous Sibling*/
1933 hr
= IXMLDOMAttribute_get_previousSibling(pAttrubute
, NULL
);
1934 ok(hr
== E_INVALIDARG
, "ret %08x\n", hr
);
1936 pNextChild
= (IXMLDOMNode
*)0x1;
1937 hr
= IXMLDOMAttribute_get_previousSibling(pAttrubute
, &pNextChild
);
1938 ok(hr
== S_FALSE
, "ret %08x\n", hr
);
1939 ok(pNextChild
== NULL
, "pNextChild not NULL\n");
1941 /* test get_attributes */
1942 hr
= IXMLDOMAttribute_get_attributes( pAttrubute
, NULL
);
1943 ok( hr
== E_INVALIDARG
, "get_attributes returned wrong code\n");
1945 pAttribs
= (IXMLDOMNamedNodeMap
*)0x1;
1946 hr
= IXMLDOMAttribute_get_attributes( pAttrubute
, &pAttribs
);
1947 ok(hr
== S_FALSE
, "ret %08x\n", hr
);
1948 ok( pAttribs
== NULL
, "pAttribs not NULL\n");
1950 hr
= IXMLDOMElement_appendChild(pElement
, (IXMLDOMNode
*)pAttrubute
, &pNewChild
);
1951 ok(hr
== E_FAIL
, "ret %08x\n", hr
);
1952 ok(pNewChild
== NULL
, "pNewChild not NULL\n");
1954 hr
= IXMLDOMElement_get_attributes(pElement
, &pAttribs
);
1955 ok(hr
== S_OK
, "ret %08x\n", hr
);
1958 hr
= IXMLDOMNamedNodeMap_setNamedItem(pAttribs
, (IXMLDOMNode
*)pAttrubute
, NULL
);
1959 ok(hr
== S_OK
, "ret %08x\n", hr
);
1961 IXMLDOMNamedNodeMap_Release(pAttribs
);
1964 hr
= IXMLDOMAttribute_get_nodeName(pAttrubute
, &str
);
1965 ok(hr
== S_OK
, "ret %08x\n", hr
);
1966 ok( !lstrcmpW( str
, szAttribute
), "incorrect attribute node Name\n");
1969 hr
= IXMLDOMAttribute_get_xml(pAttrubute
, &str
);
1970 ok(hr
== S_OK
, "ret %08x\n", hr
);
1971 ok( !lstrcmpW( str
, szAttributeXML
), "incorrect attribute xml\n");
1974 IXMLDOMAttribute_Release(pAttrubute
);
1976 /* Check Element again with the Add Attribute*/
1977 hr
= IXMLDOMElement_get_xml(pElement
, &str
);
1978 ok(hr
== S_OK
, "ret %08x\n", hr
);
1979 ok( !lstrcmpW( str
, szElementXML2
), "incorrect element xml\n");
1983 IXMLDOMElement_Release(pElement
);
1986 IXMLDOMElement_Release( pRoot
);
1990 IXMLDOMDocument_Release(doc
);
1997 r
= CoInitialize( NULL
);
1998 ok( r
== S_OK
, "failed to init com\n");
2004 test_getElementsByTagName();
2006 test_get_childNodes();
2009 test_IXMLDOMDocument2();