2017-10-28 15:31:37 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-03-06 14:55:56 +03:00
|
|
|
#define LIBSSH_STATIC
|
|
|
|
|
|
|
|
#include "torture.h"
|
2011-01-01 22:22:50 +03:00
|
|
|
#include "error.c"
|
2010-03-06 14:55:56 +03:00
|
|
|
#include "misc.c"
|
|
|
|
|
2010-12-28 16:47:19 +03:00
|
|
|
static void torture_ssh_list_new(void **state) {
|
2010-03-06 14:55:56 +03:00
|
|
|
struct ssh_list *xlist;
|
|
|
|
|
2010-12-28 16:47:19 +03:00
|
|
|
(void) state;
|
|
|
|
|
2010-03-06 14:55:56 +03:00
|
|
|
xlist = ssh_list_new();
|
|
|
|
|
2019-01-15 13:19:49 +03:00
|
|
|
assert_non_null(xlist);
|
|
|
|
assert_null(xlist->root);
|
|
|
|
assert_null(xlist->end);
|
2010-03-06 14:55:56 +03:00
|
|
|
|
2018-02-02 15:06:02 +03:00
|
|
|
assert_int_equal(ssh_list_count(xlist), 0);
|
|
|
|
|
2010-03-06 14:55:56 +03:00
|
|
|
ssh_list_free(xlist);
|
|
|
|
}
|
|
|
|
|
2010-12-28 16:47:19 +03:00
|
|
|
static void torture_ssh_list_append(void **state) {
|
2010-03-06 14:55:56 +03:00
|
|
|
struct ssh_list *xlist;
|
|
|
|
int rc;
|
|
|
|
|
2010-12-28 16:47:19 +03:00
|
|
|
(void) state;
|
|
|
|
|
2010-03-06 14:55:56 +03:00
|
|
|
xlist = ssh_list_new();
|
2019-01-15 13:19:49 +03:00
|
|
|
assert_non_null(xlist);
|
2010-03-06 14:55:56 +03:00
|
|
|
|
|
|
|
rc = ssh_list_append(xlist, "item1");
|
2010-12-28 16:47:19 +03:00
|
|
|
assert_true(rc == 0);
|
|
|
|
assert_string_equal((const char *) xlist->root->data, "item1");
|
|
|
|
assert_string_equal((const char *) xlist->end->data, "item1");
|
2010-03-06 14:55:56 +03:00
|
|
|
|
|
|
|
rc = ssh_list_append(xlist, "item2");
|
2010-12-28 16:47:19 +03:00
|
|
|
assert_true(rc == 0);
|
|
|
|
assert_string_equal((const char *) xlist->root->data, "item1");
|
|
|
|
assert_string_equal((const char *) xlist->end->data, "item2");
|
2010-03-06 14:55:56 +03:00
|
|
|
|
|
|
|
rc = ssh_list_append(xlist, "item3");
|
2010-12-28 16:47:19 +03:00
|
|
|
assert_true(rc == 0);
|
|
|
|
assert_string_equal((const char *) xlist->root->data, "item1");
|
|
|
|
assert_string_equal((const char *) xlist->root->next->data, "item2");
|
|
|
|
assert_string_equal((const char *) xlist->root->next->next->data, "item3");
|
|
|
|
assert_string_equal((const char *) xlist->end->data, "item3");
|
2010-03-06 14:55:56 +03:00
|
|
|
|
2018-02-02 15:06:02 +03:00
|
|
|
assert_int_equal(ssh_list_count(xlist), 3);
|
|
|
|
|
2010-03-06 14:55:56 +03:00
|
|
|
ssh_list_free(xlist);
|
|
|
|
}
|
|
|
|
|
2010-12-28 16:47:19 +03:00
|
|
|
static void torture_ssh_list_prepend(void **state) {
|
2010-03-06 14:55:56 +03:00
|
|
|
struct ssh_list *xlist;
|
|
|
|
int rc;
|
|
|
|
|
2010-12-28 16:47:19 +03:00
|
|
|
(void) state;
|
|
|
|
|
2010-03-06 14:55:56 +03:00
|
|
|
xlist = ssh_list_new();
|
2019-01-15 13:19:49 +03:00
|
|
|
assert_non_null(xlist);
|
2010-03-06 14:55:56 +03:00
|
|
|
|
|
|
|
rc = ssh_list_prepend(xlist, "item1");
|
2010-12-28 16:47:19 +03:00
|
|
|
assert_true(rc == 0);
|
|
|
|
assert_string_equal((const char *) xlist->root->data, "item1");
|
|
|
|
assert_string_equal((const char *) xlist->end->data, "item1");
|
2010-03-06 14:55:56 +03:00
|
|
|
|
|
|
|
rc = ssh_list_append(xlist, "item2");
|
2010-12-28 16:47:19 +03:00
|
|
|
assert_true(rc == 0);
|
|
|
|
assert_string_equal((const char *) xlist->root->data, "item1");
|
|
|
|
assert_string_equal((const char *) xlist->end->data, "item2");
|
2010-03-06 14:55:56 +03:00
|
|
|
|
|
|
|
rc = ssh_list_prepend(xlist, "item3");
|
2010-12-28 16:47:19 +03:00
|
|
|
assert_true(rc == 0);
|
|
|
|
assert_string_equal((const char *) xlist->root->data, "item3");
|
|
|
|
assert_string_equal((const char *) xlist->root->next->data, "item1");
|
|
|
|
assert_string_equal((const char *) xlist->root->next->next->data, "item2");
|
|
|
|
assert_string_equal((const char *) xlist->end->data, "item2");
|
2010-03-06 14:55:56 +03:00
|
|
|
|
2018-02-02 15:06:02 +03:00
|
|
|
assert_int_equal(ssh_list_count(xlist), 3);
|
|
|
|
|
2010-03-06 14:55:56 +03:00
|
|
|
ssh_list_free(xlist);
|
|
|
|
}
|
|
|
|
|
2010-12-28 16:47:19 +03:00
|
|
|
int torture_run_tests(void) {
|
2011-01-02 19:25:51 +03:00
|
|
|
int rc;
|
2015-09-07 11:39:51 +03:00
|
|
|
struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(torture_ssh_list_new),
|
|
|
|
cmocka_unit_test(torture_ssh_list_append),
|
|
|
|
cmocka_unit_test(torture_ssh_list_prepend),
|
2010-12-28 16:47:19 +03:00
|
|
|
};
|
2010-03-06 14:55:56 +03:00
|
|
|
|
2011-01-02 19:25:51 +03:00
|
|
|
ssh_init();
|
2014-09-02 11:07:17 +04:00
|
|
|
torture_filter_tests(tests);
|
2015-09-07 11:39:51 +03:00
|
|
|
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
2011-01-02 19:25:51 +03:00
|
|
|
ssh_finalize();
|
|
|
|
return rc;
|
2010-03-06 14:55:56 +03:00
|
|
|
}
|