William A. Kennington III | 7c9365c | 2023-06-14 17:41:13 -0700 | [diff] [blame] | 1 | #include <fmt/format.h> |
| 2 | |
William A. Kennington III | 9330c87 | 2023-01-04 15:41:53 -0800 | [diff] [blame] | 3 | #include <stdplus/net/addr/ip.hpp> |
| 4 | #include <stdplus/numeric/endian.hpp> |
| 5 | |
William A. Kennington III | 5b20b0a | 2023-07-18 13:38:37 -0700 | [diff] [blame] | 6 | #include <format> |
William A. Kennington III | 751a6cc | 2023-06-16 15:41:05 -0700 | [diff] [blame] | 7 | #include <string_view> |
| 8 | |
William A. Kennington III | 9330c87 | 2023-01-04 15:41:53 -0800 | [diff] [blame] | 9 | #include <gtest/gtest.h> |
| 10 | |
William A. Kennington III | 751a6cc | 2023-06-16 15:41:05 -0700 | [diff] [blame] | 11 | using std::literals::string_view_literals::operator""sv; |
| 12 | |
William A. Kennington III | 9330c87 | 2023-01-04 15:41:53 -0800 | [diff] [blame] | 13 | namespace stdplus |
| 14 | { |
| 15 | |
| 16 | TEST(EqualOperator, In4Addr) |
| 17 | { |
| 18 | EXPECT_EQ((In4Addr{255, 0, 255, 0}), (in_addr{hton(0xff00ff00)})); |
| 19 | EXPECT_EQ((in_addr{}), (In4Addr{})); |
| 20 | EXPECT_NE((In4Addr{1}), (In4Addr{in_addr{}})); |
| 21 | std::hash<In4Addr>{}(In4Addr{}); |
| 22 | } |
| 23 | |
William A. Kennington III | df1e473 | 2023-06-14 17:29:31 -0700 | [diff] [blame] | 24 | TEST(FromStr, In4Addr) |
| 25 | { |
| 26 | EXPECT_THROW(fromStr<In4Addr>(""), std::invalid_argument); |
| 27 | EXPECT_THROW(fromStr<In4Addr>("0"), std::invalid_argument); |
| 28 | EXPECT_THROW(fromStr<In4Addr>("0.0.0"), std::invalid_argument); |
| 29 | EXPECT_THROW(fromStr<In4Addr>("0.0.0."), std::invalid_argument); |
| 30 | EXPECT_THROW(fromStr<In4Addr>(".0.0.0"), std::invalid_argument); |
| 31 | EXPECT_THROW(fromStr<In4Addr>("0.0.0.0.0"), std::invalid_argument); |
| 32 | EXPECT_THROW(fromStr<In4Addr>("x.0.0.0"), std::invalid_argument); |
| 33 | EXPECT_THROW(fromStr<In4Addr>("ff.0.0.0"), std::invalid_argument); |
| 34 | EXPECT_THROW(fromStr<In4Addr>("256.0.0.0"), std::overflow_error); |
| 35 | |
| 36 | EXPECT_EQ((In4Addr{}), fromStr<In4Addr>("0.0.0.0")); |
| 37 | EXPECT_EQ((In4Addr{192, 168, 1, 1}), fromStr<In4Addr>("192.168.001.1")); |
William A. Kennington III | fa0b514 | 2023-06-27 00:01:34 -0700 | [diff] [blame] | 38 | |
| 39 | constexpr bool tv = detail::CompileIn4Addr("192.0.0.0").valid; |
| 40 | EXPECT_TRUE(tv); |
| 41 | constexpr bool t = "192.0.0.0"_ip4 == (In4Addr{192}); |
| 42 | EXPECT_TRUE(t); |
William A. Kennington III | df1e473 | 2023-06-14 17:29:31 -0700 | [diff] [blame] | 43 | } |
| 44 | |
William A. Kennington III | 7c9365c | 2023-06-14 17:41:13 -0700 | [diff] [blame] | 45 | TEST(ToStr, In4Addr) |
| 46 | { |
| 47 | ToStrHandle<ToStr<In4Addr>> tsh; |
| 48 | EXPECT_EQ("255.255.255.255", tsh(in_addr{0xffffffff})); |
| 49 | EXPECT_EQ("1.15.3.4", tsh(In4Addr{1, 15, 3, 4})); |
| 50 | EXPECT_EQ("0.0.0.0", tsh(In4Addr{})); |
| 51 | EXPECT_EQ("a 1.15.3.4 b", fmt::format("a {} b", In4Addr{1, 15, 3, 4})); |
William A. Kennington III | 5b20b0a | 2023-07-18 13:38:37 -0700 | [diff] [blame] | 52 | EXPECT_EQ("a 1.15.3.4 b", std::format("a {} b", In4Addr{1, 15, 3, 4})); |
William A. Kennington III | 7c9365c | 2023-06-14 17:41:13 -0700 | [diff] [blame] | 53 | } |
| 54 | |
William A. Kennington III | 9330c87 | 2023-01-04 15:41:53 -0800 | [diff] [blame] | 55 | TEST(EqualOperator, In6Addr) |
| 56 | { |
| 57 | EXPECT_EQ((In6Addr{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff}), |
| 58 | (in6_addr{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff})); |
| 59 | EXPECT_EQ((in6_addr{}), (In6Addr{})); |
| 60 | EXPECT_NE((In6Addr{1}), (In6Addr{in6_addr{}})); |
| 61 | std::hash<In6Addr>{}(In6Addr{}); |
| 62 | } |
| 63 | |
William A. Kennington III | 751a6cc | 2023-06-16 15:41:05 -0700 | [diff] [blame] | 64 | TEST(FromStr, In6Addr) |
| 65 | { |
| 66 | constexpr FromStr<In6Addr> fs; |
| 67 | EXPECT_THROW(fs(""sv), std::invalid_argument); |
| 68 | EXPECT_THROW(fs("0"sv), std::invalid_argument); |
| 69 | EXPECT_THROW(fs("0:0"sv), std::invalid_argument); |
| 70 | EXPECT_THROW(fs("0::0:"sv), std::invalid_argument); |
| 71 | EXPECT_THROW(fs("0:::"sv), std::invalid_argument); |
| 72 | EXPECT_THROW(fs(":::0"sv), std::invalid_argument); |
| 73 | EXPECT_THROW(fs("0:::0"sv), std::invalid_argument); |
| 74 | EXPECT_THROW(fs("0::0::0"sv), std::invalid_argument); |
| 75 | EXPECT_THROW(fs("1::0.0.0."sv), std::invalid_argument); |
| 76 | EXPECT_THROW(fs("1::.0.0.0"sv), std::invalid_argument); |
| 77 | EXPECT_THROW(fs("x::0"sv), std::invalid_argument); |
| 78 | EXPECT_THROW(fs("g::0"sv), std::invalid_argument); |
| 79 | EXPECT_THROW(fs("0:1:2:3:4::5:6:7"sv), std::invalid_argument); |
| 80 | EXPECT_THROW(fs("::0:1:2:3:4:5:6:7"sv), std::invalid_argument); |
| 81 | EXPECT_THROW(fs("0:1:2:3:4:5:6:7::"sv), std::invalid_argument); |
| 82 | EXPECT_THROW(fs("0:1:2:3:4:5:6:7:8"sv), std::invalid_argument); |
| 83 | EXPECT_THROW(fs("0:1:2:3:4:5:6:0.0.0.0"sv), std::invalid_argument); |
| 84 | EXPECT_THROW(fs("0:1:2:3:4:5::0.0.0.0"sv), std::invalid_argument); |
| 85 | EXPECT_THROW(fs("ffff0::0"sv), std::overflow_error); |
| 86 | |
| 87 | EXPECT_EQ((In6Addr{}), fs("::"sv)); |
| 88 | EXPECT_EQ((In6Addr{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 89 | 255, 255, 255, 255, 255}), |
| 90 | fs("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"sv)); |
| 91 | EXPECT_EQ((In6Addr{}), fs("0:0:0:0:0:0:0:0"sv)); |
William A. Kennington III | fa0b514 | 2023-06-27 00:01:34 -0700 | [diff] [blame] | 92 | EXPECT_EQ((In6Addr{0, 1}), fs("1::"sv)); |
William A. Kennington III | 751a6cc | 2023-06-16 15:41:05 -0700 | [diff] [blame] | 93 | EXPECT_EQ((In6Addr{0, 0xff}), fs("ff::"sv)); |
| 94 | EXPECT_EQ((In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff}), |
| 95 | fs("::ff"sv)); |
| 96 | EXPECT_EQ((In6Addr{0, 0, 0, 0, 0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff}), |
| 97 | fs("0:0:ff::ff"sv)); |
| 98 | EXPECT_EQ((In6Addr{0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 6, 0, 7, 0, 8}), |
| 99 | fs("1:2:3:4::6:7:8"sv)); |
| 100 | EXPECT_EQ((In6Addr{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 0}), |
| 101 | fs("1:2:3:4:5:6:7::"sv)); |
| 102 | EXPECT_EQ((In6Addr{0, 0, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8}), |
| 103 | fs("::2:3:4:5:6:7:8"sv)); |
| 104 | EXPECT_EQ( |
| 105 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 192, 168, 0, 1}), |
| 106 | fs("::ffff:192.168.0.1"sv)); |
| 107 | EXPECT_EQ((In6Addr{0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 168, 0, 1}), |
| 108 | fs("ff::255.168.0.1"sv)); |
| 109 | EXPECT_EQ((In6Addr{0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 255, 168, 0, 1}), |
| 110 | fs("0:1:2:3:4:5:255.168.0.1"sv)); |
William A. Kennington III | fa0b514 | 2023-06-27 00:01:34 -0700 | [diff] [blame] | 111 | |
| 112 | constexpr bool tv = detail::CompileIn6Addr("1::").valid; |
| 113 | EXPECT_TRUE(tv); |
| 114 | constexpr bool t = "ff02::"_ip6 == In6Addr{0xff, 2}; |
| 115 | EXPECT_TRUE(t); |
| 116 | EXPECT_EQ("1::"_ip6, (In6Addr{0, 1})); |
| 117 | EXPECT_EQ("100::"_ip6, (In6Addr{1})); |
| 118 | EXPECT_EQ("2::"_ip6, (In6Addr{0, 2})); |
| 119 | EXPECT_EQ("ff::"_ip6, (In6Addr{0, 0xff})); |
| 120 | EXPECT_EQ("::100"_ip6, |
| 121 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0})); |
| 122 | EXPECT_EQ("::1"_ip6, |
| 123 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})); |
| 124 | EXPECT_EQ("::2"_ip6, |
| 125 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2})); |
| 126 | EXPECT_EQ("::ff"_ip6, |
| 127 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff})); |
| 128 | EXPECT_EQ("1::1"_ip6, |
| 129 | (In6Addr{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})); |
| 130 | EXPECT_EQ("5::b"_ip6, |
| 131 | (In6Addr{0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xb})); |
William A. Kennington III | 751a6cc | 2023-06-16 15:41:05 -0700 | [diff] [blame] | 132 | } |
| 133 | |
William A. Kennington III | f53953b | 2023-06-16 16:05:52 -0700 | [diff] [blame] | 134 | TEST(ToStr, In6Addr) |
| 135 | { |
| 136 | ToStrHandle<ToStr<In6Addr>> tsh; |
| 137 | EXPECT_EQ("::", tsh(In6Addr{})); |
| 138 | EXPECT_EQ("ff::", tsh(In6Addr{0, 0xff})); |
| 139 | EXPECT_EQ("::ff", |
| 140 | tsh(In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff})); |
| 141 | EXPECT_EQ("0:0:ff::ff", tsh(In6Addr{0, 0, 0, 0, 0, 0xff, 0, 0, 0, 0, 0, 0, |
| 142 | 0, 0, 0, 0xff})); |
| 143 | EXPECT_EQ("::100:0:ff", |
| 144 | tsh(In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0xff})); |
| 145 | EXPECT_EQ("ff00::", tsh(In6Addr{0xff})); |
| 146 | EXPECT_EQ("1:2:3:4:5:6:7:8", |
| 147 | tsh(In6Addr{0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8})); |
| 148 | EXPECT_EQ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", |
| 149 | tsh(In6Addr{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 150 | 255, 255, 255, 255, 255})); |
| 151 | // rfc5952 4.2.2 |
| 152 | EXPECT_EQ("1:2:3:4:0:6:7:8", |
| 153 | tsh(In6Addr{0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 6, 0, 7, 0, 8})); |
| 154 | // rfc5952 4.2.3 |
| 155 | EXPECT_EQ("1::4:0:0:7:8", |
| 156 | tsh(In6Addr{0, 1, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 7, 0, 8})); |
| 157 | // rfc5952 5 |
| 158 | EXPECT_EQ("::ffff:192.168.0.1", tsh(In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 159 | 0xff, 0xff, 192, 168, 0, 1})); |
| 160 | |
| 161 | EXPECT_EQ("a ff00:: b", fmt::format("a {} b", In6Addr{0xff})); |
William A. Kennington III | 5b20b0a | 2023-07-18 13:38:37 -0700 | [diff] [blame] | 162 | EXPECT_EQ("a ff00:: b", std::format("a {} b", In6Addr{0xff})); |
William A. Kennington III | f53953b | 2023-06-16 16:05:52 -0700 | [diff] [blame] | 163 | } |
| 164 | |
William A. Kennington III | ea3aeb7 | 2023-01-05 04:22:19 -0800 | [diff] [blame] | 165 | TEST(EqualOperator, InAnyAddr) |
| 166 | { |
| 167 | EXPECT_EQ(InAnyAddr(In6Addr{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 168 | 0xff}), |
| 169 | (In6Addr{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff})); |
| 170 | EXPECT_NE(InAnyAddr(In6Addr{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 171 | 0xff}), |
| 172 | (in_addr{})); |
| 173 | EXPECT_EQ((In6Addr{}), InAnyAddr(In6Addr{})); |
| 174 | EXPECT_NE((In4Addr{}), InAnyAddr(In6Addr{})); |
| 175 | EXPECT_EQ((In4Addr{}), InAnyAddr(In4Addr{})); |
| 176 | EXPECT_NE((In6Addr{}), InAnyAddr(In4Addr{})); |
| 177 | EXPECT_EQ(InAnyAddr(In6Addr{}), (in6_addr{})); |
| 178 | EXPECT_EQ(InAnyAddr(In4Addr{}), (in_addr{})); |
| 179 | EXPECT_NE(InAnyAddr(In6Addr{1}), InAnyAddr(In6Addr{})); |
| 180 | EXPECT_EQ(InAnyAddr(In6Addr{1}), InAnyAddr(In6Addr{1})); |
| 181 | |
| 182 | std::hash<InAnyAddr>{}(In4Addr{}); |
| 183 | std::hash<InAnyAddr>{}(In6Addr{}); |
| 184 | } |
| 185 | |
William A. Kennington III | b26141d | 2023-06-16 16:13:20 -0700 | [diff] [blame] | 186 | TEST(FromStr, InAnyAddr) |
| 187 | { |
| 188 | constexpr FromStr<InAnyAddr> fs; |
| 189 | EXPECT_EQ((In4Addr{}), fs("0.0.0.0"sv)); |
| 190 | EXPECT_EQ((In6Addr{}), fs("::"sv)); |
| 191 | EXPECT_EQ( |
| 192 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 192, 168, 0, 1}), |
| 193 | fs("::ffff:192.168.0.1"sv)); |
William A. Kennington III | b396b8c | 2023-06-27 16:40:19 -0700 | [diff] [blame] | 194 | |
| 195 | constexpr bool tv = detail::CompileInAnyAddr("192.0.0.0").valid; |
| 196 | EXPECT_TRUE(tv); |
| 197 | constexpr bool tv2 = detail::CompileInAnyAddr("::").valid; |
| 198 | EXPECT_TRUE(tv2); |
| 199 | EXPECT_EQ((In4Addr{}), "0.0.0.0"_ip); |
| 200 | EXPECT_EQ((In6Addr{}), "::"_ip); |
| 201 | EXPECT_EQ("ff02::"_ip, (In6Addr{0xff, 2})); |
| 202 | EXPECT_EQ("1::"_ip, (In6Addr{0, 1})); |
| 203 | EXPECT_EQ("100::"_ip, (In6Addr{1})); |
| 204 | EXPECT_EQ("2::"_ip, (In6Addr{0, 2})); |
| 205 | EXPECT_EQ("ff::"_ip, (In6Addr{0, 0xff})); |
| 206 | EXPECT_EQ("::100"_ip, |
| 207 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0})); |
| 208 | EXPECT_EQ("::1"_ip, |
| 209 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})); |
| 210 | EXPECT_EQ("::2"_ip, |
| 211 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2})); |
| 212 | EXPECT_EQ("::ff"_ip, |
| 213 | (In6Addr{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff})); |
| 214 | EXPECT_EQ("1::1"_ip, |
| 215 | (In6Addr{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})); |
| 216 | EXPECT_EQ("5::b"_ip, |
| 217 | (In6Addr{0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xb})); |
William A. Kennington III | b26141d | 2023-06-16 16:13:20 -0700 | [diff] [blame] | 218 | } |
| 219 | |
William A. Kennington III | 5ee09cf | 2023-06-16 16:17:35 -0700 | [diff] [blame] | 220 | TEST(ToStr, InAnyAddr) |
| 221 | { |
| 222 | ToStrHandle<ToStr<InAnyAddr>> tsh; |
| 223 | EXPECT_EQ("1.15.3.4", tsh(In4Addr{1, 15, 3, 4})); |
| 224 | EXPECT_EQ("ff::", tsh(In6Addr{0, 0xff})); |
| 225 | |
| 226 | EXPECT_EQ("a ff00:: b", fmt::format("a {} b", InAnyAddr{In6Addr{0xff}})); |
William A. Kennington III | 5b20b0a | 2023-07-18 13:38:37 -0700 | [diff] [blame] | 227 | EXPECT_EQ("a ff00:: b", std::format("a {} b", InAnyAddr{In6Addr{0xff}})); |
William A. Kennington III | e38e42a | 2023-06-29 02:27:01 -0700 | [diff] [blame] | 228 | EXPECT_NE("0.0.0.0"_ip, std::optional<InAnyAddr>()); |
| 229 | EXPECT_EQ("0.0.0.0"_ip, std::optional<InAnyAddr>(In4Addr{})); |
William A. Kennington III | 5ee09cf | 2023-06-16 16:17:35 -0700 | [diff] [blame] | 230 | } |
| 231 | |
William A. Kennington III | a1323d2 | 2023-06-27 00:42:43 -0700 | [diff] [blame] | 232 | TEST(Loopback, In4Addr) |
| 233 | { |
| 234 | constexpr bool t = "127.0.0.0"_ip4.isLoopback(); |
| 235 | EXPECT_TRUE(t); |
| 236 | EXPECT_TRUE("127.0.0.1"_ip4.isLoopback()); |
| 237 | EXPECT_TRUE("127.0.0.83"_ip4.isLoopback()); |
| 238 | EXPECT_TRUE("127.253.0.0"_ip4.isLoopback()); |
| 239 | EXPECT_TRUE("127.255.255.255"_ip4.isLoopback()); |
| 240 | |
| 241 | EXPECT_FALSE("0.0.0.0"_ip4.isLoopback()); |
| 242 | EXPECT_FALSE("0.255.255.255"_ip4.isLoopback()); |
| 243 | EXPECT_FALSE("126.255.255.255"_ip4.isLoopback()); |
| 244 | EXPECT_FALSE("128.0.0.0"_ip4.isLoopback()); |
| 245 | EXPECT_FALSE("224.0.0.0"_ip4.isLoopback()); |
| 246 | EXPECT_FALSE("227.30.10.50"_ip4.isLoopback()); |
| 247 | EXPECT_FALSE("239.255.255.255"_ip4.isLoopback()); |
| 248 | EXPECT_FALSE("255.255.255.255"_ip4.isLoopback()); |
| 249 | } |
| 250 | |
| 251 | TEST(Loopback, In6Addr) |
| 252 | { |
| 253 | constexpr bool t = "::1"_ip6.isLoopback(); |
| 254 | EXPECT_TRUE(t); |
| 255 | |
| 256 | EXPECT_FALSE("::2"_ip6.isLoopback()); |
| 257 | EXPECT_FALSE("1::"_ip6.isLoopback()); |
| 258 | EXPECT_FALSE("2001:5938::fd98"_ip6.isLoopback()); |
| 259 | EXPECT_FALSE("fe80::1"_ip6.isLoopback()); |
| 260 | EXPECT_FALSE("feff:ffff:ffff:ffff::"_ip6.isLoopback()); |
| 261 | } |
| 262 | |
| 263 | TEST(Unicast, In4Addr) |
| 264 | { |
| 265 | constexpr bool t = "1.1.1.1"_ip4.isUnicast(); |
| 266 | EXPECT_TRUE(t); |
| 267 | EXPECT_TRUE("8.8.4.4"_ip4.isUnicast()); |
| 268 | EXPECT_TRUE("10.30.0.1"_ip4.isUnicast()); |
| 269 | EXPECT_TRUE("127.0.0.0"_ip4.isUnicast()); |
| 270 | EXPECT_TRUE("127.0.0.1"_ip4.isUnicast()); |
| 271 | EXPECT_TRUE("127.0.0.83"_ip4.isUnicast()); |
| 272 | EXPECT_TRUE("127.253.0.0"_ip4.isUnicast()); |
| 273 | EXPECT_TRUE("127.255.255.255"_ip4.isUnicast()); |
| 274 | EXPECT_TRUE("169.253.255.255"_ip4.isUnicast()); |
| 275 | EXPECT_TRUE("169.254.0.1"_ip4.isUnicast()); |
| 276 | EXPECT_TRUE("169.254.255.255"_ip4.isUnicast()); |
| 277 | EXPECT_TRUE("169.255.0.0"_ip4.isUnicast()); |
| 278 | EXPECT_TRUE("192.168.1.0"_ip4.isUnicast()); |
| 279 | EXPECT_TRUE("240.0.0.0"_ip4.isUnicast()); |
| 280 | EXPECT_TRUE("255.255.255.1"_ip4.isUnicast()); |
| 281 | |
| 282 | EXPECT_FALSE("0.0.0.0"_ip4.isUnicast()); |
| 283 | EXPECT_FALSE("0.255.255.255"_ip4.isUnicast()); |
| 284 | EXPECT_FALSE("224.0.0.0"_ip4.isUnicast()); |
| 285 | EXPECT_FALSE("227.30.10.50"_ip4.isUnicast()); |
| 286 | EXPECT_FALSE("239.255.255.255"_ip4.isUnicast()); |
| 287 | EXPECT_FALSE("255.255.255.255"_ip4.isUnicast()); |
| 288 | } |
| 289 | |
| 290 | TEST(Unicast, In6Addr) |
| 291 | { |
| 292 | constexpr bool t = "::2"_ip6.isUnicast(); |
| 293 | EXPECT_TRUE(t); |
| 294 | EXPECT_TRUE("::1"_ip6.isUnicast()); |
| 295 | EXPECT_TRUE("1::"_ip6.isUnicast()); |
| 296 | EXPECT_TRUE("2001:5938::fd98"_ip6.isUnicast()); |
| 297 | EXPECT_TRUE("fe80::1"_ip6.isUnicast()); |
| 298 | EXPECT_TRUE("feff:ffff:ffff:ffff::"_ip6.isUnicast()); |
| 299 | |
| 300 | EXPECT_FALSE("::"_ip6.isUnicast()); |
| 301 | EXPECT_FALSE("ff00::"_ip6.isUnicast()); |
| 302 | EXPECT_FALSE("ffff:ffff:ffff:ffff:ffff::"_ip6.isUnicast()); |
| 303 | } |
| 304 | |
William A. Kennington III | 9330c87 | 2023-01-04 15:41:53 -0800 | [diff] [blame] | 305 | } // namespace stdplus |