aboutsummaryrefslogtreecommitdiff
path: root/tests/record.c
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 00:25:36 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 00:25:36 +0200
commit0a7a6229dd130cf7abd4f5ddc462fe21b18d0714 (patch)
tree602ee9173982362eddf868599409053e8b29f9d5 /tests/record.c
parent35c378db771ea870c4a94ffc2331b13b3522cb3c (diff)
downloaddns-0a7a6229dd130cf7abd4f5ddc462fe21b18d0714.tar.gz
tests
Diffstat (limited to 'tests/record.c')
-rw-r--r--tests/record.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/record.c b/tests/record.c
new file mode 100644
index 0000000..f5c638b
--- /dev/null
+++ b/tests/record.c
@@ -0,0 +1,39 @@
+/*
+ * tests/record.c
+ * (c) 2021 Jonas Gunz <himself@jonasgunz.de>
+ * License: MIT
+ */
+
+#include "tests.h"
+
+#include "../src/record.h"
+
+START_TEST (test_records_from_string) {
+ ck_assert_int_eq(record_class_from_str("IN"), 1);
+ ck_assert_int_eq(record_class_from_str("hs"), 4);
+ ck_assert_int_eq(record_class_from_str("invalid"), 0);
+
+ ck_assert_int_eq(record_type_from_str("A"), 1);
+ ck_assert_int_eq(record_type_from_str("txt"), 16);
+ ck_assert_int_eq(record_type_from_str("invalid"), 0);
+} END_TEST
+
+START_TEST (test_records_handler) {
+ void* rdata = NULL;
+ ssize_t len;
+
+ len = record_rdata_from_str(&rdata, "69.69.69.68", record_class_from_str("A"));
+ ck_assert_int_eq(len,4);
+ ck_assert_uint_eq(*((uint32_t*)rdata),0x45454544);
+
+ free(rdata);
+}
+
+TCase* test_record(void) {
+ TCase *tc = tcase_create("record");
+
+ tcase_add_test(tc, test_records_from_string);
+ tcase_add_test(tc, test_records_handler);
+
+ return tc;
+}