[MSXML3_WINETEST]
[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;
1287
1288 /* check data types without the schema */
1289 hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_(ptr->query), &node);
1290 EXPECT_HR(hr, S_OK);
1291 ok(node != NULL, "expected node\n");
1292
1293 V_VT(&type) = VT_EMPTY;
1294 V_BSTR(&type) = (void*)-1;
1295 hr = IXMLDOMNode_get_dataType(node, &type);
1296 EXPECT_HR(hr, S_FALSE);
1297 ok(V_VT(&type) == VT_NULL, "got type %i\n", V_VT(&type));
1298 /* when returning VT_NULL, the pointer is set to NULL */
1299 ok(V_BSTR(&type) == NULL, "got %p\n", V_BSTR(&type));
1300
1301 VariantClear(&type);
1302 hr = IXMLDOMNode_get_nodeTypedValue(node, &type);
1303 ok(V_VT(&type) == VT_BSTR, "got variant type %i\n", V_VT(&v));
1304 VariantClear(&type);
1305 IXMLDOMNode_Release(node);
1306
1307 /* check the data with schema */
1308 node = NULL;
1309 hr = IXMLDOMDocument2_selectSingleNode(doc2, _bstr_(ptr->query), &node);
1310 EXPECT_HR(hr, S_OK);
1311 ok(node != NULL, "expected node\n");
1312
1313 V_VT(&type) = VT_EMPTY;
1314 hr = IXMLDOMNode_get_dataType(node, &type);
1315 if (ptr->typename)
1316 {
1317 EXPECT_HR(hr, S_OK);
1318 ok(V_VT(&type) == VT_BSTR, "got type %i\n", V_VT(&type));
1319 ok(!lstrcmpW(V_BSTR(&type), _bstr_(ptr->typename)), "got %s\n", wine_dbgstr_w(V_BSTR(&type)));
1320 }
1321 else
1322 {
1323 EXPECT_HR(hr, S_FALSE);
1324 ok(V_VT(&type) == VT_NULL, "%s: got type %i\n", ptr->query, V_VT(&type));
1325 }
1326
1327 VariantClear(&v);
1328 hr = IXMLDOMNode_get_nodeTypedValue(node, &v);
1329 EXPECT_HR(hr, S_OK);
1330
1331 if (ptr->todo)
1332 todo_wine
1333 ok(V_VT(&v) == ptr->type_schema, "%s: got variant type %i\n", ptr->query, V_VT(&v));
1334 else
1335 ok(V_VT(&v) == ptr->type_schema, "%s: got variant type %i\n", ptr->query, V_VT(&v));
1336
1337 switch (ptr->type_schema)
1338 {
1339 case VT_BOOL:
1340 ok(V_BOOL(&v) == VARIANT_TRUE, "got %x\n", V_BOOL(&v));
1341 break;
1342 case VT_I1:
1343 ok(V_I1(&v) == 42, "got %i\n", V_I1(&v));
1344 break;
1345 case VT_I2:
1346 ok(V_I2(&v) == 420, "got %i\n", V_I2(&v));
1347 break;
1348 case VT_I4:
1349 if (!strcmp(ptr->typename, "int"))
1350 ok(V_I4(&v) == 42, "got %i\n", V_I4(&v));
1351 else if (!strcmp(ptr->typename, "char"))
1352 todo_wine
1353 ok(V_I4(&v) == 'u', "got %x\n", V_I4(&v));
1354 else
1355 ok(V_I4(&v) == -420000000, "got %i\n", V_I4(&v));
1356 break;
1357 case VT_I8:
1358 expect_int64(V_I8(&v), -4200000000, 10);
1359 break;
1360 case VT_R4:
1361 ok(V_R4(&v) == (float)3.14159265, "got %f\n", V_R4(&v));
1362 break;
1363 case VT_R8:
1364 if (!strcmp(ptr->typename, "float"))
1365 ok(V_R8(&v) == (double)3.14159, "got %f\n", V_R8(&v));
1366 else
1367 todo_wine
1368 ok(V_R8(&v) == (double)3.14159265358979323846, "got %.20f\n", V_R8(&v));
1369 break;
1370 case VT_UI1:
1371 ok(V_UI1(&v) == 0xFF, "got %02x\n", V_UI1(&v));
1372 break;
1373 case VT_UI2:
1374 ok(V_UI2(&v) == 0xFFFF, "got %04x\n", V_UI2(&v));
1375 break;
1376 case VT_UI4:
1377 ok(V_UI4(&v) == 0xFFFFFFFF, "got %08x\n", V_UI4(&v));
1378 break;
1379 case VT_UI8:
1380 expect_uint64(V_UI8(&v), 0xFFFFFFFFFFFFFFFF, 16);
1381 break;
1382 default:
1383 ;
1384 }
1385
1386 VariantClear(&v);
1387
1388 IXMLDOMNode_Release(node);
1389
1390 ptr++;
1391 }
1392
1393 IXMLDOMDocument2_Release(schema);
1394 IXMLDOMDocument2_Release(doc);
1395 IXMLDOMDocument2_Release(doc2);
1396 IXMLDOMSchemaCollection_Release(cache);
1397
1398 free_bstrs();
1399 }
1400
1401 static void test_validate_on_load(void)
1402 {
1403 IXMLDOMSchemaCollection2 *cache;
1404 VARIANT_BOOL b;
1405 HRESULT hr;
1406
1407 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1408 if (!cache) return;
1409
1410 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, NULL);
1411 EXPECT_HR(hr, E_POINTER);
1412
1413 b = VARIANT_FALSE;
1414 hr = IXMLDOMSchemaCollection2_get_validateOnLoad(cache, &b);
1415 EXPECT_HR(hr, S_OK);
1416 ok(b == VARIANT_TRUE, "got %d\n", b);
1417
1418 IXMLDOMSchemaCollection2_Release(cache);
1419 }
1420
1421 static void test_obj_dispex(IUnknown *obj)
1422 {
1423 static const WCHAR testW[] = {'t','e','s','t','p','r','o','p',0};
1424 static const WCHAR starW[] = {'*',0};
1425 DISPID dispid = DISPID_SAX_XMLREADER_GETFEATURE;
1426 IDispatchEx *dispex;
1427 IUnknown *unk;
1428 DWORD props;
1429 UINT ticnt;
1430 HRESULT hr;
1431 BSTR name;
1432
1433 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
1434 EXPECT_HR(hr, S_OK);
1435 if (FAILED(hr)) return;
1436
1437 ticnt = 0;
1438 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
1439 EXPECT_HR(hr, S_OK);
1440 ok(ticnt == 1, "ticnt=%u\n", ticnt);
1441
1442 name = SysAllocString(starW);
1443 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
1444 EXPECT_HR(hr, E_NOTIMPL);
1445 SysFreeString(name);
1446
1447 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
1448 EXPECT_HR(hr, E_NOTIMPL);
1449
1450 props = 0;
1451 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
1452 EXPECT_HR(hr, E_NOTIMPL);
1453 ok(props == 0, "expected 0 got %d\n", props);
1454
1455 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
1456 EXPECT_HR(hr, E_NOTIMPL);
1457 if (SUCCEEDED(hr)) SysFreeString(name);
1458
1459 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_XMLDOM_SCHEMACOLLECTION_ADD, &dispid);
1460 EXPECT_HR(hr, E_NOTIMPL);
1461
1462 unk = (IUnknown*)0xdeadbeef;
1463 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
1464 EXPECT_HR(hr, E_NOTIMPL);
1465 ok(unk == (IUnknown*)0xdeadbeef, "got %p\n", unk);
1466
1467 name = SysAllocString(testW);
1468 hr = IDispatchEx_GetDispID(dispex, name, fdexNameEnsure, &dispid);
1469 ok(hr == DISP_E_UNKNOWNNAME, "got 0x%08x\n", hr);
1470 SysFreeString(name);
1471
1472 IDispatchEx_Release(dispex);
1473 }
1474
1475 static void test_dispex(void)
1476 {
1477 IXMLDOMSchemaCollection *cache;
1478 IDispatchEx *dispex;
1479 IUnknown *unk;
1480 HRESULT hr;
1481 DISPPARAMS dispparams;
1482 VARIANT arg, ret;
1483
1484 cache = create_cache(&IID_IXMLDOMSchemaCollection);
1485 if (!cache) return;
1486
1487 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IUnknown, (void**)&unk);
1488 EXPECT_HR(hr, S_OK);
1489 test_obj_dispex(unk);
1490 IUnknown_Release(unk);
1491
1492 hr = IXMLDOMSchemaCollection_QueryInterface(cache, &IID_IDispatchEx, (void**)&dispex);
1493 ok(hr == S_OK, "got 0x%08x\n", hr);
1494
1495 V_VT(&arg) = VT_I4;
1496 V_I4(&arg) = 0;
1497 dispparams.cArgs = 1;
1498 dispparams.cNamedArgs = 0;
1499 dispparams.rgdispidNamedArgs = NULL;
1500 dispparams.rgvarg = &arg;
1501
1502 V_VT(&ret) = VT_EMPTY;
1503 V_DISPATCH(&ret) = (void*)0x1;
1504 hr = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, 0, DISPATCH_METHOD, &dispparams, &ret, NULL, NULL);
1505 ok(hr == DISP_E_MEMBERNOTFOUND, "got 0x%08x\n", hr);
1506 ok(V_VT(&ret) == VT_EMPTY, "got %d\n", V_VT(&ret));
1507 ok(V_DISPATCH(&ret) == (void*)0x1, "got %p\n", V_DISPATCH(&ret));
1508
1509 IDispatchEx_Release(dispex);
1510 IXMLDOMSchemaCollection_Release(cache);
1511
1512 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection);
1513 if (cache)
1514 {
1515 test_obj_dispex((IUnknown*)cache);
1516 IXMLDOMSchemaCollection_Release(cache);
1517 }
1518 }
1519
1520 static void test_get(void)
1521 {
1522 IXMLDOMSchemaCollection2 *cache;
1523 IXMLDOMNode *node;
1524 HRESULT hr;
1525
1526 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
1527 if (!cache) return;
1528
1529 hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
1530 ok(hr == E_NOTIMPL || hr == E_POINTER /* win8 */, "got %08x\n", hr);
1531
1532 hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
1533 EXPECT_HR(hr, E_NOTIMPL);
1534
1535 IXMLDOMSchemaCollection2_Release(cache);
1536
1537 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1538 if (!cache) return;
1539
1540 hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
1541 EXPECT_HR(hr, E_POINTER);
1542
1543 hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
1544 EXPECT_HR(hr, S_OK);
1545
1546 IXMLDOMSchemaCollection2_Release(cache);
1547 free_bstrs();
1548 }
1549
1550 static void test_remove(void)
1551 {
1552 IXMLDOMSchemaCollection2 *cache;
1553 IXMLDOMDocument *doc;
1554 VARIANT_BOOL b;
1555 HRESULT hr;
1556 VARIANT v;
1557 LONG len;
1558
1559 cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
1560 if (!cache) return;
1561
1562 doc = create_document_version(60, &IID_IXMLDOMDocument);
1563 ok(doc != NULL, "got %p\n", doc);
1564
1565 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
1566 EXPECT_HR(hr, S_OK);
1567
1568 V_VT(&v) = VT_DISPATCH;
1569 V_DISPATCH(&v) = (IDispatch*)doc;
1570 hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
1571 EXPECT_HR(hr, S_OK);
1572
1573 len = -1;
1574 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1575 EXPECT_HR(hr, S_OK);
1576 ok(len == 1, "got %d\n", len);
1577
1578 /* ::remove() is a stub for version 6 */
1579 hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
1580 EXPECT_HR(hr, E_NOTIMPL);
1581
1582 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
1583 EXPECT_HR(hr, E_NOTIMPL);
1584
1585 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
1586 EXPECT_HR(hr, E_NOTIMPL);
1587
1588 len = -1;
1589 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1590 EXPECT_HR(hr, S_OK);
1591 ok(len == 1, "got %d\n", len);
1592
1593 IXMLDOMDocument_Release(doc);
1594 IXMLDOMSchemaCollection2_Release(cache);
1595 free_bstrs();
1596
1597 /* ::remove() works for version 4 */
1598 cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
1599 if (!cache) return;
1600
1601 doc = create_document_version(40, &IID_IXMLDOMDocument);
1602 ok(doc != NULL, "got %p\n", doc);
1603
1604 hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
1605 EXPECT_HR(hr, S_OK);
1606
1607 V_VT(&v) = VT_DISPATCH;
1608 V_DISPATCH(&v) = (IDispatch*)doc;
1609 hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
1610 EXPECT_HR(hr, S_OK);
1611
1612 len = -1;
1613 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1614 EXPECT_HR(hr, S_OK);
1615 ok(len == 1, "got %d\n", len);
1616
1617 hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
1618 EXPECT_HR(hr, S_OK);
1619
1620 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
1621 EXPECT_HR(hr, S_OK);
1622
1623 len = -1;
1624 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1625 EXPECT_HR(hr, S_OK);
1626 ok(len == 1, "got %d\n", len);
1627
1628 hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
1629 EXPECT_HR(hr, S_OK);
1630
1631 len = -1;
1632 hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
1633 EXPECT_HR(hr, S_OK);
1634 ok(len == 0, "got %d\n", len);
1635
1636 IXMLDOMDocument_Release(doc);
1637 IXMLDOMSchemaCollection2_Release(cache);
1638
1639 free_bstrs();
1640 }
1641
1642 START_TEST(schema)
1643 {
1644 HRESULT r;
1645
1646 r = CoInitialize( NULL );
1647 ok( r == S_OK, "failed to init com\n");
1648
1649 test_schema_refs();
1650 test_collection_refs();
1651 test_length();
1652 test_collection_content();
1653 test_XDR_schemas();
1654 test_XDR_datatypes();
1655 test_validate_on_load();
1656 test_dispex();
1657 test_get();
1658 test_remove();
1659
1660 CoUninitialize();
1661 }