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.
5 #include "net/base/host_port_pair.h"
7 #include "testing/gtest/include/gtest/gtest.h"
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
));
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());
26 HostPortPair bar
= HostPortPair::FromString("bar.com:two");
27 EXPECT_TRUE(bar
.host().empty());
28 EXPECT_EQ(0, bar
.port());
31 TEST(HostPortPairTest
, Emptiness
) {
33 EXPECT_TRUE(foo
.IsEmpty());
34 foo
= HostPortPair::FromString("foo.com:8080");
35 EXPECT_FALSE(foo
.IsEmpty());