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
31 #include "msxml2did.h"
35 #include "wine/test.h"
37 #define EXPECT_HR(hr,hr_exp) \
38 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
40 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
41 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
43 ULONG rc = IUnknown_AddRef(obj);
44 IUnknown_Release(obj);
45 ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
48 static BSTR alloc_str_from_narrow(const char *str)
50 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
51 BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
52 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
56 static BSTR alloced_bstrs[512];
57 static int alloced_bstrs_count;
59 static BSTR _bstr_(const char *str)
61 assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
62 alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
63 return alloced_bstrs[alloced_bstrs_count++];
66 static void free_bstrs(void)
69 for (i = 0; i < alloced_bstrs_count; i++)
70 SysFreeString(alloced_bstrs[i]);
71 alloced_bstrs_count = 0;
76 CH_PUTDOCUMENTLOCATOR,
79 CH_STARTPREFIXMAPPING,
84 CH_IGNORABLEWHITESPACE,
85 CH_PROCESSINGINSTRUCTION,
92 static const WCHAR szSimpleXML[] = {
93 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
94 '<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
95 ' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
96 ' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
97 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
100 static const WCHAR szCarriageRetTest[] = {
101 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
102 '<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
103 '\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
104 '\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
105 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n','\0'
108 static const WCHAR szUtf16XML[] = {
109 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"',' ',
110 'e','n','c','o','d','i','n','g','=','"','U','T','F','-','1','6','"',' ',
111 's','t','a','n','d','a','l','o','n','e','=','"','n','o','"','?','>','\r','\n'
114 static const CHAR szUtf16BOM[] = {0xff, 0xfe};
116 static const CHAR szUtf8XML[] =
117 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n";
119 static const char utf8xml2[] =
120 "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n";
122 static const CHAR szTestXML[] =
123 "<?xml version=\"1.0\" ?>\n"
125 " <Number>1234</Number>\n"
126 " <Name>Captain Ahab</Name>\n"
129 static const CHAR szTestAttributes[] =
130 "<?xml version=\"1.0\" ?>\n"
131 "<document xmlns:test=\"prefix_test\" xmlns=\"prefix\" test:arg1=\"arg1\" arg2=\"arg2\" test:ar3=\"arg3\">\n"
132 "<node1 xmlns:p=\"test\" />"
135 typedef struct _contenthandlercheck {
145 } content_handler_test;
147 static content_handler_test contentHandlerTest1[] = {
148 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
149 { CH_STARTDOCUMENT, 0, 0, 1, 22 },
150 { CH_STARTELEMENT, 2, 14, 2, 13, "", "BankAccount", "BankAccount" },
151 { CH_CHARACTERS, 2, 14, 3, 4, "\n " },
152 { CH_STARTELEMENT, 3, 12, 3, 11, "", "Number", "Number" },
153 { CH_CHARACTERS, 3, 12, 3, 16, "1234" },
154 { CH_ENDELEMENT, 3, 18, 3, 24, "", "Number", "Number" },
155 { CH_CHARACTERS, 3, 25, 4, 4, "\n " },
156 { CH_STARTELEMENT, 4, 10, 4, 9, "", "Name", "Name" },
157 { CH_CHARACTERS, 4, 10, 4, 22, "Captain Ahab" },
158 { CH_ENDELEMENT, 4, 24, 4, 28, "", "Name", "Name" },
159 { CH_CHARACTERS, 4, 29, 5, 1, "\n" },
160 { CH_ENDELEMENT, 5, 3, 5, 14, "", "BankAccount", "BankAccount" },
161 { CH_ENDDOCUMENT, 0, 0, 6, 0 },
165 static content_handler_test contentHandlerTest2[] = {
166 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
167 { CH_STARTDOCUMENT, 0, 0, 1, 21 },
168 { CH_STARTELEMENT, 2, 14, 2, 13, "", "BankAccount", "BankAccount" },
169 { CH_CHARACTERS, 2, 14, 3, 0, "\n" },
170 { CH_CHARACTERS, 2, 16, 3, 2, "\t" },
171 { CH_STARTELEMENT, 3, 10, 3, 9, "", "Number", "Number" },
172 { CH_CHARACTERS, 3, 10, 3, 14, "1234" },
173 { CH_ENDELEMENT, 3, 16, 3, 22, "", "Number", "Number" },
174 { CH_CHARACTERS, 3, 23, 4, 0, "\n" },
175 { CH_CHARACTERS, 3, 25, 4, 2, "\t" },
176 { CH_STARTELEMENT, 4, 8, 4, 7, "", "Name", "Name" },
177 { CH_CHARACTERS, 4, 8, 4, 20, "Captain Ahab" },
178 { CH_ENDELEMENT, 4, 22, 4, 26, "", "Name", "Name" },
179 { CH_CHARACTERS, 4, 27, 5, 0, "\n" },
180 { CH_ENDELEMENT, 5, 3, 5, 14, "", "BankAccount", "BankAccount" },
181 { CH_ENDDOCUMENT, 0, 0, 6, 0 },
185 static content_handler_test contentHandlerTestError[] = {
186 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0, NULL, NULL, NULL, E_FAIL },
187 { EH_FATALERROR, 0, 0, 0, 0, NULL, NULL, NULL, E_FAIL },
191 static content_handler_test contentHandlerTestCallbackResults[] = {
192 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0, NULL, NULL, NULL, S_FALSE },
193 { CH_STARTDOCUMENT, 0, 0, 1, 22, NULL, NULL, NULL, S_FALSE },
194 { EH_FATALERROR, 0, 0, 0, 0, NULL, NULL, NULL, S_FALSE },
198 static content_handler_test contentHandlerTestCallbackResult6[] = {
199 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0, NULL, NULL, NULL, S_FALSE },
200 { CH_STARTDOCUMENT, 0, 0, 1, 22, NULL, NULL, NULL, S_FALSE },
201 { CH_STARTELEMENT, 2, 14, 2, 13, "", "BankAccount", "BankAccount", S_FALSE },
202 { CH_CHARACTERS, 2, 14, 3, 4, "\n ", NULL, NULL, S_FALSE },
203 { CH_STARTELEMENT, 3, 12, 3, 11, "", "Number", "Number", S_FALSE },
204 { CH_CHARACTERS, 3, 12, 3, 16, "1234", NULL, NULL, S_FALSE },
205 { CH_ENDELEMENT, 3, 18, 3, 24, "", "Number", "Number", S_FALSE },
206 { CH_CHARACTERS, 3, 25, 4, 4, "\n ", NULL, NULL, S_FALSE },
207 { CH_STARTELEMENT, 4, 10, 4, 9, "", "Name", "Name", S_FALSE },
208 { CH_CHARACTERS, 4, 10, 4, 22, "Captain Ahab", NULL, NULL, S_FALSE },
209 { CH_ENDELEMENT, 4, 24, 4, 28, "", "Name", "Name", S_FALSE },
210 { CH_CHARACTERS, 4, 29, 5, 1, "\n", NULL, NULL, S_FALSE },
211 { CH_ENDELEMENT, 5, 3, 5, 14, "", "BankAccount", "BankAccount", S_FALSE },
212 { CH_ENDDOCUMENT, 0, 0, 6, 0, NULL, NULL, NULL, S_FALSE },
216 static content_handler_test contentHandlerTestAttributes[] = {
217 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
218 { CH_STARTDOCUMENT, 0, 0, 1, 22 },
219 { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "test", "prefix_test" },
220 { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "", "prefix" },
221 { CH_STARTELEMENT, 2, 96, 2, 95, "prefix", "document", "document" },
222 { CH_CHARACTERS, 2, 96, 3, 1, "\n" },
223 { CH_STARTPREFIXMAPPING, 3, 25, 3, 24, "p", "test" },
224 { CH_STARTELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
225 { CH_ENDELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
226 { CH_ENDPREFIXMAPPING, 3, 25, 3, 24, "p" },
227 { CH_ENDELEMENT, 3, 27, 3, 35, "prefix", "document", "document" },
228 { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "" },
229 { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "test" },
230 { CH_ENDDOCUMENT, 0, 0, 4, 0 },
234 static content_handler_test contentHandlerTestAttributes6[] = {
235 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
236 { CH_STARTDOCUMENT, 0, 0, 1, 22 },
237 { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "test", "prefix_test" },
238 { CH_STARTPREFIXMAPPING, 2, 96, 2, 95, "", "prefix" },
239 { CH_STARTELEMENT, 2, 96, 2, 95, "prefix", "document", "document" },
240 { CH_CHARACTERS, 2, 96, 3, 1, "\n" },
241 { CH_STARTPREFIXMAPPING, 3, 25, 3, 24, "p", "test" },
242 { CH_STARTELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
243 { CH_ENDELEMENT, 3, 25, 3, 24, "prefix", "node1", "node1" },
244 { CH_ENDPREFIXMAPPING, 3, 25, 3, 24, "p" },
245 { CH_ENDELEMENT, 3, 27, 3, 35, "prefix", "document", "document" },
246 { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "test" },
247 { CH_ENDPREFIXMAPPING, 3, 27, 3, 35, "" },
248 { CH_ENDDOCUMENT, 0, 0, 4, 0 },
252 static content_handler_test *expectCall;
253 static ISAXLocator *locator;
256 static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
262 ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
263 ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
267 len = strlen(szTest);
268 ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
272 MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
273 ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
274 wine_dbgstr_wn(szStr, nStr), szTest);
277 static BOOL test_expect_call(CH id)
279 ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
280 return expectCall->id == id;
283 static void test_locator(unsigned line, int loc_line, int loc_column)
286 ISAXLocator_getLineNumber(locator, &rline);
287 ISAXLocator_getColumnNumber(locator, &rcolumn);
289 ok_(__FILE__,line) (rline == loc_line,
290 "unexpected line %d, expected %d\n", rline, loc_line);
291 ok_(__FILE__,line) (rcolumn == loc_column,
292 "unexpected column %d, expected %d\n", rcolumn, loc_column);
295 static HRESULT WINAPI contentHandler_QueryInterface(
296 ISAXContentHandler* iface,
302 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
308 return E_NOINTERFACE;
314 static ULONG WINAPI contentHandler_AddRef(
315 ISAXContentHandler* iface)
320 static ULONG WINAPI contentHandler_Release(
321 ISAXContentHandler* iface)
326 static HRESULT WINAPI contentHandler_putDocumentLocator(
327 ISAXContentHandler* iface,
328 ISAXLocator *pLocator)
330 ISAXAttributes *attr, *attr1;
333 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
337 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
338 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
340 if(msxml_version >= 6) {
341 EXPECT_REF(pLocator, 1);
342 hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr);
344 EXPECT_REF(pLocator, 2);
345 hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr1);
347 EXPECT_REF(pLocator, 3);
348 ok(attr == attr1, "got %p, %p\n", attr, attr1);
349 ISAXAttributes_Release(attr);
350 ISAXAttributes_Release(attr1);
353 return (expectCall++)->ret;
356 static ISAXAttributes *test_attr_ptr;
357 static HRESULT WINAPI contentHandler_startDocument(
358 ISAXContentHandler* iface)
360 if(!test_expect_call(CH_STARTDOCUMENT))
363 test_attr_ptr = NULL;
364 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
365 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
367 return (expectCall++)->ret;
370 static HRESULT WINAPI contentHandler_endDocument(
371 ISAXContentHandler* iface)
373 if(!test_expect_call(CH_ENDDOCUMENT))
376 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
377 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
379 return (expectCall++)->ret;
382 static HRESULT WINAPI contentHandler_startPrefixMapping(
383 ISAXContentHandler* iface,
384 const WCHAR *pPrefix,
389 if(!test_expect_call(CH_STARTPREFIXMAPPING))
392 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
393 test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
394 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
395 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
397 return (expectCall++)->ret;
400 static HRESULT WINAPI contentHandler_endPrefixMapping(
401 ISAXContentHandler* iface,
402 const WCHAR *pPrefix,
405 if(!test_expect_call(CH_ENDPREFIXMAPPING))
408 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
409 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
410 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
412 return (expectCall++)->ret;
415 static HRESULT WINAPI contentHandler_startElement(
416 ISAXContentHandler* iface,
417 const WCHAR *pNamespaceUri,
419 const WCHAR *pLocalName,
423 ISAXAttributes *pAttr)
428 if(!test_expect_call(CH_STARTELEMENT))
431 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
432 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
433 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
434 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
435 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
438 test_attr_ptr = pAttr;
439 ok(test_attr_ptr == pAttr, "Multiple ISAXAttributes instances are used (%p %p)\n", test_attr_ptr, pAttr);
441 if(expectCall == contentHandlerTestAttributes+4) {
442 const WCHAR *uri_ptr = NULL;
444 /* msxml3 returns attributes and namespaces in the input order */
445 hres = ISAXAttributes_getLength(pAttr, &len);
446 ok(hres == S_OK, "getLength returned %x\n", hres);
447 ok(len == 5, "Incorrect number of attributes: %d\n", len);
448 ok(msxml_version < 6, "wrong msxml_version: %d\n", msxml_version);
450 for(i=0; i<len; i++) {
451 hres = ISAXAttributes_getName(pAttr, i, &pNamespaceUri, &nNamespaceUri,
452 &pLocalName, &nLocalName, &pQName, &nQName);
453 ok(hres == S_OK, "getName returned %x\n", hres);
456 todo_wine ok(i==3, "Incorrect attributes order\n");
457 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
458 test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
459 test_saxstr(__LINE__, pQName, nQName, "arg2");
460 } else if(nQName == 5) {
461 todo_wine ok(i==1, "Incorrect attributes order\n");
462 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
463 test_saxstr(__LINE__, pLocalName, nLocalName, "");
464 test_saxstr(__LINE__, pQName, nQName, "xmlns");
465 } else if(nQName == 8) {
466 todo_wine ok(i==4, "Incorrect attributes order\n");
467 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
468 test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
469 test_saxstr(__LINE__, pQName, nQName, "test:ar3");
470 ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
471 } else if(nQName == 9) {
472 todo_wine ok(i==2, "Incorrect attributes order\n");
473 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
474 test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
475 test_saxstr(__LINE__, pQName, nQName, "test:arg1");
476 uri_ptr = pNamespaceUri;
477 } else if(nQName == 10) {
478 todo_wine ok(i==0, "Incorrect attributes order\n");
479 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
480 test_saxstr(__LINE__, pLocalName, nLocalName, "");
481 test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
483 ok(0, "Unexpected attribute\n");
486 } else if(expectCall == contentHandlerTestAttributes6+4) {
487 const WCHAR *uri_ptr;
489 /* msxml6 returns attributes first and then namespaces */
490 hres = ISAXAttributes_getLength(pAttr, &len);
491 ok(hres == S_OK, "getLength returned %x\n", hres);
492 ok(len == 5, "Incorrect number of attributes: %d\n", len);
493 ok(msxml_version >= 6, "wrong msxml_version: %d\n", msxml_version);
495 hres = ISAXAttributes_getName(pAttr, 0, &pNamespaceUri, &nNamespaceUri,
496 &pLocalName, &nLocalName, &pQName, &nQName);
497 ok(hres == S_OK, "getName returned %x\n", hres);
498 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
499 test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
500 test_saxstr(__LINE__, pQName, nQName, "test:arg1");
501 uri_ptr = pNamespaceUri;
503 hres = ISAXAttributes_getName(pAttr, 1, &pNamespaceUri, &nNamespaceUri,
504 &pLocalName, &nLocalName, &pQName, &nQName);
505 ok(hres == S_OK, "getName returned %x\n", hres);
506 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
507 test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
508 test_saxstr(__LINE__, pQName, nQName, "arg2");
510 hres = ISAXAttributes_getName(pAttr, 2, &pNamespaceUri, &nNamespaceUri,
511 &pLocalName, &nLocalName, &pQName, &nQName);
512 ok(hres == S_OK, "getName returned %x\n", hres);
513 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
514 test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
515 test_saxstr(__LINE__, pQName, nQName, "test:ar3");
516 ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
518 hres = ISAXAttributes_getName(pAttr, 3, &pNamespaceUri, &nNamespaceUri,
519 &pLocalName, &nLocalName, &pQName, &nQName);
520 ok(hres == S_OK, "getName returned %x\n", hres);
521 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
522 test_saxstr(__LINE__, pLocalName, nLocalName, "");
523 test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
525 hres = ISAXAttributes_getName(pAttr, 4, &pNamespaceUri, &nNamespaceUri,
526 &pLocalName, &nLocalName, &pQName, &nQName);
527 ok(hres == S_OK, "getName returned %x\n", hres);
528 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
529 test_saxstr(__LINE__, pLocalName, nLocalName, "");
530 test_saxstr(__LINE__, pQName, nQName, "xmlns");
533 return (expectCall++)->ret;
536 static HRESULT WINAPI contentHandler_endElement(
537 ISAXContentHandler* iface,
538 const WCHAR *pNamespaceUri,
540 const WCHAR *pLocalName,
545 if(!test_expect_call(CH_ENDELEMENT))
548 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
549 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
550 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
551 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
552 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
554 return (expectCall++)->ret;
557 static HRESULT WINAPI contentHandler_characters(
558 ISAXContentHandler* iface,
562 if(!test_expect_call(CH_CHARACTERS))
565 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
566 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
567 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
569 return (expectCall++)->ret;
572 static HRESULT WINAPI contentHandler_ignorableWhitespace(
573 ISAXContentHandler* iface,
577 if(!test_expect_call(CH_IGNORABLEWHITESPACE))
580 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
581 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
582 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
584 return (expectCall++)->ret;
587 static HRESULT WINAPI contentHandler_processingInstruction(
588 ISAXContentHandler* iface,
589 const WCHAR *pTarget,
594 if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
597 test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
598 test_saxstr(__LINE__, pData, nData, expectCall->arg2);
599 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
600 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
602 return (expectCall++)->ret;
605 static HRESULT WINAPI contentHandler_skippedEntity(
606 ISAXContentHandler* iface,
610 if(!test_expect_call(CH_SKIPPEDENTITY))
613 test_saxstr(__LINE__, pName, nName, expectCall->arg1);
614 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
615 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
617 return (expectCall++)->ret;
621 static const ISAXContentHandlerVtbl contentHandlerVtbl =
623 contentHandler_QueryInterface,
624 contentHandler_AddRef,
625 contentHandler_Release,
626 contentHandler_putDocumentLocator,
627 contentHandler_startDocument,
628 contentHandler_endDocument,
629 contentHandler_startPrefixMapping,
630 contentHandler_endPrefixMapping,
631 contentHandler_startElement,
632 contentHandler_endElement,
633 contentHandler_characters,
634 contentHandler_ignorableWhitespace,
635 contentHandler_processingInstruction,
636 contentHandler_skippedEntity
639 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
641 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
642 ISAXErrorHandler* iface,
648 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
654 return E_NOINTERFACE;
660 static ULONG WINAPI isaxerrorHandler_AddRef(
661 ISAXErrorHandler* iface)
666 static ULONG WINAPI isaxerrorHandler_Release(
667 ISAXErrorHandler* iface)
672 static HRESULT WINAPI isaxerrorHandler_error(
673 ISAXErrorHandler* iface,
674 ISAXLocator *pLocator,
675 const WCHAR *pErrorMessage,
678 ok(0, "unexpected call\n");
682 static HRESULT WINAPI isaxerrorHandler_fatalError(
683 ISAXErrorHandler* iface,
684 ISAXLocator *pLocator,
685 const WCHAR *pErrorMessage,
688 if(!test_expect_call(EH_FATALERROR))
691 ok(hrErrorCode == expectCall->ret, "hrErrorCode = %x, expected %x\n", hrErrorCode, expectCall->ret);
697 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
698 ISAXErrorHandler* iface,
699 ISAXLocator *pLocator,
700 const WCHAR *pErrorMessage,
703 ok(0, "unexpected call\n");
707 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
709 isaxerrorHandler_QueryInterface,
710 isaxerrorHandler_AddRef,
711 isaxerrorHandler_Release,
712 isaxerrorHandler_error,
713 isaxerrorHandler_fatalError,
714 isaxerrorHanddler_ignorableWarning
717 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
719 static HRESULT WINAPI isaxattributes_QueryInterface(
720 ISAXAttributes* iface,
726 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
732 return E_NOINTERFACE;
738 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
743 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
748 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
754 static HRESULT WINAPI isaxattributes_getURI(
755 ISAXAttributes* iface,
760 ok(0, "unexpected call\n");
764 static HRESULT WINAPI isaxattributes_getLocalName(
765 ISAXAttributes* iface,
767 const WCHAR **pLocalName,
768 int *pLocalNameLength)
770 ok(0, "unexpected call\n");
774 static HRESULT WINAPI isaxattributes_getQName(
775 ISAXAttributes* iface,
780 static const WCHAR attrqnamesW[][15] = {{'a',':','a','t','t','r','1','j','u','n','k',0},
781 {'a','t','t','r','2','j','u','n','k',0},
782 {'a','t','t','r','3',0}};
783 static const int attrqnamelen[] = {7, 5, 5};
785 ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
787 *QName = attrqnamesW[index];
788 *QNameLength = attrqnamelen[index];
793 static HRESULT WINAPI isaxattributes_getName(
794 ISAXAttributes* iface,
798 const WCHAR ** pLocalName,
799 int * pLocalNameSize,
800 const WCHAR ** pQName,
803 ok(0, "unexpected call\n");
807 static HRESULT WINAPI isaxattributes_getIndexFromName(
808 ISAXAttributes* iface,
811 const WCHAR * pLocalName,
815 ok(0, "unexpected call\n");
819 static HRESULT WINAPI isaxattributes_getIndexFromQName(
820 ISAXAttributes* iface,
821 const WCHAR * pQName,
825 ok(0, "unexpected call\n");
829 static HRESULT WINAPI isaxattributes_getType(
830 ISAXAttributes* iface,
832 const WCHAR ** pType,
835 ok(0, "unexpected call\n");
839 static HRESULT WINAPI isaxattributes_getTypeFromName(
840 ISAXAttributes* iface,
843 const WCHAR * pLocalName,
845 const WCHAR ** pType,
848 ok(0, "unexpected call\n");
852 static HRESULT WINAPI isaxattributes_getTypeFromQName(
853 ISAXAttributes* iface,
854 const WCHAR * pQName,
856 const WCHAR ** pType,
859 ok(0, "unexpected call\n");
863 static HRESULT WINAPI isaxattributes_getValue(ISAXAttributes* iface, int index,
864 const WCHAR **value, int *nValue)
866 static const WCHAR attrvaluesW[][10] = {{'a','1','j','u','n','k',0},
867 {'a','2','j','u','n','k',0},
868 {'<','&','"','>',0}};
869 static const int attrvalueslen[] = {2, 2, 4};
871 ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
873 *value = attrvaluesW[index];
874 *nValue = attrvalueslen[index];
879 static HRESULT WINAPI isaxattributes_getValueFromName(
880 ISAXAttributes* iface,
883 const WCHAR * pLocalName,
885 const WCHAR ** pValue,
888 ok(0, "unexpected call\n");
892 static HRESULT WINAPI isaxattributes_getValueFromQName(
893 ISAXAttributes* iface,
894 const WCHAR * pQName,
896 const WCHAR ** pValue,
899 ok(0, "unexpected call\n");
903 static const ISAXAttributesVtbl SAXAttributesVtbl =
905 isaxattributes_QueryInterface,
906 isaxattributes_AddRef,
907 isaxattributes_Release,
908 isaxattributes_getLength,
909 isaxattributes_getURI,
910 isaxattributes_getLocalName,
911 isaxattributes_getQName,
912 isaxattributes_getName,
913 isaxattributes_getIndexFromName,
914 isaxattributes_getIndexFromQName,
915 isaxattributes_getType,
916 isaxattributes_getTypeFromName,
917 isaxattributes_getTypeFromQName,
918 isaxattributes_getValue,
919 isaxattributes_getValueFromName,
920 isaxattributes_getValueFromQName
923 static ISAXAttributes saxattributes = { &SAXAttributesVtbl };
925 static int handler_addrefcalled;
927 static HRESULT WINAPI isaxlexical_QueryInterface(ISAXLexicalHandler* iface, REFIID riid, void **ppvObject)
931 if(IsEqualGUID(riid, &IID_IUnknown) ||
932 IsEqualGUID(riid, &IID_ISAXLexicalHandler))
938 return E_NOINTERFACE;
944 static ULONG WINAPI isaxlexical_AddRef(ISAXLexicalHandler* iface)
946 handler_addrefcalled++;
950 static ULONG WINAPI isaxlexical_Release(ISAXLexicalHandler* iface)
955 static HRESULT WINAPI isaxlexical_startDTD(ISAXLexicalHandler* iface,
956 const WCHAR * pName, int nName, const WCHAR * pPublicId,
957 int nPublicId, const WCHAR * pSystemId, int nSystemId)
959 ok(0, "call not expected\n");
963 static HRESULT WINAPI isaxlexical_endDTD(ISAXLexicalHandler* iface)
965 ok(0, "call not expected\n");
969 static HRESULT WINAPI isaxlexical_startEntity(ISAXLexicalHandler *iface,
970 const WCHAR * pName, int nName)
972 ok(0, "call not expected\n");
976 static HRESULT WINAPI isaxlexical_endEntity(ISAXLexicalHandler *iface,
977 const WCHAR * pName, int nName)
979 ok(0, "call not expected\n");
983 static HRESULT WINAPI isaxlexical_startCDATA(ISAXLexicalHandler *iface)
985 ok(0, "call not expected\n");
989 static HRESULT WINAPI isaxlexical_endCDATA(ISAXLexicalHandler *iface)
991 ok(0, "call not expected\n");
995 static HRESULT WINAPI isaxlexical_comment(ISAXLexicalHandler *iface,
996 const WCHAR * pChars, int nChars)
998 ok(0, "call not expected\n");
1002 static const ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl =
1004 isaxlexical_QueryInterface,
1006 isaxlexical_Release,
1007 isaxlexical_startDTD,
1009 isaxlexical_startEntity,
1010 isaxlexical_endEntity,
1011 isaxlexical_startCDATA,
1012 isaxlexical_endCDATA,
1016 static ISAXLexicalHandler saxlexicalhandler = { &SAXLexicalHandlerVtbl };
1018 static HRESULT WINAPI isaxdecl_QueryInterface(ISAXDeclHandler* iface, REFIID riid, void **ppvObject)
1022 if(IsEqualGUID(riid, &IID_IUnknown) ||
1023 IsEqualGUID(riid, &IID_ISAXDeclHandler))
1029 return E_NOINTERFACE;
1035 static ULONG WINAPI isaxdecl_AddRef(ISAXDeclHandler* iface)
1037 handler_addrefcalled++;
1041 static ULONG WINAPI isaxdecl_Release(ISAXDeclHandler* iface)
1046 static HRESULT WINAPI isaxdecl_elementDecl(ISAXDeclHandler* iface,
1047 const WCHAR * pName, int nName, const WCHAR * pModel, int nModel)
1049 ok(0, "call not expected\n");
1053 static HRESULT WINAPI isaxdecl_attributeDecl(ISAXDeclHandler* iface,
1054 const WCHAR * pElementName, int nElementName, const WCHAR * pAttributeName,
1055 int nAttributeName, const WCHAR * pType, int nType, const WCHAR * pValueDefault,
1056 int nValueDefault, const WCHAR * pValue, int nValue)
1058 ok(0, "call not expected\n");
1062 static HRESULT WINAPI isaxdecl_internalEntityDecl(ISAXDeclHandler* iface,
1063 const WCHAR * pName, int nName, const WCHAR * pValue, int nValue)
1065 ok(0, "call not expected\n");
1069 static HRESULT WINAPI isaxdecl_externalEntityDecl(ISAXDeclHandler* iface,
1070 const WCHAR * pName, int nName, const WCHAR * pPublicId, int nPublicId,
1071 const WCHAR * pSystemId, int nSystemId)
1073 ok(0, "call not expected\n");
1077 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl =
1079 isaxdecl_QueryInterface,
1082 isaxdecl_elementDecl,
1083 isaxdecl_attributeDecl,
1084 isaxdecl_internalEntityDecl,
1085 isaxdecl_externalEntityDecl
1088 static ISAXDeclHandler saxdeclhandler = { &SAXDeclHandlerVtbl };
1090 typedef struct mxwriter_write_test_t {
1096 } mxwriter_write_test;
1098 typedef struct mxwriter_stream_test_t {
1100 const char *encoding;
1101 mxwriter_write_test expected_writes[4];
1102 } mxwriter_stream_test;
1104 static const mxwriter_write_test *current_write_test;
1105 static DWORD current_stream_test_index;
1107 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
1111 if(IsEqualGUID(riid, &IID_IStream) || IsEqualGUID(riid, &IID_IUnknown))
1114 return E_NOINTERFACE;
1119 static ULONG WINAPI istream_AddRef(IStream *iface)
1124 static ULONG WINAPI istream_Release(IStream *iface)
1129 static HRESULT WINAPI istream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
1131 ok(0, "unexpected call\n");
1135 static HRESULT WINAPI istream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
1139 ok(pv != NULL, "pv == NULL\n");
1141 if(current_write_test->last) {
1142 ok(0, "Too many Write calls made on test %d\n", current_stream_test_index);
1146 fail = current_write_test->fail_write;
1148 ok(current_write_test->cb == cb, "Expected %d, but got %d on test %d\n",
1149 current_write_test->cb, cb, current_stream_test_index);
1152 ok(current_write_test->null_written, "pcbWritten was NULL on test %d\n", current_stream_test_index);
1154 ok(!memcmp(current_write_test->data, pv, cb), "Unexpected data on test %d\n", current_stream_test_index);
1156 ++current_write_test;
1161 return fail ? E_FAIL : S_OK;
1164 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
1165 ULARGE_INTEGER *plibNewPosition)
1167 ok(0, "unexpected call\n");
1171 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
1173 ok(0, "unexpected call\n");
1177 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
1178 ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *plibWritten)
1180 ok(0, "unexpected call\n");
1184 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD grfCommitFlags)
1186 ok(0, "unexpected call\n");
1190 static HRESULT WINAPI istream_Revert(IStream *iface)
1192 ok(0, "unexpected call\n");
1196 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1197 ULARGE_INTEGER cb, DWORD dwLockType)
1199 ok(0, "unexpected call\n");
1203 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1204 ULARGE_INTEGER cb, DWORD dwLockType)
1206 ok(0, "unexpected call\n");
1210 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
1212 ok(0, "unexpected call\n");
1216 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **ppstm)
1218 ok(0, "unexpected call\n");
1222 static const IStreamVtbl StreamVtbl = {
1223 istream_QueryInterface,
1234 istream_UnlockRegion,
1239 static IStream mxstream = { &StreamVtbl };
1241 static void test_saxreader(int version)
1244 ISAXXMLReader *reader = NULL;
1246 ISAXContentHandler *lpContentHandler;
1247 ISAXErrorHandler *lpErrorHandler;
1249 SAFEARRAYBOUND SADim[1];
1250 char *pSAData = NULL;
1252 ULARGE_INTEGER liSize;
1253 LARGE_INTEGER liPos;
1256 static const CHAR testXmlA[] = "test.xml";
1257 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1258 IXMLDOMDocument *domDocument;
1262 msxml_version = version;
1264 hr = CoCreateInstance(&CLSID_SAXXMLReader30, NULL, CLSCTX_INPROC_SERVER,
1265 &IID_ISAXXMLReader, (LPVOID*)&reader);
1266 } else if(version == 6) {
1267 hr = CoCreateInstance(&CLSID_SAXXMLReader60, NULL, CLSCTX_INPROC_SERVER,
1268 &IID_ISAXXMLReader, (LPVOID*)&reader);
1269 if(hr == REGDB_E_CLASSNOTREG) {
1270 win_skip("SAXXMLReader6 not registered\n");
1274 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1275 &IID_ISAXXMLReader, (LPVOID*)&reader);
1277 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1280 hr = ISAXXMLReader_getContentHandler(reader, NULL);
1281 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1283 hr = ISAXXMLReader_getErrorHandler(reader, NULL);
1284 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1287 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1288 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1289 ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
1291 hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
1292 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1293 ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
1295 hr = ISAXXMLReader_putContentHandler(reader, NULL);
1296 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1298 hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
1299 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1301 hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
1302 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1304 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1305 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1306 ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
1308 V_VT(&var) = VT_BSTR;
1309 V_BSTR(&var) = SysAllocString(szSimpleXML);
1311 expectCall = contentHandlerTest1;
1312 hr = ISAXXMLReader_parse(reader, var);
1313 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1314 test_expect_call(CH_ENDTEST);
1318 SADim[0].lLbound= 0;
1319 SADim[0].cElements= sizeof(szTestXML)-1;
1320 pSA = SafeArrayCreate(VT_UI1, 1, SADim);
1321 SafeArrayAccessData(pSA, (void**)&pSAData);
1322 memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
1323 SafeArrayUnaccessData(pSA);
1324 V_VT(&var) = VT_ARRAY|VT_UI1;
1325 V_ARRAY(&var) = pSA;
1327 expectCall = contentHandlerTest1;
1328 hr = ISAXXMLReader_parse(reader, var);
1329 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1330 test_expect_call(CH_ENDTEST);
1332 SafeArrayDestroy(pSA);
1334 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1335 liSize.QuadPart = strlen(szTestXML);
1336 IStream_SetSize(iStream, liSize);
1337 IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
1339 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1340 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1341 V_UNKNOWN(&var) = (IUnknown*)iStream;
1343 expectCall = contentHandlerTest1;
1344 hr = ISAXXMLReader_parse(reader, var);
1345 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1346 test_expect_call(CH_ENDTEST);
1348 IStream_Release(iStream);
1350 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1351 liSize.QuadPart = strlen(szTestAttributes);
1352 IStream_SetSize(iStream, liSize);
1353 IStream_Write(iStream, szTestAttributes, strlen(szTestAttributes), &bytesWritten);
1355 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1356 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1357 V_UNKNOWN(&var) = (IUnknown*)iStream;
1360 expectCall = contentHandlerTestAttributes6;
1362 expectCall = contentHandlerTestAttributes;
1363 hr = ISAXXMLReader_parse(reader, var);
1364 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1365 test_expect_call(CH_ENDTEST);
1367 IStream_Release(iStream);
1369 V_VT(&var) = VT_BSTR;
1370 V_BSTR(&var) = SysAllocString(szCarriageRetTest);
1372 expectCall = contentHandlerTest2;
1373 hr = ISAXXMLReader_parse(reader, var);
1374 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1375 test_expect_call(CH_ENDTEST);
1379 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1380 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1381 WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
1384 expectCall = contentHandlerTest1;
1385 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1386 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1387 test_expect_call(CH_ENDTEST);
1389 expectCall = contentHandlerTestError;
1390 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1391 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1392 test_expect_call(CH_ENDTEST);
1395 expectCall = contentHandlerTestCallbackResult6;
1397 expectCall = contentHandlerTestCallbackResults;
1398 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1399 ok(hr == (version>=6 ? S_OK : S_FALSE), "Expected S_FALSE, got %08x\n", hr);
1400 test_expect_call(CH_ENDTEST);
1402 DeleteFileA(testXmlA);
1404 hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
1405 &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
1408 skip("Failed to create DOMDocument instance\n");
1411 bstrData = SysAllocString(szSimpleXML);
1412 hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
1413 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1414 V_VT(&var) = VT_UNKNOWN;
1415 V_UNKNOWN(&var) = (IUnknown*)domDocument;
1417 expectCall = contentHandlerTest2;
1418 hr = ISAXXMLReader_parse(reader, var);
1419 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1420 test_expect_call(CH_ENDTEST);
1421 IXMLDOMDocument_Release(domDocument);
1423 ISAXXMLReader_Release(reader);
1424 SysFreeString(bstrData);
1427 struct saxreader_props_test_t
1429 const char *prop_name;
1433 static const struct saxreader_props_test_t props_test_data[] = {
1434 { "http://xml.org/sax/properties/lexical-handler", (IUnknown*)&saxlexicalhandler },
1435 { "http://xml.org/sax/properties/declaration-handler", (IUnknown*)&saxdeclhandler },
1439 static void test_saxreader_properties(void)
1441 const struct saxreader_props_test_t *ptr = props_test_data;
1442 ISAXXMLReader *reader;
1445 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1446 &IID_ISAXXMLReader, (void**)&reader);
1447 EXPECT_HR(hr, S_OK);
1449 hr = ISAXXMLReader_getProperty(reader, _bstr_("http://xml.org/sax/properties/lexical-handler"), NULL);
1450 EXPECT_HR(hr, E_POINTER);
1452 while (ptr->prop_name)
1456 V_VT(&v) = VT_EMPTY;
1457 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1458 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1459 EXPECT_HR(hr, S_OK);
1460 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1461 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1463 V_VT(&v) = VT_UNKNOWN;
1464 V_UNKNOWN(&v) = ptr->iface;
1465 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1466 EXPECT_HR(hr, S_OK);
1468 V_VT(&v) = VT_EMPTY;
1469 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1470 handler_addrefcalled = 0;
1471 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1472 EXPECT_HR(hr, S_OK);
1473 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1474 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1475 ok(handler_addrefcalled == 1, "AddRef called %d times\n", handler_addrefcalled);
1478 V_VT(&v) = VT_EMPTY;
1479 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1480 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1481 EXPECT_HR(hr, S_OK);
1483 V_VT(&v) = VT_EMPTY;
1484 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1485 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1486 EXPECT_HR(hr, S_OK);
1487 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1488 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1490 V_VT(&v) = VT_UNKNOWN;
1491 V_UNKNOWN(&v) = ptr->iface;
1492 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1493 EXPECT_HR(hr, S_OK);
1495 /* only VT_EMPTY seems to be valid to reset property */
1497 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1498 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1499 EXPECT_HR(hr, E_INVALIDARG);
1501 V_VT(&v) = VT_EMPTY;
1502 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1503 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1504 EXPECT_HR(hr, S_OK);
1505 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1506 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1509 V_VT(&v) = VT_UNKNOWN;
1510 V_UNKNOWN(&v) = NULL;
1511 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1512 EXPECT_HR(hr, S_OK);
1514 V_VT(&v) = VT_EMPTY;
1515 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1516 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1517 EXPECT_HR(hr, S_OK);
1518 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1519 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1524 ISAXXMLReader_Release(reader);
1528 struct feature_ns_entry_t {
1534 static const struct feature_ns_entry_t feature_ns_entry_data[] = {
1535 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", VARIANT_TRUE },
1536 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", VARIANT_TRUE },
1537 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", VARIANT_TRUE },
1538 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", VARIANT_TRUE },
1542 static void test_saxreader_features(void)
1544 const struct feature_ns_entry_t *entry = feature_ns_entry_data;
1545 ISAXXMLReader *reader;
1552 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1555 win_skip("can't create %s instance\n", entry->clsid);
1561 hr = ISAXXMLReader_getFeature(reader, _bstr_("http://xml.org/sax/features/namespaces"), &value);
1562 EXPECT_HR(hr, S_OK);
1564 ok(entry->value == value, "%s: got wrong default value %x, expected %x\n", entry->clsid, value, entry->value);
1566 ISAXXMLReader_Release(reader);
1572 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1573 static const CHAR UTF8BOMTest[] =
1574 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1577 struct enc_test_entry_t {
1585 static const struct enc_test_entry_t encoding_test_data[] = {
1586 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
1587 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
1588 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
1589 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
1593 static void test_encoding(void)
1595 const struct enc_test_entry_t *entry = encoding_test_data;
1596 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1597 static const CHAR testXmlA[] = "test.xml";
1598 ISAXXMLReader *reader;
1605 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1608 win_skip("can't create %s instance\n", entry->clsid);
1613 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1614 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1615 WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
1618 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1620 todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1622 ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1624 DeleteFileA(testXmlA);
1625 ISAXXMLReader_Release(reader);
1631 static void test_mxwriter_handlers(void)
1633 ISAXContentHandler *handler;
1634 IMXWriter *writer, *writer2;
1635 ISAXLexicalHandler *lh;
1638 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1639 &IID_IMXWriter, (void**)&writer);
1640 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1642 EXPECT_REF(writer, 1);
1644 /* ISAXContentHandler */
1645 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
1646 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1647 EXPECT_REF(writer, 2);
1648 EXPECT_REF(handler, 2);
1650 hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
1651 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1652 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1653 EXPECT_REF(writer, 3);
1654 EXPECT_REF(writer2, 3);
1655 IMXWriter_Release(writer2);
1656 ISAXContentHandler_Release(handler);
1658 /* ISAXLexicalHandler */
1659 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lh);
1660 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1661 EXPECT_REF(writer, 2);
1664 hr = ISAXLexicalHandler_QueryInterface(lh, &IID_IMXWriter, (void**)&writer2);
1665 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1666 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1667 EXPECT_REF(writer, 3);
1668 EXPECT_REF(writer2, 3);
1669 IMXWriter_Release(writer2);
1671 IMXWriter_Release(writer);
1674 struct msxmlsupported_data_t
1681 static struct msxmlsupported_data_t msxmlsupported_data[] =
1683 { &CLSID_MXXMLWriter, "MXXMLWriter" },
1684 { &CLSID_MXXMLWriter30, "MXXMLWriter30" },
1685 { &CLSID_MXXMLWriter40, "MXXMLWriter40" },
1686 { &CLSID_MXXMLWriter60, "MXXMLWriter60" },
1690 static BOOL is_mxwriter_supported(const GUID *clsid, const struct msxmlsupported_data_t *table)
1692 while (table->clsid)
1694 if (table->clsid == clsid) return table->supported;
1700 struct mxwriter_props_t
1704 VARIANT_BOOL disable_escape;
1705 VARIANT_BOOL indent;
1706 VARIANT_BOOL omitdecl;
1707 VARIANT_BOOL standalone;
1708 const char *encoding;
1711 static const struct mxwriter_props_t mxwriter_default_props[] =
1713 { &CLSID_MXXMLWriter, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1714 { &CLSID_MXXMLWriter30, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1715 { &CLSID_MXXMLWriter40, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1716 { &CLSID_MXXMLWriter60, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1720 static void test_mxwriter_default_properties(const struct mxwriter_props_t *table)
1724 while (table->clsid)
1731 if (!is_mxwriter_supported(table->clsid, msxmlsupported_data))
1738 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1739 &IID_IMXWriter, (void**)&writer);
1740 EXPECT_HR(hr, S_OK);
1743 hr = IMXWriter_get_byteOrderMark(writer, &b);
1744 EXPECT_HR(hr, S_OK);
1745 ok(table->bom == b, "test %d: got BOM %d, expected %d\n", i, b, table->bom);
1747 b = !table->disable_escape;
1748 hr = IMXWriter_get_disableOutputEscaping(writer, &b);
1749 EXPECT_HR(hr, S_OK);
1750 ok(table->disable_escape == b, "test %d: got disable escape %d, expected %d\n", i, b,
1751 table->disable_escape);
1754 hr = IMXWriter_get_indent(writer, &b);
1755 EXPECT_HR(hr, S_OK);
1756 ok(table->indent == b, "test %d: got indent %d, expected %d\n", i, b, table->indent);
1758 b = !table->omitdecl;
1759 hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
1760 EXPECT_HR(hr, S_OK);
1761 ok(table->omitdecl == b, "test %d: got omitdecl %d, expected %d\n", i, b, table->omitdecl);
1763 b = !table->standalone;
1764 hr = IMXWriter_get_standalone(writer, &b);
1765 EXPECT_HR(hr, S_OK);
1766 ok(table->standalone == b, "test %d: got standalone %d, expected %d\n", i, b, table->standalone);
1768 hr = IMXWriter_get_encoding(writer, &encoding);
1769 EXPECT_HR(hr, S_OK);
1770 ok(!lstrcmpW(encoding, _bstr_(table->encoding)), "test %d: got encoding %s, expected %s\n",
1771 i, wine_dbgstr_w(encoding), table->encoding);
1772 SysFreeString(encoding);
1774 IMXWriter_Release(writer);
1781 static void test_mxwriter_properties(void)
1783 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
1784 static const WCHAR emptyW[] = {0};
1785 static const WCHAR testW[] = {'t','e','s','t',0};
1786 ISAXContentHandler *content;
1793 test_mxwriter_default_properties(mxwriter_default_props);
1795 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1796 &IID_IMXWriter, (void**)&writer);
1797 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1799 hr = IMXWriter_get_disableOutputEscaping(writer, NULL);
1800 ok(hr == E_POINTER, "got %08x\n", hr);
1802 hr = IMXWriter_get_byteOrderMark(writer, NULL);
1803 ok(hr == E_POINTER, "got %08x\n", hr);
1805 hr = IMXWriter_get_indent(writer, NULL);
1806 ok(hr == E_POINTER, "got %08x\n", hr);
1808 hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
1809 ok(hr == E_POINTER, "got %08x\n", hr);
1811 hr = IMXWriter_get_standalone(writer, NULL);
1812 ok(hr == E_POINTER, "got %08x\n", hr);
1815 hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
1816 ok(hr == S_OK, "got %08x\n", hr);
1819 hr = IMXWriter_get_standalone(writer, &b);
1820 ok(hr == S_OK, "got %08x\n", hr);
1821 ok(b == VARIANT_TRUE, "got %d\n", b);
1823 hr = IMXWriter_get_encoding(writer, NULL);
1824 EXPECT_HR(hr, E_POINTER);
1826 /* UTF-16 is a default setting apparently */
1827 str = (void*)0xdeadbeef;
1828 hr = IMXWriter_get_encoding(writer, &str);
1829 EXPECT_HR(hr, S_OK);
1830 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1832 str2 = (void*)0xdeadbeef;
1833 hr = IMXWriter_get_encoding(writer, &str2);
1834 ok(hr == S_OK, "got %08x\n", hr);
1835 ok(str != str2, "expected newly allocated, got same %p\n", str);
1837 SysFreeString(str2);
1840 /* put empty string */
1841 str = SysAllocString(emptyW);
1842 hr = IMXWriter_put_encoding(writer, str);
1843 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1846 str = (void*)0xdeadbeef;
1847 hr = IMXWriter_get_encoding(writer, &str);
1848 EXPECT_HR(hr, S_OK);
1849 ok(!lstrcmpW(str, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(str));
1852 /* invalid encoding name */
1853 str = SysAllocString(testW);
1854 hr = IMXWriter_put_encoding(writer, str);
1855 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1858 /* test case sensivity */
1859 hr = IMXWriter_put_encoding(writer, _bstr_("utf-8"));
1860 EXPECT_HR(hr, S_OK);
1861 str = (void*)0xdeadbeef;
1862 hr = IMXWriter_get_encoding(writer, &str);
1863 EXPECT_HR(hr, S_OK);
1864 ok(!lstrcmpW(str, _bstr_("utf-8")), "got %s\n", wine_dbgstr_w(str));
1867 hr = IMXWriter_put_encoding(writer, _bstr_("uTf-16"));
1868 EXPECT_HR(hr, S_OK);
1869 str = (void*)0xdeadbeef;
1870 hr = IMXWriter_get_encoding(writer, &str);
1871 EXPECT_HR(hr, S_OK);
1872 ok(!lstrcmpW(str, _bstr_("uTf-16")), "got %s\n", wine_dbgstr_w(str));
1875 /* how it affects document creation */
1876 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1877 EXPECT_HR(hr, S_OK);
1879 hr = ISAXContentHandler_startDocument(content);
1880 EXPECT_HR(hr, S_OK);
1881 hr = ISAXContentHandler_endDocument(content);
1882 EXPECT_HR(hr, S_OK);
1884 V_VT(&dest) = VT_EMPTY;
1885 hr = IMXWriter_get_output(writer, &dest);
1886 EXPECT_HR(hr, S_OK);
1887 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1888 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\"?>\r\n"),
1889 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1890 VariantClear(&dest);
1891 ISAXContentHandler_Release(content);
1893 hr = IMXWriter_get_version(writer, NULL);
1894 ok(hr == E_POINTER, "got %08x\n", hr);
1895 /* default version is 'surprisingly' 1.0 */
1896 hr = IMXWriter_get_version(writer, &str);
1897 ok(hr == S_OK, "got %08x\n", hr);
1898 ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1901 /* store version string as is */
1902 hr = IMXWriter_put_version(writer, NULL);
1903 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1905 hr = IMXWriter_put_version(writer, _bstr_("1.0"));
1906 ok(hr == S_OK, "got %08x\n", hr);
1908 hr = IMXWriter_put_version(writer, _bstr_(""));
1909 ok(hr == S_OK, "got %08x\n", hr);
1910 hr = IMXWriter_get_version(writer, &str);
1911 ok(hr == S_OK, "got %08x\n", hr);
1912 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
1915 hr = IMXWriter_put_version(writer, _bstr_("a.b"));
1916 ok(hr == S_OK, "got %08x\n", hr);
1917 hr = IMXWriter_get_version(writer, &str);
1918 ok(hr == S_OK, "got %08x\n", hr);
1919 ok(!lstrcmpW(str, _bstr_("a.b")), "got %s\n", wine_dbgstr_w(str));
1922 hr = IMXWriter_put_version(writer, _bstr_("2.0"));
1923 ok(hr == S_OK, "got %08x\n", hr);
1924 hr = IMXWriter_get_version(writer, &str);
1925 ok(hr == S_OK, "got %08x\n", hr);
1926 ok(!lstrcmpW(str, _bstr_("2.0")), "got %s\n", wine_dbgstr_w(str));
1929 IMXWriter_Release(writer);
1933 static void test_mxwriter_flush(void)
1935 ISAXContentHandler *content;
1938 ULARGE_INTEGER pos2;
1943 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1944 &IID_IMXWriter, (void**)&writer);
1945 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1947 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1948 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1949 EXPECT_REF(stream, 1);
1951 /* detach when nothing was attached */
1952 V_VT(&dest) = VT_EMPTY;
1953 hr = IMXWriter_put_output(writer, dest);
1954 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1957 V_VT(&dest) = VT_UNKNOWN;
1958 V_UNKNOWN(&dest) = (IUnknown*)stream;
1959 hr = IMXWriter_put_output(writer, dest);
1960 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1961 todo_wine EXPECT_REF(stream, 3);
1963 /* detach setting VT_EMPTY destination */
1964 V_VT(&dest) = VT_EMPTY;
1965 hr = IMXWriter_put_output(writer, dest);
1966 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1967 EXPECT_REF(stream, 1);
1969 V_VT(&dest) = VT_UNKNOWN;
1970 V_UNKNOWN(&dest) = (IUnknown*)stream;
1971 hr = IMXWriter_put_output(writer, dest);
1972 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1974 /* flush() doesn't detach a stream */
1975 hr = IMXWriter_flush(writer);
1976 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1977 todo_wine EXPECT_REF(stream, 3);
1980 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1981 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1982 ok(pos2.QuadPart == 0, "expected stream beginning\n");
1984 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1985 ok(hr == S_OK, "got %08x\n", hr);
1987 hr = ISAXContentHandler_startDocument(content);
1988 ok(hr == S_OK, "got %08x\n", hr);
1991 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1992 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1993 ok(pos2.QuadPart != 0, "expected stream beginning\n");
1995 /* already started */
1996 hr = ISAXContentHandler_startDocument(content);
1997 ok(hr == S_OK, "got %08x\n", hr);
1999 hr = ISAXContentHandler_endDocument(content);
2000 ok(hr == S_OK, "got %08x\n", hr);
2002 /* flushed on endDocument() */
2004 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2005 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2006 ok(pos2.QuadPart != 0, "expected stream position moved\n");
2008 ISAXContentHandler_Release(content);
2009 IStream_Release(stream);
2010 IMXWriter_Release(writer);
2013 static void test_mxwriter_startenddocument(void)
2015 ISAXContentHandler *content;
2020 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2021 &IID_IMXWriter, (void**)&writer);
2022 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2024 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2025 ok(hr == S_OK, "got %08x\n", hr);
2027 hr = ISAXContentHandler_startDocument(content);
2028 ok(hr == S_OK, "got %08x\n", hr);
2030 hr = ISAXContentHandler_endDocument(content);
2031 ok(hr == S_OK, "got %08x\n", hr);
2033 V_VT(&dest) = VT_EMPTY;
2034 hr = IMXWriter_get_output(writer, &dest);
2035 ok(hr == S_OK, "got %08x\n", hr);
2036 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2037 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2038 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2039 VariantClear(&dest);
2041 /* now try another startDocument */
2042 hr = ISAXContentHandler_startDocument(content);
2043 ok(hr == S_OK, "got %08x\n", hr);
2044 /* and get duplicated prolog */
2045 V_VT(&dest) = VT_EMPTY;
2046 hr = IMXWriter_get_output(writer, &dest);
2047 ok(hr == S_OK, "got %08x\n", hr);
2048 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2049 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
2050 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2051 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2052 VariantClear(&dest);
2054 ISAXContentHandler_Release(content);
2055 IMXWriter_Release(writer);
2057 /* now with omitted declaration */
2058 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2059 &IID_IMXWriter, (void**)&writer);
2060 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2062 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2063 ok(hr == S_OK, "got %08x\n", hr);
2065 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2066 ok(hr == S_OK, "got %08x\n", hr);
2068 hr = ISAXContentHandler_startDocument(content);
2069 ok(hr == S_OK, "got %08x\n", hr);
2071 hr = ISAXContentHandler_endDocument(content);
2072 ok(hr == S_OK, "got %08x\n", hr);
2074 V_VT(&dest) = VT_EMPTY;
2075 hr = IMXWriter_get_output(writer, &dest);
2076 ok(hr == S_OK, "got %08x\n", hr);
2077 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2078 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2079 VariantClear(&dest);
2081 ISAXContentHandler_Release(content);
2082 IMXWriter_Release(writer);
2094 struct writer_startendelement_t {
2096 enum startendtype type;
2098 const char *local_name;
2102 ISAXAttributes *attr;
2105 static const char startelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"<&">\">";
2106 static const char startendelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"<&">\"/>";
2108 static const struct writer_startendelement_t writer_startendelement[] = {
2110 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2111 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2112 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2113 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, NULL, "<>", S_OK },
2114 { &CLSID_MXXMLWriter, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2116 { &CLSID_MXXMLWriter30, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2117 { &CLSID_MXXMLWriter40, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2118 { &CLSID_MXXMLWriter60, StartElement, "uri", NULL, NULL, "<>", S_OK },
2119 { &CLSID_MXXMLWriter, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2120 { &CLSID_MXXMLWriter30, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2122 { &CLSID_MXXMLWriter40, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2123 { &CLSID_MXXMLWriter60, StartElement, NULL, "local", NULL, "<>", S_OK },
2124 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2125 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2126 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2128 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, "qname", "<qname>", S_OK },
2129 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2130 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2131 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2132 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2134 { &CLSID_MXXMLWriter, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2135 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2136 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2137 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", NULL, "<>", S_OK },
2138 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2140 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2141 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2142 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2143 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2144 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2146 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2147 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2148 /* endElement tests */
2149 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2150 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2151 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2153 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, NULL, "</>", S_OK },
2154 { &CLSID_MXXMLWriter, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2155 { &CLSID_MXXMLWriter30, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2156 { &CLSID_MXXMLWriter40, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2157 { &CLSID_MXXMLWriter60, EndElement, "uri", NULL, NULL, "</>", S_OK },
2159 { &CLSID_MXXMLWriter, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2160 { &CLSID_MXXMLWriter30, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2161 { &CLSID_MXXMLWriter40, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2162 { &CLSID_MXXMLWriter60, EndElement, NULL, "local", NULL, "</>", S_OK },
2163 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2165 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2166 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2167 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, "qname", "</qname>", S_OK },
2168 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2169 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2171 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2172 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2173 { &CLSID_MXXMLWriter, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2174 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2175 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2177 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", NULL, "</>", S_OK },
2178 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2179 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2180 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2181 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2183 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2184 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2185 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2186 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2188 /* with attributes */
2189 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2191 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2192 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2193 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2194 /* empty elements */
2195 { &CLSID_MXXMLWriter, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2196 { &CLSID_MXXMLWriter30, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2198 { &CLSID_MXXMLWriter40, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2199 { &CLSID_MXXMLWriter60, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2200 { &CLSID_MXXMLWriter, StartEndElement, "", "", "", "</>", S_OK },
2201 { &CLSID_MXXMLWriter30, StartEndElement, "", "", "", "</>", S_OK },
2202 { &CLSID_MXXMLWriter40, StartEndElement, "", "", "", "</>", S_OK },
2204 { &CLSID_MXXMLWriter60, StartEndElement, "", "", "", "</>", S_OK },
2208 static void get_supported_mxwriter_data(struct msxmlsupported_data_t *table)
2210 while (table->clsid)
2215 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2216 &IID_IMXWriter, (void**)&writer);
2217 if (hr == S_OK) IMXWriter_Release(writer);
2219 table->supported = hr == S_OK;
2220 if (hr != S_OK) win_skip("class %s not supported\n", table->name);
2226 static void test_mxwriter_startendelement_batch(const struct writer_startendelement_t *table)
2230 while (table->clsid)
2232 ISAXContentHandler *content;
2236 if (!is_mxwriter_supported(table->clsid, msxmlsupported_data))
2243 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2244 &IID_IMXWriter, (void**)&writer);
2245 EXPECT_HR(hr, S_OK);
2247 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2248 EXPECT_HR(hr, S_OK);
2250 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2251 EXPECT_HR(hr, S_OK);
2253 hr = ISAXContentHandler_startDocument(content);
2254 EXPECT_HR(hr, S_OK);
2256 if (table->type == StartElement)
2258 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2259 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2260 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2262 else if (table->type == EndElement)
2264 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2265 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2266 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2270 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2271 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2272 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2273 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2274 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2275 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2283 V_VT(&dest) = VT_EMPTY;
2284 hr = IMXWriter_get_output(writer, &dest);
2285 EXPECT_HR(hr, S_OK);
2286 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2287 ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
2288 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
2289 VariantClear(&dest);
2292 ISAXContentHandler_Release(content);
2293 IMXWriter_Release(writer);
2302 static void test_mxwriter_startendelement(void)
2304 ISAXContentHandler *content;
2309 test_mxwriter_startendelement_batch(writer_startendelement);
2311 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2312 &IID_IMXWriter, (void**)&writer);
2313 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2315 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2316 ok(hr == S_OK, "got %08x\n", hr);
2318 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2319 ok(hr == S_OK, "got %08x\n", hr);
2321 hr = ISAXContentHandler_startDocument(content);
2322 ok(hr == S_OK, "got %08x\n", hr);
2324 /* all string pointers should be not null */
2325 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
2326 ok(hr == S_OK, "got %08x\n", hr);
2328 V_VT(&dest) = VT_EMPTY;
2329 hr = IMXWriter_get_output(writer, &dest);
2330 ok(hr == S_OK, "got %08x\n", hr);
2331 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2332 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2333 VariantClear(&dest);
2335 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
2336 ok(hr == S_OK, "got %08x\n", hr);
2338 V_VT(&dest) = VT_EMPTY;
2339 hr = IMXWriter_get_output(writer, &dest);
2340 ok(hr == S_OK, "got %08x\n", hr);
2341 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2342 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2343 VariantClear(&dest);
2345 hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
2346 EXPECT_HR(hr, E_INVALIDARG);
2348 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
2349 EXPECT_HR(hr, E_INVALIDARG);
2351 /* only local name is an error too */
2352 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
2353 EXPECT_HR(hr, E_INVALIDARG);
2355 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
2356 EXPECT_HR(hr, S_OK);
2358 V_VT(&dest) = VT_EMPTY;
2359 hr = IMXWriter_get_output(writer, &dest);
2360 EXPECT_HR(hr, S_OK);
2361 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2362 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2363 VariantClear(&dest);
2365 hr = ISAXContentHandler_endDocument(content);
2366 EXPECT_HR(hr, S_OK);
2368 V_VT(&dest) = VT_EMPTY;
2369 hr = IMXWriter_put_output(writer, dest);
2370 EXPECT_HR(hr, S_OK);
2372 V_VT(&dest) = VT_EMPTY;
2373 hr = IMXWriter_get_output(writer, &dest);
2374 EXPECT_HR(hr, S_OK);
2375 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2376 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2377 VariantClear(&dest);
2379 hr = ISAXContentHandler_startDocument(content);
2380 EXPECT_HR(hr, S_OK);
2382 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abcdef"), 3, NULL);
2383 EXPECT_HR(hr, S_OK);
2385 V_VT(&dest) = VT_EMPTY;
2386 hr = IMXWriter_get_output(writer, &dest);
2387 EXPECT_HR(hr, S_OK);
2388 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2389 ok(!lstrcmpW(_bstr_("<abc>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2390 VariantClear(&dest);
2392 ISAXContentHandler_endDocument(content);
2393 IMXWriter_flush(writer);
2395 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abdcdef"), 3);
2396 EXPECT_HR(hr, S_OK);
2397 V_VT(&dest) = VT_EMPTY;
2398 hr = IMXWriter_get_output(writer, &dest);
2399 EXPECT_HR(hr, S_OK);
2400 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2401 ok(!lstrcmpW(_bstr_("<abc></abd>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2402 VariantClear(&dest);
2404 ISAXContentHandler_Release(content);
2405 IMXWriter_Release(writer);
2409 static void test_mxwriter_characters(void)
2411 static const WCHAR chardataW[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
2412 ISAXContentHandler *content;
2417 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2418 &IID_IMXWriter, (void**)&writer);
2419 EXPECT_HR(hr, S_OK);
2421 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2422 EXPECT_HR(hr, S_OK);
2424 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2425 EXPECT_HR(hr, S_OK);
2427 hr = ISAXContentHandler_startDocument(content);
2428 EXPECT_HR(hr, S_OK);
2430 hr = ISAXContentHandler_characters(content, NULL, 0);
2431 EXPECT_HR(hr, E_INVALIDARG);
2433 hr = ISAXContentHandler_characters(content, chardataW, 0);
2434 EXPECT_HR(hr, S_OK);
2436 hr = ISAXContentHandler_characters(content, chardataW, sizeof(chardataW)/sizeof(WCHAR) - 1);
2437 EXPECT_HR(hr, S_OK);
2439 V_VT(&dest) = VT_EMPTY;
2440 hr = IMXWriter_get_output(writer, &dest);
2441 EXPECT_HR(hr, S_OK);
2442 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2443 ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2444 VariantClear(&dest);
2446 hr = ISAXContentHandler_endDocument(content);
2447 EXPECT_HR(hr, S_OK);
2449 ISAXContentHandler_Release(content);
2450 IMXWriter_Release(writer);
2452 /* try empty characters data to see if element is closed */
2453 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2454 &IID_IMXWriter, (void**)&writer);
2455 EXPECT_HR(hr, S_OK);
2457 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2458 EXPECT_HR(hr, S_OK);
2460 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2461 EXPECT_HR(hr, S_OK);
2463 hr = ISAXContentHandler_startDocument(content);
2464 EXPECT_HR(hr, S_OK);
2466 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2467 EXPECT_HR(hr, S_OK);
2469 hr = ISAXContentHandler_characters(content, chardataW, 0);
2470 EXPECT_HR(hr, S_OK);
2472 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2473 EXPECT_HR(hr, S_OK);
2475 V_VT(&dest) = VT_EMPTY;
2476 hr = IMXWriter_get_output(writer, &dest);
2477 EXPECT_HR(hr, S_OK);
2478 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2479 ok(!lstrcmpW(_bstr_("<a></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2480 VariantClear(&dest);
2482 ISAXContentHandler_Release(content);
2483 IMXWriter_Release(writer);
2488 static const mxwriter_stream_test mxwriter_stream_tests[] = {
2490 VARIANT_TRUE,"UTF-16",
2492 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2493 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2498 VARIANT_FALSE,"UTF-16",
2500 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2505 VARIANT_TRUE,"UTF-8",
2507 {FALSE,(const BYTE*)szUtf8XML,sizeof(szUtf8XML)-1},
2508 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2509 * and the writer is released.
2516 VARIANT_TRUE,"utf-8",
2518 {FALSE,(const BYTE*)utf8xml2,sizeof(utf8xml2)-1},
2519 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2520 * and the writer is released.
2527 VARIANT_TRUE,"UTF-16",
2529 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2530 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2535 VARIANT_TRUE,"UTF-16",
2537 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE,TRUE},
2538 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2544 static void test_mxwriter_stream(void)
2547 ISAXContentHandler *content;
2552 ULARGE_INTEGER pos2;
2553 DWORD test_count = sizeof(mxwriter_stream_tests)/sizeof(mxwriter_stream_tests[0]);
2555 for(current_stream_test_index = 0; current_stream_test_index < test_count; ++current_stream_test_index) {
2556 const mxwriter_stream_test *test = mxwriter_stream_tests+current_stream_test_index;
2558 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2559 &IID_IMXWriter, (void**)&writer);
2560 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2562 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2563 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2565 hr = IMXWriter_put_encoding(writer, _bstr_(test->encoding));
2566 ok(hr == S_OK, "put_encoding failed with %08x on test %d\n", hr, current_stream_test_index);
2568 V_VT(&dest) = VT_UNKNOWN;
2569 V_UNKNOWN(&dest) = (IUnknown*)&mxstream;
2570 hr = IMXWriter_put_output(writer, dest);
2571 ok(hr == S_OK, "put_output failed with %08x on test %d\n", hr, current_stream_test_index);
2572 VariantClear(&dest);
2574 hr = IMXWriter_put_byteOrderMark(writer, test->bom);
2575 ok(hr == S_OK, "put_byteOrderMark failed with %08x on test %d\n", hr, current_stream_test_index);
2577 current_write_test = test->expected_writes;
2579 hr = ISAXContentHandler_startDocument(content);
2580 ok(hr == S_OK, "startDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2582 hr = ISAXContentHandler_endDocument(content);
2583 ok(hr == S_OK, "endDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2585 ISAXContentHandler_Release(content);
2586 IMXWriter_Release(writer);
2588 ok(current_write_test->last, "The last %d write calls on test %d were missed\n",
2589 (int)(current_write_test-test->expected_writes), current_stream_test_index);
2592 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2593 &IID_IMXWriter, (void**)&writer);
2594 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2596 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2597 ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
2599 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2600 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2602 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2603 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
2605 V_VT(&dest) = VT_UNKNOWN;
2606 V_UNKNOWN(&dest) = (IUnknown*)stream;
2607 hr = IMXWriter_put_output(writer, dest);
2608 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2610 hr = ISAXContentHandler_startDocument(content);
2611 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2613 /* Setting output of the mxwriter causes the current output to be flushed,
2614 * and the writer to start over.
2616 V_VT(&dest) = VT_EMPTY;
2617 hr = IMXWriter_put_output(writer, dest);
2618 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2621 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2622 ok(hr == S_OK, "Seek failed: %08x\n", hr);
2623 ok(pos2.QuadPart != 0, "expected stream position moved\n");
2625 hr = ISAXContentHandler_startDocument(content);
2626 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2628 hr = ISAXContentHandler_endDocument(content);
2629 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
2631 V_VT(&dest) = VT_EMPTY;
2632 hr = IMXWriter_get_output(writer, &dest);
2633 ok(hr == S_OK, "get_output failed: %08x\n", hr);
2634 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2635 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2636 "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2637 VariantClear(&dest);
2639 /* test when BOM is written to output stream */
2640 V_VT(&dest) = VT_EMPTY;
2641 hr = IMXWriter_put_output(writer, dest);
2642 EXPECT_HR(hr, S_OK);
2645 hr = IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
2646 EXPECT_HR(hr, S_OK);
2648 V_VT(&dest) = VT_UNKNOWN;
2649 V_UNKNOWN(&dest) = (IUnknown*)stream;
2650 hr = IMXWriter_put_output(writer, dest);
2651 EXPECT_HR(hr, S_OK);
2653 hr = IMXWriter_put_byteOrderMark(writer, VARIANT_TRUE);
2654 EXPECT_HR(hr, S_OK);
2656 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2657 EXPECT_HR(hr, S_OK);
2659 hr = ISAXContentHandler_startDocument(content);
2660 EXPECT_HR(hr, S_OK);
2664 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2665 EXPECT_HR(hr, S_OK);
2666 ok(pos2.QuadPart == 2, "got wrong position\n");
2668 ISAXContentHandler_Release(content);
2669 IMXWriter_Release(writer);
2674 static void test_mxwriter_encoding(void)
2676 ISAXContentHandler *content;
2685 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2686 &IID_IMXWriter, (void**)&writer);
2687 EXPECT_HR(hr, S_OK);
2689 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2690 EXPECT_HR(hr, S_OK);
2692 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2693 EXPECT_HR(hr, S_OK);
2695 hr = ISAXContentHandler_startDocument(content);
2696 EXPECT_HR(hr, S_OK);
2698 hr = ISAXContentHandler_endDocument(content);
2699 EXPECT_HR(hr, S_OK);
2701 /* The content is always re-encoded to UTF-16 when the output is
2702 * retrieved as a BSTR.
2704 V_VT(&dest) = VT_EMPTY;
2705 hr = IMXWriter_get_output(writer, &dest);
2706 EXPECT_HR(hr, S_OK);
2707 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2708 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2709 "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2710 VariantClear(&dest);
2712 /* switch encoding when something is written already */
2713 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2714 EXPECT_HR(hr, S_OK);
2716 V_VT(&dest) = VT_UNKNOWN;
2717 V_UNKNOWN(&dest) = (IUnknown*)stream;
2718 hr = IMXWriter_put_output(writer, dest);
2719 EXPECT_HR(hr, S_OK);
2721 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2722 EXPECT_HR(hr, S_OK);
2724 /* write empty element */
2725 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2726 EXPECT_HR(hr, S_OK);
2728 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2729 EXPECT_HR(hr, S_OK);
2732 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2733 EXPECT_HR(hr, S_OK);
2735 hr = IMXWriter_flush(writer);
2736 EXPECT_HR(hr, S_OK);
2738 hr = GetHGlobalFromStream(stream, &g);
2739 EXPECT_HR(hr, S_OK);
2741 ptr = GlobalLock(g);
2742 ok(!strncmp(ptr, "<a/>", 4), "got %c%c%c%c\n", ptr[0],ptr[1],ptr[2],ptr[3]);
2745 /* so output is unaffected, encoding name is stored however */
2746 hr = IMXWriter_get_encoding(writer, &s);
2747 EXPECT_HR(hr, S_OK);
2748 ok(!lstrcmpW(s, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(s));
2751 IStream_Release(stream);
2753 ISAXContentHandler_Release(content);
2754 IMXWriter_Release(writer);
2759 static void test_obj_dispex(IUnknown *obj)
2761 static const WCHAR starW[] = {'*',0};
2762 DISPID dispid = DISPID_SAX_XMLREADER_GETFEATURE;
2763 IDispatchEx *dispex;
2770 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
2771 EXPECT_HR(hr, S_OK);
2772 if (FAILED(hr)) return;
2775 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
2776 EXPECT_HR(hr, S_OK);
2777 ok(ticnt == 1, "ticnt=%u\n", ticnt);
2779 name = SysAllocString(starW);
2780 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
2781 EXPECT_HR(hr, E_NOTIMPL);
2782 SysFreeString(name);
2784 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
2785 EXPECT_HR(hr, E_NOTIMPL);
2788 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
2789 EXPECT_HR(hr, E_NOTIMPL);
2790 ok(props == 0, "expected 0 got %d\n", props);
2792 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
2793 EXPECT_HR(hr, E_NOTIMPL);
2794 if (SUCCEEDED(hr)) SysFreeString(name);
2796 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_SAX_XMLREADER_GETFEATURE, &dispid);
2797 EXPECT_HR(hr, E_NOTIMPL);
2799 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
2800 EXPECT_HR(hr, E_NOTIMPL);
2801 if (hr == S_OK && unk) IUnknown_Release(unk);
2803 IDispatchEx_Release(dispex);
2806 static void test_dispex(void)
2808 IVBSAXXMLReader *vbreader;
2809 ISAXXMLReader *reader;
2813 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
2814 &IID_ISAXXMLReader, (void**)&reader);
2815 EXPECT_HR(hr, S_OK);
2817 hr = ISAXXMLReader_QueryInterface(reader, &IID_IUnknown, (void**)&unk);
2818 EXPECT_HR(hr, S_OK);
2819 test_obj_dispex(unk);
2820 IUnknown_Release(unk);
2822 hr = ISAXXMLReader_QueryInterface(reader, &IID_IVBSAXXMLReader, (void**)&vbreader);
2823 EXPECT_HR(hr, S_OK);
2824 hr = IVBSAXXMLReader_QueryInterface(vbreader, &IID_IUnknown, (void**)&unk);
2825 EXPECT_HR(hr, S_OK);
2826 test_obj_dispex(unk);
2827 IUnknown_Release(unk);
2828 IVBSAXXMLReader_Release(vbreader);
2830 ISAXXMLReader_Release(reader);
2833 static void test_mxwriter_dispex(void)
2835 IDispatchEx *dispex;
2840 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2841 &IID_IMXWriter, (void**)&writer);
2842 EXPECT_HR(hr, S_OK);
2844 hr = IMXWriter_QueryInterface(writer, &IID_IDispatchEx, (void**)&dispex);
2845 EXPECT_HR(hr, S_OK);
2846 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
2847 test_obj_dispex(unk);
2848 IUnknown_Release(unk);
2849 IDispatchEx_Release(dispex);
2851 IMXWriter_Release(writer);
2854 static void test_mxwriter_comment(void)
2856 static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
2857 ISAXContentHandler *content;
2858 ISAXLexicalHandler *lexical;
2863 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2864 &IID_IMXWriter, (void**)&writer);
2865 EXPECT_HR(hr, S_OK);
2867 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2868 EXPECT_HR(hr, S_OK);
2870 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
2871 EXPECT_HR(hr, S_OK);
2873 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2874 EXPECT_HR(hr, S_OK);
2876 hr = ISAXContentHandler_startDocument(content);
2877 EXPECT_HR(hr, S_OK);
2879 hr = ISAXLexicalHandler_comment(lexical, NULL, 0);
2880 EXPECT_HR(hr, E_INVALIDARG);
2882 hr = ISAXLexicalHandler_comment(lexical, commentW, 0);
2883 EXPECT_HR(hr, S_OK);
2885 V_VT(&dest) = VT_EMPTY;
2886 hr = IMXWriter_get_output(writer, &dest);
2887 EXPECT_HR(hr, S_OK);
2888 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2889 ok(!lstrcmpW(_bstr_("<!---->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2890 VariantClear(&dest);
2892 hr = ISAXLexicalHandler_comment(lexical, commentW, sizeof(commentW)/sizeof(WCHAR)-1);
2893 EXPECT_HR(hr, S_OK);
2895 V_VT(&dest) = VT_EMPTY;
2896 hr = IMXWriter_get_output(writer, &dest);
2897 EXPECT_HR(hr, S_OK);
2898 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2899 ok(!lstrcmpW(_bstr_("<!---->\r\n<!--comment-->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2900 VariantClear(&dest);
2902 ISAXContentHandler_Release(content);
2903 ISAXLexicalHandler_Release(lexical);
2904 IMXWriter_Release(writer);
2908 static void test_mxwriter_cdata(void)
2910 ISAXContentHandler *content;
2911 ISAXLexicalHandler *lexical;
2916 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2917 &IID_IMXWriter, (void**)&writer);
2918 EXPECT_HR(hr, S_OK);
2920 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2921 EXPECT_HR(hr, S_OK);
2923 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
2924 EXPECT_HR(hr, S_OK);
2926 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2927 EXPECT_HR(hr, S_OK);
2929 hr = ISAXContentHandler_startDocument(content);
2930 EXPECT_HR(hr, S_OK);
2932 hr = ISAXLexicalHandler_startCDATA(lexical);
2933 EXPECT_HR(hr, S_OK);
2935 V_VT(&dest) = VT_EMPTY;
2936 hr = IMXWriter_get_output(writer, &dest);
2937 EXPECT_HR(hr, S_OK);
2938 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2939 ok(!lstrcmpW(_bstr_("<![CDATA["), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2940 VariantClear(&dest);
2942 hr = ISAXLexicalHandler_startCDATA(lexical);
2943 EXPECT_HR(hr, S_OK);
2945 hr = ISAXLexicalHandler_endCDATA(lexical);
2946 EXPECT_HR(hr, S_OK);
2948 V_VT(&dest) = VT_EMPTY;
2949 hr = IMXWriter_get_output(writer, &dest);
2950 EXPECT_HR(hr, S_OK);
2951 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2952 ok(!lstrcmpW(_bstr_("<![CDATA[<![CDATA[]]>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2953 VariantClear(&dest);
2955 ISAXContentHandler_Release(content);
2956 ISAXLexicalHandler_Release(lexical);
2957 IMXWriter_Release(writer);
2961 static void test_mxwriter_dtd(void)
2963 static const WCHAR nameW[] = {'n','a','m','e'};
2964 static const WCHAR pubW[] = {'p','u','b'};
2965 static const WCHAR sysW[] = {'s','y','s'};
2966 ISAXContentHandler *content;
2967 ISAXLexicalHandler *lexical;
2972 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2973 &IID_IMXWriter, (void**)&writer);
2974 EXPECT_HR(hr, S_OK);
2976 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2977 EXPECT_HR(hr, S_OK);
2979 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
2980 EXPECT_HR(hr, S_OK);
2982 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2983 EXPECT_HR(hr, S_OK);
2985 hr = ISAXContentHandler_startDocument(content);
2986 EXPECT_HR(hr, S_OK);
2988 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, NULL, 0);
2989 EXPECT_HR(hr, E_INVALIDARG);
2991 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
2992 EXPECT_HR(hr, E_INVALIDARG);
2994 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, sysW, sizeof(sysW)/sizeof(WCHAR));
2995 EXPECT_HR(hr, E_INVALIDARG);
2997 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
2998 EXPECT_HR(hr, E_INVALIDARG);
3000 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), NULL, 0, NULL, 0);
3001 EXPECT_HR(hr, S_OK);
3003 V_VT(&dest) = VT_EMPTY;
3004 hr = IMXWriter_get_output(writer, &dest);
3005 EXPECT_HR(hr, S_OK);
3006 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3007 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3008 VariantClear(&dest);
3010 /* system id is required if public is present */
3011 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
3012 EXPECT_HR(hr, E_INVALIDARG);
3014 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR),
3015 pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
3016 EXPECT_HR(hr, S_OK);
3018 V_VT(&dest) = VT_EMPTY;
3019 hr = IMXWriter_get_output(writer, &dest);
3020 EXPECT_HR(hr, S_OK);
3021 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3022 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3023 "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3024 VariantClear(&dest);
3026 hr = ISAXLexicalHandler_endDTD(lexical);
3027 EXPECT_HR(hr, S_OK);
3029 hr = ISAXLexicalHandler_endDTD(lexical);
3030 EXPECT_HR(hr, S_OK);
3032 V_VT(&dest) = VT_EMPTY;
3033 hr = IMXWriter_get_output(writer, &dest);
3034 EXPECT_HR(hr, S_OK);
3035 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3036 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3037 "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n]>\r\n]>\r\n"),
3038 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3039 VariantClear(&dest);
3041 ISAXContentHandler_Release(content);
3042 ISAXLexicalHandler_Release(lexical);
3043 IMXWriter_Release(writer);
3047 START_TEST(saxreader)
3049 ISAXXMLReader *reader;
3052 hr = CoInitialize(NULL);
3053 ok(hr == S_OK, "failed to init com\n");
3055 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
3056 &IID_ISAXXMLReader, (void**)&reader);
3060 skip("Failed to create SAXXMLReader instance\n");
3064 ISAXXMLReader_Release(reader);
3069 test_saxreader_properties();
3070 test_saxreader_features();
3074 /* MXXMLWriter tests */
3075 get_supported_mxwriter_data(msxmlsupported_data);
3076 if (is_mxwriter_supported(&CLSID_MXXMLWriter, msxmlsupported_data))
3078 test_mxwriter_handlers();
3079 test_mxwriter_startenddocument();
3080 test_mxwriter_startendelement();
3081 test_mxwriter_characters();
3082 test_mxwriter_comment();
3083 test_mxwriter_cdata();
3084 test_mxwriter_dtd();
3085 test_mxwriter_properties();
3086 test_mxwriter_flush();
3087 test_mxwriter_stream();
3088 test_mxwriter_encoding();
3089 test_mxwriter_dispex();
3092 win_skip("MXXMLWriter not supported\n");