Peter Qiu | c0beca5 | 2015-09-03 11:25:46 -0700 | [diff] [blame] | 1 | // |
| 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 agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 16 | |
| 17 | #include "shill/ppp_device.h" |
| 18 | |
| 19 | #include <map> |
| 20 | #include <string> |
| 21 | |
| 22 | #include <gtest/gtest.h> |
| 23 | |
Garret Kelly | 9dd6d6d | 2015-06-25 16:19:38 -0400 | [diff] [blame] | 24 | #include "shill/metrics.h" |
| 25 | #include "shill/mock_control.h" |
| 26 | #include "shill/mock_metrics.h" |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 27 | #include "shill/mock_ppp_device.h" |
| 28 | |
| 29 | using std::map; |
| 30 | using std::string; |
| 31 | |
| 32 | namespace shill { |
| 33 | |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 34 | // TODO(quiche): Add test for UpdateIPConfigFromPPP. crbug.com/266404 |
| 35 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 36 | TEST(PPPDeviceTest, GetInterfaceName) { |
| 37 | map<string, string> config; |
| 38 | config[kPPPInterfaceName] = "ppp0"; |
| 39 | config["foo"] = "bar"; |
| 40 | EXPECT_EQ("ppp0", PPPDevice::GetInterfaceName(config)); |
| 41 | } |
| 42 | |
| 43 | TEST(PPPDeviceTest, ParseIPConfiguration) { |
Garret Kelly | 9dd6d6d | 2015-06-25 16:19:38 -0400 | [diff] [blame] | 44 | MockControl control; |
| 45 | MockMetrics metrics(nullptr); |
| 46 | scoped_refptr<PPPDevice> device = new PPPDevice(&control, nullptr, &metrics, |
| 47 | nullptr, "test0", 0); |
| 48 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 49 | 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 Kelly | 16ff6eb | 2015-06-24 16:11:38 -0400 | [diff] [blame] | 57 | config[kPPPMRU] = "1492"; |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 58 | config["foo"] = "bar"; // Unrecognized keys don't cause crash. |
Garret Kelly | 9dd6d6d | 2015-06-25 16:19:38 -0400 | [diff] [blame] | 59 | EXPECT_CALL(metrics, SendSparseToUMA(Metrics::kMetricPPPMTUValue, 1492)); |
| 60 | IPConfig::Properties props = device->ParseIPConfiguration("in-test", config); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 61 | EXPECT_EQ(IPAddress::kFamilyIPv4, props.address_family); |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 62 | EXPECT_EQ(IPAddress::GetMaxPrefixLength(IPAddress::kFamilyIPv4), |
| 63 | props.subnet_prefix); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 64 | 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 agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 67 | 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 Kaliamoorthi | 762bfb8 | 2015-02-06 13:17:08 +0100 | [diff] [blame] | 70 | EXPECT_EQ("99.88.77.66/32", props.exclusion_list[0]); |
| 71 | EXPECT_EQ(1, props.exclusion_list.size()); |
Garret Kelly | 16ff6eb | 2015-06-24 16:11:38 -0400 | [diff] [blame] | 72 | EXPECT_EQ(1492, props.mtu); |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 73 | |
| 74 | // No gateway specified. |
| 75 | config.erase(kPPPGatewayAddress); |
Garret Kelly | 9dd6d6d | 2015-06-25 16:19:38 -0400 | [diff] [blame] | 76 | EXPECT_CALL(metrics, SendSparseToUMA(Metrics::kMetricPPPMTUValue, 1492)); |
| 77 | IPConfig::Properties props2 = device->ParseIPConfiguration("in-test", config); |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 78 | EXPECT_EQ("33.44.55.66", props2.gateway); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | } // namespace shill |