Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: net/base/address_list_unittest.cc

Issue 1565303002: Change IPEndpoint::address() to return a net::IPAddress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase for ChromeOS Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/services/network/net_address_type_converters.cc ('k') | net/base/ip_address.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/sys_byteorder.h" 8 #include "base/sys_byteorder.h"
9 #include "net/base/sockaddr_storage.h" 9 #include "net/base/sockaddr_storage.h"
10 #include "net/base/sys_addrinfo.h" 10 #include "net/base/sys_addrinfo.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (i + 1 < kNumElements) 63 if (i + 1 < kNumElements)
64 ai[i].ai_next = &ai[i + 1]; 64 ai[i].ai_next = &ai[i + 1];
65 } 65 }
66 66
67 AddressList list = AddressList::CreateFromAddrinfo(&ai[0]); 67 AddressList list = AddressList::CreateFromAddrinfo(&ai[0]);
68 68
69 ASSERT_EQ(kNumElements, list.size()); 69 ASSERT_EQ(kNumElements, list.size());
70 for (size_t i = 0; i < list.size(); ++i) { 70 for (size_t i = 0; i < list.size(); ++i) {
71 EXPECT_EQ(ADDRESS_FAMILY_IPV4, list[i].GetFamily()); 71 EXPECT_EQ(ADDRESS_FAMILY_IPV4, list[i].GetFamily());
72 // Only check the first byte of the address. 72 // Only check the first byte of the address.
73 EXPECT_EQ(i, list[i].address()[0]); 73 EXPECT_EQ(i, list[i].address().bytes()[0]);
74 EXPECT_EQ(static_cast<int>(i << 2), list[i].port()); 74 EXPECT_EQ(static_cast<int>(i << 2), list[i].port());
75 } 75 }
76 76
77 // Check if operator= works. 77 // Check if operator= works.
78 AddressList copy; 78 AddressList copy;
79 copy = list; 79 copy = list;
80 ASSERT_EQ(kNumElements, copy.size()); 80 ASSERT_EQ(kNumElements, copy.size());
81 81
82 // Check if copy is independent. 82 // Check if copy is independent.
83 copy[1] = IPEndPoint(copy[2].address(), 0xBEEF); 83 copy[1] = IPEndPoint(copy[2].address(), 0xBEEF);
84 // Original should be unchanged. 84 // Original should be unchanged.
85 EXPECT_EQ(1u, list[1].address()[0]); 85 EXPECT_EQ(1u, list[1].address().bytes()[0]);
86 EXPECT_EQ(1 << 2, list[1].port()); 86 EXPECT_EQ(1 << 2, list[1].port());
87 } 87 }
88 88
89 TEST(AddressListTest, CreateFromIPAddressList) { 89 TEST(AddressListTest, CreateFromIPAddressList) {
90 struct TestData { 90 struct TestData {
91 std::string ip_address; 91 std::string ip_address;
92 const char* in_addr; 92 const char* in_addr;
93 int ai_family; 93 int ai_family;
94 size_t ai_addrlen; 94 size_t ai_addrlen;
95 size_t in_addr_offset; 95 size_t in_addr_offset;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 AddressList test_list = AddressList::CreateFromIPAddressList(ip_list, 130 AddressList test_list = AddressList::CreateFromIPAddressList(ip_list,
131 kCanonicalName); 131 kCanonicalName);
132 std::string canonical_name; 132 std::string canonical_name;
133 EXPECT_EQ(kCanonicalName, test_list.canonical_name()); 133 EXPECT_EQ(kCanonicalName, test_list.canonical_name());
134 EXPECT_EQ(arraysize(tests), test_list.size()); 134 EXPECT_EQ(arraysize(tests), test_list.size());
135 } 135 }
136 136
137 } // namespace 137 } // namespace
138 } // namespace net 138 } // namespace net
OLDNEW
« no previous file with comments | « mojo/services/network/net_address_type_converters.cc ('k') | net/base/ip_address.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698