tests: Migrated torture_misc to cmockery.
Этот коммит содержится в:
родитель
d44919dfd4
Коммит
512b776245
@ -5,6 +5,6 @@ add_cmockery_test(torture_callbacks torture_callbacks.c ${TORTURE_LIBRARY})
|
|||||||
add_cmockery_test(torture_init torture_init.c ${TORTURE_LIBRARY})
|
add_cmockery_test(torture_init torture_init.c ${TORTURE_LIBRARY})
|
||||||
add_cmockery_test(torture_keyfiles torture_keyfiles.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_list torture_list.c ${TORTURE_LIBRARY})
|
||||||
#add_check_test(torture_misc torture_misc.c ${TORTURE_LIBRARY})
|
add_cmockery_test(torture_misc torture_misc.c ${TORTURE_LIBRARY})
|
||||||
#add_check_test(torture_options torture_options.c ${TORTURE_LIBRARY})
|
#add_check_test(torture_options torture_options.c ${TORTURE_LIBRARY})
|
||||||
#add_check_test(torture_rand torture_rand.c ${TORTURE_LIBRARY})
|
#add_check_test(torture_rand torture_rand.c ${TORTURE_LIBRARY})
|
||||||
|
@ -6,66 +6,70 @@
|
|||||||
|
|
||||||
#include "torture.h"
|
#include "torture.h"
|
||||||
#include "misc.c"
|
#include "misc.c"
|
||||||
#define DIR "/usr/local/bin/truc/much/.."
|
#define TORTURE_TEST_DIR "/usr/local/bin/truc/much/.."
|
||||||
|
|
||||||
ssh_session session;
|
|
||||||
|
|
||||||
static void setup(void) {
|
static void setup(void **state) {
|
||||||
session = ssh_new();
|
ssh_session session = ssh_new();
|
||||||
|
*state = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void teardown(void) {
|
static void teardown(void **state) {
|
||||||
ssh_free(session);
|
ssh_free(*state);
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST (torture_get_user_home_dir)
|
static void torture_get_user_home_dir(void **state) {
|
||||||
{
|
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
char *user;
|
char *user;
|
||||||
|
|
||||||
|
(void) state;
|
||||||
|
|
||||||
pwd = getpwuid(getuid());
|
pwd = getpwuid(getuid());
|
||||||
|
|
||||||
user = ssh_get_user_home_dir();
|
user = ssh_get_user_home_dir();
|
||||||
ck_assert_str_eq(user, pwd->pw_dir);
|
assert_string_equal(user, pwd->pw_dir);
|
||||||
|
|
||||||
SAFE_FREE(user);
|
SAFE_FREE(user);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST (torture_basename)
|
static void torture_basename(void **state) {
|
||||||
{
|
|
||||||
char *path;
|
char *path;
|
||||||
path=ssh_basename(DIR "/test");
|
|
||||||
ck_assert(path != NULL);
|
(void) state;
|
||||||
ck_assert_str_eq(path, "test");
|
|
||||||
|
path=ssh_basename(TORTURE_TEST_DIR "/test");
|
||||||
|
assert_true(path != NULL);
|
||||||
|
assert_string_equal(path, "test");
|
||||||
SAFE_FREE(path);
|
SAFE_FREE(path);
|
||||||
path=ssh_basename(DIR "/test/");
|
path=ssh_basename(TORTURE_TEST_DIR "/test/");
|
||||||
ck_assert(path != NULL);
|
assert_true(path != NULL);
|
||||||
ck_assert_str_eq(path, "test");
|
assert_string_equal(path, "test");
|
||||||
SAFE_FREE(path);
|
SAFE_FREE(path);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST (torture_dirname)
|
static void torture_dirname(void **state) {
|
||||||
{
|
|
||||||
char *path;
|
char *path;
|
||||||
path=ssh_dirname(DIR "/test");
|
|
||||||
ck_assert(path != NULL);
|
(void) state;
|
||||||
ck_assert_str_eq(path, DIR );
|
|
||||||
|
path=ssh_dirname(TORTURE_TEST_DIR "/test");
|
||||||
|
assert_true(path != NULL);
|
||||||
|
assert_string_equal(path, TORTURE_TEST_DIR );
|
||||||
SAFE_FREE(path);
|
SAFE_FREE(path);
|
||||||
path=ssh_dirname(DIR "/test/");
|
path=ssh_dirname(TORTURE_TEST_DIR "/test/");
|
||||||
ck_assert(path != NULL);
|
assert_true(path != NULL);
|
||||||
ck_assert_str_eq(path, DIR);
|
assert_string_equal(path, TORTURE_TEST_DIR);
|
||||||
SAFE_FREE(path);
|
SAFE_FREE(path);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST (torture_ntohll)
|
static void torture_ntohll(void **state) {
|
||||||
{
|
uint64_t value = 0x0123456789abcdef;
|
||||||
uint32_t sample = 1;
|
uint32_t sample = 1;
|
||||||
unsigned char *ptr = (unsigned char *) &sample;
|
unsigned char *ptr = (unsigned char *) &sample;
|
||||||
uint64_t value = 0x0123456789abcdef;
|
|
||||||
uint64_t check;
|
uint64_t check;
|
||||||
|
|
||||||
|
(void) state;
|
||||||
|
|
||||||
if (ptr[0] == 1){
|
if (ptr[0] == 1){
|
||||||
/* we're in little endian */
|
/* we're in little endian */
|
||||||
check = 0xefcdab8967452301;
|
check = 0xefcdab8967452301;
|
||||||
@ -74,36 +78,35 @@ START_TEST (torture_ntohll)
|
|||||||
check = value;
|
check = value;
|
||||||
}
|
}
|
||||||
value = ntohll(value);
|
value = ntohll(value);
|
||||||
ck_assert(value == check);
|
assert_true(value == check);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST (torture_path_expand_tilde)
|
static void torture_path_expand_tilde(void **state) {
|
||||||
{
|
|
||||||
char h[256];
|
char h[256];
|
||||||
char *d;
|
char *d;
|
||||||
|
|
||||||
|
(void) state;
|
||||||
|
|
||||||
snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME"));
|
snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME"));
|
||||||
|
|
||||||
d = ssh_path_expand_tilde("~/.ssh");
|
d = ssh_path_expand_tilde("~/.ssh");
|
||||||
ck_assert_str_eq(d, h);
|
assert_string_equal(d, h);
|
||||||
free(d);
|
free(d);
|
||||||
|
|
||||||
d = ssh_path_expand_tilde("/guru/meditation");
|
d = ssh_path_expand_tilde("/guru/meditation");
|
||||||
ck_assert_str_eq(d, "/guru/meditation");
|
assert_string_equal(d, "/guru/meditation");
|
||||||
free(d);
|
free(d);
|
||||||
|
|
||||||
snprintf(h, 256 - 1, "~%s/.ssh", getenv("USER"));
|
snprintf(h, 256 - 1, "~%s/.ssh", getenv("USER"));
|
||||||
d = ssh_path_expand_tilde(h);
|
d = ssh_path_expand_tilde(h);
|
||||||
|
|
||||||
snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME"));
|
snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME"));
|
||||||
ck_assert_str_eq(d, h);
|
assert_string_equal(d, h);
|
||||||
free(d);
|
free(d);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST (torture_path_expand_escape)
|
static void torture_path_expand_escape(void **state) {
|
||||||
{
|
ssh_session session = *state;
|
||||||
const char *s = "%d/%h/by/%r";
|
const char *s = "%d/%h/by/%r";
|
||||||
char *e;
|
char *e;
|
||||||
|
|
||||||
@ -112,36 +115,31 @@ START_TEST (torture_path_expand_escape)
|
|||||||
session->username = strdup("root");
|
session->username = strdup("root");
|
||||||
|
|
||||||
e = ssh_path_expand_escape(session, s);
|
e = ssh_path_expand_escape(session, s);
|
||||||
ck_assert_str_eq(e, "guru/meditation/by/root");
|
assert_string_equal(e, "guru/meditation/by/root");
|
||||||
free(e);
|
free(e);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
START_TEST (torture_path_expand_known_hosts)
|
static void torture_path_expand_known_hosts(void **state) {
|
||||||
{
|
ssh_session session = *state;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
session->sshdir = strdup("/home/guru/.ssh");
|
session->sshdir = strdup("/home/guru/.ssh");
|
||||||
|
|
||||||
tmp = ssh_path_expand_escape(session, "%d/known_hosts");
|
tmp = ssh_path_expand_escape(session, "%d/known_hosts");
|
||||||
ck_assert_str_eq(tmp, "/home/guru/.ssh/known_hosts");
|
assert_string_equal(tmp, "/home/guru/.ssh/known_hosts");
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
Suite *torture_make_suite(void) {
|
int torture_run_tests(void) {
|
||||||
Suite *s = suite_create("libssh_misc");
|
const UnitTest tests[] = {
|
||||||
|
unit_test(torture_get_user_home_dir),
|
||||||
|
unit_test(torture_basename),
|
||||||
|
unit_test(torture_dirname),
|
||||||
|
unit_test(torture_ntohll),
|
||||||
|
unit_test(torture_path_expand_tilde),
|
||||||
|
unit_test_setup_teardown(torture_path_expand_escape, setup, teardown),
|
||||||
|
unit_test_setup_teardown(torture_path_expand_known_hosts, setup, teardown),
|
||||||
|
};
|
||||||
|
|
||||||
torture_create_case(s, "torture_get_user_home_dir", torture_get_user_home_dir);
|
return run_tests(tests);
|
||||||
torture_create_case(s, "torture_basename", torture_basename);
|
|
||||||
torture_create_case(s, "torture_dirname", torture_dirname);
|
|
||||||
torture_create_case(s, "torture_ntohll", torture_ntohll);
|
|
||||||
torture_create_case(s, "torture_path_expand_tilde", torture_path_expand_tilde);
|
|
||||||
torture_create_case_fixture(s, "torture_path_expand_escape",
|
|
||||||
torture_path_expand_escape, setup, teardown);
|
|
||||||
torture_create_case_fixture(s, "torture_path_expand_known_hosts",
|
|
||||||
torture_path_expand_known_hosts, setup, teardown);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user