ReactOS 0.4.16-dev-2135-g2f5a67f
schema.c
Go to the documentation of this file.
1/*
2 * Schema test
3 *
4 * Copyright 2007 Huw Davies
5 * Copyright 2010 Adam Martinson for CodeWeavers
6 *
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.
11 *
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.
16 *
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
20 */
21
22#include <stdio.h>
23#include <assert.h>
24#define COBJMACROS
25
26#include "ole2.h"
27#include "msxml6.h"
28#include "msxml6did.h"
29#include "dispex.h"
30
31#include "wine/test.h"
32
33#include "initguid.h"
34
35DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
36
37static const WCHAR xsd_schema1_uri[] = L"x-schema:test1.xsd";
38static const WCHAR xsd_schema1_xml[] =
39L"<?xml version='1.0'?>"
40"<schema xmlns='http://www.w3.org/2001/XMLSchema'"
41" targetNamespace='x-schema:test1.xsd'>"
42" <element name='root'>"
43" <complexType>"
44" <sequence maxOccurs='unbounded'>"
45" <any/>"
46" </sequence>"
47" </complexType>"
48" </element>"
49"</schema>";
50
51#define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
52static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
53{
54 IUnknown *iface = iface_ptr;
55 HRESULT hr, expected_hr;
56 IUnknown *unk;
57
58 expected_hr = supported ? S_OK : E_NOINTERFACE;
59
60 hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
61 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
62 if (SUCCEEDED(hr))
63 IUnknown_Release(unk);
64}
65
66static BSTR alloced_bstrs[256];
68
69static BSTR _bstr_(const WCHAR *str)
70{
74}
75
76static void free_bstrs(void)
77{
78 int i;
79 for (i = 0; i < alloced_bstrs_count; i++)
82}
83
85{
87 HRESULT hr;
88
89 hr = CoCreateInstance(&CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&obj);
90 ok(hr == S_OK, "Failed to create a document object, hr %#lx.\n", hr);
91
92 return obj;
93}
94
96{
97 void *obj = NULL;
98 HRESULT hr;
99
100 hr = CoCreateInstance(&CLSID_XMLSchemaCache60, NULL, CLSCTX_INPROC_SERVER, riid, &obj);
101 ok(hr == S_OK, "Failed to create a document object, hr %#lx.\n", hr);
102
103 return obj;
104}
105
107 const WCHAR *regex, const WCHAR *input)
108{
109 static const WCHAR regex_doc[] =
110L""
111"<?xml version='1.0'?>"
112"<root xmlns='urn:test'>%s</root>";
113
114 static const WCHAR regex_schema[] =
115L"<?xml version='1.0'?>"
116"<schema xmlns='http://www.w3.org/2001/XMLSchema'"
117" targetNamespace='urn:test'>"
118" <element name='root'>"
119" <simpleType>"
120" <restriction base='string'>"
121" <pattern value='%s'/>"
122" </restriction>"
123" </simpleType>"
124" </element>"
125"</schema>";
126
127 WCHAR buffer[1024];
129 BSTR namespace, bstr;
131 HRESULT hr;
132 VARIANT v;
133
134 VariantInit(&v);
135
136 swprintf(buffer, ARRAY_SIZE(buffer), regex_doc, input);
137 bstr = SysAllocString(buffer);
138 hr = IXMLDOMDocument2_loadXML(doc, bstr, &b);
139 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
140 ok(b == VARIANT_TRUE, "failed to load XML\n");
141 SysFreeString(bstr);
142
143 swprintf(buffer, ARRAY_SIZE(buffer), regex_schema, regex);
144 bstr = SysAllocString(buffer);
145 hr = IXMLDOMDocument2_loadXML(schema, bstr, &b);
146 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
147 ok(b == VARIANT_TRUE, "failed to load XML\n");
148 SysFreeString(bstr);
149
150 /* add the schema to the cache */
151 V_VT(&v) = VT_DISPATCH;
152 V_DISPATCH(&v) = NULL;
153 hr = IXMLDOMDocument2_QueryInterface(schema, &IID_IDispatch, (void**)&V_DISPATCH(&v));
154 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
155 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
156 namespace = SysAllocString(L"urn:test");
157 hr = IXMLDOMSchemaCollection_add(cache, namespace, v);
158 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
159 SysFreeString(namespace);
160 VariantClear(&v);
161/*
162 if (FAILED(hr))
163 return hr;
164*/
165 /* associate the cache to the doc */
166 V_VT(&v) = VT_DISPATCH;
167 V_DISPATCH(&v) = NULL;
168 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v));
169 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
170 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
171 hr = IXMLDOMDocument2_putref_schemas(doc, v);
172 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
173 VariantClear(&v);
174
175 /* validate the doc
176 * only declared elements in the declared order
177 * this is fine */
178 err = NULL;
179 bstr = NULL;
180 hr = IXMLDOMDocument2_validate(doc, &err);
181 ok(err != NULL, "domdoc_validate() should always set err\n");
182 if (IXMLDOMParseError_get_reason(err, &bstr) != S_FALSE)
183 trace("got error: %s\n", wine_dbgstr_w(bstr));
184 SysFreeString(bstr);
185 IXMLDOMParseError_Release(err);
186
187 return hr;
188}
189
190static void test_regex(void)
191{
192 static const struct regex_test
193 {
194 const WCHAR *regex;
195 const WCHAR *input;
196 }
197 tests[] =
198 {
199 { L"\\!", L"!" },
200 { L"\\\"", L"\"" },
201 { L"\\#", L"#" },
202 { L"\\$", L"$" },
203 { L"\\%", L"%" },
204 { L"\\,", L"," },
205 { L"\\/", L"/" },
206 { L"\\:", L":" },
207 { L"\\;", L";" },
208 { L"\\=", L"=" },
209 { L"\\>", L">" },
210 { L"\\@", L"@" },
211 { L"\\`", L"`" },
212 { L"\\~", L"~" },
213 { L"\\uCAFE", L"\xCAFE" },
214 /* non-BMP character in surrogate pairs: */
215 { L"\\uD83D\\uDE00", L"\xD83D\xDE00" },
216 /* "x{,2}" is non-standard and only works on libxml2 <= v2.9.10 */
217 { L"x{0,2}", L"x" }
218 };
219 unsigned int i;
220
221 for (i = 0; i < ARRAY_SIZE(tests); ++i)
222 {
223 const struct regex_test *test = &tests[i];
226 HRESULT hr;
227
228 winetest_push_context("Test %s", wine_dbgstr_w(test->regex));
229
230 doc = create_document();
232 cache = create_cache(&IID_IXMLDOMSchemaCollection);
233
234 hr = validate_regex_document(doc, schema, cache, tests->regex, tests->input);
235 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
236
237 if (doc)
238 IXMLDOMDocument2_Release(doc);
239 if (schema)
240 IXMLDOMDocument2_Release(schema);
241 if (cache)
242 IXMLDOMSchemaCollection_Release(cache);
243
245 }
246}
247
248static void test_get(void)
249{
252 HRESULT hr;
253
254 cache = create_cache(&IID_IXMLDOMSchemaCollection2);
255
256 hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
257 ok(hr == E_NOTIMPL || hr == E_POINTER /* win8 */, "Unexpected hr %#lx.\n", hr);
258
259 hr = IXMLDOMSchemaCollection2_get(cache, _bstr_(L"uri"), &node);
260 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
261
262 IXMLDOMSchemaCollection2_Release(cache);
263 free_bstrs();
264}
265
266static void test_ifaces(void)
267{
269 IUnknown *unk;
270 HRESULT hr;
271
272 cache = create_cache(&IID_IXMLDOMSchemaCollection2);
273
274 /* CLSID_XMLSchemaCache60 is returned as an interface (the same as IXMLDOMSchemaCollection2). */
275 hr = IXMLDOMSchemaCollection2_QueryInterface(cache, &CLSID_XMLSchemaCache60, (void**)&unk);
276 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
277 ok(unk == (IUnknown *)cache, "Unexpected pointer %p.\n", unk);
278 IUnknown_Release(unk);
279
280 check_interface(cache, &IID_IXMLDOMSchemaCollection, TRUE);
281 check_interface(cache, &IID_IXMLDOMSchemaCollection2, TRUE);
283 check_interface(cache, &IID_IDispatchEx, TRUE);
284
285 IXMLDOMSchemaCollection2_Release(cache);
286}
287
288static void test_remove(void)
289{
291 IXMLDOMDocument2 *doc;
293 HRESULT hr;
294 VARIANT v;
295 LONG len;
296
297 cache = create_cache(&IID_IXMLDOMSchemaCollection2);
298
299 doc = create_document();
300 ok(doc != NULL, "got %p\n", doc);
301
302 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
303 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
304
305 V_VT(&v) = VT_DISPATCH;
306 V_DISPATCH(&v) = (IDispatch*)doc;
307 hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
308 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
309
310 len = -1;
311 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
312 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
313 ok(len == 1, "Unexpected length %ld.\n", len);
314
315 /* ::remove() is a stub for version 6 */
316 hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
317 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
318
319 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(L"invaliduri"));
320 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
321
322 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
323 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
324
325 len = -1;
326 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
327 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
328 ok(len == 1, "Unexpected length %ld.\n", len);
329
330 IXMLDOMDocument2_Release(doc);
331 IXMLDOMSchemaCollection2_Release(cache);
332 free_bstrs();
333}
334
336{
338 IDispatchEx *dispex;
339 IUnknown *unk;
340 DWORD props;
341 UINT ticnt;
342 HRESULT hr;
343 BSTR name;
344
345 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
346 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
347 if (FAILED(hr)) return;
348
349 ticnt = 0;
350 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
351 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
352 ok(ticnt == 1, "ticnt=%u\n", ticnt);
353
354 name = SysAllocString(L"*");
355 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
356 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
358
359 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
360 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
361
362 props = 0;
363 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
364 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
365 ok(props == 0, "expected 0 got %ld\n", props);
366
367 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
368 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
370
371 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_SCHEMACOLLECTION_ADD, &dispid);
372 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
373
374 unk = (IUnknown*)0xdeadbeef;
375 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
376 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
377 ok(unk == (IUnknown*)0xdeadbeef, "got %p\n", unk);
378
379 name = SysAllocString(L"testprop");
380 hr = IDispatchEx_GetDispID(dispex, name, fdexNameEnsure, &dispid);
381 ok(hr == DISP_E_UNKNOWNNAME, "Unexpected hr %#lx.\n", hr);
383
384 IDispatchEx_Release(dispex);
385}
386
387static void test_dispex(void)
388{
390 IUnknown *unk;
391 HRESULT hr;
392
393 cache = create_cache(&IID_IXMLDOMSchemaCollection);
394
395 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IUnknown, (void**)&unk);
396 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
397 test_obj_dispex(unk);
398 IUnknown_Release(unk);
399
400 IXMLDOMSchemaCollection_Release(cache);
401}
402
403static void test_validate_on_load(void)
404{
407 HRESULT hr;
408
409 cache = create_cache(&IID_IXMLDOMSchemaCollection2);
410
411 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, NULL);
412 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
413
414 b = VARIANT_FALSE;
415 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, &b);
416 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
417 ok(b == VARIANT_TRUE, "got %d\n", b);
418
419 IXMLDOMSchemaCollection2_Release(cache);
420}
421
423{
424 IUnknown *obj;
425 HRESULT hr;
426
428 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
429
430 hr = CoCreateInstance(&CLSID_DOMDocument60, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&obj);
431 if (FAILED(hr))
432 {
433 win_skip("DOMDocument60 is not supported.\n");
435 return;
436 }
437 IUnknown_Release(obj);
438
439 test_regex();
440 test_get();
441 test_ifaces();
442 test_remove();
443 test_dispex();
445
447}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
#define ARRAY_SIZE(A)
Definition: main.h:20
const GUID IID_IUnknown
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
OLECHAR * BSTR
Definition: compat.h:2293
short VARIANT_BOOL
Definition: compat.h:2290
@ VT_DISPATCH
Definition: compat.h:2304
#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 swprintf
Definition: precomp.h:40
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLdouble * v
Definition: gl.h:2040
GLuint buffer
Definition: glext.h:5915
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLsizei len
Definition: glext.h:6722
GLenum GLenum GLenum input
Definition: glext.h:9031
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
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define b
Definition: ke_i.h:79
#define wine_dbgstr_w
Definition: kernel32.h:34
#define GUID_NULL
Definition: ks.h:106
const WCHAR * schema
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
#define win_skip
Definition: minitest.h:67
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
static struct test_info tests[]
#define create_cache(iid)
Definition: schema.c:420
static BSTR alloced_bstrs[256]
Definition: schema.c:376
static int alloced_bstrs_count
Definition: schema.c:377
static void free_bstrs(void)
Definition: schema.c:386
static BSTR _bstr_(const WCHAR *str)
Definition: schema.c:379
#define create_document(iid)
Definition: schema.c:416
static void test_obj_dispex(IUnknown *obj)
Definition: schema.c:1446
static void test_dispex(void)
Definition: schema.c:1498
static const WCHAR xsd_schema1_uri[]
Definition: schema.c:87
static HRESULT validate_regex_document(IXMLDOMDocument2 *doc, IXMLDOMDocument2 *schema, IXMLDOMSchemaCollection *cache, const WCHAR *regex, const WCHAR *input)
Definition: schema.c:155
static const WCHAR xsd_schema1_xml[]
Definition: schema.c:32
static void test_regex(void)
Definition: schema.c:239
static void test_remove(void)
Definition: schema.c:315
static void test_get(void)
Definition: schema.c:297
static void test_validate_on_load(void)
Definition: schema.c:368
static void test_ifaces(void)
Definition: schema.c:266
static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
Definition: schema.c:52
#define check_interface(a, b, c)
Definition: schema.c:51
static VARIANTARG static DISPID
Definition: ordinal.c:49
#define DISPID_XMLDOM_SCHEMACOLLECTION_ADD
Definition: msxml2did.h:292
#define DISPID_SAX_XMLREADER_GETFEATURE
Definition: msxml2did.h:342
GUID CLSID_XMLSchemaCache60
unsigned int UINT
Definition: ndis.h:50
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
#define V_VT(A)
Definition: oleauto.h:211
#define V_DISPATCH(A)
Definition: oleauto.h:239
const GUID IID_IDispatch
long LONG
Definition: pedump.c:60
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define REFIID
Definition: guiddef.h:118
#define err(...)
#define test
Definition: rosglue.h:37
const WCHAR * str
HRESULT hr
Definition: shlfolder.c:183
Definition: cache.c:49
Definition: parser.c:49
Definition: name.c:39
Definition: dlist.c:348
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
static const WCHAR props[]
Definition: wbemdisp.c:288
#define S_FALSE
Definition: winerror.h:3451
#define E_NOINTERFACE
Definition: winerror.h:3479
#define E_POINTER
Definition: winerror.h:3480
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:3618
__wchar_t WCHAR
Definition: xmlstorage.h:180