Hans Leidekker : webservices: Implement WsReadCharsUtf8.
Alexandre Julliard
julliard at winehq.org
Tue Oct 25 14:58:22 CDT 2016
Module: wine
Branch: master
Commit: ec30db2e01c029b543acd16b3093c93a22886d24
URL: http://source.winehq.org/git/wine.git/?a=commit;h=ec30db2e01c029b543acd16b3093c93a22886d24
Author: Hans Leidekker <hans at codeweavers.com>
Date: Tue Oct 25 13:03:19 2016 +0200
webservices: Implement WsReadCharsUtf8.
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/webservices/reader.c | 29 ++++++++++
dlls/webservices/tests/reader.c | 118 ++++++++++++++++++++++++++++++++++++++
dlls/webservices/webservices.spec | 2 +-
3 files changed, 148 insertions(+), 1 deletion(-)
diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c
index 9a3c7d7..44f8402 100644
--- a/dlls/webservices/reader.c
+++ b/dlls/webservices/reader.c
@@ -4582,3 +4582,32 @@ HRESULT WINAPI WsReadBytes( WS_XML_READER *handle, void *bytes, ULONG max_count,
return S_OK;
}
+
+/**************************************************************************
+ * WsReadCharsUtf8 [webservices.@]
+ */
+HRESULT WINAPI WsReadCharsUtf8( WS_XML_READER *handle, BYTE *bytes, ULONG max_count, ULONG *count, WS_ERROR *error )
+{
+ struct reader *reader = (struct reader *)handle;
+
+ TRACE( "%p %p %u %p %p\n", handle, bytes, max_count, count, error );
+ if (error) FIXME( "ignoring error parameter\n" );
+
+ if (!reader) return E_INVALIDARG;
+ if (!reader->input_type) return WS_E_INVALID_OPERATION;
+ if (!count) return E_INVALIDARG;
+
+ *count = 0;
+ if (node_type( reader->current ) == WS_XML_NODE_TYPE_TEXT && bytes)
+ {
+ const WS_XML_TEXT_NODE *text = (const WS_XML_TEXT_NODE *)reader->current;
+ const WS_XML_UTF8_TEXT *utf8 = (const WS_XML_UTF8_TEXT *)text->text;
+
+ if (reader->text_conv_offset == utf8->value.length) return read_node( reader );
+ *count = min( utf8->value.length - reader->text_conv_offset, max_count );
+ memcpy( bytes, utf8->value.bytes + reader->text_conv_offset, *count );
+ reader->text_conv_offset += *count;
+ }
+
+ return S_OK;
+}
diff --git a/dlls/webservices/tests/reader.c b/dlls/webservices/tests/reader.c
index c804105..330eb00 100644
--- a/dlls/webservices/tests/reader.c
+++ b/dlls/webservices/tests/reader.c
@@ -3978,6 +3978,123 @@ static void test_WsReadBytes(void)
WsFreeReader( reader );
}
+static void test_WsReadCharsUtf8(void)
+{
+ HRESULT hr;
+ WS_XML_READER *reader;
+ const WS_XML_NODE *node;
+ const WS_XML_TEXT_NODE *text;
+ const WS_XML_UTF8_TEXT *utf8;
+ BYTE buf[4];
+ ULONG count;
+
+ hr = WsCreateReader( NULL, 0, &reader, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ hr = WsReadCharsUtf8( NULL, NULL, 0, NULL, NULL );
+ ok( hr == E_INVALIDARG, "got %08x\n", hr );
+
+ hr = WsReadCharsUtf8( reader, NULL, 0, NULL, NULL );
+ ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
+
+ hr = set_input( reader, "<t>text</t>", sizeof("<t>text</t>") - 1 );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ hr = WsReadCharsUtf8( reader, NULL, 0, NULL, NULL );
+ ok( hr == E_INVALIDARG, "got %08x\n", hr );
+
+ hr = set_input( reader, "<t>text</t>", sizeof("<t>text</t>") - 1 );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ hr = WsReadCharsUtf8( reader, buf, 0, NULL, NULL );
+ ok( hr == E_INVALIDARG, "got %08x\n", hr );
+
+ hr = set_input( reader, "<t>text</t>", sizeof("<t>text</t>") - 1 );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, NULL, 0, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !count, "got %u\n", count );
+
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, NULL, 1, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !count, "got %u\n", count );
+
+ buf[0] = 0;
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, buf, 0, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !count, "got %u\n", count );
+ ok( !buf[0], "wrong data\n" );
+
+ buf[0] = 0;
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, buf, 2, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !count, "got %u\n", count );
+ ok( !buf[0], "wrong data\n" );
+
+ hr = WsReadToStartElement( reader, NULL, NULL, NULL, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ buf[0] = 0;
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, buf, 2, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !count, "got %u\n", count );
+ ok( !buf[0], "wrong data\n" );
+
+ hr = WsReadStartElement( reader, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, NULL, 0, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !count, "got %u\n", count );
+
+ buf[0] = 0;
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, buf, 2, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( count == 2, "got %u\n", count );
+ ok( !memcmp( buf, "te", 2 ), "wrong data\n" );
+
+ hr = WsGetReaderNode( reader, &node, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ text = (const WS_XML_TEXT_NODE *)node;
+ ok( text->node.nodeType == WS_XML_NODE_TYPE_TEXT, "got %u\n", text->node.nodeType );
+ utf8 = (const 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, "text", 4 ), "wrong data\n" );
+
+ buf[0] = 0;
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, buf, 2, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( count == 2, "got %u\n", count );
+ ok( !memcmp( buf, "xt", 2 ), "wrong data\n" );
+
+ hr = WsGetReaderNode( reader, &node, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ text = (const WS_XML_TEXT_NODE *)node;
+ ok( text->node.nodeType == WS_XML_NODE_TYPE_TEXT, "got %u\n", text->node.nodeType );
+
+ count = 0xdeadbeef;
+ hr = WsReadCharsUtf8( reader, buf, 1, &count, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ ok( !count, "got %u\n", count );
+
+ hr = WsGetReaderNode( reader, &node, NULL );
+ ok( hr == S_OK, "got %08x\n", hr );
+ text = (const WS_XML_TEXT_NODE *)node;
+ ok( text->node.nodeType == WS_XML_NODE_TYPE_END_ELEMENT, "got %u\n", text->node.nodeType );
+
+ WsFreeReader( reader );
+}
+
START_TEST(reader)
{
test_WsCreateError();
@@ -4015,4 +4132,5 @@ START_TEST(reader)
test_entities();
test_field_options();
test_WsReadBytes();
+ test_WsReadCharsUtf8();
}
diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec
index 26db0b2..e785497 100644
--- a/dlls/webservices/webservices.spec
+++ b/dlls/webservices/webservices.spec
@@ -106,7 +106,7 @@
@ stdcall WsReadBody(ptr ptr long ptr ptr long ptr)
@ stdcall WsReadBytes(ptr ptr long ptr ptr)
@ stub WsReadChars
-@ stub WsReadCharsUtf8
+@ stdcall WsReadCharsUtf8(ptr ptr long ptr ptr)
@ stdcall WsReadElement(ptr ptr long ptr ptr long ptr)
@ stdcall WsReadEndAttribute(ptr ptr)
@ stdcall WsReadEndElement(ptr ptr)
More information about the wine-cvs
mailing list