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

Side by Side 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, 9 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/base/address_list.cc ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h"
7 #include "base/string_util.h" 8 #include "base/string_util.h"
8 #include "net/base/host_resolver_proc.h" 9 #include "net/base/host_resolver_proc.h"
9 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
10 #include "net/base/sys_addrinfo.h" 11 #include "net/base/sys_addrinfo.h"
11 #if defined(OS_WIN) 12 #if defined(OS_WIN)
12 #include "net/base/winsock_init.h" 13 #include "net/base/winsock_init.h"
13 #endif 14 #endif
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace { 17 namespace {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 size_t sockaddr_size = 207 size_t sockaddr_size =
207 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) : 208 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) :
208 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0; 209 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0;
209 EXPECT_EQ(memcmp(good_ai->ai_addr, test_ai->ai_addr, sockaddr_size), 0); 210 EXPECT_EQ(memcmp(good_ai->ai_addr, test_ai->ai_addr, sockaddr_size), 0);
210 EXPECT_EQ(good_ai->ai_next, test_ai->ai_next); 211 EXPECT_EQ(good_ai->ai_next, test_ai->ai_next);
211 EXPECT_EQ(strcmp(tests[i].canonical_ip_address.c_str(), 212 EXPECT_EQ(strcmp(tests[i].canonical_ip_address.c_str(),
212 test_ai->ai_canonname), 0); 213 test_ai->ai_canonname), 0);
213 } 214 }
214 } 215 }
215 216
217 TEST(AddressListTest, AddressFromAddrInfo) {
218 struct TestData {
219 std::string ip_address;
220 std::string canonical_ip_address;
221 bool is_ipv6;
222 } tests[] = {
223 { "127.0.00.1", "127.0.0.1", false },
224 { "192.168.1.1", "192.168.1.1", false },
225 { "::1", "::1", true },
226 { "2001:db8:0::42", "2001:db8::42", true },
227 };
228 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
229 net::AddressList expected_list;
230 int rv = CreateAddressList(tests[i].canonical_ip_address, 80,
231 &expected_list);
232 if (tests[i].is_ipv6 && rv != 0) {
233 LOG(WARNING) << "Unable to resolve ip literal '" << tests[i].ip_address
234 << "' test skipped.";
235 continue;
236 }
237 ASSERT_EQ(0, rv);
238 const struct addrinfo* good_ai = expected_list.head();
239
240 scoped_ptr<net::AddressList> test_list(
241 net::AddressList::CreateAddressListFromSockaddr(good_ai->ai_addr,
242 good_ai->ai_addrlen,
243 SOCK_STREAM,
244 IPPROTO_TCP));
245 const struct addrinfo* test_ai = test_list->head();
246
247 EXPECT_EQ(good_ai->ai_family, test_ai->ai_family);
248 EXPECT_EQ(good_ai->ai_addrlen, test_ai->ai_addrlen);
249 size_t sockaddr_size =
250 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) :
251 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0;
252 EXPECT_EQ(memcmp(good_ai->ai_addr, test_ai->ai_addr, sockaddr_size), 0);
253 EXPECT_EQ(good_ai->ai_next, test_ai->ai_next);
254 }
255 }
256
216 } // namespace 257 } // namespace
OLDNEW
« 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