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

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
« net/base/address_list.cc ('K') | « 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/string_util.h" 7 #include "base/string_util.h"
8 #include "net/base/host_resolver_proc.h" 8 #include "net/base/host_resolver_proc.h"
9 #include "net/base/net_util.h" 9 #include "net/base/net_util.h"
10 #include "net/base/sys_addrinfo.h" 10 #include "net/base/sys_addrinfo.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 size_t sockaddr_size = 206 size_t sockaddr_size =
207 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) : 207 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) :
208 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0; 208 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); 209 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); 210 EXPECT_EQ(good_ai->ai_next, test_ai->ai_next);
211 EXPECT_EQ(strcmp(tests[i].canonical_ip_address.c_str(), 211 EXPECT_EQ(strcmp(tests[i].canonical_ip_address.c_str(),
212 test_ai->ai_canonname), 0); 212 test_ai->ai_canonname), 0);
213 } 213 }
214 } 214 }
215 215
216 TEST(AddressListTest, AddressFromAddrInfo) {
217 struct TestData {
218 std::string ip_address;
219 std::string canonical_ip_address;
220 bool is_ipv6;
221 } tests[] = {
222 { "127.0.00.1", "127.0.0.1", false },
223 { "192.168.1.1", "192.168.1.1", false },
224 { "::1", "::1", true },
225 { "2001:db8:0::42", "2001:db8::42", true },
226 };
227 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) {
228 net::AddressList expected_list;
229 int rv = CreateAddressList(tests[i].canonical_ip_address, 80,
230 &expected_list);
231 if (tests[i].is_ipv6 && rv != 0) {
232 LOG(WARNING) << "Unable to resolve ip literal '" << tests[i].ip_address
233 << "' test skipped.";
234 continue;
235 }
236 ASSERT_EQ(0, rv);
eroman 2011/03/01 02:52:33 I wander why we aren't using net::OK throughout th
237 const struct addrinfo* good_ai = expected_list.head();
238
239 net::AddressList test_list(good_ai->ai_addr, good_ai->ai_addrlen,
240 SOCK_STREAM, IPPROTO_TCP);
241 const struct addrinfo* test_ai = test_list.head();
242
243 EXPECT_EQ(good_ai->ai_family, test_ai->ai_family);
244 EXPECT_EQ(good_ai->ai_addrlen, test_ai->ai_addrlen);
245 size_t sockaddr_size =
246 good_ai->ai_socktype == AF_INET ? sizeof(struct sockaddr_in) :
247 good_ai->ai_socktype == AF_INET6 ? sizeof(struct sockaddr_in6) : 0;
248 EXPECT_EQ(memcmp(good_ai->ai_addr, test_ai->ai_addr, sockaddr_size), 0);
249 EXPECT_EQ(good_ai->ai_next, test_ai->ai_next);
250 }
251 }
252
216 } // namespace 253 } // namespace
OLDNEW
« net/base/address_list.cc ('K') | « net/base/address_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698