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

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

Issue 1349783006: Cleanup: Pass std::string as const reference if possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert third_party changes Created 5 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_pattern.h" 5 #include "net/base/ip_pattern.h"
6 6
7 #include "net/base/ip_address_number.h" 7 #include "net/base/ip_address_number.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 namespace { 12 namespace {
13 13
14 bool IsValidPattern(const std::string& pattern_text) { 14 bool IsValidPattern(const std::string& pattern_text) {
15 IPPattern pattern; 15 IPPattern pattern;
16 return pattern.ParsePattern(pattern_text); 16 return pattern.ParsePattern(pattern_text);
17 } 17 }
18 18
19 bool CheckForMatch(const IPPattern& pattern, std::string address_text) { 19 bool CheckForMatch(const IPPattern& pattern, const std::string& address_text) {
20 IPAddressNumber address; 20 IPAddressNumber address;
21 EXPECT_TRUE(ParseIPLiteralToNumber(address_text, &address)); 21 EXPECT_TRUE(ParseIPLiteralToNumber(address_text, &address));
22 return pattern.Match(address); 22 return pattern.Match(address);
23 } 23 }
24 24
25 TEST(IPPatternTest, EmptyPattern) { 25 TEST(IPPatternTest, EmptyPattern) {
26 IPPattern pattern; 26 IPPattern pattern;
27 IPAddressNumber ipv4_address1; 27 IPAddressNumber ipv4_address1;
28 EXPECT_TRUE(ParseIPLiteralToNumber("1.2.3.4", &ipv4_address1)); 28 EXPECT_TRUE(ParseIPLiteralToNumber("1.2.3.4", &ipv4_address1));
29 IPAddressNumber ipv6_address1; 29 IPAddressNumber ipv6_address1;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 EXPECT_FALSE(IsValidPattern("1.2.3.4.5")); // Too long 152 EXPECT_FALSE(IsValidPattern("1.2.3.4.5")); // Too long
153 EXPECT_FALSE(IsValidPattern("1.2.3")); // Too short 153 EXPECT_FALSE(IsValidPattern("1.2.3")); // Too short
154 EXPECT_FALSE(IsValidPattern("1.2.3.A")); // Non-decimal. 154 EXPECT_FALSE(IsValidPattern("1.2.3.A")); // Non-decimal.
155 EXPECT_FALSE(IsValidPattern("1.A.3.4")); // Non-decimal 155 EXPECT_FALSE(IsValidPattern("1.A.3.4")); // Non-decimal
156 EXPECT_FALSE(IsValidPattern("1.256.3.4")); // Out of range 156 EXPECT_FALSE(IsValidPattern("1.256.3.4")); // Out of range
157 } 157 }
158 158
159 } // namespace 159 } // namespace
160 160
161 } // namespace net 161 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698