2010-01-18 22:05:53 +01:00
|
|
|
/*
|
2013-01-05 23:08:27 +01:00
|
|
|
* IXmlReader tests
|
2010-01-18 22:05:53 +01:00
|
|
|
*
|
2017-03-07 04:50:59 +01:00
|
|
|
* Copyright 2010, 2012-2013, 2016-2017 Nikolay Sivov
|
2010-01-18 22:05:53 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
2010-12-29 02:53:57 +01:00
|
|
|
#define CONST_VTABLE
|
2010-01-18 22:05:53 +01:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2010-01-21 15:47:03 +01:00
|
|
|
#include <stdio.h>
|
2010-01-18 22:05:53 +01:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2010-01-21 15:47:03 +01:00
|
|
|
#include "initguid.h"
|
2010-01-18 22:05:53 +01:00
|
|
|
#include "ole2.h"
|
|
|
|
#include "xmllite.h"
|
|
|
|
#include "wine/test.h"
|
2018-02-08 12:17:02 +01:00
|
|
|
#include "wine/heap.h"
|
2010-01-18 22:05:53 +01:00
|
|
|
|
2010-01-21 15:47:03 +01:00
|
|
|
DEFINE_GUID(IID_IXmlReaderInput, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda);
|
2010-01-18 22:05:53 +01:00
|
|
|
|
2012-11-25 06:10:46 +01:00
|
|
|
static const char xmldecl_full[] = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
2014-02-20 11:28:09 +01:00
|
|
|
static const char xmldecl_short[] = "<?xml version=\"1.0\"?><RegistrationInfo/>";
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-06 10:35:55 +01:00
|
|
|
static IStream *create_stream_on_data(const void *data, unsigned int size)
|
2010-01-25 19:55:02 +01:00
|
|
|
{
|
|
|
|
IStream *stream = NULL;
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
void *ptr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hglobal = GlobalAlloc(GHND, size);
|
|
|
|
ptr = GlobalLock(hglobal);
|
|
|
|
|
|
|
|
memcpy(ptr, data, size);
|
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(hglobal, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(stream != NULL, "Expected non-NULL stream\n");
|
|
|
|
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
static void test_reader_pos(IXmlReader *reader, UINT line, UINT pos, UINT line_broken,
|
|
|
|
UINT pos_broken, int _line_)
|
2010-01-25 19:55:02 +01:00
|
|
|
{
|
2017-03-09 05:14:07 +01:00
|
|
|
UINT l = ~0u, p = ~0u;
|
2014-01-07 00:14:38 +01:00
|
|
|
BOOL broken_state;
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
IXmlReader_GetLineNumber(reader, &l);
|
|
|
|
IXmlReader_GetLinePosition(reader, &p);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
if (line_broken == ~0u && pos_broken == ~0u)
|
2014-01-07 00:14:38 +01:00
|
|
|
broken_state = FALSE;
|
2010-01-25 21:52:09 +01:00
|
|
|
else
|
2017-03-09 05:14:07 +01:00
|
|
|
broken_state = broken((line_broken == ~0u ? line : line_broken) == l &&
|
|
|
|
(pos_broken == ~0u ? pos : pos_broken) == p);
|
2010-01-25 21:52:09 +01:00
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
ok_(__FILE__, _line_)((l == line && pos == p) || broken_state,
|
|
|
|
"Expected (%d,%d), got (%d,%d)\n", line, pos, l, p);
|
2010-01-25 19:55:02 +01:00
|
|
|
}
|
2017-03-09 05:14:07 +01:00
|
|
|
#define TEST_READER_POSITION(reader, line, pos) \
|
|
|
|
test_reader_pos(reader, line, pos, ~0u, ~0u, __LINE__)
|
|
|
|
#define TEST_READER_POSITION2(reader, line, pos, line_broken, pos_broken) \
|
|
|
|
test_reader_pos(reader, line, pos, line_broken, pos_broken, __LINE__)
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2010-01-21 15:47:03 +01:00
|
|
|
typedef struct input_iids_t {
|
|
|
|
IID iids[10];
|
|
|
|
int count;
|
|
|
|
} input_iids_t;
|
|
|
|
|
|
|
|
static const IID *setinput_full[] = {
|
|
|
|
&IID_IXmlReaderInput,
|
2010-01-23 17:05:50 +01:00
|
|
|
&IID_IStream,
|
2010-01-21 15:47:03 +01:00
|
|
|
&IID_ISequentialStream,
|
2010-01-23 17:05:50 +01:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* this applies to early xmllite versions */
|
|
|
|
static const IID *setinput_full_old[] = {
|
|
|
|
&IID_IXmlReaderInput,
|
|
|
|
&IID_ISequentialStream,
|
|
|
|
&IID_IStream,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* after ::SetInput(IXmlReaderInput*) */
|
|
|
|
static const IID *setinput_readerinput[] = {
|
|
|
|
&IID_IStream,
|
|
|
|
&IID_ISequentialStream,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const IID *empty_seq[] = {
|
|
|
|
NULL
|
2010-01-21 15:47:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static input_iids_t input_iids;
|
|
|
|
|
2014-01-07 00:14:38 +01:00
|
|
|
static void ok_iids_(const input_iids_t *iids, const IID **expected, const IID **exp_broken, BOOL todo, int line)
|
2010-01-21 15:47:03 +01:00
|
|
|
{
|
2010-01-23 17:05:50 +01:00
|
|
|
int i = 0, size = 0;
|
|
|
|
|
|
|
|
while (expected[i++]) size++;
|
2010-01-21 15:47:03 +01:00
|
|
|
|
2016-02-15 15:39:58 +01:00
|
|
|
todo_wine_if (todo)
|
|
|
|
ok_(__FILE__, line)(iids->count == size, "Sequence size mismatch (%d), got (%d)\n", size, iids->count);
|
2010-01-21 15:47:03 +01:00
|
|
|
|
|
|
|
if (iids->count != size) return;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
2010-01-23 17:05:50 +01:00
|
|
|
ok_(__FILE__, line)(IsEqualGUID(&iids->iids[i], expected[i]) ||
|
|
|
|
(exp_broken ? broken(IsEqualGUID(&iids->iids[i], exp_broken[i])) : FALSE),
|
2014-01-25 15:24:49 +01:00
|
|
|
"Wrong IID(%d), got %s\n", i, wine_dbgstr_guid(&iids->iids[i]));
|
2010-01-21 15:47:03 +01:00
|
|
|
}
|
|
|
|
}
|
2010-01-23 17:05:50 +01:00
|
|
|
#define ok_iids(got, exp, brk, todo) ok_iids_(got, exp, brk, todo, __LINE__)
|
2010-01-21 15:47:03 +01:00
|
|
|
|
2010-01-23 21:03:14 +01:00
|
|
|
static const char *state_to_str(XmlReadState state)
|
|
|
|
{
|
|
|
|
static const char* state_names[] = {
|
|
|
|
"XmlReadState_Initial",
|
|
|
|
"XmlReadState_Interactive",
|
|
|
|
"XmlReadState_Error",
|
|
|
|
"XmlReadState_EndOfFile",
|
|
|
|
"XmlReadState_Closed"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char unknown[] = "unknown";
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case XmlReadState_Initial:
|
|
|
|
case XmlReadState_Interactive:
|
|
|
|
case XmlReadState_Error:
|
|
|
|
case XmlReadState_EndOfFile:
|
|
|
|
case XmlReadState_Closed:
|
|
|
|
return state_names[state];
|
|
|
|
default:
|
|
|
|
return unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-25 19:55:02 +01:00
|
|
|
static const char *type_to_str(XmlNodeType type)
|
|
|
|
{
|
|
|
|
static const char* type_names[] = {
|
|
|
|
"XmlNodeType_None",
|
|
|
|
"XmlNodeType_Element",
|
|
|
|
"XmlNodeType_Attribute",
|
|
|
|
"XmlNodeType_Text",
|
|
|
|
"XmlNodeType_CDATA",
|
2010-01-27 11:49:18 +01:00
|
|
|
"", "",
|
2010-01-25 19:55:02 +01:00
|
|
|
"XmlNodeType_ProcessingInstruction",
|
|
|
|
"XmlNodeType_Comment",
|
2010-01-27 11:49:18 +01:00
|
|
|
"",
|
2010-01-25 19:55:02 +01:00
|
|
|
"XmlNodeType_DocumentType",
|
2010-01-27 11:49:18 +01:00
|
|
|
"", "",
|
2010-01-25 19:55:02 +01:00
|
|
|
"XmlNodeType_Whitespace",
|
2010-01-27 11:49:18 +01:00
|
|
|
"",
|
2010-01-25 19:55:02 +01:00
|
|
|
"XmlNodeType_EndElement",
|
2010-01-27 11:49:18 +01:00
|
|
|
"",
|
2010-01-25 19:55:02 +01:00
|
|
|
"XmlNodeType_XmlDeclaration"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char unknown[] = "unknown";
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case XmlNodeType_None:
|
|
|
|
case XmlNodeType_Element:
|
|
|
|
case XmlNodeType_Attribute:
|
|
|
|
case XmlNodeType_Text:
|
|
|
|
case XmlNodeType_CDATA:
|
|
|
|
case XmlNodeType_ProcessingInstruction:
|
|
|
|
case XmlNodeType_Comment:
|
|
|
|
case XmlNodeType_DocumentType:
|
|
|
|
case XmlNodeType_Whitespace:
|
|
|
|
case XmlNodeType_EndElement:
|
|
|
|
case XmlNodeType_XmlDeclaration:
|
|
|
|
return type_names[type];
|
|
|
|
default:
|
|
|
|
return unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
#define set_input_string(a,b) _set_input_string(__LINE__,a,b);
|
|
|
|
static void _set_input_string(unsigned line, IXmlReader *reader, const char *xml)
|
|
|
|
{
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
stream = create_stream_on_data(xml, strlen(xml));
|
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, (IUnknown *)stream);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:45:25 +02:00
|
|
|
#define read_node(a,b) _read_node(__LINE__,a,b)
|
|
|
|
static void _read_node(unsigned line, IXmlReader *reader, XmlNodeType expected_type)
|
|
|
|
{
|
|
|
|
XmlNodeType type;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
if (expected_type == XmlNodeType_None)
|
|
|
|
ok_(__FILE__,line)(hr == S_FALSE, "Read returned %08x, expected S_FALSE\n", hr);
|
|
|
|
else
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "Read returned %08x\n", hr);
|
|
|
|
ok_(__FILE__,line)(type == expected_type, "read type %d, expected %d\n", type, expected_type);
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:45:32 +02:00
|
|
|
#define next_attribute(a) _next_attribute(__LINE__,a)
|
|
|
|
static void _next_attribute(unsigned line, IXmlReader *reader)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
hr = IXmlReader_MoveToNextAttribute(reader);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "MoveToNextAttribute returned %08x\n", hr);
|
|
|
|
}
|
|
|
|
|
2017-03-31 15:57:27 +02:00
|
|
|
#define move_to_element(a) _move_to_element(__LINE__,a)
|
|
|
|
static void _move_to_element(unsigned line, IXmlReader *reader)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
hr = IXmlReader_MoveToElement(reader);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "MoveToElement failed: %08x\n", hr);
|
|
|
|
}
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
static void test_read_state(IXmlReader *reader, XmlReadState expected,
|
|
|
|
XmlReadState exp_broken, int line)
|
2010-01-23 21:03:14 +01:00
|
|
|
{
|
2014-01-07 00:14:38 +01:00
|
|
|
BOOL broken_state;
|
2017-03-07 04:50:59 +01:00
|
|
|
LONG_PTR state;
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
state = -1; /* invalid state value */
|
|
|
|
IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, &state);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2017-11-05 09:39:53 +01:00
|
|
|
if (exp_broken == expected)
|
2014-01-07 00:14:38 +01:00
|
|
|
broken_state = FALSE;
|
2010-01-25 21:52:09 +01:00
|
|
|
else
|
|
|
|
broken_state = broken(exp_broken == state);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
ok_(__FILE__, line)(state == expected || broken_state, "Expected (%s), got (%s)\n",
|
|
|
|
state_to_str(expected), state_to_str(state));
|
2010-01-23 21:03:14 +01:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:39:53 +01:00
|
|
|
#define TEST_READER_STATE(reader, state) test_read_state(reader, state, state, __LINE__)
|
2017-03-07 04:50:59 +01:00
|
|
|
#define TEST_READER_STATE2(reader, state, brk) test_read_state(reader, state, brk, __LINE__)
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2017-03-29 19:45:50 +02:00
|
|
|
#define reader_value(a,b) _reader_value(__LINE__,a,b)
|
2020-02-07 15:52:19 +01:00
|
|
|
static const WCHAR *_reader_value(unsigned line, IXmlReader *reader, const WCHAR *expect)
|
2017-03-29 19:45:50 +02:00
|
|
|
{
|
|
|
|
const WCHAR *str = (void*)0xdeadbeef;
|
|
|
|
ULONG len = 0xdeadbeef;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_GetValue(reader, &str, &len);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "GetValue returned %08x\n", hr);
|
|
|
|
ok_(__FILE__,line)(len == lstrlenW(str), "len = %u\n", len);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok_(__FILE__,line)(!lstrcmpW(str, expect), "value = %s\n", wine_dbgstr_w(str));
|
2017-03-29 19:45:50 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:46:02 +02:00
|
|
|
#define reader_name(a,b) _reader_name(__LINE__,a,b)
|
2020-02-07 15:52:19 +01:00
|
|
|
static const WCHAR *_reader_name(unsigned line, IXmlReader *reader, const WCHAR *expect)
|
2017-03-29 19:46:02 +02:00
|
|
|
{
|
|
|
|
const WCHAR *str = (void*)0xdeadbeef;
|
|
|
|
ULONG len = 0xdeadbeef;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_GetLocalName(reader, &str, &len);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "GetLocalName returned %08x\n", hr);
|
|
|
|
ok_(__FILE__,line)(len == lstrlenW(str), "len = %u\n", len);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok_(__FILE__,line)(!lstrcmpW(str, expect), "name = %s\n", wine_dbgstr_w(str));
|
2017-03-29 19:46:02 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:46:19 +02:00
|
|
|
#define reader_prefix(a,b) _reader_prefix(__LINE__,a,b)
|
2020-02-07 15:52:19 +01:00
|
|
|
static const WCHAR *_reader_prefix(unsigned line, IXmlReader *reader, const WCHAR *expect)
|
2017-03-29 19:46:19 +02:00
|
|
|
{
|
|
|
|
const WCHAR *str = (void*)0xdeadbeef;
|
|
|
|
ULONG len = 0xdeadbeef;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_GetPrefix(reader, &str, &len);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "GetPrefix returned %08x\n", hr);
|
|
|
|
ok_(__FILE__,line)(len == lstrlenW(str), "len = %u\n", len);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok_(__FILE__,line)(!lstrcmpW(str, expect), "prefix = %s\n", wine_dbgstr_w(str));
|
2017-03-29 19:46:19 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:46:28 +02:00
|
|
|
#define reader_namespace(a,b) _reader_namespace(__LINE__,a,b)
|
2020-02-07 15:52:19 +01:00
|
|
|
static const WCHAR *_reader_namespace(unsigned line, IXmlReader *reader, const WCHAR *expect)
|
2017-03-29 19:46:28 +02:00
|
|
|
{
|
|
|
|
const WCHAR *str = (void*)0xdeadbeef;
|
|
|
|
ULONG len = 0xdeadbeef;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_GetNamespaceUri(reader, &str, &len);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "GetNamespaceUri returned %08x\n", hr);
|
|
|
|
ok_(__FILE__,line)(len == lstrlenW(str), "len = %u\n", len);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok_(__FILE__,line)(!lstrcmpW(str, expect), "namespace = %s\n", wine_dbgstr_w(str));
|
2017-03-29 19:46:28 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:46:38 +02:00
|
|
|
#define reader_qname(a,b) _reader_qname(a,b,__LINE__)
|
2020-02-07 15:52:19 +01:00
|
|
|
static const WCHAR *_reader_qname(IXmlReader *reader, const WCHAR *expect, unsigned line)
|
2017-03-29 19:46:38 +02:00
|
|
|
{
|
|
|
|
const WCHAR *str = (void*)0xdeadbeef;
|
|
|
|
ULONG len = 0xdeadbeef;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "GetQualifiedName returned %08x\n", hr);
|
|
|
|
ok_(__FILE__,line)(len == lstrlenW(str), "len = %u\n", len);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok_(__FILE__,line)(!lstrcmpW(str, expect), "name = %s\n", wine_dbgstr_w(str));
|
2017-03-29 19:46:38 +02:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-03-29 19:46:48 +02:00
|
|
|
#define read_value_char(a,b) _read_value_char(a,b,__LINE__)
|
|
|
|
static void _read_value_char(IXmlReader *reader, WCHAR expected_char, unsigned line)
|
|
|
|
{
|
|
|
|
WCHAR c = 0xffff;
|
|
|
|
UINT count = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IXmlReader_ReadValueChunk(reader, &c, 1, &count);
|
|
|
|
ok_(__FILE__,line)(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok_(__FILE__,line)(count == 1, "got %u\n", c);
|
|
|
|
ok_(__FILE__,line)(c == expected_char, "got %x\n", c);
|
|
|
|
}
|
|
|
|
|
2010-01-21 15:47:03 +01:00
|
|
|
typedef struct _testinput
|
|
|
|
{
|
2010-12-29 02:53:57 +01:00
|
|
|
IUnknown IUnknown_iface;
|
2010-01-21 15:47:03 +01:00
|
|
|
LONG ref;
|
|
|
|
} testinput;
|
|
|
|
|
|
|
|
static inline testinput *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
2010-12-29 02:53:57 +01:00
|
|
|
return CONTAINING_RECORD(iface, testinput, IUnknown_iface);
|
2010-01-21 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI testinput_QueryInterface(IUnknown *iface, REFIID riid, void** ppvObj)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID( riid, &IID_IUnknown ))
|
|
|
|
{
|
|
|
|
*ppvObj = iface;
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_iids.iids[input_iids.count++] = *riid;
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI testinput_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
testinput *This = impl_from_IUnknown(iface);
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI testinput_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
testinput *This = impl_from_IUnknown(iface);
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0)
|
2018-02-08 12:17:02 +01:00
|
|
|
heap_free(This);
|
2010-01-21 15:47:03 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IUnknownVtbl testinput_vtbl =
|
|
|
|
{
|
|
|
|
testinput_QueryInterface,
|
|
|
|
testinput_AddRef,
|
|
|
|
testinput_Release
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT testinput_createinstance(void **ppObj)
|
|
|
|
{
|
|
|
|
testinput *input;
|
|
|
|
|
2018-02-08 12:17:02 +01:00
|
|
|
input = heap_alloc(sizeof(*input));
|
2010-01-21 15:47:03 +01:00
|
|
|
if(!input) return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-29 02:53:57 +01:00
|
|
|
input->IUnknown_iface.lpVtbl = &testinput_vtbl;
|
2010-01-21 15:47:03 +01:00
|
|
|
input->ref = 1;
|
|
|
|
|
2010-12-29 02:53:57 +01:00
|
|
|
*ppObj = &input->IUnknown_iface;
|
2010-01-21 15:47:03 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2010-01-18 22:05:53 +01:00
|
|
|
|
2013-01-27 08:17:27 +01:00
|
|
|
static HRESULT WINAPI teststream_QueryInterface(ISequentialStream *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ISequentialStream))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI teststream_AddRef(ISequentialStream *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI teststream_Release(ISequentialStream *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stream_readcall;
|
|
|
|
|
|
|
|
static HRESULT WINAPI teststream_Read(ISequentialStream *iface, void *pv, ULONG cb, ULONG *pread)
|
|
|
|
{
|
|
|
|
static const char xml[] = "<!-- comment -->";
|
|
|
|
|
|
|
|
if (stream_readcall++)
|
|
|
|
{
|
|
|
|
*pread = 0;
|
|
|
|
return E_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pread = sizeof(xml) / 2;
|
|
|
|
memcpy(pv, xml, *pread);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI teststream_Write(ISequentialStream *iface, const void *pv, ULONG cb, ULONG *written)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ISequentialStreamVtbl teststreamvtbl =
|
|
|
|
{
|
|
|
|
teststream_QueryInterface,
|
|
|
|
teststream_AddRef,
|
|
|
|
teststream_Release,
|
|
|
|
teststream_Read,
|
|
|
|
teststream_Write
|
|
|
|
};
|
|
|
|
|
2016-03-14 07:37:46 +01:00
|
|
|
static HRESULT WINAPI resolver_QI(IXmlResolver *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call, riid %s\n", wine_dbgstr_guid(riid));
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IXmlResolver) || IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IXmlResolver_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI resolver_AddRef(IXmlResolver *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI resolver_Release(IXmlResolver *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI resolver_ResolveUri(IXmlResolver *iface, const WCHAR *base_uri,
|
|
|
|
const WCHAR *public_id, const WCHAR *system_id, IUnknown **input)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IXmlResolverVtbl resolvervtbl =
|
|
|
|
{
|
|
|
|
resolver_QI,
|
|
|
|
resolver_AddRef,
|
|
|
|
resolver_Release,
|
|
|
|
resolver_ResolveUri
|
|
|
|
};
|
|
|
|
|
|
|
|
static IXmlResolver testresolver = { &resolvervtbl };
|
|
|
|
|
2010-01-18 22:05:53 +01:00
|
|
|
static void test_reader_create(void)
|
|
|
|
{
|
2016-03-14 07:37:46 +01:00
|
|
|
IXmlResolver *resolver;
|
2017-04-11 13:28:40 +02:00
|
|
|
IUnknown *input, *unk;
|
2010-01-18 22:05:53 +01:00
|
|
|
IXmlReader *reader;
|
2012-08-29 06:12:01 +02:00
|
|
|
DtdProcessing dtd;
|
2012-11-19 01:00:24 +01:00
|
|
|
XmlNodeType nodetype;
|
2017-04-11 13:28:40 +02:00
|
|
|
HRESULT hr;
|
2010-01-18 22:05:53 +01:00
|
|
|
|
|
|
|
/* crashes native */
|
|
|
|
if (0)
|
|
|
|
{
|
2016-03-22 08:10:37 +01:00
|
|
|
CreateXmlReader(&IID_IXmlReader, NULL, NULL);
|
|
|
|
CreateXmlReader(NULL, (void**)&reader, NULL);
|
2010-01-18 22:05:53 +01:00
|
|
|
}
|
|
|
|
|
2017-04-11 13:28:40 +02:00
|
|
|
hr = CreateXmlReader(&IID_IStream, (void **)&unk, NULL);
|
|
|
|
ok(hr == E_NOINTERFACE, "got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IUnknown, (void **)&unk, NULL);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IXmlReader, (void **)&reader);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(unk == (IUnknown *)reader, "unexpected interface\n");
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IUnknown, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2010-01-18 22:18:22 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2010-01-18 22:05:53 +01:00
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Closed);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2012-11-19 01:00:24 +01:00
|
|
|
nodetype = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &nodetype);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
ok(nodetype == XmlNodeType_None, "got %d\n", nodetype);
|
|
|
|
|
2017-01-27 09:17:41 +01:00
|
|
|
/* crashes on XP, 2k3, works on newer versions */
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
hr = IXmlReader_GetNodeType(reader, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "got %08x\n", hr);
|
|
|
|
}
|
|
|
|
|
2016-03-14 07:37:46 +01:00
|
|
|
resolver = (void*)0xdeadbeef;
|
|
|
|
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_XmlResolver, (LONG_PTR*)&resolver);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(resolver == NULL, "got %p\n", resolver);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_XmlResolver, 0);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_XmlResolver, (LONG_PTR)&testresolver);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
resolver = NULL;
|
|
|
|
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_XmlResolver, (LONG_PTR*)&resolver);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(resolver == &testresolver, "got %p\n", resolver);
|
|
|
|
IXmlResolver_Release(resolver);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_XmlResolver, 0);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2012-08-29 06:12:01 +02:00
|
|
|
dtd = 2;
|
|
|
|
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_DtdProcessing, (LONG_PTR*)&dtd);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok(dtd == DtdProcessing_Prohibit, "got %d\n", dtd);
|
|
|
|
|
|
|
|
dtd = 2;
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, dtd);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, -1);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
2010-01-21 19:05:25 +01:00
|
|
|
/* Null input pointer, releases previous input */
|
|
|
|
hr = IXmlReader_SetInput(reader, NULL);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE2(reader, XmlReadState_Initial, XmlReadState_Closed);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2010-01-21 15:47:03 +01:00
|
|
|
/* test input interface selection sequence */
|
|
|
|
hr = testinput_createinstance((void**)&input);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2010-12-29 02:53:57 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
input_iids.count = 0;
|
|
|
|
hr = IXmlReader_SetInput(reader, input);
|
|
|
|
ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
|
|
|
|
ok_iids(&input_iids, setinput_full, setinput_full_old, FALSE);
|
|
|
|
IUnknown_Release(input);
|
|
|
|
}
|
2010-01-18 22:05:53 +01:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2010-01-21 15:47:03 +01:00
|
|
|
static void test_readerinput(void)
|
|
|
|
{
|
|
|
|
IXmlReaderInput *reader_input;
|
2010-01-23 17:05:50 +01:00
|
|
|
IXmlReader *reader, *reader2;
|
|
|
|
IUnknown *obj, *input;
|
2012-11-17 19:54:16 +01:00
|
|
|
IStream *stream, *stream2;
|
2012-11-19 01:00:24 +01:00
|
|
|
XmlNodeType nodetype;
|
2010-01-21 15:47:03 +01:00
|
|
|
HRESULT hr;
|
|
|
|
LONG ref;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, NULL);
|
2010-01-21 16:19:20 +01:00
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReaderInputWithEncodingName(NULL, NULL, NULL, FALSE, NULL, &reader_input);
|
2010-01-21 16:19:20 +01:00
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
2010-01-21 15:47:03 +01:00
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
ref = IStream_AddRef(stream);
|
|
|
|
ok(ref == 2, "Expected 2, got %d\n", ref);
|
|
|
|
IStream_Release(stream);
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReaderInputWithEncodingName((IUnknown*)stream, NULL, NULL, FALSE, NULL, &reader_input);
|
2010-01-21 16:19:20 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2012-11-17 19:54:16 +01:00
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(reader_input, &IID_IStream, (void**)&stream2);
|
|
|
|
ok(hr == E_NOINTERFACE, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(reader_input, &IID_ISequentialStream, (void**)&stream2);
|
|
|
|
ok(hr == E_NOINTERFACE, "Expected S_OK, got %08x\n", hr);
|
2010-01-21 15:47:03 +01:00
|
|
|
|
2010-01-23 17:05:50 +01:00
|
|
|
/* IXmlReaderInput grabs a stream reference */
|
2010-01-21 15:47:03 +01:00
|
|
|
ref = IStream_AddRef(stream);
|
2010-01-23 17:05:50 +01:00
|
|
|
ok(ref == 3, "Expected 3, got %d\n", ref);
|
2010-01-21 15:47:03 +01:00
|
|
|
IStream_Release(stream);
|
|
|
|
|
2010-01-23 17:05:50 +01:00
|
|
|
/* try ::SetInput() with valid IXmlReaderInput */
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2010-01-23 17:05:50 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
ref = IUnknown_AddRef(reader_input);
|
|
|
|
ok(ref == 2, "Expected 2, got %d\n", ref);
|
|
|
|
IUnknown_Release(reader_input);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, reader_input);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Initial);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2012-11-19 01:00:24 +01:00
|
|
|
nodetype = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &nodetype);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(nodetype == XmlNodeType_None, "got %d\n", nodetype);
|
|
|
|
|
2010-01-23 17:05:50 +01:00
|
|
|
/* IXmlReader grabs a IXmlReaderInput reference */
|
|
|
|
ref = IUnknown_AddRef(reader_input);
|
|
|
|
ok(ref == 3, "Expected 3, got %d\n", ref);
|
|
|
|
IUnknown_Release(reader_input);
|
|
|
|
|
|
|
|
ref = IStream_AddRef(stream);
|
|
|
|
ok(ref == 4, "Expected 4, got %d\n", ref);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
2010-01-23 21:03:14 +01:00
|
|
|
/* reset input and check state */
|
|
|
|
hr = IXmlReader_SetInput(reader, NULL);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE2(reader, XmlReadState_Initial, XmlReadState_Closed);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2010-01-23 17:05:50 +01:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
|
|
|
|
ref = IStream_AddRef(stream);
|
|
|
|
ok(ref == 3, "Expected 3, got %d\n", ref);
|
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
ref = IUnknown_AddRef(reader_input);
|
|
|
|
ok(ref == 2, "Expected 2, got %d\n", ref);
|
|
|
|
IUnknown_Release(reader_input);
|
|
|
|
|
2010-01-21 15:47:03 +01:00
|
|
|
/* IID_IXmlReaderInput */
|
|
|
|
/* it returns a kind of private undocumented vtable incompatible with IUnknown,
|
|
|
|
so it's not a COM interface actually.
|
|
|
|
Such query will be used only to check if input is really IXmlReaderInput */
|
|
|
|
obj = (IUnknown*)0xdeadbeef;
|
|
|
|
hr = IUnknown_QueryInterface(reader_input, &IID_IXmlReaderInput, (void**)&obj);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
2010-01-21 16:19:20 +01:00
|
|
|
ref = IUnknown_AddRef(reader_input);
|
|
|
|
ok(ref == 3, "Expected 3, got %d\n", ref);
|
|
|
|
IUnknown_Release(reader_input);
|
2010-01-21 15:47:03 +01:00
|
|
|
|
2010-01-25 20:37:59 +01:00
|
|
|
IUnknown_Release(reader_input);
|
2010-01-21 15:47:03 +01:00
|
|
|
IUnknown_Release(reader_input);
|
|
|
|
IStream_Release(stream);
|
2010-01-23 17:05:50 +01:00
|
|
|
|
|
|
|
/* test input interface selection sequence */
|
2012-12-19 06:30:44 +01:00
|
|
|
input = NULL;
|
2010-01-23 17:05:50 +01:00
|
|
|
hr = testinput_createinstance((void**)&input);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
input_iids.count = 0;
|
|
|
|
ref = IUnknown_AddRef(input);
|
|
|
|
ok(ref == 2, "Expected 2, got %d\n", ref);
|
|
|
|
IUnknown_Release(input);
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReaderInputWithEncodingName(input, NULL, NULL, FALSE, NULL, &reader_input);
|
2010-01-23 17:05:50 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
ok_iids(&input_iids, empty_seq, NULL, FALSE);
|
|
|
|
/* IXmlReaderInput stores stream interface as IUnknown */
|
|
|
|
ref = IUnknown_AddRef(input);
|
|
|
|
ok(ref == 3, "Expected 3, got %d\n", ref);
|
|
|
|
IUnknown_Release(input);
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
|
2010-01-23 17:05:50 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
input_iids.count = 0;
|
|
|
|
ref = IUnknown_AddRef(reader_input);
|
|
|
|
ok(ref == 2, "Expected 2, got %d\n", ref);
|
|
|
|
IUnknown_Release(reader_input);
|
|
|
|
ref = IUnknown_AddRef(input);
|
|
|
|
ok(ref == 3, "Expected 3, got %d\n", ref);
|
|
|
|
IUnknown_Release(input);
|
|
|
|
hr = IXmlReader_SetInput(reader, reader_input);
|
|
|
|
ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
|
|
|
|
ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Closed);
|
2010-01-23 21:03:14 +01:00
|
|
|
|
2010-01-23 17:05:50 +01:00
|
|
|
ref = IUnknown_AddRef(input);
|
|
|
|
ok(ref == 3, "Expected 3, got %d\n", ref);
|
|
|
|
IUnknown_Release(input);
|
|
|
|
|
|
|
|
ref = IUnknown_AddRef(reader_input);
|
2010-01-25 20:37:59 +01:00
|
|
|
ok(ref == 3 || broken(ref == 2) /* versions 1.0.x and 1.1.x - XP, Vista */,
|
|
|
|
"Expected 3, got %d\n", ref);
|
2010-01-23 17:05:50 +01:00
|
|
|
IUnknown_Release(reader_input);
|
|
|
|
/* repeat another time, no check or caching here */
|
|
|
|
input_iids.count = 0;
|
|
|
|
hr = IXmlReader_SetInput(reader, reader_input);
|
|
|
|
ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
|
|
|
|
ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
|
|
|
|
|
|
|
|
/* another reader */
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader2, NULL);
|
2010-01-23 17:05:50 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
/* resolving from IXmlReaderInput to IStream/ISequentialStream is done at
|
|
|
|
::SetInput() level, each time it's called */
|
|
|
|
input_iids.count = 0;
|
|
|
|
hr = IXmlReader_SetInput(reader2, reader_input);
|
|
|
|
ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE, got %08x\n", hr);
|
|
|
|
ok_iids(&input_iids, setinput_readerinput, NULL, FALSE);
|
|
|
|
|
|
|
|
IXmlReader_Release(reader2);
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
|
|
|
|
IUnknown_Release(reader_input);
|
|
|
|
IUnknown_Release(input);
|
2010-01-21 15:47:03 +01:00
|
|
|
}
|
|
|
|
|
2010-01-23 21:03:14 +01:00
|
|
|
static void test_reader_state(void)
|
|
|
|
{
|
2012-11-19 00:01:46 +01:00
|
|
|
XmlNodeType nodetype;
|
2017-03-06 10:35:56 +01:00
|
|
|
IXmlReader *reader;
|
2010-01-23 21:03:14 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2010-01-23 21:03:14 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
/* invalid arguments */
|
|
|
|
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
/* attempt to read on closed reader */
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Closed);
|
|
|
|
|
2012-11-19 00:01:46 +01:00
|
|
|
if (0)
|
|
|
|
{
|
2017-03-06 10:35:56 +01:00
|
|
|
/* newer versions crash here, probably because no input was set */
|
2012-11-19 00:01:46 +01:00
|
|
|
hr = IXmlReader_Read(reader, &nodetype);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
}
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, "xml");
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Initial);
|
2017-03-06 10:35:56 +01:00
|
|
|
|
|
|
|
nodetype = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_Read(reader, &nodetype);
|
|
|
|
todo_wine
|
|
|
|
ok(FAILED(hr), "got %08x\n", hr);
|
|
|
|
ok(nodetype == XmlNodeType_None, "Unexpected node type %d\n", nodetype);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
todo_wine
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_Error);
|
2017-03-06 10:35:56 +01:00
|
|
|
|
|
|
|
nodetype = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_Read(reader, &nodetype);
|
|
|
|
todo_wine
|
|
|
|
ok(FAILED(hr), "got %08x\n", hr);
|
|
|
|
ok(nodetype == XmlNodeType_None, "Unexpected node type %d\n", nodetype);
|
|
|
|
|
2010-01-23 21:03:14 +01:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
static void test_reader_depth(IXmlReader *reader, UINT depth, UINT brk, int line)
|
|
|
|
{
|
|
|
|
BOOL condition;
|
|
|
|
UINT d = ~0u;
|
|
|
|
|
|
|
|
IXmlReader_GetDepth(reader, &d);
|
|
|
|
|
|
|
|
condition = d == depth;
|
|
|
|
if (brk != ~0u)
|
|
|
|
condition |= broken(d == brk);
|
|
|
|
ok_(__FILE__, line)(condition, "Unexpected nesting depth %u, expected %u\n", d, depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TEST_DEPTH(reader, depth) test_reader_depth(reader, depth, ~0u, __LINE__)
|
|
|
|
#define TEST_DEPTH2(reader, depth, brk) test_reader_depth(reader, depth, brk, __LINE__)
|
|
|
|
|
2010-01-25 19:55:02 +01:00
|
|
|
static void test_read_xmldeclaration(void)
|
|
|
|
{
|
2014-02-12 08:57:00 +01:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
WCHAR name[12];
|
|
|
|
WCHAR val[12];
|
|
|
|
} name_val[] =
|
|
|
|
{
|
|
|
|
{ {'v','e','r','s','i','o','n',0}, {'1','.','0',0} },
|
|
|
|
{ {'e','n','c','o','d','i','n','g',0}, {'U','T','F','-','8',0} },
|
|
|
|
{ {'s','t','a','n','d','a','l','o','n','e',0}, {'y','e','s',0} }
|
|
|
|
};
|
2010-01-25 19:55:02 +01:00
|
|
|
IXmlReader *reader;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
XmlNodeType type;
|
2014-02-12 08:57:00 +01:00
|
|
|
UINT count = 0, len, i;
|
2014-02-20 11:28:09 +01:00
|
|
|
BOOL ret;
|
2012-12-06 13:05:19 +01:00
|
|
|
const WCHAR *val;
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL);
|
2010-01-25 19:55:02 +01:00
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
stream = create_stream_on_data(xmldecl_full, sizeof(xmldecl_full));
|
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, (IUnknown*)stream);
|
|
|
|
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
|
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(count == 0, "got %d\n", count);
|
|
|
|
|
2012-12-06 13:05:19 +01:00
|
|
|
/* try to move without attributes */
|
|
|
|
hr = IXmlReader_MoveToElement(reader);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToNextAttribute(reader);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION(reader, 0, 0);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-29 19:45:25 +02:00
|
|
|
read_node(reader, XmlNodeType_XmlDeclaration);
|
|
|
|
|
2011-08-03 23:50:18 +02:00
|
|
|
/* new version 1.2.x and 1.3.x properly update position for <?xml ?> */
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 3, ~0u, 55);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_DEPTH(reader, 0);
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_Interactive);
|
2017-03-06 10:35:59 +01:00
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
2012-12-06 13:05:19 +01:00
|
|
|
|
2010-01-25 19:55:02 +01:00
|
|
|
/* check attributes */
|
2017-03-29 19:45:32 +02:00
|
|
|
next_attribute(reader);
|
2012-12-06 13:18:28 +01:00
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_DEPTH(reader, 1);
|
2017-03-06 10:35:59 +01:00
|
|
|
|
2012-12-06 13:18:28 +01:00
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "got %d\n", type);
|
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 7, ~0u, 55);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2012-12-06 13:05:19 +01:00
|
|
|
/* try to move from last attribute */
|
2017-03-29 19:45:32 +02:00
|
|
|
next_attribute(reader);
|
|
|
|
next_attribute(reader);
|
2012-12-06 13:05:19 +01:00
|
|
|
hr = IXmlReader_MoveToNextAttribute(reader);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
|
2012-12-06 13:18:28 +01:00
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "got %d\n", type);
|
|
|
|
|
2010-01-25 19:55:02 +01:00
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
2012-12-06 13:05:19 +01:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 7, ~0u, 55);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2012-12-04 10:31:25 +01:00
|
|
|
hr = IXmlReader_GetAttributeCount(reader, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "got %08x\n", hr);
|
|
|
|
|
2010-01-25 19:55:02 +01:00
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
2012-12-04 10:31:25 +01:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
2010-01-25 19:55:02 +01:00
|
|
|
ok(count == 3, "Expected 3, got %d\n", count);
|
2012-12-04 10:31:25 +01:00
|
|
|
|
2014-02-12 08:57:00 +01:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
hr = IXmlReader_GetLocalName(reader, &val, &len);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(len == lstrlenW(name_val[i].name), "expected %u, got %u\n", lstrlenW(name_val[i].name), len);
|
|
|
|
ok(!lstrcmpW(name_val[i].name, val), "expected %s, got %s\n", wine_dbgstr_w(name_val[i].name), wine_dbgstr_w(val));
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
hr = IXmlReader_GetValue(reader, &val, &len);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(len == lstrlenW(name_val[i].val), "expected %u, got %u\n", lstrlenW(name_val[i].val), len);
|
|
|
|
ok(!lstrcmpW(name_val[i].val, val), "expected %s, got %s\n", wine_dbgstr_w(name_val[i].val), wine_dbgstr_w(val));
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToNextAttribute(reader);
|
2014-11-10 21:06:31 +01:00
|
|
|
ok(hr == ((i < count - 1) ? S_OK : S_FALSE), "got %08x\n", hr);
|
2014-02-12 08:57:00 +01:00
|
|
|
}
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_DEPTH(reader, 1);
|
2010-01-25 19:55:02 +01:00
|
|
|
|
2017-03-31 15:57:27 +02:00
|
|
|
move_to_element(reader);
|
2017-03-09 05:14:10 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 3, ~0u, 55);
|
2012-12-06 13:05:19 +01:00
|
|
|
|
2012-12-06 13:18:28 +01:00
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_XmlDeclaration, "got %d\n", type);
|
|
|
|
|
2012-12-19 06:30:44 +01:00
|
|
|
type = XmlNodeType_XmlDeclaration;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
/* newer versions return syntax error here cause document is incomplete,
|
|
|
|
it makes more sense than invalid char error */
|
|
|
|
todo_wine {
|
|
|
|
ok(hr == WC_E_SYNTAX || broken(hr == WC_E_XMLCHARACTER), "got 0x%08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_None, "got %d\n", type);
|
|
|
|
}
|
2014-02-10 04:44:52 +01:00
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
/* test short variant */
|
|
|
|
stream = create_stream_on_data(xmldecl_short, sizeof(xmldecl_short));
|
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, (IUnknown *)stream);
|
|
|
|
ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-29 19:45:25 +02:00
|
|
|
read_node(reader, XmlNodeType_XmlDeclaration);
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 3, ~0u, 21);
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Interactive);
|
2014-02-10 04:44:52 +01:00
|
|
|
|
2014-02-20 11:28:09 +01:00
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
|
|
|
ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
|
|
|
|
ok(count == 1, "expected 1, got %d\n", count);
|
|
|
|
|
|
|
|
ret = IXmlReader_IsEmptyElement(reader);
|
|
|
|
ok(!ret, "element should not be empty\n");
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
|
|
|
reader_name(reader, L"xml");
|
2017-03-07 04:50:55 +01:00
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_qname(reader, L"xml");
|
2014-02-20 11:28:09 +01:00
|
|
|
|
2014-02-10 04:44:52 +01:00
|
|
|
/* check attributes */
|
2017-03-29 19:45:32 +02:00
|
|
|
next_attribute(reader);
|
2014-02-10 04:44:52 +01:00
|
|
|
|
|
|
|
type = -1;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "got %d\n", type);
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 7, ~0u, 21);
|
2014-02-10 04:44:52 +01:00
|
|
|
|
|
|
|
/* try to move from last attribute */
|
|
|
|
hr = IXmlReader_MoveToNextAttribute(reader);
|
|
|
|
ok(hr == S_FALSE, "expected S_FALSE, got %08x\n", hr);
|
|
|
|
|
2017-03-29 19:45:25 +02:00
|
|
|
read_node(reader, XmlNodeType_Element);
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 23, ~0u, 40);
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Interactive);
|
2014-02-20 11:28:09 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
|
|
|
ok(hr == S_OK, "expected S_OK, got %08x\n", hr);
|
|
|
|
ok(count == 0, "expected 0, got %d\n", count);
|
|
|
|
|
|
|
|
ret = IXmlReader_IsEmptyElement(reader);
|
|
|
|
ok(ret, "element should be empty\n");
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
|
|
|
reader_name(reader, L"RegistrationInfo");
|
2014-02-20 11:28:09 +01:00
|
|
|
|
|
|
|
type = -1;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == WC_E_SYNTAX || hr == WC_E_XMLCHARACTER /* XP */, "expected WC_E_SYNTAX, got %08x\n", hr);
|
2017-03-06 10:35:57 +01:00
|
|
|
ok(type == XmlNodeType_None, "expected XmlNodeType_None, got %s\n", type_to_str(type));
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION(reader, 1, 41);
|
2017-03-09 05:14:09 +01:00
|
|
|
todo_wine
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Error);
|
2017-03-09 05:14:09 +01:00
|
|
|
|
2010-01-25 19:55:02 +01:00
|
|
|
IStream_Release(stream);
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
struct test_entry
|
|
|
|
{
|
2013-01-05 23:42:02 +01:00
|
|
|
const char *xml;
|
2020-02-07 15:52:19 +01:00
|
|
|
const WCHAR *name;
|
|
|
|
const WCHAR *value;
|
2013-01-05 23:42:02 +01:00
|
|
|
HRESULT hr;
|
|
|
|
HRESULT hr_broken; /* this is set to older version results */
|
2014-01-07 00:14:38 +01:00
|
|
|
BOOL todo;
|
2013-01-05 23:42:02 +01:00
|
|
|
};
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
static struct test_entry comment_tests[] =
|
|
|
|
{
|
|
|
|
{ "<!-- comment -->", L"", L" comment ", S_OK },
|
|
|
|
{ "<!-- - comment-->", L"", L" - comment", S_OK },
|
2013-01-08 11:32:21 +01:00
|
|
|
{ "<!-- -- comment-->", NULL, NULL, WC_E_COMMENT, WC_E_GREATERTHAN },
|
|
|
|
{ "<!-- -- comment--->", NULL, NULL, WC_E_COMMENT, WC_E_GREATERTHAN },
|
2013-01-05 23:42:02 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
2012-12-19 06:30:44 +01:00
|
|
|
|
|
|
|
static void test_read_comment(void)
|
|
|
|
{
|
2017-03-08 05:07:08 +01:00
|
|
|
static const char *teststr = "<a>text<!-- comment --></a>";
|
2013-01-05 23:42:02 +01:00
|
|
|
struct test_entry *test = comment_tests;
|
2017-03-08 05:07:08 +01:00
|
|
|
static const XmlNodeType types[] =
|
|
|
|
{
|
|
|
|
XmlNodeType_Element,
|
|
|
|
XmlNodeType_Text,
|
|
|
|
XmlNodeType_Comment,
|
|
|
|
XmlNodeType_EndElement,
|
|
|
|
};
|
|
|
|
unsigned int i = 0;
|
2012-12-19 06:30:44 +01:00
|
|
|
IXmlReader *reader;
|
2017-03-08 05:07:08 +01:00
|
|
|
XmlNodeType type;
|
2013-01-05 23:42:02 +01:00
|
|
|
HRESULT hr;
|
2012-12-19 06:30:44 +01:00
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2012-12-19 06:30:44 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, teststr);
|
2017-03-08 05:07:08 +01:00
|
|
|
|
|
|
|
while (IXmlReader_Read(reader, &type) == S_OK)
|
2013-01-05 23:42:02 +01:00
|
|
|
{
|
2017-03-08 05:07:08 +01:00
|
|
|
const WCHAR *value;
|
2012-12-19 06:30:44 +01:00
|
|
|
|
2017-03-08 05:07:08 +01:00
|
|
|
ok(type == types[i], "%d: unexpected node type %d\n", i, type);
|
|
|
|
|
|
|
|
if (type == XmlNodeType_Text || type == XmlNodeType_Comment)
|
|
|
|
{
|
|
|
|
hr = IXmlReader_GetValue(reader, &value, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(*value != 0, "Expected node value\n");
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (test->xml)
|
|
|
|
{
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-01-05 23:42:02 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
if (test->hr_broken)
|
|
|
|
ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
|
|
|
|
else
|
|
|
|
ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
|
|
|
|
if (hr == S_OK)
|
2013-01-06 21:55:36 +01:00
|
|
|
{
|
2013-01-08 11:32:21 +01:00
|
|
|
const WCHAR *str;
|
2013-01-06 21:55:36 +01:00
|
|
|
|
2013-01-05 23:42:02 +01:00
|
|
|
ok(type == XmlNodeType_Comment, "got %d for %s\n", type, test->xml);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"");
|
2013-01-06 21:55:36 +01:00
|
|
|
|
2017-03-10 09:06:40 +01:00
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetLocalName(reader, &str, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_qname(reader, L"");
|
2013-01-08 11:32:21 +01:00
|
|
|
|
2017-03-10 09:06:40 +01:00
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
|
|
|
|
2013-01-08 11:32:21 +01:00
|
|
|
/* value */
|
2017-03-29 19:45:50 +02:00
|
|
|
reader_value(reader, test->value);
|
2013-01-06 21:55:36 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 23:42:02 +01:00
|
|
|
test++;
|
|
|
|
}
|
2012-12-19 06:30:44 +01:00
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
static struct test_entry pi_tests[] =
|
|
|
|
{
|
|
|
|
{ "<?pi?>", L"pi", L"", S_OK },
|
|
|
|
{ "<?pi ?>", L"pi", L"", S_OK },
|
|
|
|
{ "<?pi ?>", L"pi", L"", S_OK },
|
|
|
|
{ "<?pi pi data?>", L"pi", L"pi data", S_OK },
|
|
|
|
{ "<?pi pi data ?>", L"pi", L"pi data ", S_OK },
|
|
|
|
{ "<?pi data ?>", L"pi", L"data ", S_OK },
|
2013-01-08 11:32:21 +01:00
|
|
|
{ "<?pi:pi?>", NULL, NULL, NC_E_NAMECOLON, WC_E_NAMECHARACTER },
|
|
|
|
{ "<?:pi ?>", NULL, NULL, WC_E_PI, WC_E_NAMECHARACTER },
|
|
|
|
{ "<?-pi ?>", NULL, NULL, WC_E_PI, WC_E_NAMECHARACTER },
|
2020-02-07 15:52:19 +01:00
|
|
|
{ "<?xml-stylesheet ?>", L"xml-stylesheet", L"", S_OK },
|
2013-01-05 23:08:27 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_read_pi(void)
|
|
|
|
{
|
|
|
|
struct test_entry *test = pi_tests;
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-01-05 23:08:27 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
while (test->xml)
|
|
|
|
{
|
|
|
|
XmlNodeType type;
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-01-05 23:08:27 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
if (test->hr_broken)
|
|
|
|
ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
|
|
|
|
else
|
|
|
|
ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
|
|
|
|
if (hr == S_OK)
|
2013-01-06 21:55:36 +01:00
|
|
|
{
|
2013-01-08 12:42:57 +01:00
|
|
|
const WCHAR *str;
|
2013-01-06 21:55:36 +01:00
|
|
|
UINT len;
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
ok(type == XmlNodeType_ProcessingInstruction, "got %d for %s\n", type, test->xml);
|
|
|
|
|
2017-03-29 19:46:02 +02:00
|
|
|
reader_name(reader, test->name);
|
2013-01-06 21:55:36 +01:00
|
|
|
|
|
|
|
len = 0;
|
2013-01-08 12:42:57 +01:00
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
2013-01-06 21:55:36 +01:00
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(len == lstrlenW(test->name), "got %u\n", len);
|
|
|
|
ok(!lstrcmpW(str, test->name), "got %s\n", wine_dbgstr_w(str));
|
2013-01-08 12:42:57 +01:00
|
|
|
|
|
|
|
/* value */
|
2017-03-29 19:45:50 +02:00
|
|
|
reader_value(reader, test->value);
|
2013-01-06 21:55:36 +01:00
|
|
|
}
|
|
|
|
|
2013-01-05 23:08:27 +01:00
|
|
|
test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2013-01-13 19:36:30 +01:00
|
|
|
struct nodes_test {
|
|
|
|
const char *xml;
|
2017-03-21 16:19:49 +01:00
|
|
|
struct {
|
|
|
|
XmlNodeType type;
|
2020-02-07 15:52:19 +01:00
|
|
|
const WCHAR *value;
|
2017-03-21 16:19:49 +01:00
|
|
|
} nodes[20];
|
2013-01-13 19:36:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char misc_test_xml[] =
|
|
|
|
"<!-- comment1 -->"
|
|
|
|
"<!-- comment2 -->"
|
|
|
|
"<?pi1 pi1body ?>"
|
|
|
|
"<!-- comment3 -->"
|
|
|
|
" \t \r \n"
|
|
|
|
"<!-- comment4 -->"
|
2013-01-20 20:46:25 +01:00
|
|
|
"<a>"
|
2013-09-29 16:55:20 +02:00
|
|
|
"\r\n\t"
|
2013-01-22 10:11:51 +01:00
|
|
|
"<b/>"
|
2013-09-29 16:52:47 +02:00
|
|
|
"text"
|
2013-01-23 09:12:55 +01:00
|
|
|
"<!-- comment -->"
|
2013-09-29 16:52:47 +02:00
|
|
|
"text2"
|
2013-01-23 09:12:55 +01:00
|
|
|
"<?pi pibody ?>"
|
2013-09-29 16:55:20 +02:00
|
|
|
"\r\n"
|
2013-01-22 10:11:51 +01:00
|
|
|
"</a>"
|
2013-01-13 19:36:30 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
static struct nodes_test misc_test = {
|
|
|
|
misc_test_xml,
|
|
|
|
{
|
2020-02-07 15:52:19 +01:00
|
|
|
{ XmlNodeType_Comment, L" comment1 " },
|
|
|
|
{ XmlNodeType_Comment, L" comment2 " },
|
|
|
|
{ XmlNodeType_ProcessingInstruction, L"pi1body " },
|
|
|
|
{ XmlNodeType_Comment, L" comment3 " },
|
|
|
|
{ XmlNodeType_Whitespace, L" \t \n \n" },
|
|
|
|
{ XmlNodeType_Comment, L" comment4 " },
|
|
|
|
{ XmlNodeType_Element, L"" },
|
|
|
|
{ XmlNodeType_Whitespace, L"\n\t" },
|
|
|
|
{ XmlNodeType_Element, L"" },
|
|
|
|
{ XmlNodeType_Text, L"text" },
|
|
|
|
{ XmlNodeType_Comment, L" comment " },
|
|
|
|
{ XmlNodeType_Text, L"text2" },
|
|
|
|
{ XmlNodeType_ProcessingInstruction, L"pibody " },
|
|
|
|
{ XmlNodeType_Whitespace, L"\n" },
|
|
|
|
{ XmlNodeType_EndElement, L"" },
|
|
|
|
{ XmlNodeType_None, L"" }
|
2013-01-13 19:36:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_read_full(void)
|
|
|
|
{
|
|
|
|
struct nodes_test *test = &misc_test;
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
int i;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-01-13 19:36:30 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-01-13 19:36:30 +01:00
|
|
|
|
|
|
|
i = 0;
|
2017-03-21 16:19:49 +01:00
|
|
|
do
|
2013-01-13 19:36:30 +01:00
|
|
|
{
|
2017-03-29 19:45:25 +02:00
|
|
|
read_node(reader, test->nodes[i].type);
|
2017-03-29 19:45:50 +02:00
|
|
|
reader_value(reader, test->nodes[i].value);
|
2017-03-21 16:19:49 +01:00
|
|
|
} while(test->nodes[i++].type != XmlNodeType_None);
|
2013-01-13 19:36:30 +01:00
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2016-11-22 15:57:20 +01:00
|
|
|
static const char test_public_dtd[] =
|
|
|
|
"<!DOCTYPE testdtd PUBLIC \"pubid\" \"externalid uri\" >";
|
|
|
|
|
|
|
|
static void test_read_public_dtd(void)
|
|
|
|
{
|
|
|
|
static const WCHAR dtdnameW[] = {'t','e','s','t','d','t','d',0};
|
|
|
|
IXmlReader *reader;
|
|
|
|
const WCHAR *str;
|
|
|
|
XmlNodeType type;
|
|
|
|
UINT len, count;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, DtdProcessing_Parse);
|
|
|
|
ok(hr == S_OK, "got 0x%8x\n", hr);
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, test_public_dtd);
|
2016-11-22 15:57:20 +01:00
|
|
|
|
2017-03-29 19:45:25 +02:00
|
|
|
read_node(reader, XmlNodeType_DocumentType);
|
2016-11-22 15:57:20 +01:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(count == 2, "got %d\n", count);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "got %d\n", type);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"PUBLIC");
|
|
|
|
reader_value(reader, L"pubid");
|
2016-11-22 15:57:20 +01:00
|
|
|
|
2017-03-29 19:45:32 +02:00
|
|
|
next_attribute(reader);
|
2016-11-22 15:57:20 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "got %d\n", type);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"SYSTEM");
|
|
|
|
reader_value(reader, L"externalid uri");
|
2016-11-22 15:57:20 +01:00
|
|
|
|
2017-03-31 15:57:27 +02:00
|
|
|
move_to_element(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"testdtd");
|
2016-11-22 15:57:20 +01:00
|
|
|
|
|
|
|
len = 0;
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2017-03-07 04:50:58 +01:00
|
|
|
todo_wine {
|
2016-11-22 15:57:20 +01:00
|
|
|
ok(len == lstrlenW(dtdnameW), "got %u\n", len);
|
|
|
|
ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
|
2017-03-07 04:50:58 +01:00
|
|
|
}
|
2016-11-22 15:57:20 +01:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char test_system_dtd[] =
|
2013-01-15 20:54:14 +01:00
|
|
|
"<!DOCTYPE testdtd SYSTEM \"externalid uri\" >"
|
|
|
|
"<!-- comment -->";
|
|
|
|
|
2016-11-22 15:57:20 +01:00
|
|
|
static void test_read_system_dtd(void)
|
2013-01-15 20:54:14 +01:00
|
|
|
{
|
|
|
|
static const WCHAR dtdnameW[] = {'t','e','s','t','d','t','d',0};
|
|
|
|
IXmlReader *reader;
|
|
|
|
const WCHAR *str;
|
|
|
|
XmlNodeType type;
|
|
|
|
UINT len, count;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-01-15 20:54:14 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_DtdProcessing, DtdProcessing_Parse);
|
|
|
|
ok(hr == S_OK, "got 0x%8x\n", hr);
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, test_system_dtd);
|
2013-01-15 20:54:14 +01:00
|
|
|
|
2017-03-29 19:45:25 +02:00
|
|
|
read_node(reader, XmlNodeType_DocumentType);
|
2013-01-15 20:54:14 +01:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(count == 1, "got %d\n", count);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "got %d\n", type);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"SYSTEM");
|
|
|
|
reader_value(reader, L"externalid uri");
|
2013-08-19 08:42:38 +02:00
|
|
|
|
2017-03-31 15:57:27 +02:00
|
|
|
move_to_element(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"testdtd");
|
2013-01-15 20:54:14 +01:00
|
|
|
|
|
|
|
len = 0;
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2017-03-07 04:50:58 +01:00
|
|
|
todo_wine {
|
2013-01-15 20:54:14 +01:00
|
|
|
ok(len == lstrlenW(dtdnameW), "got %u\n", len);
|
|
|
|
ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
|
2017-03-07 04:50:58 +01:00
|
|
|
}
|
2017-03-29 19:45:25 +02:00
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Comment);
|
2013-01-15 20:54:14 +01:00
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
static struct test_entry element_tests[] =
|
|
|
|
{
|
|
|
|
{ "<a/>", L"a", L"", S_OK },
|
|
|
|
{ "<a />", L"a", L"", S_OK },
|
|
|
|
{ "<a:b/>", L"a:b", L"", NC_E_UNDECLAREDPREFIX },
|
2013-01-18 07:04:27 +01:00
|
|
|
{ "<:a/>", NULL, NULL, NC_E_QNAMECHARACTER },
|
|
|
|
{ "< a/>", NULL, NULL, NC_E_QNAMECHARACTER },
|
2020-02-07 15:52:19 +01:00
|
|
|
{ "<a>", L"a", L"", S_OK },
|
|
|
|
{ "<a >", L"a", L"", S_OK },
|
|
|
|
{ "<a \r \t\n>", L"a", L"", S_OK },
|
2013-01-22 10:11:51 +01:00
|
|
|
{ "</a>", NULL, NULL, NC_E_QNAMECHARACTER },
|
2017-03-10 09:06:41 +01:00
|
|
|
{ "<a:b:c />", NULL, NULL, NC_E_QNAMECOLON },
|
|
|
|
{ "<:b:c />", NULL, NULL, NC_E_QNAMECHARACTER },
|
2013-01-18 07:04:27 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_read_element(void)
|
|
|
|
{
|
|
|
|
struct test_entry *test = element_tests;
|
2017-03-06 10:35:59 +01:00
|
|
|
static const char stag[] =
|
|
|
|
"<a attr1=\"_a\">"
|
|
|
|
"<b attr2=\"_b\">"
|
|
|
|
"text"
|
|
|
|
"<c attr3=\"_c\"/>"
|
|
|
|
"<d attr4=\"_d\"></d>"
|
|
|
|
"</b>"
|
|
|
|
"</a>";
|
|
|
|
static const UINT depths[] = { 0, 1, 2, 2, 2, 3, 2, 1 };
|
2013-01-18 07:04:27 +01:00
|
|
|
IXmlReader *reader;
|
2013-01-20 22:03:23 +01:00
|
|
|
XmlNodeType type;
|
2017-03-06 10:35:59 +01:00
|
|
|
unsigned int i;
|
2013-01-20 22:03:23 +01:00
|
|
|
UINT depth;
|
2013-01-18 07:04:27 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-01-18 07:04:27 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
while (test->xml)
|
|
|
|
{
|
2017-03-28 17:27:17 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-01-18 07:04:27 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
if (test->hr_broken)
|
|
|
|
ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
|
|
|
|
else
|
2016-12-09 14:38:32 +01:00
|
|
|
todo_wine_if(test->hr == NC_E_UNDECLAREDPREFIX)
|
|
|
|
ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
|
2013-01-18 07:04:27 +01:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
const WCHAR *str;
|
|
|
|
UINT len;
|
|
|
|
|
|
|
|
ok(type == XmlNodeType_Element, "got %d for %s\n", type, test->xml);
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(len == lstrlenW(test->name), "got %u\n", len);
|
|
|
|
ok(!lstrcmpW(str, test->name), "got %s\n", wine_dbgstr_w(str));
|
2013-01-18 07:04:27 +01:00
|
|
|
|
|
|
|
/* value */
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
2013-01-18 07:04:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test++;
|
|
|
|
}
|
|
|
|
|
2013-01-22 10:11:51 +01:00
|
|
|
/* test reader depth increment */
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, stag);
|
2013-01-20 22:03:23 +01:00
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
i = 0;
|
|
|
|
while (IXmlReader_Read(reader, &type) == S_OK)
|
|
|
|
{
|
2017-03-17 14:46:12 +01:00
|
|
|
UINT count;
|
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
ok(type == XmlNodeType_Element || type == XmlNodeType_EndElement ||
|
|
|
|
type == XmlNodeType_Text, "Unexpected node type %d\n", type);
|
2013-01-22 10:11:51 +01:00
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
depth = 123;
|
|
|
|
hr = IXmlReader_GetDepth(reader, &depth);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(depth == depths[i], "%u: got depth %u, expected %u\n", i, depth, depths[i]);
|
2013-01-22 10:11:51 +01:00
|
|
|
|
2017-03-17 14:46:12 +01:00
|
|
|
if (type == XmlNodeType_Element || type == XmlNodeType_EndElement)
|
|
|
|
{
|
|
|
|
const WCHAR *prefix;
|
|
|
|
|
|
|
|
prefix = NULL;
|
|
|
|
hr = IXmlReader_GetPrefix(reader, &prefix, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(prefix != NULL, "got %p\n", prefix);
|
|
|
|
|
|
|
|
if (!*prefix)
|
|
|
|
{
|
|
|
|
const WCHAR *local, *qname;
|
|
|
|
|
|
|
|
local = NULL;
|
|
|
|
hr = IXmlReader_GetLocalName(reader, &local, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(local != NULL, "got %p\n", local);
|
|
|
|
|
|
|
|
qname = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &qname, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(qname != NULL, "got %p\n", qname);
|
|
|
|
|
|
|
|
ok(local == qname, "expected same pointer\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == XmlNodeType_EndElement)
|
2017-03-06 10:35:59 +01:00
|
|
|
{
|
2017-03-17 14:46:12 +01:00
|
|
|
count = 1;
|
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(count == 0, "got %u\n", count);
|
|
|
|
}
|
2017-03-06 10:35:59 +01:00
|
|
|
|
2017-03-17 14:46:12 +01:00
|
|
|
if (type == XmlNodeType_Element)
|
|
|
|
{
|
|
|
|
count = 0;
|
2017-03-06 10:35:59 +01:00
|
|
|
hr = IXmlReader_GetAttributeCount(reader, &count);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
/* moving to attributes increases depth */
|
|
|
|
if (count)
|
|
|
|
{
|
2017-03-07 04:50:56 +01:00
|
|
|
const WCHAR *value;
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
2017-03-07 04:50:56 +01:00
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
2017-03-07 04:50:56 +01:00
|
|
|
hr = IXmlReader_GetValue(reader, &value, NULL);
|
|
|
|
ok(*value != 0, "Unexpected value %s\n", wine_dbgstr_w(value));
|
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
depth = 123;
|
|
|
|
hr = IXmlReader_GetDepth(reader, &depth);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(depth == depths[i] + 1, "%u: got depth %u, expected %u\n", i, depth, depths[i] + 1);
|
|
|
|
|
2017-03-31 15:57:27 +02:00
|
|
|
move_to_element(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
2017-03-07 04:50:56 +01:00
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
depth = 123;
|
|
|
|
hr = IXmlReader_GetDepth(reader, &depth);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(depth == depths[i], "%u: got depth %u, expected %u\n", i, depth, depths[i]);
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 10:11:51 +01:00
|
|
|
|
2017-03-06 10:35:59 +01:00
|
|
|
i++;
|
|
|
|
}
|
2013-01-22 10:11:51 +01:00
|
|
|
|
|
|
|
/* start/end tag mismatch */
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, "<a></b>");
|
2013-01-22 10:11:51 +01:00
|
|
|
|
2017-03-29 19:45:25 +02:00
|
|
|
read_node(reader, XmlNodeType_Element);
|
2013-01-22 10:11:51 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == WC_E_ELEMENTMATCH, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_None, "got %d\n", type);
|
2017-03-13 10:27:54 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Error);
|
2013-01-22 10:11:51 +01:00
|
|
|
|
2013-01-18 07:04:27 +01:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2013-01-27 08:17:27 +01:00
|
|
|
static ISequentialStream teststream = { &teststreamvtbl };
|
|
|
|
|
|
|
|
static void test_read_pending(void)
|
|
|
|
{
|
|
|
|
IXmlReader *reader;
|
|
|
|
const WCHAR *value;
|
|
|
|
XmlNodeType type;
|
|
|
|
HRESULT hr;
|
|
|
|
int c;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-03-11 05:49:28 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got 0x%08x\n", hr);
|
2013-01-27 08:17:27 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, (IUnknown*)&teststream);
|
2013-03-11 05:49:28 +01:00
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2013-01-27 08:17:27 +01:00
|
|
|
|
|
|
|
/* first read call returns incomplete node, second attempt fails with E_PENDING */
|
|
|
|
stream_readcall = 0;
|
|
|
|
type = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
2013-03-11 05:49:28 +01:00
|
|
|
ok(hr == S_OK || broken(hr == E_PENDING), "got 0x%08x\n", hr);
|
2013-01-27 08:17:27 +01:00
|
|
|
/* newer versions are happy when it's enough data to detect node type,
|
|
|
|
older versions keep reading until it fails to read more */
|
2017-03-10 09:06:43 +01:00
|
|
|
todo_wine
|
2013-01-27 08:17:27 +01:00
|
|
|
ok(stream_readcall == 1 || broken(stream_readcall > 1), "got %d\n", stream_readcall);
|
|
|
|
ok(type == XmlNodeType_Comment || broken(type == XmlNodeType_None), "got %d\n", type);
|
|
|
|
|
|
|
|
/* newer versions' GetValue() makes an attempt to read more */
|
|
|
|
c = stream_readcall;
|
|
|
|
value = (void*)0xdeadbeef;
|
|
|
|
hr = IXmlReader_GetValue(reader, &value, NULL);
|
2013-03-11 05:49:28 +01:00
|
|
|
ok(hr == E_PENDING, "got 0x%08x\n", hr);
|
|
|
|
ok(value == NULL || broken(value == (void*)0xdeadbeef) /* Win8 sets it to NULL */, "got %p\n", value);
|
2013-01-27 08:17:27 +01:00
|
|
|
ok(c < stream_readcall || broken(c == stream_readcall), "got %d, expected %d\n", stream_readcall, c+1);
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2013-02-11 06:22:23 +01:00
|
|
|
static void test_readvaluechunk(void)
|
|
|
|
{
|
|
|
|
IXmlReader *reader;
|
|
|
|
XmlNodeType type;
|
2017-03-21 16:19:24 +01:00
|
|
|
WCHAR buf[64];
|
2013-02-11 06:22:23 +01:00
|
|
|
WCHAR b;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT c;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-02-11 06:22:23 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, "<!-- comment1 --><!-- comment2 -->");
|
2013-02-11 06:22:23 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
2017-03-21 16:19:24 +01:00
|
|
|
ok(type == XmlNodeType_Comment, "type = %u\n", type);
|
2013-02-11 06:22:23 +01:00
|
|
|
|
2017-03-29 19:46:48 +02:00
|
|
|
read_value_char(reader, ' ');
|
|
|
|
read_value_char(reader, 'c');
|
2017-03-21 16:19:24 +01:00
|
|
|
|
2013-02-11 06:22:23 +01:00
|
|
|
/* portion read as chunk is skipped from resulting node value */
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"omment1 ");
|
2013-02-11 06:22:23 +01:00
|
|
|
|
|
|
|
/* once value is returned/allocated it's not possible to read by chunk */
|
|
|
|
c = 0;
|
|
|
|
b = 0;
|
|
|
|
hr = IXmlReader_ReadValueChunk(reader, &b, 1, &c);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
ok(c == 0, "got %u\n", c);
|
|
|
|
ok(b == 0, "got %x\n", b);
|
|
|
|
|
2017-03-21 16:19:24 +01:00
|
|
|
c = 0xdeadbeef;
|
|
|
|
hr = IXmlReader_ReadValueChunk(reader, buf, 0, &c);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(!c, "c = %u\n", c);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"omment1 ");
|
2017-03-21 16:19:24 +01:00
|
|
|
|
|
|
|
/* read comment2 */
|
2017-03-29 19:46:48 +02:00
|
|
|
read_node(reader, XmlNodeType_Comment);
|
2017-03-21 16:19:24 +01:00
|
|
|
|
|
|
|
c = 0xdeadbeef;
|
|
|
|
hr = IXmlReader_ReadValueChunk(reader, buf, 0, &c);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(!c, "c = %u\n", c);
|
|
|
|
|
|
|
|
c = 0xdeadbeef;
|
|
|
|
memset(buf, 0xcc, sizeof(buf));
|
2018-02-22 07:01:44 +01:00
|
|
|
hr = IXmlReader_ReadValueChunk(reader, buf, ARRAY_SIZE(buf), &c);
|
2017-03-21 16:19:24 +01:00
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(c == 10, "got %u\n", c);
|
|
|
|
ok(buf[c] == 0xcccc, "buffer overflow\n");
|
|
|
|
buf[c] = 0;
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(!lstrcmpW(buf, L" comment2 "), "buf = %s\n", wine_dbgstr_w(buf));
|
2017-03-21 16:19:24 +01:00
|
|
|
|
|
|
|
c = 0xdeadbeef;
|
|
|
|
memset(buf, 0xcc, sizeof(buf));
|
2018-02-22 07:01:44 +01:00
|
|
|
hr = IXmlReader_ReadValueChunk(reader, buf, ARRAY_SIZE(buf), &c);
|
2017-03-21 16:19:24 +01:00
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
ok(!c, "got %u\n", c);
|
|
|
|
|
|
|
|
/* portion read as chunk is skipped from resulting node value */
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
2017-03-21 16:19:24 +01:00
|
|
|
|
|
|
|
/* once value is returned/allocated it's not possible to read by chunk */
|
|
|
|
c = 0xdeadbeef;
|
|
|
|
b = 0xffff;
|
|
|
|
hr = IXmlReader_ReadValueChunk(reader, &b, 1, &c);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
ok(c == 0, "got %u\n", c);
|
|
|
|
ok(b == 0xffff, "got %x\n", b);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"");
|
2013-02-11 06:22:23 +01:00
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
static struct test_entry cdata_tests[] =
|
|
|
|
{
|
|
|
|
{ "<a><![CDATA[ ]]data ]]></a>", L"", L" ]]data ", S_OK },
|
|
|
|
{ "<a><![CDATA[<![CDATA[ data ]]]]></a>", L"", L"<![CDATA[ data ]]", S_OK },
|
|
|
|
{ "<a><![CDATA[\n \r\n \n\n ]]></a>", L"", L"\n \n \n\n ", S_OK, S_OK },
|
|
|
|
{ "<a><![CDATA[\r \r\r\n \n\n ]]></a>", L"", L"\n \n\n \n\n ", S_OK, S_OK },
|
|
|
|
{ "<a><![CDATA[\r\r \n\r \r \n\n ]]></a>", L"", L"\n\n \n\n \n \n\n ", S_OK },
|
2013-03-10 15:29:43 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_read_cdata(void)
|
|
|
|
{
|
|
|
|
struct test_entry *test = cdata_tests;
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-03-10 15:29:43 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
while (test->xml)
|
|
|
|
{
|
|
|
|
XmlNodeType type;
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-03-10 15:29:43 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
|
|
|
|
/* read one more to get to CDATA */
|
|
|
|
if (type == XmlNodeType_Element)
|
|
|
|
{
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test->hr_broken)
|
|
|
|
ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
|
|
|
|
else
|
|
|
|
ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
const WCHAR *str;
|
|
|
|
UINT len;
|
|
|
|
|
|
|
|
ok(type == XmlNodeType_CDATA, "got %d for %s\n", type, test->xml);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"");
|
2013-06-12 11:06:24 +02:00
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetLocalName(reader, &str, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2017-03-10 09:06:39 +01:00
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
2013-03-10 15:29:43 +01:00
|
|
|
|
|
|
|
len = 1;
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2017-03-10 09:06:40 +01:00
|
|
|
ok(len == 0, "got %u\n", len);
|
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
2013-03-10 15:29:43 +01:00
|
|
|
|
|
|
|
/* value */
|
2017-03-29 19:45:50 +02:00
|
|
|
reader_value(reader, test->value);
|
2013-03-10 15:29:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
static struct test_entry text_tests[] =
|
|
|
|
{
|
|
|
|
{ "<a>simple text</a>", L"", L"simple text", S_OK },
|
|
|
|
{ "<a>text ]]> text</a>", L"", L"", WC_E_CDSECTEND },
|
|
|
|
{ "<a>\n \r\n \n\n text</a>", L"", L"\n \n \n\n text", S_OK, S_OK },
|
|
|
|
{ "<a>\r \r\r\n \n\n text</a>", L"", L"\n \n\n \n\n text", S_OK, S_OK },
|
2013-06-15 18:45:21 +02:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_read_text(void)
|
|
|
|
{
|
|
|
|
struct test_entry *test = text_tests;
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-06-15 18:45:21 +02:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
while (test->xml)
|
|
|
|
{
|
|
|
|
XmlNodeType type;
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-06-15 18:45:21 +02:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
|
2017-03-08 05:07:07 +01:00
|
|
|
/* read one more to get to text node */
|
2013-06-15 18:45:21 +02:00
|
|
|
if (type == XmlNodeType_Element)
|
|
|
|
{
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
}
|
2017-03-08 05:07:07 +01:00
|
|
|
ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
|
2013-06-15 18:45:21 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
const WCHAR *str;
|
|
|
|
UINT len;
|
|
|
|
|
|
|
|
ok(type == XmlNodeType_Text, "got %d for %s\n", type, test->xml);
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_name(reader, L"");
|
2013-06-15 18:45:21 +02:00
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetLocalName(reader, &str, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2017-03-10 09:06:40 +01:00
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
2013-06-15 18:45:21 +02:00
|
|
|
|
|
|
|
len = 1;
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2017-03-10 09:06:40 +01:00
|
|
|
ok(len == 0, "got %u\n", len);
|
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, NULL);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(*str == 0, "got %s\n", wine_dbgstr_w(str));
|
2013-06-15 18:45:21 +02:00
|
|
|
|
|
|
|
/* value */
|
2017-03-29 19:45:50 +02:00
|
|
|
reader_value(reader, test->value);
|
2013-06-15 18:45:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2013-06-15 19:53:33 +02:00
|
|
|
struct test_entry_empty {
|
|
|
|
const char *xml;
|
|
|
|
BOOL empty;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct test_entry_empty empty_element_tests[] = {
|
|
|
|
{ "<a></a>", FALSE },
|
|
|
|
{ "<a/>", TRUE },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_isemptyelement(void)
|
|
|
|
{
|
|
|
|
struct test_entry_empty *test = empty_element_tests;
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-06-15 19:53:33 +02:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
while (test->xml)
|
|
|
|
{
|
|
|
|
XmlNodeType type;
|
|
|
|
BOOL ret;
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-06-15 19:53:33 +02:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Element, "got %d\n", type);
|
|
|
|
|
|
|
|
ret = IXmlReader_IsEmptyElement(reader);
|
|
|
|
ok(ret == test->empty, "got %d, expected %d. xml=%s\n", ret, test->empty, test->xml);
|
|
|
|
|
|
|
|
test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:52:19 +01:00
|
|
|
static struct test_entry attributes_tests[] =
|
|
|
|
{
|
|
|
|
{ "<a attr1=\"attrvalue\"/>", L"attr1", L"attrvalue", S_OK },
|
|
|
|
{ "<a attr1=\"a\'\'ttrvalue\"/>", L"attr1", L"a\'\'ttrvalue", S_OK },
|
|
|
|
{ "<a attr1=\'a\"ttrvalue\'/>", L"attr1", L"a\"ttrvalue", S_OK },
|
|
|
|
{ "<a attr1=\' \'/>", L"attr1", L" ", S_OK },
|
|
|
|
{ "<a attr1=\" \"/>", L"attr1", L" ", S_OK },
|
|
|
|
{ "<a attr1=\"\r\n \r \n \t\n\r\"/>", L"attr1", L" ", S_OK },
|
|
|
|
{ "<a attr1=\" val \"/>", L"attr1", L" val ", S_OK },
|
|
|
|
{ "<a attr1=\"\r\n\tval\n\"/>", L"attr1", L" val ", S_OK },
|
|
|
|
{ "<a attr1=\"val \"/>", L"attr1", L"val ", S_OK },
|
|
|
|
{ "<a attr1=\"val \"/>", L"attr1", L"val ", S_OK },
|
|
|
|
{ "<a attr1=\"<>&'"\"/>", L"attr1", L"<>&\'\"", S_OK },
|
2013-08-20 12:07:32 +02:00
|
|
|
{ "<a attr1=\"&entname;\"/>", NULL, NULL, WC_E_UNDECLAREDENTITY },
|
2013-08-19 08:46:49 +02:00
|
|
|
{ "<a attr1=\"val\"/>", NULL, NULL, WC_E_XMLCHARACTER },
|
|
|
|
{ "<a attr1=\"val &#a;\"/>", NULL, NULL, WC_E_DIGIT, WC_E_SEMICOLON },
|
|
|
|
{ "<a attr1=\"val a;\"/>", NULL, NULL, WC_E_SEMICOLON },
|
|
|
|
{ "<a attr1=\"val g;\"/>", NULL, NULL, WC_E_SEMICOLON },
|
|
|
|
{ "<a attr1=\"val &#xg;\"/>", NULL, NULL, WC_E_HEXDIGIT, WC_E_SEMICOLON },
|
2013-07-30 12:59:28 +02:00
|
|
|
{ "<a attr1=attrvalue/>", NULL, NULL, WC_E_QUOTE },
|
|
|
|
{ "<a attr1=\"attr<value\"/>", NULL, NULL, WC_E_LESSTHAN },
|
2013-08-20 12:07:32 +02:00
|
|
|
{ "<a attr1=\"&entname\"/>", NULL, NULL, WC_E_SEMICOLON },
|
2013-07-30 12:59:28 +02:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_read_attribute(void)
|
|
|
|
{
|
|
|
|
struct test_entry *test = attributes_tests;
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-22 08:10:37 +01:00
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
2013-07-30 12:59:28 +02:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
while (test->xml)
|
|
|
|
{
|
|
|
|
XmlNodeType type;
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, test->xml);
|
2013-07-30 12:59:28 +02:00
|
|
|
|
2017-01-27 09:17:43 +01:00
|
|
|
hr = IXmlReader_Read(reader, NULL);
|
2013-07-30 12:59:28 +02:00
|
|
|
|
|
|
|
if (test->hr_broken)
|
|
|
|
ok(hr == test->hr || broken(hr == test->hr_broken), "got %08x for %s\n", hr, test->xml);
|
|
|
|
else
|
|
|
|
ok(hr == test->hr, "got %08x for %s\n", hr, test->xml);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
const WCHAR *str;
|
|
|
|
UINT len;
|
|
|
|
|
2017-01-27 09:17:43 +01:00
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "Failed to get node type, %#x\n", hr);
|
|
|
|
|
2013-07-30 12:59:28 +02:00
|
|
|
ok(type == XmlNodeType_Element, "got %d for %s\n", type, test->xml);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2017-03-29 19:46:02 +02:00
|
|
|
reader_name(reader, test->name);
|
2013-08-19 08:42:38 +02:00
|
|
|
|
2013-07-30 12:59:28 +02:00
|
|
|
len = 1;
|
|
|
|
str = NULL;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &str, &len);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(len == lstrlenW(test->name), "got %u\n", len);
|
|
|
|
ok(!lstrcmpW(str, test->name), "got %s\n", wine_dbgstr_w(str));
|
2017-03-07 04:50:58 +01:00
|
|
|
|
2013-07-30 12:59:28 +02:00
|
|
|
/* value */
|
2017-03-29 19:45:50 +02:00
|
|
|
reader_value(reader, test->value);
|
2013-07-30 12:59:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2016-10-27 17:34:53 +02:00
|
|
|
static void test_reader_properties(void)
|
|
|
|
{
|
|
|
|
IXmlReader *reader;
|
2017-03-07 04:50:59 +01:00
|
|
|
LONG_PTR value;
|
2016-10-27 17:34:53 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
value = 0;
|
|
|
|
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_MaxElementDepth, &value);
|
|
|
|
ok(hr == S_OK, "GetProperty failed: %08x\n", hr);
|
|
|
|
ok(value == 256, "Unexpected default max depth value %ld\n", value);
|
|
|
|
|
2016-10-27 17:34:53 +02:00
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_MultiLanguage, 0);
|
|
|
|
ok(hr == S_OK, "SetProperty failed: %08x\n", hr);
|
|
|
|
|
2016-10-27 17:34:56 +02:00
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_MaxElementDepth, 0);
|
|
|
|
ok(hr == S_OK, "SetProperty failed: %08x\n", hr);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
value = 256;
|
|
|
|
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_MaxElementDepth, &value);
|
|
|
|
ok(hr == S_OK, "GetProperty failed: %08x\n", hr);
|
|
|
|
ok(value == 0, "Unexpected max depth value %ld\n", value);
|
|
|
|
|
2016-10-27 17:34:53 +02:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:38:33 +01:00
|
|
|
static void test_prefix(void)
|
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const char *xml;
|
2020-02-07 15:52:19 +01:00
|
|
|
const WCHAR *prefix1;
|
|
|
|
const WCHAR *prefix2;
|
|
|
|
const WCHAR *prefix3;
|
2016-12-09 14:38:33 +01:00
|
|
|
} prefix_tests[] =
|
|
|
|
{
|
2020-02-07 15:52:19 +01:00
|
|
|
{ "<b xmlns=\"defns\" xml:a=\"a ns\"/>", L"", L"", L"xml" },
|
|
|
|
{ "<c:b xmlns:c=\"c ns\" xml:a=\"a ns\"/>", L"c", L"xmlns", L"xml" },
|
2016-12-09 14:38:33 +01:00
|
|
|
};
|
|
|
|
IXmlReader *reader;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2018-02-22 07:01:44 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(prefix_tests); i++) {
|
2016-12-09 14:38:33 +01:00
|
|
|
XmlNodeType type;
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, prefix_tests[i].xml);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "Read() failed, %#x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Element, "Unexpected node type %d.\n", type);
|
|
|
|
|
2017-03-29 19:46:19 +02:00
|
|
|
reader_prefix(reader, prefix_tests[i].prefix1);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
|
|
|
ok(hr == S_OK, "MoveToFirstAttribute() failed, %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "GetNodeType() failed, %#x.\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "Unexpected node type %d.\n", type);
|
|
|
|
|
2017-03-29 19:46:19 +02:00
|
|
|
reader_prefix(reader, prefix_tests[i].prefix2);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
2017-03-29 19:45:32 +02:00
|
|
|
next_attribute(reader);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_GetNodeType(reader, &type);
|
|
|
|
ok(hr == S_OK, "GetNodeType() failed, %#x.\n", hr);
|
|
|
|
ok(type == XmlNodeType_Attribute, "Unexpected node type %d.\n", type);
|
|
|
|
|
2017-03-29 19:46:19 +02:00
|
|
|
reader_prefix(reader, prefix_tests[i].prefix3);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
2017-03-07 04:50:57 +01:00
|
|
|
/* back to the element, check prefix */
|
2017-03-31 15:57:27 +02:00
|
|
|
move_to_element(reader);
|
2017-03-29 19:46:19 +02:00
|
|
|
reader_prefix(reader, prefix_tests[i].prefix1);
|
2016-12-09 14:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_namespaceuri(void)
|
|
|
|
{
|
|
|
|
struct uri_test
|
|
|
|
{
|
|
|
|
const char *xml;
|
2020-02-07 15:52:19 +01:00
|
|
|
const WCHAR *uri[5];
|
2016-12-09 14:38:33 +01:00
|
|
|
} uri_tests[] =
|
|
|
|
{
|
|
|
|
{ "<a xmlns=\"defns a\"><b xmlns=\"defns b\"><c xmlns=\"defns c\"/></b></a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"defns a", L"defns b", L"defns c", L"defns b", L"defns a" }},
|
2016-12-09 14:38:33 +01:00
|
|
|
{ "<r:a xmlns=\"defns a\" xmlns:r=\"ns r\"/>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"ns r" }},
|
2016-12-09 14:38:33 +01:00
|
|
|
{ "<r:a xmlns=\"defns a\" xmlns:r=\"ns r\"><b/></r:a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"ns r", L"defns a", L"ns r" }},
|
2016-12-09 14:38:33 +01:00
|
|
|
{ "<a xmlns=\"defns a\" xmlns:r=\"ns r\"><r:b/></a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"defns a", L"ns r", L"defns a" }},
|
2016-12-09 14:38:33 +01:00
|
|
|
{ "<a><b><c/></b></a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"", L"", L"", L"", L"" }},
|
2017-03-08 05:07:09 +01:00
|
|
|
{ "<a>text</a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"", L"", L"" }},
|
2017-03-08 05:07:09 +01:00
|
|
|
{ "<a>\r\n</a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"", L"", L"" }},
|
2017-03-08 05:07:09 +01:00
|
|
|
{ "<a><![CDATA[data]]></a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"", L"", L"" }},
|
2017-03-08 05:07:09 +01:00
|
|
|
{ "<?xml version=\"1.0\" ?><a/>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"", L"" }},
|
2017-03-08 05:07:09 +01:00
|
|
|
{ "<a><?pi ?></a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"", L"", L"" }},
|
2017-03-08 05:07:09 +01:00
|
|
|
{ "<a><!-- comment --></a>",
|
2020-02-07 15:52:19 +01:00
|
|
|
{ L"", L"", L"" }},
|
2016-12-09 14:38:33 +01:00
|
|
|
};
|
|
|
|
IXmlReader *reader;
|
|
|
|
XmlNodeType type;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void**)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2018-02-22 07:01:44 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(uri_tests); i++) {
|
2016-12-09 14:38:33 +01:00
|
|
|
unsigned int j = 0;
|
|
|
|
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, uri_tests[i].xml);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
2017-03-06 10:35:56 +01:00
|
|
|
type = ~0u;
|
2016-12-09 14:38:33 +01:00
|
|
|
while (IXmlReader_Read(reader, &type) == S_OK) {
|
2017-03-29 19:46:28 +02:00
|
|
|
const WCHAR *local, *qname;
|
2017-03-08 05:07:11 +01:00
|
|
|
UINT length, length2;
|
2016-12-09 14:38:33 +01:00
|
|
|
|
2017-03-08 05:07:09 +01:00
|
|
|
ok(type == XmlNodeType_Element ||
|
|
|
|
type == XmlNodeType_Text ||
|
|
|
|
type == XmlNodeType_CDATA ||
|
|
|
|
type == XmlNodeType_ProcessingInstruction ||
|
|
|
|
type == XmlNodeType_Comment ||
|
|
|
|
type == XmlNodeType_Whitespace ||
|
|
|
|
type == XmlNodeType_EndElement ||
|
|
|
|
type == XmlNodeType_XmlDeclaration, "Unexpected node type %d.\n", type);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
2017-03-08 05:07:10 +01:00
|
|
|
local = NULL;
|
|
|
|
length = 0;
|
|
|
|
hr = IXmlReader_GetLocalName(reader, &local, &length);
|
2016-12-09 14:38:33 +01:00
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
2017-03-08 05:07:10 +01:00
|
|
|
ok(local != NULL, "Unexpected NULL local name pointer\n");
|
|
|
|
|
2017-03-08 05:07:11 +01:00
|
|
|
qname = NULL;
|
|
|
|
length2 = 0;
|
|
|
|
hr = IXmlReader_GetQualifiedName(reader, &qname, &length2);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
ok(qname != NULL, "Unexpected NULL qualified name pointer\n");
|
|
|
|
|
|
|
|
if (type == XmlNodeType_Element ||
|
|
|
|
type == XmlNodeType_EndElement ||
|
|
|
|
type == XmlNodeType_ProcessingInstruction ||
|
|
|
|
type == XmlNodeType_XmlDeclaration)
|
2017-03-08 05:07:10 +01:00
|
|
|
{
|
|
|
|
ok(*local != 0, "Unexpected empty local name\n");
|
|
|
|
ok(length > 0, "Unexpected local name length\n");
|
2017-03-08 05:07:11 +01:00
|
|
|
|
|
|
|
ok(*qname != 0, "Unexpected empty qualified name\n");
|
|
|
|
ok(length2 > 0, "Unexpected qualified name length\n");
|
2017-03-08 05:07:10 +01:00
|
|
|
}
|
2016-12-09 14:38:33 +01:00
|
|
|
|
2017-03-29 19:46:28 +02:00
|
|
|
reader_namespace(reader, uri_tests[i].uri[j]);
|
2016-12-09 14:38:33 +01:00
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
2017-03-06 10:35:56 +01:00
|
|
|
ok(type == XmlNodeType_None, "Unexpected node type %d\n", type);
|
2016-12-09 14:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2017-02-05 23:19:30 +01:00
|
|
|
static void test_read_charref(void)
|
|
|
|
{
|
2017-03-20 14:01:11 +01:00
|
|
|
static const char testA[] = "<a b=\"c\">dză></a>";
|
|
|
|
static const WCHAR chardataW[] = {0x01f3,0x0103,'>',0};
|
2017-02-05 23:19:30 +01:00
|
|
|
const WCHAR *value;
|
|
|
|
IXmlReader *reader;
|
|
|
|
XmlNodeType type;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, testA);
|
2017-02-05 23:19:30 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Element, "Unexpected node type %d\n", type);
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Text, "Unexpected node type %d\n", type);
|
|
|
|
|
|
|
|
hr = IXmlReader_GetValue(reader, &value, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(!lstrcmpW(value, chardataW), "Text value : %s\n", wine_dbgstr_w(value));
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_EndElement, "Unexpected node type %d\n", type);
|
|
|
|
|
2017-03-20 14:01:11 +01:00
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_FALSE, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_None, "Unexpected node type %d\n", type);
|
|
|
|
|
2017-02-05 23:19:30 +01:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2017-03-06 10:35:55 +01:00
|
|
|
static void test_encoding_detection(void)
|
|
|
|
{
|
|
|
|
static const struct encoding_testW
|
|
|
|
{
|
|
|
|
WCHAR text[16];
|
|
|
|
}
|
|
|
|
encoding_testsW[] =
|
|
|
|
{
|
|
|
|
{ { '<','?','p','i',' ','?','>',0 } },
|
|
|
|
{ { '<','!','-','-',' ','c','-','-','>',0 } },
|
|
|
|
{ { 0xfeff,'<','a','/','>',0 } },
|
|
|
|
{ { '<','a','/','>',0 } },
|
|
|
|
};
|
|
|
|
static const char *encoding_testsA[] =
|
|
|
|
{
|
|
|
|
"<?pi ?>",
|
|
|
|
"<!-- comment -->",
|
|
|
|
"\xef\xbb\xbf<a/>", /* UTF-8 BOM */
|
|
|
|
"<a/>",
|
|
|
|
};
|
|
|
|
IXmlReader *reader;
|
|
|
|
XmlNodeType type;
|
|
|
|
IStream *stream;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
/* there's no way to query detected encoding back, so just verify that document is browsable */
|
|
|
|
|
2018-02-22 07:01:44 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(encoding_testsA); i++)
|
2017-03-06 10:35:55 +01:00
|
|
|
{
|
2017-07-20 18:47:08 +02:00
|
|
|
set_input_string(reader, encoding_testsA[i]);
|
2017-03-06 10:35:55 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type != XmlNodeType_None, "Unexpected node type %d\n", type);
|
|
|
|
}
|
|
|
|
|
2018-02-22 07:01:44 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(encoding_testsW); i++)
|
2017-03-06 10:35:55 +01:00
|
|
|
{
|
|
|
|
stream = create_stream_on_data(encoding_testsW[i].text, lstrlenW(encoding_testsW[i].text) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, (IUnknown *)stream);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "%u: got %08x\n", i, hr);
|
|
|
|
ok(type != XmlNodeType_None, "%u: unexpected node type %d\n", i, type);
|
|
|
|
|
|
|
|
IStream_Release(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2017-03-06 10:35:58 +01:00
|
|
|
static void test_eof_state(IXmlReader *reader, BOOL eof)
|
|
|
|
{
|
|
|
|
LONG_PTR state;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
ok(IXmlReader_IsEOF(reader) == eof, "Unexpected IsEOF() result\n");
|
|
|
|
hr = IXmlReader_GetProperty(reader, XmlReaderProperty_ReadState, &state);
|
|
|
|
ok(hr == S_OK, "GetProperty() failed, %#x\n", hr);
|
|
|
|
ok((state == XmlReadState_EndOfFile) == eof, "Unexpected EndOfFile state %ld\n", state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_endoffile(void)
|
|
|
|
{
|
|
|
|
IXmlReader *reader;
|
|
|
|
XmlNodeType type;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
test_eof_state(reader, FALSE);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, "<a/>");
|
2017-03-06 10:35:58 +01:00
|
|
|
|
|
|
|
test_eof_state(reader, FALSE);
|
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Element, "Unexpected type %d\n", type);
|
|
|
|
|
|
|
|
test_eof_state(reader, FALSE);
|
|
|
|
|
|
|
|
type = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_FALSE, "got %#x\n", hr);
|
|
|
|
ok(type == XmlNodeType_None, "Unexpected type %d\n", type);
|
|
|
|
|
|
|
|
test_eof_state(reader, TRUE);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
test_eof_state(reader, FALSE);
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
2017-03-20 14:01:00 +01:00
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, "<a/>text");
|
2017-03-20 14:01:00 +01:00
|
|
|
|
|
|
|
type = XmlNodeType_None;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %#x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Element, "Unexpected type %d\n", type);
|
|
|
|
|
|
|
|
test_eof_state(reader, FALSE);
|
|
|
|
|
|
|
|
type = XmlNodeType_Element;
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == WC_E_SYNTAX, "got %#x\n", hr);
|
|
|
|
ok(type == XmlNodeType_None, "Unexpected type %d\n", type);
|
|
|
|
|
|
|
|
test_eof_state(reader, FALSE);
|
|
|
|
|
|
|
|
hr = IXmlReader_SetInput(reader, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
2017-03-06 10:35:58 +01:00
|
|
|
}
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
static void test_max_element_depth(void)
|
|
|
|
{
|
|
|
|
static const char *xml =
|
|
|
|
"<a>"
|
|
|
|
"<b attrb=\"_b\">"
|
|
|
|
"<c>"
|
|
|
|
"<d></d>"
|
|
|
|
"</c>"
|
|
|
|
"</b>"
|
|
|
|
"</a>";
|
2017-03-13 10:27:54 +01:00
|
|
|
XmlNodeType nodetype;
|
2017-03-07 04:50:59 +01:00
|
|
|
unsigned int count;
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, xml);
|
2017-03-07 04:50:59 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_MaxElementDepth, 2);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH(reader, 0);
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH(reader, 0);
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH(reader, 1);
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_Interactive);
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, NULL);
|
|
|
|
ok(hr == SC_E_MAXELEMENTDEPTH, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH2(reader, 0, 2);
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_Error);
|
2017-03-13 10:27:54 +01:00
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_MaxElementDepth, 10);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, NULL);
|
|
|
|
ok(hr == SC_E_MAXELEMENTDEPTH, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH2(reader, 0, 2);
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_Error);
|
|
|
|
|
|
|
|
/* test if stepping into attributes enforces depth limit too */
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, xml);
|
2017-03-07 04:50:59 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_MaxElementDepth, 2);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH(reader, 0);
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH(reader, 0);
|
|
|
|
|
|
|
|
hr = IXmlReader_Read(reader, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH(reader, 1);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToFirstAttribute(reader);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
TEST_DEPTH(reader, 2);
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_Interactive);
|
|
|
|
|
2017-03-13 10:27:54 +01:00
|
|
|
nodetype = 123;
|
|
|
|
hr = IXmlReader_Read(reader, &nodetype);
|
2017-03-07 04:50:59 +01:00
|
|
|
ok(hr == SC_E_MAXELEMENTDEPTH, "got %08x\n", hr);
|
2017-03-13 10:27:54 +01:00
|
|
|
ok(nodetype == XmlNodeType_None, "got node type %d\n", nodetype);
|
2017-03-07 04:50:59 +01:00
|
|
|
|
2017-03-13 10:27:54 +01:00
|
|
|
nodetype = 123;
|
|
|
|
hr = IXmlReader_Read(reader, &nodetype);
|
|
|
|
ok(hr == SC_E_MAXELEMENTDEPTH, "got %08x\n", hr);
|
|
|
|
ok(nodetype == XmlNodeType_None, "got node type %d\n", nodetype);
|
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
TEST_DEPTH2(reader, 0, 2);
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_Error);
|
2017-03-13 10:27:54 +01:00
|
|
|
|
2017-03-07 04:50:59 +01:00
|
|
|
/* set max depth to 0, this disables depth limit */
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, xml);
|
2017-03-07 04:50:59 +01:00
|
|
|
|
|
|
|
hr = IXmlReader_SetProperty(reader, XmlReaderProperty_MaxElementDepth, 0);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
while (IXmlReader_Read(reader, NULL) == S_OK)
|
|
|
|
count++;
|
|
|
|
ok(count == 8, "Unexpected node number %u\n", count);
|
|
|
|
TEST_READER_STATE(reader, XmlReadState_EndOfFile);
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
static void test_reader_position(void)
|
|
|
|
{
|
2017-03-10 09:06:43 +01:00
|
|
|
static const char *xml = "<c:a xmlns:c=\"nsdef c\" b=\"attr b\">\n</c:a>";
|
2017-03-09 05:14:07 +01:00
|
|
|
IXmlReader *reader;
|
|
|
|
XmlNodeType type;
|
|
|
|
UINT position;
|
2017-03-09 05:14:09 +01:00
|
|
|
HRESULT hr;
|
2017-03-09 05:14:07 +01:00
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
2017-03-10 09:06:42 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Closed);
|
|
|
|
|
2017-03-09 05:14:07 +01:00
|
|
|
/* position methods with Null args */
|
|
|
|
hr = IXmlReader_GetLineNumber(reader, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_GetLinePosition(reader, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
|
|
|
|
|
|
|
|
position = 123;
|
|
|
|
hr = IXmlReader_GetLinePosition(reader, &position);
|
|
|
|
ok(hr == S_FALSE, "got %#x\n", hr);
|
|
|
|
ok(position == 0, "got %u\n", position);
|
|
|
|
|
|
|
|
position = 123;
|
|
|
|
hr = IXmlReader_GetLineNumber(reader, &position);
|
|
|
|
ok(hr == S_FALSE, "got %#x\n", hr);
|
|
|
|
ok(position == 0, "got %u\n", position);
|
|
|
|
|
2017-03-28 17:27:10 +02:00
|
|
|
set_input_string(reader, xml);
|
2017-03-09 05:14:07 +01:00
|
|
|
|
2017-03-10 09:06:42 +01:00
|
|
|
TEST_READER_STATE(reader, XmlReadState_Initial);
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION(reader, 0, 0);
|
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Element, "got type %d\n", type);
|
2017-03-09 05:14:09 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 2, ~0u, 34);
|
2017-03-09 05:14:07 +01:00
|
|
|
|
2017-03-29 19:45:32 +02:00
|
|
|
next_attribute(reader);
|
2017-03-09 05:14:09 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 6, ~0u, 34);
|
2017-03-09 05:14:07 +01:00
|
|
|
|
2017-03-29 19:45:32 +02:00
|
|
|
next_attribute(reader);
|
2017-03-09 05:14:09 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 24, ~0u, 34);
|
2017-03-09 05:14:07 +01:00
|
|
|
|
2017-03-31 15:57:27 +02:00
|
|
|
move_to_element(reader);
|
2017-03-09 05:14:09 +01:00
|
|
|
TEST_READER_POSITION2(reader, 1, 2, ~0u, 34);
|
|
|
|
|
2017-03-10 09:06:43 +01:00
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_Whitespace, "got type %d\n", type);
|
|
|
|
TEST_READER_POSITION2(reader, 1, 35, 2, 6);
|
|
|
|
|
2017-03-09 05:14:09 +01:00
|
|
|
hr = IXmlReader_Read(reader, &type);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
|
|
|
ok(type == XmlNodeType_EndElement, "got type %d\n", type);
|
2017-03-10 09:06:43 +01:00
|
|
|
TEST_READER_POSITION2(reader, 2, 3, 2, 6);
|
2017-03-09 05:14:07 +01:00
|
|
|
|
2017-03-20 06:30:48 +01:00
|
|
|
hr = IXmlReader_SetInput(reader, NULL);
|
|
|
|
ok(hr == S_OK, "got %08x\n", hr);
|
2017-03-10 09:06:42 +01:00
|
|
|
TEST_READER_STATE2(reader, XmlReadState_Initial, XmlReadState_Closed);
|
2017-03-09 05:14:07 +01:00
|
|
|
TEST_READER_POSITION(reader, 0, 0);
|
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2017-03-29 20:51:47 +02:00
|
|
|
static void test_string_pointers(void)
|
|
|
|
{
|
2017-03-31 15:58:21 +02:00
|
|
|
const WCHAR *ns, *nsq, *empty, *xmlns_ns, *xmlns_name, *name, *p, *q, *xml, *ptr, *value;
|
2017-03-29 20:51:47 +02:00
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "S_OK, got %08x\n", hr);
|
|
|
|
|
|
|
|
set_input_string(reader, "<elem xmlns=\"myns\">myns<elem2 /></elem>");
|
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
2020-02-07 15:52:19 +01:00
|
|
|
empty = reader_value(reader, L"");
|
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
name = reader_name(reader, L"elem");
|
|
|
|
ok(name == reader_qname(reader, L"elem"), "name != qname\n");
|
|
|
|
ns = reader_namespace(reader, L"myns");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
next_attribute(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
ptr = reader_value(reader, L"myns");
|
2017-03-29 20:51:47 +02:00
|
|
|
if (ns != ptr)
|
|
|
|
{
|
|
|
|
win_skip("attr value is different than namespace pointer, assuming old xmllite\n");
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok(ns == ptr, "ns != value\n");
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
xmlns_ns = reader_namespace(reader, L"http://www.w3.org/2000/xmlns/");
|
|
|
|
xmlns_name = reader_name(reader, L"xmlns");
|
|
|
|
ok(xmlns_name == reader_qname(reader, L"xmlns"), "xmlns_name != qname\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Text);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(ns != reader_value(reader, L"myns"), "ns == value\n");
|
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
ok(empty == reader_namespace(reader, L""), "empty != namespace\n");
|
|
|
|
ok(empty == reader_name(reader, L""), "empty != name\n");
|
|
|
|
ok(empty == reader_qname(reader, L""), "empty != qname\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
ok(ns == reader_namespace(reader, L"myns"), "empty != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_EndElement);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
ok(name == reader_name(reader, L"elem"), "empty != name\n");
|
|
|
|
ok(name == reader_qname(reader, L"elem"), "empty != qname\n");
|
|
|
|
ok(ns == reader_namespace(reader, L"myns"), "empty != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
set_input_string(reader, "<elem xmlns:p=\"myns\" xmlns:q=\"mynsq\"><p:elem2 q:attr=\"\"></p:elem2></elem>");
|
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
name = reader_name(reader, L"elem");
|
|
|
|
ok(empty == reader_namespace(reader, L""), "empty != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
next_attribute(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
ns = reader_value(reader, L"myns");
|
|
|
|
ok(xmlns_name == reader_prefix(reader, L"xmlns"), "xmlns_name != prefix\n");
|
|
|
|
p = reader_name(reader, L"p");
|
|
|
|
ok(xmlns_ns == reader_namespace(reader, L"http://www.w3.org/2000/xmlns/"), "xmlns_ns != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
next_attribute(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
nsq = reader_value(reader, L"mynsq");
|
|
|
|
ok(xmlns_name == reader_prefix(reader, L"xmlns"), "xmlns_name != prefix\n");
|
|
|
|
q = reader_name(reader, L"q");
|
|
|
|
ok(xmlns_ns == reader_namespace(reader, L"http://www.w3.org/2000/xmlns/"), "xmlns_ns != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(p == reader_prefix(reader, L"p"), "p != prefix\n");
|
|
|
|
ok(ns == reader_namespace(reader, L"myns"), "empty != namespace\n");
|
|
|
|
name = reader_qname(reader, L"p:elem2");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
next_attribute(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(empty != reader_value(reader, L""), "empty == value\n");
|
|
|
|
ok(q == reader_prefix(reader, L"q"), "q != prefix\n");
|
|
|
|
ok(nsq == reader_namespace(reader, L"mynsq"), "nsq != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_EndElement);
|
2020-02-07 15:52:19 +01:00
|
|
|
ptr = reader_qname(reader, L"p:elem2"); todo_wine ok(name != ptr, "q == qname\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
set_input_string(reader, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
|
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_XmlDeclaration);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(empty == reader_value(reader, L""), "empty != value\n");
|
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
xml = reader_name(reader, L"xml");
|
|
|
|
ptr = reader_qname(reader, L"xml"); todo_wine ok(xml == ptr, "xml != qname\n");
|
|
|
|
ok(empty == reader_namespace(reader, L""), "empty != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
next_attribute(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(empty == reader_prefix(reader, L""), "empty != prefix\n");
|
|
|
|
ok(empty == reader_namespace(reader, L""), "empty != namespace\n");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
set_input_string(reader, "<elem xmlns:p=\"myns\"><p:elem2 attr=\"\" /></elem>");
|
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
|
|
|
next_attribute(reader);
|
|
|
|
read_value_char(reader, 'm');
|
2020-02-07 15:52:19 +01:00
|
|
|
p = reader_value(reader, L"yns");
|
2017-03-29 20:51:47 +02:00
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
2020-02-07 15:52:19 +01:00
|
|
|
ns = reader_namespace(reader, L"myns");
|
2017-03-29 20:51:47 +02:00
|
|
|
ok(ns+1 == p, "ns+1 != p\n");
|
|
|
|
|
2017-03-31 15:57:51 +02:00
|
|
|
set_input_string(reader, "<elem attr=\"value\"></elem>");
|
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
|
|
|
next_attribute(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
name = reader_name(reader, L"attr");
|
|
|
|
value = reader_value(reader, L"value");
|
2017-03-31 15:57:51 +02:00
|
|
|
|
|
|
|
move_to_element(reader);
|
|
|
|
next_attribute(reader);
|
2020-02-07 15:52:19 +01:00
|
|
|
ok(name == reader_name(reader, L"attr"), "attr pointer changed\n");
|
|
|
|
ok(value == reader_value(reader, L"value"), "value pointer changed\n");
|
2017-03-31 15:57:51 +02:00
|
|
|
|
2017-03-29 20:51:47 +02:00
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:00:03 +02:00
|
|
|
static void test_attribute_by_name(void)
|
|
|
|
{
|
|
|
|
static const char *xml = "<a><elem xmlns=\"myns\" a=\"value a\" b=\"value b\" xmlns:ns=\"ns uri\" "
|
|
|
|
"ns:c=\"value c\" c=\"value c2\"/></a>";
|
|
|
|
static const WCHAR xmlns_uriW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','3','.','o','r','g','/',
|
|
|
|
'2','0','0','0','/','x','m','l','n','s','/',0};
|
|
|
|
static const WCHAR nsuriW[] = {'n','s',' ','u','r','i',0};
|
|
|
|
static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
|
|
|
|
static const WCHAR mynsW[] = {'m','y','n','s',0};
|
|
|
|
static const WCHAR nsW[] = {'n','s',0};
|
|
|
|
static const WCHAR emptyW[] = {0};
|
|
|
|
static const WCHAR aW[] = {'a',0};
|
|
|
|
static const WCHAR bW[] = {'b',0};
|
|
|
|
static const WCHAR cW[] = {'c',0};
|
|
|
|
IXmlReader *reader;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = CreateXmlReader(&IID_IXmlReader, (void **)&reader, NULL);
|
|
|
|
ok(hr == S_OK, "Failed to create reader, hr %#x.\n", hr);
|
|
|
|
|
|
|
|
set_input_string(reader, xml);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, NULL, NULL);
|
|
|
|
ok(hr == E_INVALIDARG || broken(hr == S_FALSE) /* WinXP */, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, emptyW, NULL);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, emptyW, NULL);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
read_node(reader, XmlNodeType_Element);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, NULL, NULL);
|
|
|
|
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, NULL, xmlns_uriW);
|
|
|
|
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, emptyW, xmlns_uriW);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, xmlnsW, NULL);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, xmlnsW, xmlns_uriW);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"myns");
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, aW, NULL);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"value a");
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, bW, NULL);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"value b");
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, aW, mynsW);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, nsW, NULL);
|
|
|
|
ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
|
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, nsW, xmlns_uriW);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"ns uri");
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, bW, emptyW);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"value b");
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, cW, NULL);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"value c2");
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
hr = IXmlReader_MoveToAttributeByName(reader, cW, nsuriW);
|
|
|
|
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
|
2020-02-07 15:52:19 +01:00
|
|
|
reader_value(reader, L"value c");
|
2017-07-21 14:00:03 +02:00
|
|
|
|
|
|
|
IXmlReader_Release(reader);
|
|
|
|
}
|
|
|
|
|
2010-01-18 22:05:53 +01:00
|
|
|
START_TEST(reader)
|
|
|
|
{
|
|
|
|
test_reader_create();
|
2010-01-21 15:47:03 +01:00
|
|
|
test_readerinput();
|
2010-01-23 21:03:14 +01:00
|
|
|
test_reader_state();
|
2013-07-30 12:59:28 +02:00
|
|
|
test_read_attribute();
|
2013-03-10 15:29:43 +01:00
|
|
|
test_read_cdata();
|
2012-12-19 06:30:44 +01:00
|
|
|
test_read_comment();
|
2013-01-05 23:08:27 +01:00
|
|
|
test_read_pi();
|
2016-11-22 15:57:20 +01:00
|
|
|
test_read_system_dtd();
|
|
|
|
test_read_public_dtd();
|
2013-01-18 07:04:27 +01:00
|
|
|
test_read_element();
|
2013-06-15 19:53:33 +02:00
|
|
|
test_isemptyelement();
|
2013-06-15 18:45:21 +02:00
|
|
|
test_read_text();
|
2013-01-13 19:36:30 +01:00
|
|
|
test_read_full();
|
2013-01-27 08:17:27 +01:00
|
|
|
test_read_pending();
|
2013-02-11 06:22:23 +01:00
|
|
|
test_readvaluechunk();
|
2010-01-25 19:55:02 +01:00
|
|
|
test_read_xmldeclaration();
|
2016-10-27 17:34:53 +02:00
|
|
|
test_reader_properties();
|
2016-12-09 14:38:33 +01:00
|
|
|
test_prefix();
|
|
|
|
test_namespaceuri();
|
2017-02-05 23:19:30 +01:00
|
|
|
test_read_charref();
|
2017-03-06 10:35:55 +01:00
|
|
|
test_encoding_detection();
|
2017-03-06 10:35:58 +01:00
|
|
|
test_endoffile();
|
2017-03-07 04:50:59 +01:00
|
|
|
test_max_element_depth();
|
2017-03-09 05:14:07 +01:00
|
|
|
test_reader_position();
|
2017-03-29 20:51:47 +02:00
|
|
|
test_string_pointers();
|
2017-07-21 14:00:03 +02:00
|
|
|
test_attribute_by_name();
|
2010-01-18 22:05:53 +01:00
|
|
|
}
|