Commit 6aaaea3e authored by Evan Hunt's avatar Evan Hunt
Browse files

convert symtab_test

(cherry picked from commit 5f377136)
(cherry picked from commit 7b228848)
parent 7ba26761
......@@ -25,7 +25,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'}
......
......@@ -161,8 +161,9 @@ socket_test@EXEEXT@: socket_test.@O@ isctest.@O@ ${ISCDEPLIBS}
socket_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 $@ \
......
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment