webservices: Add support for writing WS_ENUM_TYPE values.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
fe9a28e819
commit
7236d982c9
|
@ -553,6 +553,11 @@ static void test_WsWriteType(void)
|
|||
WS_XML_WRITER *writer;
|
||||
WS_XML_STRING prefix = {1, (BYTE*)"p"}, localname = {3, (BYTE *)"str"}, ns = {2, (BYTE *)"ns"};
|
||||
const WCHAR *val_str;
|
||||
enum {ONE = 1, TWO = 2};
|
||||
WS_XML_STRING one = {3, (BYTE *)"ONE" }, two = {3, (BYTE *)"TWO"};
|
||||
WS_ENUM_VALUE enum_values[] = {{ONE, &one}, {TWO, &two}};
|
||||
WS_ENUM_DESCRIPTION enum_desc;
|
||||
int val_enum;
|
||||
|
||||
hr = WsCreateWriter( NULL, 0, &writer, NULL );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
|
@ -637,6 +642,36 @@ static void test_WsWriteType(void)
|
|||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
check_output( writer, "<p:str xmlns:p=\"ns\">test</p:str>", __LINE__ );
|
||||
|
||||
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 );
|
||||
|
||||
enum_desc.values = enum_values;
|
||||
enum_desc.valueCount = ARRAY_SIZE(enum_values);
|
||||
enum_desc.maxByteCount = 3;
|
||||
enum_desc.nameIndices = NULL;
|
||||
|
||||
val_enum = 0;
|
||||
hr = WsWriteType( writer, WS_ELEMENT_TYPE_MAPPING, WS_ENUM_TYPE, &enum_desc,
|
||||
WS_WRITE_REQUIRED_VALUE, &val_enum, sizeof(val_enum), NULL );
|
||||
ok( hr == E_INVALIDARG, "got %08x\n", hr );
|
||||
|
||||
val_enum = 3;
|
||||
hr = WsWriteType( writer, WS_ELEMENT_TYPE_MAPPING, WS_ENUM_TYPE, &enum_desc,
|
||||
WS_WRITE_REQUIRED_VALUE, &val_enum, sizeof(val_enum), NULL );
|
||||
ok( hr == E_INVALIDARG, "got %08x\n", hr );
|
||||
|
||||
val_enum = ONE;
|
||||
hr = WsWriteType( writer, WS_ELEMENT_TYPE_MAPPING, WS_ENUM_TYPE, &enum_desc,
|
||||
WS_WRITE_REQUIRED_VALUE, &val_enum, sizeof(val_enum), NULL );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
|
||||
hr = WsWriteEndElement( writer, NULL );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
check_output( writer, "<p:str xmlns:p=\"ns\">ONE</p:str>", __LINE__ );
|
||||
|
||||
WsFreeWriter( writer );
|
||||
}
|
||||
|
||||
|
|
|
@ -3876,6 +3876,35 @@ static HRESULT write_type_struct( struct writer *writer, WS_TYPE_MAPPING mapping
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
static const WS_XML_STRING *get_enum_value_name( const WS_ENUM_DESCRIPTION *desc, int value )
|
||||
{
|
||||
ULONG i;
|
||||
for (i = 0; i < desc->valueCount; i++)
|
||||
{
|
||||
if (desc->values[i].value == value) return desc->values[i].name;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static HRESULT write_type_enum( struct writer *writer, WS_TYPE_MAPPING mapping,
|
||||
const WS_ENUM_DESCRIPTION *desc, WS_WRITE_OPTION option,
|
||||
const void *value, ULONG size )
|
||||
{
|
||||
const WS_XML_STRING *name;
|
||||
WS_XML_UTF8_TEXT utf8;
|
||||
const int *ptr;
|
||||
HRESULT hr;
|
||||
|
||||
if (!desc) return E_INVALIDARG;
|
||||
if ((hr = get_value_ptr( option, value, size, sizeof(*ptr), (const void **)&ptr )) != S_OK) return hr;
|
||||
if (!(name = get_enum_value_name( desc, *ptr ))) return E_INVALIDARG;
|
||||
|
||||
utf8.text.textType = WS_XML_TEXT_TYPE_UTF8;
|
||||
utf8.value.bytes = name->bytes;
|
||||
utf8.value.length = name->length;
|
||||
return write_type_text( writer, mapping, &utf8.text );
|
||||
}
|
||||
|
||||
static HRESULT write_type( struct writer *writer, WS_TYPE_MAPPING mapping, WS_TYPE type,
|
||||
const void *desc, WS_WRITE_OPTION option, const void *value,
|
||||
ULONG size )
|
||||
|
@ -3939,6 +3968,9 @@ static HRESULT write_type( struct writer *writer, WS_TYPE_MAPPING mapping, WS_TY
|
|||
case WS_STRUCT_TYPE:
|
||||
return write_type_struct( writer, mapping, desc, option, value, size );
|
||||
|
||||
case WS_ENUM_TYPE:
|
||||
return write_type_enum( writer, mapping, desc, option, value, size );
|
||||
|
||||
default:
|
||||
FIXME( "type %u not supported\n", type );
|
||||
return E_NOTIMPL;
|
||||
|
|
Loading…
Reference in New Issue