user32,server: Set the initial window rectangles to 0,0-0,0.
[wine.git] / dlls / msxml3 / tests / domdoc.c
blob692dd363b9ae273792ff8eb80111f9c68ec7a02a
1 /*
2 * XML test
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
22 #define COBJMACROS
24 #include "windows.h"
25 #include "ole2.h"
26 #include "xmldom.h"
27 #include "msxml2.h"
28 #include <stdio.h>
29 #include <assert.h>
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',
67 '<','f','o','>','\n',
68 '<','b','a','>','\n',
69 'f','1','\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"
91 " <elem>\n"
92 " <a>A1 field</a>\n"
93 " <b>B1 field</b>\n"
94 " <c>C1 field</c>\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"
98 " </html>\n"
99 " </description>\n"
100 " </elem>\n"
101 "\n"
102 " <elem>\n"
103 " <a>A2 field</a>\n"
104 " <b>B2 field</b>\n"
105 " <c type=\"old\">C2 field</c>\n"
106 " </elem>\n"
107 "\n"
108 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
109 " <a>A3 field</a>\n"
110 " <b>B3 field</b>\n"
111 " <c>C3 field</c>\n"
112 " </elem>\n"
113 "\n"
114 " <elem>\n"
115 " <a>A4 field</a>\n"
116 " <b>B4 field</b>\n"
117 " <foo:c>C4 field</foo:c>\n"
118 " </elem>\n"
119 "</root>\n";
121 static const WCHAR szNonExistentFile[] = {
122 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
124 static const WCHAR szDocument[] = {
125 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
128 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
129 static WCHAR szdl[] = { 'd','l',0 };
130 static const WCHAR szvr[] = { 'v','r',0 };
131 static const WCHAR szlc[] = { 'l','c',0 };
132 static WCHAR szbs[] = { 'b','s',0 };
133 static const WCHAR szstr1[] = { 's','t','r','1',0 };
134 static const WCHAR szstr2[] = { 's','t','r','2',0 };
135 static const WCHAR szstar[] = { '*',0 };
136 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
138 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
139 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
140 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
142 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
143 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
144 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
145 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
146 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
148 static WCHAR szAttribute[] = {'A','t','t','r',0 };
149 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
151 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
152 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
153 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
154 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
155 '!',']',']','>',0};
156 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
157 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
159 #define expect_bstr_eq_and_free(bstr, expect) { \
160 BSTR bstrExp = alloc_str_from_narrow(expect); \
161 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
162 SysFreeString(bstr); \
163 SysFreeString(bstrExp); \
166 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
168 #define ole_check(expr) { \
169 HRESULT r = expr; \
170 ok(r == S_OK, #expr " returned %x\n", r); \
173 #define ole_expect(expr, expect) { \
174 HRESULT r = expr; \
175 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
178 static BSTR alloc_str_from_narrow(const char *str)
180 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
181 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
182 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
183 return ret;
186 BSTR alloced_bstrs[256];
187 int alloced_bstrs_count = 0;
189 static BSTR _bstr_(const char *str)
191 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
192 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
193 return alloced_bstrs[alloced_bstrs_count++];
196 static void free_bstrs(void)
198 int i;
199 for (i = 0; i < alloced_bstrs_count; i++)
200 SysFreeString(alloced_bstrs[i]);
201 alloced_bstrs_count = 0;
204 static VARIANT _variantbstr_(const char *str)
206 VARIANT v;
207 V_VT(&v) = VT_BSTR;
208 V_BSTR(&v) = _bstr_(str);
209 return v;
212 static void get_str_for_type(DOMNodeType type, char *buf)
214 switch (type)
216 case NODE_ATTRIBUTE:
217 strcpy(buf, "A");
218 break;
219 case NODE_ELEMENT:
220 strcpy(buf, "E");
221 break;
222 case NODE_DOCUMENT:
223 strcpy(buf, "D");
224 break;
225 default:
226 wsprintfA(buf, "[%d]", type);
230 static int get_node_position(IXMLDOMNode *node)
232 HRESULT r;
233 int pos = 0;
235 IXMLDOMNode_AddRef(node);
238 IXMLDOMNode *new_node;
240 pos++;
241 r = IXMLDOMNode_get_previousSibling(node, &new_node);
242 ok(!FAILED(r), "get_previousSibling failed\n");
243 IXMLDOMNode_Release(node);
244 node = new_node;
245 } while (r == S_OK);
246 return pos;
249 static void node_to_string(IXMLDOMNode *node, char *buf)
251 HRESULT r = S_OK;
252 DOMNodeType type;
254 if (node == NULL)
256 lstrcpyA(buf, "(null)");
257 return;
260 IXMLDOMNode_AddRef(node);
261 while (r == S_OK)
263 IXMLDOMNode *new_node;
265 ole_check(IXMLDOMNode_get_nodeType(node, &type));
266 get_str_for_type(type, buf);
267 buf+=strlen(buf);
269 if (type == NODE_ATTRIBUTE)
271 BSTR bstr;
272 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
273 *(buf++) = '\'';
274 wsprintfA(buf, "%ws", bstr);
275 buf += strlen(buf);
276 *(buf++) = '\'';
277 SysFreeString(bstr);
279 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
281 else
283 int pos = get_node_position(node);
284 DOMNodeType parent_type = NODE_INVALID;
285 r = IXMLDOMNode_get_parentNode(node, &new_node);
287 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
288 * results we "fix" it */
289 if (r == S_OK)
290 ole_check(IXMLDOMNode_get_nodeType(node, &parent_type));
291 /* we need also to workaround the no document node problem - see below */
292 if (((r == S_FALSE && type != NODE_DOCUMENT) || parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
294 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
295 pos++;
297 wsprintf(buf, "%d", pos);
298 buf += strlen(buf);
301 ok(!FAILED(r), "get_parentNode failed (%08x)\n", r);
302 IXMLDOMNode_Release(node);
303 node = new_node;
304 if (r == S_OK)
305 *(buf++) = '.';
308 /* currently we can't access document node in wine. All our examples this is the
309 * root node so to be able to test query results we add it */
310 if (type != NODE_DOCUMENT)
312 todo_wine ok(FALSE, "Document node is not the last returned node!\n");
313 *(buf++) = '.';
314 *(buf++) = 'D';
315 *(buf++) = '1';
317 *buf = 0;
320 static char *list_to_string(IXMLDOMNodeList *list)
322 static char buf[4096];
323 char *pos = buf;
324 long len = 0;
325 int i;
327 if (list == NULL)
329 lstrcpyA(buf, "(null)");
330 return buf;
332 ole_check(IXMLDOMNodeList_get_length(list, &len));
333 for (i = 0; i < len; i++)
335 IXMLDOMNode *node;
336 if (i > 0)
337 *(pos++) = ' ';
338 ole_check(IXMLDOMNodeList_nextNode(list, &node));
339 node_to_string(node, pos);
340 pos += strlen(pos);
341 IXMLDOMNode_Release(node);
343 *pos = 0;
344 return buf;
347 #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); }
348 #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); }
350 static void test_domdoc( void )
352 HRESULT r;
353 IXMLDOMDocument *doc = NULL;
354 IXMLDOMParseError *error;
355 IXMLDOMElement *element = NULL;
356 IXMLDOMNode *node;
357 IXMLDOMText *nodetext = NULL;
358 IXMLDOMComment *node_comment = NULL;
359 IXMLDOMAttribute *node_attr = NULL;
360 IXMLDOMNode *nodeChild = NULL;
361 IXMLDOMProcessingInstruction *nodePI = NULL;
362 VARIANT_BOOL b;
363 VARIANT var;
364 BSTR str;
365 long code;
367 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
368 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
369 if( r != S_OK )
370 return;
372 /* try some stupid things */
373 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
374 ok( r == S_FALSE, "loadXML failed\n");
376 b = VARIANT_TRUE;
377 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
378 ok( r == S_FALSE, "loadXML failed\n");
379 ok( b == VARIANT_FALSE, "failed to load XML string\n");
381 /* try to load a document from a nonexistent file */
382 b = VARIANT_TRUE;
383 str = SysAllocString( szNonExistentFile );
384 VariantInit(&var);
385 V_VT(&var) = VT_BSTR;
386 V_BSTR(&var) = str;
388 r = IXMLDOMDocument_load( doc, var, &b);
389 ok( r == S_FALSE, "load (from file) failed\n");
390 ok( b == VARIANT_FALSE, "failed to load XML file\n");
391 SysFreeString( str );
393 /* try load an empty document */
394 b = VARIANT_TRUE;
395 str = SysAllocString( szEmpty );
396 r = IXMLDOMDocument_loadXML( doc, str, &b );
397 ok( r == S_FALSE, "loadXML failed\n");
398 ok( b == VARIANT_FALSE, "failed to load XML string\n");
399 SysFreeString( str );
401 /* check that there's no document element */
402 element = NULL;
403 r = IXMLDOMDocument_get_documentElement( doc, &element );
404 ok( r == S_FALSE, "should be no document element\n");
406 /* try finding a node */
407 node = NULL;
408 str = SysAllocString( szstr1 );
409 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
410 ok( r == S_FALSE, "ret %08x\n", r );
411 SysFreeString( str );
413 b = VARIANT_TRUE;
414 str = SysAllocString( szIncomplete );
415 r = IXMLDOMDocument_loadXML( doc, str, &b );
416 ok( r == S_FALSE, "loadXML failed\n");
417 ok( b == VARIANT_FALSE, "failed to load XML string\n");
418 SysFreeString( str );
420 /* check that there's no document element */
421 element = (IXMLDOMElement*)1;
422 r = IXMLDOMDocument_get_documentElement( doc, &element );
423 ok( r == S_FALSE, "should be no document element\n");
424 ok( element == NULL, "Element should be NULL\n");
426 /* try to load something valid */
427 b = VARIANT_FALSE;
428 str = SysAllocString( szComplete1 );
429 r = IXMLDOMDocument_loadXML( doc, str, &b );
430 ok( r == S_OK, "loadXML failed\n");
431 ok( b == VARIANT_TRUE, "failed to load XML string\n");
432 SysFreeString( str );
434 /* try with a null out pointer */
435 r = IXMLDOMDocument_get_documentElement( doc, NULL );
436 ok( r == E_INVALIDARG, "should be no document element\n");
438 /* check if nodename is correct */
439 r = IXMLDOMDocument_get_nodeName( doc, NULL );
440 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
442 /* content doesn't matter here */
443 str = NULL;
444 r = IXMLDOMDocument_get_nodeName( doc, &str );
445 ok ( r == S_OK, "get_nodeName wrong code\n");
446 ok ( str != NULL, "str is null\n");
447 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
448 SysFreeString( str );
450 /* test put_text */
451 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
452 ok( r == E_FAIL, "ret %08x\n", r );
454 /* check that there's a document element */
455 element = NULL;
456 r = IXMLDOMDocument_get_documentElement( doc, &element );
457 ok( r == S_OK, "should be a document element\n");
458 if( element )
460 BSTR tag = NULL;
462 /* check if the tag is correct */
463 r = IXMLDOMElement_get_tagName( element, &tag );
464 ok( r == S_OK, "couldn't get tag name\n");
465 ok( tag != NULL, "tag was null\n");
466 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
467 SysFreeString( tag );
469 /* figure out what happens if we try to reload the document */
470 str = SysAllocString( szComplete2 );
471 r = IXMLDOMDocument_loadXML( doc, str, &b );
472 ok( r == S_OK, "loadXML failed\n");
473 ok( b == VARIANT_TRUE, "failed to load XML string\n");
474 SysFreeString( str );
476 /* check if the tag is still correct */
477 tag = NULL;
478 r = IXMLDOMElement_get_tagName( element, &tag );
479 ok( r == S_OK, "couldn't get tag name\n");
480 ok( tag != NULL, "tag was null\n");
481 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
482 SysFreeString( tag );
484 IXMLDOMElement_Release( element );
485 element = NULL;
488 /* as soon as we call loadXML again, the document element will disappear */
489 b = 2;
490 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
491 ok( r == S_FALSE, "loadXML failed\n");
492 ok( b == 2, "variant modified\n");
493 r = IXMLDOMDocument_get_documentElement( doc, &element );
494 ok( r == S_FALSE, "should be no document element\n");
496 /* try to load something else simple and valid */
497 b = VARIANT_FALSE;
498 str = SysAllocString( szComplete3 );
499 r = IXMLDOMDocument_loadXML( doc, str, &b );
500 ok( r == S_OK, "loadXML failed\n");
501 ok( b == VARIANT_TRUE, "failed to load XML string\n");
502 SysFreeString( str );
504 /* try something a little more complicated */
505 b = FALSE;
506 str = SysAllocString( szComplete4 );
507 r = IXMLDOMDocument_loadXML( doc, str, &b );
508 ok( r == S_OK, "loadXML failed\n");
509 ok( b == VARIANT_TRUE, "failed to load XML string\n");
510 SysFreeString( str );
512 r = IXMLDOMDocument_get_parseError( doc, &error );
513 ok( r == S_OK, "returns %08x\n", r );
515 r = IXMLDOMParseError_get_errorCode( error, &code );
516 ok( r == S_FALSE, "returns %08x\n", r );
517 ok( code == 0, "code %ld\n", code );
518 IXMLDOMParseError_Release( error );
520 /* test createTextNode */
521 str = SysAllocString( szOpen );
522 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
523 ok( r == E_INVALIDARG, "returns %08x\n", r );
524 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
525 ok( r == S_OK, "returns %08x\n", r );
526 if(nodetext)
528 IXMLDOMNamedNodeMap *pAttribs;
530 /* Text Last Child Checks */
531 r = IXMLDOMText_get_lastChild(nodetext, NULL);
532 ok(r == E_INVALIDARG, "ret %08x\n", r );
534 nodeChild = (IXMLDOMNode*)0x1;
535 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
536 ok(r == S_FALSE, "ret %08x\n", r );
537 ok(nodeChild == NULL, "nodeChild not NULL\n");
539 /* test get_attributes */
540 r = IXMLDOMText_get_attributes( nodetext, NULL );
541 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
543 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
544 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
545 ok(r == S_FALSE, "ret %08x\n", r );
546 ok( pAttribs == NULL, "pAttribs not NULL\n");
548 /* test get_dataType */
549 r = IXMLDOMText_get_dataType(nodetext, &var);
550 ok(r == S_FALSE, "ret %08x\n", r );
551 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
552 VariantClear(&var);
554 /* test nodeTypeString */
555 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
556 ok(r == S_OK, "ret %08x\n", r );
557 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
558 SysFreeString(str);
560 IXMLDOMText_Release( nodetext );
562 SysFreeString( str );
564 /* test Create Comment */
565 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
566 ok( r == E_INVALIDARG, "returns %08x\n", r );
567 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
568 ok( r == S_OK, "returns %08x\n", r );
569 if(node_comment)
571 /* Last Child Checks */
572 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
573 ok(r == E_INVALIDARG, "ret %08x\n", r );
575 nodeChild = (IXMLDOMNode*)0x1;
576 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
577 ok(r == S_FALSE, "ret %08x\n", r );
578 ok(nodeChild == NULL, "pLastChild not NULL\n");
580 IXMLDOMComment_Release( node_comment );
583 /* test Create Attribute */
584 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
585 ok( r == E_INVALIDARG, "returns %08x\n", r );
586 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
587 ok( r == S_OK, "returns %08x\n", r );
588 IXMLDOMText_Release( node_attr);
590 /* test Processing Instruction */
591 str = SysAllocStringLen(NULL, 0);
592 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
593 ok( r == E_INVALIDARG, "returns %08x\n", r );
594 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
595 ok( r == E_FAIL, "returns %08x\n", r );
596 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
597 ok( r == E_FAIL, "returns %08x\n", r );
598 SysFreeString(str);
600 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
601 ok( r == S_OK, "returns %08x\n", r );
602 if(nodePI)
604 /* Last Child Checks */
605 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
606 ok(r == E_INVALIDARG, "ret %08x\n", r );
608 nodeChild = (IXMLDOMNode*)0x1;
609 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
610 ok(r == S_FALSE, "ret %08x\n", r );
611 ok(nodeChild == NULL, "nodeChild not NULL\n");
613 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
614 ok(r == S_FALSE, "ret %08x\n", r );
615 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
616 VariantClear(&var);
618 /* test nodeTypeString */
619 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
620 ok(r == S_OK, "ret %08x\n", r );
621 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
622 SysFreeString(str);
624 IXMLDOMProcessingInstruction_Release(nodePI);
627 r = IXMLDOMDocument_Release( doc );
628 ok( r == 0, "document ref count incorrect\n");
632 static void test_domnode( void )
634 HRESULT r;
635 IXMLDOMDocument *doc = NULL, *owner = NULL;
636 IXMLDOMElement *element = NULL;
637 IXMLDOMNamedNodeMap *map = NULL;
638 IXMLDOMNode *node = NULL, *next = NULL;
639 IXMLDOMNodeList *list = NULL;
640 DOMNodeType type = NODE_INVALID;
641 VARIANT_BOOL b;
642 BSTR str;
643 VARIANT var;
644 long count;
646 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
647 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
648 if( r != S_OK )
649 return;
651 b = FALSE;
652 str = SysAllocString( szComplete4 );
653 r = IXMLDOMDocument_loadXML( doc, str, &b );
654 ok( r == S_OK, "loadXML failed\n");
655 ok( b == VARIANT_TRUE, "failed to load XML string\n");
656 SysFreeString( str );
658 if (doc)
660 b = 1;
661 r = IXMLDOMNode_hasChildNodes( doc, &b );
662 ok( r == S_OK, "hasChildNoes bad return\n");
663 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
665 r = IXMLDOMDocument_get_documentElement( doc, &element );
666 ok( r == S_OK, "should be a document element\n");
667 ok( element != NULL, "should be an element\n");
669 else
670 ok( FALSE, "no document\n");
672 VariantInit(&var);
673 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
675 r = IXMLDOMNode_get_nodeValue( doc, NULL );
676 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
678 r = IXMLDOMNode_get_nodeValue( doc, &var );
679 ok( r == S_FALSE, "nextNode returned wrong code\n");
680 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
681 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
683 if (element)
685 owner = NULL;
686 r = IXMLDOMNode_get_ownerDocument( element, &owner );
687 todo_wine {
688 ok( r == S_OK, "get_ownerDocument return code\n");
690 ok( owner != doc, "get_ownerDocument return\n");
692 type = NODE_INVALID;
693 r = IXMLDOMNode_get_nodeType( element, &type);
694 ok( r == S_OK, "getNamedItem returned wrong code\n");
695 ok( type == NODE_ELEMENT, "node not an element\n");
697 str = NULL;
698 r = IXMLDOMNode_get_baseName( element, &str );
699 ok( r == S_OK, "get_baseName returned wrong code\n");
700 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
701 SysFreeString(str);
703 /* check if nodename is correct */
704 r = IXMLDOMElement_get_nodeName( element, NULL );
705 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
707 /* content doesn't matter here */
708 str = NULL;
709 r = IXMLDOMElement_get_nodeName( element, &str );
710 ok ( r == S_OK, "get_nodeName wrong code\n");
711 ok ( str != NULL, "str is null\n");
712 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
713 SysFreeString( str );
715 str = SysAllocString( szNonExistentFile );
716 V_VT(&var) = VT_I4;
717 V_I4(&var) = 0x1234;
718 r = IXMLDOMElement_getAttribute( element, str, &var );
719 ok( r == S_FALSE, "getAttribute ret %08x\n", r );
720 ok( V_VT(&var) == VT_NULL, "vt = %x\n", V_VT(&var));
721 VariantClear(&var);
722 SysFreeString( str );
724 str = SysAllocString( szdl );
725 V_VT(&var) = VT_I4;
726 V_I4(&var) = 0x1234;
727 r = IXMLDOMElement_getAttribute( element, str, &var );
728 ok( r == S_OK, "getAttribute ret %08x\n", r );
729 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
730 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
731 VariantClear( &var );
733 r = IXMLDOMElement_getAttribute( element, NULL, &var );
734 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
736 r = IXMLDOMElement_getAttribute( element, str, NULL );
737 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
739 SysFreeString( str );
741 r = IXMLDOMElement_get_attributes( element, &map );
742 ok( r == S_OK, "get_attributes returned wrong code\n");
743 ok( map != NULL, "should be attributes\n");
745 b = 1;
746 r = IXMLDOMNode_hasChildNodes( element, &b );
747 ok( r == S_OK, "hasChildNoes bad return\n");
748 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
750 else
751 ok( FALSE, "no element\n");
753 if (map)
755 ISupportErrorInfo *support_error;
756 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
757 ok( r == S_OK, "ret %08x\n", r );
759 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
760 todo_wine
762 ok( r == S_OK, "ret %08x\n", r );
764 ISupportErrorInfo_Release( support_error );
766 str = SysAllocString( szdl );
767 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
768 ok( r == S_OK, "getNamedItem returned wrong code\n");
769 ok( node != NULL, "should be attributes\n");
770 IXMLDOMNode_Release(node);
771 SysFreeString( str );
773 str = SysAllocString( szdl );
774 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
775 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
776 SysFreeString( str );
778 /* something that isn't in szComplete4 */
779 str = SysAllocString( szOpen );
780 node = (IXMLDOMNode *) 1;
781 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
782 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
783 ok( node == NULL, "getNamedItem should have returned NULL\n");
784 SysFreeString( str );
786 /* test indexed access of attributes */
787 r = IXMLDOMNamedNodeMap_get_length( map, &count );
788 ok ( r == S_OK, "get_length wrong code\n");
789 ok ( count == 1, "get_length != 1\n");
791 node = NULL;
792 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
793 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
794 ok ( node == NULL, "there is no node\n");
796 node = NULL;
797 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
798 ok ( r == S_FALSE, "get_item (1) wrong code\n");
799 ok ( node == NULL, "there is no attribute\n");
801 node = NULL;
802 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
803 ok ( r == S_OK, "get_item (0) wrong code\n");
804 ok ( node != NULL, "should be attribute\n");
806 r = IXMLDOMNode_get_nodeName( node, NULL );
807 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
809 /* content doesn't matter here */
810 str = NULL;
811 r = IXMLDOMNode_get_nodeName( node, &str );
812 ok ( r == S_OK, "get_nodeName wrong code\n");
813 ok ( str != NULL, "str is null\n");
814 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
815 SysFreeString( str );
817 /* test sequential access of attributes */
818 node = NULL;
819 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
820 ok ( r == S_OK, "nextNode (first time) wrong code\n");
821 ok ( node != NULL, "nextNode, should be attribute\n");
823 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
824 ok ( r != S_OK, "nextNode (second time) wrong code\n");
825 ok ( node == NULL, "nextNode, there is no attribute\n");
827 r = IXMLDOMNamedNodeMap_reset( map );
828 ok ( r == S_OK, "reset should return S_OK\n");
830 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
831 ok ( r == S_OK, "nextNode (third time) wrong code\n");
832 ok ( node != NULL, "nextNode, should be attribute\n");
834 else
835 ok( FALSE, "no map\n");
837 if (node)
839 type = NODE_INVALID;
840 r = IXMLDOMNode_get_nodeType( node, &type);
841 ok( r == S_OK, "getNamedItem returned wrong code\n");
842 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
844 str = NULL;
845 r = IXMLDOMNode_get_baseName( node, NULL );
846 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
848 str = NULL;
849 r = IXMLDOMNode_get_baseName( node, &str );
850 ok( r == S_OK, "get_baseName returned wrong code\n");
851 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
852 SysFreeString( str );
854 r = IXMLDOMNode_get_nodeValue( node, &var );
855 ok( r == S_OK, "returns %08x\n", r );
856 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
857 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
858 VariantClear(&var);
860 r = IXMLDOMNode_get_childNodes( node, NULL );
861 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
863 r = IXMLDOMNode_get_childNodes( node, &list );
864 ok( r == S_OK, "get_childNodes returned wrong code\n");
866 if (list)
868 r = IXMLDOMNodeList_nextNode( list, &next );
869 ok( r == S_OK, "nextNode returned wrong code\n");
871 else
872 ok( FALSE, "no childlist\n");
874 if (next)
876 b = 1;
877 r = IXMLDOMNode_hasChildNodes( next, &b );
878 ok( r == S_FALSE, "hasChildNoes bad return\n");
879 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
881 type = NODE_INVALID;
882 r = IXMLDOMNode_get_nodeType( next, &type);
883 ok( r == S_OK, "getNamedItem returned wrong code\n");
884 ok( type == NODE_TEXT, "node not text\n");
886 str = (BSTR) 1;
887 r = IXMLDOMNode_get_baseName( next, &str );
888 ok( r == S_FALSE, "get_baseName returned wrong code\n");
889 ok( str == NULL, "basename was wrong\n");
890 SysFreeString(str);
892 else
893 ok( FALSE, "no next\n");
895 if (next)
896 IXMLDOMNode_Release( next );
897 next = NULL;
898 if (list)
899 IXMLDOMNodeList_Release( list );
900 list = NULL;
901 if (node)
902 IXMLDOMNode_Release( node );
904 else
905 ok( FALSE, "no node\n");
906 node = NULL;
908 if (map)
909 IXMLDOMNamedNodeMap_Release( map );
911 /* now traverse the tree from the root element */
912 if (element)
914 IXMLDOMNode *node;
915 r = IXMLDOMNode_get_childNodes( element, &list );
916 ok( r == S_OK, "get_childNodes returned wrong code\n");
918 /* using get_item for child list doesn't advance the position */
919 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
920 expect_node(node, "E2.E2.D1");
921 IXMLDOMNode_Release(node);
922 ole_check(IXMLDOMNodeList_nextNode(list, &node));
923 expect_node(node, "E1.E2.D1");
924 IXMLDOMNode_Release(node);
925 ole_check(IXMLDOMNodeList_reset(list));
927 IXMLDOMNodeList_AddRef(list);
928 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
929 ole_check(IXMLDOMNodeList_reset(list));
931 else
932 ok( FALSE, "no element\n");
934 node = (void*)0xdeadbeef;
935 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
936 ok( r == S_FALSE, "ret %08x\n", r );
937 ok( node == NULL, "node %p\n", node );
938 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
939 ok( r == S_OK, "ret %08x\n", r );
940 r = IXMLDOMNode_Release( node );
941 ok( r == 0, "ret %08x\n", r );
943 if (list)
945 r = IXMLDOMNodeList_get_length( list, &count );
946 ok( r == S_OK, "get_length returns %08x\n", r );
947 ok( count == 4, "get_length got %ld\n", count );
949 r = IXMLDOMNodeList_nextNode( list, &node );
950 ok( r == S_OK, "nextNode returned wrong code\n");
952 else
953 ok( FALSE, "no list\n");
955 if (node)
957 type = NODE_INVALID;
958 r = IXMLDOMNode_get_nodeType( node, &type);
959 ok( r == S_OK, "getNamedItem returned wrong code\n");
960 ok( type == NODE_ELEMENT, "node not text\n");
962 VariantInit(&var);
963 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
964 r = IXMLDOMNode_get_nodeValue( node, &var );
965 ok( r == S_FALSE, "nextNode returned wrong code\n");
966 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
967 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
969 r = IXMLDOMNode_hasChildNodes( node, NULL );
970 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
972 b = 1;
973 r = IXMLDOMNode_hasChildNodes( node, &b );
974 ok( r == S_OK, "hasChildNoes bad return\n");
975 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
977 str = NULL;
978 r = IXMLDOMNode_get_baseName( node, &str );
979 ok( r == S_OK, "get_baseName returned wrong code\n");
980 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
981 SysFreeString(str);
983 else
984 ok( FALSE, "no node\n");
986 if (node)
987 IXMLDOMNode_Release( node );
988 if (list)
989 IXMLDOMNodeList_Release( list );
990 if (element)
991 IXMLDOMElement_Release( element );
993 b = FALSE;
994 str = SysAllocString( szComplete5 );
995 r = IXMLDOMDocument_loadXML( doc, str, &b );
996 ok( r == S_OK, "loadXML failed\n");
997 ok( b == VARIANT_TRUE, "failed to load XML string\n");
998 SysFreeString( str );
1000 b = 1;
1001 r = IXMLDOMNode_hasChildNodes( doc, &b );
1002 ok( r == S_OK, "hasChildNoes bad return\n");
1003 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1005 r = IXMLDOMDocument_get_documentElement( doc, &element );
1006 ok( r == S_OK, "should be a document element\n");
1007 ok( element != NULL, "should be an element\n");
1009 if (element)
1011 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1012 BSTR tag = NULL;
1014 /* check if the tag is correct */
1015 r = IXMLDOMElement_get_tagName( element, &tag );
1016 ok( r == S_OK, "couldn't get tag name\n");
1017 ok( tag != NULL, "tag was null\n");
1018 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1019 SysFreeString( tag );
1022 if (element)
1023 IXMLDOMElement_Release( element );
1024 if (doc)
1025 IXMLDOMDocument_Release( doc );
1028 static void test_refs(void)
1030 HRESULT r;
1031 BSTR str;
1032 VARIANT_BOOL b;
1033 IXMLDOMDocument *doc = NULL;
1034 IXMLDOMElement *element = NULL;
1035 IXMLDOMNode *node = NULL, *node2;
1036 IXMLDOMNodeList *node_list = NULL;
1037 LONG ref;
1038 IUnknown *unk, *unk2;
1040 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1041 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1042 if( r != S_OK )
1043 return;
1044 ref = IXMLDOMDocument_Release(doc);
1045 ok( ref == 0, "ref %d\n", ref);
1047 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1048 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1049 if( r != S_OK )
1050 return;
1052 str = SysAllocString( szComplete4 );
1053 r = IXMLDOMDocument_loadXML( doc, str, &b );
1054 ok( r == S_OK, "loadXML failed\n");
1055 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1056 SysFreeString( str );
1058 ref = IXMLDOMDocument_AddRef( doc );
1059 ok( ref == 2, "ref %d\n", ref );
1060 ref = IXMLDOMDocument_AddRef( doc );
1061 ok( ref == 3, "ref %d\n", ref );
1062 IXMLDOMDocument_Release( doc );
1063 IXMLDOMDocument_Release( doc );
1065 r = IXMLDOMDocument_get_documentElement( doc, &element );
1066 ok( r == S_OK, "should be a document element\n");
1067 ok( element != NULL, "should be an element\n");
1069 ref = IXMLDOMDocument_AddRef( doc );
1070 ok( ref == 2, "ref %d\n", ref );
1071 IXMLDOMDocument_Release( doc );
1073 r = IXMLDOMElement_get_childNodes( element, &node_list );
1074 ok( r == S_OK, "rets %08x\n", r);
1075 ref = IXMLDOMNodeList_AddRef( node_list );
1076 ok( ref == 2, "ref %d\n", ref );
1077 IXMLDOMNodeList_Release( node_list );
1079 IXMLDOMNodeList_get_item( node_list, 0, &node );
1080 ok( r == S_OK, "rets %08x\n", r);
1082 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1083 ok( r == S_OK, "rets %08x\n", r);
1085 ref = IXMLDOMNode_AddRef( node );
1086 ok( ref == 2, "ref %d\n", ref );
1087 IXMLDOMNode_Release( node );
1089 ref = IXMLDOMNode_Release( node );
1090 ok( ref == 0, "ref %d\n", ref );
1091 ref = IXMLDOMNode_Release( node2 );
1092 ok( ref == 0, "ref %d\n", ref );
1094 ref = IXMLDOMNodeList_Release( node_list );
1095 ok( ref == 0, "ref %d\n", ref );
1097 ok( node != node2, "node %p node2 %p\n", node, node2 );
1099 ref = IXMLDOMDocument_Release( doc );
1100 ok( ref == 0, "ref %d\n", ref );
1102 ref = IXMLDOMElement_AddRef( element );
1103 todo_wine {
1104 ok( ref == 3, "ref %d\n", ref );
1106 IXMLDOMElement_Release( element );
1108 /* IUnknown must be unique however we obtain it */
1109 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1110 ok( r == S_OK, "rets %08x\n", r );
1111 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1112 ok( r == S_OK, "rets %08x\n", r );
1113 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1114 ok( r == S_OK, "rets %08x\n", r );
1115 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1117 IUnknown_Release( unk2 );
1118 IUnknown_Release( unk );
1119 IXMLDOMNode_Release( node );
1121 IXMLDOMElement_Release( element );
1125 static void test_create(void)
1127 HRESULT r;
1128 VARIANT var;
1129 BSTR str, name;
1130 IXMLDOMDocument *doc;
1131 IXMLDOMElement *element;
1132 IXMLDOMNode *root, *node, *child;
1133 IXMLDOMNamedNodeMap *attr_map;
1134 IUnknown *unk;
1135 LONG ref;
1136 long num;
1138 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1139 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1140 if( r != S_OK )
1141 return;
1143 V_VT(&var) = VT_I4;
1144 V_I4(&var) = NODE_ELEMENT;
1145 str = SysAllocString( szlc );
1146 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1147 ok( r == S_OK, "returns %08x\n", r );
1148 r = IXMLDOMDocument_appendChild( doc, node, &root );
1149 ok( r == S_OK, "returns %08x\n", r );
1150 ok( node == root, "%p %p\n", node, root );
1152 ref = IXMLDOMNode_AddRef( node );
1153 ok(ref == 3, "ref %d\n", ref);
1154 IXMLDOMNode_Release( node );
1156 ref = IXMLDOMNode_Release( node );
1157 ok(ref == 1, "ref %d\n", ref);
1158 SysFreeString( str );
1160 V_VT(&var) = VT_I4;
1161 V_I4(&var) = NODE_ELEMENT;
1162 str = SysAllocString( szbs );
1163 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1164 ok( r == S_OK, "returns %08x\n", r );
1166 ref = IXMLDOMNode_AddRef( node );
1167 ok(ref == 2, "ref = %d\n", ref);
1168 IXMLDOMNode_Release( node );
1170 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1171 ok( r == S_OK, "returns %08x\n", r );
1173 ref = IXMLDOMNode_AddRef( unk );
1174 ok(ref == 3, "ref = %d\n", ref);
1175 IXMLDOMNode_Release( unk );
1177 V_VT(&var) = VT_EMPTY;
1178 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1179 ok( r == S_OK, "returns %08x\n", r );
1180 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1181 IXMLDOMNode_Release( child );
1182 IUnknown_Release( unk );
1185 V_VT(&var) = VT_NULL;
1186 V_DISPATCH(&var) = (IDispatch*)node;
1187 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1188 ok( r == S_OK, "returns %08x\n", r );
1189 ok( node == child, "%p %p\n", node, child );
1190 IXMLDOMNode_Release( child );
1193 V_VT(&var) = VT_NULL;
1194 V_DISPATCH(&var) = (IDispatch*)node;
1195 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1196 ok( r == S_OK, "returns %08x\n", r );
1197 IXMLDOMNode_Release( node );
1199 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1200 ok( r == S_OK, "returns %08x\n", r );
1202 r = IXMLDOMElement_get_attributes( element, &attr_map );
1203 ok( r == S_OK, "returns %08x\n", r );
1204 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1205 ok( r == S_OK, "returns %08x\n", r );
1206 ok( num == 0, "num %ld\n", num );
1207 IXMLDOMNamedNodeMap_Release( attr_map );
1209 V_VT(&var) = VT_BSTR;
1210 V_BSTR(&var) = SysAllocString( szstr1 );
1211 name = SysAllocString( szdl );
1212 r = IXMLDOMElement_setAttribute( element, name, var );
1213 ok( r == S_OK, "returns %08x\n", r );
1214 r = IXMLDOMElement_get_attributes( element, &attr_map );
1215 ok( r == S_OK, "returns %08x\n", r );
1216 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1217 ok( r == S_OK, "returns %08x\n", r );
1218 ok( num == 1, "num %ld\n", num );
1219 IXMLDOMNamedNodeMap_Release( attr_map );
1220 VariantClear(&var);
1222 V_VT(&var) = VT_BSTR;
1223 V_BSTR(&var) = SysAllocString( szstr2 );
1224 r = IXMLDOMElement_setAttribute( element, name, var );
1225 ok( r == S_OK, "returns %08x\n", r );
1226 r = IXMLDOMElement_get_attributes( element, &attr_map );
1227 ok( r == S_OK, "returns %08x\n", r );
1228 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1229 ok( r == S_OK, "returns %08x\n", r );
1230 ok( num == 1, "num %ld\n", num );
1231 IXMLDOMNamedNodeMap_Release( attr_map );
1232 VariantClear(&var);
1233 r = IXMLDOMElement_getAttribute( element, name, &var );
1234 ok( r == S_OK, "returns %08x\n", r );
1235 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1236 VariantClear(&var);
1237 SysFreeString(name);
1239 V_VT(&var) = VT_BSTR;
1240 V_BSTR(&var) = SysAllocString( szstr1 );
1241 name = SysAllocString( szlc );
1242 r = IXMLDOMElement_setAttribute( element, name, var );
1243 ok( r == S_OK, "returns %08x\n", r );
1244 r = IXMLDOMElement_get_attributes( element, &attr_map );
1245 ok( r == S_OK, "returns %08x\n", r );
1246 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1247 ok( r == S_OK, "returns %08x\n", r );
1248 ok( num == 2, "num %ld\n", num );
1249 IXMLDOMNamedNodeMap_Release( attr_map );
1250 VariantClear(&var);
1251 SysFreeString(name);
1253 V_VT(&var) = VT_I4;
1254 V_I4(&var) = 10;
1255 name = SysAllocString( szbs );
1256 r = IXMLDOMElement_setAttribute( element, name, var );
1257 ok( r == S_OK, "returns %08x\n", r );
1258 VariantClear(&var);
1259 r = IXMLDOMElement_getAttribute( element, name, &var );
1260 ok( r == S_OK, "returns %08x\n", r );
1261 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1262 VariantClear(&var);
1263 SysFreeString(name);
1265 IXMLDOMElement_Release( element );
1266 IXMLDOMNode_Release( root );
1267 IXMLDOMDocument_Release( doc );
1270 static void test_getElementsByTagName(void)
1272 HRESULT r;
1273 BSTR str;
1274 VARIANT_BOOL b;
1275 IXMLDOMDocument *doc;
1276 IXMLDOMNodeList *node_list;
1277 long len;
1279 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1280 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1281 if( r != S_OK )
1282 return;
1284 str = SysAllocString( szComplete4 );
1285 r = IXMLDOMDocument_loadXML( doc, str, &b );
1286 ok( r == S_OK, "loadXML failed\n");
1287 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1288 SysFreeString( str );
1290 str = SysAllocString( szstar );
1291 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1292 ok( r == S_OK, "ret %08x\n", r );
1293 r = IXMLDOMNodeList_get_length( node_list, &len );
1294 ok( r == S_OK, "ret %08x\n", r );
1295 ok( len == 6, "len %ld\n", len );
1296 IXMLDOMNodeList_Release( node_list );
1297 SysFreeString( str );
1299 str = SysAllocString( szbs );
1300 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1301 ok( r == S_OK, "ret %08x\n", r );
1302 r = IXMLDOMNodeList_get_length( node_list, &len );
1303 ok( r == S_OK, "ret %08x\n", r );
1304 ok( len == 1, "len %ld\n", len );
1305 IXMLDOMNodeList_Release( node_list );
1306 SysFreeString( str );
1308 str = SysAllocString( szdl );
1309 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1310 ok( r == S_OK, "ret %08x\n", r );
1311 r = IXMLDOMNodeList_get_length( node_list, &len );
1312 ok( r == S_OK, "ret %08x\n", r );
1313 ok( len == 0, "len %ld\n", len );
1314 IXMLDOMNodeList_Release( node_list );
1315 SysFreeString( str );
1317 str = SysAllocString( szstr1 );
1318 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1319 ok( r == S_OK, "ret %08x\n", r );
1320 r = IXMLDOMNodeList_get_length( node_list, &len );
1321 ok( r == S_OK, "ret %08x\n", r );
1322 ok( len == 0, "len %ld\n", len );
1323 IXMLDOMNodeList_Release( node_list );
1324 SysFreeString( str );
1326 IXMLDOMDocument_Release( doc );
1329 static void test_get_text(void)
1331 HRESULT r;
1332 BSTR str;
1333 VARIANT_BOOL b;
1334 IXMLDOMDocument *doc;
1335 IXMLDOMNode *node, *node2, *node3;
1336 IXMLDOMNodeList *node_list;
1337 IXMLDOMNamedNodeMap *node_map;
1339 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1340 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1341 if( r != S_OK )
1342 return;
1344 str = SysAllocString( szComplete4 );
1345 r = IXMLDOMDocument_loadXML( doc, str, &b );
1346 ok( r == S_OK, "loadXML failed\n");
1347 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1348 SysFreeString( str );
1350 str = SysAllocString( szbs );
1351 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1352 ok( r == S_OK, "ret %08x\n", r );
1353 SysFreeString(str);
1355 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1356 ok( r == S_OK, "ret %08x\n", r );
1357 IXMLDOMNodeList_Release( node_list );
1359 /* Invalid output parameter*/
1360 r = IXMLDOMNode_get_text( node, NULL );
1361 ok( r == E_INVALIDARG, "ret %08x\n", r );
1363 r = IXMLDOMNode_get_text( node, &str );
1364 ok( r == S_OK, "ret %08x\n", r );
1365 todo_wine {
1366 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
1368 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
1369 SysFreeString(str);
1371 r = IXMLDOMNode_get_attributes( node, &node_map );
1372 ok( r == S_OK, "ret %08x\n", r );
1374 str = SysAllocString( szvr );
1375 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1376 ok( r == S_OK, "ret %08x\n", r );
1377 SysFreeString(str);
1379 r = IXMLDOMNode_get_text( node2, &str );
1380 ok( r == S_OK, "ret %08x\n", r );
1381 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1382 SysFreeString(str);
1384 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1385 ok( r == S_OK, "ret %08x\n", r );
1387 r = IXMLDOMNode_get_text( node3, &str );
1388 ok( r == S_OK, "ret %08x\n", r );
1389 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1390 SysFreeString(str);
1393 IXMLDOMNode_Release( node3 );
1394 IXMLDOMNode_Release( node2 );
1395 IXMLDOMNamedNodeMap_Release( node_map );
1396 IXMLDOMNode_Release( node );
1397 IXMLDOMDocument_Release( doc );
1400 static void test_get_childNodes(void)
1402 HRESULT r;
1403 BSTR str;
1404 VARIANT_BOOL b;
1405 IXMLDOMDocument *doc;
1406 IXMLDOMElement *element;
1407 IXMLDOMNode *node, *node2;
1408 IXMLDOMNodeList *node_list, *node_list2;
1409 long len;
1411 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1412 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1413 if( r != S_OK )
1414 return;
1416 str = SysAllocString( szComplete4 );
1417 r = IXMLDOMDocument_loadXML( doc, str, &b );
1418 ok( r == S_OK, "loadXML failed\n");
1419 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1420 SysFreeString( str );
1422 r = IXMLDOMDocument_get_documentElement( doc, &element );
1423 ok( r == S_OK, "ret %08x\n", r);
1425 r = IXMLDOMElement_get_childNodes( element, &node_list );
1426 ok( r == S_OK, "ret %08x\n", r);
1428 r = IXMLDOMNodeList_get_length( node_list, &len );
1429 ok( r == S_OK, "ret %08x\n", r);
1430 ok( len == 4, "len %ld\n", len);
1432 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1433 ok( r == S_OK, "ret %08x\n", r);
1435 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1436 ok( r == S_OK, "ret %08x\n", r);
1438 r = IXMLDOMNodeList_get_length( node_list2, &len );
1439 ok( r == S_OK, "ret %08x\n", r);
1440 ok( len == 0, "len %ld\n", len);
1442 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1443 ok( r == S_FALSE, "ret %08x\n", r);
1445 IXMLDOMNodeList_Release( node_list2 );
1446 IXMLDOMNode_Release( node );
1447 IXMLDOMNodeList_Release( node_list );
1448 IXMLDOMElement_Release( element );
1449 IXMLDOMDocument_Release( doc );
1452 static void test_removeChild(void)
1454 HRESULT r;
1455 BSTR str;
1456 VARIANT_BOOL b;
1457 IXMLDOMDocument *doc;
1458 IXMLDOMElement *element;
1459 IXMLDOMNode *node, *node2, *node3, *node4;
1460 IXMLDOMNodeList *node_list, *node_list2;
1462 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1463 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1464 if( r != S_OK )
1465 return;
1467 str = SysAllocString( szComplete4 );
1468 r = IXMLDOMDocument_loadXML( doc, str, &b );
1469 ok( r == S_OK, "loadXML failed\n");
1470 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1471 SysFreeString( str );
1473 r = IXMLDOMDocument_get_documentElement( doc, &element );
1474 ok( r == S_OK, "ret %08x\n", r);
1476 r = IXMLDOMElement_get_childNodes( element, &node_list );
1477 ok( r == S_OK, "ret %08x\n", r);
1479 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1480 ok( r == S_OK, "ret %08x\n", r);
1482 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1483 ok( r == S_OK, "ret %08x\n", r);
1485 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1486 ok( r == S_OK, "ret %08x\n", r);
1488 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1489 ok( r == E_INVALIDARG, "ret %08x\n", r );
1491 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1492 ok( r == S_OK, "ret %08x\n", r);
1493 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1495 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1496 ok( r == S_FALSE, "ret %08x\n", r);
1497 ok( node3 == NULL, "%p\n", node3 );
1499 IXMLDOMNode_Release( node2 );
1500 IXMLDOMNode_Release( node4 );
1501 IXMLDOMNodeList_Release( node_list2 );
1502 IXMLDOMNode_Release( node );
1503 IXMLDOMNodeList_Release( node_list );
1504 IXMLDOMElement_Release( element );
1505 IXMLDOMDocument_Release( doc );
1508 static void test_XMLHTTP(void)
1510 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1511 static WCHAR wszPOST[] = {'P','O','S','T',0};
1512 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1513 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1514 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1515 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1516 IXMLHttpRequest *pXMLHttpRequest;
1517 BSTR bstrResponse;
1518 VARIANT dummy;
1519 VARIANT varfalse;
1520 VARIANT varbody;
1521 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1522 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1523 (void **)&pXMLHttpRequest);
1524 todo_wine {
1525 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1527 if (hr != S_OK)
1528 return;
1530 VariantInit(&dummy);
1531 V_VT(&dummy) = VT_ERROR;
1532 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1533 VariantInit(&varfalse);
1534 V_VT(&varfalse) = VT_BOOL;
1535 V_BOOL(&varfalse) = VARIANT_FALSE;
1536 V_VT(&varbody) = VT_BSTR;
1537 V_BSTR(&varbody) = SysAllocString(wszBody);
1539 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1540 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1542 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1543 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1544 VariantClear(&varbody);
1546 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1547 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1548 /* the server currently returns "FAILED" because the Content-Type header is
1549 * not what the server expects */
1550 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1551 SysFreeString(bstrResponse);
1554 static void test_IXMLDOMDocument2(void)
1556 HRESULT r;
1557 VARIANT_BOOL b;
1558 BSTR str;
1559 IXMLDOMDocument *doc;
1560 IXMLDOMDocument2 *doc2;
1561 VARIANT var;
1562 int ref;
1564 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1565 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1566 if( r != S_OK )
1567 return;
1569 str = SysAllocString( szComplete4 );
1570 r = IXMLDOMDocument_loadXML( doc, str, &b );
1571 ok( r == S_OK, "loadXML failed\n");
1572 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1573 SysFreeString( str );
1575 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1576 ok( r == S_OK, "ret %08x\n", r );
1577 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1579 /* we will check if the variant got cleared */
1580 ref = IXMLDOMDocument2_AddRef(doc2);
1581 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1582 V_VT(&var) = VT_UNKNOWN;
1583 V_UNKNOWN(&var) = (IUnknown *)doc2;
1585 /* invalid calls */
1586 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1587 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1588 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1590 /* valid call */
1591 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1592 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1593 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1594 V_VT(&var) = VT_R4;
1596 /* the variant didn't get cleared*/
1597 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1599 /* setProperty tests */
1600 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1601 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1602 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1603 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1604 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1605 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1607 /* contrary to what MSDN calims you can switch back from XPath to XSLPattern */
1608 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1609 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1610 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1612 IXMLDOMDocument2_Release( doc2 );
1613 IXMLDOMDocument_Release( doc );
1614 free_bstrs();
1617 static void test_XPath(void)
1619 HRESULT r;
1620 VARIANT var;
1621 VARIANT_BOOL b;
1622 IXMLDOMDocument2 *doc;
1623 IXMLDOMNode *rootNode;
1624 IXMLDOMNode *elem1Node;
1625 IXMLDOMNode *node;
1626 IXMLDOMNodeList *list;
1628 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1629 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1630 if( r != S_OK )
1631 return;
1633 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1634 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1636 /* switch to XPath */
1637 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1639 /* some simple queries*/
1640 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1641 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1642 ole_check(IXMLDOMNodeList_reset(list));
1643 expect_list_and_release(list, "E2.D1");
1644 if (rootNode == NULL)
1645 return;
1647 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1648 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1650 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1651 expect_list_and_release(list, "E3.E2.E2.D1");
1653 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1654 /* using get_item for query results advances the position */
1655 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1656 expect_node(node, "E2.E2.D1");
1657 IXMLDOMNode_Release(node);
1658 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1659 expect_node(node, "E4.E2.D1");
1660 IXMLDOMNode_Release(node);
1661 ole_check(IXMLDOMNodeList_reset(list));
1662 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1664 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
1665 expect_list_and_release(list, "E2.D1");
1667 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
1668 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
1669 ole_check(IXMLDOMNodeList_reset(list));
1670 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1672 /* select an attribute */
1673 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
1674 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
1676 /* would evaluate to a number */
1677 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
1678 /* would evaluate to a boolean */
1679 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
1680 /* would evaluate to a string */
1681 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
1683 /* no results */
1684 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
1685 expect_list_and_release(list, "");
1686 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
1687 expect_list_and_release(list, "");
1688 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
1689 expect_list_and_release(list, "");
1691 /* foo undeclared in document node */
1692 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1693 /* undeclared in <root> node */
1694 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
1695 /* undeclared in <elem> node */
1696 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
1697 /* but this trick can be used */
1698 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
1699 expect_list_and_release(list, "E3.E4.E2.D1");
1701 /* it has to be declared in SelectionNamespaces */
1702 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1703 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
1705 /* now the namespace can be used */
1706 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
1707 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1708 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
1709 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1710 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
1711 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1712 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
1713 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
1715 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
1716 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1717 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
1719 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1721 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
1722 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1723 if (V_VT(&var) == VT_BSTR)
1724 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
1726 /* extra attributes - same thing*/
1727 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1728 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
1729 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1731 IXMLDOMNode_Release(rootNode);
1732 IXMLDOMNode_Release(elem1Node);
1733 IXMLDOMDocument_Release(doc);
1734 free_bstrs();
1737 static void test_cloneNode(void )
1739 IXMLDOMDocument *doc = NULL;
1740 VARIANT_BOOL b;
1741 IXMLDOMNodeList *pList;
1742 IXMLDOMNamedNodeMap *mapAttr;
1743 long nLength = 0, nLength1 = 0;
1744 long nAttrCnt = 0, nAttrCnt1 = 0;
1745 IXMLDOMNode *node;
1746 IXMLDOMNode *node_clone;
1747 HRESULT r;
1748 BSTR str;
1749 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
1751 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1752 if( r != S_OK )
1753 return;
1755 str = SysAllocString( szComplete4 );
1756 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
1757 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1758 SysFreeString(str);
1760 if(!b)
1761 return;
1763 str = SysAllocString( szSearch);
1764 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
1765 ok( r == S_OK, "ret %08x\n", r );
1766 ok( node != NULL, "node %p\n", node );
1767 SysFreeString(str);
1769 if(!node)
1771 IXMLDOMDocument_Release(doc);
1772 return;
1775 /* Check invalid parameter */
1776 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
1777 ok( r == E_INVALIDARG, "ret %08x\n", r );
1779 /* All Children */
1780 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
1781 ok( r == S_OK, "ret %08x\n", r );
1782 ok( node_clone != NULL, "node %p\n", node );
1784 if(!node_clone)
1786 IXMLDOMDocument_Release(doc);
1787 IXMLDOMNode_Release(node);
1788 return;
1791 r = IXMLDOMNode_get_childNodes(node, &pList);
1792 ok( r == S_OK, "ret %08x\n", r );
1793 if (pList)
1795 IXMLDOMNodeList_get_length(pList, &nLength);
1796 IXMLDOMNodeList_Release(pList);
1799 r = IXMLDOMNode_get_attributes(node, &mapAttr);
1800 ok( r == S_OK, "ret %08x\n", r );
1801 if(mapAttr)
1803 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
1804 IXMLDOMNamedNodeMap_Release(mapAttr);
1807 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
1808 ok( r == S_OK, "ret %08x\n", r );
1809 if (pList)
1811 IXMLDOMNodeList_get_length(pList, &nLength1);
1812 IXMLDOMNodeList_Release(pList);
1815 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
1816 ok( r == S_OK, "ret %08x\n", r );
1817 if(mapAttr)
1819 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
1820 IXMLDOMNamedNodeMap_Release(mapAttr);
1823 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
1824 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
1825 IXMLDOMNode_Release(node_clone);
1827 /* No Children */
1828 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
1829 ok( r == S_OK, "ret %08x\n", r );
1830 ok( node_clone != NULL, "node %p\n", node );
1832 if(!node_clone)
1834 IXMLDOMDocument_Release(doc);
1835 IXMLDOMNode_Release(node);
1836 return;
1839 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
1840 ok( r == S_OK, "ret %08x\n", r );
1841 if (pList)
1843 IXMLDOMNodeList_get_length(pList, &nLength1);
1844 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
1845 IXMLDOMNodeList_Release(pList);
1848 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
1849 ok( r == S_OK, "ret %08x\n", r );
1850 if(mapAttr)
1852 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
1853 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
1854 IXMLDOMNamedNodeMap_Release(mapAttr);
1857 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
1858 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
1859 IXMLDOMNode_Release(node_clone);
1862 IXMLDOMNode_Release(node);
1863 IXMLDOMDocument_Release(doc);
1866 static void test_xmlTypes(void)
1868 IXMLDOMDocument *doc = NULL;
1869 IXMLDOMElement *pRoot;
1870 HRESULT hr;
1871 IXMLDOMComment *pComment;
1872 IXMLDOMElement *pElement;
1873 IXMLDOMAttribute *pAttrubute;
1874 IXMLDOMNamedNodeMap *pAttribs;
1875 IXMLDOMCDATASection *pCDataSec;
1876 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
1877 IXMLDOMDocumentFragment *pDocFrag = NULL;
1878 BSTR str;
1879 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
1880 VARIANT v;
1882 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1883 if( hr != S_OK )
1884 return;
1886 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
1887 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1889 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
1890 ok(hr == S_FALSE, "ret %08x\n", hr );
1891 ok(pNextChild == NULL, "pDocChild not NULL\n");
1893 /* test previous Sibling */
1894 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
1895 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1897 pNextChild = (IXMLDOMNode *)0x1;
1898 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
1899 ok(hr == S_FALSE, "ret %08x\n", hr );
1900 ok(pNextChild == NULL, "pNextChild not NULL\n");
1902 /* test get_attributes */
1903 hr = IXMLDOMDocument_get_attributes( doc, NULL );
1904 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
1906 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
1907 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
1908 ok(hr == S_FALSE, "ret %08x\n", hr );
1909 ok( pAttribs == NULL, "pAttribs not NULL\n");
1911 /* test get_dataType */
1912 hr = IXMLDOMDocument_get_dataType(doc, &v);
1913 ok(hr == S_FALSE, "ret %08x\n", hr );
1914 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
1915 VariantClear(&v);
1917 /* test nodeTypeString */
1918 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
1919 ok(hr == S_OK, "ret %08x\n", hr );
1920 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
1921 SysFreeString(str);
1923 /* test implementation */
1924 hr = IXMLDOMDocument_get_implementation(doc, NULL);
1925 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1927 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
1928 ok(hr == S_OK, "ret %08x\n", hr );
1929 if(hr == S_OK)
1931 VARIANT_BOOL hasFeature = VARIANT_TRUE;
1932 BSTR sEmpty = SysAllocStringLen(NULL, 0);
1934 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
1935 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1937 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
1938 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1940 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
1941 ok(hr == S_OK, "ret %08x\n", hr );
1942 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
1944 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
1945 ok(hr == S_OK, "ret %08x\n", hr );
1946 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
1948 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
1949 ok(hr == S_OK, "ret %08x\n", hr );
1950 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
1952 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
1953 ok(hr == S_OK, "ret %08x\n", hr );
1954 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
1956 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
1957 ok(hr == S_OK, "ret %08x\n", hr );
1958 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
1960 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
1961 ok(hr == S_OK, "ret %08x\n", hr );
1962 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
1964 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
1965 ok(hr == S_OK, "ret %08x\n", hr );
1966 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
1968 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
1969 ok(hr == S_OK, "ret %08x\n", hr );
1970 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
1972 SysFreeString(sEmpty);
1973 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
1978 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
1979 ok(hr == S_OK, "ret %08x\n", hr );
1980 if(hr == S_OK)
1982 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
1983 ok(hr == S_OK, "ret %08x\n", hr );
1984 if(hr == S_OK)
1986 /* Comment */
1987 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
1988 ok(hr == S_OK, "ret %08x\n", hr );
1989 if(hr == S_OK)
1991 /* test get_attributes */
1992 hr = IXMLDOMComment_get_attributes( pComment, NULL );
1993 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
1995 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
1996 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
1997 ok(hr == S_FALSE, "ret %08x\n", hr );
1998 ok( pAttribs == NULL, "pAttribs not NULL\n");
2000 /* test nodeTypeString */
2001 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2002 ok(hr == S_OK, "ret %08x\n", hr );
2003 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2004 SysFreeString(str);
2006 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2007 ok(hr == S_OK, "ret %08x\n", hr );
2009 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2010 ok(hr == S_OK, "ret %08x\n", hr );
2011 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2012 SysFreeString(str);
2014 hr = IXMLDOMComment_get_xml(pComment, &str);
2015 ok(hr == S_OK, "ret %08x\n", hr );
2016 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2017 SysFreeString(str);
2019 hr = IXMLDOMComment_get_dataType(pComment, &v);
2020 ok(hr == S_FALSE, "ret %08x\n", hr );
2021 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2022 VariantClear(&v);
2024 IXMLDOMComment_Release(pComment);
2027 /* Element */
2028 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2029 ok(hr == S_OK, "ret %08x\n", hr );
2030 if(hr == S_OK)
2032 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2033 ok(hr == S_OK, "ret %08x\n", hr );
2035 /* test nodeTypeString */
2036 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2037 ok(hr == S_OK, "ret %08x\n", hr );
2038 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2039 SysFreeString(str);
2041 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2042 ok(hr == S_OK, "ret %08x\n", hr );
2043 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2044 SysFreeString(str);
2046 hr = IXMLDOMElement_get_xml(pElement, &str);
2047 ok(hr == S_OK, "ret %08x\n", hr );
2048 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2049 SysFreeString(str);
2051 hr = IXMLDOMElement_get_dataType(pElement, &v);
2052 ok(hr == S_FALSE, "ret %08x\n", hr );
2053 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2054 VariantClear(&v);
2056 /* Attribute */
2057 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2058 ok(hr == S_OK, "ret %08x\n", hr );
2059 if(hr == S_OK)
2061 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2063 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2064 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2066 pNextChild = (IXMLDOMNode *)0x1;
2067 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2068 ok(hr == S_FALSE, "ret %08x\n", hr );
2069 ok(pNextChild == NULL, "pNextChild not NULL\n");
2071 /* test Previous Sibling*/
2072 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2073 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2075 pNextChild = (IXMLDOMNode *)0x1;
2076 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2077 ok(hr == S_FALSE, "ret %08x\n", hr );
2078 ok(pNextChild == NULL, "pNextChild not NULL\n");
2080 /* test get_attributes */
2081 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2082 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2084 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2085 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2086 ok(hr == S_FALSE, "ret %08x\n", hr );
2087 ok( pAttribs == NULL, "pAttribs not NULL\n");
2089 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2090 ok(hr == E_FAIL, "ret %08x\n", hr );
2091 ok(pNewChild == NULL, "pNewChild not NULL\n");
2093 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2094 ok(hr == S_OK, "ret %08x\n", hr );
2095 if ( hr == S_OK )
2097 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2098 ok(hr == S_OK, "ret %08x\n", hr );
2100 IXMLDOMNamedNodeMap_Release(pAttribs);
2103 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2104 ok(hr == S_OK, "ret %08x\n", hr );
2105 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2106 SysFreeString(str);
2108 /* test nodeTypeString */
2109 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2110 ok(hr == S_OK, "ret %08x\n", hr );
2111 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2112 SysFreeString(str);
2114 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2115 ok(hr == S_OK, "ret %08x\n", hr );
2116 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2117 SysFreeString(str);
2119 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2120 ok(hr == S_FALSE, "ret %08x\n", hr );
2121 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2122 VariantClear(&v);
2124 IXMLDOMAttribute_Release(pAttrubute);
2126 /* Check Element again with the Add Attribute*/
2127 hr = IXMLDOMElement_get_xml(pElement, &str);
2128 ok(hr == S_OK, "ret %08x\n", hr );
2129 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2130 SysFreeString(str);
2133 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2134 ok(hr == S_OK, "ret %08x\n", hr );
2136 hr = IXMLDOMElement_get_xml(pElement, &str);
2137 ok(hr == S_OK, "ret %08x\n", hr );
2138 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2140 IXMLDOMElement_Release(pElement);
2143 /* CData Section */
2144 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2145 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2147 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2148 ok(hr == S_OK, "ret %08x\n", hr );
2149 if(hr == S_OK)
2151 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2153 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2154 ok(hr == S_OK, "ret %08x\n", hr );
2156 /* get Attribute Tests */
2157 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2158 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2160 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2161 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2162 ok(hr == S_FALSE, "ret %08x\n", hr );
2163 ok(pAttribs == NULL, "pAttribs != NULL\n");
2165 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2166 ok(hr == S_OK, "ret %08x\n", hr );
2167 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2168 SysFreeString(str);
2170 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2171 ok(hr == S_OK, "ret %08x\n", hr );
2172 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2173 SysFreeString(str);
2175 /* test lastChild */
2176 pNextChild = (IXMLDOMNode*)0x1;
2177 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2178 ok(hr == S_FALSE, "ret %08x\n", hr );
2179 ok(pNextChild == NULL, "pNextChild not NULL\n");
2181 /* test get_dataType */
2182 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2183 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2185 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2186 ok(hr == S_FALSE, "ret %08x\n", hr );
2187 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2188 VariantClear(&v);
2190 /* test nodeTypeString */
2191 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2192 ok(hr == S_OK, "ret %08x\n", hr );
2193 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2194 SysFreeString(str);
2196 IXMLDOMCDATASection_Release(pCDataSec);
2199 /* Document Fragments */
2200 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
2201 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2203 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
2204 ok(hr == S_OK, "ret %08x\n", hr );
2205 if(hr == S_OK)
2207 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2209 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
2210 ok(hr == S_OK, "ret %08x\n", hr );
2212 /* get Attribute Tests */
2213 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
2214 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2216 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2217 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
2218 ok(hr == S_FALSE, "ret %08x\n", hr );
2219 ok(pAttribs == NULL, "pAttribs != NULL\n");
2221 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
2222 ok(hr == S_OK, "ret %08x\n", hr );
2223 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
2224 SysFreeString(str);
2226 /* test next Sibling*/
2227 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
2228 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2230 pNextChild = (IXMLDOMNode *)0x1;
2231 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
2232 ok(hr == S_FALSE, "ret %08x\n", hr );
2233 ok(pNextChild == NULL, "pNextChild not NULL\n");
2235 /* test Previous Sibling*/
2236 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
2237 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2239 pNextChild = (IXMLDOMNode *)0x1;
2240 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
2241 ok(hr == S_FALSE, "ret %08x\n", hr );
2242 ok(pNextChild == NULL, "pNextChild not NULL\n");
2244 /* test get_dataType */
2245 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
2246 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2248 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
2249 ok(hr == S_FALSE, "ret %08x\n", hr );
2250 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2251 VariantClear(&v);
2253 /* test nodeTypeString */
2254 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
2255 ok(hr == S_OK, "ret %08x\n", hr );
2256 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
2257 SysFreeString(str);
2259 IXMLDOMDocumentFragment_Release(pCDataSec);
2265 IXMLDOMElement_Release( pRoot );
2269 IXMLDOMDocument_Release(doc);
2271 free_bstrs();
2274 START_TEST(domdoc)
2276 HRESULT r;
2278 r = CoInitialize( NULL );
2279 ok( r == S_OK, "failed to init com\n");
2281 test_domdoc();
2282 test_domnode();
2283 test_refs();
2284 test_create();
2285 test_getElementsByTagName();
2286 test_get_text();
2287 test_get_childNodes();
2288 test_removeChild();
2289 test_XMLHTTP();
2290 test_IXMLDOMDocument2();
2291 test_XPath();
2292 test_cloneNode();
2293 test_xmlTypes();
2295 CoUninitialize();