]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Extend resconf_test
authorMark Andrews <marka@isc.org>
Mon, 9 Dec 2024 02:04:05 +0000 (13:04 +1100)
committerEvan Hunt <each@isc.org>
Tue, 10 Dec 2024 00:09:12 +0000 (16:09 -0800)
Update to the new unit test framework.

Add a test for an unknown directive without any arguments.

Add test for an unknown directive without arguments, followed
by a search directive.

tests/irs/resconf_test.c
tests/irs/testdata/unknown+search.conf [new file with mode: 0644]
tests/irs/testdata/unknown-with-value.conf [moved from tests/irs/testdata/unknown.conf with 100% similarity]
tests/irs/testdata/unknown-without-value.conf [new file with mode: 0644]

index ac21bbf1ddc72c465f91e9d61d3751d61032c9a4..35d966d2410e9243a9f77c56ecc245e79cf3a5e5 100644 (file)
@@ -11,8 +11,6 @@
  * information regarding copyright ownership.
  */
 
-#if HAVE_CMOCKA
-
 #include <inttypes.h>
 #include <sched.h> /* IWYU pragma: keep */
 #include <setjmp.h>
 
 #include <irs/resconf.h>
 
-static isc_mem_t *mctx = NULL;
-
-static void
-setup_test(void) {
-       isc_mem_create(&mctx);
-
-       /*
-        * the caller might run from another directory, but tests
-        * that access test data files must first chdir to the proper
-        * location.
-        */
-       assert_return_code(chdir(TESTS_DIR), 0);
-}
+#include <tests/isc.h>
 
 static isc_result_t
 check_number(unsigned int n, unsigned int expected) {
@@ -65,6 +51,24 @@ check_ndots(irs_resconf_t *resconf) {
        return check_number(irs_resconf_getndots(resconf), 2);
 }
 
+static isc_result_t
+search_example(irs_resconf_t *resconf) {
+       irs_resconf_search_t *entry;
+       irs_resconf_searchlist_t *list;
+       list = irs_resconf_getsearchlist(resconf);
+       if (list == NULL) {
+               return ISC_R_NOTFOUND;
+       }
+       entry = ISC_LIST_HEAD(*list);
+       assert_true(entry != NULL && entry->domain != NULL);
+       assert_string_equal(entry->domain, "example.com");
+
+       entry = ISC_LIST_TAIL(*list);
+       assert_true(entry != NULL && entry->domain != NULL);
+       assert_string_equal(entry->domain, "example.net");
+       return ISC_R_SUCCESS;
+}
+
 static isc_result_t
 check_options(irs_resconf_t *resconf) {
        if (irs_resconf_getattempts(resconf) != 3) {
@@ -83,8 +87,7 @@ check_options(irs_resconf_t *resconf) {
 }
 
 /* test irs_resconf_load() */
-static void
-irs_resconf_load_test(void **state) {
+ISC_RUN_TEST_IMPL(irs_resconf_load) {
        isc_result_t result;
        irs_resconf_t *resconf = NULL;
        unsigned int i;
@@ -119,18 +122,27 @@ irs_resconf_load_test(void **state) {
                  ISC_R_SUCCESS },
                { "testdata/port.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
                { "testdata/resolv.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
-               { "testdata/search.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
+               { "testdata/search.conf", ISC_R_SUCCESS, search_example,
+                 ISC_R_SUCCESS },
                { "testdata/sortlist-v4.conf", ISC_R_SUCCESS, NULL,
                  ISC_R_SUCCESS },
                { "testdata/timeout.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
-               { "testdata/unknown.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }
+               { "testdata/unknown-with-value.conf", ISC_R_SUCCESS, NULL,
+                 ISC_R_SUCCESS },
+               { "testdata/unknown-without-value.conf", ISC_R_SUCCESS, NULL,
+                 ISC_R_SUCCESS },
+               { "testdata/unknown+search.conf", ISC_R_SUCCESS, search_example,
+                 ISC_R_SUCCESS }
        };
 
        UNUSED(state);
 
-       setup_test();
+       assert_return_code(chdir(TESTS_DIR), 0);
 
        for (i = 0; i < sizeof(tests) / sizeof(tests[1]); i++) {
+               if (debug) {
+                       fprintf(stderr, "# testing '%s'\n", tests[i].file);
+               }
                result = irs_resconf_load(mctx, tests[i].file, &resconf);
                if (result != tests[i].loadres) {
                        fail_msg("# unexpected result %s loading %s",
@@ -156,27 +168,10 @@ irs_resconf_load_test(void **state) {
                        irs_resconf_destroy(&resconf);
                }
        }
-
-       isc_mem_detach(&mctx);
-}
-
-int
-main(void) {
-       const struct CMUnitTest tests[] = {
-               cmocka_unit_test(irs_resconf_load_test),
-       };
-
-       return cmocka_run_group_tests(tests, NULL, NULL);
 }
 
-#else /* HAVE_CMOCKA */
-
-#include <stdio.h>
-
-int
-main(void) {
-       printf("1..0 # Skipped: cmocka not available\n");
-       return SKIPPED_TEST_EXIT_CODE;
-}
+ISC_TEST_LIST_START
+ISC_TEST_ENTRY(irs_resconf_load)
+ISC_TEST_LIST_END
 
-#endif /* if HAVE_CMOCKA */
+ISC_TEST_MAIN
diff --git a/tests/irs/testdata/unknown+search.conf b/tests/irs/testdata/unknown+search.conf
new file mode 100644 (file)
index 0000000..7e9cec3
--- /dev/null
@@ -0,0 +1,13 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+unknown
+search example.com example.net
diff --git a/tests/irs/testdata/unknown-without-value.conf b/tests/irs/testdata/unknown-without-value.conf
new file mode 100644 (file)
index 0000000..94d12c1
--- /dev/null
@@ -0,0 +1,12 @@
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+unknown