diff options
author | Roman Yepishev <rye@keypressure.com> | 2016-02-27 11:45:02 -0500 |
---|---|---|
committer | Roman Yepishev <rye@keypressure.com> | 2016-02-27 11:45:02 -0500 |
commit | 9035325e566c47e83700f88b1ff6376dce0068e8 (patch) | |
tree | a28a96ae1868470e66272d63492e9c64f248bfa8 /auto_tests/network_test.c | |
parent | 72b1a17cc28c9a5a653823336bf0a495f6f271b1 (diff) |
Remove magic numbers from addr_resolve
* Add #defines for INET/INET6 returns
* Remove magic number 3 - exact AF_INET/INET6 result found.
* Updated network_test.c
Diffstat (limited to 'auto_tests/network_test.c')
-rw-r--r-- | auto_tests/network_test.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index c1ac8084..adf0189a 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -28,7 +28,7 @@ START_TEST(test_addr_resolv_localhost) | |||
28 | int localhost_split = 0; | 28 | int localhost_split = 0; |
29 | 29 | ||
30 | IP ip; | 30 | IP ip; |
31 | ip_init(&ip, 0); | 31 | ip_init(&ip, /* ipv6? */ 0); |
32 | 32 | ||
33 | int res = addr_resolve(localhost, &ip, NULL); | 33 | int res = addr_resolve(localhost, &ip, NULL); |
34 | 34 | ||
@@ -39,10 +39,10 @@ START_TEST(test_addr_resolv_localhost) | |||
39 | ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(ip.ip4.in_addr)); | 39 | ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(ip.ip4.in_addr)); |
40 | } | 40 | } |
41 | 41 | ||
42 | ip_init(&ip, 1); | 42 | ip_init(&ip, /* ipv6? */ 1); |
43 | res = addr_resolve(localhost, &ip, NULL); | 43 | res = addr_resolve(localhost, &ip, NULL); |
44 | 44 | ||
45 | if (res < 1) { | 45 | if (!(res & TOX_ADDR_RESOLVE_INET6)) { |
46 | res = addr_resolve("ip6-localhost", &ip, NULL); | 46 | res = addr_resolve("ip6-localhost", &ip, NULL); |
47 | localhost_split = 1; | 47 | localhost_split = 1; |
48 | } | 48 | } |
@@ -50,12 +50,12 @@ START_TEST(test_addr_resolv_localhost) | |||
50 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | 50 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); |
51 | 51 | ||
52 | if (res > 0) { | 52 | if (res > 0) { |
53 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); | 53 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6 (%u), got %u.", AF_INET6, ip.family); |
54 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); | 54 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); |
55 | } | 55 | } |
56 | 56 | ||
57 | if (!localhost_split) { | 57 | if (!localhost_split) { |
58 | ip_init(&ip, 1); | 58 | ip_init(&ip, /* ipv6? */ 1); |
59 | ip.family = AF_UNSPEC; | 59 | ip.family = AF_UNSPEC; |
60 | IP extra; | 60 | IP extra; |
61 | ip_reset(&extra); | 61 | ip_reset(&extra); |
@@ -63,10 +63,10 @@ START_TEST(test_addr_resolv_localhost) | |||
63 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | 63 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); |
64 | 64 | ||
65 | if (res > 0) { | 65 | if (res > 0) { |
66 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); | 66 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6 (%u), got %u.", AF_INET6, ip.family); |
67 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); | 67 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); |
68 | 68 | ||
69 | ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family); | 69 | ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET (%u), got %u.", AF_INET, extra.family); |
70 | ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr)); | 70 | ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr)); |
71 | } | 71 | } |
72 | } else { | 72 | } else { |