4 * Copyright 2007 Huw Davies
5 * Copyright 2010 Adam Martinson for CodeWeavers
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.
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.
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
30 #include "msxml2did.h"
33 #include "wine/test.h"
35 #define EXPECT_HR(hr,hr_exp) \
36 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
38 static const WCHAR xdr_schema_uri
[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
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
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'"
52 " <ElementType name='x' dt:type='boolean'/>"
53 " <ElementType name='y'>"
54 " <datatype dt:type='int'/>"
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'/>"
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'"
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'/>"
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'"
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'/>"
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'>"
103 " <sequence maxOccurs='unbounded'>"
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'>"
117 " <sequence maxOccurs='unbounded'>"
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'>"
131 " <sequence maxOccurs='unbounded'>"
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"
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"
205 " <ElementType name='Property' content='eltOnly' order='seq'>\n"
206 " <element type='Name'/>\n"
207 " <element type='Value'/>\n"
209 " <ElementType name='Properties' content='eltOnly'>\n"
210 " <element type='Property' minOccurs='0' maxOccurs='*'/>\n"
214 static const CHAR szDatatypeXML
[] =
215 "<?xml version='1.0'?>\n"
216 "<Properties xmlns='urn:x-schema:datatype-test-xdr'>\n"
218 " <Name>testBase64</Name>\n"
220 " <base64Data>+HugeNumber+</base64Data>\n"
224 " <Name>testHex</Name>\n"
226 " <hexData>deadbeef</hexData>\n"
230 " <Name>testBool</Name>\n"
232 " <boolData>1</boolData>\n"
236 " <Name>testChar</Name>\n"
238 " <charData>u</charData>\n"
242 " <Name>testDate</Name>\n"
244 " <dateData>1998-02-01</dateData>\n"
248 " <Name>testDateTime</Name>\n"
250 " <dateTimeData>1998-02-01T12:34:56</dateTimeData>\n"
254 " <Name>testDateTimeTz</Name>\n"
256 " <dateTimeTzData>1998-02-01T12:34:56-06:00</dateTimeTzData>\n"
260 " <Name>testFixed</Name>\n"
262 " <fixedData>3.1416</fixedData>\n"
266 " <Name>testFloat</Name>\n"
268 " <floatData>3.14159</floatData>\n"
272 " <Name>testI1</Name>\n"
274 " <i1Data>42</i1Data>\n"
278 " <Name>testI2</Name>\n"
280 " <i2Data>420</i2Data>\n"
284 " <Name>testI4</Name>\n"
286 " <i4Data>-420000000</i4Data>\n"
290 " <Name>testI8</Name>\n"
292 " <i8Data>-4200000000</i8Data>\n"
296 " <Name>testInt</Name>\n"
298 " <intData>42</intData>\n"
302 " <Name>testNmtoken</Name>\n"
304 " <nmtokData>tok1</nmtokData>\n"
308 " <Name>testNmtokens</Name>\n"
310 " <nmtoksData>tok1 tok2 tok3</nmtoksData>\n"
314 " <Name>testNumber</Name>\n"
316 " <numData>3.14159</numData>\n"
320 " <Name>testR4</Name>\n"
322 " <r4Data>3.14159265</r4Data>\n"
326 " <Name>testR8</Name>\n"
328 " <r8Data>3.14159265358979323846</r8Data>\n"
332 " <Name>testString</Name>\n"
334 " <stringData>foo bar</stringData>\n"
338 " <Name>testTime</Name>\n"
340 " <timeData>12:34:56</timeData>\n"
344 " <Name>testTimeTz</Name>\n"
346 " <timeTzData>12:34:56-06:00</timeTzData>\n"
350 " <Name>testU1</Name>\n"
352 " <u1Data>255</u1Data>\n"
356 " <Name>testU2</Name>\n"
358 " <u2Data>65535</u2Data>\n"
362 " <Name>testU4</Name>\n"
364 " <u4Data>4294967295</u4Data>\n"
368 " <Name>testU8</Name>\n"
370 " <u8Data>18446744073709551615</u8Data>\n"
374 " <Name>testURI</Name>\n"
376 " <uriData>urn:schemas-microsoft-com:datatypes</uriData>\n"
380 " <Name>testUUID</Name>\n"
382 " <uuidData>2933BF81-7B36-11D2-B20E-00C04F983E60</uuidData>\n"
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"
400 " <element type='z'/>\n"
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>";
409 #define check_ref_expr(expr, n) { \
411 ok(ref == n, "expected %i refs, got %i\n", n, ref); \
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); \
421 #define ole_check(expr) { \
423 ok(r == S_OK, #expr " returned %x\n", r); \
426 #define ole_expect(expr, expect) { \
428 ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
431 #define _expect64(expr, str, base, TYPE, CONV) { \
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)); \
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)
442 static BSTR alloced_bstrs
[256];
443 static int alloced_bstrs_count
;
445 static BSTR
alloc_str_from_narrow(const char *str
)
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
);
453 static BSTR
_bstr_(const char *str
)
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
++];
460 static void free_bstrs(void)
463 for (i
= 0; i
< alloced_bstrs_count
; i
++)
464 SysFreeString(alloced_bstrs
[i
]);
465 alloced_bstrs_count
= 0;
468 static VARIANT
_variantdoc_(void* doc
)
471 V_VT(&v
) = VT_DISPATCH
;
472 V_DISPATCH(&v
) = (IDispatch
*)doc
;
476 static void* _create_object(const GUID
*clsid
, const char *name
, const IID
*iid
, int line
)
481 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
, iid
, &obj
);
483 win_skip_(__FILE__
,line
)("failed to create %s instance: 0x%08x\n", name
, hr
);
488 #define _create(cls) cls, #cls
490 #define create_document(iid) _create_object(&_create(CLSID_DOMDocument), iid, __LINE__)
492 #define create_document_version(v, iid) _create_object(&_create(CLSID_DOMDocument ## v), iid, __LINE__)
494 #define create_cache(iid) _create_object(&_create(CLSID_XMLSchemaCache), iid, __LINE__)
496 #define create_cache_version(v, iid) _create_object(&_create(CLSID_XMLSchemaCache ## v), iid, __LINE__)
498 static void test_schema_refs(void)
500 static const WCHAR emptyW
[] = {0};
501 IXMLDOMDocument2
*doc
;
503 IXMLDOMSchemaCollection
*cache
;
509 doc
= create_document(&IID_IXMLDOMDocument2
);
513 cache
= create_cache(&IID_IXMLDOMSchemaCollection
);
516 IXMLDOMDocument2_Release(doc
);
521 str
= SysAllocString(xdr_schema_xml
);
522 ole_check(IXMLDOMDocument2_loadXML(doc
, str
, &b
));
523 ok(b
== VARIANT_TRUE
, "b %04x\n", b
);
526 node
= (void*)0xdeadbeef;
527 ole_check(IXMLDOMSchemaCollection_get(cache
, NULL
, &node
));
528 ok(node
== NULL
, "%p\n", node
);
530 /* NULL uri pointer, still adds a document */
531 ole_check(IXMLDOMSchemaCollection_add(cache
, NULL
, _variantdoc_(doc
)));
533 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &len
));
534 ok(len
== 1, "got %d\n", len
);
535 /* read back - empty valid BSTR */
537 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache
, 0, &str
));
538 ok(str
&& *str
== 0, "got %p\n", str
);
542 ole_check(IXMLDOMSchemaCollection_get(cache
, NULL
, &node
));
543 ok(node
!= NULL
, "%p\n", node
);
544 IXMLDOMNode_Release(node
);
547 str
= SysAllocString(emptyW
);
548 ole_check(IXMLDOMSchemaCollection_get(cache
, str
, &node
));
549 ok(node
!= NULL
, "%p\n", node
);
550 IXMLDOMNode_Release(node
);
553 /* remove with NULL uri */
554 ole_check(IXMLDOMSchemaCollection_remove(cache
, NULL
));
556 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &len
));
557 ok(len
== 0, "got %d\n", len
);
559 str
= SysAllocString(xdr_schema_uri
);
560 ole_check(IXMLDOMSchemaCollection_add(cache
, str
, _variantdoc_(doc
)));
562 /* IXMLDOMSchemaCollection_add doesn't add a ref on doc */
563 check_refs(IXMLDOMDocument2
, doc
, 1);
568 ole_expect(IXMLDOMDocument2_get_schemas(doc
, &v
), S_FALSE
);
569 ok(V_VT(&v
) == VT_NULL
, "vt %x\n", V_VT(&v
));
571 check_ref_expr(IXMLDOMSchemaCollection_AddRef(cache
), 2);
572 V_VT(&v
) = VT_DISPATCH
;
573 V_DISPATCH(&v
) = (IDispatch
*)cache
;
575 /* check that putref_schemas takes a ref */
576 ole_check(IXMLDOMDocument2_putref_schemas(doc
, v
));
577 check_refs(IXMLDOMSchemaCollection
, cache
, 3);
579 VariantClear(&v
); /* refs now 2 */
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);
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);
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);
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);
601 /* call putref_schema with some odd variants */
603 ole_expect(IXMLDOMDocument2_putref_schemas(doc
, v
), E_FAIL
);
604 check_refs(IXMLDOMSchemaCollection
, cache
, 2);
606 /* calling with VT_EMPTY releases the schema */
608 ole_check(IXMLDOMDocument2_putref_schemas(doc
, v
));
609 check_refs(IXMLDOMSchemaCollection
, cache
, 1);
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);
618 VariantClear(&v
); /* refs now 2 */
620 /* calling with VT_NULL releases the schema */
622 ole_check(IXMLDOMDocument2_putref_schemas(doc
, v
));
623 check_refs(IXMLDOMSchemaCollection
, cache
, 1);
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);
633 VariantClear(&v
); /* refs now 2 */
635 /* release the final ref on the doc which should release its ref on the schema */
636 check_ref_expr(IXMLDOMDocument2_Release(doc
), 0);
638 check_refs(IXMLDOMSchemaCollection
, cache
, 1);
639 check_ref_expr(IXMLDOMSchemaCollection_Release(cache
), 0);
642 static void test_collection_refs(void)
644 IXMLDOMDocument2
*schema1
, *schema2
, *schema3
;
645 IXMLDOMSchemaCollection
*cache1
, *cache2
, *cache3
;
649 schema1
= create_document(&IID_IXMLDOMDocument2
);
650 schema2
= create_document(&IID_IXMLDOMDocument2
);
651 schema3
= create_document(&IID_IXMLDOMDocument2
);
653 cache1
= create_cache(&IID_IXMLDOMSchemaCollection
);
654 cache2
= create_cache(&IID_IXMLDOMSchemaCollection
);
655 cache3
= create_cache(&IID_IXMLDOMSchemaCollection
);
657 if (!schema1
|| !schema2
|| !schema3
|| !cache1
|| !cache2
|| !cache3
)
659 if (schema1
) IXMLDOMDocument2_Release(schema1
);
660 if (schema2
) IXMLDOMDocument2_Release(schema2
);
661 if (schema3
) IXMLDOMDocument2_Release(schema3
);
663 if (cache1
) IXMLDOMSchemaCollection_Release(cache1
);
664 if (cache2
) IXMLDOMSchemaCollection_Release(cache2
);
665 if (cache3
) IXMLDOMSchemaCollection_Release(cache2
);
670 ole_check(IXMLDOMDocument2_loadXML(schema1
, _bstr_(xdr_schema1_xml
), &b
));
671 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
673 ole_check(IXMLDOMDocument2_loadXML(schema2
, _bstr_(xdr_schema2_xml
), &b
));
674 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
676 ole_check(IXMLDOMDocument2_loadXML(schema3
, _bstr_(xdr_schema3_xml
), &b
));
677 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
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
)));
683 check_ref_expr(IXMLDOMDocument2_Release(schema1
), 0);
684 check_ref_expr(IXMLDOMDocument2_Release(schema2
), 0);
685 check_ref_expr(IXMLDOMDocument2_Release(schema3
), 0);
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
));
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);
700 ole_expect(IXMLDOMSchemaCollection_addCollection(cache1
, NULL
), E_POINTER
);
701 ole_check(IXMLDOMSchemaCollection_addCollection(cache2
, cache1
));
702 ole_check(IXMLDOMSchemaCollection_addCollection(cache3
, cache2
));
705 ole_check(IXMLDOMSchemaCollection_get_length(cache1
, &length
));
706 ok(length
== 1, "expected length 1, got %i\n", length
);
709 ole_check(IXMLDOMSchemaCollection_get_length(cache2
, &length
));
710 ok(length
== 2, "expected length 2, got %i\n", length
);
713 ole_check(IXMLDOMSchemaCollection_get_length(cache3
, &length
));
714 ok(length
== 3, "expected length 3, got %i\n", length
);
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);
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);
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);
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
));
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);
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);
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);
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);
761 static void test_length(void)
763 IXMLDOMDocument2
*schema1
, *schema2
, *schema3
;
764 IXMLDOMSchemaCollection
*cache
;
769 schema1
= create_document(&IID_IXMLDOMDocument2
);
770 schema2
= create_document(&IID_IXMLDOMDocument2
);
771 schema3
= create_document(&IID_IXMLDOMDocument2
);
773 cache
= create_cache(&IID_IXMLDOMSchemaCollection
);
775 if (!schema1
|| !schema2
|| !schema3
|| !cache
)
777 if (schema1
) IXMLDOMDocument2_Release(schema1
);
778 if (schema2
) IXMLDOMDocument2_Release(schema2
);
779 if (schema3
) IXMLDOMDocument2_Release(schema3
);
781 if (cache
) IXMLDOMSchemaCollection_Release(cache
);
788 ole_check(IXMLDOMDocument2_loadXML(schema1
, _bstr_(xdr_schema1_xml
), &b
));
789 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
791 ole_check(IXMLDOMDocument2_loadXML(schema2
, _bstr_(xdr_schema2_xml
), &b
));
792 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
794 ole_check(IXMLDOMDocument2_loadXML(schema3
, _bstr_(xdr_schema3_xml
), &b
));
795 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
797 ole_expect(IXMLDOMSchemaCollection_get_length(cache
, NULL
), E_POINTER
);
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
)));
804 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &length
));
805 ok(length
== 0, "expected length 0, got %i\n", length
);
807 ole_check(IXMLDOMSchemaCollection_add(cache
, _bstr_(xdr_schema1_uri
), _variantdoc_(schema1
)));
810 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &length
));
811 ok(length
== 1, "expected length 1, got %i\n", length
);
813 ole_check(IXMLDOMSchemaCollection_add(cache
, _bstr_(xdr_schema2_uri
), _variantdoc_(schema2
)));
816 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &length
));
817 ok(length
== 2, "expected length 2, got %i\n", length
);
819 ole_check(IXMLDOMSchemaCollection_add(cache
, _bstr_(xdr_schema3_uri
), _variantdoc_(schema3
)));
822 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &length
));
823 ok(length
== 3, "expected length 3, got %i\n", length
);
825 /* adding with VT_NULL is the same as removing */
827 ole_check(IXMLDOMSchemaCollection_add(cache
, _bstr_(xdr_schema1_uri
), v
));
830 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &length
));
831 ok(length
== 2, "expected length 2, got %i\n", length
);
833 ole_check(IXMLDOMSchemaCollection_remove(cache
, _bstr_(xdr_schema2_uri
)));
836 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &length
));
837 ok(length
== 1, "expected length 1, got %i\n", length
);
839 ole_check(IXMLDOMSchemaCollection_remove(cache
, _bstr_(xdr_schema3_uri
)));
842 ole_check(IXMLDOMSchemaCollection_get_length(cache
, &length
));
843 ok(length
== 0, "expected length 0, got %i\n", length
);
845 IXMLDOMDocument2_Release(schema1
);
846 IXMLDOMDocument2_Release(schema2
);
847 IXMLDOMDocument2_Release(schema3
);
848 IXMLDOMSchemaCollection_Release(cache
);
853 static void test_collection_content(void)
855 IXMLDOMDocument2
*schema1
, *schema2
, *schema3
, *schema4
, *schema5
;
856 BSTR content
[5] = {NULL
, NULL
, NULL
, NULL
, NULL
};
857 IXMLDOMSchemaCollection
*cache1
, *cache2
;
864 schema1
= create_document_version(30, &IID_IXMLDOMDocument2
);
865 schema2
= create_document_version(30, &IID_IXMLDOMDocument2
);
866 schema3
= create_document_version(30, &IID_IXMLDOMDocument2
);
868 cache1
= create_cache_version(30, &IID_IXMLDOMSchemaCollection
);
869 cache2
= create_cache_version(40, &IID_IXMLDOMSchemaCollection
);
871 if (!schema1
|| !schema2
|| !schema3
|| !cache1
)
873 if (schema1
) IXMLDOMDocument2_Release(schema1
);
874 if (schema2
) IXMLDOMDocument2_Release(schema2
);
875 if (schema3
) IXMLDOMDocument2_Release(schema3
);
877 if (cache1
) IXMLDOMSchemaCollection_Release(cache1
);
882 ole_check(IXMLDOMDocument2_loadXML(schema1
, _bstr_(xdr_schema1_xml
), &b
));
883 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
885 ole_check(IXMLDOMDocument2_loadXML(schema2
, _bstr_(xdr_schema2_xml
), &b
));
886 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
888 ole_check(IXMLDOMDocument2_loadXML(schema3
, _bstr_(xdr_schema3_xml
), &b
));
889 ok(b
== VARIANT_TRUE
, "failed to load XML\n");
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
)));
896 ole_check(IXMLDOMSchemaCollection_get_length(cache1
, &length
));
897 ok(length
== 3, "expected length 3, got %i\n", length
);
899 IXMLDOMDocument2_Release(schema1
);
900 IXMLDOMDocument2_Release(schema2
);
901 IXMLDOMDocument2_Release(schema3
);
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");
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
)));
929 ole_check(IXMLDOMSchemaCollection_get_length(cache2
, &length
));
930 ok(length
== 5, "expected length 5, got %i\n", length
);
932 IXMLDOMDocument2_Release(schema1
);
933 IXMLDOMDocument2_Release(schema2
);
934 IXMLDOMDocument2_Release(schema3
);
935 IXMLDOMDocument2_Release(schema4
);
936 IXMLDOMDocument2_Release(schema5
);
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
);
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
);
959 for (i
= 0; i
< 3; ++i
)
962 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache1
, i
, &bstr
));
963 ok(bstr
!= NULL
&& *bstr
, "expected non-empty string\n");
966 for (j
= 0; j
< i
; ++j
)
967 ok(winetest_strcmpW(content
[j
], bstr
), "got duplicate entry\n");
970 for (i
= 0; i
< 3; ++i
)
972 SysFreeString(content
[i
]);
978 for (i
= 0; i
< 5; ++i
)
981 ole_check(IXMLDOMSchemaCollection_get_namespaceURI(cache2
, i
, &bstr
));
982 ok(bstr
!= NULL
&& *bstr
, "expected non-empty string\n");
984 for (j
= 0; j
< i
; ++j
)
985 ok(winetest_strcmpW(content
[j
], bstr
), "got duplicate entry\n");
989 for (i
= 0; i
< 5; ++i
)
991 SysFreeString(content
[i
]);
996 IXMLDOMSchemaCollection_Release(cache1
);
997 if (cache2
) IXMLDOMSchemaCollection_Release(cache2
);
1002 static void test_XDR_schemas(void)
1004 IXMLDOMDocument2
*doc
, *schema
;
1005 IXMLDOMSchemaCollection
* cache
;
1006 IXMLDOMParseError
* err
;
1011 doc
= create_document(&IID_IXMLDOMDocument2
);
1012 schema
= create_document(&IID_IXMLDOMDocument2
);
1013 cache
= create_cache(&IID_IXMLDOMSchemaCollection
);
1015 if (!doc
|| !schema
|| !cache
)
1017 if (doc
) IXMLDOMDocument2_Release(doc
);
1018 if (schema
) IXMLDOMDocument2_Release(schema
);
1019 if (cache
) IXMLDOMSchemaCollection_Release(cache
);
1026 ole_check(IXMLDOMDocument2_loadXML(doc
, _bstr_(szOpenSeqXML1
), &b
));
1027 ok(b
== VARIANT_TRUE
, "failed to load XML string\n");
1029 ole_check(IXMLDOMDocument2_loadXML(schema
, _bstr_(szOpenSeqXDR
), &b
));
1030 ok(b
== VARIANT_TRUE
, "failed to load XML string\n");
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
));
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
));
1049 * only declared elements in the declared order
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
);
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");
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
));
1075 * declared elements in the declared order, with an extra declared element at the end
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
);
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");
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
));
1101 * fails, extra elements are only allowed at the end */
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
);
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");
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
));
1125 * fails, undeclared elements are not allowed */
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
);
1134 IXMLDOMDocument2_Release(doc
);
1135 IXMLDOMDocument2_Release(schema
);
1136 IXMLDOMSchemaCollection_Release(cache
);
1143 enum VARENUM type_schema
;
1144 const char *typename
;
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" },
1180 static void test_XDR_datatypes(void)
1182 IXMLDOMDocument2
*doc
, *schema
, *doc2
;
1183 IXMLDOMSchemaCollection
* cache
;
1184 const xdr_datatypes
*ptr
;
1185 IXMLDOMParseError
* err
;
1194 doc
= create_document(&IID_IXMLDOMDocument2
);
1195 doc2
= create_document(&IID_IXMLDOMDocument2
);
1196 schema
= create_document(&IID_IXMLDOMDocument2
);
1197 cache
= create_cache(&IID_IXMLDOMSchemaCollection
);
1199 if (!doc
|| !doc2
|| !schema
|| !cache
)
1201 if (doc
) IXMLDOMDocument2_Release(doc
);
1202 if (doc2
) IXMLDOMDocument2_Release(doc2
);
1203 if (schema
) IXMLDOMDocument2_Release(schema
);
1204 if (cache
) IXMLDOMSchemaCollection_Release(cache
);
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");
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");
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");
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
);
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
);
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
);
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
);
1258 /* validate the doc */
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
);
1273 ptr
= xdr_datatypes_data
;
1276 IXMLDOMNode
* node
= NULL
;
1277 VARIANT type
, testv
;
1279 /* check data types without the schema */
1280 memset(&testv
, -1, sizeof(VARIANT
));
1281 V_VT(&testv
) = VT_NULL
;
1282 V_BSTR(&testv
) = NULL
;
1284 hr
= IXMLDOMDocument2_selectSingleNode(doc
, _bstr_(ptr
->query
), &node
);
1285 EXPECT_HR(hr
, S_OK
);
1286 ok(node
!= NULL
, "expected node\n");
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
));
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
);
1302 /* check the data with schema */
1304 hr
= IXMLDOMDocument2_selectSingleNode(doc2
, _bstr_(ptr
->query
), &node
);
1305 EXPECT_HR(hr
, S_OK
);
1306 ok(node
!= NULL
, "expected node\n");
1308 V_VT(&type
) = VT_EMPTY
;
1309 hr
= IXMLDOMNode_get_dataType(node
, &type
);
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
)));
1318 EXPECT_HR(hr
, S_FALSE
);
1319 ok(V_VT(&type
) == VT_NULL
, "%s: got type %i\n", ptr
->query
, V_VT(&type
));
1323 hr
= IXMLDOMNode_get_nodeTypedValue(node
, &v
);
1324 EXPECT_HR(hr
, S_OK
);
1328 ok(V_VT(&v
) == ptr
->type_schema
, "%s: got variant type %i\n", ptr
->query
, V_VT(&v
));
1330 ok(V_VT(&v
) == ptr
->type_schema
, "%s: got variant type %i\n", ptr
->query
, V_VT(&v
));
1332 switch (ptr
->type_schema
)
1335 ok(V_BOOL(&v
) == VARIANT_TRUE
, "got %x\n", V_BOOL(&v
));
1338 ok(V_I1(&v
) == 42, "got %i\n", V_I1(&v
));
1341 ok(V_I2(&v
) == 420, "got %i\n", V_I2(&v
));
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"))
1348 ok(V_I4(&v
) == 'u', "got %x\n", V_I4(&v
));
1350 ok(V_I4(&v
) == -420000000, "got %i\n", V_I4(&v
));
1353 expect_int64(V_I8(&v
), -4200000000, 10);
1356 ok(V_R4(&v
) == (float)3.14159265, "got %f\n", V_R4(&v
));
1359 if (!strcmp(ptr
->typename
, "float"))
1360 ok(V_R8(&v
) == (double)3.14159, "got %f\n", V_R8(&v
));
1363 ok(V_R8(&v
) == (double)3.14159265358979323846, "got %.20f\n", V_R8(&v
));
1366 ok(V_UI1(&v
) == 0xFF, "got %02x\n", V_UI1(&v
));
1369 ok(V_UI2(&v
) == 0xFFFF, "got %04x\n", V_UI2(&v
));
1372 ok(V_UI4(&v
) == 0xFFFFFFFF, "got %08x\n", V_UI4(&v
));
1375 expect_uint64(V_UI8(&v
), 0xFFFFFFFFFFFFFFFF, 16);
1383 IXMLDOMNode_Release(node
);
1388 IXMLDOMDocument2_Release(schema
);
1389 IXMLDOMDocument2_Release(doc
);
1390 IXMLDOMDocument2_Release(doc2
);
1391 IXMLDOMSchemaCollection_Release(cache
);
1396 static void test_validate_on_load(void)
1398 IXMLDOMSchemaCollection2
*cache
;
1402 cache
= create_cache_version(40, &IID_IXMLDOMSchemaCollection2
);
1405 hr
= IXMLDOMSchemaCollection2_get_validateOnLoad(cache
, NULL
);
1406 EXPECT_HR(hr
, E_POINTER
);
1409 hr
= IXMLDOMSchemaCollection2_get_validateOnLoad(cache
, &b
);
1410 EXPECT_HR(hr
, S_OK
);
1411 ok(b
== VARIANT_TRUE
, "got %d\n", b
);
1413 IXMLDOMSchemaCollection2_Release(cache
);
1416 static void test_obj_dispex(IUnknown
*obj
)
1418 static const WCHAR starW
[] = {'*',0};
1419 DISPID dispid
= DISPID_SAX_XMLREADER_GETFEATURE
;
1420 IDispatchEx
*dispex
;
1427 hr
= IUnknown_QueryInterface(obj
, &IID_IDispatchEx
, (void**)&dispex
);
1428 EXPECT_HR(hr
, S_OK
);
1429 if (FAILED(hr
)) return;
1432 hr
= IDispatchEx_GetTypeInfoCount(dispex
, &ticnt
);
1433 EXPECT_HR(hr
, S_OK
);
1434 ok(ticnt
== 1, "ticnt=%u\n", ticnt
);
1436 name
= SysAllocString(starW
);
1437 hr
= IDispatchEx_DeleteMemberByName(dispex
, name
, fdexNameCaseSensitive
);
1438 EXPECT_HR(hr
, E_NOTIMPL
);
1439 SysFreeString(name
);
1441 hr
= IDispatchEx_DeleteMemberByDispID(dispex
, dispid
);
1442 EXPECT_HR(hr
, E_NOTIMPL
);
1445 hr
= IDispatchEx_GetMemberProperties(dispex
, dispid
, grfdexPropCanAll
, &props
);
1446 EXPECT_HR(hr
, E_NOTIMPL
);
1447 ok(props
== 0, "expected 0 got %d\n", props
);
1449 hr
= IDispatchEx_GetMemberName(dispex
, dispid
, &name
);
1450 EXPECT_HR(hr
, E_NOTIMPL
);
1451 if (SUCCEEDED(hr
)) SysFreeString(name
);
1453 hr
= IDispatchEx_GetNextDispID(dispex
, fdexEnumDefault
, DISPID_XMLDOM_SCHEMACOLLECTION_ADD
, &dispid
);
1454 EXPECT_HR(hr
, E_NOTIMPL
);
1456 hr
= IDispatchEx_GetNameSpaceParent(dispex
, &unk
);
1457 EXPECT_HR(hr
, E_NOTIMPL
);
1458 if (hr
== S_OK
&& unk
) IUnknown_Release(unk
);
1460 IDispatchEx_Release(dispex
);
1463 static void test_dispex(void)
1465 IXMLDOMSchemaCollection
*cache
;
1466 IDispatchEx
*dispex
;
1469 DISPPARAMS dispparams
;
1472 cache
= create_cache(&IID_IXMLDOMSchemaCollection
);
1475 hr
= IXMLDOMSchemaCollection_QueryInterface(cache
, &IID_IUnknown
, (void**)&unk
);
1476 EXPECT_HR(hr
, S_OK
);
1477 test_obj_dispex(unk
);
1478 IUnknown_Release(unk
);
1480 hr
= IXMLDOMSchemaCollection_QueryInterface(cache
, &IID_IDispatchEx
, (void**)&dispex
);
1481 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1485 dispparams
.cArgs
= 1;
1486 dispparams
.cNamedArgs
= 0;
1487 dispparams
.rgdispidNamedArgs
= NULL
;
1488 dispparams
.rgvarg
= &arg
;
1490 V_VT(&ret
) = VT_EMPTY
;
1491 V_DISPATCH(&ret
) = (void*)0x1;
1492 hr
= IDispatchEx_Invoke(dispex
, DISPID_VALUE
, &IID_NULL
, 0, DISPATCH_METHOD
, &dispparams
, &ret
, NULL
, NULL
);
1493 ok(hr
== DISP_E_MEMBERNOTFOUND
, "got 0x%08x\n", hr
);
1494 ok(V_VT(&ret
) == VT_EMPTY
, "got %d\n", V_VT(&ret
));
1495 ok(V_DISPATCH(&ret
) == (void*)0x1, "got %p\n", V_DISPATCH(&ret
));
1497 IDispatchEx_Release(dispex
);
1499 IXMLDOMSchemaCollection_Release(cache
);
1502 static void test_get(void)
1504 IXMLDOMSchemaCollection2
*cache
;
1508 cache
= create_cache_version(60, &IID_IXMLDOMSchemaCollection2
);
1511 hr
= IXMLDOMSchemaCollection2_get(cache
, NULL
, NULL
);
1512 EXPECT_HR(hr
, E_NOTIMPL
);
1514 hr
= IXMLDOMSchemaCollection2_get(cache
, _bstr_("uri"), &node
);
1515 EXPECT_HR(hr
, E_NOTIMPL
);
1517 IXMLDOMSchemaCollection2_Release(cache
);
1519 cache
= create_cache_version(40, &IID_IXMLDOMSchemaCollection2
);
1522 hr
= IXMLDOMSchemaCollection2_get(cache
, NULL
, NULL
);
1523 EXPECT_HR(hr
, E_POINTER
);
1525 hr
= IXMLDOMSchemaCollection2_get(cache
, _bstr_("uri"), &node
);
1526 EXPECT_HR(hr
, S_OK
);
1528 IXMLDOMSchemaCollection2_Release(cache
);
1532 static void test_remove(void)
1534 IXMLDOMSchemaCollection2
*cache
;
1535 IXMLDOMDocument
*doc
;
1541 cache
= create_cache_version(60, &IID_IXMLDOMSchemaCollection2
);
1544 doc
= create_document_version(60, &IID_IXMLDOMDocument
);
1545 ok(doc
!= NULL
, "got %p\n", doc
);
1547 hr
= IXMLDOMDocument_loadXML(doc
, _bstr_(xsd_schema1_xml
), &b
);
1548 EXPECT_HR(hr
, S_OK
);
1550 V_VT(&v
) = VT_DISPATCH
;
1551 V_DISPATCH(&v
) = (IDispatch
*)doc
;
1552 hr
= IXMLDOMSchemaCollection2_add(cache
, _bstr_(xsd_schema1_uri
), v
);
1553 EXPECT_HR(hr
, S_OK
);
1556 hr
= IXMLDOMSchemaCollection2_get_length(cache
, &len
);
1557 EXPECT_HR(hr
, S_OK
);
1558 ok(len
== 1, "got %d\n", len
);
1560 /* ::remove() is a stub for version 6 */
1561 hr
= IXMLDOMSchemaCollection2_remove(cache
, NULL
);
1562 EXPECT_HR(hr
, E_NOTIMPL
);
1564 hr
= IXMLDOMSchemaCollection2_remove(cache
, _bstr_("invaliduri"));
1565 EXPECT_HR(hr
, E_NOTIMPL
);
1567 hr
= IXMLDOMSchemaCollection2_remove(cache
, _bstr_(xsd_schema1_uri
));
1568 EXPECT_HR(hr
, E_NOTIMPL
);
1571 hr
= IXMLDOMSchemaCollection2_get_length(cache
, &len
);
1572 EXPECT_HR(hr
, S_OK
);
1573 ok(len
== 1, "got %d\n", len
);
1575 IXMLDOMDocument_Release(doc
);
1576 IXMLDOMSchemaCollection2_Release(cache
);
1579 /* ::remove() works for version 4 */
1580 cache
= create_cache_version(40, &IID_IXMLDOMSchemaCollection2
);
1583 doc
= create_document_version(40, &IID_IXMLDOMDocument
);
1584 ok(doc
!= NULL
, "got %p\n", doc
);
1586 hr
= IXMLDOMDocument_loadXML(doc
, _bstr_(xsd_schema1_xml
), &b
);
1587 EXPECT_HR(hr
, S_OK
);
1589 V_VT(&v
) = VT_DISPATCH
;
1590 V_DISPATCH(&v
) = (IDispatch
*)doc
;
1591 hr
= IXMLDOMSchemaCollection2_add(cache
, _bstr_(xsd_schema1_uri
), v
);
1592 EXPECT_HR(hr
, S_OK
);
1595 hr
= IXMLDOMSchemaCollection2_get_length(cache
, &len
);
1596 EXPECT_HR(hr
, S_OK
);
1597 ok(len
== 1, "got %d\n", len
);
1599 hr
= IXMLDOMSchemaCollection2_remove(cache
, NULL
);
1600 EXPECT_HR(hr
, S_OK
);
1602 hr
= IXMLDOMSchemaCollection2_remove(cache
, _bstr_("invaliduri"));
1603 EXPECT_HR(hr
, S_OK
);
1606 hr
= IXMLDOMSchemaCollection2_get_length(cache
, &len
);
1607 EXPECT_HR(hr
, S_OK
);
1608 ok(len
== 1, "got %d\n", len
);
1610 hr
= IXMLDOMSchemaCollection2_remove(cache
, _bstr_(xsd_schema1_uri
));
1611 EXPECT_HR(hr
, S_OK
);
1614 hr
= IXMLDOMSchemaCollection2_get_length(cache
, &len
);
1615 EXPECT_HR(hr
, S_OK
);
1616 ok(len
== 0, "got %d\n", len
);
1618 IXMLDOMDocument_Release(doc
);
1619 IXMLDOMSchemaCollection2_Release(cache
);
1628 r
= CoInitialize( NULL
);
1629 ok( r
== S_OK
, "failed to init com\n");
1632 test_collection_refs();
1634 test_collection_content();
1636 test_XDR_datatypes();
1637 test_validate_on_load();