diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-02-27 01:07:46 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-05-20 19:35:28 +0000 |
commit | 21675ce0d2581597b0e0a727ab4cf6cfb796a037 (patch) | |
tree | e1ac4ca63c5cc2b2dc78fcd5b20a8202eab98d9d /auto_tests/network_test.c | |
parent | 4f6ab0708c85f3e3da7726f6caecc381c6d21370 (diff) |
Finish @Diadlo's network Family abstraction.
The Family stuff in toxcore is a big mess. I'm sure I saw a bunch of bugs
on the way, but I'm not verifying that code now, so the bugs stay.
Diffstat (limited to 'auto_tests/network_test.c')
-rw-r--r-- | auto_tests/network_test.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index 6f535ee1..0abd14a4 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -44,7 +44,7 @@ START_TEST(test_addr_resolv_localhost) | |||
44 | net_kill_strerror(strerror); | 44 | net_kill_strerror(strerror); |
45 | 45 | ||
46 | char ip_str[IP_NTOA_LEN]; | 46 | char ip_str[IP_NTOA_LEN]; |
47 | ck_assert_msg(ip.family == TOX_AF_INET, "Expected family TOX_AF_INET, got %u.", ip.family); | 47 | ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family TOX_AF_INET, got %u.", ip.family.value); |
48 | const uint32_t loopback = get_ip4_loopback().uint32; | 48 | const uint32_t loopback = get_ip4_loopback().uint32; |
49 | ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", | 49 | ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", |
50 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 50 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
@@ -62,7 +62,8 @@ START_TEST(test_addr_resolv_localhost) | |||
62 | ck_assert_msg(res > 0, "Resolver failed: %d, %s", error, strerror); | 62 | ck_assert_msg(res > 0, "Resolver failed: %d, %s", error, strerror); |
63 | net_kill_strerror(strerror); | 63 | net_kill_strerror(strerror); |
64 | 64 | ||
65 | ck_assert_msg(ip.family == TOX_AF_INET6, "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, ip.family); | 65 | ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, |
66 | ip.family.value); | ||
66 | IP6 ip6_loopback = get_ip6_loopback(); | 67 | IP6 ip6_loopback = get_ip6_loopback(); |
67 | ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.", | 68 | ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.", |
68 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 69 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
@@ -73,7 +74,7 @@ START_TEST(test_addr_resolv_localhost) | |||
73 | } | 74 | } |
74 | 75 | ||
75 | ip_init(&ip, 1); // ipv6enabled = 1 | 76 | ip_init(&ip, 1); // ipv6enabled = 1 |
76 | ip.family = TOX_AF_UNSPEC; | 77 | ip.family = net_family_unspec; |
77 | IP extra; | 78 | IP extra; |
78 | ip_reset(&extra); | 79 | ip_reset(&extra); |
79 | res = addr_resolve(localhost, &ip, &extra); | 80 | res = addr_resolve(localhost, &ip, &extra); |
@@ -83,15 +84,17 @@ START_TEST(test_addr_resolv_localhost) | |||
83 | net_kill_strerror(strerror); | 84 | net_kill_strerror(strerror); |
84 | 85 | ||
85 | #if USE_IPV6 | 86 | #if USE_IPV6 |
86 | ck_assert_msg(ip.family == TOX_AF_INET6, "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, ip.family); | 87 | ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family TOX_AF_INET6 (%u), got %u.", TOX_AF_INET6, |
88 | ip.family.value); | ||
87 | ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.", | 89 | ck_assert_msg(!memcmp(&ip.ip.v6, &ip6_loopback, sizeof(IP6)), "Expected ::1, got %s.", |
88 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 90 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
89 | 91 | ||
90 | ck_assert_msg(extra.family == TOX_AF_INET, "Expected family TOX_AF_INET (%u), got %u.", TOX_AF_INET, extra.family); | 92 | ck_assert_msg(net_family_is_ipv4(extra.family), "Expected family TOX_AF_INET (%d), got %u.", TOX_AF_INET, |
93 | extra.family.value); | ||
91 | ck_assert_msg(extra.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", | 94 | ck_assert_msg(extra.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", |
92 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 95 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
93 | #else | 96 | #else |
94 | ck_assert_msg(ip.family == TOX_AF_INET, "Expected family TOX_AF_INET (%u), got %u.", TOX_AF_INET, ip.family); | 97 | ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family TOX_AF_INET (%d), got %u.", TOX_AF_INET, ip.family.value); |
95 | ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", | 98 | ck_assert_msg(ip.ip.v4.uint32 == loopback, "Expected 127.0.0.1, got %s.", |
96 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); | 99 | ip_ntoa(&ip, ip_str, sizeof(ip_str))); |
97 | #endif | 100 | #endif |
@@ -114,14 +117,14 @@ START_TEST(test_ip_equal) | |||
114 | res = ip_equal(nullptr, &ip1); | 117 | res = ip_equal(nullptr, &ip1); |
115 | ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res); | 118 | ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res); |
116 | 119 | ||
117 | ip1.family = TOX_AF_INET; | 120 | ip1.family = net_family_ipv4; |
118 | ip1.ip.v4.uint32 = net_htonl(0x7F000001); | 121 | ip1.ip.v4.uint32 = net_htonl(0x7F000001); |
119 | 122 | ||
120 | res = ip_equal(&ip1, &ip2); | 123 | res = ip_equal(&ip1, &ip2); |
121 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_UNSPEC, 0} ): " | 124 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_UNSPEC, 0} ): " |
122 | "expected result 0, got %u.", res); | 125 | "expected result 0, got %u.", res); |
123 | 126 | ||
124 | ip2.family = TOX_AF_INET; | 127 | ip2.family = net_family_ipv4; |
125 | ip2.ip.v4.uint32 = net_htonl(0x7F000001); | 128 | ip2.ip.v4.uint32 = net_htonl(0x7F000001); |
126 | 129 | ||
127 | res = ip_equal(&ip1, &ip2); | 130 | res = ip_equal(&ip1, &ip2); |
@@ -134,7 +137,7 @@ START_TEST(test_ip_equal) | |||
134 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_INET, 127.0.0.2} ): " | 137 | ck_assert_msg(res == 0, "ip_equal( {TOX_AF_INET, 127.0.0.1}, {TOX_AF_INET, 127.0.0.2} ): " |
135 | "expected result 0, got %u.", res); | 138 | "expected result 0, got %u.", res); |
136 | 139 | ||
137 | ip2.family = TOX_AF_INET6; | 140 | ip2.family = net_family_ipv6; |
138 | ip2.ip.v6.uint32[0] = 0; | 141 | ip2.ip.v6.uint32[0] = 0; |
139 | ip2.ip.v6.uint32[1] = 0; | 142 | ip2.ip.v6.uint32[1] = 0; |
140 | ip2.ip.v6.uint32[2] = net_htonl(0xFFFF); | 143 | ip2.ip.v6.uint32[2] = net_htonl(0xFFFF); |