2 * XMLLite IXmlReader tests
4 * Copyright 2010 (C) Nikolay Sivov
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 DEFINE_GUID(IID_IXmlReaderInput, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda);
35 HRESULT WINAPI (*pCreateXmlReader)(REFIID riid, void **ppvObject, IMalloc *pMalloc);
36 HRESULT WINAPI (*pCreateXmlReaderInputWithEncodingName)(IUnknown *stream,
41 IXmlReaderInput **ppInput);
42 static const char *debugstr_guid(REFIID riid)
46 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
47 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
48 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
49 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
54 typedef struct input_iids_t {
59 static const IID *setinput_full[] = {
61 &IID_ISequentialStream,
65 static input_iids_t input_iids;
67 static void ok_iids_(const input_iids_t *iids, const IID **expected, int size, int todo, int line)
73 ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
76 ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
78 if (iids->count != size) return;
80 for (i = 0; i < size; i++) {
81 ok_(__FILE__, line)(IsEqualGUID(&iids->iids[i], expected[i]),
82 "Wrong IID(%d), got (%s)\n", i, debugstr_guid(&iids->iids[i]));
85 #define ok_iids(got, exp, size, todo) ok_iids_(got, exp, size, todo, __LINE__)
87 typedef struct _testinput
89 const IUnknownVtbl *lpVtbl;
93 static inline testinput *impl_from_IUnknown(IUnknown *iface)
95 return (testinput *)((char*)iface - FIELD_OFFSET(testinput, lpVtbl));
98 static HRESULT WINAPI testinput_QueryInterface(IUnknown *iface, REFIID riid, void** ppvObj)
100 if (IsEqualGUID( riid, &IID_IUnknown ))
103 IUnknown_AddRef(iface);
107 input_iids.iids[input_iids.count++] = *riid;
111 return E_NOINTERFACE;
114 static ULONG WINAPI testinput_AddRef(IUnknown *iface)
116 testinput *This = impl_from_IUnknown(iface);
117 return InterlockedIncrement(&This->ref);
120 static ULONG WINAPI testinput_Release(IUnknown *iface)
122 testinput *This = impl_from_IUnknown(iface);
125 ref = InterlockedDecrement(&This->ref);
128 HeapFree(GetProcessHeap(), 0, This);
134 static const struct IUnknownVtbl testinput_vtbl =
136 testinput_QueryInterface,
141 static HRESULT testinput_createinstance(void **ppObj)
145 input = HeapAlloc(GetProcessHeap(), 0, sizeof (*input));
146 if(!input) return E_OUTOFMEMORY;
148 input->lpVtbl = &testinput_vtbl;
151 *ppObj = &input->lpVtbl;
156 static BOOL init_pointers(void)
158 /* don't free module here, it's to be unloaded on exit */
159 HMODULE mod = LoadLibraryA("xmllite.dll");
163 win_skip("xmllite library not available\n");
167 #define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
168 MAKEFUNC(CreateXmlReader);
169 MAKEFUNC(CreateXmlReaderInputWithEncodingName);
175 static void test_reader_create(void)
185 hr = pCreateXmlReader(&IID_IXmlReader, NULL, NULL);
186 hr = pCreateXmlReader(NULL, (LPVOID*)&reader, NULL);
189 hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
190 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
192 hr = CoGetMalloc(1, &imalloc);
193 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
195 hr = IMalloc_DidAlloc(imalloc, reader);
196 ok(hr != 1, "Expected 0 or -1, got %08x\n", hr);
198 /* test input interface selection sequence */
199 hr = testinput_createinstance((void**)&input);
200 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
202 input_iids.count = 0;
203 hr = IXmlReader_SetInput(reader, input);
204 todo_wine ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
205 ok_iids(&input_iids, setinput_full, sizeof(setinput_full)/sizeof(REFIID), TRUE);
207 IUnknown_Release(input);
209 IXmlReader_Release(reader);
212 static void test_readerinput(void)
214 IXmlReaderInput *reader_input;
220 hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, NULL);
221 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
222 hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, &reader_input);
223 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
225 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
226 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
228 ref = IStream_AddRef(stream);
229 ok(ref == 2, "Expected 2, got %d\n", ref);
230 IStream_Release(stream);
231 hr = pCreateXmlReaderInputWithEncodingName((IUnknown*)stream, NULL, NULL, FALSE, NULL, &reader_input);
232 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
234 /* IXmlReader grabs a stream reference */
235 ref = IStream_AddRef(stream);
236 todo_wine ok(ref == 3, "Expected 3, got %d\n", ref);
237 IStream_Release(stream);
239 /* IID_IXmlReaderInput */
240 /* it returns a kind of private undocumented vtable incompatible with IUnknown,
241 so it's not a COM interface actually.
242 Such query will be used only to check if input is really IXmlReaderInput */
243 obj = (IUnknown*)0xdeadbeef;
244 hr = IUnknown_QueryInterface(reader_input, &IID_IXmlReaderInput, (void**)&obj);
245 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
246 ref = IUnknown_AddRef(reader_input);
247 ok(ref == 3, "Expected 3, got %d\n", ref);
248 IUnknown_Release(reader_input);
250 IUnknown_Release(reader_input);
251 IStream_Release(stream);
258 r = CoInitialize( NULL );
259 ok( r == S_OK, "failed to init com\n");
261 if (!init_pointers())
267 test_reader_create();