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

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

Issue 2881673002: Avoid heap allocations in IPAddress (Closed)
Patch Set: Resize Created 3 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
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/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // Unreserved block(s) 183 // Unreserved block(s)
184 {"203.0.114.0", NOT_RESERVED}, 184 {"203.0.114.0", NOT_RESERVED},
185 {"223.255.255.255", NOT_RESERVED}, 185 {"223.255.255.255", NOT_RESERVED},
186 // 224.0.0.0/8 - 255.0.0.0/8 186 // 224.0.0.0/8 - 255.0.0.0/8
187 {"224.0.0.0", RESERVED}, 187 {"224.0.0.0", RESERVED},
188 {"255.255.255.255", RESERVED}}; 188 {"255.255.255.255", RESERVED}};
189 189
190 IPAddress address; 190 IPAddress address;
191 for (const auto& test : tests) { 191 for (const auto& test : tests) {
192 EXPECT_TRUE(address.AssignFromIPLiteral(test.address)); 192 EXPECT_TRUE(address.AssignFromIPLiteral(test.address));
193 ASSERT_TRUE(address.IsValid());
193 EXPECT_EQ(!!test.is_reserved, address.IsReserved()); 194 EXPECT_EQ(!!test.is_reserved, address.IsReserved());
194 } 195 }
195 } 196 }
196 197
197 // Tests for the reserved IPv6 ranges and the (unreserved) blocks in between. 198 // Tests for the reserved IPv6 ranges and the (unreserved) blocks in between.
198 // The reserved ranges are tested by checking the first and last address of each 199 // The reserved ranges are tested by checking the first and last address of each
199 // range. The unreserved blocks are tested similarly. These tests cover the 200 // range. The unreserved blocks are tested similarly. These tests cover the
200 // entire IPv6 address range. 201 // entire IPv6 address range.
201 TEST(IPAddressTest, IsReservedIPv6) { 202 TEST(IPAddressTest, IsReservedIPv6) {
202 struct { 203 struct {
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 594
594 // Prefix is longer than the address. 595 // Prefix is longer than the address.
595 uint8_t ipv6_prefix5[] = {42, 0, 20, 80, 64, 12, 12, 9, 0, 596 uint8_t ipv6_prefix5[] = {42, 0, 20, 80, 64, 12, 12, 9, 0,
596 0, 0, 0, 0, 0, 0, 0, 10}; 597 0, 0, 0, 0, 0, 0, 0, 10};
597 EXPECT_FALSE(IPAddressStartsWith(ipv6_address, ipv6_prefix5)); 598 EXPECT_FALSE(IPAddressStartsWith(ipv6_address, ipv6_prefix5));
598 } 599 }
599 600
600 } // anonymous namespace 601 } // anonymous namespace
601 602
602 } // namespace net 603 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698