1 #include "g_sockaddrtest.h"
3 class decodenetnumTest : public sockaddrtest {
6 TEST_F(decodenetnumTest, IPv4AddressOnly) {
7 const char *str = "192.0.2.1";
11 expected.sa4.sin_family = AF_INET;
12 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
13 SET_PORT(&expected, NTP_PORT);
15 ASSERT_TRUE(decodenetnum(str, &actual));
16 EXPECT_TRUE(IsEqual(expected, actual));
19 TEST_F(decodenetnumTest, IPv4AddressWithPort) {
20 const char *str = "192.0.2.2:2000";
24 expected.sa4.sin_family = AF_INET;
25 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.2");
26 SET_PORT(&expected, 2000);
28 ASSERT_TRUE(decodenetnum(str, &actual));
29 EXPECT_TRUE(IsEqual(expected, actual));
32 TEST_F(decodenetnumTest, IPv6AddressOnly) {
33 const struct in6_addr address = {
34 0x20, 0x01, 0x0d, 0xb8,
35 0x85, 0xa3, 0x08, 0xd3,
36 0x13, 0x19, 0x8a, 0x2e,
37 0x03, 0x70, 0x73, 0x34
40 const char *str = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
44 expected.sa6.sin6_family = AF_INET6;
45 expected.sa6.sin6_addr = address;
46 SET_PORT(&expected, NTP_PORT);
48 ASSERT_TRUE(decodenetnum(str, &actual));
49 EXPECT_TRUE(IsEqual(expected, actual));
52 TEST_F(decodenetnumTest, IPv6AddressWithPort) {
53 const struct in6_addr address = {
54 0x20, 0x01, 0x0d, 0xb8,
55 0x85, 0xa3, 0x08, 0xd3,
56 0x13, 0x19, 0x8a, 0x2e,
57 0x03, 0x70, 0x73, 0x34
60 const char *str = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334]:3000";
64 expected.sa6.sin6_family = AF_INET6;
65 expected.sa6.sin6_addr = address;
66 SET_PORT(&expected, 3000);
68 ASSERT_TRUE(decodenetnum(str, &actual));
69 EXPECT_TRUE(IsEqual(expected, actual));
72 TEST_F(decodenetnumTest, IllegalAddress) {
73 const char *str = "192.0.2.270:2000";
76 ASSERT_FALSE(decodenetnum(str, &actual));
79 TEST_F(decodenetnumTest, IllegalCharInPort) {
80 /* An illegal port does not make the decodenetnum fail, but instead
81 * makes it use the standard port.
83 const char *str = "192.0.2.1:a700";
87 expected.sa4.sin_family = AF_INET;
88 expected.sa4.sin_addr.s_addr = inet_addr("192.0.2.1");
89 SET_PORT(&expected, NTP_PORT);
91 ASSERT_TRUE(decodenetnum(str, &actual));
92 EXPECT_TRUE(IsEqual(expected, actual));