aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 21:04:13 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 21:04:13 +0200
commita0ff652261af4bebad0419aaf99ccea64c7ccf2e (patch)
tree075af89783e977d842b40d36d8c0d8eeedb8d1ae
parent9dfeeff1f11685987232f8af8fd1d3c29abb6579 (diff)
downloaddns-a0ff652261af4bebad0419aaf99ccea64c7ccf2e.tar.gz
list: tests
-rw-r--r--src/list.c6
-rw-r--r--tests/list.c40
-rw-r--r--tests/main.c1
-rw-r--r--tests/tests.h1
4 files changed, 45 insertions, 3 deletions
diff --git a/src/list.c b/src/list.c
index 6a0085f..133637b 100644
--- a/src/list.c
+++ b/src/list.c
@@ -10,12 +10,12 @@ int list_add( list_element_t** _root, void* _data ) {
list_element_t** iter = _root;
list_element_t* new_element = malloc( sizeof(list_element_t) );
- new_element->data = _data;
- new_element->next = NULL;
-
if( !new_element )
return 1;
+ new_element->data = _data;
+ new_element->next = NULL;
+
while(*iter)
iter = & (*iter)->next;
diff --git a/tests/list.c b/tests/list.c
new file mode 100644
index 0000000..25fa323
--- /dev/null
+++ b/tests/list.c
@@ -0,0 +1,40 @@
+/*
+ * tests/list.c
+ * (c) 2021 Jonas Gunz <himself@jonasgunz.de>
+ * License: All rights reserved.
+ */
+
+#include "tests.h"
+#include "../src/list.h"
+
+START_TEST ( test_list_all ) {
+ list_element_t* root = NULL;
+ unsigned int i;
+ /*int values[] = {7,1,6,8,4,5,2,0,3};*/
+ int values[] = {0,1,2,3,4,5,6,7,8};
+
+
+ for ( i=0; i<=8; i++ )
+ list_add(&root, &values[i]);
+
+
+ /* Not implemented
+ list_sort(&root);
+
+ ck_assert_int_eq( list_length(root), 9 );
+ */
+
+ for ( i=0; i<=8; i++ )
+ ck_assert_int_eq(*(int*)list_pop_front(&root), i);
+
+ /*ck_assert_int_eq( list_length(root), 0 );*/
+
+} END_TEST
+
+TCase* test_list(void) {
+ TCase *tc = tcase_create("List");
+
+ tcase_add_test(tc, test_list_all);
+
+ return tc;
+}
diff --git a/tests/main.c b/tests/main.c
index dc32e3f..4f1f465 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -22,6 +22,7 @@ int main() {
suite_add_tcase(s, test_zonefile());
suite_add_tcase(s, test_record());
suite_add_tcase(s, test_database());
+ suite_add_tcase(s, test_list());
sr = srunner_create(s);
srunner_run_all(sr,CK_VERBOSE);
diff --git a/tests/tests.h b/tests/tests.h
index 3be8b88..0cc8796 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -17,3 +17,4 @@ TCase* test_tree(void);
TCase* test_zonefile(void);
TCase* test_record(void);
TCase* test_database(void);
+TCase* test_list(void);