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"
174 " <binhex dt:dt=\"bin.hex\">fffca012003c</binhex>\n"
175 " <binbase64 dt:dt=\"bin.base64\">YmFzZTY0IHRlc3Q=</binbase64>\n"
178 static const CHAR szBasicTransformSSXMLPart1[] =
179 "<?xml version=\"1.0\"?>"
180 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >"
181 "<xsl:output method=\"html\"/>\n"
182 "<xsl:template match=\"/\">"
183 "<HTML><BODY><TABLE>"
184 " <xsl:apply-templates select='document(\"";
186 static const CHAR szBasicTransformSSXMLPart2[] =
188 " <xsl:sort select=\"cost\"/><xsl:sort select=\"name\"/>"
189 " </xsl:apply-templates>"
190 "</TABLE></BODY></HTML>"
192 "<xsl:template match=\"bottle\">"
193 " <TR><xsl:apply-templates select=\"name\" /><xsl:apply-templates select=\"cost\" /></TR>"
195 "<xsl:template match=\"name\">"
196 " <TD><xsl:apply-templates /></TD>"
198 "<xsl:template match=\"cost\">"
199 " <TD><xsl:apply-templates /></TD>"
203 static const CHAR szBasicTransformXML[] =
204 "<?xml version=\"1.0\"?><bottle><wine><name>Wine</name><cost>$25.00</cost></wine></bottle>";
206 static const CHAR szBasicTransformOutput[] =
207 "<HTML><BODY><TABLE><TD>Wine</TD><TD>$25.00</TD></TABLE></BODY></HTML>";
209 static const WCHAR szNonExistentFile[] = {
210 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
212 static const WCHAR szNonExistentAttribute[] = {
213 'n','o','n','E','x','i','s','i','t','i','n','g','A','t','t','r','i','b','u','t','e',0
215 static const WCHAR szDocument[] = {
216 '#', 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 0
219 static const WCHAR szOpen[] = { 'o','p','e','n',0 };
220 static WCHAR szdl[] = { 'd','l',0 };
221 static const WCHAR szvr[] = { 'v','r',0 };
222 static const WCHAR szlc[] = { 'l','c',0 };
223 static WCHAR szbs[] = { 'b','s',0 };
224 static const WCHAR szstr1[] = { 's','t','r','1',0 };
225 static const WCHAR szstr2[] = { 's','t','r','2',0 };
226 static const WCHAR szstar[] = { '*',0 };
227 static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
229 static WCHAR szComment[] = {'A',' ','C','o','m','m','e','n','t',0 };
230 static WCHAR szCommentXML[] = {'<','!','-','-','A',' ','C','o','m','m','e','n','t','-','-','>',0 };
231 static WCHAR szCommentNodeText[] = {'#','c','o','m','m','e','n','t',0 };
233 static WCHAR szElement[] = {'E','l','e','T','e','s','t', 0 };
234 static WCHAR szElementXML[] = {'<','E','l','e','T','e','s','t','/','>',0 };
235 static WCHAR szElementXML2[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','/','>',0 };
236 static WCHAR szElementXML3[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
237 'T','e','s','t','i','n','g','N','o','d','e','<','/','E','l','e','T','e','s','t','>',0 };
238 static WCHAR szElementXML4[] = {'<','E','l','e','T','e','s','t',' ','A','t','t','r','=','"','"','>',
239 '&','a','m','p',';','x',' ',0x2103,'<','/','E','l','e','T','e','s','t','>',0 };
241 static WCHAR szAttribute[] = {'A','t','t','r',0 };
242 static WCHAR szAttributeXML[] = {'A','t','t','r','=','"','"',0 };
244 static WCHAR szCData[] = {'[','1',']','*','2','=','3',';',' ','&','g','e','e',' ','t','h','a','t','s',
245 ' ','n','o','t',' ','r','i','g','h','t','!', 0};
246 static WCHAR szCDataXML[] = {'<','!','[','C','D','A','T','A','[','[','1',']','*','2','=','3',';',' ','&',
247 'g','e','e',' ','t','h','a','t','s',' ','n','o','t',' ','r','i','g','h','t',
249 static WCHAR szCDataNodeText[] = {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0 };
250 static WCHAR szDocFragmentText[] = {'#','d','o','c','u','m','e','n','t','-','f','r','a','g','m','e','n','t',0 };
252 static WCHAR szEntityRef[] = {'e','n','t','i','t','y','r','e','f',0 };
253 static WCHAR szEntityRefXML[] = {'&','e','n','t','i','t','y','r','e','f',';',0 };
254 static WCHAR szStrangeChars[] = {'&','x',' ',0x2103, 0};
256 #define expect_bstr_eq_and_free(bstr, expect) { \
257 BSTR bstrExp = alloc_str_from_narrow(expect); \
258 ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
259 SysFreeString(bstr); \
260 SysFreeString(bstrExp); \
263 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
265 #define ole_check(expr) { \
267 ok(r == S_OK, #expr " returned %x\n", r); \
270 #define ole_expect(expr, expect) { \
272 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
275 #define double_eq(x, y) ok((x)-(y)<=1e-14*(x) && (x)-(y)>=-1e-14*(x), "expected %.16g, got %.16g\n", x, y)
277 static BSTR alloc_str_from_narrow(const char *str)
279 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
280 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
281 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
285 BSTR alloced_bstrs[256];
286 int alloced_bstrs_count = 0;
288 static BSTR _bstr_(const char *str)
290 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
291 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
292 return alloced_bstrs[alloced_bstrs_count++];
295 static void free_bstrs(void)
298 for (i = 0; i < alloced_bstrs_count; i++)
299 SysFreeString(alloced_bstrs[i]);
300 alloced_bstrs_count = 0;
303 static VARIANT _variantbstr_(const char *str)
307 V_BSTR(&v) = _bstr_(str);
311 static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
315 while (*sLeft == '\r' || *sLeft == '\n') sLeft++;
316 while (*sRight == '\r' || *sRight == '\n') sRight++;
317 if (*sLeft != *sRight) return FALSE;
318 if (!*sLeft) return TRUE;
324 static BOOL compareIgnoreReturnsWhitespace(BSTR sLeft, BSTR sRight)
326 /* MSXML3 inserts whitespace where as libxml doesn't. */
329 while (*sLeft == '\r' || *sLeft == '\n' || *sLeft == ' ') sLeft++;
330 while (*sRight == '\r' || *sRight == '\n' || *sRight == ' ') sRight++;
331 if (*sLeft != *sRight) return FALSE;
332 if (!*sLeft) return TRUE;
338 static void get_str_for_type(DOMNodeType type, char *buf)
352 wsprintfA(buf, "[%d]", type);
356 #define test_disp(u) _test_disp(__LINE__,u)
357 static void _test_disp(unsigned line, IUnknown *unk)
359 DISPID dispid = DISPID_XMLDOM_NODELIST_RESET;
367 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
368 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
373 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
374 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
375 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
377 sName = SysAllocString( szstar );
378 hres = IDispatchEx_DeleteMemberByName(dispex, sName, fdexNameCaseSensitive);
379 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
380 SysFreeString( sName );
382 hres = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
383 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
385 hres = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &dwProps);
386 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
387 ok(dwProps == 0, "expected 0 got %d\n", dwProps);
389 hres = IDispatchEx_GetMemberName(dispex, dispid, &sName);
390 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
392 SysFreeString(sName);
394 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_NODELIST_RESET, &dispid);
395 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
397 hres = IDispatchEx_GetNameSpaceParent(dispex, &pUnk);
398 ok(hres == E_NOTIMPL, "expected E_NOTIMPL got %08x\n", hres);
399 if(hres == S_OK && pUnk)
400 IUnknown_Release(pUnk);
402 IDispatchEx_Release(dispex);
405 static int get_node_position(IXMLDOMNode *node)
410 IXMLDOMNode_AddRef(node);
413 IXMLDOMNode *new_node;
416 r = IXMLDOMNode_get_previousSibling(node, &new_node);
417 ok(SUCCEEDED(r), "get_previousSibling failed\n");
418 IXMLDOMNode_Release(node);
424 static void node_to_string(IXMLDOMNode *node, char *buf)
431 lstrcpyA(buf, "(null)");
435 IXMLDOMNode_AddRef(node);
438 IXMLDOMNode *new_node;
440 ole_check(IXMLDOMNode_get_nodeType(node, &type));
441 get_str_for_type(type, buf);
444 if (type == NODE_ATTRIBUTE)
447 ole_check(IXMLDOMNode_get_nodeName(node, &bstr));
449 wsprintfA(buf, "%ws", bstr);
454 r = IXMLDOMNode_selectSingleNode(node, _bstr_(".."), &new_node);
458 int pos = get_node_position(node);
459 DOMNodeType parent_type = NODE_INVALID;
460 r = IXMLDOMNode_get_parentNode(node, &new_node);
462 /* currently wine doesn't create a node for the <?xml ... ?>. To be able to test query
463 * results we "fix" it */
465 ole_check(IXMLDOMNode_get_nodeType(new_node, &parent_type));
466 if ((parent_type == NODE_DOCUMENT) && type != NODE_PROCESSING_INSTRUCTION && pos==1)
468 todo_wine ok(FALSE, "The first child of the document node in MSXML is the <?xml ... ?> processing instruction\n");
471 wsprintf(buf, "%d", pos);
475 ok(SUCCEEDED(r), "get_parentNode failed (%08x)\n", r);
476 IXMLDOMNode_Release(node);
485 static char *list_to_string(IXMLDOMNodeList *list)
487 static char buf[4096];
494 lstrcpyA(buf, "(null)");
497 ole_check(IXMLDOMNodeList_get_length(list, &len));
498 for (i = 0; i < len; i++)
503 ole_check(IXMLDOMNodeList_nextNode(list, &node));
504 node_to_string(node, pos);
506 IXMLDOMNode_Release(node);
512 #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); }
513 #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); }
515 static void test_domdoc( void )
518 IXMLDOMDocument *doc = NULL;
519 IXMLDOMParseError *error;
520 IXMLDOMElement *element = NULL;
522 IXMLDOMText *nodetext = NULL;
523 IXMLDOMComment *node_comment = NULL;
524 IXMLDOMAttribute *node_attr = NULL;
525 IXMLDOMNode *nodeChild = NULL;
526 IXMLDOMProcessingInstruction *nodePI = NULL;
527 ISupportErrorInfo *support_error = NULL;
534 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
535 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
539 test_disp((IUnknown*)doc);
541 /* try some stupid things */
542 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
543 ok( r == S_FALSE, "loadXML failed\n");
546 r = IXMLDOMDocument_loadXML( doc, NULL, &b );
547 ok( r == S_FALSE, "loadXML failed\n");
548 ok( b == VARIANT_FALSE, "failed to load XML string\n");
550 /* try to load a document from a nonexistent file */
552 str = SysAllocString( szNonExistentFile );
554 V_VT(&var) = VT_BSTR;
557 r = IXMLDOMDocument_load( doc, var, &b);
558 ok( r == S_FALSE, "load (from file) failed\n");
559 ok( b == VARIANT_FALSE, "failed to load XML file\n");
560 SysFreeString( str );
562 /* try load an empty document */
564 str = SysAllocString( szEmpty );
565 r = IXMLDOMDocument_loadXML( doc, str, &b );
566 ok( r == S_FALSE, "loadXML failed\n");
567 ok( b == VARIANT_FALSE, "failed to load XML string\n");
568 SysFreeString( str );
570 r = IXMLDOMDocument_get_async( doc, &b );
571 ok( r == S_OK, "get_async failed (%08x)\n", r);
572 ok( b == VARIANT_TRUE, "Wrong default value\n");
574 /* check that there's no document element */
576 r = IXMLDOMDocument_get_documentElement( doc, &element );
577 ok( r == S_FALSE, "should be no document element\n");
579 /* try finding a node */
581 str = SysAllocString( szstr1 );
582 r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
583 ok( r == S_FALSE, "ret %08x\n", r );
584 SysFreeString( str );
587 str = SysAllocString( szIncomplete );
588 r = IXMLDOMDocument_loadXML( doc, str, &b );
589 ok( r == S_FALSE, "loadXML failed\n");
590 ok( b == VARIANT_FALSE, "failed to load XML string\n");
591 SysFreeString( str );
593 /* check that there's no document element */
594 element = (IXMLDOMElement*)1;
595 r = IXMLDOMDocument_get_documentElement( doc, &element );
596 ok( r == S_FALSE, "should be no document element\n");
597 ok( element == NULL, "Element should be NULL\n");
599 /* try to load something valid */
601 str = SysAllocString( szComplete1 );
602 r = IXMLDOMDocument_loadXML( doc, str, &b );
603 ok( r == S_OK, "loadXML failed\n");
604 ok( b == VARIANT_TRUE, "failed to load XML string\n");
605 SysFreeString( str );
607 /* check if nodename is correct */
608 r = IXMLDOMDocument_get_nodeName( doc, NULL );
609 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
611 /* content doesn't matter here */
613 r = IXMLDOMDocument_get_nodeName( doc, &str );
614 ok ( r == S_OK, "get_nodeName wrong code\n");
615 ok ( str != NULL, "str is null\n");
616 ok( !lstrcmpW( str, szDocument ), "incorrect nodeName\n");
617 SysFreeString( str );
620 r = IXMLDOMDocument_put_text( doc, _bstr_("Should Fail") );
621 ok( r == E_FAIL, "ret %08x\n", r );
623 /* check that there's a document element */
625 r = IXMLDOMDocument_get_documentElement( doc, &element );
626 ok( r == S_OK, "should be a document element\n");
629 IObjectIdentity *ident;
632 test_disp((IUnknown*)element);
634 r = IXMLDOMElement_QueryInterface( element, &IID_IObjectIdentity, (LPVOID*)&ident );
635 ok( r == E_NOINTERFACE, "ret %08x\n", r);
637 /* check if the tag is correct */
638 r = IXMLDOMElement_get_tagName( element, &tag );
639 ok( r == S_OK, "couldn't get tag name\n");
640 ok( tag != NULL, "tag was null\n");
641 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
642 SysFreeString( tag );
644 /* figure out what happens if we try to reload the document */
645 str = SysAllocString( szComplete2 );
646 r = IXMLDOMDocument_loadXML( doc, str, &b );
647 ok( r == S_OK, "loadXML failed\n");
648 ok( b == VARIANT_TRUE, "failed to load XML string\n");
649 SysFreeString( str );
651 /* check if the tag is still correct */
653 r = IXMLDOMElement_get_tagName( element, &tag );
654 ok( r == S_OK, "couldn't get tag name\n");
655 ok( tag != NULL, "tag was null\n");
656 ok( !lstrcmpW( tag, szOpen ), "incorrect tag name\n");
657 SysFreeString( tag );
659 IXMLDOMElement_Release( element );
663 /* as soon as we call loadXML again, the document element will disappear */
665 r = IXMLDOMDocument_loadXML( doc, NULL, NULL );
666 ok( r == S_FALSE, "loadXML failed\n");
667 ok( b == 2, "variant modified\n");
668 r = IXMLDOMDocument_get_documentElement( doc, &element );
669 ok( r == S_FALSE, "should be no document element\n");
671 /* try to load something else simple and valid */
673 str = SysAllocString( szComplete3 );
674 r = IXMLDOMDocument_loadXML( doc, str, &b );
675 ok( r == S_OK, "loadXML failed\n");
676 ok( b == VARIANT_TRUE, "failed to load XML string\n");
677 SysFreeString( str );
679 /* try something a little more complicated */
681 str = SysAllocString( szComplete4 );
682 r = IXMLDOMDocument_loadXML( doc, str, &b );
683 ok( r == S_OK, "loadXML failed\n");
684 ok( b == VARIANT_TRUE, "failed to load XML string\n");
685 SysFreeString( str );
687 r = IXMLDOMDocument_get_parseError( doc, &error );
688 ok( r == S_OK, "returns %08x\n", r );
690 r = IXMLDOMParseError_get_errorCode( error, &code );
691 ok( r == S_FALSE, "returns %08x\n", r );
692 ok( code == 0, "code %d\n", code );
693 IXMLDOMParseError_Release( error );
695 /* test createTextNode */
696 str = SysAllocString( szOpen );
697 r = IXMLDOMDocument_createTextNode(doc, str, NULL);
698 ok( r == E_INVALIDARG, "returns %08x\n", r );
699 r = IXMLDOMDocument_createTextNode(doc, str, &nodetext);
700 ok( r == S_OK, "returns %08x\n", r );
701 SysFreeString( str );
704 IXMLDOMNamedNodeMap *pAttribs;
706 r = IXMLDOMText_QueryInterface(nodetext, &IID_IXMLDOMElement, (LPVOID*)&element);
707 ok(r == E_NOINTERFACE, "ret %08x\n", r );
709 /* Text Last Child Checks */
710 r = IXMLDOMText_get_lastChild(nodetext, NULL);
711 ok(r == E_INVALIDARG, "ret %08x\n", r );
713 nodeChild = (IXMLDOMNode*)0x1;
714 r = IXMLDOMText_get_lastChild(nodetext, &nodeChild);
715 ok(r == S_FALSE, "ret %08x\n", r );
716 ok(nodeChild == NULL, "nodeChild not NULL\n");
718 /* test get_attributes */
719 r = IXMLDOMText_get_attributes( nodetext, NULL );
720 ok( r == E_INVALIDARG, "get_attributes returned wrong code\n");
722 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
723 r = IXMLDOMText_get_attributes( nodetext, &pAttribs);
724 ok(r == S_FALSE, "ret %08x\n", r );
725 ok( pAttribs == NULL, "pAttribs not NULL\n");
727 /* test get_dataType */
728 r = IXMLDOMText_get_dataType(nodetext, &var);
729 ok(r == S_FALSE, "ret %08x\n", r );
730 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
733 /* test length property */
734 r = IXMLDOMText_get_length(nodetext, NULL);
735 ok(r == E_INVALIDARG, "ret %08x\n", r );
737 r = IXMLDOMText_get_length(nodetext, &nLength);
738 ok(r == S_OK, "ret %08x\n", r );
739 ok(nLength == 4, "expected 4 got %d\n", nLength);
741 /* test nodeTypeString */
742 r = IXMLDOMText_get_nodeTypeString(nodetext, &str);
743 ok(r == S_OK, "ret %08x\n", r );
744 ok( !lstrcmpW( str, _bstr_("text") ), "incorrect nodeTypeString string\n");
748 r = IXMLDOMText_put_data(nodetext, _bstr_("This &is a ; test <>\\"));
749 ok(r == S_OK, "ret %08x\n", r );
752 r = IXMLDOMText_get_data(nodetext, &str);
753 ok(r == S_OK, "ret %08x\n", r );
754 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect put_data string\n");
757 /* Confirm XML text is good */
758 r = IXMLDOMText_get_xml(nodetext, &str);
759 ok(r == S_OK, "ret %08x\n", r );
760 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
763 /* Confirm we get the put_data Text back */
764 r = IXMLDOMText_get_text(nodetext, &str);
765 ok(r == S_OK, "ret %08x\n", r );
766 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
769 /* test substringData */
770 r = IXMLDOMText_substringData(nodetext, 0, 4, NULL);
771 ok(r == E_INVALIDARG, "ret %08x\n", r );
773 /* test substringData - Invalid offset */
774 str = (BSTR)&szElement;
775 r = IXMLDOMText_substringData(nodetext, -1, 4, &str);
776 ok(r == E_INVALIDARG, "ret %08x\n", r );
777 ok( str == NULL, "incorrect string\n");
779 /* test substringData - Invalid offset */
780 str = (BSTR)&szElement;
781 r = IXMLDOMText_substringData(nodetext, 30, 0, &str);
782 ok(r == S_FALSE, "ret %08x\n", r );
783 ok( str == NULL, "incorrect string\n");
785 /* test substringData - Invalid size */
786 str = (BSTR)&szElement;
787 r = IXMLDOMText_substringData(nodetext, 0, -1, &str);
788 ok(r == E_INVALIDARG, "ret %08x\n", r );
789 ok( str == NULL, "incorrect string\n");
791 /* test substringData - Invalid size */
792 str = (BSTR)&szElement;
793 r = IXMLDOMText_substringData(nodetext, 2, 0, &str);
794 ok(r == S_FALSE, "ret %08x\n", r );
795 ok( str == NULL, "incorrect string\n");
797 /* test substringData - Start of string */
798 r = IXMLDOMText_substringData(nodetext, 0, 4, &str);
799 ok(r == S_OK, "ret %08x\n", r );
800 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
803 /* test substringData - Middle of string */
804 r = IXMLDOMText_substringData(nodetext, 13, 4, &str);
805 ok(r == S_OK, "ret %08x\n", r );
806 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
809 /* test substringData - End of string */
810 r = IXMLDOMText_substringData(nodetext, 20, 4, &str);
811 ok(r == S_OK, "ret %08x\n", r );
812 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
815 /* test appendData */
816 r = IXMLDOMText_appendData(nodetext, NULL);
817 ok(r == S_OK, "ret %08x\n", r );
819 r = IXMLDOMText_appendData(nodetext, _bstr_(""));
820 ok(r == S_OK, "ret %08x\n", r );
822 r = IXMLDOMText_appendData(nodetext, _bstr_("Append"));
823 ok(r == S_OK, "ret %08x\n", r );
825 r = IXMLDOMText_get_text(nodetext, &str);
826 ok(r == S_OK, "ret %08x\n", r );
827 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
830 /* test insertData */
831 str = SysAllocStringLen(NULL, 0);
832 r = IXMLDOMText_insertData(nodetext, -1, str);
833 ok(r == S_OK, "ret %08x\n", r );
835 r = IXMLDOMText_insertData(nodetext, -1, NULL);
836 ok(r == S_OK, "ret %08x\n", r );
838 r = IXMLDOMText_insertData(nodetext, 1000, str);
839 ok(r == S_OK, "ret %08x\n", r );
841 r = IXMLDOMText_insertData(nodetext, 1000, NULL);
842 ok(r == S_OK, "ret %08x\n", r );
844 r = IXMLDOMText_insertData(nodetext, 0, NULL);
845 ok(r == S_OK, "ret %08x\n", r );
847 r = IXMLDOMText_insertData(nodetext, 0, str);
848 ok(r == S_OK, "ret %08x\n", r );
851 r = IXMLDOMText_insertData(nodetext, -1, _bstr_("Inserting"));
852 ok(r == E_INVALIDARG, "ret %08x\n", r );
854 r = IXMLDOMText_insertData(nodetext, 1000, _bstr_("Inserting"));
855 ok(r == E_INVALIDARG, "ret %08x\n", r );
857 r = IXMLDOMText_insertData(nodetext, 0, _bstr_("Begin "));
858 ok(r == S_OK, "ret %08x\n", r );
860 r = IXMLDOMText_insertData(nodetext, 17, _bstr_("Middle"));
861 ok(r == S_OK, "ret %08x\n", r );
863 r = IXMLDOMText_insertData(nodetext, 39, _bstr_(" End"));
864 ok(r == S_OK, "ret %08x\n", r );
866 r = IXMLDOMText_get_text(nodetext, &str);
867 ok(r == S_OK, "ret %08x\n", r );
868 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
872 V_VT(&var) = VT_BSTR;
873 V_BSTR(&var) = SysAllocString(szstr1);
874 r = IXMLDOMText_put_nodeValue(nodetext, var);
875 ok(r == S_OK, "ret %08x\n", r );
878 r = IXMLDOMText_get_text(nodetext, &str);
879 ok(r == S_OK, "ret %08x\n", r );
880 ok( !lstrcmpW( str, szstr1 ), "incorrect get_text string\n");
886 r = IXMLDOMText_put_nodeValue(nodetext, var);
887 ok(r == S_OK, "ret %08x\n", r );
890 r = IXMLDOMText_get_text(nodetext, &str);
891 ok(r == S_OK, "ret %08x\n", r );
892 ok( !lstrcmpW( str, _bstr_("99") ), "incorrect get_text string\n");
895 IXMLDOMText_Release( nodetext );
898 /* test Create Comment */
899 r = IXMLDOMDocument_createComment(doc, NULL, NULL);
900 ok( r == E_INVALIDARG, "returns %08x\n", r );
901 r = IXMLDOMDocument_createComment(doc, szComment, &node_comment);
902 ok( r == S_OK, "returns %08x\n", r );
905 /* Last Child Checks */
906 r = IXMLDOMComment_get_lastChild(node_comment, NULL);
907 ok(r == E_INVALIDARG, "ret %08x\n", r );
909 nodeChild = (IXMLDOMNode*)0x1;
910 r = IXMLDOMComment_get_lastChild(node_comment, &nodeChild);
911 ok(r == S_FALSE, "ret %08x\n", r );
912 ok(nodeChild == NULL, "pLastChild not NULL\n");
914 IXMLDOMComment_Release( node_comment );
917 /* test Create Attribute */
918 r = IXMLDOMDocument_createAttribute(doc, NULL, NULL);
919 ok( r == E_INVALIDARG, "returns %08x\n", r );
920 r = IXMLDOMDocument_createAttribute(doc, szAttribute, &node_attr);
921 ok( r == S_OK, "returns %08x\n", r );
922 IXMLDOMText_Release( node_attr);
924 /* test Processing Instruction */
925 str = SysAllocStringLen(NULL, 0);
926 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, NULL);
927 ok( r == E_INVALIDARG, "returns %08x\n", r );
928 r = IXMLDOMDocument_createProcessingInstruction(doc, NULL, str, &nodePI);
929 ok( r == E_FAIL, "returns %08x\n", r );
930 r = IXMLDOMDocument_createProcessingInstruction(doc, str, str, &nodePI);
931 ok( r == E_FAIL, "returns %08x\n", r );
934 r = IXMLDOMDocument_createProcessingInstruction(doc, _bstr_("xml"), _bstr_("version=\"1.0\""), &nodePI);
935 ok( r == S_OK, "returns %08x\n", r );
938 /* Last Child Checks */
939 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, NULL);
940 ok(r == E_INVALIDARG, "ret %08x\n", r );
942 nodeChild = (IXMLDOMNode*)0x1;
943 r = IXMLDOMProcessingInstruction_get_lastChild(nodePI, &nodeChild);
944 ok(r == S_FALSE, "ret %08x\n", r );
945 ok(nodeChild == NULL, "nodeChild not NULL\n");
947 r = IXMLDOMProcessingInstruction_get_dataType(nodePI, &var);
948 ok(r == S_FALSE, "ret %08x\n", r );
949 ok( V_VT(&var) == VT_NULL, "incorrect dataType type\n");
953 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
954 ok(r == S_OK, "ret %08x\n", r );
955 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
959 r = IXMLDOMProcessingInstruction_get_target(nodePI, &str);
960 ok(r == S_OK, "ret %08x\n", r );
961 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect target string\n");
964 /* test nodeTypeString */
965 r = IXMLDOMProcessingInstruction_get_nodeTypeString(nodePI, &str);
966 ok(r == S_OK, "ret %08x\n", r );
967 ok( !lstrcmpW( str, _bstr_("processinginstruction") ), "incorrect nodeTypeString string\n");
970 /* test get_nodeValue */
971 r = IXMLDOMProcessingInstruction_get_nodeValue(nodePI, &var);
972 ok(r == S_OK, "ret %08x\n", r );
973 ok( !lstrcmpW( V_BSTR(&var), _bstr_("version=\"1.0\"") ), "incorrect data string\n");
977 r = IXMLDOMProcessingInstruction_get_data(nodePI, &str);
978 ok(r == S_OK, "ret %08x\n", r );
979 ok( !lstrcmpW( str, _bstr_("version=\"1.0\"") ), "incorrect data string\n");
983 r = IXMLDOMProcessingInstruction_put_data(nodePI, _bstr_("version=\"1.0\" encoding=\"UTF-8\""));
984 ok(r == E_FAIL, "ret %08x\n", r );
987 V_VT(&var) = VT_BSTR;
988 V_BSTR(&var) = SysAllocString(szOpen); /* Doesn't matter what the string is, cannot set an xml node. */
989 r = IXMLDOMProcessingInstruction_put_nodeValue(nodePI, var);
990 ok(r == E_FAIL, "ret %08x\n", r );
993 /* test get nodeName */
994 r = IXMLDOMProcessingInstruction_get_nodeName(nodePI, &str);
995 ok( !lstrcmpW( str, _bstr_("xml") ), "incorrect nodeName string\n");
996 ok(r == S_OK, "ret %08x\n", r );
999 IXMLDOMProcessingInstruction_Release(nodePI);
1002 r = IXMLDOMDocument_QueryInterface( doc, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1003 ok( r == S_OK, "ret %08x\n", r );
1006 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMDocument );
1007 todo_wine ok( r == S_OK, "ret %08x\n", r );
1008 ISupportErrorInfo_Release( support_error );
1011 r = IXMLDOMDocument_Release( doc );
1012 ok( r == 0, "document ref count incorrect\n");
1017 static void test_domnode( void )
1020 IXMLDOMDocument *doc = NULL, *owner = NULL;
1021 IXMLDOMElement *element = NULL;
1022 IXMLDOMNamedNodeMap *map = NULL;
1023 IXMLDOMNode *node = NULL, *next = NULL;
1024 IXMLDOMNodeList *list = NULL;
1025 IXMLDOMAttribute *attr = NULL;
1026 DOMNodeType type = NODE_INVALID;
1032 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1033 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1037 ok( FALSE, "no document\n");
1042 str = SysAllocString( szComplete4 );
1043 r = IXMLDOMDocument_loadXML( doc, str, &b );
1044 ok( r == S_OK, "loadXML failed\n");
1045 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1046 SysFreeString( str );
1049 r = IXMLDOMNode_hasChildNodes( doc, &b );
1050 ok( r == S_OK, "hasChildNoes bad return\n");
1051 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1053 r = IXMLDOMDocument_get_documentElement( doc, &element );
1054 ok( r == S_OK, "should be a document element\n");
1055 ok( element != NULL, "should be an element\n");
1058 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1060 r = IXMLDOMNode_get_nodeValue( doc, NULL );
1061 ok(r == E_INVALIDARG, "get_nodeValue ret %08x\n", r );
1063 r = IXMLDOMNode_get_nodeValue( doc, &var );
1064 ok( r == S_FALSE, "nextNode returned wrong code\n");
1065 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1066 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1071 r = IXMLDOMNode_get_ownerDocument( element, &owner );
1072 ok( r == S_OK, "get_ownerDocument return code\n");
1073 ok( owner != doc, "get_ownerDocument return\n");
1075 type = NODE_INVALID;
1076 r = IXMLDOMNode_get_nodeType( element, &type);
1077 ok( r == S_OK, "getNamedItem returned wrong code\n");
1078 ok( type == NODE_ELEMENT, "node not an element\n");
1081 r = IXMLDOMNode_get_baseName( element, &str );
1082 ok( r == S_OK, "get_baseName returned wrong code\n");
1083 ok( lstrcmpW(str,szlc) == 0, "basename was wrong\n");
1086 /* check if nodename is correct */
1087 r = IXMLDOMElement_get_nodeName( element, NULL );
1088 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1090 /* content doesn't matter here */
1092 r = IXMLDOMElement_get_nodeName( element, &str );
1093 ok ( r == S_OK, "get_nodeName wrong code\n");
1094 ok ( str != NULL, "str is null\n");
1095 ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n");
1096 SysFreeString( str );
1098 str = SysAllocString( szNonExistentFile );
1100 V_I4(&var) = 0x1234;
1101 r = IXMLDOMElement_getAttribute( element, str, &var );
1102 ok( r == E_FAIL, "getAttribute ret %08x\n", r );
1103 ok( V_VT(&var) == VT_NULL || V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var));
1106 r = IXMLDOMElement_getAttributeNode( element, str, NULL);
1107 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1109 attr = (IXMLDOMAttribute*)0xdeadbeef;
1110 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1111 ok( r == E_FAIL, "getAttributeNode ret %08x\n", r );
1112 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1113 SysFreeString( str );
1115 attr = (IXMLDOMAttribute*)0xdeadbeef;
1116 str = SysAllocString( szNonExistentAttribute );
1117 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1118 ok( r == S_FALSE, "getAttributeNode ret %08x\n", r );
1119 ok( attr == NULL, "getAttributeNode ret %p, expected NULL\n", attr );
1120 SysFreeString( str );
1122 str = SysAllocString( szdl );
1124 V_I4(&var) = 0x1234;
1125 r = IXMLDOMElement_getAttribute( element, str, &var );
1126 ok( r == S_OK, "getAttribute ret %08x\n", r );
1127 ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var));
1128 ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n");
1129 VariantClear( &var );
1131 r = IXMLDOMElement_getAttribute( element, NULL, &var );
1132 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1134 r = IXMLDOMElement_getAttribute( element, str, NULL );
1135 ok( r == E_INVALIDARG, "getAttribute ret %08x\n", r );
1138 r = IXMLDOMElement_getAttributeNode( element, str, &attr);
1139 ok( r == S_OK, "GetAttributeNode ret %08x\n", r );
1140 ok( attr != NULL, "getAttributeNode returned NULL\n" );
1142 IXMLDOMAttribute_Release(attr);
1144 SysFreeString( str );
1146 r = IXMLDOMElement_get_attributes( element, &map );
1147 ok( r == S_OK, "get_attributes returned wrong code\n");
1148 ok( map != NULL, "should be attributes\n");
1151 r = IXMLDOMNode_hasChildNodes( element, &b );
1152 ok( r == S_OK, "hasChildNoes bad return\n");
1153 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1156 ok( FALSE, "no element\n");
1160 ISupportErrorInfo *support_error;
1161 r = IXMLDOMNamedNodeMap_QueryInterface( map, &IID_ISupportErrorInfo, (LPVOID*)&support_error );
1162 ok( r == S_OK, "ret %08x\n", r );
1164 r = ISupportErrorInfo_InterfaceSupportsErrorInfo( support_error, &IID_IXMLDOMNamedNodeMap );
1167 ok( r == S_OK, "ret %08x\n", r );
1169 ISupportErrorInfo_Release( support_error );
1171 str = SysAllocString( szdl );
1172 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1173 ok( r == S_OK, "getNamedItem returned wrong code\n");
1174 ok( node != NULL, "should be attributes\n");
1175 IXMLDOMNode_Release(node);
1176 SysFreeString( str );
1178 str = SysAllocString( szdl );
1179 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, NULL );
1180 ok( r == E_INVALIDARG, "getNamedItem should return E_INVALIDARG\n");
1181 SysFreeString( str );
1183 /* something that isn't in szComplete4 */
1184 str = SysAllocString( szOpen );
1185 node = (IXMLDOMNode *) 1;
1186 r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
1187 ok( r == S_FALSE, "getNamedItem found a node that wasn't there\n");
1188 ok( node == NULL, "getNamedItem should have returned NULL\n");
1189 SysFreeString( str );
1191 /* test indexed access of attributes */
1192 r = IXMLDOMNamedNodeMap_get_length( map, NULL );
1193 ok ( r == E_INVALIDARG, "get_length should return E_INVALIDARG\n");
1195 r = IXMLDOMNamedNodeMap_get_length( map, &count );
1196 ok ( r == S_OK, "get_length wrong code\n");
1197 ok ( count == 1, "get_length != 1\n");
1200 r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
1201 ok ( r == S_FALSE, "get_item (-1) wrong code\n");
1202 ok ( node == NULL, "there is no node\n");
1205 r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
1206 ok ( r == S_FALSE, "get_item (1) wrong code\n");
1207 ok ( node == NULL, "there is no attribute\n");
1210 r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
1211 ok ( r == S_OK, "get_item (0) wrong code\n");
1212 ok ( node != NULL, "should be attribute\n");
1214 r = IXMLDOMNode_get_nodeName( node, NULL );
1215 ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code\n");
1217 /* content doesn't matter here */
1219 r = IXMLDOMNode_get_nodeName( node, &str );
1220 ok ( r == S_OK, "get_nodeName wrong code\n");
1221 ok ( str != NULL, "str is null\n");
1222 ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
1223 SysFreeString( str );
1225 /* test sequential access of attributes */
1227 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1228 ok ( r == S_OK, "nextNode (first time) wrong code\n");
1229 ok ( node != NULL, "nextNode, should be attribute\n");
1231 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1232 ok ( r != S_OK, "nextNode (second time) wrong code\n");
1233 ok ( node == NULL, "nextNode, there is no attribute\n");
1235 r = IXMLDOMNamedNodeMap_reset( map );
1236 ok ( r == S_OK, "reset should return S_OK\n");
1238 r = IXMLDOMNamedNodeMap_nextNode( map, &node );
1239 ok ( r == S_OK, "nextNode (third time) wrong code\n");
1240 ok ( node != NULL, "nextNode, should be attribute\n");
1243 ok( FALSE, "no map\n");
1247 type = NODE_INVALID;
1248 r = IXMLDOMNode_get_nodeType( node, &type);
1249 ok( r == S_OK, "getNamedItem returned wrong code\n");
1250 ok( type == NODE_ATTRIBUTE, "node not an attribute\n");
1253 r = IXMLDOMNode_get_baseName( node, NULL );
1254 ok( r == E_INVALIDARG, "get_baseName returned wrong code\n");
1257 r = IXMLDOMNode_get_baseName( node, &str );
1258 ok( r == S_OK, "get_baseName returned wrong code\n");
1259 ok( lstrcmpW(str,szdl) == 0, "basename was wrong\n");
1260 SysFreeString( str );
1262 r = IXMLDOMNode_get_nodeValue( node, &var );
1263 ok( r == S_OK, "returns %08x\n", r );
1264 ok( V_VT(&var) == VT_BSTR, "vt %x\n", V_VT(&var));
1265 ok( !lstrcmpW(V_BSTR(&var), szstr1), "nodeValue incorrect\n");
1268 r = IXMLDOMNode_get_childNodes( node, NULL );
1269 ok( r == E_INVALIDARG, "get_childNodes returned wrong code\n");
1271 r = IXMLDOMNode_get_childNodes( node, &list );
1272 ok( r == S_OK, "get_childNodes returned wrong code\n");
1276 r = IXMLDOMNodeList_nextNode( list, &next );
1277 ok( r == S_OK, "nextNode returned wrong code\n");
1280 ok( FALSE, "no childlist\n");
1285 r = IXMLDOMNode_hasChildNodes( next, &b );
1286 ok( r == S_FALSE, "hasChildNoes bad return\n");
1287 ok( b == VARIANT_FALSE, "hasChildNoes wrong result\n");
1289 type = NODE_INVALID;
1290 r = IXMLDOMNode_get_nodeType( next, &type);
1291 ok( r == S_OK, "getNamedItem returned wrong code\n");
1292 ok( type == NODE_TEXT, "node not text\n");
1295 r = IXMLDOMNode_get_baseName( next, &str );
1296 ok( r == S_FALSE, "get_baseName returned wrong code\n");
1297 ok( str == NULL, "basename was wrong\n");
1301 ok( FALSE, "no next\n");
1304 IXMLDOMNode_Release( next );
1307 IXMLDOMNodeList_Release( list );
1310 IXMLDOMNode_Release( node );
1313 ok( FALSE, "no node\n");
1317 IXMLDOMNamedNodeMap_Release( map );
1319 /* now traverse the tree from the root element */
1322 r = IXMLDOMNode_get_childNodes( element, &list );
1323 ok( r == S_OK, "get_childNodes returned wrong code\n");
1325 /* using get_item for child list doesn't advance the position */
1326 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
1327 expect_node(node, "E2.E2.D1");
1328 IXMLDOMNode_Release(node);
1329 ole_check(IXMLDOMNodeList_nextNode(list, &node));
1330 expect_node(node, "E1.E2.D1");
1331 IXMLDOMNode_Release(node);
1332 ole_check(IXMLDOMNodeList_reset(list));
1334 IXMLDOMNodeList_AddRef(list);
1335 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1 E4.E2.D1");
1336 ole_check(IXMLDOMNodeList_reset(list));
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 );
1348 ok( FALSE, "no element\n");
1352 r = IXMLDOMNodeList_QueryInterface(list, &IID_IDispatch, NULL);
1353 ok( r == E_INVALIDARG || r == E_POINTER, "ret %08x\n", r );
1355 r = IXMLDOMNodeList_get_item(list, 0, NULL);
1356 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1358 r = IXMLDOMNodeList_get_length(list, NULL);
1359 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1361 r = IXMLDOMNodeList_get_length( list, &count );
1362 ok( r == S_OK, "get_length returns %08x\n", r );
1363 ok( count == 4, "get_length got %d\n", count );
1365 r = IXMLDOMNodeList_nextNode(list, NULL);
1366 ok(r == E_INVALIDARG, "Exected E_INVALIDARG got %08x\n", r);
1368 r = IXMLDOMNodeList_nextNode( list, &node );
1369 ok( r == S_OK, "nextNode returned wrong code\n");
1372 ok( FALSE, "no list\n");
1376 type = NODE_INVALID;
1377 r = IXMLDOMNode_get_nodeType( node, &type);
1378 ok( r == S_OK, "getNamedItem returned wrong code\n");
1379 ok( type == NODE_ELEMENT, "node not text\n");
1382 ok( V_VT(&var) == VT_EMPTY, "variant init failed\n");
1383 r = IXMLDOMNode_get_nodeValue( node, &var );
1384 ok( r == S_FALSE, "nextNode returned wrong code\n");
1385 ok( V_VT(&var) == VT_NULL, "variant wasn't empty\n");
1386 ok( V_BSTR(&var) == NULL, "variant value wasn't null\n");
1388 r = IXMLDOMNode_hasChildNodes( node, NULL );
1389 ok( r == E_INVALIDARG, "hasChildNoes bad return\n");
1392 r = IXMLDOMNode_hasChildNodes( node, &b );
1393 ok( r == S_OK, "hasChildNoes bad return\n");
1394 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1397 r = IXMLDOMNode_get_baseName( node, &str );
1398 ok( r == S_OK, "get_baseName returned wrong code\n");
1399 ok( lstrcmpW(str,szbs) == 0, "basename was wrong\n");
1403 ok( FALSE, "no node\n");
1406 IXMLDOMNode_Release( node );
1408 IXMLDOMNodeList_Release( list );
1410 IXMLDOMElement_Release( element );
1413 str = SysAllocString( szComplete5 );
1414 r = IXMLDOMDocument_loadXML( doc, str, &b );
1415 ok( r == S_OK, "loadXML failed\n");
1416 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1417 SysFreeString( str );
1420 r = IXMLDOMNode_hasChildNodes( doc, &b );
1421 ok( r == S_OK, "hasChildNoes bad return\n");
1422 ok( b == VARIANT_TRUE, "hasChildNoes wrong result\n");
1424 r = IXMLDOMDocument_get_documentElement( doc, &element );
1425 ok( r == S_OK, "should be a document element\n");
1426 ok( element != NULL, "should be an element\n");
1430 static const WCHAR szSSearch[] = {'S',':','s','e','a','r','c','h',0};
1433 /* check if the tag is correct */
1434 r = IXMLDOMElement_get_tagName( element, &tag );
1435 ok( r == S_OK, "couldn't get tag name\n");
1436 ok( tag != NULL, "tag was null\n");
1437 ok( !lstrcmpW( tag, szSSearch ), "incorrect tag name\n");
1438 SysFreeString( tag );
1442 IXMLDOMElement_Release( element );
1443 ok(IXMLDOMDocument_Release( doc ) == 0, "document is not destroyed\n");
1446 static void test_refs(void)
1451 IXMLDOMDocument *doc = NULL;
1452 IXMLDOMElement *element = NULL;
1453 IXMLDOMNode *node = NULL, *node2;
1454 IXMLDOMNodeList *node_list = NULL;
1456 IUnknown *unk, *unk2;
1458 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1459 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1462 ref = IXMLDOMDocument_Release(doc);
1463 ok( ref == 0, "ref %d\n", ref);
1465 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1466 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1470 str = SysAllocString( szComplete4 );
1471 r = IXMLDOMDocument_loadXML( doc, str, &b );
1472 ok( r == S_OK, "loadXML failed\n");
1473 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1474 SysFreeString( str );
1476 ref = IXMLDOMDocument_AddRef( doc );
1477 ok( ref == 2, "ref %d\n", ref );
1478 ref = IXMLDOMDocument_AddRef( doc );
1479 ok( ref == 3, "ref %d\n", ref );
1480 IXMLDOMDocument_Release( doc );
1481 IXMLDOMDocument_Release( doc );
1483 r = IXMLDOMDocument_get_documentElement( doc, &element );
1484 ok( r == S_OK, "should be a document element\n");
1485 ok( element != NULL, "should be an element\n");
1487 ref = IXMLDOMDocument_AddRef( doc );
1488 ok( ref == 2, "ref %d\n", ref );
1489 IXMLDOMDocument_Release( doc );
1491 r = IXMLDOMElement_get_childNodes( element, &node_list );
1492 ok( r == S_OK, "rets %08x\n", r);
1494 ref = IXMLDOMNodeList_AddRef( node_list );
1495 ok( ref == 2, "ref %d\n", ref );
1496 IXMLDOMNodeList_Release( node_list );
1498 IXMLDOMNodeList_get_item( node_list, 0, &node );
1499 ok( r == S_OK, "rets %08x\n", r);
1501 IXMLDOMNodeList_get_item( node_list, 0, &node2 );
1502 ok( r == S_OK, "rets %08x\n", r);
1504 ref = IXMLDOMNode_AddRef( node );
1505 ok( ref == 2, "ref %d\n", ref );
1506 IXMLDOMNode_Release( node );
1508 ref = IXMLDOMNode_Release( node );
1509 ok( ref == 0, "ref %d\n", ref );
1510 ref = IXMLDOMNode_Release( node2 );
1511 ok( ref == 0, "ref %d\n", ref );
1513 ref = IXMLDOMNodeList_Release( node_list );
1514 ok( ref == 0, "ref %d\n", ref );
1516 ok( node != node2, "node %p node2 %p\n", node, node2 );
1518 ref = IXMLDOMDocument_Release( doc );
1519 ok( ref == 0, "ref %d\n", ref );
1521 ref = IXMLDOMElement_AddRef( element );
1523 ok( ref == 3, "ref %d\n", ref );
1525 IXMLDOMElement_Release( element );
1527 /* IUnknown must be unique however we obtain it */
1528 r = IXMLDOMElement_QueryInterface( element, &IID_IUnknown, (LPVOID*)&unk );
1529 ok( r == S_OK, "rets %08x\n", r );
1530 r = IXMLDOMElement_QueryInterface( element, &IID_IXMLDOMNode, (LPVOID*)&node );
1531 ok( r == S_OK, "rets %08x\n", r );
1532 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk2 );
1533 ok( r == S_OK, "rets %08x\n", r );
1534 ok( unk == unk2, "unk %p unk2 %p\n", unk, unk2 );
1536 IUnknown_Release( unk2 );
1537 IUnknown_Release( unk );
1538 IXMLDOMNode_Release( node );
1540 IXMLDOMElement_Release( element );
1544 static void test_create(void)
1546 static const WCHAR szOne[] = {'1',0};
1547 static const WCHAR szOneGarbage[] = {'1','G','a','r','b','a','g','e',0};
1551 IXMLDOMDocument *doc;
1552 IXMLDOMElement *element;
1553 IXMLDOMNode *root, *node, *child;
1554 IXMLDOMNamedNodeMap *attr_map;
1559 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1560 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1565 V_I1(&var) = NODE_ELEMENT;
1566 str = SysAllocString( szlc );
1567 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1568 ok( r == S_OK, "returns %08x\n", r );
1569 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1572 V_R4(&var) = NODE_ELEMENT;
1573 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1574 ok( r == S_OK, "returns %08x\n", r );
1575 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1577 V_VT(&var) = VT_BSTR;
1578 V_BSTR(&var) = SysAllocString( szOne );
1579 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1580 ok( r == S_OK, "returns %08x\n", r );
1581 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1584 V_VT(&var) = VT_BSTR;
1585 V_BSTR(&var) = SysAllocString( szOneGarbage );
1586 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1587 ok( r == E_INVALIDARG, "returns %08x\n", r );
1588 if( SUCCEEDED(r) ) IXMLDOMNode_Release( node );
1592 V_I4(&var) = NODE_ELEMENT;
1593 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1594 ok( r == S_OK, "returns %08x\n", r );
1595 r = IXMLDOMDocument_appendChild( doc, node, &root );
1596 ok( r == S_OK, "returns %08x\n", r );
1597 ok( node == root, "%p %p\n", node, root );
1599 ref = IXMLDOMNode_AddRef( node );
1600 ok(ref == 3, "ref %d\n", ref);
1601 IXMLDOMNode_Release( node );
1603 ref = IXMLDOMNode_Release( node );
1604 ok(ref == 1, "ref %d\n", ref);
1605 SysFreeString( str );
1608 V_I4(&var) = NODE_ELEMENT;
1609 str = SysAllocString( szbs );
1610 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1611 ok( r == S_OK, "returns %08x\n", r );
1612 SysFreeString( str );
1614 ref = IXMLDOMNode_AddRef( node );
1615 ok(ref == 2, "ref = %d\n", ref);
1616 IXMLDOMNode_Release( node );
1618 r = IXMLDOMNode_QueryInterface( node, &IID_IUnknown, (LPVOID*)&unk );
1619 ok( r == S_OK, "returns %08x\n", r );
1621 ref = IXMLDOMNode_AddRef( unk );
1622 ok(ref == 3, "ref = %d\n", ref);
1623 IXMLDOMNode_Release( unk );
1625 V_VT(&var) = VT_EMPTY;
1626 r = IXMLDOMNode_insertBefore( root, (IXMLDOMNode*)unk, var, &child );
1627 ok( r == S_OK, "returns %08x\n", r );
1628 ok( unk == (IUnknown*)child, "%p %p\n", unk, child );
1629 IXMLDOMNode_Release( child );
1630 IUnknown_Release( unk );
1633 V_VT(&var) = VT_NULL;
1634 V_DISPATCH(&var) = (IDispatch*)node;
1635 r = IXMLDOMNode_insertBefore( root, node, var, &child );
1636 ok( r == S_OK, "returns %08x\n", r );
1637 ok( node == child, "%p %p\n", node, child );
1638 IXMLDOMNode_Release( child );
1641 V_VT(&var) = VT_NULL;
1642 V_DISPATCH(&var) = (IDispatch*)node;
1643 r = IXMLDOMNode_insertBefore( root, node, var, NULL );
1644 ok( r == S_OK, "returns %08x\n", r );
1645 IXMLDOMNode_Release( node );
1647 r = IXMLDOMNode_QueryInterface( root, &IID_IXMLDOMElement, (LPVOID*)&element );
1648 ok( r == S_OK, "returns %08x\n", r );
1650 r = IXMLDOMElement_get_attributes( element, &attr_map );
1651 ok( r == S_OK, "returns %08x\n", r );
1652 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1653 ok( r == S_OK, "returns %08x\n", r );
1654 ok( num == 0, "num %d\n", num );
1655 IXMLDOMNamedNodeMap_Release( attr_map );
1657 V_VT(&var) = VT_BSTR;
1658 V_BSTR(&var) = SysAllocString( szstr1 );
1659 name = SysAllocString( szdl );
1660 r = IXMLDOMElement_setAttribute( element, name, var );
1661 ok( r == S_OK, "returns %08x\n", r );
1662 r = IXMLDOMElement_get_attributes( element, &attr_map );
1663 ok( r == S_OK, "returns %08x\n", r );
1664 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1665 ok( r == S_OK, "returns %08x\n", r );
1666 ok( num == 1, "num %d\n", num );
1667 IXMLDOMNamedNodeMap_Release( attr_map );
1670 V_VT(&var) = VT_BSTR;
1671 V_BSTR(&var) = SysAllocString( szstr2 );
1672 r = IXMLDOMElement_setAttribute( element, name, var );
1673 ok( r == S_OK, "returns %08x\n", r );
1674 r = IXMLDOMElement_get_attributes( element, &attr_map );
1675 ok( r == S_OK, "returns %08x\n", r );
1676 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1677 ok( r == S_OK, "returns %08x\n", r );
1678 ok( num == 1, "num %d\n", num );
1679 IXMLDOMNamedNodeMap_Release( attr_map );
1681 r = IXMLDOMElement_getAttribute( element, name, &var );
1682 ok( r == S_OK, "returns %08x\n", r );
1683 ok( !lstrcmpW(V_BSTR(&var), szstr2), "wrong attr value\n");
1685 SysFreeString(name);
1687 V_VT(&var) = VT_BSTR;
1688 V_BSTR(&var) = SysAllocString( szstr1 );
1689 name = SysAllocString( szlc );
1690 r = IXMLDOMElement_setAttribute( element, name, var );
1691 ok( r == S_OK, "returns %08x\n", r );
1692 r = IXMLDOMElement_get_attributes( element, &attr_map );
1693 ok( r == S_OK, "returns %08x\n", r );
1694 r = IXMLDOMNamedNodeMap_get_length( attr_map, &num );
1695 ok( r == S_OK, "returns %08x\n", r );
1696 ok( num == 2, "num %d\n", num );
1697 IXMLDOMNamedNodeMap_Release( attr_map );
1699 SysFreeString(name);
1703 name = SysAllocString( szbs );
1704 r = IXMLDOMElement_setAttribute( element, name, var );
1705 ok( r == S_OK, "returns %08x\n", r );
1707 r = IXMLDOMElement_getAttribute( element, name, &var );
1708 ok( r == S_OK, "returns %08x\n", r );
1709 ok( V_VT(&var) == VT_BSTR, "variant type %x\n", V_VT(&var));
1711 SysFreeString(name);
1713 /* Create an Attribute */
1715 V_I4(&var) = NODE_ATTRIBUTE;
1716 str = SysAllocString( szAttribute );
1717 r = IXMLDOMDocument_createNode( doc, var, str, NULL, &node );
1718 ok( r == S_OK, "returns %08x\n", r );
1719 ok( node != NULL, "node was null\n");
1724 r = IXMLDOMNode_get_nodeTypeString(node, &str);
1725 ok( r == S_OK, "returns %08x\n", r );
1726 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
1728 IXMLDOMNode_Release( node );
1731 IXMLDOMElement_Release( element );
1732 IXMLDOMNode_Release( root );
1733 IXMLDOMDocument_Release( doc );
1736 static void test_getElementsByTagName(void)
1741 IXMLDOMDocument *doc;
1742 IXMLDOMNodeList *node_list;
1745 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1746 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1750 str = SysAllocString( szComplete4 );
1751 r = IXMLDOMDocument_loadXML( doc, str, &b );
1752 ok( r == S_OK, "loadXML failed\n");
1753 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1754 SysFreeString( str );
1756 str = SysAllocString( szstar );
1757 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1758 ok( r == S_OK, "ret %08x\n", r );
1759 r = IXMLDOMNodeList_get_length( node_list, &len );
1760 ok( r == S_OK, "ret %08x\n", r );
1761 ok( len == 6, "len %d\n", len );
1763 test_disp((IUnknown*)node_list);
1765 IXMLDOMNodeList_Release( node_list );
1766 SysFreeString( str );
1768 str = SysAllocString( szbs );
1769 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1770 ok( r == S_OK, "ret %08x\n", r );
1771 r = IXMLDOMNodeList_get_length( node_list, &len );
1772 ok( r == S_OK, "ret %08x\n", r );
1773 ok( len == 1, "len %d\n", len );
1774 IXMLDOMNodeList_Release( node_list );
1775 SysFreeString( str );
1777 str = SysAllocString( szdl );
1778 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1779 ok( r == S_OK, "ret %08x\n", r );
1780 r = IXMLDOMNodeList_get_length( node_list, &len );
1781 ok( r == S_OK, "ret %08x\n", r );
1782 ok( len == 0, "len %d\n", len );
1783 IXMLDOMNodeList_Release( node_list );
1784 SysFreeString( str );
1786 str = SysAllocString( szstr1 );
1787 r = IXMLDOMDocument_getElementsByTagName(doc, str, &node_list);
1788 ok( r == S_OK, "ret %08x\n", r );
1789 r = IXMLDOMNodeList_get_length( node_list, &len );
1790 ok( r == S_OK, "ret %08x\n", r );
1791 ok( len == 0, "len %d\n", len );
1792 IXMLDOMNodeList_Release( node_list );
1793 SysFreeString( str );
1795 IXMLDOMDocument_Release( doc );
1798 static void test_get_text(void)
1803 IXMLDOMDocument *doc;
1804 IXMLDOMNode *node, *node2, *node3;
1805 IXMLDOMNode *nodeRoot;
1806 IXMLDOMNodeList *node_list;
1807 IXMLDOMNamedNodeMap *node_map;
1810 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1811 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1815 str = SysAllocString( szComplete4 );
1816 r = IXMLDOMDocument_loadXML( doc, str, &b );
1817 ok( r == S_OK, "loadXML failed\n");
1818 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1819 SysFreeString( str );
1821 str = SysAllocString( szbs );
1822 r = IXMLDOMDocument_getElementsByTagName( doc, str, &node_list );
1823 ok( r == S_OK, "ret %08x\n", r );
1826 /* Test to get all child node text. */
1827 r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (LPVOID*)&nodeRoot);
1828 ok( r == S_OK, "ret %08x\n", r );
1831 r = IXMLDOMNode_get_text( nodeRoot, &str );
1832 ok( r == S_OK, "ret %08x\n", r );
1833 ok( compareIgnoreReturnsWhitespace(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text\n");
1836 IXMLDOMNode_Release(nodeRoot);
1840 /* this test crashes on win9x */
1841 r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);
1842 ok( r == E_INVALIDARG, "ret %08x\n", r );
1845 r = IXMLDOMNodeList_get_length( node_list, NULL );
1846 ok( r == E_INVALIDARG, "ret %08x\n", r );
1848 r = IXMLDOMNodeList_get_length( node_list, &len );
1849 ok( r == S_OK, "ret %08x\n", r );
1850 ok( len == 1, "expect 1 got %d\n", len );
1852 r = IXMLDOMNodeList_get_item( node_list, 0, NULL );
1853 ok( r == E_INVALIDARG, "ret %08x\n", r );
1855 r = IXMLDOMNodeList_nextNode( node_list, NULL );
1856 ok( r == E_INVALIDARG, "ret %08x\n", r );
1858 r = IXMLDOMNodeList_get_item( node_list, 0, &node );
1859 ok( r == S_OK, "ret %08x\n", r );
1860 IXMLDOMNodeList_Release( node_list );
1862 /* Invalid output parameter*/
1863 r = IXMLDOMNode_get_text( node, NULL );
1864 ok( r == E_INVALIDARG, "ret %08x\n", r );
1866 r = IXMLDOMNode_get_text( node, &str );
1867 ok( r == S_OK, "ret %08x\n", r );
1868 ok( !memcmp(str, szfn1_txt, lstrlenW(szfn1_txt) ), "wrong string\n" );
1871 r = IXMLDOMNode_get_attributes( node, &node_map );
1872 ok( r == S_OK, "ret %08x\n", r );
1874 str = SysAllocString( szvr );
1875 r = IXMLDOMNamedNodeMap_getNamedItem( node_map, str, &node2 );
1876 ok( r == S_OK, "ret %08x\n", r );
1879 r = IXMLDOMNode_get_text( node2, &str );
1880 ok( r == S_OK, "ret %08x\n", r );
1881 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1884 r = IXMLDOMNode_get_firstChild( node2, &node3 );
1885 ok( r == S_OK, "ret %08x\n", r );
1887 r = IXMLDOMNode_get_text( node3, &str );
1888 ok( r == S_OK, "ret %08x\n", r );
1889 ok( !memcmp(str, szstr2, sizeof(szstr2)), "wrong string\n" );
1893 IXMLDOMNode_Release( node3 );
1894 IXMLDOMNode_Release( node2 );
1895 IXMLDOMNamedNodeMap_Release( node_map );
1896 IXMLDOMNode_Release( node );
1897 IXMLDOMDocument_Release( doc );
1900 static void test_get_childNodes(void)
1905 IXMLDOMDocument *doc;
1906 IXMLDOMElement *element;
1907 IXMLDOMNode *node, *node2;
1908 IXMLDOMNodeList *node_list, *node_list2;
1911 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1912 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1916 str = SysAllocString( szComplete4 );
1917 r = IXMLDOMDocument_loadXML( doc, str, &b );
1918 ok( r == S_OK, "loadXML failed\n");
1919 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1920 SysFreeString( str );
1922 r = IXMLDOMDocument_get_documentElement( doc, &element );
1923 ok( r == S_OK, "ret %08x\n", r);
1925 r = IXMLDOMElement_get_childNodes( element, &node_list );
1926 ok( r == S_OK, "ret %08x\n", r);
1928 r = IXMLDOMNodeList_get_length( node_list, &len );
1929 ok( r == S_OK, "ret %08x\n", r);
1930 ok( len == 4, "len %d\n", len);
1932 r = IXMLDOMNodeList_get_item( node_list, 2, &node );
1933 ok( r == S_OK, "ret %08x\n", r);
1935 r = IXMLDOMNode_get_childNodes( node, &node_list2 );
1936 ok( r == S_OK, "ret %08x\n", r);
1938 r = IXMLDOMNodeList_get_length( node_list2, &len );
1939 ok( r == S_OK, "ret %08x\n", r);
1940 ok( len == 0, "len %d\n", len);
1942 r = IXMLDOMNodeList_get_item( node_list2, 0, &node2);
1943 ok( r == S_FALSE, "ret %08x\n", r);
1945 IXMLDOMNodeList_Release( node_list2 );
1946 IXMLDOMNode_Release( node );
1947 IXMLDOMNodeList_Release( node_list );
1948 IXMLDOMElement_Release( element );
1949 IXMLDOMDocument_Release( doc );
1952 static void test_removeChild(void)
1957 IXMLDOMDocument *doc;
1958 IXMLDOMElement *element, *lc_element;
1959 IXMLDOMNode *fo_node, *ba_node, *removed_node, *temp_node, *lc_node;
1960 IXMLDOMNodeList *root_list, *fo_list;
1962 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
1963 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
1967 str = SysAllocString( szComplete4 );
1968 r = IXMLDOMDocument_loadXML( doc, str, &b );
1969 ok( r == S_OK, "loadXML failed\n");
1970 ok( b == VARIANT_TRUE, "failed to load XML string\n");
1971 SysFreeString( str );
1973 r = IXMLDOMDocument_get_documentElement( doc, &element );
1974 ok( r == S_OK, "ret %08x\n", r);
1976 r = IXMLDOMElement_get_childNodes( element, &root_list );
1977 ok( r == S_OK, "ret %08x\n", r);
1979 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
1980 ok( r == S_OK, "ret %08x\n", r);
1982 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
1983 ok( r == S_OK, "ret %08x\n", r);
1985 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
1986 ok( r == S_OK, "ret %08x\n", r);
1988 /* invalid parameter: NULL ptr */
1989 removed_node = (void*)0xdeadbeef;
1990 r = IXMLDOMElement_removeChild( element, NULL, &removed_node );
1991 ok( r == E_INVALIDARG, "ret %08x\n", r );
1992 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
1994 /* ba_node is a descendant of element, but not a direct child. */
1995 removed_node = (void*)0xdeadbeef;
1996 r = IXMLDOMElement_removeChild( element, ba_node, &removed_node );
1997 ok( r == E_INVALIDARG, "ret %08x\n", r );
1998 ok( removed_node == NULL, "%p\n", removed_node );
2000 r = IXMLDOMElement_removeChild( element, fo_node, &removed_node );
2001 ok( r == S_OK, "ret %08x\n", r);
2002 ok( fo_node == removed_node, "node %p node2 %p\n", fo_node, removed_node );
2004 /* try removing already removed child */
2005 temp_node = (void*)0xdeadbeef;
2006 r = IXMLDOMElement_removeChild( element, fo_node, &temp_node );
2007 ok( r == E_INVALIDARG, "ret %08x\n", r);
2008 ok( temp_node == NULL, "%p\n", temp_node );
2010 /* the removed node has no parent anymore */
2011 r = IXMLDOMNode_get_parentNode( removed_node, &temp_node );
2012 ok( r == S_FALSE, "ret %08x\n", r);
2013 ok( temp_node == NULL, "%p\n", temp_node );
2015 IXMLDOMNode_Release( removed_node );
2016 IXMLDOMNode_Release( ba_node );
2017 IXMLDOMNodeList_Release( fo_list );
2019 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2020 ok( r == S_OK, "ret %08x\n", r);
2022 r = IXMLDOMElement_QueryInterface( lc_node, &IID_IXMLDOMElement, (LPVOID*)&lc_element );
2023 ok( r == S_OK, "ret %08x\n", r);
2025 /* MS quirk: passing wrong interface pointer works, too */
2026 r = IXMLDOMElement_removeChild( element, (IXMLDOMNode*)lc_element, NULL );
2027 ok( r == S_OK, "ret %08x\n", r);
2029 r = IXMLDOMNode_get_parentNode( lc_node, &temp_node );
2030 ok( r == S_FALSE, "ret %08x\n", r);
2031 ok( temp_node == NULL, "%p\n", temp_node );
2033 IXMLDOMNode_Release( lc_node );
2034 IXMLDOMNodeList_Release( root_list );
2035 IXMLDOMElement_Release( element );
2036 IXMLDOMDocument_Release( doc );
2039 static void test_replaceChild(void)
2044 IXMLDOMDocument *doc;
2045 IXMLDOMElement *element, *ba_element;
2046 IXMLDOMNode *fo_node, *ba_node, *lc_node, *removed_node, *temp_node;
2047 IXMLDOMNodeList *root_list, *fo_list;
2048 IUnknown * unk1, *unk2;
2051 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2052 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2056 str = SysAllocString( szComplete4 );
2057 r = IXMLDOMDocument_loadXML( doc, str, &b );
2058 ok( r == S_OK, "loadXML failed\n");
2059 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2060 SysFreeString( str );
2062 r = IXMLDOMDocument_get_documentElement( doc, &element );
2063 ok( r == S_OK, "ret %08x\n", r);
2065 r = IXMLDOMElement_get_childNodes( element, &root_list );
2066 ok( r == S_OK, "ret %08x\n", r);
2068 r = IXMLDOMNodeList_get_item( root_list, 0, &lc_node );
2069 ok( r == S_OK, "ret %08x\n", r);
2071 r = IXMLDOMNodeList_get_item( root_list, 3, &fo_node );
2072 ok( r == S_OK, "ret %08x\n", r);
2074 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2075 ok( r == S_OK, "ret %08x\n", r);
2077 r = IXMLDOMNodeList_get_item( fo_list, 0, &ba_node );
2078 ok( r == S_OK, "ret %08x\n", r);
2080 IXMLDOMNodeList_Release( fo_list );
2082 /* invalid parameter: NULL ptr for element to remove */
2083 removed_node = (void*)0xdeadbeef;
2084 r = IXMLDOMElement_replaceChild( element, ba_node, NULL, &removed_node );
2085 ok( r == E_INVALIDARG, "ret %08x\n", r );
2086 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2088 /* invalid parameter: NULL for replacement element. (Sic!) */
2089 removed_node = (void*)0xdeadbeef;
2090 r = IXMLDOMElement_replaceChild( element, NULL, fo_node, &removed_node );
2091 ok( r == E_INVALIDARG, "ret %08x\n", r );
2092 ok( removed_node == (void*)0xdeadbeef, "%p\n", removed_node );
2094 /* invalid parameter: OldNode is not a child */
2095 removed_node = (void*)0xdeadbeef;
2096 r = IXMLDOMElement_replaceChild( element, lc_node, ba_node, &removed_node );
2097 ok( r == E_INVALIDARG, "ret %08x\n", r );
2098 ok( removed_node == NULL, "%p\n", removed_node );
2100 /* invalid parameter: would create loop */
2101 removed_node = (void*)0xdeadbeef;
2102 r = IXMLDOMNode_replaceChild( fo_node, fo_node, ba_node, &removed_node );
2103 ok( r == E_FAIL, "ret %08x\n", r );
2104 ok( removed_node == NULL, "%p\n", removed_node );
2106 r = IXMLDOMElement_replaceChild( element, ba_node, fo_node, NULL );
2107 ok( r == S_OK, "ret %08x\n", r );
2109 r = IXMLDOMNodeList_get_item( root_list, 3, &temp_node );
2110 ok( r == S_OK, "ret %08x\n", r );
2112 /* ba_node and temp_node refer to the same node, yet they
2113 are different interface pointers */
2114 ok( ba_node != temp_node, "ba_node %p temp_node %p\n", ba_node, temp_node);
2115 r = IXMLDOMNode_QueryInterface( temp_node, &IID_IUnknown, (void**)&unk1);
2116 ok( r == S_OK, "ret %08x\n", r );
2117 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IUnknown, (void**)&unk2);
2118 ok( r == S_OK, "ret %08x\n", r );
2119 todo_wine ok( unk1 == unk2, "unk1 %p unk2 %p\n", unk1, unk2);
2121 IUnknown_Release( unk1 );
2122 IUnknown_Release( unk2 );
2124 /* ba_node should have been removed from below fo_node */
2125 r = IXMLDOMNode_get_childNodes( fo_node, &fo_list );
2126 ok( r == S_OK, "ret %08x\n", r );
2128 /* MS quirk: replaceChild also accepts elements instead of nodes */
2129 r = IXMLDOMNode_QueryInterface( ba_node, &IID_IXMLDOMElement, (void**)&ba_element);
2130 ok( r == S_OK, "ret %08x\n", r );
2132 r = IXMLDOMElement_replaceChild( element, ba_node, (IXMLDOMNode*)ba_element, &removed_node );
2133 ok( r == S_OK, "ret %08x\n", r );
2135 r = IXMLDOMNodeList_get_length( fo_list, &len);
2136 ok( r == S_OK, "ret %08x\n", r );
2137 ok( len == 0, "len %d\n", len);
2139 IXMLDOMNodeList_Release( fo_list );
2141 IXMLDOMNode_Release(ba_node);
2142 IXMLDOMNode_Release(fo_node);
2143 IXMLDOMNode_Release(temp_node);
2144 IXMLDOMNodeList_Release( root_list );
2145 IXMLDOMElement_Release( element );
2146 IXMLDOMDocument_Release( doc );
2149 static void test_removeNamedItem(void)
2151 IXMLDOMDocument *doc;
2152 IXMLDOMElement *element;
2153 IXMLDOMNode *pr_node, *removed_node, *removed_node2;
2154 IXMLDOMNodeList *root_list;
2155 IXMLDOMNamedNodeMap * pr_attrs;
2161 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2162 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2166 str = SysAllocString( szComplete4 );
2167 r = IXMLDOMDocument_loadXML( doc, str, &b );
2168 ok( r == S_OK, "loadXML failed\n");
2169 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2170 SysFreeString( str );
2172 r = IXMLDOMDocument_get_documentElement( doc, &element );
2173 ok( r == S_OK, "ret %08x\n", r);
2175 r = IXMLDOMElement_get_childNodes( element, &root_list );
2176 ok( r == S_OK, "ret %08x\n", r);
2178 r = IXMLDOMNodeList_get_item( root_list, 1, &pr_node );
2179 ok( r == S_OK, "ret %08x\n", r);
2181 r = IXMLDOMNode_get_attributes( pr_node, &pr_attrs );
2182 ok( r == S_OK, "ret %08x\n", r);
2184 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2185 ok( r == S_OK, "ret %08x\n", r);
2186 ok( len == 3, "length %d\n", len);
2188 removed_node = (void*)0xdeadbeef;
2189 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, NULL, &removed_node);
2190 ok ( r == E_INVALIDARG, "ret %08x\n", r);
2191 ok ( removed_node == (void*)0xdeadbeef, "removed_node == %p\n", removed_node);
2193 removed_node = (void*)0xdeadbeef;
2194 str = SysAllocString(szvr);
2195 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node);
2196 ok ( r == S_OK, "ret %08x\n", r);
2198 removed_node2 = (void*)0xdeadbeef;
2199 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, &removed_node2);
2200 ok ( r == S_FALSE, "ret %08x\n", r);
2201 ok ( removed_node2 == NULL, "removed_node == %p\n", removed_node2 );
2203 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2204 ok( r == S_OK, "ret %08x\n", r);
2205 ok( len == 2, "length %d\n", len);
2207 r = IXMLDOMNamedNodeMap_setNamedItem( pr_attrs, removed_node, NULL);
2208 ok ( r == S_OK, "ret %08x\n", r);
2209 IXMLDOMNode_Release(removed_node);
2211 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2212 ok( r == S_OK, "ret %08x\n", r);
2213 ok( len == 3, "length %d\n", len);
2215 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2216 ok ( r == S_OK, "ret %08x\n", r);
2218 r = IXMLDOMNamedNodeMap_get_length( pr_attrs, &len );
2219 ok( r == S_OK, "ret %08x\n", r);
2220 ok( len == 2, "length %d\n", len);
2222 r = IXMLDOMNamedNodeMap_removeNamedItem( pr_attrs, str, NULL);
2223 ok ( r == S_FALSE, "ret %08x\n", r);
2227 IXMLDOMNamedNodeMap_Release( pr_attrs );
2228 IXMLDOMNode_Release( pr_node );
2229 IXMLDOMNodeList_Release( root_list );
2230 IXMLDOMElement_Release( element );
2231 IXMLDOMDocument_Release( doc );
2234 static void test_XMLHTTP(void)
2236 static const WCHAR wszBody[] = {'m','o','d','e','=','T','e','s','t',0};
2237 static WCHAR wszPOST[] = {'P','O','S','T',0};
2238 static WCHAR wszUrl[] = {'h','t','t','p',':','/','/',
2239 'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2240 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2241 static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
2242 IXMLHttpRequest *pXMLHttpRequest;
2247 HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
2248 CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
2249 (void **)&pXMLHttpRequest);
2250 ok(hr == S_OK, "CoCreateInstance(CLSID_XMLHTTPRequest) should have succeeded instead of failing with 0x%08x\n", hr);
2254 VariantInit(&dummy);
2255 V_VT(&dummy) = VT_ERROR;
2256 V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
2257 VariantInit(&varfalse);
2258 V_VT(&varfalse) = VT_BOOL;
2259 V_BOOL(&varfalse) = VARIANT_FALSE;
2260 V_VT(&varbody) = VT_BSTR;
2261 V_BSTR(&varbody) = SysAllocString(wszBody);
2263 hr = IXMLHttpRequest_open(pXMLHttpRequest, wszPOST, wszUrl, varfalse, dummy, dummy);
2264 todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
2266 hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
2267 todo_wine ok(hr == S_OK, "IXMLHttpRequest_send should have succeeded instead of failing with 0x%08x\n", hr);
2268 VariantClear(&varbody);
2270 hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
2271 todo_wine ok(hr == S_OK, "IXMLHttpRequest_get_responseText should have succeeded instead of failing with 0x%08x\n", hr);
2272 /* the server currently returns "FAILED" because the Content-Type header is
2273 * not what the server expects */
2276 ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)), "bstrResponse differs from what was expected\n");
2277 SysFreeString(bstrResponse);
2280 IXMLHttpRequest_Release(pXMLHttpRequest);
2283 static void test_IXMLDOMDocument2(void)
2288 IXMLDOMDocument *doc;
2289 IXMLDOMDocument2 *doc2;
2290 IDispatchEx *dispex;
2294 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2295 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
2299 str = SysAllocString( szComplete4 );
2300 r = IXMLDOMDocument_loadXML( doc, str, &b );
2301 ok( r == S_OK, "loadXML failed\n");
2302 ok( b == VARIANT_TRUE, "failed to load XML string\n");
2303 SysFreeString( str );
2305 r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
2306 ok( r == S_OK, "ret %08x\n", r );
2307 ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
2309 r = IXMLDOMDocument_QueryInterface( doc, &IID_IDispatchEx, (void**)&dispex );
2310 ok( r == S_OK, "ret %08x\n", r );
2313 IDispatchEx_Release(dispex);
2316 /* we will check if the variant got cleared */
2317 ref = IXMLDOMDocument2_AddRef(doc2);
2318 expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
2319 V_VT(&var) = VT_UNKNOWN;
2320 V_UNKNOWN(&var) = (IUnknown *)doc2;
2323 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
2324 expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
2325 ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
2328 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2329 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2330 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2333 /* the variant didn't get cleared*/
2334 expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
2336 /* setProperty tests */
2337 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
2338 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
2339 ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
2340 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2341 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2342 ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
2344 /* contrary to what MSDN claims you can switch back from XPath to XSLPattern */
2345 ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
2346 expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2347 expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
2349 IXMLDOMDocument2_Release( doc2 );
2350 IXMLDOMDocument_Release( doc );
2354 static void test_XPath(void)
2359 IXMLDOMDocument2 *doc;
2360 IXMLDOMNode *rootNode;
2361 IXMLDOMNode *elem1Node;
2363 IXMLDOMNodeList *list;
2365 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
2366 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2370 ole_check(IXMLDOMDocument_loadXML(doc, _bstr_(szExampleXML), &b));
2371 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2373 /* switch to XPath */
2374 ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
2376 /* some simple queries*/
2377 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root"), &list));
2378 ole_check(IXMLDOMNodeList_get_item(list, 0, &rootNode));
2379 ole_check(IXMLDOMNodeList_reset(list));
2380 expect_list_and_release(list, "E2.D1");
2381 if (rootNode == NULL)
2384 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//c"), &list));
2385 expect_list_and_release(list, "E3.E1.E2.D1 E3.E2.E2.D1");
2387 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//c[@type]"), &list));
2388 expect_list_and_release(list, "E3.E2.E2.D1");
2390 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem"), &list));
2391 /* using get_item for query results advances the position */
2392 ole_check(IXMLDOMNodeList_get_item(list, 1, &node));
2393 expect_node(node, "E2.E2.D1");
2394 IXMLDOMNode_Release(node);
2395 ole_check(IXMLDOMNodeList_nextNode(list, &node));
2396 expect_node(node, "E4.E2.D1");
2397 IXMLDOMNode_Release(node);
2398 ole_check(IXMLDOMNodeList_reset(list));
2399 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E4.E2.D1");
2401 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("."), &list));
2402 expect_list_and_release(list, "E2.D1");
2404 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("elem[3]/preceding-sibling::*"), &list));
2405 ole_check(IXMLDOMNodeList_get_item(list, 0, &elem1Node));
2406 ole_check(IXMLDOMNodeList_reset(list));
2407 expect_list_and_release(list, "E1.E2.D1 E2.E2.D1 E3.E2.D1");
2409 /* select an attribute */
2410 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//@type"), &list));
2411 expect_list_and_release(list, "A'type'.E3.E2.E2.D1");
2413 /* would evaluate to a number */
2414 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("count(*)"), &list), E_FAIL);
2415 /* would evaluate to a boolean */
2416 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("position()>0"), &list), E_FAIL);
2417 /* would evaluate to a string */
2418 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_("name()"), &list), E_FAIL);
2421 ole_check(IXMLDOMNode_selectNodes(rootNode, _bstr_("c"), &list));
2422 expect_list_and_release(list, "");
2423 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("elem//c"), &list));
2424 expect_list_and_release(list, "");
2425 ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("//elem[4]"), &list));
2426 expect_list_and_release(list, "");
2428 /* foo undeclared in document node */
2429 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2430 /* undeclared in <root> node */
2431 ole_expect(IXMLDOMNode_selectNodes(rootNode, _bstr_(".//foo:c"), &list), E_FAIL);
2432 /* undeclared in <elem> node */
2433 ole_expect(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//foo:c"), &list), E_FAIL);
2434 /* but this trick can be used */
2435 ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
2436 expect_list_and_release(list, "E3.E4.E2.D1");
2438 /* it has to be declared in SelectionNamespaces */
2439 todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2440 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
2442 /* now the namespace can be used */
2443 todo_wine ole_check(IXMLDOMDocument_selectNodes(doc, _bstr_("root//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(rootNode, _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:c"), &list));
2448 todo_wine expect_list_and_release(list, "E3.E3.E2.D1 E3.E4.E2.D1");
2449 todo_wine ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_(".//test:x"), &list));
2450 todo_wine expect_list_and_release(list, "E5.E1.E4.E1.E2.D1");
2452 /* SelectionNamespaces syntax error - the namespaces doesn't work anymore but the value is stored */
2453 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2454 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###")), E_FAIL);
2456 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2459 todo_wine ole_check(IXMLDOMDocument2_getProperty(doc, _bstr_("SelectionNamespaces"), &var));
2460 todo_wine expect_eq(V_VT(&var), VT_BSTR, int, "%x");
2461 if (V_VT(&var) == VT_BSTR)
2462 expect_bstr_eq_and_free(V_BSTR(&var), "xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' xmlns:foo=###");
2464 /* extra attributes - same thing*/
2465 ole_expect(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
2466 _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29' param='test'")), E_FAIL);
2467 ole_expect(IXMLDOMDocument_selectNodes(doc, _bstr_("root//foo:c"), &list), E_FAIL);
2469 IXMLDOMNode_Release(rootNode);
2470 IXMLDOMNode_Release(elem1Node);
2471 IXMLDOMDocument_Release(doc);
2475 static void test_cloneNode(void )
2477 IXMLDOMDocument *doc = NULL;
2479 IXMLDOMNodeList *pList;
2480 IXMLDOMNamedNodeMap *mapAttr;
2481 LONG nLength = 0, nLength1 = 0;
2482 LONG nAttrCnt = 0, nAttrCnt1 = 0;
2484 IXMLDOMNode *node_clone;
2485 IXMLDOMNode *node_first;
2488 static const WCHAR szSearch[] = { 'l', 'c', '/', 'p', 'r', 0 };
2490 r = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2494 str = SysAllocString( szComplete4 );
2495 ole_check(IXMLDOMDocument_loadXML(doc, str, &b));
2496 ok(b == VARIANT_TRUE, "failed to load XML string\n");
2502 str = SysAllocString( szSearch);
2503 r = IXMLDOMNode_selectSingleNode(doc, str, &node);
2504 ok( r == S_OK, "ret %08x\n", r );
2505 ok( node != NULL, "node %p\n", node );
2510 IXMLDOMDocument_Release(doc);
2514 /* Check invalid parameter */
2515 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, NULL);
2516 ok( r == E_INVALIDARG, "ret %08x\n", r );
2519 r = IXMLDOMNode_cloneNode(node, VARIANT_TRUE, &node_clone);
2520 ok( r == S_OK, "ret %08x\n", r );
2521 ok( node_clone != NULL, "node %p\n", node );
2525 IXMLDOMDocument_Release(doc);
2526 IXMLDOMNode_Release(node);
2530 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2531 ok( r == S_OK, "ret %08x\n", r );
2534 IXMLDOMDocument *doc2;
2536 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2537 ok( r == S_OK, "ret %08x\n", r );
2539 IXMLDOMDocument_Release(doc2);
2541 IXMLDOMNode_Release(node_first);
2544 r = IXMLDOMNode_get_childNodes(node, &pList);
2545 ok( r == S_OK, "ret %08x\n", r );
2548 IXMLDOMNodeList_get_length(pList, &nLength);
2549 IXMLDOMNodeList_Release(pList);
2552 r = IXMLDOMNode_get_attributes(node, &mapAttr);
2553 ok( r == S_OK, "ret %08x\n", r );
2556 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt);
2557 IXMLDOMNamedNodeMap_Release(mapAttr);
2560 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2561 ok( r == S_OK, "ret %08x\n", r );
2564 IXMLDOMNodeList_get_length(pList, &nLength1);
2565 IXMLDOMNodeList_Release(pList);
2568 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2569 ok( r == S_OK, "ret %08x\n", r );
2572 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2573 IXMLDOMNamedNodeMap_Release(mapAttr);
2576 ok(nLength == nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2577 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2578 IXMLDOMNode_Release(node_clone);
2581 r = IXMLDOMNode_cloneNode(node, VARIANT_FALSE, &node_clone);
2582 ok( r == S_OK, "ret %08x\n", r );
2583 ok( node_clone != NULL, "node %p\n", node );
2587 IXMLDOMDocument_Release(doc);
2588 IXMLDOMNode_Release(node);
2592 r = IXMLDOMNode_get_firstChild(node_clone, &node_first);
2593 ok( r == S_FALSE, "ret %08x\n", r );
2596 IXMLDOMDocument *doc2;
2598 r = IXMLDOMNode_get_ownerDocument(node_clone, &doc2);
2599 ok( r == S_OK, "ret %08x\n", r );
2601 IXMLDOMDocument_Release(doc2);
2603 IXMLDOMNode_Release(node_first);
2606 r = IXMLDOMNode_get_childNodes(node_clone, &pList);
2607 ok( r == S_OK, "ret %08x\n", r );
2610 IXMLDOMNodeList_get_length(pList, &nLength1);
2611 ok( nLength1 == 0, "Length should be 0 (%d)\n", nLength1);
2612 IXMLDOMNodeList_Release(pList);
2615 r = IXMLDOMNode_get_attributes(node_clone, &mapAttr);
2616 ok( r == S_OK, "ret %08x\n", r );
2619 IXMLDOMNamedNodeMap_get_length(mapAttr, &nAttrCnt1);
2620 ok( nAttrCnt1 == 3, "Attribute count should be 3 (%d)\n", nAttrCnt1);
2621 IXMLDOMNamedNodeMap_Release(mapAttr);
2624 ok(nLength != nLength1, "wrong Child count (%d, %d)\n", nLength, nLength1);
2625 ok(nAttrCnt == nAttrCnt1, "wrong Attribute count (%d, %d)\n", nAttrCnt, nAttrCnt1);
2626 IXMLDOMNode_Release(node_clone);
2629 IXMLDOMNode_Release(node);
2630 IXMLDOMDocument_Release(doc);
2633 static void test_xmlTypes(void)
2635 IXMLDOMDocument *doc = NULL;
2636 IXMLDOMElement *pRoot;
2638 IXMLDOMComment *pComment;
2639 IXMLDOMElement *pElement;
2640 IXMLDOMAttribute *pAttrubute;
2641 IXMLDOMNamedNodeMap *pAttribs;
2642 IXMLDOMCDATASection *pCDataSec;
2643 IXMLDOMImplementation *pIXMLDOMImplementation = NULL;
2644 IXMLDOMDocumentFragment *pDocFrag = NULL;
2645 IXMLDOMEntityReference *pEntityRef = NULL;
2647 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1; /* Used for testing Siblings */
2651 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
2655 hr = IXMLDOMDocument_get_nextSibling(doc, NULL);
2656 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2658 hr = IXMLDOMDocument_get_nextSibling(doc, &pNextChild);
2659 ok(hr == S_FALSE, "ret %08x\n", hr );
2660 ok(pNextChild == NULL, "pDocChild not NULL\n");
2662 /* test previous Sibling */
2663 hr = IXMLDOMDocument_get_previousSibling(doc, NULL);
2664 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2666 pNextChild = (IXMLDOMNode *)0x1;
2667 hr = IXMLDOMDocument_get_previousSibling(doc, &pNextChild);
2668 ok(hr == S_FALSE, "ret %08x\n", hr );
2669 ok(pNextChild == NULL, "pNextChild not NULL\n");
2671 /* test get_attributes */
2672 hr = IXMLDOMDocument_get_attributes( doc, NULL );
2673 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2675 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2676 hr = IXMLDOMDocument_get_attributes( doc, &pAttribs);
2677 ok(hr == S_FALSE, "ret %08x\n", hr );
2678 ok( pAttribs == NULL, "pAttribs not NULL\n");
2680 /* test get_dataType */
2681 hr = IXMLDOMDocument_get_dataType(doc, &v);
2682 ok(hr == S_FALSE, "ret %08x\n", hr );
2683 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2686 /* test nodeTypeString */
2687 hr = IXMLDOMDocument_get_nodeTypeString(doc, &str);
2688 ok(hr == S_OK, "ret %08x\n", hr );
2689 ok( !lstrcmpW( str, _bstr_("document") ), "incorrect nodeTypeString string\n");
2692 /* test implementation */
2693 hr = IXMLDOMDocument_get_implementation(doc, NULL);
2694 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2696 hr = IXMLDOMDocument_get_implementation(doc, &pIXMLDOMImplementation);
2697 ok(hr == S_OK, "ret %08x\n", hr );
2700 VARIANT_BOOL hasFeature = VARIANT_TRUE;
2701 BSTR sEmpty = SysAllocStringLen(NULL, 0);
2703 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, NULL, sEmpty, &hasFeature);
2704 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2706 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, NULL);
2707 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2709 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2710 ok(hr == S_OK, "ret %08x\n", hr );
2711 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2713 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, sEmpty, sEmpty, &hasFeature);
2714 ok(hr == S_OK, "ret %08x\n", hr );
2715 ok(hasFeature == VARIANT_FALSE, "hasFeature returned true\n");
2717 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), NULL, &hasFeature);
2718 ok(hr == S_OK, "ret %08x\n", hr );
2719 ok(hasFeature == VARIANT_TRUE, "hasFeature returned false\n");
2721 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), sEmpty, &hasFeature);
2722 ok(hr == S_OK, "ret %08x\n", hr );
2723 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2725 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("DOM"), _bstr_("1.0"), &hasFeature);
2726 ok(hr == S_OK, "ret %08x\n", hr );
2727 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2729 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("XML"), _bstr_("1.0"), &hasFeature);
2730 ok(hr == S_OK, "ret %08x\n", hr );
2731 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2733 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("MS-DOM"), _bstr_("1.0"), &hasFeature);
2734 ok(hr == S_OK, "ret %08x\n", hr );
2735 ok(hasFeature == VARIANT_TRUE, "hasFeature returned true\n");
2737 hr = IXMLDOMImplementation_hasFeature(pIXMLDOMImplementation, _bstr_("SSS"), NULL, &hasFeature);
2738 ok(hr == S_OK, "ret %08x\n", hr );
2739 ok(hasFeature == VARIANT_FALSE, "hasFeature returned false\n");
2741 SysFreeString(sEmpty);
2742 IXMLDOMImplementation_Release(pIXMLDOMImplementation);
2747 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
2748 ok(hr == S_OK, "ret %08x\n", hr );
2751 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
2752 ok(hr == S_OK, "ret %08x\n", hr );
2756 hr = IXMLDOMDocument_createComment(doc, szComment, &pComment);
2757 ok(hr == S_OK, "ret %08x\n", hr );
2760 /* test get_attributes */
2761 hr = IXMLDOMComment_get_attributes( pComment, NULL );
2762 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2764 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2765 hr = IXMLDOMComment_get_attributes( pComment, &pAttribs);
2766 ok(hr == S_FALSE, "ret %08x\n", hr );
2767 ok( pAttribs == NULL, "pAttribs not NULL\n");
2769 /* test nodeTypeString */
2770 hr = IXMLDOMComment_get_nodeTypeString(pComment, &str);
2771 ok(hr == S_OK, "ret %08x\n", hr );
2772 ok( !lstrcmpW( str, _bstr_("comment") ), "incorrect nodeTypeString string\n");
2775 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pComment, NULL);
2776 ok(hr == S_OK, "ret %08x\n", hr );
2778 hr = IXMLDOMComment_get_nodeName(pComment, &str);
2779 ok(hr == S_OK, "ret %08x\n", hr );
2780 ok( !lstrcmpW( str, szCommentNodeText ), "incorrect comment node Name\n");
2783 hr = IXMLDOMComment_get_xml(pComment, &str);
2784 ok(hr == S_OK, "ret %08x\n", hr );
2785 ok( !lstrcmpW( str, szCommentXML ), "incorrect comment xml\n");
2788 hr = IXMLDOMComment_get_dataType(pComment, &v);
2789 ok(hr == S_FALSE, "ret %08x\n", hr );
2790 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2793 /* put data Tests */
2794 hr = IXMLDOMComment_put_data(pComment, _bstr_("This &is a ; test <>\\"));
2795 ok(hr == S_OK, "ret %08x\n", hr );
2797 /* get data Tests */
2798 hr = IXMLDOMComment_get_data(pComment, &str);
2799 ok(hr == S_OK, "ret %08x\n", hr );
2800 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect get_data string\n");
2803 /* get data Tests */
2804 hr = IXMLDOMComment_get_nodeValue(pComment, &v);
2805 ok(hr == S_OK, "ret %08x\n", hr );
2806 ok( V_VT(&v) == VT_BSTR, "incorrect dataType type\n");
2807 ok( !lstrcmpW( V_BSTR(&v), _bstr_("This &is a ; test <>\\") ), "incorrect get_nodeValue string\n");
2810 /* Confirm XML text is good */
2811 hr = IXMLDOMComment_get_xml(pComment, &str);
2812 ok(hr == S_OK, "ret %08x\n", hr );
2813 ok( !lstrcmpW( str, _bstr_("<!--This &is a ; test <>\\-->") ), "incorrect xml string\n");
2816 /* Confirm we get the put_data Text back */
2817 hr = IXMLDOMComment_get_text(pComment, &str);
2818 ok(hr == S_OK, "ret %08x\n", hr );
2819 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect xml string\n");
2822 /* test length property */
2823 hr = IXMLDOMComment_get_length(pComment, &len);
2824 ok(hr == S_OK, "ret %08x\n", hr );
2825 ok(len == 21, "expected 21 got %d\n", len);
2827 /* test substringData */
2828 hr = IXMLDOMComment_substringData(pComment, 0, 4, NULL);
2829 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2831 /* test substringData - Invalid offset */
2832 str = (BSTR)&szElement;
2833 hr = IXMLDOMComment_substringData(pComment, -1, 4, &str);
2834 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2835 ok( str == NULL, "incorrect string\n");
2837 /* test substringData - Invalid offset */
2838 str = (BSTR)&szElement;
2839 hr = IXMLDOMComment_substringData(pComment, 30, 0, &str);
2840 ok(hr == S_FALSE, "ret %08x\n", hr );
2841 ok( str == NULL, "incorrect string\n");
2843 /* test substringData - Invalid size */
2844 str = (BSTR)&szElement;
2845 hr = IXMLDOMComment_substringData(pComment, 0, -1, &str);
2846 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2847 ok( str == NULL, "incorrect string\n");
2849 /* test substringData - Invalid size */
2850 str = (BSTR)&szElement;
2851 hr = IXMLDOMComment_substringData(pComment, 2, 0, &str);
2852 ok(hr == S_FALSE, "ret %08x\n", hr );
2853 ok( str == NULL, "incorrect string\n");
2855 /* test substringData - Start of string */
2856 hr = IXMLDOMComment_substringData(pComment, 0, 4, &str);
2857 ok(hr == S_OK, "ret %08x\n", hr );
2858 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
2861 /* test substringData - Middle of string */
2862 hr = IXMLDOMComment_substringData(pComment, 13, 4, &str);
2863 ok(hr == S_OK, "ret %08x\n", hr );
2864 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
2867 /* test substringData - End of string */
2868 hr = IXMLDOMComment_substringData(pComment, 20, 4, &str);
2869 ok(hr == S_OK, "ret %08x\n", hr );
2870 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
2873 /* test appendData */
2874 hr = IXMLDOMComment_appendData(pComment, NULL);
2875 ok(hr == S_OK, "ret %08x\n", hr );
2877 hr = IXMLDOMComment_appendData(pComment, _bstr_(""));
2878 ok(hr == S_OK, "ret %08x\n", hr );
2880 hr = IXMLDOMComment_appendData(pComment, _bstr_("Append"));
2881 ok(hr == S_OK, "ret %08x\n", hr );
2883 hr = IXMLDOMComment_get_text(pComment, &str);
2884 ok(hr == S_OK, "ret %08x\n", hr );
2885 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
2888 /* test insertData */
2889 str = SysAllocStringLen(NULL, 0);
2890 hr = IXMLDOMComment_insertData(pComment, -1, str);
2891 ok(hr == S_OK, "ret %08x\n", hr );
2893 hr = IXMLDOMComment_insertData(pComment, -1, NULL);
2894 ok(hr == S_OK, "ret %08x\n", hr );
2896 hr = IXMLDOMComment_insertData(pComment, 1000, str);
2897 ok(hr == S_OK, "ret %08x\n", hr );
2899 hr = IXMLDOMComment_insertData(pComment, 1000, NULL);
2900 ok(hr == S_OK, "ret %08x\n", hr );
2902 hr = IXMLDOMComment_insertData(pComment, 0, NULL);
2903 ok(hr == S_OK, "ret %08x\n", hr );
2905 hr = IXMLDOMComment_insertData(pComment, 0, str);
2906 ok(hr == S_OK, "ret %08x\n", hr );
2909 hr = IXMLDOMComment_insertData(pComment, -1, _bstr_("Inserting"));
2910 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2912 hr = IXMLDOMComment_insertData(pComment, 1000, _bstr_("Inserting"));
2913 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2915 hr = IXMLDOMComment_insertData(pComment, 0, _bstr_("Begin "));
2916 ok(hr == S_OK, "ret %08x\n", hr );
2918 hr = IXMLDOMComment_insertData(pComment, 17, _bstr_("Middle"));
2919 ok(hr == S_OK, "ret %08x\n", hr );
2921 hr = IXMLDOMComment_insertData(pComment, 39, _bstr_(" End"));
2922 ok(hr == S_OK, "ret %08x\n", hr );
2924 hr = IXMLDOMComment_get_text(pComment, &str);
2925 ok(hr == S_OK, "ret %08x\n", hr );
2926 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
2929 IXMLDOMComment_Release(pComment);
2933 hr = IXMLDOMDocument_createElement(doc, szElement, &pElement);
2934 ok(hr == S_OK, "ret %08x\n", hr );
2937 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
2938 ok(hr == S_OK, "ret %08x\n", hr );
2940 /* test nodeTypeString */
2941 hr = IXMLDOMDocument_get_nodeTypeString(pElement, &str);
2942 ok(hr == S_OK, "ret %08x\n", hr );
2943 ok( !lstrcmpW( str, _bstr_("element") ), "incorrect nodeTypeString string\n");
2946 hr = IXMLDOMElement_get_nodeName(pElement, &str);
2947 ok(hr == S_OK, "ret %08x\n", hr );
2948 ok( !lstrcmpW( str, szElement ), "incorrect element node Name\n");
2951 hr = IXMLDOMElement_get_xml(pElement, &str);
2952 ok(hr == S_OK, "ret %08x\n", hr );
2953 ok( !lstrcmpW( str, szElementXML ), "incorrect element xml\n");
2956 hr = IXMLDOMElement_get_dataType(pElement, &v);
2957 ok(hr == S_FALSE, "ret %08x\n", hr );
2958 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
2962 hr = IXMLDOMDocument_createAttribute(doc, szAttribute, &pAttrubute);
2963 ok(hr == S_OK, "ret %08x\n", hr );
2966 IXMLDOMNode *pNewChild = (IXMLDOMNode *)0x1;
2968 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, NULL);
2969 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2971 pNextChild = (IXMLDOMNode *)0x1;
2972 hr = IXMLDOMAttribute_get_nextSibling(pAttrubute, &pNextChild);
2973 ok(hr == S_FALSE, "ret %08x\n", hr );
2974 ok(pNextChild == NULL, "pNextChild not NULL\n");
2976 /* test Previous Sibling*/
2977 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, NULL);
2978 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
2980 pNextChild = (IXMLDOMNode *)0x1;
2981 hr = IXMLDOMAttribute_get_previousSibling(pAttrubute, &pNextChild);
2982 ok(hr == S_FALSE, "ret %08x\n", hr );
2983 ok(pNextChild == NULL, "pNextChild not NULL\n");
2985 /* test get_attributes */
2986 hr = IXMLDOMAttribute_get_attributes( pAttrubute, NULL );
2987 ok( hr == E_INVALIDARG, "get_attributes returned wrong code\n");
2989 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
2990 hr = IXMLDOMAttribute_get_attributes( pAttrubute, &pAttribs);
2991 ok(hr == S_FALSE, "ret %08x\n", hr );
2992 ok( pAttribs == NULL, "pAttribs not NULL\n");
2994 hr = IXMLDOMElement_appendChild(pElement, (IXMLDOMNode*)pAttrubute, &pNewChild);
2995 ok(hr == E_FAIL, "ret %08x\n", hr );
2996 ok(pNewChild == NULL, "pNewChild not NULL\n");
2998 hr = IXMLDOMElement_get_attributes(pElement, &pAttribs);
2999 ok(hr == S_OK, "ret %08x\n", hr );
3002 hr = IXMLDOMNamedNodeMap_setNamedItem(pAttribs, (IXMLDOMNode*)pAttrubute, NULL );
3003 ok(hr == S_OK, "ret %08x\n", hr );
3005 IXMLDOMNamedNodeMap_Release(pAttribs);
3008 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
3009 ok(hr == S_OK, "ret %08x\n", hr );
3010 ok( !lstrcmpW( str, szAttribute ), "incorrect attribute node Name\n");
3013 /* test nodeTypeString */
3014 hr = IXMLDOMAttribute_get_nodeTypeString(pAttrubute, &str);
3015 ok(hr == S_OK, "ret %08x\n", hr );
3016 ok( !lstrcmpW( str, _bstr_("attribute") ), "incorrect nodeTypeString string\n");
3020 hr = IXMLDOMAttribute_get_nodeName(pAttrubute, &str);
3021 ok(hr == S_OK, "ret %08x\n", hr );
3022 ok( !lstrcmpW( str, szAttribute ), "incorrect nodeName string\n");
3025 /* test name property */
3026 hr = IXMLDOMAttribute_get_name(pAttrubute, &str);
3027 ok(hr == S_OK, "ret %08x\n", hr );
3028 ok( !lstrcmpW( str, szAttribute ), "incorrect name string\n");
3031 hr = IXMLDOMAttribute_get_xml(pAttrubute, &str);
3032 ok(hr == S_OK, "ret %08x\n", hr );
3033 ok( !lstrcmpW( str, szAttributeXML ), "incorrect attribute xml\n");
3036 hr = IXMLDOMAttribute_get_dataType(pAttrubute, &v);
3037 ok(hr == S_FALSE, "ret %08x\n", hr );
3038 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3041 IXMLDOMAttribute_Release(pAttrubute);
3043 /* Check Element again with the Add Attribute*/
3044 hr = IXMLDOMElement_get_xml(pElement, &str);
3045 ok(hr == S_OK, "ret %08x\n", hr );
3046 ok( !lstrcmpW( str, szElementXML2 ), "incorrect element xml\n");
3050 hr = IXMLDOMElement_put_text(pElement, _bstr_("TestingNode"));
3051 ok(hr == S_OK, "ret %08x\n", hr );
3053 hr = IXMLDOMElement_get_xml(pElement, &str);
3054 ok(hr == S_OK, "ret %08x\n", hr );
3055 ok( !lstrcmpW( str, szElementXML3 ), "incorrect element xml\n");
3058 /* Test for reversible escaping */
3059 str = SysAllocString( szStrangeChars );
3060 hr = IXMLDOMElement_put_text(pElement, str);
3061 ok(hr == S_OK, "ret %08x\n", hr );
3062 SysFreeString( str );
3064 hr = IXMLDOMElement_get_xml(pElement, &str);
3065 ok(hr == S_OK, "ret %08x\n", hr );
3066 ok( !lstrcmpW( str, szElementXML4 ), "incorrect element xml\n");
3069 hr = IXMLDOMElement_get_text(pElement, &str);
3070 ok(hr == S_OK, "ret %08x\n", hr );
3071 ok( !lstrcmpW( str, szStrangeChars ), "incorrect element text\n");
3074 IXMLDOMElement_Release(pElement);
3078 hr = IXMLDOMDocument_createCDATASection(doc, szCData, NULL);
3079 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3081 hr = IXMLDOMDocument_createCDATASection(doc, szCData, &pCDataSec);
3082 ok(hr == S_OK, "ret %08x\n", hr );
3085 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3090 hr = IXMLDOMCDATASection_QueryInterface(pCDataSec, &IID_IXMLDOMElement, (LPVOID*)&pElement);
3091 ok(hr == E_NOINTERFACE, "ret %08x\n", hr);
3093 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pCDataSec, NULL);
3094 ok(hr == S_OK, "ret %08x\n", hr );
3096 /* get Attribute Tests */
3097 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, NULL);
3098 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3100 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3101 hr = IXMLDOMCDATASection_get_attributes(pCDataSec, &pAttribs);
3102 ok(hr == S_FALSE, "ret %08x\n", hr );
3103 ok(pAttribs == NULL, "pAttribs != NULL\n");
3105 hr = IXMLDOMCDATASection_get_nodeName(pCDataSec, &str);
3106 ok(hr == S_OK, "ret %08x\n", hr );
3107 ok( !lstrcmpW( str, szCDataNodeText ), "incorrect cdata node Name\n");
3110 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3111 ok(hr == S_OK, "ret %08x\n", hr );
3112 ok( !lstrcmpW( str, szCDataXML ), "incorrect cdata xml\n");
3115 /* test lastChild */
3116 pNextChild = (IXMLDOMNode*)0x1;
3117 hr = IXMLDOMCDATASection_get_lastChild(pCDataSec, &pNextChild);
3118 ok(hr == S_FALSE, "ret %08x\n", hr );
3119 ok(pNextChild == NULL, "pNextChild not NULL\n");
3121 /* test get_dataType */
3122 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, NULL);
3123 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3125 hr = IXMLDOMCDATASection_get_dataType(pCDataSec, &v);
3126 ok(hr == S_FALSE, "ret %08x\n", hr );
3127 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3130 /* test nodeTypeString */
3131 hr = IXMLDOMCDATASection_get_nodeTypeString(pCDataSec, &str);
3132 ok(hr == S_OK, "ret %08x\n", hr );
3133 ok( !lstrcmpW( str, _bstr_("cdatasection") ), "incorrect nodeTypeString string\n");
3136 /* put data Tests */
3137 hr = IXMLDOMCDATASection_put_data(pCDataSec, _bstr_("This &is a ; test <>\\"));
3138 ok(hr == S_OK, "ret %08x\n", hr );
3140 /* Confirm XML text is good */
3141 hr = IXMLDOMCDATASection_get_xml(pCDataSec, &str);
3142 ok(hr == S_OK, "ret %08x\n", hr );
3143 ok( !lstrcmpW( str, _bstr_("<![CDATA[This &is a ; test <>\\]]>") ), "incorrect xml string\n");
3146 /* Confirm we get the put_data Text back */
3147 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3148 ok(hr == S_OK, "ret %08x\n", hr );
3149 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3152 /* test length property */
3153 hr = IXMLDOMCDATASection_get_length(pCDataSec, &len);
3154 ok(hr == S_OK, "ret %08x\n", hr );
3155 ok(len == 21, "expected 21 got %d\n", len);
3157 /* test get nodeValue */
3158 hr = IXMLDOMCDATASection_get_nodeValue(pCDataSec, &var);
3159 ok(hr == S_OK, "ret %08x\n", hr );
3160 ok(V_VT(&var) == VT_BSTR, "got vt %04x\n", V_VT(&var));
3161 ok( !lstrcmpW( V_BSTR(&var), _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3165 hr = IXMLDOMCDATASection_get_data(pCDataSec, &str);
3166 ok(hr == S_OK, "ret %08x\n", hr );
3167 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\") ), "incorrect text string\n");
3170 /* test substringData */
3171 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, NULL);
3172 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3174 /* test substringData - Invalid offset */
3175 str = (BSTR)&szElement;
3176 hr = IXMLDOMCDATASection_substringData(pCDataSec, -1, 4, &str);
3177 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3178 ok( str == NULL, "incorrect string\n");
3180 /* test substringData - Invalid offset */
3181 str = (BSTR)&szElement;
3182 hr = IXMLDOMCDATASection_substringData(pCDataSec, 30, 0, &str);
3183 ok(hr == S_FALSE, "ret %08x\n", hr );
3184 ok( str == NULL, "incorrect string\n");
3186 /* test substringData - Invalid size */
3187 str = (BSTR)&szElement;
3188 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, -1, &str);
3189 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3190 ok( str == NULL, "incorrect string\n");
3192 /* test substringData - Invalid size */
3193 str = (BSTR)&szElement;
3194 hr = IXMLDOMCDATASection_substringData(pCDataSec, 2, 0, &str);
3195 ok(hr == S_FALSE, "ret %08x\n", hr );
3196 ok( str == NULL, "incorrect string\n");
3198 /* test substringData - Start of string */
3199 hr = IXMLDOMCDATASection_substringData(pCDataSec, 0, 4, &str);
3200 ok(hr == S_OK, "ret %08x\n", hr );
3201 ok( !lstrcmpW( str, _bstr_("This") ), "incorrect substringData string\n");
3204 /* test substringData - Middle of string */
3205 hr = IXMLDOMCDATASection_substringData(pCDataSec, 13, 4, &str);
3206 ok(hr == S_OK, "ret %08x\n", hr );
3207 ok( !lstrcmpW( str, _bstr_("test") ), "incorrect substringData string\n");
3210 /* test substringData - End of string */
3211 hr = IXMLDOMCDATASection_substringData(pCDataSec, 20, 4, &str);
3212 ok(hr == S_OK, "ret %08x\n", hr );
3213 ok( !lstrcmpW( str, _bstr_("\\") ), "incorrect substringData string\n");
3216 /* test appendData */
3217 hr = IXMLDOMCDATASection_appendData(pCDataSec, NULL);
3218 ok(hr == S_OK, "ret %08x\n", hr );
3220 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_(""));
3221 ok(hr == S_OK, "ret %08x\n", hr );
3223 hr = IXMLDOMCDATASection_appendData(pCDataSec, _bstr_("Append"));
3224 ok(hr == S_OK, "ret %08x\n", hr );
3226 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3227 ok(hr == S_OK, "ret %08x\n", hr );
3228 ok( !lstrcmpW( str, _bstr_("This &is a ; test <>\\Append") ), "incorrect get_text string\n");
3231 /* test insertData */
3232 str = SysAllocStringLen(NULL, 0);
3233 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, str);
3234 ok(hr == S_OK, "ret %08x\n", hr );
3236 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, NULL);
3237 ok(hr == S_OK, "ret %08x\n", hr );
3239 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, str);
3240 ok(hr == S_OK, "ret %08x\n", hr );
3242 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, NULL);
3243 ok(hr == S_OK, "ret %08x\n", hr );
3245 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, NULL);
3246 ok(hr == S_OK, "ret %08x\n", hr );
3248 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, str);
3249 ok(hr == S_OK, "ret %08x\n", hr );
3252 hr = IXMLDOMCDATASection_insertData(pCDataSec, -1, _bstr_("Inserting"));
3253 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3255 hr = IXMLDOMCDATASection_insertData(pCDataSec, 1000, _bstr_("Inserting"));
3256 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3258 hr = IXMLDOMCDATASection_insertData(pCDataSec, 0, _bstr_("Begin "));
3259 ok(hr == S_OK, "ret %08x\n", hr );
3261 hr = IXMLDOMCDATASection_insertData(pCDataSec, 17, _bstr_("Middle"));
3262 ok(hr == S_OK, "ret %08x\n", hr );
3264 hr = IXMLDOMCDATASection_insertData(pCDataSec, 39, _bstr_(" End"));
3265 ok(hr == S_OK, "ret %08x\n", hr );
3267 hr = IXMLDOMCDATASection_get_text(pCDataSec, &str);
3268 ok(hr == S_OK, "ret %08x\n", hr );
3269 ok( !lstrcmpW( str, _bstr_("Begin This &is a Middle; test <>\\Append End") ), "incorrect get_text string\n");
3272 IXMLDOMCDATASection_Release(pCDataSec);
3275 /* Document Fragments */
3276 hr = IXMLDOMDocument_createDocumentFragment(doc, NULL);
3277 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3279 hr = IXMLDOMDocument_createDocumentFragment(doc, &pDocFrag);
3280 ok(hr == S_OK, "ret %08x\n", hr );
3283 IXMLDOMNode *pNextChild = (IXMLDOMNode *)0x1;
3285 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pDocFrag, NULL);
3286 ok(hr == S_OK, "ret %08x\n", hr );
3288 /* get Attribute Tests */
3289 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, NULL);
3290 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3292 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3293 hr = IXMLDOMDocumentFragment_get_attributes(pDocFrag, &pAttribs);
3294 ok(hr == S_FALSE, "ret %08x\n", hr );
3295 ok(pAttribs == NULL, "pAttribs != NULL\n");
3297 hr = IXMLDOMDocumentFragment_get_nodeName(pDocFrag, &str);
3298 ok(hr == S_OK, "ret %08x\n", hr );
3299 ok( !lstrcmpW( str, szDocFragmentText ), "incorrect docfragment node Name\n");
3302 /* test next Sibling*/
3303 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, NULL);
3304 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3306 pNextChild = (IXMLDOMNode *)0x1;
3307 hr = IXMLDOMDocumentFragment_get_nextSibling(pDocFrag, &pNextChild);
3308 ok(hr == S_FALSE, "ret %08x\n", hr );
3309 ok(pNextChild == NULL, "pNextChild not NULL\n");
3311 /* test Previous Sibling*/
3312 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, NULL);
3313 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3315 pNextChild = (IXMLDOMNode *)0x1;
3316 hr = IXMLDOMDocumentFragment_get_previousSibling(pDocFrag, &pNextChild);
3317 ok(hr == S_FALSE, "ret %08x\n", hr );
3318 ok(pNextChild == NULL, "pNextChild not NULL\n");
3320 /* test get_dataType */
3321 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, NULL);
3322 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3324 hr = IXMLDOMDocumentFragment_get_dataType(pDocFrag, &v);
3325 ok(hr == S_FALSE, "ret %08x\n", hr );
3326 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3329 /* test nodeTypeString */
3330 hr = IXMLDOMDocumentFragment_get_nodeTypeString(pDocFrag, &str);
3331 ok(hr == S_OK, "ret %08x\n", hr );
3332 ok( !lstrcmpW( str, _bstr_("documentfragment") ), "incorrect nodeTypeString string\n");
3335 IXMLDOMDocumentFragment_Release(pDocFrag);
3338 /* Entity References */
3339 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, NULL);
3340 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3342 hr = IXMLDOMDocument_createEntityReference(doc, szEntityRef, &pEntityRef);
3343 ok(hr == S_OK, "ret %08x\n", hr );
3346 hr = IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pEntityRef, NULL);
3347 ok(hr == S_OK, "ret %08x\n", hr );
3349 /* get Attribute Tests */
3350 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, NULL);
3351 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3353 pAttribs = (IXMLDOMNamedNodeMap*)0x1;
3354 hr = IXMLDOMEntityReference_get_attributes(pEntityRef, &pAttribs);
3355 ok(hr == S_FALSE, "ret %08x\n", hr );
3356 ok(pAttribs == NULL, "pAttribs != NULL\n");
3359 hr = IXMLDOMEntityReference_get_dataType(pEntityRef, &v);
3360 ok(hr == S_FALSE, "ret %08x\n", hr );
3361 ok( V_VT(&v) == VT_NULL, "incorrect dataType type\n");
3364 /* test nodeTypeString */
3365 hr = IXMLDOMEntityReference_get_nodeTypeString(pEntityRef, &str);
3366 ok(hr == S_OK, "ret %08x\n", hr );
3367 ok( !lstrcmpW( str, _bstr_("entityreference") ), "incorrect nodeTypeString string\n");
3371 hr = IXMLDOMEntityReference_get_xml(pEntityRef, &str);
3372 ok(hr == S_OK, "ret %08x\n", hr );
3373 ok( !lstrcmpW( str, szEntityRefXML ), "incorrect xml string\n");
3376 IXMLDOMEntityReference_Release(pEntityRef);
3379 IXMLDOMElement_Release( pRoot );
3383 IXMLDOMDocument_Release(doc);
3388 static void test_nodeTypeTests( void )
3390 IXMLDOMDocument *doc = NULL;
3391 IXMLDOMElement *pRoot;
3392 IXMLDOMElement *pElement;
3395 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3399 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3400 ok(hr == S_OK, "ret %08x\n", hr );
3403 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3404 ok(hr == S_OK, "ret %08x\n", hr );
3407 hr = IXMLDOMElement_put_dataType(pRoot, NULL);
3408 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3411 hr = IXMLDOMElement_put_dataType(pRoot, _bstr_("abcdefg") );
3412 ok(hr == E_FAIL, "ret %08x\n", hr );
3415 * The name passed into put_dataType is case-insensitive. So many of the names
3416 * have been changed to reflect this.
3419 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Boolean"), &pElement);
3420 ok(hr == S_OK, "ret %08x\n", hr );
3423 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3425 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Boolean") );
3426 ok(hr == S_OK, "ret %08x\n", hr );
3428 IXMLDOMElement_Release(pElement);
3432 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_String"), &pElement);
3433 ok(hr == S_OK, "ret %08x\n", hr );
3436 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3438 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("String") );
3439 ok(hr == S_OK, "ret %08x\n", hr );
3441 IXMLDOMElement_Release(pElement);
3445 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Number"), &pElement);
3446 ok(hr == S_OK, "ret %08x\n", hr );
3449 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3451 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("number") );
3452 ok(hr == S_OK, "ret %08x\n", hr );
3454 IXMLDOMElement_Release(pElement);
3458 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Int"), &pElement);
3459 ok(hr == S_OK, "ret %08x\n", hr );
3462 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3464 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("InT") );
3465 ok(hr == S_OK, "ret %08x\n", hr );
3467 IXMLDOMElement_Release(pElement);
3471 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Fixed"), &pElement);
3472 ok(hr == S_OK, "ret %08x\n", hr );
3475 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3477 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("fixed.14.4") );
3478 ok(hr == S_OK, "ret %08x\n", hr );
3480 IXMLDOMElement_Release(pElement);
3484 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime"), &pElement);
3485 ok(hr == S_OK, "ret %08x\n", hr );
3488 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3490 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime") );
3491 ok(hr == S_OK, "ret %08x\n", hr );
3493 IXMLDOMElement_Release(pElement);
3497 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_DateTime_tz"), &pElement);
3498 ok(hr == S_OK, "ret %08x\n", hr );
3501 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3503 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3504 ok(hr == S_OK, "ret %08x\n", hr );
3506 IXMLDOMElement_Release(pElement);
3510 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Date"), &pElement);
3511 ok(hr == S_OK, "ret %08x\n", hr );
3514 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3516 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Date") );
3517 ok(hr == S_OK, "ret %08x\n", hr );
3519 IXMLDOMElement_Release(pElement);
3523 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time"), &pElement);
3524 ok(hr == S_OK, "ret %08x\n", hr );
3527 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3529 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time") );
3530 ok(hr == S_OK, "ret %08x\n", hr );
3532 IXMLDOMElement_Release(pElement);
3536 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Time_TZ"), &pElement);
3537 ok(hr == S_OK, "ret %08x\n", hr );
3540 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3542 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("Time.tz") );
3543 ok(hr == S_OK, "ret %08x\n", hr );
3545 IXMLDOMElement_Release(pElement);
3549 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I1"), &pElement);
3550 ok(hr == S_OK, "ret %08x\n", hr );
3553 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3555 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I1") );
3556 ok(hr == S_OK, "ret %08x\n", hr );
3558 IXMLDOMElement_Release(pElement);
3562 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I2"), &pElement);
3563 ok(hr == S_OK, "ret %08x\n", hr );
3566 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3568 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I2") );
3569 ok(hr == S_OK, "ret %08x\n", hr );
3571 IXMLDOMElement_Release(pElement);
3575 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_I4"), &pElement);
3576 ok(hr == S_OK, "ret %08x\n", hr );
3579 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3581 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("I4") );
3582 ok(hr == S_OK, "ret %08x\n", hr );
3584 IXMLDOMElement_Release(pElement);
3588 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI1"), &pElement);
3589 ok(hr == S_OK, "ret %08x\n", hr );
3592 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3594 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI1") );
3595 ok(hr == S_OK, "ret %08x\n", hr );
3597 IXMLDOMElement_Release(pElement);
3601 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI2"), &pElement);
3602 ok(hr == S_OK, "ret %08x\n", hr );
3605 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3607 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI2") );
3608 ok(hr == S_OK, "ret %08x\n", hr );
3610 IXMLDOMElement_Release(pElement);
3614 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_UI4"), &pElement);
3615 ok(hr == S_OK, "ret %08x\n", hr );
3618 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3620 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UI4") );
3621 ok(hr == S_OK, "ret %08x\n", hr );
3623 IXMLDOMElement_Release(pElement);
3627 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r4"), &pElement);
3628 ok(hr == S_OK, "ret %08x\n", hr );
3631 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3633 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r4") );
3634 ok(hr == S_OK, "ret %08x\n", hr );
3636 IXMLDOMElement_Release(pElement);
3640 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_r8"), &pElement);
3641 ok(hr == S_OK, "ret %08x\n", hr );
3644 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3646 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("r8") );
3647 ok(hr == S_OK, "ret %08x\n", hr );
3649 IXMLDOMElement_Release(pElement);
3653 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_float"), &pElement);
3654 ok(hr == S_OK, "ret %08x\n", hr );
3657 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3659 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("float") );
3660 ok(hr == S_OK, "ret %08x\n", hr );
3662 IXMLDOMElement_Release(pElement);
3666 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_uuid"), &pElement);
3667 ok(hr == S_OK, "ret %08x\n", hr );
3670 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3672 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("UuId") );
3673 ok(hr == S_OK, "ret %08x\n", hr );
3675 IXMLDOMElement_Release(pElement);
3679 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_hex"), &pElement);
3680 ok(hr == S_OK, "ret %08x\n", hr );
3683 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3685 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.hex") );
3686 ok(hr == S_OK, "ret %08x\n", hr );
3688 IXMLDOMElement_Release(pElement);
3692 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_bin_base64"), &pElement);
3693 ok(hr == S_OK, "ret %08x\n", hr );
3696 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3698 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("bin.base64") );
3699 ok(hr == S_OK, "ret %08x\n", hr );
3701 IXMLDOMElement_Release(pElement);
3704 /* Check changing types */
3705 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing_Change"), &pElement);
3706 ok(hr == S_OK, "ret %08x\n", hr );
3709 IXMLDOMElement_appendChild(pRoot, (IXMLDOMNode*)pElement, NULL);
3711 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("DateTime.tz") );
3712 ok(hr == S_OK, "ret %08x\n", hr );
3714 hr = IXMLDOMElement_put_dataType(pElement, _bstr_("string") );
3715 ok(hr == S_OK, "ret %08x\n", hr );
3717 IXMLDOMElement_Release(pElement);
3720 IXMLDOMElement_Release(pRoot);
3724 IXMLDOMDocument_Release(doc);
3729 static void test_DocumentSaveToDocument(void)
3731 IXMLDOMDocument *doc = NULL;
3732 IXMLDOMDocument *doc2 = NULL;
3733 IXMLDOMElement *pRoot;
3737 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3741 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
3744 IXMLDOMDocument_Release(doc);
3748 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3749 ok(hr == S_OK, "ret %08x\n", hr );
3752 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3753 ok(hr == S_OK, "ret %08x\n", hr );
3760 V_VT(&vDoc) = VT_UNKNOWN;
3761 V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
3763 hr = IXMLDOMDocument_save(doc, vDoc);
3764 ok(hr == S_OK, "ret %08x\n", hr );
3766 hr = IXMLDOMDocument_get_xml(doc, &sOrig);
3767 ok(hr == S_OK, "ret %08x\n", hr );
3769 hr = IXMLDOMDocument_get_xml(doc2, &sNew);
3770 ok(hr == S_OK, "ret %08x\n", hr );
3772 ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
3774 SysFreeString(sOrig);
3775 SysFreeString(sNew);
3779 IXMLDOMDocument_Release(doc2);
3780 IXMLDOMDocument_Release(doc);
3783 static void test_DocumentSaveToFile(void)
3785 IXMLDOMDocument *doc = NULL;
3786 IXMLDOMElement *pRoot;
3792 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3796 hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
3797 ok(hr == S_OK, "ret %08x\n", hr );
3800 hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
3801 ok(hr == S_OK, "ret %08x\n", hr );
3806 V_VT(&vFile) = VT_BSTR;
3807 V_BSTR(&vFile) = _bstr_("test.xml");
3809 hr = IXMLDOMDocument_save(doc, vFile);
3810 ok(hr == S_OK, "ret %08x\n", hr );
3814 IXMLDOMElement_Release(pRoot);
3815 IXMLDOMDocument_Release(doc);
3817 file = CreateFile("test.xml", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
3818 ok(file != INVALID_HANDLE_VALUE, "Could not open file: %u\n", GetLastError());
3819 if(file == INVALID_HANDLE_VALUE)
3822 ReadFile(file, buffer, sizeof(buffer), &read, NULL);
3823 ok(read != 0, "could not read file\n");
3824 ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n");
3827 DeleteFile("test.xml");
3830 static void test_testTransforms(void)
3832 IXMLDOMDocument *doc = NULL;
3833 IXMLDOMDocument *docSS = NULL;
3839 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3843 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&docSS );
3846 IXMLDOMDocument_Release(doc);
3850 hr = IXMLDOMDocument_loadXML(doc, _bstr_(szTransformXML), &bSucc);
3851 ok(hr == S_OK, "ret %08x\n", hr );
3853 hr = IXMLDOMDocument_loadXML(docSS, _bstr_(szTransformSSXML), &bSucc);
3854 ok(hr == S_OK, "ret %08x\n", hr );
3856 hr = IXMLDOMDocument_QueryInterface(docSS, &IID_IXMLDOMNode, (LPVOID*)&pNode );
3857 ok(hr == S_OK, "ret %08x\n", hr );
3862 hr = IXMLDOMDocument_transformNode(doc, pNode, &bOut);
3863 ok(hr == S_OK, "ret %08x\n", hr );
3864 ok( compareIgnoreReturns( bOut, _bstr_(szTransformOutput)), "Stylesheet output not correct\n");
3865 SysFreeString(bOut);
3867 IXMLDOMNode_Release(pNode);
3870 IXMLDOMDocument_Release(docSS);
3871 IXMLDOMDocument_Release(doc);
3876 static void test_Namespaces(void)
3878 IXMLDOMDocument2 *doc = NULL;
3880 IXMLDOMNode *pNode2 = NULL;
3884 static const CHAR szNamespacesXML[] =
3885 "<?xml version=\"1.0\"?>\n"
3886 "<root xmlns:WEB='http://www.winehq.org'>\n"
3887 "<WEB:Site version=\"1.0\" />\n"
3890 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3894 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szNamespacesXML), &bSucc);
3895 ok(hr == S_OK, "ret %08x\n", hr );
3896 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3898 hr = IXMLDOMDocument_selectSingleNode(doc, _bstr_("root"), &pNode );
3899 ok(hr == S_OK, "ret %08x\n", hr );
3902 hr = IXMLDOMNode_get_firstChild( pNode, &pNode2 );
3903 ok( hr == S_OK, "ret %08x\n", hr );
3904 ok( pNode2 != NULL, "pNode2 == NULL\n");
3906 /* Test get_prefix */
3907 hr = IXMLDOMNode_get_prefix(pNode2, NULL);
3908 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3909 /* NOTE: Need to test that arg2 gets cleared on Error. */
3911 hr = IXMLDOMNode_get_prefix(pNode2, &str);
3912 ok( hr == S_OK, "ret %08x\n", hr );
3913 ok( !lstrcmpW( str, _bstr_("WEB")), "incorrect prefix string\n");
3916 /* Test get_namespaceURI */
3917 hr = IXMLDOMNode_get_namespaceURI(pNode2, NULL);
3918 ok( hr == E_INVALIDARG, "ret %08x\n", hr );
3919 /* NOTE: Need to test that arg2 gets cleared on Error. */
3921 hr = IXMLDOMNode_get_namespaceURI(pNode2, &str);
3922 ok( hr == S_OK, "ret %08x\n", hr );
3923 ok( !lstrcmpW( str, _bstr_("http://www.winehq.org")), "incorrect namespaceURI string\n");
3926 IXMLDOMNode_Release(pNode2);
3927 IXMLDOMNode_Release(pNode);
3930 IXMLDOMDocument2_Release(doc);
3935 static void test_FormattingXML(void)
3937 IXMLDOMDocument2 *doc = NULL;
3938 IXMLDOMElement *pElement;
3942 static const CHAR szLinefeedXML[] = "<?xml version=\"1.0\"?>\n<Root>\n\t<Sub val=\"A\" />\n</Root>";
3943 static const CHAR szLinefeedRootXML[] = "<Root>\r\n\t<Sub val=\"A\"/>\r\n</Root>";
3945 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3949 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szLinefeedXML), &bSucc);
3950 ok(hr == S_OK, "ret %08x\n", hr );
3951 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3953 if(bSucc == VARIANT_TRUE)
3955 hr = IXMLDOMDocument2_get_documentElement(doc, &pElement);
3956 ok(hr == S_OK, "ret %08x\n", hr );
3959 hr = IXMLDOMElement_get_xml(pElement, &str);
3960 ok(hr == S_OK, "ret %08x\n", hr );
3961 ok( !lstrcmpW( str, _bstr_(szLinefeedRootXML) ), "incorrect element xml\n");
3964 IXMLDOMElement_Release(pElement);
3968 IXMLDOMDocument2_Release(doc);
3973 static void test_NodeTypeValue(void)
3975 IXMLDOMDocument2 *doc = NULL;
3981 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
3985 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
3986 ok(hr == S_OK, "ret %08x\n", hr );
3987 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
3988 if(bSucc == VARIANT_TRUE)
3990 hr = IXMLDOMDocument2_get_nodeValue(doc, NULL);
3991 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
3995 hr = IXMLDOMDocument2_get_nodeValue(doc, &v);
3996 ok(hr == S_FALSE, "ret %08x\n", hr );
3997 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
3999 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, NULL);
4000 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4002 hr = IXMLDOMDocument2_get_nodeTypedValue(doc, &v);
4003 ok(hr == S_FALSE, "ret %08x\n", hr );
4005 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string"), &pNode);
4006 ok(hr == S_OK, "ret %08x\n", hr );
4011 hr = IXMLDOMNode_get_nodeValue(pNode, &v);
4012 ok(hr == S_FALSE, "ret %08x\n", hr );
4013 ok(V_VT(&v) == VT_NULL, "expect VT_NULL got %d\n", V_VT(&v));
4015 hr = IXMLDOMNode_get_nodeTypedValue(pNode, NULL);
4016 ok(hr == E_INVALIDARG, "ret %08x\n", hr );
4018 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4019 ok(hr == S_OK, "ret %08x\n", hr );
4020 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4021 ok(!lstrcmpW( V_BSTR(&v), _bstr_("Wine") ), "incorrect value\n");
4024 IXMLDOMNode_Release(pNode);
4027 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/string2"), &pNode);
4028 ok(hr == S_OK, "ret %08x\n", hr );
4031 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4032 ok(hr == S_OK, "ret %08x\n", hr );
4033 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4034 ok(!lstrcmpW( V_BSTR(&v), _bstr_("String") ), "incorrect value\n");
4037 IXMLDOMNode_Release(pNode);
4040 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number"), &pNode);
4041 ok(hr == S_OK, "ret %08x\n", hr );
4044 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4045 ok(hr == S_OK, "ret %08x\n", hr );
4046 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4047 ok(!lstrcmpW( V_BSTR(&v), _bstr_("12.44") ), "incorrect value\n");
4050 IXMLDOMNode_Release(pNode);
4053 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/number2"), &pNode);
4054 ok(hr == S_OK, "ret %08x\n", hr );
4057 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4058 ok(hr == S_OK, "ret %08x\n", hr );
4059 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4060 ok(!lstrcmpW( V_BSTR(&v), _bstr_("-3.71e3") ), "incorrect value\n");
4063 IXMLDOMNode_Release(pNode);
4066 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/int"), &pNode);
4067 ok(hr == S_OK, "ret %08x\n", hr );
4070 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4071 ok(hr == S_OK, "ret %08x\n", hr );
4072 ok(V_VT(&v) == VT_I4, "incorrect type\n");
4073 ok(V_I4(&v) == -13, "incorrect value\n");
4076 IXMLDOMNode_Release(pNode);
4079 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/fixed"), &pNode);
4080 ok(hr == S_OK, "ret %08x\n", hr );
4083 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4084 ok(hr == S_OK, "ret %08x\n", hr );
4085 ok(V_VT(&v) == VT_CY, "incorrect type\n");
4088 IXMLDOMNode_Release(pNode);
4091 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/bool"), &pNode);
4092 ok(hr == S_OK, "ret %08x\n", hr );
4095 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4096 ok(hr == S_OK, "ret %08x\n", hr );
4097 ok(V_VT(&v) == VT_BOOL, "incorrect type\n");
4098 ok(V_BOOL(&v) == VARIANT_TRUE, "incorrect value\n");
4101 IXMLDOMNode_Release(pNode);
4104 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/datetime"), &pNode);
4105 ok(hr == S_OK, "ret %08x\n", hr );
4108 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4109 ok(hr == S_OK, "ret %08x\n", hr );
4110 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4111 double_eq(40135.13996527778, V_DATE(&v));
4114 IXMLDOMNode_Release(pNode);
4117 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/datetimetz"), &pNode);
4118 ok(hr == S_OK, "ret %08x\n", hr );
4121 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4122 ok(hr == S_OK, "ret %08x\n", hr );
4123 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4124 double_eq(37813.59302083334, V_DATE(&v));
4127 IXMLDOMNode_Release(pNode);
4130 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/date"), &pNode);
4131 ok(hr == S_OK, "ret %08x\n", hr );
4134 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4135 ok(hr == S_OK, "ret %08x\n", hr );
4136 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4137 double_eq(665413.0, V_DATE(&v));
4140 IXMLDOMNode_Release(pNode);
4143 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/time"), &pNode);
4144 ok(hr == S_OK, "ret %08x\n", hr );
4147 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4148 ok(hr == S_OK, "ret %08x\n", hr );
4149 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4150 double_eq(0.5813888888888888, V_DATE(&v));
4153 IXMLDOMNode_Release(pNode);
4156 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/timetz"), &pNode);
4157 ok(hr == S_OK, "ret %08x\n", hr );
4160 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4161 ok(hr == S_OK, "ret %08x\n", hr );
4162 ok(V_VT(&v) == VT_DATE, "incorrect type\n");
4163 double_eq(1.112511574074074, V_DATE(&v));
4166 IXMLDOMNode_Release(pNode);
4169 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i1"), &pNode);
4170 ok(hr == S_OK, "ret %08x\n", hr );
4173 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4174 ok(hr == S_OK, "ret %08x\n", hr );
4175 ok(V_VT(&v) == VT_I1, "incorrect type\n");
4176 ok(V_I1(&v) == -13, "incorrect value\n");
4179 IXMLDOMNode_Release(pNode);
4182 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i2"), &pNode);
4183 ok(hr == S_OK, "ret %08x\n", hr );
4186 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4187 ok(hr == S_OK, "ret %08x\n", hr );
4188 ok(V_VT(&v) == VT_I2, "incorrect type\n");
4189 ok(V_I2(&v) == 31915, "incorrect value\n");
4192 IXMLDOMNode_Release(pNode);
4195 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/i4"), &pNode);
4196 ok(hr == S_OK, "ret %08x\n", hr );
4199 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4200 ok(hr == S_OK, "ret %08x\n", hr );
4201 ok(V_VT(&v) == VT_I4, "incorrect type\n");
4202 ok(V_I4(&v) == -312232, "incorrect value\n");
4205 IXMLDOMNode_Release(pNode);
4208 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui1"), &pNode);
4209 ok(hr == S_OK, "ret %08x\n", hr );
4212 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4213 ok(hr == S_OK, "ret %08x\n", hr );
4214 ok(V_VT(&v) == VT_UI1, "incorrect type\n");
4215 ok(V_UI1(&v) == 123, "incorrect value\n");
4218 IXMLDOMNode_Release(pNode);
4221 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui2"), &pNode);
4222 ok(hr == S_OK, "ret %08x\n", hr );
4225 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4226 ok(hr == S_OK, "ret %08x\n", hr );
4227 ok(V_VT(&v) == VT_UI2, "incorrect type\n");
4228 ok(V_UI2(&v) == 48282, "incorrect value\n");
4231 IXMLDOMNode_Release(pNode);
4234 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/ui4"), &pNode);
4235 ok(hr == S_OK, "ret %08x\n", hr );
4238 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4239 ok(hr == S_OK, "ret %08x\n", hr );
4240 ok(V_VT(&v) == VT_UI4, "incorrect type\n");
4241 ok(V_UI4(&v) == 949281, "incorrect value\n");
4244 IXMLDOMNode_Release(pNode);
4247 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/r4"), &pNode);
4248 ok(hr == S_OK, "ret %08x\n", hr );
4251 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4252 ok(hr == S_OK, "ret %08x\n", hr );
4253 ok(V_VT(&v) == VT_R4, "incorrect type\n");
4254 double_eq(213124.0, V_R4(&v));
4257 IXMLDOMNode_Release(pNode);
4260 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/r8"), &pNode);
4261 ok(hr == S_OK, "ret %08x\n", hr );
4264 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4265 ok(hr == S_OK, "ret %08x\n", hr );
4266 ok(V_VT(&v) == VT_R8, "incorrect type\n");
4267 double_eq(0.412, V_R8(&v));
4270 IXMLDOMNode_Release(pNode);
4273 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/float"), &pNode);
4274 ok(hr == S_OK, "ret %08x\n", hr );
4277 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4278 ok(hr == S_OK, "ret %08x\n", hr );
4279 ok(V_VT(&v) == VT_R8, "incorrect type\n");
4280 double_eq(41221.421, V_R8(&v));
4283 IXMLDOMNode_Release(pNode);
4286 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/uuid"), &pNode);
4287 ok(hr == S_OK, "ret %08x\n", hr );
4290 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4291 ok(hr == S_OK, "ret %08x\n", hr );
4292 ok(V_VT(&v) == VT_BSTR, "incorrect type\n");
4293 ok(!lstrcmpW(V_BSTR(&v), _bstr_("333C7BC4-460F-11D0-BC04-0080C7055a83")), "incorrect value\n");
4296 IXMLDOMNode_Release(pNode);
4299 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/binhex"), &pNode);
4300 ok(hr == S_OK, "ret %08x\n", hr );
4303 BYTE bytes[] = {0xff,0xfc,0xa0,0x12,0x00,0x3c};
4305 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4306 ok(hr == S_OK, "ret %08x\n", hr );
4307 ok(V_VT(&v) == (VT_ARRAY|VT_UI1), "incorrect type\n");
4308 ok(V_ARRAY(&v)->rgsabound[0].cElements == 6, "incorrect array size\n");
4309 if(V_ARRAY(&v)->rgsabound[0].cElements == 6)
4310 ok(!memcmp(bytes, V_ARRAY(&v)->pvData, sizeof(bytes)), "incorrect value\n");
4313 IXMLDOMNode_Release(pNode);
4316 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("root/binbase64"), &pNode);
4317 ok(hr == S_OK, "ret %08x\n", hr );
4320 BYTE bytes[] = {0x62,0x61,0x73,0x65,0x36,0x34,0x20,0x74,0x65,0x73,0x74};
4322 hr = IXMLDOMNode_get_nodeTypedValue(pNode, &v);
4323 ok(hr == S_OK, "ret %08x\n", hr );
4324 ok(V_VT(&v) == (VT_ARRAY|VT_UI1), "incorrect type\n");
4325 ok(V_ARRAY(&v)->rgsabound[0].cElements == 11, "incorrect array size\n");
4326 if(V_ARRAY(&v)->rgsabound[0].cElements == 11)
4327 ok(!memcmp(bytes, V_ARRAY(&v)->pvData, sizeof(bytes)), "incorrect value\n");
4330 IXMLDOMNode_Release(pNode);
4334 IXMLDOMDocument2_Release(doc);
4339 static void test_TransformWithLoadingLocalFile(void)
4341 IXMLDOMDocument2 *doc = NULL;
4342 IXMLDOMDocument2 *xsl = NULL;
4348 char lpPathBuffer[MAX_PATH];
4351 /* Create a Temp File. */
4352 GetTempPathA(MAX_PATH, lpPathBuffer);
4353 strcat(lpPathBuffer, "customers.xml" );
4355 file = CreateFile(lpPathBuffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
4356 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
4357 if(file == INVALID_HANDLE_VALUE)
4360 WriteFile(file, szBasicTransformXML, strlen(szBasicTransformXML), &dwWritten, NULL);
4363 /* Correct path to not include a escape character. */
4364 for(i=0; i < strlen(lpPathBuffer); i++)
4366 if(lpPathBuffer[i] == '\\')
4367 lpPathBuffer[i] = '/';
4370 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
4374 hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&xsl );
4377 IXMLDOMDocument2_Release(doc);
4381 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szTypeValueXML), &bSucc);
4382 ok(hr == S_OK, "ret %08x\n", hr );
4383 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4384 if(bSucc == VARIANT_TRUE)
4387 BSTR sPart1 = _bstr_(szBasicTransformSSXMLPart1);
4388 BSTR sPart2 = _bstr_(szBasicTransformSSXMLPart2);
4389 BSTR sFileName = _bstr_(lpPathBuffer);
4390 int nLegnth = lstrlenW(sPart1) + lstrlenW(sPart2) + lstrlenW(sFileName) + 1;
4392 sXSL = SysAllocStringLen(NULL, nLegnth);
4393 lstrcpyW(sXSL, sPart1);
4394 lstrcatW(sXSL, sFileName);
4395 lstrcatW(sXSL, sPart2);
4397 hr = IXMLDOMDocument2_loadXML(xsl, sXSL, &bSucc);
4398 ok(hr == S_OK, "ret %08x\n", hr );
4399 ok(bSucc == VARIANT_TRUE, "Expected VARIANT_TRUE got VARIANT_FALSE\n");
4400 if(bSucc == VARIANT_TRUE)
4404 hr = IXMLDOMDocument_QueryInterface(xsl, &IID_IXMLDOMNode, (LPVOID*)&pNode );
4405 ok(hr == S_OK, "ret %08x\n", hr );
4408 /* This will load the temp file via the XSL */
4409 hr = IXMLDOMDocument2_transformNode(doc, pNode, &sResult);
4410 ok(hr == S_OK, "ret %08x\n", hr );
4413 ok( compareIgnoreReturns( sResult, _bstr_(szBasicTransformOutput)), "Stylesheet output not correct\n");
4414 SysFreeString(sResult);
4417 IXMLDOMNode_Release(pNode);
4421 SysFreeString(sXSL);
4424 IXMLDOMDocument2_Release(doc);
4425 IXMLDOMDocument2_Release(xsl);
4427 DeleteFile(lpPathBuffer);
4435 r = CoInitialize( NULL );
4436 ok( r == S_OK, "failed to init com\n");
4442 test_getElementsByTagName();
4444 test_get_childNodes();
4446 test_replaceChild();
4447 test_removeNamedItem();
4449 test_IXMLDOMDocument2();
4453 test_nodeTypeTests();
4454 test_DocumentSaveToDocument();
4455 test_DocumentSaveToFile();
4456 test_testTransforms();
4458 test_FormattingXML();
4459 test_NodeTypeValue();
4460 test_TransformWithLoadingLocalFile();