1/* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#define private public 16#define protected public 17 18#include "activating.h" 19#include "active.h" 20#include "apn_manager.h" 21#include "cellular_data_state_machine.h" 22#include "core_manager_inner.h" 23#include "data_connection_manager.h" 24#include "data_connection_params.h" 25#include "data_disconnect_params.h" 26#include "default.h" 27#include "disconnecting.h" 28#include "gtest/gtest.h" 29#include "inactive.h" 30#include "incall_data_state_machine.h" 31#include "mock/mock_sim_manager.h" 32#include "mock/mock_network_search.h" 33#include "tel_event_handler.h" 34#include "telephony_types.h" 35#include "tel_ril_data_parcel.h" 36 37namespace OHOS { 38namespace Telephony { 39using namespace testing::ext; 40using ::testing::_; 41using ::testing::AtLeast; 42using ::testing::DoAll; 43using ::testing::Invoke; 44using ::testing::Mock; 45using ::testing::Return; 46using ::testing::SetArgReferee; 47 48class CellularStateMachineTest : public testing::Test { 49public: 50 CellularStateMachineTest() 51 { 52 mockSimManager = new MockSimManager(); 53 std::shared_ptr<MockSimManager> mockSimManagerPtr(mockSimManager); 54 CoreManagerInner::GetInstance().simManager_ = mockSimManagerPtr; 55 56 mockNetworkSearchManager = new MockNetworkSearchManager(); 57 std::shared_ptr<MockNetworkSearchManager> mockNetworkSearchManagerPtr(mockNetworkSearchManager); 58 CoreManagerInner::GetInstance().networkSearchManager_ = mockNetworkSearchManagerPtr; 59 } 60 static void SetUpTestCase(); 61 static void TearDownTestCase(); 62 void SetUp(); 63 void TearDown(); 64 std::shared_ptr<CellularDataStateMachine> cellularMachine; 65 MockSimManager *mockSimManager; 66 MockNetworkSearchManager *mockNetworkSearchManager; 67}; 68void CellularStateMachineTest::SetUpTestCase() {} 69 70void CellularStateMachineTest::TearDownTestCase() {} 71 72void CellularStateMachineTest::SetUp() {} 73 74void CellularStateMachineTest::TearDown() {} 75 76class IncallDataStateMachineTest : public TelEventHandler { 77public: 78 IncallDataStateMachineTest() : TelEventHandler("IncallDataStateMachineTest") {} 79 ~IncallDataStateMachineTest() = default; 80 std::shared_ptr<IncallDataStateMachine> CreateIncallDataStateMachine(int32_t slotId); 81 82public: 83 std::shared_ptr<IncallDataStateMachine> incallStateMachine_ = nullptr; 84}; 85 86std::shared_ptr<IncallDataStateMachine> IncallDataStateMachineTest::CreateIncallDataStateMachine(int32_t slotId) 87{ 88 if (incallStateMachine_ != nullptr) { 89 return incallStateMachine_; 90 } 91 sptr<ApnManager> apnManager = std::make_unique<ApnManager>().release(); 92 if (apnManager == nullptr) { 93 return nullptr; 94 } 95 incallStateMachine_ = std::make_shared<IncallDataStateMachine>(slotId, 96 std::weak_ptr<TelEventHandler>(std::static_pointer_cast<TelEventHandler>(shared_from_this())), apnManager); 97 return incallStateMachine_; 98} 99 100class CellularMachineTest : public TelEventHandler { 101public: 102 CellularMachineTest() : TelEventHandler("CellularDataStateMachineTest") {} 103 ~CellularMachineTest() = default; 104 std::shared_ptr<CellularDataStateMachine> CreateCellularDataConnect(int32_t slotId); 105 106public: 107 std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_ = nullptr; 108}; 109 110std::shared_ptr<CellularDataStateMachine> CellularMachineTest::CreateCellularDataConnect(int32_t slotId) 111{ 112 if (cellularDataStateMachine_ != nullptr) { 113 return cellularDataStateMachine_; 114 } 115 sptr<DataConnectionManager> connectionManager = std::make_unique<DataConnectionManager>(slotId).release(); 116 if (connectionManager == nullptr) { 117 return nullptr; 118 } 119 connectionManager->Init(); 120 cellularDataStateMachine_ = std::make_shared<CellularDataStateMachine>( 121 connectionManager, std::static_pointer_cast<TelEventHandler>(shared_from_this())); 122 return cellularDataStateMachine_; 123} 124 125/** 126 * @tc.number HasAnyConnectedState_001 127 * @tc.name test function branch 128 * @tc.desc Function test 129 */ 130HWTEST_F(CellularStateMachineTest, HasAnyConnectedState_001, Function | MediumTest | Level1) 131{ 132 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 133 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 134 incallStateMachineTest->CreateIncallDataStateMachine(0); 135 incallStateMachine->apnManager_ = nullptr; 136 ASSERT_EQ(incallStateMachine->HasAnyConnectedState(), false); 137} 138 139/** 140 * @tc.number IdleState_StateBegin_001 141 * @tc.name test function branch 142 * @tc.desc Function test 143 */ 144HWTEST_F(CellularStateMachineTest, IdleState_StateBegin_001, Function | MediumTest | Level1) 145{ 146 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 147 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 148 incallStateMachineTest->CreateIncallDataStateMachine(0); 149 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 150 incallStateMachine->TransitionTo(incallStateMachine->idleState_); 151 auto idleState = static_cast<IdleState *>(incallStateMachine->idleState_.GetRefPtr()); 152 incallStateMachine = nullptr; 153 idleState->stateMachine_ = incallStateMachine; 154 idleState->StateBegin(); 155 ASSERT_EQ(idleState->isActive_, false); 156} 157 158/** 159 * @tc.number IdleState_StateBegin_002 160 * @tc.name test function branch 161 * @tc.desc Function test 162 */ 163HWTEST_F(CellularStateMachineTest, IdleState_StateBegin_002, Function | MediumTest | Level1) 164{ 165 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 166 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 167 incallStateMachineTest->CreateIncallDataStateMachine(0); 168 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 169 incallStateMachine->TransitionTo(incallStateMachine->idleState_); 170 auto idleState = static_cast<IdleState *>(incallStateMachine->idleState_.GetRefPtr()); 171 incallStateMachine->UpdateCallState(static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE)); 172 idleState->stateMachine_ = incallStateMachine; 173 idleState->StateBegin(); 174 ASSERT_EQ(idleState->isActive_, true); 175} 176 177/** 178 * @tc.number IdleState_StateBegin_003 179 * @tc.name test function branch 180 * @tc.desc Function test 181 */ 182HWTEST_F(CellularStateMachineTest, IdleState_StateBegin_003, Function | MediumTest | Level1) 183{ 184 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 185 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 186 incallStateMachineTest->CreateIncallDataStateMachine(0); 187 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 188 incallStateMachine->TransitionTo(incallStateMachine->idleState_); 189 auto idleState = static_cast<IdleState *>(incallStateMachine->idleState_.GetRefPtr()); 190 incallStateMachine->UpdateCallState(static_cast<int32_t>(TelCallStatus::CALL_STATUS_DISCONNECTED)); 191 idleState->stateMachine_ = incallStateMachine; 192 idleState->StateBegin(); 193 ASSERT_EQ(idleState->isActive_, true); 194} 195 196/** 197 * @tc.number IdleState_StateProcess_001 198 * @tc.name test function branch 199 * @tc.desc Function test 200 */ 201HWTEST_F(CellularStateMachineTest, IdleState_StateProcess_001, Function | MediumTest | Level1) 202{ 203 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 204 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 205 incallStateMachineTest->CreateIncallDataStateMachine(0); 206 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 207 incallStateMachine->TransitionTo(incallStateMachine->idleState_); 208 auto idleState = static_cast<IdleState *>(incallStateMachine->idleState_.GetRefPtr()); 209 incallStateMachine = nullptr; 210 idleState->stateMachine_ = incallStateMachine; 211 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED); 212 idleState->StateProcess(event); 213 ASSERT_EQ(idleState->isActive_, NOT_PROCESSED); 214} 215 216/** 217 * @tc.number IdleState_StateProcess_002 218 * @tc.name test function branch 219 * @tc.desc Function test 220 */ 221HWTEST_F(CellularStateMachineTest, IdleState_StateProcess_002, Function | MediumTest | Level1) 222{ 223 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 224 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 225 incallStateMachineTest->CreateIncallDataStateMachine(0); 226 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 227 incallStateMachine->TransitionTo(incallStateMachine->idleState_); 228 auto idleState = static_cast<IdleState *>(incallStateMachine->idleState_.GetRefPtr()); 229 idleState->stateMachine_ = incallStateMachine; 230 idleState->eventIdFunMap_.clear(); 231 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_CALL_STARTED); 232 idleState->StateProcess(event); 233 ASSERT_EQ(idleState->isActive_, NOT_PROCESSED); 234} 235 236/** 237 * @tc.number IdleState_IncallStateMachine_001 238 * @tc.name test function branch 239 * @tc.desc Function test 240 */ 241HWTEST_F(CellularStateMachineTest, IdleState_IncallStateMachine_001, Function | MediumTest | Level1) 242{ 243 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 244 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 245 incallStateMachineTest->CreateIncallDataStateMachine(0); 246 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 247 incallStateMachine->TransitionTo(incallStateMachine->idleState_); 248 auto idleState = static_cast<IdleState *>(incallStateMachine->idleState_.GetRefPtr()); 249 incallStateMachine = nullptr; 250 idleState->stateMachine_ = incallStateMachine; 251 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED); 252 bool result = idleState->ProcessCallStarted(event); 253 ASSERT_EQ(result, NOT_PROCESSED); 254 result = idleState->ProcessCallEnded(event); 255 ASSERT_EQ(result, NOT_PROCESSED); 256 result = idleState->ProcessSettingsOn(event); 257 ASSERT_EQ(result, NOT_PROCESSED); 258 result = idleState->ProcessDsdsChanged(event); 259 ASSERT_EQ(result, NOT_PROCESSED); 260} 261 262/** 263 * @tc.number StateProcess_001 264 * @tc.name test function branch 265 * @tc.desc Function test 266 */ 267HWTEST_F(CellularStateMachineTest, StateProcess_001, Function | MediumTest | Level1) 268{ 269 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 270 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 271 incallStateMachineTest->CreateIncallDataStateMachine(0); 272 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED); 273 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 274 incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_); 275 incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_); 276 incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_); 277 auto deactivatingSecondaryState = 278 static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr()); 279 bool result = deactivatingSecondaryState->StateProcess(event); 280 EXPECT_EQ(result, true); 281} 282 283/** 284 * @tc.number StateProcess_002 285 * @tc.name test function branch 286 * @tc.desc Function test 287 */ 288HWTEST_F(CellularStateMachineTest, StateProcess_002, Function | MediumTest | Level1) 289{ 290 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 291 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 292 incallStateMachineTest->CreateIncallDataStateMachine(0); 293 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED); 294 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 295 incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_); 296 incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_); 297 incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_); 298 auto deactivatingSecondaryState = 299 static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr()); 300 bool result = deactivatingSecondaryState->StateProcess(event); 301 EXPECT_EQ(result, true); 302} 303 304/** 305 * @tc.number StateProcess_003 306 * @tc.name test function branch 307 * @tc.desc Function test 308 */ 309HWTEST_F(CellularStateMachineTest, StateProcess_003, Function | MediumTest | Level1) 310{ 311 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 312 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 313 incallStateMachineTest->CreateIncallDataStateMachine(0); 314 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED); 315 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 316 incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_); 317 incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_); 318 incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_); 319 auto deactivatingSecondaryState = 320 static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr()); 321 incallStateMachine = nullptr; 322 deactivatingSecondaryState->stateMachine_ = incallStateMachine; 323 bool result = deactivatingSecondaryState->StateProcess(event); 324 deactivatingSecondaryState->StateBegin(); 325 EXPECT_EQ(result, NOT_PROCESSED); 326} 327 328/** 329 * @tc.number StateProcess_004 330 * @tc.name test function branch 331 * @tc.desc Function test 332 */ 333HWTEST_F(CellularStateMachineTest, StateProcess_004, Function | MediumTest | Level1) 334{ 335 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 336 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 337 incallStateMachineTest->CreateIncallDataStateMachine(0); 338 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED); 339 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 340 incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_); 341 incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_); 342 incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_); 343 auto deactivatingSecondaryState = 344 static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr()); 345 bool result = deactivatingSecondaryState->StateProcess(event); 346 EXPECT_EQ(result, true); 347} 348 349/** 350 * @tc.number ActivatingStateProcess_001 351 * @tc.name test function branch 352 * @tc.desc Function test 353 */ 354HWTEST_F(CellularStateMachineTest, ActivatingStateProcess_001, Function | MediumTest | Level1) 355{ 356 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 357 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 358 incallStateMachineTest->CreateIncallDataStateMachine(0); 359 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED); 360 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 361 incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_); 362 auto activatingSecondaryState = 363 static_cast<ActivatingSecondaryState *>(incallStateMachine->activatingSecondaryState_.GetRefPtr()); 364 bool result = activatingSecondaryState->StateProcess(event); 365 EXPECT_EQ(result, true); 366} 367 368/** 369 * @tc.number ActivatingStateProcess_002 370 * @tc.name test function branch 371 * @tc.desc Function test 372 */ 373HWTEST_F(CellularStateMachineTest, ActivatingStateProcess_002, Function | MediumTest | Level1) 374{ 375 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 376 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 377 incallStateMachineTest->CreateIncallDataStateMachine(0); 378 auto event = AppExecFwk::InnerEvent::Get(-1); 379 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 380 incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_); 381 auto activatingSecondaryState = 382 static_cast<ActivatingSecondaryState *>(incallStateMachine->activatingSecondaryState_.GetRefPtr()); 383 bool result = activatingSecondaryState->StateProcess(event); 384 EXPECT_EQ(result, false); 385} 386 387/** 388 * @tc.number ActivatingSecondaryState_IncallDataStateMachine_001 389 * @tc.name test function branch 390 * @tc.desc Function test 391 */ 392HWTEST_F(CellularStateMachineTest, ActivatingSecondaryState_IncallDataStateMachine_001, Function | MediumTest | Level1) 393{ 394 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 395 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 396 incallStateMachineTest->CreateIncallDataStateMachine(0); 397 auto event = AppExecFwk::InnerEvent::Get(0); 398 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 399 incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_); 400 auto activatingSecondaryState = 401 static_cast<ActivatingSecondaryState *>(incallStateMachine->activatingSecondaryState_.GetRefPtr()); 402 incallStateMachine = nullptr; 403 activatingSecondaryState->stateMachine_ = incallStateMachine; 404 bool result = activatingSecondaryState->StateProcess(event); 405 activatingSecondaryState->StateBegin(); 406 EXPECT_EQ(result, NOT_PROCESSED); 407} 408 409/** 410 * @tc.number SecondaryActiveStateProcess_001 411 * @tc.name test function branch 412 * @tc.desc Function test 413 */ 414HWTEST_F(CellularStateMachineTest, SecondaryActiveStateProcess_001, Function | MediumTest | Level1) 415{ 416 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 417 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 418 incallStateMachineTest->CreateIncallDataStateMachine(0); 419 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED); 420 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 421 incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_); 422 auto secondaryActiveState = 423 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr()); 424 bool result = secondaryActiveState->StateProcess(event); 425 EXPECT_EQ(result, false); 426} 427 428/** 429 * @tc.number SecondaryActiveStateProcess_002 430 * @tc.name test function branch 431 * @tc.desc Function test 432 */ 433HWTEST_F(CellularStateMachineTest, SecondaryActiveStateProcess_002, Function | MediumTest | Level1) 434{ 435 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 436 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 437 incallStateMachineTest->CreateIncallDataStateMachine(0); 438 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED); 439 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 440 incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_); 441 auto secondaryActiveState = 442 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr()); 443 incallStateMachine = nullptr; 444 secondaryActiveState->stateMachine_ = incallStateMachine; 445 bool result = secondaryActiveState->StateProcess(event); 446 EXPECT_EQ(result, NOT_PROCESSED); 447} 448 449/** 450 * @tc.number SecondaryActiveStateProcess_003 451 * @tc.name test function branch 452 * @tc.desc Function test 453 */ 454HWTEST_F(CellularStateMachineTest, SecondaryActiveStateProcess_003, Function | MediumTest | Level1) 455{ 456 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 457 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 458 incallStateMachineTest->CreateIncallDataStateMachine(0); 459 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED); 460 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 461 incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_); 462 auto secondaryActiveState = 463 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr()); 464 secondaryActiveState->stateMachine_ = incallStateMachine; 465 secondaryActiveState->eventIdFunMap_.clear(); 466 bool result = secondaryActiveState->StateProcess(event); 467 EXPECT_EQ(result, NOT_PROCESSED); 468} 469 470/** 471 * @tc.number SecondaryActiveState_ProcessCallEnded_001 472 * @tc.name test function branch 473 * @tc.desc Function test 474 */ 475HWTEST_F(CellularStateMachineTest, SecondaryActiveState_ProcessCallEnded_001, Function | MediumTest | Level1) 476{ 477 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 478 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 479 incallStateMachineTest->CreateIncallDataStateMachine(0); 480 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED); 481 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 482 incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_); 483 auto secondaryActiveState = 484 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr()); 485 incallStateMachine = nullptr; 486 secondaryActiveState->stateMachine_ = incallStateMachine; 487 bool result = secondaryActiveState->ProcessCallEnded(event); 488 EXPECT_EQ(result, NOT_PROCESSED); 489} 490 491/** 492 * @tc.number SecondaryActiveState_ProcessCallEnded_002 493 * @tc.name test function branch 494 * @tc.desc Function test 495 */ 496HWTEST_F(CellularStateMachineTest, SecondaryActiveState_ProcessCallEnded_002, Function | MediumTest | Level1) 497{ 498 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 499 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 500 incallStateMachineTest->CreateIncallDataStateMachine(0); 501 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED); 502 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 503 incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_); 504 incallStateMachine->UpdateCallState(static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE)); 505 auto secondaryActiveState = 506 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr()); 507 secondaryActiveState->stateMachine_ = incallStateMachine; 508 bool result = secondaryActiveState->ProcessCallEnded(event); 509 EXPECT_EQ(result, PROCESSED); 510 incallStateMachine->UpdateCallState(static_cast<int32_t>(TelCallStatus::CALL_STATUS_DISCONNECTED)); 511 result = secondaryActiveState->ProcessCallEnded(event); 512 EXPECT_EQ(result, PROCESSED); 513} 514 515/** 516 * @tc.number SecondaryActiveState_IncallDataStateMachine_001 517 * @tc.name test function branch 518 * @tc.desc Function test 519 */ 520HWTEST_F(CellularStateMachineTest, SecondaryActiveState_IncallDataStateMachine_001, Function | MediumTest | Level1) 521{ 522 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 523 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 524 incallStateMachineTest->CreateIncallDataStateMachine(0); 525 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED); 526 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING); 527 incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_); 528 auto secondaryActiveState = 529 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr()); 530 incallStateMachine = nullptr; 531 secondaryActiveState->stateMachine_ = incallStateMachine; 532 bool result = secondaryActiveState->ProcessCallEnded(event); 533 EXPECT_EQ(result, NOT_PROCESSED); 534 result = secondaryActiveState->ProcessSettingsOff(event); 535 EXPECT_EQ(result, NOT_PROCESSED); 536} 537 538/** 539 * @tc.number InactiveStateBegin_001 540 * @tc.name test function branch 541 * @tc.desc Function test 542 */ 543HWTEST_F(CellularStateMachineTest, InactiveStateBegin_001, Function | MediumTest | Level1) 544{ 545 if (cellularMachine == nullptr) { 546 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 547 cellularMachine = machine->CreateCellularDataConnect(0); 548 cellularMachine->Init(); 549 } 550 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr()); 551 inactive->deActiveApnTypeId_ = 0; 552 inactive->SetStateMachine(cellularMachine); 553 inactive->SetDataCallResultInfoToRetry(); 554 EXPECT_EQ(inactive->resultInfo_->reason, static_cast<int32_t>(PdpErrorReason::PDP_ERR_RETRY)); 555 inactive->SetDataCallResultInfoToClear(); 556 EXPECT_EQ(inactive->resultInfo_->reason, 557 static_cast<int32_t>(PdpErrorReason::PDP_ERR_UNKNOWN_TO_CLEAR_CONNECTION)); 558} 559 560/** 561 * @tc.number InactiveStateProcess_002 562 * @tc.name test function branch 563 * @tc.desc Function test 564 */ 565HWTEST_F(CellularStateMachineTest, InactiveStateProcess_002, Function | MediumTest | Level1) 566{ 567 if (cellularMachine == nullptr) { 568 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 569 cellularMachine = machine->CreateCellularDataConnect(0); 570 cellularMachine->Init(); 571 } 572 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr()); 573 inactive->stateMachine_ = cellularMachine; 574 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT); 575 bool result = inactive->StateProcess(event); 576 EXPECT_EQ(result, true); 577} 578 579/** 580 * @tc.number InactiveStateProcess_003 581 * @tc.name test function branch 582 * @tc.desc Function test 583 */ 584HWTEST_F(CellularStateMachineTest, InactiveStateProcess_003, Function | MediumTest | Level1) 585{ 586 if (cellularMachine == nullptr) { 587 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 588 cellularMachine = machine->CreateCellularDataConnect(0); 589 cellularMachine->Init(); 590 } 591 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr()); 592 inactive->SetStateMachine(cellularMachine); 593 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT_ALL); 594 bool result = inactive->StateProcess(event); 595 EXPECT_EQ(result, true); 596} 597 598/** 599 * @tc.number Inactive_CellularDataStateMachine_001 600 * @tc.name test function branch 601 * @tc.desc Function test 602 */ 603HWTEST_F(CellularStateMachineTest, Inactive_CellularDataStateMachine_001, Function | MediumTest | Level1) 604{ 605 if (cellularMachine == nullptr) { 606 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 607 cellularMachine = machine->CreateCellularDataConnect(0); 608 cellularMachine->Init(); 609 } 610 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr()); 611 cellularMachine = nullptr; 612 inactive->stateMachine_ = cellularMachine; 613 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT_ALL); 614 bool result = inactive->StateProcess(event); 615 inactive->StateBegin(); 616 EXPECT_EQ(result, false); 617} 618 619/** 620 * @tc.number DefaultStateProcess_001 621 * @tc.name test function branch 622 * @tc.desc Function test 623 */ 624HWTEST_F(CellularStateMachineTest, DefaultStateProcess_001, Function | MediumTest | Level1) 625{ 626 if (cellularMachine == nullptr) { 627 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 628 cellularMachine = machine->CreateCellularDataConnect(0); 629 cellularMachine->Init(); 630 } 631 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 632 mDefault->stateMachine_ = cellularMachine; 633 mDefault->eventIdFunMap_.clear(); 634 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 635 bool result = mDefault->StateProcess(event); 636 EXPECT_EQ(result, false); 637} 638 639/** 640 * @tc.number DefaultStateProcess_002 641 * @tc.name test function branch 642 * @tc.desc Function test 643 */ 644HWTEST_F(CellularStateMachineTest, DefaultStateProcess_002, Function | MediumTest | Level1) 645{ 646 if (cellularMachine == nullptr) { 647 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 648 cellularMachine = machine->CreateCellularDataConnect(0); 649 cellularMachine->Init(); 650 } 651 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 652 cellularMachine = nullptr; 653 mDefault->stateMachine_ = cellularMachine; 654 mDefault->eventIdFunMap_.clear(); 655 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 656 bool result = mDefault->StateProcess(event); 657 EXPECT_EQ(result, false); 658} 659 660/** 661 * @tc.number DefaultProcessDisconnectDone_001 662 * @tc.name test function branch 663 * @tc.desc Function test 664 */ 665HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectDone_001, Function | MediumTest | Level1) 666{ 667 if (cellularMachine == nullptr) { 668 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 669 cellularMachine = machine->CreateCellularDataConnect(0); 670 cellularMachine->Init(); 671 } 672 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 673 mDefault->stateMachine_ = cellularMachine; 674 mDefault->eventIdFunMap_.clear(); 675 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 676 bool result = mDefault->ProcessDisconnectDone(event); 677 EXPECT_EQ(result, true); 678} 679 680/** 681 * @tc.number DefaultProcessDisconnectDone_002 682 * @tc.name test function branch 683 * @tc.desc Function test 684 */ 685HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectDone_002, Function | MediumTest | Level1) 686{ 687 if (cellularMachine == nullptr) { 688 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 689 cellularMachine = machine->CreateCellularDataConnect(0); 690 cellularMachine->Init(); 691 } 692 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 693 cellularMachine = nullptr; 694 mDefault->stateMachine_ = cellularMachine; 695 mDefault->eventIdFunMap_.clear(); 696 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 697 bool result = mDefault->ProcessDisconnectDone(event); 698 EXPECT_EQ(result, false); 699} 700 701/** 702 * @tc.number DefaultProcessDisconnectAllDone_001 703 * @tc.name test function branch 704 * @tc.desc Function test 705 */ 706HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectAllDone_001, Function | MediumTest | Level1) 707{ 708 if (cellularMachine == nullptr) { 709 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 710 cellularMachine = machine->CreateCellularDataConnect(0); 711 cellularMachine->Init(); 712 } 713 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 714 mDefault->stateMachine_ = cellularMachine; 715 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 716 bool result = mDefault->ProcessDisconnectAllDone(event); 717 EXPECT_EQ(result, true); 718} 719 720/** 721 * @tc.number DefaultProcessDisconnectAllDone_002 722 * @tc.name test function branch 723 * @tc.desc Function test 724 */ 725HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectAllDone_002, Function | MediumTest | Level1) 726{ 727 if (cellularMachine == nullptr) { 728 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 729 cellularMachine = machine->CreateCellularDataConnect(0); 730 cellularMachine->Init(); 731 } 732 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 733 cellularMachine = nullptr; 734 mDefault->stateMachine_ = cellularMachine; 735 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 736 bool result = mDefault->ProcessDisconnectAllDone(event); 737 EXPECT_EQ(result, false); 738} 739 740/** 741 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_001 742 * @tc.name test function branch 743 * @tc.desc Function test 744 */ 745HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_001, Function | MediumTest | Level1) 746{ 747 if (cellularMachine == nullptr) { 748 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 749 cellularMachine = machine->CreateCellularDataConnect(0); 750 cellularMachine->Init(); 751 } 752 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 753 cellularMachine->TransitionTo(cellularMachine->activeState_); 754 mDefault->stateMachine_ = cellularMachine; 755 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 756 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event); 757 EXPECT_EQ(result, false); 758} 759 760/** 761 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_002 762 * @tc.name test function branch 763 * @tc.desc Function test 764 */ 765HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_002, Function | MediumTest | Level1) 766{ 767 if (cellularMachine == nullptr) { 768 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 769 cellularMachine = machine->CreateCellularDataConnect(0); 770 cellularMachine->Init(); 771 } 772 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 773 cellularMachine->TransitionTo(cellularMachine->activatingState_); 774 mDefault->stateMachine_ = cellularMachine; 775 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 776 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event); 777 EXPECT_EQ(result, false); 778} 779 780/** 781 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_003 782 * @tc.name test function branch 783 * @tc.desc Function test 784 */ 785HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_003, Function | MediumTest | Level1) 786{ 787 if (cellularMachine == nullptr) { 788 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 789 cellularMachine = machine->CreateCellularDataConnect(0); 790 cellularMachine->Init(); 791 } 792 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 793 cellularMachine->TransitionTo(cellularMachine->disconnectingState_); 794 mDefault->stateMachine_ = cellularMachine; 795 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 796 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event); 797 EXPECT_EQ(result, false); 798} 799 800/** 801 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_004 802 * @tc.name test function branch 803 * @tc.desc Function test 804 */ 805HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_004, Function | MediumTest | Level1) 806{ 807 if (cellularMachine == nullptr) { 808 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 809 cellularMachine = machine->CreateCellularDataConnect(0); 810 cellularMachine->Init(); 811 } 812 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 813 cellularMachine = nullptr; 814 mDefault->stateMachine_ = cellularMachine; 815 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 816 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event); 817 EXPECT_EQ(result, false); 818} 819 820/** 821 * @tc.number Active_StateBegin_001 822 * @tc.name test function branch 823 * @tc.desc Function test 824 */ 825HWTEST_F(CellularStateMachineTest, Active_StateBegin_001, Function | MediumTest | Level1) 826{ 827 if (cellularMachine == nullptr) { 828 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 829 cellularMachine = machine->CreateCellularDataConnect(0); 830 cellularMachine->Init(); 831 } 832 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 833 active->stateMachine_ = cellularMachine; 834 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 835 active->StateBegin(); 836 EXPECT_EQ(active->isActive_, true); 837} 838 839/** 840 * @tc.number Active_StateProcess_001 841 * @tc.name test function branch 842 * @tc.desc Function test 843 */ 844HWTEST_F(CellularStateMachineTest, Active_StateProcess_001, Function | MediumTest | Level1) 845{ 846 if (cellularMachine == nullptr) { 847 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 848 cellularMachine = machine->CreateCellularDataConnect(0); 849 cellularMachine->Init(); 850 } 851 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 852 active->stateMachine_ = cellularMachine; 853 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 854 bool result = active->StateProcess(event); 855 EXPECT_EQ(result, true); 856} 857 858/** 859 * @tc.number Active_StateProcess_002 860 * @tc.name test function branch 861 * @tc.desc Function test 862 */ 863HWTEST_F(CellularStateMachineTest, Active_StateProcess_002, Function | MediumTest | Level1) 864{ 865 if (cellularMachine == nullptr) { 866 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 867 cellularMachine = machine->CreateCellularDataConnect(0); 868 cellularMachine->Init(); 869 } 870 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 871 active->stateMachine_ = cellularMachine; 872 auto event = AppExecFwk::InnerEvent::Get(0); 873 bool result = active->StateProcess(event); 874 EXPECT_EQ(result, false); 875} 876 877/** 878 * @tc.number Active_StateProcess_003 879 * @tc.name test function branch 880 * @tc.desc Function test 881 */ 882HWTEST_F(CellularStateMachineTest, Active_StateProcess_003, Function | MediumTest | Level1) 883{ 884 if (cellularMachine == nullptr) { 885 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 886 cellularMachine = machine->CreateCellularDataConnect(0); 887 cellularMachine->Init(); 888 } 889 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 890 cellularMachine = nullptr; 891 active->stateMachine_ = cellularMachine; 892 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 893 bool result = active->StateProcess(event); 894 EXPECT_EQ(result, true); 895} 896 897/** 898 * @tc.number Active_ProcessDisconnectDone_001 899 * @tc.name test function branch 900 * @tc.desc Function test 901 */ 902HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_001, Function | MediumTest | Level1) 903{ 904 if (cellularMachine == nullptr) { 905 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 906 cellularMachine = machine->CreateCellularDataConnect(0); 907 cellularMachine->Init(); 908 } 909 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 910 active->stateMachine_ = cellularMachine; 911 auto event = AppExecFwk::InnerEvent::Get(0); 912 event = nullptr; 913 bool result = active->ProcessDisconnectDone(event); 914 EXPECT_EQ(result, false); 915} 916 917/** 918 * @tc.number Active_ProcessDisconnectDone_002 919 * @tc.name test function branch 920 * @tc.desc Function test 921 */ 922HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_002, Function | MediumTest | Level1) 923{ 924 if (cellularMachine == nullptr) { 925 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 926 cellularMachine = machine->CreateCellularDataConnect(0); 927 cellularMachine->Init(); 928 } 929 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 930 active->stateMachine_ = cellularMachine; 931 auto event = AppExecFwk::InnerEvent::Get(0); 932 bool result = active->ProcessDisconnectDone(event); 933 EXPECT_EQ(result, false); 934} 935 936/** 937 * @tc.number Active_ProcessDisconnectAllDone_001 938 * @tc.name test function branch 939 * @tc.desc Function test 940 */ 941HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_001, Function | MediumTest | Level1) 942{ 943 if (cellularMachine == nullptr) { 944 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 945 cellularMachine = machine->CreateCellularDataConnect(0); 946 cellularMachine->Init(); 947 } 948 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 949 active->stateMachine_ = cellularMachine; 950 auto event = AppExecFwk::InnerEvent::Get(0); 951 event = nullptr; 952 bool result = active->ProcessDisconnectAllDone(event); 953 EXPECT_EQ(result, false); 954} 955 956/** 957 * @tc.number Active_ProcessDisconnectAllDone_002 958 * @tc.name test function branch 959 * @tc.desc Function test 960 */ 961HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_002, Function | MediumTest | Level1) 962{ 963 if (cellularMachine == nullptr) { 964 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 965 cellularMachine = machine->CreateCellularDataConnect(0); 966 cellularMachine->Init(); 967 } 968 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 969 active->stateMachine_ = cellularMachine; 970 auto event = AppExecFwk::InnerEvent::Get(0); 971 bool result = active->ProcessDisconnectAllDone(event); 972 EXPECT_EQ(result, false); 973} 974 975/** 976 * @tc.number Active_ProcessDisconnectAllDone_003 977 * @tc.name test function branch 978 * @tc.desc Function test 979 */ 980HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_003, Function | MediumTest | Level1) 981{ 982 if (cellularMachine == nullptr) { 983 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 984 cellularMachine = machine->CreateCellularDataConnect(0); 985 cellularMachine->Init(); 986 } 987 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 988 cellularMachine->TransitionTo(cellularMachine->inActiveState_); 989 active->stateMachine_ = cellularMachine; 990 std::shared_ptr<DataDisconnectParams> dataDisconnectParams = 991 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL); 992 auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams); 993 bool result = active->ProcessDisconnectAllDone(event); 994 EXPECT_EQ(result, false); 995} 996 997/** 998 * @tc.number Active_ProcessDisconnectAllDone_004 999 * @tc.name test function branch 1000 * @tc.desc Function test 1001 */ 1002HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_004, Function | MediumTest | Level1) 1003{ 1004 if (cellularMachine == nullptr) { 1005 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1006 cellularMachine = machine->CreateCellularDataConnect(0); 1007 cellularMachine->Init(); 1008 } 1009 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1010 cellularMachine->inActiveState_ = nullptr; 1011 active->stateMachine_ = cellularMachine; 1012 std::shared_ptr<DataDisconnectParams> dataDisconnectParams = 1013 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL); 1014 auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams); 1015 bool result = active->ProcessDisconnectAllDone(event); 1016 EXPECT_EQ(result, false); 1017} 1018 1019/** 1020 * @tc.number Active_ProcessLinkCapabilityChanged_001 1021 * @tc.name test function branch 1022 * @tc.desc Function test 1023 */ 1024HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_001, Function | MediumTest | Level1) 1025{ 1026 if (cellularMachine == nullptr) { 1027 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1028 cellularMachine = machine->CreateCellularDataConnect(0); 1029 cellularMachine->Init(); 1030 } 1031 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1032 active->stateMachine_ = cellularMachine; 1033 auto event = AppExecFwk::InnerEvent::Get(0); 1034 bool result = active->ProcessLinkCapabilityChanged(event); 1035 EXPECT_EQ(result, false); 1036} 1037 1038/** 1039 * @tc.number Active_ProcessLinkCapabilityChanged_002 1040 * @tc.name test function branch 1041 * @tc.desc Function test 1042 */ 1043HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_002, Function | MediumTest | Level1) 1044{ 1045 if (cellularMachine == nullptr) { 1046 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1047 cellularMachine = machine->CreateCellularDataConnect(0); 1048 cellularMachine->Init(); 1049 } 1050 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1051 cellularMachine = nullptr; 1052 active->stateMachine_ = cellularMachine; 1053 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>(); 1054 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability); 1055 bool result = active->ProcessLinkCapabilityChanged(event); 1056 EXPECT_EQ(result, false); 1057} 1058 1059/** 1060 * @tc.number Active_ProcessLinkCapabilityChanged_003 1061 * @tc.name test function branch 1062 * @tc.desc Function test 1063 */ 1064HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_003, Function | MediumTest | Level1) 1065{ 1066 if (cellularMachine == nullptr) { 1067 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1068 cellularMachine = machine->CreateCellularDataConnect(0); 1069 cellularMachine->Init(); 1070 } 1071 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1072 active->stateMachine_ = cellularMachine; 1073 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>(); 1074 linkCapability->primaryUplinkKbps = 0; 1075 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability); 1076 bool result = active->ProcessLinkCapabilityChanged(event); 1077 EXPECT_EQ(result, true); 1078} 1079 1080/** 1081 * @tc.number Active_ProcessLinkCapabilityChanged_004 1082 * @tc.name test function branch 1083 * @tc.desc Function test 1084 */ 1085HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_004, Function | MediumTest | Level1) 1086{ 1087 if (cellularMachine == nullptr) { 1088 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1089 cellularMachine = machine->CreateCellularDataConnect(0); 1090 cellularMachine->Init(); 1091 } 1092 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1093 active->stateMachine_ = cellularMachine; 1094 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>(); 1095 linkCapability->primaryUplinkKbps = 1; 1096 linkCapability->primaryDownlinkKbps = 0; 1097 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability); 1098 bool result = active->ProcessLinkCapabilityChanged(event); 1099 EXPECT_EQ(result, true); 1100} 1101 1102/** 1103 * @tc.number Active_ProcessLinkCapabilityChanged_005 1104 * @tc.name test function branch 1105 * @tc.desc Function test 1106 */ 1107HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_005, Function | MediumTest | Level1) 1108{ 1109 if (cellularMachine == nullptr) { 1110 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1111 cellularMachine = machine->CreateCellularDataConnect(0); 1112 cellularMachine->Init(); 1113 } 1114 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1115 active->stateMachine_ = cellularMachine; 1116 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>(); 1117 linkCapability->primaryUplinkKbps = 1; 1118 linkCapability->primaryDownlinkKbps = 1; 1119 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability); 1120 bool result = active->ProcessLinkCapabilityChanged(event); 1121 EXPECT_EQ(result, true); 1122} 1123 1124/** 1125 * @tc.number Active_ProcessDataConnectionComplete_001 1126 * @tc.name test function branch 1127 * @tc.desc Function test 1128 */ 1129HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_001, Function | MediumTest | Level1) 1130{ 1131 if (cellularMachine == nullptr) { 1132 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1133 cellularMachine = machine->CreateCellularDataConnect(0); 1134 cellularMachine->Init(); 1135 } 1136 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1137 active->stateMachine_ = cellularMachine; 1138 auto event = AppExecFwk::InnerEvent::Get(0); 1139 bool result = active->ProcessDataConnectionComplete(event); 1140 EXPECT_EQ(result, false); 1141} 1142 1143/** 1144 * @tc.number Active_ProcessDataConnectionComplete_002 1145 * @tc.name test function branch 1146 * @tc.desc Function test 1147 */ 1148HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_002, Function | MediumTest | Level1) 1149{ 1150 if (cellularMachine == nullptr) { 1151 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1152 cellularMachine = machine->CreateCellularDataConnect(0); 1153 cellularMachine->Init(); 1154 } 1155 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1156 cellularMachine = nullptr; 1157 active->stateMachine_ = cellularMachine; 1158 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>(); 1159 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo); 1160 bool result = active->ProcessDataConnectionComplete(event); 1161 EXPECT_EQ(result, false); 1162} 1163 1164/** 1165 * @tc.number Active_ProcessDataConnectionComplete_003 1166 * @tc.name test function branch 1167 * @tc.desc Function test 1168 */ 1169HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_003, Function | MediumTest | Level1) 1170{ 1171 if (cellularMachine == nullptr) { 1172 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1173 cellularMachine = machine->CreateCellularDataConnect(0); 1174 cellularMachine->Init(); 1175 } 1176 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1177 active->stateMachine_ = cellularMachine; 1178 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>(); 1179 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo); 1180 bool result = active->ProcessDataConnectionComplete(event); 1181 EXPECT_EQ(result, true); 1182} 1183 1184/** 1185 * @tc.number Active_ProcessDataConnectionComplete_004 1186 * @tc.name test function branch 1187 * @tc.desc Function test 1188 */ 1189HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_004, Function | MediumTest | Level1) 1190{ 1191 if (cellularMachine == nullptr) { 1192 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1193 cellularMachine = machine->CreateCellularDataConnect(0); 1194 cellularMachine->Init(); 1195 } 1196 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1197 cellularMachine->stateMachineEventHandler_ = nullptr; 1198 active->stateMachine_ = cellularMachine; 1199 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>(); 1200 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo); 1201 bool result = active->ProcessDataConnectionComplete(event); 1202 EXPECT_EQ(result, false); 1203} 1204 1205/** 1206 * @tc.number Active_ProcessNrStateChanged_001 1207 * @tc.name test function branch 1208 * @tc.desc Function test 1209 */ 1210HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_001, Function | MediumTest | Level1) 1211{ 1212 if (cellularMachine == nullptr) { 1213 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1214 cellularMachine = machine->CreateCellularDataConnect(0); 1215 cellularMachine->Init(); 1216 } 1217 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1218 active->stateMachine_ = cellularMachine; 1219 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 1220 bool result = active->ProcessNrStateChanged(event); 1221 EXPECT_EQ(result, true); 1222} 1223 1224/** 1225 * @tc.number Active_ProcessNrStateChanged_002 1226 * @tc.name test function branch 1227 * @tc.desc Function test 1228 */ 1229HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_002, Function | MediumTest | Level1) 1230{ 1231 if (cellularMachine == nullptr) { 1232 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1233 cellularMachine = machine->CreateCellularDataConnect(0); 1234 cellularMachine->Init(); 1235 } 1236 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1237 cellularMachine = nullptr; 1238 active->stateMachine_ = cellularMachine; 1239 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 1240 bool result = active->ProcessNrStateChanged(event); 1241 EXPECT_EQ(result, false); 1242} 1243 1244/** 1245 * @tc.number Active_ProcessNrFrequencyChanged_001 1246 * @tc.name test function branch 1247 * @tc.desc Function test 1248 */ 1249HWTEST_F(CellularStateMachineTest, Active_ProcessNrFrequencyChanged_001, Function | MediumTest | Level1) 1250{ 1251 if (cellularMachine == nullptr) { 1252 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1253 cellularMachine = machine->CreateCellularDataConnect(0); 1254 cellularMachine->Init(); 1255 } 1256 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1257 cellularMachine = nullptr; 1258 active->stateMachine_ = cellularMachine; 1259 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 1260 bool result = active->ProcessNrFrequencyChanged(event); 1261 EXPECT_EQ(result, false); 1262} 1263 1264/** 1265 * @tc.number Active_ProcessDisconnectAllDone_001 1266 * @tc.name test function branch 1267 * @tc.desc Function test 1268 */ 1269HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_001, Function | MediumTest | Level1) 1270{ 1271 if (cellularMachine == nullptr) { 1272 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1273 cellularMachine = machine->CreateCellularDataConnect(0); 1274 cellularMachine->Init(); 1275 } 1276 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1277 cellularMachine->TransitionTo(cellularMachine->inActiveState_); 1278 active->stateMachine_ = cellularMachine; 1279 auto event = AppExecFwk::InnerEvent::Get(0); 1280 bool result = active->ProcessLostConnection(event); 1281 EXPECT_EQ(result, true); 1282} 1283 1284/** 1285 * @tc.number Active_ProcessLostConnection_002 1286 * @tc.name test function branch 1287 * @tc.desc Function test 1288 */ 1289HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_002, Function | MediumTest | Level1) 1290{ 1291 if (cellularMachine == nullptr) { 1292 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1293 cellularMachine = machine->CreateCellularDataConnect(0); 1294 cellularMachine->Init(); 1295 } 1296 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1297 cellularMachine->inActiveState_ = nullptr; 1298 active->stateMachine_ = cellularMachine; 1299 auto event = AppExecFwk::InnerEvent::Get(0); 1300 bool result = active->ProcessLostConnection(event); 1301 EXPECT_EQ(result, false); 1302} 1303 1304/** 1305 * @tc.number Active_ProcessDataConnectionRoamOn_001 1306 * @tc.name test function branch 1307 * @tc.desc Function test 1308 */ 1309HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOn_001, Function | MediumTest | Level1) 1310{ 1311 if (cellularMachine == nullptr) { 1312 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1313 cellularMachine = machine->CreateCellularDataConnect(0); 1314 cellularMachine->Init(); 1315 } 1316 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1317 active->stateMachine_ = cellularMachine; 1318 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 1319 bool result = active->ProcessDataConnectionRoamOn(event); 1320 EXPECT_EQ(result, true); 1321} 1322 1323/** 1324 * @tc.number Active_ProcessDataConnectionRoamOff_001 1325 * @tc.name test function branch 1326 * @tc.desc Function test 1327 */ 1328HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOff_001, Function | MediumTest | Level1) 1329{ 1330 if (cellularMachine == nullptr) { 1331 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1332 cellularMachine = machine->CreateCellularDataConnect(0); 1333 cellularMachine->Init(); 1334 } 1335 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1336 active->stateMachine_ = cellularMachine; 1337 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 1338 bool result = active->ProcessDataConnectionRoamOff(event); 1339 EXPECT_EQ(result, true); 1340} 1341 1342/** 1343 * @tc.number Active_ProcessDataConnectionVoiceCallStartedOrEnded_001 1344 * @tc.name test function branch 1345 * @tc.desc Function test 1346 */ 1347HWTEST_F(CellularStateMachineTest, ProcessDataConnectionVoiceCallStartedOrEnded_001, Function | MediumTest | Level1) 1348{ 1349 if (cellularMachine == nullptr) { 1350 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1351 cellularMachine = machine->CreateCellularDataConnect(0); 1352 cellularMachine->Init(); 1353 } 1354 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr()); 1355 active->stateMachine_ = cellularMachine; 1356 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT); 1357 bool result = active->ProcessDataConnectionVoiceCallStartedOrEnded(event); 1358 EXPECT_EQ(result, true); 1359} 1360 1361/** 1362 * @tc.number CellularDataStateMachine_GetSlotId_001 1363 * @tc.name test function branch 1364 * @tc.desc Function test 1365 */ 1366HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetSlotId_001, Function | MediumTest | Level1) 1367{ 1368 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1369 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 1370 int result = cellularMachine->GetSlotId(); 1371 ASSERT_EQ(result, DEFAULT_SIM_SLOT_ID); 1372} 1373 1374/** 1375 * @tc.number CellularDataStateMachine_HasMatchedIpTypeAddrs_001 1376 * @tc.name test function branch 1377 * @tc.desc Function test 1378 */ 1379HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_001, Function | MediumTest | Level1) 1380{ 1381 if (cellularMachine == nullptr) { 1382 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1383 cellularMachine = machine->CreateCellularDataConnect(0); 1384 cellularMachine->Init(); 1385 } 1386 uint8_t ipType = 1; 1387 uint8_t ipInfoArraySize = 2; 1388 std::vector<AddressInfo> ipInfoArray; 1389 AddressInfo info1; 1390 info1.type = 1; 1391 AddressInfo info2; 1392 info2.type = 3; 1393 ipInfoArray.push_back(info1); 1394 ipInfoArray.push_back(info2); 1395 bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray); 1396 ASSERT_TRUE(result); 1397} 1398 1399/** 1400 * @tc.number CellularDataStateMachine_HasMatchedIpTypeAddrs_002 1401 * @tc.name test function branch 1402 * @tc.desc Function test 1403 */ 1404HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_002, Function | MediumTest | Level1) 1405{ 1406 if (cellularMachine == nullptr) { 1407 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1408 cellularMachine = machine->CreateCellularDataConnect(0); 1409 cellularMachine->Init(); 1410 } 1411 uint8_t ipType = 5; 1412 uint8_t ipInfoArraySize = 2; 1413 std::vector<AddressInfo> ipInfoArray; 1414 AddressInfo info1; 1415 info1.type = 1; 1416 AddressInfo info2; 1417 info2.type = 3; 1418 ipInfoArray.push_back(info1); 1419 ipInfoArray.push_back(info2); 1420 bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray); 1421 ASSERT_FALSE(result); 1422} 1423 1424/** 1425 * @tc.number GetIpType_ShouldReturnIPV4V6_001 1426 * @tc.name test function branch 1427 * @tc.desc Function test 1428 */ 1429HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_001, TestSize.Level0) 1430{ 1431 if (cellularMachine == nullptr) { 1432 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1433 cellularMachine = machine->CreateCellularDataConnect(0); 1434 cellularMachine->Init(); 1435 } 1436 std::vector<AddressInfo> ipInfoArray; 1437 AddressInfo info1; 1438 info1.type = INetAddr::IpType::IPV4; 1439 AddressInfo info2; 1440 info2.type = INetAddr::IpType::IPV6; 1441 ipInfoArray.push_back(info1); 1442 ipInfoArray.push_back(info2); 1443 std::string result = cellularMachine->GetIpType(ipInfoArray); 1444 ASSERT_EQ(result, "IPV4V6"); 1445} 1446 1447/** 1448 * @tc.number GetIpType_ShouldReturnIPV4V6_002 1449 * @tc.name test function branch 1450 * @tc.desc Function test 1451 */ 1452HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_002, TestSize.Level0) 1453{ 1454 if (cellularMachine == nullptr) { 1455 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1456 cellularMachine = machine->CreateCellularDataConnect(0); 1457 cellularMachine->Init(); 1458 } 1459 std::vector<AddressInfo> ipInfoArray; 1460 AddressInfo info1; 1461 info1.type = INetAddr::IpType::IPV4; 1462 ipInfoArray.push_back(info1); 1463 std::string result = cellularMachine->GetIpType(ipInfoArray); 1464 ASSERT_EQ(result, "IPV4"); 1465} 1466 1467/** 1468 * @tc.number GetIpType_ShouldReturnIPV6_003 1469 * @tc.name test function branch 1470 * @tc.desc Function test 1471 */ 1472HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV6_003, TestSize.Level0) 1473{ 1474 if (cellularMachine == nullptr) { 1475 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1476 cellularMachine = machine->CreateCellularDataConnect(0); 1477 cellularMachine->Init(); 1478 } 1479 std::vector<AddressInfo> ipInfoArray; 1480 AddressInfo info2; 1481 info2.type = INetAddr::IpType::IPV6; 1482 ipInfoArray.push_back(info2); 1483 std::string result = cellularMachine->GetIpType(ipInfoArray); 1484 ASSERT_EQ(result, "IPV6"); 1485} 1486 1487/** 1488 * @tc.number GetIpType_ShouldReturnEmpty_004 1489 * @tc.name test function branch 1490 * @tc.desc Function test 1491 */ 1492HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnEmpty_004, TestSize.Level0) 1493{ 1494 if (cellularMachine == nullptr) { 1495 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1496 cellularMachine = machine->CreateCellularDataConnect(0); 1497 cellularMachine->Init(); 1498 } 1499 std::vector<AddressInfo> ipInfoArray = {}; 1500 std::string result = cellularMachine->GetIpType(ipInfoArray); 1501 ASSERT_EQ(result, ""); 1502} 1503 1504/** 1505 * @tc.number GetIpType_ShouldReturnIPV4V6_005 1506 * @tc.name test function branch 1507 * @tc.desc Function test 1508 */ 1509HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_005, TestSize.Level0) 1510{ 1511 if (cellularMachine == nullptr) { 1512 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1513 cellularMachine = machine->CreateCellularDataConnect(0); 1514 cellularMachine->Init(); 1515 } 1516 std::vector<AddressInfo> ipInfoArray; 1517 AddressInfo info1; 1518 info1.type = 5; 1519 AddressInfo info2; 1520 info2.type = 6; 1521 ipInfoArray.push_back(info1); 1522 ipInfoArray.push_back(info2); 1523 std::string result = cellularMachine->GetIpType(ipInfoArray); 1524 ASSERT_EQ(result, ""); 1525} 1526 1527/** 1528 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_001 1529 * @tc.name test function branch 1530 * @tc.desc Function test 1531 */ 1532HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_001, TestSize.Level0) { 1533 if (cellularMachine == nullptr) { 1534 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1535 cellularMachine = machine->CreateCellularDataConnect(0); 1536 cellularMachine->Init(); 1537 } 1538 SetupDataCallResultInfo dataCallInfo; 1539 dataCallInfo.address = ""; 1540 dataCallInfo.dns = ""; 1541 dataCallInfo.dnsSec = ""; 1542 dataCallInfo.gateway = ""; 1543 cellularMachine->UpdateNetworkInfo(dataCallInfo); 1544 ASSERT_EQ(cellularMachine->cause_, 0); 1545} 1546 1547/** 1548 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_002 1549 * @tc.name test function branch 1550 * @tc.desc Function test 1551 */ 1552HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_002, TestSize.Level0) { 1553 if (cellularMachine == nullptr) { 1554 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1555 cellularMachine = machine->CreateCellularDataConnect(0); 1556 cellularMachine->Init(); 1557 } 1558 SetupDataCallResultInfo dataCallInfo; 1559 dataCallInfo.address = "192.168.1.1"; 1560 dataCallInfo.dns = "192.168.1.1"; 1561 dataCallInfo.dnsSec = "192.168.1.1"; 1562 dataCallInfo.gateway = "192.168.1.1"; 1563 dataCallInfo.reason = 1; 1564 cellularMachine->UpdateNetworkInfo(dataCallInfo); 1565 ASSERT_EQ(cellularMachine->cause_, 1); 1566} 1567 1568/** 1569 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_003 1570 * @tc.name test function branch 1571 * @tc.desc Function test 1572 */ 1573HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_003, TestSize.Level0) { 1574 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1575 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 1576 SetupDataCallResultInfo dataCallInfo; 1577 dataCallInfo.address = "192.168.1.1"; 1578 dataCallInfo.dns = "192.168.1.1"; 1579 dataCallInfo.dnsSec = "192.168.1.1"; 1580 dataCallInfo.gateway = "192.168.1.1"; 1581 dataCallInfo.reason = 1; 1582 cellularMachine->UpdateNetworkInfo(dataCallInfo); 1583 ASSERT_EQ(cellularMachine->cause_, 0); 1584} 1585 1586/** 1587 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_004 1588 * @tc.name test function branch 1589 * @tc.desc Function test 1590 */ 1591HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_004, TestSize.Level0) { 1592 if (cellularMachine == nullptr) { 1593 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1594 cellularMachine = machine->CreateCellularDataConnect(0); 1595 cellularMachine->Init(); 1596 } 1597 cellularMachine->netSupplierInfo_->isAvailable_ = true; 1598 cellularMachine->UpdateNetworkInfo(); 1599 ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr); 1600} 1601 1602/** 1603 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_005 1604 * @tc.name test function branch 1605 * @tc.desc Function test 1606 */ 1607HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_005, TestSize.Level0) { 1608 if (cellularMachine == nullptr) { 1609 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1610 cellularMachine = machine->CreateCellularDataConnect(0); 1611 cellularMachine->Init(); 1612 } 1613 cellularMachine->netSupplierInfo_->isAvailable_ = false; 1614 cellularMachine->UpdateNetworkInfo(); 1615 ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr); 1616} 1617 1618/** 1619 * @tc.number CellularDataStateMachine_ResolveRoute_001 1620 * @tc.name test function branch 1621 * @tc.desc Function test 1622 */ 1623 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_001, TestSize.Level0) 1624{ 1625 if (cellularMachine == nullptr) { 1626 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1627 cellularMachine = machine->CreateCellularDataConnect(0); 1628 cellularMachine->Init(); 1629 } 1630 std::vector<AddressInfo> routeInfoArray; 1631 cellularMachine->ResolveRoute(routeInfoArray, "eth0"); 1632 EXPECT_TRUE(cellularMachine->netLinkInfo_->routeList_.empty()); 1633} 1634 1635/** 1636 * @tc.number CellularDataStateMachine_ResolveRoute_002 1637 * @tc.name test function branch 1638 * @tc.desc Function test 1639 */ 1640HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_002, TestSize.Level0) 1641{ 1642 if (cellularMachine == nullptr) { 1643 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1644 cellularMachine = machine->CreateCellularDataConnect(0); 1645 cellularMachine->Init(); 1646 } 1647 std::vector<AddressInfo> routeInfoArray; 1648 AddressInfo routeInfo; 1649 routeInfo.ip = "192.168.1.1"; 1650 routeInfo.type = INetAddr::IpType::IPV4; 1651 routeInfo.prefixLen = 24; 1652 routeInfoArray.push_back(routeInfo); 1653 cellularMachine->ResolveRoute(routeInfoArray, "eth0"); 1654 EXPECT_FALSE(cellularMachine->netLinkInfo_->routeList_.empty()); 1655} 1656 1657/** 1658 * @tc.number CellularDataStateMachine_ResolveRoute_003 1659 * @tc.name test function branch 1660 * @tc.desc Function test 1661 */ 1662HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_003, TestSize.Level0) 1663{ 1664 if (cellularMachine == nullptr) { 1665 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1666 cellularMachine = machine->CreateCellularDataConnect(0); 1667 cellularMachine->Init(); 1668 } 1669 std::vector<AddressInfo> routeInfoArray; 1670 AddressInfo routeInfo1; 1671 routeInfo1.ip = "192.168.1.1"; 1672 routeInfo1.type = INetAddr::IpType::IPV4; 1673 routeInfo1.prefixLen = 24; 1674 routeInfoArray.push_back(routeInfo1); 1675 AddressInfo routeInfo2; 1676 routeInfo2.ip = "2001:db8::1"; 1677 routeInfo2.type = INetAddr::IpType::IPV6; 1678 routeInfo2.prefixLen = 64; 1679 routeInfoArray.push_back(routeInfo2); 1680 cellularMachine->ResolveRoute(routeInfoArray, "eth0"); 1681 EXPECT_EQ(cellularMachine->netLinkInfo_->routeList_.size(), 2); 1682} 1683 1684/** 1685 * @tc.number CellularDataStateMachine_UpdateNetworkInfoIfInActive_001 1686 * @tc.name test function branch 1687 * @tc.desc Function test 1688 */ 1689HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_001, TestSize.Level0) 1690{ 1691 if (cellularMachine == nullptr) { 1692 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1693 cellularMachine = machine->CreateCellularDataConnect(0); 1694 cellularMachine->Init(); 1695 } 1696 SetupDataCallResultInfo dataCallInfo; 1697 cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo); 1698 EXPECT_NE(cellularMachine->stateMachineEventHandler_, nullptr); 1699} 1700 1701/** 1702 * @tc.number CellularDataStateMachine_UpdateNetworkInfoIfInActive_002 1703 * @tc.name test function branch 1704 * @tc.desc Function test 1705 */ 1706HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_002, TestSize.Level0) 1707{ 1708 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1709 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 1710 SetupDataCallResultInfo dataCallInfo; 1711 cellularMachine->stateMachineEventHandler_ = nullptr; 1712 cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo); 1713 EXPECT_EQ(cellularMachine->stateMachineEventHandler_, nullptr); 1714} 1715 1716/** 1717 * @tc.number CellularDataStateMachine_DoConnect_001 1718 * @tc.name test function branch 1719 * @tc.desc Function test 1720 */ 1721HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_001, TestSize.Level0) 1722{ 1723 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1724 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 1725 std::string proxyIpAddress = ""; 1726 std::string host; 1727 uint16_t port; 1728 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port); 1729 ASSERT_EQ(host, ""); 1730 ASSERT_EQ(port, 0); 1731} 1732 1733/** 1734 * @tc.number CellularDataStateMachine_DoConnect_001 1735 * @tc.name test function branch 1736 * @tc.desc Function test 1737 */ 1738HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_002, TestSize.Level0) 1739{ 1740 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1741 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 1742 std::string proxyIpAddress = "192.168.1.1"; 1743 std::string host; 1744 uint16_t port; 1745 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port); 1746 ASSERT_EQ(host, "192.168.1.1"); 1747 ASSERT_EQ(port, 0); 1748} 1749 1750/** 1751 * @tc.number CellularDataStateMachine_DoConnect_001 1752 * @tc.name test function branch 1753 * @tc.desc Function test 1754 */ 1755HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_003, TestSize.Level0) 1756{ 1757 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 1758 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 1759 std::string proxyIpAddress = "192.168.1.1:8080"; 1760 std::string host; 1761 uint16_t port; 1762 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port); 1763 ASSERT_EQ(host, "192.168.1.1"); 1764 ASSERT_EQ(port, 8080); 1765} 1766 1767/** 1768 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_001 1769 * @tc.name test function branch 1770 * @tc.desc Function test 1771 */ 1772HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_001, TestSize.Level0) 1773{ 1774 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 1775 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 1776 incallStateMachineTest->CreateIncallDataStateMachine(0); 1777 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1)) 1778 .WillOnce([](int32_t &dsdsMode) { 1779 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V3); 1780 return 0; 1781 }); 1782 auto result = incallStateMachine->IsSecondaryCanActiveData(); 1783 ASSERT_EQ(result, false); 1784} 1785 1786/** 1787 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_002 1788 * @tc.name test function branch 1789 * @tc.desc Function test 1790 */ 1791HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_002, TestSize.Level0) 1792{ 1793 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 1794 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 1795 incallStateMachineTest->CreateIncallDataStateMachine(0); 1796 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1)) 1797 .WillOnce([](int32_t &dsdsMode) { 1798 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2); 1799 return 0; 1800 }); 1801 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1)) 1802 .WillOnce([](int32_t &slotId) { 1803 slotId = INVALID_SLOT_ID; 1804 return 0; 1805 }); 1806 auto result = incallStateMachine->IsSecondaryCanActiveData(); 1807 ASSERT_EQ(result, false); 1808 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1)) 1809 .WillOnce([](int32_t &slotId) { 1810 slotId = 0; 1811 return 0; 1812 }); 1813 result = incallStateMachine->IsSecondaryCanActiveData(); 1814 ASSERT_EQ(result, false); 1815} 1816 1817/** 1818 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_002 1819 * @tc.name test function branch 1820 * @tc.desc Function test 1821 */ 1822HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_003, TestSize.Level0) 1823{ 1824 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 1825 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 1826 incallStateMachineTest->CreateIncallDataStateMachine(0); 1827 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1)) 1828 .WillOnce([](int32_t &dsdsMode) { 1829 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2); 1830 return 0; 1831 }); 1832 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1)) 1833 .WillOnce([](int32_t &slotId) { 1834 slotId = 1; 1835 return 0; 1836 }); 1837 auto result = incallStateMachine->IsSecondaryCanActiveData(); 1838 ASSERT_EQ(result, false); 1839} 1840 1841/** 1842 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004 1843 * @tc.name test function branch 1844 * @tc.desc Function test 1845 */ 1846HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_004, TestSize.Level0) 1847{ 1848 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 1849 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 1850 incallStateMachineTest->CreateIncallDataStateMachine(0); 1851 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1)) 1852 .WillOnce([](int32_t &dsdsMode) { 1853 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2); 1854 return 0; 1855 }); 1856 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1)) 1857 .WillOnce([](int32_t &slotId) { 1858 slotId = 1; 1859 return 0; 1860 }); 1861 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1)) 1862 .WillOnce([](int32_t slotId, bool &hasSimCard) { 1863 hasSimCard = true; 1864 return 0; 1865 }); 1866 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2)) 1867 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) { 1868 switch (imsSrvType) { 1869 case ImsServiceType::TYPE_VOICE: 1870 info.imsRegState = ImsRegState::IMS_UNREGISTERED; 1871 break; 1872 case ImsServiceType::TYPE_VIDEO: 1873 info.imsRegState = ImsRegState::IMS_UNREGISTERED; 1874 break; 1875 default: 1876 break; 1877 } 1878 return 0; 1879 }); 1880 auto result = incallStateMachine->IsSecondaryCanActiveData(); 1881 ASSERT_EQ(result, false); 1882} 1883 1884/** 1885 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004 1886 * @tc.name test function branch 1887 * @tc.desc Function test 1888 */ 1889HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_005, TestSize.Level0) 1890{ 1891 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 1892 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 1893 incallStateMachineTest->CreateIncallDataStateMachine(0); 1894 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1)) 1895 .WillOnce([](int32_t &dsdsMode) { 1896 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2); 1897 return 0; 1898 }); 1899 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1)) 1900 .WillOnce([](int32_t &slotId) { 1901 slotId = 1; 1902 return 0; 1903 }); 1904 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1)) 1905 .WillOnce([](int32_t slotId, bool &hasSimCard) { 1906 hasSimCard = true; 1907 return 0; 1908 }); 1909 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2)) 1910 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) { 1911 switch (imsSrvType) { 1912 case ImsServiceType::TYPE_VOICE: 1913 info.imsRegState = ImsRegState::IMS_REGISTERED ; 1914 break; 1915 case ImsServiceType::TYPE_VIDEO: 1916 info.imsRegState = ImsRegState::IMS_UNREGISTERED; 1917 break; 1918 default: 1919 break; 1920 } 1921 return 0; 1922 }); 1923 auto result = incallStateMachine->IsSecondaryCanActiveData(); 1924 ASSERT_EQ(result, false); 1925} 1926 1927/** 1928 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004 1929 * @tc.name test function branch 1930 * @tc.desc Function test 1931 */ 1932HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_006, TestSize.Level0) 1933{ 1934 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 1935 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 1936 incallStateMachineTest->CreateIncallDataStateMachine(0); 1937 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1)) 1938 .WillOnce([](int32_t &dsdsMode) { 1939 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2); 1940 return 0; 1941 }); 1942 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1)) 1943 .WillOnce([](int32_t &slotId) { 1944 slotId = 1; 1945 return 0; 1946 }); 1947 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1)) 1948 .WillOnce([](int32_t slotId, bool &hasSimCard) { 1949 hasSimCard = true; 1950 return 0; 1951 }); 1952 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2)) 1953 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) { 1954 switch (imsSrvType) { 1955 case ImsServiceType::TYPE_VOICE: 1956 info.imsRegState = ImsRegState::IMS_REGISTERED ; 1957 break; 1958 case ImsServiceType::TYPE_VIDEO: 1959 info.imsRegState = ImsRegState::IMS_REGISTERED; 1960 break; 1961 default: 1962 break; 1963 } 1964 return 0; 1965 }); 1966 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE); 1967 auto result = incallStateMachine->IsSecondaryCanActiveData(); 1968 ASSERT_EQ(result, false); 1969 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DISCONNECTED); 1970 result = incallStateMachine->IsSecondaryCanActiveData(); 1971 ASSERT_EQ(result, false); 1972 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DIALING); 1973 result = incallStateMachine->IsSecondaryCanActiveData(); 1974 ASSERT_EQ(result, false); 1975} 1976 1977/** 1978 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004 1979 * @tc.name test function branch 1980 * @tc.desc Function test 1981 */ 1982HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_007, TestSize.Level0) 1983{ 1984 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>(); 1985 std::shared_ptr<IncallDataStateMachine> incallStateMachine = 1986 incallStateMachineTest->CreateIncallDataStateMachine(0); 1987 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1)) 1988 .WillOnce([](int32_t &dsdsMode) { 1989 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2); 1990 return 0; 1991 }); 1992 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1)) 1993 .WillOnce([](int32_t &slotId) { 1994 slotId = 1; 1995 return 0; 1996 }); 1997 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1)) 1998 .WillOnce([](int32_t slotId, bool &hasSimCard) { 1999 hasSimCard = true; 2000 return 0; 2001 }); 2002 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2)) 2003 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) { 2004 switch (imsSrvType) { 2005 case ImsServiceType::TYPE_VOICE: 2006 info.imsRegState = ImsRegState::IMS_REGISTERED ; 2007 break; 2008 case ImsServiceType::TYPE_VIDEO: 2009 info.imsRegState = ImsRegState::IMS_REGISTERED; 2010 break; 2011 default: 2012 break; 2013 } 2014 return 0; 2015 }); 2016 EXPECT_CALL(*mockNetworkSearchManager, GetPsRadioTech(_, _)).Times(AtLeast(1)) 2017 .WillOnce([](int32_t slotId, int32_t &psRadioTech) { 2018 psRadioTech = static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_LTE); 2019 return 0; 2020 }); 2021 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DIALING); 2022 auto result = incallStateMachine->IsSecondaryCanActiveData(); 2023 ASSERT_EQ(result, true); 2024} 2025 2026/** 2027 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_001 2028 * @tc.name test function branch 2029 * @tc.desc Function test 2030 */ 2031HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_001, TestSize.Level0) 2032{ 2033 int32_t mtuSize = 0; 2034 int32_t slotId = 0; 2035 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 2036 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 2037 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1)) 2038 .WillOnce([](int32_t slotId, OperatorConfig &poc) { 2039 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:1500;ipv6:1400"; 2040 return 0; 2041 }); 2042 cellularMachine->ipType_ = "ipv4"; 2043 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId); 2044 ASSERT_EQ(mtuSize, 1500); 2045} 2046 2047/** 2048 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_002 2049 * @tc.name test function branch 2050 * @tc.desc Function test 2051 */ 2052HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_002, TestSize.Level0) 2053{ 2054 int32_t mtuSize = 0; 2055 int32_t slotId = 0; 2056 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 2057 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 2058 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1)) 2059 .WillOnce([](int32_t slotId, OperatorConfig &poc) { 2060 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:1500;ipv6:1400"; 2061 return 0; 2062 }); 2063 cellularMachine->ipType_ = "ipv6"; 2064 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId); 2065 ASSERT_EQ(mtuSize, 1400); 2066} 2067 2068/** 2069 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_003 2070 * @tc.name test function branch 2071 * @tc.desc Function test 2072 */ 2073HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_003, TestSize.Level0) 2074{ 2075 int32_t mtuSize = 0; 2076 int32_t slotId = 0; 2077 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 2078 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 2079 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1)) 2080 .WillOnce([](int32_t slotId, OperatorConfig &poc) { 2081 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:1500;ipv6:1400"; 2082 return 0; 2083 }); 2084 cellularMachine->ipType_ = "ipv5"; 2085 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId); 2086 ASSERT_EQ(mtuSize, 0); 2087} 2088 2089/** 2090 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_004 2091 * @tc.name test function branch 2092 * @tc.desc Function test 2093 */ 2094HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_004, TestSize.Level0) 2095{ 2096 int32_t mtuSize = 0; 2097 int32_t slotId = 0; 2098 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 2099 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 2100 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1)) 2101 .WillOnce([](int32_t slotId, OperatorConfig &poc) { 2102 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:abc;ipv6:1400"; 2103 return 0; 2104 }); 2105 cellularMachine->ipType_ = "ipv4"; 2106 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId); 2107 ASSERT_EQ(mtuSize, 0); 2108} 2109 2110/** 2111 * @tc.number CellularDataStateMachine_GetNetScoreBySlotId_001 2112 * @tc.name test function branch 2113 * @tc.desc Function test 2114 */ 2115HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetNetScoreBySlotId_001, TestSize.Level0) 2116{ 2117 int32_t score; 2118 int32_t slotId = 0; 2119 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 2120 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 2121 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1)) 2122 .WillOnce([]() { 2123 return 0; 2124 }); 2125 score = cellularMachine->GetNetScoreBySlotId(slotId); 2126 ASSERT_EQ(score, DEFAULT_INTERNET_CONNECTION_SCORE); 2127} 2128 2129/** 2130 * @tc.number CellularDataStateMachine_GetNetScoreBySlotId_002 2131 * @tc.name test function branch 2132 * @tc.desc Function test 2133 */ 2134HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetNetScoreBySlotId_002, TestSize.Level0) 2135{ 2136 int32_t score; 2137 int32_t slotId = 0; 2138 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 2139 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0); 2140 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1)) 2141 .WillOnce([]() { 2142 return 1; 2143 }); 2144 score = cellularMachine->GetNetScoreBySlotId(slotId); 2145 ASSERT_EQ(score, OTHER_CONNECTION_SCORE); 2146} 2147 2148/** 2149 * @tc.number Default_ProcessUpdateNetworkInfo_001 2150 * @tc.name test function branch 2151 * @tc.desc Function test 2152 */ 2153HWTEST_F(CellularStateMachineTest, Default_ProcessUpdateNetworkInfo_001, Function | MediumTest | Level1) 2154{ 2155 if (cellularMachine == nullptr) { 2156 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>(); 2157 cellularMachine = machine->CreateCellularDataConnect(0); 2158 cellularMachine->Init(); 2159 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1)) 2160 .WillOnce([]() { 2161 return 0; 2162 }); 2163 } 2164 auto defaultState = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr()); 2165 defaultState->stateMachine_ = cellularMachine; 2166 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_UPDATE_NETWORK_INFO); 2167 bool result = defaultState->ProcessUpdateNetworkInfo(event); 2168 EXPECT_EQ(result, true); 2169} 2170} // namespace Telephony 2171} // namespace OHOS