From ba014d9998c9e235f52b59abb67aff17d4647cf0 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 28 Apr 2017 12:12:51 +0200 Subject: [PATCH] webservices: Implement WsWriteCharsUtf8. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/webservices/tests/writer.c | 75 +++++++++++++++++++++++++++++++ dlls/webservices/webservices.spec | 2 +- dlls/webservices/writer.c | 39 ++++++++++++++++ include/webservices.h | 1 + 4 files changed, 116 insertions(+), 1 deletion(-) diff --git a/dlls/webservices/tests/writer.c b/dlls/webservices/tests/writer.c index d0e5dee5dc8..1d1ed047069 100644 --- a/dlls/webservices/tests/writer.c +++ b/dlls/webservices/tests/writer.c @@ -3255,6 +3255,80 @@ static void test_WsWriteChars(void) WsFreeWriter( writer ); } +static void test_WsWriteCharsUtf8(void) +{ + WS_XML_STRING localname = {1, (BYTE *)"t"}, localname2 = {1, (BYTE *)"a"}, ns = {0, NULL}; + static const BYTE test[] = {'t','e','s','t'}; + WS_XML_WRITER *writer; + HRESULT hr; + + hr = WsWriteCharsUtf8( NULL, NULL, 0, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = WsCreateWriter( NULL, 0, &writer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, NULL, 0, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, test, 0, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, NULL, 1, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, test, sizeof(test), NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = set_output( writer ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, test, sizeof(test), NULL ); + ok( hr == WS_E_INVALID_FORMAT, "got %08x\n", hr ); + + hr = set_output( writer ); + ok( hr == S_OK, "got %08x\n", hr ); + + /* element */ + hr = WsWriteStartElement( writer, NULL, &localname, &ns, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, test, sizeof(test), NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, test, sizeof(test), NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteEndElement( writer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + check_output( writer, "testtest", __LINE__ ); + + hr = set_output( writer ); + ok( hr == S_OK, "got %08x\n", hr ); + + /* attribute */ + hr = WsWriteStartElement( writer, NULL, &localname, &ns, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteStartAttribute( writer, NULL, &localname2, &ns, FALSE, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, test, sizeof(test), NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteCharsUtf8( writer, test, sizeof(test), NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteEndAttribute( writer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteEndElement( writer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + check_output( writer, "", __LINE__ ); + + WsFreeWriter( writer ); +} + START_TEST(writer) { test_WsCreateWriter(); @@ -3291,4 +3365,5 @@ START_TEST(writer) test_WsWriteQualifiedName(); test_WsWriteBytes(); test_WsWriteChars(); + test_WsWriteCharsUtf8(); } diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec index dbed69845e9..728457c934f 100644 --- a/dlls/webservices/webservices.spec +++ b/dlls/webservices/webservices.spec @@ -169,7 +169,7 @@ @ stdcall WsWriteBody(ptr ptr long ptr long ptr) @ stdcall WsWriteBytes(ptr ptr long ptr) @ stdcall WsWriteChars(ptr ptr long ptr) -@ stub WsWriteCharsUtf8 +@ stdcall WsWriteCharsUtf8(ptr ptr long ptr) @ stdcall WsWriteElement(ptr ptr long ptr long ptr) @ stdcall WsWriteEndAttribute(ptr ptr) @ stdcall WsWriteEndCData(ptr ptr) diff --git a/dlls/webservices/writer.c b/dlls/webservices/writer.c index f094885e8e9..81e21e54f8e 100644 --- a/dlls/webservices/writer.c +++ b/dlls/webservices/writer.c @@ -1794,6 +1794,45 @@ HRESULT WINAPI WsWriteChars( WS_XML_WRITER *handle, const WCHAR *chars, ULONG co return hr; } +/************************************************************************** + * WsWriteCharsUtf8 [webservices.@] + */ +HRESULT WINAPI WsWriteCharsUtf8( WS_XML_WRITER *handle, const BYTE *bytes, ULONG count, WS_ERROR *error ) +{ + struct writer *writer = (struct writer *)handle; + WS_XML_UTF8_TEXT utf8; + HRESULT hr; + + TRACE( "%p %s %u %p\n", handle, debugstr_an((const char *)bytes, count), count, error ); + if (error) FIXME( "ignoring error parameter\n" ); + + if (!writer) return E_INVALIDARG; + + EnterCriticalSection( &writer->cs ); + + if (writer->magic != WRITER_MAGIC) + { + LeaveCriticalSection( &writer->cs ); + return E_INVALIDARG; + } + + if (!writer->output_type) + { + LeaveCriticalSection( &writer->cs ); + return WS_E_INVALID_OPERATION; + } + + utf8.text.textType = WS_XML_TEXT_TYPE_UTF8; + utf8.value.bytes = (BYTE *)bytes; + utf8.value.length = count; + + if (writer->state == WRITER_STATE_STARTATTRIBUTE) hr = write_set_attribute_value( writer, &utf8.text ); + else hr = write_text_node( writer, &utf8.text ); + + LeaveCriticalSection( &writer->cs ); + return hr; +} + static HRESULT write_type_text( struct writer *writer, WS_TYPE_MAPPING mapping, const WS_XML_TEXT *text ) { switch (mapping) diff --git a/include/webservices.h b/include/webservices.h index 64c8e35de1a..c5aa3ecc475 100644 --- a/include/webservices.h +++ b/include/webservices.h @@ -1667,6 +1667,7 @@ HRESULT WINAPI WsWriteBody(WS_MESSAGE*, const WS_ELEMENT_DESCRIPTION*, WS_WRITE_ ULONG, WS_ERROR*); HRESULT WINAPI WsWriteBytes(WS_XML_WRITER*, const void*, ULONG, WS_ERROR*); HRESULT WINAPI WsWriteChars(WS_XML_WRITER*, const WCHAR*, ULONG, WS_ERROR*); +HRESULT WINAPI WsWriteCharsUtf8(WS_XML_WRITER*, const BYTE*, ULONG, WS_ERROR*); HRESULT WINAPI WsWriteElement(WS_XML_WRITER*, const WS_ELEMENT_DESCRIPTION*, WS_WRITE_OPTION, const void*, ULONG, WS_ERROR*); HRESULT WINAPI WsWriteEndAttribute(WS_XML_WRITER*, WS_ERROR*);