xmllite/tests: Add basic test structure for IXmlReader.
[wine] / dlls / xmllite / tests / reader.c
1 /*
2  * XMLLite IXmlReader tests
3  *
4  * Copyright 2010 (C) Nikolay Sivov
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 #define COBJMACROS
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "ole2.h"
28 #include "xmllite.h"
29 #include "initguid.h"
30 #include "wine/test.h"
31
32 DEFINE_GUID(IID_IXmlReader, 0x7279fc81, 0x709d, 0x4095, 0xb6, 0x3d, 0x69,
33                             0xfe, 0x4b, 0x0d, 0x90, 0x30);
34
35 HRESULT WINAPI (*pCreateXmlReader)(REFIID riid, void **ppvObject, IMalloc *pMalloc);
36
37 static BOOL init_pointers(void)
38 {
39     /* don't free module here, it's to be unloaded on exit */
40     HMODULE mod = LoadLibraryA("xmllite.dll");
41
42     if (!mod)
43     {
44         win_skip("xmllite library not available\n");
45         return FALSE;
46     }
47
48     pCreateXmlReader = (void*)GetProcAddress(mod, "CreateXmlReader");
49     if (!pCreateXmlReader) return FALSE;
50
51     return TRUE;
52 }
53
54 static void test_reader_create(void)
55 {
56     HRESULT hr;
57     IXmlReader *reader;
58     IMalloc *imalloc;
59
60     /* crashes native */
61     if (0)
62     {
63         hr = pCreateXmlReader(&IID_IXmlReader, NULL, NULL);
64         hr = pCreateXmlReader(NULL, (LPVOID*)&reader, NULL);
65     }
66
67     hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
68     todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
69     if (hr != S_OK)
70     {
71         skip("Failed to create IXmlReader instance\n");
72         return;
73     }
74
75     hr = CoGetMalloc(1, &imalloc);
76     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
77
78     hr = IMalloc_DidAlloc(imalloc, reader);
79     ok(hr != 1, "Expected 0 or -1, got %08x\n", hr);
80
81     IXmlReader_Release(reader);
82 }
83
84 START_TEST(reader)
85 {
86     HRESULT r;
87
88     r = CoInitialize( NULL );
89     ok( r == S_OK, "failed to init com\n");
90
91     if (!init_pointers())
92     {
93        CoUninitialize();
94        return;
95     }
96
97     test_reader_create();
98
99     CoUninitialize();
100 }