blob: 9cf7fe92ff685f332698637b1f5859120bfd744a [file] [log] [blame]
Darin Petkovc64fe5e2012-01-11 12:46:13 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkovb05315f2011-11-07 10:14:25 +01002// 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
Jason Glasgow4c0724a2012-04-17 15:47:40 -04007#include <string>
8#include <vector>
9
Eric Shienbrood9a245532012-03-07 14:20:39 -050010#include <base/bind.h>
Ben Chana0ddf462014-02-06 11:32:42 -080011#include <base/strings/stringprintf.h>
Darin Petkov20c13ec2011-11-09 15:07:15 +010012#include <chromeos/dbus/service_constants.h>
Darin Petkov20c13ec2011-11-09 15:07:15 +010013#include <mm/mm-modem.h>
Darin Petkovb05315f2011-11-07 10:14:25 +010014
15#include "shill/cellular.h"
Darin Petkov3e509242011-11-10 14:46:44 +010016#include "shill/cellular_service.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010017#include "shill/error.h"
18#include "shill/event_dispatcher.h"
Darin Petkov3cfbf212011-11-21 16:02:09 +010019#include "shill/mock_adaptors.h"
Gary Morain82a31a02012-08-02 18:03:32 -070020#include "shill/mock_log.h"
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070021#include "shill/mock_mobile_operator_info.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010022#include "shill/mock_modem_gsm_card_proxy.h"
Darin Petkov3e509242011-11-10 14:46:44 +010023#include "shill/mock_modem_gsm_network_proxy.h"
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070024#include "shill/mock_modem_info.h"
Thieu Le923006b2012-04-05 16:32:58 -070025#include "shill/mock_modem_proxy.h"
26#include "shill/mock_modem_simple_proxy.h"
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040027#include "shill/mock_profile.h"
Thieu Le923006b2012-04-05 16:32:58 -070028#include "shill/proxy_factory.h"
Ben Chanbe277dd2014-02-05 17:26:47 -080029#include "shill/testing.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010030
Eric Shienbrood9a245532012-03-07 14:20:39 -050031using base::Bind;
Darin Petkova4ca3c32012-08-17 16:05:24 +020032using base::StringPrintf;
Eric Shienbrood9a245532012-03-07 14:20:39 -050033using base::Unretained;
Darin Petkov31332412012-01-28 01:50:02 +010034using std::string;
Jason Glasgow4c0724a2012-04-17 15:47:40 -040035using std::vector;
Darin Petkove5bc2cb2011-12-07 14:47:32 +010036using testing::_;
Eric Shienbrood9a245532012-03-07 14:20:39 -050037using testing::Invoke;
Darin Petkov3cfbf212011-11-21 16:02:09 +010038using testing::NiceMock;
Darin Petkovcb547732011-11-09 13:55:26 +010039using testing::Return;
Jason Glasgowcd0349c2012-05-03 23:32:15 -040040using testing::SaveArg;
Darin Petkovcb547732011-11-09 13:55:26 +010041
Darin Petkovb05315f2011-11-07 10:14:25 +010042namespace shill {
43
44class CellularCapabilityGSMTest : public testing::Test {
45 public:
46 CellularCapabilityGSMTest()
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070047 : modem_info_(NULL, &dispatcher_, NULL, NULL, NULL),
Thieu Le6c1e3bb2013-02-06 15:20:35 -080048 create_card_proxy_from_factory_(false),
Ben Chan3ecdf822012-08-06 12:29:23 -070049 proxy_(new MockModemProxy()),
50 simple_proxy_(new MockModemSimpleProxy()),
51 card_proxy_(new MockModemGSMCardProxy()),
52 network_proxy_(new MockModemGSMNetworkProxy()),
53 proxy_factory_(this),
54 capability_(NULL),
55 device_adaptor_(NULL),
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070056 cellular_(new Cellular(&modem_info_,
Darin Petkovb05315f2011-11-07 10:14:25 +010057 "",
Darin Petkov31332412012-01-28 01:50:02 +010058 kAddress,
Darin Petkovb05315f2011-11-07 10:14:25 +010059 0,
60 Cellular::kTypeGSM,
61 "",
62 "",
Jason Glasgowa585fc32012-06-06 11:04:09 -040063 "",
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -070064 &proxy_factory_)),
65 mock_home_provider_info_(NULL),
66 mock_serving_operator_info_(NULL) {
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070067 modem_info_.metrics()->RegisterDevice(cellular_->interface_index(),
68 Technology::kCellular);
Thieu Lece4483e2013-01-23 15:12:03 -080069 }
Darin Petkovb05315f2011-11-07 10:14:25 +010070
Darin Petkov3e509242011-11-10 14:46:44 +010071 virtual ~CellularCapabilityGSMTest() {
72 cellular_->service_ = NULL;
Darin Petkov721ac932011-11-16 15:43:09 +010073 capability_ = NULL;
Darin Petkov3cfbf212011-11-21 16:02:09 +010074 device_adaptor_ = NULL;
Darin Petkov721ac932011-11-16 15:43:09 +010075 }
76
77 virtual void SetUp() {
78 capability_ =
79 dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get());
Darin Petkov3cfbf212011-11-21 16:02:09 +010080 device_adaptor_ =
Prathmesh Prabhu27526f12013-03-25 19:42:18 -070081 dynamic_cast<DeviceMockAdaptor *>(cellular_->adaptor());
82 }
83
Thieu Le923006b2012-04-05 16:32:58 -070084 void InvokeEnable(bool enable, Error *error,
85 const ResultCallback &callback, int timeout) {
86 callback.Run(Error());
87 }
Eric Shienbrood9a245532012-03-07 14:20:39 -050088 void InvokeGetIMEI(Error *error, const GSMIdentifierCallback &callback,
89 int timeout) {
90 callback.Run(kIMEI, Error());
91 }
92 void InvokeGetIMSI(Error *error, const GSMIdentifierCallback &callback,
93 int timeout) {
94 callback.Run(kIMSI, Error());
95 }
Gary Morain82a31a02012-08-02 18:03:32 -070096 void InvokeGetIMSIFails(Error *error, const GSMIdentifierCallback &callback,
97 int timeout) {
98 callback.Run("", Error(Error::kOperationFailed));
99 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500100 void InvokeGetMSISDN(Error *error, const GSMIdentifierCallback &callback,
101 int timeout) {
102 callback.Run(kMSISDN, Error());
103 }
Thieu Le923006b2012-04-05 16:32:58 -0700104 void InvokeGetMSISDNFail(Error *error, const GSMIdentifierCallback &callback,
105 int timeout) {
106 callback.Run("", Error(Error::kOperationFailed));
107 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500108 void InvokeGetSPN(Error *error, const GSMIdentifierCallback &callback,
109 int timeout) {
110 callback.Run(kTestCarrier, Error());
111 }
Thieu Le923006b2012-04-05 16:32:58 -0700112 void InvokeGetSPNFail(Error *error, const GSMIdentifierCallback &callback,
113 int timeout) {
114 callback.Run("", Error(Error::kOperationFailed));
115 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500116 void InvokeGetSignalQuality(Error *error,
117 const SignalQualityCallback &callback,
118 int timeout) {
119 callback.Run(kStrength, Error());
120 }
121 void InvokeGetRegistrationInfo(Error *error,
122 const RegistrationInfoCallback &callback,
123 int timeout) {
124 callback.Run(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME,
125 kTestNetwork, kTestCarrier, Error());
126 }
127 void InvokeRegister(const string &network_id,
128 Error *error,
129 const ResultCallback &callback,
130 int timeout) {
131 callback.Run(Error());
132 }
133 void InvokeEnablePIN(const string &pin, bool enable,
134 Error *error, const ResultCallback &callback,
135 int timeout) {
136 callback.Run(Error());
137 }
138 void InvokeSendPIN(const string &pin, Error *error,
139 const ResultCallback &callback, int timeout) {
140 callback.Run(Error());
141 }
142 void InvokeSendPUK(const string &puk, const string &pin, Error *error,
143 const ResultCallback &callback, int timeout) {
144 callback.Run(Error());
145 }
146 void InvokeChangePIN(const string &old_pin, const string &pin, Error *error,
147 const ResultCallback &callback, int timeout) {
148 callback.Run(Error());
149 }
Thieu Le923006b2012-04-05 16:32:58 -0700150 void InvokeGetModemStatus(Error *error,
151 const DBusPropertyMapCallback &callback,
152 int timeout) {
153 DBusPropertiesMap props;
154 callback.Run(props, Error());
155 }
156 void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback,
157 int timeout) {
158 ModemHardwareInfo info;
159 callback.Run(info, Error());
160 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500161
Thieu Leb5954a22012-05-18 10:37:34 -0700162 void InvokeConnectFail(DBusPropertiesMap props, Error *error,
163 const ResultCallback &callback, int timeout) {
164 callback.Run(Error(Error::kOperationFailed));
165 }
166
Eric Shienbrood9a245532012-03-07 14:20:39 -0500167 MOCK_METHOD1(TestCallback, void(const Error &error));
168
Darin Petkovb05315f2011-11-07 10:14:25 +0100169 protected:
Darin Petkov31332412012-01-28 01:50:02 +0100170 static const char kAddress[];
Darin Petkov1272a432011-11-10 15:53:37 +0100171 static const char kTestMobileProviderDBPath[];
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500172 static const char kTestNetwork[];
Darin Petkovcb547732011-11-09 13:55:26 +0100173 static const char kTestCarrier[];
Darin Petkovb05315f2011-11-07 10:14:25 +0100174 static const char kPIN[];
175 static const char kPUK[];
Darin Petkovcb547732011-11-09 13:55:26 +0100176 static const char kIMEI[];
177 static const char kIMSI[];
178 static const char kMSISDN[];
Eric Shienbrood9a245532012-03-07 14:20:39 -0500179 static const int kStrength;
Darin Petkovcb547732011-11-09 13:55:26 +0100180
Thieu Le923006b2012-04-05 16:32:58 -0700181 class TestProxyFactory : public ProxyFactory {
182 public:
183 explicit TestProxyFactory(CellularCapabilityGSMTest *test) : test_(test) {}
184
185 virtual ModemProxyInterface *CreateModemProxy(
186 const string &/*path*/,
187 const string &/*service*/) {
188 return test_->proxy_.release();
189 }
190
191 virtual ModemSimpleProxyInterface *CreateModemSimpleProxy(
192 const string &/*path*/,
193 const string &/*service*/) {
194 return test_->simple_proxy_.release();
195 }
196
197 virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy(
198 const string &/*path*/,
199 const string &/*service*/) {
Ben Chan3ecdf822012-08-06 12:29:23 -0700200 // TODO(benchan): This code conditionally returns a NULL pointer to avoid
201 // CellularCapabilityGSM::InitProperties (and thus
202 // CellularCapabilityGSM::GetIMSI) from being called during the
203 // construction. Remove this workaround after refactoring the tests.
204 return test_->create_card_proxy_from_factory_ ?
205 test_->card_proxy_.release() : NULL;
Thieu Le923006b2012-04-05 16:32:58 -0700206 }
207
208 virtual ModemGSMNetworkProxyInterface *CreateModemGSMNetworkProxy(
209 const string &/*path*/,
210 const string &/*service*/) {
211 return test_->network_proxy_.release();
212 }
213
214 private:
215 CellularCapabilityGSMTest *test_;
216 };
217
218 void SetProxy() {
219 capability_->proxy_.reset(proxy_.release());
220 }
221
Darin Petkovcb547732011-11-09 13:55:26 +0100222 void SetCardProxy() {
Darin Petkov721ac932011-11-16 15:43:09 +0100223 capability_->card_proxy_.reset(card_proxy_.release());
Darin Petkovcb547732011-11-09 13:55:26 +0100224 }
Darin Petkovb05315f2011-11-07 10:14:25 +0100225
Darin Petkov1272a432011-11-10 15:53:37 +0100226 void SetNetworkProxy() {
Darin Petkov721ac932011-11-16 15:43:09 +0100227 capability_->network_proxy_.reset(network_proxy_.release());
Darin Petkov1272a432011-11-10 15:53:37 +0100228 }
229
Ben Chan7fab8972014-08-10 17:14:46 -0700230 void SetAccessTechnology(uint32_t technology) {
Darin Petkov721ac932011-11-16 15:43:09 +0100231 capability_->access_technology_ = technology;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100232 }
233
Ben Chan7fab8972014-08-10 17:14:46 -0700234 void SetRegistrationState(uint32_t state) {
Darin Petkov721ac932011-11-16 15:43:09 +0100235 capability_->registration_state_ = state;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100236 }
237
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700238 void CreateService() {
239 // The following constants are never directly accessed by the tests.
240 const char kStorageIdentifier[] = "default_test_storage_id";
241 const char kFriendlyServiceName[] = "default_test_service_name";
242 const char kOperatorCode[] = "10010";
243 const char kOperatorName[] = "default_test_operator_name";
244 const char kOperatorCountry[] = "us";
245
246 // Simulate all the side-effects of Cellular::CreateService
247 auto service = new CellularService(&modem_info_, cellular_);
248 service->SetStorageIdentifier(kStorageIdentifier);
249 service->SetFriendlyName(kFriendlyServiceName);
250
251 Cellular::Operator oper;
252 oper.SetCode(kOperatorCode);
253 oper.SetName(kOperatorName);
254 oper.SetCountry(kOperatorCountry);
255
256 service->SetServingOperator(oper);
257
258 cellular_->set_home_provider(oper);
259 cellular_->service_ = service;
260 }
261
262 void SetMockMobileOperatorInfoObjects() {
263 CHECK(!mock_home_provider_info_);
264 CHECK(!mock_serving_operator_info_);
Miao-chen Chou70190b32014-05-14 18:24:30 -0700265 mock_home_provider_info_ =
266 new MockMobileOperatorInfo(&dispatcher_, "HomeProvider");
267 mock_serving_operator_info_ =
268 new MockMobileOperatorInfo(&dispatcher_, "ServingOperator");
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700269 cellular_->set_home_provider_info(mock_home_provider_info_);
270 cellular_->set_serving_operator_info(mock_serving_operator_info_);
Darin Petkov1272a432011-11-10 15:53:37 +0100271 }
272
Thieu Leb5954a22012-05-18 10:37:34 -0700273 void SetupCommonProxiesExpectations() {
Thieu Le923006b2012-04-05 16:32:58 -0700274 EXPECT_CALL(*proxy_, set_state_changed_callback(_));
275 EXPECT_CALL(*network_proxy_, set_signal_quality_callback(_));
276 EXPECT_CALL(*network_proxy_, set_network_mode_callback(_));
277 EXPECT_CALL(*network_proxy_, set_registration_info_callback(_));
Thieu Leb5954a22012-05-18 10:37:34 -0700278 }
279
280 void SetupCommonStartModemExpectations() {
281 SetupCommonProxiesExpectations();
Thieu Le923006b2012-04-05 16:32:58 -0700282
283 EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable))
284 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnable));
Thieu Le923006b2012-04-05 16:32:58 -0700285 EXPECT_CALL(*card_proxy_,
286 GetIMEI(_, _, CellularCapability::kTimeoutDefault))
287 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMEI));
288 EXPECT_CALL(*card_proxy_,
289 GetIMSI(_, _, CellularCapability::kTimeoutDefault))
290 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMSI));
291 EXPECT_CALL(*network_proxy_, AccessTechnology());
292 EXPECT_CALL(*card_proxy_, EnabledFacilityLocks());
293 EXPECT_CALL(*proxy_,
294 GetModemInfo(_, _, CellularCapability::kTimeoutDefault))
295 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetModemInfo));
296 EXPECT_CALL(*network_proxy_,
297 GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault));
298 EXPECT_CALL(*network_proxy_,
299 GetSignalQuality(_, _, CellularCapability::kTimeoutDefault));
300 EXPECT_CALL(*this, TestCallback(IsSuccess()));
301 }
302
Thieu Leb5954a22012-05-18 10:37:34 -0700303 void InitProxies() {
Ben Chan3ecdf822012-08-06 12:29:23 -0700304 AllowCreateCardProxyFromFactory();
Thieu Leb5954a22012-05-18 10:37:34 -0700305 capability_->InitProxies();
306 }
307
Ben Chan3ecdf822012-08-06 12:29:23 -0700308 void AllowCreateCardProxyFromFactory() {
309 create_card_proxy_from_factory_ = true;
310 }
311
Darin Petkovb05315f2011-11-07 10:14:25 +0100312 EventDispatcher dispatcher_;
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700313 MockModemInfo modem_info_;
Ben Chan3ecdf822012-08-06 12:29:23 -0700314 bool create_card_proxy_from_factory_;
Thieu Le923006b2012-04-05 16:32:58 -0700315 scoped_ptr<MockModemProxy> proxy_;
316 scoped_ptr<MockModemSimpleProxy> simple_proxy_;
Darin Petkovcb547732011-11-09 13:55:26 +0100317 scoped_ptr<MockModemGSMCardProxy> card_proxy_;
Darin Petkov3e509242011-11-10 14:46:44 +0100318 scoped_ptr<MockModemGSMNetworkProxy> network_proxy_;
Thieu Le923006b2012-04-05 16:32:58 -0700319 TestProxyFactory proxy_factory_;
Darin Petkov721ac932011-11-16 15:43:09 +0100320 CellularCapabilityGSM *capability_; // Owned by |cellular_|.
Prathmesh Prabhu27526f12013-03-25 19:42:18 -0700321 DeviceMockAdaptor *device_adaptor_; // Owned by |cellular_|.
Ben Chan3ecdf822012-08-06 12:29:23 -0700322 CellularRefPtr cellular_;
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700323
324 // Set when required and passed to |cellular_|. Owned by |cellular_|.
325 MockMobileOperatorInfo *mock_home_provider_info_;
326 MockMobileOperatorInfo *mock_serving_operator_info_;
Darin Petkovb05315f2011-11-07 10:14:25 +0100327};
328
Darin Petkov31332412012-01-28 01:50:02 +0100329const char CellularCapabilityGSMTest::kAddress[] = "1122334455";
Darin Petkov1272a432011-11-10 15:53:37 +0100330const char CellularCapabilityGSMTest::kTestMobileProviderDBPath[] =
331 "provider_db_unittest.bfd";
Darin Petkovcb547732011-11-09 13:55:26 +0100332const char CellularCapabilityGSMTest::kTestCarrier[] = "The Cellular Carrier";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500333const char CellularCapabilityGSMTest::kTestNetwork[] = "310555";
Darin Petkovb05315f2011-11-07 10:14:25 +0100334const char CellularCapabilityGSMTest::kPIN[] = "9876";
335const char CellularCapabilityGSMTest::kPUK[] = "8765";
Darin Petkovcb547732011-11-09 13:55:26 +0100336const char CellularCapabilityGSMTest::kIMEI[] = "987654321098765";
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100337const char CellularCapabilityGSMTest::kIMSI[] = "310150123456789";
Darin Petkovcb547732011-11-09 13:55:26 +0100338const char CellularCapabilityGSMTest::kMSISDN[] = "12345678901";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500339const int CellularCapabilityGSMTest::kStrength = 80;
Darin Petkovcb547732011-11-09 13:55:26 +0100340
Darin Petkov721ac932011-11-16 15:43:09 +0100341TEST_F(CellularCapabilityGSMTest, PropertyStore) {
Ben Chan7ea768e2013-09-20 15:08:40 -0700342 EXPECT_TRUE(cellular_->store().Contains(kSIMLockStatusProperty));
Darin Petkov721ac932011-11-16 15:43:09 +0100343}
344
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500345TEST_F(CellularCapabilityGSMTest, GetIMEI) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500346 EXPECT_CALL(*card_proxy_, GetIMEI(_, _, CellularCapability::kTimeoutDefault))
347 .WillOnce(Invoke(this,
348 &CellularCapabilityGSMTest::InvokeGetIMEI));
349 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100350 SetCardProxy();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800351 ASSERT_TRUE(cellular_->imei().empty());
Eric Shienbrood9a245532012-03-07 14:20:39 -0500352 capability_->GetIMEI(Bind(&CellularCapabilityGSMTest::TestCallback,
353 Unretained(this)));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800354 EXPECT_EQ(kIMEI, cellular_->imei());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500355}
356
357TEST_F(CellularCapabilityGSMTest, GetIMSI) {
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700358 SetMockMobileOperatorInfoObjects();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500359 EXPECT_CALL(*card_proxy_, GetIMSI(_, _, CellularCapability::kTimeoutDefault))
360 .WillOnce(Invoke(this,
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700361 &CellularCapabilityGSMTest::InvokeGetIMSI));
362 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500363 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500364 ResultCallback callback = Bind(&CellularCapabilityGSMTest::TestCallback,
365 Unretained(this));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800366 EXPECT_TRUE(cellular_->imsi().empty());
367 EXPECT_FALSE(cellular_->sim_present());
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700368 EXPECT_CALL(*mock_home_provider_info_, UpdateIMSI(kIMSI));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500369 capability_->GetIMSI(callback);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800370 EXPECT_EQ(kIMSI, cellular_->imsi());
371 EXPECT_TRUE(cellular_->sim_present());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500372}
373
Gary Morain82a31a02012-08-02 18:03:32 -0700374// In this test, the call to the proxy's GetIMSI() will always indicate failure,
375// which will cause the retry logic to call the proxy again a number of times.
376// Eventually, the retries expire.
377TEST_F(CellularCapabilityGSMTest, GetIMSIFails) {
378 ScopedMockLog log;
Liam McLoughlinef342b42013-09-13 21:05:36 +0100379 EXPECT_CALL(log, Log(logging::LOG_INFO,
380 ::testing::EndsWith("cellular_capability_gsm.cc"),
Gary Morain82a31a02012-08-02 18:03:32 -0700381 ::testing::StartsWith("GetIMSI failed - ")));
382 EXPECT_CALL(*card_proxy_, GetIMSI(_, _, CellularCapability::kTimeoutDefault))
Arman Uguray29505ec2013-09-12 20:37:53 -0700383 .Times(CellularCapabilityGSM::kGetIMSIRetryLimit + 2)
Gary Morain82a31a02012-08-02 18:03:32 -0700384 .WillRepeatedly(Invoke(this,
385 &CellularCapabilityGSMTest::InvokeGetIMSIFails));
Arman Uguray29505ec2013-09-12 20:37:53 -0700386 EXPECT_CALL(*this, TestCallback(IsFailure())).Times(2);
Gary Morain82a31a02012-08-02 18:03:32 -0700387 SetCardProxy();
388 ResultCallback callback = Bind(&CellularCapabilityGSMTest::TestCallback,
389 Unretained(this));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800390 EXPECT_TRUE(cellular_->imsi().empty());
391 EXPECT_FALSE(cellular_->sim_present());
Gary Morain82a31a02012-08-02 18:03:32 -0700392
Arman Uguray29505ec2013-09-12 20:37:53 -0700393 capability_->sim_lock_status_.lock_type = "sim-pin";
394 capability_->GetIMSI(callback);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800395 EXPECT_TRUE(cellular_->imsi().empty());
396 EXPECT_TRUE(cellular_->sim_present());
Arman Uguray29505ec2013-09-12 20:37:53 -0700397
398 capability_->sim_lock_status_.lock_type.clear();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800399 cellular_->set_sim_present(false);
Gary Morain82a31a02012-08-02 18:03:32 -0700400 capability_->get_imsi_retries_ = 0;
401 EXPECT_EQ(CellularCapabilityGSM::kGetIMSIRetryDelayMilliseconds,
402 capability_->get_imsi_retry_delay_milliseconds_);
403
404 // Set the delay to zero to speed up the test.
405 capability_->get_imsi_retry_delay_milliseconds_ = 0;
406 capability_->GetIMSI(callback);
407 for (int i = 0; i < CellularCapabilityGSM::kGetIMSIRetryLimit; ++i) {
408 dispatcher_.DispatchPendingEvents();
409 }
410 EXPECT_EQ(CellularCapabilityGSM::kGetIMSIRetryLimit + 1,
411 capability_->get_imsi_retries_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800412 EXPECT_TRUE(cellular_->imsi().empty());
413 EXPECT_FALSE(cellular_->sim_present());
Gary Morain82a31a02012-08-02 18:03:32 -0700414}
415
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500416TEST_F(CellularCapabilityGSMTest, GetMSISDN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500417 EXPECT_CALL(*card_proxy_, GetMSISDN(_, _,
418 CellularCapability::kTimeoutDefault))
419 .WillOnce(Invoke(this,
420 &CellularCapabilityGSMTest::InvokeGetMSISDN));
421 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500422 SetCardProxy();
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800423 ASSERT_TRUE(cellular_->mdn().empty());
Eric Shienbrood9a245532012-03-07 14:20:39 -0500424 capability_->GetMSISDN(Bind(&CellularCapabilityGSMTest::TestCallback,
425 Unretained(this)));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800426 EXPECT_EQ(kMSISDN, cellular_->mdn());
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500427}
428
429TEST_F(CellularCapabilityGSMTest, GetSPN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500430 EXPECT_CALL(*card_proxy_, GetSPN(_, _, CellularCapability::kTimeoutDefault))
431 .WillOnce(Invoke(this,
432 &CellularCapabilityGSMTest::InvokeGetSPN));
433 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500434 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500435 ASSERT_TRUE(capability_->spn_.empty());
436 capability_->GetSPN(Bind(&CellularCapabilityGSMTest::TestCallback,
437 Unretained(this)));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500438 EXPECT_EQ(kTestCarrier, capability_->spn_);
Darin Petkovcb547732011-11-09 13:55:26 +0100439}
Darin Petkovb05315f2011-11-07 10:14:25 +0100440
Darin Petkov3e509242011-11-10 14:46:44 +0100441TEST_F(CellularCapabilityGSMTest, GetSignalQuality) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500442 EXPECT_CALL(*network_proxy_,
443 GetSignalQuality(_, _, CellularCapability::kTimeoutDefault))
444 .WillOnce(Invoke(this,
445 &CellularCapabilityGSMTest::InvokeGetSignalQuality));
Darin Petkov3e509242011-11-10 14:46:44 +0100446 SetNetworkProxy();
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700447 CreateService();
Darin Petkov3e509242011-11-10 14:46:44 +0100448 EXPECT_EQ(0, cellular_->service()->strength());
Darin Petkov721ac932011-11-16 15:43:09 +0100449 capability_->GetSignalQuality();
Darin Petkov3e509242011-11-10 14:46:44 +0100450 EXPECT_EQ(kStrength, cellular_->service()->strength());
451}
452
Darin Petkov184c54e2011-11-15 12:44:39 +0100453TEST_F(CellularCapabilityGSMTest, RegisterOnNetwork) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500454 EXPECT_CALL(*network_proxy_, Register(kTestNetwork, _, _,
455 CellularCapability::kTimeoutRegister))
456 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeRegister));
457 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkov184c54e2011-11-15 12:44:39 +0100458 SetNetworkProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500459 Error error;
460 capability_->RegisterOnNetwork(kTestNetwork, &error,
461 Bind(&CellularCapabilityGSMTest::TestCallback,
462 Unretained(this)));
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800463 EXPECT_EQ(kTestNetwork, cellular_->selected_network());
Darin Petkov184c54e2011-11-15 12:44:39 +0100464}
465
Darin Petkovb72cf402011-11-22 14:51:39 +0100466TEST_F(CellularCapabilityGSMTest, IsRegistered) {
467 EXPECT_FALSE(capability_->IsRegistered());
468 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE);
469 EXPECT_FALSE(capability_->IsRegistered());
470 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME);
471 EXPECT_TRUE(capability_->IsRegistered());
472 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING);
473 EXPECT_FALSE(capability_->IsRegistered());
474 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED);
475 EXPECT_FALSE(capability_->IsRegistered());
476 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN);
477 EXPECT_FALSE(capability_->IsRegistered());
478 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING);
479 EXPECT_TRUE(capability_->IsRegistered());
480}
481
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500482TEST_F(CellularCapabilityGSMTest, GetRegistrationState) {
483 ASSERT_FALSE(capability_->IsRegistered());
484 EXPECT_CALL(*network_proxy_,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500485 GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault))
486 .WillOnce(Invoke(this,
487 &CellularCapabilityGSMTest::InvokeGetRegistrationInfo));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500488 SetNetworkProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500489 capability_->GetRegistrationState();
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500490 EXPECT_TRUE(capability_->IsRegistered());
491 EXPECT_EQ(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME,
492 capability_->registration_state_);
493}
494
Darin Petkovb05315f2011-11-07 10:14:25 +0100495TEST_F(CellularCapabilityGSMTest, RequirePIN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500496 EXPECT_CALL(*card_proxy_, EnablePIN(kPIN, true, _, _,
497 CellularCapability::kTimeoutDefault))
498 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnablePIN));
499 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100500 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500501 Error error;
502 capability_->RequirePIN(kPIN, true, &error,
503 Bind(&CellularCapabilityGSMTest::TestCallback,
504 Unretained(this)));
505 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100506}
507
508TEST_F(CellularCapabilityGSMTest, EnterPIN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500509 EXPECT_CALL(*card_proxy_, SendPIN(kPIN, _, _,
510 CellularCapability::kTimeoutDefault))
511 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPIN));
512 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100513 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500514 Error error;
515 capability_->EnterPIN(kPIN, &error,
516 Bind(&CellularCapabilityGSMTest::TestCallback,
517 Unretained(this)));
518 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100519}
520
521TEST_F(CellularCapabilityGSMTest, UnblockPIN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500522 EXPECT_CALL(*card_proxy_, SendPUK(kPUK, kPIN, _, _,
523 CellularCapability::kTimeoutDefault))
524 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPUK));
525 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100526 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500527 Error error;
528 capability_->UnblockPIN(kPUK, kPIN, &error,
529 Bind(&CellularCapabilityGSMTest::TestCallback,
530 Unretained(this)));
531 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100532}
533
534TEST_F(CellularCapabilityGSMTest, ChangePIN) {
535 static const char kOldPIN[] = "1111";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500536 EXPECT_CALL(*card_proxy_, ChangePIN(kOldPIN, kPIN, _, _,
537 CellularCapability::kTimeoutDefault))
538 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeChangePIN));
539 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100540 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500541 Error error;
542 capability_->ChangePIN(kOldPIN, kPIN, &error,
543 Bind(&CellularCapabilityGSMTest::TestCallback,
544 Unretained(this)));
545 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100546}
547
Darin Petkov1272a432011-11-10 15:53:37 +0100548
549TEST_F(CellularCapabilityGSMTest, ParseScanResult) {
550 static const char kID[] = "123";
551 static const char kLongName[] = "long name";
552 static const char kShortName[] = "short name";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500553 GSMScanResult result;
Darin Petkov1272a432011-11-10 15:53:37 +0100554 result[CellularCapabilityGSM::kNetworkPropertyStatus] = "1";
555 result[CellularCapabilityGSM::kNetworkPropertyID] = kID;
556 result[CellularCapabilityGSM::kNetworkPropertyLongName] = kLongName;
557 result[CellularCapabilityGSM::kNetworkPropertyShortName] = kShortName;
558 result[CellularCapabilityGSM::kNetworkPropertyAccessTechnology] = "3";
559 result["unknown property"] = "random value";
Darin Petkov721ac932011-11-16 15:43:09 +0100560 Stringmap parsed = capability_->ParseScanResult(result);
Darin Petkov1272a432011-11-10 15:53:37 +0100561 EXPECT_EQ(5, parsed.size());
Ben Chan7ea768e2013-09-20 15:08:40 -0700562 EXPECT_EQ("available", parsed[kStatusProperty]);
563 EXPECT_EQ(kID, parsed[kNetworkIdProperty]);
564 EXPECT_EQ(kLongName, parsed[kLongNameProperty]);
565 EXPECT_EQ(kShortName, parsed[kShortNameProperty]);
566 EXPECT_EQ(kNetworkTechnologyEdge, parsed[kTechnologyProperty]);
Darin Petkov1272a432011-11-10 15:53:37 +0100567}
568
569TEST_F(CellularCapabilityGSMTest, ParseScanResultProviderLookup) {
Prathmesh Prabhuafe63662014-05-20 11:03:58 -0700570 static const char kID[] = "10001";
571 const string kLongName = "TestNetworkLongName";
572 // Replace the |MobileOperatorInfo| used by |ParseScanResult| by a mock.
573 auto *mock_mobile_operator_info = new MockMobileOperatorInfo(
574 &dispatcher_,
575 "MockParseScanResult");
576 capability_->mobile_operator_info_.reset(mock_mobile_operator_info);
577
578 mock_mobile_operator_info->SetEmptyDefaultsForProperties();
579 EXPECT_CALL(*mock_mobile_operator_info, UpdateMCCMNC(kID));
580 EXPECT_CALL(*mock_mobile_operator_info, IsMobileNetworkOperatorKnown()).
581 WillOnce(Return(true));
582 EXPECT_CALL(*mock_mobile_operator_info, operator_name()).
583 WillRepeatedly(ReturnRef(kLongName));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500584 GSMScanResult result;
Darin Petkov1272a432011-11-10 15:53:37 +0100585 result[CellularCapabilityGSM::kNetworkPropertyID] = kID;
Darin Petkov721ac932011-11-16 15:43:09 +0100586 Stringmap parsed = capability_->ParseScanResult(result);
Darin Petkov1272a432011-11-10 15:53:37 +0100587 EXPECT_EQ(2, parsed.size());
Ben Chan7ea768e2013-09-20 15:08:40 -0700588 EXPECT_EQ(kID, parsed[kNetworkIdProperty]);
Prathmesh Prabhuafe63662014-05-20 11:03:58 -0700589 EXPECT_EQ(kLongName, parsed[kLongNameProperty]);
Darin Petkov1272a432011-11-10 15:53:37 +0100590}
591
Darin Petkovae0c64e2011-11-15 15:50:27 +0100592TEST_F(CellularCapabilityGSMTest, SetAccessTechnology) {
Darin Petkov721ac932011-11-16 15:43:09 +0100593 capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM);
594 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GSM, capability_->access_technology_);
Prathmesh Prabhu6e0a8ef2014-05-05 22:30:07 -0700595 CreateService();
Darin Petkovb72cf402011-11-22 14:51:39 +0100596 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME);
Darin Petkov721ac932011-11-16 15:43:09 +0100597 capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS);
598 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GPRS, capability_->access_technology_);
Ben Chan7ea768e2013-09-20 15:08:40 -0700599 EXPECT_EQ(kNetworkTechnologyGprs, cellular_->service()->network_technology());
Darin Petkovae0c64e2011-11-15 15:50:27 +0100600}
601
Darin Petkovf508c822012-09-21 13:43:17 +0200602TEST_F(CellularCapabilityGSMTest, AllowRoaming) {
603 EXPECT_FALSE(cellular_->allow_roaming_);
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800604 EXPECT_FALSE(cellular_->provider_requires_roaming());
Darin Petkovf508c822012-09-21 13:43:17 +0200605 EXPECT_FALSE(capability_->AllowRoaming());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800606 cellular_->set_provider_requires_roaming(true);
Darin Petkovf508c822012-09-21 13:43:17 +0200607 EXPECT_TRUE(capability_->AllowRoaming());
Prathmesh Prabhu9f06c872013-11-21 14:08:23 -0800608 cellular_->set_provider_requires_roaming(false);
Darin Petkovf508c822012-09-21 13:43:17 +0200609 cellular_->allow_roaming_ = true;
610 EXPECT_TRUE(capability_->AllowRoaming());
611}
612
Darin Petkov20c13ec2011-11-09 15:07:15 +0100613TEST_F(CellularCapabilityGSMTest, GetNetworkTechnologyString) {
Darin Petkov721ac932011-11-16 15:43:09 +0100614 EXPECT_EQ("", capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100615 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM);
Ben Chan7ea768e2013-09-20 15:08:40 -0700616 EXPECT_EQ(kNetworkTechnologyGsm, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100617 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT);
Ben Chan7ea768e2013-09-20 15:08:40 -0700618 EXPECT_EQ(kNetworkTechnologyGsm, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100619 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS);
Ben Chan7ea768e2013-09-20 15:08:40 -0700620 EXPECT_EQ(kNetworkTechnologyGprs, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100621 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_EDGE);
Ben Chan7ea768e2013-09-20 15:08:40 -0700622 EXPECT_EQ(kNetworkTechnologyEdge, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100623 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_UMTS);
Ben Chan7ea768e2013-09-20 15:08:40 -0700624 EXPECT_EQ(kNetworkTechnologyUmts, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100625 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSDPA);
Ben Chan7ea768e2013-09-20 15:08:40 -0700626 EXPECT_EQ(kNetworkTechnologyHspa, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100627 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSUPA);
Ben Chan7ea768e2013-09-20 15:08:40 -0700628 EXPECT_EQ(kNetworkTechnologyHspa, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100629 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA);
Ben Chan7ea768e2013-09-20 15:08:40 -0700630 EXPECT_EQ(kNetworkTechnologyHspa, capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100631 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS);
Ben Chan7ea768e2013-09-20 15:08:40 -0700632 EXPECT_EQ(kNetworkTechnologyHspaPlus,
Darin Petkov721ac932011-11-16 15:43:09 +0100633 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100634}
635
636TEST_F(CellularCapabilityGSMTest, GetRoamingStateString) {
Ben Chan7ea768e2013-09-20 15:08:40 -0700637 EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100638 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME);
Ben Chan7ea768e2013-09-20 15:08:40 -0700639 EXPECT_EQ(kRoamingStateHome, capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100640 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING);
Ben Chan7ea768e2013-09-20 15:08:40 -0700641 EXPECT_EQ(kRoamingStateRoaming, capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100642 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING);
Ben Chan7ea768e2013-09-20 15:08:40 -0700643 EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100644 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED);
Ben Chan7ea768e2013-09-20 15:08:40 -0700645 EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100646 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE);
Ben Chan7ea768e2013-09-20 15:08:40 -0700647 EXPECT_EQ(kRoamingStateUnknown, capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100648}
649
Gaurav Shah67808222013-03-27 13:29:36 -0700650MATCHER_P(KeyValueStoreEq, value, "") {
651 bool match = value.bool_properties() == arg.bool_properties() &&
652 value.int_properties() == arg.int_properties() &&
653 value.string_properties() == arg.string_properties() &&
654 value.uint_properties() == arg.uint_properties();
Gaurav Shah67808222013-03-27 13:29:36 -0700655 if (!match) {
656 *result_listener << "\nExpected KeyValueStore:\n"
657 << "\tbool_properties: "
658 << testing::PrintToString(value.bool_properties())
659 << "\n\tint_properties: "
660 << testing::PrintToString(value.int_properties())
661 << "\n\tstring_properties: "
662 << testing::PrintToString(value.string_properties())
663 << "\n\tint_properties: "
664 << testing::PrintToString(value.uint_properties())
665 << "\nGot KeyValueStore:\n"
666 << "\tbool_properties: "
667 << testing::PrintToString(arg.bool_properties())
668 << "\n\tint_properties: "
669 << testing::PrintToString(arg.int_properties())
670 << "\n\tstring_properties: "
671 << testing::PrintToString(arg.string_properties())
672 << "\n\tuint_properties: "
673 << testing::PrintToString(arg.uint_properties());
674 }
Gaurav Shah67808222013-03-27 13:29:36 -0700675 return match;
676}
677
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400678TEST_F(CellularCapabilityGSMTest, OnDBusPropertiesChanged) {
Darin Petkov63138a92012-02-06 14:09:15 +0100679 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_);
680 EXPECT_FALSE(capability_->sim_lock_status_.enabled);
681 EXPECT_EQ("", capability_->sim_lock_status_.lock_type);
682 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
683 DBusPropertiesMap props;
684 static const char kLockType[] = "sim-pin";
685 const int kRetries = 3;
686 props[CellularCapabilityGSM::kPropertyAccessTechnology].writer().
687 append_uint32(MM_MODEM_GSM_ACCESS_TECH_EDGE);
688 props[CellularCapabilityGSM::kPropertyEnabledFacilityLocks].writer().
689 append_uint32(MM_MODEM_GSM_FACILITY_SIM);
690 props[CellularCapabilityGSM::kPropertyUnlockRequired].writer().append_string(
691 kLockType);
692 props[CellularCapabilityGSM::kPropertyUnlockRetries].writer().append_uint32(
693 kRetries);
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400694 // Call with the 'wrong' interface and nothing should change.
695 capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_INTERFACE, props,
696 vector<string>());
697 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_);
698 EXPECT_FALSE(capability_->sim_lock_status_.enabled);
699 EXPECT_EQ("", capability_->sim_lock_status_.lock_type);
700 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
701
Gary Morainbaeefdf2012-04-30 14:53:35 -0700702 // Call with the MM_MODEM_GSM_NETWORK_INTERFACE interface and expect a change
703 // to the enabled state of the SIM lock.
704 KeyValueStore lock_status;
Ben Chan7ea768e2013-09-20 15:08:40 -0700705 lock_status.SetBool(kSIMLockEnabledProperty, true);
706 lock_status.SetString(kSIMLockTypeProperty, "");
707 lock_status.SetUint(kSIMLockRetriesLeftProperty, 0);
Gary Morainbaeefdf2012-04-30 14:53:35 -0700708
709 EXPECT_CALL(*device_adaptor_, EmitKeyValueStoreChanged(
Ben Chan7ea768e2013-09-20 15:08:40 -0700710 kSIMLockStatusProperty,
Gary Morainbaeefdf2012-04-30 14:53:35 -0700711 KeyValueStoreEq(lock_status)));
712
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400713 capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_NETWORK_INTERFACE, props,
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400714 vector<string>());
Darin Petkov63138a92012-02-06 14:09:15 +0100715 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_EDGE, capability_->access_technology_);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400716 capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_CARD_INTERFACE, props,
717 vector<string>());
Darin Petkov63138a92012-02-06 14:09:15 +0100718 EXPECT_TRUE(capability_->sim_lock_status_.enabled);
Gary Morainbaeefdf2012-04-30 14:53:35 -0700719 EXPECT_TRUE(capability_->sim_lock_status_.lock_type.empty());
720 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
721
722 // Some properties are sent on the MM_MODEM_INTERFACE.
723 capability_->sim_lock_status_.enabled = false;
724 capability_->sim_lock_status_.lock_type = "";
725 capability_->sim_lock_status_.retries_left = 0;
726 KeyValueStore lock_status2;
Ben Chan7ea768e2013-09-20 15:08:40 -0700727 lock_status2.SetBool(kSIMLockEnabledProperty, false);
728 lock_status2.SetString(kSIMLockTypeProperty, kLockType);
729 lock_status2.SetUint(kSIMLockRetriesLeftProperty, kRetries);
Gary Morainbaeefdf2012-04-30 14:53:35 -0700730 EXPECT_CALL(*device_adaptor_,
Ben Chan7ea768e2013-09-20 15:08:40 -0700731 EmitKeyValueStoreChanged(kSIMLockStatusProperty,
Gary Morainbaeefdf2012-04-30 14:53:35 -0700732 KeyValueStoreEq(lock_status2)));
733 capability_->OnDBusPropertiesChanged(MM_MODEM_INTERFACE, props,
734 vector<string>());
735 EXPECT_FALSE(capability_->sim_lock_status_.enabled);
Darin Petkov63138a92012-02-06 14:09:15 +0100736 EXPECT_EQ(kLockType, capability_->sim_lock_status_.lock_type);
737 EXPECT_EQ(kRetries, capability_->sim_lock_status_.retries_left);
738}
739
Thieu Le923006b2012-04-05 16:32:58 -0700740TEST_F(CellularCapabilityGSMTest, StartModemSuccess) {
741 SetupCommonStartModemExpectations();
742 EXPECT_CALL(*card_proxy_,
743 GetSPN(_, _, CellularCapability::kTimeoutDefault))
744 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN));
745 EXPECT_CALL(*card_proxy_,
746 GetMSISDN(_, _, CellularCapability::kTimeoutDefault))
747 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN));
Ben Chan3ecdf822012-08-06 12:29:23 -0700748 AllowCreateCardProxyFromFactory();
Thieu Le923006b2012-04-05 16:32:58 -0700749
750 Error error;
751 capability_->StartModem(
752 &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this)));
753 dispatcher_.DispatchPendingEvents();
754}
755
756TEST_F(CellularCapabilityGSMTest, StartModemGetSPNFail) {
757 SetupCommonStartModemExpectations();
758 EXPECT_CALL(*card_proxy_,
759 GetSPN(_, _, CellularCapability::kTimeoutDefault))
760 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPNFail));
761 EXPECT_CALL(*card_proxy_,
762 GetMSISDN(_, _, CellularCapability::kTimeoutDefault))
763 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN));
Ben Chan3ecdf822012-08-06 12:29:23 -0700764 AllowCreateCardProxyFromFactory();
Thieu Le923006b2012-04-05 16:32:58 -0700765
766 Error error;
767 capability_->StartModem(
768 &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this)));
769 dispatcher_.DispatchPendingEvents();
770}
771
772TEST_F(CellularCapabilityGSMTest, StartModemGetMSISDNFail) {
773 SetupCommonStartModemExpectations();
774 EXPECT_CALL(*card_proxy_,
775 GetSPN(_, _, CellularCapability::kTimeoutDefault))
776 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN));
777 EXPECT_CALL(*card_proxy_,
778 GetMSISDN(_, _, CellularCapability::kTimeoutDefault))
779 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDNFail));
Ben Chan3ecdf822012-08-06 12:29:23 -0700780 AllowCreateCardProxyFromFactory();
Thieu Le923006b2012-04-05 16:32:58 -0700781
782 Error error;
783 capability_->StartModem(
784 &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this)));
785 dispatcher_.DispatchPendingEvents();
786}
787
Thieu Leb5954a22012-05-18 10:37:34 -0700788TEST_F(CellularCapabilityGSMTest, ConnectFailureNoService) {
789 // Make sure we don't crash if the connect failed and there is no
790 // CellularService object. This can happen if the modem is enabled and
791 // then quickly disabled.
792 SetupCommonProxiesExpectations();
793 EXPECT_CALL(*simple_proxy_,
794 Connect(_, _, _, CellularCapabilityGSM::kTimeoutConnect))
795 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeConnectFail));
796 EXPECT_CALL(*this, TestCallback(IsFailure()));
Thieu Leb5954a22012-05-18 10:37:34 -0700797 InitProxies();
798 EXPECT_FALSE(capability_->cellular()->service());
799 Error error;
800 DBusPropertiesMap props;
801 capability_->Connect(props, &error,
802 Bind(&CellularCapabilityGSMTest::TestCallback,
803 Unretained(this)));
804}
805
Darin Petkovb05315f2011-11-07 10:14:25 +0100806} // namespace shill