Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 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_cdma.h" |
| 6 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 7 | #include <base/bind.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 8 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 9 | #include <gtest/gtest.h> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 10 | #include <mm/mm-modem.h> |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 11 | |
| 12 | #include "shill/cellular.h" |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 13 | #include "shill/cellular_service.h" |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 14 | #include "shill/error.h" |
| 15 | #include "shill/event_dispatcher.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 16 | #include "shill/mock_adaptors.h" |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 17 | #include "shill/mock_cellular.h" |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 18 | #include "shill/mock_modem_cdma_proxy.h" |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 19 | #include "shill/mock_modem_info.h" |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 20 | #include "shill/mock_modem_proxy.h" |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 21 | #include "shill/proxy_factory.h" |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 22 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 23 | using base::Bind; |
| 24 | using base::Unretained; |
| 25 | using std::string; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 26 | using testing::_; |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 27 | using testing::InSequence; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 28 | using testing::Invoke; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 29 | using testing::Return; |
| 30 | |
| 31 | namespace shill { |
| 32 | |
| 33 | class CellularCapabilityCDMATest : public testing::Test { |
| 34 | public: |
| 35 | CellularCapabilityCDMATest() |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 36 | : modem_info_(NULL, &dispatcher_, NULL, NULL, NULL), |
| 37 | cellular_(new MockCellular(&modem_info_, |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 38 | "", |
| 39 | "", |
| 40 | 0, |
| 41 | Cellular::kTypeCDMA, |
| 42 | "", |
| 43 | "", |
| 44 | "", |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 45 | ProxyFactory::GetInstance())), |
| 46 | classic_proxy_(new MockModemProxy()), |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 47 | proxy_(new MockModemCDMAProxy()), |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 48 | capability_(NULL) { |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 49 | modem_info_.metrics()->RegisterDevice(cellular_->interface_index(), |
| 50 | Technology::kCellular); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 51 | } |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 52 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 53 | virtual ~CellularCapabilityCDMATest() { |
| 54 | cellular_->service_ = NULL; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 55 | capability_ = NULL; |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 58 | virtual void SetUp() { |
| 59 | capability_ = |
| 60 | dynamic_cast<CellularCapabilityCDMA *>(cellular_->capability_.get()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 63 | void InvokeActivate(const string &carrier, Error *error, |
| 64 | const ActivationResultCallback &callback, |
| 65 | int timeout) { |
| 66 | callback.Run(MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR, Error()); |
| 67 | } |
| 68 | void InvokeActivateError(const string &carrier, Error *error, |
| 69 | const ActivationResultCallback &callback, |
| 70 | int timeout) { |
| 71 | callback.Run(MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL, Error()); |
| 72 | } |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 73 | void InvokeDisconnect(Error *error, |
| 74 | const ResultCallback &callback, |
| 75 | int timeout) { |
| 76 | callback.Run(Error()); |
| 77 | } |
| 78 | void InvokeDisconnectError(Error *error, |
| 79 | const ResultCallback &callback, |
| 80 | int timeout) { |
| 81 | Error err(Error::kOperationFailed); |
| 82 | callback.Run(err); |
| 83 | } |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 84 | void InvokeGetSignalQuality(Error *error, |
| 85 | const SignalQualityCallback &callback, |
| 86 | int timeout) { |
| 87 | callback.Run(kStrength, Error()); |
| 88 | } |
| 89 | void InvokeGetRegistrationState(Error *error, |
| 90 | const RegistrationStateCallback &callback, |
| 91 | int timeout) { |
| 92 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED, |
| 93 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 94 | Error()); |
| 95 | } |
| 96 | |
| 97 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 98 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 99 | protected: |
| 100 | static const char kMEID[]; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 101 | static const char kTestCarrier[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 102 | static const unsigned int kStrength; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 103 | |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 104 | bool IsActivationStarting() const { |
| 105 | return capability_->activation_starting_; |
| 106 | } |
| 107 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 108 | void SetRegistrationStateEVDO(uint32 state) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 109 | capability_->registration_state_evdo_ = state; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | void SetRegistrationState1x(uint32 state) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 113 | capability_->registration_state_1x_ = state; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 116 | void SetProxy() { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 117 | capability_->proxy_.reset(proxy_.release()); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 118 | capability_->CellularCapabilityClassic::proxy_.reset( |
| 119 | classic_proxy_.release()); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void SetService() { |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 123 | cellular_->service_ = new CellularService(&modem_info_, cellular_); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 126 | void SetDeviceState(Cellular::State state) { |
| 127 | cellular_->state_ = state; |
| 128 | } |
| 129 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 130 | EventDispatcher dispatcher_; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 131 | MockModemInfo modem_info_; |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 132 | scoped_refptr<MockCellular> cellular_; |
| 133 | scoped_ptr<MockModemProxy> classic_proxy_; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 134 | scoped_ptr<MockModemCDMAProxy> proxy_; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 135 | CellularCapabilityCDMA *capability_; // Owned by |cellular_|. |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | const char CellularCapabilityCDMATest::kMEID[] = "D1234567EF8901"; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 139 | const char CellularCapabilityCDMATest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 140 | const unsigned int CellularCapabilityCDMATest::kStrength = 90; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 141 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 142 | TEST_F(CellularCapabilityCDMATest, PropertyStore) { |
| 143 | EXPECT_TRUE(cellular_->store().Contains(flimflam::kPRLVersionProperty)); |
| 144 | } |
| 145 | |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 146 | TEST_F(CellularCapabilityCDMATest, Activate) { |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 147 | SetDeviceState(Cellular::kStateEnabled); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 148 | EXPECT_CALL(*proxy_, Activate(kTestCarrier, _, _, |
| 149 | CellularCapability::kTimeoutActivate)) |
| 150 | .WillOnce(Invoke(this, |
| 151 | &CellularCapabilityCDMATest::InvokeActivate)); |
| 152 | EXPECT_CALL(*this, TestCallback(_)); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 153 | SetProxy(); |
| 154 | SetService(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 155 | capability_->Activate(kTestCarrier, NULL, |
| 156 | Bind(&CellularCapabilityCDMATest::TestCallback, Unretained(this))); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 157 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 158 | capability_->activation_state()); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 159 | EXPECT_EQ(flimflam::kActivationStateActivating, |
| 160 | cellular_->service()->activation_state()); |
| 161 | EXPECT_EQ("", cellular_->service()->error()); |
| 162 | } |
| 163 | |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 164 | TEST_F(CellularCapabilityCDMATest, ActivateWhileConnected) { |
| 165 | SetDeviceState(Cellular::kStateConnected); |
| 166 | { |
| 167 | InSequence dummy; |
| 168 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 169 | EXPECT_CALL(*cellular_, Disconnect(_)); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 170 | EXPECT_CALL(*proxy_, Activate(kTestCarrier, _, _, |
| 171 | CellularCapability::kTimeoutActivate)) |
| 172 | .WillOnce(Invoke(this, |
| 173 | &CellularCapabilityCDMATest::InvokeActivate)); |
| 174 | EXPECT_CALL(*this, TestCallback(_)); |
| 175 | } |
| 176 | SetProxy(); |
| 177 | SetService(); |
| 178 | Error error; |
| 179 | capability_->Activate(kTestCarrier, &error, |
| 180 | Bind(&CellularCapabilityCDMATest::TestCallback, Unretained(this))); |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 181 | // So now we should be "activating" while we wait for a disconnect. |
| 182 | EXPECT_TRUE(IsActivationStarting()); |
| 183 | EXPECT_TRUE(capability_->IsActivating()); |
| 184 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED, |
| 185 | capability_->activation_state()); |
| 186 | // Simulate a disconnect. |
| 187 | SetDeviceState(Cellular::kStateRegistered); |
| 188 | capability_->DisconnectCleanup(); |
| 189 | // Now the modem is actually activating. |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 190 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING, |
| 191 | capability_->activation_state()); |
| 192 | EXPECT_EQ(flimflam::kActivationStateActivating, |
| 193 | cellular_->service()->activation_state()); |
| 194 | EXPECT_EQ("", cellular_->service()->error()); |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 195 | EXPECT_FALSE(IsActivationStarting()); |
| 196 | EXPECT_TRUE(capability_->IsActivating()); |
| 197 | } |
| 198 | |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 199 | TEST_F(CellularCapabilityCDMATest, ActivateWhileConnectedButFail) { |
| 200 | SetDeviceState(Cellular::kStateConnected); |
| 201 | { |
| 202 | InSequence dummy; |
| 203 | |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 204 | EXPECT_CALL(*cellular_, Disconnect(_)); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 205 | EXPECT_CALL(*proxy_, Activate(kTestCarrier, _, _, |
| 206 | CellularCapability::kTimeoutActivate)) |
| 207 | .Times(0); |
| 208 | } |
| 209 | SetProxy(); |
| 210 | SetService(); |
| 211 | Error error; |
| 212 | capability_->Activate(kTestCarrier, &error, |
| 213 | Bind(&CellularCapabilityCDMATest::TestCallback, Unretained(this))); |
Christopher Wiley | 8a46890 | 2012-11-30 11:52:38 -0800 | [diff] [blame] | 214 | // So now we should be "activating" while we wait for a disconnect. |
| 215 | EXPECT_TRUE(IsActivationStarting()); |
| 216 | EXPECT_TRUE(capability_->IsActivating()); |
| 217 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED, |
| 218 | capability_->activation_state()); |
| 219 | // Similulate a failed disconnect (the modem is still connected!). |
| 220 | capability_->DisconnectCleanup(); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 221 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED, |
| 222 | capability_->activation_state()); |
| 223 | EXPECT_EQ(flimflam::kActivationStateNotActivated, |
| 224 | cellular_->service()->activation_state()); |
| 225 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 226 | cellular_->service()->error()); |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 227 | EXPECT_FALSE(IsActivationStarting()); |
| 228 | EXPECT_FALSE(capability_->IsActivating()); |
Christopher Wiley | 7d0953e | 2012-11-16 00:37:10 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 231 | TEST_F(CellularCapabilityCDMATest, ActivateError) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 232 | SetDeviceState(Cellular::kStateEnabled); |
| 233 | EXPECT_CALL(*proxy_, Activate(kTestCarrier, _, _, |
| 234 | CellularCapability::kTimeoutActivate)) |
| 235 | .WillOnce(Invoke(this, |
| 236 | &CellularCapabilityCDMATest::InvokeActivateError)); |
| 237 | EXPECT_CALL(*this, TestCallback(_)); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 238 | SetProxy(); |
| 239 | SetService(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 240 | capability_->Activate(kTestCarrier, NULL, |
| 241 | Bind(&CellularCapabilityCDMATest::TestCallback, Unretained(this))); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 242 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 243 | capability_->activation_state()); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 244 | EXPECT_EQ(flimflam::kActivationStateNotActivated, |
| 245 | cellular_->service()->activation_state()); |
| 246 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 247 | cellular_->service()->error()); |
| 248 | } |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 249 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 250 | TEST_F(CellularCapabilityCDMATest, GetActivationStateString) { |
| 251 | EXPECT_EQ(flimflam::kActivationStateActivated, |
| 252 | CellularCapabilityCDMA::GetActivationStateString( |
| 253 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED)); |
| 254 | EXPECT_EQ(flimflam::kActivationStateActivating, |
| 255 | CellularCapabilityCDMA::GetActivationStateString( |
| 256 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING)); |
| 257 | EXPECT_EQ(flimflam::kActivationStateNotActivated, |
| 258 | CellularCapabilityCDMA::GetActivationStateString( |
| 259 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED)); |
| 260 | EXPECT_EQ(flimflam::kActivationStatePartiallyActivated, |
| 261 | CellularCapabilityCDMA::GetActivationStateString( |
| 262 | MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED)); |
| 263 | EXPECT_EQ(flimflam::kActivationStateUnknown, |
| 264 | CellularCapabilityCDMA::GetActivationStateString(123)); |
| 265 | } |
| 266 | |
| 267 | TEST_F(CellularCapabilityCDMATest, GetActivationErrorString) { |
| 268 | EXPECT_EQ(flimflam::kErrorNeedEvdo, |
| 269 | CellularCapabilityCDMA::GetActivationErrorString( |
| 270 | MM_MODEM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE)); |
| 271 | EXPECT_EQ(flimflam::kErrorNeedHomeNetwork, |
| 272 | CellularCapabilityCDMA::GetActivationErrorString( |
| 273 | MM_MODEM_CDMA_ACTIVATION_ERROR_ROAMING)); |
| 274 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 275 | CellularCapabilityCDMA::GetActivationErrorString( |
| 276 | MM_MODEM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT)); |
| 277 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 278 | CellularCapabilityCDMA::GetActivationErrorString( |
| 279 | MM_MODEM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED)); |
| 280 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 281 | CellularCapabilityCDMA::GetActivationErrorString( |
| 282 | MM_MODEM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED)); |
| 283 | EXPECT_EQ("", |
| 284 | CellularCapabilityCDMA::GetActivationErrorString( |
| 285 | MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR)); |
| 286 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 287 | CellularCapabilityCDMA::GetActivationErrorString( |
| 288 | MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL)); |
| 289 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 290 | CellularCapabilityCDMA::GetActivationErrorString(1234)); |
| 291 | } |
| 292 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 293 | TEST_F(CellularCapabilityCDMATest, IsRegisteredEVDO) { |
| 294 | EXPECT_FALSE(capability_->IsRegistered()); |
| 295 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 296 | EXPECT_FALSE(capability_->IsRegistered()); |
| 297 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 298 | EXPECT_TRUE(capability_->IsRegistered()); |
| 299 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 300 | EXPECT_TRUE(capability_->IsRegistered()); |
| 301 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 302 | EXPECT_TRUE(capability_->IsRegistered()); |
| 303 | } |
| 304 | |
| 305 | TEST_F(CellularCapabilityCDMATest, IsRegistered1x) { |
| 306 | EXPECT_FALSE(capability_->IsRegistered()); |
| 307 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 308 | EXPECT_FALSE(capability_->IsRegistered()); |
| 309 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 310 | EXPECT_TRUE(capability_->IsRegistered()); |
| 311 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 312 | EXPECT_TRUE(capability_->IsRegistered()); |
| 313 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 314 | EXPECT_TRUE(capability_->IsRegistered()); |
| 315 | } |
| 316 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 317 | TEST_F(CellularCapabilityCDMATest, GetNetworkTechnologyString) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 318 | EXPECT_EQ("", capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 319 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 320 | EXPECT_EQ(flimflam::kNetworkTechnologyEvdo, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 321 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 322 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 323 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 324 | EXPECT_EQ(flimflam::kNetworkTechnology1Xrtt, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 325 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | TEST_F(CellularCapabilityCDMATest, GetRoamingStateString) { |
| 329 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 330 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 331 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 332 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 333 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 334 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 335 | EXPECT_EQ(flimflam::kRoamingStateHome, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 336 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 337 | EXPECT_EQ(flimflam::kRoamingStateRoaming, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 338 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 339 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 340 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 341 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 342 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 343 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 344 | EXPECT_EQ(flimflam::kRoamingStateHome, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 345 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 346 | EXPECT_EQ(flimflam::kRoamingStateRoaming, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 347 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 350 | TEST_F(CellularCapabilityCDMATest, GetSignalQuality) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 351 | EXPECT_CALL(*proxy_, |
| 352 | GetSignalQuality(NULL, _, CellularCapability::kTimeoutDefault)) |
| 353 | .WillOnce(Invoke(this, |
| 354 | &CellularCapabilityCDMATest::InvokeGetSignalQuality)); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 355 | SetProxy(); |
| 356 | SetService(); |
| 357 | EXPECT_EQ(0, cellular_->service()->strength()); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 358 | capability_->GetSignalQuality(); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 359 | EXPECT_EQ(kStrength, cellular_->service()->strength()); |
| 360 | } |
| 361 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 362 | TEST_F(CellularCapabilityCDMATest, GetRegistrationState) { |
| 363 | EXPECT_FALSE(cellular_->service().get()); |
| 364 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 365 | capability_->registration_state_1x()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 366 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 367 | capability_->registration_state_evdo()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 368 | EXPECT_CALL(*proxy_, |
| 369 | GetRegistrationState(NULL, _, |
| 370 | CellularCapability::kTimeoutDefault)) |
| 371 | .WillOnce(Invoke( |
| 372 | this, |
| 373 | &CellularCapabilityCDMATest::InvokeGetRegistrationState)); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 374 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 375 | cellular_->state_ = Cellular::kStateEnabled; |
Prathmesh Prabhu | 27526f1 | 2013-03-25 19:42:18 -0700 | [diff] [blame] | 376 | EXPECT_CALL(*modem_info_.mock_manager(), RegisterService(_)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 377 | capability_->GetRegistrationState(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 378 | dispatcher_.DispatchPendingEvents(); |
| 379 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 380 | capability_->registration_state_1x()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 381 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 382 | capability_->registration_state_evdo()); |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 383 | EXPECT_TRUE(cellular_->service().get()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 384 | } |
| 385 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 386 | TEST_F(CellularCapabilityCDMATest, CreateFriendlyServiceName) { |
| 387 | CellularCapabilityCDMA::friendly_service_name_id_ = 0; |
| 388 | EXPECT_EQ("CDMANetwork0", capability_->CreateFriendlyServiceName()); |
| 389 | EXPECT_EQ("CDMANetwork1", capability_->CreateFriendlyServiceName()); |
| 390 | static const char kTestCarrier[] = "A Carrier"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 391 | capability_->carrier_ = kTestCarrier; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 392 | EXPECT_EQ(kTestCarrier, capability_->CreateFriendlyServiceName()); |
| 393 | } |
| 394 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 395 | } // namespace shill |