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 "msxml2.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/", L"xmlns", L"xmlns" },
66 { L"xmlns", L"nondefaulturi", L"xmlns", L"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"" },
71 { L"xmlns:c", L"nondefaulturi", L"xmlns", L"" },
72 { 0 }
73};
74
75/* see dlls/msxml[36]/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_DOMDocument40, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&doc);
88 ok(hr == S_OK, "Failed to create DOMDocument40, 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 /* MSXML4 can report different results with different service packs */
102 ok(hr == S_OK || broken(hr == S_FALSE), "Failed to get prefix, hr %#lx.\n", hr);
103 ok(!lstrcmpW(str, _bstr_(ptr->prefix)) || broken(!str), "got %s\n", wine_dbgstr_w(str));
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)), "%d: got uri %s, expected %s\n",
118
119 IXMLDOMNode_Release(node);
120 free_bstrs();
121
122 i++;
123 ptr++;
124 }
125
126 V_VT(&var) = VT_I1;
128 hr = IXMLDOMDocument2_createNode(doc, var, _bstr_(L"e"), NULL, &node);
129 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
130
131 hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMElement, (void**)&el);
132 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
133 IXMLDOMNode_Release(node);
134
135 V_VT(&var) = VT_I1;
137 hr = IXMLDOMDocument2_createNode(doc, var, _bstr_(L"xmlns:a"),
138 _bstr_(L"http://www.w3.org/2000/xmlns/"), &node);
139 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
140
141 hr = IXMLDOMElement_setAttributeNode(el, (IXMLDOMAttribute*)node, NULL);
142 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
143
144 /* for some reason default namespace uri is not reported */
145 hr = IXMLDOMNode_get_namespaceURI(node, &str);
146 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
147 ok(!lstrcmpW(str, L""), "got uri %s\n", wine_dbgstr_w(str));
149
150 IXMLDOMNode_Release(node);
151 IXMLDOMElement_Release(el);
152 IXMLDOMDocument2_Release(doc);
153 free_bstrs();
154}
155
156/* see dlls/msxml[36]/tests/domdoc.c */
158{
159 struct test
160 {
161 const WCHAR *xml;
162 int explen;
163 const WCHAR *names[3];
164 const WCHAR *prefixes[3];
165 const WCHAR *basenames[3];
166 const WCHAR *uris[3];
167 const WCHAR *texts[3];
168 const WCHAR *xmls[3];
169 };
170 static const struct test tests[] =
171 {
172 {
173 L"<a ns:b=\"b attr\" d=\"d attr\" xmlns:ns=\"nshref\" />", 3,
174 { L"ns:b", L"d", L"xmlns:ns" }, /* nodeName */
175 { L"ns", NULL, L"xmlns" }, /* prefix */
176 { L"b", L"d", L"ns" }, /* baseName */
177 { L"nshref", NULL, L"" }, /* namespaceURI */
178 { L"b attr", L"d attr", L"nshref" }, /* text */
179 { L"ns:b=\"b attr\"", L"d=\"d attr\"", L"xmlns:ns=\"nshref\"" }, /* xml */
180 },
181 /* property only */
182 {
183 L"<a d=\"d attr\" />", 1,
184 { L"d" }, /* nodeName */
185 { NULL }, /* prefix */
186 { L"d" }, /* baseName */
187 { NULL }, /* namespaceURI */
188 { L"d attr" }, /* text */
189 { L"d=\"d attr\"" }, /* xml */
190 },
191 /* namespace only */
192 {
193 L"<a xmlns:ns=\"nshref\" />", 1,
194 { L"xmlns:ns" }, /* nodeName */
195 { L"xmlns" }, /* prefix */
196 { L"ns" }, /* baseName */
197 { L"" }, /* namespaceURI */
198 { L"nshref" }, /* text */
199 { L"xmlns:ns=\"nshref\"" }, /* xml */
200 },
201 /* default namespace */
202 {
203 L"<a xmlns=\"nshref\" />", 1,
204 { L"xmlns" }, /* nodeName */
205 { L"xmlns" }, /* prefix */
206 { L"" }, /* baseName */
207 { L"" }, /* namespaceURI */
208 { L"nshref" }, /* text */
209 { L"xmlns=\"nshref\"" }, /* xml */
210 },
211 /* no properties or namespaces */
212 {
213 L"<a />", 0,
214 },
215
216 { NULL }
217 };
218 const struct test *test;
221 IXMLDOMDocument2 *doc;
223 LONG len, i;
224 HRESULT hr;
225 BSTR str;
226
227 test = tests;
228 while (test->xml)
229 {
230 hr = CoCreateInstance(&CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&doc);
231 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
232
233 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(test->xml), &b);
234 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
235
236 node = NULL;
237 hr = IXMLDOMDocument2_get_firstChild(doc, &node);
238 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
239
240 hr = IXMLDOMNode_get_attributes(node, &map);
241 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
242
243 len = -1;
244 hr = IXMLDOMNamedNodeMap_get_length(map, &len);
245 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
246 ok(len == test->explen, "got %ld\n", len);
247
248 item = NULL;
249 hr = IXMLDOMNamedNodeMap_get_item(map, test->explen+1, &item);
250 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
251 ok(!item, "Item should be NULL\n");
252
253 for (i = 0; i < len; i++)
254 {
255 item = NULL;
256 hr = IXMLDOMNamedNodeMap_get_item(map, i, &item);
257 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
258
259 str = NULL;
260 hr = IXMLDOMNode_get_nodeName(item, &str);
261 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
262 ok(!lstrcmpW(str, test->names[i]), "got %s\n", wine_dbgstr_w(str));
264
265 str = NULL;
266 hr = IXMLDOMNode_get_prefix(item, &str);
267 if (test->prefixes[i])
268 {
269 /* MSXML4 can report different results with different service packs */
270 ok(hr == S_OK || broken(hr == S_FALSE), "Unexpected hr %#lx.\n", hr);
271 ok(!lstrcmpW(str, test->prefixes[i]) || broken(!str),
272 "got %s\n", wine_dbgstr_w(str));
274 }
275 else
276 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr );
277
278 str = NULL;
279 hr = IXMLDOMNode_get_baseName(item, &str);
280 /* MSXML4 can report different results with different service packs */
281 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
282 ok(!lstrcmpW(str, test->basenames[i]) || broken(!lstrcmpW(str, L"xmlns")),
283 "got %s\n", wine_dbgstr_w(str));
285
286 str = NULL;
287 hr = IXMLDOMNode_get_namespaceURI(item, &str);
288 if (test->uris[i])
289 {
290 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
291 if (test->prefixes[i] && !lstrcmpW(test->prefixes[i], L"xmlns"))
292 ok(!lstrcmpW(str, L""), "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_DOMDocument40, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&doc);
333 if (hr != S_OK)
334 {
335 win_skip("class &CLSID_DOMDocument40 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 WCHAR * href
Definition: domdoc.c:61
const WCHAR * name
Definition: domdoc.c:58
const WCHAR * prefix
Definition: domdoc.c:60
const WCHAR * uri
Definition: domdoc.c:59
Definition: domdoc.c:111
Definition: dlist.c:348
#define S_FALSE
Definition: winerror.h:3451
__wchar_t WCHAR
Definition: xmlstorage.h:180