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" |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 17 | #include "shill/mock_glib.h" |
| 18 | #include "shill/mock_manager.h" |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 19 | #include "shill/mock_metrics.h" |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 20 | #include "shill/mock_modem_cdma_proxy.h" |
| 21 | #include "shill/nice_mock_control.h" |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 22 | #include "shill/proxy_factory.h" |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 23 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 24 | using base::Bind; |
| 25 | using base::Unretained; |
| 26 | using std::string; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 27 | using testing::_; |
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() |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 36 | : manager_(&control_, &dispatcher_, &metrics_, &glib_), |
| 37 | cellular_(new Cellular(&control_, |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 38 | &dispatcher_, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 39 | &metrics_, |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 40 | &manager_, |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 41 | "", |
| 42 | "", |
| 43 | 0, |
| 44 | Cellular::kTypeCDMA, |
| 45 | "", |
| 46 | "", |
Jason Glasgow | a585fc3 | 2012-06-06 11:04:09 -0400 | [diff] [blame] | 47 | "", |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 48 | NULL, |
Ben Chan | 62028b2 | 2012-11-05 11:20:02 -0800 | [diff] [blame] | 49 | NULL, |
Ben Chan | 3ecdf82 | 2012-08-06 12:29:23 -0700 | [diff] [blame] | 50 | ProxyFactory::GetInstance())), |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 51 | proxy_(new MockModemCDMAProxy()), |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 52 | capability_(NULL) {} |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 53 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 54 | virtual ~CellularCapabilityCDMATest() { |
| 55 | cellular_->service_ = NULL; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 56 | capability_ = NULL; |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 59 | virtual void SetUp() { |
| 60 | capability_ = |
| 61 | dynamic_cast<CellularCapabilityCDMA *>(cellular_->capability_.get()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 64 | void InvokeActivate(const string &carrier, Error *error, |
| 65 | const ActivationResultCallback &callback, |
| 66 | int timeout) { |
| 67 | callback.Run(MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR, Error()); |
| 68 | } |
| 69 | void InvokeActivateError(const string &carrier, Error *error, |
| 70 | const ActivationResultCallback &callback, |
| 71 | int timeout) { |
| 72 | callback.Run(MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL, Error()); |
| 73 | } |
| 74 | void InvokeGetSignalQuality(Error *error, |
| 75 | const SignalQualityCallback &callback, |
| 76 | int timeout) { |
| 77 | callback.Run(kStrength, Error()); |
| 78 | } |
| 79 | void InvokeGetRegistrationState(Error *error, |
| 80 | const RegistrationStateCallback &callback, |
| 81 | int timeout) { |
| 82 | callback.Run(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED, |
| 83 | MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
| 84 | Error()); |
| 85 | } |
| 86 | |
| 87 | MOCK_METHOD1(TestCallback, void(const Error &error)); |
| 88 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 89 | protected: |
| 90 | static const char kMEID[]; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 91 | static const char kTestCarrier[]; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 92 | static const unsigned int kStrength; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 93 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 94 | void SetRegistrationStateEVDO(uint32 state) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 95 | capability_->registration_state_evdo_ = state; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void SetRegistrationState1x(uint32 state) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 99 | capability_->registration_state_1x_ = state; |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 102 | void SetProxy() { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 103 | capability_->proxy_.reset(proxy_.release()); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void SetService() { |
| 107 | cellular_->service_ = new CellularService( |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 108 | &control_, &dispatcher_, &metrics_, &manager_, cellular_); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 111 | void SetDeviceState(Cellular::State state) { |
| 112 | cellular_->state_ = state; |
| 113 | } |
| 114 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 115 | NiceMockControl control_; |
| 116 | EventDispatcher dispatcher_; |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 117 | MockGLib glib_; |
| 118 | MockManager manager_; |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 119 | MockMetrics metrics_; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 120 | CellularRefPtr cellular_; |
| 121 | scoped_ptr<MockModemCDMAProxy> proxy_; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 122 | CellularCapabilityCDMA *capability_; // Owned by |cellular_|. |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | const char CellularCapabilityCDMATest::kMEID[] = "D1234567EF8901"; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 126 | const char CellularCapabilityCDMATest::kTestCarrier[] = "The Cellular Carrier"; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 127 | const unsigned int CellularCapabilityCDMATest::kStrength = 90; |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 128 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 129 | TEST_F(CellularCapabilityCDMATest, PropertyStore) { |
| 130 | EXPECT_TRUE(cellular_->store().Contains(flimflam::kPRLVersionProperty)); |
| 131 | } |
| 132 | |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 133 | TEST_F(CellularCapabilityCDMATest, Activate) { |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 134 | SetDeviceState(Cellular::kStateEnabled); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 135 | EXPECT_CALL(*proxy_, Activate(kTestCarrier, _, _, |
| 136 | CellularCapability::kTimeoutActivate)) |
| 137 | .WillOnce(Invoke(this, |
| 138 | &CellularCapabilityCDMATest::InvokeActivate)); |
| 139 | EXPECT_CALL(*this, TestCallback(_)); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 140 | SetProxy(); |
| 141 | SetService(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 142 | capability_->Activate(kTestCarrier, NULL, |
| 143 | Bind(&CellularCapabilityCDMATest::TestCallback, Unretained(this))); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 144 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 145 | capability_->activation_state()); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 146 | EXPECT_EQ(flimflam::kActivationStateActivating, |
| 147 | cellular_->service()->activation_state()); |
| 148 | EXPECT_EQ("", cellular_->service()->error()); |
| 149 | } |
| 150 | |
| 151 | TEST_F(CellularCapabilityCDMATest, ActivateError) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 152 | SetDeviceState(Cellular::kStateEnabled); |
| 153 | EXPECT_CALL(*proxy_, Activate(kTestCarrier, _, _, |
| 154 | CellularCapability::kTimeoutActivate)) |
| 155 | .WillOnce(Invoke(this, |
| 156 | &CellularCapabilityCDMATest::InvokeActivateError)); |
| 157 | EXPECT_CALL(*this, TestCallback(_)); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 158 | SetProxy(); |
| 159 | SetService(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 160 | capability_->Activate(kTestCarrier, NULL, |
| 161 | Bind(&CellularCapabilityCDMATest::TestCallback, Unretained(this))); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 162 | EXPECT_EQ(MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 163 | capability_->activation_state()); |
Darin Petkov | a3d3be5 | 2011-11-14 21:34:16 +0100 | [diff] [blame] | 164 | EXPECT_EQ(flimflam::kActivationStateNotActivated, |
| 165 | cellular_->service()->activation_state()); |
| 166 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 167 | cellular_->service()->error()); |
| 168 | } |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 169 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 170 | TEST_F(CellularCapabilityCDMATest, GetActivationStateString) { |
| 171 | EXPECT_EQ(flimflam::kActivationStateActivated, |
| 172 | CellularCapabilityCDMA::GetActivationStateString( |
| 173 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED)); |
| 174 | EXPECT_EQ(flimflam::kActivationStateActivating, |
| 175 | CellularCapabilityCDMA::GetActivationStateString( |
| 176 | MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING)); |
| 177 | EXPECT_EQ(flimflam::kActivationStateNotActivated, |
| 178 | CellularCapabilityCDMA::GetActivationStateString( |
| 179 | MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED)); |
| 180 | EXPECT_EQ(flimflam::kActivationStatePartiallyActivated, |
| 181 | CellularCapabilityCDMA::GetActivationStateString( |
| 182 | MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED)); |
| 183 | EXPECT_EQ(flimflam::kActivationStateUnknown, |
| 184 | CellularCapabilityCDMA::GetActivationStateString(123)); |
| 185 | } |
| 186 | |
| 187 | TEST_F(CellularCapabilityCDMATest, GetActivationErrorString) { |
| 188 | EXPECT_EQ(flimflam::kErrorNeedEvdo, |
| 189 | CellularCapabilityCDMA::GetActivationErrorString( |
| 190 | MM_MODEM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE)); |
| 191 | EXPECT_EQ(flimflam::kErrorNeedHomeNetwork, |
| 192 | CellularCapabilityCDMA::GetActivationErrorString( |
| 193 | MM_MODEM_CDMA_ACTIVATION_ERROR_ROAMING)); |
| 194 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 195 | CellularCapabilityCDMA::GetActivationErrorString( |
| 196 | MM_MODEM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT)); |
| 197 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 198 | CellularCapabilityCDMA::GetActivationErrorString( |
| 199 | MM_MODEM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED)); |
| 200 | EXPECT_EQ(flimflam::kErrorOtaspFailed, |
| 201 | CellularCapabilityCDMA::GetActivationErrorString( |
| 202 | MM_MODEM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED)); |
| 203 | EXPECT_EQ("", |
| 204 | CellularCapabilityCDMA::GetActivationErrorString( |
| 205 | MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR)); |
| 206 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 207 | CellularCapabilityCDMA::GetActivationErrorString( |
| 208 | MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL)); |
| 209 | EXPECT_EQ(flimflam::kErrorActivationFailed, |
| 210 | CellularCapabilityCDMA::GetActivationErrorString(1234)); |
| 211 | } |
| 212 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 213 | TEST_F(CellularCapabilityCDMATest, IsRegisteredEVDO) { |
| 214 | EXPECT_FALSE(capability_->IsRegistered()); |
| 215 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 216 | EXPECT_FALSE(capability_->IsRegistered()); |
| 217 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 218 | EXPECT_TRUE(capability_->IsRegistered()); |
| 219 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 220 | EXPECT_TRUE(capability_->IsRegistered()); |
| 221 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 222 | EXPECT_TRUE(capability_->IsRegistered()); |
| 223 | } |
| 224 | |
| 225 | TEST_F(CellularCapabilityCDMATest, IsRegistered1x) { |
| 226 | EXPECT_FALSE(capability_->IsRegistered()); |
| 227 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 228 | EXPECT_FALSE(capability_->IsRegistered()); |
| 229 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 230 | EXPECT_TRUE(capability_->IsRegistered()); |
| 231 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 232 | EXPECT_TRUE(capability_->IsRegistered()); |
| 233 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 234 | EXPECT_TRUE(capability_->IsRegistered()); |
| 235 | } |
| 236 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 237 | TEST_F(CellularCapabilityCDMATest, GetNetworkTechnologyString) { |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 238 | EXPECT_EQ("", capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 239 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 240 | EXPECT_EQ(flimflam::kNetworkTechnologyEvdo, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 241 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 242 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 243 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
| 244 | EXPECT_EQ(flimflam::kNetworkTechnology1Xrtt, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 245 | capability_->GetNetworkTechnologyString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | TEST_F(CellularCapabilityCDMATest, GetRoamingStateString) { |
| 249 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 250 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 251 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 252 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 253 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 254 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 255 | EXPECT_EQ(flimflam::kRoamingStateHome, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 256 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 257 | EXPECT_EQ(flimflam::kRoamingStateRoaming, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 258 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 259 | SetRegistrationStateEVDO(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); |
| 260 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); |
| 261 | EXPECT_EQ(flimflam::kRoamingStateUnknown, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 262 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 263 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_HOME); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 264 | EXPECT_EQ(flimflam::kRoamingStateHome, capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 265 | SetRegistrationState1x(MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING); |
| 266 | EXPECT_EQ(flimflam::kRoamingStateRoaming, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 267 | capability_->GetRoamingStateString()); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 270 | TEST_F(CellularCapabilityCDMATest, GetSignalQuality) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 271 | EXPECT_CALL(*proxy_, |
| 272 | GetSignalQuality(NULL, _, CellularCapability::kTimeoutDefault)) |
| 273 | .WillOnce(Invoke(this, |
| 274 | &CellularCapabilityCDMATest::InvokeGetSignalQuality)); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 275 | SetProxy(); |
| 276 | SetService(); |
| 277 | EXPECT_EQ(0, cellular_->service()->strength()); |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 278 | capability_->GetSignalQuality(); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 279 | EXPECT_EQ(kStrength, cellular_->service()->strength()); |
| 280 | } |
| 281 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 282 | TEST_F(CellularCapabilityCDMATest, GetRegistrationState) { |
| 283 | EXPECT_FALSE(cellular_->service().get()); |
| 284 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 285 | capability_->registration_state_1x()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 286 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 287 | capability_->registration_state_evdo()); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 288 | EXPECT_CALL(*proxy_, |
| 289 | GetRegistrationState(NULL, _, |
| 290 | CellularCapability::kTimeoutDefault)) |
| 291 | .WillOnce(Invoke( |
| 292 | this, |
| 293 | &CellularCapabilityCDMATest::InvokeGetRegistrationState)); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 294 | SetProxy(); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 295 | cellular_->state_ = Cellular::kStateEnabled; |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 296 | EXPECT_CALL(manager_, RegisterService(_)); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 297 | capability_->GetRegistrationState(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 298 | dispatcher_.DispatchPendingEvents(); |
| 299 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 300 | capability_->registration_state_1x()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 301 | EXPECT_EQ(MM_MODEM_CDMA_REGISTRATION_STATE_HOME, |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 302 | capability_->registration_state_evdo()); |
Eric Shienbrood | 04e6358 | 2012-01-19 13:41:12 -0500 | [diff] [blame] | 303 | EXPECT_TRUE(cellular_->service().get()); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 304 | } |
| 305 | |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 306 | TEST_F(CellularCapabilityCDMATest, CreateFriendlyServiceName) { |
| 307 | CellularCapabilityCDMA::friendly_service_name_id_ = 0; |
| 308 | EXPECT_EQ("CDMANetwork0", capability_->CreateFriendlyServiceName()); |
| 309 | EXPECT_EQ("CDMANetwork1", capability_->CreateFriendlyServiceName()); |
| 310 | static const char kTestCarrier[] = "A Carrier"; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 311 | capability_->carrier_ = kTestCarrier; |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 312 | EXPECT_EQ(kTestCarrier, capability_->CreateFriendlyServiceName()); |
| 313 | } |
| 314 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 315 | } // namespace shill |