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

Unified Diff: net/base/address_list_unittest.cc

Issue 6598040: Add constructor for creating an AddressList from a struct sockaddr. This is... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/address_list.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/address_list_unittest.cc
===================================================================
--- net/base/address_list_unittest.cc (revision 76440)
+++ net/base/address_list_unittest.cc (working copy)
@@ -4,6 +4,7 @@
#include "net/base/address_list.h"
+#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "net/base/host_resolver_proc.h"
#include "net/base/net_util.h"
@@ -213,4 +214,44 @@
}
}
+TEST(AddressListTest, AddressFromAddrInfo) {
+ struct TestData {
+ std::string ip_address;
+ std::string canonical_ip_address;
+ bool is_ipv6;
+ } tests[] = {
+ { "127.0.00.1", "127.0.0.1", false },
+ { "192.168.1.1", "192.168.1.1", false },
+ { "::1", "::1", true },
+ { "2001:db8:0::42", "2001:db8::42", true },
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
+ net::AddressList expected_list;
+ int rv = CreateAddressList(tests[i].canonical_ip_address, 80,
+ &expected_list);
+ if (tests[i].is_ipv6 && rv != 0) {
+ LOG(WARNING) << "Unable to resolve ip literal '" << tests[i].ip_address
+ << "' test skipped.";
+ continue;
+ }
+ ASSERT_EQ(0, rv);
+ const struct addrinfo* good_ai = expected_list.head();
+
+ scoped_ptr<net::AddressList> test_list(
+ net::AddressList::CreateAddressListFromSockaddr(good_ai->ai_addr,
+ good_ai->ai_addrlen,
+ SOCK_STREAM,
+ IPPROTO_TCP));
+ const struct addrinfo* test_ai = test_list->head();
+
+ EXPECT_EQ(good_ai->ai_family, test_ai->ai_family);
+ EXPECT_EQ(good_ai->ai_addrlen, test_ai->ai_addrlen);
+ size_t sockaddr_size =
+ good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) :
+ good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0;
+ EXPECT_EQ(memcmp(good_ai->ai_addr, test_ai->ai_addr, sockaddr_size), 0);
+ EXPECT_EQ(good_ai->ai_next, test_ai->ai_next);
+ }
+}
+
} // namespace
« no previous file with comments | « net/base/address_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698