aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-19 16:21:04 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-19 16:21:04 +0200
commit03a5fa0dfcf98fc006d90c821d2a10eafbcdc330 (patch)
tree687ea662c18dd5af61655361aff909f79fc4f076
parent1a30093457b4f50a5c28fd8923007fc0e657ba09 (diff)
downloaddns-03a5fa0dfcf98fc006d90c821d2a10eafbcdc330.tar.gz
zonefile: tests
-rw-r--r--tests/main.c1
-rw-r--r--tests/tests.h1
-rw-r--r--tests/zonefile.c44
3 files changed, 46 insertions, 0 deletions
diff --git a/tests/main.c b/tests/main.c
index 3f60a3a..8dbe07e 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -19,6 +19,7 @@ int main() {
suite_add_tcase(s, test_dns());
suite_add_tcase(s, test_tree());
+ suite_add_tcase(s, test_zonefile());
sr = srunner_create(s);
srunner_run_all(sr,CK_VERBOSE);
diff --git a/tests/tests.h b/tests/tests.h
index c3f576e..96ae1d6 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -14,3 +14,4 @@
TCase* test_dns(void);
TCase* test_tree(void);
+TCase* test_zonefile(void);
diff --git a/tests/zonefile.c b/tests/zonefile.c
new file mode 100644
index 0000000..a8004f9
--- /dev/null
+++ b/tests/zonefile.c
@@ -0,0 +1,44 @@
+/*
+ * tests/zonefile.c
+ * (c) 2021 Jonas Gunz <himself@jonasgunz.de>
+ * License: MIT
+ */
+
+#include "tests.h"
+
+#include "../src/zonefile.h"
+
+START_TEST (test_zonefile_string_split) {
+ int i, len;
+ const char* const refstr = "this is a test";
+ char* str;
+ unsigned long str_len;
+ char* parts[4];
+ char* expected_parts[4] = {
+ "this", "is", "a", "test"
+ };
+
+ str_len = strlen(refstr) + 1;
+
+ str = malloc(str_len);
+ strncpy(str, refstr, str_len);
+
+ for (i=0; i<4; i++)
+ parts[i] = NULL;
+
+ len = zonefile_string_split(parts, 4, str, ' ');
+ ck_assert_int_eq(len, 4);
+
+ for (i=0; i<4; i++)
+ ck_assert_str_eq(parts[i], expected_parts[i]);
+
+ free(str);
+} END_TEST
+
+TCase* test_zonefile(void) {
+ TCase *tc = tcase_create("DNS");
+
+ tcase_add_test(tc, test_zonefile_string_split);
+
+ return tc;
+}