msxml3: Support startDTD()/endDTD() in MXWriter.
[wine] / dlls / msxml3 / tests / saxreader.c
1 /*
2  * XML test
3  *
4  * Copyright 2008 Piotr Caban
5  * Copyright 2011 Thomas Mullaly
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #define COBJMACROS
23 #define CONST_VTABLE
24
25 #include <stdio.h>
26 #include <assert.h>
27
28 #include "windows.h"
29 #include "ole2.h"
30 #include "msxml2.h"
31 #include "msxml2did.h"
32 #include "ocidl.h"
33 #include "dispex.h"
34
35 #include "wine/test.h"
36
37 #define EXPECT_HR(hr,hr_exp) \
38     ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
39
40 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
41 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
42 {
43     ULONG rc = IUnknown_AddRef(obj);
44     IUnknown_Release(obj);
45     ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
46 }
47
48 static BSTR alloc_str_from_narrow(const char *str)
49 {
50     int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
51     BSTR ret = SysAllocStringLen(NULL, len - 1);  /* NUL character added automatically */
52     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
53     return ret;
54 }
55
56 static BSTR alloced_bstrs[512];
57 static int alloced_bstrs_count;
58
59 static BSTR _bstr_(const char *str)
60 {
61     assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
62     alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
63     return alloced_bstrs[alloced_bstrs_count++];
64 }
65
66 static void free_bstrs(void)
67 {
68     int i;
69     for (i = 0; i < alloced_bstrs_count; i++)
70         SysFreeString(alloced_bstrs[i]);
71     alloced_bstrs_count = 0;
72 }
73
74 typedef enum _CH {
75     CH_ENDTEST,
76     CH_PUTDOCUMENTLOCATOR,
77     CH_STARTDOCUMENT,
78     CH_ENDDOCUMENT,
79     CH_STARTPREFIXMAPPING,
80     CH_ENDPREFIXMAPPING,
81     CH_STARTELEMENT,
82     CH_ENDELEMENT,
83     CH_CHARACTERS,
84     CH_IGNORABLEWHITESPACE,
85     CH_PROCESSINGINSTRUCTION,
86     CH_SKIPPEDENTITY,
87     EH_ERROR,
88     EH_FATALERROR,
89     EG_IGNORABLEWARNING
90 } CH;
91
92 static const WCHAR szSimpleXML[] = {
93 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
94 '<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
95 ' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
96 ' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
97 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
98 };
99
100 static const WCHAR szCarriageRetTest[] = {
101 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
102 '<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
103 '\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
104 '\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
105 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n','\0'
106 };
107
108 static const WCHAR szUtf16XML[] = {
109 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"',' ',
110 'e','n','c','o','d','i','n','g','=','"','U','T','F','-','1','6','"',' ',
111 's','t','a','n','d','a','l','o','n','e','=','"','n','o','"','?','>','\r','\n'
112 };
113
114 static const CHAR szUtf16BOM[] = {0xff, 0xfe};
115
116 static const CHAR szUtf8XML[] =
117 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n";
118
119 static const char utf8xml2[] =
120 "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n";
121
122 static const CHAR szTestXML[] =
123 "<?xml version=\"1.0\" ?>\n"
124 "<BankAccount>\n"
125 "   <Number>1234</Number>\n"
126 "   <Name>Captain Ahab</Name>\n"
127 "</BankAccount>\n";
128
129 static const CHAR szTestAttributes[] =
130 "<?xml version=\"1.0\" ?>\n"
131 "<document xmlns:test=\"prefix_test\" xmlns=\"prefix\" test:arg1=\"arg1\" arg2=\"arg2\" test:ar3=\"arg3\">\n"
132 "<node1 xmlns:p=\"test\" />"
133 "</document>\n";
134
135 typedef struct _contenthandlercheck {
136     CH id;
137     int line;
138     int column;
139     int line_v6;
140     int column_v6;
141     const char *arg1;
142     const char *arg2;
143     const char *arg3;
144     HRESULT ret;
145 } content_handler_test;
146
147 static content_handler_test contentHandlerTest1[] = {
148     { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
149     { CH_STARTDOCUMENT, 0, 0, 1, 22 },
150     { CH_STARTELEMENT, 2, 14, 2, 13, "", "BankAccount", "BankAccount" },
151     { CH_CHARACTERS, 2, 14, 3, 4, "\n   " },
152     { CH_STARTELEMENT, 3, 12, 3, 11, "", "Number", "Number" },
153     { CH_CHARACTERS, 3, 12, 3, 16, "1234" },
154     { CH_ENDELEMENT, 3, 18, 3, 24, "", "Number", "Number" },
155     { CH_CHARACTERS, 3, 25, 4, 4, "\n   " },
156     { CH_STARTELEMENT, 4, 10, 4, 9, "", "Name", "Name" },
157     { CH_CHARACTERS, 4, 10, 4, 22, "Captain Ahab" },
158     { CH_ENDELEMENT, 4, 24, 4, 28, "", "Name", "Name" },
159     { CH_CHARACTERS, 4, 29, 5, 1, "\n" },
160     { CH_ENDELEMENT, 5, 3, 5, 14, "", "BankAccount", "BankAccount" },
161     { CH_ENDDOCUMENT, 0, 0, 6, 0 },
162     { CH_ENDTEST }
163 };
164
165 static content_handler_test contentHandlerTest2[] = {
166     { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
167     { CH_STARTDOCUMENT, 0, 0, 1, 21 },
168     { CH_STARTELEMENT, 2, 14, 2, 13, "", "BankAccount", "BankAccount" },
169     { CH_CHARACTERS, 2, 14, 3, 0, "\n" },
170     { CH_CHARACTERS, 2, 16, 3, 2, "\t" },
171     { CH_STARTELEMENT, 3, 10, 3, 9, "", "Number", "Number" },
172     { CH_CHARACTERS, 3, 10, 3, 14, "1234" },
173     { CH_ENDELEMENT, 3, 16, 3, 22, "", "Number", "Number" },
174     { CH_CHARACTERS, 3, 23, 4, 0, "\n" },
175     { CH_CHARACTERS, 3, 25, 4, 2, "\t" },
176     { CH_STARTELEMENT, 4, 8, 4, 7, "", "Name", "Name" },
177     { CH_CHARACTERS, 4, 8, 4, 20, "Captain Ahab" },
178     { CH_ENDELEMENT, 4, 22, 4, 26, "", "Name", "Name" },
179     { CH_CHARACTERS, 4, 27, 5, 0, "\n" },
180     { CH_ENDELEMENT, 5, 3, 5, 14, "", "BankAccount", "BankAccount" },
181     { CH_ENDDOCUMENT, 0, 0, 6, 0 },
182     { CH_ENDTEST }
183 };
184
185 static content_handler_test contentHandlerTestError[] = {
186     { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0, NULL, NULL, NULL, E_FAIL },
187     { EH_FATALERROR, 0, 0, 0, 0, NULL, NULL, NULL, E_FAIL },
188     { CH_ENDTEST }
189 };
190
191 static content_handler_test contentHandlerTestCallbackResults[] = {
192     { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0, NULL, NULL, NULL, S_FALSE },
193     { CH_STARTDOCUMENT, 0, 0, 1, 22, NULL, NULL, NULL, S_FALSE },
194     { EH_FATALERROR, 0, 0, 0, 0, NULL, NULL, NULL, S_FALSE },
195     { CH_ENDTEST }
196 };
197
198 static content_handler_test contentHandlerTestCallbackResult6[] = {
199     { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0, NULL, NULL, NULL, S_FALSE },
200     { CH_STARTDOCUMENT, 0, 0, 1, 22, NULL, NULL, NULL, S_FALSE },
201     { CH_STARTELEMENT, 2, 14, 2, 13, "", "BankAccount", "BankAccount", S_FALSE },
202     { CH_CHARACTERS, 2, 14, 3, 4, "\n   ", NULL, NULL, S_FALSE },
203     { CH_STARTELEMENT, 3, 12, 3, 11, "", "Number", "Number", S_FALSE },
204     { CH_CHARACTERS, 3, 12, 3, 16, "1234", NULL, NULL, S_FALSE },
205     { CH_ENDELEMENT, 3, 18, 3, 24, "", "Number", "Number", S_FALSE },
206     { CH_CHARACTERS, 3, 25, 4, 4, "\n   ", NULL, NULL, S_FALSE },
207     { CH_STARTELEMENT, 4, 10, 4, 9, "", "Name", "Name", S_FALSE },
208     { CH_CHARACTERS, 4, 10, 4, 22, "Captain Ahab", NULL, NULL, S_FALSE },
209     { CH_ENDELEMENT, 4, 24, 4, 28, "", "Name", "Name", S_FALSE },
210     { CH_CHARACTERS, 4, 29, 5, 1, "\n", NULL, NULL, S_FALSE },
211     { CH_ENDELEMENT, 5, 3, 5, 14, "", "BankAccount", "BankAccount", S_FALSE },
212     { CH_ENDDOCUMENT, 0, 0, 6, 0, NULL, NULL, NULL, S_FALSE },
213     { CH_ENDTEST }
214 };
215
216 static content_handler_test contentHandlerTestAttributes[] = {
217     { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
218     { CH_STARTDOCUMENT, 0, 0, 1, 22 },
219     { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "test", "prefix_test" },
220     { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "", "prefix" },
221     { CH_STARTELEMENT, 2, 96, 2, 95, "prefix", "document", "document" },
222     { CH_CHARACTERS, 2, 96, 3, 1, "\n" },
223     { CH_STARTPREFIXMAPPING, 3, 25, 3, 24, "p", "test" },
224     { CH_STARTELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
225     { CH_ENDELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
226     { CH_ENDPREFIXMAPPING, 3, 25, 3, 24, "p" },
227     { CH_ENDELEMENT, 3, 27, 3, 35, "prefix", "document", "document" },
228     { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "" },
229     { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "test" },
230     { CH_ENDDOCUMENT, 0, 0, 4, 0 },
231     { CH_ENDTEST }
232 };
233
234 static content_handler_test contentHandlerTestAttributes6[] = {
235     { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
236     { CH_STARTDOCUMENT, 0, 0, 1, 22 },
237     { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "test", "prefix_test" },
238     { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "", "prefix" },
239     { CH_STARTELEMENT, 2, 96, 2, 95, "prefix", "document", "document" },
240     { CH_CHARACTERS, 2, 96, 3, 1, "\n" },
241     { CH_STARTPREFIXMAPPING, 3, 25, 3, 24, "p", "test" },
242     { CH_STARTELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
243     { CH_ENDELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
244     { CH_ENDPREFIXMAPPING, 3, 25, 3, 24, "p" },
245     { CH_ENDELEMENT, 3, 27, 3, 35, "prefix", "document", "document" },
246     { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "test" },
247     { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "" },
248     { CH_ENDDOCUMENT, 0, 0, 4, 0 },
249     { CH_ENDTEST }
250 };
251
252 static content_handler_test *expectCall;
253 static ISAXLocator *locator;
254 int msxml_version;
255
256 static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
257 {
258     WCHAR buf[1024];
259     int len;
260
261     if(!szTest) {
262         ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
263         ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
264         return;
265     }
266
267     len = strlen(szTest);
268     ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
269     if(len != nStr)
270         return;
271
272     MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
273     ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
274                         wine_dbgstr_wn(szStr, nStr), szTest);
275 }
276
277 static BOOL test_expect_call(CH id)
278 {
279     ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
280     return expectCall->id == id;
281 }
282
283 static void test_locator(unsigned line, int loc_line, int loc_column)
284 {
285     int rcolumn, rline;
286     ISAXLocator_getLineNumber(locator, &rline);
287     ISAXLocator_getColumnNumber(locator, &rcolumn);
288
289     ok_(__FILE__,line) (rline == loc_line,
290             "unexpected line %d, expected %d\n", rline, loc_line);
291     ok_(__FILE__,line) (rcolumn == loc_column,
292             "unexpected column %d, expected %d\n", rcolumn, loc_column);
293 }
294
295 static HRESULT WINAPI contentHandler_QueryInterface(
296         ISAXContentHandler* iface,
297         REFIID riid,
298         void **ppvObject)
299 {
300     *ppvObject = NULL;
301
302     if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
303     {
304         *ppvObject = iface;
305     }
306     else
307     {
308         return E_NOINTERFACE;
309     }
310
311     return S_OK;
312 }
313
314 static ULONG WINAPI contentHandler_AddRef(
315         ISAXContentHandler* iface)
316 {
317     return 2;
318 }
319
320 static ULONG WINAPI contentHandler_Release(
321         ISAXContentHandler* iface)
322 {
323     return 1;
324 }
325
326 static HRESULT WINAPI contentHandler_putDocumentLocator(
327         ISAXContentHandler* iface,
328         ISAXLocator *pLocator)
329 {
330     ISAXAttributes *attr, *attr1;
331     HRESULT hr;
332
333     if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
334         return E_FAIL;
335
336     locator = pLocator;
337     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
338             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
339
340     if(msxml_version >= 6) {
341         EXPECT_REF(pLocator, 1);
342         hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr);
343         EXPECT_HR(hr, S_OK);
344         EXPECT_REF(pLocator, 2);
345         hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr1);
346         EXPECT_HR(hr, S_OK);
347         EXPECT_REF(pLocator, 3);
348         ok(attr == attr1, "got %p, %p\n", attr, attr1);
349         ISAXAttributes_Release(attr);
350         ISAXAttributes_Release(attr1);
351     }
352
353     return (expectCall++)->ret;
354 }
355
356 static ISAXAttributes *test_attr_ptr;
357 static HRESULT WINAPI contentHandler_startDocument(
358         ISAXContentHandler* iface)
359 {
360     if(!test_expect_call(CH_STARTDOCUMENT))
361         return E_FAIL;
362
363     test_attr_ptr = NULL;
364     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
365             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
366
367     return (expectCall++)->ret;
368 }
369
370 static HRESULT WINAPI contentHandler_endDocument(
371         ISAXContentHandler* iface)
372 {
373     if(!test_expect_call(CH_ENDDOCUMENT))
374         return E_FAIL;
375
376     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
377             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
378
379     return (expectCall++)->ret;
380 }
381
382 static HRESULT WINAPI contentHandler_startPrefixMapping(
383         ISAXContentHandler* iface,
384         const WCHAR *pPrefix,
385         int nPrefix,
386         const WCHAR *pUri,
387         int nUri)
388 {
389     if(!test_expect_call(CH_STARTPREFIXMAPPING))
390         return E_FAIL;
391
392     test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
393     test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
394     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
395             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
396
397     return (expectCall++)->ret;
398 }
399
400 static HRESULT WINAPI contentHandler_endPrefixMapping(
401         ISAXContentHandler* iface,
402         const WCHAR *pPrefix,
403         int nPrefix)
404 {
405     if(!test_expect_call(CH_ENDPREFIXMAPPING))
406         return E_FAIL;
407
408     test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
409     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
410             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
411
412     return (expectCall++)->ret;
413 }
414
415 static HRESULT WINAPI contentHandler_startElement(
416         ISAXContentHandler* iface,
417         const WCHAR *pNamespaceUri,
418         int nNamespaceUri,
419         const WCHAR *pLocalName,
420         int nLocalName,
421         const WCHAR *pQName,
422         int nQName,
423         ISAXAttributes *pAttr)
424 {
425     int len;
426     HRESULT hres;
427
428     if(!test_expect_call(CH_STARTELEMENT))
429         return E_FAIL;
430
431     test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
432     test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
433     test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
434     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
435             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
436
437     if(!test_attr_ptr)
438         test_attr_ptr = pAttr;
439     ok(test_attr_ptr == pAttr, "Multiple ISAXAttributes instances are used (%p %p)\n", test_attr_ptr, pAttr);
440
441     if(expectCall == contentHandlerTestAttributes+4) {
442         const WCHAR *uri_ptr = NULL;
443         int i;
444         /* msxml3 returns attributes and namespaces in the input order */
445         hres = ISAXAttributes_getLength(pAttr, &len);
446         ok(hres == S_OK, "getLength returned %x\n", hres);
447         ok(len == 5, "Incorrect number of attributes: %d\n", len);
448         ok(msxml_version < 6, "wrong msxml_version: %d\n", msxml_version);
449
450         for(i=0; i<len; i++) {
451             hres = ISAXAttributes_getName(pAttr, i, &pNamespaceUri, &nNamespaceUri,
452                     &pLocalName, &nLocalName, &pQName, &nQName);
453             ok(hres == S_OK, "getName returned %x\n", hres);
454
455             if(nQName == 4) {
456                 todo_wine ok(i==3, "Incorrect attributes order\n");
457                 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
458                 test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
459                 test_saxstr(__LINE__, pQName, nQName, "arg2");
460             } else if(nQName == 5) {
461                 todo_wine ok(i==1, "Incorrect attributes order\n");
462                 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
463                 test_saxstr(__LINE__, pLocalName, nLocalName, "");
464                 test_saxstr(__LINE__, pQName, nQName, "xmlns");
465             } else if(nQName == 8) {
466                 todo_wine ok(i==4, "Incorrect attributes order\n");
467                 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
468                 test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
469                 test_saxstr(__LINE__, pQName, nQName, "test:ar3");
470                 ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
471             } else if(nQName == 9) {
472                 todo_wine ok(i==2, "Incorrect attributes order\n");
473                 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
474                 test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
475                 test_saxstr(__LINE__, pQName, nQName, "test:arg1");
476                 uri_ptr = pNamespaceUri;
477             } else if(nQName == 10) {
478                 todo_wine ok(i==0, "Incorrect attributes order\n");
479                 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
480                 test_saxstr(__LINE__, pLocalName, nLocalName, "");
481                 test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
482             } else {
483                 ok(0, "Unexpected attribute\n");
484             }
485         }
486     } else if(expectCall == contentHandlerTestAttributes6+4) {
487         const WCHAR *uri_ptr;
488
489         /* msxml6 returns attributes first and then namespaces */
490         hres = ISAXAttributes_getLength(pAttr, &len);
491         ok(hres == S_OK, "getLength returned %x\n", hres);
492         ok(len == 5, "Incorrect number of attributes: %d\n", len);
493         ok(msxml_version >= 6, "wrong msxml_version: %d\n", msxml_version);
494
495         hres = ISAXAttributes_getName(pAttr, 0, &pNamespaceUri, &nNamespaceUri,
496                 &pLocalName, &nLocalName, &pQName, &nQName);
497         ok(hres == S_OK, "getName returned %x\n", hres);
498         test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
499         test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
500         test_saxstr(__LINE__, pQName, nQName, "test:arg1");
501         uri_ptr = pNamespaceUri;
502
503         hres = ISAXAttributes_getName(pAttr, 1, &pNamespaceUri, &nNamespaceUri,
504                 &pLocalName, &nLocalName, &pQName, &nQName);
505         ok(hres == S_OK, "getName returned %x\n", hres);
506         test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
507         test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
508         test_saxstr(__LINE__, pQName, nQName, "arg2");
509
510         hres = ISAXAttributes_getName(pAttr, 2, &pNamespaceUri, &nNamespaceUri,
511                 &pLocalName, &nLocalName, &pQName, &nQName);
512         ok(hres == S_OK, "getName returned %x\n", hres);
513         test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
514         test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
515         test_saxstr(__LINE__, pQName, nQName, "test:ar3");
516         ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
517
518         hres = ISAXAttributes_getName(pAttr, 3, &pNamespaceUri, &nNamespaceUri,
519                 &pLocalName, &nLocalName, &pQName, &nQName);
520         ok(hres == S_OK, "getName returned %x\n", hres);
521         test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
522         test_saxstr(__LINE__, pLocalName, nLocalName, "");
523         test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
524
525         hres = ISAXAttributes_getName(pAttr, 4, &pNamespaceUri, &nNamespaceUri,
526                 &pLocalName, &nLocalName, &pQName, &nQName);
527         ok(hres == S_OK, "getName returned %x\n", hres);
528         test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
529         test_saxstr(__LINE__, pLocalName, nLocalName, "");
530         test_saxstr(__LINE__, pQName, nQName, "xmlns");
531     }
532
533     return (expectCall++)->ret;
534 }
535
536 static HRESULT WINAPI contentHandler_endElement(
537         ISAXContentHandler* iface,
538         const WCHAR *pNamespaceUri,
539         int nNamespaceUri,
540         const WCHAR *pLocalName,
541         int nLocalName,
542         const WCHAR *pQName,
543         int nQName)
544 {
545     if(!test_expect_call(CH_ENDELEMENT))
546         return E_FAIL;
547
548     test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
549     test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
550     test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
551     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
552             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
553
554     return (expectCall++)->ret;
555 }
556
557 static HRESULT WINAPI contentHandler_characters(
558         ISAXContentHandler* iface,
559         const WCHAR *pChars,
560         int nChars)
561 {
562     if(!test_expect_call(CH_CHARACTERS))
563         return E_FAIL;
564
565     test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
566     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
567             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
568
569     return (expectCall++)->ret;
570 }
571
572 static HRESULT WINAPI contentHandler_ignorableWhitespace(
573         ISAXContentHandler* iface,
574         const WCHAR *pChars,
575         int nChars)
576 {
577     if(!test_expect_call(CH_IGNORABLEWHITESPACE))
578         return E_FAIL;
579
580     test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
581     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
582             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
583
584     return (expectCall++)->ret;
585 }
586
587 static HRESULT WINAPI contentHandler_processingInstruction(
588         ISAXContentHandler* iface,
589         const WCHAR *pTarget,
590         int nTarget,
591         const WCHAR *pData,
592         int nData)
593 {
594     if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
595         return E_FAIL;
596
597     test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
598     test_saxstr(__LINE__, pData, nData, expectCall->arg2);
599     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
600             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
601
602     return (expectCall++)->ret;
603 }
604
605 static HRESULT WINAPI contentHandler_skippedEntity(
606         ISAXContentHandler* iface,
607         const WCHAR *pName,
608         int nName)
609 {
610     if(!test_expect_call(CH_SKIPPEDENTITY))
611         return E_FAIL;
612
613     test_saxstr(__LINE__, pName, nName, expectCall->arg1);
614     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
615             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
616
617     return (expectCall++)->ret;
618 }
619
620
621 static const ISAXContentHandlerVtbl contentHandlerVtbl =
622 {
623     contentHandler_QueryInterface,
624     contentHandler_AddRef,
625     contentHandler_Release,
626     contentHandler_putDocumentLocator,
627     contentHandler_startDocument,
628     contentHandler_endDocument,
629     contentHandler_startPrefixMapping,
630     contentHandler_endPrefixMapping,
631     contentHandler_startElement,
632     contentHandler_endElement,
633     contentHandler_characters,
634     contentHandler_ignorableWhitespace,
635     contentHandler_processingInstruction,
636     contentHandler_skippedEntity
637 };
638
639 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
640
641 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
642         ISAXErrorHandler* iface,
643         REFIID riid,
644         void **ppvObject)
645 {
646     *ppvObject = NULL;
647
648     if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
649     {
650         *ppvObject = iface;
651     }
652     else
653     {
654         return E_NOINTERFACE;
655     }
656
657     return S_OK;
658 }
659
660 static ULONG WINAPI isaxerrorHandler_AddRef(
661         ISAXErrorHandler* iface)
662 {
663     return 2;
664 }
665
666 static ULONG WINAPI isaxerrorHandler_Release(
667         ISAXErrorHandler* iface)
668 {
669     return 1;
670 }
671
672 static HRESULT WINAPI isaxerrorHandler_error(
673         ISAXErrorHandler* iface,
674         ISAXLocator *pLocator,
675         const WCHAR *pErrorMessage,
676         HRESULT hrErrorCode)
677 {
678     ok(0, "unexpected call\n");
679     return S_OK;
680 }
681
682 static HRESULT WINAPI isaxerrorHandler_fatalError(
683         ISAXErrorHandler* iface,
684         ISAXLocator *pLocator,
685         const WCHAR *pErrorMessage,
686         HRESULT hrErrorCode)
687 {
688     if(!test_expect_call(EH_FATALERROR))
689         return E_FAIL;
690
691     ok(hrErrorCode == expectCall->ret, "hrErrorCode = %x, expected %x\n", hrErrorCode, expectCall->ret);
692
693     expectCall++;
694     return S_OK;
695 }
696
697 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
698         ISAXErrorHandler* iface,
699         ISAXLocator *pLocator,
700         const WCHAR *pErrorMessage,
701         HRESULT hrErrorCode)
702 {
703     ok(0, "unexpected call\n");
704     return S_OK;
705 }
706
707 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
708 {
709     isaxerrorHandler_QueryInterface,
710     isaxerrorHandler_AddRef,
711     isaxerrorHandler_Release,
712     isaxerrorHandler_error,
713     isaxerrorHandler_fatalError,
714     isaxerrorHanddler_ignorableWarning
715 };
716
717 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
718
719 static HRESULT WINAPI isaxattributes_QueryInterface(
720         ISAXAttributes* iface,
721         REFIID riid,
722         void **ppvObject)
723 {
724     *ppvObject = NULL;
725
726     if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
727     {
728         *ppvObject = iface;
729     }
730     else
731     {
732         return E_NOINTERFACE;
733     }
734
735     return S_OK;
736 }
737
738 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
739 {
740     return 2;
741 }
742
743 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
744 {
745     return 1;
746 }
747
748 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
749 {
750     *length = 3;
751     return S_OK;
752 }
753
754 static HRESULT WINAPI isaxattributes_getURI(
755     ISAXAttributes* iface,
756     int nIndex,
757     const WCHAR **pUrl,
758     int *pUriSize)
759 {
760     ok(0, "unexpected call\n");
761     return E_NOTIMPL;
762 }
763
764 static HRESULT WINAPI isaxattributes_getLocalName(
765     ISAXAttributes* iface,
766     int nIndex,
767     const WCHAR **pLocalName,
768     int *pLocalNameLength)
769 {
770     ok(0, "unexpected call\n");
771     return E_NOTIMPL;
772 }
773
774 static HRESULT WINAPI isaxattributes_getQName(
775     ISAXAttributes* iface,
776     int index,
777     const WCHAR **QName,
778     int *QNameLength)
779 {
780     static const WCHAR attrqnamesW[][15] = {{'a',':','a','t','t','r','1','j','u','n','k',0},
781                                             {'a','t','t','r','2','j','u','n','k',0},
782                                             {'a','t','t','r','3',0}};
783     static const int attrqnamelen[] = {7, 5, 5};
784
785     ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
786
787     *QName = attrqnamesW[index];
788     *QNameLength = attrqnamelen[index];
789
790     return S_OK;
791 }
792
793 static HRESULT WINAPI isaxattributes_getName(
794     ISAXAttributes* iface,
795     int nIndex,
796     const WCHAR **pUri,
797     int * pUriLength,
798     const WCHAR ** pLocalName,
799     int * pLocalNameSize,
800     const WCHAR ** pQName,
801     int * pQNameLength)
802 {
803     ok(0, "unexpected call\n");
804     return E_NOTIMPL;
805 }
806
807 static HRESULT WINAPI isaxattributes_getIndexFromName(
808     ISAXAttributes* iface,
809     const WCHAR * pUri,
810     int cUriLength,
811     const WCHAR * pLocalName,
812     int cocalNameLength,
813     int * index)
814 {
815     ok(0, "unexpected call\n");
816     return E_NOTIMPL;
817 }
818
819 static HRESULT WINAPI isaxattributes_getIndexFromQName(
820     ISAXAttributes* iface,
821     const WCHAR * pQName,
822     int nQNameLength,
823     int * index)
824 {
825     ok(0, "unexpected call\n");
826     return E_NOTIMPL;
827 }
828
829 static HRESULT WINAPI isaxattributes_getType(
830     ISAXAttributes* iface,
831     int nIndex,
832     const WCHAR ** pType,
833     int * pTypeLength)
834 {
835     ok(0, "unexpected call\n");
836     return E_NOTIMPL;
837 }
838
839 static HRESULT WINAPI isaxattributes_getTypeFromName(
840     ISAXAttributes* iface,
841     const WCHAR * pUri,
842     int nUri,
843     const WCHAR * pLocalName,
844     int nLocalName,
845     const WCHAR ** pType,
846     int * nType)
847 {
848     ok(0, "unexpected call\n");
849     return E_NOTIMPL;
850 }
851
852 static HRESULT WINAPI isaxattributes_getTypeFromQName(
853     ISAXAttributes* iface,
854     const WCHAR * pQName,
855     int nQName,
856     const WCHAR ** pType,
857     int * nType)
858 {
859     ok(0, "unexpected call\n");
860     return E_NOTIMPL;
861 }
862
863 static HRESULT WINAPI isaxattributes_getValue(ISAXAttributes* iface, int index,
864     const WCHAR **value, int *nValue)
865 {
866     static const WCHAR attrvaluesW[][10] = {{'a','1','j','u','n','k',0},
867                                             {'a','2','j','u','n','k',0},
868                                             {'<','&','"','>',0}};
869     static const int attrvalueslen[] = {2, 2, 4};
870
871     ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
872
873     *value = attrvaluesW[index];
874     *nValue = attrvalueslen[index];
875
876     return S_OK;
877 }
878
879 static HRESULT WINAPI isaxattributes_getValueFromName(
880     ISAXAttributes* iface,
881     const WCHAR * pUri,
882     int nUri,
883     const WCHAR * pLocalName,
884     int nLocalName,
885     const WCHAR ** pValue,
886     int * nValue)
887 {
888     ok(0, "unexpected call\n");
889     return E_NOTIMPL;
890 }
891
892 static HRESULT WINAPI isaxattributes_getValueFromQName(
893     ISAXAttributes* iface,
894     const WCHAR * pQName,
895     int nQName,
896     const WCHAR ** pValue,
897     int * nValue)
898 {
899     ok(0, "unexpected call\n");
900     return E_NOTIMPL;
901 }
902
903 static const ISAXAttributesVtbl SAXAttributesVtbl =
904 {
905     isaxattributes_QueryInterface,
906     isaxattributes_AddRef,
907     isaxattributes_Release,
908     isaxattributes_getLength,
909     isaxattributes_getURI,
910     isaxattributes_getLocalName,
911     isaxattributes_getQName,
912     isaxattributes_getName,
913     isaxattributes_getIndexFromName,
914     isaxattributes_getIndexFromQName,
915     isaxattributes_getType,
916     isaxattributes_getTypeFromName,
917     isaxattributes_getTypeFromQName,
918     isaxattributes_getValue,
919     isaxattributes_getValueFromName,
920     isaxattributes_getValueFromQName
921 };
922
923 static ISAXAttributes saxattributes = { &SAXAttributesVtbl };
924
925 static int handler_addrefcalled;
926
927 static HRESULT WINAPI isaxlexical_QueryInterface(ISAXLexicalHandler* iface, REFIID riid, void **ppvObject)
928 {
929     *ppvObject = NULL;
930
931     if(IsEqualGUID(riid, &IID_IUnknown) ||
932        IsEqualGUID(riid, &IID_ISAXLexicalHandler))
933     {
934         *ppvObject = iface;
935     }
936     else
937     {
938         return E_NOINTERFACE;
939     }
940
941     return S_OK;
942 }
943
944 static ULONG WINAPI isaxlexical_AddRef(ISAXLexicalHandler* iface)
945 {
946     handler_addrefcalled++;
947     return 2;
948 }
949
950 static ULONG WINAPI isaxlexical_Release(ISAXLexicalHandler* iface)
951 {
952     return 1;
953 }
954
955 static HRESULT WINAPI isaxlexical_startDTD(ISAXLexicalHandler* iface,
956     const WCHAR * pName, int nName, const WCHAR * pPublicId,
957     int nPublicId, const WCHAR * pSystemId, int nSystemId)
958 {
959     ok(0, "call not expected\n");
960     return E_NOTIMPL;
961 }
962
963 static HRESULT WINAPI isaxlexical_endDTD(ISAXLexicalHandler* iface)
964 {
965     ok(0, "call not expected\n");
966     return E_NOTIMPL;
967 }
968
969 static HRESULT WINAPI isaxlexical_startEntity(ISAXLexicalHandler *iface,
970     const WCHAR * pName, int nName)
971 {
972     ok(0, "call not expected\n");
973     return E_NOTIMPL;
974 }
975
976 static HRESULT WINAPI isaxlexical_endEntity(ISAXLexicalHandler *iface,
977     const WCHAR * pName, int nName)
978 {
979     ok(0, "call not expected\n");
980     return E_NOTIMPL;
981 }
982
983 static HRESULT WINAPI isaxlexical_startCDATA(ISAXLexicalHandler *iface)
984 {
985     ok(0, "call not expected\n");
986     return E_NOTIMPL;
987 }
988
989 static HRESULT WINAPI isaxlexical_endCDATA(ISAXLexicalHandler *iface)
990 {
991     ok(0, "call not expected\n");
992     return E_NOTIMPL;
993 }
994
995 static HRESULT WINAPI isaxlexical_comment(ISAXLexicalHandler *iface,
996     const WCHAR * pChars, int nChars)
997 {
998     ok(0, "call not expected\n");
999     return E_NOTIMPL;
1000 }
1001
1002 static const ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl =
1003 {
1004    isaxlexical_QueryInterface,
1005    isaxlexical_AddRef,
1006    isaxlexical_Release,
1007    isaxlexical_startDTD,
1008    isaxlexical_endDTD,
1009    isaxlexical_startEntity,
1010    isaxlexical_endEntity,
1011    isaxlexical_startCDATA,
1012    isaxlexical_endCDATA,
1013    isaxlexical_comment
1014 };
1015
1016 static ISAXLexicalHandler saxlexicalhandler = { &SAXLexicalHandlerVtbl };
1017
1018 static HRESULT WINAPI isaxdecl_QueryInterface(ISAXDeclHandler* iface, REFIID riid, void **ppvObject)
1019 {
1020     *ppvObject = NULL;
1021
1022     if(IsEqualGUID(riid, &IID_IUnknown) ||
1023        IsEqualGUID(riid, &IID_ISAXDeclHandler))
1024     {
1025         *ppvObject = iface;
1026     }
1027     else
1028     {
1029         return E_NOINTERFACE;
1030     }
1031
1032     return S_OK;
1033 }
1034
1035 static ULONG WINAPI isaxdecl_AddRef(ISAXDeclHandler* iface)
1036 {
1037     handler_addrefcalled++;
1038     return 2;
1039 }
1040
1041 static ULONG WINAPI isaxdecl_Release(ISAXDeclHandler* iface)
1042 {
1043     return 1;
1044 }
1045
1046 static HRESULT WINAPI isaxdecl_elementDecl(ISAXDeclHandler* iface,
1047     const WCHAR * pName, int nName, const WCHAR * pModel, int nModel)
1048 {
1049     ok(0, "call not expected\n");
1050     return E_NOTIMPL;
1051 }
1052
1053 static HRESULT WINAPI isaxdecl_attributeDecl(ISAXDeclHandler* iface,
1054     const WCHAR * pElementName, int nElementName, const WCHAR * pAttributeName,
1055     int nAttributeName, const WCHAR * pType, int nType, const WCHAR * pValueDefault,
1056     int nValueDefault, const WCHAR * pValue, int nValue)
1057 {
1058     ok(0, "call not expected\n");
1059     return E_NOTIMPL;
1060 }
1061
1062 static HRESULT WINAPI isaxdecl_internalEntityDecl(ISAXDeclHandler* iface,
1063     const WCHAR * pName, int nName, const WCHAR * pValue, int nValue)
1064 {
1065     ok(0, "call not expected\n");
1066     return E_NOTIMPL;
1067 }
1068
1069 static HRESULT WINAPI isaxdecl_externalEntityDecl(ISAXDeclHandler* iface,
1070     const WCHAR * pName, int nName, const WCHAR * pPublicId, int nPublicId,
1071     const WCHAR * pSystemId, int nSystemId)
1072 {
1073     ok(0, "call not expected\n");
1074     return E_NOTIMPL;
1075 }
1076
1077 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl =
1078 {
1079    isaxdecl_QueryInterface,
1080    isaxdecl_AddRef,
1081    isaxdecl_Release,
1082    isaxdecl_elementDecl,
1083    isaxdecl_attributeDecl,
1084    isaxdecl_internalEntityDecl,
1085    isaxdecl_externalEntityDecl
1086 };
1087
1088 static ISAXDeclHandler saxdeclhandler = { &SAXDeclHandlerVtbl };
1089
1090 typedef struct mxwriter_write_test_t {
1091     BOOL        last;
1092     const BYTE  *data;
1093     DWORD       cb;
1094     BOOL        null_written;
1095     BOOL        fail_write;
1096 } mxwriter_write_test;
1097
1098 typedef struct mxwriter_stream_test_t {
1099     VARIANT_BOOL        bom;
1100     const char          *encoding;
1101     mxwriter_write_test expected_writes[4];
1102 } mxwriter_stream_test;
1103
1104 static const mxwriter_write_test *current_write_test;
1105 static DWORD current_stream_test_index;
1106
1107 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
1108 {
1109     *ppvObject = NULL;
1110
1111     if(IsEqualGUID(riid, &IID_IStream) || IsEqualGUID(riid, &IID_IUnknown))
1112         *ppvObject = iface;
1113     else
1114         return E_NOINTERFACE;
1115
1116     return S_OK;
1117 }
1118
1119 static ULONG WINAPI istream_AddRef(IStream *iface)
1120 {
1121     return 2;
1122 }
1123
1124 static ULONG WINAPI istream_Release(IStream *iface)
1125 {
1126     return 1;
1127 }
1128
1129 static HRESULT WINAPI istream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
1130 {
1131     ok(0, "unexpected call\n");
1132     return E_NOTIMPL;
1133 }
1134
1135 static HRESULT WINAPI istream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
1136 {
1137     BOOL fail = FALSE;
1138
1139     ok(pv != NULL, "pv == NULL\n");
1140
1141     if(current_write_test->last) {
1142         ok(0, "Too many Write calls made on test %d\n", current_stream_test_index);
1143         return E_FAIL;
1144     }
1145
1146     fail = current_write_test->fail_write;
1147
1148     ok(current_write_test->cb == cb, "Expected %d, but got %d on test %d\n",
1149         current_write_test->cb, cb, current_stream_test_index);
1150
1151     if(!pcbWritten)
1152         ok(current_write_test->null_written, "pcbWritten was NULL on test %d\n", current_stream_test_index);
1153     else
1154         ok(!memcmp(current_write_test->data, pv, cb), "Unexpected data on test %d\n", current_stream_test_index);
1155
1156     ++current_write_test;
1157
1158     if(pcbWritten)
1159         *pcbWritten = cb;
1160
1161     return fail ? E_FAIL : S_OK;
1162 }
1163
1164 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
1165         ULARGE_INTEGER *plibNewPosition)
1166 {
1167     ok(0, "unexpected call\n");
1168     return E_NOTIMPL;
1169 }
1170
1171 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
1172 {
1173     ok(0, "unexpected call\n");
1174     return E_NOTIMPL;
1175 }
1176
1177 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
1178         ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *plibWritten)
1179 {
1180     ok(0, "unexpected call\n");
1181     return E_NOTIMPL;
1182 }
1183
1184 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD grfCommitFlags)
1185 {
1186     ok(0, "unexpected call\n");
1187     return E_NOTIMPL;
1188 }
1189
1190 static HRESULT WINAPI istream_Revert(IStream *iface)
1191 {
1192     ok(0, "unexpected call\n");
1193     return E_NOTIMPL;
1194 }
1195
1196 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1197         ULARGE_INTEGER cb, DWORD dwLockType)
1198 {
1199     ok(0, "unexpected call\n");
1200     return E_NOTIMPL;
1201 }
1202
1203 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1204         ULARGE_INTEGER cb, DWORD dwLockType)
1205 {
1206     ok(0, "unexpected call\n");
1207     return E_NOTIMPL;
1208 }
1209
1210 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
1211 {
1212     ok(0, "unexpected call\n");
1213     return E_NOTIMPL;
1214 }
1215
1216 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **ppstm)
1217 {
1218     ok(0, "unexpected call\n");
1219     return E_NOTIMPL;
1220 }
1221
1222 static const IStreamVtbl StreamVtbl = {
1223     istream_QueryInterface,
1224     istream_AddRef,
1225     istream_Release,
1226     istream_Read,
1227     istream_Write,
1228     istream_Seek,
1229     istream_SetSize,
1230     istream_CopyTo,
1231     istream_Commit,
1232     istream_Revert,
1233     istream_LockRegion,
1234     istream_UnlockRegion,
1235     istream_Stat,
1236     istream_Clone
1237 };
1238
1239 static IStream mxstream = { &StreamVtbl };
1240
1241 static void test_saxreader(int version)
1242 {
1243     HRESULT hr;
1244     ISAXXMLReader *reader = NULL;
1245     VARIANT var;
1246     ISAXContentHandler *lpContentHandler;
1247     ISAXErrorHandler *lpErrorHandler;
1248     SAFEARRAY *pSA;
1249     SAFEARRAYBOUND SADim[1];
1250     char *pSAData = NULL;
1251     IStream *iStream;
1252     ULARGE_INTEGER liSize;
1253     LARGE_INTEGER liPos;
1254     ULONG bytesWritten;
1255     HANDLE file;
1256     static const CHAR testXmlA[] = "test.xml";
1257     static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1258     IXMLDOMDocument *domDocument;
1259     BSTR bstrData;
1260     VARIANT_BOOL vBool;
1261
1262     msxml_version = version;
1263     if(version == 3) {
1264         hr = CoCreateInstance(&CLSID_SAXXMLReader30, NULL, CLSCTX_INPROC_SERVER,
1265                 &IID_ISAXXMLReader, (LPVOID*)&reader);
1266     } else if(version == 6) {
1267         hr = CoCreateInstance(&CLSID_SAXXMLReader60, NULL, CLSCTX_INPROC_SERVER,
1268                 &IID_ISAXXMLReader, (LPVOID*)&reader);
1269         if(hr == REGDB_E_CLASSNOTREG) {
1270             win_skip("SAXXMLReader6 not registered\n");
1271             return;
1272         }
1273     } else {
1274         hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1275                 &IID_ISAXXMLReader, (LPVOID*)&reader);
1276     }
1277     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1278
1279     if(version != 6) {
1280         hr = ISAXXMLReader_getContentHandler(reader, NULL);
1281         ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1282
1283         hr = ISAXXMLReader_getErrorHandler(reader, NULL);
1284         ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1285     }
1286
1287     hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1288     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1289     ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
1290
1291     hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
1292     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1293     ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
1294
1295     hr = ISAXXMLReader_putContentHandler(reader, NULL);
1296     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1297
1298     hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
1299     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1300
1301     hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
1302     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1303
1304     hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1305     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1306     ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
1307
1308     V_VT(&var) = VT_BSTR;
1309     V_BSTR(&var) = SysAllocString(szSimpleXML);
1310
1311     expectCall = contentHandlerTest1;
1312     hr = ISAXXMLReader_parse(reader, var);
1313     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1314     test_expect_call(CH_ENDTEST);
1315
1316     VariantClear(&var);
1317
1318     SADim[0].lLbound= 0;
1319     SADim[0].cElements= sizeof(szTestXML)-1;
1320     pSA = SafeArrayCreate(VT_UI1, 1, SADim);
1321     SafeArrayAccessData(pSA, (void**)&pSAData);
1322     memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
1323     SafeArrayUnaccessData(pSA);
1324     V_VT(&var) = VT_ARRAY|VT_UI1;
1325     V_ARRAY(&var) = pSA;
1326
1327     expectCall = contentHandlerTest1;
1328     hr = ISAXXMLReader_parse(reader, var);
1329     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1330     test_expect_call(CH_ENDTEST);
1331
1332     SafeArrayDestroy(pSA);
1333
1334     CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1335     liSize.QuadPart = strlen(szTestXML);
1336     IStream_SetSize(iStream, liSize);
1337     IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
1338     liPos.QuadPart = 0;
1339     IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1340     V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1341     V_UNKNOWN(&var) = (IUnknown*)iStream;
1342
1343     expectCall = contentHandlerTest1;
1344     hr = ISAXXMLReader_parse(reader, var);
1345     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1346     test_expect_call(CH_ENDTEST);
1347
1348     IStream_Release(iStream);
1349
1350     CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1351     liSize.QuadPart = strlen(szTestAttributes);
1352     IStream_SetSize(iStream, liSize);
1353     IStream_Write(iStream, szTestAttributes, strlen(szTestAttributes), &bytesWritten);
1354     liPos.QuadPart = 0;
1355     IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1356     V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1357     V_UNKNOWN(&var) = (IUnknown*)iStream;
1358
1359     if(version >= 6)
1360         expectCall = contentHandlerTestAttributes6;
1361     else
1362         expectCall = contentHandlerTestAttributes;
1363     hr = ISAXXMLReader_parse(reader, var);
1364     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1365     test_expect_call(CH_ENDTEST);
1366
1367     IStream_Release(iStream);
1368
1369     V_VT(&var) = VT_BSTR;
1370     V_BSTR(&var) = SysAllocString(szCarriageRetTest);
1371
1372     expectCall = contentHandlerTest2;
1373     hr = ISAXXMLReader_parse(reader, var);
1374     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1375     test_expect_call(CH_ENDTEST);
1376
1377     VariantClear(&var);
1378
1379     file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1380     ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1381     WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
1382     CloseHandle(file);
1383
1384     expectCall = contentHandlerTest1;
1385     hr = ISAXXMLReader_parseURL(reader, testXmlW);
1386     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1387     test_expect_call(CH_ENDTEST);
1388
1389     expectCall = contentHandlerTestError;
1390     hr = ISAXXMLReader_parseURL(reader, testXmlW);
1391     ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1392     test_expect_call(CH_ENDTEST);
1393
1394     if(version >= 6)
1395         expectCall = contentHandlerTestCallbackResult6;
1396     else
1397         expectCall = contentHandlerTestCallbackResults;
1398     hr = ISAXXMLReader_parseURL(reader, testXmlW);
1399     ok(hr == (version>=6 ? S_OK : S_FALSE), "Expected S_FALSE, got %08x\n", hr);
1400     test_expect_call(CH_ENDTEST);
1401
1402     DeleteFileA(testXmlA);
1403
1404     hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
1405             &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
1406     if(FAILED(hr))
1407     {
1408         skip("Failed to create DOMDocument instance\n");
1409         return;
1410     }
1411     bstrData = SysAllocString(szSimpleXML);
1412     hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
1413     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1414     V_VT(&var) = VT_UNKNOWN;
1415     V_UNKNOWN(&var) = (IUnknown*)domDocument;
1416
1417     expectCall = contentHandlerTest2;
1418     hr = ISAXXMLReader_parse(reader, var);
1419     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1420     test_expect_call(CH_ENDTEST);
1421     IXMLDOMDocument_Release(domDocument);
1422
1423     ISAXXMLReader_Release(reader);
1424     SysFreeString(bstrData);
1425 }
1426
1427 struct saxreader_props_test_t
1428 {
1429     const char *prop_name;
1430     IUnknown   *iface;
1431 };
1432
1433 static const struct saxreader_props_test_t props_test_data[] = {
1434     { "http://xml.org/sax/properties/lexical-handler", (IUnknown*)&saxlexicalhandler },
1435     { "http://xml.org/sax/properties/declaration-handler", (IUnknown*)&saxdeclhandler },
1436     { 0 }
1437 };
1438
1439 static void test_saxreader_properties(void)
1440 {
1441     const struct saxreader_props_test_t *ptr = props_test_data;
1442     ISAXXMLReader *reader;
1443     HRESULT hr;
1444
1445     hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1446             &IID_ISAXXMLReader, (void**)&reader);
1447     EXPECT_HR(hr, S_OK);
1448
1449     hr = ISAXXMLReader_getProperty(reader, _bstr_("http://xml.org/sax/properties/lexical-handler"), NULL);
1450     EXPECT_HR(hr, E_POINTER);
1451
1452     while (ptr->prop_name)
1453     {
1454         VARIANT v;
1455
1456         V_VT(&v) = VT_EMPTY;
1457         V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1458         hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1459         EXPECT_HR(hr, S_OK);
1460         ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1461         ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1462
1463         V_VT(&v) = VT_UNKNOWN;
1464         V_UNKNOWN(&v) = ptr->iface;
1465         hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1466         EXPECT_HR(hr, S_OK);
1467
1468         V_VT(&v) = VT_EMPTY;
1469         V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1470         handler_addrefcalled = 0;
1471         hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1472         EXPECT_HR(hr, S_OK);
1473         ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1474         ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1475         ok(handler_addrefcalled == 1, "AddRef called %d times\n", handler_addrefcalled);
1476         VariantClear(&v);
1477
1478         V_VT(&v) = VT_EMPTY;
1479         V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1480         hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1481         EXPECT_HR(hr, S_OK);
1482
1483         V_VT(&v) = VT_EMPTY;
1484         V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1485         hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1486         EXPECT_HR(hr, S_OK);
1487         ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1488         ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1489
1490         V_VT(&v) = VT_UNKNOWN;
1491         V_UNKNOWN(&v) = ptr->iface;
1492         hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1493         EXPECT_HR(hr, S_OK);
1494
1495         /* only VT_EMPTY seems to be valid to reset property */
1496         V_VT(&v) = VT_I4;
1497         V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1498         hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1499         EXPECT_HR(hr, E_INVALIDARG);
1500
1501         V_VT(&v) = VT_EMPTY;
1502         V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1503         hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1504         EXPECT_HR(hr, S_OK);
1505         ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1506         ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1507         VariantClear(&v);
1508
1509         V_VT(&v) = VT_UNKNOWN;
1510         V_UNKNOWN(&v) = NULL;
1511         hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1512         EXPECT_HR(hr, S_OK);
1513
1514         V_VT(&v) = VT_EMPTY;
1515         V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1516         hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1517         EXPECT_HR(hr, S_OK);
1518         ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1519         ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1520
1521         ptr++;
1522     }
1523
1524     ISAXXMLReader_Release(reader);
1525     free_bstrs();
1526 }
1527
1528 struct feature_ns_entry_t {
1529     const GUID *guid;
1530     const char *clsid;
1531     VARIANT_BOOL value;
1532 };
1533
1534 static const struct feature_ns_entry_t feature_ns_entry_data[] = {
1535     { &CLSID_SAXXMLReader,   "CLSID_SAXXMLReader",   VARIANT_TRUE },
1536     { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", VARIANT_TRUE },
1537     { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", VARIANT_TRUE },
1538     { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", VARIANT_TRUE },
1539     { 0 }
1540 };
1541
1542 static void test_saxreader_features(void)
1543 {
1544     const struct feature_ns_entry_t *entry = feature_ns_entry_data;
1545     ISAXXMLReader *reader;
1546
1547     while (entry->guid)
1548     {
1549         VARIANT_BOOL value;
1550         HRESULT hr;
1551
1552         hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1553         if (hr != S_OK)
1554         {
1555             win_skip("can't create %s instance\n", entry->clsid);
1556             entry++;
1557             continue;
1558         }
1559
1560         value = 0xc;
1561         hr = ISAXXMLReader_getFeature(reader, _bstr_("http://xml.org/sax/features/namespaces"), &value);
1562         EXPECT_HR(hr, S_OK);
1563
1564         ok(entry->value == value, "%s: got wrong default value %x, expected %x\n", entry->clsid, value, entry->value);
1565
1566         ISAXXMLReader_Release(reader);
1567
1568         entry++;
1569     }
1570 }
1571
1572 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1573 static const CHAR UTF8BOMTest[] =
1574 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1575 "<a></a>\n";
1576
1577 struct enc_test_entry_t {
1578     const GUID *guid;
1579     const char *clsid;
1580     const char *data;
1581     HRESULT hr;
1582     int todo;
1583 };
1584
1585 static const struct enc_test_entry_t encoding_test_data[] = {
1586     { &CLSID_SAXXMLReader,   "CLSID_SAXXMLReader",   UTF8BOMTest, 0xc00ce56f, 1 },
1587     { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
1588     { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
1589     { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
1590     { 0 }
1591 };
1592
1593 static void test_encoding(void)
1594 {
1595     const struct enc_test_entry_t *entry = encoding_test_data;
1596     static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1597     static const CHAR testXmlA[] = "test.xml";
1598     ISAXXMLReader *reader;
1599     DWORD written;
1600     HANDLE file;
1601     HRESULT hr;
1602
1603     while (entry->guid)
1604     {
1605         hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1606         if (hr != S_OK)
1607         {
1608             win_skip("can't create %s instance\n", entry->clsid);
1609             entry++;
1610             continue;
1611         }
1612
1613         file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1614         ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1615         WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
1616         CloseHandle(file);
1617
1618         hr = ISAXXMLReader_parseURL(reader, testXmlW);
1619         if (entry->todo)
1620             todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1621         else
1622             ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1623
1624         DeleteFileA(testXmlA);
1625         ISAXXMLReader_Release(reader);
1626
1627         entry++;
1628     }
1629 }
1630
1631 static void test_mxwriter_handlers(void)
1632 {
1633     ISAXContentHandler *handler;
1634     IMXWriter *writer, *writer2;
1635     ISAXLexicalHandler *lh;
1636     HRESULT hr;
1637
1638     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1639             &IID_IMXWriter, (void**)&writer);
1640     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1641
1642     EXPECT_REF(writer, 1);
1643
1644     /* ISAXContentHandler */
1645     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
1646     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1647     EXPECT_REF(writer, 2);
1648     EXPECT_REF(handler, 2);
1649
1650     hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
1651     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1652     ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1653     EXPECT_REF(writer, 3);
1654     EXPECT_REF(writer2, 3);
1655     IMXWriter_Release(writer2);
1656     ISAXContentHandler_Release(handler);
1657
1658     /* ISAXLexicalHandler */
1659     hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lh);
1660     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1661     EXPECT_REF(writer, 2);
1662     EXPECT_REF(lh, 2);
1663
1664     hr = ISAXLexicalHandler_QueryInterface(lh, &IID_IMXWriter, (void**)&writer2);
1665     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1666     ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1667     EXPECT_REF(writer, 3);
1668     EXPECT_REF(writer2, 3);
1669     IMXWriter_Release(writer2);
1670
1671     IMXWriter_Release(writer);
1672 }
1673
1674 struct msxmlsupported_data_t
1675 {
1676     const GUID *clsid;
1677     const char *name;
1678     BOOL supported;
1679 };
1680
1681 static struct msxmlsupported_data_t msxmlsupported_data[] =
1682 {
1683     { &CLSID_MXXMLWriter,   "MXXMLWriter" },
1684     { &CLSID_MXXMLWriter30, "MXXMLWriter30" },
1685     { &CLSID_MXXMLWriter40, "MXXMLWriter40" },
1686     { &CLSID_MXXMLWriter60, "MXXMLWriter60" },
1687     { NULL }
1688 };
1689
1690 static BOOL is_mxwriter_supported(const GUID *clsid, const struct msxmlsupported_data_t *table)
1691 {
1692     while (table->clsid)
1693     {
1694         if (table->clsid == clsid) return table->supported;
1695         table++;
1696     }
1697     return FALSE;
1698 }
1699
1700 struct mxwriter_props_t
1701 {
1702     const GUID *clsid;
1703     VARIANT_BOOL bom;
1704     VARIANT_BOOL disable_escape;
1705     VARIANT_BOOL indent;
1706     VARIANT_BOOL omitdecl;
1707     VARIANT_BOOL standalone;
1708     const char *encoding;
1709 };
1710
1711 static const struct mxwriter_props_t mxwriter_default_props[] =
1712 {
1713     { &CLSID_MXXMLWriter,   VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1714     { &CLSID_MXXMLWriter30, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1715     { &CLSID_MXXMLWriter40, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1716     { &CLSID_MXXMLWriter60, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1717     { NULL }
1718 };
1719
1720 static void test_mxwriter_default_properties(const struct mxwriter_props_t *table)
1721 {
1722     int i = 0;
1723
1724     while (table->clsid)
1725     {
1726         IMXWriter *writer;
1727         VARIANT_BOOL b;
1728         BSTR encoding;
1729         HRESULT hr;
1730
1731         if (!is_mxwriter_supported(table->clsid, msxmlsupported_data))
1732         {
1733             table++;
1734             i++;
1735             continue;
1736         }
1737
1738         hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1739             &IID_IMXWriter, (void**)&writer);
1740         EXPECT_HR(hr, S_OK);
1741
1742         b = !table->bom;
1743         hr = IMXWriter_get_byteOrderMark(writer, &b);
1744         EXPECT_HR(hr, S_OK);
1745         ok(table->bom == b, "test %d: got BOM %d, expected %d\n", i, b, table->bom);
1746
1747         b = !table->disable_escape;
1748         hr = IMXWriter_get_disableOutputEscaping(writer, &b);
1749         EXPECT_HR(hr, S_OK);
1750         ok(table->disable_escape == b, "test %d: got disable escape %d, expected %d\n", i, b,
1751            table->disable_escape);
1752
1753         b = !table->indent;
1754         hr = IMXWriter_get_indent(writer, &b);
1755         EXPECT_HR(hr, S_OK);
1756         ok(table->indent == b, "test %d: got indent %d, expected %d\n", i, b, table->indent);
1757
1758         b = !table->omitdecl;
1759         hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
1760         EXPECT_HR(hr, S_OK);
1761         ok(table->omitdecl == b, "test %d: got omitdecl %d, expected %d\n", i, b, table->omitdecl);
1762
1763         b = !table->standalone;
1764         hr = IMXWriter_get_standalone(writer, &b);
1765         EXPECT_HR(hr, S_OK);
1766         ok(table->standalone == b, "test %d: got standalone %d, expected %d\n", i, b, table->standalone);
1767
1768         hr = IMXWriter_get_encoding(writer, &encoding);
1769         EXPECT_HR(hr, S_OK);
1770         ok(!lstrcmpW(encoding, _bstr_(table->encoding)), "test %d: got encoding %s, expected %s\n",
1771             i, wine_dbgstr_w(encoding), table->encoding);
1772         SysFreeString(encoding);
1773
1774         IMXWriter_Release(writer);
1775
1776         table++;
1777         i++;
1778     }
1779 }
1780
1781 static void test_mxwriter_properties(void)
1782 {
1783     static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
1784     static const WCHAR emptyW[] = {0};
1785     static const WCHAR testW[] = {'t','e','s','t',0};
1786     ISAXContentHandler *content;
1787     IMXWriter *writer;
1788     VARIANT_BOOL b;
1789     HRESULT hr;
1790     BSTR str, str2;
1791     VARIANT dest;
1792
1793     test_mxwriter_default_properties(mxwriter_default_props);
1794
1795     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1796             &IID_IMXWriter, (void**)&writer);
1797     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1798
1799     hr = IMXWriter_get_disableOutputEscaping(writer, NULL);
1800     ok(hr == E_POINTER, "got %08x\n", hr);
1801
1802     hr = IMXWriter_get_byteOrderMark(writer, NULL);
1803     ok(hr == E_POINTER, "got %08x\n", hr);
1804
1805     hr = IMXWriter_get_indent(writer, NULL);
1806     ok(hr == E_POINTER, "got %08x\n", hr);
1807
1808     hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
1809     ok(hr == E_POINTER, "got %08x\n", hr);
1810
1811     hr = IMXWriter_get_standalone(writer, NULL);
1812     ok(hr == E_POINTER, "got %08x\n", hr);
1813
1814     /* set and check */
1815     hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
1816     ok(hr == S_OK, "got %08x\n", hr);
1817
1818     b = VARIANT_FALSE;
1819     hr = IMXWriter_get_standalone(writer, &b);
1820     ok(hr == S_OK, "got %08x\n", hr);
1821     ok(b == VARIANT_TRUE, "got %d\n", b);
1822
1823     hr = IMXWriter_get_encoding(writer, NULL);
1824     EXPECT_HR(hr, E_POINTER);
1825
1826     /* UTF-16 is a default setting apparently */
1827     str = (void*)0xdeadbeef;
1828     hr = IMXWriter_get_encoding(writer, &str);
1829     EXPECT_HR(hr, S_OK);
1830     ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1831
1832     str2 = (void*)0xdeadbeef;
1833     hr = IMXWriter_get_encoding(writer, &str2);
1834     ok(hr == S_OK, "got %08x\n", hr);
1835     ok(str != str2, "expected newly allocated, got same %p\n", str);
1836
1837     SysFreeString(str2);
1838     SysFreeString(str);
1839
1840     /* put empty string */
1841     str = SysAllocString(emptyW);
1842     hr = IMXWriter_put_encoding(writer, str);
1843     ok(hr == E_INVALIDARG, "got %08x\n", hr);
1844     SysFreeString(str);
1845
1846     str = (void*)0xdeadbeef;
1847     hr = IMXWriter_get_encoding(writer, &str);
1848     EXPECT_HR(hr, S_OK);
1849     ok(!lstrcmpW(str, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(str));
1850     SysFreeString(str);
1851
1852     /* invalid encoding name */
1853     str = SysAllocString(testW);
1854     hr = IMXWriter_put_encoding(writer, str);
1855     ok(hr == E_INVALIDARG, "got %08x\n", hr);
1856     SysFreeString(str);
1857
1858     /* test case sensivity */
1859     hr = IMXWriter_put_encoding(writer, _bstr_("utf-8"));
1860     EXPECT_HR(hr, S_OK);
1861     str = (void*)0xdeadbeef;
1862     hr = IMXWriter_get_encoding(writer, &str);
1863     EXPECT_HR(hr, S_OK);
1864     ok(!lstrcmpW(str, _bstr_("utf-8")), "got %s\n", wine_dbgstr_w(str));
1865     SysFreeString(str);
1866
1867     hr = IMXWriter_put_encoding(writer, _bstr_("uTf-16"));
1868     EXPECT_HR(hr, S_OK);
1869     str = (void*)0xdeadbeef;
1870     hr = IMXWriter_get_encoding(writer, &str);
1871     EXPECT_HR(hr, S_OK);
1872     ok(!lstrcmpW(str, _bstr_("uTf-16")), "got %s\n", wine_dbgstr_w(str));
1873     SysFreeString(str);
1874
1875     /* how it affects document creation */
1876     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1877     EXPECT_HR(hr, S_OK);
1878
1879     hr = ISAXContentHandler_startDocument(content);
1880     EXPECT_HR(hr, S_OK);
1881     hr = ISAXContentHandler_endDocument(content);
1882     EXPECT_HR(hr, S_OK);
1883
1884     V_VT(&dest) = VT_EMPTY;
1885     hr = IMXWriter_get_output(writer, &dest);
1886     EXPECT_HR(hr, S_OK);
1887     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1888     ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\"?>\r\n"),
1889         V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1890     VariantClear(&dest);
1891     ISAXContentHandler_Release(content);
1892
1893     hr = IMXWriter_get_version(writer, NULL);
1894     ok(hr == E_POINTER, "got %08x\n", hr);
1895     /* default version is 'surprisingly' 1.0 */
1896     hr = IMXWriter_get_version(writer, &str);
1897     ok(hr == S_OK, "got %08x\n", hr);
1898     ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1899     SysFreeString(str);
1900
1901     /* store version string as is */
1902     hr = IMXWriter_put_version(writer, NULL);
1903     ok(hr == E_INVALIDARG, "got %08x\n", hr);
1904
1905     hr = IMXWriter_put_version(writer, _bstr_("1.0"));
1906     ok(hr == S_OK, "got %08x\n", hr);
1907
1908     hr = IMXWriter_put_version(writer, _bstr_(""));
1909     ok(hr == S_OK, "got %08x\n", hr);
1910     hr = IMXWriter_get_version(writer, &str);
1911     ok(hr == S_OK, "got %08x\n", hr);
1912     ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
1913     SysFreeString(str);
1914
1915     hr = IMXWriter_put_version(writer, _bstr_("a.b"));
1916     ok(hr == S_OK, "got %08x\n", hr);
1917     hr = IMXWriter_get_version(writer, &str);
1918     ok(hr == S_OK, "got %08x\n", hr);
1919     ok(!lstrcmpW(str, _bstr_("a.b")), "got %s\n", wine_dbgstr_w(str));
1920     SysFreeString(str);
1921
1922     hr = IMXWriter_put_version(writer, _bstr_("2.0"));
1923     ok(hr == S_OK, "got %08x\n", hr);
1924     hr = IMXWriter_get_version(writer, &str);
1925     ok(hr == S_OK, "got %08x\n", hr);
1926     ok(!lstrcmpW(str, _bstr_("2.0")), "got %s\n", wine_dbgstr_w(str));
1927     SysFreeString(str);
1928
1929     IMXWriter_Release(writer);
1930     free_bstrs();
1931 }
1932
1933 static void test_mxwriter_flush(void)
1934 {
1935     ISAXContentHandler *content;
1936     IMXWriter *writer;
1937     LARGE_INTEGER pos;
1938     ULARGE_INTEGER pos2;
1939     IStream *stream;
1940     VARIANT dest;
1941     HRESULT hr;
1942
1943     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1944             &IID_IMXWriter, (void**)&writer);
1945     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1946
1947     hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1948     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1949     EXPECT_REF(stream, 1);
1950
1951     /* detach when nothing was attached */
1952     V_VT(&dest) = VT_EMPTY;
1953     hr = IMXWriter_put_output(writer, dest);
1954     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1955
1956     /* attach stream */
1957     V_VT(&dest) = VT_UNKNOWN;
1958     V_UNKNOWN(&dest) = (IUnknown*)stream;
1959     hr = IMXWriter_put_output(writer, dest);
1960     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1961     todo_wine EXPECT_REF(stream, 3);
1962
1963     /* detach setting VT_EMPTY destination */
1964     V_VT(&dest) = VT_EMPTY;
1965     hr = IMXWriter_put_output(writer, dest);
1966     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1967     EXPECT_REF(stream, 1);
1968
1969     V_VT(&dest) = VT_UNKNOWN;
1970     V_UNKNOWN(&dest) = (IUnknown*)stream;
1971     hr = IMXWriter_put_output(writer, dest);
1972     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1973
1974     /* flush() doesn't detach a stream */
1975     hr = IMXWriter_flush(writer);
1976     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1977     todo_wine EXPECT_REF(stream, 3);
1978
1979     pos.QuadPart = 0;
1980     hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1981     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1982     ok(pos2.QuadPart == 0, "expected stream beginning\n");
1983
1984     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1985     ok(hr == S_OK, "got %08x\n", hr);
1986
1987     hr = ISAXContentHandler_startDocument(content);
1988     ok(hr == S_OK, "got %08x\n", hr);
1989
1990     pos.QuadPart = 0;
1991     hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1992     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1993     ok(pos2.QuadPart != 0, "expected stream beginning\n");
1994
1995     /* already started */
1996     hr = ISAXContentHandler_startDocument(content);
1997     ok(hr == S_OK, "got %08x\n", hr);
1998
1999     hr = ISAXContentHandler_endDocument(content);
2000     ok(hr == S_OK, "got %08x\n", hr);
2001
2002     /* flushed on endDocument() */
2003     pos.QuadPart = 0;
2004     hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2005     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2006     ok(pos2.QuadPart != 0, "expected stream position moved\n");
2007
2008     ISAXContentHandler_Release(content);
2009     IStream_Release(stream);
2010     IMXWriter_Release(writer);
2011 }
2012
2013 static void test_mxwriter_startenddocument(void)
2014 {
2015     ISAXContentHandler *content;
2016     IMXWriter *writer;
2017     VARIANT dest;
2018     HRESULT hr;
2019
2020     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2021             &IID_IMXWriter, (void**)&writer);
2022     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2023
2024     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2025     ok(hr == S_OK, "got %08x\n", hr);
2026
2027     hr = ISAXContentHandler_startDocument(content);
2028     ok(hr == S_OK, "got %08x\n", hr);
2029
2030     hr = ISAXContentHandler_endDocument(content);
2031     ok(hr == S_OK, "got %08x\n", hr);
2032
2033     V_VT(&dest) = VT_EMPTY;
2034     hr = IMXWriter_get_output(writer, &dest);
2035     ok(hr == S_OK, "got %08x\n", hr);
2036     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2037     ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2038         "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2039     VariantClear(&dest);
2040
2041     /* now try another startDocument */
2042     hr = ISAXContentHandler_startDocument(content);
2043     ok(hr == S_OK, "got %08x\n", hr);
2044     /* and get duplicated prolog */
2045     V_VT(&dest) = VT_EMPTY;
2046     hr = IMXWriter_get_output(writer, &dest);
2047     ok(hr == S_OK, "got %08x\n", hr);
2048     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2049     ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
2050                         "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2051         "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2052     VariantClear(&dest);
2053
2054     ISAXContentHandler_Release(content);
2055     IMXWriter_Release(writer);
2056
2057     /* now with omitted declaration */
2058     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2059             &IID_IMXWriter, (void**)&writer);
2060     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2061
2062     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2063     ok(hr == S_OK, "got %08x\n", hr);
2064
2065     hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2066     ok(hr == S_OK, "got %08x\n", hr);
2067
2068     hr = ISAXContentHandler_startDocument(content);
2069     ok(hr == S_OK, "got %08x\n", hr);
2070
2071     hr = ISAXContentHandler_endDocument(content);
2072     ok(hr == S_OK, "got %08x\n", hr);
2073
2074     V_VT(&dest) = VT_EMPTY;
2075     hr = IMXWriter_get_output(writer, &dest);
2076     ok(hr == S_OK, "got %08x\n", hr);
2077     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2078     ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2079     VariantClear(&dest);
2080
2081     ISAXContentHandler_Release(content);
2082     IMXWriter_Release(writer);
2083
2084     free_bstrs();
2085 }
2086
2087 enum startendtype
2088 {
2089     StartElement,
2090     EndElement,
2091     StartEndElement
2092 };
2093
2094 struct writer_startendelement_t {
2095     const GUID *clsid;
2096     enum startendtype type;
2097     const char *uri;
2098     const char *local_name;
2099     const char *qname;
2100     const char *output;
2101     HRESULT hr;
2102     ISAXAttributes *attr;
2103 };
2104
2105 static const char startelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"&lt;&amp;&quot;&gt;\">";
2106 static const char startendelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"&lt;&amp;&quot;&gt;\"/>";
2107
2108 static const struct writer_startendelement_t writer_startendelement[] = {
2109     /* 0 */
2110     { &CLSID_MXXMLWriter,   StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2111     { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2112     { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2113     { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, NULL, "<>", S_OK },
2114     { &CLSID_MXXMLWriter,   StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2115     /* 5 */
2116     { &CLSID_MXXMLWriter30, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2117     { &CLSID_MXXMLWriter40, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2118     { &CLSID_MXXMLWriter60, StartElement, "uri", NULL, NULL, "<>", S_OK },
2119     { &CLSID_MXXMLWriter,   StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2120     { &CLSID_MXXMLWriter30, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2121     /* 10 */
2122     { &CLSID_MXXMLWriter40, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2123     { &CLSID_MXXMLWriter60, StartElement, NULL, "local", NULL, "<>", S_OK },
2124     { &CLSID_MXXMLWriter,   StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2125     { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2126     { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2127     /* 15 */
2128     { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, "qname", "<qname>", S_OK },
2129     { &CLSID_MXXMLWriter,   StartElement, "uri", "local", "qname", "<qname>", S_OK },
2130     { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2131     { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2132     { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2133     /* 20 */
2134     { &CLSID_MXXMLWriter,   StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2135     { &CLSID_MXXMLWriter30, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2136     { &CLSID_MXXMLWriter40, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2137     { &CLSID_MXXMLWriter60, StartElement, "uri", "local", NULL, "<>", S_OK },
2138     { &CLSID_MXXMLWriter,   StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2139     /* 25 */
2140     { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2141     { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2142     { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2143     { &CLSID_MXXMLWriter,   StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2144     { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2145     /* 30 */
2146     { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2147     { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2148     /* endElement tests */
2149     { &CLSID_MXXMLWriter,   EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2150     { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2151     { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2152     /* 35 */
2153     { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, NULL, "</>", S_OK },
2154     { &CLSID_MXXMLWriter,   EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2155     { &CLSID_MXXMLWriter30, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2156     { &CLSID_MXXMLWriter40, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2157     { &CLSID_MXXMLWriter60, EndElement, "uri", NULL, NULL, "</>", S_OK },
2158     /* 40 */
2159     { &CLSID_MXXMLWriter,   EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2160     { &CLSID_MXXMLWriter30, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2161     { &CLSID_MXXMLWriter40, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2162     { &CLSID_MXXMLWriter60, EndElement, NULL, "local", NULL, "</>", S_OK },
2163     { &CLSID_MXXMLWriter,   EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2164     /* 45 */
2165     { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2166     { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2167     { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, "qname", "</qname>", S_OK },
2168     { &CLSID_MXXMLWriter,   EndElement, "uri", "local", "qname", "</qname>", S_OK },
2169     { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2170     /* 50 */
2171     { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2172     { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2173     { &CLSID_MXXMLWriter,   EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2174     { &CLSID_MXXMLWriter30, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2175     { &CLSID_MXXMLWriter40, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2176     /* 55 */
2177     { &CLSID_MXXMLWriter60, EndElement, "uri", "local", NULL, "</>", S_OK },
2178     { &CLSID_MXXMLWriter,   EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2179     { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2180     { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2181     { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2182     /* 60 */
2183     { &CLSID_MXXMLWriter,   EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2184     { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2185     { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2186     { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2187
2188     /* with attributes */
2189     { &CLSID_MXXMLWriter,   StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2190     /* 65 */
2191     { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2192     { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2193     { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2194     /* empty elements */
2195     { &CLSID_MXXMLWriter,   StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2196     { &CLSID_MXXMLWriter30, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2197     /* 70 */
2198     { &CLSID_MXXMLWriter40, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2199     { &CLSID_MXXMLWriter60, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2200     { &CLSID_MXXMLWriter,   StartEndElement, "", "", "", "</>", S_OK },
2201     { &CLSID_MXXMLWriter30, StartEndElement, "", "", "", "</>", S_OK },
2202     { &CLSID_MXXMLWriter40, StartEndElement, "", "", "", "</>", S_OK },
2203     /* 75 */
2204     { &CLSID_MXXMLWriter60, StartEndElement, "", "", "", "</>", S_OK },
2205     { NULL }
2206 };
2207
2208 static void get_supported_mxwriter_data(struct msxmlsupported_data_t *table)
2209 {
2210     while (table->clsid)
2211     {
2212         IMXWriter *writer;
2213         HRESULT hr;
2214
2215         hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2216             &IID_IMXWriter, (void**)&writer);
2217         if (hr == S_OK) IMXWriter_Release(writer);
2218
2219         table->supported = hr == S_OK;
2220         if (hr != S_OK) win_skip("class %s not supported\n", table->name);
2221
2222         table++;
2223     }
2224 }
2225
2226 static void test_mxwriter_startendelement_batch(const struct writer_startendelement_t *table)
2227 {
2228     int i = 0;
2229
2230     while (table->clsid)
2231     {
2232         ISAXContentHandler *content;
2233         IMXWriter *writer;
2234         HRESULT hr;
2235
2236         if (!is_mxwriter_supported(table->clsid, msxmlsupported_data))
2237         {
2238             table++;
2239             i++;
2240             continue;
2241         }
2242
2243         hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2244             &IID_IMXWriter, (void**)&writer);
2245         EXPECT_HR(hr, S_OK);
2246
2247         hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2248         EXPECT_HR(hr, S_OK);
2249
2250         hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2251         EXPECT_HR(hr, S_OK);
2252
2253         hr = ISAXContentHandler_startDocument(content);
2254         EXPECT_HR(hr, S_OK);
2255
2256         if (table->type == StartElement)
2257         {
2258             hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2259                 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2260             ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2261         }
2262         else if (table->type == EndElement)
2263         {
2264             hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2265                 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2266             ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2267         }
2268         else
2269         {
2270             hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2271                 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2272             ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2273             hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2274                 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2275             ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2276         }
2277
2278         /* test output */
2279         if (hr == S_OK)
2280         {
2281             VARIANT dest;
2282
2283             V_VT(&dest) = VT_EMPTY;
2284             hr = IMXWriter_get_output(writer, &dest);
2285             EXPECT_HR(hr, S_OK);
2286             ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2287             ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
2288                 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
2289             VariantClear(&dest);
2290         }
2291
2292         ISAXContentHandler_Release(content);
2293         IMXWriter_Release(writer);
2294
2295         table++;
2296         i++;
2297     }
2298
2299     free_bstrs();
2300 }
2301
2302 static void test_mxwriter_startendelement(void)
2303 {
2304     ISAXContentHandler *content;
2305     IMXWriter *writer;
2306     VARIANT dest;
2307     HRESULT hr;
2308
2309     test_mxwriter_startendelement_batch(writer_startendelement);
2310
2311     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2312             &IID_IMXWriter, (void**)&writer);
2313     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2314
2315     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2316     ok(hr == S_OK, "got %08x\n", hr);
2317
2318     hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2319     ok(hr == S_OK, "got %08x\n", hr);
2320
2321     hr = ISAXContentHandler_startDocument(content);
2322     ok(hr == S_OK, "got %08x\n", hr);
2323
2324     /* all string pointers should be not null */
2325     hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
2326     ok(hr == S_OK, "got %08x\n", hr);
2327
2328     V_VT(&dest) = VT_EMPTY;
2329     hr = IMXWriter_get_output(writer, &dest);
2330     ok(hr == S_OK, "got %08x\n", hr);
2331     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2332     ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2333     VariantClear(&dest);
2334
2335     hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
2336     ok(hr == S_OK, "got %08x\n", hr);
2337
2338     V_VT(&dest) = VT_EMPTY;
2339     hr = IMXWriter_get_output(writer, &dest);
2340     ok(hr == S_OK, "got %08x\n", hr);
2341     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2342     ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2343     VariantClear(&dest);
2344
2345     hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
2346     EXPECT_HR(hr, E_INVALIDARG);
2347
2348     hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
2349     EXPECT_HR(hr, E_INVALIDARG);
2350
2351     /* only local name is an error too */
2352     hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
2353     EXPECT_HR(hr, E_INVALIDARG);
2354
2355     hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
2356     EXPECT_HR(hr, S_OK);
2357
2358     V_VT(&dest) = VT_EMPTY;
2359     hr = IMXWriter_get_output(writer, &dest);
2360     EXPECT_HR(hr, S_OK);
2361     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2362     ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2363     VariantClear(&dest);
2364
2365     hr = ISAXContentHandler_endDocument(content);
2366     EXPECT_HR(hr, S_OK);
2367
2368     V_VT(&dest) = VT_EMPTY;
2369     hr = IMXWriter_put_output(writer, dest);
2370     EXPECT_HR(hr, S_OK);
2371
2372     V_VT(&dest) = VT_EMPTY;
2373     hr = IMXWriter_get_output(writer, &dest);
2374     EXPECT_HR(hr, S_OK);
2375     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2376     ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2377     VariantClear(&dest);
2378
2379     hr = ISAXContentHandler_startDocument(content);
2380     EXPECT_HR(hr, S_OK);
2381
2382     hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abcdef"), 3, NULL);
2383     EXPECT_HR(hr, S_OK);
2384
2385     V_VT(&dest) = VT_EMPTY;
2386     hr = IMXWriter_get_output(writer, &dest);
2387     EXPECT_HR(hr, S_OK);
2388     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2389     ok(!lstrcmpW(_bstr_("<abc>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2390     VariantClear(&dest);
2391
2392     ISAXContentHandler_endDocument(content);
2393     IMXWriter_flush(writer);
2394
2395     hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abdcdef"), 3);
2396     EXPECT_HR(hr, S_OK);
2397     V_VT(&dest) = VT_EMPTY;
2398     hr = IMXWriter_get_output(writer, &dest);
2399     EXPECT_HR(hr, S_OK);
2400     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2401     ok(!lstrcmpW(_bstr_("<abc></abd>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2402     VariantClear(&dest);
2403
2404     ISAXContentHandler_Release(content);
2405     IMXWriter_Release(writer);
2406     free_bstrs();
2407 }
2408
2409 static void test_mxwriter_characters(void)
2410 {
2411     static const WCHAR chardataW[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
2412     ISAXContentHandler *content;
2413     IMXWriter *writer;
2414     VARIANT dest;
2415     HRESULT hr;
2416
2417     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2418             &IID_IMXWriter, (void**)&writer);
2419     EXPECT_HR(hr, S_OK);
2420
2421     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2422     EXPECT_HR(hr, S_OK);
2423
2424     hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2425     EXPECT_HR(hr, S_OK);
2426
2427     hr = ISAXContentHandler_startDocument(content);
2428     EXPECT_HR(hr, S_OK);
2429
2430     hr = ISAXContentHandler_characters(content, NULL, 0);
2431     EXPECT_HR(hr, E_INVALIDARG);
2432
2433     hr = ISAXContentHandler_characters(content, chardataW, 0);
2434     EXPECT_HR(hr, S_OK);
2435
2436     hr = ISAXContentHandler_characters(content, chardataW, sizeof(chardataW)/sizeof(WCHAR) - 1);
2437     EXPECT_HR(hr, S_OK);
2438
2439     V_VT(&dest) = VT_EMPTY;
2440     hr = IMXWriter_get_output(writer, &dest);
2441     EXPECT_HR(hr, S_OK);
2442     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2443     ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2444     VariantClear(&dest);
2445
2446     hr = ISAXContentHandler_endDocument(content);
2447     EXPECT_HR(hr, S_OK);
2448
2449     ISAXContentHandler_Release(content);
2450     IMXWriter_Release(writer);
2451
2452     /* try empty characters data to see if element is closed */
2453     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2454             &IID_IMXWriter, (void**)&writer);
2455     EXPECT_HR(hr, S_OK);
2456
2457     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2458     EXPECT_HR(hr, S_OK);
2459
2460     hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2461     EXPECT_HR(hr, S_OK);
2462
2463     hr = ISAXContentHandler_startDocument(content);
2464     EXPECT_HR(hr, S_OK);
2465
2466     hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2467     EXPECT_HR(hr, S_OK);
2468
2469     hr = ISAXContentHandler_characters(content, chardataW, 0);
2470     EXPECT_HR(hr, S_OK);
2471
2472     hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2473     EXPECT_HR(hr, S_OK);
2474
2475     V_VT(&dest) = VT_EMPTY;
2476     hr = IMXWriter_get_output(writer, &dest);
2477     EXPECT_HR(hr, S_OK);
2478     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2479     ok(!lstrcmpW(_bstr_("<a></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2480     VariantClear(&dest);
2481
2482     ISAXContentHandler_Release(content);
2483     IMXWriter_Release(writer);
2484
2485     free_bstrs();
2486 }
2487
2488 static const mxwriter_stream_test mxwriter_stream_tests[] = {
2489     {
2490         VARIANT_TRUE,"UTF-16",
2491         {
2492             {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2493             {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2494             {TRUE}
2495         }
2496     },
2497     {
2498         VARIANT_FALSE,"UTF-16",
2499         {
2500             {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2501             {TRUE}
2502         }
2503     },
2504     {
2505         VARIANT_TRUE,"UTF-8",
2506         {
2507             {FALSE,(const BYTE*)szUtf8XML,sizeof(szUtf8XML)-1},
2508             /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2509              * and the writer is released.
2510              */
2511             {FALSE,NULL,0},
2512             {TRUE}
2513         }
2514     },
2515     {
2516         VARIANT_TRUE,"utf-8",
2517         {
2518             {FALSE,(const BYTE*)utf8xml2,sizeof(utf8xml2)-1},
2519             /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2520              * and the writer is released.
2521              */
2522             {FALSE,NULL,0},
2523             {TRUE}
2524         }
2525     },
2526     {
2527         VARIANT_TRUE,"UTF-16",
2528         {
2529             {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2530             {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2531             {TRUE}
2532         }
2533     },
2534     {
2535         VARIANT_TRUE,"UTF-16",
2536         {
2537             {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE,TRUE},
2538             {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2539             {TRUE}
2540         }
2541     }
2542 };
2543
2544 static void test_mxwriter_stream(void)
2545 {
2546     IMXWriter *writer;
2547     ISAXContentHandler *content;
2548     HRESULT hr;
2549     VARIANT dest;
2550     IStream *stream;
2551     LARGE_INTEGER pos;
2552     ULARGE_INTEGER pos2;
2553     DWORD test_count = sizeof(mxwriter_stream_tests)/sizeof(mxwriter_stream_tests[0]);
2554
2555     for(current_stream_test_index = 0; current_stream_test_index < test_count; ++current_stream_test_index) {
2556         const mxwriter_stream_test *test = mxwriter_stream_tests+current_stream_test_index;
2557
2558         hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2559                 &IID_IMXWriter, (void**)&writer);
2560         ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2561
2562         hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2563         ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2564
2565         hr = IMXWriter_put_encoding(writer, _bstr_(test->encoding));
2566         ok(hr == S_OK, "put_encoding failed with %08x on test %d\n", hr, current_stream_test_index);
2567
2568         V_VT(&dest) = VT_UNKNOWN;
2569         V_UNKNOWN(&dest) = (IUnknown*)&mxstream;
2570         hr = IMXWriter_put_output(writer, dest);
2571         ok(hr == S_OK, "put_output failed with %08x on test %d\n", hr, current_stream_test_index);
2572         VariantClear(&dest);
2573
2574         hr = IMXWriter_put_byteOrderMark(writer, test->bom);
2575         ok(hr == S_OK, "put_byteOrderMark failed with %08x on test %d\n", hr, current_stream_test_index);
2576
2577         current_write_test = test->expected_writes;
2578
2579         hr = ISAXContentHandler_startDocument(content);
2580         ok(hr == S_OK, "startDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2581
2582         hr = ISAXContentHandler_endDocument(content);
2583         ok(hr == S_OK, "endDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2584
2585         ISAXContentHandler_Release(content);
2586         IMXWriter_Release(writer);
2587
2588         ok(current_write_test->last, "The last %d write calls on test %d were missed\n",
2589             (int)(current_write_test-test->expected_writes), current_stream_test_index);
2590     }
2591
2592     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2593             &IID_IMXWriter, (void**)&writer);
2594     ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2595
2596     hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2597     ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
2598
2599     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2600     ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2601
2602     hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2603     ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
2604
2605     V_VT(&dest) = VT_UNKNOWN;
2606     V_UNKNOWN(&dest) = (IUnknown*)stream;
2607     hr = IMXWriter_put_output(writer, dest);
2608     ok(hr == S_OK, "put_output failed: %08x\n", hr);
2609
2610     hr = ISAXContentHandler_startDocument(content);
2611     ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2612
2613     /* Setting output of the mxwriter causes the current output to be flushed,
2614      * and the writer to start over.
2615      */
2616     V_VT(&dest) = VT_EMPTY;
2617     hr = IMXWriter_put_output(writer, dest);
2618     ok(hr == S_OK, "put_output failed: %08x\n", hr);
2619
2620     pos.QuadPart = 0;
2621     hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2622     ok(hr == S_OK, "Seek failed: %08x\n", hr);
2623     ok(pos2.QuadPart != 0, "expected stream position moved\n");
2624
2625     hr = ISAXContentHandler_startDocument(content);
2626     ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2627
2628     hr = ISAXContentHandler_endDocument(content);
2629     ok(hr == S_OK, "endDocument failed: %08x\n", hr);
2630
2631     V_VT(&dest) = VT_EMPTY;
2632     hr = IMXWriter_get_output(writer, &dest);
2633     ok(hr == S_OK, "get_output failed: %08x\n", hr);
2634     ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2635     ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2636             "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2637     VariantClear(&dest);
2638
2639     /* test when BOM is written to output stream */
2640     V_VT(&dest) = VT_EMPTY;
2641     hr = IMXWriter_put_output(writer, dest);
2642     EXPECT_HR(hr, S_OK);
2643
2644     pos.QuadPart = 0;
2645     hr = IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
2646     EXPECT_HR(hr, S_OK);
2647
2648     V_VT(&dest) = VT_UNKNOWN;
2649     V_UNKNOWN(&dest) = (IUnknown*)stream;
2650     hr = IMXWriter_put_output(writer, dest);
2651     EXPECT_HR(hr, S_OK);
2652
2653     hr = IMXWriter_put_byteOrderMark(writer, VARIANT_TRUE);
2654     EXPECT_HR(hr, S_OK);
2655
2656     hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2657     EXPECT_HR(hr, S_OK);
2658
2659     hr = ISAXContentHandler_startDocument(content);
2660     EXPECT_HR(hr, S_OK);
2661
2662     pos.QuadPart = 0;
2663     pos2.QuadPart = 0;
2664     hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2665     EXPECT_HR(hr, S_OK);
2666     ok(pos2.QuadPart == 2, "got wrong position\n");
2667
2668     ISAXContentHandler_Release(content);
2669     IMXWriter_Release(writer);
2670
2671     free_bstrs();
2672 }
2673
2674 static void test_mxwriter_encoding(void)
2675 {
2676     ISAXContentHandler *content;
2677     IMXWriter *writer;
2678     IStream *stream;
2679     VARIANT dest;
2680     HRESULT hr;
2681     HGLOBAL g;
2682     char *ptr;
2683     BSTR s;
2684
2685     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2686             &IID_IMXWriter, (void**)&writer);
2687     EXPECT_HR(hr, S_OK);
2688
2689     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2690     EXPECT_HR(hr, S_OK);
2691
2692     hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2693     EXPECT_HR(hr, S_OK);
2694
2695     hr = ISAXContentHandler_startDocument(content);
2696     EXPECT_HR(hr, S_OK);
2697
2698     hr = ISAXContentHandler_endDocument(content);
2699     EXPECT_HR(hr, S_OK);
2700
2701     /* The content is always re-encoded to UTF-16 when the output is
2702      * retrieved as a BSTR.
2703      */
2704     V_VT(&dest) = VT_EMPTY;
2705     hr = IMXWriter_get_output(writer, &dest);
2706     EXPECT_HR(hr, S_OK);
2707     ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2708     ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2709             "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2710     VariantClear(&dest);
2711
2712     /* switch encoding when something is written already */
2713     hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2714     EXPECT_HR(hr, S_OK);
2715
2716     V_VT(&dest) = VT_UNKNOWN;
2717     V_UNKNOWN(&dest) = (IUnknown*)stream;
2718     hr = IMXWriter_put_output(writer, dest);
2719     EXPECT_HR(hr, S_OK);
2720
2721     hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2722     EXPECT_HR(hr, S_OK);
2723
2724     /* write empty element */
2725     hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2726     EXPECT_HR(hr, S_OK);
2727
2728     hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2729     EXPECT_HR(hr, S_OK);
2730
2731     /* switch */
2732     hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2733     EXPECT_HR(hr, S_OK);
2734
2735     hr = IMXWriter_flush(writer);
2736     EXPECT_HR(hr, S_OK);
2737
2738     hr = GetHGlobalFromStream(stream, &g);
2739     EXPECT_HR(hr, S_OK);
2740
2741     ptr = GlobalLock(g);
2742     ok(!strncmp(ptr, "<a/>", 4), "got %c%c%c%c\n", ptr[0],ptr[1],ptr[2],ptr[3]);
2743     GlobalUnlock(g);
2744
2745     /* so output is unaffected, encoding name is stored however */
2746     hr = IMXWriter_get_encoding(writer, &s);
2747     EXPECT_HR(hr, S_OK);
2748     ok(!lstrcmpW(s, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(s));
2749     SysFreeString(s);
2750
2751     IStream_Release(stream);
2752
2753     ISAXContentHandler_Release(content);
2754     IMXWriter_Release(writer);
2755
2756     free_bstrs();
2757 }
2758
2759 static void test_obj_dispex(IUnknown *obj)
2760 {
2761     static const WCHAR starW[] = {'*',0};
2762     DISPID dispid = DISPID_SAX_XMLREADER_GETFEATURE;
2763     IDispatchEx *dispex;
2764     IUnknown *unk;
2765     DWORD props;
2766     UINT ticnt;
2767     HRESULT hr;
2768     BSTR name;
2769
2770     hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
2771     EXPECT_HR(hr, S_OK);
2772     if (FAILED(hr)) return;
2773
2774     ticnt = 0;
2775     hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
2776     EXPECT_HR(hr, S_OK);
2777     ok(ticnt == 1, "ticnt=%u\n", ticnt);
2778
2779     name = SysAllocString(starW);
2780     hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
2781     EXPECT_HR(hr, E_NOTIMPL);
2782     SysFreeString(name);
2783
2784     hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
2785     EXPECT_HR(hr, E_NOTIMPL);
2786
2787     props = 0;
2788     hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
2789     EXPECT_HR(hr, E_NOTIMPL);
2790     ok(props == 0, "expected 0 got %d\n", props);
2791
2792     hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
2793     EXPECT_HR(hr, E_NOTIMPL);
2794     if (SUCCEEDED(hr)) SysFreeString(name);
2795
2796     hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_SAX_XMLREADER_GETFEATURE, &dispid);
2797     EXPECT_HR(hr, E_NOTIMPL);
2798
2799     hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
2800     EXPECT_HR(hr, E_NOTIMPL);
2801     if (hr == S_OK && unk) IUnknown_Release(unk);
2802
2803     IDispatchEx_Release(dispex);
2804 }
2805
2806 static void test_dispex(void)
2807 {
2808      IVBSAXXMLReader *vbreader;
2809      ISAXXMLReader *reader;
2810      IUnknown *unk;
2811      HRESULT hr;
2812
2813      hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
2814                 &IID_ISAXXMLReader, (void**)&reader);
2815      EXPECT_HR(hr, S_OK);
2816
2817      hr = ISAXXMLReader_QueryInterface(reader, &IID_IUnknown, (void**)&unk);
2818      EXPECT_HR(hr, S_OK);
2819      test_obj_dispex(unk);
2820      IUnknown_Release(unk);
2821
2822      hr = ISAXXMLReader_QueryInterface(reader, &IID_IVBSAXXMLReader, (void**)&vbreader);
2823      EXPECT_HR(hr, S_OK);
2824      hr = IVBSAXXMLReader_QueryInterface(vbreader, &IID_IUnknown, (void**)&unk);
2825      EXPECT_HR(hr, S_OK);
2826      test_obj_dispex(unk);
2827      IUnknown_Release(unk);
2828      IVBSAXXMLReader_Release(vbreader);
2829
2830      ISAXXMLReader_Release(reader);
2831 }
2832
2833 static void test_mxwriter_dispex(void)
2834 {
2835     IDispatchEx *dispex;
2836     IMXWriter *writer;
2837     IUnknown *unk;
2838     HRESULT hr;
2839
2840     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2841             &IID_IMXWriter, (void**)&writer);
2842     EXPECT_HR(hr, S_OK);
2843
2844     hr = IMXWriter_QueryInterface(writer, &IID_IDispatchEx, (void**)&dispex);
2845     EXPECT_HR(hr, S_OK);
2846     hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
2847     test_obj_dispex(unk);
2848     IUnknown_Release(unk);
2849     IDispatchEx_Release(dispex);
2850
2851     IMXWriter_Release(writer);
2852 }
2853
2854 static void test_mxwriter_comment(void)
2855 {
2856     static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
2857     ISAXContentHandler *content;
2858     ISAXLexicalHandler *lexical;
2859     IMXWriter *writer;
2860     VARIANT dest;
2861     HRESULT hr;
2862
2863     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2864             &IID_IMXWriter, (void**)&writer);
2865     EXPECT_HR(hr, S_OK);
2866
2867     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2868     EXPECT_HR(hr, S_OK);
2869
2870     hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
2871     EXPECT_HR(hr, S_OK);
2872
2873     hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2874     EXPECT_HR(hr, S_OK);
2875
2876     hr = ISAXContentHandler_startDocument(content);
2877     EXPECT_HR(hr, S_OK);
2878
2879     hr = ISAXLexicalHandler_comment(lexical, NULL, 0);
2880     EXPECT_HR(hr, E_INVALIDARG);
2881
2882     hr = ISAXLexicalHandler_comment(lexical, commentW, 0);
2883     EXPECT_HR(hr, S_OK);
2884
2885     V_VT(&dest) = VT_EMPTY;
2886     hr = IMXWriter_get_output(writer, &dest);
2887     EXPECT_HR(hr, S_OK);
2888     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2889     ok(!lstrcmpW(_bstr_("<!---->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2890     VariantClear(&dest);
2891
2892     hr = ISAXLexicalHandler_comment(lexical, commentW, sizeof(commentW)/sizeof(WCHAR)-1);
2893     EXPECT_HR(hr, S_OK);
2894
2895     V_VT(&dest) = VT_EMPTY;
2896     hr = IMXWriter_get_output(writer, &dest);
2897     EXPECT_HR(hr, S_OK);
2898     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2899     ok(!lstrcmpW(_bstr_("<!---->\r\n<!--comment-->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2900     VariantClear(&dest);
2901
2902     ISAXContentHandler_Release(content);
2903     ISAXLexicalHandler_Release(lexical);
2904     IMXWriter_Release(writer);
2905     free_bstrs();
2906 }
2907
2908 static void test_mxwriter_cdata(void)
2909 {
2910     ISAXContentHandler *content;
2911     ISAXLexicalHandler *lexical;
2912     IMXWriter *writer;
2913     VARIANT dest;
2914     HRESULT hr;
2915
2916     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2917             &IID_IMXWriter, (void**)&writer);
2918     EXPECT_HR(hr, S_OK);
2919
2920     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2921     EXPECT_HR(hr, S_OK);
2922
2923     hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
2924     EXPECT_HR(hr, S_OK);
2925
2926     hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2927     EXPECT_HR(hr, S_OK);
2928
2929     hr = ISAXContentHandler_startDocument(content);
2930     EXPECT_HR(hr, S_OK);
2931
2932     hr = ISAXLexicalHandler_startCDATA(lexical);
2933     EXPECT_HR(hr, S_OK);
2934
2935     V_VT(&dest) = VT_EMPTY;
2936     hr = IMXWriter_get_output(writer, &dest);
2937     EXPECT_HR(hr, S_OK);
2938     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2939     ok(!lstrcmpW(_bstr_("<![CDATA["), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2940     VariantClear(&dest);
2941
2942     hr = ISAXLexicalHandler_startCDATA(lexical);
2943     EXPECT_HR(hr, S_OK);
2944
2945     hr = ISAXLexicalHandler_endCDATA(lexical);
2946     EXPECT_HR(hr, S_OK);
2947
2948     V_VT(&dest) = VT_EMPTY;
2949     hr = IMXWriter_get_output(writer, &dest);
2950     EXPECT_HR(hr, S_OK);
2951     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2952     ok(!lstrcmpW(_bstr_("<![CDATA[<![CDATA[]]>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2953     VariantClear(&dest);
2954
2955     ISAXContentHandler_Release(content);
2956     ISAXLexicalHandler_Release(lexical);
2957     IMXWriter_Release(writer);
2958     free_bstrs();
2959 }
2960
2961 static void test_mxwriter_dtd(void)
2962 {
2963     static const WCHAR nameW[] = {'n','a','m','e'};
2964     static const WCHAR pubW[] = {'p','u','b'};
2965     static const WCHAR sysW[] = {'s','y','s'};
2966     ISAXContentHandler *content;
2967     ISAXLexicalHandler *lexical;
2968     IMXWriter *writer;
2969     VARIANT dest;
2970     HRESULT hr;
2971
2972     hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2973             &IID_IMXWriter, (void**)&writer);
2974     EXPECT_HR(hr, S_OK);
2975
2976     hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2977     EXPECT_HR(hr, S_OK);
2978
2979     hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
2980     EXPECT_HR(hr, S_OK);
2981
2982     hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2983     EXPECT_HR(hr, S_OK);
2984
2985     hr = ISAXContentHandler_startDocument(content);
2986     EXPECT_HR(hr, S_OK);
2987
2988     hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, NULL, 0);
2989     EXPECT_HR(hr, E_INVALIDARG);
2990
2991     hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
2992     EXPECT_HR(hr, E_INVALIDARG);
2993
2994     hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, sysW, sizeof(sysW)/sizeof(WCHAR));
2995     EXPECT_HR(hr, E_INVALIDARG);
2996
2997     hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
2998     EXPECT_HR(hr, E_INVALIDARG);
2999
3000     hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), NULL, 0, NULL, 0);
3001     EXPECT_HR(hr, S_OK);
3002
3003     V_VT(&dest) = VT_EMPTY;
3004     hr = IMXWriter_get_output(writer, &dest);
3005     EXPECT_HR(hr, S_OK);
3006     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3007     ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3008     VariantClear(&dest);
3009
3010     /* system id is required if public is present */
3011     hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
3012     EXPECT_HR(hr, E_INVALIDARG);
3013
3014     hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR),
3015         pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
3016     EXPECT_HR(hr, S_OK);
3017
3018     V_VT(&dest) = VT_EMPTY;
3019     hr = IMXWriter_get_output(writer, &dest);
3020     EXPECT_HR(hr, S_OK);
3021     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3022     ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3023         "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3024     VariantClear(&dest);
3025
3026     hr = ISAXLexicalHandler_endDTD(lexical);
3027     EXPECT_HR(hr, S_OK);
3028
3029     hr = ISAXLexicalHandler_endDTD(lexical);
3030     EXPECT_HR(hr, S_OK);
3031
3032     V_VT(&dest) = VT_EMPTY;
3033     hr = IMXWriter_get_output(writer, &dest);
3034     EXPECT_HR(hr, S_OK);
3035     ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3036     ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3037          "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n]>\r\n]>\r\n"),
3038         V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3039     VariantClear(&dest);
3040
3041     ISAXContentHandler_Release(content);
3042     ISAXLexicalHandler_Release(lexical);
3043     IMXWriter_Release(writer);
3044     free_bstrs();
3045 }
3046
3047 START_TEST(saxreader)
3048 {
3049     ISAXXMLReader *reader;
3050     HRESULT hr;
3051
3052     hr = CoInitialize(NULL);
3053     ok(hr == S_OK, "failed to init com\n");
3054
3055     hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
3056             &IID_ISAXXMLReader, (void**)&reader);
3057
3058     if(FAILED(hr))
3059     {
3060         skip("Failed to create SAXXMLReader instance\n");
3061         CoUninitialize();
3062         return;
3063     }
3064     ISAXXMLReader_Release(reader);
3065
3066     test_saxreader(0);
3067     test_saxreader(3);
3068     test_saxreader(6);
3069     test_saxreader_properties();
3070     test_saxreader_features();
3071     test_encoding();
3072     test_dispex();
3073
3074     /* MXXMLWriter tests */
3075     get_supported_mxwriter_data(msxmlsupported_data);
3076     if (is_mxwriter_supported(&CLSID_MXXMLWriter, msxmlsupported_data))
3077     {
3078         test_mxwriter_handlers();
3079         test_mxwriter_startenddocument();
3080         test_mxwriter_startendelement();
3081         test_mxwriter_characters();
3082         test_mxwriter_comment();
3083         test_mxwriter_cdata();
3084         test_mxwriter_dtd();
3085         test_mxwriter_properties();
3086         test_mxwriter_flush();
3087         test_mxwriter_stream();
3088         test_mxwriter_encoding();
3089         test_mxwriter_dispex();
3090     }
3091     else
3092         win_skip("MXXMLWriter not supported\n");
3093
3094     CoUninitialize();
3095 }