From 461f0a74ce4ebc839c9af261b6bb1e400d46498f Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 19 Apr 2011 01:50:48 -0700 Subject: [PATCH] Add test-connection-fail. Not yet passing linux. Feel free to modify. --- test/test-connection-fail.c | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/test-connection-fail.c diff --git a/test/test-connection-fail.c b/test/test-connection-fail.c new file mode 100644 index 00000000..4e3a455f --- /dev/null +++ b/test/test-connection-fail.c @@ -0,0 +1,73 @@ +/* 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 "../oio.h" +#include "task.h" + +#include +#include + + +static oio_handle handle; +static oio_req req; +static int connect_cb_calls; +static int close_cb_calls; + + +static void on_close(oio_handle* handle, oio_err err) { + ASSERT(!err); + close_cb_calls++; +} + + +static void on_connect(oio_req *req, oio_err err) { + ASSERT(err); + connect_cb_calls++; +} + + +TEST_IMPL(test_connection_fail) { + oio_init(); + + struct sockaddr_in client_addr = oio_ip4_addr("0.0.0.0", 0); + + /* There should be no servers listening on this port. */ + struct sockaddr_in server_addr = oio_ip4_addr("127.0.0.1", TEST_PORT); + + /* Try to connec to the server and do NUM_PINGS ping-pongs. */ + int r = oio_tcp_init(&handle, on_close, NULL); + ASSERT(!r); + + /* We are never doing multiple reads/connects at a time anyway. */ + /* so these handles can be pre-initialized. */ + oio_req_init(&req, &handle, on_connect); + + oio_bind(&handle, (struct sockaddr*)&client_addr); + r = oio_connect(&req, (struct sockaddr*)&server_addr); + ASSERT(!r); + + oio_run(); + + ASSERT(connect_cb_calls == 1); + ASSERT(close_cb_calls == 1); + + return 0; +}