msxml3: Fix duplicated declarations after document ::get_xml().
[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 #include "initguid.h"
33
34 typedef enum _CH {
35     CH_ENDTEST,
36     CH_PUTDOCUMENTLOCATOR,
37     CH_STARTDOCUMENT,
38     CH_ENDDOCUMENT,
39     CH_STARTPREFIXMAPPING,
40     CH_ENDPREFIXMAPPING,
41     CH_STARTELEMENT,
42     CH_ENDELEMENT,
43     CH_CHARACTERS,
44     CH_IGNORABLEWHITESPACE,
45     CH_PROCESSINGINSTRUCTION,
46     CH_SKIPPEDENTITY
47 } CH;
48
49 DEFINE_GUID(CLSID_SAXXMLReader60, 0x88d96a0c, 0xf192, 0x11d4, 0xa6,0x5f, 0x00,0x40,0x96,0x32,0x51,0xe5);
50
51 static const WCHAR szSimpleXML[] = {
52 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
53 '<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
54 ' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
55 ' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
56 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
57 };
58
59 static const WCHAR szCarriageRetTest[] = {
60 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
61 '<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
62 '\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
63 '\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
64 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\0'
65 };
66
67 static const CHAR szTestXML[] =
68 "<?xml version=\"1.0\" ?>\n"
69 "<BankAccount>\n"
70 "   <Number>1234</Number>\n"
71 "   <Name>Captain Ahab</Name>\n"
72 "</BankAccount>\n";
73
74 typedef struct _contenthandlercheck {
75     CH id;
76     int line;
77     int column;
78     const char *arg1;
79     const char *arg2;
80     const char *arg3;
81 } content_handler_test;
82
83 static content_handler_test contentHandlerTest1[] = {
84     { CH_PUTDOCUMENTLOCATOR, 0, 0 },
85     { CH_STARTDOCUMENT, 0, 0 },
86     { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
87     { CH_CHARACTERS, 2, 14, "\n   " },
88     { CH_STARTELEMENT, 3, 12, "", "Number", "Number" },
89     { CH_CHARACTERS, 3, 12, "1234" },
90     { CH_ENDELEMENT, 3, 18, "", "Number", "Number" },
91     { CH_CHARACTERS, 3, 25, "\n   " },
92     { CH_STARTELEMENT, 4, 10, "", "Name", "Name" },
93     { CH_CHARACTERS, 4, 10, "Captain Ahab" },
94     { CH_ENDELEMENT, 4, 24, "", "Name", "Name" },
95     { CH_CHARACTERS, 4, 29, "\n" },
96     { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
97     { CH_ENDDOCUMENT, 0, 0 },
98     { CH_ENDTEST }
99 };
100
101 static content_handler_test contentHandlerTest2[] = {
102     { CH_PUTDOCUMENTLOCATOR, 0, 0 },
103     { CH_STARTDOCUMENT, 0, 0 },
104     { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
105     { CH_CHARACTERS, 2, 14, "\n" },
106     { CH_CHARACTERS, 2, 16, "\t" },
107     { CH_STARTELEMENT, 3, 10, "", "Number", "Number" },
108     { CH_CHARACTERS, 3, 10, "1234" },
109     { CH_ENDELEMENT, 3, 16, "", "Number", "Number" },
110     { CH_CHARACTERS, 3, 23, "\n" },
111     { CH_CHARACTERS, 3, 25, "\t" },
112     { CH_STARTELEMENT, 4, 8, "", "Name", "Name" },
113     { CH_CHARACTERS, 4, 8, "Captain Ahab" },
114     { CH_ENDELEMENT, 4, 22, "", "Name", "Name" },
115     { CH_CHARACTERS, 4, 27, "\n" },
116     { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
117     { CH_ENDDOCUMENT, 0, 0 },
118     { CH_ENDTEST }
119 };
120
121 static content_handler_test *expectCall;
122 static ISAXLocator *locator;
123
124 static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
125 {
126     WCHAR buf[1024];
127     int len;
128
129     if(!szTest) {
130         ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
131         ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
132         return;
133     }
134
135     len = strlen(szTest);
136     ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
137     if(len != nStr)
138         return;
139
140     MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
141     ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
142                         wine_dbgstr_wn(szStr, nStr), szTest);
143 }
144
145 static BOOL test_expect_call(CH id)
146 {
147     ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
148     return expectCall->id == id;
149 }
150
151 static void test_locator(unsigned line, int loc_line, int loc_column)
152 {
153     int rcolumn, rline;
154     ISAXLocator_getLineNumber(locator, &rline);
155     ISAXLocator_getColumnNumber(locator, &rcolumn);
156
157     ok_(__FILE__,line) (rline == loc_line,
158             "unexpected line %d, expected %d\n", rline, loc_line);
159     ok_(__FILE__,line) (rcolumn == loc_column,
160             "unexpected column %d, expected %d\n", rcolumn, loc_column);
161 }
162
163 static HRESULT WINAPI contentHandler_QueryInterface(
164         ISAXContentHandler* iface,
165         REFIID riid,
166         void **ppvObject)
167 {
168     *ppvObject = NULL;
169
170     if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
171     {
172         *ppvObject = iface;
173     }
174     else
175     {
176         return E_NOINTERFACE;
177     }
178
179     return S_OK;
180 }
181
182 static ULONG WINAPI contentHandler_AddRef(
183         ISAXContentHandler* iface)
184 {
185     return 2;
186 }
187
188 static ULONG WINAPI contentHandler_Release(
189         ISAXContentHandler* iface)
190 {
191     return 1;
192 }
193
194 static HRESULT WINAPI contentHandler_putDocumentLocator(
195         ISAXContentHandler* iface,
196         ISAXLocator *pLocator)
197 {
198     if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
199         return E_FAIL;
200
201     locator = pLocator;
202     test_locator(__LINE__, expectCall->line, expectCall->column);
203
204     expectCall++;
205     return S_OK;
206 }
207
208 static HRESULT WINAPI contentHandler_startDocument(
209         ISAXContentHandler* iface)
210 {
211     if(!test_expect_call(CH_STARTDOCUMENT))
212         return E_FAIL;
213
214     test_locator(__LINE__, expectCall->line, expectCall->column);
215
216     expectCall++;
217     return S_OK;
218 }
219
220 static HRESULT WINAPI contentHandler_endDocument(
221         ISAXContentHandler* iface)
222 {
223     if(!test_expect_call(CH_ENDDOCUMENT))
224         return E_FAIL;
225
226     test_locator(__LINE__, expectCall->line, expectCall->column);
227
228     expectCall++;
229     return S_OK;
230 }
231
232 static HRESULT WINAPI contentHandler_startPrefixMapping(
233         ISAXContentHandler* iface,
234         const WCHAR *pPrefix,
235         int nPrefix,
236         const WCHAR *pUri,
237         int nUri)
238 {
239     if(!test_expect_call(CH_ENDDOCUMENT))
240         return E_FAIL;
241
242     test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
243     test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
244     test_locator(__LINE__, expectCall->line, expectCall->column);
245
246     expectCall++;
247     return S_OK;
248 }
249
250 static HRESULT WINAPI contentHandler_endPrefixMapping(
251         ISAXContentHandler* iface,
252         const WCHAR *pPrefix,
253         int nPrefix)
254 {
255     if(!test_expect_call(CH_ENDPREFIXMAPPING))
256         return E_FAIL;
257
258     test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
259     test_locator(__LINE__, expectCall->line, expectCall->column);
260
261     expectCall++;
262     return S_OK;
263 }
264
265 static HRESULT WINAPI contentHandler_startElement(
266         ISAXContentHandler* iface,
267         const WCHAR *pNamespaceUri,
268         int nNamespaceUri,
269         const WCHAR *pLocalName,
270         int nLocalName,
271         const WCHAR *pQName,
272         int nQName,
273         ISAXAttributes *pAttr)
274 {
275     if(!test_expect_call(CH_STARTELEMENT))
276         return E_FAIL;
277
278     test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
279     test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
280     test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
281     test_locator(__LINE__, expectCall->line, expectCall->column);
282
283     expectCall++;
284     return S_OK;
285 }
286
287 static HRESULT WINAPI contentHandler_endElement(
288         ISAXContentHandler* iface,
289         const WCHAR *pNamespaceUri,
290         int nNamespaceUri,
291         const WCHAR *pLocalName,
292         int nLocalName,
293         const WCHAR *pQName,
294         int nQName)
295 {
296     if(!test_expect_call(CH_ENDELEMENT))
297         return E_FAIL;
298
299     test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
300     test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
301     test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
302     test_locator(__LINE__, expectCall->line, expectCall->column);
303
304     expectCall++;
305     return S_OK;
306 }
307
308 static HRESULT WINAPI contentHandler_characters(
309         ISAXContentHandler* iface,
310         const WCHAR *pChars,
311         int nChars)
312 {
313     if(!test_expect_call(CH_CHARACTERS))
314         return E_FAIL;
315
316     test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
317     test_locator(__LINE__, expectCall->line, expectCall->column);
318
319     expectCall++;
320     return S_OK;
321 }
322
323 static HRESULT WINAPI contentHandler_ignorableWhitespace(
324         ISAXContentHandler* iface,
325         const WCHAR *pChars,
326         int nChars)
327 {
328     if(!test_expect_call(CH_IGNORABLEWHITESPACE))
329         return E_FAIL;
330
331     test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
332     test_locator(__LINE__, expectCall->line, expectCall->column);
333
334     expectCall++;
335     return S_OK;
336 }
337
338 static HRESULT WINAPI contentHandler_processingInstruction(
339         ISAXContentHandler* iface,
340         const WCHAR *pTarget,
341         int nTarget,
342         const WCHAR *pData,
343         int nData)
344 {
345     if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
346         return E_FAIL;
347
348     test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
349     test_saxstr(__LINE__, pData, nData, expectCall->arg2);
350     test_locator(__LINE__, expectCall->line, expectCall->column);
351
352     expectCall++;
353     return S_OK;
354 }
355
356 static HRESULT WINAPI contentHandler_skippedEntity(
357         ISAXContentHandler* iface,
358         const WCHAR *pName,
359         int nName)
360 {
361     if(!test_expect_call(CH_SKIPPEDENTITY))
362         return E_FAIL;
363
364     test_saxstr(__LINE__, pName, nName, expectCall->arg1);
365     test_locator(__LINE__, expectCall->line, expectCall->column);
366
367     expectCall++;
368     return S_OK;
369 }
370
371
372 static const ISAXContentHandlerVtbl contentHandlerVtbl =
373 {
374     contentHandler_QueryInterface,
375     contentHandler_AddRef,
376     contentHandler_Release,
377     contentHandler_putDocumentLocator,
378     contentHandler_startDocument,
379     contentHandler_endDocument,
380     contentHandler_startPrefixMapping,
381     contentHandler_endPrefixMapping,
382     contentHandler_startElement,
383     contentHandler_endElement,
384     contentHandler_characters,
385     contentHandler_ignorableWhitespace,
386     contentHandler_processingInstruction,
387     contentHandler_skippedEntity
388 };
389
390 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
391
392 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
393         ISAXErrorHandler* iface,
394         REFIID riid,
395         void **ppvObject)
396 {
397     *ppvObject = NULL;
398
399     if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
400     {
401         *ppvObject = iface;
402     }
403     else
404     {
405         return E_NOINTERFACE;
406     }
407
408     return S_OK;
409 }
410
411 static ULONG WINAPI isaxerrorHandler_AddRef(
412         ISAXErrorHandler* iface)
413 {
414     return 2;
415 }
416
417 static ULONG WINAPI isaxerrorHandler_Release(
418         ISAXErrorHandler* iface)
419 {
420     return 1;
421 }
422
423 static HRESULT WINAPI isaxerrorHandler_error(
424         ISAXErrorHandler* iface,
425         ISAXLocator *pLocator,
426         const WCHAR *pErrorMessage,
427         HRESULT hrErrorCode)
428 {
429     return S_OK;
430 }
431
432 static HRESULT WINAPI isaxerrorHandler_fatalError(
433         ISAXErrorHandler* iface,
434         ISAXLocator *pLocator,
435         const WCHAR *pErrorMessage,
436         HRESULT hrErrorCode)
437 {
438     return S_OK;
439 }
440
441 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
442         ISAXErrorHandler* iface,
443         ISAXLocator *pLocator,
444         const WCHAR *pErrorMessage,
445         HRESULT hrErrorCode)
446 {
447     return S_OK;
448 }
449
450 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
451 {
452     isaxerrorHandler_QueryInterface,
453     isaxerrorHandler_AddRef,
454     isaxerrorHandler_Release,
455     isaxerrorHandler_error,
456     isaxerrorHandler_fatalError,
457     isaxerrorHanddler_ignorableWarning
458 };
459
460 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
461
462 static void test_saxreader(void)
463 {
464     HRESULT hr;
465     ISAXXMLReader *reader = NULL;
466     VARIANT var;
467     ISAXContentHandler *lpContentHandler;
468     ISAXErrorHandler *lpErrorHandler;
469     SAFEARRAY *pSA;
470     SAFEARRAYBOUND SADim[1];
471     char *pSAData = NULL;
472     IStream *iStream;
473     ULARGE_INTEGER liSize;
474     LARGE_INTEGER liPos;
475     ULONG bytesWritten;
476     HANDLE file;
477     static const CHAR testXmlA[] = "test.xml";
478     static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
479     IXMLDOMDocument *domDocument;
480     BSTR bstrData;
481     VARIANT_BOOL vBool;
482
483     hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
484             &IID_ISAXXMLReader, (LPVOID*)&reader);
485     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
486
487     hr = ISAXXMLReader_getContentHandler(reader, NULL);
488     ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
489
490     hr = ISAXXMLReader_getErrorHandler(reader, NULL);
491     ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
492
493     hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
494     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
495     ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
496
497     hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
498     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
499     ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
500
501     hr = ISAXXMLReader_putContentHandler(reader, NULL);
502     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
503
504     hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
505     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
506
507     hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
508     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
509
510     hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
511     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
512     ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
513
514     V_VT(&var) = VT_BSTR;
515     V_BSTR(&var) = SysAllocString(szSimpleXML);
516
517     expectCall = contentHandlerTest1;
518     hr = ISAXXMLReader_parse(reader, var);
519     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
520     test_expect_call(CH_ENDTEST);
521
522     VariantClear(&var);
523
524     SADim[0].lLbound= 0;
525     SADim[0].cElements= sizeof(szTestXML)-1;
526     pSA = SafeArrayCreate(VT_UI1, 1, SADim);
527     SafeArrayAccessData(pSA, (void**)&pSAData);
528     memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
529     SafeArrayUnaccessData(pSA);
530     V_VT(&var) = VT_ARRAY|VT_UI1;
531     V_ARRAY(&var) = pSA;
532
533     expectCall = contentHandlerTest1;
534     hr = ISAXXMLReader_parse(reader, var);
535     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
536     test_expect_call(CH_ENDTEST);
537
538     SafeArrayDestroy(pSA);
539
540     CreateStreamOnHGlobal(NULL, TRUE, &iStream);
541     liSize.QuadPart = strlen(szTestXML);
542     IStream_SetSize(iStream, liSize);
543     IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
544     liPos.QuadPart = 0;
545     IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
546     V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
547     V_UNKNOWN(&var) = (IUnknown*)iStream;
548
549     expectCall = contentHandlerTest1;
550     hr = ISAXXMLReader_parse(reader, var);
551     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
552     test_expect_call(CH_ENDTEST);
553
554     IStream_Release(iStream);
555
556     V_VT(&var) = VT_BSTR;
557     V_BSTR(&var) = SysAllocString(szCarriageRetTest);
558
559     expectCall = contentHandlerTest2;
560     hr = ISAXXMLReader_parse(reader, var);
561     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
562     test_expect_call(CH_ENDTEST);
563
564     VariantClear(&var);
565
566     file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
567     ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
568     WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
569     CloseHandle(file);
570
571     expectCall = contentHandlerTest1;
572     hr = ISAXXMLReader_parseURL(reader, testXmlW);
573     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
574     test_expect_call(CH_ENDTEST);
575
576     DeleteFileA(testXmlA);
577
578     hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
579             &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
580     if(FAILED(hr))
581     {
582         skip("Failed to create DOMDocument instance\n");
583         return;
584     }
585     bstrData = SysAllocString(szSimpleXML);
586     hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
587     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
588     V_VT(&var) = VT_UNKNOWN;
589     V_UNKNOWN(&var) = (IUnknown*)domDocument;
590
591     expectCall = contentHandlerTest2;
592     hr = ISAXXMLReader_parse(reader, var);
593     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
594     test_expect_call(CH_ENDTEST);
595     IXMLDOMDocument_Release(domDocument);
596
597     ISAXXMLReader_Release(reader);
598     SysFreeString(bstrData);
599 }
600
601 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
602 static const CHAR UTF8BOMTest[] =
603 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
604 "<a></a>\n";
605
606 struct enc_test_entry_t {
607     const GUID *guid;
608     const char *clsid;
609     const char *data;
610     HRESULT hr;
611     int todo;
612 };
613
614 static const struct enc_test_entry_t encoding_test_data[] = {
615     { &CLSID_SAXXMLReader,   "CLSID_SAXXMLReader",   UTF8BOMTest, 0xc00ce56f, 1 },
616     { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
617     { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
618     { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
619     { 0 }
620 };
621
622 static void test_encoding(void)
623 {
624     const struct enc_test_entry_t *entry = encoding_test_data;
625     static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
626     static const CHAR testXmlA[] = "test.xml";
627     ISAXXMLReader *reader;
628     DWORD written;
629     HANDLE file;
630     HRESULT hr;
631
632     while (entry->guid)
633     {
634         hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
635         if (hr != S_OK)
636         {
637             win_skip("can't create %s instance\n", entry->clsid);
638             entry++;
639             continue;
640         }
641
642         file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
643         ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
644         WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
645         CloseHandle(file);
646
647         hr = ISAXXMLReader_parseURL(reader, testXmlW);
648         if (entry->todo)
649             todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
650         else
651             ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
652
653         DeleteFileA(testXmlA);
654         ISAXXMLReader_Release(reader);
655
656         entry++;
657     }
658 }
659
660 START_TEST(saxreader)
661 {
662     ISAXXMLReader *reader;
663     HRESULT hr;
664
665     hr = CoInitialize(NULL);
666     ok(hr == S_OK, "failed to init com\n");
667
668     hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
669             &IID_ISAXXMLReader, (void**)&reader);
670
671     if(FAILED(hr))
672     {
673         skip("Failed to create SAXXMLReader instance\n");
674         CoUninitialize();
675         return;
676     }
677     ISAXXMLReader_Release(reader);
678
679     test_saxreader();
680     test_encoding();
681
682     CoUninitialize();
683 }