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
31 #include "wine/test.h"
33 static const WCHAR schema_uri[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
35 static const WCHAR schema_xml[] = {
36 '<','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',
37 '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',
38 '<','/','S','c','h','e','m','a','>','\n',0
41 static void test_schema_refs(void)
43 IXMLDOMDocument2 *doc;
44 IXMLDOMSchemaCollection *schema;
51 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
52 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
56 r = CoCreateInstance( &CLSID_XMLSchemaCache, NULL,
57 CLSCTX_INPROC_SERVER, &IID_IXMLDOMSchemaCollection, (LPVOID*)&schema );
60 IXMLDOMDocument2_Release(doc);
64 str = SysAllocString(schema_xml);
65 r = IXMLDOMDocument2_loadXML(doc, str, &b);
66 ok(r == S_OK, "ret %08x\n", r);
67 ok(b == VARIANT_TRUE, "b %04x\n", b);
70 ref = IXMLDOMDocument2_AddRef(doc);
71 ok(ref == 2, "ref %d\n", ref);
73 V_VT(&v) = VT_DISPATCH;
74 V_DISPATCH(&v) = (IDispatch*)doc;
76 str = SysAllocString(schema_uri);
77 r = IXMLDOMSchemaCollection_add(schema, str, v);
78 ok(r == S_OK, "ret %08x\n", r);
80 /* IXMLDOMSchemaCollection_add doesn't add a ref on doc */
81 ref = IXMLDOMDocument2_AddRef(doc);
82 ok(ref == 3, "ref %d\n", ref);
83 IXMLDOMDocument2_Release(doc);
89 r = IXMLDOMDocument2_get_schemas(doc, &v);
90 ok(r == S_FALSE, "ret %08x\n", r);
91 ok(V_VT(&v) == VT_NULL, "vt %x\n", V_VT(&v));
93 ref = IXMLDOMSchemaCollection_AddRef(schema);
94 ok(ref == 2, "ref %d\n", ref);
95 V_VT(&v) = VT_DISPATCH;
96 V_DISPATCH(&v) = (IDispatch*)schema;
98 /* check that putref_schemas takes a ref */
99 r = IXMLDOMDocument2_putref_schemas(doc, v);
100 ok(r == S_OK, "ret %08x\n", r);
101 ref = IXMLDOMSchemaCollection_AddRef(schema);
102 ok(ref == 4, "ref %d\n", ref);
103 IXMLDOMSchemaCollection_Release(schema);
108 /* check that get_schemas adds a ref */
109 r = IXMLDOMDocument2_get_schemas(doc, &v);
110 ok(r == S_OK, "ret %08x\n", r);
111 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
112 ref = IXMLDOMSchemaCollection_AddRef(schema);
113 ok(ref == 4, "ref %d\n", ref);
114 IXMLDOMSchemaCollection_Release(schema);
117 /* get_schemas doesn't release a ref if passed VT_DISPATCH - ie it doesn't call VariantClear() */
118 r = IXMLDOMDocument2_get_schemas(doc, &v);
119 ok(r == S_OK, "ret %08x\n", r);
120 ok(V_VT(&v) == VT_DISPATCH, "vt %x\n", V_VT(&v));
121 ref = IXMLDOMSchemaCollection_AddRef(schema);
122 ok(ref == 5, "ref %d\n", ref);
123 IXMLDOMSchemaCollection_Release(schema);
126 /* release the two refs returned by get_schemas */
127 IXMLDOMSchemaCollection_Release(schema);
128 IXMLDOMSchemaCollection_Release(schema);
132 /* check that taking another ref on the document doesn't change the schema's ref count */
133 IXMLDOMDocument2_AddRef(doc);
134 ref = IXMLDOMSchemaCollection_AddRef(schema);
135 ok(ref == 3, "ref %d\n", ref);
136 IXMLDOMSchemaCollection_Release(schema);
137 IXMLDOMDocument2_Release(doc);
141 /* call putref_schema with some odd variants */
143 r = IXMLDOMDocument2_putref_schemas(doc, v);
144 ok(r == E_FAIL, "ret %08x\n", r);
145 ref = IXMLDOMSchemaCollection_AddRef(schema);
146 ok(ref == 3, "ref %d\n", ref);
147 IXMLDOMSchemaCollection_Release(schema);
150 /* calling with VT_EMPTY releases the schema */
152 r = IXMLDOMDocument2_putref_schemas(doc, v);
153 ok(r == S_OK, "ret %08x\n", r);
154 ref = IXMLDOMSchemaCollection_AddRef(schema);
155 ok(ref == 2, "ref %d\n", ref);
156 IXMLDOMSchemaCollection_Release(schema);
159 /* try setting with VT_UNKNOWN */
160 IXMLDOMSchemaCollection_AddRef(schema);
161 V_VT(&v) = VT_UNKNOWN;
162 V_UNKNOWN(&v) = (IUnknown*)schema;
163 r = IXMLDOMDocument2_putref_schemas(doc, v);
164 ok(r == S_OK, "ret %08x\n", r);
165 ref = IXMLDOMSchemaCollection_AddRef(schema);
166 ok(ref == 4, "ref %d\n", ref);
167 IXMLDOMSchemaCollection_Release(schema);
171 /* calling with VT_NULL releases the schema */
173 r = IXMLDOMDocument2_putref_schemas(doc, v);
174 ok(r == S_OK, "ret %08x\n", r);
175 ref = IXMLDOMSchemaCollection_AddRef(schema);
176 ok(ref == 2, "ref %d\n", ref);
177 IXMLDOMSchemaCollection_Release(schema);
181 IXMLDOMSchemaCollection_AddRef(schema);
182 V_VT(&v) = VT_UNKNOWN;
183 V_UNKNOWN(&v) = (IUnknown*)schema;
184 r = IXMLDOMDocument2_putref_schemas(doc, v);
185 ok(r == S_OK, "ret %08x\n", r);
186 ref = IXMLDOMSchemaCollection_AddRef(schema);
187 ok(ref == 4, "ref %d\n", ref);
188 IXMLDOMSchemaCollection_Release(schema);
193 /* release the final ref on the doc which should release its ref on the schema */
194 IXMLDOMDocument2_Release(doc);
196 ref = IXMLDOMSchemaCollection_AddRef(schema);
197 ok(ref == 2, "ref %d\n", ref);
198 IXMLDOMSchemaCollection_Release(schema);
199 IXMLDOMSchemaCollection_Release(schema);
206 r = CoInitialize( NULL );
207 ok( r == S_OK, "failed to init com\n");