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