Commit b0309ae7 authored by Evan Hunt's avatar Evan Hunt
Browse files

convert isc_ntop_test

parent 7bbe60ad
......@@ -10,7 +10,7 @@ tap_test_program{name='file_test'}
tap_test_program{name='hash_test'}
tap_test_program{name='heap_test'}
tap_test_program{name='ht_test'}
atf_test_program{name='inet_ntop_test'}
tap_test_program{name='inet_ntop_test'}
tap_test_program{name='lex_test'}
tap_test_program{name='mem_test'}
tap_test_program{name='netaddr_test'}
......
......@@ -96,8 +96,9 @@ ht_test@EXEEXT@: ht_test.@O@ ${ISCDEPLIBS}
inet_ntop_test.c.@O@: ${top_srcdir}/lib/isc/ntop_test.c
inet_ntop_test@EXEEXT@: inet_ntop_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
inet_ntop_test.@O@ ${ISCLIBS} ${LIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
${LDFLAGS} -o $@ inet_ntop_test.@O@ \
${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
lex_test@EXEEXT@: lex_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
......
......@@ -11,7 +11,17 @@
#include <config.h>
#include <atf-c.h>
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <string.h>
#define UNIT_TESTING
#include <cmocka.h>
#include <isc/util.h>
/*
* Force the prototype for isc_net_ntop to be declared.
......@@ -21,11 +31,9 @@
#define ISC_PLATFORM_NEEDNTOP
#include "../inet_ntop.c"
ATF_TC(isc_net_ntop);
ATF_TC_HEAD(isc_net_ntop, tc) {
atf_tc_set_md_var(tc, "descr", "isc_net_ntop implementation");
}
ATF_TC_BODY(isc_net_ntop, tc) {
/* Test isc_net_ntop implementation */
static void
isc_net_ntop_test(void **state) {
char buf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
int r;
size_t i;
......@@ -45,18 +53,33 @@ ATF_TC_BODY(isc_net_ntop, tc) {
{ AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" }
};
UNUSED(state);
for (i = 0; i < sizeof(testdata)/sizeof(testdata[0]); i++) {
r = inet_pton(testdata[i].family, testdata[i].address, abuf);
ATF_REQUIRE_EQ_MSG(r, 1, "%s", testdata[i].address);
assert_int_equal(r, 1);
isc_net_ntop(testdata[i].family, abuf, buf, sizeof(buf));
ATF_CHECK_STREQ(buf, testdata[i].address);
assert_string_equal(buf, testdata[i].address);
}
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_net_ntop);
return (atf_no_error());
int
main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_net_ntop_test),
};
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
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