[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] tests: torture_connect: add test for user provided socket
[Thread Prev] | [Thread Next]
- Subject: [PATCH 2/2] tests: torture_connect: add test for user provided socket
- From: Luka Perkov <luka.perkov@xxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 17 Mar 2014 14:35:47 +0000
- To: libssh@xxxxxxxxxx
- Cc: Luka Perkov <luka.perkov@xxxxxxxxxx>
Signed-off-by: Luka Perkov <luka.perkov@xxxxxxxxxx> --- tests/client/torture_connect.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/client/torture_connect.c b/tests/client/torture_connect.c index a364055..1a8ad3a 100644 --- a/tests/client/torture_connect.c +++ b/tests/client/torture_connect.c @@ -24,6 +24,7 @@ #include "torture.h" #include <libssh/libssh.h> #include <sys/time.h> +#include <arpa/inet.h> #define HOST "localhost" /* Should work until Apnic decides to assign it :) */ @@ -113,6 +114,29 @@ static void torture_connect_failure(void **state) { ssh_disconnect(session); } +static void torture_connect_socket(void **state) { + ssh_session session = *state; + + int rc; + int sock_fd = 0; + struct sockaddr_in server_addr; + + sock_fd = socket(AF_INET, SOCK_STREAM, 0); + assert_true(sock_fd > 0); + + server_addr.sin_family = AF_INET; + server_addr.sin_port = htons(22); + server_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); + + rc = connect(sock_fd, &server_addr, sizeof(server_addr)); + assert_true(rc == 0); + + ssh_options_set(session, SSH_OPTIONS_FD, &sock_fd); + + rc = ssh_connect(session); + assert_true(rc == SSH_OK); +} + int torture_run_tests(void) { int rc; const UnitTest tests[] = { @@ -120,6 +144,7 @@ int torture_run_tests(void) { unit_test_setup_teardown(torture_connect_double, setup, teardown), unit_test_setup_teardown(torture_connect_failure, setup, teardown), unit_test_setup_teardown(torture_connect_timeout, setup, teardown), + unit_test_setup_teardown(torture_connect_socket, setup, teardown), }; ssh_init(); -- 1.9.0
Archive administrator: postmaster@lists.cynapses.org