]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4752. [test] Add unit test for isc_net_pton. [RT #46171]
authorMark Andrews <marka@isc.org>
Wed, 4 Oct 2017 03:10:40 +0000 (14:10 +1100)
committerMark Andrews <marka@isc.org>
Wed, 4 Oct 2017 03:10:40 +0000 (14:10 +1100)
CHANGES
lib/isc/inet_ntop.c
lib/isc/tests/Atffile
lib/isc/tests/Makefile.in
lib/isc/tests/inet_ntop_test.c [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index bad33a357fe9c9581e3da04eb64394fe48dcd339..ed28738e4edfe0a16a0601e5de75586218003b8f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+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
index a63f0587daa3691c379f9165219ef349dec5cab5..21d5f4b7de49396dceb128b7d64756caf3b45cc5 100644 (file)
@@ -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? */
index 201a5045693f62392cd8161387ee362c2b5b04ed..c22a19d66fbb6bdfd44915507f8fe29b8c4720ec 100644 (file)
@@ -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
index 70d9af69da7754c91a716ea7b44df66057e76fde..c2cd50542271116a2968ba574f8660d0be9de807 100644 (file)
@@ -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}
diff --git a/lib/isc/tests/inet_ntop_test.c b/lib/isc/tests/inet_ntop_test.c
new file mode 100644 (file)
index 0000000..b0d0eb0
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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());
+}