ReactOS 0.4.16-dev-2135-g2f5a67f
domdoc.c
Go to the documentation of this file.
1/*
2 * XML test
3 *
4 * Copyright 2005 Mike McCormack for CodeWeavers
5 * Copyright 2007-2008 Alistair Leslie-Hughes
6 * Copyright 2010-2011 Adam Martinson for CodeWeavers
7 * Copyright 2010-2013 Nikolay Sivov for CodeWeavers
8 * Copyright 2023 Daniel Lehman
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#define COBJMACROS
27#define CONST_VTABLE
28
29#include <stdio.h>
30#include <assert.h>
31
32#include "windows.h"
33
34#include "initguid.h"
35#include "msxml6.h"
36
37#include "wine/test.h"
38
39static BSTR alloced_bstrs[256];
41
42static BSTR _bstr_(const WCHAR *str)
43{
47}
48
49static void free_bstrs(void)
50{
51 int i;
52 for (i = 0; i < alloced_bstrs_count; i++)
55}
56
57struct attrtest_t {
58 const WCHAR *name;
59 const WCHAR *uri;
60 const WCHAR *prefix;
61 const WCHAR *href;
62};
63
64static struct attrtest_t attrtests[] = {
65 { L"xmlns", L"http://www.w3.org/2000/xmlns/", NULL, L"http://www.w3.org/2000/xmlns/" },
66 { L"xmlns", L"nondefaulturi", NULL, L"http://www.w3.org/2000/xmlns/" },
67 { L"c", L"http://www.w3.org/2000/xmlns/", NULL, L"http://www.w3.org/2000/xmlns/" },
68 { L"c", L"nsref1", NULL, L"nsref1" },
69 { L"ns:c", L"nsref1", L"ns", L"nsref1" },
70 { L"xmlns:c", L"http://www.w3.org/2000/xmlns/", L"xmlns", L"http://www.w3.org/2000/xmlns/" },
71 { L"xmlns:c", L"nondefaulturi", L"xmlns", L"http://www.w3.org/2000/xmlns/" },
72 { 0 }
73};
74
75/* see dlls/msxml[34]/tests/domdoc.c */
76static void test_create_attribute(void)
77{
78 struct attrtest_t *ptr = attrtests;
83 HRESULT hr;
84 int i = 0;
85 BSTR str;
86
87 hr = CoCreateInstance(&CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&doc);
88 ok(hr == S_OK, "Failed to create DOMDocument60, hr %#lx.\n", hr);
89
90 while (ptr->name)
91 {
92 V_VT(&var) = VT_I1;
94 hr = IXMLDOMDocument2_createNode(doc, var, _bstr_(ptr->name), _bstr_(ptr->uri), &node);
95 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
96
97 str = NULL;
98 hr = IXMLDOMNode_get_prefix(node, &str);
99 if (ptr->prefix)
100 {
101 ok(hr == S_OK, "%d: unexpected hr %#lx\n", i, hr);
102 ok(!lstrcmpW(str, _bstr_(ptr->prefix)), "%d: got prefix %s, expected %s\n",
103 i, wine_dbgstr_w(str), wine_dbgstr_w(ptr->prefix));
104 }
105 else
106 {
107 ok(hr == S_FALSE, "%d: unexpected hr %#lx\n", i, hr);
108 ok(str == NULL, "%d: got prefix %s\n", i, wine_dbgstr_w(str));
109 }
111
112 str = NULL;
113 hr = IXMLDOMNode_get_namespaceURI(node, &str);
114 ok(hr == S_OK, "%d: unexpected hr %#lx\n", i, hr);
115 ok(!lstrcmpW(str, _bstr_(ptr->href)) ||
116 broken(!ptr->prefix && !lstrcmpW(str, L"xmlns")), /* win7 msxml6 */
117 "%d: got uri %s, expected %s\n", i, wine_dbgstr_w(str), wine_dbgstr_w(ptr->href));
119
120 IXMLDOMNode_Release(node);
121 free_bstrs();
122
123 i++;
124 ptr++;
125 }
126
127 V_VT(&var) = VT_I1;
129 hr = IXMLDOMDocument2_createNode(doc, var, _bstr_(L"e"), NULL, &node);
130 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
131
132 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&el);
133 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
134 IXMLDOMNode_Release(node);
135
136 V_VT(&var) = VT_I1;
138 hr = IXMLDOMDocument2_createNode(doc, var, _bstr_(L"xmlns:a"),
139 _bstr_(L"http://www.w3.org/2000/xmlns/"), &node);
140 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
141
142 hr = IXMLDOMElement_setAttributeNode(el, (IXMLDOMAttribute*)node, NULL);
143 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
144
145 /* for some reason default namespace uri is not reported */
146 hr = IXMLDOMNode_get_namespaceURI(node, &str);
147 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
148 ok(!lstrcmpW(str, L"http://www.w3.org/2000/xmlns/") ||
149 broken(!ptr->prefix && !lstrcmpW(str, L"xmlns")), /* win7 msxml6 */
150 "got uri %s\n", wine_dbgstr_w(str));
152
153 IXMLDOMNode_Release(node);
154 IXMLDOMElement_Release(el);
155 IXMLDOMDocument2_Release(doc);
156 free_bstrs();
157}
158
159/* see dlls/msxml[34]/tests/domdoc.c */
161{
162 struct test
163 {
164 const WCHAR *xml;
165 int explen;
166 const WCHAR *names[3];
167 const WCHAR *prefixes[3];
168 const WCHAR *basenames[3];
169 const WCHAR *uris[3];
170 const WCHAR *texts[3];
171 const WCHAR *xmls[3];
172 };
173 static const struct test tests[] =
174 {
175 {
176 L"<a ns:b=\"b attr\" d=\"d attr\" xmlns:ns=\"nshref\" />", 3,
177 { L"ns:b", L"d", L"xmlns:ns" }, /* nodeName */
178 { L"ns", NULL, L"xmlns" }, /* prefix */
179 { L"b", L"d", L"ns" }, /* baseName */
180 { L"nshref", NULL, L"" }, /* namespaceURI */
181 { L"b attr", L"d attr", L"nshref" }, /* text */
182 { L"ns:b=\"b attr\"", L"d=\"d attr\"", L"xmlns:ns=\"nshref\"" }, /* xml */
183 },
184 /* property only */
185 {
186 L"<a d=\"d attr\" />", 1,
187 { L"d" }, /* nodeName */
188 { NULL }, /* prefix */
189 { L"d" }, /* baseName */
190 { NULL }, /* namespaceURI */
191 { L"d attr" }, /* text */
192 { L"d=\"d attr\"" }, /* xml */
193 },
194 /* namespace only */
195 {
196 L"<a xmlns:ns=\"nshref\" />", 1,
197 { L"xmlns:ns" }, /* nodeName */
198 { L"xmlns" }, /* prefix */
199 { L"ns" }, /* baseName */
200 { L"" }, /* namespaceURI */
201 { L"nshref" }, /* text */
202 { L"xmlns:ns=\"nshref\"" }, /* xml */
203 },
204 /* default namespace */
205 {
206 L"<a xmlns=\"nshref\" />", 1,
207 { L"xmlns" }, /* nodeName */
208 { NULL }, /* prefix */
209 { L"xmlns" }, /* baseName */
210 { L"http://www.w3.org/2000/xmlns/" }, /* namespaceURI */
211 { L"nshref" }, /* text */
212 { L"xmlns=\"nshref\"" }, /* xml */
213 },
214 /* no properties or namespaces */
215 {
216 L"<a />", 0,
217 },
218
219 { NULL }
220 };
221 const struct test *test;
224 IXMLDOMDocument2 *doc;
226 LONG len, i;
227 HRESULT hr;
228 BSTR str;
229
230 test = tests;
231 while (test->xml)
232 {
233 hr = CoCreateInstance(&CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&doc);
234 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
235
236 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(test->xml), &b);
237 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
238
239 node = NULL;
240 hr = IXMLDOMDocument2_get_firstChild(doc, &node);
241 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
242
243 hr = IXMLDOMNode_get_attributes(node, &map);
244 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
245
246 len = -1;
247 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
248 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
249 ok(len == test->explen, "got %ld\n", len);
250
251 item = NULL;
252 hr = IXMLDOMNamedNodeMap_get_item(map, test->explen+1, &item);
253 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
254 ok(!item, "Item should be NULL\n");
255
256 for (i = 0; i < len; i++)
257 {
258 item = NULL;
259 hr = IXMLDOMNamedNodeMap_get_item(map, i, &item);
260 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
261
262 str = NULL;
263 hr = IXMLDOMNode_get_nodeName(item, &str);
264 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
265 ok(!lstrcmpW(str, test->names[i]), "got %s\n", wine_dbgstr_w(str));
267
268 str = NULL;
269 hr = IXMLDOMNode_get_prefix(item, &str);
270 if (test->prefixes[i])
271 {
272 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
273 ok(!lstrcmpW(str, test->prefixes[i]), "got %s\n", wine_dbgstr_w(str));
275 }
276 else
277 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr );
278
279 str = NULL;
280 hr = IXMLDOMNode_get_baseName(item, &str);
281 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
282 ok(!lstrcmpW(str, test->basenames[i]), "got %s\n", wine_dbgstr_w(str));
284
285 str = NULL;
286 hr = IXMLDOMNode_get_namespaceURI(item, &str);
287 if (test->uris[i])
288 {
289 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
290 if (test->prefixes[i] && !lstrcmpW(test->prefixes[i], L"xmlns"))
291 ok(!lstrcmpW(str, L"http://www.w3.org/2000/xmlns/"),
292 "got %s\n", wine_dbgstr_w(str));
293 else
294 ok(!lstrcmpW(str, test->uris[i]), "got %s\n", wine_dbgstr_w(str));
296 }
297 else
298 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr );
299
300 str = NULL;
301 hr = IXMLDOMNode_get_text(item, &str);
302 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
303 ok(!lstrcmpW(str, test->texts[i]), "got %s\n", wine_dbgstr_w(str));
305
306 str = NULL;
307 hr = IXMLDOMNode_get_xml(item, &str);
308 ok(SUCCEEDED(hr), "Failed to get node xml, hr %#lx.\n", hr);
309 ok(!lstrcmpW(str, test->xmls[i]), "got %s\n", wine_dbgstr_w(str));
311
312 IXMLDOMNode_Release(item);
313 }
314
315 IXMLDOMNamedNodeMap_Release(map);
316 IXMLDOMNode_Release(node);
317 IXMLDOMDocument2_Release(doc);
318
319 test++;
320 }
321 free_bstrs();
322}
323
325{
326 HRESULT hr;
327 IXMLDOMDocument2 *doc;
328
330 ok(hr == S_OK, "failed to init com\n");
331
332 hr = CoCreateInstance(&CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&doc);
333 if (hr != S_OK)
334 {
335 win_skip("class &CLSID_DOMDocument60 not supported\n");
336 return;
337 }
338 IXMLDOMDocument2_Release(doc);
339
342
344}
#define ok(value,...)
Definition: atltest.h:57
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:20
Definition: _map.h:48
#define NULL
Definition: types.h:112
OLECHAR * BSTR
Definition: compat.h:2293
short VARIANT_BOOL
Definition: compat.h:2290
@ VT_I1
Definition: compat.h:2310
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4246
#define assert(_expr)
Definition: assert.h:32
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define L(x)
Definition: resources.c:13
GLuint GLuint * names
Definition: glext.h:11545
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int prefixes
Definition: i386-dis.c:276
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define b
Definition: ke_i.h:79
#define wine_dbgstr_w
Definition: kernel32.h:34
#define win_skip
Definition: minitest.h:67
static PVOID ptr
Definition: dispmode.c:27
static struct test_info tests[]
const char * var
Definition: shader.c:5666
static BSTR _bstr_(const char *str)
Definition: domdoc.c:1232
static BSTR alloced_bstrs[256]
Definition: domdoc.c:1229
static struct attrtest_t attrtests[]
Definition: domdoc.c:13385
static int alloced_bstrs_count
Definition: domdoc.c:1230
static void test_namespaces_as_attributes(void)
Definition: domdoc.c:13781
static void free_bstrs(void)
Definition: domdoc.c:1239
static void test_create_attribute(void)
Definition: domdoc.c:13397
@ NODE_ATTRIBUTE
Definition: msxml6.idl:114
@ NODE_ELEMENT
Definition: msxml6.idl:113
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
#define V_I1(A)
Definition: oleauto.h:243
#define V_VT(A)
Definition: oleauto.h:211
long LONG
Definition: pedump.c:60
#define test
Definition: rosglue.h:37
const WCHAR * str
HRESULT hr
Definition: shlfolder.c:183
const char * prefix
Definition: domdoc.c:13381
const char * name
Definition: domdoc.c:13379
const char * href
Definition: domdoc.c:13382
const char * uri
Definition: domdoc.c:13380
Definition: domdoc.c:111
Definition: dlist.c:348
#define S_FALSE
Definition: winerror.h:3451
__wchar_t WCHAR
Definition: xmlstorage.h:180