msxml3: Support indent() property.
[wine/multimedia.git] / dlls / msxml3 / tests / saxreader.c
blobfd076298aeab46c810e90e54d22b46596098a4ff
1 /*
2 * XML test
4 * Copyright 2008 Piotr Caban
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <stdio.h>
25 #include <assert.h>
27 #include "windows.h"
28 #include "ole2.h"
29 #include "msxml2.h"
30 #include "ocidl.h"
32 #include "wine/test.h"
34 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
35 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
37 ULONG rc = IUnknown_AddRef(obj);
38 IUnknown_Release(obj);
39 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
42 static BSTR alloc_str_from_narrow(const char *str)
44 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
45 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
46 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
47 return ret;
50 static BSTR alloced_bstrs[256];
51 static int alloced_bstrs_count;
53 static BSTR _bstr_(const char *str)
55 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
56 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
57 return alloced_bstrs[alloced_bstrs_count++];
60 static void free_bstrs(void)
62 int i;
63 for (i = 0; i < alloced_bstrs_count; i++)
64 SysFreeString(alloced_bstrs[i]);
65 alloced_bstrs_count = 0;
68 typedef enum _CH {
69 CH_ENDTEST,
70 CH_PUTDOCUMENTLOCATOR,
71 CH_STARTDOCUMENT,
72 CH_ENDDOCUMENT,
73 CH_STARTPREFIXMAPPING,
74 CH_ENDPREFIXMAPPING,
75 CH_STARTELEMENT,
76 CH_ENDELEMENT,
77 CH_CHARACTERS,
78 CH_IGNORABLEWHITESPACE,
79 CH_PROCESSINGINSTRUCTION,
80 CH_SKIPPEDENTITY
81 } CH;
83 static const WCHAR szSimpleXML[] = {
84 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
85 '<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
86 ' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
87 ' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
88 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
91 static const WCHAR szCarriageRetTest[] = {
92 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
93 '<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
94 '\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
95 '\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
96 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\0'
99 static const CHAR szTestXML[] =
100 "<?xml version=\"1.0\" ?>\n"
101 "<BankAccount>\n"
102 " <Number>1234</Number>\n"
103 " <Name>Captain Ahab</Name>\n"
104 "</BankAccount>\n";
106 typedef struct _contenthandlercheck {
107 CH id;
108 int line;
109 int column;
110 const char *arg1;
111 const char *arg2;
112 const char *arg3;
113 } content_handler_test;
115 static content_handler_test contentHandlerTest1[] = {
116 { CH_PUTDOCUMENTLOCATOR, 0, 0 },
117 { CH_STARTDOCUMENT, 0, 0 },
118 { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
119 { CH_CHARACTERS, 2, 14, "\n " },
120 { CH_STARTELEMENT, 3, 12, "", "Number", "Number" },
121 { CH_CHARACTERS, 3, 12, "1234" },
122 { CH_ENDELEMENT, 3, 18, "", "Number", "Number" },
123 { CH_CHARACTERS, 3, 25, "\n " },
124 { CH_STARTELEMENT, 4, 10, "", "Name", "Name" },
125 { CH_CHARACTERS, 4, 10, "Captain Ahab" },
126 { CH_ENDELEMENT, 4, 24, "", "Name", "Name" },
127 { CH_CHARACTERS, 4, 29, "\n" },
128 { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
129 { CH_ENDDOCUMENT, 0, 0 },
130 { CH_ENDTEST }
133 static content_handler_test contentHandlerTest2[] = {
134 { CH_PUTDOCUMENTLOCATOR, 0, 0 },
135 { CH_STARTDOCUMENT, 0, 0 },
136 { CH_STARTELEMENT, 2, 14, "", "BankAccount", "BankAccount" },
137 { CH_CHARACTERS, 2, 14, "\n" },
138 { CH_CHARACTERS, 2, 16, "\t" },
139 { CH_STARTELEMENT, 3, 10, "", "Number", "Number" },
140 { CH_CHARACTERS, 3, 10, "1234" },
141 { CH_ENDELEMENT, 3, 16, "", "Number", "Number" },
142 { CH_CHARACTERS, 3, 23, "\n" },
143 { CH_CHARACTERS, 3, 25, "\t" },
144 { CH_STARTELEMENT, 4, 8, "", "Name", "Name" },
145 { CH_CHARACTERS, 4, 8, "Captain Ahab" },
146 { CH_ENDELEMENT, 4, 22, "", "Name", "Name" },
147 { CH_CHARACTERS, 4, 27, "\n" },
148 { CH_ENDELEMENT, 5, 3, "", "BankAccount", "BankAccount" },
149 { CH_ENDDOCUMENT, 0, 0 },
150 { CH_ENDTEST }
153 static content_handler_test *expectCall;
154 static ISAXLocator *locator;
156 static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
158 WCHAR buf[1024];
159 int len;
161 if(!szTest) {
162 ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
163 ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
164 return;
167 len = strlen(szTest);
168 ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
169 if(len != nStr)
170 return;
172 MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
173 ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
174 wine_dbgstr_wn(szStr, nStr), szTest);
177 static BOOL test_expect_call(CH id)
179 ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
180 return expectCall->id == id;
183 static void test_locator(unsigned line, int loc_line, int loc_column)
185 int rcolumn, rline;
186 ISAXLocator_getLineNumber(locator, &rline);
187 ISAXLocator_getColumnNumber(locator, &rcolumn);
189 ok_(__FILE__,line) (rline == loc_line,
190 "unexpected line %d, expected %d\n", rline, loc_line);
191 ok_(__FILE__,line) (rcolumn == loc_column,
192 "unexpected column %d, expected %d\n", rcolumn, loc_column);
195 static HRESULT WINAPI contentHandler_QueryInterface(
196 ISAXContentHandler* iface,
197 REFIID riid,
198 void **ppvObject)
200 *ppvObject = NULL;
202 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
204 *ppvObject = iface;
206 else
208 return E_NOINTERFACE;
211 return S_OK;
214 static ULONG WINAPI contentHandler_AddRef(
215 ISAXContentHandler* iface)
217 return 2;
220 static ULONG WINAPI contentHandler_Release(
221 ISAXContentHandler* iface)
223 return 1;
226 static HRESULT WINAPI contentHandler_putDocumentLocator(
227 ISAXContentHandler* iface,
228 ISAXLocator *pLocator)
230 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
231 return E_FAIL;
233 locator = pLocator;
234 test_locator(__LINE__, expectCall->line, expectCall->column);
236 expectCall++;
237 return S_OK;
240 static HRESULT WINAPI contentHandler_startDocument(
241 ISAXContentHandler* iface)
243 if(!test_expect_call(CH_STARTDOCUMENT))
244 return E_FAIL;
246 test_locator(__LINE__, expectCall->line, expectCall->column);
248 expectCall++;
249 return S_OK;
252 static HRESULT WINAPI contentHandler_endDocument(
253 ISAXContentHandler* iface)
255 if(!test_expect_call(CH_ENDDOCUMENT))
256 return E_FAIL;
258 test_locator(__LINE__, expectCall->line, expectCall->column);
260 expectCall++;
261 return S_OK;
264 static HRESULT WINAPI contentHandler_startPrefixMapping(
265 ISAXContentHandler* iface,
266 const WCHAR *pPrefix,
267 int nPrefix,
268 const WCHAR *pUri,
269 int nUri)
271 if(!test_expect_call(CH_ENDDOCUMENT))
272 return E_FAIL;
274 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
275 test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
276 test_locator(__LINE__, expectCall->line, expectCall->column);
278 expectCall++;
279 return S_OK;
282 static HRESULT WINAPI contentHandler_endPrefixMapping(
283 ISAXContentHandler* iface,
284 const WCHAR *pPrefix,
285 int nPrefix)
287 if(!test_expect_call(CH_ENDPREFIXMAPPING))
288 return E_FAIL;
290 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
291 test_locator(__LINE__, expectCall->line, expectCall->column);
293 expectCall++;
294 return S_OK;
297 static HRESULT WINAPI contentHandler_startElement(
298 ISAXContentHandler* iface,
299 const WCHAR *pNamespaceUri,
300 int nNamespaceUri,
301 const WCHAR *pLocalName,
302 int nLocalName,
303 const WCHAR *pQName,
304 int nQName,
305 ISAXAttributes *pAttr)
307 if(!test_expect_call(CH_STARTELEMENT))
308 return E_FAIL;
310 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
311 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
312 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
313 test_locator(__LINE__, expectCall->line, expectCall->column);
315 expectCall++;
316 return S_OK;
319 static HRESULT WINAPI contentHandler_endElement(
320 ISAXContentHandler* iface,
321 const WCHAR *pNamespaceUri,
322 int nNamespaceUri,
323 const WCHAR *pLocalName,
324 int nLocalName,
325 const WCHAR *pQName,
326 int nQName)
328 if(!test_expect_call(CH_ENDELEMENT))
329 return E_FAIL;
331 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
332 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
333 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
334 test_locator(__LINE__, expectCall->line, expectCall->column);
336 expectCall++;
337 return S_OK;
340 static HRESULT WINAPI contentHandler_characters(
341 ISAXContentHandler* iface,
342 const WCHAR *pChars,
343 int nChars)
345 if(!test_expect_call(CH_CHARACTERS))
346 return E_FAIL;
348 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
349 test_locator(__LINE__, expectCall->line, expectCall->column);
351 expectCall++;
352 return S_OK;
355 static HRESULT WINAPI contentHandler_ignorableWhitespace(
356 ISAXContentHandler* iface,
357 const WCHAR *pChars,
358 int nChars)
360 if(!test_expect_call(CH_IGNORABLEWHITESPACE))
361 return E_FAIL;
363 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
364 test_locator(__LINE__, expectCall->line, expectCall->column);
366 expectCall++;
367 return S_OK;
370 static HRESULT WINAPI contentHandler_processingInstruction(
371 ISAXContentHandler* iface,
372 const WCHAR *pTarget,
373 int nTarget,
374 const WCHAR *pData,
375 int nData)
377 if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
378 return E_FAIL;
380 test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
381 test_saxstr(__LINE__, pData, nData, expectCall->arg2);
382 test_locator(__LINE__, expectCall->line, expectCall->column);
384 expectCall++;
385 return S_OK;
388 static HRESULT WINAPI contentHandler_skippedEntity(
389 ISAXContentHandler* iface,
390 const WCHAR *pName,
391 int nName)
393 if(!test_expect_call(CH_SKIPPEDENTITY))
394 return E_FAIL;
396 test_saxstr(__LINE__, pName, nName, expectCall->arg1);
397 test_locator(__LINE__, expectCall->line, expectCall->column);
399 expectCall++;
400 return S_OK;
404 static const ISAXContentHandlerVtbl contentHandlerVtbl =
406 contentHandler_QueryInterface,
407 contentHandler_AddRef,
408 contentHandler_Release,
409 contentHandler_putDocumentLocator,
410 contentHandler_startDocument,
411 contentHandler_endDocument,
412 contentHandler_startPrefixMapping,
413 contentHandler_endPrefixMapping,
414 contentHandler_startElement,
415 contentHandler_endElement,
416 contentHandler_characters,
417 contentHandler_ignorableWhitespace,
418 contentHandler_processingInstruction,
419 contentHandler_skippedEntity
422 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
424 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
425 ISAXErrorHandler* iface,
426 REFIID riid,
427 void **ppvObject)
429 *ppvObject = NULL;
431 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
433 *ppvObject = iface;
435 else
437 return E_NOINTERFACE;
440 return S_OK;
443 static ULONG WINAPI isaxerrorHandler_AddRef(
444 ISAXErrorHandler* iface)
446 return 2;
449 static ULONG WINAPI isaxerrorHandler_Release(
450 ISAXErrorHandler* iface)
452 return 1;
455 static HRESULT WINAPI isaxerrorHandler_error(
456 ISAXErrorHandler* iface,
457 ISAXLocator *pLocator,
458 const WCHAR *pErrorMessage,
459 HRESULT hrErrorCode)
461 return S_OK;
464 static HRESULT WINAPI isaxerrorHandler_fatalError(
465 ISAXErrorHandler* iface,
466 ISAXLocator *pLocator,
467 const WCHAR *pErrorMessage,
468 HRESULT hrErrorCode)
470 return S_OK;
473 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
474 ISAXErrorHandler* iface,
475 ISAXLocator *pLocator,
476 const WCHAR *pErrorMessage,
477 HRESULT hrErrorCode)
479 return S_OK;
482 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
484 isaxerrorHandler_QueryInterface,
485 isaxerrorHandler_AddRef,
486 isaxerrorHandler_Release,
487 isaxerrorHandler_error,
488 isaxerrorHandler_fatalError,
489 isaxerrorHanddler_ignorableWarning
492 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
494 static HRESULT WINAPI isaxattributes_QueryInterface(
495 ISAXAttributes* iface,
496 REFIID riid,
497 void **ppvObject)
499 *ppvObject = NULL;
501 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
503 *ppvObject = iface;
505 else
507 return E_NOINTERFACE;
510 return S_OK;
513 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
515 return 2;
518 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
520 return 1;
523 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
525 *length = 2;
526 return S_OK;
529 static HRESULT WINAPI isaxattributes_getURI(
530 ISAXAttributes* iface,
531 int nIndex,
532 const WCHAR **pUrl,
533 int *pUriSize)
535 ok(0, "unexpected call\n");
536 return E_NOTIMPL;
539 static HRESULT WINAPI isaxattributes_getLocalName(
540 ISAXAttributes* iface,
541 int nIndex,
542 const WCHAR **pLocalName,
543 int *pLocalNameLength)
545 ok(0, "unexpected call\n");
546 return E_NOTIMPL;
549 static HRESULT WINAPI isaxattributes_getQName(
550 ISAXAttributes* iface,
551 int nIndex,
552 const WCHAR **pQName,
553 int *pQNameLength)
555 static const WCHAR attr1W[] = {'a',':','a','t','t','r','1',0};
556 static const WCHAR attr2W[] = {'a','t','t','r','2',0};
558 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
560 *pQName = (nIndex == 0) ? attr1W : attr2W;
561 *pQNameLength = lstrlenW(*pQName);
563 return S_OK;
566 static HRESULT WINAPI isaxattributes_getName(
567 ISAXAttributes* iface,
568 int nIndex,
569 const WCHAR **pUri,
570 int * pUriLength,
571 const WCHAR ** pLocalName,
572 int * pLocalNameSize,
573 const WCHAR ** pQName,
574 int * pQNameLength)
576 ok(0, "unexpected call\n");
577 return E_NOTIMPL;
580 static HRESULT WINAPI isaxattributes_getIndexFromName(
581 ISAXAttributes* iface,
582 const WCHAR * pUri,
583 int cUriLength,
584 const WCHAR * pLocalName,
585 int cocalNameLength,
586 int * index)
588 ok(0, "unexpected call\n");
589 return E_NOTIMPL;
592 static HRESULT WINAPI isaxattributes_getIndexFromQName(
593 ISAXAttributes* iface,
594 const WCHAR * pQName,
595 int nQNameLength,
596 int * index)
598 ok(0, "unexpected call\n");
599 return E_NOTIMPL;
602 static HRESULT WINAPI isaxattributes_getType(
603 ISAXAttributes* iface,
604 int nIndex,
605 const WCHAR ** pType,
606 int * pTypeLength)
608 ok(0, "unexpected call\n");
609 return E_NOTIMPL;
612 static HRESULT WINAPI isaxattributes_getTypeFromName(
613 ISAXAttributes* iface,
614 const WCHAR * pUri,
615 int nUri,
616 const WCHAR * pLocalName,
617 int nLocalName,
618 const WCHAR ** pType,
619 int * nType)
621 ok(0, "unexpected call\n");
622 return E_NOTIMPL;
625 static HRESULT WINAPI isaxattributes_getTypeFromQName(
626 ISAXAttributes* iface,
627 const WCHAR * pQName,
628 int nQName,
629 const WCHAR ** pType,
630 int * nType)
632 ok(0, "unexpected call\n");
633 return E_NOTIMPL;
636 static HRESULT WINAPI isaxattributes_getValue(
637 ISAXAttributes* iface,
638 int nIndex,
639 const WCHAR ** pValue,
640 int * nValue)
642 static const WCHAR attrval1W[] = {'a','1',0};
643 static const WCHAR attrval2W[] = {'a','2',0};
645 ok(nIndex == 0 || nIndex == 1, "invalid index received %d\n", nIndex);
647 *pValue = (nIndex == 0) ? attrval1W : attrval2W;
648 *nValue = lstrlenW(*pValue);
650 return S_OK;
653 static HRESULT WINAPI isaxattributes_getValueFromName(
654 ISAXAttributes* iface,
655 const WCHAR * pUri,
656 int nUri,
657 const WCHAR * pLocalName,
658 int nLocalName,
659 const WCHAR ** pValue,
660 int * nValue)
662 ok(0, "unexpected call\n");
663 return E_NOTIMPL;
666 static HRESULT WINAPI isaxattributes_getValueFromQName(
667 ISAXAttributes* iface,
668 const WCHAR * pQName,
669 int nQName,
670 const WCHAR ** pValue,
671 int * nValue)
673 ok(0, "unexpected call\n");
674 return E_NOTIMPL;
677 static const ISAXAttributesVtbl SAXAttributesVtbl =
679 isaxattributes_QueryInterface,
680 isaxattributes_AddRef,
681 isaxattributes_Release,
682 isaxattributes_getLength,
683 isaxattributes_getURI,
684 isaxattributes_getLocalName,
685 isaxattributes_getQName,
686 isaxattributes_getName,
687 isaxattributes_getIndexFromName,
688 isaxattributes_getIndexFromQName,
689 isaxattributes_getType,
690 isaxattributes_getTypeFromName,
691 isaxattributes_getTypeFromQName,
692 isaxattributes_getValue,
693 isaxattributes_getValueFromName,
694 isaxattributes_getValueFromQName
697 static ISAXAttributes saxattributes = { &SAXAttributesVtbl };
699 static void test_saxreader(void)
701 HRESULT hr;
702 ISAXXMLReader *reader = NULL;
703 VARIANT var;
704 ISAXContentHandler *lpContentHandler;
705 ISAXErrorHandler *lpErrorHandler;
706 SAFEARRAY *pSA;
707 SAFEARRAYBOUND SADim[1];
708 char *pSAData = NULL;
709 IStream *iStream;
710 ULARGE_INTEGER liSize;
711 LARGE_INTEGER liPos;
712 ULONG bytesWritten;
713 HANDLE file;
714 static const CHAR testXmlA[] = "test.xml";
715 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
716 IXMLDOMDocument *domDocument;
717 BSTR bstrData;
718 VARIANT_BOOL vBool;
720 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
721 &IID_ISAXXMLReader, (LPVOID*)&reader);
722 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
724 hr = ISAXXMLReader_getContentHandler(reader, NULL);
725 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
727 hr = ISAXXMLReader_getErrorHandler(reader, NULL);
728 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
730 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
731 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
732 ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
734 hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
735 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
736 ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
738 hr = ISAXXMLReader_putContentHandler(reader, NULL);
739 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
741 hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
742 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
744 hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
745 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
747 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
748 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
749 ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
751 V_VT(&var) = VT_BSTR;
752 V_BSTR(&var) = SysAllocString(szSimpleXML);
754 expectCall = contentHandlerTest1;
755 hr = ISAXXMLReader_parse(reader, var);
756 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
757 test_expect_call(CH_ENDTEST);
759 VariantClear(&var);
761 SADim[0].lLbound= 0;
762 SADim[0].cElements= sizeof(szTestXML)-1;
763 pSA = SafeArrayCreate(VT_UI1, 1, SADim);
764 SafeArrayAccessData(pSA, (void**)&pSAData);
765 memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
766 SafeArrayUnaccessData(pSA);
767 V_VT(&var) = VT_ARRAY|VT_UI1;
768 V_ARRAY(&var) = pSA;
770 expectCall = contentHandlerTest1;
771 hr = ISAXXMLReader_parse(reader, var);
772 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
773 test_expect_call(CH_ENDTEST);
775 SafeArrayDestroy(pSA);
777 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
778 liSize.QuadPart = strlen(szTestXML);
779 IStream_SetSize(iStream, liSize);
780 IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
781 liPos.QuadPart = 0;
782 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
783 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
784 V_UNKNOWN(&var) = (IUnknown*)iStream;
786 expectCall = contentHandlerTest1;
787 hr = ISAXXMLReader_parse(reader, var);
788 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
789 test_expect_call(CH_ENDTEST);
791 IStream_Release(iStream);
793 V_VT(&var) = VT_BSTR;
794 V_BSTR(&var) = SysAllocString(szCarriageRetTest);
796 expectCall = contentHandlerTest2;
797 hr = ISAXXMLReader_parse(reader, var);
798 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
799 test_expect_call(CH_ENDTEST);
801 VariantClear(&var);
803 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
804 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
805 WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
806 CloseHandle(file);
808 expectCall = contentHandlerTest1;
809 hr = ISAXXMLReader_parseURL(reader, testXmlW);
810 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
811 test_expect_call(CH_ENDTEST);
813 DeleteFileA(testXmlA);
815 hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
816 &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
817 if(FAILED(hr))
819 skip("Failed to create DOMDocument instance\n");
820 return;
822 bstrData = SysAllocString(szSimpleXML);
823 hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
824 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
825 V_VT(&var) = VT_UNKNOWN;
826 V_UNKNOWN(&var) = (IUnknown*)domDocument;
828 expectCall = contentHandlerTest2;
829 hr = ISAXXMLReader_parse(reader, var);
830 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
831 test_expect_call(CH_ENDTEST);
832 IXMLDOMDocument_Release(domDocument);
834 ISAXXMLReader_Release(reader);
835 SysFreeString(bstrData);
838 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
839 static const CHAR UTF8BOMTest[] =
840 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
841 "<a></a>\n";
843 struct enc_test_entry_t {
844 const GUID *guid;
845 const char *clsid;
846 const char *data;
847 HRESULT hr;
848 int todo;
851 static const struct enc_test_entry_t encoding_test_data[] = {
852 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
853 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
854 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
855 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
856 { 0 }
859 static void test_encoding(void)
861 const struct enc_test_entry_t *entry = encoding_test_data;
862 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
863 static const CHAR testXmlA[] = "test.xml";
864 ISAXXMLReader *reader;
865 DWORD written;
866 HANDLE file;
867 HRESULT hr;
869 while (entry->guid)
871 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
872 if (hr != S_OK)
874 win_skip("can't create %s instance\n", entry->clsid);
875 entry++;
876 continue;
879 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
880 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
881 WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
882 CloseHandle(file);
884 hr = ISAXXMLReader_parseURL(reader, testXmlW);
885 if (entry->todo)
886 todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
887 else
888 ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
890 DeleteFileA(testXmlA);
891 ISAXXMLReader_Release(reader);
893 entry++;
897 static void test_mxwriter_contenthandler(void)
899 ISAXContentHandler *handler;
900 IMXWriter *writer, *writer2;
901 HRESULT hr;
903 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
904 &IID_IMXWriter, (void**)&writer);
905 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
907 EXPECT_REF(writer, 1);
909 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
910 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
911 EXPECT_REF(writer, 2);
912 EXPECT_REF(handler, 2);
914 hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
915 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
916 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
917 EXPECT_REF(writer, 3);
918 EXPECT_REF(writer2, 3);
919 IMXWriter_Release(writer2);
921 ISAXContentHandler_Release(handler);
922 IMXWriter_Release(writer);
925 static void test_mxwriter_properties(void)
927 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
928 static const WCHAR emptyW[] = {0};
929 static const WCHAR testW[] = {'t','e','s','t',0};
930 IMXWriter *writer;
931 VARIANT_BOOL b;
932 HRESULT hr;
933 BSTR str, str2;
935 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
936 &IID_IMXWriter, (void**)&writer);
937 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
939 hr = IMXWriter_get_indent(writer, NULL);
940 ok(hr == E_POINTER, "got %08x\n", hr);
942 b = VARIANT_TRUE;
943 hr = IMXWriter_get_indent(writer, &b);
944 ok(hr == S_OK, "got %08x\n", hr);
945 ok(b == VARIANT_FALSE, "got %d\n", b);
947 hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
948 ok(hr == E_POINTER, "got %08x\n", hr);
950 b = VARIANT_TRUE;
951 hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
952 ok(hr == S_OK, "got %08x\n", hr);
953 ok(b == VARIANT_FALSE, "got %d\n", b);
955 hr = IMXWriter_get_standalone(writer, NULL);
956 ok(hr == E_POINTER, "got %08x\n", hr);
958 b = VARIANT_TRUE;
959 hr = IMXWriter_get_standalone(writer, &b);
960 ok(hr == S_OK, "got %08x\n", hr);
961 ok(b == VARIANT_FALSE, "got %d\n", b);
963 /* set and check */
964 hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
965 ok(hr == S_OK, "got %08x\n", hr);
967 b = VARIANT_FALSE;
968 hr = IMXWriter_get_standalone(writer, &b);
969 ok(hr == S_OK, "got %08x\n", hr);
970 ok(b == VARIANT_TRUE, "got %d\n", b);
972 hr = IMXWriter_get_encoding(writer, NULL);
973 ok(hr == E_POINTER, "got %08x\n", hr);
975 /* UTF-16 is a default setting apparently */
976 str = (void*)0xdeadbeef;
977 hr = IMXWriter_get_encoding(writer, &str);
978 ok(hr == S_OK, "got %08x\n", hr);
979 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
981 str2 = (void*)0xdeadbeef;
982 hr = IMXWriter_get_encoding(writer, &str2);
983 ok(hr == S_OK, "got %08x\n", hr);
984 ok(str != str2, "expected newly allocated, got same %p\n", str);
986 SysFreeString(str2);
987 SysFreeString(str);
989 /* put empty string */
990 str = SysAllocString(emptyW);
991 hr = IMXWriter_put_encoding(writer, str);
992 ok(hr == E_INVALIDARG, "got %08x\n", hr);
993 SysFreeString(str);
995 str = (void*)0xdeadbeef;
996 hr = IMXWriter_get_encoding(writer, &str);
997 ok(hr == S_OK, "got %08x\n", hr);
998 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1000 /* invalid encoding name */
1001 str = SysAllocString(testW);
1002 hr = IMXWriter_put_encoding(writer, str);
1003 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1004 SysFreeString(str);
1006 hr = IMXWriter_get_version(writer, NULL);
1007 ok(hr == E_POINTER, "got %08x\n", hr);
1008 /* default version is 'surprisingly' 1.0 */
1009 hr = IMXWriter_get_version(writer, &str);
1010 ok(hr == S_OK, "got %08x\n", hr);
1011 ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1013 IMXWriter_Release(writer);
1014 free_bstrs();
1017 static void test_mxwriter_flush(void)
1019 ISAXContentHandler *content;
1020 IMXWriter *writer;
1021 LARGE_INTEGER pos;
1022 ULARGE_INTEGER pos2;
1023 IStream *stream;
1024 VARIANT dest;
1025 HRESULT hr;
1027 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1028 &IID_IMXWriter, (void**)&writer);
1029 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1031 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1032 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1033 EXPECT_REF(stream, 1);
1035 /* detach whe nothing was attached */
1036 V_VT(&dest) = VT_EMPTY;
1037 hr = IMXWriter_put_output(writer, dest);
1038 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1040 /* attach stream */
1041 V_VT(&dest) = VT_UNKNOWN;
1042 V_UNKNOWN(&dest) = (IUnknown*)stream;
1043 hr = IMXWriter_put_output(writer, dest);
1044 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1045 todo_wine EXPECT_REF(stream, 3);
1047 /* detach setting VT_EMPTY destination */
1048 V_VT(&dest) = VT_EMPTY;
1049 hr = IMXWriter_put_output(writer, dest);
1050 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1051 EXPECT_REF(stream, 1);
1053 V_VT(&dest) = VT_UNKNOWN;
1054 V_UNKNOWN(&dest) = (IUnknown*)stream;
1055 hr = IMXWriter_put_output(writer, dest);
1056 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1058 /* flush() doesn't detach a stream */
1059 hr = IMXWriter_flush(writer);
1060 todo_wine {
1061 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1062 EXPECT_REF(stream, 3);
1065 pos.QuadPart = 0;
1066 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1067 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1068 ok(pos2.QuadPart == 0, "expected stream beginning\n");
1070 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1071 ok(hr == S_OK, "got %08x\n", hr);
1073 hr = ISAXContentHandler_startDocument(content);
1074 ok(hr == S_OK, "got %08x\n", hr);
1076 pos.QuadPart = 0;
1077 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1078 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1079 todo_wine ok(pos2.QuadPart != 0, "expected stream beginning\n");
1081 /* already started */
1082 hr = ISAXContentHandler_startDocument(content);
1083 ok(hr == S_OK, "got %08x\n", hr);
1085 hr = ISAXContentHandler_endDocument(content);
1086 todo_wine ok(hr == S_OK, "got %08x\n", hr);
1088 /* flushed on endDocument() */
1089 pos.QuadPart = 0;
1090 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1091 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1092 todo_wine ok(pos2.QuadPart != 0, "expected stream position moved\n");
1094 ISAXContentHandler_Release(content);
1095 IStream_Release(stream);
1096 IMXWriter_Release(writer);
1099 static void test_mxwriter_startenddocument(void)
1101 ISAXContentHandler *content;
1102 IMXWriter *writer;
1103 VARIANT dest;
1104 HRESULT hr;
1106 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1107 &IID_IMXWriter, (void**)&writer);
1108 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1110 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1111 ok(hr == S_OK, "got %08x\n", hr);
1113 hr = ISAXContentHandler_startDocument(content);
1114 ok(hr == S_OK, "got %08x\n", hr);
1116 hr = ISAXContentHandler_endDocument(content);
1117 todo_wine ok(hr == S_OK, "got %08x\n", hr);
1119 V_VT(&dest) = VT_EMPTY;
1120 hr = IMXWriter_get_output(writer, &dest);
1121 ok(hr == S_OK, "got %08x\n", hr);
1122 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1123 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1124 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1125 VariantClear(&dest);
1127 /* now try another startDocument */
1128 hr = ISAXContentHandler_startDocument(content);
1129 ok(hr == S_OK, "got %08x\n", hr);
1130 /* and get duplcated prolog */
1131 V_VT(&dest) = VT_EMPTY;
1132 hr = IMXWriter_get_output(writer, &dest);
1133 ok(hr == S_OK, "got %08x\n", hr);
1134 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1135 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
1136 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
1137 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1138 VariantClear(&dest);
1140 ISAXContentHandler_Release(content);
1141 IMXWriter_Release(writer);
1143 /* now with omitted declaration */
1144 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1145 &IID_IMXWriter, (void**)&writer);
1146 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1148 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1149 ok(hr == S_OK, "got %08x\n", hr);
1151 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1152 ok(hr == S_OK, "got %08x\n", hr);
1154 hr = ISAXContentHandler_startDocument(content);
1155 ok(hr == S_OK, "got %08x\n", hr);
1157 hr = ISAXContentHandler_endDocument(content);
1158 todo_wine ok(hr == S_OK, "got %08x\n", hr);
1160 V_VT(&dest) = VT_EMPTY;
1161 hr = IMXWriter_get_output(writer, &dest);
1162 ok(hr == S_OK, "got %08x\n", hr);
1163 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1164 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1165 VariantClear(&dest);
1167 ISAXContentHandler_Release(content);
1168 IMXWriter_Release(writer);
1170 free_bstrs();
1173 static void test_mxwriter_startendelement(void)
1175 static const char winehqA[] = "http://winehq.org";
1176 ISAXContentHandler *content;
1177 IMXWriter *writer;
1178 VARIANT dest;
1179 HRESULT hr;
1181 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1182 &IID_IMXWriter, (void**)&writer);
1183 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1185 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1186 ok(hr == S_OK, "got %08x\n", hr);
1188 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
1189 ok(hr == S_OK, "got %08x\n", hr);
1191 hr = ISAXContentHandler_startDocument(content);
1192 ok(hr == S_OK, "got %08x\n", hr);
1194 /* qualified name without defined namespace */
1195 hr = ISAXContentHandler_startElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3, NULL);
1196 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1198 hr = ISAXContentHandler_startElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3, NULL);
1199 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1201 /* only local name is an error too */
1202 hr = ISAXContentHandler_startElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0, NULL);
1203 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1205 /* only local name is an error too */
1206 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, NULL, 0, NULL);
1207 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1209 /* all string pointers should be not null */
1210 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
1211 ok(hr == S_OK, "got %08x\n", hr);
1213 V_VT(&dest) = VT_EMPTY;
1214 hr = IMXWriter_get_output(writer, &dest);
1215 ok(hr == S_OK, "got %08x\n", hr);
1216 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1217 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1218 VariantClear(&dest);
1220 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
1221 ok(hr == S_OK, "got %08x\n", hr);
1223 V_VT(&dest) = VT_EMPTY;
1224 hr = IMXWriter_get_output(writer, &dest);
1225 ok(hr == S_OK, "got %08x\n", hr);
1226 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1227 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1228 VariantClear(&dest);
1230 hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
1231 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1233 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
1234 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1236 /* only local name is an error too */
1237 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
1238 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1240 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
1241 ok(hr == S_OK, "got %08x\n", hr);
1243 V_VT(&dest) = VT_EMPTY;
1244 hr = IMXWriter_get_output(writer, &dest);
1245 ok(hr == S_OK, "got %08x\n", hr);
1246 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1247 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1248 VariantClear(&dest);
1250 /* some with namespace URI */
1251 hr = ISAXContentHandler_startElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8, NULL);
1252 ok(hr == S_OK, "got %08x\n", hr);
1254 hr = ISAXContentHandler_endElement(content, _bstr_(winehqA), sizeof(winehqA), _bstr_(""), 0, _bstr_("nspace:c"), 8);
1255 ok(hr == S_OK, "got %08x\n", hr);
1257 V_VT(&dest) = VT_EMPTY;
1258 hr = IMXWriter_get_output(writer, &dest);
1259 ok(hr == S_OK, "got %08x\n", hr);
1260 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1261 todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1262 VariantClear(&dest);
1264 /* try to end element that wasn't open */
1265 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
1266 ok(hr == S_OK, "got %08x\n", hr);
1268 V_VT(&dest) = VT_EMPTY;
1269 hr = IMXWriter_get_output(writer, &dest);
1270 ok(hr == S_OK, "got %08x\n", hr);
1271 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1272 todo_wine ok(!lstrcmpW(_bstr_("<><b></b><nspace:c/></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1273 VariantClear(&dest);
1275 /* try with attributes */
1276 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, &saxattributes);
1277 ok(hr == S_OK, "got %08x\n", hr);
1279 hr = ISAXContentHandler_endDocument(content);
1280 todo_wine ok(hr == S_OK, "got %08x\n", hr);
1282 ISAXContentHandler_Release(content);
1283 IMXWriter_Release(writer);
1285 free_bstrs();
1288 START_TEST(saxreader)
1290 ISAXXMLReader *reader;
1291 IMXWriter *writer;
1292 HRESULT hr;
1294 hr = CoInitialize(NULL);
1295 ok(hr == S_OK, "failed to init com\n");
1297 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1298 &IID_ISAXXMLReader, (void**)&reader);
1300 if(FAILED(hr))
1302 skip("Failed to create SAXXMLReader instance\n");
1303 CoUninitialize();
1304 return;
1306 ISAXXMLReader_Release(reader);
1308 test_saxreader();
1309 test_encoding();
1311 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1312 &IID_IMXWriter, (void**)&writer);
1313 if (hr == S_OK)
1315 IMXWriter_Release(writer);
1317 test_mxwriter_contenthandler();
1318 test_mxwriter_startenddocument();
1319 test_mxwriter_startendelement();
1320 test_mxwriter_properties();
1321 test_mxwriter_flush();
1323 else
1324 win_skip("MXXMLWriter not supported\n");
1326 CoUninitialize();