forked from Mirrors/wine-wine
webservices/tests: Add tests.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>oldstable
parent
31b0d5fab8
commit
e725d9e3c7
|
@ -240,10 +240,182 @@ static void test_WsResetListener(void)
|
|||
WsFreeListener( listener );
|
||||
}
|
||||
|
||||
struct listener_info
|
||||
{
|
||||
int port;
|
||||
HANDLE wait;
|
||||
WS_CHANNEL_BINDING binding;
|
||||
WS_CHANNEL_TYPE type;
|
||||
};
|
||||
|
||||
static DWORD CALLBACK listener_proc( void *arg )
|
||||
{
|
||||
static const WCHAR fmt_tcp[] = {'n','e','t','.','t','c','p',':','/','/','+',':','%','u',0};
|
||||
static const WCHAR fmt_udp[] = {'s','o','a','p','.','u','d','p',':','/','/','+',':','%','u',0};
|
||||
struct listener_info *info = arg;
|
||||
const WCHAR *fmt = (info->binding == WS_TCP_CHANNEL_BINDING) ? fmt_tcp : fmt_udp;
|
||||
WS_XML_STRING localname = {9, (BYTE *)"localname"}, ns = {2, (BYTE *)"ns"}, action = {6, (BYTE *)"action"};
|
||||
WS_ELEMENT_DESCRIPTION body;
|
||||
WS_MESSAGE_DESCRIPTION desc_resp;
|
||||
const WS_MESSAGE_DESCRIPTION *desc[1];
|
||||
INT32 val = 0;
|
||||
WS_LISTENER *listener;
|
||||
WS_CHANNEL *channel;
|
||||
WS_MESSAGE *msg;
|
||||
WCHAR buf[64];
|
||||
WS_STRING url;
|
||||
HRESULT hr;
|
||||
|
||||
hr = WsCreateListener( info->type, info->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 );
|
||||
|
||||
body.elementLocalName = &localname;
|
||||
body.elementNs = &ns;
|
||||
body.type = WS_INT32_TYPE;
|
||||
body.typeDescription = NULL;
|
||||
|
||||
desc_resp.action = &action;
|
||||
desc_resp.bodyElementDescription = &body;
|
||||
desc[0] = &desc_resp;
|
||||
|
||||
hr = WsReceiveMessage( channel, msg, desc, 1, WS_RECEIVE_REQUIRED_MESSAGE, WS_READ_REQUIRED_VALUE,
|
||||
NULL, &val, sizeof(val), NULL, NULL, NULL );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
ok( val == -1, "got %d\n", val );
|
||||
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_WsAcceptChannel( const struct listener_info *info )
|
||||
{
|
||||
static const WCHAR fmt_tcp[] =
|
||||
{'n','e','t','.','t','c','p',':','/','/','l','o','c','a','l','h','o','s','t',':','%','u',0};
|
||||
static const WCHAR fmt_udp[] =
|
||||
{'s','o','a','p','.','u','d','p',':','/','/','l','o','c','a','l','h','o','s','t',':','%','u',0};
|
||||
const WCHAR *fmt = (info->binding == WS_TCP_CHANNEL_BINDING) ? fmt_tcp : fmt_udp;
|
||||
WS_XML_STRING localname = {9, (BYTE *)"localname"}, ns = {2, (BYTE *)"ns"}, action = {6, (BYTE *)"action"};
|
||||
WCHAR buf[64];
|
||||
WS_LISTENER *listener;
|
||||
WS_CHANNEL *channel;
|
||||
WS_MESSAGE *msg;
|
||||
WS_ENDPOINT_ADDRESS addr;
|
||||
WS_ELEMENT_DESCRIPTION body;
|
||||
WS_MESSAGE_DESCRIPTION desc;
|
||||
INT32 val = -1;
|
||||
HRESULT hr;
|
||||
DWORD err;
|
||||
|
||||
hr = WsAcceptChannel( NULL, NULL, NULL, NULL );
|
||||
ok( hr == E_INVALIDARG, "got %08x\n", hr );
|
||||
|
||||
hr = WsCreateListener( info->type, info->binding, NULL, 0, NULL, &listener, NULL );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
|
||||
hr = WsAcceptChannel( listener, NULL, NULL, NULL );
|
||||
ok( hr == E_INVALIDARG, "got %08x\n", hr );
|
||||
|
||||
hr = WsCreateChannelForListener( listener, NULL, 0, &channel, NULL );
|
||||
ok( hr == S_OK, "got %08x\n", hr );
|
||||
|
||||
hr = WsAcceptChannel( listener, channel, NULL, NULL );
|
||||
ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
|
||||
WsFreeChannel( channel );
|
||||
WsFreeListener( listener );
|
||||
|
||||
hr = WsCreateChannel( info->type, info->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 );
|
||||
|
||||
body.elementLocalName = &localname;
|
||||
body.elementNs = &ns;
|
||||
body.type = WS_INT32_TYPE;
|
||||
body.typeDescription = NULL;
|
||||
|
||||
desc.action = &action;
|
||||
desc.bodyElementDescription = &body;
|
||||
|
||||
hr = WsSendMessage( channel, msg, &desc, WS_WRITE_REQUIRED_VALUE, &val, sizeof(val), 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(listener)
|
||||
{
|
||||
struct listener_info info;
|
||||
HANDLE thread;
|
||||
|
||||
test_WsCreateListener();
|
||||
test_WsOpenListener();
|
||||
test_WsCreateChannelForListener();
|
||||
test_WsResetListener();
|
||||
|
||||
info.port = 7533;
|
||||
info.wait = CreateEventW( NULL, 0, 0, NULL );
|
||||
info.type = WS_CHANNEL_TYPE_DUPLEX;
|
||||
info.binding = WS_UDP_CHANNEL_BINDING;
|
||||
|
||||
thread = start_listener( &info );
|
||||
test_WsAcceptChannel( &info );
|
||||
WaitForSingleObject( thread, 3000 );
|
||||
|
||||
info.type = WS_CHANNEL_TYPE_DUPLEX_SESSION;
|
||||
info.binding = WS_TCP_CHANNEL_BINDING;
|
||||
|
||||
thread = start_listener( &info );
|
||||
test_WsAcceptChannel( &info );
|
||||
WaitForSingleObject( thread, 3000 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue