Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [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/cellular_capability_gsm.h" |
| 6 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 7 | #include <base/bind.h> |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 8 | #include <chromeos/dbus/service_constants.h> |
| 9 | #include <gtest/gtest.h> |
| 10 | #include <mm/mm-modem.h> |
| 11 | #include <mobile_provider.h> |
| 12 | |
| 13 | #include "shill/cellular.h" |
| 14 | #include "shill/cellular_service.h" |
| 15 | #include "shill/error.h" |
| 16 | #include "shill/event_dispatcher.h" |
| 17 | #include "shill/mock_adaptors.h" |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 18 | #include "shill/mock_glib.h" |
| 19 | #include "shill/mock_manager.h" |
| 20 | #include "shill/mock_metrics.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 21 | #include "shill/mock_modem_cdma_proxy.h" |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 22 | #include "shill/mock_modem_gobi_proxy.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 23 | #include "shill/mock_modem_gsm_card_proxy.h" |
| 24 | #include "shill/mock_modem_gsm_network_proxy.h" |
| 25 | #include "shill/mock_modem_proxy.h" |
| 26 | #include "shill/mock_modem_simple_proxy.h" |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 27 | #include "shill/mock_profile.h" |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 28 | #include "shill/mock_rtnl_handler.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 29 | #include "shill/nice_mock_control.h" |
| 30 | #include "shill/proxy_factory.h" |
| 31 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 32 | using base::Bind; |
| 33 | using base::Unretained; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 34 | using std::string; |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 35 | using testing::InSequence; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 36 | using testing::NiceMock; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 37 | using testing::_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 38 | |
| 39 | namespace shill { |
| 40 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 41 | MATCHER(IsSuccess, "") { |
| 42 | return arg.IsSuccess(); |
| 43 | } |
| 44 | MATCHER(IsFailure, "") { |
| 45 | return arg.IsFailure(); |
| 46 | } |
| 47 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 48 | class CellularCapabilityTest : public testing::Test { |
| 49 | public: |
| 50 | CellularCapabilityTest() |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 51 | : manager_(&control_, &dispatcher_, &metrics_, &glib_), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 52 | create_gsm_card_proxy_from_factory_(false), |
| 53 | proxy_(new MockModemProxy()), |
| 54 | simple_proxy_(new MockModemSimpleProxy()), |
| 55 | cdma_proxy_(new MockModemCDMAProxy()), |
| 56 | gsm_card_proxy_(new MockModemGSMCardProxy()), |
| 57 | gsm_network_proxy_(new MockModemGSMNetworkProxy()), |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 58 | gobi_proxy_(new MockModemGobiProxy()), |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 59 | proxy_factory_(this), |
| 60 | capability_(NULL), |
| 61 | device_adaptor_(NULL), |
| 62 | provider_db_(NULL), |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 63 | cellular_(new Cellular(&control_, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 64 | &dispatcher_, |
| 65 | NULL, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 66 | &manager_, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 67 | "", |
| 68 | "", |
| 69 | 0, |
| 70 | Cellular::kTypeGSM, |
| 71 | "", |
| 72 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 73 | "", |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 74 | NULL, |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 75 | NULL, |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 76 | &proxy_factory_)) {} |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 77 | |
| 78 | virtual ~CellularCapabilityTest() { |
| 79 | cellular_->service_ = NULL; |
| 80 | capability_ = NULL; |
| 81 | device_adaptor_ = NULL; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 82 | mobile_provider_close_db(provider_db_); |
| 83 | provider_db_ = NULL; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | virtual void SetUp() { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 87 | static_cast<Device *>(cellular_)->rtnl_handler_ = &rtnl_handler_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 88 | |
| 89 | capability_ = dynamic_cast<CellularCapabilityClassic *>( |
| 90 | cellular_->capability_.get()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 91 | device_adaptor_ = |
| 92 | dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor()); |
| 93 | } |
| 94 | |
| 95 | virtual void TearDown() { |
| 96 | capability_->proxy_factory_ = NULL; |
| 97 | } |
| 98 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 99 | void InitProviderDB() { |
| 100 | provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath); |
| 101 | ASSERT_TRUE(provider_db_); |
| 102 | cellular_->provider_db_ = provider_db_; |
| 103 | } |
| 104 | |
| 105 | void SetService() { |
| 106 | cellular_->service_ = new CellularService( |
| 107 | &control_, &dispatcher_, &metrics_, NULL, cellular_); |
| 108 | } |
| 109 | |
| 110 | CellularCapabilityGSM *GetGsmCapability() { |
| 111 | return dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get()); |
| 112 | } |
| 113 | |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 114 | void ReleaseCapabilityProxies() { |
| 115 | capability_->ReleaseProxies(); |
| 116 | } |
| 117 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 118 | void InvokeEnable(bool enable, Error *error, |
| 119 | const ResultCallback &callback, int timeout) { |
| 120 | callback.Run(Error()); |
| 121 | } |
| 122 | void InvokeEnableFail(bool enable, Error *error, |
| 123 | const ResultCallback &callback, int timeout) { |
| 124 | callback.Run(Error(Error::kOperationFailed)); |
| 125 | } |
| 126 | void InvokeDisconnect(Error *error, const ResultCallback &callback, |
| 127 | int timeout) { |
| 128 | callback.Run(Error()); |
| 129 | } |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 130 | void InvokeDisconnectFail(Error *error, const ResultCallback &callback, |
| 131 | int timeout) { |
| 132 | callback.Run(Error(Error::kOperationFailed)); |
| 133 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 134 | void InvokeGetModemStatus(Error *error, |
| 135 | const DBusPropertyMapCallback &callback, |
| 136 | int timeout) { |
| 137 | DBusPropertiesMap props; |
| 138 | props["carrier"].writer().append_string(kTestCarrier); |
| 139 | props["unknown-property"].writer().append_string("irrelevant-value"); |
| 140 | callback.Run(props, Error()); |
| 141 | } |
| 142 | void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback, |
| 143 | int timeout) { |
| 144 | ModemHardwareInfo info; |
| 145 | info._1 = kManufacturer; |
| 146 | info._2 = kModelID; |
| 147 | info._3 = kHWRev; |
| 148 | callback.Run(info, Error()); |
| 149 | } |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 150 | void InvokeSetCarrier(const string &carrier, Error *error, |
| 151 | const ResultCallback &callback, int timeout) { |
| 152 | callback.Run(Error()); |
| 153 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 154 | |
| 155 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 156 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 157 | protected: |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 158 | static const char kTestMobileProviderDBPath[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 159 | static const char kTestCarrier[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 160 | static const char kManufacturer[]; |
| 161 | static const char kModelID[]; |
| 162 | static const char kHWRev[]; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 163 | |
| 164 | class TestProxyFactory : public ProxyFactory { |
| 165 | public: |
| 166 | explicit TestProxyFactory(CellularCapabilityTest *test) : test_(test) {} |
| 167 | |
| 168 | virtual ModemProxyInterface *CreateModemProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 169 | const string &/*path*/, |
| 170 | const string &/*service*/) { |
| 171 | return test_->proxy_.release(); |
| 172 | } |
| 173 | |
| 174 | virtual ModemSimpleProxyInterface *CreateModemSimpleProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 175 | const string &/*path*/, |
| 176 | const string &/*service*/) { |
| 177 | return test_->simple_proxy_.release(); |
| 178 | } |
| 179 | |
| 180 | virtual ModemCDMAProxyInterface *CreateModemCDMAProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 181 | const string &/*path*/, |
| 182 | const string &/*service*/) { |
| 183 | return test_->cdma_proxy_.release(); |
| 184 | } |
| 185 | |
| 186 | virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 187 | const string &/*path*/, |
| 188 | const string &/*service*/) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 189 | // TODO(benchan): This code conditionally returns a NULL pointer to avoid |
| 190 | // CellularCapabilityGSM::InitProperties (and thus |
| 191 | // CellularCapabilityGSM::GetIMSI) from being called during the |
| 192 | // construction. Remove this workaround after refactoring the tests. |
| 193 | return test_->create_gsm_card_proxy_from_factory_ ? |
| 194 | test_->gsm_card_proxy_.release() : NULL; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy( |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 198 | const string &/*path*/, |
| 199 | const string &/*service*/) { |
| 200 | return test_->gsm_network_proxy_.release(); |
| 201 | } |
| 202 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 203 | virtual ModemGobiProxyInterface *CreateModemGobiProxy( |
| 204 | const string &/*path*/, |
| 205 | const string &/*service*/) { |
| 206 | return test_->gobi_proxy_.release(); |
| 207 | } |
| 208 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 209 | private: |
| 210 | CellularCapabilityTest *test_; |
| 211 | }; |
| 212 | |
| 213 | void SetProxy() { |
| 214 | capability_->proxy_.reset(proxy_.release()); |
| 215 | } |
| 216 | |
| 217 | void SetSimpleProxy() { |
| 218 | capability_->simple_proxy_.reset(simple_proxy_.release()); |
| 219 | } |
| 220 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 221 | void SetGSMNetworkProxy() { |
| 222 | CellularCapabilityGSM *gsm_capability = |
| 223 | dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get()); |
| 224 | gsm_capability->network_proxy_.reset(gsm_network_proxy_.release()); |
| 225 | } |
| 226 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 227 | void SetCellularType(Cellular::Type type) { |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 228 | cellular_->InitCapability(type); |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 229 | capability_ = dynamic_cast<CellularCapabilityClassic *>( |
| 230 | cellular_->capability_.get()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 231 | } |
| 232 | |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 233 | void AllowCreateGSMCardProxyFromFactory() { |
| 234 | create_gsm_card_proxy_from_factory_ = true; |
| 235 | } |
| 236 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 237 | NiceMockControl control_; |
| 238 | EventDispatcher dispatcher_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 239 | MockMetrics metrics_; |
| 240 | MockGLib glib_; |
| 241 | MockManager manager_; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 242 | MockRTNLHandler rtnl_handler_; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 243 | bool create_gsm_card_proxy_from_factory_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 244 | scoped_ptr<MockModemProxy> proxy_; |
| 245 | scoped_ptr<MockModemSimpleProxy> simple_proxy_; |
| 246 | scoped_ptr<MockModemCDMAProxy> cdma_proxy_; |
| 247 | scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_; |
| 248 | scoped_ptr<MockModemGSMNetworkProxy> gsm_network_proxy_; |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 249 | scoped_ptr<MockModemGobiProxy> gobi_proxy_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 250 | TestProxyFactory proxy_factory_; |
Jason Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 251 | CellularCapabilityClassic *capability_; // Owned by |cellular_|. |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 252 | NiceMock<DeviceMockAdaptor> *device_adaptor_; // Owned by |cellular_|. |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 253 | mobile_provider_db *provider_db_; |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 254 | CellularRefPtr cellular_; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 255 | }; |
| 256 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 257 | const char CellularCapabilityTest::kTestMobileProviderDBPath[] = |
| 258 | "provider_db_unittest.bfd"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 259 | const char CellularCapabilityTest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 260 | const char CellularCapabilityTest::kManufacturer[] = "Company"; |
| 261 | const char CellularCapabilityTest::kModelID[] = "Gobi 2000"; |
| 262 | const char CellularCapabilityTest::kHWRev[] = "A00B1234"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 263 | |
| 264 | TEST_F(CellularCapabilityTest, GetModemStatus) { |
| 265 | SetCellularType(Cellular::kTypeCDMA); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 266 | EXPECT_CALL(*simple_proxy_, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 267 | GetModemStatus(_, _, CellularCapability::kTimeoutDefault)). |
| 268 | WillOnce(Invoke(this, &CellularCapabilityTest::InvokeGetModemStatus)); |
| 269 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 270 | SetSimpleProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 271 | ResultCallback callback = |
| 272 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
| 273 | capability_->GetModemStatus(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 274 | EXPECT_EQ(kTestCarrier, capability_->carrier_); |
| 275 | EXPECT_EQ(kTestCarrier, cellular_->home_provider_.GetName()); |
| 276 | } |
| 277 | |
| 278 | TEST_F(CellularCapabilityTest, GetModemInfo) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 279 | EXPECT_CALL(*proxy_, GetModemInfo(_, _, CellularCapability::kTimeoutDefault)) |
| 280 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeGetModemInfo)); |
| 281 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 282 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 283 | ResultCallback callback = |
| 284 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
| 285 | capability_->GetModemInfo(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 286 | EXPECT_EQ(kManufacturer, capability_->manufacturer_); |
| 287 | EXPECT_EQ(kModelID, capability_->model_id_); |
| 288 | EXPECT_EQ(kHWRev, capability_->hardware_revision_); |
| 289 | } |
| 290 | |
| 291 | TEST_F(CellularCapabilityTest, EnableModemSucceed) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 292 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 293 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeEnable)); |
| 294 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 295 | ResultCallback callback = |
| 296 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 297 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 298 | capability_->EnableModem(callback); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | TEST_F(CellularCapabilityTest, EnableModemFail) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 302 | EXPECT_CALL(*proxy_, Enable(true, _, _, CellularCapability::kTimeoutEnable)) |
| 303 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeEnableFail)); |
| 304 | EXPECT_CALL(*this, TestCallback(IsFailure())); |
| 305 | ResultCallback callback = |
| 306 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 307 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 308 | capability_->EnableModem(callback); |
| 309 | } |
| 310 | |
| 311 | TEST_F(CellularCapabilityTest, FinishEnable) { |
| 312 | EXPECT_CALL(*gsm_network_proxy_, |
| 313 | GetRegistrationInfo(NULL, _, |
| 314 | CellularCapability::kTimeoutDefault)); |
| 315 | EXPECT_CALL(*gsm_network_proxy_, |
| 316 | GetSignalQuality(NULL, _, CellularCapability::kTimeoutDefault)); |
| 317 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 318 | SetGSMNetworkProxy(); |
| 319 | capability_->FinishEnable( |
| 320 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 321 | } |
| 322 | |
| 323 | TEST_F(CellularCapabilityTest, UnsupportedOperation) { |
| 324 | Error error; |
| 325 | EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(0); |
| 326 | capability_->CellularCapability::Scan(&error, |
| 327 | Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 328 | EXPECT_TRUE(error.IsFailure()); |
| 329 | EXPECT_EQ(Error::kNotSupported, error.type()); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 330 | } |
| 331 | |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 332 | TEST_F(CellularCapabilityTest, AllowRoaming) { |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 333 | EXPECT_FALSE(cellular_->GetAllowRoaming(NULL)); |
| 334 | cellular_->SetAllowRoaming(false, NULL); |
| 335 | EXPECT_FALSE(cellular_->GetAllowRoaming(NULL)); |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 336 | |
| 337 | { |
| 338 | InSequence seq; |
| 339 | EXPECT_CALL(*device_adaptor_, EmitBoolChanged( |
| 340 | flimflam::kCellularAllowRoamingProperty, true)); |
| 341 | EXPECT_CALL(*device_adaptor_, EmitBoolChanged( |
| 342 | flimflam::kCellularAllowRoamingProperty, false)); |
| 343 | } |
| 344 | |
| 345 | cellular_->state_ = Cellular::kStateConnected; |
| 346 | dynamic_cast<CellularCapabilityGSM *>(capability_)->registration_state_ = |
| 347 | MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING; |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 348 | cellular_->SetAllowRoaming(true, NULL); |
| 349 | EXPECT_TRUE(cellular_->GetAllowRoaming(NULL)); |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 350 | EXPECT_EQ(Cellular::kStateConnected, cellular_->state_); |
| 351 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 352 | EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 353 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeDisconnect)); |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 354 | SetProxy(); |
| 355 | cellular_->state_ = Cellular::kStateConnected; |
Jason Glasgow | 7b461df | 2012-05-01 16:38:45 -0400 | [diff] [blame] | 356 | cellular_->SetAllowRoaming(false, NULL); |
| 357 | EXPECT_FALSE(cellular_->GetAllowRoaming(NULL)); |
Darin Petkov | 9c1dcef | 2012-02-07 15:58:26 +0100 | [diff] [blame] | 358 | EXPECT_EQ(Cellular::kStateRegistered, cellular_->state_); |
| 359 | } |
| 360 | |
Darin Petkov | c37a9c4 | 2012-09-06 15:28:22 +0200 | [diff] [blame] | 361 | TEST_F(CellularCapabilityTest, SetCarrier) { |
| 362 | static const char kCarrier[] = "Generic UMTS"; |
| 363 | EXPECT_CALL( |
| 364 | *gobi_proxy_, |
| 365 | SetCarrier(kCarrier, _, _, |
| 366 | CellularCapabilityClassic::kTimeoutSetCarrierMilliseconds)) |
| 367 | .WillOnce(Invoke(this, &CellularCapabilityTest::InvokeSetCarrier)); |
| 368 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 369 | Error error; |
| 370 | capability_->SetCarrier(kCarrier, &error, |
| 371 | Bind(&CellularCapabilityTest::TestCallback, |
| 372 | Unretained(this))); |
| 373 | EXPECT_TRUE(error.IsSuccess()); |
| 374 | } |
| 375 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 376 | MATCHER_P(HasApn, apn, "") { |
| 377 | DBusPropertiesMap::const_iterator it = arg.find(flimflam::kApnProperty); |
| 378 | return it != arg.end() && apn == it->second.reader().get_string(); |
| 379 | } |
| 380 | |
| 381 | MATCHER(HasNoApn, "") { |
| 382 | return arg.find(flimflam::kApnProperty) == arg.end(); |
| 383 | } |
| 384 | |
| 385 | TEST_F(CellularCapabilityTest, TryApns) { |
| 386 | static const string kLastGoodApn("remembered.apn"); |
| 387 | static const string kSuppliedApn("my.apn"); |
| 388 | static const string kTmobileApn1("epc.tmobile.com"); |
| 389 | static const string kTmobileApn2("wap.voicestream.com"); |
| 390 | static const string kTmobileApn3("internet2.voicestream.com"); |
| 391 | static const string kTmobileApn4("internet3.voicestream.com"); |
| 392 | |
| 393 | using testing::InSequence; |
| 394 | { |
| 395 | InSequence dummy; |
| 396 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kLastGoodApn), _, _, _)); |
| 397 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kSuppliedApn), _, _, _)); |
| 398 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn1), _, _, _)); |
| 399 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn2), _, _, _)); |
| 400 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn3), _, _, _)); |
| 401 | EXPECT_CALL(*simple_proxy_, Connect(HasApn(kTmobileApn4), _, _, _)); |
| 402 | EXPECT_CALL(*simple_proxy_, Connect(HasNoApn(), _, _, _)); |
| 403 | } |
| 404 | CellularCapabilityGSM *gsm_capability = GetGsmCapability(); |
| 405 | SetService(); |
| 406 | gsm_capability->imsi_ = "310240123456789"; |
| 407 | InitProviderDB(); |
| 408 | gsm_capability->SetHomeProvider(); |
| 409 | ProfileRefPtr profile(new NiceMock<MockProfile>( |
| 410 | &control_, reinterpret_cast<Manager *>(NULL))); |
| 411 | cellular_->service()->set_profile(profile); |
| 412 | |
| 413 | Error error; |
| 414 | Stringmap apn_info; |
| 415 | DBusPropertiesMap props; |
| 416 | apn_info[flimflam::kApnProperty] = kSuppliedApn; |
| 417 | cellular_->service()->SetApn(apn_info, &error); |
| 418 | |
| 419 | apn_info.clear(); |
| 420 | apn_info[flimflam::kApnProperty] = kLastGoodApn; |
| 421 | cellular_->service()->SetLastGoodApn(apn_info); |
| 422 | |
| 423 | capability_->SetupConnectProperties(&props); |
| 424 | // We expect the list to contain the last good APN, plus |
| 425 | // the user-supplied APN, plus the 4 APNs from the mobile |
| 426 | // provider info database. |
| 427 | EXPECT_EQ(6, gsm_capability->apn_try_list_.size()); |
| 428 | EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end()); |
| 429 | EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string()); |
| 430 | |
| 431 | SetSimpleProxy(); |
| 432 | capability_->Connect(props, &error, ResultCallback()); |
| 433 | Error cerror(Error::kInvalidApn); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 434 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 435 | EXPECT_EQ(5, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 436 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 437 | EXPECT_EQ(4, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 438 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 439 | EXPECT_EQ(3, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 440 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 441 | EXPECT_EQ(2, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 442 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 443 | EXPECT_EQ(1, gsm_capability->apn_try_list_.size()); |
Nathan Williams | b54974f | 2012-04-19 11:16:30 -0400 | [diff] [blame] | 444 | gsm_capability->OnConnectReply(ResultCallback(), cerror); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 445 | EXPECT_EQ(0, gsm_capability->apn_try_list_.size()); |
| 446 | } |
| 447 | |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 448 | TEST_F(CellularCapabilityTest, StopModemDisconnectSuccess) { |
| 449 | EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 450 | .WillOnce(Invoke(this, |
| 451 | &CellularCapabilityTest::InvokeDisconnect)); |
Thieu Le | c8d2d96 | 2012-05-15 14:31:18 -0700 | [diff] [blame] | 452 | EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable)) |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 453 | .WillOnce(Invoke(this, |
| 454 | &CellularCapabilityTest::InvokeEnable)); |
| 455 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 456 | SetProxy(); |
| 457 | |
| 458 | Error error; |
| 459 | capability_->StopModem( |
| 460 | &error, Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 461 | dispatcher_.DispatchPendingEvents(); |
| 462 | } |
| 463 | |
| 464 | TEST_F(CellularCapabilityTest, StopModemDisconnectFail) { |
| 465 | EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 466 | .WillOnce(Invoke(this, |
| 467 | &CellularCapabilityTest::InvokeDisconnectFail)); |
Thieu Le | c8d2d96 | 2012-05-15 14:31:18 -0700 | [diff] [blame] | 468 | EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable)) |
Thieu Le | 923006b | 2012-04-05 16:32:58 -0700 | [diff] [blame] | 469 | .WillOnce(Invoke(this, |
| 470 | &CellularCapabilityTest::InvokeEnable)); |
| 471 | EXPECT_CALL(*this, TestCallback(IsSuccess())); |
| 472 | SetProxy(); |
| 473 | |
| 474 | Error error; |
| 475 | capability_->StopModem( |
| 476 | &error, Bind(&CellularCapabilityTest::TestCallback, Unretained(this))); |
| 477 | dispatcher_.DispatchPendingEvents(); |
| 478 | } |
| 479 | |
Thieu Le | 3d27539 | 2012-07-20 15:32:58 -0700 | [diff] [blame] | 480 | TEST_F(CellularCapabilityTest, DisconnectNoProxy) { |
| 481 | Error error; |
| 482 | ResultCallback disconnect_callback; |
| 483 | EXPECT_CALL(*proxy_, Disconnect(_, _, CellularCapability::kTimeoutDefault)) |
| 484 | .Times(0); |
| 485 | ReleaseCapabilityProxies(); |
| 486 | capability_->Disconnect(&error, disconnect_callback); |
| 487 | } |
| 488 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 489 | } // namespace shill |