4 * Copyright 2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/test.h"
32 static const WCHAR szEmpty
[] = { 0 };
33 static const WCHAR szIncomplete
[] = {
34 '<','?','x','m','l',' ',
35 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',0
37 static const WCHAR szComplete1
[] = {
38 '<','?','x','m','l',' ',
39 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
40 '<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
42 static const WCHAR szComplete2
[] = {
43 '<','?','x','m','l',' ',
44 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
45 '<','o','>','<','/','o','>','\n',0
47 static const WCHAR szComplete3
[] = {
48 '<','?','x','m','l',' ',
49 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>','\n',
50 '<','a','>','<','/','a','>','\n',0
52 static const WCHAR szComplete4
[] = {
53 '<','?','x','m','l',' ',
54 'v','e','r','s','i','o','n','=','\'','1','.','0','\'','?','>',
55 '<','l','c',' ','d','l','=','\'','s','t','r','1','\'','>',
56 '<','b','s',' ','v','r','=','\'','s','t','r','2','\'',' ',
57 's','z','=','\'','1','2','3','4','\'','>','f','n','1','.','t','x','t','<','/','b','s','>',
58 '<','p','r',' ','i','d','=','\'','s','t','r','3','\'',' ',
59 'v','r','=','\'','1','.','2','.','3','\'',' ',
60 'p','n','=','\'','w','i','n','e',' ','2','0','0','5','0','8','0','4','\'','>',
61 'f','n','2','.','t','x','t','<','/','p','r','>',
62 '<','/','l','c','>','\n',0
64 static const WCHAR szNonExistentFile
[] = {
65 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', '.', 'x', 'm', 'l', 0
68 static const WCHAR szOpen
[] = { 'o','p','e','n',0 };
69 static const WCHAR szdl
[] = { 'd','l',0 };
70 static const WCHAR szlc
[] = { 'l','c',0 };
71 static const WCHAR szbs
[] = { 'b','s',0 };
73 const GUID CLSID_DOMDocument
=
74 { 0x2933BF90, 0x7B36, 0x11d2, {0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
75 const GUID IID_IXMLDOMDocument
=
76 { 0x2933BF81, 0x7B36, 0x11d2, {0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
78 void test_domdoc( void )
81 IXMLDOMDocument
*doc
= NULL
;
82 IXMLDOMElement
*element
= NULL
;
87 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
88 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
92 /* try some stupid things */
93 r
= IXMLDOMDocument_loadXML( doc
, NULL
, NULL
);
94 ok( r
== S_FALSE
, "loadXML failed\n");
97 r
= IXMLDOMDocument_loadXML( doc
, NULL
, &b
);
98 ok( r
== S_FALSE
, "loadXML failed\n");
99 ok( b
== VARIANT_FALSE
, "failed to load XML string\n");
101 /* try to laod an document from an non-existent file */
103 str
= SysAllocString ( szNonExistentFile
);
105 V_VT(&var
) = VT_BSTR
;
108 r
= IXMLDOMDocument_load( doc
, var
, &b
);
109 ok( r
== S_FALSE
, "load (from file) failed\n");
110 ok( b
== VARIANT_FALSE
, "failed to load XML file\n");
111 SysFreeString( str
);
113 /* try load an empty document */
115 str
= SysAllocString( szEmpty
);
116 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
117 ok( r
== S_FALSE
, "loadXML failed\n");
118 ok( b
== VARIANT_FALSE
, "failed to load XML string\n");
119 SysFreeString( str
);
121 /* check that there's no document element */
123 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
124 ok( r
== S_FALSE
, "should be no document element\n");
127 str
= SysAllocString( szIncomplete
);
128 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
129 ok( r
== S_FALSE
, "loadXML failed\n");
130 ok( b
== VARIANT_FALSE
, "failed to load XML string\n");
131 SysFreeString( str
);
133 /* check that there's no document element */
134 element
= (IXMLDOMElement
*)1;
135 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
136 ok( r
== S_FALSE
, "should be no document element\n");
137 ok( element
== NULL
, "Element should be NULL\n");
139 /* try to load something valid */
141 str
= SysAllocString( szComplete1
);
142 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
143 ok( r
== S_OK
, "loadXML failed\n");
144 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
145 SysFreeString( str
);
147 /* try with a null out pointer - crashes */
150 r
= IXMLDOMDocument_get_documentElement( doc
, NULL
);
151 ok( r
== S_OK
, "should be no document element\n");
154 /* check that there's no document element */
156 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
157 ok( r
== S_OK
, "should be a document element\n");
162 /* check if the tag is correct */
163 r
= IXMLDOMElement_get_tagName( element
, &tag
);
164 ok( r
== S_OK
, "couldn't get tag name\n");
165 ok( tag
!= NULL
, "tag was null\n");
166 ok( !lstrcmpW( tag
, szOpen
), "incorrect tag name\n");
167 SysFreeString( tag
);
169 /* figure out what happens if we try to reload the document */
170 str
= SysAllocString( szComplete2
);
171 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
172 ok( r
== S_OK
, "loadXML failed\n");
173 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
174 SysFreeString( str
);
176 /* check if the tag is still correct */
178 r
= IXMLDOMElement_get_tagName( element
, &tag
);
179 ok( r
== S_OK
, "couldn't get tag name\n");
180 ok( tag
!= NULL
, "tag was null\n");
181 ok( !lstrcmpW( tag
, szOpen
), "incorrect tag name\n");
182 SysFreeString( tag
);
184 IXMLDOMElement_Release( element
);
188 /* as soon as we call loadXML again, the document element will disappear */
190 r
= IXMLDOMDocument_loadXML( doc
, NULL
, NULL
);
191 ok( r
== S_FALSE
, "loadXML failed\n");
192 ok( b
== 2, "variant modified\n");
193 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
194 ok( r
== S_FALSE
, "should be no document element\n");
196 /* try to load something else simple and valid */
198 str
= SysAllocString( szComplete3
);
199 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
200 ok( r
== S_OK
, "loadXML failed\n");
201 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
202 SysFreeString( str
);
204 /* try something a little more complicated */
206 str
= SysAllocString( szComplete4
);
207 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
208 ok( r
== S_OK
, "loadXML failed\n");
209 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
210 SysFreeString( str
);
212 r
= IXMLDocument_Release( doc
);
213 ok( r
== 0, "document ref count incorrect\n");
217 void test_domnode( void )
220 IXMLDOMDocument
*doc
= NULL
, *owner
= NULL
;
221 IXMLDOMElement
*element
= NULL
;
222 IXMLDOMNamedNodeMap
*map
= NULL
;
223 IXMLDOMNode
*node
= NULL
, *next
= NULL
;
224 IXMLDOMNodeList
*list
= NULL
;
225 DOMNodeType type
= NODE_INVALID
;
230 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
231 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument
, (LPVOID
*)&doc
);
236 str
= SysAllocString( szComplete4
);
237 r
= IXMLDOMDocument_loadXML( doc
, str
, &b
);
238 ok( r
== S_OK
, "loadXML failed\n");
239 ok( b
== VARIANT_TRUE
, "failed to load XML string\n");
240 SysFreeString( str
);
245 r
= IXMLDOMNode_hasChildNodes( doc
, &b
);
246 ok( r
== S_OK
, "hasChildNoes bad return\n");
247 ok( b
== VARIANT_TRUE
, "hasChildNoes wrong result\n");
249 r
= IXMLDOMDocument_get_documentElement( doc
, &element
);
250 ok( r
== S_OK
, "should be a document element\n");
251 ok( element
!= NULL
, "should be an element\n");
254 ok( FALSE
, "no document\n");
257 ok( V_VT(&var
) == VT_EMPTY
, "variant init failed\n");
258 r
= IXMLDOMNode_get_nodeValue( doc
, &var
);
259 ok( r
== S_FALSE
, "nextNode returned wrong code\n");
260 ok( V_VT(&var
) == VT_NULL
, "variant wasn't empty\n");
261 ok( V_BSTR(&var
) == NULL
, "variant value wasn't null\n");
266 r
= IXMLDOMNode_get_ownerDocument( element
, &owner
);
268 ok( r
== S_OK
, "get_ownerDocument return code\n");
270 ok( owner
!= doc
, "get_ownerDocument return\n");
273 r
= IXMLDOMNode_get_nodeType( element
, &type
);
274 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
275 ok( type
== NODE_ELEMENT
, "node not an element\n");
278 r
= IXMLDOMNode_get_baseName( element
, &str
);
279 ok( r
== S_OK
, "get_baseName returned wrong code\n");
280 ok( lstrcmpW(str
,szlc
) == 0, "basename was wrong\n");
282 r
= IXMLDOMElement_get_attributes( element
, &map
);
283 ok( r
== S_OK
, "get_attributes returned wrong code\n");
284 ok( map
!= NULL
, "should be attributes\n");
287 r
= IXMLDOMNode_hasChildNodes( element
, &b
);
288 ok( r
== S_OK
, "hasChildNoes bad return\n");
289 ok( b
== VARIANT_TRUE
, "hasChildNoes wrong result\n");
292 ok( FALSE
, "no element\n");
296 str
= SysAllocString( szdl
);
297 r
= IXMLDOMNamedNodeMap_getNamedItem( map
, str
, &node
);
298 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
299 ok( node
!= NULL
, "should be attributes\n");
302 ok( FALSE
, "no map\n");
307 r
= IXMLDOMNode_get_nodeType( node
, &type
);
308 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
309 ok( type
== NODE_ATTRIBUTE
, "node not an attribute\n");
312 r
= IXMLDOMNode_get_baseName( node
, NULL
);
313 ok( r
== E_INVALIDARG
, "get_baseName returned wrong code\n");
316 r
= IXMLDOMNode_get_baseName( node
, &str
);
317 ok( r
== S_OK
, "get_baseName returned wrong code\n");
318 ok( lstrcmpW(str
,szdl
) == 0, "basename was wrong\n");
320 r
= IXMLDOMNode_get_childNodes( node
, NULL
);
321 ok( r
== E_INVALIDARG
, "get_childNodes returned wrong code\n");
323 r
= IXMLDOMNode_get_childNodes( node
, &list
);
324 ok( r
== S_OK
, "get_childNodes returned wrong code\n");
328 r
= IXMLDOMNodeList_nextNode( list
, &next
);
329 ok( r
== S_OK
, "nextNode returned wrong code\n");
332 ok( FALSE
, "no childlist\n");
337 r
= IXMLDOMNode_hasChildNodes( next
, &b
);
338 ok( r
== S_FALSE
, "hasChildNoes bad return\n");
339 ok( b
== VARIANT_FALSE
, "hasChildNoes wrong result\n");
342 r
= IXMLDOMNode_get_nodeType( next
, &type
);
343 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
344 ok( type
== NODE_TEXT
, "node not text\n");
347 r
= IXMLDOMNode_get_baseName( next
, &str
);
348 ok( r
== S_FALSE
, "get_baseName returned wrong code\n");
349 ok( str
== NULL
, "basename was wrong\n");
352 ok( FALSE
, "no next\n");
355 IXMLDOMNode_Release( next
);
358 IXMLDOMNodeList_Release( list
);
361 IXMLDOMNode_Release( node
);
364 ok( FALSE
, "no node\n");
368 IXMLDOMNamedNodeMap_Release( map
);
370 /* now traverse the tree from the root node */
373 r
= IXMLDOMNode_get_childNodes( element
, &list
);
374 ok( r
== S_OK
, "get_childNodes returned wrong code\n");
377 ok( FALSE
, "no element\n");
381 r
= IXMLDOMNodeList_nextNode( list
, &node
);
382 ok( r
== S_OK
, "nextNode returned wrong code\n");
385 ok( FALSE
, "no list\n");
390 r
= IXMLDOMNode_get_nodeType( node
, &type
);
391 ok( r
== S_OK
, "getNamedItem returned wrong code\n");
392 ok( type
== NODE_ELEMENT
, "node not text\n");
395 ok( V_VT(&var
) == VT_EMPTY
, "variant init failed\n");
396 r
= IXMLDOMNode_get_nodeValue( node
, &var
);
397 ok( r
== S_FALSE
, "nextNode returned wrong code\n");
398 ok( V_VT(&var
) == VT_NULL
, "variant wasn't empty\n");
399 ok( V_BSTR(&var
) == NULL
, "variant value wasn't null\n");
401 r
= IXMLDOMNode_hasChildNodes( node
, NULL
);
402 ok( r
== E_INVALIDARG
, "hasChildNoes bad return\n");
405 r
= IXMLDOMNode_hasChildNodes( node
, &b
);
406 ok( r
== S_OK
, "hasChildNoes bad return\n");
407 ok( b
== VARIANT_TRUE
, "hasChildNoes wrong result\n");
410 r
= IXMLDOMNode_get_baseName( node
, &str
);
411 ok( r
== S_OK
, "get_baseName returned wrong code\n");
412 ok( lstrcmpW(str
,szbs
) == 0, "basename was wrong\n");
415 ok( FALSE
, "no node\n");
418 IXMLDOMNode_Release( node
);
420 IXMLDOMNodeList_Release( list
);
422 IXMLDOMElement_Release( element
);
424 IXMLDocument_Release( doc
);
431 r
= CoInitialize( NULL
);
432 ok( r
== S_OK
, "failed to init com\n");