mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS 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 "shill/ppp_device.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | #include "shill/mock_ppp_device.h" |
| 13 | |
| 14 | using std::map; |
| 15 | using std::string; |
| 16 | |
| 17 | namespace shill { |
| 18 | |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 19 | // TODO(quiche): Add test for UpdateIPConfigFromPPP. crbug.com/266404 |
| 20 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 21 | TEST(PPPDeviceTest, GetInterfaceName) { |
| 22 | map<string, string> config; |
| 23 | config[kPPPInterfaceName] = "ppp0"; |
| 24 | config["foo"] = "bar"; |
| 25 | EXPECT_EQ("ppp0", PPPDevice::GetInterfaceName(config)); |
| 26 | } |
| 27 | |
| 28 | TEST(PPPDeviceTest, ParseIPConfiguration) { |
| 29 | map<string, string> config; |
| 30 | config[kPPPInternalIP4Address] = "4.5.6.7"; |
| 31 | config[kPPPExternalIP4Address] = "33.44.55.66"; |
| 32 | config[kPPPGatewayAddress] = "192.168.1.1"; |
| 33 | config[kPPPDNS1] = "1.1.1.1"; |
| 34 | config[kPPPDNS2] = "2.2.2.2"; |
| 35 | config[kPPPInterfaceName] = "ppp0"; |
| 36 | config[kPPPLNSAddress] = "99.88.77.66"; |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame^] | 37 | config["foo"] = "bar"; // Unrecognized keys don't cause crash. |
| 38 | IPConfig::Properties props = |
| 39 | PPPDevice::ParseIPConfiguration("in-test", config); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 40 | EXPECT_EQ(IPAddress::kFamilyIPv4, props.address_family); |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame^] | 41 | EXPECT_EQ(IPAddress::GetMaxPrefixLength(IPAddress::kFamilyIPv4), |
| 42 | props.subnet_prefix); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 43 | EXPECT_EQ("4.5.6.7", props.address); |
| 44 | EXPECT_EQ("33.44.55.66", props.peer_address); |
| 45 | EXPECT_EQ("192.168.1.1", props.gateway); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 46 | ASSERT_EQ(2, props.dns_servers.size()); |
| 47 | EXPECT_EQ("1.1.1.1", props.dns_servers[0]); |
| 48 | EXPECT_EQ("2.2.2.2", props.dns_servers[1]); |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame^] | 49 | EXPECT_EQ("99.88.77.66", props.trusted_ip); |
| 50 | |
| 51 | // No gateway specified. |
| 52 | config.erase(kPPPGatewayAddress); |
| 53 | IPConfig::Properties props2 = |
| 54 | PPPDevice::ParseIPConfiguration("in-test", config); |
| 55 | EXPECT_EQ("33.44.55.66", props2.gateway); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } // namespace shill |