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

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

Issue 1810183002: Migrate net/proxy/* to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments eroman Created 4 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
« no previous file with comments | « net/base/ip_address_number_unittest.cc ('k') | net/proxy/proxy_bypass_rules.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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/ip_address.h" 5 #include "net/base/ip_address.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 IPAddress ipv4mapped_address; 231 IPAddress ipv4mapped_address;
232 EXPECT_TRUE(ipv4mapped_address.AssignFromIPLiteral("::ffff:c0a8:1")); 232 EXPECT_TRUE(ipv4mapped_address.AssignFromIPLiteral("::ffff:c0a8:1"));
233 233
234 IPAddress expected; 234 IPAddress expected;
235 EXPECT_TRUE(expected.AssignFromIPLiteral("192.168.0.1")); 235 EXPECT_TRUE(expected.AssignFromIPLiteral("192.168.0.1"));
236 236
237 IPAddress result = ConvertIPv4MappedIPv6ToIPv4(ipv4mapped_address); 237 IPAddress result = ConvertIPv4MappedIPv6ToIPv4(ipv4mapped_address);
238 EXPECT_EQ(expected, result); 238 EXPECT_EQ(expected, result);
239 } 239 }
240 240
241 // Test parsing invalid CIDR notation literals.
242 TEST(IPAddressTest, ParseCIDRBlock_Invalid) {
243 const char* const bad_literals[] = {"foobar",
244 "",
245 "192.168.0.1",
246 "::1",
247 "/",
248 "/1",
249 "1",
250 "192.168.1.1/-1",
251 "192.168.1.1/33",
252 "::1/-3",
253 "a::3/129",
254 "::1/x",
255 "192.168.0.1//11"};
256
257 for (const auto& bad_literal : bad_literals) {
258 IPAddress ip_address;
259 size_t prefix_length_in_bits;
260
261 EXPECT_FALSE(
262 ParseCIDRBlock(bad_literal, &ip_address, &prefix_length_in_bits));
263 }
264 }
265
266 // Test parsing a valid CIDR notation literal.
267 TEST(IPAddressTest, ParseCIDRBlock_Valid) {
268 IPAddress ip_address;
269 size_t prefix_length_in_bits;
270
271 EXPECT_TRUE(
272 ParseCIDRBlock("192.168.0.1/11", &ip_address, &prefix_length_in_bits));
273
274 EXPECT_EQ("192,168,0,1", DumpIPAddress(ip_address));
275 EXPECT_EQ(11u, prefix_length_in_bits);
276
277 EXPECT_TRUE(ParseCIDRBlock("::ffff:192.168.0.1/112", &ip_address,
278 &prefix_length_in_bits));
279
280 EXPECT_EQ("0,0,0,0,0,0,0,0,0,0,255,255,192,168,0,1",
281 DumpIPAddress(ip_address));
282 EXPECT_EQ(112u, prefix_length_in_bits);
283 }
284
241 TEST(IPAddressTest, IPAddressStartsWith) { 285 TEST(IPAddressTest, IPAddressStartsWith) {
242 IPAddress ipv4_address(192, 168, 10, 5); 286 IPAddress ipv4_address(192, 168, 10, 5);
243 287
244 uint8_t ipv4_prefix1[] = {192, 168, 10}; 288 uint8_t ipv4_prefix1[] = {192, 168, 10};
245 EXPECT_TRUE(IPAddressStartsWith(ipv4_address, ipv4_prefix1)); 289 EXPECT_TRUE(IPAddressStartsWith(ipv4_address, ipv4_prefix1));
246 290
247 uint8_t ipv4_prefix3[] = {192, 168, 10, 5}; 291 uint8_t ipv4_prefix3[] = {192, 168, 10, 5};
248 EXPECT_TRUE(IPAddressStartsWith(ipv4_address, ipv4_prefix3)); 292 EXPECT_TRUE(IPAddressStartsWith(ipv4_address, ipv4_prefix3));
249 293
250 uint8_t ipv4_prefix2[] = {192, 168, 10, 10}; 294 uint8_t ipv4_prefix2[] = {192, 168, 10, 10};
(...skipping 23 matching lines...) Expand all
274 318
275 // Prefix is longer than the address. 319 // Prefix is longer than the address.
276 uint8_t ipv6_prefix5[] = {42, 0, 20, 80, 64, 12, 12, 9, 0, 320 uint8_t ipv6_prefix5[] = {42, 0, 20, 80, 64, 12, 12, 9, 0,
277 0, 0, 0, 0, 0, 0, 0, 10}; 321 0, 0, 0, 0, 0, 0, 0, 10};
278 EXPECT_FALSE(IPAddressStartsWith(ipv6_address, ipv6_prefix5)); 322 EXPECT_FALSE(IPAddressStartsWith(ipv6_address, ipv6_prefix5));
279 } 323 }
280 324
281 } // anonymous namespace 325 } // anonymous namespace
282 326
283 } // namespace net 327 } // namespace net
OLDNEW
« no previous file with comments | « net/base/ip_address_number_unittest.cc ('k') | net/proxy/proxy_bypass_rules.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698