424b26751fca236dfb46a6c8bdda65639248d3a6
[reactos.git] / 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 0x%08x%08x, expected 0x%08x%08x\n", \
444 (ULONG)((ULONG64)v1 >> 32), (ULONG)((ULONG64)v2 & (ULONG64)0xffffffff), \
445 (ULONG)((ULONG64)v1 >> 32), (ULONG)((ULONG64)v2 & (ULONG64)0xffffffff)); \
446 }
447
448 #define expect_int64(expr, x, base) _expect64(expr, #x, base, LONG64, _strtoi64)
449 #define expect_uint64(expr, x, base) _expect64(expr, #x, base, ULONG64, _strtoui64)
450
451 static BSTR alloced_bstrs[256];
452 static int alloced_bstrs_count;
453
454 static BSTR alloc_str_from_narrow(const char *str)
455 {
456 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
457 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
458 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
459 return ret;
460 }
461
462 static BSTR _bstr_(const char *str)
463 {
464 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
465 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
466 return alloced_bstrs[alloced_bstrs_count++];
467 }
468
469 static void free_bstrs(void)
470 {
471 int i;
472 for (i = 0; i < alloced_bstrs_count; i++)
473 SysFreeString(alloced_bstrs[i]);
474 alloced_bstrs_count = 0;
475 }
476
477 static VARIANT _variantdoc_(void* doc)
478 {
479 VARIANT v;
480 V_VT(&v) = VT_DISPATCH;
481 V_DISPATCH(&v) = (IDispatch*)doc;
482 return v;
483 }
484
485 static void* _create_object(const GUID *clsid, const char *name, const IID *iid, int line)
486 {
487 void *obj = NULL;
488 HRESULT hr;
489
490 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, &obj);
491 if (hr != S_OK)
492 win_skip_(__FILE__,line)("failed to create %s instance: 0x%08x\n", name, hr);
493
494 return obj;
495 }
496
497 #define _create(cls) cls, #cls
498
499 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument), iid, __LINE__)
500
501 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
502
503 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
504
505 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
506
507 static void test_schema_refs(void)
508 {
509 static const WCHAR emptyW[] = {0};
510 IXMLDOMDocument2 *doc;
511 IXMLDOMNode *node;
512 IXMLDOMSchemaCollection *cache;
513 VARIANT v;
514 VARIANT_BOOL b;
515 BSTR str;
516 LONG len;
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 str = SysAllocString(xdr_schema_uri);
569 ole_check(IXMLDOMSchemaCollection_add(cache, str, _variantdoc_(doc)));
570
571 /* IXMLDOMSchemaCollection_add doesn't add a ref on doc */
572 check_refs(IXMLDOMDocument2, doc, 1);
573
574 SysFreeString(str);
575
576 V_VT(&v) = VT_INT;
577 ole_expect(IXMLDOMDocument2_get_schemas(doc, &v), S_FALSE);
578 ok(V_VT(&v) == VT_NULL, "vt %x\n", V_VT(&v));
579
580 check_ref_expr(IXMLDOMSchemaCollection_AddRef(cache), 2);
581 V_VT(&v) = VT_DISPATCH;
582 V_DISPATCH(&v) = (IDispatch*)cache;
583
584 /* check that putref_schemas takes a ref */
585 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
586 check_refs(IXMLDOMSchemaCollection, cache, 3);
587
588 VariantClear(&v); /* refs now 2 */
589
590 V_VT(&v) = VT_INT;
591 /* check that get_schemas adds a ref */
592 ole_check(IXMLDOMDocument2_get_schemas(doc, &v));
593 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
594 check_refs(IXMLDOMSchemaCollection, cache, 3);
595
596 /* get_schemas doesn't release a ref if passed VT_DISPATCH - ie it doesn't call VariantClear() */
597 ole_check(IXMLDOMDocument2_get_schemas(doc, &v));
598 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
599 check_refs(IXMLDOMSchemaCollection, cache, 4);
600
601 /* release the two refs returned by get_schemas */
602 check_ref_expr(IXMLDOMSchemaCollection_Release(cache), 3);
603 check_ref_expr(IXMLDOMSchemaCollection_Release(cache), 2);
604
605 /* check that taking another ref on the document doesn't change the schema's ref count */
606 check_ref_expr(IXMLDOMDocument2_AddRef(doc), 2);
607 check_refs(IXMLDOMSchemaCollection, cache, 2);
608 check_ref_expr(IXMLDOMDocument2_Release(doc), 1);
609
610 /* call putref_schema with some odd variants */
611 V_VT(&v) = VT_INT;
612 ole_expect(IXMLDOMDocument2_putref_schemas(doc, v), E_FAIL);
613 check_refs(IXMLDOMSchemaCollection, cache, 2);
614
615 /* calling with VT_EMPTY releases the schema */
616 V_VT(&v) = VT_EMPTY;
617 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
618 check_refs(IXMLDOMSchemaCollection, cache, 1);
619
620 /* try setting with VT_UNKNOWN */
621 check_ref_expr(IXMLDOMSchemaCollection_AddRef(cache), 2);
622 V_VT(&v) = VT_UNKNOWN;
623 V_UNKNOWN(&v) = (IUnknown*)cache;
624 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
625 check_refs(IXMLDOMSchemaCollection, cache, 3);
626
627 VariantClear(&v); /* refs now 2 */
628
629 /* calling with VT_NULL releases the schema */
630 V_VT(&v) = VT_NULL;
631 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
632 check_refs(IXMLDOMSchemaCollection, cache, 1);
633
634 /* refs now 1 */
635 /* set again */
636 check_ref_expr(IXMLDOMSchemaCollection_AddRef(cache), 2);
637 V_VT(&v) = VT_UNKNOWN;
638 V_UNKNOWN(&v) = (IUnknown*)cache;
639 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
640 check_refs(IXMLDOMSchemaCollection, cache, 3);
641
642 VariantClear(&v); /* refs now 2 */
643
644 /* release the final ref on the doc which should release its ref on the schema */
645 check_ref_expr(IXMLDOMDocument2_Release(doc), 0);
646
647 check_refs(IXMLDOMSchemaCollection, cache, 1);
648 check_ref_expr(IXMLDOMSchemaCollection_Release(cache), 0);
649 }
650
651 static void test_collection_refs(void)
652 {
653 IXMLDOMDocument2 *schema1, *schema2, *schema3;
654 IXMLDOMSchemaCollection *cache1, *cache2, *cache3;
655 VARIANT_BOOL b;
656 LONG length;
657
658 schema1 = create_document(&IID_IXMLDOMDocument2);
659 schema2 = create_document(&IID_IXMLDOMDocument2);
660 schema3 = create_document(&IID_IXMLDOMDocument2);
661
662 cache1 = create_cache(&IID_IXMLDOMSchemaCollection);
663 cache2 = create_cache(&IID_IXMLDOMSchemaCollection);
664 cache3 = create_cache(&IID_IXMLDOMSchemaCollection);
665
666 if (!schema1 || !schema2 || !schema3 || !cache1 || !cache2 || !cache3)
667 {
668 if (schema1) IXMLDOMDocument2_Release(schema1);
669 if (schema2) IXMLDOMDocument2_Release(schema2);
670 if (schema3) IXMLDOMDocument2_Release(schema3);
671
672 if (cache1) IXMLDOMSchemaCollection_Release(cache1);
673 if (cache2) IXMLDOMSchemaCollection_Release(cache2);
674 if (cache3) IXMLDOMSchemaCollection_Release(cache2);
675
676 return;
677 }
678
679 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
680 ok(b == VARIANT_TRUE, "failed to load XML\n");
681
682 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
683 ok(b == VARIANT_TRUE, "failed to load XML\n");
684
685 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xdr_schema3_xml), &b));
686 ok(b == VARIANT_TRUE, "failed to load XML\n");
687
688 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
689 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
690 ole_check(IXMLDOMSchemaCollection_add(cache3, _bstr_(xdr_schema3_uri), _variantdoc_(schema3)));
691
692 check_ref_expr(IXMLDOMDocument2_Release(schema1), 0);
693 check_ref_expr(IXMLDOMDocument2_Release(schema2), 0);
694 check_ref_expr(IXMLDOMDocument2_Release(schema3), 0);
695 schema1 = NULL;
696 schema2 = NULL;
697 schema3 = NULL;
698
699 /* releasing the original doc does not affect the schema cache */
700 ole_check(IXMLDOMSchemaCollection_get(cache1, _bstr_(xdr_schema1_uri), (IXMLDOMNode**)&schema1));
701 ole_check(IXMLDOMSchemaCollection_get(cache2, _bstr_(xdr_schema2_uri), (IXMLDOMNode**)&schema2));
702 ole_check(IXMLDOMSchemaCollection_get(cache3, _bstr_(xdr_schema3_uri), (IXMLDOMNode**)&schema3));
703
704 /* we get a read-only domdoc interface, created just for us */
705 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
706 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
707 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
708
709 ole_expect(IXMLDOMSchemaCollection_addCollection(cache1, NULL), E_POINTER);
710 ole_check(IXMLDOMSchemaCollection_addCollection(cache2, cache1));
711 ole_check(IXMLDOMSchemaCollection_addCollection(cache3, cache2));
712
713 length = -1;
714 ole_check(IXMLDOMSchemaCollection_get_length(cache1, &length));
715 ok(length == 1, "expected length 1, got %i\n", length);
716
717 length = -1;
718 ole_check(IXMLDOMSchemaCollection_get_length(cache2, &length));
719 ok(length == 2, "expected length 2, got %i\n", length);
720
721 length = -1;
722 ole_check(IXMLDOMSchemaCollection_get_length(cache3, &length));
723 ok(length == 3, "expected length 3, got %i\n", length);
724
725
726 /* merging collections does not affect the ref count */
727 check_refs(IXMLDOMSchemaCollection, cache1, 1);
728 check_refs(IXMLDOMSchemaCollection, cache2, 1);
729 check_refs(IXMLDOMSchemaCollection, cache3, 1);
730
731 /* nor does it affect the domdoc instances */
732 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
733 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
734 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
735
736 if (schema1) check_ref_expr(IXMLDOMDocument2_Release(schema1), 0);
737 if (schema2) check_ref_expr(IXMLDOMDocument2_Release(schema2), 0);
738 if (schema3) check_ref_expr(IXMLDOMDocument2_Release(schema3), 0);
739 schema1 = NULL;
740 schema2 = NULL;
741 schema3 = NULL;
742
743 /* releasing the domdoc instances doesn't change the cache */
744 ole_check(IXMLDOMSchemaCollection_get(cache1, _bstr_(xdr_schema1_uri), (IXMLDOMNode**)&schema1));
745 ole_check(IXMLDOMSchemaCollection_get(cache2, _bstr_(xdr_schema2_uri), (IXMLDOMNode**)&schema2));
746 ole_check(IXMLDOMSchemaCollection_get(cache3, _bstr_(xdr_schema3_uri), (IXMLDOMNode**)&schema3));
747
748 /* we can just get them again */
749 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
750 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
751 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
752
753 /* releasing the caches does not affect the domdoc instances */
754 check_ref_expr(IXMLDOMSchemaCollection_Release(cache1), 0);
755 check_ref_expr(IXMLDOMSchemaCollection_Release(cache2), 0);
756 check_ref_expr(IXMLDOMSchemaCollection_Release(cache3), 0);
757
758 /* they're just for us */
759 if (schema1) check_refs(IXMLDOMDocument2, schema1, 1);
760 if (schema2) check_refs(IXMLDOMDocument2, schema2, 1);
761 if (schema3) check_refs(IXMLDOMDocument2, schema3, 1);
762
763 if (schema1) check_ref_expr(IXMLDOMDocument2_Release(schema1), 0);
764 if (schema2) check_ref_expr(IXMLDOMDocument2_Release(schema2), 0);
765 if (schema3) check_ref_expr(IXMLDOMDocument2_Release(schema3), 0);
766
767 free_bstrs();
768 }
769
770 static void test_length(void)
771 {
772 IXMLDOMDocument2 *schema1, *schema2, *schema3;
773 IXMLDOMSchemaCollection *cache;
774 VARIANT_BOOL b;
775 VARIANT v;
776 LONG length;
777
778 schema1 = create_document(&IID_IXMLDOMDocument2);
779 schema2 = create_document(&IID_IXMLDOMDocument2);
780 schema3 = create_document(&IID_IXMLDOMDocument2);
781
782 cache = create_cache(&IID_IXMLDOMSchemaCollection);
783
784 if (!schema1 || !schema2 || !schema3 || !cache)
785 {
786 if (schema1) IXMLDOMDocument2_Release(schema1);
787 if (schema2) IXMLDOMDocument2_Release(schema2);
788 if (schema3) IXMLDOMDocument2_Release(schema3);
789
790 if (cache) IXMLDOMSchemaCollection_Release(cache);
791
792 return;
793 }
794
795 VariantInit(&v);
796
797 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
798 ok(b == VARIANT_TRUE, "failed to load XML\n");
799
800 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
801 ok(b == VARIANT_TRUE, "failed to load XML\n");
802
803 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xdr_schema3_xml), &b));
804 ok(b == VARIANT_TRUE, "failed to load XML\n");
805
806 ole_expect(IXMLDOMSchemaCollection_get_length(cache, NULL), E_POINTER);
807
808 /* MSDN lies; removing a nonexistent entry produces no error */
809 ole_check(IXMLDOMSchemaCollection_remove(cache, NULL));
810 ole_check(IXMLDOMSchemaCollection_remove(cache, _bstr_(xdr_schema1_uri)));
811
812 length = -1;
813 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
814 ok(length == 0, "expected length 0, got %i\n", length);
815
816 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
817
818 length = -1;
819 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
820 ok(length == 1, "expected length 1, got %i\n", length);
821
822 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
823
824 length = -1;
825 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
826 ok(length == 2, "expected length 2, got %i\n", length);
827
828 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema3_uri), _variantdoc_(schema3)));
829
830 length = -1;
831 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
832 ok(length == 3, "expected length 3, got %i\n", length);
833
834 /* adding with VT_NULL is the same as removing */
835 V_VT(&v) = VT_NULL;
836 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(xdr_schema1_uri), v));
837
838 length = -1;
839 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
840 ok(length == 2, "expected length 2, got %i\n", length);
841
842 ole_check(IXMLDOMSchemaCollection_remove(cache, _bstr_(xdr_schema2_uri)));
843
844 length = -1;
845 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
846 ok(length == 1, "expected length 1, got %i\n", length);
847
848 ole_check(IXMLDOMSchemaCollection_remove(cache, _bstr_(xdr_schema3_uri)));
849
850 length = -1;
851 ole_check(IXMLDOMSchemaCollection_get_length(cache, &length));
852 ok(length == 0, "expected length 0, got %i\n", length);
853
854 IXMLDOMDocument2_Release(schema1);
855 IXMLDOMDocument2_Release(schema2);
856 IXMLDOMDocument2_Release(schema3);
857 IXMLDOMSchemaCollection_Release(cache);
858
859 free_bstrs();
860 }
861
862 static void test_collection_content(void)
863 {
864 IXMLDOMDocument2 *schema1, *schema2, *schema3, *schema4, *schema5;
865 BSTR content[5] = {NULL, NULL, NULL, NULL, NULL};
866 IXMLDOMSchemaCollection *cache1, *cache2;
867 VARIANT_BOOL b;
868 LONG length;
869 HRESULT hr;
870 BSTR bstr;
871 int i, j;
872
873 schema1 = create_document_version(30, &IID_IXMLDOMDocument2);
874 schema2 = create_document_version(30, &IID_IXMLDOMDocument2);
875 schema3 = create_document_version(30, &IID_IXMLDOMDocument2);
876
877 cache1 = create_cache_version(30, &IID_IXMLDOMSchemaCollection);
878 cache2 = create_cache_version(40, &IID_IXMLDOMSchemaCollection);
879
880 if (!schema1 || !schema2 || !schema3 || !cache1)
881 {
882 if (schema1) IXMLDOMDocument2_Release(schema1);
883 if (schema2) IXMLDOMDocument2_Release(schema2);
884 if (schema3) IXMLDOMDocument2_Release(schema3);
885
886 if (cache1) IXMLDOMSchemaCollection_Release(cache1);
887
888 return;
889 }
890
891 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
892 ok(b == VARIANT_TRUE, "failed to load XML\n");
893
894 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
895 ok(b == VARIANT_TRUE, "failed to load XML\n");
896
897 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xdr_schema3_xml), &b));
898 ok(b == VARIANT_TRUE, "failed to load XML\n");
899
900 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
901 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
902 ole_check(IXMLDOMSchemaCollection_add(cache1, _bstr_(xdr_schema3_uri), _variantdoc_(schema3)));
903
904 length = -1;
905 ole_check(IXMLDOMSchemaCollection_get_length(cache1, &length));
906 ok(length == 3, "expected length 3, got %i\n", length);
907
908 IXMLDOMDocument2_Release(schema1);
909 IXMLDOMDocument2_Release(schema2);
910 IXMLDOMDocument2_Release(schema3);
911
912 if (cache2)
913 {
914 schema1 = create_document_version(40, &IID_IXMLDOMDocument2);
915 schema2 = create_document_version(40, &IID_IXMLDOMDocument2);
916 schema3 = create_document_version(40, &IID_IXMLDOMDocument2);
917 schema4 = create_document_version(40, &IID_IXMLDOMDocument2);
918 schema5 = create_document_version(40, &IID_IXMLDOMDocument2);
919 ole_check(IXMLDOMDocument2_loadXML(schema1, _bstr_(xdr_schema1_xml), &b));
920 ok(b == VARIANT_TRUE, "failed to load XML\n");
921 ole_check(IXMLDOMDocument2_loadXML(schema2, _bstr_(xdr_schema2_xml), &b));
922 ok(b == VARIANT_TRUE, "failed to load XML\n");
923 ole_check(IXMLDOMDocument2_loadXML(schema3, _bstr_(xsd_schema1_xml), &b));
924 ok(b == VARIANT_TRUE, "failed to load XML\n");
925 ole_check(IXMLDOMDocument2_loadXML(schema4, _bstr_(xsd_schema2_xml), &b));
926 ok(b == VARIANT_TRUE, "failed to load XML\n");
927 ole_check(IXMLDOMDocument2_loadXML(schema5, _bstr_(xsd_schema3_xml), &b));
928 ok(b == VARIANT_TRUE, "failed to load XML\n");
929
930 /* combining XDR and XSD schemas in the same cache is fine */
931 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xdr_schema1_uri), _variantdoc_(schema1)));
932 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xdr_schema2_uri), _variantdoc_(schema2)));
933 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xsd_schema1_uri), _variantdoc_(schema3)));
934 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xsd_schema2_uri), _variantdoc_(schema4)));
935 ole_check(IXMLDOMSchemaCollection_add(cache2, _bstr_(xsd_schema3_uri), _variantdoc_(schema5)));
936
937 length = -1;
938 ole_check(IXMLDOMSchemaCollection_get_length(cache2, &length));
939 ok(length == 5, "expected length 5, got %i\n", length);
940
941 IXMLDOMDocument2_Release(schema1);
942 IXMLDOMDocument2_Release(schema2);
943 IXMLDOMDocument2_Release(schema3);
944 IXMLDOMDocument2_Release(schema4);
945 IXMLDOMDocument2_Release(schema5);
946 }
947
948 bstr = (void*)0xdeadbeef;
949 /* error if index is out of range */
950 hr = IXMLDOMSchemaCollection_get_namespaceURI(cache1, 3, &bstr);
951 EXPECT_HR(hr, E_FAIL);
952 ok(bstr == (void*)0xdeadbeef, "got %p\n", bstr);
953 /* error if return pointer is NULL */
954 ole_expect(IXMLDOMSchemaCollection_get_namespaceURI(cache1, 0, NULL), E_POINTER);
955 /* pointer is checked first */
956 ole_expect(IXMLDOMSchemaCollection_get_namespaceURI(cache1, 3, NULL), E_POINTER);
957
958 schema1 = NULL;
959 /* no error if ns uri does not exist */
960 ole_check(IXMLDOMSchemaCollection_get(cache1, _bstr_(xsd_schema1_uri), (IXMLDOMNode**)&schema1));
961 ok(!schema1, "expected NULL\n");
962 /* a NULL bstr corresponds to no-uri ns */
963 ole_check(IXMLDOMSchemaCollection_get(cache1, NULL, (IXMLDOMNode**)&schema1));
964 ok(!schema1, "expected NULL\n");
965 /* error if return pointer is NULL */
966 ole_expect(IXMLDOMSchemaCollection_get(cache1, _bstr_(xdr_schema1_uri), NULL), E_POINTER);
967
968 for (i = 0; i < 3; ++i)
969 {
970 bstr = NULL;
971 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache1, i, &bstr));
972 ok(bstr != NULL && *bstr, "expected non-empty string\n");
973 content[i] = bstr;
974
975 for (j = 0; j < i; ++j)
976 ok(winetest_strcmpW(content[j], bstr), "got duplicate entry\n");
977 }
978
979 for (i = 0; i < 3; ++i)
980 {
981 SysFreeString(content[i]);
982 content[i] = NULL;
983 }
984
985 if (cache2)
986 {
987 for (i = 0; i < 5; ++i)
988 {
989 bstr = NULL;
990 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache2, i, &bstr));
991 ok(bstr != NULL && *bstr, "expected non-empty string\n");
992
993 for (j = 0; j < i; ++j)
994 ok(winetest_strcmpW(content[j], bstr), "got duplicate entry\n");
995 content[i] = bstr;
996 }
997
998 for (i = 0; i < 5; ++i)
999 {
1000 SysFreeString(content[i]);
1001 content[i] = NULL;
1002 }
1003 }
1004
1005 IXMLDOMSchemaCollection_Release(cache1);
1006 if (cache2) IXMLDOMSchemaCollection_Release(cache2);
1007
1008 free_bstrs();
1009 }
1010
1011 static void test_XDR_schemas(void)
1012 {
1013 IXMLDOMDocument2 *doc, *schema;
1014 IXMLDOMSchemaCollection* cache;
1015 IXMLDOMParseError* err;
1016 VARIANT_BOOL b;
1017 VARIANT v;
1018 BSTR bstr;
1019
1020 doc = create_document(&IID_IXMLDOMDocument2);
1021 schema = create_document(&IID_IXMLDOMDocument2);
1022 cache = create_cache(&IID_IXMLDOMSchemaCollection);
1023
1024 if (!doc || !schema || !cache)
1025 {
1026 if (doc) IXMLDOMDocument2_Release(doc);
1027 if (schema) IXMLDOMDocument2_Release(schema);
1028 if (cache) IXMLDOMSchemaCollection_Release(cache);
1029
1030 return;
1031 }
1032
1033 VariantInit(&v);
1034
1035 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML1), &b));
1036 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1037
1038 ole_check(IXMLDOMDocument2_loadXML(schema, _bstr_(szOpenSeqXDR), &b));
1039 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1040
1041 /* load the schema */
1042 V_VT(&v) = VT_DISPATCH;
1043 V_DISPATCH(&v) = NULL;
1044 ole_check(IXMLDOMDocument2_QueryInterface(schema, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1045 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1046 ole_check(IXMLDOMSchemaCollection_add(cache, _bstr_(""), v));
1047 VariantClear(&v);
1048
1049 /* associate the cache to the doc */
1050 V_VT(&v) = VT_DISPATCH;
1051 V_DISPATCH(&v) = NULL;
1052 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1053 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1054 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1055 VariantClear(&v);
1056
1057 /* validate the doc
1058 * only declared elements in the declared order
1059 * this is fine */
1060 err = NULL;
1061 bstr = NULL;
1062 ole_check(IXMLDOMDocument2_validate(doc, &err));
1063 ok(err != NULL, "domdoc_validate() should always set err\n");
1064 ole_expect(IXMLDOMParseError_get_reason(err, &bstr), S_FALSE);
1065 ok(IXMLDOMParseError_get_reason(err, &bstr) == S_FALSE, "got error: %s\n", wine_dbgstr_w(bstr));
1066 SysFreeString(bstr);
1067 IXMLDOMParseError_Release(err);
1068
1069 /* load the next doc */
1070 IXMLDOMDocument2_Release(doc);
1071 doc = create_document(&IID_IXMLDOMDocument2);
1072 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML2), &b));
1073 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1074
1075 /* associate the cache to the doc */
1076 V_VT(&v) = VT_DISPATCH;
1077 V_DISPATCH(&v) = NULL;
1078 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1079 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1080 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1081 VariantClear(&v);
1082
1083 /* validate the doc
1084 * declared elements in the declared order, with an extra declared element at the end
1085 * this is fine */
1086 err = NULL;
1087 bstr = NULL;
1088 ole_check(IXMLDOMDocument2_validate(doc, &err));
1089 ok(err != NULL, "domdoc_validate() should always set err\n");
1090 ole_expect(IXMLDOMParseError_get_reason(err, &bstr), S_FALSE);
1091 ok(IXMLDOMParseError_get_reason(err, &bstr) == S_FALSE, "got error: %s\n", wine_dbgstr_w(bstr));
1092 SysFreeString(bstr);
1093 IXMLDOMParseError_Release(err);
1094
1095 /* load the next doc */
1096 IXMLDOMDocument2_Release(doc);
1097 doc = create_document(&IID_IXMLDOMDocument2);
1098 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML3), &b));
1099 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1100
1101 /* associate the cache to the doc */
1102 V_VT(&v) = VT_DISPATCH;
1103 V_DISPATCH(&v) = NULL;
1104 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1105 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1106 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1107 VariantClear(&v);
1108
1109 /* validate the doc
1110 * fails, extra elements are only allowed at the end */
1111 err = NULL;
1112 bstr = NULL;
1113 ole_expect(IXMLDOMDocument2_validate(doc, &err), S_FALSE);
1114 ok(err != NULL, "domdoc_validate() should always set err\n");
1115 todo_wine ok(IXMLDOMParseError_get_reason(err, &bstr) == S_OK, "got error: %s\n", wine_dbgstr_w(bstr));
1116 SysFreeString(bstr);
1117 IXMLDOMParseError_Release(err);
1118
1119 /* load the next doc */
1120 IXMLDOMDocument2_Release(doc);
1121 doc = create_document(&IID_IXMLDOMDocument2);
1122 ole_check(IXMLDOMDocument2_loadXML(doc, _bstr_(szOpenSeqXML4), &b));
1123 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1124
1125 /* associate the cache to the doc */
1126 V_VT(&v) = VT_DISPATCH;
1127 V_DISPATCH(&v) = NULL;
1128 ole_check(IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v)));
1129 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1130 ole_check(IXMLDOMDocument2_putref_schemas(doc, v));
1131 VariantClear(&v);
1132
1133 /* validate the doc
1134 * fails, undeclared elements are not allowed */
1135 err = NULL;
1136 bstr = NULL;
1137 ole_expect(IXMLDOMDocument2_validate(doc, &err), S_FALSE);
1138 ok(err != NULL, "domdoc_validate() should always set err\n");
1139 todo_wine ok(IXMLDOMParseError_get_reason(err, &bstr) == S_OK, "got error: %s\n", wine_dbgstr_w(bstr));
1140 SysFreeString(bstr);
1141 IXMLDOMParseError_Release(err);
1142
1143 IXMLDOMDocument2_Release(doc);
1144 IXMLDOMDocument2_Release(schema);
1145 IXMLDOMSchemaCollection_Release(cache);
1146
1147 free_bstrs();
1148 }
1149
1150 typedef struct {
1151 const char *query;
1152 enum VARENUM type_schema;
1153 const char *typename;
1154 BOOL todo;
1155 } xdr_datatypes;
1156
1157 static const xdr_datatypes xdr_datatypes_data[] = {
1158 { "//Property[Name!text()='testBase64']/Value/base64Data", VT_ARRAY|VT_UI1, "bin.base64" },
1159 { "//Property[Name!text()='testHex']/Value/hexData", VT_ARRAY|VT_UI1, "bin.hex" },
1160 { "//Property[Name!text()='testBool']/Value/boolData", VT_BOOL, "boolean" },
1161 { "//Property[Name!text()='testChar']/Value/charData", VT_I4, "char", TRUE },
1162 { "//Property[Name!text()='testDate']/Value/dateData", VT_DATE, "date" },
1163 { "//Property[Name!text()='testDateTime']/Value/dateTimeData", VT_DATE, "dateTime" },
1164 { "//Property[Name!text()='testDateTimeTz']/Value/dateTimeTzData", VT_DATE, "dateTime.tz" },
1165 { "//Property[Name!text()='testFixed']/Value/fixedData", VT_CY, "fixed.14.4" },
1166 { "//Property[Name!text()='testFloat']/Value/floatData", VT_R8, "float" },
1167 { "//Property[Name!text()='testI1']/Value/i1Data", VT_I1, "i1" },
1168 { "//Property[Name!text()='testI2']/Value/i2Data", VT_I2, "i2" },
1169 { "//Property[Name!text()='testI4']/Value/i4Data", VT_I4, "i4" },
1170 { "//Property[Name!text()='testI8']/Value/i8Data", VT_NULL, "i8", TRUE },
1171 { "//Property[Name!text()='testInt']/Value/intData", VT_I4, "int" },
1172 { "//Property[Name!text()='testNmtoken']/Value/nmtokData", VT_BSTR, NULL },
1173 { "//Property[Name!text()='testNmtokens']/Value/nmtoksData", VT_BSTR, NULL },
1174 { "//Property[Name!text()='testNumber']/Value/numData", VT_BSTR, "number" },
1175 { "//Property[Name!text()='testR4']/Value/r4Data", VT_R4, "r4" },
1176 { "//Property[Name!text()='testR8']/Value/r8Data", VT_R8, "r8" },
1177 { "//Property[Name!text()='testString']/Value/stringData", VT_BSTR, NULL },
1178 { "//Property[Name!text()='testTime']/Value/timeData", VT_DATE, "time" },
1179 { "//Property[Name!text()='testTimeTz']/Value/timeTzData", VT_DATE, "time.tz" },
1180 { "//Property[Name!text()='testU1']/Value/u1Data", VT_UI1, "ui1" },
1181 { "//Property[Name!text()='testU2']/Value/u2Data", VT_UI2, "ui2" },
1182 { "//Property[Name!text()='testU4']/Value/u4Data", VT_UI4, "ui4" },
1183 { "//Property[Name!text()='testU8']/Value/u8Data", VT_NULL, "ui8", TRUE },
1184 { "//Property[Name!text()='testURI']/Value/uriData", VT_BSTR, "uri" },
1185 { "//Property[Name!text()='testUUID']/Value/uuidData", VT_BSTR, "uuid" },
1186 { NULL }
1187 };
1188
1189 static void test_XDR_datatypes(void)
1190 {
1191 IXMLDOMDocument2 *doc, *schema, *doc2;
1192 IXMLDOMSchemaCollection* cache;
1193 const xdr_datatypes *ptr;
1194 IXMLDOMParseError* err;
1195 VARIANT_BOOL b;
1196 HRESULT hr;
1197 VARIANT v;
1198 BSTR bstr;
1199 LONG l;
1200
1201 VariantInit(&v);
1202
1203 doc = create_document(&IID_IXMLDOMDocument2);
1204 doc2 = create_document(&IID_IXMLDOMDocument2);
1205 schema = create_document(&IID_IXMLDOMDocument2);
1206 cache = create_cache(&IID_IXMLDOMSchemaCollection);
1207
1208 if (!doc || !doc2 || !schema || !cache)
1209 {
1210 if (doc) IXMLDOMDocument2_Release(doc);
1211 if (doc2) IXMLDOMDocument2_Release(doc2);
1212 if (schema) IXMLDOMDocument2_Release(schema);
1213 if (cache) IXMLDOMSchemaCollection_Release(cache);
1214 return;
1215 }
1216
1217 hr = IXMLDOMDocument2_loadXML(doc, _bstr_(szDatatypeXML), &b);
1218 EXPECT_HR(hr, S_OK);
1219 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1220
1221 hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(szDatatypeXML), &b);
1222 EXPECT_HR(hr, S_OK);
1223 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1224
1225 hr = IXMLDOMDocument2_loadXML(schema, _bstr_(szDatatypeXDR), &b);
1226 EXPECT_HR(hr, S_OK);
1227 ok(b == VARIANT_TRUE, "failed to load XML string\n");
1228
1229 err = NULL;
1230 hr = IXMLDOMDocument2_validate(doc, &err);
1231 EXPECT_HR(hr, S_FALSE);
1232 ok(err != NULL, "domdoc_validate() should always set err\n");
1233 hr = IXMLDOMParseError_get_errorCode(err, &l);
1234 EXPECT_HR(hr, S_OK);
1235 ok(l == E_XML_NODTD, "got %08x\n", l);
1236 IXMLDOMParseError_Release(err);
1237
1238 err = NULL;
1239 hr = IXMLDOMDocument2_validate(doc2, &err);
1240 EXPECT_HR(hr, S_FALSE);
1241 ok(err != NULL, "domdoc_validate() should always set err\n");
1242 hr = IXMLDOMParseError_get_errorCode(err, &l);
1243 EXPECT_HR(hr, S_OK);
1244 ok(l == E_XML_NODTD, "got %08x\n", l);
1245 IXMLDOMParseError_Release(err);
1246
1247 /* now load the schema */
1248 V_VT(&v) = VT_DISPATCH;
1249 V_DISPATCH(&v) = NULL;
1250 hr = IXMLDOMDocument2_QueryInterface(schema, &IID_IDispatch, (void**)&V_DISPATCH(&v));
1251 EXPECT_HR(hr, S_OK);
1252 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1253 hr = IXMLDOMSchemaCollection_add(cache, _bstr_("urn:x-schema:datatype-test-xdr"), v);
1254 EXPECT_HR(hr, S_OK);
1255 VariantClear(&v);
1256
1257 /* associate the cache to the doc */
1258 V_VT(&v) = VT_DISPATCH;
1259 V_DISPATCH(&v) = NULL;
1260 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatch, (void**)&V_DISPATCH(&v));
1261 EXPECT_HR(hr, S_OK);
1262 ok(V_DISPATCH(&v) != NULL, "failed to get IDispatch interface\n");
1263 hr = IXMLDOMDocument2_putref_schemas(doc2, v);
1264 EXPECT_HR(hr, S_OK);
1265 VariantClear(&v);
1266
1267 /* validate the doc */
1268 err = NULL;
1269 l = 0;
1270 bstr = NULL;
1271 hr = IXMLDOMDocument2_validate(doc2, &err);
1272 EXPECT_HR(hr, S_OK);
1273 ok(err != NULL, "domdoc_validate() should always set err\n");
1274 hr = IXMLDOMParseError_get_errorCode(err, &l);
1275 EXPECT_HR(hr, S_FALSE);
1276 hr = IXMLDOMParseError_get_reason(err, &bstr);
1277 EXPECT_HR(hr, S_FALSE);
1278 ok(l == 0, "got %08x : %s\n", l, wine_dbgstr_w(bstr));
1279 SysFreeString(bstr);
1280 IXMLDOMParseError_Release(err);
1281
1282 ptr = xdr_datatypes_data;
1283 while (ptr->query)
1284 {
1285 IXMLDOMNode* node = NULL;
1286 VARIANT type, testv;
1287
1288 /* check data types without the schema */
1289 memset(&testv, -1, sizeof(VARIANT));
1290 V_VT(&testv) = VT_NULL;
1291 V_BSTR(&testv) = NULL;
1292
1293 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_(ptr->query), &node);
1294 EXPECT_HR(hr, S_OK);
1295 ok(node != NULL, "expected node\n");
1296
1297 memset(&type, -1, sizeof(VARIANT));
1298 V_VT(&type) = VT_EMPTY;
1299 hr = IXMLDOMNode_get_dataType(node, &type);
1300 EXPECT_HR(hr, S_FALSE);
1301 ok(V_VT(&type) == VT_NULL, "got type %i\n", V_VT(&type));
1302 /* when returning VT_NULL, the pointer is set to NULL */
1303 ok(!memcmp(&testv, &type, sizeof(VARIANT)), "got %p\n", V_BSTR(&type));
1304
1305 VariantClear(&type);
1306 hr = IXMLDOMNode_get_nodeTypedValue(node, &type);
1307 ok(V_VT(&type) == VT_BSTR, "got variant type %i\n", V_VT(&v));
1308 VariantClear(&type);
1309 IXMLDOMNode_Release(node);
1310
1311 /* check the data with schema */
1312 node = NULL;
1313 hr = IXMLDOMDocument2_selectSingleNode(doc2, _bstr_(ptr->query), &node);
1314 EXPECT_HR(hr, S_OK);
1315 ok(node != NULL, "expected node\n");
1316
1317 V_VT(&type) = VT_EMPTY;
1318 hr = IXMLDOMNode_get_dataType(node, &type);
1319 if (ptr->typename)
1320 {
1321 EXPECT_HR(hr, S_OK);
1322 ok(V_VT(&type) == VT_BSTR, "got type %i\n", V_VT(&type));
1323 ok(!lstrcmpW(V_BSTR(&type), _bstr_(ptr->typename)), "got %s\n", wine_dbgstr_w(V_BSTR(&type)));
1324 }
1325 else
1326 {
1327 EXPECT_HR(hr, S_FALSE);
1328 ok(V_VT(&type) == VT_NULL, "%s: got type %i\n", ptr->query, V_VT(&type));
1329 }
1330
1331 VariantClear(&v);
1332 hr = IXMLDOMNode_get_nodeTypedValue(node, &v);
1333 EXPECT_HR(hr, S_OK);
1334
1335 if (ptr->todo)
1336 todo_wine
1337 ok(V_VT(&v) == ptr->type_schema, "%s: got variant type %i\n", ptr->query, V_VT(&v));
1338 else
1339 ok(V_VT(&v) == ptr->type_schema, "%s: got variant type %i\n", ptr->query, V_VT(&v));
1340
1341 switch (ptr->type_schema)
1342 {
1343 case VT_BOOL:
1344 ok(V_BOOL(&v) == VARIANT_TRUE, "got %x\n", V_BOOL(&v));
1345 break;
1346 case VT_I1:
1347 ok(V_I1(&v) == 42, "got %i\n", V_I1(&v));
1348 break;
1349 case VT_I2:
1350 ok(V_I2(&v) == 420, "got %i\n", V_I2(&v));
1351 break;
1352 case VT_I4:
1353 if (!strcmp(ptr->typename, "int"))
1354 ok(V_I4(&v) == 42, "got %i\n", V_I4(&v));
1355 else if (!strcmp(ptr->typename, "char"))
1356 todo_wine
1357 ok(V_I4(&v) == 'u', "got %x\n", V_I4(&v));
1358 else
1359 ok(V_I4(&v) == -420000000, "got %i\n", V_I4(&v));
1360 break;
1361 case VT_I8:
1362 expect_int64(V_I8(&v), -4200000000, 10);
1363 break;
1364 case VT_R4:
1365 ok(V_R4(&v) == (float)3.14159265, "got %f\n", V_R4(&v));
1366 break;
1367 case VT_R8:
1368 if (!strcmp(ptr->typename, "float"))
1369 ok(V_R8(&v) == (double)3.14159, "got %f\n", V_R8(&v));
1370 else
1371 todo_wine
1372 ok(V_R8(&v) == (double)3.14159265358979323846, "got %.20f\n", V_R8(&v));
1373 break;
1374 case VT_UI1:
1375 ok(V_UI1(&v) == 0xFF, "got %02x\n", V_UI1(&v));
1376 break;
1377 case VT_UI2:
1378 ok(V_UI2(&v) == 0xFFFF, "got %04x\n", V_UI2(&v));
1379 break;
1380 case VT_UI4:
1381 ok(V_UI4(&v) == 0xFFFFFFFF, "got %08x\n", V_UI4(&v));
1382 break;
1383 case VT_UI8:
1384 expect_uint64(V_UI8(&v), 0xFFFFFFFFFFFFFFFF, 16);
1385 break;
1386 default:
1387 ;
1388 }
1389
1390 VariantClear(&v);
1391
1392 IXMLDOMNode_Release(node);
1393
1394 ptr++;
1395 }
1396
1397 IXMLDOMDocument2_Release(schema);
1398 IXMLDOMDocument2_Release(doc);
1399 IXMLDOMDocument2_Release(doc2);
1400 IXMLDOMSchemaCollection_Release(cache);
1401
1402 free_bstrs();
1403 }
1404
1405 static void test_validate_on_load(void)
1406 {
1407 IXMLDOMSchemaCollection2 *cache;
1408 VARIANT_BOOL b;
1409 HRESULT hr;
1410
1411 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1412 if (!cache) return;
1413
1414 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, NULL);
1415 EXPECT_HR(hr, E_POINTER);
1416
1417 b = VARIANT_FALSE;
1418 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, &b);
1419 EXPECT_HR(hr, S_OK);
1420 ok(b == VARIANT_TRUE, "got %d\n", b);
1421
1422 IXMLDOMSchemaCollection2_Release(cache);
1423 }
1424
1425 static void test_obj_dispex(IUnknown *obj)
1426 {
1427 static const WCHAR testW[] = {'t','e','s','t','p','r','o','p',0};
1428 static const WCHAR starW[] = {'*',0};
1429 DISPID dispid = DISPID_SAX_XMLREADER_GETFEATURE;
1430 IDispatchEx *dispex;
1431 IUnknown *unk;
1432 DWORD props;
1433 UINT ticnt;
1434 HRESULT hr;
1435 BSTR name;
1436
1437 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
1438 EXPECT_HR(hr, S_OK);
1439 if (FAILED(hr)) return;
1440
1441 ticnt = 0;
1442 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
1443 EXPECT_HR(hr, S_OK);
1444 ok(ticnt == 1, "ticnt=%u\n", ticnt);
1445
1446 name = SysAllocString(starW);
1447 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
1448 EXPECT_HR(hr, E_NOTIMPL);
1449 SysFreeString(name);
1450
1451 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
1452 EXPECT_HR(hr, E_NOTIMPL);
1453
1454 props = 0;
1455 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
1456 EXPECT_HR(hr, E_NOTIMPL);
1457 ok(props == 0, "expected 0 got %d\n", props);
1458
1459 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
1460 EXPECT_HR(hr, E_NOTIMPL);
1461 if (SUCCEEDED(hr)) SysFreeString(name);
1462
1463 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_SCHEMACOLLECTION_ADD, &dispid);
1464 EXPECT_HR(hr, E_NOTIMPL);
1465
1466 unk = (IUnknown*)0xdeadbeef;
1467 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
1468 EXPECT_HR(hr, E_NOTIMPL);
1469 ok(unk == (IUnknown*)0xdeadbeef, "got %p\n", unk);
1470
1471 name = SysAllocString(testW);
1472 hr = IDispatchEx_GetDispID(dispex, name, fdexNameEnsure, &dispid);
1473 ok(hr == DISP_E_UNKNOWNNAME, "got 0x%08x\n", hr);
1474 SysFreeString(name);
1475
1476 IDispatchEx_Release(dispex);
1477 }
1478
1479 static void test_dispex(void)
1480 {
1481 IXMLDOMSchemaCollection *cache;
1482 IDispatchEx *dispex;
1483 IUnknown *unk;
1484 HRESULT hr;
1485 DISPPARAMS dispparams;
1486 VARIANT arg, ret;
1487
1488 cache = create_cache(&IID_IXMLDOMSchemaCollection);
1489 if (!cache) return;
1490
1491 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IUnknown, (void**)&unk);
1492 EXPECT_HR(hr, S_OK);
1493 test_obj_dispex(unk);
1494 IUnknown_Release(unk);
1495
1496 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatchEx, (void**)&dispex);
1497 ok(hr == S_OK, "got 0x%08x\n", hr);
1498
1499 V_VT(&arg) = VT_I4;
1500 V_I4(&arg) = 0;
1501 dispparams.cArgs = 1;
1502 dispparams.cNamedArgs = 0;
1503 dispparams.rgdispidNamedArgs = NULL;
1504 dispparams.rgvarg = &arg;
1505
1506 V_VT(&ret) = VT_EMPTY;
1507 V_DISPATCH(&ret) = (void*)0x1;
1508 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
1509 ok(hr == DISP_E_MEMBERNOTFOUND, "got 0x%08x\n", hr);
1510 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
1511 ok(V_DISPATCH(&ret) == (void*)0x1, "got %p\n", V_DISPATCH(&ret));
1512
1513 IDispatchEx_Release(dispex);
1514 IXMLDOMSchemaCollection_Release(cache);
1515
1516 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection);
1517 if (cache)
1518 {
1519 test_obj_dispex((IUnknown*)cache);
1520 IXMLDOMSchemaCollection_Release(cache);
1521 }
1522 }
1523
1524 static void test_get(void)
1525 {
1526 IXMLDOMSchemaCollection2 *cache;
1527 IXMLDOMNode *node;
1528 HRESULT hr;
1529
1530 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
1531 if (!cache) return;
1532
1533 hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
1534 EXPECT_HR(hr, E_NOTIMPL);
1535
1536 hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
1537 EXPECT_HR(hr, E_NOTIMPL);
1538
1539 IXMLDOMSchemaCollection2_Release(cache);
1540
1541 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1542 if (!cache) return;
1543
1544 hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
1545 EXPECT_HR(hr, E_POINTER);
1546
1547 hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
1548 EXPECT_HR(hr, S_OK);
1549
1550 IXMLDOMSchemaCollection2_Release(cache);
1551 free_bstrs();
1552 }
1553
1554 static void test_remove(void)
1555 {
1556 IXMLDOMSchemaCollection2 *cache;
1557 IXMLDOMDocument *doc;
1558 VARIANT_BOOL b;
1559 HRESULT hr;
1560 VARIANT v;
1561 LONG len;
1562
1563 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
1564 if (!cache) return;
1565
1566 doc = create_document_version(60, &IID_IXMLDOMDocument);
1567 ok(doc != NULL, "got %p\n", doc);
1568
1569 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
1570 EXPECT_HR(hr, S_OK);
1571
1572 V_VT(&v) = VT_DISPATCH;
1573 V_DISPATCH(&v) = (IDispatch*)doc;
1574 hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
1575 EXPECT_HR(hr, S_OK);
1576
1577 len = -1;
1578 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1579 EXPECT_HR(hr, S_OK);
1580 ok(len == 1, "got %d\n", len);
1581
1582 /* ::remove() is a stub for version 6 */
1583 hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
1584 EXPECT_HR(hr, E_NOTIMPL);
1585
1586 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
1587 EXPECT_HR(hr, E_NOTIMPL);
1588
1589 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
1590 EXPECT_HR(hr, E_NOTIMPL);
1591
1592 len = -1;
1593 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1594 EXPECT_HR(hr, S_OK);
1595 ok(len == 1, "got %d\n", len);
1596
1597 IXMLDOMDocument_Release(doc);
1598 IXMLDOMSchemaCollection2_Release(cache);
1599 free_bstrs();
1600
1601 /* ::remove() works for version 4 */
1602 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1603 if (!cache) return;
1604
1605 doc = create_document_version(40, &IID_IXMLDOMDocument);
1606 ok(doc != NULL, "got %p\n", doc);
1607
1608 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
1609 EXPECT_HR(hr, S_OK);
1610
1611 V_VT(&v) = VT_DISPATCH;
1612 V_DISPATCH(&v) = (IDispatch*)doc;
1613 hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
1614 EXPECT_HR(hr, S_OK);
1615
1616 len = -1;
1617 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1618 EXPECT_HR(hr, S_OK);
1619 ok(len == 1, "got %d\n", len);
1620
1621 hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
1622 EXPECT_HR(hr, S_OK);
1623
1624 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
1625 EXPECT_HR(hr, S_OK);
1626
1627 len = -1;
1628 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1629 EXPECT_HR(hr, S_OK);
1630 ok(len == 1, "got %d\n", len);
1631
1632 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
1633 EXPECT_HR(hr, S_OK);
1634
1635 len = -1;
1636 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1637 EXPECT_HR(hr, S_OK);
1638 ok(len == 0, "got %d\n", len);
1639
1640 IXMLDOMDocument_Release(doc);
1641 IXMLDOMSchemaCollection2_Release(cache);
1642
1643 free_bstrs();
1644 }
1645
1646 START_TEST(schema)
1647 {
1648 HRESULT r;
1649
1650 r = CoInitialize( NULL );
1651 ok( r == S_OK, "failed to init com\n");
1652
1653 test_schema_refs();
1654 test_collection_refs();
1655 test_length();
1656 test_collection_content();
1657 test_XDR_schemas();
1658 test_XDR_datatypes();
1659 test_validate_on_load();
1660 test_dispex();
1661 test_get();
1662 test_remove();
1663
1664 CoUninitialize();
1665 }