• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #include "activating.h"
18 #include "active.h"
19 #include "apn_holder.h"
20 #include "apn_item.h"
21 #include "apn_manager.h"
22 #include "cellular_data_client.h"
23 #include "cellular_data_constant.h"
24 #include "cellular_data_controller.h"
25 #include "cellular_data_dump_helper.h"
26 #include "cellular_data_handler.h"
27 #include "cellular_data_hisysevent.h"
28 #include "cellular_data_rdb_observer.h"
29 #include "cellular_data_roaming_observer.h"
30 #include "cellular_data_service.h"
31 #include "cellular_data_service_stub.h"
32 #include "cellular_data_setting_observer.h"
33 #include "cellular_data_settings_rdb_helper.h"
34 #include "cellular_data_state_machine.h"
35 #include "cellular_data_utils.h"
36 #include "common_event_manager.h"
37 #include "common_event_support.h"
38 #include "data_connection_manager.h"
39 #include "data_connection_monitor.h"
40 #include "datashare_result_set.h"
41 #include "default.h"
42 #include "disconnecting.h"
43 #include "gtest/gtest.h"
44 #include "inactive.h"
45 #include "incall_data_state_machine.h"
46 #include "net_manager_call_back.h"
47 #include "net_manager_tactics_call_back.h"
48 #include "network_search_callback.h"
49 #include "pdp_profile_data.h"
50 #include "state_notification.h"
51 #include "telephony_errors.h"
52 #include "telephony_hisysevent.h"
53 #include "telephony_log_wrapper.h"
54 #include "uri.h"
55 
56 namespace OHOS {
57 namespace Telephony {
58 using namespace testing::ext;
59 
60 namespace {
61 const int32_t INVALID_SLOTID = -1;
62 const int32_t INVALID_SLOTID_TWO = 5;
63 const int32_t INVALID_CID = -1;
64 const int32_t INVALID_FD = -1;
65 const std::string ADDRESS = "127.0.0.1";
66 const std::string FLAG = ".";
67 } // namespace
68 
69 class DemoHandler : public AppExecFwk::EventHandler {
70 public:
DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> & runner)71     explicit DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> &runner) : AppExecFwk::EventHandler(runner) {}
~DemoHandler()72     virtual ~DemoHandler() {}
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)73     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) {}
74 };
75 
76 class BranchTest : public testing::Test {
77 public:
78     static void SetUpTestCase();
79     static void TearDownTestCase();
80     void SetUp();
81     void TearDown();
82 };
SetUpTestCase()83 void BranchTest::SetUpTestCase() {}
84 
TearDownTestCase()85 void BranchTest::TearDownTestCase() {}
86 
SetUp()87 void BranchTest::SetUp() {}
88 
TearDown()89 void BranchTest::TearDown() {}
90 
91 class StateMachineTest : public TelEventHandler {
92 public:
StateMachineTest()93     StateMachineTest() : TelEventHandler("StateMachineTest") {}
94     ~StateMachineTest() = default;
95     std::shared_ptr<CellularDataStateMachine> CreateCellularDataConnect(int32_t slotId);
96 
97 public:
98     std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_ = nullptr;
99 };
100 
CreateCellularDataConnect(int32_t slotId)101 std::shared_ptr<CellularDataStateMachine> StateMachineTest::CreateCellularDataConnect(int32_t slotId)
102 {
103     if (cellularDataStateMachine_ != nullptr) {
104         return cellularDataStateMachine_;
105     }
106     sptr<DataConnectionManager> connectionManager = std::make_unique<DataConnectionManager>(slotId).release();
107     if (connectionManager == nullptr) {
108         return nullptr;
109     }
110     connectionManager->Init();
111     cellularDataStateMachine_ = std::make_shared<CellularDataStateMachine>(
112         connectionManager, std::static_pointer_cast<TelEventHandler>(shared_from_this()));
113     return cellularDataStateMachine_;
114 }
115 
116 class IncallStateMachineTest : public TelEventHandler {
117 public:
IncallStateMachineTest()118     IncallStateMachineTest() : TelEventHandler("IncallStateMachineTest") {}
119     ~IncallStateMachineTest() = default;
120     std::shared_ptr<IncallDataStateMachine> CreateIncallDataStateMachine(int32_t slotId);
121 
122 public:
123     std::shared_ptr<IncallDataStateMachine> incallStateMachine_ = nullptr;
124 };
125 
CreateIncallDataStateMachine(int32_t slotId)126 std::shared_ptr<IncallDataStateMachine> IncallStateMachineTest::CreateIncallDataStateMachine(int32_t slotId)
127 {
128     if (incallStateMachine_ != nullptr) {
129         return incallStateMachine_;
130     }
131     sptr<ApnManager> apnManager = std::make_unique<ApnManager>().release();
132     if (apnManager == nullptr) {
133         return nullptr;
134     }
135     incallStateMachine_ = std::make_shared<IncallDataStateMachine>(slotId,
136         std::weak_ptr<TelEventHandler>(std::static_pointer_cast<TelEventHandler>(shared_from_this())), apnManager);
137     return incallStateMachine_;
138 }
139 
140 /**
141  * @tc.number   Telephony_CellularDataHandler_001
142  * @tc.name     test error branch
143  * @tc.desc     Function test
144  */
145 HWTEST_F(BranchTest, Telephony_CellularDataHandler_001, Function | MediumTest | Level1)
146 {
147     EventFwk::MatchingSkills matchingSkills;
148     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED);
149     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
150     CellularDataHandler cellularDataHandler { subscriberInfo, 0 };
151     NetRequest request { 0, "simId1" };
152     ASSERT_FALSE(cellularDataHandler.ReleaseNet(request));
153     ASSERT_FALSE(cellularDataHandler.RequestNet(request));
154     auto event = AppExecFwk::InnerEvent::Get(0);
155     event = nullptr;
156     cellularDataHandler.ProcessEvent(event);
157     EventFwk::CommonEventData data;
158     cellularDataHandler.OnReceiveEvent(data);
159     ASSERT_NE(cellularDataHandler.SetCellularDataEnable(true), TELEPHONY_ERR_SUCCESS);
160     bool dataEnaled = false;
161     cellularDataHandler.IsCellularDataEnabled(dataEnaled);
162     ASSERT_FALSE(dataEnaled);
163     bool dataRoamingEnabled = false;
164     cellularDataHandler.IsCellularDataRoamingEnabled(dataRoamingEnabled);
165     ASSERT_FALSE(dataRoamingEnabled);
166     ASSERT_NE(cellularDataHandler.SetCellularDataRoamingEnabled(true), TELEPHONY_ERR_SUCCESS);
167     ASSERT_EQ(ApnProfileState::PROFILE_STATE_IDLE, cellularDataHandler.GetCellularDataState());
168     ASSERT_EQ(ApnProfileState::PROFILE_STATE_IDLE, cellularDataHandler.GetCellularDataState(""));
169     sptr<ApnHolder> apnHolder;
170     DisConnectionReason reason = cellularDataHandler.GetDisConnectionReason();
171     cellularDataHandler.ClearConnection(apnHolder, reason);
172     cellularDataHandler.EstablishAllApnsIfConnectable();
173     cellularDataHandler.ClearAllConnections(reason);
174     cellularDataHandler.GetSlotId();
175     ASSERT_FALSE(cellularDataHandler.HandleApnChanged());
176     cellularDataHandler.HandleApnChanged(event);
177     cellularDataHandler.GetCellularDataFlowType();
178     cellularDataHandler.SetPolicyDataOn(true);
179     ASSERT_FALSE(cellularDataHandler.IsRestrictedMode());
180     cellularDataHandler.GetDisConnectionReason();
181     ASSERT_FALSE(cellularDataHandler.HasInternetCapability(0));
182     ASSERT_EQ(nullptr, cellularDataHandler.FindIdleCellularDataConnection());
183     cellularDataHandler.AttemptEstablishDataConnection(apnHolder);
184     ASSERT_FALSE(cellularDataHandler.CheckAttachAndSimState(apnHolder));
185     ASSERT_FALSE(cellularDataHandler.CheckRoamingState(apnHolder));
186     ASSERT_FALSE(cellularDataHandler.CheckApnState(apnHolder));
187 }
188 
189 /**
190  * @tc.number   Telephony_CellularDataHandler_002
191  * @tc.name     test error branch
192  * @tc.desc     Function test
193  */
194 HWTEST_F(BranchTest, Telephony_CellularDataHandler_002, Function | MediumTest | Level1)
195 {
196     EventFwk::MatchingSkills matchingSkills;
197     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED);
198     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
199     CellularDataHandler cellularDataHandler { subscriberInfo, 0 };
200     auto event = AppExecFwk::InnerEvent::Get(0);
201     event = nullptr;
202     sptr<ApnHolder> apnHolder;
203     ApnItem::Attribute apnAttr;
204     cellularDataHandler.RadioPsConnectionAttached(event);
205     cellularDataHandler.RadioPsConnectionDetached(event);
206     cellularDataHandler.RoamingStateOn(event);
207     cellularDataHandler.RoamingStateOff(event);
208     cellularDataHandler.EstablishDataConnectionComplete(event);
209     cellularDataHandler.DisconnectDataComplete(event);
210     cellularDataHandler.MsgEstablishDataConnection(event);
211     cellularDataHandler.MsgRequestNetwork(event);
212     cellularDataHandler.HandleSettingSwitchChanged(event);
213     cellularDataHandler.HandleDBSettingIncallChanged(event);
214     cellularDataHandler.HandleDefaultDataSubscriptionChanged();
215     cellularDataHandler.IncallDataComplete(event);
216     cellularDataHandler.HandleCallChanged(0);
217     cellularDataHandler.HandleImsCallChanged(0);
218     cellularDataHandler.HandleVoiceCallChanged(0);
219     cellularDataHandler.HandleSimStateOrRecordsChanged(event);
220     cellularDataHandler.HandleSimAccountLoaded(event);
221     cellularDataHandler.HandleRadioStateChanged(event);
222     cellularDataHandler.HandleDsdsModeChanged(event);
223     cellularDataHandler.SetRilAttachApnResponse(event);
224     cellularDataHandler.GetDefaultConfiguration();
225     cellularDataHandler.HandleRadioNrStateChanged(event);
226     cellularDataHandler.HandleRadioNrFrequencyChanged(event);
227     cellularDataHandler.HandleDBSettingEnableChanged(event);
228     cellularDataHandler.HandleDBSettingRoamingChanged(event);
229     cellularDataHandler.SetDataPermittedResponse(event);
230     cellularDataHandler.OnRilAdapterHostDied(event);
231     cellularDataHandler.OnCleanAllDataConnectionsDone(event);
232     cellularDataHandler.RegisterDataSettingObserver();
233     cellularDataHandler.UnRegisterDataSettingObserver();
234     cellularDataHandler.GetDataConnApnAttr(apnAttr);
235     cellularDataHandler.HandleFactoryReset(event);
236     ASSERT_FALSE(cellularDataHandler.HasAnyHigherPriorityConnection(apnHolder));
237 }
238 
239 /**
240  * @tc.number   Telephony_CellularDataHandler_003
241  * @tc.name     test error branch
242  * @tc.desc     Function test
243  */
244 HWTEST_F(BranchTest, Telephony_CellularDataHandler_003, Function | MediumTest | Level3)
245 {
246     EventFwk::MatchingSkills matchingSkills;
247     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED);
248     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
249     CellularDataHandler cellularDataHandler { subscriberInfo, INVALID_SLOTID };
250     cellularDataHandler.apnManager_ = std::make_unique<ApnManager>().release();
251     NetRequest request;
252     ASSERT_FALSE(cellularDataHandler.ReleaseNet(request));
253     cellularDataHandler.SetDataPermittedForMms(false);
254     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
255     DisConnectionReason reason = DisConnectionReason::REASON_NORMAL;
256     cellularDataHandler.ClearConnection(apnHolder, reason);
257     cellularDataHandler.EstablishAllApnsIfConnectable();
258     cellularDataHandler.ClearAllConnections(reason);
259     cellularDataHandler.ChangeConnectionForDsds(false);
260     cellularDataHandler.connectionManager_ = std::make_unique<DataConnectionManager>(INVALID_SLOTID).release();
261     cellularDataHandler.ClearAllConnections(reason);
262     cellularDataHandler.EstablishAllApnsIfConnectable();
263     cellularDataHandler.UpdatePhysicalConnectionState(true);
264     cellularDataHandler.ClearAllConnections(DisConnectionReason::REASON_CLEAR_CONNECTION);
265     ASSERT_FALSE(cellularDataHandler.CheckApnState(apnHolder));
266     cellularDataHandler.AttemptEstablishDataConnection(apnHolder);
267     cellularDataHandler.connectionManager_ = nullptr;
268     auto event = AppExecFwk::InnerEvent::Get(0);
269     event = nullptr;
270     cellularDataHandler.MsgEstablishDataConnection(event);
271     ASSERT_FALSE(cellularDataHandler.HasAnyHigherPriorityConnection(apnHolder));
272     cellularDataHandler.connectionManager_ = std::make_unique<DataConnectionManager>(INVALID_SLOTID).release();
273     ASSERT_FALSE(cellularDataHandler.HasInternetCapability(INVALID_CID));
274 }
275 
276 /**
277  * @tc.number   Telephony_CellularDataService_001
278  * @tc.name     test error branch
279  * @tc.desc     Function test
280  */
281 HWTEST_F(BranchTest, Telephony_CellularDataService_001, Function | MediumTest | Level3)
282 {
283     CellularDataService service;
284     std::vector<std::u16string> strV;
285     ASSERT_EQ(TELEPHONY_ERR_FAIL, service.Dump(INVALID_FD, strV));
286     service.state_ = ServiceRunningState::STATE_RUNNING;
287     service.OnStart();
288     service.InitModule();
289     bool dataEnabled = false;
290     bool dataRoamingEnabled = false;
291     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.IsCellularDataEnabled(dataEnabled));
292     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.EnableCellularData(false));
293     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.GetCellularDataState());
294     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.IsCellularDataRoamingEnabled(INVALID_SLOTID, dataRoamingEnabled));
295     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.EnableCellularDataRoaming(INVALID_SLOTID, false));
296     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.HandleApnChanged(INVALID_SLOTID));
297     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.GetDefaultCellularDataSlotId());
298     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.SetDefaultCellularDataSlotId(INVALID_SLOTID));
299     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.GetCellularDataFlowType());
300     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.HasInternetCapability(INVALID_SLOTID, 0));
301     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ClearCellularDataConnections(INVALID_SLOTID));
302     DisConnectionReason reason = DisConnectionReason::REASON_NORMAL;
303     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ClearAllConnections(INVALID_SLOTID, reason));
304     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ChangeConnectionForDsds(INVALID_SLOTID, false));
305     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.StrategySwitch(INVALID_SLOTID, false));
306     NetRequest request;
307     request.ident = "simId12";
308     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.RequestNet(request));
309     request.ident = "simId2";
310     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ReleaseNet(request));
311     ASSERT_FALSE(service.CheckParamValid(INVALID_SLOTID));
312     ASSERT_FALSE(service.CheckParamValid(INVALID_SLOTID_TWO));
313 }
314 
315 /**
316  * @tc.number  CellularDataController_001
317  * @tc.name     test error branch
318  * @tc.desc     Function test
319  */
320 HWTEST_F(BranchTest, Telephony_CellularDataController_001, Function | MediumTest | Level3)
321 {
322     CellularDataController controller { 0 };
323     controller.RegisterEvents();
324     controller.Init();
325     controller.cellularDataHandler_ = nullptr;
326     NetRequest request;
327     ASSERT_FALSE(controller.ReleaseNet(request));
328     ASSERT_FALSE(controller.RequestNet(request));
329     ASSERT_NE(controller.SetCellularDataEnable(true), TELEPHONY_ERR_SUCCESS);
330     bool dataEnabled = false;
331     controller.IsCellularDataEnabled(dataEnabled);
332     ASSERT_FALSE(dataEnabled);
333     ASSERT_NE(controller.SetCellularDataRoamingEnabled(true), TELEPHONY_ERR_SUCCESS);
334     EXPECT_EQ(ApnProfileState::PROFILE_STATE_FAILED, controller.GetCellularDataState());
335     EXPECT_EQ(ApnProfileState::PROFILE_STATE_FAILED, controller.GetCellularDataState(""));
336     bool dataRoamingEnabled = false;
337     controller.IsCellularDataRoamingEnabled(dataRoamingEnabled);
338     ASSERT_FALSE(dataRoamingEnabled);
339     ASSERT_FALSE(controller.HandleApnChanged());
340     auto event = AppExecFwk::InnerEvent::Get(0);
341     controller.ProcessEvent(event);
342     event = nullptr;
343     controller.ProcessEvent(event);
344     controller.RegisterEvents();
345     ASSERT_FALSE(controller.IsRestrictedMode());
346     ASSERT_EQ(DisConnectionReason::REASON_NORMAL, controller.GetDisConnectionReason());
347     controller.HasInternetCapability(0);
348     DisConnectionReason reason = DisConnectionReason::REASON_NORMAL;
349     ASSERT_FALSE(controller.ClearAllConnections(reason));
350     ASSERT_FALSE(controller.ChangeConnectionForDsds(false));
351     controller.UnRegisterEvents();
352     ASSERT_FALSE(controller.HandleApnChanged());
353     ASSERT_FALSE(controller.GetCellularDataFlowType());
354 }
355 
356 /**
357  * @tc.number  CellularDataConnectionManager_001
358  * @tc.name     test error branch
359  * @tc.desc     Function test
360  */
361 HWTEST_F(BranchTest, Telephony_CellularDataConnectionManager_001, Function | MediumTest | Level3)
362 {
363     DataConnectionManager con { 0 };
364     con.Init();
365     con.connectionMonitor_ = nullptr;
366     con.ccmDefaultState_ = nullptr;
367     con.stateMachineEventHandler_ = nullptr;
368     std::shared_ptr<CellularDataStateMachine> stateMachine = nullptr;
369     con.RemoveConnectionStateMachine(stateMachine);
370     ASSERT_TRUE(con.GetActiveConnectionByCid(0) == nullptr);
371     ASSERT_TRUE(con.isNoActiveConnection());
372     auto event = AppExecFwk::InnerEvent::Get(0);
373     event = nullptr;
374     CcmDefaultState ccmDefaultState { con, "CcmDefaultState" };
375     ASSERT_FALSE(ccmDefaultState.StateProcess(event));
376     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_CONNECTED);
377     ASSERT_TRUE(ccmDefaultState.StateProcess(event));
378     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_DATA_CALL_LIST_CHANGED);
379     ASSERT_TRUE(ccmDefaultState.StateProcess(event));
380     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_LINK_CAPABILITY_CHANGED);
381     ASSERT_TRUE(ccmDefaultState.StateProcess(event));
382     event = AppExecFwk::InnerEvent::Get(0);
383     ASSERT_FALSE(ccmDefaultState.StateProcess(event));
384     ccmDefaultState.RadioDataCallListChanged(event);
385     ccmDefaultState.UpdateNetworkInfo(event);
386     ccmDefaultState.RadioLinkCapabilityChanged(event);
387     con.GetDataFlowType();
388     con.GetDefaultBandWidthsConfig();
389     con.GetDefaultTcpBufferConfig();
390     con.SetDataFlowType(CellDataFlowType::DATA_FLOW_TYPE_NONE);
391     con.UpdateCallState(0);
392     ASSERT_EQ("", con.GetTcpBufferByRadioTech(0));
393     ASSERT_TRUE(con.GetBandwidthsByRadioTech(0).upBandwidth == DEFAULT_BANDWIDTH);
394 }
395 
396 /**
397  * @tc.number  DataConnectionMonitor_001
398  * @tc.name     test error branch
399  * @tc.desc     Function test
400  */
401 HWTEST_F(BranchTest, Telephony_DataConnectionMonitor_001, Function | MediumTest | Level3)
402 {
403     DataConnectionMonitor mon { 0 };
404     mon.trafficManager_ = nullptr;
405     mon.stallDetectionTrafficManager_ = nullptr;
406     mon.UpdateFlowInfo();
407     mon.UpdateCallState(0);
408     auto event = AppExecFwk::InnerEvent::Get(0);
409     mon.SetPreferredNetworkPara(event);
410     mon.UpdateDataFlowType();
411     mon.ProcessEvent(event);
412     event = nullptr;
413     mon.ProcessEvent(event);
414     ASSERT_EQ(CellDataFlowType::DATA_FLOW_TYPE_NONE, mon.GetDataFlowType());
415 }
416 
417 /**
418  * @tc.number  CellularDataUtils_001
419  * @tc.name     test error branch
420  * @tc.desc     Function test
421  */
422 HWTEST_F(BranchTest, Telephony_CellularDataUtils_001, Function | MediumTest | Level3)
423 {
424     ASSERT_EQ("unknown",
425         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_UNKNOWN)));
426     ASSERT_EQ(
427         "EDGE", CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_GSM)));
428     ASSERT_EQ("1xRTT",
429         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_1XRTT)));
430     ASSERT_EQ("UMTS",
431         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_WCDMA)));
432     ASSERT_EQ(
433         "HSPA", CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_HSPA)));
434     ASSERT_EQ("HSPAP",
435         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_HSPAP)));
436     ASSERT_EQ("TD-SCDMA",
437         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_TD_SCDMA)));
438     ASSERT_EQ(
439         "EVDO", CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_EVDO)));
440     ASSERT_EQ("eHRPD",
441         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_EHRPD)));
442     ASSERT_EQ(
443         "LTE", CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_LTE)));
444     ASSERT_EQ("LTE_CA",
445         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_LTE_CA)));
446     ASSERT_EQ("IWAN",
447         CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_IWLAN)));
448     ASSERT_EQ(
449         "NR", CellularDataUtils::ConvertRadioTechToRadioName(static_cast<int32_t>(RadioTech::RADIO_TECHNOLOGY_NR)));
450     ASSERT_FALSE(CellularDataUtils::IsDigit(""));
451     ASSERT_TRUE(CellularDataUtils::Split("", "").empty());
452     AddressInfo info;
453     ASSERT_TRUE(CellularDataUtils::ParseDotIpData(
454         "a1.a2.a3.a4.a5.a6.a7.a8.a9.a10.a11.a12.a13.a14.a15.a16.m1.m2.m3.m4.m5.m6.m7.m8.m9.m10.m11.m12.m13.m14.m15.m16",
455         info));
456     ASSERT_TRUE(CellularDataUtils::ParseDotIpData("a1.a2.a3.a4.m1.m2.m3.m4", info));
457     EXPECT_GE(DelayedSingleton<CellularDataClient>::GetInstance()->GetCellularDataFlowType(), 0);
458     auto recipient =
459         std::make_shared<CellularDataClient::CellularDataDeathRecipient>(CellularDataClient::GetInstance());
460     recipient->OnRemoteDied(nullptr);
461     EXPECT_GE(DelayedSingleton<CellularDataClient>::GetInstance()->GetCellularDataFlowType(), 0);
462 }
463 
464 /**
465  * @tc.number   Telephony_ApnHolder_001
466  * @tc.name     test error branch
467  * @tc.desc     Function test
468  */
469 HWTEST_F(BranchTest, Telephony_ApnHolder_001, Function | MediumTest | Level3)
470 {
471     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
472     apnHolder->GetNextRetryApn();
473     std::vector<sptr<ApnItem>> matchedApns;
474     apnHolder->SetAllMatchedApns(matchedApns);
475     apnHolder->GetRetryDelay();
476     sptr<ApnItem> apnItem;
477     apnHolder->SetCurrentApn(apnItem);
478     apnHolder->GetCurrentApn();
479     apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_IDLE);
480     apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_FAILED);
481     apnHolder->GetApnState();
482     apnHolder->IsDataCallEnabled();
483     apnHolder->IsDataCallConnectable();
484     apnHolder->GetApnType();
485     apnHolder->ReleaseDataConnection();
486     apnHolder->cellularDataStateMachine_ = nullptr;
487     apnHolder->ReleaseDataConnection();
488     apnHolder->SetCellularDataStateMachine(apnHolder->cellularDataStateMachine_);
489     apnHolder->InitialApnRetryCount();
490     apnHolder->GetCellularDataStateMachine();
491     apnHolder->GetCapability();
492     apnHolder->GetPriority();
493     apnHolder->InitialApnRetryCount();
494     NetRequest request;
495     request.ident = "test";
496     request.capability = -1;
497     apnHolder->RequestCellularData(request);
498     apnHolder->ReleaseCellularData(request);
499     apnHolder->RequestCellularData(request);
500     apnHolder->ReleaseCellularData(request);
501     ASSERT_FALSE(apnHolder->IsEmergencyType());
502     ASSERT_FALSE(apnHolder->IsMmsType());
503     EXPECT_GE(apnHolder->GetProfileId(DATA_CONTEXT_ROLE_DEFAULT), DATA_PROFILE_DEFAULT);
504     EXPECT_GE(apnHolder->GetProfileId("test"), DATA_PROFILE_DEFAULT);
505 }
506 
507 /**
508  * @tc.number   Telephony_ApnHolder_002
509  * @tc.name     test error branch
510  * @tc.desc     Function test
511  */
512 HWTEST_F(BranchTest, Telephony_ApnHolder_002, Function | MediumTest | Level3)
513 {
514     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
515     std::vector<sptr<ApnItem>> newMatchedApns;
516     std::vector<sptr<ApnItem>> oldMatchedApns;
517     apnHolder->SetAllMatchedApns(oldMatchedApns);
518     ASSERT_FALSE(apnHolder->IsSameMatchedApns(newMatchedApns, true));
519     sptr<ApnItem> apnItemFirst = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
520     newMatchedApns.push_back(apnItemFirst);
521     oldMatchedApns.push_back(apnItemFirst);
522     apnHolder->SetAllMatchedApns(oldMatchedApns);
523     ASSERT_TRUE(apnHolder->IsSameMatchedApns(newMatchedApns, true));
524     sptr<ApnItem> apnItemSecond = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
525     newMatchedApns.push_back(apnItemSecond);
526     ASSERT_FALSE(apnHolder->IsSameMatchedApns(newMatchedApns, true));
527 }
528 
529 /**
530  * @tc.number   Telephony_ApnHolder_003
531  * @tc.name     test error branch
532  * @tc.desc     Function test
533  */
534 HWTEST_F(BranchTest, Telephony_ApnHolder_003, Function | MediumTest | Level3)
535 {
536     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
537     sptr<ApnItem> newApnItem;
538     sptr<ApnItem> oldApnItem;
539     ASSERT_FALSE(apnHolder->IsSameApnItem(newApnItem, oldApnItem, true));
540     newApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
541     oldApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
542     ASSERT_TRUE(apnHolder->IsSameApnItem(newApnItem, oldApnItem, true));
543     oldApnItem->CanDealWithType(DATA_CONTEXT_ROLE_DEFAULT);
544     oldApnItem->GetApnTypes();
545     PdpProfile apnBean;
546     oldApnItem->MakeApn(apnBean);
547     oldApnItem->MarkBadApn(false);
548     ASSERT_FALSE(oldApnItem->IsBadApn());
549 }
550 
551 /**
552  * @tc.number   NetworkSearchCallback_Test_01
553  * @tc.name    TestDump
554  * @tc.desc     Function test
555  */
556 HWTEST_F(BranchTest, NetworkSearchCallback_Test_01, Function | MediumTest | Level3)
557 {
558     auto networkSearchCallback = std::make_shared<NetworkSearchCallback>();
559     networkSearchCallback->ClearCellularDataConnections(0);
560     networkSearchCallback->ClearCellularDataConnections(-1);
561     networkSearchCallback->HasInternetCapability(0, 0);
562     ASSERT_FALSE(networkSearchCallback->HasInternetCapability(-1, -1));
563 }
564 
565 /**
566  * @tc.number   StateNotification_Test_01
567  * @tc.name    TestDump
568  * @tc.desc     Function test
569  */
570 HWTEST_F(BranchTest, StateNotification_Test_01, Function | MediumTest | Level3)
571 {
572     StateNotification::GetInstance().UpdateCellularDataConnectState(0, PROFILE_STATE_DISCONNECTING, 0);
573     StateNotification::GetInstance().OnUpDataFlowtype(0, CellDataFlowType::DATA_FLOW_TYPE_NONE);
574     StateNotification::GetInstance().OnUpDataFlowtype(1, CellDataFlowType::DATA_FLOW_TYPE_UP_DOWN);
575     std::shared_ptr<CellularDataHandler> cellularDataHandler = nullptr;
576     auto cellularDataRdbObserver = std::make_shared<CellularDataRdbObserver>(cellularDataHandler);
577     cellularDataRdbObserver->OnChange();
578     ASSERT_TRUE(cellularDataHandler == nullptr);
579 }
580 
581 /**
582  * @tc.number   Active_Test_01
583  * @tc.name    TestDump
584  * @tc.desc     Function test
585  */
586 HWTEST_F(BranchTest, Active_Test_01, Function | MediumTest | Level3)
587 {
588     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
589     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
590     cellularMachine->Init();
591     auto active = static_cast<Active *>(cellularMachine->activeState_.GetRefPtr());
592     std::weak_ptr<CellularDataStateMachine> stateMachine1;
593     active->stateMachine_ = stateMachine1;
594     active->StateBegin();
595     active->StateEnd();
596     auto event = AppExecFwk::InnerEvent::Get(0);
597     event = nullptr;
598     active->RefreshTcpBufferSizes();
599     active->RefreshConnectionBandwidths();
600     active->ProcessConnectDone(event);
601     ASSERT_FALSE(active->StateProcess(event));
602     ASSERT_FALSE(active->ProcessDisconnectDone(event));
603     ASSERT_FALSE(active->ProcessDisconnectAllDone(event));
604     ASSERT_FALSE(active->ProcessLostConnection(event));
605     ASSERT_FALSE(active->ProcessRilAdapterHostDied(event));
606     ASSERT_FALSE(active->ProcessLinkCapabilityChanged(event));
607     ASSERT_FALSE(active->ProcessNrStateChanged(event));
608     ASSERT_FALSE(active->ProcessNrFrequencyChanged(event));
609     ASSERT_FALSE(active->ProcessDataConnectionComplete(event));
610     ASSERT_FALSE(active->ProcessDataConnectionVoiceCallStartedOrEnded(event));
611     ASSERT_FALSE(active->ProcessDataConnectionRoamOn(event));
612     ASSERT_FALSE(active->ProcessDataConnectionRoamOff(event));
613 }
614 
615 /**
616  * @tc.number   Activating_Test_01
617  * @tc.name    TestDump
618  * @tc.desc     Function test
619  */
620 HWTEST_F(BranchTest, Activating_Test_02, Function | MediumTest | Level3)
621 {
622     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
623     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
624     cellularMachine->Init();
625     auto activating = static_cast<Activating *>(cellularMachine->activatingState_.GetRefPtr());
626     std::weak_ptr<CellularDataStateMachine> stateMachine1;
627     activating->stateMachine_ = stateMachine1;
628     activating->StateBegin();
629     activating->StateEnd();
630     auto event = AppExecFwk::InnerEvent::Get(0);
631     event = nullptr;
632     activating->ProcessConnectTimeout(event);
633     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_RETRY);
634     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_UNKNOWN);
635     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_SHORTAGE_RESOURCES);
636     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_ACTIVATION_REJECTED_UNSPECIFIED);
637     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_SERVICE_OPTION_TEMPORARILY_OUT_OF_ORDER);
638     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_APN_NOT_SUPPORTED_IN_CURRENT_RAT_PLMN);
639     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_APN_RESTRICTION_VALUE_INCOMPATIBLE);
640     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_MULT_ACCESSES_PDN_NOT_ALLOWED);
641     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_OPERATOR_DETERMINED_BARRING);
642     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_MISSING_OR_UNKNOWN_APN);
643     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_UNKNOWN_PDP_ADDR_OR_TYPE);
644     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_USER_VERIFICATION);
645     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_ACTIVATION_REJECTED_GGSN);
646     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_SERVICE_OPTION_NOT_SUPPORTED);
647     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_REQUESTED_SERVICE_OPTION_NOT_SUBSCRIBED);
648     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_NSAPI_ALREADY_USED);
649     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_IPV4_ONLY_ALLOWED);
650     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_IPV6_ONLY_ALLOWED);
651     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_IPV4V6_ONLY_ALLOWED);
652     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_NON_IP_ONLY_ALLOWED);
653     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_MAX_NUM_OF_PDP_CONTEXTS);
654     activating->DataCallPdpError(HRilPdpErrorReason::HRIL_PDP_ERR_PROTOCOL_ERRORS);
655     activating->DataCallPdpError(-1);
656     ASSERT_FALSE(activating->RilActivatePdpContextDone(event));
657     ASSERT_FALSE(activating->RilErrorResponse(event));
658     ASSERT_FALSE(activating->StateProcess(event));
659 }
660 
661 /**
662  * @tc.number   Inactive_Test_01
663  * @tc.name    TestDump
664  * @tc.desc     Function test
665  */
666 HWTEST_F(BranchTest, Inactive_Test_01, Function | MediumTest | Level3)
667 {
668     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
669     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
670     cellularMachine->Init();
671     auto inactive = static_cast<Inactive *>(cellularMachine->inActiveState_.GetRefPtr());
672     std::weak_ptr<CellularDataStateMachine> stateMachine1;
673     inactive->SetStateMachine(stateMachine1);
674     auto event = AppExecFwk::InnerEvent::Get(0);
675     event = nullptr;
676     inactive->StateBegin();
677     inactive->StateEnd();
678     inactive->SetDeActiveApnTypeId(0);
679     inactive->SetReason(DisConnectionReason::REASON_NORMAL);
680     ASSERT_FALSE(inactive->StateProcess(event));
681 }
682 
683 /**
684  * @tc.number   Disconnecting_Test_01
685  * @tc.name    TestDump
686  * @tc.desc     Function test
687  */
688 HWTEST_F(BranchTest, Disconnecting_Test_01, Function | MediumTest | Level3)
689 {
690     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
691     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
692     cellularMachine->Init();
693     auto disconnecting = static_cast<Disconnecting *>(cellularMachine->disconnectingState_.GetRefPtr());
694     std::weak_ptr<CellularDataStateMachine> stateMachine1;
695     disconnecting->stateMachine_ = stateMachine1;
696     auto event = AppExecFwk::InnerEvent::Get(0);
697     event = nullptr;
698     disconnecting->StateBegin();
699     disconnecting->StateEnd();
700     disconnecting->ProcessDisconnectTimeout(event);
701     disconnecting->ProcessRilAdapterHostDied(event);
702     ASSERT_FALSE(disconnecting->StateProcess(event));
703 }
704 
705 /**
706  * @tc.number   Default_Test_01
707  * @tc.name    TestDump
708  * @tc.desc     Function test
709  */
710 HWTEST_F(BranchTest, Default_Test_01, Function | MediumTest | Level3)
711 {
712     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
713     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
714     cellularMachine->Init();
715     auto mDefault = static_cast<Default *>(cellularMachine->defaultState_.GetRefPtr());
716     std::weak_ptr<CellularDataStateMachine> stateMachine1;
717     mDefault->stateMachine_ = stateMachine1;
718     auto event = AppExecFwk::InnerEvent::Get(0);
719     event = nullptr;
720     mDefault->StateBegin();
721     mDefault->StateEnd();
722     ASSERT_FALSE(mDefault->StateProcess(event));
723     ASSERT_FALSE(mDefault->ProcessConnectDone(event));
724     ASSERT_FALSE(mDefault->ProcessDisconnectDone(event));
725     ASSERT_FALSE(mDefault->ProcessDisconnectAllDone(event));
726     ASSERT_FALSE(mDefault->ProcessDataConnectionDrsOrRatChanged(event));
727     ASSERT_FALSE(mDefault->ProcessDataConnectionRoamOn(event));
728     ASSERT_FALSE(mDefault->ProcessDataConnectionRoamOff(event));
729 }
730 
731 /**
732  * @tc.number   ApnManager_Test_01
733  * @tc.name    TestDump
734  * @tc.desc     Function test
735  */
736 HWTEST_F(BranchTest, ApnManager_Test_01, Function | MediumTest | Level3)
737 {
738     auto apnManager = std::make_shared<ApnManager>();
739     apnManager->CreateAllApnItem();
740     EXPECT_GE(apnManager->CreateAllApnItemByDatabase(0), 0);
741     EXPECT_EQ(apnManager->CreateAllApnItemByDatabase(0), 0);
742     apnManager->ResetApns();
743     std::string operatorNumeric = "46011";
744     apnManager->GetCTOperator(0, operatorNumeric);
745     EXPECT_EQ(operatorNumeric, "46011");
746     apnManager->GetApnHolder(DATA_CONTEXT_ROLE_DEFAULT);
747     apnManager->FindApnNameByApnId(1);
748     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
749     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
750     cellularMachine->Init();
751     ASSERT_TRUE(apnManager->IsDataConnectionNotUsed(cellularMachine));
752     auto helper = CellularDataRdbHelper::GetInstance();
753     helper->ResetApns();
754     std::shared_ptr<DataShare::DataShareResultSet> result = nullptr;
755     std::vector<PdpProfile> apnVec;
756     helper->ReadMvnoApnResult(result, "", apnVec);
757     PdpProfile apnBean;
758     ASSERT_FALSE(helper->IsMvnoDataMatched("", apnBean));
759     apnBean.mvnoType = MvnoType::ICCID;
760     apnBean.mvnoMatchData = "test";
761     ASSERT_TRUE(helper->IsMvnoDataMatched("test", apnBean));
762     apnBean.mvnoType = MvnoType::SPN;
763     ASSERT_TRUE(helper->IsMvnoDataMatched("test", apnBean));
764     apnBean.mvnoType = MvnoType::GID1;
765     ASSERT_TRUE(helper->IsMvnoDataMatched("test", apnBean));
766     apnBean.mvnoType = MvnoType::IMSI;
767     ASSERT_TRUE(helper->IsMvnoDataMatched("test", apnBean));
768     apnBean.mvnoType = "error";
769     ASSERT_FALSE(helper->IsMvnoDataMatched("test", apnBean));
770     helper->QueryPreferApn(0, apnVec);
771     ASSERT_FALSE(helper->QueryPreferApn(-1, apnVec));
772 }
773 
774 /**
775  * @tc.number   IdleState_Test_01
776  * @tc.name     test error branch
777  * @tc.desc     Function test
778  */
779 HWTEST_F(BranchTest, Idle_Test_01, Function | MediumTest | Level3)
780 {
781     std::shared_ptr<IncallStateMachineTest> incallStateMachineTest = std::make_shared<IncallStateMachineTest>();
782     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
783         incallStateMachineTest->CreateIncallDataStateMachine(0);
784     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
785     incallStateMachine->GetCurrentState();
786     incallStateMachine->GetSlotId();
787     incallStateMachine->GetCallState();
788     incallStateMachine->HasAnyConnectedState();
789     incallStateMachine->UpdateCallState(TelCallStatus::CALL_STATUS_ALERTING);
790     incallStateMachine->IsIncallDataSwitchOn();
791     incallStateMachine->IsSecondaryCanActiveData();
792     incallStateMachine->CanActiveDataByRadioTech();
793     auto idleState = static_cast<IdleState *>(incallStateMachine->idleState_.GetRefPtr());
794     auto event = AppExecFwk::InnerEvent::Get(0);
795     event = nullptr;
796     idleState->StateBegin();
797     ASSERT_FALSE(idleState->StateProcess(event));
798     ASSERT_TRUE(idleState->ProcessCallStarted(event));
799     ASSERT_TRUE(idleState->ProcessCallEnded(event));
800     ASSERT_TRUE(idleState->ProcessSettingsOn(event));
801     ASSERT_TRUE(idleState->ProcessDsdsChanged(event));
802     idleState->StateEnd();
803 }
804 
805 /**
806  * @tc.number   ActivatingSecondaryState_Test_01
807  * @tc.name     test error branch
808  * @tc.desc     Function test
809  */
810 HWTEST_F(BranchTest, ActivatingSecondaryState_Test_01, Function | MediumTest | Level3)
811 {
812     std::shared_ptr<IncallStateMachineTest> incallStateMachineTest = std::make_shared<IncallStateMachineTest>();
813     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
814         incallStateMachineTest->CreateIncallDataStateMachine(0);
815     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
816     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
817     auto activatingSecondaryState =
818         static_cast<ActivatingSecondaryState *>(incallStateMachine->activatingSecondaryState_.GetRefPtr());
819     auto secondaryActiveState =
820         static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr());
821     auto event = AppExecFwk::InnerEvent::Get(0);
822     event = nullptr;
823     secondaryActiveState->StateBegin();
824     activatingSecondaryState->StateBegin();
825     ASSERT_FALSE(activatingSecondaryState->StateProcess(event));
826     ASSERT_FALSE(secondaryActiveState->StateProcess(event));
827     ASSERT_TRUE(secondaryActiveState->ProcessSettingsOn(event));
828     ASSERT_TRUE(secondaryActiveState->ProcessCallEnded(event));
829     ASSERT_TRUE(secondaryActiveState->ProcessSettingsOff(event));
830     ASSERT_TRUE(secondaryActiveState->ProcessDsdsChanged(event));
831     activatingSecondaryState->StateEnd();
832     secondaryActiveState->StateEnd();
833 }
834 
835 /**
836  * @tc.number   ActivatedSecondaryState_Test_01
837  * @tc.name     test error branch
838  * @tc.desc     Function test
839  */
840 HWTEST_F(BranchTest, ActivatedSecondaryState_Test_01, Function | MediumTest | Level3)
841 {
842     std::shared_ptr<IncallStateMachineTest> incallStateMachineTest = std::make_shared<IncallStateMachineTest>();
843     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
844         incallStateMachineTest->CreateIncallDataStateMachine(0);
845     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
846     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
847     incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_);
848     auto activatedSecondaryState =
849         static_cast<ActivatedSecondaryState *>(incallStateMachine->activatedSecondaryState_.GetRefPtr());
850     auto secondaryActiveState =
851         static_cast<SecondaryActiveState *>(incallStateMachine->secondaryActiveState_.GetRefPtr());
852     auto event = AppExecFwk::InnerEvent::Get(0);
853     event = nullptr;
854     secondaryActiveState->StateBegin();
855     activatedSecondaryState->StateBegin();
856     ASSERT_FALSE(activatedSecondaryState->StateProcess(event));
857     ASSERT_FALSE(secondaryActiveState->StateProcess(event));
858     ASSERT_TRUE(secondaryActiveState->ProcessCallEnded(event));
859     ASSERT_TRUE(secondaryActiveState->ProcessSettingsOff(event));
860     activatedSecondaryState->StateEnd();
861     secondaryActiveState->StateEnd();
862 }
863 
864 /**
865  * @tc.number   DeactivatingSecondaryState_Test_01
866  * @tc.name     test error branch
867  * @tc.desc     Function test
868  */
869 HWTEST_F(BranchTest, DeactivatingSecondaryState_Test_01, Function | MediumTest | Level3)
870 {
871     std::shared_ptr<IncallStateMachineTest> incallStateMachineTest = std::make_shared<IncallStateMachineTest>();
872     std::shared_ptr<IncallDataStateMachine> incallStateMachine =
873         incallStateMachineTest->CreateIncallDataStateMachine(0);
874     incallStateMachine->Init(TelCallStatus::CALL_STATUS_DIALING);
875     incallStateMachine->TransitionTo(incallStateMachine->activatingSecondaryState_);
876     incallStateMachine->TransitionTo(incallStateMachine->activatedSecondaryState_);
877     incallStateMachine->TransitionTo(incallStateMachine->deactivatingSecondaryState_);
878     auto deactivatingSecondaryState =
879         static_cast<DeactivatingSecondaryState *>(incallStateMachine->deactivatingSecondaryState_.GetRefPtr());
880     auto event = AppExecFwk::InnerEvent::Get(0);
881     event = nullptr;
882     deactivatingSecondaryState->StateBegin();
883     ASSERT_FALSE(deactivatingSecondaryState->StateProcess(event));
884     deactivatingSecondaryState->StateEnd();
885 }
886 
887 /**
888  * @tc.number   GetIpType_Test_01
889  * @tc.name     TestDump
890  * @tc.desc     Function test
891  */
892 HWTEST_F(BranchTest, GetIpType_Test_01, Function | MediumTest | Level3)
893 {
894     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
895     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
896     cellularMachine->Init();
897     std::string result = "";
898     std::string address = "";
899     std::vector<AddressInfo> ipInfoArray = CellularDataUtils::ParseIpAddr(address);
900     result = cellularMachine->GetIpType(ipInfoArray);
901     ASSERT_TRUE(result == "");
902 }
903 
904 /**
905  * @tc.number   DataSwitchSettings_Test_01
906  * @tc.name     test error branch
907  * @tc.desc     Function test
908  */
909 HWTEST_F(BranchTest, DataSwitchSettings_Test_01, Function | MediumTest | Level3)
910 {
911     std::unique_ptr<DataSwitchSettings> dataSwitchSettings = std::make_unique<DataSwitchSettings>(0);
912     dataSwitchSettings->LoadSwitchValue();
913     bool status = true;
914     dataSwitchSettings->QueryUserDataStatus(status);
915     dataSwitchSettings->QueryUserDataRoamingStatus(status);
916     dataSwitchSettings->SetPolicyDataOn(true);
917     ASSERT_TRUE(dataSwitchSettings->IsPolicyDataOn());
918     dataSwitchSettings->IsAllowActiveData();
919     dataSwitchSettings->SetUserDataOn(true);
920     dataSwitchSettings->IsUserDataOn();
921     dataSwitchSettings->SetCarrierDataOn(true);
922     ASSERT_TRUE(dataSwitchSettings->IsCarrierDataOn());
923     dataSwitchSettings->SetUserDataRoamingOn(true);
924     dataSwitchSettings->IsUserDataRoamingOn();
925     dataSwitchSettings->SetInternalDataOn(true);
926     ASSERT_TRUE(dataSwitchSettings->IsInternalDataOn());
927 }
928 
929 /**
930  * @tc.number   CellularDataServices_Test_01
931  * @tc.name     test error branch
932  * @tc.desc     Function test
933  */
934 HWTEST_F(BranchTest, CellularDataServices_Test_01, Function | MediumTest | Level3)
935 {
936     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
937     std::shared_ptr<CellularDataStateMachine> cellularMachine = machine->CreateCellularDataConnect(0);
938     cellularMachine->IsInactiveState();
939     uint64_t capability = 1;
940     cellularMachine->SetCapability(capability);
941     cellularMachine->GetCapability();
942     const int32_t cid = 1;
943     cellularMachine->SetCid(cid);
944     cellularMachine->GetSlotId();
945     cellularMachine->GetApnItem();
946     cellularMachine->GetCurrentState();
947     const uint32_t upBandwidth = 0;
948     const uint32_t downBandwidth = 0;
949     cellularMachine->SetConnectionBandwidth(upBandwidth, downBandwidth);
950     const std::string tcpBuffer = "";
951     cellularMachine->SetConnectionTcpBuffer(tcpBuffer);
952     std::string proxyIpAddress = "1234:567";
953     std::string host = "";
954     uint16_t port = 0;
955     cellularMachine->SplitProxyIpAddress(proxyIpAddress, host, port);
956     EXPECT_EQ(host, "1234");
957     EXPECT_EQ(port, 567);
958     EXPECT_TRUE(cellularMachine != nullptr);
959     CellularDataDumpHelper dumpHelper;
960     std::string result = "";
961     dumpHelper.ShowHelp(result);
962     EXPECT_GE(result.size(), 0);
963 }
964 
965 /**
966  * @tc.number   CellularDataServices_Test_02
967  * @tc.name     test error branch
968  * @tc.desc     Function test
969  */
970 HWTEST_F(BranchTest, CellularDataServices_Test_02, Function | MediumTest | Level3)
971 {
972     CellularDataUtils::ParseNormalIpAddr(ADDRESS);
973     CellularDataUtils::ParseRoute(ADDRESS);
974     CellularDataUtils::GetPrefixLen(ADDRESS, FLAG);
975     auto cellularDataHiSysEvent = DelayedSingleton<CellularDataHiSysEvent>::GetInstance();
976     cellularDataHiSysEvent->WriteRoamingConnectStateBehaviorEvent(1);
977     cellularDataHiSysEvent->SetCellularDataActivateStartTime();
978     cellularDataHiSysEvent->JudgingDataActivateTimeOut(0, 1);
979     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
980     dataConnectionMonitor->HandleRecovery();
981     dataConnectionMonitor->GetPdpContextList();
982     dataConnectionMonitor->SetRadioState(0, RadioEvent::RADIO_ON);
983     dataConnectionMonitor->GetPreferredNetworkPara();
984     dataConnectionMonitor->GetDataFlowType();
985     auto cellularDataService = DelayedSingleton<CellularDataService>::GetInstance();
986     MessageParcel data;
987     MessageParcel reply;
988     EXPECT_GE(cellularDataService->OnIsCellularDataEnabled(data, reply), 0);
989     EXPECT_GE(cellularDataService->OnEnableCellularData(data, reply), 0);
990     EXPECT_GE(cellularDataService->OnGetCellularDataState(data, reply), 0);
991     EXPECT_GE(cellularDataService->OnIsCellularDataRoamingEnabled(data, reply), 0);
992     EXPECT_GE(cellularDataService->OnEnableCellularDataRoaming(data, reply), 0);
993     EXPECT_GE(cellularDataService->OnHandleApnChanged(data, reply), 0);
994     cellularDataService->OnGetDefaultCellularDataSlotId(data, reply);
995     EXPECT_GE(cellularDataService->OnGetDefaultCellularDataSimId(data, reply), 0);
996     EXPECT_GE(cellularDataService->OnSetDefaultCellularDataSlotId(data, reply), 0);
997     EXPECT_GE(cellularDataService->OnGetCellularDataFlowType(data, reply), 0);
998     EXPECT_GE(cellularDataService->OnHasInternetCapability(data, reply), 0);
999     EXPECT_GE(cellularDataService->OnClearCellularDataConnections(data, reply), 0);
1000     EXPECT_GE(cellularDataService->OnRegisterSimAccountCallback(data, reply), 0);
1001     EXPECT_GE(cellularDataService->OnUnregisterSimAccountCallback(data, reply), 0);
1002 }
1003 
1004 /**
1005  * @tc.number   CellularDataSettingsRdbHelper_Test_01
1006  * @tc.name     test error branch
1007  * @tc.desc     Function test
1008  */
1009 HWTEST_F(BranchTest, CellularDataSettingsRdbHelper_Test_01, Function | MediumTest | Level3)
1010 {
1011     auto settingHelper = CellularDataSettingsRdbHelper::GetInstance();
1012     if (settingHelper == nullptr) {
1013         TELEPHONY_LOGE("settingHelper is null");
1014         return;
1015     }
1016     Uri dataEnableUri(CELLULAR_DATA_SETTING_DATA_ROAMING_URI);
1017     settingHelper->RegisterSettingsObserver(dataEnableUri, nullptr);
1018     settingHelper->UnRegisterSettingsObserver(dataEnableUri, nullptr);
1019     EXPECT_TRUE(settingHelper != nullptr);
1020 }
1021 } // namespace Telephony
1022 } // namespace OHOS
1023