1
1
libssh/tests/unittests/torture_list.c

87 строки
2.4 KiB
C
Исходник Обычный вид История

2010-03-06 14:55:56 +03:00
#define LIBSSH_STATIC
#include "torture.h"
#include "misc.c"
static void torture_ssh_list_new(void **state) {
2010-03-06 14:55:56 +03:00
struct ssh_list *xlist;
(void) state;
2010-03-06 14:55:56 +03:00
xlist = ssh_list_new();
assert_true(xlist != NULL);
assert_true(xlist->root == NULL);
assert_true(xlist->end == NULL);
2010-03-06 14:55:56 +03:00
ssh_list_free(xlist);
}
static void torture_ssh_list_append(void **state) {
2010-03-06 14:55:56 +03:00
struct ssh_list *xlist;
int rc;
(void) state;
2010-03-06 14:55:56 +03:00
xlist = ssh_list_new();
assert_true(xlist != NULL);
2010-03-06 14:55:56 +03:00
rc = ssh_list_append(xlist, "item1");
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");
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");
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
ssh_list_free(xlist);
}
static void torture_ssh_list_prepend(void **state) {
2010-03-06 14:55:56 +03:00
struct ssh_list *xlist;
int rc;
(void) state;
2010-03-06 14:55:56 +03:00
xlist = ssh_list_new();
assert_true(xlist != NULL);
2010-03-06 14:55:56 +03:00
rc = ssh_list_prepend(xlist, "item1");
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");
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");
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
ssh_list_free(xlist);
}
int torture_run_tests(void) {
const UnitTest tests[] = {
unit_test(torture_ssh_list_new),
unit_test(torture_ssh_list_append),
unit_test(torture_ssh_list_prepend),
};
2010-03-06 14:55:56 +03:00
return run_tests(tests);
2010-03-06 14:55:56 +03:00
}