Index: net/dns/address_sorter_unittest.cc |
diff --git a/net/dns/address_sorter_unittest.cc b/net/dns/address_sorter_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..673421c9fd81167fa48f9479fea33d0c6f94b753 |
--- /dev/null |
+++ b/net/dns/address_sorter_unittest.cc |
@@ -0,0 +1,48 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/dns/address_sorter.h" |
+ |
+#include "base/bind.h" |
+#include "base/logging.h" |
+#include "base/synchronization/waitable_event.h" |
+#include "net/base/address_list.h" |
+#include "net/base/net_util.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace net { |
+namespace { |
+ |
+IPEndPoint MakeEndPoint(const std::string& str) { |
+ IPAddressNumber addr; |
+ CHECK(ParseIPLiteralToNumber(str, &addr)); |
+ return IPEndPoint(addr, 0); |
+} |
+ |
+void OnSortComplete(AddressList* result_buf, |
+ base::WaitableEvent* event, |
+ bool success, |
+ const AddressList& result) { |
+ EXPECT_TRUE(success); |
+ if (success) |
+ *result_buf = result; |
+ event->Signal(); |
+} |
+ |
+TEST(AddressSorterTest, Sort) { |
+ scoped_ptr<AddressSorter> sorter(AddressSorter::CreateAddressSorter()); |
+ AddressList list; |
+ list.push_back(MakeEndPoint("10.0.0.1")); |
+ list.push_back(MakeEndPoint("8.8.8.8")); |
+ list.push_back(MakeEndPoint("::1")); |
+ list.push_back(MakeEndPoint("2001:4860:4860::8888")); |
+ |
+ base::WaitableEvent event(false, false); |
+ AddressList result; |
+ sorter->Sort(list, base::Bind(&OnSortComplete, &result, &event)); |
+ event.Wait(); |
+} |
+ |
+} // namespace |
+} // namespace net |