msi: Set all folders' source paths to the root directory if the source type is compre...
[wine] / dlls / msxml3 / tests / 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
30 #include "wine/test.h"
31
32 static const WCHAR schema_uri[] = {'x','-','s','c','h','e','m','a',':','t','e','s','t','.','x','m','l',0};
33
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
38 };
39
40 static void test_schema_refs(void)
41 {
42     IXMLDOMDocument2 *doc;
43     IXMLDOMSchemaCollection *schema;
44     HRESULT r;
45     LONG ref;
46     VARIANT v;
47     VARIANT_BOOL b;
48     BSTR str;
49
50     r = CoCreateInstance( &CLSID_DOMDocument, NULL,
51         CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
52     if( r != S_OK )
53         return;
54
55     r = CoCreateInstance( &CLSID_XMLSchemaCache, NULL,
56         CLSCTX_INPROC_SERVER, &IID_IXMLDOMSchemaCollection, (LPVOID*)&schema );
57     if( r != S_OK )
58     {
59         IXMLDOMDocument2_Release(doc);
60         return;
61     }
62
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);
67     SysFreeString(str);
68
69     ref = IXMLDOMDocument2_AddRef(doc);
70     ok(ref == 2, "ref %d\n", ref);
71     VariantInit(&v);
72     V_VT(&v) = VT_DISPATCH;
73     V_DISPATCH(&v) = (IDispatch*)doc;
74
75     str = SysAllocString(schema_uri);
76     r = IXMLDOMSchemaCollection_add(schema, str, v);
77     ok(r == S_OK, "ret %08x\n", r);
78
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);
83
84     SysFreeString(str);
85     VariantClear(&v);
86
87     V_VT(&v) = VT_INT;
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));
91
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;
96
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);
103     VariantClear(&v);
104
105     /* refs now 2 */
106     V_VT(&v) = VT_INT;
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);
114
115     /* refs now 3 */
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);
123
124     /* refs now 4 */
125     /* release the two refs returned by get_schemas */
126     IXMLDOMSchemaCollection_Release(schema);
127     IXMLDOMSchemaCollection_Release(schema);
128
129     /* refs now 2 */
130
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);
137
138
139     /* refs now 2 */
140     /* call putref_schema with some odd variants */
141     V_VT(&v) = VT_INT;
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);
147
148     /* refs now 2 */
149     /* calling with VT_EMPTY releases the schema */
150     V_VT(&v) = VT_EMPTY;
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);
156
157     /* refs now 1 */
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);
167     VariantClear(&v);
168
169     /* refs now 2 */
170     /* calling with VT_NULL releases the schema */
171     V_VT(&v) = VT_NULL;
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);
177
178     /* refs now 1 */
179     /* set again */
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);
188     VariantClear(&v);
189
190     /* refs now 2 */
191
192     /* release the final ref on the doc which should release its ref on the schema */
193     IXMLDOMDocument2_Release(doc);
194
195     ref = IXMLDOMSchemaCollection_AddRef(schema);
196     ok(ref == 2, "ref %d\n", ref);
197     IXMLDOMSchemaCollection_Release(schema);
198     IXMLDOMSchemaCollection_Release(schema);
199 }
200
201 START_TEST(schema)
202 {
203     HRESULT r;
204
205     r = CoInitialize( NULL );
206     ok( r == S_OK, "failed to init com\n");
207
208     test_schema_refs();
209
210     CoUninitialize();
211 }