Commit 08c32f4e authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices/tests: Add tests.

parent f236df36
......@@ -326,10 +326,89 @@ static void test_WsSetOutputToBuffer(void)
WsFreeHeap( heap );
}
static void check_output( WS_XML_WRITER *writer, const char *expected, unsigned int line )
{
WS_BYTES bytes;
ULONG size = sizeof(bytes);
int len = strlen( expected );
HRESULT hr;
memset( &bytes, 0, sizeof(bytes) );
hr = WsGetWriterProperty( writer, WS_XML_WRITER_PROPERTY_BYTES, &bytes, size, NULL );
ok( hr == S_OK, "%u: got %08x\n", line, hr );
ok( bytes.length == len, "%u: got %u expected %u\n", line, bytes.length, len );
if (bytes.length != len) return;
ok( !memcmp( bytes.bytes, expected, len ), "%u: got %s expected %s\n", line, bytes.bytes, expected );
}
static void test_WsWriteStartElement(void)
{
HRESULT hr;
WS_XML_WRITER *writer;
WS_XML_STRING prefix = {1, (BYTE *)"p"}, ns = {2, (BYTE *)"ns"};
WS_XML_STRING localname = {1, (BYTE *)"a"}, localname2 = {1, (BYTE *)"b"};
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( NULL, &prefix, &localname, &ns, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
/* first call to WsWriteStartElement doesn't output anything */
hr = WsWriteStartElement( writer, &prefix, &localname, &ns, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "", __LINE__ );
/* two ways to close an element */
hr = WsWriteEndStartElement( writer, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "<p:a xmlns:p=\"ns\">", __LINE__ );
hr = WsWriteEndElement( writer, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "<p:a xmlns:p=\"ns\"></p:a>", __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 );
hr = WsWriteEndElement( writer, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "<p:a xmlns:p=\"ns\"/>", __LINE__ );
/* nested elements */
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 = WsWriteStartElement( writer, NULL, &localname2, &ns, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "<a xmlns=\"ns\">", __LINE__ );
hr = WsWriteEndElement( writer, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "<a xmlns=\"ns\"><b/>", __LINE__ );
hr = WsWriteEndElement( writer, NULL );
ok( hr == S_OK, "got %08x\n", hr );
check_output( writer, "<a xmlns=\"ns\"><b/></a>", __LINE__ );
WsFreeWriter( writer );
}
START_TEST(writer)
{
test_WsCreateWriter();
test_WsCreateXmlBuffer();
test_WsSetOutput();
test_WsSetOutputToBuffer();
test_WsWriteStartElement();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment