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/address_list.h" | 5 #include "net/base/address_list.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/host_resolver_proc.h" | 9 #include "net/base/host_resolver_proc.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 &expected_list); | 209 &expected_list); |
210 if (tests[i].is_ipv6 && rv != 0) { | 210 if (tests[i].is_ipv6 && rv != 0) { |
211 LOG(WARNING) << "Unable to resolve ip literal '" << tests[i].ip_address | 211 LOG(WARNING) << "Unable to resolve ip literal '" << tests[i].ip_address |
212 << "' test skipped."; | 212 << "' test skipped."; |
213 continue; | 213 continue; |
214 } | 214 } |
215 ASSERT_EQ(0, rv); | 215 ASSERT_EQ(0, rv); |
216 const struct addrinfo* good_ai = expected_list.head(); | 216 const struct addrinfo* good_ai = expected_list.head(); |
217 | 217 |
218 IPAddressNumber ip_number; | 218 IPAddressNumber ip_number; |
219 ParseIPLiteralToNumber(tests[i].ip_address, &ip_number); | 219 ASSERT_TRUE(ParseIPLiteralToNumber(tests[i].ip_address, &ip_number)); |
220 AddressList test_list = AddressList::CreateFromIPAddressWithCname( | 220 AddressList test_list = AddressList::CreateFromIPAddressWithCname( |
221 ip_number, 80, true); | 221 ip_number, 80, true); |
222 const struct addrinfo* test_ai = test_list.head(); | 222 const struct addrinfo* test_ai = test_list.head(); |
223 | 223 |
224 EXPECT_EQ(good_ai->ai_family, test_ai->ai_family); | 224 EXPECT_EQ(good_ai->ai_family, test_ai->ai_family); |
225 EXPECT_EQ(good_ai->ai_socktype, test_ai->ai_socktype); | 225 EXPECT_EQ(good_ai->ai_socktype, test_ai->ai_socktype); |
226 EXPECT_EQ(good_ai->ai_addrlen, test_ai->ai_addrlen); | 226 EXPECT_EQ(good_ai->ai_addrlen, test_ai->ai_addrlen); |
227 size_t sockaddr_size = | 227 size_t sockaddr_size = |
228 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) : | 228 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) : |
229 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0; | 229 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 sizeof(struct in6_addr), | 298 sizeof(struct in6_addr), |
299 }, | 299 }, |
300 { "192.168.1.1", | 300 { "192.168.1.1", |
301 "\xc0\xa8\x01\x01", | 301 "\xc0\xa8\x01\x01", |
302 AF_INET, | 302 AF_INET, |
303 sizeof(struct sockaddr_in), | 303 sizeof(struct sockaddr_in), |
304 offsetof(struct sockaddr_in, sin_addr), | 304 offsetof(struct sockaddr_in, sin_addr), |
305 sizeof(struct in_addr), | 305 sizeof(struct in_addr), |
306 }, | 306 }, |
307 }; | 307 }; |
308 const uint16 kPort = 80; | 308 const std::string kCanonicalName = "canonical.example.com"; |
309 | 309 |
310 // Construct a list of ip addresses. | 310 // Construct a list of ip addresses. |
311 IPAddressList ip_list; | 311 IPAddressList ip_list; |
312 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 312 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
313 IPAddressNumber ip_number; | 313 IPAddressNumber ip_number; |
314 ParseIPLiteralToNumber(tests[i].ip_address, &ip_number); | 314 ASSERT_TRUE(ParseIPLiteralToNumber(tests[i].ip_address, &ip_number)); |
315 ip_list.push_back(ip_number); | 315 ip_list.push_back(ip_number); |
316 } | 316 } |
317 | 317 |
318 AddressList test_list = AddressList::CreateFromIPAddressList(ip_list, kPort); | 318 AddressList test_list = AddressList::CreateFromIPAddressList(ip_list, |
319 EXPECT_EQ(kPort, test_list.GetPort()); | 319 kCanonicalName); |
| 320 std::string canonical_name; |
| 321 EXPECT_TRUE(test_list.GetCanonicalName(&canonical_name)); |
| 322 EXPECT_EQ(kCanonicalName, canonical_name); |
320 | 323 |
321 // Make sure that CreateFromIPAddressList has created an addrinfo | 324 // Make sure that CreateFromIPAddressList has created an addrinfo |
322 // chain of exactly the same length as the |tests| with correct content. | 325 // chain of exactly the same length as the |tests| with correct content. |
323 const struct addrinfo* next_ai = test_list.head(); | 326 const struct addrinfo* next_ai = test_list.head(); |
324 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 327 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
325 ASSERT_TRUE(next_ai != NULL); | 328 ASSERT_TRUE(next_ai != NULL); |
326 EXPECT_EQ(tests[i].ai_family, next_ai->ai_family); | 329 EXPECT_EQ(tests[i].ai_family, next_ai->ai_family); |
327 EXPECT_EQ(tests[i].ai_addrlen, static_cast<size_t>(next_ai->ai_addrlen)); | 330 EXPECT_EQ(tests[i].ai_addrlen, static_cast<size_t>(next_ai->ai_addrlen)); |
328 | 331 |
329 char* ai_addr = reinterpret_cast<char*>(next_ai->ai_addr); | 332 char* ai_addr = reinterpret_cast<char*>(next_ai->ai_addr); |
330 int rv = memcmp(tests[i].in_addr, | 333 int rv = memcmp(tests[i].in_addr, |
331 ai_addr + tests[i].in_addr_offset, | 334 ai_addr + tests[i].in_addr_offset, |
332 tests[i].in_addr_size); | 335 tests[i].in_addr_size); |
333 EXPECT_EQ(0, rv); | 336 EXPECT_EQ(0, rv); |
334 next_ai = next_ai->ai_next; | 337 next_ai = next_ai->ai_next; |
335 } | 338 } |
336 EXPECT_EQ(NULL, next_ai); | 339 EXPECT_EQ(NULL, next_ai); |
337 } | 340 } |
338 | 341 |
339 } // namespace | 342 } // namespace |
340 } // namespace net | 343 } // namespace net |
OLD | NEW |