| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/net_util.h" | 5 #include "net/base/net_util.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 2148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2159 &ip_prefix, | 2159 &ip_prefix, |
| 2160 &prefix_length_in_bits)); | 2160 &prefix_length_in_bits)); |
| 2161 | 2161 |
| 2162 EXPECT_EQ(tests[i].expected_to_match, | 2162 EXPECT_EQ(tests[i].expected_to_match, |
| 2163 IPNumberMatchesPrefix(ip_number, | 2163 IPNumberMatchesPrefix(ip_number, |
| 2164 ip_prefix, | 2164 ip_prefix, |
| 2165 prefix_length_in_bits)); | 2165 prefix_length_in_bits)); |
| 2166 } | 2166 } |
| 2167 } | 2167 } |
| 2168 | 2168 |
| 2169 TEST(NetUtilTest, IsLocalhost) { |
| 2170 EXPECT_TRUE(net::IsLocalhost("localhost")); |
| 2171 EXPECT_TRUE(net::IsLocalhost("localhost.localdomain")); |
| 2172 EXPECT_TRUE(net::IsLocalhost("localhost6")); |
| 2173 EXPECT_TRUE(net::IsLocalhost("localhost6.localdomain6")); |
| 2174 EXPECT_TRUE(net::IsLocalhost("127.0.0.1")); |
| 2175 EXPECT_TRUE(net::IsLocalhost("127.0.1.0")); |
| 2176 EXPECT_TRUE(net::IsLocalhost("127.1.0.0")); |
| 2177 EXPECT_TRUE(net::IsLocalhost("127.0.0.255")); |
| 2178 EXPECT_TRUE(net::IsLocalhost("127.0.255.0")); |
| 2179 EXPECT_TRUE(net::IsLocalhost("127.255.0.0")); |
| 2180 EXPECT_TRUE(net::IsLocalhost("::1")); |
| 2181 EXPECT_TRUE(net::IsLocalhost("0:0:0:0:0:0:0:1")); |
| 2182 |
| 2183 EXPECT_FALSE(net::IsLocalhost("localhostx")); |
| 2184 EXPECT_FALSE(net::IsLocalhost("foo.localdomain")); |
| 2185 EXPECT_FALSE(net::IsLocalhost("localhost6x")); |
| 2186 EXPECT_FALSE(net::IsLocalhost("localhost.localdomain6")); |
| 2187 EXPECT_FALSE(net::IsLocalhost("localhost6.localdomain")); |
| 2188 EXPECT_FALSE(net::IsLocalhost("127.0.0.1.1")); |
| 2189 EXPECT_FALSE(net::IsLocalhost(".127.0.0.255")); |
| 2190 EXPECT_FALSE(net::IsLocalhost("::2")); |
| 2191 EXPECT_FALSE(net::IsLocalhost("::1:1")); |
| 2192 EXPECT_FALSE(net::IsLocalhost("0:0:0:0:1:0:0:1")); |
| 2193 EXPECT_FALSE(net::IsLocalhost("::1:1")); |
| 2194 EXPECT_FALSE(net::IsLocalhost("0:0:0:0:0:0:0:0:1")); |
| 2195 } |
| 2196 |
| 2169 // Verify GetNetworkList(). | 2197 // Verify GetNetworkList(). |
| 2170 TEST(NetUtilTest, GetNetworkList) { | 2198 TEST(NetUtilTest, GetNetworkList) { |
| 2171 NetworkInterfaceList list; | 2199 NetworkInterfaceList list; |
| 2172 ASSERT_TRUE(GetNetworkList(&list)); | 2200 ASSERT_TRUE(GetNetworkList(&list)); |
| 2173 | 2201 |
| 2174 for (NetworkInterfaceList::iterator it = list.begin(); | 2202 for (NetworkInterfaceList::iterator it = list.begin(); |
| 2175 it != list.end(); ++it) { | 2203 it != list.end(); ++it) { |
| 2176 // Verify that the name is not empty. | 2204 // Verify that the name is not empty. |
| 2177 EXPECT_FALSE(it->name.empty()); | 2205 EXPECT_FALSE(it->name.empty()); |
| 2178 | 2206 |
| 2179 // Verify that the address is correct. | 2207 // Verify that the address is correct. |
| 2180 EXPECT_TRUE(it->address.size() == kIPv4AddressSize || | 2208 EXPECT_TRUE(it->address.size() == kIPv4AddressSize || |
| 2181 it->address.size() == kIPv6AddressSize) | 2209 it->address.size() == kIPv6AddressSize) |
| 2182 << "Invalid address of size " << it->address.size(); | 2210 << "Invalid address of size " << it->address.size(); |
| 2183 bool all_zeroes = true; | 2211 bool all_zeroes = true; |
| 2184 for (size_t i = 0; i < it->address.size(); ++i) { | 2212 for (size_t i = 0; i < it->address.size(); ++i) { |
| 2185 if (it->address[i] != 0) { | 2213 if (it->address[i] != 0) { |
| 2186 all_zeroes = false; | 2214 all_zeroes = false; |
| 2187 break; | 2215 break; |
| 2188 } | 2216 } |
| 2189 } | 2217 } |
| 2190 EXPECT_FALSE(all_zeroes); | 2218 EXPECT_FALSE(all_zeroes); |
| 2191 } | 2219 } |
| 2192 } | 2220 } |
| 2193 | 2221 |
| 2194 } // namespace net | 2222 } // namespace net |
| OLD | NEW |