blob: 6bc2c1086ab38d9e7eb012c91e2d50a4677edb0e [file] [log] [blame]
Peter Qiuc0beca52015-09-03 11:25:46 -07001//
2// Copyright (C) 2013 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
mukesh agrawal9da07772013-05-15 14:15:17 -070016
17#include "shill/ppp_device.h"
18
19#include <map>
20#include <string>
21
22#include <gtest/gtest.h>
23
Garret Kelly9dd6d6d2015-06-25 16:19:38 -040024#include "shill/metrics.h"
25#include "shill/mock_control.h"
26#include "shill/mock_metrics.h"
mukesh agrawal9da07772013-05-15 14:15:17 -070027#include "shill/mock_ppp_device.h"
28
29using std::map;
30using std::string;
31
32namespace shill {
33
mukesh agrawalf407d592013-07-31 11:37:57 -070034// TODO(quiche): Add test for UpdateIPConfigFromPPP. crbug.com/266404
35
mukesh agrawal9da07772013-05-15 14:15:17 -070036TEST(PPPDeviceTest, GetInterfaceName) {
37 map<string, string> config;
38 config[kPPPInterfaceName] = "ppp0";
39 config["foo"] = "bar";
40 EXPECT_EQ("ppp0", PPPDevice::GetInterfaceName(config));
41}
42
43TEST(PPPDeviceTest, ParseIPConfiguration) {
Garret Kelly9dd6d6d2015-06-25 16:19:38 -040044 MockControl control;
45 MockMetrics metrics(nullptr);
46 scoped_refptr<PPPDevice> device = new PPPDevice(&control, nullptr, &metrics,
47 nullptr, "test0", 0);
48
mukesh agrawal9da07772013-05-15 14:15:17 -070049 map<string, string> config;
50 config[kPPPInternalIP4Address] = "4.5.6.7";
51 config[kPPPExternalIP4Address] = "33.44.55.66";
52 config[kPPPGatewayAddress] = "192.168.1.1";
53 config[kPPPDNS1] = "1.1.1.1";
54 config[kPPPDNS2] = "2.2.2.2";
55 config[kPPPInterfaceName] = "ppp0";
56 config[kPPPLNSAddress] = "99.88.77.66";
Garret Kelly16ff6eb2015-06-24 16:11:38 -040057 config[kPPPMRU] = "1492";
mukesh agrawal4fef2492013-08-01 16:03:59 -070058 config["foo"] = "bar"; // Unrecognized keys don't cause crash.
Garret Kelly9dd6d6d2015-06-25 16:19:38 -040059 EXPECT_CALL(metrics, SendSparseToUMA(Metrics::kMetricPPPMTUValue, 1492));
60 IPConfig::Properties props = device->ParseIPConfiguration("in-test", config);
mukesh agrawal9da07772013-05-15 14:15:17 -070061 EXPECT_EQ(IPAddress::kFamilyIPv4, props.address_family);
mukesh agrawal4fef2492013-08-01 16:03:59 -070062 EXPECT_EQ(IPAddress::GetMaxPrefixLength(IPAddress::kFamilyIPv4),
63 props.subnet_prefix);
mukesh agrawal9da07772013-05-15 14:15:17 -070064 EXPECT_EQ("4.5.6.7", props.address);
65 EXPECT_EQ("33.44.55.66", props.peer_address);
66 EXPECT_EQ("192.168.1.1", props.gateway);
mukesh agrawal9da07772013-05-15 14:15:17 -070067 ASSERT_EQ(2, props.dns_servers.size());
68 EXPECT_EQ("1.1.1.1", props.dns_servers[0]);
69 EXPECT_EQ("2.2.2.2", props.dns_servers[1]);
Prabhu Kaliamoorthi762bfb82015-02-06 13:17:08 +010070 EXPECT_EQ("99.88.77.66/32", props.exclusion_list[0]);
71 EXPECT_EQ(1, props.exclusion_list.size());
Garret Kelly16ff6eb2015-06-24 16:11:38 -040072 EXPECT_EQ(1492, props.mtu);
mukesh agrawal4fef2492013-08-01 16:03:59 -070073
74 // No gateway specified.
75 config.erase(kPPPGatewayAddress);
Garret Kelly9dd6d6d2015-06-25 16:19:38 -040076 EXPECT_CALL(metrics, SendSparseToUMA(Metrics::kMetricPPPMTUValue, 1492));
77 IPConfig::Properties props2 = device->ParseIPConfiguration("in-test", config);
mukesh agrawal4fef2492013-08-01 16:03:59 -070078 EXPECT_EQ("33.44.55.66", props2.gateway);
mukesh agrawal9da07772013-05-15 14:15:17 -070079}
80
81} // namespace shill