From 86738d095df8d4a28e46cb115787e2eba7bf48f8 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 28 Apr 2017 12:12:49 +0200 Subject: [PATCH] webservices: Implement WsWriteBytes. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/webservices/tests/writer.c | 68 +++++++++++++++++++++++++++++++ dlls/webservices/webservices.spec | 2 +- dlls/webservices/writer.c | 40 ++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/dlls/webservices/tests/writer.c b/dlls/webservices/tests/writer.c index 3d0124544aa..d53cb13c063 100644 --- a/dlls/webservices/tests/writer.c +++ b/dlls/webservices/tests/writer.c @@ -3114,6 +3114,73 @@ static void test_WsWriteQualifiedName(void) WsFreeWriter( writer ); } +static void test_WsWriteBytes(void) +{ + WS_XML_STRING localname = {1, (BYTE *)"t"}, localname2 = {1, (BYTE *)"a"}, ns = {0, NULL}; + WS_XML_WRITER *writer; + HRESULT hr; + + hr = WsWriteBytes( 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 = WsWriteBytes( writer, NULL, 0, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsWriteBytes( writer, "test", 0, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsWriteBytes( writer, NULL, 1, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsWriteBytes( 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 = WsWriteBytes( 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 = WsWriteBytes( 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, "dGVzdAA=", __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 = WsWriteBytes( 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(); @@ -3148,4 +3215,5 @@ START_TEST(writer) test_datetime(); test_repeating_element(); test_WsWriteQualifiedName(); + test_WsWriteBytes(); } diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec index 1ef8aaeb0fe..304e917c25a 100644 --- a/dlls/webservices/webservices.spec +++ b/dlls/webservices/webservices.spec @@ -167,7 +167,7 @@ @ stdcall WsWriteArray(ptr ptr ptr long ptr long long long ptr) @ stdcall WsWriteAttribute(ptr ptr long ptr long ptr) @ stdcall WsWriteBody(ptr ptr long ptr long ptr) -@ stub WsWriteBytes +@ stdcall WsWriteBytes(ptr ptr long ptr) @ stub WsWriteChars @ stub WsWriteCharsUtf8 @ stdcall WsWriteElement(ptr ptr long ptr long ptr) diff --git a/dlls/webservices/writer.c b/dlls/webservices/writer.c index 4fd112642f2..059acb0875f 100644 --- a/dlls/webservices/writer.c +++ b/dlls/webservices/writer.c @@ -1697,6 +1697,7 @@ HRESULT WINAPI WsWriteText( WS_XML_WRITER *handle, const WS_XML_TEXT *text, WS_E HRESULT hr; TRACE( "%p %p %p\n", handle, text, error ); + if (error) FIXME( "ignoring error parameter\n" ); if (!writer || !text) return E_INVALIDARG; @@ -1715,6 +1716,45 @@ HRESULT WINAPI WsWriteText( WS_XML_WRITER *handle, const WS_XML_TEXT *text, WS_E return hr; } +/************************************************************************** + * WsWriteBytes [webservices.@] + */ +HRESULT WINAPI WsWriteBytes( WS_XML_WRITER *handle, const void *bytes, ULONG count, WS_ERROR *error ) +{ + struct writer *writer = (struct writer *)handle; + WS_XML_BASE64_TEXT base64; + HRESULT hr; + + TRACE( "%p %p %u %p\n", handle, bytes, 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; + } + + base64.text.textType = WS_XML_TEXT_TYPE_BASE64; + base64.bytes = (BYTE *)bytes; + base64.length = count; + + if (writer->state == WRITER_STATE_STARTATTRIBUTE) hr = write_set_attribute_value( writer, &base64.text ); + else hr = write_text_node( writer, &base64.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)