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

Side by Side Diff: net/dns/address_sorter_posix_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: Fix Android Created 4 years, 11 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
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/dns/address_sorter_posix.h" 5 #include "net/dns/address_sorter_posix.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 NOTIMPLEMENTED(); 66 NOTIMPLEMENTED();
67 return ERR_NOT_IMPLEMENTED; 67 return ERR_NOT_IMPLEMENTED;
68 } 68 }
69 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override { 69 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override {
70 return NetworkChangeNotifier::kInvalidNetworkHandle; 70 return NetworkChangeNotifier::kInvalidNetworkHandle;
71 } 71 }
72 72
73 int Connect(const IPEndPoint& remote) override { 73 int Connect(const IPEndPoint& remote) override {
74 if (connected_) 74 if (connected_)
75 return ERR_UNEXPECTED; 75 return ERR_UNEXPECTED;
76 AddressMapping::const_iterator it = mapping_->find(remote.address()); 76 AddressMapping::const_iterator it = mapping_->find(remote.address_number());
77 if (it == mapping_->end()) 77 if (it == mapping_->end())
78 return ERR_FAILED; 78 return ERR_FAILED;
79 connected_ = true; 79 connected_ = true;
80 local_endpoint_ = IPEndPoint(it->second, 39874 /* arbitrary port */); 80 local_endpoint_ = IPEndPoint(it->second, 39874 /* arbitrary port */);
81 return OK; 81 return OK;
82 } 82 }
83 83
84 const BoundNetLog& NetLog() const override { return net_log_; } 84 const BoundNetLog& NetLog() const override { return net_log_; }
85 85
86 private: 86 private:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 AddressList result; 173 AddressList result;
174 TestCompletionCallback callback; 174 TestCompletionCallback callback;
175 sorter_.Sort(list, base::Bind(&OnSortComplete, &result, 175 sorter_.Sort(list, base::Bind(&OnSortComplete, &result,
176 callback.callback())); 176 callback.callback()));
177 callback.WaitForResult(); 177 callback.WaitForResult();
178 178
179 for (size_t i = 0; (i < result.size()) || (order[i] >= 0); ++i) { 179 for (size_t i = 0; (i < result.size()) || (order[i] >= 0); ++i) {
180 IPEndPoint expected = order[i] >= 0 ? list[order[i]] : IPEndPoint(); 180 IPEndPoint expected = order[i] >= 0 ? list[order[i]] : IPEndPoint();
181 IPEndPoint actual = i < result.size() ? result[i] : IPEndPoint(); 181 IPEndPoint actual = i < result.size() ? result[i] : IPEndPoint();
182 EXPECT_TRUE(expected.address() == actual.address()) << 182 EXPECT_TRUE(expected.address_number() == actual.address_number())
183 "Address out of order at position " << i << "\n" << 183 << "Address out of order at position " << i << "\n"
184 " Actual: " << actual.ToStringWithoutPort() << "\n" << 184 << " Actual: " << actual.ToStringWithoutPort() << "\n"
185 "Expected: " << expected.ToStringWithoutPort(); 185 << "Expected: " << expected.ToStringWithoutPort();
186 } 186 }
187 } 187 }
188 188
189 TestSocketFactory socket_factory_; 189 TestSocketFactory socket_factory_;
190 AddressSorterPosix sorter_; 190 AddressSorterPosix sorter_;
191 }; 191 };
192 192
193 // Rule 1: Avoid unusable destinations. 193 // Rule 1: Avoid unusable destinations.
194 TEST_F(AddressSorterPosixTest, Rule1) { 194 TEST_F(AddressSorterPosixTest, Rule1) {
195 AddMapping("10.0.0.231", "10.0.0.1"); 195 AddMapping("10.0.0.231", "10.0.0.1");
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 AddMapping("4000::1", "4000::10"); // global unicast 322 AddMapping("4000::1", "4000::10"); // global unicast
323 AddMapping("ff32::2", "fe81::20"); // deprecated link-local multicast 323 AddMapping("ff32::2", "fe81::20"); // deprecated link-local multicast
324 GetSourceInfo("fe81::20")->deprecated = true; 324 GetSourceInfo("fe81::20")->deprecated = true;
325 const char* const addresses[] = { "ff3e::1", "ff32::2", "4000::1", "ff32::1", 325 const char* const addresses[] = { "ff3e::1", "ff32::2", "4000::1", "ff32::1",
326 "::1", "8.0.0.1", NULL }; 326 "::1", "8.0.0.1", NULL };
327 const int order[] = { 4, 3, 0, 2, 1, -1 }; 327 const int order[] = { 4, 3, 0, 2, 1, -1 };
328 Verify(addresses, order); 328 Verify(addresses, order);
329 } 329 }
330 330
331 } // namespace net 331 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698