blob: 648bb008369d4cf7afe7a1665ab0cf92a18f4686 [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>
Darin Petkov20c13ec2011-11-09 15:07:15 +010011#include <chromeos/dbus/service_constants.h>
Darin Petkovb05315f2011-11-07 10:14:25 +010012#include <gtest/gtest.h>
Darin Petkov20c13ec2011-11-09 15:07:15 +010013#include <mm/mm-modem.h>
Darin Petkov1272a432011-11-10 15:53:37 +010014#include <mobile_provider.h>
Darin Petkovb05315f2011-11-07 10:14:25 +010015
16#include "shill/cellular.h"
Darin Petkov3e509242011-11-10 14:46:44 +010017#include "shill/cellular_service.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010018#include "shill/error.h"
19#include "shill/event_dispatcher.h"
Darin Petkov3cfbf212011-11-21 16:02:09 +010020#include "shill/mock_adaptors.h"
Thieu Le3426c8f2012-01-11 17:35:11 -080021#include "shill/mock_metrics.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"
Thieu Le923006b2012-04-05 16:32:58 -070024#include "shill/mock_modem_proxy.h"
25#include "shill/mock_modem_simple_proxy.h"
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040026#include "shill/mock_profile.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010027#include "shill/nice_mock_control.h"
Thieu Le923006b2012-04-05 16:32:58 -070028#include "shill/proxy_factory.h"
Darin Petkovb05315f2011-11-07 10:14:25 +010029
Eric Shienbrood9a245532012-03-07 14:20:39 -050030using base::Bind;
31using base::Unretained;
Darin Petkov31332412012-01-28 01:50:02 +010032using std::string;
Jason Glasgow4c0724a2012-04-17 15:47:40 -040033using std::vector;
Darin Petkove5bc2cb2011-12-07 14:47:32 +010034using testing::_;
Eric Shienbrood9a245532012-03-07 14:20:39 -050035using testing::Invoke;
Darin Petkov3cfbf212011-11-21 16:02:09 +010036using testing::NiceMock;
Darin Petkovcb547732011-11-09 13:55:26 +010037using testing::Return;
38
Darin Petkovb05315f2011-11-07 10:14:25 +010039namespace shill {
40
Eric Shienbrood9a245532012-03-07 14:20:39 -050041MATCHER(IsSuccess, "") {
42 return arg.IsSuccess();
43}
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050044
Darin Petkovb05315f2011-11-07 10:14:25 +010045class CellularCapabilityGSMTest : public testing::Test {
46 public:
47 CellularCapabilityGSMTest()
48 : cellular_(new Cellular(&control_,
49 &dispatcher_,
Thieu Le3426c8f2012-01-11 17:35:11 -080050 &metrics_,
Darin Petkovb05315f2011-11-07 10:14:25 +010051 NULL,
52 "",
Darin Petkov31332412012-01-28 01:50:02 +010053 kAddress,
Darin Petkovb05315f2011-11-07 10:14:25 +010054 0,
55 Cellular::kTypeGSM,
56 "",
57 "",
58 NULL)),
Thieu Le923006b2012-04-05 16:32:58 -070059 proxy_(new MockModemProxy()),
60 simple_proxy_(new MockModemSimpleProxy()),
Darin Petkovcb547732011-11-09 13:55:26 +010061 card_proxy_(new MockModemGSMCardProxy()),
Darin Petkov3e509242011-11-10 14:46:44 +010062 network_proxy_(new MockModemGSMNetworkProxy()),
Thieu Le923006b2012-04-05 16:32:58 -070063 proxy_factory_(this),
Darin Petkov721ac932011-11-16 15:43:09 +010064 capability_(NULL),
Darin Petkov3cfbf212011-11-21 16:02:09 +010065 device_adaptor_(NULL),
Darin Petkov1272a432011-11-10 15:53:37 +010066 provider_db_(NULL) {}
Darin Petkovb05315f2011-11-07 10:14:25 +010067
Darin Petkov3e509242011-11-10 14:46:44 +010068 virtual ~CellularCapabilityGSMTest() {
69 cellular_->service_ = NULL;
Darin Petkov1272a432011-11-10 15:53:37 +010070 mobile_provider_close_db(provider_db_);
71 provider_db_ = NULL;
Darin Petkov721ac932011-11-16 15:43:09 +010072 capability_ = NULL;
Darin Petkov3cfbf212011-11-21 16:02:09 +010073 device_adaptor_ = NULL;
Darin Petkov721ac932011-11-16 15:43:09 +010074 }
75
76 virtual void SetUp() {
77 capability_ =
78 dynamic_cast<CellularCapabilityGSM *>(cellular_->capability_.get());
Darin Petkov3cfbf212011-11-21 16:02:09 +010079 device_adaptor_ =
80 dynamic_cast<NiceMock<DeviceMockAdaptor> *>(cellular_->adaptor());
Darin Petkov3e509242011-11-10 14:46:44 +010081 }
82
Thieu Le923006b2012-04-05 16:32:58 -070083 void InvokeEnable(bool enable, Error *error,
84 const ResultCallback &callback, int timeout) {
85 callback.Run(Error());
86 }
Eric Shienbrood9a245532012-03-07 14:20:39 -050087 void InvokeGetIMEI(Error *error, const GSMIdentifierCallback &callback,
88 int timeout) {
89 callback.Run(kIMEI, Error());
90 }
91 void InvokeGetIMSI(Error *error, const GSMIdentifierCallback &callback,
92 int timeout) {
93 callback.Run(kIMSI, Error());
94 }
95 void InvokeGetIMSI2(Error *error, const GSMIdentifierCallback &callback,
96 int timeout) {
97 callback.Run("310240123456789", Error());
98 }
99 void InvokeGetMSISDN(Error *error, const GSMIdentifierCallback &callback,
100 int timeout) {
101 callback.Run(kMSISDN, Error());
102 }
Thieu Le923006b2012-04-05 16:32:58 -0700103 void InvokeGetMSISDNFail(Error *error, const GSMIdentifierCallback &callback,
104 int timeout) {
105 callback.Run("", Error(Error::kOperationFailed));
106 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500107 void InvokeGetSPN(Error *error, const GSMIdentifierCallback &callback,
108 int timeout) {
109 callback.Run(kTestCarrier, Error());
110 }
Thieu Le923006b2012-04-05 16:32:58 -0700111 void InvokeGetSPNFail(Error *error, const GSMIdentifierCallback &callback,
112 int timeout) {
113 callback.Run("", Error(Error::kOperationFailed));
114 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500115 void InvokeGetSignalQuality(Error *error,
116 const SignalQualityCallback &callback,
117 int timeout) {
118 callback.Run(kStrength, Error());
119 }
120 void InvokeGetRegistrationInfo(Error *error,
121 const RegistrationInfoCallback &callback,
122 int timeout) {
123 callback.Run(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME,
124 kTestNetwork, kTestCarrier, Error());
125 }
126 void InvokeRegister(const string &network_id,
127 Error *error,
128 const ResultCallback &callback,
129 int timeout) {
130 callback.Run(Error());
131 }
132 void InvokeEnablePIN(const string &pin, bool enable,
133 Error *error, const ResultCallback &callback,
134 int timeout) {
135 callback.Run(Error());
136 }
137 void InvokeSendPIN(const string &pin, Error *error,
138 const ResultCallback &callback, int timeout) {
139 callback.Run(Error());
140 }
141 void InvokeSendPUK(const string &puk, const string &pin, Error *error,
142 const ResultCallback &callback, int timeout) {
143 callback.Run(Error());
144 }
145 void InvokeChangePIN(const string &old_pin, const string &pin, Error *error,
146 const ResultCallback &callback, int timeout) {
147 callback.Run(Error());
148 }
149 void InvokeScan(Error *error, const ScanResultsCallback &callback,
150 int timeout) {
151 GSMScanResults results;
152 results.push_back(GSMScanResult());
153 results[0][CellularCapabilityGSM::kNetworkPropertyID] = kScanID0;
154 results.push_back(GSMScanResult());
155 results[1][CellularCapabilityGSM::kNetworkPropertyID] = kScanID1;
156 callback.Run(results, Error());
157 }
Thieu Le923006b2012-04-05 16:32:58 -0700158 void InvokeGetModemStatus(Error *error,
159 const DBusPropertyMapCallback &callback,
160 int timeout) {
161 DBusPropertiesMap props;
162 callback.Run(props, Error());
163 }
164 void InvokeGetModemInfo(Error *error, const ModemInfoCallback &callback,
165 int timeout) {
166 ModemHardwareInfo info;
167 callback.Run(info, Error());
168 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500169
170 MOCK_METHOD1(TestCallback, void(const Error &error));
171
Darin Petkovb05315f2011-11-07 10:14:25 +0100172 protected:
Darin Petkov31332412012-01-28 01:50:02 +0100173 static const char kAddress[];
Darin Petkov1272a432011-11-10 15:53:37 +0100174 static const char kTestMobileProviderDBPath[];
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500175 static const char kTestNetwork[];
Darin Petkovcb547732011-11-09 13:55:26 +0100176 static const char kTestCarrier[];
Darin Petkovb05315f2011-11-07 10:14:25 +0100177 static const char kPIN[];
178 static const char kPUK[];
Darin Petkovcb547732011-11-09 13:55:26 +0100179 static const char kIMEI[];
180 static const char kIMSI[];
181 static const char kMSISDN[];
Eric Shienbrood9a245532012-03-07 14:20:39 -0500182 static const char kScanID0[];
183 static const char kScanID1[];
184 static const int kStrength;
Darin Petkovcb547732011-11-09 13:55:26 +0100185
Thieu Le923006b2012-04-05 16:32:58 -0700186 class TestProxyFactory : public ProxyFactory {
187 public:
188 explicit TestProxyFactory(CellularCapabilityGSMTest *test) : test_(test) {}
189
190 virtual ModemProxyInterface *CreateModemProxy(
191 const string &/*path*/,
192 const string &/*service*/) {
193 return test_->proxy_.release();
194 }
195
196 virtual ModemSimpleProxyInterface *CreateModemSimpleProxy(
197 const string &/*path*/,
198 const string &/*service*/) {
199 return test_->simple_proxy_.release();
200 }
201
202 virtual ModemGSMCardProxyInterface *CreateModemGSMCardProxy(
203 const string &/*path*/,
204 const string &/*service*/) {
205 return test_->card_proxy_.release();
206 }
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
Thieu Le923006b2012-04-05 16:32:58 -0700230 void SetProxyFactory() {
231 capability_->proxy_factory_ = &proxy_factory_;
232 }
233
Darin Petkov20c13ec2011-11-09 15:07:15 +0100234 void SetAccessTechnology(uint32 technology) {
Darin Petkov721ac932011-11-16 15:43:09 +0100235 capability_->access_technology_ = technology;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100236 }
237
238 void SetRegistrationState(uint32 state) {
Darin Petkov721ac932011-11-16 15:43:09 +0100239 capability_->registration_state_ = state;
Darin Petkov20c13ec2011-11-09 15:07:15 +0100240 }
241
Darin Petkov3e509242011-11-10 14:46:44 +0100242 void SetService() {
243 cellular_->service_ = new CellularService(
Thieu Le3426c8f2012-01-11 17:35:11 -0800244 &control_, &dispatcher_, &metrics_, NULL, cellular_);
Darin Petkov3e509242011-11-10 14:46:44 +0100245 }
246
Darin Petkov1272a432011-11-10 15:53:37 +0100247 void InitProviderDB() {
248 provider_db_ = mobile_provider_open_db(kTestMobileProviderDBPath);
249 ASSERT_TRUE(provider_db_);
250 cellular_->provider_db_ = provider_db_;
251 }
252
Thieu Le923006b2012-04-05 16:32:58 -0700253 void SetupCommonStartModemExpectations() {
254 EXPECT_CALL(*proxy_, set_state_changed_callback(_));
255 EXPECT_CALL(*network_proxy_, set_signal_quality_callback(_));
256 EXPECT_CALL(*network_proxy_, set_network_mode_callback(_));
257 EXPECT_CALL(*network_proxy_, set_registration_info_callback(_));
258
259 EXPECT_CALL(*proxy_, Enable(_, _, _, CellularCapability::kTimeoutEnable))
260 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnable));
Thieu Le923006b2012-04-05 16:32:58 -0700261 EXPECT_CALL(*card_proxy_,
262 GetIMEI(_, _, CellularCapability::kTimeoutDefault))
263 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMEI));
264 EXPECT_CALL(*card_proxy_,
265 GetIMSI(_, _, CellularCapability::kTimeoutDefault))
266 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetIMSI));
267 EXPECT_CALL(*network_proxy_, AccessTechnology());
268 EXPECT_CALL(*card_proxy_, EnabledFacilityLocks());
269 EXPECT_CALL(*proxy_,
270 GetModemInfo(_, _, CellularCapability::kTimeoutDefault))
271 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetModemInfo));
272 EXPECT_CALL(*network_proxy_,
273 GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault));
274 EXPECT_CALL(*network_proxy_,
275 GetSignalQuality(_, _, CellularCapability::kTimeoutDefault));
276 EXPECT_CALL(*this, TestCallback(IsSuccess()));
277 }
278
Darin Petkovb05315f2011-11-07 10:14:25 +0100279 NiceMockControl control_;
280 EventDispatcher dispatcher_;
Thieu Le3426c8f2012-01-11 17:35:11 -0800281 MockMetrics metrics_;
Darin Petkovb05315f2011-11-07 10:14:25 +0100282 CellularRefPtr cellular_;
Thieu Le923006b2012-04-05 16:32:58 -0700283 scoped_ptr<MockModemProxy> proxy_;
284 scoped_ptr<MockModemSimpleProxy> simple_proxy_;
Darin Petkovcb547732011-11-09 13:55:26 +0100285 scoped_ptr<MockModemGSMCardProxy> card_proxy_;
Darin Petkov3e509242011-11-10 14:46:44 +0100286 scoped_ptr<MockModemGSMNetworkProxy> network_proxy_;
Thieu Le923006b2012-04-05 16:32:58 -0700287 TestProxyFactory proxy_factory_;
Darin Petkov721ac932011-11-16 15:43:09 +0100288 CellularCapabilityGSM *capability_; // Owned by |cellular_|.
Darin Petkov3cfbf212011-11-21 16:02:09 +0100289 NiceMock<DeviceMockAdaptor> *device_adaptor_; // Owned by |cellular_|.
Darin Petkov1272a432011-11-10 15:53:37 +0100290 mobile_provider_db *provider_db_;
Darin Petkovb05315f2011-11-07 10:14:25 +0100291};
292
Darin Petkov31332412012-01-28 01:50:02 +0100293const char CellularCapabilityGSMTest::kAddress[] = "1122334455";
Darin Petkov1272a432011-11-10 15:53:37 +0100294const char CellularCapabilityGSMTest::kTestMobileProviderDBPath[] =
295 "provider_db_unittest.bfd";
Darin Petkovcb547732011-11-09 13:55:26 +0100296const char CellularCapabilityGSMTest::kTestCarrier[] = "The Cellular Carrier";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500297const char CellularCapabilityGSMTest::kTestNetwork[] = "310555";
Darin Petkovb05315f2011-11-07 10:14:25 +0100298const char CellularCapabilityGSMTest::kPIN[] = "9876";
299const char CellularCapabilityGSMTest::kPUK[] = "8765";
Darin Petkovcb547732011-11-09 13:55:26 +0100300const char CellularCapabilityGSMTest::kIMEI[] = "987654321098765";
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100301const char CellularCapabilityGSMTest::kIMSI[] = "310150123456789";
Darin Petkovcb547732011-11-09 13:55:26 +0100302const char CellularCapabilityGSMTest::kMSISDN[] = "12345678901";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500303const char CellularCapabilityGSMTest::kScanID0[] = "123";
304const char CellularCapabilityGSMTest::kScanID1[] = "456";
305const int CellularCapabilityGSMTest::kStrength = 80;
Darin Petkovcb547732011-11-09 13:55:26 +0100306
Darin Petkov721ac932011-11-16 15:43:09 +0100307TEST_F(CellularCapabilityGSMTest, PropertyStore) {
308 EXPECT_TRUE(cellular_->store().Contains(flimflam::kSIMLockStatusProperty));
309}
310
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500311TEST_F(CellularCapabilityGSMTest, GetIMEI) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500312 EXPECT_CALL(*card_proxy_, GetIMEI(_, _, CellularCapability::kTimeoutDefault))
313 .WillOnce(Invoke(this,
314 &CellularCapabilityGSMTest::InvokeGetIMEI));
315 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100316 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500317 ASSERT_TRUE(capability_->imei_.empty());
318 capability_->GetIMEI(Bind(&CellularCapabilityGSMTest::TestCallback,
319 Unretained(this)));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500320 EXPECT_EQ(kIMEI, capability_->imei_);
321}
322
323TEST_F(CellularCapabilityGSMTest, GetIMSI) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500324 EXPECT_CALL(*card_proxy_, GetIMSI(_, _, CellularCapability::kTimeoutDefault))
325 .WillOnce(Invoke(this,
326 &CellularCapabilityGSMTest::InvokeGetIMSI))
327 .WillOnce(Invoke(this,
328 &CellularCapabilityGSMTest::InvokeGetIMSI2));
329 EXPECT_CALL(*this, TestCallback(IsSuccess())).Times(2);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500330 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500331 ResultCallback callback = Bind(&CellularCapabilityGSMTest::TestCallback,
332 Unretained(this));
333 ASSERT_TRUE(capability_->imsi_.empty());
334 capability_->GetIMSI(callback);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500335 EXPECT_EQ(kIMSI, capability_->imsi_);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500336 capability_->imsi_.clear();
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100337 InitProviderDB();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500338 capability_->GetIMSI(callback);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500339 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
340}
341
342TEST_F(CellularCapabilityGSMTest, GetMSISDN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500343 EXPECT_CALL(*card_proxy_, GetMSISDN(_, _,
344 CellularCapability::kTimeoutDefault))
345 .WillOnce(Invoke(this,
346 &CellularCapabilityGSMTest::InvokeGetMSISDN));
347 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500348 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500349 ASSERT_TRUE(capability_->mdn_.empty());
350 capability_->GetMSISDN(Bind(&CellularCapabilityGSMTest::TestCallback,
351 Unretained(this)));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500352 EXPECT_EQ(kMSISDN, capability_->mdn_);
353}
354
355TEST_F(CellularCapabilityGSMTest, GetSPN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500356 EXPECT_CALL(*card_proxy_, GetSPN(_, _, CellularCapability::kTimeoutDefault))
357 .WillOnce(Invoke(this,
358 &CellularCapabilityGSMTest::InvokeGetSPN));
359 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500360 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500361 ASSERT_TRUE(capability_->spn_.empty());
362 capability_->GetSPN(Bind(&CellularCapabilityGSMTest::TestCallback,
363 Unretained(this)));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500364 EXPECT_EQ(kTestCarrier, capability_->spn_);
Darin Petkovcb547732011-11-09 13:55:26 +0100365}
Darin Petkovb05315f2011-11-07 10:14:25 +0100366
Darin Petkov3e509242011-11-10 14:46:44 +0100367TEST_F(CellularCapabilityGSMTest, GetSignalQuality) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500368 EXPECT_CALL(*network_proxy_,
369 GetSignalQuality(_, _, CellularCapability::kTimeoutDefault))
370 .WillOnce(Invoke(this,
371 &CellularCapabilityGSMTest::InvokeGetSignalQuality));
Darin Petkov3e509242011-11-10 14:46:44 +0100372 SetNetworkProxy();
373 SetService();
374 EXPECT_EQ(0, cellular_->service()->strength());
Darin Petkov721ac932011-11-16 15:43:09 +0100375 capability_->GetSignalQuality();
Darin Petkov3e509242011-11-10 14:46:44 +0100376 EXPECT_EQ(kStrength, cellular_->service()->strength());
377}
378
Darin Petkov184c54e2011-11-15 12:44:39 +0100379TEST_F(CellularCapabilityGSMTest, RegisterOnNetwork) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500380 EXPECT_CALL(*network_proxy_, Register(kTestNetwork, _, _,
381 CellularCapability::kTimeoutRegister))
382 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeRegister));
383 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkov184c54e2011-11-15 12:44:39 +0100384 SetNetworkProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500385 Error error;
386 capability_->RegisterOnNetwork(kTestNetwork, &error,
387 Bind(&CellularCapabilityGSMTest::TestCallback,
388 Unretained(this)));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500389 EXPECT_EQ(kTestNetwork, capability_->selected_network_);
Darin Petkov184c54e2011-11-15 12:44:39 +0100390}
391
Darin Petkovb72cf402011-11-22 14:51:39 +0100392TEST_F(CellularCapabilityGSMTest, IsRegistered) {
393 EXPECT_FALSE(capability_->IsRegistered());
394 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE);
395 EXPECT_FALSE(capability_->IsRegistered());
396 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME);
397 EXPECT_TRUE(capability_->IsRegistered());
398 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING);
399 EXPECT_FALSE(capability_->IsRegistered());
400 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED);
401 EXPECT_FALSE(capability_->IsRegistered());
402 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN);
403 EXPECT_FALSE(capability_->IsRegistered());
404 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING);
405 EXPECT_TRUE(capability_->IsRegistered());
406}
407
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500408TEST_F(CellularCapabilityGSMTest, GetRegistrationState) {
409 ASSERT_FALSE(capability_->IsRegistered());
410 EXPECT_CALL(*network_proxy_,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500411 GetRegistrationInfo(_, _, CellularCapability::kTimeoutDefault))
412 .WillOnce(Invoke(this,
413 &CellularCapabilityGSMTest::InvokeGetRegistrationInfo));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500414 SetNetworkProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500415 capability_->GetRegistrationState();
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500416 EXPECT_TRUE(capability_->IsRegistered());
417 EXPECT_EQ(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME,
418 capability_->registration_state_);
419}
420
Darin Petkovb05315f2011-11-07 10:14:25 +0100421TEST_F(CellularCapabilityGSMTest, RequirePIN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500422 EXPECT_CALL(*card_proxy_, EnablePIN(kPIN, true, _, _,
423 CellularCapability::kTimeoutDefault))
424 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeEnablePIN));
425 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100426 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500427 Error error;
428 capability_->RequirePIN(kPIN, true, &error,
429 Bind(&CellularCapabilityGSMTest::TestCallback,
430 Unretained(this)));
431 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100432}
433
434TEST_F(CellularCapabilityGSMTest, EnterPIN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500435 EXPECT_CALL(*card_proxy_, SendPIN(kPIN, _, _,
436 CellularCapability::kTimeoutDefault))
437 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPIN));
438 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100439 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500440 Error error;
441 capability_->EnterPIN(kPIN, &error,
442 Bind(&CellularCapabilityGSMTest::TestCallback,
443 Unretained(this)));
444 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100445}
446
447TEST_F(CellularCapabilityGSMTest, UnblockPIN) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500448 EXPECT_CALL(*card_proxy_, SendPUK(kPUK, kPIN, _, _,
449 CellularCapability::kTimeoutDefault))
450 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeSendPUK));
451 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100452 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500453 Error error;
454 capability_->UnblockPIN(kPUK, kPIN, &error,
455 Bind(&CellularCapabilityGSMTest::TestCallback,
456 Unretained(this)));
457 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100458}
459
460TEST_F(CellularCapabilityGSMTest, ChangePIN) {
461 static const char kOldPIN[] = "1111";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500462 EXPECT_CALL(*card_proxy_, ChangePIN(kOldPIN, kPIN, _, _,
463 CellularCapability::kTimeoutDefault))
464 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeChangePIN));
465 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkovcb547732011-11-09 13:55:26 +0100466 SetCardProxy();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500467 Error error;
468 capability_->ChangePIN(kOldPIN, kPIN, &error,
469 Bind(&CellularCapabilityGSMTest::TestCallback,
470 Unretained(this)));
471 EXPECT_TRUE(error.IsSuccess());
Darin Petkovb05315f2011-11-07 10:14:25 +0100472}
473
Darin Petkovb7828b02012-02-03 12:34:30 +0100474namespace {
475
476MATCHER(SizeIs2, "") {
477 return arg.size() == 2;
478}
479
480} // namespace
481
Darin Petkov1272a432011-11-10 15:53:37 +0100482TEST_F(CellularCapabilityGSMTest, Scan) {
Darin Petkov1272a432011-11-10 15:53:37 +0100483 Error error;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500484 EXPECT_CALL(*network_proxy_, Scan(_, _, CellularCapability::kTimeoutScan))
485 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeScan));
486 EXPECT_CALL(*this, TestCallback(IsSuccess()));
Darin Petkov721ac932011-11-16 15:43:09 +0100487 capability_->found_networks_.resize(3, Stringmap());
Darin Petkovb7828b02012-02-03 12:34:30 +0100488 EXPECT_CALL(*device_adaptor_,
489 EmitStringmapsChanged(flimflam::kFoundNetworksProperty,
490 SizeIs2()));
Eric Shienbrood9a245532012-03-07 14:20:39 -0500491 SetNetworkProxy();
492 capability_->Scan(&error, Bind(&CellularCapabilityGSMTest::TestCallback,
493 Unretained(this)));
494 EXPECT_TRUE(error.IsSuccess());
Darin Petkov721ac932011-11-16 15:43:09 +0100495 EXPECT_EQ(2, capability_->found_networks_.size());
Eric Shienbrood9a245532012-03-07 14:20:39 -0500496 EXPECT_EQ(kScanID0,
Darin Petkov721ac932011-11-16 15:43:09 +0100497 capability_->found_networks_[0][flimflam::kNetworkIdProperty]);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500498 EXPECT_EQ(kScanID1,
Darin Petkov721ac932011-11-16 15:43:09 +0100499 capability_->found_networks_[1][flimflam::kNetworkIdProperty]);
Darin Petkov1272a432011-11-10 15:53:37 +0100500}
501
502TEST_F(CellularCapabilityGSMTest, ParseScanResult) {
503 static const char kID[] = "123";
504 static const char kLongName[] = "long name";
505 static const char kShortName[] = "short name";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500506 GSMScanResult result;
Darin Petkov1272a432011-11-10 15:53:37 +0100507 result[CellularCapabilityGSM::kNetworkPropertyStatus] = "1";
508 result[CellularCapabilityGSM::kNetworkPropertyID] = kID;
509 result[CellularCapabilityGSM::kNetworkPropertyLongName] = kLongName;
510 result[CellularCapabilityGSM::kNetworkPropertyShortName] = kShortName;
511 result[CellularCapabilityGSM::kNetworkPropertyAccessTechnology] = "3";
512 result["unknown property"] = "random value";
Darin Petkov721ac932011-11-16 15:43:09 +0100513 Stringmap parsed = capability_->ParseScanResult(result);
Darin Petkov1272a432011-11-10 15:53:37 +0100514 EXPECT_EQ(5, parsed.size());
515 EXPECT_EQ("available", parsed[flimflam::kStatusProperty]);
516 EXPECT_EQ(kID, parsed[flimflam::kNetworkIdProperty]);
517 EXPECT_EQ(kLongName, parsed[flimflam::kLongNameProperty]);
518 EXPECT_EQ(kShortName, parsed[flimflam::kShortNameProperty]);
519 EXPECT_EQ(flimflam::kNetworkTechnologyEdge,
520 parsed[flimflam::kTechnologyProperty]);
521}
522
523TEST_F(CellularCapabilityGSMTest, ParseScanResultProviderLookup) {
524 InitProviderDB();
525 static const char kID[] = "310210";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500526 GSMScanResult result;
Darin Petkov1272a432011-11-10 15:53:37 +0100527 result[CellularCapabilityGSM::kNetworkPropertyID] = kID;
Darin Petkov721ac932011-11-16 15:43:09 +0100528 Stringmap parsed = capability_->ParseScanResult(result);
Darin Petkov1272a432011-11-10 15:53:37 +0100529 EXPECT_EQ(2, parsed.size());
530 EXPECT_EQ(kID, parsed[flimflam::kNetworkIdProperty]);
531 EXPECT_EQ("T-Mobile", parsed[flimflam::kLongNameProperty]);
532}
533
Darin Petkovae0c64e2011-11-15 15:50:27 +0100534TEST_F(CellularCapabilityGSMTest, SetAccessTechnology) {
Darin Petkov721ac932011-11-16 15:43:09 +0100535 capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM);
536 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GSM, capability_->access_technology_);
Darin Petkovae0c64e2011-11-15 15:50:27 +0100537 SetService();
Darin Petkovb72cf402011-11-22 14:51:39 +0100538 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME);
Darin Petkov721ac932011-11-16 15:43:09 +0100539 capability_->SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS);
540 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_GPRS, capability_->access_technology_);
Darin Petkovae0c64e2011-11-15 15:50:27 +0100541 EXPECT_EQ(flimflam::kNetworkTechnologyGprs,
Darin Petkovb72cf402011-11-22 14:51:39 +0100542 cellular_->service()->network_technology());
Darin Petkovae0c64e2011-11-15 15:50:27 +0100543}
544
545TEST_F(CellularCapabilityGSMTest, UpdateOperatorInfo) {
546 static const char kOperatorName[] = "Swisscom";
547 InitProviderDB();
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100548 capability_->serving_operator_.SetCode("22801");
Darin Petkovae0c64e2011-11-15 15:50:27 +0100549 SetService();
Darin Petkov721ac932011-11-16 15:43:09 +0100550 capability_->UpdateOperatorInfo();
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100551 EXPECT_EQ(kOperatorName, capability_->serving_operator_.GetName());
552 EXPECT_EQ("ch", capability_->serving_operator_.GetCountry());
Darin Petkovae0c64e2011-11-15 15:50:27 +0100553 EXPECT_EQ(kOperatorName, cellular_->service()->serving_operator().GetName());
554}
555
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100556TEST_F(CellularCapabilityGSMTest, UpdateStatus) {
557 InitProviderDB();
558 DBusPropertiesMap props;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500559 capability_->imsi_ = "310240123456789";
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400560 props[CellularCapability::kModemPropertyIMSI].writer().append_string("");
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100561 capability_->UpdateStatus(props);
562 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
563}
564
565TEST_F(CellularCapabilityGSMTest, SetHomeProvider) {
566 static const char kCountry[] = "us";
567 static const char kCode[] = "310160";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500568 capability_->imsi_ = "310240123456789";
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100569
570 capability_->SetHomeProvider(); // No mobile provider DB available.
571 EXPECT_TRUE(cellular_->home_provider().GetName().empty());
572 EXPECT_TRUE(cellular_->home_provider().GetCountry().empty());
573 EXPECT_TRUE(cellular_->home_provider().GetCode().empty());
574
575 InitProviderDB();
576 capability_->SetHomeProvider();
577 EXPECT_EQ("T-Mobile", cellular_->home_provider().GetName());
578 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
579 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
Darin Petkov3cfbf212011-11-21 16:02:09 +0100580 EXPECT_EQ(4, capability_->apn_list_.size());
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100581
582 Cellular::Operator oper;
583 cellular_->set_home_provider(oper);
584 capability_->spn_ = kTestCarrier;
585 capability_->SetHomeProvider();
586 EXPECT_EQ(kTestCarrier, cellular_->home_provider().GetName());
587 EXPECT_EQ(kCountry, cellular_->home_provider().GetCountry());
588 EXPECT_EQ(kCode, cellular_->home_provider().GetCode());
589}
590
Darin Petkov3cfbf212011-11-21 16:02:09 +0100591namespace {
592
593MATCHER(SizeIs4, "") {
594 return arg.size() == 4;
595}
596
597} // namespace
598
599TEST_F(CellularCapabilityGSMTest, InitAPNList) {
600 InitProviderDB();
601 capability_->home_provider_ =
602 mobile_provider_lookup_by_name(cellular_->provider_db(), "T-Mobile");
603 ASSERT_TRUE(capability_->home_provider_);
604 EXPECT_EQ(0, capability_->apn_list_.size());
605 EXPECT_CALL(*device_adaptor_,
606 EmitStringmapsChanged(flimflam::kCellularApnListProperty,
607 SizeIs4()));
608 capability_->InitAPNList();
609 EXPECT_EQ(4, capability_->apn_list_.size());
610 EXPECT_EQ("wap.voicestream.com",
611 capability_->apn_list_[1][flimflam::kApnProperty]);
612 EXPECT_EQ("Web2Go/t-zones",
613 capability_->apn_list_[1][flimflam::kApnNameProperty]);
614}
615
Darin Petkov20c13ec2011-11-09 15:07:15 +0100616TEST_F(CellularCapabilityGSMTest, GetNetworkTechnologyString) {
Darin Petkov721ac932011-11-16 15:43:09 +0100617 EXPECT_EQ("", capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100618 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM);
Darin Petkov20c13ec2011-11-09 15:07:15 +0100619 EXPECT_EQ(flimflam::kNetworkTechnologyGsm,
Darin Petkov721ac932011-11-16 15:43:09 +0100620 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100621 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT);
622 EXPECT_EQ(flimflam::kNetworkTechnologyGsm,
Darin Petkov721ac932011-11-16 15:43:09 +0100623 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100624 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_GPRS);
625 EXPECT_EQ(flimflam::kNetworkTechnologyGprs,
Darin Petkov721ac932011-11-16 15:43:09 +0100626 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100627 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_EDGE);
628 EXPECT_EQ(flimflam::kNetworkTechnologyEdge,
Darin Petkov721ac932011-11-16 15:43:09 +0100629 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100630 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_UMTS);
631 EXPECT_EQ(flimflam::kNetworkTechnologyUmts,
Darin Petkov721ac932011-11-16 15:43:09 +0100632 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100633 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSDPA);
634 EXPECT_EQ(flimflam::kNetworkTechnologyHspa,
Darin Petkov721ac932011-11-16 15:43:09 +0100635 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100636 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSUPA);
637 EXPECT_EQ(flimflam::kNetworkTechnologyHspa,
Darin Petkov721ac932011-11-16 15:43:09 +0100638 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100639 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA);
640 EXPECT_EQ(flimflam::kNetworkTechnologyHspa,
Darin Petkov721ac932011-11-16 15:43:09 +0100641 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100642 SetAccessTechnology(MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS);
643 EXPECT_EQ(flimflam::kNetworkTechnologyHspaPlus,
Darin Petkov721ac932011-11-16 15:43:09 +0100644 capability_->GetNetworkTechnologyString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100645}
646
647TEST_F(CellularCapabilityGSMTest, GetRoamingStateString) {
648 EXPECT_EQ(flimflam::kRoamingStateUnknown,
Darin Petkov721ac932011-11-16 15:43:09 +0100649 capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100650 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_HOME);
651 EXPECT_EQ(flimflam::kRoamingStateHome,
Darin Petkov721ac932011-11-16 15:43:09 +0100652 capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100653 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING);
654 EXPECT_EQ(flimflam::kRoamingStateRoaming,
Darin Petkov721ac932011-11-16 15:43:09 +0100655 capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100656 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING);
657 EXPECT_EQ(flimflam::kRoamingStateUnknown,
Darin Petkov721ac932011-11-16 15:43:09 +0100658 capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100659 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED);
660 EXPECT_EQ(flimflam::kRoamingStateUnknown,
Darin Petkov721ac932011-11-16 15:43:09 +0100661 capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100662 SetRegistrationState(MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE);
663 EXPECT_EQ(flimflam::kRoamingStateUnknown,
Darin Petkov721ac932011-11-16 15:43:09 +0100664 capability_->GetRoamingStateString());
Darin Petkov20c13ec2011-11-09 15:07:15 +0100665}
666
Darin Petkovac635a82012-01-10 16:51:58 +0100667TEST_F(CellularCapabilityGSMTest, CreateFriendlyServiceName) {
668 CellularCapabilityGSM::friendly_service_name_id_ = 0;
669 EXPECT_EQ("GSMNetwork0", capability_->CreateFriendlyServiceName());
670 EXPECT_EQ("GSMNetwork1", capability_->CreateFriendlyServiceName());
671 capability_->serving_operator_.SetCode("1234");
672 EXPECT_EQ("cellular_1234", capability_->CreateFriendlyServiceName());
673 static const char kTestCarrier[] = "A GSM Carrier";
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500674 capability_->carrier_ = kTestCarrier;
Darin Petkovac635a82012-01-10 16:51:58 +0100675 EXPECT_EQ(kTestCarrier, capability_->CreateFriendlyServiceName());
676 static const char kTestOperator[] = "A GSM Operator";
677 capability_->serving_operator_.SetName(kTestOperator);
678 EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName());
679 static const char kHomeProvider[] = "The GSM Home Provider";
680 cellular_->home_provider_.SetName(kHomeProvider);
681 EXPECT_EQ(kTestOperator, capability_->CreateFriendlyServiceName());
682 capability_->registration_state_ = MM_MODEM_GSM_NETWORK_REG_STATUS_HOME;
683 EXPECT_EQ(kHomeProvider, capability_->CreateFriendlyServiceName());
684}
685
Darin Petkov31332412012-01-28 01:50:02 +0100686TEST_F(CellularCapabilityGSMTest, SetStorageIdentifier) {
687 SetService();
688 capability_->OnServiceCreated();
Darin Petkovdd3e8662012-02-03 13:16:20 +0100689 EXPECT_EQ(string(flimflam::kTypeCellular) + "_" + kAddress + "_" +
Darin Petkov31332412012-01-28 01:50:02 +0100690 cellular_->service()->friendly_name(),
691 cellular_->service()->GetStorageIdentifier());
692 capability_->imsi_ = kIMSI;
693 capability_->OnServiceCreated();
Darin Petkovdd3e8662012-02-03 13:16:20 +0100694 EXPECT_EQ(string(flimflam::kTypeCellular) + "_" + kAddress + "_" + kIMSI,
Darin Petkov31332412012-01-28 01:50:02 +0100695 cellular_->service()->GetStorageIdentifier());
696}
697
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400698TEST_F(CellularCapabilityGSMTest, OnDBusPropertiesChanged) {
Darin Petkov63138a92012-02-06 14:09:15 +0100699 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_);
700 EXPECT_FALSE(capability_->sim_lock_status_.enabled);
701 EXPECT_EQ("", capability_->sim_lock_status_.lock_type);
702 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
703 DBusPropertiesMap props;
704 static const char kLockType[] = "sim-pin";
705 const int kRetries = 3;
706 props[CellularCapabilityGSM::kPropertyAccessTechnology].writer().
707 append_uint32(MM_MODEM_GSM_ACCESS_TECH_EDGE);
708 props[CellularCapabilityGSM::kPropertyEnabledFacilityLocks].writer().
709 append_uint32(MM_MODEM_GSM_FACILITY_SIM);
710 props[CellularCapabilityGSM::kPropertyUnlockRequired].writer().append_string(
711 kLockType);
712 props[CellularCapabilityGSM::kPropertyUnlockRetries].writer().append_uint32(
713 kRetries);
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400714 // Call with the 'wrong' interface and nothing should change.
715 capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_INTERFACE, props,
716 vector<string>());
717 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN, capability_->access_technology_);
718 EXPECT_FALSE(capability_->sim_lock_status_.enabled);
719 EXPECT_EQ("", capability_->sim_lock_status_.lock_type);
720 EXPECT_EQ(0, capability_->sim_lock_status_.retries_left);
721
722 // Call with the right interface and expect changes.
Darin Petkov63138a92012-02-06 14:09:15 +0100723 EXPECT_CALL(*device_adaptor_,
724 EmitKeyValueStoreChanged(flimflam::kSIMLockStatusProperty, _));
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400725 capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_NETWORK_INTERFACE, props,
Jason Glasgow4c0724a2012-04-17 15:47:40 -0400726 vector<string>());
Darin Petkov63138a92012-02-06 14:09:15 +0100727 EXPECT_EQ(MM_MODEM_GSM_ACCESS_TECH_EDGE, capability_->access_technology_);
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400728 capability_->OnDBusPropertiesChanged(MM_MODEM_GSM_CARD_INTERFACE, props,
729 vector<string>());
Darin Petkov63138a92012-02-06 14:09:15 +0100730 EXPECT_TRUE(capability_->sim_lock_status_.enabled);
731 EXPECT_EQ(kLockType, capability_->sim_lock_status_.lock_type);
732 EXPECT_EQ(kRetries, capability_->sim_lock_status_.retries_left);
733}
734
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400735TEST_F(CellularCapabilityGSMTest, SetupApnTryList) {
736 static const string kTmobileApn("epc.tmobile.com");
737 static const string kLastGoodApn("remembered.apn");
738 static const string kLastGoodUsername("remembered.user");
739 static const string kSuppliedApn("my.apn");
740
741 SetService();
742 capability_->imsi_ = "310240123456789";
743 InitProviderDB();
744 capability_->SetHomeProvider();
745 DBusPropertiesMap props;
746 capability_->SetupConnectProperties(&props);
747 EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end());
748 EXPECT_EQ(kTmobileApn, props[flimflam::kApnProperty].reader().get_string());
749
750 ProfileRefPtr profile(new NiceMock<MockProfile>(
751 &control_, reinterpret_cast<Manager *>(NULL)));
752 cellular_->service()->set_profile(profile);
753 Stringmap apn_info;
754 apn_info[flimflam::kApnProperty] = kLastGoodApn;
755 apn_info[flimflam::kApnUsernameProperty] = kLastGoodUsername;
756 cellular_->service()->SetLastGoodApn(apn_info);
757 props.clear();
758 EXPECT_TRUE(props.find(flimflam::kApnProperty) == props.end());
759 capability_->SetupConnectProperties(&props);
760 // We expect the list to contain the last good APN, plus
761 // the 4 APNs from the mobile provider info database.
762 EXPECT_EQ(5, capability_->apn_try_list_.size());
763 EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end());
764 EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string());
765 EXPECT_FALSE(props.find(flimflam::kApnUsernameProperty) == props.end());
766 EXPECT_EQ(kLastGoodUsername,
767 props[flimflam::kApnUsernameProperty].reader().get_string());
768
769 Error error;
770 apn_info.clear();
771 props.clear();
772 apn_info[flimflam::kApnProperty] = kSuppliedApn;
773 // Setting the APN has the side effect of clearing the LastGoodApn,
774 // so the try list will have 5 elements, with the first one being
775 // the supplied APN.
776 cellular_->service()->SetApn(apn_info, &error);
777 EXPECT_TRUE(props.find(flimflam::kApnProperty) == props.end());
778 capability_->SetupConnectProperties(&props);
779 EXPECT_EQ(5, capability_->apn_try_list_.size());
780 EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end());
781 EXPECT_EQ(kSuppliedApn, props[flimflam::kApnProperty].reader().get_string());
782
783 apn_info.clear();
784 props.clear();
785 apn_info[flimflam::kApnProperty] = kLastGoodApn;
786 apn_info[flimflam::kApnUsernameProperty] = kLastGoodUsername;
787 // Now when LastGoodAPN is set, it will be the one selected.
788 cellular_->service()->SetLastGoodApn(apn_info);
789 EXPECT_TRUE(props.find(flimflam::kApnProperty) == props.end());
790 capability_->SetupConnectProperties(&props);
791 // We expect the list to contain the last good APN, plus
792 // the user-supplied APN, plus the 4 APNs from the mobile
793 // provider info database.
794 EXPECT_EQ(6, capability_->apn_try_list_.size());
795 EXPECT_FALSE(props.find(flimflam::kApnProperty) == props.end());
796 EXPECT_EQ(kLastGoodApn, props[flimflam::kApnProperty].reader().get_string());
797 EXPECT_FALSE(props.find(flimflam::kApnUsernameProperty) == props.end());
798 EXPECT_EQ(kLastGoodUsername,
799 props[flimflam::kApnUsernameProperty].reader().get_string());
800}
801
Thieu Le923006b2012-04-05 16:32:58 -0700802TEST_F(CellularCapabilityGSMTest, StartModemSuccess) {
803 SetupCommonStartModemExpectations();
804 EXPECT_CALL(*card_proxy_,
805 GetSPN(_, _, CellularCapability::kTimeoutDefault))
806 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN));
807 EXPECT_CALL(*card_proxy_,
808 GetMSISDN(_, _, CellularCapability::kTimeoutDefault))
809 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN));
810 SetProxyFactory();
811
812 Error error;
813 capability_->StartModem(
814 &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this)));
815 dispatcher_.DispatchPendingEvents();
816}
817
818TEST_F(CellularCapabilityGSMTest, StartModemGetSPNFail) {
819 SetupCommonStartModemExpectations();
820 EXPECT_CALL(*card_proxy_,
821 GetSPN(_, _, CellularCapability::kTimeoutDefault))
822 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPNFail));
823 EXPECT_CALL(*card_proxy_,
824 GetMSISDN(_, _, CellularCapability::kTimeoutDefault))
825 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDN));
826 SetProxyFactory();
827
828 Error error;
829 capability_->StartModem(
830 &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this)));
831 dispatcher_.DispatchPendingEvents();
832}
833
834TEST_F(CellularCapabilityGSMTest, StartModemGetMSISDNFail) {
835 SetupCommonStartModemExpectations();
836 EXPECT_CALL(*card_proxy_,
837 GetSPN(_, _, CellularCapability::kTimeoutDefault))
838 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetSPN));
839 EXPECT_CALL(*card_proxy_,
840 GetMSISDN(_, _, CellularCapability::kTimeoutDefault))
841 .WillOnce(Invoke(this, &CellularCapabilityGSMTest::InvokeGetMSISDNFail));
842 SetProxyFactory();
843
844 Error error;
845 capability_->StartModem(
846 &error, Bind(&CellularCapabilityGSMTest::TestCallback, Unretained(this)));
847 dispatcher_.DispatchPendingEvents();
848}
849
Darin Petkovb05315f2011-11-07 10:14:25 +0100850} // namespace shill