msxml3/tests: Clean up test_removeChild.
[wine/multimedia.git] / dlls / msxml3 / tests / domdoc.c
blob8922a3e9012e22d6074b7fef46399079258efc1f
1 /*
2 * XML test
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define COBJMACROS
25 #include "windows.h"
26 #include "ole2.h"
27 #include "xmldom.h"
28 #include "msxml2.h"
29 #include "msxml2did.h"
30 #include "dispex.h"
31 #include <stdio.h>
32 #include <assert.h>
34 #include "wine/test.h"
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 CHAR szTransformXML[] =
122 "<?xml version=\"1.0\"?>\n"
123 "<greeting>\n"
124 "Hello World\n"
125 "</greeting>";
127 static const CHAR szTransformSSXML[] =
128 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
129 " <xsl:output method=\"html\"/>\n"
130 " <xsl:template match=\"/\">\n"
131 " <xsl:apply-templates select=\"greeting\"/>\n"
132 " </xsl:template>\n"
133 " <xsl:template match=\"greeting\">\n"
134 " <html>\n"
135 " <body>\n"
136 " <h1>\n"
137 " <xsl:value-of select=\".\"/>\n"
138 " </h1>\n"
139 " </body>\n"
140 " </html>\n"
141 " </xsl:template>\n"
142 "</xsl:stylesheet>";
144 static const CHAR szTransformOutput[] =
145 "<html><body><h1>"
146 "Hello World"
147 "</h1></body></html>";
149 static const WCHAR szNonExistentFile[] = {
150 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
152 static const WCHAR szDocument[] = {
153 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
156 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
157 static WCHAR szdl[] = { 'd','l',0 };
158 static const WCHAR szvr[] = { 'v','r',0 };
159 static const WCHAR szlc[] = { 'l','c',0 };
160 static WCHAR szbs[] = { 'b','s',0 };
161 static const WCHAR szstr1[] = { 's','t','r','1',0 };
162 static const WCHAR szstr2[] = { 's','t','r','2',0 };
163 static const WCHAR szstar[] = { '*',0 };
164 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
166 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
167 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
168 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
170 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
171 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
172 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
173 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
174 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
176 static WCHAR szAttribute[] = {'A','t','t','r',0 };
177 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
179 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
180 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
181 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
182 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
183 '!',']',']','>',0};
184 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
185 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
187 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
188 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
190 #define expect_bstr_eq_and_free(bstr, expect) { \
191 BSTR bstrExp = alloc_str_from_narrow(expect); \
192 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
193 SysFreeString(bstr); \
194 SysFreeString(bstrExp); \
197 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
199 #define ole_check(expr) { \
200 HRESULT r = expr; \
201 ok(r == S_OK, #expr " returned %x\n", r); \
204 #define ole_expect(expr, expect) { \
205 HRESULT r = expr; \
206 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
209 static BSTR alloc_str_from_narrow(const char *str)
211 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
212 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
213 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
214 return ret;
217 BSTR alloced_bstrs[256];
218 int alloced_bstrs_count = 0;
220 static BSTR _bstr_(const char *str)
222 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
223 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
224 return alloced_bstrs[alloced_bstrs_count++];
227 static void free_bstrs(void)
229 int i;
230 for (i = 0; i < alloced_bstrs_count; i++)
231 SysFreeString(alloced_bstrs[i]);
232 alloced_bstrs_count = 0;
235 static VARIANT _variantbstr_(const char *str)
237 VARIANT v;
238 V_VT(&v) = VT_BSTR;
239 V_BSTR(&v) = _bstr_(str);
240 return v;
243 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
245 for (;;)
247 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
248 while (*sRight == '\r' || *sRight == '\n') sRight++;
249 if (*sLeft != *sRight) return FALSE;
250 if (!*sLeft) return TRUE;
251 sLeft++;
252 sRight++;
256 static void get_str_for_type(DOMNodeType type, char *buf)
258 switch (type)
260 case NODE_ATTRIBUTE:
261 strcpy(buf, "A");
262 break;
263 case NODE_ELEMENT:
264 strcpy(buf, "E");
265 break;
266 case NODE_DOCUMENT:
267 strcpy(buf, "D");
268 break;
269 default:
270 wsprintfA(buf, "[%d]", type);
274 static int get_node_position(IXMLDOMNode *node)
276 HRESULT r;
277 int pos = 0;
279 IXMLDOMNode_AddRef(node);
282 IXMLDOMNode *new_node;
284 pos++;
285 r = IXMLDOMNode_get_previousSibling(node, &new_node);
286 ok(!FAILED(r), "get_previousSibling failed\n");
287 IXMLDOMNode_Release(node);
288 node = new_node;
289 } while (r == S_OK);
290 return pos;
293 static void node_to_string(IXMLDOMNode *node, char *buf)
295 HRESULT r = S_OK;
296 DOMNodeType type;
298 if (node == NULL)
300 lstrcpyA(buf, "(null)");
301 return;
304 IXMLDOMNode_AddRef(node);
305 while (r == S_OK)
307 IXMLDOMNode *new_node;
309 ole_check(IXMLDOMNode_get_nodeType(node, &type));
310 get_str_for_type(type, buf);
311 buf+=strlen(buf);
313 if (type == NODE_ATTRIBUTE)
315 BSTR bstr;
316 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
317 *(buf++) = '\'';
318 wsprintfA(buf, "%ws", bstr);
319 buf += strlen(buf);
320 *(buf++) = '\'';
321 SysFreeString(bstr);
323 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
325 else
327 int pos = get_node_position(node);
328 DOMNodeType parent_type = NODE_INVALID;
329 r = IXMLDOMNode_get_parentNode(node, &new_node);
331 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
332 * results we "fix" it */
333 if (r == S_OK)
334 ole_check(IXMLDOMNode_get_nodeType(new_node, &parent_type));
335 if ((parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
337 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
338 pos++;
340 wsprintf(buf, "%d", pos);
341 buf += strlen(buf);
344 ok(!FAILED(r), "get_parentNode failed (%08x)\n", r);
345 IXMLDOMNode_Release(node);
346 node = new_node;
347 if (r == S_OK)
348 *(buf++) = '.';
351 *buf = 0;
354 static char *list_to_string(IXMLDOMNodeList *list)
356 static char buf[4096];
357 char *pos = buf;
358 long len = 0;
359 int i;
361 if (list == NULL)
363 lstrcpyA(buf, "(null)");
364 return buf;
366 ole_check(IXMLDOMNodeList_get_length(list, &len));
367 for (i = 0; i < len; i++)
369 IXMLDOMNode *node;
370 if (i > 0)
371 *(pos++) = ' ';
372 ole_check(IXMLDOMNodeList_nextNode(list, &node));
373 node_to_string(node, pos);
374 pos += strlen(pos);
375 IXMLDOMNode_Release(node);
377 *pos = 0;
378 return buf;
381 #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); }
382 #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); }
384 static void test_domdoc( void )
386 HRESULT r;
387 IXMLDOMDocument *doc = NULL;
388 IXMLDOMParseError *error;
389 IXMLDOMElement *element = NULL;
390 IXMLDOMNode *node;
391 IXMLDOMText *nodetext = NULL;
392 IXMLDOMComment *node_comment = NULL;
393 IXMLDOMAttribute *node_attr = NULL;
394 IXMLDOMNode *nodeChild = NULL;
395 IXMLDOMProcessingInstruction *nodePI = NULL;
396 VARIANT_BOOL b;
397 VARIANT var;
398 BSTR str;
399 long code;
400 long nLength = 0;
402 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
403 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
404 if( r != S_OK )
405 return;
407 /* try some stupid things */
408 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
409 ok( r == S_FALSE, "loadXML failed\n");
411 b = VARIANT_TRUE;
412 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
413 ok( r == S_FALSE, "loadXML failed\n");
414 ok( b == VARIANT_FALSE, "failed to load XML string\n");
416 /* try to load a document from a nonexistent file */
417 b = VARIANT_TRUE;
418 str = SysAllocString( szNonExistentFile );
419 VariantInit(&var);
420 V_VT(&var) = VT_BSTR;
421 V_BSTR(&var) = str;
423 r = IXMLDOMDocument_load( doc, var, &b);
424 ok( r == S_FALSE, "load (from file) failed\n");
425 ok( b == VARIANT_FALSE, "failed to load XML file\n");
426 SysFreeString( str );
428 /* try load an empty document */
429 b = VARIANT_TRUE;
430 str = SysAllocString( szEmpty );
431 r = IXMLDOMDocument_loadXML( doc, str, &b );
432 ok( r == S_FALSE, "loadXML failed\n");
433 ok( b == VARIANT_FALSE, "failed to load XML string\n");
434 SysFreeString( str );
436 /* check that there's no document element */
437 element = NULL;
438 r = IXMLDOMDocument_get_documentElement( doc, &element );
439 ok( r == S_FALSE, "should be no document element\n");
441 /* try finding a node */
442 node = NULL;
443 str = SysAllocString( szstr1 );
444 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
445 ok( r == S_FALSE, "ret %08x\n", r );
446 SysFreeString( str );
448 b = VARIANT_TRUE;
449 str = SysAllocString( szIncomplete );
450 r = IXMLDOMDocument_loadXML( doc, str, &b );
451 ok( r == S_FALSE, "loadXML failed\n");
452 ok( b == VARIANT_FALSE, "failed to load XML string\n");
453 SysFreeString( str );
455 /* check that there's no document element */
456 element = (IXMLDOMElement*)1;
457 r = IXMLDOMDocument_get_documentElement( doc, &element );
458 ok( r == S_FALSE, "should be no document element\n");
459 ok( element == NULL, "Element should be NULL\n");
461 /* try to load something valid */
462 b = VARIANT_FALSE;
463 str = SysAllocString( szComplete1 );
464 r = IXMLDOMDocument_loadXML( doc, str, &b );
465 ok( r == S_OK, "loadXML failed\n");
466 ok( b == VARIANT_TRUE, "failed to load XML string\n");
467 SysFreeString( str );
469 /* check if nodename is correct */
470 r = IXMLDOMDocument_get_nodeName( doc, NULL );
471 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
473 /* content doesn't matter here */
474 str = NULL;
475 r = IXMLDOMDocument_get_nodeName( doc, &str );
476 ok ( r == S_OK, "get_nodeName wrong code\n");
477 ok ( str != NULL, "str is null\n");
478 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
479 SysFreeString( str );
481 /* test put_text */
482 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
483 ok( r == E_FAIL, "ret %08x\n", r );
485 /* check that there's a document element */
486 element = NULL;
487 r = IXMLDOMDocument_get_documentElement( doc, &element );
488 ok( r == S_OK, "should be a document element\n");
489 if( element )
491 BSTR tag = NULL;
493 /* check if the tag is correct */
494 r = IXMLDOMElement_get_tagName( element, &tag );
495 ok( r == S_OK, "couldn't get tag name\n");
496 ok( tag != NULL, "tag was null\n");
497 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
498 SysFreeString( tag );
500 /* figure out what happens if we try to reload the document */
501 str = SysAllocString( szComplete2 );
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 /* check if the tag is still correct */
508 tag = NULL;
509 r = IXMLDOMElement_get_tagName( element, &tag );
510 ok( r == S_OK, "couldn't get tag name\n");
511 ok( tag != NULL, "tag was null\n");
512 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
513 SysFreeString( tag );
515 IXMLDOMElement_Release( element );
516 element = NULL;
519 /* as soon as we call loadXML again, the document element will disappear */
520 b = 2;
521 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
522 ok( r == S_FALSE, "loadXML failed\n");
523 ok( b == 2, "variant modified\n");
524 r = IXMLDOMDocument_get_documentElement( doc, &element );
525 ok( r == S_FALSE, "should be no document element\n");
527 /* try to load something else simple and valid */
528 b = VARIANT_FALSE;
529 str = SysAllocString( szComplete3 );
530 r = IXMLDOMDocument_loadXML( doc, str, &b );
531 ok( r == S_OK, "loadXML failed\n");
532 ok( b == VARIANT_TRUE, "failed to load XML string\n");
533 SysFreeString( str );
535 /* try something a little more complicated */
536 b = FALSE;
537 str = SysAllocString( szComplete4 );
538 r = IXMLDOMDocument_loadXML( doc, str, &b );
539 ok( r == S_OK, "loadXML failed\n");
540 ok( b == VARIANT_TRUE, "failed to load XML string\n");
541 SysFreeString( str );
543 r = IXMLDOMDocument_get_parseError( doc, &error );
544 ok( r == S_OK, "returns %08x\n", r );
546 r = IXMLDOMParseError_get_errorCode( error, &code );
547 ok( r == S_FALSE, "returns %08x\n", r );
548 ok( code == 0, "code %ld\n", code );
549 IXMLDOMParseError_Release( error );
551 /* test createTextNode */
552 str = SysAllocString( szOpen );
553 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
554 ok( r == E_INVALIDARG, "returns %08x\n", r );
555 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
556 ok( r == S_OK, "returns %08x\n", r );
557 SysFreeString( str );
558 if(nodetext)
560 IXMLDOMNamedNodeMap *pAttribs;
562 /* Text Last Child Checks */
563 r = IXMLDOMText_get_lastChild(nodetext, NULL);
564 ok(r == E_INVALIDARG, "ret %08x\n", r );
566 nodeChild = (IXMLDOMNode*)0x1;
567 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
568 ok(r == S_FALSE, "ret %08x\n", r );
569 ok(nodeChild == NULL, "nodeChild not NULL\n");
571 /* test get_attributes */
572 r = IXMLDOMText_get_attributes( nodetext, NULL );
573 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
575 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
576 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
577 ok(r == S_FALSE, "ret %08x\n", r );
578 ok( pAttribs == NULL, "pAttribs not NULL\n");
580 /* test get_dataType */
581 r = IXMLDOMText_get_dataType(nodetext, &var);
582 ok(r == S_FALSE, "ret %08x\n", r );
583 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
584 VariantClear(&var);
586 /* test length property */
587 r = IXMLDOMText_get_length(nodetext, NULL);
588 ok(r == E_INVALIDARG, "ret %08x\n", r );
590 r = IXMLDOMText_get_length(nodetext, &nLength);
591 ok(r == S_OK, "ret %08x\n", r );
592 ok(nLength == 4, "expected 4 got %ld\n", nLength);
594 /* test nodeTypeString */
595 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
596 ok(r == S_OK, "ret %08x\n", r );
597 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
598 SysFreeString(str);
600 /* put data Tests */
601 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
602 ok(r == S_OK, "ret %08x\n", r );
604 /* get data Tests */
605 r = IXMLDOMText_get_data(nodetext, &str);
606 ok(r == S_OK, "ret %08x\n", r );
607 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
608 SysFreeString(str);
610 /* Confirm XML text is good */
611 r = IXMLDOMText_get_xml(nodetext, &str);
612 ok(r == S_OK, "ret %08x\n", r );
613 ok( !lstrcmpW( str, _bstr_("This &amp;is a ; test &lt;&gt;\\") ), "incorrect xml string\n");
614 SysFreeString(str);
616 /* Confirm we get the put_data Text back */
617 r = IXMLDOMText_get_text(nodetext, &str);
618 ok(r == S_OK, "ret %08x\n", r );
619 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
620 SysFreeString(str);
622 /* test substringData */
623 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
624 ok(r == E_INVALIDARG, "ret %08x\n", r );
626 /* test substringData - Invalid offset */
627 str = (BSTR)&szElement;
628 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
629 ok(r == E_INVALIDARG, "ret %08x\n", r );
630 ok( str == NULL, "incorrect string\n");
632 /* test substringData - Invalid offset */
633 str = (BSTR)&szElement;
634 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
635 ok(r == S_FALSE, "ret %08x\n", r );
636 ok( str == NULL, "incorrect string\n");
638 /* test substringData - Invalid size */
639 str = (BSTR)&szElement;
640 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
641 ok(r == E_INVALIDARG, "ret %08x\n", r );
642 ok( str == NULL, "incorrect string\n");
644 /* test substringData - Invalid size */
645 str = (BSTR)&szElement;
646 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
647 ok(r == S_FALSE, "ret %08x\n", r );
648 ok( str == NULL, "incorrect string\n");
650 /* test substringData - Start of string */
651 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
652 ok(r == S_OK, "ret %08x\n", r );
653 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
654 SysFreeString(str);
656 /* test substringData - Middle of string */
657 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
658 ok(r == S_OK, "ret %08x\n", r );
659 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
660 SysFreeString(str);
662 /* test substringData - End of string */
663 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
664 ok(r == S_OK, "ret %08x\n", r );
665 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
666 SysFreeString(str);
668 /* test appendData */
669 r = IXMLDOMText_appendData(nodetext, NULL);
670 ok(r == S_OK, "ret %08x\n", r );
672 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
673 ok(r == S_OK, "ret %08x\n", r );
675 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
676 ok(r == S_OK, "ret %08x\n", r );
678 r = IXMLDOMText_get_text(nodetext, &str);
679 ok(r == S_OK, "ret %08x\n", r );
680 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
681 SysFreeString(str);
683 /* test insertData */
684 str = SysAllocStringLen(NULL, 0);
685 r = IXMLDOMText_insertData(nodetext, -1, str);
686 ok(r == S_OK, "ret %08x\n", r );
688 r = IXMLDOMText_insertData(nodetext, -1, NULL);
689 ok(r == S_OK, "ret %08x\n", r );
691 r = IXMLDOMText_insertData(nodetext, 1000, str);
692 ok(r == S_OK, "ret %08x\n", r );
694 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
695 ok(r == S_OK, "ret %08x\n", r );
697 r = IXMLDOMText_insertData(nodetext, 0, NULL);
698 ok(r == S_OK, "ret %08x\n", r );
700 r = IXMLDOMText_insertData(nodetext, 0, str);
701 ok(r == S_OK, "ret %08x\n", r );
702 SysFreeString(str);
704 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
705 ok(r == E_INVALIDARG, "ret %08x\n", r );
707 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
708 ok(r == E_INVALIDARG, "ret %08x\n", r );
710 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
711 ok(r == S_OK, "ret %08x\n", r );
713 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
714 ok(r == S_OK, "ret %08x\n", r );
716 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
717 ok(r == S_OK, "ret %08x\n", r );
719 r = IXMLDOMText_get_text(nodetext, &str);
720 ok(r == S_OK, "ret %08x\n", r );
721 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
722 SysFreeString(str);
724 IXMLDOMText_Release( nodetext );
727 /* test Create Comment */
728 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
729 ok( r == E_INVALIDARG, "returns %08x\n", r );
730 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
731 ok( r == S_OK, "returns %08x\n", r );
732 if(node_comment)
734 /* Last Child Checks */
735 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
736 ok(r == E_INVALIDARG, "ret %08x\n", r );
738 nodeChild = (IXMLDOMNode*)0x1;
739 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
740 ok(r == S_FALSE, "ret %08x\n", r );
741 ok(nodeChild == NULL, "pLastChild not NULL\n");
743 IXMLDOMComment_Release( node_comment );
746 /* test Create Attribute */
747 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
748 ok( r == E_INVALIDARG, "returns %08x\n", r );
749 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
750 ok( r == S_OK, "returns %08x\n", r );
751 IXMLDOMText_Release( node_attr);
753 /* test Processing Instruction */
754 str = SysAllocStringLen(NULL, 0);
755 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
756 ok( r == E_INVALIDARG, "returns %08x\n", r );
757 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
758 ok( r == E_FAIL, "returns %08x\n", r );
759 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
760 ok( r == E_FAIL, "returns %08x\n", r );
761 SysFreeString(str);
763 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
764 ok( r == S_OK, "returns %08x\n", r );
765 if(nodePI)
767 /* Last Child Checks */
768 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
769 ok(r == E_INVALIDARG, "ret %08x\n", r );
771 nodeChild = (IXMLDOMNode*)0x1;
772 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
773 ok(r == S_FALSE, "ret %08x\n", r );
774 ok(nodeChild == NULL, "nodeChild not NULL\n");
776 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
777 ok(r == S_FALSE, "ret %08x\n", r );
778 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
779 VariantClear(&var);
781 /* test nodeName */
782 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
783 ok(r == S_OK, "ret %08x\n", r );
784 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
785 SysFreeString(str);
787 /* test Target */
788 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
789 ok(r == S_OK, "ret %08x\n", r );
790 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
791 SysFreeString(str);
793 /* test nodeTypeString */
794 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
795 ok(r == S_OK, "ret %08x\n", r );
796 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
797 SysFreeString(str);
799 /* test get_nodeValue */
800 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
801 ok(r == S_OK, "ret %08x\n", r );
802 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
803 VariantClear(&var);
805 /* test get_data */
806 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
807 ok(r == S_OK, "ret %08x\n", r );
808 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
809 SysFreeString(str);
811 /* test put_data */
812 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
813 ok(r == E_FAIL, "ret %08x\n", r );
815 /* test put_data */
816 V_VT(&var) = VT_BSTR;
817 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
818 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
819 ok(r == E_FAIL, "ret %08x\n", r );
820 VariantClear(&var);
822 /* test get nodeName */
823 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
824 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
825 ok(r == S_OK, "ret %08x\n", r );
826 SysFreeString(str);
828 IXMLDOMProcessingInstruction_Release(nodePI);
831 r = IXMLDOMDocument_Release( doc );
832 ok( r == 0, "document ref count incorrect\n");
834 free_bstrs();
837 static void test_domnode( void )
839 HRESULT r;
840 IXMLDOMDocument *doc = NULL, *owner = NULL;
841 IXMLDOMElement *element = NULL;
842 IXMLDOMNamedNodeMap *map = NULL;
843 IXMLDOMNode *node = NULL, *next = NULL;
844 IXMLDOMNodeList *list = NULL;
845 IXMLDOMAttribute *attr = NULL;
846 DOMNodeType type = NODE_INVALID;
847 VARIANT_BOOL b;
848 BSTR str;
849 VARIANT var;
850 long count;
852 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
853 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
854 if( r != S_OK )
855 return;
857 b = FALSE;
858 str = SysAllocString( szComplete4 );
859 r = IXMLDOMDocument_loadXML( doc, str, &b );
860 ok( r == S_OK, "loadXML failed\n");
861 ok( b == VARIANT_TRUE, "failed to load XML string\n");
862 SysFreeString( str );
864 if (doc)
866 b = 1;
867 r = IXMLDOMNode_hasChildNodes( doc, &b );
868 ok( r == S_OK, "hasChildNoes bad return\n");
869 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
871 r = IXMLDOMDocument_get_documentElement( doc, &element );
872 ok( r == S_OK, "should be a document element\n");
873 ok( element != NULL, "should be an element\n");
875 else
876 ok( FALSE, "no document\n");
878 VariantInit(&var);
879 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
881 r = IXMLDOMNode_get_nodeValue( doc, NULL );
882 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
884 r = IXMLDOMNode_get_nodeValue( doc, &var );
885 ok( r == S_FALSE, "nextNode returned wrong code\n");
886 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
887 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
889 if (element)
891 owner = NULL;
892 r = IXMLDOMNode_get_ownerDocument( element, &owner );
893 ok( r == S_OK, "get_ownerDocument return code\n");
894 ok( owner != doc, "get_ownerDocument return\n");
896 type = NODE_INVALID;
897 r = IXMLDOMNode_get_nodeType( element, &type);
898 ok( r == S_OK, "getNamedItem returned wrong code\n");
899 ok( type == NODE_ELEMENT, "node not an element\n");
901 str = NULL;
902 r = IXMLDOMNode_get_baseName( element, &str );
903 ok( r == S_OK, "get_baseName returned wrong code\n");
904 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
905 SysFreeString(str);
907 /* check if nodename is correct */
908 r = IXMLDOMElement_get_nodeName( element, NULL );
909 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
911 /* content doesn't matter here */
912 str = NULL;
913 r = IXMLDOMElement_get_nodeName( element, &str );
914 ok ( r == S_OK, "get_nodeName wrong code\n");
915 ok ( str != NULL, "str is null\n");
916 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
917 SysFreeString( str );
919 str = SysAllocString( szNonExistentFile );
920 V_VT(&var) = VT_I4;
921 V_I4(&var) = 0x1234;
922 r = IXMLDOMElement_getAttribute( element, str, &var );
923 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
924 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
925 VariantClear(&var);
927 attr = (IXMLDOMAttribute*)0xdeadbeef;
928 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
929 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
930 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
931 SysFreeString( str );
933 str = SysAllocString( szdl );
934 V_VT(&var) = VT_I4;
935 V_I4(&var) = 0x1234;
936 r = IXMLDOMElement_getAttribute( element, str, &var );
937 ok( r == S_OK, "getAttribute ret %08x\n", r );
938 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
939 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
940 VariantClear( &var );
942 r = IXMLDOMElement_getAttribute( element, NULL, &var );
943 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
945 r = IXMLDOMElement_getAttribute( element, str, NULL );
946 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
948 attr = NULL;
949 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
950 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
951 ok( attr != NULL, "getAttributeNode returned NULL\n" );
952 if(attr)
953 IXMLDOMAttribute_Release(attr);
955 SysFreeString( str );
957 r = IXMLDOMElement_get_attributes( element, &map );
958 ok( r == S_OK, "get_attributes returned wrong code\n");
959 ok( map != NULL, "should be attributes\n");
961 b = 1;
962 r = IXMLDOMNode_hasChildNodes( element, &b );
963 ok( r == S_OK, "hasChildNoes bad return\n");
964 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
966 else
967 ok( FALSE, "no element\n");
969 if (map)
971 ISupportErrorInfo *support_error;
972 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
973 ok( r == S_OK, "ret %08x\n", r );
975 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
976 todo_wine
978 ok( r == S_OK, "ret %08x\n", r );
980 ISupportErrorInfo_Release( support_error );
982 str = SysAllocString( szdl );
983 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
984 ok( r == S_OK, "getNamedItem returned wrong code\n");
985 ok( node != NULL, "should be attributes\n");
986 IXMLDOMNode_Release(node);
987 SysFreeString( str );
989 str = SysAllocString( szdl );
990 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
991 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
992 SysFreeString( str );
994 /* something that isn't in szComplete4 */
995 str = SysAllocString( szOpen );
996 node = (IXMLDOMNode *) 1;
997 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
998 ok( r = S_FALSE, "getNamedItem found a node that wasn't there\n");
999 ok( node == NULL, "getNamedItem should have returned NULL\n");
1000 SysFreeString( str );
1002 /* test indexed access of attributes */
1003 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1004 ok ( r == S_OK, "get_length wrong code\n");
1005 ok ( count == 1, "get_length != 1\n");
1007 node = NULL;
1008 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1009 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1010 ok ( node == NULL, "there is no node\n");
1012 node = NULL;
1013 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1014 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1015 ok ( node == NULL, "there is no attribute\n");
1017 node = NULL;
1018 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1019 ok ( r == S_OK, "get_item (0) wrong code\n");
1020 ok ( node != NULL, "should be attribute\n");
1022 r = IXMLDOMNode_get_nodeName( node, NULL );
1023 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1025 /* content doesn't matter here */
1026 str = NULL;
1027 r = IXMLDOMNode_get_nodeName( node, &str );
1028 ok ( r == S_OK, "get_nodeName wrong code\n");
1029 ok ( str != NULL, "str is null\n");
1030 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1031 SysFreeString( str );
1033 /* test sequential access of attributes */
1034 node = NULL;
1035 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1036 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1037 ok ( node != NULL, "nextNode, should be attribute\n");
1039 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1040 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1041 ok ( node == NULL, "nextNode, there is no attribute\n");
1043 r = IXMLDOMNamedNodeMap_reset( map );
1044 ok ( r == S_OK, "reset should return S_OK\n");
1046 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1047 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1048 ok ( node != NULL, "nextNode, should be attribute\n");
1050 else
1051 ok( FALSE, "no map\n");
1053 if (node)
1055 type = NODE_INVALID;
1056 r = IXMLDOMNode_get_nodeType( node, &type);
1057 ok( r == S_OK, "getNamedItem returned wrong code\n");
1058 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1060 str = NULL;
1061 r = IXMLDOMNode_get_baseName( node, NULL );
1062 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1064 str = NULL;
1065 r = IXMLDOMNode_get_baseName( node, &str );
1066 ok( r == S_OK, "get_baseName returned wrong code\n");
1067 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1068 SysFreeString( str );
1070 r = IXMLDOMNode_get_nodeValue( node, &var );
1071 ok( r == S_OK, "returns %08x\n", r );
1072 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1073 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1074 VariantClear(&var);
1076 r = IXMLDOMNode_get_childNodes( node, NULL );
1077 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1079 r = IXMLDOMNode_get_childNodes( node, &list );
1080 ok( r == S_OK, "get_childNodes returned wrong code\n");
1082 if (list)
1084 r = IXMLDOMNodeList_nextNode( list, &next );
1085 ok( r == S_OK, "nextNode returned wrong code\n");
1087 else
1088 ok( FALSE, "no childlist\n");
1090 if (next)
1092 b = 1;
1093 r = IXMLDOMNode_hasChildNodes( next, &b );
1094 ok( r == S_FALSE, "hasChildNoes bad return\n");
1095 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1097 type = NODE_INVALID;
1098 r = IXMLDOMNode_get_nodeType( next, &type);
1099 ok( r == S_OK, "getNamedItem returned wrong code\n");
1100 ok( type == NODE_TEXT, "node not text\n");
1102 str = (BSTR) 1;
1103 r = IXMLDOMNode_get_baseName( next, &str );
1104 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1105 ok( str == NULL, "basename was wrong\n");
1106 SysFreeString(str);
1108 else
1109 ok( FALSE, "no next\n");
1111 if (next)
1112 IXMLDOMNode_Release( next );
1113 next = NULL;
1114 if (list)
1115 IXMLDOMNodeList_Release( list );
1116 list = NULL;
1117 if (node)
1118 IXMLDOMNode_Release( node );
1120 else
1121 ok( FALSE, "no node\n");
1122 node = NULL;
1124 if (map)
1125 IXMLDOMNamedNodeMap_Release( map );
1127 /* now traverse the tree from the root element */
1128 if (element)
1130 IXMLDOMNode *node;
1131 r = IXMLDOMNode_get_childNodes( element, &list );
1132 ok( r == S_OK, "get_childNodes returned wrong code\n");
1134 /* using get_item for child list doesn't advance the position */
1135 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1136 expect_node(node, "E2.E2.D1");
1137 IXMLDOMNode_Release(node);
1138 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1139 expect_node(node, "E1.E2.D1");
1140 IXMLDOMNode_Release(node);
1141 ole_check(IXMLDOMNodeList_reset(list));
1143 IXMLDOMNodeList_AddRef(list);
1144 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1145 ole_check(IXMLDOMNodeList_reset(list));
1147 else
1148 ok( FALSE, "no element\n");
1150 node = (void*)0xdeadbeef;
1151 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1152 ok( r == S_FALSE, "ret %08x\n", r );
1153 ok( node == NULL, "node %p\n", node );
1154 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1155 ok( r == S_OK, "ret %08x\n", r );
1156 r = IXMLDOMNode_Release( node );
1157 ok( r == 0, "ret %08x\n", r );
1159 if (list)
1161 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1162 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1164 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1165 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1167 r = IXMLDOMNodeList_get_length(list, NULL);
1168 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1170 r = IXMLDOMNodeList_get_length( list, &count );
1171 ok( r == S_OK, "get_length returns %08x\n", r );
1172 ok( count == 4, "get_length got %ld\n", count );
1174 r = IXMLDOMNodeList_nextNode(list, NULL);
1175 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1177 r = IXMLDOMNodeList_nextNode( list, &node );
1178 ok( r == S_OK, "nextNode returned wrong code\n");
1180 else
1181 ok( FALSE, "no list\n");
1183 if (node)
1185 type = NODE_INVALID;
1186 r = IXMLDOMNode_get_nodeType( node, &type);
1187 ok( r == S_OK, "getNamedItem returned wrong code\n");
1188 ok( type == NODE_ELEMENT, "node not text\n");
1190 VariantInit(&var);
1191 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1192 r = IXMLDOMNode_get_nodeValue( node, &var );
1193 ok( r == S_FALSE, "nextNode returned wrong code\n");
1194 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1195 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1197 r = IXMLDOMNode_hasChildNodes( node, NULL );
1198 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1200 b = 1;
1201 r = IXMLDOMNode_hasChildNodes( node, &b );
1202 ok( r == S_OK, "hasChildNoes bad return\n");
1203 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1205 str = NULL;
1206 r = IXMLDOMNode_get_baseName( node, &str );
1207 ok( r == S_OK, "get_baseName returned wrong code\n");
1208 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1209 SysFreeString(str);
1211 else
1212 ok( FALSE, "no node\n");
1214 if (node)
1215 IXMLDOMNode_Release( node );
1216 if (list)
1217 IXMLDOMNodeList_Release( list );
1218 if (element)
1219 IXMLDOMElement_Release( element );
1221 b = FALSE;
1222 str = SysAllocString( szComplete5 );
1223 r = IXMLDOMDocument_loadXML( doc, str, &b );
1224 ok( r == S_OK, "loadXML failed\n");
1225 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1226 SysFreeString( str );
1228 b = 1;
1229 r = IXMLDOMNode_hasChildNodes( doc, &b );
1230 ok( r == S_OK, "hasChildNoes bad return\n");
1231 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1233 r = IXMLDOMDocument_get_documentElement( doc, &element );
1234 ok( r == S_OK, "should be a document element\n");
1235 ok( element != NULL, "should be an element\n");
1237 if (element)
1239 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1240 BSTR tag = NULL;
1242 /* check if the tag is correct */
1243 r = IXMLDOMElement_get_tagName( element, &tag );
1244 ok( r == S_OK, "couldn't get tag name\n");
1245 ok( tag != NULL, "tag was null\n");
1246 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1247 SysFreeString( tag );
1250 if (element)
1251 IXMLDOMElement_Release( element );
1252 if (doc)
1253 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1256 static void test_refs(void)
1258 HRESULT r;
1259 BSTR str;
1260 VARIANT_BOOL b;
1261 IXMLDOMDocument *doc = NULL;
1262 IXMLDOMElement *element = NULL;
1263 IXMLDOMNode *node = NULL, *node2;
1264 IXMLDOMNodeList *node_list = NULL;
1265 LONG ref;
1266 IUnknown *unk, *unk2;
1268 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1269 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1270 if( r != S_OK )
1271 return;
1272 ref = IXMLDOMDocument_Release(doc);
1273 ok( ref == 0, "ref %d\n", ref);
1275 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1276 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1277 if( r != S_OK )
1278 return;
1280 str = SysAllocString( szComplete4 );
1281 r = IXMLDOMDocument_loadXML( doc, str, &b );
1282 ok( r == S_OK, "loadXML failed\n");
1283 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1284 SysFreeString( str );
1286 ref = IXMLDOMDocument_AddRef( doc );
1287 ok( ref == 2, "ref %d\n", ref );
1288 ref = IXMLDOMDocument_AddRef( doc );
1289 ok( ref == 3, "ref %d\n", ref );
1290 IXMLDOMDocument_Release( doc );
1291 IXMLDOMDocument_Release( doc );
1293 r = IXMLDOMDocument_get_documentElement( doc, &element );
1294 ok( r == S_OK, "should be a document element\n");
1295 ok( element != NULL, "should be an element\n");
1297 ref = IXMLDOMDocument_AddRef( doc );
1298 ok( ref == 2, "ref %d\n", ref );
1299 IXMLDOMDocument_Release( doc );
1301 r = IXMLDOMElement_get_childNodes( element, &node_list );
1302 ok( r == S_OK, "rets %08x\n", r);
1304 ref = IXMLDOMNodeList_AddRef( node_list );
1305 ok( ref == 2, "ref %d\n", ref );
1306 IXMLDOMNodeList_Release( node_list );
1308 IXMLDOMNodeList_get_item( node_list, 0, &node );
1309 ok( r == S_OK, "rets %08x\n", r);
1311 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1312 ok( r == S_OK, "rets %08x\n", r);
1314 ref = IXMLDOMNode_AddRef( node );
1315 ok( ref == 2, "ref %d\n", ref );
1316 IXMLDOMNode_Release( node );
1318 ref = IXMLDOMNode_Release( node );
1319 ok( ref == 0, "ref %d\n", ref );
1320 ref = IXMLDOMNode_Release( node2 );
1321 ok( ref == 0, "ref %d\n", ref );
1323 ref = IXMLDOMNodeList_Release( node_list );
1324 ok( ref == 0, "ref %d\n", ref );
1326 ok( node != node2, "node %p node2 %p\n", node, node2 );
1328 ref = IXMLDOMDocument_Release( doc );
1329 ok( ref == 0, "ref %d\n", ref );
1331 ref = IXMLDOMElement_AddRef( element );
1332 todo_wine {
1333 ok( ref == 3, "ref %d\n", ref );
1335 IXMLDOMElement_Release( element );
1337 /* IUnknown must be unique however we obtain it */
1338 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1339 ok( r == S_OK, "rets %08x\n", r );
1340 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1341 ok( r == S_OK, "rets %08x\n", r );
1342 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1343 ok( r == S_OK, "rets %08x\n", r );
1344 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1346 IUnknown_Release( unk2 );
1347 IUnknown_Release( unk );
1348 IXMLDOMNode_Release( node );
1350 IXMLDOMElement_Release( element );
1354 static void test_create(void)
1356 HRESULT r;
1357 VARIANT var;
1358 BSTR str, name;
1359 IXMLDOMDocument *doc;
1360 IXMLDOMElement *element;
1361 IXMLDOMNode *root, *node, *child;
1362 IXMLDOMNamedNodeMap *attr_map;
1363 IUnknown *unk;
1364 LONG ref;
1365 long num;
1367 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1368 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1369 if( r != S_OK )
1370 return;
1372 V_VT(&var) = VT_I4;
1373 V_I4(&var) = NODE_ELEMENT;
1374 str = SysAllocString( szlc );
1375 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1376 ok( r == S_OK, "returns %08x\n", r );
1377 r = IXMLDOMDocument_appendChild( doc, node, &root );
1378 ok( r == S_OK, "returns %08x\n", r );
1379 ok( node == root, "%p %p\n", node, root );
1381 ref = IXMLDOMNode_AddRef( node );
1382 ok(ref == 3, "ref %d\n", ref);
1383 IXMLDOMNode_Release( node );
1385 ref = IXMLDOMNode_Release( node );
1386 ok(ref == 1, "ref %d\n", ref);
1387 SysFreeString( str );
1389 V_VT(&var) = VT_I4;
1390 V_I4(&var) = NODE_ELEMENT;
1391 str = SysAllocString( szbs );
1392 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1393 ok( r == S_OK, "returns %08x\n", r );
1395 ref = IXMLDOMNode_AddRef( node );
1396 ok(ref == 2, "ref = %d\n", ref);
1397 IXMLDOMNode_Release( node );
1399 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1400 ok( r == S_OK, "returns %08x\n", r );
1402 ref = IXMLDOMNode_AddRef( unk );
1403 ok(ref == 3, "ref = %d\n", ref);
1404 IXMLDOMNode_Release( unk );
1406 V_VT(&var) = VT_EMPTY;
1407 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1408 ok( r == S_OK, "returns %08x\n", r );
1409 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1410 IXMLDOMNode_Release( child );
1411 IUnknown_Release( unk );
1414 V_VT(&var) = VT_NULL;
1415 V_DISPATCH(&var) = (IDispatch*)node;
1416 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1417 ok( r == S_OK, "returns %08x\n", r );
1418 ok( node == child, "%p %p\n", node, child );
1419 IXMLDOMNode_Release( child );
1422 V_VT(&var) = VT_NULL;
1423 V_DISPATCH(&var) = (IDispatch*)node;
1424 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1425 ok( r == S_OK, "returns %08x\n", r );
1426 IXMLDOMNode_Release( node );
1428 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1429 ok( r == S_OK, "returns %08x\n", r );
1431 r = IXMLDOMElement_get_attributes( element, &attr_map );
1432 ok( r == S_OK, "returns %08x\n", r );
1433 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1434 ok( r == S_OK, "returns %08x\n", r );
1435 ok( num == 0, "num %ld\n", num );
1436 IXMLDOMNamedNodeMap_Release( attr_map );
1438 V_VT(&var) = VT_BSTR;
1439 V_BSTR(&var) = SysAllocString( szstr1 );
1440 name = SysAllocString( szdl );
1441 r = IXMLDOMElement_setAttribute( element, name, var );
1442 ok( r == S_OK, "returns %08x\n", r );
1443 r = IXMLDOMElement_get_attributes( element, &attr_map );
1444 ok( r == S_OK, "returns %08x\n", r );
1445 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1446 ok( r == S_OK, "returns %08x\n", r );
1447 ok( num == 1, "num %ld\n", num );
1448 IXMLDOMNamedNodeMap_Release( attr_map );
1449 VariantClear(&var);
1451 V_VT(&var) = VT_BSTR;
1452 V_BSTR(&var) = SysAllocString( szstr2 );
1453 r = IXMLDOMElement_setAttribute( element, name, var );
1454 ok( r == S_OK, "returns %08x\n", r );
1455 r = IXMLDOMElement_get_attributes( element, &attr_map );
1456 ok( r == S_OK, "returns %08x\n", r );
1457 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1458 ok( r == S_OK, "returns %08x\n", r );
1459 ok( num == 1, "num %ld\n", num );
1460 IXMLDOMNamedNodeMap_Release( attr_map );
1461 VariantClear(&var);
1462 r = IXMLDOMElement_getAttribute( element, name, &var );
1463 ok( r == S_OK, "returns %08x\n", r );
1464 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1465 VariantClear(&var);
1466 SysFreeString(name);
1468 V_VT(&var) = VT_BSTR;
1469 V_BSTR(&var) = SysAllocString( szstr1 );
1470 name = SysAllocString( szlc );
1471 r = IXMLDOMElement_setAttribute( element, name, var );
1472 ok( r == S_OK, "returns %08x\n", r );
1473 r = IXMLDOMElement_get_attributes( element, &attr_map );
1474 ok( r == S_OK, "returns %08x\n", r );
1475 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1476 ok( r == S_OK, "returns %08x\n", r );
1477 ok( num == 2, "num %ld\n", num );
1478 IXMLDOMNamedNodeMap_Release( attr_map );
1479 VariantClear(&var);
1480 SysFreeString(name);
1482 V_VT(&var) = VT_I4;
1483 V_I4(&var) = 10;
1484 name = SysAllocString( szbs );
1485 r = IXMLDOMElement_setAttribute( element, name, var );
1486 ok( r == S_OK, "returns %08x\n", r );
1487 VariantClear(&var);
1488 r = IXMLDOMElement_getAttribute( element, name, &var );
1489 ok( r == S_OK, "returns %08x\n", r );
1490 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1491 VariantClear(&var);
1492 SysFreeString(name);
1494 /* Create an Attribute */
1495 V_VT(&var) = VT_I4;
1496 V_I4(&var) = NODE_ATTRIBUTE;
1497 str = SysAllocString( szAttribute );
1498 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1499 ok( r == S_OK, "returns %08x\n", r );
1500 ok( node != NULL, "node was null\n");
1501 SysFreeString(str);
1503 if(r == S_OK)
1505 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1506 ok( r == S_OK, "returns %08x\n", r );
1507 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1508 SysFreeString(str);
1509 IXMLDOMNode_Release( node );
1512 IXMLDOMElement_Release( element );
1513 IXMLDOMNode_Release( root );
1514 IXMLDOMDocument_Release( doc );
1517 static void test_getElementsByTagName(void)
1519 HRESULT r;
1520 BSTR str;
1521 VARIANT_BOOL b;
1522 IXMLDOMDocument *doc;
1523 IXMLDOMNodeList *node_list;
1524 IDispatchEx *dispex;
1525 long len;
1527 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1528 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1529 if( r != S_OK )
1530 return;
1532 str = SysAllocString( szComplete4 );
1533 r = IXMLDOMDocument_loadXML( doc, str, &b );
1534 ok( r == S_OK, "loadXML failed\n");
1535 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1536 SysFreeString( str );
1538 str = SysAllocString( szstar );
1539 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1540 ok( r == S_OK, "ret %08x\n", r );
1541 r = IXMLDOMNodeList_get_length( node_list, &len );
1542 ok( r == S_OK, "ret %08x\n", r );
1543 ok( len == 6, "len %ld\n", len );
1545 r = IXMLDOMNodeList_QueryInterface( node_list, &IID_IDispatchEx, (void**)&dispex );
1546 ok( r == S_OK, "rets %08x\n", r);
1547 if( r == S_OK )
1549 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
1550 DWORD dwProps = 0;
1551 BSTR sName;
1552 IUnknown *pUnk;
1554 sName = SysAllocString( szstar );
1555 r = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
1556 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1557 SysFreeString( sName );
1559 r = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
1560 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1562 r = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
1563 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1564 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
1566 r = IDispatchEx_GetMemberName(dispex, dispid, &sName);
1567 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1568 SysFreeString(sName);
1570 r = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
1571 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1573 r = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
1574 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1575 if(r == S_OK)
1576 IUnknown_Release(pUnk);
1578 IDispatchEx_Release( dispex );
1582 IXMLDOMNodeList_Release( node_list );
1583 SysFreeString( str );
1585 str = SysAllocString( szbs );
1586 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1587 ok( r == S_OK, "ret %08x\n", r );
1588 r = IXMLDOMNodeList_get_length( node_list, &len );
1589 ok( r == S_OK, "ret %08x\n", r );
1590 ok( len == 1, "len %ld\n", len );
1591 IXMLDOMNodeList_Release( node_list );
1592 SysFreeString( str );
1594 str = SysAllocString( szdl );
1595 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1596 ok( r == S_OK, "ret %08x\n", r );
1597 r = IXMLDOMNodeList_get_length( node_list, &len );
1598 ok( r == S_OK, "ret %08x\n", r );
1599 ok( len == 0, "len %ld\n", len );
1600 IXMLDOMNodeList_Release( node_list );
1601 SysFreeString( str );
1603 str = SysAllocString( szstr1 );
1604 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1605 ok( r == S_OK, "ret %08x\n", r );
1606 r = IXMLDOMNodeList_get_length( node_list, &len );
1607 ok( r == S_OK, "ret %08x\n", r );
1608 ok( len == 0, "len %ld\n", len );
1609 IXMLDOMNodeList_Release( node_list );
1610 SysFreeString( str );
1612 IXMLDOMDocument_Release( doc );
1615 static void test_get_text(void)
1617 HRESULT r;
1618 BSTR str;
1619 VARIANT_BOOL b;
1620 IXMLDOMDocument *doc;
1621 IXMLDOMNode *node, *node2, *node3;
1622 IXMLDOMNodeList *node_list;
1623 IXMLDOMNamedNodeMap *node_map;
1624 long len;
1626 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1627 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1628 if( r != S_OK )
1629 return;
1631 str = SysAllocString( szComplete4 );
1632 r = IXMLDOMDocument_loadXML( doc, str, &b );
1633 ok( r == S_OK, "loadXML failed\n");
1634 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1635 SysFreeString( str );
1637 str = SysAllocString( szbs );
1638 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1639 ok( r == S_OK, "ret %08x\n", r );
1640 SysFreeString(str);
1642 if (0) {
1643 /* this test crashes on win9x */
1644 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1645 ok( r == E_INVALIDARG, "ret %08x\n", r );
1648 r = IXMLDOMNodeList_get_length( node_list, NULL );
1649 ok( r == E_INVALIDARG, "ret %08x\n", r );
1651 r = IXMLDOMNodeList_get_length( node_list, &len );
1652 ok( r == S_OK, "ret %08x\n", r );
1653 ok( len == 1, "expect 1 got %ld\n", len );
1655 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1656 ok( r == E_INVALIDARG, "ret %08x\n", r );
1658 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1659 ok( r == E_INVALIDARG, "ret %08x\n", r );
1661 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1662 ok( r == S_OK, "ret %08x\n", r );
1663 IXMLDOMNodeList_Release( node_list );
1665 /* Invalid output parameter*/
1666 r = IXMLDOMNode_get_text( node, NULL );
1667 ok( r == E_INVALIDARG, "ret %08x\n", r );
1669 r = IXMLDOMNode_get_text( node, &str );
1670 ok( r == S_OK, "ret %08x\n", r );
1671 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1672 SysFreeString(str);
1674 r = IXMLDOMNode_get_attributes( node, &node_map );
1675 ok( r == S_OK, "ret %08x\n", r );
1677 str = SysAllocString( szvr );
1678 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1679 ok( r == S_OK, "ret %08x\n", r );
1680 SysFreeString(str);
1682 r = IXMLDOMNode_get_text( node2, &str );
1683 ok( r == S_OK, "ret %08x\n", r );
1684 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1685 SysFreeString(str);
1687 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1688 ok( r == S_OK, "ret %08x\n", r );
1690 r = IXMLDOMNode_get_text( node3, &str );
1691 ok( r == S_OK, "ret %08x\n", r );
1692 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1693 SysFreeString(str);
1696 IXMLDOMNode_Release( node3 );
1697 IXMLDOMNode_Release( node2 );
1698 IXMLDOMNamedNodeMap_Release( node_map );
1699 IXMLDOMNode_Release( node );
1700 IXMLDOMDocument_Release( doc );
1703 static void test_get_childNodes(void)
1705 HRESULT r;
1706 BSTR str;
1707 VARIANT_BOOL b;
1708 IXMLDOMDocument *doc;
1709 IXMLDOMElement *element;
1710 IXMLDOMNode *node, *node2;
1711 IXMLDOMNodeList *node_list, *node_list2;
1712 long len;
1714 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1715 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1716 if( r != S_OK )
1717 return;
1719 str = SysAllocString( szComplete4 );
1720 r = IXMLDOMDocument_loadXML( doc, str, &b );
1721 ok( r == S_OK, "loadXML failed\n");
1722 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1723 SysFreeString( str );
1725 r = IXMLDOMDocument_get_documentElement( doc, &element );
1726 ok( r == S_OK, "ret %08x\n", r);
1728 r = IXMLDOMElement_get_childNodes( element, &node_list );
1729 ok( r == S_OK, "ret %08x\n", r);
1731 r = IXMLDOMNodeList_get_length( node_list, &len );
1732 ok( r == S_OK, "ret %08x\n", r);
1733 ok( len == 4, "len %ld\n", len);
1735 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1736 ok( r == S_OK, "ret %08x\n", r);
1738 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1739 ok( r == S_OK, "ret %08x\n", r);
1741 r = IXMLDOMNodeList_get_length( node_list2, &len );
1742 ok( r == S_OK, "ret %08x\n", r);
1743 ok( len == 0, "len %ld\n", len);
1745 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1746 ok( r == S_FALSE, "ret %08x\n", r);
1748 IXMLDOMNodeList_Release( node_list2 );
1749 IXMLDOMNode_Release( node );
1750 IXMLDOMNodeList_Release( node_list );
1751 IXMLDOMElement_Release( element );
1752 IXMLDOMDocument_Release( doc );
1755 static void test_removeChild(void)
1757 HRESULT r;
1758 BSTR str;
1759 VARIANT_BOOL b;
1760 IXMLDOMDocument *doc;
1761 IXMLDOMElement *element;
1762 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
1763 IXMLDOMNodeList *root_list, *fo_list;
1765 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1766 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1767 if( r != S_OK )
1768 return;
1770 str = SysAllocString( szComplete4 );
1771 r = IXMLDOMDocument_loadXML( doc, str, &b );
1772 ok( r == S_OK, "loadXML failed\n");
1773 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1774 SysFreeString( str );
1776 r = IXMLDOMDocument_get_documentElement( doc, &element );
1777 ok( r == S_OK, "ret %08x\n", r);
1779 r = IXMLDOMElement_get_childNodes( element, &root_list );
1780 ok( r == S_OK, "ret %08x\n", r);
1782 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1783 ok( r == S_OK, "ret %08x\n", r);
1785 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1786 ok( r == S_OK, "ret %08x\n", r);
1788 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1789 ok( r == S_OK, "ret %08x\n", r);
1791 /* invalid parameter: NULL ptr */
1792 removed_node = (void*)0xdeadbeef;
1793 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
1794 ok( r == E_INVALIDARG, "ret %08x\n", r );
1795 todo_wine ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1797 /* ba_node is a descendant of element, but not a direct child. */
1798 removed_node = (void*)0xdeadbeef;
1799 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
1800 todo_wine ok( r == E_INVALIDARG, "ret %08x\n", r );
1801 todo_wine ok( removed_node == NULL, "%p\n", removed_node );
1803 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
1804 ok( r == S_OK, "ret %08x\n", r);
1805 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
1807 /* try removing already removed child */
1808 temp_node = (void*)0xdeadbeef;
1809 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
1810 ok( r == E_INVALIDARG, "ret %08x\n", r);
1811 ok( temp_node == NULL, "%p\n", temp_node );
1813 /* the removed node has no parent anymore */
1814 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
1815 ok( r == S_FALSE, "ret %08x\n", r);
1816 ok( temp_node == NULL, "%p\n", temp_node );
1818 IXMLDOMNode_Release( removed_node );
1819 IXMLDOMNode_Release( ba_node );
1820 IXMLDOMNodeList_Release( fo_list );
1822 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
1823 ok( r == S_OK, "ret %08x\n", r);
1825 r = IXMLDOMElement_removeChild( element, lc_node, NULL );
1826 ok( r == S_OK, "ret %08x\n", r);
1828 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
1829 ok( r == S_FALSE, "ret %08x\n", r);
1830 ok( temp_node == NULL, "%p\n", temp_node );
1832 IXMLDOMNode_Release( lc_node );
1833 IXMLDOMNodeList_Release( root_list );
1834 IXMLDOMElement_Release( element );
1835 IXMLDOMDocument_Release( doc );
1838 static void test_XMLHTTP(void)
1840 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1841 static WCHAR wszPOST[] = {'P','O','S','T',0};
1842 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1843 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1844 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1845 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1846 IXMLHttpRequest *pXMLHttpRequest;
1847 BSTR bstrResponse;
1848 VARIANT dummy;
1849 VARIANT varfalse;
1850 VARIANT varbody;
1851 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1852 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1853 (void **)&pXMLHttpRequest);
1854 todo_wine {
1855 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1857 if (hr != S_OK)
1858 return;
1860 VariantInit(&dummy);
1861 V_VT(&dummy) = VT_ERROR;
1862 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1863 VariantInit(&varfalse);
1864 V_VT(&varfalse) = VT_BOOL;
1865 V_BOOL(&varfalse) = VARIANT_FALSE;
1866 V_VT(&varbody) = VT_BSTR;
1867 V_BSTR(&varbody) = SysAllocString(wszBody);
1869 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1870 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1872 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1873 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1874 VariantClear(&varbody);
1876 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1877 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1878 /* the server currently returns "FAILED" because the Content-Type header is
1879 * not what the server expects */
1880 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1881 SysFreeString(bstrResponse);
1884 static void test_IXMLDOMDocument2(void)
1886 HRESULT r;
1887 VARIANT_BOOL b;
1888 BSTR str;
1889 IXMLDOMDocument *doc;
1890 IXMLDOMDocument2 *doc2;
1891 IDispatchEx *dispex;
1892 VARIANT var;
1893 int ref;
1895 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1896 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1897 if( r != S_OK )
1898 return;
1900 str = SysAllocString( szComplete4 );
1901 r = IXMLDOMDocument_loadXML( doc, str, &b );
1902 ok( r == S_OK, "loadXML failed\n");
1903 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1904 SysFreeString( str );
1906 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1907 ok( r == S_OK, "ret %08x\n", r );
1908 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1910 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
1911 ok( r == S_OK, "ret %08x\n", r );
1912 if(r == S_OK)
1914 IDispatchEx_Release(dispex);
1917 /* we will check if the variant got cleared */
1918 ref = IXMLDOMDocument2_AddRef(doc2);
1919 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1920 V_VT(&var) = VT_UNKNOWN;
1921 V_UNKNOWN(&var) = (IUnknown *)doc2;
1923 /* invalid calls */
1924 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1925 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1926 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1928 /* valid call */
1929 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1930 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1931 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1932 V_VT(&var) = VT_R4;
1934 /* the variant didn't get cleared*/
1935 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1937 /* setProperty tests */
1938 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1939 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1940 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1941 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1942 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1943 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1945 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
1946 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1947 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1948 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1950 IXMLDOMDocument2_Release( doc2 );
1951 IXMLDOMDocument_Release( doc );
1952 free_bstrs();
1955 static void test_XPath(void)
1957 HRESULT r;
1958 VARIANT var;
1959 VARIANT_BOOL b;
1960 IXMLDOMDocument2 *doc;
1961 IXMLDOMNode *rootNode;
1962 IXMLDOMNode *elem1Node;
1963 IXMLDOMNode *node;
1964 IXMLDOMNodeList *list;
1966 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1967 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1968 if( r != S_OK )
1969 return;
1971 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1972 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1974 /* switch to XPath */
1975 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1977 /* some simple queries*/
1978 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1979 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1980 ole_check(IXMLDOMNodeList_reset(list));
1981 expect_list_and_release(list, "E2.D1");
1982 if (rootNode == NULL)
1983 return;
1985 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1986 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1988 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1989 expect_list_and_release(list, "E3.E2.E2.D1");
1991 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1992 /* using get_item for query results advances the position */
1993 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1994 expect_node(node, "E2.E2.D1");
1995 IXMLDOMNode_Release(node);
1996 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1997 expect_node(node, "E4.E2.D1");
1998 IXMLDOMNode_Release(node);
1999 ole_check(IXMLDOMNodeList_reset(list));
2000 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2002 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2003 expect_list_and_release(list, "E2.D1");
2005 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2006 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2007 ole_check(IXMLDOMNodeList_reset(list));
2008 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2010 /* select an attribute */
2011 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2012 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2014 /* would evaluate to a number */
2015 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2016 /* would evaluate to a boolean */
2017 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2018 /* would evaluate to a string */
2019 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2021 /* no results */
2022 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2023 expect_list_and_release(list, "");
2024 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2025 expect_list_and_release(list, "");
2026 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2027 expect_list_and_release(list, "");
2029 /* foo undeclared in document node */
2030 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2031 /* undeclared in <root> node */
2032 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2033 /* undeclared in <elem> node */
2034 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2035 /* but this trick can be used */
2036 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2037 expect_list_and_release(list, "E3.E4.E2.D1");
2039 /* it has to be declared in SelectionNamespaces */
2040 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2041 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2043 /* now the namespace can be used */
2044 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2045 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2046 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2047 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2048 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2049 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2050 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2051 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2053 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2054 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2055 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2057 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2059 VariantInit(&var);
2060 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2061 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2062 if (V_VT(&var) == VT_BSTR)
2063 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2065 /* extra attributes - same thing*/
2066 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2067 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2068 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2070 IXMLDOMNode_Release(rootNode);
2071 IXMLDOMNode_Release(elem1Node);
2072 IXMLDOMDocument_Release(doc);
2073 free_bstrs();
2076 static void test_cloneNode(void )
2078 IXMLDOMDocument *doc = NULL;
2079 VARIANT_BOOL b;
2080 IXMLDOMNodeList *pList;
2081 IXMLDOMNamedNodeMap *mapAttr;
2082 long nLength = 0, nLength1 = 0;
2083 long nAttrCnt = 0, nAttrCnt1 = 0;
2084 IXMLDOMNode *node;
2085 IXMLDOMNode *node_clone;
2086 HRESULT r;
2087 BSTR str;
2088 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2090 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2091 if( r != S_OK )
2092 return;
2094 str = SysAllocString( szComplete4 );
2095 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2096 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2097 SysFreeString(str);
2099 if(!b)
2100 return;
2102 str = SysAllocString( szSearch);
2103 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2104 ok( r == S_OK, "ret %08x\n", r );
2105 ok( node != NULL, "node %p\n", node );
2106 SysFreeString(str);
2108 if(!node)
2110 IXMLDOMDocument_Release(doc);
2111 return;
2114 /* Check invalid parameter */
2115 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2116 ok( r == E_INVALIDARG, "ret %08x\n", r );
2118 /* All Children */
2119 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2120 ok( r == S_OK, "ret %08x\n", r );
2121 ok( node_clone != NULL, "node %p\n", node );
2123 if(!node_clone)
2125 IXMLDOMDocument_Release(doc);
2126 IXMLDOMNode_Release(node);
2127 return;
2130 r = IXMLDOMNode_get_childNodes(node, &pList);
2131 ok( r == S_OK, "ret %08x\n", r );
2132 if (pList)
2134 IXMLDOMNodeList_get_length(pList, &nLength);
2135 IXMLDOMNodeList_Release(pList);
2138 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2139 ok( r == S_OK, "ret %08x\n", r );
2140 if(mapAttr)
2142 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2143 IXMLDOMNamedNodeMap_Release(mapAttr);
2146 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2147 ok( r == S_OK, "ret %08x\n", r );
2148 if (pList)
2150 IXMLDOMNodeList_get_length(pList, &nLength1);
2151 IXMLDOMNodeList_Release(pList);
2154 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2155 ok( r == S_OK, "ret %08x\n", r );
2156 if(mapAttr)
2158 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2159 IXMLDOMNamedNodeMap_Release(mapAttr);
2162 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2163 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2164 IXMLDOMNode_Release(node_clone);
2166 /* No Children */
2167 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2168 ok( r == S_OK, "ret %08x\n", r );
2169 ok( node_clone != NULL, "node %p\n", node );
2171 if(!node_clone)
2173 IXMLDOMDocument_Release(doc);
2174 IXMLDOMNode_Release(node);
2175 return;
2178 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2179 ok( r == S_OK, "ret %08x\n", r );
2180 if (pList)
2182 IXMLDOMNodeList_get_length(pList, &nLength1);
2183 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
2184 IXMLDOMNodeList_Release(pList);
2187 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2188 ok( r == S_OK, "ret %08x\n", r );
2189 if(mapAttr)
2191 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2192 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
2193 IXMLDOMNamedNodeMap_Release(mapAttr);
2196 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2197 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2198 IXMLDOMNode_Release(node_clone);
2201 IXMLDOMNode_Release(node);
2202 IXMLDOMDocument_Release(doc);
2205 static void test_xmlTypes(void)
2207 IXMLDOMDocument *doc = NULL;
2208 IXMLDOMElement *pRoot;
2209 HRESULT hr;
2210 IXMLDOMComment *pComment;
2211 IXMLDOMElement *pElement;
2212 IXMLDOMAttribute *pAttrubute;
2213 IXMLDOMNamedNodeMap *pAttribs;
2214 IXMLDOMCDATASection *pCDataSec;
2215 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2216 IXMLDOMDocumentFragment *pDocFrag = NULL;
2217 IXMLDOMEntityReference *pEntityRef = NULL;
2218 BSTR str;
2219 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2220 VARIANT v;
2221 long len = 0;
2223 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2224 if( hr != S_OK )
2225 return;
2227 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2228 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2230 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2231 ok(hr == S_FALSE, "ret %08x\n", hr );
2232 ok(pNextChild == NULL, "pDocChild not NULL\n");
2234 /* test previous Sibling */
2235 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2236 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2238 pNextChild = (IXMLDOMNode *)0x1;
2239 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2240 ok(hr == S_FALSE, "ret %08x\n", hr );
2241 ok(pNextChild == NULL, "pNextChild not NULL\n");
2243 /* test get_attributes */
2244 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2245 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2247 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2248 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2249 ok(hr == S_FALSE, "ret %08x\n", hr );
2250 ok( pAttribs == NULL, "pAttribs not NULL\n");
2252 /* test get_dataType */
2253 hr = IXMLDOMDocument_get_dataType(doc, &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 = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2260 ok(hr == S_OK, "ret %08x\n", hr );
2261 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2262 SysFreeString(str);
2264 /* test implementation */
2265 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2266 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2268 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2269 ok(hr == S_OK, "ret %08x\n", hr );
2270 if(hr == S_OK)
2272 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2273 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2275 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2276 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2278 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2279 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2281 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2282 ok(hr == S_OK, "ret %08x\n", hr );
2283 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2285 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2286 ok(hr == S_OK, "ret %08x\n", hr );
2287 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2289 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2290 ok(hr == S_OK, "ret %08x\n", hr );
2291 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2293 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2294 ok(hr == S_OK, "ret %08x\n", hr );
2295 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2297 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2298 ok(hr == S_OK, "ret %08x\n", hr );
2299 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2301 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2302 ok(hr == S_OK, "ret %08x\n", hr );
2303 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2305 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2306 ok(hr == S_OK, "ret %08x\n", hr );
2307 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2309 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2310 ok(hr == S_OK, "ret %08x\n", hr );
2311 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2313 SysFreeString(sEmpty);
2314 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2319 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2320 ok(hr == S_OK, "ret %08x\n", hr );
2321 if(hr == S_OK)
2323 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2324 ok(hr == S_OK, "ret %08x\n", hr );
2325 if(hr == S_OK)
2327 /* Comment */
2328 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2329 ok(hr == S_OK, "ret %08x\n", hr );
2330 if(hr == S_OK)
2332 /* test get_attributes */
2333 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2334 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2336 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2337 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2338 ok(hr == S_FALSE, "ret %08x\n", hr );
2339 ok( pAttribs == NULL, "pAttribs not NULL\n");
2341 /* test nodeTypeString */
2342 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2343 ok(hr == S_OK, "ret %08x\n", hr );
2344 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2345 SysFreeString(str);
2347 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2348 ok(hr == S_OK, "ret %08x\n", hr );
2350 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2351 ok(hr == S_OK, "ret %08x\n", hr );
2352 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2353 SysFreeString(str);
2355 hr = IXMLDOMComment_get_xml(pComment, &str);
2356 ok(hr == S_OK, "ret %08x\n", hr );
2357 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2358 SysFreeString(str);
2360 hr = IXMLDOMComment_get_dataType(pComment, &v);
2361 ok(hr == S_FALSE, "ret %08x\n", hr );
2362 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2363 VariantClear(&v);
2365 /* put data Tests */
2366 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2367 ok(hr == S_OK, "ret %08x\n", hr );
2369 /* get data Tests */
2370 hr = IXMLDOMComment_get_data(pComment, &str);
2371 ok(hr == S_OK, "ret %08x\n", hr );
2372 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2373 SysFreeString(str);
2375 /* get data Tests */
2376 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2377 ok(hr == S_OK, "ret %08x\n", hr );
2378 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2379 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2380 VariantClear(&v);
2382 /* Confirm XML text is good */
2383 hr = IXMLDOMComment_get_xml(pComment, &str);
2384 ok(hr == S_OK, "ret %08x\n", hr );
2385 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2386 SysFreeString(str);
2388 /* Confirm we get the put_data Text back */
2389 hr = IXMLDOMComment_get_text(pComment, &str);
2390 ok(hr == S_OK, "ret %08x\n", hr );
2391 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2392 SysFreeString(str);
2394 /* test length property */
2395 hr = IXMLDOMComment_get_length(pComment, &len);
2396 ok(hr == S_OK, "ret %08x\n", hr );
2397 ok(len == 21, "expected 21 got %ld\n", len);
2399 /* test substringData */
2400 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2401 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2403 /* test substringData - Invalid offset */
2404 str = (BSTR)&szElement;
2405 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2406 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2407 ok( str == NULL, "incorrect string\n");
2409 /* test substringData - Invalid offset */
2410 str = (BSTR)&szElement;
2411 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2412 ok(hr == S_FALSE, "ret %08x\n", hr );
2413 ok( str == NULL, "incorrect string\n");
2415 /* test substringData - Invalid size */
2416 str = (BSTR)&szElement;
2417 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2418 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2419 ok( str == NULL, "incorrect string\n");
2421 /* test substringData - Invalid size */
2422 str = (BSTR)&szElement;
2423 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2424 ok(hr == S_FALSE, "ret %08x\n", hr );
2425 ok( str == NULL, "incorrect string\n");
2427 /* test substringData - Start of string */
2428 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2429 ok(hr == S_OK, "ret %08x\n", hr );
2430 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2431 SysFreeString(str);
2433 /* test substringData - Middle of string */
2434 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2435 ok(hr == S_OK, "ret %08x\n", hr );
2436 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2437 SysFreeString(str);
2439 /* test substringData - End of string */
2440 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2441 ok(hr == S_OK, "ret %08x\n", hr );
2442 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2443 SysFreeString(str);
2445 /* test appendData */
2446 hr = IXMLDOMComment_appendData(pComment, NULL);
2447 ok(hr == S_OK, "ret %08x\n", hr );
2449 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2450 ok(hr == S_OK, "ret %08x\n", hr );
2452 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2453 ok(hr == S_OK, "ret %08x\n", hr );
2455 hr = IXMLDOMComment_get_text(pComment, &str);
2456 ok(hr == S_OK, "ret %08x\n", hr );
2457 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2458 SysFreeString(str);
2460 /* test insertData */
2461 str = SysAllocStringLen(NULL, 0);
2462 hr = IXMLDOMComment_insertData(pComment, -1, str);
2463 ok(hr == S_OK, "ret %08x\n", hr );
2465 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2466 ok(hr == S_OK, "ret %08x\n", hr );
2468 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2469 ok(hr == S_OK, "ret %08x\n", hr );
2471 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2472 ok(hr == S_OK, "ret %08x\n", hr );
2474 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2475 ok(hr == S_OK, "ret %08x\n", hr );
2477 hr = IXMLDOMComment_insertData(pComment, 0, str);
2478 ok(hr == S_OK, "ret %08x\n", hr );
2479 SysFreeString(str);
2481 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2482 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2484 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2485 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2487 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2488 ok(hr == S_OK, "ret %08x\n", hr );
2490 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2491 ok(hr == S_OK, "ret %08x\n", hr );
2493 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2494 ok(hr == S_OK, "ret %08x\n", hr );
2496 hr = IXMLDOMComment_get_text(pComment, &str);
2497 ok(hr == S_OK, "ret %08x\n", hr );
2498 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2499 SysFreeString(str);
2501 IXMLDOMComment_Release(pComment);
2504 /* Element */
2505 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2506 ok(hr == S_OK, "ret %08x\n", hr );
2507 if(hr == S_OK)
2509 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2510 ok(hr == S_OK, "ret %08x\n", hr );
2512 /* test nodeTypeString */
2513 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2514 ok(hr == S_OK, "ret %08x\n", hr );
2515 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2516 SysFreeString(str);
2518 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2519 ok(hr == S_OK, "ret %08x\n", hr );
2520 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2521 SysFreeString(str);
2523 hr = IXMLDOMElement_get_xml(pElement, &str);
2524 ok(hr == S_OK, "ret %08x\n", hr );
2525 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2526 SysFreeString(str);
2528 hr = IXMLDOMElement_get_dataType(pElement, &v);
2529 ok(hr == S_FALSE, "ret %08x\n", hr );
2530 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2531 VariantClear(&v);
2533 /* Attribute */
2534 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2535 ok(hr == S_OK, "ret %08x\n", hr );
2536 if(hr == S_OK)
2538 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2540 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2541 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2543 pNextChild = (IXMLDOMNode *)0x1;
2544 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2545 ok(hr == S_FALSE, "ret %08x\n", hr );
2546 ok(pNextChild == NULL, "pNextChild not NULL\n");
2548 /* test Previous Sibling*/
2549 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2550 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2552 pNextChild = (IXMLDOMNode *)0x1;
2553 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2554 ok(hr == S_FALSE, "ret %08x\n", hr );
2555 ok(pNextChild == NULL, "pNextChild not NULL\n");
2557 /* test get_attributes */
2558 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2559 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2561 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2562 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2563 ok(hr == S_FALSE, "ret %08x\n", hr );
2564 ok( pAttribs == NULL, "pAttribs not NULL\n");
2566 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2567 ok(hr == E_FAIL, "ret %08x\n", hr );
2568 ok(pNewChild == NULL, "pNewChild not NULL\n");
2570 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2571 ok(hr == S_OK, "ret %08x\n", hr );
2572 if ( hr == S_OK )
2574 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2575 ok(hr == S_OK, "ret %08x\n", hr );
2577 IXMLDOMNamedNodeMap_Release(pAttribs);
2580 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2581 ok(hr == S_OK, "ret %08x\n", hr );
2582 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2583 SysFreeString(str);
2585 /* test nodeTypeString */
2586 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2587 ok(hr == S_OK, "ret %08x\n", hr );
2588 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2589 SysFreeString(str);
2591 /* test nodeName */
2592 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2593 ok(hr == S_OK, "ret %08x\n", hr );
2594 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
2595 SysFreeString(str);
2597 /* test name property */
2598 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
2599 ok(hr == S_OK, "ret %08x\n", hr );
2600 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
2601 SysFreeString(str);
2603 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2604 ok(hr == S_OK, "ret %08x\n", hr );
2605 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2606 SysFreeString(str);
2608 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2609 ok(hr == S_FALSE, "ret %08x\n", hr );
2610 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2611 VariantClear(&v);
2613 IXMLDOMAttribute_Release(pAttrubute);
2615 /* Check Element again with the Add Attribute*/
2616 hr = IXMLDOMElement_get_xml(pElement, &str);
2617 ok(hr == S_OK, "ret %08x\n", hr );
2618 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2619 SysFreeString(str);
2622 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2623 ok(hr == S_OK, "ret %08x\n", hr );
2625 hr = IXMLDOMElement_get_xml(pElement, &str);
2626 ok(hr == S_OK, "ret %08x\n", hr );
2627 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2628 SysFreeString(str);
2630 IXMLDOMElement_Release(pElement);
2633 /* CData Section */
2634 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2635 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2637 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2638 ok(hr == S_OK, "ret %08x\n", hr );
2639 if(hr == S_OK)
2641 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2642 VARIANT var;
2644 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2645 ok(hr == S_OK, "ret %08x\n", hr );
2647 /* get Attribute Tests */
2648 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2649 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2651 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2652 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2653 ok(hr == S_FALSE, "ret %08x\n", hr );
2654 ok(pAttribs == NULL, "pAttribs != NULL\n");
2656 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2657 ok(hr == S_OK, "ret %08x\n", hr );
2658 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2659 SysFreeString(str);
2661 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2662 ok(hr == S_OK, "ret %08x\n", hr );
2663 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2664 SysFreeString(str);
2666 /* test lastChild */
2667 pNextChild = (IXMLDOMNode*)0x1;
2668 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2669 ok(hr == S_FALSE, "ret %08x\n", hr );
2670 ok(pNextChild == NULL, "pNextChild not NULL\n");
2672 /* test get_dataType */
2673 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2674 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2676 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2677 ok(hr == S_FALSE, "ret %08x\n", hr );
2678 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2679 VariantClear(&v);
2681 /* test nodeTypeString */
2682 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2683 ok(hr == S_OK, "ret %08x\n", hr );
2684 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2685 SysFreeString(str);
2687 /* put data Tests */
2688 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
2689 ok(hr == S_OK, "ret %08x\n", hr );
2691 /* Confirm XML text is good */
2692 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2693 ok(hr == S_OK, "ret %08x\n", hr );
2694 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
2695 SysFreeString(str);
2697 /* Confirm we get the put_data Text back */
2698 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2699 ok(hr == S_OK, "ret %08x\n", hr );
2700 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2701 SysFreeString(str);
2703 /* test length property */
2704 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
2705 ok(hr == S_OK, "ret %08x\n", hr );
2706 ok(len == 21, "expected 21 got %ld\n", len);
2708 /* test get nodeValue */
2709 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
2710 ok(hr == S_OK, "ret %08x\n", hr );
2711 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2712 VariantClear(&var);
2714 /* test get data */
2715 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
2716 ok(hr == S_OK, "ret %08x\n", hr );
2717 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2718 SysFreeString(str);
2720 /* test substringData */
2721 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
2722 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2724 /* test substringData - Invalid offset */
2725 str = (BSTR)&szElement;
2726 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
2727 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2728 ok( str == NULL, "incorrect string\n");
2730 /* test substringData - Invalid offset */
2731 str = (BSTR)&szElement;
2732 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
2733 ok(hr == S_FALSE, "ret %08x\n", hr );
2734 ok( str == NULL, "incorrect string\n");
2736 /* test substringData - Invalid size */
2737 str = (BSTR)&szElement;
2738 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
2739 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2740 ok( str == NULL, "incorrect string\n");
2742 /* test substringData - Invalid size */
2743 str = (BSTR)&szElement;
2744 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
2745 ok(hr == S_FALSE, "ret %08x\n", hr );
2746 ok( str == NULL, "incorrect string\n");
2748 /* test substringData - Start of string */
2749 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
2750 ok(hr == S_OK, "ret %08x\n", hr );
2751 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2752 SysFreeString(str);
2754 /* test substringData - Middle of string */
2755 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
2756 ok(hr == S_OK, "ret %08x\n", hr );
2757 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2758 SysFreeString(str);
2760 /* test substringData - End of string */
2761 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
2762 ok(hr == S_OK, "ret %08x\n", hr );
2763 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2764 SysFreeString(str);
2766 /* test appendData */
2767 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
2768 ok(hr == S_OK, "ret %08x\n", hr );
2770 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
2771 ok(hr == S_OK, "ret %08x\n", hr );
2773 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
2774 ok(hr == S_OK, "ret %08x\n", hr );
2776 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2777 ok(hr == S_OK, "ret %08x\n", hr );
2778 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2779 SysFreeString(str);
2781 /* test insertData */
2782 str = SysAllocStringLen(NULL, 0);
2783 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
2784 ok(hr == S_OK, "ret %08x\n", hr );
2786 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
2787 ok(hr == S_OK, "ret %08x\n", hr );
2789 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
2790 ok(hr == S_OK, "ret %08x\n", hr );
2792 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
2793 ok(hr == S_OK, "ret %08x\n", hr );
2795 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
2796 ok(hr == S_OK, "ret %08x\n", hr );
2798 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
2799 ok(hr == S_OK, "ret %08x\n", hr );
2800 SysFreeString(str);
2802 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
2803 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2805 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
2806 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2808 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
2809 ok(hr == S_OK, "ret %08x\n", hr );
2811 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
2812 ok(hr == S_OK, "ret %08x\n", hr );
2814 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
2815 ok(hr == S_OK, "ret %08x\n", hr );
2817 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2818 ok(hr == S_OK, "ret %08x\n", hr );
2819 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2820 SysFreeString(str);
2822 IXMLDOMCDATASection_Release(pCDataSec);
2825 /* Document Fragments */
2826 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
2827 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2829 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
2830 ok(hr == S_OK, "ret %08x\n", hr );
2831 if(hr == S_OK)
2833 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2835 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
2836 ok(hr == S_OK, "ret %08x\n", hr );
2838 /* get Attribute Tests */
2839 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
2840 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2842 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2843 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
2844 ok(hr == S_FALSE, "ret %08x\n", hr );
2845 ok(pAttribs == NULL, "pAttribs != NULL\n");
2847 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
2848 ok(hr == S_OK, "ret %08x\n", hr );
2849 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
2850 SysFreeString(str);
2852 /* test next Sibling*/
2853 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
2854 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2856 pNextChild = (IXMLDOMNode *)0x1;
2857 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
2858 ok(hr == S_FALSE, "ret %08x\n", hr );
2859 ok(pNextChild == NULL, "pNextChild not NULL\n");
2861 /* test Previous Sibling*/
2862 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
2863 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2865 pNextChild = (IXMLDOMNode *)0x1;
2866 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
2867 ok(hr == S_FALSE, "ret %08x\n", hr );
2868 ok(pNextChild == NULL, "pNextChild not NULL\n");
2870 /* test get_dataType */
2871 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
2872 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2874 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
2875 ok(hr == S_FALSE, "ret %08x\n", hr );
2876 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2877 VariantClear(&v);
2879 /* test nodeTypeString */
2880 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
2881 ok(hr == S_OK, "ret %08x\n", hr );
2882 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
2883 SysFreeString(str);
2885 IXMLDOMDocumentFragment_Release(pDocFrag);
2888 /* Entity References */
2889 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
2890 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2892 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
2893 ok(hr == S_OK, "ret %08x\n", hr );
2894 if(hr == S_OK)
2896 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
2897 ok(hr == S_OK, "ret %08x\n", hr );
2899 /* get Attribute Tests */
2900 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
2901 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2903 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2904 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
2905 ok(hr == S_FALSE, "ret %08x\n", hr );
2906 ok(pAttribs == NULL, "pAttribs != NULL\n");
2908 /* test dataType */
2909 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
2910 ok(hr == S_FALSE, "ret %08x\n", hr );
2911 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2912 VariantClear(&v);
2914 /* test nodeTypeString */
2915 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
2916 ok(hr == S_OK, "ret %08x\n", hr );
2917 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
2918 SysFreeString(str);
2920 /* test get_xml*/
2921 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
2922 ok(hr == S_OK, "ret %08x\n", hr );
2923 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
2924 SysFreeString(str);
2926 IXMLDOMEntityReference_Release(pEntityRef);
2929 IXMLDOMElement_Release( pRoot );
2933 IXMLDOMDocument_Release(doc);
2935 free_bstrs();
2938 static void test_nodeTypeTests( void )
2940 IXMLDOMDocument *doc = NULL;
2941 IXMLDOMElement *pRoot;
2942 IXMLDOMElement *pElement;
2943 HRESULT hr;
2945 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2946 if( hr != S_OK )
2947 return;
2949 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2950 ok(hr == S_OK, "ret %08x\n", hr );
2951 if(hr == S_OK)
2953 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2954 ok(hr == S_OK, "ret %08x\n", hr );
2955 if(hr == S_OK)
2957 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
2958 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2960 /* Invalid Value */
2961 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
2962 ok(hr == E_FAIL, "ret %08x\n", hr );
2964 /* NOTE:
2965 * The name passed into put_dataType is case-insensitive. So many of the names
2966 * have been changed to reflect this.
2968 /* Boolean */
2969 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
2970 ok(hr == S_OK, "ret %08x\n", hr );
2971 if(hr == S_OK)
2973 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2975 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
2976 ok(hr == S_OK, "ret %08x\n", hr );
2978 IXMLDOMElement_Release(pElement);
2981 /* String */
2982 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
2983 ok(hr == S_OK, "ret %08x\n", hr );
2984 if(hr == S_OK)
2986 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2988 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
2989 ok(hr == S_OK, "ret %08x\n", hr );
2991 IXMLDOMElement_Release(pElement);
2994 /* Number */
2995 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
2996 ok(hr == S_OK, "ret %08x\n", hr );
2997 if(hr == S_OK)
2999 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3001 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
3002 ok(hr == S_OK, "ret %08x\n", hr );
3004 IXMLDOMElement_Release(pElement);
3007 /* Int */
3008 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
3009 ok(hr == S_OK, "ret %08x\n", hr );
3010 if(hr == S_OK)
3012 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3014 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
3015 ok(hr == S_OK, "ret %08x\n", hr );
3017 IXMLDOMElement_Release(pElement);
3020 /* Fixed */
3021 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3022 ok(hr == S_OK, "ret %08x\n", hr );
3023 if(hr == S_OK)
3025 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3027 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3028 ok(hr == S_OK, "ret %08x\n", hr );
3030 IXMLDOMElement_Release(pElement);
3033 /* DateTime */
3034 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3035 ok(hr == S_OK, "ret %08x\n", hr );
3036 if(hr == S_OK)
3038 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3040 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3041 ok(hr == S_OK, "ret %08x\n", hr );
3043 IXMLDOMElement_Release(pElement);
3046 /* DateTime TZ */
3047 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3048 ok(hr == S_OK, "ret %08x\n", hr );
3049 if(hr == S_OK)
3051 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3053 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3054 ok(hr == S_OK, "ret %08x\n", hr );
3056 IXMLDOMElement_Release(pElement);
3059 /* Date */
3060 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3061 ok(hr == S_OK, "ret %08x\n", hr );
3062 if(hr == S_OK)
3064 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3066 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3067 ok(hr == S_OK, "ret %08x\n", hr );
3069 IXMLDOMElement_Release(pElement);
3072 /* Time */
3073 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3074 ok(hr == S_OK, "ret %08x\n", hr );
3075 if(hr == S_OK)
3077 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3079 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3080 ok(hr == S_OK, "ret %08x\n", hr );
3082 IXMLDOMElement_Release(pElement);
3085 /* Time.tz */
3086 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3087 ok(hr == S_OK, "ret %08x\n", hr );
3088 if(hr == S_OK)
3090 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3092 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3093 ok(hr == S_OK, "ret %08x\n", hr );
3095 IXMLDOMElement_Release(pElement);
3098 /* I1 */
3099 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3100 ok(hr == S_OK, "ret %08x\n", hr );
3101 if(hr == S_OK)
3103 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3105 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3106 ok(hr == S_OK, "ret %08x\n", hr );
3108 IXMLDOMElement_Release(pElement);
3111 /* I2 */
3112 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3113 ok(hr == S_OK, "ret %08x\n", hr );
3114 if(hr == S_OK)
3116 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3118 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3119 ok(hr == S_OK, "ret %08x\n", hr );
3121 IXMLDOMElement_Release(pElement);
3124 /* I4 */
3125 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3126 ok(hr == S_OK, "ret %08x\n", hr );
3127 if(hr == S_OK)
3129 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3131 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3132 ok(hr == S_OK, "ret %08x\n", hr );
3134 IXMLDOMElement_Release(pElement);
3137 /* UI1 */
3138 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3139 ok(hr == S_OK, "ret %08x\n", hr );
3140 if(hr == S_OK)
3142 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3144 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3145 ok(hr == S_OK, "ret %08x\n", hr );
3147 IXMLDOMElement_Release(pElement);
3150 /* UI2 */
3151 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3152 ok(hr == S_OK, "ret %08x\n", hr );
3153 if(hr == S_OK)
3155 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3157 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3158 ok(hr == S_OK, "ret %08x\n", hr );
3160 IXMLDOMElement_Release(pElement);
3163 /* UI4 */
3164 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3165 ok(hr == S_OK, "ret %08x\n", hr );
3166 if(hr == S_OK)
3168 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3170 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3171 ok(hr == S_OK, "ret %08x\n", hr );
3173 IXMLDOMElement_Release(pElement);
3176 /* r4 */
3177 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3178 ok(hr == S_OK, "ret %08x\n", hr );
3179 if(hr == S_OK)
3181 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3183 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3184 ok(hr == S_OK, "ret %08x\n", hr );
3186 IXMLDOMElement_Release(pElement);
3189 /* r8 */
3190 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3191 ok(hr == S_OK, "ret %08x\n", hr );
3192 if(hr == S_OK)
3194 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3196 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3197 ok(hr == S_OK, "ret %08x\n", hr );
3199 IXMLDOMElement_Release(pElement);
3202 /* float */
3203 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3204 ok(hr == S_OK, "ret %08x\n", hr );
3205 if(hr == S_OK)
3207 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3209 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3210 ok(hr == S_OK, "ret %08x\n", hr );
3212 IXMLDOMElement_Release(pElement);
3215 /* uuid */
3216 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3217 ok(hr == S_OK, "ret %08x\n", hr );
3218 if(hr == S_OK)
3220 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3222 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3223 ok(hr == S_OK, "ret %08x\n", hr );
3225 IXMLDOMElement_Release(pElement);
3228 /* bin.hex */
3229 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3230 ok(hr == S_OK, "ret %08x\n", hr );
3231 if(hr == S_OK)
3233 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3235 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3236 ok(hr == S_OK, "ret %08x\n", hr );
3238 IXMLDOMElement_Release(pElement);
3241 /* bin.base64 */
3242 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3243 ok(hr == S_OK, "ret %08x\n", hr );
3244 if(hr == S_OK)
3246 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3248 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3249 ok(hr == S_OK, "ret %08x\n", hr );
3251 IXMLDOMElement_Release(pElement);
3254 /* Check changing types */
3255 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3256 ok(hr == S_OK, "ret %08x\n", hr );
3257 if(hr == S_OK)
3259 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3261 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3262 ok(hr == S_OK, "ret %08x\n", hr );
3264 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3265 ok(hr == S_OK, "ret %08x\n", hr );
3267 IXMLDOMElement_Release(pElement);
3270 IXMLDOMElement_Release(pRoot);
3274 IXMLDOMDocument_Release(doc);
3276 free_bstrs();
3279 static void test_DocumentSaveToDocument(void)
3281 IXMLDOMDocument *doc = NULL;
3282 IXMLDOMDocument *doc2 = NULL;
3283 IXMLDOMElement *pRoot;
3285 HRESULT hr;
3287 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3288 if( hr != S_OK )
3289 return;
3291 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3292 if( hr != S_OK )
3294 IXMLDOMDocument_Release(doc);
3295 return;
3298 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3299 ok(hr == S_OK, "ret %08x\n", hr );
3300 if(hr == S_OK)
3302 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3303 ok(hr == S_OK, "ret %08x\n", hr );
3304 if(hr == S_OK)
3306 VARIANT vDoc;
3307 BSTR sOrig;
3308 BSTR sNew;
3310 V_VT(&vDoc) = VT_UNKNOWN;
3311 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3313 hr = IXMLDOMDocument_save(doc, vDoc);
3314 ok(hr == S_OK, "ret %08x\n", hr );
3316 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3317 ok(hr == S_OK, "ret %08x\n", hr );
3319 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3320 ok(hr == S_OK, "ret %08x\n", hr );
3322 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3324 SysFreeString(sOrig);
3325 SysFreeString(sNew);
3329 IXMLDOMDocument_Release(doc2);
3330 IXMLDOMDocument_Release(doc);
3333 static void test_DocumentSaveToFile(void)
3335 IXMLDOMDocument *doc = NULL;
3336 IXMLDOMElement *pRoot;
3337 HANDLE file;
3338 char buffer[100];
3339 DWORD read = 0;
3340 HRESULT hr;
3342 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3343 if( hr != S_OK )
3344 return;
3346 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3347 ok(hr == S_OK, "ret %08x\n", hr );
3348 if(hr == S_OK)
3350 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3351 ok(hr == S_OK, "ret %08x\n", hr );
3352 if(hr == S_OK)
3354 VARIANT vFile;
3356 V_VT(&vFile) = VT_BSTR;
3357 V_BSTR(&vFile) = _bstr_("test.xml");
3359 hr = IXMLDOMDocument_save(doc, vFile);
3360 ok(hr == S_OK, "ret %08x\n", hr );
3364 IXMLDOMElement_Release(pRoot);
3365 IXMLDOMDocument_Release(doc);
3367 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3368 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3369 if(file == INVALID_HANDLE_VALUE)
3370 return;
3372 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3373 ok(read != 0, "could not read file\n");
3374 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3376 CloseHandle(file);
3377 DeleteFile("test.xml");
3380 static void test_testTransforms(void)
3382 IXMLDOMDocument *doc = NULL;
3383 IXMLDOMDocument *docSS = NULL;
3384 IXMLDOMNode *pNode;
3385 VARIANT_BOOL bSucc;
3387 HRESULT hr;
3389 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3390 if( hr != S_OK )
3391 return;
3393 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3394 if( hr != S_OK )
3396 IXMLDOMDocument_Release(doc);
3397 return;
3400 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3401 ok(hr == S_OK, "ret %08x\n", hr );
3403 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3404 ok(hr == S_OK, "ret %08x\n", hr );
3406 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3407 ok(hr == S_OK, "ret %08x\n", hr );
3408 if(hr == S_OK)
3410 BSTR bOut;
3412 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3413 ok(hr == S_OK, "ret %08x\n", hr );
3414 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3416 IXMLDOMNode_Release(pNode);
3419 IXMLDOMDocument_Release(docSS);
3420 IXMLDOMDocument_Release(doc);
3422 free_bstrs();
3425 static void test_Namespaces(void)
3427 IXMLDOMDocument2 *doc = NULL;
3428 IXMLDOMNode *pNode;
3429 IXMLDOMNode *pNode2 = NULL;
3430 VARIANT_BOOL bSucc;
3431 HRESULT hr;
3432 BSTR str;
3433 static const CHAR szNamespacesXML[] =
3434 "<?xml version=\"1.0\"?>\n"
3435 "<root xmlns:WEB='http://www.winehq.org'>\n"
3436 "<WEB:Site version=\"1.0\" />\n"
3437 "</root>";
3439 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3440 if( hr != S_OK )
3441 return;
3443 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3444 ok(hr == S_OK, "ret %08x\n", hr );
3445 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3447 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3448 ok(hr == S_OK, "ret %08x\n", hr );
3449 if(hr == S_OK)
3451 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3452 ok( hr == S_OK, "ret %08x\n", hr );
3453 ok( pNode2 != NULL, "pNode2 == NULL\n");
3455 /* Test get_prefix */
3456 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3457 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3458 /* NOTE: Need to test that arg2 gets cleared on Error. */
3460 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3461 ok( hr == S_OK, "ret %08x\n", hr );
3462 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3463 SysFreeString(str);
3465 /* Test get_namespaceURI */
3466 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3467 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3468 /* NOTE: Need to test that arg2 gets cleared on Error. */
3470 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3471 ok( hr == S_OK, "ret %08x\n", hr );
3472 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3473 SysFreeString(str);
3475 IXMLDOMNode_Release(pNode2);
3476 IXMLDOMNode_Release(pNode);
3479 IXMLDOMDocument2_Release(doc);
3481 free_bstrs();
3484 static void test_FormattingXML(void)
3486 IXMLDOMDocument2 *doc = NULL;
3487 IXMLDOMElement *pElement;
3488 VARIANT_BOOL bSucc;
3489 HRESULT hr;
3490 BSTR str;
3491 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
3492 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
3494 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3495 if( hr != S_OK )
3496 return;
3498 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
3499 ok(hr == S_OK, "ret %08x\n", hr );
3500 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3502 if(bSucc == VARIANT_TRUE)
3504 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
3505 ok(hr == S_OK, "ret %08x\n", hr );
3506 if(hr == S_OK)
3508 hr = IXMLDOMElement_get_xml(pElement, &str);
3509 ok(hr == S_OK, "ret %08x\n", hr );
3510 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
3511 SysFreeString(str);
3513 IXMLDOMElement_Release(pElement);
3517 IXMLDOMDocument2_Release(doc);
3519 free_bstrs();
3522 START_TEST(domdoc)
3524 HRESULT r;
3526 r = CoInitialize( NULL );
3527 ok( r == S_OK, "failed to init com\n");
3529 test_domdoc();
3530 test_domnode();
3531 test_refs();
3532 test_create();
3533 test_getElementsByTagName();
3534 test_get_text();
3535 test_get_childNodes();
3536 test_removeChild();
3537 test_XMLHTTP();
3538 test_IXMLDOMDocument2();
3539 test_XPath();
3540 test_cloneNode();
3541 test_xmlTypes();
3542 test_nodeTypeTests();
3543 test_DocumentSaveToDocument();
3544 test_DocumentSaveToFile();
3545 test_testTransforms();
3546 test_Namespaces();
3547 test_FormattingXML();
3549 CoUninitialize();