Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / msxml3 / tests / domdoc.c
blob97cb7728358ed7b9e4ae77d15f5f3d90836faca1
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 CHAR szTypeValueXML[] =
150 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
151 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
152 " <string>Wine</string>\n"
153 " <string2 dt:dt=\"string\">String</string2>\n"
154 " <number dt:dt=\"number\">12.44</number>\n"
155 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
156 " <int dt:dt=\"int\">-13</int>\n"
157 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
158 " <bool dt:dt=\"boolean\">1</bool>\n"
159 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
160 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
161 " <date dt:dt=\"date\">3721-11-01</date>\n"
162 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
163 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
164 " <i1 dt:dt=\"i1\">-13</i1>\n"
165 " <i2 dt:dt=\"i2\">31915</i2>\n"
166 " <i4 dt:dt=\"i4\">-312232</i4>\n"
167 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
168 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
169 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
170 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
171 " <r8 dt:dt=\"r8\">0.412</r8>\n"
172 " <float dt:dt=\"float\">41221.421</float>\n"
173 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
174 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
175 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
176 "</root>";
178 static const CHAR szBasicTransformSSXMLPart1[] =
179 "<?xml version=\"1.0\"?>"
180 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
181 "<xsl:output method=\"html\"/>\n"
182 "<xsl:template match=\"/\">"
183 "<HTML><BODY><TABLE>"
184 " <xsl:apply-templates select='document(\"";
186 static const CHAR szBasicTransformSSXMLPart2[] =
187 "\")/bottle/wine'>"
188 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
189 " </xsl:apply-templates>"
190 "</TABLE></BODY></HTML>"
191 "</xsl:template>"
192 "<xsl:template match=\"bottle\">"
193 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
194 "</xsl:template>"
195 "<xsl:template match=\"name\">"
196 " <TD><xsl:apply-templates /></TD>"
197 "</xsl:template>"
198 "<xsl:template match=\"cost\">"
199 " <TD><xsl:apply-templates /></TD>"
200 "</xsl:template>"
201 "</xsl:stylesheet>";
203 static const CHAR szBasicTransformXML[] =
204 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
206 static const CHAR szBasicTransformOutput[] =
207 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
209 static const WCHAR szNonExistentFile[] = {
210 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
212 static const WCHAR szNonExistentAttribute[] = {
213 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
215 static const WCHAR szDocument[] = {
216 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
219 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
220 static WCHAR szdl[] = { 'd','l',0 };
221 static const WCHAR szvr[] = { 'v','r',0 };
222 static const WCHAR szlc[] = { 'l','c',0 };
223 static WCHAR szbs[] = { 'b','s',0 };
224 static const WCHAR szstr1[] = { 's','t','r','1',0 };
225 static const WCHAR szstr2[] = { 's','t','r','2',0 };
226 static const WCHAR szstar[] = { '*',0 };
227 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
229 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
230 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
231 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
233 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
234 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
235 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
236 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
237 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
238 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
239 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
241 static WCHAR szAttribute[] = {'A','t','t','r',0 };
242 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
244 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
245 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
246 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
247 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
248 '!',']',']','>',0};
249 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
250 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
252 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
253 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
254 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
256 #define expect_bstr_eq_and_free(bstr, expect) { \
257 BSTR bstrExp = alloc_str_from_narrow(expect); \
258 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
259 SysFreeString(bstr); \
260 SysFreeString(bstrExp); \
263 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
265 #define ole_check(expr) { \
266 HRESULT r = expr; \
267 ok(r == S_OK, #expr " returned %x\n", r); \
270 #define ole_expect(expr, expect) { \
271 HRESULT r = expr; \
272 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
275 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
277 static BSTR alloc_str_from_narrow(const char *str)
279 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
280 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
281 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
282 return ret;
285 BSTR alloced_bstrs[256];
286 int alloced_bstrs_count = 0;
288 static BSTR _bstr_(const char *str)
290 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
291 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
292 return alloced_bstrs[alloced_bstrs_count++];
295 static void free_bstrs(void)
297 int i;
298 for (i = 0; i < alloced_bstrs_count; i++)
299 SysFreeString(alloced_bstrs[i]);
300 alloced_bstrs_count = 0;
303 static VARIANT _variantbstr_(const char *str)
305 VARIANT v;
306 V_VT(&v) = VT_BSTR;
307 V_BSTR(&v) = _bstr_(str);
308 return v;
311 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
313 for (;;)
315 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
316 while (*sRight == '\r' || *sRight == '\n') sRight++;
317 if (*sLeft != *sRight) return FALSE;
318 if (!*sLeft) return TRUE;
319 sLeft++;
320 sRight++;
324 static BOOL compareIgnoreReturnsWhitespace(BSTR sLeft, BSTR sRight)
326 /* MSXML3 inserts whitespace where as libxml doesn't. */
327 for (;;)
329 while (*sLeft == '\r' || *sLeft == '\n' || *sLeft == ' ') sLeft++;
330 while (*sRight == '\r' || *sRight == '\n' || *sRight == ' ') sRight++;
331 if (*sLeft != *sRight) return FALSE;
332 if (!*sLeft) return TRUE;
333 sLeft++;
334 sRight++;
338 static void get_str_for_type(DOMNodeType type, char *buf)
340 switch (type)
342 case NODE_ATTRIBUTE:
343 strcpy(buf, "A");
344 break;
345 case NODE_ELEMENT:
346 strcpy(buf, "E");
347 break;
348 case NODE_DOCUMENT:
349 strcpy(buf, "D");
350 break;
351 default:
352 wsprintfA(buf, "[%d]", type);
356 #define test_disp(u) _test_disp(__LINE__,u)
357 static void _test_disp(unsigned line, IUnknown *unk)
359 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
360 IDispatchEx *dispex;
361 DWORD dwProps = 0;
362 BSTR sName;
363 UINT ticnt;
364 IUnknown *pUnk;
365 HRESULT hres;
367 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
368 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
369 if(FAILED(hres))
370 return;
372 ticnt = 0xdeadbeef;
373 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
374 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
375 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
377 sName = SysAllocString( szstar );
378 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
379 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
380 SysFreeString( sName );
382 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
383 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
385 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
386 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
387 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
389 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
390 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
391 if(SUCCEEDED(hres))
392 SysFreeString(sName);
394 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
395 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
397 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
398 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
399 if(hres == S_OK && pUnk)
400 IUnknown_Release(pUnk);
402 IDispatchEx_Release(dispex);
405 static int get_node_position(IXMLDOMNode *node)
407 HRESULT r;
408 int pos = 0;
410 IXMLDOMNode_AddRef(node);
413 IXMLDOMNode *new_node;
415 pos++;
416 r = IXMLDOMNode_get_previousSibling(node, &new_node);
417 ok(SUCCEEDED(r), "get_previousSibling failed\n");
418 IXMLDOMNode_Release(node);
419 node = new_node;
420 } while (r == S_OK);
421 return pos;
424 static void node_to_string(IXMLDOMNode *node, char *buf)
426 HRESULT r = S_OK;
427 DOMNodeType type;
429 if (node == NULL)
431 lstrcpyA(buf, "(null)");
432 return;
435 IXMLDOMNode_AddRef(node);
436 while (r == S_OK)
438 IXMLDOMNode *new_node;
440 ole_check(IXMLDOMNode_get_nodeType(node, &type));
441 get_str_for_type(type, buf);
442 buf+=strlen(buf);
444 if (type == NODE_ATTRIBUTE)
446 BSTR bstr;
447 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
448 *(buf++) = '\'';
449 wsprintfA(buf, "%ws", bstr);
450 buf += strlen(buf);
451 *(buf++) = '\'';
452 SysFreeString(bstr);
454 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
456 else
458 int pos = get_node_position(node);
459 DOMNodeType parent_type = NODE_INVALID;
460 r = IXMLDOMNode_get_parentNode(node, &new_node);
462 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
463 * results we "fix" it */
464 if (r == S_OK)
465 ole_check(IXMLDOMNode_get_nodeType(new_node, &parent_type));
466 if ((parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
468 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
469 pos++;
471 wsprintf(buf, "%d", pos);
472 buf += strlen(buf);
475 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
476 IXMLDOMNode_Release(node);
477 node = new_node;
478 if (r == S_OK)
479 *(buf++) = '.';
482 *buf = 0;
485 static char *list_to_string(IXMLDOMNodeList *list)
487 static char buf[4096];
488 char *pos = buf;
489 LONG len = 0;
490 int i;
492 if (list == NULL)
494 lstrcpyA(buf, "(null)");
495 return buf;
497 ole_check(IXMLDOMNodeList_get_length(list, &len));
498 for (i = 0; i < len; i++)
500 IXMLDOMNode *node;
501 if (i > 0)
502 *(pos++) = ' ';
503 ole_check(IXMLDOMNodeList_nextNode(list, &node));
504 node_to_string(node, pos);
505 pos += strlen(pos);
506 IXMLDOMNode_Release(node);
508 *pos = 0;
509 return buf;
512 #define expect_node(node, expstr) { char str[4096]; node_to_string(node, str); ok(strcmp(str, expstr)==0, "Invalid node: %s, expected %s\n", str, expstr); }
513 #define expect_list_and_release(list, expstr) { char *str = list_to_string(list); ok(strcmp(str, expstr)==0, "Invalid node list: %s, expected %s\n", str, expstr); if (list) IXMLDOMNodeList_Release(list); }
515 static void test_domdoc( void )
517 HRESULT r;
518 IXMLDOMDocument *doc = NULL;
519 IXMLDOMParseError *error;
520 IXMLDOMElement *element = NULL;
521 IXMLDOMNode *node;
522 IXMLDOMText *nodetext = NULL;
523 IXMLDOMComment *node_comment = NULL;
524 IXMLDOMAttribute *node_attr = NULL;
525 IXMLDOMNode *nodeChild = NULL;
526 IXMLDOMProcessingInstruction *nodePI = NULL;
527 ISupportErrorInfo *support_error = NULL;
528 VARIANT_BOOL b;
529 VARIANT var;
530 BSTR str;
531 LONG code;
532 LONG nLength = 0;
534 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
535 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
536 if( r != S_OK )
537 return;
539 test_disp((IUnknown*)doc);
541 /* try some stupid things */
542 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
543 ok( r == S_FALSE, "loadXML failed\n");
545 b = VARIANT_TRUE;
546 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
547 ok( r == S_FALSE, "loadXML failed\n");
548 ok( b == VARIANT_FALSE, "failed to load XML string\n");
550 /* try to load a document from a nonexistent file */
551 b = VARIANT_TRUE;
552 str = SysAllocString( szNonExistentFile );
553 VariantInit(&var);
554 V_VT(&var) = VT_BSTR;
555 V_BSTR(&var) = str;
557 r = IXMLDOMDocument_load( doc, var, &b);
558 ok( r == S_FALSE, "load (from file) failed\n");
559 ok( b == VARIANT_FALSE, "failed to load XML file\n");
560 SysFreeString( str );
562 /* try load an empty document */
563 b = VARIANT_TRUE;
564 str = SysAllocString( szEmpty );
565 r = IXMLDOMDocument_loadXML( doc, str, &b );
566 ok( r == S_FALSE, "loadXML failed\n");
567 ok( b == VARIANT_FALSE, "failed to load XML string\n");
568 SysFreeString( str );
570 r = IXMLDOMDocument_get_async( doc, &b );
571 ok( r == S_OK, "get_async failed (%08x)\n", r);
572 ok( b == VARIANT_TRUE, "Wrong default value\n");
574 /* check that there's no document element */
575 element = NULL;
576 r = IXMLDOMDocument_get_documentElement( doc, &element );
577 ok( r == S_FALSE, "should be no document element\n");
579 /* try finding a node */
580 node = NULL;
581 str = SysAllocString( szstr1 );
582 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
583 ok( r == S_FALSE, "ret %08x\n", r );
584 SysFreeString( str );
586 b = VARIANT_TRUE;
587 str = SysAllocString( szIncomplete );
588 r = IXMLDOMDocument_loadXML( doc, str, &b );
589 ok( r == S_FALSE, "loadXML failed\n");
590 ok( b == VARIANT_FALSE, "failed to load XML string\n");
591 SysFreeString( str );
593 /* check that there's no document element */
594 element = (IXMLDOMElement*)1;
595 r = IXMLDOMDocument_get_documentElement( doc, &element );
596 ok( r == S_FALSE, "should be no document element\n");
597 ok( element == NULL, "Element should be NULL\n");
599 /* try to load something valid */
600 b = VARIANT_FALSE;
601 str = SysAllocString( szComplete1 );
602 r = IXMLDOMDocument_loadXML( doc, str, &b );
603 ok( r == S_OK, "loadXML failed\n");
604 ok( b == VARIANT_TRUE, "failed to load XML string\n");
605 SysFreeString( str );
607 /* check if nodename is correct */
608 r = IXMLDOMDocument_get_nodeName( doc, NULL );
609 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
611 /* content doesn't matter here */
612 str = NULL;
613 r = IXMLDOMDocument_get_nodeName( doc, &str );
614 ok ( r == S_OK, "get_nodeName wrong code\n");
615 ok ( str != NULL, "str is null\n");
616 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
617 SysFreeString( str );
619 /* test put_text */
620 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
621 ok( r == E_FAIL, "ret %08x\n", r );
623 /* check that there's a document element */
624 element = NULL;
625 r = IXMLDOMDocument_get_documentElement( doc, &element );
626 ok( r == S_OK, "should be a document element\n");
627 if( element )
629 IObjectIdentity *ident;
630 BSTR tag = NULL;
632 test_disp((IUnknown*)element);
634 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (LPVOID*)&ident );
635 ok( r == E_NOINTERFACE, "ret %08x\n", r);
637 /* check if the tag is correct */
638 r = IXMLDOMElement_get_tagName( element, &tag );
639 ok( r == S_OK, "couldn't get tag name\n");
640 ok( tag != NULL, "tag was null\n");
641 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
642 SysFreeString( tag );
644 /* figure out what happens if we try to reload the document */
645 str = SysAllocString( szComplete2 );
646 r = IXMLDOMDocument_loadXML( doc, str, &b );
647 ok( r == S_OK, "loadXML failed\n");
648 ok( b == VARIANT_TRUE, "failed to load XML string\n");
649 SysFreeString( str );
651 /* check if the tag is still correct */
652 tag = NULL;
653 r = IXMLDOMElement_get_tagName( element, &tag );
654 ok( r == S_OK, "couldn't get tag name\n");
655 ok( tag != NULL, "tag was null\n");
656 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
657 SysFreeString( tag );
659 IXMLDOMElement_Release( element );
660 element = NULL;
663 /* as soon as we call loadXML again, the document element will disappear */
664 b = 2;
665 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
666 ok( r == S_FALSE, "loadXML failed\n");
667 ok( b == 2, "variant modified\n");
668 r = IXMLDOMDocument_get_documentElement( doc, &element );
669 ok( r == S_FALSE, "should be no document element\n");
671 /* try to load something else simple and valid */
672 b = VARIANT_FALSE;
673 str = SysAllocString( szComplete3 );
674 r = IXMLDOMDocument_loadXML( doc, str, &b );
675 ok( r == S_OK, "loadXML failed\n");
676 ok( b == VARIANT_TRUE, "failed to load XML string\n");
677 SysFreeString( str );
679 /* try something a little more complicated */
680 b = FALSE;
681 str = SysAllocString( szComplete4 );
682 r = IXMLDOMDocument_loadXML( doc, str, &b );
683 ok( r == S_OK, "loadXML failed\n");
684 ok( b == VARIANT_TRUE, "failed to load XML string\n");
685 SysFreeString( str );
687 r = IXMLDOMDocument_get_parseError( doc, &error );
688 ok( r == S_OK, "returns %08x\n", r );
690 r = IXMLDOMParseError_get_errorCode( error, &code );
691 ok( r == S_FALSE, "returns %08x\n", r );
692 ok( code == 0, "code %d\n", code );
693 IXMLDOMParseError_Release( error );
695 /* test createTextNode */
696 str = SysAllocString( szOpen );
697 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
698 ok( r == E_INVALIDARG, "returns %08x\n", r );
699 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
700 ok( r == S_OK, "returns %08x\n", r );
701 SysFreeString( str );
702 if(nodetext)
704 IXMLDOMNamedNodeMap *pAttribs;
706 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (LPVOID*)&element);
707 ok(r == E_NOINTERFACE, "ret %08x\n", r );
709 /* Text Last Child Checks */
710 r = IXMLDOMText_get_lastChild(nodetext, NULL);
711 ok(r == E_INVALIDARG, "ret %08x\n", r );
713 nodeChild = (IXMLDOMNode*)0x1;
714 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
715 ok(r == S_FALSE, "ret %08x\n", r );
716 ok(nodeChild == NULL, "nodeChild not NULL\n");
718 /* test get_attributes */
719 r = IXMLDOMText_get_attributes( nodetext, NULL );
720 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
722 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
723 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
724 ok(r == S_FALSE, "ret %08x\n", r );
725 ok( pAttribs == NULL, "pAttribs not NULL\n");
727 /* test get_dataType */
728 r = IXMLDOMText_get_dataType(nodetext, &var);
729 ok(r == S_FALSE, "ret %08x\n", r );
730 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
731 VariantClear(&var);
733 /* test length property */
734 r = IXMLDOMText_get_length(nodetext, NULL);
735 ok(r == E_INVALIDARG, "ret %08x\n", r );
737 r = IXMLDOMText_get_length(nodetext, &nLength);
738 ok(r == S_OK, "ret %08x\n", r );
739 ok(nLength == 4, "expected 4 got %d\n", nLength);
741 /* test nodeTypeString */
742 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
743 ok(r == S_OK, "ret %08x\n", r );
744 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
745 SysFreeString(str);
747 /* put data Tests */
748 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
749 ok(r == S_OK, "ret %08x\n", r );
751 /* get data Tests */
752 r = IXMLDOMText_get_data(nodetext, &str);
753 ok(r == S_OK, "ret %08x\n", r );
754 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
755 SysFreeString(str);
757 /* Confirm XML text is good */
758 r = IXMLDOMText_get_xml(nodetext, &str);
759 ok(r == S_OK, "ret %08x\n", r );
760 ok( !lstrcmpW( str, _bstr_("This &amp;is a ; test &lt;&gt;\\") ), "incorrect xml string\n");
761 SysFreeString(str);
763 /* Confirm we get the put_data Text back */
764 r = IXMLDOMText_get_text(nodetext, &str);
765 ok(r == S_OK, "ret %08x\n", r );
766 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
767 SysFreeString(str);
769 /* test substringData */
770 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
771 ok(r == E_INVALIDARG, "ret %08x\n", r );
773 /* test substringData - Invalid offset */
774 str = (BSTR)&szElement;
775 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
776 ok(r == E_INVALIDARG, "ret %08x\n", r );
777 ok( str == NULL, "incorrect string\n");
779 /* test substringData - Invalid offset */
780 str = (BSTR)&szElement;
781 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
782 ok(r == S_FALSE, "ret %08x\n", r );
783 ok( str == NULL, "incorrect string\n");
785 /* test substringData - Invalid size */
786 str = (BSTR)&szElement;
787 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
788 ok(r == E_INVALIDARG, "ret %08x\n", r );
789 ok( str == NULL, "incorrect string\n");
791 /* test substringData - Invalid size */
792 str = (BSTR)&szElement;
793 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
794 ok(r == S_FALSE, "ret %08x\n", r );
795 ok( str == NULL, "incorrect string\n");
797 /* test substringData - Start of string */
798 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
799 ok(r == S_OK, "ret %08x\n", r );
800 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
801 SysFreeString(str);
803 /* test substringData - Middle of string */
804 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
805 ok(r == S_OK, "ret %08x\n", r );
806 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
807 SysFreeString(str);
809 /* test substringData - End of string */
810 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
811 ok(r == S_OK, "ret %08x\n", r );
812 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
813 SysFreeString(str);
815 /* test appendData */
816 r = IXMLDOMText_appendData(nodetext, NULL);
817 ok(r == S_OK, "ret %08x\n", r );
819 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
820 ok(r == S_OK, "ret %08x\n", r );
822 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
823 ok(r == S_OK, "ret %08x\n", r );
825 r = IXMLDOMText_get_text(nodetext, &str);
826 ok(r == S_OK, "ret %08x\n", r );
827 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
828 SysFreeString(str);
830 /* test insertData */
831 str = SysAllocStringLen(NULL, 0);
832 r = IXMLDOMText_insertData(nodetext, -1, str);
833 ok(r == S_OK, "ret %08x\n", r );
835 r = IXMLDOMText_insertData(nodetext, -1, NULL);
836 ok(r == S_OK, "ret %08x\n", r );
838 r = IXMLDOMText_insertData(nodetext, 1000, str);
839 ok(r == S_OK, "ret %08x\n", r );
841 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
842 ok(r == S_OK, "ret %08x\n", r );
844 r = IXMLDOMText_insertData(nodetext, 0, NULL);
845 ok(r == S_OK, "ret %08x\n", r );
847 r = IXMLDOMText_insertData(nodetext, 0, str);
848 ok(r == S_OK, "ret %08x\n", r );
849 SysFreeString(str);
851 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
852 ok(r == E_INVALIDARG, "ret %08x\n", r );
854 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
855 ok(r == E_INVALIDARG, "ret %08x\n", r );
857 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
858 ok(r == S_OK, "ret %08x\n", r );
860 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
861 ok(r == S_OK, "ret %08x\n", r );
863 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
864 ok(r == S_OK, "ret %08x\n", r );
866 r = IXMLDOMText_get_text(nodetext, &str);
867 ok(r == S_OK, "ret %08x\n", r );
868 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
869 SysFreeString(str);
871 /* test put_data */
872 V_VT(&var) = VT_BSTR;
873 V_BSTR(&var) = SysAllocString(szstr1);
874 r = IXMLDOMText_put_nodeValue(nodetext, var);
875 ok(r == S_OK, "ret %08x\n", r );
876 VariantClear(&var);
878 r = IXMLDOMText_get_text(nodetext, &str);
879 ok(r == S_OK, "ret %08x\n", r );
880 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string\n");
881 SysFreeString(str);
883 /* test put_data */
884 V_VT(&var) = VT_I4;
885 V_I4(&var) = 99;
886 r = IXMLDOMText_put_nodeValue(nodetext, var);
887 ok(r == S_OK, "ret %08x\n", r );
888 VariantClear(&var);
890 r = IXMLDOMText_get_text(nodetext, &str);
891 ok(r == S_OK, "ret %08x\n", r );
892 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string\n");
893 SysFreeString(str);
895 IXMLDOMText_Release( nodetext );
898 /* test Create Comment */
899 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
900 ok( r == E_INVALIDARG, "returns %08x\n", r );
901 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
902 ok( r == S_OK, "returns %08x\n", r );
903 if(node_comment)
905 /* Last Child Checks */
906 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
907 ok(r == E_INVALIDARG, "ret %08x\n", r );
909 nodeChild = (IXMLDOMNode*)0x1;
910 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
911 ok(r == S_FALSE, "ret %08x\n", r );
912 ok(nodeChild == NULL, "pLastChild not NULL\n");
914 IXMLDOMComment_Release( node_comment );
917 /* test Create Attribute */
918 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
919 ok( r == E_INVALIDARG, "returns %08x\n", r );
920 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
921 ok( r == S_OK, "returns %08x\n", r );
922 IXMLDOMText_Release( node_attr);
924 /* test Processing Instruction */
925 str = SysAllocStringLen(NULL, 0);
926 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
927 ok( r == E_INVALIDARG, "returns %08x\n", r );
928 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
929 ok( r == E_FAIL, "returns %08x\n", r );
930 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
931 ok( r == E_FAIL, "returns %08x\n", r );
932 SysFreeString(str);
934 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
935 ok( r == S_OK, "returns %08x\n", r );
936 if(nodePI)
938 /* Last Child Checks */
939 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
940 ok(r == E_INVALIDARG, "ret %08x\n", r );
942 nodeChild = (IXMLDOMNode*)0x1;
943 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
944 ok(r == S_FALSE, "ret %08x\n", r );
945 ok(nodeChild == NULL, "nodeChild not NULL\n");
947 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
948 ok(r == S_FALSE, "ret %08x\n", r );
949 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
950 VariantClear(&var);
952 /* test nodeName */
953 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
954 ok(r == S_OK, "ret %08x\n", r );
955 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
956 SysFreeString(str);
958 /* test Target */
959 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
960 ok(r == S_OK, "ret %08x\n", r );
961 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
962 SysFreeString(str);
964 /* test nodeTypeString */
965 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
966 ok(r == S_OK, "ret %08x\n", r );
967 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
968 SysFreeString(str);
970 /* test get_nodeValue */
971 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
972 ok(r == S_OK, "ret %08x\n", r );
973 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
974 VariantClear(&var);
976 /* test get_data */
977 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
978 ok(r == S_OK, "ret %08x\n", r );
979 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
980 SysFreeString(str);
982 /* test put_data */
983 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
984 ok(r == E_FAIL, "ret %08x\n", r );
986 /* test put_data */
987 V_VT(&var) = VT_BSTR;
988 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
989 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
990 ok(r == E_FAIL, "ret %08x\n", r );
991 VariantClear(&var);
993 /* test get nodeName */
994 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
995 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
996 ok(r == S_OK, "ret %08x\n", r );
997 SysFreeString(str);
999 IXMLDOMProcessingInstruction_Release(nodePI);
1002 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1003 ok( r == S_OK, "ret %08x\n", r );
1004 if(r == S_OK)
1006 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
1007 todo_wine ok( r == S_OK, "ret %08x\n", r );
1008 ISupportErrorInfo_Release( support_error );
1011 r = IXMLDOMDocument_Release( doc );
1012 ok( r == 0, "document ref count incorrect\n");
1014 free_bstrs();
1017 static void test_domnode( void )
1019 HRESULT r;
1020 IXMLDOMDocument *doc = NULL, *owner = NULL;
1021 IXMLDOMElement *element = NULL;
1022 IXMLDOMNamedNodeMap *map = NULL;
1023 IXMLDOMNode *node = NULL, *next = NULL;
1024 IXMLDOMNodeList *list = NULL;
1025 IXMLDOMAttribute *attr = NULL;
1026 DOMNodeType type = NODE_INVALID;
1027 VARIANT_BOOL b;
1028 BSTR str;
1029 VARIANT var;
1030 LONG count;
1032 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1033 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1034 if( r != S_OK )
1035 return;
1036 if (!doc) {
1037 ok( FALSE, "no document\n");
1038 return;
1041 b = FALSE;
1042 str = SysAllocString( szComplete4 );
1043 r = IXMLDOMDocument_loadXML( doc, str, &b );
1044 ok( r == S_OK, "loadXML failed\n");
1045 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1046 SysFreeString( str );
1048 b = 1;
1049 r = IXMLDOMNode_hasChildNodes( doc, &b );
1050 ok( r == S_OK, "hasChildNoes bad return\n");
1051 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1053 r = IXMLDOMDocument_get_documentElement( doc, &element );
1054 ok( r == S_OK, "should be a document element\n");
1055 ok( element != NULL, "should be an element\n");
1057 VariantInit(&var);
1058 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1060 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1061 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1063 r = IXMLDOMNode_get_nodeValue( doc, &var );
1064 ok( r == S_FALSE, "nextNode returned wrong code\n");
1065 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1066 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1068 if (element)
1070 owner = NULL;
1071 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1072 ok( r == S_OK, "get_ownerDocument return code\n");
1073 ok( owner != doc, "get_ownerDocument return\n");
1074 IXMLDOMDocument_Release(owner);
1076 type = NODE_INVALID;
1077 r = IXMLDOMNode_get_nodeType( element, &type);
1078 ok( r == S_OK, "getNamedItem returned wrong code\n");
1079 ok( type == NODE_ELEMENT, "node not an element\n");
1081 str = NULL;
1082 r = IXMLDOMNode_get_baseName( element, &str );
1083 ok( r == S_OK, "get_baseName returned wrong code\n");
1084 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1085 SysFreeString(str);
1087 /* check if nodename is correct */
1088 r = IXMLDOMElement_get_nodeName( element, NULL );
1089 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1091 /* content doesn't matter here */
1092 str = NULL;
1093 r = IXMLDOMElement_get_nodeName( element, &str );
1094 ok ( r == S_OK, "get_nodeName wrong code\n");
1095 ok ( str != NULL, "str is null\n");
1096 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1097 SysFreeString( str );
1099 str = SysAllocString( szNonExistentFile );
1100 V_VT(&var) = VT_I4;
1101 V_I4(&var) = 0x1234;
1102 r = IXMLDOMElement_getAttribute( element, str, &var );
1103 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1104 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1105 VariantClear(&var);
1107 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1108 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1110 attr = (IXMLDOMAttribute*)0xdeadbeef;
1111 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1112 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1113 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1114 SysFreeString( str );
1116 attr = (IXMLDOMAttribute*)0xdeadbeef;
1117 str = SysAllocString( szNonExistentAttribute );
1118 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1119 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1120 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1121 SysFreeString( str );
1123 str = SysAllocString( szdl );
1124 V_VT(&var) = VT_I4;
1125 V_I4(&var) = 0x1234;
1126 r = IXMLDOMElement_getAttribute( element, str, &var );
1127 ok( r == S_OK, "getAttribute ret %08x\n", r );
1128 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1129 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1130 VariantClear( &var );
1132 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1133 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1135 r = IXMLDOMElement_getAttribute( element, str, NULL );
1136 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1138 attr = NULL;
1139 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1140 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1141 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1142 if(attr)
1143 IXMLDOMAttribute_Release(attr);
1145 SysFreeString( str );
1147 r = IXMLDOMElement_get_attributes( element, &map );
1148 ok( r == S_OK, "get_attributes returned wrong code\n");
1149 ok( map != NULL, "should be attributes\n");
1151 b = 1;
1152 r = IXMLDOMNode_hasChildNodes( element, &b );
1153 ok( r == S_OK, "hasChildNoes bad return\n");
1154 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1156 else
1157 ok( FALSE, "no element\n");
1159 if (map)
1161 ISupportErrorInfo *support_error;
1162 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1163 ok( r == S_OK, "ret %08x\n", r );
1165 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1166 todo_wine
1168 ok( r == S_OK, "ret %08x\n", r );
1170 ISupportErrorInfo_Release( support_error );
1172 str = SysAllocString( szdl );
1173 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1174 ok( r == S_OK, "getNamedItem returned wrong code\n");
1175 ok( node != NULL, "should be attributes\n");
1176 IXMLDOMNode_Release(node);
1177 SysFreeString( str );
1179 str = SysAllocString( szdl );
1180 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1181 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1182 SysFreeString( str );
1184 /* something that isn't in szComplete4 */
1185 str = SysAllocString( szOpen );
1186 node = (IXMLDOMNode *) 1;
1187 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1188 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1189 ok( node == NULL, "getNamedItem should have returned NULL\n");
1190 SysFreeString( str );
1192 /* test indexed access of attributes */
1193 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1194 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1196 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1197 ok ( r == S_OK, "get_length wrong code\n");
1198 ok ( count == 1, "get_length != 1\n");
1200 node = NULL;
1201 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1202 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1203 ok ( node == NULL, "there is no node\n");
1205 node = NULL;
1206 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1207 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1208 ok ( node == NULL, "there is no attribute\n");
1210 node = NULL;
1211 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1212 ok ( r == S_OK, "get_item (0) wrong code\n");
1213 ok ( node != NULL, "should be attribute\n");
1215 r = IXMLDOMNode_get_nodeName( node, NULL );
1216 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1218 /* content doesn't matter here */
1219 str = NULL;
1220 r = IXMLDOMNode_get_nodeName( node, &str );
1221 ok ( r == S_OK, "get_nodeName wrong code\n");
1222 ok ( str != NULL, "str is null\n");
1223 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1224 SysFreeString( str );
1226 /* test sequential access of attributes */
1227 node = NULL;
1228 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1229 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1230 ok ( node != NULL, "nextNode, should be attribute\n");
1232 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1233 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1234 ok ( node == NULL, "nextNode, there is no attribute\n");
1236 r = IXMLDOMNamedNodeMap_reset( map );
1237 ok ( r == S_OK, "reset should return S_OK\n");
1239 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1240 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1241 ok ( node != NULL, "nextNode, should be attribute\n");
1243 else
1244 ok( FALSE, "no map\n");
1246 if (node)
1248 type = NODE_INVALID;
1249 r = IXMLDOMNode_get_nodeType( node, &type);
1250 ok( r == S_OK, "getNamedItem returned wrong code\n");
1251 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1253 str = NULL;
1254 r = IXMLDOMNode_get_baseName( node, NULL );
1255 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1257 str = NULL;
1258 r = IXMLDOMNode_get_baseName( node, &str );
1259 ok( r == S_OK, "get_baseName returned wrong code\n");
1260 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1261 SysFreeString( str );
1263 r = IXMLDOMNode_get_nodeValue( node, &var );
1264 ok( r == S_OK, "returns %08x\n", r );
1265 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1266 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1267 VariantClear(&var);
1269 r = IXMLDOMNode_get_childNodes( node, NULL );
1270 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1272 r = IXMLDOMNode_get_childNodes( node, &list );
1273 ok( r == S_OK, "get_childNodes returned wrong code\n");
1275 if (list)
1277 r = IXMLDOMNodeList_nextNode( list, &next );
1278 ok( r == S_OK, "nextNode returned wrong code\n");
1280 else
1281 ok( FALSE, "no childlist\n");
1283 if (next)
1285 b = 1;
1286 r = IXMLDOMNode_hasChildNodes( next, &b );
1287 ok( r == S_FALSE, "hasChildNoes bad return\n");
1288 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1290 type = NODE_INVALID;
1291 r = IXMLDOMNode_get_nodeType( next, &type);
1292 ok( r == S_OK, "getNamedItem returned wrong code\n");
1293 ok( type == NODE_TEXT, "node not text\n");
1295 str = (BSTR) 1;
1296 r = IXMLDOMNode_get_baseName( next, &str );
1297 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1298 ok( str == NULL, "basename was wrong\n");
1299 SysFreeString(str);
1301 else
1302 ok( FALSE, "no next\n");
1304 if (next)
1305 IXMLDOMNode_Release( next );
1306 next = NULL;
1307 if (list)
1308 IXMLDOMNodeList_Release( list );
1309 list = NULL;
1310 if (node)
1311 IXMLDOMNode_Release( node );
1313 else
1314 ok( FALSE, "no node\n");
1315 node = NULL;
1317 if (map)
1318 IXMLDOMNamedNodeMap_Release( map );
1320 /* now traverse the tree from the root element */
1321 if (element)
1323 r = IXMLDOMNode_get_childNodes( element, &list );
1324 ok( r == S_OK, "get_childNodes returned wrong code\n");
1326 /* using get_item for child list doesn't advance the position */
1327 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1328 expect_node(node, "E2.E2.D1");
1329 IXMLDOMNode_Release(node);
1330 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1331 expect_node(node, "E1.E2.D1");
1332 IXMLDOMNode_Release(node);
1333 ole_check(IXMLDOMNodeList_reset(list));
1335 IXMLDOMNodeList_AddRef(list);
1336 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1337 ole_check(IXMLDOMNodeList_reset(list));
1339 node = (void*)0xdeadbeef;
1340 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1341 ok( r == S_FALSE, "ret %08x\n", r );
1342 ok( node == NULL, "node %p\n", node );
1343 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1344 ok( r == S_OK, "ret %08x\n", r );
1345 r = IXMLDOMNode_Release( node );
1346 ok( r == 0, "ret %08x\n", r );
1348 else
1349 ok( FALSE, "no element\n");
1351 if (list)
1353 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1354 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1356 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1357 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1359 r = IXMLDOMNodeList_get_length(list, NULL);
1360 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1362 r = IXMLDOMNodeList_get_length( list, &count );
1363 ok( r == S_OK, "get_length returns %08x\n", r );
1364 ok( count == 4, "get_length got %d\n", count );
1366 r = IXMLDOMNodeList_nextNode(list, NULL);
1367 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1369 r = IXMLDOMNodeList_nextNode( list, &node );
1370 ok( r == S_OK, "nextNode returned wrong code\n");
1372 else
1373 ok( FALSE, "no list\n");
1375 if (node)
1377 type = NODE_INVALID;
1378 r = IXMLDOMNode_get_nodeType( node, &type);
1379 ok( r == S_OK, "getNamedItem returned wrong code\n");
1380 ok( type == NODE_ELEMENT, "node not text\n");
1382 VariantInit(&var);
1383 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1384 r = IXMLDOMNode_get_nodeValue( node, &var );
1385 ok( r == S_FALSE, "nextNode returned wrong code\n");
1386 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1387 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1389 r = IXMLDOMNode_hasChildNodes( node, NULL );
1390 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1392 b = 1;
1393 r = IXMLDOMNode_hasChildNodes( node, &b );
1394 ok( r == S_OK, "hasChildNoes bad return\n");
1395 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1397 str = NULL;
1398 r = IXMLDOMNode_get_baseName( node, &str );
1399 ok( r == S_OK, "get_baseName returned wrong code\n");
1400 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1401 SysFreeString(str);
1403 else
1404 ok( FALSE, "no node\n");
1406 if (node)
1407 IXMLDOMNode_Release( node );
1408 if (list)
1409 IXMLDOMNodeList_Release( list );
1410 if (element)
1411 IXMLDOMElement_Release( element );
1413 b = FALSE;
1414 str = SysAllocString( szComplete5 );
1415 r = IXMLDOMDocument_loadXML( doc, str, &b );
1416 ok( r == S_OK, "loadXML failed\n");
1417 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1418 SysFreeString( str );
1420 b = 1;
1421 r = IXMLDOMNode_hasChildNodes( doc, &b );
1422 ok( r == S_OK, "hasChildNoes bad return\n");
1423 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1425 r = IXMLDOMDocument_get_documentElement( doc, &element );
1426 ok( r == S_OK, "should be a document element\n");
1427 ok( element != NULL, "should be an element\n");
1429 if (element)
1431 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1432 BSTR tag = NULL;
1434 /* check if the tag is correct */
1435 r = IXMLDOMElement_get_tagName( element, &tag );
1436 ok( r == S_OK, "couldn't get tag name\n");
1437 ok( tag != NULL, "tag was null\n");
1438 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1439 SysFreeString( tag );
1442 if (element)
1443 IXMLDOMElement_Release( element );
1444 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1447 static void test_refs(void)
1449 HRESULT r;
1450 BSTR str;
1451 VARIANT_BOOL b;
1452 IXMLDOMDocument *doc = NULL;
1453 IXMLDOMElement *element = NULL;
1454 IXMLDOMNode *node = NULL, *node2;
1455 IXMLDOMNodeList *node_list = NULL;
1456 LONG ref;
1457 IUnknown *unk, *unk2;
1459 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1460 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1461 if( r != S_OK )
1462 return;
1463 ref = IXMLDOMDocument_Release(doc);
1464 ok( ref == 0, "ref %d\n", ref);
1466 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1467 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1468 if( r != S_OK )
1469 return;
1471 str = SysAllocString( szComplete4 );
1472 r = IXMLDOMDocument_loadXML( doc, str, &b );
1473 ok( r == S_OK, "loadXML failed\n");
1474 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1475 SysFreeString( str );
1477 ref = IXMLDOMDocument_AddRef( doc );
1478 ok( ref == 2, "ref %d\n", ref );
1479 ref = IXMLDOMDocument_AddRef( doc );
1480 ok( ref == 3, "ref %d\n", ref );
1481 IXMLDOMDocument_Release( doc );
1482 IXMLDOMDocument_Release( doc );
1484 r = IXMLDOMDocument_get_documentElement( doc, &element );
1485 ok( r == S_OK, "should be a document element\n");
1486 ok( element != NULL, "should be an element\n");
1488 ref = IXMLDOMDocument_AddRef( doc );
1489 ok( ref == 2, "ref %d\n", ref );
1490 IXMLDOMDocument_Release( doc );
1492 r = IXMLDOMElement_get_childNodes( element, &node_list );
1493 ok( r == S_OK, "rets %08x\n", r);
1495 ref = IXMLDOMNodeList_AddRef( node_list );
1496 ok( ref == 2, "ref %d\n", ref );
1497 IXMLDOMNodeList_Release( node_list );
1499 IXMLDOMNodeList_get_item( node_list, 0, &node );
1500 ok( r == S_OK, "rets %08x\n", r);
1502 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1503 ok( r == S_OK, "rets %08x\n", r);
1505 ref = IXMLDOMNode_AddRef( node );
1506 ok( ref == 2, "ref %d\n", ref );
1507 IXMLDOMNode_Release( node );
1509 ref = IXMLDOMNode_Release( node );
1510 ok( ref == 0, "ref %d\n", ref );
1511 ref = IXMLDOMNode_Release( node2 );
1512 ok( ref == 0, "ref %d\n", ref );
1514 ref = IXMLDOMNodeList_Release( node_list );
1515 ok( ref == 0, "ref %d\n", ref );
1517 ok( node != node2, "node %p node2 %p\n", node, node2 );
1519 ref = IXMLDOMDocument_Release( doc );
1520 ok( ref == 0, "ref %d\n", ref );
1522 ref = IXMLDOMElement_AddRef( element );
1523 todo_wine {
1524 ok( ref == 3, "ref %d\n", ref );
1526 IXMLDOMElement_Release( element );
1528 /* IUnknown must be unique however we obtain it */
1529 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1530 ok( r == S_OK, "rets %08x\n", r );
1531 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1532 ok( r == S_OK, "rets %08x\n", r );
1533 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1534 ok( r == S_OK, "rets %08x\n", r );
1535 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1537 IUnknown_Release( unk2 );
1538 IUnknown_Release( unk );
1539 IXMLDOMNode_Release( node );
1541 IXMLDOMElement_Release( element );
1545 static void test_create(void)
1547 static const WCHAR szOne[] = {'1',0};
1548 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1549 HRESULT r;
1550 VARIANT var;
1551 BSTR str, name;
1552 IXMLDOMDocument *doc;
1553 IXMLDOMElement *element;
1554 IXMLDOMNode *root, *node, *child;
1555 IXMLDOMNamedNodeMap *attr_map;
1556 IUnknown *unk;
1557 LONG ref;
1558 LONG num;
1560 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1561 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1562 if( r != S_OK )
1563 return;
1565 V_VT(&var) = VT_I1;
1566 V_I1(&var) = NODE_ELEMENT;
1567 str = SysAllocString( szlc );
1568 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1569 ok( r == S_OK, "returns %08x\n", r );
1570 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1572 V_VT(&var) = VT_R4;
1573 V_R4(&var) = NODE_ELEMENT;
1574 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1575 ok( r == S_OK, "returns %08x\n", r );
1576 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1578 V_VT(&var) = VT_BSTR;
1579 V_BSTR(&var) = SysAllocString( szOne );
1580 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1581 ok( r == S_OK, "returns %08x\n", r );
1582 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1583 VariantClear(&var);
1585 V_VT(&var) = VT_BSTR;
1586 V_BSTR(&var) = SysAllocString( szOneGarbage );
1587 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1588 ok( r == E_INVALIDARG, "returns %08x\n", r );
1589 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1590 VariantClear(&var);
1592 V_VT(&var) = VT_I4;
1593 V_I4(&var) = NODE_ELEMENT;
1594 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1595 ok( r == S_OK, "returns %08x\n", r );
1596 r = IXMLDOMDocument_appendChild( doc, node, &root );
1597 ok( r == S_OK, "returns %08x\n", r );
1598 ok( node == root, "%p %p\n", node, root );
1600 ref = IXMLDOMNode_AddRef( node );
1601 ok(ref == 3, "ref %d\n", ref);
1602 IXMLDOMNode_Release( node );
1604 ref = IXMLDOMNode_Release( node );
1605 ok(ref == 1, "ref %d\n", ref);
1606 SysFreeString( str );
1608 V_VT(&var) = VT_I4;
1609 V_I4(&var) = NODE_ELEMENT;
1610 str = SysAllocString( szbs );
1611 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1612 ok( r == S_OK, "returns %08x\n", r );
1613 SysFreeString( str );
1615 ref = IXMLDOMNode_AddRef( node );
1616 ok(ref == 2, "ref = %d\n", ref);
1617 IXMLDOMNode_Release( node );
1619 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1620 ok( r == S_OK, "returns %08x\n", r );
1622 ref = IXMLDOMNode_AddRef( unk );
1623 ok(ref == 3, "ref = %d\n", ref);
1624 IXMLDOMNode_Release( unk );
1626 V_VT(&var) = VT_EMPTY;
1627 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1628 ok( r == S_OK, "returns %08x\n", r );
1629 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1630 IXMLDOMNode_Release( child );
1631 IUnknown_Release( unk );
1634 V_VT(&var) = VT_NULL;
1635 V_DISPATCH(&var) = (IDispatch*)node;
1636 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1637 ok( r == S_OK, "returns %08x\n", r );
1638 ok( node == child, "%p %p\n", node, child );
1639 IXMLDOMNode_Release( child );
1642 V_VT(&var) = VT_NULL;
1643 V_DISPATCH(&var) = (IDispatch*)node;
1644 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1645 ok( r == S_OK, "returns %08x\n", r );
1646 IXMLDOMNode_Release( node );
1648 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1649 ok( r == S_OK, "returns %08x\n", r );
1651 r = IXMLDOMElement_get_attributes( element, &attr_map );
1652 ok( r == S_OK, "returns %08x\n", r );
1653 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1654 ok( r == S_OK, "returns %08x\n", r );
1655 ok( num == 0, "num %d\n", num );
1656 IXMLDOMNamedNodeMap_Release( attr_map );
1658 V_VT(&var) = VT_BSTR;
1659 V_BSTR(&var) = SysAllocString( szstr1 );
1660 name = SysAllocString( szdl );
1661 r = IXMLDOMElement_setAttribute( element, name, var );
1662 ok( r == S_OK, "returns %08x\n", r );
1663 r = IXMLDOMElement_get_attributes( element, &attr_map );
1664 ok( r == S_OK, "returns %08x\n", r );
1665 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1666 ok( r == S_OK, "returns %08x\n", r );
1667 ok( num == 1, "num %d\n", num );
1668 IXMLDOMNamedNodeMap_Release( attr_map );
1669 VariantClear(&var);
1671 V_VT(&var) = VT_BSTR;
1672 V_BSTR(&var) = SysAllocString( szstr2 );
1673 r = IXMLDOMElement_setAttribute( element, name, var );
1674 ok( r == S_OK, "returns %08x\n", r );
1675 r = IXMLDOMElement_get_attributes( element, &attr_map );
1676 ok( r == S_OK, "returns %08x\n", r );
1677 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1678 ok( r == S_OK, "returns %08x\n", r );
1679 ok( num == 1, "num %d\n", num );
1680 IXMLDOMNamedNodeMap_Release( attr_map );
1681 VariantClear(&var);
1682 r = IXMLDOMElement_getAttribute( element, name, &var );
1683 ok( r == S_OK, "returns %08x\n", r );
1684 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1685 VariantClear(&var);
1686 SysFreeString(name);
1688 V_VT(&var) = VT_BSTR;
1689 V_BSTR(&var) = SysAllocString( szstr1 );
1690 name = SysAllocString( szlc );
1691 r = IXMLDOMElement_setAttribute( element, name, var );
1692 ok( r == S_OK, "returns %08x\n", r );
1693 r = IXMLDOMElement_get_attributes( element, &attr_map );
1694 ok( r == S_OK, "returns %08x\n", r );
1695 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1696 ok( r == S_OK, "returns %08x\n", r );
1697 ok( num == 2, "num %d\n", num );
1698 IXMLDOMNamedNodeMap_Release( attr_map );
1699 VariantClear(&var);
1700 SysFreeString(name);
1702 V_VT(&var) = VT_I4;
1703 V_I4(&var) = 10;
1704 name = SysAllocString( szbs );
1705 r = IXMLDOMElement_setAttribute( element, name, var );
1706 ok( r == S_OK, "returns %08x\n", r );
1707 VariantClear(&var);
1708 r = IXMLDOMElement_getAttribute( element, name, &var );
1709 ok( r == S_OK, "returns %08x\n", r );
1710 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1711 VariantClear(&var);
1712 SysFreeString(name);
1714 /* Create an Attribute */
1715 V_VT(&var) = VT_I4;
1716 V_I4(&var) = NODE_ATTRIBUTE;
1717 str = SysAllocString( szAttribute );
1718 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1719 ok( r == S_OK, "returns %08x\n", r );
1720 ok( node != NULL, "node was null\n");
1721 SysFreeString(str);
1723 if(r == S_OK)
1725 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1726 ok( r == S_OK, "returns %08x\n", r );
1727 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1728 SysFreeString(str);
1729 IXMLDOMNode_Release( node );
1732 IXMLDOMElement_Release( element );
1733 IXMLDOMNode_Release( root );
1734 IXMLDOMDocument_Release( doc );
1737 static void test_getElementsByTagName(void)
1739 HRESULT r;
1740 BSTR str;
1741 VARIANT_BOOL b;
1742 IXMLDOMDocument *doc;
1743 IXMLDOMNodeList *node_list;
1744 LONG len;
1746 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1747 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1748 if( r != S_OK )
1749 return;
1751 str = SysAllocString( szComplete4 );
1752 r = IXMLDOMDocument_loadXML( doc, str, &b );
1753 ok( r == S_OK, "loadXML failed\n");
1754 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1755 SysFreeString( str );
1757 str = SysAllocString( szstar );
1758 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1759 ok( r == S_OK, "ret %08x\n", r );
1760 r = IXMLDOMNodeList_get_length( node_list, &len );
1761 ok( r == S_OK, "ret %08x\n", r );
1762 ok( len == 6, "len %d\n", len );
1764 test_disp((IUnknown*)node_list);
1766 IXMLDOMNodeList_Release( node_list );
1767 SysFreeString( str );
1769 str = SysAllocString( szbs );
1770 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1771 ok( r == S_OK, "ret %08x\n", r );
1772 r = IXMLDOMNodeList_get_length( node_list, &len );
1773 ok( r == S_OK, "ret %08x\n", r );
1774 ok( len == 1, "len %d\n", len );
1775 IXMLDOMNodeList_Release( node_list );
1776 SysFreeString( str );
1778 str = SysAllocString( szdl );
1779 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1780 ok( r == S_OK, "ret %08x\n", r );
1781 r = IXMLDOMNodeList_get_length( node_list, &len );
1782 ok( r == S_OK, "ret %08x\n", r );
1783 ok( len == 0, "len %d\n", len );
1784 IXMLDOMNodeList_Release( node_list );
1785 SysFreeString( str );
1787 str = SysAllocString( szstr1 );
1788 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1789 ok( r == S_OK, "ret %08x\n", r );
1790 r = IXMLDOMNodeList_get_length( node_list, &len );
1791 ok( r == S_OK, "ret %08x\n", r );
1792 ok( len == 0, "len %d\n", len );
1793 IXMLDOMNodeList_Release( node_list );
1794 SysFreeString( str );
1796 IXMLDOMDocument_Release( doc );
1799 static void test_get_text(void)
1801 HRESULT r;
1802 BSTR str;
1803 VARIANT_BOOL b;
1804 IXMLDOMDocument *doc;
1805 IXMLDOMNode *node, *node2, *node3;
1806 IXMLDOMNode *nodeRoot;
1807 IXMLDOMNodeList *node_list;
1808 IXMLDOMNamedNodeMap *node_map;
1809 LONG len;
1811 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1812 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1813 if( r != S_OK )
1814 return;
1816 str = SysAllocString( szComplete4 );
1817 r = IXMLDOMDocument_loadXML( doc, str, &b );
1818 ok( r == S_OK, "loadXML failed\n");
1819 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1820 SysFreeString( str );
1822 str = SysAllocString( szbs );
1823 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1824 ok( r == S_OK, "ret %08x\n", r );
1825 SysFreeString(str);
1827 /* Test to get all child node text. */
1828 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (LPVOID*)&nodeRoot);
1829 ok( r == S_OK, "ret %08x\n", r );
1830 if(r == S_OK)
1832 r = IXMLDOMNode_get_text( nodeRoot, &str );
1833 ok( r == S_OK, "ret %08x\n", r );
1834 ok( compareIgnoreReturnsWhitespace(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text\n");
1835 SysFreeString(str);
1837 IXMLDOMNode_Release(nodeRoot);
1840 if (0) {
1841 /* this test crashes on win9x */
1842 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1843 ok( r == E_INVALIDARG, "ret %08x\n", r );
1846 r = IXMLDOMNodeList_get_length( node_list, NULL );
1847 ok( r == E_INVALIDARG, "ret %08x\n", r );
1849 r = IXMLDOMNodeList_get_length( node_list, &len );
1850 ok( r == S_OK, "ret %08x\n", r );
1851 ok( len == 1, "expect 1 got %d\n", len );
1853 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1854 ok( r == E_INVALIDARG, "ret %08x\n", r );
1856 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1857 ok( r == E_INVALIDARG, "ret %08x\n", r );
1859 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1860 ok( r == S_OK, "ret %08x\n", r );
1861 IXMLDOMNodeList_Release( node_list );
1863 /* Invalid output parameter*/
1864 r = IXMLDOMNode_get_text( node, NULL );
1865 ok( r == E_INVALIDARG, "ret %08x\n", r );
1867 r = IXMLDOMNode_get_text( node, &str );
1868 ok( r == S_OK, "ret %08x\n", r );
1869 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1870 SysFreeString(str);
1872 r = IXMLDOMNode_get_attributes( node, &node_map );
1873 ok( r == S_OK, "ret %08x\n", r );
1875 str = SysAllocString( szvr );
1876 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1877 ok( r == S_OK, "ret %08x\n", r );
1878 SysFreeString(str);
1880 r = IXMLDOMNode_get_text( node2, &str );
1881 ok( r == S_OK, "ret %08x\n", r );
1882 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1883 SysFreeString(str);
1885 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1886 ok( r == S_OK, "ret %08x\n", r );
1888 r = IXMLDOMNode_get_text( node3, &str );
1889 ok( r == S_OK, "ret %08x\n", r );
1890 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1891 SysFreeString(str);
1894 IXMLDOMNode_Release( node3 );
1895 IXMLDOMNode_Release( node2 );
1896 IXMLDOMNamedNodeMap_Release( node_map );
1897 IXMLDOMNode_Release( node );
1898 IXMLDOMDocument_Release( doc );
1901 static void test_get_childNodes(void)
1903 HRESULT r;
1904 BSTR str;
1905 VARIANT_BOOL b;
1906 IXMLDOMDocument *doc;
1907 IXMLDOMElement *element;
1908 IXMLDOMNode *node, *node2;
1909 IXMLDOMNodeList *node_list, *node_list2;
1910 LONG len;
1912 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1913 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1914 if( r != S_OK )
1915 return;
1917 str = SysAllocString( szComplete4 );
1918 r = IXMLDOMDocument_loadXML( doc, str, &b );
1919 ok( r == S_OK, "loadXML failed\n");
1920 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1921 SysFreeString( str );
1923 r = IXMLDOMDocument_get_documentElement( doc, &element );
1924 ok( r == S_OK, "ret %08x\n", r);
1926 r = IXMLDOMElement_get_childNodes( element, &node_list );
1927 ok( r == S_OK, "ret %08x\n", r);
1929 r = IXMLDOMNodeList_get_length( node_list, &len );
1930 ok( r == S_OK, "ret %08x\n", r);
1931 ok( len == 4, "len %d\n", len);
1933 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1934 ok( r == S_OK, "ret %08x\n", r);
1936 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1937 ok( r == S_OK, "ret %08x\n", r);
1939 r = IXMLDOMNodeList_get_length( node_list2, &len );
1940 ok( r == S_OK, "ret %08x\n", r);
1941 ok( len == 0, "len %d\n", len);
1943 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1944 ok( r == S_FALSE, "ret %08x\n", r);
1946 IXMLDOMNodeList_Release( node_list2 );
1947 IXMLDOMNode_Release( node );
1948 IXMLDOMNodeList_Release( node_list );
1949 IXMLDOMElement_Release( element );
1950 IXMLDOMDocument_Release( doc );
1953 static void test_removeChild(void)
1955 HRESULT r;
1956 BSTR str;
1957 VARIANT_BOOL b;
1958 IXMLDOMDocument *doc;
1959 IXMLDOMElement *element, *lc_element;
1960 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
1961 IXMLDOMNodeList *root_list, *fo_list;
1963 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1964 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1965 if( r != S_OK )
1966 return;
1968 str = SysAllocString( szComplete4 );
1969 r = IXMLDOMDocument_loadXML( doc, str, &b );
1970 ok( r == S_OK, "loadXML failed\n");
1971 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1972 SysFreeString( str );
1974 r = IXMLDOMDocument_get_documentElement( doc, &element );
1975 ok( r == S_OK, "ret %08x\n", r);
1977 r = IXMLDOMElement_get_childNodes( element, &root_list );
1978 ok( r == S_OK, "ret %08x\n", r);
1980 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1981 ok( r == S_OK, "ret %08x\n", r);
1983 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1984 ok( r == S_OK, "ret %08x\n", r);
1986 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1987 ok( r == S_OK, "ret %08x\n", r);
1989 /* invalid parameter: NULL ptr */
1990 removed_node = (void*)0xdeadbeef;
1991 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
1992 ok( r == E_INVALIDARG, "ret %08x\n", r );
1993 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1995 /* ba_node is a descendant of element, but not a direct child. */
1996 removed_node = (void*)0xdeadbeef;
1997 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
1998 ok( r == E_INVALIDARG, "ret %08x\n", r );
1999 ok( removed_node == NULL, "%p\n", removed_node );
2001 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
2002 ok( r == S_OK, "ret %08x\n", r);
2003 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
2005 /* try removing already removed child */
2006 temp_node = (void*)0xdeadbeef;
2007 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
2008 ok( r == E_INVALIDARG, "ret %08x\n", r);
2009 ok( temp_node == NULL, "%p\n", temp_node );
2011 /* the removed node has no parent anymore */
2012 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
2013 ok( r == S_FALSE, "ret %08x\n", r);
2014 ok( temp_node == NULL, "%p\n", temp_node );
2016 IXMLDOMNode_Release( removed_node );
2017 IXMLDOMNode_Release( ba_node );
2018 IXMLDOMNodeList_Release( fo_list );
2020 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2021 ok( r == S_OK, "ret %08x\n", r);
2023 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (LPVOID*)&lc_element );
2024 ok( r == S_OK, "ret %08x\n", r);
2026 /* MS quirk: passing wrong interface pointer works, too */
2027 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
2028 ok( r == S_OK, "ret %08x\n", r);
2030 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
2031 ok( r == S_FALSE, "ret %08x\n", r);
2032 ok( temp_node == NULL, "%p\n", temp_node );
2034 IXMLDOMNode_Release( lc_node );
2035 IXMLDOMNodeList_Release( root_list );
2036 IXMLDOMElement_Release( element );
2037 IXMLDOMDocument_Release( doc );
2040 static void test_replaceChild(void)
2042 HRESULT r;
2043 BSTR str;
2044 VARIANT_BOOL b;
2045 IXMLDOMDocument *doc;
2046 IXMLDOMElement *element, *ba_element;
2047 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
2048 IXMLDOMNodeList *root_list, *fo_list;
2049 IUnknown * unk1, *unk2;
2050 LONG len;
2052 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2053 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2054 if( r != S_OK )
2055 return;
2057 str = SysAllocString( szComplete4 );
2058 r = IXMLDOMDocument_loadXML( doc, str, &b );
2059 ok( r == S_OK, "loadXML failed\n");
2060 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2061 SysFreeString( str );
2063 r = IXMLDOMDocument_get_documentElement( doc, &element );
2064 ok( r == S_OK, "ret %08x\n", r);
2066 r = IXMLDOMElement_get_childNodes( element, &root_list );
2067 ok( r == S_OK, "ret %08x\n", r);
2069 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2070 ok( r == S_OK, "ret %08x\n", r);
2072 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2073 ok( r == S_OK, "ret %08x\n", r);
2075 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2076 ok( r == S_OK, "ret %08x\n", r);
2078 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2079 ok( r == S_OK, "ret %08x\n", r);
2081 IXMLDOMNodeList_Release( fo_list );
2083 /* invalid parameter: NULL ptr for element to remove */
2084 removed_node = (void*)0xdeadbeef;
2085 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
2086 ok( r == E_INVALIDARG, "ret %08x\n", r );
2087 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2089 /* invalid parameter: NULL for replacement element. (Sic!) */
2090 removed_node = (void*)0xdeadbeef;
2091 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
2092 ok( r == E_INVALIDARG, "ret %08x\n", r );
2093 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2095 /* invalid parameter: OldNode is not a child */
2096 removed_node = (void*)0xdeadbeef;
2097 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
2098 ok( r == E_INVALIDARG, "ret %08x\n", r );
2099 ok( removed_node == NULL, "%p\n", removed_node );
2101 /* invalid parameter: would create loop */
2102 removed_node = (void*)0xdeadbeef;
2103 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
2104 ok( r == E_FAIL, "ret %08x\n", r );
2105 ok( removed_node == NULL, "%p\n", removed_node );
2107 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
2108 ok( r == S_OK, "ret %08x\n", r );
2110 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
2111 ok( r == S_OK, "ret %08x\n", r );
2113 /* ba_node and temp_node refer to the same node, yet they
2114 are different interface pointers */
2115 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
2116 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
2117 ok( r == S_OK, "ret %08x\n", r );
2118 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
2119 ok( r == S_OK, "ret %08x\n", r );
2120 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
2122 IUnknown_Release( unk1 );
2123 IUnknown_Release( unk2 );
2125 /* ba_node should have been removed from below fo_node */
2126 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2127 ok( r == S_OK, "ret %08x\n", r );
2129 /* MS quirk: replaceChild also accepts elements instead of nodes */
2130 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
2131 ok( r == S_OK, "ret %08x\n", r );
2133 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
2134 ok( r == S_OK, "ret %08x\n", r );
2136 r = IXMLDOMNodeList_get_length( fo_list, &len);
2137 ok( r == S_OK, "ret %08x\n", r );
2138 ok( len == 0, "len %d\n", len);
2140 IXMLDOMNodeList_Release( fo_list );
2142 IXMLDOMNode_Release(ba_node);
2143 IXMLDOMNode_Release(fo_node);
2144 IXMLDOMNode_Release(temp_node);
2145 IXMLDOMNodeList_Release( root_list );
2146 IXMLDOMElement_Release( element );
2147 IXMLDOMDocument_Release( doc );
2150 static void test_removeNamedItem(void)
2152 IXMLDOMDocument *doc;
2153 IXMLDOMElement *element;
2154 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
2155 IXMLDOMNodeList *root_list;
2156 IXMLDOMNamedNodeMap * pr_attrs;
2157 VARIANT_BOOL b;
2158 BSTR str;
2159 LONG len;
2160 HRESULT r;
2162 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2163 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2164 if( r != S_OK )
2165 return;
2167 str = SysAllocString( szComplete4 );
2168 r = IXMLDOMDocument_loadXML( doc, str, &b );
2169 ok( r == S_OK, "loadXML failed\n");
2170 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2171 SysFreeString( str );
2173 r = IXMLDOMDocument_get_documentElement( doc, &element );
2174 ok( r == S_OK, "ret %08x\n", r);
2176 r = IXMLDOMElement_get_childNodes( element, &root_list );
2177 ok( r == S_OK, "ret %08x\n", r);
2179 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2180 ok( r == S_OK, "ret %08x\n", r);
2182 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2183 ok( r == S_OK, "ret %08x\n", r);
2185 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2186 ok( r == S_OK, "ret %08x\n", r);
2187 ok( len == 3, "length %d\n", len);
2189 removed_node = (void*)0xdeadbeef;
2190 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2191 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2192 ok ( removed_node == (void*)0xdeadbeef, "removed_node == %p\n", removed_node);
2194 removed_node = (void*)0xdeadbeef;
2195 str = SysAllocString(szvr);
2196 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2197 ok ( r == S_OK, "ret %08x\n", r);
2199 removed_node2 = (void*)0xdeadbeef;
2200 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2201 ok ( r == S_FALSE, "ret %08x\n", r);
2202 ok ( removed_node2 == NULL, "removed_node == %p\n", removed_node2 );
2204 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2205 ok( r == S_OK, "ret %08x\n", r);
2206 ok( len == 2, "length %d\n", len);
2208 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2209 ok ( r == S_OK, "ret %08x\n", r);
2210 IXMLDOMNode_Release(removed_node);
2212 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2213 ok( r == S_OK, "ret %08x\n", r);
2214 ok( len == 3, "length %d\n", len);
2216 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2217 ok ( r == S_OK, "ret %08x\n", r);
2219 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2220 ok( r == S_OK, "ret %08x\n", r);
2221 ok( len == 2, "length %d\n", len);
2223 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2224 ok ( r == S_FALSE, "ret %08x\n", r);
2226 SysFreeString(str);
2228 IXMLDOMNamedNodeMap_Release( pr_attrs );
2229 IXMLDOMNode_Release( pr_node );
2230 IXMLDOMNodeList_Release( root_list );
2231 IXMLDOMElement_Release( element );
2232 IXMLDOMDocument_Release( doc );
2235 static void test_XMLHTTP(void)
2237 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2238 static WCHAR wszPOST[] = {'P','O','S','T',0};
2239 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2240 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2241 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2242 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2243 IXMLHttpRequest *pXMLHttpRequest;
2244 BSTR bstrResponse;
2245 VARIANT dummy;
2246 VARIANT varfalse;
2247 VARIANT varbody;
2248 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2249 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2250 (void **)&pXMLHttpRequest);
2251 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
2252 if (hr != S_OK)
2253 return;
2255 VariantInit(&dummy);
2256 V_VT(&dummy) = VT_ERROR;
2257 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2258 VariantInit(&varfalse);
2259 V_VT(&varfalse) = VT_BOOL;
2260 V_BOOL(&varfalse) = VARIANT_FALSE;
2261 V_VT(&varbody) = VT_BSTR;
2262 V_BSTR(&varbody) = SysAllocString(wszBody);
2264 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
2265 todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
2267 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2268 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2269 VariantClear(&varbody);
2271 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2272 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2273 /* the server currently returns "FAILED" because the Content-Type header is
2274 * not what the server expects */
2275 if(hr == S_OK)
2277 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2278 SysFreeString(bstrResponse);
2281 IXMLHttpRequest_Release(pXMLHttpRequest);
2284 static void test_IXMLDOMDocument2(void)
2286 HRESULT r;
2287 VARIANT_BOOL b;
2288 BSTR str;
2289 IXMLDOMDocument *doc;
2290 IXMLDOMDocument2 *doc2;
2291 IDispatchEx *dispex;
2292 VARIANT var;
2293 int ref;
2295 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2296 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2297 if( r != S_OK )
2298 return;
2300 str = SysAllocString( szComplete4 );
2301 r = IXMLDOMDocument_loadXML( doc, str, &b );
2302 ok( r == S_OK, "loadXML failed\n");
2303 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2304 SysFreeString( str );
2306 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
2307 ok( r == S_OK, "ret %08x\n", r );
2308 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
2310 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
2311 ok( r == S_OK, "ret %08x\n", r );
2312 if(r == S_OK)
2314 IDispatchEx_Release(dispex);
2317 /* we will check if the variant got cleared */
2318 ref = IXMLDOMDocument2_AddRef(doc2);
2319 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
2320 V_VT(&var) = VT_UNKNOWN;
2321 V_UNKNOWN(&var) = (IUnknown *)doc2;
2323 /* invalid calls */
2324 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
2325 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
2326 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
2328 /* valid call */
2329 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2330 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2331 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2332 V_VT(&var) = VT_R4;
2334 /* the variant didn't get cleared*/
2335 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
2337 /* setProperty tests */
2338 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
2339 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
2340 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
2341 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2342 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2343 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2345 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
2346 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2347 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2348 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2350 IXMLDOMDocument2_Release( doc2 );
2351 IXMLDOMDocument_Release( doc );
2352 free_bstrs();
2355 static void test_XPath(void)
2357 HRESULT r;
2358 VARIANT var;
2359 VARIANT_BOOL b;
2360 IXMLDOMDocument2 *doc;
2361 IXMLDOMNode *rootNode;
2362 IXMLDOMNode *elem1Node;
2363 IXMLDOMNode *node;
2364 IXMLDOMNodeList *list;
2366 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2367 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2368 if( r != S_OK )
2369 return;
2371 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
2372 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2374 /* switch to XPath */
2375 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2377 /* some simple queries*/
2378 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
2379 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
2380 ole_check(IXMLDOMNodeList_reset(list));
2381 expect_list_and_release(list, "E2.D1");
2382 if (rootNode == NULL)
2383 return;
2385 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
2386 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
2388 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
2389 expect_list_and_release(list, "E3.E2.E2.D1");
2391 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
2392 /* using get_item for query results advances the position */
2393 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2394 expect_node(node, "E2.E2.D1");
2395 IXMLDOMNode_Release(node);
2396 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2397 expect_node(node, "E4.E2.D1");
2398 IXMLDOMNode_Release(node);
2399 ole_check(IXMLDOMNodeList_reset(list));
2400 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2402 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2403 expect_list_and_release(list, "E2.D1");
2405 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2406 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2407 ole_check(IXMLDOMNodeList_reset(list));
2408 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2410 /* select an attribute */
2411 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2412 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2414 /* would evaluate to a number */
2415 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2416 /* would evaluate to a boolean */
2417 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2418 /* would evaluate to a string */
2419 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2421 /* no results */
2422 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2423 expect_list_and_release(list, "");
2424 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2425 expect_list_and_release(list, "");
2426 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2427 expect_list_and_release(list, "");
2429 /* foo undeclared in document node */
2430 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2431 /* undeclared in <root> node */
2432 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2433 /* undeclared in <elem> node */
2434 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2435 /* but this trick can be used */
2436 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2437 expect_list_and_release(list, "E3.E4.E2.D1");
2439 /* it has to be declared in SelectionNamespaces */
2440 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2441 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2443 /* now the namespace can be used */
2444 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2445 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2446 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2447 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2448 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2449 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2450 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2451 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2453 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2454 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2455 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2457 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2459 VariantInit(&var);
2460 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2461 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2462 if (V_VT(&var) == VT_BSTR)
2463 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2465 /* extra attributes - same thing*/
2466 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2467 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2468 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2470 IXMLDOMNode_Release(rootNode);
2471 IXMLDOMNode_Release(elem1Node);
2472 IXMLDOMDocument_Release(doc);
2473 free_bstrs();
2476 static void test_cloneNode(void )
2478 IXMLDOMDocument *doc = NULL;
2479 VARIANT_BOOL b;
2480 IXMLDOMNodeList *pList;
2481 IXMLDOMNamedNodeMap *mapAttr;
2482 LONG nLength = 0, nLength1 = 0;
2483 LONG nAttrCnt = 0, nAttrCnt1 = 0;
2484 IXMLDOMNode *node;
2485 IXMLDOMNode *node_clone;
2486 IXMLDOMNode *node_first;
2487 HRESULT r;
2488 BSTR str;
2489 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2491 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2492 if( r != S_OK )
2493 return;
2495 str = SysAllocString( szComplete4 );
2496 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2497 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2498 SysFreeString(str);
2500 if(!b)
2501 return;
2503 str = SysAllocString( szSearch);
2504 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2505 ok( r == S_OK, "ret %08x\n", r );
2506 ok( node != NULL, "node %p\n", node );
2507 SysFreeString(str);
2509 if(!node)
2511 IXMLDOMDocument_Release(doc);
2512 return;
2515 /* Check invalid parameter */
2516 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2517 ok( r == E_INVALIDARG, "ret %08x\n", r );
2519 /* All Children */
2520 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2521 ok( r == S_OK, "ret %08x\n", r );
2522 ok( node_clone != NULL, "node %p\n", node );
2524 if(!node_clone)
2526 IXMLDOMDocument_Release(doc);
2527 IXMLDOMNode_Release(node);
2528 return;
2531 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2532 ok( r == S_OK, "ret %08x\n", r );
2533 if(r == S_OK)
2535 IXMLDOMDocument *doc2;
2537 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2538 ok( r == S_OK, "ret %08x\n", r );
2539 if(r == S_OK)
2540 IXMLDOMDocument_Release(doc2);
2542 IXMLDOMNode_Release(node_first);
2545 r = IXMLDOMNode_get_childNodes(node, &pList);
2546 ok( r == S_OK, "ret %08x\n", r );
2547 if (pList)
2549 IXMLDOMNodeList_get_length(pList, &nLength);
2550 IXMLDOMNodeList_Release(pList);
2553 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2554 ok( r == S_OK, "ret %08x\n", r );
2555 if(mapAttr)
2557 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2558 IXMLDOMNamedNodeMap_Release(mapAttr);
2561 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2562 ok( r == S_OK, "ret %08x\n", r );
2563 if (pList)
2565 IXMLDOMNodeList_get_length(pList, &nLength1);
2566 IXMLDOMNodeList_Release(pList);
2569 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2570 ok( r == S_OK, "ret %08x\n", r );
2571 if(mapAttr)
2573 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2574 IXMLDOMNamedNodeMap_Release(mapAttr);
2577 ok(nLength == nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2578 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2579 IXMLDOMNode_Release(node_clone);
2581 /* No Children */
2582 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2583 ok( r == S_OK, "ret %08x\n", r );
2584 ok( node_clone != NULL, "node %p\n", node );
2586 if(!node_clone)
2588 IXMLDOMDocument_Release(doc);
2589 IXMLDOMNode_Release(node);
2590 return;
2593 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2594 ok( r == S_FALSE, "ret %08x\n", r );
2595 if(r == S_OK)
2597 IXMLDOMDocument *doc2;
2599 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2600 ok( r == S_OK, "ret %08x\n", r );
2601 if(r == S_OK)
2602 IXMLDOMDocument_Release(doc2);
2604 IXMLDOMNode_Release(node_first);
2607 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2608 ok( r == S_OK, "ret %08x\n", r );
2609 if (pList)
2611 IXMLDOMNodeList_get_length(pList, &nLength1);
2612 ok( nLength1 == 0, "Length should be 0 (%d)\n", nLength1);
2613 IXMLDOMNodeList_Release(pList);
2616 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2617 ok( r == S_OK, "ret %08x\n", r );
2618 if(mapAttr)
2620 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2621 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%d)\n", nAttrCnt1);
2622 IXMLDOMNamedNodeMap_Release(mapAttr);
2625 ok(nLength != nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2626 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2627 IXMLDOMNode_Release(node_clone);
2630 IXMLDOMNode_Release(node);
2631 IXMLDOMDocument_Release(doc);
2634 static void test_xmlTypes(void)
2636 IXMLDOMDocument *doc = NULL;
2637 IXMLDOMElement *pRoot;
2638 HRESULT hr;
2639 IXMLDOMComment *pComment;
2640 IXMLDOMElement *pElement;
2641 IXMLDOMAttribute *pAttrubute;
2642 IXMLDOMNamedNodeMap *pAttribs;
2643 IXMLDOMCDATASection *pCDataSec;
2644 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2645 IXMLDOMDocumentFragment *pDocFrag = NULL;
2646 IXMLDOMEntityReference *pEntityRef = NULL;
2647 BSTR str;
2648 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2649 VARIANT v;
2650 LONG len = 0;
2652 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2653 if( hr != S_OK )
2654 return;
2656 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2657 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2659 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2660 ok(hr == S_FALSE, "ret %08x\n", hr );
2661 ok(pNextChild == NULL, "pDocChild not NULL\n");
2663 /* test previous Sibling */
2664 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2665 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2667 pNextChild = (IXMLDOMNode *)0x1;
2668 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2669 ok(hr == S_FALSE, "ret %08x\n", hr );
2670 ok(pNextChild == NULL, "pNextChild not NULL\n");
2672 /* test get_attributes */
2673 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2674 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2676 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2677 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2678 ok(hr == S_FALSE, "ret %08x\n", hr );
2679 ok( pAttribs == NULL, "pAttribs not NULL\n");
2681 /* test get_dataType */
2682 hr = IXMLDOMDocument_get_dataType(doc, &v);
2683 ok(hr == S_FALSE, "ret %08x\n", hr );
2684 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2685 VariantClear(&v);
2687 /* test nodeTypeString */
2688 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2689 ok(hr == S_OK, "ret %08x\n", hr );
2690 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2691 SysFreeString(str);
2693 /* test implementation */
2694 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2695 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2697 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2698 ok(hr == S_OK, "ret %08x\n", hr );
2699 if(hr == S_OK)
2701 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2702 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2704 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2705 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2707 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2708 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2710 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2711 ok(hr == S_OK, "ret %08x\n", hr );
2712 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2714 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2715 ok(hr == S_OK, "ret %08x\n", hr );
2716 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2718 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2719 ok(hr == S_OK, "ret %08x\n", hr );
2720 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2722 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2723 ok(hr == S_OK, "ret %08x\n", hr );
2724 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2726 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2727 ok(hr == S_OK, "ret %08x\n", hr );
2728 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2730 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2731 ok(hr == S_OK, "ret %08x\n", hr );
2732 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2734 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2735 ok(hr == S_OK, "ret %08x\n", hr );
2736 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2738 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2739 ok(hr == S_OK, "ret %08x\n", hr );
2740 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2742 SysFreeString(sEmpty);
2743 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2748 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2749 ok(hr == S_OK, "ret %08x\n", hr );
2750 if(hr == S_OK)
2752 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2753 ok(hr == S_OK, "ret %08x\n", hr );
2754 if(hr == S_OK)
2756 /* Comment */
2757 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2758 ok(hr == S_OK, "ret %08x\n", hr );
2759 if(hr == S_OK)
2761 /* test get_attributes */
2762 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2763 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2765 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2766 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2767 ok(hr == S_FALSE, "ret %08x\n", hr );
2768 ok( pAttribs == NULL, "pAttribs not NULL\n");
2770 /* test nodeTypeString */
2771 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2772 ok(hr == S_OK, "ret %08x\n", hr );
2773 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2774 SysFreeString(str);
2776 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2777 ok(hr == S_OK, "ret %08x\n", hr );
2779 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2780 ok(hr == S_OK, "ret %08x\n", hr );
2781 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2782 SysFreeString(str);
2784 hr = IXMLDOMComment_get_xml(pComment, &str);
2785 ok(hr == S_OK, "ret %08x\n", hr );
2786 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2787 SysFreeString(str);
2789 hr = IXMLDOMComment_get_dataType(pComment, &v);
2790 ok(hr == S_FALSE, "ret %08x\n", hr );
2791 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2792 VariantClear(&v);
2794 /* put data Tests */
2795 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2796 ok(hr == S_OK, "ret %08x\n", hr );
2798 /* get data Tests */
2799 hr = IXMLDOMComment_get_data(pComment, &str);
2800 ok(hr == S_OK, "ret %08x\n", hr );
2801 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2802 SysFreeString(str);
2804 /* get data Tests */
2805 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2806 ok(hr == S_OK, "ret %08x\n", hr );
2807 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2808 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2809 VariantClear(&v);
2811 /* Confirm XML text is good */
2812 hr = IXMLDOMComment_get_xml(pComment, &str);
2813 ok(hr == S_OK, "ret %08x\n", hr );
2814 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2815 SysFreeString(str);
2817 /* Confirm we get the put_data Text back */
2818 hr = IXMLDOMComment_get_text(pComment, &str);
2819 ok(hr == S_OK, "ret %08x\n", hr );
2820 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2821 SysFreeString(str);
2823 /* test length property */
2824 hr = IXMLDOMComment_get_length(pComment, &len);
2825 ok(hr == S_OK, "ret %08x\n", hr );
2826 ok(len == 21, "expected 21 got %d\n", len);
2828 /* test substringData */
2829 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2830 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2832 /* test substringData - Invalid offset */
2833 str = (BSTR)&szElement;
2834 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2835 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2836 ok( str == NULL, "incorrect string\n");
2838 /* test substringData - Invalid offset */
2839 str = (BSTR)&szElement;
2840 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2841 ok(hr == S_FALSE, "ret %08x\n", hr );
2842 ok( str == NULL, "incorrect string\n");
2844 /* test substringData - Invalid size */
2845 str = (BSTR)&szElement;
2846 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2847 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2848 ok( str == NULL, "incorrect string\n");
2850 /* test substringData - Invalid size */
2851 str = (BSTR)&szElement;
2852 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2853 ok(hr == S_FALSE, "ret %08x\n", hr );
2854 ok( str == NULL, "incorrect string\n");
2856 /* test substringData - Start of string */
2857 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2858 ok(hr == S_OK, "ret %08x\n", hr );
2859 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2860 SysFreeString(str);
2862 /* test substringData - Middle of string */
2863 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2864 ok(hr == S_OK, "ret %08x\n", hr );
2865 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2866 SysFreeString(str);
2868 /* test substringData - End of string */
2869 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2870 ok(hr == S_OK, "ret %08x\n", hr );
2871 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2872 SysFreeString(str);
2874 /* test appendData */
2875 hr = IXMLDOMComment_appendData(pComment, NULL);
2876 ok(hr == S_OK, "ret %08x\n", hr );
2878 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2879 ok(hr == S_OK, "ret %08x\n", hr );
2881 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2882 ok(hr == S_OK, "ret %08x\n", hr );
2884 hr = IXMLDOMComment_get_text(pComment, &str);
2885 ok(hr == S_OK, "ret %08x\n", hr );
2886 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2887 SysFreeString(str);
2889 /* test insertData */
2890 str = SysAllocStringLen(NULL, 0);
2891 hr = IXMLDOMComment_insertData(pComment, -1, str);
2892 ok(hr == S_OK, "ret %08x\n", hr );
2894 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2895 ok(hr == S_OK, "ret %08x\n", hr );
2897 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2898 ok(hr == S_OK, "ret %08x\n", hr );
2900 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2901 ok(hr == S_OK, "ret %08x\n", hr );
2903 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2904 ok(hr == S_OK, "ret %08x\n", hr );
2906 hr = IXMLDOMComment_insertData(pComment, 0, str);
2907 ok(hr == S_OK, "ret %08x\n", hr );
2908 SysFreeString(str);
2910 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2911 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2913 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2914 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2916 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2917 ok(hr == S_OK, "ret %08x\n", hr );
2919 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2920 ok(hr == S_OK, "ret %08x\n", hr );
2922 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2923 ok(hr == S_OK, "ret %08x\n", hr );
2925 hr = IXMLDOMComment_get_text(pComment, &str);
2926 ok(hr == S_OK, "ret %08x\n", hr );
2927 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2928 SysFreeString(str);
2930 /* delete data */
2931 /* invalid arguments */
2932 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
2933 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2935 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
2936 ok(hr == S_OK, "ret %08x\n", hr );
2938 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
2939 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2941 hr = IXMLDOMComment_get_length(pComment, &len);
2942 ok(hr == S_OK, "ret %08x\n", hr );
2943 ok(len == 43, "expected 43 got %d\n", len);
2945 hr = IXMLDOMComment_deleteData(pComment, len, 1);
2946 ok(hr == S_OK, "ret %08x\n", hr );
2948 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
2949 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2951 /* delete from start */
2952 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
2953 ok(hr == S_OK, "ret %08x\n", hr );
2955 hr = IXMLDOMComment_get_length(pComment, &len);
2956 ok(hr == S_OK, "ret %08x\n", hr );
2957 ok(len == 38, "expected 38 got %d\n", len);
2959 hr = IXMLDOMComment_get_text(pComment, &str);
2960 ok(hr == S_OK, "ret %08x\n", hr );
2961 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2962 SysFreeString(str);
2964 /* delete from end */
2965 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
2966 ok(hr == S_OK, "ret %08x\n", hr );
2968 hr = IXMLDOMComment_get_length(pComment, &len);
2969 ok(hr == S_OK, "ret %08x\n", hr );
2970 ok(len == 35, "expected 35 got %d\n", len);
2972 hr = IXMLDOMComment_get_text(pComment, &str);
2973 ok(hr == S_OK, "ret %08x\n", hr );
2974 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string\n");
2975 SysFreeString(str);
2977 /* delete from inside */
2978 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
2979 ok(hr == S_OK, "ret %08x\n", hr );
2981 hr = IXMLDOMComment_get_length(pComment, &len);
2982 ok(hr == S_OK, "ret %08x\n", hr );
2983 ok(len == 2, "expected 2 got %d\n", len);
2985 hr = IXMLDOMComment_get_text(pComment, &str);
2986 ok(hr == S_OK, "ret %08x\n", hr );
2987 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string\n");
2988 SysFreeString(str);
2990 /* delete whole data ... */
2991 hr = IXMLDOMComment_get_length(pComment, &len);
2992 ok(hr == S_OK, "ret %08x\n", hr );
2994 hr = IXMLDOMComment_deleteData(pComment, 0, len);
2995 ok(hr == S_OK, "ret %08x\n", hr );
2996 /* ... and try again with empty string */
2997 hr = IXMLDOMComment_deleteData(pComment, 0, len);
2998 ok(hr == S_OK, "ret %08x\n", hr );
3000 IXMLDOMComment_Release(pComment);
3003 /* Element */
3004 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
3005 ok(hr == S_OK, "ret %08x\n", hr );
3006 if(hr == S_OK)
3008 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3009 ok(hr == S_OK, "ret %08x\n", hr );
3011 /* test nodeTypeString */
3012 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
3013 ok(hr == S_OK, "ret %08x\n", hr );
3014 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
3015 SysFreeString(str);
3017 hr = IXMLDOMElement_get_nodeName(pElement, &str);
3018 ok(hr == S_OK, "ret %08x\n", hr );
3019 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
3020 SysFreeString(str);
3022 hr = IXMLDOMElement_get_xml(pElement, &str);
3023 ok(hr == S_OK, "ret %08x\n", hr );
3024 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
3025 SysFreeString(str);
3027 hr = IXMLDOMElement_get_dataType(pElement, &v);
3028 ok(hr == S_FALSE, "ret %08x\n", hr );
3029 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3030 VariantClear(&v);
3032 /* Attribute */
3033 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
3034 ok(hr == S_OK, "ret %08x\n", hr );
3035 if(hr == S_OK)
3037 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
3039 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
3040 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3042 pNextChild = (IXMLDOMNode *)0x1;
3043 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
3044 ok(hr == S_FALSE, "ret %08x\n", hr );
3045 ok(pNextChild == NULL, "pNextChild not NULL\n");
3047 /* test Previous Sibling*/
3048 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
3049 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3051 pNextChild = (IXMLDOMNode *)0x1;
3052 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
3053 ok(hr == S_FALSE, "ret %08x\n", hr );
3054 ok(pNextChild == NULL, "pNextChild not NULL\n");
3056 /* test get_attributes */
3057 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
3058 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
3060 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3061 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
3062 ok(hr == S_FALSE, "ret %08x\n", hr );
3063 ok( pAttribs == NULL, "pAttribs not NULL\n");
3065 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
3066 ok(hr == E_FAIL, "ret %08x\n", hr );
3067 ok(pNewChild == NULL, "pNewChild not NULL\n");
3069 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
3070 ok(hr == S_OK, "ret %08x\n", hr );
3071 if ( hr == S_OK )
3073 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
3074 ok(hr == S_OK, "ret %08x\n", hr );
3076 IXMLDOMNamedNodeMap_Release(pAttribs);
3079 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
3080 ok(hr == S_OK, "ret %08x\n", hr );
3081 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
3082 SysFreeString(str);
3084 /* test nodeTypeString */
3085 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
3086 ok(hr == S_OK, "ret %08x\n", hr );
3087 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
3088 SysFreeString(str);
3090 /* test nodeName */
3091 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
3092 ok(hr == S_OK, "ret %08x\n", hr );
3093 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
3094 SysFreeString(str);
3096 /* test name property */
3097 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
3098 ok(hr == S_OK, "ret %08x\n", hr );
3099 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
3100 SysFreeString(str);
3102 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
3103 ok(hr == S_OK, "ret %08x\n", hr );
3104 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
3105 SysFreeString(str);
3107 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
3108 ok(hr == S_FALSE, "ret %08x\n", hr );
3109 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3110 VariantClear(&v);
3112 IXMLDOMAttribute_Release(pAttrubute);
3114 /* Check Element again with the Add Attribute*/
3115 hr = IXMLDOMElement_get_xml(pElement, &str);
3116 ok(hr == S_OK, "ret %08x\n", hr );
3117 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
3118 SysFreeString(str);
3121 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
3122 ok(hr == S_OK, "ret %08x\n", hr );
3124 hr = IXMLDOMElement_get_xml(pElement, &str);
3125 ok(hr == S_OK, "ret %08x\n", hr );
3126 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
3127 SysFreeString(str);
3129 /* Test for reversible escaping */
3130 str = SysAllocString( szStrangeChars );
3131 hr = IXMLDOMElement_put_text(pElement, str);
3132 ok(hr == S_OK, "ret %08x\n", hr );
3133 SysFreeString( str );
3135 hr = IXMLDOMElement_get_xml(pElement, &str);
3136 ok(hr == S_OK, "ret %08x\n", hr );
3137 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
3138 SysFreeString(str);
3140 hr = IXMLDOMElement_get_text(pElement, &str);
3141 ok(hr == S_OK, "ret %08x\n", hr );
3142 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
3143 SysFreeString(str);
3145 IXMLDOMElement_Release(pElement);
3148 /* CData Section */
3149 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
3150 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3152 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
3153 ok(hr == S_OK, "ret %08x\n", hr );
3154 if(hr == S_OK)
3156 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3157 VARIANT var;
3159 VariantInit(&var);
3161 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (LPVOID*)&pElement);
3162 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
3164 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
3165 ok(hr == S_OK, "ret %08x\n", hr );
3167 /* get Attribute Tests */
3168 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
3169 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3171 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3172 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
3173 ok(hr == S_FALSE, "ret %08x\n", hr );
3174 ok(pAttribs == NULL, "pAttribs != NULL\n");
3176 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
3177 ok(hr == S_OK, "ret %08x\n", hr );
3178 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
3179 SysFreeString(str);
3181 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3182 ok(hr == S_OK, "ret %08x\n", hr );
3183 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
3184 SysFreeString(str);
3186 /* test lastChild */
3187 pNextChild = (IXMLDOMNode*)0x1;
3188 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
3189 ok(hr == S_FALSE, "ret %08x\n", hr );
3190 ok(pNextChild == NULL, "pNextChild not NULL\n");
3192 /* test get_dataType */
3193 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
3194 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3196 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
3197 ok(hr == S_FALSE, "ret %08x\n", hr );
3198 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3199 VariantClear(&v);
3201 /* test nodeTypeString */
3202 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
3203 ok(hr == S_OK, "ret %08x\n", hr );
3204 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
3205 SysFreeString(str);
3207 /* put data Tests */
3208 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
3209 ok(hr == S_OK, "ret %08x\n", hr );
3211 /* Confirm XML text is good */
3212 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3213 ok(hr == S_OK, "ret %08x\n", hr );
3214 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
3215 SysFreeString(str);
3217 /* Confirm we get the put_data Text back */
3218 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3219 ok(hr == S_OK, "ret %08x\n", hr );
3220 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3221 SysFreeString(str);
3223 /* test length property */
3224 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
3225 ok(hr == S_OK, "ret %08x\n", hr );
3226 ok(len == 21, "expected 21 got %d\n", len);
3228 /* test get nodeValue */
3229 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
3230 ok(hr == S_OK, "ret %08x\n", hr );
3231 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
3232 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3233 VariantClear(&var);
3235 /* test get data */
3236 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
3237 ok(hr == S_OK, "ret %08x\n", hr );
3238 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3239 SysFreeString(str);
3241 /* test substringData */
3242 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
3243 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3245 /* test substringData - Invalid offset */
3246 str = (BSTR)&szElement;
3247 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
3248 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3249 ok( str == NULL, "incorrect string\n");
3251 /* test substringData - Invalid offset */
3252 str = (BSTR)&szElement;
3253 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
3254 ok(hr == S_FALSE, "ret %08x\n", hr );
3255 ok( str == NULL, "incorrect string\n");
3257 /* test substringData - Invalid size */
3258 str = (BSTR)&szElement;
3259 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
3260 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3261 ok( str == NULL, "incorrect string\n");
3263 /* test substringData - Invalid size */
3264 str = (BSTR)&szElement;
3265 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
3266 ok(hr == S_FALSE, "ret %08x\n", hr );
3267 ok( str == NULL, "incorrect string\n");
3269 /* test substringData - Start of string */
3270 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
3271 ok(hr == S_OK, "ret %08x\n", hr );
3272 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
3273 SysFreeString(str);
3275 /* test substringData - Middle of string */
3276 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
3277 ok(hr == S_OK, "ret %08x\n", hr );
3278 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
3279 SysFreeString(str);
3281 /* test substringData - End of string */
3282 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
3283 ok(hr == S_OK, "ret %08x\n", hr );
3284 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
3285 SysFreeString(str);
3287 /* test appendData */
3288 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
3289 ok(hr == S_OK, "ret %08x\n", hr );
3291 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
3292 ok(hr == S_OK, "ret %08x\n", hr );
3294 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
3295 ok(hr == S_OK, "ret %08x\n", hr );
3297 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3298 ok(hr == S_OK, "ret %08x\n", hr );
3299 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
3300 SysFreeString(str);
3302 /* test insertData */
3303 str = SysAllocStringLen(NULL, 0);
3304 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
3305 ok(hr == S_OK, "ret %08x\n", hr );
3307 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
3308 ok(hr == S_OK, "ret %08x\n", hr );
3310 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
3311 ok(hr == S_OK, "ret %08x\n", hr );
3313 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
3314 ok(hr == S_OK, "ret %08x\n", hr );
3316 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
3317 ok(hr == S_OK, "ret %08x\n", hr );
3319 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
3320 ok(hr == S_OK, "ret %08x\n", hr );
3321 SysFreeString(str);
3323 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
3324 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3326 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
3327 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3329 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
3330 ok(hr == S_OK, "ret %08x\n", hr );
3332 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
3333 ok(hr == S_OK, "ret %08x\n", hr );
3335 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
3336 ok(hr == S_OK, "ret %08x\n", hr );
3338 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3339 ok(hr == S_OK, "ret %08x\n", hr );
3340 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
3341 SysFreeString(str);
3343 IXMLDOMCDATASection_Release(pCDataSec);
3346 /* Document Fragments */
3347 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
3348 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3350 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
3351 ok(hr == S_OK, "ret %08x\n", hr );
3352 if(hr == S_OK)
3354 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3356 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
3357 ok(hr == S_OK, "ret %08x\n", hr );
3359 /* get Attribute Tests */
3360 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
3361 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3363 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3364 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
3365 ok(hr == S_FALSE, "ret %08x\n", hr );
3366 ok(pAttribs == NULL, "pAttribs != NULL\n");
3368 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
3369 ok(hr == S_OK, "ret %08x\n", hr );
3370 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
3371 SysFreeString(str);
3373 /* test next Sibling*/
3374 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
3375 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3377 pNextChild = (IXMLDOMNode *)0x1;
3378 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
3379 ok(hr == S_FALSE, "ret %08x\n", hr );
3380 ok(pNextChild == NULL, "pNextChild not NULL\n");
3382 /* test Previous Sibling*/
3383 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
3384 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3386 pNextChild = (IXMLDOMNode *)0x1;
3387 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
3388 ok(hr == S_FALSE, "ret %08x\n", hr );
3389 ok(pNextChild == NULL, "pNextChild not NULL\n");
3391 /* test get_dataType */
3392 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
3393 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3395 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
3396 ok(hr == S_FALSE, "ret %08x\n", hr );
3397 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3398 VariantClear(&v);
3400 /* test nodeTypeString */
3401 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
3402 ok(hr == S_OK, "ret %08x\n", hr );
3403 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
3404 SysFreeString(str);
3406 IXMLDOMDocumentFragment_Release(pDocFrag);
3409 /* Entity References */
3410 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
3411 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3413 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
3414 ok(hr == S_OK, "ret %08x\n", hr );
3415 if(hr == S_OK)
3417 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
3418 ok(hr == S_OK, "ret %08x\n", hr );
3420 /* get Attribute Tests */
3421 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
3422 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3424 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3425 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
3426 ok(hr == S_FALSE, "ret %08x\n", hr );
3427 ok(pAttribs == NULL, "pAttribs != NULL\n");
3429 /* test dataType */
3430 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
3431 ok(hr == S_FALSE, "ret %08x\n", hr );
3432 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3433 VariantClear(&v);
3435 /* test nodeTypeString */
3436 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
3437 ok(hr == S_OK, "ret %08x\n", hr );
3438 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
3439 SysFreeString(str);
3441 /* test get_xml*/
3442 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
3443 ok(hr == S_OK, "ret %08x\n", hr );
3444 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
3445 SysFreeString(str);
3447 IXMLDOMEntityReference_Release(pEntityRef);
3450 IXMLDOMElement_Release( pRoot );
3454 IXMLDOMDocument_Release(doc);
3456 free_bstrs();
3459 static void test_nodeTypeTests( void )
3461 IXMLDOMDocument *doc = NULL;
3462 IXMLDOMElement *pRoot;
3463 IXMLDOMElement *pElement;
3464 HRESULT hr;
3466 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3467 if( hr != S_OK )
3468 return;
3470 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3471 ok(hr == S_OK, "ret %08x\n", hr );
3472 if(hr == S_OK)
3474 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3475 ok(hr == S_OK, "ret %08x\n", hr );
3476 if(hr == S_OK)
3478 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
3479 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3481 /* Invalid Value */
3482 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
3483 ok(hr == E_FAIL, "ret %08x\n", hr );
3485 /* NOTE:
3486 * The name passed into put_dataType is case-insensitive. So many of the names
3487 * have been changed to reflect this.
3489 /* Boolean */
3490 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
3491 ok(hr == S_OK, "ret %08x\n", hr );
3492 if(hr == S_OK)
3494 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3496 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
3497 ok(hr == S_OK, "ret %08x\n", hr );
3499 IXMLDOMElement_Release(pElement);
3502 /* String */
3503 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
3504 ok(hr == S_OK, "ret %08x\n", hr );
3505 if(hr == S_OK)
3507 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3509 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
3510 ok(hr == S_OK, "ret %08x\n", hr );
3512 IXMLDOMElement_Release(pElement);
3515 /* Number */
3516 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
3517 ok(hr == S_OK, "ret %08x\n", hr );
3518 if(hr == S_OK)
3520 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3522 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
3523 ok(hr == S_OK, "ret %08x\n", hr );
3525 IXMLDOMElement_Release(pElement);
3528 /* Int */
3529 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
3530 ok(hr == S_OK, "ret %08x\n", hr );
3531 if(hr == S_OK)
3533 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3535 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
3536 ok(hr == S_OK, "ret %08x\n", hr );
3538 IXMLDOMElement_Release(pElement);
3541 /* Fixed */
3542 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3543 ok(hr == S_OK, "ret %08x\n", hr );
3544 if(hr == S_OK)
3546 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3548 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3549 ok(hr == S_OK, "ret %08x\n", hr );
3551 IXMLDOMElement_Release(pElement);
3554 /* DateTime */
3555 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3556 ok(hr == S_OK, "ret %08x\n", hr );
3557 if(hr == S_OK)
3559 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3561 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3562 ok(hr == S_OK, "ret %08x\n", hr );
3564 IXMLDOMElement_Release(pElement);
3567 /* DateTime TZ */
3568 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3569 ok(hr == S_OK, "ret %08x\n", hr );
3570 if(hr == S_OK)
3572 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3574 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3575 ok(hr == S_OK, "ret %08x\n", hr );
3577 IXMLDOMElement_Release(pElement);
3580 /* Date */
3581 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3582 ok(hr == S_OK, "ret %08x\n", hr );
3583 if(hr == S_OK)
3585 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3587 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3588 ok(hr == S_OK, "ret %08x\n", hr );
3590 IXMLDOMElement_Release(pElement);
3593 /* Time */
3594 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3595 ok(hr == S_OK, "ret %08x\n", hr );
3596 if(hr == S_OK)
3598 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3600 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3601 ok(hr == S_OK, "ret %08x\n", hr );
3603 IXMLDOMElement_Release(pElement);
3606 /* Time.tz */
3607 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3608 ok(hr == S_OK, "ret %08x\n", hr );
3609 if(hr == S_OK)
3611 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3613 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3614 ok(hr == S_OK, "ret %08x\n", hr );
3616 IXMLDOMElement_Release(pElement);
3619 /* I1 */
3620 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3621 ok(hr == S_OK, "ret %08x\n", hr );
3622 if(hr == S_OK)
3624 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3626 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3627 ok(hr == S_OK, "ret %08x\n", hr );
3629 IXMLDOMElement_Release(pElement);
3632 /* I2 */
3633 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3634 ok(hr == S_OK, "ret %08x\n", hr );
3635 if(hr == S_OK)
3637 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3639 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3640 ok(hr == S_OK, "ret %08x\n", hr );
3642 IXMLDOMElement_Release(pElement);
3645 /* I4 */
3646 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3647 ok(hr == S_OK, "ret %08x\n", hr );
3648 if(hr == S_OK)
3650 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3652 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3653 ok(hr == S_OK, "ret %08x\n", hr );
3655 IXMLDOMElement_Release(pElement);
3658 /* UI1 */
3659 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3660 ok(hr == S_OK, "ret %08x\n", hr );
3661 if(hr == S_OK)
3663 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3665 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3666 ok(hr == S_OK, "ret %08x\n", hr );
3668 IXMLDOMElement_Release(pElement);
3671 /* UI2 */
3672 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3673 ok(hr == S_OK, "ret %08x\n", hr );
3674 if(hr == S_OK)
3676 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3678 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3679 ok(hr == S_OK, "ret %08x\n", hr );
3681 IXMLDOMElement_Release(pElement);
3684 /* UI4 */
3685 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3686 ok(hr == S_OK, "ret %08x\n", hr );
3687 if(hr == S_OK)
3689 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3691 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3692 ok(hr == S_OK, "ret %08x\n", hr );
3694 IXMLDOMElement_Release(pElement);
3697 /* r4 */
3698 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3699 ok(hr == S_OK, "ret %08x\n", hr );
3700 if(hr == S_OK)
3702 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3704 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3705 ok(hr == S_OK, "ret %08x\n", hr );
3707 IXMLDOMElement_Release(pElement);
3710 /* r8 */
3711 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3712 ok(hr == S_OK, "ret %08x\n", hr );
3713 if(hr == S_OK)
3715 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3717 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3718 ok(hr == S_OK, "ret %08x\n", hr );
3720 IXMLDOMElement_Release(pElement);
3723 /* float */
3724 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3725 ok(hr == S_OK, "ret %08x\n", hr );
3726 if(hr == S_OK)
3728 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3730 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3731 ok(hr == S_OK, "ret %08x\n", hr );
3733 IXMLDOMElement_Release(pElement);
3736 /* uuid */
3737 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3738 ok(hr == S_OK, "ret %08x\n", hr );
3739 if(hr == S_OK)
3741 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3743 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3744 ok(hr == S_OK, "ret %08x\n", hr );
3746 IXMLDOMElement_Release(pElement);
3749 /* bin.hex */
3750 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3751 ok(hr == S_OK, "ret %08x\n", hr );
3752 if(hr == S_OK)
3754 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3756 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3757 ok(hr == S_OK, "ret %08x\n", hr );
3759 IXMLDOMElement_Release(pElement);
3762 /* bin.base64 */
3763 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3764 ok(hr == S_OK, "ret %08x\n", hr );
3765 if(hr == S_OK)
3767 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3769 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3770 ok(hr == S_OK, "ret %08x\n", hr );
3772 IXMLDOMElement_Release(pElement);
3775 /* Check changing types */
3776 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3777 ok(hr == S_OK, "ret %08x\n", hr );
3778 if(hr == S_OK)
3780 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3782 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3783 ok(hr == S_OK, "ret %08x\n", hr );
3785 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3786 ok(hr == S_OK, "ret %08x\n", hr );
3788 IXMLDOMElement_Release(pElement);
3791 IXMLDOMElement_Release(pRoot);
3795 IXMLDOMDocument_Release(doc);
3797 free_bstrs();
3800 static void test_DocumentSaveToDocument(void)
3802 IXMLDOMDocument *doc = NULL;
3803 IXMLDOMDocument *doc2 = NULL;
3804 IXMLDOMElement *pRoot;
3806 HRESULT hr;
3808 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3809 if( hr != S_OK )
3810 return;
3812 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3813 if( hr != S_OK )
3815 IXMLDOMDocument_Release(doc);
3816 return;
3819 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3820 ok(hr == S_OK, "ret %08x\n", hr );
3821 if(hr == S_OK)
3823 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3824 ok(hr == S_OK, "ret %08x\n", hr );
3825 if(hr == S_OK)
3827 VARIANT vDoc;
3828 BSTR sOrig;
3829 BSTR sNew;
3831 V_VT(&vDoc) = VT_UNKNOWN;
3832 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3834 hr = IXMLDOMDocument_save(doc, vDoc);
3835 ok(hr == S_OK, "ret %08x\n", hr );
3837 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3838 ok(hr == S_OK, "ret %08x\n", hr );
3840 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3841 ok(hr == S_OK, "ret %08x\n", hr );
3843 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3845 SysFreeString(sOrig);
3846 SysFreeString(sNew);
3850 IXMLDOMDocument_Release(doc2);
3851 IXMLDOMDocument_Release(doc);
3854 static void test_DocumentSaveToFile(void)
3856 IXMLDOMDocument *doc = NULL;
3857 IXMLDOMElement *pRoot;
3858 HANDLE file;
3859 char buffer[100];
3860 DWORD read = 0;
3861 HRESULT hr;
3863 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3864 if( hr != S_OK )
3865 return;
3867 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3868 ok(hr == S_OK, "ret %08x\n", hr );
3869 if(hr == S_OK)
3871 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3872 ok(hr == S_OK, "ret %08x\n", hr );
3873 if(hr == S_OK)
3875 VARIANT vFile;
3877 V_VT(&vFile) = VT_BSTR;
3878 V_BSTR(&vFile) = _bstr_("test.xml");
3880 hr = IXMLDOMDocument_save(doc, vFile);
3881 ok(hr == S_OK, "ret %08x\n", hr );
3885 IXMLDOMElement_Release(pRoot);
3886 IXMLDOMDocument_Release(doc);
3888 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3889 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3890 if(file == INVALID_HANDLE_VALUE)
3891 return;
3893 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3894 ok(read != 0, "could not read file\n");
3895 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3897 CloseHandle(file);
3898 DeleteFile("test.xml");
3901 static void test_testTransforms(void)
3903 IXMLDOMDocument *doc = NULL;
3904 IXMLDOMDocument *docSS = NULL;
3905 IXMLDOMNode *pNode;
3906 VARIANT_BOOL bSucc;
3908 HRESULT hr;
3910 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3911 if( hr != S_OK )
3912 return;
3914 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3915 if( hr != S_OK )
3917 IXMLDOMDocument_Release(doc);
3918 return;
3921 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3922 ok(hr == S_OK, "ret %08x\n", hr );
3924 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3925 ok(hr == S_OK, "ret %08x\n", hr );
3927 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3928 ok(hr == S_OK, "ret %08x\n", hr );
3929 if(hr == S_OK)
3931 BSTR bOut;
3933 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3934 ok(hr == S_OK, "ret %08x\n", hr );
3935 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3936 SysFreeString(bOut);
3938 IXMLDOMNode_Release(pNode);
3941 IXMLDOMDocument_Release(docSS);
3942 IXMLDOMDocument_Release(doc);
3944 free_bstrs();
3947 static void test_Namespaces(void)
3949 IXMLDOMDocument2 *doc = NULL;
3950 IXMLDOMNode *pNode;
3951 IXMLDOMNode *pNode2 = NULL;
3952 VARIANT_BOOL bSucc;
3953 HRESULT hr;
3954 BSTR str;
3955 static const CHAR szNamespacesXML[] =
3956 "<?xml version=\"1.0\"?>\n"
3957 "<root xmlns:WEB='http://www.winehq.org'>\n"
3958 "<WEB:Site version=\"1.0\" />\n"
3959 "</root>";
3961 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3962 if( hr != S_OK )
3963 return;
3965 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3966 ok(hr == S_OK, "ret %08x\n", hr );
3967 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3969 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3970 ok(hr == S_OK, "ret %08x\n", hr );
3971 if(hr == S_OK)
3973 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3974 ok( hr == S_OK, "ret %08x\n", hr );
3975 ok( pNode2 != NULL, "pNode2 == NULL\n");
3977 /* Test get_prefix */
3978 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3979 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3980 /* NOTE: Need to test that arg2 gets cleared on Error. */
3982 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3983 ok( hr == S_OK, "ret %08x\n", hr );
3984 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3985 SysFreeString(str);
3987 /* Test get_namespaceURI */
3988 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3989 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3990 /* NOTE: Need to test that arg2 gets cleared on Error. */
3992 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3993 ok( hr == S_OK, "ret %08x\n", hr );
3994 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3995 SysFreeString(str);
3997 IXMLDOMNode_Release(pNode2);
3998 IXMLDOMNode_Release(pNode);
4001 IXMLDOMDocument2_Release(doc);
4003 free_bstrs();
4006 static void test_FormattingXML(void)
4008 IXMLDOMDocument2 *doc = NULL;
4009 IXMLDOMElement *pElement;
4010 VARIANT_BOOL bSucc;
4011 HRESULT hr;
4012 BSTR str;
4013 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
4014 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
4016 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
4017 if( hr != S_OK )
4018 return;
4020 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
4021 ok(hr == S_OK, "ret %08x\n", hr );
4022 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4024 if(bSucc == VARIANT_TRUE)
4026 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
4027 ok(hr == S_OK, "ret %08x\n", hr );
4028 if(hr == S_OK)
4030 hr = IXMLDOMElement_get_xml(pElement, &str);
4031 ok(hr == S_OK, "ret %08x\n", hr );
4032 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
4033 SysFreeString(str);
4035 IXMLDOMElement_Release(pElement);
4039 IXMLDOMDocument2_Release(doc);
4041 free_bstrs();
4044 static void test_NodeTypeValue(void)
4046 IXMLDOMDocument2 *doc = NULL;
4047 IXMLDOMNode *pNode;
4048 VARIANT_BOOL bSucc;
4049 HRESULT hr;
4050 VARIANT v;
4052 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
4053 if( hr != S_OK )
4054 return;
4056 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
4057 ok(hr == S_OK, "ret %08x\n", hr );
4058 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4059 if(bSucc == VARIANT_TRUE)
4061 hr = IXMLDOMDocument2_get_nodeValue(doc, NULL);
4062 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4064 V_VT(&v) = VT_BSTR;
4065 V_BSTR(&v) = NULL;
4066 hr = IXMLDOMDocument2_get_nodeValue(doc, &v);
4067 ok(hr == S_FALSE, "ret %08x\n", hr );
4068 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
4070 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, NULL);
4071 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4073 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, &v);
4074 ok(hr == S_FALSE, "ret %08x\n", hr );
4076 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string"), &pNode);
4077 ok(hr == S_OK, "ret %08x\n", hr );
4078 if(hr == S_OK)
4080 V_VT(&v) = VT_BSTR;
4081 V_BSTR(&v) = NULL;
4082 hr = IXMLDOMNode_get_nodeValue(pNode, &v);
4083 ok(hr == S_FALSE, "ret %08x\n", hr );
4084 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
4086 hr = IXMLDOMNode_get_nodeTypedValue(pNode, NULL);
4087 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4089 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4090 ok(hr == S_OK, "ret %08x\n", hr );
4091 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4092 ok(!lstrcmpW( V_BSTR(&v), _bstr_("Wine") ), "incorrect value\n");
4093 VariantClear( &v );
4095 IXMLDOMNode_Release(pNode);
4098 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string2"), &pNode);
4099 ok(hr == S_OK, "ret %08x\n", hr );
4100 if(hr == S_OK)
4102 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4103 ok(hr == S_OK, "ret %08x\n", hr );
4104 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4105 ok(!lstrcmpW( V_BSTR(&v), _bstr_("String") ), "incorrect value\n");
4106 VariantClear( &v );
4108 IXMLDOMNode_Release(pNode);
4111 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number"), &pNode);
4112 ok(hr == S_OK, "ret %08x\n", hr );
4113 if(hr == S_OK)
4115 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4116 ok(hr == S_OK, "ret %08x\n", hr );
4117 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4118 ok(!lstrcmpW( V_BSTR(&v), _bstr_("12.44") ), "incorrect value\n");
4119 VariantClear( &v );
4121 IXMLDOMNode_Release(pNode);
4124 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number2"), &pNode);
4125 ok(hr == S_OK, "ret %08x\n", hr );
4126 if(hr == S_OK)
4128 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4129 ok(hr == S_OK, "ret %08x\n", hr );
4130 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4131 ok(!lstrcmpW( V_BSTR(&v), _bstr_("-3.71e3") ), "incorrect value\n");
4132 VariantClear( &v );
4134 IXMLDOMNode_Release(pNode);
4137 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/int"), &pNode);
4138 ok(hr == S_OK, "ret %08x\n", hr );
4139 if(hr == S_OK)
4141 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4142 ok(hr == S_OK, "ret %08x\n", hr );
4143 ok(V_VT(&v) == VT_I4, "incorrect type\n");
4144 ok(V_I4(&v) == -13, "incorrect value\n");
4145 VariantClear( &v );
4147 IXMLDOMNode_Release(pNode);
4150 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/fixed"), &pNode);
4151 ok(hr == S_OK, "ret %08x\n", hr );
4152 if(hr == S_OK)
4154 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4155 ok(hr == S_OK, "ret %08x\n", hr );
4156 ok(V_VT(&v) == VT_CY, "incorrect type\n");
4157 VariantClear(&v);
4159 IXMLDOMNode_Release(pNode);
4162 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/bool"), &pNode);
4163 ok(hr == S_OK, "ret %08x\n", hr );
4164 if(hr == S_OK)
4166 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4167 ok(hr == S_OK, "ret %08x\n", hr );
4168 ok(V_VT(&v) == VT_BOOL, "incorrect type\n");
4169 ok(V_BOOL(&v) == VARIANT_TRUE, "incorrect value\n");
4170 VariantClear( &v );
4172 IXMLDOMNode_Release(pNode);
4175 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/datetime"), &pNode);
4176 ok(hr == S_OK, "ret %08x\n", hr );
4177 if(hr == S_OK)
4179 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4180 ok(hr == S_OK, "ret %08x\n", hr );
4181 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4182 double_eq(40135.13996527778, V_DATE(&v));
4183 VariantClear( &v );
4185 IXMLDOMNode_Release(pNode);
4188 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/datetimetz"), &pNode);
4189 ok(hr == S_OK, "ret %08x\n", hr );
4190 if(hr == S_OK)
4192 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4193 ok(hr == S_OK, "ret %08x\n", hr );
4194 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4195 double_eq(37813.59302083334, V_DATE(&v));
4196 VariantClear( &v );
4198 IXMLDOMNode_Release(pNode);
4201 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/date"), &pNode);
4202 ok(hr == S_OK, "ret %08x\n", hr );
4203 if(hr == S_OK)
4205 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4206 ok(hr == S_OK, "ret %08x\n", hr );
4207 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4208 double_eq(665413.0, V_DATE(&v));
4209 VariantClear( &v );
4211 IXMLDOMNode_Release(pNode);
4214 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/time"), &pNode);
4215 ok(hr == S_OK, "ret %08x\n", hr );
4216 if(hr == S_OK)
4218 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4219 ok(hr == S_OK, "ret %08x\n", hr );
4220 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4221 double_eq(0.5813888888888888, V_DATE(&v));
4222 VariantClear( &v );
4224 IXMLDOMNode_Release(pNode);
4227 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/timetz"), &pNode);
4228 ok(hr == S_OK, "ret %08x\n", hr );
4229 if(hr == S_OK)
4231 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4232 ok(hr == S_OK, "ret %08x\n", hr );
4233 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4234 double_eq(1.112511574074074, V_DATE(&v));
4235 VariantClear( &v );
4237 IXMLDOMNode_Release(pNode);
4240 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i1"), &pNode);
4241 ok(hr == S_OK, "ret %08x\n", hr );
4242 if(hr == S_OK)
4244 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4245 ok(hr == S_OK, "ret %08x\n", hr );
4246 ok(V_VT(&v) == VT_I1, "incorrect type\n");
4247 ok(V_I1(&v) == -13, "incorrect value\n");
4248 VariantClear( &v );
4250 IXMLDOMNode_Release(pNode);
4253 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i2"), &pNode);
4254 ok(hr == S_OK, "ret %08x\n", hr );
4255 if(hr == S_OK)
4257 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4258 ok(hr == S_OK, "ret %08x\n", hr );
4259 ok(V_VT(&v) == VT_I2, "incorrect type\n");
4260 ok(V_I2(&v) == 31915, "incorrect value\n");
4261 VariantClear( &v );
4263 IXMLDOMNode_Release(pNode);
4266 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i4"), &pNode);
4267 ok(hr == S_OK, "ret %08x\n", hr );
4268 if(hr == S_OK)
4270 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4271 ok(hr == S_OK, "ret %08x\n", hr );
4272 ok(V_VT(&v) == VT_I4, "incorrect type\n");
4273 ok(V_I4(&v) == -312232, "incorrect value\n");
4274 VariantClear(&v);
4276 IXMLDOMNode_Release(pNode);
4279 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui1"), &pNode);
4280 ok(hr == S_OK, "ret %08x\n", hr );
4281 if(hr == S_OK)
4283 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4284 ok(hr == S_OK, "ret %08x\n", hr );
4285 ok(V_VT(&v) == VT_UI1, "incorrect type\n");
4286 ok(V_UI1(&v) == 123, "incorrect value\n");
4287 VariantClear(&v);
4289 IXMLDOMNode_Release(pNode);
4292 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui2"), &pNode);
4293 ok(hr == S_OK, "ret %08x\n", hr );
4294 if(hr == S_OK)
4296 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4297 ok(hr == S_OK, "ret %08x\n", hr );
4298 ok(V_VT(&v) == VT_UI2, "incorrect type\n");
4299 ok(V_UI2(&v) == 48282, "incorrect value\n");
4300 VariantClear(&v);
4302 IXMLDOMNode_Release(pNode);
4305 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui4"), &pNode);
4306 ok(hr == S_OK, "ret %08x\n", hr );
4307 if(hr == S_OK)
4309 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4310 ok(hr == S_OK, "ret %08x\n", hr );
4311 ok(V_VT(&v) == VT_UI4, "incorrect type\n");
4312 ok(V_UI4(&v) == 949281, "incorrect value\n");
4313 VariantClear(&v);
4315 IXMLDOMNode_Release(pNode);
4318 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/r4"), &pNode);
4319 ok(hr == S_OK, "ret %08x\n", hr );
4320 if(hr == S_OK)
4322 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4323 ok(hr == S_OK, "ret %08x\n", hr );
4324 ok(V_VT(&v) == VT_R4, "incorrect type\n");
4325 double_eq(213124.0, V_R4(&v));
4326 VariantClear(&v);
4328 IXMLDOMNode_Release(pNode);
4331 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/r8"), &pNode);
4332 ok(hr == S_OK, "ret %08x\n", hr );
4333 if(hr == S_OK)
4335 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4336 ok(hr == S_OK, "ret %08x\n", hr );
4337 ok(V_VT(&v) == VT_R8, "incorrect type\n");
4338 double_eq(0.412, V_R8(&v));
4339 VariantClear(&v);
4341 IXMLDOMNode_Release(pNode);
4344 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/float"), &pNode);
4345 ok(hr == S_OK, "ret %08x\n", hr );
4346 if(hr == S_OK)
4348 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4349 ok(hr == S_OK, "ret %08x\n", hr );
4350 ok(V_VT(&v) == VT_R8, "incorrect type\n");
4351 double_eq(41221.421, V_R8(&v));
4352 VariantClear(&v);
4354 IXMLDOMNode_Release(pNode);
4357 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/uuid"), &pNode);
4358 ok(hr == S_OK, "ret %08x\n", hr );
4359 if(hr == S_OK)
4361 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4362 ok(hr == S_OK, "ret %08x\n", hr );
4363 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4364 ok(!lstrcmpW(V_BSTR(&v), _bstr_("333C7BC4-460F-11D0-BC04-0080C7055a83")), "incorrect value\n");
4365 VariantClear(&v);
4367 IXMLDOMNode_Release(pNode);
4370 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/binhex"), &pNode);
4371 ok(hr == S_OK, "ret %08x\n", hr );
4372 if(hr == S_OK)
4374 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
4376 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4377 ok(hr == S_OK, "ret %08x\n", hr );
4378 ok(V_VT(&v) == (VT_ARRAY|VT_UI1), "incorrect type\n");
4379 ok(V_ARRAY(&v)->rgsabound[0].cElements == 6, "incorrect array size\n");
4380 if(V_ARRAY(&v)->rgsabound[0].cElements == 6)
4381 ok(!memcmp(bytes, V_ARRAY(&v)->pvData, sizeof(bytes)), "incorrect value\n");
4382 VariantClear(&v);
4384 IXMLDOMNode_Release(pNode);
4387 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/binbase64"), &pNode);
4388 ok(hr == S_OK, "ret %08x\n", hr );
4389 if(hr == S_OK)
4391 BYTE bytes[] = {0x62,0x61,0x73,0x65,0x36,0x34,0x20,0x74,0x65,0x73,0x74};
4393 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4394 ok(hr == S_OK, "ret %08x\n", hr );
4395 ok(V_VT(&v) == (VT_ARRAY|VT_UI1), "incorrect type\n");
4396 ok(V_ARRAY(&v)->rgsabound[0].cElements == 11, "incorrect array size\n");
4397 if(V_ARRAY(&v)->rgsabound[0].cElements == 11)
4398 ok(!memcmp(bytes, V_ARRAY(&v)->pvData, sizeof(bytes)), "incorrect value\n");
4399 VariantClear(&v);
4401 IXMLDOMNode_Release(pNode);
4405 IXMLDOMDocument2_Release(doc);
4407 free_bstrs();
4410 static void test_TransformWithLoadingLocalFile(void)
4412 IXMLDOMDocument2 *doc = NULL;
4413 IXMLDOMDocument2 *xsl = NULL;
4414 IXMLDOMNode *pNode;
4415 VARIANT_BOOL bSucc;
4416 HRESULT hr;
4417 HANDLE file;
4418 DWORD dwWritten;
4419 char lpPathBuffer[MAX_PATH];
4420 int i;
4422 /* Create a Temp File. */
4423 GetTempPathA(MAX_PATH, lpPathBuffer);
4424 strcat(lpPathBuffer, "customers.xml" );
4426 file = CreateFile(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
4427 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
4428 if(file == INVALID_HANDLE_VALUE)
4429 return;
4431 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
4432 CloseHandle(file);
4434 /* Correct path to not include a escape character. */
4435 for(i=0; i < strlen(lpPathBuffer); i++)
4437 if(lpPathBuffer[i] == '\\')
4438 lpPathBuffer[i] = '/';
4441 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
4442 if( hr != S_OK )
4443 return;
4445 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&xsl );
4446 if( hr != S_OK )
4448 IXMLDOMDocument2_Release(doc);
4449 return;
4452 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
4453 ok(hr == S_OK, "ret %08x\n", hr );
4454 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4455 if(bSucc == VARIANT_TRUE)
4457 BSTR sXSL;
4458 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
4459 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
4460 BSTR sFileName = _bstr_(lpPathBuffer);
4461 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
4463 sXSL = SysAllocStringLen(NULL, nLegnth);
4464 lstrcpyW(sXSL, sPart1);
4465 lstrcatW(sXSL, sFileName);
4466 lstrcatW(sXSL, sPart2);
4468 hr = IXMLDOMDocument2_loadXML(xsl, sXSL, &bSucc);
4469 ok(hr == S_OK, "ret %08x\n", hr );
4470 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4471 if(bSucc == VARIANT_TRUE)
4473 BSTR sResult;
4475 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (LPVOID*)&pNode );
4476 ok(hr == S_OK, "ret %08x\n", hr );
4477 if(hr == S_OK)
4479 /* This will load the temp file via the XSL */
4480 hr = IXMLDOMDocument2_transformNode(doc, pNode, &sResult);
4481 ok(hr == S_OK, "ret %08x\n", hr );
4482 if(hr == S_OK)
4484 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
4485 SysFreeString(sResult);
4488 IXMLDOMNode_Release(pNode);
4492 SysFreeString(sXSL);
4495 IXMLDOMDocument2_Release(doc);
4496 IXMLDOMDocument2_Release(xsl);
4498 DeleteFile(lpPathBuffer);
4499 free_bstrs();
4502 START_TEST(domdoc)
4504 HRESULT r;
4506 r = CoInitialize( NULL );
4507 ok( r == S_OK, "failed to init com\n");
4509 test_domdoc();
4510 test_domnode();
4511 test_refs();
4512 test_create();
4513 test_getElementsByTagName();
4514 test_get_text();
4515 test_get_childNodes();
4516 test_removeChild();
4517 test_replaceChild();
4518 test_removeNamedItem();
4519 test_XMLHTTP();
4520 test_IXMLDOMDocument2();
4521 test_XPath();
4522 test_cloneNode();
4523 test_xmlTypes();
4524 test_nodeTypeTests();
4525 test_DocumentSaveToDocument();
4526 test_DocumentSaveToFile();
4527 test_testTransforms();
4528 test_Namespaces();
4529 test_FormattingXML();
4530 test_NodeTypeValue();
4531 test_TransformWithLoadingLocalFile();
4533 CoUninitialize();