4 * Copyright 2008 Piotr Caban
5 * Copyright 2011 Thomas Mullaly
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 #define EXPECT_HR(hr,hr_exp) \
36 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
38 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
39 static void _expect_ref(IUnknown
* obj
, ULONG ref
, int line
)
41 ULONG rc
= IUnknown_AddRef(obj
);
42 IUnknown_Release(obj
);
43 ok_(__FILE__
,line
)(rc
-1 == ref
, "expected refcount %d, got %d\n", ref
, rc
-1);
46 static BSTR
alloc_str_from_narrow(const char *str
)
48 int len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
49 BSTR ret
= SysAllocStringLen(NULL
, len
- 1); /* NUL character added automatically */
50 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
54 static BSTR alloced_bstrs
[512];
55 static int alloced_bstrs_count
;
57 static BSTR
_bstr_(const char *str
)
59 assert(alloced_bstrs_count
< sizeof(alloced_bstrs
)/sizeof(alloced_bstrs
[0]));
60 alloced_bstrs
[alloced_bstrs_count
] = alloc_str_from_narrow(str
);
61 return alloced_bstrs
[alloced_bstrs_count
++];
64 static void free_bstrs(void)
67 for (i
= 0; i
< alloced_bstrs_count
; i
++)
68 SysFreeString(alloced_bstrs
[i
]);
69 alloced_bstrs_count
= 0;
74 CH_PUTDOCUMENTLOCATOR
,
77 CH_STARTPREFIXMAPPING
,
82 CH_IGNORABLEWHITESPACE
,
83 CH_PROCESSINGINSTRUCTION
,
90 static const WCHAR szSimpleXML
[] = {
91 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','\"','1','.','0','\"',' ','?','>','\n',
92 '<','B','a','n','k','A','c','c','o','u','n','t','>','\n',
93 ' ',' ',' ','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\n',
94 ' ',' ',' ','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\n',
95 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\n','\0'
98 static const WCHAR szCarriageRetTest
[] = {
99 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"','?','>','\r','\n',
100 '<','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n',
101 '\t','<','N','u','m','b','e','r','>','1','2','3','4','<','/','N','u','m','b','e','r','>','\r','\n',
102 '\t','<','N','a','m','e','>','C','a','p','t','a','i','n',' ','A','h','a','b','<','/','N','a','m','e','>','\r','\n',
103 '<','/','B','a','n','k','A','c','c','o','u','n','t','>','\r','\n','\0'
106 static const WCHAR szUtf16XML
[] = {
107 '<','?','x','m','l',' ','v','e','r','s','i','o','n','=','"','1','.','0','"',' ',
108 'e','n','c','o','d','i','n','g','=','"','U','T','F','-','1','6','"',' ',
109 's','t','a','n','d','a','l','o','n','e','=','"','n','o','"','?','>','\r','\n'
112 static const CHAR szUtf16BOM
[] = {0xff, 0xfe};
114 static const CHAR szUtf8XML
[] =
115 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n";
117 static const CHAR szTestXML
[] =
118 "<?xml version=\"1.0\" ?>\n"
120 " <Number>1234</Number>\n"
121 " <Name>Captain Ahab</Name>\n"
124 static const CHAR szTestAttributes
[] =
125 "<?xml version=\"1.0\" ?>\n"
126 "<document xmlns:test=\"prefix_test\" xmlns=\"prefix\" test:arg1=\"arg1\" arg2=\"arg2\" test:ar3=\"arg3\">\n"
127 "<node1 xmlns:p=\"test\" />"
130 typedef struct _contenthandlercheck
{
140 } content_handler_test
;
142 static content_handler_test contentHandlerTest1
[] = {
143 { CH_PUTDOCUMENTLOCATOR
, 0, 0, 1, 0 },
144 { CH_STARTDOCUMENT
, 0, 0, 1, 22 },
145 { CH_STARTELEMENT
, 2, 14, 2, 13, "", "BankAccount", "BankAccount" },
146 { CH_CHARACTERS
, 2, 14, 3, 4, "\n " },
147 { CH_STARTELEMENT
, 3, 12, 3, 11, "", "Number", "Number" },
148 { CH_CHARACTERS
, 3, 12, 3, 16, "1234" },
149 { CH_ENDELEMENT
, 3, 18, 3, 24, "", "Number", "Number" },
150 { CH_CHARACTERS
, 3, 25, 4, 4, "\n " },
151 { CH_STARTELEMENT
, 4, 10, 4, 9, "", "Name", "Name" },
152 { CH_CHARACTERS
, 4, 10, 4, 22, "Captain Ahab" },
153 { CH_ENDELEMENT
, 4, 24, 4, 28, "", "Name", "Name" },
154 { CH_CHARACTERS
, 4, 29, 5, 1, "\n" },
155 { CH_ENDELEMENT
, 5, 3, 5, 14, "", "BankAccount", "BankAccount" },
156 { CH_ENDDOCUMENT
, 0, 0, 6, 0 },
160 static content_handler_test contentHandlerTest2
[] = {
161 { CH_PUTDOCUMENTLOCATOR
, 0, 0, 1, 0 },
162 { CH_STARTDOCUMENT
, 0, 0, 1, 21 },
163 { CH_STARTELEMENT
, 2, 14, 2, 13, "", "BankAccount", "BankAccount" },
164 { CH_CHARACTERS
, 2, 14, 3, 0, "\n" },
165 { CH_CHARACTERS
, 2, 16, 3, 2, "\t" },
166 { CH_STARTELEMENT
, 3, 10, 3, 9, "", "Number", "Number" },
167 { CH_CHARACTERS
, 3, 10, 3, 14, "1234" },
168 { CH_ENDELEMENT
, 3, 16, 3, 22, "", "Number", "Number" },
169 { CH_CHARACTERS
, 3, 23, 4, 0, "\n" },
170 { CH_CHARACTERS
, 3, 25, 4, 2, "\t" },
171 { CH_STARTELEMENT
, 4, 8, 4, 7, "", "Name", "Name" },
172 { CH_CHARACTERS
, 4, 8, 4, 20, "Captain Ahab" },
173 { CH_ENDELEMENT
, 4, 22, 4, 26, "", "Name", "Name" },
174 { CH_CHARACTERS
, 4, 27, 5, 0, "\n" },
175 { CH_ENDELEMENT
, 5, 3, 5, 14, "", "BankAccount", "BankAccount" },
176 { CH_ENDDOCUMENT
, 0, 0, 6, 0 },
180 static content_handler_test contentHandlerTestError
[] = {
181 { CH_PUTDOCUMENTLOCATOR
, 0, 0, 1, 0, NULL
, NULL
, NULL
, E_FAIL
},
182 { EH_FATALERROR
, 0, 0, 0, 0, NULL
, NULL
, NULL
, E_FAIL
},
186 static content_handler_test contentHandlerTestCallbackResults
[] = {
187 { CH_PUTDOCUMENTLOCATOR
, 0, 0, 1, 0, NULL
, NULL
, NULL
, S_FALSE
},
188 { CH_STARTDOCUMENT
, 0, 0, 1, 22, NULL
, NULL
, NULL
, S_FALSE
},
189 { EH_FATALERROR
, 0, 0, 0, 0, NULL
, NULL
, NULL
, S_FALSE
},
193 static content_handler_test contentHandlerTestCallbackResult6
[] = {
194 { CH_PUTDOCUMENTLOCATOR
, 0, 0, 1, 0, NULL
, NULL
, NULL
, S_FALSE
},
195 { CH_STARTDOCUMENT
, 0, 0, 1, 22, NULL
, NULL
, NULL
, S_FALSE
},
196 { CH_STARTELEMENT
, 2, 14, 2, 13, "", "BankAccount", "BankAccount", S_FALSE
},
197 { CH_CHARACTERS
, 2, 14, 3, 4, "\n ", NULL
, NULL
, S_FALSE
},
198 { CH_STARTELEMENT
, 3, 12, 3, 11, "", "Number", "Number", S_FALSE
},
199 { CH_CHARACTERS
, 3, 12, 3, 16, "1234", NULL
, NULL
, S_FALSE
},
200 { CH_ENDELEMENT
, 3, 18, 3, 24, "", "Number", "Number", S_FALSE
},
201 { CH_CHARACTERS
, 3, 25, 4, 4, "\n ", NULL
, NULL
, S_FALSE
},
202 { CH_STARTELEMENT
, 4, 10, 4, 9, "", "Name", "Name", S_FALSE
},
203 { CH_CHARACTERS
, 4, 10, 4, 22, "Captain Ahab", NULL
, NULL
, S_FALSE
},
204 { CH_ENDELEMENT
, 4, 24, 4, 28, "", "Name", "Name", S_FALSE
},
205 { CH_CHARACTERS
, 4, 29, 5, 1, "\n", NULL
, NULL
, S_FALSE
},
206 { CH_ENDELEMENT
, 5, 3, 5, 14, "", "BankAccount", "BankAccount", S_FALSE
},
207 { CH_ENDDOCUMENT
, 0, 0, 6, 0, NULL
, NULL
, NULL
, S_FALSE
},
211 static content_handler_test contentHandlerTestAttributes
[] = {
212 { CH_PUTDOCUMENTLOCATOR
, 0, 0, 1, 0 },
213 { CH_STARTDOCUMENT
, 0, 0, 1, 22 },
214 { CH_STARTPREFIXMAPPING
, 2, 96, 2, 95, "test", "prefix_test" },
215 { CH_STARTPREFIXMAPPING
, 2, 96, 2, 95, "", "prefix" },
216 { CH_STARTELEMENT
, 2, 96, 2, 95, "prefix", "document", "document" },
217 { CH_CHARACTERS
, 2, 96, 3, 1, "\n" },
218 { CH_STARTPREFIXMAPPING
, 3, 25, 3, 24, "p", "test" },
219 { CH_STARTELEMENT
, 3, 25, 3, 24, "prefix", "node1", "node1" },
220 { CH_ENDELEMENT
, 3, 25, 3, 24, "prefix", "node1", "node1" },
221 { CH_ENDPREFIXMAPPING
, 3, 25, 3, 24, "p" },
222 { CH_ENDELEMENT
, 3, 27, 3, 35, "prefix", "document", "document" },
223 { CH_ENDPREFIXMAPPING
, 3, 27, 3, 35, "" },
224 { CH_ENDPREFIXMAPPING
, 3, 27, 3, 35, "test" },
225 { CH_ENDDOCUMENT
, 0, 0, 4, 0 },
229 static content_handler_test contentHandlerTestAttributes6
[] = {
230 { CH_PUTDOCUMENTLOCATOR
, 0, 0, 1, 0 },
231 { CH_STARTDOCUMENT
, 0, 0, 1, 22 },
232 { CH_STARTPREFIXMAPPING
, 2, 96, 2, 95, "test", "prefix_test" },
233 { CH_STARTPREFIXMAPPING
, 2, 96, 2, 95, "", "prefix" },
234 { CH_STARTELEMENT
, 2, 96, 2, 95, "prefix", "document", "document" },
235 { CH_CHARACTERS
, 2, 96, 3, 1, "\n" },
236 { CH_STARTPREFIXMAPPING
, 3, 25, 3, 24, "p", "test" },
237 { CH_STARTELEMENT
, 3, 25, 3, 24, "prefix", "node1", "node1" },
238 { CH_ENDELEMENT
, 3, 25, 3, 24, "prefix", "node1", "node1" },
239 { CH_ENDPREFIXMAPPING
, 3, 25, 3, 24, "p" },
240 { CH_ENDELEMENT
, 3, 27, 3, 35, "prefix", "document", "document" },
241 { CH_ENDPREFIXMAPPING
, 3, 27, 3, 35, "test" },
242 { CH_ENDPREFIXMAPPING
, 3, 27, 3, 35, "" },
243 { CH_ENDDOCUMENT
, 0, 0, 4, 0 },
247 static content_handler_test
*expectCall
;
248 static ISAXLocator
*locator
;
251 static void test_saxstr(unsigned line
, const WCHAR
*szStr
, int nStr
, const char *szTest
)
257 ok_(__FILE__
,line
) (szStr
== NULL
, "szStr != NULL\n");
258 ok_(__FILE__
,line
) (nStr
== 0, "nStr = %d, expected 0\n", nStr
);
262 len
= strlen(szTest
);
263 ok_(__FILE__
,line
) (len
== nStr
, "nStr = %d, expected %d (%s)\n", nStr
, len
, szTest
);
267 MultiByteToWideChar(CP_ACP
, 0, szTest
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
268 ok_(__FILE__
,line
) (!memcmp(szStr
, buf
, len
*sizeof(WCHAR
)), "unexpected szStr %s, expected %s\n",
269 wine_dbgstr_wn(szStr
, nStr
), szTest
);
272 static BOOL
test_expect_call(CH id
)
274 ok(expectCall
->id
== id
, "unexpected call %d, expected %d\n", id
, expectCall
->id
);
275 return expectCall
->id
== id
;
278 static void test_locator(unsigned line
, int loc_line
, int loc_column
)
281 ISAXLocator_getLineNumber(locator
, &rline
);
282 ISAXLocator_getColumnNumber(locator
, &rcolumn
);
284 ok_(__FILE__
,line
) (rline
== loc_line
,
285 "unexpected line %d, expected %d\n", rline
, loc_line
);
286 ok_(__FILE__
,line
) (rcolumn
== loc_column
,
287 "unexpected column %d, expected %d\n", rcolumn
, loc_column
);
290 static HRESULT WINAPI
contentHandler_QueryInterface(
291 ISAXContentHandler
* iface
,
297 if(IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISAXContentHandler
))
303 return E_NOINTERFACE
;
309 static ULONG WINAPI
contentHandler_AddRef(
310 ISAXContentHandler
* iface
)
315 static ULONG WINAPI
contentHandler_Release(
316 ISAXContentHandler
* iface
)
321 static HRESULT WINAPI
contentHandler_putDocumentLocator(
322 ISAXContentHandler
* iface
,
323 ISAXLocator
*pLocator
)
325 ISAXAttributes
*attr
;
328 if(!test_expect_call(CH_PUTDOCUMENTLOCATOR
))
332 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
333 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
335 if(msxml_version
>= 6) {
336 hres
= ISAXLocator_QueryInterface(pLocator
, &IID_ISAXAttributes
, (void**)&attr
);
337 ok(hres
== S_OK
, "QueryInterface failed: %x\n", hres
);
338 ISAXAttributes_Release(attr
);
341 return (expectCall
++)->ret
;
344 static ISAXAttributes
*test_attr_ptr
;
345 static HRESULT WINAPI
contentHandler_startDocument(
346 ISAXContentHandler
* iface
)
348 if(!test_expect_call(CH_STARTDOCUMENT
))
351 test_attr_ptr
= NULL
;
352 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
353 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
355 return (expectCall
++)->ret
;
358 static HRESULT WINAPI
contentHandler_endDocument(
359 ISAXContentHandler
* iface
)
361 if(!test_expect_call(CH_ENDDOCUMENT
))
364 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
365 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
367 return (expectCall
++)->ret
;
370 static HRESULT WINAPI
contentHandler_startPrefixMapping(
371 ISAXContentHandler
* iface
,
372 const WCHAR
*pPrefix
,
377 if(!test_expect_call(CH_STARTPREFIXMAPPING
))
380 test_saxstr(__LINE__
, pPrefix
, nPrefix
, expectCall
->arg1
);
381 test_saxstr(__LINE__
, pUri
, nUri
, expectCall
->arg2
);
382 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
383 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
385 return (expectCall
++)->ret
;
388 static HRESULT WINAPI
contentHandler_endPrefixMapping(
389 ISAXContentHandler
* iface
,
390 const WCHAR
*pPrefix
,
393 if(!test_expect_call(CH_ENDPREFIXMAPPING
))
396 test_saxstr(__LINE__
, pPrefix
, nPrefix
, expectCall
->arg1
);
397 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
398 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
400 return (expectCall
++)->ret
;
403 static HRESULT WINAPI
contentHandler_startElement(
404 ISAXContentHandler
* iface
,
405 const WCHAR
*pNamespaceUri
,
407 const WCHAR
*pLocalName
,
411 ISAXAttributes
*pAttr
)
416 if(!test_expect_call(CH_STARTELEMENT
))
419 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, expectCall
->arg1
);
420 test_saxstr(__LINE__
, pLocalName
, nLocalName
, expectCall
->arg2
);
421 test_saxstr(__LINE__
, pQName
, nQName
, expectCall
->arg3
);
422 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
423 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
426 test_attr_ptr
= pAttr
;
427 ok(test_attr_ptr
== pAttr
, "Multiple ISAXAttributes instances are used (%p %p)\n", test_attr_ptr
, pAttr
);
429 if(expectCall
== contentHandlerTestAttributes
+4) {
430 const WCHAR
*uri_ptr
= NULL
;
432 /* msxml3 returns attributes and namespaces in the input order */
433 hres
= ISAXAttributes_getLength(pAttr
, &len
);
434 ok(hres
== S_OK
, "getLength returned %x\n", hres
);
435 ok(len
== 5, "Incorrect number of attributes: %d\n", len
);
436 ok(msxml_version
< 6, "wrong msxml_version: %d\n", msxml_version
);
438 for(i
=0; i
<len
; i
++) {
439 hres
= ISAXAttributes_getName(pAttr
, i
, &pNamespaceUri
, &nNamespaceUri
,
440 &pLocalName
, &nLocalName
, &pQName
, &nQName
);
441 ok(hres
== S_OK
, "getName returned %x\n", hres
);
444 todo_wine
ok(i
==3, "Incorrect attributes order\n");
445 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "");
446 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "arg2");
447 test_saxstr(__LINE__
, pQName
, nQName
, "arg2");
448 } else if(nQName
== 5) {
449 todo_wine
ok(i
==1, "Incorrect attributes order\n");
450 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "");
451 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "");
452 test_saxstr(__LINE__
, pQName
, nQName
, "xmlns");
453 } else if(nQName
== 8) {
454 todo_wine
ok(i
==4, "Incorrect attributes order\n");
455 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "prefix_test");
456 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "ar3");
457 test_saxstr(__LINE__
, pQName
, nQName
, "test:ar3");
458 ok(uri_ptr
== pNamespaceUri
, "Incorrect NamespaceUri pointer\n");
459 } else if(nQName
== 9) {
460 todo_wine
ok(i
==2, "Incorrect attributes order\n");
461 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "prefix_test");
462 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "arg1");
463 test_saxstr(__LINE__
, pQName
, nQName
, "test:arg1");
464 uri_ptr
= pNamespaceUri
;
465 } else if(nQName
== 10) {
466 todo_wine
ok(i
==0, "Incorrect attributes order\n");
467 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "");
468 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "");
469 test_saxstr(__LINE__
, pQName
, nQName
, "xmlns:test");
471 ok(0, "Unexpected attribute\n");
474 } else if(expectCall
== contentHandlerTestAttributes6
+4) {
475 const WCHAR
*uri_ptr
;
477 /* msxml6 returns attributes first and then namespaces */
478 hres
= ISAXAttributes_getLength(pAttr
, &len
);
479 ok(hres
== S_OK
, "getLength returned %x\n", hres
);
480 ok(len
== 5, "Incorrect number of attributes: %d\n", len
);
481 ok(msxml_version
>= 6, "wrong msxml_version: %d\n", msxml_version
);
483 hres
= ISAXAttributes_getName(pAttr
, 0, &pNamespaceUri
, &nNamespaceUri
,
484 &pLocalName
, &nLocalName
, &pQName
, &nQName
);
485 ok(hres
== S_OK
, "getName returned %x\n", hres
);
486 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "prefix_test");
487 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "arg1");
488 test_saxstr(__LINE__
, pQName
, nQName
, "test:arg1");
489 uri_ptr
= pNamespaceUri
;
491 hres
= ISAXAttributes_getName(pAttr
, 1, &pNamespaceUri
, &nNamespaceUri
,
492 &pLocalName
, &nLocalName
, &pQName
, &nQName
);
493 ok(hres
== S_OK
, "getName returned %x\n", hres
);
494 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "");
495 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "arg2");
496 test_saxstr(__LINE__
, pQName
, nQName
, "arg2");
498 hres
= ISAXAttributes_getName(pAttr
, 2, &pNamespaceUri
, &nNamespaceUri
,
499 &pLocalName
, &nLocalName
, &pQName
, &nQName
);
500 ok(hres
== S_OK
, "getName returned %x\n", hres
);
501 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "prefix_test");
502 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "ar3");
503 test_saxstr(__LINE__
, pQName
, nQName
, "test:ar3");
504 ok(uri_ptr
== pNamespaceUri
, "Incorrect NamespaceUri pointer\n");
506 hres
= ISAXAttributes_getName(pAttr
, 3, &pNamespaceUri
, &nNamespaceUri
,
507 &pLocalName
, &nLocalName
, &pQName
, &nQName
);
508 ok(hres
== S_OK
, "getName returned %x\n", hres
);
509 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "http://www.w3.org/2000/xmlns/");
510 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "");
511 test_saxstr(__LINE__
, pQName
, nQName
, "xmlns:test");
513 hres
= ISAXAttributes_getName(pAttr
, 4, &pNamespaceUri
, &nNamespaceUri
,
514 &pLocalName
, &nLocalName
, &pQName
, &nQName
);
515 ok(hres
== S_OK
, "getName returned %x\n", hres
);
516 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, "http://www.w3.org/2000/xmlns/");
517 test_saxstr(__LINE__
, pLocalName
, nLocalName
, "");
518 test_saxstr(__LINE__
, pQName
, nQName
, "xmlns");
521 return (expectCall
++)->ret
;
524 static HRESULT WINAPI
contentHandler_endElement(
525 ISAXContentHandler
* iface
,
526 const WCHAR
*pNamespaceUri
,
528 const WCHAR
*pLocalName
,
533 if(!test_expect_call(CH_ENDELEMENT
))
536 test_saxstr(__LINE__
, pNamespaceUri
, nNamespaceUri
, expectCall
->arg1
);
537 test_saxstr(__LINE__
, pLocalName
, nLocalName
, expectCall
->arg2
);
538 test_saxstr(__LINE__
, pQName
, nQName
, expectCall
->arg3
);
539 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
540 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
542 return (expectCall
++)->ret
;
545 static HRESULT WINAPI
contentHandler_characters(
546 ISAXContentHandler
* iface
,
550 if(!test_expect_call(CH_CHARACTERS
))
553 test_saxstr(__LINE__
, pChars
, nChars
, expectCall
->arg1
);
554 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
555 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
557 return (expectCall
++)->ret
;
560 static HRESULT WINAPI
contentHandler_ignorableWhitespace(
561 ISAXContentHandler
* iface
,
565 if(!test_expect_call(CH_IGNORABLEWHITESPACE
))
568 test_saxstr(__LINE__
, pChars
, nChars
, expectCall
->arg1
);
569 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
570 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
572 return (expectCall
++)->ret
;
575 static HRESULT WINAPI
contentHandler_processingInstruction(
576 ISAXContentHandler
* iface
,
577 const WCHAR
*pTarget
,
582 if(!test_expect_call(CH_PROCESSINGINSTRUCTION
))
585 test_saxstr(__LINE__
, pTarget
, nTarget
, expectCall
->arg1
);
586 test_saxstr(__LINE__
, pData
, nData
, expectCall
->arg2
);
587 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
588 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
590 return (expectCall
++)->ret
;
593 static HRESULT WINAPI
contentHandler_skippedEntity(
594 ISAXContentHandler
* iface
,
598 if(!test_expect_call(CH_SKIPPEDENTITY
))
601 test_saxstr(__LINE__
, pName
, nName
, expectCall
->arg1
);
602 test_locator(__LINE__
, msxml_version
>=6 ? expectCall
->line_v6
: expectCall
->line
,
603 msxml_version
>=6 ? expectCall
->column_v6
: expectCall
->column
);
605 return (expectCall
++)->ret
;
609 static const ISAXContentHandlerVtbl contentHandlerVtbl
=
611 contentHandler_QueryInterface
,
612 contentHandler_AddRef
,
613 contentHandler_Release
,
614 contentHandler_putDocumentLocator
,
615 contentHandler_startDocument
,
616 contentHandler_endDocument
,
617 contentHandler_startPrefixMapping
,
618 contentHandler_endPrefixMapping
,
619 contentHandler_startElement
,
620 contentHandler_endElement
,
621 contentHandler_characters
,
622 contentHandler_ignorableWhitespace
,
623 contentHandler_processingInstruction
,
624 contentHandler_skippedEntity
627 static ISAXContentHandler contentHandler
= { &contentHandlerVtbl
};
629 static HRESULT WINAPI
isaxerrorHandler_QueryInterface(
630 ISAXErrorHandler
* iface
,
636 if(IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISAXErrorHandler
))
642 return E_NOINTERFACE
;
648 static ULONG WINAPI
isaxerrorHandler_AddRef(
649 ISAXErrorHandler
* iface
)
654 static ULONG WINAPI
isaxerrorHandler_Release(
655 ISAXErrorHandler
* iface
)
660 static HRESULT WINAPI
isaxerrorHandler_error(
661 ISAXErrorHandler
* iface
,
662 ISAXLocator
*pLocator
,
663 const WCHAR
*pErrorMessage
,
666 ok(0, "unexpected call\n");
670 static HRESULT WINAPI
isaxerrorHandler_fatalError(
671 ISAXErrorHandler
* iface
,
672 ISAXLocator
*pLocator
,
673 const WCHAR
*pErrorMessage
,
676 if(!test_expect_call(EH_FATALERROR
))
679 ok(hrErrorCode
== expectCall
->ret
, "hrErrorCode = %x, expected %x\n", hrErrorCode
, expectCall
->ret
);
685 static HRESULT WINAPI
isaxerrorHanddler_ignorableWarning(
686 ISAXErrorHandler
* iface
,
687 ISAXLocator
*pLocator
,
688 const WCHAR
*pErrorMessage
,
691 ok(0, "unexpected call\n");
695 static const ISAXErrorHandlerVtbl errorHandlerVtbl
=
697 isaxerrorHandler_QueryInterface
,
698 isaxerrorHandler_AddRef
,
699 isaxerrorHandler_Release
,
700 isaxerrorHandler_error
,
701 isaxerrorHandler_fatalError
,
702 isaxerrorHanddler_ignorableWarning
705 static ISAXErrorHandler errorHandler
= { &errorHandlerVtbl
};
707 static HRESULT WINAPI
isaxattributes_QueryInterface(
708 ISAXAttributes
* iface
,
714 if(IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISAXAttributes
))
720 return E_NOINTERFACE
;
726 static ULONG WINAPI
isaxattributes_AddRef(ISAXAttributes
* iface
)
731 static ULONG WINAPI
isaxattributes_Release(ISAXAttributes
* iface
)
736 static HRESULT WINAPI
isaxattributes_getLength(ISAXAttributes
* iface
, int *length
)
742 static HRESULT WINAPI
isaxattributes_getURI(
743 ISAXAttributes
* iface
,
748 ok(0, "unexpected call\n");
752 static HRESULT WINAPI
isaxattributes_getLocalName(
753 ISAXAttributes
* iface
,
755 const WCHAR
**pLocalName
,
756 int *pLocalNameLength
)
758 ok(0, "unexpected call\n");
762 static HRESULT WINAPI
isaxattributes_getQName(
763 ISAXAttributes
* iface
,
765 const WCHAR
**pQName
,
768 static const WCHAR attr1W
[] = {'a',':','a','t','t','r','1','j','u','n','k',0};
769 static const WCHAR attr2W
[] = {'a','t','t','r','2','j','u','n','k',0};
771 ok(nIndex
== 0 || nIndex
== 1, "invalid index received %d\n", nIndex
);
773 *pQName
= (nIndex
== 0) ? attr1W
: attr2W
;
774 *pQNameLength
= (nIndex
== 0) ? 7 : 5;
779 static HRESULT WINAPI
isaxattributes_getName(
780 ISAXAttributes
* iface
,
784 const WCHAR
** pLocalName
,
785 int * pLocalNameSize
,
786 const WCHAR
** pQName
,
789 ok(0, "unexpected call\n");
793 static HRESULT WINAPI
isaxattributes_getIndexFromName(
794 ISAXAttributes
* iface
,
797 const WCHAR
* pLocalName
,
801 ok(0, "unexpected call\n");
805 static HRESULT WINAPI
isaxattributes_getIndexFromQName(
806 ISAXAttributes
* iface
,
807 const WCHAR
* pQName
,
811 ok(0, "unexpected call\n");
815 static HRESULT WINAPI
isaxattributes_getType(
816 ISAXAttributes
* iface
,
818 const WCHAR
** pType
,
821 ok(0, "unexpected call\n");
825 static HRESULT WINAPI
isaxattributes_getTypeFromName(
826 ISAXAttributes
* iface
,
829 const WCHAR
* pLocalName
,
831 const WCHAR
** pType
,
834 ok(0, "unexpected call\n");
838 static HRESULT WINAPI
isaxattributes_getTypeFromQName(
839 ISAXAttributes
* iface
,
840 const WCHAR
* pQName
,
842 const WCHAR
** pType
,
845 ok(0, "unexpected call\n");
849 static HRESULT WINAPI
isaxattributes_getValue(
850 ISAXAttributes
* iface
,
852 const WCHAR
** pValue
,
855 static const WCHAR attrval1W
[] = {'a','1','j','u','n','k',0};
856 static const WCHAR attrval2W
[] = {'a','2','j','u','n','k',0};
858 ok(nIndex
== 0 || nIndex
== 1, "invalid index received %d\n", nIndex
);
860 *pValue
= (nIndex
== 0) ? attrval1W
: attrval2W
;
866 static HRESULT WINAPI
isaxattributes_getValueFromName(
867 ISAXAttributes
* iface
,
870 const WCHAR
* pLocalName
,
872 const WCHAR
** pValue
,
875 ok(0, "unexpected call\n");
879 static HRESULT WINAPI
isaxattributes_getValueFromQName(
880 ISAXAttributes
* iface
,
881 const WCHAR
* pQName
,
883 const WCHAR
** pValue
,
886 ok(0, "unexpected call\n");
890 static const ISAXAttributesVtbl SAXAttributesVtbl
=
892 isaxattributes_QueryInterface
,
893 isaxattributes_AddRef
,
894 isaxattributes_Release
,
895 isaxattributes_getLength
,
896 isaxattributes_getURI
,
897 isaxattributes_getLocalName
,
898 isaxattributes_getQName
,
899 isaxattributes_getName
,
900 isaxattributes_getIndexFromName
,
901 isaxattributes_getIndexFromQName
,
902 isaxattributes_getType
,
903 isaxattributes_getTypeFromName
,
904 isaxattributes_getTypeFromQName
,
905 isaxattributes_getValue
,
906 isaxattributes_getValueFromName
,
907 isaxattributes_getValueFromQName
910 static ISAXAttributes saxattributes
= { &SAXAttributesVtbl
};
912 static int handler_addrefcalled
;
914 static HRESULT WINAPI
isaxlexical_QueryInterface(ISAXLexicalHandler
* iface
, REFIID riid
, void **ppvObject
)
918 if(IsEqualGUID(riid
, &IID_IUnknown
) ||
919 IsEqualGUID(riid
, &IID_ISAXLexicalHandler
))
925 return E_NOINTERFACE
;
931 static ULONG WINAPI
isaxlexical_AddRef(ISAXLexicalHandler
* iface
)
933 handler_addrefcalled
++;
937 static ULONG WINAPI
isaxlexical_Release(ISAXLexicalHandler
* iface
)
942 static HRESULT WINAPI
isaxlexical_startDTD(ISAXLexicalHandler
* iface
,
943 const WCHAR
* pName
, int nName
, const WCHAR
* pPublicId
,
944 int nPublicId
, const WCHAR
* pSystemId
, int nSystemId
)
946 ok(0, "call not expected\n");
950 static HRESULT WINAPI
isaxlexical_endDTD(ISAXLexicalHandler
* iface
)
952 ok(0, "call not expected\n");
956 static HRESULT WINAPI
isaxlexical_startEntity(ISAXLexicalHandler
*iface
,
957 const WCHAR
* pName
, int nName
)
959 ok(0, "call not expected\n");
963 static HRESULT WINAPI
isaxlexical_endEntity(ISAXLexicalHandler
*iface
,
964 const WCHAR
* pName
, int nName
)
966 ok(0, "call not expected\n");
970 static HRESULT WINAPI
isaxlexical_startCDATA(ISAXLexicalHandler
*iface
)
972 ok(0, "call not expected\n");
976 static HRESULT WINAPI
isaxlexical_endCDATA(ISAXLexicalHandler
*iface
)
978 ok(0, "call not expected\n");
982 static HRESULT WINAPI
isaxlexical_comment(ISAXLexicalHandler
*iface
,
983 const WCHAR
* pChars
, int nChars
)
985 ok(0, "call not expected\n");
989 static const ISAXLexicalHandlerVtbl SAXLexicalHandlerVtbl
=
991 isaxlexical_QueryInterface
,
994 isaxlexical_startDTD
,
996 isaxlexical_startEntity
,
997 isaxlexical_endEntity
,
998 isaxlexical_startCDATA
,
999 isaxlexical_endCDATA
,
1003 static ISAXLexicalHandler saxlexicalhandler
= { &SAXLexicalHandlerVtbl
};
1005 static HRESULT WINAPI
isaxdecl_QueryInterface(ISAXDeclHandler
* iface
, REFIID riid
, void **ppvObject
)
1009 if(IsEqualGUID(riid
, &IID_IUnknown
) ||
1010 IsEqualGUID(riid
, &IID_ISAXDeclHandler
))
1016 return E_NOINTERFACE
;
1022 static ULONG WINAPI
isaxdecl_AddRef(ISAXDeclHandler
* iface
)
1024 handler_addrefcalled
++;
1028 static ULONG WINAPI
isaxdecl_Release(ISAXDeclHandler
* iface
)
1033 static HRESULT WINAPI
isaxdecl_elementDecl(ISAXDeclHandler
* iface
,
1034 const WCHAR
* pName
, int nName
, const WCHAR
* pModel
, int nModel
)
1036 ok(0, "call not expected\n");
1040 static HRESULT WINAPI
isaxdecl_attributeDecl(ISAXDeclHandler
* iface
,
1041 const WCHAR
* pElementName
, int nElementName
, const WCHAR
* pAttributeName
,
1042 int nAttributeName
, const WCHAR
* pType
, int nType
, const WCHAR
* pValueDefault
,
1043 int nValueDefault
, const WCHAR
* pValue
, int nValue
)
1045 ok(0, "call not expected\n");
1049 static HRESULT WINAPI
isaxdecl_internalEntityDecl(ISAXDeclHandler
* iface
,
1050 const WCHAR
* pName
, int nName
, const WCHAR
* pValue
, int nValue
)
1052 ok(0, "call not expected\n");
1056 static HRESULT WINAPI
isaxdecl_externalEntityDecl(ISAXDeclHandler
* iface
,
1057 const WCHAR
* pName
, int nName
, const WCHAR
* pPublicId
, int nPublicId
,
1058 const WCHAR
* pSystemId
, int nSystemId
)
1060 ok(0, "call not expected\n");
1064 static const ISAXDeclHandlerVtbl SAXDeclHandlerVtbl
=
1066 isaxdecl_QueryInterface
,
1069 isaxdecl_elementDecl
,
1070 isaxdecl_attributeDecl
,
1071 isaxdecl_internalEntityDecl
,
1072 isaxdecl_externalEntityDecl
1075 static ISAXDeclHandler saxdeclhandler
= { &SAXDeclHandlerVtbl
};
1077 typedef struct mxwriter_write_test_t
{
1083 } mxwriter_write_test
;
1085 typedef struct mxwriter_stream_test_t
{
1087 const char *encoding
;
1088 mxwriter_write_test expected_writes
[4];
1089 } mxwriter_stream_test
;
1091 static const mxwriter_write_test
*current_write_test
;
1092 static DWORD current_stream_test_index
;
1094 static HRESULT WINAPI
istream_QueryInterface(IStream
*iface
, REFIID riid
, void **ppvObject
)
1098 if(IsEqualGUID(riid
, &IID_IStream
) || IsEqualGUID(riid
, &IID_IUnknown
))
1101 return E_NOINTERFACE
;
1106 static ULONG WINAPI
istream_AddRef(IStream
*iface
)
1111 static ULONG WINAPI
istream_Release(IStream
*iface
)
1116 static HRESULT WINAPI
istream_Read(IStream
*iface
, void *pv
, ULONG cb
, ULONG
*pcbRead
)
1118 ok(0, "unexpected call\n");
1122 static HRESULT WINAPI
istream_Write(IStream
*iface
, const void *pv
, ULONG cb
, ULONG
*pcbWritten
)
1126 ok(pv
!= NULL
, "pv == NULL\n");
1128 if(current_write_test
->last
) {
1129 ok(0, "Too many Write calls made on test %d\n", current_stream_test_index
);
1133 fail
= current_write_test
->fail_write
;
1135 ok(current_write_test
->cb
== cb
, "Expected %d, but got %d on test %d\n",
1136 current_write_test
->cb
, cb
, current_stream_test_index
);
1139 ok(current_write_test
->null_written
, "pcbWritten was NULL on test %d\n", current_stream_test_index
);
1141 ok(!memcmp(current_write_test
->data
, pv
, cb
), "Unexpected data on test %d\n", current_stream_test_index
);
1143 ++current_write_test
;
1148 return fail
? E_FAIL
: S_OK
;
1151 static HRESULT WINAPI
istream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
, DWORD dwOrigin
,
1152 ULARGE_INTEGER
*plibNewPosition
)
1154 ok(0, "unexpected call\n");
1158 static HRESULT WINAPI
istream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
1160 ok(0, "unexpected call\n");
1164 static HRESULT WINAPI
istream_CopyTo(IStream
*iface
, IStream
*pstm
, ULARGE_INTEGER cb
,
1165 ULARGE_INTEGER
*pcbRead
, ULARGE_INTEGER
*plibWritten
)
1167 ok(0, "unexpected call\n");
1171 static HRESULT WINAPI
istream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
1173 ok(0, "unexpected call\n");
1177 static HRESULT WINAPI
istream_Revert(IStream
*iface
)
1179 ok(0, "unexpected call\n");
1183 static HRESULT WINAPI
istream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
1184 ULARGE_INTEGER cb
, DWORD dwLockType
)
1186 ok(0, "unexpected call\n");
1190 static HRESULT WINAPI
istream_UnlockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
1191 ULARGE_INTEGER cb
, DWORD dwLockType
)
1193 ok(0, "unexpected call\n");
1197 static HRESULT WINAPI
istream_Stat(IStream
*iface
, STATSTG
*pstatstg
, DWORD grfStatFlag
)
1199 ok(0, "unexpected call\n");
1203 static HRESULT WINAPI
istream_Clone(IStream
*iface
, IStream
**ppstm
)
1205 ok(0, "unexpected call\n");
1209 static const IStreamVtbl StreamVtbl
= {
1210 istream_QueryInterface
,
1221 istream_UnlockRegion
,
1226 static IStream mxstream
= { &StreamVtbl
};
1228 static void test_saxreader(int version
)
1231 ISAXXMLReader
*reader
= NULL
;
1233 ISAXContentHandler
*lpContentHandler
;
1234 ISAXErrorHandler
*lpErrorHandler
;
1236 SAFEARRAYBOUND SADim
[1];
1237 char *pSAData
= NULL
;
1239 ULARGE_INTEGER liSize
;
1240 LARGE_INTEGER liPos
;
1243 static const CHAR testXmlA
[] = "test.xml";
1244 static const WCHAR testXmlW
[] = {'t','e','s','t','.','x','m','l',0};
1245 IXMLDOMDocument
*domDocument
;
1249 msxml_version
= version
;
1251 hr
= CoCreateInstance(&CLSID_SAXXMLReader30
, NULL
, CLSCTX_INPROC_SERVER
,
1252 &IID_ISAXXMLReader
, (LPVOID
*)&reader
);
1253 } else if(version
== 6) {
1254 hr
= CoCreateInstance(&CLSID_SAXXMLReader60
, NULL
, CLSCTX_INPROC_SERVER
,
1255 &IID_ISAXXMLReader
, (LPVOID
*)&reader
);
1256 if(hr
== REGDB_E_CLASSNOTREG
) {
1257 win_skip("SAXXMLReader6 not registered\n");
1261 hr
= CoCreateInstance(&CLSID_SAXXMLReader
, NULL
, CLSCTX_INPROC_SERVER
,
1262 &IID_ISAXXMLReader
, (LPVOID
*)&reader
);
1264 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1267 hr
= ISAXXMLReader_getContentHandler(reader
, NULL
);
1268 ok(hr
== E_POINTER
, "Expected E_POINTER, got %08x\n", hr
);
1270 hr
= ISAXXMLReader_getErrorHandler(reader
, NULL
);
1271 ok(hr
== E_POINTER
, "Expected E_POINTER, got %08x\n", hr
);
1274 hr
= ISAXXMLReader_getContentHandler(reader
, &lpContentHandler
);
1275 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1276 ok(lpContentHandler
== NULL
, "Expected %p, got %p\n", NULL
, lpContentHandler
);
1278 hr
= ISAXXMLReader_getErrorHandler(reader
, &lpErrorHandler
);
1279 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1280 ok(lpErrorHandler
== NULL
, "Expected %p, got %p\n", NULL
, lpErrorHandler
);
1282 hr
= ISAXXMLReader_putContentHandler(reader
, NULL
);
1283 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1285 hr
= ISAXXMLReader_putContentHandler(reader
, &contentHandler
);
1286 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1288 hr
= ISAXXMLReader_putErrorHandler(reader
, &errorHandler
);
1289 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1291 hr
= ISAXXMLReader_getContentHandler(reader
, &lpContentHandler
);
1292 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1293 ok(lpContentHandler
== &contentHandler
, "Expected %p, got %p\n", &contentHandler
, lpContentHandler
);
1295 V_VT(&var
) = VT_BSTR
;
1296 V_BSTR(&var
) = SysAllocString(szSimpleXML
);
1298 expectCall
= contentHandlerTest1
;
1299 hr
= ISAXXMLReader_parse(reader
, var
);
1300 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1301 test_expect_call(CH_ENDTEST
);
1305 SADim
[0].lLbound
= 0;
1306 SADim
[0].cElements
= sizeof(szTestXML
)-1;
1307 pSA
= SafeArrayCreate(VT_UI1
, 1, SADim
);
1308 SafeArrayAccessData(pSA
, (void**)&pSAData
);
1309 memcpy(pSAData
, szTestXML
, sizeof(szTestXML
)-1);
1310 SafeArrayUnaccessData(pSA
);
1311 V_VT(&var
) = VT_ARRAY
|VT_UI1
;
1312 V_ARRAY(&var
) = pSA
;
1314 expectCall
= contentHandlerTest1
;
1315 hr
= ISAXXMLReader_parse(reader
, var
);
1316 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1317 test_expect_call(CH_ENDTEST
);
1319 SafeArrayDestroy(pSA
);
1321 CreateStreamOnHGlobal(NULL
, TRUE
, &iStream
);
1322 liSize
.QuadPart
= strlen(szTestXML
);
1323 IStream_SetSize(iStream
, liSize
);
1324 IStream_Write(iStream
, szTestXML
, strlen(szTestXML
), &bytesWritten
);
1326 IStream_Seek(iStream
, liPos
, STREAM_SEEK_SET
, NULL
);
1327 V_VT(&var
) = VT_UNKNOWN
|VT_DISPATCH
;
1328 V_UNKNOWN(&var
) = (IUnknown
*)iStream
;
1330 expectCall
= contentHandlerTest1
;
1331 hr
= ISAXXMLReader_parse(reader
, var
);
1332 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1333 test_expect_call(CH_ENDTEST
);
1335 IStream_Release(iStream
);
1337 CreateStreamOnHGlobal(NULL
, TRUE
, &iStream
);
1338 liSize
.QuadPart
= strlen(szTestAttributes
);
1339 IStream_SetSize(iStream
, liSize
);
1340 IStream_Write(iStream
, szTestAttributes
, strlen(szTestAttributes
), &bytesWritten
);
1342 IStream_Seek(iStream
, liPos
, STREAM_SEEK_SET
, NULL
);
1343 V_VT(&var
) = VT_UNKNOWN
|VT_DISPATCH
;
1344 V_UNKNOWN(&var
) = (IUnknown
*)iStream
;
1347 expectCall
= contentHandlerTestAttributes6
;
1349 expectCall
= contentHandlerTestAttributes
;
1350 hr
= ISAXXMLReader_parse(reader
, var
);
1351 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1352 test_expect_call(CH_ENDTEST
);
1354 IStream_Release(iStream
);
1356 V_VT(&var
) = VT_BSTR
;
1357 V_BSTR(&var
) = SysAllocString(szCarriageRetTest
);
1359 expectCall
= contentHandlerTest2
;
1360 hr
= ISAXXMLReader_parse(reader
, var
);
1361 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1362 test_expect_call(CH_ENDTEST
);
1366 file
= CreateFileA(testXmlA
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1367 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1368 WriteFile(file
, szTestXML
, sizeof(szTestXML
)-1, &bytesWritten
, NULL
);
1371 expectCall
= contentHandlerTest1
;
1372 hr
= ISAXXMLReader_parseURL(reader
, testXmlW
);
1373 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1374 test_expect_call(CH_ENDTEST
);
1376 expectCall
= contentHandlerTestError
;
1377 hr
= ISAXXMLReader_parseURL(reader
, testXmlW
);
1378 ok(hr
== E_FAIL
, "Expected E_FAIL, got %08x\n", hr
);
1379 test_expect_call(CH_ENDTEST
);
1382 expectCall
= contentHandlerTestCallbackResult6
;
1384 expectCall
= contentHandlerTestCallbackResults
;
1385 hr
= ISAXXMLReader_parseURL(reader
, testXmlW
);
1386 ok(hr
== (version
>=6 ? S_OK
: S_FALSE
), "Expected S_FALSE, got %08x\n", hr
);
1387 test_expect_call(CH_ENDTEST
);
1389 DeleteFileA(testXmlA
);
1391 hr
= CoCreateInstance(&CLSID_DOMDocument
, NULL
, CLSCTX_INPROC_SERVER
,
1392 &IID_IXMLDOMDocument
, (LPVOID
*)&domDocument
);
1395 skip("Failed to create DOMDocument instance\n");
1398 bstrData
= SysAllocString(szSimpleXML
);
1399 hr
= IXMLDOMDocument_loadXML(domDocument
, bstrData
, &vBool
);
1400 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1401 V_VT(&var
) = VT_UNKNOWN
;
1402 V_UNKNOWN(&var
) = (IUnknown
*)domDocument
;
1404 expectCall
= contentHandlerTest2
;
1405 hr
= ISAXXMLReader_parse(reader
, var
);
1406 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1407 test_expect_call(CH_ENDTEST
);
1408 IXMLDOMDocument_Release(domDocument
);
1410 ISAXXMLReader_Release(reader
);
1411 SysFreeString(bstrData
);
1414 struct saxreader_props_test_t
1416 const char *prop_name
;
1420 static const struct saxreader_props_test_t props_test_data
[] = {
1421 { "http://xml.org/sax/properties/lexical-handler", (IUnknown
*)&saxlexicalhandler
},
1422 { "http://xml.org/sax/properties/declaration-handler", (IUnknown
*)&saxdeclhandler
},
1426 static void test_saxreader_properties(void)
1428 const struct saxreader_props_test_t
*ptr
= props_test_data
;
1429 ISAXXMLReader
*reader
;
1432 hr
= CoCreateInstance(&CLSID_SAXXMLReader
, NULL
, CLSCTX_INPROC_SERVER
,
1433 &IID_ISAXXMLReader
, (void**)&reader
);
1434 EXPECT_HR(hr
, S_OK
);
1436 hr
= ISAXXMLReader_getProperty(reader
, _bstr_("http://xml.org/sax/properties/lexical-handler"), NULL
);
1437 EXPECT_HR(hr
, E_POINTER
);
1439 while (ptr
->prop_name
)
1443 V_VT(&v
) = VT_EMPTY
;
1444 V_UNKNOWN(&v
) = (IUnknown
*)0xdeadbeef;
1445 hr
= ISAXXMLReader_getProperty(reader
, _bstr_(ptr
->prop_name
), &v
);
1446 EXPECT_HR(hr
, S_OK
);
1447 ok(V_VT(&v
) == VT_UNKNOWN
, "got %d\n", V_VT(&v
));
1448 ok(V_UNKNOWN(&v
) == NULL
, "got %p\n", V_UNKNOWN(&v
));
1450 V_VT(&v
) = VT_UNKNOWN
;
1451 V_UNKNOWN(&v
) = ptr
->iface
;
1452 hr
= ISAXXMLReader_putProperty(reader
, _bstr_(ptr
->prop_name
), v
);
1453 EXPECT_HR(hr
, S_OK
);
1455 V_VT(&v
) = VT_EMPTY
;
1456 V_UNKNOWN(&v
) = (IUnknown
*)0xdeadbeef;
1457 handler_addrefcalled
= 0;
1458 hr
= ISAXXMLReader_getProperty(reader
, _bstr_(ptr
->prop_name
), &v
);
1459 EXPECT_HR(hr
, S_OK
);
1460 ok(V_VT(&v
) == VT_UNKNOWN
, "got %d\n", V_VT(&v
));
1461 ok(V_UNKNOWN(&v
) == ptr
->iface
, "got %p\n", V_UNKNOWN(&v
));
1462 ok(handler_addrefcalled
== 1, "AddRef called %d times\n", handler_addrefcalled
);
1465 V_VT(&v
) = VT_EMPTY
;
1466 V_UNKNOWN(&v
) = (IUnknown
*)0xdeadbeef;
1467 hr
= ISAXXMLReader_putProperty(reader
, _bstr_(ptr
->prop_name
), v
);
1468 EXPECT_HR(hr
, S_OK
);
1470 V_VT(&v
) = VT_EMPTY
;
1471 V_UNKNOWN(&v
) = (IUnknown
*)0xdeadbeef;
1472 hr
= ISAXXMLReader_getProperty(reader
, _bstr_(ptr
->prop_name
), &v
);
1473 EXPECT_HR(hr
, S_OK
);
1474 ok(V_VT(&v
) == VT_UNKNOWN
, "got %d\n", V_VT(&v
));
1475 ok(V_UNKNOWN(&v
) == NULL
, "got %p\n", V_UNKNOWN(&v
));
1477 V_VT(&v
) = VT_UNKNOWN
;
1478 V_UNKNOWN(&v
) = ptr
->iface
;
1479 hr
= ISAXXMLReader_putProperty(reader
, _bstr_(ptr
->prop_name
), v
);
1480 EXPECT_HR(hr
, S_OK
);
1482 /* only VT_EMPTY seems to be valid to reset property */
1484 V_UNKNOWN(&v
) = (IUnknown
*)0xdeadbeef;
1485 hr
= ISAXXMLReader_putProperty(reader
, _bstr_(ptr
->prop_name
), v
);
1486 EXPECT_HR(hr
, E_INVALIDARG
);
1488 V_VT(&v
) = VT_EMPTY
;
1489 V_UNKNOWN(&v
) = (IUnknown
*)0xdeadbeef;
1490 hr
= ISAXXMLReader_getProperty(reader
, _bstr_(ptr
->prop_name
), &v
);
1491 EXPECT_HR(hr
, S_OK
);
1492 ok(V_VT(&v
) == VT_UNKNOWN
, "got %d\n", V_VT(&v
));
1493 ok(V_UNKNOWN(&v
) == ptr
->iface
, "got %p\n", V_UNKNOWN(&v
));
1496 V_VT(&v
) = VT_UNKNOWN
;
1497 V_UNKNOWN(&v
) = NULL
;
1498 hr
= ISAXXMLReader_putProperty(reader
, _bstr_(ptr
->prop_name
), v
);
1499 EXPECT_HR(hr
, S_OK
);
1501 V_VT(&v
) = VT_EMPTY
;
1502 V_UNKNOWN(&v
) = (IUnknown
*)0xdeadbeef;
1503 hr
= ISAXXMLReader_getProperty(reader
, _bstr_(ptr
->prop_name
), &v
);
1504 EXPECT_HR(hr
, S_OK
);
1505 ok(V_VT(&v
) == VT_UNKNOWN
, "got %d\n", V_VT(&v
));
1506 ok(V_UNKNOWN(&v
) == NULL
, "got %p\n", V_UNKNOWN(&v
));
1511 ISAXXMLReader_Release(reader
);
1515 struct feature_ns_entry_t
{
1521 static const struct feature_ns_entry_t feature_ns_entry_data
[] = {
1522 { &CLSID_SAXXMLReader
, "CLSID_SAXXMLReader", VARIANT_TRUE
},
1523 { &CLSID_SAXXMLReader30
, "CLSID_SAXXMLReader30", VARIANT_TRUE
},
1524 { &CLSID_SAXXMLReader40
, "CLSID_SAXXMLReader40", VARIANT_TRUE
},
1525 { &CLSID_SAXXMLReader60
, "CLSID_SAXXMLReader60", VARIANT_TRUE
},
1529 static void test_saxreader_features(void)
1531 const struct feature_ns_entry_t
*entry
= feature_ns_entry_data
;
1532 ISAXXMLReader
*reader
;
1539 hr
= CoCreateInstance(entry
->guid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_ISAXXMLReader
, (void**)&reader
);
1542 win_skip("can't create %s instance\n", entry
->clsid
);
1548 hr
= ISAXXMLReader_getFeature(reader
, _bstr_("http://xml.org/sax/features/namespaces"), &value
);
1549 EXPECT_HR(hr
, S_OK
);
1551 ok(entry
->value
== value
, "%s: got wrong default value %x, expected %x\n", entry
->clsid
, value
, entry
->value
);
1553 ISAXXMLReader_Release(reader
);
1559 /* UTF-8 data with UTF-8 BOM and UTF-16 in prolog */
1560 static const CHAR UTF8BOMTest
[] =
1561 "\xEF\xBB\xBF<?xml version = \"1.0\" encoding = \"UTF-16\"?>\n"
1564 struct enc_test_entry_t
{
1572 static const struct enc_test_entry_t encoding_test_data
[] = {
1573 { &CLSID_SAXXMLReader
, "CLSID_SAXXMLReader", UTF8BOMTest
, 0xc00ce56f, 1 },
1574 { &CLSID_SAXXMLReader30
, "CLSID_SAXXMLReader30", UTF8BOMTest
, 0xc00ce56f, 1 },
1575 { &CLSID_SAXXMLReader40
, "CLSID_SAXXMLReader40", UTF8BOMTest
, S_OK
, 0 },
1576 { &CLSID_SAXXMLReader60
, "CLSID_SAXXMLReader60", UTF8BOMTest
, S_OK
, 0 },
1580 static void test_encoding(void)
1582 const struct enc_test_entry_t
*entry
= encoding_test_data
;
1583 static const WCHAR testXmlW
[] = {'t','e','s','t','.','x','m','l',0};
1584 static const CHAR testXmlA
[] = "test.xml";
1585 ISAXXMLReader
*reader
;
1592 hr
= CoCreateInstance(entry
->guid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_ISAXXMLReader
, (void**)&reader
);
1595 win_skip("can't create %s instance\n", entry
->clsid
);
1600 file
= CreateFileA(testXmlA
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1601 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1602 WriteFile(file
, UTF8BOMTest
, sizeof(UTF8BOMTest
)-1, &written
, NULL
);
1605 hr
= ISAXXMLReader_parseURL(reader
, testXmlW
);
1607 todo_wine
ok(hr
== entry
->hr
, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry
->hr
, hr
, entry
->clsid
);
1609 ok(hr
== entry
->hr
, "Expected 0x%08x, got 0x%08x. CLSID %s\n", entry
->hr
, hr
, entry
->clsid
);
1611 DeleteFileA(testXmlA
);
1612 ISAXXMLReader_Release(reader
);
1618 static void test_mxwriter_contenthandler(void)
1620 ISAXContentHandler
*handler
;
1621 IMXWriter
*writer
, *writer2
;
1624 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
1625 &IID_IMXWriter
, (void**)&writer
);
1626 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1628 EXPECT_REF(writer
, 1);
1630 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&handler
);
1631 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1632 EXPECT_REF(writer
, 2);
1633 EXPECT_REF(handler
, 2);
1635 hr
= ISAXContentHandler_QueryInterface(handler
, &IID_IMXWriter
, (void**)&writer2
);
1636 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1637 ok(writer2
== writer
, "got %p, expected %p\n", writer2
, writer
);
1638 EXPECT_REF(writer
, 3);
1639 EXPECT_REF(writer2
, 3);
1640 IMXWriter_Release(writer2
);
1642 ISAXContentHandler_Release(handler
);
1643 IMXWriter_Release(writer
);
1646 struct msxmlsupported_data_t
1653 static struct msxmlsupported_data_t msxmlsupported_data
[] =
1655 { &CLSID_MXXMLWriter
, "MXXMLWriter" },
1656 { &CLSID_MXXMLWriter30
, "MXXMLWriter30" },
1657 { &CLSID_MXXMLWriter40
, "MXXMLWriter40" },
1658 { &CLSID_MXXMLWriter60
, "MXXMLWriter60" },
1662 static BOOL
is_mxwriter_supported(const GUID
*clsid
, const struct msxmlsupported_data_t
*table
)
1664 while (table
->clsid
)
1666 if (table
->clsid
== clsid
) return table
->supported
;
1672 struct mxwriter_props_t
1676 VARIANT_BOOL disable_escape
;
1677 VARIANT_BOOL indent
;
1678 VARIANT_BOOL omitdecl
;
1679 VARIANT_BOOL standalone
;
1680 const char *encoding
;
1683 static const struct mxwriter_props_t mxwriter_default_props
[] =
1685 { &CLSID_MXXMLWriter
, VARIANT_TRUE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, "UTF-16" },
1686 { &CLSID_MXXMLWriter30
, VARIANT_TRUE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, "UTF-16" },
1687 { &CLSID_MXXMLWriter40
, VARIANT_TRUE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, "UTF-16" },
1688 { &CLSID_MXXMLWriter60
, VARIANT_TRUE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, VARIANT_FALSE
, "UTF-16" },
1692 static void test_mxwriter_default_properties(const struct mxwriter_props_t
*table
)
1696 while (table
->clsid
)
1703 if (!is_mxwriter_supported(table
->clsid
, msxmlsupported_data
))
1710 hr
= CoCreateInstance(table
->clsid
, NULL
, CLSCTX_INPROC_SERVER
,
1711 &IID_IMXWriter
, (void**)&writer
);
1712 EXPECT_HR(hr
, S_OK
);
1715 hr
= IMXWriter_get_byteOrderMark(writer
, &b
);
1716 EXPECT_HR(hr
, S_OK
);
1717 ok(table
->bom
== b
, "test %d: got BOM %d, expected %d\n", i
, b
, table
->bom
);
1719 b
= !table
->disable_escape
;
1720 hr
= IMXWriter_get_disableOutputEscaping(writer
, &b
);
1721 EXPECT_HR(hr
, S_OK
);
1722 ok(table
->disable_escape
== b
, "test %d: got disable escape %d, expected %d\n", i
, b
,
1723 table
->disable_escape
);
1726 hr
= IMXWriter_get_indent(writer
, &b
);
1727 EXPECT_HR(hr
, S_OK
);
1728 ok(table
->indent
== b
, "test %d: got indent %d, expected %d\n", i
, b
, table
->indent
);
1730 b
= !table
->omitdecl
;
1731 hr
= IMXWriter_get_omitXMLDeclaration(writer
, &b
);
1732 EXPECT_HR(hr
, S_OK
);
1733 ok(table
->omitdecl
== b
, "test %d: got omitdecl %d, expected %d\n", i
, b
, table
->omitdecl
);
1735 b
= !table
->standalone
;
1736 hr
= IMXWriter_get_standalone(writer
, &b
);
1737 EXPECT_HR(hr
, S_OK
);
1738 ok(table
->standalone
== b
, "test %d: got standalone %d, expected %d\n", i
, b
, table
->standalone
);
1740 hr
= IMXWriter_get_encoding(writer
, &encoding
);
1741 EXPECT_HR(hr
, S_OK
);
1742 ok(!lstrcmpW(encoding
, _bstr_(table
->encoding
)), "test %d: got encoding %s, expected %s\n",
1743 i
, wine_dbgstr_w(encoding
), table
->encoding
);
1744 SysFreeString(encoding
);
1746 IMXWriter_Release(writer
);
1753 static void test_mxwriter_properties(void)
1755 static const WCHAR utf16W
[] = {'U','T','F','-','1','6',0};
1756 static const WCHAR emptyW
[] = {0};
1757 static const WCHAR testW
[] = {'t','e','s','t',0};
1763 test_mxwriter_default_properties(mxwriter_default_props
);
1765 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
1766 &IID_IMXWriter
, (void**)&writer
);
1767 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1769 hr
= IMXWriter_get_disableOutputEscaping(writer
, NULL
);
1770 ok(hr
== E_POINTER
, "got %08x\n", hr
);
1772 hr
= IMXWriter_get_byteOrderMark(writer
, NULL
);
1773 ok(hr
== E_POINTER
, "got %08x\n", hr
);
1775 hr
= IMXWriter_get_indent(writer
, NULL
);
1776 ok(hr
== E_POINTER
, "got %08x\n", hr
);
1778 hr
= IMXWriter_get_omitXMLDeclaration(writer
, NULL
);
1779 ok(hr
== E_POINTER
, "got %08x\n", hr
);
1781 hr
= IMXWriter_get_standalone(writer
, NULL
);
1782 ok(hr
== E_POINTER
, "got %08x\n", hr
);
1785 hr
= IMXWriter_put_standalone(writer
, VARIANT_TRUE
);
1786 ok(hr
== S_OK
, "got %08x\n", hr
);
1789 hr
= IMXWriter_get_standalone(writer
, &b
);
1790 ok(hr
== S_OK
, "got %08x\n", hr
);
1791 ok(b
== VARIANT_TRUE
, "got %d\n", b
);
1793 hr
= IMXWriter_get_encoding(writer
, NULL
);
1794 ok(hr
== E_POINTER
, "got %08x\n", hr
);
1796 /* UTF-16 is a default setting apparently */
1797 str
= (void*)0xdeadbeef;
1798 hr
= IMXWriter_get_encoding(writer
, &str
);
1799 ok(hr
== S_OK
, "got %08x\n", hr
);
1800 ok(lstrcmpW(str
, utf16W
) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str
));
1802 str2
= (void*)0xdeadbeef;
1803 hr
= IMXWriter_get_encoding(writer
, &str2
);
1804 ok(hr
== S_OK
, "got %08x\n", hr
);
1805 ok(str
!= str2
, "expected newly allocated, got same %p\n", str
);
1807 SysFreeString(str2
);
1810 /* put empty string */
1811 str
= SysAllocString(emptyW
);
1812 hr
= IMXWriter_put_encoding(writer
, str
);
1813 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
1816 str
= (void*)0xdeadbeef;
1817 hr
= IMXWriter_get_encoding(writer
, &str
);
1818 ok(hr
== S_OK
, "got %08x\n", hr
);
1819 ok(!lstrcmpW(str
, emptyW
) == 0, "expected empty string, got %s\n", wine_dbgstr_w(str
));
1822 /* invalid encoding name */
1823 str
= SysAllocString(testW
);
1824 hr
= IMXWriter_put_encoding(writer
, str
);
1825 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
1828 hr
= IMXWriter_get_version(writer
, NULL
);
1829 ok(hr
== E_POINTER
, "got %08x\n", hr
);
1830 /* default version is 'surprisingly' 1.0 */
1831 hr
= IMXWriter_get_version(writer
, &str
);
1832 ok(hr
== S_OK
, "got %08x\n", hr
);
1833 ok(!lstrcmpW(str
, _bstr_("1.0")), "got %s\n", wine_dbgstr_w(str
));
1836 /* store version string as is */
1837 hr
= IMXWriter_put_version(writer
, NULL
);
1838 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
1840 hr
= IMXWriter_put_version(writer
, _bstr_("1.0"));
1841 ok(hr
== S_OK
, "got %08x\n", hr
);
1843 hr
= IMXWriter_put_version(writer
, _bstr_(""));
1844 ok(hr
== S_OK
, "got %08x\n", hr
);
1845 hr
= IMXWriter_get_version(writer
, &str
);
1846 ok(hr
== S_OK
, "got %08x\n", hr
);
1847 ok(!lstrcmpW(str
, _bstr_("")), "got %s\n", wine_dbgstr_w(str
));
1850 hr
= IMXWriter_put_version(writer
, _bstr_("a.b"));
1851 ok(hr
== S_OK
, "got %08x\n", hr
);
1852 hr
= IMXWriter_get_version(writer
, &str
);
1853 ok(hr
== S_OK
, "got %08x\n", hr
);
1854 ok(!lstrcmpW(str
, _bstr_("a.b")), "got %s\n", wine_dbgstr_w(str
));
1857 hr
= IMXWriter_put_version(writer
, _bstr_("2.0"));
1858 ok(hr
== S_OK
, "got %08x\n", hr
);
1859 hr
= IMXWriter_get_version(writer
, &str
);
1860 ok(hr
== S_OK
, "got %08x\n", hr
);
1861 ok(!lstrcmpW(str
, _bstr_("2.0")), "got %s\n", wine_dbgstr_w(str
));
1864 IMXWriter_Release(writer
);
1868 static void test_mxwriter_flush(void)
1870 ISAXContentHandler
*content
;
1873 ULARGE_INTEGER pos2
;
1878 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
1879 &IID_IMXWriter
, (void**)&writer
);
1880 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1882 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1883 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1884 EXPECT_REF(stream
, 1);
1886 /* detach when nothing was attached */
1887 V_VT(&dest
) = VT_EMPTY
;
1888 hr
= IMXWriter_put_output(writer
, dest
);
1889 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1892 V_VT(&dest
) = VT_UNKNOWN
;
1893 V_UNKNOWN(&dest
) = (IUnknown
*)stream
;
1894 hr
= IMXWriter_put_output(writer
, dest
);
1895 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1896 todo_wine
EXPECT_REF(stream
, 3);
1898 /* detach setting VT_EMPTY destination */
1899 V_VT(&dest
) = VT_EMPTY
;
1900 hr
= IMXWriter_put_output(writer
, dest
);
1901 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1902 EXPECT_REF(stream
, 1);
1904 V_VT(&dest
) = VT_UNKNOWN
;
1905 V_UNKNOWN(&dest
) = (IUnknown
*)stream
;
1906 hr
= IMXWriter_put_output(writer
, dest
);
1907 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1909 /* flush() doesn't detach a stream */
1910 hr
= IMXWriter_flush(writer
);
1911 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1912 todo_wine
EXPECT_REF(stream
, 3);
1915 hr
= IStream_Seek(stream
, pos
, STREAM_SEEK_CUR
, &pos2
);
1916 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1917 ok(pos2
.QuadPart
== 0, "expected stream beginning\n");
1919 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
1920 ok(hr
== S_OK
, "got %08x\n", hr
);
1922 hr
= ISAXContentHandler_startDocument(content
);
1923 ok(hr
== S_OK
, "got %08x\n", hr
);
1926 hr
= IStream_Seek(stream
, pos
, STREAM_SEEK_CUR
, &pos2
);
1927 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1928 ok(pos2
.QuadPart
!= 0, "expected stream beginning\n");
1930 /* already started */
1931 hr
= ISAXContentHandler_startDocument(content
);
1932 ok(hr
== S_OK
, "got %08x\n", hr
);
1934 hr
= ISAXContentHandler_endDocument(content
);
1935 ok(hr
== S_OK
, "got %08x\n", hr
);
1937 /* flushed on endDocument() */
1939 hr
= IStream_Seek(stream
, pos
, STREAM_SEEK_CUR
, &pos2
);
1940 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1941 ok(pos2
.QuadPart
!= 0, "expected stream position moved\n");
1943 ISAXContentHandler_Release(content
);
1944 IStream_Release(stream
);
1945 IMXWriter_Release(writer
);
1948 static void test_mxwriter_startenddocument(void)
1950 ISAXContentHandler
*content
;
1955 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
1956 &IID_IMXWriter
, (void**)&writer
);
1957 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1959 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
1960 ok(hr
== S_OK
, "got %08x\n", hr
);
1962 hr
= ISAXContentHandler_startDocument(content
);
1963 ok(hr
== S_OK
, "got %08x\n", hr
);
1965 hr
= ISAXContentHandler_endDocument(content
);
1966 ok(hr
== S_OK
, "got %08x\n", hr
);
1968 V_VT(&dest
) = VT_EMPTY
;
1969 hr
= IMXWriter_get_output(writer
, &dest
);
1970 ok(hr
== S_OK
, "got %08x\n", hr
);
1971 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
1972 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest
)),
1973 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
1974 VariantClear(&dest
);
1976 /* now try another startDocument */
1977 hr
= ISAXContentHandler_startDocument(content
);
1978 ok(hr
== S_OK
, "got %08x\n", hr
);
1979 /* and get duplicated prolog */
1980 V_VT(&dest
) = VT_EMPTY
;
1981 hr
= IMXWriter_get_output(writer
, &dest
);
1982 ok(hr
== S_OK
, "got %08x\n", hr
);
1983 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
1984 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"
1985 "<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest
)),
1986 "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
1987 VariantClear(&dest
);
1989 ISAXContentHandler_Release(content
);
1990 IMXWriter_Release(writer
);
1992 /* now with omitted declaration */
1993 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
1994 &IID_IMXWriter
, (void**)&writer
);
1995 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
1997 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
1998 ok(hr
== S_OK
, "got %08x\n", hr
);
2000 hr
= IMXWriter_put_omitXMLDeclaration(writer
, VARIANT_TRUE
);
2001 ok(hr
== S_OK
, "got %08x\n", hr
);
2003 hr
= ISAXContentHandler_startDocument(content
);
2004 ok(hr
== S_OK
, "got %08x\n", hr
);
2006 hr
= ISAXContentHandler_endDocument(content
);
2007 ok(hr
== S_OK
, "got %08x\n", hr
);
2009 V_VT(&dest
) = VT_EMPTY
;
2010 hr
= IMXWriter_get_output(writer
, &dest
);
2011 ok(hr
== S_OK
, "got %08x\n", hr
);
2012 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2013 ok(!lstrcmpW(_bstr_(""), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2014 VariantClear(&dest
);
2016 ISAXContentHandler_Release(content
);
2017 IMXWriter_Release(writer
);
2029 struct writer_startendelement_t
{
2031 enum startendtype type
;
2033 const char *local_name
;
2037 ISAXAttributes
*attr
;
2040 static const struct writer_startendelement_t writer_startendelement
[] = {
2042 { &CLSID_MXXMLWriter
, StartElement
, NULL
, NULL
, NULL
, NULL
, E_INVALIDARG
},
2043 { &CLSID_MXXMLWriter30
, StartElement
, NULL
, NULL
, NULL
, NULL
, E_INVALIDARG
},
2044 { &CLSID_MXXMLWriter40
, StartElement
, NULL
, NULL
, NULL
, NULL
, E_INVALIDARG
},
2045 { &CLSID_MXXMLWriter60
, StartElement
, NULL
, NULL
, NULL
, "<>", S_OK
},
2046 { &CLSID_MXXMLWriter
, StartElement
, "uri", NULL
, NULL
, NULL
, E_INVALIDARG
},
2048 { &CLSID_MXXMLWriter30
, StartElement
, "uri", NULL
, NULL
, NULL
, E_INVALIDARG
},
2049 { &CLSID_MXXMLWriter40
, StartElement
, "uri", NULL
, NULL
, NULL
, E_INVALIDARG
},
2050 { &CLSID_MXXMLWriter60
, StartElement
, "uri", NULL
, NULL
, "<>", S_OK
},
2051 { &CLSID_MXXMLWriter
, StartElement
, NULL
, "local", NULL
, NULL
, E_INVALIDARG
},
2052 { &CLSID_MXXMLWriter30
, StartElement
, NULL
, "local", NULL
, NULL
, E_INVALIDARG
},
2054 { &CLSID_MXXMLWriter40
, StartElement
, NULL
, "local", NULL
, NULL
, E_INVALIDARG
},
2055 { &CLSID_MXXMLWriter60
, StartElement
, NULL
, "local", NULL
, "<>", S_OK
},
2056 { &CLSID_MXXMLWriter
, StartElement
, NULL
, NULL
, "qname", NULL
, E_INVALIDARG
},
2057 { &CLSID_MXXMLWriter30
, StartElement
, NULL
, NULL
, "qname", NULL
, E_INVALIDARG
},
2058 { &CLSID_MXXMLWriter40
, StartElement
, NULL
, NULL
, "qname", NULL
, E_INVALIDARG
},
2060 { &CLSID_MXXMLWriter60
, StartElement
, NULL
, NULL
, "qname", "<qname>", S_OK
},
2061 { &CLSID_MXXMLWriter
, StartElement
, "uri", "local", "qname", "<qname>", S_OK
},
2062 { &CLSID_MXXMLWriter30
, StartElement
, "uri", "local", "qname", "<qname>", S_OK
},
2063 { &CLSID_MXXMLWriter40
, StartElement
, "uri", "local", "qname", "<qname>", S_OK
},
2064 { &CLSID_MXXMLWriter60
, StartElement
, "uri", "local", "qname", "<qname>", S_OK
},
2066 { &CLSID_MXXMLWriter
, StartElement
, "uri", "local", NULL
, NULL
, E_INVALIDARG
},
2067 { &CLSID_MXXMLWriter30
, StartElement
, "uri", "local", NULL
, NULL
, E_INVALIDARG
},
2068 { &CLSID_MXXMLWriter40
, StartElement
, "uri", "local", NULL
, NULL
, E_INVALIDARG
},
2069 { &CLSID_MXXMLWriter60
, StartElement
, "uri", "local", NULL
, "<>", S_OK
},
2070 { &CLSID_MXXMLWriter
, StartElement
, "uri", "local", "uri:local", "<uri:local>", S_OK
},
2072 { &CLSID_MXXMLWriter30
, StartElement
, "uri", "local", "uri:local", "<uri:local>", S_OK
},
2073 { &CLSID_MXXMLWriter40
, StartElement
, "uri", "local", "uri:local", "<uri:local>", S_OK
},
2074 { &CLSID_MXXMLWriter60
, StartElement
, "uri", "local", "uri:local", "<uri:local>", S_OK
},
2075 { &CLSID_MXXMLWriter
, StartElement
, "uri", "local", "uri:local2", "<uri:local2>", S_OK
},
2076 { &CLSID_MXXMLWriter30
, StartElement
, "uri", "local", "uri:local2", "<uri:local2>", S_OK
},
2078 { &CLSID_MXXMLWriter40
, StartElement
, "uri", "local", "uri:local2", "<uri:local2>", S_OK
},
2079 { &CLSID_MXXMLWriter60
, StartElement
, "uri", "local", "uri:local2", "<uri:local2>", S_OK
},
2080 /* endElement tests */
2081 { &CLSID_MXXMLWriter
, EndElement
, NULL
, NULL
, NULL
, NULL
, E_INVALIDARG
},
2082 { &CLSID_MXXMLWriter30
, EndElement
, NULL
, NULL
, NULL
, NULL
, E_INVALIDARG
},
2083 { &CLSID_MXXMLWriter40
, EndElement
, NULL
, NULL
, NULL
, NULL
, E_INVALIDARG
},
2085 { &CLSID_MXXMLWriter60
, EndElement
, NULL
, NULL
, NULL
, "</>", S_OK
},
2086 { &CLSID_MXXMLWriter
, EndElement
, "uri", NULL
, NULL
, NULL
, E_INVALIDARG
},
2087 { &CLSID_MXXMLWriter30
, EndElement
, "uri", NULL
, NULL
, NULL
, E_INVALIDARG
},
2088 { &CLSID_MXXMLWriter40
, EndElement
, "uri", NULL
, NULL
, NULL
, E_INVALIDARG
},
2089 { &CLSID_MXXMLWriter60
, EndElement
, "uri", NULL
, NULL
, "</>", S_OK
},
2091 { &CLSID_MXXMLWriter
, EndElement
, NULL
, "local", NULL
, NULL
, E_INVALIDARG
},
2092 { &CLSID_MXXMLWriter30
, EndElement
, NULL
, "local", NULL
, NULL
, E_INVALIDARG
},
2093 { &CLSID_MXXMLWriter40
, EndElement
, NULL
, "local", NULL
, NULL
, E_INVALIDARG
},
2094 { &CLSID_MXXMLWriter60
, EndElement
, NULL
, "local", NULL
, "</>", S_OK
},
2095 { &CLSID_MXXMLWriter
, EndElement
, NULL
, NULL
, "qname", NULL
, E_INVALIDARG
},
2097 { &CLSID_MXXMLWriter30
, EndElement
, NULL
, NULL
, "qname", NULL
, E_INVALIDARG
},
2098 { &CLSID_MXXMLWriter40
, EndElement
, NULL
, NULL
, "qname", NULL
, E_INVALIDARG
},
2099 { &CLSID_MXXMLWriter60
, EndElement
, NULL
, NULL
, "qname", "</qname>", S_OK
},
2100 { &CLSID_MXXMLWriter
, EndElement
, "uri", "local", "qname", "</qname>", S_OK
},
2101 { &CLSID_MXXMLWriter30
, EndElement
, "uri", "local", "qname", "</qname>", S_OK
},
2103 { &CLSID_MXXMLWriter40
, EndElement
, "uri", "local", "qname", "</qname>", S_OK
},
2104 { &CLSID_MXXMLWriter60
, EndElement
, "uri", "local", "qname", "</qname>", S_OK
},
2105 { &CLSID_MXXMLWriter
, EndElement
, "uri", "local", NULL
, NULL
, E_INVALIDARG
},
2106 { &CLSID_MXXMLWriter30
, EndElement
, "uri", "local", NULL
, NULL
, E_INVALIDARG
},
2107 { &CLSID_MXXMLWriter40
, EndElement
, "uri", "local", NULL
, NULL
, E_INVALIDARG
},
2109 { &CLSID_MXXMLWriter60
, EndElement
, "uri", "local", NULL
, "</>", S_OK
},
2110 { &CLSID_MXXMLWriter
, EndElement
, "uri", "local", "uri:local", "</uri:local>", S_OK
},
2111 { &CLSID_MXXMLWriter30
, EndElement
, "uri", "local", "uri:local", "</uri:local>", S_OK
},
2112 { &CLSID_MXXMLWriter40
, EndElement
, "uri", "local", "uri:local", "</uri:local>", S_OK
},
2113 { &CLSID_MXXMLWriter60
, EndElement
, "uri", "local", "uri:local", "</uri:local>", S_OK
},
2115 { &CLSID_MXXMLWriter
, EndElement
, "uri", "local", "uri:local2", "</uri:local2>", S_OK
},
2116 { &CLSID_MXXMLWriter30
, EndElement
, "uri", "local", "uri:local2", "</uri:local2>", S_OK
},
2117 { &CLSID_MXXMLWriter40
, EndElement
, "uri", "local", "uri:local2", "</uri:local2>", S_OK
},
2118 { &CLSID_MXXMLWriter60
, EndElement
, "uri", "local", "uri:local2", "</uri:local2>", S_OK
},
2120 /* with attributes */
2121 { &CLSID_MXXMLWriter
, StartElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK
, &saxattributes
},
2123 { &CLSID_MXXMLWriter30
, StartElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK
, &saxattributes
},
2124 { &CLSID_MXXMLWriter40
, StartElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK
, &saxattributes
},
2125 { &CLSID_MXXMLWriter60
, StartElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\">", S_OK
, &saxattributes
},
2126 /* empty elements */
2127 { &CLSID_MXXMLWriter
, StartEndElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK
, &saxattributes
},
2128 { &CLSID_MXXMLWriter30
, StartEndElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK
, &saxattributes
},
2130 { &CLSID_MXXMLWriter40
, StartEndElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK
, &saxattributes
},
2131 { &CLSID_MXXMLWriter60
, StartEndElement
, "uri", "local", "uri:local", "<uri:local a:attr1=\"a1\" attr2=\"a2\"/>", S_OK
, &saxattributes
},
2132 { &CLSID_MXXMLWriter
, StartEndElement
, "", "", "", "</>", S_OK
},
2133 { &CLSID_MXXMLWriter30
, StartEndElement
, "", "", "", "</>", S_OK
},
2134 { &CLSID_MXXMLWriter40
, StartEndElement
, "", "", "", "</>", S_OK
},
2136 { &CLSID_MXXMLWriter60
, StartEndElement
, "", "", "", "</>", S_OK
},
2140 static void get_supported_mxwriter_data(struct msxmlsupported_data_t
*table
)
2142 while (table
->clsid
)
2147 hr
= CoCreateInstance(table
->clsid
, NULL
, CLSCTX_INPROC_SERVER
,
2148 &IID_IMXWriter
, (void**)&writer
);
2149 if (hr
== S_OK
) IMXWriter_Release(writer
);
2151 table
->supported
= hr
== S_OK
;
2152 if (hr
!= S_OK
) win_skip("class %s not supported\n", table
->name
);
2158 static void test_mxwriter_startendelement_batch(const struct writer_startendelement_t
*table
)
2162 while (table
->clsid
)
2164 ISAXContentHandler
*content
;
2168 if (!is_mxwriter_supported(table
->clsid
, msxmlsupported_data
))
2175 hr
= CoCreateInstance(table
->clsid
, NULL
, CLSCTX_INPROC_SERVER
,
2176 &IID_IMXWriter
, (void**)&writer
);
2177 EXPECT_HR(hr
, S_OK
);
2179 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
2180 EXPECT_HR(hr
, S_OK
);
2182 hr
= IMXWriter_put_omitXMLDeclaration(writer
, VARIANT_TRUE
);
2183 EXPECT_HR(hr
, S_OK
);
2185 hr
= ISAXContentHandler_startDocument(content
);
2186 EXPECT_HR(hr
, S_OK
);
2188 if (table
->type
== StartElement
)
2190 hr
= ISAXContentHandler_startElement(content
, _bstr_(table
->uri
), lstrlen(table
->uri
),
2191 _bstr_(table
->local_name
), lstrlen(table
->local_name
), _bstr_(table
->qname
), lstrlen(table
->qname
), table
->attr
);
2192 ok(hr
== table
->hr
, "test %d: got 0x%08x, expected 0x%08x\n", i
, hr
, table
->hr
);
2194 else if (table
->type
== EndElement
)
2196 hr
= ISAXContentHandler_endElement(content
, _bstr_(table
->uri
), lstrlen(table
->uri
),
2197 _bstr_(table
->local_name
), lstrlen(table
->local_name
), _bstr_(table
->qname
), lstrlen(table
->qname
));
2198 ok(hr
== table
->hr
, "test %d: got 0x%08x, expected 0x%08x\n", i
, hr
, table
->hr
);
2202 hr
= ISAXContentHandler_startElement(content
, _bstr_(table
->uri
), lstrlen(table
->uri
),
2203 _bstr_(table
->local_name
), lstrlen(table
->local_name
), _bstr_(table
->qname
), lstrlen(table
->qname
), table
->attr
);
2204 ok(hr
== table
->hr
, "test %d: got 0x%08x, expected 0x%08x\n", i
, hr
, table
->hr
);
2205 hr
= ISAXContentHandler_endElement(content
, _bstr_(table
->uri
), lstrlen(table
->uri
),
2206 _bstr_(table
->local_name
), lstrlen(table
->local_name
), _bstr_(table
->qname
), lstrlen(table
->qname
));
2207 ok(hr
== table
->hr
, "test %d: got 0x%08x, expected 0x%08x\n", i
, hr
, table
->hr
);
2215 V_VT(&dest
) = VT_EMPTY
;
2216 hr
= IMXWriter_get_output(writer
, &dest
);
2217 EXPECT_HR(hr
, S_OK
);
2218 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2219 ok(!lstrcmpW(_bstr_(table
->output
), V_BSTR(&dest
)),
2220 "test %d: got wrong content %s, expected %s\n", i
, wine_dbgstr_w(V_BSTR(&dest
)), table
->output
);
2221 VariantClear(&dest
);
2224 ISAXContentHandler_Release(content
);
2225 IMXWriter_Release(writer
);
2234 static void test_mxwriter_startendelement(void)
2236 ISAXContentHandler
*content
;
2241 test_mxwriter_startendelement_batch(writer_startendelement
);
2243 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
2244 &IID_IMXWriter
, (void**)&writer
);
2245 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
2247 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
2248 ok(hr
== S_OK
, "got %08x\n", hr
);
2250 hr
= IMXWriter_put_omitXMLDeclaration(writer
, VARIANT_TRUE
);
2251 ok(hr
== S_OK
, "got %08x\n", hr
);
2253 hr
= ISAXContentHandler_startDocument(content
);
2254 ok(hr
== S_OK
, "got %08x\n", hr
);
2256 /* all string pointers should be not null */
2257 hr
= ISAXContentHandler_startElement(content
, _bstr_(""), 0, _bstr_("b"), 1, _bstr_(""), 0, NULL
);
2258 ok(hr
== S_OK
, "got %08x\n", hr
);
2260 V_VT(&dest
) = VT_EMPTY
;
2261 hr
= IMXWriter_get_output(writer
, &dest
);
2262 ok(hr
== S_OK
, "got %08x\n", hr
);
2263 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2264 ok(!lstrcmpW(_bstr_("<>"), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2265 VariantClear(&dest
);
2267 hr
= ISAXContentHandler_startElement(content
, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1, NULL
);
2268 ok(hr
== S_OK
, "got %08x\n", hr
);
2270 V_VT(&dest
) = VT_EMPTY
;
2271 hr
= IMXWriter_get_output(writer
, &dest
);
2272 ok(hr
== S_OK
, "got %08x\n", hr
);
2273 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2274 ok(!lstrcmpW(_bstr_("<><b>"), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2275 VariantClear(&dest
);
2277 hr
= ISAXContentHandler_endElement(content
, NULL
, 0, NULL
, 0, _bstr_("a:b"), 3);
2278 EXPECT_HR(hr
, E_INVALIDARG
);
2280 hr
= ISAXContentHandler_endElement(content
, NULL
, 0, _bstr_("b"), 1, _bstr_("a:b"), 3);
2281 EXPECT_HR(hr
, E_INVALIDARG
);
2283 /* only local name is an error too */
2284 hr
= ISAXContentHandler_endElement(content
, NULL
, 0, _bstr_("b"), 1, NULL
, 0);
2285 EXPECT_HR(hr
, E_INVALIDARG
);
2287 hr
= ISAXContentHandler_endElement(content
, _bstr_(""), 0, _bstr_(""), 0, _bstr_("b"), 1);
2288 EXPECT_HR(hr
, S_OK
);
2290 V_VT(&dest
) = VT_EMPTY
;
2291 hr
= IMXWriter_get_output(writer
, &dest
);
2292 EXPECT_HR(hr
, S_OK
);
2293 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2294 ok(!lstrcmpW(_bstr_("<><b></b>"), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2295 VariantClear(&dest
);
2297 hr
= ISAXContentHandler_endDocument(content
);
2298 EXPECT_HR(hr
, S_OK
);
2300 V_VT(&dest
) = VT_EMPTY
;
2301 hr
= IMXWriter_put_output(writer
, dest
);
2302 EXPECT_HR(hr
, S_OK
);
2304 hr
= ISAXContentHandler_startDocument(content
);
2305 EXPECT_HR(hr
, S_OK
);
2307 hr
= ISAXContentHandler_startElement(content
, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abcdef"), 3, NULL
);
2308 EXPECT_HR(hr
, S_OK
);
2310 V_VT(&dest
) = VT_EMPTY
;
2311 hr
= IMXWriter_get_output(writer
, &dest
);
2312 EXPECT_HR(hr
, S_OK
);
2313 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2314 ok(!lstrcmpW(_bstr_("<abc>"), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2315 VariantClear(&dest
);
2317 ISAXContentHandler_endDocument(content
);
2318 IMXWriter_flush(writer
);
2320 hr
= ISAXContentHandler_endElement(content
, _bstr_(""), 0, _bstr_(""), 0, _bstr_("abdcdef"), 3);
2321 EXPECT_HR(hr
, S_OK
);
2322 V_VT(&dest
) = VT_EMPTY
;
2323 hr
= IMXWriter_get_output(writer
, &dest
);
2324 EXPECT_HR(hr
, S_OK
);
2325 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2326 ok(!lstrcmpW(_bstr_("<abc></abd>"), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2327 VariantClear(&dest
);
2329 ISAXContentHandler_Release(content
);
2330 IMXWriter_Release(writer
);
2334 static void test_mxwriter_characters(void)
2336 static const WCHAR chardataW
[] = {'T','E','S','T','C','H','A','R','D','A','T','A',' ','.',0};
2337 ISAXContentHandler
*content
;
2342 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
2343 &IID_IMXWriter
, (void**)&writer
);
2344 EXPECT_HR(hr
, S_OK
);
2346 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
2347 EXPECT_HR(hr
, S_OK
);
2349 hr
= IMXWriter_put_omitXMLDeclaration(writer
, VARIANT_TRUE
);
2350 EXPECT_HR(hr
, S_OK
);
2352 hr
= ISAXContentHandler_startDocument(content
);
2353 EXPECT_HR(hr
, S_OK
);
2355 hr
= ISAXContentHandler_characters(content
, NULL
, 0);
2356 EXPECT_HR(hr
, E_INVALIDARG
);
2358 hr
= ISAXContentHandler_characters(content
, chardataW
, 0);
2359 EXPECT_HR(hr
, S_OK
);
2361 hr
= ISAXContentHandler_characters(content
, chardataW
, sizeof(chardataW
)/sizeof(WCHAR
) - 1);
2362 EXPECT_HR(hr
, S_OK
);
2364 V_VT(&dest
) = VT_EMPTY
;
2365 hr
= IMXWriter_get_output(writer
, &dest
);
2366 EXPECT_HR(hr
, S_OK
);
2367 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2368 ok(!lstrcmpW(_bstr_("TESTCHARDATA ."), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2369 VariantClear(&dest
);
2371 hr
= ISAXContentHandler_endDocument(content
);
2372 EXPECT_HR(hr
, S_OK
);
2374 ISAXContentHandler_Release(content
);
2375 IMXWriter_Release(writer
);
2377 /* try empty characters data to see if element is closed */
2378 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
2379 &IID_IMXWriter
, (void**)&writer
);
2380 EXPECT_HR(hr
, S_OK
);
2382 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
2383 EXPECT_HR(hr
, S_OK
);
2385 hr
= IMXWriter_put_omitXMLDeclaration(writer
, VARIANT_TRUE
);
2386 EXPECT_HR(hr
, S_OK
);
2388 hr
= ISAXContentHandler_startDocument(content
);
2389 EXPECT_HR(hr
, S_OK
);
2391 hr
= ISAXContentHandler_startElement(content
, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1, NULL
);
2392 EXPECT_HR(hr
, S_OK
);
2394 hr
= ISAXContentHandler_characters(content
, chardataW
, 0);
2395 EXPECT_HR(hr
, S_OK
);
2397 hr
= ISAXContentHandler_endElement(content
, _bstr_(""), 0, _bstr_(""), 0, _bstr_("a"), 1);
2398 EXPECT_HR(hr
, S_OK
);
2400 V_VT(&dest
) = VT_EMPTY
;
2401 hr
= IMXWriter_get_output(writer
, &dest
);
2402 EXPECT_HR(hr
, S_OK
);
2403 ok(V_VT(&dest
) == VT_BSTR
, "got %d\n", V_VT(&dest
));
2404 ok(!lstrcmpW(_bstr_("<a></a>"), V_BSTR(&dest
)), "got wrong content %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2405 VariantClear(&dest
);
2407 ISAXContentHandler_Release(content
);
2408 IMXWriter_Release(writer
);
2413 static const mxwriter_stream_test mxwriter_stream_tests
[] = {
2415 VARIANT_TRUE
,"UTF-16",
2417 {FALSE
,(const BYTE
*)szUtf16BOM
,sizeof(szUtf16BOM
),TRUE
},
2418 {FALSE
,(const BYTE
*)szUtf16XML
,sizeof(szUtf16XML
)},
2423 VARIANT_FALSE
,"UTF-16",
2425 {FALSE
,(const BYTE
*)szUtf16XML
,sizeof(szUtf16XML
)},
2430 VARIANT_TRUE
,"UTF-8",
2432 {FALSE
,(const BYTE
*)szUtf8XML
,sizeof(szUtf8XML
)-1},
2433 /* For some reason Windows makes an empty write call when UTF-8 encoding is used
2434 * and the writer is released.
2441 VARIANT_TRUE
,"UTF-16",
2443 {FALSE
,(const BYTE
*)szUtf16BOM
,sizeof(szUtf16BOM
),TRUE
},
2444 {FALSE
,(const BYTE
*)szUtf16XML
,sizeof(szUtf16XML
)},
2449 VARIANT_TRUE
,"UTF-16",
2451 {FALSE
,(const BYTE
*)szUtf16BOM
,sizeof(szUtf16BOM
),TRUE
,TRUE
},
2452 {FALSE
,(const BYTE
*)szUtf16XML
,sizeof(szUtf16XML
)},
2458 static void test_mxwriter_stream(void)
2461 ISAXContentHandler
*content
;
2466 ULARGE_INTEGER pos2
;
2467 DWORD test_count
= sizeof(mxwriter_stream_tests
)/sizeof(mxwriter_stream_tests
[0]);
2469 for(current_stream_test_index
= 0; current_stream_test_index
< test_count
; ++current_stream_test_index
) {
2470 const mxwriter_stream_test
*test
= mxwriter_stream_tests
+current_stream_test_index
;
2472 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
2473 &IID_IMXWriter
, (void**)&writer
);
2474 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2476 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
2477 ok(hr
== S_OK
, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr
);
2479 hr
= IMXWriter_put_encoding(writer
, _bstr_(test
->encoding
));
2480 ok(hr
== S_OK
, "put_encoding failed with %08x on test %d\n", hr
, current_stream_test_index
);
2482 V_VT(&dest
) = VT_UNKNOWN
;
2483 V_UNKNOWN(&dest
) = (IUnknown
*)&mxstream
;
2484 hr
= IMXWriter_put_output(writer
, dest
);
2485 ok(hr
== S_OK
, "put_output failed with %08x on test %d\n", hr
, current_stream_test_index
);
2486 VariantClear(&dest
);
2488 hr
= IMXWriter_put_byteOrderMark(writer
, test
->bom
);
2489 ok(hr
== S_OK
, "put_byteOrderMark failed with %08x on test %d\n", hr
, current_stream_test_index
);
2491 current_write_test
= test
->expected_writes
;
2493 hr
= ISAXContentHandler_startDocument(content
);
2494 ok(hr
== S_OK
, "startDocument failed with %08x on test %d\n", hr
, current_stream_test_index
);
2496 hr
= ISAXContentHandler_endDocument(content
);
2497 ok(hr
== S_OK
, "endDocument failed with %08x on test %d\n", hr
, current_stream_test_index
);
2499 ISAXContentHandler_Release(content
);
2500 IMXWriter_Release(writer
);
2502 ok(current_write_test
->last
, "The last %d write calls on test %d were missed\n",
2503 (int)(current_write_test
-test
->expected_writes
), current_stream_test_index
);
2506 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
2507 &IID_IMXWriter
, (void**)&writer
);
2508 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2510 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2511 ok(hr
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hr
);
2513 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
2514 ok(hr
== S_OK
, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr
);
2516 hr
= IMXWriter_put_encoding(writer
, _bstr_("UTF-8"));
2517 ok(hr
== S_OK
, "put_encoding failed: %08x\n", hr
);
2519 V_VT(&dest
) = VT_UNKNOWN
;
2520 V_UNKNOWN(&dest
) = (IUnknown
*)stream
;
2521 hr
= IMXWriter_put_output(writer
, dest
);
2522 ok(hr
== S_OK
, "put_output failed: %08x\n", hr
);
2524 hr
= ISAXContentHandler_startDocument(content
);
2525 ok(hr
== S_OK
, "startDocument failed: %08x\n", hr
);
2527 /* Setting output of the mxwriter causes the current output to be flushed,
2528 * and the writer to start over.
2530 V_VT(&dest
) = VT_EMPTY
;
2531 hr
= IMXWriter_put_output(writer
, dest
);
2532 ok(hr
== S_OK
, "put_output failed: %08x\n", hr
);
2535 hr
= IStream_Seek(stream
, pos
, STREAM_SEEK_CUR
, &pos2
);
2536 ok(hr
== S_OK
, "Seek failed: %08x\n", hr
);
2537 ok(pos2
.QuadPart
!= 0, "expected stream position moved\n");
2539 hr
= ISAXContentHandler_startDocument(content
);
2540 ok(hr
== S_OK
, "startDocument failed: %08x\n", hr
);
2542 hr
= ISAXContentHandler_endDocument(content
);
2543 ok(hr
== S_OK
, "endDocument failed: %08x\n", hr
);
2545 V_VT(&dest
) = VT_EMPTY
;
2546 hr
= IMXWriter_get_output(writer
, &dest
);
2547 ok(hr
== S_OK
, "get_output failed: %08x\n", hr
);
2548 ok(V_VT(&dest
) == VT_BSTR
, "Expected VT_BSTR, got %d\n", V_VT(&dest
));
2549 ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest
)),
2550 "Got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2551 VariantClear(&dest
);
2553 ISAXContentHandler_Release(content
);
2554 IMXWriter_Release(writer
);
2559 static void test_mxwriter_encoding(void)
2562 ISAXContentHandler
*content
;
2566 hr
= CoCreateInstance(&CLSID_MXXMLWriter
, NULL
, CLSCTX_INPROC_SERVER
,
2567 &IID_IMXWriter
, (void**)&writer
);
2568 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2570 hr
= IMXWriter_QueryInterface(writer
, &IID_ISAXContentHandler
, (void**)&content
);
2571 ok(hr
== S_OK
, "QueryInterface(ISAXContentHandler) failed: %08x\n", hr
);
2573 hr
= IMXWriter_put_encoding(writer
, _bstr_("UTF-8"));
2574 ok(hr
== S_OK
, "put_encoding failed: %08x\n", hr
);
2576 hr
= ISAXContentHandler_startDocument(content
);
2577 ok(hr
== S_OK
, "startDocument failed: %08x\n", hr
);
2579 hr
= ISAXContentHandler_endDocument(content
);
2580 ok(hr
== S_OK
, "endDocument failed: %08x\n", hr
);
2582 /* The content is always re-encoded to UTF-16 when the output is
2583 * retrieved as a BSTR.
2585 V_VT(&dest
) = VT_EMPTY
;
2586 hr
= IMXWriter_get_output(writer
, &dest
);
2587 todo_wine
ok(hr
== S_OK
, "get_output failed: %08x\n", hr
);
2588 todo_wine
ok(V_VT(&dest
) == VT_BSTR
, "Expected VT_BSTR, got %d\n", V_VT(&dest
));
2589 if (V_VT(&dest
) == VT_BSTR
) todo_wine
ok(!lstrcmpW(_bstr_("<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"no\"?>\r\n"), V_BSTR(&dest
)),
2590 "got wrong content: %s\n", wine_dbgstr_w(V_BSTR(&dest
)));
2591 VariantClear(&dest
);
2593 ISAXContentHandler_Release(content
);
2594 IMXWriter_Release(writer
);
2599 START_TEST(saxreader
)
2601 ISAXXMLReader
*reader
;
2604 hr
= CoInitialize(NULL
);
2605 ok(hr
== S_OK
, "failed to init com\n");
2607 hr
= CoCreateInstance(&CLSID_SAXXMLReader
, NULL
, CLSCTX_INPROC_SERVER
,
2608 &IID_ISAXXMLReader
, (void**)&reader
);
2612 skip("Failed to create SAXXMLReader instance\n");
2616 ISAXXMLReader_Release(reader
);
2621 test_saxreader_properties();
2622 test_saxreader_features();
2625 /* MXXMLWriter tests */
2626 get_supported_mxwriter_data(msxmlsupported_data
);
2627 if (is_mxwriter_supported(&CLSID_MXXMLWriter
, msxmlsupported_data
))
2629 test_mxwriter_contenthandler();
2630 test_mxwriter_startenddocument();
2631 test_mxwriter_startendelement();
2632 test_mxwriter_characters();
2633 test_mxwriter_properties();
2634 test_mxwriter_flush();
2635 test_mxwriter_stream();
2636 test_mxwriter_encoding();
2639 win_skip("MXXMLWriter not supported\n");