webservices: Implement WsWriteText.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2015-11-11 11:02:08 +01:00 committed by Alexandre Julliard
parent 112e1af5f1
commit 83e4e13571
5 changed files with 81 additions and 2 deletions

View File

@ -659,7 +659,7 @@ 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 *alloc_utf8_text( const char *data, ULONG len )
{
WS_XML_UTF8_TEXT *ret;

View File

@ -404,6 +404,51 @@ static void test_WsWriteStartElement(void)
WsFreeWriter( writer );
}
static void test_WsWriteStartAttribute(void)
{
HRESULT hr;
WS_XML_WRITER *writer;
WS_XML_STRING prefix = {1, (BYTE *)"p"}, localname = {3, (BYTE *)"str"}, ns = {2, (BYTE *)"ns"};
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, &prefix, &localname, &ns, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsWriteStartAttribute( NULL, &prefix, &localname, &ns, FALSE, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
/* WsWriteStartAttribute doesn't output anything */
localname.length = 3;
localname.bytes = (BYTE *)"len";
hr = WsWriteStartAttribute( writer, &prefix, &localname, &ns, FALSE, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "", __LINE__ );
text.text.textType = WS_XML_TEXT_TYPE_UTF8;
text.value.length = 1;
text.value.bytes = (BYTE *)"0";
hr = WsWriteText( writer, &text.text, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "", __LINE__ );
/* WsWriteEndAttribute doesn't output anything */
hr = WsWriteEndAttribute( 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, "<p:str p:len=\"0\" xmlns:p=\"ns\"/>", __LINE__ );
WsFreeWriter( writer );
}
START_TEST(writer)
{
test_WsCreateWriter();
@ -411,4 +456,5 @@ START_TEST(writer)
test_WsSetOutput();
test_WsSetOutputToBuffer();
test_WsWriteStartElement();
test_WsWriteStartAttribute();
}

View File

@ -184,7 +184,7 @@
@ stdcall WsWriteStartAttribute(ptr ptr ptr ptr long ptr)
@ stub WsWriteStartCData
@ stdcall WsWriteStartElement(ptr ptr ptr ptr ptr)
@ stub WsWriteText
@ stdcall WsWriteText(ptr ptr ptr)
@ stub WsWriteType
@ stub WsWriteValue
@ stub WsWriteXmlBuffer

View File

@ -29,6 +29,7 @@ void *ws_realloc( WS_HEAP *, void *, SIZE_T ) DECLSPEC_HIDDEN;
void ws_free( WS_HEAP *, void * ) DECLSPEC_HIDDEN;
const char *debugstr_xmlstr( const WS_XML_STRING * ) DECLSPEC_HIDDEN;
WS_XML_STRING *alloc_xml_string( const char *, ULONG ) DECLSPEC_HIDDEN;
WS_XML_UTF8_TEXT *alloc_utf8_text( const char *, ULONG ) DECLSPEC_HIDDEN;
HRESULT append_attribute( WS_XML_ELEMENT_NODE *, WS_XML_ATTRIBUTE * ) DECLSPEC_HIDDEN;
void free_attribute( WS_XML_ATTRIBUTE * ) DECLSPEC_HIDDEN;

View File

@ -738,3 +738,35 @@ error:
free_node( node );
return hr;
}
/**************************************************************************
* WsWriteText [webservices.@]
*/
HRESULT WINAPI WsWriteText( WS_XML_WRITER *handle, const WS_XML_TEXT *text, WS_ERROR *error )
{
struct writer *writer = (struct writer *)handle;
WS_XML_ELEMENT_NODE *elem;
WS_XML_UTF8_TEXT *src, *dst;
TRACE( "%p %p %p\n", handle, text, error );
if (!writer || !text) return E_INVALIDARG;
if (writer->state != WRITER_STATE_STARTATTRIBUTE)
{
FIXME( "can't handle writer state %u\n", writer->state );
return E_NOTIMPL;
}
if (text->textType != WS_XML_TEXT_TYPE_UTF8)
{
FIXME( "text type %u not supported\n", text->textType );
return E_NOTIMPL;
}
src = (WS_XML_UTF8_TEXT *)text;
if (!(dst = alloc_utf8_text( (const char *)src->value.bytes, src->value.length )))
return E_OUTOFMEMORY;
elem = (WS_XML_ELEMENT_NODE *)writer->current;
elem->attributes[elem->attributeCount - 1]->value = (WS_XML_TEXT *)dst;
return S_OK;
}