aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cynapses.org>2010-12-28 15:05:56 +0100
committerAndreas Schneider <asn@cynapses.org>2010-12-28 22:14:47 +0100
commitd04ce30b037edf59caafb486921c9af114a22d04 (patch)
tree87e1744761d429bc7fce4aa2d813836e2cce9b7f /tests
parent512b776245a9d04d017161656d6df8bfafba0610 (diff)
downloadlibssh-d04ce30b037edf59caafb486921c9af114a22d04.tar.gz
libssh-d04ce30b037edf59caafb486921c9af114a22d04.tar.xz
libssh-d04ce30b037edf59caafb486921c9af114a22d04.zip
tests: Migrated torture_options to cmockery.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/CMakeLists.txt2
-rw-r--r--tests/unittests/torture_options.c148
2 files changed, 65 insertions, 85 deletions
diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt
index 1b88a57..f3375c9 100644
--- a/tests/unittests/CMakeLists.txt
+++ b/tests/unittests/CMakeLists.txt
@@ -6,5 +6,5 @@ add_cmockery_test(torture_init torture_init.c ${TORTURE_LIBRARY})
add_cmockery_test(torture_keyfiles torture_keyfiles.c ${TORTURE_LIBRARY})
add_cmockery_test(torture_list torture_list.c ${TORTURE_LIBRARY})
add_cmockery_test(torture_misc torture_misc.c ${TORTURE_LIBRARY})
-#add_check_test(torture_options torture_options.c ${TORTURE_LIBRARY})
+add_cmockery_test(torture_options torture_options.c ${TORTURE_LIBRARY})
#add_check_test(torture_rand torture_rand.c ${TORTURE_LIBRARY})
diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c
index bba5500..b01435a 100644
--- a/tests/unittests/torture_options.c
+++ b/tests/unittests/torture_options.c
@@ -3,144 +3,124 @@
#include "torture.h"
#include "options.c"
-ssh_session session;
-#ifndef _WIN32
-struct passwd pwd;
-#endif /* _WIN32 */
-
-static void setup(void) {
- session = ssh_new();
-}
-
-static void setup_passwd(void) {
- int rc;
-#ifndef _WIN32
-#ifndef NSS_BUFLEN_PASSWD
-#define NSS_BUFLEN_PASSWD 4096
-#endif /* NSS_BUFLEN_PASSWD */
- struct passwd *pwdbuf;
- char buf[NSS_BUFLEN_PASSWD];
-
- /* get local username */
- rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
- ck_assert(rc == 0);
-#endif /* _WIN32 */
- session = ssh_new();
+static void setup(void **state) {
+ ssh_session session = ssh_new();
+ *state = session;
}
-static void teardown(void) {
- ZERO_STRUCT(pwd);
- ssh_free(session);
+static void teardown(void **state) {
+ ssh_free(*state);
}
-START_TEST (torture_options_set_host)
-{
+static void torture_options_set_host(void **state) {
+ ssh_session session = *state;
int rc;
rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
- ck_assert(rc == 0);
- ck_assert_str_eq(session->host, "localhost");
+ assert_true(rc == 0);
+ assert_string_equal(session->host, "localhost");
rc = ssh_options_set(session, SSH_OPTIONS_HOST, "guru@meditation");
- ck_assert(rc == 0);
- ck_assert_str_eq(session->host, "meditation");
- ck_assert_str_eq(session->username, "guru");
+ assert_true(rc == 0);
+ assert_string_equal(session->host, "meditation");
+ assert_string_equal(session->username, "guru");
}
-END_TEST
-START_TEST (torture_options_set_port)
-{
+static void torture_options_set_port(void **state) {
+ ssh_session session = *state;
int rc;
unsigned int port = 42;
rc = ssh_options_set(session, SSH_OPTIONS_PORT, &port);
- ck_assert(rc == 0);
- ck_assert(session->port == port);
+ assert_true(rc == 0);
+ assert_true(session->port == port);
rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, "23");
- ck_assert(rc == 0);
- ck_assert(session->port == 23);
+ assert_true(rc == 0);
+ assert_true(session->port == 23);
rc = ssh_options_set(session, SSH_OPTIONS_PORT_STR, "five");
- ck_assert(rc == 0);
- ck_assert(session->port == 0);
+ assert_true(rc == 0);
+ assert_true(session->port == 0);
rc = ssh_options_set(session, SSH_OPTIONS_PORT, NULL);
- ck_assert(rc == 0);
- ck_assert(session->port == 22);
+ assert_true(rc == 0);
+ assert_true(session->port == 22);
}
-END_TEST
-START_TEST (torture_options_set_fd)
-{
+static void torture_options_set_fd(void **state) {
+ ssh_session session = *state;
socket_t fd = 42;
int rc;
rc = ssh_options_set(session, SSH_OPTIONS_FD, &fd);
- ck_assert(rc == 0);
- ck_assert(session->fd == fd);
+ assert_true(rc == 0);
+ assert_true(session->fd == fd);
rc = ssh_options_set(session, SSH_OPTIONS_FD, NULL);
- ck_assert(rc == 0);
- ck_assert(session->fd == SSH_INVALID_SOCKET);
+ assert_true(rc == 0);
+ assert_true(session->fd == SSH_INVALID_SOCKET);
}
-END_TEST
-START_TEST (torture_options_set_user)
-{
+static void torture_options_set_user(void **state) {
+ ssh_session session = *state;
int rc;
+#ifndef _WIN32
+# ifndef NSS_BUFLEN_PASSWD
+# define NSS_BUFLEN_PASSWD 4096
+# endif /* NSS_BUFLEN_PASSWD */
+ struct passwd pwd;
+ struct passwd *pwdbuf;
+ char buf[NSS_BUFLEN_PASSWD];
+
+ /* get local username */
+ rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
+ assert_true(rc == 0);
+#endif /* _WIN32 */
rc = ssh_options_set(session, SSH_OPTIONS_USER, "guru");
- ck_assert(rc == 0);
- ck_assert_str_eq(session->username, "guru");
+ assert_true(rc == 0);
+ assert_string_equal(session->username, "guru");
rc = ssh_options_set(session, SSH_OPTIONS_USER, NULL);
- ck_assert(rc == 0);
+ assert_true(rc == 0);
#ifndef _WIN32
- ck_assert_str_eq(session->username, pwd.pw_name);
+ assert_string_equal(session->username, pwd.pw_name);
#endif
}
-END_TEST
/* TODO */
#if 0
-START_TEST (torture_options_set_sshdir)
+static voidtorture_options_set_sshdir)
{
}
END_TEST
#endif
-START_TEST (torture_options_set_identity)
-{
+static void torture_options_set_identity(void **state) {
+ ssh_session session = *state;
int rc;
rc = ssh_options_set(session, SSH_OPTIONS_ADD_IDENTITY, "identity1");
- ck_assert(rc == 0);
- ck_assert_str_eq(session->identity->root->data, "identity1");
+ assert_true(rc == 0);
+ assert_string_equal(session->identity->root->data, "identity1");
rc = ssh_options_set(session, SSH_OPTIONS_IDENTITY, "identity2");
- ck_assert(rc == 0);
- ck_assert_str_eq(session->identity->root->data, "identity2");
- ck_assert_str_eq(session->identity->root->next->data, "identity1");
+ assert_true(rc == 0);
+ assert_string_equal(session->identity->root->data, "identity2");
+ assert_string_equal(session->identity->root->next->data, "identity1");
}
-END_TEST
-Suite *torture_make_suite(void) {
- Suite *s = suite_create("libssh_options");
-
- torture_create_case_fixture(s, "torture_options_set_host",
- torture_options_set_host, setup, teardown);
- torture_create_case_fixture(s, "torture_options_set_port",
- torture_options_set_port, setup, teardown);
- torture_create_case_fixture(s, "torture_options_set_fd",
- torture_options_set_fd, setup, teardown);
- torture_create_case_fixture(s, "torture_options_set_user",
- torture_options_set_user, setup_passwd, teardown);
- torture_create_case_fixture(s, "torture_options_set_identity",
- torture_options_set_identity, setup, teardown);
-
- return s;
-}
+int torture_run_tests(void) {
+ const UnitTest tests[] = {
+ unit_test_setup_teardown(torture_options_set_host, setup, teardown),
+ unit_test_setup_teardown(torture_options_set_port, setup, teardown),
+ unit_test_setup_teardown(torture_options_set_fd, setup, teardown),
+ unit_test_setup_teardown(torture_options_set_user, setup, teardown),
+ unit_test_setup_teardown(torture_options_set_identity, setup, teardown),
+ };
+ return run_tests(tests);
+}