msxml3/test: Added ISAXXMLReader test.
[wine] / dlls / msxml3 / tests / saxreader.c
1 /*
2  * XML test
3  *
4  * Copyright 2008 Piotr Caban
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 #define CONST_VTABLE
23
24 #include <stdio.h>
25 #include "windows.h"
26 #include "ole2.h"
27 #include "msxml2.h"
28 #include "ocidl.h"
29
30 #include "wine/test.h"
31
32 typedef struct _contenthandler
33 {
34     const struct ISAXContentHandlerVtbl *lpContentHandlerVtbl;
35 } contenthandler;
36
37 static inline contenthandler *impl_from_ISAXContentHandler(ISAXContentHandler *iface)
38 {
39     return (contenthandler *)((char*)iface - FIELD_OFFSET(contenthandler, lpContentHandlerVtbl));
40 }
41
42 static HRESULT WINAPI contentHandler_QueryInterface(
43         ISAXContentHandler* iface,
44         REFIID riid,
45         void **ppvObject)
46 {
47     *ppvObject = NULL;
48
49     if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
50     {
51         *ppvObject = iface;
52     }
53     else
54     {
55         return E_NOINTERFACE;
56     }
57
58     return S_OK;
59 }
60
61 static ULONG WINAPI contentHandler_AddRef(
62         ISAXContentHandler* iface)
63 {
64         return 2;
65 }
66
67 static ULONG WINAPI contentHandler_Release(
68         ISAXContentHandler* iface)
69 {
70         return 1;
71 }
72
73 static HRESULT WINAPI contentHandler_putDocumentLocator(
74         ISAXContentHandler* iface,
75         ISAXLocator *pLocator)
76 {
77         return S_OK;
78 }
79
80 static HRESULT WINAPI contentHandler_startDocument(
81         ISAXContentHandler* iface)
82 {
83         return S_OK;
84 }
85
86 static HRESULT WINAPI contentHandler_endDocument(
87         ISAXContentHandler* iface)
88 {
89         return S_OK;
90 }
91
92 static HRESULT WINAPI contentHandler_startPrefixMapping(
93         ISAXContentHandler* iface,
94         const WCHAR *pPrefix,
95         int nPrefix,
96         const WCHAR *pUri,
97         int nUri)
98 {
99         return S_OK;
100 }
101
102 static HRESULT WINAPI contentHandler_endPrefixMapping(
103         ISAXContentHandler* iface,
104         const WCHAR *pPrefix,
105         int nPrefix)
106 {
107         return S_OK;
108 }
109
110 static HRESULT WINAPI contentHandler_startElement(
111         ISAXContentHandler* iface,
112         const WCHAR *pNamespaceUri,
113         int nNamespaceUri,
114         const WCHAR *pLocalName,
115         int nLocalName,
116         const WCHAR *pQName,
117         int nQName,
118         ISAXAttributes *pAttr)
119 {
120         return S_OK;
121 }
122
123 static HRESULT WINAPI contentHandler_endElement(
124         ISAXContentHandler* iface,
125         const WCHAR *pNamespaceUri,
126         int nNamespaceUri,
127         const WCHAR *pLocalName,
128         int nLocalName,
129         const WCHAR *pQName,
130         int nQName)
131 {
132         return S_OK;
133 }
134
135 static HRESULT WINAPI contentHandler_characters(
136         ISAXContentHandler* iface,
137         const WCHAR *pChars,
138         int nChars)
139 {
140         return S_OK;
141 }
142
143 static HRESULT WINAPI contentHandler_ignorableWhitespace(
144         ISAXContentHandler* iface,
145         const WCHAR *pChars,
146         int nChars)
147 {
148         return S_OK;
149 }
150
151 static HRESULT WINAPI contentHandler_processingInstruction(
152         ISAXContentHandler* iface,
153         const WCHAR *pTarget,
154         int nTarget,
155         const WCHAR *pData,
156         int nData)
157 {
158         return S_OK;
159 }
160
161 static HRESULT WINAPI contentHandler_skippedEntity(
162         ISAXContentHandler* iface,
163         const WCHAR *pName,
164         int nName)
165 {
166         return S_OK;
167 }
168
169
170 static const ISAXContentHandlerVtbl contentHandlerVtbl =
171 {
172     contentHandler_QueryInterface,
173     contentHandler_AddRef,
174     contentHandler_Release,
175     contentHandler_putDocumentLocator,
176     contentHandler_startDocument,
177     contentHandler_endDocument,
178     contentHandler_startPrefixMapping,
179     contentHandler_endPrefixMapping,
180     contentHandler_startElement,
181     contentHandler_endElement,
182     contentHandler_characters,
183     contentHandler_ignorableWhitespace,
184     contentHandler_processingInstruction,
185     contentHandler_skippedEntity
186 };
187
188 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
189
190
191 static void test_saxreader(void)
192 {
193     HRESULT hr;
194     ISAXXMLReader *reader = NULL;
195
196     hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
197             &IID_ISAXXMLReader, (LPVOID*)&reader);
198
199     if(FAILED(hr))
200     {
201         skip("Failed to create SAXXMLReader instance\n");
202         return;
203     }
204
205     hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
206     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
207
208     ISAXXMLReader_Release(reader);
209 }
210
211 START_TEST(saxreader)
212 {
213     HRESULT hr;
214
215     hr = CoInitialize(NULL);
216     ok(hr == S_OK, "failed to init com\n");
217
218     test_saxreader();
219
220     CoUninitialize();
221 }