msxml3: Fix parameter validation for startElement() for MXXMLWriter60.
[wine/multimedia.git] / dlls / msxml3 / tests / saxreader.c
blobca70a0d0e694c7353cdabcab6a4c52b65f6f1d80
1 /*
2 * XML test
4 * Copyright 2008 Piotr Caban
5 * Copyright 2011 Thomas Mullaly
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.
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.
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
22 #define COBJMACROS
23 #define CONST_VTABLE
25 #include <stdio.h>
26 #include <assert.h>
28 #include "windows.h"
29 #include "ole2.h"
30 #include "msxml2.h"
31 #include "ocidl.h"
33 #include "wine/test.h"
35 #define EXPECT_HR(hr,hr_exp) \
36 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
38 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
39 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
41 ULONG rc = IUnknown_AddRef(obj);
42 IUnknown_Release(obj);
43 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
46 static BSTR alloc_str_from_narrow(const char *str)
48 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
49 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
50 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
51 return ret;
54 static BSTR alloced_bstrs[256];
55 static int alloced_bstrs_count;
57 static BSTR _bstr_(const char *str)
59 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
60 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
61 return alloced_bstrs[alloced_bstrs_count++];
64 static void free_bstrs(void)
66 int i;
67 for (i = 0; i < alloced_bstrs_count; i++)
68 SysFreeString(alloced_bstrs[i]);
69 alloced_bstrs_count = 0;
72 typedef enum _CH {
73 CH_ENDTEST,
74 CH_PUTDOCUMENTLOCATOR,
75 CH_STARTDOCUMENT,
76 CH_ENDDOCUMENT,
77 CH_STARTPREFIXMAPPING,
78 CH_ENDPREFIXMAPPING,
79 CH_STARTELEMENT,
80 CH_ENDELEMENT,
81 CH_CHARACTERS,
82 CH_IGNORABLEWHITESPACE,
83 CH_PROCESSINGINSTRUCTION,
84 CH_SKIPPEDENTITY
85 } CH;
87 static const WCHAR szSimpleXML[] = {
88 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
89 '<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
90 ' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
91 ' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
92 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
95 static const WCHAR szCarriageRetTest[] = {
96 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
97 '<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
98 '\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
99 '\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
100 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\0'
103 static const WCHAR szUtf16XML[] = {
104 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"',' ',
105 'e','n','c','o','d','i','n','g','=','"','U','T','F','-','1','6','"',' ',
106 's','t','a','n','d','a','l','o','n','e','=','"','n','o','"','?','>','\r','\n'
109 static const CHAR szUtf16BOM[] = {0xff, 0xfe};
111 static const CHAR szUtf8XML[] =
112 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n";
114 static const CHAR szTestXML[] =
115 "<?xml version=\"1.0\" ?>\n"
116 "<BankAccount>\n"
117 " <Number>1234</Number>\n"
118 " <Name>Captain Ahab</Name>\n"
119 "</BankAccount>\n";
121 typedef struct _contenthandlercheck {
122 CH id;
123 int line;
124 int column;
125 const char *arg1;
126 const char *arg2;
127 const char *arg3;
128 } content_handler_test;
130 static content_handler_test contentHandlerTest1[] = {
131 { CH_PUTDOCUMENTLOCATOR, 0, 0 },
132 { CH_STARTDOCUMENT, 0, 0 },
133 { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
134 { CH_CHARACTERS, 2, 14, "\n " },
135 { CH_STARTELEMENT, 3, 12, "", "Number", "Number" },
136 { CH_CHARACTERS, 3, 12, "1234" },
137 { CH_ENDELEMENT, 3, 18, "", "Number", "Number" },
138 { CH_CHARACTERS, 3, 25, "\n " },
139 { CH_STARTELEMENT, 4, 10, "", "Name", "Name" },
140 { CH_CHARACTERS, 4, 10, "Captain Ahab" },
141 { CH_ENDELEMENT, 4, 24, "", "Name", "Name" },
142 { CH_CHARACTERS, 4, 29, "\n" },
143 { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
144 { CH_ENDDOCUMENT, 0, 0 },
145 { CH_ENDTEST }
148 static content_handler_test contentHandlerTest2[] = {
149 { CH_PUTDOCUMENTLOCATOR, 0, 0 },
150 { CH_STARTDOCUMENT, 0, 0 },
151 { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
152 { CH_CHARACTERS, 2, 14, "\n" },
153 { CH_CHARACTERS, 2, 16, "\t" },
154 { CH_STARTELEMENT, 3, 10, "", "Number", "Number" },
155 { CH_CHARACTERS, 3, 10, "1234" },
156 { CH_ENDELEMENT, 3, 16, "", "Number", "Number" },
157 { CH_CHARACTERS, 3, 23, "\n" },
158 { CH_CHARACTERS, 3, 25, "\t" },
159 { CH_STARTELEMENT, 4, 8, "", "Name", "Name" },
160 { CH_CHARACTERS, 4, 8, "Captain Ahab" },
161 { CH_ENDELEMENT, 4, 22, "", "Name", "Name" },
162 { CH_CHARACTERS, 4, 27, "\n" },
163 { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
164 { CH_ENDDOCUMENT, 0, 0 },
165 { CH_ENDTEST }
168 static content_handler_test *expectCall;
169 static ISAXLocator *locator;
171 static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
173 WCHAR buf[1024];
174 int len;
176 if(!szTest) {
177 ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
178 ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
179 return;
182 len = strlen(szTest);
183 ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
184 if(len != nStr)
185 return;
187 MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
188 ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
189 wine_dbgstr_wn(szStr, nStr), szTest);
192 static BOOL test_expect_call(CH id)
194 ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
195 return expectCall->id == id;
198 static void test_locator(unsigned line, int loc_line, int loc_column)
200 int rcolumn, rline;
201 ISAXLocator_getLineNumber(locator, &rline);
202 ISAXLocator_getColumnNumber(locator, &rcolumn);
204 ok_(__FILE__,line) (rline == loc_line,
205 "unexpected line %d, expected %d\n", rline, loc_line);
206 ok_(__FILE__,line) (rcolumn == loc_column,
207 "unexpected column %d, expected %d\n", rcolumn, loc_column);
210 static HRESULT WINAPI contentHandler_QueryInterface(
211 ISAXContentHandler* iface,
212 REFIID riid,
213 void **ppvObject)
215 *ppvObject = NULL;
217 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
219 *ppvObject = iface;
221 else
223 return E_NOINTERFACE;
226 return S_OK;
229 static ULONG WINAPI contentHandler_AddRef(
230 ISAXContentHandler* iface)
232 return 2;
235 static ULONG WINAPI contentHandler_Release(
236 ISAXContentHandler* iface)
238 return 1;
241 static HRESULT WINAPI contentHandler_putDocumentLocator(
242 ISAXContentHandler* iface,
243 ISAXLocator *pLocator)
245 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
246 return E_FAIL;
248 locator = pLocator;
249 test_locator(__LINE__, expectCall->line, expectCall->column);
251 expectCall++;
252 return S_OK;
255 static HRESULT WINAPI contentHandler_startDocument(
256 ISAXContentHandler* iface)
258 if(!test_expect_call(CH_STARTDOCUMENT))
259 return E_FAIL;
261 test_locator(__LINE__, expectCall->line, expectCall->column);
263 expectCall++;
264 return S_OK;
267 static HRESULT WINAPI contentHandler_endDocument(
268 ISAXContentHandler* iface)
270 if(!test_expect_call(CH_ENDDOCUMENT))
271 return E_FAIL;
273 test_locator(__LINE__, expectCall->line, expectCall->column);
275 expectCall++;
276 return S_OK;
279 static HRESULT WINAPI contentHandler_startPrefixMapping(
280 ISAXContentHandler* iface,
281 const WCHAR *pPrefix,
282 int nPrefix,
283 const WCHAR *pUri,
284 int nUri)
286 if(!test_expect_call(CH_ENDDOCUMENT))
287 return E_FAIL;
289 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
290 test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
291 test_locator(__LINE__, expectCall->line, expectCall->column);
293 expectCall++;
294 return S_OK;
297 static HRESULT WINAPI contentHandler_endPrefixMapping(
298 ISAXContentHandler* iface,
299 const WCHAR *pPrefix,
300 int nPrefix)
302 if(!test_expect_call(CH_ENDPREFIXMAPPING))
303 return E_FAIL;
305 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
306 test_locator(__LINE__, expectCall->line, expectCall->column);
308 expectCall++;
309 return S_OK;
312 static HRESULT WINAPI contentHandler_startElement(
313 ISAXContentHandler* iface,
314 const WCHAR *pNamespaceUri,
315 int nNamespaceUri,
316 const WCHAR *pLocalName,
317 int nLocalName,
318 const WCHAR *pQName,
319 int nQName,
320 ISAXAttributes *pAttr)
322 if(!test_expect_call(CH_STARTELEMENT))
323 return E_FAIL;
325 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
326 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
327 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
328 test_locator(__LINE__, expectCall->line, expectCall->column);
330 expectCall++;
331 return S_OK;
334 static HRESULT WINAPI contentHandler_endElement(
335 ISAXContentHandler* iface,
336 const WCHAR *pNamespaceUri,
337 int nNamespaceUri,
338 const WCHAR *pLocalName,
339 int nLocalName,
340 const WCHAR *pQName,
341 int nQName)
343 if(!test_expect_call(CH_ENDELEMENT))
344 return E_FAIL;
346 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
347 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
348 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
349 test_locator(__LINE__, expectCall->line, expectCall->column);
351 expectCall++;
352 return S_OK;
355 static HRESULT WINAPI contentHandler_characters(
356 ISAXContentHandler* iface,
357 const WCHAR *pChars,
358 int nChars)
360 if(!test_expect_call(CH_CHARACTERS))
361 return E_FAIL;
363 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
364 test_locator(__LINE__, expectCall->line, expectCall->column);
366 expectCall++;
367 return S_OK;
370 static HRESULT WINAPI contentHandler_ignorableWhitespace(
371 ISAXContentHandler* iface,
372 const WCHAR *pChars,
373 int nChars)
375 if(!test_expect_call(CH_IGNORABLEWHITESPACE))
376 return E_FAIL;
378 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
379 test_locator(__LINE__, expectCall->line, expectCall->column);
381 expectCall++;
382 return S_OK;
385 static HRESULT WINAPI contentHandler_processingInstruction(
386 ISAXContentHandler* iface,
387 const WCHAR *pTarget,
388 int nTarget,
389 const WCHAR *pData,
390 int nData)
392 if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
393 return E_FAIL;
395 test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
396 test_saxstr(__LINE__, pData, nData, expectCall->arg2);
397 test_locator(__LINE__, expectCall->line, expectCall->column);
399 expectCall++;
400 return S_OK;
403 static HRESULT WINAPI contentHandler_skippedEntity(
404 ISAXContentHandler* iface,
405 const WCHAR *pName,
406 int nName)
408 if(!test_expect_call(CH_SKIPPEDENTITY))
409 return E_FAIL;
411 test_saxstr(__LINE__, pName, nName, expectCall->arg1);
412 test_locator(__LINE__, expectCall->line, expectCall->column);
414 expectCall++;
415 return S_OK;
419 static const ISAXContentHandlerVtbl contentHandlerVtbl =
421 contentHandler_QueryInterface,
422 contentHandler_AddRef,
423 contentHandler_Release,
424 contentHandler_putDocumentLocator,
425 contentHandler_startDocument,
426 contentHandler_endDocument,
427 contentHandler_startPrefixMapping,
428 contentHandler_endPrefixMapping,
429 contentHandler_startElement,
430 contentHandler_endElement,
431 contentHandler_characters,
432 contentHandler_ignorableWhitespace,
433 contentHandler_processingInstruction,
434 contentHandler_skippedEntity
437 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
439 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
440 ISAXErrorHandler* iface,
441 REFIID riid,
442 void **ppvObject)
444 *ppvObject = NULL;
446 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
448 *ppvObject = iface;
450 else
452 return E_NOINTERFACE;
455 return S_OK;
458 static ULONG WINAPI isaxerrorHandler_AddRef(
459 ISAXErrorHandler* iface)
461 return 2;
464 static ULONG WINAPI isaxerrorHandler_Release(
465 ISAXErrorHandler* iface)
467 return 1;
470 static HRESULT WINAPI isaxerrorHandler_error(
471 ISAXErrorHandler* iface,
472 ISAXLocator *pLocator,
473 const WCHAR *pErrorMessage,
474 HRESULT hrErrorCode)
476 return S_OK;
479 static HRESULT WINAPI isaxerrorHandler_fatalError(
480 ISAXErrorHandler* iface,
481 ISAXLocator *pLocator,
482 const WCHAR *pErrorMessage,
483 HRESULT hrErrorCode)
485 return S_OK;
488 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
489 ISAXErrorHandler* iface,
490 ISAXLocator *pLocator,
491 const WCHAR *pErrorMessage,
492 HRESULT hrErrorCode)
494 return S_OK;
497 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
499 isaxerrorHandler_QueryInterface,
500 isaxerrorHandler_AddRef,
501 isaxerrorHandler_Release,
502 isaxerrorHandler_error,
503 isaxerrorHandler_fatalError,
504 isaxerrorHanddler_ignorableWarning
507 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
509 static HRESULT WINAPI isaxattributes_QueryInterface(
510 ISAXAttributes* iface,
511 REFIID riid,
512 void **ppvObject)
514 *ppvObject = NULL;
516 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
518 *ppvObject = iface;
520 else
522 return E_NOINTERFACE;
525 return S_OK;
528 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
530 return 2;
533 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
535 return 1;
538 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
540 *length = 2;
541 return S_OK;
544 static HRESULT WINAPI isaxattributes_getURI(
545 ISAXAttributes* iface,
546 int nIndex,
547 const WCHAR **pUrl,
548 int *pUriSize)
550 ok(0, "unexpected call\n");
551 return E_NOTIMPL;
554 static HRESULT WINAPI isaxattributes_getLocalName(
555 ISAXAttributes* iface,
556 int nIndex,
557 const WCHAR **pLocalName,
558 int *pLocalNameLength)
560 ok(0, "unexpected call\n");
561 return E_NOTIMPL;
564 static HRESULT WINAPI isaxattributes_getQName(
565 ISAXAttributes* iface,
566 int nIndex,
567 const WCHAR **pQName,
568 int *pQNameLength)
570 static const WCHAR attr1W[] = {'a',':','a','t','t','r','1',0};
571 static const WCHAR attr2W[] = {'a','t','t','r','2',0};
573 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
575 *pQName = (nIndex == 0) ? attr1W : attr2W;
576 *pQNameLength = lstrlenW(*pQName);
578 return S_OK;
581 static HRESULT WINAPI isaxattributes_getName(
582 ISAXAttributes* iface,
583 int nIndex,
584 const WCHAR **pUri,
585 int * pUriLength,
586 const WCHAR ** pLocalName,
587 int * pLocalNameSize,
588 const WCHAR ** pQName,
589 int * pQNameLength)
591 ok(0, "unexpected call\n");
592 return E_NOTIMPL;
595 static HRESULT WINAPI isaxattributes_getIndexFromName(
596 ISAXAttributes* iface,
597 const WCHAR * pUri,
598 int cUriLength,
599 const WCHAR * pLocalName,
600 int cocalNameLength,
601 int * index)
603 ok(0, "unexpected call\n");
604 return E_NOTIMPL;
607 static HRESULT WINAPI isaxattributes_getIndexFromQName(
608 ISAXAttributes* iface,
609 const WCHAR * pQName,
610 int nQNameLength,
611 int * index)
613 ok(0, "unexpected call\n");
614 return E_NOTIMPL;
617 static HRESULT WINAPI isaxattributes_getType(
618 ISAXAttributes* iface,
619 int nIndex,
620 const WCHAR ** pType,
621 int * pTypeLength)
623 ok(0, "unexpected call\n");
624 return E_NOTIMPL;
627 static HRESULT WINAPI isaxattributes_getTypeFromName(
628 ISAXAttributes* iface,
629 const WCHAR * pUri,
630 int nUri,
631 const WCHAR * pLocalName,
632 int nLocalName,
633 const WCHAR ** pType,
634 int * nType)
636 ok(0, "unexpected call\n");
637 return E_NOTIMPL;
640 static HRESULT WINAPI isaxattributes_getTypeFromQName(
641 ISAXAttributes* iface,
642 const WCHAR * pQName,
643 int nQName,
644 const WCHAR ** pType,
645 int * nType)
647 ok(0, "unexpected call\n");
648 return E_NOTIMPL;
651 static HRESULT WINAPI isaxattributes_getValue(
652 ISAXAttributes* iface,
653 int nIndex,
654 const WCHAR ** pValue,
655 int * nValue)
657 static const WCHAR attrval1W[] = {'a','1',0};
658 static const WCHAR attrval2W[] = {'a','2',0};
660 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
662 *pValue = (nIndex == 0) ? attrval1W : attrval2W;
663 *nValue = lstrlenW(*pValue);
665 return S_OK;
668 static HRESULT WINAPI isaxattributes_getValueFromName(
669 ISAXAttributes* iface,
670 const WCHAR * pUri,
671 int nUri,
672 const WCHAR * pLocalName,
673 int nLocalName,
674 const WCHAR ** pValue,
675 int * nValue)
677 ok(0, "unexpected call\n");
678 return E_NOTIMPL;
681 static HRESULT WINAPI isaxattributes_getValueFromQName(
682 ISAXAttributes* iface,
683 const WCHAR * pQName,
684 int nQName,
685 const WCHAR ** pValue,
686 int * nValue)
688 ok(0, "unexpected call\n");
689 return E_NOTIMPL;
692 static const ISAXAttributesVtbl SAXAttributesVtbl =
694 isaxattributes_QueryInterface,
695 isaxattributes_AddRef,
696 isaxattributes_Release,
697 isaxattributes_getLength,
698 isaxattributes_getURI,
699 isaxattributes_getLocalName,
700 isaxattributes_getQName,
701 isaxattributes_getName,
702 isaxattributes_getIndexFromName,
703 isaxattributes_getIndexFromQName,
704 isaxattributes_getType,
705 isaxattributes_getTypeFromName,
706 isaxattributes_getTypeFromQName,
707 isaxattributes_getValue,
708 isaxattributes_getValueFromName,
709 isaxattributes_getValueFromQName
712 static ISAXAttributes saxattributes = { &SAXAttributesVtbl };
714 typedef struct mxwriter_write_test_t {
715 BOOL last;
716 const BYTE *data;
717 DWORD cb;
718 BOOL null_written;
719 BOOL fail_write;
720 } mxwriter_write_test;
722 typedef struct mxwriter_stream_test_t {
723 VARIANT_BOOL bom;
724 const char *encoding;
725 mxwriter_write_test expected_writes[4];
726 } mxwriter_stream_test;
728 static const mxwriter_write_test *current_write_test;
729 static DWORD current_stream_test_index;
731 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
733 *ppvObject = NULL;
735 if(IsEqualGUID(riid, &IID_IStream) || IsEqualGUID(riid, &IID_IUnknown))
736 *ppvObject = iface;
737 else
738 return E_NOINTERFACE;
740 return S_OK;
743 static ULONG WINAPI istream_AddRef(IStream *iface)
745 return 2;
748 static ULONG WINAPI istream_Release(IStream *iface)
750 return 1;
753 static HRESULT WINAPI istream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
755 ok(0, "unexpected call\n");
756 return E_NOTIMPL;
759 static HRESULT WINAPI istream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
761 BOOL fail = FALSE;
763 ok(pv != NULL, "pv == NULL\n");
765 if(current_write_test->last) {
766 ok(0, "Too many Write calls made on test %d\n", current_stream_test_index);
767 return E_FAIL;
770 fail = current_write_test->fail_write;
772 ok(current_write_test->cb == cb, "Expected %d, but got %d on test %d\n",
773 current_write_test->cb, cb, current_stream_test_index);
775 if(!pcbWritten)
776 ok(current_write_test->null_written, "pcbWritten was NULL on test %d\n", current_stream_test_index);
777 else
778 ok(!memcmp(current_write_test->data, pv, cb), "Unexpected data on test %d\n", current_stream_test_index);
780 ++current_write_test;
782 if(pcbWritten)
783 *pcbWritten = cb;
785 return fail ? E_FAIL : S_OK;
788 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
789 ULARGE_INTEGER *plibNewPosition)
791 ok(0, "unexpected call\n");
792 return E_NOTIMPL;
795 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
797 ok(0, "unexpected call\n");
798 return E_NOTIMPL;
801 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
802 ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *plibWritten)
804 ok(0, "unexpected call\n");
805 return E_NOTIMPL;
808 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD grfCommitFlags)
810 ok(0, "unexpected call\n");
811 return E_NOTIMPL;
814 static HRESULT WINAPI istream_Revert(IStream *iface)
816 ok(0, "unexpected call\n");
817 return E_NOTIMPL;
820 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
821 ULARGE_INTEGER cb, DWORD dwLockType)
823 ok(0, "unexpected call\n");
824 return E_NOTIMPL;
827 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
828 ULARGE_INTEGER cb, DWORD dwLockType)
830 ok(0, "unexpected call\n");
831 return E_NOTIMPL;
834 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
836 ok(0, "unexpected call\n");
837 return E_NOTIMPL;
840 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **ppstm)
842 ok(0, "unexpected call\n");
843 return E_NOTIMPL;
846 static const IStreamVtbl StreamVtbl = {
847 istream_QueryInterface,
848 istream_AddRef,
849 istream_Release,
850 istream_Read,
851 istream_Write,
852 istream_Seek,
853 istream_SetSize,
854 istream_CopyTo,
855 istream_Commit,
856 istream_Revert,
857 istream_LockRegion,
858 istream_UnlockRegion,
859 istream_Stat,
860 istream_Clone
863 static IStream mxstream = { &StreamVtbl };
865 static void test_saxreader(void)
867 HRESULT hr;
868 ISAXXMLReader *reader = NULL;
869 VARIANT var;
870 ISAXContentHandler *lpContentHandler;
871 ISAXErrorHandler *lpErrorHandler;
872 SAFEARRAY *pSA;
873 SAFEARRAYBOUND SADim[1];
874 char *pSAData = NULL;
875 IStream *iStream;
876 ULARGE_INTEGER liSize;
877 LARGE_INTEGER liPos;
878 ULONG bytesWritten;
879 HANDLE file;
880 static const CHAR testXmlA[] = "test.xml";
881 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
882 IXMLDOMDocument *domDocument;
883 BSTR bstrData;
884 VARIANT_BOOL vBool;
886 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
887 &IID_ISAXXMLReader, (LPVOID*)&reader);
888 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
890 hr = ISAXXMLReader_getContentHandler(reader, NULL);
891 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
893 hr = ISAXXMLReader_getErrorHandler(reader, NULL);
894 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
896 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
897 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
898 ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
900 hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
901 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
902 ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
904 hr = ISAXXMLReader_putContentHandler(reader, NULL);
905 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
907 hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
908 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
910 hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
911 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
913 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
914 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
915 ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
917 V_VT(&var) = VT_BSTR;
918 V_BSTR(&var) = SysAllocString(szSimpleXML);
920 expectCall = contentHandlerTest1;
921 hr = ISAXXMLReader_parse(reader, var);
922 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
923 test_expect_call(CH_ENDTEST);
925 VariantClear(&var);
927 SADim[0].lLbound= 0;
928 SADim[0].cElements= sizeof(szTestXML)-1;
929 pSA = SafeArrayCreate(VT_UI1, 1, SADim);
930 SafeArrayAccessData(pSA, (void**)&pSAData);
931 memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
932 SafeArrayUnaccessData(pSA);
933 V_VT(&var) = VT_ARRAY|VT_UI1;
934 V_ARRAY(&var) = pSA;
936 expectCall = contentHandlerTest1;
937 hr = ISAXXMLReader_parse(reader, var);
938 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
939 test_expect_call(CH_ENDTEST);
941 SafeArrayDestroy(pSA);
943 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
944 liSize.QuadPart = strlen(szTestXML);
945 IStream_SetSize(iStream, liSize);
946 IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
947 liPos.QuadPart = 0;
948 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
949 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
950 V_UNKNOWN(&var) = (IUnknown*)iStream;
952 expectCall = contentHandlerTest1;
953 hr = ISAXXMLReader_parse(reader, var);
954 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
955 test_expect_call(CH_ENDTEST);
957 IStream_Release(iStream);
959 V_VT(&var) = VT_BSTR;
960 V_BSTR(&var) = SysAllocString(szCarriageRetTest);
962 expectCall = contentHandlerTest2;
963 hr = ISAXXMLReader_parse(reader, var);
964 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
965 test_expect_call(CH_ENDTEST);
967 VariantClear(&var);
969 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
970 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
971 WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
972 CloseHandle(file);
974 expectCall = contentHandlerTest1;
975 hr = ISAXXMLReader_parseURL(reader, testXmlW);
976 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
977 test_expect_call(CH_ENDTEST);
979 DeleteFileA(testXmlA);
981 hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
982 &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
983 if(FAILED(hr))
985 skip("Failed to create DOMDocument instance\n");
986 return;
988 bstrData = SysAllocString(szSimpleXML);
989 hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
990 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
991 V_VT(&var) = VT_UNKNOWN;
992 V_UNKNOWN(&var) = (IUnknown*)domDocument;
994 expectCall = contentHandlerTest2;
995 hr = ISAXXMLReader_parse(reader, var);
996 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
997 test_expect_call(CH_ENDTEST);
998 IXMLDOMDocument_Release(domDocument);
1000 ISAXXMLReader_Release(reader);
1001 SysFreeString(bstrData);
1004 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1005 static const CHAR UTF8BOMTest[] =
1006 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1007 "<a></a>\n";
1009 struct enc_test_entry_t {
1010 const GUID *guid;
1011 const char *clsid;
1012 const char *data;
1013 HRESULT hr;
1014 int todo;
1017 static const struct enc_test_entry_t encoding_test_data[] = {
1018 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
1019 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
1020 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
1021 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
1022 { 0 }
1025 static void test_encoding(void)
1027 const struct enc_test_entry_t *entry = encoding_test_data;
1028 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1029 static const CHAR testXmlA[] = "test.xml";
1030 ISAXXMLReader *reader;
1031 DWORD written;
1032 HANDLE file;
1033 HRESULT hr;
1035 while (entry->guid)
1037 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1038 if (hr != S_OK)
1040 win_skip("can't create %s instance\n", entry->clsid);
1041 entry++;
1042 continue;
1045 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1046 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1047 WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
1048 CloseHandle(file);
1050 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1051 if (entry->todo)
1052 todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1053 else
1054 ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1056 DeleteFileA(testXmlA);
1057 ISAXXMLReader_Release(reader);
1059 entry++;
1063 static void test_mxwriter_contenthandler(void)
1065 ISAXContentHandler *handler;
1066 IMXWriter *writer, *writer2;
1067 HRESULT hr;
1069 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1070 &IID_IMXWriter, (void**)&writer);
1071 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1073 EXPECT_REF(writer, 1);
1075 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
1076 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1077 EXPECT_REF(writer, 2);
1078 EXPECT_REF(handler, 2);
1080 hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
1081 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1082 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1083 EXPECT_REF(writer, 3);
1084 EXPECT_REF(writer2, 3);
1085 IMXWriter_Release(writer2);
1087 ISAXContentHandler_Release(handler);
1088 IMXWriter_Release(writer);
1091 static void test_mxwriter_properties(void)
1093 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
1094 static const WCHAR emptyW[] = {0};
1095 static const WCHAR testW[] = {'t','e','s','t',0};
1096 IMXWriter *writer;
1097 VARIANT_BOOL b;
1098 HRESULT hr;
1099 BSTR str, str2;
1101 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1102 &IID_IMXWriter, (void**)&writer);
1103 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1105 hr = IMXWriter_get_disableOutputEscaping(writer, NULL);
1106 ok(hr == E_POINTER, "got %08x\n", hr);
1108 b = VARIANT_TRUE;
1109 hr = IMXWriter_get_disableOutputEscaping(writer, &b);
1110 ok(hr == S_OK, "got %08x\n", hr);
1111 ok(b == VARIANT_FALSE, "got %d\n", b);
1113 hr = IMXWriter_get_byteOrderMark(writer, NULL);
1114 ok(hr == E_POINTER, "got %08x\n", hr);
1116 b = VARIANT_FALSE;
1117 hr = IMXWriter_get_byteOrderMark(writer, &b);
1118 ok(hr == S_OK, "got %08x\n", hr);
1119 ok(b == VARIANT_TRUE, "got %d\n", b);
1121 hr = IMXWriter_get_indent(writer, NULL);
1122 ok(hr == E_POINTER, "got %08x\n", hr);
1124 b = VARIANT_TRUE;
1125 hr = IMXWriter_get_indent(writer, &b);
1126 ok(hr == S_OK, "got %08x\n", hr);
1127 ok(b == VARIANT_FALSE, "got %d\n", b);
1129 hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
1130 ok(hr == E_POINTER, "got %08x\n", hr);
1132 b = VARIANT_TRUE;
1133 hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
1134 ok(hr == S_OK, "got %08x\n", hr);
1135 ok(b == VARIANT_FALSE, "got %d\n", b);
1137 hr = IMXWriter_get_standalone(writer, NULL);
1138 ok(hr == E_POINTER, "got %08x\n", hr);
1140 b = VARIANT_TRUE;
1141 hr = IMXWriter_get_standalone(writer, &b);
1142 ok(hr == S_OK, "got %08x\n", hr);
1143 ok(b == VARIANT_FALSE, "got %d\n", b);
1145 /* set and check */
1146 hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
1147 ok(hr == S_OK, "got %08x\n", hr);
1149 b = VARIANT_FALSE;
1150 hr = IMXWriter_get_standalone(writer, &b);
1151 ok(hr == S_OK, "got %08x\n", hr);
1152 ok(b == VARIANT_TRUE, "got %d\n", b);
1154 hr = IMXWriter_get_encoding(writer, NULL);
1155 ok(hr == E_POINTER, "got %08x\n", hr);
1157 /* UTF-16 is a default setting apparently */
1158 str = (void*)0xdeadbeef;
1159 hr = IMXWriter_get_encoding(writer, &str);
1160 ok(hr == S_OK, "got %08x\n", hr);
1161 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1163 str2 = (void*)0xdeadbeef;
1164 hr = IMXWriter_get_encoding(writer, &str2);
1165 ok(hr == S_OK, "got %08x\n", hr);
1166 ok(str != str2, "expected newly allocated, got same %p\n", str);
1168 SysFreeString(str2);
1169 SysFreeString(str);
1171 /* put empty string */
1172 str = SysAllocString(emptyW);
1173 hr = IMXWriter_put_encoding(writer, str);
1174 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1175 SysFreeString(str);
1177 str = (void*)0xdeadbeef;
1178 hr = IMXWriter_get_encoding(writer, &str);
1179 ok(hr == S_OK, "got %08x\n", hr);
1180 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1181 SysFreeString(str);
1183 /* invalid encoding name */
1184 str = SysAllocString(testW);
1185 hr = IMXWriter_put_encoding(writer, str);
1186 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1187 SysFreeString(str);
1189 hr = IMXWriter_get_version(writer, NULL);
1190 ok(hr == E_POINTER, "got %08x\n", hr);
1191 /* default version is 'surprisingly' 1.0 */
1192 hr = IMXWriter_get_version(writer, &str);
1193 ok(hr == S_OK, "got %08x\n", hr);
1194 ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1195 SysFreeString(str);
1197 /* store version string as is */
1198 hr = IMXWriter_put_version(writer, NULL);
1199 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1201 hr = IMXWriter_put_version(writer, _bstr_("1.0"));
1202 ok(hr == S_OK, "got %08x\n", hr);
1204 hr = IMXWriter_put_version(writer, _bstr_(""));
1205 ok(hr == S_OK, "got %08x\n", hr);
1206 hr = IMXWriter_get_version(writer, &str);
1207 ok(hr == S_OK, "got %08x\n", hr);
1208 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
1209 SysFreeString(str);
1211 hr = IMXWriter_put_version(writer, _bstr_("a.b"));
1212 ok(hr == S_OK, "got %08x\n", hr);
1213 hr = IMXWriter_get_version(writer, &str);
1214 ok(hr == S_OK, "got %08x\n", hr);
1215 ok(!lstrcmpW(str, _bstr_("a.b")), "got %s\n", wine_dbgstr_w(str));
1216 SysFreeString(str);
1218 hr = IMXWriter_put_version(writer, _bstr_("2.0"));
1219 ok(hr == S_OK, "got %08x\n", hr);
1220 hr = IMXWriter_get_version(writer, &str);
1221 ok(hr == S_OK, "got %08x\n", hr);
1222 ok(!lstrcmpW(str, _bstr_("2.0")), "got %s\n", wine_dbgstr_w(str));
1223 SysFreeString(str);
1225 IMXWriter_Release(writer);
1226 free_bstrs();
1229 static void test_mxwriter_flush(void)
1231 ISAXContentHandler *content;
1232 IMXWriter *writer;
1233 LARGE_INTEGER pos;
1234 ULARGE_INTEGER pos2;
1235 IStream *stream;
1236 VARIANT dest;
1237 HRESULT hr;
1239 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1240 &IID_IMXWriter, (void**)&writer);
1241 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1243 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1244 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1245 EXPECT_REF(stream, 1);
1247 /* detach when nothing was attached */
1248 V_VT(&dest) = VT_EMPTY;
1249 hr = IMXWriter_put_output(writer, dest);
1250 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1252 /* attach stream */
1253 V_VT(&dest) = VT_UNKNOWN;
1254 V_UNKNOWN(&dest) = (IUnknown*)stream;
1255 hr = IMXWriter_put_output(writer, dest);
1256 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1257 todo_wine EXPECT_REF(stream, 3);
1259 /* detach setting VT_EMPTY destination */
1260 V_VT(&dest) = VT_EMPTY;
1261 hr = IMXWriter_put_output(writer, dest);
1262 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1263 EXPECT_REF(stream, 1);
1265 V_VT(&dest) = VT_UNKNOWN;
1266 V_UNKNOWN(&dest) = (IUnknown*)stream;
1267 hr = IMXWriter_put_output(writer, dest);
1268 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1270 /* flush() doesn't detach a stream */
1271 hr = IMXWriter_flush(writer);
1272 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1273 todo_wine EXPECT_REF(stream, 3);
1275 pos.QuadPart = 0;
1276 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1277 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1278 ok(pos2.QuadPart == 0, "expected stream beginning\n");
1280 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1281 ok(hr == S_OK, "got %08x\n", hr);
1283 hr = ISAXContentHandler_startDocument(content);
1284 ok(hr == S_OK, "got %08x\n", hr);
1286 pos.QuadPart = 0;
1287 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1288 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1289 ok(pos2.QuadPart != 0, "expected stream beginning\n");
1291 /* already started */
1292 hr = ISAXContentHandler_startDocument(content);
1293 ok(hr == S_OK, "got %08x\n", hr);
1295 hr = ISAXContentHandler_endDocument(content);
1296 ok(hr == S_OK, "got %08x\n", hr);
1298 /* flushed on endDocument() */
1299 pos.QuadPart = 0;
1300 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1301 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1302 ok(pos2.QuadPart != 0, "expected stream position moved\n");
1304 ISAXContentHandler_Release(content);
1305 IStream_Release(stream);
1306 IMXWriter_Release(writer);
1309 static void test_mxwriter_startenddocument(void)
1311 ISAXContentHandler *content;
1312 IMXWriter *writer;
1313 VARIANT dest;
1314 HRESULT hr;
1316 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1317 &IID_IMXWriter, (void**)&writer);
1318 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1320 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1321 ok(hr == S_OK, "got %08x\n", hr);
1323 hr = ISAXContentHandler_startDocument(content);
1324 ok(hr == S_OK, "got %08x\n", hr);
1326 hr = ISAXContentHandler_endDocument(content);
1327 ok(hr == S_OK, "got %08x\n", hr);
1329 V_VT(&dest) = VT_EMPTY;
1330 hr = IMXWriter_get_output(writer, &dest);
1331 ok(hr == S_OK, "got %08x\n", hr);
1332 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1333 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1334 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1335 VariantClear(&dest);
1337 /* now try another startDocument */
1338 hr = ISAXContentHandler_startDocument(content);
1339 ok(hr == S_OK, "got %08x\n", hr);
1340 /* and get duplicated prolog */
1341 V_VT(&dest) = VT_EMPTY;
1342 hr = IMXWriter_get_output(writer, &dest);
1343 ok(hr == S_OK, "got %08x\n", hr);
1344 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1345 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
1346 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1347 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1348 VariantClear(&dest);
1350 ISAXContentHandler_Release(content);
1351 IMXWriter_Release(writer);
1353 /* now with omitted declaration */
1354 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1355 &IID_IMXWriter, (void**)&writer);
1356 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1358 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1359 ok(hr == S_OK, "got %08x\n", hr);
1361 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1362 ok(hr == S_OK, "got %08x\n", hr);
1364 hr = ISAXContentHandler_startDocument(content);
1365 ok(hr == S_OK, "got %08x\n", hr);
1367 hr = ISAXContentHandler_endDocument(content);
1368 ok(hr == S_OK, "got %08x\n", hr);
1370 V_VT(&dest) = VT_EMPTY;
1371 hr = IMXWriter_get_output(writer, &dest);
1372 ok(hr == S_OK, "got %08x\n", hr);
1373 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1374 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1375 VariantClear(&dest);
1377 ISAXContentHandler_Release(content);
1378 IMXWriter_Release(writer);
1380 free_bstrs();
1383 struct writer_startelement_t {
1384 const GUID *clsid;
1385 const char *uri;
1386 const char *local_name;
1387 const char *qname;
1388 const char *output;
1389 HRESULT hr;
1392 static const struct writer_startelement_t writer_startelement[] = {
1393 /* 0 */
1394 { &CLSID_MXXMLWriter, NULL, NULL, NULL, NULL, E_INVALIDARG },
1395 { &CLSID_MXXMLWriter30, NULL, NULL, NULL, NULL, E_INVALIDARG },
1396 { &CLSID_MXXMLWriter40, NULL, NULL, NULL, NULL, E_INVALIDARG },
1397 { &CLSID_MXXMLWriter60, NULL, NULL, NULL, "<>", S_OK },
1398 { &CLSID_MXXMLWriter, "uri", NULL, NULL, NULL, E_INVALIDARG },
1399 /* 5 */
1400 { &CLSID_MXXMLWriter30, "uri", NULL, NULL, NULL, E_INVALIDARG },
1401 { &CLSID_MXXMLWriter40, "uri", NULL, NULL, NULL, E_INVALIDARG },
1402 { &CLSID_MXXMLWriter60, "uri", NULL, NULL, "<>", S_OK },
1403 { &CLSID_MXXMLWriter, NULL, "local", NULL, NULL, E_INVALIDARG },
1404 { &CLSID_MXXMLWriter30, NULL, "local", NULL, NULL, E_INVALIDARG },
1405 /* 10 */
1406 { &CLSID_MXXMLWriter40, NULL, "local", NULL, NULL, E_INVALIDARG },
1407 { &CLSID_MXXMLWriter60, NULL, "local", NULL, "<>", S_OK },
1408 { &CLSID_MXXMLWriter, NULL, NULL, "qname", NULL, E_INVALIDARG },
1409 { &CLSID_MXXMLWriter30, NULL, NULL, "qname", NULL, E_INVALIDARG },
1410 { &CLSID_MXXMLWriter40, NULL, NULL, "qname", NULL, E_INVALIDARG },
1411 /* 15 */
1412 { &CLSID_MXXMLWriter60, NULL, NULL, "qname", "<qname>", S_OK },
1413 { &CLSID_MXXMLWriter, "uri", "local", "qname", "<qname>", S_OK },
1414 { &CLSID_MXXMLWriter30, "uri", "local", "qname", "<qname>", S_OK },
1415 { &CLSID_MXXMLWriter40, "uri", "local", "qname", "<qname>", S_OK },
1416 { &CLSID_MXXMLWriter60, "uri", "local", "qname", "<qname>", S_OK },
1417 /* 20 */
1418 { &CLSID_MXXMLWriter, "uri", "local", NULL, NULL, E_INVALIDARG },
1419 { &CLSID_MXXMLWriter30, "uri", "local", NULL, NULL, E_INVALIDARG },
1420 { &CLSID_MXXMLWriter40, "uri", "local", NULL, NULL, E_INVALIDARG },
1421 { &CLSID_MXXMLWriter60, "uri", "local", NULL, "<>", S_OK },
1422 { &CLSID_MXXMLWriter, "uri", "local", "uri:local", "<uri:local>", S_OK },
1423 /* 25 */
1424 { &CLSID_MXXMLWriter30, "uri", "local", "uri:local", "<uri:local>", S_OK },
1425 { &CLSID_MXXMLWriter40, "uri", "local", "uri:local", "<uri:local>", S_OK },
1426 { &CLSID_MXXMLWriter60, "uri", "local", "uri:local", "<uri:local>", S_OK },
1427 { &CLSID_MXXMLWriter, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1428 { &CLSID_MXXMLWriter30, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1429 /* 30 */
1430 { &CLSID_MXXMLWriter40, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1431 { &CLSID_MXXMLWriter60, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1432 { NULL }
1435 struct msxmlsupported_data_t
1437 const GUID *clsid;
1438 const char *name;
1439 BOOL supported;
1442 static struct msxmlsupported_data_t msxmlsupported_data[] =
1444 { &CLSID_MXXMLWriter, "MXXMLWriter" },
1445 { &CLSID_MXXMLWriter30, "MXXMLWriter30" },
1446 { &CLSID_MXXMLWriter40, "MXXMLWriter40" },
1447 { &CLSID_MXXMLWriter60, "MXXMLWriter60" },
1448 { NULL }
1451 static void get_supported_mxwriter_data(struct msxmlsupported_data_t *table)
1453 while (table->clsid)
1455 IMXWriter *writer;
1456 HRESULT hr;
1458 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1459 &IID_IMXWriter, (void**)&writer);
1460 if (hr == S_OK) IMXWriter_Release(writer);
1462 table->supported = hr == S_OK;
1463 if (hr != S_OK) win_skip("class %s not supported\n", table->name);
1465 table++;
1469 static BOOL is_mxwriter_supported(const GUID *clsid, const struct msxmlsupported_data_t *table)
1471 while (table->clsid)
1473 if (table->clsid == clsid) return table->supported;
1474 table++;
1476 return FALSE;
1479 static void test_mxwriter_startelement(const struct writer_startelement_t *table)
1481 int i;
1483 get_supported_mxwriter_data(msxmlsupported_data);
1485 i = 0;
1486 while (table->clsid)
1488 ISAXContentHandler *content;
1489 IMXWriter *writer;
1490 HRESULT hr;
1492 if (!is_mxwriter_supported(table->clsid, msxmlsupported_data))
1494 table++;
1495 i++;
1496 continue;
1499 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1500 &IID_IMXWriter, (void**)&writer);
1501 EXPECT_HR(hr, S_OK);
1503 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1504 EXPECT_HR(hr, S_OK);
1506 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1507 EXPECT_HR(hr, S_OK);
1509 hr = ISAXContentHandler_startDocument(content);
1510 EXPECT_HR(hr, S_OK);
1512 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
1513 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), NULL);
1514 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
1516 /* test output */
1517 if (hr == S_OK)
1519 VARIANT dest;
1521 V_VT(&dest) = VT_EMPTY;
1522 hr = IMXWriter_get_output(writer, &dest);
1523 EXPECT_HR(hr, S_OK);
1524 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1525 ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
1526 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
1527 VariantClear(&dest);
1530 ISAXContentHandler_Release(content);
1531 IMXWriter_Release(writer);
1533 table++;
1534 i++;
1537 free_bstrs();
1540 static void test_mxwriter_startendelement(void)
1542 static const char winehqA[] = "http://winehq.org";
1543 ISAXContentHandler *content;
1544 IMXWriter *writer;
1545 VARIANT dest;
1546 HRESULT hr;
1548 test_mxwriter_startelement(writer_startelement);
1550 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1551 &IID_IMXWriter, (void**)&writer);
1552 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1554 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1555 ok(hr == S_OK, "got %08x\n", hr);
1557 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1558 ok(hr == S_OK, "got %08x\n", hr);
1560 hr = ISAXContentHandler_startDocument(content);
1561 ok(hr == S_OK, "got %08x\n", hr);
1563 /* all string pointers should be not null */
1564 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
1565 ok(hr == S_OK, "got %08x\n", hr);
1567 V_VT(&dest) = VT_EMPTY;
1568 hr = IMXWriter_get_output(writer, &dest);
1569 ok(hr == S_OK, "got %08x\n", hr);
1570 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1571 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1572 VariantClear(&dest);
1574 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
1575 ok(hr == S_OK, "got %08x\n", hr);
1577 V_VT(&dest) = VT_EMPTY;
1578 hr = IMXWriter_get_output(writer, &dest);
1579 ok(hr == S_OK, "got %08x\n", hr);
1580 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1581 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1582 VariantClear(&dest);
1584 hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
1585 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1587 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
1588 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1590 /* only local name is an error too */
1591 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
1592 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1594 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
1595 ok(hr == S_OK, "got %08x\n", hr);
1597 V_VT(&dest) = VT_EMPTY;
1598 hr = IMXWriter_get_output(writer, &dest);
1599 ok(hr == S_OK, "got %08x\n", hr);
1600 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1601 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1602 VariantClear(&dest);
1604 /* some with namespace URI */
1605 hr = ISAXContentHandler_startElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8, NULL);
1606 ok(hr == S_OK, "got %08x\n", hr);
1608 hr = ISAXContentHandler_endElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8);
1609 ok(hr == S_OK, "got %08x\n", hr);
1611 V_VT(&dest) = VT_EMPTY;
1612 hr = IMXWriter_get_output(writer, &dest);
1613 ok(hr == S_OK, "got %08x\n", hr);
1614 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1615 todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1616 VariantClear(&dest);
1618 /* try to end element that wasn't open */
1619 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
1620 ok(hr == S_OK, "got %08x\n", hr);
1622 V_VT(&dest) = VT_EMPTY;
1623 hr = IMXWriter_get_output(writer, &dest);
1624 ok(hr == S_OK, "got %08x\n", hr);
1625 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1626 todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1627 VariantClear(&dest);
1629 /* try with attributes */
1630 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, &saxattributes);
1631 ok(hr == S_OK, "got %08x\n", hr);
1633 hr = ISAXContentHandler_endDocument(content);
1634 ok(hr == S_OK, "got %08x\n", hr);
1636 ISAXContentHandler_Release(content);
1637 IMXWriter_Release(writer);
1639 free_bstrs();
1642 static void test_mxwriter_characters(void)
1644 static const WCHAR chardataW[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
1645 ISAXContentHandler *content;
1646 IMXWriter *writer;
1647 VARIANT dest;
1648 HRESULT hr;
1650 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1651 &IID_IMXWriter, (void**)&writer);
1652 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1654 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1655 ok(hr == S_OK, "got %08x\n", hr);
1657 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1658 ok(hr == S_OK, "got %08x\n", hr);
1660 hr = ISAXContentHandler_startDocument(content);
1661 ok(hr == S_OK, "got %08x\n", hr);
1663 hr = ISAXContentHandler_characters(content, NULL, 0);
1664 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1666 hr = ISAXContentHandler_characters(content, chardataW, 0);
1667 ok(hr == S_OK, "got %08x\n", hr);
1669 hr = ISAXContentHandler_characters(content, chardataW, sizeof(chardataW)/sizeof(WCHAR) - 1);
1670 ok(hr == S_OK, "got %08x\n", hr);
1672 V_VT(&dest) = VT_EMPTY;
1673 hr = IMXWriter_get_output(writer, &dest);
1674 ok(hr == S_OK, "got %08x\n", hr);
1675 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1676 ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1677 VariantClear(&dest);
1679 hr = ISAXContentHandler_endDocument(content);
1680 ok(hr == S_OK, "got %08x\n", hr);
1682 ISAXContentHandler_Release(content);
1683 IMXWriter_Release(writer);
1685 free_bstrs();
1688 static const mxwriter_stream_test mxwriter_stream_tests[] = {
1690 VARIANT_TRUE,"UTF-16",
1692 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
1693 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1694 {TRUE}
1698 VARIANT_FALSE,"UTF-16",
1700 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1701 {TRUE}
1705 VARIANT_TRUE,"UTF-8",
1707 {FALSE,(const BYTE*)szUtf8XML,sizeof(szUtf8XML)-1},
1708 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
1709 * and the writer is released.
1711 {FALSE,NULL,0},
1712 {TRUE}
1716 VARIANT_TRUE,"UTF-16",
1718 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
1719 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1720 {TRUE}
1724 VARIANT_TRUE,"UTF-16",
1726 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE,TRUE},
1727 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1728 {TRUE}
1733 static void test_mxwriter_stream(void)
1735 IMXWriter *writer;
1736 ISAXContentHandler *content;
1737 HRESULT hr;
1738 VARIANT dest;
1739 IStream *stream;
1740 LARGE_INTEGER pos;
1741 ULARGE_INTEGER pos2;
1742 DWORD test_count = sizeof(mxwriter_stream_tests)/sizeof(mxwriter_stream_tests[0]);
1744 for(current_stream_test_index = 0; current_stream_test_index < test_count; ++current_stream_test_index) {
1745 const mxwriter_stream_test *test = mxwriter_stream_tests+current_stream_test_index;
1747 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1748 &IID_IMXWriter, (void**)&writer);
1749 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
1751 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1752 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
1754 hr = IMXWriter_put_encoding(writer, _bstr_(test->encoding));
1755 ok(hr == S_OK, "put_encoding failed with %08x on test %d\n", hr, current_stream_test_index);
1757 V_VT(&dest) = VT_UNKNOWN;
1758 V_UNKNOWN(&dest) = (IUnknown*)&mxstream;
1759 hr = IMXWriter_put_output(writer, dest);
1760 ok(hr == S_OK, "put_output failed with %08x on test %d\n", hr, current_stream_test_index);
1761 VariantClear(&dest);
1763 hr = IMXWriter_put_byteOrderMark(writer, test->bom);
1764 ok(hr == S_OK, "put_byteOrderMark failed with %08x on test %d\n", hr, current_stream_test_index);
1766 current_write_test = test->expected_writes;
1768 hr = ISAXContentHandler_startDocument(content);
1769 ok(hr == S_OK, "startDocument failed with %08x on test %d\n", hr, current_stream_test_index);
1771 hr = ISAXContentHandler_endDocument(content);
1772 ok(hr == S_OK, "endDocument failed with %08x on test %d\n", hr, current_stream_test_index);
1774 ISAXContentHandler_Release(content);
1775 IMXWriter_Release(writer);
1777 ok(current_write_test->last, "The last %d write calls on test %d were missed\n",
1778 current_write_test-test->expected_writes, current_stream_test_index);
1781 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1782 &IID_IMXWriter, (void**)&writer);
1783 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
1785 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1786 ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
1788 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1789 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
1791 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
1792 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
1794 V_VT(&dest) = VT_UNKNOWN;
1795 V_UNKNOWN(&dest) = (IUnknown*)stream;
1796 hr = IMXWriter_put_output(writer, dest);
1797 ok(hr == S_OK, "put_output failed: %08x\n", hr);
1799 hr = ISAXContentHandler_startDocument(content);
1800 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
1802 /* Setting output of the mxwriter causes the current output to be flushed,
1803 * and the writer to start over.
1805 V_VT(&dest) = VT_EMPTY;
1806 hr = IMXWriter_put_output(writer, dest);
1807 ok(hr == S_OK, "put_output failed: %08x\n", hr);
1809 pos.QuadPart = 0;
1810 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1811 ok(hr == S_OK, "Seek failed: %08x\n", hr);
1812 ok(pos2.QuadPart != 0, "expected stream position moved\n");
1814 hr = ISAXContentHandler_startDocument(content);
1815 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
1817 hr = ISAXContentHandler_endDocument(content);
1818 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
1820 V_VT(&dest) = VT_EMPTY;
1821 hr = IMXWriter_get_output(writer, &dest);
1822 ok(hr == S_OK, "get_output failed: %08x\n", hr);
1823 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
1824 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1825 "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1826 VariantClear(&dest);
1828 ISAXContentHandler_Release(content);
1829 IMXWriter_Release(writer);
1831 free_bstrs();
1834 static void test_mxwriter_encoding(void)
1836 IMXWriter *writer;
1837 ISAXContentHandler *content;
1838 HRESULT hr;
1839 VARIANT dest;
1841 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1842 &IID_IMXWriter, (void**)&writer);
1843 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
1845 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1846 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
1848 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
1849 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
1851 hr = ISAXContentHandler_startDocument(content);
1852 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
1854 hr = ISAXContentHandler_endDocument(content);
1855 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
1857 /* The content is always re-encoded to UTF-16 when the output is
1858 * retrieved as a BSTR.
1860 V_VT(&dest) = VT_EMPTY;
1861 hr = IMXWriter_get_output(writer, &dest);
1862 todo_wine ok(hr == S_OK, "get_output failed: %08x\n", hr);
1863 todo_wine ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
1864 if (V_VT(&dest) == VT_BSTR) todo_wine ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1865 "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1866 VariantClear(&dest);
1868 ISAXContentHandler_Release(content);
1869 IMXWriter_Release(writer);
1871 free_bstrs();
1874 START_TEST(saxreader)
1876 ISAXXMLReader *reader;
1877 IMXWriter *writer;
1878 HRESULT hr;
1880 hr = CoInitialize(NULL);
1881 ok(hr == S_OK, "failed to init com\n");
1883 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1884 &IID_ISAXXMLReader, (void**)&reader);
1886 if(FAILED(hr))
1888 skip("Failed to create SAXXMLReader instance\n");
1889 CoUninitialize();
1890 return;
1892 ISAXXMLReader_Release(reader);
1894 test_saxreader();
1895 test_encoding();
1897 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1898 &IID_IMXWriter, (void**)&writer);
1899 if (hr == S_OK)
1901 IMXWriter_Release(writer);
1903 test_mxwriter_contenthandler();
1904 test_mxwriter_startenddocument();
1905 test_mxwriter_startendelement();
1906 test_mxwriter_characters();
1907 test_mxwriter_properties();
1908 test_mxwriter_flush();
1909 test_mxwriter_stream();
1910 test_mxwriter_encoding();
1912 else
1913 win_skip("MXXMLWriter not supported\n");
1915 CoUninitialize();