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)
184 hr
= pCreateXmlReader(&IID_IXmlReader
, NULL
, NULL
);
185 hr
= pCreateXmlReader(NULL
, (LPVOID
*)&reader
, NULL
);
188 hr
= pCreateXmlReader(&IID_IXmlReader
, (LPVOID
*)&reader
, NULL
);
189 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
191 /* Null input pointer, releases previous input */
192 hr
= IXmlReader_SetInput(reader
, NULL
);
193 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
195 /* test input interface selection sequence */
196 hr
= testinput_createinstance((void**)&input
);
197 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
199 input_iids
.count
= 0;
200 hr
= IXmlReader_SetInput(reader
, input
);
201 ok(hr
== E_NOINTERFACE
, "Expected E_NOINTERFACE, got %08x\n", hr
);
202 ok_iids(&input_iids
, setinput_full
, sizeof(setinput_full
)/sizeof(REFIID
), FALSE
);
204 IUnknown_Release(input
);
206 IXmlReader_Release(reader
);
209 static void test_readerinput(void)
211 IXmlReaderInput
*reader_input
;
217 hr
= pCreateXmlReaderInputWithEncodingName(NULL
, NULL
, NULL
, FALSE
, NULL
, NULL
);
218 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
219 hr
= pCreateXmlReaderInputWithEncodingName(NULL
, NULL
, NULL
, FALSE
, NULL
, &reader_input
);
220 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
222 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
223 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
225 ref
= IStream_AddRef(stream
);
226 ok(ref
== 2, "Expected 2, got %d\n", ref
);
227 IStream_Release(stream
);
228 hr
= pCreateXmlReaderInputWithEncodingName((IUnknown
*)stream
, NULL
, NULL
, FALSE
, NULL
, &reader_input
);
229 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
231 /* IXmlReader grabs a stream reference */
232 ref
= IStream_AddRef(stream
);
233 todo_wine
ok(ref
== 3, "Expected 3, got %d\n", ref
);
234 IStream_Release(stream
);
236 /* IID_IXmlReaderInput */
237 /* it returns a kind of private undocumented vtable incompatible with IUnknown,
238 so it's not a COM interface actually.
239 Such query will be used only to check if input is really IXmlReaderInput */
240 obj
= (IUnknown
*)0xdeadbeef;
241 hr
= IUnknown_QueryInterface(reader_input
, &IID_IXmlReaderInput
, (void**)&obj
);
242 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
243 ref
= IUnknown_AddRef(reader_input
);
244 ok(ref
== 3, "Expected 3, got %d\n", ref
);
245 IUnknown_Release(reader_input
);
247 IUnknown_Release(reader_input
);
248 IStream_Release(stream
);
255 r
= CoInitialize( NULL
);
256 ok( r
== S_OK
, "failed to init com\n");
258 if (!init_pointers())
264 test_reader_create();