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

Side by Side Diff: net/base/address_list_unittest.cc

Issue 7008021: Added DnsQuery class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/address_list.h" 5 #include "net/base/address_list.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/host_resolver_proc.h" 9 #include "net/base/host_resolver_proc.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 EXPECT_EQ(good_ai->ai_family, test_ai->ai_family); 267 EXPECT_EQ(good_ai->ai_family, test_ai->ai_family);
268 EXPECT_EQ(good_ai->ai_addrlen, test_ai->ai_addrlen); 268 EXPECT_EQ(good_ai->ai_addrlen, test_ai->ai_addrlen);
269 size_t sockaddr_size = 269 size_t sockaddr_size =
270 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) : 270 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) :
271 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0; 271 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0;
272 EXPECT_EQ(memcmp(good_ai->ai_addr, test_ai->ai_addr, sockaddr_size), 0); 272 EXPECT_EQ(memcmp(good_ai->ai_addr, test_ai->ai_addr, sockaddr_size), 0);
273 EXPECT_EQ(good_ai->ai_next, test_ai->ai_next); 273 EXPECT_EQ(good_ai->ai_next, test_ai->ai_next);
274 } 274 }
275 } 275 }
276 276
277 TEST(AddressListTest, CreateFromIPAddressList) {
278 struct TestData {
279 std::string ip_address;
280 bool is_ipv6;
281 } tests[] = {
282 { "127.0.0.1", false },
283 { "2001:db8:0::42", true },
284 { "192.168.1.1", false },
285 };
286
287 // Construct a list of ip addresses.
288 std::vector<IPAddressNumber> ip_list;
289 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
290 IPAddressNumber ip_number;
291 ParseIPLiteralToNumber(tests[i].ip_address, &ip_number);
292 ip_list.push_back(ip_number);
293 }
294
295 AddressList test_list = AddressList::CreateFromIPAddressList(ip_list, 80);
296 EXPECT_EQ(80, test_list.GetPort());
297
298 // Make sure that CreateFromIPAddressList has created an addrinfo
299 // chain of exactly the same length as the |tests| with correct content.
300 struct addrinfo* next_ai = const_cast<struct addrinfo*>(test_list.head());
301 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
302 ASSERT_TRUE(next_ai != NULL);
303 AddressList expected_list;
304 int rv = CreateAddressList(tests[i].ip_address, 80, &expected_list);
305 if (tests[i].is_ipv6 && rv != 0) {
306 LOG(WARNING) << "Unable to resolve ip literal '" << tests[i].ip_address
307 << "' test skipped.";
308 } else {
309 ASSERT_EQ(0, rv);
310 const struct addrinfo* good_ai = expected_list.head();
311 EXPECT_EQ(good_ai->ai_family, next_ai->ai_family);
312 EXPECT_EQ(good_ai->ai_addrlen, next_ai->ai_addrlen);
313 size_t sockaddr_size =
314 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) :
315 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0;
316 EXPECT_EQ(memcmp(good_ai->ai_addr, next_ai->ai_addr, sockaddr_size), 0);
317 }
318 next_ai = next_ai->ai_next;
319 }
320 EXPECT_EQ(NULL, next_ai);
321 }
322
277 } // namespace 323 } // namespace
278 } // namespace net 324 } // namespace net
OLDNEW
« no previous file with comments | « net/base/address_list.cc ('k') | net/base/dns_query.h » ('j') | net/base/dns_query.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698