Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / msxml3 / tests / domdoc.c
blobf86026d555c0d856535c57501cc382110357e572
1 /*
2 * XML test
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
6 * Copyright 2010 Adam Martinson for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define COBJMACROS
26 #include "windows.h"
27 #include "ole2.h"
28 #include "objsafe.h"
29 #include "xmldom.h"
30 #include "msxml2.h"
31 #include "msxml2did.h"
32 #include "dispex.h"
33 #include <stdio.h>
34 #include <assert.h>
36 #include "wine/test.h"
38 #include "initguid.h"
40 DEFINE_GUID(IID_IObjectSafety, 0xcb5bdc81, 0x93c1, 0x11cf, 0x8f,0x20, 0x00,0x80,0x5f,0x2c,0xd0,0x64);
42 static int g_unexpectedcall, g_expectedcall;
44 typedef struct
46 const struct IDispatchVtbl *lpVtbl;
47 LONG ref;
48 } dispevent;
50 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
52 return (dispevent *)((char*)iface - FIELD_OFFSET(dispevent, lpVtbl));
55 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
57 *ppvObject = NULL;
59 if ( IsEqualGUID( riid, &IID_IDispatch) ||
60 IsEqualGUID( riid, &IID_IUnknown) )
62 *ppvObject = iface;
64 else
65 return E_NOINTERFACE;
67 IDispatch_AddRef( iface );
69 return S_OK;
72 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
74 dispevent *This = impl_from_IDispatch( iface );
75 return InterlockedIncrement( &This->ref );
78 static ULONG WINAPI dispevent_Release(IDispatch *iface)
80 dispevent *This = impl_from_IDispatch( iface );
81 ULONG ref = InterlockedDecrement( &This->ref );
83 if (ref == 0)
84 HeapFree(GetProcessHeap(), 0, This);
86 return ref;
89 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
91 g_unexpectedcall++;
92 *pctinfo = 0;
93 return S_OK;
96 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
97 LCID lcid, ITypeInfo **ppTInfo)
99 g_unexpectedcall++;
100 return S_OK;
103 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
104 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
106 g_unexpectedcall++;
107 return S_OK;
110 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
111 LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
112 EXCEPINFO *excepInfo, UINT *argErr)
114 ok(member == 0, "expected 0 member, got %d\n", member);
115 ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
116 ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
118 ok(params->cArgs == 0, "got %d\n", params->cArgs);
119 ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
120 ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
121 ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
123 ok(result == NULL, "got %p\n", result);
124 ok(excepInfo == NULL, "got %p\n", excepInfo);
125 ok(argErr == NULL, "got %p\n", argErr);
127 g_expectedcall++;
128 return E_FAIL;
131 static const IDispatchVtbl dispeventVtbl =
133 dispevent_QueryInterface,
134 dispevent_AddRef,
135 dispevent_Release,
136 dispevent_GetTypeInfoCount,
137 dispevent_GetTypeInfo,
138 dispevent_GetIDsOfNames,
139 dispevent_Invoke
142 static IDispatch* create_dispevent(void)
144 dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
146 event->lpVtbl = &dispeventVtbl;
147 event->ref = 1;
149 return (IDispatch*)&event->lpVtbl;
153 static const WCHAR szEmpty[] = { 0 };
154 static const WCHAR szIncomplete[] = {
155 '<','?','x','m','l',' ',
156 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
158 static const WCHAR szComplete1[] = {
159 '<','?','x','m','l',' ',
160 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
161 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
163 static const WCHAR szComplete2[] = {
164 '<','?','x','m','l',' ',
165 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
166 '<','o','>','<','/','o','>','\n',0
168 static const WCHAR szComplete3[] = {
169 '<','?','x','m','l',' ',
170 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
171 '<','a','>','<','/','a','>','\n',0
173 static const WCHAR szComplete4[] = {
174 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
175 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
176 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
177 'f','n','1','.','t','x','t','\n',
178 '<','/','b','s','>','\n',
179 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
180 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
181 'f','n','2','.','t','x','t','\n',
182 '<','/','p','r','>','\n',
183 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
184 '<','f','o','>','\n',
185 '<','b','a','>','\n',
186 'f','1','\n',
187 '<','/','b','a','>','\n',
188 '<','/','f','o','>','\n',
189 '<','/','l','c','>','\n',0
191 static const WCHAR szComplete5[] = {
192 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
193 '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','"',
194 ' ','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','"','>',
195 '<','S',':','s','c','o','p','e','>',
196 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
197 '<','/','S',':','s','c','o','p','e','>',
198 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
199 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
200 'c','o','m','p','u','t','e','r',
201 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
202 '<','/','S',':','s','e','a','r','c','h','>',0
205 static const WCHAR szComplete6[] = {
206 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'',' ',
207 'e','n','c','o','d','i','n','g','=','\'','W','i','n','d','o','w','s','-','1','2','5','2','\'','?','>','\n',
208 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
211 static const CHAR szNonUnicodeXML[] =
212 "<?xml version='1.0' encoding='Windows-1252'?>\n"
213 "<open></open>\n";
215 static const CHAR szExampleXML[] =
216 "<?xml version='1.0' encoding='utf-8'?>\n"
217 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
218 " <elem>\n"
219 " <a>A1 field</a>\n"
220 " <b>B1 field</b>\n"
221 " <c>C1 field</c>\n"
222 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
223 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
224 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
225 " </html>\n"
226 " <html xml:space='preserve' xmlns='http://www.w3.org/1999/xhtml'>\n"
227 " This is <strong>a</strong> <i>description</i> with preserved whitespace. <bar:x/>\n"
228 " </html>\n"
229 " </description>\n"
230 " </elem>\n"
231 "\n"
232 " <elem>\n"
233 " <a>A2 field</a>\n"
234 " <b>B2 field</b>\n"
235 " <c type=\"old\">C2 field</c>\n"
236 " </elem>\n"
237 "\n"
238 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
239 " <a>A3 field</a>\n"
240 " <b>B3 field</b>\n"
241 " <c>C3 field</c>\n"
242 " </elem>\n"
243 "\n"
244 " <elem>\n"
245 " <a>A4 field</a>\n"
246 " <b>B4 field</b>\n"
247 " <foo:c>C4 field</foo:c>\n"
248 " </elem>\n"
249 "</root>\n";
251 static const CHAR szNodeTypesXML[] =
252 "<?xml version='1.0'?>"
253 "<!-- comment node 0 -->"
254 "<root id='0' depth='0'>"
255 " <!-- comment node 1 -->"
256 " text node 0"
257 " <x id='1' depth='1'>"
258 " <?foo value='PI for x'?>"
259 " <!-- comment node 2 -->"
260 " text node 1"
261 " <a id='3' depth='2'/>"
262 " <b id='4' depth='2'/>"
263 " <c id='5' depth='2'/>"
264 " </x>"
265 " <y id='2' depth='1'>"
266 " <?bar value='PI for y'?>"
267 " <!-- comment node 3 -->"
268 " text node 2"
269 " <a id='6' depth='2'/>"
270 " <b id='7' depth='2'/>"
271 " <c id='8' depth='2'/>"
272 " </y>"
273 "</root>";
275 static const CHAR szTransformXML[] =
276 "<?xml version=\"1.0\"?>\n"
277 "<greeting>\n"
278 "Hello World\n"
279 "</greeting>";
281 static const CHAR szTransformSSXML[] =
282 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
283 " <xsl:output method=\"html\"/>\n"
284 " <xsl:template match=\"/\">\n"
285 " <xsl:apply-templates select=\"greeting\"/>\n"
286 " </xsl:template>\n"
287 " <xsl:template match=\"greeting\">\n"
288 " <html>\n"
289 " <body>\n"
290 " <h1>\n"
291 " <xsl:value-of select=\".\"/>\n"
292 " </h1>\n"
293 " </body>\n"
294 " </html>\n"
295 " </xsl:template>\n"
296 "</xsl:stylesheet>";
298 static const CHAR szTransformOutput[] =
299 "<html><body><h1>"
300 "Hello World"
301 "</h1></body></html>";
303 static const CHAR szTypeValueXML[] =
304 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
305 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
306 " <string>Wine</string>\n"
307 " <string2 dt:dt=\"string\">String</string2>\n"
308 " <number dt:dt=\"number\">12.44</number>\n"
309 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
310 " <int dt:dt=\"int\">-13</int>\n"
311 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
312 " <bool dt:dt=\"boolean\">1</bool>\n"
313 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
314 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
315 " <date dt:dt=\"date\">3721-11-01</date>\n"
316 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
317 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
318 " <i1 dt:dt=\"i1\">-13</i1>\n"
319 " <i2 dt:dt=\"i2\">31915</i2>\n"
320 " <i4 dt:dt=\"i4\">-312232</i4>\n"
321 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
322 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
323 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
324 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
325 " <r8 dt:dt=\"r8\">0.412</r8>\n"
326 " <float dt:dt=\"float\">41221.421</float>\n"
327 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
328 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
329 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
330 "</root>";
332 static const CHAR szBasicTransformSSXMLPart1[] =
333 "<?xml version=\"1.0\"?>"
334 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
335 "<xsl:output method=\"html\"/>\n"
336 "<xsl:template match=\"/\">"
337 "<HTML><BODY><TABLE>"
338 " <xsl:apply-templates select='document(\"";
340 static const CHAR szBasicTransformSSXMLPart2[] =
341 "\")/bottle/wine'>"
342 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
343 " </xsl:apply-templates>"
344 "</TABLE></BODY></HTML>"
345 "</xsl:template>"
346 "<xsl:template match=\"bottle\">"
347 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
348 "</xsl:template>"
349 "<xsl:template match=\"name\">"
350 " <TD><xsl:apply-templates /></TD>"
351 "</xsl:template>"
352 "<xsl:template match=\"cost\">"
353 " <TD><xsl:apply-templates /></TD>"
354 "</xsl:template>"
355 "</xsl:stylesheet>";
357 static const CHAR szBasicTransformXML[] =
358 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
360 static const CHAR szBasicTransformOutput[] =
361 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
363 #define SZ_EMAIL_DTD \
364 "<!DOCTYPE email ["\
365 " <!ELEMENT email (recipients,from,reply-to?,subject,body,attachment*)>"\
366 " <!ATTLIST email attachments IDREFS #REQUIRED>"\
367 " <!ATTLIST email sent (yes|no) \"no\">"\
368 " <!ELEMENT recipients (to+,cc*)>"\
369 " <!ELEMENT to (#PCDATA)>"\
370 " <!ATTLIST to name CDATA #IMPLIED>"\
371 " <!ELEMENT cc (#PCDATA)>"\
372 " <!ATTLIST cc name CDATA #IMPLIED>"\
373 " <!ELEMENT from (#PCDATA)>"\
374 " <!ATTLIST from name CDATA #IMPLIED>"\
375 " <!ELEMENT reply-to (#PCDATA)>"\
376 " <!ATTLIST reply-to name CDATA #IMPLIED>"\
377 " <!ELEMENT subject ANY>"\
378 " <!ELEMENT body ANY>"\
379 " <!ATTLIST body enc CDATA #FIXED \"UTF-8\">"\
380 " <!ELEMENT attachment (#PCDATA)>"\
381 " <!ATTLIST attachment id ID #REQUIRED>"\
382 "]>"
384 static const CHAR szEmailXML[] =
385 "<?xml version=\"1.0\"?>"
386 SZ_EMAIL_DTD
387 "<email attachments=\"patch1\">"
388 " <recipients>"
389 " <to>wine-patches@winehq.org</to>"
390 " </recipients>"
391 " <from name=\"Anonymous\">user@localhost</from>"
392 " <subject>msxml3/tests: DTD validation (try 87)</subject>"
393 " <body>"
394 " It no longer causes spontaneous combustion..."
395 " </body>"
396 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
397 "</email>";
399 static const CHAR szEmailXML_0D[] =
400 "<?xml version=\"1.0\"?>"
401 SZ_EMAIL_DTD
402 "<email attachments=\"patch1\">"
403 " <recipients>"
404 " <to>wine-patches@winehq.org</to>"
405 " </recipients>"
406 " <from name=\"Anonymous\">user@localhost</from>"
407 " <subject>msxml3/tests: DTD validation (try 88)</subject>"
408 " <body>"
409 " <undecl />"
410 " XML_ELEMENT_UNDECLARED 0xC00CE00D"
411 " </body>"
412 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
413 "</email>";
415 static const CHAR szEmailXML_0E[] =
416 "<?xml version=\"1.0\"?>"
417 SZ_EMAIL_DTD
418 "<email attachments=\"patch1\">"
419 " <recipients>"
420 " <to>wine-patches@winehq.org</to>"
421 " </recipients>"
422 " <from name=\"Anonymous\">user@localhost</from>"
423 " <subject>msxml3/tests: DTD validation (try 89)</subject>"
424 " <body>"
425 " XML_ELEMENT_ID_NOT_FOUND 0xC00CE00E"
426 " </body>"
427 " <attachment id=\"patch\">0001-msxml3-tests-DTD-validation.patch</attachment>"
428 "</email>";
430 static const CHAR szEmailXML_11[] =
431 "<?xml version=\"1.0\"?>"
432 SZ_EMAIL_DTD
433 "<email attachments=\"patch1\">"
434 " <recipients>"
435 " </recipients>"
436 " <from name=\"Anonymous\">user@localhost</from>"
437 " <subject>msxml3/tests: DTD validation (try 90)</subject>"
438 " <body>"
439 " XML_EMPTY_NOT_ALLOWED 0xC00CE011"
440 " </body>"
441 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
442 "</email>";
444 static const CHAR szEmailXML_13[] =
445 "<?xml version=\"1.0\"?>"
446 SZ_EMAIL_DTD
447 "<msg attachments=\"patch1\">"
448 " <recipients>"
449 " <to>wine-patches@winehq.org</to>"
450 " </recipients>"
451 " <from name=\"Anonymous\">user@localhost</from>"
452 " <subject>msxml3/tests: DTD validation (try 91)</subject>"
453 " <body>"
454 " XML_ROOT_NAME_MISMATCH 0xC00CE013"
455 " </body>"
456 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
457 "</msg>";
459 static const CHAR szEmailXML_14[] =
460 "<?xml version=\"1.0\"?>"
461 SZ_EMAIL_DTD
462 "<email attachments=\"patch1\">"
463 " <to>wine-patches@winehq.org</to>"
464 " <from name=\"Anonymous\">user@localhost</from>"
465 " <subject>msxml3/tests: DTD validation (try 92)</subject>"
466 " <body>"
467 " XML_INVALID_CONTENT 0xC00CE014"
468 " </body>"
469 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
470 "</email>";
472 static const CHAR szEmailXML_15[] =
473 "<?xml version=\"1.0\"?>"
474 SZ_EMAIL_DTD
475 "<email attachments=\"patch1\" ip=\"127.0.0.1\">"
476 " <recipients>"
477 " <to>wine-patches@winehq.org</to>"
478 " </recipients>"
479 " <from name=\"Anonymous\">user@localhost</from>"
480 " <subject>msxml3/tests: DTD validation (try 93)</subject>"
481 " <body>"
482 " XML_ATTRIBUTE_NOT_DEFINED 0xC00CE015"
483 " </body>"
484 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
485 "</email>";
487 static const CHAR szEmailXML_16[] =
488 "<?xml version=\"1.0\"?>"
489 SZ_EMAIL_DTD
490 "<email attachments=\"patch1\">"
491 " <recipients>"
492 " <to>wine-patches@winehq.org</to>"
493 " </recipients>"
494 " <from name=\"Anonymous\">user@localhost</from>"
495 " <subject>msxml3/tests: DTD validation (try 94)</subject>"
496 " <body enc=\"ASCII\">"
497 " XML_ATTRIBUTE_FIXED 0xC00CE016"
498 " </body>"
499 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
500 "</email>";
502 static const CHAR szEmailXML_17[] =
503 "<?xml version=\"1.0\"?>"
504 SZ_EMAIL_DTD
505 "<email attachments=\"patch1\" sent=\"true\">"
506 " <recipients>"
507 " <to>wine-patches@winehq.org</to>"
508 " </recipients>"
509 " <from name=\"Anonymous\">user@localhost</from>"
510 " <subject>msxml3/tests: DTD validation (try 95)</subject>"
511 " <body>"
512 " XML_ATTRIBUTE_VALUE 0xC00CE017"
513 " </body>"
514 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
515 "</email>";
517 static const CHAR szEmailXML_18[] =
518 "<?xml version=\"1.0\"?>"
519 SZ_EMAIL_DTD
520 "<email attachments=\"patch1\">"
521 " oops"
522 " <recipients>"
523 " <to>wine-patches@winehq.org</to>"
524 " </recipients>"
525 " <from name=\"Anonymous\">user@localhost</from>"
526 " <subject>msxml3/tests: DTD validation (try 96)</subject>"
527 " <body>"
528 " XML_ILLEGAL_TEXT 0xC00CE018"
529 " </body>"
530 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
531 "</email>";
533 static const CHAR szEmailXML_20[] =
534 "<?xml version=\"1.0\"?>"
535 SZ_EMAIL_DTD
536 "<email>"
537 " <recipients>"
538 " <to>wine-patches@winehq.org</to>"
539 " </recipients>"
540 " <from name=\"Anonymous\">user@localhost</from>"
541 " <subject>msxml3/tests: DTD validation (try 97)</subject>"
542 " <body>"
543 " XML_REQUIRED_ATTRIBUTE_MISSING 0xC00CE020"
544 " </body>"
545 " <attachment id=\"patch1\">0001-msxml3-tests-DTD-validation.patch</attachment>"
546 "</email>";
548 static const CHAR szDatatypeXDR[] =
549 "<Schema xmlns='urn:schemas-microsoft-com:xml-data'\n"
550 " xmlns:dt='urn:schemas-microsoft-com:datatypes'>\n"
551 " <ElementType name='base64Data' content='textOnly' dt:type='bin.base64'/>\n"
552 " <ElementType name='hexData' content='textOnly' dt:type='bin.hex'/>\n"
553 " <ElementType name='boolData' content='textOnly' dt:type='boolean'/>\n"
554 " <ElementType name='charData' content='textOnly' dt:type='char'/>\n"
555 " <ElementType name='dateData' content='textOnly' dt:type='date'/>\n"
556 " <ElementType name='dateTimeData' content='textOnly' dt:type='dateTime'/>\n"
557 " <ElementType name='dateTimeTzData' content='textOnly' dt:type='dateTime.tz'/>\n"
558 " <ElementType name='entityData' content='textOnly' dt:type='entity'/>\n"
559 " <ElementType name='entitiesData' content='textOnly' dt:type='entities'/>\n"
560 " <ElementType name='fixedData' content='textOnly' dt:type='fixed.14.4'/>\n"
561 " <ElementType name='floatData' content='textOnly' dt:type='float'/>\n"
562 " <ElementType name='i1Data' content='textOnly' dt:type='i1'/>\n"
563 " <ElementType name='i2Data' content='textOnly' dt:type='i2'/>\n"
564 " <ElementType name='i4Data' content='textOnly' dt:type='i4'/>\n"
565 " <ElementType name='i8Data' content='textOnly' dt:type='i8'/>\n"
566 " <ElementType name='intData' content='textOnly' dt:type='int'/>\n"
567 " <ElementType name='nmtokData' content='textOnly' dt:type='nmtoken'/>\n"
568 " <ElementType name='nmtoksData' content='textOnly' dt:type='nmtokens'/>\n"
569 " <ElementType name='numData' content='textOnly' dt:type='number'/>\n"
570 " <ElementType name='r4Data' content='textOnly' dt:type='r4'/>\n"
571 " <ElementType name='r8Data' content='textOnly' dt:type='r8'/>\n"
572 " <ElementType name='stringData' content='textOnly' dt:type='string'/>\n"
573 " <ElementType name='timeData' content='textOnly' dt:type='time'/>\n"
574 " <ElementType name='timeTzData' content='textOnly' dt:type='time.tz'/>\n"
575 " <ElementType name='u1Data' content='textOnly' dt:type='ui1'/>\n"
576 " <ElementType name='u2Data' content='textOnly' dt:type='ui2'/>\n"
577 " <ElementType name='u4Data' content='textOnly' dt:type='ui4'/>\n"
578 " <ElementType name='u8Data' content='textOnly' dt:type='ui8'/>\n"
579 " <ElementType name='uriData' content='textOnly' dt:type='uri'/>\n"
580 " <ElementType name='uuidData' content='textOnly' dt:type='uuid'/>\n"
581 "\n"
582 " <ElementType name='Name' content='textOnly' dt:type='nmtoken'/>\n"
583 " <ElementType name='Value' content='eltOnly' order='many'>\n"
584 " <element type='base64Data'/>\n"
585 " <element type='hexData'/>\n"
586 " <element type='boolData'/>\n"
587 " <element type='charData'/>\n"
588 " <element type='dateData'/>\n"
589 " <element type='dateTimeData'/>\n"
590 " <element type='dateTimeTzData'/>\n"
591 " <element type='entityData'/>\n"
592 " <element type='entitiesData'/>\n"
593 " <element type='fixedData'/>\n"
594 " <element type='floatData'/>\n"
595 " <element type='i1Data'/>\n"
596 " <element type='i2Data'/>\n"
597 " <element type='i4Data'/>\n"
598 " <element type='i8Data'/>\n"
599 " <element type='intData'/>\n"
600 " <element type='nmtokData'/>\n"
601 " <element type='nmtoksData'/>\n"
602 " <element type='numData'/>\n"
603 " <element type='r4Data'/>\n"
604 " <element type='r8Data'/>\n"
605 " <element type='stringData'/>\n"
606 " <element type='timeData'/>\n"
607 " <element type='timeTzData'/>\n"
608 " <element type='u1Data'/>\n"
609 " <element type='u2Data'/>\n"
610 " <element type='u4Data'/>\n"
611 " <element type='u8Data'/>\n"
612 " <element type='uriData'/>\n"
613 " <element type='uuidData'/>\n"
614 " </ElementType>\n"
615 " <ElementType name='Property' content='eltOnly' order='seq'>\n"
616 " <element type='Name'/>\n"
617 " <element type='Value'/>\n"
618 " </ElementType>\n"
619 " <ElementType name='Properties' content='eltOnly'>\n"
620 " <element type='Property' minOccurs='0' maxOccurs='*'/>\n"
621 " </ElementType>\n"
622 "</Schema>";
624 static const CHAR szDatatypeXML[] =
625 "<?xml version='1.0'?>\n"
626 "<Properties xmlns='urn:x-schema:datatype-test-xdr'>\n"
627 " <Property>\n"
628 " <Name>testBase64</Name>\n"
629 " <Value>\n"
630 " <base64Data>+HugeNumber+</base64Data>\n"
631 " </Value>\n"
632 " </Property>\n"
633 " <Property>\n"
634 " <Name>testHex</Name>\n"
635 " <Value>\n"
636 " <hexData>deadbeef</hexData>\n"
637 " </Value>\n"
638 " </Property>\n"
639 " <Property>\n"
640 " <Name>testBool</Name>\n"
641 " <Value>\n"
642 " <boolData>1</boolData>\n"
643 " </Value>\n"
644 " </Property>\n"
645 " <Property>\n"
646 " <Name>testChar</Name>\n"
647 " <Value>\n"
648 " <charData>u</charData>\n"
649 " </Value>\n"
650 " </Property>\n"
651 " <Property>\n"
652 " <Name>testDate</Name>\n"
653 " <Value>\n"
654 " <dateData>1998-02-01</dateData>\n"
655 " </Value>\n"
656 " </Property>\n"
657 " <Property>\n"
658 " <Name>testDateTime</Name>\n"
659 " <Value>\n"
660 " <dateTimeData>1998-02-01T12:34:56</dateTimeData>\n"
661 " </Value>\n"
662 " </Property>\n"
663 " <Property>\n"
664 " <Name>testDateTimeTz</Name>\n"
665 " <Value>\n"
666 " <dateTimeTzData>1998-02-01T12:34:56-06:00</dateTimeTzData>\n"
667 " </Value>\n"
668 " </Property>\n"
669 " <Property>\n"
670 " <Name>testFixed</Name>\n"
671 " <Value>\n"
672 " <fixedData>3.1416</fixedData>\n"
673 " </Value>\n"
674 " </Property>\n"
675 " <Property>\n"
676 " <Name>testFloat</Name>\n"
677 " <Value>\n"
678 " <floatData>3.14159</floatData>\n"
679 " </Value>\n"
680 " </Property>\n"
681 " <Property>\n"
682 " <Name>testI1</Name>\n"
683 " <Value>\n"
684 " <i1Data>42</i1Data>\n"
685 " </Value>\n"
686 " </Property>\n"
687 " <Property>\n"
688 " <Name>testI2</Name>\n"
689 " <Value>\n"
690 " <i2Data>420</i2Data>\n"
691 " </Value>\n"
692 " </Property>\n"
693 " <Property>\n"
694 " <Name>testI4</Name>\n"
695 " <Value>\n"
696 " <i4Data>-420000000</i4Data>\n"
697 " </Value>\n"
698 " </Property>\n"
699 " <Property>\n"
700 " <Name>testI8</Name>\n"
701 " <Value>\n"
702 " <i8Data>-4200000000</i8Data>\n"
703 " </Value>\n"
704 " </Property>\n"
705 " <Property>\n"
706 " <Name>testInt</Name>\n"
707 " <Value>\n"
708 " <intData>42</intData>\n"
709 " </Value>\n"
710 " </Property>\n"
711 " <Property>\n"
712 " <Name>testNmtoken</Name>\n"
713 " <Value>\n"
714 " <nmtokData>tok1</nmtokData>\n"
715 " </Value>\n"
716 " </Property>\n"
717 " <Property>\n"
718 " <Name>testNmtokens</Name>\n"
719 " <Value>\n"
720 " <nmtoksData>tok1 tok2 tok3</nmtoksData>\n"
721 " </Value>\n"
722 " </Property>\n"
723 " <Property>\n"
724 " <Name>testNumber</Name>\n"
725 " <Value>\n"
726 " <numData>3.14159</numData>\n"
727 " </Value>\n"
728 " </Property>\n"
729 " <Property>\n"
730 " <Name>testR4</Name>\n"
731 " <Value>\n"
732 " <r4Data>3.14159265</r4Data>\n"
733 " </Value>\n"
734 " </Property>\n"
735 " <Property>\n"
736 " <Name>testR8</Name>\n"
737 " <Value>\n"
738 " <r8Data>3.14159265358979323846</r8Data>\n"
739 " </Value>\n"
740 " </Property>\n"
741 " <Property>\n"
742 " <Name>testString</Name>\n"
743 " <Value>\n"
744 " <stringData>foo bar</stringData>\n"
745 " </Value>\n"
746 " </Property>\n"
747 " <Property>\n"
748 " <Name>testTime</Name>\n"
749 " <Value>\n"
750 " <timeData>12:34:56</timeData>\n"
751 " </Value>\n"
752 " </Property>\n"
753 " <Property>\n"
754 " <Name>testTimeTz</Name>\n"
755 " <Value>\n"
756 " <timeTzData>12:34:56-06:00</timeTzData>\n"
757 " </Value>\n"
758 " </Property>\n"
759 " <Property>\n"
760 " <Name>testU1</Name>\n"
761 " <Value>\n"
762 " <u1Data>255</u1Data>\n"
763 " </Value>\n"
764 " </Property>\n"
765 " <Property>\n"
766 " <Name>testU2</Name>\n"
767 " <Value>\n"
768 " <u2Data>65535</u2Data>\n"
769 " </Value>\n"
770 " </Property>\n"
771 " <Property>\n"
772 " <Name>testU4</Name>\n"
773 " <Value>\n"
774 " <u4Data>4294967295</u4Data>\n"
775 " </Value>\n"
776 " </Property>\n"
777 " <Property>\n"
778 " <Name>testU8</Name>\n"
779 " <Value>\n"
780 " <u8Data>18446744073709551615</u8Data>\n"
781 " </Value>\n"
782 " </Property>\n"
783 " <Property>\n"
784 " <Name>testURI</Name>\n"
785 " <Value>\n"
786 " <uriData>urn:schemas-microsoft-com:datatypes</uriData>\n"
787 " </Value>\n"
788 " </Property>\n"
789 " <Property>\n"
790 " <Name>testUUID</Name>\n"
791 " <Value>\n"
792 " <uuidData>2933BF81-7B36-11D2-B20E-00C04F983E60</uuidData>\n"
793 " </Value>\n"
794 " </Property>\n"
795 "</Properties>";
797 static const WCHAR szNonExistentFile[] = {
798 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
800 static const WCHAR szNonExistentAttribute[] = {
801 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
803 static const WCHAR szDocument[] = {
804 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
807 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
808 static WCHAR szdl[] = { 'd','l',0 };
809 static const WCHAR szvr[] = { 'v','r',0 };
810 static const WCHAR szlc[] = { 'l','c',0 };
811 static WCHAR szbs[] = { 'b','s',0 };
812 static const WCHAR szstr1[] = { 's','t','r','1',0 };
813 static const WCHAR szstr2[] = { 's','t','r','2',0 };
814 static const WCHAR szstar[] = { '*',0 };
815 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
817 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
818 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
819 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
821 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
822 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
823 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
824 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
825 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
826 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
827 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
829 static WCHAR szAttribute[] = {'A','t','t','r',0 };
830 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
832 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
833 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
834 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
835 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
836 '!',']',']','>',0};
837 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
838 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
840 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
841 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
842 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
844 #define expect_bstr_eq_and_free(bstr, expect) { \
845 BSTR bstrExp = alloc_str_from_narrow(expect); \
846 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
847 SysFreeString(bstr); \
848 SysFreeString(bstrExp); \
851 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
853 #define ole_check(expr) { \
854 HRESULT r = expr; \
855 ok(r == S_OK, #expr " returned %x\n", r); \
858 #define ole_expect(expr, expect) { \
859 HRESULT r = expr; \
860 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
863 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
865 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
867 void *obj = NULL;
868 HRESULT hr;
870 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
871 if (hr != S_OK)
872 win_skip_(__FILE__,line)("failed to create %s instance: 0x%08x\n", name, hr);
874 return obj;
877 #define _create(cls) cls, #cls
879 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument), iid, __LINE__)
881 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
883 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
885 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
887 static BSTR alloc_str_from_narrow(const char *str)
889 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
890 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
891 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
892 return ret;
895 static BSTR alloced_bstrs[256];
896 static int alloced_bstrs_count;
898 static BSTR _bstr_(const char *str)
900 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
901 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
902 return alloced_bstrs[alloced_bstrs_count++];
905 static void free_bstrs(void)
907 int i;
908 for (i = 0; i < alloced_bstrs_count; i++)
909 SysFreeString(alloced_bstrs[i]);
910 alloced_bstrs_count = 0;
913 static VARIANT _variantbstr_(const char *str)
915 VARIANT v;
916 V_VT(&v) = VT_BSTR;
917 V_BSTR(&v) = _bstr_(str);
918 return v;
921 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
923 for (;;)
925 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
926 while (*sRight == '\r' || *sRight == '\n') sRight++;
927 if (*sLeft != *sRight) return FALSE;
928 if (!*sLeft) return TRUE;
929 sLeft++;
930 sRight++;
934 static void get_str_for_type(DOMNodeType type, char *buf)
936 switch (type)
938 case NODE_ATTRIBUTE:
939 strcpy(buf, "A");
940 break;
941 case NODE_ELEMENT:
942 strcpy(buf, "E");
943 break;
944 case NODE_DOCUMENT:
945 strcpy(buf, "D");
946 break;
947 case NODE_TEXT:
948 strcpy(buf, "T");
949 break;
950 case NODE_COMMENT:
951 strcpy(buf, "C");
952 break;
953 case NODE_PROCESSING_INSTRUCTION:
954 strcpy(buf, "P");
955 break;
956 default:
957 wsprintfA(buf, "[%d]", type);
961 #define test_disp(u) _test_disp(__LINE__,u)
962 static void _test_disp(unsigned line, IUnknown *unk)
964 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
965 IDispatchEx *dispex;
966 DWORD dwProps = 0;
967 BSTR sName;
968 UINT ticnt;
969 IUnknown *pUnk;
970 HRESULT hres;
972 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
973 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
974 if(FAILED(hres))
975 return;
977 ticnt = 0xdeadbeef;
978 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
979 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
980 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
982 sName = SysAllocString( szstar );
983 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
984 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
985 SysFreeString( sName );
987 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
988 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
990 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
991 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
992 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
994 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
995 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
996 if(SUCCEEDED(hres))
997 SysFreeString(sName);
999 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
1000 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1002 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
1003 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
1004 if(hres == S_OK && pUnk)
1005 IUnknown_Release(pUnk);
1007 IDispatchEx_Release(dispex);
1010 static int get_node_position(IXMLDOMNode *node)
1012 HRESULT r;
1013 int pos = 0;
1015 IXMLDOMNode_AddRef(node);
1018 IXMLDOMNode *new_node;
1020 pos++;
1021 r = IXMLDOMNode_get_previousSibling(node, &new_node);
1022 ok(SUCCEEDED(r), "get_previousSibling failed\n");
1023 IXMLDOMNode_Release(node);
1024 node = new_node;
1025 } while (r == S_OK);
1026 return pos;
1029 static void node_to_string(IXMLDOMNode *node, char *buf)
1031 HRESULT r = S_OK;
1032 DOMNodeType type;
1034 if (node == NULL)
1036 lstrcpyA(buf, "(null)");
1037 return;
1040 IXMLDOMNode_AddRef(node);
1041 while (r == S_OK)
1043 IXMLDOMNode *new_node;
1045 ole_check(IXMLDOMNode_get_nodeType(node, &type));
1046 get_str_for_type(type, buf);
1047 buf+=strlen(buf);
1049 if (type == NODE_ATTRIBUTE)
1051 BSTR bstr;
1052 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
1053 *(buf++) = '\'';
1054 wsprintfA(buf, "%ws", bstr);
1055 buf += strlen(buf);
1056 *(buf++) = '\'';
1057 SysFreeString(bstr);
1059 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
1061 else
1063 r = IXMLDOMNode_get_parentNode(node, &new_node);
1064 wsprintf(buf, "%d", get_node_position(node));
1065 buf += strlen(buf);
1068 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
1069 IXMLDOMNode_Release(node);
1070 node = new_node;
1071 if (r == S_OK)
1072 *(buf++) = '.';
1075 *buf = 0;
1078 static char *list_to_string(IXMLDOMNodeList *list)
1080 static char buf[4096];
1081 char *pos = buf;
1082 LONG len = 0;
1083 int i;
1085 if (list == NULL)
1087 lstrcpyA(buf, "(null)");
1088 return buf;
1090 ole_check(IXMLDOMNodeList_get_length(list, &len));
1091 for (i = 0; i < len; i++)
1093 IXMLDOMNode *node;
1094 if (i > 0)
1095 *(pos++) = ' ';
1096 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1097 node_to_string(node, pos);
1098 pos += strlen(pos);
1099 IXMLDOMNode_Release(node);
1101 *pos = 0;
1102 return buf;
1105 #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); }
1106 #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); }
1108 static void test_domdoc( void )
1110 HRESULT r;
1111 IXMLDOMDocument *doc;
1112 IXMLDOMParseError *error;
1113 IXMLDOMElement *element = NULL;
1114 IXMLDOMNode *node;
1115 IXMLDOMText *nodetext = NULL;
1116 IXMLDOMComment *node_comment = NULL;
1117 IXMLDOMAttribute *node_attr = NULL;
1118 IXMLDOMNode *nodeChild = NULL;
1119 IXMLDOMProcessingInstruction *nodePI = NULL;
1120 ISupportErrorInfo *support_error = NULL;
1121 VARIANT_BOOL b;
1122 VARIANT var;
1123 BSTR str;
1124 LONG code;
1125 LONG nLength = 0;
1126 WCHAR buff[100];
1128 doc = create_document(&IID_IXMLDOMDocument);
1129 if (!doc) return;
1131 test_disp((IUnknown*)doc);
1133 if (0)
1135 /* crashes on native */
1136 r = IXMLDOMDocument_loadXML( doc, (BSTR)0x1, NULL );
1139 /* try some stupid things */
1140 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
1141 ok( r == S_FALSE, "loadXML succeeded\n");
1143 b = VARIANT_TRUE;
1144 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
1145 ok( r == S_FALSE, "loadXML succeeded\n");
1146 ok( b == VARIANT_FALSE, "failed to load XML string\n");
1148 /* try to load a document from a nonexistent file */
1149 b = VARIANT_TRUE;
1150 str = SysAllocString( szNonExistentFile );
1151 VariantInit(&var);
1152 V_VT(&var) = VT_BSTR;
1153 V_BSTR(&var) = str;
1155 r = IXMLDOMDocument_load( doc, var, &b);
1156 ok( r == S_FALSE, "loadXML succeeded\n");
1157 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1158 SysFreeString( str );
1160 /* try load an empty document */
1161 b = VARIANT_TRUE;
1162 str = SysAllocString( szEmpty );
1163 r = IXMLDOMDocument_loadXML( doc, str, &b );
1164 ok( r == S_FALSE, "loadXML succeeded\n");
1165 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1166 SysFreeString( str );
1168 r = IXMLDOMDocument_get_async( doc, &b );
1169 ok( r == S_OK, "get_async failed (%08x)\n", r);
1170 ok( b == VARIANT_TRUE, "Wrong default value\n");
1172 /* check that there's no document element */
1173 element = NULL;
1174 r = IXMLDOMDocument_get_documentElement( doc, &element );
1175 ok( r == S_FALSE, "should be no document element\n");
1177 /* try finding a node */
1178 node = NULL;
1179 str = SysAllocString( szstr1 );
1180 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
1181 ok( r == S_FALSE, "ret %08x\n", r );
1182 SysFreeString( str );
1184 b = VARIANT_TRUE;
1185 str = SysAllocString( szIncomplete );
1186 r = IXMLDOMDocument_loadXML( doc, str, &b );
1187 ok( r == S_FALSE, "loadXML succeeded\n");
1188 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1189 SysFreeString( str );
1191 /* check that there's no document element */
1192 element = (IXMLDOMElement*)1;
1193 r = IXMLDOMDocument_get_documentElement( doc, &element );
1194 ok( r == S_FALSE, "should be no document element\n");
1195 ok( element == NULL, "Element should be NULL\n");
1197 /* test for BSTR handling, pass broken BSTR */
1198 memcpy(&buff[2], szComplete1, sizeof(szComplete1));
1199 /* just a big length */
1200 *(DWORD*)buff = 0xf0f0;
1201 b = VARIANT_FALSE;
1202 r = IXMLDOMDocument_loadXML( doc, &buff[2], &b );
1203 ok( r == S_OK, "loadXML failed\n");
1204 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1206 /* loadXML ignores the encoding attribute and always expects Unicode */
1207 b = VARIANT_FALSE;
1208 str = SysAllocString( szComplete6 );
1209 r = IXMLDOMDocument_loadXML( doc, str, &b );
1210 ok( r == S_OK, "loadXML failed\n");
1211 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1212 SysFreeString( str );
1214 /* try a BSTR containing a Windows-1252 document */
1215 b = VARIANT_TRUE;
1216 str = SysAllocStringByteLen( szNonUnicodeXML, sizeof(szNonUnicodeXML) - 1 );
1217 r = IXMLDOMDocument_loadXML( doc, str, &b );
1218 ok( r == S_FALSE, "loadXML succeeded\n");
1219 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
1220 SysFreeString( str );
1222 /* try to load something valid */
1223 b = VARIANT_FALSE;
1224 str = SysAllocString( szComplete1 );
1225 r = IXMLDOMDocument_loadXML( doc, str, &b );
1226 ok( r == S_OK, "loadXML failed\n");
1227 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1228 SysFreeString( str );
1230 /* check if nodename is correct */
1231 r = IXMLDOMDocument_get_nodeName( doc, NULL );
1232 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1234 str = (BSTR)0xdeadbeef;
1235 r = IXMLDOMDocument_get_baseName( doc, &str );
1236 ok ( r == S_FALSE, "got 0x%08x\n", r);
1237 ok (str == NULL, "got %p\n", str);
1239 /* content doesn't matter here */
1240 str = NULL;
1241 r = IXMLDOMDocument_get_nodeName( doc, &str );
1242 ok ( r == S_OK, "get_nodeName wrong code\n");
1243 ok ( str != NULL, "str is null\n");
1244 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
1245 SysFreeString( str );
1247 /* test put_text */
1248 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
1249 ok( r == E_FAIL, "ret %08x\n", r );
1251 /* check that there's a document element */
1252 element = NULL;
1253 r = IXMLDOMDocument_get_documentElement( doc, &element );
1254 ok( r == S_OK, "should be a document element\n");
1255 if( element )
1257 IObjectIdentity *ident;
1258 BSTR tag = NULL;
1260 test_disp((IUnknown*)element);
1262 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (void**)&ident );
1263 ok( r == E_NOINTERFACE, "ret %08x\n", r);
1265 r = IXMLDOMElement_get_tagName( element, NULL );
1266 ok( r == E_INVALIDARG, "ret %08x\n", r);
1268 /* check if the tag is correct */
1269 r = IXMLDOMElement_get_tagName( element, &tag );
1270 ok( r == S_OK, "couldn't get tag name\n");
1271 ok( tag != NULL, "tag was null\n");
1272 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
1273 SysFreeString( tag );
1275 /* figure out what happens if we try to reload the document */
1276 str = SysAllocString( szComplete2 );
1277 r = IXMLDOMDocument_loadXML( doc, str, &b );
1278 ok( r == S_OK, "loadXML failed\n");
1279 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1280 SysFreeString( str );
1282 /* check if the tag is still correct */
1283 tag = NULL;
1284 r = IXMLDOMElement_get_tagName( element, &tag );
1285 ok( r == S_OK, "couldn't get tag name\n");
1286 ok( tag != NULL, "tag was null\n");
1287 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
1288 SysFreeString( tag );
1290 IXMLDOMElement_Release( element );
1291 element = NULL;
1294 /* as soon as we call loadXML again, the document element will disappear */
1295 b = 2;
1296 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
1297 ok( r == S_FALSE, "loadXML failed\n");
1298 ok( b == 2, "variant modified\n");
1299 r = IXMLDOMDocument_get_documentElement( doc, &element );
1300 ok( r == S_FALSE, "should be no document element\n");
1302 /* try to load something else simple and valid */
1303 b = VARIANT_FALSE;
1304 str = SysAllocString( szComplete3 );
1305 r = IXMLDOMDocument_loadXML( doc, str, &b );
1306 ok( r == S_OK, "loadXML failed\n");
1307 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1308 SysFreeString( str );
1310 /* try something a little more complicated */
1311 b = FALSE;
1312 str = SysAllocString( szComplete4 );
1313 r = IXMLDOMDocument_loadXML( doc, str, &b );
1314 ok( r == S_OK, "loadXML failed\n");
1315 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1316 SysFreeString( str );
1318 r = IXMLDOMDocument_get_parseError( doc, &error );
1319 ok( r == S_OK, "returns %08x\n", r );
1321 r = IXMLDOMParseError_get_errorCode( error, &code );
1322 ok( r == S_FALSE, "returns %08x\n", r );
1323 ok( code == 0, "code %d\n", code );
1324 IXMLDOMParseError_Release( error );
1326 /* test createTextNode */
1327 r = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &nodetext);
1328 ok( r == S_OK, "returns %08x\n", r );
1329 IXMLDOMText_Release(nodetext);
1331 str = SysAllocString( szOpen );
1332 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
1333 ok( r == E_INVALIDARG, "returns %08x\n", r );
1334 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
1335 ok( r == S_OK, "returns %08x\n", r );
1336 SysFreeString( str );
1337 if(nodetext)
1339 IXMLDOMNamedNodeMap *pAttribs;
1341 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element);
1342 ok(r == E_NOINTERFACE, "ret %08x\n", r );
1344 /* Text Last Child Checks */
1345 r = IXMLDOMText_get_lastChild(nodetext, NULL);
1346 ok(r == E_INVALIDARG, "ret %08x\n", r );
1348 nodeChild = (IXMLDOMNode*)0x1;
1349 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
1350 ok(r == S_FALSE, "ret %08x\n", r );
1351 ok(nodeChild == NULL, "nodeChild not NULL\n");
1353 /* test get_attributes */
1354 r = IXMLDOMText_get_attributes( nodetext, NULL );
1355 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
1357 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
1358 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
1359 ok(r == S_FALSE, "ret %08x\n", r );
1360 ok( pAttribs == NULL, "pAttribs not NULL\n");
1362 /* test get_dataType */
1363 r = IXMLDOMText_get_dataType(nodetext, &var);
1364 ok(r == S_FALSE, "ret %08x\n", r );
1365 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
1366 VariantClear(&var);
1368 /* test length property */
1369 r = IXMLDOMText_get_length(nodetext, NULL);
1370 ok(r == E_INVALIDARG, "ret %08x\n", r );
1372 r = IXMLDOMText_get_length(nodetext, &nLength);
1373 ok(r == S_OK, "ret %08x\n", r );
1374 ok(nLength == 4, "expected 4 got %d\n", nLength);
1376 /* test nodeTypeString */
1377 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
1378 ok(r == S_OK, "ret %08x\n", r );
1379 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
1380 SysFreeString(str);
1382 /* put data Tests */
1383 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
1384 ok(r == S_OK, "ret %08x\n", r );
1386 /* get data Tests */
1387 r = IXMLDOMText_get_data(nodetext, &str);
1388 ok(r == S_OK, "ret %08x\n", r );
1389 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
1390 SysFreeString(str);
1392 /* Confirm XML text is good */
1393 r = IXMLDOMText_get_xml(nodetext, &str);
1394 ok(r == S_OK, "ret %08x\n", r );
1395 ok( !lstrcmpW( str, _bstr_("This &amp;is a ; test &lt;&gt;\\") ), "incorrect xml string\n");
1396 SysFreeString(str);
1398 /* Confirm we get the put_data Text back */
1399 r = IXMLDOMText_get_text(nodetext, &str);
1400 ok(r == S_OK, "ret %08x\n", r );
1401 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
1402 SysFreeString(str);
1404 /* test substringData */
1405 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
1406 ok(r == E_INVALIDARG, "ret %08x\n", r );
1408 /* test substringData - Invalid offset */
1409 str = (BSTR)&szElement;
1410 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
1411 ok(r == E_INVALIDARG, "ret %08x\n", r );
1412 ok( str == NULL, "incorrect string\n");
1414 /* test substringData - Invalid offset */
1415 str = (BSTR)&szElement;
1416 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
1417 ok(r == S_FALSE, "ret %08x\n", r );
1418 ok( str == NULL, "incorrect string\n");
1420 /* test substringData - Invalid size */
1421 str = (BSTR)&szElement;
1422 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
1423 ok(r == E_INVALIDARG, "ret %08x\n", r );
1424 ok( str == NULL, "incorrect string\n");
1426 /* test substringData - Invalid size */
1427 str = (BSTR)&szElement;
1428 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
1429 ok(r == S_FALSE, "ret %08x\n", r );
1430 ok( str == NULL, "incorrect string\n");
1432 /* test substringData - Start of string */
1433 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
1434 ok(r == S_OK, "ret %08x\n", r );
1435 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
1436 SysFreeString(str);
1438 /* test substringData - Middle of string */
1439 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
1440 ok(r == S_OK, "ret %08x\n", r );
1441 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
1442 SysFreeString(str);
1444 /* test substringData - End of string */
1445 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
1446 ok(r == S_OK, "ret %08x\n", r );
1447 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
1448 SysFreeString(str);
1450 /* test appendData */
1451 r = IXMLDOMText_appendData(nodetext, NULL);
1452 ok(r == S_OK, "ret %08x\n", r );
1454 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
1455 ok(r == S_OK, "ret %08x\n", r );
1457 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
1458 ok(r == S_OK, "ret %08x\n", r );
1460 r = IXMLDOMText_get_text(nodetext, &str);
1461 ok(r == S_OK, "ret %08x\n", r );
1462 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1463 SysFreeString(str);
1465 /* test insertData */
1466 str = SysAllocStringLen(NULL, 0);
1467 r = IXMLDOMText_insertData(nodetext, -1, str);
1468 ok(r == S_OK, "ret %08x\n", r );
1470 r = IXMLDOMText_insertData(nodetext, -1, NULL);
1471 ok(r == S_OK, "ret %08x\n", r );
1473 r = IXMLDOMText_insertData(nodetext, 1000, str);
1474 ok(r == S_OK, "ret %08x\n", r );
1476 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
1477 ok(r == S_OK, "ret %08x\n", r );
1479 r = IXMLDOMText_insertData(nodetext, 0, NULL);
1480 ok(r == S_OK, "ret %08x\n", r );
1482 r = IXMLDOMText_insertData(nodetext, 0, str);
1483 ok(r == S_OK, "ret %08x\n", r );
1484 SysFreeString(str);
1486 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
1487 ok(r == E_INVALIDARG, "ret %08x\n", r );
1489 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
1490 ok(r == E_INVALIDARG, "ret %08x\n", r );
1492 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
1493 ok(r == S_OK, "ret %08x\n", r );
1495 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
1496 ok(r == S_OK, "ret %08x\n", r );
1498 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
1499 ok(r == S_OK, "ret %08x\n", r );
1501 r = IXMLDOMText_get_text(nodetext, &str);
1502 ok(r == S_OK, "ret %08x\n", r );
1503 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1504 SysFreeString(str);
1506 /* delete data */
1507 /* invalid arguments */
1508 r = IXMLDOMText_deleteData(nodetext, -1, 1);
1509 ok(r == E_INVALIDARG, "ret %08x\n", r );
1511 r = IXMLDOMText_deleteData(nodetext, 0, 0);
1512 ok(r == S_OK, "ret %08x\n", r );
1514 r = IXMLDOMText_deleteData(nodetext, 0, -1);
1515 ok(r == E_INVALIDARG, "ret %08x\n", r );
1517 r = IXMLDOMText_get_length(nodetext, &nLength);
1518 ok(r == S_OK, "ret %08x\n", r );
1519 ok(nLength == 43, "expected 43 got %d\n", nLength);
1521 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
1522 ok(r == S_OK, "ret %08x\n", r );
1524 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
1525 ok(r == E_INVALIDARG, "ret %08x\n", r );
1527 /* delete from start */
1528 r = IXMLDOMText_deleteData(nodetext, 0, 5);
1529 ok(r == S_OK, "ret %08x\n", r );
1531 r = IXMLDOMText_get_length(nodetext, &nLength);
1532 ok(r == S_OK, "ret %08x\n", r );
1533 ok(nLength == 38, "expected 38 got %d\n", nLength);
1535 r = IXMLDOMText_get_text(nodetext, &str);
1536 ok(r == S_OK, "ret %08x\n", r );
1537 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1538 SysFreeString(str);
1540 /* delete from end */
1541 r = IXMLDOMText_deleteData(nodetext, 35, 3);
1542 ok(r == S_OK, "ret %08x\n", r );
1544 r = IXMLDOMText_get_length(nodetext, &nLength);
1545 ok(r == S_OK, "ret %08x\n", r );
1546 ok(nLength == 35, "expected 35 got %d\n", nLength);
1548 r = IXMLDOMText_get_text(nodetext, &str);
1549 ok(r == S_OK, "ret %08x\n", r );
1550 ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1551 SysFreeString(str);
1553 /* delete from inside */
1554 r = IXMLDOMText_deleteData(nodetext, 1, 33);
1555 ok(r == S_OK, "ret %08x\n", r );
1557 r = IXMLDOMText_get_length(nodetext, &nLength);
1558 ok(r == S_OK, "ret %08x\n", r );
1559 ok(nLength == 2, "expected 2 got %d\n", nLength);
1561 r = IXMLDOMText_get_text(nodetext, &str);
1562 ok(r == S_OK, "ret %08x\n", r );
1563 ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1564 SysFreeString(str);
1566 /* delete whole data ... */
1567 r = IXMLDOMText_get_length(nodetext, &nLength);
1568 ok(r == S_OK, "ret %08x\n", r );
1570 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1571 ok(r == S_OK, "ret %08x\n", r );
1572 /* ... and try again with empty string */
1573 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1574 ok(r == S_OK, "ret %08x\n", r );
1576 /* test put_data */
1577 V_VT(&var) = VT_BSTR;
1578 V_BSTR(&var) = SysAllocString(szstr1);
1579 r = IXMLDOMText_put_nodeValue(nodetext, var);
1580 ok(r == S_OK, "ret %08x\n", r );
1581 VariantClear(&var);
1583 r = IXMLDOMText_get_text(nodetext, &str);
1584 ok(r == S_OK, "ret %08x\n", r );
1585 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1586 SysFreeString(str);
1588 /* test put_data */
1589 V_VT(&var) = VT_I4;
1590 V_I4(&var) = 99;
1591 r = IXMLDOMText_put_nodeValue(nodetext, var);
1592 ok(r == S_OK, "ret %08x\n", r );
1593 VariantClear(&var);
1595 r = IXMLDOMText_get_text(nodetext, &str);
1596 ok(r == S_OK, "ret %08x\n", r );
1597 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1598 SysFreeString(str);
1600 /* ::replaceData() */
1601 V_VT(&var) = VT_BSTR;
1602 V_BSTR(&var) = SysAllocString(szstr1);
1603 r = IXMLDOMText_put_nodeValue(nodetext, var);
1604 ok(r == S_OK, "ret %08x\n", r );
1605 VariantClear(&var);
1607 r = IXMLDOMText_replaceData(nodetext, 6, 0, NULL);
1608 ok(r == E_INVALIDARG, "ret %08x\n", r );
1609 r = IXMLDOMText_get_text(nodetext, &str);
1610 ok(r == S_OK, "ret %08x\n", r );
1611 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1612 SysFreeString(str);
1614 r = IXMLDOMText_replaceData(nodetext, 0, 0, NULL);
1615 ok(r == S_OK, "ret %08x\n", r );
1616 r = IXMLDOMText_get_text(nodetext, &str);
1617 ok(r == S_OK, "ret %08x\n", r );
1618 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1619 SysFreeString(str);
1621 /* NULL pointer means delete */
1622 r = IXMLDOMText_replaceData(nodetext, 0, 1, NULL);
1623 ok(r == S_OK, "ret %08x\n", r );
1624 r = IXMLDOMText_get_text(nodetext, &str);
1625 ok(r == S_OK, "ret %08x\n", r );
1626 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1627 SysFreeString(str);
1629 /* empty string means delete */
1630 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_(""));
1631 ok(r == S_OK, "ret %08x\n", r );
1632 r = IXMLDOMText_get_text(nodetext, &str);
1633 ok(r == S_OK, "ret %08x\n", r );
1634 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1635 SysFreeString(str);
1637 /* zero count means insert */
1638 r = IXMLDOMText_replaceData(nodetext, 0, 0, _bstr_("a"));
1639 ok(r == S_OK, "ret %08x\n", r );
1640 r = IXMLDOMText_get_text(nodetext, &str);
1641 ok(r == S_OK, "ret %08x\n", r );
1642 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1643 SysFreeString(str);
1645 r = IXMLDOMText_replaceData(nodetext, 0, 2, NULL);
1646 ok(r == S_OK, "ret %08x\n", r );
1648 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("m"));
1649 ok(r == S_OK, "ret %08x\n", r );
1650 r = IXMLDOMText_get_text(nodetext, &str);
1651 ok(r == S_OK, "ret %08x\n", r );
1652 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1653 SysFreeString(str);
1655 /* nonempty string, count greater than its length */
1656 r = IXMLDOMText_replaceData(nodetext, 0, 2, _bstr_("a1.2"));
1657 ok(r == S_OK, "ret %08x\n", r );
1658 r = IXMLDOMText_get_text(nodetext, &str);
1659 ok(r == S_OK, "ret %08x\n", r );
1660 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1661 SysFreeString(str);
1663 /* nonempty string, count less than its length */
1664 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_("wine"));
1665 ok(r == S_OK, "ret %08x\n", r );
1666 r = IXMLDOMText_get_text(nodetext, &str);
1667 ok(r == S_OK, "ret %08x\n", r );
1668 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1669 SysFreeString(str);
1671 IXMLDOMText_Release( nodetext );
1674 /* test Create Comment */
1675 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
1676 ok( r == E_INVALIDARG, "returns %08x\n", r );
1677 node_comment = (IXMLDOMComment*)0x1;
1679 /* empty comment */
1680 r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
1681 ok( r == S_OK, "returns %08x\n", r );
1682 str = (BSTR)0x1;
1683 r = IXMLDOMComment_get_data(node_comment, &str);
1684 ok( r == S_OK, "returns %08x\n", r );
1685 ok( str && SysStringLen(str) == 0, "expected empty string data\n");
1686 IXMLDOMComment_Release(node_comment);
1687 SysFreeString(str);
1689 r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
1690 ok( r == S_OK, "returns %08x\n", r );
1691 str = (BSTR)0x1;
1692 r = IXMLDOMComment_get_data(node_comment, &str);
1693 ok( r == S_OK, "returns %08x\n", r );
1694 ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
1695 IXMLDOMComment_Release(node_comment);
1696 SysFreeString(str);
1698 str = SysAllocString(szComment);
1699 r = IXMLDOMDocument_createComment(doc, str, &node_comment);
1700 SysFreeString(str);
1701 ok( r == S_OK, "returns %08x\n", r );
1702 if(node_comment)
1704 /* Last Child Checks */
1705 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
1706 ok(r == E_INVALIDARG, "ret %08x\n", r );
1708 nodeChild = (IXMLDOMNode*)0x1;
1709 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
1710 ok(r == S_FALSE, "ret %08x\n", r );
1711 ok(nodeChild == NULL, "pLastChild not NULL\n");
1713 /* baseName */
1714 str = (BSTR)0xdeadbeef;
1715 IXMLDOMComment_get_baseName(node_comment, &str);
1716 ok(r == S_FALSE, "ret %08x\n", r );
1717 ok(str == NULL, "Expected NULL\n");
1719 IXMLDOMComment_Release( node_comment );
1722 /* test Create Attribute */
1723 str = SysAllocString(szAttribute);
1724 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
1725 ok( r == E_INVALIDARG, "returns %08x\n", r );
1726 r = IXMLDOMDocument_createAttribute(doc, str, &node_attr);
1727 ok( r == S_OK, "returns %08x\n", r );
1728 IXMLDOMText_Release( node_attr);
1729 SysFreeString(str);
1731 /* test Processing Instruction */
1732 str = SysAllocStringLen(NULL, 0);
1733 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
1734 ok( r == E_INVALIDARG, "returns %08x\n", r );
1735 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
1736 ok( r == E_FAIL, "returns %08x\n", r );
1737 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
1738 ok( r == E_FAIL, "returns %08x\n", r );
1739 SysFreeString(str);
1741 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
1742 ok( r == S_OK, "returns %08x\n", r );
1743 if(nodePI)
1745 /* Last Child Checks */
1746 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
1747 ok(r == E_INVALIDARG, "ret %08x\n", r );
1749 nodeChild = (IXMLDOMNode*)0x1;
1750 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
1751 ok(r == S_FALSE, "ret %08x\n", r );
1752 ok(nodeChild == NULL, "nodeChild not NULL\n");
1754 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
1755 ok(r == S_FALSE, "ret %08x\n", r );
1756 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
1757 VariantClear(&var);
1759 /* test nodeName */
1760 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1761 ok(r == S_OK, "ret %08x\n", r );
1762 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1763 SysFreeString(str);
1765 /* test baseName */
1766 str = (BSTR)0x1;
1767 r = IXMLDOMProcessingInstruction_get_baseName(nodePI, &str);
1768 ok(r == S_OK, "ret %08x\n", r );
1769 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1770 SysFreeString(str);
1772 /* test Target */
1773 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
1774 ok(r == S_OK, "ret %08x\n", r );
1775 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
1776 SysFreeString(str);
1778 /* test nodeTypeString */
1779 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
1780 ok(r == S_OK, "ret %08x\n", r );
1781 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
1782 SysFreeString(str);
1784 /* test get_nodeValue */
1785 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
1786 ok(r == S_OK, "ret %08x\n", r );
1787 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1788 VariantClear(&var);
1790 /* test get_data */
1791 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
1792 ok(r == S_OK, "ret %08x\n", r );
1793 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1794 SysFreeString(str);
1796 /* test put_data */
1797 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
1798 ok(r == E_FAIL, "ret %08x\n", r );
1800 /* test put_data */
1801 V_VT(&var) = VT_BSTR;
1802 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
1803 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
1804 ok(r == E_FAIL, "ret %08x\n", r );
1805 VariantClear(&var);
1807 /* test get nodeName */
1808 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1809 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1810 ok(r == S_OK, "ret %08x\n", r );
1811 SysFreeString(str);
1813 IXMLDOMProcessingInstruction_Release(nodePI);
1816 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (void**)&support_error );
1817 ok( r == S_OK, "ret %08x\n", r );
1818 if(r == S_OK)
1820 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
1821 todo_wine ok( r == S_OK, "ret %08x\n", r );
1822 ISupportErrorInfo_Release( support_error );
1825 r = IXMLDOMDocument_Release( doc );
1826 ok( r == 0, "document ref count incorrect\n");
1828 free_bstrs();
1831 static void test_persiststreaminit(void)
1833 IXMLDOMDocument *doc;
1834 IPersistStreamInit *streaminit;
1835 HRESULT hr;
1837 doc = create_document(&IID_IXMLDOMDocument);
1838 if (!doc) return;
1840 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&streaminit);
1841 ok( hr == S_OK, "failed with 0x%08x\n", hr );
1843 hr = IPersistStreamInit_InitNew(streaminit);
1844 ok( hr == S_OK, "failed with 0x%08x\n", hr );
1846 IXMLDOMDocument_Release(doc);
1849 static void test_domnode( void )
1851 HRESULT r;
1852 IXMLDOMDocument *doc, *owner = NULL;
1853 IXMLDOMElement *element = NULL;
1854 IXMLDOMNamedNodeMap *map = NULL;
1855 IXMLDOMNode *node = NULL, *next = NULL;
1856 IXMLDOMNodeList *list = NULL;
1857 IXMLDOMAttribute *attr = NULL;
1858 DOMNodeType type = NODE_INVALID;
1859 VARIANT_BOOL b;
1860 BSTR str;
1861 VARIANT var;
1862 LONG count;
1864 doc = create_document(&IID_IXMLDOMDocument);
1865 if (!doc) return;
1867 b = FALSE;
1868 str = SysAllocString( szComplete4 );
1869 r = IXMLDOMDocument_loadXML( doc, str, &b );
1870 ok( r == S_OK, "loadXML failed\n");
1871 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1872 SysFreeString( str );
1874 b = 1;
1875 r = IXMLDOMNode_hasChildNodes( doc, &b );
1876 ok( r == S_OK, "hasChildNoes bad return\n");
1877 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1879 r = IXMLDOMDocument_get_documentElement( doc, &element );
1880 ok( r == S_OK, "should be a document element\n");
1881 ok( element != NULL, "should be an element\n");
1883 VariantInit(&var);
1884 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1886 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1887 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1889 r = IXMLDOMNode_get_nodeValue( doc, &var );
1890 ok( r == S_FALSE, "nextNode returned wrong code\n");
1891 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1892 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1894 if (element)
1896 owner = NULL;
1897 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1898 ok( r == S_OK, "get_ownerDocument return code\n");
1899 ok( owner != doc, "get_ownerDocument return\n");
1900 IXMLDOMDocument_Release(owner);
1902 type = NODE_INVALID;
1903 r = IXMLDOMNode_get_nodeType( element, &type);
1904 ok( r == S_OK, "got %08x\n", r);
1905 ok( type == NODE_ELEMENT, "node not an element\n");
1907 str = NULL;
1908 r = IXMLDOMNode_get_baseName( element, &str );
1909 ok( r == S_OK, "get_baseName returned wrong code\n");
1910 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1911 SysFreeString(str);
1913 /* check if nodename is correct */
1914 r = IXMLDOMElement_get_nodeName( element, NULL );
1915 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1917 /* content doesn't matter here */
1918 str = NULL;
1919 r = IXMLDOMElement_get_nodeName( element, &str );
1920 ok ( r == S_OK, "get_nodeName wrong code\n");
1921 ok ( str != NULL, "str is null\n");
1922 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1923 SysFreeString( str );
1925 str = SysAllocString( szNonExistentFile );
1926 V_VT(&var) = VT_I4;
1927 V_I4(&var) = 0x1234;
1928 r = IXMLDOMElement_getAttribute( element, str, &var );
1929 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1930 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1931 VariantClear(&var);
1933 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1934 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1936 attr = (IXMLDOMAttribute*)0xdeadbeef;
1937 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1938 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1939 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1940 SysFreeString( str );
1942 attr = (IXMLDOMAttribute*)0xdeadbeef;
1943 str = SysAllocString( szNonExistentAttribute );
1944 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1945 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1946 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1947 SysFreeString( str );
1949 str = SysAllocString( szdl );
1950 V_VT(&var) = VT_I4;
1951 V_I4(&var) = 0x1234;
1952 r = IXMLDOMElement_getAttribute( element, str, &var );
1953 ok( r == S_OK, "getAttribute ret %08x\n", r );
1954 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1955 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1956 VariantClear( &var );
1958 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1959 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1961 r = IXMLDOMElement_getAttribute( element, str, NULL );
1962 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1964 attr = NULL;
1965 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1966 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1967 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1968 if (attr)
1970 r = IXMLDOMAttribute_get_parentNode( attr, NULL );
1971 ok( r == E_INVALIDARG, "Expected E_INVALIDARG, ret %08x\n", r );
1973 /* attribute doesn't have a parent in msxml interpretation */
1974 node = (IXMLDOMNode*)0xdeadbeef;
1975 r = IXMLDOMAttribute_get_parentNode( attr, &node );
1976 ok( r == S_FALSE, "Expected S_FALSE, ret %08x\n", r );
1977 ok( node == NULL, "Expected NULL, got %p\n", node );
1979 IXMLDOMAttribute_Release(attr);
1982 SysFreeString( str );
1984 r = IXMLDOMElement_get_attributes( element, &map );
1985 ok( r == S_OK, "get_attributes returned wrong code\n");
1986 ok( map != NULL, "should be attributes\n");
1988 b = 1;
1989 r = IXMLDOMNode_hasChildNodes( element, &b );
1990 ok( r == S_OK, "hasChildNoes bad return\n");
1991 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1993 else
1994 ok( FALSE, "no element\n");
1996 if (map)
1998 ISupportErrorInfo *support_error;
1999 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (void**)&support_error );
2000 ok( r == S_OK, "ret %08x\n", r );
2002 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
2003 todo_wine
2005 ok( r == S_OK, "ret %08x\n", r );
2007 ISupportErrorInfo_Release( support_error );
2009 str = SysAllocString( szdl );
2010 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
2011 ok( r == S_OK, "getNamedItem returned wrong code\n");
2012 ok( node != NULL, "should be attributes\n");
2013 IXMLDOMNode_Release(node);
2014 SysFreeString( str );
2016 str = SysAllocString( szdl );
2017 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
2018 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
2019 SysFreeString( str );
2021 /* something that isn't in szComplete4 */
2022 str = SysAllocString( szOpen );
2023 node = (IXMLDOMNode *) 1;
2024 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
2025 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
2026 ok( node == NULL, "getNamedItem should have returned NULL\n");
2027 SysFreeString( str );
2029 /* test indexed access of attributes */
2030 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
2031 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
2033 r = IXMLDOMNamedNodeMap_get_length( map, &count );
2034 ok ( r == S_OK, "get_length wrong code\n");
2035 ok ( count == 1, "get_length != 1\n");
2037 node = NULL;
2038 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
2039 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
2040 ok ( node == NULL, "there is no node\n");
2042 node = NULL;
2043 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
2044 ok ( r == S_FALSE, "get_item (1) wrong code\n");
2045 ok ( node == NULL, "there is no attribute\n");
2047 node = NULL;
2048 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
2049 ok ( r == S_OK, "get_item (0) wrong code\n");
2050 ok ( node != NULL, "should be attribute\n");
2052 r = IXMLDOMNode_get_nodeName( node, NULL );
2053 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
2055 /* content doesn't matter here */
2056 str = NULL;
2057 r = IXMLDOMNode_get_nodeName( node, &str );
2058 ok ( r == S_OK, "get_nodeName wrong code\n");
2059 ok ( str != NULL, "str is null\n");
2060 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
2061 SysFreeString( str );
2063 /* test sequential access of attributes */
2064 node = NULL;
2065 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2066 ok ( r == S_OK, "nextNode (first time) wrong code\n");
2067 ok ( node != NULL, "nextNode, should be attribute\n");
2069 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2070 ok ( r != S_OK, "nextNode (second time) wrong code\n");
2071 ok ( node == NULL, "nextNode, there is no attribute\n");
2073 r = IXMLDOMNamedNodeMap_reset( map );
2074 ok ( r == S_OK, "reset should return S_OK\n");
2076 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
2077 ok ( r == S_OK, "nextNode (third time) wrong code\n");
2078 ok ( node != NULL, "nextNode, should be attribute\n");
2080 else
2081 ok( FALSE, "no map\n");
2083 if (node)
2085 type = NODE_INVALID;
2086 r = IXMLDOMNode_get_nodeType( node, &type);
2087 ok( r == S_OK, "getNamedItem returned wrong code\n");
2088 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
2090 str = NULL;
2091 r = IXMLDOMNode_get_baseName( node, NULL );
2092 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
2094 str = NULL;
2095 r = IXMLDOMNode_get_baseName( node, &str );
2096 ok( r == S_OK, "get_baseName returned wrong code\n");
2097 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
2098 SysFreeString( str );
2100 r = IXMLDOMNode_get_nodeValue( node, &var );
2101 ok( r == S_OK, "returns %08x\n", r );
2102 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
2103 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
2104 VariantClear(&var);
2106 r = IXMLDOMNode_get_childNodes( node, NULL );
2107 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
2109 r = IXMLDOMNode_get_childNodes( node, &list );
2110 ok( r == S_OK, "get_childNodes returned wrong code\n");
2112 if (list)
2114 r = IXMLDOMNodeList_nextNode( list, &next );
2115 ok( r == S_OK, "nextNode returned wrong code\n");
2117 else
2118 ok( FALSE, "no childlist\n");
2120 if (next)
2122 b = 1;
2123 r = IXMLDOMNode_hasChildNodes( next, &b );
2124 ok( r == S_FALSE, "hasChildNoes bad return\n");
2125 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
2127 type = NODE_INVALID;
2128 r = IXMLDOMNode_get_nodeType( next, &type);
2129 ok( r == S_OK, "getNamedItem returned wrong code\n");
2130 ok( type == NODE_TEXT, "node not text\n");
2132 str = (BSTR) 1;
2133 r = IXMLDOMNode_get_baseName( next, &str );
2134 ok( r == S_FALSE, "get_baseName returned wrong code\n");
2135 ok( str == NULL, "basename was wrong\n");
2136 SysFreeString(str);
2138 else
2139 ok( FALSE, "no next\n");
2141 if (next)
2142 IXMLDOMNode_Release( next );
2143 next = NULL;
2144 if (list)
2145 IXMLDOMNodeList_Release( list );
2146 list = NULL;
2147 if (node)
2148 IXMLDOMNode_Release( node );
2150 else
2151 ok( FALSE, "no node\n");
2152 node = NULL;
2154 if (map)
2155 IXMLDOMNamedNodeMap_Release( map );
2157 /* now traverse the tree from the root element */
2158 if (element)
2160 r = IXMLDOMNode_get_childNodes( element, &list );
2161 ok( r == S_OK, "get_childNodes returned wrong code\n");
2163 /* using get_item for child list doesn't advance the position */
2164 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2165 expect_node(node, "E2.E2.D1");
2166 IXMLDOMNode_Release(node);
2167 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2168 expect_node(node, "E1.E2.D1");
2169 IXMLDOMNode_Release(node);
2170 ole_check(IXMLDOMNodeList_reset(list));
2172 IXMLDOMNodeList_AddRef(list);
2173 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
2174 ole_check(IXMLDOMNodeList_reset(list));
2176 node = (void*)0xdeadbeef;
2177 str = SysAllocString(szdl);
2178 r = IXMLDOMNode_selectSingleNode( element, str, &node );
2179 SysFreeString(str);
2180 ok( r == S_FALSE, "ret %08x\n", r );
2181 ok( node == NULL, "node %p\n", node );
2183 str = SysAllocString(szbs);
2184 r = IXMLDOMNode_selectSingleNode( element, str, &node );
2185 SysFreeString(str);
2186 ok( r == S_OK, "ret %08x\n", r );
2187 r = IXMLDOMNode_Release( node );
2188 ok( r == 0, "ret %08x\n", r );
2190 else
2191 ok( FALSE, "no element\n");
2193 if (list)
2195 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
2196 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
2198 r = IXMLDOMNodeList_get_item(list, 0, NULL);
2199 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
2201 r = IXMLDOMNodeList_get_length(list, NULL);
2202 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
2204 r = IXMLDOMNodeList_get_length( list, &count );
2205 ok( r == S_OK, "get_length returns %08x\n", r );
2206 ok( count == 4, "get_length got %d\n", count );
2208 r = IXMLDOMNodeList_nextNode(list, NULL);
2209 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
2211 r = IXMLDOMNodeList_nextNode( list, &node );
2212 ok( r == S_OK, "nextNode returned wrong code\n");
2214 else
2215 ok( FALSE, "no list\n");
2217 if (node)
2219 type = NODE_INVALID;
2220 r = IXMLDOMNode_get_nodeType( node, &type);
2221 ok( r == S_OK, "getNamedItem returned wrong code\n");
2222 ok( type == NODE_ELEMENT, "node not text\n");
2224 VariantInit(&var);
2225 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
2226 r = IXMLDOMNode_get_nodeValue( node, &var );
2227 ok( r == S_FALSE, "nextNode returned wrong code\n");
2228 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
2229 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
2231 r = IXMLDOMNode_hasChildNodes( node, NULL );
2232 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
2234 b = 1;
2235 r = IXMLDOMNode_hasChildNodes( node, &b );
2236 ok( r == S_OK, "hasChildNoes bad return\n");
2237 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
2239 str = NULL;
2240 r = IXMLDOMNode_get_baseName( node, &str );
2241 ok( r == S_OK, "get_baseName returned wrong code\n");
2242 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
2243 SysFreeString(str);
2245 else
2246 ok( FALSE, "no node\n");
2248 if (node)
2249 IXMLDOMNode_Release( node );
2250 if (list)
2251 IXMLDOMNodeList_Release( list );
2252 if (element)
2253 IXMLDOMElement_Release( element );
2255 b = FALSE;
2256 str = SysAllocString( szComplete5 );
2257 r = IXMLDOMDocument_loadXML( doc, str, &b );
2258 ok( r == S_OK, "loadXML failed\n");
2259 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2260 SysFreeString( str );
2262 b = 1;
2263 r = IXMLDOMNode_hasChildNodes( doc, &b );
2264 ok( r == S_OK, "hasChildNoes bad return\n");
2265 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
2267 r = IXMLDOMDocument_get_documentElement( doc, &element );
2268 ok( r == S_OK, "should be a document element\n");
2269 ok( element != NULL, "should be an element\n");
2271 if (element)
2273 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
2274 BSTR tag = NULL;
2276 /* check if the tag is correct */
2277 r = IXMLDOMElement_get_tagName( element, &tag );
2278 ok( r == S_OK, "couldn't get tag name\n");
2279 ok( tag != NULL, "tag was null\n");
2280 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
2281 SysFreeString( tag );
2284 if (element)
2285 IXMLDOMElement_Release( element );
2286 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
2289 static void test_refs(void)
2291 HRESULT r;
2292 BSTR str;
2293 VARIANT_BOOL b;
2294 IXMLDOMDocument *doc;
2295 IXMLDOMElement *element = NULL;
2296 IXMLDOMNode *node = NULL, *node2;
2297 IXMLDOMNodeList *node_list = NULL;
2298 LONG ref;
2299 IUnknown *unk, *unk2;
2301 doc = create_document(&IID_IXMLDOMDocument);
2302 if (!doc) return;
2304 ref = IXMLDOMDocument_Release(doc);
2305 ok( ref == 0, "ref %d\n", ref);
2307 doc = create_document(&IID_IXMLDOMDocument);
2308 if (!doc) return;
2310 str = SysAllocString( szComplete4 );
2311 r = IXMLDOMDocument_loadXML( doc, str, &b );
2312 ok( r == S_OK, "loadXML failed\n");
2313 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2314 SysFreeString( str );
2316 ref = IXMLDOMDocument_AddRef( doc );
2317 ok( ref == 2, "ref %d\n", ref );
2318 ref = IXMLDOMDocument_AddRef( doc );
2319 ok( ref == 3, "ref %d\n", ref );
2320 IXMLDOMDocument_Release( doc );
2321 IXMLDOMDocument_Release( doc );
2323 r = IXMLDOMDocument_get_documentElement( doc, &element );
2324 ok( r == S_OK, "should be a document element\n");
2325 ok( element != NULL, "should be an element\n");
2327 ref = IXMLDOMDocument_AddRef( doc );
2328 ok( ref == 2, "ref %d\n", ref );
2329 IXMLDOMDocument_Release( doc );
2331 r = IXMLDOMElement_get_childNodes( element, &node_list );
2332 ok( r == S_OK, "rets %08x\n", r);
2334 ref = IXMLDOMNodeList_AddRef( node_list );
2335 ok( ref == 2, "ref %d\n", ref );
2336 IXMLDOMNodeList_Release( node_list );
2338 IXMLDOMNodeList_get_item( node_list, 0, &node );
2339 ok( r == S_OK, "rets %08x\n", r);
2341 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
2342 ok( r == S_OK, "rets %08x\n", r);
2344 ref = IXMLDOMNode_AddRef( node );
2345 ok( ref == 2, "ref %d\n", ref );
2346 IXMLDOMNode_Release( node );
2348 ref = IXMLDOMNode_Release( node );
2349 ok( ref == 0, "ref %d\n", ref );
2350 ref = IXMLDOMNode_Release( node2 );
2351 ok( ref == 0, "ref %d\n", ref );
2353 ref = IXMLDOMNodeList_Release( node_list );
2354 ok( ref == 0, "ref %d\n", ref );
2356 ok( node != node2, "node %p node2 %p\n", node, node2 );
2358 ref = IXMLDOMDocument_Release( doc );
2359 ok( ref == 0, "ref %d\n", ref );
2361 ref = IXMLDOMElement_AddRef( element );
2362 todo_wine {
2363 ok( ref == 3, "ref %d\n", ref );
2365 IXMLDOMElement_Release( element );
2367 /* IUnknown must be unique however we obtain it */
2368 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (void**)&unk );
2369 ok( r == S_OK, "rets %08x\n", r );
2370 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (void**)&node );
2371 ok( r == S_OK, "rets %08x\n", r );
2372 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk2 );
2373 ok( r == S_OK, "rets %08x\n", r );
2374 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
2376 IUnknown_Release( unk2 );
2377 IUnknown_Release( unk );
2378 IXMLDOMNode_Release( node );
2380 IXMLDOMElement_Release( element );
2384 static void test_create(void)
2386 static const WCHAR szOne[] = {'1',0};
2387 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
2388 HRESULT r;
2389 VARIANT var;
2390 BSTR str, name;
2391 IXMLDOMDocument *doc;
2392 IXMLDOMElement *element;
2393 IXMLDOMComment *comment;
2394 IXMLDOMText *text;
2395 IXMLDOMCDATASection *cdata;
2396 IXMLDOMNode *root, *node, *child;
2397 IXMLDOMNamedNodeMap *attr_map;
2398 IUnknown *unk;
2399 LONG ref;
2400 LONG num;
2402 doc = create_document(&IID_IXMLDOMDocument);
2403 if (!doc) return;
2405 /* types not supported for creation */
2406 V_VT(&var) = VT_I1;
2407 V_I1(&var) = NODE_DOCUMENT;
2408 node = (IXMLDOMNode*)0x1;
2409 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2410 ok( r == E_INVALIDARG, "returns %08x\n", r );
2411 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2413 V_VT(&var) = VT_I1;
2414 V_I1(&var) = NODE_DOCUMENT_TYPE;
2415 node = (IXMLDOMNode*)0x1;
2416 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2417 ok( r == E_INVALIDARG, "returns %08x\n", r );
2418 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2420 V_VT(&var) = VT_I1;
2421 V_I1(&var) = NODE_ENTITY;
2422 node = (IXMLDOMNode*)0x1;
2423 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2424 ok( r == E_INVALIDARG, "returns %08x\n", r );
2425 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2427 V_VT(&var) = VT_I1;
2428 V_I1(&var) = NODE_NOTATION;
2429 node = (IXMLDOMNode*)0x1;
2430 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2431 ok( r == E_INVALIDARG, "returns %08x\n", r );
2432 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2434 /* NODE_COMMENT */
2435 V_VT(&var) = VT_I1;
2436 V_I1(&var) = NODE_COMMENT;
2437 node = NULL;
2438 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2439 ok( r == S_OK, "returns %08x\n", r );
2440 ok( node != NULL, "\n");
2442 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2443 ok( r == S_OK, "returns %08x\n", r );
2444 IXMLDOMNode_Release(node);
2446 str = NULL;
2447 r = IXMLDOMComment_get_data(comment, &str);
2448 ok( r == S_OK, "returns %08x\n", r );
2449 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2450 IXMLDOMComment_Release(comment);
2451 SysFreeString(str);
2453 node = (IXMLDOMNode*)0x1;
2454 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2455 ok( r == S_OK, "returns %08x\n", r );
2457 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2458 ok( r == S_OK, "returns %08x\n", r );
2459 IXMLDOMNode_Release(node);
2461 str = NULL;
2462 r = IXMLDOMComment_get_data(comment, &str);
2463 ok( r == S_OK, "returns %08x\n", r );
2464 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2465 IXMLDOMComment_Release(comment);
2466 SysFreeString(str);
2468 node = (IXMLDOMNode*)0x1;
2469 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2470 ok( r == S_OK, "returns %08x\n", r );
2472 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
2473 ok( r == S_OK, "returns %08x\n", r );
2474 IXMLDOMNode_Release(node);
2476 str = NULL;
2477 r = IXMLDOMComment_get_data(comment, &str);
2478 ok( r == S_OK, "returns %08x\n", r );
2479 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2480 IXMLDOMComment_Release(comment);
2481 SysFreeString(str);
2483 /* NODE_TEXT */
2484 V_VT(&var) = VT_I1;
2485 V_I1(&var) = NODE_TEXT;
2486 node = NULL;
2487 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2488 ok( r == S_OK, "returns %08x\n", r );
2489 ok( node != NULL, "\n");
2491 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2492 ok( r == S_OK, "returns %08x\n", r );
2493 IXMLDOMNode_Release(node);
2495 str = NULL;
2496 r = IXMLDOMText_get_data(text, &str);
2497 ok( r == S_OK, "returns %08x\n", r );
2498 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2499 IXMLDOMText_Release(text);
2500 SysFreeString(str);
2502 node = (IXMLDOMNode*)0x1;
2503 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2504 ok( r == S_OK, "returns %08x\n", r );
2506 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2507 ok( r == S_OK, "returns %08x\n", r );
2508 IXMLDOMNode_Release(node);
2510 str = NULL;
2511 r = IXMLDOMText_get_data(text, &str);
2512 ok( r == S_OK, "returns %08x\n", r );
2513 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2514 IXMLDOMText_Release(text);
2515 SysFreeString(str);
2517 node = (IXMLDOMNode*)0x1;
2518 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2519 ok( r == S_OK, "returns %08x\n", r );
2521 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
2522 ok( r == S_OK, "returns %08x\n", r );
2523 IXMLDOMNode_Release(node);
2525 str = NULL;
2526 r = IXMLDOMText_get_data(text, &str);
2527 ok( r == S_OK, "returns %08x\n", r );
2528 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2529 IXMLDOMText_Release(text);
2530 SysFreeString(str);
2532 /* NODE_CDATA_SECTION */
2533 V_VT(&var) = VT_I1;
2534 V_I1(&var) = NODE_CDATA_SECTION;
2535 node = NULL;
2536 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2537 ok( r == S_OK, "returns %08x\n", r );
2538 ok( node != NULL, "\n");
2540 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2541 ok( r == S_OK, "returns %08x\n", r );
2542 IXMLDOMNode_Release(node);
2544 str = NULL;
2545 r = IXMLDOMCDATASection_get_data(cdata, &str);
2546 ok( r == S_OK, "returns %08x\n", r );
2547 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2548 IXMLDOMCDATASection_Release(cdata);
2549 SysFreeString(str);
2551 node = (IXMLDOMNode*)0x1;
2552 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2553 ok( r == S_OK, "returns %08x\n", r );
2555 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2556 ok( r == S_OK, "returns %08x\n", r );
2557 IXMLDOMNode_Release(node);
2559 str = NULL;
2560 r = IXMLDOMCDATASection_get_data(cdata, &str);
2561 ok( r == S_OK, "returns %08x\n", r );
2562 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2563 IXMLDOMCDATASection_Release(cdata);
2564 SysFreeString(str);
2566 node = (IXMLDOMNode*)0x1;
2567 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
2568 ok( r == S_OK, "returns %08x\n", r );
2570 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2571 ok( r == S_OK, "returns %08x\n", r );
2572 IXMLDOMNode_Release(node);
2574 str = NULL;
2575 r = IXMLDOMCDATASection_get_data(cdata, &str);
2576 ok( r == S_OK, "returns %08x\n", r );
2577 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2578 IXMLDOMCDATASection_Release(cdata);
2579 SysFreeString(str);
2581 /* NODE_ATTRIBUTE */
2582 V_VT(&var) = VT_I1;
2583 V_I1(&var) = NODE_ATTRIBUTE;
2584 node = (IXMLDOMNode*)0x1;
2585 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2586 ok( r == E_FAIL, "returns %08x\n", r );
2587 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2589 V_VT(&var) = VT_I1;
2590 V_I1(&var) = NODE_ATTRIBUTE;
2591 node = (IXMLDOMNode*)0x1;
2592 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2593 ok( r == E_FAIL, "returns %08x\n", r );
2594 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2596 V_VT(&var) = VT_I1;
2597 V_I1(&var) = NODE_ATTRIBUTE;
2598 str = SysAllocString( szlc );
2599 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2600 ok( r == S_OK, "returns %08x\n", r );
2601 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2602 SysFreeString(str);
2604 /* a name is required for attribute, try a BSTR with first null wchar */
2605 V_VT(&var) = VT_I1;
2606 V_I1(&var) = NODE_ATTRIBUTE;
2607 str = SysAllocString( szstr1 );
2608 str[0] = 0;
2609 node = (IXMLDOMNode*)0x1;
2610 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2611 ok( r == E_FAIL, "returns %08x\n", r );
2612 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2613 SysFreeString(str);
2615 /* NODE_PROCESSING_INSTRUCTION */
2616 V_VT(&var) = VT_I1;
2617 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2618 node = (IXMLDOMNode*)0x1;
2619 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2620 ok( r == E_FAIL, "returns %08x\n", r );
2621 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2623 V_VT(&var) = VT_I1;
2624 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2625 node = (IXMLDOMNode*)0x1;
2626 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2627 ok( r == E_FAIL, "returns %08x\n", r );
2628 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2630 V_VT(&var) = VT_I1;
2631 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2632 r = IXMLDOMDocument_createNode( doc, var, _bstr_("pi"), NULL, NULL );
2633 ok( r == E_INVALIDARG, "returns %08x\n", r );
2635 /* NODE_ENTITY_REFERENCE */
2636 V_VT(&var) = VT_I1;
2637 V_I1(&var) = NODE_ENTITY_REFERENCE;
2638 node = (IXMLDOMNode*)0x1;
2639 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2640 ok( r == E_FAIL, "returns %08x\n", r );
2641 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2643 V_VT(&var) = VT_I1;
2644 V_I1(&var) = NODE_ENTITY_REFERENCE;
2645 node = (IXMLDOMNode*)0x1;
2646 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2647 ok( r == E_FAIL, "returns %08x\n", r );
2648 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2650 /* NODE_ELEMENT */
2651 V_VT(&var) = VT_I1;
2652 V_I1(&var) = NODE_ELEMENT;
2653 node = (IXMLDOMNode*)0x1;
2654 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2655 ok( r == E_FAIL, "returns %08x\n", r );
2656 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2658 V_VT(&var) = VT_I1;
2659 V_I1(&var) = NODE_ELEMENT;
2660 node = (IXMLDOMNode*)0x1;
2661 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2662 ok( r == E_FAIL, "returns %08x\n", r );
2663 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2665 V_VT(&var) = VT_I1;
2666 V_I1(&var) = NODE_ELEMENT;
2667 str = SysAllocString( szlc );
2668 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2669 ok( r == S_OK, "returns %08x\n", r );
2670 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2672 V_VT(&var) = VT_I1;
2673 V_I1(&var) = NODE_ELEMENT;
2674 r = IXMLDOMDocument_createNode( doc, var, str, NULL, NULL );
2675 ok( r == E_INVALIDARG, "returns %08x\n", r );
2677 V_VT(&var) = VT_R4;
2678 V_R4(&var) = NODE_ELEMENT;
2679 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2680 ok( r == S_OK, "returns %08x\n", r );
2681 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2683 V_VT(&var) = VT_BSTR;
2684 V_BSTR(&var) = SysAllocString( szOne );
2685 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2686 ok( r == S_OK, "returns %08x\n", r );
2687 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2688 VariantClear(&var);
2690 V_VT(&var) = VT_BSTR;
2691 V_BSTR(&var) = SysAllocString( szOneGarbage );
2692 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2693 ok( r == E_INVALIDARG, "returns %08x\n", r );
2694 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2695 VariantClear(&var);
2697 V_VT(&var) = VT_I4;
2698 V_I4(&var) = NODE_ELEMENT;
2699 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2700 ok( r == S_OK, "returns %08x\n", r );
2701 r = IXMLDOMDocument_appendChild( doc, node, &root );
2702 ok( r == S_OK, "returns %08x\n", r );
2703 ok( node == root, "%p %p\n", node, root );
2705 ref = IXMLDOMNode_AddRef( node );
2706 ok(ref == 3, "ref %d\n", ref);
2707 IXMLDOMNode_Release( node );
2709 ref = IXMLDOMNode_Release( node );
2710 ok(ref == 1, "ref %d\n", ref);
2711 SysFreeString( str );
2713 V_VT(&var) = VT_I4;
2714 V_I4(&var) = NODE_ELEMENT;
2715 str = SysAllocString( szbs );
2716 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2717 ok( r == S_OK, "returns %08x\n", r );
2718 SysFreeString( str );
2720 ref = IXMLDOMNode_AddRef( node );
2721 ok(ref == 2, "ref = %d\n", ref);
2722 IXMLDOMNode_Release( node );
2724 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk );
2725 ok( r == S_OK, "returns %08x\n", r );
2727 ref = IXMLDOMNode_AddRef( unk );
2728 ok(ref == 3, "ref = %d\n", ref);
2729 IXMLDOMNode_Release( unk );
2731 V_VT(&var) = VT_EMPTY;
2732 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
2733 ok( r == S_OK, "returns %08x\n", r );
2734 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
2735 IXMLDOMNode_Release( child );
2736 IUnknown_Release( unk );
2739 V_VT(&var) = VT_NULL;
2740 V_DISPATCH(&var) = (IDispatch*)node;
2741 r = IXMLDOMNode_insertBefore( root, node, var, &child );
2742 ok( r == S_OK, "returns %08x\n", r );
2743 ok( node == child, "%p %p\n", node, child );
2744 IXMLDOMNode_Release( child );
2747 V_VT(&var) = VT_NULL;
2748 V_DISPATCH(&var) = (IDispatch*)node;
2749 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
2750 ok( r == S_OK, "returns %08x\n", r );
2751 IXMLDOMNode_Release( node );
2753 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (void**)&element );
2754 ok( r == S_OK, "returns %08x\n", r );
2756 r = IXMLDOMElement_get_attributes( element, &attr_map );
2757 ok( r == S_OK, "returns %08x\n", r );
2758 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2759 ok( r == S_OK, "returns %08x\n", r );
2760 ok( num == 0, "num %d\n", num );
2761 IXMLDOMNamedNodeMap_Release( attr_map );
2763 V_VT(&var) = VT_BSTR;
2764 V_BSTR(&var) = SysAllocString( szstr1 );
2765 name = SysAllocString( szdl );
2766 r = IXMLDOMElement_setAttribute( element, name, var );
2767 ok( r == S_OK, "returns %08x\n", r );
2768 r = IXMLDOMElement_get_attributes( element, &attr_map );
2769 ok( r == S_OK, "returns %08x\n", r );
2770 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2771 ok( r == S_OK, "returns %08x\n", r );
2772 ok( num == 1, "num %d\n", num );
2773 IXMLDOMNamedNodeMap_Release( attr_map );
2774 VariantClear(&var);
2776 V_VT(&var) = VT_BSTR;
2777 V_BSTR(&var) = SysAllocString( szstr2 );
2778 r = IXMLDOMElement_setAttribute( element, name, var );
2779 ok( r == S_OK, "returns %08x\n", r );
2780 r = IXMLDOMElement_get_attributes( element, &attr_map );
2781 ok( r == S_OK, "returns %08x\n", r );
2782 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2783 ok( r == S_OK, "returns %08x\n", r );
2784 ok( num == 1, "num %d\n", num );
2785 IXMLDOMNamedNodeMap_Release( attr_map );
2786 VariantClear(&var);
2787 r = IXMLDOMElement_getAttribute( element, name, &var );
2788 ok( r == S_OK, "returns %08x\n", r );
2789 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
2790 VariantClear(&var);
2791 SysFreeString(name);
2793 V_VT(&var) = VT_BSTR;
2794 V_BSTR(&var) = SysAllocString( szstr1 );
2795 name = SysAllocString( szlc );
2796 r = IXMLDOMElement_setAttribute( element, name, var );
2797 ok( r == S_OK, "returns %08x\n", r );
2798 r = IXMLDOMElement_get_attributes( element, &attr_map );
2799 ok( r == S_OK, "returns %08x\n", r );
2800 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2801 ok( r == S_OK, "returns %08x\n", r );
2802 ok( num == 2, "num %d\n", num );
2803 IXMLDOMNamedNodeMap_Release( attr_map );
2804 VariantClear(&var);
2805 SysFreeString(name);
2807 V_VT(&var) = VT_I4;
2808 V_I4(&var) = 10;
2809 name = SysAllocString( szbs );
2810 r = IXMLDOMElement_setAttribute( element, name, var );
2811 ok( r == S_OK, "returns %08x\n", r );
2812 VariantClear(&var);
2813 r = IXMLDOMElement_getAttribute( element, name, &var );
2814 ok( r == S_OK, "returns %08x\n", r );
2815 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
2816 VariantClear(&var);
2817 SysFreeString(name);
2819 /* Create an Attribute */
2820 V_VT(&var) = VT_I4;
2821 V_I4(&var) = NODE_ATTRIBUTE;
2822 str = SysAllocString( szAttribute );
2823 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2824 ok( r == S_OK, "returns %08x\n", r );
2825 ok( node != NULL, "node was null\n");
2826 SysFreeString(str);
2828 r = IXMLDOMNode_get_nodeTypeString(node, &str);
2829 ok( r == S_OK, "returns %08x\n", r );
2830 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2831 SysFreeString(str);
2832 IXMLDOMNode_Release( node );
2834 IXMLDOMElement_Release( element );
2835 IXMLDOMNode_Release( root );
2836 IXMLDOMDocument_Release( doc );
2839 static void test_getElementsByTagName(void)
2841 IXMLDOMNodeList *node_list;
2842 IXMLDOMDocument *doc;
2843 IXMLDOMElement *elem;
2844 WCHAR buff[100];
2845 VARIANT_BOOL b;
2846 HRESULT r;
2847 LONG len;
2848 BSTR str;
2850 doc = create_document(&IID_IXMLDOMDocument);
2851 if (!doc) return;
2853 str = SysAllocString( szComplete4 );
2854 r = IXMLDOMDocument_loadXML( doc, str, &b );
2855 ok( r == S_OK, "loadXML failed\n");
2856 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2857 SysFreeString( str );
2859 str = SysAllocString( szstar );
2861 /* null arguments cases */
2862 r = IXMLDOMDocument_getElementsByTagName(doc, NULL, &node_list);
2863 ok( r == E_INVALIDARG, "ret %08x\n", r );
2864 r = IXMLDOMDocument_getElementsByTagName(doc, str, NULL);
2865 ok( r == E_INVALIDARG, "ret %08x\n", r );
2867 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2868 ok( r == S_OK, "ret %08x\n", r );
2869 r = IXMLDOMNodeList_get_length( node_list, &len );
2870 ok( r == S_OK, "ret %08x\n", r );
2871 ok( len == 6, "len %d\n", len );
2873 test_disp((IUnknown*)node_list);
2875 IXMLDOMNodeList_Release( node_list );
2876 SysFreeString( str );
2878 /* broken query BSTR */
2879 memcpy(&buff[2], szstar, sizeof(szstar));
2880 /* just a big length */
2881 *(DWORD*)buff = 0xf0f0;
2882 r = IXMLDOMDocument_getElementsByTagName(doc, &buff[2], &node_list);
2883 ok( r == S_OK, "ret %08x\n", r );
2884 r = IXMLDOMNodeList_get_length( node_list, &len );
2885 ok( r == S_OK, "ret %08x\n", r );
2886 ok( len == 6, "len %d\n", len );
2887 IXMLDOMNodeList_Release( node_list );
2889 str = SysAllocString( szbs );
2890 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2891 ok( r == S_OK, "ret %08x\n", r );
2892 r = IXMLDOMNodeList_get_length( node_list, &len );
2893 ok( r == S_OK, "ret %08x\n", r );
2894 ok( len == 1, "len %d\n", len );
2895 IXMLDOMNodeList_Release( node_list );
2896 SysFreeString( str );
2898 str = SysAllocString( szdl );
2899 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2900 ok( r == S_OK, "ret %08x\n", r );
2901 r = IXMLDOMNodeList_get_length( node_list, &len );
2902 ok( r == S_OK, "ret %08x\n", r );
2903 ok( len == 0, "len %d\n", len );
2904 IXMLDOMNodeList_Release( node_list );
2905 SysFreeString( str );
2907 str = SysAllocString( szstr1 );
2908 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2909 ok( r == S_OK, "ret %08x\n", r );
2910 r = IXMLDOMNodeList_get_length( node_list, &len );
2911 ok( r == S_OK, "ret %08x\n", r );
2912 ok( len == 0, "len %d\n", len );
2913 IXMLDOMNodeList_Release( node_list );
2914 SysFreeString( str );
2916 /* test for element */
2917 r = IXMLDOMDocument_get_documentElement(doc, &elem);
2918 ok( r == S_OK, "ret %08x\n", r );
2920 str = SysAllocString( szstar );
2922 /* null arguments cases */
2923 r = IXMLDOMElement_getElementsByTagName(elem, NULL, &node_list);
2924 ok( r == E_INVALIDARG, "ret %08x\n", r );
2925 r = IXMLDOMElement_getElementsByTagName(elem, str, NULL);
2926 ok( r == E_INVALIDARG, "ret %08x\n", r );
2928 r = IXMLDOMElement_getElementsByTagName(elem, str, &node_list);
2929 ok( r == S_OK, "ret %08x\n", r );
2930 r = IXMLDOMNodeList_get_length( node_list, &len );
2931 ok( r == S_OK, "ret %08x\n", r );
2932 todo_wine ok( len == 5, "len %d\n", len );
2934 IXMLDOMNodeList_Release( node_list );
2935 SysFreeString( str );
2937 /* broken query BSTR */
2938 memcpy(&buff[2], szstar, sizeof(szstar));
2939 /* just a big length */
2940 *(DWORD*)buff = 0xf0f0;
2941 r = IXMLDOMElement_getElementsByTagName(elem, &buff[2], &node_list);
2942 ok( r == S_OK, "ret %08x\n", r );
2943 r = IXMLDOMNodeList_get_length( node_list, &len );
2944 ok( r == S_OK, "ret %08x\n", r );
2945 todo_wine ok( len == 5, "len %d\n", len );
2946 IXMLDOMNodeList_Release( node_list );
2948 IXMLDOMElement_Release(elem);
2950 IXMLDOMDocument_Release( doc );
2953 static void test_get_text(void)
2955 HRESULT r;
2956 BSTR str;
2957 VARIANT_BOOL b;
2958 IXMLDOMDocument *doc;
2959 IXMLDOMNode *node, *node2, *node3;
2960 IXMLDOMNode *nodeRoot;
2961 IXMLDOMNodeList *node_list;
2962 IXMLDOMNamedNodeMap *node_map;
2963 LONG len;
2965 doc = create_document(&IID_IXMLDOMDocument);
2966 if (!doc) return;
2968 str = SysAllocString( szComplete4 );
2969 r = IXMLDOMDocument_loadXML( doc, str, &b );
2970 ok( r == S_OK, "loadXML failed\n");
2971 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2972 SysFreeString( str );
2974 str = SysAllocString( szbs );
2975 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
2976 ok( r == S_OK, "ret %08x\n", r );
2977 SysFreeString(str);
2979 /* Test to get all child node text. */
2980 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&nodeRoot);
2981 ok( r == S_OK, "ret %08x\n", r );
2982 if(r == S_OK)
2984 r = IXMLDOMNode_get_text( nodeRoot, &str );
2985 ok( r == S_OK, "ret %08x\n", r );
2986 ok( compareIgnoreReturns(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text: %s\n", wine_dbgstr_w(str));
2987 SysFreeString(str);
2989 IXMLDOMNode_Release(nodeRoot);
2992 if (0) {
2993 /* this test crashes on win9x */
2994 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
2995 ok( r == E_INVALIDARG, "ret %08x\n", r );
2998 r = IXMLDOMNodeList_get_length( node_list, NULL );
2999 ok( r == E_INVALIDARG, "ret %08x\n", r );
3001 r = IXMLDOMNodeList_get_length( node_list, &len );
3002 ok( r == S_OK, "ret %08x\n", r );
3003 ok( len == 1, "expect 1 got %d\n", len );
3005 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
3006 ok( r == E_INVALIDARG, "ret %08x\n", r );
3008 r = IXMLDOMNodeList_nextNode( node_list, NULL );
3009 ok( r == E_INVALIDARG, "ret %08x\n", r );
3011 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
3012 ok( r == S_OK, "ret %08x\n", r );
3013 IXMLDOMNodeList_Release( node_list );
3015 /* Invalid output parameter*/
3016 r = IXMLDOMNode_get_text( node, NULL );
3017 ok( r == E_INVALIDARG, "ret %08x\n", r );
3019 r = IXMLDOMNode_get_text( node, &str );
3020 ok( r == S_OK, "ret %08x\n", r );
3021 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
3022 SysFreeString(str);
3024 r = IXMLDOMNode_get_attributes( node, &node_map );
3025 ok( r == S_OK, "ret %08x\n", r );
3027 str = SysAllocString( szvr );
3028 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
3029 ok( r == S_OK, "ret %08x\n", r );
3030 SysFreeString(str);
3032 r = IXMLDOMNode_get_text( node2, &str );
3033 ok( r == S_OK, "ret %08x\n", r );
3034 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3035 SysFreeString(str);
3037 r = IXMLDOMNode_get_firstChild( node2, &node3 );
3038 ok( r == S_OK, "ret %08x\n", r );
3040 r = IXMLDOMNode_get_text( node3, &str );
3041 ok( r == S_OK, "ret %08x\n", r );
3042 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
3043 SysFreeString(str);
3046 IXMLDOMNode_Release( node3 );
3047 IXMLDOMNode_Release( node2 );
3048 IXMLDOMNamedNodeMap_Release( node_map );
3049 IXMLDOMNode_Release( node );
3050 IXMLDOMDocument_Release( doc );
3053 static void test_get_childNodes(void)
3055 HRESULT r;
3056 BSTR str;
3057 VARIANT_BOOL b;
3058 IXMLDOMDocument *doc;
3059 IXMLDOMElement *element;
3060 IXMLDOMNode *node, *node2;
3061 IXMLDOMNodeList *node_list, *node_list2;
3062 LONG len;
3064 doc = create_document(&IID_IXMLDOMDocument);
3065 if (!doc) return;
3067 str = SysAllocString( szComplete4 );
3068 r = IXMLDOMDocument_loadXML( doc, str, &b );
3069 ok( r == S_OK, "loadXML failed\n");
3070 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3071 SysFreeString( str );
3073 r = IXMLDOMDocument_get_documentElement( doc, &element );
3074 ok( r == S_OK, "ret %08x\n", r);
3076 r = IXMLDOMElement_get_childNodes( element, &node_list );
3077 ok( r == S_OK, "ret %08x\n", r);
3079 r = IXMLDOMNodeList_get_length( node_list, &len );
3080 ok( r == S_OK, "ret %08x\n", r);
3081 ok( len == 4, "len %d\n", len);
3083 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
3084 ok( r == S_OK, "ret %08x\n", r);
3086 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
3087 ok( r == S_OK, "ret %08x\n", r);
3089 r = IXMLDOMNodeList_get_length( node_list2, &len );
3090 ok( r == S_OK, "ret %08x\n", r);
3091 ok( len == 0, "len %d\n", len);
3093 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
3094 ok( r == S_FALSE, "ret %08x\n", r);
3096 IXMLDOMNodeList_Release( node_list2 );
3097 IXMLDOMNode_Release( node );
3098 IXMLDOMNodeList_Release( node_list );
3099 IXMLDOMElement_Release( element );
3100 IXMLDOMDocument_Release( doc );
3103 static void test_get_firstChild(void)
3105 static WCHAR xmlW[] = {'x','m','l',0};
3106 IXMLDOMDocument *doc;
3107 IXMLDOMNode *node;
3108 VARIANT_BOOL b;
3109 HRESULT r;
3110 BSTR str;
3112 doc = create_document(&IID_IXMLDOMDocument);
3113 if (!doc) return;
3115 str = SysAllocString( szComplete4 );
3116 r = IXMLDOMDocument_loadXML( doc, str, &b );
3117 ok( r == S_OK, "loadXML failed\n");
3118 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3119 SysFreeString( str );
3121 r = IXMLDOMDocument_get_firstChild( doc, &node );
3122 ok( r == S_OK, "ret %08x\n", r);
3124 r = IXMLDOMNode_get_nodeName( node, &str );
3125 ok( r == S_OK, "ret %08x\n", r);
3127 ok(memcmp(str, xmlW, sizeof(xmlW)) == 0, "expected \"xml\" node name\n");
3129 SysFreeString(str);
3130 IXMLDOMNode_Release( node );
3131 IXMLDOMDocument_Release( doc );
3134 static void test_get_lastChild(void)
3136 static WCHAR lcW[] = {'l','c',0};
3137 static WCHAR foW[] = {'f','o',0};
3138 IXMLDOMDocument *doc;
3139 IXMLDOMNode *node, *child;
3140 VARIANT_BOOL b;
3141 HRESULT r;
3142 BSTR str;
3144 doc = create_document(&IID_IXMLDOMDocument);
3145 if (!doc) return;
3147 str = SysAllocString( szComplete4 );
3148 r = IXMLDOMDocument_loadXML( doc, str, &b );
3149 ok( r == S_OK, "loadXML failed\n");
3150 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3151 SysFreeString( str );
3153 r = IXMLDOMDocument_get_lastChild( doc, &node );
3154 ok( r == S_OK, "ret %08x\n", r);
3156 r = IXMLDOMNode_get_nodeName( node, &str );
3157 ok( r == S_OK, "ret %08x\n", r);
3159 ok(memcmp(str, lcW, sizeof(lcW)) == 0, "expected \"lc\" node name\n");
3160 SysFreeString(str);
3162 r = IXMLDOMNode_get_lastChild( node, &child );
3163 ok( r == S_OK, "ret %08x\n", r);
3165 r = IXMLDOMNode_get_nodeName( child, &str );
3166 ok( r == S_OK, "ret %08x\n", r);
3168 ok(memcmp(str, foW, sizeof(foW)) == 0, "expected \"fo\" node name\n");
3169 SysFreeString(str);
3171 IXMLDOMNode_Release( child );
3172 IXMLDOMNode_Release( node );
3173 IXMLDOMDocument_Release( doc );
3176 static void test_removeChild(void)
3178 HRESULT r;
3179 BSTR str;
3180 VARIANT_BOOL b;
3181 IXMLDOMDocument *doc;
3182 IXMLDOMElement *element, *lc_element;
3183 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
3184 IXMLDOMNodeList *root_list, *fo_list;
3186 doc = create_document(&IID_IXMLDOMDocument);
3187 if (!doc) return;
3189 str = SysAllocString( szComplete4 );
3190 r = IXMLDOMDocument_loadXML( doc, str, &b );
3191 ok( r == S_OK, "loadXML failed\n");
3192 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3193 SysFreeString( str );
3195 r = IXMLDOMDocument_get_documentElement( doc, &element );
3196 ok( r == S_OK, "ret %08x\n", r);
3198 r = IXMLDOMElement_get_childNodes( element, &root_list );
3199 ok( r == S_OK, "ret %08x\n", r);
3201 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
3202 ok( r == S_OK, "ret %08x\n", r);
3204 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3205 ok( r == S_OK, "ret %08x\n", r);
3207 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
3208 ok( r == S_OK, "ret %08x\n", r);
3210 /* invalid parameter: NULL ptr */
3211 removed_node = (void*)0xdeadbeef;
3212 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
3213 ok( r == E_INVALIDARG, "ret %08x\n", r );
3214 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3216 /* ba_node is a descendant of element, but not a direct child. */
3217 removed_node = (void*)0xdeadbeef;
3218 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
3219 ok( r == E_INVALIDARG, "ret %08x\n", r );
3220 ok( removed_node == NULL, "%p\n", removed_node );
3222 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
3223 ok( r == S_OK, "ret %08x\n", r);
3224 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
3226 /* try removing already removed child */
3227 temp_node = (void*)0xdeadbeef;
3228 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
3229 ok( r == E_INVALIDARG, "ret %08x\n", r);
3230 ok( temp_node == NULL, "%p\n", temp_node );
3232 /* the removed node has no parent anymore */
3233 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
3234 ok( r == S_FALSE, "ret %08x\n", r);
3235 ok( temp_node == NULL, "%p\n", temp_node );
3237 IXMLDOMNode_Release( removed_node );
3238 IXMLDOMNode_Release( ba_node );
3239 IXMLDOMNodeList_Release( fo_list );
3241 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
3242 ok( r == S_OK, "ret %08x\n", r);
3244 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (void**)&lc_element );
3245 ok( r == S_OK, "ret %08x\n", r);
3247 /* MS quirk: passing wrong interface pointer works, too */
3248 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
3249 ok( r == S_OK, "ret %08x\n", r);
3251 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
3252 ok( r == S_FALSE, "ret %08x\n", r);
3253 ok( temp_node == NULL, "%p\n", temp_node );
3255 IXMLDOMNode_Release( lc_node );
3256 IXMLDOMNodeList_Release( root_list );
3257 IXMLDOMElement_Release( element );
3258 IXMLDOMDocument_Release( doc );
3261 static void test_replaceChild(void)
3263 HRESULT r;
3264 BSTR str;
3265 VARIANT_BOOL b;
3266 IXMLDOMDocument *doc;
3267 IXMLDOMElement *element, *ba_element;
3268 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
3269 IXMLDOMNodeList *root_list, *fo_list;
3270 IUnknown * unk1, *unk2;
3271 LONG len;
3273 doc = create_document(&IID_IXMLDOMDocument);
3274 if (!doc) return;
3276 str = SysAllocString( szComplete4 );
3277 r = IXMLDOMDocument_loadXML( doc, str, &b );
3278 ok( r == S_OK, "loadXML failed\n");
3279 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3280 SysFreeString( str );
3282 r = IXMLDOMDocument_get_documentElement( doc, &element );
3283 ok( r == S_OK, "ret %08x\n", r);
3285 r = IXMLDOMElement_get_childNodes( element, &root_list );
3286 ok( r == S_OK, "ret %08x\n", r);
3288 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
3289 ok( r == S_OK, "ret %08x\n", r);
3291 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
3292 ok( r == S_OK, "ret %08x\n", r);
3294 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3295 ok( r == S_OK, "ret %08x\n", r);
3297 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
3298 ok( r == S_OK, "ret %08x\n", r);
3300 IXMLDOMNodeList_Release( fo_list );
3302 /* invalid parameter: NULL ptr for element to remove */
3303 removed_node = (void*)0xdeadbeef;
3304 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
3305 ok( r == E_INVALIDARG, "ret %08x\n", r );
3306 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3308 /* invalid parameter: NULL for replacement element. (Sic!) */
3309 removed_node = (void*)0xdeadbeef;
3310 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
3311 ok( r == E_INVALIDARG, "ret %08x\n", r );
3312 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
3314 /* invalid parameter: OldNode is not a child */
3315 removed_node = (void*)0xdeadbeef;
3316 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
3317 ok( r == E_INVALIDARG, "ret %08x\n", r );
3318 ok( removed_node == NULL, "%p\n", removed_node );
3320 /* invalid parameter: would create loop */
3321 removed_node = (void*)0xdeadbeef;
3322 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
3323 ok( r == E_FAIL, "ret %08x\n", r );
3324 ok( removed_node == NULL, "%p\n", removed_node );
3326 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
3327 ok( r == S_OK, "ret %08x\n", r );
3329 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
3330 ok( r == S_OK, "ret %08x\n", r );
3332 /* ba_node and temp_node refer to the same node, yet they
3333 are different interface pointers */
3334 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
3335 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
3336 ok( r == S_OK, "ret %08x\n", r );
3337 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
3338 ok( r == S_OK, "ret %08x\n", r );
3339 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
3341 IUnknown_Release( unk1 );
3342 IUnknown_Release( unk2 );
3344 /* ba_node should have been removed from below fo_node */
3345 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
3346 ok( r == S_OK, "ret %08x\n", r );
3348 /* MS quirk: replaceChild also accepts elements instead of nodes */
3349 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
3350 ok( r == S_OK, "ret %08x\n", r );
3352 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
3353 ok( r == S_OK, "ret %08x\n", r );
3355 r = IXMLDOMNodeList_get_length( fo_list, &len);
3356 ok( r == S_OK, "ret %08x\n", r );
3357 ok( len == 0, "len %d\n", len);
3359 IXMLDOMNodeList_Release( fo_list );
3361 IXMLDOMNode_Release(ba_node);
3362 IXMLDOMNode_Release(fo_node);
3363 IXMLDOMNode_Release(temp_node);
3364 IXMLDOMNodeList_Release( root_list );
3365 IXMLDOMElement_Release( element );
3366 IXMLDOMDocument_Release( doc );
3369 static void test_removeNamedItem(void)
3371 IXMLDOMDocument *doc;
3372 IXMLDOMElement *element;
3373 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
3374 IXMLDOMNodeList *root_list;
3375 IXMLDOMNamedNodeMap * pr_attrs;
3376 VARIANT_BOOL b;
3377 BSTR str;
3378 LONG len;
3379 HRESULT r;
3381 doc = create_document(&IID_IXMLDOMDocument);
3382 if (!doc) return;
3384 str = SysAllocString( szComplete4 );
3385 r = IXMLDOMDocument_loadXML( doc, str, &b );
3386 ok( r == S_OK, "loadXML failed\n");
3387 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3388 SysFreeString( str );
3390 r = IXMLDOMDocument_get_documentElement( doc, &element );
3391 ok( r == S_OK, "ret %08x\n", r);
3393 r = IXMLDOMElement_get_childNodes( element, &root_list );
3394 ok( r == S_OK, "ret %08x\n", r);
3396 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
3397 ok( r == S_OK, "ret %08x\n", r);
3399 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
3400 ok( r == S_OK, "ret %08x\n", r);
3402 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3403 ok( r == S_OK, "ret %08x\n", r);
3404 ok( len == 3, "length %d\n", len);
3406 removed_node = (void*)0xdeadbeef;
3407 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
3408 ok ( r == E_INVALIDARG, "ret %08x\n", r);
3409 ok ( removed_node == (void*)0xdeadbeef, "got %p\n", removed_node);
3411 removed_node = (void*)0xdeadbeef;
3412 str = SysAllocString(szvr);
3413 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
3414 ok ( r == S_OK, "ret %08x\n", r);
3416 removed_node2 = (void*)0xdeadbeef;
3417 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
3418 ok ( r == S_FALSE, "ret %08x\n", r);
3419 ok ( removed_node2 == NULL, "got %p\n", removed_node2 );
3421 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3422 ok( r == S_OK, "ret %08x\n", r);
3423 ok( len == 2, "length %d\n", len);
3425 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
3426 ok ( r == S_OK, "ret %08x\n", r);
3427 IXMLDOMNode_Release(removed_node);
3429 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3430 ok( r == S_OK, "ret %08x\n", r);
3431 ok( len == 3, "length %d\n", len);
3433 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
3434 ok ( r == S_OK, "ret %08x\n", r);
3436 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
3437 ok( r == S_OK, "ret %08x\n", r);
3438 ok( len == 2, "length %d\n", len);
3440 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
3441 ok ( r == S_FALSE, "ret %08x\n", r);
3443 SysFreeString(str);
3445 IXMLDOMNamedNodeMap_Release( pr_attrs );
3446 IXMLDOMNode_Release( pr_node );
3447 IXMLDOMNodeList_Release( root_list );
3448 IXMLDOMElement_Release( element );
3449 IXMLDOMDocument_Release( doc );
3452 static void test_XMLHTTP(void)
3454 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
3455 static const WCHAR wszPOST[] = {'P','O','S','T',0};
3456 static const WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
3457 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
3458 'p','o','s','t','t','e','s','t','.','p','h','p',0};
3459 static const WCHAR xmltestW[] = {'h','t','t','p',':','/','/',
3460 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
3461 'x','m','l','t','e','s','t','.','x','m','l',0};
3462 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
3463 static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
3465 IXMLHttpRequest *pXMLHttpRequest;
3466 BSTR bstrResponse, method, url;
3467 VARIANT dummy;
3468 VARIANT async;
3469 VARIANT varbody;
3470 LONG state, status, ref, bound;
3471 void *ptr;
3472 IDispatch *event;
3473 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
3474 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
3475 (void **)&pXMLHttpRequest);
3476 if (FAILED(hr))
3478 win_skip("IXMLHTTPRequest is not available (0x%08x)\n", hr);
3479 return;
3482 VariantInit(&dummy);
3483 V_VT(&dummy) = VT_ERROR;
3484 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
3485 VariantInit(&async);
3486 V_VT(&async) = VT_BOOL;
3487 V_BOOL(&async) = VARIANT_FALSE;
3488 V_VT(&varbody) = VT_BSTR;
3489 V_BSTR(&varbody) = SysAllocString(wszBody);
3491 method = SysAllocString(wszPOST);
3492 url = SysAllocString(wszUrl);
3494 if (0)
3496 /* crashes on win98 */
3497 hr = IXMLHttpRequest_put_onreadystatechange(pXMLHttpRequest, NULL);
3498 ok(hr == S_OK, "got 0x%08x\n", hr);
3501 hr = IXMLHttpRequest_abort(pXMLHttpRequest);
3502 ok(hr == S_OK, "got 0x%08x\n", hr);
3504 /* send before open */
3505 hr = IXMLHttpRequest_send(pXMLHttpRequest, dummy);
3506 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
3508 /* initial status code */
3509 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, NULL);
3510 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3512 status = 0xdeadbeef;
3513 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, &status);
3514 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
3515 ok(status == 0xdeadbeef, "got %d\n", status);
3517 /* invalid parameters */
3518 hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, NULL, async, dummy, dummy);
3519 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3521 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, NULL, async, dummy, dummy);
3522 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3524 hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, url, async, dummy, dummy);
3525 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3527 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, NULL);
3528 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3530 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), NULL);
3531 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
3533 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, _bstr_("value1"));
3534 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3536 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), _bstr_("value1"));
3537 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
3539 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, NULL);
3540 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3542 state = -1;
3543 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
3544 ok(hr == S_OK, "got 0x%08x\n", hr);
3545 ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state);
3547 event = create_dispevent();
3548 ref = IDispatch_AddRef(event);
3549 ok(ref == 2, "got %d\n", ref);
3550 IDispatch_Release(event);
3552 hr = IXMLHttpRequest_put_onreadystatechange(pXMLHttpRequest, event);
3553 ok(hr == S_OK, "got 0x%08x\n", hr);
3555 ref = IDispatch_AddRef(event);
3556 ok(ref == 3, "got %d\n", ref);
3557 IDispatch_Release(event);
3559 g_unexpectedcall = g_expectedcall = 0;
3561 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, url, async, dummy, dummy);
3562 ok(hr == S_OK, "got 0x%08x\n", hr);
3564 ok(g_unexpectedcall == 0, "unexpected disp event call\n");
3565 ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n");
3567 /* status code after ::open() */
3568 status = 0xdeadbeef;
3569 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, &status);
3570 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
3571 ok(status == 0xdeadbeef, "got %d\n", status);
3573 state = -1;
3574 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
3575 ok(hr == S_OK, "got 0x%08x\n", hr);
3576 ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state);
3578 hr = IXMLHttpRequest_abort(pXMLHttpRequest);
3579 ok(hr == S_OK, "got 0x%08x\n", hr);
3581 state = -1;
3582 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
3583 ok(hr == S_OK, "got 0x%08x\n", hr);
3584 ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win98, win2k */,
3585 "got %d, expected READYSTATE_UNINITIALIZED\n", state);
3587 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, url, async, dummy, dummy);
3588 ok(hr == S_OK, "got 0x%08x\n", hr);
3590 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), _bstr_("value1"));
3591 ok(hr == S_OK, "got 0x%08x\n", hr);
3593 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, _bstr_("value1"));
3594 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3596 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_(""), _bstr_("value1"));
3597 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3599 SysFreeString(method);
3600 SysFreeString(url);
3602 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
3603 if (hr == INET_E_RESOURCE_NOT_FOUND)
3605 skip("No connection could be made with crossover.codeweavers.com\n");
3606 IXMLHttpRequest_Release(pXMLHttpRequest);
3607 return;
3609 ok(hr == S_OK, "got 0x%08x\n", hr);
3611 /* status code after ::send() */
3612 status = 0xdeadbeef;
3613 hr = IXMLHttpRequest_get_status(pXMLHttpRequest, &status);
3614 ok(hr == S_OK, "got 0x%08x\n", hr);
3615 ok(status == 200, "got %d\n", status);
3617 /* another ::send() after completed request */
3618 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
3619 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
3621 VariantClear(&varbody);
3623 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
3624 ok(hr == S_OK, "got 0x%08x\n", hr);
3625 /* the server currently returns "FAILED" because the Content-Type header is
3626 * not what the server expects */
3627 if(hr == S_OK)
3629 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)),
3630 "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse));
3631 SysFreeString(bstrResponse);
3634 /* GET request */
3635 url = SysAllocString(xmltestW);
3637 hr = IXMLHttpRequest_open(pXMLHttpRequest, _bstr_("GET"), url, async, dummy, dummy);
3638 ok(hr == S_OK, "got 0x%08x\n", hr);
3640 V_VT(&varbody) = VT_EMPTY;
3642 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
3643 if (hr == INET_E_RESOURCE_NOT_FOUND)
3645 skip("No connection could be made with crossover.codeweavers.com\n");
3646 IXMLHttpRequest_Release(pXMLHttpRequest);
3647 return;
3649 ok(hr == S_OK, "got 0x%08x\n", hr);
3651 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, NULL);
3652 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3654 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
3655 ok(hr == S_OK, "got 0x%08x\n", hr);
3656 if(hr == S_OK)
3658 ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
3659 "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
3660 SysFreeString(bstrResponse);
3663 hr = IXMLHttpRequest_get_responseBody(pXMLHttpRequest, NULL);
3664 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3666 V_VT(&varbody) = VT_EMPTY;
3667 hr = IXMLHttpRequest_get_responseBody(pXMLHttpRequest, &varbody);
3668 ok(hr == S_OK, "got 0x%08x\n", hr);
3669 ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
3670 ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
3672 bound = -1;
3673 hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
3674 ok(hr == S_OK, "got 0x%08x\n", hr);
3675 ok(bound == 0, "got %d, expected zero bound\n", bound);
3677 hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
3678 ok(hr == S_OK, "got 0x%08x\n", hr);
3679 ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrond body data\n");
3680 SafeArrayUnaccessData(V_ARRAY(&varbody));
3682 VariantClear(&varbody);
3684 SysFreeString(url);
3686 IDispatch_Release(event);
3687 IXMLHttpRequest_Release(pXMLHttpRequest);
3688 free_bstrs();
3691 static void test_IXMLDOMDocument2(void)
3693 static const WCHAR emptyW[] = {0};
3694 IXMLDOMDocument2 *doc2, *dtddoc2;
3695 IXMLDOMDocument *doc;
3696 IXMLDOMParseError* err;
3697 IDispatchEx *dispex;
3698 VARIANT_BOOL b;
3699 VARIANT var;
3700 HRESULT r;
3701 LONG ref, res;
3702 BSTR str;
3704 doc = create_document(&IID_IXMLDOMDocument);
3705 if (!doc) return;
3707 dtddoc2 = create_document(&IID_IXMLDOMDocument2);
3708 if (!dtddoc2)
3710 IXMLDOMDocument_Release(doc);
3711 return;
3714 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
3715 ok( r == S_OK, "ret %08x\n", r );
3716 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
3718 ole_expect(IXMLDOMDocument2_get_readyState(doc2, NULL), E_INVALIDARG);
3719 ole_check(IXMLDOMDocument2_get_readyState(doc2, &res));
3720 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
3722 err = NULL;
3723 ole_expect(IXMLDOMDocument2_validate(doc2, NULL), S_FALSE);
3724 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
3725 ok(err != NULL, "expected a pointer\n");
3726 if (err)
3728 res = 0;
3729 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3730 /* XML_E_NOTWF */
3731 ok(res == E_XML_NOTWF, "got %08x\n", res);
3732 IXMLDOMParseError_Release(err);
3735 str = SysAllocString( szComplete4 );
3736 r = IXMLDOMDocument_loadXML( doc2, str, &b );
3737 ok( r == S_OK, "loadXML failed\n");
3738 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3739 SysFreeString( str );
3741 ole_check(IXMLDOMDocument2_get_readyState(doc, &res));
3742 ok(res == READYSTATE_COMPLETE, "expected READYSTATE_COMPLETE (4), got %i\n", res);
3744 err = NULL;
3745 ole_expect(IXMLDOMDocument2_validate(doc2, &err), S_FALSE);
3746 ok(err != NULL, "expected a pointer\n");
3747 if (err)
3749 res = 0;
3750 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3751 /* XML_E_NODTD */
3752 ok(res == E_XML_NODTD, "got %08x\n", res);
3753 IXMLDOMParseError_Release(err);
3756 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
3757 ok( r == S_OK, "ret %08x\n", r );
3758 if(r == S_OK)
3760 IDispatchEx_Release(dispex);
3763 /* we will check if the variant got cleared */
3764 ref = IXMLDOMDocument2_AddRef(doc2);
3765 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
3766 V_VT(&var) = VT_UNKNOWN;
3767 V_UNKNOWN(&var) = (IUnknown *)doc2;
3769 /* invalid calls */
3770 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
3771 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
3772 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
3774 /* valid call */
3775 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3776 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3777 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3778 V_VT(&var) = VT_R4;
3780 /* the variant didn't get cleared*/
3781 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
3783 /* setProperty tests */
3784 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
3785 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
3786 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
3787 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3788 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3789 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3791 V_VT(&var) = VT_BSTR;
3792 V_BSTR(&var) = SysAllocString(emptyW);
3793 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3794 ok(r == S_OK, "got 0x%08x\n", r);
3795 VariantClear(&var);
3797 V_VT(&var) = VT_I2;
3798 V_I2(&var) = 0;
3799 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3800 ok(r == E_FAIL, "got 0x%08x\n", r);
3802 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
3803 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3804 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3805 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3807 IXMLDOMDocument2_Release( doc2 );
3808 IXMLDOMDocument_Release( doc );
3810 /* DTD validation */
3811 ole_check(IXMLDOMDocument2_put_validateOnParse(dtddoc2, VARIANT_FALSE));
3812 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML), &b));
3813 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3814 err = NULL;
3815 ole_check(IXMLDOMDocument2_validate(dtddoc2, &err));
3816 ok(err != NULL, "expected pointer\n");
3817 if (err)
3819 res = 0;
3820 ole_expect(IXMLDOMParseError_get_errorCode(err, &res), S_FALSE);
3821 ok(res == 0, "got %08x\n", res);
3822 IXMLDOMParseError_Release(err);
3825 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0D), &b));
3826 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3827 err = NULL;
3828 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3829 ok(err != NULL, "expected pointer\n");
3830 if (err)
3832 res = 0;
3833 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3834 /* XML_ELEMENT_UNDECLARED */
3835 todo_wine ok(res == 0xC00CE00D, "got %08x\n", res);
3836 IXMLDOMParseError_Release(err);
3839 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_0E), &b));
3840 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3841 err = NULL;
3842 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3843 ok(err != NULL, "expected pointer\n");
3844 if (err)
3846 res = 0;
3847 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3848 /* XML_ELEMENT_ID_NOT_FOUND */
3849 todo_wine ok(res == 0xC00CE00E, "got %08x\n", res);
3850 IXMLDOMParseError_Release(err);
3853 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_11), &b));
3854 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3855 err = NULL;
3856 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3857 ok(err != NULL, "expected pointer\n");
3858 if (err)
3860 res = 0;
3861 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3862 /* XML_EMPTY_NOT_ALLOWED */
3863 todo_wine ok(res == 0xC00CE011, "got %08x\n", res);
3864 IXMLDOMParseError_Release(err);
3867 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_13), &b));
3868 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3869 err = NULL;
3870 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3871 ok(err != NULL, "expected pointer\n");
3872 if (err)
3874 res = 0;
3875 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3876 /* XML_ROOT_NAME_MISMATCH */
3877 todo_wine ok(res == 0xC00CE013, "got %08x\n", res);
3878 IXMLDOMParseError_Release(err);
3881 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_14), &b));
3882 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3883 err = NULL;
3884 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3885 ok(err != NULL, "expected pointer\n");
3886 if (err)
3888 res = 0;
3889 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3890 /* XML_INVALID_CONTENT */
3891 todo_wine ok(res == 0xC00CE014, "got %08x\n", res);
3892 IXMLDOMParseError_Release(err);
3895 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_15), &b));
3896 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3897 err = NULL;
3898 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3899 ok(err != NULL, "expected pointer\n");
3900 if (err)
3902 res = 0;
3903 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3904 /* XML_ATTRIBUTE_NOT_DEFINED */
3905 todo_wine ok(res == 0xC00CE015, "got %08x\n", res);
3906 IXMLDOMParseError_Release(err);
3909 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_16), &b));
3910 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3911 err = NULL;
3912 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3913 ok(err != NULL, "expected pointer\n");
3914 if (err)
3916 res = 0;
3917 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3918 /* XML_ATTRIBUTE_FIXED */
3919 todo_wine ok(res == 0xC00CE016, "got %08x\n", res);
3920 IXMLDOMParseError_Release(err);
3923 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_17), &b));
3924 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3925 err = NULL;
3926 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3927 ok(err != NULL, "expected pointer\n");
3928 if (err)
3930 res = 0;
3931 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3932 /* XML_ATTRIBUTE_VALUE */
3933 todo_wine ok(res == 0xC00CE017, "got %08x\n", res);
3934 IXMLDOMParseError_Release(err);
3937 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_18), &b));
3938 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3939 err = NULL;
3940 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3941 ok(err != NULL, "expected pointer\n");
3942 if (err)
3944 res = 0;
3945 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3946 /* XML_ILLEGAL_TEXT */
3947 todo_wine ok(res == 0xC00CE018, "got %08x\n", res);
3948 IXMLDOMParseError_Release(err);
3951 ole_check(IXMLDOMDocument2_loadXML(dtddoc2, _bstr_(szEmailXML_20), &b));
3952 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3953 err = NULL;
3954 ole_expect(IXMLDOMDocument2_validate(dtddoc2, &err), S_FALSE);
3955 ok(err != NULL, "expected pointer\n");
3956 if (err)
3958 res = 0;
3959 ole_check(IXMLDOMParseError_get_errorCode(err, &res));
3960 /* XML_REQUIRED_ATTRIBUTE_MISSING */
3961 todo_wine ok(res == 0xC00CE020, "got %08x\n", res);
3962 IXMLDOMParseError_Release(err);
3965 IXMLDOMDocument2_Release( dtddoc2 );
3966 free_bstrs();
3969 #define helper_ole_check(expr) { \
3970 HRESULT r = expr; \
3971 ok_(__FILE__, line)(r == S_OK, "=> %i: " #expr " returned %08x\n", __LINE__, r); \
3974 #define helper_expect_list_and_release(list, expstr) { \
3975 char *str = list_to_string(list); \
3976 ok_(__FILE__, line)(strcmp(str, expstr)==0, "=> %i: Invalid node list: %s, expected %s\n", __LINE__, str, expstr); \
3977 if (list) IXMLDOMNodeList_Release(list); \
3980 #define helper_expect_bstr_and_release(bstr, str) { \
3981 ok_(__FILE__, line)(lstrcmpW(bstr, _bstr_(str)) == 0, \
3982 "=> %i: got %s\n", __LINE__, wine_dbgstr_w(bstr)); \
3983 SysFreeString(bstr); \
3986 #define check_ws_ignored(doc, str) _check_ws_ignored(__LINE__, doc, str)
3987 static inline void _check_ws_ignored(int line, IXMLDOMDocument2* doc, char const* str)
3989 IXMLDOMNode *node1, *node2;
3990 IXMLDOMNodeList *list;
3991 BSTR bstr;
3993 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
3994 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
3995 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
3996 helper_ole_check(IXMLDOMNodeList_reset(list));
3997 helper_expect_list_and_release(list, "E1.E4.E1.E2.D1 E2.E4.E1.E2.D1");
3999 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
4000 helper_expect_list_and_release(list, "T1.E1.E4.E1.E2.D1 E2.E1.E4.E1.E2.D1 E3.E1.E4.E1.E2.D1 T4.E1.E4.E1.E2.D1 E5.E1.E4.E1.E2.D1");
4001 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
4002 if (str)
4004 helper_expect_bstr_and_release(bstr, str);
4006 else
4008 helper_expect_bstr_and_release(bstr, "This is a description.");
4010 IXMLDOMNode_Release(node1);
4012 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
4013 helper_expect_list_and_release(list, "T1.E2.E4.E1.E2.D1 E2.E2.E4.E1.E2.D1 T3.E2.E4.E1.E2.D1 E4.E2.E4.E1.E2.D1 T5.E2.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1 T7.E2.E4.E1.E2.D1");
4014 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
4015 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
4016 IXMLDOMNode_Release(node2);
4019 #define check_ws_preserved(doc, str) _check_ws_preserved(__LINE__, doc, str)
4020 static inline void _check_ws_preserved(int line, IXMLDOMDocument2* doc, char const* str)
4022 IXMLDOMNode *node1, *node2;
4023 IXMLDOMNodeList *list;
4024 BSTR bstr;
4026 helper_ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
4027 helper_ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
4028 helper_ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
4029 helper_ole_check(IXMLDOMNodeList_reset(list));
4030 helper_expect_list_and_release(list, "E2.E8.E2.E2.D1 E4.E8.E2.E2.D1");
4032 helper_ole_check(IXMLDOMNode_get_childNodes(node1, &list));
4033 helper_expect_list_and_release(list, "T1.E2.E8.E2.E2.D1 E2.E2.E8.E2.E2.D1 T3.E2.E8.E2.E2.D1 E4.E2.E8.E2.E2.D1 T5.E2.E8.E2.E2.D1 E6.E2.E8.E2.E2.D1 T7.E2.E8.E2.E2.D1");
4034 helper_ole_check(IXMLDOMNode_get_text(node1, &bstr));
4035 if (str)
4037 helper_expect_bstr_and_release(bstr, str);
4039 else
4041 helper_expect_bstr_and_release(bstr, "\n This is a description. \n ");
4043 IXMLDOMNode_Release(node1);
4045 helper_ole_check(IXMLDOMNode_get_childNodes(node2, &list));
4046 helper_expect_list_and_release(list, "T1.E4.E8.E2.E2.D1 E2.E4.E8.E2.E2.D1 T3.E4.E8.E2.E2.D1 E4.E4.E8.E2.E2.D1 T5.E4.E8.E2.E2.D1 E6.E4.E8.E2.E2.D1 T7.E4.E8.E2.E2.D1");
4047 helper_ole_check(IXMLDOMNode_get_text(node2, &bstr));
4048 helper_expect_bstr_and_release(bstr, "\n This is a description with preserved whitespace. \n ");
4049 IXMLDOMNode_Release(node2);
4052 static void test_whitespace(void)
4054 VARIANT_BOOL b;
4055 IXMLDOMDocument2 *doc1, *doc2, *doc3, *doc4;
4057 doc1 = create_document(&IID_IXMLDOMDocument2);
4058 doc2 = create_document(&IID_IXMLDOMDocument2);
4059 if (!doc1 || !doc2) return;
4061 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_TRUE));
4062 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
4063 ok(b == VARIANT_FALSE, "expected false\n");
4064 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
4065 ok(b == VARIANT_TRUE, "expected true\n");
4067 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
4068 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4069 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
4070 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4072 /* switch to XPath */
4073 ole_check(IXMLDOMDocument2_setProperty(doc1, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4074 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4076 check_ws_ignored(doc1, NULL);
4077 check_ws_preserved(doc2, NULL);
4079 /* new instances copy the property */
4080 ole_check(IXMLDOMDocument2_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**) &doc3));
4081 ole_check(IXMLDOMDocument2_QueryInterface(doc2, &IID_IXMLDOMDocument2, (void**) &doc4));
4083 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
4084 ok(b == VARIANT_FALSE, "expected false\n");
4085 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
4086 ok(b == VARIANT_TRUE, "expected true\n");
4088 check_ws_ignored(doc3, NULL);
4089 check_ws_preserved(doc4, NULL);
4091 /* setting after loading xml affects trimming of leading/trailing ws only */
4092 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_TRUE));
4093 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_FALSE));
4095 /* the trailing "\n " isn't there, because it was ws-only node */
4096 check_ws_ignored(doc1, "\n This is a description. ");
4097 check_ws_preserved(doc2, "This is a description.");
4099 /* it takes effect on reload */
4100 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
4101 ok(b == VARIANT_TRUE, "expected true\n");
4102 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
4103 ok(b == VARIANT_FALSE, "expected false\n");
4105 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
4106 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4107 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
4108 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4110 check_ws_preserved(doc1, NULL);
4111 check_ws_ignored(doc2, NULL);
4113 /* other instances follow suit */
4114 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
4115 ok(b == VARIANT_TRUE, "expected true\n");
4116 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
4117 ok(b == VARIANT_FALSE, "expected false\n");
4119 check_ws_preserved(doc3, NULL);
4120 check_ws_ignored(doc4, NULL);
4122 IXMLDOMDocument_Release(doc1);
4123 IXMLDOMDocument_Release(doc2);
4124 IXMLDOMDocument_Release(doc3);
4125 IXMLDOMDocument_Release(doc4);
4126 free_bstrs();
4129 static void test_XPath(void)
4131 VARIANT var;
4132 VARIANT_BOOL b;
4133 IXMLDOMDocument2 *doc;
4134 IXMLDOMNode *rootNode;
4135 IXMLDOMNode *elem1Node;
4136 IXMLDOMNode *node;
4137 IXMLDOMNodeList *list;
4139 doc = create_document(&IID_IXMLDOMDocument2);
4140 if (!doc) return;
4142 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
4143 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4145 /* switch to XPath */
4146 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
4148 /* some simple queries*/
4149 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
4150 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
4151 ole_check(IXMLDOMNodeList_reset(list));
4152 expect_list_and_release(list, "E2.D1");
4153 if (rootNode == NULL)
4154 return;
4156 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
4157 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
4159 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
4160 expect_list_and_release(list, "E3.E2.E2.D1");
4162 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
4163 /* using get_item for query results advances the position */
4164 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
4165 expect_node(node, "E2.E2.D1");
4166 IXMLDOMNode_Release(node);
4167 ole_check(IXMLDOMNodeList_nextNode(list, &node));
4168 expect_node(node, "E4.E2.D1");
4169 IXMLDOMNode_Release(node);
4170 ole_check(IXMLDOMNodeList_reset(list));
4171 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
4173 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
4174 expect_list_and_release(list, "E2.D1");
4176 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
4177 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
4178 ole_check(IXMLDOMNodeList_reset(list));
4179 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
4181 /* select an attribute */
4182 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
4183 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
4185 /* would evaluate to a number */
4186 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
4187 /* would evaluate to a boolean */
4188 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
4189 /* would evaluate to a string */
4190 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
4192 /* no results */
4193 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
4194 expect_list_and_release(list, "");
4195 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
4196 expect_list_and_release(list, "");
4197 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
4198 expect_list_and_release(list, "");
4199 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//elem[0]"), &list));
4200 expect_list_and_release(list, "");
4202 /* foo undeclared in document node */
4203 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4204 /* undeclared in <root> node */
4205 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
4206 /* undeclared in <elem> node */
4207 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
4208 /* but this trick can be used */
4209 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
4210 expect_list_and_release(list, "E3.E4.E2.D1");
4212 /* it has to be declared in SelectionNamespaces */
4213 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4214 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
4216 /* now the namespace can be used */
4217 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
4218 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4219 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
4220 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4221 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
4222 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
4223 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
4224 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
4226 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
4227 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4228 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
4230 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4232 VariantInit(&var);
4233 ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
4234 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
4235 if (V_VT(&var) == VT_BSTR)
4236 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
4238 /* extra attributes - same thing*/
4239 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
4240 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
4241 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
4243 IXMLDOMNode_Release(rootNode);
4244 IXMLDOMNode_Release(elem1Node);
4245 IXMLDOMDocument_Release(doc);
4246 free_bstrs();
4249 static void test_cloneNode(void )
4251 IXMLDOMDocument *doc;
4252 VARIANT_BOOL b;
4253 IXMLDOMNodeList *pList;
4254 IXMLDOMNamedNodeMap *mapAttr;
4255 LONG nLength = 0, nLength1 = 0;
4256 LONG nAttrCnt = 0, nAttrCnt1 = 0;
4257 IXMLDOMNode *node;
4258 IXMLDOMNode *node_clone;
4259 IXMLDOMNode *node_first;
4260 HRESULT r;
4261 BSTR str;
4262 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
4264 doc = create_document(&IID_IXMLDOMDocument);
4265 if (!doc) return;
4267 str = SysAllocString( szComplete4 );
4268 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
4269 ok(b == VARIANT_TRUE, "failed to load XML string\n");
4270 SysFreeString(str);
4272 if(!b)
4273 return;
4275 str = SysAllocString( szSearch);
4276 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
4277 ok( r == S_OK, "ret %08x\n", r );
4278 ok( node != NULL, "node %p\n", node );
4279 SysFreeString(str);
4281 if(!node)
4283 IXMLDOMDocument_Release(doc);
4284 return;
4287 /* Check invalid parameter */
4288 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
4289 ok( r == E_INVALIDARG, "ret %08x\n", r );
4291 /* All Children */
4292 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
4293 ok( r == S_OK, "ret %08x\n", r );
4294 ok( node_clone != NULL, "node %p\n", node );
4296 if(!node_clone)
4298 IXMLDOMDocument_Release(doc);
4299 IXMLDOMNode_Release(node);
4300 return;
4303 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
4304 ok( r == S_OK, "ret %08x\n", r );
4305 if(r == S_OK)
4307 IXMLDOMDocument *doc2;
4309 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
4310 ok( r == S_OK, "ret %08x\n", r );
4311 if(r == S_OK)
4312 IXMLDOMDocument_Release(doc2);
4314 IXMLDOMNode_Release(node_first);
4317 r = IXMLDOMNode_get_childNodes(node, &pList);
4318 ok( r == S_OK, "ret %08x\n", r );
4319 if (pList)
4321 IXMLDOMNodeList_get_length(pList, &nLength);
4322 IXMLDOMNodeList_Release(pList);
4325 r = IXMLDOMNode_get_attributes(node, &mapAttr);
4326 ok( r == S_OK, "ret %08x\n", r );
4327 if(mapAttr)
4329 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
4330 IXMLDOMNamedNodeMap_Release(mapAttr);
4333 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
4334 ok( r == S_OK, "ret %08x\n", r );
4335 if (pList)
4337 IXMLDOMNodeList_get_length(pList, &nLength1);
4338 IXMLDOMNodeList_Release(pList);
4341 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
4342 ok( r == S_OK, "ret %08x\n", r );
4343 if(mapAttr)
4345 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
4346 IXMLDOMNamedNodeMap_Release(mapAttr);
4349 ok(nLength == nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
4350 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
4351 IXMLDOMNode_Release(node_clone);
4353 /* No Children */
4354 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
4355 ok( r == S_OK, "ret %08x\n", r );
4356 ok( node_clone != NULL, "node %p\n", node );
4358 if(!node_clone)
4360 IXMLDOMDocument_Release(doc);
4361 IXMLDOMNode_Release(node);
4362 return;
4365 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
4366 ok( r == S_FALSE, "ret %08x\n", r );
4367 if(r == S_OK)
4369 IXMLDOMDocument *doc2;
4371 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
4372 ok( r == S_OK, "ret %08x\n", r );
4373 if(r == S_OK)
4374 IXMLDOMDocument_Release(doc2);
4376 IXMLDOMNode_Release(node_first);
4379 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
4380 ok( r == S_OK, "ret %08x\n", r );
4381 if (pList)
4383 IXMLDOMNodeList_get_length(pList, &nLength1);
4384 ok( nLength1 == 0, "Length should be 0 (%d)\n", nLength1);
4385 IXMLDOMNodeList_Release(pList);
4388 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
4389 ok( r == S_OK, "ret %08x\n", r );
4390 if(mapAttr)
4392 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
4393 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%d)\n", nAttrCnt1);
4394 IXMLDOMNamedNodeMap_Release(mapAttr);
4397 ok(nLength != nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
4398 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
4399 IXMLDOMNode_Release(node_clone);
4402 IXMLDOMNode_Release(node);
4403 IXMLDOMDocument_Release(doc);
4406 static void test_xmlTypes(void)
4408 IXMLDOMDocument *doc;
4409 IXMLDOMElement *pRoot;
4410 HRESULT hr;
4411 IXMLDOMComment *pComment;
4412 IXMLDOMElement *pElement;
4413 IXMLDOMAttribute *pAttribute;
4414 IXMLDOMNamedNodeMap *pAttribs;
4415 IXMLDOMCDATASection *pCDataSec;
4416 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
4417 IXMLDOMDocumentFragment *pDocFrag = NULL;
4418 IXMLDOMEntityReference *pEntityRef = NULL;
4419 BSTR str;
4420 IXMLDOMNode *pNextChild;
4421 VARIANT v;
4422 LONG len = 0;
4424 doc = create_document(&IID_IXMLDOMDocument);
4425 if (!doc) return;
4427 pNextChild = (void*)0xdeadbeef;
4428 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
4429 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4431 pNextChild = (void*)0xdeadbeef;
4432 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
4433 ok(hr == S_FALSE, "ret %08x\n", hr );
4434 ok(pNextChild == NULL, "pDocChild not NULL\n");
4436 /* test previous Sibling */
4437 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
4438 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4440 pNextChild = (void*)0xdeadbeef;
4441 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
4442 ok(hr == S_FALSE, "ret %08x\n", hr );
4443 ok(pNextChild == NULL, "pNextChild not NULL\n");
4445 /* test get_attributes */
4446 hr = IXMLDOMDocument_get_attributes( doc, NULL );
4447 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
4449 pAttribs = (void*)0xdeadbeef;
4450 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
4451 ok(hr == S_FALSE, "ret %08x\n", hr );
4452 ok( pAttribs == NULL, "pAttribs not NULL\n");
4454 /* test get_dataType */
4455 V_VT(&v) = VT_EMPTY;
4456 hr = IXMLDOMDocument_get_dataType(doc, &v);
4457 ok(hr == S_FALSE, "ret %08x\n", hr );
4458 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4459 VariantClear(&v);
4461 /* test nodeTypeString */
4462 str = NULL;
4463 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
4464 ok(hr == S_OK, "ret %08x\n", hr );
4465 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
4466 SysFreeString(str);
4468 /* test implementation */
4469 hr = IXMLDOMDocument_get_implementation(doc, NULL);
4470 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4472 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
4473 ok(hr == S_OK, "ret %08x\n", hr );
4474 if(hr == S_OK)
4476 VARIANT_BOOL hasFeature = VARIANT_TRUE;
4477 BSTR sEmpty = SysAllocStringLen(NULL, 0);
4479 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
4480 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4482 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
4483 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4485 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
4486 ok(hr == S_OK, "ret %08x\n", hr );
4487 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4489 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
4490 ok(hr == S_OK, "ret %08x\n", hr );
4491 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
4493 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
4494 ok(hr == S_OK, "ret %08x\n", hr );
4495 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
4497 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
4498 ok(hr == S_OK, "ret %08x\n", hr );
4499 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4501 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
4502 ok(hr == S_OK, "ret %08x\n", hr );
4503 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4505 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
4506 ok(hr == S_OK, "ret %08x\n", hr );
4507 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4509 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
4510 ok(hr == S_OK, "ret %08x\n", hr );
4511 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
4513 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
4514 ok(hr == S_OK, "ret %08x\n", hr );
4515 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
4517 SysFreeString(sEmpty);
4518 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
4521 pRoot = (IXMLDOMElement*)0x1;
4522 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
4523 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4524 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
4526 pRoot = (IXMLDOMElement*)0x1;
4527 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
4528 ok(hr == E_FAIL, "ret %08x\n", hr );
4529 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
4531 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
4532 ok(hr == S_OK, "ret %08x\n", hr );
4533 if(hr == S_OK)
4535 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
4536 ok(hr == S_OK, "ret %08x\n", hr );
4537 if(hr == S_OK)
4539 /* Comment */
4540 str = SysAllocString(szComment);
4541 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
4542 SysFreeString(str);
4543 ok(hr == S_OK, "ret %08x\n", hr );
4544 if(hr == S_OK)
4546 /* test get_attributes */
4547 hr = IXMLDOMComment_get_attributes( pComment, NULL );
4548 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
4550 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4551 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
4552 ok(hr == S_FALSE, "ret %08x\n", hr );
4553 ok( pAttribs == NULL, "pAttribs not NULL\n");
4555 /* test nodeTypeString */
4556 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
4557 ok(hr == S_OK, "ret %08x\n", hr );
4558 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
4559 SysFreeString(str);
4561 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
4562 ok(hr == S_OK, "ret %08x\n", hr );
4564 hr = IXMLDOMComment_get_nodeName(pComment, &str);
4565 ok(hr == S_OK, "ret %08x\n", hr );
4566 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
4567 SysFreeString(str);
4569 hr = IXMLDOMComment_get_xml(pComment, &str);
4570 ok(hr == S_OK, "ret %08x\n", hr );
4571 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
4572 SysFreeString(str);
4574 hr = IXMLDOMComment_get_dataType(pComment, &v);
4575 ok(hr == S_FALSE, "ret %08x\n", hr );
4576 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4577 VariantClear(&v);
4579 /* put data Tests */
4580 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
4581 ok(hr == S_OK, "ret %08x\n", hr );
4583 /* get data Tests */
4584 hr = IXMLDOMComment_get_data(pComment, &str);
4585 ok(hr == S_OK, "ret %08x\n", hr );
4586 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
4587 SysFreeString(str);
4589 /* get data Tests */
4590 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
4591 ok(hr == S_OK, "ret %08x\n", hr );
4592 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
4593 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
4594 VariantClear(&v);
4596 /* Confirm XML text is good */
4597 hr = IXMLDOMComment_get_xml(pComment, &str);
4598 ok(hr == S_OK, "ret %08x\n", hr );
4599 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
4600 SysFreeString(str);
4602 /* Confirm we get the put_data Text back */
4603 hr = IXMLDOMComment_get_text(pComment, &str);
4604 ok(hr == S_OK, "ret %08x\n", hr );
4605 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
4606 SysFreeString(str);
4608 /* test length property */
4609 hr = IXMLDOMComment_get_length(pComment, &len);
4610 ok(hr == S_OK, "ret %08x\n", hr );
4611 ok(len == 21, "expected 21 got %d\n", len);
4613 /* test substringData */
4614 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
4615 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4617 /* test substringData - Invalid offset */
4618 str = (BSTR)&szElement;
4619 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
4620 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4621 ok( str == NULL, "incorrect string\n");
4623 /* test substringData - Invalid offset */
4624 str = (BSTR)&szElement;
4625 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
4626 ok(hr == S_FALSE, "ret %08x\n", hr );
4627 ok( str == NULL, "incorrect string\n");
4629 /* test substringData - Invalid size */
4630 str = (BSTR)&szElement;
4631 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
4632 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4633 ok( str == NULL, "incorrect string\n");
4635 /* test substringData - Invalid size */
4636 str = (BSTR)&szElement;
4637 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
4638 ok(hr == S_FALSE, "ret %08x\n", hr );
4639 ok( str == NULL, "incorrect string\n");
4641 /* test substringData - Start of string */
4642 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
4643 ok(hr == S_OK, "ret %08x\n", hr );
4644 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
4645 SysFreeString(str);
4647 /* test substringData - Middle of string */
4648 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
4649 ok(hr == S_OK, "ret %08x\n", hr );
4650 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
4651 SysFreeString(str);
4653 /* test substringData - End of string */
4654 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
4655 ok(hr == S_OK, "ret %08x\n", hr );
4656 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
4657 SysFreeString(str);
4659 /* test appendData */
4660 hr = IXMLDOMComment_appendData(pComment, NULL);
4661 ok(hr == S_OK, "ret %08x\n", hr );
4663 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
4664 ok(hr == S_OK, "ret %08x\n", hr );
4666 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
4667 ok(hr == S_OK, "ret %08x\n", hr );
4669 hr = IXMLDOMComment_get_text(pComment, &str);
4670 ok(hr == S_OK, "ret %08x\n", hr );
4671 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4672 SysFreeString(str);
4674 /* test insertData */
4675 str = SysAllocStringLen(NULL, 0);
4676 hr = IXMLDOMComment_insertData(pComment, -1, str);
4677 ok(hr == S_OK, "ret %08x\n", hr );
4679 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
4680 ok(hr == S_OK, "ret %08x\n", hr );
4682 hr = IXMLDOMComment_insertData(pComment, 1000, str);
4683 ok(hr == S_OK, "ret %08x\n", hr );
4685 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
4686 ok(hr == S_OK, "ret %08x\n", hr );
4688 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
4689 ok(hr == S_OK, "ret %08x\n", hr );
4691 hr = IXMLDOMComment_insertData(pComment, 0, str);
4692 ok(hr == S_OK, "ret %08x\n", hr );
4693 SysFreeString(str);
4695 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
4696 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4698 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
4699 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4701 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
4702 ok(hr == S_OK, "ret %08x\n", hr );
4704 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
4705 ok(hr == S_OK, "ret %08x\n", hr );
4707 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
4708 ok(hr == S_OK, "ret %08x\n", hr );
4710 hr = IXMLDOMComment_get_text(pComment, &str);
4711 ok(hr == S_OK, "ret %08x\n", hr );
4712 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4713 SysFreeString(str);
4715 /* delete data */
4716 /* invalid arguments */
4717 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
4718 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4720 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
4721 ok(hr == S_OK, "ret %08x\n", hr );
4723 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
4724 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4726 hr = IXMLDOMComment_get_length(pComment, &len);
4727 ok(hr == S_OK, "ret %08x\n", hr );
4728 ok(len == 43, "expected 43 got %d\n", len);
4730 hr = IXMLDOMComment_deleteData(pComment, len, 1);
4731 ok(hr == S_OK, "ret %08x\n", hr );
4733 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
4734 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4736 /* delete from start */
4737 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
4738 ok(hr == S_OK, "ret %08x\n", hr );
4740 hr = IXMLDOMComment_get_length(pComment, &len);
4741 ok(hr == S_OK, "ret %08x\n", hr );
4742 ok(len == 38, "expected 38 got %d\n", len);
4744 hr = IXMLDOMComment_get_text(pComment, &str);
4745 ok(hr == S_OK, "ret %08x\n", hr );
4746 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4747 SysFreeString(str);
4749 /* delete from end */
4750 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
4751 ok(hr == S_OK, "ret %08x\n", hr );
4753 hr = IXMLDOMComment_get_length(pComment, &len);
4754 ok(hr == S_OK, "ret %08x\n", hr );
4755 ok(len == 35, "expected 35 got %d\n", len);
4757 hr = IXMLDOMComment_get_text(pComment, &str);
4758 ok(hr == S_OK, "ret %08x\n", hr );
4759 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4760 SysFreeString(str);
4762 /* delete from inside */
4763 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
4764 ok(hr == S_OK, "ret %08x\n", hr );
4766 hr = IXMLDOMComment_get_length(pComment, &len);
4767 ok(hr == S_OK, "ret %08x\n", hr );
4768 ok(len == 2, "expected 2 got %d\n", len);
4770 hr = IXMLDOMComment_get_text(pComment, &str);
4771 ok(hr == S_OK, "ret %08x\n", hr );
4772 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4773 SysFreeString(str);
4775 /* delete whole data ... */
4776 hr = IXMLDOMComment_get_length(pComment, &len);
4777 ok(hr == S_OK, "ret %08x\n", hr );
4779 hr = IXMLDOMComment_deleteData(pComment, 0, len);
4780 ok(hr == S_OK, "ret %08x\n", hr );
4781 /* ... and try again with empty string */
4782 hr = IXMLDOMComment_deleteData(pComment, 0, len);
4783 ok(hr == S_OK, "ret %08x\n", hr );
4785 /* ::replaceData() */
4786 V_VT(&v) = VT_BSTR;
4787 V_BSTR(&v) = SysAllocString(szstr1);
4788 hr = IXMLDOMComment_put_nodeValue(pComment, v);
4789 ok(hr == S_OK, "ret %08x\n", hr );
4790 VariantClear(&v);
4792 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
4793 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4794 hr = IXMLDOMComment_get_text(pComment, &str);
4795 ok(hr == S_OK, "ret %08x\n", hr );
4796 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4797 SysFreeString(str);
4799 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
4800 ok(hr == S_OK, "ret %08x\n", hr );
4801 hr = IXMLDOMComment_get_text(pComment, &str);
4802 ok(hr == S_OK, "ret %08x\n", hr );
4803 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4804 SysFreeString(str);
4806 /* NULL pointer means delete */
4807 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
4808 ok(hr == S_OK, "ret %08x\n", hr );
4809 hr = IXMLDOMComment_get_text(pComment, &str);
4810 ok(hr == S_OK, "ret %08x\n", hr );
4811 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4812 SysFreeString(str);
4814 /* empty string means delete */
4815 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
4816 ok(hr == S_OK, "ret %08x\n", hr );
4817 hr = IXMLDOMComment_get_text(pComment, &str);
4818 ok(hr == S_OK, "ret %08x\n", hr );
4819 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4820 SysFreeString(str);
4822 /* zero count means insert */
4823 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
4824 ok(hr == S_OK, "ret %08x\n", hr );
4825 hr = IXMLDOMComment_get_text(pComment, &str);
4826 ok(hr == S_OK, "ret %08x\n", hr );
4827 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4828 SysFreeString(str);
4830 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
4831 ok(hr == S_OK, "ret %08x\n", hr );
4833 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
4834 ok(hr == S_OK, "ret %08x\n", hr );
4835 hr = IXMLDOMComment_get_text(pComment, &str);
4836 ok(hr == S_OK, "ret %08x\n", hr );
4837 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4838 SysFreeString(str);
4840 /* nonempty string, count greater than its length */
4841 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
4842 ok(hr == S_OK, "ret %08x\n", hr );
4843 hr = IXMLDOMComment_get_text(pComment, &str);
4844 ok(hr == S_OK, "ret %08x\n", hr );
4845 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4846 SysFreeString(str);
4848 /* nonempty string, count less than its length */
4849 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
4850 ok(hr == S_OK, "ret %08x\n", hr );
4851 hr = IXMLDOMComment_get_text(pComment, &str);
4852 ok(hr == S_OK, "ret %08x\n", hr );
4853 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4854 SysFreeString(str);
4856 IXMLDOMComment_Release(pComment);
4859 /* Element */
4860 str = SysAllocString(szElement);
4861 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
4862 SysFreeString(str);
4863 ok(hr == S_OK, "ret %08x\n", hr );
4864 if(hr == S_OK)
4866 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4867 ok(hr == S_OK, "ret %08x\n", hr );
4869 /* test nodeTypeString */
4870 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
4871 ok(hr == S_OK, "ret %08x\n", hr );
4872 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
4873 SysFreeString(str);
4875 hr = IXMLDOMElement_get_nodeName(pElement, &str);
4876 ok(hr == S_OK, "ret %08x\n", hr );
4877 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
4878 SysFreeString(str);
4880 hr = IXMLDOMElement_get_xml(pElement, &str);
4881 ok(hr == S_OK, "ret %08x\n", hr );
4882 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
4883 SysFreeString(str);
4885 hr = IXMLDOMElement_get_dataType(pElement, &v);
4886 ok(hr == S_FALSE, "ret %08x\n", hr );
4887 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4888 VariantClear(&v);
4890 /* Attribute */
4891 pAttribute = (IXMLDOMAttribute*)0x1;
4892 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
4893 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4894 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
4896 pAttribute = (IXMLDOMAttribute*)0x1;
4897 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
4898 ok(hr == E_FAIL, "ret %08x\n", hr );
4899 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
4901 str = SysAllocString(szAttribute);
4902 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
4903 SysFreeString(str);
4904 ok(hr == S_OK, "ret %08x\n", hr );
4905 if(hr == S_OK)
4907 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
4909 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
4910 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4912 pNextChild = (IXMLDOMNode *)0x1;
4913 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
4914 ok(hr == S_FALSE, "ret %08x\n", hr );
4915 ok(pNextChild == NULL, "pNextChild not NULL\n");
4917 /* test Previous Sibling*/
4918 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
4919 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4921 pNextChild = (IXMLDOMNode *)0x1;
4922 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
4923 ok(hr == S_FALSE, "ret %08x\n", hr );
4924 ok(pNextChild == NULL, "pNextChild not NULL\n");
4926 /* test get_attributes */
4927 hr = IXMLDOMAttribute_get_attributes( pAttribute, NULL );
4928 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
4930 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4931 hr = IXMLDOMAttribute_get_attributes( pAttribute, &pAttribs);
4932 ok(hr == S_FALSE, "ret %08x\n", hr );
4933 ok( pAttribs == NULL, "pAttribs not NULL\n");
4935 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
4936 ok(hr == E_FAIL, "ret %08x\n", hr );
4937 ok(pNewChild == NULL, "pNewChild not NULL\n");
4939 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
4940 ok(hr == S_OK, "ret %08x\n", hr );
4941 if ( hr == S_OK )
4943 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
4944 ok(hr == S_OK, "ret %08x\n", hr );
4946 IXMLDOMNamedNodeMap_Release(pAttribs);
4949 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
4950 ok(hr == S_OK, "ret %08x\n", hr );
4951 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
4952 SysFreeString(str);
4954 /* test nodeTypeString */
4955 hr = IXMLDOMAttribute_get_nodeTypeString(pAttribute, &str);
4956 ok(hr == S_OK, "ret %08x\n", hr );
4957 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
4958 SysFreeString(str);
4960 /* test nodeName */
4961 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
4962 ok(hr == S_OK, "ret %08x\n", hr );
4963 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
4964 SysFreeString(str);
4966 /* test name property */
4967 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
4968 ok(hr == S_OK, "ret %08x\n", hr );
4969 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
4970 SysFreeString(str);
4972 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
4973 ok(hr == S_OK, "ret %08x\n", hr );
4974 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
4975 SysFreeString(str);
4977 hr = IXMLDOMAttribute_get_dataType(pAttribute, &v);
4978 ok(hr == S_FALSE, "ret %08x\n", hr );
4979 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4980 VariantClear(&v);
4982 IXMLDOMAttribute_Release(pAttribute);
4984 /* Check Element again with the Add Attribute*/
4985 hr = IXMLDOMElement_get_xml(pElement, &str);
4986 ok(hr == S_OK, "ret %08x\n", hr );
4987 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
4988 SysFreeString(str);
4991 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
4992 ok(hr == S_OK, "ret %08x\n", hr );
4994 hr = IXMLDOMElement_get_xml(pElement, &str);
4995 ok(hr == S_OK, "ret %08x\n", hr );
4996 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
4997 SysFreeString(str);
4999 /* Test for reversible escaping */
5000 str = SysAllocString( szStrangeChars );
5001 hr = IXMLDOMElement_put_text(pElement, str);
5002 ok(hr == S_OK, "ret %08x\n", hr );
5003 SysFreeString( str );
5005 hr = IXMLDOMElement_get_xml(pElement, &str);
5006 ok(hr == S_OK, "ret %08x\n", hr );
5007 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
5008 SysFreeString(str);
5010 hr = IXMLDOMElement_get_text(pElement, &str);
5011 ok(hr == S_OK, "ret %08x\n", hr );
5012 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
5013 SysFreeString(str);
5015 IXMLDOMElement_Release(pElement);
5018 /* CData Section */
5019 str = SysAllocString(szCData);
5020 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
5021 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5023 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
5024 SysFreeString(str);
5025 ok(hr == S_OK, "ret %08x\n", hr );
5026 if(hr == S_OK)
5028 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
5029 VARIANT var;
5031 VariantInit(&var);
5033 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
5034 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
5036 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
5037 ok(hr == S_OK, "ret %08x\n", hr );
5039 /* get Attribute Tests */
5040 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
5041 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5043 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
5044 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
5045 ok(hr == S_FALSE, "ret %08x\n", hr );
5046 ok(pAttribs == NULL, "pAttribs != NULL\n");
5048 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
5049 ok(hr == S_OK, "ret %08x\n", hr );
5050 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
5051 SysFreeString(str);
5053 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
5054 ok(hr == S_OK, "ret %08x\n", hr );
5055 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
5056 SysFreeString(str);
5058 /* test lastChild */
5059 pNextChild = (IXMLDOMNode*)0x1;
5060 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
5061 ok(hr == S_FALSE, "ret %08x\n", hr );
5062 ok(pNextChild == NULL, "pNextChild not NULL\n");
5064 /* test get_dataType */
5065 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
5066 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5068 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
5069 ok(hr == S_FALSE, "ret %08x\n", hr );
5070 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5071 VariantClear(&v);
5073 /* test nodeTypeString */
5074 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
5075 ok(hr == S_OK, "ret %08x\n", hr );
5076 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
5077 SysFreeString(str);
5079 /* put data Tests */
5080 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
5081 ok(hr == S_OK, "ret %08x\n", hr );
5083 /* Confirm XML text is good */
5084 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
5085 ok(hr == S_OK, "ret %08x\n", hr );
5086 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
5087 SysFreeString(str);
5089 /* Confirm we get the put_data Text back */
5090 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5091 ok(hr == S_OK, "ret %08x\n", hr );
5092 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5093 SysFreeString(str);
5095 /* test length property */
5096 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5097 ok(hr == S_OK, "ret %08x\n", hr );
5098 ok(len == 21, "expected 21 got %d\n", len);
5100 /* test get nodeValue */
5101 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
5102 ok(hr == S_OK, "ret %08x\n", hr );
5103 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
5104 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5105 VariantClear(&var);
5107 /* test get data */
5108 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
5109 ok(hr == S_OK, "ret %08x\n", hr );
5110 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
5111 SysFreeString(str);
5113 /* test substringData */
5114 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
5115 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5117 /* test substringData - Invalid offset */
5118 str = (BSTR)&szElement;
5119 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
5120 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5121 ok( str == NULL, "incorrect string\n");
5123 /* test substringData - Invalid offset */
5124 str = (BSTR)&szElement;
5125 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
5126 ok(hr == S_FALSE, "ret %08x\n", hr );
5127 ok( str == NULL, "incorrect string\n");
5129 /* test substringData - Invalid size */
5130 str = (BSTR)&szElement;
5131 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
5132 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5133 ok( str == NULL, "incorrect string\n");
5135 /* test substringData - Invalid size */
5136 str = (BSTR)&szElement;
5137 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
5138 ok(hr == S_FALSE, "ret %08x\n", hr );
5139 ok( str == NULL, "incorrect string\n");
5141 /* test substringData - Start of string */
5142 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
5143 ok(hr == S_OK, "ret %08x\n", hr );
5144 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
5145 SysFreeString(str);
5147 /* test substringData - Middle of string */
5148 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
5149 ok(hr == S_OK, "ret %08x\n", hr );
5150 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
5151 SysFreeString(str);
5153 /* test substringData - End of string */
5154 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
5155 ok(hr == S_OK, "ret %08x\n", hr );
5156 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
5157 SysFreeString(str);
5159 /* test appendData */
5160 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
5161 ok(hr == S_OK, "ret %08x\n", hr );
5163 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
5164 ok(hr == S_OK, "ret %08x\n", hr );
5166 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
5167 ok(hr == S_OK, "ret %08x\n", hr );
5169 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5170 ok(hr == S_OK, "ret %08x\n", hr );
5171 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5172 SysFreeString(str);
5174 /* test insertData */
5175 str = SysAllocStringLen(NULL, 0);
5176 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
5177 ok(hr == S_OK, "ret %08x\n", hr );
5179 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
5180 ok(hr == S_OK, "ret %08x\n", hr );
5182 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
5183 ok(hr == S_OK, "ret %08x\n", hr );
5185 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
5186 ok(hr == S_OK, "ret %08x\n", hr );
5188 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
5189 ok(hr == S_OK, "ret %08x\n", hr );
5191 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
5192 ok(hr == S_OK, "ret %08x\n", hr );
5193 SysFreeString(str);
5195 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
5196 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5198 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
5199 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5201 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
5202 ok(hr == S_OK, "ret %08x\n", hr );
5204 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
5205 ok(hr == S_OK, "ret %08x\n", hr );
5207 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
5208 ok(hr == S_OK, "ret %08x\n", hr );
5210 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5211 ok(hr == S_OK, "ret %08x\n", hr );
5212 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5213 SysFreeString(str);
5215 /* delete data */
5216 /* invalid arguments */
5217 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
5218 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5220 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
5221 ok(hr == S_OK, "ret %08x\n", hr );
5223 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
5224 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5226 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5227 ok(hr == S_OK, "ret %08x\n", hr );
5228 ok(len == 43, "expected 43 got %d\n", len);
5230 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
5231 ok(hr == S_OK, "ret %08x\n", hr );
5233 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
5234 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5236 /* delete from start */
5237 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
5238 ok(hr == S_OK, "ret %08x\n", hr );
5240 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5241 ok(hr == S_OK, "ret %08x\n", hr );
5242 ok(len == 38, "expected 38 got %d\n", len);
5244 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5245 ok(hr == S_OK, "ret %08x\n", hr );
5246 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5247 SysFreeString(str);
5249 /* delete from end */
5250 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
5251 ok(hr == S_OK, "ret %08x\n", hr );
5253 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5254 ok(hr == S_OK, "ret %08x\n", hr );
5255 ok(len == 35, "expected 35 got %d\n", len);
5257 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5258 ok(hr == S_OK, "ret %08x\n", hr );
5259 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5260 SysFreeString(str);
5262 /* delete from inside */
5263 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
5264 ok(hr == S_OK, "ret %08x\n", hr );
5266 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5267 ok(hr == S_OK, "ret %08x\n", hr );
5268 ok(len == 2, "expected 2 got %d\n", len);
5270 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5271 ok(hr == S_OK, "ret %08x\n", hr );
5272 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5273 SysFreeString(str);
5275 /* delete whole data ... */
5276 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
5277 ok(hr == S_OK, "ret %08x\n", hr );
5279 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
5280 ok(hr == S_OK, "ret %08x\n", hr );
5282 /* ... and try again with empty string */
5283 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
5284 ok(hr == S_OK, "ret %08x\n", hr );
5286 /* ::replaceData() */
5287 V_VT(&v) = VT_BSTR;
5288 V_BSTR(&v) = SysAllocString(szstr1);
5289 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
5290 ok(hr == S_OK, "ret %08x\n", hr );
5291 VariantClear(&v);
5293 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
5294 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5295 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5296 ok(hr == S_OK, "ret %08x\n", hr );
5297 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5298 SysFreeString(str);
5300 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
5301 ok(hr == S_OK, "ret %08x\n", hr );
5302 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5303 ok(hr == S_OK, "ret %08x\n", hr );
5304 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5305 SysFreeString(str);
5307 /* NULL pointer means delete */
5308 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
5309 ok(hr == S_OK, "ret %08x\n", hr );
5310 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5311 ok(hr == S_OK, "ret %08x\n", hr );
5312 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5313 SysFreeString(str);
5315 /* empty string means delete */
5316 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
5317 ok(hr == S_OK, "ret %08x\n", hr );
5318 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5319 ok(hr == S_OK, "ret %08x\n", hr );
5320 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5321 SysFreeString(str);
5323 /* zero count means insert */
5324 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
5325 ok(hr == S_OK, "ret %08x\n", hr );
5326 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5327 ok(hr == S_OK, "ret %08x\n", hr );
5328 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5329 SysFreeString(str);
5331 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
5332 ok(hr == S_OK, "ret %08x\n", hr );
5334 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
5335 ok(hr == S_OK, "ret %08x\n", hr );
5336 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5337 ok(hr == S_OK, "ret %08x\n", hr );
5338 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5339 SysFreeString(str);
5341 /* nonempty string, count greater than its length */
5342 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
5343 ok(hr == S_OK, "ret %08x\n", hr );
5344 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5345 ok(hr == S_OK, "ret %08x\n", hr );
5346 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5347 SysFreeString(str);
5349 /* nonempty string, count less than its length */
5350 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
5351 ok(hr == S_OK, "ret %08x\n", hr );
5352 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
5353 ok(hr == S_OK, "ret %08x\n", hr );
5354 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
5355 SysFreeString(str);
5357 IXMLDOMCDATASection_Release(pCDataSec);
5360 /* Document Fragments */
5361 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
5362 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5364 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
5365 ok(hr == S_OK, "ret %08x\n", hr );
5366 if(hr == S_OK)
5368 IXMLDOMNode *node;
5370 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
5371 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5373 node = (IXMLDOMNode *)0x1;
5374 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
5375 ok(hr == S_FALSE, "ret %08x\n", hr );
5376 ok(node == NULL, "expected NULL, got %p\n", node);
5378 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
5379 ok(hr == S_OK, "ret %08x\n", hr );
5381 /* get Attribute Tests */
5382 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
5383 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5385 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
5386 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
5387 ok(hr == S_FALSE, "ret %08x\n", hr );
5388 ok(pAttribs == NULL, "pAttribs != NULL\n");
5390 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
5391 ok(hr == S_OK, "ret %08x\n", hr );
5392 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
5393 SysFreeString(str);
5395 /* test next Sibling*/
5396 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
5397 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5399 node = (IXMLDOMNode *)0x1;
5400 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
5401 ok(hr == S_FALSE, "ret %08x\n", hr );
5402 ok(node == NULL, "next sibling not NULL\n");
5404 /* test Previous Sibling*/
5405 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
5406 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5408 node = (IXMLDOMNode *)0x1;
5409 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
5410 ok(hr == S_FALSE, "ret %08x\n", hr );
5411 ok(node == NULL, "previous sibling not NULL\n");
5413 /* test get_dataType */
5414 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
5415 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5417 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
5418 ok(hr == S_FALSE, "ret %08x\n", hr );
5419 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5420 VariantClear(&v);
5422 /* test nodeTypeString */
5423 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
5424 ok(hr == S_OK, "ret %08x\n", hr );
5425 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
5426 SysFreeString(str);
5428 IXMLDOMDocumentFragment_Release(pDocFrag);
5431 /* Entity References */
5432 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
5433 ok(hr == E_FAIL, "ret %08x\n", hr );
5434 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
5435 ok(hr == E_FAIL, "ret %08x\n", hr );
5437 str = SysAllocString(szEntityRef);
5438 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
5439 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5441 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
5442 SysFreeString(str);
5443 ok(hr == S_OK, "ret %08x\n", hr );
5444 if(hr == S_OK)
5446 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
5447 ok(hr == S_OK, "ret %08x\n", hr );
5449 /* get Attribute Tests */
5450 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
5451 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5453 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
5454 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
5455 ok(hr == S_FALSE, "ret %08x\n", hr );
5456 ok(pAttribs == NULL, "pAttribs != NULL\n");
5458 /* test dataType */
5459 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
5460 ok(hr == S_FALSE, "ret %08x\n", hr );
5461 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
5462 VariantClear(&v);
5464 /* test nodeTypeString */
5465 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
5466 ok(hr == S_OK, "ret %08x\n", hr );
5467 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
5468 SysFreeString(str);
5470 /* test get_xml*/
5471 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
5472 ok(hr == S_OK, "ret %08x\n", hr );
5473 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
5474 SysFreeString(str);
5476 IXMLDOMEntityReference_Release(pEntityRef);
5479 IXMLDOMElement_Release( pRoot );
5483 IXMLDOMDocument_Release(doc);
5485 free_bstrs();
5488 static void test_nodeTypeTests( void )
5490 IXMLDOMDocument *doc = NULL;
5491 IXMLDOMElement *pRoot;
5492 IXMLDOMElement *pElement;
5493 HRESULT hr;
5495 doc = create_document(&IID_IXMLDOMDocument);
5496 if (!doc) return;
5498 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
5499 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5501 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5502 ok(hr == S_OK, "ret %08x\n", hr );
5503 if(hr == S_OK)
5505 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5506 ok(hr == S_OK, "ret %08x\n", hr );
5507 if(hr == S_OK)
5509 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
5510 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5512 /* Invalid Value */
5513 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
5514 ok(hr == E_FAIL, "ret %08x\n", hr );
5516 /* NOTE:
5517 * The name passed into put_dataType is case-insensitive. So many of the names
5518 * have been changed to reflect this.
5520 /* Boolean */
5521 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
5522 ok(hr == S_OK, "ret %08x\n", hr );
5523 if(hr == S_OK)
5525 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5527 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
5528 ok(hr == S_OK, "ret %08x\n", hr );
5530 IXMLDOMElement_Release(pElement);
5533 /* String */
5534 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
5535 ok(hr == S_OK, "ret %08x\n", hr );
5536 if(hr == S_OK)
5538 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5540 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
5541 ok(hr == S_OK, "ret %08x\n", hr );
5543 IXMLDOMElement_Release(pElement);
5546 /* Number */
5547 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
5548 ok(hr == S_OK, "ret %08x\n", hr );
5549 if(hr == S_OK)
5551 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5553 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
5554 ok(hr == S_OK, "ret %08x\n", hr );
5556 IXMLDOMElement_Release(pElement);
5559 /* Int */
5560 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
5561 ok(hr == S_OK, "ret %08x\n", hr );
5562 if(hr == S_OK)
5564 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5566 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
5567 ok(hr == S_OK, "ret %08x\n", hr );
5569 IXMLDOMElement_Release(pElement);
5572 /* Fixed */
5573 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
5574 ok(hr == S_OK, "ret %08x\n", hr );
5575 if(hr == S_OK)
5577 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5579 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
5580 ok(hr == S_OK, "ret %08x\n", hr );
5582 IXMLDOMElement_Release(pElement);
5585 /* DateTime */
5586 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
5587 ok(hr == S_OK, "ret %08x\n", hr );
5588 if(hr == S_OK)
5590 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5592 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
5593 ok(hr == S_OK, "ret %08x\n", hr );
5595 IXMLDOMElement_Release(pElement);
5598 /* DateTime TZ */
5599 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
5600 ok(hr == S_OK, "ret %08x\n", hr );
5601 if(hr == S_OK)
5603 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5605 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
5606 ok(hr == S_OK, "ret %08x\n", hr );
5608 IXMLDOMElement_Release(pElement);
5611 /* Date */
5612 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
5613 ok(hr == S_OK, "ret %08x\n", hr );
5614 if(hr == S_OK)
5616 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5618 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
5619 ok(hr == S_OK, "ret %08x\n", hr );
5621 IXMLDOMElement_Release(pElement);
5624 /* Time */
5625 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
5626 ok(hr == S_OK, "ret %08x\n", hr );
5627 if(hr == S_OK)
5629 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5631 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
5632 ok(hr == S_OK, "ret %08x\n", hr );
5634 IXMLDOMElement_Release(pElement);
5637 /* Time.tz */
5638 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
5639 ok(hr == S_OK, "ret %08x\n", hr );
5640 if(hr == S_OK)
5642 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5644 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
5645 ok(hr == S_OK, "ret %08x\n", hr );
5647 IXMLDOMElement_Release(pElement);
5650 /* I1 */
5651 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
5652 ok(hr == S_OK, "ret %08x\n", hr );
5653 if(hr == S_OK)
5655 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5657 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
5658 ok(hr == S_OK, "ret %08x\n", hr );
5660 IXMLDOMElement_Release(pElement);
5663 /* I2 */
5664 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
5665 ok(hr == S_OK, "ret %08x\n", hr );
5666 if(hr == S_OK)
5668 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5670 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
5671 ok(hr == S_OK, "ret %08x\n", hr );
5673 IXMLDOMElement_Release(pElement);
5676 /* I4 */
5677 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
5678 ok(hr == S_OK, "ret %08x\n", hr );
5679 if(hr == S_OK)
5681 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5683 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
5684 ok(hr == S_OK, "ret %08x\n", hr );
5686 IXMLDOMElement_Release(pElement);
5689 /* UI1 */
5690 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
5691 ok(hr == S_OK, "ret %08x\n", hr );
5692 if(hr == S_OK)
5694 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5696 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
5697 ok(hr == S_OK, "ret %08x\n", hr );
5699 IXMLDOMElement_Release(pElement);
5702 /* UI2 */
5703 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
5704 ok(hr == S_OK, "ret %08x\n", hr );
5705 if(hr == S_OK)
5707 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5709 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
5710 ok(hr == S_OK, "ret %08x\n", hr );
5712 IXMLDOMElement_Release(pElement);
5715 /* UI4 */
5716 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
5717 ok(hr == S_OK, "ret %08x\n", hr );
5718 if(hr == S_OK)
5720 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5722 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
5723 ok(hr == S_OK, "ret %08x\n", hr );
5725 IXMLDOMElement_Release(pElement);
5728 /* r4 */
5729 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
5730 ok(hr == S_OK, "ret %08x\n", hr );
5731 if(hr == S_OK)
5733 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5735 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
5736 ok(hr == S_OK, "ret %08x\n", hr );
5738 IXMLDOMElement_Release(pElement);
5741 /* r8 */
5742 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
5743 ok(hr == S_OK, "ret %08x\n", hr );
5744 if(hr == S_OK)
5746 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5748 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
5749 ok(hr == S_OK, "ret %08x\n", hr );
5751 IXMLDOMElement_Release(pElement);
5754 /* float */
5755 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
5756 ok(hr == S_OK, "ret %08x\n", hr );
5757 if(hr == S_OK)
5759 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5761 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
5762 ok(hr == S_OK, "ret %08x\n", hr );
5764 IXMLDOMElement_Release(pElement);
5767 /* uuid */
5768 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
5769 ok(hr == S_OK, "ret %08x\n", hr );
5770 if(hr == S_OK)
5772 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5774 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
5775 ok(hr == S_OK, "ret %08x\n", hr );
5777 IXMLDOMElement_Release(pElement);
5780 /* bin.hex */
5781 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
5782 ok(hr == S_OK, "ret %08x\n", hr );
5783 if(hr == S_OK)
5785 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5787 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
5788 ok(hr == S_OK, "ret %08x\n", hr );
5790 IXMLDOMElement_Release(pElement);
5793 /* bin.base64 */
5794 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
5795 ok(hr == S_OK, "ret %08x\n", hr );
5796 if(hr == S_OK)
5798 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5800 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
5801 ok(hr == S_OK, "ret %08x\n", hr );
5803 IXMLDOMElement_Release(pElement);
5806 /* Check changing types */
5807 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
5808 ok(hr == S_OK, "ret %08x\n", hr );
5809 if(hr == S_OK)
5811 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
5813 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
5814 ok(hr == S_OK, "ret %08x\n", hr );
5816 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
5817 ok(hr == S_OK, "ret %08x\n", hr );
5819 IXMLDOMElement_Release(pElement);
5822 IXMLDOMElement_Release(pRoot);
5826 IXMLDOMDocument_Release(doc);
5828 free_bstrs();
5831 static void test_DocumentSaveToDocument(void)
5833 IXMLDOMDocument *doc, *doc2;
5834 IXMLDOMElement *pRoot;
5835 HRESULT hr;
5837 doc = create_document(&IID_IXMLDOMDocument);
5838 if (!doc) return;
5840 doc2 = create_document(&IID_IXMLDOMDocument);
5841 if (!doc2)
5843 IXMLDOMDocument_Release(doc);
5844 return;
5847 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5848 ok(hr == S_OK, "ret %08x\n", hr );
5849 if(hr == S_OK)
5851 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5852 ok(hr == S_OK, "ret %08x\n", hr );
5853 if(hr == S_OK)
5855 VARIANT vDoc;
5856 BSTR sOrig;
5857 BSTR sNew;
5859 V_VT(&vDoc) = VT_UNKNOWN;
5860 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
5862 hr = IXMLDOMDocument_save(doc, vDoc);
5863 ok(hr == S_OK, "ret %08x\n", hr );
5865 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
5866 ok(hr == S_OK, "ret %08x\n", hr );
5868 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
5869 ok(hr == S_OK, "ret %08x\n", hr );
5871 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
5873 SysFreeString(sOrig);
5874 SysFreeString(sNew);
5878 IXMLDOMDocument_Release(doc2);
5879 IXMLDOMDocument_Release(doc);
5882 static void test_DocumentSaveToFile(void)
5884 IXMLDOMDocument *doc;
5885 IXMLDOMElement *pRoot;
5886 HANDLE file;
5887 char buffer[100];
5888 DWORD read = 0;
5889 HRESULT hr;
5891 doc = create_document(&IID_IXMLDOMDocument);
5892 if (!doc) return;
5894 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
5895 ok(hr == S_OK, "ret %08x\n", hr );
5896 if(hr == S_OK)
5898 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
5899 ok(hr == S_OK, "ret %08x\n", hr );
5900 if(hr == S_OK)
5902 VARIANT vFile;
5904 V_VT(&vFile) = VT_BSTR;
5905 V_BSTR(&vFile) = _bstr_("test.xml");
5907 hr = IXMLDOMDocument_save(doc, vFile);
5908 ok(hr == S_OK, "ret %08x\n", hr );
5912 IXMLDOMElement_Release(pRoot);
5913 IXMLDOMDocument_Release(doc);
5915 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
5916 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
5917 if(file == INVALID_HANDLE_VALUE)
5918 return;
5920 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
5921 ok(read != 0, "could not read file\n");
5922 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
5924 CloseHandle(file);
5925 DeleteFile("test.xml");
5928 static void test_testTransforms(void)
5930 IXMLDOMDocument *doc, *docSS;
5931 IXMLDOMNode *pNode;
5932 VARIANT_BOOL bSucc;
5934 HRESULT hr;
5936 doc = create_document(&IID_IXMLDOMDocument);
5937 if (!doc) return;
5939 docSS = create_document(&IID_IXMLDOMDocument);
5940 if (!docSS)
5942 IXMLDOMDocument_Release(doc);
5943 return;
5946 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
5947 ok(hr == S_OK, "ret %08x\n", hr );
5949 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
5950 ok(hr == S_OK, "ret %08x\n", hr );
5952 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
5953 ok(hr == S_OK, "ret %08x\n", hr );
5954 if(hr == S_OK)
5956 BSTR bOut;
5958 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
5959 ok(hr == S_OK, "ret %08x\n", hr );
5960 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
5961 SysFreeString(bOut);
5963 IXMLDOMNode_Release(pNode);
5966 IXMLDOMDocument_Release(docSS);
5967 IXMLDOMDocument_Release(doc);
5969 free_bstrs();
5972 static void test_Namespaces(void)
5974 IXMLDOMDocument *doc;
5975 IXMLDOMNode *pNode;
5976 IXMLDOMNode *pNode2 = NULL;
5977 VARIANT_BOOL bSucc;
5978 HRESULT hr;
5979 BSTR str;
5980 static const CHAR szNamespacesXML[] =
5981 "<?xml version=\"1.0\"?>\n"
5982 "<root xmlns:WEB='http://www.winehq.org'>\n"
5983 "<WEB:Site version=\"1.0\" />\n"
5984 "</root>";
5986 doc = create_document(&IID_IXMLDOMDocument);
5987 if (!doc) return;
5989 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
5990 ok(hr == S_OK, "ret %08x\n", hr );
5991 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
5993 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
5994 ok(hr == S_OK, "ret %08x\n", hr );
5995 if(hr == S_OK)
5997 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
5998 ok( hr == S_OK, "ret %08x\n", hr );
5999 ok( pNode2 != NULL, "pNode2 == NULL\n");
6001 /* Test get_prefix */
6002 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
6003 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
6004 /* NOTE: Need to test that arg2 gets cleared on Error. */
6006 hr = IXMLDOMNode_get_prefix(pNode2, &str);
6007 ok( hr == S_OK, "ret %08x\n", hr );
6008 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
6009 SysFreeString(str);
6011 /* Test get_namespaceURI */
6012 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
6013 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
6014 /* NOTE: Need to test that arg2 gets cleared on Error. */
6016 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
6017 ok( hr == S_OK, "ret %08x\n", hr );
6018 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
6019 SysFreeString(str);
6021 IXMLDOMNode_Release(pNode2);
6022 IXMLDOMNode_Release(pNode);
6025 IXMLDOMDocument_Release(doc);
6027 free_bstrs();
6030 static void test_FormattingXML(void)
6032 IXMLDOMDocument *doc;
6033 IXMLDOMElement *pElement;
6034 VARIANT_BOOL bSucc;
6035 HRESULT hr;
6036 BSTR str;
6037 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
6038 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
6040 doc = create_document(&IID_IXMLDOMDocument);
6041 if (!doc) return;
6043 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
6044 ok(hr == S_OK, "ret %08x\n", hr );
6045 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6047 if(bSucc == VARIANT_TRUE)
6049 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
6050 ok(hr == S_OK, "ret %08x\n", hr );
6051 if(hr == S_OK)
6053 hr = IXMLDOMElement_get_xml(pElement, &str);
6054 ok(hr == S_OK, "ret %08x\n", hr );
6055 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
6056 SysFreeString(str);
6058 IXMLDOMElement_Release(pElement);
6062 IXMLDOMDocument_Release(doc);
6064 free_bstrs();
6067 typedef struct _nodetypedvalue_t {
6068 const char *name;
6069 VARTYPE type;
6070 const char *value; /* value in string format */
6071 } nodetypedvalue_t;
6073 static const nodetypedvalue_t get_nodetypedvalue[] = {
6074 { "root/string", VT_BSTR, "Wine" },
6075 { "root/string2", VT_BSTR, "String" },
6076 { "root/number", VT_BSTR, "12.44" },
6077 { "root/number2", VT_BSTR, "-3.71e3" },
6078 { "root/int", VT_I4, "-13" },
6079 { "root/fixed", VT_CY, "7322.9371" },
6080 { "root/bool", VT_BOOL, "-1" },
6081 { "root/datetime", VT_DATE, "40135.14" },
6082 { "root/datetimetz",VT_DATE, "37813.59" },
6083 { "root/date", VT_DATE, "665413" },
6084 { "root/time", VT_DATE, "0.5813889" },
6085 { "root/timetz", VT_DATE, "1.112512" },
6086 { "root/i1", VT_I1, "-13" },
6087 { "root/i2", VT_I2, "31915" },
6088 { "root/i4", VT_I4, "-312232" },
6089 { "root/ui1", VT_UI1, "123" },
6090 { "root/ui2", VT_UI2, "48282" },
6091 { "root/ui4", VT_UI4, "949281" },
6092 { "root/r4", VT_R4, "213124" },
6093 { "root/r8", VT_R8, "0.412" },
6094 { "root/float", VT_R8, "41221.421" },
6095 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
6096 { 0 }
6099 static void test_nodeTypedValue(void)
6101 const nodetypedvalue_t *entry = get_nodetypedvalue;
6102 IXMLDOMDocument *doc;
6103 IXMLDOMNode *node;
6104 VARIANT_BOOL b;
6105 VARIANT value;
6106 HRESULT hr;
6108 doc = create_document(&IID_IXMLDOMDocument);
6109 if (!doc) return;
6111 b = VARIANT_FALSE;
6112 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
6113 ok(hr == S_OK, "ret %08x\n", hr );
6114 ok(b == VARIANT_TRUE, "got %d\n", b);
6116 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
6117 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6119 V_VT(&value) = VT_BSTR;
6120 V_BSTR(&value) = NULL;
6121 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
6122 ok(hr == S_FALSE, "ret %08x\n", hr );
6123 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
6125 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
6126 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6128 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
6129 ok(hr == S_FALSE, "ret %08x\n", hr );
6131 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
6132 ok(hr == S_OK, "ret %08x\n", hr );
6134 V_VT(&value) = VT_BSTR;
6135 V_BSTR(&value) = NULL;
6136 hr = IXMLDOMNode_get_nodeValue(node, &value);
6137 ok(hr == S_FALSE, "ret %08x\n", hr );
6138 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
6140 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
6141 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
6143 IXMLDOMNode_Release(node);
6145 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
6146 ok(hr == S_OK, "ret %08x\n", hr );
6148 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
6150 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6151 ok(hr == S_OK, "ret %08x\n", hr );
6152 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
6153 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
6154 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
6155 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
6156 VariantClear(&value);
6157 IXMLDOMNode_Release(node);
6160 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binbase64"), &node);
6161 ok(hr == S_OK, "ret %08x\n", hr );
6163 BYTE bytes[] = {0x62,0x61,0x73,0x65,0x36,0x34,0x20,0x74,0x65,0x73,0x74};
6165 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6166 ok(hr == S_OK, "ret %08x\n", hr );
6167 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
6168 ok(V_ARRAY(&value)->rgsabound[0].cElements == 11, "incorrect array size\n");
6169 if(V_ARRAY(&value)->rgsabound[0].cElements == 11)
6170 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
6171 VariantClear(&value);
6172 IXMLDOMNode_Release(node);
6175 while (entry->name)
6177 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
6178 ok(hr == S_OK, "ret %08x\n", hr );
6180 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
6181 ok(hr == S_OK, "ret %08x\n", hr );
6182 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
6184 if (entry->type != VT_BSTR)
6186 if (entry->type == VT_DATE ||
6187 entry->type == VT_R8 ||
6188 entry->type == VT_CY)
6190 if (entry->type == VT_DATE)
6192 hr = VariantChangeType(&value, &value, 0, VT_R4);
6193 ok(hr == S_OK, "ret %08x\n", hr );
6195 hr = VariantChangeTypeEx(&value, &value,
6196 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
6197 VARIANT_NOUSEROVERRIDE, VT_BSTR);
6198 ok(hr == S_OK, "ret %08x\n", hr );
6200 else
6202 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
6203 ok(hr == S_OK, "ret %08x\n", hr );
6206 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
6207 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
6209 else
6210 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
6211 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
6213 VariantClear( &value );
6214 IXMLDOMNode_Release(node);
6216 entry++;
6219 IXMLDOMDocument_Release(doc);
6220 free_bstrs();
6223 static void test_TransformWithLoadingLocalFile(void)
6225 IXMLDOMDocument *doc;
6226 IXMLDOMDocument *xsl;
6227 IXMLDOMNode *pNode;
6228 VARIANT_BOOL bSucc;
6229 HRESULT hr;
6230 HANDLE file;
6231 DWORD dwWritten;
6232 char lpPathBuffer[MAX_PATH];
6233 int i;
6235 /* Create a Temp File. */
6236 GetTempPathA(MAX_PATH, lpPathBuffer);
6237 strcat(lpPathBuffer, "customers.xml" );
6239 file = CreateFile(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
6240 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
6241 if(file == INVALID_HANDLE_VALUE)
6242 return;
6244 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
6245 CloseHandle(file);
6247 /* Correct path to not include a escape character. */
6248 for(i=0; i < strlen(lpPathBuffer); i++)
6250 if(lpPathBuffer[i] == '\\')
6251 lpPathBuffer[i] = '/';
6254 doc = create_document(&IID_IXMLDOMDocument);
6255 if (!doc) return;
6257 xsl = create_document(&IID_IXMLDOMDocument);
6258 if (!xsl)
6260 IXMLDOMDocument2_Release(doc);
6261 return;
6264 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
6265 ok(hr == S_OK, "ret %08x\n", hr );
6266 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6267 if(bSucc == VARIANT_TRUE)
6269 BSTR sXSL;
6270 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
6271 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
6272 BSTR sFileName = _bstr_(lpPathBuffer);
6273 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
6275 sXSL = SysAllocStringLen(NULL, nLegnth);
6276 lstrcpyW(sXSL, sPart1);
6277 lstrcatW(sXSL, sFileName);
6278 lstrcatW(sXSL, sPart2);
6280 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
6281 ok(hr == S_OK, "ret %08x\n", hr );
6282 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
6283 if(bSucc == VARIANT_TRUE)
6285 BSTR sResult;
6287 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
6288 ok(hr == S_OK, "ret %08x\n", hr );
6289 if(hr == S_OK)
6291 /* This will load the temp file via the XSL */
6292 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
6293 ok(hr == S_OK, "ret %08x\n", hr );
6294 if(hr == S_OK)
6296 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
6297 SysFreeString(sResult);
6300 IXMLDOMNode_Release(pNode);
6304 SysFreeString(sXSL);
6307 IXMLDOMDocument_Release(doc);
6308 IXMLDOMDocument_Release(xsl);
6310 DeleteFile(lpPathBuffer);
6311 free_bstrs();
6314 static void test_put_nodeValue(void)
6316 static const WCHAR jeevesW[] = {'J','e','e','v','e','s',' ','&',' ','W','o','o','s','t','e','r',0};
6317 IXMLDOMDocument *doc;
6318 IXMLDOMText *text;
6319 IXMLDOMEntityReference *entityref;
6320 IXMLDOMAttribute *attr;
6321 IXMLDOMNode *node;
6322 HRESULT hr;
6323 VARIANT data, type;
6325 doc = create_document(&IID_IXMLDOMDocument);
6326 if (!doc) return;
6328 /* test for unsupported types */
6329 /* NODE_DOCUMENT */
6330 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
6331 ok(hr == S_OK, "ret %08x\n", hr );
6332 V_VT(&data) = VT_BSTR;
6333 V_BSTR(&data) = _bstr_("one two three");
6334 hr = IXMLDOMNode_put_nodeValue(node, data);
6335 ok(hr == E_FAIL, "ret %08x\n", hr );
6336 IXMLDOMNode_Release(node);
6338 /* NODE_DOCUMENT_FRAGMENT */
6339 V_VT(&type) = VT_I1;
6340 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
6341 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
6342 ok(hr == S_OK, "ret %08x\n", hr );
6343 V_VT(&data) = VT_BSTR;
6344 V_BSTR(&data) = _bstr_("one two three");
6345 hr = IXMLDOMNode_put_nodeValue(node, data);
6346 ok(hr == E_FAIL, "ret %08x\n", hr );
6347 IXMLDOMNode_Release(node);
6349 /* NODE_ELEMENT */
6350 V_VT(&type) = VT_I1;
6351 V_I1(&type) = NODE_ELEMENT;
6352 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
6353 ok(hr == S_OK, "ret %08x\n", hr );
6354 V_VT(&data) = VT_BSTR;
6355 V_BSTR(&data) = _bstr_("one two three");
6356 hr = IXMLDOMNode_put_nodeValue(node, data);
6357 ok(hr == E_FAIL, "ret %08x\n", hr );
6358 IXMLDOMNode_Release(node);
6360 /* NODE_ENTITY_REFERENCE */
6361 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
6362 ok(hr == S_OK, "ret %08x\n", hr );
6364 V_VT(&data) = VT_BSTR;
6365 V_BSTR(&data) = _bstr_("one two three");
6366 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
6367 ok(hr == E_FAIL, "ret %08x\n", hr );
6369 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
6370 ok(hr == S_OK, "ret %08x\n", hr );
6371 V_VT(&data) = VT_BSTR;
6372 V_BSTR(&data) = _bstr_("one two three");
6373 hr = IXMLDOMNode_put_nodeValue(node, data);
6374 ok(hr == E_FAIL, "ret %08x\n", hr );
6375 IXMLDOMNode_Release(node);
6376 IXMLDOMEntityReference_Release(entityref);
6378 /* supported types */
6379 hr = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &text);
6380 ok(hr == S_OK, "ret %08x\n", hr );
6381 V_VT(&data) = VT_BSTR;
6382 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
6383 hr = IXMLDOMText_put_nodeValue(text, data);
6384 ok(hr == S_OK, "ret %08x\n", hr );
6385 IXMLDOMText_Release(text);
6387 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
6388 ok(hr == S_OK, "ret %08x\n", hr );
6389 V_VT(&data) = VT_BSTR;
6390 V_BSTR(&data) = _bstr_("Jeeves & Wooster");
6391 hr = IXMLDOMAttribute_put_nodeValue(attr, data);
6392 ok(hr == S_OK, "ret %08x\n", hr );
6393 hr = IXMLDOMAttribute_get_nodeValue(attr, &data);
6394 ok(hr == S_OK, "ret %08x\n", hr );
6395 ok(memcmp(V_BSTR(&data), jeevesW, sizeof(jeevesW)) == 0, "got %s\n",
6396 wine_dbgstr_w(V_BSTR(&data)));
6397 VariantClear(&data);
6398 IXMLDOMAttribute_Release(attr);
6400 free_bstrs();
6402 IXMLDOMDocument_Release(doc);
6405 static void test_IObjectSafety_set(IObjectSafety *safety, HRESULT result, HRESULT result2, DWORD set, DWORD mask, DWORD expected, DWORD expected2)
6407 DWORD enabled, supported;
6408 HRESULT hr;
6410 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL, set, mask);
6411 if (result == result2)
6412 ok(hr == result, "SetInterfaceSafetyOptions: expected %08x, returned %08x\n", result, hr );
6413 else
6414 ok(broken(hr == result) || hr == result2,
6415 "SetInterfaceSafetyOptions: expected %08x, got %08x\n", result2, hr );
6417 supported = enabled = 0xCAFECAFE;
6418 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
6419 ok(hr == S_OK, "ret %08x\n", hr );
6420 if (expected == expected2)
6421 ok(enabled == expected, "Expected %08x, got %08x\n", expected, enabled);
6422 else
6423 ok(broken(enabled == expected) || enabled == expected2,
6424 "Expected %08x, got %08x\n", expected2, enabled);
6426 /* reset the safety options */
6428 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
6429 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER,
6431 ok(hr == S_OK, "ret %08x\n", hr );
6433 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
6434 ok(hr == S_OK, "ret %08x\n", hr );
6435 ok(enabled == 0, "Expected 0, got %08x\n", enabled);
6438 static void test_document_IObjectSafety(void)
6440 IXMLDOMDocument *doc;
6441 IObjectSafety *safety;
6442 DWORD enabled = 0, supported = 0;
6443 HRESULT hr;
6445 doc = create_document(&IID_IXMLDOMDocument);
6446 if (!doc) return;
6448 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
6449 ok(hr == S_OK, "ret %08x\n", hr );
6451 /* get */
6452 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, NULL, &enabled);
6453 ok(hr == E_POINTER, "ret %08x\n", hr );
6454 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, NULL);
6455 ok(hr == E_POINTER, "ret %08x\n", hr );
6457 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
6458 ok(hr == S_OK, "ret %08x\n", hr );
6459 ok(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
6460 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
6461 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
6462 "got %08x\n", supported);
6463 ok(enabled == 0, "Expected 0, got %08x\n", enabled);
6465 /* set -- individual flags */
6467 test_IObjectSafety_set(safety, S_OK, S_OK,
6468 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER,
6469 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER);
6471 test_IObjectSafety_set(safety, S_OK, S_OK,
6472 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA,
6473 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
6475 test_IObjectSafety_set(safety, S_OK, S_OK,
6476 INTERFACE_USES_SECURITY_MANAGER, INTERFACE_USES_SECURITY_MANAGER,
6477 0, INTERFACE_USES_SECURITY_MANAGER /* msxml3 SP8+ */);
6479 /* set INTERFACE_USES_DISPEX */
6481 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
6482 INTERFACE_USES_DISPEX, INTERFACE_USES_DISPEX,
6483 0, 0);
6485 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
6486 INTERFACE_USES_DISPEX, 0,
6487 0, 0);
6489 test_IObjectSafety_set(safety, S_OK, S_OK /* msxml3 SP8+ */,
6490 0, INTERFACE_USES_DISPEX,
6491 0, 0);
6493 /* set option masking */
6495 test_IObjectSafety_set(safety, S_OK, S_OK,
6496 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
6497 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
6498 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
6499 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
6501 test_IObjectSafety_set(safety, S_OK, S_OK,
6502 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
6503 INTERFACESAFE_FOR_UNTRUSTED_DATA,
6504 INTERFACESAFE_FOR_UNTRUSTED_DATA,
6505 INTERFACESAFE_FOR_UNTRUSTED_DATA);
6507 test_IObjectSafety_set(safety, S_OK, S_OK,
6508 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
6509 INTERFACE_USES_SECURITY_MANAGER,
6513 /* set -- inheriting previous settings */
6515 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
6516 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
6517 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
6518 ok(hr == S_OK, "ret %08x\n", hr );
6519 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
6520 ok(hr == S_OK, "ret %08x\n", hr );
6521 todo_wine
6522 ok(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_CALLER) ||
6523 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
6524 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER), "
6525 "got %08x\n", enabled);
6527 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
6528 INTERFACESAFE_FOR_UNTRUSTED_DATA,
6529 INTERFACESAFE_FOR_UNTRUSTED_DATA);
6530 ok(hr == S_OK, "ret %08x\n", hr );
6531 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
6532 ok(hr == S_OK, "ret %08x\n", hr );
6533 todo_wine
6534 ok(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_DATA) ||
6535 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA) /* msxml3 SP8+ */,
6536 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA), "
6537 "got %08x\n", enabled);
6539 IObjectSafety_Release(safety);
6541 IXMLDOMDocument_Release(doc);
6544 typedef struct _property_test_t {
6545 const GUID *guid;
6546 const char *clsid;
6547 const char *property;
6548 const char *value;
6549 } property_test_t;
6551 static const property_test_t properties_test_data[] = {
6552 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
6553 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
6554 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
6555 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
6556 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
6557 { 0 }
6560 static void test_default_properties(void)
6562 const property_test_t *entry = properties_test_data;
6563 IXMLDOMDocument2 *doc;
6564 VARIANT var;
6565 HRESULT hr;
6567 while (entry->guid)
6569 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
6570 if (hr != S_OK)
6572 win_skip("can't create %s instance\n", entry->clsid);
6573 entry++;
6574 continue;
6577 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
6578 ok(hr == S_OK, "got 0x%08x\n", hr);
6579 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
6580 entry->value, entry->clsid);
6581 VariantClear(&var);
6583 IXMLDOMDocument2_Release(doc);
6585 entry++;
6589 static void test_XSLPattern(void)
6591 IXMLDOMDocument2 *doc;
6592 IXMLDOMNodeList *list;
6593 VARIANT_BOOL b;
6594 LONG len;
6596 doc = create_document(&IID_IXMLDOMDocument2);
6597 if (!doc) return;
6599 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
6600 ok(b == VARIANT_TRUE, "failed to load XML string\n");
6602 /* switch to XSLPattern */
6603 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
6605 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
6606 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list));
6607 len = 0;
6608 ole_check(IXMLDOMNodeList_get_length(list, &len));
6609 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
6610 ok(len == 3, "expected 3 entries in list, got %d\n", len);
6611 IXMLDOMNodeList_Release(list);
6613 /* for XSLPattern start index is 0, for XPath it's 1 */
6614 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
6615 len = 0;
6616 ole_check(IXMLDOMNodeList_get_length(list, &len));
6617 ok(len != 0, "expected filled list\n");
6618 if (len)
6619 expect_list_and_release(list, "E1.E2.D1");
6621 /* index() */
6622 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=1]"), &list));
6623 len = 0;
6624 ole_check(IXMLDOMNodeList_get_length(list, &len));
6625 ok(len != 0, "expected filled list\n");
6626 if (len)
6627 expect_list_and_release(list, "E2.E2.D1");
6629 /* $eq$ */
6630 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $eq$ 1]"), &list));
6631 len = 0;
6632 ole_check(IXMLDOMNodeList_get_length(list, &len));
6633 ok(len != 0, "expected filled list\n");
6634 if (len)
6635 expect_list_and_release(list, "E2.E2.D1");
6637 /* end() */
6638 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[end()]"), &list));
6639 len = 0;
6640 ole_check(IXMLDOMNodeList_get_length(list, &len));
6641 ok(len != 0, "expected filled list\n");
6642 if (len)
6643 expect_list_and_release(list, "E4.E2.D1");
6645 /* $not$ */
6646 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$not$ end()]"), &list));
6647 len = 0;
6648 ole_check(IXMLDOMNodeList_get_length(list, &len));
6649 ok(len != 0, "expected filled list\n");
6650 if (len)
6651 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
6653 /* !=/$ne$ */
6654 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() != 0]"), &list));
6655 len = 0;
6656 ole_check(IXMLDOMNodeList_get_length(list, &len));
6657 ok(len != 0, "expected filled list\n");
6658 if (len)
6659 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
6660 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ne$ 0]"), &list));
6661 len = 0;
6662 ole_check(IXMLDOMNodeList_get_length(list, &len));
6663 ok(len != 0, "expected filled list\n");
6664 if (len)
6665 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1 E4.E2.D1");
6667 /* </$lt$ */
6668 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() < 2]"), &list));
6669 len = 0;
6670 ole_check(IXMLDOMNodeList_get_length(list, &len));
6671 ok(len != 0, "expected filled list\n");
6672 if (len)
6673 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6674 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $lt$ 2]"), &list));
6675 len = 0;
6676 ole_check(IXMLDOMNodeList_get_length(list, &len));
6677 ok(len != 0, "expected filled list\n");
6678 if (len)
6679 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6681 /* <=/$le$ */
6682 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() <= 1]"), &list));
6683 len = 0;
6684 ole_check(IXMLDOMNodeList_get_length(list, &len));
6685 ok(len != 0, "expected filled list\n");
6686 if (len)
6687 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6688 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $le$ 1]"), &list));
6689 len = 0;
6690 ole_check(IXMLDOMNodeList_get_length(list, &len));
6691 ok(len != 0, "expected filled list\n");
6692 if (len)
6693 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6695 /* >/$gt$ */
6696 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() > 1]"), &list));
6697 len = 0;
6698 ole_check(IXMLDOMNodeList_get_length(list, &len));
6699 ok(len != 0, "expected filled list\n");
6700 if (len)
6701 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6702 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $gt$ 1]"), &list));
6703 len = 0;
6704 ole_check(IXMLDOMNodeList_get_length(list, &len));
6705 ok(len != 0, "expected filled list\n");
6706 if (len)
6707 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6709 /* >=/$ge$ */
6710 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() >= 2]"), &list));
6711 len = 0;
6712 ole_check(IXMLDOMNodeList_get_length(list, &len));
6713 ok(len != 0, "expected filled list\n");
6714 if (len)
6715 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6716 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index() $ge$ 2]"), &list));
6717 len = 0;
6718 ole_check(IXMLDOMNodeList_get_length(list, &len));
6719 ok(len != 0, "expected filled list\n");
6720 if (len)
6721 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6723 /* $ieq$ */
6724 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ieq$ 'a2 field']"), &list));
6725 len = 0;
6726 ole_check(IXMLDOMNodeList_get_length(list, &len));
6727 ok(len != 0, "expected filled list\n");
6728 if (len)
6729 expect_list_and_release(list, "E2.E2.D1");
6731 /* $ine$ */
6732 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ine$ 'a2 field']"), &list));
6733 len = 0;
6734 ole_check(IXMLDOMNodeList_get_length(list, &len));
6735 ok(len != 0, "expected filled list\n");
6736 if (len)
6737 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
6739 /* $ilt$ */
6740 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ilt$ 'a3 field']"), &list));
6741 len = 0;
6742 ole_check(IXMLDOMNodeList_get_length(list, &len));
6743 ok(len != 0, "expected filled list\n");
6744 if (len)
6745 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6747 /* $ile$ */
6748 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ile$ 'a2 field']"), &list));
6749 len = 0;
6750 ole_check(IXMLDOMNodeList_get_length(list, &len));
6751 ok(len != 0, "expected filled list\n");
6752 if (len)
6753 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1");
6755 /* $igt$ */
6756 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $igt$ 'a2 field']"), &list));
6757 len = 0;
6758 ole_check(IXMLDOMNodeList_get_length(list, &len));
6759 ok(len != 0, "expected filled list\n");
6760 if (len)
6761 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6763 /* $ige$ */
6764 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[a $ige$ 'a3 field']"), &list));
6765 len = 0;
6766 ole_check(IXMLDOMNodeList_get_length(list, &len));
6767 ok(len != 0, "expected filled list\n");
6768 if (len)
6769 expect_list_and_release(list, "E3.E2.D1 E4.E2.D1");
6771 /* $any$ */
6772 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$any$ *='B2 field']"), &list));
6773 len = 0;
6774 ole_check(IXMLDOMNodeList_get_length(list, &len));
6775 ok(len != 0, "expected filled list\n");
6776 if (len)
6777 expect_list_and_release(list, "E2.E2.D1");
6779 /* $all$ */
6780 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[$all$ *!='B2 field']"), &list));
6781 len = 0;
6782 ole_check(IXMLDOMNodeList_get_length(list, &len));
6783 ok(len != 0, "expected filled list\n");
6784 if (len)
6785 expect_list_and_release(list, "E1.E2.D1 E3.E2.D1 E4.E2.D1");
6787 /* or/$or$/|| */
6788 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 or end()]"), &list));
6789 len = 0;
6790 ole_check(IXMLDOMNodeList_get_length(list, &len));
6791 ok(len != 0, "expected filled list\n");
6792 if (len)
6793 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
6794 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 $or$ end()]"), &list));
6795 len = 0;
6796 ole_check(IXMLDOMNodeList_get_length(list, &len));
6797 ok(len != 0, "expected filled list\n");
6798 if (len)
6799 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
6800 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()=0 || end()]"), &list));
6801 len = 0;
6802 ole_check(IXMLDOMNodeList_get_length(list, &len));
6803 ok(len != 0, "expected filled list\n");
6804 if (len)
6805 expect_list_and_release(list, "E1.E2.D1 E4.E2.D1");
6807 /* and/$and$/&& */
6808 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 and $not$ end()]"), &list));
6809 len = 0;
6810 ole_check(IXMLDOMNodeList_get_length(list, &len));
6811 ok(len != 0, "expected filled list\n");
6812 if (len)
6813 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
6814 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 $and$ $not$ end()]"), &list));
6815 len = 0;
6816 ole_check(IXMLDOMNodeList_get_length(list, &len));
6817 ok(len != 0, "expected filled list\n");
6818 if (len)
6819 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
6820 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[index()>0 && $not$ end()]"), &list));
6821 len = 0;
6822 ole_check(IXMLDOMNodeList_get_length(list, &len));
6823 ok(len != 0, "expected filled list\n");
6824 if (len)
6825 expect_list_and_release(list, "E2.E2.D1 E3.E2.D1");
6827 /* namespace handling */
6828 /* no registered namespaces */
6829 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("")));
6830 list = NULL;
6832 /* prefixes don't need to be registered, you may use them as they are in the doc */
6833 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//bar:x"), &list));
6834 len = 0;
6835 ole_check(IXMLDOMNodeList_get_length(list, &len));
6836 ok(len != 0, "expected filled list\n");
6837 if (len)
6838 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
6840 /* prefixes must be explicitly specified in the name */
6841 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:elem"), &list));
6842 len = 0;
6843 ole_check(IXMLDOMNodeList_get_length(list, &len));
6844 ok(len == 0, "expected empty list\n");
6845 if (len)
6846 IXMLDOMNodeList_Release(list);
6848 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
6849 len = 0;
6850 ole_check(IXMLDOMNodeList_get_length(list, &len));
6851 ok(len != 0, "expected filled list\n");
6852 if (len)
6853 expect_list_and_release(list, "E3.E4.E2.D1");
6855 /* explicitly register prefix foo */
6856 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
6858 /* now we get the same behavior as XPath */
6859 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
6860 len = 0;
6861 ole_check(IXMLDOMNodeList_get_length(list, &len));
6862 ok(len != 0, "expected filled list\n");
6863 if (len)
6864 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
6866 /* set prefix foo to some nonexistent namespace */
6867 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:foo='urn:nonexistent-foo'")));
6869 /* the registered prefix takes precedence */
6870 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//foo:c"), &list));
6871 len = 0;
6872 ole_check(IXMLDOMNodeList_get_length(list, &len));
6873 ok(len == 0, "expected empty list\n");
6874 if (len)
6875 IXMLDOMNodeList_Release(list);
6877 IXMLDOMDocument2_Release(doc);
6879 doc = create_document(&IID_IXMLDOMDocument2);
6880 if (!doc) return;
6882 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szNodeTypesXML), &b));
6883 ok(b == VARIANT_TRUE, "failed to load XML string\n");
6884 list = NULL;
6886 /* attribute() */
6887 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute()"), &list));
6888 len = 0;
6889 ole_check(IXMLDOMNodeList_get_length(list, &len));
6890 ok(len == 0, "expected empty list\n");
6891 if (len)
6892 IXMLDOMNodeList_Release(list);
6894 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("attribute('depth')"), &list));
6895 len = 0;
6896 ole_check(IXMLDOMNodeList_get_length(list, &len));
6897 ok(len == 0, "expected empty list\n");
6898 if (len)
6899 IXMLDOMNodeList_Release(list);
6901 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/attribute('depth')"), &list));
6902 len = 0;
6903 ole_check(IXMLDOMNodeList_get_length(list, &len));
6904 ok(len != 0, "expected filled list\n");
6905 if (len)
6906 expect_list_and_release(list, "A'depth'.E3.D1");
6908 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/attribute()"), &list));
6909 len = 0;
6910 ole_check(IXMLDOMNodeList_get_length(list, &len));
6911 ok(len != 0, "expected filled list\n");
6912 if (len)
6913 expect_list_and_release(list, "A'id'.E3.E3.D1 A'depth'.E3.E3.D1");
6915 list = NULL;
6916 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute(id)"), &list), E_FAIL);
6917 if (list)
6918 IXMLDOMNodeList_Release(list);
6919 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x//attribute('id')"), &list));
6920 len = 0;
6921 ole_check(IXMLDOMNodeList_get_length(list, &len));
6922 ok(len != 0, "expected filled list\n");
6923 if (len)
6924 expect_list_and_release(list, "A'id'.E3.E3.D1 A'id'.E4.E3.E3.D1 A'id'.E5.E3.E3.D1 A'id'.E6.E3.E3.D1");
6926 /* comment() */
6927 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("comment()"), &list));
6928 len = 0;
6929 ole_check(IXMLDOMNodeList_get_length(list, &len));
6930 ok(len != 0, "expected filled list\n");
6931 if (len)
6932 expect_list_and_release(list, "C2.D1");
6934 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//comment()"), &list));
6935 len = 0;
6936 ole_check(IXMLDOMNodeList_get_length(list, &len));
6937 ok(len != 0, "expected filled list\n");
6938 if (len)
6939 expect_list_and_release(list, "C2.D1 C1.E3.D1 C2.E3.E3.D1 C2.E4.E3.D1");
6941 /* element() */
6942 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("element()"), &list));
6943 len = 0;
6944 ole_check(IXMLDOMNodeList_get_length(list, &len));
6945 ok(len != 0, "expected filled list\n");
6946 if (len)
6947 expect_list_and_release(list, "E3.D1");
6949 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/y/element()"), &list));
6950 len = 0;
6951 ole_check(IXMLDOMNodeList_get_length(list, &len));
6952 ok(len != 0, "expected filled list\n");
6953 if (len)
6954 expect_list_and_release(list, "E4.E4.E3.D1 E5.E4.E3.D1 E6.E4.E3.D1");
6956 list = NULL;
6957 ole_expect(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element(a)"), &list), E_FAIL);
6958 if (list)
6959 IXMLDOMNodeList_Release(list);
6960 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//element('a')"), &list));
6961 len = 0;
6962 ole_check(IXMLDOMNodeList_get_length(list, &len));
6963 ok(len != 0, "expected filled list\n");
6964 if (len)
6965 expect_list_and_release(list, "E4.E3.E3.D1 E4.E4.E3.D1");
6967 /* node() */
6968 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("node()"), &list));
6969 len = 0;
6970 ole_check(IXMLDOMNodeList_get_length(list, &len));
6971 ok(len != 0, "expected filled list\n");
6972 if (len)
6973 expect_list_and_release(list, "P1.D1 C2.D1 E3.D1");
6975 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()"), &list));
6976 len = 0;
6977 ole_check(IXMLDOMNodeList_get_length(list, &len));
6978 ok(len != 0, "expected filled list\n");
6979 if (len)
6980 expect_list_and_release(list, "P1.E3.E3.D1 C2.E3.E3.D1 T3.E3.E3.D1 E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
6982 /* nodeType() */
6983 /* XML_ELEMENT_NODE */
6984 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=1]"), &list));
6985 len = 0;
6986 ole_check(IXMLDOMNodeList_get_length(list, &len));
6987 ok(len != 0, "expected filled list\n");
6988 if (len)
6989 expect_list_and_release(list, "E4.E3.E3.D1 E5.E3.E3.D1 E6.E3.E3.D1");
6990 /* XML_TEXT_NODE */
6991 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=3]"), &list));
6992 len = 0;
6993 ole_check(IXMLDOMNodeList_get_length(list, &len));
6994 ok(len != 0, "expected filled list\n");
6995 if (len)
6996 expect_list_and_release(list, "T3.E3.E3.D1");
6997 /* XML_PI_NODE */
6998 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=7]"), &list));
6999 len = 0;
7000 ole_check(IXMLDOMNodeList_get_length(list, &len));
7001 ok(len != 0, "expected filled list\n");
7002 if (len)
7003 expect_list_and_release(list, "P1.E3.E3.D1");
7004 /* XML_COMMENT_NODE */
7005 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//x/node()[nodeType()=8]"), &list));
7006 len = 0;
7007 ole_check(IXMLDOMNodeList_get_length(list, &len));
7008 ok(len != 0, "expected filled list\n");
7009 if (len)
7010 expect_list_and_release(list, "C2.E3.E3.D1");
7012 /* pi() */
7013 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("pi()"), &list));
7014 if (list)
7016 len = 0;
7017 ole_check(IXMLDOMNodeList_get_length(list, &len));
7018 ok(len != 0, "expected filled list\n");
7019 if (len)
7020 expect_list_and_release(list, "P1.D1");
7023 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//y/pi()"), &list));
7024 len = 0;
7025 ole_check(IXMLDOMNodeList_get_length(list, &len));
7026 ok(len != 0, "expected filled list\n");
7027 if (len)
7028 expect_list_and_release(list, "P1.E4.E3.D1");
7030 /* textnode() */
7031 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/textnode()"), &list));
7032 len = 0;
7033 ole_check(IXMLDOMNodeList_get_length(list, &len));
7034 ok(len != 0, "expected filled list\n");
7035 if (len)
7036 expect_list_and_release(list, "T2.E3.D1");
7038 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root/element()/textnode()"), &list));
7039 len = 0;
7040 ole_check(IXMLDOMNodeList_get_length(list, &len));
7041 ok(len != 0, "expected filled list\n");
7042 if (len)
7043 expect_list_and_release(list, "T3.E3.E3.D1 T3.E4.E3.D1");
7045 IXMLDOMDocument2_Release(doc);
7046 free_bstrs();
7049 static void test_splitText(void)
7051 IXMLDOMCDATASection *cdata;
7052 IXMLDOMElement *root;
7053 IXMLDOMDocument *doc;
7054 IXMLDOMText *text, *text2;
7055 IXMLDOMNode *node;
7056 VARIANT var;
7057 VARIANT_BOOL success;
7058 LONG length;
7059 HRESULT hr;
7061 doc = create_document(&IID_IXMLDOMDocument);
7062 if (!doc) return;
7064 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
7065 ok(hr == S_OK, "got 0x%08x\n", hr);
7067 hr = IXMLDOMDocument_get_documentElement(doc, &root);
7068 ok(hr == S_OK, "got 0x%08x\n", hr);
7070 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
7071 ok(hr == S_OK, "got 0x%08x\n", hr);
7073 V_VT(&var) = VT_EMPTY;
7074 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
7075 ok(hr == S_OK, "got 0x%08x\n", hr);
7077 length = 0;
7078 hr = IXMLDOMCDATASection_get_length(cdata, &length);
7079 ok(hr == S_OK, "got 0x%08x\n", hr);
7080 ok(length > 0, "got %d\n", length);
7082 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
7083 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7085 text = (void*)0xdeadbeef;
7086 /* negative offset */
7087 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
7088 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7089 ok(text == (void*)0xdeadbeef, "got %p\n", text);
7091 text = (void*)0xdeadbeef;
7092 /* offset outside data */
7093 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
7094 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7095 ok(text == 0, "got %p\n", text);
7097 text = (void*)0xdeadbeef;
7098 /* offset outside data */
7099 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
7100 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7101 ok(text == 0, "got %p\n", text);
7103 /* no empty node created */
7104 node = (void*)0xdeadbeef;
7105 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
7106 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7107 ok(node == 0, "got %p\n", text);
7109 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
7110 ok(hr == S_OK, "got 0x%08x\n", hr);
7112 length = 0;
7113 hr = IXMLDOMText_get_length(text, &length);
7114 ok(hr == S_OK, "got 0x%08x\n", hr);
7115 ok(length == 7, "got %d\n", length);
7117 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
7118 ok(hr == S_OK, "got 0x%08x\n", hr);
7119 IXMLDOMNode_Release(node);
7121 /* split new text node */
7122 hr = IXMLDOMText_get_length(text, &length);
7123 ok(hr == S_OK, "got 0x%08x\n", hr);
7125 node = (void*)0xdeadbeef;
7126 hr = IXMLDOMText_get_nextSibling(text, &node);
7127 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7128 ok(node == 0, "got %p\n", text);
7130 hr = IXMLDOMText_splitText(text, 0, NULL);
7131 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7133 text2 = (void*)0xdeadbeef;
7134 /* negative offset */
7135 hr = IXMLDOMText_splitText(text, -1, &text2);
7136 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7137 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
7139 text2 = (void*)0xdeadbeef;
7140 /* offset outside data */
7141 hr = IXMLDOMText_splitText(text, length + 1, &text2);
7142 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
7143 ok(text2 == 0, "got %p\n", text2);
7145 text2 = (void*)0xdeadbeef;
7146 /* offset outside data */
7147 hr = IXMLDOMText_splitText(text, length, &text2);
7148 ok(hr == S_FALSE, "got 0x%08x\n", hr);
7149 ok(text2 == 0, "got %p\n", text);
7151 text2 = 0;
7152 hr = IXMLDOMText_splitText(text, 4, &text2);
7153 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
7154 if (text2) IXMLDOMText_Release(text2);
7156 node = 0;
7157 hr = IXMLDOMText_get_nextSibling(text, &node);
7158 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
7159 if (node) IXMLDOMNode_Release(node);
7161 IXMLDOMText_Release(text);
7162 IXMLDOMElement_Release(root);
7163 IXMLDOMCDATASection_Release(cdata);
7164 free_bstrs();
7167 static void test_getQualifiedItem(void)
7169 IXMLDOMDocument *doc;
7170 IXMLDOMElement *element;
7171 IXMLDOMNode *pr_node, *node;
7172 IXMLDOMNodeList *root_list;
7173 IXMLDOMNamedNodeMap *map;
7174 VARIANT_BOOL b;
7175 BSTR str;
7176 LONG len;
7177 HRESULT hr;
7179 doc = create_document(&IID_IXMLDOMDocument);
7180 if (!doc) return;
7182 str = SysAllocString( szComplete4 );
7183 hr = IXMLDOMDocument_loadXML( doc, str, &b );
7184 ok( hr == S_OK, "loadXML failed\n");
7185 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7186 SysFreeString( str );
7188 hr = IXMLDOMDocument_get_documentElement(doc, &element);
7189 ok( hr == S_OK, "ret %08x\n", hr);
7191 hr = IXMLDOMElement_get_childNodes(element, &root_list);
7192 ok( hr == S_OK, "ret %08x\n", hr);
7194 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
7195 ok( hr == S_OK, "ret %08x\n", hr);
7196 IXMLDOMNodeList_Release(root_list);
7198 hr = IXMLDOMNode_get_attributes(pr_node, &map);
7199 ok( hr == S_OK, "ret %08x\n", hr);
7200 IXMLDOMNode_Release(pr_node);
7202 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
7203 ok( hr == S_OK, "ret %08x\n", hr);
7204 ok( len == 3, "length %d\n", len);
7206 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
7207 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7209 node = (void*)0xdeadbeef;
7210 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
7211 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7212 ok( node == (void*)0xdeadbeef, "got %p\n", node);
7214 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
7215 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7217 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
7218 ok( hr == S_OK, "ret %08x\n", hr);
7219 IXMLDOMNode_Release(node);
7221 IXMLDOMNamedNodeMap_Release( map );
7222 IXMLDOMElement_Release( element );
7223 IXMLDOMDocument_Release( doc );
7224 free_bstrs();
7227 static void test_removeQualifiedItem(void)
7229 IXMLDOMDocument *doc;
7230 IXMLDOMElement *element;
7231 IXMLDOMNode *pr_node, *node;
7232 IXMLDOMNodeList *root_list;
7233 IXMLDOMNamedNodeMap *map;
7234 VARIANT_BOOL b;
7235 BSTR str;
7236 LONG len;
7237 HRESULT hr;
7239 doc = create_document(&IID_IXMLDOMDocument);
7240 if (!doc) return;
7242 str = SysAllocString( szComplete4 );
7243 hr = IXMLDOMDocument_loadXML( doc, str, &b );
7244 ok( hr == S_OK, "loadXML failed\n");
7245 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7246 SysFreeString( str );
7248 hr = IXMLDOMDocument_get_documentElement(doc, &element);
7249 ok( hr == S_OK, "ret %08x\n", hr);
7251 hr = IXMLDOMElement_get_childNodes(element, &root_list);
7252 ok( hr == S_OK, "ret %08x\n", hr);
7254 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
7255 ok( hr == S_OK, "ret %08x\n", hr);
7256 IXMLDOMNodeList_Release(root_list);
7258 hr = IXMLDOMNode_get_attributes(pr_node, &map);
7259 ok( hr == S_OK, "ret %08x\n", hr);
7260 IXMLDOMNode_Release(pr_node);
7262 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
7263 ok( hr == S_OK, "ret %08x\n", hr);
7264 ok( len == 3, "length %d\n", len);
7266 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
7267 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7269 node = (void*)0xdeadbeef;
7270 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
7271 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
7272 ok( node == (void*)0xdeadbeef, "got %p\n", node);
7274 /* out pointer is optional */
7275 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
7276 ok( hr == S_OK, "ret %08x\n", hr);
7278 /* already removed */
7279 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
7280 ok( hr == S_FALSE, "ret %08x\n", hr);
7282 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
7283 ok( hr == S_OK, "ret %08x\n", hr);
7284 IXMLDOMNode_Release(node);
7286 IXMLDOMNamedNodeMap_Release( map );
7287 IXMLDOMElement_Release( element );
7288 IXMLDOMDocument_Release( doc );
7289 free_bstrs();
7292 static void test_get_ownerDocument(void)
7294 IXMLDOMDocument *doc1, *doc2, *doc3;
7295 IXMLDOMDocument2 *doc, *doc_owner;
7296 IXMLDOMNode *node;
7297 VARIANT_BOOL b;
7298 VARIANT var;
7299 HRESULT hr;
7300 BSTR str;
7302 doc = create_document(&IID_IXMLDOMDocument2);
7303 if (!doc) return;
7305 str = SysAllocString( szComplete4 );
7306 hr = IXMLDOMDocument_loadXML( doc, str, &b );
7307 ok( hr == S_OK, "loadXML failed\n");
7308 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7309 SysFreeString( str );
7311 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var);
7312 ok( hr == S_OK, "got 0x%08x\n", hr);
7313 ok( lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
7314 VariantClear(&var);
7316 /* set to XPath and check that new instances use it */
7317 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath"));
7318 ok( hr == S_OK, "got 0x%08x\n", hr);
7320 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'"));
7321 ok( hr == S_OK, "got 0x%08x\n", hr);
7323 hr = IXMLDOMDocument2_get_firstChild(doc, &node);
7324 ok( hr == S_OK, "got 0x%08x\n", hr);
7326 hr = IXMLDOMNode_get_ownerDocument(node, &doc1);
7327 ok( hr == S_OK, "got 0x%08x\n", hr);
7329 hr = IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner);
7330 ok( hr == S_OK, "got 0x%08x\n", hr);
7331 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
7332 hr = IXMLDOMDocument2_getProperty(doc_owner, _bstr_("SelectionNamespaces"), &var);
7333 ok( hr == S_OK, "got 0x%08x\n", hr);
7334 ok( lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "expected previously set value\n");
7335 VariantClear(&var);
7337 hr = IXMLDOMDocument2_getProperty(doc_owner, _bstr_("SelectionLanguage"), &var);
7338 ok( hr == S_OK, "got 0x%08x\n", hr);
7339 ok( lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
7340 VariantClear(&var);
7341 IXMLDOMDocument2_Release(doc_owner);
7343 hr = IXMLDOMNode_get_ownerDocument(node, &doc2);
7344 ok( hr == S_OK, "got 0x%08x\n", hr);
7345 IXMLDOMNode_Release(node);
7347 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
7349 /* reload */
7350 str = SysAllocString( szComplete4 );
7351 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
7352 ok( hr == S_OK, "got 0x%08x\n", hr);
7353 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7354 SysFreeString( str );
7356 /* properties retained even after reload */
7357 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var);
7358 ok( hr == S_OK, "got 0x%08x\n", hr);
7359 ok( lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "expected previously set value\n");
7360 VariantClear(&var);
7362 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var);
7363 ok( hr == S_OK, "got 0x%08x\n", hr);
7364 ok( lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
7365 VariantClear(&var);
7367 hr = IXMLDOMDocument2_get_firstChild(doc, &node);
7368 ok( hr == S_OK, "got 0x%08x\n", hr);
7370 hr = IXMLDOMNode_get_ownerDocument(node, &doc3);
7371 ok( hr == S_OK, "got 0x%08x\n", hr);
7372 IXMLDOMNode_Release(node);
7374 hr = IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner);
7375 ok( hr == S_OK, "got 0x%08x\n", hr);
7376 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
7378 IXMLDOMDocument_Release(doc1);
7379 IXMLDOMDocument_Release(doc2);
7380 IXMLDOMDocument_Release(doc3);
7381 IXMLDOMDocument2_Release(doc);
7382 free_bstrs();
7385 static void test_setAttributeNode(void)
7387 IXMLDOMDocument *doc, *doc2;
7388 IXMLDOMElement *elem;
7389 IXMLDOMAttribute *attr, *attr2, *ret_attr;
7390 VARIANT_BOOL b;
7391 HRESULT hr;
7392 BSTR str;
7394 doc = create_document(&IID_IXMLDOMDocument);
7395 if (!doc) return;
7397 str = SysAllocString( szComplete4 );
7398 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
7399 ok( hr == S_OK, "loadXML failed\n");
7400 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7401 SysFreeString( str );
7403 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7404 ok( hr == S_OK, "got 0x%08x\n", hr);
7406 ret_attr = (void*)0xdeadbeef;
7407 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
7408 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
7409 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7411 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
7412 ok( hr == S_OK, "got 0x%08x\n", hr);
7414 ret_attr = (void*)0xdeadbeef;
7415 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7416 ok( hr == S_OK, "got 0x%08x\n", hr);
7417 ok( ret_attr == NULL, "got %p\n", ret_attr);
7419 attr2 = NULL;
7420 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
7421 ok( hr == S_OK, "got 0x%08x\n", hr);
7422 IXMLDOMAttribute_Release(attr2);
7424 /* try to add it another time */
7425 ret_attr = (void*)0xdeadbeef;
7426 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7427 todo_wine ok( hr == E_FAIL, "got 0x%08x\n", hr);
7428 todo_wine ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7430 IXMLDOMElement_Release(elem);
7432 /* initialy used element is released, attribute still 'has' a container */
7433 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
7434 ok( hr == S_OK, "got 0x%08x\n", hr);
7435 ret_attr = (void*)0xdeadbeef;
7436 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
7437 todo_wine ok( hr == E_FAIL, "got 0x%08x\n", hr);
7438 todo_wine ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
7439 IXMLDOMElement_Release(elem);
7441 /* add attribute already attached to another document */
7442 doc2 = create_document(&IID_IXMLDOMDocument);
7444 str = SysAllocString( szComplete4 );
7445 hr = IXMLDOMDocument_loadXML( doc2, str, &b );
7446 ok( hr == S_OK, "loadXML failed\n");
7447 ok( b == VARIANT_TRUE, "failed to load XML string\n");
7448 SysFreeString( str );
7450 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
7451 ok( hr == S_OK, "got 0x%08x\n", hr);
7452 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
7453 todo_wine ok( hr == E_FAIL, "got 0x%08x\n", hr);
7454 IXMLDOMElement_Release(elem);
7456 IXMLDOMDocument_Release(doc2);
7458 IXMLDOMAttribute_Release(attr);
7459 IXMLDOMDocument_Release(doc);
7460 free_bstrs();
7463 static void test_get_dataType(void)
7465 IXMLDOMDocument2 *doc, *schema;
7466 IXMLDOMSchemaCollection* cache;
7467 IXMLDOMNode* node;
7468 IXMLDOMParseError* err;
7469 VARIANT_BOOL b;
7470 VARIANT v;
7471 LONG l;
7472 BSTR bstr;
7474 VariantInit(&v);
7476 doc = create_document(&IID_IXMLDOMDocument2);
7477 schema = create_document(&IID_IXMLDOMDocument2);
7478 cache = create_cache(&IID_IXMLDOMSchemaCollection);
7480 if (!doc || !schema || !cache)
7482 if (doc) IXMLDOMDocument2_Release(doc);
7483 if (schema) IXMLDOMDocument2_Release(schema);
7484 if (cache) IXMLDOMSchemaCollection_Release(cache);
7486 return;
7489 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szDatatypeXML), &b));
7490 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7492 ole_check(IXMLDOMDocument2_loadXML(schema, _bstr_(szDatatypeXDR), &b));
7493 ok(b == VARIANT_TRUE, "failed to load XML string\n");
7495 err = NULL;
7496 ole_expect(IXMLDOMDocument2_validate(doc, &err), S_FALSE);
7497 ok(err != NULL, "domdoc_validate() should always set err\n");
7498 ole_check(IXMLDOMParseError_get_errorCode(err, &l));
7499 ok(l == E_XML_NODTD, "got %08x\n", l);
7500 IXMLDOMParseError_Release(err);
7502 /* check data types without the schema */
7503 node = NULL;
7504 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testBase64']/Value/base64Data"), &node));
7505 ok(node != NULL, "expected node\n");
7506 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7507 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7508 if (V_VT(&v) == VT_BSTR)
7509 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7510 VariantClear(&v);
7511 IXMLDOMNode_Release(node);
7513 node = NULL;
7514 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testHex']/Value/hexData"), &node));
7515 ok(node != NULL, "expected node\n");
7516 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7517 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7518 if (V_VT(&v) == VT_BSTR)
7519 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7520 VariantClear(&v);
7521 IXMLDOMNode_Release(node);
7523 node = NULL;
7524 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testBool']/Value/boolData"), &node));
7525 ok(node != NULL, "expected node\n");
7526 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7527 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7528 if (V_VT(&v) == VT_BSTR)
7529 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7530 VariantClear(&v);
7531 IXMLDOMNode_Release(node);
7533 node = NULL;
7534 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testChar']/Value/charData"), &node));
7535 ok(node != NULL, "expected node\n");
7536 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7537 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7538 if (V_VT(&v) == VT_BSTR)
7539 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7540 VariantClear(&v);
7541 IXMLDOMNode_Release(node);
7543 node = NULL;
7544 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testDate']/Value/dateData"), &node));
7545 ok(node != NULL, "expected node\n");
7546 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7547 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7548 if (V_VT(&v) == VT_BSTR)
7549 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7550 VariantClear(&v);
7551 IXMLDOMNode_Release(node);
7553 node = NULL;
7554 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testDateTime']/Value/dateTimeData"), &node));
7555 ok(node != NULL, "expected node\n");
7556 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7557 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7558 if (V_VT(&v) == VT_BSTR)
7559 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7560 VariantClear(&v);
7561 IXMLDOMNode_Release(node);
7563 node = NULL;
7564 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testDateTimeTz']/Value/dateTimeTzData"), &node));
7565 ok(node != NULL, "expected node\n");
7566 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7567 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7568 if (V_VT(&v) == VT_BSTR)
7569 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7570 VariantClear(&v);
7571 IXMLDOMNode_Release(node);
7573 node = NULL;
7574 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testFixed']/Value/fixedData"), &node));
7575 ok(node != NULL, "expected node\n");
7576 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7577 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7578 if (V_VT(&v) == VT_BSTR)
7579 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7580 VariantClear(&v);
7581 IXMLDOMNode_Release(node);
7583 node = NULL;
7584 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testFloat']/Value/floatData"), &node));
7585 ok(node != NULL, "expected node\n");
7586 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7587 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7588 if (V_VT(&v) == VT_BSTR)
7589 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7590 VariantClear(&v);
7591 IXMLDOMNode_Release(node);
7593 node = NULL;
7594 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI1']/Value/i1Data"), &node));
7595 ok(node != NULL, "expected node\n");
7596 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7597 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7598 if (V_VT(&v) == VT_BSTR)
7599 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7600 VariantClear(&v);
7601 IXMLDOMNode_Release(node);
7603 node = NULL;
7604 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI2']/Value/i2Data"), &node));
7605 ok(node != NULL, "expected node\n");
7606 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7607 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7608 if (V_VT(&v) == VT_BSTR)
7609 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7610 VariantClear(&v);
7611 IXMLDOMNode_Release(node);
7613 node = NULL;
7614 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI4']/Value/i4Data"), &node));
7615 ok(node != NULL, "expected node\n");
7616 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7617 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7618 if (V_VT(&v) == VT_BSTR)
7619 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7620 VariantClear(&v);
7621 IXMLDOMNode_Release(node);
7623 node = NULL;
7624 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI8']/Value/i8Data"), &node));
7625 ok(node != NULL, "expected node\n");
7626 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7627 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7628 if (V_VT(&v) == VT_BSTR)
7629 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7630 VariantClear(&v);
7631 IXMLDOMNode_Release(node);
7633 node = NULL;
7634 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testInt']/Value/intData"), &node));
7635 ok(node != NULL, "expected node\n");
7636 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7637 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7638 if (V_VT(&v) == VT_BSTR)
7639 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7640 VariantClear(&v);
7641 IXMLDOMNode_Release(node);
7643 node = NULL;
7644 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testNmtoken']/Value/nmtokData"), &node));
7645 ok(node != NULL, "expected node\n");
7646 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7647 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7648 if (V_VT(&v) == VT_BSTR)
7649 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7650 VariantClear(&v);
7651 IXMLDOMNode_Release(node);
7653 node = NULL;
7654 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testNmtokens']/Value/nmtoksData"), &node));
7655 ok(node != NULL, "expected node\n");
7656 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7657 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7658 if (V_VT(&v) == VT_BSTR)
7659 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7660 VariantClear(&v);
7661 IXMLDOMNode_Release(node);
7663 node = NULL;
7664 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testNumber']/Value/numData"), &node));
7665 ok(node != NULL, "expected node\n");
7666 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7667 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7668 if (V_VT(&v) == VT_BSTR)
7669 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7670 VariantClear(&v);
7671 IXMLDOMNode_Release(node);
7673 node = NULL;
7674 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testR4']/Value/r4Data"), &node));
7675 ok(node != NULL, "expected node\n");
7676 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7677 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7678 if (V_VT(&v) == VT_BSTR)
7679 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7680 VariantClear(&v);
7681 IXMLDOMNode_Release(node);
7683 node = NULL;
7684 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testR8']/Value/r8Data"), &node));
7685 ok(node != NULL, "expected node\n");
7686 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7687 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7688 if (V_VT(&v) == VT_BSTR)
7689 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7690 VariantClear(&v);
7691 IXMLDOMNode_Release(node);
7693 node = NULL;
7694 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testString']/Value/stringData"), &node));
7695 ok(node != NULL, "expected node\n");
7696 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7697 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7698 if (V_VT(&v) == VT_BSTR)
7699 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7700 VariantClear(&v);
7701 IXMLDOMNode_Release(node);
7703 node = NULL;
7704 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testTime']/Value/timeData"), &node));
7705 ok(node != NULL, "expected node\n");
7706 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7707 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7708 if (V_VT(&v) == VT_BSTR)
7709 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7710 VariantClear(&v);
7711 IXMLDOMNode_Release(node);
7713 node = NULL;
7714 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testTimeTz']/Value/timeTzData"), &node));
7715 ok(node != NULL, "expected node\n");
7716 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7717 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7718 if (V_VT(&v) == VT_BSTR)
7719 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7720 VariantClear(&v);
7721 IXMLDOMNode_Release(node);
7723 node = NULL;
7724 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU1']/Value/u1Data"), &node));
7725 ok(node != NULL, "expected node\n");
7726 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7727 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7728 if (V_VT(&v) == VT_BSTR)
7729 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7730 VariantClear(&v);
7731 IXMLDOMNode_Release(node);
7733 node = NULL;
7734 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU2']/Value/u2Data"), &node));
7735 ok(node != NULL, "expected node\n");
7736 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7737 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7738 if (V_VT(&v) == VT_BSTR)
7739 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7740 VariantClear(&v);
7741 IXMLDOMNode_Release(node);
7743 node = NULL;
7744 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU4']/Value/u4Data"), &node));
7745 ok(node != NULL, "expected node\n");
7746 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7747 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7748 if (V_VT(&v) == VT_BSTR)
7749 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7750 VariantClear(&v);
7751 IXMLDOMNode_Release(node);
7753 node = NULL;
7754 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU8']/Value/u8Data"), &node));
7755 ok(node != NULL, "expected node\n");
7756 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7757 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7758 if (V_VT(&v) == VT_BSTR)
7759 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7760 VariantClear(&v);
7761 IXMLDOMNode_Release(node);
7763 node = NULL;
7764 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testURI']/Value/uriData"), &node));
7765 ok(node != NULL, "expected node\n");
7766 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7767 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7768 if (V_VT(&v) == VT_BSTR)
7769 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7770 VariantClear(&v);
7771 IXMLDOMNode_Release(node);
7773 node = NULL;
7774 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testUUID']/Value/uuidData"), &node));
7775 ok(node != NULL, "expected node\n");
7776 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7777 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7778 if (V_VT(&v) == VT_BSTR)
7779 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7780 VariantClear(&v);
7781 IXMLDOMNode_Release(node);
7783 /* now load the schema */
7784 V_VT(&v) = VT_DISPATCH;
7785 V_DISPATCH(&v) = NULL;
7786 ole_check(IXMLDOMDocument2_QueryInterface(schema, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
7787 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
7788 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_("urn:x-schema:datatype-test-xdr"), v));
7789 VariantClear(&v);
7791 /* associate the cache to the doc */
7792 V_VT(&v) = VT_DISPATCH;
7793 V_DISPATCH(&v) = NULL;
7794 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
7795 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
7796 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
7797 VariantClear(&v);
7799 /* validate the doc */
7800 err = NULL;
7801 l = 0;
7802 bstr = NULL;
7803 ole_check(IXMLDOMDocument2_validate(doc, &err));
7804 ok(err != NULL, "domdoc_validate() should always set err\n");
7805 ole_expect(IXMLDOMParseError_get_errorCode(err, &l), S_FALSE);
7806 ole_expect(IXMLDOMParseError_get_reason(err, &bstr), S_FALSE);
7807 ok(l == 0, "got %08x : %s\n", l, wine_dbgstr_w(bstr));
7808 IXMLDOMParseError_Release(err);
7810 /* check the data types again */
7811 node = NULL;
7812 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testBase64']/Value/base64Data"), &node));
7813 ok(node != NULL, "expected node\n");
7814 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7815 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7816 if (V_VT(&v) == VT_BSTR)
7817 ok(lstrcmpW(V_BSTR(&v), _bstr_("bin.base64")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7818 VariantClear(&v);
7819 IXMLDOMNode_Release(node);
7821 node = NULL;
7822 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testHex']/Value/hexData"), &node));
7823 ok(node != NULL, "expected node\n");
7824 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7825 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7826 if (V_VT(&v) == VT_BSTR)
7827 ok(lstrcmpW(V_BSTR(&v), _bstr_("bin.hex")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7828 VariantClear(&v);
7829 IXMLDOMNode_Release(node);
7831 node = NULL;
7832 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testBool']/Value/boolData"), &node));
7833 ok(node != NULL, "expected node\n");
7834 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7835 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7836 if (V_VT(&v) == VT_BSTR)
7837 ok(lstrcmpW(V_BSTR(&v), _bstr_("boolean")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7838 VariantClear(&v);
7839 IXMLDOMNode_Release(node);
7841 node = NULL;
7842 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testChar']/Value/charData"), &node));
7843 ok(node != NULL, "expected node\n");
7844 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7845 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7846 if (V_VT(&v) == VT_BSTR)
7847 ok(lstrcmpW(V_BSTR(&v), _bstr_("char")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7848 VariantClear(&v);
7849 IXMLDOMNode_Release(node);
7851 node = NULL;
7852 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testDate']/Value/dateData"), &node));
7853 ok(node != NULL, "expected node\n");
7854 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7855 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7856 if (V_VT(&v) == VT_BSTR)
7857 ok(lstrcmpW(V_BSTR(&v), _bstr_("date")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7858 VariantClear(&v);
7859 IXMLDOMNode_Release(node);
7861 node = NULL;
7862 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testDateTime']/Value/dateTimeData"), &node));
7863 ok(node != NULL, "expected node\n");
7864 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7865 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7866 if (V_VT(&v) == VT_BSTR)
7867 ok(lstrcmpW(V_BSTR(&v), _bstr_("dateTime")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7868 VariantClear(&v);
7869 IXMLDOMNode_Release(node);
7871 node = NULL;
7872 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testDateTimeTz']/Value/dateTimeTzData"), &node));
7873 ok(node != NULL, "expected node\n");
7874 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7875 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7876 if (V_VT(&v) == VT_BSTR)
7877 ok(lstrcmpW(V_BSTR(&v), _bstr_("dateTime.tz")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7878 VariantClear(&v);
7879 IXMLDOMNode_Release(node);
7881 node = NULL;
7882 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testFixed']/Value/fixedData"), &node));
7883 ok(node != NULL, "expected node\n");
7884 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7885 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7886 if (V_VT(&v) == VT_BSTR)
7887 ok(lstrcmpW(V_BSTR(&v), _bstr_("fixed.14.4")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7888 VariantClear(&v);
7889 IXMLDOMNode_Release(node);
7891 node = NULL;
7892 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testFloat']/Value/floatData"), &node));
7893 ok(node != NULL, "expected node\n");
7894 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7895 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7896 if (V_VT(&v) == VT_BSTR)
7897 ok(lstrcmpW(V_BSTR(&v), _bstr_("float")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7898 VariantClear(&v);
7899 IXMLDOMNode_Release(node);
7901 node = NULL;
7902 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI1']/Value/i1Data"), &node));
7903 ok(node != NULL, "expected node\n");
7904 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7905 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7906 if (V_VT(&v) == VT_BSTR)
7907 ok(lstrcmpW(V_BSTR(&v), _bstr_("i1")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7908 VariantClear(&v);
7909 IXMLDOMNode_Release(node);
7911 node = NULL;
7912 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI2']/Value/i2Data"), &node));
7913 ok(node != NULL, "expected node\n");
7914 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7915 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7916 if (V_VT(&v) == VT_BSTR)
7917 ok(lstrcmpW(V_BSTR(&v), _bstr_("i2")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7918 VariantClear(&v);
7919 IXMLDOMNode_Release(node);
7921 node = NULL;
7922 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI4']/Value/i4Data"), &node));
7923 ok(node != NULL, "expected node\n");
7924 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7925 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7926 if (V_VT(&v) == VT_BSTR)
7927 ok(lstrcmpW(V_BSTR(&v), _bstr_("i4")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7928 VariantClear(&v);
7929 IXMLDOMNode_Release(node);
7931 node = NULL;
7932 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testI8']/Value/i8Data"), &node));
7933 ok(node != NULL, "expected node\n");
7934 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7935 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7936 if (V_VT(&v) == VT_BSTR)
7937 ok(lstrcmpW(V_BSTR(&v), _bstr_("i8")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7938 VariantClear(&v);
7939 IXMLDOMNode_Release(node);
7941 node = NULL;
7942 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testInt']/Value/intData"), &node));
7943 ok(node != NULL, "expected node\n");
7944 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7945 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7946 if (V_VT(&v) == VT_BSTR)
7947 ok(lstrcmpW(V_BSTR(&v), _bstr_("int")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7948 VariantClear(&v);
7949 IXMLDOMNode_Release(node);
7951 /* nmtoken does not return a bstr */
7952 node = NULL;
7953 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testNmtoken']/Value/nmtokData"), &node));
7954 ok(node != NULL, "expected node\n");
7955 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7956 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7957 if (V_VT(&v) == VT_BSTR)
7958 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7959 VariantClear(&v);
7960 IXMLDOMNode_Release(node);
7962 /* nmtokens does not return a bstr */
7963 node = NULL;
7964 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testNmtokens']/Value/nmtoksData"), &node));
7965 ok(node != NULL, "expected node\n");
7966 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
7967 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
7968 if (V_VT(&v) == VT_BSTR)
7969 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7970 VariantClear(&v);
7971 IXMLDOMNode_Release(node);
7973 node = NULL;
7974 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testNumber']/Value/numData"), &node));
7975 ok(node != NULL, "expected node\n");
7976 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7977 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7978 if (V_VT(&v) == VT_BSTR)
7979 ok(lstrcmpW(V_BSTR(&v), _bstr_("number")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7980 VariantClear(&v);
7981 IXMLDOMNode_Release(node);
7983 node = NULL;
7984 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testR4']/Value/r4Data"), &node));
7985 ok(node != NULL, "expected node\n");
7986 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7987 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7988 if (V_VT(&v) == VT_BSTR)
7989 ok(lstrcmpW(V_BSTR(&v), _bstr_("r4")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
7990 VariantClear(&v);
7991 IXMLDOMNode_Release(node);
7993 node = NULL;
7994 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testR8']/Value/r8Data"), &node));
7995 ok(node != NULL, "expected node\n");
7996 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
7997 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
7998 if (V_VT(&v) == VT_BSTR)
7999 ok(lstrcmpW(V_BSTR(&v), _bstr_("r8")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8000 VariantClear(&v);
8001 IXMLDOMNode_Release(node);
8003 /* dt:string is the default, does not return a bstr */
8004 node = NULL;
8005 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testString']/Value/stringData"), &node));
8006 ok(node != NULL, "expected node\n");
8007 ole_expect(IXMLDOMNode_get_dataType(node, &v), S_FALSE);
8008 ok(V_VT(&v) == VT_NULL, "got variant type %i\n", V_VT(&v));
8009 if (V_VT(&v) == VT_BSTR)
8010 ok(0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8011 VariantClear(&v);
8012 IXMLDOMNode_Release(node);
8014 node = NULL;
8015 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testTime']/Value/timeData"), &node));
8016 ok(node != NULL, "expected node\n");
8017 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8018 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8019 if (V_VT(&v) == VT_BSTR)
8020 ok(lstrcmpW(V_BSTR(&v), _bstr_("time")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8021 VariantClear(&v);
8022 IXMLDOMNode_Release(node);
8024 node = NULL;
8025 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testTimeTz']/Value/timeTzData"), &node));
8026 ok(node != NULL, "expected node\n");
8027 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8028 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8029 if (V_VT(&v) == VT_BSTR)
8030 ok(lstrcmpW(V_BSTR(&v), _bstr_("time.tz")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8031 VariantClear(&v);
8032 IXMLDOMNode_Release(node);
8034 node = NULL;
8035 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU1']/Value/u1Data"), &node));
8036 ok(node != NULL, "expected node\n");
8037 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8038 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8039 if (V_VT(&v) == VT_BSTR)
8040 ok(lstrcmpW(V_BSTR(&v), _bstr_("ui1")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8041 VariantClear(&v);
8042 IXMLDOMNode_Release(node);
8044 node = NULL;
8045 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU2']/Value/u2Data"), &node));
8046 ok(node != NULL, "expected node\n");
8047 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8048 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8049 if (V_VT(&v) == VT_BSTR)
8050 ok(lstrcmpW(V_BSTR(&v), _bstr_("ui2")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8051 VariantClear(&v);
8052 IXMLDOMNode_Release(node);
8054 node = NULL;
8055 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU4']/Value/u4Data"), &node));
8056 ok(node != NULL, "expected node\n");
8057 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8058 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8059 if (V_VT(&v) == VT_BSTR)
8060 ok(lstrcmpW(V_BSTR(&v), _bstr_("ui4")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8061 VariantClear(&v);
8062 IXMLDOMNode_Release(node);
8064 node = NULL;
8065 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testU8']/Value/u8Data"), &node));
8066 ok(node != NULL, "expected node\n");
8067 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8068 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8069 if (V_VT(&v) == VT_BSTR)
8070 ok(lstrcmpW(V_BSTR(&v), _bstr_("ui8")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8071 VariantClear(&v);
8072 IXMLDOMNode_Release(node);
8074 node = NULL;
8075 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testURI']/Value/uriData"), &node));
8076 ok(node != NULL, "expected node\n");
8077 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8078 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8079 if (V_VT(&v) == VT_BSTR)
8080 ok(lstrcmpW(V_BSTR(&v), _bstr_("uri")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8081 VariantClear(&v);
8082 IXMLDOMNode_Release(node);
8084 node = NULL;
8085 ole_check(IXMLDOMDocument2_selectSingleNode(doc, _bstr_("//Property[Name!text()='testUUID']/Value/uuidData"), &node));
8086 ok(node != NULL, "expected node\n");
8087 todo_wine ole_check(IXMLDOMNode_get_dataType(node, &v));
8088 todo_wine ok(V_VT(&v) == VT_BSTR, "got variant type %i\n", V_VT(&v));
8089 if (V_VT(&v) == VT_BSTR)
8090 ok(lstrcmpW(V_BSTR(&v), _bstr_("uuid")) == 0, "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
8091 VariantClear(&v);
8092 IXMLDOMNode_Release(node);
8094 ok(IXMLDOMDocument2_Release(schema) == 0, "schema not released\n");
8095 ok(IXMLDOMDocument2_Release(doc) == 0, "doc not released\n");
8096 ok(IXMLDOMSchemaCollection_Release(cache) == 0, "cache not released\n");
8098 free_bstrs();
8101 static void test_put_dataType(void)
8103 IXMLDOMCDATASection *cdata;
8104 IXMLDOMDocument *doc;
8105 VARIANT_BOOL b;
8106 HRESULT hr;
8107 BSTR str;
8109 doc = create_document(&IID_IXMLDOMDocument);
8110 if (!doc) return;
8112 str = SysAllocString( szComplete4 );
8113 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8114 ok( hr == S_OK, "loadXML failed\n");
8115 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8116 SysFreeString( str );
8118 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("test"), &cdata);
8119 ok( hr == S_OK, "got 0x%08x\n", hr);
8120 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("number"));
8121 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8122 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("string"));
8123 ok( hr == E_FAIL, "got 0x%08x\n", hr);
8124 IXMLDOMCDATASection_Release(cdata);
8126 IXMLDOMDocument_Release(doc);
8127 free_bstrs();
8130 static void test_createNode(void)
8132 IXMLDOMDocument *doc;
8133 IXMLDOMElement *elem;
8134 IXMLDOMNode *node;
8135 VARIANT v, var;
8136 BSTR prefix, str;
8137 HRESULT hr;
8139 doc = create_document(&IID_IXMLDOMDocument);
8140 if (!doc) return;
8142 /* NODE_ELEMENT nodes */
8143 /* 1. specified namespace */
8144 V_VT(&v) = VT_I4;
8145 V_I4(&v) = NODE_ELEMENT;
8147 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
8148 ok( hr == S_OK, "got 0x%08x\n", hr);
8149 prefix = NULL;
8150 hr = IXMLDOMNode_get_prefix(node, &prefix);
8151 ok( hr == S_OK, "got 0x%08x\n", hr);
8152 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
8153 SysFreeString(prefix);
8154 IXMLDOMNode_Release(node);
8156 /* 2. default namespace */
8157 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
8158 ok( hr == S_OK, "got 0x%08x\n", hr);
8159 prefix = (void*)0xdeadbeef;
8160 hr = IXMLDOMNode_get_prefix(node, &prefix);
8161 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8162 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
8164 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
8165 ok( hr == S_OK, "got 0x%08x\n", hr);
8167 V_VT(&var) = VT_BSTR;
8168 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
8169 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8170 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
8172 str = NULL;
8173 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
8174 ok( hr == S_OK, "got 0x%08x\n", hr);
8175 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
8176 SysFreeString(str);
8178 IXMLDOMElement_Release(elem);
8179 IXMLDOMNode_Release(node);
8181 IXMLDOMDocument_Release(doc);
8182 free_bstrs();
8185 static void test_get_prefix(void)
8187 IXMLDOMDocumentFragment *fragment;
8188 IXMLDOMCDATASection *cdata;
8189 IXMLDOMElement *element;
8190 IXMLDOMComment *comment;
8191 IXMLDOMDocument *doc;
8192 HRESULT hr;
8193 BSTR str;
8195 doc = create_document(&IID_IXMLDOMDocument);
8196 if (!doc) return;
8198 /* nodes that can't support prefix */
8199 /* 1. document */
8200 str = (void*)0xdeadbeef;
8201 hr = IXMLDOMDocument_get_prefix(doc, &str);
8202 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8203 ok( str == 0, "got %p\n", str);
8205 hr = IXMLDOMDocument_get_prefix(doc, NULL);
8206 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8208 /* 2. cdata */
8209 hr = IXMLDOMDocument_createCDATASection(doc, NULL, &cdata);
8210 ok(hr == S_OK, "got %08x\n", hr );
8212 str = (void*)0xdeadbeef;
8213 hr = IXMLDOMCDATASection_get_prefix(cdata, &str);
8214 ok(hr == S_FALSE, "got %08x\n", hr);
8215 ok( str == 0, "got %p\n", str);
8217 hr = IXMLDOMCDATASection_get_prefix(cdata, NULL);
8218 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8219 IXMLDOMCDATASection_Release(cdata);
8221 /* 3. comment */
8222 hr = IXMLDOMDocument_createComment(doc, NULL, &comment);
8223 ok(hr == S_OK, "got %08x\n", hr );
8225 str = (void*)0xdeadbeef;
8226 hr = IXMLDOMComment_get_prefix(comment, &str);
8227 ok(hr == S_FALSE, "got %08x\n", hr);
8228 ok( str == 0, "got %p\n", str);
8230 hr = IXMLDOMComment_get_prefix(comment, NULL);
8231 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8232 IXMLDOMComment_Release(comment);
8234 /* 4. fragment */
8235 hr = IXMLDOMDocument_createDocumentFragment(doc, &fragment);
8236 ok(hr == S_OK, "got %08x\n", hr );
8238 str = (void*)0xdeadbeef;
8239 hr = IXMLDOMDocumentFragment_get_prefix(fragment, &str);
8240 ok(hr == S_FALSE, "got %08x\n", hr);
8241 ok( str == 0, "got %p\n", str);
8243 hr = IXMLDOMDocumentFragment_get_prefix(fragment, NULL);
8244 ok(hr == E_INVALIDARG, "got %08x\n", hr);
8245 IXMLDOMDocumentFragment_Release(fragment);
8247 /* no prefix */
8248 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
8249 ok( hr == S_OK, "got 0x%08x\n", hr);
8251 hr = IXMLDOMElement_get_prefix(element, NULL);
8252 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
8254 str = (void*)0xdeadbeef;
8255 hr = IXMLDOMElement_get_prefix(element, &str);
8256 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8257 ok( str == 0, "got %p\n", str);
8259 IXMLDOMElement_Release(element);
8261 /* with prefix */
8262 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
8263 ok( hr == S_OK, "got 0x%08x\n", hr);
8265 str = (void*)0xdeadbeef;
8266 hr = IXMLDOMElement_get_prefix(element, &str);
8267 ok( hr == S_OK, "got 0x%08x\n", hr);
8268 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
8269 SysFreeString(str);
8271 str = (void*)0xdeadbeef;
8272 hr = IXMLDOMElement_get_namespaceURI(element, &str);
8273 ok( hr == S_FALSE, "got 0x%08x\n", hr);
8274 ok( str == 0, "got %p\n", str);
8276 IXMLDOMElement_Release(element);
8278 IXMLDOMDocument_Release(doc);
8279 free_bstrs();
8282 static void test_selectSingleNode(void)
8284 IXMLDOMDocument *doc;
8285 IXMLDOMNodeList *list;
8286 IXMLDOMNode *node;
8287 VARIANT_BOOL b;
8288 HRESULT hr;
8289 LONG len;
8290 BSTR str;
8292 doc = create_document(&IID_IXMLDOMDocument);
8293 if (!doc) return;
8295 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8296 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8298 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8299 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8301 str = SysAllocString( szComplete4 );
8302 hr = IXMLDOMDocument_loadXML( doc, str, &b );
8303 ok( hr == S_OK, "loadXML failed\n");
8304 ok( b == VARIANT_TRUE, "failed to load XML string\n");
8305 SysFreeString( str );
8307 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
8308 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8310 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
8311 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8313 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
8314 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8316 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
8317 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8319 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
8320 ok(hr == S_OK, "got 0x%08x\n", hr);
8321 IXMLDOMNode_Release(node);
8323 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
8324 ok(hr == S_OK, "got 0x%08x\n", hr);
8325 IXMLDOMNodeList_Release(list);
8327 list = (void*)0xdeadbeef;
8328 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
8329 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
8330 ok(list == (void*)0xdeadbeef, "got %p\n", list);
8332 node = (void*)0xdeadbeef;
8333 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
8334 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8335 ok(node == 0, "got %p\n", node);
8337 list = (void*)0xdeadbeef;
8338 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
8339 ok(hr == S_OK, "got 0x%08x\n", hr);
8340 len = 1;
8341 hr = IXMLDOMNodeList_get_length(list, &len);
8342 ok(hr == S_OK, "got 0x%08x\n", hr);
8343 ok(len == 0, "got %d\n", len);
8344 IXMLDOMNodeList_Release(list);
8346 IXMLDOMDocument_Release(doc);
8347 free_bstrs();
8350 static void test_events(void)
8352 IConnectionPointContainer *conn;
8353 IConnectionPoint *point;
8354 IXMLDOMDocument *doc;
8355 HRESULT hr;
8357 doc = create_document(&IID_IXMLDOMDocument);
8358 if (!doc) return;
8360 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&conn);
8361 ok(hr == S_OK, "got 0x%08x\n", hr);
8363 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IDispatch, &point);
8364 ok(hr == S_OK, "got 0x%08x\n", hr);
8365 IConnectionPoint_Release(point);
8366 hr = IConnectionPointContainer_FindConnectionPoint(conn, &IID_IPropertyNotifySink, &point);
8367 ok(hr == S_OK, "got 0x%08x\n", hr);
8368 IConnectionPoint_Release(point);
8369 hr = IConnectionPointContainer_FindConnectionPoint(conn, &DIID_XMLDOMDocumentEvents, &point);
8370 ok(hr == S_OK, "got 0x%08x\n", hr);
8371 IConnectionPoint_Release(point);
8373 IConnectionPointContainer_Release(conn);
8375 IXMLDOMDocument_Release(doc);
8378 static void test_createProcessingInstruction(void)
8380 static const WCHAR bodyW[] = {'t','e','s','t',0};
8381 IXMLDOMProcessingInstruction *pi;
8382 IXMLDOMDocument *doc;
8383 WCHAR buff[10];
8384 HRESULT hr;
8386 doc = create_document(&IID_IXMLDOMDocument);
8387 if (!doc) return;
8389 /* test for BSTR handling, pass broken BSTR */
8390 memcpy(&buff[2], bodyW, sizeof(bodyW));
8391 /* just a big length */
8392 *(DWORD*)buff = 0xf0f0;
8393 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("test"), &buff[2], &pi);
8394 ok(hr == S_OK, "got 0x%08x\n", hr);
8396 IXMLDOMProcessingInstruction_Release(pi);
8397 IXMLDOMDocument_Release(doc);
8400 static void test_put_nodeTypedValue(void)
8402 IXMLDOMDocument *doc;
8403 IXMLDOMElement *elem;
8404 VARIANT type;
8405 HRESULT hr;
8407 doc = create_document(&IID_IXMLDOMDocument);
8408 if (!doc) return;
8410 hr = IXMLDOMDocument_createElement(doc, _bstr_("Element"), &elem);
8411 ok(hr == S_OK, "got 0x%08x\n", hr);
8413 V_VT(&type) = VT_EMPTY;
8414 hr = IXMLDOMElement_get_dataType(elem, &type);
8415 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8416 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8418 /* set typed value for untyped node */
8419 V_VT(&type) = VT_I1;
8420 V_I1(&type) = 1;
8421 hr = IXMLDOMElement_put_nodeTypedValue(elem, type);
8422 ok(hr == S_OK, "got 0x%08x\n", hr);
8424 V_VT(&type) = VT_EMPTY;
8425 hr = IXMLDOMElement_get_dataType(elem, &type);
8426 ok(hr == S_FALSE, "got 0x%08x\n", hr);
8427 ok(V_VT(&type) == VT_NULL, "got %d, expected VT_NULL\n", V_VT(&type));
8429 /* no type info stored */
8430 V_VT(&type) = VT_EMPTY;
8431 hr = IXMLDOMElement_get_nodeTypedValue(elem, &type);
8432 ok(hr == S_OK, "got 0x%08x\n", hr);
8433 ok(V_VT(&type) == VT_BSTR, "got %d, expected VT_BSTR\n", V_VT(&type));
8434 ok(memcmp(V_BSTR(&type), _bstr_("1"), 2*sizeof(WCHAR)) == 0,
8435 "got %s, expected \"1\"\n", wine_dbgstr_w(V_BSTR(&type)));
8436 VariantClear(&type);
8438 IXMLDOMDocument_Release(doc);
8439 free_bstrs();
8442 static void test_get_xml(void)
8444 static const char xmlA[] = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\r\n<a>test</a>\r\n";
8445 IXMLDOMProcessingInstruction *pi;
8446 IXMLDOMNode *first;
8447 IXMLDOMDocument *doc;
8448 VARIANT_BOOL b;
8449 VARIANT v;
8450 BSTR xml;
8451 HRESULT hr;
8453 doc = create_document(&IID_IXMLDOMDocument);
8454 if (!doc) return;
8456 b = VARIANT_TRUE;
8457 hr = IXMLDOMDocument_loadXML( doc, _bstr_("<a>test</a>"), &b );
8458 ok(hr == S_OK, "got 0x%08x\n", hr);
8459 ok( b == VARIANT_TRUE, "got %d\n", b);
8461 hr = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"),
8462 _bstr_("version=\"1.0\" encoding=\"UTF-16\""), &pi);
8463 ok(hr == S_OK, "got 0x%08x\n", hr);
8465 hr = IXMLDOMDocument_get_firstChild(doc, &first);
8466 ok(hr == S_OK, "got 0x%08x\n", hr);
8468 V_UNKNOWN(&v) = (IUnknown*)first;
8469 V_VT(&v) = VT_UNKNOWN;
8471 hr = IXMLDOMDocument_insertBefore(doc, (IXMLDOMNode*)pi, v, NULL);
8472 ok(hr == S_OK, "got 0x%08x\n", hr);
8474 IXMLDOMProcessingInstruction_Release(pi);
8475 IXMLDOMNode_Release(first);
8477 hr = IXMLDOMDocument_get_xml(doc, &xml);
8478 ok(hr == S_OK, "got 0x%08x\n", hr);
8480 ok(memcmp(xml, _bstr_(xmlA), sizeof(xmlA)*sizeof(WCHAR)) == 0,
8481 "got %s, expected %s\n", wine_dbgstr_w(xml), xmlA);
8482 SysFreeString(xml);
8484 IXMLDOMDocument_Release(doc);
8487 START_TEST(domdoc)
8489 IXMLDOMDocument *doc;
8490 HRESULT hr;
8492 hr = CoInitialize( NULL );
8493 ok( hr == S_OK, "failed to init com\n");
8494 if (hr != S_OK)
8495 return;
8497 test_XMLHTTP();
8499 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc );
8500 if (hr != S_OK)
8502 win_skip("IXMLDOMDocument is not available (0x%08x)\n", hr);
8503 return;
8506 IXMLDOMDocument_Release(doc);
8508 test_domdoc();
8509 test_persiststreaminit();
8510 test_domnode();
8511 test_refs();
8512 test_create();
8513 test_getElementsByTagName();
8514 test_get_text();
8515 test_get_childNodes();
8516 test_get_firstChild();
8517 test_get_lastChild();
8518 test_removeChild();
8519 test_replaceChild();
8520 test_removeNamedItem();
8521 test_IXMLDOMDocument2();
8522 test_whitespace();
8523 test_XPath();
8524 test_XSLPattern();
8525 test_cloneNode();
8526 test_xmlTypes();
8527 test_nodeTypeTests();
8528 test_DocumentSaveToDocument();
8529 test_DocumentSaveToFile();
8530 test_testTransforms();
8531 test_Namespaces();
8532 test_FormattingXML();
8533 test_nodeTypedValue();
8534 test_TransformWithLoadingLocalFile();
8535 test_put_nodeValue();
8536 test_document_IObjectSafety();
8537 test_splitText();
8538 test_getQualifiedItem();
8539 test_removeQualifiedItem();
8540 test_get_ownerDocument();
8541 test_setAttributeNode();
8542 test_get_dataType();
8543 test_put_dataType();
8544 test_createNode();
8545 test_get_prefix();
8546 test_default_properties();
8547 test_selectSingleNode();
8548 test_events();
8549 test_createProcessingInstruction();
8550 test_put_nodeTypedValue();
8551 test_get_xml();
8553 CoUninitialize();