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

Side by Side Diff: net/dns/dns_config_service_win_unittest.cc

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « net/disk_cache/simple/simple_util_win.cc ('k') | net/dns/host_resolver.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/dns/dns_config_service_win.h" 5 #include "net/dns/dns_config_service_win.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 #include "net/dns/dns_protocol.h" 10 #include "net/dns/dns_protocol.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 EXPECT_FALSE(result) << "Unexpected parse success on " << t.input; 48 EXPECT_FALSE(result) << "Unexpected parse success on " << t.input;
49 } 49 }
50 } 50 }
51 } 51 }
52 52
53 struct AdapterInfo { 53 struct AdapterInfo {
54 IFTYPE if_type; 54 IFTYPE if_type;
55 IF_OPER_STATUS oper_status; 55 IF_OPER_STATUS oper_status;
56 const WCHAR* dns_suffix; 56 const WCHAR* dns_suffix;
57 std::string dns_server_addresses[4]; // Empty string indicates end. 57 std::string dns_server_addresses[4]; // Empty string indicates end.
58 int ports[4]; 58 uint16 ports[4];
59 }; 59 };
60 60
61 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> CreateAdapterAddresses( 61 scoped_ptr<IP_ADAPTER_ADDRESSES, base::FreeDeleter> CreateAdapterAddresses(
62 const AdapterInfo* infos) { 62 const AdapterInfo* infos) {
63 size_t num_adapters = 0; 63 size_t num_adapters = 0;
64 size_t num_addresses = 0; 64 size_t num_addresses = 0;
65 for (size_t i = 0; infos[i].if_type; ++i) { 65 for (size_t i = 0; infos[i].if_type; ++i) {
66 ++num_adapters; 66 ++num_adapters;
67 for (size_t j = 0; !infos[i].dns_server_addresses[j].empty(); ++j) { 67 for (size_t j = 0; !infos[i].dns_server_addresses[j].empty(); ++j) {
68 ++num_addresses; 68 ++num_addresses;
(...skipping 26 matching lines...) Expand all
95 for (size_t j = 0; !info.dns_server_addresses[j].empty(); ++j) { 95 for (size_t j = 0; !info.dns_server_addresses[j].empty(); ++j) {
96 --num_addresses; 96 --num_addresses;
97 if (j == 0) { 97 if (j == 0) {
98 address = adapter->FirstDnsServerAddress = addresses + num_addresses; 98 address = adapter->FirstDnsServerAddress = addresses + num_addresses;
99 } else { 99 } else {
100 // Note that |address| is moving backwards. 100 // Note that |address| is moving backwards.
101 address = address->Next = address - 1; 101 address = address->Next = address - 1;
102 } 102 }
103 IPAddressNumber ip; 103 IPAddressNumber ip;
104 CHECK(ParseIPLiteralToNumber(info.dns_server_addresses[j], &ip)); 104 CHECK(ParseIPLiteralToNumber(info.dns_server_addresses[j], &ip));
105 IPEndPoint ipe(ip, info.ports[j]); 105 IPEndPoint ipe = IPEndPoint(ip, info.ports[j]);
106 address->Address.lpSockaddr = 106 address->Address.lpSockaddr =
107 reinterpret_cast<LPSOCKADDR>(storage + num_addresses); 107 reinterpret_cast<LPSOCKADDR>(storage + num_addresses);
108 socklen_t length = sizeof(struct sockaddr_storage); 108 socklen_t length = sizeof(struct sockaddr_storage);
109 CHECK(ipe.ToSockAddr(address->Address.lpSockaddr, &length)); 109 CHECK(ipe.ToSockAddr(address->Address.lpSockaddr, &length));
110 address->Address.iSockaddrLength = static_cast<int>(length); 110 address->Address.iSockaddrLength = static_cast<int>(length);
111 } 111 }
112 } 112 }
113 113
114 return heap.Pass(); 114 return heap.Pass();
115 } 115 }
116 116
117 TEST(DnsConfigServiceWinTest, ConvertAdapterAddresses) { 117 TEST(DnsConfigServiceWinTest, ConvertAdapterAddresses) {
118 // Check nameservers and connection-specific suffix. 118 // Check nameservers and connection-specific suffix.
119 const struct TestCase { 119 const struct TestCase {
120 AdapterInfo input_adapters[4]; // |if_type| == 0 indicates end. 120 AdapterInfo input_adapters[4]; // |if_type| == 0 indicates end.
121 std::string expected_nameservers[4]; // Empty string indicates end. 121 std::string expected_nameservers[4]; // Empty string indicates end.
122 std::string expected_suffix; 122 std::string expected_suffix;
123 int expected_ports[4]; 123 uint16 expected_ports[4];
124 } cases[] = { 124 } cases[] = {
125 { // Ignore loopback and inactive adapters. 125 { // Ignore loopback and inactive adapters.
126 { 126 {
127 { IF_TYPE_SOFTWARE_LOOPBACK, IfOperStatusUp, L"funnyloop", 127 { IF_TYPE_SOFTWARE_LOOPBACK, IfOperStatusUp, L"funnyloop",
128 { "2.0.0.2" } }, 128 { "2.0.0.2" } },
129 { IF_TYPE_FASTETHER, IfOperStatusDormant, L"example.com", 129 { IF_TYPE_FASTETHER, IfOperStatusDormant, L"example.com",
130 { "1.0.0.1" } }, 130 { "1.0.0.1" } },
131 { IF_TYPE_USB, IfOperStatusUp, L"chromium.org", 131 { IF_TYPE_USB, IfOperStatusUp, L"chromium.org",
132 { "10.0.0.10", "2001:FFFF::1111" } }, 132 { "10.0.0.10", "2001:FFFF::1111" } },
133 { 0 }, 133 { 0 },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 for (size_t i = 0; i < arraysize(cases); ++i) { 174 for (size_t i = 0; i < arraysize(cases); ++i) {
175 const TestCase& t = cases[i]; 175 const TestCase& t = cases[i];
176 internal::DnsSystemSettings settings = { 176 internal::DnsSystemSettings settings = {
177 CreateAdapterAddresses(t.input_adapters), 177 CreateAdapterAddresses(t.input_adapters),
178 // Default settings for the rest. 178 // Default settings for the rest.
179 }; 179 };
180 std::vector<IPEndPoint> expected_nameservers; 180 std::vector<IPEndPoint> expected_nameservers;
181 for (size_t j = 0; !t.expected_nameservers[j].empty(); ++j) { 181 for (size_t j = 0; !t.expected_nameservers[j].empty(); ++j) {
182 IPAddressNumber ip; 182 IPAddressNumber ip;
183 ASSERT_TRUE(ParseIPLiteralToNumber(t.expected_nameservers[j], &ip)); 183 ASSERT_TRUE(ParseIPLiteralToNumber(t.expected_nameservers[j], &ip));
184 int port = t.expected_ports[j]; 184 uint16 port = t.expected_ports[j];
185 if (!port) 185 if (!port)
186 port = dns_protocol::kDefaultPort; 186 port = dns_protocol::kDefaultPort;
187 expected_nameservers.push_back(IPEndPoint(ip, port)); 187 expected_nameservers.push_back(IPEndPoint(ip, port));
188 } 188 }
189 189
190 DnsConfig config; 190 DnsConfig config;
191 internal::ConfigParseWinResult result = 191 internal::ConfigParseWinResult result =
192 internal::ConvertSettingsToDnsConfig(settings, &config); 192 internal::ConvertSettingsToDnsConfig(settings, &config);
193 internal::ConfigParseWinResult expected_result = 193 internal::ConfigParseWinResult expected_result =
194 expected_nameservers.empty() ? internal::CONFIG_PARSE_WIN_NO_NAMESERVERS 194 expected_nameservers.empty() ? internal::CONFIG_PARSE_WIN_NO_NAMESERVERS
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 EXPECT_EQ(t.unhandled_options, config.unhandled_options); 458 EXPECT_EQ(t.unhandled_options, config.unhandled_options);
459 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6); 459 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6);
460 } 460 }
461 } 461 }
462 462
463 463
464 } // namespace 464 } // namespace
465 465
466 } // namespace net 466 } // namespace net
467 467
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_util_win.cc ('k') | net/dns/host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698