MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / remoting / protocol / port_range_unittest.cc
blobf0fc3759081bd864341ac823016e1559c347e136
1 // Copyright 2015 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 "remoting/protocol/port_range.h"
7 #include <sstream>
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace remoting {
14 TEST(PortRange, ParseEmpty) {
15 PortRange port_range;
17 EXPECT_TRUE(PortRange::Parse("", &port_range));
18 EXPECT_TRUE(port_range.is_null());
21 TEST(PortRange, ParseValid) {
22 PortRange port_range;
24 EXPECT_TRUE(PortRange::Parse("1-65535", &port_range));
25 EXPECT_FALSE(port_range.is_null());
26 EXPECT_EQ(1u, port_range.min_port);
27 EXPECT_EQ(65535u, port_range.max_port);
29 EXPECT_TRUE(PortRange::Parse(" 1 - 65535 ", &port_range));
30 EXPECT_FALSE(port_range.is_null());
31 EXPECT_EQ(1u, port_range.min_port);
32 EXPECT_EQ(65535u, port_range.max_port);
34 EXPECT_TRUE(PortRange::Parse("12400-12400", &port_range));
35 EXPECT_FALSE(port_range.is_null());
36 EXPECT_EQ(12400u, port_range.min_port);
37 EXPECT_EQ(12400u, port_range.max_port);
40 TEST(PortRange, ParseInvalid) {
41 PortRange port_range;
42 port_range.min_port = 123;
43 port_range.max_port = 456;
45 EXPECT_FALSE(PortRange::Parse("-65535", &port_range));
46 EXPECT_FALSE(PortRange::Parse("1-", &port_range));
47 EXPECT_FALSE(PortRange::Parse("-", &port_range));
48 EXPECT_FALSE(PortRange::Parse("-1-65535", &port_range));
49 EXPECT_FALSE(PortRange::Parse("1--65535", &port_range));
50 EXPECT_FALSE(PortRange::Parse("1-65535-", &port_range));
51 EXPECT_FALSE(PortRange::Parse("0-65535", &port_range));
52 EXPECT_FALSE(PortRange::Parse("1-65536", &port_range));
53 EXPECT_FALSE(PortRange::Parse("1-4294967295", &port_range));
54 EXPECT_FALSE(PortRange::Parse("10-1", &port_range));
55 EXPECT_FALSE(PortRange::Parse("1foo-2bar", &port_range));
57 // Unsuccessful parses should NOT modify their output.
58 EXPECT_EQ(123, port_range.min_port);
59 EXPECT_EQ(456, port_range.max_port);
62 TEST(PortRange, Output) {
63 PortRange port_range;
64 port_range.min_port = 123;
65 port_range.max_port = 456;
67 std::ostringstream str;
68 str << port_range;
70 EXPECT_THAT(str.str(), testing::MatchesRegex(".*123.*456.*"));
73 } // namespace remoting