diff options
author | Ronny Chevalier <chevalier.ronny@gmail.com> | 2014-08-16 14:19:05 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-18 18:43:45 +0200 |
commit | 43dc004336ae0c99cac45df20e32dc7aa2e7cd0c (patch) | |
tree | 98fdcaff1c7f825df46d42d049a19421ca7c7e31 | |
parent | c16d01af5771bdc20171e81855dc1ef83326c10d (diff) |
tests: add tests for socket-util.c
add tests for:
- socket_address_is
- socket_address_is_netlink
- sockaddr_equal
-rw-r--r-- | src/test/test-socket-util.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index 4e90590599..17180db652 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -140,6 +140,24 @@ static void test_socket_address_get_path(void) { assert_se(streq(socket_address_get_path(&a), "/foo/bar")); } +static void test_socket_address_is(void) { + SocketAddress a; + + assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0); + assert_se(socket_address_is(&a, "192.168.1.1:8888", SOCK_STREAM)); + assert_se(!socket_address_is(&a, "route", SOCK_STREAM)); + assert_se(!socket_address_is(&a, "192.168.1.1:8888", SOCK_RAW)); +} + +static void test_socket_address_is_netlink(void) { + SocketAddress a; + + assert_se(socket_address_parse_netlink(&a, "route 10") >= 0); + assert_se(socket_address_is_netlink(&a, "route 10")); + assert_se(!socket_address_is_netlink(&a, "192.168.1.1:8888")); + assert_se(!socket_address_is_netlink(&a, "route 1")); +} + static void test_in_addr_prefix_intersect_one(unsigned f, const char *a, unsigned apl, const char *b, unsigned bpl, int result) { union in_addr_union ua, ub; @@ -265,6 +283,34 @@ static void test_nameinfo_pretty(void) { assert(r == 0); } +static void test_sockaddr_equal(void) { + union sockaddr_union a = { + .in.sin_family = AF_INET, + .in.sin_port = 0, + .in.sin_addr.s_addr = htonl(INADDR_ANY), + }; + union sockaddr_union b = { + .in.sin_family = AF_INET, + .in.sin_port = 0, + .in.sin_addr.s_addr = htonl(INADDR_ANY), + }; + union sockaddr_union c = { + .in.sin_family = AF_INET, + .in.sin_port = 0, + .in.sin_addr.s_addr = htonl(1234), + }; + union sockaddr_union d = { + .in6.sin6_family = AF_INET6, + .in6.sin6_port = 0, + .in6.sin6_addr = IN6ADDR_ANY_INIT, + }; + assert_se(sockaddr_equal(&a, &a)); + assert_se(sockaddr_equal(&a, &b)); + assert_se(sockaddr_equal(&d, &d)); + assert_se(!sockaddr_equal(&a, &c)); + assert_se(!sockaddr_equal(&b, &c)); +} + int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); @@ -273,11 +319,15 @@ int main(int argc, char *argv[]) { test_socket_address_parse_netlink(); test_socket_address_equal(); test_socket_address_get_path(); + test_socket_address_is(); + test_socket_address_is_netlink(); test_in_addr_prefix_intersect(); test_in_addr_prefix_next(); test_nameinfo_pretty(); + test_sockaddr_equal(); + return 0; } |