From 436d987224f8bdc4ea92a4e1af2e67d1fa40b3e8 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Thu, 15 Nov 2018 00:24:14 -0800 Subject: [PATCH] convert isc_ntop_test (cherry picked from commit b0309ae7399ed084f2e766ee2367368defb25826) --- lib/isc/tests/Kyuafile | 2 +- lib/isc/tests/Makefile.in | 5 ++-- lib/isc/tests/inet_ntop_test.c | 52 +++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/lib/isc/tests/Kyuafile b/lib/isc/tests/Kyuafile index af88b70079..649cbcf6e1 100644 --- a/lib/isc/tests/Kyuafile +++ b/lib/isc/tests/Kyuafile @@ -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'} diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index 23b67d7b44..69e6619238 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -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} \ diff --git a/lib/isc/tests/inet_ntop_test.c b/lib/isc/tests/inet_ntop_test.c index 2bfe9deb95..d2959055df 100644 --- a/lib/isc/tests/inet_ntop_test.c +++ b/lib/isc/tests/inet_ntop_test.c @@ -11,7 +11,18 @@ #include -#include +#if HAVE_CMOCKA + +#include +#include +#include +#include + +#define UNIT_TESTING +#include + +#include +#include /* * Force the prototype for isc_net_ntop to be declared. @@ -21,11 +32,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 +54,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 + +int +main(void) { + printf("1..0 # Skipped: cmocka not available\n"); + return (0); +} + +#endif