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 SecondaryActiveState_ProcessCallEnded_001
451 * @tc.name test function branch
452 * @tc.desc Function test
453 */
454 HWTEST_F(CellularStateMachineTest, SecondaryActiveState_ProcessCallEnded_001, 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 incallStateMachine = nullptr;
465 secondaryActiveState->stateMachine_ = incallStateMachine;
466 bool result = secondaryActiveState->ProcessCallEnded(event);
467 EXPECT_EQ(result, NOT_PROCESSED);
468 }
469
470 /**
471 * @tc.number SecondaryActiveState_ProcessCallEnded_002
472 * @tc.name test function branch
473 * @tc.desc Function test
474 */
475 HWTEST_F(CellularStateMachineTest, SecondaryActiveState_ProcessCallEnded_002, 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 incallStateMachine->UpdateCallState(static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE));
484 auto secondaryActiveState =
485 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr());
486 secondaryActiveState->stateMachine_ = incallStateMachine;
487 bool result = secondaryActiveState->ProcessCallEnded(event);
488 EXPECT_EQ(result, PROCESSED);
489 incallStateMachine->UpdateCallState(static_cast<int32_t>(TelCallStatus::CALL_STATUS_DISCONNECTED));
490 result = secondaryActiveState->ProcessCallEnded(event);
491 EXPECT_EQ(result, PROCESSED);
492 }
493
494 /**
495 * @tc.number SecondaryActiveState_IncallDataStateMachine_001
496 * @tc.name test function branch
497 * @tc.desc Function test
498 */
499 HWTEST_F(CellularStateMachineTest, SecondaryActiveState_IncallDataStateMachine_001, Function | MediumTest | Level1)
500 {
501 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
502 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
503 incallStateMachineTest->CreateIncallDataStateMachine(0);
504 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_INCALL_DATA_DATA_CONNECTED);
505 incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
506 incallStateMachine->TransitionTo(incallStateMachine->secondaryActiveState_);
507 auto secondaryActiveState =
508 static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr());
509 incallStateMachine = nullptr;
510 secondaryActiveState->stateMachine_ = incallStateMachine;
511 bool result = secondaryActiveState->ProcessCallEnded(event);
512 EXPECT_EQ(result, NOT_PROCESSED);
513 result = secondaryActiveState->ProcessSettingsOff(event);
514 EXPECT_EQ(result, NOT_PROCESSED);
515 }
516
517 /**
518 * @tc.number InactiveStateBegin_001
519 * @tc.name test function branch
520 * @tc.desc Function test
521 */
522 HWTEST_F(CellularStateMachineTest, InactiveStateBegin_001, Function | MediumTest | Level1)
523 {
524 if (cellularMachine == nullptr) {
525 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
526 cellularMachine = machine->CreateCellularDataConnect(0);
527 cellularMachine->Init();
528 }
529 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
530 inactive->deActiveApnTypeId_ = 0;
531 inactive->SetStateMachine(cellularMachine);
532 inactive->SetPdpErrorReason(PdpErrorReason::PDP_ERR_RETRY);
533 EXPECT_EQ(inactive->resultInfo_->reason, static_cast<int32_t>(PdpErrorReason::PDP_ERR_RETRY));
534 }
535
536 /**
537 * @tc.number InactiveStateProcess_002
538 * @tc.name test function branch
539 * @tc.desc Function test
540 */
541 HWTEST_F(CellularStateMachineTest, InactiveStateProcess_002, Function | MediumTest | Level1)
542 {
543 if (cellularMachine == nullptr) {
544 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
545 cellularMachine = machine->CreateCellularDataConnect(0);
546 cellularMachine->Init();
547 }
548 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
549 inactive->stateMachine_ = cellularMachine;
550 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT);
551 bool result = inactive->StateProcess(event);
552 EXPECT_EQ(result, true);
553 }
554
555 /**
556 * @tc.number InactiveStateProcess_003
557 * @tc.name test function branch
558 * @tc.desc Function test
559 */
560 HWTEST_F(CellularStateMachineTest, InactiveStateProcess_003, Function | MediumTest | Level1)
561 {
562 if (cellularMachine == nullptr) {
563 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
564 cellularMachine = machine->CreateCellularDataConnect(0);
565 cellularMachine->Init();
566 }
567 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
568 inactive->SetStateMachine(cellularMachine);
569 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT_ALL);
570 bool result = inactive->StateProcess(event);
571 EXPECT_EQ(result, true);
572 }
573
574 /**
575 * @tc.number Inactive_CellularDataStateMachine_001
576 * @tc.name test function branch
577 * @tc.desc Function test
578 */
579 HWTEST_F(CellularStateMachineTest, Inactive_CellularDataStateMachine_001, Function | MediumTest | Level1)
580 {
581 if (cellularMachine == nullptr) {
582 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
583 cellularMachine = machine->CreateCellularDataConnect(0);
584 cellularMachine->Init();
585 }
586 auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
587 cellularMachine = nullptr;
588 inactive->stateMachine_ = cellularMachine;
589 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_DISCONNECT_ALL);
590 bool result = inactive->StateProcess(event);
591 inactive->StateBegin();
592 EXPECT_EQ(result, false);
593 }
594
595 /**
596 * @tc.number DefaultStateProcess_001
597 * @tc.name test function branch
598 * @tc.desc Function test
599 */
600 HWTEST_F(CellularStateMachineTest, DefaultStateProcess_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 mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
608 mDefault->stateMachine_ = cellularMachine;
609 mDefault->eventIdFunMap_.clear();
610 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
611 bool result = mDefault->StateProcess(event);
612 EXPECT_EQ(result, false);
613 }
614
615 /**
616 * @tc.number DefaultStateProcess_002
617 * @tc.name test function branch
618 * @tc.desc Function test
619 */
620 HWTEST_F(CellularStateMachineTest, DefaultStateProcess_002, Function | MediumTest | Level1)
621 {
622 if (cellularMachine == nullptr) {
623 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
624 cellularMachine = machine->CreateCellularDataConnect(0);
625 cellularMachine->Init();
626 }
627 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
628 cellularMachine = nullptr;
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 DefaultProcessDisconnectDone_001
638 * @tc.name test function branch
639 * @tc.desc Function test
640 */
641 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectDone_001, 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 mDefault->stateMachine_ = cellularMachine;
650 mDefault->eventIdFunMap_.clear();
651 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
652 bool result = mDefault->ProcessDisconnectDone(event);
653 EXPECT_EQ(result, true);
654 }
655
656 /**
657 * @tc.number DefaultProcessDisconnectDone_002
658 * @tc.name test function branch
659 * @tc.desc Function test
660 */
661 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectDone_002, Function | MediumTest | Level1)
662 {
663 if (cellularMachine == nullptr) {
664 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
665 cellularMachine = machine->CreateCellularDataConnect(0);
666 cellularMachine->Init();
667 }
668 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
669 cellularMachine = nullptr;
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, false);
675 }
676
677 /**
678 * @tc.number DefaultProcessDisconnectAllDone_001
679 * @tc.name test function branch
680 * @tc.desc Function test
681 */
682 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectAllDone_001, 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 mDefault->stateMachine_ = cellularMachine;
691 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
692 bool result = mDefault->ProcessDisconnectAllDone(event);
693 EXPECT_EQ(result, true);
694 }
695
696 /**
697 * @tc.number DefaultProcessDisconnectAllDone_002
698 * @tc.name test function branch
699 * @tc.desc Function test
700 */
701 HWTEST_F(CellularStateMachineTest, DefaultProcessDisconnectAllDone_002, 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 mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
709 cellularMachine = nullptr;
710 mDefault->stateMachine_ = cellularMachine;
711 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
712 bool result = mDefault->ProcessDisconnectAllDone(event);
713 EXPECT_EQ(result, false);
714 }
715
716 /**
717 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_001
718 * @tc.name test function branch
719 * @tc.desc Function test
720 */
721 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_001, Function | MediumTest | Level1)
722 {
723 if (cellularMachine == nullptr) {
724 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
725 cellularMachine = machine->CreateCellularDataConnect(0);
726 cellularMachine->Init();
727 }
728 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
729 cellularMachine->TransitionTo(cellularMachine->activeState_);
730 mDefault->stateMachine_ = cellularMachine;
731 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
732 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
733 EXPECT_EQ(result, false);
734 }
735
736 /**
737 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_002
738 * @tc.name test function branch
739 * @tc.desc Function test
740 */
741 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_002, 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 mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
749 cellularMachine->TransitionTo(cellularMachine->activatingState_);
750 mDefault->stateMachine_ = cellularMachine;
751 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
752 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
753 EXPECT_EQ(result, false);
754 }
755
756 /**
757 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_003
758 * @tc.name test function branch
759 * @tc.desc Function test
760 */
761 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_003, 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 mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
769 cellularMachine->TransitionTo(cellularMachine->disconnectingState_);
770 mDefault->stateMachine_ = cellularMachine;
771 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
772 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
773 EXPECT_EQ(result, false);
774 }
775
776 /**
777 * @tc.number DefaultProcessDataConnectionDrsOrRatChanged_004
778 * @tc.name test function branch
779 * @tc.desc Function test
780 */
781 HWTEST_F(CellularStateMachineTest, DefaultProcessDataConnectionDrsOrRatChanged_004, Function | MediumTest | Level1)
782 {
783 if (cellularMachine == nullptr) {
784 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
785 cellularMachine = machine->CreateCellularDataConnect(0);
786 cellularMachine->Init();
787 }
788 auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
789 cellularMachine = nullptr;
790 mDefault->stateMachine_ = cellularMachine;
791 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
792 bool result = mDefault->ProcessDataConnectionDrsOrRatChanged(event);
793 EXPECT_EQ(result, false);
794 }
795
796 /**
797 * @tc.number Active_StateBegin_001
798 * @tc.name test function branch
799 * @tc.desc Function test
800 */
801 HWTEST_F(CellularStateMachineTest, Active_StateBegin_001, 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 active->stateMachine_ = cellularMachine;
810 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
811 active->StateBegin();
812 EXPECT_EQ(active->isActive_, true);
813 }
814
815 /**
816 * @tc.number Active_StateProcess_001
817 * @tc.name test function branch
818 * @tc.desc Function test
819 */
820 HWTEST_F(CellularStateMachineTest, Active_StateProcess_001, Function | MediumTest | Level1)
821 {
822 if (cellularMachine == nullptr) {
823 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
824 cellularMachine = machine->CreateCellularDataConnect(0);
825 cellularMachine->Init();
826 }
827 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
828 active->stateMachine_ = cellularMachine;
829 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
830 bool result = active->StateProcess(event);
831 EXPECT_EQ(result, true);
832 }
833
834 /**
835 * @tc.number Active_StateProcess_002
836 * @tc.name test function branch
837 * @tc.desc Function test
838 */
839 HWTEST_F(CellularStateMachineTest, Active_StateProcess_002, Function | MediumTest | Level1)
840 {
841 if (cellularMachine == nullptr) {
842 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
843 cellularMachine = machine->CreateCellularDataConnect(0);
844 cellularMachine->Init();
845 }
846 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
847 active->stateMachine_ = cellularMachine;
848 auto event = AppExecFwk::InnerEvent::Get(0);
849 bool result = active->StateProcess(event);
850 EXPECT_EQ(result, false);
851 }
852
853 /**
854 * @tc.number Active_StateProcess_003
855 * @tc.name test function branch
856 * @tc.desc Function test
857 */
858 HWTEST_F(CellularStateMachineTest, Active_StateProcess_003, Function | MediumTest | Level1)
859 {
860 if (cellularMachine == nullptr) {
861 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
862 cellularMachine = machine->CreateCellularDataConnect(0);
863 cellularMachine->Init();
864 }
865 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
866 cellularMachine = nullptr;
867 active->stateMachine_ = cellularMachine;
868 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
869 bool result = active->StateProcess(event);
870 EXPECT_EQ(result, true);
871 }
872
873 /**
874 * @tc.number Active_ProcessDisconnectDone_001
875 * @tc.name test function branch
876 * @tc.desc Function test
877 */
878 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_001, Function | MediumTest | Level1)
879 {
880 if (cellularMachine == nullptr) {
881 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
882 cellularMachine = machine->CreateCellularDataConnect(0);
883 cellularMachine->Init();
884 }
885 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
886 active->stateMachine_ = cellularMachine;
887 auto event = AppExecFwk::InnerEvent::Get(0);
888 event = nullptr;
889 bool result = active->ProcessDisconnectDone(event);
890 EXPECT_EQ(result, false);
891 }
892
893 /**
894 * @tc.number Active_ProcessDisconnectDone_002
895 * @tc.name test function branch
896 * @tc.desc Function test
897 */
898 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectDone_002, Function | MediumTest | Level1)
899 {
900 if (cellularMachine == nullptr) {
901 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
902 cellularMachine = machine->CreateCellularDataConnect(0);
903 cellularMachine->Init();
904 }
905 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
906 active->stateMachine_ = cellularMachine;
907 auto event = AppExecFwk::InnerEvent::Get(0);
908 bool result = active->ProcessDisconnectDone(event);
909 EXPECT_EQ(result, false);
910 }
911
912 /**
913 * @tc.number Active_ProcessDisconnectAllDone_001
914 * @tc.name test function branch
915 * @tc.desc Function test
916 */
917 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_001, Function | MediumTest | Level1)
918 {
919 if (cellularMachine == nullptr) {
920 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
921 cellularMachine = machine->CreateCellularDataConnect(0);
922 cellularMachine->Init();
923 }
924 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
925 active->stateMachine_ = cellularMachine;
926 auto event = AppExecFwk::InnerEvent::Get(0);
927 event = nullptr;
928 bool result = active->ProcessDisconnectAllDone(event);
929 EXPECT_EQ(result, false);
930 }
931
932 /**
933 * @tc.number Active_ProcessDisconnectAllDone_002
934 * @tc.name test function branch
935 * @tc.desc Function test
936 */
937 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_002, Function | MediumTest | Level1)
938 {
939 if (cellularMachine == nullptr) {
940 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
941 cellularMachine = machine->CreateCellularDataConnect(0);
942 cellularMachine->Init();
943 }
944 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
945 active->stateMachine_ = cellularMachine;
946 auto event = AppExecFwk::InnerEvent::Get(0);
947 bool result = active->ProcessDisconnectAllDone(event);
948 EXPECT_EQ(result, false);
949 }
950
951 /**
952 * @tc.number Active_ProcessDisconnectAllDone_003
953 * @tc.name test function branch
954 * @tc.desc Function test
955 */
956 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_003, Function | MediumTest | Level1)
957 {
958 if (cellularMachine == nullptr) {
959 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
960 cellularMachine = machine->CreateCellularDataConnect(0);
961 cellularMachine->Init();
962 }
963 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
964 cellularMachine->TransitionTo(cellularMachine->inActiveState_);
965 active->stateMachine_ = cellularMachine;
966 std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
967 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
968 auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams);
969 bool result = active->ProcessDisconnectAllDone(event);
970 EXPECT_EQ(result, false);
971 }
972
973 /**
974 * @tc.number Active_ProcessDisconnectAllDone_004
975 * @tc.name test function branch
976 * @tc.desc Function test
977 */
978 HWTEST_F(CellularStateMachineTest, Active_ProcessDisconnectAllDone_004, Function | MediumTest | Level1)
979 {
980 if (cellularMachine == nullptr) {
981 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
982 cellularMachine = machine->CreateCellularDataConnect(0);
983 cellularMachine->Init();
984 }
985 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
986 cellularMachine->inActiveState_ = nullptr;
987 active->stateMachine_ = cellularMachine;
988 std::shared_ptr<DataDisconnectParams> dataDisconnectParams =
989 std::make_shared<DataDisconnectParams>("", DisConnectionReason::REASON_NORMAL);
990 auto event = AppExecFwk::InnerEvent::Get(0, dataDisconnectParams);
991 bool result = active->ProcessDisconnectAllDone(event);
992 EXPECT_EQ(result, false);
993 }
994
995 /**
996 * @tc.number Active_ProcessLinkCapabilityChanged_001
997 * @tc.name test function branch
998 * @tc.desc Function test
999 */
1000 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_001, Function | MediumTest | Level1)
1001 {
1002 if (cellularMachine == nullptr) {
1003 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1004 cellularMachine = machine->CreateCellularDataConnect(0);
1005 cellularMachine->Init();
1006 }
1007 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1008 active->stateMachine_ = cellularMachine;
1009 auto event = AppExecFwk::InnerEvent::Get(0);
1010 bool result = active->ProcessLinkCapabilityChanged(event);
1011 EXPECT_EQ(result, false);
1012 }
1013
1014 /**
1015 * @tc.number Active_ProcessLinkCapabilityChanged_002
1016 * @tc.name test function branch
1017 * @tc.desc Function test
1018 */
1019 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_002, Function | MediumTest | Level1)
1020 {
1021 if (cellularMachine == nullptr) {
1022 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1023 cellularMachine = machine->CreateCellularDataConnect(0);
1024 cellularMachine->Init();
1025 }
1026 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1027 cellularMachine = nullptr;
1028 active->stateMachine_ = cellularMachine;
1029 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
1030 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1031 bool result = active->ProcessLinkCapabilityChanged(event);
1032 EXPECT_EQ(result, false);
1033 }
1034
1035 /**
1036 * @tc.number Active_ProcessLinkCapabilityChanged_003
1037 * @tc.name test function branch
1038 * @tc.desc Function test
1039 */
1040 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_003, 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 active->stateMachine_ = cellularMachine;
1049 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
1050 linkCapability->primaryUplinkKbps = 0;
1051 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1052 bool result = active->ProcessLinkCapabilityChanged(event);
1053 EXPECT_EQ(result, true);
1054 }
1055
1056 /**
1057 * @tc.number Active_ProcessLinkCapabilityChanged_004
1058 * @tc.name test function branch
1059 * @tc.desc Function test
1060 */
1061 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_004, 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 = 1;
1072 linkCapability->primaryDownlinkKbps = 0;
1073 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1074 bool result = active->ProcessLinkCapabilityChanged(event);
1075 EXPECT_EQ(result, true);
1076 }
1077
1078 /**
1079 * @tc.number Active_ProcessLinkCapabilityChanged_005
1080 * @tc.name test function branch
1081 * @tc.desc Function test
1082 */
1083 HWTEST_F(CellularStateMachineTest, Active_ProcessLinkCapabilityChanged_005, Function | MediumTest | Level1)
1084 {
1085 if (cellularMachine == nullptr) {
1086 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1087 cellularMachine = machine->CreateCellularDataConnect(0);
1088 cellularMachine->Init();
1089 }
1090 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1091 active->stateMachine_ = cellularMachine;
1092 std::shared_ptr<DataLinkCapability> linkCapability = std::make_shared<DataLinkCapability>();
1093 linkCapability->primaryUplinkKbps = 1;
1094 linkCapability->primaryDownlinkKbps = 1;
1095 auto event = AppExecFwk::InnerEvent::Get(0, linkCapability);
1096 bool result = active->ProcessLinkCapabilityChanged(event);
1097 EXPECT_EQ(result, true);
1098 }
1099
1100 /**
1101 * @tc.number Active_ProcessDataConnectionComplete_001
1102 * @tc.name test function branch
1103 * @tc.desc Function test
1104 */
1105 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_001, Function | MediumTest | Level1)
1106 {
1107 if (cellularMachine == nullptr) {
1108 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1109 cellularMachine = machine->CreateCellularDataConnect(0);
1110 cellularMachine->Init();
1111 }
1112 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1113 active->stateMachine_ = cellularMachine;
1114 auto event = AppExecFwk::InnerEvent::Get(0);
1115 bool result = active->ProcessDataConnectionComplete(event);
1116 EXPECT_EQ(result, false);
1117 }
1118
1119 /**
1120 * @tc.number Active_ProcessDataConnectionComplete_002
1121 * @tc.name test function branch
1122 * @tc.desc Function test
1123 */
1124 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_002, Function | MediumTest | Level1)
1125 {
1126 if (cellularMachine == nullptr) {
1127 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1128 cellularMachine = machine->CreateCellularDataConnect(0);
1129 cellularMachine->Init();
1130 }
1131 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1132 cellularMachine = nullptr;
1133 active->stateMachine_ = cellularMachine;
1134 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
1135 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
1136 bool result = active->ProcessDataConnectionComplete(event);
1137 EXPECT_EQ(result, false);
1138 }
1139
1140 /**
1141 * @tc.number Active_ProcessDataConnectionComplete_003
1142 * @tc.name test function branch
1143 * @tc.desc Function test
1144 */
1145 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_003, 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 active->stateMachine_ = cellularMachine;
1154 std::shared_ptr<SetupDataCallResultInfo> setupDataCallResultInfo = std::make_shared<SetupDataCallResultInfo>();
1155 auto event = AppExecFwk::InnerEvent::Get(0, setupDataCallResultInfo);
1156 bool result = active->ProcessDataConnectionComplete(event);
1157 EXPECT_EQ(result, true);
1158 }
1159
1160 /**
1161 * @tc.number Active_ProcessDataConnectionComplete_004
1162 * @tc.name test function branch
1163 * @tc.desc Function test
1164 */
1165 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionComplete_004, Function | MediumTest | Level1)
1166 {
1167 if (cellularMachine == nullptr) {
1168 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1169 cellularMachine = machine->CreateCellularDataConnect(0);
1170 cellularMachine->Init();
1171 }
1172 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1173 cellularMachine->stateMachineEventHandler_ = nullptr;
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, false);
1179 }
1180
1181 /**
1182 * @tc.number Active_ProcessNrStateChanged_001
1183 * @tc.name test function branch
1184 * @tc.desc Function test
1185 */
1186 HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_001, 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 active->stateMachine_ = cellularMachine;
1195 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1196 bool result = active->ProcessNrStateChanged(event);
1197 EXPECT_EQ(result, true);
1198 }
1199
1200 /**
1201 * @tc.number Active_ProcessNrStateChanged_002
1202 * @tc.name test function branch
1203 * @tc.desc Function test
1204 */
1205 HWTEST_F(CellularStateMachineTest, Active_ProcessNrStateChanged_002, Function | MediumTest | Level1)
1206 {
1207 if (cellularMachine == nullptr) {
1208 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1209 cellularMachine = machine->CreateCellularDataConnect(0);
1210 cellularMachine->Init();
1211 }
1212 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1213 cellularMachine = nullptr;
1214 active->stateMachine_ = cellularMachine;
1215 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1216 bool result = active->ProcessNrStateChanged(event);
1217 EXPECT_EQ(result, false);
1218 }
1219
1220 /**
1221 * @tc.number Active_ProcessNrFrequencyChanged_001
1222 * @tc.name test function branch
1223 * @tc.desc Function test
1224 */
1225 HWTEST_F(CellularStateMachineTest, Active_ProcessNrFrequencyChanged_001, Function | MediumTest | Level1)
1226 {
1227 if (cellularMachine == nullptr) {
1228 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1229 cellularMachine = machine->CreateCellularDataConnect(0);
1230 cellularMachine->Init();
1231 }
1232 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1233 cellularMachine = nullptr;
1234 active->stateMachine_ = cellularMachine;
1235 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1236 bool result = active->ProcessNrFrequencyChanged(event);
1237 EXPECT_EQ(result, false);
1238 }
1239
1240 /**
1241 * @tc.number Active_ProcessDisconnectAllDone_001
1242 * @tc.name test function branch
1243 * @tc.desc Function test
1244 */
1245 HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_001, Function | MediumTest | Level1)
1246 {
1247 if (cellularMachine == nullptr) {
1248 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1249 cellularMachine = machine->CreateCellularDataConnect(0);
1250 cellularMachine->Init();
1251 }
1252 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1253 cellularMachine->TransitionTo(cellularMachine->inActiveState_);
1254 active->stateMachine_ = cellularMachine;
1255 auto event = AppExecFwk::InnerEvent::Get(0);
1256 bool result = active->ProcessLostConnection(event);
1257 EXPECT_EQ(result, false);
1258 }
1259
1260 /**
1261 * @tc.number Active_ProcessLostConnection_002
1262 * @tc.name test function branch
1263 * @tc.desc Function test
1264 */
1265 HWTEST_F(CellularStateMachineTest, Active_ProcessLostConnection_002, Function | MediumTest | Level1)
1266 {
1267 if (cellularMachine == nullptr) {
1268 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1269 cellularMachine = machine->CreateCellularDataConnect(0);
1270 cellularMachine->Init();
1271 }
1272 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1273 cellularMachine->inActiveState_ = nullptr;
1274 active->stateMachine_ = cellularMachine;
1275 auto event = AppExecFwk::InnerEvent::Get(0);
1276 bool result = active->ProcessLostConnection(event);
1277 EXPECT_EQ(result, false);
1278 }
1279
1280 /**
1281 * @tc.number Active_ProcessDataConnectionRoamOn_001
1282 * @tc.name test function branch
1283 * @tc.desc Function test
1284 */
1285 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOn_001, Function | MediumTest | Level1)
1286 {
1287 if (cellularMachine == nullptr) {
1288 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1289 cellularMachine = machine->CreateCellularDataConnect(0);
1290 cellularMachine->Init();
1291 }
1292 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1293 active->stateMachine_ = cellularMachine;
1294 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1295 bool result = active->ProcessDataConnectionRoamOn(event);
1296 EXPECT_EQ(result, true);
1297 }
1298
1299 /**
1300 * @tc.number Active_ProcessDataConnectionRoamOff_001
1301 * @tc.name test function branch
1302 * @tc.desc Function test
1303 */
1304 HWTEST_F(CellularStateMachineTest, Active_ProcessDataConnectionRoamOff_001, Function | MediumTest | Level1)
1305 {
1306 if (cellularMachine == nullptr) {
1307 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1308 cellularMachine = machine->CreateCellularDataConnect(0);
1309 cellularMachine->Init();
1310 }
1311 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1312 active->stateMachine_ = cellularMachine;
1313 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1314 bool result = active->ProcessDataConnectionRoamOff(event);
1315 EXPECT_EQ(result, true);
1316 }
1317
1318 /**
1319 * @tc.number Active_ProcessDataConnectionVoiceCallStartedOrEnded_001
1320 * @tc.name test function branch
1321 * @tc.desc Function test
1322 */
1323 HWTEST_F(CellularStateMachineTest, ProcessDataConnectionVoiceCallStartedOrEnded_001, Function | MediumTest | Level1)
1324 {
1325 if (cellularMachine == nullptr) {
1326 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1327 cellularMachine = machine->CreateCellularDataConnect(0);
1328 cellularMachine->Init();
1329 }
1330 auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
1331 active->stateMachine_ = cellularMachine;
1332 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_CONNECT);
1333 bool result = active->ProcessDataConnectionVoiceCallStartedOrEnded(event);
1334 EXPECT_EQ(result, true);
1335 }
1336
1337 /**
1338 * @tc.number CellularDataStateMachine_GetSlotId_001
1339 * @tc.name test function branch
1340 * @tc.desc Function test
1341 */
1342 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetSlotId_001, Function | MediumTest | Level1)
1343 {
1344 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1345 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1346 int result = cellularMachine->GetSlotId();
1347 ASSERT_EQ(result, DEFAULT_SIM_SLOT_ID);
1348 }
1349
1350 /**
1351 * @tc.number CellularDataStateMachine_HasMatchedIpTypeAddrs_001
1352 * @tc.name test function branch
1353 * @tc.desc Function test
1354 */
1355 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_001, Function | MediumTest | Level1)
1356 {
1357 if (cellularMachine == nullptr) {
1358 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1359 cellularMachine = machine->CreateCellularDataConnect(0);
1360 cellularMachine->Init();
1361 }
1362 uint8_t ipType = 1;
1363 uint8_t ipInfoArraySize = 2;
1364 std::vector<AddressInfo> ipInfoArray;
1365 AddressInfo info1;
1366 info1.type = 1;
1367 AddressInfo info2;
1368 info2.type = 3;
1369 ipInfoArray.push_back(info1);
1370 ipInfoArray.push_back(info2);
1371 bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray);
1372 ASSERT_TRUE(result);
1373 }
1374
1375 /**
1376 * @tc.number CellularDataStateMachine_HasMatchedIpTypeAddrs_002
1377 * @tc.name test function branch
1378 * @tc.desc Function test
1379 */
1380 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_HasMatchedIpTypeAddrs_002, Function | MediumTest | Level1)
1381 {
1382 if (cellularMachine == nullptr) {
1383 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1384 cellularMachine = machine->CreateCellularDataConnect(0);
1385 cellularMachine->Init();
1386 }
1387 uint8_t ipType = 5;
1388 uint8_t ipInfoArraySize = 2;
1389 std::vector<AddressInfo> ipInfoArray;
1390 AddressInfo info1;
1391 info1.type = 1;
1392 AddressInfo info2;
1393 info2.type = 3;
1394 ipInfoArray.push_back(info1);
1395 ipInfoArray.push_back(info2);
1396 bool result = cellularMachine->HasMatchedIpTypeAddrs(ipType, ipInfoArraySize, ipInfoArray);
1397 ASSERT_FALSE(result);
1398 }
1399
1400 /**
1401 * @tc.number GetIpType_ShouldReturnIPV4V6_001
1402 * @tc.name test function branch
1403 * @tc.desc Function test
1404 */
1405 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_001, TestSize.Level0)
1406 {
1407 if (cellularMachine == nullptr) {
1408 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1409 cellularMachine = machine->CreateCellularDataConnect(0);
1410 cellularMachine->Init();
1411 }
1412 std::vector<AddressInfo> ipInfoArray;
1413 AddressInfo info1;
1414 info1.type = INetAddr::IpType::IPV4;
1415 AddressInfo info2;
1416 info2.type = INetAddr::IpType::IPV6;
1417 ipInfoArray.push_back(info1);
1418 ipInfoArray.push_back(info2);
1419 std::string result = cellularMachine->GetIpType(ipInfoArray);
1420 ASSERT_EQ(result, "IPV4V6");
1421 }
1422
1423 /**
1424 * @tc.number GetIpType_ShouldReturnIPV4V6_002
1425 * @tc.name test function branch
1426 * @tc.desc Function test
1427 */
1428 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_002, TestSize.Level0)
1429 {
1430 if (cellularMachine == nullptr) {
1431 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1432 cellularMachine = machine->CreateCellularDataConnect(0);
1433 cellularMachine->Init();
1434 }
1435 std::vector<AddressInfo> ipInfoArray;
1436 AddressInfo info1;
1437 info1.type = INetAddr::IpType::IPV4;
1438 ipInfoArray.push_back(info1);
1439 std::string result = cellularMachine->GetIpType(ipInfoArray);
1440 ASSERT_EQ(result, "IPV4");
1441 }
1442
1443 /**
1444 * @tc.number GetIpType_ShouldReturnIPV6_003
1445 * @tc.name test function branch
1446 * @tc.desc Function test
1447 */
1448 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV6_003, TestSize.Level0)
1449 {
1450 if (cellularMachine == nullptr) {
1451 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1452 cellularMachine = machine->CreateCellularDataConnect(0);
1453 cellularMachine->Init();
1454 }
1455 std::vector<AddressInfo> ipInfoArray;
1456 AddressInfo info2;
1457 info2.type = INetAddr::IpType::IPV6;
1458 ipInfoArray.push_back(info2);
1459 std::string result = cellularMachine->GetIpType(ipInfoArray);
1460 ASSERT_EQ(result, "IPV6");
1461 }
1462
1463 /**
1464 * @tc.number GetIpType_ShouldReturnEmpty_004
1465 * @tc.name test function branch
1466 * @tc.desc Function test
1467 */
1468 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnEmpty_004, TestSize.Level0)
1469 {
1470 if (cellularMachine == nullptr) {
1471 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1472 cellularMachine = machine->CreateCellularDataConnect(0);
1473 cellularMachine->Init();
1474 }
1475 std::vector<AddressInfo> ipInfoArray = {};
1476 std::string result = cellularMachine->GetIpType(ipInfoArray);
1477 ASSERT_EQ(result, "");
1478 }
1479
1480 /**
1481 * @tc.number GetIpType_ShouldReturnIPV4V6_005
1482 * @tc.name test function branch
1483 * @tc.desc Function test
1484 */
1485 HWTEST_F(CellularStateMachineTest, GetIpType_ShouldReturnIPV4V6_005, TestSize.Level0)
1486 {
1487 if (cellularMachine == nullptr) {
1488 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1489 cellularMachine = machine->CreateCellularDataConnect(0);
1490 cellularMachine->Init();
1491 }
1492 std::vector<AddressInfo> ipInfoArray;
1493 AddressInfo info1;
1494 info1.type = 5;
1495 AddressInfo info2;
1496 info2.type = 6;
1497 ipInfoArray.push_back(info1);
1498 ipInfoArray.push_back(info2);
1499 std::string result = cellularMachine->GetIpType(ipInfoArray);
1500 ASSERT_EQ(result, "");
1501 }
1502
1503 /**
1504 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_001
1505 * @tc.name test function branch
1506 * @tc.desc Function test
1507 */
1508 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_001, TestSize.Level0) {
1509 if (cellularMachine == nullptr) {
1510 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1511 cellularMachine = machine->CreateCellularDataConnect(0);
1512 cellularMachine->Init();
1513 }
1514 SetupDataCallResultInfo dataCallInfo;
1515 dataCallInfo.address = "";
1516 dataCallInfo.dns = "";
1517 dataCallInfo.dnsSec = "";
1518 dataCallInfo.gateway = "";
1519 cellularMachine->UpdateNetworkInfo(dataCallInfo);
1520 ASSERT_EQ(cellularMachine->cause_, 0);
1521 }
1522
1523 /**
1524 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_002
1525 * @tc.name test function branch
1526 * @tc.desc Function test
1527 */
1528 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_002, TestSize.Level0) {
1529 if (cellularMachine == nullptr) {
1530 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1531 cellularMachine = machine->CreateCellularDataConnect(0);
1532 cellularMachine->Init();
1533 }
1534 SetupDataCallResultInfo dataCallInfo;
1535 dataCallInfo.address = "192.168.1.1";
1536 dataCallInfo.dns = "192.168.1.1";
1537 dataCallInfo.dnsSec = "192.168.1.1";
1538 dataCallInfo.gateway = "192.168.1.1";
1539 dataCallInfo.reason = 1;
1540 cellularMachine->UpdateNetworkInfo(dataCallInfo);
1541 ASSERT_EQ(cellularMachine->cause_, 1);
1542 }
1543
1544 /**
1545 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_003
1546 * @tc.name test function branch
1547 * @tc.desc Function test
1548 */
1549 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_003, TestSize.Level0) {
1550 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1551 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1552 SetupDataCallResultInfo dataCallInfo;
1553 dataCallInfo.address = "192.168.1.1";
1554 dataCallInfo.dns = "192.168.1.1";
1555 dataCallInfo.dnsSec = "192.168.1.1";
1556 dataCallInfo.gateway = "192.168.1.1";
1557 dataCallInfo.reason = 1;
1558 cellularMachine->UpdateNetworkInfo(dataCallInfo);
1559 ASSERT_EQ(cellularMachine->cause_, 0);
1560 }
1561
1562 /**
1563 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_004
1564 * @tc.name test function branch
1565 * @tc.desc Function test
1566 */
1567 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_004, TestSize.Level0) {
1568 if (cellularMachine == nullptr) {
1569 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1570 cellularMachine = machine->CreateCellularDataConnect(0);
1571 cellularMachine->Init();
1572 }
1573 cellularMachine->netSupplierInfo_->isAvailable_ = true;
1574 cellularMachine->UpdateNetworkInfo();
1575 ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr);
1576 }
1577
1578 /**
1579 * @tc.number CellularDataStateMachine_UpdateNetworkInfo_005
1580 * @tc.name test function branch
1581 * @tc.desc Function test
1582 */
1583 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfo_005, TestSize.Level0) {
1584 if (cellularMachine == nullptr) {
1585 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1586 cellularMachine = machine->CreateCellularDataConnect(0);
1587 cellularMachine->Init();
1588 }
1589 cellularMachine->netSupplierInfo_->isAvailable_ = false;
1590 cellularMachine->UpdateNetworkInfo();
1591 ASSERT_NE(cellularMachine->netSupplierInfo_, nullptr);
1592 }
1593
1594 /**
1595 * @tc.number CellularDataStateMachine_ResolveRoute_001
1596 * @tc.name test function branch
1597 * @tc.desc Function test
1598 */
1599 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_001, TestSize.Level0)
1600 {
1601 if (cellularMachine == nullptr) {
1602 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1603 cellularMachine = machine->CreateCellularDataConnect(0);
1604 cellularMachine->Init();
1605 }
1606 std::vector<AddressInfo> routeInfoArray;
1607 cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1608 EXPECT_TRUE(cellularMachine->netLinkInfo_->routeList_.empty());
1609 }
1610
1611 /**
1612 * @tc.number CellularDataStateMachine_ResolveRoute_002
1613 * @tc.name test function branch
1614 * @tc.desc Function test
1615 */
1616 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_002, TestSize.Level0)
1617 {
1618 if (cellularMachine == nullptr) {
1619 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1620 cellularMachine = machine->CreateCellularDataConnect(0);
1621 cellularMachine->Init();
1622 }
1623 std::vector<AddressInfo> routeInfoArray;
1624 AddressInfo routeInfo;
1625 routeInfo.ip = "192.168.1.1";
1626 routeInfo.type = INetAddr::IpType::IPV4;
1627 routeInfo.prefixLen = 24;
1628 routeInfoArray.push_back(routeInfo);
1629 cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1630 EXPECT_FALSE(cellularMachine->netLinkInfo_->routeList_.empty());
1631 }
1632
1633 /**
1634 * @tc.number CellularDataStateMachine_ResolveRoute_003
1635 * @tc.name test function branch
1636 * @tc.desc Function test
1637 */
1638 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_ResolveRoute_003, TestSize.Level0)
1639 {
1640 if (cellularMachine == nullptr) {
1641 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1642 cellularMachine = machine->CreateCellularDataConnect(0);
1643 cellularMachine->Init();
1644 }
1645 std::vector<AddressInfo> routeInfoArray;
1646 AddressInfo routeInfo1;
1647 routeInfo1.ip = "192.168.1.1";
1648 routeInfo1.type = INetAddr::IpType::IPV4;
1649 routeInfo1.prefixLen = 24;
1650 routeInfoArray.push_back(routeInfo1);
1651 AddressInfo routeInfo2;
1652 routeInfo2.ip = "2001:db8::1";
1653 routeInfo2.type = INetAddr::IpType::IPV6;
1654 routeInfo2.prefixLen = 64;
1655 routeInfoArray.push_back(routeInfo2);
1656 cellularMachine->ResolveRoute(routeInfoArray, "eth0");
1657 EXPECT_EQ(cellularMachine->netLinkInfo_->routeList_.size(), 2);
1658 }
1659
1660 /**
1661 * @tc.number CellularDataStateMachine_UpdateNetworkInfoIfInActive_001
1662 * @tc.name test function branch
1663 * @tc.desc Function test
1664 */
1665 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_001, TestSize.Level0)
1666 {
1667 if (cellularMachine == nullptr) {
1668 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1669 cellularMachine = machine->CreateCellularDataConnect(0);
1670 cellularMachine->Init();
1671 }
1672 SetupDataCallResultInfo dataCallInfo;
1673 cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo);
1674 EXPECT_NE(cellularMachine->stateMachineEventHandler_, nullptr);
1675 }
1676
1677 /**
1678 * @tc.number CellularDataStateMachine_UpdateNetworkInfoIfInActive_002
1679 * @tc.name test function branch
1680 * @tc.desc Function test
1681 */
1682 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_UpdateNetworkInfoIfInActive_002, TestSize.Level0)
1683 {
1684 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1685 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1686 SetupDataCallResultInfo dataCallInfo;
1687 cellularMachine->stateMachineEventHandler_ = nullptr;
1688 cellularMachine->UpdateNetworkInfoIfInActive(dataCallInfo);
1689 EXPECT_EQ(cellularMachine->stateMachineEventHandler_, nullptr);
1690 }
1691
1692 /**
1693 * @tc.number CellularDataStateMachine_DoConnect_001
1694 * @tc.name test function branch
1695 * @tc.desc Function test
1696 */
1697 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_001, TestSize.Level0)
1698 {
1699 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1700 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1701 std::string proxyIpAddress = "";
1702 std::string host;
1703 uint16_t port;
1704 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port);
1705 ASSERT_EQ(host, "");
1706 ASSERT_EQ(port, 0);
1707 }
1708
1709 /**
1710 * @tc.number CellularDataStateMachine_DoConnect_001
1711 * @tc.name test function branch
1712 * @tc.desc Function test
1713 */
1714 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_002, TestSize.Level0)
1715 {
1716 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1717 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1718 std::string proxyIpAddress = "192.168.1.1";
1719 std::string host;
1720 uint16_t port;
1721 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port);
1722 ASSERT_EQ(host, "192.168.1.1");
1723 ASSERT_EQ(port, 0);
1724 }
1725
1726 /**
1727 * @tc.number CellularDataStateMachine_DoConnect_001
1728 * @tc.name test function branch
1729 * @tc.desc Function test
1730 */
1731 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_SplitProxyIpAddress_003, TestSize.Level0)
1732 {
1733 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
1734 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
1735 std::string proxyIpAddress = "192.168.1.1:8080";
1736 std::string host;
1737 uint16_t port;
1738 cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port);
1739 ASSERT_EQ(host, "192.168.1.1");
1740 ASSERT_EQ(port, 8080);
1741 }
1742
1743 /**
1744 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_001
1745 * @tc.name test function branch
1746 * @tc.desc Function test
1747 */
1748 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_001, TestSize.Level0)
1749 {
1750 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1751 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1752 incallStateMachineTest->CreateIncallDataStateMachine(0);
1753 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anonb0f166fd0102(int32_t &dsdsMode) 1754 .WillOnce([](int32_t &dsdsMode) {
1755 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V3);
1756 return 0;
1757 });
1758 auto result = incallStateMachine->IsSecondaryCanActiveData();
1759 ASSERT_EQ(result, false);
1760 }
1761
1762 /**
1763 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_002
1764 * @tc.name test function branch
1765 * @tc.desc Function test
1766 */
1767 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_002, TestSize.Level0)
1768 {
1769 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1770 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1771 incallStateMachineTest->CreateIncallDataStateMachine(0);
1772 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anonb0f166fd0202(int32_t &dsdsMode) 1773 .WillOnce([](int32_t &dsdsMode) {
1774 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1775 return 0;
1776 });
1777 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anonb0f166fd0302(int32_t &slotId) 1778 .WillOnce([](int32_t &slotId) {
1779 slotId = INVALID_SLOT_ID;
1780 return 0;
1781 });
1782 auto result = incallStateMachine->IsSecondaryCanActiveData();
1783 ASSERT_EQ(result, false);
1784 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anonb0f166fd0402(int32_t &slotId) 1785 .WillOnce([](int32_t &slotId) {
1786 slotId = 0;
1787 return 0;
1788 });
1789 result = incallStateMachine->IsSecondaryCanActiveData();
1790 ASSERT_EQ(result, false);
1791 }
1792
1793 /**
1794 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_002
1795 * @tc.name test function branch
1796 * @tc.desc Function test
1797 */
1798 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_003, TestSize.Level0)
1799 {
1800 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1801 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1802 incallStateMachineTest->CreateIncallDataStateMachine(0);
1803 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anonb0f166fd0502(int32_t &dsdsMode) 1804 .WillOnce([](int32_t &dsdsMode) {
1805 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1806 return 0;
1807 });
1808 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anonb0f166fd0602(int32_t &slotId) 1809 .WillOnce([](int32_t &slotId) {
1810 slotId = 1;
1811 return 0;
1812 });
1813 auto result = incallStateMachine->IsSecondaryCanActiveData();
1814 ASSERT_EQ(result, false);
1815 }
1816
1817 /**
1818 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1819 * @tc.name test function branch
1820 * @tc.desc Function test
1821 */
1822 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_004, TestSize.Level0)
1823 {
1824 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1825 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1826 incallStateMachineTest->CreateIncallDataStateMachine(0);
1827 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anonb0f166fd0702(int32_t &dsdsMode) 1828 .WillOnce([](int32_t &dsdsMode) {
1829 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1830 return 0;
1831 });
1832 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anonb0f166fd0802(int32_t &slotId) 1833 .WillOnce([](int32_t &slotId) {
1834 slotId = 1;
1835 return 0;
1836 });
1837 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anonb0f166fd0902(int32_t slotId, bool &hasSimCard) 1838 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1839 hasSimCard = true;
1840 return 0;
1841 });
1842 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anonb0f166fd0a02(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 1843 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
1844 switch (imsSrvType) {
1845 case ImsServiceType::TYPE_VOICE:
1846 info.imsRegState = ImsRegState::IMS_UNREGISTERED;
1847 break;
1848 case ImsServiceType::TYPE_VIDEO:
1849 info.imsRegState = ImsRegState::IMS_UNREGISTERED;
1850 break;
1851 default:
1852 break;
1853 }
1854 return 0;
1855 });
1856 auto result = incallStateMachine->IsSecondaryCanActiveData();
1857 ASSERT_EQ(result, false);
1858 }
1859
1860 /**
1861 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1862 * @tc.name test function branch
1863 * @tc.desc Function test
1864 */
1865 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_005, TestSize.Level0)
1866 {
1867 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1868 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1869 incallStateMachineTest->CreateIncallDataStateMachine(0);
1870 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anonb0f166fd0b02(int32_t &dsdsMode) 1871 .WillOnce([](int32_t &dsdsMode) {
1872 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1873 return 0;
1874 });
1875 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anonb0f166fd0c02(int32_t &slotId) 1876 .WillOnce([](int32_t &slotId) {
1877 slotId = 1;
1878 return 0;
1879 });
1880 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anonb0f166fd0d02(int32_t slotId, bool &hasSimCard) 1881 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1882 hasSimCard = true;
1883 return 0;
1884 });
1885 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anonb0f166fd0e02(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 1886 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
1887 switch (imsSrvType) {
1888 case ImsServiceType::TYPE_VOICE:
1889 info.imsRegState = ImsRegState::IMS_REGISTERED ;
1890 break;
1891 case ImsServiceType::TYPE_VIDEO:
1892 info.imsRegState = ImsRegState::IMS_UNREGISTERED;
1893 break;
1894 default:
1895 break;
1896 }
1897 return 0;
1898 });
1899 auto result = incallStateMachine->IsSecondaryCanActiveData();
1900 ASSERT_EQ(result, false);
1901 }
1902
1903 /**
1904 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1905 * @tc.name test function branch
1906 * @tc.desc Function test
1907 */
1908 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_006, TestSize.Level0)
1909 {
1910 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1911 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1912 incallStateMachineTest->CreateIncallDataStateMachine(0);
1913 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anonb0f166fd0f02(int32_t &dsdsMode) 1914 .WillOnce([](int32_t &dsdsMode) {
1915 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1916 return 0;
1917 });
1918 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anonb0f166fd1002(int32_t &slotId) 1919 .WillOnce([](int32_t &slotId) {
1920 slotId = 1;
1921 return 0;
1922 });
1923 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anonb0f166fd1102(int32_t slotId, bool &hasSimCard) 1924 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1925 hasSimCard = true;
1926 return 0;
1927 });
1928 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anonb0f166fd1202(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 1929 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
1930 switch (imsSrvType) {
1931 case ImsServiceType::TYPE_VOICE:
1932 info.imsRegState = ImsRegState::IMS_REGISTERED ;
1933 break;
1934 case ImsServiceType::TYPE_VIDEO:
1935 info.imsRegState = ImsRegState::IMS_REGISTERED;
1936 break;
1937 default:
1938 break;
1939 }
1940 return 0;
1941 });
1942 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_IDLE);
1943 auto result = incallStateMachine->IsSecondaryCanActiveData();
1944 ASSERT_EQ(result, false);
1945 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DISCONNECTED);
1946 result = incallStateMachine->IsSecondaryCanActiveData();
1947 ASSERT_EQ(result, false);
1948 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DIALING);
1949 result = incallStateMachine->IsSecondaryCanActiveData();
1950 ASSERT_EQ(result, false);
1951 }
1952
1953 /**
1954 * @tc.number IncallDataStateMachine_IsSecondaryCanActiveData_004
1955 * @tc.name test function branch
1956 * @tc.desc Function test
1957 */
1958 HWTEST_F(CellularStateMachineTest, IncallDataStateMachine_IsSecondaryCanActiveData_007, TestSize.Level0)
1959 {
1960 std::shared_ptr<IncallDataStateMachineTest> incallStateMachineTest = std::make_shared<IncallDataStateMachineTest>();
1961 std::shared_ptr<IncallDataStateMachine> incallStateMachine =
1962 incallStateMachineTest->CreateIncallDataStateMachine(0);
1963 EXPECT_CALL(*mockSimManager, GetDsdsMode(_)).Times(AtLeast(1))
__anonb0f166fd1302(int32_t &dsdsMode) 1964 .WillOnce([](int32_t &dsdsMode) {
1965 dsdsMode = static_cast<int32_t>(DsdsMode::DSDS_MODE_V2);
1966 return 0;
1967 });
1968 EXPECT_CALL(*mockSimManager, GetPrimarySlotId(_)).Times(AtLeast(1))
__anonb0f166fd1402(int32_t &slotId) 1969 .WillOnce([](int32_t &slotId) {
1970 slotId = 1;
1971 return 0;
1972 });
1973 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).Times(AtLeast(1))
__anonb0f166fd1502(int32_t slotId, bool &hasSimCard) 1974 .WillOnce([](int32_t slotId, bool &hasSimCard) {
1975 hasSimCard = true;
1976 return 0;
1977 });
1978 EXPECT_CALL(*mockNetworkSearchManager, GetImsRegStatus(_, _, _)).Times(AtLeast(2))
__anonb0f166fd1602(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) 1979 .WillOnce([](int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) {
1980 switch (imsSrvType) {
1981 case ImsServiceType::TYPE_VOICE:
1982 info.imsRegState = ImsRegState::IMS_REGISTERED ;
1983 break;
1984 case ImsServiceType::TYPE_VIDEO:
1985 info.imsRegState = ImsRegState::IMS_REGISTERED;
1986 break;
1987 default:
1988 break;
1989 }
1990 return 0;
1991 });
1992 EXPECT_CALL(*mockNetworkSearchManager, GetPsRadioTech(_, _)).Times(AtLeast(1))
__anonb0f166fd1702(int32_t slotId, int32_t &psRadioTech) 1993 .WillOnce([](int32_t slotId, int32_t &psRadioTech) {
1994 psRadioTech = static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_LTE);
1995 return 0;
1996 });
1997 incallStateMachine->callState_ = static_cast<int32_t>(TelCallStatus::CALL_STATUS_DIALING);
1998 auto result = incallStateMachine->IsSecondaryCanActiveData();
1999 ASSERT_EQ(result, true);
2000 }
2001
2002 /**
2003 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_001
2004 * @tc.name test function branch
2005 * @tc.desc Function test
2006 */
2007 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_001, TestSize.Level0)
2008 {
2009 int32_t mtuSize = 0;
2010 int32_t slotId = 0;
2011 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2012 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2013 EXPECT_CALL(*mockSimManager, GetOperatorConfigs(_, _)).Times(AtLeast(1))
__anonb0f166fd1802(int32_t slotId, OperatorConfig &poc) 2014 .WillOnce([](int32_t slotId, OperatorConfig &poc) {
2015 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:1500;ipv6:1400";
2016 return 0;
2017 });
2018 cellularMachine->ipType_ = "ipv4";
2019 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2020 ASSERT_EQ(mtuSize, 1500);
2021 }
2022
2023 /**
2024 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_002
2025 * @tc.name test function branch
2026 * @tc.desc Function test
2027 */
2028 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_002, 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))
__anonb0f166fd1902(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_ = "ipv6";
2040 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2041 ASSERT_EQ(mtuSize, 1400);
2042 }
2043
2044 /**
2045 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_003
2046 * @tc.name test function branch
2047 * @tc.desc Function test
2048 */
2049 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_003, 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))
__anonb0f166fd1a02(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_ = "ipv5";
2061 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2062 ASSERT_EQ(mtuSize, 0);
2063 }
2064
2065 /**
2066 * @tc.number CellularDataStateMachine_GetMtuSizeFromOpCfg_004
2067 * @tc.name test function branch
2068 * @tc.desc Function test
2069 */
2070 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetMtuSizeFromOpCfg_004, 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))
__anonb0f166fd1b02(int32_t slotId, OperatorConfig &poc) 2077 .WillOnce([](int32_t slotId, OperatorConfig &poc) {
2078 poc.stringValue[KEY_MTU_SIZE_STRING] = "ipv4:abc;ipv6:1400";
2079 return 0;
2080 });
2081 cellularMachine->ipType_ = "ipv4";
2082 cellularMachine->GetMtuSizeFromOpCfg(mtuSize, slotId);
2083 ASSERT_EQ(mtuSize, 0);
2084 }
2085
2086 /**
2087 * @tc.number CellularDataStateMachine_GetNetScoreBySlotId_001
2088 * @tc.name test function branch
2089 * @tc.desc Function test
2090 */
2091 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetNetScoreBySlotId_001, TestSize.Level0)
2092 {
2093 int32_t score;
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, GetDefaultCellularDataSlotId()).Times(AtLeast(1))
__anonb0f166fd1c02() 2098 .WillOnce([]() {
2099 return 0;
2100 });
2101 score = cellularMachine->GetNetScoreBySlotId(slotId);
2102 ASSERT_EQ(score, DEFAULT_INTERNET_CONNECTION_SCORE);
2103 }
2104
2105 /**
2106 * @tc.number CellularDataStateMachine_GetNetScoreBySlotId_002
2107 * @tc.name test function branch
2108 * @tc.desc Function test
2109 */
2110 HWTEST_F(CellularStateMachineTest, CellularDataStateMachine_GetNetScoreBySlotId_002, TestSize.Level0)
2111 {
2112 int32_t score;
2113 int32_t slotId = 0;
2114 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2115 std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
2116 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1))
__anonb0f166fd1d02() 2117 .WillOnce([]() {
2118 return 1;
2119 });
2120 score = cellularMachine->GetNetScoreBySlotId(slotId);
2121 ASSERT_EQ(score, OTHER_CONNECTION_SCORE);
2122 }
2123
2124 /**
2125 * @tc.number Default_ProcessUpdateNetworkInfo_001
2126 * @tc.name test function branch
2127 * @tc.desc Function test
2128 */
2129 HWTEST_F(CellularStateMachineTest, Default_ProcessUpdateNetworkInfo_001, Function | MediumTest | Level1)
2130 {
2131 if (cellularMachine == nullptr) {
2132 std::shared_ptr<CellularMachineTest> machine = std::make_shared<CellularMachineTest>();
2133 cellularMachine = machine->CreateCellularDataConnect(0);
2134 cellularMachine->Init();
2135 EXPECT_CALL(*mockSimManager, GetDefaultCellularDataSlotId()).Times(AtLeast(1))
__anonb0f166fd1e02() 2136 .WillOnce([]() {
2137 return 0;
2138 });
2139 }
2140 auto defaultState = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
2141 defaultState->stateMachine_ = cellularMachine;
2142 auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_SM_UPDATE_NETWORK_INFO);
2143 bool result = defaultState->ProcessUpdateNetworkInfo(event);
2144 EXPECT_EQ(result, true);
2145 }
2146 } // namespace Telephony
2147 } // namespace OHOS