blob: add236eea50345af05a28b28f4e0d1991ed2d7ff [file] [log] [blame]
mukesh agrawal9da07772013-05-15 14:15:17 -07001// 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
14using std::map;
15using std::string;
16
17namespace shill {
18
mukesh agrawalf407d592013-07-31 11:37:57 -070019// TODO(quiche): Add test for UpdateIPConfigFromPPP. crbug.com/266404
20
mukesh agrawal9da07772013-05-15 14:15:17 -070021TEST(PPPDeviceTest, GetInterfaceName) {
22 map<string, string> config;
23 config[kPPPInterfaceName] = "ppp0";
24 config["foo"] = "bar";
25 EXPECT_EQ("ppp0", PPPDevice::GetInterfaceName(config));
26}
27
28TEST(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 agrawal4fef2492013-08-01 16:03:59 -070037 config["foo"] = "bar"; // Unrecognized keys don't cause crash.
38 IPConfig::Properties props =
39 PPPDevice::ParseIPConfiguration("in-test", config);
mukesh agrawal9da07772013-05-15 14:15:17 -070040 EXPECT_EQ(IPAddress::kFamilyIPv4, props.address_family);
mukesh agrawal4fef2492013-08-01 16:03:59 -070041 EXPECT_EQ(IPAddress::GetMaxPrefixLength(IPAddress::kFamilyIPv4),
42 props.subnet_prefix);
mukesh agrawal9da07772013-05-15 14:15:17 -070043 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 agrawal9da07772013-05-15 14:15:17 -070046 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 agrawal4fef2492013-08-01 16:03:59 -070049 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 agrawal9da07772013-05-15 14:15:17 -070056}
57
58} // namespace shill