Add uv_pipe_bind tests

This commit is contained in:
Igor Zinkovsky 2011-07-21 02:00:12 +02:00 committed by Bert Belder
parent 2765509430
commit afc998759f
6 changed files with 199 additions and 38 deletions

View File

@ -144,7 +144,6 @@
<ItemGroup>
<ClCompile Include="..\test\echo-server.c" />
<ClCompile Include="..\test\test-async.c" />
<ClCompile Include="..\test\test-bind6-error.c" />
<ClCompile Include="..\test\test-delayed-accept.c" />
<ClCompile Include="..\test\test-callback-stack.c" />
<ClCompile Include="..\test\test-connection-fail.c" />
@ -159,8 +158,10 @@
<ClCompile Include="..\test\test-ping-pong.c" />
<ClCompile Include="..\test\runner-win.c" />
<ClCompile Include="..\test\runner.c" />
<ClCompile Include="..\test\test-bind-error.c" />
<ClCompile Include="..\test\test-pipe-bind-error.c" />
<ClCompile Include="..\test\test-shutdown-eof.c" />
<ClCompile Include="..\test\test-tcp-bind-error.c" />
<ClCompile Include="..\test\test-tcp-bind6-error.c" />
<ClCompile Include="..\test\test-tcp-writealot.c" />
<ClCompile Include="..\test\test-timer-again.c" />
<ClCompile Include="..\test\test-timer.c" />

View File

@ -32,8 +32,10 @@
#ifdef _WIN32
# define TEST_PIPENAME "\\\\.\\pipe\\uv-test"
# define TEST_PIPENAME_2 "\\\\.\\pipe\\uv-test2"
#else
# define TEST_PIPENAME "/tmp/uv-test-sock"
# define TEST_PIPENAME_2 "/tmp/uv-test-sock2"
#endif
typedef enum {

View File

@ -24,18 +24,22 @@ TEST_DECLARE (tcp_ping_pong_v6)
TEST_DECLARE (pipe_ping_pong)
TEST_DECLARE (delayed_accept)
TEST_DECLARE (tcp_writealot)
TEST_DECLARE (bind_error_addrinuse)
TEST_DECLARE (bind_error_addrnotavail_1)
TEST_DECLARE (bind_error_addrnotavail_2)
TEST_DECLARE (bind_error_fault)
TEST_DECLARE (bind_error_inval)
TEST_DECLARE (bind_localhost_ok)
TEST_DECLARE (listen_without_bind)
TEST_DECLARE (bind6_error_addrinuse)
TEST_DECLARE (bind6_error_addrnotavail)
TEST_DECLARE (bind6_error_fault)
TEST_DECLARE (bind6_error_inval)
TEST_DECLARE (bind6_localhost_ok)
TEST_DECLARE (tcp_bind_error_addrinuse)
TEST_DECLARE (tcp_bind_error_addrnotavail_1)
TEST_DECLARE (tcp_bind_error_addrnotavail_2)
TEST_DECLARE (tcp_bind_error_fault)
TEST_DECLARE (tcp_bind_error_inval)
TEST_DECLARE (tcp_bind_localhost_ok)
TEST_DECLARE (tcp_listen_without_bind)
TEST_DECLARE (tcp_bind6_error_addrinuse)
TEST_DECLARE (tcp_bind6_error_addrnotavail)
TEST_DECLARE (tcp_bind6_error_fault)
TEST_DECLARE (tcp_bind6_error_inval)
TEST_DECLARE (tcp_bind6_localhost_ok)
TEST_DECLARE (pipe_bind_error_addrinuse)
TEST_DECLARE (pipe_bind_error_addrnotavail)
TEST_DECLARE (pipe_bind_error_inval)
TEST_DECLARE (pipe_listen_without_bind)
TEST_DECLARE (connection_fail)
TEST_DECLARE (connection_fail_doesnt_auto_close)
TEST_DECLARE (shutdown_eof)
@ -77,19 +81,24 @@ TASK_LIST_START
TEST_ENTRY (tcp_writealot)
TEST_HELPER (tcp_writealot, tcp4_echo_server)
TEST_ENTRY (bind_error_addrinuse)
TEST_ENTRY (bind_error_addrnotavail_1)
TEST_ENTRY (bind_error_addrnotavail_2)
TEST_ENTRY (bind_error_fault)
TEST_ENTRY (bind_error_inval)
TEST_ENTRY (bind_localhost_ok)
TEST_ENTRY (listen_without_bind)
TEST_ENTRY (tcp_bind_error_addrinuse)
TEST_ENTRY (tcp_bind_error_addrnotavail_1)
TEST_ENTRY (tcp_bind_error_addrnotavail_2)
TEST_ENTRY (tcp_bind_error_fault)
TEST_ENTRY (tcp_bind_error_inval)
TEST_ENTRY (tcp_bind_localhost_ok)
TEST_ENTRY (tcp_listen_without_bind)
TEST_ENTRY (bind6_error_addrinuse)
TEST_ENTRY (bind6_error_addrnotavail)
TEST_ENTRY (bind6_error_fault)
TEST_ENTRY (bind6_error_inval)
TEST_ENTRY (bind6_localhost_ok)
TEST_ENTRY (tcp_bind6_error_addrinuse)
TEST_ENTRY (tcp_bind6_error_addrnotavail)
TEST_ENTRY (tcp_bind6_error_fault)
TEST_ENTRY (tcp_bind6_error_inval)
TEST_ENTRY (tcp_bind6_localhost_ok)
TEST_ENTRY (pipe_bind_error_addrinuse)
TEST_ENTRY (pipe_bind_error_addrnotavail)
TEST_ENTRY (pipe_bind_error_inval)
TEST_ENTRY (pipe_listen_without_bind)
TEST_ENTRY (connection_fail)
TEST_ENTRY (connection_fail_doesnt_auto_close)

149
test/test-pipe-bind-error.c Normal file
View File

@ -0,0 +1,149 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "uv.h"
#include "task.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
# define BAD_PIPENAME "bad-pipe"
#else
/* TODO: define a bad pipe name for unix (see pipe_bind_error_addrnotavail) */
# define BAD_PIPENAME ""
#endif
static int close_cb_called = 0;
static void close_cb(uv_handle_t* handle) {
ASSERT(handle != NULL);
close_cb_called++;
}
TEST_IMPL(pipe_bind_error_addrinuse) {
uv_pipe_t server1, server2;
int r;
uv_init();
r = uv_pipe_init(&server1);
ASSERT(r == 0);
r = uv_pipe_bind(&server1, TEST_PIPENAME);
ASSERT(r == 0);
r = uv_pipe_init(&server2);
ASSERT(r == 0);
r = uv_pipe_bind(&server2, TEST_PIPENAME);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EADDRINUSE);
r = uv_pipe_listen(&server1, NULL);
ASSERT(r == 0);
r = uv_pipe_listen(&server2, NULL);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EADDRINUSE);
uv_close((uv_handle_t*)&server1, close_cb);
uv_close((uv_handle_t*)&server2, close_cb);
uv_run();
ASSERT(close_cb_called == 2);
return 0;
}
TEST_IMPL(pipe_bind_error_addrnotavail) {
uv_pipe_t server;
int r;
uv_init();
r = uv_pipe_init(&server);
ASSERT(r == 0);
r = uv_pipe_bind(&server, BAD_PIPENAME);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL);
uv_close((uv_handle_t*)&server, close_cb);
uv_run();
ASSERT(close_cb_called == 1);
return 0;
}
TEST_IMPL(pipe_bind_error_inval) {
uv_pipe_t server;
int r;
uv_init();
r = uv_pipe_init(&server);
ASSERT(r == 0);
r = uv_pipe_bind(&server, TEST_PIPENAME);
ASSERT(r == 0);
r = uv_pipe_bind(&server, TEST_PIPENAME_2);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
uv_run();
ASSERT(close_cb_called == 1);
return 0;
}
TEST_IMPL(pipe_listen_without_bind) {
uv_pipe_t server;
int r;
uv_init();
r = uv_pipe_init(&server);
ASSERT(r == 0);
r = uv_pipe_listen(&server, NULL);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_ENOTCONN);
uv_close((uv_handle_t*)&server, close_cb);
uv_run();
ASSERT(close_cb_called == 1);
return 0;
}

View File

@ -34,7 +34,7 @@ static void close_cb(uv_handle_t* handle) {
}
TEST_IMPL(bind_error_addrinuse) {
TEST_IMPL(tcp_bind_error_addrinuse) {
struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
uv_tcp_t server1, server2;
int r;
@ -69,7 +69,7 @@ TEST_IMPL(bind_error_addrinuse) {
}
TEST_IMPL(bind_error_addrnotavail_1) {
TEST_IMPL(tcp_bind_error_addrnotavail_1) {
struct sockaddr_in addr = uv_ip4_addr("127.255.255.255", TEST_PORT);
uv_tcp_t server;
int r;
@ -95,7 +95,7 @@ TEST_IMPL(bind_error_addrnotavail_1) {
}
TEST_IMPL(bind_error_addrnotavail_2) {
TEST_IMPL(tcp_bind_error_addrnotavail_2) {
struct sockaddr_in addr = uv_ip4_addr("4.4.4.4", TEST_PORT);
uv_tcp_t server;
int r;
@ -118,7 +118,7 @@ TEST_IMPL(bind_error_addrnotavail_2) {
}
TEST_IMPL(bind_error_fault) {
TEST_IMPL(tcp_bind_error_fault) {
char garbage[] = "blah blah blah blah blah blah blah blah blah blah blah blah";
struct sockaddr_in* garbage_addr;
uv_tcp_t server;
@ -146,7 +146,7 @@ TEST_IMPL(bind_error_fault) {
/* Notes: On Linux uv_bind(server, NULL) will segfault the program. */
TEST_IMPL(bind_error_inval) {
TEST_IMPL(tcp_bind_error_inval) {
struct sockaddr_in addr1 = uv_ip4_addr("0.0.0.0", TEST_PORT);
struct sockaddr_in addr2 = uv_ip4_addr("0.0.0.0", TEST_PORT_2);
uv_tcp_t server;
@ -173,7 +173,7 @@ TEST_IMPL(bind_error_inval) {
}
TEST_IMPL(bind_localhost_ok) {
TEST_IMPL(tcp_bind_localhost_ok) {
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
uv_tcp_t server;
@ -190,7 +190,7 @@ TEST_IMPL(bind_localhost_ok) {
}
TEST_IMPL(listen_without_bind) {
TEST_IMPL(tcp_listen_without_bind) {
int r;
uv_tcp_t server;

View File

@ -34,7 +34,7 @@ static void close_cb(uv_handle_t* handle) {
}
TEST_IMPL(bind6_error_addrinuse) {
TEST_IMPL(tcp_bind6_error_addrinuse) {
struct sockaddr_in6 addr = uv_ip6_addr("::", TEST_PORT);
uv_tcp_t server1, server2;
int r;
@ -69,7 +69,7 @@ TEST_IMPL(bind6_error_addrinuse) {
}
TEST_IMPL(bind6_error_addrnotavail) {
TEST_IMPL(tcp_bind6_error_addrnotavail) {
struct sockaddr_in6 addr = uv_ip6_addr("4:4:4:4:4:4:4:4", TEST_PORT);
uv_tcp_t server;
int r;
@ -92,7 +92,7 @@ TEST_IMPL(bind6_error_addrnotavail) {
}
TEST_IMPL(bind6_error_fault) {
TEST_IMPL(tcp_bind6_error_fault) {
char garbage[] = "blah blah blah blah blah blah blah blah blah blah blah blah";
struct sockaddr_in6* garbage_addr;
uv_tcp_t server;
@ -120,7 +120,7 @@ TEST_IMPL(bind6_error_fault) {
/* Notes: On Linux uv_bind6(server, NULL) will segfault the program. */
TEST_IMPL(bind6_error_inval) {
TEST_IMPL(tcp_bind6_error_inval) {
struct sockaddr_in6 addr1 = uv_ip6_addr("::", TEST_PORT);
struct sockaddr_in6 addr2 = uv_ip6_addr("::", TEST_PORT_2);
uv_tcp_t server;
@ -147,7 +147,7 @@ TEST_IMPL(bind6_error_inval) {
}
TEST_IMPL(bind6_localhost_ok) {
TEST_IMPL(tcp_bind6_localhost_ok) {
struct sockaddr_in6 addr = uv_ip6_addr("::1", TEST_PORT);
uv_tcp_t server;