summaryrefslogtreecommitdiffstats
path: root/net/base/host_port_pair_unittest.cc
blob: d654622dd0036a4dda06aebaf879ab09f5d1148e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/base/host_port_pair.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace net {

namespace {

TEST(HostPortPairTest, Parsing) {
  HostPortPair foo("foo.com", 10);
  std::string foo_str = foo.ToString();
  EXPECT_EQ("foo.com:10", foo_str);
  HostPortPair bar = HostPortPair::FromString(foo_str);
  EXPECT_TRUE(foo.Equals(bar));
}

TEST(HostPortPairTest, BadString) {
  HostPortPair foo = HostPortPair::FromString("foo.com:2:3");
  EXPECT_TRUE(foo.host().empty());
  EXPECT_EQ(0, foo.port());

  HostPortPair bar = HostPortPair::FromString("bar.com:two");
  EXPECT_TRUE(bar.host().empty());
  EXPECT_EQ(0, bar.port());
}

TEST(HostPortPairTest, Emptiness) {
  HostPortPair foo;
  EXPECT_TRUE(foo.IsEmpty());
  foo = HostPortPair::FromString("foo.com:8080");
  EXPECT_FALSE(foo.IsEmpty());
}

}  // namespace

}  // namespace net