Commit c305b21b authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices/tests: Add tests.

parent 804e9b60
......@@ -77,11 +77,9 @@ static void test_WsOpenChannel(void)
hr = WsOpenChannel( channel, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
memset( &addr, 0, sizeof(addr) );
addr.url.length = sizeof(url)/sizeof(url[0]);
addr.url.chars = url;
addr.headers = NULL;
addr.extensions = NULL;
addr.identity = NULL;
hr = WsOpenChannel( NULL, &addr, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
......@@ -124,11 +122,9 @@ static void test_WsResetChannel(void)
hr = WsSetChannelProperty( channel, WS_CHANNEL_PROPERTY_RESOLVE_TIMEOUT, &timeout, size, NULL );
ok( hr == S_OK, "got %08x\n", hr );
memset( &addr, 0, sizeof(addr) );
addr.url.length = sizeof(url)/sizeof(url[0]);
addr.url.chars = url;
addr.headers = NULL;
addr.extensions = NULL;
addr.identity = NULL;
hr = WsOpenChannel( channel, &addr, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
......@@ -162,9 +158,166 @@ static void test_WsResetChannel(void)
WsFreeChannel( channel );
}
struct listener_info
{
int port;
HANDLE wait;
};
static DWORD CALLBACK listener_proc( void *arg )
{
static const WCHAR fmt[] =
{'s','o','a','p','.','u','d','p',':','/','/','l','o','c','a','l','h','o','s','t',':','%','u',0};
struct listener_info *info = arg;
WS_LISTENER *listener;
WS_CHANNEL *channel;
WS_MESSAGE *msg;
WCHAR buf[64];
WS_STRING url;
HRESULT hr;
hr = WsCreateListener( WS_CHANNEL_TYPE_DUPLEX, WS_UDP_CHANNEL_BINDING, NULL, 0, NULL, &listener, NULL );
ok( hr == S_OK, "got %08x\n", hr );
url.length = wsprintfW( buf, fmt, info->port );
url.chars = buf;
hr = WsOpenListener( listener, &url, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsCreateChannelForListener( listener, NULL, 0, &channel, NULL );
ok( hr == S_OK, "got %08x\n", hr );
SetEvent( info->wait );
hr = WsAcceptChannel( listener, channel, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsReadMessageStart( NULL, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsReadMessageStart( channel, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsReadMessageStart( NULL, msg, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsReadMessageStart( channel, msg, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsReadMessageEnd( NULL, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsReadMessageEnd( channel, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsReadMessageEnd( NULL, msg, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsReadMessageEnd( channel, msg, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
WsFreeMessage( msg );
SetEvent( info->wait );
hr = WsCloseChannel( channel, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
WsFreeChannel( channel );
hr = WsCloseListener( listener, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
WsFreeListener( listener );
return 0;
}
static void test_message_read_write( const struct listener_info *info )
{
static const WCHAR fmt[] =
{'s','o','a','p','.','u','d','p',':','/','/','l','o','c','a','l','h','o','s','t',':','%','u',0};
WS_ENDPOINT_ADDRESS addr;
WCHAR buf[64];
WS_CHANNEL *channel;
WS_MESSAGE *msg;
HRESULT hr;
DWORD err;
hr = WsCreateChannel( WS_CHANNEL_TYPE_DUPLEX, WS_UDP_CHANNEL_BINDING, NULL, 0, NULL, &channel, NULL );
ok( hr == S_OK, "got %08x\n", hr );
memset( &addr, 0, sizeof(addr) );
addr.url.length = wsprintfW( buf, fmt, info->port );
addr.url.chars = buf;
hr = WsOpenChannel( channel, &addr, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsWriteMessageStart( NULL, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsWriteMessageStart( channel, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsWriteMessageStart( NULL, msg, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsWriteMessageStart( channel, msg, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
hr = WsWriteMessageEnd( NULL, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsWriteMessageEnd( channel, NULL, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsWriteMessageEnd( NULL, msg, NULL, NULL );
ok( hr == E_INVALIDARG, "got %08x\n", hr );
hr = WsWriteMessageEnd( channel, msg, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
err = WaitForSingleObject( info->wait, 3000 );
ok( err == WAIT_OBJECT_0, "wait failed %u\n", err );
hr = WsCloseChannel( channel, NULL, NULL );
ok( hr == S_OK, "got %08x\n", hr );
WsFreeMessage( msg );
WsFreeChannel( channel );
}
static HANDLE start_listener( struct listener_info *info )
{
DWORD err;
HANDLE thread = CreateThread( NULL, 0, listener_proc, info, 0, NULL );
ok( thread != NULL, "failed to create listener thread %u\n", GetLastError() );
err = WaitForSingleObject( info->wait, 3000 );
ok( err == WAIT_OBJECT_0, "failed to start listener %u\n", err );
return thread;
}
START_TEST(channel)
{
struct listener_info info;
HANDLE thread;
test_WsCreateChannel();
test_WsOpenChannel();
test_WsResetChannel();
info.port = 7533;
info.wait = CreateEventW( NULL, 0, 0, NULL );
thread = start_listener( &info );
test_message_read_write( &info );
WaitForSingleObject( thread, 3000 );
}
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