- Merge the remaining portion of the wlan-bringup branch
[reactos.git] / rostests / winetests / msxml3 / schema.c
1 /*
2 * Schema test
3 *
4 * Copyright 2007 Huw Davies
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdio.h>
22 #define COBJMACROS
23
24 #include "initguid.h"
25 #include "windows.h"
26 #include "ole2.h"
27 #include "xmldom.h"
28 #include "msxml2.h"
29 #include "dispex.h"
30
31 #include "wine/test.h"
32
33 static const WCHAR schema_uri[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
34
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
39 };
40
41 static void test_schema_refs(void)
42 {
43 IXMLDOMDocument2 *doc;
44 IXMLDOMSchemaCollection *schema;
45 HRESULT r;
46 LONG ref;
47 VARIANT v;
48 VARIANT_BOOL b;
49 BSTR str;
50
51 r = CoCreateInstance( &CLSID_DOMDocument, NULL,
52 CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
53 if( r != S_OK )
54 return;
55
56 r = CoCreateInstance( &CLSID_XMLSchemaCache, NULL,
57 CLSCTX_INPROC_SERVER, &IID_IXMLDOMSchemaCollection, (LPVOID*)&schema );
58 if( r != S_OK )
59 {
60 IXMLDOMDocument2_Release(doc);
61 return;
62 }
63
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);
68 SysFreeString(str);
69
70 ref = IXMLDOMDocument2_AddRef(doc);
71 ok(ref == 2, "ref %d\n", ref);
72 VariantInit(&v);
73 V_VT(&v) = VT_DISPATCH;
74 V_DISPATCH(&v) = (IDispatch*)doc;
75
76 str = SysAllocString(schema_uri);
77 r = IXMLDOMSchemaCollection_add(schema, str, v);
78 ok(r == S_OK, "ret %08x\n", r);
79
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);
84
85 SysFreeString(str);
86 VariantClear(&v);
87
88 V_VT(&v) = VT_INT;
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));
92
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;
97
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);
104 VariantClear(&v);
105
106 /* refs now 2 */
107 V_VT(&v) = VT_INT;
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);
115
116 /* refs now 3 */
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);
124
125 /* refs now 4 */
126 /* release the two refs returned by get_schemas */
127 IXMLDOMSchemaCollection_Release(schema);
128 IXMLDOMSchemaCollection_Release(schema);
129
130 /* refs now 2 */
131
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);
138
139
140 /* refs now 2 */
141 /* call putref_schema with some odd variants */
142 V_VT(&v) = VT_INT;
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);
148
149 /* refs now 2 */
150 /* calling with VT_EMPTY releases the schema */
151 V_VT(&v) = VT_EMPTY;
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);
157
158 /* refs now 1 */
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);
168 VariantClear(&v);
169
170 /* refs now 2 */
171 /* calling with VT_NULL releases the schema */
172 V_VT(&v) = VT_NULL;
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);
178
179 /* refs now 1 */
180 /* set again */
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);
189 VariantClear(&v);
190
191 /* refs now 2 */
192
193 /* release the final ref on the doc which should release its ref on the schema */
194 IXMLDOMDocument2_Release(doc);
195
196 ref = IXMLDOMSchemaCollection_AddRef(schema);
197 ok(ref == 2, "ref %d\n", ref);
198 IXMLDOMSchemaCollection_Release(schema);
199 IXMLDOMSchemaCollection_Release(schema);
200 }
201
202 START_TEST(schema)
203 {
204 HRESULT r;
205
206 r = CoInitialize( NULL );
207 ok( r == S_OK, "failed to init com\n");
208
209 test_schema_refs();
210
211 CoUninitialize();
212 }