OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host_port_pair.h" | 5 #include "net/base/host_port_pair.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/test/gtest_util.h" | 8 #include "net/test/gtest_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 TEST(HostPortPairTest, Parsing) { | 31 TEST(HostPortPairTest, Parsing) { |
32 HostPortPair foo("foo.com", 10); | 32 HostPortPair foo("foo.com", 10); |
33 string foo_str = foo.ToString(); | 33 string foo_str = foo.ToString(); |
34 EXPECT_EQ("foo.com:10", foo_str); | 34 EXPECT_EQ("foo.com:10", foo_str); |
35 HostPortPair bar = HostPortPair::FromString(foo_str); | 35 HostPortPair bar = HostPortPair::FromString(foo_str); |
36 EXPECT_TRUE(foo.Equals(bar)); | 36 EXPECT_TRUE(foo.Equals(bar)); |
37 } | 37 } |
38 | 38 |
39 TEST(HostPortPairTest, BadString) { | 39 TEST(HostPortPairTest, BadString) { |
40 HostPortPair foo = HostPortPair::FromString("foo.com:2:3"); | 40 const char* kBadStrings[] = { |
41 EXPECT_TRUE(foo.host().empty()); | 41 "foo.com:2:3", |
42 EXPECT_EQ(0, foo.port()); | 42 "bar.com:two", |
| 43 "www.google.com:-1", |
| 44 "127.0.0.1:65536", |
| 45 "[2001:db8::42]:65536", |
| 46 }; |
43 | 47 |
44 HostPortPair bar = HostPortPair::FromString("bar.com:two"); | 48 for (size_t index = 0; index < arraysize(kBadStrings); ++index) { |
45 EXPECT_TRUE(bar.host().empty()); | 49 HostPortPair foo = HostPortPair::FromString(kBadStrings[index]); |
46 EXPECT_EQ(0, bar.port()); | 50 EXPECT_TRUE(foo.host().empty()); |
| 51 EXPECT_EQ(0, foo.port()); |
| 52 } |
47 } | 53 } |
48 | 54 |
49 TEST(HostPortPairTest, Emptiness) { | 55 TEST(HostPortPairTest, Emptiness) { |
50 HostPortPair foo; | 56 HostPortPair foo; |
51 EXPECT_TRUE(foo.IsEmpty()); | 57 EXPECT_TRUE(foo.IsEmpty()); |
52 foo = HostPortPair::FromString("foo.com:8080"); | 58 foo = HostPortPair::FromString("foo.com:8080"); |
53 EXPECT_FALSE(foo.IsEmpty()); | 59 EXPECT_FALSE(foo.IsEmpty()); |
54 } | 60 } |
55 | 61 |
56 TEST(HostPortPairTest, ToString) { | 62 TEST(HostPortPairTest, ToString) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 112 |
107 EXPECT_TRUE(new_a_10.Equals(a_10)); | 113 EXPECT_TRUE(new_a_10.Equals(a_10)); |
108 EXPECT_FALSE(new_a_10.Equals(a_11)); | 114 EXPECT_FALSE(new_a_10.Equals(a_11)); |
109 EXPECT_FALSE(new_a_10.Equals(b_10)); | 115 EXPECT_FALSE(new_a_10.Equals(b_10)); |
110 EXPECT_FALSE(new_a_10.Equals(b_11)); | 116 EXPECT_FALSE(new_a_10.Equals(b_11)); |
111 } | 117 } |
112 | 118 |
113 } // namespace | 119 } // namespace |
114 | 120 |
115 } // namespace net | 121 } // namespace net |
OLD | NEW |