push a18c97e3310ae68c9cf1d09430f25ca292f320eb
[wine/hacks.git] / dlls / msxml3 / tests / domdoc.c
blobcbc7c6bdf598f3a92f7e0bd309b90cda4b4e762e
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 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
160 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
162 #define expect_bstr_eq_and_free(bstr, expect) { \
163 BSTR bstrExp = alloc_str_from_narrow(expect); \
164 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
165 SysFreeString(bstr); \
166 SysFreeString(bstrExp); \
169 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
171 #define ole_check(expr) { \
172 HRESULT r = expr; \
173 ok(r == S_OK, #expr " returned %x\n", r); \
176 #define ole_expect(expr, expect) { \
177 HRESULT r = expr; \
178 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
181 static BSTR alloc_str_from_narrow(const char *str)
183 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
184 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
185 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
186 return ret;
189 BSTR alloced_bstrs[256];
190 int alloced_bstrs_count = 0;
192 static BSTR _bstr_(const char *str)
194 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
195 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
196 return alloced_bstrs[alloced_bstrs_count++];
199 static void free_bstrs(void)
201 int i;
202 for (i = 0; i < alloced_bstrs_count; i++)
203 SysFreeString(alloced_bstrs[i]);
204 alloced_bstrs_count = 0;
207 static VARIANT _variantbstr_(const char *str)
209 VARIANT v;
210 V_VT(&v) = VT_BSTR;
211 V_BSTR(&v) = _bstr_(str);
212 return v;
215 static void get_str_for_type(DOMNodeType type, char *buf)
217 switch (type)
219 case NODE_ATTRIBUTE:
220 strcpy(buf, "A");
221 break;
222 case NODE_ELEMENT:
223 strcpy(buf, "E");
224 break;
225 case NODE_DOCUMENT:
226 strcpy(buf, "D");
227 break;
228 default:
229 wsprintfA(buf, "[%d]", type);
233 static int get_node_position(IXMLDOMNode *node)
235 HRESULT r;
236 int pos = 0;
238 IXMLDOMNode_AddRef(node);
241 IXMLDOMNode *new_node;
243 pos++;
244 r = IXMLDOMNode_get_previousSibling(node, &new_node);
245 ok(!FAILED(r), "get_previousSibling failed\n");
246 IXMLDOMNode_Release(node);
247 node = new_node;
248 } while (r == S_OK);
249 return pos;
252 static void node_to_string(IXMLDOMNode *node, char *buf)
254 HRESULT r = S_OK;
255 DOMNodeType type;
257 if (node == NULL)
259 lstrcpyA(buf, "(null)");
260 return;
263 IXMLDOMNode_AddRef(node);
264 while (r == S_OK)
266 IXMLDOMNode *new_node;
268 ole_check(IXMLDOMNode_get_nodeType(node, &type));
269 get_str_for_type(type, buf);
270 buf+=strlen(buf);
272 if (type == NODE_ATTRIBUTE)
274 BSTR bstr;
275 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
276 *(buf++) = '\'';
277 wsprintfA(buf, "%ws", bstr);
278 buf += strlen(buf);
279 *(buf++) = '\'';
280 SysFreeString(bstr);
282 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
284 else
286 int pos = get_node_position(node);
287 DOMNodeType parent_type = NODE_INVALID;
288 r = IXMLDOMNode_get_parentNode(node, &new_node);
290 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
291 * results we "fix" it */
292 if (r == S_OK)
293 ole_check(IXMLDOMNode_get_nodeType(node, &parent_type));
294 /* we need also to workaround the no document node problem - see below */
295 if (((r == S_FALSE && type != NODE_DOCUMENT) || parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
297 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
298 pos++;
300 wsprintf(buf, "%d", pos);
301 buf += strlen(buf);
304 ok(!FAILED(r), "get_parentNode failed (%08x)\n", r);
305 IXMLDOMNode_Release(node);
306 node = new_node;
307 if (r == S_OK)
308 *(buf++) = '.';
311 /* currently we can't access document node in wine. All our examples this is the
312 * root node so to be able to test query results we add it */
313 if (type != NODE_DOCUMENT)
315 todo_wine ok(FALSE, "Document node is not the last returned node!\n");
316 *(buf++) = '.';
317 *(buf++) = 'D';
318 *(buf++) = '1';
320 *buf = 0;
323 static char *list_to_string(IXMLDOMNodeList *list)
325 static char buf[4096];
326 char *pos = buf;
327 long len = 0;
328 int i;
330 if (list == NULL)
332 lstrcpyA(buf, "(null)");
333 return buf;
335 ole_check(IXMLDOMNodeList_get_length(list, &len));
336 for (i = 0; i < len; i++)
338 IXMLDOMNode *node;
339 if (i > 0)
340 *(pos++) = ' ';
341 ole_check(IXMLDOMNodeList_nextNode(list, &node));
342 node_to_string(node, pos);
343 pos += strlen(pos);
344 IXMLDOMNode_Release(node);
346 *pos = 0;
347 return buf;
350 #define expect_node(node, expstr) { char str[4096]; node_to_string(node, str); ok(strcmp(str, expstr)==0, "Invalid node: %s, exptected %s\n", str, expstr); }
351 #define expect_list_and_release(list, expstr) { char *str = list_to_string(list); ok(strcmp(str, expstr)==0, "Invalid node list: %s, exptected %s\n", str, expstr); if (list) IXMLDOMNodeList_Release(list); }
353 static void test_domdoc( void )
355 HRESULT r;
356 IXMLDOMDocument *doc = NULL;
357 IXMLDOMParseError *error;
358 IXMLDOMElement *element = NULL;
359 IXMLDOMNode *node;
360 IXMLDOMText *nodetext = NULL;
361 IXMLDOMComment *node_comment = NULL;
362 IXMLDOMAttribute *node_attr = NULL;
363 IXMLDOMNode *nodeChild = NULL;
364 IXMLDOMProcessingInstruction *nodePI = NULL;
365 VARIANT_BOOL b;
366 VARIANT var;
367 BSTR str;
368 long code;
370 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
371 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
372 if( r != S_OK )
373 return;
375 /* try some stupid things */
376 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
377 ok( r == S_FALSE, "loadXML failed\n");
379 b = VARIANT_TRUE;
380 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
381 ok( r == S_FALSE, "loadXML failed\n");
382 ok( b == VARIANT_FALSE, "failed to load XML string\n");
384 /* try to load a document from a nonexistent file */
385 b = VARIANT_TRUE;
386 str = SysAllocString( szNonExistentFile );
387 VariantInit(&var);
388 V_VT(&var) = VT_BSTR;
389 V_BSTR(&var) = str;
391 r = IXMLDOMDocument_load( doc, var, &b);
392 ok( r == S_FALSE, "load (from file) failed\n");
393 ok( b == VARIANT_FALSE, "failed to load XML file\n");
394 SysFreeString( str );
396 /* try load an empty document */
397 b = VARIANT_TRUE;
398 str = SysAllocString( szEmpty );
399 r = IXMLDOMDocument_loadXML( doc, str, &b );
400 ok( r == S_FALSE, "loadXML failed\n");
401 ok( b == VARIANT_FALSE, "failed to load XML string\n");
402 SysFreeString( str );
404 /* check that there's no document element */
405 element = NULL;
406 r = IXMLDOMDocument_get_documentElement( doc, &element );
407 ok( r == S_FALSE, "should be no document element\n");
409 /* try finding a node */
410 node = NULL;
411 str = SysAllocString( szstr1 );
412 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
413 ok( r == S_FALSE, "ret %08x\n", r );
414 SysFreeString( str );
416 b = VARIANT_TRUE;
417 str = SysAllocString( szIncomplete );
418 r = IXMLDOMDocument_loadXML( doc, str, &b );
419 ok( r == S_FALSE, "loadXML failed\n");
420 ok( b == VARIANT_FALSE, "failed to load XML string\n");
421 SysFreeString( str );
423 /* check that there's no document element */
424 element = (IXMLDOMElement*)1;
425 r = IXMLDOMDocument_get_documentElement( doc, &element );
426 ok( r == S_FALSE, "should be no document element\n");
427 ok( element == NULL, "Element should be NULL\n");
429 /* try to load something valid */
430 b = VARIANT_FALSE;
431 str = SysAllocString( szComplete1 );
432 r = IXMLDOMDocument_loadXML( doc, str, &b );
433 ok( r == S_OK, "loadXML failed\n");
434 ok( b == VARIANT_TRUE, "failed to load XML string\n");
435 SysFreeString( str );
437 /* try with a null out pointer */
438 r = IXMLDOMDocument_get_documentElement( doc, NULL );
439 ok( r == E_INVALIDARG, "should be no document element\n");
441 /* check if nodename is correct */
442 r = IXMLDOMDocument_get_nodeName( doc, NULL );
443 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
445 /* content doesn't matter here */
446 str = NULL;
447 r = IXMLDOMDocument_get_nodeName( doc, &str );
448 ok ( r == S_OK, "get_nodeName wrong code\n");
449 ok ( str != NULL, "str is null\n");
450 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
451 SysFreeString( str );
453 /* test put_text */
454 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
455 ok( r == E_FAIL, "ret %08x\n", r );
457 /* check that there's a document element */
458 element = NULL;
459 r = IXMLDOMDocument_get_documentElement( doc, &element );
460 ok( r == S_OK, "should be a document element\n");
461 if( element )
463 BSTR tag = NULL;
465 /* check if the tag is correct */
466 r = IXMLDOMElement_get_tagName( element, &tag );
467 ok( r == S_OK, "couldn't get tag name\n");
468 ok( tag != NULL, "tag was null\n");
469 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
470 SysFreeString( tag );
472 /* figure out what happens if we try to reload the document */
473 str = SysAllocString( szComplete2 );
474 r = IXMLDOMDocument_loadXML( doc, str, &b );
475 ok( r == S_OK, "loadXML failed\n");
476 ok( b == VARIANT_TRUE, "failed to load XML string\n");
477 SysFreeString( str );
479 /* check if the tag is still correct */
480 tag = NULL;
481 r = IXMLDOMElement_get_tagName( element, &tag );
482 ok( r == S_OK, "couldn't get tag name\n");
483 ok( tag != NULL, "tag was null\n");
484 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
485 SysFreeString( tag );
487 IXMLDOMElement_Release( element );
488 element = NULL;
491 /* as soon as we call loadXML again, the document element will disappear */
492 b = 2;
493 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
494 ok( r == S_FALSE, "loadXML failed\n");
495 ok( b == 2, "variant modified\n");
496 r = IXMLDOMDocument_get_documentElement( doc, &element );
497 ok( r == S_FALSE, "should be no document element\n");
499 /* try to load something else simple and valid */
500 b = VARIANT_FALSE;
501 str = SysAllocString( szComplete3 );
502 r = IXMLDOMDocument_loadXML( doc, str, &b );
503 ok( r == S_OK, "loadXML failed\n");
504 ok( b == VARIANT_TRUE, "failed to load XML string\n");
505 SysFreeString( str );
507 /* try something a little more complicated */
508 b = FALSE;
509 str = SysAllocString( szComplete4 );
510 r = IXMLDOMDocument_loadXML( doc, str, &b );
511 ok( r == S_OK, "loadXML failed\n");
512 ok( b == VARIANT_TRUE, "failed to load XML string\n");
513 SysFreeString( str );
515 r = IXMLDOMDocument_get_parseError( doc, &error );
516 ok( r == S_OK, "returns %08x\n", r );
518 r = IXMLDOMParseError_get_errorCode( error, &code );
519 ok( r == S_FALSE, "returns %08x\n", r );
520 ok( code == 0, "code %ld\n", code );
521 IXMLDOMParseError_Release( error );
523 /* test createTextNode */
524 str = SysAllocString( szOpen );
525 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
526 ok( r == E_INVALIDARG, "returns %08x\n", r );
527 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
528 ok( r == S_OK, "returns %08x\n", r );
529 if(nodetext)
531 IXMLDOMNamedNodeMap *pAttribs;
533 /* Text Last Child Checks */
534 r = IXMLDOMText_get_lastChild(nodetext, NULL);
535 ok(r == E_INVALIDARG, "ret %08x\n", r );
537 nodeChild = (IXMLDOMNode*)0x1;
538 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
539 ok(r == S_FALSE, "ret %08x\n", r );
540 ok(nodeChild == NULL, "nodeChild not NULL\n");
542 /* test get_attributes */
543 r = IXMLDOMText_get_attributes( nodetext, NULL );
544 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
546 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
547 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
548 ok(r == S_FALSE, "ret %08x\n", r );
549 ok( pAttribs == NULL, "pAttribs not NULL\n");
551 /* test get_dataType */
552 r = IXMLDOMText_get_dataType(nodetext, &var);
553 ok(r == S_FALSE, "ret %08x\n", r );
554 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
555 VariantClear(&var);
557 /* test nodeTypeString */
558 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
559 ok(r == S_OK, "ret %08x\n", r );
560 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
561 SysFreeString(str);
563 IXMLDOMText_Release( nodetext );
565 SysFreeString( str );
567 /* test Create Comment */
568 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
569 ok( r == E_INVALIDARG, "returns %08x\n", r );
570 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
571 ok( r == S_OK, "returns %08x\n", r );
572 if(node_comment)
574 /* Last Child Checks */
575 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
576 ok(r == E_INVALIDARG, "ret %08x\n", r );
578 nodeChild = (IXMLDOMNode*)0x1;
579 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
580 ok(r == S_FALSE, "ret %08x\n", r );
581 ok(nodeChild == NULL, "pLastChild not NULL\n");
583 IXMLDOMComment_Release( node_comment );
586 /* test Create Attribute */
587 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
588 ok( r == E_INVALIDARG, "returns %08x\n", r );
589 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
590 ok( r == S_OK, "returns %08x\n", r );
591 IXMLDOMText_Release( node_attr);
593 /* test Processing Instruction */
594 str = SysAllocStringLen(NULL, 0);
595 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
596 ok( r == E_INVALIDARG, "returns %08x\n", r );
597 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
598 ok( r == E_FAIL, "returns %08x\n", r );
599 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
600 ok( r == E_FAIL, "returns %08x\n", r );
601 SysFreeString(str);
603 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
604 ok( r == S_OK, "returns %08x\n", r );
605 if(nodePI)
607 /* Last Child Checks */
608 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
609 ok(r == E_INVALIDARG, "ret %08x\n", r );
611 nodeChild = (IXMLDOMNode*)0x1;
612 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
613 ok(r == S_FALSE, "ret %08x\n", r );
614 ok(nodeChild == NULL, "nodeChild not NULL\n");
616 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
617 ok(r == S_FALSE, "ret %08x\n", r );
618 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
619 VariantClear(&var);
621 /* test nodeTypeString */
622 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
623 ok(r == S_OK, "ret %08x\n", r );
624 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
625 SysFreeString(str);
627 IXMLDOMProcessingInstruction_Release(nodePI);
630 r = IXMLDOMDocument_Release( doc );
631 ok( r == 0, "document ref count incorrect\n");
635 static void test_domnode( void )
637 HRESULT r;
638 IXMLDOMDocument *doc = NULL, *owner = NULL;
639 IXMLDOMElement *element = NULL;
640 IXMLDOMNamedNodeMap *map = NULL;
641 IXMLDOMNode *node = NULL, *next = NULL;
642 IXMLDOMNodeList *list = NULL;
643 DOMNodeType type = NODE_INVALID;
644 VARIANT_BOOL b;
645 BSTR str;
646 VARIANT var;
647 long count;
649 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
650 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
651 if( r != S_OK )
652 return;
654 b = FALSE;
655 str = SysAllocString( szComplete4 );
656 r = IXMLDOMDocument_loadXML( doc, str, &b );
657 ok( r == S_OK, "loadXML failed\n");
658 ok( b == VARIANT_TRUE, "failed to load XML string\n");
659 SysFreeString( str );
661 if (doc)
663 b = 1;
664 r = IXMLDOMNode_hasChildNodes( doc, &b );
665 ok( r == S_OK, "hasChildNoes bad return\n");
666 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
668 r = IXMLDOMDocument_get_documentElement( doc, &element );
669 ok( r == S_OK, "should be a document element\n");
670 ok( element != NULL, "should be an element\n");
672 else
673 ok( FALSE, "no document\n");
675 VariantInit(&var);
676 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
678 r = IXMLDOMNode_get_nodeValue( doc, NULL );
679 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
681 r = IXMLDOMNode_get_nodeValue( doc, &var );
682 ok( r == S_FALSE, "nextNode returned wrong code\n");
683 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
684 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
686 if (element)
688 owner = NULL;
689 r = IXMLDOMNode_get_ownerDocument( element, &owner );
690 todo_wine {
691 ok( r == S_OK, "get_ownerDocument return code\n");
693 ok( owner != doc, "get_ownerDocument return\n");
695 type = NODE_INVALID;
696 r = IXMLDOMNode_get_nodeType( element, &type);
697 ok( r == S_OK, "getNamedItem returned wrong code\n");
698 ok( type == NODE_ELEMENT, "node not an element\n");
700 str = NULL;
701 r = IXMLDOMNode_get_baseName( element, &str );
702 ok( r == S_OK, "get_baseName returned wrong code\n");
703 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
704 SysFreeString(str);
706 /* check if nodename is correct */
707 r = IXMLDOMElement_get_nodeName( element, NULL );
708 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
710 /* content doesn't matter here */
711 str = NULL;
712 r = IXMLDOMElement_get_nodeName( element, &str );
713 ok ( r == S_OK, "get_nodeName wrong code\n");
714 ok ( str != NULL, "str is null\n");
715 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
716 SysFreeString( str );
718 str = SysAllocString( szNonExistentFile );
719 V_VT(&var) = VT_I4;
720 V_I4(&var) = 0x1234;
721 r = IXMLDOMElement_getAttribute( element, str, &var );
722 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
723 ok( V_VT(&var) == VT_NULL, "vt = %x\n", V_VT(&var));
724 VariantClear(&var);
725 SysFreeString( str );
727 str = SysAllocString( szdl );
728 V_VT(&var) = VT_I4;
729 V_I4(&var) = 0x1234;
730 r = IXMLDOMElement_getAttribute( element, str, &var );
731 ok( r == S_OK, "getAttribute ret %08x\n", r );
732 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
733 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
734 VariantClear( &var );
736 r = IXMLDOMElement_getAttribute( element, NULL, &var );
737 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
739 r = IXMLDOMElement_getAttribute( element, str, NULL );
740 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
742 SysFreeString( str );
744 r = IXMLDOMElement_get_attributes( element, &map );
745 ok( r == S_OK, "get_attributes returned wrong code\n");
746 ok( map != NULL, "should be attributes\n");
748 b = 1;
749 r = IXMLDOMNode_hasChildNodes( element, &b );
750 ok( r == S_OK, "hasChildNoes bad return\n");
751 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
753 else
754 ok( FALSE, "no element\n");
756 if (map)
758 ISupportErrorInfo *support_error;
759 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
760 ok( r == S_OK, "ret %08x\n", r );
762 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
763 todo_wine
765 ok( r == S_OK, "ret %08x\n", r );
767 ISupportErrorInfo_Release( support_error );
769 str = SysAllocString( szdl );
770 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
771 ok( r == S_OK, "getNamedItem returned wrong code\n");
772 ok( node != NULL, "should be attributes\n");
773 IXMLDOMNode_Release(node);
774 SysFreeString( str );
776 str = SysAllocString( szdl );
777 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
778 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
779 SysFreeString( str );
781 /* something that isn't in szComplete4 */
782 str = SysAllocString( szOpen );
783 node = (IXMLDOMNode *) 1;
784 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
785 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
786 ok( node == NULL, "getNamedItem should have returned NULL\n");
787 SysFreeString( str );
789 /* test indexed access of attributes */
790 r = IXMLDOMNamedNodeMap_get_length( map, &count );
791 ok ( r == S_OK, "get_length wrong code\n");
792 ok ( count == 1, "get_length != 1\n");
794 node = NULL;
795 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
796 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
797 ok ( node == NULL, "there is no node\n");
799 node = NULL;
800 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
801 ok ( r == S_FALSE, "get_item (1) wrong code\n");
802 ok ( node == NULL, "there is no attribute\n");
804 node = NULL;
805 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
806 ok ( r == S_OK, "get_item (0) wrong code\n");
807 ok ( node != NULL, "should be attribute\n");
809 r = IXMLDOMNode_get_nodeName( node, NULL );
810 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
812 /* content doesn't matter here */
813 str = NULL;
814 r = IXMLDOMNode_get_nodeName( node, &str );
815 ok ( r == S_OK, "get_nodeName wrong code\n");
816 ok ( str != NULL, "str is null\n");
817 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
818 SysFreeString( str );
820 /* test sequential access of attributes */
821 node = NULL;
822 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
823 ok ( r == S_OK, "nextNode (first time) wrong code\n");
824 ok ( node != NULL, "nextNode, should be attribute\n");
826 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
827 ok ( r != S_OK, "nextNode (second time) wrong code\n");
828 ok ( node == NULL, "nextNode, there is no attribute\n");
830 r = IXMLDOMNamedNodeMap_reset( map );
831 ok ( r == S_OK, "reset should return S_OK\n");
833 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
834 ok ( r == S_OK, "nextNode (third time) wrong code\n");
835 ok ( node != NULL, "nextNode, should be attribute\n");
837 else
838 ok( FALSE, "no map\n");
840 if (node)
842 type = NODE_INVALID;
843 r = IXMLDOMNode_get_nodeType( node, &type);
844 ok( r == S_OK, "getNamedItem returned wrong code\n");
845 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
847 str = NULL;
848 r = IXMLDOMNode_get_baseName( node, NULL );
849 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
851 str = NULL;
852 r = IXMLDOMNode_get_baseName( node, &str );
853 ok( r == S_OK, "get_baseName returned wrong code\n");
854 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
855 SysFreeString( str );
857 r = IXMLDOMNode_get_nodeValue( node, &var );
858 ok( r == S_OK, "returns %08x\n", r );
859 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
860 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
861 VariantClear(&var);
863 r = IXMLDOMNode_get_childNodes( node, NULL );
864 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
866 r = IXMLDOMNode_get_childNodes( node, &list );
867 ok( r == S_OK, "get_childNodes returned wrong code\n");
869 if (list)
871 r = IXMLDOMNodeList_nextNode( list, &next );
872 ok( r == S_OK, "nextNode returned wrong code\n");
874 else
875 ok( FALSE, "no childlist\n");
877 if (next)
879 b = 1;
880 r = IXMLDOMNode_hasChildNodes( next, &b );
881 ok( r == S_FALSE, "hasChildNoes bad return\n");
882 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
884 type = NODE_INVALID;
885 r = IXMLDOMNode_get_nodeType( next, &type);
886 ok( r == S_OK, "getNamedItem returned wrong code\n");
887 ok( type == NODE_TEXT, "node not text\n");
889 str = (BSTR) 1;
890 r = IXMLDOMNode_get_baseName( next, &str );
891 ok( r == S_FALSE, "get_baseName returned wrong code\n");
892 ok( str == NULL, "basename was wrong\n");
893 SysFreeString(str);
895 else
896 ok( FALSE, "no next\n");
898 if (next)
899 IXMLDOMNode_Release( next );
900 next = NULL;
901 if (list)
902 IXMLDOMNodeList_Release( list );
903 list = NULL;
904 if (node)
905 IXMLDOMNode_Release( node );
907 else
908 ok( FALSE, "no node\n");
909 node = NULL;
911 if (map)
912 IXMLDOMNamedNodeMap_Release( map );
914 /* now traverse the tree from the root element */
915 if (element)
917 IXMLDOMNode *node;
918 r = IXMLDOMNode_get_childNodes( element, &list );
919 ok( r == S_OK, "get_childNodes returned wrong code\n");
921 /* using get_item for child list doesn't advance the position */
922 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
923 expect_node(node, "E2.E2.D1");
924 IXMLDOMNode_Release(node);
925 ole_check(IXMLDOMNodeList_nextNode(list, &node));
926 expect_node(node, "E1.E2.D1");
927 IXMLDOMNode_Release(node);
928 ole_check(IXMLDOMNodeList_reset(list));
930 IXMLDOMNodeList_AddRef(list);
931 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
932 ole_check(IXMLDOMNodeList_reset(list));
934 else
935 ok( FALSE, "no element\n");
937 node = (void*)0xdeadbeef;
938 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
939 ok( r == S_FALSE, "ret %08x\n", r );
940 ok( node == NULL, "node %p\n", node );
941 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
942 ok( r == S_OK, "ret %08x\n", r );
943 r = IXMLDOMNode_Release( node );
944 ok( r == 0, "ret %08x\n", r );
946 if (list)
948 r = IXMLDOMNodeList_get_length( list, &count );
949 ok( r == S_OK, "get_length returns %08x\n", r );
950 ok( count == 4, "get_length got %ld\n", count );
952 r = IXMLDOMNodeList_nextNode( list, &node );
953 ok( r == S_OK, "nextNode returned wrong code\n");
955 else
956 ok( FALSE, "no list\n");
958 if (node)
960 type = NODE_INVALID;
961 r = IXMLDOMNode_get_nodeType( node, &type);
962 ok( r == S_OK, "getNamedItem returned wrong code\n");
963 ok( type == NODE_ELEMENT, "node not text\n");
965 VariantInit(&var);
966 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
967 r = IXMLDOMNode_get_nodeValue( node, &var );
968 ok( r == S_FALSE, "nextNode returned wrong code\n");
969 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
970 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
972 r = IXMLDOMNode_hasChildNodes( node, NULL );
973 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
975 b = 1;
976 r = IXMLDOMNode_hasChildNodes( node, &b );
977 ok( r == S_OK, "hasChildNoes bad return\n");
978 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
980 str = NULL;
981 r = IXMLDOMNode_get_baseName( node, &str );
982 ok( r == S_OK, "get_baseName returned wrong code\n");
983 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
984 SysFreeString(str);
986 else
987 ok( FALSE, "no node\n");
989 if (node)
990 IXMLDOMNode_Release( node );
991 if (list)
992 IXMLDOMNodeList_Release( list );
993 if (element)
994 IXMLDOMElement_Release( element );
996 b = FALSE;
997 str = SysAllocString( szComplete5 );
998 r = IXMLDOMDocument_loadXML( doc, str, &b );
999 ok( r == S_OK, "loadXML failed\n");
1000 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1001 SysFreeString( str );
1003 b = 1;
1004 r = IXMLDOMNode_hasChildNodes( doc, &b );
1005 ok( r == S_OK, "hasChildNoes bad return\n");
1006 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1008 r = IXMLDOMDocument_get_documentElement( doc, &element );
1009 ok( r == S_OK, "should be a document element\n");
1010 ok( element != NULL, "should be an element\n");
1012 if (element)
1014 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1015 BSTR tag = NULL;
1017 /* check if the tag is correct */
1018 r = IXMLDOMElement_get_tagName( element, &tag );
1019 ok( r == S_OK, "couldn't get tag name\n");
1020 ok( tag != NULL, "tag was null\n");
1021 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1022 SysFreeString( tag );
1025 if (element)
1026 IXMLDOMElement_Release( element );
1027 if (doc)
1028 IXMLDOMDocument_Release( doc );
1031 static void test_refs(void)
1033 HRESULT r;
1034 BSTR str;
1035 VARIANT_BOOL b;
1036 IXMLDOMDocument *doc = NULL;
1037 IXMLDOMElement *element = NULL;
1038 IXMLDOMNode *node = NULL, *node2;
1039 IXMLDOMNodeList *node_list = NULL;
1040 LONG ref;
1041 IUnknown *unk, *unk2;
1043 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1044 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1045 if( r != S_OK )
1046 return;
1047 ref = IXMLDOMDocument_Release(doc);
1048 ok( ref == 0, "ref %d\n", ref);
1050 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1051 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1052 if( r != S_OK )
1053 return;
1055 str = SysAllocString( szComplete4 );
1056 r = IXMLDOMDocument_loadXML( doc, str, &b );
1057 ok( r == S_OK, "loadXML failed\n");
1058 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1059 SysFreeString( str );
1061 ref = IXMLDOMDocument_AddRef( doc );
1062 ok( ref == 2, "ref %d\n", ref );
1063 ref = IXMLDOMDocument_AddRef( doc );
1064 ok( ref == 3, "ref %d\n", ref );
1065 IXMLDOMDocument_Release( doc );
1066 IXMLDOMDocument_Release( doc );
1068 r = IXMLDOMDocument_get_documentElement( doc, &element );
1069 ok( r == S_OK, "should be a document element\n");
1070 ok( element != NULL, "should be an element\n");
1072 ref = IXMLDOMDocument_AddRef( doc );
1073 ok( ref == 2, "ref %d\n", ref );
1074 IXMLDOMDocument_Release( doc );
1076 r = IXMLDOMElement_get_childNodes( element, &node_list );
1077 ok( r == S_OK, "rets %08x\n", r);
1078 ref = IXMLDOMNodeList_AddRef( node_list );
1079 ok( ref == 2, "ref %d\n", ref );
1080 IXMLDOMNodeList_Release( node_list );
1082 IXMLDOMNodeList_get_item( node_list, 0, &node );
1083 ok( r == S_OK, "rets %08x\n", r);
1085 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1086 ok( r == S_OK, "rets %08x\n", r);
1088 ref = IXMLDOMNode_AddRef( node );
1089 ok( ref == 2, "ref %d\n", ref );
1090 IXMLDOMNode_Release( node );
1092 ref = IXMLDOMNode_Release( node );
1093 ok( ref == 0, "ref %d\n", ref );
1094 ref = IXMLDOMNode_Release( node2 );
1095 ok( ref == 0, "ref %d\n", ref );
1097 ref = IXMLDOMNodeList_Release( node_list );
1098 ok( ref == 0, "ref %d\n", ref );
1100 ok( node != node2, "node %p node2 %p\n", node, node2 );
1102 ref = IXMLDOMDocument_Release( doc );
1103 ok( ref == 0, "ref %d\n", ref );
1105 ref = IXMLDOMElement_AddRef( element );
1106 todo_wine {
1107 ok( ref == 3, "ref %d\n", ref );
1109 IXMLDOMElement_Release( element );
1111 /* IUnknown must be unique however we obtain it */
1112 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1113 ok( r == S_OK, "rets %08x\n", r );
1114 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1115 ok( r == S_OK, "rets %08x\n", r );
1116 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1117 ok( r == S_OK, "rets %08x\n", r );
1118 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1120 IUnknown_Release( unk2 );
1121 IUnknown_Release( unk );
1122 IXMLDOMNode_Release( node );
1124 IXMLDOMElement_Release( element );
1128 static void test_create(void)
1130 HRESULT r;
1131 VARIANT var;
1132 BSTR str, name;
1133 IXMLDOMDocument *doc;
1134 IXMLDOMElement *element;
1135 IXMLDOMNode *root, *node, *child;
1136 IXMLDOMNamedNodeMap *attr_map;
1137 IUnknown *unk;
1138 LONG ref;
1139 long num;
1141 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1142 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1143 if( r != S_OK )
1144 return;
1146 V_VT(&var) = VT_I4;
1147 V_I4(&var) = NODE_ELEMENT;
1148 str = SysAllocString( szlc );
1149 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1150 ok( r == S_OK, "returns %08x\n", r );
1151 r = IXMLDOMDocument_appendChild( doc, node, &root );
1152 ok( r == S_OK, "returns %08x\n", r );
1153 ok( node == root, "%p %p\n", node, root );
1155 ref = IXMLDOMNode_AddRef( node );
1156 ok(ref == 3, "ref %d\n", ref);
1157 IXMLDOMNode_Release( node );
1159 ref = IXMLDOMNode_Release( node );
1160 ok(ref == 1, "ref %d\n", ref);
1161 SysFreeString( str );
1163 V_VT(&var) = VT_I4;
1164 V_I4(&var) = NODE_ELEMENT;
1165 str = SysAllocString( szbs );
1166 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1167 ok( r == S_OK, "returns %08x\n", r );
1169 ref = IXMLDOMNode_AddRef( node );
1170 ok(ref == 2, "ref = %d\n", ref);
1171 IXMLDOMNode_Release( node );
1173 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1174 ok( r == S_OK, "returns %08x\n", r );
1176 ref = IXMLDOMNode_AddRef( unk );
1177 ok(ref == 3, "ref = %d\n", ref);
1178 IXMLDOMNode_Release( unk );
1180 V_VT(&var) = VT_EMPTY;
1181 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1182 ok( r == S_OK, "returns %08x\n", r );
1183 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1184 IXMLDOMNode_Release( child );
1185 IUnknown_Release( unk );
1188 V_VT(&var) = VT_NULL;
1189 V_DISPATCH(&var) = (IDispatch*)node;
1190 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1191 ok( r == S_OK, "returns %08x\n", r );
1192 ok( node == child, "%p %p\n", node, child );
1193 IXMLDOMNode_Release( child );
1196 V_VT(&var) = VT_NULL;
1197 V_DISPATCH(&var) = (IDispatch*)node;
1198 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1199 ok( r == S_OK, "returns %08x\n", r );
1200 IXMLDOMNode_Release( node );
1202 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1203 ok( r == S_OK, "returns %08x\n", r );
1205 r = IXMLDOMElement_get_attributes( element, &attr_map );
1206 ok( r == S_OK, "returns %08x\n", r );
1207 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1208 ok( r == S_OK, "returns %08x\n", r );
1209 ok( num == 0, "num %ld\n", num );
1210 IXMLDOMNamedNodeMap_Release( attr_map );
1212 V_VT(&var) = VT_BSTR;
1213 V_BSTR(&var) = SysAllocString( szstr1 );
1214 name = SysAllocString( szdl );
1215 r = IXMLDOMElement_setAttribute( element, name, var );
1216 ok( r == S_OK, "returns %08x\n", r );
1217 r = IXMLDOMElement_get_attributes( element, &attr_map );
1218 ok( r == S_OK, "returns %08x\n", r );
1219 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1220 ok( r == S_OK, "returns %08x\n", r );
1221 ok( num == 1, "num %ld\n", num );
1222 IXMLDOMNamedNodeMap_Release( attr_map );
1223 VariantClear(&var);
1225 V_VT(&var) = VT_BSTR;
1226 V_BSTR(&var) = SysAllocString( szstr2 );
1227 r = IXMLDOMElement_setAttribute( element, name, var );
1228 ok( r == S_OK, "returns %08x\n", r );
1229 r = IXMLDOMElement_get_attributes( element, &attr_map );
1230 ok( r == S_OK, "returns %08x\n", r );
1231 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1232 ok( r == S_OK, "returns %08x\n", r );
1233 ok( num == 1, "num %ld\n", num );
1234 IXMLDOMNamedNodeMap_Release( attr_map );
1235 VariantClear(&var);
1236 r = IXMLDOMElement_getAttribute( element, name, &var );
1237 ok( r == S_OK, "returns %08x\n", r );
1238 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1239 VariantClear(&var);
1240 SysFreeString(name);
1242 V_VT(&var) = VT_BSTR;
1243 V_BSTR(&var) = SysAllocString( szstr1 );
1244 name = SysAllocString( szlc );
1245 r = IXMLDOMElement_setAttribute( element, name, var );
1246 ok( r == S_OK, "returns %08x\n", r );
1247 r = IXMLDOMElement_get_attributes( element, &attr_map );
1248 ok( r == S_OK, "returns %08x\n", r );
1249 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1250 ok( r == S_OK, "returns %08x\n", r );
1251 ok( num == 2, "num %ld\n", num );
1252 IXMLDOMNamedNodeMap_Release( attr_map );
1253 VariantClear(&var);
1254 SysFreeString(name);
1256 V_VT(&var) = VT_I4;
1257 V_I4(&var) = 10;
1258 name = SysAllocString( szbs );
1259 r = IXMLDOMElement_setAttribute( element, name, var );
1260 ok( r == S_OK, "returns %08x\n", r );
1261 VariantClear(&var);
1262 r = IXMLDOMElement_getAttribute( element, name, &var );
1263 ok( r == S_OK, "returns %08x\n", r );
1264 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1265 VariantClear(&var);
1266 SysFreeString(name);
1268 IXMLDOMElement_Release( element );
1269 IXMLDOMNode_Release( root );
1270 IXMLDOMDocument_Release( doc );
1273 static void test_getElementsByTagName(void)
1275 HRESULT r;
1276 BSTR str;
1277 VARIANT_BOOL b;
1278 IXMLDOMDocument *doc;
1279 IXMLDOMNodeList *node_list;
1280 long len;
1282 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1283 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1284 if( r != S_OK )
1285 return;
1287 str = SysAllocString( szComplete4 );
1288 r = IXMLDOMDocument_loadXML( doc, str, &b );
1289 ok( r == S_OK, "loadXML failed\n");
1290 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1291 SysFreeString( str );
1293 str = SysAllocString( szstar );
1294 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1295 ok( r == S_OK, "ret %08x\n", r );
1296 r = IXMLDOMNodeList_get_length( node_list, &len );
1297 ok( r == S_OK, "ret %08x\n", r );
1298 ok( len == 6, "len %ld\n", len );
1299 IXMLDOMNodeList_Release( node_list );
1300 SysFreeString( str );
1302 str = SysAllocString( szbs );
1303 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1304 ok( r == S_OK, "ret %08x\n", r );
1305 r = IXMLDOMNodeList_get_length( node_list, &len );
1306 ok( r == S_OK, "ret %08x\n", r );
1307 ok( len == 1, "len %ld\n", len );
1308 IXMLDOMNodeList_Release( node_list );
1309 SysFreeString( str );
1311 str = SysAllocString( szdl );
1312 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1313 ok( r == S_OK, "ret %08x\n", r );
1314 r = IXMLDOMNodeList_get_length( node_list, &len );
1315 ok( r == S_OK, "ret %08x\n", r );
1316 ok( len == 0, "len %ld\n", len );
1317 IXMLDOMNodeList_Release( node_list );
1318 SysFreeString( str );
1320 str = SysAllocString( szstr1 );
1321 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1322 ok( r == S_OK, "ret %08x\n", r );
1323 r = IXMLDOMNodeList_get_length( node_list, &len );
1324 ok( r == S_OK, "ret %08x\n", r );
1325 ok( len == 0, "len %ld\n", len );
1326 IXMLDOMNodeList_Release( node_list );
1327 SysFreeString( str );
1329 IXMLDOMDocument_Release( doc );
1332 static void test_get_text(void)
1334 HRESULT r;
1335 BSTR str;
1336 VARIANT_BOOL b;
1337 IXMLDOMDocument *doc;
1338 IXMLDOMNode *node, *node2, *node3;
1339 IXMLDOMNodeList *node_list;
1340 IXMLDOMNamedNodeMap *node_map;
1342 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1343 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1344 if( r != S_OK )
1345 return;
1347 str = SysAllocString( szComplete4 );
1348 r = IXMLDOMDocument_loadXML( doc, str, &b );
1349 ok( r == S_OK, "loadXML failed\n");
1350 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1351 SysFreeString( str );
1353 str = SysAllocString( szbs );
1354 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1355 ok( r == S_OK, "ret %08x\n", r );
1356 SysFreeString(str);
1358 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1359 ok( r == S_OK, "ret %08x\n", r );
1360 IXMLDOMNodeList_Release( node_list );
1362 /* Invalid output parameter*/
1363 r = IXMLDOMNode_get_text( node, NULL );
1364 ok( r == E_INVALIDARG, "ret %08x\n", r );
1366 r = IXMLDOMNode_get_text( node, &str );
1367 ok( r == S_OK, "ret %08x\n", r );
1368 todo_wine {
1369 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
1371 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
1372 SysFreeString(str);
1374 r = IXMLDOMNode_get_attributes( node, &node_map );
1375 ok( r == S_OK, "ret %08x\n", r );
1377 str = SysAllocString( szvr );
1378 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1379 ok( r == S_OK, "ret %08x\n", r );
1380 SysFreeString(str);
1382 r = IXMLDOMNode_get_text( node2, &str );
1383 ok( r == S_OK, "ret %08x\n", r );
1384 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1385 SysFreeString(str);
1387 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1388 ok( r == S_OK, "ret %08x\n", r );
1390 r = IXMLDOMNode_get_text( node3, &str );
1391 ok( r == S_OK, "ret %08x\n", r );
1392 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1393 SysFreeString(str);
1396 IXMLDOMNode_Release( node3 );
1397 IXMLDOMNode_Release( node2 );
1398 IXMLDOMNamedNodeMap_Release( node_map );
1399 IXMLDOMNode_Release( node );
1400 IXMLDOMDocument_Release( doc );
1403 static void test_get_childNodes(void)
1405 HRESULT r;
1406 BSTR str;
1407 VARIANT_BOOL b;
1408 IXMLDOMDocument *doc;
1409 IXMLDOMElement *element;
1410 IXMLDOMNode *node, *node2;
1411 IXMLDOMNodeList *node_list, *node_list2;
1412 long len;
1414 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1415 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1416 if( r != S_OK )
1417 return;
1419 str = SysAllocString( szComplete4 );
1420 r = IXMLDOMDocument_loadXML( doc, str, &b );
1421 ok( r == S_OK, "loadXML failed\n");
1422 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1423 SysFreeString( str );
1425 r = IXMLDOMDocument_get_documentElement( doc, &element );
1426 ok( r == S_OK, "ret %08x\n", r);
1428 r = IXMLDOMElement_get_childNodes( element, &node_list );
1429 ok( r == S_OK, "ret %08x\n", r);
1431 r = IXMLDOMNodeList_get_length( node_list, &len );
1432 ok( r == S_OK, "ret %08x\n", r);
1433 ok( len == 4, "len %ld\n", len);
1435 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1436 ok( r == S_OK, "ret %08x\n", r);
1438 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1439 ok( r == S_OK, "ret %08x\n", r);
1441 r = IXMLDOMNodeList_get_length( node_list2, &len );
1442 ok( r == S_OK, "ret %08x\n", r);
1443 ok( len == 0, "len %ld\n", len);
1445 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1446 ok( r == S_FALSE, "ret %08x\n", r);
1448 IXMLDOMNodeList_Release( node_list2 );
1449 IXMLDOMNode_Release( node );
1450 IXMLDOMNodeList_Release( node_list );
1451 IXMLDOMElement_Release( element );
1452 IXMLDOMDocument_Release( doc );
1455 static void test_removeChild(void)
1457 HRESULT r;
1458 BSTR str;
1459 VARIANT_BOOL b;
1460 IXMLDOMDocument *doc;
1461 IXMLDOMElement *element;
1462 IXMLDOMNode *node, *node2, *node3, *node4;
1463 IXMLDOMNodeList *node_list, *node_list2;
1465 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1466 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1467 if( r != S_OK )
1468 return;
1470 str = SysAllocString( szComplete4 );
1471 r = IXMLDOMDocument_loadXML( doc, str, &b );
1472 ok( r == S_OK, "loadXML failed\n");
1473 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1474 SysFreeString( str );
1476 r = IXMLDOMDocument_get_documentElement( doc, &element );
1477 ok( r == S_OK, "ret %08x\n", r);
1479 r = IXMLDOMElement_get_childNodes( element, &node_list );
1480 ok( r == S_OK, "ret %08x\n", r);
1482 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1483 ok( r == S_OK, "ret %08x\n", r);
1485 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1486 ok( r == S_OK, "ret %08x\n", r);
1488 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1489 ok( r == S_OK, "ret %08x\n", r);
1491 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1492 ok( r == E_INVALIDARG, "ret %08x\n", r );
1494 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1495 ok( r == S_OK, "ret %08x\n", r);
1496 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1498 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1499 ok( r == S_FALSE, "ret %08x\n", r);
1500 ok( node3 == NULL, "%p\n", node3 );
1502 IXMLDOMNode_Release( node2 );
1503 IXMLDOMNode_Release( node4 );
1504 IXMLDOMNodeList_Release( node_list2 );
1505 IXMLDOMNode_Release( node );
1506 IXMLDOMNodeList_Release( node_list );
1507 IXMLDOMElement_Release( element );
1508 IXMLDOMDocument_Release( doc );
1511 static void test_XMLHTTP(void)
1513 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1514 static WCHAR wszPOST[] = {'P','O','S','T',0};
1515 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1516 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1517 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1518 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1519 IXMLHttpRequest *pXMLHttpRequest;
1520 BSTR bstrResponse;
1521 VARIANT dummy;
1522 VARIANT varfalse;
1523 VARIANT varbody;
1524 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1525 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1526 (void **)&pXMLHttpRequest);
1527 todo_wine {
1528 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1530 if (hr != S_OK)
1531 return;
1533 VariantInit(&dummy);
1534 V_VT(&dummy) = VT_ERROR;
1535 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1536 VariantInit(&varfalse);
1537 V_VT(&varfalse) = VT_BOOL;
1538 V_BOOL(&varfalse) = VARIANT_FALSE;
1539 V_VT(&varbody) = VT_BSTR;
1540 V_BSTR(&varbody) = SysAllocString(wszBody);
1542 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1543 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1545 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1546 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1547 VariantClear(&varbody);
1549 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1550 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1551 /* the server currently returns "FAILED" because the Content-Type header is
1552 * not what the server expects */
1553 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1554 SysFreeString(bstrResponse);
1557 static void test_IXMLDOMDocument2(void)
1559 HRESULT r;
1560 VARIANT_BOOL b;
1561 BSTR str;
1562 IXMLDOMDocument *doc;
1563 IXMLDOMDocument2 *doc2;
1564 VARIANT var;
1565 int ref;
1567 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1568 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1569 if( r != S_OK )
1570 return;
1572 str = SysAllocString( szComplete4 );
1573 r = IXMLDOMDocument_loadXML( doc, str, &b );
1574 ok( r == S_OK, "loadXML failed\n");
1575 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1576 SysFreeString( str );
1578 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1579 ok( r == S_OK, "ret %08x\n", r );
1580 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1582 /* we will check if the variant got cleared */
1583 ref = IXMLDOMDocument2_AddRef(doc2);
1584 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1585 V_VT(&var) = VT_UNKNOWN;
1586 V_UNKNOWN(&var) = (IUnknown *)doc2;
1588 /* invalid calls */
1589 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1590 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1591 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1593 /* valid call */
1594 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1595 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1596 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1597 V_VT(&var) = VT_R4;
1599 /* the variant didn't get cleared*/
1600 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1602 /* setProperty tests */
1603 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1604 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1605 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1606 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1607 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1608 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1610 /* contrary to what MSDN calims you can switch back from XPath to XSLPattern */
1611 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1612 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1613 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1615 IXMLDOMDocument2_Release( doc2 );
1616 IXMLDOMDocument_Release( doc );
1617 free_bstrs();
1620 static void test_XPath(void)
1622 HRESULT r;
1623 VARIANT var;
1624 VARIANT_BOOL b;
1625 IXMLDOMDocument2 *doc;
1626 IXMLDOMNode *rootNode;
1627 IXMLDOMNode *elem1Node;
1628 IXMLDOMNode *node;
1629 IXMLDOMNodeList *list;
1631 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1632 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1633 if( r != S_OK )
1634 return;
1636 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1637 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1639 /* switch to XPath */
1640 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1642 /* some simple queries*/
1643 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1644 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1645 ole_check(IXMLDOMNodeList_reset(list));
1646 expect_list_and_release(list, "E2.D1");
1647 if (rootNode == NULL)
1648 return;
1650 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1651 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1653 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1654 expect_list_and_release(list, "E3.E2.E2.D1");
1656 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1657 /* using get_item for query results advances the position */
1658 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1659 expect_node(node, "E2.E2.D1");
1660 IXMLDOMNode_Release(node);
1661 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1662 expect_node(node, "E4.E2.D1");
1663 IXMLDOMNode_Release(node);
1664 ole_check(IXMLDOMNodeList_reset(list));
1665 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1667 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
1668 expect_list_and_release(list, "E2.D1");
1670 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
1671 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
1672 ole_check(IXMLDOMNodeList_reset(list));
1673 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1675 /* select an attribute */
1676 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
1677 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
1679 /* would evaluate to a number */
1680 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
1681 /* would evaluate to a boolean */
1682 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
1683 /* would evaluate to a string */
1684 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
1686 /* no results */
1687 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
1688 expect_list_and_release(list, "");
1689 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
1690 expect_list_and_release(list, "");
1691 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
1692 expect_list_and_release(list, "");
1694 /* foo undeclared in document node */
1695 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1696 /* undeclared in <root> node */
1697 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
1698 /* undeclared in <elem> node */
1699 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
1700 /* but this trick can be used */
1701 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
1702 expect_list_and_release(list, "E3.E4.E2.D1");
1704 /* it has to be declared in SelectionNamespaces */
1705 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1706 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
1708 /* now the namespace can be used */
1709 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
1710 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1711 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
1712 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1713 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
1714 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
1715 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
1716 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
1718 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
1719 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1720 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
1722 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1724 VariantClear(&var);
1725 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
1726 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1727 if (V_VT(&var) == VT_BSTR)
1728 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
1730 /* extra attributes - same thing*/
1731 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
1732 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
1733 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
1735 IXMLDOMNode_Release(rootNode);
1736 IXMLDOMNode_Release(elem1Node);
1737 IXMLDOMDocument_Release(doc);
1738 free_bstrs();
1741 static void test_cloneNode(void )
1743 IXMLDOMDocument *doc = NULL;
1744 VARIANT_BOOL b;
1745 IXMLDOMNodeList *pList;
1746 IXMLDOMNamedNodeMap *mapAttr;
1747 long nLength = 0, nLength1 = 0;
1748 long nAttrCnt = 0, nAttrCnt1 = 0;
1749 IXMLDOMNode *node;
1750 IXMLDOMNode *node_clone;
1751 HRESULT r;
1752 BSTR str;
1753 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
1755 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1756 if( r != S_OK )
1757 return;
1759 str = SysAllocString( szComplete4 );
1760 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
1761 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1762 SysFreeString(str);
1764 if(!b)
1765 return;
1767 str = SysAllocString( szSearch);
1768 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
1769 ok( r == S_OK, "ret %08x\n", r );
1770 ok( node != NULL, "node %p\n", node );
1771 SysFreeString(str);
1773 if(!node)
1775 IXMLDOMDocument_Release(doc);
1776 return;
1779 /* Check invalid parameter */
1780 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
1781 ok( r == E_INVALIDARG, "ret %08x\n", r );
1783 /* All Children */
1784 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
1785 ok( r == S_OK, "ret %08x\n", r );
1786 ok( node_clone != NULL, "node %p\n", node );
1788 if(!node_clone)
1790 IXMLDOMDocument_Release(doc);
1791 IXMLDOMNode_Release(node);
1792 return;
1795 r = IXMLDOMNode_get_childNodes(node, &pList);
1796 ok( r == S_OK, "ret %08x\n", r );
1797 if (pList)
1799 IXMLDOMNodeList_get_length(pList, &nLength);
1800 IXMLDOMNodeList_Release(pList);
1803 r = IXMLDOMNode_get_attributes(node, &mapAttr);
1804 ok( r == S_OK, "ret %08x\n", r );
1805 if(mapAttr)
1807 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
1808 IXMLDOMNamedNodeMap_Release(mapAttr);
1811 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
1812 ok( r == S_OK, "ret %08x\n", r );
1813 if (pList)
1815 IXMLDOMNodeList_get_length(pList, &nLength1);
1816 IXMLDOMNodeList_Release(pList);
1819 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
1820 ok( r == S_OK, "ret %08x\n", r );
1821 if(mapAttr)
1823 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
1824 IXMLDOMNamedNodeMap_Release(mapAttr);
1827 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
1828 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
1829 IXMLDOMNode_Release(node_clone);
1831 /* No Children */
1832 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
1833 ok( r == S_OK, "ret %08x\n", r );
1834 ok( node_clone != NULL, "node %p\n", node );
1836 if(!node_clone)
1838 IXMLDOMDocument_Release(doc);
1839 IXMLDOMNode_Release(node);
1840 return;
1843 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
1844 ok( r == S_OK, "ret %08x\n", r );
1845 if (pList)
1847 IXMLDOMNodeList_get_length(pList, &nLength1);
1848 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
1849 IXMLDOMNodeList_Release(pList);
1852 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
1853 ok( r == S_OK, "ret %08x\n", r );
1854 if(mapAttr)
1856 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
1857 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
1858 IXMLDOMNamedNodeMap_Release(mapAttr);
1861 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
1862 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
1863 IXMLDOMNode_Release(node_clone);
1866 IXMLDOMNode_Release(node);
1867 IXMLDOMDocument_Release(doc);
1870 static void test_xmlTypes(void)
1872 IXMLDOMDocument *doc = NULL;
1873 IXMLDOMElement *pRoot;
1874 HRESULT hr;
1875 IXMLDOMComment *pComment;
1876 IXMLDOMElement *pElement;
1877 IXMLDOMAttribute *pAttrubute;
1878 IXMLDOMNamedNodeMap *pAttribs;
1879 IXMLDOMCDATASection *pCDataSec;
1880 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
1881 IXMLDOMDocumentFragment *pDocFrag = NULL;
1882 IXMLDOMEntityReference *pEntityRef = NULL;
1883 BSTR str;
1884 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
1885 VARIANT v;
1887 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1888 if( hr != S_OK )
1889 return;
1891 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
1892 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1894 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
1895 ok(hr == S_FALSE, "ret %08x\n", hr );
1896 ok(pNextChild == NULL, "pDocChild not NULL\n");
1898 /* test previous Sibling */
1899 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
1900 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1902 pNextChild = (IXMLDOMNode *)0x1;
1903 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
1904 ok(hr == S_FALSE, "ret %08x\n", hr );
1905 ok(pNextChild == NULL, "pNextChild not NULL\n");
1907 /* test get_attributes */
1908 hr = IXMLDOMDocument_get_attributes( doc, NULL );
1909 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
1911 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
1912 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
1913 ok(hr == S_FALSE, "ret %08x\n", hr );
1914 ok( pAttribs == NULL, "pAttribs not NULL\n");
1916 /* test get_dataType */
1917 hr = IXMLDOMDocument_get_dataType(doc, &v);
1918 ok(hr == S_FALSE, "ret %08x\n", hr );
1919 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
1920 VariantClear(&v);
1922 /* test nodeTypeString */
1923 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
1924 ok(hr == S_OK, "ret %08x\n", hr );
1925 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
1926 SysFreeString(str);
1928 /* test implementation */
1929 hr = IXMLDOMDocument_get_implementation(doc, NULL);
1930 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1932 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
1933 ok(hr == S_OK, "ret %08x\n", hr );
1934 if(hr == S_OK)
1936 VARIANT_BOOL hasFeature = VARIANT_TRUE;
1937 BSTR sEmpty = SysAllocStringLen(NULL, 0);
1939 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
1940 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1942 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
1943 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
1945 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
1946 ok(hr == S_OK, "ret %08x\n", hr );
1947 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
1949 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
1950 ok(hr == S_OK, "ret %08x\n", hr );
1951 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
1953 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
1954 ok(hr == S_OK, "ret %08x\n", hr );
1955 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
1957 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
1958 ok(hr == S_OK, "ret %08x\n", hr );
1959 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
1961 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
1962 ok(hr == S_OK, "ret %08x\n", hr );
1963 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
1965 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
1966 ok(hr == S_OK, "ret %08x\n", hr );
1967 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
1969 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
1970 ok(hr == S_OK, "ret %08x\n", hr );
1971 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
1973 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
1974 ok(hr == S_OK, "ret %08x\n", hr );
1975 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
1977 SysFreeString(sEmpty);
1978 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
1983 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
1984 ok(hr == S_OK, "ret %08x\n", hr );
1985 if(hr == S_OK)
1987 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
1988 ok(hr == S_OK, "ret %08x\n", hr );
1989 if(hr == S_OK)
1991 /* Comment */
1992 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
1993 ok(hr == S_OK, "ret %08x\n", hr );
1994 if(hr == S_OK)
1996 /* test get_attributes */
1997 hr = IXMLDOMComment_get_attributes( pComment, NULL );
1998 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2000 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2001 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2002 ok(hr == S_FALSE, "ret %08x\n", hr );
2003 ok( pAttribs == NULL, "pAttribs not NULL\n");
2005 /* test nodeTypeString */
2006 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2007 ok(hr == S_OK, "ret %08x\n", hr );
2008 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2009 SysFreeString(str);
2011 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2012 ok(hr == S_OK, "ret %08x\n", hr );
2014 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2015 ok(hr == S_OK, "ret %08x\n", hr );
2016 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2017 SysFreeString(str);
2019 hr = IXMLDOMComment_get_xml(pComment, &str);
2020 ok(hr == S_OK, "ret %08x\n", hr );
2021 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2022 SysFreeString(str);
2024 hr = IXMLDOMComment_get_dataType(pComment, &v);
2025 ok(hr == S_FALSE, "ret %08x\n", hr );
2026 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2027 VariantClear(&v);
2029 IXMLDOMComment_Release(pComment);
2032 /* Element */
2033 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2034 ok(hr == S_OK, "ret %08x\n", hr );
2035 if(hr == S_OK)
2037 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2038 ok(hr == S_OK, "ret %08x\n", hr );
2040 /* test nodeTypeString */
2041 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2042 ok(hr == S_OK, "ret %08x\n", hr );
2043 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2044 SysFreeString(str);
2046 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2047 ok(hr == S_OK, "ret %08x\n", hr );
2048 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2049 SysFreeString(str);
2051 hr = IXMLDOMElement_get_xml(pElement, &str);
2052 ok(hr == S_OK, "ret %08x\n", hr );
2053 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2054 SysFreeString(str);
2056 hr = IXMLDOMElement_get_dataType(pElement, &v);
2057 ok(hr == S_FALSE, "ret %08x\n", hr );
2058 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2059 VariantClear(&v);
2061 /* Attribute */
2062 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2063 ok(hr == S_OK, "ret %08x\n", hr );
2064 if(hr == S_OK)
2066 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2068 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2069 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2071 pNextChild = (IXMLDOMNode *)0x1;
2072 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2073 ok(hr == S_FALSE, "ret %08x\n", hr );
2074 ok(pNextChild == NULL, "pNextChild not NULL\n");
2076 /* test Previous Sibling*/
2077 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2078 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2080 pNextChild = (IXMLDOMNode *)0x1;
2081 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2082 ok(hr == S_FALSE, "ret %08x\n", hr );
2083 ok(pNextChild == NULL, "pNextChild not NULL\n");
2085 /* test get_attributes */
2086 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2087 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2089 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2090 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2091 ok(hr == S_FALSE, "ret %08x\n", hr );
2092 ok( pAttribs == NULL, "pAttribs not NULL\n");
2094 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2095 ok(hr == E_FAIL, "ret %08x\n", hr );
2096 ok(pNewChild == NULL, "pNewChild not NULL\n");
2098 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2099 ok(hr == S_OK, "ret %08x\n", hr );
2100 if ( hr == S_OK )
2102 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2103 ok(hr == S_OK, "ret %08x\n", hr );
2105 IXMLDOMNamedNodeMap_Release(pAttribs);
2108 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2109 ok(hr == S_OK, "ret %08x\n", hr );
2110 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2111 SysFreeString(str);
2113 /* test nodeTypeString */
2114 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2115 ok(hr == S_OK, "ret %08x\n", hr );
2116 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2117 SysFreeString(str);
2119 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2120 ok(hr == S_OK, "ret %08x\n", hr );
2121 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2122 SysFreeString(str);
2124 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2125 ok(hr == S_FALSE, "ret %08x\n", hr );
2126 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2127 VariantClear(&v);
2129 IXMLDOMAttribute_Release(pAttrubute);
2131 /* Check Element again with the Add Attribute*/
2132 hr = IXMLDOMElement_get_xml(pElement, &str);
2133 ok(hr == S_OK, "ret %08x\n", hr );
2134 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2135 SysFreeString(str);
2138 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2139 ok(hr == S_OK, "ret %08x\n", hr );
2141 hr = IXMLDOMElement_get_xml(pElement, &str);
2142 ok(hr == S_OK, "ret %08x\n", hr );
2143 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2145 IXMLDOMElement_Release(pElement);
2148 /* CData Section */
2149 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2150 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2152 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2153 ok(hr == S_OK, "ret %08x\n", hr );
2154 if(hr == S_OK)
2156 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2158 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2159 ok(hr == S_OK, "ret %08x\n", hr );
2161 /* get Attribute Tests */
2162 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2163 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2165 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2166 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2167 ok(hr == S_FALSE, "ret %08x\n", hr );
2168 ok(pAttribs == NULL, "pAttribs != NULL\n");
2170 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2171 ok(hr == S_OK, "ret %08x\n", hr );
2172 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2173 SysFreeString(str);
2175 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2176 ok(hr == S_OK, "ret %08x\n", hr );
2177 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2178 SysFreeString(str);
2180 /* test lastChild */
2181 pNextChild = (IXMLDOMNode*)0x1;
2182 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2183 ok(hr == S_FALSE, "ret %08x\n", hr );
2184 ok(pNextChild == NULL, "pNextChild not NULL\n");
2186 /* test get_dataType */
2187 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2188 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2190 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2191 ok(hr == S_FALSE, "ret %08x\n", hr );
2192 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2193 VariantClear(&v);
2195 /* test nodeTypeString */
2196 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2197 ok(hr == S_OK, "ret %08x\n", hr );
2198 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2199 SysFreeString(str);
2201 IXMLDOMCDATASection_Release(pCDataSec);
2204 /* Document Fragments */
2205 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
2206 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2208 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
2209 ok(hr == S_OK, "ret %08x\n", hr );
2210 if(hr == S_OK)
2212 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2214 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
2215 ok(hr == S_OK, "ret %08x\n", hr );
2217 /* get Attribute Tests */
2218 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
2219 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2221 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2222 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
2223 ok(hr == S_FALSE, "ret %08x\n", hr );
2224 ok(pAttribs == NULL, "pAttribs != NULL\n");
2226 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
2227 ok(hr == S_OK, "ret %08x\n", hr );
2228 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
2229 SysFreeString(str);
2231 /* test next Sibling*/
2232 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
2233 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2235 pNextChild = (IXMLDOMNode *)0x1;
2236 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
2237 ok(hr == S_FALSE, "ret %08x\n", hr );
2238 ok(pNextChild == NULL, "pNextChild not NULL\n");
2240 /* test Previous Sibling*/
2241 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
2242 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2244 pNextChild = (IXMLDOMNode *)0x1;
2245 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
2246 ok(hr == S_FALSE, "ret %08x\n", hr );
2247 ok(pNextChild == NULL, "pNextChild not NULL\n");
2249 /* test get_dataType */
2250 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
2251 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2253 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
2254 ok(hr == S_FALSE, "ret %08x\n", hr );
2255 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2256 VariantClear(&v);
2258 /* test nodeTypeString */
2259 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
2260 ok(hr == S_OK, "ret %08x\n", hr );
2261 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
2262 SysFreeString(str);
2264 IXMLDOMDocumentFragment_Release(pCDataSec);
2267 /* Entity References */
2268 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
2269 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2271 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
2272 ok(hr == S_OK, "ret %08x\n", hr );
2273 if(hr == S_OK)
2275 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
2276 ok(hr == S_OK, "ret %08x\n", hr );
2278 /* get Attribute Tests */
2279 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
2280 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2282 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2283 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
2284 ok(hr == S_FALSE, "ret %08x\n", hr );
2285 ok(pAttribs == NULL, "pAttribs != NULL\n");
2287 /* test dataType */
2288 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
2289 ok(hr == S_FALSE, "ret %08x\n", hr );
2290 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2291 VariantClear(&v);
2293 /* test nodeTypeString */
2294 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
2295 ok(hr == S_OK, "ret %08x\n", hr );
2296 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
2297 SysFreeString(str);
2299 /* test get_xml*/
2300 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
2301 ok(hr == S_OK, "ret %08x\n", hr );
2302 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
2303 SysFreeString(str);
2305 IXMLDOMEntityReference_Release(pEntityRef);
2308 IXMLDOMElement_Release( pRoot );
2312 IXMLDOMDocument_Release(doc);
2314 free_bstrs();
2317 START_TEST(domdoc)
2319 HRESULT r;
2321 r = CoInitialize( NULL );
2322 ok( r == S_OK, "failed to init com\n");
2324 test_domdoc();
2325 test_domnode();
2326 test_refs();
2327 test_create();
2328 test_getElementsByTagName();
2329 test_get_text();
2330 test_get_childNodes();
2331 test_removeChild();
2332 test_XMLHTTP();
2333 test_IXMLDOMDocument2();
2334 test_XPath();
2335 test_cloneNode();
2336 test_xmlTypes();
2338 CoUninitialize();