[MSXML3_WINETEST] Sync with Wine Staging 2.16. CORE-13762
[reactos.git] / modules / rostests / winetests / msxml3 / schema.c
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 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 //#include <stdio.h>
27 #include <assert.h>
28 #define COBJMACROS
29
30 #include <wine/test.h>
31
32 #include <initguid.h>
33 //#include "windows.h"
34 #include <winnls.h>
35 #include <ole2.h>
36 #include <msxml2.h>
37 #undef CLSID_DOMDocument
38 #include <msxml2did.h>
39 #include <dispex.h>
40
41
42 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
43
44 #define EXPECT_HR(hr,hr_exp) \
45 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
46
47 static const WCHAR xdr_schema_uri[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
48
49 static const WCHAR xdr_schema_xml[] = {
50 '<','S','c','h','e','m','a',' ','x','m','l','n','s','=','\"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','x','m','l','-','d','a','t','a','\"','\n',
51 'x','m','l','n','s',':','d','t','=','\"','u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','d','a','t','a','t','y','p','e','s','\"','>','\n',
52 '<','/','S','c','h','e','m','a','>','\n',0
53 };
54
55 static const CHAR xdr_schema1_uri[] = "x-schema:test1.xdr";
56 static const CHAR xdr_schema1_xml[] =
57 "<?xml version='1.0'?>"
58 "<Schema xmlns='urn:schemas-microsoft-com:xml-data'"
59 " xmlns:dt='urn:schemas-microsoft-com:datatypes'"
60 " name='test1.xdr'>"
61 " <ElementType name='x' dt:type='boolean'/>"
62 " <ElementType name='y'>"
63 " <datatype dt:type='int'/>"
64 " </ElementType>"
65 " <ElementType name='z'/>"
66 " <ElementType name='root' content='eltOnly' model='open' order='seq'>"
67 " <element type='x'/>"
68 " <element type='y'/>"
69 " <element type='z'/>"
70 " </ElementType>"
71 "</Schema>";
72
73 static const CHAR xdr_schema2_uri[] = "x-schema:test2.xdr";
74 static const CHAR xdr_schema2_xml[] =
75 "<?xml version='1.0'?>"
76 "<Schema xmlns='urn:schemas-microsoft-com:xml-data'"
77 " xmlns:dt='urn:schemas-microsoft-com:datatypes'"
78 " name='test2.xdr'>"
79 " <ElementType name='x' dt:type='bin.base64'/>"
80 " <ElementType name='y' dt:type='uuid'/>"
81 " <ElementType name='z'/>"
82 " <ElementType name='root' content='eltOnly' model='closed' order='one'>"
83 " <element type='x'/>"
84 " <element type='y'/>"
85 " <element type='z'/>"
86 " </ElementType>"
87 "</Schema>";
88
89 static const CHAR xdr_schema3_uri[] = "x-schema:test3.xdr";
90 static const CHAR xdr_schema3_xml[] =
91 "<?xml version='1.0'?>"
92 "<Schema xmlns='urn:schemas-microsoft-com:xml-data'"
93 " xmlns:dt='urn:schemas-microsoft-com:datatypes'"
94 " name='test3.xdr'>"
95 " <ElementType name='root' content='textOnly' model='open'>"
96 " <AttributeType name='x' dt:type='int'/>"
97 " <AttributeType name='y' dt:type='enumeration' dt:values='a b c'/>"
98 " <AttributeType name='z' dt:type='uuid'/>"
99 " <attribute type='x'/>"
100 " <attribute type='y'/>"
101 " <attribute type='z'/>"
102 " </ElementType>"
103 "</Schema>";
104
105 static const CHAR xsd_schema1_uri[] = "x-schema:test1.xsd";
106 static const CHAR xsd_schema1_xml[] =
107 "<?xml version='1.0'?>"
108 "<schema xmlns='http://www.w3.org/2001/XMLSchema'"
109 " targetNamespace='x-schema:test1.xsd'>"
110 " <element name='root'>"
111 " <complexType>"
112 " <sequence maxOccurs='unbounded'>"
113 " <any/>"
114 " </sequence>"
115 " </complexType>"
116 " </element>"
117 "</schema>";
118
119 static const CHAR xsd_schema2_uri[] = "x-schema:test2.xsd";
120 static const CHAR xsd_schema2_xml[] =
121 "<?xml version='1.0'?>"
122 "<schema xmlns='http://www.w3.org/2001/XMLSchema'"
123 " targetNamespace='x-schema:test2.xsd'>"
124 " <element name='root'>"
125 " <complexType>"
126 " <sequence maxOccurs='unbounded'>"
127 " <any/>"
128 " </sequence>"
129 " </complexType>"
130 " </element>"
131 "</schema>";
132
133 static const CHAR xsd_schema3_uri[] = "x-schema:test3.xsd";
134 static const CHAR xsd_schema3_xml[] =
135 "<?xml version='1.0'?>"
136 "<schema xmlns='http://www.w3.org/2001/XMLSchema'"
137 " targetNamespace='x-schema:test3.xsd'>"
138 " <element name='root'>"
139 " <complexType>"
140 " <sequence maxOccurs='unbounded'>"
141 " <any/>"
142 " </sequence>"
143 " </complexType>"
144 " </element>"
145 "</schema>";
146
147 static const CHAR szDatatypeXDR[] =
148 "<Schema xmlns='urn:schemas-microsoft-com:xml-data'\n"
149 " xmlns:dt='urn:schemas-microsoft-com:datatypes'>\n"
150 " <ElementType name='base64Data' content='textOnly' dt:type='bin.base64'/>\n"
151 " <ElementType name='hexData' content='textOnly' dt:type='bin.hex'/>\n"
152 " <ElementType name='boolData' content='textOnly' dt:type='boolean'/>\n"
153 " <ElementType name='charData' content='textOnly' dt:type='char'/>\n"
154 " <ElementType name='dateData' content='textOnly' dt:type='date'/>\n"
155 " <ElementType name='dateTimeData' content='textOnly' dt:type='dateTime'/>\n"
156 " <ElementType name='dateTimeTzData' content='textOnly' dt:type='dateTime.tz'/>\n"
157 " <ElementType name='entityData' content='textOnly' dt:type='entity'/>\n"
158 " <ElementType name='entitiesData' content='textOnly' dt:type='entities'/>\n"
159 " <ElementType name='fixedData' content='textOnly' dt:type='fixed.14.4'/>\n"
160 " <ElementType name='floatData' content='textOnly' dt:type='float'/>\n"
161 " <ElementType name='i1Data' content='textOnly' dt:type='i1'/>\n"
162 " <ElementType name='i2Data' content='textOnly' dt:type='i2'/>\n"
163 " <ElementType name='i4Data' content='textOnly' dt:type='i4'/>\n"
164 " <ElementType name='i8Data' content='textOnly' dt:type='i8'/>\n"
165 " <ElementType name='intData' content='textOnly' dt:type='int'/>\n"
166 " <ElementType name='nmtokData' content='textOnly' dt:type='nmtoken'/>\n"
167 " <ElementType name='nmtoksData' content='textOnly' dt:type='nmtokens'/>\n"
168 " <ElementType name='numData' content='textOnly' dt:type='number'/>\n"
169 " <ElementType name='r4Data' content='textOnly' dt:type='r4'/>\n"
170 " <ElementType name='r8Data' content='textOnly' dt:type='r8'/>\n"
171 " <ElementType name='stringData' content='textOnly' dt:type='string'/>\n"
172 " <ElementType name='timeData' content='textOnly' dt:type='time'/>\n"
173 " <ElementType name='timeTzData' content='textOnly' dt:type='time.tz'/>\n"
174 " <ElementType name='u1Data' content='textOnly' dt:type='ui1'/>\n"
175 " <ElementType name='u2Data' content='textOnly' dt:type='ui2'/>\n"
176 " <ElementType name='u4Data' content='textOnly' dt:type='ui4'/>\n"
177 " <ElementType name='u8Data' content='textOnly' dt:type='ui8'/>\n"
178 " <ElementType name='uriData' content='textOnly' dt:type='uri'/>\n"
179 " <ElementType name='uuidData' content='textOnly' dt:type='uuid'/>\n"
180 "\n"
181 " <ElementType name='Name' content='textOnly' dt:type='nmtoken'/>\n"
182 " <ElementType name='Value' content='eltOnly' order='many'>\n"
183 " <element type='base64Data'/>\n"
184 " <element type='hexData'/>\n"
185 " <element type='boolData'/>\n"
186 " <element type='charData'/>\n"
187 " <element type='dateData'/>\n"
188 " <element type='dateTimeData'/>\n"
189 " <element type='dateTimeTzData'/>\n"
190 " <element type='entityData'/>\n"
191 " <element type='entitiesData'/>\n"
192 " <element type='fixedData'/>\n"
193 " <element type='floatData'/>\n"
194 " <element type='i1Data'/>\n"
195 " <element type='i2Data'/>\n"
196 " <element type='i4Data'/>\n"
197 " <element type='i8Data'/>\n"
198 " <element type='intData'/>\n"
199 " <element type='nmtokData'/>\n"
200 " <element type='nmtoksData'/>\n"
201 " <element type='numData'/>\n"
202 " <element type='r4Data'/>\n"
203 " <element type='r8Data'/>\n"
204 " <element type='stringData'/>\n"
205 " <element type='timeData'/>\n"
206 " <element type='timeTzData'/>\n"
207 " <element type='u1Data'/>\n"
208 " <element type='u2Data'/>\n"
209 " <element type='u4Data'/>\n"
210 " <element type='u8Data'/>\n"
211 " <element type='uriData'/>\n"
212 " <element type='uuidData'/>\n"
213 " </ElementType>\n"
214 " <ElementType name='Property' content='eltOnly' order='seq'>\n"
215 " <element type='Name'/>\n"
216 " <element type='Value'/>\n"
217 " </ElementType>\n"
218 " <ElementType name='Properties' content='eltOnly'>\n"
219 " <element type='Property' minOccurs='0' maxOccurs='*'/>\n"
220 " </ElementType>\n"
221 "</Schema>";
222
223 static const CHAR szDatatypeXML[] =
224 "<?xml version='1.0'?>\n"
225 "<Properties xmlns='urn:x-schema:datatype-test-xdr'>\n"
226 " <Property>\n"
227 " <Name>testBase64</Name>\n"
228 " <Value>\n"
229 " <base64Data>+HugeNumber+</base64Data>\n"
230 " </Value>\n"
231 " </Property>\n"
232 " <Property>\n"
233 " <Name>testHex</Name>\n"
234 " <Value>\n"
235 " <hexData>deadbeef</hexData>\n"
236 " </Value>\n"
237 " </Property>\n"
238 " <Property>\n"
239 " <Name>testBool</Name>\n"
240 " <Value>\n"
241 " <boolData>1</boolData>\n"
242 " </Value>\n"
243 " </Property>\n"
244 " <Property>\n"
245 " <Name>testChar</Name>\n"
246 " <Value>\n"
247 " <charData>u</charData>\n"
248 " </Value>\n"
249 " </Property>\n"
250 " <Property>\n"
251 " <Name>testDate</Name>\n"
252 " <Value>\n"
253 " <dateData>1998-02-01</dateData>\n"
254 " </Value>\n"
255 " </Property>\n"
256 " <Property>\n"
257 " <Name>testDateTime</Name>\n"
258 " <Value>\n"
259 " <dateTimeData>1998-02-01T12:34:56</dateTimeData>\n"
260 " </Value>\n"
261 " </Property>\n"
262 " <Property>\n"
263 " <Name>testDateTimeTz</Name>\n"
264 " <Value>\n"
265 " <dateTimeTzData>1998-02-01T12:34:56-06:00</dateTimeTzData>\n"
266 " </Value>\n"
267 " </Property>\n"
268 " <Property>\n"
269 " <Name>testFixed</Name>\n"
270 " <Value>\n"
271 " <fixedData>3.1416</fixedData>\n"
272 " </Value>\n"
273 " </Property>\n"
274 " <Property>\n"
275 " <Name>testFloat</Name>\n"
276 " <Value>\n"
277 " <floatData>3.14159</floatData>\n"
278 " </Value>\n"
279 " </Property>\n"
280 " <Property>\n"
281 " <Name>testI1</Name>\n"
282 " <Value>\n"
283 " <i1Data>42</i1Data>\n"
284 " </Value>\n"
285 " </Property>\n"
286 " <Property>\n"
287 " <Name>testI2</Name>\n"
288 " <Value>\n"
289 " <i2Data>420</i2Data>\n"
290 " </Value>\n"
291 " </Property>\n"
292 " <Property>\n"
293 " <Name>testI4</Name>\n"
294 " <Value>\n"
295 " <i4Data>-420000000</i4Data>\n"
296 " </Value>\n"
297 " </Property>\n"
298 " <Property>\n"
299 " <Name>testI8</Name>\n"
300 " <Value>\n"
301 " <i8Data>-4200000000</i8Data>\n"
302 " </Value>\n"
303 " </Property>\n"
304 " <Property>\n"
305 " <Name>testInt</Name>\n"
306 " <Value>\n"
307 " <intData>42</intData>\n"
308 " </Value>\n"
309 " </Property>\n"
310 " <Property>\n"
311 " <Name>testNmtoken</Name>\n"
312 " <Value>\n"
313 " <nmtokData>tok1</nmtokData>\n"
314 " </Value>\n"
315 " </Property>\n"
316 " <Property>\n"
317 " <Name>testNmtokens</Name>\n"
318 " <Value>\n"
319 " <nmtoksData>tok1 tok2 tok3</nmtoksData>\n"
320 " </Value>\n"
321 " </Property>\n"
322 " <Property>\n"
323 " <Name>testNumber</Name>\n"
324 " <Value>\n"
325 " <numData>3.14159</numData>\n"
326 " </Value>\n"
327 " </Property>\n"
328 " <Property>\n"
329 " <Name>testR4</Name>\n"
330 " <Value>\n"
331 " <r4Data>3.14159265</r4Data>\n"
332 " </Value>\n"
333 " </Property>\n"
334 " <Property>\n"
335 " <Name>testR8</Name>\n"
336 " <Value>\n"
337 " <r8Data>3.14159265358979323846</r8Data>\n"
338 " </Value>\n"
339 " </Property>\n"
340 " <Property>\n"
341 " <Name>testString</Name>\n"
342 " <Value>\n"
343 " <stringData>foo bar</stringData>\n"
344 " </Value>\n"
345 " </Property>\n"
346 " <Property>\n"
347 " <Name>testTime</Name>\n"
348 " <Value>\n"
349 " <timeData>12:34:56</timeData>\n"
350 " </Value>\n"
351 " </Property>\n"
352 " <Property>\n"
353 " <Name>testTimeTz</Name>\n"
354 " <Value>\n"
355 " <timeTzData>12:34:56-06:00</timeTzData>\n"
356 " </Value>\n"
357 " </Property>\n"
358 " <Property>\n"
359 " <Name>testU1</Name>\n"
360 " <Value>\n"
361 " <u1Data>255</u1Data>\n"
362 " </Value>\n"
363 " </Property>\n"
364 " <Property>\n"
365 " <Name>testU2</Name>\n"
366 " <Value>\n"
367 " <u2Data>65535</u2Data>\n"
368 " </Value>\n"
369 " </Property>\n"
370 " <Property>\n"
371 " <Name>testU4</Name>\n"
372 " <Value>\n"
373 " <u4Data>4294967295</u4Data>\n"
374 " </Value>\n"
375 " </Property>\n"
376 " <Property>\n"
377 " <Name>testU8</Name>\n"
378 " <Value>\n"
379 " <u8Data>18446744073709551615</u8Data>\n"
380 " </Value>\n"
381 " </Property>\n"
382 " <Property>\n"
383 " <Name>testURI</Name>\n"
384 " <Value>\n"
385 " <uriData>urn:schemas-microsoft-com:datatypes</uriData>\n"
386 " </Value>\n"
387 " </Property>\n"
388 " <Property>\n"
389 " <Name>testUUID</Name>\n"
390 " <Value>\n"
391 " <uuidData>2933BF81-7B36-11D2-B20E-00C04F983E60</uuidData>\n"
392 " </Value>\n"
393 " </Property>\n"
394 "</Properties>";
395
396 static const CHAR szOpenSeqXDR[] =
397 "<Schema xmlns='urn:schemas-microsoft-com:xml-data'>\n"
398 " <ElementType name='w' content='empty' model='closed'/>\n"
399 " <ElementType name='x' content='empty' model='closed'/>\n"
400 " <ElementType name='y' content='empty' model='closed'/>\n"
401 " <ElementType name='z' content='empty' model='closed'/>\n"
402 " <ElementType name='test' content='eltOnly' model='open' order='seq'>\n"
403 " <element type='x'/>\n"
404 " <group order='seq'>\n"
405 " <element type='x'/>\n"
406 " <element type='y'/>\n"
407 " <element type='z'/>\n"
408 " </group>\n"
409 " <element type='z'/>\n"
410 " </ElementType>\n"
411 "</Schema>";
412
413 static const CHAR szOpenSeqXML1[] = "<test><x/><x/><y/><z/><z/></test>";
414 static const CHAR szOpenSeqXML2[] = "<test><x/><x/><y/><z/><z/><w/></test>";
415 static const CHAR szOpenSeqXML3[] = "<test><w/><x/><x/><y/><z/><z/></test>";
416 static const CHAR szOpenSeqXML4[] = "<test><x/><x/><y/><z/><z/><v/></test>";
417
418 #define check_ref_expr(expr, n) { \
419 LONG ref = expr; \
420 ok(ref == n, "expected %i refs, got %i\n", n, ref); \
421 }
422
423 #define check_refs(iface, obj, n) { \
424 LONG ref = iface ## _AddRef(obj); \
425 ok(ref == n+1, "expected %i refs, got %i\n", n+1, ref); \
426 ref = iface ## _Release(obj); \
427 ok(ref == n, "expected %i refs, got %i\n", n, ref); \
428 }
429
430 #define ole_check(expr) { \
431 HRESULT r = expr; \
432 ok(r == S_OK, #expr " returned %x\n", r); \
433 }
434
435 #define ole_expect(expr, expect) { \
436 HRESULT r = expr; \
437 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
438 }
439
440 #define _expect64(expr, str, base, TYPE, CONV) { \
441 TYPE v1 = expr; \
442 TYPE v2 = CONV(str, NULL, base); \
443 ok(v1 == v2, #expr "returned %s, expected %s\n", \
444 wine_dbgstr_longlong(v1), wine_dbgstr_longlong(v2)); \
445 }
446
447 #define expect_int64(expr, x, base) _expect64(expr, #x, base, LONG64, _strtoi64)
448 #define expect_uint64(expr, x, base) _expect64(expr, #x, base, ULONG64, _strtoui64)
449
450 static BSTR alloced_bstrs[256];
451 static int alloced_bstrs_count;
452
453 static BSTR alloc_str_from_narrow(const char *str)
454 {
455 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
456 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
457 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
458 return ret;
459 }
460
461 static BSTR _bstr_(const char *str)
462 {
463 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
464 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
465 return alloced_bstrs[alloced_bstrs_count++];
466 }
467
468 static void free_bstrs(void)
469 {
470 int i;
471 for (i = 0; i < alloced_bstrs_count; i++)
472 SysFreeString(alloced_bstrs[i]);
473 alloced_bstrs_count = 0;
474 }
475
476 static VARIANT _variantdoc_(void* doc)
477 {
478 VARIANT v;
479 V_VT(&v) = VT_DISPATCH;
480 V_DISPATCH(&v) = (IDispatch*)doc;
481 return v;
482 }
483
484 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
485 {
486 void *obj = NULL;
487 HRESULT hr;
488
489 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
490 if (hr != S_OK)
491 win_skip_(__FILE__,line)("failed to create %s instance: 0x%08x\n", name, hr);
492
493 return obj;
494 }
495
496 #define _create(cls) cls, #cls
497
498 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument), iid, __LINE__)
499
500 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
501
502 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
503
504 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
505
506 static void test_schema_refs(void)
507 {
508 static const WCHAR emptyW[] = {0};
509 IXMLDOMDocument2 *doc;
510 IXMLDOMNode *node;
511 IXMLDOMSchemaCollection *cache;
512 VARIANT v;
513 VARIANT_BOOL b;
514 BSTR str;
515 LONG len;
516 HRESULT hr;
517
518 doc = create_document(&IID_IXMLDOMDocument2);
519 if (!doc)
520 return;
521
522 cache = create_cache(&IID_IXMLDOMSchemaCollection);
523 if(!cache)
524 {
525 IXMLDOMDocument2_Release(doc);
526 return;
527 }
528
529 VariantInit(&v);
530 str = SysAllocString(xdr_schema_xml);
531 ole_check(IXMLDOMDocument2_loadXML(doc, str, &b));
532 ok(b == VARIANT_TRUE, "b %04x\n", b);
533 SysFreeString(str);
534
535 node = (void*)0xdeadbeef;
536 ole_check(IXMLDOMSchemaCollection_get(cache, NULL, &node));
537 ok(node == NULL, "%p\n", node);
538
539 /* NULL uri pointer, still adds a document */
540 ole_check(IXMLDOMSchemaCollection_add(cache, NULL, _variantdoc_(doc)));
541 len = -1;
542 ole_check(IXMLDOMSchemaCollection_get_length(cache, &len));
543 ok(len == 1, "got %d\n", len);
544 /* read back - empty valid BSTR */
545 str = NULL;
546 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache, 0, &str));
547 ok(str && *str == 0, "got %p\n", str);
548 SysFreeString(str);
549
550 node = NULL;
551 ole_check(IXMLDOMSchemaCollection_get(cache, NULL, &node));
552 ok(node != NULL, "%p\n", node);
553 IXMLDOMNode_Release(node);
554
555 node = NULL;
556 str = SysAllocString(emptyW);
557 ole_check(IXMLDOMSchemaCollection_get(cache, str, &node));
558 ok(node != NULL, "%p\n", node);
559 IXMLDOMNode_Release(node);
560 SysFreeString(str);
561
562 /* remove with NULL uri */
563 ole_check(IXMLDOMSchemaCollection_remove(cache, NULL));
564 len = -1;
565 ole_check(IXMLDOMSchemaCollection_get_length(cache, &len));
566 ok(len == 0, "got %d\n", len);
567
568 /* same, but with VT_UNKNOWN type */
569 V_VT(&v) = VT_UNKNOWN;
570 V_UNKNOWN(&v) = (IUnknown*)doc;
571 hr = IXMLDOMSchemaCollection_add(cache, NULL, v);
572 ok(hr == S_OK, "got 0x%08x\n", hr);
573
574 len = -1;
575 hr = IXMLDOMSchemaCollection_get_length(cache, &len);
576 ok(hr == S_OK, "got 0x%08x\n", hr);
577 ok(len == 1, "got %d\n", len);
578
579 hr = IXMLDOMSchemaCollection_remove(cache, NULL);
580 ok(hr == S_OK, "got 0x%08x\n", hr);
581 len = -1;
582 hr = IXMLDOMSchemaCollection_get_length(cache, &len);
583 ok(hr == S_OK, "got 0x%08x\n", hr);
584 ok(len == 0, "got %d\n", len);
585
586 str = SysAllocString(xdr_schema_uri);
587 ole_check(IXMLDOMSchemaCollection_add(cache, str, _variantdoc_(doc)));
588
589 /* IXMLDOMSchemaCollection_add doesn't add a ref on doc */
590 check_refs(IXMLDOMDocument2, doc, 1);
591
592 SysFreeString(str);
593
594 V_VT(&v) = VT_INT;
595 ole_expect(IXMLDOMDocument2_get_schemas(doc, &v), S_FALSE);
596 ok(V_VT(&v) == VT_NULL, "vt %x\n", V_VT(&v));
597
598 check_ref_expr(IXMLDOMSchemaCollection_AddRef(cache), 2);
599 V_VT(&v) = VT_DISPATCH;
600 V_DISPATCH(&v) = (IDispatch*)cache;
601
602 /* check that putref_schemas takes a ref */
603 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
604 check_refs(IXMLDOMSchemaCollection, cache, 3);
605
606 VariantClear(&v); /* refs now 2 */
607
608 V_VT(&v) = VT_INT;
609 /* check that get_schemas adds a ref */
610 ole_check(IXMLDOMDocument2_get_schemas(doc, &v));
611 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
612 check_refs(IXMLDOMSchemaCollection, cache, 3);
613
614 /* get_schemas doesn't release a ref if passed VT_DISPATCH - ie it doesn't call VariantClear() */
615 ole_check(IXMLDOMDocument2_get_schemas(doc, &v));
616 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
617 check_refs(IXMLDOMSchemaCollection, cache, 4);
618
619 /* release the two refs returned by get_schemas */
620 check_ref_expr(IXMLDOMSchemaCollection_Release(cache), 3);
621 check_ref_expr(IXMLDOMSchemaCollection_Release(cache), 2);
622
623 /* check that taking another ref on the document doesn't change the schema's ref count */
624 check_ref_expr(IXMLDOMDocument2_AddRef(doc), 2);
625 check_refs(IXMLDOMSchemaCollection, cache, 2);
626 check_ref_expr(IXMLDOMDocument2_Release(doc), 1);
627
628 /* call putref_schema with some odd variants */
629 V_VT(&v) = VT_INT;
630 ole_expect(IXMLDOMDocument2_putref_schemas(doc, v), E_FAIL);
631 check_refs(IXMLDOMSchemaCollection, cache, 2);
632
633 /* calling with VT_EMPTY releases the schema */
634 V_VT(&v) = VT_EMPTY;
635 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
636 check_refs(IXMLDOMSchemaCollection, cache, 1);
637
638 /* try setting with VT_UNKNOWN */
639 check_ref_expr(IXMLDOMSchemaCollection_AddRef(cache), 2);
640 V_VT(&v) = VT_UNKNOWN;
641 V_UNKNOWN(&v) = (IUnknown*)cache;
642 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
643 check_refs(IXMLDOMSchemaCollection, cache, 3);
644
645 VariantClear(&v); /* refs now 2 */
646
647 /* calling with VT_NULL releases the schema */
648 V_VT(&v) = VT_NULL;
649 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
650 check_refs(IXMLDOMSchemaCollection, cache, 1);
651
652 /* refs now 1 */
653 /* set again */
654 check_ref_expr(IXMLDOMSchemaCollection_AddRef(cache), 2);
655 V_VT(&v) = VT_UNKNOWN;
656 V_UNKNOWN(&v) = (IUnknown*)cache;
657 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
658 check_refs(IXMLDOMSchemaCollection, cache, 3);
659
660 VariantClear(&v); /* refs now 2 */
661
662 /* release the final ref on the doc which should release its ref on the schema */
663 check_ref_expr(IXMLDOMDocument2_Release(doc), 0);
664
665 check_refs(IXMLDOMSchemaCollection, cache, 1);
666 check_ref_expr(IXMLDOMSchemaCollection_Release(cache), 0);
667 }
668
669 static void test_collection_refs(void)
670 {
671 IXMLDOMDocument2 *schema1, *schema2, *schema3;
672 IXMLDOMSchemaCollection *cache1, *cache2, *cache3;
673 VARIANT_BOOL b;
674 LONG length;
675
676 schema1 = create_document(&IID_IXMLDOMDocument2);
677 schema2 = create_document(&IID_IXMLDOMDocument2);
678 schema3 = create_document(&IID_IXMLDOMDocument2);
679
680 cache1 = create_cache(&IID_IXMLDOMSchemaCollection);
681 cache2 = create_cache(&IID_IXMLDOMSchemaCollection);
682 cache3 = create_cache(&IID_IXMLDOMSchemaCollection);
683
684 if (!schema1 || !schema2 || !schema3 || !cache1 || !cache2 || !cache3)
685 {
686 if (schema1) IXMLDOMDocument2_Release(schema1);
687 if (schema2) IXMLDOMDocument2_Release(schema2);
688 if (schema3) IXMLDOMDocument2_Release(schema3);
689
690 if (cache1) IXMLDOMSchemaCollection_Release(cache1);
691 if (cache2) IXMLDOMSchemaCollection_Release(cache2);
692 if (cache3) IXMLDOMSchemaCollection_Release(cache2);
693
694 return;
695 }
696
697 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
698 ok(b == VARIANT_TRUE, "failed to load XML\n");
699
700 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
701 ok(b == VARIANT_TRUE, "failed to load XML\n");
702
703 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xdr_schema3_xml), &b));
704 ok(b == VARIANT_TRUE, "failed to load XML\n");
705
706 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
707 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
708 ole_check(IXMLDOMSchemaCollection_add(cache3, _bstr_(xdr_schema3_uri), _variantdoc_(schema3)));
709
710 check_ref_expr(IXMLDOMDocument2_Release(schema1), 0);
711 check_ref_expr(IXMLDOMDocument2_Release(schema2), 0);
712 check_ref_expr(IXMLDOMDocument2_Release(schema3), 0);
713 schema1 = NULL;
714 schema2 = NULL;
715 schema3 = NULL;
716
717 /* releasing the original doc does not affect the schema cache */
718 ole_check(IXMLDOMSchemaCollection_get(cache1, _bstr_(xdr_schema1_uri), (IXMLDOMNode**)&schema1));
719 ole_check(IXMLDOMSchemaCollection_get(cache2, _bstr_(xdr_schema2_uri), (IXMLDOMNode**)&schema2));
720 ole_check(IXMLDOMSchemaCollection_get(cache3, _bstr_(xdr_schema3_uri), (IXMLDOMNode**)&schema3));
721
722 /* we get a read-only domdoc interface, created just for us */
723 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
724 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
725 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
726
727 ole_expect(IXMLDOMSchemaCollection_addCollection(cache1, NULL), E_POINTER);
728 ole_check(IXMLDOMSchemaCollection_addCollection(cache2, cache1));
729 ole_check(IXMLDOMSchemaCollection_addCollection(cache3, cache2));
730
731 length = -1;
732 ole_check(IXMLDOMSchemaCollection_get_length(cache1, &length));
733 ok(length == 1, "expected length 1, got %i\n", length);
734
735 length = -1;
736 ole_check(IXMLDOMSchemaCollection_get_length(cache2, &length));
737 ok(length == 2, "expected length 2, got %i\n", length);
738
739 length = -1;
740 ole_check(IXMLDOMSchemaCollection_get_length(cache3, &length));
741 ok(length == 3, "expected length 3, got %i\n", length);
742
743
744 /* merging collections does not affect the ref count */
745 check_refs(IXMLDOMSchemaCollection, cache1, 1);
746 check_refs(IXMLDOMSchemaCollection, cache2, 1);
747 check_refs(IXMLDOMSchemaCollection, cache3, 1);
748
749 /* nor does it affect the domdoc instances */
750 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
751 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
752 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
753
754 if (schema1) check_ref_expr(IXMLDOMDocument2_Release(schema1), 0);
755 if (schema2) check_ref_expr(IXMLDOMDocument2_Release(schema2), 0);
756 if (schema3) check_ref_expr(IXMLDOMDocument2_Release(schema3), 0);
757 schema1 = NULL;
758 schema2 = NULL;
759 schema3 = NULL;
760
761 /* releasing the domdoc instances doesn't change the cache */
762 ole_check(IXMLDOMSchemaCollection_get(cache1, _bstr_(xdr_schema1_uri), (IXMLDOMNode**)&schema1));
763 ole_check(IXMLDOMSchemaCollection_get(cache2, _bstr_(xdr_schema2_uri), (IXMLDOMNode**)&schema2));
764 ole_check(IXMLDOMSchemaCollection_get(cache3, _bstr_(xdr_schema3_uri), (IXMLDOMNode**)&schema3));
765
766 /* we can just get them again */
767 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
768 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
769 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
770
771 /* releasing the caches does not affect the domdoc instances */
772 check_ref_expr(IXMLDOMSchemaCollection_Release(cache1), 0);
773 check_ref_expr(IXMLDOMSchemaCollection_Release(cache2), 0);
774 check_ref_expr(IXMLDOMSchemaCollection_Release(cache3), 0);
775
776 /* they're just for us */
777 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
778 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
779 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
780
781 if (schema1) check_ref_expr(IXMLDOMDocument2_Release(schema1), 0);
782 if (schema2) check_ref_expr(IXMLDOMDocument2_Release(schema2), 0);
783 if (schema3) check_ref_expr(IXMLDOMDocument2_Release(schema3), 0);
784
785 free_bstrs();
786 }
787
788 static void test_length(void)
789 {
790 IXMLDOMDocument2 *schema1, *schema2, *schema3;
791 IXMLDOMSchemaCollection *cache;
792 VARIANT_BOOL b;
793 VARIANT v;
794 LONG length;
795
796 schema1 = create_document(&IID_IXMLDOMDocument2);
797 schema2 = create_document(&IID_IXMLDOMDocument2);
798 schema3 = create_document(&IID_IXMLDOMDocument2);
799
800 cache = create_cache(&IID_IXMLDOMSchemaCollection);
801
802 if (!schema1 || !schema2 || !schema3 || !cache)
803 {
804 if (schema1) IXMLDOMDocument2_Release(schema1);
805 if (schema2) IXMLDOMDocument2_Release(schema2);
806 if (schema3) IXMLDOMDocument2_Release(schema3);
807
808 if (cache) IXMLDOMSchemaCollection_Release(cache);
809
810 return;
811 }
812
813 VariantInit(&v);
814
815 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
816 ok(b == VARIANT_TRUE, "failed to load XML\n");
817
818 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
819 ok(b == VARIANT_TRUE, "failed to load XML\n");
820
821 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xdr_schema3_xml), &b));
822 ok(b == VARIANT_TRUE, "failed to load XML\n");
823
824 ole_expect(IXMLDOMSchemaCollection_get_length(cache, NULL), E_POINTER);
825
826 /* MSDN lies; removing a nonexistent entry produces no error */
827 ole_check(IXMLDOMSchemaCollection_remove(cache, NULL));
828 ole_check(IXMLDOMSchemaCollection_remove(cache, _bstr_(xdr_schema1_uri)));
829
830 length = -1;
831 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
832 ok(length == 0, "expected length 0, got %i\n", length);
833
834 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
835
836 length = -1;
837 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
838 ok(length == 1, "expected length 1, got %i\n", length);
839
840 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
841
842 length = -1;
843 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
844 ok(length == 2, "expected length 2, got %i\n", length);
845
846 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema3_uri), _variantdoc_(schema3)));
847
848 length = -1;
849 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
850 ok(length == 3, "expected length 3, got %i\n", length);
851
852 /* adding with VT_NULL is the same as removing */
853 V_VT(&v) = VT_NULL;
854 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema1_uri), v));
855
856 length = -1;
857 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
858 ok(length == 2, "expected length 2, got %i\n", length);
859
860 ole_check(IXMLDOMSchemaCollection_remove(cache, _bstr_(xdr_schema2_uri)));
861
862 length = -1;
863 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
864 ok(length == 1, "expected length 1, got %i\n", length);
865
866 ole_check(IXMLDOMSchemaCollection_remove(cache, _bstr_(xdr_schema3_uri)));
867
868 length = -1;
869 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
870 ok(length == 0, "expected length 0, got %i\n", length);
871
872 IXMLDOMDocument2_Release(schema1);
873 IXMLDOMDocument2_Release(schema2);
874 IXMLDOMDocument2_Release(schema3);
875 IXMLDOMSchemaCollection_Release(cache);
876
877 free_bstrs();
878 }
879
880 static void test_collection_content(void)
881 {
882 IXMLDOMDocument2 *schema1, *schema2, *schema3, *schema4, *schema5;
883 BSTR content[5] = {NULL, NULL, NULL, NULL, NULL};
884 IXMLDOMSchemaCollection *cache1, *cache2;
885 VARIANT_BOOL b;
886 LONG length;
887 HRESULT hr;
888 BSTR bstr;
889 int i, j;
890
891 schema1 = create_document_version(30, &IID_IXMLDOMDocument2);
892 schema2 = create_document_version(30, &IID_IXMLDOMDocument2);
893 schema3 = create_document_version(30, &IID_IXMLDOMDocument2);
894
895 cache1 = create_cache_version(30, &IID_IXMLDOMSchemaCollection);
896 cache2 = create_cache_version(40, &IID_IXMLDOMSchemaCollection);
897
898 if (!schema1 || !schema2 || !schema3 || !cache1)
899 {
900 if (schema1) IXMLDOMDocument2_Release(schema1);
901 if (schema2) IXMLDOMDocument2_Release(schema2);
902 if (schema3) IXMLDOMDocument2_Release(schema3);
903
904 if (cache1) IXMLDOMSchemaCollection_Release(cache1);
905
906 return;
907 }
908
909 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
910 ok(b == VARIANT_TRUE, "failed to load XML\n");
911
912 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
913 ok(b == VARIANT_TRUE, "failed to load XML\n");
914
915 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xdr_schema3_xml), &b));
916 ok(b == VARIANT_TRUE, "failed to load XML\n");
917
918 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
919 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
920 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema3_uri), _variantdoc_(schema3)));
921
922 length = -1;
923 ole_check(IXMLDOMSchemaCollection_get_length(cache1, &length));
924 ok(length == 3, "expected length 3, got %i\n", length);
925
926 IXMLDOMDocument2_Release(schema1);
927 IXMLDOMDocument2_Release(schema2);
928 IXMLDOMDocument2_Release(schema3);
929
930 if (cache2)
931 {
932 schema1 = create_document_version(40, &IID_IXMLDOMDocument2);
933 schema2 = create_document_version(40, &IID_IXMLDOMDocument2);
934 schema3 = create_document_version(40, &IID_IXMLDOMDocument2);
935 schema4 = create_document_version(40, &IID_IXMLDOMDocument2);
936 schema5 = create_document_version(40, &IID_IXMLDOMDocument2);
937 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
938 ok(b == VARIANT_TRUE, "failed to load XML\n");
939 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
940 ok(b == VARIANT_TRUE, "failed to load XML\n");
941 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xsd_schema1_xml), &b));
942 ok(b == VARIANT_TRUE, "failed to load XML\n");
943 ole_check(IXMLDOMDocument2_loadXML(schema4, _bstr_(xsd_schema2_xml), &b));
944 ok(b == VARIANT_TRUE, "failed to load XML\n");
945 ole_check(IXMLDOMDocument2_loadXML(schema5, _bstr_(xsd_schema3_xml), &b));
946 ok(b == VARIANT_TRUE, "failed to load XML\n");
947
948 /* combining XDR and XSD schemas in the same cache is fine */
949 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
950 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
951 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xsd_schema1_uri), _variantdoc_(schema3)));
952 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xsd_schema2_uri), _variantdoc_(schema4)));
953 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xsd_schema3_uri), _variantdoc_(schema5)));
954
955 length = -1;
956 ole_check(IXMLDOMSchemaCollection_get_length(cache2, &length));
957 ok(length == 5, "expected length 5, got %i\n", length);
958
959 IXMLDOMDocument2_Release(schema1);
960 IXMLDOMDocument2_Release(schema2);
961 IXMLDOMDocument2_Release(schema3);
962 IXMLDOMDocument2_Release(schema4);
963 IXMLDOMDocument2_Release(schema5);
964 }
965
966 bstr = (void*)0xdeadbeef;
967 /* error if index is out of range */
968 hr = IXMLDOMSchemaCollection_get_namespaceURI(cache1, 3, &bstr);
969 EXPECT_HR(hr, E_FAIL);
970 ok(bstr == (void*)0xdeadbeef, "got %p\n", bstr);
971 /* error if return pointer is NULL */
972 ole_expect(IXMLDOMSchemaCollection_get_namespaceURI(cache1, 0, NULL), E_POINTER);
973 /* pointer is checked first */
974 ole_expect(IXMLDOMSchemaCollection_get_namespaceURI(cache1, 3, NULL), E_POINTER);
975
976 schema1 = NULL;
977 /* no error if ns uri does not exist */
978 ole_check(IXMLDOMSchemaCollection_get(cache1, _bstr_(xsd_schema1_uri), (IXMLDOMNode**)&schema1));
979 ok(!schema1, "expected NULL\n");
980 /* a NULL bstr corresponds to no-uri ns */
981 ole_check(IXMLDOMSchemaCollection_get(cache1, NULL, (IXMLDOMNode**)&schema1));
982 ok(!schema1, "expected NULL\n");
983 /* error if return pointer is NULL */
984 ole_expect(IXMLDOMSchemaCollection_get(cache1, _bstr_(xdr_schema1_uri), NULL), E_POINTER);
985
986 for (i = 0; i < 3; ++i)
987 {
988 bstr = NULL;
989 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache1, i, &bstr));
990 ok(bstr != NULL && *bstr, "expected non-empty string\n");
991 content[i] = bstr;
992
993 for (j = 0; j < i; ++j)
994 ok(winetest_strcmpW(content[j], bstr), "got duplicate entry\n");
995 }
996
997 for (i = 0; i < 3; ++i)
998 {
999 SysFreeString(content[i]);
1000 content[i] = NULL;
1001 }
1002
1003 if (cache2)
1004 {
1005 for (i = 0; i < 5; ++i)
1006 {
1007 bstr = NULL;
1008 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache2, i, &bstr));
1009 ok(bstr != NULL && *bstr, "expected non-empty string\n");
1010
1011 for (j = 0; j < i; ++j)
1012 ok(winetest_strcmpW(content[j], bstr), "got duplicate entry\n");
1013 content[i] = bstr;
1014 }
1015
1016 for (i = 0; i < 5; ++i)
1017 {
1018 SysFreeString(content[i]);
1019 content[i] = NULL;
1020 }
1021 }
1022
1023 IXMLDOMSchemaCollection_Release(cache1);
1024 if (cache2) IXMLDOMSchemaCollection_Release(cache2);
1025
1026 free_bstrs();
1027 }
1028
1029 static void test_XDR_schemas(void)
1030 {
1031 IXMLDOMDocument2 *doc, *schema;
1032 IXMLDOMSchemaCollection* cache;
1033 IXMLDOMParseError* err;
1034 VARIANT_BOOL b;
1035 VARIANT v;
1036 BSTR bstr;
1037
1038 doc = create_document(&IID_IXMLDOMDocument2);
1039 schema = create_document(&IID_IXMLDOMDocument2);
1040 cache = create_cache(&IID_IXMLDOMSchemaCollection);
1041
1042 if (!doc || !schema || !cache)
1043 {
1044 if (doc) IXMLDOMDocument2_Release(doc);
1045 if (schema) IXMLDOMDocument2_Release(schema);
1046 if (cache) IXMLDOMSchemaCollection_Release(cache);
1047
1048 return;
1049 }
1050
1051 VariantInit(&v);
1052
1053 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML1), &b));
1054 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1055
1056 ole_check(IXMLDOMDocument2_loadXML(schema, _bstr_(szOpenSeqXDR), &b));
1057 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1058
1059 /* load the schema */
1060 V_VT(&v) = VT_DISPATCH;
1061 V_DISPATCH(&v) = NULL;
1062 ole_check(IXMLDOMDocument2_QueryInterface(schema, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1063 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1064 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(""), v));
1065 VariantClear(&v);
1066
1067 /* associate the cache to the doc */
1068 V_VT(&v) = VT_DISPATCH;
1069 V_DISPATCH(&v) = NULL;
1070 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1071 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1072 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1073 VariantClear(&v);
1074
1075 /* validate the doc
1076 * only declared elements in the declared order
1077 * this is fine */
1078 err = NULL;
1079 bstr = NULL;
1080 ole_check(IXMLDOMDocument2_validate(doc, &err));
1081 ok(err != NULL, "domdoc_validate() should always set err\n");
1082 ole_expect(IXMLDOMParseError_get_reason(err, &bstr), S_FALSE);
1083 ok(IXMLDOMParseError_get_reason(err, &bstr) == S_FALSE, "got error: %s\n", wine_dbgstr_w(bstr));
1084 SysFreeString(bstr);
1085 IXMLDOMParseError_Release(err);
1086
1087 /* load the next doc */
1088 IXMLDOMDocument2_Release(doc);
1089 doc = create_document(&IID_IXMLDOMDocument2);
1090 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML2), &b));
1091 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1092
1093 /* associate the cache to the doc */
1094 V_VT(&v) = VT_DISPATCH;
1095 V_DISPATCH(&v) = NULL;
1096 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1097 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1098 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1099 VariantClear(&v);
1100
1101 /* validate the doc
1102 * declared elements in the declared order, with an extra declared element at the end
1103 * this is fine */
1104 err = NULL;
1105 bstr = NULL;
1106 ole_check(IXMLDOMDocument2_validate(doc, &err));
1107 ok(err != NULL, "domdoc_validate() should always set err\n");
1108 ole_expect(IXMLDOMParseError_get_reason(err, &bstr), S_FALSE);
1109 ok(IXMLDOMParseError_get_reason(err, &bstr) == S_FALSE, "got error: %s\n", wine_dbgstr_w(bstr));
1110 SysFreeString(bstr);
1111 IXMLDOMParseError_Release(err);
1112
1113 /* load the next doc */
1114 IXMLDOMDocument2_Release(doc);
1115 doc = create_document(&IID_IXMLDOMDocument2);
1116 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML3), &b));
1117 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1118
1119 /* associate the cache to the doc */
1120 V_VT(&v) = VT_DISPATCH;
1121 V_DISPATCH(&v) = NULL;
1122 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1123 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1124 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1125 VariantClear(&v);
1126
1127 /* validate the doc
1128 * fails, extra elements are only allowed at the end */
1129 err = NULL;
1130 bstr = NULL;
1131 ole_expect(IXMLDOMDocument2_validate(doc, &err), S_FALSE);
1132 ok(err != NULL, "domdoc_validate() should always set err\n");
1133 todo_wine ok(IXMLDOMParseError_get_reason(err, &bstr) == S_OK, "got error: %s\n", wine_dbgstr_w(bstr));
1134 SysFreeString(bstr);
1135 IXMLDOMParseError_Release(err);
1136
1137 /* load the next doc */
1138 IXMLDOMDocument2_Release(doc);
1139 doc = create_document(&IID_IXMLDOMDocument2);
1140 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML4), &b));
1141 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1142
1143 /* associate the cache to the doc */
1144 V_VT(&v) = VT_DISPATCH;
1145 V_DISPATCH(&v) = NULL;
1146 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1147 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1148 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1149 VariantClear(&v);
1150
1151 /* validate the doc
1152 * fails, undeclared elements are not allowed */
1153 err = NULL;
1154 bstr = NULL;
1155 ole_expect(IXMLDOMDocument2_validate(doc, &err), S_FALSE);
1156 ok(err != NULL, "domdoc_validate() should always set err\n");
1157 todo_wine ok(IXMLDOMParseError_get_reason(err, &bstr) == S_OK, "got error: %s\n", wine_dbgstr_w(bstr));
1158 SysFreeString(bstr);
1159 IXMLDOMParseError_Release(err);
1160
1161 IXMLDOMDocument2_Release(doc);
1162 IXMLDOMDocument2_Release(schema);
1163 IXMLDOMSchemaCollection_Release(cache);
1164
1165 free_bstrs();
1166 }
1167
1168 typedef struct {
1169 const char *query;
1170 enum VARENUM type_schema;
1171 const char *typename;
1172 BOOL todo;
1173 } xdr_datatypes;
1174
1175 static const xdr_datatypes xdr_datatypes_data[] = {
1176 { "//Property[Name!text()='testBase64']/Value/base64Data", VT_ARRAY|VT_UI1, "bin.base64" },
1177 { "//Property[Name!text()='testHex']/Value/hexData", VT_ARRAY|VT_UI1, "bin.hex" },
1178 { "//Property[Name!text()='testBool']/Value/boolData", VT_BOOL, "boolean" },
1179 { "//Property[Name!text()='testChar']/Value/charData", VT_I4, "char", TRUE },
1180 { "//Property[Name!text()='testDate']/Value/dateData", VT_DATE, "date" },
1181 { "//Property[Name!text()='testDateTime']/Value/dateTimeData", VT_DATE, "dateTime" },
1182 { "//Property[Name!text()='testDateTimeTz']/Value/dateTimeTzData", VT_DATE, "dateTime.tz" },
1183 { "//Property[Name!text()='testFixed']/Value/fixedData", VT_CY, "fixed.14.4" },
1184 { "//Property[Name!text()='testFloat']/Value/floatData", VT_R8, "float" },
1185 { "//Property[Name!text()='testI1']/Value/i1Data", VT_I1, "i1" },
1186 { "//Property[Name!text()='testI2']/Value/i2Data", VT_I2, "i2" },
1187 { "//Property[Name!text()='testI4']/Value/i4Data", VT_I4, "i4" },
1188 { "//Property[Name!text()='testI8']/Value/i8Data", VT_NULL, "i8", TRUE },
1189 { "//Property[Name!text()='testInt']/Value/intData", VT_I4, "int" },
1190 { "//Property[Name!text()='testNmtoken']/Value/nmtokData", VT_BSTR, NULL },
1191 { "//Property[Name!text()='testNmtokens']/Value/nmtoksData", VT_BSTR, NULL },
1192 { "//Property[Name!text()='testNumber']/Value/numData", VT_BSTR, "number" },
1193 { "//Property[Name!text()='testR4']/Value/r4Data", VT_R4, "r4" },
1194 { "//Property[Name!text()='testR8']/Value/r8Data", VT_R8, "r8" },
1195 { "//Property[Name!text()='testString']/Value/stringData", VT_BSTR, NULL },
1196 { "//Property[Name!text()='testTime']/Value/timeData", VT_DATE, "time" },
1197 { "//Property[Name!text()='testTimeTz']/Value/timeTzData", VT_DATE, "time.tz" },
1198 { "//Property[Name!text()='testU1']/Value/u1Data", VT_UI1, "ui1" },
1199 { "//Property[Name!text()='testU2']/Value/u2Data", VT_UI2, "ui2" },
1200 { "//Property[Name!text()='testU4']/Value/u4Data", VT_UI4, "ui4" },
1201 { "//Property[Name!text()='testU8']/Value/u8Data", VT_NULL, "ui8", TRUE },
1202 { "//Property[Name!text()='testURI']/Value/uriData", VT_BSTR, "uri" },
1203 { "//Property[Name!text()='testUUID']/Value/uuidData", VT_BSTR, "uuid" },
1204 { NULL }
1205 };
1206
1207 static void test_XDR_datatypes(void)
1208 {
1209 IXMLDOMDocument2 *doc, *schema, *doc2;
1210 IXMLDOMSchemaCollection* cache;
1211 const xdr_datatypes *ptr;
1212 IXMLDOMParseError* err;
1213 VARIANT_BOOL b;
1214 HRESULT hr;
1215 VARIANT v;
1216 BSTR bstr;
1217 LONG l;
1218
1219 VariantInit(&v);
1220
1221 doc = create_document(&IID_IXMLDOMDocument2);
1222 doc2 = create_document(&IID_IXMLDOMDocument2);
1223 schema = create_document(&IID_IXMLDOMDocument2);
1224 cache = create_cache(&IID_IXMLDOMSchemaCollection);
1225
1226 if (!doc || !doc2 || !schema || !cache)
1227 {
1228 if (doc) IXMLDOMDocument2_Release(doc);
1229 if (doc2) IXMLDOMDocument2_Release(doc2);
1230 if (schema) IXMLDOMDocument2_Release(schema);
1231 if (cache) IXMLDOMSchemaCollection_Release(cache);
1232 return;
1233 }
1234
1235 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szDatatypeXML), &b);
1236 EXPECT_HR(hr, S_OK);
1237 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1238
1239 hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(szDatatypeXML), &b);
1240 EXPECT_HR(hr, S_OK);
1241 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1242
1243 hr = IXMLDOMDocument2_loadXML(schema, _bstr_(szDatatypeXDR), &b);
1244 EXPECT_HR(hr, S_OK);
1245 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1246
1247 err = NULL;
1248 hr = IXMLDOMDocument2_validate(doc, &err);
1249 EXPECT_HR(hr, S_FALSE);
1250 ok(err != NULL, "domdoc_validate() should always set err\n");
1251 hr = IXMLDOMParseError_get_errorCode(err, &l);
1252 EXPECT_HR(hr, S_OK);
1253 ok(l == E_XML_NODTD, "got %08x\n", l);
1254 IXMLDOMParseError_Release(err);
1255
1256 err = NULL;
1257 hr = IXMLDOMDocument2_validate(doc2, &err);
1258 EXPECT_HR(hr, S_FALSE);
1259 ok(err != NULL, "domdoc_validate() should always set err\n");
1260 hr = IXMLDOMParseError_get_errorCode(err, &l);
1261 EXPECT_HR(hr, S_OK);
1262 ok(l == E_XML_NODTD, "got %08x\n", l);
1263 IXMLDOMParseError_Release(err);
1264
1265 /* now load the schema */
1266 V_VT(&v) = VT_DISPATCH;
1267 V_DISPATCH(&v) = NULL;
1268 hr = IXMLDOMDocument2_QueryInterface(schema, &IID_IDispatch, (void**)&V_DISPATCH(&v));
1269 EXPECT_HR(hr, S_OK);
1270 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1271 hr = IXMLDOMSchemaCollection_add(cache, _bstr_("urn:x-schema:datatype-test-xdr"), v);
1272 EXPECT_HR(hr, S_OK);
1273 VariantClear(&v);
1274
1275 /* associate the cache to the doc */
1276 V_VT(&v) = VT_DISPATCH;
1277 V_DISPATCH(&v) = NULL;
1278 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v));
1279 EXPECT_HR(hr, S_OK);
1280 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1281 hr = IXMLDOMDocument2_putref_schemas(doc2, v);
1282 EXPECT_HR(hr, S_OK);
1283 VariantClear(&v);
1284
1285 /* validate the doc */
1286 err = NULL;
1287 l = 0;
1288 bstr = NULL;
1289 hr = IXMLDOMDocument2_validate(doc2, &err);
1290 EXPECT_HR(hr, S_OK);
1291 ok(err != NULL, "domdoc_validate() should always set err\n");
1292 hr = IXMLDOMParseError_get_errorCode(err, &l);
1293 EXPECT_HR(hr, S_FALSE);
1294 hr = IXMLDOMParseError_get_reason(err, &bstr);
1295 EXPECT_HR(hr, S_FALSE);
1296 ok(l == 0, "got %08x : %s\n", l, wine_dbgstr_w(bstr));
1297 SysFreeString(bstr);
1298 IXMLDOMParseError_Release(err);
1299
1300 ptr = xdr_datatypes_data;
1301 while (ptr->query)
1302 {
1303 IXMLDOMNode* node = NULL;
1304 VARIANT type;
1305
1306 /* check data types without the schema */
1307 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_(ptr->query), &node);
1308 EXPECT_HR(hr, S_OK);
1309 ok(node != NULL, "expected node\n");
1310
1311 V_VT(&type) = VT_EMPTY;
1312 V_BSTR(&type) = (void*)-1;
1313 hr = IXMLDOMNode_get_dataType(node, &type);
1314 EXPECT_HR(hr, S_FALSE);
1315 ok(V_VT(&type) == VT_NULL, "got type %i\n", V_VT(&type));
1316 /* when returning VT_NULL, the pointer is set to NULL */
1317 ok(V_BSTR(&type) == NULL, "got %p\n", V_BSTR(&type));
1318
1319 VariantClear(&type);
1320 hr = IXMLDOMNode_get_nodeTypedValue(node, &type);
1321 EXPECT_HR(hr, S_OK);
1322 ok(V_VT(&type) == VT_BSTR, "got variant type %i\n", V_VT(&v));
1323 VariantClear(&type);
1324 IXMLDOMNode_Release(node);
1325
1326 /* check the data with schema */
1327 node = NULL;
1328 hr = IXMLDOMDocument2_selectSingleNode(doc2, _bstr_(ptr->query), &node);
1329 EXPECT_HR(hr, S_OK);
1330 ok(node != NULL, "expected node\n");
1331
1332 V_VT(&type) = VT_EMPTY;
1333 hr = IXMLDOMNode_get_dataType(node, &type);
1334 if (ptr->typename)
1335 {
1336 EXPECT_HR(hr, S_OK);
1337 ok(V_VT(&type) == VT_BSTR, "got type %i\n", V_VT(&type));
1338 ok(!lstrcmpW(V_BSTR(&type), _bstr_(ptr->typename)), "got %s\n", wine_dbgstr_w(V_BSTR(&type)));
1339 }
1340 else
1341 {
1342 EXPECT_HR(hr, S_FALSE);
1343 ok(V_VT(&type) == VT_NULL, "%s: got type %i\n", ptr->query, V_VT(&type));
1344 }
1345 VariantClear(&type);
1346
1347 VariantClear(&v);
1348 hr = IXMLDOMNode_get_nodeTypedValue(node, &v);
1349 EXPECT_HR(hr, S_OK);
1350
1351 todo_wine_if(ptr->todo)
1352 ok(V_VT(&v) == ptr->type_schema, "%s: got variant type %i\n", ptr->query, V_VT(&v));
1353
1354 switch (ptr->type_schema)
1355 {
1356 case VT_BOOL:
1357 ok(V_BOOL(&v) == VARIANT_TRUE, "got %x\n", V_BOOL(&v));
1358 break;
1359 case VT_I1:
1360 ok(V_I1(&v) == 42, "got %i\n", V_I1(&v));
1361 break;
1362 case VT_I2:
1363 ok(V_I2(&v) == 420, "got %i\n", V_I2(&v));
1364 break;
1365 case VT_I4:
1366 if (!strcmp(ptr->typename, "int"))
1367 ok(V_I4(&v) == 42, "got %i\n", V_I4(&v));
1368 else if (!strcmp(ptr->typename, "char"))
1369 todo_wine
1370 ok(V_I4(&v) == 'u', "got %x\n", V_I4(&v));
1371 else
1372 ok(V_I4(&v) == -420000000, "got %i\n", V_I4(&v));
1373 break;
1374 case VT_I8:
1375 expect_int64(V_I8(&v), -4200000000, 10);
1376 break;
1377 case VT_R4:
1378 ok(V_R4(&v) == (float)3.14159265, "got %f\n", V_R4(&v));
1379 break;
1380 case VT_R8:
1381 if (!strcmp(ptr->typename, "float"))
1382 ok(V_R8(&v) == (double)3.14159, "got %f\n", V_R8(&v));
1383 else
1384 todo_wine
1385 ok(V_R8(&v) == (double)3.14159265358979323846, "got %.20f\n", V_R8(&v));
1386 break;
1387 case VT_UI1:
1388 ok(V_UI1(&v) == 0xFF, "got %02x\n", V_UI1(&v));
1389 break;
1390 case VT_UI2:
1391 ok(V_UI2(&v) == 0xFFFF, "got %04x\n", V_UI2(&v));
1392 break;
1393 case VT_UI4:
1394 ok(V_UI4(&v) == 0xFFFFFFFF, "got %08x\n", V_UI4(&v));
1395 break;
1396 case VT_UI8:
1397 expect_uint64(V_UI8(&v), 0xFFFFFFFFFFFFFFFF, 16);
1398 break;
1399 default:
1400 ;
1401 }
1402
1403 VariantClear(&v);
1404
1405 IXMLDOMNode_Release(node);
1406
1407 ptr++;
1408 }
1409
1410 IXMLDOMDocument2_Release(schema);
1411 IXMLDOMDocument2_Release(doc);
1412 IXMLDOMDocument2_Release(doc2);
1413 IXMLDOMSchemaCollection_Release(cache);
1414
1415 free_bstrs();
1416 }
1417
1418 static void test_validate_on_load(void)
1419 {
1420 IXMLDOMSchemaCollection2 *cache;
1421 VARIANT_BOOL b;
1422 HRESULT hr;
1423
1424 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1425 if (!cache) return;
1426
1427 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, NULL);
1428 EXPECT_HR(hr, E_POINTER);
1429
1430 b = VARIANT_FALSE;
1431 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, &b);
1432 EXPECT_HR(hr, S_OK);
1433 ok(b == VARIANT_TRUE, "got %d\n", b);
1434
1435 IXMLDOMSchemaCollection2_Release(cache);
1436 }
1437
1438 static void test_obj_dispex(IUnknown *obj)
1439 {
1440 static const WCHAR testW[] = {'t','e','s','t','p','r','o','p',0};
1441 static const WCHAR starW[] = {'*',0};
1442 DISPID dispid = DISPID_SAX_XMLREADER_GETFEATURE;
1443 IDispatchEx *dispex;
1444 IUnknown *unk;
1445 DWORD props;
1446 UINT ticnt;
1447 HRESULT hr;
1448 BSTR name;
1449
1450 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
1451 EXPECT_HR(hr, S_OK);
1452 if (FAILED(hr)) return;
1453
1454 ticnt = 0;
1455 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
1456 EXPECT_HR(hr, S_OK);
1457 ok(ticnt == 1, "ticnt=%u\n", ticnt);
1458
1459 name = SysAllocString(starW);
1460 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
1461 EXPECT_HR(hr, E_NOTIMPL);
1462 SysFreeString(name);
1463
1464 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
1465 EXPECT_HR(hr, E_NOTIMPL);
1466
1467 props = 0;
1468 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
1469 EXPECT_HR(hr, E_NOTIMPL);
1470 ok(props == 0, "expected 0 got %d\n", props);
1471
1472 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
1473 EXPECT_HR(hr, E_NOTIMPL);
1474 if (SUCCEEDED(hr)) SysFreeString(name);
1475
1476 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_SCHEMACOLLECTION_ADD, &dispid);
1477 EXPECT_HR(hr, E_NOTIMPL);
1478
1479 unk = (IUnknown*)0xdeadbeef;
1480 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
1481 EXPECT_HR(hr, E_NOTIMPL);
1482 ok(unk == (IUnknown*)0xdeadbeef, "got %p\n", unk);
1483
1484 name = SysAllocString(testW);
1485 hr = IDispatchEx_GetDispID(dispex, name, fdexNameEnsure, &dispid);
1486 ok(hr == DISP_E_UNKNOWNNAME, "got 0x%08x\n", hr);
1487 SysFreeString(name);
1488
1489 IDispatchEx_Release(dispex);
1490 }
1491
1492 static void test_dispex(void)
1493 {
1494 IXMLDOMSchemaCollection *cache;
1495 IDispatchEx *dispex;
1496 IUnknown *unk;
1497 HRESULT hr;
1498 DISPPARAMS dispparams;
1499 VARIANT arg, ret;
1500
1501 cache = create_cache(&IID_IXMLDOMSchemaCollection);
1502 if (!cache) return;
1503
1504 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IUnknown, (void**)&unk);
1505 EXPECT_HR(hr, S_OK);
1506 test_obj_dispex(unk);
1507 IUnknown_Release(unk);
1508
1509 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatchEx, (void**)&dispex);
1510 ok(hr == S_OK, "got 0x%08x\n", hr);
1511
1512 V_VT(&arg) = VT_I4;
1513 V_I4(&arg) = 0;
1514 dispparams.cArgs = 1;
1515 dispparams.cNamedArgs = 0;
1516 dispparams.rgdispidNamedArgs = NULL;
1517 dispparams.rgvarg = &arg;
1518
1519 V_VT(&ret) = VT_EMPTY;
1520 V_DISPATCH(&ret) = (void*)0x1;
1521 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
1522 ok(hr == DISP_E_MEMBERNOTFOUND, "got 0x%08x\n", hr);
1523 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
1524 ok(V_DISPATCH(&ret) == (void*)0x1, "got %p\n", V_DISPATCH(&ret));
1525
1526 IDispatchEx_Release(dispex);
1527 IXMLDOMSchemaCollection_Release(cache);
1528
1529 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection);
1530 if (cache)
1531 {
1532 test_obj_dispex((IUnknown*)cache);
1533 IXMLDOMSchemaCollection_Release(cache);
1534 }
1535 }
1536
1537 static void test_get(void)
1538 {
1539 IXMLDOMSchemaCollection2 *cache;
1540 IXMLDOMNode *node;
1541 HRESULT hr;
1542
1543 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
1544 if (!cache) return;
1545
1546 hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
1547 ok(hr == E_NOTIMPL || hr == E_POINTER /* win8 */, "got %08x\n", hr);
1548
1549 hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
1550 EXPECT_HR(hr, E_NOTIMPL);
1551
1552 IXMLDOMSchemaCollection2_Release(cache);
1553
1554 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1555 if (!cache) return;
1556
1557 hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
1558 EXPECT_HR(hr, E_POINTER);
1559
1560 hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
1561 EXPECT_HR(hr, S_OK);
1562
1563 IXMLDOMSchemaCollection2_Release(cache);
1564 free_bstrs();
1565 }
1566
1567 static void test_remove(void)
1568 {
1569 IXMLDOMSchemaCollection2 *cache;
1570 IXMLDOMDocument *doc;
1571 VARIANT_BOOL b;
1572 HRESULT hr;
1573 VARIANT v;
1574 LONG len;
1575
1576 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
1577 if (!cache) return;
1578
1579 doc = create_document_version(60, &IID_IXMLDOMDocument);
1580 ok(doc != NULL, "got %p\n", doc);
1581
1582 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
1583 EXPECT_HR(hr, S_OK);
1584
1585 V_VT(&v) = VT_DISPATCH;
1586 V_DISPATCH(&v) = (IDispatch*)doc;
1587 hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
1588 EXPECT_HR(hr, S_OK);
1589
1590 len = -1;
1591 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1592 EXPECT_HR(hr, S_OK);
1593 ok(len == 1, "got %d\n", len);
1594
1595 /* ::remove() is a stub for version 6 */
1596 hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
1597 EXPECT_HR(hr, E_NOTIMPL);
1598
1599 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
1600 EXPECT_HR(hr, E_NOTIMPL);
1601
1602 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
1603 EXPECT_HR(hr, E_NOTIMPL);
1604
1605 len = -1;
1606 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1607 EXPECT_HR(hr, S_OK);
1608 ok(len == 1, "got %d\n", len);
1609
1610 IXMLDOMDocument_Release(doc);
1611 IXMLDOMSchemaCollection2_Release(cache);
1612 free_bstrs();
1613
1614 /* ::remove() works for version 4 */
1615 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1616 if (!cache) return;
1617
1618 doc = create_document_version(40, &IID_IXMLDOMDocument);
1619 ok(doc != NULL, "got %p\n", doc);
1620
1621 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
1622 EXPECT_HR(hr, S_OK);
1623
1624 V_VT(&v) = VT_DISPATCH;
1625 V_DISPATCH(&v) = (IDispatch*)doc;
1626 hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
1627 EXPECT_HR(hr, S_OK);
1628
1629 len = -1;
1630 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1631 EXPECT_HR(hr, S_OK);
1632 ok(len == 1, "got %d\n", len);
1633
1634 hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
1635 EXPECT_HR(hr, S_OK);
1636
1637 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
1638 EXPECT_HR(hr, S_OK);
1639
1640 len = -1;
1641 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1642 EXPECT_HR(hr, S_OK);
1643 ok(len == 1, "got %d\n", len);
1644
1645 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
1646 EXPECT_HR(hr, S_OK);
1647
1648 len = -1;
1649 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1650 EXPECT_HR(hr, S_OK);
1651 ok(len == 0, "got %d\n", len);
1652
1653 IXMLDOMDocument_Release(doc);
1654 IXMLDOMSchemaCollection2_Release(cache);
1655
1656 free_bstrs();
1657 }
1658
1659 static void test_ifaces(void)
1660 {
1661 IXMLDOMSchemaCollection2 *cache;
1662 IUnknown *unk;
1663 HRESULT hr;
1664
1665 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
1666 if (!cache) return;
1667
1668 /* CLSID_XMLSchemaCache60 is returned as an interface (the same as IXMLDOMSchemaCollection2). */
1669 hr = IXMLDOMSchemaCollection2_QueryInterface(cache, &CLSID_XMLSchemaCache60, (void**)&unk);
1670 ok (hr == S_OK, "Could not get CLSID_XMLSchemaCache60 iface: %08x\n", hr);
1671 ok (unk == (IUnknown*)cache, "unk != cache\n");
1672
1673 IUnknown_Release(unk);
1674 IXMLDOMSchemaCollection2_Release(cache);
1675 }
1676
1677 START_TEST(schema)
1678 {
1679 HRESULT r;
1680
1681 r = CoInitialize( NULL );
1682 ok( r == S_OK, "failed to init com\n");
1683
1684 test_schema_refs();
1685 test_collection_refs();
1686 test_length();
1687 test_collection_content();
1688 test_XDR_schemas();
1689 test_XDR_datatypes();
1690 test_validate_on_load();
1691 test_dispex();
1692 test_get();
1693 test_remove();
1694 test_ifaces();
1695
1696 CoUninitialize();
1697 }