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
29 #include "msxml2did.h"
34 #include "wine/test.h"
36 static const WCHAR szEmpty[] = { 0 };
37 static const WCHAR szIncomplete[] = {
38 '<','?','x','m','l',' ',
39 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
41 static const WCHAR szComplete1[] = {
42 '<','?','x','m','l',' ',
43 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
44 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
46 static const WCHAR szComplete2[] = {
47 '<','?','x','m','l',' ',
48 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
49 '<','o','>','<','/','o','>','\n',0
51 static const WCHAR szComplete3[] = {
52 '<','?','x','m','l',' ',
53 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
54 '<','a','>','<','/','a','>','\n',0
56 static const WCHAR szComplete4[] = {
57 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
58 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>','\n',
59 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ','s','z','=','\'','1','2','3','4','\'','>',
60 'f','n','1','.','t','x','t','\n',
61 '<','/','b','s','>','\n',
62 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ','v','r','=','\'','1','.','2','.','3','\'',' ',
63 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>','\n',
64 'f','n','2','.','t','x','t','\n',
65 '<','/','p','r','>','\n',
66 '<','e','m','p','t','y','>','<','/','e','m','p','t','y','>','\n',
70 '<','/','b','a','>','\n',
71 '<','/','f','o','>','\n',
72 '<','/','l','c','>','\n',0
74 static const WCHAR szComplete5[] = {
75 '<','S',':','s','e','a','r','c','h',' ','x','m','l','n','s',':','D','=','"','D','A','V',':','"',' ',
76 'x','m','l','n','s',':','C','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y','"',
77 ' ','x','m','l','n','s',':','S','=','"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','o','f','f','i','c','e',':','c','l','i','p','g','a','l','l','e','r','y',':','s','e','a','r','c','h','"','>',
78 '<','S',':','s','c','o','p','e','>',
79 '<','S',':','d','e','e','p','>','/','<','/','S',':','d','e','e','p','>',
80 '<','/','S',':','s','c','o','p','e','>',
81 '<','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
82 '<','C',':','t','e','x','t','o','r','p','r','o','p','e','r','t','y','/','>',
83 'c','o','m','p','u','t','e','r',
84 '<','/','S',':','c','o','n','t','e','n','t','f','r','e','e','t','e','x','t','>',
85 '<','/','S',':','s','e','a','r','c','h','>',0
88 static const CHAR szExampleXML[] =
89 "<?xml version='1.0' encoding='utf-8'?>\n"
90 "<root xmlns:foo='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
95 " <description xmlns:foo='http://www.winehq.org' xmlns:bar='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
96 " <html xmlns='http://www.w3.org/1999/xhtml'>\n"
97 " This is <strong>a</strong> <i>description</i>. <bar:x/>\n"
105 " <c type=\"old\">C2 field</c>\n"
108 " <elem xmlns='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'>\n"
117 " <foo:c>C4 field</foo:c>\n"
121 static const CHAR szTransformXML[] =
122 "<?xml version=\"1.0\"?>\n"
127 static const CHAR szTransformSSXML[] =
128 "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
129 " <xsl:output method=\"html\"/>\n"
130 " <xsl:template match=\"/\">\n"
131 " <xsl:apply-templates select=\"greeting\"/>\n"
133 " <xsl:template match=\"greeting\">\n"
137 " <xsl:value-of select=\".\"/>\n"
144 static const CHAR szTransformOutput[] =
147 "</h1></body></html>";
149 static const CHAR szTypeValueXML[] =
150 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
151 "<root xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">\n"
152 " <string>Wine</string>\n"
153 " <string2 dt:dt=\"string\">String</string2>\n"
154 " <number dt:dt=\"number\">12.44</number>\n"
155 " <number2 dt:dt=\"NUMbEr\">-3.71e3</number2>\n"
156 " <int dt:dt=\"int\">-13</int>\n"
157 " <fixed dt:dt=\"fixed.14.4\">7322.9371</fixed>\n"
158 " <bool dt:dt=\"boolean\">1</bool>\n"
159 " <datetime dt:dt=\"datetime\">2009-11-18T03:21:33.12</datetime>\n"
160 " <datetimetz dt:dt=\"datetime.tz\">2003-07-11T11:13:57+03:00</datetimetz>\n"
161 " <date dt:dt=\"date\">3721-11-01</date>\n"
162 " <time dt:dt=\"time\">13:57:12.31321</time>\n"
163 " <timetz dt:dt=\"time.tz\">23:21:01.13+03:21</timetz>\n"
164 " <i1 dt:dt=\"i1\">-13</i1>\n"
167 static const CHAR szBasicTransformSSXMLPart1[] =
168 "<?xml version=\"1.0\"?>"
169 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
170 "<xsl:output method=\"html\"/>\n"
171 "<xsl:template match=\"/\">"
172 "<HTML><BODY><TABLE>"
173 " <xsl:apply-templates select='document(\"";
175 static const CHAR szBasicTransformSSXMLPart2[] =
177 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
178 " </xsl:apply-templates>"
179 "</TABLE></BODY></HTML>"
181 "<xsl:template match=\"bottle\">"
182 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
184 "<xsl:template match=\"name\">"
185 " <TD><xsl:apply-templates /></TD>"
187 "<xsl:template match=\"cost\">"
188 " <TD><xsl:apply-templates /></TD>"
192 static const CHAR szBasicTransformXML[] =
193 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
195 static const CHAR szBasicTransformOutput[] =
196 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
198 static const WCHAR szNonExistentFile[] = {
199 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
201 static const WCHAR szDocument[] = {
202 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
205 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
206 static WCHAR szdl[] = { 'd','l',0 };
207 static const WCHAR szvr[] = { 'v','r',0 };
208 static const WCHAR szlc[] = { 'l','c',0 };
209 static WCHAR szbs[] = { 'b','s',0 };
210 static const WCHAR szstr1[] = { 's','t','r','1',0 };
211 static const WCHAR szstr2[] = { 's','t','r','2',0 };
212 static const WCHAR szstar[] = { '*',0 };
213 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
215 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
216 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
217 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
219 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
220 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
221 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
222 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
223 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
224 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
225 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
227 static WCHAR szAttribute[] = {'A','t','t','r',0 };
228 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
230 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
231 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
232 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
233 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
235 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
236 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
238 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
239 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
240 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
242 #define expect_bstr_eq_and_free(bstr, expect) { \
243 BSTR bstrExp = alloc_str_from_narrow(expect); \
244 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
245 SysFreeString(bstr); \
246 SysFreeString(bstrExp); \
249 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
251 #define ole_check(expr) { \
253 ok(r == S_OK, #expr " returned %x\n", r); \
256 #define ole_expect(expr, expect) { \
258 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
261 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
263 static BSTR alloc_str_from_narrow(const char *str)
265 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
266 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
267 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
271 BSTR alloced_bstrs[256];
272 int alloced_bstrs_count = 0;
274 static BSTR _bstr_(const char *str)
276 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
277 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
278 return alloced_bstrs[alloced_bstrs_count++];
281 static void free_bstrs(void)
284 for (i = 0; i < alloced_bstrs_count; i++)
285 SysFreeString(alloced_bstrs[i]);
286 alloced_bstrs_count = 0;
289 static VARIANT _variantbstr_(const char *str)
293 V_BSTR(&v) = _bstr_(str);
297 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
301 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
302 while (*sRight == '\r' || *sRight == '\n') sRight++;
303 if (*sLeft != *sRight) return FALSE;
304 if (!*sLeft) return TRUE;
310 static BOOL compareIgnoreReturnsWhitespace(BSTR sLeft, BSTR sRight)
312 /* MSXML3 inserts whitespace where as libxml doesn't. */
315 while (*sLeft == '\r' || *sLeft == '\n' || *sLeft == ' ') sLeft++;
316 while (*sRight == '\r' || *sRight == '\n' || *sRight == ' ') sRight++;
317 if (*sLeft != *sRight) return FALSE;
318 if (!*sLeft) return TRUE;
324 static void get_str_for_type(DOMNodeType type, char *buf)
338 wsprintfA(buf, "[%d]", type);
342 #define test_disp(u) _test_disp(__LINE__,u)
343 static void _test_disp(unsigned line, IUnknown *unk)
345 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
353 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
354 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
359 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
360 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
361 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
363 sName = SysAllocString( szstar );
364 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
365 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
366 SysFreeString( sName );
368 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
369 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
371 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
372 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
373 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
375 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
376 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
378 SysFreeString(sName);
380 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
381 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
383 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
384 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
385 if(hres == S_OK && pUnk)
386 IUnknown_Release(pUnk);
388 IDispatchEx_Release(dispex);
391 static int get_node_position(IXMLDOMNode *node)
396 IXMLDOMNode_AddRef(node);
399 IXMLDOMNode *new_node;
402 r = IXMLDOMNode_get_previousSibling(node, &new_node);
403 ok(SUCCEEDED(r), "get_previousSibling failed\n");
404 IXMLDOMNode_Release(node);
410 static void node_to_string(IXMLDOMNode *node, char *buf)
417 lstrcpyA(buf, "(null)");
421 IXMLDOMNode_AddRef(node);
424 IXMLDOMNode *new_node;
426 ole_check(IXMLDOMNode_get_nodeType(node, &type));
427 get_str_for_type(type, buf);
430 if (type == NODE_ATTRIBUTE)
433 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
435 wsprintfA(buf, "%ws", bstr);
440 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
444 int pos = get_node_position(node);
445 DOMNodeType parent_type = NODE_INVALID;
446 r = IXMLDOMNode_get_parentNode(node, &new_node);
448 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
449 * results we "fix" it */
451 ole_check(IXMLDOMNode_get_nodeType(new_node, &parent_type));
452 if ((parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
454 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
457 wsprintf(buf, "%d", pos);
461 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
462 IXMLDOMNode_Release(node);
471 static char *list_to_string(IXMLDOMNodeList *list)
473 static char buf[4096];
480 lstrcpyA(buf, "(null)");
483 ole_check(IXMLDOMNodeList_get_length(list, &len));
484 for (i = 0; i < len; i++)
489 ole_check(IXMLDOMNodeList_nextNode(list, &node));
490 node_to_string(node, pos);
492 IXMLDOMNode_Release(node);
498 #define expect_node(node, expstr) { char str[4096]; node_to_string(node, str); ok(strcmp(str, expstr)==0, "Invalid node: %s, exptected %s\n", str, expstr); }
499 #define expect_list_and_release(list, expstr) { char *str = list_to_string(list); ok(strcmp(str, expstr)==0, "Invalid node list: %s, exptected %s\n", str, expstr); if (list) IXMLDOMNodeList_Release(list); }
501 static void test_domdoc( void )
504 IXMLDOMDocument *doc = NULL;
505 IXMLDOMParseError *error;
506 IXMLDOMElement *element = NULL;
508 IXMLDOMText *nodetext = NULL;
509 IXMLDOMComment *node_comment = NULL;
510 IXMLDOMAttribute *node_attr = NULL;
511 IXMLDOMNode *nodeChild = NULL;
512 IXMLDOMProcessingInstruction *nodePI = NULL;
513 ISupportErrorInfo *support_error = NULL;
520 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
521 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
525 test_disp((IUnknown*)doc);
527 /* try some stupid things */
528 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
529 ok( r == S_FALSE, "loadXML failed\n");
532 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
533 ok( r == S_FALSE, "loadXML failed\n");
534 ok( b == VARIANT_FALSE, "failed to load XML string\n");
536 /* try to load a document from a nonexistent file */
538 str = SysAllocString( szNonExistentFile );
540 V_VT(&var) = VT_BSTR;
543 r = IXMLDOMDocument_load( doc, var, &b);
544 ok( r == S_FALSE, "load (from file) failed\n");
545 ok( b == VARIANT_FALSE, "failed to load XML file\n");
546 SysFreeString( str );
548 /* try load an empty document */
550 str = SysAllocString( szEmpty );
551 r = IXMLDOMDocument_loadXML( doc, str, &b );
552 ok( r == S_FALSE, "loadXML failed\n");
553 ok( b == VARIANT_FALSE, "failed to load XML string\n");
554 SysFreeString( str );
556 r = IXMLDOMDocument_get_async( doc, &b );
557 ok( r == S_OK, "get_async failed (%08x)\n", r);
558 ok( b == VARIANT_TRUE, "Wrong default value\n");
560 /* check that there's no document element */
562 r = IXMLDOMDocument_get_documentElement( doc, &element );
563 ok( r == S_FALSE, "should be no document element\n");
565 /* try finding a node */
567 str = SysAllocString( szstr1 );
568 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
569 ok( r == S_FALSE, "ret %08x\n", r );
570 SysFreeString( str );
573 str = SysAllocString( szIncomplete );
574 r = IXMLDOMDocument_loadXML( doc, str, &b );
575 ok( r == S_FALSE, "loadXML failed\n");
576 ok( b == VARIANT_FALSE, "failed to load XML string\n");
577 SysFreeString( str );
579 /* check that there's no document element */
580 element = (IXMLDOMElement*)1;
581 r = IXMLDOMDocument_get_documentElement( doc, &element );
582 ok( r == S_FALSE, "should be no document element\n");
583 ok( element == NULL, "Element should be NULL\n");
585 /* try to load something valid */
587 str = SysAllocString( szComplete1 );
588 r = IXMLDOMDocument_loadXML( doc, str, &b );
589 ok( r == S_OK, "loadXML failed\n");
590 ok( b == VARIANT_TRUE, "failed to load XML string\n");
591 SysFreeString( str );
593 /* check if nodename is correct */
594 r = IXMLDOMDocument_get_nodeName( doc, NULL );
595 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
597 /* content doesn't matter here */
599 r = IXMLDOMDocument_get_nodeName( doc, &str );
600 ok ( r == S_OK, "get_nodeName wrong code\n");
601 ok ( str != NULL, "str is null\n");
602 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
603 SysFreeString( str );
606 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
607 ok( r == E_FAIL, "ret %08x\n", r );
609 /* check that there's a document element */
611 r = IXMLDOMDocument_get_documentElement( doc, &element );
612 ok( r == S_OK, "should be a document element\n");
615 IObjectIdentity *ident;
618 test_disp((IUnknown*)element);
620 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (LPVOID*)&ident );
621 ok( r == E_NOINTERFACE, "ret %08x\n", r);
623 /* check if the tag is correct */
624 r = IXMLDOMElement_get_tagName( element, &tag );
625 ok( r == S_OK, "couldn't get tag name\n");
626 ok( tag != NULL, "tag was null\n");
627 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
628 SysFreeString( tag );
630 /* figure out what happens if we try to reload the document */
631 str = SysAllocString( szComplete2 );
632 r = IXMLDOMDocument_loadXML( doc, str, &b );
633 ok( r == S_OK, "loadXML failed\n");
634 ok( b == VARIANT_TRUE, "failed to load XML string\n");
635 SysFreeString( str );
637 /* check if the tag is still correct */
639 r = IXMLDOMElement_get_tagName( element, &tag );
640 ok( r == S_OK, "couldn't get tag name\n");
641 ok( tag != NULL, "tag was null\n");
642 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
643 SysFreeString( tag );
645 IXMLDOMElement_Release( element );
649 /* as soon as we call loadXML again, the document element will disappear */
651 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
652 ok( r == S_FALSE, "loadXML failed\n");
653 ok( b == 2, "variant modified\n");
654 r = IXMLDOMDocument_get_documentElement( doc, &element );
655 ok( r == S_FALSE, "should be no document element\n");
657 /* try to load something else simple and valid */
659 str = SysAllocString( szComplete3 );
660 r = IXMLDOMDocument_loadXML( doc, str, &b );
661 ok( r == S_OK, "loadXML failed\n");
662 ok( b == VARIANT_TRUE, "failed to load XML string\n");
663 SysFreeString( str );
665 /* try something a little more complicated */
667 str = SysAllocString( szComplete4 );
668 r = IXMLDOMDocument_loadXML( doc, str, &b );
669 ok( r == S_OK, "loadXML failed\n");
670 ok( b == VARIANT_TRUE, "failed to load XML string\n");
671 SysFreeString( str );
673 r = IXMLDOMDocument_get_parseError( doc, &error );
674 ok( r == S_OK, "returns %08x\n", r );
676 r = IXMLDOMParseError_get_errorCode( error, &code );
677 ok( r == S_FALSE, "returns %08x\n", r );
678 ok( code == 0, "code %d\n", code );
679 IXMLDOMParseError_Release( error );
681 /* test createTextNode */
682 str = SysAllocString( szOpen );
683 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
684 ok( r == E_INVALIDARG, "returns %08x\n", r );
685 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
686 ok( r == S_OK, "returns %08x\n", r );
687 SysFreeString( str );
690 IXMLDOMNamedNodeMap *pAttribs;
692 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (LPVOID*)&element);
693 ok(r == E_NOINTERFACE, "ret %08x\n", r );
695 /* Text Last Child Checks */
696 r = IXMLDOMText_get_lastChild(nodetext, NULL);
697 ok(r == E_INVALIDARG, "ret %08x\n", r );
699 nodeChild = (IXMLDOMNode*)0x1;
700 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
701 ok(r == S_FALSE, "ret %08x\n", r );
702 ok(nodeChild == NULL, "nodeChild not NULL\n");
704 /* test get_attributes */
705 r = IXMLDOMText_get_attributes( nodetext, NULL );
706 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
708 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
709 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
710 ok(r == S_FALSE, "ret %08x\n", r );
711 ok( pAttribs == NULL, "pAttribs not NULL\n");
713 /* test get_dataType */
714 r = IXMLDOMText_get_dataType(nodetext, &var);
715 ok(r == S_FALSE, "ret %08x\n", r );
716 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
719 /* test length property */
720 r = IXMLDOMText_get_length(nodetext, NULL);
721 ok(r == E_INVALIDARG, "ret %08x\n", r );
723 r = IXMLDOMText_get_length(nodetext, &nLength);
724 ok(r == S_OK, "ret %08x\n", r );
725 ok(nLength == 4, "expected 4 got %d\n", nLength);
727 /* test nodeTypeString */
728 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
729 ok(r == S_OK, "ret %08x\n", r );
730 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
734 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
735 ok(r == S_OK, "ret %08x\n", r );
738 r = IXMLDOMText_get_data(nodetext, &str);
739 ok(r == S_OK, "ret %08x\n", r );
740 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
743 /* Confirm XML text is good */
744 r = IXMLDOMText_get_xml(nodetext, &str);
745 ok(r == S_OK, "ret %08x\n", r );
746 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
749 /* Confirm we get the put_data Text back */
750 r = IXMLDOMText_get_text(nodetext, &str);
751 ok(r == S_OK, "ret %08x\n", r );
752 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
755 /* test substringData */
756 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
757 ok(r == E_INVALIDARG, "ret %08x\n", r );
759 /* test substringData - Invalid offset */
760 str = (BSTR)&szElement;
761 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
762 ok(r == E_INVALIDARG, "ret %08x\n", r );
763 ok( str == NULL, "incorrect string\n");
765 /* test substringData - Invalid offset */
766 str = (BSTR)&szElement;
767 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
768 ok(r == S_FALSE, "ret %08x\n", r );
769 ok( str == NULL, "incorrect string\n");
771 /* test substringData - Invalid size */
772 str = (BSTR)&szElement;
773 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
774 ok(r == E_INVALIDARG, "ret %08x\n", r );
775 ok( str == NULL, "incorrect string\n");
777 /* test substringData - Invalid size */
778 str = (BSTR)&szElement;
779 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
780 ok(r == S_FALSE, "ret %08x\n", r );
781 ok( str == NULL, "incorrect string\n");
783 /* test substringData - Start of string */
784 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
785 ok(r == S_OK, "ret %08x\n", r );
786 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
789 /* test substringData - Middle of string */
790 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
791 ok(r == S_OK, "ret %08x\n", r );
792 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
795 /* test substringData - End of string */
796 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
797 ok(r == S_OK, "ret %08x\n", r );
798 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
801 /* test appendData */
802 r = IXMLDOMText_appendData(nodetext, NULL);
803 ok(r == S_OK, "ret %08x\n", r );
805 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
806 ok(r == S_OK, "ret %08x\n", r );
808 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
809 ok(r == S_OK, "ret %08x\n", r );
811 r = IXMLDOMText_get_text(nodetext, &str);
812 ok(r == S_OK, "ret %08x\n", r );
813 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
816 /* test insertData */
817 str = SysAllocStringLen(NULL, 0);
818 r = IXMLDOMText_insertData(nodetext, -1, str);
819 ok(r == S_OK, "ret %08x\n", r );
821 r = IXMLDOMText_insertData(nodetext, -1, NULL);
822 ok(r == S_OK, "ret %08x\n", r );
824 r = IXMLDOMText_insertData(nodetext, 1000, str);
825 ok(r == S_OK, "ret %08x\n", r );
827 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
828 ok(r == S_OK, "ret %08x\n", r );
830 r = IXMLDOMText_insertData(nodetext, 0, NULL);
831 ok(r == S_OK, "ret %08x\n", r );
833 r = IXMLDOMText_insertData(nodetext, 0, str);
834 ok(r == S_OK, "ret %08x\n", r );
837 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
838 ok(r == E_INVALIDARG, "ret %08x\n", r );
840 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
841 ok(r == E_INVALIDARG, "ret %08x\n", r );
843 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
844 ok(r == S_OK, "ret %08x\n", r );
846 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
847 ok(r == S_OK, "ret %08x\n", r );
849 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
850 ok(r == S_OK, "ret %08x\n", r );
852 r = IXMLDOMText_get_text(nodetext, &str);
853 ok(r == S_OK, "ret %08x\n", r );
854 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
858 V_VT(&var) = VT_BSTR;
859 V_BSTR(&var) = SysAllocString(szstr1);
860 r = IXMLDOMText_put_nodeValue(nodetext, var);
861 ok(r == S_OK, "ret %08x\n", r );
864 r = IXMLDOMText_get_text(nodetext, &str);
865 ok(r == S_OK, "ret %08x\n", r );
866 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string\n");
872 r = IXMLDOMText_put_nodeValue(nodetext, var);
873 ok(r == S_OK, "ret %08x\n", r );
876 r = IXMLDOMText_get_text(nodetext, &str);
877 ok(r == S_OK, "ret %08x\n", r );
878 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string\n");
881 IXMLDOMText_Release( nodetext );
884 /* test Create Comment */
885 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
886 ok( r == E_INVALIDARG, "returns %08x\n", r );
887 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
888 ok( r == S_OK, "returns %08x\n", r );
891 /* Last Child Checks */
892 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
893 ok(r == E_INVALIDARG, "ret %08x\n", r );
895 nodeChild = (IXMLDOMNode*)0x1;
896 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
897 ok(r == S_FALSE, "ret %08x\n", r );
898 ok(nodeChild == NULL, "pLastChild not NULL\n");
900 IXMLDOMComment_Release( node_comment );
903 /* test Create Attribute */
904 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
905 ok( r == E_INVALIDARG, "returns %08x\n", r );
906 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
907 ok( r == S_OK, "returns %08x\n", r );
908 IXMLDOMText_Release( node_attr);
910 /* test Processing Instruction */
911 str = SysAllocStringLen(NULL, 0);
912 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
913 ok( r == E_INVALIDARG, "returns %08x\n", r );
914 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
915 ok( r == E_FAIL, "returns %08x\n", r );
916 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
917 ok( r == E_FAIL, "returns %08x\n", r );
920 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
921 ok( r == S_OK, "returns %08x\n", r );
924 /* Last Child Checks */
925 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
926 ok(r == E_INVALIDARG, "ret %08x\n", r );
928 nodeChild = (IXMLDOMNode*)0x1;
929 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
930 ok(r == S_FALSE, "ret %08x\n", r );
931 ok(nodeChild == NULL, "nodeChild not NULL\n");
933 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
934 ok(r == S_FALSE, "ret %08x\n", r );
935 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
939 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
940 ok(r == S_OK, "ret %08x\n", r );
941 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
945 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
946 ok(r == S_OK, "ret %08x\n", r );
947 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
950 /* test nodeTypeString */
951 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
952 ok(r == S_OK, "ret %08x\n", r );
953 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
956 /* test get_nodeValue */
957 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
958 ok(r == S_OK, "ret %08x\n", r );
959 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
963 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
964 ok(r == S_OK, "ret %08x\n", r );
965 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
969 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
970 ok(r == E_FAIL, "ret %08x\n", r );
973 V_VT(&var) = VT_BSTR;
974 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
975 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
976 ok(r == E_FAIL, "ret %08x\n", r );
979 /* test get nodeName */
980 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
981 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
982 ok(r == S_OK, "ret %08x\n", r );
985 IXMLDOMProcessingInstruction_Release(nodePI);
988 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
989 ok( r == S_OK, "ret %08x\n", r );
992 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
993 todo_wine ok( r == S_OK, "ret %08x\n", r );
994 ISupportErrorInfo_Release( support_error );
997 r = IXMLDOMDocument_Release( doc );
998 ok( r == 0, "document ref count incorrect\n");
1003 static void test_domnode( void )
1006 IXMLDOMDocument *doc = NULL, *owner = NULL;
1007 IXMLDOMElement *element = NULL;
1008 IXMLDOMNamedNodeMap *map = NULL;
1009 IXMLDOMNode *node = NULL, *next = NULL;
1010 IXMLDOMNodeList *list = NULL;
1011 IXMLDOMAttribute *attr = NULL;
1012 DOMNodeType type = NODE_INVALID;
1018 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1019 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1024 str = SysAllocString( szComplete4 );
1025 r = IXMLDOMDocument_loadXML( doc, str, &b );
1026 ok( r == S_OK, "loadXML failed\n");
1027 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1028 SysFreeString( str );
1033 r = IXMLDOMNode_hasChildNodes( doc, &b );
1034 ok( r == S_OK, "hasChildNoes bad return\n");
1035 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1037 r = IXMLDOMDocument_get_documentElement( doc, &element );
1038 ok( r == S_OK, "should be a document element\n");
1039 ok( element != NULL, "should be an element\n");
1042 ok( FALSE, "no document\n");
1045 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1047 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1048 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1050 r = IXMLDOMNode_get_nodeValue( doc, &var );
1051 ok( r == S_FALSE, "nextNode returned wrong code\n");
1052 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1053 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1058 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1059 ok( r == S_OK, "get_ownerDocument return code\n");
1060 ok( owner != doc, "get_ownerDocument return\n");
1062 type = NODE_INVALID;
1063 r = IXMLDOMNode_get_nodeType( element, &type);
1064 ok( r == S_OK, "getNamedItem returned wrong code\n");
1065 ok( type == NODE_ELEMENT, "node not an element\n");
1068 r = IXMLDOMNode_get_baseName( element, &str );
1069 ok( r == S_OK, "get_baseName returned wrong code\n");
1070 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1073 /* check if nodename is correct */
1074 r = IXMLDOMElement_get_nodeName( element, NULL );
1075 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1077 /* content doesn't matter here */
1079 r = IXMLDOMElement_get_nodeName( element, &str );
1080 ok ( r == S_OK, "get_nodeName wrong code\n");
1081 ok ( str != NULL, "str is null\n");
1082 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1083 SysFreeString( str );
1085 str = SysAllocString( szNonExistentFile );
1087 V_I4(&var) = 0x1234;
1088 r = IXMLDOMElement_getAttribute( element, str, &var );
1089 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1090 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1093 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1094 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1096 attr = (IXMLDOMAttribute*)0xdeadbeef;
1097 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1098 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1099 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1100 SysFreeString( str );
1102 attr = (IXMLDOMAttribute*)0xdeadbeef;
1103 str = _bstr_("nonExisitingAttribute");
1104 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1105 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1106 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1107 SysFreeString( str );
1109 str = SysAllocString( szdl );
1111 V_I4(&var) = 0x1234;
1112 r = IXMLDOMElement_getAttribute( element, str, &var );
1113 ok( r == S_OK, "getAttribute ret %08x\n", r );
1114 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1115 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1116 VariantClear( &var );
1118 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1119 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1121 r = IXMLDOMElement_getAttribute( element, str, NULL );
1122 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1125 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1126 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1127 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1129 IXMLDOMAttribute_Release(attr);
1131 SysFreeString( str );
1133 r = IXMLDOMElement_get_attributes( element, &map );
1134 ok( r == S_OK, "get_attributes returned wrong code\n");
1135 ok( map != NULL, "should be attributes\n");
1138 r = IXMLDOMNode_hasChildNodes( element, &b );
1139 ok( r == S_OK, "hasChildNoes bad return\n");
1140 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1143 ok( FALSE, "no element\n");
1147 ISupportErrorInfo *support_error;
1148 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1149 ok( r == S_OK, "ret %08x\n", r );
1151 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1154 ok( r == S_OK, "ret %08x\n", r );
1156 ISupportErrorInfo_Release( support_error );
1158 str = SysAllocString( szdl );
1159 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1160 ok( r == S_OK, "getNamedItem returned wrong code\n");
1161 ok( node != NULL, "should be attributes\n");
1162 IXMLDOMNode_Release(node);
1163 SysFreeString( str );
1165 str = SysAllocString( szdl );
1166 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1167 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1168 SysFreeString( str );
1170 /* something that isn't in szComplete4 */
1171 str = SysAllocString( szOpen );
1172 node = (IXMLDOMNode *) 1;
1173 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1174 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1175 ok( node == NULL, "getNamedItem should have returned NULL\n");
1176 SysFreeString( str );
1178 /* test indexed access of attributes */
1179 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1180 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1182 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1183 ok ( r == S_OK, "get_length wrong code\n");
1184 ok ( count == 1, "get_length != 1\n");
1187 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1188 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1189 ok ( node == NULL, "there is no node\n");
1192 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1193 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1194 ok ( node == NULL, "there is no attribute\n");
1197 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1198 ok ( r == S_OK, "get_item (0) wrong code\n");
1199 ok ( node != NULL, "should be attribute\n");
1201 r = IXMLDOMNode_get_nodeName( node, NULL );
1202 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1204 /* content doesn't matter here */
1206 r = IXMLDOMNode_get_nodeName( node, &str );
1207 ok ( r == S_OK, "get_nodeName wrong code\n");
1208 ok ( str != NULL, "str is null\n");
1209 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1210 SysFreeString( str );
1212 /* test sequential access of attributes */
1214 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1215 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1216 ok ( node != NULL, "nextNode, should be attribute\n");
1218 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1219 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1220 ok ( node == NULL, "nextNode, there is no attribute\n");
1222 r = IXMLDOMNamedNodeMap_reset( map );
1223 ok ( r == S_OK, "reset should return S_OK\n");
1225 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1226 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1227 ok ( node != NULL, "nextNode, should be attribute\n");
1230 ok( FALSE, "no map\n");
1234 type = NODE_INVALID;
1235 r = IXMLDOMNode_get_nodeType( node, &type);
1236 ok( r == S_OK, "getNamedItem returned wrong code\n");
1237 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1240 r = IXMLDOMNode_get_baseName( node, NULL );
1241 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1244 r = IXMLDOMNode_get_baseName( node, &str );
1245 ok( r == S_OK, "get_baseName returned wrong code\n");
1246 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1247 SysFreeString( str );
1249 r = IXMLDOMNode_get_nodeValue( node, &var );
1250 ok( r == S_OK, "returns %08x\n", r );
1251 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1252 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1255 r = IXMLDOMNode_get_childNodes( node, NULL );
1256 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1258 r = IXMLDOMNode_get_childNodes( node, &list );
1259 ok( r == S_OK, "get_childNodes returned wrong code\n");
1263 r = IXMLDOMNodeList_nextNode( list, &next );
1264 ok( r == S_OK, "nextNode returned wrong code\n");
1267 ok( FALSE, "no childlist\n");
1272 r = IXMLDOMNode_hasChildNodes( next, &b );
1273 ok( r == S_FALSE, "hasChildNoes bad return\n");
1274 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1276 type = NODE_INVALID;
1277 r = IXMLDOMNode_get_nodeType( next, &type);
1278 ok( r == S_OK, "getNamedItem returned wrong code\n");
1279 ok( type == NODE_TEXT, "node not text\n");
1282 r = IXMLDOMNode_get_baseName( next, &str );
1283 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1284 ok( str == NULL, "basename was wrong\n");
1288 ok( FALSE, "no next\n");
1291 IXMLDOMNode_Release( next );
1294 IXMLDOMNodeList_Release( list );
1297 IXMLDOMNode_Release( node );
1300 ok( FALSE, "no node\n");
1304 IXMLDOMNamedNodeMap_Release( map );
1306 /* now traverse the tree from the root element */
1310 r = IXMLDOMNode_get_childNodes( element, &list );
1311 ok( r == S_OK, "get_childNodes returned wrong code\n");
1313 /* using get_item for child list doesn't advance the position */
1314 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1315 expect_node(node, "E2.E2.D1");
1316 IXMLDOMNode_Release(node);
1317 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1318 expect_node(node, "E1.E2.D1");
1319 IXMLDOMNode_Release(node);
1320 ole_check(IXMLDOMNodeList_reset(list));
1322 IXMLDOMNodeList_AddRef(list);
1323 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1324 ole_check(IXMLDOMNodeList_reset(list));
1327 ok( FALSE, "no element\n");
1329 node = (void*)0xdeadbeef;
1330 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1331 ok( r == S_FALSE, "ret %08x\n", r );
1332 ok( node == NULL, "node %p\n", node );
1333 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1334 ok( r == S_OK, "ret %08x\n", r );
1335 r = IXMLDOMNode_Release( node );
1336 ok( r == 0, "ret %08x\n", r );
1340 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1341 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1343 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1344 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1346 r = IXMLDOMNodeList_get_length(list, NULL);
1347 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1349 r = IXMLDOMNodeList_get_length( list, &count );
1350 ok( r == S_OK, "get_length returns %08x\n", r );
1351 ok( count == 4, "get_length got %d\n", count );
1353 r = IXMLDOMNodeList_nextNode(list, NULL);
1354 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1356 r = IXMLDOMNodeList_nextNode( list, &node );
1357 ok( r == S_OK, "nextNode returned wrong code\n");
1360 ok( FALSE, "no list\n");
1364 type = NODE_INVALID;
1365 r = IXMLDOMNode_get_nodeType( node, &type);
1366 ok( r == S_OK, "getNamedItem returned wrong code\n");
1367 ok( type == NODE_ELEMENT, "node not text\n");
1370 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1371 r = IXMLDOMNode_get_nodeValue( node, &var );
1372 ok( r == S_FALSE, "nextNode returned wrong code\n");
1373 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1374 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1376 r = IXMLDOMNode_hasChildNodes( node, NULL );
1377 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1380 r = IXMLDOMNode_hasChildNodes( node, &b );
1381 ok( r == S_OK, "hasChildNoes bad return\n");
1382 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1385 r = IXMLDOMNode_get_baseName( node, &str );
1386 ok( r == S_OK, "get_baseName returned wrong code\n");
1387 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1391 ok( FALSE, "no node\n");
1394 IXMLDOMNode_Release( node );
1396 IXMLDOMNodeList_Release( list );
1398 IXMLDOMElement_Release( element );
1401 str = SysAllocString( szComplete5 );
1402 r = IXMLDOMDocument_loadXML( doc, str, &b );
1403 ok( r == S_OK, "loadXML failed\n");
1404 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1405 SysFreeString( str );
1408 r = IXMLDOMNode_hasChildNodes( doc, &b );
1409 ok( r == S_OK, "hasChildNoes bad return\n");
1410 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1412 r = IXMLDOMDocument_get_documentElement( doc, &element );
1413 ok( r == S_OK, "should be a document element\n");
1414 ok( element != NULL, "should be an element\n");
1418 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1421 /* check if the tag is correct */
1422 r = IXMLDOMElement_get_tagName( element, &tag );
1423 ok( r == S_OK, "couldn't get tag name\n");
1424 ok( tag != NULL, "tag was null\n");
1425 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1426 SysFreeString( tag );
1430 IXMLDOMElement_Release( element );
1432 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1435 static void test_refs(void)
1440 IXMLDOMDocument *doc = NULL;
1441 IXMLDOMElement *element = NULL;
1442 IXMLDOMNode *node = NULL, *node2;
1443 IXMLDOMNodeList *node_list = NULL;
1445 IUnknown *unk, *unk2;
1447 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1448 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1451 ref = IXMLDOMDocument_Release(doc);
1452 ok( ref == 0, "ref %d\n", ref);
1454 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1455 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1459 str = SysAllocString( szComplete4 );
1460 r = IXMLDOMDocument_loadXML( doc, str, &b );
1461 ok( r == S_OK, "loadXML failed\n");
1462 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1463 SysFreeString( str );
1465 ref = IXMLDOMDocument_AddRef( doc );
1466 ok( ref == 2, "ref %d\n", ref );
1467 ref = IXMLDOMDocument_AddRef( doc );
1468 ok( ref == 3, "ref %d\n", ref );
1469 IXMLDOMDocument_Release( doc );
1470 IXMLDOMDocument_Release( doc );
1472 r = IXMLDOMDocument_get_documentElement( doc, &element );
1473 ok( r == S_OK, "should be a document element\n");
1474 ok( element != NULL, "should be an element\n");
1476 ref = IXMLDOMDocument_AddRef( doc );
1477 ok( ref == 2, "ref %d\n", ref );
1478 IXMLDOMDocument_Release( doc );
1480 r = IXMLDOMElement_get_childNodes( element, &node_list );
1481 ok( r == S_OK, "rets %08x\n", r);
1483 ref = IXMLDOMNodeList_AddRef( node_list );
1484 ok( ref == 2, "ref %d\n", ref );
1485 IXMLDOMNodeList_Release( node_list );
1487 IXMLDOMNodeList_get_item( node_list, 0, &node );
1488 ok( r == S_OK, "rets %08x\n", r);
1490 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1491 ok( r == S_OK, "rets %08x\n", r);
1493 ref = IXMLDOMNode_AddRef( node );
1494 ok( ref == 2, "ref %d\n", ref );
1495 IXMLDOMNode_Release( node );
1497 ref = IXMLDOMNode_Release( node );
1498 ok( ref == 0, "ref %d\n", ref );
1499 ref = IXMLDOMNode_Release( node2 );
1500 ok( ref == 0, "ref %d\n", ref );
1502 ref = IXMLDOMNodeList_Release( node_list );
1503 ok( ref == 0, "ref %d\n", ref );
1505 ok( node != node2, "node %p node2 %p\n", node, node2 );
1507 ref = IXMLDOMDocument_Release( doc );
1508 ok( ref == 0, "ref %d\n", ref );
1510 ref = IXMLDOMElement_AddRef( element );
1512 ok( ref == 3, "ref %d\n", ref );
1514 IXMLDOMElement_Release( element );
1516 /* IUnknown must be unique however we obtain it */
1517 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1518 ok( r == S_OK, "rets %08x\n", r );
1519 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1520 ok( r == S_OK, "rets %08x\n", r );
1521 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1522 ok( r == S_OK, "rets %08x\n", r );
1523 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1525 IUnknown_Release( unk2 );
1526 IUnknown_Release( unk );
1527 IXMLDOMNode_Release( node );
1529 IXMLDOMElement_Release( element );
1533 static void test_create(void)
1535 static const WCHAR szOne[] = {'1',0};
1536 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1540 IXMLDOMDocument *doc;
1541 IXMLDOMElement *element;
1542 IXMLDOMNode *root, *node, *child;
1543 IXMLDOMNamedNodeMap *attr_map;
1548 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1549 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1554 V_I1(&var) = NODE_ELEMENT;
1555 str = SysAllocString( szlc );
1556 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1557 ok( r == S_OK, "returns %08x\n", r );
1558 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1561 V_R4(&var) = NODE_ELEMENT;
1562 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1563 ok( r == S_OK, "returns %08x\n", r );
1564 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1566 V_VT(&var) = VT_BSTR;
1567 V_BSTR(&var) = SysAllocString( szOne );
1568 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1569 ok( r == S_OK, "returns %08x\n", r );
1570 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1573 V_VT(&var) = VT_BSTR;
1574 V_BSTR(&var) = SysAllocString( szOneGarbage );
1575 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1576 ok( r == E_INVALIDARG, "returns %08x\n", r );
1577 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1581 V_I4(&var) = NODE_ELEMENT;
1582 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1583 ok( r == S_OK, "returns %08x\n", r );
1584 r = IXMLDOMDocument_appendChild( doc, node, &root );
1585 ok( r == S_OK, "returns %08x\n", r );
1586 ok( node == root, "%p %p\n", node, root );
1588 ref = IXMLDOMNode_AddRef( node );
1589 ok(ref == 3, "ref %d\n", ref);
1590 IXMLDOMNode_Release( node );
1592 ref = IXMLDOMNode_Release( node );
1593 ok(ref == 1, "ref %d\n", ref);
1594 SysFreeString( str );
1597 V_I4(&var) = NODE_ELEMENT;
1598 str = SysAllocString( szbs );
1599 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1600 ok( r == S_OK, "returns %08x\n", r );
1601 SysFreeString( str );
1603 ref = IXMLDOMNode_AddRef( node );
1604 ok(ref == 2, "ref = %d\n", ref);
1605 IXMLDOMNode_Release( node );
1607 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1608 ok( r == S_OK, "returns %08x\n", r );
1610 ref = IXMLDOMNode_AddRef( unk );
1611 ok(ref == 3, "ref = %d\n", ref);
1612 IXMLDOMNode_Release( unk );
1614 V_VT(&var) = VT_EMPTY;
1615 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1616 ok( r == S_OK, "returns %08x\n", r );
1617 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1618 IXMLDOMNode_Release( child );
1619 IUnknown_Release( unk );
1622 V_VT(&var) = VT_NULL;
1623 V_DISPATCH(&var) = (IDispatch*)node;
1624 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1625 ok( r == S_OK, "returns %08x\n", r );
1626 ok( node == child, "%p %p\n", node, child );
1627 IXMLDOMNode_Release( child );
1630 V_VT(&var) = VT_NULL;
1631 V_DISPATCH(&var) = (IDispatch*)node;
1632 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1633 ok( r == S_OK, "returns %08x\n", r );
1634 IXMLDOMNode_Release( node );
1636 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1637 ok( r == S_OK, "returns %08x\n", r );
1639 r = IXMLDOMElement_get_attributes( element, &attr_map );
1640 ok( r == S_OK, "returns %08x\n", r );
1641 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1642 ok( r == S_OK, "returns %08x\n", r );
1643 ok( num == 0, "num %d\n", num );
1644 IXMLDOMNamedNodeMap_Release( attr_map );
1646 V_VT(&var) = VT_BSTR;
1647 V_BSTR(&var) = SysAllocString( szstr1 );
1648 name = SysAllocString( szdl );
1649 r = IXMLDOMElement_setAttribute( element, name, var );
1650 ok( r == S_OK, "returns %08x\n", r );
1651 r = IXMLDOMElement_get_attributes( element, &attr_map );
1652 ok( r == S_OK, "returns %08x\n", r );
1653 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1654 ok( r == S_OK, "returns %08x\n", r );
1655 ok( num == 1, "num %d\n", num );
1656 IXMLDOMNamedNodeMap_Release( attr_map );
1659 V_VT(&var) = VT_BSTR;
1660 V_BSTR(&var) = SysAllocString( szstr2 );
1661 r = IXMLDOMElement_setAttribute( element, name, var );
1662 ok( r == S_OK, "returns %08x\n", r );
1663 r = IXMLDOMElement_get_attributes( element, &attr_map );
1664 ok( r == S_OK, "returns %08x\n", r );
1665 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1666 ok( r == S_OK, "returns %08x\n", r );
1667 ok( num == 1, "num %d\n", num );
1668 IXMLDOMNamedNodeMap_Release( attr_map );
1670 r = IXMLDOMElement_getAttribute( element, name, &var );
1671 ok( r == S_OK, "returns %08x\n", r );
1672 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1674 SysFreeString(name);
1676 V_VT(&var) = VT_BSTR;
1677 V_BSTR(&var) = SysAllocString( szstr1 );
1678 name = SysAllocString( szlc );
1679 r = IXMLDOMElement_setAttribute( element, name, var );
1680 ok( r == S_OK, "returns %08x\n", r );
1681 r = IXMLDOMElement_get_attributes( element, &attr_map );
1682 ok( r == S_OK, "returns %08x\n", r );
1683 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1684 ok( r == S_OK, "returns %08x\n", r );
1685 ok( num == 2, "num %d\n", num );
1686 IXMLDOMNamedNodeMap_Release( attr_map );
1688 SysFreeString(name);
1692 name = SysAllocString( szbs );
1693 r = IXMLDOMElement_setAttribute( element, name, var );
1694 ok( r == S_OK, "returns %08x\n", r );
1696 r = IXMLDOMElement_getAttribute( element, name, &var );
1697 ok( r == S_OK, "returns %08x\n", r );
1698 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1700 SysFreeString(name);
1702 /* Create an Attribute */
1704 V_I4(&var) = NODE_ATTRIBUTE;
1705 str = SysAllocString( szAttribute );
1706 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1707 ok( r == S_OK, "returns %08x\n", r );
1708 ok( node != NULL, "node was null\n");
1713 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1714 ok( r == S_OK, "returns %08x\n", r );
1715 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1717 IXMLDOMNode_Release( node );
1720 IXMLDOMElement_Release( element );
1721 IXMLDOMNode_Release( root );
1722 IXMLDOMDocument_Release( doc );
1725 static void test_getElementsByTagName(void)
1730 IXMLDOMDocument *doc;
1731 IXMLDOMNodeList *node_list;
1734 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1735 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1739 str = SysAllocString( szComplete4 );
1740 r = IXMLDOMDocument_loadXML( doc, str, &b );
1741 ok( r == S_OK, "loadXML failed\n");
1742 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1743 SysFreeString( str );
1745 str = SysAllocString( szstar );
1746 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1747 ok( r == S_OK, "ret %08x\n", r );
1748 r = IXMLDOMNodeList_get_length( node_list, &len );
1749 ok( r == S_OK, "ret %08x\n", r );
1750 ok( len == 6, "len %d\n", len );
1752 test_disp((IUnknown*)node_list);
1754 IXMLDOMNodeList_Release( node_list );
1755 SysFreeString( str );
1757 str = SysAllocString( szbs );
1758 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1759 ok( r == S_OK, "ret %08x\n", r );
1760 r = IXMLDOMNodeList_get_length( node_list, &len );
1761 ok( r == S_OK, "ret %08x\n", r );
1762 ok( len == 1, "len %d\n", len );
1763 IXMLDOMNodeList_Release( node_list );
1764 SysFreeString( str );
1766 str = SysAllocString( szdl );
1767 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1768 ok( r == S_OK, "ret %08x\n", r );
1769 r = IXMLDOMNodeList_get_length( node_list, &len );
1770 ok( r == S_OK, "ret %08x\n", r );
1771 ok( len == 0, "len %d\n", len );
1772 IXMLDOMNodeList_Release( node_list );
1773 SysFreeString( str );
1775 str = SysAllocString( szstr1 );
1776 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1777 ok( r == S_OK, "ret %08x\n", r );
1778 r = IXMLDOMNodeList_get_length( node_list, &len );
1779 ok( r == S_OK, "ret %08x\n", r );
1780 ok( len == 0, "len %d\n", len );
1781 IXMLDOMNodeList_Release( node_list );
1782 SysFreeString( str );
1784 IXMLDOMDocument_Release( doc );
1787 static void test_get_text(void)
1792 IXMLDOMDocument *doc;
1793 IXMLDOMNode *node, *node2, *node3;
1794 IXMLDOMNode *nodeRoot;
1795 IXMLDOMNodeList *node_list;
1796 IXMLDOMNamedNodeMap *node_map;
1799 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1800 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1804 str = SysAllocString( szComplete4 );
1805 r = IXMLDOMDocument_loadXML( doc, str, &b );
1806 ok( r == S_OK, "loadXML failed\n");
1807 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1808 SysFreeString( str );
1810 str = SysAllocString( szbs );
1811 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1812 ok( r == S_OK, "ret %08x\n", r );
1815 /* Test to get all child node text. */
1816 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (LPVOID*)&nodeRoot);
1817 ok( r == S_OK, "ret %08x\n", r );
1820 r = IXMLDOMNode_get_text( nodeRoot, &str );
1821 ok( r == S_OK, "ret %08x\n", r );
1822 ok( compareIgnoreReturnsWhitespace(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text\n");
1825 IXMLDOMNode_Release(nodeRoot);
1829 /* this test crashes on win9x */
1830 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1831 ok( r == E_INVALIDARG, "ret %08x\n", r );
1834 r = IXMLDOMNodeList_get_length( node_list, NULL );
1835 ok( r == E_INVALIDARG, "ret %08x\n", r );
1837 r = IXMLDOMNodeList_get_length( node_list, &len );
1838 ok( r == S_OK, "ret %08x\n", r );
1839 ok( len == 1, "expect 1 got %d\n", len );
1841 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1842 ok( r == E_INVALIDARG, "ret %08x\n", r );
1844 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1845 ok( r == E_INVALIDARG, "ret %08x\n", r );
1847 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1848 ok( r == S_OK, "ret %08x\n", r );
1849 IXMLDOMNodeList_Release( node_list );
1851 /* Invalid output parameter*/
1852 r = IXMLDOMNode_get_text( node, NULL );
1853 ok( r == E_INVALIDARG, "ret %08x\n", r );
1855 r = IXMLDOMNode_get_text( node, &str );
1856 ok( r == S_OK, "ret %08x\n", r );
1857 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1860 r = IXMLDOMNode_get_attributes( node, &node_map );
1861 ok( r == S_OK, "ret %08x\n", r );
1863 str = SysAllocString( szvr );
1864 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1865 ok( r == S_OK, "ret %08x\n", r );
1868 r = IXMLDOMNode_get_text( node2, &str );
1869 ok( r == S_OK, "ret %08x\n", r );
1870 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1873 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1874 ok( r == S_OK, "ret %08x\n", r );
1876 r = IXMLDOMNode_get_text( node3, &str );
1877 ok( r == S_OK, "ret %08x\n", r );
1878 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1882 IXMLDOMNode_Release( node3 );
1883 IXMLDOMNode_Release( node2 );
1884 IXMLDOMNamedNodeMap_Release( node_map );
1885 IXMLDOMNode_Release( node );
1886 IXMLDOMDocument_Release( doc );
1889 static void test_get_childNodes(void)
1894 IXMLDOMDocument *doc;
1895 IXMLDOMElement *element;
1896 IXMLDOMNode *node, *node2;
1897 IXMLDOMNodeList *node_list, *node_list2;
1900 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1901 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1905 str = SysAllocString( szComplete4 );
1906 r = IXMLDOMDocument_loadXML( doc, str, &b );
1907 ok( r == S_OK, "loadXML failed\n");
1908 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1909 SysFreeString( str );
1911 r = IXMLDOMDocument_get_documentElement( doc, &element );
1912 ok( r == S_OK, "ret %08x\n", r);
1914 r = IXMLDOMElement_get_childNodes( element, &node_list );
1915 ok( r == S_OK, "ret %08x\n", r);
1917 r = IXMLDOMNodeList_get_length( node_list, &len );
1918 ok( r == S_OK, "ret %08x\n", r);
1919 ok( len == 4, "len %d\n", len);
1921 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1922 ok( r == S_OK, "ret %08x\n", r);
1924 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1925 ok( r == S_OK, "ret %08x\n", r);
1927 r = IXMLDOMNodeList_get_length( node_list2, &len );
1928 ok( r == S_OK, "ret %08x\n", r);
1929 ok( len == 0, "len %d\n", len);
1931 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1932 ok( r == S_FALSE, "ret %08x\n", r);
1934 IXMLDOMNodeList_Release( node_list2 );
1935 IXMLDOMNode_Release( node );
1936 IXMLDOMNodeList_Release( node_list );
1937 IXMLDOMElement_Release( element );
1938 IXMLDOMDocument_Release( doc );
1941 static void test_removeChild(void)
1946 IXMLDOMDocument *doc;
1947 IXMLDOMElement *element, *lc_element;
1948 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
1949 IXMLDOMNodeList *root_list, *fo_list;
1951 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1952 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1956 str = SysAllocString( szComplete4 );
1957 r = IXMLDOMDocument_loadXML( doc, str, &b );
1958 ok( r == S_OK, "loadXML failed\n");
1959 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1960 SysFreeString( str );
1962 r = IXMLDOMDocument_get_documentElement( doc, &element );
1963 ok( r == S_OK, "ret %08x\n", r);
1965 r = IXMLDOMElement_get_childNodes( element, &root_list );
1966 ok( r == S_OK, "ret %08x\n", r);
1968 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1969 ok( r == S_OK, "ret %08x\n", r);
1971 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1972 ok( r == S_OK, "ret %08x\n", r);
1974 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1975 ok( r == S_OK, "ret %08x\n", r);
1977 /* invalid parameter: NULL ptr */
1978 removed_node = (void*)0xdeadbeef;
1979 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
1980 ok( r == E_INVALIDARG, "ret %08x\n", r );
1981 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1983 /* ba_node is a descendant of element, but not a direct child. */
1984 removed_node = (void*)0xdeadbeef;
1985 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
1986 ok( r == E_INVALIDARG, "ret %08x\n", r );
1987 ok( removed_node == NULL, "%p\n", removed_node );
1989 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
1990 ok( r == S_OK, "ret %08x\n", r);
1991 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
1993 /* try removing already removed child */
1994 temp_node = (void*)0xdeadbeef;
1995 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
1996 ok( r == E_INVALIDARG, "ret %08x\n", r);
1997 ok( temp_node == NULL, "%p\n", temp_node );
1999 /* the removed node has no parent anymore */
2000 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
2001 ok( r == S_FALSE, "ret %08x\n", r);
2002 ok( temp_node == NULL, "%p\n", temp_node );
2004 IXMLDOMNode_Release( removed_node );
2005 IXMLDOMNode_Release( ba_node );
2006 IXMLDOMNodeList_Release( fo_list );
2008 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2009 ok( r == S_OK, "ret %08x\n", r);
2011 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (LPVOID*)&lc_element );
2012 ok( r == S_OK, "ret %08x\n", r);
2014 /* MS quirk: passing wrong interface pointer works, too */
2015 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
2016 ok( r == S_OK, "ret %08x\n", r);
2018 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
2019 ok( r == S_FALSE, "ret %08x\n", r);
2020 ok( temp_node == NULL, "%p\n", temp_node );
2022 IXMLDOMNode_Release( lc_node );
2023 IXMLDOMNodeList_Release( root_list );
2024 IXMLDOMElement_Release( element );
2025 IXMLDOMDocument_Release( doc );
2028 static void test_replaceChild(void)
2033 IXMLDOMDocument *doc;
2034 IXMLDOMElement *element, *ba_element;
2035 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
2036 IXMLDOMNodeList *root_list, *fo_list;
2037 IUnknown * unk1, *unk2;
2040 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2041 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2045 str = SysAllocString( szComplete4 );
2046 r = IXMLDOMDocument_loadXML( doc, str, &b );
2047 ok( r == S_OK, "loadXML failed\n");
2048 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2049 SysFreeString( str );
2051 r = IXMLDOMDocument_get_documentElement( doc, &element );
2052 ok( r == S_OK, "ret %08x\n", r);
2054 r = IXMLDOMElement_get_childNodes( element, &root_list );
2055 ok( r == S_OK, "ret %08x\n", r);
2057 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2058 ok( r == S_OK, "ret %08x\n", r);
2060 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2061 ok( r == S_OK, "ret %08x\n", r);
2063 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2064 ok( r == S_OK, "ret %08x\n", r);
2066 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2067 ok( r == S_OK, "ret %08x\n", r);
2069 IXMLDOMNodeList_Release( fo_list );
2071 /* invalid parameter: NULL ptr for element to remove */
2072 removed_node = (void*)0xdeadbeef;
2073 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
2074 ok( r == E_INVALIDARG, "ret %08x\n", r );
2075 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2077 /* invalid parameter: NULL for replacement element. (Sic!) */
2078 removed_node = (void*)0xdeadbeef;
2079 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
2080 ok( r == E_INVALIDARG, "ret %08x\n", r );
2081 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2083 /* invalid parameter: OldNode is not a child */
2084 removed_node = (void*)0xdeadbeef;
2085 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
2086 ok( r == E_INVALIDARG, "ret %08x\n", r );
2087 ok( removed_node == NULL, "%p\n", removed_node );
2089 /* invalid parameter: would create loop */
2090 removed_node = (void*)0xdeadbeef;
2091 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
2092 ok( r == E_FAIL, "ret %08x\n", r );
2093 ok( removed_node == NULL, "%p\n", removed_node );
2095 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
2096 ok( r == S_OK, "ret %08x\n", r );
2098 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
2099 ok( r == S_OK, "ret %08x\n", r );
2101 /* ba_node and temp_node refer to the same node, yet they
2102 are different interface pointers */
2103 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
2104 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
2105 ok( r == S_OK, "ret %08x\n", r );
2106 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
2107 ok( r == S_OK, "ret %08x\n", r );
2108 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
2110 IUnknown_Release( unk1 );
2111 IUnknown_Release( unk2 );
2113 /* ba_node should have been removed from below fo_node */
2114 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2115 ok( r == S_OK, "ret %08x\n", r );
2117 /* MS quirk: replaceChild also accepts elements instead of nodes */
2118 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
2119 ok( r == S_OK, "ret %08x\n", r );
2121 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
2122 ok( r == S_OK, "ret %08x\n", r );
2124 r = IXMLDOMNodeList_get_length( fo_list, &len);
2125 ok( r == S_OK, "ret %08x\n", r );
2126 ok( len == 0, "len %d\n", len);
2128 IXMLDOMNodeList_Release( fo_list );
2130 IXMLDOMNode_Release(ba_node);
2131 IXMLDOMNode_Release(fo_node);
2132 IXMLDOMNode_Release(temp_node);
2133 IXMLDOMNodeList_Release( root_list );
2134 IXMLDOMElement_Release( element );
2135 IXMLDOMDocument_Release( doc );
2138 static void test_removeNamedItem(void)
2140 IXMLDOMDocument *doc;
2141 IXMLDOMElement *element;
2142 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
2143 IXMLDOMNodeList *root_list;
2144 IXMLDOMNamedNodeMap * pr_attrs;
2150 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2151 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2155 str = SysAllocString( szComplete4 );
2156 r = IXMLDOMDocument_loadXML( doc, str, &b );
2157 ok( r == S_OK, "loadXML failed\n");
2158 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2159 SysFreeString( str );
2161 r = IXMLDOMDocument_get_documentElement( doc, &element );
2162 ok( r == S_OK, "ret %08x\n", r);
2164 r = IXMLDOMElement_get_childNodes( element, &root_list );
2165 ok( r == S_OK, "ret %08x\n", r);
2167 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2168 ok( r == S_OK, "ret %08x\n", r);
2170 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2171 ok( r == S_OK, "ret %08x\n", r);
2173 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2174 ok( r == S_OK, "ret %08x\n", r);
2175 ok( len == 3, "length %d\n", len);
2177 removed_node = (void*)0xdeadbeef;
2178 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2179 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2180 ok ( removed_node == (void*)0xdeadbeef, "removed_node == %p\n", removed_node);
2182 removed_node = (void*)0xdeadbeef;
2183 str = SysAllocString(szvr);
2184 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2185 ok ( r == S_OK, "ret %08x\n", r);
2187 removed_node2 = (void*)0xdeadbeef;
2188 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2189 ok ( r == S_FALSE, "ret %08x\n", r);
2190 ok ( removed_node2 == NULL, "removed_node == %p\n", removed_node2 );
2192 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2193 ok( r == S_OK, "ret %08x\n", r);
2194 ok( len == 2, "length %d\n", len);
2196 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2197 ok ( r == S_OK, "ret %08x\n", r);
2198 IXMLDOMNode_Release(removed_node);
2200 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2201 ok( r == S_OK, "ret %08x\n", r);
2202 ok( len == 3, "length %d\n", len);
2204 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2205 ok ( r == S_OK, "ret %08x\n", r);
2207 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2208 ok( r == S_OK, "ret %08x\n", r);
2209 ok( len == 2, "length %d\n", len);
2211 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2212 ok ( r == S_FALSE, "ret %08x\n", r);
2216 IXMLDOMNamedNodeMap_Release( pr_attrs );
2217 IXMLDOMNode_Release( pr_node );
2218 IXMLDOMNodeList_Release( root_list );
2219 IXMLDOMElement_Release( element );
2220 IXMLDOMDocument_Release( doc );
2223 static void test_XMLHTTP(void)
2225 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2226 static WCHAR wszPOST[] = {'P','O','S','T',0};
2227 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2228 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2229 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2230 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2231 IXMLHttpRequest *pXMLHttpRequest;
2236 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2237 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2238 (void **)&pXMLHttpRequest);
2239 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
2243 VariantInit(&dummy);
2244 V_VT(&dummy) = VT_ERROR;
2245 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2246 VariantInit(&varfalse);
2247 V_VT(&varfalse) = VT_BOOL;
2248 V_BOOL(&varfalse) = VARIANT_FALSE;
2249 V_VT(&varbody) = VT_BSTR;
2250 V_BSTR(&varbody) = SysAllocString(wszBody);
2252 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
2253 todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
2255 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2256 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2257 VariantClear(&varbody);
2259 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2260 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2261 /* the server currently returns "FAILED" because the Content-Type header is
2262 * not what the server expects */
2265 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2266 SysFreeString(bstrResponse);
2269 IXMLHttpRequest_Release(pXMLHttpRequest);
2272 static void test_IXMLDOMDocument2(void)
2277 IXMLDOMDocument *doc;
2278 IXMLDOMDocument2 *doc2;
2279 IDispatchEx *dispex;
2283 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2284 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2288 str = SysAllocString( szComplete4 );
2289 r = IXMLDOMDocument_loadXML( doc, str, &b );
2290 ok( r == S_OK, "loadXML failed\n");
2291 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2292 SysFreeString( str );
2294 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
2295 ok( r == S_OK, "ret %08x\n", r );
2296 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
2298 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
2299 ok( r == S_OK, "ret %08x\n", r );
2302 IDispatchEx_Release(dispex);
2305 /* we will check if the variant got cleared */
2306 ref = IXMLDOMDocument2_AddRef(doc2);
2307 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
2308 V_VT(&var) = VT_UNKNOWN;
2309 V_UNKNOWN(&var) = (IUnknown *)doc2;
2312 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
2313 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
2314 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
2317 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2318 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2319 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2322 /* the variant didn't get cleared*/
2323 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
2325 /* setProperty tests */
2326 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
2327 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
2328 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
2329 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2330 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2331 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2333 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
2334 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2335 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2336 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2338 IXMLDOMDocument2_Release( doc2 );
2339 IXMLDOMDocument_Release( doc );
2343 static void test_XPath(void)
2348 IXMLDOMDocument2 *doc;
2349 IXMLDOMNode *rootNode;
2350 IXMLDOMNode *elem1Node;
2352 IXMLDOMNodeList *list;
2354 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2355 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2359 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
2360 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2362 /* switch to XPath */
2363 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2365 /* some simple queries*/
2366 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
2367 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
2368 ole_check(IXMLDOMNodeList_reset(list));
2369 expect_list_and_release(list, "E2.D1");
2370 if (rootNode == NULL)
2373 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
2374 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
2376 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
2377 expect_list_and_release(list, "E3.E2.E2.D1");
2379 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
2380 /* using get_item for query results advances the position */
2381 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2382 expect_node(node, "E2.E2.D1");
2383 IXMLDOMNode_Release(node);
2384 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2385 expect_node(node, "E4.E2.D1");
2386 IXMLDOMNode_Release(node);
2387 ole_check(IXMLDOMNodeList_reset(list));
2388 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2390 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2391 expect_list_and_release(list, "E2.D1");
2393 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2394 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2395 ole_check(IXMLDOMNodeList_reset(list));
2396 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2398 /* select an attribute */
2399 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2400 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2402 /* would evaluate to a number */
2403 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2404 /* would evaluate to a boolean */
2405 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2406 /* would evaluate to a string */
2407 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2410 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2411 expect_list_and_release(list, "");
2412 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2413 expect_list_and_release(list, "");
2414 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2415 expect_list_and_release(list, "");
2417 /* foo undeclared in document node */
2418 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2419 /* undeclared in <root> node */
2420 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2421 /* undeclared in <elem> node */
2422 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2423 /* but this trick can be used */
2424 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2425 expect_list_and_release(list, "E3.E4.E2.D1");
2427 /* it has to be declared in SelectionNamespaces */
2428 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2429 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2431 /* now the namespace can be used */
2432 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2433 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2434 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2435 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2436 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2437 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2438 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2439 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2441 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2442 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2443 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2445 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2448 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2449 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2450 if (V_VT(&var) == VT_BSTR)
2451 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2453 /* extra attributes - same thing*/
2454 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2455 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2456 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2458 IXMLDOMNode_Release(rootNode);
2459 IXMLDOMNode_Release(elem1Node);
2460 IXMLDOMDocument_Release(doc);
2464 static void test_cloneNode(void )
2466 IXMLDOMDocument *doc = NULL;
2468 IXMLDOMNodeList *pList;
2469 IXMLDOMNamedNodeMap *mapAttr;
2470 LONG nLength = 0, nLength1 = 0;
2471 LONG nAttrCnt = 0, nAttrCnt1 = 0;
2473 IXMLDOMNode *node_clone;
2474 IXMLDOMNode *node_first;
2477 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2479 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2483 str = SysAllocString( szComplete4 );
2484 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2485 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2491 str = SysAllocString( szSearch);
2492 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2493 ok( r == S_OK, "ret %08x\n", r );
2494 ok( node != NULL, "node %p\n", node );
2499 IXMLDOMDocument_Release(doc);
2503 /* Check invalid parameter */
2504 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2505 ok( r == E_INVALIDARG, "ret %08x\n", r );
2508 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2509 ok( r == S_OK, "ret %08x\n", r );
2510 ok( node_clone != NULL, "node %p\n", node );
2514 IXMLDOMDocument_Release(doc);
2515 IXMLDOMNode_Release(node);
2519 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2520 ok( r == S_OK, "ret %08x\n", r );
2523 IXMLDOMDocument *doc2;
2525 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2526 ok( r == S_OK, "ret %08x\n", r );
2528 IXMLDOMDocument_Release(doc2);
2530 IXMLDOMNode_Release(node_first);
2533 r = IXMLDOMNode_get_childNodes(node, &pList);
2534 ok( r == S_OK, "ret %08x\n", r );
2537 IXMLDOMNodeList_get_length(pList, &nLength);
2538 IXMLDOMNodeList_Release(pList);
2541 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2542 ok( r == S_OK, "ret %08x\n", r );
2545 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2546 IXMLDOMNamedNodeMap_Release(mapAttr);
2549 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2550 ok( r == S_OK, "ret %08x\n", r );
2553 IXMLDOMNodeList_get_length(pList, &nLength1);
2554 IXMLDOMNodeList_Release(pList);
2557 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2558 ok( r == S_OK, "ret %08x\n", r );
2561 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2562 IXMLDOMNamedNodeMap_Release(mapAttr);
2565 ok(nLength == nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2566 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2567 IXMLDOMNode_Release(node_clone);
2570 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2571 ok( r == S_OK, "ret %08x\n", r );
2572 ok( node_clone != NULL, "node %p\n", node );
2576 IXMLDOMDocument_Release(doc);
2577 IXMLDOMNode_Release(node);
2581 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2582 ok( r == S_FALSE, "ret %08x\n", r );
2585 IXMLDOMDocument *doc2;
2587 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2588 ok( r == S_OK, "ret %08x\n", r );
2590 IXMLDOMDocument_Release(doc2);
2592 IXMLDOMNode_Release(node_first);
2595 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2596 ok( r == S_OK, "ret %08x\n", r );
2599 IXMLDOMNodeList_get_length(pList, &nLength1);
2600 ok( nLength1 == 0, "Length should be 0 (%d)\n", nLength1);
2601 IXMLDOMNodeList_Release(pList);
2604 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2605 ok( r == S_OK, "ret %08x\n", r );
2608 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2609 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%d)\n", nAttrCnt1);
2610 IXMLDOMNamedNodeMap_Release(mapAttr);
2613 ok(nLength != nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2614 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2615 IXMLDOMNode_Release(node_clone);
2618 IXMLDOMNode_Release(node);
2619 IXMLDOMDocument_Release(doc);
2622 static void test_xmlTypes(void)
2624 IXMLDOMDocument *doc = NULL;
2625 IXMLDOMElement *pRoot;
2627 IXMLDOMComment *pComment;
2628 IXMLDOMElement *pElement;
2629 IXMLDOMAttribute *pAttrubute;
2630 IXMLDOMNamedNodeMap *pAttribs;
2631 IXMLDOMCDATASection *pCDataSec;
2632 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2633 IXMLDOMDocumentFragment *pDocFrag = NULL;
2634 IXMLDOMEntityReference *pEntityRef = NULL;
2636 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2640 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2644 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2645 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2647 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2648 ok(hr == S_FALSE, "ret %08x\n", hr );
2649 ok(pNextChild == NULL, "pDocChild not NULL\n");
2651 /* test previous Sibling */
2652 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2653 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2655 pNextChild = (IXMLDOMNode *)0x1;
2656 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2657 ok(hr == S_FALSE, "ret %08x\n", hr );
2658 ok(pNextChild == NULL, "pNextChild not NULL\n");
2660 /* test get_attributes */
2661 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2662 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2664 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2665 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2666 ok(hr == S_FALSE, "ret %08x\n", hr );
2667 ok( pAttribs == NULL, "pAttribs not NULL\n");
2669 /* test get_dataType */
2670 hr = IXMLDOMDocument_get_dataType(doc, &v);
2671 ok(hr == S_FALSE, "ret %08x\n", hr );
2672 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2675 /* test nodeTypeString */
2676 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2677 ok(hr == S_OK, "ret %08x\n", hr );
2678 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2681 /* test implementation */
2682 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2683 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2685 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2686 ok(hr == S_OK, "ret %08x\n", hr );
2689 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2690 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2692 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2693 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2695 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2696 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2698 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2699 ok(hr == S_OK, "ret %08x\n", hr );
2700 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2702 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2703 ok(hr == S_OK, "ret %08x\n", hr );
2704 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2706 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2707 ok(hr == S_OK, "ret %08x\n", hr );
2708 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2710 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2711 ok(hr == S_OK, "ret %08x\n", hr );
2712 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2714 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2715 ok(hr == S_OK, "ret %08x\n", hr );
2716 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2718 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2719 ok(hr == S_OK, "ret %08x\n", hr );
2720 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2722 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2723 ok(hr == S_OK, "ret %08x\n", hr );
2724 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2726 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2727 ok(hr == S_OK, "ret %08x\n", hr );
2728 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2730 SysFreeString(sEmpty);
2731 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2736 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2737 ok(hr == S_OK, "ret %08x\n", hr );
2740 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2741 ok(hr == S_OK, "ret %08x\n", hr );
2745 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2746 ok(hr == S_OK, "ret %08x\n", hr );
2749 /* test get_attributes */
2750 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2751 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2753 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2754 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2755 ok(hr == S_FALSE, "ret %08x\n", hr );
2756 ok( pAttribs == NULL, "pAttribs not NULL\n");
2758 /* test nodeTypeString */
2759 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2760 ok(hr == S_OK, "ret %08x\n", hr );
2761 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2764 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2765 ok(hr == S_OK, "ret %08x\n", hr );
2767 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2768 ok(hr == S_OK, "ret %08x\n", hr );
2769 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2772 hr = IXMLDOMComment_get_xml(pComment, &str);
2773 ok(hr == S_OK, "ret %08x\n", hr );
2774 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2777 hr = IXMLDOMComment_get_dataType(pComment, &v);
2778 ok(hr == S_FALSE, "ret %08x\n", hr );
2779 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2782 /* put data Tests */
2783 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2784 ok(hr == S_OK, "ret %08x\n", hr );
2786 /* get data Tests */
2787 hr = IXMLDOMComment_get_data(pComment, &str);
2788 ok(hr == S_OK, "ret %08x\n", hr );
2789 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2792 /* get data Tests */
2793 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2794 ok(hr == S_OK, "ret %08x\n", hr );
2795 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2796 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2799 /* Confirm XML text is good */
2800 hr = IXMLDOMComment_get_xml(pComment, &str);
2801 ok(hr == S_OK, "ret %08x\n", hr );
2802 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2805 /* Confirm we get the put_data Text back */
2806 hr = IXMLDOMComment_get_text(pComment, &str);
2807 ok(hr == S_OK, "ret %08x\n", hr );
2808 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2811 /* test length property */
2812 hr = IXMLDOMComment_get_length(pComment, &len);
2813 ok(hr == S_OK, "ret %08x\n", hr );
2814 ok(len == 21, "expected 21 got %d\n", len);
2816 /* test substringData */
2817 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2818 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2820 /* test substringData - Invalid offset */
2821 str = (BSTR)&szElement;
2822 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2823 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2824 ok( str == NULL, "incorrect string\n");
2826 /* test substringData - Invalid offset */
2827 str = (BSTR)&szElement;
2828 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2829 ok(hr == S_FALSE, "ret %08x\n", hr );
2830 ok( str == NULL, "incorrect string\n");
2832 /* test substringData - Invalid size */
2833 str = (BSTR)&szElement;
2834 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2835 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2836 ok( str == NULL, "incorrect string\n");
2838 /* test substringData - Invalid size */
2839 str = (BSTR)&szElement;
2840 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2841 ok(hr == S_FALSE, "ret %08x\n", hr );
2842 ok( str == NULL, "incorrect string\n");
2844 /* test substringData - Start of string */
2845 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2846 ok(hr == S_OK, "ret %08x\n", hr );
2847 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2850 /* test substringData - Middle of string */
2851 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2852 ok(hr == S_OK, "ret %08x\n", hr );
2853 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2856 /* test substringData - End of string */
2857 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2858 ok(hr == S_OK, "ret %08x\n", hr );
2859 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2862 /* test appendData */
2863 hr = IXMLDOMComment_appendData(pComment, NULL);
2864 ok(hr == S_OK, "ret %08x\n", hr );
2866 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2867 ok(hr == S_OK, "ret %08x\n", hr );
2869 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2870 ok(hr == S_OK, "ret %08x\n", hr );
2872 hr = IXMLDOMComment_get_text(pComment, &str);
2873 ok(hr == S_OK, "ret %08x\n", hr );
2874 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2877 /* test insertData */
2878 str = SysAllocStringLen(NULL, 0);
2879 hr = IXMLDOMComment_insertData(pComment, -1, str);
2880 ok(hr == S_OK, "ret %08x\n", hr );
2882 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2883 ok(hr == S_OK, "ret %08x\n", hr );
2885 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2886 ok(hr == S_OK, "ret %08x\n", hr );
2888 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2889 ok(hr == S_OK, "ret %08x\n", hr );
2891 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2892 ok(hr == S_OK, "ret %08x\n", hr );
2894 hr = IXMLDOMComment_insertData(pComment, 0, str);
2895 ok(hr == S_OK, "ret %08x\n", hr );
2898 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2899 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2901 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2902 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2904 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2905 ok(hr == S_OK, "ret %08x\n", hr );
2907 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2908 ok(hr == S_OK, "ret %08x\n", hr );
2910 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2911 ok(hr == S_OK, "ret %08x\n", hr );
2913 hr = IXMLDOMComment_get_text(pComment, &str);
2914 ok(hr == S_OK, "ret %08x\n", hr );
2915 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2918 IXMLDOMComment_Release(pComment);
2922 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2923 ok(hr == S_OK, "ret %08x\n", hr );
2926 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2927 ok(hr == S_OK, "ret %08x\n", hr );
2929 /* test nodeTypeString */
2930 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2931 ok(hr == S_OK, "ret %08x\n", hr );
2932 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2935 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2936 ok(hr == S_OK, "ret %08x\n", hr );
2937 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2940 hr = IXMLDOMElement_get_xml(pElement, &str);
2941 ok(hr == S_OK, "ret %08x\n", hr );
2942 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2945 hr = IXMLDOMElement_get_dataType(pElement, &v);
2946 ok(hr == S_FALSE, "ret %08x\n", hr );
2947 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2951 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2952 ok(hr == S_OK, "ret %08x\n", hr );
2955 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2957 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2958 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2960 pNextChild = (IXMLDOMNode *)0x1;
2961 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2962 ok(hr == S_FALSE, "ret %08x\n", hr );
2963 ok(pNextChild == NULL, "pNextChild not NULL\n");
2965 /* test Previous Sibling*/
2966 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2967 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2969 pNextChild = (IXMLDOMNode *)0x1;
2970 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2971 ok(hr == S_FALSE, "ret %08x\n", hr );
2972 ok(pNextChild == NULL, "pNextChild not NULL\n");
2974 /* test get_attributes */
2975 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2976 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2978 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2979 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2980 ok(hr == S_FALSE, "ret %08x\n", hr );
2981 ok( pAttribs == NULL, "pAttribs not NULL\n");
2983 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2984 ok(hr == E_FAIL, "ret %08x\n", hr );
2985 ok(pNewChild == NULL, "pNewChild not NULL\n");
2987 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2988 ok(hr == S_OK, "ret %08x\n", hr );
2991 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
2992 ok(hr == S_OK, "ret %08x\n", hr );
2994 IXMLDOMNamedNodeMap_Release(pAttribs);
2997 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
2998 ok(hr == S_OK, "ret %08x\n", hr );
2999 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
3002 /* test nodeTypeString */
3003 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
3004 ok(hr == S_OK, "ret %08x\n", hr );
3005 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
3009 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
3010 ok(hr == S_OK, "ret %08x\n", hr );
3011 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
3014 /* test name property */
3015 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
3016 ok(hr == S_OK, "ret %08x\n", hr );
3017 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
3020 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
3021 ok(hr == S_OK, "ret %08x\n", hr );
3022 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
3025 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
3026 ok(hr == S_FALSE, "ret %08x\n", hr );
3027 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3030 IXMLDOMAttribute_Release(pAttrubute);
3032 /* Check Element again with the Add Attribute*/
3033 hr = IXMLDOMElement_get_xml(pElement, &str);
3034 ok(hr == S_OK, "ret %08x\n", hr );
3035 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
3039 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
3040 ok(hr == S_OK, "ret %08x\n", hr );
3042 hr = IXMLDOMElement_get_xml(pElement, &str);
3043 ok(hr == S_OK, "ret %08x\n", hr );
3044 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
3047 /* Test for reversible escaping */
3048 str = SysAllocString( szStrangeChars );
3049 hr = IXMLDOMElement_put_text(pElement, str);
3050 ok(hr == S_OK, "ret %08x\n", hr );
3051 SysFreeString( str );
3053 hr = IXMLDOMElement_get_xml(pElement, &str);
3054 ok(hr == S_OK, "ret %08x\n", hr );
3055 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
3058 hr = IXMLDOMElement_get_text(pElement, &str);
3059 ok(hr == S_OK, "ret %08x\n", hr );
3060 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
3063 IXMLDOMElement_Release(pElement);
3067 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
3068 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3070 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
3071 ok(hr == S_OK, "ret %08x\n", hr );
3074 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3077 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (LPVOID*)&pElement);
3078 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
3080 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
3081 ok(hr == S_OK, "ret %08x\n", hr );
3083 /* get Attribute Tests */
3084 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
3085 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3087 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3088 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
3089 ok(hr == S_FALSE, "ret %08x\n", hr );
3090 ok(pAttribs == NULL, "pAttribs != NULL\n");
3092 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
3093 ok(hr == S_OK, "ret %08x\n", hr );
3094 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
3097 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3098 ok(hr == S_OK, "ret %08x\n", hr );
3099 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
3102 /* test lastChild */
3103 pNextChild = (IXMLDOMNode*)0x1;
3104 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
3105 ok(hr == S_FALSE, "ret %08x\n", hr );
3106 ok(pNextChild == NULL, "pNextChild not NULL\n");
3108 /* test get_dataType */
3109 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
3110 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3112 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
3113 ok(hr == S_FALSE, "ret %08x\n", hr );
3114 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3117 /* test nodeTypeString */
3118 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
3119 ok(hr == S_OK, "ret %08x\n", hr );
3120 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
3123 /* put data Tests */
3124 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
3125 ok(hr == S_OK, "ret %08x\n", hr );
3127 /* Confirm XML text is good */
3128 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3129 ok(hr == S_OK, "ret %08x\n", hr );
3130 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
3133 /* Confirm we get the put_data Text back */
3134 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3135 ok(hr == S_OK, "ret %08x\n", hr );
3136 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3139 /* test length property */
3140 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
3141 ok(hr == S_OK, "ret %08x\n", hr );
3142 ok(len == 21, "expected 21 got %d\n", len);
3144 /* test get nodeValue */
3145 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
3146 ok(hr == S_OK, "ret %08x\n", hr );
3147 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3151 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
3152 ok(hr == S_OK, "ret %08x\n", hr );
3153 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3156 /* test substringData */
3157 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
3158 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3160 /* test substringData - Invalid offset */
3161 str = (BSTR)&szElement;
3162 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
3163 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3164 ok( str == NULL, "incorrect string\n");
3166 /* test substringData - Invalid offset */
3167 str = (BSTR)&szElement;
3168 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
3169 ok(hr == S_FALSE, "ret %08x\n", hr );
3170 ok( str == NULL, "incorrect string\n");
3172 /* test substringData - Invalid size */
3173 str = (BSTR)&szElement;
3174 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
3175 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3176 ok( str == NULL, "incorrect string\n");
3178 /* test substringData - Invalid size */
3179 str = (BSTR)&szElement;
3180 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
3181 ok(hr == S_FALSE, "ret %08x\n", hr );
3182 ok( str == NULL, "incorrect string\n");
3184 /* test substringData - Start of string */
3185 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
3186 ok(hr == S_OK, "ret %08x\n", hr );
3187 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
3190 /* test substringData - Middle of string */
3191 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
3192 ok(hr == S_OK, "ret %08x\n", hr );
3193 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
3196 /* test substringData - End of string */
3197 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
3198 ok(hr == S_OK, "ret %08x\n", hr );
3199 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
3202 /* test appendData */
3203 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
3204 ok(hr == S_OK, "ret %08x\n", hr );
3206 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
3207 ok(hr == S_OK, "ret %08x\n", hr );
3209 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
3210 ok(hr == S_OK, "ret %08x\n", hr );
3212 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3213 ok(hr == S_OK, "ret %08x\n", hr );
3214 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
3217 /* test insertData */
3218 str = SysAllocStringLen(NULL, 0);
3219 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
3220 ok(hr == S_OK, "ret %08x\n", hr );
3222 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
3223 ok(hr == S_OK, "ret %08x\n", hr );
3225 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
3226 ok(hr == S_OK, "ret %08x\n", hr );
3228 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
3229 ok(hr == S_OK, "ret %08x\n", hr );
3231 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
3232 ok(hr == S_OK, "ret %08x\n", hr );
3234 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
3235 ok(hr == S_OK, "ret %08x\n", hr );
3238 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
3239 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3241 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
3242 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3244 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
3245 ok(hr == S_OK, "ret %08x\n", hr );
3247 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
3248 ok(hr == S_OK, "ret %08x\n", hr );
3250 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
3251 ok(hr == S_OK, "ret %08x\n", hr );
3253 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3254 ok(hr == S_OK, "ret %08x\n", hr );
3255 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
3258 IXMLDOMCDATASection_Release(pCDataSec);
3261 /* Document Fragments */
3262 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
3263 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3265 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
3266 ok(hr == S_OK, "ret %08x\n", hr );
3269 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3271 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
3272 ok(hr == S_OK, "ret %08x\n", hr );
3274 /* get Attribute Tests */
3275 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
3276 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3278 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3279 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
3280 ok(hr == S_FALSE, "ret %08x\n", hr );
3281 ok(pAttribs == NULL, "pAttribs != NULL\n");
3283 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
3284 ok(hr == S_OK, "ret %08x\n", hr );
3285 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
3288 /* test next Sibling*/
3289 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
3290 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3292 pNextChild = (IXMLDOMNode *)0x1;
3293 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
3294 ok(hr == S_FALSE, "ret %08x\n", hr );
3295 ok(pNextChild == NULL, "pNextChild not NULL\n");
3297 /* test Previous Sibling*/
3298 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
3299 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3301 pNextChild = (IXMLDOMNode *)0x1;
3302 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
3303 ok(hr == S_FALSE, "ret %08x\n", hr );
3304 ok(pNextChild == NULL, "pNextChild not NULL\n");
3306 /* test get_dataType */
3307 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
3308 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3310 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
3311 ok(hr == S_FALSE, "ret %08x\n", hr );
3312 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3315 /* test nodeTypeString */
3316 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
3317 ok(hr == S_OK, "ret %08x\n", hr );
3318 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
3321 IXMLDOMDocumentFragment_Release(pDocFrag);
3324 /* Entity References */
3325 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
3326 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3328 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
3329 ok(hr == S_OK, "ret %08x\n", hr );
3332 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
3333 ok(hr == S_OK, "ret %08x\n", hr );
3335 /* get Attribute Tests */
3336 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
3337 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3339 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3340 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
3341 ok(hr == S_FALSE, "ret %08x\n", hr );
3342 ok(pAttribs == NULL, "pAttribs != NULL\n");
3345 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
3346 ok(hr == S_FALSE, "ret %08x\n", hr );
3347 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3350 /* test nodeTypeString */
3351 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
3352 ok(hr == S_OK, "ret %08x\n", hr );
3353 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
3357 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
3358 ok(hr == S_OK, "ret %08x\n", hr );
3359 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
3362 IXMLDOMEntityReference_Release(pEntityRef);
3365 IXMLDOMElement_Release( pRoot );
3369 IXMLDOMDocument_Release(doc);
3374 static void test_nodeTypeTests( void )
3376 IXMLDOMDocument *doc = NULL;
3377 IXMLDOMElement *pRoot;
3378 IXMLDOMElement *pElement;
3381 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3385 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3386 ok(hr == S_OK, "ret %08x\n", hr );
3389 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3390 ok(hr == S_OK, "ret %08x\n", hr );
3393 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
3394 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3397 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
3398 ok(hr == E_FAIL, "ret %08x\n", hr );
3401 * The name passed into put_dataType is case-insensitive. So many of the names
3402 * have been changed to reflect this.
3405 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
3406 ok(hr == S_OK, "ret %08x\n", hr );
3409 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3411 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
3412 ok(hr == S_OK, "ret %08x\n", hr );
3414 IXMLDOMElement_Release(pElement);
3418 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
3419 ok(hr == S_OK, "ret %08x\n", hr );
3422 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3424 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
3425 ok(hr == S_OK, "ret %08x\n", hr );
3427 IXMLDOMElement_Release(pElement);
3431 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
3432 ok(hr == S_OK, "ret %08x\n", hr );
3435 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3437 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
3438 ok(hr == S_OK, "ret %08x\n", hr );
3440 IXMLDOMElement_Release(pElement);
3444 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
3445 ok(hr == S_OK, "ret %08x\n", hr );
3448 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3450 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
3451 ok(hr == S_OK, "ret %08x\n", hr );
3453 IXMLDOMElement_Release(pElement);
3457 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3458 ok(hr == S_OK, "ret %08x\n", hr );
3461 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3463 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3464 ok(hr == S_OK, "ret %08x\n", hr );
3466 IXMLDOMElement_Release(pElement);
3470 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3471 ok(hr == S_OK, "ret %08x\n", hr );
3474 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3476 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3477 ok(hr == S_OK, "ret %08x\n", hr );
3479 IXMLDOMElement_Release(pElement);
3483 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3484 ok(hr == S_OK, "ret %08x\n", hr );
3487 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3489 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3490 ok(hr == S_OK, "ret %08x\n", hr );
3492 IXMLDOMElement_Release(pElement);
3496 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3497 ok(hr == S_OK, "ret %08x\n", hr );
3500 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3502 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3503 ok(hr == S_OK, "ret %08x\n", hr );
3505 IXMLDOMElement_Release(pElement);
3509 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3510 ok(hr == S_OK, "ret %08x\n", hr );
3513 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3515 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3516 ok(hr == S_OK, "ret %08x\n", hr );
3518 IXMLDOMElement_Release(pElement);
3522 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3523 ok(hr == S_OK, "ret %08x\n", hr );
3526 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3528 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3529 ok(hr == S_OK, "ret %08x\n", hr );
3531 IXMLDOMElement_Release(pElement);
3535 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3536 ok(hr == S_OK, "ret %08x\n", hr );
3539 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3541 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3542 ok(hr == S_OK, "ret %08x\n", hr );
3544 IXMLDOMElement_Release(pElement);
3548 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3549 ok(hr == S_OK, "ret %08x\n", hr );
3552 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3554 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3555 ok(hr == S_OK, "ret %08x\n", hr );
3557 IXMLDOMElement_Release(pElement);
3561 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3562 ok(hr == S_OK, "ret %08x\n", hr );
3565 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3567 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3568 ok(hr == S_OK, "ret %08x\n", hr );
3570 IXMLDOMElement_Release(pElement);
3574 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3575 ok(hr == S_OK, "ret %08x\n", hr );
3578 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3580 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3581 ok(hr == S_OK, "ret %08x\n", hr );
3583 IXMLDOMElement_Release(pElement);
3587 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3588 ok(hr == S_OK, "ret %08x\n", hr );
3591 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3593 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3594 ok(hr == S_OK, "ret %08x\n", hr );
3596 IXMLDOMElement_Release(pElement);
3600 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3601 ok(hr == S_OK, "ret %08x\n", hr );
3604 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3606 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3607 ok(hr == S_OK, "ret %08x\n", hr );
3609 IXMLDOMElement_Release(pElement);
3613 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3614 ok(hr == S_OK, "ret %08x\n", hr );
3617 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3619 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3620 ok(hr == S_OK, "ret %08x\n", hr );
3622 IXMLDOMElement_Release(pElement);
3626 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3627 ok(hr == S_OK, "ret %08x\n", hr );
3630 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3632 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3633 ok(hr == S_OK, "ret %08x\n", hr );
3635 IXMLDOMElement_Release(pElement);
3639 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3640 ok(hr == S_OK, "ret %08x\n", hr );
3643 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3645 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3646 ok(hr == S_OK, "ret %08x\n", hr );
3648 IXMLDOMElement_Release(pElement);
3652 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3653 ok(hr == S_OK, "ret %08x\n", hr );
3656 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3658 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3659 ok(hr == S_OK, "ret %08x\n", hr );
3661 IXMLDOMElement_Release(pElement);
3665 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3666 ok(hr == S_OK, "ret %08x\n", hr );
3669 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3671 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3672 ok(hr == S_OK, "ret %08x\n", hr );
3674 IXMLDOMElement_Release(pElement);
3678 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3679 ok(hr == S_OK, "ret %08x\n", hr );
3682 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3684 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3685 ok(hr == S_OK, "ret %08x\n", hr );
3687 IXMLDOMElement_Release(pElement);
3690 /* Check changing types */
3691 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3692 ok(hr == S_OK, "ret %08x\n", hr );
3695 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3697 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3698 ok(hr == S_OK, "ret %08x\n", hr );
3700 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3701 ok(hr == S_OK, "ret %08x\n", hr );
3703 IXMLDOMElement_Release(pElement);
3706 IXMLDOMElement_Release(pRoot);
3710 IXMLDOMDocument_Release(doc);
3715 static void test_DocumentSaveToDocument(void)
3717 IXMLDOMDocument *doc = NULL;
3718 IXMLDOMDocument *doc2 = NULL;
3719 IXMLDOMElement *pRoot;
3723 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3727 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3730 IXMLDOMDocument_Release(doc);
3734 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3735 ok(hr == S_OK, "ret %08x\n", hr );
3738 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3739 ok(hr == S_OK, "ret %08x\n", hr );
3746 V_VT(&vDoc) = VT_UNKNOWN;
3747 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3749 hr = IXMLDOMDocument_save(doc, vDoc);
3750 ok(hr == S_OK, "ret %08x\n", hr );
3752 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3753 ok(hr == S_OK, "ret %08x\n", hr );
3755 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3756 ok(hr == S_OK, "ret %08x\n", hr );
3758 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3760 SysFreeString(sOrig);
3761 SysFreeString(sNew);
3765 IXMLDOMDocument_Release(doc2);
3766 IXMLDOMDocument_Release(doc);
3769 static void test_DocumentSaveToFile(void)
3771 IXMLDOMDocument *doc = NULL;
3772 IXMLDOMElement *pRoot;
3778 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3782 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3783 ok(hr == S_OK, "ret %08x\n", hr );
3786 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3787 ok(hr == S_OK, "ret %08x\n", hr );
3792 V_VT(&vFile) = VT_BSTR;
3793 V_BSTR(&vFile) = _bstr_("test.xml");
3795 hr = IXMLDOMDocument_save(doc, vFile);
3796 ok(hr == S_OK, "ret %08x\n", hr );
3800 IXMLDOMElement_Release(pRoot);
3801 IXMLDOMDocument_Release(doc);
3803 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3804 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3805 if(file == INVALID_HANDLE_VALUE)
3808 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3809 ok(read != 0, "could not read file\n");
3810 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3813 DeleteFile("test.xml");
3816 static void test_testTransforms(void)
3818 IXMLDOMDocument *doc = NULL;
3819 IXMLDOMDocument *docSS = NULL;
3825 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3829 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3832 IXMLDOMDocument_Release(doc);
3836 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3837 ok(hr == S_OK, "ret %08x\n", hr );
3839 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3840 ok(hr == S_OK, "ret %08x\n", hr );
3842 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3843 ok(hr == S_OK, "ret %08x\n", hr );
3848 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3849 ok(hr == S_OK, "ret %08x\n", hr );
3850 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3851 SysFreeString(bOut);
3853 IXMLDOMNode_Release(pNode);
3856 IXMLDOMDocument_Release(docSS);
3857 IXMLDOMDocument_Release(doc);
3862 static void test_Namespaces(void)
3864 IXMLDOMDocument2 *doc = NULL;
3866 IXMLDOMNode *pNode2 = NULL;
3870 static const CHAR szNamespacesXML[] =
3871 "<?xml version=\"1.0\"?>\n"
3872 "<root xmlns:WEB='http://www.winehq.org'>\n"
3873 "<WEB:Site version=\"1.0\" />\n"
3876 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3880 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3881 ok(hr == S_OK, "ret %08x\n", hr );
3882 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3884 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3885 ok(hr == S_OK, "ret %08x\n", hr );
3888 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3889 ok( hr == S_OK, "ret %08x\n", hr );
3890 ok( pNode2 != NULL, "pNode2 == NULL\n");
3892 /* Test get_prefix */
3893 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3894 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3895 /* NOTE: Need to test that arg2 gets cleared on Error. */
3897 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3898 ok( hr == S_OK, "ret %08x\n", hr );
3899 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3902 /* Test get_namespaceURI */
3903 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3904 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3905 /* NOTE: Need to test that arg2 gets cleared on Error. */
3907 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3908 ok( hr == S_OK, "ret %08x\n", hr );
3909 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3912 IXMLDOMNode_Release(pNode2);
3913 IXMLDOMNode_Release(pNode);
3916 IXMLDOMDocument2_Release(doc);
3921 static void test_FormattingXML(void)
3923 IXMLDOMDocument2 *doc = NULL;
3924 IXMLDOMElement *pElement;
3928 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
3929 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
3931 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3935 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
3936 ok(hr == S_OK, "ret %08x\n", hr );
3937 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3939 if(bSucc == VARIANT_TRUE)
3941 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
3942 ok(hr == S_OK, "ret %08x\n", hr );
3945 hr = IXMLDOMElement_get_xml(pElement, &str);
3946 ok(hr == S_OK, "ret %08x\n", hr );
3947 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
3950 IXMLDOMElement_Release(pElement);
3954 IXMLDOMDocument2_Release(doc);
3959 static void test_NodeTypeValue(void)
3961 IXMLDOMDocument2 *doc = NULL;
3967 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3971 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
3972 ok(hr == S_OK, "ret %08x\n", hr );
3973 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3974 if(bSucc == VARIANT_TRUE)
3976 hr = IXMLDOMDocument2_get_nodeValue(doc, NULL);
3977 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3981 hr = IXMLDOMDocument2_get_nodeValue(doc, &v);
3982 ok(hr == S_FALSE, "ret %08x\n", hr );
3983 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
3985 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, NULL);
3986 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3988 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, &v);
3989 ok(hr == S_FALSE, "ret %08x\n", hr );
3991 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string"), &pNode);
3992 ok(hr == S_OK, "ret %08x\n", hr );
3997 hr = IXMLDOMNode_get_nodeValue(pNode, &v);
3998 ok(hr == S_FALSE, "ret %08x\n", hr );
3999 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
4001 hr = IXMLDOMNode_get_nodeTypedValue(pNode, NULL);
4002 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4004 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4005 ok(hr == S_OK, "ret %08x\n", hr );
4006 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4007 ok(!lstrcmpW( V_BSTR(&v), _bstr_("Wine") ), "incorrect value\n");
4010 IXMLDOMNode_Release(pNode);
4013 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string2"), &pNode);
4014 ok(hr == S_OK, "ret %08x\n", hr );
4017 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4018 ok(hr == S_OK, "ret %08x\n", hr );
4019 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4020 ok(!lstrcmpW( V_BSTR(&v), _bstr_("String") ), "incorrect value\n");
4023 IXMLDOMNode_Release(pNode);
4026 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number"), &pNode);
4027 ok(hr == S_OK, "ret %08x\n", hr );
4030 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4031 ok(hr == S_OK, "ret %08x\n", hr );
4032 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4033 ok(!lstrcmpW( V_BSTR(&v), _bstr_("12.44") ), "incorrect value\n");
4036 IXMLDOMNode_Release(pNode);
4039 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number2"), &pNode);
4040 ok(hr == S_OK, "ret %08x\n", hr );
4043 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4044 ok(hr == S_OK, "ret %08x\n", hr );
4045 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4046 ok(!lstrcmpW( V_BSTR(&v), _bstr_("-3.71e3") ), "incorrect value\n");
4049 IXMLDOMNode_Release(pNode);
4052 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/int"), &pNode);
4053 ok(hr == S_OK, "ret %08x\n", hr );
4056 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4057 ok(hr == S_OK, "ret %08x\n", hr );
4058 ok(V_VT(&v) == VT_I4, "incorrect type\n");
4059 ok(V_I4(&v) == -13, "incorrect value\n");
4062 IXMLDOMNode_Release(pNode);
4065 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/fixed"), &pNode);
4066 ok(hr == S_OK, "ret %08x\n", hr );
4069 VARIANT hlp_in, hlp_out;
4070 V_VT(&hlp_in) = VT_BSTR;
4071 V_BSTR(&hlp_in) = _bstr_("7322.9371");
4072 V_VT(&hlp_out) = VT_CY;
4073 ok(VariantChangeType(&hlp_out, &hlp_in, 0, VT_CY) == S_OK, "VariantChangeType failed\n");
4074 VariantClear(&hlp_in);
4076 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4077 ok(hr == S_OK, "ret %08x\n", hr );
4078 ok(V_VT(&v) == VT_CY, "incorrect type\n");
4079 ok(VarCyCmp(V_CY(&v), V_CY(&hlp_out)) == VARCMP_EQ, "incorrect value\n");
4080 VariantClear(&hlp_out);
4083 IXMLDOMNode_Release(pNode);
4086 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/bool"), &pNode);
4087 ok(hr == S_OK, "ret %08x\n", hr );
4090 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4091 ok(hr == S_OK, "ret %08x\n", hr );
4092 ok(V_VT(&v) == VT_BOOL, "incorrect type\n");
4093 ok(V_BOOL(&v) == VARIANT_TRUE, "incorrect value\n");
4096 IXMLDOMNode_Release(pNode);
4099 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/datetime"), &pNode);
4100 ok(hr == S_OK, "ret %08x\n", hr );
4103 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4104 ok(hr == S_OK, "ret %08x\n", hr );
4105 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4106 double_eq(40135.13996666666, V_DATE(&v));
4109 IXMLDOMNode_Release(pNode);
4112 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/datetimetz"), &pNode);
4113 ok(hr == S_OK, "ret %08x\n", hr );
4116 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4117 ok(hr == S_OK, "ret %08x\n", hr );
4118 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4119 double_eq(37813.59302083334, V_DATE(&v));
4122 IXMLDOMNode_Release(pNode);
4125 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/date"), &pNode);
4126 ok(hr == S_OK, "ret %08x\n", hr );
4129 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4130 ok(hr == S_OK, "ret %08x\n", hr );
4131 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4132 double_eq(665413.0, V_DATE(&v));
4135 IXMLDOMNode_Release(pNode);
4138 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/time"), &pNode);
4139 ok(hr == S_OK, "ret %08x\n", hr );
4142 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4143 ok(hr == S_OK, "ret %08x\n", hr );
4144 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4145 double_eq(0.581392511574074, V_DATE(&v));
4148 IXMLDOMNode_Release(pNode);
4151 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/timetz"), &pNode);
4152 ok(hr == S_OK, "ret %08x\n", hr );
4155 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4156 ok(hr == S_OK, "ret %08x\n", hr );
4157 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4158 double_eq(1.112513078703703, V_DATE(&v));
4161 IXMLDOMNode_Release(pNode);
4164 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i1"), &pNode);
4165 ok(hr == S_OK, "ret %08x\n", hr );
4168 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4169 ok(hr == S_OK, "ret %08x\n", hr );
4170 ok(V_VT(&v) == VT_I1, "incorrect type\n");
4171 ok(V_I1(&v) == -13, "incorrect value\n");
4174 IXMLDOMNode_Release(pNode);
4178 IXMLDOMDocument2_Release(doc);
4183 static void test_TransformWithLoadingLocalFile(void)
4185 IXMLDOMDocument2 *doc = NULL;
4186 IXMLDOMDocument2 *xsl = NULL;
4192 char lpPathBuffer[MAX_PATH];
4195 /* Create a Temp File. */
4196 GetTempPathA(MAX_PATH, lpPathBuffer);
4197 strcat(lpPathBuffer, "customers.xml" );
4199 file = CreateFile(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
4200 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
4201 if(file == INVALID_HANDLE_VALUE)
4204 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
4207 /* Correct path to not include a escape character. */
4208 for(i=0; i < strlen(lpPathBuffer); i++)
4210 if(lpPathBuffer[i] == '\\')
4211 lpPathBuffer[i] = '/';
4214 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
4218 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&xsl );
4221 IXMLDOMDocument2_Release(doc);
4225 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
4226 ok(hr == S_OK, "ret %08x\n", hr );
4227 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4228 if(bSucc == VARIANT_TRUE)
4231 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
4232 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
4233 BSTR sFileName = _bstr_(lpPathBuffer);
4234 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
4236 sXSL = SysAllocStringLen(NULL, nLegnth);
4237 lstrcpyW(sXSL, sPart1);
4238 lstrcatW(sXSL, sFileName);
4239 lstrcatW(sXSL, sPart2);
4241 hr = IXMLDOMDocument2_loadXML(xsl, sXSL, &bSucc);
4242 ok(hr == S_OK, "ret %08x\n", hr );
4243 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4244 if(bSucc == VARIANT_TRUE)
4248 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (LPVOID*)&pNode );
4249 ok(hr == S_OK, "ret %08x\n", hr );
4252 /* This will load the temp file via the XSL */
4253 hr = IXMLDOMDocument2_transformNode(doc, pNode, &sResult);
4254 ok(hr == S_OK, "ret %08x\n", hr );
4257 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
4258 SysFreeString(sResult);
4261 IXMLDOMNode_Release(pNode);
4265 SysFreeString(sXSL);
4268 IXMLDOMDocument2_Release(doc);
4269 IXMLDOMDocument2_Release(xsl);
4271 DeleteFile(lpPathBuffer);
4279 r = CoInitialize( NULL );
4280 ok( r == S_OK, "failed to init com\n");
4286 test_getElementsByTagName();
4288 test_get_childNodes();
4290 test_replaceChild();
4291 test_removeNamedItem();
4293 test_IXMLDOMDocument2();
4297 test_nodeTypeTests();
4298 test_DocumentSaveToDocument();
4299 test_DocumentSaveToFile();
4300 test_testTransforms();
4302 test_FormattingXML();
4303 test_NodeTypeValue();
4304 test_TransformWithLoadingLocalFile();