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
37 namespace OHOS {
38 namespace Telephony {
39 using namespace testing::ext;
40 using ::testing::_;
41 using ::testing::AtLeast;
42 using ::testing::DoAll;
43 using ::testing::Invoke;
44 using ::testing::Mock;
45 using ::testing::Return;
46 using ::testing::SetArgReferee;
47
48 class CellularStateMachineTest : public testing::Test {
49 public:
CellularStateMachineTest()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 };
SetUpTestCase()68 void CellularStateMachineTest::SetUpTestCase() {}
69
TearDownTestCase()70 void CellularStateMachineTest::TearDownTestCase() {}
71
SetUp()72 void CellularStateMachineTest::SetUp() {}
73
TearDown()74 void CellularStateMachineTest::TearDown() {}
75
76 class IncallDataStateMachineTest : public TelEventHandler {
77 public:
IncallDataStateMachineTest()78 IncallDataStateMachineTest() : TelEventHandler("IncallDataStateMachineTest") {}
79 ~IncallDataStateMachineTest() = default;
80 std::shared_ptr<IncallDataStateMachine> CreateIncallDataStateMachine(int32_t slotId);
81
82 public:
83 std::shared_ptr<IncallDataStateMachine> incallStateMachine_ = nullptr;
84 };
85
CreateIncallDataStateMachine(int32_t slotId)86 std::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
100 class CellularMachineTest : public TelEventHandler {
101 public:
CellularMachineTest()102 CellularMachineTest() : TelEventHandler("CellularDataStateMachineTest") {}
103 ~CellularMachineTest() = default;
104 std::shared_ptr<CellularDataStateMachine> CreateCellularDataConnect(int32_t slotId);
105
106 public:
107 std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_ = nullptr;
108 };
109
CreateCellularDataConnect(int32_t slotId)110 std::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 */
130 HWTEST_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 */
144 HWTEST_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 */
163 HWTEST_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 */
182 HWTEST_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 */
201 HWTEST_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 */
221 HWTEST_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 */
241 HWTEST_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 */
267 HWTEST_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 */
288 HWTEST_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 */
309 HWTEST_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 */
333 HWTEST_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 */
354 HWTEST_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 */
373 HWTEST_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 */
392 HWTEST_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 */
414 HWTEST_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 */
433 HWTEST_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 */
454 HWTEST_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 */
475 HWTEST_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 */
496 HWTEST_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 */
520 HWTEST_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 */
543 HWTEST_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->SetPdpErrorReason(PdpErrorReason::PDP_ERR_RETRY);
554 EXPECT_EQ(inactive->resultInfo_->reason, static_cast<int32_t>(PdpErrorReason::PDP_ERR_RETRY));
555 }
556
557 /**
558 * @tc.number InactiveStateProcess_002
559 * @tc.name test function branch
560 * @tc.desc Function test
561 */
562 HWTEST_F(CellularStateMachineTest, InactiveStateProcess_002, Function | MediumTest | Level1)
563 {
564 if (cellularMachine == nullptr) {
565 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
566 cellularMachine = machine->CreateCellularDataConnect(0);
567 cellularMachine->Init();
568 }
569 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
570 inactive->stateMachine_ = cellularMachine;
571 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT);
572 bool result = inactive->StateProcess(event);
573 EXPECT_EQ(result, true);
574 }
575
576 /**
577 * @tc.number InactiveStateProcess_003
578 * @tc.name test function branch
579 * @tc.desc Function test
580 */
581 HWTEST_F(CellularStateMachineTest, InactiveStateProcess_003, Function | MediumTest | Level1)
582 {
583 if (cellularMachine == nullptr) {
584 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
585 cellularMachine = machine->CreateCellularDataConnect(0);
586 cellularMachine->Init();
587 }
588 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
589 inactive->SetStateMachine(cellularMachine);
590 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT_ALL);
591 bool result = inactive->StateProcess(event);
592 EXPECT_EQ(result, true);
593 }
594
595 /**
596 * @tc.number Inactive_CellularDataStateMachine_001
597 * @tc.name test function branch
598 * @tc.desc Function test
599 */
600 HWTEST_F(CellularStateMachineTest, Inactive_CellularDataStateMachine_001, Function | MediumTest | Level1)
601 {
602 if (cellularMachine == nullptr) {
603 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
604 cellularMachine = machine->CreateCellularDataConnect(0);
605 cellularMachine->Init();
606 }
607 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
608 cellularMachine = nullptr;
609 inactive->stateMachine_ = cellularMachine;
610 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT_ALL);
611 bool result = inactive->StateProcess(event);
612 inactive->StateBegin();
613 EXPECT_EQ(result, false);
614 }
615
616 /**
617 * @tc.number DefaultStateProcess_001
618 * @tc.name test function branch
619 * @tc.desc Function test
620 */
621 HWTEST_F(CellularStateMachineTest, DefaultStateProcess_001, Function | MediumTest | Level1)
622 {
623 if (cellularMachine == nullptr) {
624 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
625 cellularMachine = machine->CreateCellularDataConnect(0);
626 cellularMachine->Init();
627 }
628 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
629 mDefault->stateMachine_ = cellularMachine;
630 mDefault->eventIdFunMap_.clear();
631 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
632 bool result = mDefault->StateProcess(event);
633 EXPECT_EQ(result, false);
634 }
635
636 /**
637 * @tc.number DefaultStateProcess_002
638 * @tc.name test function branch
639 * @tc.desc Function test
640 */
641 HWTEST_F(CellularStateMachineTest, DefaultStateProcess_002, Function | MediumTest | Level1)
642 {
643 if (cellularMachine == nullptr) {
644 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
645 cellularMachine = machine->CreateCellularDataConnect(0);
646 cellularMachine->Init();
647 }
648 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
649 cellularMachine = nullptr;
650 mDefault->stateMachine_ = cellularMachine;
651 mDefault->eventIdFunMap_.clear();
652 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
653 bool result = mDefault->StateProcess(event);
654 EXPECT_EQ(result, false);
655 }
656
657 /**
658 * @tc.number DefaultProcessDisconnectDone_001
659 * @tc.name test function branch
660 * @tc.desc Function test
661 */
662 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectDone_001, Function | MediumTest | Level1)
663 {
664 if (cellularMachine == nullptr) {
665 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
666 cellularMachine = machine->CreateCellularDataConnect(0);
667 cellularMachine->Init();
668 }
669 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
670 mDefault->stateMachine_ = cellularMachine;
671 mDefault->eventIdFunMap_.clear();
672 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
673 bool result = mDefault->ProcessDisconnectDone(event);
674 EXPECT_EQ(result, true);
675 }
676
677 /**
678 * @tc.number DefaultProcessDisconnectDone_002
679 * @tc.name test function branch
680 * @tc.desc Function test
681 */
682 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectDone_002, Function | MediumTest | Level1)
683 {
684 if (cellularMachine == nullptr) {
685 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
686 cellularMachine = machine->CreateCellularDataConnect(0);
687 cellularMachine->Init();
688 }
689 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
690 cellularMachine = nullptr;
691 mDefault->stateMachine_ = cellularMachine;
692 mDefault->eventIdFunMap_.clear();
693 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
694 bool result = mDefault->ProcessDisconnectDone(event);
695 EXPECT_EQ(result, false);
696 }
697
698 /**
699 * @tc.number DefaultProcessDisconnectAllDone_001
700 * @tc.name test function branch
701 * @tc.desc Function test
702 */
703 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectAllDone_001, Function | MediumTest | Level1)
704 {
705 if (cellularMachine == nullptr) {
706 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
707 cellularMachine = machine->CreateCellularDataConnect(0);
708 cellularMachine->Init();
709 }
710 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
711 mDefault->stateMachine_ = cellularMachine;
712 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
713 bool result = mDefault->ProcessDisconnectAllDone(event);
714 EXPECT_EQ(result, true);
715 }
716
717 /**
718 * @tc.number DefaultProcessDisconnectAllDone_002
719 * @tc.name test function branch
720 * @tc.desc Function test
721 */
722 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectAllDone_002, Function | MediumTest | Level1)
723 {
724 if (cellularMachine == nullptr) {
725 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
726 cellularMachine = machine->CreateCellularDataConnect(0);
727 cellularMachine->Init();
728 }
729 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
730 cellularMachine = nullptr;
731 mDefault->stateMachine_ = cellularMachine;
732 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
733 bool result = mDefault->ProcessDisconnectAllDone(event);
734 EXPECT_EQ(result, false);
735 }
736
737 /**
738 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_001
739 * @tc.name test function branch
740 * @tc.desc Function test
741 */
742 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_001, Function | MediumTest | Level1)
743 {
744 if (cellularMachine == nullptr) {
745 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
746 cellularMachine = machine->CreateCellularDataConnect(0);
747 cellularMachine->Init();
748 }
749 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
750 cellularMachine->TransitionTo(cellularMachine->activeState_);
751 mDefault->stateMachine_ = cellularMachine;
752 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
753 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
754 EXPECT_EQ(result, false);
755 }
756
757 /**
758 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_002
759 * @tc.name test function branch
760 * @tc.desc Function test
761 */
762 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_002, Function | MediumTest | Level1)
763 {
764 if (cellularMachine == nullptr) {
765 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
766 cellularMachine = machine->CreateCellularDataConnect(0);
767 cellularMachine->Init();
768 }
769 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
770 cellularMachine->TransitionTo(cellularMachine->activatingState_);
771 mDefault->stateMachine_ = cellularMachine;
772 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
773 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
774 EXPECT_EQ(result, false);
775 }
776
777 /**
778 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_003
779 * @tc.name test function branch
780 * @tc.desc Function test
781 */
782 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_003, Function | MediumTest | Level1)
783 {
784 if (cellularMachine == nullptr) {
785 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
786 cellularMachine = machine->CreateCellularDataConnect(0);
787 cellularMachine->Init();
788 }
789 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
790 cellularMachine->TransitionTo(cellularMachine->disconnectingState_);
791 mDefault->stateMachine_ = cellularMachine;
792 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
793 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
794 EXPECT_EQ(result, false);
795 }
796
797 /**
798 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_004
799 * @tc.name test function branch
800 * @tc.desc Function test
801 */
802 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_004, Function | MediumTest | Level1)
803 {
804 if (cellularMachine == nullptr) {
805 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
806 cellularMachine = machine->CreateCellularDataConnect(0);
807 cellularMachine->Init();
808 }
809 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
810 cellularMachine = nullptr;
811 mDefault->stateMachine_ = cellularMachine;
812 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
813 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
814 EXPECT_EQ(result, false);
815 }
816
817 /**
818 * @tc.number Active_StateBegin_001
819 * @tc.name test function branch
820 * @tc.desc Function test
821 */
822 HWTEST_F(CellularStateMachineTest, Active_StateBegin_001, Function | MediumTest | Level1)
823 {
824 if (cellularMachine == nullptr) {
825 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
826 cellularMachine = machine->CreateCellularDataConnect(0);
827 cellularMachine->Init();
828 }
829 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
830 active->stateMachine_ = cellularMachine;
831 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
832 active->StateBegin();
833 EXPECT_EQ(active->isActive_, true);
834 }
835
836 /**
837 * @tc.number Active_StateProcess_001
838 * @tc.name test function branch
839 * @tc.desc Function test
840 */
841 HWTEST_F(CellularStateMachineTest, Active_StateProcess_001, Function | MediumTest | Level1)
842 {
843 if (cellularMachine == nullptr) {
844 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
845 cellularMachine = machine->CreateCellularDataConnect(0);
846 cellularMachine->Init();
847 }
848 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
849 active->stateMachine_ = cellularMachine;
850 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
851 bool result = active->StateProcess(event);
852 EXPECT_EQ(result, true);
853 }
854
855 /**
856 * @tc.number Active_StateProcess_002
857 * @tc.name test function branch
858 * @tc.desc Function test
859 */
860 HWTEST_F(CellularStateMachineTest, Active_StateProcess_002, Function | MediumTest | Level1)
861 {
862 if (cellularMachine == nullptr) {
863 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
864 cellularMachine = machine->CreateCellularDataConnect(0);
865 cellularMachine->Init();
866 }
867 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
868 active->stateMachine_ = cellularMachine;
869 auto event = AppExecFwk::InnerEvent::Get(0);
870 bool result = active->StateProcess(event);
871 EXPECT_EQ(result, false);
872 }
873
874 /**
875 * @tc.number Active_StateProcess_003
876 * @tc.name test function branch
877 * @tc.desc Function test
878 */
879 HWTEST_F(CellularStateMachineTest, Active_StateProcess_003, Function | MediumTest | Level1)
880 {
881 if (cellularMachine == nullptr) {
882 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
883 cellularMachine = machine->CreateCellularDataConnect(0);
884 cellularMachine->Init();
885 }
886 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
887 cellularMachine = nullptr;
888 active->stateMachine_ = cellularMachine;
889 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
890 bool result = active->StateProcess(event);
891 EXPECT_EQ(result, true);
892 }
893
894 /**
895 * @tc.number Active_ProcessDisconnectDone_001
896 * @tc.name test function branch
897 * @tc.desc Function test
898 */
899 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_001, Function | MediumTest | Level1)
900 {
901 if (cellularMachine == nullptr) {
902 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
903 cellularMachine = machine->CreateCellularDataConnect(0);
904 cellularMachine->Init();
905 }
906 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
907 active->stateMachine_ = cellularMachine;
908 auto event = AppExecFwk::InnerEvent::Get(0);
909 event = nullptr;
910 bool result = active->ProcessDisconnectDone(event);
911 EXPECT_EQ(result, false);
912 }
913
914 /**
915 * @tc.number Active_ProcessDisconnectDone_002
916 * @tc.name test function branch
917 * @tc.desc Function test
918 */
919 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_002, Function | MediumTest | Level1)
920 {
921 if (cellularMachine == nullptr) {
922 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
923 cellularMachine = machine->CreateCellularDataConnect(0);
924 cellularMachine->Init();
925 }
926 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
927 active->stateMachine_ = cellularMachine;
928 auto event = AppExecFwk::InnerEvent::Get(0);
929 bool result = active->ProcessDisconnectDone(event);
930 EXPECT_EQ(result, false);
931 }
932
933 /**
934 * @tc.number Active_ProcessDisconnectAllDone_001
935 * @tc.name test function branch
936 * @tc.desc Function test
937 */
938 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_001, Function | MediumTest | Level1)
939 {
940 if (cellularMachine == nullptr) {
941 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
942 cellularMachine = machine->CreateCellularDataConnect(0);
943 cellularMachine->Init();
944 }
945 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
946 active->stateMachine_ = cellularMachine;
947 auto event = AppExecFwk::InnerEvent::Get(0);
948 event = nullptr;
949 bool result = active->ProcessDisconnectAllDone(event);
950 EXPECT_EQ(result, false);
951 }
952
953 /**
954 * @tc.number Active_ProcessDisconnectAllDone_002
955 * @tc.name test function branch
956 * @tc.desc Function test
957 */
958 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_002, Function | MediumTest | Level1)
959 {
960 if (cellularMachine == nullptr) {
961 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
962 cellularMachine = machine->CreateCellularDataConnect(0);
963 cellularMachine->Init();
964 }
965 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
966 active->stateMachine_ = cellularMachine;
967 auto event = AppExecFwk::InnerEvent::Get(0);
968 bool result = active->ProcessDisconnectAllDone(event);
969 EXPECT_EQ(result, false);
970 }
971
972 /**
973 * @tc.number Active_ProcessDisconnectAllDone_003
974 * @tc.name test function branch
975 * @tc.desc Function test
976 */
977 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_003, Function | MediumTest | Level1)
978 {
979 if (cellularMachine == nullptr) {
980 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
981 cellularMachine = machine->CreateCellularDataConnect(0);
982 cellularMachine->Init();
983 }
984 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
985 cellularMachine->TransitionTo(cellularMachine->inActiveState_);
986 active->stateMachine_ = cellularMachine;
987 std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
988 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
989 auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams);
990 bool result = active->ProcessDisconnectAllDone(event);
991 EXPECT_EQ(result, false);
992 }
993
994 /**
995 * @tc.number Active_ProcessDisconnectAllDone_004
996 * @tc.name test function branch
997 * @tc.desc Function test
998 */
999 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_004, Function | MediumTest | Level1)
1000 {
1001 if (cellularMachine == nullptr) {
1002 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1003 cellularMachine = machine->CreateCellularDataConnect(0);
1004 cellularMachine->Init();
1005 }
1006 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1007 cellularMachine->inActiveState_ = nullptr;
1008 active->stateMachine_ = cellularMachine;
1009 std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
1010 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
1011 auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams);
1012 bool result = active->ProcessDisconnectAllDone(event);
1013 EXPECT_EQ(result, false);
1014 }
1015
1016 /**
1017 * @tc.number Active_ProcessLinkCapabilityChanged_001
1018 * @tc.name test function branch
1019 * @tc.desc Function test
1020 */
1021 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_001, Function | MediumTest | Level1)
1022 {
1023 if (cellularMachine == nullptr) {
1024 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1025 cellularMachine = machine->CreateCellularDataConnect(0);
1026 cellularMachine->Init();
1027 }
1028 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1029 active->stateMachine_ = cellularMachine;
1030 auto event = AppExecFwk::InnerEvent::Get(0);
1031 bool result = active->ProcessLinkCapabilityChanged(event);
1032 EXPECT_EQ(result, false);
1033 }
1034
1035 /**
1036 * @tc.number Active_ProcessLinkCapabilityChanged_002
1037 * @tc.name test function branch
1038 * @tc.desc Function test
1039 */
1040 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_002, Function | MediumTest | Level1)
1041 {
1042 if (cellularMachine == nullptr) {
1043 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1044 cellularMachine = machine->CreateCellularDataConnect(0);
1045 cellularMachine->Init();
1046 }
1047 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1048 cellularMachine = nullptr;
1049 active->stateMachine_ = cellularMachine;
1050 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
1051 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1052 bool result = active->ProcessLinkCapabilityChanged(event);
1053 EXPECT_EQ(result, false);
1054 }
1055
1056 /**
1057 * @tc.number Active_ProcessLinkCapabilityChanged_003
1058 * @tc.name test function branch
1059 * @tc.desc Function test
1060 */
1061 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_003, Function | MediumTest | Level1)
1062 {
1063 if (cellularMachine == nullptr) {
1064 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1065 cellularMachine = machine->CreateCellularDataConnect(0);
1066 cellularMachine->Init();
1067 }
1068 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1069 active->stateMachine_ = cellularMachine;
1070 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
1071 linkCapability->primaryUplinkKbps = 0;
1072 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1073 bool result = active->ProcessLinkCapabilityChanged(event);
1074 EXPECT_EQ(result, true);
1075 }
1076
1077 /**
1078 * @tc.number Active_ProcessLinkCapabilityChanged_004
1079 * @tc.name test function branch
1080 * @tc.desc Function test
1081 */
1082 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_004, Function | MediumTest | Level1)
1083 {
1084 if (cellularMachine == nullptr) {
1085 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1086 cellularMachine = machine->CreateCellularDataConnect(0);
1087 cellularMachine->Init();
1088 }
1089 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1090 active->stateMachine_ = cellularMachine;
1091 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
1092 linkCapability->primaryUplinkKbps = 1;
1093 linkCapability->primaryDownlinkKbps = 0;
1094 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1095 bool result = active->ProcessLinkCapabilityChanged(event);
1096 EXPECT_EQ(result, true);
1097 }
1098
1099 /**
1100 * @tc.number Active_ProcessLinkCapabilityChanged_005
1101 * @tc.name test function branch
1102 * @tc.desc Function test
1103 */
1104 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_005, Function | MediumTest | Level1)
1105 {
1106 if (cellularMachine == nullptr) {
1107 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1108 cellularMachine = machine->CreateCellularDataConnect(0);
1109 cellularMachine->Init();
1110 }
1111 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1112 active->stateMachine_ = cellularMachine;
1113 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
1114 linkCapability->primaryUplinkKbps = 1;
1115 linkCapability->primaryDownlinkKbps = 1;
1116 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1117 bool result = active->ProcessLinkCapabilityChanged(event);
1118 EXPECT_EQ(result, true);
1119 }
1120
1121 /**
1122 * @tc.number Active_ProcessDataConnectionComplete_001
1123 * @tc.name test function branch
1124 * @tc.desc Function test
1125 */
1126 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_001, Function | MediumTest | Level1)
1127 {
1128 if (cellularMachine == nullptr) {
1129 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1130 cellularMachine = machine->CreateCellularDataConnect(0);
1131 cellularMachine->Init();
1132 }
1133 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1134 active->stateMachine_ = cellularMachine;
1135 auto event = AppExecFwk::InnerEvent::Get(0);
1136 bool result = active->ProcessDataConnectionComplete(event);
1137 EXPECT_EQ(result, false);
1138 }
1139
1140 /**
1141 * @tc.number Active_ProcessDataConnectionComplete_002
1142 * @tc.name test function branch
1143 * @tc.desc Function test
1144 */
1145 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_002, Function | MediumTest | Level1)
1146 {
1147 if (cellularMachine == nullptr) {
1148 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1149 cellularMachine = machine->CreateCellularDataConnect(0);
1150 cellularMachine->Init();
1151 }
1152 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1153 cellularMachine = nullptr;
1154 active->stateMachine_ = cellularMachine;
1155 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
1156 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
1157 bool result = active->ProcessDataConnectionComplete(event);
1158 EXPECT_EQ(result, false);
1159 }
1160
1161 /**
1162 * @tc.number Active_ProcessDataConnectionComplete_003
1163 * @tc.name test function branch
1164 * @tc.desc Function test
1165 */
1166 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_003, Function | MediumTest | Level1)
1167 {
1168 if (cellularMachine == nullptr) {
1169 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1170 cellularMachine = machine->CreateCellularDataConnect(0);
1171 cellularMachine->Init();
1172 }
1173 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1174 active->stateMachine_ = cellularMachine;
1175 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
1176 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
1177 bool result = active->ProcessDataConnectionComplete(event);
1178 EXPECT_EQ(result, true);
1179 }
1180
1181 /**
1182 * @tc.number Active_ProcessDataConnectionComplete_004
1183 * @tc.name test function branch
1184 * @tc.desc Function test
1185 */
1186 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_004, Function | MediumTest | Level1)
1187 {
1188 if (cellularMachine == nullptr) {
1189 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1190 cellularMachine = machine->CreateCellularDataConnect(0);
1191 cellularMachine->Init();
1192 }
1193 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1194 cellularMachine->stateMachineEventHandler_ = nullptr;
1195 active->stateMachine_ = cellularMachine;
1196 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
1197 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
1198 bool result = active->ProcessDataConnectionComplete(event);
1199 EXPECT_EQ(result, false);
1200 }
1201
1202 /**
1203 * @tc.number Active_ProcessNrStateChanged_001
1204 * @tc.name test function branch
1205 * @tc.desc Function test
1206 */
1207 HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_001, Function | MediumTest | Level1)
1208 {
1209 if (cellularMachine == nullptr) {
1210 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1211 cellularMachine = machine->CreateCellularDataConnect(0);
1212 cellularMachine->Init();
1213 }
1214 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1215 active->stateMachine_ = cellularMachine;
1216 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1217 bool result = active->ProcessNrStateChanged(event);
1218 EXPECT_EQ(result, true);
1219 }
1220
1221 /**
1222 * @tc.number Active_ProcessNrStateChanged_002
1223 * @tc.name test function branch
1224 * @tc.desc Function test
1225 */
1226 HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_002, Function | MediumTest | Level1)
1227 {
1228 if (cellularMachine == nullptr) {
1229 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1230 cellularMachine = machine->CreateCellularDataConnect(0);
1231 cellularMachine->Init();
1232 }
1233 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1234 cellularMachine = nullptr;
1235 active->stateMachine_ = cellularMachine;
1236 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1237 bool result = active->ProcessNrStateChanged(event);
1238 EXPECT_EQ(result, false);
1239 }
1240
1241 /**
1242 * @tc.number Active_ProcessNrFrequencyChanged_001
1243 * @tc.name test function branch
1244 * @tc.desc Function test
1245 */
1246 HWTEST_F(CellularStateMachineTest, Active_ProcessNrFrequencyChanged_001, Function | MediumTest | Level1)
1247 {
1248 if (cellularMachine == nullptr) {
1249 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1250 cellularMachine = machine->CreateCellularDataConnect(0);
1251 cellularMachine->Init();
1252 }
1253 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1254 cellularMachine = nullptr;
1255 active->stateMachine_ = cellularMachine;
1256 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1257 bool result = active->ProcessNrFrequencyChanged(event);
1258 EXPECT_EQ(result, false);
1259 }
1260
1261 /**
1262 * @tc.number Active_ProcessDisconnectAllDone_001
1263 * @tc.name test function branch
1264 * @tc.desc Function test
1265 */
1266 HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_001, Function | MediumTest | Level1)
1267 {
1268 if (cellularMachine == nullptr) {
1269 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1270 cellularMachine = machine->CreateCellularDataConnect(0);
1271 cellularMachine->Init();
1272 }
1273 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1274 cellularMachine->TransitionTo(cellularMachine->inActiveState_);
1275 active->stateMachine_ = cellularMachine;
1276 auto event = AppExecFwk::InnerEvent::Get(0);
1277 bool result = active->ProcessLostConnection(event);
1278 EXPECT_EQ(result, false);
1279 }
1280
1281 /**
1282 * @tc.number Active_ProcessLostConnection_002
1283 * @tc.name test function branch
1284 * @tc.desc Function test
1285 */
1286 HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_002, Function | MediumTest | Level1)
1287 {
1288 if (cellularMachine == nullptr) {
1289 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1290 cellularMachine = machine->CreateCellularDataConnect(0);
1291 cellularMachine->Init();
1292 }
1293 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1294 cellularMachine->inActiveState_ = nullptr;
1295 active->stateMachine_ = cellularMachine;
1296 auto event = AppExecFwk::InnerEvent::Get(0);
1297 bool result = active->ProcessLostConnection(event);
1298 EXPECT_EQ(result, false);
1299 }
1300
1301 /**
1302 * @tc.number Active_ProcessDataConnectionRoamOn_001
1303 * @tc.name test function branch
1304 * @tc.desc Function test
1305 */
1306 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOn_001, Function | MediumTest | Level1)
1307 {
1308 if (cellularMachine == nullptr) {
1309 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1310 cellularMachine = machine->CreateCellularDataConnect(0);
1311 cellularMachine->Init();
1312 }
1313 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1314 active->stateMachine_ = cellularMachine;
1315 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1316 bool result = active->ProcessDataConnectionRoamOn(event);
1317 EXPECT_EQ(result, true);
1318 }
1319
1320 /**
1321 * @tc.number Active_ProcessDataConnectionRoamOff_001
1322 * @tc.name test function branch
1323 * @tc.desc Function test
1324 */
1325 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOff_001, Function | MediumTest | Level1)
1326 {
1327 if (cellularMachine == nullptr) {
1328 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1329 cellularMachine = machine->CreateCellularDataConnect(0);
1330 cellularMachine->Init();
1331 }
1332 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1333 active->stateMachine_ = cellularMachine;
1334 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1335 bool result = active->ProcessDataConnectionRoamOff(event);
1336 EXPECT_EQ(result, true);
1337 }
1338
1339 /**
1340 * @tc.number Active_ProcessDataConnectionVoiceCallStartedOrEnded_001
1341 * @tc.name test function branch
1342 * @tc.desc Function test
1343 */
1344 HWTEST_F(CellularStateMachineTest, ProcessDataConnectionVoiceCallStartedOrEnded_001, Function | MediumTest | Level1)
1345 {
1346 if (cellularMachine == nullptr) {
1347 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1348 cellularMachine = machine->CreateCellularDataConnect(0);
1349 cellularMachine->Init();
1350 }
1351 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1352 active->stateMachine_ = cellularMachine;
1353 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1354 bool result = active->ProcessDataConnectionVoiceCallStartedOrEnded(event);
1355 EXPECT_EQ(result, true);
1356 }
1357
1358 /**
1359 * @tc.number CellularDataStateMachine_GetSlotId_001
1360 * @tc.name test function branch
1361 * @tc.desc Function test
1362 */
1363 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetSlotId_001, Function | MediumTest | Level1)
1364 {
1365 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1366 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1367 int result = cellularMachine->GetSlotId();
1368 ASSERT_EQ(result, DEFAULT_SIM_SLOT_ID);
1369 }
1370
1371 /**
1372 * @tc.number CellularDataStateMachine_HasMatchedIpTypeAddrs_001
1373 * @tc.name test function branch
1374 * @tc.desc Function test
1375 */
1376 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_001, Function | MediumTest | Level1)
1377 {
1378 if (cellularMachine == nullptr) {
1379 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1380 cellularMachine = machine->CreateCellularDataConnect(0);
1381 cellularMachine->Init();
1382 }
1383 uint8_t ipType = 1;
1384 uint8_t ipInfoArraySize = 2;
1385 std::vector<AddressInfo> ipInfoArray;
1386 AddressInfo info1;
1387 info1.type = 1;
1388 AddressInfo info2;
1389 info2.type = 3;
1390 ipInfoArray.push_back(info1);
1391 ipInfoArray.push_back(info2);
1392 bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray);
1393 ASSERT_TRUE(result);
1394 }
1395
1396 /**
1397 * @tc.number CellularDataStateMachine_HasMatchedIpTypeAddrs_002
1398 * @tc.name test function branch
1399 * @tc.desc Function test
1400 */
1401 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_002, Function | MediumTest | Level1)
1402 {
1403 if (cellularMachine == nullptr) {
1404 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1405 cellularMachine = machine->CreateCellularDataConnect(0);
1406 cellularMachine->Init();
1407 }
1408 uint8_t ipType = 5;
1409 uint8_t ipInfoArraySize = 2;
1410 std::vector<AddressInfo> ipInfoArray;
1411 AddressInfo info1;
1412 info1.type = 1;
1413 AddressInfo info2;
1414 info2.type = 3;
1415 ipInfoArray.push_back(info1);
1416 ipInfoArray.push_back(info2);
1417 bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray);
1418 ASSERT_FALSE(result);
1419 }
1420
1421 /**
1422 * @tc.number GetIpType_ShouldReturnIPV4V6_001
1423 * @tc.name test function branch
1424 * @tc.desc Function test
1425 */
1426 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_001, TestSize.Level0)
1427 {
1428 if (cellularMachine == nullptr) {
1429 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1430 cellularMachine = machine->CreateCellularDataConnect(0);
1431 cellularMachine->Init();
1432 }
1433 std::vector<AddressInfo> ipInfoArray;
1434 AddressInfo info1;
1435 info1.type = INetAddr::IpType::IPV4;
1436 AddressInfo info2;
1437 info2.type = INetAddr::IpType::IPV6;
1438 ipInfoArray.push_back(info1);
1439 ipInfoArray.push_back(info2);
1440 std::string result = cellularMachine->GetIpType(ipInfoArray);
1441 ASSERT_EQ(result, "IPV4V6");
1442 }
1443
1444 /**
1445 * @tc.number GetIpType_ShouldReturnIPV4V6_002
1446 * @tc.name test function branch
1447 * @tc.desc Function test
1448 */
1449 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_002, TestSize.Level0)
1450 {
1451 if (cellularMachine == nullptr) {
1452 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1453 cellularMachine = machine->CreateCellularDataConnect(0);
1454 cellularMachine->Init();
1455 }
1456 std::vector<AddressInfo> ipInfoArray;
1457 AddressInfo info1;
1458 info1.type = INetAddr::IpType::IPV4;
1459 ipInfoArray.push_back(info1);
1460 std::string result = cellularMachine->GetIpType(ipInfoArray);
1461 ASSERT_EQ(result, "IPV4");
1462 }
1463
1464 /**
1465 * @tc.number GetIpType_ShouldReturnIPV6_003
1466 * @tc.name test function branch
1467 * @tc.desc Function test
1468 */
1469 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV6_003, TestSize.Level0)
1470 {
1471 if (cellularMachine == nullptr) {
1472 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1473 cellularMachine = machine->CreateCellularDataConnect(0);
1474 cellularMachine->Init();
1475 }
1476 std::vector<AddressInfo> ipInfoArray;
1477 AddressInfo info2;
1478 info2.type = INetAddr::IpType::IPV6;
1479 ipInfoArray.push_back(info2);
1480 std::string result = cellularMachine->GetIpType(ipInfoArray);
1481 ASSERT_EQ(result, "IPV6");
1482 }
1483
1484 /**
1485 * @tc.number GetIpType_ShouldReturnEmpty_004
1486 * @tc.name test function branch
1487 * @tc.desc Function test
1488 */
1489 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnEmpty_004, TestSize.Level0)
1490 {
1491 if (cellularMachine == nullptr) {
1492 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1493 cellularMachine = machine->CreateCellularDataConnect(0);
1494 cellularMachine->Init();
1495 }
1496 std::vector<AddressInfo> ipInfoArray = {};
1497 std::string result = cellularMachine->GetIpType(ipInfoArray);
1498 ASSERT_EQ(result, "");
1499 }
1500
1501 /**
1502 * @tc.number GetIpType_ShouldReturnIPV4V6_005
1503 * @tc.name test function branch
1504 * @tc.desc Function test
1505 */
1506 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_005, TestSize.Level0)
1507 {
1508 if (cellularMachine == nullptr) {
1509 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1510 cellularMachine = machine->CreateCellularDataConnect(0);
1511 cellularMachine->Init();
1512 }
1513 std::vector<AddressInfo> ipInfoArray;
1514 AddressInfo info1;
1515 info1.type = 5;
1516 AddressInfo info2;
1517 info2.type = 6;
1518 ipInfoArray.push_back(info1);
1519 ipInfoArray.push_back(info2);
1520 std::string result = cellularMachine->GetIpType(ipInfoArray);
1521 ASSERT_EQ(result, "");
1522 }
1523
1524 /**
1525 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_001
1526 * @tc.name test function branch
1527 * @tc.desc Function test
1528 */
1529 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_001, TestSize.Level0) {
1530 if (cellularMachine == nullptr) {
1531 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1532 cellularMachine = machine->CreateCellularDataConnect(0);
1533 cellularMachine->Init();
1534 }
1535 SetupDataCallResultInfo dataCallInfo;
1536 dataCallInfo.address = "";
1537 dataCallInfo.dns = "";
1538 dataCallInfo.dnsSec = "";
1539 dataCallInfo.gateway = "";
1540 cellularMachine->UpdateNetworkInfo(dataCallInfo);
1541 ASSERT_EQ(cellularMachine->cause_, 0);
1542 }
1543
1544 /**
1545 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_002
1546 * @tc.name test function branch
1547 * @tc.desc Function test
1548 */
1549 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_002, TestSize.Level0) {
1550 if (cellularMachine == nullptr) {
1551 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1552 cellularMachine = machine->CreateCellularDataConnect(0);
1553 cellularMachine->Init();
1554 }
1555 SetupDataCallResultInfo dataCallInfo;
1556 dataCallInfo.address = "192.168.1.1";
1557 dataCallInfo.dns = "192.168.1.1";
1558 dataCallInfo.dnsSec = "192.168.1.1";
1559 dataCallInfo.gateway = "192.168.1.1";
1560 dataCallInfo.reason = 1;
1561 cellularMachine->UpdateNetworkInfo(dataCallInfo);
1562 ASSERT_EQ(cellularMachine->cause_, 1);
1563 }
1564
1565 /**
1566 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_003
1567 * @tc.name test function branch
1568 * @tc.desc Function test
1569 */
1570 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_003, TestSize.Level0) {
1571 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1572 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1573 SetupDataCallResultInfo dataCallInfo;
1574 dataCallInfo.address = "192.168.1.1";
1575 dataCallInfo.dns = "192.168.1.1";
1576 dataCallInfo.dnsSec = "192.168.1.1";
1577 dataCallInfo.gateway = "192.168.1.1";
1578 dataCallInfo.reason = 1;
1579 cellularMachine->UpdateNetworkInfo(dataCallInfo);
1580 ASSERT_EQ(cellularMachine->cause_, 0);
1581 }
1582
1583 /**
1584 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_004
1585 * @tc.name test function branch
1586 * @tc.desc Function test
1587 */
1588 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_004, TestSize.Level0) {
1589 if (cellularMachine == nullptr) {
1590 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1591 cellularMachine = machine->CreateCellularDataConnect(0);
1592 cellularMachine->Init();
1593 }
1594 cellularMachine->netSupplierInfo_->isAvailable_ = true;
1595 cellularMachine->UpdateNetworkInfo();
1596 ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr);
1597 }
1598
1599 /**
1600 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_005
1601 * @tc.name test function branch
1602 * @tc.desc Function test
1603 */
1604 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_005, TestSize.Level0) {
1605 if (cellularMachine == nullptr) {
1606 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1607 cellularMachine = machine->CreateCellularDataConnect(0);
1608 cellularMachine->Init();
1609 }
1610 cellularMachine->netSupplierInfo_->isAvailable_ = false;
1611 cellularMachine->UpdateNetworkInfo();
1612 ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr);
1613 }
1614
1615 /**
1616 * @tc.number CellularDataStateMachine_ResolveRoute_001
1617 * @tc.name test function branch
1618 * @tc.desc Function test
1619 */
1620 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_001, TestSize.Level0)
1621 {
1622 if (cellularMachine == nullptr) {
1623 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1624 cellularMachine = machine->CreateCellularDataConnect(0);
1625 cellularMachine->Init();
1626 }
1627 std::vector<AddressInfo> routeInfoArray;
1628 cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1629 EXPECT_TRUE(cellularMachine->netLinkInfo_->routeList_.empty());
1630 }
1631
1632 /**
1633 * @tc.number CellularDataStateMachine_ResolveRoute_002
1634 * @tc.name test function branch
1635 * @tc.desc Function test
1636 */
1637 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_002, TestSize.Level0)
1638 {
1639 if (cellularMachine == nullptr) {
1640 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1641 cellularMachine = machine->CreateCellularDataConnect(0);
1642 cellularMachine->Init();
1643 }
1644 std::vector<AddressInfo> routeInfoArray;
1645 AddressInfo routeInfo;
1646 routeInfo.ip = "192.168.1.1";
1647 routeInfo.type = INetAddr::IpType::IPV4;
1648 routeInfo.prefixLen = 24;
1649 routeInfoArray.push_back(routeInfo);
1650 cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1651 EXPECT_FALSE(cellularMachine->netLinkInfo_->routeList_.empty());
1652 }
1653
1654 /**
1655 * @tc.number CellularDataStateMachine_ResolveRoute_003
1656 * @tc.name test function branch
1657 * @tc.desc Function test
1658 */
1659 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_003, TestSize.Level0)
1660 {
1661 if (cellularMachine == nullptr) {
1662 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1663 cellularMachine = machine->CreateCellularDataConnect(0);
1664 cellularMachine->Init();
1665 }
1666 std::vector<AddressInfo> routeInfoArray;
1667 AddressInfo routeInfo1;
1668 routeInfo1.ip = "192.168.1.1";
1669 routeInfo1.type = INetAddr::IpType::IPV4;
1670 routeInfo1.prefixLen = 24;
1671 routeInfoArray.push_back(routeInfo1);
1672 AddressInfo routeInfo2;
1673 routeInfo2.ip = "2001:db8::1";
1674 routeInfo2.type = INetAddr::IpType::IPV6;
1675 routeInfo2.prefixLen = 64;
1676 routeInfoArray.push_back(routeInfo2);
1677 cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1678 EXPECT_EQ(cellularMachine->netLinkInfo_->routeList_.size(), 2);
1679 }
1680
1681 /**
1682 * @tc.number CellularDataStateMachine_UpdateNetworkInfoIfInActive_001
1683 * @tc.name test function branch
1684 * @tc.desc Function test
1685 */
1686 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_001, TestSize.Level0)
1687 {
1688 if (cellularMachine == nullptr) {
1689 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1690 cellularMachine = machine->CreateCellularDataConnect(0);
1691 cellularMachine->Init();
1692 }
1693 SetupDataCallResultInfo dataCallInfo;
1694 cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo);
1695 EXPECT_NE(cellularMachine->stateMachineEventHandler_, nullptr);
1696 }
1697
1698 /**
1699 * @tc.number CellularDataStateMachine_UpdateNetworkInfoIfInActive_002
1700 * @tc.name test function branch
1701 * @tc.desc Function test
1702 */
1703 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_002, TestSize.Level0)
1704 {
1705 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1706 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1707 SetupDataCallResultInfo dataCallInfo;
1708 cellularMachine->stateMachineEventHandler_ = nullptr;
1709 cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo);
1710 EXPECT_EQ(cellularMachine->stateMachineEventHandler_, nullptr);
1711 }
1712
1713 /**
1714 * @tc.number CellularDataStateMachine_SplitProxyIpAddress_001
1715 * @tc.name test function branch
1716 * @tc.desc Function test
1717 */
1718 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_001, TestSize.Level0)
1719 {
1720 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1721 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1722 std::string proxyIpAddress = "";
1723 std::string host;
1724 uint16_t port;
1725 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port);
1726 ASSERT_EQ(host, "");
1727 ASSERT_EQ(port, 0);
1728 }
1729
1730 /**
1731 * @tc.number CellularDataStateMachine_SplitProxyIpAddress_002
1732 * @tc.name test function branch
1733 * @tc.desc Function test
1734 */
1735 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_002, TestSize.Level0)
1736 {
1737 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1738 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1739 std::string proxyIpAddress = "192.168.1.1";
1740 std::string host;
1741 uint16_t port;
1742 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port);
1743 ASSERT_EQ(host, "192.168.1.1");
1744 ASSERT_EQ(port, 0);
1745 }
1746
1747 /**
1748 * @tc.number CellularDataStateMachine_SplitProxyIpAddress_003
1749 * @tc.name test function branch
1750 * @tc.desc Function test
1751 */
1752 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_003, TestSize.Level0)
1753 {
1754 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1755 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1756 std::string proxyIpAddress = "192.168.1.1:8080";
1757 std::string host;
1758 uint16_t port;
1759 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port);
1760 ASSERT_EQ(host, "192.168.1.1");
1761 ASSERT_EQ(port, 8080);
1762 }
1763
1764 /**
1765 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_001
1766 * @tc.name test function branch
1767 * @tc.desc Function test
1768 */
1769 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_001, TestSize.Level0)
1770 {
1771 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1772 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1773 incallStateMachineTest->CreateIncallDataStateMachine(0);
1774 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anon9b60741f0102(int32_t &dsdsMode) 1775 .WillOnce([](int32_t &dsdsMode) {
1776 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V3);
1777 return 0;
1778 });
1779 auto result = incallStateMachine->IsSecondaryCanActiveData();
1780 ASSERT_EQ(result, false);
1781 }
1782
1783 /**
1784 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_002
1785 * @tc.name test function branch
1786 * @tc.desc Function test
1787 */
1788 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_002, TestSize.Level0)
1789 {
1790 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1791 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1792 incallStateMachineTest->CreateIncallDataStateMachine(0);
1793 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anon9b60741f0202(int32_t &dsdsMode) 1794 .WillOnce([](int32_t &dsdsMode) {
1795 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1796 return 0;
1797 });
1798 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anon9b60741f0302(int32_t &slotId) 1799 .WillOnce([](int32_t &slotId) {
1800 slotId = INVALID_SLOT_ID;
1801 return 0;
1802 });
1803 auto result = incallStateMachine->IsSecondaryCanActiveData();
1804 ASSERT_EQ(result, false);
1805 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anon9b60741f0402(int32_t &slotId) 1806 .WillOnce([](int32_t &slotId) {
1807 slotId = 0;
1808 return 0;
1809 });
1810 result = incallStateMachine->IsSecondaryCanActiveData();
1811 ASSERT_EQ(result, false);
1812 }
1813
1814 /**
1815 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_002
1816 * @tc.name test function branch
1817 * @tc.desc Function test
1818 */
1819 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_003, TestSize.Level0)
1820 {
1821 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1822 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1823 incallStateMachineTest->CreateIncallDataStateMachine(0);
1824 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anon9b60741f0502(int32_t &dsdsMode) 1825 .WillOnce([](int32_t &dsdsMode) {
1826 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1827 return 0;
1828 });
1829 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anon9b60741f0602(int32_t &slotId) 1830 .WillOnce([](int32_t &slotId) {
1831 slotId = 1;
1832 return 0;
1833 });
1834 auto result = incallStateMachine->IsSecondaryCanActiveData();
1835 ASSERT_EQ(result, false);
1836 }
1837
1838 /**
1839 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1840 * @tc.name test function branch
1841 * @tc.desc Function test
1842 */
1843 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_004, TestSize.Level0)
1844 {
1845 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1846 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1847 incallStateMachineTest->CreateIncallDataStateMachine(0);
1848 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anon9b60741f0702(int32_t &dsdsMode) 1849 .WillOnce([](int32_t &dsdsMode) {
1850 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1851 return 0;
1852 });
1853 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anon9b60741f0802(int32_t &slotId) 1854 .WillOnce([](int32_t &slotId) {
1855 slotId = 1;
1856 return 0;
1857 });
1858 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anon9b60741f0902(int32_t slotId, bool &hasSimCard) 1859 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1860 hasSimCard = true;
1861 return 0;
1862 });
1863 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anon9b60741f0a02(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 1864 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
1865 switch (imsSrvType) {
1866 case ImsServiceType::TYPE_VOICE:
1867 info.imsRegState = ImsRegState::IMS_UNREGISTERED;
1868 break;
1869 case ImsServiceType::TYPE_VIDEO:
1870 info.imsRegState = ImsRegState::IMS_UNREGISTERED;
1871 break;
1872 default:
1873 break;
1874 }
1875 return 0;
1876 });
1877 auto result = incallStateMachine->IsSecondaryCanActiveData();
1878 ASSERT_EQ(result, false);
1879 }
1880
1881 /**
1882 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1883 * @tc.name test function branch
1884 * @tc.desc Function test
1885 */
1886 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_005, TestSize.Level0)
1887 {
1888 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1889 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1890 incallStateMachineTest->CreateIncallDataStateMachine(0);
1891 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anon9b60741f0b02(int32_t &dsdsMode) 1892 .WillOnce([](int32_t &dsdsMode) {
1893 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1894 return 0;
1895 });
1896 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anon9b60741f0c02(int32_t &slotId) 1897 .WillOnce([](int32_t &slotId) {
1898 slotId = 1;
1899 return 0;
1900 });
1901 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anon9b60741f0d02(int32_t slotId, bool &hasSimCard) 1902 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1903 hasSimCard = true;
1904 return 0;
1905 });
1906 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anon9b60741f0e02(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 1907 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
1908 switch (imsSrvType) {
1909 case ImsServiceType::TYPE_VOICE:
1910 info.imsRegState = ImsRegState::IMS_REGISTERED ;
1911 break;
1912 case ImsServiceType::TYPE_VIDEO:
1913 info.imsRegState = ImsRegState::IMS_UNREGISTERED;
1914 break;
1915 default:
1916 break;
1917 }
1918 return 0;
1919 });
1920 auto result = incallStateMachine->IsSecondaryCanActiveData();
1921 ASSERT_EQ(result, false);
1922 }
1923
1924 /**
1925 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1926 * @tc.name test function branch
1927 * @tc.desc Function test
1928 */
1929 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_006, TestSize.Level0)
1930 {
1931 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1932 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1933 incallStateMachineTest->CreateIncallDataStateMachine(0);
1934 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anon9b60741f0f02(int32_t &dsdsMode) 1935 .WillOnce([](int32_t &dsdsMode) {
1936 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1937 return 0;
1938 });
1939 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anon9b60741f1002(int32_t &slotId) 1940 .WillOnce([](int32_t &slotId) {
1941 slotId = 1;
1942 return 0;
1943 });
1944 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anon9b60741f1102(int32_t slotId, bool &hasSimCard) 1945 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1946 hasSimCard = true;
1947 return 0;
1948 });
1949 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anon9b60741f1202(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 1950 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
1951 switch (imsSrvType) {
1952 case ImsServiceType::TYPE_VOICE:
1953 info.imsRegState = ImsRegState::IMS_REGISTERED ;
1954 break;
1955 case ImsServiceType::TYPE_VIDEO:
1956 info.imsRegState = ImsRegState::IMS_REGISTERED;
1957 break;
1958 default:
1959 break;
1960 }
1961 return 0;
1962 });
1963 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE);
1964 auto result = incallStateMachine->IsSecondaryCanActiveData();
1965 ASSERT_EQ(result, false);
1966 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DISCONNECTED);
1967 result = incallStateMachine->IsSecondaryCanActiveData();
1968 ASSERT_EQ(result, false);
1969 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DIALING);
1970 result = incallStateMachine->IsSecondaryCanActiveData();
1971 ASSERT_EQ(result, false);
1972 }
1973
1974 /**
1975 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1976 * @tc.name test function branch
1977 * @tc.desc Function test
1978 */
1979 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_007, TestSize.Level0)
1980 {
1981 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1982 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1983 incallStateMachineTest->CreateIncallDataStateMachine(0);
1984 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anon9b60741f1302(int32_t &dsdsMode) 1985 .WillOnce([](int32_t &dsdsMode) {
1986 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1987 return 0;
1988 });
1989 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anon9b60741f1402(int32_t &slotId) 1990 .WillOnce([](int32_t &slotId) {
1991 slotId = 1;
1992 return 0;
1993 });
1994 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anon9b60741f1502(int32_t slotId, bool &hasSimCard) 1995 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1996 hasSimCard = true;
1997 return 0;
1998 });
1999 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anon9b60741f1602(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 2000 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
2001 switch (imsSrvType) {
2002 case ImsServiceType::TYPE_VOICE:
2003 info.imsRegState = ImsRegState::IMS_REGISTERED ;
2004 break;
2005 case ImsServiceType::TYPE_VIDEO:
2006 info.imsRegState = ImsRegState::IMS_REGISTERED;
2007 break;
2008 default:
2009 break;
2010 }
2011 return 0;
2012 });
2013 EXPECT_CALL(*mockNetworkSearchManager, GetPsRadioTech(_, _)).Times(AtLeast(1))
__anon9b60741f1702(int32_t slotId, int32_t &psRadioTech) 2014 .WillOnce([](int32_t slotId, int32_t &psRadioTech) {
2015 psRadioTech = static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_LTE);
2016 return 0;
2017 });
2018 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DIALING);
2019 auto result = incallStateMachine->IsSecondaryCanActiveData();
2020 ASSERT_EQ(result, true);
2021 }
2022
2023 /**
2024 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_001
2025 * @tc.name test function branch
2026 * @tc.desc Function test
2027 */
2028 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_001, TestSize.Level0)
2029 {
2030 int32_t mtuSize = 0;
2031 int32_t slotId = 0;
2032 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2033 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2034 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1))
__anon9b60741f1802(int32_t slotId, OperatorConfig &poc) 2035 .WillOnce([](int32_t slotId, OperatorConfig &poc) {
2036 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:1500;ipv6:1400";
2037 return 0;
2038 });
2039 cellularMachine->ipType_ = "ipv4";
2040 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2041 ASSERT_EQ(mtuSize, 1500);
2042 }
2043
2044 /**
2045 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_002
2046 * @tc.name test function branch
2047 * @tc.desc Function test
2048 */
2049 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_002, TestSize.Level0)
2050 {
2051 int32_t mtuSize = 0;
2052 int32_t slotId = 0;
2053 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2054 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2055 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1))
__anon9b60741f1902(int32_t slotId, OperatorConfig &poc) 2056 .WillOnce([](int32_t slotId, OperatorConfig &poc) {
2057 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:1500;ipv6:1400";
2058 return 0;
2059 });
2060 cellularMachine->ipType_ = "ipv6";
2061 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2062 ASSERT_EQ(mtuSize, 1400);
2063 }
2064
2065 /**
2066 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_003
2067 * @tc.name test function branch
2068 * @tc.desc Function test
2069 */
2070 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_003, TestSize.Level0)
2071 {
2072 int32_t mtuSize = 0;
2073 int32_t slotId = 0;
2074 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2075 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2076 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1))
__anon9b60741f1a02(int32_t slotId, OperatorConfig &poc) 2077 .WillOnce([](int32_t slotId, OperatorConfig &poc) {
2078 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:1500;ipv6:1400";
2079 return 0;
2080 });
2081 cellularMachine->ipType_ = "ipv5";
2082 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2083 ASSERT_EQ(mtuSize, 0);
2084 }
2085
2086 /**
2087 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_004
2088 * @tc.name test function branch
2089 * @tc.desc Function test
2090 */
2091 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_004, TestSize.Level0)
2092 {
2093 int32_t mtuSize = 0;
2094 int32_t slotId = 0;
2095 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2096 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2097 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1))
__anon9b60741f1b02(int32_t slotId, OperatorConfig &poc) 2098 .WillOnce([](int32_t slotId, OperatorConfig &poc) {
2099 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:abc;ipv6:1400";
2100 return 0;
2101 });
2102 cellularMachine->ipType_ = "ipv4";
2103 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2104 ASSERT_EQ(mtuSize, 0);
2105 }
2106
2107 /**
2108 * @tc.number CellularDataStateMachine_GetNetScoreBySlotId_001
2109 * @tc.name test function branch
2110 * @tc.desc Function test
2111 */
2112 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetNetScoreBySlotId_001, TestSize.Level0)
2113 {
2114 int32_t score;
2115 int32_t slotId = 0;
2116 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2117 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2118 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1))
__anon9b60741f1c02() 2119 .WillOnce([]() {
2120 return 0;
2121 });
2122 score = cellularMachine->GetNetScoreBySlotId(slotId);
2123 ASSERT_EQ(score, DEFAULT_INTERNET_CONNECTION_SCORE);
2124 }
2125
2126 /**
2127 * @tc.number CellularDataStateMachine_GetNetScoreBySlotId_002
2128 * @tc.name test function branch
2129 * @tc.desc Function test
2130 */
2131 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetNetScoreBySlotId_002, TestSize.Level0)
2132 {
2133 int32_t score;
2134 int32_t slotId = 0;
2135 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2136 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2137 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1))
__anon9b60741f1d02() 2138 .WillOnce([]() {
2139 return 1;
2140 });
2141 score = cellularMachine->GetNetScoreBySlotId(slotId);
2142 ASSERT_EQ(score, OTHER_CONNECTION_SCORE);
2143 }
2144
2145 /**
2146 * @tc.number Default_ProcessUpdateNetworkInfo_001
2147 * @tc.name test function branch
2148 * @tc.desc Function test
2149 */
2150 HWTEST_F(CellularStateMachineTest, Default_ProcessUpdateNetworkInfo_001, Function | MediumTest | Level1)
2151 {
2152 if (cellularMachine == nullptr) {
2153 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2154 cellularMachine = machine->CreateCellularDataConnect(0);
2155 cellularMachine->Init();
2156 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1))
__anon9b60741f1e02() 2157 .WillOnce([]() {
2158 return 0;
2159 });
2160 }
2161 auto defaultState = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
2162 defaultState->stateMachine_ = cellularMachine;
2163 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_UPDATE_NETWORK_INFO);
2164 bool result = defaultState->ProcessUpdateNetworkInfo(event);
2165 EXPECT_EQ(result, true);
2166 }
2167
2168 /**
2169 * @tc.number SetIfReuseSupplierId_001
2170 * @tc.name test function branch
2171 * @tc.desc Function test
2172 */
2173 HWTEST_F(CellularStateMachineTest, SetIfReuseSupplierId_001, Function | MediumTest | Level1)
2174 {
2175 if (cellularMachine == nullptr) {
2176 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2177 cellularMachine = machine->CreateCellularDataConnect(0);
2178 cellularMachine->Init();
2179 }
2180 EXPECT_EQ(cellularMachine->reuseApnCap_, NetManagerStandard::NetCap::NET_CAPABILITY_END);
2181 cellularMachine->SetIfReuseSupplierId(true);
2182 }
2183
2184 /**
2185 * @tc.number SetIfReuseSupplierId_002
2186 * @tc.name test function branch
2187 * @tc.desc Function test
2188 */
2189 HWTEST_F(CellularStateMachineTest, SetIfReuseSupplierId_002, Function | MediumTest | Level1)
2190 {
2191 if (cellularMachine == nullptr) {
2192 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2193 cellularMachine = machine->CreateCellularDataConnect(0);
2194 cellularMachine->Init();
2195 }
2196 cellularMachine->reuseApnCap_ = NetManagerStandard::NetCap::NET_CAPABILITY_MMS;
2197 cellularMachine->SetIfReuseSupplierId(true);
2198 EXPECT_NE(cellularMachine->reuseApnCap_, NetManagerStandard::NetCap::NET_CAPABILITY_END);
2199 }
2200
2201 /**
2202 * @tc.number UpdateNetworkInfoIfInActive_001
2203 * @tc.name test function branch
2204 * @tc.desc Function test
2205 */
2206 HWTEST_F(CellularStateMachineTest, UpdateNetworkInfoIfInActive_001, Function | MediumTest | Level1)
2207 {
2208 if (cellularMachine == nullptr) {
2209 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2210 cellularMachine = machine->CreateCellularDataConnect(0);
2211 cellularMachine->Init();
2212 }
2213 SetupDataCallResultInfo info;
2214 EXPECT_NE(cellularMachine->cellularDataHandler_, nullptr);
2215 cellularMachine->cellularDataHandler_ = nullptr;
2216 cellularMachine->UpdateNetworkInfoIfInActive(info);
2217 }
2218
2219 /**
2220 * @tc.number FillRSDFromNetCap_001
2221 * @tc.name test function branch
2222 * @tc.desc Function test
2223 */
2224 HWTEST_F(CellularStateMachineTest, FillRSDFromNetCap_001, Function | MediumTest | Level1)
2225 {
2226 if (cellularMachine == nullptr) {
2227 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2228 cellularMachine = machine->CreateCellularDataConnect(0);
2229 cellularMachine->Init();
2230 }
2231 EXPECT_NE(cellularMachine, nullptr);
2232 std::map<std::string, std::string> networkSliceParas;
2233 sptr<ApnItem> apn = new ApnItem();
2234 cellularMachine->FillRSDFromNetCap(networkSliceParas, apn);
2235 }
2236
2237 /**
2238 * @tc.number OnInterfaceLinkStateChanged_001
2239 * @tc.name test function branch
2240 * @tc.desc Function test
2241 */
2242 HWTEST_F(CellularStateMachineTest, OnInterfaceLinkStateChanged_001, Function | MediumTest | Level0)
2243 {
2244 if (cellularMachine == nullptr) {
2245 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2246 cellularMachine = machine->CreateCellularDataConnect(0);
2247 cellularMachine->Init();
2248 }
2249 SetupDataCallResultInfo dataCallInfo;
2250 dataCallInfo.address = "192.168.1.1";
2251 dataCallInfo.dns = "192.168.1.1";
2252 dataCallInfo.dnsSec = "192.168.1.1";
2253 dataCallInfo.gateway = "192.168.1.1";
2254 dataCallInfo.reason = 1;
2255 dataCallInfo.netPortName = "rmnet0";
2256 cellularMachine->UpdateNetworkInfo(dataCallInfo);
2257 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
2258 cellularMachine->TransitionTo(cellularMachine->inActiveState_);
2259 active->stateMachine_ = cellularMachine;
2260 std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
2261 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
2262 auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams);
2263 bool result = active->ProcessDisconnectAllDone(event);
2264 if (cellularMachine->netInterfaceCallback_ != nullptr) {
2265 if (cellularMachine->stateMachineEventHandler_ != nullptr) {
2266 cellularMachine->stateMachineEventHandler_->SendEvent(
2267 CellularDataEventCode::MSG_DISCONNECT_TIMEOUT_CHECK, 0, 1000);
2268 }
2269 cellularMachine->netInterfaceCallback_->OnInterfaceLinkStateChanged("rmnet0", false);
2270 }
2271 if (cellularMachine->netInterfaceCallback_ != nullptr) {
2272 cellularMachine->netInterfaceCallback_->OnInterfaceLinkStateChanged("rmnet", false);
2273 }
2274 if (cellularMachine->netInterfaceCallback_ != nullptr) {
2275 cellularMachine->stateMachineEventHandler_ = nullptr;
2276 cellularMachine->OnInterfaceLinkStateChanged("rmnet0", false);
2277 }
2278 cellularMachine->UnregisterNetInterfaceCallback();
2279 EXPECT_EQ(result, false);
2280 }
2281
2282 /**
2283 * @tc.number FreeConnection_001
2284 * @tc.name test function branch
2285 * @tc.desc Function test
2286 */
2287 HWTEST_F(CellularStateMachineTest, FreeConnection_001, Function | MediumTest |Level0)
2288 {
2289 if (cellularMachine == nullptr) {
2290 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2291 cellularMachine = machine->CreateCellularDataConnect(0);
2292 cellularMachine->Init();
2293 }
2294 std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
2295 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
2296 cellularMachine->FreeConnection(*dataDisconnectParams);
2297 EXPECT_NE(cellularMachine->netInterfaceCallback_, nullptr);
2298 }
2299
2300 /**
2301 * @tc.number DoConnect_001
2302 * @tc.name test function branch
2303 * @tc.desc Function test
2304 */
2305 HWTEST_F(CellularStateMachineTest, DoConnect_001, Function | MediumTest | Level0)
2306 {
2307 if (cellularMachine == nullptr) {
2308 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2309 cellularMachine = machine->CreateCellularDataConnect(0);
2310 cellularMachine->Init();
2311 }
2312 sptr apnHolder = new ApnHolder(DATA_CONTEXT_ROLE_DEFAULT, 0);
2313 sptr defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
2314 apnHolder->SetCurrentApn(defaultApnItem);
2315 int32_t profileId = 0;
2316 int32_t radioTechnology = 0;
2317 bool nonTrafficUseOnly = false;
2318 bool roamingState = false;
2319 bool userDataRoaming = false;
2320 std::shared_ptr<DataConnectionParams> dataConnectionParams = std::make_shared<DataConnectionParams>(apnHolder,
2321 profileId, radioTechnology, nonTrafficUseOnly, roamingState, userDataRoaming);
2322 cellularMachine->DoConnect(*dataConnectionParams);
2323 EXPECT_NE(cellularMachine->netInterfaceCallback_, nullptr);
2324 }
2325 } // namespace Telephony
2326 } // namespace OHOS