]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
convert symtab_test
authorEvan Hunt <each@isc.org>
Wed, 24 Oct 2018 05:52:30 +0000 (22:52 -0700)
committerEvan Hunt <each@isc.org>
Thu, 15 Nov 2018 04:17:04 +0000 (20:17 -0800)
lib/isc/tests/Kyuafile
lib/isc/tests/Makefile.in
lib/isc/tests/symtab_test.c

index dfa3e3e7ad1f8f5ad3cec2c3eef77ab03ab72867..a24014c02af5fd2019068c4d16566aa5766d72e7 100644 (file)
@@ -23,7 +23,7 @@ tap_test_program{name='result_test'}
 tap_test_program{name='safe_test'}
 atf_test_program{name='sockaddr_test'}
 atf_test_program{name='socket_test'}
-atf_test_program{name='symtab_test'}
+tap_test_program{name='symtab_test'}
 atf_test_program{name='task_test'}
 atf_test_program{name='taskpool_test'}
 atf_test_program{name='time_test'}
index b7ea4027c3c96e76e4a3478bd0939c27330b119d..ee4043db4dae590a7d3e15f7fef5ffbd71951eba 100644 (file)
@@ -162,8 +162,9 @@ sockaddr_test@EXEEXT@: sockaddr_test.@O@ isctest.@O@ ${ISCDEPLIBS}
                        sockaddr_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
 
 symtab_test@EXEEXT@: symtab_test.@O@ isctest.@O@ ${ISCDEPLIBS}
-       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
-                       symtab_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
+       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
+               ${LDFLAGS} -o $@ symtab_test.@O@ isctest.@O@ \
+               ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
 
 task_test@EXEEXT@: task_test.@O@ isctest.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
index a50553b20f7fcfc149709faf70a57c731d5c495b..3503952251bdb7732a5f14a7e6a21555a94c622e 100644 (file)
@@ -9,51 +9,71 @@
  * information regarding copyright ownership.
  */
 
-/*! \file */
-
 #include <config.h>
 
-#include <atf-c.h>
+#if HAVE_CMOCKA
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
 
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
+#define UNIT_TESTING
+#include <cmocka.h>
+
 #include <isc/symtab.h>
 #include <isc/print.h>
+#include <isc/util.h>
 
 #include "isctest.h"
 
+static int
+_setup(void **state) {
+       isc_result_t result;
+
+       UNUSED(state);
+
+       result = isc_test_begin(NULL, true, 0);
+       assert_int_equal(result, ISC_R_SUCCESS);
+
+       return (0);
+}
+
+static int
+_teardown(void **state) {
+       UNUSED(state);
+
+       isc_test_end();
+
+       return (0);
+}
+
 static void
 undefine(char *key, unsigned int type, isc_symvalue_t value, void *arg) {
        UNUSED(arg);
 
-       ATF_REQUIRE_EQ(type, 1);
+       assert_int_equal(type, 1);
        isc_mem_free(mctx, key);
        isc_mem_free(mctx, value.as_pointer);
 }
 
-/*
- * Individual unit tests
- */
-
-ATF_TC(symtab_grow);
-ATF_TC_HEAD(symtab_grow, tc) {
-       atf_tc_set_md_var(tc, "descr", "symbol table growth");
-}
-ATF_TC_BODY(symtab_grow, tc) {
+/* test symbol table growth */
+static void
+symtab_grow(void **state) {
        isc_result_t result;
        isc_symtab_t *st = NULL;
        isc_symvalue_t value;
        isc_symexists_t policy = isc_symexists_reject;
        int i;
 
-       UNUSED(tc);
-
-       result = isc_test_begin(NULL, true, 0);
-       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       UNUSED(state);
 
        result = isc_symtab_create(mctx, 3, undefine, NULL, false, &st);
-       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-       ATF_REQUIRE(st != NULL);
+       assert_int_equal(result, ISC_R_SUCCESS);
+       assert_non_null(st);
 
        /* Nothing should be in the table yet */
 
@@ -66,11 +86,11 @@ ATF_TC_BODY(symtab_grow, tc) {
 
                snprintf(str, sizeof(str), "%04x", i);
                key = isc_mem_strdup(mctx, str);
-               ATF_REQUIRE(key != NULL);
+               assert_non_null(key);
                value.as_pointer = isc_mem_strdup(mctx, str);
-               ATF_REQUIRE(value.as_pointer != NULL);
+               assert_non_null(value.as_pointer);
                result = isc_symtab_define(st, key, 1, value, policy);
-               ATF_CHECK_EQ(result, ISC_R_SUCCESS);
+               assert_int_equal(result, ISC_R_SUCCESS);
                if (result != ISC_R_SUCCESS)
                        undefine(key, 1, value, NULL);
        }
@@ -83,11 +103,11 @@ ATF_TC_BODY(symtab_grow, tc) {
 
                snprintf(str, sizeof(str), "%04x", i);
                key = isc_mem_strdup(mctx, str);
-               ATF_REQUIRE(key != NULL);
+               assert_non_null(key);
                value.as_pointer = isc_mem_strdup(mctx, str);
-               ATF_REQUIRE(value.as_pointer != NULL);
+               assert_non_null(value.as_pointer);
                result = isc_symtab_define(st, key, 1, value, policy);
-               ATF_CHECK_EQ(result, ISC_R_EXISTS);
+               assert_int_equal(result, ISC_R_EXISTS);
                undefine(key, 1, value, NULL);
        }
 
@@ -99,8 +119,8 @@ ATF_TC_BODY(symtab_grow, tc) {
 
                snprintf(str, sizeof(str), "%04x", i);
                result = isc_symtab_lookup(st, str, 0, &value);
-               ATF_CHECK_EQ(result, ISC_R_SUCCESS);
-               ATF_CHECK_STREQ(str, (char *)value.as_pointer);
+               assert_int_equal(result, ISC_R_SUCCESS);
+               assert_string_equal(str, (char *)value.as_pointer);
        }
 
        /*
@@ -111,7 +131,7 @@ ATF_TC_BODY(symtab_grow, tc) {
 
                snprintf(str, sizeof(str), "%04x", i);
                result = isc_symtab_undefine(st, str, 1);
-               ATF_CHECK_EQ(result, ISC_R_SUCCESS);
+               assert_int_equal(result, ISC_R_SUCCESS);
        }
 
        /*
@@ -122,19 +142,30 @@ ATF_TC_BODY(symtab_grow, tc) {
 
                snprintf(str, sizeof(str), "%04x", i);
                result = isc_symtab_lookup(st, str, 0, &value);
-               ATF_CHECK_EQ(result, ISC_R_NOTFOUND);
+               assert_int_equal(result, ISC_R_NOTFOUND);
        }
 
        isc_symtab_destroy(&st);
-       isc_test_end();
 }
 
-/*
- * Main
- */
-ATF_TP_ADD_TCS(tp) {
-       ATF_TP_ADD_TC(tp, symtab_grow);
+int
+main(void) {
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test_setup_teardown(symtab_grow,
+                                               _setup, _teardown),
+       };
+
+       return (cmocka_run_group_tests(tests, NULL, NULL));
+}
+
+#else /* HAVE_CMOCKA */
+
+#include <stdio.h>
 
-       return (atf_no_error());
+int
+main(void) {
+       printf("1..0 # Skipped: cmocka not available\n");
+       return (0);
 }
 
+#endif