msxml3: Correct unsupported functions in IDispatchEx.
[wine/multimedia.git] / dlls / msxml3 / tests / domdoc.c
blob8af6b02dda18f6e4d27fa3fb6c7a203744dd6dee
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 if(sName)
1569 SysFreeString(sName);
1571 r = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
1572 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1574 r = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
1575 ok(r == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", r);
1576 if(r == S_OK)
1577 IUnknown_Release(pUnk);
1579 IDispatchEx_Release( dispex );
1583 IXMLDOMNodeList_Release( node_list );
1584 SysFreeString( str );
1586 str = SysAllocString( szbs );
1587 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1588 ok( r == S_OK, "ret %08x\n", r );
1589 r = IXMLDOMNodeList_get_length( node_list, &len );
1590 ok( r == S_OK, "ret %08x\n", r );
1591 ok( len == 1, "len %ld\n", len );
1592 IXMLDOMNodeList_Release( node_list );
1593 SysFreeString( str );
1595 str = SysAllocString( szdl );
1596 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1597 ok( r == S_OK, "ret %08x\n", r );
1598 r = IXMLDOMNodeList_get_length( node_list, &len );
1599 ok( r == S_OK, "ret %08x\n", r );
1600 ok( len == 0, "len %ld\n", len );
1601 IXMLDOMNodeList_Release( node_list );
1602 SysFreeString( str );
1604 str = SysAllocString( szstr1 );
1605 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1606 ok( r == S_OK, "ret %08x\n", r );
1607 r = IXMLDOMNodeList_get_length( node_list, &len );
1608 ok( r == S_OK, "ret %08x\n", r );
1609 ok( len == 0, "len %ld\n", len );
1610 IXMLDOMNodeList_Release( node_list );
1611 SysFreeString( str );
1613 IXMLDOMDocument_Release( doc );
1616 static void test_get_text(void)
1618 HRESULT r;
1619 BSTR str;
1620 VARIANT_BOOL b;
1621 IXMLDOMDocument *doc;
1622 IXMLDOMNode *node, *node2, *node3;
1623 IXMLDOMNodeList *node_list;
1624 IXMLDOMNamedNodeMap *node_map;
1625 long len;
1627 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1628 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1629 if( r != S_OK )
1630 return;
1632 str = SysAllocString( szComplete4 );
1633 r = IXMLDOMDocument_loadXML( doc, str, &b );
1634 ok( r == S_OK, "loadXML failed\n");
1635 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1636 SysFreeString( str );
1638 str = SysAllocString( szbs );
1639 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1640 ok( r == S_OK, "ret %08x\n", r );
1641 SysFreeString(str);
1643 if (0) {
1644 /* this test crashes on win9x */
1645 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1646 ok( r == E_INVALIDARG, "ret %08x\n", r );
1649 r = IXMLDOMNodeList_get_length( node_list, NULL );
1650 ok( r == E_INVALIDARG, "ret %08x\n", r );
1652 r = IXMLDOMNodeList_get_length( node_list, &len );
1653 ok( r == S_OK, "ret %08x\n", r );
1654 ok( len == 1, "expect 1 got %ld\n", len );
1656 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1657 ok( r == E_INVALIDARG, "ret %08x\n", r );
1659 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1660 ok( r == E_INVALIDARG, "ret %08x\n", r );
1662 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1663 ok( r == S_OK, "ret %08x\n", r );
1664 IXMLDOMNodeList_Release( node_list );
1666 /* Invalid output parameter*/
1667 r = IXMLDOMNode_get_text( node, NULL );
1668 ok( r == E_INVALIDARG, "ret %08x\n", r );
1670 r = IXMLDOMNode_get_text( node, &str );
1671 ok( r == S_OK, "ret %08x\n", r );
1672 todo_wine {
1673 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)), "wrong string\n" );
1675 ok( !memcmp(str, szfn1_txt, sizeof(szfn1_txt)-4), "wrong string\n" );
1676 SysFreeString(str);
1678 r = IXMLDOMNode_get_attributes( node, &node_map );
1679 ok( r == S_OK, "ret %08x\n", r );
1681 str = SysAllocString( szvr );
1682 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1683 ok( r == S_OK, "ret %08x\n", r );
1684 SysFreeString(str);
1686 r = IXMLDOMNode_get_text( node2, &str );
1687 ok( r == S_OK, "ret %08x\n", r );
1688 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1689 SysFreeString(str);
1691 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1692 ok( r == S_OK, "ret %08x\n", r );
1694 r = IXMLDOMNode_get_text( node3, &str );
1695 ok( r == S_OK, "ret %08x\n", r );
1696 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1697 SysFreeString(str);
1700 IXMLDOMNode_Release( node3 );
1701 IXMLDOMNode_Release( node2 );
1702 IXMLDOMNamedNodeMap_Release( node_map );
1703 IXMLDOMNode_Release( node );
1704 IXMLDOMDocument_Release( doc );
1707 static void test_get_childNodes(void)
1709 HRESULT r;
1710 BSTR str;
1711 VARIANT_BOOL b;
1712 IXMLDOMDocument *doc;
1713 IXMLDOMElement *element;
1714 IXMLDOMNode *node, *node2;
1715 IXMLDOMNodeList *node_list, *node_list2;
1716 long len;
1718 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1719 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1720 if( r != S_OK )
1721 return;
1723 str = SysAllocString( szComplete4 );
1724 r = IXMLDOMDocument_loadXML( doc, str, &b );
1725 ok( r == S_OK, "loadXML failed\n");
1726 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1727 SysFreeString( str );
1729 r = IXMLDOMDocument_get_documentElement( doc, &element );
1730 ok( r == S_OK, "ret %08x\n", r);
1732 r = IXMLDOMElement_get_childNodes( element, &node_list );
1733 ok( r == S_OK, "ret %08x\n", r);
1735 r = IXMLDOMNodeList_get_length( node_list, &len );
1736 ok( r == S_OK, "ret %08x\n", r);
1737 ok( len == 4, "len %ld\n", len);
1739 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1740 ok( r == S_OK, "ret %08x\n", r);
1742 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1743 ok( r == S_OK, "ret %08x\n", r);
1745 r = IXMLDOMNodeList_get_length( node_list2, &len );
1746 ok( r == S_OK, "ret %08x\n", r);
1747 ok( len == 0, "len %ld\n", len);
1749 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1750 ok( r == S_FALSE, "ret %08x\n", r);
1752 IXMLDOMNodeList_Release( node_list2 );
1753 IXMLDOMNode_Release( node );
1754 IXMLDOMNodeList_Release( node_list );
1755 IXMLDOMElement_Release( element );
1756 IXMLDOMDocument_Release( doc );
1759 static void test_removeChild(void)
1761 HRESULT r;
1762 BSTR str;
1763 VARIANT_BOOL b;
1764 IXMLDOMDocument *doc;
1765 IXMLDOMElement *element;
1766 IXMLDOMNode *node, *node2, *node3, *node4;
1767 IXMLDOMNodeList *node_list, *node_list2;
1769 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1770 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1771 if( r != S_OK )
1772 return;
1774 str = SysAllocString( szComplete4 );
1775 r = IXMLDOMDocument_loadXML( doc, str, &b );
1776 ok( r == S_OK, "loadXML failed\n");
1777 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1778 SysFreeString( str );
1780 r = IXMLDOMDocument_get_documentElement( doc, &element );
1781 ok( r == S_OK, "ret %08x\n", r);
1783 r = IXMLDOMElement_get_childNodes( element, &node_list );
1784 ok( r == S_OK, "ret %08x\n", r);
1786 r = IXMLDOMNodeList_get_item( node_list, 3, &node );
1787 ok( r == S_OK, "ret %08x\n", r);
1789 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1790 ok( r == S_OK, "ret %08x\n", r);
1792 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1793 ok( r == S_OK, "ret %08x\n", r);
1795 r = IXMLDOMElement_removeChild( element, NULL, &node2 );
1796 ok( r == E_INVALIDARG, "ret %08x\n", r );
1798 r = IXMLDOMElement_removeChild( element, node4, &node2 );
1799 ok( r == S_OK, "ret %08x\n", r);
1800 ok( node4 == node2, "node %p node2 %p\n", node4, node2 );
1802 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1803 ok( r == S_FALSE, "ret %08x\n", r);
1804 ok( node3 == NULL, "%p\n", node3 );
1806 IXMLDOMNode_Release( node2 );
1807 IXMLDOMNode_Release( node4 );
1809 r = IXMLDOMNodeList_get_item( node_list, 0, &node4 );
1810 ok( r == S_OK, "ret %08x\n", r);
1812 r = IXMLDOMElement_removeChild( element, node4, NULL );
1813 ok( r == S_OK, "ret %08x\n", r);
1815 r = IXMLDOMNode_get_parentNode( node4, &node3 );
1816 ok( r == S_FALSE, "ret %08x\n", r);
1817 ok( node3 == NULL, "%p\n", node3 );
1819 IXMLDOMNode_Release( node4 );
1820 IXMLDOMNodeList_Release( node_list2 );
1821 IXMLDOMNode_Release( node );
1822 IXMLDOMNodeList_Release( node_list );
1823 IXMLDOMElement_Release( element );
1824 IXMLDOMDocument_Release( doc );
1827 static void test_XMLHTTP(void)
1829 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
1830 static WCHAR wszPOST[] = {'P','O','S','T',0};
1831 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
1832 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
1833 'p','o','s','t','t','e','s','t','.','p','h','p',0};
1834 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1835 IXMLHttpRequest *pXMLHttpRequest;
1836 BSTR bstrResponse;
1837 VARIANT dummy;
1838 VARIANT varfalse;
1839 VARIANT varbody;
1840 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
1841 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
1842 (void **)&pXMLHttpRequest);
1843 todo_wine {
1844 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
1846 if (hr != S_OK)
1847 return;
1849 VariantInit(&dummy);
1850 V_VT(&dummy) = VT_ERROR;
1851 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1852 VariantInit(&varfalse);
1853 V_VT(&varfalse) = VT_BOOL;
1854 V_BOOL(&varfalse) = VARIANT_FALSE;
1855 V_VT(&varbody) = VT_BSTR;
1856 V_BSTR(&varbody) = SysAllocString(wszBody);
1858 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
1859 ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
1861 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
1862 ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
1863 VariantClear(&varbody);
1865 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
1866 ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
1867 /* the server currently returns "FAILED" because the Content-Type header is
1868 * not what the server expects */
1869 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
1870 SysFreeString(bstrResponse);
1873 static void test_IXMLDOMDocument2(void)
1875 HRESULT r;
1876 VARIANT_BOOL b;
1877 BSTR str;
1878 IXMLDOMDocument *doc;
1879 IXMLDOMDocument2 *doc2;
1880 VARIANT var;
1881 int ref;
1883 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1884 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1885 if( r != S_OK )
1886 return;
1888 str = SysAllocString( szComplete4 );
1889 r = IXMLDOMDocument_loadXML( doc, str, &b );
1890 ok( r == S_OK, "loadXML failed\n");
1891 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1892 SysFreeString( str );
1894 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
1895 ok( r == S_OK, "ret %08x\n", r );
1896 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
1898 /* we will check if the variant got cleared */
1899 ref = IXMLDOMDocument2_AddRef(doc2);
1900 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
1901 V_VT(&var) = VT_UNKNOWN;
1902 V_UNKNOWN(&var) = (IUnknown *)doc2;
1904 /* invalid calls */
1905 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
1906 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
1907 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
1909 /* valid call */
1910 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1911 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1912 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1913 V_VT(&var) = VT_R4;
1915 /* the variant didn't get cleared*/
1916 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
1918 /* setProperty tests */
1919 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
1920 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
1921 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
1922 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1923 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1924 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
1926 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
1927 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
1928 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
1929 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
1931 IXMLDOMDocument2_Release( doc2 );
1932 IXMLDOMDocument_Release( doc );
1933 free_bstrs();
1936 static void test_XPath(void)
1938 HRESULT r;
1939 VARIANT var;
1940 VARIANT_BOOL b;
1941 IXMLDOMDocument2 *doc;
1942 IXMLDOMNode *rootNode;
1943 IXMLDOMNode *elem1Node;
1944 IXMLDOMNode *node;
1945 IXMLDOMNodeList *list;
1947 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1948 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
1949 if( r != S_OK )
1950 return;
1952 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
1953 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1955 /* switch to XPath */
1956 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
1958 /* some simple queries*/
1959 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
1960 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
1961 ole_check(IXMLDOMNodeList_reset(list));
1962 expect_list_and_release(list, "E2.D1");
1963 if (rootNode == NULL)
1964 return;
1966 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
1967 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
1969 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
1970 expect_list_and_release(list, "E3.E2.E2.D1");
1972 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
1973 /* using get_item for query results advances the position */
1974 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1975 expect_node(node, "E2.E2.D1");
1976 IXMLDOMNode_Release(node);
1977 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1978 expect_node(node, "E4.E2.D1");
1979 IXMLDOMNode_Release(node);
1980 ole_check(IXMLDOMNodeList_reset(list));
1981 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
1983 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
1984 expect_list_and_release(list, "E2.D1");
1986 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
1987 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
1988 ole_check(IXMLDOMNodeList_reset(list));
1989 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
1991 /* select an attribute */
1992 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
1993 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
1995 /* would evaluate to a number */
1996 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
1997 /* would evaluate to a boolean */
1998 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
1999 /* would evaluate to a string */
2000 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2002 /* no results */
2003 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2004 expect_list_and_release(list, "");
2005 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2006 expect_list_and_release(list, "");
2007 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2008 expect_list_and_release(list, "");
2010 /* foo undeclared in document node */
2011 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2012 /* undeclared in <root> node */
2013 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2014 /* undeclared in <elem> node */
2015 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2016 /* but this trick can be used */
2017 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2018 expect_list_and_release(list, "E3.E4.E2.D1");
2020 /* it has to be declared in SelectionNamespaces */
2021 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2022 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2024 /* now the namespace can be used */
2025 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2026 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2027 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2028 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2029 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2030 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2031 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2032 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2034 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2035 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2036 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2038 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2040 VariantInit(&var);
2041 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2042 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2043 if (V_VT(&var) == VT_BSTR)
2044 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2046 /* extra attributes - same thing*/
2047 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2048 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2049 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2051 IXMLDOMNode_Release(rootNode);
2052 IXMLDOMNode_Release(elem1Node);
2053 IXMLDOMDocument_Release(doc);
2054 free_bstrs();
2057 static void test_cloneNode(void )
2059 IXMLDOMDocument *doc = NULL;
2060 VARIANT_BOOL b;
2061 IXMLDOMNodeList *pList;
2062 IXMLDOMNamedNodeMap *mapAttr;
2063 long nLength = 0, nLength1 = 0;
2064 long nAttrCnt = 0, nAttrCnt1 = 0;
2065 IXMLDOMNode *node;
2066 IXMLDOMNode *node_clone;
2067 HRESULT r;
2068 BSTR str;
2069 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2071 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2072 if( r != S_OK )
2073 return;
2075 str = SysAllocString( szComplete4 );
2076 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2077 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2078 SysFreeString(str);
2080 if(!b)
2081 return;
2083 str = SysAllocString( szSearch);
2084 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2085 ok( r == S_OK, "ret %08x\n", r );
2086 ok( node != NULL, "node %p\n", node );
2087 SysFreeString(str);
2089 if(!node)
2091 IXMLDOMDocument_Release(doc);
2092 return;
2095 /* Check invalid parameter */
2096 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2097 ok( r == E_INVALIDARG, "ret %08x\n", r );
2099 /* All Children */
2100 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2101 ok( r == S_OK, "ret %08x\n", r );
2102 ok( node_clone != NULL, "node %p\n", node );
2104 if(!node_clone)
2106 IXMLDOMDocument_Release(doc);
2107 IXMLDOMNode_Release(node);
2108 return;
2111 r = IXMLDOMNode_get_childNodes(node, &pList);
2112 ok( r == S_OK, "ret %08x\n", r );
2113 if (pList)
2115 IXMLDOMNodeList_get_length(pList, &nLength);
2116 IXMLDOMNodeList_Release(pList);
2119 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2120 ok( r == S_OK, "ret %08x\n", r );
2121 if(mapAttr)
2123 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2124 IXMLDOMNamedNodeMap_Release(mapAttr);
2127 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2128 ok( r == S_OK, "ret %08x\n", r );
2129 if (pList)
2131 IXMLDOMNodeList_get_length(pList, &nLength1);
2132 IXMLDOMNodeList_Release(pList);
2135 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2136 ok( r == S_OK, "ret %08x\n", r );
2137 if(mapAttr)
2139 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2140 IXMLDOMNamedNodeMap_Release(mapAttr);
2143 ok(nLength == nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2144 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2145 IXMLDOMNode_Release(node_clone);
2147 /* No Children */
2148 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2149 ok( r == S_OK, "ret %08x\n", r );
2150 ok( node_clone != NULL, "node %p\n", node );
2152 if(!node_clone)
2154 IXMLDOMDocument_Release(doc);
2155 IXMLDOMNode_Release(node);
2156 return;
2159 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2160 ok( r == S_OK, "ret %08x\n", r );
2161 if (pList)
2163 IXMLDOMNodeList_get_length(pList, &nLength1);
2164 ok( nLength1 == 0, "Length should be 0 (%ld)\n", nLength1);
2165 IXMLDOMNodeList_Release(pList);
2168 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2169 ok( r == S_OK, "ret %08x\n", r );
2170 if(mapAttr)
2172 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2173 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%ld)\n", nAttrCnt1);
2174 IXMLDOMNamedNodeMap_Release(mapAttr);
2177 ok(nLength != nLength1, "wrong Child count (%ld, %ld)\n", nLength, nLength1);
2178 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%ld, %ld)\n", nAttrCnt, nAttrCnt1);
2179 IXMLDOMNode_Release(node_clone);
2182 IXMLDOMNode_Release(node);
2183 IXMLDOMDocument_Release(doc);
2186 static void test_xmlTypes(void)
2188 IXMLDOMDocument *doc = NULL;
2189 IXMLDOMElement *pRoot;
2190 HRESULT hr;
2191 IXMLDOMComment *pComment;
2192 IXMLDOMElement *pElement;
2193 IXMLDOMAttribute *pAttrubute;
2194 IXMLDOMNamedNodeMap *pAttribs;
2195 IXMLDOMCDATASection *pCDataSec;
2196 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2197 IXMLDOMDocumentFragment *pDocFrag = NULL;
2198 IXMLDOMEntityReference *pEntityRef = NULL;
2199 BSTR str;
2200 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2201 VARIANT v;
2202 long len = 0;
2204 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2205 if( hr != S_OK )
2206 return;
2208 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2209 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2211 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2212 ok(hr == S_FALSE, "ret %08x\n", hr );
2213 ok(pNextChild == NULL, "pDocChild not NULL\n");
2215 /* test previous Sibling */
2216 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2217 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2219 pNextChild = (IXMLDOMNode *)0x1;
2220 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2221 ok(hr == S_FALSE, "ret %08x\n", hr );
2222 ok(pNextChild == NULL, "pNextChild not NULL\n");
2224 /* test get_attributes */
2225 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2226 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2228 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2229 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2230 ok(hr == S_FALSE, "ret %08x\n", hr );
2231 ok( pAttribs == NULL, "pAttribs not NULL\n");
2233 /* test get_dataType */
2234 hr = IXMLDOMDocument_get_dataType(doc, &v);
2235 ok(hr == S_FALSE, "ret %08x\n", hr );
2236 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2237 VariantClear(&v);
2239 /* test nodeTypeString */
2240 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2241 ok(hr == S_OK, "ret %08x\n", hr );
2242 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2243 SysFreeString(str);
2245 /* test implementation */
2246 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2247 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2249 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2250 ok(hr == S_OK, "ret %08x\n", hr );
2251 if(hr == S_OK)
2253 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2254 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2256 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2257 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2259 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2260 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2262 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2263 ok(hr == S_OK, "ret %08x\n", hr );
2264 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2266 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2267 ok(hr == S_OK, "ret %08x\n", hr );
2268 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2270 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2271 ok(hr == S_OK, "ret %08x\n", hr );
2272 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2274 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2275 ok(hr == S_OK, "ret %08x\n", hr );
2276 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2278 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2279 ok(hr == S_OK, "ret %08x\n", hr );
2280 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2282 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2283 ok(hr == S_OK, "ret %08x\n", hr );
2284 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2286 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2287 ok(hr == S_OK, "ret %08x\n", hr );
2288 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2290 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2291 ok(hr == S_OK, "ret %08x\n", hr );
2292 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2294 SysFreeString(sEmpty);
2295 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2300 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2301 ok(hr == S_OK, "ret %08x\n", hr );
2302 if(hr == S_OK)
2304 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2305 ok(hr == S_OK, "ret %08x\n", hr );
2306 if(hr == S_OK)
2308 /* Comment */
2309 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2310 ok(hr == S_OK, "ret %08x\n", hr );
2311 if(hr == S_OK)
2313 /* test get_attributes */
2314 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2315 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2317 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2318 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2319 ok(hr == S_FALSE, "ret %08x\n", hr );
2320 ok( pAttribs == NULL, "pAttribs not NULL\n");
2322 /* test nodeTypeString */
2323 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2324 ok(hr == S_OK, "ret %08x\n", hr );
2325 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2326 SysFreeString(str);
2328 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2329 ok(hr == S_OK, "ret %08x\n", hr );
2331 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2332 ok(hr == S_OK, "ret %08x\n", hr );
2333 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2334 SysFreeString(str);
2336 hr = IXMLDOMComment_get_xml(pComment, &str);
2337 ok(hr == S_OK, "ret %08x\n", hr );
2338 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2339 SysFreeString(str);
2341 hr = IXMLDOMComment_get_dataType(pComment, &v);
2342 ok(hr == S_FALSE, "ret %08x\n", hr );
2343 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2344 VariantClear(&v);
2346 /* put data Tests */
2347 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2348 ok(hr == S_OK, "ret %08x\n", hr );
2350 /* get data Tests */
2351 hr = IXMLDOMComment_get_data(pComment, &str);
2352 ok(hr == S_OK, "ret %08x\n", hr );
2353 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2354 SysFreeString(str);
2356 /* get data Tests */
2357 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2358 ok(hr == S_OK, "ret %08x\n", hr );
2359 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2360 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2361 VariantClear(&v);
2363 /* Confirm XML text is good */
2364 hr = IXMLDOMComment_get_xml(pComment, &str);
2365 ok(hr == S_OK, "ret %08x\n", hr );
2366 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2367 SysFreeString(str);
2369 /* Confirm we get the put_data Text back */
2370 hr = IXMLDOMComment_get_text(pComment, &str);
2371 ok(hr == S_OK, "ret %08x\n", hr );
2372 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2373 SysFreeString(str);
2375 /* test length property */
2376 hr = IXMLDOMComment_get_length(pComment, &len);
2377 ok(hr == S_OK, "ret %08x\n", hr );
2378 ok(len == 21, "expected 21 got %ld\n", len);
2380 /* test substringData */
2381 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2382 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2384 /* test substringData - Invalid offset */
2385 str = (BSTR)&szElement;
2386 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2387 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2388 ok( str == NULL, "incorrect string\n");
2390 /* test substringData - Invalid offset */
2391 str = (BSTR)&szElement;
2392 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2393 ok(hr == S_FALSE, "ret %08x\n", hr );
2394 ok( str == NULL, "incorrect string\n");
2396 /* test substringData - Invalid size */
2397 str = (BSTR)&szElement;
2398 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2399 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2400 ok( str == NULL, "incorrect string\n");
2402 /* test substringData - Invalid size */
2403 str = (BSTR)&szElement;
2404 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2405 ok(hr == S_FALSE, "ret %08x\n", hr );
2406 ok( str == NULL, "incorrect string\n");
2408 /* test substringData - Start of string */
2409 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2410 ok(hr == S_OK, "ret %08x\n", hr );
2411 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2412 SysFreeString(str);
2414 /* test substringData - Middle of string */
2415 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2416 ok(hr == S_OK, "ret %08x\n", hr );
2417 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2418 SysFreeString(str);
2420 /* test substringData - End of string */
2421 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2422 ok(hr == S_OK, "ret %08x\n", hr );
2423 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2424 SysFreeString(str);
2426 /* test appendData */
2427 hr = IXMLDOMComment_appendData(pComment, NULL);
2428 ok(hr == S_OK, "ret %08x\n", hr );
2430 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2431 ok(hr == S_OK, "ret %08x\n", hr );
2433 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2434 ok(hr == S_OK, "ret %08x\n", hr );
2436 hr = IXMLDOMComment_get_text(pComment, &str);
2437 ok(hr == S_OK, "ret %08x\n", hr );
2438 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2439 SysFreeString(str);
2441 /* test insertData */
2442 str = SysAllocStringLen(NULL, 0);
2443 hr = IXMLDOMComment_insertData(pComment, -1, str);
2444 ok(hr == S_OK, "ret %08x\n", hr );
2446 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2447 ok(hr == S_OK, "ret %08x\n", hr );
2449 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2450 ok(hr == S_OK, "ret %08x\n", hr );
2452 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2453 ok(hr == S_OK, "ret %08x\n", hr );
2455 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2456 ok(hr == S_OK, "ret %08x\n", hr );
2458 hr = IXMLDOMComment_insertData(pComment, 0, str);
2459 ok(hr == S_OK, "ret %08x\n", hr );
2460 SysFreeString(str);
2462 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2463 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2465 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2466 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2468 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2469 ok(hr == S_OK, "ret %08x\n", hr );
2471 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2472 ok(hr == S_OK, "ret %08x\n", hr );
2474 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2475 ok(hr == S_OK, "ret %08x\n", hr );
2477 hr = IXMLDOMComment_get_text(pComment, &str);
2478 ok(hr == S_OK, "ret %08x\n", hr );
2479 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2480 SysFreeString(str);
2482 IXMLDOMComment_Release(pComment);
2485 /* Element */
2486 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2487 ok(hr == S_OK, "ret %08x\n", hr );
2488 if(hr == S_OK)
2490 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2491 ok(hr == S_OK, "ret %08x\n", hr );
2493 /* test nodeTypeString */
2494 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2495 ok(hr == S_OK, "ret %08x\n", hr );
2496 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2497 SysFreeString(str);
2499 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2500 ok(hr == S_OK, "ret %08x\n", hr );
2501 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2502 SysFreeString(str);
2504 hr = IXMLDOMElement_get_xml(pElement, &str);
2505 ok(hr == S_OK, "ret %08x\n", hr );
2506 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2507 SysFreeString(str);
2509 hr = IXMLDOMElement_get_dataType(pElement, &v);
2510 ok(hr == S_FALSE, "ret %08x\n", hr );
2511 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2512 VariantClear(&v);
2514 /* Attribute */
2515 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2516 ok(hr == S_OK, "ret %08x\n", hr );
2517 if(hr == S_OK)
2519 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2521 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2522 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2524 pNextChild = (IXMLDOMNode *)0x1;
2525 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2526 ok(hr == S_FALSE, "ret %08x\n", hr );
2527 ok(pNextChild == NULL, "pNextChild not NULL\n");
2529 /* test Previous Sibling*/
2530 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2531 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2533 pNextChild = (IXMLDOMNode *)0x1;
2534 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2535 ok(hr == S_FALSE, "ret %08x\n", hr );
2536 ok(pNextChild == NULL, "pNextChild not NULL\n");
2538 /* test get_attributes */
2539 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2540 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2542 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2543 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2544 ok(hr == S_FALSE, "ret %08x\n", hr );
2545 ok( pAttribs == NULL, "pAttribs not NULL\n");
2547 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2548 ok(hr == E_FAIL, "ret %08x\n", hr );
2549 ok(pNewChild == NULL, "pNewChild not NULL\n");
2551 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2552 ok(hr == S_OK, "ret %08x\n", hr );
2553 if ( hr == S_OK )
2555 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2556 ok(hr == S_OK, "ret %08x\n", hr );
2558 IXMLDOMNamedNodeMap_Release(pAttribs);
2561 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2562 ok(hr == S_OK, "ret %08x\n", hr );
2563 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
2564 SysFreeString(str);
2566 /* test nodeTypeString */
2567 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
2568 ok(hr == S_OK, "ret %08x\n", hr );
2569 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2570 SysFreeString(str);
2572 /* test nodeName */
2573 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2574 ok(hr == S_OK, "ret %08x\n", hr );
2575 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
2576 SysFreeString(str);
2578 /* test name property */
2579 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
2580 ok(hr == S_OK, "ret %08x\n", hr );
2581 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
2582 SysFreeString(str);
2584 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
2585 ok(hr == S_OK, "ret %08x\n", hr );
2586 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
2587 SysFreeString(str);
2589 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
2590 ok(hr == S_FALSE, "ret %08x\n", hr );
2591 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2592 VariantClear(&v);
2594 IXMLDOMAttribute_Release(pAttrubute);
2596 /* Check Element again with the Add Attribute*/
2597 hr = IXMLDOMElement_get_xml(pElement, &str);
2598 ok(hr == S_OK, "ret %08x\n", hr );
2599 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
2600 SysFreeString(str);
2603 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
2604 ok(hr == S_OK, "ret %08x\n", hr );
2606 hr = IXMLDOMElement_get_xml(pElement, &str);
2607 ok(hr == S_OK, "ret %08x\n", hr );
2608 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
2609 SysFreeString(str);
2611 IXMLDOMElement_Release(pElement);
2614 /* CData Section */
2615 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
2616 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2618 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
2619 ok(hr == S_OK, "ret %08x\n", hr );
2620 if(hr == S_OK)
2622 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2623 VARIANT var;
2625 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
2626 ok(hr == S_OK, "ret %08x\n", hr );
2628 /* get Attribute Tests */
2629 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
2630 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2632 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2633 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
2634 ok(hr == S_FALSE, "ret %08x\n", hr );
2635 ok(pAttribs == NULL, "pAttribs != NULL\n");
2637 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
2638 ok(hr == S_OK, "ret %08x\n", hr );
2639 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
2640 SysFreeString(str);
2642 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2643 ok(hr == S_OK, "ret %08x\n", hr );
2644 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
2645 SysFreeString(str);
2647 /* test lastChild */
2648 pNextChild = (IXMLDOMNode*)0x1;
2649 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
2650 ok(hr == S_FALSE, "ret %08x\n", hr );
2651 ok(pNextChild == NULL, "pNextChild not NULL\n");
2653 /* test get_dataType */
2654 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
2655 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2657 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
2658 ok(hr == S_FALSE, "ret %08x\n", hr );
2659 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2660 VariantClear(&v);
2662 /* test nodeTypeString */
2663 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
2664 ok(hr == S_OK, "ret %08x\n", hr );
2665 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
2666 SysFreeString(str);
2668 /* put data Tests */
2669 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
2670 ok(hr == S_OK, "ret %08x\n", hr );
2672 /* Confirm XML text is good */
2673 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
2674 ok(hr == S_OK, "ret %08x\n", hr );
2675 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
2676 SysFreeString(str);
2678 /* Confirm we get the put_data Text back */
2679 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2680 ok(hr == S_OK, "ret %08x\n", hr );
2681 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2682 SysFreeString(str);
2684 /* test length property */
2685 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
2686 ok(hr == S_OK, "ret %08x\n", hr );
2687 ok(len == 21, "expected 21 got %ld\n", len);
2689 /* test get nodeValue */
2690 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
2691 ok(hr == S_OK, "ret %08x\n", hr );
2692 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2693 VariantClear(&var);
2695 /* test get data */
2696 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
2697 ok(hr == S_OK, "ret %08x\n", hr );
2698 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
2699 SysFreeString(str);
2701 /* test substringData */
2702 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
2703 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2705 /* test substringData - Invalid offset */
2706 str = (BSTR)&szElement;
2707 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
2708 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2709 ok( str == NULL, "incorrect string\n");
2711 /* test substringData - Invalid offset */
2712 str = (BSTR)&szElement;
2713 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
2714 ok(hr == S_FALSE, "ret %08x\n", hr );
2715 ok( str == NULL, "incorrect string\n");
2717 /* test substringData - Invalid size */
2718 str = (BSTR)&szElement;
2719 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
2720 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2721 ok( str == NULL, "incorrect string\n");
2723 /* test substringData - Invalid size */
2724 str = (BSTR)&szElement;
2725 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
2726 ok(hr == S_FALSE, "ret %08x\n", hr );
2727 ok( str == NULL, "incorrect string\n");
2729 /* test substringData - Start of string */
2730 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
2731 ok(hr == S_OK, "ret %08x\n", hr );
2732 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2733 SysFreeString(str);
2735 /* test substringData - Middle of string */
2736 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
2737 ok(hr == S_OK, "ret %08x\n", hr );
2738 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2739 SysFreeString(str);
2741 /* test substringData - End of string */
2742 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
2743 ok(hr == S_OK, "ret %08x\n", hr );
2744 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2745 SysFreeString(str);
2747 /* test appendData */
2748 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
2749 ok(hr == S_OK, "ret %08x\n", hr );
2751 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
2752 ok(hr == S_OK, "ret %08x\n", hr );
2754 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
2755 ok(hr == S_OK, "ret %08x\n", hr );
2757 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2758 ok(hr == S_OK, "ret %08x\n", hr );
2759 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2760 SysFreeString(str);
2762 /* test insertData */
2763 str = SysAllocStringLen(NULL, 0);
2764 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
2765 ok(hr == S_OK, "ret %08x\n", hr );
2767 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
2768 ok(hr == S_OK, "ret %08x\n", hr );
2770 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
2771 ok(hr == S_OK, "ret %08x\n", hr );
2773 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
2774 ok(hr == S_OK, "ret %08x\n", hr );
2776 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
2777 ok(hr == S_OK, "ret %08x\n", hr );
2779 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
2780 ok(hr == S_OK, "ret %08x\n", hr );
2781 SysFreeString(str);
2783 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
2784 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2786 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
2787 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2789 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
2790 ok(hr == S_OK, "ret %08x\n", hr );
2792 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
2793 ok(hr == S_OK, "ret %08x\n", hr );
2795 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
2796 ok(hr == S_OK, "ret %08x\n", hr );
2798 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
2799 ok(hr == S_OK, "ret %08x\n", hr );
2800 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2801 SysFreeString(str);
2803 IXMLDOMCDATASection_Release(pCDataSec);
2806 /* Document Fragments */
2807 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
2808 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2810 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
2811 ok(hr == S_OK, "ret %08x\n", hr );
2812 if(hr == S_OK)
2814 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
2816 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
2817 ok(hr == S_OK, "ret %08x\n", hr );
2819 /* get Attribute Tests */
2820 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
2821 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2823 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2824 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
2825 ok(hr == S_FALSE, "ret %08x\n", hr );
2826 ok(pAttribs == NULL, "pAttribs != NULL\n");
2828 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
2829 ok(hr == S_OK, "ret %08x\n", hr );
2830 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
2831 SysFreeString(str);
2833 /* test next Sibling*/
2834 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
2835 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2837 pNextChild = (IXMLDOMNode *)0x1;
2838 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
2839 ok(hr == S_FALSE, "ret %08x\n", hr );
2840 ok(pNextChild == NULL, "pNextChild not NULL\n");
2842 /* test Previous Sibling*/
2843 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
2844 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2846 pNextChild = (IXMLDOMNode *)0x1;
2847 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
2848 ok(hr == S_FALSE, "ret %08x\n", hr );
2849 ok(pNextChild == NULL, "pNextChild not NULL\n");
2851 /* test get_dataType */
2852 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
2853 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2855 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
2856 ok(hr == S_FALSE, "ret %08x\n", hr );
2857 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2858 VariantClear(&v);
2860 /* test nodeTypeString */
2861 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
2862 ok(hr == S_OK, "ret %08x\n", hr );
2863 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
2864 SysFreeString(str);
2866 IXMLDOMDocumentFragment_Release(pDocFrag);
2869 /* Entity References */
2870 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
2871 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2873 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
2874 ok(hr == S_OK, "ret %08x\n", hr );
2875 if(hr == S_OK)
2877 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
2878 ok(hr == S_OK, "ret %08x\n", hr );
2880 /* get Attribute Tests */
2881 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
2882 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2884 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2885 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
2886 ok(hr == S_FALSE, "ret %08x\n", hr );
2887 ok(pAttribs == NULL, "pAttribs != NULL\n");
2889 /* test dataType */
2890 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
2891 ok(hr == S_FALSE, "ret %08x\n", hr );
2892 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2893 VariantClear(&v);
2895 /* test nodeTypeString */
2896 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
2897 ok(hr == S_OK, "ret %08x\n", hr );
2898 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
2899 SysFreeString(str);
2901 /* test get_xml*/
2902 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
2903 ok(hr == S_OK, "ret %08x\n", hr );
2904 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
2905 SysFreeString(str);
2907 IXMLDOMEntityReference_Release(pEntityRef);
2910 IXMLDOMElement_Release( pRoot );
2914 IXMLDOMDocument_Release(doc);
2916 free_bstrs();
2919 static void test_nodeTypeTests( void )
2921 IXMLDOMDocument *doc = NULL;
2922 IXMLDOMElement *pRoot;
2923 IXMLDOMElement *pElement;
2924 HRESULT hr;
2926 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2927 if( hr != S_OK )
2928 return;
2930 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2931 ok(hr == S_OK, "ret %08x\n", hr );
2932 if(hr == S_OK)
2934 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2935 ok(hr == S_OK, "ret %08x\n", hr );
2936 if(hr == S_OK)
2938 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
2939 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2941 /* Invalid Value */
2942 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
2943 ok(hr == E_FAIL, "ret %08x\n", hr );
2945 /* NOTE:
2946 * The name passed into put_dataType is case-insensitive. So many of the names
2947 * have been changed to reflect this.
2949 /* Boolean */
2950 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
2951 ok(hr == S_OK, "ret %08x\n", hr );
2952 if(hr == S_OK)
2954 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2956 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
2957 ok(hr == S_OK, "ret %08x\n", hr );
2959 IXMLDOMElement_Release(pElement);
2962 /* String */
2963 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
2964 ok(hr == S_OK, "ret %08x\n", hr );
2965 if(hr == S_OK)
2967 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2969 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
2970 ok(hr == S_OK, "ret %08x\n", hr );
2972 IXMLDOMElement_Release(pElement);
2975 /* Number */
2976 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
2977 ok(hr == S_OK, "ret %08x\n", hr );
2978 if(hr == S_OK)
2980 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2982 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
2983 ok(hr == S_OK, "ret %08x\n", hr );
2985 IXMLDOMElement_Release(pElement);
2988 /* Int */
2989 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
2990 ok(hr == S_OK, "ret %08x\n", hr );
2991 if(hr == S_OK)
2993 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2995 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
2996 ok(hr == S_OK, "ret %08x\n", hr );
2998 IXMLDOMElement_Release(pElement);
3001 /* Fixed */
3002 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3003 ok(hr == S_OK, "ret %08x\n", hr );
3004 if(hr == S_OK)
3006 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3008 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3009 ok(hr == S_OK, "ret %08x\n", hr );
3011 IXMLDOMElement_Release(pElement);
3014 /* DateTime */
3015 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3016 ok(hr == S_OK, "ret %08x\n", hr );
3017 if(hr == S_OK)
3019 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3021 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3022 ok(hr == S_OK, "ret %08x\n", hr );
3024 IXMLDOMElement_Release(pElement);
3027 /* DateTime TZ */
3028 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3029 ok(hr == S_OK, "ret %08x\n", hr );
3030 if(hr == S_OK)
3032 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3034 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3035 ok(hr == S_OK, "ret %08x\n", hr );
3037 IXMLDOMElement_Release(pElement);
3040 /* Date */
3041 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3042 ok(hr == S_OK, "ret %08x\n", hr );
3043 if(hr == S_OK)
3045 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3047 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3048 ok(hr == S_OK, "ret %08x\n", hr );
3050 IXMLDOMElement_Release(pElement);
3053 /* Time */
3054 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3055 ok(hr == S_OK, "ret %08x\n", hr );
3056 if(hr == S_OK)
3058 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3060 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3061 ok(hr == S_OK, "ret %08x\n", hr );
3063 IXMLDOMElement_Release(pElement);
3066 /* Time.tz */
3067 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3068 ok(hr == S_OK, "ret %08x\n", hr );
3069 if(hr == S_OK)
3071 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3073 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3074 ok(hr == S_OK, "ret %08x\n", hr );
3076 IXMLDOMElement_Release(pElement);
3079 /* I1 */
3080 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3081 ok(hr == S_OK, "ret %08x\n", hr );
3082 if(hr == S_OK)
3084 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3086 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3087 ok(hr == S_OK, "ret %08x\n", hr );
3089 IXMLDOMElement_Release(pElement);
3092 /* I2 */
3093 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3094 ok(hr == S_OK, "ret %08x\n", hr );
3095 if(hr == S_OK)
3097 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3099 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3100 ok(hr == S_OK, "ret %08x\n", hr );
3102 IXMLDOMElement_Release(pElement);
3105 /* I4 */
3106 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3107 ok(hr == S_OK, "ret %08x\n", hr );
3108 if(hr == S_OK)
3110 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3112 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3113 ok(hr == S_OK, "ret %08x\n", hr );
3115 IXMLDOMElement_Release(pElement);
3118 /* UI1 */
3119 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3120 ok(hr == S_OK, "ret %08x\n", hr );
3121 if(hr == S_OK)
3123 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3125 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3126 ok(hr == S_OK, "ret %08x\n", hr );
3128 IXMLDOMElement_Release(pElement);
3131 /* UI2 */
3132 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3133 ok(hr == S_OK, "ret %08x\n", hr );
3134 if(hr == S_OK)
3136 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3138 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3139 ok(hr == S_OK, "ret %08x\n", hr );
3141 IXMLDOMElement_Release(pElement);
3144 /* UI4 */
3145 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3146 ok(hr == S_OK, "ret %08x\n", hr );
3147 if(hr == S_OK)
3149 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3151 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3152 ok(hr == S_OK, "ret %08x\n", hr );
3154 IXMLDOMElement_Release(pElement);
3157 /* r4 */
3158 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3159 ok(hr == S_OK, "ret %08x\n", hr );
3160 if(hr == S_OK)
3162 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3164 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3165 ok(hr == S_OK, "ret %08x\n", hr );
3167 IXMLDOMElement_Release(pElement);
3170 /* r8 */
3171 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3172 ok(hr == S_OK, "ret %08x\n", hr );
3173 if(hr == S_OK)
3175 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3177 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3178 ok(hr == S_OK, "ret %08x\n", hr );
3180 IXMLDOMElement_Release(pElement);
3183 /* float */
3184 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3185 ok(hr == S_OK, "ret %08x\n", hr );
3186 if(hr == S_OK)
3188 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3190 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3191 ok(hr == S_OK, "ret %08x\n", hr );
3193 IXMLDOMElement_Release(pElement);
3196 /* uuid */
3197 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3198 ok(hr == S_OK, "ret %08x\n", hr );
3199 if(hr == S_OK)
3201 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3203 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3204 ok(hr == S_OK, "ret %08x\n", hr );
3206 IXMLDOMElement_Release(pElement);
3209 /* bin.hex */
3210 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3211 ok(hr == S_OK, "ret %08x\n", hr );
3212 if(hr == S_OK)
3214 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3216 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3217 ok(hr == S_OK, "ret %08x\n", hr );
3219 IXMLDOMElement_Release(pElement);
3222 /* bin.base64 */
3223 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3224 ok(hr == S_OK, "ret %08x\n", hr );
3225 if(hr == S_OK)
3227 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3229 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3230 ok(hr == S_OK, "ret %08x\n", hr );
3232 IXMLDOMElement_Release(pElement);
3235 /* Check changing types */
3236 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3237 ok(hr == S_OK, "ret %08x\n", hr );
3238 if(hr == S_OK)
3240 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3242 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3243 ok(hr == S_OK, "ret %08x\n", hr );
3245 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3246 ok(hr == S_OK, "ret %08x\n", hr );
3248 IXMLDOMElement_Release(pElement);
3251 IXMLDOMElement_Release(pRoot);
3255 IXMLDOMDocument_Release(doc);
3257 free_bstrs();
3260 static void test_DocumentSaveToDocument(void)
3262 IXMLDOMDocument *doc = NULL;
3263 IXMLDOMDocument *doc2 = NULL;
3264 IXMLDOMElement *pRoot;
3266 HRESULT hr;
3268 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3269 if( hr != S_OK )
3270 return;
3272 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3273 if( hr != S_OK )
3275 IXMLDOMDocument_Release(doc);
3276 return;
3279 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3280 ok(hr == S_OK, "ret %08x\n", hr );
3281 if(hr == S_OK)
3283 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3284 ok(hr == S_OK, "ret %08x\n", hr );
3285 if(hr == S_OK)
3287 VARIANT vDoc;
3288 BSTR sOrig;
3289 BSTR sNew;
3291 V_VT(&vDoc) = VT_UNKNOWN;
3292 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3294 hr = IXMLDOMDocument_save(doc, vDoc);
3295 ok(hr == S_OK, "ret %08x\n", hr );
3297 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3298 ok(hr == S_OK, "ret %08x\n", hr );
3300 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3301 ok(hr == S_OK, "ret %08x\n", hr );
3303 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3305 SysFreeString(sOrig);
3306 SysFreeString(sNew);
3310 IXMLDOMDocument_Release(doc2);
3311 IXMLDOMDocument_Release(doc);
3314 static void test_DocumentSaveToFile(void)
3316 IXMLDOMDocument *doc = NULL;
3317 IXMLDOMElement *pRoot;
3318 HANDLE file;
3319 char buffer[100];
3320 DWORD read = 0;
3321 HRESULT hr;
3323 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3324 if( hr != S_OK )
3325 return;
3327 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3328 ok(hr == S_OK, "ret %08x\n", hr );
3329 if(hr == S_OK)
3331 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3332 ok(hr == S_OK, "ret %08x\n", hr );
3333 if(hr == S_OK)
3335 VARIANT vFile;
3337 V_VT(&vFile) = VT_BSTR;
3338 V_BSTR(&vFile) = _bstr_("test.xml");
3340 hr = IXMLDOMDocument_save(doc, vFile);
3341 ok(hr == S_OK, "ret %08x\n", hr );
3345 IXMLDOMElement_Release(pRoot);
3346 IXMLDOMDocument_Release(doc);
3348 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3349 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3350 if(file == INVALID_HANDLE_VALUE)
3351 return;
3353 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3354 ok(read != 0, "could not read file\n");
3355 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3357 CloseHandle(file);
3358 DeleteFile("test.xml");
3361 static void test_testTransforms(void)
3363 IXMLDOMDocument *doc = NULL;
3364 IXMLDOMDocument *docSS = NULL;
3365 IXMLDOMNode *pNode;
3366 VARIANT_BOOL bSucc;
3368 HRESULT hr;
3370 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3371 if( hr != S_OK )
3372 return;
3374 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3375 if( hr != S_OK )
3377 IXMLDOMDocument_Release(doc);
3378 return;
3381 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3382 ok(hr == S_OK, "ret %08x\n", hr );
3384 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3385 ok(hr == S_OK, "ret %08x\n", hr );
3387 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3388 ok(hr == S_OK, "ret %08x\n", hr );
3389 if(hr == S_OK)
3391 BSTR bOut;
3393 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3394 ok(hr == S_OK, "ret %08x\n", hr );
3395 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3397 IXMLDOMNode_Release(pNode);
3400 IXMLDOMDocument_Release(docSS);
3401 IXMLDOMDocument_Release(doc);
3403 free_bstrs();
3406 static void test_Namespaces(void)
3408 IXMLDOMDocument2 *doc = NULL;
3409 IXMLDOMNode *pNode;
3410 IXMLDOMNode *pNode2 = NULL;
3411 VARIANT_BOOL bSucc;
3412 HRESULT hr;
3413 BSTR str;
3414 static const CHAR szNamespacesXML[] =
3415 "<?xml version=\"1.0\"?>\n"
3416 "<root xmlns:WEB='http://www.winehq.org'>\n"
3417 "<WEB:Site version=\"1.0\" />\n"
3418 "</root>";
3420 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3421 if( hr != S_OK )
3422 return;
3424 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3425 ok(hr == S_OK, "ret %08x\n", hr );
3426 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3428 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3429 ok(hr == S_OK, "ret %08x\n", hr );
3430 if(hr == S_OK)
3432 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3433 ok( hr == S_OK, "ret %08x\n", hr );
3434 ok( pNode2 != NULL, "pNode2 == NULL\n");
3436 /* Test get_prefix */
3437 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3438 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3439 /* NOTE: Need to test that arg2 gets cleared on Error. */
3441 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3442 ok( hr == S_OK, "ret %08x\n", hr );
3443 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3444 SysFreeString(str);
3446 /* Test get_namespaceURI */
3447 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3448 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3449 /* NOTE: Need to test that arg2 gets cleared on Error. */
3451 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3452 ok( hr == S_OK, "ret %08x\n", hr );
3453 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3454 SysFreeString(str);
3456 IXMLDOMNode_Release(pNode2);
3457 IXMLDOMNode_Release(pNode);
3460 IXMLDOMDocument2_Release(doc);
3462 free_bstrs();
3465 static void test_FormattingXML(void)
3467 IXMLDOMDocument2 *doc = NULL;
3468 IXMLDOMElement *pElement;
3469 VARIANT_BOOL bSucc;
3470 HRESULT hr;
3471 BSTR str;
3472 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
3473 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
3475 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3476 if( hr != S_OK )
3477 return;
3479 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
3480 ok(hr == S_OK, "ret %08x\n", hr );
3481 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3483 if(bSucc == VARIANT_TRUE)
3485 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
3486 ok(hr == S_OK, "ret %08x\n", hr );
3487 if(hr == S_OK)
3489 hr = IXMLDOMElement_get_xml(pElement, &str);
3490 ok(hr == S_OK, "ret %08x\n", hr );
3491 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
3492 SysFreeString(str);
3494 IXMLDOMElement_Release(pElement);
3498 IXMLDOMDocument2_Release(doc);
3500 free_bstrs();
3503 START_TEST(domdoc)
3505 HRESULT r;
3507 r = CoInitialize( NULL );
3508 ok( r == S_OK, "failed to init com\n");
3510 test_domdoc();
3511 test_domnode();
3512 test_refs();
3513 test_create();
3514 test_getElementsByTagName();
3515 test_get_text();
3516 test_get_childNodes();
3517 test_removeChild();
3518 test_XMLHTTP();
3519 test_IXMLDOMDocument2();
3520 test_XPath();
3521 test_cloneNode();
3522 test_xmlTypes();
3523 test_nodeTypeTests();
3524 test_DocumentSaveToDocument();
3525 test_DocumentSaveToFile();
3526 test_testTransforms();
3527 test_Namespaces();
3528 test_FormattingXML();
3530 CoUninitialize();