]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
convert counter_test
authorEvan Hunt <each@isc.org>
Wed, 24 Oct 2018 04:16:16 +0000 (21:16 -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/counter_test.c

index 18bb8c75837cfa31e278c529a11fece92b1c2f10..8de9a9167143cbeec97f8f54f2df49794d6b091d 100644 (file)
@@ -3,7 +3,7 @@ test_suite('bind9')
 
 tap_test_program{name='aes_test'}
 tap_test_program{name='buffer_test'}
-atf_test_program{name='counter_test'}
+tap_test_program{name='counter_test'}
 atf_test_program{name='errno_test'}
 atf_test_program{name='file_test'}
 atf_test_program{name='hash_test'}
index dfbd1b8dd751683e1147daca750d35ca30f79bc5..2bcdb2c092e9bb8965084c18c11e1b8361446e1e 100644 (file)
@@ -64,8 +64,9 @@ buffer_test@EXEEXT@: buffer_test.@O@ isctest.@O@ ${ISCDEPLIBS}
                ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
 
 counter_test@EXEEXT@: counter_test.@O@ isctest.@O@ ${ISCDEPLIBS}
-       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
-                       counter_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
+       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
+               ${LDFLAGS} -o $@ counter_test.@O@ isctest.@O@ \
+               ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
 
 crc64_test@EXEEXT@: crc64_test.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} ${LDFLAGS} -o $@ \
index ddcdae3595117088c1c2a29475810f92b32321e8..28c1fbb3556b473bdcea256ddb511d4e6522e9ac 100644 (file)
  */
 
 #include <config.h>
+
+#if HAVE_CMOCKA
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+
 #include <stdlib.h>
+#include <string.h>
 
-#include <atf-c.h>
+#define UNIT_TESTING
+#include <cmocka.h>
 
 #include <isc/counter.h>
 #include <isc/result.h>
+#include <isc/util.h>
 
 #include "isctest.h"
 
-ATF_TC(isc_counter);
-ATF_TC_HEAD(isc_counter, tc) {
-       atf_tc_set_md_var(tc, "descr", "isc counter object");
+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);
 }
-ATF_TC_BODY(isc_counter, tc) {
+
+static int
+_teardown(void **state) {
+       UNUSED(state);
+
+       isc_test_end();
+
+       return (0);
+}
+
+/* test isc_counter object */
+static void
+isc_counter_test(void **state) {
        isc_result_t result;
        isc_counter_t *counter = NULL;
        int i;
 
-       result = isc_test_begin(NULL, true, 0);
-       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       UNUSED(state);
 
        result = isc_counter_create(mctx, 0, &counter);
-       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       assert_int_equal(result, ISC_R_SUCCESS);
 
        for (i = 0; i < 10; i++) {
                result = isc_counter_increment(counter);
-               ATF_CHECK_EQ(result, ISC_R_SUCCESS);
+               assert_int_equal(result, ISC_R_SUCCESS);
        }
 
-       ATF_CHECK_EQ(isc_counter_used(counter), 10);
+       assert_int_equal(isc_counter_used(counter), 10);
 
        isc_counter_setlimit(counter, 15);
        for (i = 0; i < 10; i++) {
                result = isc_counter_increment(counter);
-               if (result != ISC_R_SUCCESS)
+               if (result != ISC_R_SUCCESS) {
                        break;
+               }
        }
 
-       ATF_CHECK_EQ(isc_counter_used(counter), 15);
+       assert_int_equal(isc_counter_used(counter), 15);
 
        isc_counter_detach(&counter);
-       isc_test_end();
 }
 
-/*
- * Main
- */
-ATF_TP_ADD_TCS(tp) {
-       ATF_TP_ADD_TC(tp, isc_counter);
-       return (atf_no_error());
+int
+main(void) {
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test_setup_teardown(isc_counter_test,
+                                               _setup, _teardown),
+       };
+
+       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 (0);
 }
 
+#endif