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"
165 " <i2 dt:dt=\"i2\">31915</i2>\n"
166 " <i4 dt:dt=\"i4\">-312232</i4>\n"
167 " <ui1 dt:dt=\"ui1\">123</ui1>\n"
168 " <ui2 dt:dt=\"ui2\">48282</ui2>\n"
169 " <ui4 dt:dt=\"ui4\">949281</ui4>\n"
170 " <r4 dt:dt=\"r4\">213124.0</r4>\n"
171 " <r8 dt:dt=\"r8\">0.412</r8>\n"
172 " <float dt:dt=\"float\">41221.421</float>\n"
173 " <uuid dt:dt=\"uuid\">333C7BC4-460F-11D0-BC04-0080C7055a83</uuid>\n"
176 static const CHAR szBasicTransformSSXMLPart1[] =
177 "<?xml version=\"1.0\"?>"
178 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
179 "<xsl:output method=\"html\"/>\n"
180 "<xsl:template match=\"/\">"
181 "<HTML><BODY><TABLE>"
182 " <xsl:apply-templates select='document(\"";
184 static const CHAR szBasicTransformSSXMLPart2[] =
186 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
187 " </xsl:apply-templates>"
188 "</TABLE></BODY></HTML>"
190 "<xsl:template match=\"bottle\">"
191 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
193 "<xsl:template match=\"name\">"
194 " <TD><xsl:apply-templates /></TD>"
196 "<xsl:template match=\"cost\">"
197 " <TD><xsl:apply-templates /></TD>"
201 static const CHAR szBasicTransformXML[] =
202 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
204 static const CHAR szBasicTransformOutput[] =
205 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
207 static const WCHAR szNonExistentFile[] = {
208 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
210 static const WCHAR szDocument[] = {
211 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
214 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
215 static WCHAR szdl[] = { 'd','l',0 };
216 static const WCHAR szvr[] = { 'v','r',0 };
217 static const WCHAR szlc[] = { 'l','c',0 };
218 static WCHAR szbs[] = { 'b','s',0 };
219 static const WCHAR szstr1[] = { 's','t','r','1',0 };
220 static const WCHAR szstr2[] = { 's','t','r','2',0 };
221 static const WCHAR szstar[] = { '*',0 };
222 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
224 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
225 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
226 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
228 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
229 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
230 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
231 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
232 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
233 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
234 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
236 static WCHAR szAttribute[] = {'A','t','t','r',0 };
237 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
239 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
240 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
241 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
242 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
244 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
245 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
247 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
248 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
249 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
251 #define expect_bstr_eq_and_free(bstr, expect) { \
252 BSTR bstrExp = alloc_str_from_narrow(expect); \
253 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
254 SysFreeString(bstr); \
255 SysFreeString(bstrExp); \
258 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
260 #define ole_check(expr) { \
262 ok(r == S_OK, #expr " returned %x\n", r); \
265 #define ole_expect(expr, expect) { \
267 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
270 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
272 static BSTR alloc_str_from_narrow(const char *str)
274 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
275 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
276 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
280 BSTR alloced_bstrs[256];
281 int alloced_bstrs_count = 0;
283 static BSTR _bstr_(const char *str)
285 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
286 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
287 return alloced_bstrs[alloced_bstrs_count++];
290 static void free_bstrs(void)
293 for (i = 0; i < alloced_bstrs_count; i++)
294 SysFreeString(alloced_bstrs[i]);
295 alloced_bstrs_count = 0;
298 static VARIANT _variantbstr_(const char *str)
302 V_BSTR(&v) = _bstr_(str);
306 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
310 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
311 while (*sRight == '\r' || *sRight == '\n') sRight++;
312 if (*sLeft != *sRight) return FALSE;
313 if (!*sLeft) return TRUE;
319 static BOOL compareIgnoreReturnsWhitespace(BSTR sLeft, BSTR sRight)
321 /* MSXML3 inserts whitespace where as libxml doesn't. */
324 while (*sLeft == '\r' || *sLeft == '\n' || *sLeft == ' ') sLeft++;
325 while (*sRight == '\r' || *sRight == '\n' || *sRight == ' ') sRight++;
326 if (*sLeft != *sRight) return FALSE;
327 if (!*sLeft) return TRUE;
333 static void get_str_for_type(DOMNodeType type, char *buf)
347 wsprintfA(buf, "[%d]", type);
351 #define test_disp(u) _test_disp(__LINE__,u)
352 static void _test_disp(unsigned line, IUnknown *unk)
354 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
362 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
363 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
368 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
369 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
370 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
372 sName = SysAllocString( szstar );
373 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
374 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
375 SysFreeString( sName );
377 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
378 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
380 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
381 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
382 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
384 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
385 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
387 SysFreeString(sName);
389 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
390 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
392 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
393 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
394 if(hres == S_OK && pUnk)
395 IUnknown_Release(pUnk);
397 IDispatchEx_Release(dispex);
400 static int get_node_position(IXMLDOMNode *node)
405 IXMLDOMNode_AddRef(node);
408 IXMLDOMNode *new_node;
411 r = IXMLDOMNode_get_previousSibling(node, &new_node);
412 ok(SUCCEEDED(r), "get_previousSibling failed\n");
413 IXMLDOMNode_Release(node);
419 static void node_to_string(IXMLDOMNode *node, char *buf)
426 lstrcpyA(buf, "(null)");
430 IXMLDOMNode_AddRef(node);
433 IXMLDOMNode *new_node;
435 ole_check(IXMLDOMNode_get_nodeType(node, &type));
436 get_str_for_type(type, buf);
439 if (type == NODE_ATTRIBUTE)
442 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
444 wsprintfA(buf, "%ws", bstr);
449 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
453 int pos = get_node_position(node);
454 DOMNodeType parent_type = NODE_INVALID;
455 r = IXMLDOMNode_get_parentNode(node, &new_node);
457 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
458 * results we "fix" it */
460 ole_check(IXMLDOMNode_get_nodeType(new_node, &parent_type));
461 if ((parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
463 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
466 wsprintf(buf, "%d", pos);
470 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
471 IXMLDOMNode_Release(node);
480 static char *list_to_string(IXMLDOMNodeList *list)
482 static char buf[4096];
489 lstrcpyA(buf, "(null)");
492 ole_check(IXMLDOMNodeList_get_length(list, &len));
493 for (i = 0; i < len; i++)
498 ole_check(IXMLDOMNodeList_nextNode(list, &node));
499 node_to_string(node, pos);
501 IXMLDOMNode_Release(node);
507 #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); }
508 #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); }
510 static void test_domdoc( void )
513 IXMLDOMDocument *doc = NULL;
514 IXMLDOMParseError *error;
515 IXMLDOMElement *element = NULL;
517 IXMLDOMText *nodetext = NULL;
518 IXMLDOMComment *node_comment = NULL;
519 IXMLDOMAttribute *node_attr = NULL;
520 IXMLDOMNode *nodeChild = NULL;
521 IXMLDOMProcessingInstruction *nodePI = NULL;
522 ISupportErrorInfo *support_error = NULL;
529 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
530 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
534 test_disp((IUnknown*)doc);
536 /* try some stupid things */
537 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
538 ok( r == S_FALSE, "loadXML failed\n");
541 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
542 ok( r == S_FALSE, "loadXML failed\n");
543 ok( b == VARIANT_FALSE, "failed to load XML string\n");
545 /* try to load a document from a nonexistent file */
547 str = SysAllocString( szNonExistentFile );
549 V_VT(&var) = VT_BSTR;
552 r = IXMLDOMDocument_load( doc, var, &b);
553 ok( r == S_FALSE, "load (from file) failed\n");
554 ok( b == VARIANT_FALSE, "failed to load XML file\n");
555 SysFreeString( str );
557 /* try load an empty document */
559 str = SysAllocString( szEmpty );
560 r = IXMLDOMDocument_loadXML( doc, str, &b );
561 ok( r == S_FALSE, "loadXML failed\n");
562 ok( b == VARIANT_FALSE, "failed to load XML string\n");
563 SysFreeString( str );
565 r = IXMLDOMDocument_get_async( doc, &b );
566 ok( r == S_OK, "get_async failed (%08x)\n", r);
567 ok( b == VARIANT_TRUE, "Wrong default value\n");
569 /* check that there's no document element */
571 r = IXMLDOMDocument_get_documentElement( doc, &element );
572 ok( r == S_FALSE, "should be no document element\n");
574 /* try finding a node */
576 str = SysAllocString( szstr1 );
577 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
578 ok( r == S_FALSE, "ret %08x\n", r );
579 SysFreeString( str );
582 str = SysAllocString( szIncomplete );
583 r = IXMLDOMDocument_loadXML( doc, str, &b );
584 ok( r == S_FALSE, "loadXML failed\n");
585 ok( b == VARIANT_FALSE, "failed to load XML string\n");
586 SysFreeString( str );
588 /* check that there's no document element */
589 element = (IXMLDOMElement*)1;
590 r = IXMLDOMDocument_get_documentElement( doc, &element );
591 ok( r == S_FALSE, "should be no document element\n");
592 ok( element == NULL, "Element should be NULL\n");
594 /* try to load something valid */
596 str = SysAllocString( szComplete1 );
597 r = IXMLDOMDocument_loadXML( doc, str, &b );
598 ok( r == S_OK, "loadXML failed\n");
599 ok( b == VARIANT_TRUE, "failed to load XML string\n");
600 SysFreeString( str );
602 /* check if nodename is correct */
603 r = IXMLDOMDocument_get_nodeName( doc, NULL );
604 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
606 /* content doesn't matter here */
608 r = IXMLDOMDocument_get_nodeName( doc, &str );
609 ok ( r == S_OK, "get_nodeName wrong code\n");
610 ok ( str != NULL, "str is null\n");
611 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
612 SysFreeString( str );
615 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
616 ok( r == E_FAIL, "ret %08x\n", r );
618 /* check that there's a document element */
620 r = IXMLDOMDocument_get_documentElement( doc, &element );
621 ok( r == S_OK, "should be a document element\n");
624 IObjectIdentity *ident;
627 test_disp((IUnknown*)element);
629 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (LPVOID*)&ident );
630 ok( r == E_NOINTERFACE, "ret %08x\n", r);
632 /* check if the tag is correct */
633 r = IXMLDOMElement_get_tagName( element, &tag );
634 ok( r == S_OK, "couldn't get tag name\n");
635 ok( tag != NULL, "tag was null\n");
636 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
637 SysFreeString( tag );
639 /* figure out what happens if we try to reload the document */
640 str = SysAllocString( szComplete2 );
641 r = IXMLDOMDocument_loadXML( doc, str, &b );
642 ok( r == S_OK, "loadXML failed\n");
643 ok( b == VARIANT_TRUE, "failed to load XML string\n");
644 SysFreeString( str );
646 /* check if the tag is still correct */
648 r = IXMLDOMElement_get_tagName( element, &tag );
649 ok( r == S_OK, "couldn't get tag name\n");
650 ok( tag != NULL, "tag was null\n");
651 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
652 SysFreeString( tag );
654 IXMLDOMElement_Release( element );
658 /* as soon as we call loadXML again, the document element will disappear */
660 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
661 ok( r == S_FALSE, "loadXML failed\n");
662 ok( b == 2, "variant modified\n");
663 r = IXMLDOMDocument_get_documentElement( doc, &element );
664 ok( r == S_FALSE, "should be no document element\n");
666 /* try to load something else simple and valid */
668 str = SysAllocString( szComplete3 );
669 r = IXMLDOMDocument_loadXML( doc, str, &b );
670 ok( r == S_OK, "loadXML failed\n");
671 ok( b == VARIANT_TRUE, "failed to load XML string\n");
672 SysFreeString( str );
674 /* try something a little more complicated */
676 str = SysAllocString( szComplete4 );
677 r = IXMLDOMDocument_loadXML( doc, str, &b );
678 ok( r == S_OK, "loadXML failed\n");
679 ok( b == VARIANT_TRUE, "failed to load XML string\n");
680 SysFreeString( str );
682 r = IXMLDOMDocument_get_parseError( doc, &error );
683 ok( r == S_OK, "returns %08x\n", r );
685 r = IXMLDOMParseError_get_errorCode( error, &code );
686 ok( r == S_FALSE, "returns %08x\n", r );
687 ok( code == 0, "code %d\n", code );
688 IXMLDOMParseError_Release( error );
690 /* test createTextNode */
691 str = SysAllocString( szOpen );
692 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
693 ok( r == E_INVALIDARG, "returns %08x\n", r );
694 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
695 ok( r == S_OK, "returns %08x\n", r );
696 SysFreeString( str );
699 IXMLDOMNamedNodeMap *pAttribs;
701 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (LPVOID*)&element);
702 ok(r == E_NOINTERFACE, "ret %08x\n", r );
704 /* Text Last Child Checks */
705 r = IXMLDOMText_get_lastChild(nodetext, NULL);
706 ok(r == E_INVALIDARG, "ret %08x\n", r );
708 nodeChild = (IXMLDOMNode*)0x1;
709 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
710 ok(r == S_FALSE, "ret %08x\n", r );
711 ok(nodeChild == NULL, "nodeChild not NULL\n");
713 /* test get_attributes */
714 r = IXMLDOMText_get_attributes( nodetext, NULL );
715 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
717 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
718 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
719 ok(r == S_FALSE, "ret %08x\n", r );
720 ok( pAttribs == NULL, "pAttribs not NULL\n");
722 /* test get_dataType */
723 r = IXMLDOMText_get_dataType(nodetext, &var);
724 ok(r == S_FALSE, "ret %08x\n", r );
725 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
728 /* test length property */
729 r = IXMLDOMText_get_length(nodetext, NULL);
730 ok(r == E_INVALIDARG, "ret %08x\n", r );
732 r = IXMLDOMText_get_length(nodetext, &nLength);
733 ok(r == S_OK, "ret %08x\n", r );
734 ok(nLength == 4, "expected 4 got %d\n", nLength);
736 /* test nodeTypeString */
737 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
738 ok(r == S_OK, "ret %08x\n", r );
739 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
743 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
744 ok(r == S_OK, "ret %08x\n", r );
747 r = IXMLDOMText_get_data(nodetext, &str);
748 ok(r == S_OK, "ret %08x\n", r );
749 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
752 /* Confirm XML text is good */
753 r = IXMLDOMText_get_xml(nodetext, &str);
754 ok(r == S_OK, "ret %08x\n", r );
755 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
758 /* Confirm we get the put_data Text back */
759 r = IXMLDOMText_get_text(nodetext, &str);
760 ok(r == S_OK, "ret %08x\n", r );
761 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
764 /* test substringData */
765 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
766 ok(r == E_INVALIDARG, "ret %08x\n", r );
768 /* test substringData - Invalid offset */
769 str = (BSTR)&szElement;
770 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
771 ok(r == E_INVALIDARG, "ret %08x\n", r );
772 ok( str == NULL, "incorrect string\n");
774 /* test substringData - Invalid offset */
775 str = (BSTR)&szElement;
776 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
777 ok(r == S_FALSE, "ret %08x\n", r );
778 ok( str == NULL, "incorrect string\n");
780 /* test substringData - Invalid size */
781 str = (BSTR)&szElement;
782 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
783 ok(r == E_INVALIDARG, "ret %08x\n", r );
784 ok( str == NULL, "incorrect string\n");
786 /* test substringData - Invalid size */
787 str = (BSTR)&szElement;
788 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
789 ok(r == S_FALSE, "ret %08x\n", r );
790 ok( str == NULL, "incorrect string\n");
792 /* test substringData - Start of string */
793 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
794 ok(r == S_OK, "ret %08x\n", r );
795 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
798 /* test substringData - Middle of string */
799 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
800 ok(r == S_OK, "ret %08x\n", r );
801 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
804 /* test substringData - End of string */
805 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
806 ok(r == S_OK, "ret %08x\n", r );
807 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
810 /* test appendData */
811 r = IXMLDOMText_appendData(nodetext, NULL);
812 ok(r == S_OK, "ret %08x\n", r );
814 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
815 ok(r == S_OK, "ret %08x\n", r );
817 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
818 ok(r == S_OK, "ret %08x\n", r );
820 r = IXMLDOMText_get_text(nodetext, &str);
821 ok(r == S_OK, "ret %08x\n", r );
822 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
825 /* test insertData */
826 str = SysAllocStringLen(NULL, 0);
827 r = IXMLDOMText_insertData(nodetext, -1, str);
828 ok(r == S_OK, "ret %08x\n", r );
830 r = IXMLDOMText_insertData(nodetext, -1, NULL);
831 ok(r == S_OK, "ret %08x\n", r );
833 r = IXMLDOMText_insertData(nodetext, 1000, str);
834 ok(r == S_OK, "ret %08x\n", r );
836 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
837 ok(r == S_OK, "ret %08x\n", r );
839 r = IXMLDOMText_insertData(nodetext, 0, NULL);
840 ok(r == S_OK, "ret %08x\n", r );
842 r = IXMLDOMText_insertData(nodetext, 0, str);
843 ok(r == S_OK, "ret %08x\n", r );
846 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
847 ok(r == E_INVALIDARG, "ret %08x\n", r );
849 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
850 ok(r == E_INVALIDARG, "ret %08x\n", r );
852 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
853 ok(r == S_OK, "ret %08x\n", r );
855 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
856 ok(r == S_OK, "ret %08x\n", r );
858 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
859 ok(r == S_OK, "ret %08x\n", r );
861 r = IXMLDOMText_get_text(nodetext, &str);
862 ok(r == S_OK, "ret %08x\n", r );
863 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
867 V_VT(&var) = VT_BSTR;
868 V_BSTR(&var) = SysAllocString(szstr1);
869 r = IXMLDOMText_put_nodeValue(nodetext, var);
870 ok(r == S_OK, "ret %08x\n", r );
873 r = IXMLDOMText_get_text(nodetext, &str);
874 ok(r == S_OK, "ret %08x\n", r );
875 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string\n");
881 r = IXMLDOMText_put_nodeValue(nodetext, var);
882 ok(r == S_OK, "ret %08x\n", r );
885 r = IXMLDOMText_get_text(nodetext, &str);
886 ok(r == S_OK, "ret %08x\n", r );
887 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string\n");
890 IXMLDOMText_Release( nodetext );
893 /* test Create Comment */
894 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
895 ok( r == E_INVALIDARG, "returns %08x\n", r );
896 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
897 ok( r == S_OK, "returns %08x\n", r );
900 /* Last Child Checks */
901 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
902 ok(r == E_INVALIDARG, "ret %08x\n", r );
904 nodeChild = (IXMLDOMNode*)0x1;
905 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
906 ok(r == S_FALSE, "ret %08x\n", r );
907 ok(nodeChild == NULL, "pLastChild not NULL\n");
909 IXMLDOMComment_Release( node_comment );
912 /* test Create Attribute */
913 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
914 ok( r == E_INVALIDARG, "returns %08x\n", r );
915 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
916 ok( r == S_OK, "returns %08x\n", r );
917 IXMLDOMText_Release( node_attr);
919 /* test Processing Instruction */
920 str = SysAllocStringLen(NULL, 0);
921 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
922 ok( r == E_INVALIDARG, "returns %08x\n", r );
923 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
924 ok( r == E_FAIL, "returns %08x\n", r );
925 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
926 ok( r == E_FAIL, "returns %08x\n", r );
929 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
930 ok( r == S_OK, "returns %08x\n", r );
933 /* Last Child Checks */
934 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
935 ok(r == E_INVALIDARG, "ret %08x\n", r );
937 nodeChild = (IXMLDOMNode*)0x1;
938 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
939 ok(r == S_FALSE, "ret %08x\n", r );
940 ok(nodeChild == NULL, "nodeChild not NULL\n");
942 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
943 ok(r == S_FALSE, "ret %08x\n", r );
944 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
948 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
949 ok(r == S_OK, "ret %08x\n", r );
950 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
954 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
955 ok(r == S_OK, "ret %08x\n", r );
956 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
959 /* test nodeTypeString */
960 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
961 ok(r == S_OK, "ret %08x\n", r );
962 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
965 /* test get_nodeValue */
966 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
967 ok(r == S_OK, "ret %08x\n", r );
968 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
972 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
973 ok(r == S_OK, "ret %08x\n", r );
974 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
978 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
979 ok(r == E_FAIL, "ret %08x\n", r );
982 V_VT(&var) = VT_BSTR;
983 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
984 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
985 ok(r == E_FAIL, "ret %08x\n", r );
988 /* test get nodeName */
989 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
990 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
991 ok(r == S_OK, "ret %08x\n", r );
994 IXMLDOMProcessingInstruction_Release(nodePI);
997 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
998 ok( r == S_OK, "ret %08x\n", r );
1001 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
1002 todo_wine ok( r == S_OK, "ret %08x\n", r );
1003 ISupportErrorInfo_Release( support_error );
1006 r = IXMLDOMDocument_Release( doc );
1007 ok( r == 0, "document ref count incorrect\n");
1012 static void test_domnode( void )
1015 IXMLDOMDocument *doc = NULL, *owner = NULL;
1016 IXMLDOMElement *element = NULL;
1017 IXMLDOMNamedNodeMap *map = NULL;
1018 IXMLDOMNode *node = NULL, *next = NULL;
1019 IXMLDOMNodeList *list = NULL;
1020 IXMLDOMAttribute *attr = NULL;
1021 DOMNodeType type = NODE_INVALID;
1027 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1028 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1033 str = SysAllocString( szComplete4 );
1034 r = IXMLDOMDocument_loadXML( doc, str, &b );
1035 ok( r == S_OK, "loadXML failed\n");
1036 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1037 SysFreeString( str );
1042 r = IXMLDOMNode_hasChildNodes( doc, &b );
1043 ok( r == S_OK, "hasChildNoes bad return\n");
1044 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1046 r = IXMLDOMDocument_get_documentElement( doc, &element );
1047 ok( r == S_OK, "should be a document element\n");
1048 ok( element != NULL, "should be an element\n");
1051 ok( FALSE, "no document\n");
1054 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1056 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1057 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1059 r = IXMLDOMNode_get_nodeValue( doc, &var );
1060 ok( r == S_FALSE, "nextNode returned wrong code\n");
1061 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1062 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1067 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1068 ok( r == S_OK, "get_ownerDocument return code\n");
1069 ok( owner != doc, "get_ownerDocument return\n");
1071 type = NODE_INVALID;
1072 r = IXMLDOMNode_get_nodeType( element, &type);
1073 ok( r == S_OK, "getNamedItem returned wrong code\n");
1074 ok( type == NODE_ELEMENT, "node not an element\n");
1077 r = IXMLDOMNode_get_baseName( element, &str );
1078 ok( r == S_OK, "get_baseName returned wrong code\n");
1079 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1082 /* check if nodename is correct */
1083 r = IXMLDOMElement_get_nodeName( element, NULL );
1084 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1086 /* content doesn't matter here */
1088 r = IXMLDOMElement_get_nodeName( element, &str );
1089 ok ( r == S_OK, "get_nodeName wrong code\n");
1090 ok ( str != NULL, "str is null\n");
1091 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1092 SysFreeString( str );
1094 str = SysAllocString( szNonExistentFile );
1096 V_I4(&var) = 0x1234;
1097 r = IXMLDOMElement_getAttribute( element, str, &var );
1098 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1099 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1102 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1103 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1105 attr = (IXMLDOMAttribute*)0xdeadbeef;
1106 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1107 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1108 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1109 SysFreeString( str );
1111 attr = (IXMLDOMAttribute*)0xdeadbeef;
1112 str = _bstr_("nonExisitingAttribute");
1113 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1114 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1115 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1116 SysFreeString( str );
1118 str = SysAllocString( szdl );
1120 V_I4(&var) = 0x1234;
1121 r = IXMLDOMElement_getAttribute( element, str, &var );
1122 ok( r == S_OK, "getAttribute ret %08x\n", r );
1123 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1124 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1125 VariantClear( &var );
1127 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1128 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1130 r = IXMLDOMElement_getAttribute( element, str, NULL );
1131 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1134 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1135 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1136 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1138 IXMLDOMAttribute_Release(attr);
1140 SysFreeString( str );
1142 r = IXMLDOMElement_get_attributes( element, &map );
1143 ok( r == S_OK, "get_attributes returned wrong code\n");
1144 ok( map != NULL, "should be attributes\n");
1147 r = IXMLDOMNode_hasChildNodes( element, &b );
1148 ok( r == S_OK, "hasChildNoes bad return\n");
1149 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1152 ok( FALSE, "no element\n");
1156 ISupportErrorInfo *support_error;
1157 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1158 ok( r == S_OK, "ret %08x\n", r );
1160 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1163 ok( r == S_OK, "ret %08x\n", r );
1165 ISupportErrorInfo_Release( support_error );
1167 str = SysAllocString( szdl );
1168 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1169 ok( r == S_OK, "getNamedItem returned wrong code\n");
1170 ok( node != NULL, "should be attributes\n");
1171 IXMLDOMNode_Release(node);
1172 SysFreeString( str );
1174 str = SysAllocString( szdl );
1175 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1176 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1177 SysFreeString( str );
1179 /* something that isn't in szComplete4 */
1180 str = SysAllocString( szOpen );
1181 node = (IXMLDOMNode *) 1;
1182 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1183 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1184 ok( node == NULL, "getNamedItem should have returned NULL\n");
1185 SysFreeString( str );
1187 /* test indexed access of attributes */
1188 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1189 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1191 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1192 ok ( r == S_OK, "get_length wrong code\n");
1193 ok ( count == 1, "get_length != 1\n");
1196 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1197 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1198 ok ( node == NULL, "there is no node\n");
1201 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1202 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1203 ok ( node == NULL, "there is no attribute\n");
1206 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1207 ok ( r == S_OK, "get_item (0) wrong code\n");
1208 ok ( node != NULL, "should be attribute\n");
1210 r = IXMLDOMNode_get_nodeName( node, NULL );
1211 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1213 /* content doesn't matter here */
1215 r = IXMLDOMNode_get_nodeName( node, &str );
1216 ok ( r == S_OK, "get_nodeName wrong code\n");
1217 ok ( str != NULL, "str is null\n");
1218 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1219 SysFreeString( str );
1221 /* test sequential access of attributes */
1223 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1224 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1225 ok ( node != NULL, "nextNode, should be attribute\n");
1227 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1228 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1229 ok ( node == NULL, "nextNode, there is no attribute\n");
1231 r = IXMLDOMNamedNodeMap_reset( map );
1232 ok ( r == S_OK, "reset should return S_OK\n");
1234 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1235 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1236 ok ( node != NULL, "nextNode, should be attribute\n");
1239 ok( FALSE, "no map\n");
1243 type = NODE_INVALID;
1244 r = IXMLDOMNode_get_nodeType( node, &type);
1245 ok( r == S_OK, "getNamedItem returned wrong code\n");
1246 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1249 r = IXMLDOMNode_get_baseName( node, NULL );
1250 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1253 r = IXMLDOMNode_get_baseName( node, &str );
1254 ok( r == S_OK, "get_baseName returned wrong code\n");
1255 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1256 SysFreeString( str );
1258 r = IXMLDOMNode_get_nodeValue( node, &var );
1259 ok( r == S_OK, "returns %08x\n", r );
1260 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1261 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1264 r = IXMLDOMNode_get_childNodes( node, NULL );
1265 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1267 r = IXMLDOMNode_get_childNodes( node, &list );
1268 ok( r == S_OK, "get_childNodes returned wrong code\n");
1272 r = IXMLDOMNodeList_nextNode( list, &next );
1273 ok( r == S_OK, "nextNode returned wrong code\n");
1276 ok( FALSE, "no childlist\n");
1281 r = IXMLDOMNode_hasChildNodes( next, &b );
1282 ok( r == S_FALSE, "hasChildNoes bad return\n");
1283 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1285 type = NODE_INVALID;
1286 r = IXMLDOMNode_get_nodeType( next, &type);
1287 ok( r == S_OK, "getNamedItem returned wrong code\n");
1288 ok( type == NODE_TEXT, "node not text\n");
1291 r = IXMLDOMNode_get_baseName( next, &str );
1292 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1293 ok( str == NULL, "basename was wrong\n");
1297 ok( FALSE, "no next\n");
1300 IXMLDOMNode_Release( next );
1303 IXMLDOMNodeList_Release( list );
1306 IXMLDOMNode_Release( node );
1309 ok( FALSE, "no node\n");
1313 IXMLDOMNamedNodeMap_Release( map );
1315 /* now traverse the tree from the root element */
1319 r = IXMLDOMNode_get_childNodes( element, &list );
1320 ok( r == S_OK, "get_childNodes returned wrong code\n");
1322 /* using get_item for child list doesn't advance the position */
1323 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1324 expect_node(node, "E2.E2.D1");
1325 IXMLDOMNode_Release(node);
1326 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1327 expect_node(node, "E1.E2.D1");
1328 IXMLDOMNode_Release(node);
1329 ole_check(IXMLDOMNodeList_reset(list));
1331 IXMLDOMNodeList_AddRef(list);
1332 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1333 ole_check(IXMLDOMNodeList_reset(list));
1336 ok( FALSE, "no element\n");
1338 node = (void*)0xdeadbeef;
1339 r = IXMLDOMNode_selectSingleNode( element, szdl, &node );
1340 ok( r == S_FALSE, "ret %08x\n", r );
1341 ok( node == NULL, "node %p\n", node );
1342 r = IXMLDOMNode_selectSingleNode( element, szbs, &node );
1343 ok( r == S_OK, "ret %08x\n", r );
1344 r = IXMLDOMNode_Release( node );
1345 ok( r == 0, "ret %08x\n", r );
1349 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1350 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1352 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1353 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1355 r = IXMLDOMNodeList_get_length(list, NULL);
1356 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1358 r = IXMLDOMNodeList_get_length( list, &count );
1359 ok( r == S_OK, "get_length returns %08x\n", r );
1360 ok( count == 4, "get_length got %d\n", count );
1362 r = IXMLDOMNodeList_nextNode(list, NULL);
1363 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1365 r = IXMLDOMNodeList_nextNode( list, &node );
1366 ok( r == S_OK, "nextNode returned wrong code\n");
1369 ok( FALSE, "no list\n");
1373 type = NODE_INVALID;
1374 r = IXMLDOMNode_get_nodeType( node, &type);
1375 ok( r == S_OK, "getNamedItem returned wrong code\n");
1376 ok( type == NODE_ELEMENT, "node not text\n");
1379 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1380 r = IXMLDOMNode_get_nodeValue( node, &var );
1381 ok( r == S_FALSE, "nextNode returned wrong code\n");
1382 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1383 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1385 r = IXMLDOMNode_hasChildNodes( node, NULL );
1386 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1389 r = IXMLDOMNode_hasChildNodes( node, &b );
1390 ok( r == S_OK, "hasChildNoes bad return\n");
1391 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1394 r = IXMLDOMNode_get_baseName( node, &str );
1395 ok( r == S_OK, "get_baseName returned wrong code\n");
1396 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1400 ok( FALSE, "no node\n");
1403 IXMLDOMNode_Release( node );
1405 IXMLDOMNodeList_Release( list );
1407 IXMLDOMElement_Release( element );
1410 str = SysAllocString( szComplete5 );
1411 r = IXMLDOMDocument_loadXML( doc, str, &b );
1412 ok( r == S_OK, "loadXML failed\n");
1413 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1414 SysFreeString( str );
1417 r = IXMLDOMNode_hasChildNodes( doc, &b );
1418 ok( r == S_OK, "hasChildNoes bad return\n");
1419 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1421 r = IXMLDOMDocument_get_documentElement( doc, &element );
1422 ok( r == S_OK, "should be a document element\n");
1423 ok( element != NULL, "should be an element\n");
1427 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1430 /* check if the tag is correct */
1431 r = IXMLDOMElement_get_tagName( element, &tag );
1432 ok( r == S_OK, "couldn't get tag name\n");
1433 ok( tag != NULL, "tag was null\n");
1434 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1435 SysFreeString( tag );
1439 IXMLDOMElement_Release( element );
1441 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1444 static void test_refs(void)
1449 IXMLDOMDocument *doc = NULL;
1450 IXMLDOMElement *element = NULL;
1451 IXMLDOMNode *node = NULL, *node2;
1452 IXMLDOMNodeList *node_list = NULL;
1454 IUnknown *unk, *unk2;
1456 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1457 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1460 ref = IXMLDOMDocument_Release(doc);
1461 ok( ref == 0, "ref %d\n", ref);
1463 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1464 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1468 str = SysAllocString( szComplete4 );
1469 r = IXMLDOMDocument_loadXML( doc, str, &b );
1470 ok( r == S_OK, "loadXML failed\n");
1471 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1472 SysFreeString( str );
1474 ref = IXMLDOMDocument_AddRef( doc );
1475 ok( ref == 2, "ref %d\n", ref );
1476 ref = IXMLDOMDocument_AddRef( doc );
1477 ok( ref == 3, "ref %d\n", ref );
1478 IXMLDOMDocument_Release( doc );
1479 IXMLDOMDocument_Release( doc );
1481 r = IXMLDOMDocument_get_documentElement( doc, &element );
1482 ok( r == S_OK, "should be a document element\n");
1483 ok( element != NULL, "should be an element\n");
1485 ref = IXMLDOMDocument_AddRef( doc );
1486 ok( ref == 2, "ref %d\n", ref );
1487 IXMLDOMDocument_Release( doc );
1489 r = IXMLDOMElement_get_childNodes( element, &node_list );
1490 ok( r == S_OK, "rets %08x\n", r);
1492 ref = IXMLDOMNodeList_AddRef( node_list );
1493 ok( ref == 2, "ref %d\n", ref );
1494 IXMLDOMNodeList_Release( node_list );
1496 IXMLDOMNodeList_get_item( node_list, 0, &node );
1497 ok( r == S_OK, "rets %08x\n", r);
1499 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1500 ok( r == S_OK, "rets %08x\n", r);
1502 ref = IXMLDOMNode_AddRef( node );
1503 ok( ref == 2, "ref %d\n", ref );
1504 IXMLDOMNode_Release( node );
1506 ref = IXMLDOMNode_Release( node );
1507 ok( ref == 0, "ref %d\n", ref );
1508 ref = IXMLDOMNode_Release( node2 );
1509 ok( ref == 0, "ref %d\n", ref );
1511 ref = IXMLDOMNodeList_Release( node_list );
1512 ok( ref == 0, "ref %d\n", ref );
1514 ok( node != node2, "node %p node2 %p\n", node, node2 );
1516 ref = IXMLDOMDocument_Release( doc );
1517 ok( ref == 0, "ref %d\n", ref );
1519 ref = IXMLDOMElement_AddRef( element );
1521 ok( ref == 3, "ref %d\n", ref );
1523 IXMLDOMElement_Release( element );
1525 /* IUnknown must be unique however we obtain it */
1526 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1527 ok( r == S_OK, "rets %08x\n", r );
1528 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1529 ok( r == S_OK, "rets %08x\n", r );
1530 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1531 ok( r == S_OK, "rets %08x\n", r );
1532 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1534 IUnknown_Release( unk2 );
1535 IUnknown_Release( unk );
1536 IXMLDOMNode_Release( node );
1538 IXMLDOMElement_Release( element );
1542 static void test_create(void)
1544 static const WCHAR szOne[] = {'1',0};
1545 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1549 IXMLDOMDocument *doc;
1550 IXMLDOMElement *element;
1551 IXMLDOMNode *root, *node, *child;
1552 IXMLDOMNamedNodeMap *attr_map;
1557 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1558 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1563 V_I1(&var) = NODE_ELEMENT;
1564 str = SysAllocString( szlc );
1565 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1566 ok( r == S_OK, "returns %08x\n", r );
1567 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1570 V_R4(&var) = NODE_ELEMENT;
1571 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1572 ok( r == S_OK, "returns %08x\n", r );
1573 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1575 V_VT(&var) = VT_BSTR;
1576 V_BSTR(&var) = SysAllocString( szOne );
1577 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1578 ok( r == S_OK, "returns %08x\n", r );
1579 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1582 V_VT(&var) = VT_BSTR;
1583 V_BSTR(&var) = SysAllocString( szOneGarbage );
1584 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1585 ok( r == E_INVALIDARG, "returns %08x\n", r );
1586 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1590 V_I4(&var) = NODE_ELEMENT;
1591 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1592 ok( r == S_OK, "returns %08x\n", r );
1593 r = IXMLDOMDocument_appendChild( doc, node, &root );
1594 ok( r == S_OK, "returns %08x\n", r );
1595 ok( node == root, "%p %p\n", node, root );
1597 ref = IXMLDOMNode_AddRef( node );
1598 ok(ref == 3, "ref %d\n", ref);
1599 IXMLDOMNode_Release( node );
1601 ref = IXMLDOMNode_Release( node );
1602 ok(ref == 1, "ref %d\n", ref);
1603 SysFreeString( str );
1606 V_I4(&var) = NODE_ELEMENT;
1607 str = SysAllocString( szbs );
1608 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1609 ok( r == S_OK, "returns %08x\n", r );
1610 SysFreeString( str );
1612 ref = IXMLDOMNode_AddRef( node );
1613 ok(ref == 2, "ref = %d\n", ref);
1614 IXMLDOMNode_Release( node );
1616 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1617 ok( r == S_OK, "returns %08x\n", r );
1619 ref = IXMLDOMNode_AddRef( unk );
1620 ok(ref == 3, "ref = %d\n", ref);
1621 IXMLDOMNode_Release( unk );
1623 V_VT(&var) = VT_EMPTY;
1624 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1625 ok( r == S_OK, "returns %08x\n", r );
1626 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1627 IXMLDOMNode_Release( child );
1628 IUnknown_Release( unk );
1631 V_VT(&var) = VT_NULL;
1632 V_DISPATCH(&var) = (IDispatch*)node;
1633 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1634 ok( r == S_OK, "returns %08x\n", r );
1635 ok( node == child, "%p %p\n", node, child );
1636 IXMLDOMNode_Release( child );
1639 V_VT(&var) = VT_NULL;
1640 V_DISPATCH(&var) = (IDispatch*)node;
1641 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1642 ok( r == S_OK, "returns %08x\n", r );
1643 IXMLDOMNode_Release( node );
1645 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1646 ok( r == S_OK, "returns %08x\n", r );
1648 r = IXMLDOMElement_get_attributes( element, &attr_map );
1649 ok( r == S_OK, "returns %08x\n", r );
1650 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1651 ok( r == S_OK, "returns %08x\n", r );
1652 ok( num == 0, "num %d\n", num );
1653 IXMLDOMNamedNodeMap_Release( attr_map );
1655 V_VT(&var) = VT_BSTR;
1656 V_BSTR(&var) = SysAllocString( szstr1 );
1657 name = SysAllocString( szdl );
1658 r = IXMLDOMElement_setAttribute( element, name, var );
1659 ok( r == S_OK, "returns %08x\n", r );
1660 r = IXMLDOMElement_get_attributes( element, &attr_map );
1661 ok( r == S_OK, "returns %08x\n", r );
1662 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1663 ok( r == S_OK, "returns %08x\n", r );
1664 ok( num == 1, "num %d\n", num );
1665 IXMLDOMNamedNodeMap_Release( attr_map );
1668 V_VT(&var) = VT_BSTR;
1669 V_BSTR(&var) = SysAllocString( szstr2 );
1670 r = IXMLDOMElement_setAttribute( element, name, var );
1671 ok( r == S_OK, "returns %08x\n", r );
1672 r = IXMLDOMElement_get_attributes( element, &attr_map );
1673 ok( r == S_OK, "returns %08x\n", r );
1674 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1675 ok( r == S_OK, "returns %08x\n", r );
1676 ok( num == 1, "num %d\n", num );
1677 IXMLDOMNamedNodeMap_Release( attr_map );
1679 r = IXMLDOMElement_getAttribute( element, name, &var );
1680 ok( r == S_OK, "returns %08x\n", r );
1681 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1683 SysFreeString(name);
1685 V_VT(&var) = VT_BSTR;
1686 V_BSTR(&var) = SysAllocString( szstr1 );
1687 name = SysAllocString( szlc );
1688 r = IXMLDOMElement_setAttribute( element, name, var );
1689 ok( r == S_OK, "returns %08x\n", r );
1690 r = IXMLDOMElement_get_attributes( element, &attr_map );
1691 ok( r == S_OK, "returns %08x\n", r );
1692 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1693 ok( r == S_OK, "returns %08x\n", r );
1694 ok( num == 2, "num %d\n", num );
1695 IXMLDOMNamedNodeMap_Release( attr_map );
1697 SysFreeString(name);
1701 name = SysAllocString( szbs );
1702 r = IXMLDOMElement_setAttribute( element, name, var );
1703 ok( r == S_OK, "returns %08x\n", r );
1705 r = IXMLDOMElement_getAttribute( element, name, &var );
1706 ok( r == S_OK, "returns %08x\n", r );
1707 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1709 SysFreeString(name);
1711 /* Create an Attribute */
1713 V_I4(&var) = NODE_ATTRIBUTE;
1714 str = SysAllocString( szAttribute );
1715 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1716 ok( r == S_OK, "returns %08x\n", r );
1717 ok( node != NULL, "node was null\n");
1722 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1723 ok( r == S_OK, "returns %08x\n", r );
1724 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1726 IXMLDOMNode_Release( node );
1729 IXMLDOMElement_Release( element );
1730 IXMLDOMNode_Release( root );
1731 IXMLDOMDocument_Release( doc );
1734 static void test_getElementsByTagName(void)
1739 IXMLDOMDocument *doc;
1740 IXMLDOMNodeList *node_list;
1743 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1744 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1748 str = SysAllocString( szComplete4 );
1749 r = IXMLDOMDocument_loadXML( doc, str, &b );
1750 ok( r == S_OK, "loadXML failed\n");
1751 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1752 SysFreeString( str );
1754 str = SysAllocString( szstar );
1755 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1756 ok( r == S_OK, "ret %08x\n", r );
1757 r = IXMLDOMNodeList_get_length( node_list, &len );
1758 ok( r == S_OK, "ret %08x\n", r );
1759 ok( len == 6, "len %d\n", len );
1761 test_disp((IUnknown*)node_list);
1763 IXMLDOMNodeList_Release( node_list );
1764 SysFreeString( str );
1766 str = SysAllocString( szbs );
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 == 1, "len %d\n", len );
1772 IXMLDOMNodeList_Release( node_list );
1773 SysFreeString( str );
1775 str = SysAllocString( szdl );
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 str = SysAllocString( szstr1 );
1785 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1786 ok( r == S_OK, "ret %08x\n", r );
1787 r = IXMLDOMNodeList_get_length( node_list, &len );
1788 ok( r == S_OK, "ret %08x\n", r );
1789 ok( len == 0, "len %d\n", len );
1790 IXMLDOMNodeList_Release( node_list );
1791 SysFreeString( str );
1793 IXMLDOMDocument_Release( doc );
1796 static void test_get_text(void)
1801 IXMLDOMDocument *doc;
1802 IXMLDOMNode *node, *node2, *node3;
1803 IXMLDOMNode *nodeRoot;
1804 IXMLDOMNodeList *node_list;
1805 IXMLDOMNamedNodeMap *node_map;
1808 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1809 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1813 str = SysAllocString( szComplete4 );
1814 r = IXMLDOMDocument_loadXML( doc, str, &b );
1815 ok( r == S_OK, "loadXML failed\n");
1816 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1817 SysFreeString( str );
1819 str = SysAllocString( szbs );
1820 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1821 ok( r == S_OK, "ret %08x\n", r );
1824 /* Test to get all child node text. */
1825 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (LPVOID*)&nodeRoot);
1826 ok( r == S_OK, "ret %08x\n", r );
1829 r = IXMLDOMNode_get_text( nodeRoot, &str );
1830 ok( r == S_OK, "ret %08x\n", r );
1831 ok( compareIgnoreReturnsWhitespace(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text\n");
1834 IXMLDOMNode_Release(nodeRoot);
1838 /* this test crashes on win9x */
1839 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1840 ok( r == E_INVALIDARG, "ret %08x\n", r );
1843 r = IXMLDOMNodeList_get_length( node_list, NULL );
1844 ok( r == E_INVALIDARG, "ret %08x\n", r );
1846 r = IXMLDOMNodeList_get_length( node_list, &len );
1847 ok( r == S_OK, "ret %08x\n", r );
1848 ok( len == 1, "expect 1 got %d\n", len );
1850 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1851 ok( r == E_INVALIDARG, "ret %08x\n", r );
1853 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1854 ok( r == E_INVALIDARG, "ret %08x\n", r );
1856 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1857 ok( r == S_OK, "ret %08x\n", r );
1858 IXMLDOMNodeList_Release( node_list );
1860 /* Invalid output parameter*/
1861 r = IXMLDOMNode_get_text( node, NULL );
1862 ok( r == E_INVALIDARG, "ret %08x\n", r );
1864 r = IXMLDOMNode_get_text( node, &str );
1865 ok( r == S_OK, "ret %08x\n", r );
1866 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1869 r = IXMLDOMNode_get_attributes( node, &node_map );
1870 ok( r == S_OK, "ret %08x\n", r );
1872 str = SysAllocString( szvr );
1873 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1874 ok( r == S_OK, "ret %08x\n", r );
1877 r = IXMLDOMNode_get_text( node2, &str );
1878 ok( r == S_OK, "ret %08x\n", r );
1879 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1882 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1883 ok( r == S_OK, "ret %08x\n", r );
1885 r = IXMLDOMNode_get_text( node3, &str );
1886 ok( r == S_OK, "ret %08x\n", r );
1887 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1891 IXMLDOMNode_Release( node3 );
1892 IXMLDOMNode_Release( node2 );
1893 IXMLDOMNamedNodeMap_Release( node_map );
1894 IXMLDOMNode_Release( node );
1895 IXMLDOMDocument_Release( doc );
1898 static void test_get_childNodes(void)
1903 IXMLDOMDocument *doc;
1904 IXMLDOMElement *element;
1905 IXMLDOMNode *node, *node2;
1906 IXMLDOMNodeList *node_list, *node_list2;
1909 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1910 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1914 str = SysAllocString( szComplete4 );
1915 r = IXMLDOMDocument_loadXML( doc, str, &b );
1916 ok( r == S_OK, "loadXML failed\n");
1917 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1918 SysFreeString( str );
1920 r = IXMLDOMDocument_get_documentElement( doc, &element );
1921 ok( r == S_OK, "ret %08x\n", r);
1923 r = IXMLDOMElement_get_childNodes( element, &node_list );
1924 ok( r == S_OK, "ret %08x\n", r);
1926 r = IXMLDOMNodeList_get_length( node_list, &len );
1927 ok( r == S_OK, "ret %08x\n", r);
1928 ok( len == 4, "len %d\n", len);
1930 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1931 ok( r == S_OK, "ret %08x\n", r);
1933 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1934 ok( r == S_OK, "ret %08x\n", r);
1936 r = IXMLDOMNodeList_get_length( node_list2, &len );
1937 ok( r == S_OK, "ret %08x\n", r);
1938 ok( len == 0, "len %d\n", len);
1940 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1941 ok( r == S_FALSE, "ret %08x\n", r);
1943 IXMLDOMNodeList_Release( node_list2 );
1944 IXMLDOMNode_Release( node );
1945 IXMLDOMNodeList_Release( node_list );
1946 IXMLDOMElement_Release( element );
1947 IXMLDOMDocument_Release( doc );
1950 static void test_removeChild(void)
1955 IXMLDOMDocument *doc;
1956 IXMLDOMElement *element, *lc_element;
1957 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
1958 IXMLDOMNodeList *root_list, *fo_list;
1960 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1961 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1965 str = SysAllocString( szComplete4 );
1966 r = IXMLDOMDocument_loadXML( doc, str, &b );
1967 ok( r == S_OK, "loadXML failed\n");
1968 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1969 SysFreeString( str );
1971 r = IXMLDOMDocument_get_documentElement( doc, &element );
1972 ok( r == S_OK, "ret %08x\n", r);
1974 r = IXMLDOMElement_get_childNodes( element, &root_list );
1975 ok( r == S_OK, "ret %08x\n", r);
1977 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1978 ok( r == S_OK, "ret %08x\n", r);
1980 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1981 ok( r == S_OK, "ret %08x\n", r);
1983 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1984 ok( r == S_OK, "ret %08x\n", r);
1986 /* invalid parameter: NULL ptr */
1987 removed_node = (void*)0xdeadbeef;
1988 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
1989 ok( r == E_INVALIDARG, "ret %08x\n", r );
1990 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1992 /* ba_node is a descendant of element, but not a direct child. */
1993 removed_node = (void*)0xdeadbeef;
1994 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
1995 ok( r == E_INVALIDARG, "ret %08x\n", r );
1996 ok( removed_node == NULL, "%p\n", removed_node );
1998 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
1999 ok( r == S_OK, "ret %08x\n", r);
2000 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
2002 /* try removing already removed child */
2003 temp_node = (void*)0xdeadbeef;
2004 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
2005 ok( r == E_INVALIDARG, "ret %08x\n", r);
2006 ok( temp_node == NULL, "%p\n", temp_node );
2008 /* the removed node has no parent anymore */
2009 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
2010 ok( r == S_FALSE, "ret %08x\n", r);
2011 ok( temp_node == NULL, "%p\n", temp_node );
2013 IXMLDOMNode_Release( removed_node );
2014 IXMLDOMNode_Release( ba_node );
2015 IXMLDOMNodeList_Release( fo_list );
2017 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2018 ok( r == S_OK, "ret %08x\n", r);
2020 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (LPVOID*)&lc_element );
2021 ok( r == S_OK, "ret %08x\n", r);
2023 /* MS quirk: passing wrong interface pointer works, too */
2024 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
2025 ok( r == S_OK, "ret %08x\n", r);
2027 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
2028 ok( r == S_FALSE, "ret %08x\n", r);
2029 ok( temp_node == NULL, "%p\n", temp_node );
2031 IXMLDOMNode_Release( lc_node );
2032 IXMLDOMNodeList_Release( root_list );
2033 IXMLDOMElement_Release( element );
2034 IXMLDOMDocument_Release( doc );
2037 static void test_replaceChild(void)
2042 IXMLDOMDocument *doc;
2043 IXMLDOMElement *element, *ba_element;
2044 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
2045 IXMLDOMNodeList *root_list, *fo_list;
2046 IUnknown * unk1, *unk2;
2049 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2050 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2054 str = SysAllocString( szComplete4 );
2055 r = IXMLDOMDocument_loadXML( doc, str, &b );
2056 ok( r == S_OK, "loadXML failed\n");
2057 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2058 SysFreeString( str );
2060 r = IXMLDOMDocument_get_documentElement( doc, &element );
2061 ok( r == S_OK, "ret %08x\n", r);
2063 r = IXMLDOMElement_get_childNodes( element, &root_list );
2064 ok( r == S_OK, "ret %08x\n", r);
2066 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2067 ok( r == S_OK, "ret %08x\n", r);
2069 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2070 ok( r == S_OK, "ret %08x\n", r);
2072 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2073 ok( r == S_OK, "ret %08x\n", r);
2075 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2076 ok( r == S_OK, "ret %08x\n", r);
2078 IXMLDOMNodeList_Release( fo_list );
2080 /* invalid parameter: NULL ptr for element to remove */
2081 removed_node = (void*)0xdeadbeef;
2082 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
2083 ok( r == E_INVALIDARG, "ret %08x\n", r );
2084 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2086 /* invalid parameter: NULL for replacement element. (Sic!) */
2087 removed_node = (void*)0xdeadbeef;
2088 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
2089 ok( r == E_INVALIDARG, "ret %08x\n", r );
2090 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2092 /* invalid parameter: OldNode is not a child */
2093 removed_node = (void*)0xdeadbeef;
2094 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
2095 ok( r == E_INVALIDARG, "ret %08x\n", r );
2096 ok( removed_node == NULL, "%p\n", removed_node );
2098 /* invalid parameter: would create loop */
2099 removed_node = (void*)0xdeadbeef;
2100 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
2101 ok( r == E_FAIL, "ret %08x\n", r );
2102 ok( removed_node == NULL, "%p\n", removed_node );
2104 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
2105 ok( r == S_OK, "ret %08x\n", r );
2107 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
2108 ok( r == S_OK, "ret %08x\n", r );
2110 /* ba_node and temp_node refer to the same node, yet they
2111 are different interface pointers */
2112 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
2113 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
2114 ok( r == S_OK, "ret %08x\n", r );
2115 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
2116 ok( r == S_OK, "ret %08x\n", r );
2117 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
2119 IUnknown_Release( unk1 );
2120 IUnknown_Release( unk2 );
2122 /* ba_node should have been removed from below fo_node */
2123 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2124 ok( r == S_OK, "ret %08x\n", r );
2126 /* MS quirk: replaceChild also accepts elements instead of nodes */
2127 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
2128 ok( r == S_OK, "ret %08x\n", r );
2130 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
2131 ok( r == S_OK, "ret %08x\n", r );
2133 r = IXMLDOMNodeList_get_length( fo_list, &len);
2134 ok( r == S_OK, "ret %08x\n", r );
2135 ok( len == 0, "len %d\n", len);
2137 IXMLDOMNodeList_Release( fo_list );
2139 IXMLDOMNode_Release(ba_node);
2140 IXMLDOMNode_Release(fo_node);
2141 IXMLDOMNode_Release(temp_node);
2142 IXMLDOMNodeList_Release( root_list );
2143 IXMLDOMElement_Release( element );
2144 IXMLDOMDocument_Release( doc );
2147 static void test_removeNamedItem(void)
2149 IXMLDOMDocument *doc;
2150 IXMLDOMElement *element;
2151 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
2152 IXMLDOMNodeList *root_list;
2153 IXMLDOMNamedNodeMap * pr_attrs;
2159 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2160 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2164 str = SysAllocString( szComplete4 );
2165 r = IXMLDOMDocument_loadXML( doc, str, &b );
2166 ok( r == S_OK, "loadXML failed\n");
2167 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2168 SysFreeString( str );
2170 r = IXMLDOMDocument_get_documentElement( doc, &element );
2171 ok( r == S_OK, "ret %08x\n", r);
2173 r = IXMLDOMElement_get_childNodes( element, &root_list );
2174 ok( r == S_OK, "ret %08x\n", r);
2176 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2177 ok( r == S_OK, "ret %08x\n", r);
2179 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2180 ok( r == S_OK, "ret %08x\n", r);
2182 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2183 ok( r == S_OK, "ret %08x\n", r);
2184 ok( len == 3, "length %d\n", len);
2186 removed_node = (void*)0xdeadbeef;
2187 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2188 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2189 ok ( removed_node == (void*)0xdeadbeef, "removed_node == %p\n", removed_node);
2191 removed_node = (void*)0xdeadbeef;
2192 str = SysAllocString(szvr);
2193 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2194 ok ( r == S_OK, "ret %08x\n", r);
2196 removed_node2 = (void*)0xdeadbeef;
2197 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2198 ok ( r == S_FALSE, "ret %08x\n", r);
2199 ok ( removed_node2 == NULL, "removed_node == %p\n", removed_node2 );
2201 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2202 ok( r == S_OK, "ret %08x\n", r);
2203 ok( len == 2, "length %d\n", len);
2205 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2206 ok ( r == S_OK, "ret %08x\n", r);
2207 IXMLDOMNode_Release(removed_node);
2209 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2210 ok( r == S_OK, "ret %08x\n", r);
2211 ok( len == 3, "length %d\n", len);
2213 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2214 ok ( r == S_OK, "ret %08x\n", r);
2216 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2217 ok( r == S_OK, "ret %08x\n", r);
2218 ok( len == 2, "length %d\n", len);
2220 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2221 ok ( r == S_FALSE, "ret %08x\n", r);
2225 IXMLDOMNamedNodeMap_Release( pr_attrs );
2226 IXMLDOMNode_Release( pr_node );
2227 IXMLDOMNodeList_Release( root_list );
2228 IXMLDOMElement_Release( element );
2229 IXMLDOMDocument_Release( doc );
2232 static void test_XMLHTTP(void)
2234 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2235 static WCHAR wszPOST[] = {'P','O','S','T',0};
2236 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2237 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2238 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2239 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2240 IXMLHttpRequest *pXMLHttpRequest;
2245 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2246 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2247 (void **)&pXMLHttpRequest);
2248 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
2252 VariantInit(&dummy);
2253 V_VT(&dummy) = VT_ERROR;
2254 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2255 VariantInit(&varfalse);
2256 V_VT(&varfalse) = VT_BOOL;
2257 V_BOOL(&varfalse) = VARIANT_FALSE;
2258 V_VT(&varbody) = VT_BSTR;
2259 V_BSTR(&varbody) = SysAllocString(wszBody);
2261 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
2262 todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
2264 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2265 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2266 VariantClear(&varbody);
2268 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2269 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2270 /* the server currently returns "FAILED" because the Content-Type header is
2271 * not what the server expects */
2274 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2275 SysFreeString(bstrResponse);
2278 IXMLHttpRequest_Release(pXMLHttpRequest);
2281 static void test_IXMLDOMDocument2(void)
2286 IXMLDOMDocument *doc;
2287 IXMLDOMDocument2 *doc2;
2288 IDispatchEx *dispex;
2292 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2293 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2297 str = SysAllocString( szComplete4 );
2298 r = IXMLDOMDocument_loadXML( doc, str, &b );
2299 ok( r == S_OK, "loadXML failed\n");
2300 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2301 SysFreeString( str );
2303 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
2304 ok( r == S_OK, "ret %08x\n", r );
2305 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
2307 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
2308 ok( r == S_OK, "ret %08x\n", r );
2311 IDispatchEx_Release(dispex);
2314 /* we will check if the variant got cleared */
2315 ref = IXMLDOMDocument2_AddRef(doc2);
2316 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
2317 V_VT(&var) = VT_UNKNOWN;
2318 V_UNKNOWN(&var) = (IUnknown *)doc2;
2321 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
2322 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
2323 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
2326 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2327 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2328 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2331 /* the variant didn't get cleared*/
2332 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
2334 /* setProperty tests */
2335 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
2336 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
2337 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
2338 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2339 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2340 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2342 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
2343 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2344 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2345 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2347 IXMLDOMDocument2_Release( doc2 );
2348 IXMLDOMDocument_Release( doc );
2352 static void test_XPath(void)
2357 IXMLDOMDocument2 *doc;
2358 IXMLDOMNode *rootNode;
2359 IXMLDOMNode *elem1Node;
2361 IXMLDOMNodeList *list;
2363 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2364 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2368 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
2369 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2371 /* switch to XPath */
2372 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2374 /* some simple queries*/
2375 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
2376 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
2377 ole_check(IXMLDOMNodeList_reset(list));
2378 expect_list_and_release(list, "E2.D1");
2379 if (rootNode == NULL)
2382 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
2383 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
2385 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
2386 expect_list_and_release(list, "E3.E2.E2.D1");
2388 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
2389 /* using get_item for query results advances the position */
2390 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2391 expect_node(node, "E2.E2.D1");
2392 IXMLDOMNode_Release(node);
2393 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2394 expect_node(node, "E4.E2.D1");
2395 IXMLDOMNode_Release(node);
2396 ole_check(IXMLDOMNodeList_reset(list));
2397 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2399 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2400 expect_list_and_release(list, "E2.D1");
2402 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2403 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2404 ole_check(IXMLDOMNodeList_reset(list));
2405 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2407 /* select an attribute */
2408 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2409 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2411 /* would evaluate to a number */
2412 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2413 /* would evaluate to a boolean */
2414 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2415 /* would evaluate to a string */
2416 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2419 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2420 expect_list_and_release(list, "");
2421 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2422 expect_list_and_release(list, "");
2423 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2424 expect_list_and_release(list, "");
2426 /* foo undeclared in document node */
2427 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2428 /* undeclared in <root> node */
2429 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2430 /* undeclared in <elem> node */
2431 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2432 /* but this trick can be used */
2433 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2434 expect_list_and_release(list, "E3.E4.E2.D1");
2436 /* it has to be declared in SelectionNamespaces */
2437 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2438 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2440 /* now the namespace can be used */
2441 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//test:c"), &list));
2442 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2443 todo_wine ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//test:c"), &list));
2444 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2445 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//test:c"), &list));
2446 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2447 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2448 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2450 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2451 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2452 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2454 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2457 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2458 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2459 if (V_VT(&var) == VT_BSTR)
2460 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2462 /* extra attributes - same thing*/
2463 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2464 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2465 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2467 IXMLDOMNode_Release(rootNode);
2468 IXMLDOMNode_Release(elem1Node);
2469 IXMLDOMDocument_Release(doc);
2473 static void test_cloneNode(void )
2475 IXMLDOMDocument *doc = NULL;
2477 IXMLDOMNodeList *pList;
2478 IXMLDOMNamedNodeMap *mapAttr;
2479 LONG nLength = 0, nLength1 = 0;
2480 LONG nAttrCnt = 0, nAttrCnt1 = 0;
2482 IXMLDOMNode *node_clone;
2483 IXMLDOMNode *node_first;
2486 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2488 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2492 str = SysAllocString( szComplete4 );
2493 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2494 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2500 str = SysAllocString( szSearch);
2501 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2502 ok( r == S_OK, "ret %08x\n", r );
2503 ok( node != NULL, "node %p\n", node );
2508 IXMLDOMDocument_Release(doc);
2512 /* Check invalid parameter */
2513 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2514 ok( r == E_INVALIDARG, "ret %08x\n", r );
2517 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2518 ok( r == S_OK, "ret %08x\n", r );
2519 ok( node_clone != NULL, "node %p\n", node );
2523 IXMLDOMDocument_Release(doc);
2524 IXMLDOMNode_Release(node);
2528 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2529 ok( r == S_OK, "ret %08x\n", r );
2532 IXMLDOMDocument *doc2;
2534 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2535 ok( r == S_OK, "ret %08x\n", r );
2537 IXMLDOMDocument_Release(doc2);
2539 IXMLDOMNode_Release(node_first);
2542 r = IXMLDOMNode_get_childNodes(node, &pList);
2543 ok( r == S_OK, "ret %08x\n", r );
2546 IXMLDOMNodeList_get_length(pList, &nLength);
2547 IXMLDOMNodeList_Release(pList);
2550 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2551 ok( r == S_OK, "ret %08x\n", r );
2554 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2555 IXMLDOMNamedNodeMap_Release(mapAttr);
2558 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2559 ok( r == S_OK, "ret %08x\n", r );
2562 IXMLDOMNodeList_get_length(pList, &nLength1);
2563 IXMLDOMNodeList_Release(pList);
2566 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2567 ok( r == S_OK, "ret %08x\n", r );
2570 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2571 IXMLDOMNamedNodeMap_Release(mapAttr);
2574 ok(nLength == nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2575 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2576 IXMLDOMNode_Release(node_clone);
2579 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2580 ok( r == S_OK, "ret %08x\n", r );
2581 ok( node_clone != NULL, "node %p\n", node );
2585 IXMLDOMDocument_Release(doc);
2586 IXMLDOMNode_Release(node);
2590 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2591 ok( r == S_FALSE, "ret %08x\n", r );
2594 IXMLDOMDocument *doc2;
2596 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2597 ok( r == S_OK, "ret %08x\n", r );
2599 IXMLDOMDocument_Release(doc2);
2601 IXMLDOMNode_Release(node_first);
2604 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2605 ok( r == S_OK, "ret %08x\n", r );
2608 IXMLDOMNodeList_get_length(pList, &nLength1);
2609 ok( nLength1 == 0, "Length should be 0 (%d)\n", nLength1);
2610 IXMLDOMNodeList_Release(pList);
2613 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2614 ok( r == S_OK, "ret %08x\n", r );
2617 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2618 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%d)\n", nAttrCnt1);
2619 IXMLDOMNamedNodeMap_Release(mapAttr);
2622 ok(nLength != nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2623 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2624 IXMLDOMNode_Release(node_clone);
2627 IXMLDOMNode_Release(node);
2628 IXMLDOMDocument_Release(doc);
2631 static void test_xmlTypes(void)
2633 IXMLDOMDocument *doc = NULL;
2634 IXMLDOMElement *pRoot;
2636 IXMLDOMComment *pComment;
2637 IXMLDOMElement *pElement;
2638 IXMLDOMAttribute *pAttrubute;
2639 IXMLDOMNamedNodeMap *pAttribs;
2640 IXMLDOMCDATASection *pCDataSec;
2641 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2642 IXMLDOMDocumentFragment *pDocFrag = NULL;
2643 IXMLDOMEntityReference *pEntityRef = NULL;
2645 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2649 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2653 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2654 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2656 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2657 ok(hr == S_FALSE, "ret %08x\n", hr );
2658 ok(pNextChild == NULL, "pDocChild not NULL\n");
2660 /* test previous Sibling */
2661 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2662 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2664 pNextChild = (IXMLDOMNode *)0x1;
2665 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2666 ok(hr == S_FALSE, "ret %08x\n", hr );
2667 ok(pNextChild == NULL, "pNextChild not NULL\n");
2669 /* test get_attributes */
2670 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2671 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2673 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2674 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2675 ok(hr == S_FALSE, "ret %08x\n", hr );
2676 ok( pAttribs == NULL, "pAttribs not NULL\n");
2678 /* test get_dataType */
2679 hr = IXMLDOMDocument_get_dataType(doc, &v);
2680 ok(hr == S_FALSE, "ret %08x\n", hr );
2681 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2684 /* test nodeTypeString */
2685 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2686 ok(hr == S_OK, "ret %08x\n", hr );
2687 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2690 /* test implementation */
2691 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2692 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2694 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2695 ok(hr == S_OK, "ret %08x\n", hr );
2698 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2699 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2701 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2702 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2704 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2705 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2707 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2708 ok(hr == S_OK, "ret %08x\n", hr );
2709 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2711 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2712 ok(hr == S_OK, "ret %08x\n", hr );
2713 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2715 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2716 ok(hr == S_OK, "ret %08x\n", hr );
2717 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2719 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2720 ok(hr == S_OK, "ret %08x\n", hr );
2721 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2723 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2724 ok(hr == S_OK, "ret %08x\n", hr );
2725 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2727 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2728 ok(hr == S_OK, "ret %08x\n", hr );
2729 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2731 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2732 ok(hr == S_OK, "ret %08x\n", hr );
2733 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2735 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2736 ok(hr == S_OK, "ret %08x\n", hr );
2737 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2739 SysFreeString(sEmpty);
2740 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2745 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2746 ok(hr == S_OK, "ret %08x\n", hr );
2749 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2750 ok(hr == S_OK, "ret %08x\n", hr );
2754 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2755 ok(hr == S_OK, "ret %08x\n", hr );
2758 /* test get_attributes */
2759 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2760 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2762 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2763 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2764 ok(hr == S_FALSE, "ret %08x\n", hr );
2765 ok( pAttribs == NULL, "pAttribs not NULL\n");
2767 /* test nodeTypeString */
2768 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2769 ok(hr == S_OK, "ret %08x\n", hr );
2770 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2773 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2774 ok(hr == S_OK, "ret %08x\n", hr );
2776 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2777 ok(hr == S_OK, "ret %08x\n", hr );
2778 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2781 hr = IXMLDOMComment_get_xml(pComment, &str);
2782 ok(hr == S_OK, "ret %08x\n", hr );
2783 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2786 hr = IXMLDOMComment_get_dataType(pComment, &v);
2787 ok(hr == S_FALSE, "ret %08x\n", hr );
2788 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2791 /* put data Tests */
2792 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2793 ok(hr == S_OK, "ret %08x\n", hr );
2795 /* get data Tests */
2796 hr = IXMLDOMComment_get_data(pComment, &str);
2797 ok(hr == S_OK, "ret %08x\n", hr );
2798 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2801 /* get data Tests */
2802 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2803 ok(hr == S_OK, "ret %08x\n", hr );
2804 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2805 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2808 /* Confirm XML text is good */
2809 hr = IXMLDOMComment_get_xml(pComment, &str);
2810 ok(hr == S_OK, "ret %08x\n", hr );
2811 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2814 /* Confirm we get the put_data Text back */
2815 hr = IXMLDOMComment_get_text(pComment, &str);
2816 ok(hr == S_OK, "ret %08x\n", hr );
2817 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2820 /* test length property */
2821 hr = IXMLDOMComment_get_length(pComment, &len);
2822 ok(hr == S_OK, "ret %08x\n", hr );
2823 ok(len == 21, "expected 21 got %d\n", len);
2825 /* test substringData */
2826 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2827 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2829 /* test substringData - Invalid offset */
2830 str = (BSTR)&szElement;
2831 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2832 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2833 ok( str == NULL, "incorrect string\n");
2835 /* test substringData - Invalid offset */
2836 str = (BSTR)&szElement;
2837 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2838 ok(hr == S_FALSE, "ret %08x\n", hr );
2839 ok( str == NULL, "incorrect string\n");
2841 /* test substringData - Invalid size */
2842 str = (BSTR)&szElement;
2843 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2844 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2845 ok( str == NULL, "incorrect string\n");
2847 /* test substringData - Invalid size */
2848 str = (BSTR)&szElement;
2849 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2850 ok(hr == S_FALSE, "ret %08x\n", hr );
2851 ok( str == NULL, "incorrect string\n");
2853 /* test substringData - Start of string */
2854 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2855 ok(hr == S_OK, "ret %08x\n", hr );
2856 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2859 /* test substringData - Middle of string */
2860 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2861 ok(hr == S_OK, "ret %08x\n", hr );
2862 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2865 /* test substringData - End of string */
2866 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2867 ok(hr == S_OK, "ret %08x\n", hr );
2868 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2871 /* test appendData */
2872 hr = IXMLDOMComment_appendData(pComment, NULL);
2873 ok(hr == S_OK, "ret %08x\n", hr );
2875 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2876 ok(hr == S_OK, "ret %08x\n", hr );
2878 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2879 ok(hr == S_OK, "ret %08x\n", hr );
2881 hr = IXMLDOMComment_get_text(pComment, &str);
2882 ok(hr == S_OK, "ret %08x\n", hr );
2883 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2886 /* test insertData */
2887 str = SysAllocStringLen(NULL, 0);
2888 hr = IXMLDOMComment_insertData(pComment, -1, str);
2889 ok(hr == S_OK, "ret %08x\n", hr );
2891 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2892 ok(hr == S_OK, "ret %08x\n", hr );
2894 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2895 ok(hr == S_OK, "ret %08x\n", hr );
2897 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2898 ok(hr == S_OK, "ret %08x\n", hr );
2900 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2901 ok(hr == S_OK, "ret %08x\n", hr );
2903 hr = IXMLDOMComment_insertData(pComment, 0, str);
2904 ok(hr == S_OK, "ret %08x\n", hr );
2907 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2908 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2910 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2911 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2913 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2914 ok(hr == S_OK, "ret %08x\n", hr );
2916 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2917 ok(hr == S_OK, "ret %08x\n", hr );
2919 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2920 ok(hr == S_OK, "ret %08x\n", hr );
2922 hr = IXMLDOMComment_get_text(pComment, &str);
2923 ok(hr == S_OK, "ret %08x\n", hr );
2924 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2927 IXMLDOMComment_Release(pComment);
2931 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2932 ok(hr == S_OK, "ret %08x\n", hr );
2935 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2936 ok(hr == S_OK, "ret %08x\n", hr );
2938 /* test nodeTypeString */
2939 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2940 ok(hr == S_OK, "ret %08x\n", hr );
2941 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2944 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2945 ok(hr == S_OK, "ret %08x\n", hr );
2946 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2949 hr = IXMLDOMElement_get_xml(pElement, &str);
2950 ok(hr == S_OK, "ret %08x\n", hr );
2951 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2954 hr = IXMLDOMElement_get_dataType(pElement, &v);
2955 ok(hr == S_FALSE, "ret %08x\n", hr );
2956 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2960 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2961 ok(hr == S_OK, "ret %08x\n", hr );
2964 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2966 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2967 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2969 pNextChild = (IXMLDOMNode *)0x1;
2970 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2971 ok(hr == S_FALSE, "ret %08x\n", hr );
2972 ok(pNextChild == NULL, "pNextChild not NULL\n");
2974 /* test Previous Sibling*/
2975 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2976 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2978 pNextChild = (IXMLDOMNode *)0x1;
2979 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2980 ok(hr == S_FALSE, "ret %08x\n", hr );
2981 ok(pNextChild == NULL, "pNextChild not NULL\n");
2983 /* test get_attributes */
2984 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2985 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2987 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2988 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2989 ok(hr == S_FALSE, "ret %08x\n", hr );
2990 ok( pAttribs == NULL, "pAttribs not NULL\n");
2992 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2993 ok(hr == E_FAIL, "ret %08x\n", hr );
2994 ok(pNewChild == NULL, "pNewChild not NULL\n");
2996 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2997 ok(hr == S_OK, "ret %08x\n", hr );
3000 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
3001 ok(hr == S_OK, "ret %08x\n", hr );
3003 IXMLDOMNamedNodeMap_Release(pAttribs);
3006 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
3007 ok(hr == S_OK, "ret %08x\n", hr );
3008 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
3011 /* test nodeTypeString */
3012 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
3013 ok(hr == S_OK, "ret %08x\n", hr );
3014 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
3018 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
3019 ok(hr == S_OK, "ret %08x\n", hr );
3020 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
3023 /* test name property */
3024 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
3025 ok(hr == S_OK, "ret %08x\n", hr );
3026 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
3029 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
3030 ok(hr == S_OK, "ret %08x\n", hr );
3031 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
3034 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
3035 ok(hr == S_FALSE, "ret %08x\n", hr );
3036 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3039 IXMLDOMAttribute_Release(pAttrubute);
3041 /* Check Element again with the Add Attribute*/
3042 hr = IXMLDOMElement_get_xml(pElement, &str);
3043 ok(hr == S_OK, "ret %08x\n", hr );
3044 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
3048 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
3049 ok(hr == S_OK, "ret %08x\n", hr );
3051 hr = IXMLDOMElement_get_xml(pElement, &str);
3052 ok(hr == S_OK, "ret %08x\n", hr );
3053 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
3056 /* Test for reversible escaping */
3057 str = SysAllocString( szStrangeChars );
3058 hr = IXMLDOMElement_put_text(pElement, str);
3059 ok(hr == S_OK, "ret %08x\n", hr );
3060 SysFreeString( str );
3062 hr = IXMLDOMElement_get_xml(pElement, &str);
3063 ok(hr == S_OK, "ret %08x\n", hr );
3064 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
3067 hr = IXMLDOMElement_get_text(pElement, &str);
3068 ok(hr == S_OK, "ret %08x\n", hr );
3069 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
3072 IXMLDOMElement_Release(pElement);
3076 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
3077 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3079 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
3080 ok(hr == S_OK, "ret %08x\n", hr );
3083 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3086 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (LPVOID*)&pElement);
3087 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
3089 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
3090 ok(hr == S_OK, "ret %08x\n", hr );
3092 /* get Attribute Tests */
3093 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
3094 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3096 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3097 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
3098 ok(hr == S_FALSE, "ret %08x\n", hr );
3099 ok(pAttribs == NULL, "pAttribs != NULL\n");
3101 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
3102 ok(hr == S_OK, "ret %08x\n", hr );
3103 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
3106 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3107 ok(hr == S_OK, "ret %08x\n", hr );
3108 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
3111 /* test lastChild */
3112 pNextChild = (IXMLDOMNode*)0x1;
3113 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
3114 ok(hr == S_FALSE, "ret %08x\n", hr );
3115 ok(pNextChild == NULL, "pNextChild not NULL\n");
3117 /* test get_dataType */
3118 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
3119 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3121 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
3122 ok(hr == S_FALSE, "ret %08x\n", hr );
3123 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3126 /* test nodeTypeString */
3127 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
3128 ok(hr == S_OK, "ret %08x\n", hr );
3129 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
3132 /* put data Tests */
3133 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
3134 ok(hr == S_OK, "ret %08x\n", hr );
3136 /* Confirm XML text is good */
3137 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3138 ok(hr == S_OK, "ret %08x\n", hr );
3139 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
3142 /* Confirm we get the put_data Text back */
3143 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3144 ok(hr == S_OK, "ret %08x\n", hr );
3145 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3148 /* test length property */
3149 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
3150 ok(hr == S_OK, "ret %08x\n", hr );
3151 ok(len == 21, "expected 21 got %d\n", len);
3153 /* test get nodeValue */
3154 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
3155 ok(hr == S_OK, "ret %08x\n", hr );
3156 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3160 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
3161 ok(hr == S_OK, "ret %08x\n", hr );
3162 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3165 /* test substringData */
3166 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
3167 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3169 /* test substringData - Invalid offset */
3170 str = (BSTR)&szElement;
3171 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
3172 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3173 ok( str == NULL, "incorrect string\n");
3175 /* test substringData - Invalid offset */
3176 str = (BSTR)&szElement;
3177 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
3178 ok(hr == S_FALSE, "ret %08x\n", hr );
3179 ok( str == NULL, "incorrect string\n");
3181 /* test substringData - Invalid size */
3182 str = (BSTR)&szElement;
3183 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
3184 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3185 ok( str == NULL, "incorrect string\n");
3187 /* test substringData - Invalid size */
3188 str = (BSTR)&szElement;
3189 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
3190 ok(hr == S_FALSE, "ret %08x\n", hr );
3191 ok( str == NULL, "incorrect string\n");
3193 /* test substringData - Start of string */
3194 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
3195 ok(hr == S_OK, "ret %08x\n", hr );
3196 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
3199 /* test substringData - Middle of string */
3200 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
3201 ok(hr == S_OK, "ret %08x\n", hr );
3202 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
3205 /* test substringData - End of string */
3206 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
3207 ok(hr == S_OK, "ret %08x\n", hr );
3208 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
3211 /* test appendData */
3212 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
3213 ok(hr == S_OK, "ret %08x\n", hr );
3215 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
3216 ok(hr == S_OK, "ret %08x\n", hr );
3218 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
3219 ok(hr == S_OK, "ret %08x\n", hr );
3221 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3222 ok(hr == S_OK, "ret %08x\n", hr );
3223 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
3226 /* test insertData */
3227 str = SysAllocStringLen(NULL, 0);
3228 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
3229 ok(hr == S_OK, "ret %08x\n", hr );
3231 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
3232 ok(hr == S_OK, "ret %08x\n", hr );
3234 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
3235 ok(hr == S_OK, "ret %08x\n", hr );
3237 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
3238 ok(hr == S_OK, "ret %08x\n", hr );
3240 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
3241 ok(hr == S_OK, "ret %08x\n", hr );
3243 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
3244 ok(hr == S_OK, "ret %08x\n", hr );
3247 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
3248 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3250 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
3251 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3253 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
3254 ok(hr == S_OK, "ret %08x\n", hr );
3256 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
3257 ok(hr == S_OK, "ret %08x\n", hr );
3259 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
3260 ok(hr == S_OK, "ret %08x\n", hr );
3262 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3263 ok(hr == S_OK, "ret %08x\n", hr );
3264 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
3267 IXMLDOMCDATASection_Release(pCDataSec);
3270 /* Document Fragments */
3271 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
3272 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3274 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
3275 ok(hr == S_OK, "ret %08x\n", hr );
3278 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3280 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
3281 ok(hr == S_OK, "ret %08x\n", hr );
3283 /* get Attribute Tests */
3284 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
3285 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3287 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3288 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
3289 ok(hr == S_FALSE, "ret %08x\n", hr );
3290 ok(pAttribs == NULL, "pAttribs != NULL\n");
3292 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
3293 ok(hr == S_OK, "ret %08x\n", hr );
3294 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
3297 /* test next Sibling*/
3298 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
3299 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3301 pNextChild = (IXMLDOMNode *)0x1;
3302 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
3303 ok(hr == S_FALSE, "ret %08x\n", hr );
3304 ok(pNextChild == NULL, "pNextChild not NULL\n");
3306 /* test Previous Sibling*/
3307 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
3308 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3310 pNextChild = (IXMLDOMNode *)0x1;
3311 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
3312 ok(hr == S_FALSE, "ret %08x\n", hr );
3313 ok(pNextChild == NULL, "pNextChild not NULL\n");
3315 /* test get_dataType */
3316 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
3317 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3319 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
3320 ok(hr == S_FALSE, "ret %08x\n", hr );
3321 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3324 /* test nodeTypeString */
3325 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
3326 ok(hr == S_OK, "ret %08x\n", hr );
3327 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
3330 IXMLDOMDocumentFragment_Release(pDocFrag);
3333 /* Entity References */
3334 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
3335 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3337 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
3338 ok(hr == S_OK, "ret %08x\n", hr );
3341 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
3342 ok(hr == S_OK, "ret %08x\n", hr );
3344 /* get Attribute Tests */
3345 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
3346 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3348 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3349 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
3350 ok(hr == S_FALSE, "ret %08x\n", hr );
3351 ok(pAttribs == NULL, "pAttribs != NULL\n");
3354 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
3355 ok(hr == S_FALSE, "ret %08x\n", hr );
3356 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3359 /* test nodeTypeString */
3360 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
3361 ok(hr == S_OK, "ret %08x\n", hr );
3362 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
3366 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
3367 ok(hr == S_OK, "ret %08x\n", hr );
3368 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
3371 IXMLDOMEntityReference_Release(pEntityRef);
3374 IXMLDOMElement_Release( pRoot );
3378 IXMLDOMDocument_Release(doc);
3383 static void test_nodeTypeTests( void )
3385 IXMLDOMDocument *doc = NULL;
3386 IXMLDOMElement *pRoot;
3387 IXMLDOMElement *pElement;
3390 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3394 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3395 ok(hr == S_OK, "ret %08x\n", hr );
3398 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3399 ok(hr == S_OK, "ret %08x\n", hr );
3402 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
3403 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3406 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
3407 ok(hr == E_FAIL, "ret %08x\n", hr );
3410 * The name passed into put_dataType is case-insensitive. So many of the names
3411 * have been changed to reflect this.
3414 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
3415 ok(hr == S_OK, "ret %08x\n", hr );
3418 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3420 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
3421 ok(hr == S_OK, "ret %08x\n", hr );
3423 IXMLDOMElement_Release(pElement);
3427 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
3428 ok(hr == S_OK, "ret %08x\n", hr );
3431 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3433 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
3434 ok(hr == S_OK, "ret %08x\n", hr );
3436 IXMLDOMElement_Release(pElement);
3440 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
3441 ok(hr == S_OK, "ret %08x\n", hr );
3444 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3446 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
3447 ok(hr == S_OK, "ret %08x\n", hr );
3449 IXMLDOMElement_Release(pElement);
3453 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
3454 ok(hr == S_OK, "ret %08x\n", hr );
3457 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3459 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
3460 ok(hr == S_OK, "ret %08x\n", hr );
3462 IXMLDOMElement_Release(pElement);
3466 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3467 ok(hr == S_OK, "ret %08x\n", hr );
3470 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3472 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3473 ok(hr == S_OK, "ret %08x\n", hr );
3475 IXMLDOMElement_Release(pElement);
3479 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3480 ok(hr == S_OK, "ret %08x\n", hr );
3483 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3485 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3486 ok(hr == S_OK, "ret %08x\n", hr );
3488 IXMLDOMElement_Release(pElement);
3492 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3493 ok(hr == S_OK, "ret %08x\n", hr );
3496 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3498 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3499 ok(hr == S_OK, "ret %08x\n", hr );
3501 IXMLDOMElement_Release(pElement);
3505 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3506 ok(hr == S_OK, "ret %08x\n", hr );
3509 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3511 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3512 ok(hr == S_OK, "ret %08x\n", hr );
3514 IXMLDOMElement_Release(pElement);
3518 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3519 ok(hr == S_OK, "ret %08x\n", hr );
3522 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3524 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3525 ok(hr == S_OK, "ret %08x\n", hr );
3527 IXMLDOMElement_Release(pElement);
3531 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3532 ok(hr == S_OK, "ret %08x\n", hr );
3535 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3537 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3538 ok(hr == S_OK, "ret %08x\n", hr );
3540 IXMLDOMElement_Release(pElement);
3544 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3545 ok(hr == S_OK, "ret %08x\n", hr );
3548 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3550 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3551 ok(hr == S_OK, "ret %08x\n", hr );
3553 IXMLDOMElement_Release(pElement);
3557 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3558 ok(hr == S_OK, "ret %08x\n", hr );
3561 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3563 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3564 ok(hr == S_OK, "ret %08x\n", hr );
3566 IXMLDOMElement_Release(pElement);
3570 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3571 ok(hr == S_OK, "ret %08x\n", hr );
3574 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3576 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3577 ok(hr == S_OK, "ret %08x\n", hr );
3579 IXMLDOMElement_Release(pElement);
3583 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3584 ok(hr == S_OK, "ret %08x\n", hr );
3587 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3589 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3590 ok(hr == S_OK, "ret %08x\n", hr );
3592 IXMLDOMElement_Release(pElement);
3596 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3597 ok(hr == S_OK, "ret %08x\n", hr );
3600 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3602 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3603 ok(hr == S_OK, "ret %08x\n", hr );
3605 IXMLDOMElement_Release(pElement);
3609 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3610 ok(hr == S_OK, "ret %08x\n", hr );
3613 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3615 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3616 ok(hr == S_OK, "ret %08x\n", hr );
3618 IXMLDOMElement_Release(pElement);
3622 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3623 ok(hr == S_OK, "ret %08x\n", hr );
3626 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3628 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3629 ok(hr == S_OK, "ret %08x\n", hr );
3631 IXMLDOMElement_Release(pElement);
3635 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3636 ok(hr == S_OK, "ret %08x\n", hr );
3639 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3641 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3642 ok(hr == S_OK, "ret %08x\n", hr );
3644 IXMLDOMElement_Release(pElement);
3648 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3649 ok(hr == S_OK, "ret %08x\n", hr );
3652 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3654 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3655 ok(hr == S_OK, "ret %08x\n", hr );
3657 IXMLDOMElement_Release(pElement);
3661 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3662 ok(hr == S_OK, "ret %08x\n", hr );
3665 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3667 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3668 ok(hr == S_OK, "ret %08x\n", hr );
3670 IXMLDOMElement_Release(pElement);
3674 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3675 ok(hr == S_OK, "ret %08x\n", hr );
3678 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3680 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3681 ok(hr == S_OK, "ret %08x\n", hr );
3683 IXMLDOMElement_Release(pElement);
3687 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3688 ok(hr == S_OK, "ret %08x\n", hr );
3691 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3693 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3694 ok(hr == S_OK, "ret %08x\n", hr );
3696 IXMLDOMElement_Release(pElement);
3699 /* Check changing types */
3700 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3701 ok(hr == S_OK, "ret %08x\n", hr );
3704 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3706 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3707 ok(hr == S_OK, "ret %08x\n", hr );
3709 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3710 ok(hr == S_OK, "ret %08x\n", hr );
3712 IXMLDOMElement_Release(pElement);
3715 IXMLDOMElement_Release(pRoot);
3719 IXMLDOMDocument_Release(doc);
3724 static void test_DocumentSaveToDocument(void)
3726 IXMLDOMDocument *doc = NULL;
3727 IXMLDOMDocument *doc2 = NULL;
3728 IXMLDOMElement *pRoot;
3732 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3736 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3739 IXMLDOMDocument_Release(doc);
3743 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3744 ok(hr == S_OK, "ret %08x\n", hr );
3747 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3748 ok(hr == S_OK, "ret %08x\n", hr );
3755 V_VT(&vDoc) = VT_UNKNOWN;
3756 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3758 hr = IXMLDOMDocument_save(doc, vDoc);
3759 ok(hr == S_OK, "ret %08x\n", hr );
3761 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3762 ok(hr == S_OK, "ret %08x\n", hr );
3764 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3765 ok(hr == S_OK, "ret %08x\n", hr );
3767 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3769 SysFreeString(sOrig);
3770 SysFreeString(sNew);
3774 IXMLDOMDocument_Release(doc2);
3775 IXMLDOMDocument_Release(doc);
3778 static void test_DocumentSaveToFile(void)
3780 IXMLDOMDocument *doc = NULL;
3781 IXMLDOMElement *pRoot;
3787 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3791 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3792 ok(hr == S_OK, "ret %08x\n", hr );
3795 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3796 ok(hr == S_OK, "ret %08x\n", hr );
3801 V_VT(&vFile) = VT_BSTR;
3802 V_BSTR(&vFile) = _bstr_("test.xml");
3804 hr = IXMLDOMDocument_save(doc, vFile);
3805 ok(hr == S_OK, "ret %08x\n", hr );
3809 IXMLDOMElement_Release(pRoot);
3810 IXMLDOMDocument_Release(doc);
3812 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3813 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3814 if(file == INVALID_HANDLE_VALUE)
3817 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3818 ok(read != 0, "could not read file\n");
3819 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3822 DeleteFile("test.xml");
3825 static void test_testTransforms(void)
3827 IXMLDOMDocument *doc = NULL;
3828 IXMLDOMDocument *docSS = NULL;
3834 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3838 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3841 IXMLDOMDocument_Release(doc);
3845 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3846 ok(hr == S_OK, "ret %08x\n", hr );
3848 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3849 ok(hr == S_OK, "ret %08x\n", hr );
3851 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3852 ok(hr == S_OK, "ret %08x\n", hr );
3857 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3858 ok(hr == S_OK, "ret %08x\n", hr );
3859 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3860 SysFreeString(bOut);
3862 IXMLDOMNode_Release(pNode);
3865 IXMLDOMDocument_Release(docSS);
3866 IXMLDOMDocument_Release(doc);
3871 static void test_Namespaces(void)
3873 IXMLDOMDocument2 *doc = NULL;
3875 IXMLDOMNode *pNode2 = NULL;
3879 static const CHAR szNamespacesXML[] =
3880 "<?xml version=\"1.0\"?>\n"
3881 "<root xmlns:WEB='http://www.winehq.org'>\n"
3882 "<WEB:Site version=\"1.0\" />\n"
3885 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3889 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3890 ok(hr == S_OK, "ret %08x\n", hr );
3891 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3893 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3894 ok(hr == S_OK, "ret %08x\n", hr );
3897 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3898 ok( hr == S_OK, "ret %08x\n", hr );
3899 ok( pNode2 != NULL, "pNode2 == NULL\n");
3901 /* Test get_prefix */
3902 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3903 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3904 /* NOTE: Need to test that arg2 gets cleared on Error. */
3906 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3907 ok( hr == S_OK, "ret %08x\n", hr );
3908 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3911 /* Test get_namespaceURI */
3912 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3913 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3914 /* NOTE: Need to test that arg2 gets cleared on Error. */
3916 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3917 ok( hr == S_OK, "ret %08x\n", hr );
3918 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3921 IXMLDOMNode_Release(pNode2);
3922 IXMLDOMNode_Release(pNode);
3925 IXMLDOMDocument2_Release(doc);
3930 static void test_FormattingXML(void)
3932 IXMLDOMDocument2 *doc = NULL;
3933 IXMLDOMElement *pElement;
3937 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
3938 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
3940 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3944 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
3945 ok(hr == S_OK, "ret %08x\n", hr );
3946 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3948 if(bSucc == VARIANT_TRUE)
3950 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
3951 ok(hr == S_OK, "ret %08x\n", hr );
3954 hr = IXMLDOMElement_get_xml(pElement, &str);
3955 ok(hr == S_OK, "ret %08x\n", hr );
3956 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
3959 IXMLDOMElement_Release(pElement);
3963 IXMLDOMDocument2_Release(doc);
3968 static void test_NodeTypeValue(void)
3970 IXMLDOMDocument2 *doc = NULL;
3976 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3980 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
3981 ok(hr == S_OK, "ret %08x\n", hr );
3982 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3983 if(bSucc == VARIANT_TRUE)
3985 hr = IXMLDOMDocument2_get_nodeValue(doc, NULL);
3986 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3990 hr = IXMLDOMDocument2_get_nodeValue(doc, &v);
3991 ok(hr == S_FALSE, "ret %08x\n", hr );
3992 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
3994 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, NULL);
3995 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3997 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, &v);
3998 ok(hr == S_FALSE, "ret %08x\n", hr );
4000 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string"), &pNode);
4001 ok(hr == S_OK, "ret %08x\n", hr );
4006 hr = IXMLDOMNode_get_nodeValue(pNode, &v);
4007 ok(hr == S_FALSE, "ret %08x\n", hr );
4008 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
4010 hr = IXMLDOMNode_get_nodeTypedValue(pNode, NULL);
4011 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4013 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4014 ok(hr == S_OK, "ret %08x\n", hr );
4015 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4016 ok(!lstrcmpW( V_BSTR(&v), _bstr_("Wine") ), "incorrect value\n");
4019 IXMLDOMNode_Release(pNode);
4022 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string2"), &pNode);
4023 ok(hr == S_OK, "ret %08x\n", hr );
4026 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4027 ok(hr == S_OK, "ret %08x\n", hr );
4028 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4029 ok(!lstrcmpW( V_BSTR(&v), _bstr_("String") ), "incorrect value\n");
4032 IXMLDOMNode_Release(pNode);
4035 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number"), &pNode);
4036 ok(hr == S_OK, "ret %08x\n", hr );
4039 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4040 ok(hr == S_OK, "ret %08x\n", hr );
4041 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4042 ok(!lstrcmpW( V_BSTR(&v), _bstr_("12.44") ), "incorrect value\n");
4045 IXMLDOMNode_Release(pNode);
4048 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number2"), &pNode);
4049 ok(hr == S_OK, "ret %08x\n", hr );
4052 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4053 ok(hr == S_OK, "ret %08x\n", hr );
4054 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4055 ok(!lstrcmpW( V_BSTR(&v), _bstr_("-3.71e3") ), "incorrect value\n");
4058 IXMLDOMNode_Release(pNode);
4061 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/int"), &pNode);
4062 ok(hr == S_OK, "ret %08x\n", hr );
4065 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4066 ok(hr == S_OK, "ret %08x\n", hr );
4067 ok(V_VT(&v) == VT_I4, "incorrect type\n");
4068 ok(V_I4(&v) == -13, "incorrect value\n");
4071 IXMLDOMNode_Release(pNode);
4074 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/fixed"), &pNode);
4075 ok(hr == S_OK, "ret %08x\n", hr );
4078 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4079 ok(hr == S_OK, "ret %08x\n", hr );
4080 ok(V_VT(&v) == VT_CY, "incorrect type\n");
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.13996527778, 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.5813888888888888, 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.112511574074074, 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);
4177 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i2"), &pNode);
4178 ok(hr == S_OK, "ret %08x\n", hr );
4181 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4182 ok(hr == S_OK, "ret %08x\n", hr );
4183 ok(V_VT(&v) == VT_I2, "incorrect type\n");
4184 ok(V_I2(&v) == 31915, "incorrect value\n");
4187 IXMLDOMNode_Release(pNode);
4190 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i4"), &pNode);
4191 ok(hr == S_OK, "ret %08x\n", hr );
4194 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4195 ok(hr == S_OK, "ret %08x\n", hr );
4196 ok(V_VT(&v) == VT_I4, "incorrect type\n");
4197 ok(V_I4(&v) == -312232, "incorrect value\n");
4200 IXMLDOMNode_Release(pNode);
4203 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui1"), &pNode);
4204 ok(hr == S_OK, "ret %08x\n", hr );
4207 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4208 ok(hr == S_OK, "ret %08x\n", hr );
4209 ok(V_VT(&v) == VT_UI1, "incorrect type\n");
4210 ok(V_UI1(&v) == 123, "incorrect value\n");
4213 IXMLDOMNode_Release(pNode);
4216 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui2"), &pNode);
4217 ok(hr == S_OK, "ret %08x\n", hr );
4220 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4221 ok(hr == S_OK, "ret %08x\n", hr );
4222 ok(V_VT(&v) == VT_UI2, "incorrect type\n");
4223 ok(V_UI2(&v) == 48282, "incorrect value\n");
4226 IXMLDOMNode_Release(pNode);
4229 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui4"), &pNode);
4230 ok(hr == S_OK, "ret %08x\n", hr );
4233 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4234 ok(hr == S_OK, "ret %08x\n", hr );
4235 ok(V_VT(&v) == VT_UI4, "incorrect type\n");
4236 ok(V_UI4(&v) == 949281, "incorrect value\n");
4239 IXMLDOMNode_Release(pNode);
4242 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/r4"), &pNode);
4243 ok(hr == S_OK, "ret %08x\n", hr );
4246 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4247 ok(hr == S_OK, "ret %08x\n", hr );
4248 ok(V_VT(&v) == VT_R4, "incorrect type\n");
4249 double_eq(213124.0, V_R4(&v));
4252 IXMLDOMNode_Release(pNode);
4255 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/r8"), &pNode);
4256 ok(hr == S_OK, "ret %08x\n", hr );
4259 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4260 ok(hr == S_OK, "ret %08x\n", hr );
4261 ok(V_VT(&v) == VT_R8, "incorrect type\n");
4262 double_eq(0.412, V_R8(&v));
4265 IXMLDOMNode_Release(pNode);
4268 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/float"), &pNode);
4269 ok(hr == S_OK, "ret %08x\n", hr );
4272 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4273 ok(hr == S_OK, "ret %08x\n", hr );
4274 ok(V_VT(&v) == VT_R8, "incorrect type\n");
4275 double_eq(41221.421, V_R8(&v));
4278 IXMLDOMNode_Release(pNode);
4281 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/uuid"), &pNode);
4282 ok(hr == S_OK, "ret %08x\n", hr );
4285 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4286 ok(hr == S_OK, "ret %08x\n", hr );
4287 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4288 ok(!lstrcmpW(V_BSTR(&v), _bstr_("333C7BC4-460F-11D0-BC04-0080C7055a83")), "incorrect value\n");
4291 IXMLDOMNode_Release(pNode);
4295 IXMLDOMDocument2_Release(doc);
4300 static void test_TransformWithLoadingLocalFile(void)
4302 IXMLDOMDocument2 *doc = NULL;
4303 IXMLDOMDocument2 *xsl = NULL;
4309 char lpPathBuffer[MAX_PATH];
4312 /* Create a Temp File. */
4313 GetTempPathA(MAX_PATH, lpPathBuffer);
4314 strcat(lpPathBuffer, "customers.xml" );
4316 file = CreateFile(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
4317 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
4318 if(file == INVALID_HANDLE_VALUE)
4321 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
4324 /* Correct path to not include a escape character. */
4325 for(i=0; i < strlen(lpPathBuffer); i++)
4327 if(lpPathBuffer[i] == '\\')
4328 lpPathBuffer[i] = '/';
4331 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
4335 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&xsl );
4338 IXMLDOMDocument2_Release(doc);
4342 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
4343 ok(hr == S_OK, "ret %08x\n", hr );
4344 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4345 if(bSucc == VARIANT_TRUE)
4348 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
4349 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
4350 BSTR sFileName = _bstr_(lpPathBuffer);
4351 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
4353 sXSL = SysAllocStringLen(NULL, nLegnth);
4354 lstrcpyW(sXSL, sPart1);
4355 lstrcatW(sXSL, sFileName);
4356 lstrcatW(sXSL, sPart2);
4358 hr = IXMLDOMDocument2_loadXML(xsl, sXSL, &bSucc);
4359 ok(hr == S_OK, "ret %08x\n", hr );
4360 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4361 if(bSucc == VARIANT_TRUE)
4365 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (LPVOID*)&pNode );
4366 ok(hr == S_OK, "ret %08x\n", hr );
4369 /* This will load the temp file via the XSL */
4370 hr = IXMLDOMDocument2_transformNode(doc, pNode, &sResult);
4371 ok(hr == S_OK, "ret %08x\n", hr );
4374 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
4375 SysFreeString(sResult);
4378 IXMLDOMNode_Release(pNode);
4382 SysFreeString(sXSL);
4385 IXMLDOMDocument2_Release(doc);
4386 IXMLDOMDocument2_Release(xsl);
4388 DeleteFile(lpPathBuffer);
4396 r = CoInitialize( NULL );
4397 ok( r == S_OK, "failed to init com\n");
4403 test_getElementsByTagName();
4405 test_get_childNodes();
4407 test_replaceChild();
4408 test_removeNamedItem();
4410 test_IXMLDOMDocument2();
4414 test_nodeTypeTests();
4415 test_DocumentSaveToDocument();
4416 test_DocumentSaveToFile();
4417 test_testTransforms();
4419 test_FormattingXML();
4420 test_NodeTypeValue();
4421 test_TransformWithLoadingLocalFile();