Commit 5fcdb091 authored by Mark Andrews's avatar Mark Andrews
Browse files

4752. [test] Add unit test for isc_net_pton. [RT #46171]

parent 0bb08908
4752. [test] Add unit test for isc_net_pton. [RT #46171]
4751. [func] "dnssec-signzone -S" can now automatically add parent
synchronization records (CDS and CDNSKEY) according
to key metadata set using the -Psync and -Dsync
......
......@@ -173,7 +173,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
tp += strlen(tp);
break;
}
INSIST((tp - tmp) < sizeof(tmp));
INSIST((size_t)(tp - tmp) < sizeof(tmp));
tp += snprintf(tp, sizeof(tmp) - (tp - tmp), "%x", words[i]);
}
/* Was it a trailing run of 0x00's? */
......
......@@ -9,6 +9,7 @@ tp: errno_test
tp: file_test
tp: hash_test
tp: ht_test
tp: inet_ntop_test
tp: lex_test
tp: mem_test
tp: netaddr_test
......
......@@ -27,20 +27,21 @@ LIBS = @LIBS@ @ATFLIBS@
OBJS = isctest.@O@
SRCS = isctest.c aes_test.c buffer_test.c counter_test.c \
errno_test.c file_test.c hash_test.c ht_test.c \
lex_test.c mem_test.c netaddr_test.c parse_test.c \
pool_test.c print_test.c queue_test.c radix_test.c \
random_test.c regex_test.c result_test.c safe_test.c \
sockaddr_test.c socket_test.c socket_test.c \
inet_ntop_test.c lex_test.c mem_test.c netaddr_test.c \
parse_test.c pool_test.c print_test.c queue_test.c \
radix_test.c random_test.c regex_test.c result_test.c \
safe_test.c sockaddr_test.c socket_test.c socket_test.c \
symtab_test.c task_test.c taskpool_test.c time_test.c
SUBDIRS =
TARGETS = aes_test@EXEEXT@ buffer_test@EXEEXT@ counter_test@EXEEXT@ \
errno_test@EXEEXT@ file_test@EXEEXT@ hash_test@EXEEXT@ \
ht_test@EXEEXT@ lex_test@EXEEXT@ mem_test@EXEEXT@ \
netaddr_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
print_test@EXEEXT@ queue_test@EXEEXT@ radix_test@EXEEXT@ \
random_test@EXEEXT@ regex_test@EXEEXT@ result_test@EXEEXT@ \
safe_test@EXEEXT@ sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \
ht_test@EXEEXT@ inet_ntop_test@EXEEXT@ lex_test@EXEEXT@ \
mem_test@EXEEXT@ netaddr_test@EXEEXT@ parse_test@EXEEXT@ \
pool_test@EXEEXT@ print_test@EXEEXT@ queue_test@EXEEXT@ \
radix_test@EXEEXT@ random_test@EXEEXT@ regex_test@EXEEXT@ \
result_test@EXEEXT@ safe_test@EXEEXT@ \
sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \
socket_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \
taskpool_test@EXEEXT@ time_test@EXEEXT@
......@@ -74,6 +75,11 @@ ht_test@EXEEXT@: ht_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
ht_test.@O@ ${ISCLIBS} ${LIBS}
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}
lex_test@EXEEXT@: lex_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
lex_test.@O@ ${ISCLIBS} ${LIBS}
......
/*
* Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config.h>
#include <atf-c.h>
/*
* Force the prototype for isc_net_ntop to be declared.
*/
#include <isc/platform.h>
#undef ISC_PLATFORM_NEEDNTOP
#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) {
char buf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
int r;
size_t i;
unsigned char abuf[16];
struct {
int family;
const char * address;
} testdata[] = {
{ AF_INET, "0.0.0.0" },
{ AF_INET, "0.1.0.0" },
{ AF_INET, "0.0.2.0" },
{ AF_INET, "0.0.0.3" },
{ AF_INET, "255.255.255.255" },
{ AF_INET6, "::" },
{ AF_INET6, "::1.2.3.4" },
{ AF_INET6, "::ffff:1.2.3.4" },
{ AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" }
};
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);
isc_net_ntop(testdata[i].family, abuf, buf, sizeof(buf));
ATF_CHECK_STREQ(buf, testdata[i].address);
}
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_net_ntop);
return (atf_no_error());
}
Markdown is supported
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