Mercurial > dovecot > core-2.2
annotate src/lib/test-net.c @ 22664:fea53c2725c0
director: Fix director_max_parallel_moves/kicks type
Should be uint, not time.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 09 Nov 2017 12:24:16 +0200 |
parents | da6cf4b7caf4 |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19680
diff
changeset
|
1 /* Copyright (c) 2007-2017 Dovecot authors, see the included COPYING file */ |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "test-lib.h" |
15187
02451e967a06
Renamed network.[ch] to net.[ch].
Timo Sirainen <tss@iki.fi>
parents:
14682
diff
changeset
|
4 #include "net.h" |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 struct test_net_is_in_network_input { |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 const char *ip; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 const char *net; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 unsigned int bits; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 bool ret; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 }; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 static void test_net_is_in_network(void) |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 { |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 static struct test_net_is_in_network_input input[] = { |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 { "1.2.3.4", "1.2.3.4", 32, TRUE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 { "1.2.3.4", "1.2.3.3", 32, FALSE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 { "1.2.3.4", "1.2.3.5", 32, FALSE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 { "1.2.3.4", "1.2.2.4", 32, FALSE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 { "1.2.3.4", "1.1.3.4", 32, FALSE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 { "1.2.3.4", "0.2.3.4", 32, FALSE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 { "1.2.3.253", "1.2.3.254", 31, FALSE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 { "1.2.3.254", "1.2.3.254", 31, TRUE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 { "1.2.3.255", "1.2.3.254", 31, TRUE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 { "1.2.3.255", "1.2.3.0", 24, TRUE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 { "1.2.255.255", "1.2.254.0", 23, TRUE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 { "255.255.255.255", "128.0.0.0", 1, TRUE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 { "255.255.255.255", "127.0.0.0", 1, FALSE } |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 #ifdef HAVE_IPV6 |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 , |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 { "1234:5678::abcf", "1234:5678::abce", 127, TRUE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 { "1234:5678::abcd", "1234:5678::abce", 127, FALSE }, |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 { "123e::ffff", "123e::0", 15, TRUE }, |
19535
60e922d0b318
lib: Added unit tests for net_is_in_network() about IPv4-mapped IPv6 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19534
diff
changeset
|
34 { "::ffff:1.2.3.4", "1.2.3.4", 32, TRUE }, |
60e922d0b318
lib: Added unit tests for net_is_in_network() about IPv4-mapped IPv6 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19534
diff
changeset
|
35 { "::ffff:1.2.3.4", "1.2.3.3", 32, FALSE }, |
60e922d0b318
lib: Added unit tests for net_is_in_network() about IPv4-mapped IPv6 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19534
diff
changeset
|
36 { "::ffff:1.2.3.4", "::ffff:1.2.3.4", 0, FALSE } |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 #endif |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 }; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 struct ip_addr ip, net_ip; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 unsigned int i; |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 |
18502
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
42 test_begin("net_is_in_network()"); |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 for (i = 0; i < N_ELEMENTS(input); i++) { |
14682
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
44 test_assert(net_addr2ip(input[i].ip, &ip) == 0); |
d0d7b810646b
Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
45 test_assert(net_addr2ip(input[i].net, &net_ip) == 0); |
19535
60e922d0b318
lib: Added unit tests for net_is_in_network() about IPv4-mapped IPv6 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19534
diff
changeset
|
46 test_assert_idx(net_is_in_network(&ip, &net_ip, input[i].bits) == |
60e922d0b318
lib: Added unit tests for net_is_in_network() about IPv4-mapped IPv6 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19534
diff
changeset
|
47 input[i].ret, i); |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 } |
19534
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
49 /* make sure non-IPv4 and non-IPv6 ip_addrs fail */ |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
50 test_assert(net_addr2ip("127.0.0.1", &ip) == 0); |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
51 net_ip = ip; |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
52 net_ip.family = 0; |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
53 test_assert(!net_is_in_network(&ip, &net_ip, 0)); |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
54 test_assert(!net_is_in_network(&net_ip, &ip, 0)); |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
55 #ifdef HAVE_IPV6 |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
56 test_assert(net_addr2ip("::1", &ip) == 0); |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
57 net_ip = ip; |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
58 net_ip.family = 0; |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
59 test_assert(!net_is_in_network(&ip, &net_ip, 0)); |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
60 test_assert(!net_is_in_network(&net_ip, &ip, 0)); |
25e892203e2b
lib: Fixed assert-crash with net_is_in_network(family=ipv6, family=0, ..)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
18892
diff
changeset
|
61 #endif |
18502
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
62 test_end(); |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
63 } |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
64 |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
65 static void test_net_ip2addr(void) |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
66 { |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
67 struct ip_addr ip; |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
68 |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
69 test_begin("net_ip2addr()"); |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
70 test_assert(net_addr2ip("127.0.0.1", &ip) == 0 && |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
71 ip.family == AF_INET && |
18892
b268e186d029
lib: Fixed unit test with big-endian CPUs.
Timo Sirainen <tss@iki.fi>
parents:
18502
diff
changeset
|
72 ntohl(ip.u.ip4.s_addr) == (0x7f000001)); |
18502
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
73 #ifdef HAVE_IPV6 |
22639
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
74 test_assert(net_addr2ip("2130706433", &ip) == 0 && |
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
75 ip.family == AF_INET && |
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
76 ntohl(ip.u.ip4.s_addr) == (0x7f000001)); |
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
77 test_assert(strcmp(net_ip2addr(&ip), "127.0.0.1") == 0); |
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
78 test_assert(net_addr2ip("255.254.253.252", &ip) == 0 && |
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
79 ip.family == AF_INET && |
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
80 ntohl(ip.u.ip4.s_addr) == (0xfffefdfc)); |
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
81 test_assert(strcmp(net_ip2addr(&ip), "255.254.253.252") == 0); |
18502
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
82 test_assert(net_addr2ip("::5", &ip) == 0 && |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
83 ip.family == AF_INET6 && |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
84 ip.u.ip6.s6_addr[15] == 5); |
22639
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
85 test_assert(strcmp(net_ip2addr(&ip), "::5") == 0); |
18502
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
86 test_assert(net_addr2ip("[::5]", &ip) == 0 && |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
87 ip.family == AF_INET6 && |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
88 ip.u.ip6.s6_addr[15] == 5); |
22639
da6cf4b7caf4
lib: net_addr2ip() - Optimize for parsing IPv4 addresses
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
89 test_assert(strcmp(net_ip2addr(&ip), "::5") == 0); |
18502
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
90 ip.family = 123; |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
91 test_assert(net_addr2ip("abc", &ip) < 0 && |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
92 ip.family == 123); |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
93 #endif |
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
94 test_end(); |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 } |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 |
19680
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
97 static void test_net_str2hostport(void) |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
98 { |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
99 const char *host; |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
100 in_port_t port; |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
101 |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
102 test_begin("net_str2hostport()"); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
103 /* [IPv6] */ |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
104 test_assert(net_str2hostport("[1::4]", 0, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
105 strcmp(host, "1::4") == 0 && port == 0); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
106 test_assert(net_str2hostport("[1::4]", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
107 strcmp(host, "1::4") == 0 && port == 1234); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
108 test_assert(net_str2hostport("[1::4]:78", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
109 strcmp(host, "1::4") == 0 && port == 78); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
110 host = NULL; |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
111 test_assert(net_str2hostport("[1::4]:", 1234, &host, &port) < 0 && host == NULL); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
112 test_assert(net_str2hostport("[1::4]:0", 1234, &host, &port) < 0 && host == NULL); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
113 test_assert(net_str2hostport("[1::4]:x", 1234, &host, &port) < 0 && host == NULL); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
114 /* IPv6 */ |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
115 test_assert(net_str2hostport("1::4", 0, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
116 strcmp(host, "1::4") == 0 && port == 0); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
117 test_assert(net_str2hostport("1::4", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
118 strcmp(host, "1::4") == 0 && port == 1234); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
119 /* host */ |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
120 test_assert(net_str2hostport("foo", 0, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
121 strcmp(host, "foo") == 0 && port == 0); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
122 test_assert(net_str2hostport("foo", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
123 strcmp(host, "foo") == 0 && port == 1234); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
124 test_assert(net_str2hostport("foo:78", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
125 strcmp(host, "foo") == 0 && port == 78); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
126 host = NULL; |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
127 test_assert(net_str2hostport("foo:", 1234, &host, &port) < 0 && host == NULL); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
128 test_assert(net_str2hostport("foo:0", 1234, &host, &port) < 0 && host == NULL); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
129 test_assert(net_str2hostport("foo:x", 1234, &host, &port) < 0 && host == NULL); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
130 /* edge cases with multiple ':' - currently these don't return errors, |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
131 but perhaps they should. */ |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
132 test_assert(net_str2hostport("foo::78", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
133 strcmp(host, "foo::78") == 0 && port == 1234); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
134 test_assert(net_str2hostport("::foo:78", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
135 strcmp(host, "::foo:78") == 0 && port == 1234); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
136 test_assert(net_str2hostport("[::foo]:78", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
137 strcmp(host, "::foo") == 0 && port == 78); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
138 test_assert(net_str2hostport("[::::]", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
139 strcmp(host, "::::") == 0 && port == 1234); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
140 test_assert(net_str2hostport("[::::]:78", 1234, &host, &port) == 0 && |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
141 strcmp(host, "::::") == 0 && port == 78); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
142 test_end(); |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
143 } |
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
144 |
18501
334bb95f27d4
lib: Renamed test-network to test-net
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
145 void test_net(void) |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 { |
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 test_net_is_in_network(); |
18502
009648acd7fb
lib: Added unit test for net_ip2addr() and fixed net_is_in_network() test.
Timo Sirainen <tss@iki.fi>
parents:
18501
diff
changeset
|
148 test_net_ip2addr(); |
19680
55831f9d2e66
lib: Added net_str2hostport()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
149 test_net_str2hostport(); |
9425
810e36796e3d
liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 } |