convert counter_test
This commit is contained in:
@@ -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'}
|
||||
|
||||
@@ -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 $@ \
|
||||
|
||||
@@ -10,55 +10,96 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.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
|
||||
|
||||
Reference in New Issue
Block a user