OLD | NEW |
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 Loading... |
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 |
OLD | NEW |