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 "data_connection_manager.h"
23 #include "data_disconnect_params.h"
24 #include "default.h"
25 #include "disconnecting.h"
26 #include "gtest/gtest.h"
27 #include "inactive.h"
28 #include "incall_data_state_machine.h"
29 #include "tel_event_handler.h"
30 #include "telephony_types.h"
31 #include "tel_ril_data_parcel.h"
32 
33 namespace OHOS {
34 namespace Telephony {
35 using namespace testing::ext;
36 
37 class CellularStateMachineTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43     std::shared_ptr<CellularDataStateMachine> cellularMachine;
44 };
SetUpTestCase()45 void CellularStateMachineTest::SetUpTestCase() {}
46 
TearDownTestCase()47 void CellularStateMachineTest::TearDownTestCase() {}
48 
SetUp()49 void CellularStateMachineTest::SetUp() {}
50 
TearDown()51 void CellularStateMachineTest::TearDown() {}
52 
53 class IncallDataStateMachineTest : public TelEventHandler {
54 public:
IncallDataStateMachineTest()55     IncallDataStateMachineTest() : TelEventHandler("IncallDataStateMachineTest") {}
56     ~IncallDataStateMachineTest() = default;
57     std::shared_ptr<IncallDataStateMachine> CreateIncallDataStateMachine(int32_t slotId);
58 
59 public:
60     std::shared_ptr<IncallDataStateMachine> incallStateMachine_ = nullptr;
61 };
62 
CreateIncallDataStateMachine(int32_t slotId)63 std::shared_ptr<IncallDataStateMachine> IncallDataStateMachineTest::CreateIncallDataStateMachine(int32_t slotId)
64 {
65     if (incallStateMachine_ != nullptr) {
66         return incallStateMachine_;
67     }
68     sptr<ApnManager> apnManager = std::make_unique<ApnManager>().release();
69     if (apnManager == nullptr) {
70         return nullptr;
71     }
72     incallStateMachine_ = std::make_shared<IncallDataStateMachine>(slotId,
73         std::weak_ptr<TelEventHandler>(std::static_pointer_cast<TelEventHandler>(shared_from_this())), apnManager);
74     return incallStateMachine_;
75 }
76 
77 class CellularMachineTest : public TelEventHandler {
78 public:
CellularMachineTest()79     CellularMachineTest() : TelEventHandler("CellularDataStateMachineTest") {}
80     ~CellularMachineTest() = default;
81     std::shared_ptr<CellularDataStateMachine> CreateCellularDataConnect(int32_t slotId);
82 
83 public:
84     std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_ = nullptr;
85 };
86 
CreateCellularDataConnect(int32_t slotId)87 std::shared_ptr<CellularDataStateMachine> CellularMachineTest::CreateCellularDataConnect(int32_t slotId)
88 {
89     if (cellularDataStateMachine_ != nullptr) {
90         return cellularDataStateMachine_;
91     }
92     sptr<DataConnectionManager> connectionManager = std::make_unique<DataConnectionManager>(slotId).release();
93     if (connectionManager == nullptr) {
94         return nullptr;
95     }
96     connectionManager->Init();
97     cellularDataStateMachine_ = std::make_shared<CellularDataStateMachine>(
98         connectionManager, std::static_pointer_cast<TelEventHandler>(shared_from_this()));
99     return cellularDataStateMachine_;
100 }
101 
102 /**
103  * @tc.number   HasAnyConnectedState_001
104  * @tc.name     test function branch
105  * @tc.desc     Function test
106  */
107 HWTEST_F(CellularStateMachineTest, HasAnyConnectedState_001, Function | MediumTest | Level1)
108 {
109     std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
110     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
111         incallStateMachineTest->CreateIncallDataStateMachine(0);
112     incallStateMachine->apnManager_ = nullptr;
113     ASSERT_EQ(incallStateMachine->HasAnyConnectedState(), false);
114 }
115 
116 /**
117  * @tc.number   StateProcess_001
118  * @tc.name     test function branch
119  * @tc.desc     Function test
120  */
121 HWTEST_F(CellularStateMachineTest, StateProcess_001, Function | MediumTest | Level1)
122 {
123     std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
124     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
125         incallStateMachineTest->CreateIncallDataStateMachine(0);
126     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED);
127     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
128     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
129     incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_);
130     incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_);
131     auto deactivatingSecondaryState =
132         static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr());
133     bool result = deactivatingSecondaryState->StateProcess(event);
134     EXPECT_EQ(result, true);
135 }
136 
137 /**
138  * @tc.number   StateProcess_002
139  * @tc.name     test function branch
140  * @tc.desc     Function test
141  */
142 HWTEST_F(CellularStateMachineTest, StateProcess_002, Function | MediumTest | Level1)
143 {
144     std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
145     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
146         incallStateMachineTest->CreateIncallDataStateMachine(0);
147     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_DISCONNECTED);
148     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
149     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
150     incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_);
151     incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_);
152     auto deactivatingSecondaryState =
153         static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr());
154     bool result = deactivatingSecondaryState->StateProcess(event);
155     EXPECT_EQ(result, true);
156 }
157 
158 /**
159  * @tc.number   StateProcess_003
160  * @tc.name     test function branch
161  * @tc.desc     Function test
162  */
163 HWTEST_F(CellularStateMachineTest, StateProcess_003, 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     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_SETTINGS_ON);
169     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
170     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
171     incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_);
172     incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_);
173     auto deactivatingSecondaryState =
174         static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr());
175     bool result = deactivatingSecondaryState->StateProcess(event);
176     EXPECT_EQ(result, true);
177 }
178 
179 /**
180  * @tc.number   ActivatingStateProcess_001
181  * @tc.name     test function branch
182  * @tc.desc     Function test
183  */
184 HWTEST_F(CellularStateMachineTest, ActivatingStateProcess_001, Function | MediumTest | Level1)
185 {
186     std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
187     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
188         incallStateMachineTest->CreateIncallDataStateMachine(0);
189     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED);
190     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
191     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
192     auto activatingSecondaryState =
193         static_cast<ActivatingSecondaryState *>(incallStateMachine->activatingSecondaryState_.GetRefPtr());
194     bool result = activatingSecondaryState->StateProcess(event);
195     EXPECT_EQ(result, true);
196 }
197 
198 /**
199  * @tc.number   ActivatingStateProcess_002
200  * @tc.name     test function branch
201  * @tc.desc     Function test
202  */
203 HWTEST_F(CellularStateMachineTest, ActivatingStateProcess_002, Function | MediumTest | Level1)
204 {
205     std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
206     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
207         incallStateMachineTest->CreateIncallDataStateMachine(0);
208     auto event = AppExecFwk::InnerEvent::Get(-1);
209     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
210     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
211     auto activatingSecondaryState =
212         static_cast<ActivatingSecondaryState *>(incallStateMachine->activatingSecondaryState_.GetRefPtr());
213     bool result = activatingSecondaryState->StateProcess(event);
214     EXPECT_EQ(result, false);
215 }
216 
217 /**
218  * @tc.number   SecondaryActiveStateProcess_001
219  * @tc.name     test function branch
220  * @tc.desc     Function test
221  */
222 HWTEST_F(CellularStateMachineTest, SecondaryActiveStateProcess_001, Function | MediumTest | Level1)
223 {
224     std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
225     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
226         incallStateMachineTest->CreateIncallDataStateMachine(0);
227     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED);
228     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
229     incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_);
230     auto secondaryActiveState =
231         static_cast<ActivatingSecondaryState *>(incallStateMachine->secondaryActiveState_.GetRefPtr());
232     bool result = secondaryActiveState->StateProcess(event);
233     EXPECT_EQ(result, false);
234 }
235 
236 /**
237  * @tc.number   InactiveStateBegin_001
238  * @tc.name     test function branch
239  * @tc.desc     Function test
240  */
241 HWTEST_F(CellularStateMachineTest, InactiveStateBegin_001, Function | MediumTest | Level1)
242 {
243     if (cellularMachine == nullptr) {
244         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
245         cellularMachine = machine->CreateCellularDataConnect(0);
246         cellularMachine->Init();
247     }
248     auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
249     inactive->deActiveApnTypeId_ = 0;
250     inactive->SetStateMachine(cellularMachine);
251     EXPECT_EQ(inactive->reason_, DisConnectionReason::REASON_RETRY_CONNECTION);
252 }
253 
254 /**
255  * @tc.number   InactiveStateBegin_001
256  * @tc.name     test function branch
257  * @tc.desc     Function test
258  */
259 HWTEST_F(CellularStateMachineTest, InactiveStateProcess_002, Function | MediumTest | Level1)
260 {
261     if (cellularMachine == nullptr) {
262         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
263         cellularMachine = machine->CreateCellularDataConnect(0);
264         cellularMachine->Init();
265     }
266     auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
267     inactive->stateMachine_ = cellularMachine;
268     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT);
269     bool result = inactive->StateProcess(event);
270     EXPECT_EQ(result, true);
271 }
272 
273 /**
274  * @tc.number   InactiveStateBegin_001
275  * @tc.name     test function branch
276  * @tc.desc     Function test
277  */
278 HWTEST_F(CellularStateMachineTest, InactiveStateProcess_003, Function | MediumTest | Level1)
279 {
280     if (cellularMachine == nullptr) {
281         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
282         cellularMachine = machine->CreateCellularDataConnect(0);
283         cellularMachine->Init();
284     }
285     auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
286     inactive->SetStateMachine(cellularMachine);
287     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT_ALL);
288     bool result = inactive->StateProcess(event);
289     EXPECT_EQ(result, true);
290 }
291 
292 /**
293  * @tc.number   DefaultStateProcess_001
294  * @tc.name     test function branch
295  * @tc.desc     Function test
296  */
297 HWTEST_F(CellularStateMachineTest, DefaultStateProcess_001, Function | MediumTest | Level1)
298 {
299     if (cellularMachine == nullptr) {
300         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
301         cellularMachine = machine->CreateCellularDataConnect(0);
302         cellularMachine->Init();
303     }
304     auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
305     mDefault->stateMachine_ = cellularMachine;
306     mDefault->eventIdFunMap_.clear();
307     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
308     bool result = mDefault->StateProcess(event);
309     EXPECT_EQ(result, false);
310 }
311 
312 /**
313  * @tc.number   DefaultProcessDisconnectDone_001
314  * @tc.name     test function branch
315  * @tc.desc     Function test
316  */
317 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectDone_001, Function | MediumTest | Level1)
318 {
319     if (cellularMachine == nullptr) {
320         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
321         cellularMachine = machine->CreateCellularDataConnect(0);
322         cellularMachine->Init();
323     }
324     auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
325     mDefault->stateMachine_ = cellularMachine;
326     mDefault->eventIdFunMap_.clear();
327     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
328     bool result = mDefault->ProcessDisconnectDone(event);
329     EXPECT_EQ(result, true);
330 }
331 
332 /**
333  * @tc.number   DefaultProcessDataConnectionDrsOrRatChanged_001
334  * @tc.name     test function branch
335  * @tc.desc     Function test
336  */
337 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_001, Function | MediumTest | Level1)
338 {
339     if (cellularMachine == nullptr) {
340         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
341         cellularMachine = machine->CreateCellularDataConnect(0);
342         cellularMachine->Init();
343     }
344     auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
345     cellularMachine->TransitionTo(cellularMachine->activeState_);
346     mDefault->stateMachine_ = cellularMachine;
347     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
348     bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
349     EXPECT_EQ(result, false);
350 }
351 
352 /**
353  * @tc.number   DefaultProcessDataConnectionDrsOrRatChanged_002
354  * @tc.name     test function branch
355  * @tc.desc     Function test
356  */
357 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_002, Function | MediumTest | Level1)
358 {
359     if (cellularMachine == nullptr) {
360         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
361         cellularMachine = machine->CreateCellularDataConnect(0);
362         cellularMachine->Init();
363     }
364     auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
365     cellularMachine->TransitionTo(cellularMachine->activatingState_);
366     mDefault->stateMachine_ = cellularMachine;
367     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
368     bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
369     EXPECT_EQ(result, false);
370 }
371 
372 /**
373  * @tc.number   DefaultProcessDataConnectionDrsOrRatChanged_003
374  * @tc.name     test function branch
375  * @tc.desc     Function test
376  */
377 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_003, Function | MediumTest | Level1)
378 {
379     if (cellularMachine == nullptr) {
380         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
381         cellularMachine = machine->CreateCellularDataConnect(0);
382         cellularMachine->Init();
383     }
384     auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
385     cellularMachine->TransitionTo(cellularMachine->disconnectingState_);
386     mDefault->stateMachine_ = cellularMachine;
387     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
388     bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
389     EXPECT_EQ(result, false);
390 }
391 
392 /**
393  * @tc.number   DefaultProcessDataCallListChanged_001
394  * @tc.name     test function branch
395  * @tc.desc     Function test
396  */
397 HWTEST_F(CellularStateMachineTest, DefaultProcessDataCallListChanged_001, Function | MediumTest | Level1)
398 {
399     if (cellularMachine == nullptr) {
400         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
401         cellularMachine = machine->CreateCellularDataConnect(0);
402         cellularMachine->Init();
403     }
404     auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
405     cellularMachine->TransitionTo(cellularMachine->disconnectingState_);
406     mDefault->stateMachine_ = cellularMachine;
407     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
408     bool result = mDefault->ProcessDataCallListChanged(event);
409     EXPECT_EQ(result, false);
410 }
411 
412 /**
413  * @tc.number   Active_StateBegin_001
414  * @tc.name     test function branch
415  * @tc.desc     Function test
416  */
417 HWTEST_F(CellularStateMachineTest, Active_StateBegin_001, Function | MediumTest | Level1)
418 {
419     if (cellularMachine == nullptr) {
420         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
421         cellularMachine = machine->CreateCellularDataConnect(0);
422         cellularMachine->Init();
423     }
424     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
425     active->stateMachine_ = cellularMachine;
426     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
427     active->StateBegin();
428     EXPECT_EQ(active->isActive_, true);
429 }
430 
431 /**
432  * @tc.number   Active_StateProcess_001
433  * @tc.name     test function branch
434  * @tc.desc     Function test
435  */
436 HWTEST_F(CellularStateMachineTest, Active_StateProcess_001, Function | MediumTest | Level1)
437 {
438     if (cellularMachine == nullptr) {
439         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
440         cellularMachine = machine->CreateCellularDataConnect(0);
441         cellularMachine->Init();
442     }
443     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
444     active->stateMachine_ = cellularMachine;
445     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
446     bool result = active->StateProcess(event);
447     EXPECT_EQ(result, true);
448 }
449 
450 /**
451  * @tc.number   Active_StateProcess_002
452  * @tc.name     test function branch
453  * @tc.desc     Function test
454  */
455 HWTEST_F(CellularStateMachineTest, Active_StateProcess_002, Function | MediumTest | Level1)
456 {
457     if (cellularMachine == nullptr) {
458         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
459         cellularMachine = machine->CreateCellularDataConnect(0);
460         cellularMachine->Init();
461     }
462     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
463     active->stateMachine_ = cellularMachine;
464     auto event = AppExecFwk::InnerEvent::Get(0);
465     bool result = active->StateProcess(event);
466     EXPECT_EQ(result, false);
467 }
468 
469 /**
470  * @tc.number   Active_ProcessDisconnectDone_001
471  * @tc.name     test function branch
472  * @tc.desc     Function test
473  */
474 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_001, Function | MediumTest | Level1)
475 {
476     if (cellularMachine == nullptr) {
477         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
478         cellularMachine = machine->CreateCellularDataConnect(0);
479         cellularMachine->Init();
480     }
481     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
482     active->stateMachine_ = cellularMachine;
483     auto event = AppExecFwk::InnerEvent::Get(0);
484     event = nullptr;
485     bool result = active->ProcessDisconnectDone(event);
486     EXPECT_EQ(result, false);
487 }
488 
489 /**
490  * @tc.number   Active_ProcessDisconnectDone_002
491  * @tc.name     test function branch
492  * @tc.desc     Function test
493  */
494 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_002, Function | MediumTest | Level1)
495 {
496     if (cellularMachine == nullptr) {
497         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
498         cellularMachine = machine->CreateCellularDataConnect(0);
499         cellularMachine->Init();
500     }
501     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
502     active->stateMachine_ = cellularMachine;
503     auto event = AppExecFwk::InnerEvent::Get(0);
504     bool result = active->ProcessDisconnectDone(event);
505     EXPECT_EQ(result, false);
506 }
507 
508 /**
509  * @tc.number   Active_ProcessDisconnectAllDone_001
510  * @tc.name     test function branch
511  * @tc.desc     Function test
512  */
513 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_001, Function | MediumTest | Level1)
514 {
515     if (cellularMachine == nullptr) {
516         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
517         cellularMachine = machine->CreateCellularDataConnect(0);
518         cellularMachine->Init();
519     }
520     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
521     active->stateMachine_ = cellularMachine;
522     auto event = AppExecFwk::InnerEvent::Get(0);
523     event = nullptr;
524     bool result = active->ProcessDisconnectAllDone(event);
525     EXPECT_EQ(result, false);
526 }
527 
528 /**
529  * @tc.number   Active_ProcessDisconnectAllDone_002
530  * @tc.name     test function branch
531  * @tc.desc     Function test
532  */
533 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_002, Function | MediumTest | Level1)
534 {
535     if (cellularMachine == nullptr) {
536         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
537         cellularMachine = machine->CreateCellularDataConnect(0);
538         cellularMachine->Init();
539     }
540     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
541     active->stateMachine_ = cellularMachine;
542     auto event = AppExecFwk::InnerEvent::Get(0);
543     bool result = active->ProcessDisconnectAllDone(event);
544     EXPECT_EQ(result, false);
545 }
546 
547 /**
548  * @tc.number   Active_ProcessDisconnectAllDone_003
549  * @tc.name     test function branch
550  * @tc.desc     Function test
551  */
552 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_003, Function | MediumTest | Level1)
553 {
554     if (cellularMachine == nullptr) {
555         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
556         cellularMachine = machine->CreateCellularDataConnect(0);
557         cellularMachine->Init();
558     }
559     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
560     cellularMachine->TransitionTo(cellularMachine->inActiveState_);
561     active->stateMachine_ = cellularMachine;
562     std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
563         std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
564     auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams);
565     bool result = active->ProcessDisconnectAllDone(event);
566     EXPECT_EQ(result, false);
567 }
568 
569 /**
570  * @tc.number   Active_ProcessDisconnectAllDone_004
571  * @tc.name     test function branch
572  * @tc.desc     Function test
573  */
574 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_004, Function | MediumTest | Level1)
575 {
576     if (cellularMachine == nullptr) {
577         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
578         cellularMachine = machine->CreateCellularDataConnect(0);
579         cellularMachine->Init();
580     }
581     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
582     cellularMachine->inActiveState_ = nullptr;
583     active->stateMachine_ = cellularMachine;
584     std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
585         std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
586     auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams);
587     bool result = active->ProcessDisconnectAllDone(event);
588     EXPECT_EQ(result, false);
589 }
590 
591 /**
592  * @tc.number   Active_ProcessLinkCapabilityChanged_001
593  * @tc.name     test function branch
594  * @tc.desc     Function test
595  */
596 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_001, Function | MediumTest | Level1)
597 {
598     if (cellularMachine == nullptr) {
599         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
600         cellularMachine = machine->CreateCellularDataConnect(0);
601         cellularMachine->Init();
602     }
603     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
604     active->stateMachine_ = cellularMachine;
605     auto event = AppExecFwk::InnerEvent::Get(0);
606     bool result = active->ProcessLinkCapabilityChanged(event);
607     EXPECT_EQ(result, false);
608 }
609 
610 /**
611  * @tc.number   Active_ProcessLinkCapabilityChanged_002
612  * @tc.name     test function branch
613  * @tc.desc     Function test
614  */
615 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_002, Function | MediumTest | Level1)
616 {
617     if (cellularMachine == nullptr) {
618         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
619         cellularMachine = machine->CreateCellularDataConnect(0);
620         cellularMachine->Init();
621     }
622     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
623     cellularMachine = nullptr;
624     active->stateMachine_ = cellularMachine;
625     std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
626     auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
627     bool result = active->ProcessLinkCapabilityChanged(event);
628     EXPECT_EQ(result, false);
629 }
630 
631 /**
632  * @tc.number   Active_ProcessLinkCapabilityChanged_003
633  * @tc.name     test function branch
634  * @tc.desc     Function test
635  */
636 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_003, Function | MediumTest | Level1)
637 {
638     if (cellularMachine == nullptr) {
639         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
640         cellularMachine = machine->CreateCellularDataConnect(0);
641         cellularMachine->Init();
642     }
643     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
644     active->stateMachine_ = cellularMachine;
645     std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
646     linkCapability->primaryUplinkKbps = 0;
647     auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
648     bool result = active->ProcessLinkCapabilityChanged(event);
649     EXPECT_EQ(result, true);
650 }
651 
652 /**
653  * @tc.number   Active_ProcessLinkCapabilityChanged_004
654  * @tc.name     test function branch
655  * @tc.desc     Function test
656  */
657 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_004, Function | MediumTest | Level1)
658 {
659     if (cellularMachine == nullptr) {
660         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
661         cellularMachine = machine->CreateCellularDataConnect(0);
662         cellularMachine->Init();
663     }
664     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
665     active->stateMachine_ = cellularMachine;
666     std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
667     linkCapability->primaryUplinkKbps = 1;
668     linkCapability->primaryDownlinkKbps = 0;
669     auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
670     bool result = active->ProcessLinkCapabilityChanged(event);
671     EXPECT_EQ(result, true);
672 }
673 
674 /**
675  * @tc.number   Active_ProcessLinkCapabilityChanged_005
676  * @tc.name     test function branch
677  * @tc.desc     Function test
678  */
679 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_005, Function | MediumTest | Level1)
680 {
681     if (cellularMachine == nullptr) {
682         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
683         cellularMachine = machine->CreateCellularDataConnect(0);
684         cellularMachine->Init();
685     }
686     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
687     active->stateMachine_ = cellularMachine;
688     std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
689     linkCapability->primaryUplinkKbps = 1;
690     linkCapability->primaryDownlinkKbps = 1;
691     auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
692     bool result = active->ProcessLinkCapabilityChanged(event);
693     EXPECT_EQ(result, true);
694 }
695 
696 /**
697  * @tc.number   Active_ProcessDataConnectionComplete_001
698  * @tc.name     test function branch
699  * @tc.desc     Function test
700  */
701 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_001, Function | MediumTest | Level1)
702 {
703     if (cellularMachine == nullptr) {
704         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
705         cellularMachine = machine->CreateCellularDataConnect(0);
706         cellularMachine->Init();
707     }
708     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
709     active->stateMachine_ = cellularMachine;
710     auto event = AppExecFwk::InnerEvent::Get(0);
711     bool result = active->ProcessDataConnectionComplete(event);
712     EXPECT_EQ(result, false);
713 }
714 
715 /**
716  * @tc.number   Active_ProcessDataConnectionComplete_002
717  * @tc.name     test function branch
718  * @tc.desc     Function test
719  */
720 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_002, Function | MediumTest | Level1)
721 {
722     if (cellularMachine == nullptr) {
723         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
724         cellularMachine = machine->CreateCellularDataConnect(0);
725         cellularMachine->Init();
726     }
727     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
728     cellularMachine = nullptr;
729     active->stateMachine_ = cellularMachine;
730     std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
731     auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
732     bool result = active->ProcessDataConnectionComplete(event);
733     EXPECT_EQ(result, false);
734 }
735 
736 /**
737  * @tc.number   Active_ProcessDataConnectionComplete_003
738  * @tc.name     test function branch
739  * @tc.desc     Function test
740  */
741 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_003, Function | MediumTest | Level1)
742 {
743     if (cellularMachine == nullptr) {
744         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
745         cellularMachine = machine->CreateCellularDataConnect(0);
746         cellularMachine->Init();
747     }
748     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
749     active->stateMachine_ = cellularMachine;
750     std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
751     auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
752     bool result = active->ProcessDataConnectionComplete(event);
753     EXPECT_EQ(result, true);
754 }
755 
756 /**
757  * @tc.number   Active_ProcessDataConnectionComplete_004
758  * @tc.name     test function branch
759  * @tc.desc     Function test
760  */
761 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_004, Function | MediumTest | Level1)
762 {
763     if (cellularMachine == nullptr) {
764         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
765         cellularMachine = machine->CreateCellularDataConnect(0);
766         cellularMachine->Init();
767     }
768     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
769     cellularMachine->stateMachineEventHandler_ = nullptr;
770     active->stateMachine_ = cellularMachine;
771     std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
772     auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
773     bool result = active->ProcessDataConnectionComplete(event);
774     EXPECT_EQ(result, false);
775 }
776 
777 /**
778  * @tc.number   Active_ProcessNrStateChanged_001
779  * @tc.name     test function branch
780  * @tc.desc     Function test
781  */
782 HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_001, 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 active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
790     active->stateMachine_ = cellularMachine;
791     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
792     bool result = active->ProcessNrStateChanged(event);
793     EXPECT_EQ(result, true);
794 }
795 
796 /**
797  * @tc.number   Active_ProcessNrStateChanged_002
798  * @tc.name     test function branch
799  * @tc.desc     Function test
800  */
801 HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_002, Function | MediumTest | Level1)
802 {
803     if (cellularMachine == nullptr) {
804         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
805         cellularMachine = machine->CreateCellularDataConnect(0);
806         cellularMachine->Init();
807     }
808     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
809     cellularMachine = nullptr;
810     active->stateMachine_ = cellularMachine;
811     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
812     bool result = active->ProcessNrStateChanged(event);
813     EXPECT_EQ(result, false);
814 }
815 
816 /**
817  * @tc.number   Active_ProcessNrFrequencyChanged_001
818  * @tc.name     test function branch
819  * @tc.desc     Function test
820  */
821 HWTEST_F(CellularStateMachineTest, Active_ProcessNrFrequencyChanged_001, Function | MediumTest | Level1)
822 {
823     if (cellularMachine == nullptr) {
824         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
825         cellularMachine = machine->CreateCellularDataConnect(0);
826         cellularMachine->Init();
827     }
828     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
829     cellularMachine = nullptr;
830     active->stateMachine_ = cellularMachine;
831     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
832     bool result = active->ProcessNrFrequencyChanged(event);
833     EXPECT_EQ(result, false);
834 }
835 
836 /**
837  * @tc.number   Active_ProcessDisconnectAllDone_001
838  * @tc.name     test function branch
839  * @tc.desc     Function test
840  */
841 HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_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     cellularMachine->TransitionTo(cellularMachine->inActiveState_);
850     active->stateMachine_ = cellularMachine;
851     auto event = AppExecFwk::InnerEvent::Get(0);
852     bool result = active->ProcessLostConnection(event);
853     EXPECT_EQ(result, true);
854 }
855 
856 /**
857  * @tc.number   Active_ProcessLostConnection_002
858  * @tc.name     test function branch
859  * @tc.desc     Function test
860  */
861 HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_002, Function | MediumTest | Level1)
862 {
863     if (cellularMachine == nullptr) {
864         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
865         cellularMachine = machine->CreateCellularDataConnect(0);
866         cellularMachine->Init();
867     }
868     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
869     cellularMachine->inActiveState_ = nullptr;
870     active->stateMachine_ = cellularMachine;
871     auto event = AppExecFwk::InnerEvent::Get(0);
872     bool result = active->ProcessLostConnection(event);
873     EXPECT_EQ(result, false);
874 }
875 
876 /**
877  * @tc.number   Active_ProcessDataConnectionRoamOn_001
878  * @tc.name     test function branch
879  * @tc.desc     Function test
880  */
881 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOn_001, Function | MediumTest | Level1)
882 {
883     if (cellularMachine == nullptr) {
884         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
885         cellularMachine = machine->CreateCellularDataConnect(0);
886         cellularMachine->Init();
887     }
888     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
889     active->stateMachine_ = cellularMachine;
890     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
891     bool result = active->ProcessDataConnectionRoamOn(event);
892     EXPECT_EQ(result, true);
893 }
894 
895 /**
896  * @tc.number   Active_ProcessDataConnectionRoamOff_001
897  * @tc.name     test function branch
898  * @tc.desc     Function test
899  */
900 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOff_001, Function | MediumTest | Level1)
901 {
902     if (cellularMachine == nullptr) {
903         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
904         cellularMachine = machine->CreateCellularDataConnect(0);
905         cellularMachine->Init();
906     }
907     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
908     active->stateMachine_ = cellularMachine;
909     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
910     bool result = active->ProcessDataConnectionRoamOff(event);
911     EXPECT_EQ(result, true);
912 }
913 
914 /**
915  * @tc.number   Active_ProcessDataConnectionVoiceCallStartedOrEnded_001
916  * @tc.name     test function branch
917  * @tc.desc     Function test
918  */
919 HWTEST_F(CellularStateMachineTest, ProcessDataConnectionVoiceCallStartedOrEnded_001, 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(CellularDataEventCode::MSG_SM_CONNECT);
929     bool result = active->ProcessDataConnectionVoiceCallStartedOrEnded(event);
930     EXPECT_EQ(result, true);
931 }
932 
933 /**
934  * @tc.number   CellularDataStateMachine_GetSlotId_001
935  * @tc.name     test function branch
936  * @tc.desc     Function test
937  */
938 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetSlotId_001, Function | MediumTest | Level1)
939 {
940     std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
941     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
942     int result = cellularMachine->GetSlotId();
943     ASSERT_EQ(result, DEFAULT_SIM_SLOT_ID);
944 }
945 
946 /**
947  * @tc.number   CellularDataStateMachine_HasMatchedIpTypeAddrs_001
948  * @tc.name     test function branch
949  * @tc.desc     Function test
950  */
951 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_001, Function | MediumTest | Level1)
952 {
953     if (cellularMachine == nullptr) {
954         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
955         cellularMachine = machine->CreateCellularDataConnect(0);
956         cellularMachine->Init();
957     }
958     uint8_t ipType = 1;
959     uint8_t ipInfoArraySize = 2;
960     std::vector<AddressInfo> ipInfoArray;
961     AddressInfo info1;
962     info1.type = 1;
963     AddressInfo info2;
964     info2.type = 3;
965     ipInfoArray.push_back(info1);
966     ipInfoArray.push_back(info2);
967     bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray);
968     ASSERT_TRUE(result);
969 }
970 
971 /**
972  * @tc.number   CellularDataStateMachine_HasMatchedIpTypeAddrs_002
973  * @tc.name     test function branch
974  * @tc.desc     Function test
975  */
976 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_002, Function | MediumTest | Level1)
977 {
978     if (cellularMachine == nullptr) {
979         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
980         cellularMachine = machine->CreateCellularDataConnect(0);
981         cellularMachine->Init();
982     }
983     uint8_t ipType = 5;
984     uint8_t ipInfoArraySize = 2;
985     std::vector<AddressInfo> ipInfoArray;
986     AddressInfo info1;
987     info1.type = 1;
988     AddressInfo info2;
989     info2.type = 3;
990     ipInfoArray.push_back(info1);
991     ipInfoArray.push_back(info2);
992     bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray);
993     ASSERT_FALSE(result);
994 }
995 
996 /**
997  * @tc.number   GetIpType_ShouldReturnIPV4V6_001
998  * @tc.name     test function branch
999  * @tc.desc     Function test
1000  */
1001 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_001, TestSize.Level0)
1002 {
1003     if (cellularMachine == nullptr) {
1004         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1005         cellularMachine = machine->CreateCellularDataConnect(0);
1006         cellularMachine->Init();
1007     }
1008     std::vector<AddressInfo> ipInfoArray;
1009     AddressInfo info1;
1010     info1.type = INetAddr::IpType::IPV4;
1011     AddressInfo info2;
1012     info2.type = INetAddr::IpType::IPV6;
1013     ipInfoArray.push_back(info1);
1014     ipInfoArray.push_back(info2);
1015     std::string result = cellularMachine->GetIpType(ipInfoArray);
1016     ASSERT_EQ(result, "IPV4V6");
1017 }
1018 
1019 /**
1020  * @tc.number   GetIpType_ShouldReturnIPV4V6_002
1021  * @tc.name     test function branch
1022  * @tc.desc     Function test
1023  */
1024 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_002, TestSize.Level0)
1025 {
1026     if (cellularMachine == nullptr) {
1027         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1028         cellularMachine = machine->CreateCellularDataConnect(0);
1029         cellularMachine->Init();
1030     }
1031     std::vector<AddressInfo> ipInfoArray;
1032     AddressInfo info1;
1033     info1.type = INetAddr::IpType::IPV4;
1034     ipInfoArray.push_back(info1);
1035     std::string result = cellularMachine->GetIpType(ipInfoArray);
1036     ASSERT_EQ(result, "IPV4");
1037 }
1038 
1039 /**
1040  * @tc.number   GetIpType_ShouldReturnIPV6_003
1041  * @tc.name     test function branch
1042  * @tc.desc     Function test
1043  */
1044 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV6_003, TestSize.Level0)
1045 {
1046     if (cellularMachine == nullptr) {
1047         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1048         cellularMachine = machine->CreateCellularDataConnect(0);
1049         cellularMachine->Init();
1050     }
1051     std::vector<AddressInfo> ipInfoArray;
1052     AddressInfo info2;
1053     info2.type = INetAddr::IpType::IPV6;
1054     ipInfoArray.push_back(info2);
1055     std::string result = cellularMachine->GetIpType(ipInfoArray);
1056     ASSERT_EQ(result, "IPV6");
1057 }
1058 
1059 /**
1060  * @tc.number   GetIpType_ShouldReturnEmpty_004
1061  * @tc.name     test function branch
1062  * @tc.desc     Function test
1063  */
1064 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnEmpty_004, TestSize.Level0)
1065 {
1066     if (cellularMachine == nullptr) {
1067         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1068         cellularMachine = machine->CreateCellularDataConnect(0);
1069         cellularMachine->Init();
1070     }
1071     std::vector<AddressInfo> ipInfoArray = {};
1072     std::string result = cellularMachine->GetIpType(ipInfoArray);
1073     ASSERT_EQ(result, "");
1074 }
1075 
1076 /**
1077  * @tc.number   GetIpType_ShouldReturnIPV4V6_005
1078  * @tc.name     test function branch
1079  * @tc.desc     Function test
1080  */
1081 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_005, TestSize.Level0)
1082 {
1083     if (cellularMachine == nullptr) {
1084         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1085         cellularMachine = machine->CreateCellularDataConnect(0);
1086         cellularMachine->Init();
1087     }
1088     std::vector<AddressInfo> ipInfoArray;
1089     AddressInfo info1;
1090     info1.type = 5;
1091     AddressInfo info2;
1092     info2.type = 6;
1093     ipInfoArray.push_back(info1);
1094     ipInfoArray.push_back(info2);
1095     std::string result = cellularMachine->GetIpType(ipInfoArray);
1096     ASSERT_EQ(result, "");
1097 }
1098 
1099 /**
1100  * @tc.number   CellularDataStateMachine_UpdateNetworkInfo_001
1101  * @tc.name     test function branch
1102  * @tc.desc     Function test
1103  */
1104 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_001, TestSize.Level0) {
1105     if (cellularMachine == nullptr) {
1106         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1107         cellularMachine = machine->CreateCellularDataConnect(0);
1108         cellularMachine->Init();
1109     }
1110     SetupDataCallResultInfo dataCallInfo;
1111     dataCallInfo.address = "";
1112     dataCallInfo.dns = "";
1113     dataCallInfo.dnsSec = "";
1114     dataCallInfo.gateway = "";
1115     cellularMachine->UpdateNetworkInfo(dataCallInfo);
1116     ASSERT_EQ(cellularMachine->cause_, 0);
1117 }
1118 
1119 /**
1120  * @tc.number   CellularDataStateMachine_UpdateNetworkInfo_002
1121  * @tc.name     test function branch
1122  * @tc.desc     Function test
1123  */
1124 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_002, TestSize.Level0) {
1125     if (cellularMachine == nullptr) {
1126         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1127         cellularMachine = machine->CreateCellularDataConnect(0);
1128         cellularMachine->Init();
1129     }
1130     SetupDataCallResultInfo dataCallInfo;
1131     dataCallInfo.address = "192.168.1.1";
1132     dataCallInfo.dns = "192.168.1.1";
1133     dataCallInfo.dnsSec = "192.168.1.1";
1134     dataCallInfo.gateway = "192.168.1.1";
1135     dataCallInfo.reason = 1;
1136     cellularMachine->UpdateNetworkInfo(dataCallInfo);
1137     ASSERT_EQ(cellularMachine->cause_, 1);
1138 }
1139 
1140 /**
1141  * @tc.number   CellularDataStateMachine_UpdateNetworkInfo_003
1142  * @tc.name     test function branch
1143  * @tc.desc     Function test
1144  */
1145 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_003, TestSize.Level0) {
1146     std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1147     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1148     SetupDataCallResultInfo dataCallInfo;
1149     dataCallInfo.address = "192.168.1.1";
1150     dataCallInfo.dns = "192.168.1.1";
1151     dataCallInfo.dnsSec = "192.168.1.1";
1152     dataCallInfo.gateway = "192.168.1.1";
1153     dataCallInfo.reason = 1;
1154     cellularMachine->UpdateNetworkInfo(dataCallInfo);
1155     ASSERT_EQ(cellularMachine->cause_, 0);
1156 }
1157 
1158 /**
1159  * @tc.number   CellularDataStateMachine_UpdateNetworkInfo_004
1160  * @tc.name     test function branch
1161  * @tc.desc     Function test
1162  */
1163 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_004, TestSize.Level0) {
1164     if (cellularMachine == nullptr) {
1165         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1166         cellularMachine = machine->CreateCellularDataConnect(0);
1167         cellularMachine->Init();
1168     }
1169     cellularMachine->netSupplierInfo_->isAvailable_ = true;
1170     cellularMachine->UpdateNetworkInfo();
1171     ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr);
1172 }
1173 
1174 /**
1175  * @tc.number   CellularDataStateMachine_UpdateNetworkInfo_005
1176  * @tc.name     test function branch
1177  * @tc.desc     Function test
1178  */
1179 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_005, TestSize.Level0) {
1180     if (cellularMachine == nullptr) {
1181         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1182         cellularMachine = machine->CreateCellularDataConnect(0);
1183         cellularMachine->Init();
1184     }
1185     cellularMachine->netSupplierInfo_->isAvailable_ = false;
1186     cellularMachine->UpdateNetworkInfo();
1187     ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr);
1188 }
1189 
1190 /**
1191  * @tc.number   CellularDataStateMachine_ResolveRoute_001
1192  * @tc.name     test function branch
1193  * @tc.desc     Function test
1194  */
1195  HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_001, TestSize.Level0)
1196 {
1197     if (cellularMachine == nullptr) {
1198         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1199         cellularMachine = machine->CreateCellularDataConnect(0);
1200         cellularMachine->Init();
1201     }
1202     std::vector<AddressInfo> routeInfoArray;
1203     cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1204     EXPECT_TRUE(cellularMachine->netLinkInfo_->routeList_.empty());
1205 }
1206 
1207 /**
1208  * @tc.number   CellularDataStateMachine_ResolveRoute_002
1209  * @tc.name     test function branch
1210  * @tc.desc     Function test
1211  */
1212 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_002, TestSize.Level0)
1213 {
1214     if (cellularMachine == nullptr) {
1215         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1216         cellularMachine = machine->CreateCellularDataConnect(0);
1217         cellularMachine->Init();
1218     }
1219     std::vector<AddressInfo> routeInfoArray;
1220     AddressInfo routeInfo;
1221     routeInfo.ip = "192.168.1.1";
1222     routeInfo.type = INetAddr::IpType::IPV4;
1223     routeInfo.prefixLen = 24;
1224     routeInfoArray.push_back(routeInfo);
1225     cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1226     EXPECT_FALSE(cellularMachine->netLinkInfo_->routeList_.empty());
1227 }
1228 
1229 /**
1230  * @tc.number   CellularDataStateMachine_ResolveRoute_003
1231  * @tc.name     test function branch
1232  * @tc.desc     Function test
1233  */
1234 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_003, TestSize.Level0)
1235 {
1236     if (cellularMachine == nullptr) {
1237         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1238         cellularMachine = machine->CreateCellularDataConnect(0);
1239         cellularMachine->Init();
1240     }
1241     std::vector<AddressInfo> routeInfoArray;
1242     AddressInfo routeInfo1;
1243     routeInfo1.ip = "192.168.1.1";
1244     routeInfo1.type = INetAddr::IpType::IPV4;
1245     routeInfo1.prefixLen = 24;
1246     routeInfoArray.push_back(routeInfo1);
1247     AddressInfo routeInfo2;
1248     routeInfo2.ip = "2001:db8::1";
1249     routeInfo2.type = INetAddr::IpType::IPV6;
1250     routeInfo2.prefixLen = 64;
1251     routeInfoArray.push_back(routeInfo2);
1252     cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1253     EXPECT_EQ(cellularMachine->netLinkInfo_->routeList_.size(), 2);
1254 }
1255 
1256 /**
1257  * @tc.number   CellularDataStateMachine_UpdateNetworkInfoIfInActive_001
1258  * @tc.name     test function branch
1259  * @tc.desc     Function test
1260  */
1261 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_001, TestSize.Level0)
1262 {
1263     if (cellularMachine == nullptr) {
1264         std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1265         cellularMachine = machine->CreateCellularDataConnect(0);
1266         cellularMachine->Init();
1267     }
1268     SetupDataCallResultInfo dataCallInfo;
1269     cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo);
1270     EXPECT_NE(cellularMachine->stateMachineEventHandler_, nullptr);
1271 }
1272 
1273 /**
1274  * @tc.number   CellularDataStateMachine_UpdateNetworkInfoIfInActive_002
1275  * @tc.name     test function branch
1276  * @tc.desc     Function test
1277  */
1278 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_002, TestSize.Level0)
1279 {
1280     std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1281     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1282     SetupDataCallResultInfo dataCallInfo;
1283     cellularMachine->stateMachineEventHandler_ = nullptr;
1284     cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo);
1285     EXPECT_EQ(cellularMachine->stateMachineEventHandler_, nullptr);
1286 }
1287 } // namespace Telephony
1288 } // namespace OHOS