webservices: Implement WsReadStartElement.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2015-10-09 10:19:29 +02:00 committed by Alexandre Julliard
parent 3ec48f1d9d
commit bac2d5c37f
3 changed files with 165 additions and 1 deletions

View File

@ -557,6 +557,20 @@ static WS_XML_STRING *alloc_xml_string( const char *data, ULONG len )
return ret;
}
static WS_XML_UTF8_TEXT *alloc_utf8_text( const char *data, ULONG len )
{
WS_XML_UTF8_TEXT *ret;
if (!(ret = heap_alloc( sizeof(*ret) + len ))) return NULL;
ret->text.textType = WS_XML_TEXT_TYPE_UTF8;
ret->value.length = len;
ret->value.bytes = (BYTE *)(ret + 1);
ret->value.dictionary = NULL;
ret->value.id = 0;
if (data) memcpy( ret->value.bytes, data, len );
return ret;
}
static inline BOOL read_end_of_data( struct reader *reader )
{
return reader->read_pos >= reader->read_size;
@ -749,6 +763,45 @@ error:
return hr;
}
static HRESULT read_text( struct reader *reader )
{
unsigned int len = 0, ch, skip;
const char *start;
struct node *node;
WS_XML_TEXT_NODE *text;
WS_XML_UTF8_TEXT *utf8;
start = read_current_ptr( reader );
for (;;)
{
if (read_end_of_data( reader )) break;
if (!(ch = read_utf8_char( reader, &skip ))) return WS_E_INVALID_FORMAT;
if (ch == '<') break;
read_skip( reader, skip );
len += skip;
}
if (!(node = alloc_node( WS_XML_NODE_TYPE_TEXT ))) return E_OUTOFMEMORY;
text = (WS_XML_TEXT_NODE *)node;
if (!(utf8 = alloc_utf8_text( start, len )))
{
heap_free( node );
return E_OUTOFMEMORY;
}
text->text = (WS_XML_TEXT *)utf8;
list_add_after( &reader->current->entry, &node->entry );
reader->current = node;
reader->state = READER_STATE_TEXT;
return S_OK;
}
static HRESULT read_startelement( struct reader *reader )
{
if (!read_cmp( reader, "<", 1 )) return read_element( reader );
return read_text( reader );
}
static HRESULT read_to_startelement( struct reader *reader, BOOL *found )
{
HRESULT hr;
@ -780,6 +833,20 @@ static HRESULT read_to_startelement( struct reader *reader, BOOL *found )
return hr;
}
/**************************************************************************
* WsReadStartElement [webservices.@]
*/
HRESULT WINAPI WsReadStartElement( WS_XML_READER *handle, WS_ERROR *error )
{
struct reader *reader = (struct reader *)handle;
TRACE( "%p %p\n", handle, error );
if (error) FIXME( "ignoring error parameter\n" );
if (!reader) return E_INVALIDARG;
return read_startelement( reader );
}
/**************************************************************************
* WsReadToStartElement [webservices.@]
*/

View File

@ -45,6 +45,9 @@ static const char data4[] =
"</o:services>\r\n"
"</o:OfficeConfig>\r\n";
static const char data8[] =
"<node1><node2>test</node2></node1>";
static void test_WsCreateError(void)
{
HRESULT hr;
@ -598,6 +601,99 @@ static void test_WsReadToStartElement(void)
WsFreeReader( reader );
}
static void test_WsReadStartElement(void)
{
HRESULT hr;
WS_XML_READER *reader;
const WS_XML_NODE *node, *node2;
int found;
hr = WsCreateReader( NULL, 0, &reader, NULL ) ;
ok( hr == S_OK, "got %08x\n", hr );
hr = set_input( reader, data2, sizeof(data2) - 1 );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsFillReader( reader, sizeof(data2) - 1, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
found = -1;
hr = WsReadToStartElement( reader, NULL, NULL, &found, NULL );
ok( hr == S_OK, "got %08x\n", hr );
ok( found == TRUE, "got %d\n", found );
hr = WsReadStartElement( NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsGetReaderNode( reader, &node, NULL );
ok( hr == S_OK, "got %08x\n", hr );
if (node) ok( node->nodeType == WS_XML_NODE_TYPE_ELEMENT, "got %u\n", node->nodeType );
hr = WsReadStartElement( reader, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsGetReaderNode( reader, &node, NULL );
ok( hr == S_OK, "got %08x\n", hr );
if (node)
{
WS_XML_TEXT_NODE *text = (WS_XML_TEXT_NODE *)node;
ok( text->node.nodeType == WS_XML_NODE_TYPE_TEXT, "got %u\n", text->node.nodeType );
ok( text->text != NULL, "text not set\n" );
if (text->text)
{
WS_XML_UTF8_TEXT *utf8 = (WS_XML_UTF8_TEXT *)text->text;
ok( text->text->textType == WS_XML_TEXT_TYPE_UTF8, "got %u\n", text->text->textType );
ok( utf8->value.length == 4, "got %u\n", utf8->value.length );
ok( !memcmp( utf8->value.bytes, "test", 4 ), "wrong data\n" );
}
}
hr = WsReadStartElement( reader, NULL );
ok( hr == WS_E_INVALID_FORMAT, "got %08x\n", hr );
node2 = NULL;
hr = WsGetReaderNode( reader, &node2, NULL );
ok( hr == S_OK, "got %08x\n", hr );
ok( node2 == node, "different node\n" );
hr = set_input( reader, data8, sizeof(data8) - 1 );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsFillReader( reader, sizeof(data8) - 1, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
found = -1;
hr = WsReadToStartElement( reader, NULL, NULL, &found, NULL );
ok( hr == S_OK, "got %08x\n", hr );
ok( found == TRUE, "got %d\n", found );
hr = WsGetReaderNode( reader, &node, NULL );
ok( hr == S_OK, "got %08x\n", hr );
if (node) ok( node->nodeType == WS_XML_NODE_TYPE_ELEMENT, "got %u\n", node->nodeType );
hr = WsGetReaderNode( reader, &node, NULL );
ok( hr == S_OK, "got %08x\n", hr );
if (node)
{
WS_XML_ELEMENT_NODE *elem = (WS_XML_ELEMENT_NODE *)node;
ok( node->nodeType == WS_XML_NODE_TYPE_ELEMENT, "got %u\n", node->nodeType );
ok( !memcmp( elem->localName->bytes, "node1", 5), "wrong name\n" );
}
hr = WsReadStartElement( reader, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsGetReaderNode( reader, &node, NULL );
ok( hr == S_OK, "got %08x\n", hr );
if (node)
{
WS_XML_ELEMENT_NODE *elem = (WS_XML_ELEMENT_NODE *)node;
ok( node->nodeType == WS_XML_NODE_TYPE_ELEMENT, "got %u\n", node->nodeType );
ok( !memcmp( elem->localName->bytes, "node2", 5), "wrong name\n" );
}
WsFreeReader( reader );
}
START_TEST(reader)
{
test_WsCreateError();
@ -606,4 +702,5 @@ START_TEST(reader)
test_WsSetInput();
test_WsFillReader();
test_WsReadToStartElement();
test_WsReadStartElement();
}

View File

@ -119,7 +119,7 @@
@ stub WsReadNode
@ stub WsReadQualifiedName
@ stub WsReadStartAttribute
@ stub WsReadStartElement
@ stdcall WsReadStartElement(ptr ptr)
@ stdcall WsReadToStartElement(ptr ptr ptr ptr ptr)
@ stub WsReadType
@ stub WsReadValue