shill: add yet more unit tests for ppp dongle support
This time, we add a test for Modem.
BUG=chromium:246826
TEST=unit tests (old+new)
Change-Id: I8d7118868d16eef370e5a95e8212ca510efe393e
Reviewed-on: https://gerrit.chromium.org/gerrit/64288
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
Commit-Queue: mukesh agrawal <quiche@chromium.org>
diff --git a/device_info.h b/device_info.h
index a85eb3b..c1d378e 100644
--- a/device_info.h
+++ b/device_info.h
@@ -63,7 +63,7 @@
virtual ~DeviceInfo();
void AddDeviceToBlackList(const std::string &device_name);
- bool IsDeviceBlackListed(const std::string &device_name);
+ virtual bool IsDeviceBlackListed(const std::string &device_name);
void Start();
void Stop();
diff --git a/mock_device_info.h b/mock_device_info.h
index 71ae32d..2d83a78 100644
--- a/mock_device_info.h
+++ b/mock_device_info.h
@@ -29,6 +29,7 @@
Manager *manager);
virtual ~MockDeviceInfo();
+ MOCK_METHOD1(IsDeviceBlackListed, bool(const std::string &device_name));
MOCK_CONST_METHOD1(GetDevice, DeviceRefPtr(int interface_index));
MOCK_CONST_METHOD1(GetIndex, int(const std::string &interface_name));
MOCK_CONST_METHOD2(GetMACAddress, bool(int interface_index,
diff --git a/modem.h b/modem.h
index 5c08f81..936a65f 100644
--- a/modem.h
+++ b/modem.h
@@ -82,6 +82,7 @@
FRIEND_TEST(ModemTest, CreateDeviceEarlyFailures);
FRIEND_TEST(ModemTest, CreateDevicePPP);
FRIEND_TEST(ModemTest, EarlyDeviceProperties);
+ FRIEND_TEST(ModemTest, GetDeviceParams);
FRIEND_TEST(ModemTest, Init);
FRIEND_TEST(ModemTest, PendingDevicePropertiesAndCreate);
@@ -93,7 +94,8 @@
// Find the |mac_address| and |interface_index| for the kernel
// network device with name |link_name|. Returns true iff both
- // |mac_address| and |interface_index| were found.
+ // |mac_address| and |interface_index| were found. Modifies
+ // |interface_index| even on failure.
virtual bool GetDeviceParams(std::string *mac_address, int *interface_index);
virtual void OnDBusPropertiesChanged(
diff --git a/modem_unittest.cc b/modem_unittest.cc
index 2480177..d950f98 100644
--- a/modem_unittest.cc
+++ b/modem_unittest.cc
@@ -30,6 +30,7 @@
using std::string;
using std::vector;
using testing::_;
+using testing::AnyNumber;
using testing::DoAll;
using testing::Return;
using testing::SetArgumentPointee;
@@ -204,6 +205,22 @@
Return(-1));
modem_->CreateDeviceFromModemProperties(properties);
EXPECT_FALSE(modem_->device_.get());
+
+ // The params are good, but the device is blacklisted.
+ EXPECT_CALL(*modem_, GetLinkName(_, _)).WillOnce(DoAll(
+ SetArgumentPointee<1>(string(kLinkName)),
+ Return(true)));
+ EXPECT_CALL(rtnl_handler_, GetInterfaceIndex(StrEq(kLinkName)))
+ .WillOnce(Return(kTestInterfaceIndex));
+ EXPECT_CALL(device_info_, GetMACAddress(kTestInterfaceIndex, _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(expected_address_),
+ Return(true)));
+ EXPECT_CALL(device_info_, IsDeviceBlackListed(kLinkName))
+ .WillRepeatedly(Return(true));
+ modem_->CreateDeviceFromModemProperties(properties);
+ EXPECT_FALSE(modem_->device_.get());
+
+ // No link name: see CreateDevicePPP.
}
TEST_F(ModemTest, CreateDevicePPP) {
@@ -244,6 +261,36 @@
EXPECT_CALL(device_info_, DeregisterDevice(_));
}
+TEST_F(ModemTest, GetDeviceParams) {
+ string mac_address;
+ int interface_index = 2;
+ EXPECT_CALL(rtnl_handler_, GetInterfaceIndex(_)).WillOnce(Return(-1));
+ EXPECT_CALL(device_info_, GetMACAddress(_, _)).Times(AnyNumber())
+ .WillRepeatedly(Return(false));
+ EXPECT_FALSE(modem_->GetDeviceParams(&mac_address, &interface_index));
+ EXPECT_EQ(-1, interface_index);
+
+ EXPECT_CALL(rtnl_handler_, GetInterfaceIndex(_)).WillOnce(Return(-2));
+ EXPECT_CALL(device_info_, GetMACAddress(_, _)).Times(AnyNumber())
+ .WillRepeatedly(Return(false));
+ EXPECT_FALSE(modem_->GetDeviceParams(&mac_address, &interface_index));
+ EXPECT_EQ(-2, interface_index);
+
+ EXPECT_CALL(rtnl_handler_, GetInterfaceIndex(_)).WillOnce(Return(1));
+ EXPECT_CALL(device_info_, GetMACAddress(_, _)).WillOnce(Return(false));
+ EXPECT_FALSE(modem_->GetDeviceParams(&mac_address, &interface_index));
+ EXPECT_EQ(1, interface_index);
+
+ EXPECT_CALL(rtnl_handler_, GetInterfaceIndex(_)).WillOnce(Return(2));
+ EXPECT_CALL(device_info_, GetMACAddress(2, _)).
+ WillOnce(DoAll(SetArgumentPointee<1>(expected_address_),
+ Return(true)));
+ EXPECT_TRUE(modem_->GetDeviceParams(&mac_address, &interface_index));
+ EXPECT_EQ(2, interface_index);
+ EXPECT_EQ(kAddressAsString, mac_address);
+
+}
+
TEST_F(ModemTest, RejectPPPModem) {
// TODO(rochberg): Port this to ModemClassic
}