aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 17:25:57 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 17:25:57 +0200
commit1ee4fe72a51be8a71b275cf33514eab7b2a28268 (patch)
tree958a1c2b918a02723c4440b9a9ac2826429f1756
parent75395c048e6c66b8df768c2cafb5e7d980412787 (diff)
downloaddns-1ee4fe72a51be8a71b275cf33514eab7b2a28268.tar.gz
tests: database.c
-rw-r--r--tests/database.c42
-rw-r--r--tests/zone.file4
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/database.c b/tests/database.c
new file mode 100644
index 0000000..18c7ec4
--- /dev/null
+++ b/tests/database.c
@@ -0,0 +1,42 @@
+/*
+ * tests/database.c
+ * (c) 2021 Jonas Gunz <himself@jonasgunz.de>
+ * License: MIT
+ */
+
+#include "tests.h"
+
+#include "../src/database.h"
+#include "../src/zonefile.h"
+
+START_TEST ( test_database_parse_zonefile ) {
+ int ret;
+ char qname[128];
+ int qname_len;
+ database_t db;
+ database_rdata_t data;
+
+ qname_len = fqdn_to_qname("test.example.com.", 18, qname, 128);
+ ck_assert_int_gt(qname_len, 0);
+
+ database_init( &db );
+ ck_assert_ptr_nonnull( db.zone );
+
+ ret = zonefile_to_database( &db, "tests/zone.file" );
+ ck_assert_int_eq(ret,0);
+
+ ret = database_query( &data, &db, qname, qname_len, 1, 1 );
+ ck_assert_int_eq(ret, 0);
+
+ database_destroy(&db);
+ ck_assert_ptr_null( db.zone );
+} END_TEST
+
+
+TCase* test_database(void) {
+ TCase *tc = tcase_create("Database");
+
+ tcase_add_test(tc, test_database_parse_zonefile);
+
+ return tc;
+}
diff --git a/tests/zone.file b/tests/zone.file
new file mode 100644
index 0000000..12ca15b
--- /dev/null
+++ b/tests/zone.file
@@ -0,0 +1,4 @@
+test.example.com. 3600 IN A 69.69.69.69
+test1.example.com. 3600 IN CNAME test.example.com.
+ns.example.com. 3600 IN A 69.69.69.70
+example.com. 3600 IN NS ns.example.com.