[MSXML3_WINETEST]
[reactos.git] / rostests / winetests / msxml3 / domdoc.c
1 /*
2 * XML test
3 *
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
6 *
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.
11 *
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.
16 *
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
20 */
21
22
23 #define COBJMACROS
24
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>
33
34 #include "wine/test.h"
35
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
40 };
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
45 };
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
50 };
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
55 };
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
73 };
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
86 };
87
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";
120
121 static const CHAR szTransformXML[] =
122 "<?xml version=\"1.0\"?>\n"
123 "<greeting>\n"
124 "Hello World\n"
125 "</greeting>";
126
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>";
143
144 static const CHAR szTransformOutput[] =
145 "<html><body><h1>"
146 "Hello World"
147 "</h1></body></html>";
148
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>";
177
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(\"";
185
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>";
202
203 static const CHAR szBasicTransformXML[] =
204 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
205
206 static const CHAR szBasicTransformOutput[] =
207 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
208
209 static const WCHAR szNonExistentFile[] = {
210 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
211 };
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
214 };
215 static const WCHAR szDocument[] = {
216 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
217 };
218
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};
228
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 };
232
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 };
240
241 static WCHAR szAttribute[] = {'A','t','t','r',0 };
242 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
243
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 };
251
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};
255
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); \
261 }
262
263 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
264
265 #define ole_check(expr) { \
266 HRESULT r = expr; \
267 ok(r == S_OK, #expr " returned %x\n", r); \
268 }
269
270 #define ole_expect(expr, expect) { \
271 HRESULT r = expr; \
272 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
273 }
274
275 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
276
277 static BSTR alloc_str_from_narrow(const char *str)
278 {
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;
283 }
284
285 BSTR alloced_bstrs[256];
286 int alloced_bstrs_count = 0;
287
288 static BSTR _bstr_(const char *str)
289 {
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++];
293 }
294
295 static void free_bstrs(void)
296 {
297 int i;
298 for (i = 0; i < alloced_bstrs_count; i++)
299 SysFreeString(alloced_bstrs[i]);
300 alloced_bstrs_count = 0;
301 }
302
303 static VARIANT _variantbstr_(const char *str)
304 {
305 VARIANT v;
306 V_VT(&v) = VT_BSTR;
307 V_BSTR(&v) = _bstr_(str);
308 return v;
309 }
310
311 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
312 {
313 for (;;)
314 {
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++;
321 }
322 }
323
324 static BOOL compareIgnoreReturnsWhitespace(BSTR sLeft, BSTR sRight)
325 {
326 /* MSXML3 inserts whitespace where as libxml doesn't. */
327 for (;;)
328 {
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++;
335 }
336 }
337
338 static void get_str_for_type(DOMNodeType type, char *buf)
339 {
340 switch (type)
341 {
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);
353 }
354 }
355
356 #define test_disp(u) _test_disp(__LINE__,u)
357 static void _test_disp(unsigned line, IUnknown *unk)
358 {
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;
366
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;
371
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);
376
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 );
381
382 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
383 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
384
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);
388
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);
393
394 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
395 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
396
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);
401
402 IDispatchEx_Release(dispex);
403 }
404
405 static int get_node_position(IXMLDOMNode *node)
406 {
407 HRESULT r;
408 int pos = 0;
409
410 IXMLDOMNode_AddRef(node);
411 do
412 {
413 IXMLDOMNode *new_node;
414
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;
422 }
423
424 static void node_to_string(IXMLDOMNode *node, char *buf)
425 {
426 HRESULT r = S_OK;
427 DOMNodeType type;
428
429 if (node == NULL)
430 {
431 lstrcpyA(buf, "(null)");
432 return;
433 }
434
435 IXMLDOMNode_AddRef(node);
436 while (r == S_OK)
437 {
438 IXMLDOMNode *new_node;
439
440 ole_check(IXMLDOMNode_get_nodeType(node, &type));
441 get_str_for_type(type, buf);
442 buf+=strlen(buf);
443
444 if (type == NODE_ATTRIBUTE)
445 {
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);
453
454 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
455 }
456 else
457 {
458 int pos = get_node_position(node);
459 DOMNodeType parent_type = NODE_INVALID;
460 r = IXMLDOMNode_get_parentNode(node, &new_node);
461
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)
467 {
468 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
469 pos++;
470 }
471 wsprintf(buf, "%d", pos);
472 buf += strlen(buf);
473 }
474
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++) = '.';
480 }
481
482 *buf = 0;
483 }
484
485 static char *list_to_string(IXMLDOMNodeList *list)
486 {
487 static char buf[4096];
488 char *pos = buf;
489 LONG len = 0;
490 int i;
491
492 if (list == NULL)
493 {
494 lstrcpyA(buf, "(null)");
495 return buf;
496 }
497 ole_check(IXMLDOMNodeList_get_length(list, &len));
498 for (i = 0; i < len; i++)
499 {
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);
507 }
508 *pos = 0;
509 return buf;
510 }
511
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); }
514
515 static void test_domdoc( void )
516 {
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;
533
534 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
535 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
536 if( r != S_OK )
537 return;
538
539 test_disp((IUnknown*)doc);
540
541 /* try some stupid things */
542 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
543 ok( r == S_FALSE, "loadXML failed\n");
544
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");
549
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;
556
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 );
561
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 );
569
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");
573
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");
578
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 );
585
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 );
592
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");
598
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 );
606
607 /* check if nodename is correct */
608 r = IXMLDOMDocument_get_nodeName( doc, NULL );
609 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
610
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 );
618
619 /* test put_text */
620 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
621 ok( r == E_FAIL, "ret %08x\n", r );
622
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 )
628 {
629 IObjectIdentity *ident;
630 BSTR tag = NULL;
631
632 test_disp((IUnknown*)element);
633
634 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (LPVOID*)&ident );
635 ok( r == E_NOINTERFACE, "ret %08x\n", r);
636
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 );
643
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 );
650
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 );
658
659 IXMLDOMElement_Release( element );
660 element = NULL;
661 }
662
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");
670
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 );
678
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 );
686
687 r = IXMLDOMDocument_get_parseError( doc, &error );
688 ok( r == S_OK, "returns %08x\n", r );
689
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 );
694
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)
703 {
704 IXMLDOMNamedNodeMap *pAttribs;
705
706 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (LPVOID*)&element);
707 ok(r == E_NOINTERFACE, "ret %08x\n", r );
708
709 /* Text Last Child Checks */
710 r = IXMLDOMText_get_lastChild(nodetext, NULL);
711 ok(r == E_INVALIDARG, "ret %08x\n", r );
712
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");
717
718 /* test get_attributes */
719 r = IXMLDOMText_get_attributes( nodetext, NULL );
720 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
721
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");
726
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);
732
733 /* test length property */
734 r = IXMLDOMText_get_length(nodetext, NULL);
735 ok(r == E_INVALIDARG, "ret %08x\n", r );
736
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);
740
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);
746
747 /* put data Tests */
748 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
749 ok(r == S_OK, "ret %08x\n", r );
750
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);
756
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);
762
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);
768
769 /* test substringData */
770 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
771 ok(r == E_INVALIDARG, "ret %08x\n", r );
772
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");
778
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");
784
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");
790
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");
796
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);
802
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);
808
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);
814
815 /* test appendData */
816 r = IXMLDOMText_appendData(nodetext, NULL);
817 ok(r == S_OK, "ret %08x\n", r );
818
819 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
820 ok(r == S_OK, "ret %08x\n", r );
821
822 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
823 ok(r == S_OK, "ret %08x\n", r );
824
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);
829
830 /* test insertData */
831 str = SysAllocStringLen(NULL, 0);
832 r = IXMLDOMText_insertData(nodetext, -1, str);
833 ok(r == S_OK, "ret %08x\n", r );
834
835 r = IXMLDOMText_insertData(nodetext, -1, NULL);
836 ok(r == S_OK, "ret %08x\n", r );
837
838 r = IXMLDOMText_insertData(nodetext, 1000, str);
839 ok(r == S_OK, "ret %08x\n", r );
840
841 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
842 ok(r == S_OK, "ret %08x\n", r );
843
844 r = IXMLDOMText_insertData(nodetext, 0, NULL);
845 ok(r == S_OK, "ret %08x\n", r );
846
847 r = IXMLDOMText_insertData(nodetext, 0, str);
848 ok(r == S_OK, "ret %08x\n", r );
849 SysFreeString(str);
850
851 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
852 ok(r == E_INVALIDARG, "ret %08x\n", r );
853
854 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
855 ok(r == E_INVALIDARG, "ret %08x\n", r );
856
857 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
858 ok(r == S_OK, "ret %08x\n", r );
859
860 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
861 ok(r == S_OK, "ret %08x\n", r );
862
863 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
864 ok(r == S_OK, "ret %08x\n", r );
865
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);
870
871 /* delete data */
872 /* invalid arguments */
873 r = IXMLDOMText_deleteData(nodetext, -1, 1);
874 ok(r == E_INVALIDARG, "ret %08x\n", r );
875
876 r = IXMLDOMText_deleteData(nodetext, 0, 0);
877 ok(r == S_OK, "ret %08x\n", r );
878
879 r = IXMLDOMText_deleteData(nodetext, 0, -1);
880 ok(r == E_INVALIDARG, "ret %08x\n", r );
881
882 r = IXMLDOMText_get_length(nodetext, &nLength);
883 ok(r == S_OK, "ret %08x\n", r );
884 ok(nLength == 43, "expected 43 got %d\n", nLength);
885
886 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
887 ok(r == S_OK, "ret %08x\n", r );
888
889 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
890 ok(r == E_INVALIDARG, "ret %08x\n", r );
891
892 /* delete from start */
893 r = IXMLDOMText_deleteData(nodetext, 0, 5);
894 ok(r == S_OK, "ret %08x\n", r );
895
896 r = IXMLDOMText_get_length(nodetext, &nLength);
897 ok(r == S_OK, "ret %08x\n", r );
898 ok(nLength == 38, "expected 38 got %d\n", nLength);
899
900 r = IXMLDOMText_get_text(nodetext, &str);
901 ok(r == S_OK, "ret %08x\n", r );
902 /* whitespace preserving needs to be handled here */
903 todo_wine ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
904 SysFreeString(str);
905
906 /* delete from end */
907 r = IXMLDOMText_deleteData(nodetext, 35, 3);
908 ok(r == S_OK, "ret %08x\n", r );
909
910 r = IXMLDOMText_get_length(nodetext, &nLength);
911 ok(r == S_OK, "ret %08x\n", r );
912 ok(nLength == 35, "expected 35 got %d\n", nLength);
913
914 r = IXMLDOMText_get_text(nodetext, &str);
915 ok(r == S_OK, "ret %08x\n", r );
916 todo_wine ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string\n");
917 SysFreeString(str);
918
919 /* delete from inside */
920 r = IXMLDOMText_deleteData(nodetext, 1, 33);
921 ok(r == S_OK, "ret %08x\n", r );
922
923 r = IXMLDOMText_get_length(nodetext, &nLength);
924 ok(r == S_OK, "ret %08x\n", r );
925 ok(nLength == 2, "expected 2 got %d\n", nLength);
926
927 r = IXMLDOMText_get_text(nodetext, &str);
928 ok(r == S_OK, "ret %08x\n", r );
929 todo_wine ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string\n");
930 SysFreeString(str);
931
932 /* delete whole data ... */
933 r = IXMLDOMText_get_length(nodetext, &nLength);
934 ok(r == S_OK, "ret %08x\n", r );
935
936 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
937 ok(r == S_OK, "ret %08x\n", r );
938 /* ... and try again with empty string */
939 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
940 ok(r == S_OK, "ret %08x\n", r );
941
942 /* test put_data */
943 V_VT(&var) = VT_BSTR;
944 V_BSTR(&var) = SysAllocString(szstr1);
945 r = IXMLDOMText_put_nodeValue(nodetext, var);
946 ok(r == S_OK, "ret %08x\n", r );
947 VariantClear(&var);
948
949 r = IXMLDOMText_get_text(nodetext, &str);
950 ok(r == S_OK, "ret %08x\n", r );
951 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string\n");
952 SysFreeString(str);
953
954 /* test put_data */
955 V_VT(&var) = VT_I4;
956 V_I4(&var) = 99;
957 r = IXMLDOMText_put_nodeValue(nodetext, var);
958 ok(r == S_OK, "ret %08x\n", r );
959 VariantClear(&var);
960
961 r = IXMLDOMText_get_text(nodetext, &str);
962 ok(r == S_OK, "ret %08x\n", r );
963 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string\n");
964 SysFreeString(str);
965
966 IXMLDOMText_Release( nodetext );
967 }
968
969 /* test Create Comment */
970 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
971 ok( r == E_INVALIDARG, "returns %08x\n", r );
972 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
973 ok( r == S_OK, "returns %08x\n", r );
974 if(node_comment)
975 {
976 /* Last Child Checks */
977 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
978 ok(r == E_INVALIDARG, "ret %08x\n", r );
979
980 nodeChild = (IXMLDOMNode*)0x1;
981 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
982 ok(r == S_FALSE, "ret %08x\n", r );
983 ok(nodeChild == NULL, "pLastChild not NULL\n");
984
985 IXMLDOMComment_Release( node_comment );
986 }
987
988 /* test Create Attribute */
989 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
990 ok( r == E_INVALIDARG, "returns %08x\n", r );
991 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
992 ok( r == S_OK, "returns %08x\n", r );
993 IXMLDOMText_Release( node_attr);
994
995 /* test Processing Instruction */
996 str = SysAllocStringLen(NULL, 0);
997 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
998 ok( r == E_INVALIDARG, "returns %08x\n", r );
999 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
1000 ok( r == E_FAIL, "returns %08x\n", r );
1001 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
1002 ok( r == E_FAIL, "returns %08x\n", r );
1003 SysFreeString(str);
1004
1005 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
1006 ok( r == S_OK, "returns %08x\n", r );
1007 if(nodePI)
1008 {
1009 /* Last Child Checks */
1010 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
1011 ok(r == E_INVALIDARG, "ret %08x\n", r );
1012
1013 nodeChild = (IXMLDOMNode*)0x1;
1014 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
1015 ok(r == S_FALSE, "ret %08x\n", r );
1016 ok(nodeChild == NULL, "nodeChild not NULL\n");
1017
1018 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
1019 ok(r == S_FALSE, "ret %08x\n", r );
1020 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
1021 VariantClear(&var);
1022
1023 /* test nodeName */
1024 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1025 ok(r == S_OK, "ret %08x\n", r );
1026 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1027 SysFreeString(str);
1028
1029 /* test Target */
1030 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
1031 ok(r == S_OK, "ret %08x\n", r );
1032 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
1033 SysFreeString(str);
1034
1035 /* test nodeTypeString */
1036 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
1037 ok(r == S_OK, "ret %08x\n", r );
1038 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
1039 SysFreeString(str);
1040
1041 /* test get_nodeValue */
1042 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
1043 ok(r == S_OK, "ret %08x\n", r );
1044 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1045 VariantClear(&var);
1046
1047 /* test get_data */
1048 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
1049 ok(r == S_OK, "ret %08x\n", r );
1050 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1051 SysFreeString(str);
1052
1053 /* test put_data */
1054 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
1055 ok(r == E_FAIL, "ret %08x\n", r );
1056
1057 /* test put_data */
1058 V_VT(&var) = VT_BSTR;
1059 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
1060 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
1061 ok(r == E_FAIL, "ret %08x\n", r );
1062 VariantClear(&var);
1063
1064 /* test get nodeName */
1065 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1066 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1067 ok(r == S_OK, "ret %08x\n", r );
1068 SysFreeString(str);
1069
1070 IXMLDOMProcessingInstruction_Release(nodePI);
1071 }
1072
1073 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1074 ok( r == S_OK, "ret %08x\n", r );
1075 if(r == S_OK)
1076 {
1077 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
1078 todo_wine ok( r == S_OK, "ret %08x\n", r );
1079 ISupportErrorInfo_Release( support_error );
1080 }
1081
1082 r = IXMLDOMDocument_Release( doc );
1083 ok( r == 0, "document ref count incorrect\n");
1084
1085 free_bstrs();
1086 }
1087
1088 static void test_domnode( void )
1089 {
1090 HRESULT r;
1091 IXMLDOMDocument *doc = NULL, *owner = NULL;
1092 IXMLDOMElement *element = NULL;
1093 IXMLDOMNamedNodeMap *map = NULL;
1094 IXMLDOMNode *node = NULL, *next = NULL;
1095 IXMLDOMNodeList *list = NULL;
1096 IXMLDOMAttribute *attr = NULL;
1097 DOMNodeType type = NODE_INVALID;
1098 VARIANT_BOOL b;
1099 BSTR str;
1100 VARIANT var;
1101 LONG count;
1102
1103 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1104 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1105 if( r != S_OK )
1106 return;
1107 if (!doc) {
1108 ok( FALSE, "no document\n");
1109 return;
1110 }
1111
1112 b = FALSE;
1113 str = SysAllocString( szComplete4 );
1114 r = IXMLDOMDocument_loadXML( doc, str, &b );
1115 ok( r == S_OK, "loadXML failed\n");
1116 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1117 SysFreeString( str );
1118
1119 b = 1;
1120 r = IXMLDOMNode_hasChildNodes( doc, &b );
1121 ok( r == S_OK, "hasChildNoes bad return\n");
1122 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1123
1124 r = IXMLDOMDocument_get_documentElement( doc, &element );
1125 ok( r == S_OK, "should be a document element\n");
1126 ok( element != NULL, "should be an element\n");
1127
1128 VariantInit(&var);
1129 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1130
1131 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1132 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1133
1134 r = IXMLDOMNode_get_nodeValue( doc, &var );
1135 ok( r == S_FALSE, "nextNode returned wrong code\n");
1136 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1137 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1138
1139 if (element)
1140 {
1141 owner = NULL;
1142 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1143 ok( r == S_OK, "get_ownerDocument return code\n");
1144 ok( owner != doc, "get_ownerDocument return\n");
1145 IXMLDOMDocument_Release(owner);
1146
1147 type = NODE_INVALID;
1148 r = IXMLDOMNode_get_nodeType( element, &type);
1149 ok( r == S_OK, "getNamedItem returned wrong code\n");
1150 ok( type == NODE_ELEMENT, "node not an element\n");
1151
1152 str = NULL;
1153 r = IXMLDOMNode_get_baseName( element, &str );
1154 ok( r == S_OK, "get_baseName returned wrong code\n");
1155 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1156 SysFreeString(str);
1157
1158 /* check if nodename is correct */
1159 r = IXMLDOMElement_get_nodeName( element, NULL );
1160 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1161
1162 /* content doesn't matter here */
1163 str = NULL;
1164 r = IXMLDOMElement_get_nodeName( element, &str );
1165 ok ( r == S_OK, "get_nodeName wrong code\n");
1166 ok ( str != NULL, "str is null\n");
1167 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1168 SysFreeString( str );
1169
1170 str = SysAllocString( szNonExistentFile );
1171 V_VT(&var) = VT_I4;
1172 V_I4(&var) = 0x1234;
1173 r = IXMLDOMElement_getAttribute( element, str, &var );
1174 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1175 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1176 VariantClear(&var);
1177
1178 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1179 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1180
1181 attr = (IXMLDOMAttribute*)0xdeadbeef;
1182 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1183 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1184 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1185 SysFreeString( str );
1186
1187 attr = (IXMLDOMAttribute*)0xdeadbeef;
1188 str = SysAllocString( szNonExistentAttribute );
1189 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1190 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1191 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1192 SysFreeString( str );
1193
1194 str = SysAllocString( szdl );
1195 V_VT(&var) = VT_I4;
1196 V_I4(&var) = 0x1234;
1197 r = IXMLDOMElement_getAttribute( element, str, &var );
1198 ok( r == S_OK, "getAttribute ret %08x\n", r );
1199 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1200 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1201 VariantClear( &var );
1202
1203 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1204 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1205
1206 r = IXMLDOMElement_getAttribute( element, str, NULL );
1207 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1208
1209 attr = NULL;
1210 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1211 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1212 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1213 if(attr)
1214 IXMLDOMAttribute_Release(attr);
1215
1216 SysFreeString( str );
1217
1218 r = IXMLDOMElement_get_attributes( element, &map );
1219 ok( r == S_OK, "get_attributes returned wrong code\n");
1220 ok( map != NULL, "should be attributes\n");
1221
1222 b = 1;
1223 r = IXMLDOMNode_hasChildNodes( element, &b );
1224 ok( r == S_OK, "hasChildNoes bad return\n");
1225 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1226 }
1227 else
1228 ok( FALSE, "no element\n");
1229
1230 if (map)
1231 {
1232 ISupportErrorInfo *support_error;
1233 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1234 ok( r == S_OK, "ret %08x\n", r );
1235
1236 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1237 todo_wine
1238 {
1239 ok( r == S_OK, "ret %08x\n", r );
1240 }
1241 ISupportErrorInfo_Release( support_error );
1242
1243 str = SysAllocString( szdl );
1244 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1245 ok( r == S_OK, "getNamedItem returned wrong code\n");
1246 ok( node != NULL, "should be attributes\n");
1247 IXMLDOMNode_Release(node);
1248 SysFreeString( str );
1249
1250 str = SysAllocString( szdl );
1251 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1252 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1253 SysFreeString( str );
1254
1255 /* something that isn't in szComplete4 */
1256 str = SysAllocString( szOpen );
1257 node = (IXMLDOMNode *) 1;
1258 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1259 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1260 ok( node == NULL, "getNamedItem should have returned NULL\n");
1261 SysFreeString( str );
1262
1263 /* test indexed access of attributes */
1264 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1265 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1266
1267 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1268 ok ( r == S_OK, "get_length wrong code\n");
1269 ok ( count == 1, "get_length != 1\n");
1270
1271 node = NULL;
1272 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1273 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1274 ok ( node == NULL, "there is no node\n");
1275
1276 node = NULL;
1277 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1278 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1279 ok ( node == NULL, "there is no attribute\n");
1280
1281 node = NULL;
1282 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1283 ok ( r == S_OK, "get_item (0) wrong code\n");
1284 ok ( node != NULL, "should be attribute\n");
1285
1286 r = IXMLDOMNode_get_nodeName( node, NULL );
1287 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1288
1289 /* content doesn't matter here */
1290 str = NULL;
1291 r = IXMLDOMNode_get_nodeName( node, &str );
1292 ok ( r == S_OK, "get_nodeName wrong code\n");
1293 ok ( str != NULL, "str is null\n");
1294 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1295 SysFreeString( str );
1296
1297 /* test sequential access of attributes */
1298 node = NULL;
1299 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1300 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1301 ok ( node != NULL, "nextNode, should be attribute\n");
1302
1303 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1304 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1305 ok ( node == NULL, "nextNode, there is no attribute\n");
1306
1307 r = IXMLDOMNamedNodeMap_reset( map );
1308 ok ( r == S_OK, "reset should return S_OK\n");
1309
1310 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1311 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1312 ok ( node != NULL, "nextNode, should be attribute\n");
1313 }
1314 else
1315 ok( FALSE, "no map\n");
1316
1317 if (node)
1318 {
1319 type = NODE_INVALID;
1320 r = IXMLDOMNode_get_nodeType( node, &type);
1321 ok( r == S_OK, "getNamedItem returned wrong code\n");
1322 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1323
1324 str = NULL;
1325 r = IXMLDOMNode_get_baseName( node, NULL );
1326 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1327
1328 str = NULL;
1329 r = IXMLDOMNode_get_baseName( node, &str );
1330 ok( r == S_OK, "get_baseName returned wrong code\n");
1331 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1332 SysFreeString( str );
1333
1334 r = IXMLDOMNode_get_nodeValue( node, &var );
1335 ok( r == S_OK, "returns %08x\n", r );
1336 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1337 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1338 VariantClear(&var);
1339
1340 r = IXMLDOMNode_get_childNodes( node, NULL );
1341 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1342
1343 r = IXMLDOMNode_get_childNodes( node, &list );
1344 ok( r == S_OK, "get_childNodes returned wrong code\n");
1345
1346 if (list)
1347 {
1348 r = IXMLDOMNodeList_nextNode( list, &next );
1349 ok( r == S_OK, "nextNode returned wrong code\n");
1350 }
1351 else
1352 ok( FALSE, "no childlist\n");
1353
1354 if (next)
1355 {
1356 b = 1;
1357 r = IXMLDOMNode_hasChildNodes( next, &b );
1358 ok( r == S_FALSE, "hasChildNoes bad return\n");
1359 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1360
1361 type = NODE_INVALID;
1362 r = IXMLDOMNode_get_nodeType( next, &type);
1363 ok( r == S_OK, "getNamedItem returned wrong code\n");
1364 ok( type == NODE_TEXT, "node not text\n");
1365
1366 str = (BSTR) 1;
1367 r = IXMLDOMNode_get_baseName( next, &str );
1368 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1369 ok( str == NULL, "basename was wrong\n");
1370 SysFreeString(str);
1371 }
1372 else
1373 ok( FALSE, "no next\n");
1374
1375 if (next)
1376 IXMLDOMNode_Release( next );
1377 next = NULL;
1378 if (list)
1379 IXMLDOMNodeList_Release( list );
1380 list = NULL;
1381 if (node)
1382 IXMLDOMNode_Release( node );
1383 }
1384 else
1385 ok( FALSE, "no node\n");
1386 node = NULL;
1387
1388 if (map)
1389 IXMLDOMNamedNodeMap_Release( map );
1390
1391 /* now traverse the tree from the root element */
1392 if (element)
1393 {
1394 r = IXMLDOMNode_get_childNodes( element, &list );
1395 ok( r == S_OK, "get_childNodes returned wrong code\n");
1396
1397 /* using get_item for child list doesn't advance the position */
1398 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1399 expect_node(node, "E2.E2.D1");
1400 IXMLDOMNode_Release(node);
1401 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1402 expect_node(node, "E1.E2.D1");
1403 IXMLDOMNode_Release(node);
1404 ole_check(IXMLDOMNodeList_reset(list));
1405
1406 IXMLDOMNodeList_AddRef(list);
1407 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1408 ole_check(IXMLDOMNodeList_reset(list));
1409
1410 node = (void*)0xdeadbeef;
1411 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1412 ok( r == S_FALSE, "ret %08x\n", r );
1413 ok( node == NULL, "node %p\n", node );
1414 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1415 ok( r == S_OK, "ret %08x\n", r );
1416 r = IXMLDOMNode_Release( node );
1417 ok( r == 0, "ret %08x\n", r );
1418 }
1419 else
1420 ok( FALSE, "no element\n");
1421
1422 if (list)
1423 {
1424 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1425 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1426
1427 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1428 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1429
1430 r = IXMLDOMNodeList_get_length(list, NULL);
1431 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1432
1433 r = IXMLDOMNodeList_get_length( list, &count );
1434 ok( r == S_OK, "get_length returns %08x\n", r );
1435 ok( count == 4, "get_length got %d\n", count );
1436
1437 r = IXMLDOMNodeList_nextNode(list, NULL);
1438 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1439
1440 r = IXMLDOMNodeList_nextNode( list, &node );
1441 ok( r == S_OK, "nextNode returned wrong code\n");
1442 }
1443 else
1444 ok( FALSE, "no list\n");
1445
1446 if (node)
1447 {
1448 type = NODE_INVALID;
1449 r = IXMLDOMNode_get_nodeType( node, &type);
1450 ok( r == S_OK, "getNamedItem returned wrong code\n");
1451 ok( type == NODE_ELEMENT, "node not text\n");
1452
1453 VariantInit(&var);
1454 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1455 r = IXMLDOMNode_get_nodeValue( node, &var );
1456 ok( r == S_FALSE, "nextNode returned wrong code\n");
1457 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1458 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1459
1460 r = IXMLDOMNode_hasChildNodes( node, NULL );
1461 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1462
1463 b = 1;
1464 r = IXMLDOMNode_hasChildNodes( node, &b );
1465 ok( r == S_OK, "hasChildNoes bad return\n");
1466 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1467
1468 str = NULL;
1469 r = IXMLDOMNode_get_baseName( node, &str );
1470 ok( r == S_OK, "get_baseName returned wrong code\n");
1471 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1472 SysFreeString(str);
1473 }
1474 else
1475 ok( FALSE, "no node\n");
1476
1477 if (node)
1478 IXMLDOMNode_Release( node );
1479 if (list)
1480 IXMLDOMNodeList_Release( list );
1481 if (element)
1482 IXMLDOMElement_Release( element );
1483
1484 b = FALSE;
1485 str = SysAllocString( szComplete5 );
1486 r = IXMLDOMDocument_loadXML( doc, str, &b );
1487 ok( r == S_OK, "loadXML failed\n");
1488 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1489 SysFreeString( str );
1490
1491 b = 1;
1492 r = IXMLDOMNode_hasChildNodes( doc, &b );
1493 ok( r == S_OK, "hasChildNoes bad return\n");
1494 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1495
1496 r = IXMLDOMDocument_get_documentElement( doc, &element );
1497 ok( r == S_OK, "should be a document element\n");
1498 ok( element != NULL, "should be an element\n");
1499
1500 if (element)
1501 {
1502 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1503 BSTR tag = NULL;
1504
1505 /* check if the tag is correct */
1506 r = IXMLDOMElement_get_tagName( element, &tag );
1507 ok( r == S_OK, "couldn't get tag name\n");
1508 ok( tag != NULL, "tag was null\n");
1509 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1510 SysFreeString( tag );
1511 }
1512
1513 if (element)
1514 IXMLDOMElement_Release( element );
1515 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1516 }
1517
1518 static void test_refs(void)
1519 {
1520 HRESULT r;
1521 BSTR str;
1522 VARIANT_BOOL b;
1523 IXMLDOMDocument *doc = NULL;
1524 IXMLDOMElement *element = NULL;
1525 IXMLDOMNode *node = NULL, *node2;
1526 IXMLDOMNodeList *node_list = NULL;
1527 LONG ref;
1528 IUnknown *unk, *unk2;
1529
1530 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1531 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1532 if( r != S_OK )
1533 return;
1534 ref = IXMLDOMDocument_Release(doc);
1535 ok( ref == 0, "ref %d\n", ref);
1536
1537 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1538 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1539 if( r != S_OK )
1540 return;
1541
1542 str = SysAllocString( szComplete4 );
1543 r = IXMLDOMDocument_loadXML( doc, str, &b );
1544 ok( r == S_OK, "loadXML failed\n");
1545 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1546 SysFreeString( str );
1547
1548 ref = IXMLDOMDocument_AddRef( doc );
1549 ok( ref == 2, "ref %d\n", ref );
1550 ref = IXMLDOMDocument_AddRef( doc );
1551 ok( ref == 3, "ref %d\n", ref );
1552 IXMLDOMDocument_Release( doc );
1553 IXMLDOMDocument_Release( doc );
1554
1555 r = IXMLDOMDocument_get_documentElement( doc, &element );
1556 ok( r == S_OK, "should be a document element\n");
1557 ok( element != NULL, "should be an element\n");
1558
1559 ref = IXMLDOMDocument_AddRef( doc );
1560 ok( ref == 2, "ref %d\n", ref );
1561 IXMLDOMDocument_Release( doc );
1562
1563 r = IXMLDOMElement_get_childNodes( element, &node_list );
1564 ok( r == S_OK, "rets %08x\n", r);
1565
1566 ref = IXMLDOMNodeList_AddRef( node_list );
1567 ok( ref == 2, "ref %d\n", ref );
1568 IXMLDOMNodeList_Release( node_list );
1569
1570 IXMLDOMNodeList_get_item( node_list, 0, &node );
1571 ok( r == S_OK, "rets %08x\n", r);
1572
1573 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1574 ok( r == S_OK, "rets %08x\n", r);
1575
1576 ref = IXMLDOMNode_AddRef( node );
1577 ok( ref == 2, "ref %d\n", ref );
1578 IXMLDOMNode_Release( node );
1579
1580 ref = IXMLDOMNode_Release( node );
1581 ok( ref == 0, "ref %d\n", ref );
1582 ref = IXMLDOMNode_Release( node2 );
1583 ok( ref == 0, "ref %d\n", ref );
1584
1585 ref = IXMLDOMNodeList_Release( node_list );
1586 ok( ref == 0, "ref %d\n", ref );
1587
1588 ok( node != node2, "node %p node2 %p\n", node, node2 );
1589
1590 ref = IXMLDOMDocument_Release( doc );
1591 ok( ref == 0, "ref %d\n", ref );
1592
1593 ref = IXMLDOMElement_AddRef( element );
1594 todo_wine {
1595 ok( ref == 3, "ref %d\n", ref );
1596 }
1597 IXMLDOMElement_Release( element );
1598
1599 /* IUnknown must be unique however we obtain it */
1600 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1601 ok( r == S_OK, "rets %08x\n", r );
1602 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1603 ok( r == S_OK, "rets %08x\n", r );
1604 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1605 ok( r == S_OK, "rets %08x\n", r );
1606 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1607
1608 IUnknown_Release( unk2 );
1609 IUnknown_Release( unk );
1610 IXMLDOMNode_Release( node );
1611
1612 IXMLDOMElement_Release( element );
1613
1614 }
1615
1616 static void test_create(void)
1617 {
1618 static const WCHAR szOne[] = {'1',0};
1619 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1620 HRESULT r;
1621 VARIANT var;
1622 BSTR str, name;
1623 IXMLDOMDocument *doc;
1624 IXMLDOMElement *element;
1625 IXMLDOMNode *root, *node, *child;
1626 IXMLDOMNamedNodeMap *attr_map;
1627 IUnknown *unk;
1628 LONG ref;
1629 LONG num;
1630
1631 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1632 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1633 if( r != S_OK )
1634 return;
1635
1636 V_VT(&var) = VT_I1;
1637 V_I1(&var) = NODE_ELEMENT;
1638 str = SysAllocString( szlc );
1639 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1640 ok( r == S_OK, "returns %08x\n", r );
1641 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1642
1643 V_VT(&var) = VT_R4;
1644 V_R4(&var) = NODE_ELEMENT;
1645 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1646 ok( r == S_OK, "returns %08x\n", r );
1647 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1648
1649 V_VT(&var) = VT_BSTR;
1650 V_BSTR(&var) = SysAllocString( szOne );
1651 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1652 ok( r == S_OK, "returns %08x\n", r );
1653 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1654 VariantClear(&var);
1655
1656 V_VT(&var) = VT_BSTR;
1657 V_BSTR(&var) = SysAllocString( szOneGarbage );
1658 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1659 ok( r == E_INVALIDARG, "returns %08x\n", r );
1660 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1661 VariantClear(&var);
1662
1663 V_VT(&var) = VT_I4;
1664 V_I4(&var) = NODE_ELEMENT;
1665 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1666 ok( r == S_OK, "returns %08x\n", r );
1667 r = IXMLDOMDocument_appendChild( doc, node, &root );
1668 ok( r == S_OK, "returns %08x\n", r );
1669 ok( node == root, "%p %p\n", node, root );
1670
1671 ref = IXMLDOMNode_AddRef( node );
1672 ok(ref == 3, "ref %d\n", ref);
1673 IXMLDOMNode_Release( node );
1674
1675 ref = IXMLDOMNode_Release( node );
1676 ok(ref == 1, "ref %d\n", ref);
1677 SysFreeString( str );
1678
1679 V_VT(&var) = VT_I4;
1680 V_I4(&var) = NODE_ELEMENT;
1681 str = SysAllocString( szbs );
1682 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1683 ok( r == S_OK, "returns %08x\n", r );
1684 SysFreeString( str );
1685
1686 ref = IXMLDOMNode_AddRef( node );
1687 ok(ref == 2, "ref = %d\n", ref);
1688 IXMLDOMNode_Release( node );
1689
1690 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1691 ok( r == S_OK, "returns %08x\n", r );
1692
1693 ref = IXMLDOMNode_AddRef( unk );
1694 ok(ref == 3, "ref = %d\n", ref);
1695 IXMLDOMNode_Release( unk );
1696
1697 V_VT(&var) = VT_EMPTY;
1698 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1699 ok( r == S_OK, "returns %08x\n", r );
1700 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1701 IXMLDOMNode_Release( child );
1702 IUnknown_Release( unk );
1703
1704
1705 V_VT(&var) = VT_NULL;
1706 V_DISPATCH(&var) = (IDispatch*)node;
1707 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1708 ok( r == S_OK, "returns %08x\n", r );
1709 ok( node == child, "%p %p\n", node, child );
1710 IXMLDOMNode_Release( child );
1711
1712
1713 V_VT(&var) = VT_NULL;
1714 V_DISPATCH(&var) = (IDispatch*)node;
1715 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1716 ok( r == S_OK, "returns %08x\n", r );
1717 IXMLDOMNode_Release( node );
1718
1719 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1720 ok( r == S_OK, "returns %08x\n", r );
1721
1722 r = IXMLDOMElement_get_attributes( element, &attr_map );
1723 ok( r == S_OK, "returns %08x\n", r );
1724 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1725 ok( r == S_OK, "returns %08x\n", r );
1726 ok( num == 0, "num %d\n", num );
1727 IXMLDOMNamedNodeMap_Release( attr_map );
1728
1729 V_VT(&var) = VT_BSTR;
1730 V_BSTR(&var) = SysAllocString( szstr1 );
1731 name = SysAllocString( szdl );
1732 r = IXMLDOMElement_setAttribute( element, name, var );
1733 ok( r == S_OK, "returns %08x\n", r );
1734 r = IXMLDOMElement_get_attributes( element, &attr_map );
1735 ok( r == S_OK, "returns %08x\n", r );
1736 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1737 ok( r == S_OK, "returns %08x\n", r );
1738 ok( num == 1, "num %d\n", num );
1739 IXMLDOMNamedNodeMap_Release( attr_map );
1740 VariantClear(&var);
1741
1742 V_VT(&var) = VT_BSTR;
1743 V_BSTR(&var) = SysAllocString( szstr2 );
1744 r = IXMLDOMElement_setAttribute( element, name, var );
1745 ok( r == S_OK, "returns %08x\n", r );
1746 r = IXMLDOMElement_get_attributes( element, &attr_map );
1747 ok( r == S_OK, "returns %08x\n", r );
1748 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1749 ok( r == S_OK, "returns %08x\n", r );
1750 ok( num == 1, "num %d\n", num );
1751 IXMLDOMNamedNodeMap_Release( attr_map );
1752 VariantClear(&var);
1753 r = IXMLDOMElement_getAttribute( element, name, &var );
1754 ok( r == S_OK, "returns %08x\n", r );
1755 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1756 VariantClear(&var);
1757 SysFreeString(name);
1758
1759 V_VT(&var) = VT_BSTR;
1760 V_BSTR(&var) = SysAllocString( szstr1 );
1761 name = SysAllocString( szlc );
1762 r = IXMLDOMElement_setAttribute( element, name, var );
1763 ok( r == S_OK, "returns %08x\n", r );
1764 r = IXMLDOMElement_get_attributes( element, &attr_map );
1765 ok( r == S_OK, "returns %08x\n", r );
1766 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1767 ok( r == S_OK, "returns %08x\n", r );
1768 ok( num == 2, "num %d\n", num );
1769 IXMLDOMNamedNodeMap_Release( attr_map );
1770 VariantClear(&var);
1771 SysFreeString(name);
1772
1773 V_VT(&var) = VT_I4;
1774 V_I4(&var) = 10;
1775 name = SysAllocString( szbs );
1776 r = IXMLDOMElement_setAttribute( element, name, var );
1777 ok( r == S_OK, "returns %08x\n", r );
1778 VariantClear(&var);
1779 r = IXMLDOMElement_getAttribute( element, name, &var );
1780 ok( r == S_OK, "returns %08x\n", r );
1781 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1782 VariantClear(&var);
1783 SysFreeString(name);
1784
1785 /* Create an Attribute */
1786 V_VT(&var) = VT_I4;
1787 V_I4(&var) = NODE_ATTRIBUTE;
1788 str = SysAllocString( szAttribute );
1789 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1790 ok( r == S_OK, "returns %08x\n", r );
1791 ok( node != NULL, "node was null\n");
1792 SysFreeString(str);
1793
1794 if(r == S_OK)
1795 {
1796 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1797 ok( r == S_OK, "returns %08x\n", r );
1798 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1799 SysFreeString(str);
1800 IXMLDOMNode_Release( node );
1801 }
1802
1803 IXMLDOMElement_Release( element );
1804 IXMLDOMNode_Release( root );
1805 IXMLDOMDocument_Release( doc );
1806 }
1807
1808 static void test_getElementsByTagName(void)
1809 {
1810 HRESULT r;
1811 BSTR str;
1812 VARIANT_BOOL b;
1813 IXMLDOMDocument *doc;
1814 IXMLDOMNodeList *node_list;
1815 LONG len;
1816
1817 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1818 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1819 if( r != S_OK )
1820 return;
1821
1822 str = SysAllocString( szComplete4 );
1823 r = IXMLDOMDocument_loadXML( doc, str, &b );
1824 ok( r == S_OK, "loadXML failed\n");
1825 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1826 SysFreeString( str );
1827
1828 str = SysAllocString( szstar );
1829 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1830 ok( r == S_OK, "ret %08x\n", r );
1831 r = IXMLDOMNodeList_get_length( node_list, &len );
1832 ok( r == S_OK, "ret %08x\n", r );
1833 ok( len == 6, "len %d\n", len );
1834
1835 test_disp((IUnknown*)node_list);
1836
1837 IXMLDOMNodeList_Release( node_list );
1838 SysFreeString( str );
1839
1840 str = SysAllocString( szbs );
1841 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1842 ok( r == S_OK, "ret %08x\n", r );
1843 r = IXMLDOMNodeList_get_length( node_list, &len );
1844 ok( r == S_OK, "ret %08x\n", r );
1845 ok( len == 1, "len %d\n", len );
1846 IXMLDOMNodeList_Release( node_list );
1847 SysFreeString( str );
1848
1849 str = SysAllocString( szdl );
1850 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1851 ok( r == S_OK, "ret %08x\n", r );
1852 r = IXMLDOMNodeList_get_length( node_list, &len );
1853 ok( r == S_OK, "ret %08x\n", r );
1854 ok( len == 0, "len %d\n", len );
1855 IXMLDOMNodeList_Release( node_list );
1856 SysFreeString( str );
1857
1858 str = SysAllocString( szstr1 );
1859 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1860 ok( r == S_OK, "ret %08x\n", r );
1861 r = IXMLDOMNodeList_get_length( node_list, &len );
1862 ok( r == S_OK, "ret %08x\n", r );
1863 ok( len == 0, "len %d\n", len );
1864 IXMLDOMNodeList_Release( node_list );
1865 SysFreeString( str );
1866
1867 IXMLDOMDocument_Release( doc );
1868 }
1869
1870 static void test_get_text(void)
1871 {
1872 HRESULT r;
1873 BSTR str;
1874 VARIANT_BOOL b;
1875 IXMLDOMDocument *doc;
1876 IXMLDOMNode *node, *node2, *node3;
1877 IXMLDOMNode *nodeRoot;
1878 IXMLDOMNodeList *node_list;
1879 IXMLDOMNamedNodeMap *node_map;
1880 LONG len;
1881
1882 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1883 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1884 if( r != S_OK )
1885 return;
1886
1887 str = SysAllocString( szComplete4 );
1888 r = IXMLDOMDocument_loadXML( doc, str, &b );
1889 ok( r == S_OK, "loadXML failed\n");
1890 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1891 SysFreeString( str );
1892
1893 str = SysAllocString( szbs );
1894 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1895 ok( r == S_OK, "ret %08x\n", r );
1896 SysFreeString(str);
1897
1898 /* Test to get all child node text. */
1899 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (LPVOID*)&nodeRoot);
1900 ok( r == S_OK, "ret %08x\n", r );
1901 if(r == S_OK)
1902 {
1903 r = IXMLDOMNode_get_text( nodeRoot, &str );
1904 ok( r == S_OK, "ret %08x\n", r );
1905 ok( compareIgnoreReturnsWhitespace(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text\n");
1906 SysFreeString(str);
1907
1908 IXMLDOMNode_Release(nodeRoot);
1909 }
1910
1911 if (0) {
1912 /* this test crashes on win9x */
1913 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1914 ok( r == E_INVALIDARG, "ret %08x\n", r );
1915 }
1916
1917 r = IXMLDOMNodeList_get_length( node_list, NULL );
1918 ok( r == E_INVALIDARG, "ret %08x\n", r );
1919
1920 r = IXMLDOMNodeList_get_length( node_list, &len );
1921 ok( r == S_OK, "ret %08x\n", r );
1922 ok( len == 1, "expect 1 got %d\n", len );
1923
1924 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1925 ok( r == E_INVALIDARG, "ret %08x\n", r );
1926
1927 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1928 ok( r == E_INVALIDARG, "ret %08x\n", r );
1929
1930 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1931 ok( r == S_OK, "ret %08x\n", r );
1932 IXMLDOMNodeList_Release( node_list );
1933
1934 /* Invalid output parameter*/
1935 r = IXMLDOMNode_get_text( node, NULL );
1936 ok( r == E_INVALIDARG, "ret %08x\n", r );
1937
1938 r = IXMLDOMNode_get_text( node, &str );
1939 ok( r == S_OK, "ret %08x\n", r );
1940 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1941 SysFreeString(str);
1942
1943 r = IXMLDOMNode_get_attributes( node, &node_map );
1944 ok( r == S_OK, "ret %08x\n", r );
1945
1946 str = SysAllocString( szvr );
1947 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1948 ok( r == S_OK, "ret %08x\n", r );
1949 SysFreeString(str);
1950
1951 r = IXMLDOMNode_get_text( node2, &str );
1952 ok( r == S_OK, "ret %08x\n", r );
1953 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1954 SysFreeString(str);
1955
1956 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1957 ok( r == S_OK, "ret %08x\n", r );
1958
1959 r = IXMLDOMNode_get_text( node3, &str );
1960 ok( r == S_OK, "ret %08x\n", r );
1961 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1962 SysFreeString(str);
1963
1964
1965 IXMLDOMNode_Release( node3 );
1966 IXMLDOMNode_Release( node2 );
1967 IXMLDOMNamedNodeMap_Release( node_map );
1968 IXMLDOMNode_Release( node );
1969 IXMLDOMDocument_Release( doc );
1970 }
1971
1972 static void test_get_childNodes(void)
1973 {
1974 HRESULT r;
1975 BSTR str;
1976 VARIANT_BOOL b;
1977 IXMLDOMDocument *doc;
1978 IXMLDOMElement *element;
1979 IXMLDOMNode *node, *node2;
1980 IXMLDOMNodeList *node_list, *node_list2;
1981 LONG len;
1982
1983 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1984 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1985 if( r != S_OK )
1986 return;
1987
1988 str = SysAllocString( szComplete4 );
1989 r = IXMLDOMDocument_loadXML( doc, str, &b );
1990 ok( r == S_OK, "loadXML failed\n");
1991 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1992 SysFreeString( str );
1993
1994 r = IXMLDOMDocument_get_documentElement( doc, &element );
1995 ok( r == S_OK, "ret %08x\n", r);
1996
1997 r = IXMLDOMElement_get_childNodes( element, &node_list );
1998 ok( r == S_OK, "ret %08x\n", r);
1999
2000 r = IXMLDOMNodeList_get_length( node_list, &len );
2001 ok( r == S_OK, "ret %08x\n", r);
2002 ok( len == 4, "len %d\n", len);
2003
2004 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
2005 ok( r == S_OK, "ret %08x\n", r);
2006
2007 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
2008 ok( r == S_OK, "ret %08x\n", r);
2009
2010 r = IXMLDOMNodeList_get_length( node_list2, &len );
2011 ok( r == S_OK, "ret %08x\n", r);
2012 ok( len == 0, "len %d\n", len);
2013
2014 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
2015 ok( r == S_FALSE, "ret %08x\n", r);
2016
2017 IXMLDOMNodeList_Release( node_list2 );
2018 IXMLDOMNode_Release( node );
2019 IXMLDOMNodeList_Release( node_list );
2020 IXMLDOMElement_Release( element );
2021 IXMLDOMDocument_Release( doc );
2022 }
2023
2024 static void test_removeChild(void)
2025 {
2026 HRESULT r;
2027 BSTR str;
2028 VARIANT_BOOL b;
2029 IXMLDOMDocument *doc;
2030 IXMLDOMElement *element, *lc_element;
2031 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
2032 IXMLDOMNodeList *root_list, *fo_list;
2033
2034 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2035 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2036 if( r != S_OK )
2037 return;
2038
2039 str = SysAllocString( szComplete4 );
2040 r = IXMLDOMDocument_loadXML( doc, str, &b );
2041 ok( r == S_OK, "loadXML failed\n");
2042 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2043 SysFreeString( str );
2044
2045 r = IXMLDOMDocument_get_documentElement( doc, &element );
2046 ok( r == S_OK, "ret %08x\n", r);
2047
2048 r = IXMLDOMElement_get_childNodes( element, &root_list );
2049 ok( r == S_OK, "ret %08x\n", r);
2050
2051 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2052 ok( r == S_OK, "ret %08x\n", r);
2053
2054 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2055 ok( r == S_OK, "ret %08x\n", r);
2056
2057 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2058 ok( r == S_OK, "ret %08x\n", r);
2059
2060 /* invalid parameter: NULL ptr */
2061 removed_node = (void*)0xdeadbeef;
2062 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
2063 ok( r == E_INVALIDARG, "ret %08x\n", r );
2064 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2065
2066 /* ba_node is a descendant of element, but not a direct child. */
2067 removed_node = (void*)0xdeadbeef;
2068 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
2069 ok( r == E_INVALIDARG, "ret %08x\n", r );
2070 ok( removed_node == NULL, "%p\n", removed_node );
2071
2072 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
2073 ok( r == S_OK, "ret %08x\n", r);
2074 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
2075
2076 /* try removing already removed child */
2077 temp_node = (void*)0xdeadbeef;
2078 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
2079 ok( r == E_INVALIDARG, "ret %08x\n", r);
2080 ok( temp_node == NULL, "%p\n", temp_node );
2081
2082 /* the removed node has no parent anymore */
2083 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
2084 ok( r == S_FALSE, "ret %08x\n", r);
2085 ok( temp_node == NULL, "%p\n", temp_node );
2086
2087 IXMLDOMNode_Release( removed_node );
2088 IXMLDOMNode_Release( ba_node );
2089 IXMLDOMNodeList_Release( fo_list );
2090
2091 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2092 ok( r == S_OK, "ret %08x\n", r);
2093
2094 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (LPVOID*)&lc_element );
2095 ok( r == S_OK, "ret %08x\n", r);
2096
2097 /* MS quirk: passing wrong interface pointer works, too */
2098 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
2099 ok( r == S_OK, "ret %08x\n", r);
2100
2101 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
2102 ok( r == S_FALSE, "ret %08x\n", r);
2103 ok( temp_node == NULL, "%p\n", temp_node );
2104
2105 IXMLDOMNode_Release( lc_node );
2106 IXMLDOMNodeList_Release( root_list );
2107 IXMLDOMElement_Release( element );
2108 IXMLDOMDocument_Release( doc );
2109 }
2110
2111 static void test_replaceChild(void)
2112 {
2113 HRESULT r;
2114 BSTR str;
2115 VARIANT_BOOL b;
2116 IXMLDOMDocument *doc;
2117 IXMLDOMElement *element, *ba_element;
2118 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
2119 IXMLDOMNodeList *root_list, *fo_list;
2120 IUnknown * unk1, *unk2;
2121 LONG len;
2122
2123 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2124 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2125 if( r != S_OK )
2126 return;
2127
2128 str = SysAllocString( szComplete4 );
2129 r = IXMLDOMDocument_loadXML( doc, str, &b );
2130 ok( r == S_OK, "loadXML failed\n");
2131 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2132 SysFreeString( str );
2133
2134 r = IXMLDOMDocument_get_documentElement( doc, &element );
2135 ok( r == S_OK, "ret %08x\n", r);
2136
2137 r = IXMLDOMElement_get_childNodes( element, &root_list );
2138 ok( r == S_OK, "ret %08x\n", r);
2139
2140 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2141 ok( r == S_OK, "ret %08x\n", r);
2142
2143 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2144 ok( r == S_OK, "ret %08x\n", r);
2145
2146 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2147 ok( r == S_OK, "ret %08x\n", r);
2148
2149 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2150 ok( r == S_OK, "ret %08x\n", r);
2151
2152 IXMLDOMNodeList_Release( fo_list );
2153
2154 /* invalid parameter: NULL ptr for element to remove */
2155 removed_node = (void*)0xdeadbeef;
2156 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
2157 ok( r == E_INVALIDARG, "ret %08x\n", r );
2158 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2159
2160 /* invalid parameter: NULL for replacement element. (Sic!) */
2161 removed_node = (void*)0xdeadbeef;
2162 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
2163 ok( r == E_INVALIDARG, "ret %08x\n", r );
2164 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2165
2166 /* invalid parameter: OldNode is not a child */
2167 removed_node = (void*)0xdeadbeef;
2168 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
2169 ok( r == E_INVALIDARG, "ret %08x\n", r );
2170 ok( removed_node == NULL, "%p\n", removed_node );
2171
2172 /* invalid parameter: would create loop */
2173 removed_node = (void*)0xdeadbeef;
2174 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
2175 ok( r == E_FAIL, "ret %08x\n", r );
2176 ok( removed_node == NULL, "%p\n", removed_node );
2177
2178 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
2179 ok( r == S_OK, "ret %08x\n", r );
2180
2181 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
2182 ok( r == S_OK, "ret %08x\n", r );
2183
2184 /* ba_node and temp_node refer to the same node, yet they
2185 are different interface pointers */
2186 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
2187 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
2188 ok( r == S_OK, "ret %08x\n", r );
2189 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
2190 ok( r == S_OK, "ret %08x\n", r );
2191 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
2192
2193 IUnknown_Release( unk1 );
2194 IUnknown_Release( unk2 );
2195
2196 /* ba_node should have been removed from below fo_node */
2197 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2198 ok( r == S_OK, "ret %08x\n", r );
2199
2200 /* MS quirk: replaceChild also accepts elements instead of nodes */
2201 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
2202 ok( r == S_OK, "ret %08x\n", r );
2203
2204 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
2205 ok( r == S_OK, "ret %08x\n", r );
2206
2207 r = IXMLDOMNodeList_get_length( fo_list, &len);
2208 ok( r == S_OK, "ret %08x\n", r );
2209 ok( len == 0, "len %d\n", len);
2210
2211 IXMLDOMNodeList_Release( fo_list );
2212
2213 IXMLDOMNode_Release(ba_node);
2214 IXMLDOMNode_Release(fo_node);
2215 IXMLDOMNode_Release(temp_node);
2216 IXMLDOMNodeList_Release( root_list );
2217 IXMLDOMElement_Release( element );
2218 IXMLDOMDocument_Release( doc );
2219 }
2220
2221 static void test_removeNamedItem(void)
2222 {
2223 IXMLDOMDocument *doc;
2224 IXMLDOMElement *element;
2225 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
2226 IXMLDOMNodeList *root_list;
2227 IXMLDOMNamedNodeMap * pr_attrs;
2228 VARIANT_BOOL b;
2229 BSTR str;
2230 LONG len;
2231 HRESULT r;
2232
2233 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2234 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2235 if( r != S_OK )
2236 return;
2237
2238 str = SysAllocString( szComplete4 );
2239 r = IXMLDOMDocument_loadXML( doc, str, &b );
2240 ok( r == S_OK, "loadXML failed\n");
2241 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2242 SysFreeString( str );
2243
2244 r = IXMLDOMDocument_get_documentElement( doc, &element );
2245 ok( r == S_OK, "ret %08x\n", r);
2246
2247 r = IXMLDOMElement_get_childNodes( element, &root_list );
2248 ok( r == S_OK, "ret %08x\n", r);
2249
2250 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2251 ok( r == S_OK, "ret %08x\n", r);
2252
2253 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2254 ok( r == S_OK, "ret %08x\n", r);
2255
2256 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2257 ok( r == S_OK, "ret %08x\n", r);
2258 ok( len == 3, "length %d\n", len);
2259
2260 removed_node = (void*)0xdeadbeef;
2261 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2262 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2263 ok ( removed_node == (void*)0xdeadbeef, "removed_node == %p\n", removed_node);
2264
2265 removed_node = (void*)0xdeadbeef;
2266 str = SysAllocString(szvr);
2267 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2268 ok ( r == S_OK, "ret %08x\n", r);
2269
2270 removed_node2 = (void*)0xdeadbeef;
2271 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2272 ok ( r == S_FALSE, "ret %08x\n", r);
2273 ok ( removed_node2 == NULL, "removed_node == %p\n", removed_node2 );
2274
2275 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2276 ok( r == S_OK, "ret %08x\n", r);
2277 ok( len == 2, "length %d\n", len);
2278
2279 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2280 ok ( r == S_OK, "ret %08x\n", r);
2281 IXMLDOMNode_Release(removed_node);
2282
2283 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2284 ok( r == S_OK, "ret %08x\n", r);
2285 ok( len == 3, "length %d\n", len);
2286
2287 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2288 ok ( r == S_OK, "ret %08x\n", r);
2289
2290 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2291 ok( r == S_OK, "ret %08x\n", r);
2292 ok( len == 2, "length %d\n", len);
2293
2294 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2295 ok ( r == S_FALSE, "ret %08x\n", r);
2296
2297 SysFreeString(str);
2298
2299 IXMLDOMNamedNodeMap_Release( pr_attrs );
2300 IXMLDOMNode_Release( pr_node );
2301 IXMLDOMNodeList_Release( root_list );
2302 IXMLDOMElement_Release( element );
2303 IXMLDOMDocument_Release( doc );
2304 }
2305
2306 static void test_XMLHTTP(void)
2307 {
2308 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2309 static WCHAR wszPOST[] = {'P','O','S','T',0};
2310 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2311 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2312 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2313 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2314 IXMLHttpRequest *pXMLHttpRequest;
2315 BSTR bstrResponse;
2316 VARIANT dummy;
2317 VARIANT varfalse;
2318 VARIANT varbody;
2319 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2320 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2321 (void **)&pXMLHttpRequest);
2322 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
2323 if (hr != S_OK)
2324 return;
2325
2326 VariantInit(&dummy);
2327 V_VT(&dummy) = VT_ERROR;
2328 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2329 VariantInit(&varfalse);
2330 V_VT(&varfalse) = VT_BOOL;
2331 V_BOOL(&varfalse) = VARIANT_FALSE;
2332 V_VT(&varbody) = VT_BSTR;
2333 V_BSTR(&varbody) = SysAllocString(wszBody);
2334
2335 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
2336 todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
2337
2338 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2339 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2340 VariantClear(&varbody);
2341
2342 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2343 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2344 /* the server currently returns "FAILED" because the Content-Type header is
2345 * not what the server expects */
2346 if(hr == S_OK)
2347 {
2348 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2349 SysFreeString(bstrResponse);
2350 }
2351
2352 IXMLHttpRequest_Release(pXMLHttpRequest);
2353 }
2354
2355 static void test_IXMLDOMDocument2(void)
2356 {
2357 HRESULT r;
2358 VARIANT_BOOL b;
2359 BSTR str;
2360 IXMLDOMDocument *doc;
2361 IXMLDOMDocument2 *doc2;
2362 IDispatchEx *dispex;
2363 VARIANT var;
2364 int ref;
2365
2366 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2367 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2368 if( r != S_OK )
2369 return;
2370
2371 str = SysAllocString( szComplete4 );
2372 r = IXMLDOMDocument_loadXML( doc, str, &b );
2373 ok( r == S_OK, "loadXML failed\n");
2374 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2375 SysFreeString( str );
2376
2377 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
2378 ok( r == S_OK, "ret %08x\n", r );
2379 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
2380
2381 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
2382 ok( r == S_OK, "ret %08x\n", r );
2383 if(r == S_OK)
2384 {
2385 IDispatchEx_Release(dispex);
2386 }
2387
2388 /* we will check if the variant got cleared */
2389 ref = IXMLDOMDocument2_AddRef(doc2);
2390 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
2391 V_VT(&var) = VT_UNKNOWN;
2392 V_UNKNOWN(&var) = (IUnknown *)doc2;
2393
2394 /* invalid calls */
2395 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
2396 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
2397 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
2398
2399 /* valid call */
2400 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2401 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2402 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2403 V_VT(&var) = VT_R4;
2404
2405 /* the variant didn't get cleared*/
2406 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
2407
2408 /* setProperty tests */
2409 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
2410 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
2411 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
2412 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2413 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2414 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2415
2416 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
2417 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2418 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2419 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2420
2421 IXMLDOMDocument2_Release( doc2 );
2422 IXMLDOMDocument_Release( doc );
2423 free_bstrs();
2424 }
2425
2426 static void test_XPath(void)
2427 {
2428 HRESULT r;
2429 VARIANT var;
2430 VARIANT_BOOL b;
2431 IXMLDOMDocument2 *doc;
2432 IXMLDOMNode *rootNode;
2433 IXMLDOMNode *elem1Node;
2434 IXMLDOMNode *node;
2435 IXMLDOMNodeList *list;
2436
2437 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2438 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2439 if( r != S_OK )
2440 return;
2441
2442 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
2443 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2444
2445 /* switch to XPath */
2446 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2447
2448 /* some simple queries*/
2449 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
2450 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
2451 ole_check(IXMLDOMNodeList_reset(list));
2452 expect_list_and_release(list, "E2.D1");
2453 if (rootNode == NULL)
2454 return;
2455
2456 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
2457 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
2458
2459 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
2460 expect_list_and_release(list, "E3.E2.E2.D1");
2461
2462 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
2463 /* using get_item for query results advances the position */
2464 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2465 expect_node(node, "E2.E2.D1");
2466 IXMLDOMNode_Release(node);
2467 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2468 expect_node(node, "E4.E2.D1");
2469 IXMLDOMNode_Release(node);
2470 ole_check(IXMLDOMNodeList_reset(list));
2471 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2472
2473 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2474 expect_list_and_release(list, "E2.D1");
2475
2476 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2477 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2478 ole_check(IXMLDOMNodeList_reset(list));
2479 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2480
2481 /* select an attribute */
2482 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2483 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2484
2485 /* would evaluate to a number */
2486 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2487 /* would evaluate to a boolean */
2488 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2489 /* would evaluate to a string */
2490 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2491
2492 /* no results */
2493 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2494 expect_list_and_release(list, "");
2495 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2496 expect_list_and_release(list, "");
2497 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2498 expect_list_and_release(list, "");
2499
2500 /* foo undeclared in document node */
2501 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2502 /* undeclared in <root> node */
2503 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2504 /* undeclared in <elem> node */
2505 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2506 /* but this trick can be used */
2507 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2508 expect_list_and_release(list, "E3.E4.E2.D1");
2509
2510 /* it has to be declared in SelectionNamespaces */
2511 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2512 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2513
2514 /* now the namespace can be used */
2515 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2516 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2517 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2518 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2519 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2520 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2521 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2522 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2523
2524 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2525 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2526 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2527
2528 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2529
2530 VariantInit(&var);
2531 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2532 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2533 if (V_VT(&var) == VT_BSTR)
2534 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2535
2536 /* extra attributes - same thing*/
2537 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2538 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2539 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2540
2541 IXMLDOMNode_Release(rootNode);
2542 IXMLDOMNode_Release(elem1Node);
2543 IXMLDOMDocument_Release(doc);
2544 free_bstrs();
2545 }
2546
2547 static void test_cloneNode(void )
2548 {
2549 IXMLDOMDocument *doc = NULL;
2550 VARIANT_BOOL b;
2551 IXMLDOMNodeList *pList;
2552 IXMLDOMNamedNodeMap *mapAttr;
2553 LONG nLength = 0, nLength1 = 0;
2554 LONG nAttrCnt = 0, nAttrCnt1 = 0;
2555 IXMLDOMNode *node;
2556 IXMLDOMNode *node_clone;
2557 IXMLDOMNode *node_first;
2558 HRESULT r;
2559 BSTR str;
2560 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2561
2562 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2563 if( r != S_OK )
2564 return;
2565
2566 str = SysAllocString( szComplete4 );
2567 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2568 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2569 SysFreeString(str);
2570
2571 if(!b)
2572 return;
2573
2574 str = SysAllocString( szSearch);
2575 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2576 ok( r == S_OK, "ret %08x\n", r );
2577 ok( node != NULL, "node %p\n", node );
2578 SysFreeString(str);
2579
2580 if(!node)
2581 {
2582 IXMLDOMDocument_Release(doc);
2583 return;
2584 }
2585
2586 /* Check invalid parameter */
2587 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2588 ok( r == E_INVALIDARG, "ret %08x\n", r );
2589
2590 /* All Children */
2591 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2592 ok( r == S_OK, "ret %08x\n", r );