diff options
author | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-15 21:30:46 +0000 |
---|---|---|
committer | szym@chromium.org <szym@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-15 21:30:46 +0000 |
commit | 0adcb2b7566fc42a11409b79f81a8bbf4f1eed32 (patch) | |
tree | 650466bc57a4bf5082d4a0291dc030ada658f6ca /net/dns/address_sorter_unittest.cc | |
parent | 69cc9fd8cf3a8b7a67109d13a687dc3f5d80626b (diff) | |
download | chromium_src-0adcb2b7566fc42a11409b79f81a8bbf4f1eed32.zip chromium_src-0adcb2b7566fc42a11409b79f81a8bbf4f1eed32.tar.gz chromium_src-0adcb2b7566fc42a11409b79f81a8bbf4f1eed32.tar.bz2 |
[net/dns] Resolve AF_UNSPEC on dual-stacked systems. Sort addresses according to RFC3484.
Original review: http://codereview.chromium.org/10442098/
BUG=113993
TEST=./net_unittests --gtest_filter=AddressSorter*:HostResolverImplDnsTest.DnsTaskUnspec
Review URL: https://chromiumcodereview.appspot.com/10855179
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/dns/address_sorter_unittest.cc')
-rw-r--r-- | net/dns/address_sorter_unittest.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/net/dns/address_sorter_unittest.cc b/net/dns/address_sorter_unittest.cc new file mode 100644 index 0000000..0c2be88 --- /dev/null +++ b/net/dns/address_sorter_unittest.cc @@ -0,0 +1,66 @@ +// 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" + +#if defined(OS_WIN) +#include <winsock2.h> +#endif + +#include "base/bind.h" +#include "base/logging.h" +#include "net/base/address_list.h" +#include "net/base/net_util.h" +#include "net/base/test_completion_callback.h" +#include "testing/gtest/include/gtest/gtest.h" + +#if defined(OS_WIN) +#include "net/base/winsock_init.h" +#endif + +namespace net { +namespace { + +IPEndPoint MakeEndPoint(const std::string& str) { + IPAddressNumber addr; + CHECK(ParseIPLiteralToNumber(str, &addr)); + return IPEndPoint(addr, 0); +} + +void OnSortComplete(AddressList* result_buf, + const CompletionCallback& callback, + bool success, + const AddressList& result) { + if (success) + *result_buf = result; + callback.Run(success ? OK : ERR_FAILED); +} + +TEST(AddressSorterTest, Sort) { + int expected_result = OK; +#if defined(OS_WIN) + EnsureWinsockInit(); + SOCKET sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + if (sock == INVALID_SOCKET) { + expected_result = ERR_FAILED; + } else { + closesocket(sock); + } +#endif + 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")); + + AddressList result; + TestCompletionCallback callback; + sorter->Sort(list, base::Bind(&OnSortComplete, &result, + callback.callback())); + EXPECT_EQ(expected_result, callback.WaitForResult()); +} + +} // namespace +} // namespace net |