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 xmlspaceattr_test[] = {
253 { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
254 { CH_STARTDOCUMENT, 0, 0, 1, 39 },
255 { CH_STARTELEMENT, 1, 64, 1, 63, "", "a", "a" },
256 { CH_CHARACTERS, 1, 64, 1, 80, " Some text data " },
257 { CH_ENDELEMENT, 1, 82, 1, 83, "", "a", "a" },
258 { CH_ENDDOCUMENT, 0, 0, 1, 83 },
262 static const char xmlspace_attr[] =
263 "<?xml version=\"1.0\" encoding=\"UTF-16\"?>"
264 "<a xml:space=\"preserve\"> Some text data </a>";
266 static content_handler_test *expectCall;
267 static ISAXLocator *locator;
270 static void test_saxstr(unsigned line, const WCHAR *szStr, int nStr, const char *szTest)
276 ok_(__FILE__,line) (szStr == NULL, "szStr != NULL\n");
277 ok_(__FILE__,line) (nStr == 0, "nStr = %d, expected 0\n", nStr);
281 len = strlen(szTest);
282 ok_(__FILE__,line) (len == nStr, "nStr = %d, expected %d (%s)\n", nStr, len, szTest);
284 ok_(__FILE__,line)(0, "got string %s, expected %s\n", wine_dbgstr_wn(szStr, nStr), szTest);
288 MultiByteToWideChar(CP_ACP, 0, szTest, -1, buf, sizeof(buf)/sizeof(WCHAR));
289 ok_(__FILE__,line) (!memcmp(szStr, buf, len*sizeof(WCHAR)), "unexpected szStr %s, expected %s\n",
290 wine_dbgstr_wn(szStr, nStr), szTest);
293 static BOOL test_expect_call(CH id)
295 ok(expectCall->id == id, "unexpected call %d, expected %d\n", id, expectCall->id);
296 return expectCall->id == id;
299 static void test_locator(unsigned line, int loc_line, int loc_column)
302 ISAXLocator_getLineNumber(locator, &rline);
303 ISAXLocator_getColumnNumber(locator, &rcolumn);
305 ok_(__FILE__,line) (rline == loc_line,
306 "unexpected line %d, expected %d\n", rline, loc_line);
307 ok_(__FILE__,line) (rcolumn == loc_column,
308 "unexpected column %d, expected %d\n", rcolumn, loc_column);
311 static HRESULT WINAPI contentHandler_QueryInterface(
312 ISAXContentHandler* iface,
318 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXContentHandler))
324 return E_NOINTERFACE;
330 static ULONG WINAPI contentHandler_AddRef(
331 ISAXContentHandler* iface)
336 static ULONG WINAPI contentHandler_Release(
337 ISAXContentHandler* iface)
342 static HRESULT WINAPI contentHandler_putDocumentLocator(
343 ISAXContentHandler* iface,
344 ISAXLocator *pLocator)
348 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR))
352 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
353 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
355 if(msxml_version >= 6) {
356 ISAXAttributes *attr, *attr1;
357 IMXAttributes *mxattr;
359 EXPECT_REF(pLocator, 1);
360 hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr);
362 EXPECT_REF(pLocator, 2);
363 hr = ISAXLocator_QueryInterface(pLocator, &IID_ISAXAttributes, (void**)&attr1);
365 EXPECT_REF(pLocator, 3);
366 ok(attr == attr1, "got %p, %p\n", attr, attr1);
368 hr = ISAXAttributes_QueryInterface(attr, &IID_IMXAttributes, (void**)&mxattr);
369 EXPECT_HR(hr, E_NOINTERFACE);
371 ISAXAttributes_Release(attr);
372 ISAXAttributes_Release(attr1);
375 return (expectCall++)->ret;
378 static ISAXAttributes *test_attr_ptr;
379 static HRESULT WINAPI contentHandler_startDocument(
380 ISAXContentHandler* iface)
382 if(!test_expect_call(CH_STARTDOCUMENT))
385 test_attr_ptr = NULL;
386 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
387 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
389 return (expectCall++)->ret;
392 static HRESULT WINAPI contentHandler_endDocument(
393 ISAXContentHandler* iface)
395 if(!test_expect_call(CH_ENDDOCUMENT))
398 if(expectCall == xmlspaceattr_test+5 && msxml_version>=6) {
400 test_locator(__LINE__, expectCall->line_v6, expectCall->column_v6);
403 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
404 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
406 return (expectCall++)->ret;
409 static HRESULT WINAPI contentHandler_startPrefixMapping(
410 ISAXContentHandler* iface,
411 const WCHAR *pPrefix,
416 if(!test_expect_call(CH_STARTPREFIXMAPPING))
419 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
420 test_saxstr(__LINE__, pUri, nUri, expectCall->arg2);
421 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
422 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
424 return (expectCall++)->ret;
427 static HRESULT WINAPI contentHandler_endPrefixMapping(
428 ISAXContentHandler* iface,
429 const WCHAR *pPrefix,
432 if(!test_expect_call(CH_ENDPREFIXMAPPING))
435 test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
436 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
437 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
439 return (expectCall++)->ret;
442 static HRESULT WINAPI contentHandler_startElement(
443 ISAXContentHandler* iface,
444 const WCHAR *pNamespaceUri,
446 const WCHAR *pLocalName,
450 ISAXAttributes *pAttr)
452 IMXAttributes *mxattr;
456 hres = ISAXAttributes_QueryInterface(pAttr, &IID_IMXAttributes, (void**)&mxattr);
457 EXPECT_HR(hres, E_NOINTERFACE);
459 if(!test_expect_call(CH_STARTELEMENT))
462 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
463 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
464 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
465 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
466 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
469 test_attr_ptr = pAttr;
470 ok(test_attr_ptr == pAttr, "Multiple ISAXAttributes instances are used (%p %p)\n", test_attr_ptr, pAttr);
472 if(expectCall == contentHandlerTestAttributes+4) {
473 const WCHAR *uri_ptr = NULL;
475 /* msxml3 returns attributes and namespaces in the input order */
476 hres = ISAXAttributes_getLength(pAttr, &len);
477 ok(hres == S_OK, "getLength returned %x\n", hres);
478 ok(len == 5, "Incorrect number of attributes: %d\n", len);
479 ok(msxml_version < 6, "wrong msxml_version: %d\n", msxml_version);
481 for(i=0; i<len; i++) {
482 hres = ISAXAttributes_getName(pAttr, i, &pNamespaceUri, &nNamespaceUri,
483 &pLocalName, &nLocalName, &pQName, &nQName);
484 ok(hres == S_OK, "getName returned %x\n", hres);
487 todo_wine ok(i==3, "Incorrect attributes order\n");
488 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
489 test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
490 test_saxstr(__LINE__, pQName, nQName, "arg2");
491 } else if(nQName == 5) {
492 todo_wine ok(i==1, "Incorrect attributes order\n");
493 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
494 test_saxstr(__LINE__, pLocalName, nLocalName, "");
495 test_saxstr(__LINE__, pQName, nQName, "xmlns");
496 } else if(nQName == 8) {
497 todo_wine ok(i==4, "Incorrect attributes order\n");
498 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
499 test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
500 test_saxstr(__LINE__, pQName, nQName, "test:ar3");
501 ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
502 } else if(nQName == 9) {
503 todo_wine ok(i==2, "Incorrect attributes order\n");
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;
508 } else if(nQName == 10) {
509 todo_wine ok(i==0, "Incorrect attributes order\n");
510 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
511 test_saxstr(__LINE__, pLocalName, nLocalName, "");
512 test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
514 ok(0, "Unexpected attribute\n");
517 } else if(expectCall == contentHandlerTestAttributes6+4) {
518 const WCHAR *uri_ptr;
520 /* msxml6 returns attributes first and then namespaces */
521 hres = ISAXAttributes_getLength(pAttr, &len);
522 ok(hres == S_OK, "getLength returned %x\n", hres);
523 ok(len == 5, "Incorrect number of attributes: %d\n", len);
524 ok(msxml_version >= 6, "wrong msxml_version: %d\n", msxml_version);
526 hres = ISAXAttributes_getName(pAttr, 0, &pNamespaceUri, &nNamespaceUri,
527 &pLocalName, &nLocalName, &pQName, &nQName);
528 ok(hres == S_OK, "getName returned %x\n", hres);
529 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
530 test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
531 test_saxstr(__LINE__, pQName, nQName, "test:arg1");
532 uri_ptr = pNamespaceUri;
534 hres = ISAXAttributes_getName(pAttr, 1, &pNamespaceUri, &nNamespaceUri,
535 &pLocalName, &nLocalName, &pQName, &nQName);
536 ok(hres == S_OK, "getName returned %x\n", hres);
537 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
538 test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
539 test_saxstr(__LINE__, pQName, nQName, "arg2");
541 hres = ISAXAttributes_getName(pAttr, 2, &pNamespaceUri, &nNamespaceUri,
542 &pLocalName, &nLocalName, &pQName, &nQName);
543 ok(hres == S_OK, "getName returned %x\n", hres);
544 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
545 test_saxstr(__LINE__, pLocalName, nLocalName, "ar3");
546 test_saxstr(__LINE__, pQName, nQName, "test:ar3");
547 ok(uri_ptr == pNamespaceUri, "Incorrect NamespaceUri pointer\n");
549 hres = ISAXAttributes_getName(pAttr, 3, &pNamespaceUri, &nNamespaceUri,
550 &pLocalName, &nLocalName, &pQName, &nQName);
551 ok(hres == S_OK, "getName returned %x\n", hres);
552 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
553 test_saxstr(__LINE__, pLocalName, nLocalName, "");
554 test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
556 hres = ISAXAttributes_getName(pAttr, 4, &pNamespaceUri, &nNamespaceUri,
557 &pLocalName, &nLocalName, &pQName, &nQName);
558 ok(hres == S_OK, "getName returned %x\n", hres);
559 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
560 test_saxstr(__LINE__, pLocalName, nLocalName, "");
561 test_saxstr(__LINE__, pQName, nQName, "xmlns");
562 } else if(expectCall == xmlspaceattr_test+2) {
566 hres = ISAXAttributes_getLength(pAttr, &len);
567 EXPECT_HR(hres, S_OK);
568 ok(len == 1, "Incorrect number of attributes: %d\n", len);
570 hres = ISAXAttributes_getName(pAttr, 0, &pNamespaceUri, &nNamespaceUri,
571 &pLocalName, &nLocalName, &pQName, &nQName);
572 EXPECT_HR(hres, S_OK);
573 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/XML/1998/namespace");
574 test_saxstr(__LINE__, pLocalName, nLocalName, "space");
575 test_saxstr(__LINE__, pQName, nQName, "xml:space");
577 hres = ISAXAttributes_getValue(pAttr, 0, &value, &valuelen);
578 EXPECT_HR(hres, S_OK);
579 test_saxstr(__LINE__, value, valuelen, "preserve");
582 return (expectCall++)->ret;
585 static HRESULT WINAPI contentHandler_endElement(
586 ISAXContentHandler* iface,
587 const WCHAR *pNamespaceUri,
589 const WCHAR *pLocalName,
594 if(!test_expect_call(CH_ENDELEMENT))
597 test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, expectCall->arg1);
598 test_saxstr(__LINE__, pLocalName, nLocalName, expectCall->arg2);
599 test_saxstr(__LINE__, pQName, nQName, expectCall->arg3);
600 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
601 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
603 return (expectCall++)->ret;
606 static HRESULT WINAPI contentHandler_characters(
607 ISAXContentHandler* iface,
611 if(!test_expect_call(CH_CHARACTERS))
614 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
615 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
616 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
618 return (expectCall++)->ret;
621 static HRESULT WINAPI contentHandler_ignorableWhitespace(
622 ISAXContentHandler* iface,
626 if(!test_expect_call(CH_IGNORABLEWHITESPACE))
629 test_saxstr(__LINE__, pChars, nChars, expectCall->arg1);
630 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
631 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
633 return (expectCall++)->ret;
636 static HRESULT WINAPI contentHandler_processingInstruction(
637 ISAXContentHandler* iface,
638 const WCHAR *pTarget,
643 if(!test_expect_call(CH_PROCESSINGINSTRUCTION))
646 test_saxstr(__LINE__, pTarget, nTarget, expectCall->arg1);
647 test_saxstr(__LINE__, pData, nData, expectCall->arg2);
648 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
649 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
651 return (expectCall++)->ret;
654 static HRESULT WINAPI contentHandler_skippedEntity(
655 ISAXContentHandler* iface,
659 if(!test_expect_call(CH_SKIPPEDENTITY))
662 test_saxstr(__LINE__, pName, nName, expectCall->arg1);
663 test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
664 msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
666 return (expectCall++)->ret;
670 static const ISAXContentHandlerVtbl contentHandlerVtbl =
672 contentHandler_QueryInterface,
673 contentHandler_AddRef,
674 contentHandler_Release,
675 contentHandler_putDocumentLocator,
676 contentHandler_startDocument,
677 contentHandler_endDocument,
678 contentHandler_startPrefixMapping,
679 contentHandler_endPrefixMapping,
680 contentHandler_startElement,
681 contentHandler_endElement,
682 contentHandler_characters,
683 contentHandler_ignorableWhitespace,
684 contentHandler_processingInstruction,
685 contentHandler_skippedEntity
688 static ISAXContentHandler contentHandler = { &contentHandlerVtbl };
690 static HRESULT WINAPI isaxerrorHandler_QueryInterface(
691 ISAXErrorHandler* iface,
697 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXErrorHandler))
703 return E_NOINTERFACE;
709 static ULONG WINAPI isaxerrorHandler_AddRef(
710 ISAXErrorHandler* iface)
715 static ULONG WINAPI isaxerrorHandler_Release(
716 ISAXErrorHandler* iface)
721 static HRESULT WINAPI isaxerrorHandler_error(
722 ISAXErrorHandler* iface,
723 ISAXLocator *pLocator,
724 const WCHAR *pErrorMessage,
727 ok(0, "unexpected call\n");
731 static HRESULT WINAPI isaxerrorHandler_fatalError(
732 ISAXErrorHandler* iface,
733 ISAXLocator *pLocator,
734 const WCHAR *pErrorMessage,
737 if(!test_expect_call(EH_FATALERROR))
740 ok(hrErrorCode == expectCall->ret, "hrErrorCode = %x, expected %x\n", hrErrorCode, expectCall->ret);
746 static HRESULT WINAPI isaxerrorHanddler_ignorableWarning(
747 ISAXErrorHandler* iface,
748 ISAXLocator *pLocator,
749 const WCHAR *pErrorMessage,
752 ok(0, "unexpected call\n");
756 static const ISAXErrorHandlerVtbl errorHandlerVtbl =
758 isaxerrorHandler_QueryInterface,
759 isaxerrorHandler_AddRef,
760 isaxerrorHandler_Release,
761 isaxerrorHandler_error,
762 isaxerrorHandler_fatalError,
763 isaxerrorHanddler_ignorableWarning
766 static ISAXErrorHandler errorHandler = { &errorHandlerVtbl };
768 static HRESULT WINAPI isaxattributes_QueryInterface(
769 ISAXAttributes* iface,
775 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISAXAttributes))
781 return E_NOINTERFACE;
787 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface)
792 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
797 static HRESULT WINAPI isaxattributes_getLength(ISAXAttributes* iface, int *length)
803 static HRESULT WINAPI isaxattributes_getURI(
804 ISAXAttributes* iface,
809 ok(0, "unexpected call\n");
813 static HRESULT WINAPI isaxattributes_getLocalName(
814 ISAXAttributes* iface,
816 const WCHAR **pLocalName,
817 int *pLocalNameLength)
819 ok(0, "unexpected call\n");
823 static HRESULT WINAPI isaxattributes_getQName(
824 ISAXAttributes* iface,
829 static const WCHAR attrqnamesW[][15] = {{'a',':','a','t','t','r','1','j','u','n','k',0},
830 {'a','t','t','r','2','j','u','n','k',0},
831 {'a','t','t','r','3',0}};
832 static const int attrqnamelen[] = {7, 5, 5};
834 ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
836 *QName = attrqnamesW[index];
837 *QNameLength = attrqnamelen[index];
842 static HRESULT WINAPI isaxattributes_getName(
843 ISAXAttributes* iface,
847 const WCHAR ** pLocalName,
848 int * pLocalNameSize,
849 const WCHAR ** pQName,
852 ok(0, "unexpected call\n");
856 static HRESULT WINAPI isaxattributes_getIndexFromName(
857 ISAXAttributes* iface,
860 const WCHAR * pLocalName,
864 ok(0, "unexpected call\n");
868 static HRESULT WINAPI isaxattributes_getIndexFromQName(
869 ISAXAttributes* iface,
870 const WCHAR * pQName,
874 ok(0, "unexpected call\n");
878 static HRESULT WINAPI isaxattributes_getType(
879 ISAXAttributes* iface,
881 const WCHAR ** pType,
884 ok(0, "unexpected call\n");
888 static HRESULT WINAPI isaxattributes_getTypeFromName(
889 ISAXAttributes* iface,
892 const WCHAR * pLocalName,
894 const WCHAR ** pType,
897 ok(0, "unexpected call\n");
901 static HRESULT WINAPI isaxattributes_getTypeFromQName(
902 ISAXAttributes* iface,
903 const WCHAR * pQName,
905 const WCHAR ** pType,
908 ok(0, "unexpected call\n");
912 static HRESULT WINAPI isaxattributes_getValue(ISAXAttributes* iface, int index,
913 const WCHAR **value, int *nValue)
915 static const WCHAR attrvaluesW[][10] = {{'a','1','j','u','n','k',0},
916 {'a','2','j','u','n','k',0},
917 {'<','&','"','>',0}};
918 static const int attrvalueslen[] = {2, 2, 4};
920 ok(index >= 0 && index <= 2, "invalid index received %d\n", index);
922 *value = attrvaluesW[index];
923 *nValue = attrvalueslen[index];
928 static HRESULT WINAPI isaxattributes_getValueFromName(
929 ISAXAttributes* iface,
932 const WCHAR * pLocalName,
934 const WCHAR ** pValue,
937 ok(0, "unexpected call\n");
941 static HRESULT WINAPI isaxattributes_getValueFromQName(
942 ISAXAttributes* iface,
943 const WCHAR * pQName,
945 const WCHAR ** pValue,
948 ok(0, "unexpected call\n");
952 static const ISAXAttributesVtbl SAXAttributesVtbl =
954 isaxattributes_QueryInterface,
955 isaxattributes_AddRef,
956 isaxattributes_Release,
957 isaxattributes_getLength,
958 isaxattributes_getURI,
959 isaxattributes_getLocalName,
960 isaxattributes_getQName,
961 isaxattributes_getName,
962 isaxattributes_getIndexFromName,
963 isaxattributes_getIndexFromQName,
964 isaxattributes_getType,
965 isaxattributes_getTypeFromName,
966 isaxattributes_getTypeFromQName,
967 isaxattributes_getValue,
968 isaxattributes_getValueFromName,
969 isaxattributes_getValueFromQName
972 static ISAXAttributes saxattributes = { &SAXAttributesVtbl };
974 static int handler_addrefcalled;
976 static HRESULT WINAPI isaxlexical_QueryInterface(ISAXLexicalHandler* iface, REFIID riid, void **ppvObject)
980 if(IsEqualGUID(riid, &IID_IUnknown) ||
981 IsEqualGUID(riid, &IID_ISAXLexicalHandler))
987 return E_NOINTERFACE;
993 static ULONG WINAPI isaxlexical_AddRef(ISAXLexicalHandler* iface)
995 handler_addrefcalled++;
999 static ULONG WINAPI isaxlexical_Release(ISAXLexicalHandler* iface)
1004 static HRESULT WINAPI isaxlexical_startDTD(ISAXLexicalHandler* iface,
1005 const WCHAR * pName, int nName, const WCHAR * pPublicId,
1006 int nPublicId, const WCHAR * pSystemId, int nSystemId)
1008 ok(0, "call not expected\n");
1012 static HRESULT WINAPI isaxlexical_endDTD(ISAXLexicalHandler* iface)
1014 ok(0, "call not expected\n");
1018 static HRESULT WINAPI isaxlexical_startEntity(ISAXLexicalHandler *iface,
1019 const WCHAR * pName, int nName)
1021 ok(0, "call not expected\n");
1025 static HRESULT WINAPI isaxlexical_endEntity(ISAXLexicalHandler *iface,
1026 const WCHAR * pName, int nName)
1028 ok(0, "call not expected\n");
1032 static HRESULT WINAPI isaxlexical_startCDATA(ISAXLexicalHandler *iface)
1034 ok(0, "call not expected\n");
1038 static HRESULT WINAPI isaxlexical_endCDATA(ISAXLexicalHandler *iface)
1040 ok(0, "call not expected\n");
1044 static HRESULT WINAPI isaxlexical_comment(ISAXLexicalHandler *iface,
1045 const WCHAR * pChars, int nChars)
1047 ok(0, "call not expected\n");
1051 static const ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl =
1053 isaxlexical_QueryInterface,
1055 isaxlexical_Release,
1056 isaxlexical_startDTD,
1058 isaxlexical_startEntity,
1059 isaxlexical_endEntity,
1060 isaxlexical_startCDATA,
1061 isaxlexical_endCDATA,
1065 static ISAXLexicalHandler saxlexicalhandler = { &SAXLexicalHandlerVtbl };
1067 static HRESULT WINAPI isaxdecl_QueryInterface(ISAXDeclHandler* iface, REFIID riid, void **ppvObject)
1071 if(IsEqualGUID(riid, &IID_IUnknown) ||
1072 IsEqualGUID(riid, &IID_ISAXDeclHandler))
1078 return E_NOINTERFACE;
1084 static ULONG WINAPI isaxdecl_AddRef(ISAXDeclHandler* iface)
1086 handler_addrefcalled++;
1090 static ULONG WINAPI isaxdecl_Release(ISAXDeclHandler* iface)
1095 static HRESULT WINAPI isaxdecl_elementDecl(ISAXDeclHandler* iface,
1096 const WCHAR * pName, int nName, const WCHAR * pModel, int nModel)
1098 ok(0, "call not expected\n");
1102 static HRESULT WINAPI isaxdecl_attributeDecl(ISAXDeclHandler* iface,
1103 const WCHAR * pElementName, int nElementName, const WCHAR * pAttributeName,
1104 int nAttributeName, const WCHAR * pType, int nType, const WCHAR * pValueDefault,
1105 int nValueDefault, const WCHAR * pValue, int nValue)
1107 ok(0, "call not expected\n");
1111 static HRESULT WINAPI isaxdecl_internalEntityDecl(ISAXDeclHandler* iface,
1112 const WCHAR * pName, int nName, const WCHAR * pValue, int nValue)
1114 ok(0, "call not expected\n");
1118 static HRESULT WINAPI isaxdecl_externalEntityDecl(ISAXDeclHandler* iface,
1119 const WCHAR * pName, int nName, const WCHAR * pPublicId, int nPublicId,
1120 const WCHAR * pSystemId, int nSystemId)
1122 ok(0, "call not expected\n");
1126 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl =
1128 isaxdecl_QueryInterface,
1131 isaxdecl_elementDecl,
1132 isaxdecl_attributeDecl,
1133 isaxdecl_internalEntityDecl,
1134 isaxdecl_externalEntityDecl
1137 static ISAXDeclHandler saxdeclhandler = { &SAXDeclHandlerVtbl };
1139 typedef struct mxwriter_write_test_t {
1145 } mxwriter_write_test;
1147 typedef struct mxwriter_stream_test_t {
1149 const char *encoding;
1150 mxwriter_write_test expected_writes[4];
1151 } mxwriter_stream_test;
1153 static const mxwriter_write_test *current_write_test;
1154 static DWORD current_stream_test_index;
1156 static HRESULT WINAPI istream_QueryInterface(IStream *iface, REFIID riid, void **ppvObject)
1160 if(IsEqualGUID(riid, &IID_IStream) || IsEqualGUID(riid, &IID_IUnknown))
1163 return E_NOINTERFACE;
1168 static ULONG WINAPI istream_AddRef(IStream *iface)
1173 static ULONG WINAPI istream_Release(IStream *iface)
1178 static HRESULT WINAPI istream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
1180 ok(0, "unexpected call\n");
1184 static HRESULT WINAPI istream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
1188 ok(pv != NULL, "pv == NULL\n");
1190 if(current_write_test->last) {
1191 ok(0, "Too many Write calls made on test %d\n", current_stream_test_index);
1195 fail = current_write_test->fail_write;
1197 ok(current_write_test->cb == cb, "Expected %d, but got %d on test %d\n",
1198 current_write_test->cb, cb, current_stream_test_index);
1201 ok(current_write_test->null_written, "pcbWritten was NULL on test %d\n", current_stream_test_index);
1203 ok(!memcmp(current_write_test->data, pv, cb), "Unexpected data on test %d\n", current_stream_test_index);
1205 ++current_write_test;
1210 return fail ? E_FAIL : S_OK;
1213 static HRESULT WINAPI istream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
1214 ULARGE_INTEGER *plibNewPosition)
1216 ok(0, "unexpected call\n");
1220 static HRESULT WINAPI istream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
1222 ok(0, "unexpected call\n");
1226 static HRESULT WINAPI istream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
1227 ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *plibWritten)
1229 ok(0, "unexpected call\n");
1233 static HRESULT WINAPI istream_Commit(IStream *iface, DWORD grfCommitFlags)
1235 ok(0, "unexpected call\n");
1239 static HRESULT WINAPI istream_Revert(IStream *iface)
1241 ok(0, "unexpected call\n");
1245 static HRESULT WINAPI istream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1246 ULARGE_INTEGER cb, DWORD dwLockType)
1248 ok(0, "unexpected call\n");
1252 static HRESULT WINAPI istream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1253 ULARGE_INTEGER cb, DWORD dwLockType)
1255 ok(0, "unexpected call\n");
1259 static HRESULT WINAPI istream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
1261 ok(0, "unexpected call\n");
1265 static HRESULT WINAPI istream_Clone(IStream *iface, IStream **ppstm)
1267 ok(0, "unexpected call\n");
1271 static const IStreamVtbl StreamVtbl = {
1272 istream_QueryInterface,
1283 istream_UnlockRegion,
1288 static IStream mxstream = { &StreamVtbl };
1290 static void test_saxreader(int version)
1293 ISAXXMLReader *reader = NULL;
1295 ISAXContentHandler *lpContentHandler;
1296 ISAXErrorHandler *lpErrorHandler;
1298 SAFEARRAYBOUND SADim[1];
1299 char *pSAData = NULL;
1301 ULARGE_INTEGER liSize;
1302 LARGE_INTEGER liPos;
1305 static const CHAR testXmlA[] = "test.xml";
1306 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1307 IXMLDOMDocument *domDocument;
1311 msxml_version = version;
1313 hr = CoCreateInstance(&CLSID_SAXXMLReader30, NULL, CLSCTX_INPROC_SERVER,
1314 &IID_ISAXXMLReader, (LPVOID*)&reader);
1315 } else if(version == 6) {
1316 hr = CoCreateInstance(&CLSID_SAXXMLReader60, NULL, CLSCTX_INPROC_SERVER,
1317 &IID_ISAXXMLReader, (LPVOID*)&reader);
1318 if(hr == REGDB_E_CLASSNOTREG) {
1319 win_skip("SAXXMLReader6 not registered\n");
1323 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1324 &IID_ISAXXMLReader, (LPVOID*)&reader);
1326 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1329 hr = ISAXXMLReader_getContentHandler(reader, NULL);
1330 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1332 hr = ISAXXMLReader_getErrorHandler(reader, NULL);
1333 ok(hr == E_POINTER, "Expected E_POINTER, got %08x\n", hr);
1336 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1337 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1338 ok(lpContentHandler == NULL, "Expected %p, got %p\n", NULL, lpContentHandler);
1340 hr = ISAXXMLReader_getErrorHandler(reader, &lpErrorHandler);
1341 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1342 ok(lpErrorHandler == NULL, "Expected %p, got %p\n", NULL, lpErrorHandler);
1344 hr = ISAXXMLReader_putContentHandler(reader, NULL);
1345 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1347 hr = ISAXXMLReader_putContentHandler(reader, &contentHandler);
1348 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1350 hr = ISAXXMLReader_putErrorHandler(reader, &errorHandler);
1351 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1353 hr = ISAXXMLReader_getContentHandler(reader, &lpContentHandler);
1354 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1355 ok(lpContentHandler == &contentHandler, "Expected %p, got %p\n", &contentHandler, lpContentHandler);
1357 V_VT(&var) = VT_BSTR;
1358 V_BSTR(&var) = SysAllocString(szSimpleXML);
1360 expectCall = contentHandlerTest1;
1361 hr = ISAXXMLReader_parse(reader, var);
1362 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1363 test_expect_call(CH_ENDTEST);
1367 SADim[0].lLbound= 0;
1368 SADim[0].cElements= sizeof(szTestXML)-1;
1369 pSA = SafeArrayCreate(VT_UI1, 1, SADim);
1370 SafeArrayAccessData(pSA, (void**)&pSAData);
1371 memcpy(pSAData, szTestXML, sizeof(szTestXML)-1);
1372 SafeArrayUnaccessData(pSA);
1373 V_VT(&var) = VT_ARRAY|VT_UI1;
1374 V_ARRAY(&var) = pSA;
1376 expectCall = contentHandlerTest1;
1377 hr = ISAXXMLReader_parse(reader, var);
1378 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1379 test_expect_call(CH_ENDTEST);
1381 SafeArrayDestroy(pSA);
1383 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1384 liSize.QuadPart = strlen(szTestXML);
1385 IStream_SetSize(iStream, liSize);
1386 IStream_Write(iStream, szTestXML, strlen(szTestXML), &bytesWritten);
1388 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1389 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1390 V_UNKNOWN(&var) = (IUnknown*)iStream;
1392 expectCall = contentHandlerTest1;
1393 hr = ISAXXMLReader_parse(reader, var);
1394 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1395 test_expect_call(CH_ENDTEST);
1397 IStream_Release(iStream);
1399 CreateStreamOnHGlobal(NULL, TRUE, &iStream);
1400 liSize.QuadPart = strlen(szTestAttributes);
1401 IStream_SetSize(iStream, liSize);
1402 IStream_Write(iStream, szTestAttributes, strlen(szTestAttributes), &bytesWritten);
1404 IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
1405 V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
1406 V_UNKNOWN(&var) = (IUnknown*)iStream;
1409 expectCall = contentHandlerTestAttributes6;
1411 expectCall = contentHandlerTestAttributes;
1412 hr = ISAXXMLReader_parse(reader, var);
1413 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1414 test_expect_call(CH_ENDTEST);
1416 IStream_Release(iStream);
1418 V_VT(&var) = VT_BSTR;
1419 V_BSTR(&var) = SysAllocString(szCarriageRetTest);
1421 expectCall = contentHandlerTest2;
1422 hr = ISAXXMLReader_parse(reader, var);
1423 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1424 test_expect_call(CH_ENDTEST);
1428 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1429 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1430 WriteFile(file, szTestXML, sizeof(szTestXML)-1, &bytesWritten, NULL);
1433 expectCall = contentHandlerTest1;
1434 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1435 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1436 test_expect_call(CH_ENDTEST);
1438 expectCall = contentHandlerTestError;
1439 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1440 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1441 test_expect_call(CH_ENDTEST);
1444 expectCall = contentHandlerTestCallbackResult6;
1446 expectCall = contentHandlerTestCallbackResults;
1447 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1448 ok(hr == (version>=6 ? S_OK : S_FALSE), "Expected S_FALSE, got %08x\n", hr);
1449 test_expect_call(CH_ENDTEST);
1451 DeleteFileA(testXmlA);
1453 hr = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
1454 &IID_IXMLDOMDocument, (LPVOID*)&domDocument);
1457 skip("Failed to create DOMDocument instance\n");
1460 bstrData = SysAllocString(szSimpleXML);
1461 hr = IXMLDOMDocument_loadXML(domDocument, bstrData, &vBool);
1462 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1463 V_VT(&var) = VT_UNKNOWN;
1464 V_UNKNOWN(&var) = (IUnknown*)domDocument;
1466 expectCall = contentHandlerTest2;
1467 hr = ISAXXMLReader_parse(reader, var);
1468 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1469 test_expect_call(CH_ENDTEST);
1470 IXMLDOMDocument_Release(domDocument);
1472 expectCall = xmlspaceattr_test;
1473 V_VT(&var) = VT_BSTR;
1474 V_BSTR(&var) = _bstr_(xmlspace_attr);
1475 hr = ISAXXMLReader_parse(reader, var);
1476 EXPECT_HR(hr, S_OK);
1477 test_expect_call(CH_ENDTEST);
1479 ISAXXMLReader_Release(reader);
1480 SysFreeString(bstrData);
1484 struct saxreader_props_test_t
1486 const char *prop_name;
1490 static const struct saxreader_props_test_t props_test_data[] = {
1491 { "http://xml.org/sax/properties/lexical-handler", (IUnknown*)&saxlexicalhandler },
1492 { "http://xml.org/sax/properties/declaration-handler", (IUnknown*)&saxdeclhandler },
1496 static void test_saxreader_properties(void)
1498 const struct saxreader_props_test_t *ptr = props_test_data;
1499 ISAXXMLReader *reader;
1502 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
1503 &IID_ISAXXMLReader, (void**)&reader);
1504 EXPECT_HR(hr, S_OK);
1506 hr = ISAXXMLReader_getProperty(reader, _bstr_("http://xml.org/sax/properties/lexical-handler"), NULL);
1507 EXPECT_HR(hr, E_POINTER);
1509 while (ptr->prop_name)
1513 V_VT(&v) = VT_EMPTY;
1514 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1515 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1516 EXPECT_HR(hr, S_OK);
1517 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1518 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1520 V_VT(&v) = VT_UNKNOWN;
1521 V_UNKNOWN(&v) = ptr->iface;
1522 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1523 EXPECT_HR(hr, S_OK);
1525 V_VT(&v) = VT_EMPTY;
1526 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1527 handler_addrefcalled = 0;
1528 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1529 EXPECT_HR(hr, S_OK);
1530 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1531 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1532 ok(handler_addrefcalled == 1, "AddRef called %d times\n", handler_addrefcalled);
1535 V_VT(&v) = VT_EMPTY;
1536 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1537 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1538 EXPECT_HR(hr, S_OK);
1540 V_VT(&v) = VT_EMPTY;
1541 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1542 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1543 EXPECT_HR(hr, S_OK);
1544 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1545 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1547 V_VT(&v) = VT_UNKNOWN;
1548 V_UNKNOWN(&v) = ptr->iface;
1549 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1550 EXPECT_HR(hr, S_OK);
1552 /* only VT_EMPTY seems to be valid to reset property */
1554 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1555 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1556 EXPECT_HR(hr, E_INVALIDARG);
1558 V_VT(&v) = VT_EMPTY;
1559 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1560 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1561 EXPECT_HR(hr, S_OK);
1562 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1563 ok(V_UNKNOWN(&v) == ptr->iface, "got %p\n", V_UNKNOWN(&v));
1566 V_VT(&v) = VT_UNKNOWN;
1567 V_UNKNOWN(&v) = NULL;
1568 hr = ISAXXMLReader_putProperty(reader, _bstr_(ptr->prop_name), v);
1569 EXPECT_HR(hr, S_OK);
1571 V_VT(&v) = VT_EMPTY;
1572 V_UNKNOWN(&v) = (IUnknown*)0xdeadbeef;
1573 hr = ISAXXMLReader_getProperty(reader, _bstr_(ptr->prop_name), &v);
1574 EXPECT_HR(hr, S_OK);
1575 ok(V_VT(&v) == VT_UNKNOWN, "got %d\n", V_VT(&v));
1576 ok(V_UNKNOWN(&v) == NULL, "got %p\n", V_UNKNOWN(&v));
1581 ISAXXMLReader_Release(reader);
1585 struct feature_ns_entry_t {
1591 static const struct feature_ns_entry_t feature_ns_entry_data[] = {
1592 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", VARIANT_TRUE },
1593 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", VARIANT_TRUE },
1594 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", VARIANT_TRUE },
1595 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", VARIANT_TRUE },
1599 static void test_saxreader_features(void)
1601 const struct feature_ns_entry_t *entry = feature_ns_entry_data;
1602 ISAXXMLReader *reader;
1609 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1612 win_skip("can't create %s instance\n", entry->clsid);
1618 hr = ISAXXMLReader_getFeature(reader, _bstr_("http://xml.org/sax/features/namespaces"), &value);
1619 EXPECT_HR(hr, S_OK);
1621 ok(entry->value == value, "%s: got wrong default value %x, expected %x\n", entry->clsid, value, entry->value);
1623 ISAXXMLReader_Release(reader);
1629 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1630 static const CHAR UTF8BOMTest[] =
1631 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1634 struct enc_test_entry_t {
1642 static const struct enc_test_entry_t encoding_test_data[] = {
1643 { &CLSID_SAXXMLReader, "CLSID_SAXXMLReader", UTF8BOMTest, 0xc00ce56f, 1 },
1644 { &CLSID_SAXXMLReader30, "CLSID_SAXXMLReader30", UTF8BOMTest, 0xc00ce56f, 1 },
1645 { &CLSID_SAXXMLReader40, "CLSID_SAXXMLReader40", UTF8BOMTest, S_OK, 0 },
1646 { &CLSID_SAXXMLReader60, "CLSID_SAXXMLReader60", UTF8BOMTest, S_OK, 0 },
1650 static void test_encoding(void)
1652 const struct enc_test_entry_t *entry = encoding_test_data;
1653 static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
1654 static const CHAR testXmlA[] = "test.xml";
1655 ISAXXMLReader *reader;
1662 hr = CoCreateInstance(entry->guid, NULL, CLSCTX_INPROC_SERVER, &IID_ISAXXMLReader, (void**)&reader);
1665 win_skip("can't create %s instance\n", entry->clsid);
1670 file = CreateFileA(testXmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1671 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1672 WriteFile(file, UTF8BOMTest, sizeof(UTF8BOMTest)-1, &written, NULL);
1675 hr = ISAXXMLReader_parseURL(reader, testXmlW);
1677 todo_wine ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1679 ok(hr == entry->hr, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry->hr, hr, entry->clsid);
1681 DeleteFileA(testXmlA);
1682 ISAXXMLReader_Release(reader);
1688 static void test_mxwriter_handlers(void)
1690 ISAXContentHandler *handler;
1691 IMXWriter *writer, *writer2;
1692 ISAXDeclHandler *decl;
1693 ISAXLexicalHandler *lh;
1696 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1697 &IID_IMXWriter, (void**)&writer);
1698 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1700 EXPECT_REF(writer, 1);
1702 /* ISAXContentHandler */
1703 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&handler);
1704 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1705 EXPECT_REF(writer, 2);
1706 EXPECT_REF(handler, 2);
1708 hr = ISAXContentHandler_QueryInterface(handler, &IID_IMXWriter, (void**)&writer2);
1709 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1710 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1711 EXPECT_REF(writer, 3);
1712 EXPECT_REF(writer2, 3);
1713 IMXWriter_Release(writer2);
1714 ISAXContentHandler_Release(handler);
1716 /* ISAXLexicalHandler */
1717 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lh);
1718 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1719 EXPECT_REF(writer, 2);
1722 hr = ISAXLexicalHandler_QueryInterface(lh, &IID_IMXWriter, (void**)&writer2);
1723 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1724 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1725 EXPECT_REF(writer, 3);
1726 EXPECT_REF(writer2, 3);
1727 IMXWriter_Release(writer2);
1728 ISAXLexicalHandler_Release(lh);
1730 /* ISAXDeclHandler */
1731 hr = IMXWriter_QueryInterface(writer, &IID_ISAXDeclHandler, (void**)&decl);
1732 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1733 EXPECT_REF(writer, 2);
1736 hr = ISAXDeclHandler_QueryInterface(decl, &IID_IMXWriter, (void**)&writer2);
1737 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1738 ok(writer2 == writer, "got %p, expected %p\n", writer2, writer);
1739 EXPECT_REF(writer, 3);
1740 EXPECT_REF(writer2, 3);
1741 IMXWriter_Release(writer2);
1742 ISAXDeclHandler_Release(decl);
1744 IMXWriter_Release(writer);
1747 struct msxmlsupported_data_t
1754 static struct msxmlsupported_data_t mxwriter_support_data[] =
1756 { &CLSID_MXXMLWriter, "MXXMLWriter" },
1757 { &CLSID_MXXMLWriter30, "MXXMLWriter30" },
1758 { &CLSID_MXXMLWriter40, "MXXMLWriter40" },
1759 { &CLSID_MXXMLWriter60, "MXXMLWriter60" },
1763 static struct msxmlsupported_data_t mxattributes_support_data[] =
1765 { &CLSID_SAXAttributes, "SAXAttributes" },
1766 { &CLSID_SAXAttributes30, "SAXAttributes30" },
1767 { &CLSID_SAXAttributes40, "SAXAttributes40" },
1768 { &CLSID_SAXAttributes60, "SAXAttributes60" },
1772 static BOOL is_clsid_supported(const GUID *clsid, const struct msxmlsupported_data_t *table)
1774 while (table->clsid)
1776 if (table->clsid == clsid) return table->supported;
1782 struct mxwriter_props_t
1786 VARIANT_BOOL disable_escape;
1787 VARIANT_BOOL indent;
1788 VARIANT_BOOL omitdecl;
1789 VARIANT_BOOL standalone;
1790 const char *encoding;
1793 static const struct mxwriter_props_t mxwriter_default_props[] =
1795 { &CLSID_MXXMLWriter, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1796 { &CLSID_MXXMLWriter30, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1797 { &CLSID_MXXMLWriter40, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1798 { &CLSID_MXXMLWriter60, VARIANT_TRUE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, "UTF-16" },
1802 static void test_mxwriter_default_properties(const struct mxwriter_props_t *table)
1806 while (table->clsid)
1813 if (!is_clsid_supported(table->clsid, mxwriter_support_data))
1820 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
1821 &IID_IMXWriter, (void**)&writer);
1822 EXPECT_HR(hr, S_OK);
1825 hr = IMXWriter_get_byteOrderMark(writer, &b);
1826 EXPECT_HR(hr, S_OK);
1827 ok(table->bom == b, "test %d: got BOM %d, expected %d\n", i, b, table->bom);
1829 b = !table->disable_escape;
1830 hr = IMXWriter_get_disableOutputEscaping(writer, &b);
1831 EXPECT_HR(hr, S_OK);
1832 ok(table->disable_escape == b, "test %d: got disable escape %d, expected %d\n", i, b,
1833 table->disable_escape);
1836 hr = IMXWriter_get_indent(writer, &b);
1837 EXPECT_HR(hr, S_OK);
1838 ok(table->indent == b, "test %d: got indent %d, expected %d\n", i, b, table->indent);
1840 b = !table->omitdecl;
1841 hr = IMXWriter_get_omitXMLDeclaration(writer, &b);
1842 EXPECT_HR(hr, S_OK);
1843 ok(table->omitdecl == b, "test %d: got omitdecl %d, expected %d\n", i, b, table->omitdecl);
1845 b = !table->standalone;
1846 hr = IMXWriter_get_standalone(writer, &b);
1847 EXPECT_HR(hr, S_OK);
1848 ok(table->standalone == b, "test %d: got standalone %d, expected %d\n", i, b, table->standalone);
1850 hr = IMXWriter_get_encoding(writer, &encoding);
1851 EXPECT_HR(hr, S_OK);
1852 ok(!lstrcmpW(encoding, _bstr_(table->encoding)), "test %d: got encoding %s, expected %s\n",
1853 i, wine_dbgstr_w(encoding), table->encoding);
1854 SysFreeString(encoding);
1856 IMXWriter_Release(writer);
1863 static void test_mxwriter_properties(void)
1865 static const WCHAR utf16W[] = {'U','T','F','-','1','6',0};
1866 static const WCHAR emptyW[] = {0};
1867 static const WCHAR testW[] = {'t','e','s','t',0};
1868 ISAXContentHandler *content;
1875 test_mxwriter_default_properties(mxwriter_default_props);
1877 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
1878 &IID_IMXWriter, (void**)&writer);
1879 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1881 hr = IMXWriter_get_disableOutputEscaping(writer, NULL);
1882 ok(hr == E_POINTER, "got %08x\n", hr);
1884 hr = IMXWriter_get_byteOrderMark(writer, NULL);
1885 ok(hr == E_POINTER, "got %08x\n", hr);
1887 hr = IMXWriter_get_indent(writer, NULL);
1888 ok(hr == E_POINTER, "got %08x\n", hr);
1890 hr = IMXWriter_get_omitXMLDeclaration(writer, NULL);
1891 ok(hr == E_POINTER, "got %08x\n", hr);
1893 hr = IMXWriter_get_standalone(writer, NULL);
1894 ok(hr == E_POINTER, "got %08x\n", hr);
1897 hr = IMXWriter_put_standalone(writer, VARIANT_TRUE);
1898 ok(hr == S_OK, "got %08x\n", hr);
1901 hr = IMXWriter_get_standalone(writer, &b);
1902 ok(hr == S_OK, "got %08x\n", hr);
1903 ok(b == VARIANT_TRUE, "got %d\n", b);
1905 hr = IMXWriter_get_encoding(writer, NULL);
1906 EXPECT_HR(hr, E_POINTER);
1908 /* UTF-16 is a default setting apparently */
1909 str = (void*)0xdeadbeef;
1910 hr = IMXWriter_get_encoding(writer, &str);
1911 EXPECT_HR(hr, S_OK);
1912 ok(lstrcmpW(str, utf16W) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str));
1914 str2 = (void*)0xdeadbeef;
1915 hr = IMXWriter_get_encoding(writer, &str2);
1916 ok(hr == S_OK, "got %08x\n", hr);
1917 ok(str != str2, "expected newly allocated, got same %p\n", str);
1919 SysFreeString(str2);
1922 /* put empty string */
1923 str = SysAllocString(emptyW);
1924 hr = IMXWriter_put_encoding(writer, str);
1925 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1928 str = (void*)0xdeadbeef;
1929 hr = IMXWriter_get_encoding(writer, &str);
1930 EXPECT_HR(hr, S_OK);
1931 ok(!lstrcmpW(str, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(str));
1934 /* invalid encoding name */
1935 str = SysAllocString(testW);
1936 hr = IMXWriter_put_encoding(writer, str);
1937 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1940 /* test case sensivity */
1941 hr = IMXWriter_put_encoding(writer, _bstr_("utf-8"));
1942 EXPECT_HR(hr, S_OK);
1943 str = (void*)0xdeadbeef;
1944 hr = IMXWriter_get_encoding(writer, &str);
1945 EXPECT_HR(hr, S_OK);
1946 ok(!lstrcmpW(str, _bstr_("utf-8")), "got %s\n", wine_dbgstr_w(str));
1949 hr = IMXWriter_put_encoding(writer, _bstr_("uTf-16"));
1950 EXPECT_HR(hr, S_OK);
1951 str = (void*)0xdeadbeef;
1952 hr = IMXWriter_get_encoding(writer, &str);
1953 EXPECT_HR(hr, S_OK);
1954 ok(!lstrcmpW(str, _bstr_("uTf-16")), "got %s\n", wine_dbgstr_w(str));
1957 /* how it affects document creation */
1958 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
1959 EXPECT_HR(hr, S_OK);
1961 hr = ISAXContentHandler_startDocument(content);
1962 EXPECT_HR(hr, S_OK);
1963 hr = ISAXContentHandler_endDocument(content);
1964 EXPECT_HR(hr, S_OK);
1966 V_VT(&dest) = VT_EMPTY;
1967 hr = IMXWriter_get_output(writer, &dest);
1968 EXPECT_HR(hr, S_OK);
1969 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
1970 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\"?>\r\n"),
1971 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
1972 VariantClear(&dest);
1973 ISAXContentHandler_Release(content);
1975 hr = IMXWriter_get_version(writer, NULL);
1976 ok(hr == E_POINTER, "got %08x\n", hr);
1977 /* default version is 'surprisingly' 1.0 */
1978 hr = IMXWriter_get_version(writer, &str);
1979 ok(hr == S_OK, "got %08x\n", hr);
1980 ok(!lstrcmpW(str, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str));
1983 /* store version string as is */
1984 hr = IMXWriter_put_version(writer, NULL);
1985 ok(hr == E_INVALIDARG, "got %08x\n", hr);
1987 hr = IMXWriter_put_version(writer, _bstr_("1.0"));
1988 ok(hr == S_OK, "got %08x\n", hr);
1990 hr = IMXWriter_put_version(writer, _bstr_(""));
1991 ok(hr == S_OK, "got %08x\n", hr);
1992 hr = IMXWriter_get_version(writer, &str);
1993 ok(hr == S_OK, "got %08x\n", hr);
1994 ok(!lstrcmpW(str, _bstr_("")), "got %s\n", wine_dbgstr_w(str));
1997 hr = IMXWriter_put_version(writer, _bstr_("a.b"));
1998 ok(hr == S_OK, "got %08x\n", hr);
1999 hr = IMXWriter_get_version(writer, &str);
2000 ok(hr == S_OK, "got %08x\n", hr);
2001 ok(!lstrcmpW(str, _bstr_("a.b")), "got %s\n", wine_dbgstr_w(str));
2004 hr = IMXWriter_put_version(writer, _bstr_("2.0"));
2005 ok(hr == S_OK, "got %08x\n", hr);
2006 hr = IMXWriter_get_version(writer, &str);
2007 ok(hr == S_OK, "got %08x\n", hr);
2008 ok(!lstrcmpW(str, _bstr_("2.0")), "got %s\n", wine_dbgstr_w(str));
2011 IMXWriter_Release(writer);
2015 static void test_mxwriter_flush(void)
2017 ISAXContentHandler *content;
2020 ULARGE_INTEGER pos2;
2025 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2026 &IID_IMXWriter, (void**)&writer);
2027 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2029 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2030 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2031 EXPECT_REF(stream, 1);
2033 /* detach when nothing was attached */
2034 V_VT(&dest) = VT_EMPTY;
2035 hr = IMXWriter_put_output(writer, dest);
2036 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2039 V_VT(&dest) = VT_UNKNOWN;
2040 V_UNKNOWN(&dest) = (IUnknown*)stream;
2041 hr = IMXWriter_put_output(writer, dest);
2042 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2043 todo_wine EXPECT_REF(stream, 3);
2045 /* detach setting VT_EMPTY destination */
2046 V_VT(&dest) = VT_EMPTY;
2047 hr = IMXWriter_put_output(writer, dest);
2048 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2049 EXPECT_REF(stream, 1);
2051 V_VT(&dest) = VT_UNKNOWN;
2052 V_UNKNOWN(&dest) = (IUnknown*)stream;
2053 hr = IMXWriter_put_output(writer, dest);
2054 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2056 /* flush() doesn't detach a stream */
2057 hr = IMXWriter_flush(writer);
2058 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2059 todo_wine EXPECT_REF(stream, 3);
2062 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2063 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2064 ok(pos2.QuadPart == 0, "expected stream beginning\n");
2066 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2067 ok(hr == S_OK, "got %08x\n", hr);
2069 hr = ISAXContentHandler_startDocument(content);
2070 ok(hr == S_OK, "got %08x\n", hr);
2073 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2074 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2075 ok(pos2.QuadPart != 0, "expected stream beginning\n");
2077 /* already started */
2078 hr = ISAXContentHandler_startDocument(content);
2079 ok(hr == S_OK, "got %08x\n", hr);
2081 hr = ISAXContentHandler_endDocument(content);
2082 ok(hr == S_OK, "got %08x\n", hr);
2084 /* flushed on endDocument() */
2086 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2087 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2088 ok(pos2.QuadPart != 0, "expected stream position moved\n");
2090 ISAXContentHandler_Release(content);
2091 IStream_Release(stream);
2092 IMXWriter_Release(writer);
2095 static void test_mxwriter_startenddocument(void)
2097 ISAXContentHandler *content;
2102 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2103 &IID_IMXWriter, (void**)&writer);
2104 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2106 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2107 ok(hr == S_OK, "got %08x\n", hr);
2109 hr = ISAXContentHandler_startDocument(content);
2110 ok(hr == S_OK, "got %08x\n", hr);
2112 hr = ISAXContentHandler_endDocument(content);
2113 ok(hr == S_OK, "got %08x\n", hr);
2115 V_VT(&dest) = VT_EMPTY;
2116 hr = IMXWriter_get_output(writer, &dest);
2117 ok(hr == S_OK, "got %08x\n", hr);
2118 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2119 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2120 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2121 VariantClear(&dest);
2123 /* now try another startDocument */
2124 hr = ISAXContentHandler_startDocument(content);
2125 ok(hr == S_OK, "got %08x\n", hr);
2126 /* and get duplicated prolog */
2127 V_VT(&dest) = VT_EMPTY;
2128 hr = IMXWriter_get_output(writer, &dest);
2129 ok(hr == S_OK, "got %08x\n", hr);
2130 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2131 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
2132 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2133 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2134 VariantClear(&dest);
2136 ISAXContentHandler_Release(content);
2137 IMXWriter_Release(writer);
2139 /* now with omitted declaration */
2140 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2141 &IID_IMXWriter, (void**)&writer);
2142 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2144 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2145 ok(hr == S_OK, "got %08x\n", hr);
2147 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2148 ok(hr == S_OK, "got %08x\n", hr);
2150 hr = ISAXContentHandler_startDocument(content);
2151 ok(hr == S_OK, "got %08x\n", hr);
2153 hr = ISAXContentHandler_endDocument(content);
2154 ok(hr == S_OK, "got %08x\n", hr);
2156 V_VT(&dest) = VT_EMPTY;
2157 hr = IMXWriter_get_output(writer, &dest);
2158 ok(hr == S_OK, "got %08x\n", hr);
2159 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2160 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2161 VariantClear(&dest);
2163 ISAXContentHandler_Release(content);
2164 IMXWriter_Release(writer);
2176 struct writer_startendelement_t {
2178 enum startendtype type;
2180 const char *local_name;
2184 ISAXAttributes *attr;
2187 static const char startelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"<&">\">";
2188 static const char startendelement_xml[] = "<uri:local a:attr1=\"a1\" attr2=\"a2\" attr3=\"<&">\"/>";
2190 static const struct writer_startendelement_t writer_startendelement[] = {
2192 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2193 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2194 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2195 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, NULL, "<>", S_OK },
2196 { &CLSID_MXXMLWriter, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2198 { &CLSID_MXXMLWriter30, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2199 { &CLSID_MXXMLWriter40, StartElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2200 { &CLSID_MXXMLWriter60, StartElement, "uri", NULL, NULL, "<>", S_OK },
2201 { &CLSID_MXXMLWriter, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2202 { &CLSID_MXXMLWriter30, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2204 { &CLSID_MXXMLWriter40, StartElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2205 { &CLSID_MXXMLWriter60, StartElement, NULL, "local", NULL, "<>", S_OK },
2206 { &CLSID_MXXMLWriter, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2207 { &CLSID_MXXMLWriter30, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2208 { &CLSID_MXXMLWriter40, StartElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2210 { &CLSID_MXXMLWriter60, StartElement, NULL, NULL, "qname", "<qname>", S_OK },
2211 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2212 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2213 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2214 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "qname", "<qname>", S_OK },
2216 { &CLSID_MXXMLWriter, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2217 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2218 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2219 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", NULL, "<>", S_OK },
2220 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2222 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2223 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2224 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", "<uri:local>", S_OK },
2225 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2226 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2228 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2229 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local2", "<uri:local2>", S_OK },
2230 /* endElement tests */
2231 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2232 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2233 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, NULL, NULL, E_INVALIDARG },
2235 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, NULL, "</>", S_OK },
2236 { &CLSID_MXXMLWriter, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2237 { &CLSID_MXXMLWriter30, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2238 { &CLSID_MXXMLWriter40, EndElement, "uri", NULL, NULL, NULL, E_INVALIDARG },
2239 { &CLSID_MXXMLWriter60, EndElement, "uri", NULL, NULL, "</>", S_OK },
2241 { &CLSID_MXXMLWriter, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2242 { &CLSID_MXXMLWriter30, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2243 { &CLSID_MXXMLWriter40, EndElement, NULL, "local", NULL, NULL, E_INVALIDARG },
2244 { &CLSID_MXXMLWriter60, EndElement, NULL, "local", NULL, "</>", S_OK },
2245 { &CLSID_MXXMLWriter, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2247 { &CLSID_MXXMLWriter30, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2248 { &CLSID_MXXMLWriter40, EndElement, NULL, NULL, "qname", NULL, E_INVALIDARG },
2249 { &CLSID_MXXMLWriter60, EndElement, NULL, NULL, "qname", "</qname>", S_OK },
2250 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2251 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2253 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2254 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "qname", "</qname>", S_OK },
2255 { &CLSID_MXXMLWriter, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2256 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2257 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", NULL, NULL, E_INVALIDARG },
2259 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", NULL, "</>", S_OK },
2260 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2261 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2262 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2263 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local", "</uri:local>", S_OK },
2265 { &CLSID_MXXMLWriter, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2266 { &CLSID_MXXMLWriter30, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2267 { &CLSID_MXXMLWriter40, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2268 { &CLSID_MXXMLWriter60, EndElement, "uri", "local", "uri:local2", "</uri:local2>", S_OK },
2270 /* with attributes */
2271 { &CLSID_MXXMLWriter, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2273 { &CLSID_MXXMLWriter30, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2274 { &CLSID_MXXMLWriter40, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2275 { &CLSID_MXXMLWriter60, StartElement, "uri", "local", "uri:local", startelement_xml, S_OK, &saxattributes },
2276 /* empty elements */
2277 { &CLSID_MXXMLWriter, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2278 { &CLSID_MXXMLWriter30, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2280 { &CLSID_MXXMLWriter40, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2281 { &CLSID_MXXMLWriter60, StartEndElement, "uri", "local", "uri:local", startendelement_xml, S_OK, &saxattributes },
2282 { &CLSID_MXXMLWriter, StartEndElement, "", "", "", "</>", S_OK },
2283 { &CLSID_MXXMLWriter30, StartEndElement, "", "", "", "</>", S_OK },
2284 { &CLSID_MXXMLWriter40, StartEndElement, "", "", "", "</>", S_OK },
2286 { &CLSID_MXXMLWriter60, StartEndElement, "", "", "", "</>", S_OK },
2290 static void get_mxwriter_support_data(struct msxmlsupported_data_t *table)
2292 while (table->clsid)
2297 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2298 &IID_IMXWriter, (void**)&writer);
2299 if (hr == S_OK) IMXWriter_Release(writer);
2301 table->supported = hr == S_OK;
2302 if (hr != S_OK) win_skip("class %s not supported\n", table->name);
2308 static void get_mxattributes_support_data(struct msxmlsupported_data_t *table)
2310 while (table->clsid)
2312 IMXAttributes *attr;
2315 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2316 &IID_IMXAttributes, (void**)&attr);
2317 if (hr == S_OK) IMXAttributes_Release(attr);
2319 table->supported = hr == S_OK;
2320 if (hr != S_OK) skip("class %s not supported\n", table->name);
2326 static void test_mxwriter_startendelement_batch(const struct writer_startendelement_t *table)
2330 while (table->clsid)
2332 ISAXContentHandler *content;
2336 if (!is_clsid_supported(table->clsid, mxwriter_support_data))
2343 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2344 &IID_IMXWriter, (void**)&writer);
2345 EXPECT_HR(hr, S_OK);
2347 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2348 EXPECT_HR(hr, S_OK);
2350 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2351 EXPECT_HR(hr, S_OK);
2353 hr = ISAXContentHandler_startDocument(content);
2354 EXPECT_HR(hr, S_OK);
2356 if (table->type == StartElement)
2358 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2359 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2360 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2362 else if (table->type == EndElement)
2364 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2365 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2366 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2370 hr = ISAXContentHandler_startElement(content, _bstr_(table->uri), lstrlen(table->uri),
2371 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname), table->attr);
2372 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2373 hr = ISAXContentHandler_endElement(content, _bstr_(table->uri), lstrlen(table->uri),
2374 _bstr_(table->local_name), lstrlen(table->local_name), _bstr_(table->qname), lstrlen(table->qname));
2375 ok(hr == table->hr, "test %d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
2383 V_VT(&dest) = VT_EMPTY;
2384 hr = IMXWriter_get_output(writer, &dest);
2385 EXPECT_HR(hr, S_OK);
2386 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2387 ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
2388 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
2389 VariantClear(&dest);
2392 ISAXContentHandler_Release(content);
2393 IMXWriter_Release(writer);
2402 static void test_mxwriter_startendelement(void)
2404 ISAXContentHandler *content;
2409 test_mxwriter_startendelement_batch(writer_startendelement);
2411 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2412 &IID_IMXWriter, (void**)&writer);
2413 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
2415 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2416 ok(hr == S_OK, "got %08x\n", hr);
2418 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2419 ok(hr == S_OK, "got %08x\n", hr);
2421 hr = ISAXContentHandler_startDocument(content);
2422 ok(hr == S_OK, "got %08x\n", hr);
2424 /* all string pointers should be not null */
2425 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL);
2426 ok(hr == S_OK, "got %08x\n", hr);
2428 V_VT(&dest) = VT_EMPTY;
2429 hr = IMXWriter_get_output(writer, &dest);
2430 ok(hr == S_OK, "got %08x\n", hr);
2431 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2432 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2433 VariantClear(&dest);
2435 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL);
2436 ok(hr == S_OK, "got %08x\n", hr);
2438 V_VT(&dest) = VT_EMPTY;
2439 hr = IMXWriter_get_output(writer, &dest);
2440 ok(hr == S_OK, "got %08x\n", hr);
2441 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2442 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2443 VariantClear(&dest);
2445 hr = ISAXContentHandler_endElement(content, NULL, 0, NULL, 0, _bstr_("a:b"), 3);
2446 EXPECT_HR(hr, E_INVALIDARG);
2448 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
2449 EXPECT_HR(hr, E_INVALIDARG);
2451 /* only local name is an error too */
2452 hr = ISAXContentHandler_endElement(content, NULL, 0, _bstr_("b"), 1, NULL, 0);
2453 EXPECT_HR(hr, E_INVALIDARG);
2455 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
2456 EXPECT_HR(hr, S_OK);
2458 V_VT(&dest) = VT_EMPTY;
2459 hr = IMXWriter_get_output(writer, &dest);
2460 EXPECT_HR(hr, S_OK);
2461 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2462 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2463 VariantClear(&dest);
2465 hr = ISAXContentHandler_endDocument(content);
2466 EXPECT_HR(hr, S_OK);
2468 V_VT(&dest) = VT_EMPTY;
2469 hr = IMXWriter_put_output(writer, dest);
2470 EXPECT_HR(hr, S_OK);
2472 V_VT(&dest) = VT_EMPTY;
2473 hr = IMXWriter_get_output(writer, &dest);
2474 EXPECT_HR(hr, S_OK);
2475 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2476 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2477 VariantClear(&dest);
2479 hr = ISAXContentHandler_startDocument(content);
2480 EXPECT_HR(hr, S_OK);
2482 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abcdef"), 3, NULL);
2483 EXPECT_HR(hr, S_OK);
2485 V_VT(&dest) = VT_EMPTY;
2486 hr = IMXWriter_get_output(writer, &dest);
2487 EXPECT_HR(hr, S_OK);
2488 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2489 ok(!lstrcmpW(_bstr_("<abc>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2490 VariantClear(&dest);
2492 ISAXContentHandler_endDocument(content);
2493 IMXWriter_flush(writer);
2495 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abdcdef"), 3);
2496 EXPECT_HR(hr, S_OK);
2497 V_VT(&dest) = VT_EMPTY;
2498 hr = IMXWriter_get_output(writer, &dest);
2499 EXPECT_HR(hr, S_OK);
2500 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2501 ok(!lstrcmpW(_bstr_("<abc></abd>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2502 VariantClear(&dest);
2504 ISAXContentHandler_Release(content);
2505 IMXWriter_Release(writer);
2509 struct writer_characters_t {
2515 static const struct writer_characters_t writer_characters[] = {
2516 { &CLSID_MXXMLWriter, "< > & \"", "< > & \"" },
2517 { &CLSID_MXXMLWriter30, "< > & \"", "< > & \"" },
2518 { &CLSID_MXXMLWriter40, "< > & \"", "< > & \"" },
2519 { &CLSID_MXXMLWriter60, "< > & \"", "< > & \"" },
2523 static void test_mxwriter_characters(void)
2525 static const WCHAR chardataW[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
2526 const struct writer_characters_t *table = writer_characters;
2527 ISAXContentHandler *content;
2533 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2534 &IID_IMXWriter, (void**)&writer);
2535 EXPECT_HR(hr, S_OK);
2537 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2538 EXPECT_HR(hr, S_OK);
2540 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2541 EXPECT_HR(hr, S_OK);
2543 hr = ISAXContentHandler_startDocument(content);
2544 EXPECT_HR(hr, S_OK);
2546 hr = ISAXContentHandler_characters(content, NULL, 0);
2547 EXPECT_HR(hr, E_INVALIDARG);
2549 hr = ISAXContentHandler_characters(content, chardataW, 0);
2550 EXPECT_HR(hr, S_OK);
2552 hr = ISAXContentHandler_characters(content, chardataW, sizeof(chardataW)/sizeof(WCHAR) - 1);
2553 EXPECT_HR(hr, S_OK);
2555 V_VT(&dest) = VT_EMPTY;
2556 hr = IMXWriter_get_output(writer, &dest);
2557 EXPECT_HR(hr, S_OK);
2558 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2559 ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2560 VariantClear(&dest);
2562 hr = ISAXContentHandler_endDocument(content);
2563 EXPECT_HR(hr, S_OK);
2565 ISAXContentHandler_Release(content);
2566 IMXWriter_Release(writer);
2568 /* try empty characters data to see if element is closed */
2569 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2570 &IID_IMXWriter, (void**)&writer);
2571 EXPECT_HR(hr, S_OK);
2573 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2574 EXPECT_HR(hr, S_OK);
2576 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2577 EXPECT_HR(hr, S_OK);
2579 hr = ISAXContentHandler_startDocument(content);
2580 EXPECT_HR(hr, S_OK);
2582 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2583 EXPECT_HR(hr, S_OK);
2585 hr = ISAXContentHandler_characters(content, chardataW, 0);
2586 EXPECT_HR(hr, S_OK);
2588 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2589 EXPECT_HR(hr, S_OK);
2591 V_VT(&dest) = VT_EMPTY;
2592 hr = IMXWriter_get_output(writer, &dest);
2593 EXPECT_HR(hr, S_OK);
2594 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2595 ok(!lstrcmpW(_bstr_("<a></a>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2596 VariantClear(&dest);
2598 ISAXContentHandler_Release(content);
2599 IMXWriter_Release(writer);
2602 while (table->clsid)
2604 ISAXContentHandler *content;
2608 if (!is_clsid_supported(table->clsid, mxwriter_support_data))
2615 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
2616 &IID_IMXWriter, (void**)&writer);
2617 EXPECT_HR(hr, S_OK);
2619 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2620 EXPECT_HR(hr, S_OK);
2622 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
2623 EXPECT_HR(hr, S_OK);
2625 hr = ISAXContentHandler_startDocument(content);
2626 EXPECT_HR(hr, S_OK);
2628 hr = ISAXContentHandler_characters(content, _bstr_(table->data), strlen(table->data));
2629 EXPECT_HR(hr, S_OK);
2636 V_VT(&dest) = VT_EMPTY;
2637 hr = IMXWriter_get_output(writer, &dest);
2638 EXPECT_HR(hr, S_OK);
2639 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
2640 ok(!lstrcmpW(_bstr_(table->output), V_BSTR(&dest)),
2641 "test %d: got wrong content %s, expected %s\n", i, wine_dbgstr_w(V_BSTR(&dest)), table->output);
2642 VariantClear(&dest);
2652 static const mxwriter_stream_test mxwriter_stream_tests[] = {
2654 VARIANT_TRUE,"UTF-16",
2656 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2657 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2662 VARIANT_FALSE,"UTF-16",
2664 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2669 VARIANT_TRUE,"UTF-8",
2671 {FALSE,(const BYTE*)szUtf8XML,sizeof(szUtf8XML)-1},
2672 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2673 * and the writer is released.
2680 VARIANT_TRUE,"utf-8",
2682 {FALSE,(const BYTE*)utf8xml2,sizeof(utf8xml2)-1},
2683 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2684 * and the writer is released.
2691 VARIANT_TRUE,"UTF-16",
2693 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE},
2694 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2699 VARIANT_TRUE,"UTF-16",
2701 {FALSE,(const BYTE*)szUtf16BOM,sizeof(szUtf16BOM),TRUE,TRUE},
2702 {FALSE,(const BYTE*)szUtf16XML,sizeof(szUtf16XML)},
2708 static void test_mxwriter_stream(void)
2711 ISAXContentHandler *content;
2716 ULARGE_INTEGER pos2;
2717 DWORD test_count = sizeof(mxwriter_stream_tests)/sizeof(mxwriter_stream_tests[0]);
2719 for(current_stream_test_index = 0; current_stream_test_index < test_count; ++current_stream_test_index) {
2720 const mxwriter_stream_test *test = mxwriter_stream_tests+current_stream_test_index;
2722 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2723 &IID_IMXWriter, (void**)&writer);
2724 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2726 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2727 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2729 hr = IMXWriter_put_encoding(writer, _bstr_(test->encoding));
2730 ok(hr == S_OK, "put_encoding failed with %08x on test %d\n", hr, current_stream_test_index);
2732 V_VT(&dest) = VT_UNKNOWN;
2733 V_UNKNOWN(&dest) = (IUnknown*)&mxstream;
2734 hr = IMXWriter_put_output(writer, dest);
2735 ok(hr == S_OK, "put_output failed with %08x on test %d\n", hr, current_stream_test_index);
2736 VariantClear(&dest);
2738 hr = IMXWriter_put_byteOrderMark(writer, test->bom);
2739 ok(hr == S_OK, "put_byteOrderMark failed with %08x on test %d\n", hr, current_stream_test_index);
2741 current_write_test = test->expected_writes;
2743 hr = ISAXContentHandler_startDocument(content);
2744 ok(hr == S_OK, "startDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2746 hr = ISAXContentHandler_endDocument(content);
2747 ok(hr == S_OK, "endDocument failed with %08x on test %d\n", hr, current_stream_test_index);
2749 ISAXContentHandler_Release(content);
2750 IMXWriter_Release(writer);
2752 ok(current_write_test->last, "The last %d write calls on test %d were missed\n",
2753 (int)(current_write_test-test->expected_writes), current_stream_test_index);
2756 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2757 &IID_IMXWriter, (void**)&writer);
2758 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
2760 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2761 ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
2763 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2764 ok(hr == S_OK, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr);
2766 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2767 ok(hr == S_OK, "put_encoding failed: %08x\n", hr);
2769 V_VT(&dest) = VT_UNKNOWN;
2770 V_UNKNOWN(&dest) = (IUnknown*)stream;
2771 hr = IMXWriter_put_output(writer, dest);
2772 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2774 hr = ISAXContentHandler_startDocument(content);
2775 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2777 /* Setting output of the mxwriter causes the current output to be flushed,
2778 * and the writer to start over.
2780 V_VT(&dest) = VT_EMPTY;
2781 hr = IMXWriter_put_output(writer, dest);
2782 ok(hr == S_OK, "put_output failed: %08x\n", hr);
2785 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2786 ok(hr == S_OK, "Seek failed: %08x\n", hr);
2787 ok(pos2.QuadPart != 0, "expected stream position moved\n");
2789 hr = ISAXContentHandler_startDocument(content);
2790 ok(hr == S_OK, "startDocument failed: %08x\n", hr);
2792 hr = ISAXContentHandler_endDocument(content);
2793 ok(hr == S_OK, "endDocument failed: %08x\n", hr);
2795 V_VT(&dest) = VT_EMPTY;
2796 hr = IMXWriter_get_output(writer, &dest);
2797 ok(hr == S_OK, "get_output failed: %08x\n", hr);
2798 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2799 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2800 "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2801 VariantClear(&dest);
2803 /* test when BOM is written to output stream */
2804 V_VT(&dest) = VT_EMPTY;
2805 hr = IMXWriter_put_output(writer, dest);
2806 EXPECT_HR(hr, S_OK);
2809 hr = IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
2810 EXPECT_HR(hr, S_OK);
2812 V_VT(&dest) = VT_UNKNOWN;
2813 V_UNKNOWN(&dest) = (IUnknown*)stream;
2814 hr = IMXWriter_put_output(writer, dest);
2815 EXPECT_HR(hr, S_OK);
2817 hr = IMXWriter_put_byteOrderMark(writer, VARIANT_TRUE);
2818 EXPECT_HR(hr, S_OK);
2820 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2821 EXPECT_HR(hr, S_OK);
2823 hr = ISAXContentHandler_startDocument(content);
2824 EXPECT_HR(hr, S_OK);
2828 hr = IStream_Seek(stream, pos, STREAM_SEEK_CUR, &pos2);
2829 EXPECT_HR(hr, S_OK);
2830 ok(pos2.QuadPart == 2, "got wrong position\n");
2832 ISAXContentHandler_Release(content);
2833 IMXWriter_Release(writer);
2838 static void test_mxwriter_encoding(void)
2840 ISAXContentHandler *content;
2849 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
2850 &IID_IMXWriter, (void**)&writer);
2851 EXPECT_HR(hr, S_OK);
2853 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
2854 EXPECT_HR(hr, S_OK);
2856 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2857 EXPECT_HR(hr, S_OK);
2859 hr = ISAXContentHandler_startDocument(content);
2860 EXPECT_HR(hr, S_OK);
2862 hr = ISAXContentHandler_endDocument(content);
2863 EXPECT_HR(hr, S_OK);
2865 /* The content is always re-encoded to UTF-16 when the output is
2866 * retrieved as a BSTR.
2868 V_VT(&dest) = VT_EMPTY;
2869 hr = IMXWriter_get_output(writer, &dest);
2870 EXPECT_HR(hr, S_OK);
2871 ok(V_VT(&dest) == VT_BSTR, "Expected VT_BSTR, got %d\n", V_VT(&dest));
2872 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest)),
2873 "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest)));
2874 VariantClear(&dest);
2876 /* switch encoding when something is written already */
2877 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2878 EXPECT_HR(hr, S_OK);
2880 V_VT(&dest) = VT_UNKNOWN;
2881 V_UNKNOWN(&dest) = (IUnknown*)stream;
2882 hr = IMXWriter_put_output(writer, dest);
2883 EXPECT_HR(hr, S_OK);
2885 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-8"));
2886 EXPECT_HR(hr, S_OK);
2888 /* write empty element */
2889 hr = ISAXContentHandler_startElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL);
2890 EXPECT_HR(hr, S_OK);
2892 hr = ISAXContentHandler_endElement(content, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2893 EXPECT_HR(hr, S_OK);
2896 hr = IMXWriter_put_encoding(writer, _bstr_("UTF-16"));
2897 EXPECT_HR(hr, S_OK);
2899 hr = IMXWriter_flush(writer);
2900 EXPECT_HR(hr, S_OK);
2902 hr = GetHGlobalFromStream(stream, &g);
2903 EXPECT_HR(hr, S_OK);
2905 ptr = GlobalLock(g);
2906 ok(!strncmp(ptr, "<a/>", 4), "got %c%c%c%c\n", ptr[0],ptr[1],ptr[2],ptr[3]);
2909 /* so output is unaffected, encoding name is stored however */
2910 hr = IMXWriter_get_encoding(writer, &s);
2911 EXPECT_HR(hr, S_OK);
2912 ok(!lstrcmpW(s, _bstr_("UTF-16")), "got %s\n", wine_dbgstr_w(s));
2915 IStream_Release(stream);
2917 ISAXContentHandler_Release(content);
2918 IMXWriter_Release(writer);
2923 static void test_obj_dispex(IUnknown *obj)
2925 static const WCHAR starW[] = {'*',0};
2926 DISPID dispid = DISPID_SAX_XMLREADER_GETFEATURE;
2927 IDispatchEx *dispex;
2934 hr = IUnknown_QueryInterface(obj, &IID_IDispatchEx, (void**)&dispex);
2935 EXPECT_HR(hr, S_OK);
2936 if (FAILED(hr)) return;
2939 hr = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
2940 EXPECT_HR(hr, S_OK);
2941 ok(ticnt == 1, "ticnt=%u\n", ticnt);
2943 name = SysAllocString(starW);
2944 hr = IDispatchEx_DeleteMemberByName(dispex, name, fdexNameCaseSensitive);
2945 EXPECT_HR(hr, E_NOTIMPL);
2946 SysFreeString(name);
2948 hr = IDispatchEx_DeleteMemberByDispID(dispex, dispid);
2949 EXPECT_HR(hr, E_NOTIMPL);
2952 hr = IDispatchEx_GetMemberProperties(dispex, dispid, grfdexPropCanAll, &props);
2953 EXPECT_HR(hr, E_NOTIMPL);
2954 ok(props == 0, "expected 0 got %d\n", props);
2956 hr = IDispatchEx_GetMemberName(dispex, dispid, &name);
2957 EXPECT_HR(hr, E_NOTIMPL);
2958 if (SUCCEEDED(hr)) SysFreeString(name);
2960 hr = IDispatchEx_GetNextDispID(dispex, fdexEnumDefault, DISPID_SAX_XMLREADER_GETFEATURE, &dispid);
2961 EXPECT_HR(hr, E_NOTIMPL);
2963 hr = IDispatchEx_GetNameSpaceParent(dispex, &unk);
2964 EXPECT_HR(hr, E_NOTIMPL);
2965 if (hr == S_OK && unk) IUnknown_Release(unk);
2967 IDispatchEx_Release(dispex);
2970 static void test_dispex(void)
2972 IVBSAXXMLReader *vbreader;
2973 ISAXXMLReader *reader;
2977 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
2978 &IID_ISAXXMLReader, (void**)&reader);
2979 EXPECT_HR(hr, S_OK);
2981 hr = ISAXXMLReader_QueryInterface(reader, &IID_IUnknown, (void**)&unk);
2982 EXPECT_HR(hr, S_OK);
2983 test_obj_dispex(unk);
2984 IUnknown_Release(unk);
2986 hr = ISAXXMLReader_QueryInterface(reader, &IID_IVBSAXXMLReader, (void**)&vbreader);
2987 EXPECT_HR(hr, S_OK);
2988 hr = IVBSAXXMLReader_QueryInterface(vbreader, &IID_IUnknown, (void**)&unk);
2989 EXPECT_HR(hr, S_OK);
2990 test_obj_dispex(unk);
2991 IUnknown_Release(unk);
2992 IVBSAXXMLReader_Release(vbreader);
2994 ISAXXMLReader_Release(reader);
2997 static void test_mxwriter_dispex(void)
2999 IDispatchEx *dispex;
3004 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
3005 &IID_IMXWriter, (void**)&writer);
3006 EXPECT_HR(hr, S_OK);
3008 hr = IMXWriter_QueryInterface(writer, &IID_IDispatchEx, (void**)&dispex);
3009 EXPECT_HR(hr, S_OK);
3010 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
3011 test_obj_dispex(unk);
3012 IUnknown_Release(unk);
3013 IDispatchEx_Release(dispex);
3015 IMXWriter_Release(writer);
3018 static void test_mxwriter_comment(void)
3020 static const WCHAR commentW[] = {'c','o','m','m','e','n','t',0};
3021 ISAXContentHandler *content;
3022 ISAXLexicalHandler *lexical;
3027 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
3028 &IID_IMXWriter, (void**)&writer);
3029 EXPECT_HR(hr, S_OK);
3031 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
3032 EXPECT_HR(hr, S_OK);
3034 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
3035 EXPECT_HR(hr, S_OK);
3037 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
3038 EXPECT_HR(hr, S_OK);
3040 hr = ISAXContentHandler_startDocument(content);
3041 EXPECT_HR(hr, S_OK);
3043 hr = ISAXLexicalHandler_comment(lexical, NULL, 0);
3044 EXPECT_HR(hr, E_INVALIDARG);
3046 hr = ISAXLexicalHandler_comment(lexical, commentW, 0);
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_("<!---->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3054 VariantClear(&dest);
3056 hr = ISAXLexicalHandler_comment(lexical, commentW, sizeof(commentW)/sizeof(WCHAR)-1);
3057 EXPECT_HR(hr, S_OK);
3059 V_VT(&dest) = VT_EMPTY;
3060 hr = IMXWriter_get_output(writer, &dest);
3061 EXPECT_HR(hr, S_OK);
3062 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3063 ok(!lstrcmpW(_bstr_("<!---->\r\n<!--comment-->\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3064 VariantClear(&dest);
3066 ISAXContentHandler_Release(content);
3067 ISAXLexicalHandler_Release(lexical);
3068 IMXWriter_Release(writer);
3072 static void test_mxwriter_cdata(void)
3074 ISAXContentHandler *content;
3075 ISAXLexicalHandler *lexical;
3080 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
3081 &IID_IMXWriter, (void**)&writer);
3082 EXPECT_HR(hr, S_OK);
3084 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
3085 EXPECT_HR(hr, S_OK);
3087 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
3088 EXPECT_HR(hr, S_OK);
3090 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
3091 EXPECT_HR(hr, S_OK);
3093 hr = ISAXContentHandler_startDocument(content);
3094 EXPECT_HR(hr, S_OK);
3096 hr = ISAXLexicalHandler_startCDATA(lexical);
3097 EXPECT_HR(hr, S_OK);
3099 V_VT(&dest) = VT_EMPTY;
3100 hr = IMXWriter_get_output(writer, &dest);
3101 EXPECT_HR(hr, S_OK);
3102 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3103 ok(!lstrcmpW(_bstr_("<![CDATA["), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3104 VariantClear(&dest);
3106 hr = ISAXLexicalHandler_startCDATA(lexical);
3107 EXPECT_HR(hr, S_OK);
3109 /* all these are escaped for text nodes */
3110 hr = ISAXContentHandler_characters(content, _bstr_("< > & \""), 7);
3111 EXPECT_HR(hr, S_OK);
3113 hr = ISAXLexicalHandler_endCDATA(lexical);
3114 EXPECT_HR(hr, S_OK);
3116 V_VT(&dest) = VT_EMPTY;
3117 hr = IMXWriter_get_output(writer, &dest);
3118 EXPECT_HR(hr, S_OK);
3119 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3120 ok(!lstrcmpW(_bstr_("<![CDATA[<![CDATA[< > & \"]]>"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3121 VariantClear(&dest);
3123 ISAXContentHandler_Release(content);
3124 ISAXLexicalHandler_Release(lexical);
3125 IMXWriter_Release(writer);
3129 static void test_mxwriter_dtd(void)
3131 static const WCHAR contentW[] = {'c','o','n','t','e','n','t'};
3132 static const WCHAR nameW[] = {'n','a','m','e'};
3133 static const WCHAR pubW[] = {'p','u','b'};
3134 static const WCHAR sysW[] = {'s','y','s'};
3135 ISAXContentHandler *content;
3136 ISAXLexicalHandler *lexical;
3137 ISAXDeclHandler *decl;
3142 hr = CoCreateInstance(&CLSID_MXXMLWriter, NULL, CLSCTX_INPROC_SERVER,
3143 &IID_IMXWriter, (void**)&writer);
3144 EXPECT_HR(hr, S_OK);
3146 hr = IMXWriter_QueryInterface(writer, &IID_ISAXContentHandler, (void**)&content);
3147 EXPECT_HR(hr, S_OK);
3149 hr = IMXWriter_QueryInterface(writer, &IID_ISAXLexicalHandler, (void**)&lexical);
3150 EXPECT_HR(hr, S_OK);
3152 hr = IMXWriter_QueryInterface(writer, &IID_ISAXDeclHandler, (void**)&decl);
3153 EXPECT_HR(hr, S_OK);
3155 hr = IMXWriter_put_omitXMLDeclaration(writer, VARIANT_TRUE);
3156 EXPECT_HR(hr, S_OK);
3158 hr = ISAXContentHandler_startDocument(content);
3159 EXPECT_HR(hr, S_OK);
3161 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, NULL, 0);
3162 EXPECT_HR(hr, E_INVALIDARG);
3164 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
3165 EXPECT_HR(hr, E_INVALIDARG);
3167 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, NULL, 0, sysW, sizeof(sysW)/sizeof(WCHAR));
3168 EXPECT_HR(hr, E_INVALIDARG);
3170 hr = ISAXLexicalHandler_startDTD(lexical, NULL, 0, pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
3171 EXPECT_HR(hr, E_INVALIDARG);
3173 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), NULL, 0, NULL, 0);
3174 EXPECT_HR(hr, S_OK);
3176 V_VT(&dest) = VT_EMPTY;
3177 hr = IMXWriter_get_output(writer, &dest);
3178 EXPECT_HR(hr, S_OK);
3179 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3180 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3181 VariantClear(&dest);
3183 /* system id is required if public is present */
3184 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR), pubW, sizeof(pubW)/sizeof(WCHAR), NULL, 0);
3185 EXPECT_HR(hr, E_INVALIDARG);
3187 hr = ISAXLexicalHandler_startDTD(lexical, nameW, sizeof(nameW)/sizeof(WCHAR),
3188 pubW, sizeof(pubW)/sizeof(WCHAR), sysW, sizeof(sysW)/sizeof(WCHAR));
3189 EXPECT_HR(hr, S_OK);
3191 V_VT(&dest) = VT_EMPTY;
3192 hr = IMXWriter_get_output(writer, &dest);
3193 EXPECT_HR(hr, S_OK);
3194 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3195 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3196 "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n"), V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3197 VariantClear(&dest);
3199 hr = ISAXLexicalHandler_endDTD(lexical);
3200 EXPECT_HR(hr, S_OK);
3202 hr = ISAXLexicalHandler_endDTD(lexical);
3203 EXPECT_HR(hr, S_OK);
3205 V_VT(&dest) = VT_EMPTY;
3206 hr = IMXWriter_get_output(writer, &dest);
3207 EXPECT_HR(hr, S_OK);
3208 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3209 ok(!lstrcmpW(_bstr_("<!DOCTYPE name [\r\n<!DOCTYPE name PUBLIC \"pub\""
3210 "<!DOCTYPE name PUBLIC \"pub\" \"sys\" [\r\n]>\r\n]>\r\n"),
3211 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3212 VariantClear(&dest);
3214 /* element declaration */
3215 V_VT(&dest) = VT_EMPTY;
3216 hr = IMXWriter_put_output(writer, dest);
3217 EXPECT_HR(hr, S_OK);
3219 hr = ISAXDeclHandler_elementDecl(decl, NULL, 0, NULL, 0);
3220 EXPECT_HR(hr, E_INVALIDARG);
3222 hr = ISAXDeclHandler_elementDecl(decl, nameW, sizeof(nameW)/sizeof(WCHAR), NULL, 0);
3223 EXPECT_HR(hr, E_INVALIDARG);
3225 hr = ISAXDeclHandler_elementDecl(decl, nameW, sizeof(nameW)/sizeof(WCHAR), contentW, sizeof(contentW)/sizeof(WCHAR));
3226 EXPECT_HR(hr, S_OK);
3228 V_VT(&dest) = VT_EMPTY;
3229 hr = IMXWriter_get_output(writer, &dest);
3230 EXPECT_HR(hr, S_OK);
3231 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3232 ok(!lstrcmpW(_bstr_("<!ELEMENT name content>\r\n"),
3233 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3234 VariantClear(&dest);
3236 V_VT(&dest) = VT_EMPTY;
3237 hr = IMXWriter_put_output(writer, dest);
3238 EXPECT_HR(hr, S_OK);
3240 hr = ISAXDeclHandler_elementDecl(decl, nameW, sizeof(nameW)/sizeof(WCHAR), contentW, 0);
3241 EXPECT_HR(hr, S_OK);
3243 V_VT(&dest) = VT_EMPTY;
3244 hr = IMXWriter_get_output(writer, &dest);
3245 EXPECT_HR(hr, S_OK);
3246 ok(V_VT(&dest) == VT_BSTR, "got %d\n", V_VT(&dest));
3247 ok(!lstrcmpW(_bstr_("<!ELEMENT name >\r\n"),
3248 V_BSTR(&dest)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest)));
3249 VariantClear(&dest);
3251 ISAXContentHandler_Release(content);
3252 ISAXLexicalHandler_Release(lexical);
3253 ISAXDeclHandler_Release(decl);
3254 IMXWriter_Release(writer);
3266 } addattribute_test_t;
3268 static const addattribute_test_t addattribute_data[] = {
3269 { &CLSID_SAXAttributes, NULL, NULL, "ns:qname", NULL, "value", E_INVALIDARG },
3270 { &CLSID_SAXAttributes30, NULL, NULL, "ns:qname", NULL, "value", E_INVALIDARG },
3271 { &CLSID_SAXAttributes40, NULL, NULL, "ns:qname", NULL, "value", E_INVALIDARG },
3272 { &CLSID_SAXAttributes60, NULL, NULL, "ns:qname", NULL, "value", S_OK },
3274 { &CLSID_SAXAttributes, NULL, "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3275 { &CLSID_SAXAttributes30, NULL, "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3276 { &CLSID_SAXAttributes40, NULL, "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3277 { &CLSID_SAXAttributes60, NULL, "qname", "ns:qname", NULL, "value", S_OK },
3279 { &CLSID_SAXAttributes, "uri", "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3280 { &CLSID_SAXAttributes30, "uri", "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3281 { &CLSID_SAXAttributes40, "uri", "qname", "ns:qname", NULL, "value", E_INVALIDARG },
3282 { &CLSID_SAXAttributes60, "uri", "qname", "ns:qname", NULL, "value", S_OK },
3284 { &CLSID_SAXAttributes, "uri", "qname", "ns:qname", "type", "value", S_OK },
3285 { &CLSID_SAXAttributes30, "uri", "qname", "ns:qname", "type", "value", S_OK },
3286 { &CLSID_SAXAttributes40, "uri", "qname", "ns:qname", "type", "value", S_OK },
3287 { &CLSID_SAXAttributes60, "uri", "qname", "ns:qname", "type", "value", S_OK },
3292 static void test_mxattr_addAttribute(void)
3294 const addattribute_test_t *table = addattribute_data;
3297 while (table->clsid)
3299 ISAXAttributes *saxattr;
3300 IMXAttributes *mxattr;
3304 if (!is_clsid_supported(table->clsid, mxattributes_support_data))
3311 hr = CoCreateInstance(table->clsid, NULL, CLSCTX_INPROC_SERVER,
3312 &IID_IMXAttributes, (void**)&mxattr);
3313 EXPECT_HR(hr, S_OK);
3315 hr = IMXAttributes_QueryInterface(mxattr, &IID_ISAXAttributes, (void**)&saxattr);
3317 EXPECT_HR(hr, S_OK);
3320 IMXAttributes_Release(mxattr);
3326 /* SAXAttributes30 and SAXAttributes60 both crash on this test */
3327 if (IsEqualGUID(table->clsid, &CLSID_SAXAttributes) ||
3328 IsEqualGUID(table->clsid, &CLSID_SAXAttributes30))
3330 hr = ISAXAttributes_getLength(saxattr, NULL);
3331 EXPECT_HR(hr, E_POINTER);
3335 hr = ISAXAttributes_getLength(saxattr, &len);
3336 EXPECT_HR(hr, S_OK);
3337 ok(len == 0, "got %d\n", len);
3339 hr = IMXAttributes_addAttribute(mxattr, _bstr_(table->uri), _bstr_(table->local),
3340 _bstr_(table->qname), _bstr_(table->type), _bstr_(table->value));
3341 ok(hr == table->hr, "%d: got 0x%08x, expected 0x%08x\n", i, hr, table->hr);
3344 hr = ISAXAttributes_getLength(saxattr, &len);
3345 EXPECT_HR(hr, S_OK);
3346 if (table->hr == S_OK)
3347 ok(len == 1, "%d: got %d length, expected 0\n", i, len);
3349 ok(len == 0, "%d: got %d length, expected 1\n", i, len);
3351 ISAXAttributes_Release(saxattr);
3352 IMXAttributes_Release(mxattr);
3361 static void test_mxattr_clear(void)
3363 ISAXAttributes *saxattr;
3364 IMXAttributes *mxattr;
3369 hr = CoCreateInstance(&CLSID_SAXAttributes, NULL, CLSCTX_INPROC_SERVER,
3370 &IID_IMXAttributes, (void**)&mxattr);
3371 EXPECT_HR(hr, S_OK);
3373 hr = IMXAttributes_QueryInterface(mxattr, &IID_ISAXAttributes, (void**)&saxattr);
3375 EXPECT_HR(hr, S_OK);
3378 IMXAttributes_Release(mxattr);
3382 hr = ISAXAttributes_getQName(saxattr, 0, NULL, NULL);
3383 EXPECT_HR(hr, E_INVALIDARG);
3385 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, &len);
3386 EXPECT_HR(hr, E_INVALIDARG);
3388 hr = IMXAttributes_addAttribute(mxattr, _bstr_("uri"), _bstr_("local"),
3389 _bstr_("qname"), _bstr_("type"), _bstr_("value"));
3390 EXPECT_HR(hr, S_OK);
3393 hr = ISAXAttributes_getLength(saxattr, &len);
3394 EXPECT_HR(hr, S_OK);
3395 ok(len == 1, "got %d\n", len);
3398 hr = ISAXAttributes_getQName(saxattr, 0, NULL, &len);
3399 EXPECT_HR(hr, E_POINTER);
3400 ok(len == -1, "got %d\n", len);
3402 ptr = (void*)0xdeadbeef;
3403 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, NULL);
3404 EXPECT_HR(hr, E_POINTER);
3405 ok(ptr == (void*)0xdeadbeef, "got %p\n", ptr);
3408 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, &len);
3409 EXPECT_HR(hr, S_OK);
3410 ok(len == 5, "got %d\n", len);
3411 ok(!lstrcmpW(ptr, _bstr_("qname")), "got %s\n", wine_dbgstr_w(ptr));
3413 hr = IMXAttributes_clear(mxattr);
3414 EXPECT_HR(hr, S_OK);
3417 hr = ISAXAttributes_getLength(saxattr, &len);
3418 EXPECT_HR(hr, S_OK);
3419 ok(len == 0, "got %d\n", len);
3422 ptr = (void*)0xdeadbeef;
3423 hr = ISAXAttributes_getQName(saxattr, 0, &ptr, &len);
3424 EXPECT_HR(hr, E_INVALIDARG);
3425 ok(len == -1, "got %d\n", len);
3426 ok(ptr == (void*)0xdeadbeef, "got %p\n", ptr);
3428 IMXAttributes_Release(mxattr);
3429 ISAXAttributes_Release(saxattr);
3433 static void test_mxattr_dispex(void)
3435 IMXAttributes *mxattr;
3436 IDispatchEx *dispex;
3440 hr = CoCreateInstance(&CLSID_SAXAttributes, NULL, CLSCTX_INPROC_SERVER,
3441 &IID_IMXAttributes, (void**)&mxattr);
3442 EXPECT_HR(hr, S_OK);
3444 hr = IMXAttributes_QueryInterface(mxattr, &IID_IDispatchEx, (void**)&dispex);
3445 EXPECT_HR(hr, S_OK);
3446 hr = IDispatchEx_QueryInterface(dispex, &IID_IUnknown, (void**)&unk);
3447 test_obj_dispex(unk);
3448 IUnknown_Release(unk);
3449 IDispatchEx_Release(dispex);
3451 IMXAttributes_Release(mxattr);
3454 START_TEST(saxreader)
3456 ISAXXMLReader *reader;
3459 hr = CoInitialize(NULL);
3460 ok(hr == S_OK, "failed to init com\n");
3462 hr = CoCreateInstance(&CLSID_SAXXMLReader, NULL, CLSCTX_INPROC_SERVER,
3463 &IID_ISAXXMLReader, (void**)&reader);
3467 skip("Failed to create SAXXMLReader instance\n");
3471 ISAXXMLReader_Release(reader);
3476 test_saxreader_properties();
3477 test_saxreader_features();
3481 /* MXXMLWriter tests */
3482 get_mxwriter_support_data(mxwriter_support_data);
3483 if (is_clsid_supported(&CLSID_MXXMLWriter, mxwriter_support_data))
3485 test_mxwriter_handlers();
3486 test_mxwriter_startenddocument();
3487 test_mxwriter_startendelement();
3488 test_mxwriter_characters();
3489 test_mxwriter_comment();
3490 test_mxwriter_cdata();
3491 test_mxwriter_dtd();
3492 test_mxwriter_properties();
3493 test_mxwriter_flush();
3494 test_mxwriter_stream();
3495 test_mxwriter_encoding();
3496 test_mxwriter_dispex();
3499 win_skip("MXXMLWriter not supported\n");
3501 /* SAXAttributes tests */
3502 get_mxattributes_support_data(mxattributes_support_data);
3503 if (is_clsid_supported(&CLSID_SAXAttributes, mxattributes_support_data))
3505 test_mxattr_addAttribute();
3506 test_mxattr_clear();
3507 test_mxattr_dispex();
3510 skip("SAXAttributes not supported\n");