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)
332 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
336 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
337 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
339 if(msxml_version >= 6) {
340 ISAXAttributes *attr, *attr1;
341 IMXAttributes *mxattr;
343 EXPECT_REF(pLocator, 1);
344 hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr);
346 EXPECT_REF(pLocator, 2);
347 hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr1);
349 EXPECT_REF(pLocator, 3);
350 ok(attr == attr1, "got %p, %p\n", attr, attr1);
352 hr = ISAXAttributes_QueryInterface(attr, &IID_IMXAttributes, (void**)&mxattr);
353 EXPECT_HR(hr, E_NOINTERFACE);
355 ISAXAttributes_Release(attr);
356 ISAXAttributes_Release(attr1);
359 return (expectCall++)->ret;
362 static ISAXAttributes *test_attr_ptr;
363 static HRESULT WINAPI contentHandler_startDocument(
364 ISAXContentHandler* iface)
366 if(!test_expect_call(CH_STARTDOCUMENT))
369 test_attr_ptr = NULL;
370 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
371 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
373 return (expectCall++)->ret;
376 static HRESULT WINAPI contentHandler_endDocument(
377 ISAXContentHandler* iface)
379 if(!test_expect_call(CH_ENDDOCUMENT))
382 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
383 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
385 return (expectCall++)->ret;
388 static HRESULT WINAPI contentHandler_startPrefixMapping(
389 ISAXContentHandler* iface,
390 const WCHAR *pPrefix,
395 if(!test_expect_call(CH_STARTPREFIXMAPPING))
398 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
399 test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
400 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
401 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
403 return (expectCall++)->ret;
406 static HRESULT WINAPI contentHandler_endPrefixMapping(
407 ISAXContentHandler* iface,
408 const WCHAR *pPrefix,
411 if(!test_expect_call(CH_ENDPREFIXMAPPING))
414 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
415 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
416 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
418 return (expectCall++)->ret;
421 static HRESULT WINAPI contentHandler_startElement(
422 ISAXContentHandler* iface,
423 const WCHAR *pNamespaceUri,
425 const WCHAR *pLocalName,
429 ISAXAttributes *pAttr)
434 if(!test_expect_call(CH_STARTELEMENT))
437 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
438 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
439 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
440 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
441 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
444 test_attr_ptr = pAttr;
445 ok(test_attr_ptr == pAttr, "Multiple ISAXAttributes instances are used (%p %p)\n", test_attr_ptr, pAttr);
447 if(expectCall == contentHandlerTestAttributes+4) {
448 const WCHAR *uri_ptr = NULL;
450 /* msxml3 returns attributes and namespaces in the input order */
451 hres = ISAXAttributes_getLength(pAttr, &len);
452 ok(hres == S_OK, "getLength returned %x\n", hres);
453 ok(len == 5, "Incorrect number of attributes: %d\n", len);
454 ok(msxml_version < 6, "wrong msxml_version: %d\n", msxml_version);
456 for(i=0; i<len; i++) {
457 hres = ISAXAttributes_getName(pAttr, i, &pNamespaceUri, &nNamespaceUri,
458 &pLocalName, &nLocalName, &pQName, &nQName);
459 ok(hres == S_OK, "getName returned %x\n", hres);
462 todo_wine ok(i==3, "Incorrect attributes order\n");
463 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
464 test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
465 test_saxstr(__LINE__, pQName, nQName, "arg2");
466 } else if(nQName == 5) {
467 todo_wine ok(i==1, "Incorrect attributes order\n");
468 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
469 test_saxstr(__LINE__, pLocalName, nLocalName, "");
470 test_saxstr(__LINE__, pQName, nQName, "xmlns");
471 } else if(nQName == 8) {
472 todo_wine ok(i==4, "Incorrect attributes order\n");
473 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
474 test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
475 test_saxstr(__LINE__, pQName, nQName, "test:ar3");
476 ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
477 } else if(nQName == 9) {
478 todo_wine ok(i==2, "Incorrect attributes order\n");
479 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
480 test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
481 test_saxstr(__LINE__, pQName, nQName, "test:arg1");
482 uri_ptr = pNamespaceUri;
483 } else if(nQName == 10) {
484 todo_wine ok(i==0, "Incorrect attributes order\n");
485 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
486 test_saxstr(__LINE__, pLocalName, nLocalName, "");
487 test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
489 ok(0, "Unexpected attribute\n");
492 } else if(expectCall == contentHandlerTestAttributes6+4) {
493 const WCHAR *uri_ptr;
495 /* msxml6 returns attributes first and then namespaces */
496 hres = ISAXAttributes_getLength(pAttr, &len);
497 ok(hres == S_OK, "getLength returned %x\n", hres);
498 ok(len == 5, "Incorrect number of attributes: %d\n", len);
499 ok(msxml_version >= 6, "wrong msxml_version: %d\n", msxml_version);
501 hres = ISAXAttributes_getName(pAttr, 0, &pNamespaceUri, &nNamespaceUri,
502 &pLocalName, &nLocalName, &pQName, &nQName);
503 ok(hres == S_OK, "getName returned %x\n", hres);
504 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
505 test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
506 test_saxstr(__LINE__, pQName, nQName, "test:arg1");
507 uri_ptr = pNamespaceUri;
509 hres = ISAXAttributes_getName(pAttr, 1, &pNamespaceUri, &nNamespaceUri,
510 &pLocalName, &nLocalName, &pQName, &nQName);
511 ok(hres == S_OK, "getName returned %x\n", hres);
512 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
513 test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
514 test_saxstr(__LINE__, pQName, nQName, "arg2");
516 hres = ISAXAttributes_getName(pAttr, 2, &pNamespaceUri, &nNamespaceUri,
517 &pLocalName, &nLocalName, &pQName, &nQName);
518 ok(hres == S_OK, "getName returned %x\n", hres);
519 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
520 test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
521 test_saxstr(__LINE__, pQName, nQName, "test:ar3");
522 ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
524 hres = ISAXAttributes_getName(pAttr, 3, &pNamespaceUri, &nNamespaceUri,
525 &pLocalName, &nLocalName, &pQName, &nQName);
526 ok(hres == S_OK, "getName returned %x\n", hres);
527 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
528 test_saxstr(__LINE__, pLocalName, nLocalName, "");
529 test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
531 hres = ISAXAttributes_getName(pAttr, 4, &pNamespaceUri, &nNamespaceUri,
532 &pLocalName, &nLocalName, &pQName, &nQName);
533 ok(hres == S_OK, "getName returned %x\n", hres);
534 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
535 test_saxstr(__LINE__, pLocalName, nLocalName, "");
536 test_saxstr(__LINE__, pQName, nQName, "xmlns");
539 return (expectCall++)->ret;
542 static HRESULT WINAPI contentHandler_endElement(
543 ISAXContentHandler* iface,
544 const WCHAR *pNamespaceUri,
546 const WCHAR *pLocalName,
551 if(!test_expect_call(CH_ENDELEMENT))
554 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
555 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
556 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
557 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
558 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
560 return (expectCall++)->ret;
563 static HRESULT WINAPI contentHandler_characters(
564 ISAXContentHandler* iface,
568 if(!test_expect_call(CH_CHARACTERS))
571 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
572 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
573 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
575 return (expectCall++)->ret;
578 static HRESULT WINAPI contentHandler_ignorableWhitespace(
579 ISAXContentHandler* iface,
583 if(!test_expect_call(CH_IGNORABLEWHITESPACE))
586 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
587 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
588 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
590 return (expectCall++)->ret;
593 static HRESULT WINAPI contentHandler_processingInstruction(
594 ISAXContentHandler* iface,
595 const WCHAR *pTarget,
600 if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
603 test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
604 test_saxstr(__LINE__, pData, nData, expectCall->arg2);
605 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
606 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
608 return (expectCall++)->ret;
611 static HRESULT WINAPI contentHandler_skippedEntity(
612 ISAXContentHandler* iface,
616 if(!test_expect_call(CH_SKIPPEDENTITY))
619 test_saxstr(__LINE__, pName, nName, expectCall->arg1);
620 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
621 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
623 return (expectCall++)->ret;
627 static const ISAXContentHandlerVtbl contentHandlerVtbl =
629 contentHandler_QueryInterface,
630 contentHandler_AddRef,
631 contentHandler_Release,
632 contentHandler_putDocumentLocator,
633 contentHandler_startDocument,
634 contentHandler_endDocument,
635 contentHandler_startPrefixMapping,
636 contentHandler_endPrefixMapping,
637 contentHandler_startElement,
638 contentHandler_endElement,
639 contentHandler_characters,
640 contentHandler_ignorableWhitespace,
641 contentHandler_processingInstruction,
642 contentHandler_skippedEntity
645 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
647 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
648 ISAXErrorHandler* iface,
654 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
660 return E_NOINTERFACE;
666 static ULONG WINAPI isaxerrorHandler_AddRef(
667 ISAXErrorHandler* iface)
672 static ULONG WINAPI isaxerrorHandler_Release(
673 ISAXErrorHandler* iface)
678 static HRESULT WINAPI isaxerrorHandler_error(
679 ISAXErrorHandler* iface,
680 ISAXLocator *pLocator,
681 const WCHAR *pErrorMessage,
684 ok(0, "unexpected call\n");
688 static HRESULT WINAPI isaxerrorHandler_fatalError(
689 ISAXErrorHandler* iface,
690 ISAXLocator *pLocator,
691 const WCHAR *pErrorMessage,
694 if(!test_expect_call(EH_FATALERROR))
697 ok(hrErrorCode == expectCall->ret, "hrErrorCode = %x, expected %x\n", hrErrorCode, expectCall->ret);
703 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
704 ISAXErrorHandler* iface,
705 ISAXLocator *pLocator,
706 const WCHAR *pErrorMessage,
709 ok(0, "unexpected call\n");
713 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
715 isaxerrorHandler_QueryInterface,
716 isaxerrorHandler_AddRef,
717 isaxerrorHandler_Release,
718 isaxerrorHandler_error,
719 isaxerrorHandler_fatalError,
720 isaxerrorHanddler_ignorableWarning
723 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
725 static HRESULT WINAPI isaxattributes_QueryInterface(
726 ISAXAttributes* iface,
732 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
738 return E_NOINTERFACE;
744 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
749 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
754 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
760 static HRESULT WINAPI isaxattributes_getURI(
761 ISAXAttributes* iface,
766 ok(0, "unexpected call\n");
770 static HRESULT WINAPI isaxattributes_getLocalName(
771 ISAXAttributes* iface,
773 const WCHAR **pLocalName,
774 int *pLocalNameLength)
776 ok(0, "unexpected call\n");
780 static HRESULT WINAPI isaxattributes_getQName(
781 ISAXAttributes* iface,
786 static const WCHAR attrqnamesW[][15] = {{'a',':','a','t','t','r','1','j','u','n','k',0},
787 {'a','t','t','r','2','j','u','n','k',0},
788 {'a','t','t','r','3',0}};
789 static const int attrqnamelen[] = {7, 5, 5};
791 ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
793 *QName = attrqnamesW[index];
794 *QNameLength = attrqnamelen[index];
799 static HRESULT WINAPI isaxattributes_getName(
800 ISAXAttributes* iface,
804 const WCHAR ** pLocalName,
805 int * pLocalNameSize,
806 const WCHAR ** pQName,
809 ok(0, "unexpected call\n");
813 static HRESULT WINAPI isaxattributes_getIndexFromName(
814 ISAXAttributes* iface,
817 const WCHAR * pLocalName,
821 ok(0, "unexpected call\n");
825 static HRESULT WINAPI isaxattributes_getIndexFromQName(
826 ISAXAttributes* iface,
827 const WCHAR * pQName,
831 ok(0, "unexpected call\n");
835 static HRESULT WINAPI isaxattributes_getType(
836 ISAXAttributes* iface,
838 const WCHAR ** pType,
841 ok(0, "unexpected call\n");
845 static HRESULT WINAPI isaxattributes_getTypeFromName(
846 ISAXAttributes* iface,
849 const WCHAR * pLocalName,
851 const WCHAR ** pType,
854 ok(0, "unexpected call\n");
858 static HRESULT WINAPI isaxattributes_getTypeFromQName(
859 ISAXAttributes* iface,
860 const WCHAR * pQName,
862 const WCHAR ** pType,
865 ok(0, "unexpected call\n");
869 static HRESULT WINAPI isaxattributes_getValue(ISAXAttributes* iface, int index,
870 const WCHAR **value, int *nValue)
872 static const WCHAR attrvaluesW[][10] = {{'a','1','j','u','n','k',0},
873 {'a','2','j','u','n','k',0},
874 {'<','&','"','>',0}};
875 static const int attrvalueslen[] = {2, 2, 4};
877 ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
879 *value = attrvaluesW[index];
880 *nValue = attrvalueslen[index];
885 static HRESULT WINAPI isaxattributes_getValueFromName(
886 ISAXAttributes* iface,
889 const WCHAR * pLocalName,
891 const WCHAR ** pValue,
894 ok(0, "unexpected call\n");
898 static HRESULT WINAPI isaxattributes_getValueFromQName(
899 ISAXAttributes* iface,
900 const WCHAR * pQName,
902 const WCHAR ** pValue,
905 ok(0, "unexpected call\n");
909 static const ISAXAttributesVtbl SAXAttributesVtbl =
911 isaxattributes_QueryInterface,
912 isaxattributes_AddRef,
913 isaxattributes_Release,
914 isaxattributes_getLength,
915 isaxattributes_getURI,
916 isaxattributes_getLocalName,
917 isaxattributes_getQName,
918 isaxattributes_getName,
919 isaxattributes_getIndexFromName,
920 isaxattributes_getIndexFromQName,
921 isaxattributes_getType,
922 isaxattributes_getTypeFromName,
923 isaxattributes_getTypeFromQName,
924 isaxattributes_getValue,
925 isaxattributes_getValueFromName,
926 isaxattributes_getValueFromQName
929 static ISAXAttributes saxattributes = { &SAXAttributesVtbl };
931 static int handler_addrefcalled;
933 static HRESULT WINAPI isaxlexical_QueryInterface(ISAXLexicalHandler* iface, REFIID riid, void **ppvObject)
937 if(IsEqualGUID(riid, &IID_IUnknown) ||
938 IsEqualGUID(riid, &IID_ISAXLexicalHandler))
944 return E_NOINTERFACE;
950 static ULONG WINAPI isaxlexical_AddRef(ISAXLexicalHandler* iface)
952 handler_addrefcalled++;
956 static ULONG WINAPI isaxlexical_Release(ISAXLexicalHandler* iface)
961 static HRESULT WINAPI isaxlexical_startDTD(ISAXLexicalHandler* iface,
962 const WCHAR * pName, int nName, const WCHAR * pPublicId,
963 int nPublicId, const WCHAR * pSystemId, int nSystemId)
965 ok(0, "call not expected\n");
969 static HRESULT WINAPI isaxlexical_endDTD(ISAXLexicalHandler* iface)
971 ok(0, "call not expected\n");
975 static HRESULT WINAPI isaxlexical_startEntity(ISAXLexicalHandler *iface,
976 const WCHAR * pName, int nName)
978 ok(0, "call not expected\n");
982 static HRESULT WINAPI isaxlexical_endEntity(ISAXLexicalHandler *iface,
983 const WCHAR * pName, int nName)
985 ok(0, "call not expected\n");
989 static HRESULT WINAPI isaxlexical_startCDATA(ISAXLexicalHandler *iface)
991 ok(0, "call not expected\n");
995 static HRESULT WINAPI isaxlexical_endCDATA(ISAXLexicalHandler *iface)
997 ok(0, "call not expected\n");
1001 static HRESULT WINAPI isaxlexical_comment(ISAXLexicalHandler *iface,
1002 const WCHAR * pChars, int nChars)
1004 ok(0, "call not expected\n");
1008 static const ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl =
1010 isaxlexical_QueryInterface,
1012 isaxlexical_Release,
1013 isaxlexical_startDTD,
1015 isaxlexical_startEntity,
1016 isaxlexical_endEntity,
1017 isaxlexical_startCDATA,
1018 isaxlexical_endCDATA,
1022 static ISAXLexicalHandler saxlexicalhandler = { &SAXLexicalHandlerVtbl };
1024 static HRESULT WINAPI isaxdecl_QueryInterface(ISAXDeclHandler* iface, REFIID riid, void **ppvObject)
1028 if(IsEqualGUID(riid, &IID_IUnknown) ||
1029 IsEqualGUID(riid, &IID_ISAXDeclHandler))
1035 return E_NOINTERFACE;
1041 static ULONG WINAPI isaxdecl_AddRef(ISAXDeclHandler* iface)
1043 handler_addrefcalled++;
1047 static ULONG WINAPI isaxdecl_Release(ISAXDeclHandler* iface)
1052 static HRESULT WINAPI isaxdecl_elementDecl(ISAXDeclHandler* iface,
1053 const WCHAR * pName, int nName, const WCHAR * pModel, int nModel)
1055 ok(0, "call not expected\n");
1059 static HRESULT WINAPI isaxdecl_attributeDecl(ISAXDeclHandler* iface,
1060 const WCHAR * pElementName, int nElementName, const WCHAR * pAttributeName,
1061 int nAttributeName, const WCHAR * pType, int nType, const WCHAR * pValueDefault,
1062 int nValueDefault, const WCHAR * pValue, int nValue)
1064 ok(0, "call not expected\n");
1068 static HRESULT WINAPI isaxdecl_internalEntityDecl(ISAXDeclHandler* iface,
1069 const WCHAR * pName, int nName, const WCHAR * pValue, int nValue)
1071 ok(0, "call not expected\n");
1075 static HRESULT WINAPI isaxdecl_externalEntityDecl(ISAXDeclHandler* iface,
1076 const WCHAR * pName, int nName, const WCHAR * pPublicId, int nPublicId,
1077 const WCHAR * pSystemId, int nSystemId)
1079 ok(0, "call not expected\n");
1083 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl =
1085 isaxdecl_QueryInterface,
1088 isaxdecl_elementDecl,
1089 isaxdecl_attributeDecl,
1090 isaxdecl_internalEntityDecl,
1091 isaxdecl_externalEntityDecl
1094 static ISAXDeclHandler saxdeclhandler = { &SAXDeclHandlerVtbl };
1096 typedef struct mxwriter_write_test_t {
1102 } mxwriter_write_test;
1104 typedef struct mxwriter_stream_test_t {
1106 const char *encoding;
1107 mxwriter_write_test expected_writes[4];
1108 } mxwriter_stream_test;
1110 static const mxwriter_write_test *current_write_test;
1111 static DWORD current_stream_test_index;
1113 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
1117 if(IsEqualGUID(riid, &IID_IStream) || IsEqualGUID(riid, &IID_IUnknown))
1120 return E_NOINTERFACE;
1125 static ULONG WINAPI istream_AddRef(IStream *iface)
1130 static ULONG WINAPI istream_Release(IStream *iface)
1135 static HRESULT WINAPI istream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
1137 ok(0, "unexpected call\n");
1141 static HRESULT WINAPI istream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
1145 ok(pv != NULL, "pv == NULL\n");
1147 if(current_write_test->last) {
1148 ok(0, "Too many Write calls made on test %d\n", current_stream_test_index);
1152 fail = current_write_test->fail_write;
1154 ok(current_write_test->cb == cb, "Expected %d, but got %d on test %d\n",
1155 current_write_test->cb, cb, current_stream_test_index);
1158 ok(current_write_test->null_written, "pcbWritten was NULL on test %d\n", current_stream_test_index);
1160 ok(!memcmp(current_write_test->data, pv, cb), "Unexpected data on test %d\n", current_stream_test_index);
1162 ++current_write_test;
1167 return fail ? E_FAIL : S_OK;
1170 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
1171 ULARGE_INTEGER *plibNewPosition)
1173 ok(0, "unexpected call\n");
1177 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
1179 ok(0, "unexpected call\n");
1183 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
1184 ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *plibWritten)
1186 ok(0, "unexpected call\n");
1190 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD grfCommitFlags)
1192 ok(0, "unexpected call\n");
1196 static HRESULT WINAPI istream_Revert(IStream *iface)
1198 ok(0, "unexpected call\n");
1202 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1203 ULARGE_INTEGER cb, DWORD dwLockType)
1205 ok(0, "unexpected call\n");
1209 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1210 ULARGE_INTEGER cb, DWORD dwLockType)
1212 ok(0, "unexpected call\n");
1216 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
1218 ok(0, "unexpected call\n");
1222 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **ppstm)
1224 ok(0, "unexpected call\n");
1228 static const IStreamVtbl StreamVtbl = {
1229 istream_QueryInterface,
1240 istream_UnlockRegion,
1245 static IStream mxstream = { &StreamVtbl };
1247 static void test_saxreader(int version)
1250 ISAXXMLReader *reader = NULL;
1252 ISAXContentHandler *lpContentHandler;
1253 ISAXErrorHandler *lpErrorHandler;
1255 SAFEARRAYBOUND SADim[1];
1256 char *pSAData = NULL;
1258 ULARGE_INTEGER liSize;
1259 LARGE_INTEGER liPos;
1262 static const CHAR testXmlA[] = "test.xml";
1263 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1264 IXMLDOMDocument *domDocument;
1268 msxml_version = version;
1270 hr = CoCreateInstance(&CLSID_SAXXMLReader30, NULL, CLSCTX_INPROC_SERVER,
1271 &IID_ISAXXMLReader, (LPVOID*)&reader);
1272 } else if(version == 6) {
1273 hr = CoCreateInstance(&CLSID_SAXXMLReader60, NULL, CLSCTX_INPROC_SERVER,
1274 &IID_ISAXXMLReader, (LPVOID*)&reader);
1275 if(hr == REGDB_E_CLASSNOTREG) {
1276 win_skip("SAXXMLReader6 not registered\n");
1280 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1281 &IID_ISAXXMLReader, (LPVOID*)&reader);
1283 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1286 hr = ISAXXMLReader_getContentHandler(reader, NULL);
1287 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1289 hr = ISAXXMLReader_getErrorHandler(reader, NULL);
1290 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1293 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1294 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1295 ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
1297 hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
1298 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1299 ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
1301 hr = ISAXXMLReader_putContentHandler(reader, NULL);
1302 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1304 hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
1305 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1307 hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
1308 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1310 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1311 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1312 ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
1314 V_VT(&var) = VT_BSTR;
1315 V_BSTR(&var) = SysAllocString(szSimpleXML);
1317 expectCall = contentHandlerTest1;
1318 hr = ISAXXMLReader_parse(reader, var);
1319 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1320 test_expect_call(CH_ENDTEST);
1324 SADim[0].lLbound= 0;
1325 SADim[0].cElements= sizeof(szTestXML)-1;
1326 pSA = SafeArrayCreate(VT_UI1, 1, SADim);
1327 SafeArrayAccessData(pSA, (void**)&pSAData);
1328 memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
1329 SafeArrayUnaccessData(pSA);
1330 V_VT(&var) = VT_ARRAY|VT_UI1;
1331 V_ARRAY(&var) = pSA;
1333 expectCall = contentHandlerTest1;
1334 hr = ISAXXMLReader_parse(reader, var);
1335 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1336 test_expect_call(CH_ENDTEST);
1338 SafeArrayDestroy(pSA);
1340 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1341 liSize.QuadPart = strlen(szTestXML);
1342 IStream_SetSize(iStream, liSize);
1343 IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
1345 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1346 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1347 V_UNKNOWN(&var) = (IUnknown*)iStream;
1349 expectCall = contentHandlerTest1;
1350 hr = ISAXXMLReader_parse(reader, var);
1351 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1352 test_expect_call(CH_ENDTEST);
1354 IStream_Release(iStream);
1356 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1357 liSize.QuadPart = strlen(szTestAttributes);
1358 IStream_SetSize(iStream, liSize);
1359 IStream_Write(iStream, szTestAttributes, strlen(szTestAttributes), &bytesWritten);
1361 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1362 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1363 V_UNKNOWN(&var) = (IUnknown*)iStream;
1366 expectCall = contentHandlerTestAttributes6;
1368 expectCall = contentHandlerTestAttributes;
1369 hr = ISAXXMLReader_parse(reader, var);
1370 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1371 test_expect_call(CH_ENDTEST);
1373 IStream_Release(iStream);
1375 V_VT(&var) = VT_BSTR;
1376 V_BSTR(&var) = SysAllocString(szCarriageRetTest);
1378 expectCall = contentHandlerTest2;
1379 hr = ISAXXMLReader_parse(reader, var);
1380 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1381 test_expect_call(CH_ENDTEST);
1385 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1386 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1387 WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
1390 expectCall = contentHandlerTest1;
1391 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1392 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1393 test_expect_call(CH_ENDTEST);
1395 expectCall = contentHandlerTestError;
1396 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1397 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1398 test_expect_call(CH_ENDTEST);
1401 expectCall = contentHandlerTestCallbackResult6;
1403 expectCall = contentHandlerTestCallbackResults;
1404 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1405 ok(hr == (version>=6 ? S_OK : S_FALSE), "Expected S_FALSE, got %08x\n", hr);
1406 test_expect_call(CH_ENDTEST);
1408 DeleteFileA(testXmlA);
1410 hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
1411 &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
1414 skip("Failed to create DOMDocument instance\n");
1417 bstrData = SysAllocString(szSimpleXML);
1418 hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
1419 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1420 V_VT(&var) = VT_UNKNOWN;
1421 V_UNKNOWN(&var) = (IUnknown*)domDocument;
1423 expectCall = contentHandlerTest2;
1424 hr = ISAXXMLReader_parse(reader, var);
1425 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1426 test_expect_call(CH_ENDTEST);
1427 IXMLDOMDocument_Release(domDocument);
1429 ISAXXMLReader_Release(reader);
1430 SysFreeString(bstrData);
1433 struct saxreader_props_test_t
1435 const char *prop_name;
1439 static const struct saxreader_props_test_t props_test_data[] = {
1440 { "http://xml.org/sax/properties/lexical-handler", (IUnknown*)&saxlexicalhandler },
1441 { "http://xml.org/sax/properties/declaration-handler", (IUnknown*)&saxdeclhandler },
1445 static void test_saxreader_properties(void)
1447 const struct saxreader_props_test_t *ptr = props_test_data;
1448 ISAXXMLReader *reader;
1451 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1452 &IID_ISAXXMLReader, (void**)&reader);
1453 EXPECT_HR(hr, S_OK);
1455 hr = ISAXXMLReader_getProperty(reader, _bstr_("http://xml.org/sax/properties/lexical-handler"), NULL);
1456 EXPECT_HR(hr, E_POINTER);
1458 while (ptr->prop_name)
1462 V_VT(&v) = VT_EMPTY;
1463 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1464 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1465 EXPECT_HR(hr, S_OK);
1466 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1467 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1469 V_VT(&v) = VT_UNKNOWN;
1470 V_UNKNOWN(&v) = ptr->iface;
1471 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1472 EXPECT_HR(hr, S_OK);
1474 V_VT(&v) = VT_EMPTY;
1475 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1476 handler_addrefcalled = 0;
1477 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1478 EXPECT_HR(hr, S_OK);
1479 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1480 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1481 ok(handler_addrefcalled == 1, "AddRef called %d times\n", handler_addrefcalled);
1484 V_VT(&v) = VT_EMPTY;
1485 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1486 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1487 EXPECT_HR(hr, S_OK);
1489 V_VT(&v) = VT_EMPTY;
1490 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1491 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1492 EXPECT_HR(hr, S_OK);
1493 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1494 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1496 V_VT(&v) = VT_UNKNOWN;
1497 V_UNKNOWN(&v) = ptr->iface;
1498 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1499 EXPECT_HR(hr, S_OK);
1501 /* only VT_EMPTY seems to be valid to reset property */
1503 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1504 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1505 EXPECT_HR(hr, E_INVALIDARG);
1507 V_VT(&v) = VT_EMPTY;
1508 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1509 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1510 EXPECT_HR(hr, S_OK);
1511 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1512 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1515 V_VT(&v) = VT_UNKNOWN;
1516 V_UNKNOWN(&v) = NULL;
1517 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1518 EXPECT_HR(hr, S_OK);
1520 V_VT(&v) = VT_EMPTY;
1521 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1522 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1523 EXPECT_HR(hr, S_OK);
1524 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1525 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1530 ISAXXMLReader_Release(reader);
1534 struct feature_ns_entry_t {
1540 static const struct feature_ns_entry_t feature_ns_entry_data[] = {
1541 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", VARIANT_TRUE },
1542 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", VARIANT_TRUE },
1543 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", VARIANT_TRUE },
1544 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", VARIANT_TRUE },
1548 static void test_saxreader_features(void)
1550 const struct feature_ns_entry_t *entry = feature_ns_entry_data;
1551 ISAXXMLReader *reader;
1558 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1561 win_skip("can't create %s instance\n", entry->clsid);
1567 hr = ISAXXMLReader_getFeature(reader, _bstr_("http://xml.org/sax/features/namespaces"), &value);
1568 EXPECT_HR(hr, S_OK);
1570 ok(entry->value == value, "%s: got wrong default value %x, expected %x\n", entry->clsid, value, entry->value);
1572 ISAXXMLReader_Release(reader);
1578 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1579 static const CHAR UTF8BOMTest[] =
1580 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1583 struct enc_test_entry_t {
1591 static const struct enc_test_entry_t encoding_test_data[] = {
1592 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
1593 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
1594 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
1595 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
1599 static void test_encoding(void)
1601 const struct enc_test_entry_t *entry = encoding_test_data;
1602 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1603 static const CHAR testXmlA[] = "test.xml";
1604 ISAXXMLReader *reader;
1611 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1614 win_skip("can't create %s instance\n", entry->clsid);
1619 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1620 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1621 WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
1624 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1626 todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1628 ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1630 DeleteFileA(testXmlA);
1631 ISAXXMLReader_Release(reader);
1637 static void test_mxwriter_handlers(void)
1639 ISAXContentHandler *handler;
1640 IMXWriter *writer, *writer2;
1641 ISAXLexicalHandler *lh;
1644 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1645 &IID_IMXWriter, (void**)&writer);
1646 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1648 EXPECT_REF(writer, 1);
1650 /* ISAXContentHandler */
1651 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
1652 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1653 EXPECT_REF(writer, 2);
1654 EXPECT_REF(handler, 2);
1656 hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
1657 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1658 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1659 EXPECT_REF(writer, 3);
1660 EXPECT_REF(writer2, 3);
1661 IMXWriter_Release(writer2);
1662 ISAXContentHandler_Release(handler);
1664 /* ISAXLexicalHandler */
1665 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lh);
1666 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1667 EXPECT_REF(writer, 2);
1670 hr = ISAXLexicalHandler_QueryInterface(lh, &IID_IMXWriter, (void**)&writer2);
1671 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1672 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1673 EXPECT_REF(writer, 3);
1674 EXPECT_REF(writer2, 3);
1675 IMXWriter_Release(writer2);
1677 IMXWriter_Release(writer);
1680 struct msxmlsupported_data_t
1687 static struct msxmlsupported_data_t mxwriter_support_data[] =
1689 { &CLSID_MXXMLWriter, "MXXMLWriter" },
1690 { &CLSID_MXXMLWriter30, "MXXMLWriter30" },
1691 { &CLSID_MXXMLWriter40, "MXXMLWriter40" },
1692 { &CLSID_MXXMLWriter60, "MXXMLWriter60" },
1696 static struct msxmlsupported_data_t mxattributes_support_data[] =
1698 { &CLSID_SAXAttributes, "SAXAttributes" },
1699 { &CLSID_SAXAttributes30, "SAXAttributes30" },
1700 { &CLSID_SAXAttributes40, "SAXAttributes40" },
1701 { &CLSID_SAXAttributes60, "SAXAttributes60" },
1705 static BOOL is_clsid_supported(const GUID *clsid, const struct msxmlsupported_data_t *table)
1707 while (table->clsid)
1709 if (table->clsid == clsid) return table->supported;
1715 struct mxwriter_props_t
1719 VARIANT_BOOL disable_escape;
1720 VARIANT_BOOL indent;
1721 VARIANT_BOOL omitdecl;
1722 VARIANT_BOOL standalone;
1723 const char *encoding;
1726 static const struct mxwriter_props_t mxwriter_default_props[] =
1728 { &CLSID_MXXMLWriter, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1729 { &CLSID_MXXMLWriter30, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1730 { &CLSID_MXXMLWriter40, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1731 { &CLSID_MXXMLWriter60, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1735 static void test_mxwriter_default_properties(const struct mxwriter_props_t *table)
1739 while (table->clsid)
1746 if (!is_clsid_supported(table->clsid, mxwriter_support_data))
1753 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1754 &IID_IMXWriter, (void**)&writer);
1755 EXPECT_HR(hr, S_OK);
1758 hr = IMXWriter_get_byteOrderMark(writer, &b);
1759 EXPECT_HR(hr, S_OK);
1760 ok(table->bom == b, "test %d: got BOM %d, expected %d\n", i, b, table->bom);
1762 b = !table->disable_escape;
1763 hr = IMXWriter_get_disableOutputEscaping(writer, &b);
1764 EXPECT_HR(hr, S_OK);
1765 ok(table->disable_escape == b, "test %d: got disable escape %d, expected %d\n", i, b,
1766 table->disable_escape);
1769 hr = IMXWriter_get_indent(writer, &b);
1770 EXPECT_HR(hr, S_OK);
1771 ok(table->indent == b, "test %d: got indent %d, expected %d\n", i, b, table->indent);
1773 b = !table->omitdecl;
1774 hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
1775 EXPECT_HR(hr, S_OK);
1776 ok(table->omitdecl == b, "test %d: got omitdecl %d, expected %d\n", i, b, table->omitdecl);
1778 b = !table->standalone;
1779 hr = IMXWriter_get_standalone(writer, &b);
1780 EXPECT_HR(hr, S_OK);
1781 ok(table->standalone == b, "test %d: got standalone %d, expected %d\n", i, b, table->standalone);
1783 hr = IMXWriter_get_encoding(writer, &encoding);
1784 EXPECT_HR(hr, S_OK);
1785 ok(!lstrcmpW(encoding, _bstr_(table->encoding)), "test %d: got encoding %s, expected %s\n",
1786 i, wine_dbgstr_w(encoding), table->encoding);
1787 SysFreeString(encoding);
1789 IMXWriter_Release(writer);
1796 static void test_mxwriter_properties(void)
1798 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
1799 static const WCHAR emptyW[] = {0};
1800 static const WCHAR testW[] = {'t','e','s','t',0};
1801 ISAXContentHandler *content;
1808 test_mxwriter_default_properties(mxwriter_default_props);
1810 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1811 &IID_IMXWriter, (void**)&writer);
1812 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1814 hr = IMXWriter_get_disableOutputEscaping(writer, NULL);
1815 ok(hr == E_POINTER, "got %08x\n", hr);
1817 hr = IMXWriter_get_byteOrderMark(writer, NULL);
1818 ok(hr == E_POINTER, "got %08x\n", hr);
1820 hr = IMXWriter_get_indent(writer, NULL);
1821 ok(hr == E_POINTER, "got %08x\n", hr);
1823 hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
1824 ok(hr == E_POINTER, "got %08x\n", hr);
1826 hr = IMXWriter_get_standalone(writer, NULL);
1827 ok(hr == E_POINTER, "got %08x\n", hr);
1830 hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
1831 ok(hr == S_OK, "got %08x\n", hr);
1834 hr = IMXWriter_get_standalone(writer, &b);
1835 ok(hr == S_OK, "got %08x\n", hr);
1836 ok(b == VARIANT_TRUE, "got %d\n", b);
1838 hr = IMXWriter_get_encoding(writer, NULL);
1839 EXPECT_HR(hr, E_POINTER);
1841 /* UTF-16 is a default setting apparently */
1842 str = (void*)0xdeadbeef;
1843 hr = IMXWriter_get_encoding(writer, &str);
1844 EXPECT_HR(hr, S_OK);
1845 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1847 str2 = (void*)0xdeadbeef;
1848 hr = IMXWriter_get_encoding(writer, &str2);
1849 ok(hr == S_OK, "got %08x\n", hr);
1850 ok(str != str2, "expected newly allocated, got same %p\n", str);
1852 SysFreeString(str2);
1855 /* put empty string */
1856 str = SysAllocString(emptyW);
1857 hr = IMXWriter_put_encoding(writer, str);
1858 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1861 str = (void*)0xdeadbeef;
1862 hr = IMXWriter_get_encoding(writer, &str);
1863 EXPECT_HR(hr, S_OK);
1864 ok(!lstrcmpW(str, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(str));
1867 /* invalid encoding name */
1868 str = SysAllocString(testW);
1869 hr = IMXWriter_put_encoding(writer, str);
1870 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1873 /* test case sensivity */
1874 hr = IMXWriter_put_encoding(writer, _bstr_("utf-8"));
1875 EXPECT_HR(hr, S_OK);
1876 str = (void*)0xdeadbeef;
1877 hr = IMXWriter_get_encoding(writer, &str);
1878 EXPECT_HR(hr, S_OK);
1879 ok(!lstrcmpW(str, _bstr_("utf-8")), "got %s\n", wine_dbgstr_w(str));
1882 hr = IMXWriter_put_encoding(writer, _bstr_("uTf-16"));
1883 EXPECT_HR(hr, S_OK);
1884 str = (void*)0xdeadbeef;
1885 hr = IMXWriter_get_encoding(writer, &str);
1886 EXPECT_HR(hr, S_OK);
1887 ok(!lstrcmpW(str, _bstr_("uTf-16")), "got %s\n", wine_dbgstr_w(str));
1890 /* how it affects document creation */
1891 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1892 EXPECT_HR(hr, S_OK);
1894 hr = ISAXContentHandler_startDocument(content);
1895 EXPECT_HR(hr, S_OK);
1896 hr = ISAXContentHandler_endDocument(content);
1897 EXPECT_HR(hr, S_OK);
1899 V_VT(&dest) = VT_EMPTY;
1900 hr = IMXWriter_get_output(writer, &dest);
1901 EXPECT_HR(hr, S_OK);
1902 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1903 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\"?>\r\n"),
1904 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1905 VariantClear(&dest);
1906 ISAXContentHandler_Release(content);
1908 hr = IMXWriter_get_version(writer, NULL);
1909 ok(hr == E_POINTER, "got %08x\n", hr);
1910 /* default version is 'surprisingly' 1.0 */
1911 hr = IMXWriter_get_version(writer, &str);
1912 ok(hr == S_OK, "got %08x\n", hr);
1913 ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1916 /* store version string as is */
1917 hr = IMXWriter_put_version(writer, NULL);
1918 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1920 hr = IMXWriter_put_version(writer, _bstr_("1.0"));
1921 ok(hr == S_OK, "got %08x\n", hr);
1923 hr = IMXWriter_put_version(writer, _bstr_(""));
1924 ok(hr == S_OK, "got %08x\n", hr);
1925 hr = IMXWriter_get_version(writer, &str);
1926 ok(hr == S_OK, "got %08x\n", hr);
1927 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
1930 hr = IMXWriter_put_version(writer, _bstr_("a.b"));
1931 ok(hr == S_OK, "got %08x\n", hr);
1932 hr = IMXWriter_get_version(writer, &str);
1933 ok(hr == S_OK, "got %08x\n", hr);
1934 ok(!lstrcmpW(str, _bstr_("a.b")), "got %s\n", wine_dbgstr_w(str));
1937 hr = IMXWriter_put_version(writer, _bstr_("2.0"));
1938 ok(hr == S_OK, "got %08x\n", hr);
1939 hr = IMXWriter_get_version(writer, &str);
1940 ok(hr == S_OK, "got %08x\n", hr);
1941 ok(!lstrcmpW(str, _bstr_("2.0")), "got %s\n", wine_dbgstr_w(str));
1944 IMXWriter_Release(writer);
1948 static void test_mxwriter_flush(void)
1950 ISAXContentHandler *content;
1953 ULARGE_INTEGER pos2;
1958 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1959 &IID_IMXWriter, (void**)&writer);
1960 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1962 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1963 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1964 EXPECT_REF(stream, 1);
1966 /* detach when nothing was attached */
1967 V_VT(&dest) = VT_EMPTY;
1968 hr = IMXWriter_put_output(writer, dest);
1969 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1972 V_VT(&dest) = VT_UNKNOWN;
1973 V_UNKNOWN(&dest) = (IUnknown*)stream;
1974 hr = IMXWriter_put_output(writer, dest);
1975 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1976 todo_wine EXPECT_REF(stream, 3);
1978 /* detach setting VT_EMPTY destination */
1979 V_VT(&dest) = VT_EMPTY;
1980 hr = IMXWriter_put_output(writer, dest);
1981 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1982 EXPECT_REF(stream, 1);
1984 V_VT(&dest) = VT_UNKNOWN;
1985 V_UNKNOWN(&dest) = (IUnknown*)stream;
1986 hr = IMXWriter_put_output(writer, dest);
1987 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1989 /* flush() doesn't detach a stream */
1990 hr = IMXWriter_flush(writer);
1991 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1992 todo_wine EXPECT_REF(stream, 3);
1995 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
1996 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1997 ok(pos2.QuadPart == 0, "expected stream beginning\n");
1999 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2000 ok(hr == S_OK, "got %08x\n", hr);
2002 hr = ISAXContentHandler_startDocument(content);
2003 ok(hr == S_OK, "got %08x\n", hr);
2006 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2007 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2008 ok(pos2.QuadPart != 0, "expected stream beginning\n");
2010 /* already started */
2011 hr = ISAXContentHandler_startDocument(content);
2012 ok(hr == S_OK, "got %08x\n", hr);
2014 hr = ISAXContentHandler_endDocument(content);
2015 ok(hr == S_OK, "got %08x\n", hr);
2017 /* flushed on endDocument() */
2019 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2020 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2021 ok(pos2.QuadPart != 0, "expected stream position moved\n");
2023 ISAXContentHandler_Release(content);
2024 IStream_Release(stream);
2025 IMXWriter_Release(writer);
2028 static void test_mxwriter_startenddocument(void)
2030 ISAXContentHandler *content;
2035 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2036 &IID_IMXWriter, (void**)&writer);
2037 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2039 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2040 ok(hr == S_OK, "got %08x\n", hr);
2042 hr = ISAXContentHandler_startDocument(content);
2043 ok(hr == S_OK, "got %08x\n", hr);
2045 hr = ISAXContentHandler_endDocument(content);
2046 ok(hr == S_OK, "got %08x\n", hr);
2048 V_VT(&dest) = VT_EMPTY;
2049 hr = IMXWriter_get_output(writer, &dest);
2050 ok(hr == S_OK, "got %08x\n", hr);
2051 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2052 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2053 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2054 VariantClear(&dest);
2056 /* now try another startDocument */
2057 hr = ISAXContentHandler_startDocument(content);
2058 ok(hr == S_OK, "got %08x\n", hr);
2059 /* and get duplicated prolog */
2060 V_VT(&dest) = VT_EMPTY;
2061 hr = IMXWriter_get_output(writer, &dest);
2062 ok(hr == S_OK, "got %08x\n", hr);
2063 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2064 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
2065 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2066 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2067 VariantClear(&dest);
2069 ISAXContentHandler_Release(content);
2070 IMXWriter_Release(writer);
2072 /* now with omitted declaration */
2073 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2074 &IID_IMXWriter, (void**)&writer);
2075 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2077 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2078 ok(hr == S_OK, "got %08x\n", hr);
2080 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2081 ok(hr == S_OK, "got %08x\n", hr);
2083 hr = ISAXContentHandler_startDocument(content);
2084 ok(hr == S_OK, "got %08x\n", hr);
2086 hr = ISAXContentHandler_endDocument(content);
2087 ok(hr == S_OK, "got %08x\n", hr);
2089 V_VT(&dest) = VT_EMPTY;
2090 hr = IMXWriter_get_output(writer, &dest);
2091 ok(hr == S_OK, "got %08x\n", hr);
2092 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2093 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2094 VariantClear(&dest);
2096 ISAXContentHandler_Release(content);
2097 IMXWriter_Release(writer);
2109 struct writer_startendelement_t {
2111 enum startendtype type;
2113 const char *local_name;
2117 ISAXAttributes *attr;
2120 static const char startelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"<&">\">";
2121 static const char startendelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"<&">\"/>";
2123 static const struct writer_startendelement_t writer_startendelement[] = {
2125 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2126 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2127 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2128 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, NULL, "<>", S_OK },
2129 { &CLSID_MXXMLWriter, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2131 { &CLSID_MXXMLWriter30, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2132 { &CLSID_MXXMLWriter40, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2133 { &CLSID_MXXMLWriter60, StartElement, "uri", NULL, NULL, "<>", S_OK },
2134 { &CLSID_MXXMLWriter, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2135 { &CLSID_MXXMLWriter30, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2137 { &CLSID_MXXMLWriter40, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2138 { &CLSID_MXXMLWriter60, StartElement, NULL, "local", NULL, "<>", S_OK },
2139 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2140 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2141 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2143 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, "qname", "<qname>", S_OK },
2144 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2145 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2146 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2147 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2149 { &CLSID_MXXMLWriter, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2150 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2151 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2152 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", NULL, "<>", S_OK },
2153 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2155 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2156 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2157 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2158 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2159 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2161 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2162 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2163 /* endElement tests */
2164 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2165 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2166 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2168 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, NULL, "</>", S_OK },
2169 { &CLSID_MXXMLWriter, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2170 { &CLSID_MXXMLWriter30, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2171 { &CLSID_MXXMLWriter40, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2172 { &CLSID_MXXMLWriter60, EndElement, "uri", NULL, NULL, "</>", S_OK },
2174 { &CLSID_MXXMLWriter, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2175 { &CLSID_MXXMLWriter30, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2176 { &CLSID_MXXMLWriter40, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2177 { &CLSID_MXXMLWriter60, EndElement, NULL, "local", NULL, "</>", S_OK },
2178 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2180 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2181 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2182 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, "qname", "</qname>", S_OK },
2183 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2184 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2186 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2187 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2188 { &CLSID_MXXMLWriter, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2189 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2190 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2192 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", NULL, "</>", S_OK },
2193 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2194 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2195 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2196 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2198 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2199 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2200 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2201 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2203 /* with attributes */
2204 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2206 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2207 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2208 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2209 /* empty elements */
2210 { &CLSID_MXXMLWriter, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2211 { &CLSID_MXXMLWriter30, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2213 { &CLSID_MXXMLWriter40, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2214 { &CLSID_MXXMLWriter60, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2215 { &CLSID_MXXMLWriter, StartEndElement, "", "", "", "</>", S_OK },
2216 { &CLSID_MXXMLWriter30, StartEndElement, "", "", "", "</>", S_OK },
2217 { &CLSID_MXXMLWriter40, StartEndElement, "", "", "", "</>", S_OK },
2219 { &CLSID_MXXMLWriter60, StartEndElement, "", "", "", "</>", S_OK },
2223 static void get_mxwriter_support_data(struct msxmlsupported_data_t *table)
2225 while (table->clsid)
2230 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2231 &IID_IMXWriter, (void**)&writer);
2232 if (hr == S_OK) IMXWriter_Release(writer);
2234 table->supported = hr == S_OK;
2235 if (hr != S_OK) win_skip("class %s not supported\n", table->name);
2241 static void get_mxattributes_support_data(struct msxmlsupported_data_t *table)
2243 while (table->clsid)
2245 IMXAttributes *attr;
2248 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2249 &IID_IMXAttributes, (void**)&attr);
2250 if (hr == S_OK) IMXAttributes_Release(attr);
2252 table->supported = hr == S_OK;
2253 if (hr != S_OK) skip("class %s not supported\n", table->name);
2259 static void test_mxwriter_startendelement_batch(const struct writer_startendelement_t *table)
2263 while (table->clsid)
2265 ISAXContentHandler *content;
2269 if (!is_clsid_supported(table->clsid, mxwriter_support_data))
2276 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2277 &IID_IMXWriter, (void**)&writer);
2278 EXPECT_HR(hr, S_OK);
2280 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2281 EXPECT_HR(hr, S_OK);
2283 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2284 EXPECT_HR(hr, S_OK);
2286 hr = ISAXContentHandler_startDocument(content);
2287 EXPECT_HR(hr, S_OK);
2289 if (table->type == StartElement)
2291 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2292 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2293 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2295 else if (table->type == EndElement)
2297 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2298 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2299 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2303 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2304 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2305 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2306 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2307 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2308 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2316 V_VT(&dest) = VT_EMPTY;
2317 hr = IMXWriter_get_output(writer, &dest);
2318 EXPECT_HR(hr, S_OK);
2319 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2320 ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
2321 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
2322 VariantClear(&dest);
2325 ISAXContentHandler_Release(content);
2326 IMXWriter_Release(writer);
2335 static void test_mxwriter_startendelement(void)
2337 ISAXContentHandler *content;
2342 test_mxwriter_startendelement_batch(writer_startendelement);
2344 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2345 &IID_IMXWriter, (void**)&writer);
2346 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2348 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2349 ok(hr == S_OK, "got %08x\n", hr);
2351 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2352 ok(hr == S_OK, "got %08x\n", hr);
2354 hr = ISAXContentHandler_startDocument(content);
2355 ok(hr == S_OK, "got %08x\n", hr);
2357 /* all string pointers should be not null */
2358 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
2359 ok(hr == S_OK, "got %08x\n", hr);
2361 V_VT(&dest) = VT_EMPTY;
2362 hr = IMXWriter_get_output(writer, &dest);
2363 ok(hr == S_OK, "got %08x\n", hr);
2364 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2365 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2366 VariantClear(&dest);
2368 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
2369 ok(hr == S_OK, "got %08x\n", hr);
2371 V_VT(&dest) = VT_EMPTY;
2372 hr = IMXWriter_get_output(writer, &dest);
2373 ok(hr == S_OK, "got %08x\n", hr);
2374 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2375 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2376 VariantClear(&dest);
2378 hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
2379 EXPECT_HR(hr, E_INVALIDARG);
2381 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
2382 EXPECT_HR(hr, E_INVALIDARG);
2384 /* only local name is an error too */
2385 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
2386 EXPECT_HR(hr, E_INVALIDARG);
2388 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
2389 EXPECT_HR(hr, S_OK);
2391 V_VT(&dest) = VT_EMPTY;
2392 hr = IMXWriter_get_output(writer, &dest);
2393 EXPECT_HR(hr, S_OK);
2394 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2395 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2396 VariantClear(&dest);
2398 hr = ISAXContentHandler_endDocument(content);
2399 EXPECT_HR(hr, S_OK);
2401 V_VT(&dest) = VT_EMPTY;
2402 hr = IMXWriter_put_output(writer, dest);
2403 EXPECT_HR(hr, S_OK);
2405 V_VT(&dest) = VT_EMPTY;
2406 hr = IMXWriter_get_output(writer, &dest);
2407 EXPECT_HR(hr, S_OK);
2408 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2409 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2410 VariantClear(&dest);
2412 hr = ISAXContentHandler_startDocument(content);
2413 EXPECT_HR(hr, S_OK);
2415 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abcdef"), 3, NULL);
2416 EXPECT_HR(hr, S_OK);
2418 V_VT(&dest) = VT_EMPTY;
2419 hr = IMXWriter_get_output(writer, &dest);
2420 EXPECT_HR(hr, S_OK);
2421 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2422 ok(!lstrcmpW(_bstr_("<abc>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2423 VariantClear(&dest);
2425 ISAXContentHandler_endDocument(content);
2426 IMXWriter_flush(writer);
2428 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abdcdef"), 3);
2429 EXPECT_HR(hr, S_OK);
2430 V_VT(&dest) = VT_EMPTY;
2431 hr = IMXWriter_get_output(writer, &dest);
2432 EXPECT_HR(hr, S_OK);
2433 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2434 ok(!lstrcmpW(_bstr_("<abc></abd>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2435 VariantClear(&dest);
2437 ISAXContentHandler_Release(content);
2438 IMXWriter_Release(writer);
2442 struct writer_characters_t {
2448 static const struct writer_characters_t writer_characters[] = {
2449 { &CLSID_MXXMLWriter, "< > & \"", "< > & \"" },
2450 { &CLSID_MXXMLWriter30, "< > & \"", "< > & \"" },
2451 { &CLSID_MXXMLWriter40, "< > & \"", "< > & \"" },
2452 { &CLSID_MXXMLWriter60, "< > & \"", "< > & \"" },
2456 static void test_mxwriter_characters(void)
2458 static const WCHAR chardataW[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
2459 const struct writer_characters_t *table = writer_characters;
2460 ISAXContentHandler *content;
2466 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2467 &IID_IMXWriter, (void**)&writer);
2468 EXPECT_HR(hr, S_OK);
2470 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2471 EXPECT_HR(hr, S_OK);
2473 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2474 EXPECT_HR(hr, S_OK);
2476 hr = ISAXContentHandler_startDocument(content);
2477 EXPECT_HR(hr, S_OK);
2479 hr = ISAXContentHandler_characters(content, NULL, 0);
2480 EXPECT_HR(hr, E_INVALIDARG);
2482 hr = ISAXContentHandler_characters(content, chardataW, 0);
2483 EXPECT_HR(hr, S_OK);
2485 hr = ISAXContentHandler_characters(content, chardataW, sizeof(chardataW)/sizeof(WCHAR) - 1);
2486 EXPECT_HR(hr, S_OK);
2488 V_VT(&dest) = VT_EMPTY;
2489 hr = IMXWriter_get_output(writer, &dest);
2490 EXPECT_HR(hr, S_OK);
2491 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2492 ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2493 VariantClear(&dest);
2495 hr = ISAXContentHandler_endDocument(content);
2496 EXPECT_HR(hr, S_OK);
2498 ISAXContentHandler_Release(content);
2499 IMXWriter_Release(writer);
2501 /* try empty characters data to see if element is closed */
2502 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2503 &IID_IMXWriter, (void**)&writer);
2504 EXPECT_HR(hr, S_OK);
2506 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2507 EXPECT_HR(hr, S_OK);
2509 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2510 EXPECT_HR(hr, S_OK);
2512 hr = ISAXContentHandler_startDocument(content);
2513 EXPECT_HR(hr, S_OK);
2515 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2516 EXPECT_HR(hr, S_OK);
2518 hr = ISAXContentHandler_characters(content, chardataW, 0);
2519 EXPECT_HR(hr, S_OK);
2521 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2522 EXPECT_HR(hr, S_OK);
2524 V_VT(&dest) = VT_EMPTY;
2525 hr = IMXWriter_get_output(writer, &dest);
2526 EXPECT_HR(hr, S_OK);
2527 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2528 ok(!lstrcmpW(_bstr_("<a></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2529 VariantClear(&dest);
2531 ISAXContentHandler_Release(content);
2532 IMXWriter_Release(writer);
2535 while (table->clsid)
2537 ISAXContentHandler *content;
2541 if (!is_clsid_supported(table->clsid, mxwriter_support_data))
2548 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2549 &IID_IMXWriter, (void**)&writer);
2550 EXPECT_HR(hr, S_OK);
2552 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2553 EXPECT_HR(hr, S_OK);
2555 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2556 EXPECT_HR(hr, S_OK);
2558 hr = ISAXContentHandler_startDocument(content);
2559 EXPECT_HR(hr, S_OK);
2561 hr = ISAXContentHandler_characters(content, _bstr_(table->data), strlen(table->data));
2562 EXPECT_HR(hr, S_OK);
2569 V_VT(&dest) = VT_EMPTY;
2570 hr = IMXWriter_get_output(writer, &dest);
2571 EXPECT_HR(hr, S_OK);
2572 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2573 ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
2574 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
2575 VariantClear(&dest);
2585 static const mxwriter_stream_test mxwriter_stream_tests[] = {
2587 VARIANT_TRUE,"UTF-16",
2589 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2590 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2595 VARIANT_FALSE,"UTF-16",
2597 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2602 VARIANT_TRUE,"UTF-8",
2604 {FALSE,(const BYTE*)szUtf8XML,sizeof(szUtf8XML)-1},
2605 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2606 * and the writer is released.
2613 VARIANT_TRUE,"utf-8",
2615 {FALSE,(const BYTE*)utf8xml2,sizeof(utf8xml2)-1},
2616 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2617 * and the writer is released.
2624 VARIANT_TRUE,"UTF-16",
2626 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2627 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2632 VARIANT_TRUE,"UTF-16",
2634 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE,TRUE},
2635 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2641 static void test_mxwriter_stream(void)
2644 ISAXContentHandler *content;
2649 ULARGE_INTEGER pos2;
2650 DWORD test_count = sizeof(mxwriter_stream_tests)/sizeof(mxwriter_stream_tests[0]);
2652 for(current_stream_test_index = 0; current_stream_test_index < test_count; ++current_stream_test_index) {
2653 const mxwriter_stream_test *test = mxwriter_stream_tests+current_stream_test_index;
2655 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2656 &IID_IMXWriter, (void**)&writer);
2657 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2659 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2660 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2662 hr = IMXWriter_put_encoding(writer, _bstr_(test->encoding));
2663 ok(hr == S_OK, "put_encoding failed with %08x on test %d\n", hr, current_stream_test_index);
2665 V_VT(&dest) = VT_UNKNOWN;
2666 V_UNKNOWN(&dest) = (IUnknown*)&mxstream;
2667 hr = IMXWriter_put_output(writer, dest);
2668 ok(hr == S_OK, "put_output failed with %08x on test %d\n", hr, current_stream_test_index);
2669 VariantClear(&dest);
2671 hr = IMXWriter_put_byteOrderMark(writer, test->bom);
2672 ok(hr == S_OK, "put_byteOrderMark failed with %08x on test %d\n", hr, current_stream_test_index);
2674 current_write_test = test->expected_writes;
2676 hr = ISAXContentHandler_startDocument(content);
2677 ok(hr == S_OK, "startDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2679 hr = ISAXContentHandler_endDocument(content);
2680 ok(hr == S_OK, "endDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2682 ISAXContentHandler_Release(content);
2683 IMXWriter_Release(writer);
2685 ok(current_write_test->last, "The last %d write calls on test %d were missed\n",
2686 (int)(current_write_test-test->expected_writes), current_stream_test_index);
2689 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2690 &IID_IMXWriter, (void**)&writer);
2691 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2693 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2694 ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
2696 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2697 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2699 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2700 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
2702 V_VT(&dest) = VT_UNKNOWN;
2703 V_UNKNOWN(&dest) = (IUnknown*)stream;
2704 hr = IMXWriter_put_output(writer, dest);
2705 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2707 hr = ISAXContentHandler_startDocument(content);
2708 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2710 /* Setting output of the mxwriter causes the current output to be flushed,
2711 * and the writer to start over.
2713 V_VT(&dest) = VT_EMPTY;
2714 hr = IMXWriter_put_output(writer, dest);
2715 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2718 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2719 ok(hr == S_OK, "Seek failed: %08x\n", hr);
2720 ok(pos2.QuadPart != 0, "expected stream position moved\n");
2722 hr = ISAXContentHandler_startDocument(content);
2723 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2725 hr = ISAXContentHandler_endDocument(content);
2726 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
2728 V_VT(&dest) = VT_EMPTY;
2729 hr = IMXWriter_get_output(writer, &dest);
2730 ok(hr == S_OK, "get_output failed: %08x\n", hr);
2731 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2732 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2733 "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2734 VariantClear(&dest);
2736 /* test when BOM is written to output stream */
2737 V_VT(&dest) = VT_EMPTY;
2738 hr = IMXWriter_put_output(writer, dest);
2739 EXPECT_HR(hr, S_OK);
2742 hr = IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
2743 EXPECT_HR(hr, S_OK);
2745 V_VT(&dest) = VT_UNKNOWN;
2746 V_UNKNOWN(&dest) = (IUnknown*)stream;
2747 hr = IMXWriter_put_output(writer, dest);
2748 EXPECT_HR(hr, S_OK);
2750 hr = IMXWriter_put_byteOrderMark(writer, VARIANT_TRUE);
2751 EXPECT_HR(hr, S_OK);
2753 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2754 EXPECT_HR(hr, S_OK);
2756 hr = ISAXContentHandler_startDocument(content);
2757 EXPECT_HR(hr, S_OK);
2761 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2762 EXPECT_HR(hr, S_OK);
2763 ok(pos2.QuadPart == 2, "got wrong position\n");
2765 ISAXContentHandler_Release(content);
2766 IMXWriter_Release(writer);
2771 static void test_mxwriter_encoding(void)
2773 ISAXContentHandler *content;
2782 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2783 &IID_IMXWriter, (void**)&writer);
2784 EXPECT_HR(hr, S_OK);
2786 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2787 EXPECT_HR(hr, S_OK);
2789 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2790 EXPECT_HR(hr, S_OK);
2792 hr = ISAXContentHandler_startDocument(content);
2793 EXPECT_HR(hr, S_OK);
2795 hr = ISAXContentHandler_endDocument(content);
2796 EXPECT_HR(hr, S_OK);
2798 /* The content is always re-encoded to UTF-16 when the output is
2799 * retrieved as a BSTR.
2801 V_VT(&dest) = VT_EMPTY;
2802 hr = IMXWriter_get_output(writer, &dest);
2803 EXPECT_HR(hr, S_OK);
2804 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2805 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2806 "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2807 VariantClear(&dest);
2809 /* switch encoding when something is written already */
2810 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2811 EXPECT_HR(hr, S_OK);
2813 V_VT(&dest) = VT_UNKNOWN;
2814 V_UNKNOWN(&dest) = (IUnknown*)stream;
2815 hr = IMXWriter_put_output(writer, dest);
2816 EXPECT_HR(hr, S_OK);
2818 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2819 EXPECT_HR(hr, S_OK);
2821 /* write empty element */
2822 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2823 EXPECT_HR(hr, S_OK);
2825 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2826 EXPECT_HR(hr, S_OK);
2829 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2830 EXPECT_HR(hr, S_OK);
2832 hr = IMXWriter_flush(writer);
2833 EXPECT_HR(hr, S_OK);
2835 hr = GetHGlobalFromStream(stream, &g);
2836 EXPECT_HR(hr, S_OK);
2838 ptr = GlobalLock(g);
2839 ok(!strncmp(ptr, "<a/>", 4), "got %c%c%c%c\n", ptr[0],ptr[1],ptr[2],ptr[3]);
2842 /* so output is unaffected, encoding name is stored however */
2843 hr = IMXWriter_get_encoding(writer, &s);
2844 EXPECT_HR(hr, S_OK);
2845 ok(!lstrcmpW(s, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(s));
2848 IStream_Release(stream);
2850 ISAXContentHandler_Release(content);
2851 IMXWriter_Release(writer);
2856 static void test_obj_dispex(IUnknown *obj)
2858 static const WCHAR starW[] = {'*',0};
2859 DISPID dispid = DISPID_SAX_XMLREADER_GETFEATURE;
2860 IDispatchEx *dispex;
2867 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
2868 EXPECT_HR(hr, S_OK);
2869 if (FAILED(hr)) return;
2872 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
2873 EXPECT_HR(hr, S_OK);
2874 ok(ticnt == 1, "ticnt=%u\n", ticnt);
2876 name = SysAllocString(starW);
2877 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
2878 EXPECT_HR(hr, E_NOTIMPL);
2879 SysFreeString(name);
2881 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
2882 EXPECT_HR(hr, E_NOTIMPL);
2885 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
2886 EXPECT_HR(hr, E_NOTIMPL);
2887 ok(props == 0, "expected 0 got %d\n", props);
2889 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
2890 EXPECT_HR(hr, E_NOTIMPL);
2891 if (SUCCEEDED(hr)) SysFreeString(name);
2893 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_SAX_XMLREADER_GETFEATURE, &dispid);
2894 EXPECT_HR(hr, E_NOTIMPL);
2896 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
2897 EXPECT_HR(hr, E_NOTIMPL);
2898 if (hr == S_OK && unk) IUnknown_Release(unk);
2900 IDispatchEx_Release(dispex);
2903 static void test_dispex(void)
2905 IVBSAXXMLReader *vbreader;
2906 ISAXXMLReader *reader;
2910 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
2911 &IID_ISAXXMLReader, (void**)&reader);
2912 EXPECT_HR(hr, S_OK);
2914 hr = ISAXXMLReader_QueryInterface(reader, &IID_IUnknown, (void**)&unk);
2915 EXPECT_HR(hr, S_OK);
2916 test_obj_dispex(unk);
2917 IUnknown_Release(unk);
2919 hr = ISAXXMLReader_QueryInterface(reader, &IID_IVBSAXXMLReader, (void**)&vbreader);
2920 EXPECT_HR(hr, S_OK);
2921 hr = IVBSAXXMLReader_QueryInterface(vbreader, &IID_IUnknown, (void**)&unk);
2922 EXPECT_HR(hr, S_OK);
2923 test_obj_dispex(unk);
2924 IUnknown_Release(unk);
2925 IVBSAXXMLReader_Release(vbreader);
2927 ISAXXMLReader_Release(reader);
2930 static void test_mxwriter_dispex(void)
2932 IDispatchEx *dispex;
2937 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2938 &IID_IMXWriter, (void**)&writer);
2939 EXPECT_HR(hr, S_OK);
2941 hr = IMXWriter_QueryInterface(writer, &IID_IDispatchEx, (void**)&dispex);
2942 EXPECT_HR(hr, S_OK);
2943 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
2944 test_obj_dispex(unk);
2945 IUnknown_Release(unk);
2946 IDispatchEx_Release(dispex);
2948 IMXWriter_Release(writer);
2951 static void test_mxwriter_comment(void)
2953 static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
2954 ISAXContentHandler *content;
2955 ISAXLexicalHandler *lexical;
2960 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2961 &IID_IMXWriter, (void**)&writer);
2962 EXPECT_HR(hr, S_OK);
2964 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2965 EXPECT_HR(hr, S_OK);
2967 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
2968 EXPECT_HR(hr, S_OK);
2970 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2971 EXPECT_HR(hr, S_OK);
2973 hr = ISAXContentHandler_startDocument(content);
2974 EXPECT_HR(hr, S_OK);
2976 hr = ISAXLexicalHandler_comment(lexical, NULL, 0);
2977 EXPECT_HR(hr, E_INVALIDARG);
2979 hr = ISAXLexicalHandler_comment(lexical, commentW, 0);
2980 EXPECT_HR(hr, S_OK);
2982 V_VT(&dest) = VT_EMPTY;
2983 hr = IMXWriter_get_output(writer, &dest);
2984 EXPECT_HR(hr, S_OK);
2985 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2986 ok(!lstrcmpW(_bstr_("<!---->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2987 VariantClear(&dest);
2989 hr = ISAXLexicalHandler_comment(lexical, commentW, sizeof(commentW)/sizeof(WCHAR)-1);
2990 EXPECT_HR(hr, S_OK);
2992 V_VT(&dest) = VT_EMPTY;
2993 hr = IMXWriter_get_output(writer, &dest);
2994 EXPECT_HR(hr, S_OK);
2995 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2996 ok(!lstrcmpW(_bstr_("<!---->\r\n<!--comment-->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2997 VariantClear(&dest);
2999 ISAXContentHandler_Release(content);
3000 ISAXLexicalHandler_Release(lexical);
3001 IMXWriter_Release(writer);
3005 static void test_mxwriter_cdata(void)
3007 ISAXContentHandler *content;
3008 ISAXLexicalHandler *lexical;
3013 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
3014 &IID_IMXWriter, (void**)&writer);
3015 EXPECT_HR(hr, S_OK);
3017 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
3018 EXPECT_HR(hr, S_OK);
3020 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
3021 EXPECT_HR(hr, S_OK);
3023 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
3024 EXPECT_HR(hr, S_OK);
3026 hr = ISAXContentHandler_startDocument(content);
3027 EXPECT_HR(hr, S_OK);
3029 hr = ISAXLexicalHandler_startCDATA(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_("<![CDATA["), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3037 VariantClear(&dest);
3039 hr = ISAXLexicalHandler_startCDATA(lexical);
3040 EXPECT_HR(hr, S_OK);
3042 /* all these are escaped for text nodes */
3043 hr = ISAXContentHandler_characters(content, _bstr_("< > & \""), 7);
3044 EXPECT_HR(hr, S_OK);
3046 hr = ISAXLexicalHandler_endCDATA(lexical);
3047 EXPECT_HR(hr, S_OK);
3049 V_VT(&dest) = VT_EMPTY;
3050 hr = IMXWriter_get_output(writer, &dest);
3051 EXPECT_HR(hr, S_OK);
3052 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3053 ok(!lstrcmpW(_bstr_("<![CDATA[<![CDATA[< > & \"]]>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3054 VariantClear(&dest);
3056 ISAXContentHandler_Release(content);
3057 ISAXLexicalHandler_Release(lexical);
3058 IMXWriter_Release(writer);
3062 static void test_mxwriter_dtd(void)
3064 static const WCHAR nameW[] = {'n','a','m','e'};
3065 static const WCHAR pubW[] = {'p','u','b'};
3066 static const WCHAR sysW[] = {'s','y','s'};
3067 ISAXContentHandler *content;
3068 ISAXLexicalHandler *lexical;
3073 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
3074 &IID_IMXWriter, (void**)&writer);
3075 EXPECT_HR(hr, S_OK);
3077 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
3078 EXPECT_HR(hr, S_OK);
3080 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
3081 EXPECT_HR(hr, S_OK);
3083 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
3084 EXPECT_HR(hr, S_OK);
3086 hr = ISAXContentHandler_startDocument(content);
3087 EXPECT_HR(hr, S_OK);
3089 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, NULL, 0);
3090 EXPECT_HR(hr, E_INVALIDARG);
3092 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
3093 EXPECT_HR(hr, E_INVALIDARG);
3095 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, sysW, sizeof(sysW)/sizeof(WCHAR));
3096 EXPECT_HR(hr, E_INVALIDARG);
3098 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
3099 EXPECT_HR(hr, E_INVALIDARG);
3101 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), NULL, 0, NULL, 0);
3102 EXPECT_HR(hr, S_OK);
3104 V_VT(&dest) = VT_EMPTY;
3105 hr = IMXWriter_get_output(writer, &dest);
3106 EXPECT_HR(hr, S_OK);
3107 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3108 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3109 VariantClear(&dest);
3111 /* system id is required if public is present */
3112 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
3113 EXPECT_HR(hr, E_INVALIDARG);
3115 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR),
3116 pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
3117 EXPECT_HR(hr, S_OK);
3119 V_VT(&dest) = VT_EMPTY;
3120 hr = IMXWriter_get_output(writer, &dest);
3121 EXPECT_HR(hr, S_OK);
3122 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3123 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3124 "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3125 VariantClear(&dest);
3127 hr = ISAXLexicalHandler_endDTD(lexical);
3128 EXPECT_HR(hr, S_OK);
3130 hr = ISAXLexicalHandler_endDTD(lexical);
3131 EXPECT_HR(hr, S_OK);
3133 V_VT(&dest) = VT_EMPTY;
3134 hr = IMXWriter_get_output(writer, &dest);
3135 EXPECT_HR(hr, S_OK);
3136 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3137 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3138 "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n]>\r\n]>\r\n"),
3139 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3140 VariantClear(&dest);
3142 ISAXContentHandler_Release(content);
3143 ISAXLexicalHandler_Release(lexical);
3144 IMXWriter_Release(writer);
3156 } addattribute_test_t;
3158 static const addattribute_test_t addattribute_data[] = {
3159 { &CLSID_SAXAttributes, NULL, NULL, "ns:qname", NULL, "value", E_INVALIDARG },
3160 { &CLSID_SAXAttributes30, NULL, NULL, "ns:qname", NULL, "value", E_INVALIDARG },
3161 { &CLSID_SAXAttributes40, NULL, NULL, "ns:qname", NULL, "value", E_INVALIDARG },
3162 { &CLSID_SAXAttributes60, NULL, NULL, "ns:qname", NULL, "value", S_OK },
3164 { &CLSID_SAXAttributes, NULL, "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3165 { &CLSID_SAXAttributes30, NULL, "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3166 { &CLSID_SAXAttributes40, NULL, "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3167 { &CLSID_SAXAttributes60, NULL, "qname", "ns:qname", NULL, "value", S_OK },
3169 { &CLSID_SAXAttributes, "uri", "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3170 { &CLSID_SAXAttributes30, "uri", "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3171 { &CLSID_SAXAttributes40, "uri", "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3172 { &CLSID_SAXAttributes60, "uri", "qname", "ns:qname", NULL, "value", S_OK },
3174 { &CLSID_SAXAttributes, "uri", "qname", "ns:qname", "type", "value", S_OK },
3175 { &CLSID_SAXAttributes30, "uri", "qname", "ns:qname", "type", "value", S_OK },
3176 { &CLSID_SAXAttributes40, "uri", "qname", "ns:qname", "type", "value", S_OK },
3177 { &CLSID_SAXAttributes60, "uri", "qname", "ns:qname", "type", "value", S_OK },
3182 static void test_mxattr_addAttribute(void)
3184 const addattribute_test_t *table = addattribute_data;
3187 while (table->clsid)
3189 ISAXAttributes *saxattr;
3190 IMXAttributes *mxattr;
3194 if (!is_clsid_supported(table->clsid, mxattributes_support_data))
3201 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
3202 &IID_IMXAttributes, (void**)&mxattr);
3203 EXPECT_HR(hr, S_OK);
3205 hr = IMXAttributes_QueryInterface(mxattr, &IID_ISAXAttributes, (void**)&saxattr);
3206 EXPECT_HR(hr, S_OK);
3208 /* SAXAttributes30 and SAXAttributes60 both crash on this test */
3209 if (IsEqualGUID(table->clsid, &CLSID_SAXAttributes) ||
3210 IsEqualGUID(table->clsid, &CLSID_SAXAttributes30))
3212 hr = ISAXAttributes_getLength(saxattr, NULL);
3213 EXPECT_HR(hr, E_POINTER);
3217 hr = ISAXAttributes_getLength(saxattr, &len);
3218 EXPECT_HR(hr, S_OK);
3219 ok(len == 0, "got %d\n", len);
3221 hr = IMXAttributes_addAttribute(mxattr, _bstr_(table->uri), _bstr_(table->local),
3222 _bstr_(table->qname), _bstr_(table->type), _bstr_(table->value));
3223 ok(hr == table->hr, "%d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
3226 hr = ISAXAttributes_getLength(saxattr, &len);
3227 EXPECT_HR(hr, S_OK);
3228 if (table->hr == S_OK)
3229 ok(len == 1, "%d: got %d length, expected 0\n", i, len);
3231 ok(len == 0, "%d: got %d length, expected 1\n", i, len);
3233 ISAXAttributes_Release(saxattr);
3234 IMXAttributes_Release(mxattr);
3243 static void test_mxattr_clear(void)
3245 ISAXAttributes *saxattr;
3246 IMXAttributes *mxattr;
3251 hr = CoCreateInstance(&CLSID_SAXAttributes, NULL, CLSCTX_INPROC_SERVER,
3252 &IID_IMXAttributes, (void**)&mxattr);
3253 EXPECT_HR(hr, S_OK);
3255 hr = IMXAttributes_QueryInterface(mxattr, &IID_ISAXAttributes, (void**)&saxattr);
3256 EXPECT_HR(hr, S_OK);
3258 hr = ISAXAttributes_getQName(saxattr, 0, NULL, NULL);
3259 EXPECT_HR(hr, E_INVALIDARG);
3261 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, &len);
3262 EXPECT_HR(hr, E_INVALIDARG);
3264 hr = IMXAttributes_addAttribute(mxattr, _bstr_("uri"), _bstr_("local"),
3265 _bstr_("qname"), _bstr_("type"), _bstr_("value"));
3266 EXPECT_HR(hr, S_OK);
3269 hr = ISAXAttributes_getLength(saxattr, &len);
3270 EXPECT_HR(hr, S_OK);
3271 ok(len == 1, "got %d\n", len);
3274 hr = ISAXAttributes_getQName(saxattr, 0, NULL, &len);
3275 EXPECT_HR(hr, E_POINTER);
3276 ok(len == -1, "got %d\n", len);
3278 ptr = (void*)0xdeadbeef;
3279 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, NULL);
3280 EXPECT_HR(hr, E_POINTER);
3281 ok(ptr == (void*)0xdeadbeef, "got %p\n", ptr);
3284 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, &len);
3285 EXPECT_HR(hr, S_OK);
3286 ok(len == 5, "got %d\n", len);
3287 ok(!lstrcmpW(ptr, _bstr_("qname")), "got %s\n", wine_dbgstr_w(ptr));
3289 hr = IMXAttributes_clear(mxattr);
3290 EXPECT_HR(hr, S_OK);
3293 hr = ISAXAttributes_getLength(saxattr, &len);
3294 EXPECT_HR(hr, S_OK);
3295 ok(len == 0, "got %d\n", len);
3298 ptr = (void*)0xdeadbeef;
3299 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, &len);
3300 EXPECT_HR(hr, E_INVALIDARG);
3301 ok(len == -1, "got %d\n", len);
3302 ok(ptr == (void*)0xdeadbeef, "got %p\n", ptr);
3304 IMXAttributes_Release(mxattr);
3305 ISAXAttributes_Release(saxattr);
3309 START_TEST(saxreader)
3311 ISAXXMLReader *reader;
3314 hr = CoInitialize(NULL);
3315 ok(hr == S_OK, "failed to init com\n");
3317 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
3318 &IID_ISAXXMLReader, (void**)&reader);
3322 skip("Failed to create SAXXMLReader instance\n");
3326 ISAXXMLReader_Release(reader);
3331 test_saxreader_properties();
3332 test_saxreader_features();
3336 /* MXXMLWriter tests */
3337 get_mxwriter_support_data(mxwriter_support_data);
3338 if (is_clsid_supported(&CLSID_MXXMLWriter, mxwriter_support_data))
3340 test_mxwriter_handlers();
3341 test_mxwriter_startenddocument();
3342 test_mxwriter_startendelement();
3343 test_mxwriter_characters();
3344 test_mxwriter_comment();
3345 test_mxwriter_cdata();
3346 test_mxwriter_dtd();
3347 test_mxwriter_properties();
3348 test_mxwriter_flush();
3349 test_mxwriter_stream();
3350 test_mxwriter_encoding();
3351 test_mxwriter_dispex();
3354 win_skip("MXXMLWriter not supported\n");
3356 /* SAXAttributes tests */
3357 get_mxattributes_support_data(mxattributes_support_data);
3358 if (is_clsid_supported(&CLSID_SAXAttributes, mxattributes_support_data))
3360 test_mxattr_addAttribute();
3361 test_mxattr_clear();
3364 skip("SAXAttributes not supported\n");