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