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