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 3 // found in the LICENSE file. 4 5 #include "net/base/host_port_pair.h" 6 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 namespace net { 10 11 namespace { 12 13 TEST(HostPortPairTest, Parsing) { 14 HostPortPair foo("foo.com", 10); 15 std::string foo_str = foo.ToString(); 16 EXPECT_EQ("foo.com:10", foo_str); 17 HostPortPair bar = HostPortPair::FromString(foo_str); 18 EXPECT_TRUE(foo.Equals(bar)); 19 } 20 21 TEST(HostPortPairTest, BadString) { 22 HostPortPair foo = HostPortPair::FromString("foo.com:2:3"); 23 EXPECT_TRUE(foo.host().empty()); 24 EXPECT_EQ(0, foo.port()); 25 26 HostPortPair bar = HostPortPair::FromString("bar.com:two"); 27 EXPECT_TRUE(bar.host().empty()); 28 EXPECT_EQ(0, bar.port()); 29 } 30 31 TEST(HostPortPairTest, Emptiness) { 32 HostPortPair foo; 33 EXPECT_TRUE(foo.IsEmpty()); 34 foo = HostPortPair::FromString("foo.com:8080"); 35 EXPECT_FALSE(foo.IsEmpty()); 36 } 37 38 } // namespace 39 40 } // namespace net 41