]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test-net - Add more tests for net_str2hostport()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 13 Apr 2022 12:01:40 +0000 (15:01 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 14 Apr 2022 11:10:37 +0000 (11:10 +0000)
src/lib/test-net.c

index 7e116086638a238f8060ef158ef5cde82d7304e8..c0c290b9506ef07c8be2678c21f50bc4bf129d59 100644 (file)
@@ -98,7 +98,30 @@ static void test_net_str2hostport(void)
        in_port_t port;
 
        test_begin("net_str2hostport()");
+       /* IPv4  */
+       test_assert(net_str2hostport("127.0.0.1", 0, &host, &port) == 0 &&
+                   strcmp(host, "127.0.0.1") == 0 && port == 0);
+       test_assert(net_str2hostport("127.0.0.1", 143, &host, &port) == 0 &&
+                   strcmp(host, "127.0.0.1") == 0 && port == 143);
+       test_assert(net_str2hostport("127.0.0.1:993", 143, &host, &port) == 0 &&
+                   strcmp(host, "127.0.0.1") == 0 && port == 993);
+       test_assert(net_str2hostport("127.0.0.1:143", 0, &host, &port) == 0 &&
+                   strcmp(host, "127.0.0.1") == 0 && port == 143);
+       test_assert(net_str2hostport("*", 0, &host, &port) == 0 &&
+                   strcmp(host, "*") == 0 && port == 0);
+       test_assert(net_str2hostport("*:143", 0, &host, &port) == 0 &&
+                   strcmp(host, "*") == 0 && port == 143);
        /* [IPv6] */
+       test_assert(net_str2hostport("::", 0, &host, &port) == 0 &&
+                   strcmp(host, "::") == 0 && port == 0);
+       test_assert(net_str2hostport("[::]", 0, &host, &port) == 0 &&
+                   strcmp(host, "::") == 0 && port == 0);
+       test_assert(net_str2hostport("[::]:143", 0, &host, &port) == 0 &&
+                   strcmp(host, "::") == 0 && port == 143);
+       test_assert(net_str2hostport("[::]", 143, &host, &port) == 0 &&
+                   strcmp(host, "::") == 0 && port == 143);
+       test_assert(net_str2hostport("[::]:993", 143, &host, &port) == 0 &&
+                   strcmp(host, "::") == 0 && port == 993);
        test_assert(net_str2hostport("[1::4]", 0, &host, &port) == 0 &&
                    strcmp(host, "1::4") == 0 && port == 0);
        test_assert(net_str2hostport("[1::4]", 1234, &host, &port) == 0 &&