]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add more unit tests for dns_qp unit
authorOndřej Surý <ondrej@isc.org>
Tue, 16 Sep 2025 10:01:44 +0000 (12:01 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 17 Sep 2025 13:58:44 +0000 (15:58 +0200)
Add basic unit tests and add missing DbC checks for mandatory
dns_qp_create() arguments.

lib/dns/qp.c
tests/dns/qp_test.c

index d27726d74f9ada81b913539779613b5a46024d3b..625e4675b3658cc0b47b779f990b729f685f4dd7 100644 (file)
@@ -1494,6 +1494,8 @@ dns_qpsnap_destroy(dns_qpmulti_t *multi, dns_qpsnap_t **qpsp) {
 void
 dns_qp_create(isc_mem_t *mctx, const dns_qpmethods_t *methods, void *uctx,
              dns_qp_t **qptp) {
+       REQUIRE(mctx != NULL);
+       REQUIRE(methods != NULL);
        REQUIRE(qptp != NULL && *qptp == NULL);
 
        dns_qp_t *qp = isc_mem_get(mctx, sizeof(*qp));
index e93d20040da06628c91867803822a04e84cdb7a4..e6729056e993be36adc76f3f21551daf9c000cef 100644 (file)
 #include <tests/dns.h>
 #include <tests/qp.h>
 
+#define DONT_REORDER
+
+#include "../qp.c"
+
 bool verbose = false;
 
 ISC_RUN_TEST_IMPL(qpkey_name) {
@@ -2059,7 +2063,39 @@ ISC_RUN_TEST_IMPL(qpkey_delete) {
        dns_qp_destroy(&qp);
 }
 
+ISC_RUN_TEST_IMPL(qp_basics) {
+       dns_qp_t *qp = NULL;
+       expect_assert_failure(
+               dns_qp_create(isc_g_mctx, &string_methods, NULL, NULL));
+       expect_assert_failure(dns_qp_create(NULL, &string_methods, NULL, &qp));
+       expect_assert_failure(dns_qp_create(isc_g_mctx, NULL, NULL, &qp));
+
+       qp = NULL;
+       dns_qp_create(isc_g_mctx, &string_methods, NULL, &qp);
+       assert_non_null(qp);
+
+       dns_qp_destroy(&qp);
+       assert_null(qp);
+}
+
+ISC_RUN_TEST_IMPL(qp_memusage) {
+       dns_qp_t *qp = NULL;
+       dns_qp_memusage_t mu;
+
+       dns_qp_create(isc_g_mctx, &string_methods, NULL, &qp);
+       assert_non_null(qp);
+
+       mu = dns_qp_memusage(qp);
+       assert_int_equal(mu.leaves, 0);
+       assert_int_equal(mu.used, 0);
+
+       dns_qp_destroy(&qp);
+       assert_null(qp);
+}
+
 ISC_TEST_LIST_START
+ISC_TEST_ENTRY(qp_basics)
+ISC_TEST_ENTRY(qp_memusage)
 ISC_TEST_ENTRY(qpkey_name)
 ISC_TEST_ENTRY(qpkey_sort)
 ISC_TEST_ENTRY(qpiter)