xmllite: Fix a test failure on Windows 8.
[wine.git] / dlls / xmllite / tests / reader.c
blobb0a14d36377f4efb006396707414aeba4955324f
1 /*
2 * IXmlReader tests
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
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <stdarg.h>
25 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "initguid.h"
30 #include "ole2.h"
31 #include "xmllite.h"
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,
38 IMalloc *pMalloc,
39 LPCWSTR encoding,
40 BOOL hint,
41 LPCWSTR base_uri,
42 IXmlReaderInput **ppInput);
43 static const char *debugstr_guid(REFIID riid)
45 static char buf[50];
47 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
48 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
49 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
50 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
52 return buf;
55 static WCHAR *a2w(const char *str)
57 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
58 WCHAR *ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
59 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
60 return ret;
63 static void free_str(WCHAR *str)
65 HeapFree(GetProcessHeap(), 0, str);
68 static const char xmldecl_full[] = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
70 static IStream *create_stream_on_data(const char *data, int size)
72 IStream *stream = NULL;
73 HGLOBAL hglobal;
74 void *ptr;
75 HRESULT hr;
77 hglobal = GlobalAlloc(GHND, size);
78 ptr = GlobalLock(hglobal);
80 memcpy(ptr, data, size);
82 hr = CreateStreamOnHGlobal(hglobal, TRUE, &stream);
83 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
84 ok(stream != NULL, "Expected non-NULL stream\n");
86 GlobalUnlock(hglobal);
88 return stream;
91 static void ok_pos_(IXmlReader *reader, int line, int pos, int line_broken,
92 int pos_broken, int todo, int _line_)
94 UINT l, p;
95 HRESULT hr;
96 int broken_state;
98 hr = IXmlReader_GetLineNumber(reader, &l);
99 ok_(__FILE__, _line_)(hr == S_OK, "Expected S_OK, got %08x\n", hr);
100 hr = IXmlReader_GetLinePosition(reader, &p);
101 ok_(__FILE__, _line_)(hr == S_OK, "Expected S_OK, got %08x\n", hr);
103 if (line_broken == -1 && pos_broken == -1)
104 broken_state = 0;
105 else
106 broken_state = broken((line_broken == -1 ? line : line_broken) == l &&
107 (pos_broken == -1 ? pos : pos_broken) == p);
109 if (todo)
110 todo_wine
111 ok_(__FILE__, _line_)((l == line && pos == p) || broken_state,
112 "Expected (%d,%d), got (%d,%d)\n", line, pos, l, p);
113 else
115 ok_(__FILE__, _line_)((l == line && pos == p) || broken_state,
116 "Expected (%d,%d), got (%d,%d)\n", line, pos, l, p);
119 #define ok_pos(reader, l, p, l_brk, p_brk, todo) ok_pos_(reader, l, p, l_brk, p_brk, todo, __LINE__)
121 typedef struct input_iids_t {
122 IID iids[10];
123 int count;
124 } input_iids_t;
126 static const IID *setinput_full[] = {
127 &IID_IXmlReaderInput,
128 &IID_IStream,
129 &IID_ISequentialStream,
130 NULL
133 /* this applies to early xmllite versions */
134 static const IID *setinput_full_old[] = {
135 &IID_IXmlReaderInput,
136 &IID_ISequentialStream,
137 &IID_IStream,
138 NULL
141 /* after ::SetInput(IXmlReaderInput*) */
142 static const IID *setinput_readerinput[] = {
143 &IID_IStream,
144 &IID_ISequentialStream,
145 NULL
148 static const IID *empty_seq[] = {
149 NULL
152 static input_iids_t input_iids;
154 static void ok_iids_(const input_iids_t *iids, const IID **expected, const IID **exp_broken, int todo, int line)
156 int i = 0, size = 0;
158 while (expected[i++]) size++;
160 if (todo) {
161 todo_wine
162 ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
164 else
165 ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
167 if (iids->count != size) return;
169 for (i = 0; i < size; i++) {
170 ok_(__FILE__, line)(IsEqualGUID(&iids->iids[i], expected[i]) ||
171 (exp_broken ? broken(IsEqualGUID(&iids->iids[i], exp_broken[i])) : FALSE),
172 "Wrong IID(%d), got (%s)\n", i, debugstr_guid(&iids->iids[i]));
175 #define ok_iids(got, exp, brk, todo) ok_iids_(got, exp, brk, todo, __LINE__)
177 static const char *state_to_str(XmlReadState state)
179 static const char* state_names[] = {
180 "XmlReadState_Initial",
181 "XmlReadState_Interactive",
182 "XmlReadState_Error",
183 "XmlReadState_EndOfFile",
184 "XmlReadState_Closed"
187 static const char unknown[] = "unknown";
189 switch (state)
191 case XmlReadState_Initial:
192 case XmlReadState_Interactive:
193 case XmlReadState_Error:
194 case XmlReadState_EndOfFile:
195 case XmlReadState_Closed:
196 return state_names[state];
197 default:
198 return unknown;
202 static const char *type_to_str(XmlNodeType type)
204 static const char* type_names[] = {
205 "XmlNodeType_None",
206 "XmlNodeType_Element",
207 "XmlNodeType_Attribute",
208 "XmlNodeType_Text",
209 "XmlNodeType_CDATA",
210 "", "",
211 "XmlNodeType_ProcessingInstruction",
212 "XmlNodeType_Comment",
214 "XmlNodeType_DocumentType",
215 "", "",
216 "XmlNodeType_Whitespace",
218 "XmlNodeType_EndElement",
220 "XmlNodeType_XmlDeclaration"
223 static const char unknown[] = "unknown";
225 switch (type)
227 case XmlNodeType_None:
228 case XmlNodeType_Element:
229 case XmlNodeType_Attribute:
230 case XmlNodeType_Text:
231 case XmlNodeType_CDATA:
232 case XmlNodeType_ProcessingInstruction:
233 case XmlNodeType_Comment:
234 case XmlNodeType_DocumentType:
235 case XmlNodeType_Whitespace:
236 case XmlNodeType_EndElement:
237 case XmlNodeType_XmlDeclaration:
238 return type_names[type];
239 default:
240 return unknown;
244 static void test_read_state_(IXmlReader *reader, XmlReadState expected,
245 XmlReadState exp_broken, int todo, int line)
247 XmlReadState state;
248 HRESULT hr;
249 int broken_state;
251 state = -1; /* invalid value */
252 hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, (LONG_PTR*)&state);
253 ok_(__FILE__, line)(hr == S_OK, "Expected S_OK, got %08x\n", hr);
255 if (exp_broken == -1)
256 broken_state = 0;
257 else
258 broken_state = broken(exp_broken == state);
260 if (todo)
262 todo_wine
263 ok_(__FILE__, line)(state == expected || broken_state, "Expected (%s), got (%s)\n",
264 state_to_str(expected), state_to_str(state));
266 else
267 ok_(__FILE__, line)(state == expected || broken_state, "Expected (%s), got (%s)\n",
268 state_to_str(expected), state_to_str(state));
271 #define test_read_state(reader, exp, brk, todo) test_read_state_(reader, exp, brk, todo, __LINE__)
273 typedef struct _testinput
275 IUnknown IUnknown_iface;
276 LONG ref;
277 } testinput;
279 static inline testinput *impl_from_IUnknown(IUnknown *iface)
281 return CONTAINING_RECORD(iface, testinput, IUnknown_iface);
284 static HRESULT WINAPI testinput_QueryInterface(IUnknown *iface, REFIID riid, void** ppvObj)
286 if (IsEqualGUID( riid, &IID_IUnknown ))
288 *ppvObj = iface;
289 IUnknown_AddRef(iface);
290 return S_OK;
293 input_iids.iids[input_iids.count++] = *riid;
295 *ppvObj = NULL;
297 return E_NOINTERFACE;
300 static ULONG WINAPI testinput_AddRef(IUnknown *iface)
302 testinput *This = impl_from_IUnknown(iface);
303 return InterlockedIncrement(&This->ref);
306 static ULONG WINAPI testinput_Release(IUnknown *iface)
308 testinput *This = impl_from_IUnknown(iface);
309 LONG ref;
311 ref = InterlockedDecrement(&This->ref);
312 if (ref == 0)
314 HeapFree(GetProcessHeap(), 0, This);
317 return ref;
320 static const struct IUnknownVtbl testinput_vtbl =
322 testinput_QueryInterface,
323 testinput_AddRef,
324 testinput_Release
327 static HRESULT testinput_createinstance(void **ppObj)
329 testinput *input;
331 input = HeapAlloc(GetProcessHeap(), 0, sizeof (*input));
332 if(!input) return E_OUTOFMEMORY;
334 input->IUnknown_iface.lpVtbl = &testinput_vtbl;
335 input->ref = 1;
337 *ppObj = &input->IUnknown_iface;
339 return S_OK;
342 static HRESULT WINAPI teststream_QueryInterface(ISequentialStream *iface, REFIID riid, void **obj)
344 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ISequentialStream))
346 *obj = iface;
347 return S_OK;
350 *obj = NULL;
351 return E_NOINTERFACE;
354 static ULONG WINAPI teststream_AddRef(ISequentialStream *iface)
356 return 2;
359 static ULONG WINAPI teststream_Release(ISequentialStream *iface)
361 return 1;
364 static int stream_readcall;
366 static HRESULT WINAPI teststream_Read(ISequentialStream *iface, void *pv, ULONG cb, ULONG *pread)
368 static const char xml[] = "<!-- comment -->";
370 if (stream_readcall++)
372 *pread = 0;
373 return E_PENDING;
376 *pread = sizeof(xml) / 2;
377 memcpy(pv, xml, *pread);
378 return S_OK;
381 static HRESULT WINAPI teststream_Write(ISequentialStream *iface, const void *pv, ULONG cb, ULONG *written)
383 ok(0, "unexpected call\n");
384 return E_NOTIMPL;
387 static const ISequentialStreamVtbl teststreamvtbl =
389 teststream_QueryInterface,
390 teststream_AddRef,
391 teststream_Release,
392 teststream_Read,
393 teststream_Write
396 static BOOL init_pointers(void)
398 /* don't free module here, it's to be unloaded on exit */
399 HMODULE mod = LoadLibraryA("xmllite.dll");
401 if (!mod)
403 win_skip("xmllite library not available\n");
404 return FALSE;
407 #define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
408 MAKEFUNC(CreateXmlReader);
409 MAKEFUNC(CreateXmlReaderInputWithEncodingName);
410 #undef MAKEFUNC
412 return TRUE;
415 static void test_reader_create(void)
417 HRESULT hr;
418 IXmlReader *reader;
419 IUnknown *input;
420 DtdProcessing dtd;
421 XmlNodeType nodetype;
423 /* crashes native */
424 if (0)
426 pCreateXmlReader(&IID_IXmlReader, NULL, NULL);
427 pCreateXmlReader(NULL, (void**)&reader, NULL);
430 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
431 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
433 test_read_state(reader, XmlReadState_Closed, -1, FALSE);
435 nodetype = XmlNodeType_Element;
436 hr = IXmlReader_GetNodeType(reader, &nodetype);
437 ok(hr == S_FALSE, "got %08x\n", hr);
438 ok(nodetype == XmlNodeType_None, "got %d\n", nodetype);
440 dtd = 2;
441 hr = IXmlReader_GetProperty(reader, XmlReaderProperty_DtdProcessing, (LONG_PTR*)&dtd);
442 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
443 ok(dtd == DtdProcessing_Prohibit, "got %d\n", dtd);
445 dtd = 2;
446 hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, dtd);
447 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
449 hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, -1);
450 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
452 /* Null input pointer, releases previous input */
453 hr = IXmlReader_SetInput(reader, NULL);
454 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
456 test_read_state(reader, XmlReadState_Initial, XmlReadState_Closed, FALSE);
458 /* test input interface selection sequence */
459 hr = testinput_createinstance((void**)&input);
460 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
462 if (hr == S_OK)
464 input_iids.count = 0;
465 hr = IXmlReader_SetInput(reader, input);
466 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
467 ok_iids(&input_iids, setinput_full, setinput_full_old, FALSE);
468 IUnknown_Release(input);
470 IXmlReader_Release(reader);
473 static void test_readerinput(void)
475 IXmlReaderInput *reader_input;
476 IXmlReader *reader, *reader2;
477 IUnknown *obj, *input;
478 IStream *stream, *stream2;
479 XmlNodeType nodetype;
480 HRESULT hr;
481 LONG ref;
483 hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, NULL);
484 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
485 hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, &reader_input);
486 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
488 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
489 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
491 ref = IStream_AddRef(stream);
492 ok(ref == 2, "Expected 2, got %d\n", ref);
493 IStream_Release(stream);
494 hr = pCreateXmlReaderInputWithEncodingName((IUnknown*)stream, NULL, NULL, FALSE, NULL, &reader_input);
495 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
497 hr = IUnknown_QueryInterface(reader_input, &IID_IStream, (void**)&stream2);
498 ok(hr == E_NOINTERFACE, "Expected S_OK, got %08x\n", hr);
500 hr = IUnknown_QueryInterface(reader_input, &IID_ISequentialStream, (void**)&stream2);
501 ok(hr == E_NOINTERFACE, "Expected S_OK, got %08x\n", hr);
503 /* IXmlReaderInput grabs a stream reference */
504 ref = IStream_AddRef(stream);
505 ok(ref == 3, "Expected 3, got %d\n", ref);
506 IStream_Release(stream);
508 /* try ::SetInput() with valid IXmlReaderInput */
509 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
510 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
512 ref = IUnknown_AddRef(reader_input);
513 ok(ref == 2, "Expected 2, got %d\n", ref);
514 IUnknown_Release(reader_input);
516 hr = IXmlReader_SetInput(reader, reader_input);
517 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
519 test_read_state(reader, XmlReadState_Initial, -1, FALSE);
521 nodetype = XmlNodeType_Element;
522 hr = IXmlReader_GetNodeType(reader, &nodetype);
523 ok(hr == S_OK, "got %08x\n", hr);
524 ok(nodetype == XmlNodeType_None, "got %d\n", nodetype);
526 /* IXmlReader grabs a IXmlReaderInput reference */
527 ref = IUnknown_AddRef(reader_input);
528 ok(ref == 3, "Expected 3, got %d\n", ref);
529 IUnknown_Release(reader_input);
531 ref = IStream_AddRef(stream);
532 ok(ref == 4, "Expected 4, got %d\n", ref);
533 IStream_Release(stream);
535 /* reset input and check state */
536 hr = IXmlReader_SetInput(reader, NULL);
537 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
539 test_read_state(reader, XmlReadState_Initial, XmlReadState_Closed, FALSE);
541 IXmlReader_Release(reader);
543 ref = IStream_AddRef(stream);
544 ok(ref == 3, "Expected 3, got %d\n", ref);
545 IStream_Release(stream);
547 ref = IUnknown_AddRef(reader_input);
548 ok(ref == 2, "Expected 2, got %d\n", ref);
549 IUnknown_Release(reader_input);
551 /* IID_IXmlReaderInput */
552 /* it returns a kind of private undocumented vtable incompatible with IUnknown,
553 so it's not a COM interface actually.
554 Such query will be used only to check if input is really IXmlReaderInput */
555 obj = (IUnknown*)0xdeadbeef;
556 hr = IUnknown_QueryInterface(reader_input, &IID_IXmlReaderInput, (void**)&obj);
557 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
558 ref = IUnknown_AddRef(reader_input);
559 ok(ref == 3, "Expected 3, got %d\n", ref);
560 IUnknown_Release(reader_input);
562 IUnknown_Release(reader_input);
563 IUnknown_Release(reader_input);
564 IStream_Release(stream);
566 /* test input interface selection sequence */
567 input = NULL;
568 hr = testinput_createinstance((void**)&input);
569 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
571 input_iids.count = 0;
572 ref = IUnknown_AddRef(input);
573 ok(ref == 2, "Expected 2, got %d\n", ref);
574 IUnknown_Release(input);
575 hr = pCreateXmlReaderInputWithEncodingName(input, NULL, NULL, FALSE, NULL, &reader_input);
576 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
577 ok_iids(&input_iids, empty_seq, NULL, FALSE);
578 /* IXmlReaderInput stores stream interface as IUnknown */
579 ref = IUnknown_AddRef(input);
580 ok(ref == 3, "Expected 3, got %d\n", ref);
581 IUnknown_Release(input);
583 hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
584 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
586 input_iids.count = 0;
587 ref = IUnknown_AddRef(reader_input);
588 ok(ref == 2, "Expected 2, got %d\n", ref);
589 IUnknown_Release(reader_input);
590 ref = IUnknown_AddRef(input);
591 ok(ref == 3, "Expected 3, got %d\n", ref);
592 IUnknown_Release(input);
593 hr = IXmlReader_SetInput(reader, reader_input);
594 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
595 ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
597 test_read_state(reader, XmlReadState_Closed, -1, FALSE);
599 ref = IUnknown_AddRef(input);
600 ok(ref == 3, "Expected 3, got %d\n", ref);
601 IUnknown_Release(input);
603 ref = IUnknown_AddRef(reader_input);
604 ok(ref == 3 || broken(ref == 2) /* versions 1.0.x and 1.1.x - XP, Vista */,
605 "Expected 3, got %d\n", ref);
606 IUnknown_Release(reader_input);
607 /* repeat another time, no check or caching here */
608 input_iids.count = 0;
609 hr = IXmlReader_SetInput(reader, reader_input);
610 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
611 ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
613 /* another reader */
614 hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader2, NULL);
615 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
617 /* resolving from IXmlReaderInput to IStream/ISequentialStream is done at
618 ::SetInput() level, each time it's called */
619 input_iids.count = 0;
620 hr = IXmlReader_SetInput(reader2, reader_input);
621 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
622 ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
624 IXmlReader_Release(reader2);
625 IXmlReader_Release(reader);
627 IUnknown_Release(reader_input);
628 IUnknown_Release(input);
631 static void test_reader_state(void)
633 IXmlReader *reader;
634 XmlNodeType nodetype;
635 HRESULT hr;
637 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
638 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
640 /* invalid arguments */
641 hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, NULL);
642 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
644 /* attempt to read on closed reader */
645 test_read_state(reader, XmlReadState_Closed, -1, 0);
646 if (0)
648 /* newer versions crash here, probably cause no input was set */
649 hr = IXmlReader_Read(reader, &nodetype);
650 ok(hr == S_FALSE, "got %08x\n", hr);
652 IXmlReader_Release(reader);
655 static void test_read_xmldeclaration(void)
657 IXmlReader *reader;
658 IStream *stream;
659 HRESULT hr;
660 XmlNodeType type;
661 UINT count = 0;
662 const WCHAR *val;
664 hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
665 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
667 /* position methods with Null args */
668 hr = IXmlReader_GetLineNumber(reader, NULL);
669 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
671 hr = IXmlReader_GetLinePosition(reader, NULL);
672 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
674 stream = create_stream_on_data(xmldecl_full, sizeof(xmldecl_full));
676 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
677 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
679 hr = IXmlReader_GetAttributeCount(reader, &count);
680 ok(hr == S_OK, "got %08x\n", hr);
681 ok(count == 0, "got %d\n", count);
683 /* try to move without attributes */
684 hr = IXmlReader_MoveToElement(reader);
685 ok(hr == S_FALSE, "got %08x\n", hr);
687 hr = IXmlReader_MoveToNextAttribute(reader);
688 ok(hr == S_FALSE, "got %08x\n", hr);
690 hr = IXmlReader_MoveToFirstAttribute(reader);
691 ok(hr == S_FALSE, "got %08x\n", hr);
693 ok_pos(reader, 0, 0, -1, -1, FALSE);
695 type = -1;
696 hr = IXmlReader_Read(reader, &type);
697 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
698 ok(type == XmlNodeType_XmlDeclaration,
699 "Expected XmlNodeType_XmlDeclaration, got %s\n", type_to_str(type));
700 /* new version 1.2.x and 1.3.x properly update position for <?xml ?> */
701 ok_pos(reader, 1, 3, -1, 55, TRUE);
702 test_read_state(reader, XmlReadState_Interactive, -1, 0);
704 hr = IXmlReader_GetValue(reader, &val, NULL);
705 ok(hr == S_OK, "got %08x\n", hr);
706 ok(*val == 0, "got %s\n", wine_dbgstr_w(val));
708 /* check attributes */
709 hr = IXmlReader_MoveToNextAttribute(reader);
710 ok(hr == S_OK, "got %08x\n", hr);
712 type = XmlNodeType_None;
713 hr = IXmlReader_GetNodeType(reader, &type);
714 ok(hr == S_OK, "got %08x\n", hr);
715 ok(type == XmlNodeType_Attribute, "got %d\n", type);
717 ok_pos(reader, 1, 7, -1, 55, TRUE);
719 /* try to move from last attribute */
720 hr = IXmlReader_MoveToNextAttribute(reader);
721 ok(hr == S_OK, "got %08x\n", hr);
722 hr = IXmlReader_MoveToNextAttribute(reader);
723 ok(hr == S_OK, "got %08x\n", hr);
724 hr = IXmlReader_MoveToNextAttribute(reader);
725 ok(hr == S_FALSE, "got %08x\n", hr);
727 type = XmlNodeType_None;
728 hr = IXmlReader_GetNodeType(reader, &type);
729 ok(hr == S_OK, "got %08x\n", hr);
730 ok(type == XmlNodeType_Attribute, "got %d\n", type);
732 hr = IXmlReader_MoveToFirstAttribute(reader);
733 ok(hr == S_OK, "got %08x\n", hr);
734 ok_pos(reader, 1, 7, -1, 55, TRUE);
736 hr = IXmlReader_GetAttributeCount(reader, NULL);
737 ok(hr == E_INVALIDARG, "got %08x\n", hr);
739 hr = IXmlReader_GetAttributeCount(reader, &count);
740 ok(hr == S_OK, "got %08x\n", hr);
741 ok(count == 3, "Expected 3, got %d\n", count);
743 hr = IXmlReader_GetDepth(reader, &count);
744 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
745 todo_wine
746 ok(count == 1, "Expected 1, got %d\n", count);
748 hr = IXmlReader_MoveToElement(reader);
749 ok(hr == S_OK, "got %08x\n", hr);
751 type = XmlNodeType_None;
752 hr = IXmlReader_GetNodeType(reader, &type);
753 ok(hr == S_OK, "got %08x\n", hr);
754 ok(type == XmlNodeType_XmlDeclaration, "got %d\n", type);
756 type = XmlNodeType_XmlDeclaration;
757 hr = IXmlReader_Read(reader, &type);
758 /* newer versions return syntax error here cause document is incomplete,
759 it makes more sense than invalid char error */
760 todo_wine {
761 ok(hr == WC_E_SYNTAX || broken(hr == WC_E_XMLCHARACTER), "got 0x%08x\n", hr);
762 ok(type == XmlNodeType_None, "got %d\n", type);
764 IStream_Release(stream);
765 IXmlReader_Release(reader);
768 struct test_entry {
769 const char *xml;
770 const char *name;
771 const char *value;
772 HRESULT hr;
773 HRESULT hr_broken; /* this is set to older version results */
776 static struct test_entry comment_tests[] = {
777 { "<!-- comment -->", "", " comment ", S_OK },
778 { "<!-- - comment-->", "", " - comment", S_OK },
779 { "<!-- -- comment-->", NULL, NULL, WC_E_COMMENT, WC_E_GREATERTHAN },
780 { "<!-- -- comment--->", NULL, NULL, WC_E_COMMENT, WC_E_GREATERTHAN },
781 { NULL }
784 static void test_read_comment(void)
786 struct test_entry *test = comment_tests;
787 IXmlReader *reader;
788 HRESULT hr;
790 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
791 ok(hr == S_OK, "S_OK, got %08x\n", hr);
793 while (test->xml)
795 XmlNodeType type;
796 IStream *stream;
798 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
799 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
800 ok(hr == S_OK, "got %08x\n", hr);
802 type = XmlNodeType_None;
803 hr = IXmlReader_Read(reader, &type);
804 if (test->hr_broken)
805 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
806 else
807 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
808 if (hr == S_OK)
810 const WCHAR *str;
811 WCHAR *str_exp;
812 UINT len;
814 ok(type == XmlNodeType_Comment, "got %d for %s\n", type, test->xml);
816 len = 1;
817 str = NULL;
818 hr = IXmlReader_GetLocalName(reader, &str, &len);
819 ok(hr == S_OK, "got 0x%08x\n", hr);
820 ok(len == strlen(test->name), "got %u\n", len);
821 str_exp = a2w(test->name);
822 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
823 free_str(str_exp);
825 len = 1;
826 str = NULL;
827 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
828 ok(hr == S_OK, "got 0x%08x\n", hr);
829 ok(len == strlen(test->name), "got %u\n", len);
830 str_exp = a2w(test->name);
831 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
832 free_str(str_exp);
834 /* value */
835 len = 1;
836 str = NULL;
837 hr = IXmlReader_GetValue(reader, &str, &len);
838 ok(hr == S_OK, "got 0x%08x\n", hr);
839 ok(len == strlen(test->value), "got %u\n", len);
840 str_exp = a2w(test->value);
841 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
842 free_str(str_exp);
845 IStream_Release(stream);
846 test++;
849 IXmlReader_Release(reader);
852 static struct test_entry pi_tests[] = {
853 { "<?pi?>", "pi", "", S_OK },
854 { "<?pi ?>", "pi", "", S_OK },
855 { "<?pi ?>", "pi", "", S_OK },
856 { "<?pi pi data?>", "pi", "pi data", S_OK },
857 { "<?pi pi data ?>", "pi", "pi data ", S_OK },
858 { "<?pi:pi?>", NULL, NULL, NC_E_NAMECOLON, WC_E_NAMECHARACTER },
859 { "<?:pi ?>", NULL, NULL, WC_E_PI, WC_E_NAMECHARACTER },
860 { "<?-pi ?>", NULL, NULL, WC_E_PI, WC_E_NAMECHARACTER },
861 { "<?xml-stylesheet ?>", "xml-stylesheet", "", S_OK },
862 { NULL }
865 static void test_read_pi(void)
867 struct test_entry *test = pi_tests;
868 IXmlReader *reader;
869 HRESULT hr;
871 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
872 ok(hr == S_OK, "S_OK, got %08x\n", hr);
874 while (test->xml)
876 XmlNodeType type;
877 IStream *stream;
879 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
880 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
881 ok(hr == S_OK, "got %08x\n", hr);
883 type = XmlNodeType_None;
884 hr = IXmlReader_Read(reader, &type);
885 if (test->hr_broken)
886 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
887 else
888 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
889 if (hr == S_OK)
891 const WCHAR *str;
892 WCHAR *str_exp;
893 UINT len;
895 ok(type == XmlNodeType_ProcessingInstruction, "got %d for %s\n", type, test->xml);
897 len = 0;
898 str = NULL;
899 hr = IXmlReader_GetLocalName(reader, &str, &len);
900 ok(hr == S_OK, "got 0x%08x\n", hr);
901 ok(len == strlen(test->name), "got %u\n", len);
902 str_exp = a2w(test->name);
903 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
904 free_str(str_exp);
906 len = 0;
907 str = NULL;
908 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
909 ok(hr == S_OK, "got 0x%08x\n", hr);
910 ok(len == strlen(test->name), "got %u\n", len);
911 str_exp = a2w(test->name);
912 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
913 free_str(str_exp);
915 /* value */
916 len = !strlen(test->value);
917 str = NULL;
918 hr = IXmlReader_GetValue(reader, &str, &len);
919 ok(hr == S_OK, "got 0x%08x\n", hr);
920 ok(len == strlen(test->value), "got %u\n", len);
921 str_exp = a2w(test->value);
922 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
923 free_str(str_exp);
926 IStream_Release(stream);
927 test++;
930 IXmlReader_Release(reader);
933 struct nodes_test {
934 const char *xml;
935 XmlNodeType types[20];
938 static const char misc_test_xml[] =
939 "<!-- comment1 -->"
940 "<!-- comment2 -->"
941 "<?pi1 pi1body ?>"
942 "<!-- comment3 -->"
943 " \t \r \n"
944 "<!-- comment4 -->"
945 "<a>"
946 "<b/>"
947 "<!-- comment -->"
948 "<?pi pibody ?>"
949 "</a>"
952 static struct nodes_test misc_test = {
953 misc_test_xml,
955 XmlNodeType_Comment,
956 XmlNodeType_Comment,
957 XmlNodeType_ProcessingInstruction,
958 XmlNodeType_Comment,
959 XmlNodeType_Whitespace,
960 XmlNodeType_Comment,
961 XmlNodeType_Element,
962 XmlNodeType_Element,
963 XmlNodeType_Comment,
964 XmlNodeType_ProcessingInstruction,
965 XmlNodeType_EndElement,
966 XmlNodeType_None
970 static void test_read_full(void)
972 struct nodes_test *test = &misc_test;
973 IXmlReader *reader;
974 XmlNodeType type;
975 IStream *stream;
976 HRESULT hr;
977 int i;
979 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
980 ok(hr == S_OK, "S_OK, got %08x\n", hr);
982 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
983 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
984 ok(hr == S_OK, "got %08x\n", hr);
986 i = 0;
987 type = XmlNodeType_None;
988 hr = IXmlReader_Read(reader, &type);
989 while (hr == S_OK)
991 ok(test->types[i] != XmlNodeType_None, "%d: unexpected end of test data\n", i);
992 if (test->types[i] == XmlNodeType_None) break;
993 ok(type == test->types[i], "%d: got wrong type %d, expected %d\n", i, type, test->types[i]);
994 hr = IXmlReader_Read(reader, &type);
995 i++;
997 ok(test->types[i] == XmlNodeType_None, "incomplete sequence, got %d\n", test->types[i]);
999 IStream_Release(stream);
1000 IXmlReader_Release(reader);
1003 static const char test_dtd[] =
1004 "<!DOCTYPE testdtd SYSTEM \"externalid uri\" >"
1005 "<!-- comment -->";
1007 static void test_read_dtd(void)
1009 static const WCHAR sysvalW[] = {'e','x','t','e','r','n','a','l','i','d',' ','u','r','i',0};
1010 static const WCHAR dtdnameW[] = {'t','e','s','t','d','t','d',0};
1011 static const WCHAR sysW[] = {'S','Y','S','T','E','M',0};
1012 IXmlReader *reader;
1013 const WCHAR *str;
1014 XmlNodeType type;
1015 IStream *stream;
1016 UINT len, count;
1017 HRESULT hr;
1019 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1020 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1022 hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, DtdProcessing_Parse);
1023 ok(hr == S_OK, "got 0x%8x\n", hr);
1025 stream = create_stream_on_data(test_dtd, sizeof(test_dtd));
1026 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1027 ok(hr == S_OK, "got %08x\n", hr);
1029 type = XmlNodeType_None;
1030 hr = IXmlReader_Read(reader, &type);
1031 ok(hr == S_OK, "got 0x%8x\n", hr);
1032 ok(type == XmlNodeType_DocumentType, "got type %d\n", type);
1034 count = 0;
1035 hr = IXmlReader_GetAttributeCount(reader, &count);
1036 ok(hr == S_OK, "got %08x\n", hr);
1037 ok(count == 1, "got %d\n", count);
1039 hr = IXmlReader_MoveToFirstAttribute(reader);
1040 ok(hr == S_OK, "got %08x\n", hr);
1042 type = XmlNodeType_None;
1043 hr = IXmlReader_GetNodeType(reader, &type);
1044 ok(hr == S_OK, "got %08x\n", hr);
1045 ok(type == XmlNodeType_Attribute, "got %d\n", type);
1047 len = 0;
1048 str = NULL;
1049 hr = IXmlReader_GetLocalName(reader, &str, &len);
1050 ok(hr == S_OK, "got 0x%08x\n", hr);
1051 todo_wine {
1052 ok(len == lstrlenW(sysW), "got %u\n", len);
1053 ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
1055 len = 0;
1056 str = NULL;
1057 hr = IXmlReader_GetValue(reader, &str, &len);
1058 ok(hr == S_OK, "got 0x%08x\n", hr);
1059 todo_wine {
1060 ok(len == lstrlenW(sysvalW), "got %u\n", len);
1061 ok(!lstrcmpW(str, sysvalW), "got %s\n", wine_dbgstr_w(str));
1063 hr = IXmlReader_MoveToElement(reader);
1064 ok(hr == S_OK, "got 0x%08x\n", hr);
1066 len = 0;
1067 str = NULL;
1068 hr = IXmlReader_GetLocalName(reader, &str, &len);
1069 ok(hr == S_OK, "got 0x%08x\n", hr);
1070 ok(len == lstrlenW(dtdnameW), "got %u\n", len);
1071 ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
1073 len = 0;
1074 str = NULL;
1075 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1076 ok(hr == S_OK, "got 0x%08x\n", hr);
1077 ok(len == lstrlenW(dtdnameW), "got %u\n", len);
1078 ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
1080 type = XmlNodeType_None;
1081 hr = IXmlReader_Read(reader, &type);
1082 ok(hr == S_OK, "got 0x%8x\n", hr);
1083 ok(type == XmlNodeType_Comment, "got type %d\n", type);
1085 IStream_Release(stream);
1086 IXmlReader_Release(reader);
1089 static struct test_entry element_tests[] = {
1090 { "<a/>", "a", "", S_OK },
1091 { "<a />", "a", "", S_OK },
1092 { "<a:b/>", "a:b", "", NC_E_UNDECLAREDPREFIX },
1093 { "<:a/>", NULL, NULL, NC_E_QNAMECHARACTER },
1094 { "< a/>", NULL, NULL, NC_E_QNAMECHARACTER },
1095 { "<a>", "a", "", S_OK },
1096 { "<a >", "a", "", S_OK },
1097 { "<a \r \t\n>", "a", "", S_OK },
1098 { "</a>", NULL, NULL, NC_E_QNAMECHARACTER },
1099 { NULL }
1102 static void test_read_element(void)
1104 struct test_entry *test = element_tests;
1105 static const char stag[] = "<a><b></b></a>";
1106 static const char mismatch[] = "<a></b>";
1107 IXmlReader *reader;
1108 XmlNodeType type;
1109 IStream *stream;
1110 UINT depth;
1111 HRESULT hr;
1113 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1114 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1116 while (test->xml)
1118 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1119 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1120 ok(hr == S_OK, "got %08x\n", hr);
1122 type = XmlNodeType_None;
1123 hr = IXmlReader_Read(reader, &type);
1124 if (test->hr_broken)
1125 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1126 else
1127 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1128 if (hr == S_OK)
1130 const WCHAR *str;
1131 WCHAR *str_exp;
1132 UINT len;
1134 ok(type == XmlNodeType_Element, "got %d for %s\n", type, test->xml);
1136 len = 0;
1137 str = NULL;
1138 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1139 ok(hr == S_OK, "got 0x%08x\n", hr);
1140 ok(len == strlen(test->name), "got %u\n", len);
1141 str_exp = a2w(test->name);
1142 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1143 free_str(str_exp);
1145 /* value */
1146 len = 1;
1147 str = NULL;
1148 hr = IXmlReader_GetValue(reader, &str, &len);
1149 ok(hr == S_OK, "got 0x%08x\n", hr);
1150 ok(len == 0, "got %u\n", len);
1151 ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
1154 IStream_Release(stream);
1155 test++;
1158 /* test reader depth increment */
1159 stream = create_stream_on_data(stag, sizeof(stag));
1160 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1161 ok(hr == S_OK, "got %08x\n", hr);
1163 depth = 1;
1164 hr = IXmlReader_GetDepth(reader, &depth);
1165 ok(hr == S_OK, "got %08x\n", hr);
1166 ok(depth == 0, "got %d\n", depth);
1168 hr = IXmlReader_Read(reader, &type);
1169 ok(hr == S_OK, "got %08x\n", hr);
1171 depth = 1;
1172 hr = IXmlReader_GetDepth(reader, &depth);
1173 ok(hr == S_OK, "got %08x\n", hr);
1174 ok(depth == 0, "got %d\n", depth);
1176 hr = IXmlReader_Read(reader, &type);
1177 ok(hr == S_OK, "got %08x\n", hr);
1179 depth = 0;
1180 hr = IXmlReader_GetDepth(reader, &depth);
1181 ok(hr == S_OK, "got %08x\n", hr);
1182 ok(depth == 1, "got %d\n", depth);
1184 /* read end tag for inner element */
1185 type = XmlNodeType_None;
1186 hr = IXmlReader_Read(reader, &type);
1187 ok(hr == S_OK, "got %08x\n", hr);
1188 ok(type == XmlNodeType_EndElement, "got %d\n", type);
1190 depth = 0;
1191 hr = IXmlReader_GetDepth(reader, &depth);
1192 ok(hr == S_OK, "got %08x\n", hr);
1193 todo_wine
1194 ok(depth == 2, "got %d\n", depth);
1196 /* read end tag for container element */
1197 type = XmlNodeType_None;
1198 hr = IXmlReader_Read(reader, &type);
1199 ok(hr == S_OK, "got %08x\n", hr);
1200 ok(type == XmlNodeType_EndElement, "got %d\n", type);
1202 depth = 0;
1203 hr = IXmlReader_GetDepth(reader, &depth);
1204 ok(hr == S_OK, "got %08x\n", hr);
1205 ok(depth == 1, "got %d\n", depth);
1207 IStream_Release(stream);
1209 /* start/end tag mismatch */
1210 stream = create_stream_on_data(mismatch, sizeof(mismatch));
1211 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1212 ok(hr == S_OK, "got %08x\n", hr);
1214 type = XmlNodeType_None;
1215 hr = IXmlReader_Read(reader, &type);
1216 ok(hr == S_OK, "got %08x\n", hr);
1217 ok(type == XmlNodeType_Element, "got %d\n", type);
1219 type = XmlNodeType_Element;
1220 hr = IXmlReader_Read(reader, &type);
1221 ok(hr == WC_E_ELEMENTMATCH, "got %08x\n", hr);
1222 todo_wine
1223 ok(type == XmlNodeType_None, "got %d\n", type);
1225 IStream_Release(stream);
1227 IXmlReader_Release(reader);
1230 static ISequentialStream teststream = { &teststreamvtbl };
1232 static void test_read_pending(void)
1234 IXmlReader *reader;
1235 const WCHAR *value;
1236 XmlNodeType type;
1237 HRESULT hr;
1238 int c;
1240 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1241 ok(hr == S_OK, "S_OK, got 0x%08x\n", hr);
1243 hr = IXmlReader_SetInput(reader, (IUnknown*)&teststream);
1244 ok(hr == S_OK, "got 0x%08x\n", hr);
1246 /* first read call returns incomplete node, second attempt fails with E_PENDING */
1247 stream_readcall = 0;
1248 type = XmlNodeType_Element;
1249 hr = IXmlReader_Read(reader, &type);
1250 ok(hr == S_OK || broken(hr == E_PENDING), "got 0x%08x\n", hr);
1251 /* newer versions are happy when it's enough data to detect node type,
1252 older versions keep reading until it fails to read more */
1253 ok(stream_readcall == 1 || broken(stream_readcall > 1), "got %d\n", stream_readcall);
1254 ok(type == XmlNodeType_Comment || broken(type == XmlNodeType_None), "got %d\n", type);
1256 /* newer versions' GetValue() makes an attempt to read more */
1257 c = stream_readcall;
1258 value = (void*)0xdeadbeef;
1259 hr = IXmlReader_GetValue(reader, &value, NULL);
1260 ok(hr == E_PENDING, "got 0x%08x\n", hr);
1261 ok(value == NULL || broken(value == (void*)0xdeadbeef) /* Win8 sets it to NULL */, "got %p\n", value);
1262 ok(c < stream_readcall || broken(c == stream_readcall), "got %d, expected %d\n", stream_readcall, c+1);
1264 IXmlReader_Release(reader);
1267 static void test_readvaluechunk(void)
1269 static const char testA[] = "<!-- comment1 -->";
1270 IXmlReader *reader;
1271 XmlNodeType type;
1272 IStream *stream;
1273 const WCHAR *value;
1274 WCHAR b;
1275 HRESULT hr;
1276 UINT c;
1278 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1279 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1281 stream = create_stream_on_data(testA, sizeof(testA));
1282 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1283 ok(hr == S_OK, "got %08x\n", hr);
1285 hr = IXmlReader_Read(reader, &type);
1286 ok(hr == S_OK, "got %08x\n", hr);
1288 c = 0;
1289 b = 0;
1290 hr = IXmlReader_ReadValueChunk(reader, &b, 1, &c);
1291 todo_wine {
1292 ok(hr == S_OK, "got %08x\n", hr);
1293 ok(c == 1, "got %u\n", c);
1294 ok(b == ' ', "got %x\n", b);
1296 /* portion read as chunk is skipped from resulting node value */
1297 value = NULL;
1298 hr = IXmlReader_GetValue(reader, &value, NULL);
1299 ok(hr == S_OK, "got %08x\n", hr);
1300 todo_wine
1301 ok(value[0] == 'c', "got %s\n", wine_dbgstr_w(value));
1303 /* once value is returned/allocated it's not possible to read by chunk */
1304 c = 0;
1305 b = 0;
1306 hr = IXmlReader_ReadValueChunk(reader, &b, 1, &c);
1307 todo_wine
1308 ok(hr == S_FALSE, "got %08x\n", hr);
1309 ok(c == 0, "got %u\n", c);
1310 ok(b == 0, "got %x\n", b);
1312 value = NULL;
1313 hr = IXmlReader_GetValue(reader, &value, NULL);
1314 ok(hr == S_OK, "got %08x\n", hr);
1315 todo_wine
1316 ok(value[0] == 'c', "got %s\n", wine_dbgstr_w(value));
1318 IXmlReader_Release(reader);
1321 static struct test_entry cdata_tests[] = {
1322 { "<a><![CDATA[ ]]data ]]></a>", "", " ]]data ", S_OK },
1323 { "<a><![CDATA[<![CDATA[ data ]]]]></a>", "", "<![CDATA[ data ]]", S_OK },
1324 { NULL }
1327 static void test_read_cdata(void)
1329 struct test_entry *test = cdata_tests;
1330 IXmlReader *reader;
1331 HRESULT hr;
1333 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1334 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1336 while (test->xml)
1338 XmlNodeType type;
1339 IStream *stream;
1341 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1342 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1343 ok(hr == S_OK, "got %08x\n", hr);
1345 type = XmlNodeType_None;
1346 hr = IXmlReader_Read(reader, &type);
1348 /* read one more to get to CDATA */
1349 if (type == XmlNodeType_Element)
1351 type = XmlNodeType_None;
1352 hr = IXmlReader_Read(reader, &type);
1355 if (test->hr_broken)
1356 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1357 else
1358 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1359 if (hr == S_OK)
1361 const WCHAR *str;
1362 WCHAR *str_exp;
1363 UINT len;
1365 ok(type == XmlNodeType_CDATA, "got %d for %s\n", type, test->xml);
1367 len = 1;
1368 str = NULL;
1369 hr = IXmlReader_GetLocalName(reader, &str, &len);
1370 ok(hr == S_OK, "got 0x%08x\n", hr);
1371 ok(len == strlen(test->name), "got %u\n", len);
1372 str_exp = a2w(test->name);
1373 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1374 free_str(str_exp);
1376 len = 1;
1377 str = NULL;
1378 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1379 ok(hr == S_OK, "got 0x%08x\n", hr);
1380 ok(len == strlen(test->name), "got %u\n", len);
1381 str_exp = a2w(test->name);
1382 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1383 free_str(str_exp);
1385 /* value */
1386 len = 1;
1387 str = NULL;
1388 hr = IXmlReader_GetValue(reader, &str, &len);
1389 ok(hr == S_OK, "got 0x%08x\n", hr);
1390 ok(len == strlen(test->value), "got %u\n", len);
1391 str_exp = a2w(test->value);
1392 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1393 free_str(str_exp);
1396 IStream_Release(stream);
1397 test++;
1400 IXmlReader_Release(reader);
1403 START_TEST(reader)
1405 HRESULT r;
1407 r = CoInitialize( NULL );
1408 ok( r == S_OK, "failed to init com\n");
1410 if (!init_pointers())
1412 CoUninitialize();
1413 return;
1416 test_reader_create();
1417 test_readerinput();
1418 test_reader_state();
1419 test_read_cdata();
1420 test_read_comment();
1421 test_read_pi();
1422 test_read_dtd();
1423 test_read_element();
1424 test_read_full();
1425 test_read_pending();
1426 test_readvaluechunk();
1427 test_read_xmldeclaration();
1429 CoUninitialize();