OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/ip_endpoint.h" | 5 #include "net/base/ip_endpoint.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <winsock2.h> | 10 #include <winsock2.h> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 const uint16_t* port_field = GetPortFieldFromSockaddr(address, address_len); | 47 const uint16_t* port_field = GetPortFieldFromSockaddr(address, address_len); |
48 if (!port_field) | 48 if (!port_field) |
49 return -1; | 49 return -1; |
50 return base::NetToHost16(*port_field); | 50 return base::NetToHost16(*port_field); |
51 } | 51 } |
52 | 52 |
53 struct TestData { | 53 struct TestData { |
54 std::string host; | 54 std::string host; |
55 std::string host_normalized; | 55 std::string host_normalized; |
56 bool ipv6; | 56 bool ipv6; |
57 IPAddressNumber ip_address; | 57 IPAddress ip_address; |
58 } tests[] = { | 58 } tests[] = { |
59 { "127.0.00.1", "127.0.0.1", false}, | 59 { "127.0.00.1", "127.0.0.1", false}, |
60 { "192.168.1.1", "192.168.1.1", false }, | 60 { "192.168.1.1", "192.168.1.1", false }, |
61 { "::1", "[::1]", true }, | 61 { "::1", "[::1]", true }, |
62 { "2001:db8:0::42", "[2001:db8::42]", true }, | 62 { "2001:db8:0::42", "[2001:db8::42]", true }, |
63 }; | 63 }; |
64 uint16_t test_count = static_cast<uint16_t>(arraysize(tests)); | 64 uint16_t test_count = static_cast<uint16_t>(arraysize(tests)); |
65 | 65 |
66 class IPEndPointTest : public PlatformTest { | 66 class IPEndPointTest : public PlatformTest { |
67 public: | 67 public: |
68 void SetUp() override { | 68 void SetUp() override { |
69 // This is where we populate the TestData. | 69 // This is where we populate the TestData. |
70 for (int index = 0; index < test_count; ++index) { | 70 for (int index = 0; index < test_count; ++index) { |
71 EXPECT_TRUE(ParseIPLiteralToNumber(tests[index].host, | 71 EXPECT_TRUE(IPAddress::FromIPLiteral(tests[index].host, |
72 &tests[index].ip_address)); | 72 &tests[index].ip_address)); |
73 } | 73 } |
74 } | 74 } |
75 }; | 75 }; |
76 | 76 |
77 TEST_F(IPEndPointTest, Constructor) { | 77 TEST_F(IPEndPointTest, Constructor) { |
78 IPEndPoint endpoint; | 78 IPEndPoint endpoint; |
79 EXPECT_EQ(0, endpoint.port()); | 79 EXPECT_EQ(0, endpoint.port()); |
80 | 80 |
81 for (uint16_t index = 0; index < test_count; ++index) { | 81 for (uint16_t index = 0; index < test_count; ++index) { |
82 IPEndPoint endpoint(tests[index].ip_address, 80); | 82 IPEndPoint endpoint(tests[index].ip_address, 80); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 IPEndPoint endpoint(tests[index].ip_address, port); | 196 IPEndPoint endpoint(tests[index].ip_address, port); |
197 const std::string result = endpoint.ToString(); | 197 const std::string result = endpoint.ToString(); |
198 EXPECT_EQ(tests[index].host_normalized + ":" + base::UintToString(port), | 198 EXPECT_EQ(tests[index].host_normalized + ":" + base::UintToString(port), |
199 result); | 199 result); |
200 } | 200 } |
201 } | 201 } |
202 | 202 |
203 } // namespace | 203 } // namespace |
204 | 204 |
205 } // namespace net | 205 } // namespace net |
OLD | NEW |