diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2010-06-25 16:19:19 +0200 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2010-06-25 16:19:19 +0200 |
commit | 94b00cc7625bf139a72c3c8d5f8c30243319f5b4 (patch) | |
tree | f2fb01507002a4163e0ced9fbc340faed649ca16 /tests/unittests | |
parent | e4701e7c86aecc7bd201ea2ed54282f2d4737092 (diff) | |
download | libssh-94b00cc7625bf139a72c3c8d5f8c30243319f5b4.tar.gz libssh-94b00cc7625bf139a72c3c8d5f8c30243319f5b4.tar.xz libssh-94b00cc7625bf139a72c3c8d5f8c30243319f5b4.zip |
Add ssh_callbacks_exists internal macro + unittest
(first commit with eclipse helios, crossing fingers ...)
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/unittests/torture_callbacks.c | 61 |
2 files changed, 64 insertions, 2 deletions
diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index c7f2238..28aa50b 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -1,8 +1,9 @@ project(unittests C) +add_check_test(torture_callbacks torture_callbacks.c ${TORTURE_LIBRARY}) add_check_test(torture_init torture_init.c ${TORTURE_LIBRARY}) +add_check_test(torture_keyfiles torture_keyfiles.c ${TORTURE_LIBRARY}) +add_check_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY}) add_check_test(torture_list torture_list.c ${TORTURE_LIBRARY}) add_check_test(torture_misc torture_misc.c ${TORTURE_LIBRARY}) -add_check_test(torture_keyfiles torture_keyfiles.c ${TORTURE_LIBRARY}) add_check_test(torture_options torture_options.c ${TORTURE_LIBRARY}) -add_check_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY}) diff --git a/tests/unittests/torture_callbacks.c b/tests/unittests/torture_callbacks.c new file mode 100644 index 0000000..3f681e0 --- /dev/null +++ b/tests/unittests/torture_callbacks.c @@ -0,0 +1,61 @@ +#define LIBSSH_STATIC + +#include "torture.h" +#include <libssh/priv.h> +#include <libssh/callbacks.h> + +static int myauthcallback (const char *prompt, char *buf, size_t len, + int echo, int verify, void *userdata){ + (void) prompt; + (void) buf; + (void) len; + (void) echo; + (void) verify; + (void) userdata; + return 0; +} + +struct ssh_callbacks_struct callbacks = +{ + .userdata=(void *)0x0badc0de, + .auth_function=myauthcallback +}; + +static void setup(void) { + ssh_callbacks_init(&callbacks); +} + +static void teardown(void) { + +} + +START_TEST (torture_callbacks_size) +{ + ck_assert_int_ne(callbacks.size,0); +} +END_TEST + +START_TEST (torture_callbacks_exists) +{ + ck_assert_int_ne(ssh_callbacks_exists(&callbacks,auth_function),0); + ck_assert_int_eq(ssh_callbacks_exists(&callbacks,log_function),0); + /* we redefine size so auth_function is outside the range of callbacks->size */ + callbacks.size=(unsigned char *)&(callbacks.auth_function) - (unsigned char *)&callbacks; + ck_assert_int_eq(ssh_callbacks_exists(&callbacks,auth_function),0); + /* now make it one pointer bigger so we spill over the auth_function slot */ + callbacks.size += sizeof(void *); + ck_assert_int_ne(ssh_callbacks_exists(&callbacks,auth_function),0); +} +END_TEST + +Suite *torture_make_suite(void) { + Suite *s = suite_create("libssh_options"); + + torture_create_case_fixture(s, "torture_callbacks_size", + torture_callbacks_size, setup, teardown); + torture_create_case_fixture(s, "torture_callbacks_exists", + torture_callbacks_exists, setup, teardown); + + return s; +} + |