4 * Copyright 2007 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
31 const CLSID CLSID_XMLSchemaCache = {0x373984c9, 0xb845, 0x449b, {0x91, 0xe7, 0x45, 0xac, 0x83, 0x03, 0x6a, 0xde}};
32 const IID IID_IXMLDOMSchemaCollection = {0x373984c8, 0xb845, 0x449b, {0x91, 0xe7, 0x45, 0xac, 0x83, 0x03, 0x6a, 0xde}};
34 static const WCHAR schema_uri[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
36 static const WCHAR schema_xml[] = {
37 '<','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',
38 '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',
39 '<','/','S','c','h','e','m','a','>','\n',0
42 static void test_schema_refs(void)
44 IXMLDOMDocument2 *doc;
45 IXMLDOMSchemaCollection *schema;
52 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
53 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
57 r = CoCreateInstance( &CLSID_XMLSchemaCache, NULL,
58 CLSCTX_INPROC_SERVER, &IID_IXMLDOMSchemaCollection, (LPVOID*)&schema );
61 IXMLDOMDocument2_Release(doc);
65 str = SysAllocString(schema_xml);
66 r = IXMLDOMDocument2_loadXML(doc, str, &b);
67 ok(r == S_OK, "ret %08x\n", r);
68 ok(b == VARIANT_TRUE, "b %04x\n", b);
71 ref = IXMLDOMDocument2_AddRef(doc);
72 ok(ref == 2, "ref %d\n", ref);
74 V_VT(&v) = VT_DISPATCH;
75 V_DISPATCH(&v) = (IDispatch*)doc;
77 str = SysAllocString(schema_uri);
78 r = IXMLDOMSchemaCollection_add(schema, str, v);
79 ok(r == S_OK, "ret %08x\n", r);
81 /* IXMLDOMSchemaCollection_add doesn't add a ref on doc */
82 ref = IXMLDOMDocument2_AddRef(doc);
83 ok(ref == 3, "ref %d\n", ref);
84 IXMLDOMDocument2_Release(doc);
90 r = IXMLDOMDocument2_get_schemas(doc, &v);
91 ok(r == S_FALSE, "ret %08x\n", r);
92 ok(V_VT(&v) == VT_NULL, "vt %x\n", V_VT(&v));
94 ref = IXMLDOMSchemaCollection_AddRef(schema);
95 ok(ref == 2, "ref %d\n", ref);
96 V_VT(&v) = VT_DISPATCH;
97 V_DISPATCH(&v) = (IDispatch*)schema;
99 /* check that putref_schemas takes a ref */
100 r = IXMLDOMDocument2_putref_schemas(doc, v);
101 ok(r == S_OK, "ret %08x\n", r);
102 ref = IXMLDOMSchemaCollection_AddRef(schema);
103 ok(ref == 4, "ref %d\n", ref);
104 IXMLDOMSchemaCollection_Release(schema);
109 /* check that get_schemas adds a ref */
110 r = IXMLDOMDocument2_get_schemas(doc, &v);
111 ok(r == S_OK, "ret %08x\n", r);
112 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
113 ref = IXMLDOMSchemaCollection_AddRef(schema);
114 ok(ref == 4, "ref %d\n", ref);
115 IXMLDOMSchemaCollection_Release(schema);
118 /* get_schemas doesn't release a ref if passed VT_DISPATCH - ie it doesn't call VariantClear() */
119 r = IXMLDOMDocument2_get_schemas(doc, &v);
120 ok(r == S_OK, "ret %08x\n", r);
121 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
122 ref = IXMLDOMSchemaCollection_AddRef(schema);
123 ok(ref == 5, "ref %d\n", ref);
124 IXMLDOMSchemaCollection_Release(schema);
127 /* release the two refs returned by get_schemas */
128 IXMLDOMSchemaCollection_Release(schema);
129 IXMLDOMSchemaCollection_Release(schema);
133 /* check that taking another ref on the document doesn't change the schema's ref count */
134 IXMLDOMDocument2_AddRef(doc);
135 ref = IXMLDOMSchemaCollection_AddRef(schema);
136 ok(ref == 3, "ref %d\n", ref);
137 IXMLDOMSchemaCollection_Release(schema);
138 IXMLDOMDocument2_Release(doc);
142 /* call putref_schema with some odd variants */
144 r = IXMLDOMDocument2_putref_schemas(doc, v);
145 ok(r == E_FAIL, "ret %08x\n", r);
146 ref = IXMLDOMSchemaCollection_AddRef(schema);
147 ok(ref == 3, "ref %d\n", ref);
148 IXMLDOMSchemaCollection_Release(schema);
151 /* calling with VT_EMPTY releases the schema */
153 r = IXMLDOMDocument2_putref_schemas(doc, v);
154 ok(r == S_OK, "ret %08x\n", r);
155 ref = IXMLDOMSchemaCollection_AddRef(schema);
156 ok(ref == 2, "ref %d\n", ref);
157 IXMLDOMSchemaCollection_Release(schema);
160 /* try setting with VT_UNKNOWN */
161 IXMLDOMSchemaCollection_AddRef(schema);
162 V_VT(&v) = VT_UNKNOWN;
163 V_UNKNOWN(&v) = (IUnknown*)schema;
164 r = IXMLDOMDocument2_putref_schemas(doc, v);
165 ok(r == S_OK, "ret %08x\n", r);
166 ref = IXMLDOMSchemaCollection_AddRef(schema);
167 ok(ref == 4, "ref %d\n", ref);
168 IXMLDOMSchemaCollection_Release(schema);
172 /* calling with VT_NULL releases the schema */
174 r = IXMLDOMDocument2_putref_schemas(doc, v);
175 ok(r == S_OK, "ret %08x\n", r);
176 ref = IXMLDOMSchemaCollection_AddRef(schema);
177 ok(ref == 2, "ref %d\n", ref);
178 IXMLDOMSchemaCollection_Release(schema);
182 IXMLDOMSchemaCollection_AddRef(schema);
183 V_VT(&v) = VT_UNKNOWN;
184 V_UNKNOWN(&v) = (IUnknown*)schema;
185 r = IXMLDOMDocument2_putref_schemas(doc, v);
186 ok(r == S_OK, "ret %08x\n", r);
187 ref = IXMLDOMSchemaCollection_AddRef(schema);
188 ok(ref == 4, "ref %d\n", ref);
189 IXMLDOMSchemaCollection_Release(schema);
194 /* release the final ref on the doc which should release its ref on the schema */
195 IXMLDOMDocument2_Release(doc);
197 ref = IXMLDOMSchemaCollection_AddRef(schema);
198 ok(ref == 2, "ref %d\n", ref);
199 IXMLDOMSchemaCollection_Release(schema);
200 IXMLDOMSchemaCollection_Release(schema);
207 r = CoInitialize( NULL );
208 ok( r == S_OK, "failed to init com\n");