[XMLLITE_WINETEST] Sync with Wine Staging 1.7.37. CORE-9246
[reactos.git] / rostests / winetests / xmllite / reader.c
1 /*
2 * IXmlReader tests
3 *
4 * Copyright 2010, 2012-2013 Nikolay Sivov
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #define COBJMACROS
26 #define CONST_VTABLE
27
28 //#include <stdarg.h>
29 #include <stdio.h>
30
31 #include <windef.h>
32 #include <winbase.h>
33 #include <winnls.h>
34 #include <initguid.h>
35 #include <ole2.h>
36 #include <xmllite.h>
37 #include <wine/test.h>
38
39 DEFINE_GUID(IID_IXmlReaderInput, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda);
40
41 static HRESULT (WINAPI *pCreateXmlReader)(REFIID riid, void **ppvObject, IMalloc *pMalloc);
42 static HRESULT (WINAPI *pCreateXmlReaderInputWithEncodingName)(IUnknown *stream,
43 IMalloc *pMalloc,
44 LPCWSTR encoding,
45 BOOL hint,
46 LPCWSTR base_uri,
47 IXmlReaderInput **ppInput);
48
49 static WCHAR *a2w(const char *str)
50 {
51 int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
52 WCHAR *ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
53 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
54 return ret;
55 }
56
57 static void free_str(WCHAR *str)
58 {
59 HeapFree(GetProcessHeap(), 0, str);
60 }
61
62 static const char xmldecl_full[] = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
63 static const char xmldecl_short[] = "<?xml version=\"1.0\"?><RegistrationInfo/>";
64
65 static IStream *create_stream_on_data(const char *data, int size)
66 {
67 IStream *stream = NULL;
68 HGLOBAL hglobal;
69 void *ptr;
70 HRESULT hr;
71
72 hglobal = GlobalAlloc(GHND, size);
73 ptr = GlobalLock(hglobal);
74
75 memcpy(ptr, data, size);
76
77 hr = CreateStreamOnHGlobal(hglobal, TRUE, &stream);
78 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
79 ok(stream != NULL, "Expected non-NULL stream\n");
80
81 GlobalUnlock(hglobal);
82
83 return stream;
84 }
85
86 static void ok_pos_(IXmlReader *reader, int line, int pos, int line_broken,
87 int pos_broken, BOOL todo, int _line_)
88 {
89 UINT l, p;
90 HRESULT hr;
91 BOOL broken_state;
92
93 hr = IXmlReader_GetLineNumber(reader, &l);
94 ok_(__FILE__, _line_)(hr == S_OK, "Expected S_OK, got %08x\n", hr);
95 hr = IXmlReader_GetLinePosition(reader, &p);
96 ok_(__FILE__, _line_)(hr == S_OK, "Expected S_OK, got %08x\n", hr);
97
98 if (line_broken == -1 && pos_broken == -1)
99 broken_state = FALSE;
100 else
101 broken_state = broken((line_broken == -1 ? line : line_broken) == l &&
102 (pos_broken == -1 ? pos : pos_broken) == p);
103
104 if (todo)
105 todo_wine
106 ok_(__FILE__, _line_)((l == line && pos == p) || broken_state,
107 "Expected (%d,%d), got (%d,%d)\n", line, pos, l, p);
108 else
109 {
110 ok_(__FILE__, _line_)((l == line && pos == p) || broken_state,
111 "Expected (%d,%d), got (%d,%d)\n", line, pos, l, p);
112 }
113 }
114 #define ok_pos(reader, l, p, l_brk, p_brk, todo) ok_pos_(reader, l, p, l_brk, p_brk, todo, __LINE__)
115
116 typedef struct input_iids_t {
117 IID iids[10];
118 int count;
119 } input_iids_t;
120
121 static const IID *setinput_full[] = {
122 &IID_IXmlReaderInput,
123 &IID_IStream,
124 &IID_ISequentialStream,
125 NULL
126 };
127
128 /* this applies to early xmllite versions */
129 static const IID *setinput_full_old[] = {
130 &IID_IXmlReaderInput,
131 &IID_ISequentialStream,
132 &IID_IStream,
133 NULL
134 };
135
136 /* after ::SetInput(IXmlReaderInput*) */
137 static const IID *setinput_readerinput[] = {
138 &IID_IStream,
139 &IID_ISequentialStream,
140 NULL
141 };
142
143 static const IID *empty_seq[] = {
144 NULL
145 };
146
147 static input_iids_t input_iids;
148
149 static void ok_iids_(const input_iids_t *iids, const IID **expected, const IID **exp_broken, BOOL todo, int line)
150 {
151 int i = 0, size = 0;
152
153 while (expected[i++]) size++;
154
155 if (todo) {
156 todo_wine
157 ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
158 }
159 else
160 ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
161
162 if (iids->count != size) return;
163
164 for (i = 0; i < size; i++) {
165 ok_(__FILE__, line)(IsEqualGUID(&iids->iids[i], expected[i]) ||
166 (exp_broken ? broken(IsEqualGUID(&iids->iids[i], exp_broken[i])) : FALSE),
167 "Wrong IID(%d), got %s\n", i, wine_dbgstr_guid(&iids->iids[i]));
168 }
169 }
170 #define ok_iids(got, exp, brk, todo) ok_iids_(got, exp, brk, todo, __LINE__)
171
172 static const char *state_to_str(XmlReadState state)
173 {
174 static const char* state_names[] = {
175 "XmlReadState_Initial",
176 "XmlReadState_Interactive",
177 "XmlReadState_Error",
178 "XmlReadState_EndOfFile",
179 "XmlReadState_Closed"
180 };
181
182 static const char unknown[] = "unknown";
183
184 switch (state)
185 {
186 case XmlReadState_Initial:
187 case XmlReadState_Interactive:
188 case XmlReadState_Error:
189 case XmlReadState_EndOfFile:
190 case XmlReadState_Closed:
191 return state_names[state];
192 default:
193 return unknown;
194 }
195 }
196
197 static const char *type_to_str(XmlNodeType type)
198 {
199 static const char* type_names[] = {
200 "XmlNodeType_None",
201 "XmlNodeType_Element",
202 "XmlNodeType_Attribute",
203 "XmlNodeType_Text",
204 "XmlNodeType_CDATA",
205 "", "",
206 "XmlNodeType_ProcessingInstruction",
207 "XmlNodeType_Comment",
208 "",
209 "XmlNodeType_DocumentType",
210 "", "",
211 "XmlNodeType_Whitespace",
212 "",
213 "XmlNodeType_EndElement",
214 "",
215 "XmlNodeType_XmlDeclaration"
216 };
217
218 static const char unknown[] = "unknown";
219
220 switch (type)
221 {
222 case XmlNodeType_None:
223 case XmlNodeType_Element:
224 case XmlNodeType_Attribute:
225 case XmlNodeType_Text:
226 case XmlNodeType_CDATA:
227 case XmlNodeType_ProcessingInstruction:
228 case XmlNodeType_Comment:
229 case XmlNodeType_DocumentType:
230 case XmlNodeType_Whitespace:
231 case XmlNodeType_EndElement:
232 case XmlNodeType_XmlDeclaration:
233 return type_names[type];
234 default:
235 return unknown;
236 }
237 }
238
239 static void test_read_state_(IXmlReader *reader, XmlReadState expected,
240 XmlReadState exp_broken, BOOL todo, int line)
241 {
242 LONG_PTR state;
243 HRESULT hr;
244 BOOL broken_state;
245
246 state = -1; /* invalid value */
247 hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, &state);
248 ok_(__FILE__, line)(hr == S_OK, "Expected S_OK, got %08x\n", hr);
249
250 if (exp_broken == -1)
251 broken_state = FALSE;
252 else
253 broken_state = broken(exp_broken == state);
254
255 if (todo)
256 {
257 todo_wine
258 ok_(__FILE__, line)(state == expected || broken_state, "Expected (%s), got (%s)\n",
259 state_to_str(expected), state_to_str(state));
260 }
261 else
262 ok_(__FILE__, line)(state == expected || broken_state, "Expected (%s), got (%s)\n",
263 state_to_str(expected), state_to_str(state));
264 }
265
266 #define test_read_state(reader, exp, brk, todo) test_read_state_(reader, exp, brk, todo, __LINE__)
267
268 typedef struct _testinput
269 {
270 IUnknown IUnknown_iface;
271 LONG ref;
272 } testinput;
273
274 static inline testinput *impl_from_IUnknown(IUnknown *iface)
275 {
276 return CONTAINING_RECORD(iface, testinput, IUnknown_iface);
277 }
278
279 static HRESULT WINAPI testinput_QueryInterface(IUnknown *iface, REFIID riid, void** ppvObj)
280 {
281 if (IsEqualGUID( riid, &IID_IUnknown ))
282 {
283 *ppvObj = iface;
284 IUnknown_AddRef(iface);
285 return S_OK;
286 }
287
288 input_iids.iids[input_iids.count++] = *riid;
289
290 *ppvObj = NULL;
291
292 return E_NOINTERFACE;
293 }
294
295 static ULONG WINAPI testinput_AddRef(IUnknown *iface)
296 {
297 testinput *This = impl_from_IUnknown(iface);
298 return InterlockedIncrement(&This->ref);
299 }
300
301 static ULONG WINAPI testinput_Release(IUnknown *iface)
302 {
303 testinput *This = impl_from_IUnknown(iface);
304 LONG ref;
305
306 ref = InterlockedDecrement(&This->ref);
307 if (ref == 0)
308 {
309 HeapFree(GetProcessHeap(), 0, This);
310 }
311
312 return ref;
313 }
314
315 static const struct IUnknownVtbl testinput_vtbl =
316 {
317 testinput_QueryInterface,
318 testinput_AddRef,
319 testinput_Release
320 };
321
322 static HRESULT testinput_createinstance(void **ppObj)
323 {
324 testinput *input;
325
326 input = HeapAlloc(GetProcessHeap(), 0, sizeof (*input));
327 if(!input) return E_OUTOFMEMORY;
328
329 input->IUnknown_iface.lpVtbl = &testinput_vtbl;
330 input->ref = 1;
331
332 *ppObj = &input->IUnknown_iface;
333
334 return S_OK;
335 }
336
337 static HRESULT WINAPI teststream_QueryInterface(ISequentialStream *iface, REFIID riid, void **obj)
338 {
339 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ISequentialStream))
340 {
341 *obj = iface;
342 return S_OK;
343 }
344
345 *obj = NULL;
346 return E_NOINTERFACE;
347 }
348
349 static ULONG WINAPI teststream_AddRef(ISequentialStream *iface)
350 {
351 return 2;
352 }
353
354 static ULONG WINAPI teststream_Release(ISequentialStream *iface)
355 {
356 return 1;
357 }
358
359 static int stream_readcall;
360
361 static HRESULT WINAPI teststream_Read(ISequentialStream *iface, void *pv, ULONG cb, ULONG *pread)
362 {
363 static const char xml[] = "<!-- comment -->";
364
365 if (stream_readcall++)
366 {
367 *pread = 0;
368 return E_PENDING;
369 }
370
371 *pread = sizeof(xml) / 2;
372 memcpy(pv, xml, *pread);
373 return S_OK;
374 }
375
376 static HRESULT WINAPI teststream_Write(ISequentialStream *iface, const void *pv, ULONG cb, ULONG *written)
377 {
378 ok(0, "unexpected call\n");
379 return E_NOTIMPL;
380 }
381
382 static const ISequentialStreamVtbl teststreamvtbl =
383 {
384 teststream_QueryInterface,
385 teststream_AddRef,
386 teststream_Release,
387 teststream_Read,
388 teststream_Write
389 };
390
391 static BOOL init_pointers(void)
392 {
393 /* don't free module here, it's to be unloaded on exit */
394 HMODULE mod = LoadLibraryA("xmllite.dll");
395
396 if (!mod)
397 {
398 win_skip("xmllite library not available\n");
399 return FALSE;
400 }
401
402 #define MAKEFUNC(f) if (!(p##f = (void*)GetProcAddress(mod, #f))) return FALSE;
403 MAKEFUNC(CreateXmlReader);
404 MAKEFUNC(CreateXmlReaderInputWithEncodingName);
405 #undef MAKEFUNC
406
407 return TRUE;
408 }
409
410 static void test_reader_create(void)
411 {
412 HRESULT hr;
413 IXmlReader *reader;
414 IUnknown *input;
415 DtdProcessing dtd;
416 XmlNodeType nodetype;
417
418 /* crashes native */
419 if (0)
420 {
421 pCreateXmlReader(&IID_IXmlReader, NULL, NULL);
422 pCreateXmlReader(NULL, (void**)&reader, NULL);
423 }
424
425 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
426 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
427
428 test_read_state(reader, XmlReadState_Closed, -1, FALSE);
429
430 nodetype = XmlNodeType_Element;
431 hr = IXmlReader_GetNodeType(reader, &nodetype);
432 ok(hr == S_FALSE, "got %08x\n", hr);
433 ok(nodetype == XmlNodeType_None, "got %d\n", nodetype);
434
435 dtd = 2;
436 hr = IXmlReader_GetProperty(reader, XmlReaderProperty_DtdProcessing, (LONG_PTR*)&dtd);
437 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
438 ok(dtd == DtdProcessing_Prohibit, "got %d\n", dtd);
439
440 dtd = 2;
441 hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, dtd);
442 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
443
444 hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, -1);
445 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
446
447 /* Null input pointer, releases previous input */
448 hr = IXmlReader_SetInput(reader, NULL);
449 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
450
451 test_read_state(reader, XmlReadState_Initial, XmlReadState_Closed, FALSE);
452
453 /* test input interface selection sequence */
454 hr = testinput_createinstance((void**)&input);
455 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
456
457 if (hr == S_OK)
458 {
459 input_iids.count = 0;
460 hr = IXmlReader_SetInput(reader, input);
461 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
462 ok_iids(&input_iids, setinput_full, setinput_full_old, FALSE);
463 IUnknown_Release(input);
464 }
465 IXmlReader_Release(reader);
466 }
467
468 static void test_readerinput(void)
469 {
470 IXmlReaderInput *reader_input;
471 IXmlReader *reader, *reader2;
472 IUnknown *obj, *input;
473 IStream *stream, *stream2;
474 XmlNodeType nodetype;
475 HRESULT hr;
476 LONG ref;
477
478 hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, NULL);
479 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
480 hr = pCreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, &reader_input);
481 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
482
483 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
484 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
485
486 ref = IStream_AddRef(stream);
487 ok(ref == 2, "Expected 2, got %d\n", ref);
488 IStream_Release(stream);
489 hr = pCreateXmlReaderInputWithEncodingName((IUnknown*)stream, NULL, NULL, FALSE, NULL, &reader_input);
490 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
491
492 hr = IUnknown_QueryInterface(reader_input, &IID_IStream, (void**)&stream2);
493 ok(hr == E_NOINTERFACE, "Expected S_OK, got %08x\n", hr);
494
495 hr = IUnknown_QueryInterface(reader_input, &IID_ISequentialStream, (void**)&stream2);
496 ok(hr == E_NOINTERFACE, "Expected S_OK, got %08x\n", hr);
497
498 /* IXmlReaderInput grabs a stream reference */
499 ref = IStream_AddRef(stream);
500 ok(ref == 3, "Expected 3, got %d\n", ref);
501 IStream_Release(stream);
502
503 /* try ::SetInput() with valid IXmlReaderInput */
504 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
505 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
506
507 ref = IUnknown_AddRef(reader_input);
508 ok(ref == 2, "Expected 2, got %d\n", ref);
509 IUnknown_Release(reader_input);
510
511 hr = IXmlReader_SetInput(reader, reader_input);
512 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
513
514 test_read_state(reader, XmlReadState_Initial, -1, FALSE);
515
516 nodetype = XmlNodeType_Element;
517 hr = IXmlReader_GetNodeType(reader, &nodetype);
518 ok(hr == S_OK, "got %08x\n", hr);
519 ok(nodetype == XmlNodeType_None, "got %d\n", nodetype);
520
521 /* IXmlReader grabs a IXmlReaderInput reference */
522 ref = IUnknown_AddRef(reader_input);
523 ok(ref == 3, "Expected 3, got %d\n", ref);
524 IUnknown_Release(reader_input);
525
526 ref = IStream_AddRef(stream);
527 ok(ref == 4, "Expected 4, got %d\n", ref);
528 IStream_Release(stream);
529
530 /* reset input and check state */
531 hr = IXmlReader_SetInput(reader, NULL);
532 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
533
534 test_read_state(reader, XmlReadState_Initial, XmlReadState_Closed, FALSE);
535
536 IXmlReader_Release(reader);
537
538 ref = IStream_AddRef(stream);
539 ok(ref == 3, "Expected 3, got %d\n", ref);
540 IStream_Release(stream);
541
542 ref = IUnknown_AddRef(reader_input);
543 ok(ref == 2, "Expected 2, got %d\n", ref);
544 IUnknown_Release(reader_input);
545
546 /* IID_IXmlReaderInput */
547 /* it returns a kind of private undocumented vtable incompatible with IUnknown,
548 so it's not a COM interface actually.
549 Such query will be used only to check if input is really IXmlReaderInput */
550 obj = (IUnknown*)0xdeadbeef;
551 hr = IUnknown_QueryInterface(reader_input, &IID_IXmlReaderInput, (void**)&obj);
552 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
553 ref = IUnknown_AddRef(reader_input);
554 ok(ref == 3, "Expected 3, got %d\n", ref);
555 IUnknown_Release(reader_input);
556
557 IUnknown_Release(reader_input);
558 IUnknown_Release(reader_input);
559 IStream_Release(stream);
560
561 /* test input interface selection sequence */
562 input = NULL;
563 hr = testinput_createinstance((void**)&input);
564 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
565
566 input_iids.count = 0;
567 ref = IUnknown_AddRef(input);
568 ok(ref == 2, "Expected 2, got %d\n", ref);
569 IUnknown_Release(input);
570 hr = pCreateXmlReaderInputWithEncodingName(input, NULL, NULL, FALSE, NULL, &reader_input);
571 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
572 ok_iids(&input_iids, empty_seq, NULL, FALSE);
573 /* IXmlReaderInput stores stream interface as IUnknown */
574 ref = IUnknown_AddRef(input);
575 ok(ref == 3, "Expected 3, got %d\n", ref);
576 IUnknown_Release(input);
577
578 hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
579 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
580
581 input_iids.count = 0;
582 ref = IUnknown_AddRef(reader_input);
583 ok(ref == 2, "Expected 2, got %d\n", ref);
584 IUnknown_Release(reader_input);
585 ref = IUnknown_AddRef(input);
586 ok(ref == 3, "Expected 3, got %d\n", ref);
587 IUnknown_Release(input);
588 hr = IXmlReader_SetInput(reader, reader_input);
589 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
590 ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
591
592 test_read_state(reader, XmlReadState_Closed, -1, FALSE);
593
594 ref = IUnknown_AddRef(input);
595 ok(ref == 3, "Expected 3, got %d\n", ref);
596 IUnknown_Release(input);
597
598 ref = IUnknown_AddRef(reader_input);
599 ok(ref == 3 || broken(ref == 2) /* versions 1.0.x and 1.1.x - XP, Vista */,
600 "Expected 3, got %d\n", ref);
601 IUnknown_Release(reader_input);
602 /* repeat another time, no check or caching here */
603 input_iids.count = 0;
604 hr = IXmlReader_SetInput(reader, reader_input);
605 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
606 ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
607
608 /* another reader */
609 hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader2, NULL);
610 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
611
612 /* resolving from IXmlReaderInput to IStream/ISequentialStream is done at
613 ::SetInput() level, each time it's called */
614 input_iids.count = 0;
615 hr = IXmlReader_SetInput(reader2, reader_input);
616 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
617 ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
618
619 IXmlReader_Release(reader2);
620 IXmlReader_Release(reader);
621
622 IUnknown_Release(reader_input);
623 IUnknown_Release(input);
624 }
625
626 static void test_reader_state(void)
627 {
628 IXmlReader *reader;
629 XmlNodeType nodetype;
630 HRESULT hr;
631
632 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
633 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
634
635 /* invalid arguments */
636 hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, NULL);
637 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
638
639 /* attempt to read on closed reader */
640 test_read_state(reader, XmlReadState_Closed, -1, FALSE);
641 if (0)
642 {
643 /* newer versions crash here, probably cause no input was set */
644 hr = IXmlReader_Read(reader, &nodetype);
645 ok(hr == S_FALSE, "got %08x\n", hr);
646 }
647 IXmlReader_Release(reader);
648 }
649
650 static void test_read_xmldeclaration(void)
651 {
652 static const WCHAR xmlW[] = {'x','m','l',0};
653 static const WCHAR RegistrationInfoW[] = {'R','e','g','i','s','t','r','a','t','i','o','n','I','n','f','o',0};
654 static const struct
655 {
656 WCHAR name[12];
657 WCHAR val[12];
658 } name_val[] =
659 {
660 { {'v','e','r','s','i','o','n',0}, {'1','.','0',0} },
661 { {'e','n','c','o','d','i','n','g',0}, {'U','T','F','-','8',0} },
662 { {'s','t','a','n','d','a','l','o','n','e',0}, {'y','e','s',0} }
663 };
664 IXmlReader *reader;
665 IStream *stream;
666 HRESULT hr;
667 XmlNodeType type;
668 UINT count = 0, len, i;
669 BOOL ret;
670 const WCHAR *val;
671
672 hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
673 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
674
675 /* position methods with Null args */
676 hr = IXmlReader_GetLineNumber(reader, NULL);
677 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
678
679 hr = IXmlReader_GetLinePosition(reader, NULL);
680 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
681
682 stream = create_stream_on_data(xmldecl_full, sizeof(xmldecl_full));
683
684 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
685 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
686
687 hr = IXmlReader_GetAttributeCount(reader, &count);
688 ok(hr == S_OK, "got %08x\n", hr);
689 ok(count == 0, "got %d\n", count);
690
691 /* try to move without attributes */
692 hr = IXmlReader_MoveToElement(reader);
693 ok(hr == S_FALSE, "got %08x\n", hr);
694
695 hr = IXmlReader_MoveToNextAttribute(reader);
696 ok(hr == S_FALSE, "got %08x\n", hr);
697
698 hr = IXmlReader_MoveToFirstAttribute(reader);
699 ok(hr == S_FALSE, "got %08x\n", hr);
700
701 ok_pos(reader, 0, 0, -1, -1, FALSE);
702
703 type = -1;
704 hr = IXmlReader_Read(reader, &type);
705 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
706 ok(type == XmlNodeType_XmlDeclaration,
707 "Expected XmlNodeType_XmlDeclaration, got %s\n", type_to_str(type));
708 /* new version 1.2.x and 1.3.x properly update position for <?xml ?> */
709 ok_pos(reader, 1, 3, -1, 55, TRUE);
710 test_read_state(reader, XmlReadState_Interactive, -1, FALSE);
711
712 hr = IXmlReader_GetValue(reader, &val, NULL);
713 ok(hr == S_OK, "got %08x\n", hr);
714 ok(*val == 0, "got %s\n", wine_dbgstr_w(val));
715
716 /* check attributes */
717 hr = IXmlReader_MoveToNextAttribute(reader);
718 ok(hr == S_OK, "got %08x\n", hr);
719
720 type = XmlNodeType_None;
721 hr = IXmlReader_GetNodeType(reader, &type);
722 ok(hr == S_OK, "got %08x\n", hr);
723 ok(type == XmlNodeType_Attribute, "got %d\n", type);
724
725 ok_pos(reader, 1, 7, -1, 55, TRUE);
726
727 /* try to move from last attribute */
728 hr = IXmlReader_MoveToNextAttribute(reader);
729 ok(hr == S_OK, "got %08x\n", hr);
730 hr = IXmlReader_MoveToNextAttribute(reader);
731 ok(hr == S_OK, "got %08x\n", hr);
732 hr = IXmlReader_MoveToNextAttribute(reader);
733 ok(hr == S_FALSE, "got %08x\n", hr);
734
735 type = XmlNodeType_None;
736 hr = IXmlReader_GetNodeType(reader, &type);
737 ok(hr == S_OK, "got %08x\n", hr);
738 ok(type == XmlNodeType_Attribute, "got %d\n", type);
739
740 hr = IXmlReader_MoveToFirstAttribute(reader);
741 ok(hr == S_OK, "got %08x\n", hr);
742 ok_pos(reader, 1, 7, -1, 55, TRUE);
743
744 hr = IXmlReader_GetAttributeCount(reader, NULL);
745 ok(hr == E_INVALIDARG, "got %08x\n", hr);
746
747 hr = IXmlReader_GetAttributeCount(reader, &count);
748 ok(hr == S_OK, "got %08x\n", hr);
749 ok(count == 3, "Expected 3, got %d\n", count);
750
751 for (i = 0; i < count; i++)
752 {
753 len = 0;
754 hr = IXmlReader_GetLocalName(reader, &val, &len);
755 ok(hr == S_OK, "got %08x\n", hr);
756 ok(len == lstrlenW(name_val[i].name), "expected %u, got %u\n", lstrlenW(name_val[i].name), len);
757 ok(!lstrcmpW(name_val[i].name, val), "expected %s, got %s\n", wine_dbgstr_w(name_val[i].name), wine_dbgstr_w(val));
758
759 len = 0;
760 hr = IXmlReader_GetValue(reader, &val, &len);
761 ok(hr == S_OK, "got %08x\n", hr);
762 ok(len == lstrlenW(name_val[i].val), "expected %u, got %u\n", lstrlenW(name_val[i].val), len);
763 ok(!lstrcmpW(name_val[i].val, val), "expected %s, got %s\n", wine_dbgstr_w(name_val[i].val), wine_dbgstr_w(val));
764
765 hr = IXmlReader_MoveToNextAttribute(reader);
766 ok(hr == ((i < count - 1) ? S_OK : S_FALSE), "got %08x\n", hr);
767 }
768
769 hr = IXmlReader_GetDepth(reader, &count);
770 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
771 ok(count == 1, "Expected 1, got %d\n", count);
772
773 hr = IXmlReader_MoveToElement(reader);
774 ok(hr == S_OK, "got %08x\n", hr);
775
776 type = XmlNodeType_None;
777 hr = IXmlReader_GetNodeType(reader, &type);
778 ok(hr == S_OK, "got %08x\n", hr);
779 ok(type == XmlNodeType_XmlDeclaration, "got %d\n", type);
780
781 type = XmlNodeType_XmlDeclaration;
782 hr = IXmlReader_Read(reader, &type);
783 /* newer versions return syntax error here cause document is incomplete,
784 it makes more sense than invalid char error */
785 todo_wine {
786 ok(hr == WC_E_SYNTAX || broken(hr == WC_E_XMLCHARACTER), "got 0x%08x\n", hr);
787 ok(type == XmlNodeType_None, "got %d\n", type);
788 }
789 IStream_Release(stream);
790
791 /* test short variant */
792 stream = create_stream_on_data(xmldecl_short, sizeof(xmldecl_short));
793
794 hr = IXmlReader_SetInput(reader, (IUnknown *)stream);
795 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
796
797 type = -1;
798 hr = IXmlReader_Read(reader, &type);
799 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
800 ok(type == XmlNodeType_XmlDeclaration, "expected XmlDeclaration, got %s\n", type_to_str(type));
801 ok_pos(reader, 1, 3, 1, 21, TRUE);
802 test_read_state(reader, XmlReadState_Interactive, -1, TRUE);
803
804 hr = IXmlReader_GetAttributeCount(reader, &count);
805 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
806 ok(count == 1, "expected 1, got %d\n", count);
807
808 ret = IXmlReader_IsEmptyElement(reader);
809 ok(!ret, "element should not be empty\n");
810
811 hr = IXmlReader_GetValue(reader, &val, NULL);
812 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
813 ok(*val == 0, "got %s\n", wine_dbgstr_w(val));
814
815 hr = IXmlReader_GetLocalName(reader, &val, NULL);
816 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
817 todo_wine
818 ok(!lstrcmpW(val, xmlW), "got %s\n", wine_dbgstr_w(val));
819
820 /* check attributes */
821 hr = IXmlReader_MoveToNextAttribute(reader);
822 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
823
824 type = -1;
825 hr = IXmlReader_GetNodeType(reader, &type);
826 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
827 ok(type == XmlNodeType_Attribute, "got %d\n", type);
828 ok_pos(reader, 1, 7, 1, 21, TRUE);
829
830 /* try to move from last attribute */
831 hr = IXmlReader_MoveToNextAttribute(reader);
832 ok(hr == S_FALSE, "expected S_FALSE, got %08x\n", hr);
833
834 type = -1;
835 hr = IXmlReader_Read(reader, &type);
836 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
837 ok(type == XmlNodeType_Element, "expected Element, got %s\n", type_to_str(type));
838 ok_pos(reader, 1, 23, 1, 40, TRUE);
839 test_read_state(reader, XmlReadState_Interactive, -1, TRUE);
840
841 hr = IXmlReader_GetAttributeCount(reader, &count);
842 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
843 ok(count == 0, "expected 0, got %d\n", count);
844
845 ret = IXmlReader_IsEmptyElement(reader);
846 ok(ret, "element should be empty\n");
847
848 hr = IXmlReader_GetValue(reader, &val, NULL);
849 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
850 todo_wine
851 ok(*val == 0, "got %s\n", wine_dbgstr_w(val));
852
853 hr = IXmlReader_GetLocalName(reader, &val, NULL);
854 ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
855 ok(!lstrcmpW(val, RegistrationInfoW), "got %s\n", wine_dbgstr_w(val));
856
857 type = -1;
858 hr = IXmlReader_Read(reader, &type);
859 todo_wine
860 ok(hr == WC_E_SYNTAX || hr == WC_E_XMLCHARACTER /* XP */, "expected WC_E_SYNTAX, got %08x\n", hr);
861 todo_wine
862 ok(type == XmlNodeType_None, "expected None, got %s\n", type_to_str(type));
863 ok_pos(reader, 1, 41, -1, -1, TRUE);
864 test_read_state(reader, XmlReadState_Error, -1, TRUE);
865
866 IStream_Release(stream);
867 IXmlReader_Release(reader);
868 }
869
870 struct test_entry {
871 const char *xml;
872 const char *name;
873 const char *value;
874 HRESULT hr;
875 HRESULT hr_broken; /* this is set to older version results */
876 BOOL todo;
877 };
878
879 static struct test_entry comment_tests[] = {
880 { "<!-- comment -->", "", " comment ", S_OK },
881 { "<!-- - comment-->", "", " - comment", S_OK },
882 { "<!-- -- comment-->", NULL, NULL, WC_E_COMMENT, WC_E_GREATERTHAN },
883 { "<!-- -- comment--->", NULL, NULL, WC_E_COMMENT, WC_E_GREATERTHAN },
884 { NULL }
885 };
886
887 static void test_read_comment(void)
888 {
889 struct test_entry *test = comment_tests;
890 IXmlReader *reader;
891 HRESULT hr;
892
893 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
894 ok(hr == S_OK, "S_OK, got %08x\n", hr);
895
896 while (test->xml)
897 {
898 XmlNodeType type;
899 IStream *stream;
900
901 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
902 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
903 ok(hr == S_OK, "got %08x\n", hr);
904
905 type = XmlNodeType_None;
906 hr = IXmlReader_Read(reader, &type);
907 if (test->hr_broken)
908 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
909 else
910 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
911 if (hr == S_OK)
912 {
913 const WCHAR *str;
914 WCHAR *str_exp;
915 UINT len;
916
917 ok(type == XmlNodeType_Comment, "got %d for %s\n", type, test->xml);
918
919 len = 1;
920 str = NULL;
921 hr = IXmlReader_GetLocalName(reader, &str, &len);
922 ok(hr == S_OK, "got 0x%08x\n", hr);
923 ok(len == strlen(test->name), "got %u\n", len);
924 str_exp = a2w(test->name);
925 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
926 free_str(str_exp);
927
928 len = 1;
929 str = NULL;
930 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
931 ok(hr == S_OK, "got 0x%08x\n", hr);
932 ok(len == strlen(test->name), "got %u\n", len);
933 str_exp = a2w(test->name);
934 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
935 free_str(str_exp);
936
937 /* value */
938 len = 1;
939 str = NULL;
940 hr = IXmlReader_GetValue(reader, &str, &len);
941 ok(hr == S_OK, "got 0x%08x\n", hr);
942 ok(len == strlen(test->value), "got %u\n", len);
943 str_exp = a2w(test->value);
944 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
945 free_str(str_exp);
946 }
947
948 IStream_Release(stream);
949 test++;
950 }
951
952 IXmlReader_Release(reader);
953 }
954
955 static struct test_entry pi_tests[] = {
956 { "<?pi?>", "pi", "", S_OK },
957 { "<?pi ?>", "pi", "", S_OK },
958 { "<?pi ?>", "pi", "", S_OK },
959 { "<?pi pi data?>", "pi", "pi data", S_OK },
960 { "<?pi pi data ?>", "pi", "pi data ", S_OK },
961 { "<?pi data ?>", "pi", "data ", S_OK },
962 { "<?pi:pi?>", NULL, NULL, NC_E_NAMECOLON, WC_E_NAMECHARACTER },
963 { "<?:pi ?>", NULL, NULL, WC_E_PI, WC_E_NAMECHARACTER },
964 { "<?-pi ?>", NULL, NULL, WC_E_PI, WC_E_NAMECHARACTER },
965 { "<?xml-stylesheet ?>", "xml-stylesheet", "", S_OK },
966 { NULL }
967 };
968
969 static void test_read_pi(void)
970 {
971 struct test_entry *test = pi_tests;
972 IXmlReader *reader;
973 HRESULT hr;
974
975 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
976 ok(hr == S_OK, "S_OK, got %08x\n", hr);
977
978 while (test->xml)
979 {
980 XmlNodeType type;
981 IStream *stream;
982
983 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
984 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
985 ok(hr == S_OK, "got %08x\n", hr);
986
987 type = XmlNodeType_None;
988 hr = IXmlReader_Read(reader, &type);
989 if (test->hr_broken)
990 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
991 else
992 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
993 if (hr == S_OK)
994 {
995 const WCHAR *str;
996 WCHAR *str_exp;
997 UINT len;
998
999 ok(type == XmlNodeType_ProcessingInstruction, "got %d for %s\n", type, test->xml);
1000
1001 len = 0;
1002 str = NULL;
1003 hr = IXmlReader_GetLocalName(reader, &str, &len);
1004 ok(hr == S_OK, "got 0x%08x\n", hr);
1005 ok(len == strlen(test->name), "got %u\n", len);
1006 str_exp = a2w(test->name);
1007 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1008 free_str(str_exp);
1009
1010 len = 0;
1011 str = NULL;
1012 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1013 ok(hr == S_OK, "got 0x%08x\n", hr);
1014 ok(len == strlen(test->name), "got %u\n", len);
1015 str_exp = a2w(test->name);
1016 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1017 free_str(str_exp);
1018
1019 /* value */
1020 len = !strlen(test->value);
1021 str = NULL;
1022 hr = IXmlReader_GetValue(reader, &str, &len);
1023 ok(hr == S_OK, "got 0x%08x\n", hr);
1024 ok(len == strlen(test->value), "got %u\n", len);
1025 str_exp = a2w(test->value);
1026 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1027 free_str(str_exp);
1028 }
1029
1030 IStream_Release(stream);
1031 test++;
1032 }
1033
1034 IXmlReader_Release(reader);
1035 }
1036
1037 struct nodes_test {
1038 const char *xml;
1039 XmlNodeType types[20];
1040 };
1041
1042 static const char misc_test_xml[] =
1043 "<!-- comment1 -->"
1044 "<!-- comment2 -->"
1045 "<?pi1 pi1body ?>"
1046 "<!-- comment3 -->"
1047 " \t \r \n"
1048 "<!-- comment4 -->"
1049 "<a>"
1050 "\r\n\t"
1051 "<b/>"
1052 "text"
1053 "<!-- comment -->"
1054 "text2"
1055 "<?pi pibody ?>"
1056 "\r\n"
1057 "</a>"
1058 ;
1059
1060 static struct nodes_test misc_test = {
1061 misc_test_xml,
1062 {
1063 XmlNodeType_Comment,
1064 XmlNodeType_Comment,
1065 XmlNodeType_ProcessingInstruction,
1066 XmlNodeType_Comment,
1067 XmlNodeType_Whitespace,
1068 XmlNodeType_Comment,
1069 XmlNodeType_Element,
1070 XmlNodeType_Whitespace,
1071 XmlNodeType_Element,
1072 XmlNodeType_Text,
1073 XmlNodeType_Comment,
1074 XmlNodeType_Text,
1075 XmlNodeType_ProcessingInstruction,
1076 XmlNodeType_Whitespace,
1077 XmlNodeType_EndElement,
1078 XmlNodeType_None
1079 }
1080 };
1081
1082 static void test_read_full(void)
1083 {
1084 struct nodes_test *test = &misc_test;
1085 IXmlReader *reader;
1086 XmlNodeType type;
1087 IStream *stream;
1088 HRESULT hr;
1089 int i;
1090
1091 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1092 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1093
1094 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1095 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1096 ok(hr == S_OK, "got %08x\n", hr);
1097
1098 i = 0;
1099 type = XmlNodeType_None;
1100 hr = IXmlReader_Read(reader, &type);
1101 while (hr == S_OK)
1102 {
1103 ok(test->types[i] != XmlNodeType_None, "%d: unexpected end of test data\n", i);
1104 if (test->types[i] == XmlNodeType_None) break;
1105 ok(type == test->types[i], "%d: got wrong type %d, expected %d\n", i, type, test->types[i]);
1106 if (type == XmlNodeType_Whitespace)
1107 {
1108 const WCHAR *ptr;
1109 UINT len = 0;
1110
1111 hr = IXmlReader_GetValue(reader, &ptr, &len);
1112 ok(hr == S_OK, "%d: GetValue failed 0x%08x\n", i, hr);
1113 ok(len > 0, "%d: wrong value length %d\n", i, len);
1114 }
1115 hr = IXmlReader_Read(reader, &type);
1116 i++;
1117 }
1118 ok(test->types[i] == XmlNodeType_None, "incomplete sequence, got %d\n", test->types[i]);
1119
1120 IStream_Release(stream);
1121 IXmlReader_Release(reader);
1122 }
1123
1124 static const char test_dtd[] =
1125 "<!DOCTYPE testdtd SYSTEM \"externalid uri\" >"
1126 "<!-- comment -->";
1127
1128 static void test_read_dtd(void)
1129 {
1130 static const WCHAR sysvalW[] = {'e','x','t','e','r','n','a','l','i','d',' ','u','r','i',0};
1131 static const WCHAR dtdnameW[] = {'t','e','s','t','d','t','d',0};
1132 static const WCHAR sysW[] = {'S','Y','S','T','E','M',0};
1133 IXmlReader *reader;
1134 const WCHAR *str;
1135 XmlNodeType type;
1136 IStream *stream;
1137 UINT len, count;
1138 HRESULT hr;
1139
1140 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1141 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1142
1143 hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, DtdProcessing_Parse);
1144 ok(hr == S_OK, "got 0x%8x\n", hr);
1145
1146 stream = create_stream_on_data(test_dtd, sizeof(test_dtd));
1147 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1148 ok(hr == S_OK, "got %08x\n", hr);
1149
1150 type = XmlNodeType_None;
1151 hr = IXmlReader_Read(reader, &type);
1152 ok(hr == S_OK, "got 0x%8x\n", hr);
1153 ok(type == XmlNodeType_DocumentType, "got type %d\n", type);
1154
1155 count = 0;
1156 hr = IXmlReader_GetAttributeCount(reader, &count);
1157 ok(hr == S_OK, "got %08x\n", hr);
1158 ok(count == 1, "got %d\n", count);
1159
1160 hr = IXmlReader_MoveToFirstAttribute(reader);
1161 ok(hr == S_OK, "got %08x\n", hr);
1162
1163 type = XmlNodeType_None;
1164 hr = IXmlReader_GetNodeType(reader, &type);
1165 ok(hr == S_OK, "got %08x\n", hr);
1166 ok(type == XmlNodeType_Attribute, "got %d\n", type);
1167
1168 len = 0;
1169 str = NULL;
1170 hr = IXmlReader_GetLocalName(reader, &str, &len);
1171 ok(hr == S_OK, "got 0x%08x\n", hr);
1172 ok(len == lstrlenW(sysW), "got %u\n", len);
1173 ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
1174
1175 len = 0;
1176 str = NULL;
1177 hr = IXmlReader_GetValue(reader, &str, &len);
1178 ok(hr == S_OK, "got 0x%08x\n", hr);
1179 ok(len == lstrlenW(sysvalW), "got %u\n", len);
1180 ok(!lstrcmpW(str, sysvalW), "got %s\n", wine_dbgstr_w(str));
1181
1182 hr = IXmlReader_MoveToElement(reader);
1183 ok(hr == S_OK, "got 0x%08x\n", hr);
1184
1185 len = 0;
1186 str = NULL;
1187 hr = IXmlReader_GetLocalName(reader, &str, &len);
1188 ok(hr == S_OK, "got 0x%08x\n", hr);
1189 todo_wine {
1190 ok(len == lstrlenW(dtdnameW), "got %u\n", len);
1191 ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
1192 }
1193 len = 0;
1194 str = NULL;
1195 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1196 ok(hr == S_OK, "got 0x%08x\n", hr);
1197 ok(len == lstrlenW(dtdnameW), "got %u\n", len);
1198 ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
1199
1200 type = XmlNodeType_None;
1201 hr = IXmlReader_Read(reader, &type);
1202 ok(hr == S_OK, "got 0x%8x\n", hr);
1203 ok(type == XmlNodeType_Comment, "got type %d\n", type);
1204
1205 IStream_Release(stream);
1206 IXmlReader_Release(reader);
1207 }
1208
1209 static struct test_entry element_tests[] = {
1210 { "<a/>", "a", "", S_OK },
1211 { "<a />", "a", "", S_OK },
1212 { "<a:b/>", "a:b", "", NC_E_UNDECLAREDPREFIX },
1213 { "<:a/>", NULL, NULL, NC_E_QNAMECHARACTER },
1214 { "< a/>", NULL, NULL, NC_E_QNAMECHARACTER },
1215 { "<a>", "a", "", S_OK },
1216 { "<a >", "a", "", S_OK },
1217 { "<a \r \t\n>", "a", "", S_OK },
1218 { "</a>", NULL, NULL, NC_E_QNAMECHARACTER },
1219 { NULL }
1220 };
1221
1222 static void test_read_element(void)
1223 {
1224 struct test_entry *test = element_tests;
1225 static const char stag[] = "<a><b></b></a>";
1226 static const char mismatch[] = "<a></b>";
1227 IXmlReader *reader;
1228 XmlNodeType type;
1229 IStream *stream;
1230 UINT depth;
1231 HRESULT hr;
1232
1233 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1234 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1235
1236 while (test->xml)
1237 {
1238 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1239 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1240 ok(hr == S_OK, "got %08x\n", hr);
1241
1242 type = XmlNodeType_None;
1243 hr = IXmlReader_Read(reader, &type);
1244 if (test->hr_broken)
1245 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1246 else
1247 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1248 if (hr == S_OK)
1249 {
1250 const WCHAR *str;
1251 WCHAR *str_exp;
1252 UINT len;
1253
1254 ok(type == XmlNodeType_Element, "got %d for %s\n", type, test->xml);
1255
1256 len = 0;
1257 str = NULL;
1258 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1259 ok(hr == S_OK, "got 0x%08x\n", hr);
1260 ok(len == strlen(test->name), "got %u\n", len);
1261 str_exp = a2w(test->name);
1262 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1263 free_str(str_exp);
1264
1265 /* value */
1266 len = 1;
1267 str = NULL;
1268 hr = IXmlReader_GetValue(reader, &str, &len);
1269 ok(hr == S_OK, "got 0x%08x\n", hr);
1270 ok(len == 0, "got %u\n", len);
1271 ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
1272 }
1273
1274 IStream_Release(stream);
1275 test++;
1276 }
1277
1278 /* test reader depth increment */
1279 stream = create_stream_on_data(stag, sizeof(stag));
1280 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1281 ok(hr == S_OK, "got %08x\n", hr);
1282
1283 depth = 1;
1284 hr = IXmlReader_GetDepth(reader, &depth);
1285 ok(hr == S_OK, "got %08x\n", hr);
1286 ok(depth == 0, "got %d\n", depth);
1287
1288 type = XmlNodeType_None;
1289 hr = IXmlReader_Read(reader, &type);
1290 ok(hr == S_OK, "got %08x\n", hr);
1291 ok(type == XmlNodeType_Element, "got %d\n", type);
1292
1293 depth = 1;
1294 hr = IXmlReader_GetDepth(reader, &depth);
1295 ok(hr == S_OK, "got %08x\n", hr);
1296 ok(depth == 0, "got %d\n", depth);
1297
1298 type = XmlNodeType_None;
1299 hr = IXmlReader_Read(reader, &type);
1300 ok(hr == S_OK, "got %08x\n", hr);
1301 ok(type == XmlNodeType_Element, "got %d\n", type);
1302
1303 depth = 0;
1304 hr = IXmlReader_GetDepth(reader, &depth);
1305 ok(hr == S_OK, "got %08x\n", hr);
1306 ok(depth == 1, "got %d\n", depth);
1307
1308 /* read end tag for inner element */
1309 type = XmlNodeType_None;
1310 hr = IXmlReader_Read(reader, &type);
1311 ok(hr == S_OK, "got %08x\n", hr);
1312 ok(type == XmlNodeType_EndElement, "got %d\n", type);
1313
1314 depth = 0;
1315 hr = IXmlReader_GetDepth(reader, &depth);
1316 ok(hr == S_OK, "got %08x\n", hr);
1317 todo_wine
1318 ok(depth == 2, "got %d\n", depth);
1319
1320 /* read end tag for container element */
1321 type = XmlNodeType_None;
1322 hr = IXmlReader_Read(reader, &type);
1323 ok(hr == S_OK, "got %08x\n", hr);
1324 ok(type == XmlNodeType_EndElement, "got %d\n", type);
1325
1326 depth = 0;
1327 hr = IXmlReader_GetDepth(reader, &depth);
1328 ok(hr == S_OK, "got %08x\n", hr);
1329 ok(depth == 1, "got %d\n", depth);
1330
1331 IStream_Release(stream);
1332
1333 /* start/end tag mismatch */
1334 stream = create_stream_on_data(mismatch, sizeof(mismatch));
1335 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1336 ok(hr == S_OK, "got %08x\n", hr);
1337
1338 type = XmlNodeType_None;
1339 hr = IXmlReader_Read(reader, &type);
1340 ok(hr == S_OK, "got %08x\n", hr);
1341 ok(type == XmlNodeType_Element, "got %d\n", type);
1342
1343 type = XmlNodeType_Element;
1344 hr = IXmlReader_Read(reader, &type);
1345 ok(hr == WC_E_ELEMENTMATCH, "got %08x\n", hr);
1346 todo_wine
1347 ok(type == XmlNodeType_None, "got %d\n", type);
1348
1349 IStream_Release(stream);
1350
1351 IXmlReader_Release(reader);
1352 }
1353
1354 static ISequentialStream teststream = { &teststreamvtbl };
1355
1356 static void test_read_pending(void)
1357 {
1358 IXmlReader *reader;
1359 const WCHAR *value;
1360 XmlNodeType type;
1361 HRESULT hr;
1362 int c;
1363
1364 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1365 ok(hr == S_OK, "S_OK, got 0x%08x\n", hr);
1366
1367 hr = IXmlReader_SetInput(reader, (IUnknown*)&teststream);
1368 ok(hr == S_OK, "got 0x%08x\n", hr);
1369
1370 /* first read call returns incomplete node, second attempt fails with E_PENDING */
1371 stream_readcall = 0;
1372 type = XmlNodeType_Element;
1373 hr = IXmlReader_Read(reader, &type);
1374 ok(hr == S_OK || broken(hr == E_PENDING), "got 0x%08x\n", hr);
1375 /* newer versions are happy when it's enough data to detect node type,
1376 older versions keep reading until it fails to read more */
1377 ok(stream_readcall == 1 || broken(stream_readcall > 1), "got %d\n", stream_readcall);
1378 ok(type == XmlNodeType_Comment || broken(type == XmlNodeType_None), "got %d\n", type);
1379
1380 /* newer versions' GetValue() makes an attempt to read more */
1381 c = stream_readcall;
1382 value = (void*)0xdeadbeef;
1383 hr = IXmlReader_GetValue(reader, &value, NULL);
1384 ok(hr == E_PENDING, "got 0x%08x\n", hr);
1385 ok(value == NULL || broken(value == (void*)0xdeadbeef) /* Win8 sets it to NULL */, "got %p\n", value);
1386 ok(c < stream_readcall || broken(c == stream_readcall), "got %d, expected %d\n", stream_readcall, c+1);
1387
1388 IXmlReader_Release(reader);
1389 }
1390
1391 static void test_readvaluechunk(void)
1392 {
1393 static const char testA[] = "<!-- comment1 -->";
1394 IXmlReader *reader;
1395 XmlNodeType type;
1396 IStream *stream;
1397 const WCHAR *value;
1398 WCHAR b;
1399 HRESULT hr;
1400 UINT c;
1401
1402 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1403 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1404
1405 stream = create_stream_on_data(testA, sizeof(testA));
1406 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1407 ok(hr == S_OK, "got %08x\n", hr);
1408
1409 hr = IXmlReader_Read(reader, &type);
1410 ok(hr == S_OK, "got %08x\n", hr);
1411
1412 c = 0;
1413 b = 0;
1414 hr = IXmlReader_ReadValueChunk(reader, &b, 1, &c);
1415 ok(hr == S_OK, "got %08x\n", hr);
1416 ok(c == 1, "got %u\n", c);
1417 ok(b == ' ', "got %x\n", b);
1418
1419 /* portion read as chunk is skipped from resulting node value */
1420 value = NULL;
1421 hr = IXmlReader_GetValue(reader, &value, NULL);
1422 ok(hr == S_OK, "got %08x\n", hr);
1423 ok(value[0] == 'c', "got %s\n", wine_dbgstr_w(value));
1424
1425 /* once value is returned/allocated it's not possible to read by chunk */
1426 c = 0;
1427 b = 0;
1428 hr = IXmlReader_ReadValueChunk(reader, &b, 1, &c);
1429 ok(hr == S_FALSE, "got %08x\n", hr);
1430 ok(c == 0, "got %u\n", c);
1431 ok(b == 0, "got %x\n", b);
1432
1433 value = NULL;
1434 hr = IXmlReader_GetValue(reader, &value, NULL);
1435 ok(hr == S_OK, "got %08x\n", hr);
1436 ok(value[0] == 'c', "got %s\n", wine_dbgstr_w(value));
1437
1438 IXmlReader_Release(reader);
1439 }
1440
1441 static struct test_entry cdata_tests[] = {
1442 { "<a><![CDATA[ ]]data ]]></a>", "", " ]]data ", S_OK },
1443 { "<a><![CDATA[<![CDATA[ data ]]]]></a>", "", "<![CDATA[ data ]]", S_OK },
1444 { "<a><![CDATA[\n \r\n \n\n ]]></a>", "", "\n \n \n\n ", S_OK, S_OK, TRUE },
1445 { "<a><![CDATA[\r \r\r\n \n\n ]]></a>", "", "\n \n\n \n\n ", S_OK, S_OK, TRUE },
1446 { "<a><![CDATA[\r\r \n\r \r \n\n ]]></a>", "", "\n\n \n\n \n \n\n ", S_OK },
1447 { NULL }
1448 };
1449
1450 static void test_read_cdata(void)
1451 {
1452 struct test_entry *test = cdata_tests;
1453 IXmlReader *reader;
1454 HRESULT hr;
1455
1456 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1457 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1458
1459 while (test->xml)
1460 {
1461 XmlNodeType type;
1462 IStream *stream;
1463
1464 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1465 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1466 ok(hr == S_OK, "got %08x\n", hr);
1467
1468 type = XmlNodeType_None;
1469 hr = IXmlReader_Read(reader, &type);
1470
1471 /* read one more to get to CDATA */
1472 if (type == XmlNodeType_Element)
1473 {
1474 type = XmlNodeType_None;
1475 hr = IXmlReader_Read(reader, &type);
1476 }
1477
1478 if (test->hr_broken)
1479 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1480 else
1481 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1482 if (hr == S_OK)
1483 {
1484 const WCHAR *str;
1485 WCHAR *str_exp;
1486 UINT len;
1487
1488 ok(type == XmlNodeType_CDATA, "got %d for %s\n", type, test->xml);
1489
1490 str_exp = a2w(test->name);
1491
1492 len = 1;
1493 str = NULL;
1494 hr = IXmlReader_GetLocalName(reader, &str, &len);
1495 ok(hr == S_OK, "got 0x%08x\n", hr);
1496 ok(len == strlen(test->name), "got %u\n", len);
1497 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1498
1499 str = NULL;
1500 hr = IXmlReader_GetLocalName(reader, &str, NULL);
1501 ok(hr == S_OK, "got 0x%08x\n", hr);
1502 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1503
1504 free_str(str_exp);
1505
1506 len = 1;
1507 str = NULL;
1508 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1509 ok(hr == S_OK, "got 0x%08x\n", hr);
1510 ok(len == strlen(test->name), "got %u\n", len);
1511 str_exp = a2w(test->name);
1512 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1513 free_str(str_exp);
1514
1515 /* value */
1516 len = 1;
1517 str = NULL;
1518 hr = IXmlReader_GetValue(reader, &str, &len);
1519 ok(hr == S_OK, "got 0x%08x\n", hr);
1520
1521 str_exp = a2w(test->value);
1522 if (test->todo)
1523 {
1524 todo_wine {
1525 ok(len == strlen(test->value), "got %u\n", len);
1526 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1527 }
1528 }
1529 else
1530 {
1531 ok(len == strlen(test->value), "got %u\n", len);
1532 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1533 }
1534 free_str(str_exp);
1535 }
1536
1537 IStream_Release(stream);
1538 test++;
1539 }
1540
1541 IXmlReader_Release(reader);
1542 }
1543
1544 static struct test_entry text_tests[] = {
1545 { "<a>simple text</a>", "", "simple text", S_OK },
1546 { "<a>text ]]> text</a>", "", "", WC_E_CDSECTEND },
1547 { NULL }
1548 };
1549
1550 static void test_read_text(void)
1551 {
1552 struct test_entry *test = text_tests;
1553 IXmlReader *reader;
1554 HRESULT hr;
1555
1556 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1557 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1558
1559 while (test->xml)
1560 {
1561 XmlNodeType type;
1562 IStream *stream;
1563
1564 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1565 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1566 ok(hr == S_OK, "got %08x\n", hr);
1567
1568 type = XmlNodeType_None;
1569 hr = IXmlReader_Read(reader, &type);
1570
1571 /* read one more to get to CDATA */
1572 if (type == XmlNodeType_Element)
1573 {
1574 type = XmlNodeType_None;
1575 hr = IXmlReader_Read(reader, &type);
1576 }
1577
1578 if (test->hr_broken)
1579 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1580 else
1581 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1582 if (hr == S_OK)
1583 {
1584 const WCHAR *str;
1585 WCHAR *str_exp;
1586 UINT len;
1587
1588 ok(type == XmlNodeType_Text, "got %d for %s\n", type, test->xml);
1589
1590 str_exp = a2w(test->name);
1591
1592 len = 1;
1593 str = NULL;
1594 hr = IXmlReader_GetLocalName(reader, &str, &len);
1595 ok(hr == S_OK, "got 0x%08x\n", hr);
1596 ok(len == strlen(test->name), "got %u\n", len);
1597 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1598
1599 str = NULL;
1600 hr = IXmlReader_GetLocalName(reader, &str, NULL);
1601 ok(hr == S_OK, "got 0x%08x\n", hr);
1602 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1603
1604 free_str(str_exp);
1605
1606 len = 1;
1607 str = NULL;
1608 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1609 ok(hr == S_OK, "got 0x%08x\n", hr);
1610 ok(len == strlen(test->name), "got %u\n", len);
1611 str_exp = a2w(test->name);
1612 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1613 free_str(str_exp);
1614
1615 /* value */
1616 len = 1;
1617 str = NULL;
1618 hr = IXmlReader_GetValue(reader, &str, &len);
1619 ok(hr == S_OK, "got 0x%08x\n", hr);
1620
1621 str_exp = a2w(test->value);
1622 if (test->todo)
1623 {
1624 todo_wine {
1625 ok(len == strlen(test->value), "got %u\n", len);
1626 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1627 }
1628 }
1629 else
1630 {
1631 ok(len == strlen(test->value), "got %u\n", len);
1632 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1633 }
1634 free_str(str_exp);
1635 }
1636
1637 IStream_Release(stream);
1638 test++;
1639 }
1640
1641 IXmlReader_Release(reader);
1642 }
1643
1644 struct test_entry_empty {
1645 const char *xml;
1646 BOOL empty;
1647 };
1648
1649 static struct test_entry_empty empty_element_tests[] = {
1650 { "<a></a>", FALSE },
1651 { "<a/>", TRUE },
1652 { NULL }
1653 };
1654
1655 static void test_isemptyelement(void)
1656 {
1657 struct test_entry_empty *test = empty_element_tests;
1658 IXmlReader *reader;
1659 HRESULT hr;
1660
1661 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1662 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1663
1664 while (test->xml)
1665 {
1666 XmlNodeType type;
1667 IStream *stream;
1668 BOOL ret;
1669
1670 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1671 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1672 ok(hr == S_OK, "got %08x\n", hr);
1673
1674 type = XmlNodeType_None;
1675 hr = IXmlReader_Read(reader, &type);
1676 ok(hr == S_OK, "got 0x%08x\n", hr);
1677 ok(type == XmlNodeType_Element, "got %d\n", type);
1678
1679 ret = IXmlReader_IsEmptyElement(reader);
1680 ok(ret == test->empty, "got %d, expected %d. xml=%s\n", ret, test->empty, test->xml);
1681
1682 IStream_Release(stream);
1683 test++;
1684 }
1685
1686 IXmlReader_Release(reader);
1687 }
1688
1689 static struct test_entry attributes_tests[] = {
1690 { "<a attr1=\"attrvalue\"/>", "attr1", "attrvalue", S_OK },
1691 { "<a attr1=\"a\'\'ttrvalue\"/>", "attr1", "a\'\'ttrvalue", S_OK },
1692 { "<a attr1=\'a\"ttrvalue\'/>", "attr1", "a\"ttrvalue", S_OK },
1693 { "<a attr1=\' \'/>", "attr1", " ", S_OK },
1694 { "<a attr1=\" \"/>", "attr1", " ", S_OK },
1695 { "<a attr1=\"\r\n \r \n \t\n\r\"/>", "attr1", " ", S_OK },
1696 { "<a attr1=\" val \"/>", "attr1", " val ", S_OK },
1697 { "<a attr1=\"\r\n\tval\n\"/>", "attr1", " val ", S_OK },
1698 { "<a attr1=\"val&#32;\"/>", "attr1", "val ", S_OK },
1699 { "<a attr1=\"val&#x20;\"/>", "attr1", "val ", S_OK },
1700 { "<a attr1=\"&lt;&gt;&amp;&apos;&quot;\"/>", "attr1", "<>&\'\"", S_OK },
1701 { "<a attr1=\"&entname;\"/>", NULL, NULL, WC_E_UNDECLAREDENTITY },
1702 { "<a attr1=\"val&#xfffe;\"/>", NULL, NULL, WC_E_XMLCHARACTER },
1703 { "<a attr1=\"val &#a;\"/>", NULL, NULL, WC_E_DIGIT, WC_E_SEMICOLON },
1704 { "<a attr1=\"val &#12a;\"/>", NULL, NULL, WC_E_SEMICOLON },
1705 { "<a attr1=\"val &#x12g;\"/>", NULL, NULL, WC_E_SEMICOLON },
1706 { "<a attr1=\"val &#xg;\"/>", NULL, NULL, WC_E_HEXDIGIT, WC_E_SEMICOLON },
1707 { "<a attr1=attrvalue/>", NULL, NULL, WC_E_QUOTE },
1708 { "<a attr1=\"attr<value\"/>", NULL, NULL, WC_E_LESSTHAN },
1709 { "<a attr1=\"&entname\"/>", NULL, NULL, WC_E_SEMICOLON },
1710 { NULL }
1711 };
1712
1713 static void test_read_attribute(void)
1714 {
1715 struct test_entry *test = attributes_tests;
1716 IXmlReader *reader;
1717 HRESULT hr;
1718
1719 hr = pCreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
1720 ok(hr == S_OK, "S_OK, got %08x\n", hr);
1721
1722 while (test->xml)
1723 {
1724 XmlNodeType type;
1725 IStream *stream;
1726
1727 stream = create_stream_on_data(test->xml, strlen(test->xml)+1);
1728 hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
1729 ok(hr == S_OK, "got %08x\n", hr);
1730
1731 type = XmlNodeType_None;
1732 hr = IXmlReader_Read(reader, &type);
1733
1734 if (test->hr_broken)
1735 ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
1736 else
1737 ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
1738 if (hr == S_OK)
1739 {
1740 const WCHAR *str;
1741 WCHAR *str_exp;
1742 UINT len;
1743
1744 ok(type == XmlNodeType_Element, "got %d for %s\n", type, test->xml);
1745
1746 hr = IXmlReader_MoveToFirstAttribute(reader);
1747 ok(hr == S_OK, "got 0x%08x\n", hr);
1748
1749 len = 1;
1750 str = NULL;
1751 hr = IXmlReader_GetLocalName(reader, &str, &len);
1752 ok(hr == S_OK, "got 0x%08x\n", hr);
1753 ok(len == strlen(test->name), "got %u\n", len);
1754 str_exp = a2w(test->name);
1755 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1756 free_str(str_exp);
1757
1758 len = 1;
1759 str = NULL;
1760 hr = IXmlReader_GetQualifiedName(reader, &str, &len);
1761 ok(hr == S_OK, "got 0x%08x\n", hr);
1762 todo_wine {
1763 ok(len == strlen(test->name), "got %u\n", len);
1764 str_exp = a2w(test->name);
1765 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1766 free_str(str_exp);
1767 }
1768 /* value */
1769 len = 1;
1770 str = NULL;
1771 hr = IXmlReader_GetValue(reader, &str, &len);
1772 ok(hr == S_OK, "got 0x%08x\n", hr);
1773 ok(len == strlen(test->value), "got %u\n", len);
1774 str_exp = a2w(test->value);
1775 ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
1776 free_str(str_exp);
1777 }
1778
1779 IStream_Release(stream);
1780 test++;
1781 }
1782
1783 IXmlReader_Release(reader);
1784 }
1785
1786 START_TEST(reader)
1787 {
1788 if (!init_pointers())
1789 return;
1790
1791 test_reader_create();
1792 test_readerinput();
1793 test_reader_state();
1794 test_read_attribute();
1795 test_read_cdata();
1796 test_read_comment();
1797 test_read_pi();
1798 test_read_dtd();
1799 test_read_element();
1800 test_isemptyelement();
1801 test_read_text();
1802 test_read_full();
1803 test_read_pending();
1804 test_readvaluechunk();
1805 test_read_xmldeclaration();
1806 }