OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/dns/address_sorter.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | |
9 #include "net/base/address_list.h" | |
10 #include "net/base/net_util.h" | |
11 #include "net/base/test_completion_callback.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace net { | |
15 namespace { | |
16 | |
17 IPEndPoint MakeEndPoint(const std::string& str) { | |
18 IPAddressNumber addr; | |
19 CHECK(ParseIPLiteralToNumber(str, &addr)); | |
20 return IPEndPoint(addr, 0); | |
21 } | |
22 | |
23 void OnSortComplete(AddressList* result_buf, | |
24 const CompletionCallback& callback, | |
25 bool success, | |
26 const AddressList& result) { | |
27 EXPECT_TRUE(success); | |
28 if (success) | |
29 *result_buf = result; | |
30 callback.Run(OK); | |
31 } | |
32 | |
33 TEST(AddressSorterTest, Sort) { | |
34 scoped_ptr<AddressSorter> sorter(AddressSorter::CreateAddressSorter()); | |
35 AddressList list; | |
36 list.push_back(MakeEndPoint("10.0.0.1")); | |
37 list.push_back(MakeEndPoint("8.8.8.8")); | |
38 list.push_back(MakeEndPoint("::1")); | |
39 list.push_back(MakeEndPoint("2001:4860:4860::8888")); | |
40 | |
41 AddressList result; | |
42 TestCompletionCallback callback; | |
43 sorter->Sort(list, base::Bind(&OnSortComplete, &result, | |
44 callback.callback())); | |
45 callback.WaitForResult(); | |
46 } | |
47 | |
48 } // namespace | |
49 } // namespace net | |
OLD | NEW |