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
30 #include "wine/test.h"
32 static const WCHAR schema_uri
[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
34 static const WCHAR schema_xml
[] = {
35 '<','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',
36 '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',
37 '<','/','S','c','h','e','m','a','>','\n',0
40 static void test_schema_refs(void)
42 IXMLDOMDocument2
*doc
;
43 IXMLDOMSchemaCollection
*schema
;
50 r
= CoCreateInstance( &CLSID_DOMDocument
, NULL
,
51 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMDocument2
, (LPVOID
*)&doc
);
55 r
= CoCreateInstance( &CLSID_XMLSchemaCache
, NULL
,
56 CLSCTX_INPROC_SERVER
, &IID_IXMLDOMSchemaCollection
, (LPVOID
*)&schema
);
59 IXMLDOMDocument2_Release(doc
);
63 str
= SysAllocString(schema_xml
);
64 r
= IXMLDOMDocument2_loadXML(doc
, str
, &b
);
65 ok(r
== S_OK
, "ret %08x\n", r
);
66 ok(b
== VARIANT_TRUE
, "b %04x\n", b
);
69 ref
= IXMLDOMDocument2_AddRef(doc
);
70 ok(ref
== 2, "ref %d\n", ref
);
72 V_VT(&v
) = VT_DISPATCH
;
73 V_DISPATCH(&v
) = (IDispatch
*)doc
;
75 str
= SysAllocString(schema_uri
);
76 r
= IXMLDOMSchemaCollection_add(schema
, str
, v
);
77 ok(r
== S_OK
, "ret %08x\n", r
);
79 /* IXMLDOMSchemaCollection_add doesn't add a ref on doc */
80 ref
= IXMLDOMDocument2_AddRef(doc
);
81 ok(ref
== 3, "ref %d\n", ref
);
82 IXMLDOMDocument2_Release(doc
);
88 r
= IXMLDOMDocument2_get_schemas(doc
, &v
);
89 ok(r
== S_FALSE
, "ret %08x\n", r
);
90 ok(V_VT(&v
) == VT_NULL
, "vt %x\n", V_VT(&v
));
92 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
93 ok(ref
== 2, "ref %d\n", ref
);
94 V_VT(&v
) = VT_DISPATCH
;
95 V_DISPATCH(&v
) = (IDispatch
*)schema
;
97 /* check that putref_schemas takes a ref */
98 r
= IXMLDOMDocument2_putref_schemas(doc
, v
);
99 ok(r
== S_OK
, "ret %08x\n", r
);
100 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
101 ok(ref
== 4, "ref %d\n", ref
);
102 IXMLDOMSchemaCollection_Release(schema
);
107 /* check that get_schemas adds a ref */
108 r
= IXMLDOMDocument2_get_schemas(doc
, &v
);
109 ok(r
== S_OK
, "ret %08x\n", r
);
110 ok(V_VT(&v
) == VT_DISPATCH
, "vt %x\n", V_VT(&v
));
111 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
112 ok(ref
== 4, "ref %d\n", ref
);
113 IXMLDOMSchemaCollection_Release(schema
);
116 /* get_schemas doesn't release a ref if passed VT_DISPATCH - ie it doesn't call VariantClear() */
117 r
= IXMLDOMDocument2_get_schemas(doc
, &v
);
118 ok(r
== S_OK
, "ret %08x\n", r
);
119 ok(V_VT(&v
) == VT_DISPATCH
, "vt %x\n", V_VT(&v
));
120 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
121 ok(ref
== 5, "ref %d\n", ref
);
122 IXMLDOMSchemaCollection_Release(schema
);
125 /* release the two refs returned by get_schemas */
126 IXMLDOMSchemaCollection_Release(schema
);
127 IXMLDOMSchemaCollection_Release(schema
);
131 /* check that taking another ref on the document doesn't change the schema's ref count */
132 IXMLDOMDocument2_AddRef(doc
);
133 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
134 ok(ref
== 3, "ref %d\n", ref
);
135 IXMLDOMSchemaCollection_Release(schema
);
136 IXMLDOMDocument2_Release(doc
);
140 /* call putref_schema with some odd variants */
142 r
= IXMLDOMDocument2_putref_schemas(doc
, v
);
143 ok(r
== E_FAIL
, "ret %08x\n", r
);
144 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
145 ok(ref
== 3, "ref %d\n", ref
);
146 IXMLDOMSchemaCollection_Release(schema
);
149 /* calling with VT_EMPTY releases the schema */
151 r
= IXMLDOMDocument2_putref_schemas(doc
, v
);
152 ok(r
== S_OK
, "ret %08x\n", r
);
153 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
154 ok(ref
== 2, "ref %d\n", ref
);
155 IXMLDOMSchemaCollection_Release(schema
);
158 /* try setting with VT_UNKNOWN */
159 IXMLDOMSchemaCollection_AddRef(schema
);
160 V_VT(&v
) = VT_UNKNOWN
;
161 V_UNKNOWN(&v
) = (IUnknown
*)schema
;
162 r
= IXMLDOMDocument2_putref_schemas(doc
, v
);
163 ok(r
== S_OK
, "ret %08x\n", r
);
164 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
165 ok(ref
== 4, "ref %d\n", ref
);
166 IXMLDOMSchemaCollection_Release(schema
);
170 /* calling with VT_NULL releases the schema */
172 r
= IXMLDOMDocument2_putref_schemas(doc
, v
);
173 ok(r
== S_OK
, "ret %08x\n", r
);
174 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
175 ok(ref
== 2, "ref %d\n", ref
);
176 IXMLDOMSchemaCollection_Release(schema
);
180 IXMLDOMSchemaCollection_AddRef(schema
);
181 V_VT(&v
) = VT_UNKNOWN
;
182 V_UNKNOWN(&v
) = (IUnknown
*)schema
;
183 r
= IXMLDOMDocument2_putref_schemas(doc
, v
);
184 ok(r
== S_OK
, "ret %08x\n", r
);
185 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
186 ok(ref
== 4, "ref %d\n", ref
);
187 IXMLDOMSchemaCollection_Release(schema
);
192 /* release the final ref on the doc which should release its ref on the schema */
193 IXMLDOMDocument2_Release(doc
);
195 ref
= IXMLDOMSchemaCollection_AddRef(schema
);
196 ok(ref
== 2, "ref %d\n", ref
);
197 IXMLDOMSchemaCollection_Release(schema
);
198 IXMLDOMSchemaCollection_Release(schema
);
205 r
= CoInitialize( NULL
);
206 ok( r
== S_OK
, "failed to init com\n");