4 * Copyright 2010, 2012-2013 Nikolay Sivov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 DEFINE_GUID(IID_IXmlReaderInput
, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda);
36 static HRESULT (WINAPI
*pCreateXmlReader
)(REFIID riid
, void **ppvObject
, IMalloc
*pMalloc
);
37 static HRESULT (WINAPI
*pCreateXmlReaderInputWithEncodingName
)(IUnknown
*stream
,
42 IXmlReaderInput
**ppInput
);
44 static WCHAR
*a2w(const char *str
)
46 int len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
47 WCHAR
*ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
48 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
52 static void free_str(WCHAR
*str
)
54 HeapFree(GetProcessHeap(), 0, str
);
57 static const char xmldecl_full
[] = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
58 static const char xmldecl_short
[] = "<?xml version=\"1.0\"?><RegistrationInfo/>";
60 static IStream
*create_stream_on_data(const char *data
, int size
)
62 IStream
*stream
= NULL
;
67 hglobal
= GlobalAlloc(GHND
, size
);
68 ptr
= GlobalLock(hglobal
);
70 memcpy(ptr
, data
, size
);
72 hr
= CreateStreamOnHGlobal(hglobal
, TRUE
, &stream
);
73 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
74 ok(stream
!= NULL
, "Expected non-NULL stream\n");
76 GlobalUnlock(hglobal
);
81 static void ok_pos_(IXmlReader
*reader
, int line
, int pos
, int line_broken
,
82 int pos_broken
, BOOL todo
, int _line_
)
88 hr
= IXmlReader_GetLineNumber(reader
, &l
);
89 ok_(__FILE__
, _line_
)(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
90 hr
= IXmlReader_GetLinePosition(reader
, &p
);
91 ok_(__FILE__
, _line_
)(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
93 if (line_broken
== -1 && pos_broken
== -1)
96 broken_state
= broken((line_broken
== -1 ? line
: line_broken
) == l
&&
97 (pos_broken
== -1 ? pos
: pos_broken
) == p
);
101 ok_(__FILE__
, _line_
)((l
== line
&& pos
== p
) || broken_state
,
102 "Expected (%d,%d), got (%d,%d)\n", line
, pos
, l
, p
);
105 ok_(__FILE__
, _line_
)((l
== line
&& pos
== p
) || broken_state
,
106 "Expected (%d,%d), got (%d,%d)\n", line
, pos
, l
, p
);
109 #define ok_pos(reader, l, p, l_brk, p_brk, todo) ok_pos_(reader, l, p, l_brk, p_brk, todo, __LINE__)
111 typedef struct input_iids_t
{
116 static const IID
*setinput_full
[] = {
117 &IID_IXmlReaderInput
,
119 &IID_ISequentialStream
,
123 /* this applies to early xmllite versions */
124 static const IID
*setinput_full_old
[] = {
125 &IID_IXmlReaderInput
,
126 &IID_ISequentialStream
,
131 /* after ::SetInput(IXmlReaderInput*) */
132 static const IID
*setinput_readerinput
[] = {
134 &IID_ISequentialStream
,
138 static const IID
*empty_seq
[] = {
142 static input_iids_t input_iids
;
144 static void ok_iids_(const input_iids_t
*iids
, const IID
**expected
, const IID
**exp_broken
, BOOL todo
, int line
)
148 while (expected
[i
++]) size
++;
152 ok_(__FILE__
, line
)(iids
->count
== size
, "Sequence size mismatch (%d), got (%d)\n", size
, iids
->count
);
155 ok_(__FILE__
, line
)(iids
->count
== size
, "Sequence size mismatch (%d), got (%d)\n", size
, iids
->count
);
157 if (iids
->count
!= size
) return;
159 for (i
= 0; i
< size
; i
++) {
160 ok_(__FILE__
, line
)(IsEqualGUID(&iids
->iids
[i
], expected
[i
]) ||
161 (exp_broken
? broken(IsEqualGUID(&iids
->iids
[i
], exp_broken
[i
])) : FALSE
),
162 "Wrong IID(%d), got %s\n", i
, wine_dbgstr_guid(&iids
->iids
[i
]));
165 #define ok_iids(got, exp, brk, todo) ok_iids_(got, exp, brk, todo, __LINE__)
167 static const char *state_to_str(XmlReadState state
)
169 static const char* state_names
[] = {
170 "XmlReadState_Initial",
171 "XmlReadState_Interactive",
172 "XmlReadState_Error",
173 "XmlReadState_EndOfFile",
174 "XmlReadState_Closed"
177 static const char unknown
[] = "unknown";
181 case XmlReadState_Initial
:
182 case XmlReadState_Interactive
:
183 case XmlReadState_Error
:
184 case XmlReadState_EndOfFile
:
185 case XmlReadState_Closed
:
186 return state_names
[state
];
192 static const char *type_to_str(XmlNodeType type
)
194 static const char* type_names
[] = {
196 "XmlNodeType_Element",
197 "XmlNodeType_Attribute",
201 "XmlNodeType_ProcessingInstruction",
202 "XmlNodeType_Comment",
204 "XmlNodeType_DocumentType",
206 "XmlNodeType_Whitespace",
208 "XmlNodeType_EndElement",
210 "XmlNodeType_XmlDeclaration"
213 static const char unknown
[] = "unknown";
217 case XmlNodeType_None
:
218 case XmlNodeType_Element
:
219 case XmlNodeType_Attribute
:
220 case XmlNodeType_Text
:
221 case XmlNodeType_CDATA
:
222 case XmlNodeType_ProcessingInstruction
:
223 case XmlNodeType_Comment
:
224 case XmlNodeType_DocumentType
:
225 case XmlNodeType_Whitespace
:
226 case XmlNodeType_EndElement
:
227 case XmlNodeType_XmlDeclaration
:
228 return type_names
[type
];
234 static void test_read_state_(IXmlReader
*reader
, XmlReadState expected
,
235 XmlReadState exp_broken
, BOOL todo
, int line
)
241 state
= -1; /* invalid value */
242 hr
= IXmlReader_GetProperty(reader
, XmlReaderProperty_ReadState
, &state
);
243 ok_(__FILE__
, line
)(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
245 if (exp_broken
== -1)
246 broken_state
= FALSE
;
248 broken_state
= broken(exp_broken
== state
);
253 ok_(__FILE__
, line
)(state
== expected
|| broken_state
, "Expected (%s), got (%s)\n",
254 state_to_str(expected
), state_to_str(state
));
257 ok_(__FILE__
, line
)(state
== expected
|| broken_state
, "Expected (%s), got (%s)\n",
258 state_to_str(expected
), state_to_str(state
));
261 #define test_read_state(reader, exp, brk, todo) test_read_state_(reader, exp, brk, todo, __LINE__)
263 typedef struct _testinput
265 IUnknown IUnknown_iface
;
269 static inline testinput
*impl_from_IUnknown(IUnknown
*iface
)
271 return CONTAINING_RECORD(iface
, testinput
, IUnknown_iface
);
274 static HRESULT WINAPI
testinput_QueryInterface(IUnknown
*iface
, REFIID riid
, void** ppvObj
)
276 if (IsEqualGUID( riid
, &IID_IUnknown
))
279 IUnknown_AddRef(iface
);
283 input_iids
.iids
[input_iids
.count
++] = *riid
;
287 return E_NOINTERFACE
;
290 static ULONG WINAPI
testinput_AddRef(IUnknown
*iface
)
292 testinput
*This
= impl_from_IUnknown(iface
);
293 return InterlockedIncrement(&This
->ref
);
296 static ULONG WINAPI
testinput_Release(IUnknown
*iface
)
298 testinput
*This
= impl_from_IUnknown(iface
);
301 ref
= InterlockedDecrement(&This
->ref
);
304 HeapFree(GetProcessHeap(), 0, This
);
310 static const struct IUnknownVtbl testinput_vtbl
=
312 testinput_QueryInterface
,
317 static HRESULT
testinput_createinstance(void **ppObj
)
321 input
= HeapAlloc(GetProcessHeap(), 0, sizeof (*input
));
322 if(!input
) return E_OUTOFMEMORY
;
324 input
->IUnknown_iface
.lpVtbl
= &testinput_vtbl
;
327 *ppObj
= &input
->IUnknown_iface
;
332 static HRESULT WINAPI
teststream_QueryInterface(ISequentialStream
*iface
, REFIID riid
, void **obj
)
334 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_ISequentialStream
))
341 return E_NOINTERFACE
;
344 static ULONG WINAPI
teststream_AddRef(ISequentialStream
*iface
)
349 static ULONG WINAPI
teststream_Release(ISequentialStream
*iface
)
354 static int stream_readcall
;
356 static HRESULT WINAPI
teststream_Read(ISequentialStream
*iface
, void *pv
, ULONG cb
, ULONG
*pread
)
358 static const char xml
[] = "<!-- comment -->";
360 if (stream_readcall
++)
366 *pread
= sizeof(xml
) / 2;
367 memcpy(pv
, xml
, *pread
);
371 static HRESULT WINAPI
teststream_Write(ISequentialStream
*iface
, const void *pv
, ULONG cb
, ULONG
*written
)
373 ok(0, "unexpected call\n");
377 static const ISequentialStreamVtbl teststreamvtbl
=
379 teststream_QueryInterface
,
386 static BOOL
init_pointers(void)
388 /* don't free module here, it's to be unloaded on exit */
389 HMODULE mod
= LoadLibraryA("xmllite.dll");
393 win_skip("xmllite library not available\n");
397 #define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
398 MAKEFUNC(CreateXmlReader
);
399 MAKEFUNC(CreateXmlReaderInputWithEncodingName
);
405 static void test_reader_create(void)
411 XmlNodeType nodetype
;
416 pCreateXmlReader(&IID_IXmlReader
, NULL
, NULL
);
417 pCreateXmlReader(NULL
, (void**)&reader
, NULL
);
420 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
421 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
423 test_read_state(reader
, XmlReadState_Closed
, -1, FALSE
);
425 nodetype
= XmlNodeType_Element
;
426 hr
= IXmlReader_GetNodeType(reader
, &nodetype
);
427 ok(hr
== S_FALSE
, "got %08x\n", hr
);
428 ok(nodetype
== XmlNodeType_None
, "got %d\n", nodetype
);
431 hr
= IXmlReader_GetProperty(reader
, XmlReaderProperty_DtdProcessing
, (LONG_PTR
*)&dtd
);
432 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
433 ok(dtd
== DtdProcessing_Prohibit
, "got %d\n", dtd
);
436 hr
= IXmlReader_SetProperty(reader
, XmlReaderProperty_DtdProcessing
, dtd
);
437 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
439 hr
= IXmlReader_SetProperty(reader
, XmlReaderProperty_DtdProcessing
, -1);
440 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
442 /* Null input pointer, releases previous input */
443 hr
= IXmlReader_SetInput(reader
, NULL
);
444 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
446 test_read_state(reader
, XmlReadState_Initial
, XmlReadState_Closed
, FALSE
);
448 /* test input interface selection sequence */
449 hr
= testinput_createinstance((void**)&input
);
450 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
454 input_iids
.count
= 0;
455 hr
= IXmlReader_SetInput(reader
, input
);
456 ok(hr
== E_NOINTERFACE
, "Expected E_NOINTERFACE, got %08x\n", hr
);
457 ok_iids(&input_iids
, setinput_full
, setinput_full_old
, FALSE
);
458 IUnknown_Release(input
);
460 IXmlReader_Release(reader
);
463 static void test_readerinput(void)
465 IXmlReaderInput
*reader_input
;
466 IXmlReader
*reader
, *reader2
;
467 IUnknown
*obj
, *input
;
468 IStream
*stream
, *stream2
;
469 XmlNodeType nodetype
;
473 hr
= pCreateXmlReaderInputWithEncodingName(NULL
, NULL
, NULL
, FALSE
, NULL
, NULL
);
474 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
475 hr
= pCreateXmlReaderInputWithEncodingName(NULL
, NULL
, NULL
, FALSE
, NULL
, &reader_input
);
476 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
478 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
479 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
481 ref
= IStream_AddRef(stream
);
482 ok(ref
== 2, "Expected 2, got %d\n", ref
);
483 IStream_Release(stream
);
484 hr
= pCreateXmlReaderInputWithEncodingName((IUnknown
*)stream
, NULL
, NULL
, FALSE
, NULL
, &reader_input
);
485 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
487 hr
= IUnknown_QueryInterface(reader_input
, &IID_IStream
, (void**)&stream2
);
488 ok(hr
== E_NOINTERFACE
, "Expected S_OK, got %08x\n", hr
);
490 hr
= IUnknown_QueryInterface(reader_input
, &IID_ISequentialStream
, (void**)&stream2
);
491 ok(hr
== E_NOINTERFACE
, "Expected S_OK, got %08x\n", hr
);
493 /* IXmlReaderInput grabs a stream reference */
494 ref
= IStream_AddRef(stream
);
495 ok(ref
== 3, "Expected 3, got %d\n", ref
);
496 IStream_Release(stream
);
498 /* try ::SetInput() with valid IXmlReaderInput */
499 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
500 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
502 ref
= IUnknown_AddRef(reader_input
);
503 ok(ref
== 2, "Expected 2, got %d\n", ref
);
504 IUnknown_Release(reader_input
);
506 hr
= IXmlReader_SetInput(reader
, reader_input
);
507 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
509 test_read_state(reader
, XmlReadState_Initial
, -1, FALSE
);
511 nodetype
= XmlNodeType_Element
;
512 hr
= IXmlReader_GetNodeType(reader
, &nodetype
);
513 ok(hr
== S_OK
, "got %08x\n", hr
);
514 ok(nodetype
== XmlNodeType_None
, "got %d\n", nodetype
);
516 /* IXmlReader grabs a IXmlReaderInput reference */
517 ref
= IUnknown_AddRef(reader_input
);
518 ok(ref
== 3, "Expected 3, got %d\n", ref
);
519 IUnknown_Release(reader_input
);
521 ref
= IStream_AddRef(stream
);
522 ok(ref
== 4, "Expected 4, got %d\n", ref
);
523 IStream_Release(stream
);
525 /* reset input and check state */
526 hr
= IXmlReader_SetInput(reader
, NULL
);
527 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
529 test_read_state(reader
, XmlReadState_Initial
, XmlReadState_Closed
, FALSE
);
531 IXmlReader_Release(reader
);
533 ref
= IStream_AddRef(stream
);
534 ok(ref
== 3, "Expected 3, got %d\n", ref
);
535 IStream_Release(stream
);
537 ref
= IUnknown_AddRef(reader_input
);
538 ok(ref
== 2, "Expected 2, got %d\n", ref
);
539 IUnknown_Release(reader_input
);
541 /* IID_IXmlReaderInput */
542 /* it returns a kind of private undocumented vtable incompatible with IUnknown,
543 so it's not a COM interface actually.
544 Such query will be used only to check if input is really IXmlReaderInput */
545 obj
= (IUnknown
*)0xdeadbeef;
546 hr
= IUnknown_QueryInterface(reader_input
, &IID_IXmlReaderInput
, (void**)&obj
);
547 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
548 ref
= IUnknown_AddRef(reader_input
);
549 ok(ref
== 3, "Expected 3, got %d\n", ref
);
550 IUnknown_Release(reader_input
);
552 IUnknown_Release(reader_input
);
553 IUnknown_Release(reader_input
);
554 IStream_Release(stream
);
556 /* test input interface selection sequence */
558 hr
= testinput_createinstance((void**)&input
);
559 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
561 input_iids
.count
= 0;
562 ref
= IUnknown_AddRef(input
);
563 ok(ref
== 2, "Expected 2, got %d\n", ref
);
564 IUnknown_Release(input
);
565 hr
= pCreateXmlReaderInputWithEncodingName(input
, NULL
, NULL
, FALSE
, NULL
, &reader_input
);
566 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
567 ok_iids(&input_iids
, empty_seq
, NULL
, FALSE
);
568 /* IXmlReaderInput stores stream interface as IUnknown */
569 ref
= IUnknown_AddRef(input
);
570 ok(ref
== 3, "Expected 3, got %d\n", ref
);
571 IUnknown_Release(input
);
573 hr
= pCreateXmlReader(&IID_IXmlReader
, (LPVOID
*)&reader
, NULL
);
574 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
576 input_iids
.count
= 0;
577 ref
= IUnknown_AddRef(reader_input
);
578 ok(ref
== 2, "Expected 2, got %d\n", ref
);
579 IUnknown_Release(reader_input
);
580 ref
= IUnknown_AddRef(input
);
581 ok(ref
== 3, "Expected 3, got %d\n", ref
);
582 IUnknown_Release(input
);
583 hr
= IXmlReader_SetInput(reader
, reader_input
);
584 ok(hr
== E_NOINTERFACE
, "Expected E_NOINTERFACE, got %08x\n", hr
);
585 ok_iids(&input_iids
, setinput_readerinput
, NULL
, FALSE
);
587 test_read_state(reader
, XmlReadState_Closed
, -1, FALSE
);
589 ref
= IUnknown_AddRef(input
);
590 ok(ref
== 3, "Expected 3, got %d\n", ref
);
591 IUnknown_Release(input
);
593 ref
= IUnknown_AddRef(reader_input
);
594 ok(ref
== 3 || broken(ref
== 2) /* versions 1.0.x and 1.1.x - XP, Vista */,
595 "Expected 3, got %d\n", ref
);
596 IUnknown_Release(reader_input
);
597 /* repeat another time, no check or caching here */
598 input_iids
.count
= 0;
599 hr
= IXmlReader_SetInput(reader
, reader_input
);
600 ok(hr
== E_NOINTERFACE
, "Expected E_NOINTERFACE, got %08x\n", hr
);
601 ok_iids(&input_iids
, setinput_readerinput
, NULL
, FALSE
);
604 hr
= pCreateXmlReader(&IID_IXmlReader
, (LPVOID
*)&reader2
, NULL
);
605 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
607 /* resolving from IXmlReaderInput to IStream/ISequentialStream is done at
608 ::SetInput() level, each time it's called */
609 input_iids
.count
= 0;
610 hr
= IXmlReader_SetInput(reader2
, reader_input
);
611 ok(hr
== E_NOINTERFACE
, "Expected E_NOINTERFACE, got %08x\n", hr
);
612 ok_iids(&input_iids
, setinput_readerinput
, NULL
, FALSE
);
614 IXmlReader_Release(reader2
);
615 IXmlReader_Release(reader
);
617 IUnknown_Release(reader_input
);
618 IUnknown_Release(input
);
621 static void test_reader_state(void)
624 XmlNodeType nodetype
;
627 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
628 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
630 /* invalid arguments */
631 hr
= IXmlReader_GetProperty(reader
, XmlReaderProperty_ReadState
, NULL
);
632 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
634 /* attempt to read on closed reader */
635 test_read_state(reader
, XmlReadState_Closed
, -1, FALSE
);
638 /* newer versions crash here, probably cause no input was set */
639 hr
= IXmlReader_Read(reader
, &nodetype
);
640 ok(hr
== S_FALSE
, "got %08x\n", hr
);
642 IXmlReader_Release(reader
);
645 static void test_read_xmldeclaration(void)
647 static const WCHAR xmlW
[] = {'x','m','l',0};
648 static const WCHAR RegistrationInfoW
[] = {'R','e','g','i','s','t','r','a','t','i','o','n','I','n','f','o',0};
655 { {'v','e','r','s','i','o','n',0}, {'1','.','0',0} },
656 { {'e','n','c','o','d','i','n','g',0}, {'U','T','F','-','8',0} },
657 { {'s','t','a','n','d','a','l','o','n','e',0}, {'y','e','s',0} }
663 UINT count
= 0, len
, i
;
667 hr
= pCreateXmlReader(&IID_IXmlReader
, (LPVOID
*)&reader
, NULL
);
668 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
670 /* position methods with Null args */
671 hr
= IXmlReader_GetLineNumber(reader
, NULL
);
672 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
674 hr
= IXmlReader_GetLinePosition(reader
, NULL
);
675 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %08x\n", hr
);
677 stream
= create_stream_on_data(xmldecl_full
, sizeof(xmldecl_full
));
679 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
680 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
682 hr
= IXmlReader_GetAttributeCount(reader
, &count
);
683 ok(hr
== S_OK
, "got %08x\n", hr
);
684 ok(count
== 0, "got %d\n", count
);
686 /* try to move without attributes */
687 hr
= IXmlReader_MoveToElement(reader
);
688 ok(hr
== S_FALSE
, "got %08x\n", hr
);
690 hr
= IXmlReader_MoveToNextAttribute(reader
);
691 ok(hr
== S_FALSE
, "got %08x\n", hr
);
693 hr
= IXmlReader_MoveToFirstAttribute(reader
);
694 ok(hr
== S_FALSE
, "got %08x\n", hr
);
696 ok_pos(reader
, 0, 0, -1, -1, FALSE
);
699 hr
= IXmlReader_Read(reader
, &type
);
700 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
701 ok(type
== XmlNodeType_XmlDeclaration
,
702 "Expected XmlNodeType_XmlDeclaration, got %s\n", type_to_str(type
));
703 /* new version 1.2.x and 1.3.x properly update position for <?xml ?> */
704 ok_pos(reader
, 1, 3, -1, 55, TRUE
);
705 test_read_state(reader
, XmlReadState_Interactive
, -1, FALSE
);
707 hr
= IXmlReader_GetValue(reader
, &val
, NULL
);
708 ok(hr
== S_OK
, "got %08x\n", hr
);
709 ok(*val
== 0, "got %s\n", wine_dbgstr_w(val
));
711 /* check attributes */
712 hr
= IXmlReader_MoveToNextAttribute(reader
);
713 ok(hr
== S_OK
, "got %08x\n", hr
);
715 type
= XmlNodeType_None
;
716 hr
= IXmlReader_GetNodeType(reader
, &type
);
717 ok(hr
== S_OK
, "got %08x\n", hr
);
718 ok(type
== XmlNodeType_Attribute
, "got %d\n", type
);
720 ok_pos(reader
, 1, 7, -1, 55, TRUE
);
722 /* try to move from last attribute */
723 hr
= IXmlReader_MoveToNextAttribute(reader
);
724 ok(hr
== S_OK
, "got %08x\n", hr
);
725 hr
= IXmlReader_MoveToNextAttribute(reader
);
726 ok(hr
== S_OK
, "got %08x\n", hr
);
727 hr
= IXmlReader_MoveToNextAttribute(reader
);
728 ok(hr
== S_FALSE
, "got %08x\n", hr
);
730 type
= XmlNodeType_None
;
731 hr
= IXmlReader_GetNodeType(reader
, &type
);
732 ok(hr
== S_OK
, "got %08x\n", hr
);
733 ok(type
== XmlNodeType_Attribute
, "got %d\n", type
);
735 hr
= IXmlReader_MoveToFirstAttribute(reader
);
736 ok(hr
== S_OK
, "got %08x\n", hr
);
737 ok_pos(reader
, 1, 7, -1, 55, TRUE
);
739 hr
= IXmlReader_GetAttributeCount(reader
, NULL
);
740 ok(hr
== E_INVALIDARG
, "got %08x\n", hr
);
742 hr
= IXmlReader_GetAttributeCount(reader
, &count
);
743 ok(hr
== S_OK
, "got %08x\n", hr
);
744 ok(count
== 3, "Expected 3, got %d\n", count
);
746 for (i
= 0; i
< count
; i
++)
749 hr
= IXmlReader_GetLocalName(reader
, &val
, &len
);
750 ok(hr
== S_OK
, "got %08x\n", hr
);
751 ok(len
== lstrlenW(name_val
[i
].name
), "expected %u, got %u\n", lstrlenW(name_val
[i
].name
), len
);
752 ok(!lstrcmpW(name_val
[i
].name
, val
), "expected %s, got %s\n", wine_dbgstr_w(name_val
[i
].name
), wine_dbgstr_w(val
));
755 hr
= IXmlReader_GetValue(reader
, &val
, &len
);
756 ok(hr
== S_OK
, "got %08x\n", hr
);
757 ok(len
== lstrlenW(name_val
[i
].val
), "expected %u, got %u\n", lstrlenW(name_val
[i
].val
), len
);
758 ok(!lstrcmpW(name_val
[i
].val
, val
), "expected %s, got %s\n", wine_dbgstr_w(name_val
[i
].val
), wine_dbgstr_w(val
));
760 hr
= IXmlReader_MoveToNextAttribute(reader
);
761 ok(hr
== ((i
< count
- 1) ? S_OK
: S_FALSE
), "got %08x\n", hr
);
764 hr
= IXmlReader_GetDepth(reader
, &count
);
765 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
766 ok(count
== 1, "Expected 1, got %d\n", count
);
768 hr
= IXmlReader_MoveToElement(reader
);
769 ok(hr
== S_OK
, "got %08x\n", hr
);
771 type
= XmlNodeType_None
;
772 hr
= IXmlReader_GetNodeType(reader
, &type
);
773 ok(hr
== S_OK
, "got %08x\n", hr
);
774 ok(type
== XmlNodeType_XmlDeclaration
, "got %d\n", type
);
776 type
= XmlNodeType_XmlDeclaration
;
777 hr
= IXmlReader_Read(reader
, &type
);
778 /* newer versions return syntax error here cause document is incomplete,
779 it makes more sense than invalid char error */
781 ok(hr
== WC_E_SYNTAX
|| broken(hr
== WC_E_XMLCHARACTER
), "got 0x%08x\n", hr
);
782 ok(type
== XmlNodeType_None
, "got %d\n", type
);
784 IStream_Release(stream
);
786 /* test short variant */
787 stream
= create_stream_on_data(xmldecl_short
, sizeof(xmldecl_short
));
789 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
790 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
793 hr
= IXmlReader_Read(reader
, &type
);
794 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
795 ok(type
== XmlNodeType_XmlDeclaration
, "expected XmlDeclaration, got %s\n", type_to_str(type
));
796 ok_pos(reader
, 1, 3, 1, 21, TRUE
);
797 test_read_state(reader
, XmlReadState_Interactive
, -1, TRUE
);
799 hr
= IXmlReader_GetAttributeCount(reader
, &count
);
800 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
801 ok(count
== 1, "expected 1, got %d\n", count
);
803 ret
= IXmlReader_IsEmptyElement(reader
);
804 ok(!ret
, "element should not be empty\n");
806 hr
= IXmlReader_GetValue(reader
, &val
, NULL
);
807 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
808 ok(*val
== 0, "got %s\n", wine_dbgstr_w(val
));
810 hr
= IXmlReader_GetLocalName(reader
, &val
, NULL
);
811 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
813 ok(!lstrcmpW(val
, xmlW
), "got %s\n", wine_dbgstr_w(val
));
815 /* check attributes */
816 hr
= IXmlReader_MoveToNextAttribute(reader
);
817 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
820 hr
= IXmlReader_GetNodeType(reader
, &type
);
821 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
822 ok(type
== XmlNodeType_Attribute
, "got %d\n", type
);
823 ok_pos(reader
, 1, 7, 1, 21, TRUE
);
825 /* try to move from last attribute */
826 hr
= IXmlReader_MoveToNextAttribute(reader
);
827 ok(hr
== S_FALSE
, "expected S_FALSE, got %08x\n", hr
);
830 hr
= IXmlReader_Read(reader
, &type
);
831 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
832 ok(type
== XmlNodeType_Element
, "expected Element, got %s\n", type_to_str(type
));
833 ok_pos(reader
, 1, 23, 1, 40, TRUE
);
834 test_read_state(reader
, XmlReadState_Interactive
, -1, TRUE
);
836 hr
= IXmlReader_GetAttributeCount(reader
, &count
);
837 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
838 ok(count
== 0, "expected 0, got %d\n", count
);
840 ret
= IXmlReader_IsEmptyElement(reader
);
841 ok(ret
, "element should be empty\n");
843 hr
= IXmlReader_GetValue(reader
, &val
, NULL
);
844 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
846 ok(*val
== 0, "got %s\n", wine_dbgstr_w(val
));
848 hr
= IXmlReader_GetLocalName(reader
, &val
, NULL
);
849 ok(hr
== S_OK
, "expected S_OK, got %08x\n", hr
);
850 ok(!lstrcmpW(val
, RegistrationInfoW
), "got %s\n", wine_dbgstr_w(val
));
853 hr
= IXmlReader_Read(reader
, &type
);
855 ok(hr
== WC_E_SYNTAX
|| hr
== WC_E_XMLCHARACTER
/* XP */, "expected WC_E_SYNTAX, got %08x\n", hr
);
857 ok(type
== XmlNodeType_None
, "expected None, got %s\n", type_to_str(type
));
858 ok_pos(reader
, 1, 41, -1, -1, TRUE
);
859 test_read_state(reader
, XmlReadState_Error
, -1, TRUE
);
861 IStream_Release(stream
);
862 IXmlReader_Release(reader
);
870 HRESULT hr_broken
; /* this is set to older version results */
874 static struct test_entry comment_tests
[] = {
875 { "<!-- comment -->", "", " comment ", S_OK
},
876 { "<!-- - comment-->", "", " - comment", S_OK
},
877 { "<!-- -- comment-->", NULL
, NULL
, WC_E_COMMENT
, WC_E_GREATERTHAN
},
878 { "<!-- -- comment--->", NULL
, NULL
, WC_E_COMMENT
, WC_E_GREATERTHAN
},
882 static void test_read_comment(void)
884 struct test_entry
*test
= comment_tests
;
888 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
889 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
896 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
897 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
898 ok(hr
== S_OK
, "got %08x\n", hr
);
900 type
= XmlNodeType_None
;
901 hr
= IXmlReader_Read(reader
, &type
);
903 ok(hr
== test
->hr
|| broken(hr
== test
->hr_broken
), "got %08x for %s\n", hr
, test
->xml
);
905 ok(hr
== test
->hr
, "got %08x for %s\n", hr
, test
->xml
);
912 ok(type
== XmlNodeType_Comment
, "got %d for %s\n", type
, test
->xml
);
916 hr
= IXmlReader_GetLocalName(reader
, &str
, &len
);
917 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
918 ok(len
== strlen(test
->name
), "got %u\n", len
);
919 str_exp
= a2w(test
->name
);
920 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
925 hr
= IXmlReader_GetQualifiedName(reader
, &str
, &len
);
926 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
927 ok(len
== strlen(test
->name
), "got %u\n", len
);
928 str_exp
= a2w(test
->name
);
929 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
935 hr
= IXmlReader_GetValue(reader
, &str
, &len
);
936 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
937 ok(len
== strlen(test
->value
), "got %u\n", len
);
938 str_exp
= a2w(test
->value
);
939 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
943 IStream_Release(stream
);
947 IXmlReader_Release(reader
);
950 static struct test_entry pi_tests
[] = {
951 { "<?pi?>", "pi", "", S_OK
},
952 { "<?pi ?>", "pi", "", S_OK
},
953 { "<?pi ?>", "pi", "", S_OK
},
954 { "<?pi pi data?>", "pi", "pi data", S_OK
},
955 { "<?pi pi data ?>", "pi", "pi data ", S_OK
},
956 { "<?pi data ?>", "pi", "data ", S_OK
},
957 { "<?pi:pi?>", NULL
, NULL
, NC_E_NAMECOLON
, WC_E_NAMECHARACTER
},
958 { "<?:pi ?>", NULL
, NULL
, WC_E_PI
, WC_E_NAMECHARACTER
},
959 { "<?-pi ?>", NULL
, NULL
, WC_E_PI
, WC_E_NAMECHARACTER
},
960 { "<?xml-stylesheet ?>", "xml-stylesheet", "", S_OK
},
964 static void test_read_pi(void)
966 struct test_entry
*test
= pi_tests
;
970 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
971 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
978 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
979 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
980 ok(hr
== S_OK
, "got %08x\n", hr
);
982 type
= XmlNodeType_None
;
983 hr
= IXmlReader_Read(reader
, &type
);
985 ok(hr
== test
->hr
|| broken(hr
== test
->hr_broken
), "got %08x for %s\n", hr
, test
->xml
);
987 ok(hr
== test
->hr
, "got %08x for %s\n", hr
, test
->xml
);
994 ok(type
== XmlNodeType_ProcessingInstruction
, "got %d for %s\n", type
, test
->xml
);
998 hr
= IXmlReader_GetLocalName(reader
, &str
, &len
);
999 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1000 ok(len
== strlen(test
->name
), "got %u\n", len
);
1001 str_exp
= a2w(test
->name
);
1002 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1007 hr
= IXmlReader_GetQualifiedName(reader
, &str
, &len
);
1008 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1009 ok(len
== strlen(test
->name
), "got %u\n", len
);
1010 str_exp
= a2w(test
->name
);
1011 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1015 len
= !strlen(test
->value
);
1017 hr
= IXmlReader_GetValue(reader
, &str
, &len
);
1018 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1019 ok(len
== strlen(test
->value
), "got %u\n", len
);
1020 str_exp
= a2w(test
->value
);
1021 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1025 IStream_Release(stream
);
1029 IXmlReader_Release(reader
);
1034 XmlNodeType types
[20];
1037 static const char misc_test_xml
[] =
1055 static struct nodes_test misc_test
= {
1058 XmlNodeType_Comment
,
1059 XmlNodeType_Comment
,
1060 XmlNodeType_ProcessingInstruction
,
1061 XmlNodeType_Comment
,
1062 XmlNodeType_Whitespace
,
1063 XmlNodeType_Comment
,
1064 XmlNodeType_Element
,
1065 XmlNodeType_Whitespace
,
1066 XmlNodeType_Element
,
1068 XmlNodeType_Comment
,
1070 XmlNodeType_ProcessingInstruction
,
1071 XmlNodeType_Whitespace
,
1072 XmlNodeType_EndElement
,
1077 static void test_read_full(void)
1079 struct nodes_test
*test
= &misc_test
;
1086 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1087 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1089 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
1090 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1091 ok(hr
== S_OK
, "got %08x\n", hr
);
1094 type
= XmlNodeType_None
;
1095 hr
= IXmlReader_Read(reader
, &type
);
1098 ok(test
->types
[i
] != XmlNodeType_None
, "%d: unexpected end of test data\n", i
);
1099 if (test
->types
[i
] == XmlNodeType_None
) break;
1100 ok(type
== test
->types
[i
], "%d: got wrong type %d, expected %d\n", i
, type
, test
->types
[i
]);
1101 if (type
== XmlNodeType_Whitespace
)
1106 hr
= IXmlReader_GetValue(reader
, &ptr
, &len
);
1107 ok(hr
== S_OK
, "%d: GetValue failed 0x%08x\n", i
, hr
);
1108 ok(len
> 0, "%d: wrong value length %d\n", i
, len
);
1110 hr
= IXmlReader_Read(reader
, &type
);
1113 ok(test
->types
[i
] == XmlNodeType_None
, "incomplete sequence, got %d\n", test
->types
[i
]);
1115 IStream_Release(stream
);
1116 IXmlReader_Release(reader
);
1119 static const char test_dtd
[] =
1120 "<!DOCTYPE testdtd SYSTEM \"externalid uri\" >"
1123 static void test_read_dtd(void)
1125 static const WCHAR sysvalW
[] = {'e','x','t','e','r','n','a','l','i','d',' ','u','r','i',0};
1126 static const WCHAR dtdnameW
[] = {'t','e','s','t','d','t','d',0};
1127 static const WCHAR sysW
[] = {'S','Y','S','T','E','M',0};
1135 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1136 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1138 hr
= IXmlReader_SetProperty(reader
, XmlReaderProperty_DtdProcessing
, DtdProcessing_Parse
);
1139 ok(hr
== S_OK
, "got 0x%8x\n", hr
);
1141 stream
= create_stream_on_data(test_dtd
, sizeof(test_dtd
));
1142 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1143 ok(hr
== S_OK
, "got %08x\n", hr
);
1145 type
= XmlNodeType_None
;
1146 hr
= IXmlReader_Read(reader
, &type
);
1147 ok(hr
== S_OK
, "got 0x%8x\n", hr
);
1148 ok(type
== XmlNodeType_DocumentType
, "got type %d\n", type
);
1151 hr
= IXmlReader_GetAttributeCount(reader
, &count
);
1152 ok(hr
== S_OK
, "got %08x\n", hr
);
1153 ok(count
== 1, "got %d\n", count
);
1155 hr
= IXmlReader_MoveToFirstAttribute(reader
);
1156 ok(hr
== S_OK
, "got %08x\n", hr
);
1158 type
= XmlNodeType_None
;
1159 hr
= IXmlReader_GetNodeType(reader
, &type
);
1160 ok(hr
== S_OK
, "got %08x\n", hr
);
1161 ok(type
== XmlNodeType_Attribute
, "got %d\n", type
);
1165 hr
= IXmlReader_GetLocalName(reader
, &str
, &len
);
1166 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1167 ok(len
== lstrlenW(sysW
), "got %u\n", len
);
1168 ok(!lstrcmpW(str
, sysW
), "got %s\n", wine_dbgstr_w(str
));
1172 hr
= IXmlReader_GetValue(reader
, &str
, &len
);
1173 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1174 ok(len
== lstrlenW(sysvalW
), "got %u\n", len
);
1175 ok(!lstrcmpW(str
, sysvalW
), "got %s\n", wine_dbgstr_w(str
));
1177 hr
= IXmlReader_MoveToElement(reader
);
1178 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1182 hr
= IXmlReader_GetLocalName(reader
, &str
, &len
);
1183 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1185 ok(len
== lstrlenW(dtdnameW
), "got %u\n", len
);
1186 ok(!lstrcmpW(str
, dtdnameW
), "got %s\n", wine_dbgstr_w(str
));
1190 hr
= IXmlReader_GetQualifiedName(reader
, &str
, &len
);
1191 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1192 ok(len
== lstrlenW(dtdnameW
), "got %u\n", len
);
1193 ok(!lstrcmpW(str
, dtdnameW
), "got %s\n", wine_dbgstr_w(str
));
1195 type
= XmlNodeType_None
;
1196 hr
= IXmlReader_Read(reader
, &type
);
1197 ok(hr
== S_OK
, "got 0x%8x\n", hr
);
1198 ok(type
== XmlNodeType_Comment
, "got type %d\n", type
);
1200 IStream_Release(stream
);
1201 IXmlReader_Release(reader
);
1204 static struct test_entry element_tests
[] = {
1205 { "<a/>", "a", "", S_OK
},
1206 { "<a />", "a", "", S_OK
},
1207 { "<a:b/>", "a:b", "", NC_E_UNDECLAREDPREFIX
},
1208 { "<:a/>", NULL
, NULL
, NC_E_QNAMECHARACTER
},
1209 { "< a/>", NULL
, NULL
, NC_E_QNAMECHARACTER
},
1210 { "<a>", "a", "", S_OK
},
1211 { "<a >", "a", "", S_OK
},
1212 { "<a \r \t\n>", "a", "", S_OK
},
1213 { "</a>", NULL
, NULL
, NC_E_QNAMECHARACTER
},
1217 static void test_read_element(void)
1219 struct test_entry
*test
= element_tests
;
1220 static const char stag
[] = "<a><b></b></a>";
1221 static const char mismatch
[] = "<a></b>";
1228 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1229 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1233 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
1234 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1235 ok(hr
== S_OK
, "got %08x\n", hr
);
1237 type
= XmlNodeType_None
;
1238 hr
= IXmlReader_Read(reader
, &type
);
1239 if (test
->hr_broken
)
1240 ok(hr
== test
->hr
|| broken(hr
== test
->hr_broken
), "got %08x for %s\n", hr
, test
->xml
);
1242 ok(hr
== test
->hr
, "got %08x for %s\n", hr
, test
->xml
);
1249 ok(type
== XmlNodeType_Element
, "got %d for %s\n", type
, test
->xml
);
1253 hr
= IXmlReader_GetQualifiedName(reader
, &str
, &len
);
1254 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1255 ok(len
== strlen(test
->name
), "got %u\n", len
);
1256 str_exp
= a2w(test
->name
);
1257 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1263 hr
= IXmlReader_GetValue(reader
, &str
, &len
);
1264 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1265 ok(len
== 0, "got %u\n", len
);
1266 ok(*str
== 0, "got %s\n", wine_dbgstr_w(str
));
1269 IStream_Release(stream
);
1273 /* test reader depth increment */
1274 stream
= create_stream_on_data(stag
, sizeof(stag
));
1275 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1276 ok(hr
== S_OK
, "got %08x\n", hr
);
1279 hr
= IXmlReader_GetDepth(reader
, &depth
);
1280 ok(hr
== S_OK
, "got %08x\n", hr
);
1281 ok(depth
== 0, "got %d\n", depth
);
1283 type
= XmlNodeType_None
;
1284 hr
= IXmlReader_Read(reader
, &type
);
1285 ok(hr
== S_OK
, "got %08x\n", hr
);
1286 ok(type
== XmlNodeType_Element
, "got %d\n", type
);
1289 hr
= IXmlReader_GetDepth(reader
, &depth
);
1290 ok(hr
== S_OK
, "got %08x\n", hr
);
1291 ok(depth
== 0, "got %d\n", depth
);
1293 type
= XmlNodeType_None
;
1294 hr
= IXmlReader_Read(reader
, &type
);
1295 ok(hr
== S_OK
, "got %08x\n", hr
);
1296 ok(type
== XmlNodeType_Element
, "got %d\n", type
);
1299 hr
= IXmlReader_GetDepth(reader
, &depth
);
1300 ok(hr
== S_OK
, "got %08x\n", hr
);
1301 ok(depth
== 1, "got %d\n", depth
);
1303 /* read end tag for inner element */
1304 type
= XmlNodeType_None
;
1305 hr
= IXmlReader_Read(reader
, &type
);
1306 ok(hr
== S_OK
, "got %08x\n", hr
);
1307 ok(type
== XmlNodeType_EndElement
, "got %d\n", type
);
1310 hr
= IXmlReader_GetDepth(reader
, &depth
);
1311 ok(hr
== S_OK
, "got %08x\n", hr
);
1313 ok(depth
== 2, "got %d\n", depth
);
1315 /* read end tag for container element */
1316 type
= XmlNodeType_None
;
1317 hr
= IXmlReader_Read(reader
, &type
);
1318 ok(hr
== S_OK
, "got %08x\n", hr
);
1319 ok(type
== XmlNodeType_EndElement
, "got %d\n", type
);
1322 hr
= IXmlReader_GetDepth(reader
, &depth
);
1323 ok(hr
== S_OK
, "got %08x\n", hr
);
1324 ok(depth
== 1, "got %d\n", depth
);
1326 IStream_Release(stream
);
1328 /* start/end tag mismatch */
1329 stream
= create_stream_on_data(mismatch
, sizeof(mismatch
));
1330 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1331 ok(hr
== S_OK
, "got %08x\n", hr
);
1333 type
= XmlNodeType_None
;
1334 hr
= IXmlReader_Read(reader
, &type
);
1335 ok(hr
== S_OK
, "got %08x\n", hr
);
1336 ok(type
== XmlNodeType_Element
, "got %d\n", type
);
1338 type
= XmlNodeType_Element
;
1339 hr
= IXmlReader_Read(reader
, &type
);
1340 ok(hr
== WC_E_ELEMENTMATCH
, "got %08x\n", hr
);
1342 ok(type
== XmlNodeType_None
, "got %d\n", type
);
1344 IStream_Release(stream
);
1346 IXmlReader_Release(reader
);
1349 static ISequentialStream teststream
= { &teststreamvtbl
};
1351 static void test_read_pending(void)
1359 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1360 ok(hr
== S_OK
, "S_OK, got 0x%08x\n", hr
);
1362 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)&teststream
);
1363 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1365 /* first read call returns incomplete node, second attempt fails with E_PENDING */
1366 stream_readcall
= 0;
1367 type
= XmlNodeType_Element
;
1368 hr
= IXmlReader_Read(reader
, &type
);
1369 ok(hr
== S_OK
|| broken(hr
== E_PENDING
), "got 0x%08x\n", hr
);
1370 /* newer versions are happy when it's enough data to detect node type,
1371 older versions keep reading until it fails to read more */
1372 ok(stream_readcall
== 1 || broken(stream_readcall
> 1), "got %d\n", stream_readcall
);
1373 ok(type
== XmlNodeType_Comment
|| broken(type
== XmlNodeType_None
), "got %d\n", type
);
1375 /* newer versions' GetValue() makes an attempt to read more */
1376 c
= stream_readcall
;
1377 value
= (void*)0xdeadbeef;
1378 hr
= IXmlReader_GetValue(reader
, &value
, NULL
);
1379 ok(hr
== E_PENDING
, "got 0x%08x\n", hr
);
1380 ok(value
== NULL
|| broken(value
== (void*)0xdeadbeef) /* Win8 sets it to NULL */, "got %p\n", value
);
1381 ok(c
< stream_readcall
|| broken(c
== stream_readcall
), "got %d, expected %d\n", stream_readcall
, c
+1);
1383 IXmlReader_Release(reader
);
1386 static void test_readvaluechunk(void)
1388 static const char testA
[] = "<!-- comment1 -->";
1397 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1398 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1400 stream
= create_stream_on_data(testA
, sizeof(testA
));
1401 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1402 ok(hr
== S_OK
, "got %08x\n", hr
);
1404 hr
= IXmlReader_Read(reader
, &type
);
1405 ok(hr
== S_OK
, "got %08x\n", hr
);
1409 hr
= IXmlReader_ReadValueChunk(reader
, &b
, 1, &c
);
1410 ok(hr
== S_OK
, "got %08x\n", hr
);
1411 ok(c
== 1, "got %u\n", c
);
1412 ok(b
== ' ', "got %x\n", b
);
1414 /* portion read as chunk is skipped from resulting node value */
1416 hr
= IXmlReader_GetValue(reader
, &value
, NULL
);
1417 ok(hr
== S_OK
, "got %08x\n", hr
);
1418 ok(value
[0] == 'c', "got %s\n", wine_dbgstr_w(value
));
1420 /* once value is returned/allocated it's not possible to read by chunk */
1423 hr
= IXmlReader_ReadValueChunk(reader
, &b
, 1, &c
);
1424 ok(hr
== S_FALSE
, "got %08x\n", hr
);
1425 ok(c
== 0, "got %u\n", c
);
1426 ok(b
== 0, "got %x\n", b
);
1429 hr
= IXmlReader_GetValue(reader
, &value
, NULL
);
1430 ok(hr
== S_OK
, "got %08x\n", hr
);
1431 ok(value
[0] == 'c', "got %s\n", wine_dbgstr_w(value
));
1433 IXmlReader_Release(reader
);
1434 IStream_Release(stream
);
1437 static struct test_entry cdata_tests
[] = {
1438 { "<a><![CDATA[ ]]data ]]></a>", "", " ]]data ", S_OK
},
1439 { "<a><![CDATA[<![CDATA[ data ]]]]></a>", "", "<![CDATA[ data ]]", S_OK
},
1440 { "<a><![CDATA[\n \r\n \n\n ]]></a>", "", "\n \n \n\n ", S_OK
, S_OK
, TRUE
},
1441 { "<a><![CDATA[\r \r\r\n \n\n ]]></a>", "", "\n \n\n \n\n ", S_OK
, S_OK
, TRUE
},
1442 { "<a><![CDATA[\r\r \n\r \r \n\n ]]></a>", "", "\n\n \n\n \n \n\n ", S_OK
},
1446 static void test_read_cdata(void)
1448 struct test_entry
*test
= cdata_tests
;
1452 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1453 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1460 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
1461 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1462 ok(hr
== S_OK
, "got %08x\n", hr
);
1464 type
= XmlNodeType_None
;
1465 hr
= IXmlReader_Read(reader
, &type
);
1467 /* read one more to get to CDATA */
1468 if (type
== XmlNodeType_Element
)
1470 type
= XmlNodeType_None
;
1471 hr
= IXmlReader_Read(reader
, &type
);
1474 if (test
->hr_broken
)
1475 ok(hr
== test
->hr
|| broken(hr
== test
->hr_broken
), "got %08x for %s\n", hr
, test
->xml
);
1477 ok(hr
== test
->hr
, "got %08x for %s\n", hr
, test
->xml
);
1484 ok(type
== XmlNodeType_CDATA
, "got %d for %s\n", type
, test
->xml
);
1486 str_exp
= a2w(test
->name
);
1490 hr
= IXmlReader_GetLocalName(reader
, &str
, &len
);
1491 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1492 ok(len
== strlen(test
->name
), "got %u\n", len
);
1493 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1496 hr
= IXmlReader_GetLocalName(reader
, &str
, NULL
);
1497 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1498 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1504 hr
= IXmlReader_GetQualifiedName(reader
, &str
, &len
);
1505 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1506 ok(len
== strlen(test
->name
), "got %u\n", len
);
1507 str_exp
= a2w(test
->name
);
1508 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1514 hr
= IXmlReader_GetValue(reader
, &str
, &len
);
1515 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1517 str_exp
= a2w(test
->value
);
1521 ok(len
== strlen(test
->value
), "got %u\n", len
);
1522 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1527 ok(len
== strlen(test
->value
), "got %u\n", len
);
1528 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1533 IStream_Release(stream
);
1537 IXmlReader_Release(reader
);
1540 static struct test_entry text_tests
[] = {
1541 { "<a>simple text</a>", "", "simple text", S_OK
},
1542 { "<a>text ]]> text</a>", "", "", WC_E_CDSECTEND
},
1546 static void test_read_text(void)
1548 struct test_entry
*test
= text_tests
;
1552 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1553 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1560 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
1561 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1562 ok(hr
== S_OK
, "got %08x\n", hr
);
1564 type
= XmlNodeType_None
;
1565 hr
= IXmlReader_Read(reader
, &type
);
1567 /* read one more to get to CDATA */
1568 if (type
== XmlNodeType_Element
)
1570 type
= XmlNodeType_None
;
1571 hr
= IXmlReader_Read(reader
, &type
);
1574 if (test
->hr_broken
)
1575 ok(hr
== test
->hr
|| broken(hr
== test
->hr_broken
), "got %08x for %s\n", hr
, test
->xml
);
1577 ok(hr
== test
->hr
, "got %08x for %s\n", hr
, test
->xml
);
1584 ok(type
== XmlNodeType_Text
, "got %d for %s\n", type
, test
->xml
);
1586 str_exp
= a2w(test
->name
);
1590 hr
= IXmlReader_GetLocalName(reader
, &str
, &len
);
1591 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1592 ok(len
== strlen(test
->name
), "got %u\n", len
);
1593 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1596 hr
= IXmlReader_GetLocalName(reader
, &str
, NULL
);
1597 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1598 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1604 hr
= IXmlReader_GetQualifiedName(reader
, &str
, &len
);
1605 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1606 ok(len
== strlen(test
->name
), "got %u\n", len
);
1607 str_exp
= a2w(test
->name
);
1608 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1614 hr
= IXmlReader_GetValue(reader
, &str
, &len
);
1615 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1617 str_exp
= a2w(test
->value
);
1621 ok(len
== strlen(test
->value
), "got %u\n", len
);
1622 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1627 ok(len
== strlen(test
->value
), "got %u\n", len
);
1628 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1633 IStream_Release(stream
);
1637 IXmlReader_Release(reader
);
1640 struct test_entry_empty
{
1645 static struct test_entry_empty empty_element_tests
[] = {
1646 { "<a></a>", FALSE
},
1651 static void test_isemptyelement(void)
1653 struct test_entry_empty
*test
= empty_element_tests
;
1657 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1658 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1666 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
1667 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1668 ok(hr
== S_OK
, "got %08x\n", hr
);
1670 type
= XmlNodeType_None
;
1671 hr
= IXmlReader_Read(reader
, &type
);
1672 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1673 ok(type
== XmlNodeType_Element
, "got %d\n", type
);
1675 ret
= IXmlReader_IsEmptyElement(reader
);
1676 ok(ret
== test
->empty
, "got %d, expected %d. xml=%s\n", ret
, test
->empty
, test
->xml
);
1678 IStream_Release(stream
);
1682 IXmlReader_Release(reader
);
1685 static struct test_entry attributes_tests
[] = {
1686 { "<a attr1=\"attrvalue\"/>", "attr1", "attrvalue", S_OK
},
1687 { "<a attr1=\"a\'\'ttrvalue\"/>", "attr1", "a\'\'ttrvalue", S_OK
},
1688 { "<a attr1=\'a\"ttrvalue\'/>", "attr1", "a\"ttrvalue", S_OK
},
1689 { "<a attr1=\' \'/>", "attr1", " ", S_OK
},
1690 { "<a attr1=\" \"/>", "attr1", " ", S_OK
},
1691 { "<a attr1=\"\r\n \r \n \t\n\r\"/>", "attr1", " ", S_OK
},
1692 { "<a attr1=\" val \"/>", "attr1", " val ", S_OK
},
1693 { "<a attr1=\"\r\n\tval\n\"/>", "attr1", " val ", S_OK
},
1694 { "<a attr1=\"val \"/>", "attr1", "val ", S_OK
},
1695 { "<a attr1=\"val \"/>", "attr1", "val ", S_OK
},
1696 { "<a attr1=\"<>&'"\"/>", "attr1", "<>&\'\"", S_OK
},
1697 { "<a attr1=\"&entname;\"/>", NULL
, NULL
, WC_E_UNDECLAREDENTITY
},
1698 { "<a attr1=\"val\"/>", NULL
, NULL
, WC_E_XMLCHARACTER
},
1699 { "<a attr1=\"val &#a;\"/>", NULL
, NULL
, WC_E_DIGIT
, WC_E_SEMICOLON
},
1700 { "<a attr1=\"val a;\"/>", NULL
, NULL
, WC_E_SEMICOLON
},
1701 { "<a attr1=\"val g;\"/>", NULL
, NULL
, WC_E_SEMICOLON
},
1702 { "<a attr1=\"val &#xg;\"/>", NULL
, NULL
, WC_E_HEXDIGIT
, WC_E_SEMICOLON
},
1703 { "<a attr1=attrvalue/>", NULL
, NULL
, WC_E_QUOTE
},
1704 { "<a attr1=\"attr<value\"/>", NULL
, NULL
, WC_E_LESSTHAN
},
1705 { "<a attr1=\"&entname\"/>", NULL
, NULL
, WC_E_SEMICOLON
},
1709 static void test_read_attribute(void)
1711 struct test_entry
*test
= attributes_tests
;
1715 hr
= pCreateXmlReader(&IID_IXmlReader
, (void**)&reader
, NULL
);
1716 ok(hr
== S_OK
, "S_OK, got %08x\n", hr
);
1723 stream
= create_stream_on_data(test
->xml
, strlen(test
->xml
)+1);
1724 hr
= IXmlReader_SetInput(reader
, (IUnknown
*)stream
);
1725 ok(hr
== S_OK
, "got %08x\n", hr
);
1727 type
= XmlNodeType_None
;
1728 hr
= IXmlReader_Read(reader
, &type
);
1730 if (test
->hr_broken
)
1731 ok(hr
== test
->hr
|| broken(hr
== test
->hr_broken
), "got %08x for %s\n", hr
, test
->xml
);
1733 ok(hr
== test
->hr
, "got %08x for %s\n", hr
, test
->xml
);
1740 ok(type
== XmlNodeType_Element
, "got %d for %s\n", type
, test
->xml
);
1742 hr
= IXmlReader_MoveToFirstAttribute(reader
);
1743 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1747 hr
= IXmlReader_GetLocalName(reader
, &str
, &len
);
1748 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1749 ok(len
== strlen(test
->name
), "got %u\n", len
);
1750 str_exp
= a2w(test
->name
);
1751 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1756 hr
= IXmlReader_GetQualifiedName(reader
, &str
, &len
);
1757 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1759 ok(len
== strlen(test
->name
), "got %u\n", len
);
1760 str_exp
= a2w(test
->name
);
1761 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1767 hr
= IXmlReader_GetValue(reader
, &str
, &len
);
1768 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1769 ok(len
== strlen(test
->value
), "got %u\n", len
);
1770 str_exp
= a2w(test
->value
);
1771 ok(!lstrcmpW(str
, str_exp
), "got %s\n", wine_dbgstr_w(str
));
1775 IStream_Release(stream
);
1779 IXmlReader_Release(reader
);
1784 if (!init_pointers())
1787 test_reader_create();
1789 test_reader_state();
1790 test_read_attribute();
1792 test_read_comment();
1795 test_read_element();
1796 test_isemptyelement();
1799 test_read_pending();
1800 test_readvaluechunk();
1801 test_read_xmldeclaration();