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
30 #include "wine/test.h"
32 const CLSID CLSID_DOMDocument2 = {0xf6d90f11, 0x9c73, 0x11d3, {0xb3, 0x2e, 0x00,0xc0, 0x4f, 0x99, 0x0b, 0xb4}};
34 static const WCHAR szEmpty[] = { 0 };
35 static const WCHAR szIncomplete[] = {
36 '<','?','x','m','l',' ',
37 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
39 static const WCHAR szComplete1[] = {
40 '<','?','x','m','l',' ',
41 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
42 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
44 static const WCHAR szComplete2[] = {
45 '<','?','x','m','l',' ',
46 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
47 '<','o','>','<','/','o','>','\n',0
49 static const WCHAR szComplete3[] = {
50 '<','?','x','m','l',' ',
51 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
52 '<','a','>','<','/','a','>','\n',0
54 static const WCHAR szComplete4[] = {
55 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
56 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
57 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
58 'f','n','1','.','t','x','t','\n',
59 '<','/','b','s','>','\n',
60 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
61 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
62 'f','n','2','.','t','x','t','\n',
63 '<','/','p','r','>','\n',
64 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
68 '<','/','b','a','>','\n',
69 '<','/','f','o','>','\n',
70 '<','/','l','c','>','\n',0
72 static const WCHAR szComplete5[] = {
73 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
74 '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','"',
75 ' ','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','"','>',
76 '<','S',':','s','c','o','p','e','>',
77 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
78 '<','/','S',':','s','c','o','p','e','>',
79 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
80 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
81 'c','o','m','p','u','t','e','r',
82 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
83 '<','/','S',':','s','e','a','r','c','h','>',0
86 static const WCHAR szNonExistentFile[] = {
87 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
89 static const WCHAR szDocument[] = {
90 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
93 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
94 static const WCHAR szdl[] = { 'd','l',0 };
95 static const WCHAR szvr[] = { 'v','r',0 };
96 static const WCHAR szlc[] = { 'l','c',0 };
97 static const WCHAR szbs[] = { 'b','s',0 };
98 static const WCHAR szstr1[] = { 's','t','r','1',0 };
99 static const WCHAR szstr2[] = { 's','t','r','2',0 };
100 static const WCHAR szstar[] = { '*',0 };
101 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
103 static void test_domdoc( void )
106 IXMLDOMDocument *doc = NULL;
107 IXMLDOMParseError *error;
108 IXMLDOMElement *element = NULL;
115 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
116 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
120 /* try some stupid things */
121 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
122 ok( r == S_FALSE, "loadXML failed\n");
125 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
126 ok( r == S_FALSE, "loadXML failed\n");
127 ok( b == VARIANT_FALSE, "failed to load XML string\n");
129 /* try to load a document from a nonexistent file */
131 str = SysAllocString( szNonExistentFile );
133 V_VT(&var) = VT_BSTR;
136 r = IXMLDOMDocument_load( doc, var, &b);
137 ok( r == S_FALSE, "load (from file) failed\n");
138 ok( b == VARIANT_FALSE, "failed to load XML file\n");
139 SysFreeString( str );
141 /* try load an empty document */
143 str = SysAllocString( szEmpty );
144 r = IXMLDOMDocument_loadXML( doc, str, &b );
145 ok( r == S_FALSE, "loadXML failed\n");
146 ok( b == VARIANT_FALSE, "failed to load XML string\n");
147 SysFreeString( str );
149 /* check that there's no document element */
151 r = IXMLDOMDocument_get_documentElement( doc, &element );
152 ok( r == S_FALSE, "should be no document element\n");
154 /* try finding a node */
156 str = SysAllocString( szstr1 );
157 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
158 ok( r == S_FALSE, "ret %08x\n", r );
159 SysFreeString( str );
162 str = SysAllocString( szIncomplete );
163 r = IXMLDOMDocument_loadXML( doc, str, &b );
164 ok( r == S_FALSE, "loadXML failed\n");
165 ok( b == VARIANT_FALSE, "failed to load XML string\n");
166 SysFreeString( str );
168 /* check that there's no document element */
169 element = (IXMLDOMElement*)1;
170 r = IXMLDOMDocument_get_documentElement( doc, &element );
171 ok( r == S_FALSE, "should be no document element\n");
172 ok( element == NULL, "Element should be NULL\n");
174 /* try to load something valid */
176 str = SysAllocString( szComplete1 );
177 r = IXMLDOMDocument_loadXML( doc, str, &b );
178 ok( r == S_OK, "loadXML failed\n");
179 ok( b == VARIANT_TRUE, "failed to load XML string\n");
180 SysFreeString( str );
182 /* try with a null out pointer - crashes */
185 r = IXMLDOMDocument_get_documentElement( doc, NULL );
186 ok( r == S_OK, "should be no document element\n");
189 /* check if nodename is correct */
190 r = IXMLDOMDocument_get_nodeName( doc, NULL );
191 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
193 /* content doesn't matter here */
194 str = SysAllocString( szNonExistentFile );
195 r = IXMLDOMDocument_get_nodeName( doc, &str );
196 ok ( r == S_OK, "get_nodeName wrong code\n");
197 ok ( str != NULL, "str is null\n");
198 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
199 SysFreeString( str );
202 /* check that there's a document element */
204 r = IXMLDOMDocument_get_documentElement( doc, &element );
205 ok( r == S_OK, "should be a document element\n");
210 /* check if the tag is correct */
211 r = IXMLDOMElement_get_tagName( element, &tag );
212 ok( r == S_OK, "couldn't get tag name\n");
213 ok( tag != NULL, "tag was null\n");
214 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
215 SysFreeString( tag );
217 /* figure out what happens if we try to reload the document */
218 str = SysAllocString( szComplete2 );
219 r = IXMLDOMDocument_loadXML( doc, str, &b );
220 ok( r == S_OK, "loadXML failed\n");
221 ok( b == VARIANT_TRUE, "failed to load XML string\n");
222 SysFreeString( str );
224 /* check if the tag is still correct */
226 r = IXMLDOMElement_get_tagName( element, &tag );
227 ok( r == S_OK, "couldn't get tag name\n");
228 ok( tag != NULL, "tag was null\n");
229 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
230 SysFreeString( tag );
232 IXMLDOMElement_Release( element );
236 /* as soon as we call loadXML again, the document element will disappear */
238 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
239 ok( r == S_FALSE, "loadXML failed\n");
240 ok( b == 2, "variant modified\n");
241 r = IXMLDOMDocument_get_documentElement( doc, &element );
242 ok( r == S_FALSE, "should be no document element\n");
244 /* try to load something else simple and valid */
246 str = SysAllocString( szComplete3 );
247 r = IXMLDOMDocument_loadXML( doc, str, &b );
248 ok( r == S_OK, "loadXML failed\n");
249 ok( b == VARIANT_TRUE, "failed to load XML string\n");
250 SysFreeString( str );
252 /* try something a little more complicated */
254 str = SysAllocString( szComplete4 );
255 r = IXMLDOMDocument_loadXML( doc, str, &b );
256 ok( r == S_OK, "loadXML failed\n");
257 ok( b == VARIANT_TRUE, "failed to load XML string\n");
258 SysFreeString( str );
260 r = IXMLDOMDocument_get_parseError( doc, &error );
261 ok( r == S_OK, "returns %08x\n", r );
263 r = IXMLDOMParseError_get_errorCode( error, &code );
264 ok( r == S_FALSE, "returns %08x\n", r );
265 ok( code == 0, "code %ld\n", code );
266 IXMLDOMParseError_Release( error );
268 r = IXMLDOMDocument_Release( doc );
269 ok( r == 0, "document ref count incorrect\n");
273 static void test_domnode( void )
276 IXMLDOMDocument *doc = NULL, *owner = NULL;
277 IXMLDOMElement *element = NULL;
278 IXMLDOMNamedNodeMap *map = NULL;
279 IXMLDOMNode *node = NULL, *next = NULL;
280 IXMLDOMNodeList *list = NULL;
281 DOMNodeType type = NODE_INVALID;
287 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
288 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
293 str = SysAllocString( szComplete4 );
294 r = IXMLDOMDocument_loadXML( doc, str, &b );
295 ok( r == S_OK, "loadXML failed\n");
296 ok( b == VARIANT_TRUE, "failed to load XML string\n");
297 SysFreeString( str );
302 r = IXMLDOMNode_hasChildNodes( doc, &b );
303 ok( r == S_OK, "hasChildNoes bad return\n");
304 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
306 r = IXMLDOMDocument_get_documentElement( doc, &element );
307 ok( r == S_OK, "should be a document element\n");
308 ok( element != NULL, "should be an element\n");
311 ok( FALSE, "no document\n");
314 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
315 r = IXMLDOMNode_get_nodeValue( doc, &var );
316 ok( r == S_FALSE, "nextNode returned wrong code\n");
317 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
318 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
323 r = IXMLDOMNode_get_ownerDocument( element, &owner );
325 ok( r == S_OK, "get_ownerDocument return code\n");
327 ok( owner != doc, "get_ownerDocument return\n");
330 r = IXMLDOMNode_get_nodeType( element, &type);
331 ok( r == S_OK, "getNamedItem returned wrong code\n");
332 ok( type == NODE_ELEMENT, "node not an element\n");
335 r = IXMLDOMNode_get_baseName( element, &str );
336 ok( r == S_OK, "get_baseName returned wrong code\n");
337 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
339 /* check if nodename is correct */
340 r = IXMLDOMElement_get_nodeName( element, NULL );
341 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
343 /* content doesn't matter here */
344 str = SysAllocString( szNonExistentFile );
345 r = IXMLDOMElement_get_nodeName( element, &str );
346 ok ( r == S_OK, "get_nodeName wrong code\n");
347 ok ( str != NULL, "str is null\n");
348 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
349 SysFreeString( str );
351 str = SysAllocString( szNonExistentFile );
354 r = IXMLDOMElement_getAttribute( element, str, &var );
355 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
356 ok( V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
358 SysFreeString( str );
360 str = SysAllocString( szdl );
363 r = IXMLDOMElement_getAttribute( element, str, &var );
364 ok( r == S_OK, "getAttribute ret %08x\n", r );
365 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
366 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
367 VariantClear( &var );
368 SysFreeString( str );
370 r = IXMLDOMElement_get_attributes( element, &map );
371 ok( r == S_OK, "get_attributes returned wrong code\n");
372 ok( map != NULL, "should be attributes\n");
375 r = IXMLDOMNode_hasChildNodes( element, &b );
376 ok( r == S_OK, "hasChildNoes bad return\n");
377 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
380 ok( FALSE, "no element\n");
384 ISupportErrorInfo *support_error;
385 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
386 ok( r == S_OK, "ret %08x\n", r );
388 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
391 ok( r == S_OK, "ret %08x\n", r );
393 ISupportErrorInfo_Release( support_error );
395 str = SysAllocString( szdl );
396 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
397 ok( r == S_OK, "getNamedItem returned wrong code\n");
398 ok( node != NULL, "should be attributes\n");
399 IXMLDOMNode_Release(node);
400 SysFreeString( str );
402 str = SysAllocString( szdl );
403 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
404 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
405 SysFreeString( str );
407 /* something that isn't in szComplete4 */
408 str = SysAllocString( szOpen );
409 node = (IXMLDOMNode *) 1;
410 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
411 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
412 ok( node == NULL, "getNamedItem should have returned NULL\n");
413 SysFreeString( str );
415 /* test indexed access of attributes */
416 r = IXMLDOMNamedNodeMap_get_length( map, &count );
417 ok ( r == S_OK, "get_length wrong code\n");
418 ok ( count == 1, "get_length != 1\n");
421 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
422 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
423 ok ( node == NULL, "there is no node\n");
426 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
427 ok ( r == S_FALSE, "get_item (1) wrong code\n");
428 ok ( node == NULL, "there is no attribute\n");
431 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
432 ok ( r == S_OK, "get_item (0) wrong code\n");
433 ok ( node != NULL, "should be attribute\n");
435 r = IXMLDOMNode_get_nodeName( node, NULL );
436 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
438 /* content doesn't matter here */
439 str = SysAllocString( szNonExistentFile );
440 r = IXMLDOMNode_get_nodeName( node, &str );
441 ok ( r == S_OK, "get_nodeName wrong code\n");
442 ok ( str != NULL, "str is null\n");
443 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
444 SysFreeString( str );
446 /* test sequential access of attributes */
448 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
449 ok ( r == S_OK, "nextNode (first time) wrong code\n");
450 ok ( node != NULL, "nextNode, should be attribute\n");
452 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
453 ok ( r != S_OK, "nextNode (second time) wrong code\n");
454 ok ( node == NULL, "nextNode, there is no attribute\n");
456 r = IXMLDOMNamedNodeMap_reset( map );
457 ok ( r == S_OK, "reset should return S_OK\n");
459 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
460 ok ( r == S_OK, "nextNode (third time) wrong code\n");
461 ok ( node != NULL, "nextNode, should be attribute\n");
464 ok( FALSE, "no map\n");
469 r = IXMLDOMNode_get_nodeType( node, &type);
470 ok( r == S_OK, "getNamedItem returned wrong code\n");
471 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
474 r = IXMLDOMNode_get_baseName( node, NULL );
475 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
478 r = IXMLDOMNode_get_baseName( node, &str );
479 ok( r == S_OK, "get_baseName returned wrong code\n");
480 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
482 r = IXMLDOMNode_get_nodeValue( node, &var );
483 ok( r == S_OK, "returns %08x\n", r );
484 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
485 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
488 r = IXMLDOMNode_get_childNodes( node, NULL );
489 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
491 r = IXMLDOMNode_get_childNodes( node, &list );
492 ok( r == S_OK, "get_childNodes returned wrong code\n");
496 r = IXMLDOMNodeList_nextNode( list, &next );
497 ok( r == S_OK, "nextNode returned wrong code\n");
500 ok( FALSE, "no childlist\n");
505 r = IXMLDOMNode_hasChildNodes( next, &b );
506 ok( r == S_FALSE, "hasChildNoes bad return\n");
507 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
510 r = IXMLDOMNode_get_nodeType( next, &type);
511 ok( r == S_OK, "getNamedItem returned wrong code\n");
512 ok( type == NODE_TEXT, "node not text\n");
515 r = IXMLDOMNode_get_baseName( next, &str );
516 ok( r == S_FALSE, "get_baseName returned wrong code\n");
517 ok( str == NULL, "basename was wrong\n");
520 ok( FALSE, "no next\n");
523 IXMLDOMNode_Release( next );
526 IXMLDOMNodeList_Release( list );
529 IXMLDOMNode_Release( node );
532 ok( FALSE, "no node\n");
536 IXMLDOMNamedNodeMap_Release( map );
538 /* now traverse the tree from the root node */
541 r = IXMLDOMNode_get_childNodes( element, &list );
542 ok( r == S_OK, "get_childNodes returned wrong code\n");
545 ok( FALSE, "no element\n");
547 node = (void*)0xdeadbeef;
548 r = IXMLDOMNode_selectSingleNode( element, (BSTR)szdl, &node );
549 ok( r == S_FALSE, "ret %08x\n", r );
550 ok( node == NULL, "node %p\n", node );
551 r = IXMLDOMNode_selectSingleNode( element, (BSTR)szbs, &node );
552 ok( r == S_OK, "ret %08x\n", r );
553 r = IXMLDOMNode_Release( node );
554 ok( r == 0, "ret %08x\n", r );
558 r = IXMLDOMNodeList_get_length( list, &count );
559 ok( r == S_OK, "get_length returns %08x\n", r );
560 ok( count == 4, "get_length got %ld\n", count );
562 r = IXMLDOMNodeList_nextNode( list, &node );
563 ok( r == S_OK, "nextNode returned wrong code\n");
566 ok( FALSE, "no list\n");
571 r = IXMLDOMNode_get_nodeType( node, &type);
572 ok( r == S_OK, "getNamedItem returned wrong code\n");
573 ok( type == NODE_ELEMENT, "node not text\n");
576 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
577 r = IXMLDOMNode_get_nodeValue( node, &var );
578 ok( r == S_FALSE, "nextNode returned wrong code\n");
579 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
580 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
582 r = IXMLDOMNode_hasChildNodes( node, NULL );
583 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
586 r = IXMLDOMNode_hasChildNodes( node, &b );
587 ok( r == S_OK, "hasChildNoes bad return\n");
588 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
591 r = IXMLDOMNode_get_baseName( node, &str );
592 ok( r == S_OK, "get_baseName returned wrong code\n");
593 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
596 ok( FALSE, "no node\n");
599 IXMLDOMNode_Release( node );
601 IXMLDOMNodeList_Release( list );
603 IXMLDOMElement_Release( element );
606 str = SysAllocString( szComplete5 );
607 r = IXMLDOMDocument_loadXML( doc, str, &b );
608 ok( r == S_OK, "loadXML failed\n");
609 ok( b == VARIANT_TRUE, "failed to load XML string\n");
610 SysFreeString( str );
613 r = IXMLDOMNode_hasChildNodes( doc, &b );
614 ok( r == S_OK, "hasChildNoes bad return\n");
615 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
617 r = IXMLDOMDocument_get_documentElement( doc, &element );
618 ok( r == S_OK, "should be a document element\n");
619 ok( element != NULL, "should be an element\n");
623 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
626 /* check if the tag is correct */
627 r = IXMLDOMElement_get_tagName( element, &tag );
628 ok( r == S_OK, "couldn't get tag name\n");
629 ok( tag != NULL, "tag was null\n");
630 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
631 SysFreeString( tag );
635 IXMLDOMElement_Release( element );
637 IXMLDOMDocument_Release( doc );
640 static void test_refs(void)
645 IXMLDOMDocument *doc = NULL;
646 IXMLDOMElement *element = NULL;
647 IXMLDOMNode *node = NULL, *node2;
648 IXMLDOMNodeList *node_list = NULL;
650 IUnknown *unk, *unk2;
652 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
653 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
656 ref = IXMLDOMDocument_Release(doc);
657 ok( ref == 0, "ref %d\n", ref);
659 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
660 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
664 str = SysAllocString( szComplete4 );
665 r = IXMLDOMDocument_loadXML( doc, str, &b );
666 ok( r == S_OK, "loadXML failed\n");
667 ok( b == VARIANT_TRUE, "failed to load XML string\n");
668 SysFreeString( str );
670 ref = IXMLDOMDocument_AddRef( doc );
671 ok( ref == 2, "ref %d\n", ref );
672 ref = IXMLDOMDocument_AddRef( doc );
673 ok( ref == 3, "ref %d\n", ref );
674 IXMLDOMDocument_Release( doc );
675 IXMLDOMDocument_Release( doc );
677 r = IXMLDOMDocument_get_documentElement( doc, &element );
678 ok( r == S_OK, "should be a document element\n");
679 ok( element != NULL, "should be an element\n");
681 ref = IXMLDOMDocument_AddRef( doc );
682 ok( ref == 2, "ref %d\n", ref );
683 IXMLDOMDocument_Release( doc );
685 r = IXMLDOMElement_get_childNodes( element, &node_list );
686 ok( r == S_OK, "rets %08x\n", r);
687 ref = IXMLDOMNodeList_AddRef( node_list );
688 ok( ref == 2, "ref %d\n", ref );
689 IXMLDOMNodeList_Release( node_list );
691 IXMLDOMNodeList_get_item( node_list, 0, &node );
692 ok( r == S_OK, "rets %08x\n", r);
694 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
695 ok( r == S_OK, "rets %08x\n", r);
697 ref = IXMLDOMNode_AddRef( node );
698 ok( ref == 2, "ref %d\n", ref );
699 IXMLDOMNode_Release( node );
701 ref = IXMLDOMNode_Release( node );
702 ok( ref == 0, "ref %d\n", ref );
703 ref = IXMLDOMNode_Release( node2 );
704 ok( ref == 0, "ref %d\n", ref );
706 ref = IXMLDOMNodeList_Release( node_list );
707 ok( ref == 0, "ref %d\n", ref );
709 ok( node != node2, "node %p node2 %p\n", node, node2 );
711 ref = IXMLDOMDocument_Release( doc );
712 ok( ref == 0, "ref %d\n", ref );
714 ref = IXMLDOMElement_AddRef( element );
716 ok( ref == 3, "ref %d\n", ref );
718 IXMLDOMElement_Release( element );
720 /* IUnknown must be unique however we obtain it */
721 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
722 ok( r == S_OK, "rets %08x\n", r );
723 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
724 ok( r == S_OK, "rets %08x\n", r );
725 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
726 ok( r == S_OK, "rets %08x\n", r );
727 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
729 IUnknown_Release( unk2 );
730 IUnknown_Release( unk );
731 IXMLDOMNode_Release( node );
733 IXMLDOMElement_Release( element );
737 static void test_create(void)
742 IXMLDOMDocument *doc;
743 IXMLDOMElement *element;
744 IXMLDOMNode *root, *node, *child;
745 IXMLDOMNamedNodeMap *attr_map;
750 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
751 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
756 V_I4(&var) = NODE_ELEMENT;
757 str = SysAllocString( szlc );
758 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
759 ok( r == S_OK, "returns %08x\n", r );
760 r = IXMLDOMDocument_appendChild( doc, node, &root );
761 ok( r == S_OK, "returns %08x\n", r );
762 ok( node == root, "%p %p\n", node, root );
764 ref = IXMLDOMNode_AddRef( node );
765 ok(ref == 3, "ref %d\n", ref);
766 IXMLDOMNode_Release( node );
768 ref = IXMLDOMNode_Release( node );
769 ok(ref == 1, "ref %d\n", ref);
770 SysFreeString( str );
773 V_I4(&var) = NODE_ELEMENT;
774 str = SysAllocString( szbs );
775 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
776 ok( r == S_OK, "returns %08x\n", r );
778 ref = IXMLDOMNode_AddRef( node );
779 ok(ref == 2, "ref = %d\n", ref);
780 IXMLDOMNode_Release( node );
782 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
783 ok( r == S_OK, "returns %08x\n", r );
785 ref = IXMLDOMNode_AddRef( unk );
786 ok(ref == 3, "ref = %d\n", ref);
787 IXMLDOMNode_Release( unk );
789 V_VT(&var) = VT_EMPTY;
790 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
791 ok( r == S_OK, "returns %08x\n", r );
792 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
793 IXMLDOMNode_Release( child );
794 IUnknown_Release( unk );
797 V_VT(&var) = VT_NULL;
798 V_DISPATCH(&var) = (IDispatch*)node;
799 r = IXMLDOMNode_insertBefore( root, node, var, &child );
800 ok( r == S_OK, "returns %08x\n", r );
801 ok( node == child, "%p %p\n", node, child );
802 IXMLDOMNode_Release( child );
803 IXMLDOMNode_Release( node );
806 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
807 ok( r == S_OK, "returns %08x\n", r );
809 r = IXMLDOMElement_get_attributes( element, &attr_map );
810 ok( r == S_OK, "returns %08x\n", r );
811 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
812 ok( r == S_OK, "returns %08x\n", r );
813 ok( num == 0, "num %ld\n", num );
814 IXMLDOMNamedNodeMap_Release( attr_map );
816 V_VT(&var) = VT_BSTR;
817 V_BSTR(&var) = SysAllocString( szstr1 );
818 name = SysAllocString( szdl );
819 r = IXMLDOMElement_setAttribute( element, name, var );
820 ok( r == S_OK, "returns %08x\n", r );
821 r = IXMLDOMElement_get_attributes( element, &attr_map );
822 ok( r == S_OK, "returns %08x\n", r );
823 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
824 ok( r == S_OK, "returns %08x\n", r );
825 ok( num == 1, "num %ld\n", num );
826 IXMLDOMNamedNodeMap_Release( attr_map );
829 V_VT(&var) = VT_BSTR;
830 V_BSTR(&var) = SysAllocString( szstr2 );
831 r = IXMLDOMElement_setAttribute( element, name, var );
832 ok( r == S_OK, "returns %08x\n", r );
833 r = IXMLDOMElement_get_attributes( element, &attr_map );
834 ok( r == S_OK, "returns %08x\n", r );
835 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
836 ok( r == S_OK, "returns %08x\n", r );
837 ok( num == 1, "num %ld\n", num );
838 IXMLDOMNamedNodeMap_Release( attr_map );
840 r = IXMLDOMElement_getAttribute( element, name, &var );
841 ok( r == S_OK, "returns %08x\n", r );
842 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
846 V_VT(&var) = VT_BSTR;
847 V_BSTR(&var) = SysAllocString( szstr1 );
848 name = SysAllocString( szlc );
849 r = IXMLDOMElement_setAttribute( element, name, var );
850 ok( r == S_OK, "returns %08x\n", r );
851 r = IXMLDOMElement_get_attributes( element, &attr_map );
852 ok( r == S_OK, "returns %08x\n", r );
853 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
854 ok( r == S_OK, "returns %08x\n", r );
855 ok( num == 2, "num %ld\n", num );
856 IXMLDOMNamedNodeMap_Release( attr_map );
862 name = SysAllocString( szbs );
863 r = IXMLDOMElement_setAttribute( element, name, var );
864 ok( r == S_OK, "returns %08x\n", r );
866 r = IXMLDOMElement_getAttribute( element, name, &var );
867 ok( r == S_OK, "returns %08x\n", r );
868 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
872 IXMLDOMElement_Release( element );
873 IXMLDOMNode_Release( root );
874 IXMLDOMDocument_Release( doc );
877 static void test_getElementsByTagName(void)
882 IXMLDOMDocument *doc;
883 IXMLDOMNodeList *node_list;
886 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
887 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
891 str = SysAllocString( szComplete4 );
892 r = IXMLDOMDocument_loadXML( doc, str, &b );
893 ok( r == S_OK, "loadXML failed\n");
894 ok( b == VARIANT_TRUE, "failed to load XML string\n");
895 SysFreeString( str );
897 str = SysAllocString( szstar );
898 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
899 ok( r == S_OK, "ret %08x\n", r );
900 r = IXMLDOMNodeList_get_length( node_list, &len );
901 ok( r == S_OK, "ret %08x\n", r );
902 ok( len == 6, "len %ld\n", len );
903 IXMLDOMNodeList_Release( node_list );
904 SysFreeString( str );
906 str = SysAllocString( szbs );
907 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
908 ok( r == S_OK, "ret %08x\n", r );
909 r = IXMLDOMNodeList_get_length( node_list, &len );
910 ok( r == S_OK, "ret %08x\n", r );
911 ok( len == 1, "len %ld\n", len );
912 IXMLDOMNodeList_Release( node_list );
913 SysFreeString( str );
915 str = SysAllocString( szdl );
916 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
917 ok( r == S_OK, "ret %08x\n", r );
918 r = IXMLDOMNodeList_get_length( node_list, &len );
919 ok( r == S_OK, "ret %08x\n", r );
920 ok( len == 0, "len %ld\n", len );
921 IXMLDOMNodeList_Release( node_list );
922 SysFreeString( str );
924 str = SysAllocString( szstr1 );
925 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
926 ok( r == S_OK, "ret %08x\n", r );
927 r = IXMLDOMNodeList_get_length( node_list, &len );
928 ok( r == S_OK, "ret %08x\n", r );
929 ok( len == 0, "len %ld\n", len );
930 IXMLDOMNodeList_Release( node_list );
931 SysFreeString( str );
933 IXMLDOMDocument_Release( doc );
936 static void test_get_text(void)
941 IXMLDOMDocument *doc;
942 IXMLDOMNode *node, *node2, *node3;
943 IXMLDOMNodeList *node_list;
944 IXMLDOMNamedNodeMap *node_map;
946 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
947 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
951 str = SysAllocString( szComplete4 );
952 r = IXMLDOMDocument_loadXML( doc, str, &b );
953 ok( r == S_OK, "loadXML failed\n");
954 ok( b == VARIANT_TRUE, "failed to load XML string\n");
955 SysFreeString( str );
957 str = SysAllocString( szbs );
958 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
959 ok( r == S_OK, "ret %08x\n", r );
962 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
963 ok( r == S_OK, "ret %08x\n", r );
964 IXMLDOMNodeList_Release( node_list );
966 r = IXMLDOMNode_get_text( node, &str );
967 ok( r == S_OK, "ret %08x\n", r );
969 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
971 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
974 r = IXMLDOMNode_get_attributes( node, &node_map );
975 ok( r == S_OK, "ret %08x\n", r );
977 str = SysAllocString( szvr );
978 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
979 ok( r == S_OK, "ret %08x\n", r );
982 r = IXMLDOMNode_get_text( node2, &str );
983 ok( r == S_OK, "ret %08x\n", r );
984 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
987 r = IXMLDOMNode_get_firstChild( node2, &node3 );
988 ok( r == S_OK, "ret %08x\n", r );
990 r = IXMLDOMNode_get_text( node3, &str );
991 ok( r == S_OK, "ret %08x\n", r );
992 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
996 IXMLDOMNode_Release( node3 );
997 IXMLDOMNode_Release( node2 );
998 IXMLDOMNamedNodeMap_Release( node_map );
999 IXMLDOMNode_Release( node );
1000 IXMLDOMDocument_Release( doc );
1003 static void test_get_childNodes(void)
1008 IXMLDOMDocument *doc;
1009 IXMLDOMElement *element;
1010 IXMLDOMNode *node, *node2;
1011 IXMLDOMNodeList *node_list, *node_list2;
1014 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1015 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1019 str = SysAllocString( szComplete4 );
1020 r = IXMLDOMDocument_loadXML( doc, str, &b );
1021 ok( r == S_OK, "loadXML failed\n");
1022 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1023 SysFreeString( str );
1025 r = IXMLDOMDocument_get_documentElement( doc, &element );
1026 ok( r == S_OK, "ret %08x\n", r);
1028 r = IXMLDOMElement_get_childNodes( element, &node_list );
1029 ok( r == S_OK, "ret %08x\n", r);
1031 r = IXMLDOMNodeList_get_length( node_list, &len );
1032 ok( r == S_OK, "ret %08x\n", r);
1033 ok( len == 4, "len %ld\n", len);
1035 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1036 ok( r == S_OK, "ret %08x\n", r);
1038 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1039 ok( r == S_OK, "ret %08x\n", r);
1041 r = IXMLDOMNodeList_get_length( node_list2, &len );
1042 ok( r == S_OK, "ret %08x\n", r);
1043 ok( len == 0, "len %ld\n", len);
1045 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1046 ok( r == S_FALSE, "ret %08x\n", r);
1048 IXMLDOMNodeList_Release( node_list2 );
1049 IXMLDOMNode_Release( node );
1050 IXMLDOMNodeList_Release( node_list );
1051 IXMLDOMElement_Release( element );
1052 IXMLDOMDocument_Release( doc );
1055 static void test_removeChild(void)
1060 IXMLDOMDocument *doc;
1061 IXMLDOMElement *element;
1062 IXMLDOMNode *node, *node2, *node3, *node4;
1063 IXMLDOMNodeList *node_list, *node_list2;
1065 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1066 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1070 str = SysAllocString( szComplete4 );
1071 r = IXMLDOMDocument_loadXML( doc, str, &b );
1072 ok( r == S_OK, "loadXML failed\n");
1073 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1074 SysFreeString( str );
1076 r = IXMLDOMDocument_get_documentElement( doc, &element );
1077 ok( r == S_OK, "ret %08x\n", r);
1079 r = IXMLDOMElement_get_childNodes( element, &node_list );
1080 ok( r == S_OK, "ret %08x\n", r);
1082 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1083 ok( r == S_OK, "ret %08x\n", r);
1085 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1086 ok( r == S_OK, "ret %08x\n", r);
1088 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1089 ok( r == S_OK, "ret %08x\n", r);
1091 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1092 ok( r == E_INVALIDARG, "ret %08x\n", r );
1094 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1095 ok( r == S_OK, "ret %08x\n", r);
1096 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1098 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1099 ok( r == S_FALSE, "ret %08x\n", r);
1100 ok( node3 == NULL, "%p\n", node3 );
1102 IXMLDOMNode_Release( node2 );
1103 IXMLDOMNode_Release( node4 );
1104 IXMLDOMNodeList_Release( node_list2 );
1105 IXMLDOMNode_Release( node );
1106 IXMLDOMNodeList_Release( node_list );
1107 IXMLDOMElement_Release( element );
1108 IXMLDOMDocument_Release( doc );
1111 static void test_XMLHTTP(void)
1113 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1114 static WCHAR wszPOST[] = {'P','O','S','T',0};
1115 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1116 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1117 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1118 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1119 IXMLHttpRequest *pXMLHttpRequest;
1124 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1125 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1126 (void **)&pXMLHttpRequest);
1128 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1133 VariantInit(&dummy);
1134 V_VT(&dummy) = VT_ERROR;
1135 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1136 VariantInit(&varfalse);
1137 V_VT(&varfalse) = VT_BOOL;
1138 V_BOOL(&varfalse) = VARIANT_FALSE;
1139 V_VT(&varbody) = VT_BSTR;
1140 V_BSTR(&varbody) = SysAllocString(wszBody);
1142 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1143 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1145 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1146 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1147 VariantClear(&varbody);
1149 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1150 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1151 /* the server currently returns "FAILED" because the Content-Type header is
1152 * not what the server expects */
1153 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1154 SysFreeString(bstrResponse);
1161 r = CoInitialize( NULL );
1162 ok( r == S_OK, "failed to init com\n");
1168 test_getElementsByTagName();
1170 test_get_childNodes();