dovecot-2.2: lib: Added unit test for net_ip2addr() and fixed ne...

dovecot at dovecot.org dovecot at dovecot.org
Wed Apr 29 15:45:01 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/009648acd7fb
changeset: 18502:009648acd7fb
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Apr 29 17:43:13 2015 +0200
description:
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.

diffstat:

 src/lib/test-net.c |  25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diffs (45 lines):

diff -r 334bb95f27d4 -r 009648acd7fb src/lib/test-net.c
--- a/src/lib/test-net.c	Wed Apr 29 17:36:44 2015 +0200
+++ b/src/lib/test-net.c	Wed Apr 29 17:43:13 2015 +0200
@@ -38,6 +38,7 @@
 	unsigned int i;
 	bool success;
 
+	test_begin("net_is_in_network()");
 	for (i = 0; i < N_ELEMENTS(input); i++) {
 		test_assert(net_addr2ip(input[i].ip, &ip) == 0);
 		test_assert(net_addr2ip(input[i].net, &net_ip) == 0);
@@ -45,9 +46,33 @@
 			input[i].ret;
 		test_out(t_strdup_printf("net_is_in_network(%u)", i), success);
 	}
+	test_end();
+}
+
+static void test_net_ip2addr(void)
+{
+	struct ip_addr ip;
+
+	test_begin("net_ip2addr()");
+	test_assert(net_addr2ip("127.0.0.1", &ip) == 0 &&
+		    ip.family == AF_INET &&
+		    ip.u.ip4.s_addr == (127 | (1 << 24)));
+#ifdef HAVE_IPV6
+	test_assert(net_addr2ip("::5", &ip) == 0 &&
+		    ip.family == AF_INET6 &&
+		    ip.u.ip6.s6_addr[15] == 5);
+	test_assert(net_addr2ip("[::5]", &ip) == 0 &&
+		    ip.family == AF_INET6 &&
+		    ip.u.ip6.s6_addr[15] == 5);
+	ip.family = 123;
+	test_assert(net_addr2ip("abc", &ip) < 0 &&
+		    ip.family == 123);
+#endif
+	test_end();
 }
 
 void test_net(void)
 {
 	test_net_is_in_network();
+	test_net_ip2addr();
 }


More information about the dovecot-cvs mailing list