From db591a05832873436dff6f1d4178174f3f5cf789 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Wed, 3 Feb 2016 15:43:47 +0100 Subject: [PATCH] webservices: Implement WsWriteStartCData and WsWriteEndCData. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/webservices/tests/writer.c | 53 +++++++++++++++++++++++++++++-- dlls/webservices/webservices.spec | 4 +-- dlls/webservices/writer.c | 49 ++++++++++++++++++++++++++-- include/webservices.h | 2 ++ 4 files changed, 102 insertions(+), 6 deletions(-) diff --git a/dlls/webservices/tests/writer.c b/dlls/webservices/tests/writer.c index a4d19733ead..2bbedf786ac 100644 --- a/dlls/webservices/tests/writer.c +++ b/dlls/webservices/tests/writer.c @@ -971,6 +971,54 @@ static void test_WsWriteAttribute(void) WsFreeWriter( writer ); } +static void test_WsWriteStartCData(void) +{ + HRESULT hr; + WS_XML_WRITER *writer; + WS_XML_STRING localname = {1, (BYTE *)"t"}, ns = {0, NULL}; + WS_XML_UTF8_TEXT text; + + hr = WsCreateWriter( NULL, 0, &writer, NULL ) ; + ok( hr == S_OK, "got %08x\n", hr ); + + hr = set_output( writer ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteStartElement( writer, NULL, &localname, &ns, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteEndCData( writer, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = set_output( writer ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsWriteStartElement( writer, NULL, &localname, &ns, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + check_output( writer, "", __LINE__ ); + + hr = WsWriteStartCData( writer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + check_output( writer, ""; + text.value.length = 6; + hr = WsWriteText( writer, &text.text, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + check_output( writer, "", __LINE__ ); + + hr = WsWriteEndCData( writer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + check_output( writer, "]]>", __LINE__ ); + + hr = WsWriteEndElement( writer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + check_output( writer, "]]>", __LINE__ ); + + WsFreeWriter( writer ); +} + START_TEST(writer) { test_WsCreateWriter(); @@ -980,9 +1028,10 @@ START_TEST(writer) test_WsWriteStartElement(); test_WsWriteStartAttribute(); test_WsWriteType(); + test_basic_type(); + test_simple_struct_type(); test_WsWriteElement(); test_WsWriteValue(); test_WsWriteAttribute(); - test_basic_type(); - test_simple_struct_type(); + test_WsWriteStartCData(); } diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec index 699406d5dff..ffe8bcab284 100644 --- a/dlls/webservices/webservices.spec +++ b/dlls/webservices/webservices.spec @@ -172,7 +172,7 @@ @ stub WsWriteCharsUtf8 @ stdcall WsWriteElement(ptr ptr long ptr long ptr) @ stdcall WsWriteEndAttribute(ptr ptr) -@ stub WsWriteEndCData +@ stdcall WsWriteEndCData(ptr ptr) @ stdcall WsWriteEndElement(ptr ptr) @ stdcall WsWriteEndStartElement(ptr ptr) @ stub WsWriteEnvelopeEnd @@ -182,7 +182,7 @@ @ stub WsWriteNode @ stub WsWriteQualifiedName @ stdcall WsWriteStartAttribute(ptr ptr ptr ptr long ptr) -@ stub WsWriteStartCData +@ stdcall WsWriteStartCData(ptr ptr) @ stdcall WsWriteStartElement(ptr ptr ptr ptr ptr) @ stdcall WsWriteText(ptr ptr ptr) @ stdcall WsWriteType(ptr long long ptr long ptr long ptr) diff --git a/dlls/webservices/writer.c b/dlls/webservices/writer.c index 95f565d664a..88dab7798dd 100644 --- a/dlls/webservices/writer.c +++ b/dlls/webservices/writer.c @@ -1,5 +1,5 @@ /* - * Copyright 2015 Hans Leidekker for CodeWeavers + * Copyright 2015, 2016 Hans Leidekker for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -64,9 +64,11 @@ enum writer_state WRITER_STATE_STARTELEMENT, WRITER_STATE_STARTENDELEMENT, WRITER_STATE_STARTATTRIBUTE, + WRITER_STATE_STARTCDATA, WRITER_STATE_ENDSTARTELEMENT, WRITER_STATE_TEXT, - WRITER_STATE_ENDELEMENT + WRITER_STATE_ENDELEMENT, + WRITER_STATE_ENDCDATA }; struct writer @@ -727,6 +729,49 @@ HRESULT WINAPI WsWriteStartAttribute( WS_XML_WRITER *handle, const WS_XML_STRING return write_add_attribute( writer, prefix, localname, ns, single ); } +/************************************************************************** + * WsWriteStartCData [webservices.@] + */ +HRESULT WINAPI WsWriteStartCData( WS_XML_WRITER *handle, WS_ERROR *error ) +{ + struct writer *writer = (struct writer *)handle; + HRESULT hr; + + TRACE( "%p %p\n", handle, error ); + if (error) FIXME( "ignoring error parameter\n" ); + + if (!writer) return E_INVALIDARG; + + /* flush current start element if necessary */ + if (writer->state == WRITER_STATE_STARTELEMENT && ((hr = write_endstartelement( writer )) != S_OK)) + return hr; + + if ((hr = write_grow_buffer( writer, 9 )) != S_OK) return hr; + write_bytes( writer, (const BYTE *)"state = WRITER_STATE_STARTCDATA; + return S_OK; +} + +/************************************************************************** + * WsWriteEndCData [webservices.@] + */ +HRESULT WINAPI WsWriteEndCData( WS_XML_WRITER *handle, WS_ERROR *error ) +{ + struct writer *writer = (struct writer *)handle; + HRESULT hr; + + TRACE( "%p %p\n", handle, error ); + if (error) FIXME( "ignoring error parameter\n" ); + + if (!writer) return E_INVALIDARG; + if (writer->state != WRITER_STATE_STARTCDATA) return WS_E_INVALID_OPERATION; + + if ((hr = write_grow_buffer( writer, 3 )) != S_OK) return hr; + write_bytes( writer, (const BYTE *)"]]>", 3 ); + writer->state = WRITER_STATE_ENDCDATA; + return S_OK; +} + static HRESULT write_add_element_node( struct writer *writer, const WS_XML_STRING *prefix, const WS_XML_STRING *localname, const WS_XML_STRING *ns ) { diff --git a/include/webservices.h b/include/webservices.h index 7599c966615..9ed4a18c94e 100644 --- a/include/webservices.h +++ b/include/webservices.h @@ -590,10 +590,12 @@ HRESULT WINAPI WsWriteAttribute(WS_XML_WRITER*, const WS_ATTRIBUTE_DESCRIPTION*, 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*); +HRESULT WINAPI WsWriteEndCData(WS_XML_WRITER*, WS_ERROR*); HRESULT WINAPI WsWriteEndElement(WS_XML_WRITER*, WS_ERROR*); HRESULT WINAPI WsWriteEndStartElement(WS_XML_WRITER*, WS_ERROR*); HRESULT WINAPI WsWriteStartAttribute(WS_XML_WRITER*, const WS_XML_STRING*, const WS_XML_STRING*, const WS_XML_STRING*, BOOL, WS_ERROR*); +HRESULT WINAPI WsWriteStartCData(WS_XML_WRITER*, WS_ERROR*); HRESULT WINAPI WsWriteStartElement(WS_XML_WRITER*, const WS_XML_STRING*, const WS_XML_STRING*, const WS_XML_STRING*, WS_ERROR*); HRESULT WINAPI WsWriteText(WS_XML_WRITER*, const WS_XML_TEXT*, WS_ERROR*);