d2d1: Implement d2d_d3d_render_target_CreateBitmap().
[wine/multimedia.git] / dlls / xmllite / tests / reader.c
blob010802722d8b8b501f19805c456bf70dc633786b
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);
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);
49 return ret;
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;
63 HGLOBAL hglobal;
64 void *ptr;
65 HRESULT hr;
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);
78 return stream;
81 static void ok_pos_(IXmlReader *reader, int line, int pos, int line_broken,
82 int pos_broken, BOOL todo, int _line_)
84 UINT l, p;
85 HRESULT hr;
86 BOOL broken_state;
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)
94 broken_state = FALSE;
95 else
96 broken_state = broken((line_broken == -1 ? line : line_broken) == l &&
97 (pos_broken == -1 ? pos : pos_broken) == p);
99 if (todo)
100 todo_wine
101 ok_(__FILE__, _line_)((l == line && pos == p) || broken_state,
102 "Expected (%d,%d), got (%d,%d)\n", line, pos, l, p);
103 else
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 {
112 IID iids[10];
113 int count;
114 } input_iids_t;
116 static const IID *setinput_full[] = {
117 &IID_IXmlReaderInput,
118 &IID_IStream,
119 &IID_ISequentialStream,
120 NULL
123 /* this applies to early xmllite versions */
124 static const IID *setinput_full_old[] = {
125 &IID_IXmlReaderInput,
126 &IID_ISequentialStream,
127 &IID_IStream,
128 NULL
131 /* after ::SetInput(IXmlReaderInput*) */
132 static const IID *setinput_readerinput[] = {
133 &IID_IStream,
134 &IID_ISequentialStream,
135 NULL
138 static const IID *empty_seq[] = {
139 NULL
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)
146 int i = 0, size = 0;
148 while (expected[i++]) size++;
150 if (todo) {
151 todo_wine
152 ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
154 else
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";
179 switch (state)
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];
187 default:
188 return unknown;
192 static const char *type_to_str(XmlNodeType type)
194 static const char* type_names[] = {
195 "XmlNodeType_None",
196 "XmlNodeType_Element",
197 "XmlNodeType_Attribute",
198 "XmlNodeType_Text",
199 "XmlNodeType_CDATA",
200 "", "",
201 "XmlNodeType_ProcessingInstruction",
202 "XmlNodeType_Comment",
204 "XmlNodeType_DocumentType",
205 "", "",
206 "XmlNodeType_Whitespace",
208 "XmlNodeType_EndElement",
210 "XmlNodeType_XmlDeclaration"
213 static const char unknown[] = "unknown";
215 switch (type)
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];
229 default:
230 return unknown;
234 static void test_read_state_(IXmlReader *reader, XmlReadState expected,
235 XmlReadState exp_broken, BOOL todo, int line)
237 LONG_PTR state;
238 HRESULT hr;
239 BOOL broken_state;
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;
247 else
248 broken_state = broken(exp_broken == state);
250 if (todo)
252 todo_wine
253 ok_(__FILE__, line)(state == expected || broken_state, "Expected (%s), got (%s)\n",
254 state_to_str(expected), state_to_str(state));
256 else
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;
266 LONG ref;
267 } testinput;
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 ))
278 *ppvObj = iface;
279 IUnknown_AddRef(iface);
280 return S_OK;
283 input_iids.iids[input_iids.count++] = *riid;
285 *ppvObj = NULL;
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);
299 LONG ref;
301 ref = InterlockedDecrement(&This->ref);
302 if (ref == 0)
304 HeapFree(GetProcessHeap(), 0, This);
307 return ref;
310 static const struct IUnknownVtbl testinput_vtbl =
312 testinput_QueryInterface,
313 testinput_AddRef,
314 testinput_Release
317 static HRESULT testinput_createinstance(void **ppObj)
319 testinput *input;
321 input = HeapAlloc(GetProcessHeap(), 0, sizeof (*input));
322 if(!input) return E_OUTOFMEMORY;
324 input->IUnknown_iface.lpVtbl = &testinput_vtbl;
325 input->ref = 1;
327 *ppObj = &input->IUnknown_iface;
329 return S_OK;
332 static HRESULT WINAPI teststream_QueryInterface(ISequentialStream *iface, REFIID riid, void **obj)
334 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ISequentialStream))
336 *obj = iface;
337 return S_OK;
340 *obj = NULL;
341 return E_NOINTERFACE;
344 static ULONG WINAPI teststream_AddRef(ISequentialStream *iface)
346 return 2;
349 static ULONG WINAPI teststream_Release(ISequentialStream *iface)
351 return 1;
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++)
362 *pread = 0;
363 return E_PENDING;
366 *pread = sizeof(xml) / 2;
367 memcpy(pv, xml, *pread);
368 return S_OK;
371 static HRESULT WINAPI teststream_Write(ISequentialStream *iface, const void *pv, ULONG cb, ULONG *written)
373 ok(0, "unexpected call\n");
374 return E_NOTIMPL;
377 static const ISequentialStreamVtbl teststreamvtbl =
379 teststream_QueryInterface,
380 teststream_AddRef,
381 teststream_Release,
382 teststream_Read,
383 teststream_Write
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");
391 if (!mod)
393 win_skip("xmllite library not available\n");
394 return FALSE;
397 #define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
398 MAKEFUNC(CreateXmlReader);
399 MAKEFUNC(CreateXmlReaderInputWithEncodingName);
400 #undef MAKEFUNC
402 return TRUE;
405 static void test_reader_create(void)
407 HRESULT hr;
408 IXmlReader *reader;
409 IUnknown *input;
410 DtdProcessing dtd;
411 XmlNodeType nodetype;
413 /* crashes native */
414 if (0)
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);
430 dtd = 2;
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);
435 dtd = 2;
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);
452 if (hr == S_OK)
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;
470 HRESULT hr;
471 LONG ref;
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 */
557 input = NULL;
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);
603 /* another reader */
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)
623 IXmlReader *reader;
624 XmlNodeType nodetype;
625 HRESULT hr;
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);
636 if (0)
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};
649 static const struct
651 WCHAR name[12];
652 WCHAR val[12];
653 } name_val[] =
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} }
659 IXmlReader *reader;
660 IStream *stream;
661 HRESULT hr;
662 XmlNodeType type;
663 UINT count = 0, len, i;
664 BOOL ret;
665 const WCHAR *val;
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);
698 type = -1;
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++)
748 len = 0;
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));
754 len = 0;
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 */
780 todo_wine {
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);
792 type = -1;
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);
812 todo_wine
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);
819 type = -1;
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);
829 type = -1;
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);
845 todo_wine
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));
852 type = -1;
853 hr = IXmlReader_Read(reader, &type);
854 todo_wine
855 ok(hr == WC_E_SYNTAX || hr == WC_E_XMLCHARACTER /* XP */, "expected WC_E_SYNTAX, got %08x\n", hr);
856 todo_wine
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);
865 struct test_entry {
866 const char *xml;
867 const char *name;
868 const char *value;
869 HRESULT hr;
870 HRESULT hr_broken; /* this is set to older version results */
871 BOOL todo;
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 },
879 { NULL }
882 static void test_read_comment(void)
884 struct test_entry *test = comment_tests;
885 IXmlReader *reader;
886 HRESULT hr;
888 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
889 ok(hr == S_OK, "S_OK, got %08x\n", hr);
891 while (test->xml)
893 XmlNodeType type;
894 IStream *stream;
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);
902 if (test->hr_broken)
903 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
904 else
905 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
906 if (hr == S_OK)
908 const WCHAR *str;
909 WCHAR *str_exp;
910 UINT len;
912 ok(type == XmlNodeType_Comment, "got %d for %s\n", type, test->xml);
914 len = 1;
915 str = NULL;
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));
921 free_str(str_exp);
923 len = 1;
924 str = NULL;
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));
930 free_str(str_exp);
932 /* value */
933 len = 1;
934 str = NULL;
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));
940 free_str(str_exp);
943 IStream_Release(stream);
944 test++;
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 },
961 { NULL }
964 static void test_read_pi(void)
966 struct test_entry *test = pi_tests;
967 IXmlReader *reader;
968 HRESULT hr;
970 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
971 ok(hr == S_OK, "S_OK, got %08x\n", hr);
973 while (test->xml)
975 XmlNodeType type;
976 IStream *stream;
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);
984 if (test->hr_broken)
985 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
986 else
987 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
988 if (hr == S_OK)
990 const WCHAR *str;
991 WCHAR *str_exp;
992 UINT len;
994 ok(type == XmlNodeType_ProcessingInstruction, "got %d for %s\n", type, test->xml);
996 len = 0;
997 str = NULL;
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));
1003 free_str(str_exp);
1005 len = 0;
1006 str = NULL;
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));
1012 free_str(str_exp);
1014 /* value */
1015 len = !strlen(test->value);
1016 str = NULL;
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));
1022 free_str(str_exp);
1025 IStream_Release(stream);
1026 test++;
1029 IXmlReader_Release(reader);
1032 struct nodes_test {
1033 const char *xml;
1034 XmlNodeType types[20];
1037 static const char misc_test_xml[] =
1038 "<!-- comment1 -->"
1039 "<!-- comment2 -->"
1040 "<?pi1 pi1body ?>"
1041 "<!-- comment3 -->"
1042 " \t \r \n"
1043 "<!-- comment4 -->"
1044 "<a>"
1045 "\r\n\t"
1046 "<b/>"
1047 "text"
1048 "<!-- comment -->"
1049 "text2"
1050 "<?pi pibody ?>"
1051 "\r\n"
1052 "</a>"
1055 static struct nodes_test misc_test = {
1056 misc_test_xml,
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,
1067 XmlNodeType_Text,
1068 XmlNodeType_Comment,
1069 XmlNodeType_Text,
1070 XmlNodeType_ProcessingInstruction,
1071 XmlNodeType_Whitespace,
1072 XmlNodeType_EndElement,
1073 XmlNodeType_None
1077 static void test_read_full(void)
1079 struct nodes_test *test = &misc_test;
1080 IXmlReader *reader;
1081 XmlNodeType type;
1082 IStream *stream;
1083 HRESULT hr;
1084 int i;
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);
1093 i = 0;
1094 type = XmlNodeType_None;
1095 hr = IXmlReader_Read(reader, &type);
1096 while (hr == S_OK)
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)
1103 const WCHAR *ptr;
1104 UINT len = 0;
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);
1111 i++;
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\" >"
1121 "<!-- comment -->";
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};
1128 IXmlReader *reader;
1129 const WCHAR *str;
1130 XmlNodeType type;
1131 IStream *stream;
1132 UINT len, count;
1133 HRESULT hr;
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);
1150 count = 0;
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);
1163 len = 0;
1164 str = NULL;
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));
1170 len = 0;
1171 str = NULL;
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);
1180 len = 0;
1181 str = NULL;
1182 hr = IXmlReader_GetLocalName(reader, &str, &len);
1183 ok(hr == S_OK, "got 0x%08x\n", hr);
1184 todo_wine {
1185 ok(len == lstrlenW(dtdnameW), "got %u\n", len);
1186 ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
1188 len = 0;
1189 str = NULL;
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 },
1214 { NULL }
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>";
1222 IXmlReader *reader;
1223 XmlNodeType type;
1224 IStream *stream;
1225 UINT depth;
1226 HRESULT hr;
1228 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1229 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1231 while (test->xml)
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);
1241 else
1242 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1243 if (hr == S_OK)
1245 const WCHAR *str;
1246 WCHAR *str_exp;
1247 UINT len;
1249 ok(type == XmlNodeType_Element, "got %d for %s\n", type, test->xml);
1251 len = 0;
1252 str = NULL;
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));
1258 free_str(str_exp);
1260 /* value */
1261 len = 1;
1262 str = NULL;
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);
1270 test++;
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);
1278 depth = 1;
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);
1288 depth = 1;
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);
1298 depth = 0;
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);
1309 depth = 0;
1310 hr = IXmlReader_GetDepth(reader, &depth);
1311 ok(hr == S_OK, "got %08x\n", hr);
1312 todo_wine
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);
1321 depth = 0;
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);
1341 todo_wine
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)
1353 IXmlReader *reader;
1354 const WCHAR *value;
1355 XmlNodeType type;
1356 HRESULT hr;
1357 int c;
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 -->";
1389 IXmlReader *reader;
1390 XmlNodeType type;
1391 IStream *stream;
1392 const WCHAR *value;
1393 WCHAR b;
1394 HRESULT hr;
1395 UINT c;
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);
1407 c = 0;
1408 b = 0;
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 */
1415 value = NULL;
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 */
1421 c = 0;
1422 b = 0;
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);
1428 value = NULL;
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);
1436 static struct test_entry cdata_tests[] = {
1437 { "<a><![CDATA[ ]]data ]]></a>", "", " ]]data ", S_OK },
1438 { "<a><![CDATA[<![CDATA[ data ]]]]></a>", "", "<![CDATA[ data ]]", S_OK },
1439 { "<a><![CDATA[\n \r\n \n\n ]]></a>", "", "\n \n \n\n ", S_OK, S_OK, TRUE },
1440 { "<a><![CDATA[\r \r\r\n \n\n ]]></a>", "", "\n \n\n \n\n ", S_OK, S_OK, TRUE },
1441 { "<a><![CDATA[\r\r \n\r \r \n\n ]]></a>", "", "\n\n \n\n \n \n\n ", S_OK },
1442 { NULL }
1445 static void test_read_cdata(void)
1447 struct test_entry *test = cdata_tests;
1448 IXmlReader *reader;
1449 HRESULT hr;
1451 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1452 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1454 while (test->xml)
1456 XmlNodeType type;
1457 IStream *stream;
1459 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1460 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1461 ok(hr == S_OK, "got %08x\n", hr);
1463 type = XmlNodeType_None;
1464 hr = IXmlReader_Read(reader, &type);
1466 /* read one more to get to CDATA */
1467 if (type == XmlNodeType_Element)
1469 type = XmlNodeType_None;
1470 hr = IXmlReader_Read(reader, &type);
1473 if (test->hr_broken)
1474 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1475 else
1476 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1477 if (hr == S_OK)
1479 const WCHAR *str;
1480 WCHAR *str_exp;
1481 UINT len;
1483 ok(type == XmlNodeType_CDATA, "got %d for %s\n", type, test->xml);
1485 str_exp = a2w(test->name);
1487 len = 1;
1488 str = NULL;
1489 hr = IXmlReader_GetLocalName(reader, &str, &len);
1490 ok(hr == S_OK, "got 0x%08x\n", hr);
1491 ok(len == strlen(test->name), "got %u\n", len);
1492 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1494 str = NULL;
1495 hr = IXmlReader_GetLocalName(reader, &str, NULL);
1496 ok(hr == S_OK, "got 0x%08x\n", hr);
1497 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1499 free_str(str_exp);
1501 len = 1;
1502 str = NULL;
1503 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1504 ok(hr == S_OK, "got 0x%08x\n", hr);
1505 ok(len == strlen(test->name), "got %u\n", len);
1506 str_exp = a2w(test->name);
1507 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1508 free_str(str_exp);
1510 /* value */
1511 len = 1;
1512 str = NULL;
1513 hr = IXmlReader_GetValue(reader, &str, &len);
1514 ok(hr == S_OK, "got 0x%08x\n", hr);
1516 str_exp = a2w(test->value);
1517 if (test->todo)
1519 todo_wine {
1520 ok(len == strlen(test->value), "got %u\n", len);
1521 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1524 else
1526 ok(len == strlen(test->value), "got %u\n", len);
1527 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1529 free_str(str_exp);
1532 IStream_Release(stream);
1533 test++;
1536 IXmlReader_Release(reader);
1539 static struct test_entry text_tests[] = {
1540 { "<a>simple text</a>", "", "simple text", S_OK },
1541 { "<a>text ]]> text</a>", "", "", WC_E_CDSECTEND },
1542 { NULL }
1545 static void test_read_text(void)
1547 struct test_entry *test = text_tests;
1548 IXmlReader *reader;
1549 HRESULT hr;
1551 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1552 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1554 while (test->xml)
1556 XmlNodeType type;
1557 IStream *stream;
1559 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1560 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1561 ok(hr == S_OK, "got %08x\n", hr);
1563 type = XmlNodeType_None;
1564 hr = IXmlReader_Read(reader, &type);
1566 /* read one more to get to CDATA */
1567 if (type == XmlNodeType_Element)
1569 type = XmlNodeType_None;
1570 hr = IXmlReader_Read(reader, &type);
1573 if (test->hr_broken)
1574 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1575 else
1576 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1577 if (hr == S_OK)
1579 const WCHAR *str;
1580 WCHAR *str_exp;
1581 UINT len;
1583 ok(type == XmlNodeType_Text, "got %d for %s\n", type, test->xml);
1585 str_exp = a2w(test->name);
1587 len = 1;
1588 str = NULL;
1589 hr = IXmlReader_GetLocalName(reader, &str, &len);
1590 ok(hr == S_OK, "got 0x%08x\n", hr);
1591 ok(len == strlen(test->name), "got %u\n", len);
1592 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1594 str = NULL;
1595 hr = IXmlReader_GetLocalName(reader, &str, NULL);
1596 ok(hr == S_OK, "got 0x%08x\n", hr);
1597 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1599 free_str(str_exp);
1601 len = 1;
1602 str = NULL;
1603 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1604 ok(hr == S_OK, "got 0x%08x\n", hr);
1605 ok(len == strlen(test->name), "got %u\n", len);
1606 str_exp = a2w(test->name);
1607 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1608 free_str(str_exp);
1610 /* value */
1611 len = 1;
1612 str = NULL;
1613 hr = IXmlReader_GetValue(reader, &str, &len);
1614 ok(hr == S_OK, "got 0x%08x\n", hr);
1616 str_exp = a2w(test->value);
1617 if (test->todo)
1619 todo_wine {
1620 ok(len == strlen(test->value), "got %u\n", len);
1621 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1624 else
1626 ok(len == strlen(test->value), "got %u\n", len);
1627 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1629 free_str(str_exp);
1632 IStream_Release(stream);
1633 test++;
1636 IXmlReader_Release(reader);
1639 struct test_entry_empty {
1640 const char *xml;
1641 BOOL empty;
1644 static struct test_entry_empty empty_element_tests[] = {
1645 { "<a></a>", FALSE },
1646 { "<a/>", TRUE },
1647 { NULL }
1650 static void test_isemptyelement(void)
1652 struct test_entry_empty *test = empty_element_tests;
1653 IXmlReader *reader;
1654 HRESULT hr;
1656 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1657 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1659 while (test->xml)
1661 XmlNodeType type;
1662 IStream *stream;
1663 BOOL ret;
1665 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1666 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1667 ok(hr == S_OK, "got %08x\n", hr);
1669 type = XmlNodeType_None;
1670 hr = IXmlReader_Read(reader, &type);
1671 ok(hr == S_OK, "got 0x%08x\n", hr);
1672 ok(type == XmlNodeType_Element, "got %d\n", type);
1674 ret = IXmlReader_IsEmptyElement(reader);
1675 ok(ret == test->empty, "got %d, expected %d. xml=%s\n", ret, test->empty, test->xml);
1677 IStream_Release(stream);
1678 test++;
1681 IXmlReader_Release(reader);
1684 static struct test_entry attributes_tests[] = {
1685 { "<a attr1=\"attrvalue\"/>", "attr1", "attrvalue", S_OK },
1686 { "<a attr1=\"a\'\'ttrvalue\"/>", "attr1", "a\'\'ttrvalue", S_OK },
1687 { "<a attr1=\'a\"ttrvalue\'/>", "attr1", "a\"ttrvalue", S_OK },
1688 { "<a attr1=\' \'/>", "attr1", " ", S_OK },
1689 { "<a attr1=\" \"/>", "attr1", " ", S_OK },
1690 { "<a attr1=\"\r\n \r \n \t\n\r\"/>", "attr1", " ", S_OK },
1691 { "<a attr1=\" val \"/>", "attr1", " val ", S_OK },
1692 { "<a attr1=\"\r\n\tval\n\"/>", "attr1", " val ", S_OK },
1693 { "<a attr1=\"val&#32;\"/>", "attr1", "val ", S_OK },
1694 { "<a attr1=\"val&#x20;\"/>", "attr1", "val ", S_OK },
1695 { "<a attr1=\"&lt;&gt;&amp;&apos;&quot;\"/>", "attr1", "<>&\'\"", S_OK },
1696 { "<a attr1=\"&entname;\"/>", NULL, NULL, WC_E_UNDECLAREDENTITY },
1697 { "<a attr1=\"val&#xfffe;\"/>", NULL, NULL, WC_E_XMLCHARACTER },
1698 { "<a attr1=\"val &#a;\"/>", NULL, NULL, WC_E_DIGIT, WC_E_SEMICOLON },
1699 { "<a attr1=\"val &#12a;\"/>", NULL, NULL, WC_E_SEMICOLON },
1700 { "<a attr1=\"val &#x12g;\"/>", NULL, NULL, WC_E_SEMICOLON },
1701 { "<a attr1=\"val &#xg;\"/>", NULL, NULL, WC_E_HEXDIGIT, WC_E_SEMICOLON },
1702 { "<a attr1=attrvalue/>", NULL, NULL, WC_E_QUOTE },
1703 { "<a attr1=\"attr<value\"/>", NULL, NULL, WC_E_LESSTHAN },
1704 { "<a attr1=\"&entname\"/>", NULL, NULL, WC_E_SEMICOLON },
1705 { NULL }
1708 static void test_read_attribute(void)
1710 struct test_entry *test = attributes_tests;
1711 IXmlReader *reader;
1712 HRESULT hr;
1714 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1715 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1717 while (test->xml)
1719 XmlNodeType type;
1720 IStream *stream;
1722 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1723 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1724 ok(hr == S_OK, "got %08x\n", hr);
1726 type = XmlNodeType_None;
1727 hr = IXmlReader_Read(reader, &type);
1729 if (test->hr_broken)
1730 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1731 else
1732 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1733 if (hr == S_OK)
1735 const WCHAR *str;
1736 WCHAR *str_exp;
1737 UINT len;
1739 ok(type == XmlNodeType_Element, "got %d for %s\n", type, test->xml);
1741 hr = IXmlReader_MoveToFirstAttribute(reader);
1742 ok(hr == S_OK, "got 0x%08x\n", hr);
1744 len = 1;
1745 str = NULL;
1746 hr = IXmlReader_GetLocalName(reader, &str, &len);
1747 ok(hr == S_OK, "got 0x%08x\n", hr);
1748 ok(len == strlen(test->name), "got %u\n", len);
1749 str_exp = a2w(test->name);
1750 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1751 free_str(str_exp);
1753 len = 1;
1754 str = NULL;
1755 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1756 ok(hr == S_OK, "got 0x%08x\n", hr);
1757 todo_wine {
1758 ok(len == strlen(test->name), "got %u\n", len);
1759 str_exp = a2w(test->name);
1760 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1761 free_str(str_exp);
1763 /* value */
1764 len = 1;
1765 str = NULL;
1766 hr = IXmlReader_GetValue(reader, &str, &len);
1767 ok(hr == S_OK, "got 0x%08x\n", hr);
1768 ok(len == strlen(test->value), "got %u\n", len);
1769 str_exp = a2w(test->value);
1770 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1771 free_str(str_exp);
1774 IStream_Release(stream);
1775 test++;
1778 IXmlReader_Release(reader);
1781 START_TEST(reader)
1783 if (!init_pointers())
1784 return;
1786 test_reader_create();
1787 test_readerinput();
1788 test_reader_state();
1789 test_read_attribute();
1790 test_read_cdata();
1791 test_read_comment();
1792 test_read_pi();
1793 test_read_dtd();
1794 test_read_element();
1795 test_isemptyelement();
1796 test_read_text();
1797 test_read_full();
1798 test_read_pending();
1799 test_readvaluechunk();
1800 test_read_xmldeclaration();