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
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);
54 static BSTR alloced_bstrs[512];
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)
67 for (i = 0; i < alloced_bstrs_count; i++)
68 SysFreeString(alloced_bstrs[i]);
69 alloced_bstrs_count = 0;
74 CH_PUTDOCUMENTLOCATOR,
77 CH_STARTPREFIXMAPPING,
82 CH_IGNORABLEWHITESPACE,
83 CH_PROCESSINGINSTRUCTION,
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"
117 " <Number>1234</Number>\n"
118 " <Name>Captain Ahab</Name>\n"
121 typedef struct _contenthandlercheck {
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 },
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 },
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)
177 ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
178 ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
182 len = strlen(szTest);
183 ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
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)
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,
217 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
223 return E_NOINTERFACE;
229 static ULONG WINAPI contentHandler_AddRef(
230 ISAXContentHandler* iface)
235 static ULONG WINAPI contentHandler_Release(
236 ISAXContentHandler* iface)
241 static HRESULT WINAPI contentHandler_putDocumentLocator(
242 ISAXContentHandler* iface,
243 ISAXLocator *pLocator)
245 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
249 test_locator(__LINE__, expectCall->line, expectCall->column);
255 static HRESULT WINAPI contentHandler_startDocument(
256 ISAXContentHandler* iface)
258 if(!test_expect_call(CH_STARTDOCUMENT))
261 test_locator(__LINE__, expectCall->line, expectCall->column);
267 static HRESULT WINAPI contentHandler_endDocument(
268 ISAXContentHandler* iface)
270 if(!test_expect_call(CH_ENDDOCUMENT))
273 test_locator(__LINE__, expectCall->line, expectCall->column);
279 static HRESULT WINAPI contentHandler_startPrefixMapping(
280 ISAXContentHandler* iface,
281 const WCHAR *pPrefix,
286 if(!test_expect_call(CH_ENDDOCUMENT))
289 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
290 test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
291 test_locator(__LINE__, expectCall->line, expectCall->column);
297 static HRESULT WINAPI contentHandler_endPrefixMapping(
298 ISAXContentHandler* iface,
299 const WCHAR *pPrefix,
302 if(!test_expect_call(CH_ENDPREFIXMAPPING))
305 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
306 test_locator(__LINE__, expectCall->line, expectCall->column);
312 static HRESULT WINAPI contentHandler_startElement(
313 ISAXContentHandler* iface,
314 const WCHAR *pNamespaceUri,
316 const WCHAR *pLocalName,
320 ISAXAttributes *pAttr)
322 if(!test_expect_call(CH_STARTELEMENT))
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);
334 static HRESULT WINAPI contentHandler_endElement(
335 ISAXContentHandler* iface,
336 const WCHAR *pNamespaceUri,
338 const WCHAR *pLocalName,
343 if(!test_expect_call(CH_ENDELEMENT))
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);
355 static HRESULT WINAPI contentHandler_characters(
356 ISAXContentHandler* iface,
360 if(!test_expect_call(CH_CHARACTERS))
363 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
364 test_locator(__LINE__, expectCall->line, expectCall->column);
370 static HRESULT WINAPI contentHandler_ignorableWhitespace(
371 ISAXContentHandler* iface,
375 if(!test_expect_call(CH_IGNORABLEWHITESPACE))
378 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
379 test_locator(__LINE__, expectCall->line, expectCall->column);
385 static HRESULT WINAPI contentHandler_processingInstruction(
386 ISAXContentHandler* iface,
387 const WCHAR *pTarget,
392 if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
395 test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
396 test_saxstr(__LINE__, pData, nData, expectCall->arg2);
397 test_locator(__LINE__, expectCall->line, expectCall->column);
403 static HRESULT WINAPI contentHandler_skippedEntity(
404 ISAXContentHandler* iface,
408 if(!test_expect_call(CH_SKIPPEDENTITY))
411 test_saxstr(__LINE__, pName, nName, expectCall->arg1);
412 test_locator(__LINE__, expectCall->line, expectCall->column);
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,
446 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
452 return E_NOINTERFACE;
458 static ULONG WINAPI isaxerrorHandler_AddRef(
459 ISAXErrorHandler* iface)
464 static ULONG WINAPI isaxerrorHandler_Release(
465 ISAXErrorHandler* iface)
470 static HRESULT WINAPI isaxerrorHandler_error(
471 ISAXErrorHandler* iface,
472 ISAXLocator *pLocator,
473 const WCHAR *pErrorMessage,
479 static HRESULT WINAPI isaxerrorHandler_fatalError(
480 ISAXErrorHandler* iface,
481 ISAXLocator *pLocator,
482 const WCHAR *pErrorMessage,
488 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
489 ISAXErrorHandler* iface,
490 ISAXLocator *pLocator,
491 const WCHAR *pErrorMessage,
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,
516 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
522 return E_NOINTERFACE;
528 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
533 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
538 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
544 static HRESULT WINAPI isaxattributes_getURI(
545 ISAXAttributes* iface,
550 ok(0, "unexpected call\n");
554 static HRESULT WINAPI isaxattributes_getLocalName(
555 ISAXAttributes* iface,
557 const WCHAR **pLocalName,
558 int *pLocalNameLength)
560 ok(0, "unexpected call\n");
564 static HRESULT WINAPI isaxattributes_getQName(
565 ISAXAttributes* iface,
567 const WCHAR **pQName,
570 static const WCHAR attr1W[] = {'a',':','a','t','t','r','1','j','u','n','k',0};
571 static const WCHAR attr2W[] = {'a','t','t','r','2','j','u','n','k',0};
573 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
575 *pQName = (nIndex == 0) ? attr1W : attr2W;
576 *pQNameLength = (nIndex == 0) ? 7 : 5;
581 static HRESULT WINAPI isaxattributes_getName(
582 ISAXAttributes* iface,
586 const WCHAR ** pLocalName,
587 int * pLocalNameSize,
588 const WCHAR ** pQName,
591 ok(0, "unexpected call\n");
595 static HRESULT WINAPI isaxattributes_getIndexFromName(
596 ISAXAttributes* iface,
599 const WCHAR * pLocalName,
603 ok(0, "unexpected call\n");
607 static HRESULT WINAPI isaxattributes_getIndexFromQName(
608 ISAXAttributes* iface,
609 const WCHAR * pQName,
613 ok(0, "unexpected call\n");
617 static HRESULT WINAPI isaxattributes_getType(
618 ISAXAttributes* iface,
620 const WCHAR ** pType,
623 ok(0, "unexpected call\n");
627 static HRESULT WINAPI isaxattributes_getTypeFromName(
628 ISAXAttributes* iface,
631 const WCHAR * pLocalName,
633 const WCHAR ** pType,
636 ok(0, "unexpected call\n");
640 static HRESULT WINAPI isaxattributes_getTypeFromQName(
641 ISAXAttributes* iface,
642 const WCHAR * pQName,
644 const WCHAR ** pType,
647 ok(0, "unexpected call\n");
651 static HRESULT WINAPI isaxattributes_getValue(
652 ISAXAttributes* iface,
654 const WCHAR ** pValue,
657 static const WCHAR attrval1W[] = {'a','1','j','u','n','k',0};
658 static const WCHAR attrval2W[] = {'a','2','j','u','n','k',0};
660 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
662 *pValue = (nIndex == 0) ? attrval1W : attrval2W;
668 static HRESULT WINAPI isaxattributes_getValueFromName(
669 ISAXAttributes* iface,
672 const WCHAR * pLocalName,
674 const WCHAR ** pValue,
677 ok(0, "unexpected call\n");
681 static HRESULT WINAPI isaxattributes_getValueFromQName(
682 ISAXAttributes* iface,
683 const WCHAR * pQName,
685 const WCHAR ** pValue,
688 ok(0, "unexpected call\n");
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 static int handler_addrefcalled;
716 static HRESULT WINAPI isaxlexical_QueryInterface(ISAXLexicalHandler* iface, REFIID riid, void **ppvObject)
720 if(IsEqualGUID(riid, &IID_IUnknown) ||
721 IsEqualGUID(riid, &IID_ISAXLexicalHandler))
727 return E_NOINTERFACE;
733 static ULONG WINAPI isaxlexical_AddRef(ISAXLexicalHandler* iface)
735 handler_addrefcalled++;
739 static ULONG WINAPI isaxlexical_Release(ISAXLexicalHandler* iface)
744 static HRESULT WINAPI isaxlexical_startDTD(ISAXLexicalHandler* iface,
745 const WCHAR * pName, int nName, const WCHAR * pPublicId,
746 int nPublicId, const WCHAR * pSystemId, int nSystemId)
748 ok(0, "call not expected\n");
752 static HRESULT WINAPI isaxlexical_endDTD(ISAXLexicalHandler* iface)
754 ok(0, "call not expected\n");
758 static HRESULT WINAPI isaxlexical_startEntity(ISAXLexicalHandler *iface,
759 const WCHAR * pName, int nName)
761 ok(0, "call not expected\n");
765 static HRESULT WINAPI isaxlexical_endEntity(ISAXLexicalHandler *iface,
766 const WCHAR * pName, int nName)
768 ok(0, "call not expected\n");
772 static HRESULT WINAPI isaxlexical_startCDATA(ISAXLexicalHandler *iface)
774 ok(0, "call not expected\n");
778 static HRESULT WINAPI isaxlexical_endCDATA(ISAXLexicalHandler *iface)
780 ok(0, "call not expected\n");
784 static HRESULT WINAPI isaxlexical_comment(ISAXLexicalHandler *iface,
785 const WCHAR * pChars, int nChars)
787 ok(0, "call not expected\n");
791 static const ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl =
793 isaxlexical_QueryInterface,
796 isaxlexical_startDTD,
798 isaxlexical_startEntity,
799 isaxlexical_endEntity,
800 isaxlexical_startCDATA,
801 isaxlexical_endCDATA,
805 static ISAXLexicalHandler saxlexicalhandler = { &SAXLexicalHandlerVtbl };
807 static HRESULT WINAPI isaxdecl_QueryInterface(ISAXDeclHandler* iface, REFIID riid, void **ppvObject)
811 if(IsEqualGUID(riid, &IID_IUnknown) ||
812 IsEqualGUID(riid, &IID_ISAXDeclHandler))
818 return E_NOINTERFACE;
824 static ULONG WINAPI isaxdecl_AddRef(ISAXDeclHandler* iface)
826 handler_addrefcalled++;
830 static ULONG WINAPI isaxdecl_Release(ISAXDeclHandler* iface)
835 static HRESULT WINAPI isaxdecl_elementDecl(ISAXDeclHandler* iface,
836 const WCHAR * pName, int nName, const WCHAR * pModel, int nModel)
838 ok(0, "call not expected\n");
842 static HRESULT WINAPI isaxdecl_attributeDecl(ISAXDeclHandler* iface,
843 const WCHAR * pElementName, int nElementName, const WCHAR * pAttributeName,
844 int nAttributeName, const WCHAR * pType, int nType, const WCHAR * pValueDefault,
845 int nValueDefault, const WCHAR * pValue, int nValue)
847 ok(0, "call not expected\n");
851 static HRESULT WINAPI isaxdecl_internalEntityDecl(ISAXDeclHandler* iface,
852 const WCHAR * pName, int nName, const WCHAR * pValue, int nValue)
854 ok(0, "call not expected\n");
858 static HRESULT WINAPI isaxdecl_externalEntityDecl(ISAXDeclHandler* iface,
859 const WCHAR * pName, int nName, const WCHAR * pPublicId, int nPublicId,
860 const WCHAR * pSystemId, int nSystemId)
862 ok(0, "call not expected\n");
866 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl =
868 isaxdecl_QueryInterface,
871 isaxdecl_elementDecl,
872 isaxdecl_attributeDecl,
873 isaxdecl_internalEntityDecl,
874 isaxdecl_externalEntityDecl
877 static ISAXDeclHandler saxdeclhandler = { &SAXDeclHandlerVtbl };
879 typedef struct mxwriter_write_test_t {
885 } mxwriter_write_test;
887 typedef struct mxwriter_stream_test_t {
889 const char *encoding;
890 mxwriter_write_test expected_writes[4];
891 } mxwriter_stream_test;
893 static const mxwriter_write_test *current_write_test;
894 static DWORD current_stream_test_index;
896 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
900 if(IsEqualGUID(riid, &IID_IStream) || IsEqualGUID(riid, &IID_IUnknown))
903 return E_NOINTERFACE;
908 static ULONG WINAPI istream_AddRef(IStream *iface)
913 static ULONG WINAPI istream_Release(IStream *iface)
918 static HRESULT WINAPI istream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
920 ok(0, "unexpected call\n");
924 static HRESULT WINAPI istream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
928 ok(pv != NULL, "pv == NULL\n");
930 if(current_write_test->last) {
931 ok(0, "Too many Write calls made on test %d\n", current_stream_test_index);
935 fail = current_write_test->fail_write;
937 ok(current_write_test->cb == cb, "Expected %d, but got %d on test %d\n",
938 current_write_test->cb, cb, current_stream_test_index);
941 ok(current_write_test->null_written, "pcbWritten was NULL on test %d\n", current_stream_test_index);
943 ok(!memcmp(current_write_test->data, pv, cb), "Unexpected data on test %d\n", current_stream_test_index);
945 ++current_write_test;
950 return fail ? E_FAIL : S_OK;
953 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
954 ULARGE_INTEGER *plibNewPosition)
956 ok(0, "unexpected call\n");
960 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
962 ok(0, "unexpected call\n");
966 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
967 ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *plibWritten)
969 ok(0, "unexpected call\n");
973 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD grfCommitFlags)
975 ok(0, "unexpected call\n");
979 static HRESULT WINAPI istream_Revert(IStream *iface)
981 ok(0, "unexpected call\n");
985 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
986 ULARGE_INTEGER cb, DWORD dwLockType)
988 ok(0, "unexpected call\n");
992 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
993 ULARGE_INTEGER cb, DWORD dwLockType)
995 ok(0, "unexpected call\n");
999 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
1001 ok(0, "unexpected call\n");
1005 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **ppstm)
1007 ok(0, "unexpected call\n");
1011 static const IStreamVtbl StreamVtbl = {
1012 istream_QueryInterface,
1023 istream_UnlockRegion,
1028 static IStream mxstream = { &StreamVtbl };
1030 static void test_saxreader(void)
1033 ISAXXMLReader *reader = NULL;
1035 ISAXContentHandler *lpContentHandler;
1036 ISAXErrorHandler *lpErrorHandler;
1038 SAFEARRAYBOUND SADim[1];
1039 char *pSAData = NULL;
1041 ULARGE_INTEGER liSize;
1042 LARGE_INTEGER liPos;
1045 static const CHAR testXmlA[] = "test.xml";
1046 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1047 IXMLDOMDocument *domDocument;
1051 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1052 &IID_ISAXXMLReader, (LPVOID*)&reader);
1053 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1055 hr = ISAXXMLReader_getContentHandler(reader, NULL);
1056 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1058 hr = ISAXXMLReader_getErrorHandler(reader, NULL);
1059 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1061 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1062 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1063 ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
1065 hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
1066 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1067 ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
1069 hr = ISAXXMLReader_putContentHandler(reader, NULL);
1070 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1072 hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
1073 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1075 hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
1076 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1078 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1079 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1080 ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
1082 V_VT(&var) = VT_BSTR;
1083 V_BSTR(&var) = SysAllocString(szSimpleXML);
1085 expectCall = contentHandlerTest1;
1086 hr = ISAXXMLReader_parse(reader, var);
1087 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1088 test_expect_call(CH_ENDTEST);
1092 SADim[0].lLbound= 0;
1093 SADim[0].cElements= sizeof(szTestXML)-1;
1094 pSA = SafeArrayCreate(VT_UI1, 1, SADim);
1095 SafeArrayAccessData(pSA, (void**)&pSAData);
1096 memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
1097 SafeArrayUnaccessData(pSA);
1098 V_VT(&var) = VT_ARRAY|VT_UI1;
1099 V_ARRAY(&var) = pSA;
1101 expectCall = contentHandlerTest1;
1102 hr = ISAXXMLReader_parse(reader, var);
1103 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1104 test_expect_call(CH_ENDTEST);
1106 SafeArrayDestroy(pSA);
1108 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1109 liSize.QuadPart = strlen(szTestXML);
1110 IStream_SetSize(iStream, liSize);
1111 IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
1113 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1114 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1115 V_UNKNOWN(&var) = (IUnknown*)iStream;
1117 expectCall = contentHandlerTest1;
1118 hr = ISAXXMLReader_parse(reader, var);
1119 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1120 test_expect_call(CH_ENDTEST);
1122 IStream_Release(iStream);
1124 V_VT(&var) = VT_BSTR;
1125 V_BSTR(&var) = SysAllocString(szCarriageRetTest);
1127 expectCall = contentHandlerTest2;
1128 hr = ISAXXMLReader_parse(reader, var);
1129 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1130 test_expect_call(CH_ENDTEST);
1134 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1135 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1136 WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
1139 expectCall = contentHandlerTest1;
1140 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1141 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1142 test_expect_call(CH_ENDTEST);
1144 DeleteFileA(testXmlA);
1146 hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
1147 &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
1150 skip("Failed to create DOMDocument instance\n");
1153 bstrData = SysAllocString(szSimpleXML);
1154 hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
1155 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1156 V_VT(&var) = VT_UNKNOWN;
1157 V_UNKNOWN(&var) = (IUnknown*)domDocument;
1159 expectCall = contentHandlerTest2;
1160 hr = ISAXXMLReader_parse(reader, var);
1161 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1162 test_expect_call(CH_ENDTEST);
1163 IXMLDOMDocument_Release(domDocument);
1165 ISAXXMLReader_Release(reader);
1166 SysFreeString(bstrData);
1169 struct saxreader_props_test_t
1171 const char *prop_name;
1175 static const struct saxreader_props_test_t props_test_data[] = {
1176 { "http://xml.org/sax/properties/lexical-handler", (IUnknown*)&saxlexicalhandler },
1177 { "http://xml.org/sax/properties/declaration-handler", (IUnknown*)&saxdeclhandler },
1181 static void test_saxreader_properties(void)
1183 const struct saxreader_props_test_t *ptr = props_test_data;
1184 ISAXXMLReader *reader;
1187 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1188 &IID_ISAXXMLReader, (void**)&reader);
1189 EXPECT_HR(hr, S_OK);
1191 hr = ISAXXMLReader_getProperty(reader, _bstr_("http://xml.org/sax/properties/lexical-handler"), NULL);
1192 EXPECT_HR(hr, E_POINTER);
1194 while (ptr->prop_name)
1198 V_VT(&v) = VT_EMPTY;
1199 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1200 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1201 EXPECT_HR(hr, S_OK);
1202 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1203 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1205 V_VT(&v) = VT_UNKNOWN;
1206 V_UNKNOWN(&v) = ptr->iface;
1207 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1208 EXPECT_HR(hr, S_OK);
1210 V_VT(&v) = VT_EMPTY;
1211 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1212 handler_addrefcalled = 0;
1213 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1214 EXPECT_HR(hr, S_OK);
1215 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1216 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1217 ok(handler_addrefcalled == 1, "AddRef called %d times\n", handler_addrefcalled);
1220 V_VT(&v) = VT_EMPTY;
1221 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1222 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1223 EXPECT_HR(hr, S_OK);
1225 V_VT(&v) = VT_EMPTY;
1226 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1227 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1228 EXPECT_HR(hr, S_OK);
1229 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1230 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1232 V_VT(&v) = VT_UNKNOWN;
1233 V_UNKNOWN(&v) = ptr->iface;
1234 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1235 EXPECT_HR(hr, S_OK);
1237 /* only VT_EMPTY seems to be valid to reset property */
1239 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1240 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1241 EXPECT_HR(hr, E_INVALIDARG);
1243 V_VT(&v) = VT_EMPTY;
1244 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1245 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1246 EXPECT_HR(hr, S_OK);
1247 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1248 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1251 V_VT(&v) = VT_UNKNOWN;
1252 V_UNKNOWN(&v) = NULL;
1253 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1254 EXPECT_HR(hr, S_OK);
1256 V_VT(&v) = VT_EMPTY;
1257 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1258 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1259 EXPECT_HR(hr, S_OK);
1260 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1261 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1266 ISAXXMLReader_Release(reader);
1270 struct feature_ns_entry_t {
1276 static const struct feature_ns_entry_t feature_ns_entry_data[] = {
1277 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", VARIANT_TRUE },
1278 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", VARIANT_TRUE },
1279 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", VARIANT_TRUE },
1280 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", VARIANT_TRUE },
1284 static void test_saxreader_features(void)
1286 const struct feature_ns_entry_t *entry = feature_ns_entry_data;
1287 ISAXXMLReader *reader;
1294 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1297 win_skip("can't create %s instance\n", entry->clsid);
1303 hr = ISAXXMLReader_getFeature(reader, _bstr_("http://xml.org/sax/features/namespaces"), &value);
1304 EXPECT_HR(hr, S_OK);
1306 ok(entry->value == value, "%s: got wrong default value %x, expected %x\n", entry->clsid, value, entry->value);
1308 ISAXXMLReader_Release(reader);
1314 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1315 static const CHAR UTF8BOMTest[] =
1316 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1319 struct enc_test_entry_t {
1327 static const struct enc_test_entry_t encoding_test_data[] = {
1328 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
1329 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
1330 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
1331 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
1335 static void test_encoding(void)
1337 const struct enc_test_entry_t *entry = encoding_test_data;
1338 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1339 static const CHAR testXmlA[] = "test.xml";
1340 ISAXXMLReader *reader;
1347 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1350 win_skip("can't create %s instance\n", entry->clsid);
1355 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1356 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1357 WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
1360 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1362 todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1364 ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1366 DeleteFileA(testXmlA);
1367 ISAXXMLReader_Release(reader);
1373 static void test_mxwriter_contenthandler(void)
1375 ISAXContentHandler *handler;
1376 IMXWriter *writer, *writer2;
1379 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1380 &IID_IMXWriter, (void**)&writer);
1381 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1383 EXPECT_REF(writer, 1);
1385 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
1386 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1387 EXPECT_REF(writer, 2);
1388 EXPECT_REF(handler, 2);
1390 hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
1391 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1392 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1393 EXPECT_REF(writer, 3);
1394 EXPECT_REF(writer2, 3);
1395 IMXWriter_Release(writer2);
1397 ISAXContentHandler_Release(handler);
1398 IMXWriter_Release(writer);
1401 struct msxmlsupported_data_t
1408 static struct msxmlsupported_data_t msxmlsupported_data[] =
1410 { &CLSID_MXXMLWriter, "MXXMLWriter" },
1411 { &CLSID_MXXMLWriter30, "MXXMLWriter30" },
1412 { &CLSID_MXXMLWriter40, "MXXMLWriter40" },
1413 { &CLSID_MXXMLWriter60, "MXXMLWriter60" },
1417 static BOOL is_mxwriter_supported(const GUID *clsid, const struct msxmlsupported_data_t *table)
1419 while (table->clsid)
1421 if (table->clsid == clsid) return table->supported;
1427 struct mxwriter_props_t
1431 VARIANT_BOOL disable_escape;
1432 VARIANT_BOOL indent;
1433 VARIANT_BOOL omitdecl;
1434 VARIANT_BOOL standalone;
1435 const char *encoding;
1438 static const struct mxwriter_props_t mxwriter_default_props[] =
1440 { &CLSID_MXXMLWriter, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1441 { &CLSID_MXXMLWriter30, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1442 { &CLSID_MXXMLWriter40, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1443 { &CLSID_MXXMLWriter60, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1447 static void test_mxwriter_default_properties(const struct mxwriter_props_t *table)
1451 while (table->clsid)
1458 if (!is_mxwriter_supported(table->clsid, msxmlsupported_data))
1465 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1466 &IID_IMXWriter, (void**)&writer);
1467 EXPECT_HR(hr, S_OK);
1470 hr = IMXWriter_get_byteOrderMark(writer, &b);
1471 EXPECT_HR(hr, S_OK);
1472 ok(table->bom == b, "test %d: got BOM %d, expected %d\n", i, b, table->bom);
1474 b = !table->disable_escape;
1475 hr = IMXWriter_get_disableOutputEscaping(writer, &b);
1476 EXPECT_HR(hr, S_OK);
1477 ok(table->disable_escape == b, "test %d: got disable escape %d, expected %d\n", i, b,
1478 table->disable_escape);
1481 hr = IMXWriter_get_indent(writer, &b);
1482 EXPECT_HR(hr, S_OK);
1483 ok(table->indent == b, "test %d: got indent %d, expected %d\n", i, b, table->indent);
1485 b = !table->omitdecl;
1486 hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
1487 EXPECT_HR(hr, S_OK);
1488 ok(table->omitdecl == b, "test %d: got omitdecl %d, expected %d\n", i, b, table->omitdecl);
1490 b = !table->standalone;
1491 hr = IMXWriter_get_standalone(writer, &b);
1492 EXPECT_HR(hr, S_OK);
1493 ok(table->standalone == b, "test %d: got standalone %d, expected %d\n", i, b, table->standalone);
1495 hr = IMXWriter_get_encoding(writer, &encoding);
1496 EXPECT_HR(hr, S_OK);
1497 ok(!lstrcmpW(encoding, _bstr_(table->encoding)), "test %d: got encoding %s, expected %s\n",
1498 i, wine_dbgstr_w(encoding), table->encoding);
1499 SysFreeString(encoding);
1501 IMXWriter_Release(writer);
1508 static void test_mxwriter_properties(void)
1510 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
1511 static const WCHAR emptyW[] = {0};
1512 static const WCHAR testW[] = {'t','e','s','t',0};
1518 test_mxwriter_default_properties(mxwriter_default_props);
1520 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1521 &IID_IMXWriter, (void**)&writer);
1522 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1524 hr = IMXWriter_get_disableOutputEscaping(writer, NULL);
1525 ok(hr == E_POINTER, "got %08x\n", hr);
1527 hr = IMXWriter_get_byteOrderMark(writer, NULL);
1528 ok(hr == E_POINTER, "got %08x\n", hr);
1530 hr = IMXWriter_get_indent(writer, NULL);
1531 ok(hr == E_POINTER, "got %08x\n", hr);
1533 hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
1534 ok(hr == E_POINTER, "got %08x\n", hr);
1536 hr = IMXWriter_get_standalone(writer, NULL);
1537 ok(hr == E_POINTER, "got %08x\n", hr);
1540 hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
1541 ok(hr == S_OK, "got %08x\n", hr);
1544 hr = IMXWriter_get_standalone(writer, &b);
1545 ok(hr == S_OK, "got %08x\n", hr);
1546 ok(b == VARIANT_TRUE, "got %d\n", b);
1548 hr = IMXWriter_get_encoding(writer, NULL);
1549 ok(hr == E_POINTER, "got %08x\n", hr);
1551 /* UTF-16 is a default setting apparently */
1552 str = (void*)0xdeadbeef;
1553 hr = IMXWriter_get_encoding(writer, &str);
1554 ok(hr == S_OK, "got %08x\n", hr);
1555 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1557 str2 = (void*)0xdeadbeef;
1558 hr = IMXWriter_get_encoding(writer, &str2);
1559 ok(hr == S_OK, "got %08x\n", hr);
1560 ok(str != str2, "expected newly allocated, got same %p\n", str);
1562 SysFreeString(str2);
1565 /* put empty string */
1566 str = SysAllocString(emptyW);
1567 hr = IMXWriter_put_encoding(writer, str);
1568 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1571 str = (void*)0xdeadbeef;
1572 hr = IMXWriter_get_encoding(writer, &str);
1573 ok(hr == S_OK, "got %08x\n", hr);
1574 ok(!lstrcmpW(str, emptyW) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1577 /* invalid encoding name */
1578 str = SysAllocString(testW);
1579 hr = IMXWriter_put_encoding(writer, str);
1580 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1583 hr = IMXWriter_get_version(writer, NULL);
1584 ok(hr == E_POINTER, "got %08x\n", hr);
1585 /* default version is 'surprisingly' 1.0 */
1586 hr = IMXWriter_get_version(writer, &str);
1587 ok(hr == S_OK, "got %08x\n", hr);
1588 ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1591 /* store version string as is */
1592 hr = IMXWriter_put_version(writer, NULL);
1593 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1595 hr = IMXWriter_put_version(writer, _bstr_("1.0"));
1596 ok(hr == S_OK, "got %08x\n", hr);
1598 hr = IMXWriter_put_version(writer, _bstr_(""));
1599 ok(hr == S_OK, "got %08x\n", hr);
1600 hr = IMXWriter_get_version(writer, &str);
1601 ok(hr == S_OK, "got %08x\n", hr);
1602 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
1605 hr = IMXWriter_put_version(writer, _bstr_("a.b"));
1606 ok(hr == S_OK, "got %08x\n", hr);
1607 hr = IMXWriter_get_version(writer, &str);
1608 ok(hr == S_OK, "got %08x\n", hr);
1609 ok(!lstrcmpW(str, _bstr_("a.b")), "got %s\n", wine_dbgstr_w(str));
1612 hr = IMXWriter_put_version(writer, _bstr_("2.0"));
1613 ok(hr == S_OK, "got %08x\n", hr);
1614 hr = IMXWriter_get_version(writer, &str);
1615 ok(hr == S_OK, "got %08x\n", hr);
1616 ok(!lstrcmpW(str, _bstr_("2.0")), "got %s\n", wine_dbgstr_w(str));
1619 IMXWriter_Release(writer);
1623 static void test_mxwriter_flush(void)
1625 ISAXContentHandler *content;
1628 ULARGE_INTEGER pos2;
1633 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1634 &IID_IMXWriter, (void**)&writer);
1635 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1637 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1638 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1639 EXPECT_REF(stream, 1);
1641 /* detach when nothing was attached */
1642 V_VT(&dest) = VT_EMPTY;
1643 hr = IMXWriter_put_output(writer, dest);
1644 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1647 V_VT(&dest) = VT_UNKNOWN;
1648 V_UNKNOWN(&dest) = (IUnknown*)stream;
1649 hr = IMXWriter_put_output(writer, dest);
1650 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1651 todo_wine EXPECT_REF(stream, 3);
1653 /* detach setting VT_EMPTY destination */
1654 V_VT(&dest) = VT_EMPTY;
1655 hr = IMXWriter_put_output(writer, dest);
1656 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1657 EXPECT_REF(stream, 1);
1659 V_VT(&dest) = VT_UNKNOWN;
1660 V_UNKNOWN(&dest) = (IUnknown*)stream;
1661 hr = IMXWriter_put_output(writer, dest);
1662 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1664 /* flush() doesn't detach a stream */
1665 hr = IMXWriter_flush(writer);
1666 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1667 todo_wine EXPECT_REF(stream, 3);
1670 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1671 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1672 ok(pos2.QuadPart == 0, "expected stream beginning\n");
1674 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1675 ok(hr == S_OK, "got %08x\n", hr);
1677 hr = ISAXContentHandler_startDocument(content);
1678 ok(hr == S_OK, "got %08x\n", hr);
1681 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1682 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1683 ok(pos2.QuadPart != 0, "expected stream beginning\n");
1685 /* already started */
1686 hr = ISAXContentHandler_startDocument(content);
1687 ok(hr == S_OK, "got %08x\n", hr);
1689 hr = ISAXContentHandler_endDocument(content);
1690 ok(hr == S_OK, "got %08x\n", hr);
1692 /* flushed on endDocument() */
1694 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1695 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1696 ok(pos2.QuadPart != 0, "expected stream position moved\n");
1698 ISAXContentHandler_Release(content);
1699 IStream_Release(stream);
1700 IMXWriter_Release(writer);
1703 static void test_mxwriter_startenddocument(void)
1705 ISAXContentHandler *content;
1710 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1711 &IID_IMXWriter, (void**)&writer);
1712 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1714 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1715 ok(hr == S_OK, "got %08x\n", hr);
1717 hr = ISAXContentHandler_startDocument(content);
1718 ok(hr == S_OK, "got %08x\n", hr);
1720 hr = ISAXContentHandler_endDocument(content);
1721 ok(hr == S_OK, "got %08x\n", hr);
1723 V_VT(&dest) = VT_EMPTY;
1724 hr = IMXWriter_get_output(writer, &dest);
1725 ok(hr == S_OK, "got %08x\n", hr);
1726 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1727 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1728 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1729 VariantClear(&dest);
1731 /* now try another startDocument */
1732 hr = ISAXContentHandler_startDocument(content);
1733 ok(hr == S_OK, "got %08x\n", hr);
1734 /* and get duplicated prolog */
1735 V_VT(&dest) = VT_EMPTY;
1736 hr = IMXWriter_get_output(writer, &dest);
1737 ok(hr == S_OK, "got %08x\n", hr);
1738 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1739 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
1740 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1741 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1742 VariantClear(&dest);
1744 ISAXContentHandler_Release(content);
1745 IMXWriter_Release(writer);
1747 /* now with omitted declaration */
1748 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1749 &IID_IMXWriter, (void**)&writer);
1750 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1752 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1753 ok(hr == S_OK, "got %08x\n", hr);
1755 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1756 ok(hr == S_OK, "got %08x\n", hr);
1758 hr = ISAXContentHandler_startDocument(content);
1759 ok(hr == S_OK, "got %08x\n", hr);
1761 hr = ISAXContentHandler_endDocument(content);
1762 ok(hr == S_OK, "got %08x\n", hr);
1764 V_VT(&dest) = VT_EMPTY;
1765 hr = IMXWriter_get_output(writer, &dest);
1766 ok(hr == S_OK, "got %08x\n", hr);
1767 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1768 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1769 VariantClear(&dest);
1771 ISAXContentHandler_Release(content);
1772 IMXWriter_Release(writer);
1784 struct writer_startendelement_t {
1786 enum startendtype type;
1788 const char *local_name;
1792 ISAXAttributes *attr;
1795 static const struct writer_startendelement_t writer_startendelement[] = {
1797 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
1798 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
1799 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
1800 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, NULL, "<>", S_OK },
1801 { &CLSID_MXXMLWriter, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
1803 { &CLSID_MXXMLWriter30, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
1804 { &CLSID_MXXMLWriter40, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
1805 { &CLSID_MXXMLWriter60, StartElement, "uri", NULL, NULL, "<>", S_OK },
1806 { &CLSID_MXXMLWriter, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
1807 { &CLSID_MXXMLWriter30, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
1809 { &CLSID_MXXMLWriter40, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
1810 { &CLSID_MXXMLWriter60, StartElement, NULL, "local", NULL, "<>", S_OK },
1811 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
1812 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
1813 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
1815 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, "qname", "<qname>", S_OK },
1816 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "qname", "<qname>", S_OK },
1817 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "qname", "<qname>", S_OK },
1818 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "qname", "<qname>", S_OK },
1819 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "qname", "<qname>", S_OK },
1821 { &CLSID_MXXMLWriter, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
1822 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
1823 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
1824 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", NULL, "<>", S_OK },
1825 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
1827 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
1828 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
1829 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
1830 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1831 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1833 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1834 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
1835 /* endElement tests */
1836 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
1837 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
1838 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
1840 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, NULL, "</>", S_OK },
1841 { &CLSID_MXXMLWriter, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
1842 { &CLSID_MXXMLWriter30, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
1843 { &CLSID_MXXMLWriter40, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
1844 { &CLSID_MXXMLWriter60, EndElement, "uri", NULL, NULL, "</>", S_OK },
1846 { &CLSID_MXXMLWriter, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
1847 { &CLSID_MXXMLWriter30, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
1848 { &CLSID_MXXMLWriter40, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
1849 { &CLSID_MXXMLWriter60, EndElement, NULL, "local", NULL, "</>", S_OK },
1850 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
1852 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
1853 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
1854 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, "qname", "</qname>", S_OK },
1855 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "qname", "</qname>", S_OK },
1856 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "qname", "</qname>", S_OK },
1858 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "qname", "</qname>", S_OK },
1859 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "qname", "</qname>", S_OK },
1860 { &CLSID_MXXMLWriter, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
1861 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
1862 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
1864 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", NULL, "</>", S_OK },
1865 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
1866 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
1867 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
1868 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
1870 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
1871 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
1872 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
1873 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
1875 /* with attributes */
1876 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK, &saxattributes },
1878 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK, &saxattributes },
1879 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK, &saxattributes },
1880 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK, &saxattributes },
1881 /* empty elements */
1882 { &CLSID_MXXMLWriter, StartEndElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK, &saxattributes },
1883 { &CLSID_MXXMLWriter30, StartEndElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK, &saxattributes },
1885 { &CLSID_MXXMLWriter40, StartEndElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK, &saxattributes },
1886 { &CLSID_MXXMLWriter60, StartEndElement, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK, &saxattributes },
1887 { &CLSID_MXXMLWriter, StartEndElement, "", "", "", "</>", S_OK },
1888 { &CLSID_MXXMLWriter30, StartEndElement, "", "", "", "</>", S_OK },
1889 { &CLSID_MXXMLWriter40, StartEndElement, "", "", "", "</>", S_OK },
1891 { &CLSID_MXXMLWriter60, StartEndElement, "", "", "", "</>", S_OK },
1895 static void get_supported_mxwriter_data(struct msxmlsupported_data_t *table)
1897 while (table->clsid)
1902 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1903 &IID_IMXWriter, (void**)&writer);
1904 if (hr == S_OK) IMXWriter_Release(writer);
1906 table->supported = hr == S_OK;
1907 if (hr != S_OK) win_skip("class %s not supported\n", table->name);
1913 static void test_mxwriter_startendelement_batch(const struct writer_startendelement_t *table)
1917 while (table->clsid)
1919 ISAXContentHandler *content;
1923 if (!is_mxwriter_supported(table->clsid, msxmlsupported_data))
1930 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1931 &IID_IMXWriter, (void**)&writer);
1932 EXPECT_HR(hr, S_OK);
1934 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1935 EXPECT_HR(hr, S_OK);
1937 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1938 EXPECT_HR(hr, S_OK);
1940 hr = ISAXContentHandler_startDocument(content);
1941 EXPECT_HR(hr, S_OK);
1943 if (table->type == StartElement)
1945 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
1946 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
1947 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
1949 else if (table->type == EndElement)
1951 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
1952 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
1953 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
1957 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
1958 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
1959 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
1960 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
1961 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
1962 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
1970 V_VT(&dest) = VT_EMPTY;
1971 hr = IMXWriter_get_output(writer, &dest);
1972 EXPECT_HR(hr, S_OK);
1973 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1974 ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
1975 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
1976 VariantClear(&dest);
1979 ISAXContentHandler_Release(content);
1980 IMXWriter_Release(writer);
1989 static void test_mxwriter_startendelement(void)
1991 ISAXContentHandler *content;
1996 test_mxwriter_startendelement_batch(writer_startendelement);
1998 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1999 &IID_IMXWriter, (void**)&writer);
2000 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2002 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2003 ok(hr == S_OK, "got %08x\n", hr);
2005 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2006 ok(hr == S_OK, "got %08x\n", hr);
2008 hr = ISAXContentHandler_startDocument(content);
2009 ok(hr == S_OK, "got %08x\n", hr);
2011 /* all string pointers should be not null */
2012 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
2013 ok(hr == S_OK, "got %08x\n", hr);
2015 V_VT(&dest) = VT_EMPTY;
2016 hr = IMXWriter_get_output(writer, &dest);
2017 ok(hr == S_OK, "got %08x\n", hr);
2018 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2019 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2020 VariantClear(&dest);
2022 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
2023 ok(hr == S_OK, "got %08x\n", hr);
2025 V_VT(&dest) = VT_EMPTY;
2026 hr = IMXWriter_get_output(writer, &dest);
2027 ok(hr == S_OK, "got %08x\n", hr);
2028 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2029 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2030 VariantClear(&dest);
2032 hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
2033 EXPECT_HR(hr, E_INVALIDARG);
2035 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
2036 EXPECT_HR(hr, E_INVALIDARG);
2038 /* only local name is an error too */
2039 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
2040 EXPECT_HR(hr, E_INVALIDARG);
2042 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
2043 EXPECT_HR(hr, S_OK);
2045 V_VT(&dest) = VT_EMPTY;
2046 hr = IMXWriter_get_output(writer, &dest);
2047 EXPECT_HR(hr, S_OK);
2048 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2049 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2050 VariantClear(&dest);
2052 hr = ISAXContentHandler_endDocument(content);
2053 EXPECT_HR(hr, S_OK);
2055 V_VT(&dest) = VT_EMPTY;
2056 hr = IMXWriter_put_output(writer, dest);
2057 EXPECT_HR(hr, S_OK);
2059 hr = ISAXContentHandler_startDocument(content);
2060 EXPECT_HR(hr, S_OK);
2062 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abcdef"), 3, NULL);
2063 EXPECT_HR(hr, S_OK);
2065 V_VT(&dest) = VT_EMPTY;
2066 hr = IMXWriter_get_output(writer, &dest);
2067 EXPECT_HR(hr, S_OK);
2068 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2069 ok(!lstrcmpW(_bstr_("<abc>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2070 VariantClear(&dest);
2072 ISAXContentHandler_endDocument(content);
2073 IMXWriter_flush(writer);
2075 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abdcdef"), 3);
2076 EXPECT_HR(hr, S_OK);
2077 V_VT(&dest) = VT_EMPTY;
2078 hr = IMXWriter_get_output(writer, &dest);
2079 EXPECT_HR(hr, S_OK);
2080 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2081 ok(!lstrcmpW(_bstr_("<abc></abd>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2082 VariantClear(&dest);
2084 ISAXContentHandler_Release(content);
2085 IMXWriter_Release(writer);
2089 static void test_mxwriter_characters(void)
2091 static const WCHAR chardataW[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
2092 ISAXContentHandler *content;
2097 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2098 &IID_IMXWriter, (void**)&writer);
2099 EXPECT_HR(hr, S_OK);
2101 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2102 EXPECT_HR(hr, S_OK);
2104 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2105 EXPECT_HR(hr, S_OK);
2107 hr = ISAXContentHandler_startDocument(content);
2108 EXPECT_HR(hr, S_OK);
2110 hr = ISAXContentHandler_characters(content, NULL, 0);
2111 EXPECT_HR(hr, E_INVALIDARG);
2113 hr = ISAXContentHandler_characters(content, chardataW, 0);
2114 EXPECT_HR(hr, S_OK);
2116 hr = ISAXContentHandler_characters(content, chardataW, sizeof(chardataW)/sizeof(WCHAR) - 1);
2117 EXPECT_HR(hr, S_OK);
2119 V_VT(&dest) = VT_EMPTY;
2120 hr = IMXWriter_get_output(writer, &dest);
2121 EXPECT_HR(hr, S_OK);
2122 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2123 ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2124 VariantClear(&dest);
2126 hr = ISAXContentHandler_endDocument(content);
2127 EXPECT_HR(hr, S_OK);
2129 ISAXContentHandler_Release(content);
2130 IMXWriter_Release(writer);
2132 /* try empty characters data to see if element is closed */
2133 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2134 &IID_IMXWriter, (void**)&writer);
2135 EXPECT_HR(hr, S_OK);
2137 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2138 EXPECT_HR(hr, S_OK);
2140 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2141 EXPECT_HR(hr, S_OK);
2143 hr = ISAXContentHandler_startDocument(content);
2144 EXPECT_HR(hr, S_OK);
2146 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2147 EXPECT_HR(hr, S_OK);
2149 hr = ISAXContentHandler_characters(content, chardataW, 0);
2150 EXPECT_HR(hr, S_OK);
2152 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2153 EXPECT_HR(hr, S_OK);
2155 V_VT(&dest) = VT_EMPTY;
2156 hr = IMXWriter_get_output(writer, &dest);
2157 EXPECT_HR(hr, S_OK);
2158 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2159 ok(!lstrcmpW(_bstr_("<a></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2160 VariantClear(&dest);
2162 ISAXContentHandler_Release(content);
2163 IMXWriter_Release(writer);
2168 static const mxwriter_stream_test mxwriter_stream_tests[] = {
2170 VARIANT_TRUE,"UTF-16",
2172 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2173 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2178 VARIANT_FALSE,"UTF-16",
2180 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2185 VARIANT_TRUE,"UTF-8",
2187 {FALSE,(const BYTE*)szUtf8XML,sizeof(szUtf8XML)-1},
2188 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2189 * and the writer is released.
2196 VARIANT_TRUE,"UTF-16",
2198 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2199 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2204 VARIANT_TRUE,"UTF-16",
2206 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE,TRUE},
2207 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2213 static void test_mxwriter_stream(void)
2216 ISAXContentHandler *content;
2221 ULARGE_INTEGER pos2;
2222 DWORD test_count = sizeof(mxwriter_stream_tests)/sizeof(mxwriter_stream_tests[0]);
2224 for(current_stream_test_index = 0; current_stream_test_index < test_count; ++current_stream_test_index) {
2225 const mxwriter_stream_test *test = mxwriter_stream_tests+current_stream_test_index;
2227 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2228 &IID_IMXWriter, (void**)&writer);
2229 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2231 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2232 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2234 hr = IMXWriter_put_encoding(writer, _bstr_(test->encoding));
2235 ok(hr == S_OK, "put_encoding failed with %08x on test %d\n", hr, current_stream_test_index);
2237 V_VT(&dest) = VT_UNKNOWN;
2238 V_UNKNOWN(&dest) = (IUnknown*)&mxstream;
2239 hr = IMXWriter_put_output(writer, dest);
2240 ok(hr == S_OK, "put_output failed with %08x on test %d\n", hr, current_stream_test_index);
2241 VariantClear(&dest);
2243 hr = IMXWriter_put_byteOrderMark(writer, test->bom);
2244 ok(hr == S_OK, "put_byteOrderMark failed with %08x on test %d\n", hr, current_stream_test_index);
2246 current_write_test = test->expected_writes;
2248 hr = ISAXContentHandler_startDocument(content);
2249 ok(hr == S_OK, "startDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2251 hr = ISAXContentHandler_endDocument(content);
2252 ok(hr == S_OK, "endDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2254 ISAXContentHandler_Release(content);
2255 IMXWriter_Release(writer);
2257 ok(current_write_test->last, "The last %d write calls on test %d were missed\n",
2258 (int)(current_write_test-test->expected_writes), current_stream_test_index);
2261 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2262 &IID_IMXWriter, (void**)&writer);
2263 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2265 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2266 ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
2268 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2269 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2271 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2272 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
2274 V_VT(&dest) = VT_UNKNOWN;
2275 V_UNKNOWN(&dest) = (IUnknown*)stream;
2276 hr = IMXWriter_put_output(writer, dest);
2277 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2279 hr = ISAXContentHandler_startDocument(content);
2280 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2282 /* Setting output of the mxwriter causes the current output to be flushed,
2283 * and the writer to start over.
2285 V_VT(&dest) = VT_EMPTY;
2286 hr = IMXWriter_put_output(writer, dest);
2287 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2290 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2291 ok(hr == S_OK, "Seek failed: %08x\n", hr);
2292 ok(pos2.QuadPart != 0, "expected stream position moved\n");
2294 hr = ISAXContentHandler_startDocument(content);
2295 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2297 hr = ISAXContentHandler_endDocument(content);
2298 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
2300 V_VT(&dest) = VT_EMPTY;
2301 hr = IMXWriter_get_output(writer, &dest);
2302 ok(hr == S_OK, "get_output failed: %08x\n", hr);
2303 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2304 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2305 "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2306 VariantClear(&dest);
2308 ISAXContentHandler_Release(content);
2309 IMXWriter_Release(writer);
2314 static void test_mxwriter_encoding(void)
2317 ISAXContentHandler *content;
2321 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2322 &IID_IMXWriter, (void**)&writer);
2323 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2325 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2326 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2328 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2329 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
2331 hr = ISAXContentHandler_startDocument(content);
2332 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2334 hr = ISAXContentHandler_endDocument(content);
2335 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
2337 /* The content is always re-encoded to UTF-16 when the output is
2338 * retrieved as a BSTR.
2340 V_VT(&dest) = VT_EMPTY;
2341 hr = IMXWriter_get_output(writer, &dest);
2342 todo_wine ok(hr == S_OK, "get_output failed: %08x\n", hr);
2343 todo_wine ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2344 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)),
2345 "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2346 VariantClear(&dest);
2348 ISAXContentHandler_Release(content);
2349 IMXWriter_Release(writer);
2354 START_TEST(saxreader)
2356 ISAXXMLReader *reader;
2359 hr = CoInitialize(NULL);
2360 ok(hr == S_OK, "failed to init com\n");
2362 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
2363 &IID_ISAXXMLReader, (void**)&reader);
2367 skip("Failed to create SAXXMLReader instance\n");
2371 ISAXXMLReader_Release(reader);
2374 test_saxreader_properties();
2375 test_saxreader_features();
2378 /* MXXMLWriter tests */
2379 get_supported_mxwriter_data(msxmlsupported_data);
2380 if (is_mxwriter_supported(&CLSID_MXXMLWriter, msxmlsupported_data))
2382 test_mxwriter_contenthandler();
2383 test_mxwriter_startenddocument();
2384 test_mxwriter_startendelement();
2385 test_mxwriter_characters();
2386 test_mxwriter_properties();
2387 test_mxwriter_flush();
2388 test_mxwriter_stream();
2389 test_mxwriter_encoding();
2392 win_skip("MXXMLWriter not supported\n");