network_settings_unittest.cc revision 116680a4aac90f2aa7413d9095a592090648e557
1// Copyright 2014 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 "remoting/protocol/network_settings.h"
6
7#include "testing/gtest/include/gtest/gtest.h"
8
9namespace remoting {
10namespace protocol {
11
12TEST(ParsePortRange, Basic) {
13  int min, max;
14
15  // Valid range
16  EXPECT_TRUE(NetworkSettings::ParsePortRange("1-65535", &min, &max));
17  EXPECT_EQ(1, min);
18  EXPECT_EQ(65535, max);
19
20  EXPECT_TRUE(NetworkSettings::ParsePortRange(" 1 - 65535 ", &min, &max));
21  EXPECT_EQ(1, min);
22  EXPECT_EQ(65535, max);
23
24  EXPECT_TRUE(NetworkSettings::ParsePortRange("12400-12400", &min, &max));
25  EXPECT_EQ(12400, min);
26  EXPECT_EQ(12400, max);
27
28  // Invalid
29  EXPECT_FALSE(NetworkSettings::ParsePortRange("", &min, &max));
30  EXPECT_FALSE(NetworkSettings::ParsePortRange("-65535", &min, &max));
31  EXPECT_FALSE(NetworkSettings::ParsePortRange("1-", &min, &max));
32  EXPECT_FALSE(NetworkSettings::ParsePortRange("-", &min, &max));
33  EXPECT_FALSE(NetworkSettings::ParsePortRange("-1-65535", &min, &max));
34  EXPECT_FALSE(NetworkSettings::ParsePortRange("1--65535", &min, &max));
35  EXPECT_FALSE(NetworkSettings::ParsePortRange("1-65535-", &min, &max));
36  EXPECT_FALSE(NetworkSettings::ParsePortRange("0-65535", &min, &max));
37  EXPECT_FALSE(NetworkSettings::ParsePortRange("1-65536", &min, &max));
38  EXPECT_FALSE(NetworkSettings::ParsePortRange("1-4294967295", &min, &max));
39  EXPECT_FALSE(NetworkSettings::ParsePortRange("10-1", &min, &max));
40  EXPECT_FALSE(NetworkSettings::ParsePortRange("1foo-2bar", &min, &max));
41}
42
43}  // namespace protocol
44}  // namespace remoting
45