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

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

Issue 10309002: Reimplements net::AddressList without struct addrinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: get_canonical_name -> canonical_name. iterator to indexing Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/dns/dns_config_service_win_unittest.cc ('k') | net/dns/dns_transaction_unittest.cc » ('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_response.h" 5 #include "net/dns/dns_response.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "net/base/address_list.h" 8 #include "net/base/address_list.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
11 #include "net/base/sys_addrinfo.h"
12 #include "net/dns/dns_protocol.h" 11 #include "net/dns/dns_protocol.h"
13 #include "net/dns/dns_query.h" 12 #include "net/dns/dns_query.h"
14 #include "net/dns/dns_test_util.h" 13 #include "net/dns/dns_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 15
17 namespace net { 16 namespace net {
18 17
19 namespace { 18 namespace {
20 19
21 TEST(DnsRecordParserTest, Constructor) { 20 TEST(DnsRecordParserTest, Constructor) {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 DnsRecordParser parser = resp.Parser(); 240 DnsRecordParser parser = resp.Parser();
242 EXPECT_TRUE(parser.ReadRecord(&record)); 241 EXPECT_TRUE(parser.ReadRecord(&record));
243 EXPECT_FALSE(parser.AtEnd()); 242 EXPECT_FALSE(parser.AtEnd());
244 EXPECT_TRUE(parser.ReadRecord(&record)); 243 EXPECT_TRUE(parser.ReadRecord(&record));
245 EXPECT_TRUE(parser.AtEnd()); 244 EXPECT_TRUE(parser.AtEnd());
246 EXPECT_FALSE(parser.ReadRecord(&record)); 245 EXPECT_FALSE(parser.ReadRecord(&record));
247 } 246 }
248 247
249 void VerifyAddressList(const std::vector<const char*>& ip_addresses, 248 void VerifyAddressList(const std::vector<const char*>& ip_addresses,
250 const AddressList& addrlist) { 249 const AddressList& addrlist) {
251 ASSERT_GT(ip_addresses.size(), 0u); 250 ASSERT_EQ(ip_addresses.size(), addrlist.size());
252 ASSERT_NE(static_cast<addrinfo*>(NULL), addrlist.head());
253 251
254 IPAddressNumber ip_number; 252 for (size_t i = 0; i < addrlist.size(); ++i) {
255 const struct addrinfo* ainfo = addrlist.head(); 253 EXPECT_EQ(ip_addresses[i], addrlist[i].ToStringWithoutPort());
256 for (std::vector<const char*>::const_iterator i = ip_addresses.begin();
257 i != ip_addresses.end(); ++i, ainfo = ainfo->ai_next) {
258 ASSERT_NE(static_cast<addrinfo*>(NULL), ainfo);
259 EXPECT_EQ(sizeof(struct sockaddr_in),
260 static_cast<size_t>(ainfo->ai_addrlen));
261
262 const struct sockaddr* sa = ainfo->ai_addr;
263 EXPECT_STREQ(*i, NetAddressToString(sa, ainfo->ai_addrlen).c_str());
264 } 254 }
265 ASSERT_EQ(static_cast<addrinfo*>(NULL), ainfo);
266 } 255 }
267 256
268 TEST(DnsResponseTest, ParseToAddressList) { 257 TEST(DnsResponseTest, ParseToAddressList) {
269 const struct TestCase { 258 const struct TestCase {
270 size_t query_size; 259 size_t query_size;
271 const uint8* response_data; 260 const uint8* response_data;
272 size_t response_size; 261 size_t response_size;
273 const char* const* expected_addresses; 262 const char* const* expected_addresses;
274 size_t num_expected_addresses; 263 size_t num_expected_addresses;
275 const char* expected_cname; 264 const char* expected_cname;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 const TestCase& t = cases[i]; 298 const TestCase& t = cases[i];
310 DnsResponse response(t.response_data, t.response_size, t.query_size); 299 DnsResponse response(t.response_data, t.response_size, t.query_size);
311 AddressList addr_list; 300 AddressList addr_list;
312 base::TimeDelta ttl; 301 base::TimeDelta ttl;
313 EXPECT_EQ(DnsResponse::DNS_SUCCESS, 302 EXPECT_EQ(DnsResponse::DNS_SUCCESS,
314 response.ParseToAddressList(&addr_list, &ttl)); 303 response.ParseToAddressList(&addr_list, &ttl));
315 std::vector<const char*> expected_addresses( 304 std::vector<const char*> expected_addresses(
316 t.expected_addresses, 305 t.expected_addresses,
317 t.expected_addresses + t.num_expected_addresses); 306 t.expected_addresses + t.num_expected_addresses);
318 VerifyAddressList(expected_addresses, addr_list); 307 VerifyAddressList(expected_addresses, addr_list);
319 std::string cname; 308 EXPECT_EQ(t.expected_cname, addr_list.canonical_name());
320 ASSERT_TRUE(addr_list.GetCanonicalName(&cname));
321 EXPECT_EQ(t.expected_cname, cname);
322 EXPECT_EQ(base::TimeDelta::FromSeconds(t.expected_ttl_sec), ttl); 309 EXPECT_EQ(base::TimeDelta::FromSeconds(t.expected_ttl_sec), ttl);
323 } 310 }
324 } 311 }
325 312
326 const uint8 kResponseTruncatedRecord[] = { 313 const uint8 kResponseTruncatedRecord[] = {
327 // Header: 1 question, 1 answer RR 314 // Header: 1 question, 1 answer RR
328 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 315 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
329 // Question: name = 'a', type = A (0x1) 316 // Question: name = 'a', type = A (0x1)
330 0x01, 'a', 0x00, 0x00, 0x01, 0x00, 0x01, 317 0x01, 'a', 0x00, 0x00, 0x01, 0x00, 0x01,
331 // Answer: name = 'a', type = A, TTL = 0xFF, RDATA = 10.10.10.10 318 // Answer: name = 'a', type = A, TTL = 0xFF, RDATA = 10.10.10.10
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 AddressList addr_list; 442 AddressList addr_list;
456 base::TimeDelta ttl; 443 base::TimeDelta ttl;
457 EXPECT_EQ(t.expected_result, 444 EXPECT_EQ(t.expected_result,
458 response.ParseToAddressList(&addr_list, &ttl)); 445 response.ParseToAddressList(&addr_list, &ttl));
459 } 446 }
460 } 447 }
461 448
462 } // namespace 449 } // namespace
463 450
464 } // namespace net 451 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_config_service_win_unittest.cc ('k') | net/dns/dns_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698