Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 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/modem.h" |
| 6 | |
Paul Stewart | 5ad1606 | 2013-02-21 18:10:48 -0800 | [diff] [blame] | 7 | #include <base/files/scoped_temp_dir.h> |
Ben Chan | 5c853ef | 2012-10-05 00:05:37 -0700 | [diff] [blame] | 8 | #include <ModemManager/ModemManager.h> |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 9 | |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 10 | #include "shill/cellular_capability.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 11 | #include "shill/dbus_property_matchers.h" |
| 12 | #include "shill/event_dispatcher.h" |
| 13 | #include "shill/manager.h" |
| 14 | #include "shill/mock_cellular.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 15 | #include "shill/mock_dbus_properties_proxy.h" |
| 16 | #include "shill/mock_device_info.h" |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 17 | #include "shill/mock_modem_info.h" |
Ben Chan | 1e2ba23 | 2014-01-27 16:35:45 -0800 | [diff] [blame] | 18 | #include "shill/mock_proxy_factory.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 19 | #include "shill/mock_rtnl_handler.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 20 | #include "shill/rtnl_handler.h" |
Ben Chan | 1e2ba23 | 2014-01-27 16:35:45 -0800 | [diff] [blame] | 21 | #include "shill/testing.h" |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 22 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 23 | using base::FilePath; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 24 | using std::string; |
Prathmesh Prabhu | 5c1f29c | 2013-09-10 18:14:09 -0700 | [diff] [blame] | 25 | using std::vector; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 26 | using testing::_; |
| 27 | using testing::DoAll; |
| 28 | using testing::Return; |
| 29 | using testing::SetArgumentPointee; |
| 30 | using testing::Test; |
| 31 | |
| 32 | namespace shill { |
| 33 | |
| 34 | namespace { |
| 35 | |
| 36 | const int kTestInterfaceIndex = 5; |
| 37 | const char kLinkName[] = "usb0"; |
| 38 | const char kOwner[] = ":1.18"; |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 39 | const char kService[] = "org.chromium.ModemManager"; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 40 | const char kPath[] = "/org/chromium/ModemManager/Gobi/0"; |
| 41 | const unsigned char kAddress[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 42 | |
| 43 | } // namespace |
| 44 | |
| 45 | class Modem1Test : public Test { |
| 46 | public: |
| 47 | Modem1Test() |
Ben Chan | ea18c6c | 2014-09-30 13:08:26 -0700 | [diff] [blame] | 48 | : modem_info_(nullptr, &dispatcher_, nullptr, nullptr, nullptr), |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 49 | device_info_(modem_info_.control_interface(), modem_info_.dispatcher(), |
| 50 | modem_info_.metrics(), modem_info_.manager()), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 51 | proxy_(new MockDBusPropertiesProxy()), |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 52 | modem_( |
| 53 | new Modem1( |
| 54 | kOwner, |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 55 | kService, |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 56 | kPath, |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 57 | &modem_info_)) {} |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 58 | virtual void SetUp(); |
| 59 | virtual void TearDown(); |
| 60 | |
| 61 | void ReplaceSingletons() { |
| 62 | modem_->rtnl_handler_ = &rtnl_handler_; |
| 63 | modem_->proxy_factory_ = &proxy_factory_; |
| 64 | } |
| 65 | |
| 66 | protected: |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 67 | EventDispatcher dispatcher_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 68 | MockModemInfo modem_info_; |
| 69 | MockDeviceInfo device_info_; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 70 | std::unique_ptr<MockDBusPropertiesProxy> proxy_; |
Ben Chan | 1e2ba23 | 2014-01-27 16:35:45 -0800 | [diff] [blame] | 71 | MockProxyFactory proxy_factory_; |
Ben Chan | c20ed13 | 2014-10-16 12:25:03 -0700 | [diff] [blame] | 72 | std::unique_ptr<Modem1> modem_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 73 | MockRTNLHandler rtnl_handler_; |
| 74 | ByteString expected_address_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | void Modem1Test::SetUp() { |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 78 | EXPECT_EQ(kOwner, modem_->owner_); |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 79 | EXPECT_EQ(kService, modem_->service_); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 80 | EXPECT_EQ(kPath, modem_->path_); |
| 81 | ReplaceSingletons(); |
| 82 | expected_address_ = ByteString(kAddress, arraysize(kAddress)); |
| 83 | |
| 84 | EXPECT_CALL(rtnl_handler_, GetInterfaceIndex(kLinkName)). |
| 85 | WillRepeatedly(Return(kTestInterfaceIndex)); |
| 86 | |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 87 | EXPECT_CALL(*modem_info_.mock_manager(), device_info()) |
| 88 | .WillRepeatedly(Return(&device_info_)); |
| 89 | EXPECT_CALL(device_info_, GetMACAddress(kTestInterfaceIndex, _)). |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 90 | WillOnce(DoAll(SetArgumentPointee<1>(expected_address_), |
| 91 | Return(true))); |
| 92 | } |
| 93 | |
| 94 | void Modem1Test::TearDown() { |
| 95 | modem_.reset(); |
| 96 | } |
| 97 | |
| 98 | TEST_F(Modem1Test, CreateDeviceMM1) { |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 99 | DBusInterfaceToProperties properties; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 100 | DBusPropertiesMap modem_properties; |
| 101 | DBus::Variant lock; |
| 102 | lock.writer().append_uint32(MM_MODEM_LOCK_NONE); |
| 103 | modem_properties[MM_MODEM_PROPERTY_UNLOCKREQUIRED] = lock; |
Prathmesh Prabhu | 5c1f29c | 2013-09-10 18:14:09 -0700 | [diff] [blame] | 104 | |
| 105 | DBus::Variant ports_variant; |
| 106 | DBus::MessageIter ports_message_iter = ports_variant.writer(); |
| 107 | DBus::MessageIter ports_array_iter = ports_message_iter.new_array("(su)"); |
| 108 | DBus::MessageIter port_struct_iter = ports_array_iter.new_struct(); |
| 109 | port_struct_iter.append_string(kLinkName); |
| 110 | port_struct_iter.append_uint32(MM_MODEM_PORT_TYPE_NET); |
| 111 | ports_array_iter.close_container(port_struct_iter); |
| 112 | ports_message_iter.close_container(ports_array_iter); |
| 113 | modem_properties[MM_MODEM_PROPERTY_PORTS] = ports_variant; |
| 114 | |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 115 | properties[MM_DBUS_INTERFACE_MODEM] = modem_properties; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 116 | |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 117 | DBusPropertiesMap modem3gpp_properties; |
| 118 | DBus::Variant registration_state_variant; |
| 119 | registration_state_variant.writer().append_uint32( |
| 120 | MM_MODEM_3GPP_REGISTRATION_STATE_HOME); |
| 121 | modem3gpp_properties[MM_MODEM_MODEM3GPP_PROPERTY_REGISTRATIONSTATE] = |
| 122 | registration_state_variant; |
| 123 | properties[MM_DBUS_INTERFACE_MODEM_MODEM3GPP] = modem3gpp_properties; |
| 124 | |
Ben Chan | 1e2ba23 | 2014-01-27 16:35:45 -0800 | [diff] [blame] | 125 | EXPECT_CALL(proxy_factory_, CreateDBusPropertiesProxy(kPath, kOwner)) |
| 126 | .WillOnce(ReturnAndReleasePointee(&proxy_)); |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 127 | modem_->CreateDeviceMM1(properties); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 128 | EXPECT_TRUE(modem_->device().get()); |
Ben Chan | 876efd3 | 2012-09-28 15:25:13 -0700 | [diff] [blame] | 129 | EXPECT_TRUE(modem_->device()->capability_->IsRegistered()); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | } // namespace shill |