Chromium Code Reviews| 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 |
| 11 using std::string; | 11 using std::string; |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 struct TestData { | 17 struct TestData { |
| 18 string host; | 18 string host; |
| 19 uint16 port; | 19 uint16 port; |
| 20 string to_string; | 20 string to_string; |
| 21 string host_for_url; | 21 string host_for_url; |
| 22 } tests[] = { | 22 } tests[] = { |
| 23 { "www.google.com", 80, "www.google.com:80", "www.google.com" }, | 23 {"www.google.com", 80, "www.google.com:80", "www.google.com"}, |
|
mef
2014/10/10 20:38:17
questionable alignment.
| |
| 24 { "www.google.com", 443, "www.google.com:443", "www.google.com" }, | 24 {"www.google.com", 443, "www.google.com:443", "www.google.com"}, |
| 25 { "127.0.0.1", 80, "127.0.0.1:80", "127.0.0.1" }, | 25 {"127.0.0.1", 80, "127.0.0.1:80", "127.0.0.1"}, |
| 26 { "192.168.1.1", 80, "192.168.1.1:80", "192.168.1.1" }, | 26 {"192.168.1.1", 80, "192.168.1.1:80", "192.168.1.1"}, |
| 27 { "::1", 80, "[::1]:80", "[::1]" }, | 27 {"::1", 80, "[::1]:80", "[::1]"}, |
| 28 { "2001:db8::42", 80, "[2001:db8::42]:80", "[2001:db8::42]" }, | 28 {"2001:db8::42", 80, "[2001:db8::42]:80", "[2001:db8::42]"}, |
| 29 }; | 29 }; |
| 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 EXPECT_DFATAL(bar.HostForURL(), expected_error); | 76 EXPECT_DFATAL(bar.HostForURL(), expected_error); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST(HostPortPairTest, LessThan) { | 79 TEST(HostPortPairTest, LessThan) { |
| 80 HostPortPair a_10("a.com", 10); | 80 HostPortPair a_10("a.com", 10); |
| 81 HostPortPair a_11("a.com", 11); | 81 HostPortPair a_11("a.com", 11); |
| 82 HostPortPair b_10("b.com", 10); | 82 HostPortPair b_10("b.com", 10); |
| 83 HostPortPair b_11("b.com", 11); | 83 HostPortPair b_11("b.com", 11); |
| 84 | 84 |
| 85 EXPECT_FALSE(a_10 < a_10); | 85 EXPECT_FALSE(a_10 < a_10); |
| 86 EXPECT_TRUE(a_10 < a_11); | 86 EXPECT_TRUE(a_10 < a_11); |
| 87 EXPECT_TRUE(a_10 < b_10); | 87 EXPECT_TRUE(a_10 < b_10); |
| 88 EXPECT_TRUE(a_10 < b_11); | 88 EXPECT_TRUE(a_10 < b_11); |
| 89 | 89 |
| 90 EXPECT_FALSE(a_11 < a_10); | 90 EXPECT_FALSE(a_11 < a_10); |
| 91 EXPECT_FALSE(a_11 < b_10); | 91 EXPECT_FALSE(a_11 < b_10); |
| 92 | 92 |
| 93 EXPECT_FALSE(b_10 < a_10); | 93 EXPECT_FALSE(b_10 < a_10); |
| 94 EXPECT_TRUE(b_10 < a_11); | 94 EXPECT_TRUE(b_10 < a_11); |
| 95 | 95 |
| 96 EXPECT_FALSE(b_11 < a_10); | 96 EXPECT_FALSE(b_11 < a_10); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST(HostPortPairTest, Equals) { | 99 TEST(HostPortPairTest, Equals) { |
| 100 HostPortPair a_10("a.com", 10); | 100 HostPortPair a_10("a.com", 10); |
| 101 HostPortPair a_11("a.com", 11); | 101 HostPortPair a_11("a.com", 11); |
| 102 HostPortPair b_10("b.com", 10); | 102 HostPortPair b_10("b.com", 10); |
| 103 HostPortPair b_11("b.com", 11); | 103 HostPortPair b_11("b.com", 11); |
| 104 | 104 |
| 105 HostPortPair new_a_10("a.com", 10); | 105 HostPortPair new_a_10("a.com", 10); |
| 106 | 106 |
| 107 EXPECT_TRUE(new_a_10.Equals(a_10)); | 107 EXPECT_TRUE(new_a_10.Equals(a_10)); |
| 108 EXPECT_FALSE(new_a_10.Equals(a_11)); | 108 EXPECT_FALSE(new_a_10.Equals(a_11)); |
| 109 EXPECT_FALSE(new_a_10.Equals(b_10)); | 109 EXPECT_FALSE(new_a_10.Equals(b_10)); |
| 110 EXPECT_FALSE(new_a_10.Equals(b_11)); | 110 EXPECT_FALSE(new_a_10.Equals(b_11)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace | 113 } // namespace |
| 114 | 114 |
| 115 } // namespace net | 115 } // namespace net |
| OLD | NEW |