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 287 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 ParseIPLiteralToNumber(tests[i].ip_address, &ip_number); |
mmenke
2012/02/14 18:46:00
nit: While you're here, might want to ASSERT_TRUE
| |
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 |