diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:41:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:41:58 +0000 |
commit | 1852910ef0fd7393da62b88aee66ee092208748e (patch) | |
tree | ad3b659dbbe622b58a5bda4fe0b5e1d80eee9277 /lib/test_rplan.c | |
parent | Initial commit. (diff) | |
download | knot-resolver-upstream.tar.xz knot-resolver-upstream.zip |
Adding upstream version 5.3.1.upstream/5.3.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/test_rplan.c')
-rw-r--r-- | lib/test_rplan.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/test_rplan.c b/lib/test_rplan.c new file mode 100644 index 0000000..e041973 --- /dev/null +++ b/lib/test_rplan.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2014-2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "tests/unit/test.h" +#include "lib/resolve.h" +#include "lib/rplan.h" + +static void test_rplan_params(void **state) +{ + /* NULL rplan */ + + assert_int_equal(kr_rplan_init(NULL, NULL, NULL), KNOT_EINVAL); + assert_null((void *)kr_rplan_push(NULL, NULL, NULL, 0, 0)); + assert_int_equal(kr_rplan_pop(NULL, NULL), KNOT_EINVAL); + assert_true(kr_rplan_empty(NULL) == true); + kr_rplan_deinit(NULL); + + /* NULL mandatory parameters */ + + struct kr_rplan rplan; + assert_int_equal(kr_rplan_init(&rplan, NULL, NULL), KNOT_EOK); + assert_null((void *)kr_rplan_push(&rplan, NULL, NULL, 0, 0)); + assert_int_equal(kr_rplan_pop(&rplan, NULL), KNOT_EINVAL); + assert_true(kr_rplan_empty(&rplan) == true); + kr_rplan_deinit(&rplan); +} + +static void test_rplan_push(void **state) +{ + knot_mm_t mm; + test_mm_ctx_init(&mm); + struct kr_request request = { + .pool = mm, + .options = { 0 }, + }; + + struct kr_rplan rplan; + kr_rplan_init(&rplan, &request, &mm); + + /* Push query. */ + assert_non_null((void *)kr_rplan_push(&rplan, NULL, (knot_dname_t *)"", 0, 0)); + + kr_rplan_deinit(&rplan); +} + +/** + * Set and clear must not omit any bit, especially around byte boundaries. + */ +static void test_rplan_flags(void **state) +{ + static struct kr_qflags f1, f2, ones, zeros; /* static => initialized to zeroes */ + assert_true(memcmp(&f1, &f2, sizeof(f1)) == 0); /* sanity check */ + memset(&ones, 0xff, sizeof(ones)); /* all ones */ + + /* test set */ + kr_qflags_set(&f1, ones); + assert_true(memcmp(&f1, &ones, sizeof(f1)) == 0); /* 1 == 1 */ + + /* test clear */ + memset(&f2, 0xff, sizeof(f2)); /* all ones */ + kr_qflags_clear(&f2, ones); + assert_true(memcmp(&f2, &zeros, sizeof(f1)) == 0); /* 0 == 0 */ +} + +int main(void) +{ + const UnitTest tests[] = { + unit_test(test_rplan_params), + unit_test(test_rplan_push), + unit_test(test_rplan_flags) + }; + + return run_tests(tests); +} |