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_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
36 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
38 ULONG rc = IUnknown_AddRef(obj);
39 IUnknown_Release(obj);
40 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
43 static BSTR alloc_str_from_narrow(const char *str)
45 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
46 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
47 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
51 static BSTR alloced_bstrs[256];
52 static int alloced_bstrs_count;
54 static BSTR _bstr_(const char *str)
56 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
57 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
58 return alloced_bstrs[alloced_bstrs_count++];
61 static void free_bstrs(void)
64 for (i = 0; i < alloced_bstrs_count; i++)
65 SysFreeString(alloced_bstrs[i]);
66 alloced_bstrs_count = 0;
71 CH_PUTDOCUMENTLOCATOR,
74 CH_STARTPREFIXMAPPING,
79 CH_IGNORABLEWHITESPACE,
80 CH_PROCESSINGINSTRUCTION,
84 static const WCHAR szSimpleXML[] = {
85 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
86 '<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
87 ' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
88 ' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
89 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
92 static const WCHAR szCarriageRetTest[] = {
93 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
94 '<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
95 '\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
96 '\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
97 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\0'
100 static const WCHAR szUtf16XML[] = {
101 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"',' ',
102 'e','n','c','o','d','i','n','g','=','"','U','T','F','-','1','6','"',' ',
103 's','t','a','n','d','a','l','o','n','e','=','"','n','o','"','?','>','\r','\n'
106 static const CHAR szUtf16BOM[] = {0xff, 0xfe};
108 static const CHAR szUtf8XML[] =
109 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n";
111 static const CHAR szTestXML[] =
112 "<?xml version=\"1.0\" ?>\n"
114 " <Number>1234</Number>\n"
115 " <Name>Captain Ahab</Name>\n"
118 typedef struct _contenthandlercheck {
125 } content_handler_test;
127 static content_handler_test contentHandlerTest1[] = {
128 { CH_PUTDOCUMENTLOCATOR, 0, 0 },
129 { CH_STARTDOCUMENT, 0, 0 },
130 { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
131 { CH_CHARACTERS, 2, 14, "\n " },
132 { CH_STARTELEMENT, 3, 12, "", "Number", "Number" },
133 { CH_CHARACTERS, 3, 12, "1234" },
134 { CH_ENDELEMENT, 3, 18, "", "Number", "Number" },
135 { CH_CHARACTERS, 3, 25, "\n " },
136 { CH_STARTELEMENT, 4, 10, "", "Name", "Name" },
137 { CH_CHARACTERS, 4, 10, "Captain Ahab" },
138 { CH_ENDELEMENT, 4, 24, "", "Name", "Name" },
139 { CH_CHARACTERS, 4, 29, "\n" },
140 { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
141 { CH_ENDDOCUMENT, 0, 0 },
145 static content_handler_test contentHandlerTest2[] = {
146 { CH_PUTDOCUMENTLOCATOR, 0, 0 },
147 { CH_STARTDOCUMENT, 0, 0 },
148 { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
149 { CH_CHARACTERS, 2, 14, "\n" },
150 { CH_CHARACTERS, 2, 16, "\t" },
151 { CH_STARTELEMENT, 3, 10, "", "Number", "Number" },
152 { CH_CHARACTERS, 3, 10, "1234" },
153 { CH_ENDELEMENT, 3, 16, "", "Number", "Number" },
154 { CH_CHARACTERS, 3, 23, "\n" },
155 { CH_CHARACTERS, 3, 25, "\t" },
156 { CH_STARTELEMENT, 4, 8, "", "Name", "Name" },
157 { CH_CHARACTERS, 4, 8, "Captain Ahab" },
158 { CH_ENDELEMENT, 4, 22, "", "Name", "Name" },
159 { CH_CHARACTERS, 4, 27, "\n" },
160 { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
161 { CH_ENDDOCUMENT, 0, 0 },
165 static content_handler_test *expectCall;
166 static ISAXLocator *locator;
168 static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
174 ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
175 ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
179 len = strlen(szTest);
180 ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
184 MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
185 ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
186 wine_dbgstr_wn(szStr, nStr), szTest);
189 static BOOL test_expect_call(CH id)
191 ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
192 return expectCall->id == id;
195 static void test_locator(unsigned line, int loc_line, int loc_column)
198 ISAXLocator_getLineNumber(locator, &rline);
199 ISAXLocator_getColumnNumber(locator, &rcolumn);
201 ok_(__FILE__,line) (rline == loc_line,
202 "unexpected line %d, expected %d\n", rline, loc_line);
203 ok_(__FILE__,line) (rcolumn == loc_column,
204 "unexpected column %d, expected %d\n", rcolumn, loc_column);
207 static HRESULT WINAPI contentHandler_QueryInterface(
208 ISAXContentHandler* iface,
214 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
220 return E_NOINTERFACE;
226 static ULONG WINAPI contentHandler_AddRef(
227 ISAXContentHandler* iface)
232 static ULONG WINAPI contentHandler_Release(
233 ISAXContentHandler* iface)
238 static HRESULT WINAPI contentHandler_putDocumentLocator(
239 ISAXContentHandler* iface,
240 ISAXLocator *pLocator)
242 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
246 test_locator(__LINE__, expectCall->line, expectCall->column);
252 static HRESULT WINAPI contentHandler_startDocument(
253 ISAXContentHandler* iface)
255 if(!test_expect_call(CH_STARTDOCUMENT))
258 test_locator(__LINE__, expectCall->line, expectCall->column);
264 static HRESULT WINAPI contentHandler_endDocument(
265 ISAXContentHandler* iface)
267 if(!test_expect_call(CH_ENDDOCUMENT))
270 test_locator(__LINE__, expectCall->line, expectCall->column);
276 static HRESULT WINAPI contentHandler_startPrefixMapping(
277 ISAXContentHandler* iface,
278 const WCHAR *pPrefix,
283 if(!test_expect_call(CH_ENDDOCUMENT))
286 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
287 test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
288 test_locator(__LINE__, expectCall->line, expectCall->column);
294 static HRESULT WINAPI contentHandler_endPrefixMapping(
295 ISAXContentHandler* iface,
296 const WCHAR *pPrefix,
299 if(!test_expect_call(CH_ENDPREFIXMAPPING))
302 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
303 test_locator(__LINE__, expectCall->line, expectCall->column);
309 static HRESULT WINAPI contentHandler_startElement(
310 ISAXContentHandler* iface,
311 const WCHAR *pNamespaceUri,
313 const WCHAR *pLocalName,
317 ISAXAttributes *pAttr)
319 if(!test_expect_call(CH_STARTELEMENT))
322 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
323 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
324 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
325 test_locator(__LINE__, expectCall->line, expectCall->column);
331 static HRESULT WINAPI contentHandler_endElement(
332 ISAXContentHandler* iface,
333 const WCHAR *pNamespaceUri,
335 const WCHAR *pLocalName,
340 if(!test_expect_call(CH_ENDELEMENT))
343 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
344 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
345 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
346 test_locator(__LINE__, expectCall->line, expectCall->column);
352 static HRESULT WINAPI contentHandler_characters(
353 ISAXContentHandler* iface,
357 if(!test_expect_call(CH_CHARACTERS))
360 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
361 test_locator(__LINE__, expectCall->line, expectCall->column);
367 static HRESULT WINAPI contentHandler_ignorableWhitespace(
368 ISAXContentHandler* iface,
372 if(!test_expect_call(CH_IGNORABLEWHITESPACE))
375 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
376 test_locator(__LINE__, expectCall->line, expectCall->column);
382 static HRESULT WINAPI contentHandler_processingInstruction(
383 ISAXContentHandler* iface,
384 const WCHAR *pTarget,
389 if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
392 test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
393 test_saxstr(__LINE__, pData, nData, expectCall->arg2);
394 test_locator(__LINE__, expectCall->line, expectCall->column);
400 static HRESULT WINAPI contentHandler_skippedEntity(
401 ISAXContentHandler* iface,
405 if(!test_expect_call(CH_SKIPPEDENTITY))
408 test_saxstr(__LINE__, pName, nName, expectCall->arg1);
409 test_locator(__LINE__, expectCall->line, expectCall->column);
416 static const ISAXContentHandlerVtbl contentHandlerVtbl =
418 contentHandler_QueryInterface,
419 contentHandler_AddRef,
420 contentHandler_Release,
421 contentHandler_putDocumentLocator,
422 contentHandler_startDocument,
423 contentHandler_endDocument,
424 contentHandler_startPrefixMapping,
425 contentHandler_endPrefixMapping,
426 contentHandler_startElement,
427 contentHandler_endElement,
428 contentHandler_characters,
429 contentHandler_ignorableWhitespace,
430 contentHandler_processingInstruction,
431 contentHandler_skippedEntity
434 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
436 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
437 ISAXErrorHandler* iface,
443 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
449 return E_NOINTERFACE;
455 static ULONG WINAPI isaxerrorHandler_AddRef(
456 ISAXErrorHandler* iface)
461 static ULONG WINAPI isaxerrorHandler_Release(
462 ISAXErrorHandler* iface)
467 static HRESULT WINAPI isaxerrorHandler_error(
468 ISAXErrorHandler* iface,
469 ISAXLocator *pLocator,
470 const WCHAR *pErrorMessage,
476 static HRESULT WINAPI isaxerrorHandler_fatalError(
477 ISAXErrorHandler* iface,
478 ISAXLocator *pLocator,
479 const WCHAR *pErrorMessage,
485 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
486 ISAXErrorHandler* iface,
487 ISAXLocator *pLocator,
488 const WCHAR *pErrorMessage,
494 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
496 isaxerrorHandler_QueryInterface,
497 isaxerrorHandler_AddRef,
498 isaxerrorHandler_Release,
499 isaxerrorHandler_error,
500 isaxerrorHandler_fatalError,
501 isaxerrorHanddler_ignorableWarning
504 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
506 static HRESULT WINAPI isaxattributes_QueryInterface(
507 ISAXAttributes* iface,
513 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
519 return E_NOINTERFACE;
525 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
530 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
535 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
541 static HRESULT WINAPI isaxattributes_getURI(
542 ISAXAttributes* iface,
547 ok(0, "unexpected call\n");
551 static HRESULT WINAPI isaxattributes_getLocalName(
552 ISAXAttributes* iface,
554 const WCHAR **pLocalName,
555 int *pLocalNameLength)
557 ok(0, "unexpected call\n");
561 static HRESULT WINAPI isaxattributes_getQName(
562 ISAXAttributes* iface,
564 const WCHAR **pQName,
567 static const WCHAR attr1W[] = {'a',':','a','t','t','r','1',0};
568 static const WCHAR attr2W[] = {'a','t','t','r','2',0};
570 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
572 *pQName = (nIndex == 0) ? attr1W : attr2W;
573 *pQNameLength = lstrlenW(*pQName);
578 static HRESULT WINAPI isaxattributes_getName(
579 ISAXAttributes* iface,
583 const WCHAR ** pLocalName,
584 int * pLocalNameSize,
585 const WCHAR ** pQName,
588 ok(0, "unexpected call\n");
592 static HRESULT WINAPI isaxattributes_getIndexFromName(
593 ISAXAttributes* iface,
596 const WCHAR * pLocalName,
600 ok(0, "unexpected call\n");
604 static HRESULT WINAPI isaxattributes_getIndexFromQName(
605 ISAXAttributes* iface,
606 const WCHAR * pQName,
610 ok(0, "unexpected call\n");
614 static HRESULT WINAPI isaxattributes_getType(
615 ISAXAttributes* iface,
617 const WCHAR ** pType,
620 ok(0, "unexpected call\n");
624 static HRESULT WINAPI isaxattributes_getTypeFromName(
625 ISAXAttributes* iface,
628 const WCHAR * pLocalName,
630 const WCHAR ** pType,
633 ok(0, "unexpected call\n");
637 static HRESULT WINAPI isaxattributes_getTypeFromQName(
638 ISAXAttributes* iface,
639 const WCHAR * pQName,
641 const WCHAR ** pType,
644 ok(0, "unexpected call\n");
648 static HRESULT WINAPI isaxattributes_getValue(
649 ISAXAttributes* iface,
651 const WCHAR ** pValue,
654 static const WCHAR attrval1W[] = {'a','1',0};
655 static const WCHAR attrval2W[] = {'a','2',0};
657 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
659 *pValue = (nIndex == 0) ? attrval1W : attrval2W;
660 *nValue = lstrlenW(*pValue);
665 static HRESULT WINAPI isaxattributes_getValueFromName(
666 ISAXAttributes* iface,
669 const WCHAR * pLocalName,
671 const WCHAR ** pValue,
674 ok(0, "unexpected call\n");
678 static HRESULT WINAPI isaxattributes_getValueFromQName(
679 ISAXAttributes* iface,
680 const WCHAR * pQName,
682 const WCHAR ** pValue,
685 ok(0, "unexpected call\n");
689 static const ISAXAttributesVtbl SAXAttributesVtbl =
691 isaxattributes_QueryInterface,
692 isaxattributes_AddRef,
693 isaxattributes_Release,
694 isaxattributes_getLength,
695 isaxattributes_getURI,
696 isaxattributes_getLocalName,
697 isaxattributes_getQName,
698 isaxattributes_getName,
699 isaxattributes_getIndexFromName,
700 isaxattributes_getIndexFromQName,
701 isaxattributes_getType,
702 isaxattributes_getTypeFromName,
703 isaxattributes_getTypeFromQName,
704 isaxattributes_getValue,
705 isaxattributes_getValueFromName,
706 isaxattributes_getValueFromQName
709 static ISAXAttributes saxattributes = { &SAXAttributesVtbl };
711 typedef struct mxwriter_write_test_t {
717 } mxwriter_write_test;
719 typedef struct mxwriter_stream_test_t {
721 const char *encoding;
722 mxwriter_write_test expected_writes[4];
723 } mxwriter_stream_test;
725 static const mxwriter_write_test *current_write_test;
726 static DWORD current_stream_test_index;
728 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
732 if(IsEqualGUID(riid, &IID_IStream) || IsEqualGUID(riid, &IID_IUnknown))
735 return E_NOINTERFACE;
740 static ULONG WINAPI istream_AddRef(IStream *iface)
745 static ULONG WINAPI istream_Release(IStream *iface)
750 static HRESULT WINAPI istream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
752 ok(0, "unexpected call\n");
756 static HRESULT WINAPI istream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
760 ok(pv != NULL, "pv == NULL\n");
762 if(current_write_test->last) {
763 ok(0, "Too many Write calls made on test %d\n", current_stream_test_index);
767 fail = current_write_test->fail_write;
769 ok(current_write_test->cb == cb, "Expected %d, but got %d on test %d\n",
770 current_write_test->cb, cb, current_stream_test_index);
773 ok(current_write_test->null_written, "pcbWritten was NULL on test %d\n", current_stream_test_index);
775 ok(!memcmp(current_write_test->data, pv, cb), "Unexpected data on test %d\n", current_stream_test_index);
777 ++current_write_test;
782 return fail ? E_FAIL : S_OK;
785 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
786 ULARGE_INTEGER *plibNewPosition)
788 ok(0, "unexpected call\n");
792 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
794 ok(0, "unexpected call\n");
798 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
799 ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *plibWritten)
801 ok(0, "unexpected call\n");
805 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD grfCommitFlags)
807 ok(0, "unexpected call\n");
811 static HRESULT WINAPI istream_Revert(IStream *iface)
813 ok(0, "unexpected call\n");
817 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
818 ULARGE_INTEGER cb, DWORD dwLockType)
820 ok(0, "unexpected call\n");
824 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
825 ULARGE_INTEGER cb, DWORD dwLockType)
827 ok(0, "unexpected call\n");
831 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
833 ok(0, "unexpected call\n");
837 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **ppstm)
839 ok(0, "unexpected call\n");
843 static const IStreamVtbl StreamVtbl = {
844 istream_QueryInterface,
855 istream_UnlockRegion,
860 static IStream mxstream = { &StreamVtbl };
862 static void test_saxreader(void)
865 ISAXXMLReader *reader = NULL;
867 ISAXContentHandler *lpContentHandler;
868 ISAXErrorHandler *lpErrorHandler;
870 SAFEARRAYBOUND SADim[1];
871 char *pSAData = NULL;
873 ULARGE_INTEGER liSize;
877 static const CHAR testXmlA[] = "test.xml";
878 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
879 IXMLDOMDocument *domDocument;
883 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
884 &IID_ISAXXMLReader, (LPVOID*)&reader);
885 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
887 hr = ISAXXMLReader_getContentHandler(reader, NULL);
888 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
890 hr = ISAXXMLReader_getErrorHandler(reader, NULL);
891 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
893 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
894 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
895 ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
897 hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
898 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
899 ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
901 hr = ISAXXMLReader_putContentHandler(reader, NULL);
902 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
904 hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
905 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
907 hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
908 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
910 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
911 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
912 ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
914 V_VT(&var) = VT_BSTR;
915 V_BSTR(&var) = SysAllocString(szSimpleXML);
917 expectCall = contentHandlerTest1;
918 hr = ISAXXMLReader_parse(reader, var);
919 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
920 test_expect_call(CH_ENDTEST);
925 SADim[0].cElements= sizeof(szTestXML)-1;
926 pSA = SafeArrayCreate(VT_UI1, 1, SADim);
927 SafeArrayAccessData(pSA, (void**)&pSAData);
928 memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
929 SafeArrayUnaccessData(pSA);
930 V_VT(&var) = VT_ARRAY|VT_UI1;
933 expectCall = contentHandlerTest1;
934 hr = ISAXXMLReader_parse(reader, var);
935 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
936 test_expect_call(CH_ENDTEST);
938 SafeArrayDestroy(pSA);
940 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
941 liSize.QuadPart = strlen(szTestXML);
942 IStream_SetSize(iStream, liSize);
943 IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
945 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
946 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
947 V_UNKNOWN(&var) = (IUnknown*)iStream;
949 expectCall = contentHandlerTest1;
950 hr = ISAXXMLReader_parse(reader, var);
951 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
952 test_expect_call(CH_ENDTEST);
954 IStream_Release(iStream);
956 V_VT(&var) = VT_BSTR;
957 V_BSTR(&var) = SysAllocString(szCarriageRetTest);
959 expectCall = contentHandlerTest2;
960 hr = ISAXXMLReader_parse(reader, var);
961 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
962 test_expect_call(CH_ENDTEST);
966 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
967 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
968 WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
971 expectCall = contentHandlerTest1;
972 hr = ISAXXMLReader_parseURL(reader, testXmlW);
973 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
974 test_expect_call(CH_ENDTEST);
976 DeleteFileA(testXmlA);
978 hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
979 &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
982 skip("Failed to create DOMDocument instance\n");
985 bstrData = SysAllocString(szSimpleXML);
986 hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
987 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
988 V_VT(&var) = VT_UNKNOWN;
989 V_UNKNOWN(&var) = (IUnknown*)domDocument;
991 expectCall = contentHandlerTest2;
992 hr = ISAXXMLReader_parse(reader, var);
993 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
994 test_expect_call(CH_ENDTEST);
995 IXMLDOMDocument_Release(domDocument);
997 ISAXXMLReader_Release(reader);
998 SysFreeString(bstrData);
1001 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1002 static const CHAR UTF8BOMTest[] =
1003 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1006 struct enc_test_entry_t {
1014 static const struct enc_test_entry_t encoding_test_data[] = {
1015 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
1016 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
1017 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
1018 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
1022 static void test_encoding(void)
1024 const struct enc_test_entry_t *entry = encoding_test_data;
1025 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1026 static const CHAR testXmlA[] = "test.xml";
1027 ISAXXMLReader *reader;
1034 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1037 win_skip("can't create %s instance\n", entry->clsid);
1042 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1043 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1044 WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
1047 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1049 todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1051 ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1053 DeleteFileA(testXmlA);
1054 ISAXXMLReader_Release(reader);
1060 static void test_mxwriter_contenthandler(void)
1062 ISAXContentHandler *handler;
1063 IMXWriter *writer, *writer2;
1066 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1067 &IID_IMXWriter, (void**)&writer);
1068 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1070 EXPECT_REF(writer, 1);
1072 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
1073 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1074 EXPECT_REF(writer, 2);
1075 EXPECT_REF(handler, 2);
1077 hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
1078 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1079 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1080 EXPECT_REF(writer, 3);
1081 EXPECT_REF(writer2, 3);
1082 IMXWriter_Release(writer2);
1084 ISAXContentHandler_Release(handler);
1085 IMXWriter_Release(writer);
1088 static void test_mxwriter_properties(void)
1090 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
1091 static const WCHAR emptyW[] = {0};
1092 static const WCHAR testW[] = {'t','e','s','t',0};
1098 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1099 &IID_IMXWriter, (void**)&writer);
1100 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1102 hr = IMXWriter_get_disableOutputEscaping(writer, NULL);
1103 ok(hr == E_POINTER, "got %08x\n", hr);
1106 hr = IMXWriter_get_disableOutputEscaping(writer, &b);
1107 ok(hr == S_OK, "got %08x\n", hr);
1108 ok(b == VARIANT_FALSE, "got %d\n", b);
1110 hr = IMXWriter_get_byteOrderMark(writer, NULL);
1111 ok(hr == E_POINTER, "got %08x\n", hr);
1114 hr = IMXWriter_get_byteOrderMark(writer, &b);
1115 ok(hr == S_OK, "got %08x\n", hr);
1116 ok(b == VARIANT_TRUE, "got %d\n", b);
1118 hr = IMXWriter_get_indent(writer, NULL);
1119 ok(hr == E_POINTER, "got %08x\n", hr);
1122 hr = IMXWriter_get_indent(writer, &b);
1123 ok(hr == S_OK, "got %08x\n", hr);
1124 ok(b == VARIANT_FALSE, "got %d\n", b);
1126 hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
1127 ok(hr == E_POINTER, "got %08x\n", hr);
1130 hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
1131 ok(hr == S_OK, "got %08x\n", hr);
1132 ok(b == VARIANT_FALSE, "got %d\n", b);
1134 hr = IMXWriter_get_standalone(writer, NULL);
1135 ok(hr == E_POINTER, "got %08x\n", hr);
1138 hr = IMXWriter_get_standalone(writer, &b);
1139 ok(hr == S_OK, "got %08x\n", hr);
1140 ok(b == VARIANT_FALSE, "got %d\n", b);
1143 hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
1144 ok(hr == S_OK, "got %08x\n", hr);
1147 hr = IMXWriter_get_standalone(writer, &b);
1148 ok(hr == S_OK, "got %08x\n", hr);
1149 ok(b == VARIANT_TRUE, "got %d\n", b);
1151 hr = IMXWriter_get_encoding(writer, NULL);
1152 ok(hr == E_POINTER, "got %08x\n", hr);
1154 /* UTF-16 is a default setting apparently */
1155 str = (void*)0xdeadbeef;
1156 hr = IMXWriter_get_encoding(writer, &str);
1157 ok(hr == S_OK, "got %08x\n", hr);
1158 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1160 str2 = (void*)0xdeadbeef;
1161 hr = IMXWriter_get_encoding(writer, &str2);
1162 ok(hr == S_OK, "got %08x\n", hr);
1163 ok(str != str2, "expected newly allocated, got same %p\n", str);
1165 SysFreeString(str2);
1168 /* put empty string */
1169 str = SysAllocString(emptyW);
1170 hr = IMXWriter_put_encoding(writer, str);
1171 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1174 str = (void*)0xdeadbeef;
1175 hr = IMXWriter_get_encoding(writer, &str);
1176 ok(hr == S_OK, "got %08x\n", hr);
1177 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1180 /* invalid encoding name */
1181 str = SysAllocString(testW);
1182 hr = IMXWriter_put_encoding(writer, str);
1183 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1186 hr = IMXWriter_get_version(writer, NULL);
1187 ok(hr == E_POINTER, "got %08x\n", hr);
1188 /* default version is 'surprisingly' 1.0 */
1189 hr = IMXWriter_get_version(writer, &str);
1190 ok(hr == S_OK, "got %08x\n", hr);
1191 ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1194 IMXWriter_Release(writer);
1198 static void test_mxwriter_flush(void)
1200 ISAXContentHandler *content;
1203 ULARGE_INTEGER pos2;
1208 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1209 &IID_IMXWriter, (void**)&writer);
1210 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1212 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1213 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1214 EXPECT_REF(stream, 1);
1216 /* detach when nothing was attached */
1217 V_VT(&dest) = VT_EMPTY;
1218 hr = IMXWriter_put_output(writer, dest);
1219 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1222 V_VT(&dest) = VT_UNKNOWN;
1223 V_UNKNOWN(&dest) = (IUnknown*)stream;
1224 hr = IMXWriter_put_output(writer, dest);
1225 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1226 todo_wine EXPECT_REF(stream, 3);
1228 /* detach setting VT_EMPTY destination */
1229 V_VT(&dest) = VT_EMPTY;
1230 hr = IMXWriter_put_output(writer, dest);
1231 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1232 EXPECT_REF(stream, 1);
1234 V_VT(&dest) = VT_UNKNOWN;
1235 V_UNKNOWN(&dest) = (IUnknown*)stream;
1236 hr = IMXWriter_put_output(writer, dest);
1237 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1239 /* flush() doesn't detach a stream */
1240 hr = IMXWriter_flush(writer);
1241 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1242 todo_wine EXPECT_REF(stream, 3);
1245 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1246 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1247 ok(pos2.QuadPart == 0, "expected stream beginning");
1249 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1250 ok(hr == S_OK, "got %08x\n", hr);
1252 hr = ISAXContentHandler_startDocument(content);
1253 ok(hr == S_OK, "got %08x\n", hr);
1256 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1257 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1258 ok(pos2.QuadPart != 0, "expected stream beginning\n");
1260 /* already started */
1261 hr = ISAXContentHandler_startDocument(content);
1262 ok(hr == S_OK, "got %08x\n", hr);
1264 hr = ISAXContentHandler_endDocument(content);
1265 ok(hr == S_OK, "got %08x\n", hr);
1267 /* flushed on endDocument() */
1269 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1270 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1271 ok(pos2.QuadPart != 0, "expected stream position moved\n");
1273 ISAXContentHandler_Release(content);
1274 IStream_Release(stream);
1275 IMXWriter_Release(writer);
1278 static void test_mxwriter_startenddocument(void)
1280 ISAXContentHandler *content;
1285 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1286 &IID_IMXWriter, (void**)&writer);
1287 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1289 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1290 ok(hr == S_OK, "got %08x\n", hr);
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 V_VT(&dest) = VT_EMPTY;
1299 hr = IMXWriter_get_output(writer, &dest);
1300 ok(hr == S_OK, "got %08x\n", hr);
1301 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1302 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1303 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1304 VariantClear(&dest);
1306 /* now try another startDocument */
1307 hr = ISAXContentHandler_startDocument(content);
1308 ok(hr == S_OK, "got %08x\n", hr);
1309 /* and get duplicated prolog */
1310 V_VT(&dest) = VT_EMPTY;
1311 hr = IMXWriter_get_output(writer, &dest);
1312 ok(hr == S_OK, "got %08x\n", hr);
1313 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1314 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
1315 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1316 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1317 VariantClear(&dest);
1319 ISAXContentHandler_Release(content);
1320 IMXWriter_Release(writer);
1322 /* now with omitted declaration */
1323 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1324 &IID_IMXWriter, (void**)&writer);
1325 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1327 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1328 ok(hr == S_OK, "got %08x\n", hr);
1330 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1331 ok(hr == S_OK, "got %08x\n", hr);
1333 hr = ISAXContentHandler_startDocument(content);
1334 ok(hr == S_OK, "got %08x\n", hr);
1336 hr = ISAXContentHandler_endDocument(content);
1337 ok(hr == S_OK, "got %08x\n", hr);
1339 V_VT(&dest) = VT_EMPTY;
1340 hr = IMXWriter_get_output(writer, &dest);
1341 ok(hr == S_OK, "got %08x\n", hr);
1342 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1343 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1344 VariantClear(&dest);
1346 ISAXContentHandler_Release(content);
1347 IMXWriter_Release(writer);
1352 static void test_mxwriter_startendelement(void)
1354 static const char winehqA[] = "http://winehq.org";
1355 ISAXContentHandler *content;
1360 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1361 &IID_IMXWriter, (void**)&writer);
1362 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1364 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1365 ok(hr == S_OK, "got %08x\n", hr);
1367 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1368 ok(hr == S_OK, "got %08x\n", hr);
1370 hr = ISAXContentHandler_startDocument(content);
1371 ok(hr == S_OK, "got %08x\n", hr);
1373 /* qualified name without defined namespace */
1374 hr = ISAXContentHandler_startElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3, NULL);
1375 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1377 hr = ISAXContentHandler_startElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3, NULL);
1378 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1380 /* only local name is an error too */
1381 hr = ISAXContentHandler_startElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0, NULL);
1382 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1384 /* only local name is an error too */
1385 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, NULL, 0, NULL);
1386 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1388 /* all string pointers should be not null */
1389 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
1390 ok(hr == S_OK, "got %08x\n", hr);
1392 V_VT(&dest) = VT_EMPTY;
1393 hr = IMXWriter_get_output(writer, &dest);
1394 ok(hr == S_OK, "got %08x\n", hr);
1395 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1396 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1397 VariantClear(&dest);
1399 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
1400 ok(hr == S_OK, "got %08x\n", hr);
1402 V_VT(&dest) = VT_EMPTY;
1403 hr = IMXWriter_get_output(writer, &dest);
1404 ok(hr == S_OK, "got %08x\n", hr);
1405 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1406 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1407 VariantClear(&dest);
1409 hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
1410 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1412 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
1413 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1415 /* only local name is an error too */
1416 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
1417 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1419 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
1420 ok(hr == S_OK, "got %08x\n", hr);
1422 V_VT(&dest) = VT_EMPTY;
1423 hr = IMXWriter_get_output(writer, &dest);
1424 ok(hr == S_OK, "got %08x\n", hr);
1425 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1426 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1427 VariantClear(&dest);
1429 /* some with namespace URI */
1430 hr = ISAXContentHandler_startElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8, NULL);
1431 ok(hr == S_OK, "got %08x\n", hr);
1433 hr = ISAXContentHandler_endElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8);
1434 ok(hr == S_OK, "got %08x\n", hr);
1436 V_VT(&dest) = VT_EMPTY;
1437 hr = IMXWriter_get_output(writer, &dest);
1438 ok(hr == S_OK, "got %08x\n", hr);
1439 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1440 todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1441 VariantClear(&dest);
1443 /* try to end element that wasn't open */
1444 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
1445 ok(hr == S_OK, "got %08x\n", hr);
1447 V_VT(&dest) = VT_EMPTY;
1448 hr = IMXWriter_get_output(writer, &dest);
1449 ok(hr == S_OK, "got %08x\n", hr);
1450 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1451 todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1452 VariantClear(&dest);
1454 /* try with attributes */
1455 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, &saxattributes);
1456 ok(hr == S_OK, "got %08x\n", hr);
1458 hr = ISAXContentHandler_endDocument(content);
1459 ok(hr == S_OK, "got %08x\n", hr);
1461 ISAXContentHandler_Release(content);
1462 IMXWriter_Release(writer);
1467 static void test_mxwriter_characters(void)
1469 static const WCHAR chardataW[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
1470 ISAXContentHandler *content;
1475 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1476 &IID_IMXWriter, (void**)&writer);
1477 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1479 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1480 ok(hr == S_OK, "got %08x\n", hr);
1482 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1483 ok(hr == S_OK, "got %08x\n", hr);
1485 hr = ISAXContentHandler_startDocument(content);
1486 ok(hr == S_OK, "got %08x\n", hr);
1488 hr = ISAXContentHandler_characters(content, NULL, 0);
1489 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1491 hr = ISAXContentHandler_characters(content, chardataW, 0);
1492 ok(hr == S_OK, "got %08x\n", hr);
1494 hr = ISAXContentHandler_characters(content, chardataW, sizeof(chardataW)/sizeof(WCHAR) - 1);
1495 ok(hr == S_OK, "got %08x\n", hr);
1497 V_VT(&dest) = VT_EMPTY;
1498 hr = IMXWriter_get_output(writer, &dest);
1499 ok(hr == S_OK, "got %08x\n", hr);
1500 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1501 ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1502 VariantClear(&dest);
1504 hr = ISAXContentHandler_endDocument(content);
1505 ok(hr == S_OK, "got %08x\n", hr);
1507 ISAXContentHandler_Release(content);
1508 IMXWriter_Release(writer);
1513 static const mxwriter_stream_test mxwriter_stream_tests[] = {
1515 VARIANT_TRUE,"UTF-16",
1517 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
1518 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1523 VARIANT_FALSE,"UTF-16",
1525 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1530 VARIANT_TRUE,"UTF-8",
1532 {FALSE,(const BYTE*)szUtf8XML,sizeof(szUtf8XML)-1},
1533 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
1534 * and the writer is released.
1541 VARIANT_TRUE,"UTF-16",
1543 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
1544 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1549 VARIANT_TRUE,"UTF-16",
1551 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE,TRUE},
1552 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
1558 static void test_mxwriter_stream(void)
1561 ISAXContentHandler *content;
1566 ULARGE_INTEGER pos2;
1567 DWORD test_count = sizeof(mxwriter_stream_tests)/sizeof(mxwriter_stream_tests[0]);
1569 for(current_stream_test_index = 0; current_stream_test_index < test_count; ++current_stream_test_index) {
1570 const mxwriter_stream_test *test = mxwriter_stream_tests+current_stream_test_index;
1572 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1573 &IID_IMXWriter, (void**)&writer);
1574 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
1576 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1577 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
1579 hr = IMXWriter_put_encoding(writer, _bstr_(test->encoding));
1580 ok(hr == S_OK, "put_encoding failed with %08x on test %d\n", hr, current_stream_test_index);
1582 V_VT(&dest) = VT_UNKNOWN;
1583 V_UNKNOWN(&dest) = (IUnknown*)&mxstream;
1584 hr = IMXWriter_put_output(writer, dest);
1585 ok(hr == S_OK, "put_output failed with %08x on test %d\n", hr, current_stream_test_index);
1586 VariantClear(&dest);
1588 hr = IMXWriter_put_byteOrderMark(writer, test->bom);
1589 ok(hr == S_OK, "put_byteOrderMark failed with %08x on test %d\n", hr, current_stream_test_index);
1591 current_write_test = test->expected_writes;
1593 hr = ISAXContentHandler_startDocument(content);
1594 ok(hr == S_OK, "startDocument failed with %08x on test %d\n", hr, current_stream_test_index);
1596 hr = ISAXContentHandler_endDocument(content);
1597 ok(hr == S_OK, "endDocument failed with %08x on test %d\n", hr, current_stream_test_index);
1599 ISAXContentHandler_Release(content);
1600 IMXWriter_Release(writer);
1602 ok(current_write_test->last, "The last %d write calls on test %d were missed\n",
1603 current_write_test-test->expected_writes, current_stream_test_index);
1606 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1607 &IID_IMXWriter, (void**)&writer);
1608 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
1610 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1611 ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
1613 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1614 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
1616 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
1617 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
1619 V_VT(&dest) = VT_UNKNOWN;
1620 V_UNKNOWN(&dest) = (IUnknown*)stream;
1621 hr = IMXWriter_put_output(writer, dest);
1622 ok(hr == S_OK, "put_output failed: %08x\n", hr);
1624 hr = ISAXContentHandler_startDocument(content);
1625 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
1627 /* Setting output of the mxwriter causes the current output to be flushed,
1628 * and the writer to start over.
1630 V_VT(&dest) = VT_EMPTY;
1631 hr = IMXWriter_put_output(writer, dest);
1632 ok(hr == S_OK, "put_output failed: %08x\n", hr);
1635 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1636 ok(hr == S_OK, "Seek failed: %08x\n", hr);
1637 ok(pos2.QuadPart != 0, "expected stream position moved\n");
1639 hr = ISAXContentHandler_startDocument(content);
1640 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
1642 hr = ISAXContentHandler_endDocument(content);
1643 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
1645 V_VT(&dest) = VT_EMPTY;
1646 hr = IMXWriter_get_output(writer, &dest);
1647 ok(hr == S_OK, "get_output failed: %08x\n", hr);
1648 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
1649 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1650 "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1651 VariantClear(&dest);
1653 ISAXContentHandler_Release(content);
1654 IMXWriter_Release(writer);
1659 static void test_mxwriter_encoding(void)
1662 ISAXContentHandler *content;
1666 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1667 &IID_IMXWriter, (void**)&writer);
1668 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
1670 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1671 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
1673 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
1674 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
1676 hr = ISAXContentHandler_startDocument(content);
1677 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
1679 hr = ISAXContentHandler_endDocument(content);
1680 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
1682 /* The content is always re-encoded to UTF-16 when the output is
1683 * retrieved as a BSTR.
1685 V_VT(&dest) = VT_EMPTY;
1686 hr = IMXWriter_get_output(writer, &dest);
1687 todo_wine ok(hr == S_OK, "get_output failed: %08x\n", hr);
1688 todo_wine ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
1689 todo_wine ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1690 "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1691 VariantClear(&dest);
1693 ISAXContentHandler_Release(content);
1694 IMXWriter_Release(writer);
1699 START_TEST(saxreader)
1701 ISAXXMLReader *reader;
1705 hr = CoInitialize(NULL);
1706 ok(hr == S_OK, "failed to init com\n");
1708 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1709 &IID_ISAXXMLReader, (void**)&reader);
1713 skip("Failed to create SAXXMLReader instance\n");
1717 ISAXXMLReader_Release(reader);
1722 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1723 &IID_IMXWriter, (void**)&writer);
1726 IMXWriter_Release(writer);
1728 test_mxwriter_contenthandler();
1729 test_mxwriter_startenddocument();
1730 test_mxwriter_startendelement();
1731 test_mxwriter_characters();
1732 test_mxwriter_properties();
1733 test_mxwriter_flush();
1734 test_mxwriter_stream();
1735 test_mxwriter_encoding();
1738 win_skip("MXXMLWriter not supported\n");