4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "msxml2did.h"
35 #include "wine/test.h"
39 DEFINE_GUID(IID_IObjectSafety, 0xcb5bdc81, 0x93c1, 0x11cf, 0x8f,0x20, 0x00,0x80,0x5f,0x2c,0xd0,0x64);
40 DEFINE_GUID(CLSID_DOMDocument60, 0x88d96a05, 0xf192, 0x11d4, 0xa6,0x5f, 0x00,0x40,0x96,0x32,0x51,0xe5);
42 static const WCHAR szEmpty[] = { 0 };
43 static const WCHAR szIncomplete[] = {
44 '<','?','x','m','l',' ',
45 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
47 static const WCHAR szComplete1[] = {
48 '<','?','x','m','l',' ',
49 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
50 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
52 static const WCHAR szComplete2[] = {
53 '<','?','x','m','l',' ',
54 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
55 '<','o','>','<','/','o','>','\n',0
57 static const WCHAR szComplete3[] = {
58 '<','?','x','m','l',' ',
59 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
60 '<','a','>','<','/','a','>','\n',0
62 static const WCHAR szComplete4[] = {
63 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
64 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
65 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
66 'f','n','1','.','t','x','t','\n',
67 '<','/','b','s','>','\n',
68 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
69 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
70 'f','n','2','.','t','x','t','\n',
71 '<','/','p','r','>','\n',
72 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
76 '<','/','b','a','>','\n',
77 '<','/','f','o','>','\n',
78 '<','/','l','c','>','\n',0
80 static const WCHAR szComplete5[] = {
81 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
82 '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','"',
83 ' ','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','"','>',
84 '<','S',':','s','c','o','p','e','>',
85 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
86 '<','/','S',':','s','c','o','p','e','>',
87 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
88 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
89 'c','o','m','p','u','t','e','r',
90 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
91 '<','/','S',':','s','e','a','r','c','h','>',0
94 static const WCHAR szComplete6[] = {
95 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'',' ',
96 'e','n','c','o','d','i','n','g','=','\'','W','i','n','d','o','w','s','-','1','2','5','2','\'','?','>','\n',
97 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
100 static const CHAR szNonUnicodeXML[] =
101 "<?xml version='1.0' encoding='Windows-1252'?>\n"
104 static const CHAR szExampleXML[] =
105 "<?xml version='1.0' encoding='utf-8'?>\n"
106 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
111 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
112 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
113 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
115 " <html xml:space='preserve' xmlns='http://www.w3.org/1999/xhtml'>\n"
116 " This is <strong>a</strong> <i>description</i> with preserved whitespace. <bar:x/>\n"
124 " <c type=\"old\">C2 field</c>\n"
127 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
136 " <foo:c>C4 field</foo:c>\n"
140 static const CHAR szTransformXML[] =
141 "<?xml version=\"1.0\"?>\n"
146 static const CHAR szTransformSSXML[] =
147 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
148 " <xsl:output method=\"html\"/>\n"
149 " <xsl:template match=\"/\">\n"
150 " <xsl:apply-templates select=\"greeting\"/>\n"
152 " <xsl:template match=\"greeting\">\n"
156 " <xsl:value-of select=\".\"/>\n"
163 static const CHAR szTransformOutput[] =
166 "</h1></body></html>";
168 static const CHAR szTypeValueXML[] =
169 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
170 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
171 " <string>Wine</string>\n"
172 " <string2 dt:dt=\"string\">String</string2>\n"
173 " <number dt:dt=\"number\">12.44</number>\n"
174 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
175 " <int dt:dt=\"int\">-13</int>\n"
176 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
177 " <bool dt:dt=\"boolean\">1</bool>\n"
178 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
179 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
180 " <date dt:dt=\"date\">3721-11-01</date>\n"
181 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
182 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
183 " <i1 dt:dt=\"i1\">-13</i1>\n"
184 " <i2 dt:dt=\"i2\">31915</i2>\n"
185 " <i4 dt:dt=\"i4\">-312232</i4>\n"
186 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
187 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
188 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
189 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
190 " <r8 dt:dt=\"r8\">0.412</r8>\n"
191 " <float dt:dt=\"float\">41221.421</float>\n"
192 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
193 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
194 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
197 static const CHAR szBasicTransformSSXMLPart1[] =
198 "<?xml version=\"1.0\"?>"
199 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
200 "<xsl:output method=\"html\"/>\n"
201 "<xsl:template match=\"/\">"
202 "<HTML><BODY><TABLE>"
203 " <xsl:apply-templates select='document(\"";
205 static const CHAR szBasicTransformSSXMLPart2[] =
207 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
208 " </xsl:apply-templates>"
209 "</TABLE></BODY></HTML>"
211 "<xsl:template match=\"bottle\">"
212 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
214 "<xsl:template match=\"name\">"
215 " <TD><xsl:apply-templates /></TD>"
217 "<xsl:template match=\"cost\">"
218 " <TD><xsl:apply-templates /></TD>"
222 static const CHAR szBasicTransformXML[] =
223 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
225 static const CHAR szBasicTransformOutput[] =
226 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
228 static const WCHAR szNonExistentFile[] = {
229 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
231 static const WCHAR szNonExistentAttribute[] = {
232 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
234 static const WCHAR szDocument[] = {
235 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
238 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
239 static WCHAR szdl[] = { 'd','l',0 };
240 static const WCHAR szvr[] = { 'v','r',0 };
241 static const WCHAR szlc[] = { 'l','c',0 };
242 static WCHAR szbs[] = { 'b','s',0 };
243 static const WCHAR szstr1[] = { 's','t','r','1',0 };
244 static const WCHAR szstr2[] = { 's','t','r','2',0 };
245 static const WCHAR szstar[] = { '*',0 };
246 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
248 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
249 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
250 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
252 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
253 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
254 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
255 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
256 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
257 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
258 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
260 static WCHAR szAttribute[] = {'A','t','t','r',0 };
261 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
263 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
264 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
265 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
266 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
268 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
269 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
271 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
272 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
273 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
275 #define expect_bstr_eq_and_free(bstr, expect) { \
276 BSTR bstrExp = alloc_str_from_narrow(expect); \
277 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
278 SysFreeString(bstr); \
279 SysFreeString(bstrExp); \
282 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
284 #define ole_check(expr) { \
286 ok(r == S_OK, #expr " returned %x\n", r); \
289 #define ole_expect(expr, expect) { \
291 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
294 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
296 static void* _create_document(const IID *iid, int line)
301 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, iid, (void**)&doc );
302 ok_(__FILE__,line)( hr == S_OK, "failed to create CLSID_DOMDocument instance: 0x%08x\n", hr );
307 #define create_document(iid) _create_document(iid, __LINE__)
309 static BSTR alloc_str_from_narrow(const char *str)
311 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
312 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
313 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
317 static BSTR alloced_bstrs[256];
318 static int alloced_bstrs_count;
320 static BSTR _bstr_(const char *str)
322 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
323 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
324 return alloced_bstrs[alloced_bstrs_count++];
327 static void free_bstrs(void)
330 for (i = 0; i < alloced_bstrs_count; i++)
331 SysFreeString(alloced_bstrs[i]);
332 alloced_bstrs_count = 0;
335 static VARIANT _variantbstr_(const char *str)
339 V_BSTR(&v) = _bstr_(str);
343 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
347 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
348 while (*sRight == '\r' || *sRight == '\n') sRight++;
349 if (*sLeft != *sRight) return FALSE;
350 if (!*sLeft) return TRUE;
356 static BOOL compareIgnoreReturnsWhitespace(BSTR sLeft, BSTR sRight)
358 /* MSXML3 inserts whitespace where as libxml doesn't. */
361 while (*sLeft == '\r' || *sLeft == '\n' || *sLeft == ' ') sLeft++;
362 while (*sRight == '\r' || *sRight == '\n' || *sRight == ' ') sRight++;
363 if (*sLeft != *sRight) return FALSE;
364 if (!*sLeft) return TRUE;
370 static void get_str_for_type(DOMNodeType type, char *buf)
387 wsprintfA(buf, "[%d]", type);
391 #define test_disp(u) _test_disp(__LINE__,u)
392 static void _test_disp(unsigned line, IUnknown *unk)
394 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
402 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
403 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
408 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
409 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
410 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
412 sName = SysAllocString( szstar );
413 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
414 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
415 SysFreeString( sName );
417 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
418 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
420 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
421 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
422 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
424 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
425 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
427 SysFreeString(sName);
429 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
430 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
432 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
433 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
434 if(hres == S_OK && pUnk)
435 IUnknown_Release(pUnk);
437 IDispatchEx_Release(dispex);
440 static int get_node_position(IXMLDOMNode *node)
445 IXMLDOMNode_AddRef(node);
448 IXMLDOMNode *new_node;
451 r = IXMLDOMNode_get_previousSibling(node, &new_node);
452 ok(SUCCEEDED(r), "get_previousSibling failed\n");
453 IXMLDOMNode_Release(node);
459 static void node_to_string(IXMLDOMNode *node, char *buf)
466 lstrcpyA(buf, "(null)");
470 IXMLDOMNode_AddRef(node);
473 IXMLDOMNode *new_node;
475 ole_check(IXMLDOMNode_get_nodeType(node, &type));
476 get_str_for_type(type, buf);
479 if (type == NODE_ATTRIBUTE)
482 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
484 wsprintfA(buf, "%ws", bstr);
489 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
493 r = IXMLDOMNode_get_parentNode(node, &new_node);
494 wsprintf(buf, "%d", get_node_position(node));
498 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
499 IXMLDOMNode_Release(node);
508 static char *list_to_string(IXMLDOMNodeList *list)
510 static char buf[4096];
517 lstrcpyA(buf, "(null)");
520 ole_check(IXMLDOMNodeList_get_length(list, &len));
521 for (i = 0; i < len; i++)
526 ole_check(IXMLDOMNodeList_nextNode(list, &node));
527 node_to_string(node, pos);
529 IXMLDOMNode_Release(node);
535 #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); }
536 #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); }
538 static void test_domdoc( void )
541 IXMLDOMDocument *doc;
542 IXMLDOMParseError *error;
543 IXMLDOMElement *element = NULL;
545 IXMLDOMText *nodetext = NULL;
546 IXMLDOMComment *node_comment = NULL;
547 IXMLDOMAttribute *node_attr = NULL;
548 IXMLDOMNode *nodeChild = NULL;
549 IXMLDOMProcessingInstruction *nodePI = NULL;
550 ISupportErrorInfo *support_error = NULL;
558 doc = create_document(&IID_IXMLDOMDocument);
561 test_disp((IUnknown*)doc);
565 /* crashes on native */
566 r = IXMLDOMDocument_loadXML( doc, (BSTR)0x1, NULL );
569 /* try some stupid things */
570 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
571 ok( r == S_FALSE, "loadXML succeeded\n");
574 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
575 ok( r == S_FALSE, "loadXML succeeded\n");
576 ok( b == VARIANT_FALSE, "failed to load XML string\n");
578 /* try to load a document from a nonexistent file */
580 str = SysAllocString( szNonExistentFile );
582 V_VT(&var) = VT_BSTR;
585 r = IXMLDOMDocument_load( doc, var, &b);
586 ok( r == S_FALSE, "loadXML succeeded\n");
587 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
588 SysFreeString( str );
590 /* try load an empty document */
592 str = SysAllocString( szEmpty );
593 r = IXMLDOMDocument_loadXML( doc, str, &b );
594 ok( r == S_FALSE, "loadXML succeeded\n");
595 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
596 SysFreeString( str );
598 r = IXMLDOMDocument_get_async( doc, &b );
599 ok( r == S_OK, "get_async failed (%08x)\n", r);
600 ok( b == VARIANT_TRUE, "Wrong default value\n");
602 /* check that there's no document element */
604 r = IXMLDOMDocument_get_documentElement( doc, &element );
605 ok( r == S_FALSE, "should be no document element\n");
607 /* try finding a node */
609 str = SysAllocString( szstr1 );
610 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
611 ok( r == S_FALSE, "ret %08x\n", r );
612 SysFreeString( str );
615 str = SysAllocString( szIncomplete );
616 r = IXMLDOMDocument_loadXML( doc, str, &b );
617 ok( r == S_FALSE, "loadXML succeeded\n");
618 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
619 SysFreeString( str );
621 /* check that there's no document element */
622 element = (IXMLDOMElement*)1;
623 r = IXMLDOMDocument_get_documentElement( doc, &element );
624 ok( r == S_FALSE, "should be no document element\n");
625 ok( element == NULL, "Element should be NULL\n");
627 /* test for BSTR handling, pass broken BSTR */
628 memcpy(&buff[2], szComplete1, sizeof(szComplete1));
629 /* just a big length */
630 *(DWORD*)buff = 0xf0f0;
632 r = IXMLDOMDocument_loadXML( doc, &buff[2], &b );
633 ok( r == S_OK, "loadXML failed\n");
634 ok( b == VARIANT_TRUE, "failed to load XML string\n");
636 /* loadXML ignores the encoding attribute and always expects Unicode */
638 str = SysAllocString( szComplete6 );
639 r = IXMLDOMDocument_loadXML( doc, str, &b );
640 ok( r == S_OK, "loadXML failed\n");
641 ok( b == VARIANT_TRUE, "failed to load XML string\n");
642 SysFreeString( str );
644 /* try a BSTR containing a Windows-1252 document */
646 str = SysAllocStringByteLen( szNonUnicodeXML, sizeof(szNonUnicodeXML) - 1 );
647 r = IXMLDOMDocument_loadXML( doc, str, &b );
648 ok( r == S_FALSE, "loadXML succeeded\n");
649 ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
650 SysFreeString( str );
652 /* try to load something valid */
654 str = SysAllocString( szComplete1 );
655 r = IXMLDOMDocument_loadXML( doc, str, &b );
656 ok( r == S_OK, "loadXML failed\n");
657 ok( b == VARIANT_TRUE, "failed to load XML string\n");
658 SysFreeString( str );
660 /* check if nodename is correct */
661 r = IXMLDOMDocument_get_nodeName( doc, NULL );
662 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
664 str = (BSTR)0xdeadbeef;
665 r = IXMLDOMDocument_get_baseName( doc, &str );
666 ok ( r == S_FALSE, "got 0x%08x\n", r);
667 ok (str == NULL, "got %p\n", str);
669 /* content doesn't matter here */
671 r = IXMLDOMDocument_get_nodeName( doc, &str );
672 ok ( r == S_OK, "get_nodeName wrong code\n");
673 ok ( str != NULL, "str is null\n");
674 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
675 SysFreeString( str );
678 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
679 ok( r == E_FAIL, "ret %08x\n", r );
681 /* check that there's a document element */
683 r = IXMLDOMDocument_get_documentElement( doc, &element );
684 ok( r == S_OK, "should be a document element\n");
687 IObjectIdentity *ident;
690 test_disp((IUnknown*)element);
692 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (void**)&ident );
693 ok( r == E_NOINTERFACE, "ret %08x\n", r);
695 r = IXMLDOMElement_get_tagName( element, NULL );
696 ok( r == E_INVALIDARG, "ret %08x\n", r);
698 /* check if the tag is correct */
699 r = IXMLDOMElement_get_tagName( element, &tag );
700 ok( r == S_OK, "couldn't get tag name\n");
701 ok( tag != NULL, "tag was null\n");
702 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
703 SysFreeString( tag );
705 /* figure out what happens if we try to reload the document */
706 str = SysAllocString( szComplete2 );
707 r = IXMLDOMDocument_loadXML( doc, str, &b );
708 ok( r == S_OK, "loadXML failed\n");
709 ok( b == VARIANT_TRUE, "failed to load XML string\n");
710 SysFreeString( str );
712 /* check if the tag is still correct */
714 r = IXMLDOMElement_get_tagName( element, &tag );
715 ok( r == S_OK, "couldn't get tag name\n");
716 ok( tag != NULL, "tag was null\n");
717 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
718 SysFreeString( tag );
720 IXMLDOMElement_Release( element );
724 /* as soon as we call loadXML again, the document element will disappear */
726 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
727 ok( r == S_FALSE, "loadXML failed\n");
728 ok( b == 2, "variant modified\n");
729 r = IXMLDOMDocument_get_documentElement( doc, &element );
730 ok( r == S_FALSE, "should be no document element\n");
732 /* try to load something else simple and valid */
734 str = SysAllocString( szComplete3 );
735 r = IXMLDOMDocument_loadXML( doc, str, &b );
736 ok( r == S_OK, "loadXML failed\n");
737 ok( b == VARIANT_TRUE, "failed to load XML string\n");
738 SysFreeString( str );
740 /* try something a little more complicated */
742 str = SysAllocString( szComplete4 );
743 r = IXMLDOMDocument_loadXML( doc, str, &b );
744 ok( r == S_OK, "loadXML failed\n");
745 ok( b == VARIANT_TRUE, "failed to load XML string\n");
746 SysFreeString( str );
748 r = IXMLDOMDocument_get_parseError( doc, &error );
749 ok( r == S_OK, "returns %08x\n", r );
751 r = IXMLDOMParseError_get_errorCode( error, &code );
752 ok( r == S_FALSE, "returns %08x\n", r );
753 ok( code == 0, "code %d\n", code );
754 IXMLDOMParseError_Release( error );
756 /* test createTextNode */
757 r = IXMLDOMDocument_createTextNode(doc, _bstr_(""), &nodetext);
758 ok( r == S_OK, "returns %08x\n", r );
759 IXMLDOMText_Release(nodetext);
761 str = SysAllocString( szOpen );
762 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
763 ok( r == E_INVALIDARG, "returns %08x\n", r );
764 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
765 ok( r == S_OK, "returns %08x\n", r );
766 SysFreeString( str );
769 IXMLDOMNamedNodeMap *pAttribs;
771 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (void**)&element);
772 ok(r == E_NOINTERFACE, "ret %08x\n", r );
774 /* Text Last Child Checks */
775 r = IXMLDOMText_get_lastChild(nodetext, NULL);
776 ok(r == E_INVALIDARG, "ret %08x\n", r );
778 nodeChild = (IXMLDOMNode*)0x1;
779 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
780 ok(r == S_FALSE, "ret %08x\n", r );
781 ok(nodeChild == NULL, "nodeChild not NULL\n");
783 /* test get_attributes */
784 r = IXMLDOMText_get_attributes( nodetext, NULL );
785 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
787 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
788 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
789 ok(r == S_FALSE, "ret %08x\n", r );
790 ok( pAttribs == NULL, "pAttribs not NULL\n");
792 /* test get_dataType */
793 r = IXMLDOMText_get_dataType(nodetext, &var);
794 ok(r == S_FALSE, "ret %08x\n", r );
795 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
798 /* test length property */
799 r = IXMLDOMText_get_length(nodetext, NULL);
800 ok(r == E_INVALIDARG, "ret %08x\n", r );
802 r = IXMLDOMText_get_length(nodetext, &nLength);
803 ok(r == S_OK, "ret %08x\n", r );
804 ok(nLength == 4, "expected 4 got %d\n", nLength);
806 /* test nodeTypeString */
807 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
808 ok(r == S_OK, "ret %08x\n", r );
809 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
813 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
814 ok(r == S_OK, "ret %08x\n", r );
817 r = IXMLDOMText_get_data(nodetext, &str);
818 ok(r == S_OK, "ret %08x\n", r );
819 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
822 /* Confirm XML text is good */
823 r = IXMLDOMText_get_xml(nodetext, &str);
824 ok(r == S_OK, "ret %08x\n", r );
825 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
828 /* Confirm we get the put_data Text back */
829 r = IXMLDOMText_get_text(nodetext, &str);
830 ok(r == S_OK, "ret %08x\n", r );
831 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
834 /* test substringData */
835 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
836 ok(r == E_INVALIDARG, "ret %08x\n", r );
838 /* test substringData - Invalid offset */
839 str = (BSTR)&szElement;
840 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
841 ok(r == E_INVALIDARG, "ret %08x\n", r );
842 ok( str == NULL, "incorrect string\n");
844 /* test substringData - Invalid offset */
845 str = (BSTR)&szElement;
846 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
847 ok(r == S_FALSE, "ret %08x\n", r );
848 ok( str == NULL, "incorrect string\n");
850 /* test substringData - Invalid size */
851 str = (BSTR)&szElement;
852 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
853 ok(r == E_INVALIDARG, "ret %08x\n", r );
854 ok( str == NULL, "incorrect string\n");
856 /* test substringData - Invalid size */
857 str = (BSTR)&szElement;
858 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
859 ok(r == S_FALSE, "ret %08x\n", r );
860 ok( str == NULL, "incorrect string\n");
862 /* test substringData - Start of string */
863 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
864 ok(r == S_OK, "ret %08x\n", r );
865 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
868 /* test substringData - Middle of string */
869 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
870 ok(r == S_OK, "ret %08x\n", r );
871 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
874 /* test substringData - End of string */
875 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
876 ok(r == S_OK, "ret %08x\n", r );
877 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
880 /* test appendData */
881 r = IXMLDOMText_appendData(nodetext, NULL);
882 ok(r == S_OK, "ret %08x\n", r );
884 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
885 ok(r == S_OK, "ret %08x\n", r );
887 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
888 ok(r == S_OK, "ret %08x\n", r );
890 r = IXMLDOMText_get_text(nodetext, &str);
891 ok(r == S_OK, "ret %08x\n", r );
892 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
895 /* test insertData */
896 str = SysAllocStringLen(NULL, 0);
897 r = IXMLDOMText_insertData(nodetext, -1, str);
898 ok(r == S_OK, "ret %08x\n", r );
900 r = IXMLDOMText_insertData(nodetext, -1, NULL);
901 ok(r == S_OK, "ret %08x\n", r );
903 r = IXMLDOMText_insertData(nodetext, 1000, str);
904 ok(r == S_OK, "ret %08x\n", r );
906 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
907 ok(r == S_OK, "ret %08x\n", r );
909 r = IXMLDOMText_insertData(nodetext, 0, NULL);
910 ok(r == S_OK, "ret %08x\n", r );
912 r = IXMLDOMText_insertData(nodetext, 0, str);
913 ok(r == S_OK, "ret %08x\n", r );
916 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
917 ok(r == E_INVALIDARG, "ret %08x\n", r );
919 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
920 ok(r == E_INVALIDARG, "ret %08x\n", r );
922 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
923 ok(r == S_OK, "ret %08x\n", r );
925 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
926 ok(r == S_OK, "ret %08x\n", r );
928 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
929 ok(r == S_OK, "ret %08x\n", r );
931 r = IXMLDOMText_get_text(nodetext, &str);
932 ok(r == S_OK, "ret %08x\n", r );
933 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
937 /* invalid arguments */
938 r = IXMLDOMText_deleteData(nodetext, -1, 1);
939 ok(r == E_INVALIDARG, "ret %08x\n", r );
941 r = IXMLDOMText_deleteData(nodetext, 0, 0);
942 ok(r == S_OK, "ret %08x\n", r );
944 r = IXMLDOMText_deleteData(nodetext, 0, -1);
945 ok(r == E_INVALIDARG, "ret %08x\n", r );
947 r = IXMLDOMText_get_length(nodetext, &nLength);
948 ok(r == S_OK, "ret %08x\n", r );
949 ok(nLength == 43, "expected 43 got %d\n", nLength);
951 r = IXMLDOMText_deleteData(nodetext, nLength, 1);
952 ok(r == S_OK, "ret %08x\n", r );
954 r = IXMLDOMText_deleteData(nodetext, nLength+1, 1);
955 ok(r == E_INVALIDARG, "ret %08x\n", r );
957 /* delete from start */
958 r = IXMLDOMText_deleteData(nodetext, 0, 5);
959 ok(r == S_OK, "ret %08x\n", r );
961 r = IXMLDOMText_get_length(nodetext, &nLength);
962 ok(r == S_OK, "ret %08x\n", r );
963 ok(nLength == 38, "expected 38 got %d\n", nLength);
965 r = IXMLDOMText_get_text(nodetext, &str);
966 ok(r == S_OK, "ret %08x\n", r );
967 /* whitespace preserving needs to be handled here */
968 todo_wine ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
971 /* delete from end */
972 r = IXMLDOMText_deleteData(nodetext, 35, 3);
973 ok(r == S_OK, "ret %08x\n", r );
975 r = IXMLDOMText_get_length(nodetext, &nLength);
976 ok(r == S_OK, "ret %08x\n", r );
977 ok(nLength == 35, "expected 35 got %d\n", nLength);
979 r = IXMLDOMText_get_text(nodetext, &str);
980 ok(r == S_OK, "ret %08x\n", r );
981 todo_wine ok( !lstrcmpW( str, _bstr_("This &is a Middle; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
984 /* delete from inside */
985 r = IXMLDOMText_deleteData(nodetext, 1, 33);
986 ok(r == S_OK, "ret %08x\n", r );
988 r = IXMLDOMText_get_length(nodetext, &nLength);
989 ok(r == S_OK, "ret %08x\n", r );
990 ok(nLength == 2, "expected 2 got %d\n", nLength);
992 r = IXMLDOMText_get_text(nodetext, &str);
993 ok(r == S_OK, "ret %08x\n", r );
994 todo_wine ok( !lstrcmpW( str, _bstr_("") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
997 /* delete whole data ... */
998 r = IXMLDOMText_get_length(nodetext, &nLength);
999 ok(r == S_OK, "ret %08x\n", r );
1001 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1002 ok(r == S_OK, "ret %08x\n", r );
1003 /* ... and try again with empty string */
1004 r = IXMLDOMText_deleteData(nodetext, 0, nLength);
1005 ok(r == S_OK, "ret %08x\n", r );
1008 V_VT(&var) = VT_BSTR;
1009 V_BSTR(&var) = SysAllocString(szstr1);
1010 r = IXMLDOMText_put_nodeValue(nodetext, var);
1011 ok(r == S_OK, "ret %08x\n", r );
1014 r = IXMLDOMText_get_text(nodetext, &str);
1015 ok(r == S_OK, "ret %08x\n", r );
1016 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1022 r = IXMLDOMText_put_nodeValue(nodetext, var);
1023 ok(r == S_OK, "ret %08x\n", r );
1026 r = IXMLDOMText_get_text(nodetext, &str);
1027 ok(r == S_OK, "ret %08x\n", r );
1028 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1031 /* ::replaceData() */
1032 V_VT(&var) = VT_BSTR;
1033 V_BSTR(&var) = SysAllocString(szstr1);
1034 r = IXMLDOMText_put_nodeValue(nodetext, var);
1035 ok(r == S_OK, "ret %08x\n", r );
1038 r = IXMLDOMText_replaceData(nodetext, 6, 0, NULL);
1039 ok(r == E_INVALIDARG, "ret %08x\n", r );
1040 r = IXMLDOMText_get_text(nodetext, &str);
1041 ok(r == S_OK, "ret %08x\n", r );
1042 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1045 r = IXMLDOMText_replaceData(nodetext, 0, 0, NULL);
1046 ok(r == S_OK, "ret %08x\n", r );
1047 r = IXMLDOMText_get_text(nodetext, &str);
1048 ok(r == S_OK, "ret %08x\n", r );
1049 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1052 /* NULL pointer means delete */
1053 r = IXMLDOMText_replaceData(nodetext, 0, 1, NULL);
1054 ok(r == S_OK, "ret %08x\n", r );
1055 r = IXMLDOMText_get_text(nodetext, &str);
1056 ok(r == S_OK, "ret %08x\n", r );
1057 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1060 /* empty string means delete */
1061 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_(""));
1062 ok(r == S_OK, "ret %08x\n", r );
1063 r = IXMLDOMText_get_text(nodetext, &str);
1064 ok(r == S_OK, "ret %08x\n", r );
1065 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1068 /* zero count means insert */
1069 r = IXMLDOMText_replaceData(nodetext, 0, 0, _bstr_("a"));
1070 ok(r == S_OK, "ret %08x\n", r );
1071 r = IXMLDOMText_get_text(nodetext, &str);
1072 ok(r == S_OK, "ret %08x\n", r );
1073 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1076 r = IXMLDOMText_replaceData(nodetext, 0, 2, NULL);
1077 ok(r == S_OK, "ret %08x\n", r );
1079 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("m"));
1080 ok(r == S_OK, "ret %08x\n", r );
1081 r = IXMLDOMText_get_text(nodetext, &str);
1082 ok(r == S_OK, "ret %08x\n", r );
1083 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1086 /* nonempty string, count greater than its length */
1087 r = IXMLDOMText_replaceData(nodetext, 0, 2, _bstr_("a1.2"));
1088 ok(r == S_OK, "ret %08x\n", r );
1089 r = IXMLDOMText_get_text(nodetext, &str);
1090 ok(r == S_OK, "ret %08x\n", r );
1091 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1094 /* nonempty string, count less than its length */
1095 r = IXMLDOMText_replaceData(nodetext, 0, 1, _bstr_("wine"));
1096 ok(r == S_OK, "ret %08x\n", r );
1097 r = IXMLDOMText_get_text(nodetext, &str);
1098 ok(r == S_OK, "ret %08x\n", r );
1099 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
1102 IXMLDOMText_Release( nodetext );
1105 /* test Create Comment */
1106 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
1107 ok( r == E_INVALIDARG, "returns %08x\n", r );
1108 node_comment = (IXMLDOMComment*)0x1;
1111 r = IXMLDOMDocument_createComment(doc, _bstr_(""), &node_comment);
1112 ok( r == S_OK, "returns %08x\n", r );
1114 r = IXMLDOMComment_get_data(node_comment, &str);
1115 ok( r == S_OK, "returns %08x\n", r );
1116 ok( str && SysStringLen(str) == 0, "expected empty string data\n");
1117 IXMLDOMComment_Release(node_comment);
1120 r = IXMLDOMDocument_createComment(doc, NULL, &node_comment);
1121 ok( r == S_OK, "returns %08x\n", r );
1123 r = IXMLDOMComment_get_data(node_comment, &str);
1124 ok( r == S_OK, "returns %08x\n", r );
1125 ok( str && (SysStringLen(str) == 0), "expected empty string data\n");
1126 IXMLDOMComment_Release(node_comment);
1129 str = SysAllocString(szComment);
1130 r = IXMLDOMDocument_createComment(doc, str, &node_comment);
1132 ok( r == S_OK, "returns %08x\n", r );
1135 /* Last Child Checks */
1136 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
1137 ok(r == E_INVALIDARG, "ret %08x\n", r );
1139 nodeChild = (IXMLDOMNode*)0x1;
1140 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
1141 ok(r == S_FALSE, "ret %08x\n", r );
1142 ok(nodeChild == NULL, "pLastChild not NULL\n");
1145 str = (BSTR)0xdeadbeef;
1146 IXMLDOMComment_get_baseName(node_comment, &str);
1147 ok(r == S_FALSE, "ret %08x\n", r );
1148 ok(str == NULL, "Expected NULL\n");
1150 IXMLDOMComment_Release( node_comment );
1153 /* test Create Attribute */
1154 str = SysAllocString(szAttribute);
1155 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
1156 ok( r == E_INVALIDARG, "returns %08x\n", r );
1157 r = IXMLDOMDocument_createAttribute(doc, str, &node_attr);
1158 ok( r == S_OK, "returns %08x\n", r );
1159 IXMLDOMText_Release( node_attr);
1162 /* test Processing Instruction */
1163 str = SysAllocStringLen(NULL, 0);
1164 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
1165 ok( r == E_INVALIDARG, "returns %08x\n", r );
1166 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
1167 ok( r == E_FAIL, "returns %08x\n", r );
1168 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
1169 ok( r == E_FAIL, "returns %08x\n", r );
1172 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
1173 ok( r == S_OK, "returns %08x\n", r );
1176 /* Last Child Checks */
1177 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
1178 ok(r == E_INVALIDARG, "ret %08x\n", r );
1180 nodeChild = (IXMLDOMNode*)0x1;
1181 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
1182 ok(r == S_FALSE, "ret %08x\n", r );
1183 ok(nodeChild == NULL, "nodeChild not NULL\n");
1185 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
1186 ok(r == S_FALSE, "ret %08x\n", r );
1187 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
1191 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1192 ok(r == S_OK, "ret %08x\n", r );
1193 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1198 r = IXMLDOMProcessingInstruction_get_baseName(nodePI, &str);
1199 ok(r == S_OK, "ret %08x\n", r );
1200 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1204 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
1205 ok(r == S_OK, "ret %08x\n", r );
1206 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
1209 /* test nodeTypeString */
1210 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
1211 ok(r == S_OK, "ret %08x\n", r );
1212 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
1215 /* test get_nodeValue */
1216 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
1217 ok(r == S_OK, "ret %08x\n", r );
1218 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1222 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
1223 ok(r == S_OK, "ret %08x\n", r );
1224 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
1228 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
1229 ok(r == E_FAIL, "ret %08x\n", r );
1232 V_VT(&var) = VT_BSTR;
1233 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
1234 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
1235 ok(r == E_FAIL, "ret %08x\n", r );
1238 /* test get nodeName */
1239 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
1240 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
1241 ok(r == S_OK, "ret %08x\n", r );
1244 IXMLDOMProcessingInstruction_Release(nodePI);
1247 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (void**)&support_error );
1248 ok( r == S_OK, "ret %08x\n", r );
1251 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
1252 todo_wine ok( r == S_OK, "ret %08x\n", r );
1253 ISupportErrorInfo_Release( support_error );
1256 r = IXMLDOMDocument_Release( doc );
1257 ok( r == 0, "document ref count incorrect\n");
1262 static void test_persiststreaminit(void)
1264 IXMLDOMDocument *doc;
1265 IPersistStreamInit *streaminit;
1268 doc = create_document(&IID_IXMLDOMDocument);
1271 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&streaminit);
1272 ok( hr == S_OK, "failed with 0x%08x\n", hr );
1274 hr = IPersistStreamInit_InitNew(streaminit);
1275 ok( hr == S_OK, "failed with 0x%08x\n", hr );
1277 IXMLDOMDocument_Release(doc);
1280 static void test_domnode( void )
1283 IXMLDOMDocument *doc, *owner = NULL;
1284 IXMLDOMElement *element = NULL;
1285 IXMLDOMNamedNodeMap *map = NULL;
1286 IXMLDOMNode *node = NULL, *next = NULL;
1287 IXMLDOMNodeList *list = NULL;
1288 IXMLDOMAttribute *attr = NULL;
1289 DOMNodeType type = NODE_INVALID;
1295 doc = create_document(&IID_IXMLDOMDocument);
1299 str = SysAllocString( szComplete4 );
1300 r = IXMLDOMDocument_loadXML( doc, str, &b );
1301 ok( r == S_OK, "loadXML failed\n");
1302 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1303 SysFreeString( str );
1306 r = IXMLDOMNode_hasChildNodes( doc, &b );
1307 ok( r == S_OK, "hasChildNoes bad return\n");
1308 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1310 r = IXMLDOMDocument_get_documentElement( doc, &element );
1311 ok( r == S_OK, "should be a document element\n");
1312 ok( element != NULL, "should be an element\n");
1315 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1317 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1318 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1320 r = IXMLDOMNode_get_nodeValue( doc, &var );
1321 ok( r == S_FALSE, "nextNode returned wrong code\n");
1322 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1323 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1328 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1329 ok( r == S_OK, "get_ownerDocument return code\n");
1330 ok( owner != doc, "get_ownerDocument return\n");
1331 IXMLDOMDocument_Release(owner);
1333 type = NODE_INVALID;
1334 r = IXMLDOMNode_get_nodeType( element, &type);
1335 ok( r == S_OK, "got %08x\n", r);
1336 ok( type == NODE_ELEMENT, "node not an element\n");
1339 r = IXMLDOMNode_get_baseName( element, &str );
1340 ok( r == S_OK, "get_baseName returned wrong code\n");
1341 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1344 /* check if nodename is correct */
1345 r = IXMLDOMElement_get_nodeName( element, NULL );
1346 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1348 /* content doesn't matter here */
1350 r = IXMLDOMElement_get_nodeName( element, &str );
1351 ok ( r == S_OK, "get_nodeName wrong code\n");
1352 ok ( str != NULL, "str is null\n");
1353 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1354 SysFreeString( str );
1356 str = SysAllocString( szNonExistentFile );
1358 V_I4(&var) = 0x1234;
1359 r = IXMLDOMElement_getAttribute( element, str, &var );
1360 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1361 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1364 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1365 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1367 attr = (IXMLDOMAttribute*)0xdeadbeef;
1368 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1369 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1370 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1371 SysFreeString( str );
1373 attr = (IXMLDOMAttribute*)0xdeadbeef;
1374 str = SysAllocString( szNonExistentAttribute );
1375 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1376 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1377 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1378 SysFreeString( str );
1380 str = SysAllocString( szdl );
1382 V_I4(&var) = 0x1234;
1383 r = IXMLDOMElement_getAttribute( element, str, &var );
1384 ok( r == S_OK, "getAttribute ret %08x\n", r );
1385 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1386 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1387 VariantClear( &var );
1389 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1390 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1392 r = IXMLDOMElement_getAttribute( element, str, NULL );
1393 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1396 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1397 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1398 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1401 r = IXMLDOMAttribute_get_parentNode( attr, NULL );
1402 ok( r == E_INVALIDARG, "Expected E_INVALIDARG, ret %08x\n", r );
1404 /* attribute doesn't have a parent in msxml interpretation */
1405 node = (IXMLDOMNode*)0xdeadbeef;
1406 r = IXMLDOMAttribute_get_parentNode( attr, &node );
1407 ok( r == S_FALSE, "Expected S_FALSE, ret %08x\n", r );
1408 ok( node == NULL, "Expected NULL, got %p\n", node );
1410 IXMLDOMAttribute_Release(attr);
1413 SysFreeString( str );
1415 r = IXMLDOMElement_get_attributes( element, &map );
1416 ok( r == S_OK, "get_attributes returned wrong code\n");
1417 ok( map != NULL, "should be attributes\n");
1420 r = IXMLDOMNode_hasChildNodes( element, &b );
1421 ok( r == S_OK, "hasChildNoes bad return\n");
1422 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1425 ok( FALSE, "no element\n");
1429 ISupportErrorInfo *support_error;
1430 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (void**)&support_error );
1431 ok( r == S_OK, "ret %08x\n", r );
1433 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1436 ok( r == S_OK, "ret %08x\n", r );
1438 ISupportErrorInfo_Release( support_error );
1440 str = SysAllocString( szdl );
1441 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1442 ok( r == S_OK, "getNamedItem returned wrong code\n");
1443 ok( node != NULL, "should be attributes\n");
1444 IXMLDOMNode_Release(node);
1445 SysFreeString( str );
1447 str = SysAllocString( szdl );
1448 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1449 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1450 SysFreeString( str );
1452 /* something that isn't in szComplete4 */
1453 str = SysAllocString( szOpen );
1454 node = (IXMLDOMNode *) 1;
1455 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1456 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1457 ok( node == NULL, "getNamedItem should have returned NULL\n");
1458 SysFreeString( str );
1460 /* test indexed access of attributes */
1461 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1462 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1464 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1465 ok ( r == S_OK, "get_length wrong code\n");
1466 ok ( count == 1, "get_length != 1\n");
1469 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1470 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1471 ok ( node == NULL, "there is no node\n");
1474 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1475 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1476 ok ( node == NULL, "there is no attribute\n");
1479 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1480 ok ( r == S_OK, "get_item (0) wrong code\n");
1481 ok ( node != NULL, "should be attribute\n");
1483 r = IXMLDOMNode_get_nodeName( node, NULL );
1484 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1486 /* content doesn't matter here */
1488 r = IXMLDOMNode_get_nodeName( node, &str );
1489 ok ( r == S_OK, "get_nodeName wrong code\n");
1490 ok ( str != NULL, "str is null\n");
1491 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1492 SysFreeString( str );
1494 /* test sequential access of attributes */
1496 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1497 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1498 ok ( node != NULL, "nextNode, should be attribute\n");
1500 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1501 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1502 ok ( node == NULL, "nextNode, there is no attribute\n");
1504 r = IXMLDOMNamedNodeMap_reset( map );
1505 ok ( r == S_OK, "reset should return S_OK\n");
1507 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1508 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1509 ok ( node != NULL, "nextNode, should be attribute\n");
1512 ok( FALSE, "no map\n");
1516 type = NODE_INVALID;
1517 r = IXMLDOMNode_get_nodeType( node, &type);
1518 ok( r == S_OK, "getNamedItem returned wrong code\n");
1519 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1522 r = IXMLDOMNode_get_baseName( node, NULL );
1523 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1526 r = IXMLDOMNode_get_baseName( node, &str );
1527 ok( r == S_OK, "get_baseName returned wrong code\n");
1528 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1529 SysFreeString( str );
1531 r = IXMLDOMNode_get_nodeValue( node, &var );
1532 ok( r == S_OK, "returns %08x\n", r );
1533 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1534 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1537 r = IXMLDOMNode_get_childNodes( node, NULL );
1538 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1540 r = IXMLDOMNode_get_childNodes( node, &list );
1541 ok( r == S_OK, "get_childNodes returned wrong code\n");
1545 r = IXMLDOMNodeList_nextNode( list, &next );
1546 ok( r == S_OK, "nextNode returned wrong code\n");
1549 ok( FALSE, "no childlist\n");
1554 r = IXMLDOMNode_hasChildNodes( next, &b );
1555 ok( r == S_FALSE, "hasChildNoes bad return\n");
1556 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1558 type = NODE_INVALID;
1559 r = IXMLDOMNode_get_nodeType( next, &type);
1560 ok( r == S_OK, "getNamedItem returned wrong code\n");
1561 ok( type == NODE_TEXT, "node not text\n");
1564 r = IXMLDOMNode_get_baseName( next, &str );
1565 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1566 ok( str == NULL, "basename was wrong\n");
1570 ok( FALSE, "no next\n");
1573 IXMLDOMNode_Release( next );
1576 IXMLDOMNodeList_Release( list );
1579 IXMLDOMNode_Release( node );
1582 ok( FALSE, "no node\n");
1586 IXMLDOMNamedNodeMap_Release( map );
1588 /* now traverse the tree from the root element */
1591 r = IXMLDOMNode_get_childNodes( element, &list );
1592 ok( r == S_OK, "get_childNodes returned wrong code\n");
1594 /* using get_item for child list doesn't advance the position */
1595 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1596 expect_node(node, "E2.E2.D1");
1597 IXMLDOMNode_Release(node);
1598 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1599 expect_node(node, "E1.E2.D1");
1600 IXMLDOMNode_Release(node);
1601 ole_check(IXMLDOMNodeList_reset(list));
1603 IXMLDOMNodeList_AddRef(list);
1604 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1605 ole_check(IXMLDOMNodeList_reset(list));
1607 node = (void*)0xdeadbeef;
1608 str = SysAllocString(szdl);
1609 r = IXMLDOMNode_selectSingleNode( element, str, &node );
1611 ok( r == S_FALSE, "ret %08x\n", r );
1612 ok( node == NULL, "node %p\n", node );
1614 str = SysAllocString(szbs);
1615 r = IXMLDOMNode_selectSingleNode( element, str, &node );
1617 ok( r == S_OK, "ret %08x\n", r );
1618 r = IXMLDOMNode_Release( node );
1619 ok( r == 0, "ret %08x\n", r );
1622 ok( FALSE, "no element\n");
1626 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1627 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1629 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1630 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1632 r = IXMLDOMNodeList_get_length(list, NULL);
1633 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1635 r = IXMLDOMNodeList_get_length( list, &count );
1636 ok( r == S_OK, "get_length returns %08x\n", r );
1637 ok( count == 4, "get_length got %d\n", count );
1639 r = IXMLDOMNodeList_nextNode(list, NULL);
1640 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1642 r = IXMLDOMNodeList_nextNode( list, &node );
1643 ok( r == S_OK, "nextNode returned wrong code\n");
1646 ok( FALSE, "no list\n");
1650 type = NODE_INVALID;
1651 r = IXMLDOMNode_get_nodeType( node, &type);
1652 ok( r == S_OK, "getNamedItem returned wrong code\n");
1653 ok( type == NODE_ELEMENT, "node not text\n");
1656 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1657 r = IXMLDOMNode_get_nodeValue( node, &var );
1658 ok( r == S_FALSE, "nextNode returned wrong code\n");
1659 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1660 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1662 r = IXMLDOMNode_hasChildNodes( node, NULL );
1663 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1666 r = IXMLDOMNode_hasChildNodes( node, &b );
1667 ok( r == S_OK, "hasChildNoes bad return\n");
1668 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1671 r = IXMLDOMNode_get_baseName( node, &str );
1672 ok( r == S_OK, "get_baseName returned wrong code\n");
1673 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1677 ok( FALSE, "no node\n");
1680 IXMLDOMNode_Release( node );
1682 IXMLDOMNodeList_Release( list );
1684 IXMLDOMElement_Release( element );
1687 str = SysAllocString( szComplete5 );
1688 r = IXMLDOMDocument_loadXML( doc, str, &b );
1689 ok( r == S_OK, "loadXML failed\n");
1690 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1691 SysFreeString( str );
1694 r = IXMLDOMNode_hasChildNodes( doc, &b );
1695 ok( r == S_OK, "hasChildNoes bad return\n");
1696 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1698 r = IXMLDOMDocument_get_documentElement( doc, &element );
1699 ok( r == S_OK, "should be a document element\n");
1700 ok( element != NULL, "should be an element\n");
1704 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1707 /* check if the tag is correct */
1708 r = IXMLDOMElement_get_tagName( element, &tag );
1709 ok( r == S_OK, "couldn't get tag name\n");
1710 ok( tag != NULL, "tag was null\n");
1711 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1712 SysFreeString( tag );
1716 IXMLDOMElement_Release( element );
1717 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1720 static void test_refs(void)
1725 IXMLDOMDocument *doc;
1726 IXMLDOMElement *element = NULL;
1727 IXMLDOMNode *node = NULL, *node2;
1728 IXMLDOMNodeList *node_list = NULL;
1730 IUnknown *unk, *unk2;
1732 doc = create_document(&IID_IXMLDOMDocument);
1735 ref = IXMLDOMDocument_Release(doc);
1736 ok( ref == 0, "ref %d\n", ref);
1738 doc = create_document(&IID_IXMLDOMDocument);
1741 str = SysAllocString( szComplete4 );
1742 r = IXMLDOMDocument_loadXML( doc, str, &b );
1743 ok( r == S_OK, "loadXML failed\n");
1744 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1745 SysFreeString( str );
1747 ref = IXMLDOMDocument_AddRef( doc );
1748 ok( ref == 2, "ref %d\n", ref );
1749 ref = IXMLDOMDocument_AddRef( doc );
1750 ok( ref == 3, "ref %d\n", ref );
1751 IXMLDOMDocument_Release( doc );
1752 IXMLDOMDocument_Release( doc );
1754 r = IXMLDOMDocument_get_documentElement( doc, &element );
1755 ok( r == S_OK, "should be a document element\n");
1756 ok( element != NULL, "should be an element\n");
1758 ref = IXMLDOMDocument_AddRef( doc );
1759 ok( ref == 2, "ref %d\n", ref );
1760 IXMLDOMDocument_Release( doc );
1762 r = IXMLDOMElement_get_childNodes( element, &node_list );
1763 ok( r == S_OK, "rets %08x\n", r);
1765 ref = IXMLDOMNodeList_AddRef( node_list );
1766 ok( ref == 2, "ref %d\n", ref );
1767 IXMLDOMNodeList_Release( node_list );
1769 IXMLDOMNodeList_get_item( node_list, 0, &node );
1770 ok( r == S_OK, "rets %08x\n", r);
1772 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1773 ok( r == S_OK, "rets %08x\n", r);
1775 ref = IXMLDOMNode_AddRef( node );
1776 ok( ref == 2, "ref %d\n", ref );
1777 IXMLDOMNode_Release( node );
1779 ref = IXMLDOMNode_Release( node );
1780 ok( ref == 0, "ref %d\n", ref );
1781 ref = IXMLDOMNode_Release( node2 );
1782 ok( ref == 0, "ref %d\n", ref );
1784 ref = IXMLDOMNodeList_Release( node_list );
1785 ok( ref == 0, "ref %d\n", ref );
1787 ok( node != node2, "node %p node2 %p\n", node, node2 );
1789 ref = IXMLDOMDocument_Release( doc );
1790 ok( ref == 0, "ref %d\n", ref );
1792 ref = IXMLDOMElement_AddRef( element );
1794 ok( ref == 3, "ref %d\n", ref );
1796 IXMLDOMElement_Release( element );
1798 /* IUnknown must be unique however we obtain it */
1799 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (void**)&unk );
1800 ok( r == S_OK, "rets %08x\n", r );
1801 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (void**)&node );
1802 ok( r == S_OK, "rets %08x\n", r );
1803 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk2 );
1804 ok( r == S_OK, "rets %08x\n", r );
1805 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1807 IUnknown_Release( unk2 );
1808 IUnknown_Release( unk );
1809 IXMLDOMNode_Release( node );
1811 IXMLDOMElement_Release( element );
1815 static void test_create(void)
1817 static const WCHAR szOne[] = {'1',0};
1818 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1822 IXMLDOMDocument *doc;
1823 IXMLDOMElement *element;
1824 IXMLDOMComment *comment;
1826 IXMLDOMCDATASection *cdata;
1827 IXMLDOMNode *root, *node, *child;
1828 IXMLDOMNamedNodeMap *attr_map;
1833 doc = create_document(&IID_IXMLDOMDocument);
1836 /* types not supported for creation */
1838 V_I1(&var) = NODE_DOCUMENT;
1839 node = (IXMLDOMNode*)0x1;
1840 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
1841 ok( r == E_INVALIDARG, "returns %08x\n", r );
1842 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
1845 V_I1(&var) = NODE_DOCUMENT_TYPE;
1846 node = (IXMLDOMNode*)0x1;
1847 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
1848 ok( r == E_INVALIDARG, "returns %08x\n", r );
1849 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
1852 V_I1(&var) = NODE_ENTITY;
1853 node = (IXMLDOMNode*)0x1;
1854 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
1855 ok( r == E_INVALIDARG, "returns %08x\n", r );
1856 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
1859 V_I1(&var) = NODE_NOTATION;
1860 node = (IXMLDOMNode*)0x1;
1861 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
1862 ok( r == E_INVALIDARG, "returns %08x\n", r );
1863 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
1867 V_I1(&var) = NODE_COMMENT;
1869 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
1870 ok( r == S_OK, "returns %08x\n", r );
1871 ok( node != NULL, "\n");
1873 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
1874 ok( r == S_OK, "returns %08x\n", r );
1875 IXMLDOMNode_Release(node);
1878 r = IXMLDOMComment_get_data(comment, &str);
1879 ok( r == S_OK, "returns %08x\n", r );
1880 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1881 IXMLDOMComment_Release(comment);
1884 node = (IXMLDOMNode*)0x1;
1885 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
1886 ok( r == S_OK, "returns %08x\n", r );
1888 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
1889 ok( r == S_OK, "returns %08x\n", r );
1890 IXMLDOMNode_Release(node);
1893 r = IXMLDOMComment_get_data(comment, &str);
1894 ok( r == S_OK, "returns %08x\n", r );
1895 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1896 IXMLDOMComment_Release(comment);
1899 node = (IXMLDOMNode*)0x1;
1900 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
1901 ok( r == S_OK, "returns %08x\n", r );
1903 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMComment, (void**)&comment);
1904 ok( r == S_OK, "returns %08x\n", r );
1905 IXMLDOMNode_Release(node);
1908 r = IXMLDOMComment_get_data(comment, &str);
1909 ok( r == S_OK, "returns %08x\n", r );
1910 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1911 IXMLDOMComment_Release(comment);
1916 V_I1(&var) = NODE_TEXT;
1918 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
1919 ok( r == S_OK, "returns %08x\n", r );
1920 ok( node != NULL, "\n");
1922 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
1923 ok( r == S_OK, "returns %08x\n", r );
1924 IXMLDOMNode_Release(node);
1927 r = IXMLDOMText_get_data(text, &str);
1928 ok( r == S_OK, "returns %08x\n", r );
1929 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1930 IXMLDOMText_Release(text);
1933 node = (IXMLDOMNode*)0x1;
1934 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
1935 ok( r == S_OK, "returns %08x\n", r );
1937 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
1938 ok( r == S_OK, "returns %08x\n", r );
1939 IXMLDOMNode_Release(node);
1942 r = IXMLDOMText_get_data(text, &str);
1943 ok( r == S_OK, "returns %08x\n", r );
1944 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1945 IXMLDOMText_Release(text);
1948 node = (IXMLDOMNode*)0x1;
1949 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
1950 ok( r == S_OK, "returns %08x\n", r );
1952 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMText, (void**)&text);
1953 ok( r == S_OK, "returns %08x\n", r );
1954 IXMLDOMNode_Release(node);
1957 r = IXMLDOMText_get_data(text, &str);
1958 ok( r == S_OK, "returns %08x\n", r );
1959 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1960 IXMLDOMText_Release(text);
1963 /* NODE_CDATA_SECTION */
1965 V_I1(&var) = NODE_CDATA_SECTION;
1967 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
1968 ok( r == S_OK, "returns %08x\n", r );
1969 ok( node != NULL, "\n");
1971 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
1972 ok( r == S_OK, "returns %08x\n", r );
1973 IXMLDOMNode_Release(node);
1976 r = IXMLDOMCDATASection_get_data(cdata, &str);
1977 ok( r == S_OK, "returns %08x\n", r );
1978 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1979 IXMLDOMCDATASection_Release(cdata);
1982 node = (IXMLDOMNode*)0x1;
1983 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
1984 ok( r == S_OK, "returns %08x\n", r );
1986 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
1987 ok( r == S_OK, "returns %08x\n", r );
1988 IXMLDOMNode_Release(node);
1991 r = IXMLDOMCDATASection_get_data(cdata, &str);
1992 ok( r == S_OK, "returns %08x\n", r );
1993 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
1994 IXMLDOMCDATASection_Release(cdata);
1997 node = (IXMLDOMNode*)0x1;
1998 r = IXMLDOMDocument_createNode( doc, var, _bstr_("blah"), NULL, &node );
1999 ok( r == S_OK, "returns %08x\n", r );
2001 r = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMCDATASection, (void**)&cdata);
2002 ok( r == S_OK, "returns %08x\n", r );
2003 IXMLDOMNode_Release(node);
2006 r = IXMLDOMCDATASection_get_data(cdata, &str);
2007 ok( r == S_OK, "returns %08x\n", r );
2008 ok( str && SysStringLen(str) == 0, "expected empty comment, %p\n", str);
2009 IXMLDOMCDATASection_Release(cdata);
2012 /* NODE_ATTRIBUTE */
2014 V_I1(&var) = NODE_ATTRIBUTE;
2015 node = (IXMLDOMNode*)0x1;
2016 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2017 ok( r == E_FAIL, "returns %08x\n", r );
2018 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2021 V_I1(&var) = NODE_ATTRIBUTE;
2022 node = (IXMLDOMNode*)0x1;
2023 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2024 ok( r == E_FAIL, "returns %08x\n", r );
2025 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2028 V_I1(&var) = NODE_ATTRIBUTE;
2029 str = SysAllocString( szlc );
2030 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2031 ok( r == S_OK, "returns %08x\n", r );
2032 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2035 /* a name is required for attribute, try a BSTR with first null wchar */
2037 V_I1(&var) = NODE_ATTRIBUTE;
2038 str = SysAllocString( szstr1 );
2040 node = (IXMLDOMNode*)0x1;
2041 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2042 ok( r == E_FAIL, "returns %08x\n", r );
2043 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2046 /* NODE_PROCESSING_INSTRUCTION */
2048 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2049 node = (IXMLDOMNode*)0x1;
2050 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2051 ok( r == E_FAIL, "returns %08x\n", r );
2052 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2055 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2056 node = (IXMLDOMNode*)0x1;
2057 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2058 ok( r == E_FAIL, "returns %08x\n", r );
2059 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2062 V_I1(&var) = NODE_PROCESSING_INSTRUCTION;
2063 r = IXMLDOMDocument_createNode( doc, var, _bstr_("pi"), NULL, NULL );
2064 ok( r == E_INVALIDARG, "returns %08x\n", r );
2066 /* NODE_ENTITY_REFERENCE */
2068 V_I1(&var) = NODE_ENTITY_REFERENCE;
2069 node = (IXMLDOMNode*)0x1;
2070 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2071 ok( r == E_FAIL, "returns %08x\n", r );
2072 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2075 V_I1(&var) = NODE_ENTITY_REFERENCE;
2076 node = (IXMLDOMNode*)0x1;
2077 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2078 ok( r == E_FAIL, "returns %08x\n", r );
2079 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2083 V_I1(&var) = NODE_ELEMENT;
2084 node = (IXMLDOMNode*)0x1;
2085 r = IXMLDOMDocument_createNode( doc, var, NULL, NULL, &node );
2086 ok( r == E_FAIL, "returns %08x\n", r );
2087 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2090 V_I1(&var) = NODE_ELEMENT;
2091 node = (IXMLDOMNode*)0x1;
2092 r = IXMLDOMDocument_createNode( doc, var, _bstr_(""), NULL, &node );
2093 ok( r == E_FAIL, "returns %08x\n", r );
2094 ok( node == (void*)0x1, "expected same ptr, got %p\n", node);
2097 V_I1(&var) = NODE_ELEMENT;
2098 str = SysAllocString( szlc );
2099 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2100 ok( r == S_OK, "returns %08x\n", r );
2101 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2104 V_I1(&var) = NODE_ELEMENT;
2105 r = IXMLDOMDocument_createNode( doc, var, str, NULL, NULL );
2106 ok( r == E_INVALIDARG, "returns %08x\n", r );
2109 V_R4(&var) = NODE_ELEMENT;
2110 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2111 ok( r == S_OK, "returns %08x\n", r );
2112 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2114 V_VT(&var) = VT_BSTR;
2115 V_BSTR(&var) = SysAllocString( szOne );
2116 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2117 ok( r == S_OK, "returns %08x\n", r );
2118 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2121 V_VT(&var) = VT_BSTR;
2122 V_BSTR(&var) = SysAllocString( szOneGarbage );
2123 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2124 ok( r == E_INVALIDARG, "returns %08x\n", r );
2125 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
2129 V_I4(&var) = NODE_ELEMENT;
2130 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2131 ok( r == S_OK, "returns %08x\n", r );
2132 r = IXMLDOMDocument_appendChild( doc, node, &root );
2133 ok( r == S_OK, "returns %08x\n", r );
2134 ok( node == root, "%p %p\n", node, root );
2136 ref = IXMLDOMNode_AddRef( node );
2137 ok(ref == 3, "ref %d\n", ref);
2138 IXMLDOMNode_Release( node );
2140 ref = IXMLDOMNode_Release( node );
2141 ok(ref == 1, "ref %d\n", ref);
2142 SysFreeString( str );
2145 V_I4(&var) = NODE_ELEMENT;
2146 str = SysAllocString( szbs );
2147 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2148 ok( r == S_OK, "returns %08x\n", r );
2149 SysFreeString( str );
2151 ref = IXMLDOMNode_AddRef( node );
2152 ok(ref == 2, "ref = %d\n", ref);
2153 IXMLDOMNode_Release( node );
2155 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (void**)&unk );
2156 ok( r == S_OK, "returns %08x\n", r );
2158 ref = IXMLDOMNode_AddRef( unk );
2159 ok(ref == 3, "ref = %d\n", ref);
2160 IXMLDOMNode_Release( unk );
2162 V_VT(&var) = VT_EMPTY;
2163 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
2164 ok( r == S_OK, "returns %08x\n", r );
2165 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
2166 IXMLDOMNode_Release( child );
2167 IUnknown_Release( unk );
2170 V_VT(&var) = VT_NULL;
2171 V_DISPATCH(&var) = (IDispatch*)node;
2172 r = IXMLDOMNode_insertBefore( root, node, var, &child );
2173 ok( r == S_OK, "returns %08x\n", r );
2174 ok( node == child, "%p %p\n", node, child );
2175 IXMLDOMNode_Release( child );
2178 V_VT(&var) = VT_NULL;
2179 V_DISPATCH(&var) = (IDispatch*)node;
2180 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
2181 ok( r == S_OK, "returns %08x\n", r );
2182 IXMLDOMNode_Release( node );
2184 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (void**)&element );
2185 ok( r == S_OK, "returns %08x\n", r );
2187 r = IXMLDOMElement_get_attributes( element, &attr_map );
2188 ok( r == S_OK, "returns %08x\n", r );
2189 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2190 ok( r == S_OK, "returns %08x\n", r );
2191 ok( num == 0, "num %d\n", num );
2192 IXMLDOMNamedNodeMap_Release( attr_map );
2194 V_VT(&var) = VT_BSTR;
2195 V_BSTR(&var) = SysAllocString( szstr1 );
2196 name = SysAllocString( szdl );
2197 r = IXMLDOMElement_setAttribute( element, name, var );
2198 ok( r == S_OK, "returns %08x\n", r );
2199 r = IXMLDOMElement_get_attributes( element, &attr_map );
2200 ok( r == S_OK, "returns %08x\n", r );
2201 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2202 ok( r == S_OK, "returns %08x\n", r );
2203 ok( num == 1, "num %d\n", num );
2204 IXMLDOMNamedNodeMap_Release( attr_map );
2207 V_VT(&var) = VT_BSTR;
2208 V_BSTR(&var) = SysAllocString( szstr2 );
2209 r = IXMLDOMElement_setAttribute( element, name, var );
2210 ok( r == S_OK, "returns %08x\n", r );
2211 r = IXMLDOMElement_get_attributes( element, &attr_map );
2212 ok( r == S_OK, "returns %08x\n", r );
2213 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2214 ok( r == S_OK, "returns %08x\n", r );
2215 ok( num == 1, "num %d\n", num );
2216 IXMLDOMNamedNodeMap_Release( attr_map );
2218 r = IXMLDOMElement_getAttribute( element, name, &var );
2219 ok( r == S_OK, "returns %08x\n", r );
2220 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
2222 SysFreeString(name);
2224 V_VT(&var) = VT_BSTR;
2225 V_BSTR(&var) = SysAllocString( szstr1 );
2226 name = SysAllocString( szlc );
2227 r = IXMLDOMElement_setAttribute( element, name, var );
2228 ok( r == S_OK, "returns %08x\n", r );
2229 r = IXMLDOMElement_get_attributes( element, &attr_map );
2230 ok( r == S_OK, "returns %08x\n", r );
2231 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
2232 ok( r == S_OK, "returns %08x\n", r );
2233 ok( num == 2, "num %d\n", num );
2234 IXMLDOMNamedNodeMap_Release( attr_map );
2236 SysFreeString(name);
2240 name = SysAllocString( szbs );
2241 r = IXMLDOMElement_setAttribute( element, name, var );
2242 ok( r == S_OK, "returns %08x\n", r );
2244 r = IXMLDOMElement_getAttribute( element, name, &var );
2245 ok( r == S_OK, "returns %08x\n", r );
2246 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
2248 SysFreeString(name);
2250 /* Create an Attribute */
2252 V_I4(&var) = NODE_ATTRIBUTE;
2253 str = SysAllocString( szAttribute );
2254 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
2255 ok( r == S_OK, "returns %08x\n", r );
2256 ok( node != NULL, "node was null\n");
2259 r = IXMLDOMNode_get_nodeTypeString(node, &str);
2260 ok( r == S_OK, "returns %08x\n", r );
2261 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
2263 IXMLDOMNode_Release( node );
2265 IXMLDOMElement_Release( element );
2266 IXMLDOMNode_Release( root );
2267 IXMLDOMDocument_Release( doc );
2270 static void test_getElementsByTagName(void)
2272 IXMLDOMNodeList *node_list;
2273 IXMLDOMDocument *doc;
2274 IXMLDOMElement *elem;
2281 doc = create_document(&IID_IXMLDOMDocument);
2284 str = SysAllocString( szComplete4 );
2285 r = IXMLDOMDocument_loadXML( doc, str, &b );
2286 ok( r == S_OK, "loadXML failed\n");
2287 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2288 SysFreeString( str );
2290 str = SysAllocString( szstar );
2292 /* null arguments cases */
2293 r = IXMLDOMDocument_getElementsByTagName(doc, NULL, &node_list);
2294 ok( r == E_INVALIDARG, "ret %08x\n", r );
2295 r = IXMLDOMDocument_getElementsByTagName(doc, str, NULL);
2296 ok( r == E_INVALIDARG, "ret %08x\n", r );
2298 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2299 ok( r == S_OK, "ret %08x\n", r );
2300 r = IXMLDOMNodeList_get_length( node_list, &len );
2301 ok( r == S_OK, "ret %08x\n", r );
2302 ok( len == 6, "len %d\n", len );
2304 test_disp((IUnknown*)node_list);
2306 IXMLDOMNodeList_Release( node_list );
2307 SysFreeString( str );
2309 /* broken query BSTR */
2310 memcpy(&buff[2], szstar, sizeof(szstar));
2311 /* just a big length */
2312 *(DWORD*)buff = 0xf0f0;
2313 r = IXMLDOMDocument_getElementsByTagName(doc, &buff[2], &node_list);
2314 ok( r == S_OK, "ret %08x\n", r );
2315 r = IXMLDOMNodeList_get_length( node_list, &len );
2316 ok( r == S_OK, "ret %08x\n", r );
2317 ok( len == 6, "len %d\n", len );
2318 IXMLDOMNodeList_Release( node_list );
2320 str = SysAllocString( szbs );
2321 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2322 ok( r == S_OK, "ret %08x\n", r );
2323 r = IXMLDOMNodeList_get_length( node_list, &len );
2324 ok( r == S_OK, "ret %08x\n", r );
2325 ok( len == 1, "len %d\n", len );
2326 IXMLDOMNodeList_Release( node_list );
2327 SysFreeString( str );
2329 str = SysAllocString( szdl );
2330 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2331 ok( r == S_OK, "ret %08x\n", r );
2332 r = IXMLDOMNodeList_get_length( node_list, &len );
2333 ok( r == S_OK, "ret %08x\n", r );
2334 ok( len == 0, "len %d\n", len );
2335 IXMLDOMNodeList_Release( node_list );
2336 SysFreeString( str );
2338 str = SysAllocString( szstr1 );
2339 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
2340 ok( r == S_OK, "ret %08x\n", r );
2341 r = IXMLDOMNodeList_get_length( node_list, &len );
2342 ok( r == S_OK, "ret %08x\n", r );
2343 ok( len == 0, "len %d\n", len );
2344 IXMLDOMNodeList_Release( node_list );
2345 SysFreeString( str );
2347 /* test for element */
2348 r = IXMLDOMDocument_get_documentElement(doc, &elem);
2349 ok( r == S_OK, "ret %08x\n", r );
2351 str = SysAllocString( szstar );
2353 /* null arguments cases */
2354 r = IXMLDOMElement_getElementsByTagName(elem, NULL, &node_list);
2355 ok( r == E_INVALIDARG, "ret %08x\n", r );
2356 r = IXMLDOMElement_getElementsByTagName(elem, str, NULL);
2357 ok( r == E_INVALIDARG, "ret %08x\n", r );
2359 r = IXMLDOMElement_getElementsByTagName(elem, str, &node_list);
2360 ok( r == S_OK, "ret %08x\n", r );
2361 r = IXMLDOMNodeList_get_length( node_list, &len );
2362 ok( r == S_OK, "ret %08x\n", r );
2363 todo_wine ok( len == 5, "len %d\n", len );
2365 IXMLDOMNodeList_Release( node_list );
2366 SysFreeString( str );
2368 /* broken query BSTR */
2369 memcpy(&buff[2], szstar, sizeof(szstar));
2370 /* just a big length */
2371 *(DWORD*)buff = 0xf0f0;
2372 r = IXMLDOMElement_getElementsByTagName(elem, &buff[2], &node_list);
2373 ok( r == S_OK, "ret %08x\n", r );
2374 r = IXMLDOMNodeList_get_length( node_list, &len );
2375 ok( r == S_OK, "ret %08x\n", r );
2376 todo_wine ok( len == 5, "len %d\n", len );
2377 IXMLDOMNodeList_Release( node_list );
2379 IXMLDOMElement_Release(elem);
2381 IXMLDOMDocument_Release( doc );
2384 static void test_get_text(void)
2389 IXMLDOMDocument *doc;
2390 IXMLDOMNode *node, *node2, *node3;
2391 IXMLDOMNode *nodeRoot;
2392 IXMLDOMNodeList *node_list;
2393 IXMLDOMNamedNodeMap *node_map;
2396 doc = create_document(&IID_IXMLDOMDocument);
2399 str = SysAllocString( szComplete4 );
2400 r = IXMLDOMDocument_loadXML( doc, str, &b );
2401 ok( r == S_OK, "loadXML failed\n");
2402 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2403 SysFreeString( str );
2405 str = SysAllocString( szbs );
2406 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
2407 ok( r == S_OK, "ret %08x\n", r );
2410 /* Test to get all child node text. */
2411 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&nodeRoot);
2412 ok( r == S_OK, "ret %08x\n", r );
2415 r = IXMLDOMNode_get_text( nodeRoot, &str );
2416 ok( r == S_OK, "ret %08x\n", r );
2417 ok( compareIgnoreReturnsWhitespace(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text\n");
2420 IXMLDOMNode_Release(nodeRoot);
2424 /* this test crashes on win9x */
2425 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
2426 ok( r == E_INVALIDARG, "ret %08x\n", r );
2429 r = IXMLDOMNodeList_get_length( node_list, NULL );
2430 ok( r == E_INVALIDARG, "ret %08x\n", r );
2432 r = IXMLDOMNodeList_get_length( node_list, &len );
2433 ok( r == S_OK, "ret %08x\n", r );
2434 ok( len == 1, "expect 1 got %d\n", len );
2436 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
2437 ok( r == E_INVALIDARG, "ret %08x\n", r );
2439 r = IXMLDOMNodeList_nextNode( node_list, NULL );
2440 ok( r == E_INVALIDARG, "ret %08x\n", r );
2442 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
2443 ok( r == S_OK, "ret %08x\n", r );
2444 IXMLDOMNodeList_Release( node_list );
2446 /* Invalid output parameter*/
2447 r = IXMLDOMNode_get_text( node, NULL );
2448 ok( r == E_INVALIDARG, "ret %08x\n", r );
2450 r = IXMLDOMNode_get_text( node, &str );
2451 ok( r == S_OK, "ret %08x\n", r );
2452 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
2455 r = IXMLDOMNode_get_attributes( node, &node_map );
2456 ok( r == S_OK, "ret %08x\n", r );
2458 str = SysAllocString( szvr );
2459 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
2460 ok( r == S_OK, "ret %08x\n", r );
2463 r = IXMLDOMNode_get_text( node2, &str );
2464 ok( r == S_OK, "ret %08x\n", r );
2465 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
2468 r = IXMLDOMNode_get_firstChild( node2, &node3 );
2469 ok( r == S_OK, "ret %08x\n", r );
2471 r = IXMLDOMNode_get_text( node3, &str );
2472 ok( r == S_OK, "ret %08x\n", r );
2473 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
2477 IXMLDOMNode_Release( node3 );
2478 IXMLDOMNode_Release( node2 );
2479 IXMLDOMNamedNodeMap_Release( node_map );
2480 IXMLDOMNode_Release( node );
2481 IXMLDOMDocument_Release( doc );
2484 static void test_get_childNodes(void)
2489 IXMLDOMDocument *doc;
2490 IXMLDOMElement *element;
2491 IXMLDOMNode *node, *node2;
2492 IXMLDOMNodeList *node_list, *node_list2;
2495 doc = create_document(&IID_IXMLDOMDocument);
2498 str = SysAllocString( szComplete4 );
2499 r = IXMLDOMDocument_loadXML( doc, str, &b );
2500 ok( r == S_OK, "loadXML failed\n");
2501 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2502 SysFreeString( str );
2504 r = IXMLDOMDocument_get_documentElement( doc, &element );
2505 ok( r == S_OK, "ret %08x\n", r);
2507 r = IXMLDOMElement_get_childNodes( element, &node_list );
2508 ok( r == S_OK, "ret %08x\n", r);
2510 r = IXMLDOMNodeList_get_length( node_list, &len );
2511 ok( r == S_OK, "ret %08x\n", r);
2512 ok( len == 4, "len %d\n", len);
2514 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
2515 ok( r == S_OK, "ret %08x\n", r);
2517 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
2518 ok( r == S_OK, "ret %08x\n", r);
2520 r = IXMLDOMNodeList_get_length( node_list2, &len );
2521 ok( r == S_OK, "ret %08x\n", r);
2522 ok( len == 0, "len %d\n", len);
2524 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
2525 ok( r == S_FALSE, "ret %08x\n", r);
2527 IXMLDOMNodeList_Release( node_list2 );
2528 IXMLDOMNode_Release( node );
2529 IXMLDOMNodeList_Release( node_list );
2530 IXMLDOMElement_Release( element );
2531 IXMLDOMDocument_Release( doc );
2534 static void test_get_firstChild(void)
2536 static WCHAR xmlW[] = {'x','m','l',0};
2537 IXMLDOMDocument *doc;
2543 doc = create_document(&IID_IXMLDOMDocument);
2546 str = SysAllocString( szComplete4 );
2547 r = IXMLDOMDocument_loadXML( doc, str, &b );
2548 ok( r == S_OK, "loadXML failed\n");
2549 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2550 SysFreeString( str );
2552 r = IXMLDOMDocument_get_firstChild( doc, &node );
2553 ok( r == S_OK, "ret %08x\n", r);
2555 r = IXMLDOMNode_get_nodeName( node, &str );
2556 ok( r == S_OK, "ret %08x\n", r);
2558 ok(memcmp(str, xmlW, sizeof(xmlW)) == 0, "expected \"xml\" node name\n");
2561 IXMLDOMNode_Release( node );
2562 IXMLDOMDocument_Release( doc );
2565 static void test_get_lastChild(void)
2567 static WCHAR lcW[] = {'l','c',0};
2568 static WCHAR foW[] = {'f','o',0};
2569 IXMLDOMDocument *doc;
2570 IXMLDOMNode *node, *child;
2575 doc = create_document(&IID_IXMLDOMDocument);
2578 str = SysAllocString( szComplete4 );
2579 r = IXMLDOMDocument_loadXML( doc, str, &b );
2580 ok( r == S_OK, "loadXML failed\n");
2581 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2582 SysFreeString( str );
2584 r = IXMLDOMDocument_get_lastChild( doc, &node );
2585 ok( r == S_OK, "ret %08x\n", r);
2587 r = IXMLDOMNode_get_nodeName( node, &str );
2588 ok( r == S_OK, "ret %08x\n", r);
2590 ok(memcmp(str, lcW, sizeof(lcW)) == 0, "expected \"lc\" node name\n");
2593 r = IXMLDOMNode_get_lastChild( node, &child );
2594 ok( r == S_OK, "ret %08x\n", r);
2596 r = IXMLDOMNode_get_nodeName( child, &str );
2597 ok( r == S_OK, "ret %08x\n", r);
2599 ok(memcmp(str, foW, sizeof(foW)) == 0, "expected \"fo\" node name\n");
2602 IXMLDOMNode_Release( child );
2603 IXMLDOMNode_Release( node );
2604 IXMLDOMDocument_Release( doc );
2607 static void test_removeChild(void)
2612 IXMLDOMDocument *doc;
2613 IXMLDOMElement *element, *lc_element;
2614 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
2615 IXMLDOMNodeList *root_list, *fo_list;
2617 doc = create_document(&IID_IXMLDOMDocument);
2620 str = SysAllocString( szComplete4 );
2621 r = IXMLDOMDocument_loadXML( doc, str, &b );
2622 ok( r == S_OK, "loadXML failed\n");
2623 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2624 SysFreeString( str );
2626 r = IXMLDOMDocument_get_documentElement( doc, &element );
2627 ok( r == S_OK, "ret %08x\n", r);
2629 r = IXMLDOMElement_get_childNodes( element, &root_list );
2630 ok( r == S_OK, "ret %08x\n", r);
2632 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2633 ok( r == S_OK, "ret %08x\n", r);
2635 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2636 ok( r == S_OK, "ret %08x\n", r);
2638 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2639 ok( r == S_OK, "ret %08x\n", r);
2641 /* invalid parameter: NULL ptr */
2642 removed_node = (void*)0xdeadbeef;
2643 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
2644 ok( r == E_INVALIDARG, "ret %08x\n", r );
2645 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2647 /* ba_node is a descendant of element, but not a direct child. */
2648 removed_node = (void*)0xdeadbeef;
2649 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
2650 ok( r == E_INVALIDARG, "ret %08x\n", r );
2651 ok( removed_node == NULL, "%p\n", removed_node );
2653 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
2654 ok( r == S_OK, "ret %08x\n", r);
2655 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
2657 /* try removing already removed child */
2658 temp_node = (void*)0xdeadbeef;
2659 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
2660 ok( r == E_INVALIDARG, "ret %08x\n", r);
2661 ok( temp_node == NULL, "%p\n", temp_node );
2663 /* the removed node has no parent anymore */
2664 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
2665 ok( r == S_FALSE, "ret %08x\n", r);
2666 ok( temp_node == NULL, "%p\n", temp_node );
2668 IXMLDOMNode_Release( removed_node );
2669 IXMLDOMNode_Release( ba_node );
2670 IXMLDOMNodeList_Release( fo_list );
2672 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2673 ok( r == S_OK, "ret %08x\n", r);
2675 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (void**)&lc_element );
2676 ok( r == S_OK, "ret %08x\n", r);
2678 /* MS quirk: passing wrong interface pointer works, too */
2679 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
2680 ok( r == S_OK, "ret %08x\n", r);
2682 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
2683 ok( r == S_FALSE, "ret %08x\n", r);
2684 ok( temp_node == NULL, "%p\n", temp_node );
2686 IXMLDOMNode_Release( lc_node );
2687 IXMLDOMNodeList_Release( root_list );
2688 IXMLDOMElement_Release( element );
2689 IXMLDOMDocument_Release( doc );
2692 static void test_replaceChild(void)
2697 IXMLDOMDocument *doc;
2698 IXMLDOMElement *element, *ba_element;
2699 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
2700 IXMLDOMNodeList *root_list, *fo_list;
2701 IUnknown * unk1, *unk2;
2704 doc = create_document(&IID_IXMLDOMDocument);
2707 str = SysAllocString( szComplete4 );
2708 r = IXMLDOMDocument_loadXML( doc, str, &b );
2709 ok( r == S_OK, "loadXML failed\n");
2710 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2711 SysFreeString( str );
2713 r = IXMLDOMDocument_get_documentElement( doc, &element );
2714 ok( r == S_OK, "ret %08x\n", r);
2716 r = IXMLDOMElement_get_childNodes( element, &root_list );
2717 ok( r == S_OK, "ret %08x\n", r);
2719 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2720 ok( r == S_OK, "ret %08x\n", r);
2722 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2723 ok( r == S_OK, "ret %08x\n", r);
2725 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2726 ok( r == S_OK, "ret %08x\n", r);
2728 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2729 ok( r == S_OK, "ret %08x\n", r);
2731 IXMLDOMNodeList_Release( fo_list );
2733 /* invalid parameter: NULL ptr for element to remove */
2734 removed_node = (void*)0xdeadbeef;
2735 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
2736 ok( r == E_INVALIDARG, "ret %08x\n", r );
2737 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2739 /* invalid parameter: NULL for replacement element. (Sic!) */
2740 removed_node = (void*)0xdeadbeef;
2741 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
2742 ok( r == E_INVALIDARG, "ret %08x\n", r );
2743 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2745 /* invalid parameter: OldNode is not a child */
2746 removed_node = (void*)0xdeadbeef;
2747 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
2748 ok( r == E_INVALIDARG, "ret %08x\n", r );
2749 ok( removed_node == NULL, "%p\n", removed_node );
2751 /* invalid parameter: would create loop */
2752 removed_node = (void*)0xdeadbeef;
2753 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
2754 ok( r == E_FAIL, "ret %08x\n", r );
2755 ok( removed_node == NULL, "%p\n", removed_node );
2757 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
2758 ok( r == S_OK, "ret %08x\n", r );
2760 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
2761 ok( r == S_OK, "ret %08x\n", r );
2763 /* ba_node and temp_node refer to the same node, yet they
2764 are different interface pointers */
2765 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
2766 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
2767 ok( r == S_OK, "ret %08x\n", r );
2768 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
2769 ok( r == S_OK, "ret %08x\n", r );
2770 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
2772 IUnknown_Release( unk1 );
2773 IUnknown_Release( unk2 );
2775 /* ba_node should have been removed from below fo_node */
2776 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2777 ok( r == S_OK, "ret %08x\n", r );
2779 /* MS quirk: replaceChild also accepts elements instead of nodes */
2780 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
2781 ok( r == S_OK, "ret %08x\n", r );
2783 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
2784 ok( r == S_OK, "ret %08x\n", r );
2786 r = IXMLDOMNodeList_get_length( fo_list, &len);
2787 ok( r == S_OK, "ret %08x\n", r );
2788 ok( len == 0, "len %d\n", len);
2790 IXMLDOMNodeList_Release( fo_list );
2792 IXMLDOMNode_Release(ba_node);
2793 IXMLDOMNode_Release(fo_node);
2794 IXMLDOMNode_Release(temp_node);
2795 IXMLDOMNodeList_Release( root_list );
2796 IXMLDOMElement_Release( element );
2797 IXMLDOMDocument_Release( doc );
2800 static void test_removeNamedItem(void)
2802 IXMLDOMDocument *doc;
2803 IXMLDOMElement *element;
2804 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
2805 IXMLDOMNodeList *root_list;
2806 IXMLDOMNamedNodeMap * pr_attrs;
2812 doc = create_document(&IID_IXMLDOMDocument);
2815 str = SysAllocString( szComplete4 );
2816 r = IXMLDOMDocument_loadXML( doc, str, &b );
2817 ok( r == S_OK, "loadXML failed\n");
2818 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2819 SysFreeString( str );
2821 r = IXMLDOMDocument_get_documentElement( doc, &element );
2822 ok( r == S_OK, "ret %08x\n", r);
2824 r = IXMLDOMElement_get_childNodes( element, &root_list );
2825 ok( r == S_OK, "ret %08x\n", r);
2827 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2828 ok( r == S_OK, "ret %08x\n", r);
2830 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2831 ok( r == S_OK, "ret %08x\n", r);
2833 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2834 ok( r == S_OK, "ret %08x\n", r);
2835 ok( len == 3, "length %d\n", len);
2837 removed_node = (void*)0xdeadbeef;
2838 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2839 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2840 ok ( removed_node == (void*)0xdeadbeef, "got %p\n", removed_node);
2842 removed_node = (void*)0xdeadbeef;
2843 str = SysAllocString(szvr);
2844 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2845 ok ( r == S_OK, "ret %08x\n", r);
2847 removed_node2 = (void*)0xdeadbeef;
2848 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2849 ok ( r == S_FALSE, "ret %08x\n", r);
2850 ok ( removed_node2 == NULL, "got %p\n", removed_node2 );
2852 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2853 ok( r == S_OK, "ret %08x\n", r);
2854 ok( len == 2, "length %d\n", len);
2856 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2857 ok ( r == S_OK, "ret %08x\n", r);
2858 IXMLDOMNode_Release(removed_node);
2860 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2861 ok( r == S_OK, "ret %08x\n", r);
2862 ok( len == 3, "length %d\n", len);
2864 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2865 ok ( r == S_OK, "ret %08x\n", r);
2867 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2868 ok( r == S_OK, "ret %08x\n", r);
2869 ok( len == 2, "length %d\n", len);
2871 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2872 ok ( r == S_FALSE, "ret %08x\n", r);
2876 IXMLDOMNamedNodeMap_Release( pr_attrs );
2877 IXMLDOMNode_Release( pr_node );
2878 IXMLDOMNodeList_Release( root_list );
2879 IXMLDOMElement_Release( element );
2880 IXMLDOMDocument_Release( doc );
2883 static void test_XMLHTTP(void)
2885 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2886 static const WCHAR wszPOST[] = {'P','O','S','T',0};
2887 static const WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2888 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2889 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2890 static const WCHAR xmltestW[] = {'h','t','t','p',':','/','/',
2891 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2892 'x','m','l','t','e','s','t','.','x','m','l',0};
2893 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2894 IXMLHttpRequest *pXMLHttpRequest;
2895 BSTR bstrResponse, method, url;
2900 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2901 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2902 (void **)&pXMLHttpRequest);
2905 win_skip("IXMLHTTPRequest is not available (0x%08x)\n", hr);
2909 VariantInit(&dummy);
2910 V_VT(&dummy) = VT_ERROR;
2911 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2912 VariantInit(&async);
2913 V_VT(&async) = VT_BOOL;
2914 V_BOOL(&async) = VARIANT_FALSE;
2915 V_VT(&varbody) = VT_BSTR;
2916 V_BSTR(&varbody) = SysAllocString(wszBody);
2918 method = SysAllocString(wszPOST);
2919 url = SysAllocString(wszUrl);
2921 /* send before open */
2922 hr = IXMLHttpRequest_send(pXMLHttpRequest, dummy);
2923 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
2925 /* invalid parameters */
2926 hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, NULL, async, dummy, dummy);
2927 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2929 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, NULL, async, dummy, dummy);
2930 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2932 hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, url, async, dummy, dummy);
2933 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2935 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, NULL);
2936 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2938 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), NULL);
2939 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
2941 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, _bstr_("value1"));
2942 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2944 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), _bstr_("value1"));
2945 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
2947 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, NULL);
2948 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2951 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
2952 ok(hr == S_OK, "got 0x%08x\n", hr);
2953 ok(state == 0, "got %d, expected 0\n", state);
2955 hr = IXMLHttpRequest_open(pXMLHttpRequest, method, url, async, dummy, dummy);
2956 ok(hr == S_OK, "got 0x%08x\n", hr);
2959 hr = IXMLHttpRequest_get_readyState(pXMLHttpRequest, &state);
2960 ok(hr == S_OK, "got 0x%08x\n", hr);
2961 ok(state == 1, "got %d, expected 1\n", state);
2963 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_("header1"), _bstr_("value1"));
2964 ok(hr == S_OK, "got 0x%08x\n", hr);
2966 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, NULL, _bstr_("value1"));
2967 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2969 hr = IXMLHttpRequest_setRequestHeader(pXMLHttpRequest, _bstr_(""), _bstr_("value1"));
2970 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2972 SysFreeString(method);
2975 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2976 if (hr == INET_E_RESOURCE_NOT_FOUND)
2978 skip("No connection could be made with crossover.codeweavers.com\n");
2979 IXMLHttpRequest_Release(pXMLHttpRequest);
2982 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2984 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2985 ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win9x, win2k */, "got 0x%08x\n", hr);
2987 VariantClear(&varbody);
2989 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2990 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2991 /* the server currently returns "FAILED" because the Content-Type header is
2992 * not what the server expects */
2995 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2996 SysFreeString(bstrResponse);
3000 url = SysAllocString(xmltestW);
3002 hr = IXMLHttpRequest_open(pXMLHttpRequest, _bstr_("GET"), url, async, dummy, dummy);
3003 ok(hr == S_OK, "got 0x%08x\n", hr);
3005 V_VT(&varbody) = VT_EMPTY;
3007 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
3008 if (hr == INET_E_RESOURCE_NOT_FOUND)
3010 skip("No connection could be made with crossover.codeweavers.com\n");
3011 IXMLHttpRequest_Release(pXMLHttpRequest);
3014 ok(hr == S_OK, "got 0x%08x\n", hr);
3018 IXMLHttpRequest_Release(pXMLHttpRequest);
3022 static void test_IXMLDOMDocument2(void)
3024 static const WCHAR emptyW[] = {0};
3025 IXMLDOMDocument2 *doc2;
3026 IXMLDOMDocument *doc;
3027 IDispatchEx *dispex;
3034 doc = create_document(&IID_IXMLDOMDocument);
3037 str = SysAllocString( szComplete4 );
3038 r = IXMLDOMDocument_loadXML( doc, str, &b );
3039 ok( r == S_OK, "loadXML failed\n");
3040 ok( b == VARIANT_TRUE, "failed to load XML string\n");
3041 SysFreeString( str );
3043 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
3044 ok( r == S_OK, "ret %08x\n", r );
3045 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
3047 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
3048 ok( r == S_OK, "ret %08x\n", r );
3051 IDispatchEx_Release(dispex);
3054 /* we will check if the variant got cleared */
3055 ref = IXMLDOMDocument2_AddRef(doc2);
3056 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
3057 V_VT(&var) = VT_UNKNOWN;
3058 V_UNKNOWN(&var) = (IUnknown *)doc2;
3061 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
3062 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
3063 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
3066 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3067 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3068 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3071 /* the variant didn't get cleared*/
3072 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
3074 /* setProperty tests */
3075 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
3076 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
3077 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
3078 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3079 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3080 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
3082 V_VT(&var) = VT_BSTR;
3083 V_BSTR(&var) = SysAllocString(emptyW);
3084 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3085 ok(r == S_OK, "got 0x%08x\n", r);
3090 r = IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionNamespaces"), var);
3091 ok(r == E_FAIL, "got 0x%08x\n", r);
3093 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
3094 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
3095 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3096 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
3098 IXMLDOMDocument2_Release( doc2 );
3099 IXMLDOMDocument_Release( doc );
3103 static inline void check_ws_ignored(IXMLDOMDocument2* doc)
3105 IXMLDOMNode *node1, *node2;
3106 IXMLDOMNodeList *list;
3108 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
3109 ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
3110 ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
3111 ole_check(IXMLDOMNodeList_reset(list));
3112 expect_list_and_release(list, "E1.E4.E1.E2.D1 E2.E4.E1.E2.D1");
3114 ole_check(IXMLDOMNode_get_childNodes(node1, &list));
3115 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");
3116 IXMLDOMNode_Release(node1);
3117 ole_check(IXMLDOMNode_get_childNodes(node2, &list));
3118 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");
3119 IXMLDOMNode_Release(node2);
3122 static inline void check_ws_preserved(IXMLDOMDocument2* doc)
3124 IXMLDOMNode *node1, *node2;
3125 IXMLDOMNodeList *list;
3127 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//*[local-name()='html']"), &list));
3128 ole_check(IXMLDOMNodeList_get_item(list, 0, &node1));
3129 ole_check(IXMLDOMNodeList_get_item(list, 1, &node2));
3130 ole_check(IXMLDOMNodeList_reset(list));
3131 expect_list_and_release(list, "E2.E8.E2.E2.D1 E4.E8.E2.E2.D1");
3133 ole_check(IXMLDOMNode_get_childNodes(node1, &list));
3134 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");
3135 IXMLDOMNode_Release(node1);
3136 ole_check(IXMLDOMNode_get_childNodes(node2, &list));
3137 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");
3138 IXMLDOMNode_Release(node2);
3141 static void test_whitespace(void)
3144 IXMLDOMDocument2 *doc1, *doc2, *doc3, *doc4;
3146 doc1 = create_document(&IID_IXMLDOMDocument2);
3147 doc2 = create_document(&IID_IXMLDOMDocument2);
3148 if (!doc1 || !doc2) return;
3150 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_TRUE));
3151 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
3152 ok(b == VARIANT_FALSE, "expected false\n");
3153 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
3154 ok(b == VARIANT_TRUE, "expected true\n");
3156 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
3157 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3158 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
3159 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3161 /* switch to XPath */
3162 ole_check(IXMLDOMDocument2_setProperty(doc1, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3163 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3165 check_ws_ignored(doc1);
3166 check_ws_preserved(doc2);
3168 /* new instances copy the property */
3169 ole_check(IXMLDOMDocument2_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**) &doc3));
3170 ole_check(IXMLDOMDocument2_QueryInterface(doc2, &IID_IXMLDOMDocument2, (void**) &doc4));
3172 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
3173 ok(b == VARIANT_FALSE, "expected false\n");
3174 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
3175 ok(b == VARIANT_TRUE, "expected true\n");
3177 check_ws_ignored(doc3);
3178 check_ws_preserved(doc4);
3180 /* setting after loading xml does nothing */
3181 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc1, VARIANT_TRUE));
3182 ole_check(IXMLDOMDocument2_put_preserveWhiteSpace(doc2, VARIANT_FALSE));
3184 check_ws_ignored(doc1);
3185 check_ws_preserved(doc2);
3187 /* it takes effect on reload */
3188 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc1, &b));
3189 ok(b == VARIANT_TRUE, "expected true\n");
3190 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc2, &b));
3191 ok(b == VARIANT_FALSE, "expected false\n");
3193 ole_check(IXMLDOMDocument2_loadXML(doc1, _bstr_(szExampleXML), &b));
3194 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3195 ole_check(IXMLDOMDocument2_loadXML(doc2, _bstr_(szExampleXML), &b));
3196 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3198 check_ws_preserved(doc1);
3199 check_ws_ignored(doc2);
3201 /* other instances follow suit */
3202 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc3, &b));
3203 ok(b == VARIANT_TRUE, "expected true\n");
3204 ole_check(IXMLDOMDocument2_get_preserveWhiteSpace(doc4, &b));
3205 ok(b == VARIANT_FALSE, "expected false\n");
3207 check_ws_preserved(doc3);
3208 check_ws_ignored(doc4);
3210 IXMLDOMDocument_Release(doc1);
3211 IXMLDOMDocument_Release(doc2);
3212 IXMLDOMDocument_Release(doc3);
3213 IXMLDOMDocument_Release(doc4);
3217 static void test_XPath(void)
3221 IXMLDOMDocument2 *doc;
3222 IXMLDOMNode *rootNode;
3223 IXMLDOMNode *elem1Node;
3225 IXMLDOMNodeList *list;
3227 doc = create_document(&IID_IXMLDOMDocument2);
3230 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
3231 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3233 /* switch to XPath */
3234 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
3236 /* some simple queries*/
3237 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
3238 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
3239 ole_check(IXMLDOMNodeList_reset(list));
3240 expect_list_and_release(list, "E2.D1");
3241 if (rootNode == NULL)
3244 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
3245 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
3247 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
3248 expect_list_and_release(list, "E3.E2.E2.D1");
3250 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
3251 /* using get_item for query results advances the position */
3252 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
3253 expect_node(node, "E2.E2.D1");
3254 IXMLDOMNode_Release(node);
3255 ole_check(IXMLDOMNodeList_nextNode(list, &node));
3256 expect_node(node, "E4.E2.D1");
3257 IXMLDOMNode_Release(node);
3258 ole_check(IXMLDOMNodeList_reset(list));
3259 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
3261 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
3262 expect_list_and_release(list, "E2.D1");
3264 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
3265 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
3266 ole_check(IXMLDOMNodeList_reset(list));
3267 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
3269 /* select an attribute */
3270 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
3271 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
3273 /* would evaluate to a number */
3274 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
3275 /* would evaluate to a boolean */
3276 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
3277 /* would evaluate to a string */
3278 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
3281 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
3282 expect_list_and_release(list, "");
3283 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
3284 expect_list_and_release(list, "");
3285 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
3286 expect_list_and_release(list, "");
3287 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//elem[0]"), &list));
3288 expect_list_and_release(list, "");
3290 /* foo undeclared in document node */
3291 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
3292 /* undeclared in <root> node */
3293 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
3294 /* undeclared in <elem> node */
3295 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
3296 /* but this trick can be used */
3297 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
3298 expect_list_and_release(list, "E3.E4.E2.D1");
3300 /* it has to be declared in SelectionNamespaces */
3301 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
3302 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
3304 /* now the namespace can be used */
3305 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
3306 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
3307 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
3308 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
3309 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
3310 expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
3311 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
3312 expect_list_and_release(list, "E5.E1.E4.E1.E2.D1 E6.E2.E4.E1.E2.D1");
3314 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
3315 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
3316 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
3318 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
3321 ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
3322 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
3323 if (V_VT(&var) == VT_BSTR)
3324 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
3326 /* extra attributes - same thing*/
3327 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
3328 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
3329 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
3331 IXMLDOMNode_Release(rootNode);
3332 IXMLDOMNode_Release(elem1Node);
3333 IXMLDOMDocument_Release(doc);
3337 static void test_cloneNode(void )
3339 IXMLDOMDocument *doc;
3341 IXMLDOMNodeList *pList;
3342 IXMLDOMNamedNodeMap *mapAttr;
3343 LONG nLength = 0, nLength1 = 0;
3344 LONG nAttrCnt = 0, nAttrCnt1 = 0;
3346 IXMLDOMNode *node_clone;
3347 IXMLDOMNode *node_first;
3350 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
3352 doc = create_document(&IID_IXMLDOMDocument);
3355 str = SysAllocString( szComplete4 );
3356 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
3357 ok(b == VARIANT_TRUE, "failed to load XML string\n");
3363 str = SysAllocString( szSearch);
3364 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
3365 ok( r == S_OK, "ret %08x\n", r );
3366 ok( node != NULL, "node %p\n", node );
3371 IXMLDOMDocument_Release(doc);
3375 /* Check invalid parameter */
3376 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
3377 ok( r == E_INVALIDARG, "ret %08x\n", r );
3380 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
3381 ok( r == S_OK, "ret %08x\n", r );
3382 ok( node_clone != NULL, "node %p\n", node );
3386 IXMLDOMDocument_Release(doc);
3387 IXMLDOMNode_Release(node);
3391 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
3392 ok( r == S_OK, "ret %08x\n", r );
3395 IXMLDOMDocument *doc2;
3397 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
3398 ok( r == S_OK, "ret %08x\n", r );
3400 IXMLDOMDocument_Release(doc2);
3402 IXMLDOMNode_Release(node_first);
3405 r = IXMLDOMNode_get_childNodes(node, &pList);
3406 ok( r == S_OK, "ret %08x\n", r );
3409 IXMLDOMNodeList_get_length(pList, &nLength);
3410 IXMLDOMNodeList_Release(pList);
3413 r = IXMLDOMNode_get_attributes(node, &mapAttr);
3414 ok( r == S_OK, "ret %08x\n", r );
3417 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
3418 IXMLDOMNamedNodeMap_Release(mapAttr);
3421 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
3422 ok( r == S_OK, "ret %08x\n", r );
3425 IXMLDOMNodeList_get_length(pList, &nLength1);
3426 IXMLDOMNodeList_Release(pList);
3429 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
3430 ok( r == S_OK, "ret %08x\n", r );
3433 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
3434 IXMLDOMNamedNodeMap_Release(mapAttr);
3437 ok(nLength == nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
3438 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
3439 IXMLDOMNode_Release(node_clone);
3442 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
3443 ok( r == S_OK, "ret %08x\n", r );
3444 ok( node_clone != NULL, "node %p\n", node );
3448 IXMLDOMDocument_Release(doc);
3449 IXMLDOMNode_Release(node);
3453 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
3454 ok( r == S_FALSE, "ret %08x\n", r );
3457 IXMLDOMDocument *doc2;
3459 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
3460 ok( r == S_OK, "ret %08x\n", r );
3462 IXMLDOMDocument_Release(doc2);
3464 IXMLDOMNode_Release(node_first);
3467 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
3468 ok( r == S_OK, "ret %08x\n", r );
3471 IXMLDOMNodeList_get_length(pList, &nLength1);
3472 ok( nLength1 == 0, "Length should be 0 (%d)\n", nLength1);
3473 IXMLDOMNodeList_Release(pList);
3476 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
3477 ok( r == S_OK, "ret %08x\n", r );
3480 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
3481 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%d)\n", nAttrCnt1);
3482 IXMLDOMNamedNodeMap_Release(mapAttr);
3485 ok(nLength != nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
3486 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
3487 IXMLDOMNode_Release(node_clone);
3490 IXMLDOMNode_Release(node);
3491 IXMLDOMDocument_Release(doc);
3494 static void test_xmlTypes(void)
3496 IXMLDOMDocument *doc;
3497 IXMLDOMElement *pRoot;
3499 IXMLDOMComment *pComment;
3500 IXMLDOMElement *pElement;
3501 IXMLDOMAttribute *pAttribute;
3502 IXMLDOMNamedNodeMap *pAttribs;
3503 IXMLDOMCDATASection *pCDataSec;
3504 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
3505 IXMLDOMDocumentFragment *pDocFrag = NULL;
3506 IXMLDOMEntityReference *pEntityRef = NULL;
3508 IXMLDOMNode *pNextChild;
3512 doc = create_document(&IID_IXMLDOMDocument);
3515 pNextChild = (void*)0xdeadbeef;
3516 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
3517 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3519 pNextChild = (void*)0xdeadbeef;
3520 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
3521 ok(hr == S_FALSE, "ret %08x\n", hr );
3522 ok(pNextChild == NULL, "pDocChild not NULL\n");
3524 /* test previous Sibling */
3525 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
3526 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3528 pNextChild = (void*)0xdeadbeef;
3529 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
3530 ok(hr == S_FALSE, "ret %08x\n", hr );
3531 ok(pNextChild == NULL, "pNextChild not NULL\n");
3533 /* test get_attributes */
3534 hr = IXMLDOMDocument_get_attributes( doc, NULL );
3535 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
3537 pAttribs = (void*)0xdeadbeef;
3538 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
3539 ok(hr == S_FALSE, "ret %08x\n", hr );
3540 ok( pAttribs == NULL, "pAttribs not NULL\n");
3542 /* test get_dataType */
3543 V_VT(&v) = VT_EMPTY;
3544 hr = IXMLDOMDocument_get_dataType(doc, &v);
3545 ok(hr == S_FALSE, "ret %08x\n", hr );
3546 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3549 /* test nodeTypeString */
3551 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
3552 ok(hr == S_OK, "ret %08x\n", hr );
3553 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
3556 /* test implementation */
3557 hr = IXMLDOMDocument_get_implementation(doc, NULL);
3558 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3560 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
3561 ok(hr == S_OK, "ret %08x\n", hr );
3564 VARIANT_BOOL hasFeature = VARIANT_TRUE;
3565 BSTR sEmpty = SysAllocStringLen(NULL, 0);
3567 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
3568 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3570 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
3571 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3573 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
3574 ok(hr == S_OK, "ret %08x\n", hr );
3575 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
3577 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
3578 ok(hr == S_OK, "ret %08x\n", hr );
3579 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
3581 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
3582 ok(hr == S_OK, "ret %08x\n", hr );
3583 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
3585 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
3586 ok(hr == S_OK, "ret %08x\n", hr );
3587 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
3589 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
3590 ok(hr == S_OK, "ret %08x\n", hr );
3591 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
3593 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
3594 ok(hr == S_OK, "ret %08x\n", hr );
3595 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
3597 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
3598 ok(hr == S_OK, "ret %08x\n", hr );
3599 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
3601 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
3602 ok(hr == S_OK, "ret %08x\n", hr );
3603 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
3605 SysFreeString(sEmpty);
3606 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
3609 pRoot = (IXMLDOMElement*)0x1;
3610 hr = IXMLDOMDocument_createElement(doc, NULL, &pRoot);
3611 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3612 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
3614 pRoot = (IXMLDOMElement*)0x1;
3615 hr = IXMLDOMDocument_createElement(doc, _bstr_(""), &pRoot);
3616 ok(hr == E_FAIL, "ret %08x\n", hr );
3617 ok(pRoot == (void*)0x1, "Expect same ptr, got %p\n", pRoot);
3619 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3620 ok(hr == S_OK, "ret %08x\n", hr );
3623 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3624 ok(hr == S_OK, "ret %08x\n", hr );
3628 str = SysAllocString(szComment);
3629 hr = IXMLDOMDocument_createComment(doc, str, &pComment);
3631 ok(hr == S_OK, "ret %08x\n", hr );
3634 /* test get_attributes */
3635 hr = IXMLDOMComment_get_attributes( pComment, NULL );
3636 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
3638 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3639 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
3640 ok(hr == S_FALSE, "ret %08x\n", hr );
3641 ok( pAttribs == NULL, "pAttribs not NULL\n");
3643 /* test nodeTypeString */
3644 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
3645 ok(hr == S_OK, "ret %08x\n", hr );
3646 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
3649 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
3650 ok(hr == S_OK, "ret %08x\n", hr );
3652 hr = IXMLDOMComment_get_nodeName(pComment, &str);
3653 ok(hr == S_OK, "ret %08x\n", hr );
3654 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
3657 hr = IXMLDOMComment_get_xml(pComment, &str);
3658 ok(hr == S_OK, "ret %08x\n", hr );
3659 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
3662 hr = IXMLDOMComment_get_dataType(pComment, &v);
3663 ok(hr == S_FALSE, "ret %08x\n", hr );
3664 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3667 /* put data Tests */
3668 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
3669 ok(hr == S_OK, "ret %08x\n", hr );
3671 /* get data Tests */
3672 hr = IXMLDOMComment_get_data(pComment, &str);
3673 ok(hr == S_OK, "ret %08x\n", hr );
3674 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
3677 /* get data Tests */
3678 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
3679 ok(hr == S_OK, "ret %08x\n", hr );
3680 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
3681 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
3684 /* Confirm XML text is good */
3685 hr = IXMLDOMComment_get_xml(pComment, &str);
3686 ok(hr == S_OK, "ret %08x\n", hr );
3687 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
3690 /* Confirm we get the put_data Text back */
3691 hr = IXMLDOMComment_get_text(pComment, &str);
3692 ok(hr == S_OK, "ret %08x\n", hr );
3693 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
3696 /* test length property */
3697 hr = IXMLDOMComment_get_length(pComment, &len);
3698 ok(hr == S_OK, "ret %08x\n", hr );
3699 ok(len == 21, "expected 21 got %d\n", len);
3701 /* test substringData */
3702 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
3703 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3705 /* test substringData - Invalid offset */
3706 str = (BSTR)&szElement;
3707 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
3708 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3709 ok( str == NULL, "incorrect string\n");
3711 /* test substringData - Invalid offset */
3712 str = (BSTR)&szElement;
3713 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
3714 ok(hr == S_FALSE, "ret %08x\n", hr );
3715 ok( str == NULL, "incorrect string\n");
3717 /* test substringData - Invalid size */
3718 str = (BSTR)&szElement;
3719 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
3720 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3721 ok( str == NULL, "incorrect string\n");
3723 /* test substringData - Invalid size */
3724 str = (BSTR)&szElement;
3725 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
3726 ok(hr == S_FALSE, "ret %08x\n", hr );
3727 ok( str == NULL, "incorrect string\n");
3729 /* test substringData - Start of string */
3730 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
3731 ok(hr == S_OK, "ret %08x\n", hr );
3732 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
3735 /* test substringData - Middle of string */
3736 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
3737 ok(hr == S_OK, "ret %08x\n", hr );
3738 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
3741 /* test substringData - End of string */
3742 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
3743 ok(hr == S_OK, "ret %08x\n", hr );
3744 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
3747 /* test appendData */
3748 hr = IXMLDOMComment_appendData(pComment, NULL);
3749 ok(hr == S_OK, "ret %08x\n", hr );
3751 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
3752 ok(hr == S_OK, "ret %08x\n", hr );
3754 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
3755 ok(hr == S_OK, "ret %08x\n", hr );
3757 hr = IXMLDOMComment_get_text(pComment, &str);
3758 ok(hr == S_OK, "ret %08x\n", hr );
3759 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3762 /* test insertData */
3763 str = SysAllocStringLen(NULL, 0);
3764 hr = IXMLDOMComment_insertData(pComment, -1, str);
3765 ok(hr == S_OK, "ret %08x\n", hr );
3767 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
3768 ok(hr == S_OK, "ret %08x\n", hr );
3770 hr = IXMLDOMComment_insertData(pComment, 1000, str);
3771 ok(hr == S_OK, "ret %08x\n", hr );
3773 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
3774 ok(hr == S_OK, "ret %08x\n", hr );
3776 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
3777 ok(hr == S_OK, "ret %08x\n", hr );
3779 hr = IXMLDOMComment_insertData(pComment, 0, str);
3780 ok(hr == S_OK, "ret %08x\n", hr );
3783 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
3784 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3786 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
3787 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3789 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
3790 ok(hr == S_OK, "ret %08x\n", hr );
3792 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
3793 ok(hr == S_OK, "ret %08x\n", hr );
3795 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
3796 ok(hr == S_OK, "ret %08x\n", hr );
3798 hr = IXMLDOMComment_get_text(pComment, &str);
3799 ok(hr == S_OK, "ret %08x\n", hr );
3800 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3804 /* invalid arguments */
3805 hr = IXMLDOMComment_deleteData(pComment, -1, 1);
3806 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3808 hr = IXMLDOMComment_deleteData(pComment, 0, 0);
3809 ok(hr == S_OK, "ret %08x\n", hr );
3811 hr = IXMLDOMComment_deleteData(pComment, 0, -1);
3812 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3814 hr = IXMLDOMComment_get_length(pComment, &len);
3815 ok(hr == S_OK, "ret %08x\n", hr );
3816 ok(len == 43, "expected 43 got %d\n", len);
3818 hr = IXMLDOMComment_deleteData(pComment, len, 1);
3819 ok(hr == S_OK, "ret %08x\n", hr );
3821 hr = IXMLDOMComment_deleteData(pComment, len+1, 1);
3822 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3824 /* delete from start */
3825 hr = IXMLDOMComment_deleteData(pComment, 0, 5);
3826 ok(hr == S_OK, "ret %08x\n", hr );
3828 hr = IXMLDOMComment_get_length(pComment, &len);
3829 ok(hr == S_OK, "ret %08x\n", hr );
3830 ok(len == 38, "expected 38 got %d\n", len);
3832 hr = IXMLDOMComment_get_text(pComment, &str);
3833 ok(hr == S_OK, "ret %08x\n", hr );
3834 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3837 /* delete from end */
3838 hr = IXMLDOMComment_deleteData(pComment, 35, 3);
3839 ok(hr == S_OK, "ret %08x\n", hr );
3841 hr = IXMLDOMComment_get_length(pComment, &len);
3842 ok(hr == S_OK, "ret %08x\n", hr );
3843 ok(len == 35, "expected 35 got %d\n", len);
3845 hr = IXMLDOMComment_get_text(pComment, &str);
3846 ok(hr == S_OK, "ret %08x\n", hr );
3847 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3850 /* delete from inside */
3851 hr = IXMLDOMComment_deleteData(pComment, 1, 33);
3852 ok(hr == S_OK, "ret %08x\n", hr );
3854 hr = IXMLDOMComment_get_length(pComment, &len);
3855 ok(hr == S_OK, "ret %08x\n", hr );
3856 ok(len == 2, "expected 2 got %d\n", len);
3858 hr = IXMLDOMComment_get_text(pComment, &str);
3859 ok(hr == S_OK, "ret %08x\n", hr );
3860 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3863 /* delete whole data ... */
3864 hr = IXMLDOMComment_get_length(pComment, &len);
3865 ok(hr == S_OK, "ret %08x\n", hr );
3867 hr = IXMLDOMComment_deleteData(pComment, 0, len);
3868 ok(hr == S_OK, "ret %08x\n", hr );
3869 /* ... and try again with empty string */
3870 hr = IXMLDOMComment_deleteData(pComment, 0, len);
3871 ok(hr == S_OK, "ret %08x\n", hr );
3873 /* ::replaceData() */
3875 V_BSTR(&v) = SysAllocString(szstr1);
3876 hr = IXMLDOMComment_put_nodeValue(pComment, v);
3877 ok(hr == S_OK, "ret %08x\n", hr );
3880 hr = IXMLDOMComment_replaceData(pComment, 6, 0, NULL);
3881 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3882 hr = IXMLDOMComment_get_text(pComment, &str);
3883 ok(hr == S_OK, "ret %08x\n", hr );
3884 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3887 hr = IXMLDOMComment_replaceData(pComment, 0, 0, NULL);
3888 ok(hr == S_OK, "ret %08x\n", hr );
3889 hr = IXMLDOMComment_get_text(pComment, &str);
3890 ok(hr == S_OK, "ret %08x\n", hr );
3891 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3894 /* NULL pointer means delete */
3895 hr = IXMLDOMComment_replaceData(pComment, 0, 1, NULL);
3896 ok(hr == S_OK, "ret %08x\n", hr );
3897 hr = IXMLDOMComment_get_text(pComment, &str);
3898 ok(hr == S_OK, "ret %08x\n", hr );
3899 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3902 /* empty string means delete */
3903 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_(""));
3904 ok(hr == S_OK, "ret %08x\n", hr );
3905 hr = IXMLDOMComment_get_text(pComment, &str);
3906 ok(hr == S_OK, "ret %08x\n", hr );
3907 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3910 /* zero count means insert */
3911 hr = IXMLDOMComment_replaceData(pComment, 0, 0, _bstr_("a"));
3912 ok(hr == S_OK, "ret %08x\n", hr );
3913 hr = IXMLDOMComment_get_text(pComment, &str);
3914 ok(hr == S_OK, "ret %08x\n", hr );
3915 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3918 hr = IXMLDOMComment_replaceData(pComment, 0, 2, NULL);
3919 ok(hr == S_OK, "ret %08x\n", hr );
3921 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("m"));
3922 ok(hr == S_OK, "ret %08x\n", hr );
3923 hr = IXMLDOMComment_get_text(pComment, &str);
3924 ok(hr == S_OK, "ret %08x\n", hr );
3925 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3928 /* nonempty string, count greater than its length */
3929 hr = IXMLDOMComment_replaceData(pComment, 0, 2, _bstr_("a1.2"));
3930 ok(hr == S_OK, "ret %08x\n", hr );
3931 hr = IXMLDOMComment_get_text(pComment, &str);
3932 ok(hr == S_OK, "ret %08x\n", hr );
3933 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3936 /* nonempty string, count less than its length */
3937 hr = IXMLDOMComment_replaceData(pComment, 0, 1, _bstr_("wine"));
3938 ok(hr == S_OK, "ret %08x\n", hr );
3939 hr = IXMLDOMComment_get_text(pComment, &str);
3940 ok(hr == S_OK, "ret %08x\n", hr );
3941 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
3944 IXMLDOMComment_Release(pComment);
3948 str = SysAllocString(szElement);
3949 hr = IXMLDOMDocument_createElement(doc, str, &pElement);
3951 ok(hr == S_OK, "ret %08x\n", hr );
3954 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3955 ok(hr == S_OK, "ret %08x\n", hr );
3957 /* test nodeTypeString */
3958 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
3959 ok(hr == S_OK, "ret %08x\n", hr );
3960 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
3963 hr = IXMLDOMElement_get_nodeName(pElement, &str);
3964 ok(hr == S_OK, "ret %08x\n", hr );
3965 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
3968 hr = IXMLDOMElement_get_xml(pElement, &str);
3969 ok(hr == S_OK, "ret %08x\n", hr );
3970 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
3973 hr = IXMLDOMElement_get_dataType(pElement, &v);
3974 ok(hr == S_FALSE, "ret %08x\n", hr );
3975 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3979 pAttribute = (IXMLDOMAttribute*)0x1;
3980 hr = IXMLDOMDocument_createAttribute(doc, NULL, &pAttribute);
3981 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3982 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
3984 pAttribute = (IXMLDOMAttribute*)0x1;
3985 hr = IXMLDOMDocument_createAttribute(doc, _bstr_(""), &pAttribute);
3986 ok(hr == E_FAIL, "ret %08x\n", hr );
3987 ok(pAttribute == (void*)0x1, "Expect same ptr, got %p\n", pAttribute);
3989 str = SysAllocString(szAttribute);
3990 hr = IXMLDOMDocument_createAttribute(doc, str, &pAttribute);
3992 ok(hr == S_OK, "ret %08x\n", hr );
3995 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
3997 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, NULL);
3998 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4000 pNextChild = (IXMLDOMNode *)0x1;
4001 hr = IXMLDOMAttribute_get_nextSibling(pAttribute, &pNextChild);
4002 ok(hr == S_FALSE, "ret %08x\n", hr );
4003 ok(pNextChild == NULL, "pNextChild not NULL\n");
4005 /* test Previous Sibling*/
4006 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, NULL);
4007 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4009 pNextChild = (IXMLDOMNode *)0x1;
4010 hr = IXMLDOMAttribute_get_previousSibling(pAttribute, &pNextChild);
4011 ok(hr == S_FALSE, "ret %08x\n", hr );
4012 ok(pNextChild == NULL, "pNextChild not NULL\n");
4014 /* test get_attributes */
4015 hr = IXMLDOMAttribute_get_attributes( pAttribute, NULL );
4016 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
4018 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4019 hr = IXMLDOMAttribute_get_attributes( pAttribute, &pAttribs);
4020 ok(hr == S_FALSE, "ret %08x\n", hr );
4021 ok( pAttribs == NULL, "pAttribs not NULL\n");
4023 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttribute, &pNewChild);
4024 ok(hr == E_FAIL, "ret %08x\n", hr );
4025 ok(pNewChild == NULL, "pNewChild not NULL\n");
4027 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
4028 ok(hr == S_OK, "ret %08x\n", hr );
4031 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttribute, NULL );
4032 ok(hr == S_OK, "ret %08x\n", hr );
4034 IXMLDOMNamedNodeMap_Release(pAttribs);
4037 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
4038 ok(hr == S_OK, "ret %08x\n", hr );
4039 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
4042 /* test nodeTypeString */
4043 hr = IXMLDOMAttribute_get_nodeTypeString(pAttribute, &str);
4044 ok(hr == S_OK, "ret %08x\n", hr );
4045 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
4049 hr = IXMLDOMAttribute_get_nodeName(pAttribute, &str);
4050 ok(hr == S_OK, "ret %08x\n", hr );
4051 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
4054 /* test name property */
4055 hr = IXMLDOMAttribute_get_name(pAttribute, &str);
4056 ok(hr == S_OK, "ret %08x\n", hr );
4057 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
4060 hr = IXMLDOMAttribute_get_xml(pAttribute, &str);
4061 ok(hr == S_OK, "ret %08x\n", hr );
4062 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
4065 hr = IXMLDOMAttribute_get_dataType(pAttribute, &v);
4066 ok(hr == S_FALSE, "ret %08x\n", hr );
4067 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4070 IXMLDOMAttribute_Release(pAttribute);
4072 /* Check Element again with the Add Attribute*/
4073 hr = IXMLDOMElement_get_xml(pElement, &str);
4074 ok(hr == S_OK, "ret %08x\n", hr );
4075 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
4079 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
4080 ok(hr == S_OK, "ret %08x\n", hr );
4082 hr = IXMLDOMElement_get_xml(pElement, &str);
4083 ok(hr == S_OK, "ret %08x\n", hr );
4084 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
4087 /* Test for reversible escaping */
4088 str = SysAllocString( szStrangeChars );
4089 hr = IXMLDOMElement_put_text(pElement, str);
4090 ok(hr == S_OK, "ret %08x\n", hr );
4091 SysFreeString( str );
4093 hr = IXMLDOMElement_get_xml(pElement, &str);
4094 ok(hr == S_OK, "ret %08x\n", hr );
4095 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
4098 hr = IXMLDOMElement_get_text(pElement, &str);
4099 ok(hr == S_OK, "ret %08x\n", hr );
4100 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
4103 IXMLDOMElement_Release(pElement);
4107 str = SysAllocString(szCData);
4108 hr = IXMLDOMDocument_createCDATASection(doc, str, NULL);
4109 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4111 hr = IXMLDOMDocument_createCDATASection(doc, str, &pCDataSec);
4113 ok(hr == S_OK, "ret %08x\n", hr );
4116 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
4121 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (void**)&pElement);
4122 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
4124 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
4125 ok(hr == S_OK, "ret %08x\n", hr );
4127 /* get Attribute Tests */
4128 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
4129 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4131 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4132 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
4133 ok(hr == S_FALSE, "ret %08x\n", hr );
4134 ok(pAttribs == NULL, "pAttribs != NULL\n");
4136 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
4137 ok(hr == S_OK, "ret %08x\n", hr );
4138 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
4141 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
4142 ok(hr == S_OK, "ret %08x\n", hr );
4143 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
4146 /* test lastChild */
4147 pNextChild = (IXMLDOMNode*)0x1;
4148 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
4149 ok(hr == S_FALSE, "ret %08x\n", hr );
4150 ok(pNextChild == NULL, "pNextChild not NULL\n");
4152 /* test get_dataType */
4153 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
4154 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4156 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
4157 ok(hr == S_FALSE, "ret %08x\n", hr );
4158 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4161 /* test nodeTypeString */
4162 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
4163 ok(hr == S_OK, "ret %08x\n", hr );
4164 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
4167 /* put data Tests */
4168 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
4169 ok(hr == S_OK, "ret %08x\n", hr );
4171 /* Confirm XML text is good */
4172 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
4173 ok(hr == S_OK, "ret %08x\n", hr );
4174 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
4177 /* Confirm we get the put_data Text back */
4178 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4179 ok(hr == S_OK, "ret %08x\n", hr );
4180 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
4183 /* test length property */
4184 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
4185 ok(hr == S_OK, "ret %08x\n", hr );
4186 ok(len == 21, "expected 21 got %d\n", len);
4188 /* test get nodeValue */
4189 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
4190 ok(hr == S_OK, "ret %08x\n", hr );
4191 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
4192 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
4196 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
4197 ok(hr == S_OK, "ret %08x\n", hr );
4198 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
4201 /* test substringData */
4202 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
4203 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4205 /* test substringData - Invalid offset */
4206 str = (BSTR)&szElement;
4207 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
4208 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4209 ok( str == NULL, "incorrect string\n");
4211 /* test substringData - Invalid offset */
4212 str = (BSTR)&szElement;
4213 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
4214 ok(hr == S_FALSE, "ret %08x\n", hr );
4215 ok( str == NULL, "incorrect string\n");
4217 /* test substringData - Invalid size */
4218 str = (BSTR)&szElement;
4219 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
4220 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4221 ok( str == NULL, "incorrect string\n");
4223 /* test substringData - Invalid size */
4224 str = (BSTR)&szElement;
4225 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
4226 ok(hr == S_FALSE, "ret %08x\n", hr );
4227 ok( str == NULL, "incorrect string\n");
4229 /* test substringData - Start of string */
4230 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
4231 ok(hr == S_OK, "ret %08x\n", hr );
4232 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
4235 /* test substringData - Middle of string */
4236 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
4237 ok(hr == S_OK, "ret %08x\n", hr );
4238 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
4241 /* test substringData - End of string */
4242 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
4243 ok(hr == S_OK, "ret %08x\n", hr );
4244 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
4247 /* test appendData */
4248 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
4249 ok(hr == S_OK, "ret %08x\n", hr );
4251 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
4252 ok(hr == S_OK, "ret %08x\n", hr );
4254 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
4255 ok(hr == S_OK, "ret %08x\n", hr );
4257 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4258 ok(hr == S_OK, "ret %08x\n", hr );
4259 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4262 /* test insertData */
4263 str = SysAllocStringLen(NULL, 0);
4264 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
4265 ok(hr == S_OK, "ret %08x\n", hr );
4267 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
4268 ok(hr == S_OK, "ret %08x\n", hr );
4270 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
4271 ok(hr == S_OK, "ret %08x\n", hr );
4273 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
4274 ok(hr == S_OK, "ret %08x\n", hr );
4276 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
4277 ok(hr == S_OK, "ret %08x\n", hr );
4279 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
4280 ok(hr == S_OK, "ret %08x\n", hr );
4283 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
4284 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4286 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
4287 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4289 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
4290 ok(hr == S_OK, "ret %08x\n", hr );
4292 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
4293 ok(hr == S_OK, "ret %08x\n", hr );
4295 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
4296 ok(hr == S_OK, "ret %08x\n", hr );
4298 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4299 ok(hr == S_OK, "ret %08x\n", hr );
4300 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4304 /* invalid arguments */
4305 hr = IXMLDOMCDATASection_deleteData(pCDataSec, -1, 1);
4306 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4308 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 0);
4309 ok(hr == S_OK, "ret %08x\n", hr );
4311 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, -1);
4312 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4314 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
4315 ok(hr == S_OK, "ret %08x\n", hr );
4316 ok(len == 43, "expected 43 got %d\n", len);
4318 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len, 1);
4319 ok(hr == S_OK, "ret %08x\n", hr );
4321 hr = IXMLDOMCDATASection_deleteData(pCDataSec, len+1, 1);
4322 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4324 /* delete from start */
4325 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, 5);
4326 ok(hr == S_OK, "ret %08x\n", hr );
4328 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
4329 ok(hr == S_OK, "ret %08x\n", hr );
4330 ok(len == 38, "expected 38 got %d\n", len);
4332 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4333 ok(hr == S_OK, "ret %08x\n", hr );
4334 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append End") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4337 /* delete from end */
4338 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 35, 3);
4339 ok(hr == S_OK, "ret %08x\n", hr );
4341 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
4342 ok(hr == S_OK, "ret %08x\n", hr );
4343 ok(len == 35, "expected 35 got %d\n", len);
4345 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4346 ok(hr == S_OK, "ret %08x\n", hr );
4347 ok( !lstrcmpW( str, _bstr_(" This &is a Middle; test <>\\Append ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4350 /* delete from inside */
4351 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 1, 33);
4352 ok(hr == S_OK, "ret %08x\n", hr );
4354 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
4355 ok(hr == S_OK, "ret %08x\n", hr );
4356 ok(len == 2, "expected 2 got %d\n", len);
4358 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4359 ok(hr == S_OK, "ret %08x\n", hr );
4360 ok( !lstrcmpW( str, _bstr_(" ") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4363 /* delete whole data ... */
4364 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
4365 ok(hr == S_OK, "ret %08x\n", hr );
4367 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
4368 ok(hr == S_OK, "ret %08x\n", hr );
4370 /* ... and try again with empty string */
4371 hr = IXMLDOMCDATASection_deleteData(pCDataSec, 0, len);
4372 ok(hr == S_OK, "ret %08x\n", hr );
4374 /* ::replaceData() */
4376 V_BSTR(&v) = SysAllocString(szstr1);
4377 hr = IXMLDOMCDATASection_put_nodeValue(pCDataSec, v);
4378 ok(hr == S_OK, "ret %08x\n", hr );
4381 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 6, 0, NULL);
4382 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4383 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4384 ok(hr == S_OK, "ret %08x\n", hr );
4385 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4388 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, NULL);
4389 ok(hr == S_OK, "ret %08x\n", hr );
4390 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4391 ok(hr == S_OK, "ret %08x\n", hr );
4392 ok( !lstrcmpW( str, _bstr_("str1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4395 /* NULL pointer means delete */
4396 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, NULL);
4397 ok(hr == S_OK, "ret %08x\n", hr );
4398 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4399 ok(hr == S_OK, "ret %08x\n", hr );
4400 ok( !lstrcmpW( str, _bstr_("tr1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4403 /* empty string means delete */
4404 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_(""));
4405 ok(hr == S_OK, "ret %08x\n", hr );
4406 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4407 ok(hr == S_OK, "ret %08x\n", hr );
4408 ok( !lstrcmpW( str, _bstr_("r1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4411 /* zero count means insert */
4412 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 0, _bstr_("a"));
4413 ok(hr == S_OK, "ret %08x\n", hr );
4414 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4415 ok(hr == S_OK, "ret %08x\n", hr );
4416 ok( !lstrcmpW( str, _bstr_("ar1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4419 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, NULL);
4420 ok(hr == S_OK, "ret %08x\n", hr );
4422 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("m"));
4423 ok(hr == S_OK, "ret %08x\n", hr );
4424 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4425 ok(hr == S_OK, "ret %08x\n", hr );
4426 ok( !lstrcmpW( str, _bstr_("m1") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4429 /* nonempty string, count greater than its length */
4430 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 2, _bstr_("a1.2"));
4431 ok(hr == S_OK, "ret %08x\n", hr );
4432 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4433 ok(hr == S_OK, "ret %08x\n", hr );
4434 ok( !lstrcmpW( str, _bstr_("a1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4437 /* nonempty string, count less than its length */
4438 hr = IXMLDOMCDATASection_replaceData(pCDataSec, 0, 1, _bstr_("wine"));
4439 ok(hr == S_OK, "ret %08x\n", hr );
4440 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
4441 ok(hr == S_OK, "ret %08x\n", hr );
4442 ok( !lstrcmpW( str, _bstr_("wine1.2") ), "incorrect get_text string, got '%s'\n", wine_dbgstr_w(str) );
4445 IXMLDOMCDATASection_Release(pCDataSec);
4448 /* Document Fragments */
4449 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
4450 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4452 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
4453 ok(hr == S_OK, "ret %08x\n", hr );
4458 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, NULL);
4459 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4461 node = (IXMLDOMNode *)0x1;
4462 hr = IXMLDOMDocumentFragment_get_parentNode(pDocFrag, &node);
4463 ok(hr == S_FALSE, "ret %08x\n", hr );
4464 ok(node == NULL, "expected NULL, got %p\n", node);
4466 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
4467 ok(hr == S_OK, "ret %08x\n", hr );
4469 /* get Attribute Tests */
4470 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
4471 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4473 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4474 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
4475 ok(hr == S_FALSE, "ret %08x\n", hr );
4476 ok(pAttribs == NULL, "pAttribs != NULL\n");
4478 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
4479 ok(hr == S_OK, "ret %08x\n", hr );
4480 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
4483 /* test next Sibling*/
4484 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
4485 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4487 node = (IXMLDOMNode *)0x1;
4488 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &node);
4489 ok(hr == S_FALSE, "ret %08x\n", hr );
4490 ok(node == NULL, "next sibling not NULL\n");
4492 /* test Previous Sibling*/
4493 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
4494 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4496 node = (IXMLDOMNode *)0x1;
4497 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &node);
4498 ok(hr == S_FALSE, "ret %08x\n", hr );
4499 ok(node == NULL, "previous sibling not NULL\n");
4501 /* test get_dataType */
4502 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
4503 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4505 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
4506 ok(hr == S_FALSE, "ret %08x\n", hr );
4507 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4510 /* test nodeTypeString */
4511 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
4512 ok(hr == S_OK, "ret %08x\n", hr );
4513 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
4516 IXMLDOMDocumentFragment_Release(pDocFrag);
4519 /* Entity References */
4520 hr = IXMLDOMDocument_createEntityReference(doc, NULL, &pEntityRef);
4521 ok(hr == E_FAIL, "ret %08x\n", hr );
4522 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_(""), &pEntityRef);
4523 ok(hr == E_FAIL, "ret %08x\n", hr );
4525 str = SysAllocString(szEntityRef);
4526 hr = IXMLDOMDocument_createEntityReference(doc, str, NULL);
4527 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4529 hr = IXMLDOMDocument_createEntityReference(doc, str, &pEntityRef);
4531 ok(hr == S_OK, "ret %08x\n", hr );
4534 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
4535 ok(hr == S_OK, "ret %08x\n", hr );
4537 /* get Attribute Tests */
4538 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
4539 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4541 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
4542 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
4543 ok(hr == S_FALSE, "ret %08x\n", hr );
4544 ok(pAttribs == NULL, "pAttribs != NULL\n");
4547 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
4548 ok(hr == S_FALSE, "ret %08x\n", hr );
4549 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
4552 /* test nodeTypeString */
4553 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
4554 ok(hr == S_OK, "ret %08x\n", hr );
4555 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
4559 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
4560 ok(hr == S_OK, "ret %08x\n", hr );
4561 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
4564 IXMLDOMEntityReference_Release(pEntityRef);
4567 IXMLDOMElement_Release( pRoot );
4571 IXMLDOMDocument_Release(doc);
4576 static void test_nodeTypeTests( void )
4578 IXMLDOMDocument *doc = NULL;
4579 IXMLDOMElement *pRoot;
4580 IXMLDOMElement *pElement;
4583 doc = create_document(&IID_IXMLDOMDocument);
4586 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), NULL);
4587 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4589 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
4590 ok(hr == S_OK, "ret %08x\n", hr );
4593 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
4594 ok(hr == S_OK, "ret %08x\n", hr );
4597 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
4598 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4601 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
4602 ok(hr == E_FAIL, "ret %08x\n", hr );
4605 * The name passed into put_dataType is case-insensitive. So many of the names
4606 * have been changed to reflect this.
4609 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
4610 ok(hr == S_OK, "ret %08x\n", hr );
4613 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4615 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
4616 ok(hr == S_OK, "ret %08x\n", hr );
4618 IXMLDOMElement_Release(pElement);
4622 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
4623 ok(hr == S_OK, "ret %08x\n", hr );
4626 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4628 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
4629 ok(hr == S_OK, "ret %08x\n", hr );
4631 IXMLDOMElement_Release(pElement);
4635 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
4636 ok(hr == S_OK, "ret %08x\n", hr );
4639 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4641 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
4642 ok(hr == S_OK, "ret %08x\n", hr );
4644 IXMLDOMElement_Release(pElement);
4648 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
4649 ok(hr == S_OK, "ret %08x\n", hr );
4652 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4654 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
4655 ok(hr == S_OK, "ret %08x\n", hr );
4657 IXMLDOMElement_Release(pElement);
4661 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
4662 ok(hr == S_OK, "ret %08x\n", hr );
4665 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4667 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
4668 ok(hr == S_OK, "ret %08x\n", hr );
4670 IXMLDOMElement_Release(pElement);
4674 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
4675 ok(hr == S_OK, "ret %08x\n", hr );
4678 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4680 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
4681 ok(hr == S_OK, "ret %08x\n", hr );
4683 IXMLDOMElement_Release(pElement);
4687 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
4688 ok(hr == S_OK, "ret %08x\n", hr );
4691 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4693 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
4694 ok(hr == S_OK, "ret %08x\n", hr );
4696 IXMLDOMElement_Release(pElement);
4700 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
4701 ok(hr == S_OK, "ret %08x\n", hr );
4704 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4706 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
4707 ok(hr == S_OK, "ret %08x\n", hr );
4709 IXMLDOMElement_Release(pElement);
4713 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
4714 ok(hr == S_OK, "ret %08x\n", hr );
4717 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4719 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
4720 ok(hr == S_OK, "ret %08x\n", hr );
4722 IXMLDOMElement_Release(pElement);
4726 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
4727 ok(hr == S_OK, "ret %08x\n", hr );
4730 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4732 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
4733 ok(hr == S_OK, "ret %08x\n", hr );
4735 IXMLDOMElement_Release(pElement);
4739 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
4740 ok(hr == S_OK, "ret %08x\n", hr );
4743 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4745 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
4746 ok(hr == S_OK, "ret %08x\n", hr );
4748 IXMLDOMElement_Release(pElement);
4752 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
4753 ok(hr == S_OK, "ret %08x\n", hr );
4756 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4758 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
4759 ok(hr == S_OK, "ret %08x\n", hr );
4761 IXMLDOMElement_Release(pElement);
4765 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
4766 ok(hr == S_OK, "ret %08x\n", hr );
4769 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4771 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
4772 ok(hr == S_OK, "ret %08x\n", hr );
4774 IXMLDOMElement_Release(pElement);
4778 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
4779 ok(hr == S_OK, "ret %08x\n", hr );
4782 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4784 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
4785 ok(hr == S_OK, "ret %08x\n", hr );
4787 IXMLDOMElement_Release(pElement);
4791 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
4792 ok(hr == S_OK, "ret %08x\n", hr );
4795 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4797 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
4798 ok(hr == S_OK, "ret %08x\n", hr );
4800 IXMLDOMElement_Release(pElement);
4804 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
4805 ok(hr == S_OK, "ret %08x\n", hr );
4808 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4810 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
4811 ok(hr == S_OK, "ret %08x\n", hr );
4813 IXMLDOMElement_Release(pElement);
4817 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
4818 ok(hr == S_OK, "ret %08x\n", hr );
4821 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4823 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
4824 ok(hr == S_OK, "ret %08x\n", hr );
4826 IXMLDOMElement_Release(pElement);
4830 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
4831 ok(hr == S_OK, "ret %08x\n", hr );
4834 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4836 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
4837 ok(hr == S_OK, "ret %08x\n", hr );
4839 IXMLDOMElement_Release(pElement);
4843 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
4844 ok(hr == S_OK, "ret %08x\n", hr );
4847 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4849 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
4850 ok(hr == S_OK, "ret %08x\n", hr );
4852 IXMLDOMElement_Release(pElement);
4856 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
4857 ok(hr == S_OK, "ret %08x\n", hr );
4860 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4862 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
4863 ok(hr == S_OK, "ret %08x\n", hr );
4865 IXMLDOMElement_Release(pElement);
4869 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
4870 ok(hr == S_OK, "ret %08x\n", hr );
4873 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4875 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
4876 ok(hr == S_OK, "ret %08x\n", hr );
4878 IXMLDOMElement_Release(pElement);
4882 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
4883 ok(hr == S_OK, "ret %08x\n", hr );
4886 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4888 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
4889 ok(hr == S_OK, "ret %08x\n", hr );
4891 IXMLDOMElement_Release(pElement);
4894 /* Check changing types */
4895 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
4896 ok(hr == S_OK, "ret %08x\n", hr );
4899 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
4901 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
4902 ok(hr == S_OK, "ret %08x\n", hr );
4904 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
4905 ok(hr == S_OK, "ret %08x\n", hr );
4907 IXMLDOMElement_Release(pElement);
4910 IXMLDOMElement_Release(pRoot);
4914 IXMLDOMDocument_Release(doc);
4919 static void test_DocumentSaveToDocument(void)
4921 IXMLDOMDocument *doc, *doc2;
4922 IXMLDOMElement *pRoot;
4925 doc = create_document(&IID_IXMLDOMDocument);
4928 doc2 = create_document(&IID_IXMLDOMDocument);
4931 IXMLDOMDocument_Release(doc);
4935 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
4936 ok(hr == S_OK, "ret %08x\n", hr );
4939 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
4940 ok(hr == S_OK, "ret %08x\n", hr );
4947 V_VT(&vDoc) = VT_UNKNOWN;
4948 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
4950 hr = IXMLDOMDocument_save(doc, vDoc);
4951 ok(hr == S_OK, "ret %08x\n", hr );
4953 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
4954 ok(hr == S_OK, "ret %08x\n", hr );
4956 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
4957 ok(hr == S_OK, "ret %08x\n", hr );
4959 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
4961 SysFreeString(sOrig);
4962 SysFreeString(sNew);
4966 IXMLDOMDocument_Release(doc2);
4967 IXMLDOMDocument_Release(doc);
4970 static void test_DocumentSaveToFile(void)
4972 IXMLDOMDocument *doc;
4973 IXMLDOMElement *pRoot;
4979 doc = create_document(&IID_IXMLDOMDocument);
4982 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
4983 ok(hr == S_OK, "ret %08x\n", hr );
4986 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
4987 ok(hr == S_OK, "ret %08x\n", hr );
4992 V_VT(&vFile) = VT_BSTR;
4993 V_BSTR(&vFile) = _bstr_("test.xml");
4995 hr = IXMLDOMDocument_save(doc, vFile);
4996 ok(hr == S_OK, "ret %08x\n", hr );
5000 IXMLDOMElement_Release(pRoot);
5001 IXMLDOMDocument_Release(doc);
5003 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
5004 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
5005 if(file == INVALID_HANDLE_VALUE)
5008 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
5009 ok(read != 0, "could not read file\n");
5010 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
5013 DeleteFile("test.xml");
5016 static void test_testTransforms(void)
5018 IXMLDOMDocument *doc, *docSS;
5024 doc = create_document(&IID_IXMLDOMDocument);
5027 docSS = create_document(&IID_IXMLDOMDocument);
5030 IXMLDOMDocument_Release(doc);
5034 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
5035 ok(hr == S_OK, "ret %08x\n", hr );
5037 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
5038 ok(hr == S_OK, "ret %08x\n", hr );
5040 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (void**)&pNode );
5041 ok(hr == S_OK, "ret %08x\n", hr );
5046 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
5047 ok(hr == S_OK, "ret %08x\n", hr );
5048 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
5049 SysFreeString(bOut);
5051 IXMLDOMNode_Release(pNode);
5054 IXMLDOMDocument_Release(docSS);
5055 IXMLDOMDocument_Release(doc);
5060 static void test_Namespaces(void)
5062 IXMLDOMDocument *doc;
5064 IXMLDOMNode *pNode2 = NULL;
5068 static const CHAR szNamespacesXML[] =
5069 "<?xml version=\"1.0\"?>\n"
5070 "<root xmlns:WEB='http://www.winehq.org'>\n"
5071 "<WEB:Site version=\"1.0\" />\n"
5074 doc = create_document(&IID_IXMLDOMDocument);
5077 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
5078 ok(hr == S_OK, "ret %08x\n", hr );
5079 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
5081 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
5082 ok(hr == S_OK, "ret %08x\n", hr );
5085 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
5086 ok( hr == S_OK, "ret %08x\n", hr );
5087 ok( pNode2 != NULL, "pNode2 == NULL\n");
5089 /* Test get_prefix */
5090 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
5091 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
5092 /* NOTE: Need to test that arg2 gets cleared on Error. */
5094 hr = IXMLDOMNode_get_prefix(pNode2, &str);
5095 ok( hr == S_OK, "ret %08x\n", hr );
5096 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
5099 /* Test get_namespaceURI */
5100 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
5101 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
5102 /* NOTE: Need to test that arg2 gets cleared on Error. */
5104 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
5105 ok( hr == S_OK, "ret %08x\n", hr );
5106 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
5109 IXMLDOMNode_Release(pNode2);
5110 IXMLDOMNode_Release(pNode);
5113 IXMLDOMDocument_Release(doc);
5118 static void test_FormattingXML(void)
5120 IXMLDOMDocument *doc;
5121 IXMLDOMElement *pElement;
5125 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
5126 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
5128 doc = create_document(&IID_IXMLDOMDocument);
5131 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
5132 ok(hr == S_OK, "ret %08x\n", hr );
5133 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
5135 if(bSucc == VARIANT_TRUE)
5137 hr = IXMLDOMDocument_get_documentElement(doc, &pElement);
5138 ok(hr == S_OK, "ret %08x\n", hr );
5141 hr = IXMLDOMElement_get_xml(pElement, &str);
5142 ok(hr == S_OK, "ret %08x\n", hr );
5143 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
5146 IXMLDOMElement_Release(pElement);
5150 IXMLDOMDocument_Release(doc);
5155 typedef struct _nodetypedvalue_t {
5158 const char *value; /* value in string format */
5161 static const nodetypedvalue_t get_nodetypedvalue[] = {
5162 { "root/string", VT_BSTR, "Wine" },
5163 { "root/string2", VT_BSTR, "String" },
5164 { "root/number", VT_BSTR, "12.44" },
5165 { "root/number2", VT_BSTR, "-3.71e3" },
5166 { "root/int", VT_I4, "-13" },
5167 { "root/fixed", VT_CY, "7322.9371" },
5168 { "root/bool", VT_BOOL, "-1" },
5169 { "root/datetime", VT_DATE, "40135.14" },
5170 { "root/datetimetz",VT_DATE, "37813.59" },
5171 { "root/date", VT_DATE, "665413" },
5172 { "root/time", VT_DATE, "0.5813889" },
5173 { "root/timetz", VT_DATE, "1.112512" },
5174 { "root/i1", VT_I1, "-13" },
5175 { "root/i2", VT_I2, "31915" },
5176 { "root/i4", VT_I4, "-312232" },
5177 { "root/ui1", VT_UI1, "123" },
5178 { "root/ui2", VT_UI2, "48282" },
5179 { "root/ui4", VT_UI4, "949281" },
5180 { "root/r4", VT_R4, "213124" },
5181 { "root/r8", VT_R8, "0.412" },
5182 { "root/float", VT_R8, "41221.421" },
5183 { "root/uuid", VT_BSTR, "333C7BC4-460F-11D0-BC04-0080C7055a83" },
5187 static void test_nodeTypedValue(void)
5189 const nodetypedvalue_t *entry = get_nodetypedvalue;
5190 IXMLDOMDocument *doc;
5196 doc = create_document(&IID_IXMLDOMDocument);
5200 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &b);
5201 ok(hr == S_OK, "ret %08x\n", hr );
5202 ok(b == VARIANT_TRUE, "got %d\n", b);
5204 hr = IXMLDOMDocument_get_nodeValue(doc, NULL);
5205 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5207 V_VT(&value) = VT_BSTR;
5208 V_BSTR(&value) = NULL;
5209 hr = IXMLDOMDocument_get_nodeValue(doc, &value);
5210 ok(hr == S_FALSE, "ret %08x\n", hr );
5211 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
5213 hr = IXMLDOMDocument_get_nodeTypedValue(doc, NULL);
5214 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5216 hr = IXMLDOMDocument_get_nodeTypedValue(doc, &value);
5217 ok(hr == S_FALSE, "ret %08x\n", hr );
5219 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/string"), &node);
5220 ok(hr == S_OK, "ret %08x\n", hr );
5222 V_VT(&value) = VT_BSTR;
5223 V_BSTR(&value) = NULL;
5224 hr = IXMLDOMNode_get_nodeValue(node, &value);
5225 ok(hr == S_FALSE, "ret %08x\n", hr );
5226 ok(V_VT(&value) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&value));
5228 hr = IXMLDOMNode_get_nodeTypedValue(node, NULL);
5229 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
5231 IXMLDOMNode_Release(node);
5233 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binhex"), &node);
5234 ok(hr == S_OK, "ret %08x\n", hr );
5236 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
5238 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
5239 ok(hr == S_OK, "ret %08x\n", hr );
5240 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
5241 ok(V_ARRAY(&value)->rgsabound[0].cElements == 6, "incorrect array size\n");
5242 if(V_ARRAY(&value)->rgsabound[0].cElements == 6)
5243 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
5244 VariantClear(&value);
5245 IXMLDOMNode_Release(node);
5248 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root/binbase64"), &node);
5249 ok(hr == S_OK, "ret %08x\n", hr );
5251 BYTE bytes[] = {0x62,0x61,0x73,0x65,0x36,0x34,0x20,0x74,0x65,0x73,0x74};
5253 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
5254 ok(hr == S_OK, "ret %08x\n", hr );
5255 ok(V_VT(&value) == (VT_ARRAY|VT_UI1), "incorrect type\n");
5256 ok(V_ARRAY(&value)->rgsabound[0].cElements == 11, "incorrect array size\n");
5257 if(V_ARRAY(&value)->rgsabound[0].cElements == 11)
5258 ok(!memcmp(bytes, V_ARRAY(&value)->pvData, sizeof(bytes)), "incorrect value\n");
5259 VariantClear(&value);
5260 IXMLDOMNode_Release(node);
5265 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_(entry->name), &node);
5266 ok(hr == S_OK, "ret %08x\n", hr );
5268 hr = IXMLDOMNode_get_nodeTypedValue(node, &value);
5269 ok(hr == S_OK, "ret %08x\n", hr );
5270 ok(V_VT(&value) == entry->type, "incorrect type, expected %d, got %d\n", entry->type, V_VT(&value));
5272 if (entry->type != VT_BSTR)
5274 if (entry->type == VT_DATE ||
5275 entry->type == VT_R8 ||
5276 entry->type == VT_CY)
5278 if (entry->type == VT_DATE)
5280 hr = VariantChangeType(&value, &value, 0, VT_R4);
5281 ok(hr == S_OK, "ret %08x\n", hr );
5283 hr = VariantChangeTypeEx(&value, &value,
5284 MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT),
5285 VARIANT_NOUSEROVERRIDE, VT_BSTR);
5286 ok(hr == S_OK, "ret %08x\n", hr );
5290 hr = VariantChangeType(&value, &value, 0, VT_BSTR);
5291 ok(hr == S_OK, "ret %08x\n", hr );
5294 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
5295 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
5298 ok(lstrcmpW( V_BSTR(&value), _bstr_(entry->value)) == 0,
5299 "expected %s, got %s\n", entry->value, wine_dbgstr_w(V_BSTR(&value)));
5301 VariantClear( &value );
5302 IXMLDOMNode_Release(node);
5307 IXMLDOMDocument_Release(doc);
5311 static void test_TransformWithLoadingLocalFile(void)
5313 IXMLDOMDocument *doc;
5314 IXMLDOMDocument *xsl;
5320 char lpPathBuffer[MAX_PATH];
5323 /* Create a Temp File. */
5324 GetTempPathA(MAX_PATH, lpPathBuffer);
5325 strcat(lpPathBuffer, "customers.xml" );
5327 file = CreateFile(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
5328 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
5329 if(file == INVALID_HANDLE_VALUE)
5332 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
5335 /* Correct path to not include a escape character. */
5336 for(i=0; i < strlen(lpPathBuffer); i++)
5338 if(lpPathBuffer[i] == '\\')
5339 lpPathBuffer[i] = '/';
5342 doc = create_document(&IID_IXMLDOMDocument);
5345 xsl = create_document(&IID_IXMLDOMDocument);
5348 IXMLDOMDocument2_Release(doc);
5352 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
5353 ok(hr == S_OK, "ret %08x\n", hr );
5354 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
5355 if(bSucc == VARIANT_TRUE)
5358 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
5359 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
5360 BSTR sFileName = _bstr_(lpPathBuffer);
5361 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
5363 sXSL = SysAllocStringLen(NULL, nLegnth);
5364 lstrcpyW(sXSL, sPart1);
5365 lstrcatW(sXSL, sFileName);
5366 lstrcatW(sXSL, sPart2);
5368 hr = IXMLDOMDocument_loadXML(xsl, sXSL, &bSucc);
5369 ok(hr == S_OK, "ret %08x\n", hr );
5370 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
5371 if(bSucc == VARIANT_TRUE)
5375 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (void**)&pNode );
5376 ok(hr == S_OK, "ret %08x\n", hr );
5379 /* This will load the temp file via the XSL */
5380 hr = IXMLDOMDocument_transformNode(doc, pNode, &sResult);
5381 ok(hr == S_OK, "ret %08x\n", hr );
5384 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
5385 SysFreeString(sResult);
5388 IXMLDOMNode_Release(pNode);
5392 SysFreeString(sXSL);
5395 IXMLDOMDocument_Release(doc);
5396 IXMLDOMDocument_Release(xsl);
5398 DeleteFile(lpPathBuffer);
5402 static void test_put_nodeValue(void)
5404 IXMLDOMDocument *doc;
5405 IXMLDOMEntityReference *entityref;
5410 doc = create_document(&IID_IXMLDOMDocument);
5413 /* test for unsupported types */
5415 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (void**)&node);
5416 ok(hr == S_OK, "ret %08x\n", hr );
5417 V_VT(&data) = VT_BSTR;
5418 V_BSTR(&data) = _bstr_("one two three");
5419 hr = IXMLDOMNode_put_nodeValue(node, data);
5420 ok(hr == E_FAIL, "ret %08x\n", hr );
5421 IXMLDOMNode_Release(node);
5423 /* NODE_DOCUMENT_FRAGMENT */
5424 V_VT(&type) = VT_I1;
5425 V_I1(&type) = NODE_DOCUMENT_FRAGMENT;
5426 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
5427 ok(hr == S_OK, "ret %08x\n", hr );
5428 V_VT(&data) = VT_BSTR;
5429 V_BSTR(&data) = _bstr_("one two three");
5430 hr = IXMLDOMNode_put_nodeValue(node, data);
5431 ok(hr == E_FAIL, "ret %08x\n", hr );
5432 IXMLDOMNode_Release(node);
5435 V_VT(&type) = VT_I1;
5436 V_I1(&type) = NODE_ELEMENT;
5437 hr = IXMLDOMDocument_createNode(doc, type, _bstr_("test"), NULL, &node);
5438 ok(hr == S_OK, "ret %08x\n", hr );
5439 V_VT(&data) = VT_BSTR;
5440 V_BSTR(&data) = _bstr_("one two three");
5441 hr = IXMLDOMNode_put_nodeValue(node, data);
5442 ok(hr == E_FAIL, "ret %08x\n", hr );
5443 IXMLDOMNode_Release(node);
5445 /* NODE_ENTITY_REFERENCE */
5446 hr = IXMLDOMDocument_createEntityReference(doc, _bstr_("ref"), &entityref);
5447 ok(hr == S_OK, "ret %08x\n", hr );
5449 V_VT(&data) = VT_BSTR;
5450 V_BSTR(&data) = _bstr_("one two three");
5451 hr = IXMLDOMEntityReference_put_nodeValue(entityref, data);
5452 ok(hr == E_FAIL, "ret %08x\n", hr );
5454 hr = IXMLDOMEntityReference_QueryInterface(entityref, &IID_IXMLDOMNode, (void**)&node);
5455 ok(hr == S_OK, "ret %08x\n", hr );
5456 V_VT(&data) = VT_BSTR;
5457 V_BSTR(&data) = _bstr_("one two three");
5458 hr = IXMLDOMNode_put_nodeValue(node, data);
5459 ok(hr == E_FAIL, "ret %08x\n", hr );
5460 IXMLDOMNode_Release(node);
5461 IXMLDOMEntityReference_Release(entityref);
5465 IXMLDOMDocument_Release(doc);
5468 static void test_IObjectSafety_set(IObjectSafety *safety, HRESULT result, HRESULT result2, DWORD set, DWORD mask, DWORD expected, DWORD expected2)
5470 DWORD enabled, supported;
5473 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL, set, mask);
5474 if (result == result2)
5475 ok(hr == result, "SetInterfaceSafetyOptions: expected %08x, returned %08x\n", result, hr );
5477 ok(broken(hr == result) || hr == result2,
5478 "SetInterfaceSafetyOptions: expected %08x, got %08x\n", result2, hr );
5480 supported = enabled = 0xCAFECAFE;
5481 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
5482 ok(hr == S_OK, "ret %08x\n", hr );
5483 if (expected == expected2)
5484 ok(enabled == expected, "Expected %08x, got %08x\n", expected, enabled);
5486 ok(broken(enabled == expected) || enabled == expected2,
5487 "Expected %08x, got %08x\n", expected2, enabled);
5489 /* reset the safety options */
5491 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
5492 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER,
5494 ok(hr == S_OK, "ret %08x\n", hr );
5496 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
5497 ok(hr == S_OK, "ret %08x\n", hr );
5498 ok(enabled == 0, "Expected 0, got %08x\n", enabled);
5501 static void test_document_IObjectSafety(void)
5503 IXMLDOMDocument *doc;
5504 IObjectSafety *safety;
5505 DWORD enabled = 0, supported = 0;
5508 doc = create_document(&IID_IXMLDOMDocument);
5511 hr = IXMLDOMDocument_QueryInterface(doc, &IID_IObjectSafety, (void**)&safety);
5512 ok(hr == S_OK, "ret %08x\n", hr );
5515 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, NULL, &enabled);
5516 ok(hr == E_POINTER, "ret %08x\n", hr );
5517 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, NULL);
5518 ok(hr == E_POINTER, "ret %08x\n", hr );
5520 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
5521 ok(hr == S_OK, "ret %08x\n", hr );
5522 ok(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
5523 supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
5524 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), "
5525 "got %08x\n", supported);
5526 ok(enabled == 0, "Expected 0, got %08x\n", enabled);
5528 /* set -- individual flags */
5530 test_IObjectSafety_set(safety, S_OK, S_OK,
5531 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER,
5532 INTERFACESAFE_FOR_UNTRUSTED_CALLER, INTERFACESAFE_FOR_UNTRUSTED_CALLER);
5534 test_IObjectSafety_set(safety, S_OK, S_OK,
5535 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA,
5536 INTERFACESAFE_FOR_UNTRUSTED_DATA, INTERFACESAFE_FOR_UNTRUSTED_DATA);
5538 test_IObjectSafety_set(safety, S_OK, S_OK,
5539 INTERFACE_USES_SECURITY_MANAGER, INTERFACE_USES_SECURITY_MANAGER,
5540 0, INTERFACE_USES_SECURITY_MANAGER /* msxml3 SP8+ */);
5542 /* set INTERFACE_USES_DISPEX */
5544 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
5545 INTERFACE_USES_DISPEX, INTERFACE_USES_DISPEX,
5548 test_IObjectSafety_set(safety, S_OK, E_FAIL /* msxml3 SP8+ */,
5549 INTERFACE_USES_DISPEX, 0,
5552 test_IObjectSafety_set(safety, S_OK, S_OK /* msxml3 SP8+ */,
5553 0, INTERFACE_USES_DISPEX,
5556 /* set option masking */
5558 test_IObjectSafety_set(safety, S_OK, S_OK,
5559 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
5560 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
5561 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
5562 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
5564 test_IObjectSafety_set(safety, S_OK, S_OK,
5565 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
5566 INTERFACESAFE_FOR_UNTRUSTED_DATA,
5567 INTERFACESAFE_FOR_UNTRUSTED_DATA,
5568 INTERFACESAFE_FOR_UNTRUSTED_DATA);
5570 test_IObjectSafety_set(safety, S_OK, S_OK,
5571 INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA,
5572 INTERFACE_USES_SECURITY_MANAGER,
5576 /* set -- inheriting previous settings */
5578 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
5579 INTERFACESAFE_FOR_UNTRUSTED_CALLER,
5580 INTERFACESAFE_FOR_UNTRUSTED_CALLER);
5581 ok(hr == S_OK, "ret %08x\n", hr );
5582 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
5583 ok(hr == S_OK, "ret %08x\n", hr );
5585 ok(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_CALLER) ||
5586 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
5587 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACE_USES_SECURITY_MANAGER), "
5588 "got %08x\n", enabled);
5590 hr = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
5591 INTERFACESAFE_FOR_UNTRUSTED_DATA,
5592 INTERFACESAFE_FOR_UNTRUSTED_DATA);
5593 ok(hr == S_OK, "ret %08x\n", hr );
5594 hr = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
5595 ok(hr == S_OK, "ret %08x\n", hr );
5597 ok(broken(enabled == INTERFACESAFE_FOR_UNTRUSTED_DATA) ||
5598 enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA) /* msxml3 SP8+ */,
5599 "Expected (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA), "
5600 "got %08x\n", enabled);
5602 IObjectSafety_Release(safety);
5604 IXMLDOMDocument_Release(doc);
5607 typedef struct _property_test_t {
5610 const char *property;
5614 static const property_test_t properties_test_data[] = {
5615 { &CLSID_DOMDocument, "CLSID_DOMDocument" , "SelectionLanguage", "XSLPattern" },
5616 { &CLSID_DOMDocument2, "CLSID_DOMDocument2" , "SelectionLanguage", "XSLPattern" },
5617 { &CLSID_DOMDocument30, "CLSID_DOMDocument30", "SelectionLanguage", "XSLPattern" },
5618 { &CLSID_DOMDocument40, "CLSID_DOMDocument40", "SelectionLanguage", "XPath" },
5619 { &CLSID_DOMDocument60, "CLSID_DOMDocument60", "SelectionLanguage", "XPath" },
5623 static void test_default_properties(void)
5625 const property_test_t *entry = properties_test_data;
5626 IXMLDOMDocument2 *doc;
5632 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void**)&doc);
5635 win_skip("can't create %s instance\n", entry->clsid);
5640 hr = IXMLDOMDocument2_getProperty(doc, _bstr_(entry->property), &var);
5641 ok(hr == S_OK, "got 0x%08x\n", hr);
5642 ok(lstrcmpW(V_BSTR(&var), _bstr_(entry->value)) == 0, "expected %s, for %s\n",
5643 entry->value, entry->clsid);
5646 IXMLDOMDocument2_Release(doc);
5652 static void test_XSLPattern(void)
5654 IXMLDOMDocument2 *doc;
5655 IXMLDOMNodeList *list;
5659 doc = create_document(&IID_IXMLDOMDocument2);
5662 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szExampleXML), &b));
5663 ok(b == VARIANT_TRUE, "failed to load XML string\n");
5665 /* switch to XSLPattern */
5666 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
5668 /* XPath doesn't select elements with non-null default namespace with unqualified selectors, XSLPattern does */
5669 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("//elem/c"), &list));
5671 ole_check(IXMLDOMNodeList_get_length(list, &len));
5672 /* should select <elem><c> and <elem xmlns='...'><c> but not <elem><foo:c> */
5673 todo_wine ok(len == 3, "expected 3 entries in list, got %d\n", len);
5674 IXMLDOMNodeList_Release(list);
5676 /* for XSLPattern start index is 0, for XPath it's 1 */
5677 ole_check(IXMLDOMDocument2_selectNodes(doc, _bstr_("root//elem[0]"), &list));
5679 ole_check(IXMLDOMNodeList_get_length(list, &len));
5680 todo_wine ok(len != 0, "expected filled list\n");
5682 todo_wine expect_list_and_release(list, "E1.E2.D1");
5684 IXMLDOMDocument2_Release(doc);
5688 static void test_splitText(void)
5690 IXMLDOMCDATASection *cdata;
5691 IXMLDOMElement *root;
5692 IXMLDOMDocument *doc;
5693 IXMLDOMText *text, *text2;
5696 VARIANT_BOOL success;
5700 doc = create_document(&IID_IXMLDOMDocument);
5703 hr = IXMLDOMDocument_loadXML(doc, _bstr_("<root></root>"), &success);
5704 ok(hr == S_OK, "got 0x%08x\n", hr);
5706 hr = IXMLDOMDocument_get_documentElement(doc, &root);
5707 ok(hr == S_OK, "got 0x%08x\n", hr);
5709 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("beautiful plumage"), &cdata);
5710 ok(hr == S_OK, "got 0x%08x\n", hr);
5712 V_VT(&var) = VT_EMPTY;
5713 hr = IXMLDOMElement_appendChild(root, (IXMLDOMNode*)cdata, NULL);
5714 ok(hr == S_OK, "got 0x%08x\n", hr);
5717 hr = IXMLDOMCDATASection_get_length(cdata, &length);
5718 ok(hr == S_OK, "got 0x%08x\n", hr);
5719 ok(length > 0, "got %d\n", length);
5721 hr = IXMLDOMCDATASection_splitText(cdata, 0, NULL);
5722 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
5724 text = (void*)0xdeadbeef;
5725 /* negative offset */
5726 hr = IXMLDOMCDATASection_splitText(cdata, -1, &text);
5727 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
5728 ok(text == (void*)0xdeadbeef, "got %p\n", text);
5730 text = (void*)0xdeadbeef;
5731 /* offset outside data */
5732 hr = IXMLDOMCDATASection_splitText(cdata, length + 1, &text);
5733 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
5734 ok(text == 0, "got %p\n", text);
5736 text = (void*)0xdeadbeef;
5737 /* offset outside data */
5738 hr = IXMLDOMCDATASection_splitText(cdata, length, &text);
5739 ok(hr == S_FALSE, "got 0x%08x\n", hr);
5740 ok(text == 0, "got %p\n", text);
5742 /* no empty node created */
5743 node = (void*)0xdeadbeef;
5744 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
5745 ok(hr == S_FALSE, "got 0x%08x\n", hr);
5746 ok(node == 0, "got %p\n", text);
5748 hr = IXMLDOMCDATASection_splitText(cdata, 10, &text);
5749 ok(hr == S_OK, "got 0x%08x\n", hr);
5752 hr = IXMLDOMText_get_length(text, &length);
5753 ok(hr == S_OK, "got 0x%08x\n", hr);
5754 ok(length == 7, "got %d\n", length);
5756 hr = IXMLDOMCDATASection_get_nextSibling(cdata, &node);
5757 ok(hr == S_OK, "got 0x%08x\n", hr);
5758 IXMLDOMNode_Release(node);
5760 /* split new text node */
5761 hr = IXMLDOMText_get_length(text, &length);
5762 ok(hr == S_OK, "got 0x%08x\n", hr);
5764 node = (void*)0xdeadbeef;
5765 hr = IXMLDOMText_get_nextSibling(text, &node);
5766 ok(hr == S_FALSE, "got 0x%08x\n", hr);
5767 ok(node == 0, "got %p\n", text);
5769 hr = IXMLDOMText_splitText(text, 0, NULL);
5770 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
5772 text2 = (void*)0xdeadbeef;
5773 /* negative offset */
5774 hr = IXMLDOMText_splitText(text, -1, &text2);
5775 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
5776 ok(text2 == (void*)0xdeadbeef, "got %p\n", text2);
5778 text2 = (void*)0xdeadbeef;
5779 /* offset outside data */
5780 hr = IXMLDOMText_splitText(text, length + 1, &text2);
5781 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
5782 ok(text2 == 0, "got %p\n", text2);
5784 text2 = (void*)0xdeadbeef;
5785 /* offset outside data */
5786 hr = IXMLDOMText_splitText(text, length, &text2);
5787 ok(hr == S_FALSE, "got 0x%08x\n", hr);
5788 ok(text2 == 0, "got %p\n", text);
5791 hr = IXMLDOMText_splitText(text, 4, &text2);
5792 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
5793 if (text2) IXMLDOMText_Release(text2);
5796 hr = IXMLDOMText_get_nextSibling(text, &node);
5797 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
5798 if (node) IXMLDOMNode_Release(node);
5800 IXMLDOMText_Release(text);
5801 IXMLDOMElement_Release(root);
5802 IXMLDOMCDATASection_Release(cdata);
5806 static void test_getQualifiedItem(void)
5808 IXMLDOMDocument *doc;
5809 IXMLDOMElement *element;
5810 IXMLDOMNode *pr_node, *node;
5811 IXMLDOMNodeList *root_list;
5812 IXMLDOMNamedNodeMap *map;
5818 doc = create_document(&IID_IXMLDOMDocument);
5821 str = SysAllocString( szComplete4 );
5822 hr = IXMLDOMDocument_loadXML( doc, str, &b );
5823 ok( hr == S_OK, "loadXML failed\n");
5824 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5825 SysFreeString( str );
5827 hr = IXMLDOMDocument_get_documentElement(doc, &element);
5828 ok( hr == S_OK, "ret %08x\n", hr);
5830 hr = IXMLDOMElement_get_childNodes(element, &root_list);
5831 ok( hr == S_OK, "ret %08x\n", hr);
5833 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
5834 ok( hr == S_OK, "ret %08x\n", hr);
5835 IXMLDOMNodeList_Release(root_list);
5837 hr = IXMLDOMNode_get_attributes(pr_node, &map);
5838 ok( hr == S_OK, "ret %08x\n", hr);
5839 IXMLDOMNode_Release(pr_node);
5841 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
5842 ok( hr == S_OK, "ret %08x\n", hr);
5843 ok( len == 3, "length %d\n", len);
5845 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, NULL);
5846 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
5848 node = (void*)0xdeadbeef;
5849 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, NULL, NULL, &node);
5850 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
5851 ok( node == (void*)0xdeadbeef, "got %p\n", node);
5853 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, NULL);
5854 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
5856 hr = IXMLDOMNamedNodeMap_getQualifiedItem(map, _bstr_("id"), NULL, &node);
5857 ok( hr == S_OK, "ret %08x\n", hr);
5858 IXMLDOMNode_Release(node);
5860 IXMLDOMNamedNodeMap_Release( map );
5861 IXMLDOMElement_Release( element );
5862 IXMLDOMDocument_Release( doc );
5866 static void test_removeQualifiedItem(void)
5868 IXMLDOMDocument *doc;
5869 IXMLDOMElement *element;
5870 IXMLDOMNode *pr_node, *node;
5871 IXMLDOMNodeList *root_list;
5872 IXMLDOMNamedNodeMap *map;
5878 doc = create_document(&IID_IXMLDOMDocument);
5881 str = SysAllocString( szComplete4 );
5882 hr = IXMLDOMDocument_loadXML( doc, str, &b );
5883 ok( hr == S_OK, "loadXML failed\n");
5884 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5885 SysFreeString( str );
5887 hr = IXMLDOMDocument_get_documentElement(doc, &element);
5888 ok( hr == S_OK, "ret %08x\n", hr);
5890 hr = IXMLDOMElement_get_childNodes(element, &root_list);
5891 ok( hr == S_OK, "ret %08x\n", hr);
5893 hr = IXMLDOMNodeList_get_item(root_list, 1, &pr_node);
5894 ok( hr == S_OK, "ret %08x\n", hr);
5895 IXMLDOMNodeList_Release(root_list);
5897 hr = IXMLDOMNode_get_attributes(pr_node, &map);
5898 ok( hr == S_OK, "ret %08x\n", hr);
5899 IXMLDOMNode_Release(pr_node);
5901 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
5902 ok( hr == S_OK, "ret %08x\n", hr);
5903 ok( len == 3, "length %d\n", len);
5905 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, NULL);
5906 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
5908 node = (void*)0xdeadbeef;
5909 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, NULL, NULL, &node);
5910 ok( hr == E_INVALIDARG, "ret %08x\n", hr);
5911 ok( node == (void*)0xdeadbeef, "got %p\n", node);
5913 /* out pointer is optional */
5914 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
5915 ok( hr == S_OK, "ret %08x\n", hr);
5917 /* already removed */
5918 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("id"), NULL, NULL);
5919 ok( hr == S_FALSE, "ret %08x\n", hr);
5921 hr = IXMLDOMNamedNodeMap_removeQualifiedItem(map, _bstr_("vr"), NULL, &node);
5922 ok( hr == S_OK, "ret %08x\n", hr);
5923 IXMLDOMNode_Release(node);
5925 IXMLDOMNamedNodeMap_Release( map );
5926 IXMLDOMElement_Release( element );
5927 IXMLDOMDocument_Release( doc );
5931 static void test_get_ownerDocument(void)
5933 IXMLDOMDocument *doc1, *doc2, *doc3;
5934 IXMLDOMDocument2 *doc, *doc_owner;
5941 doc = create_document(&IID_IXMLDOMDocument2);
5944 str = SysAllocString( szComplete4 );
5945 hr = IXMLDOMDocument_loadXML( doc, str, &b );
5946 ok( hr == S_OK, "loadXML failed\n");
5947 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5948 SysFreeString( str );
5950 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var);
5951 ok( hr == S_OK, "got 0x%08x\n", hr);
5952 ok( lstrcmpW(V_BSTR(&var), _bstr_("XSLPattern")) == 0, "expected XSLPattern\n");
5955 /* set to XPath and check that new instances use it */
5956 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath"));
5957 ok( hr == S_OK, "got 0x%08x\n", hr);
5959 hr = IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"), _variantbstr_("xmlns:wi=\'www.winehq.org\'"));
5960 ok( hr == S_OK, "got 0x%08x\n", hr);
5962 hr = IXMLDOMDocument2_get_firstChild(doc, &node);
5963 ok( hr == S_OK, "got 0x%08x\n", hr);
5965 hr = IXMLDOMNode_get_ownerDocument(node, &doc1);
5966 ok( hr == S_OK, "got 0x%08x\n", hr);
5968 hr = IXMLDOMDocument_QueryInterface(doc1, &IID_IXMLDOMDocument2, (void**)&doc_owner);
5969 ok( hr == S_OK, "got 0x%08x\n", hr);
5970 ok( doc_owner != doc, "got %p, doc %p\n", doc_owner, doc);
5971 hr = IXMLDOMDocument2_getProperty(doc_owner, _bstr_("SelectionNamespaces"), &var);
5972 ok( hr == S_OK, "got 0x%08x\n", hr);
5973 ok( lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "expected previously set value\n");
5976 hr = IXMLDOMDocument2_getProperty(doc_owner, _bstr_("SelectionLanguage"), &var);
5977 ok( hr == S_OK, "got 0x%08x\n", hr);
5978 ok( lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
5980 IXMLDOMDocument2_Release(doc_owner);
5982 hr = IXMLDOMNode_get_ownerDocument(node, &doc2);
5983 ok( hr == S_OK, "got 0x%08x\n", hr);
5984 IXMLDOMNode_Release(node);
5986 ok(doc1 != doc2, "got %p, expected %p. original %p\n", doc2, doc1, doc);
5989 str = SysAllocString( szComplete4 );
5990 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
5991 ok( hr == S_OK, "got 0x%08x\n", hr);
5992 ok( b == VARIANT_TRUE, "failed to load XML string\n");
5993 SysFreeString( str );
5995 /* properties retained even after reload */
5996 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var);
5997 ok( hr == S_OK, "got 0x%08x\n", hr);
5998 ok( lstrcmpW(V_BSTR(&var), _bstr_("xmlns:wi=\'www.winehq.org\'")) == 0, "expected previously set value\n");
6001 hr = IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionLanguage"), &var);
6002 ok( hr == S_OK, "got 0x%08x\n", hr);
6003 ok( lstrcmpW(V_BSTR(&var), _bstr_("XPath")) == 0, "expected XPath\n");
6006 hr = IXMLDOMDocument2_get_firstChild(doc, &node);
6007 ok( hr == S_OK, "got 0x%08x\n", hr);
6009 hr = IXMLDOMNode_get_ownerDocument(node, &doc3);
6010 ok( hr == S_OK, "got 0x%08x\n", hr);
6011 IXMLDOMNode_Release(node);
6013 hr = IXMLDOMDocument_QueryInterface(doc3, &IID_IXMLDOMDocument2, (void**)&doc_owner);
6014 ok( hr == S_OK, "got 0x%08x\n", hr);
6015 ok(doc3 != doc1 && doc3 != doc2 && doc_owner != doc, "got %p, (%p, %p, %p)\n", doc3, doc, doc1, doc2);
6017 IXMLDOMDocument_Release(doc1);
6018 IXMLDOMDocument_Release(doc2);
6019 IXMLDOMDocument_Release(doc3);
6020 IXMLDOMDocument2_Release(doc);
6024 static void test_setAttributeNode(void)
6026 IXMLDOMDocument *doc, *doc2;
6027 IXMLDOMElement *elem;
6028 IXMLDOMAttribute *attr, *attr2, *ret_attr;
6033 doc = create_document(&IID_IXMLDOMDocument);
6036 str = SysAllocString( szComplete4 );
6037 hr = IXMLDOMDocument2_loadXML( doc, str, &b );
6038 ok( hr == S_OK, "loadXML failed\n");
6039 ok( b == VARIANT_TRUE, "failed to load XML string\n");
6040 SysFreeString( str );
6042 hr = IXMLDOMDocument_get_documentElement(doc, &elem);
6043 ok( hr == S_OK, "got 0x%08x\n", hr);
6045 ret_attr = (void*)0xdeadbeef;
6046 hr = IXMLDOMElement_setAttributeNode(elem, NULL, &ret_attr);
6047 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
6048 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
6050 hr = IXMLDOMDocument_createAttribute(doc, _bstr_("attr"), &attr);
6051 ok( hr == S_OK, "got 0x%08x\n", hr);
6053 ret_attr = (void*)0xdeadbeef;
6054 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
6055 todo_wine ok( hr == S_OK, "got 0x%08x\n", hr);
6056 todo_wine ok( ret_attr == NULL, "got %p\n", ret_attr);
6059 hr = IXMLDOMElement_getAttributeNode(elem, _bstr_("attr"), &attr2);
6060 todo_wine ok( hr == S_OK, "got 0x%08x\n", hr);
6061 if (attr2) IXMLDOMAttribute_Release(attr2);
6063 /* try to add it another time */
6064 ret_attr = (void*)0xdeadbeef;
6065 hr = IXMLDOMElement_setAttributeNode(elem, attr, &ret_attr);
6066 todo_wine ok( hr == E_FAIL, "got 0x%08x\n", hr);
6067 ok( ret_attr == (void*)0xdeadbeef, "got %p\n", ret_attr);
6069 IXMLDOMElement_Release(elem);
6071 /* add attribute already attached to another document */
6072 doc2 = create_document(&IID_IXMLDOMDocument);
6074 str = SysAllocString( szComplete4 );
6075 hr = IXMLDOMDocument_loadXML( doc2, str, &b );
6076 ok( hr == S_OK, "loadXML failed\n");
6077 ok( b == VARIANT_TRUE, "failed to load XML string\n");
6078 SysFreeString( str );
6080 hr = IXMLDOMDocument_get_documentElement(doc2, &elem);
6081 ok( hr == S_OK, "got 0x%08x\n", hr);
6082 hr = IXMLDOMElement_setAttributeNode(elem, attr, NULL);
6083 todo_wine ok( hr == E_FAIL, "got 0x%08x\n", hr);
6084 IXMLDOMElement_Release(elem);
6086 IXMLDOMDocument_Release(doc2);
6088 IXMLDOMAttribute_Release(attr);
6089 IXMLDOMDocument_Release(doc);
6093 static void test_put_dataType(void)
6095 IXMLDOMCDATASection *cdata;
6096 IXMLDOMDocument *doc;
6101 doc = create_document(&IID_IXMLDOMDocument);
6104 str = SysAllocString( szComplete4 );
6105 hr = IXMLDOMDocument_loadXML( doc, str, &b );
6106 ok( hr == S_OK, "loadXML failed\n");
6107 ok( b == VARIANT_TRUE, "failed to load XML string\n");
6108 SysFreeString( str );
6110 hr = IXMLDOMDocument_createCDATASection(doc, _bstr_("test"), &cdata);
6111 ok( hr == S_OK, "got 0x%08x\n", hr);
6112 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("number"));
6113 ok( hr == E_FAIL, "got 0x%08x\n", hr);
6114 hr = IXMLDOMCDATASection_put_dataType(cdata, _bstr_("string"));
6115 ok( hr == E_FAIL, "got 0x%08x\n", hr);
6116 IXMLDOMCDATASection_Release(cdata);
6118 IXMLDOMDocument_Release(doc);
6122 static void test_createNode(void)
6124 IXMLDOMDocument *doc;
6125 IXMLDOMElement *elem;
6131 doc = create_document(&IID_IXMLDOMDocument);
6134 /* NODE_ELEMENT nodes */
6135 /* 1. specified namespace */
6137 V_I4(&v) = NODE_ELEMENT;
6139 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("ns1:test"), _bstr_("http://winehq.org"), &node);
6140 ok( hr == S_OK, "got 0x%08x\n", hr);
6142 hr = IXMLDOMNode_get_prefix(node, &prefix);
6143 ok( hr == S_OK, "got 0x%08x\n", hr);
6144 ok(lstrcmpW(prefix, _bstr_("ns1")) == 0, "wrong prefix\n");
6145 SysFreeString(prefix);
6146 IXMLDOMNode_Release(node);
6148 /* 2. default namespace */
6149 hr = IXMLDOMDocument_createNode(doc, v, _bstr_("test"), _bstr_("http://winehq.org/default"), &node);
6150 ok( hr == S_OK, "got 0x%08x\n", hr);
6151 prefix = (void*)0xdeadbeef;
6152 hr = IXMLDOMNode_get_prefix(node, &prefix);
6153 ok( hr == S_FALSE, "got 0x%08x\n", hr);
6154 ok(prefix == 0, "expected empty prefix, got %p\n", prefix);
6156 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&elem);
6157 ok( hr == S_OK, "got 0x%08x\n", hr);
6159 V_VT(&var) = VT_BSTR;
6160 hr = IXMLDOMElement_getAttribute(elem, _bstr_("xmlns"), &var);
6161 ok( hr == S_FALSE, "got 0x%08x\n", hr);
6162 ok( V_VT(&var) == VT_NULL, "got %d\n", V_VT(&var));
6165 hr = IXMLDOMElement_get_namespaceURI(elem, &str);
6166 ok( hr == S_OK, "got 0x%08x\n", hr);
6167 ok( lstrcmpW(str, _bstr_("http://winehq.org/default")) == 0, "expected default namespace\n");
6170 IXMLDOMElement_Release(elem);
6171 IXMLDOMNode_Release(node);
6173 IXMLDOMDocument_Release(doc);
6177 static void test_get_prefix(void)
6179 IXMLDOMDocument *doc;
6180 IXMLDOMElement *element;
6184 doc = create_document(&IID_IXMLDOMDocument);
6188 hr = IXMLDOMDocument_createElement(doc, _bstr_("elem"), &element);
6189 ok( hr == S_OK, "got 0x%08x\n", hr);
6191 hr = IXMLDOMElement_get_prefix(element, NULL);
6192 ok( hr == E_INVALIDARG, "got 0x%08x\n", hr);
6194 str = (void*)0xdeadbeef;
6195 hr = IXMLDOMElement_get_prefix(element, &str);
6196 ok( hr == S_FALSE, "got 0x%08x\n", hr);
6197 ok( str == 0, "got %p\n", str);
6199 IXMLDOMElement_Release(element);
6202 hr = IXMLDOMDocument_createElement(doc, _bstr_("a:elem"), &element);
6203 ok( hr == S_OK, "got 0x%08x\n", hr);
6205 str = (void*)0xdeadbeef;
6206 hr = IXMLDOMElement_get_prefix(element, &str);
6207 ok( hr == S_OK, "got 0x%08x\n", hr);
6208 ok( lstrcmpW(str, _bstr_("a")) == 0, "expected prefix \"a\"\n");
6211 str = (void*)0xdeadbeef;
6212 hr = IXMLDOMElement_get_namespaceURI(element, &str);
6213 ok( hr == S_FALSE, "got 0x%08x\n", hr);
6214 ok( str == 0, "got %p\n", str);
6216 IXMLDOMElement_Release(element);
6218 IXMLDOMDocument_Release(doc);
6222 static void test_selectSingleNode(void)
6224 IXMLDOMDocument *doc;
6225 IXMLDOMNodeList *list;
6232 doc = create_document(&IID_IXMLDOMDocument);
6235 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
6236 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6238 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
6239 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6241 str = SysAllocString( szComplete4 );
6242 hr = IXMLDOMDocument_loadXML( doc, str, &b );
6243 ok( hr == S_OK, "loadXML failed\n");
6244 ok( b == VARIANT_TRUE, "failed to load XML string\n");
6245 SysFreeString( str );
6247 hr = IXMLDOMDocument_selectSingleNode(doc, NULL, NULL);
6248 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6250 hr = IXMLDOMDocument_selectNodes(doc, NULL, NULL);
6251 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6253 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), NULL);
6254 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6256 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), NULL);
6257 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6259 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("lc"), &node);
6260 ok(hr == S_OK, "got 0x%08x\n", hr);
6261 IXMLDOMNode_Release(node);
6263 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("lc"), &list);
6264 ok(hr == S_OK, "got 0x%08x\n", hr);
6265 IXMLDOMNodeList_Release(list);
6267 list = (void*)0xdeadbeef;
6268 hr = IXMLDOMDocument_selectNodes(doc, NULL, &list);
6269 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
6270 ok(list == (void*)0xdeadbeef, "got %p\n", list);
6272 node = (void*)0xdeadbeef;
6273 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("nonexistent"), &node);
6274 ok(hr == S_FALSE, "got 0x%08x\n", hr);
6275 ok(node == 0, "got %p\n", node);
6277 list = (void*)0xdeadbeef;
6278 hr = IXMLDOMDocument_selectNodes(doc, _bstr_("nonexistent"), &list);
6279 ok(hr == S_OK, "got 0x%08x\n", hr);
6281 hr = IXMLDOMNodeList_get_length(list, &len);
6282 ok(hr == S_OK, "got 0x%08x\n", hr);
6283 ok(len == 0, "got %d\n", len);
6284 IXMLDOMNodeList_Release(list);
6286 IXMLDOMDocument_Release(doc);
6292 IXMLDOMDocument *doc;
6295 hr = CoInitialize( NULL );
6296 ok( hr == S_OK, "failed to init com\n");
6302 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&doc );
6305 win_skip("IXMLDOMDocument is not available (0x%08x)\n", hr);
6309 IXMLDOMDocument_Release(doc);
6312 test_persiststreaminit();
6316 test_getElementsByTagName();
6318 test_get_childNodes();
6319 test_get_firstChild();
6320 test_get_lastChild();
6322 test_replaceChild();
6323 test_removeNamedItem();
6324 test_IXMLDOMDocument2();
6330 test_nodeTypeTests();
6331 test_DocumentSaveToDocument();
6332 test_DocumentSaveToFile();
6333 test_testTransforms();
6335 test_FormattingXML();
6336 test_nodeTypedValue();
6337 test_TransformWithLoadingLocalFile();
6338 test_put_nodeValue();
6339 test_document_IObjectSafety();
6341 test_getQualifiedItem();
6342 test_removeQualifiedItem();
6343 test_get_ownerDocument();
6344 test_setAttributeNode();
6345 test_put_dataType();
6348 test_default_properties();
6349 test_selectSingleNode();