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 "apn_holder.h"
19 #include "apn_manager.h"
20 #include "cellular_data_state_machine.h"
21 #include "cellular_data_client.h"
22 #include "data_connection_manager.h"
23 #include "gtest/gtest.h"
24 #include "tel_event_handler.h"
25 #include "pdp_profile_data.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 using namespace testing::ext;
30 
31 class ApnManagerTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp();
36     void TearDown();
37     std::shared_ptr<ApnManager> apnManager;
38 };
SetUpTestCase()39 void ApnManagerTest::SetUpTestCase() {}
40 
TearDownTestCase()41 void ApnManagerTest::TearDownTestCase() {}
42 
SetUp()43 void ApnManagerTest::SetUp()
44 {
45     apnManager = std::make_shared<ApnManager>();
46 }
47 
TearDown()48 void ApnManagerTest::TearDown()
49 {
50     apnManager.reset();
51 }
52 
53 class StateMachineTest : public TelEventHandler {
54 public:
StateMachineTest()55     StateMachineTest() : TelEventHandler("StateMachineTest") {}
56     ~StateMachineTest() = default;
57     std::shared_ptr<CellularDataStateMachine> CreateCellularDataStateMachine(int32_t slotId);
58 
59 public:
60     std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_ = nullptr;
61 };
62 
CreateCellularDataStateMachine(int32_t slotId)63 std::shared_ptr<CellularDataStateMachine> StateMachineTest::CreateCellularDataStateMachine(int32_t slotId)
64 {
65     if (cellularDataStateMachine_ != nullptr) {
66         return cellularDataStateMachine_;
67     }
68     sptr<DataConnectionManager> connectionManager = std::make_unique<DataConnectionManager>(slotId).release();
69     if (connectionManager == nullptr) {
70         return nullptr;
71     }
72     connectionManager->Init();
73     cellularDataStateMachine_ = std::make_shared<CellularDataStateMachine>(
74         connectionManager, std::static_pointer_cast<TelEventHandler>(shared_from_this()));
75     return cellularDataStateMachine_;
76 }
77 
78 /**
79  * @tc.number   FindApnNameByApnId_001
80  * @tc.name     test function branch
81  * @tc.desc     Function test
82  */
83 HWTEST_F(ApnManagerTest, FindApnNameByApnId_001, Function | MediumTest | Level1)
84 {
85     int32_t id = 1;
86     std::string result = apnManager->FindApnNameByApnId(id);
87     ASSERT_EQ(result, DATA_CONTEXT_ROLE_DEFAULT);
88 }
89 
90 /**
91  * @tc.number   FindApnNameByApnId_002
92  * @tc.name     test function branch
93  * @tc.desc     Function test
94  */
95 HWTEST_F(ApnManagerTest, FindApnNameByApnId_002, Function | MediumTest | Level1)
96 {
97     int32_t id = 2;
98     std::string result = apnManager->FindApnNameByApnId(id);
99     ASSERT_EQ(result, DATA_CONTEXT_ROLE_MMS);
100 }
101 
102 /**
103  * @tc.number   FindApnIdByCapability_001
104  * @tc.name     test function branch
105  * @tc.desc     Function test
106  */
107 HWTEST_F(ApnManagerTest, FindApnIdByCapability_001, Function | MediumTest | Level1)
108 {
109     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET;
110     int32_t expected = DATA_CONTEXT_ROLE_DEFAULT_ID;
111     int32_t actual = apnManager->FindApnIdByCapability(capability);
112     ASSERT_EQ(actual, expected);
113 }
114 
115 /**
116  * @tc.number   FindApnIdByCapability_002
117  * @tc.name     test function branch
118  * @tc.desc     Function test
119  */
120 HWTEST_F(ApnManagerTest, FindApnIdByCapability_002, Function | MediumTest | Level1)
121 {
122     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_MMS;
123     int32_t expected = DATA_CONTEXT_ROLE_MMS_ID;
124     int32_t actual = apnManager->FindApnIdByCapability(capability);
125     ASSERT_EQ(actual, expected);
126 }
127 
128 /**
129  * @tc.number   FindApnIdByCapability_003
130  * @tc.name     test function branch
131  * @tc.desc     Function test
132  */
133 HWTEST_F(ApnManagerTest, FindApnIdByCapability_003, Function | MediumTest | Level1)
134 {
135     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNAL_DEFAULT;
136     int32_t expected = DATA_CONTEXT_ROLE_INTERNAL_DEFAULT_ID;
137     int32_t actual = apnManager->FindApnIdByCapability(capability);
138     ASSERT_EQ(actual, expected);
139 }
140 
141 /**
142  * @tc.number   FindApnIdByCapability_004
143  * @tc.name     test function branch
144  * @tc.desc     Function test
145  */
146 HWTEST_F(ApnManagerTest, FindApnIdByCapability_004, Function | MediumTest | Level1)
147 {
148     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_IA;
149     int32_t expected = DATA_CONTEXT_ROLE_IA_ID;
150     int32_t actual = apnManager->FindApnIdByCapability(capability);
151     ASSERT_EQ(actual, expected);
152 }
153 
154 /**
155  * @tc.number   FindApnIdByCapability_005
156  * @tc.name     test function branch
157  * @tc.desc     Function test
158  */
159 HWTEST_F(ApnManagerTest, FindApnIdByCapability_005, Function | MediumTest | Level1)
160 {
161     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
162     int32_t expected = DATA_CONTEXT_ROLE_XCAP_ID;
163     int32_t actual = apnManager->FindApnIdByCapability(capability);
164     ASSERT_EQ(actual, expected);
165 }
166 
167 /**
168  * @tc.number   FindApnIdByCapability_006
169  * @tc.name     test function branch
170  * @tc.desc     Function test
171  */
172 HWTEST_F(ApnManagerTest, FindApnIdByCapability_006, Function | MediumTest | Level1)
173 {
174     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
175     int32_t expected = DATA_CONTEXT_ROLE_SUPL_ID;
176     int32_t actual = apnManager->FindApnIdByCapability(capability);
177     ASSERT_EQ(actual, expected);
178 }
179 
180 /**
181  * @tc.number   FindApnIdByCapability_007
182  * @tc.name     test function branch
183  * @tc.desc     Function test
184  */
185 HWTEST_F(ApnManagerTest, FindApnIdByCapability_007, Function | MediumTest | Level1)
186 {
187     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
188     int32_t expected = DATA_CONTEXT_ROLE_DUN_ID;
189     int32_t actual = apnManager->FindApnIdByCapability(capability);
190     ASSERT_EQ(actual, expected);
191 }
192 
193 /**
194  * @tc.number   FindApnIdByCapability_008
195  * @tc.name     test function branch
196  * @tc.desc     Function test
197  */
198 HWTEST_F(ApnManagerTest, FindApnIdByCapability_008, Function | MediumTest | Level1)
199 {
200     uint64_t capability = 100;
201     int32_t expected = DATA_CONTEXT_ROLE_INVALID_ID;
202     int32_t actual = apnManager->FindApnIdByCapability(capability);
203     ASSERT_EQ(actual, expected);
204 }
205 
206 /**
207  * @tc.number   FindBestCapability_001
208  * @tc.name     test function branch
209  * @tc.desc     Function test
210  */
211 HWTEST_F(ApnManagerTest, FindBestCapability_001, Function | MediumTest | Level1)
212 {
213     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
214     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
215     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SUPL);
216 }
217 
218 /**
219  * @tc.number   FindBestCapability_002
220  * @tc.name     test function branch
221  * @tc.desc     Function test
222  */
223 HWTEST_F(ApnManagerTest, FindBestCapability_002, Function | MediumTest | Level1)
224 {
225     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
226     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
227     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_DUN);
228 }
229 
230 /**
231  * @tc.number   FindBestCapability_003
232  * @tc.name     test function branch
233  * @tc.desc     Function test
234  */
235 HWTEST_F(ApnManagerTest, FindBestCapability_003, Function | MediumTest | Level1)
236 {
237     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
238     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
239     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_XCAP);
240 }
241 
242 /**
243  * @tc.number   FindBestCapability_004
244  * @tc.name     test function branch
245  * @tc.desc     Function test
246  */
247 HWTEST_F(ApnManagerTest, FindBestCapability_004, Function | MediumTest | Level1)
248 {
249     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_IA;
250     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
251     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_IA);
252 }
253 
254 /**
255  * @tc.number   CreateMvnoApnItems_001
256  * @tc.name     test function branch
257  * @tc.desc     Function test
258  */
259 HWTEST_F(ApnManagerTest, CreateMvnoApnItems_001, Function | MediumTest | Level1)
260 {
261     int32_t slotId = 0;
262     std::string mcc = "460";
263     std::string mnc = "00";
264     int32_t result = apnManager->CreateMvnoApnItems(slotId, mcc, mnc);
265     ASSERT_EQ(result, 0);
266 }
267 
268 /**
269  * @tc.number   IsPreferredApnUserEdited_001
270  * @tc.name     test function branch
271  * @tc.desc     Function test
272  */
273 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_001, Function | MediumTest | Level1)
274 {
275     auto preferId = 1;
276     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
277     defaultApnItem->attr_.profileId_ = preferId;
278     defaultApnItem->attr_.isEdited_ = true;
279     apnManager->allApnItem_.push_back(defaultApnItem);
280     apnManager->preferId_ = preferId;
281     ASSERT_TRUE(apnManager->IsPreferredApnUserEdited());
282 }
283 
284 /**
285  * @tc.number   IsPreferredApnUserEdited_002
286  * @tc.name     test function branch
287  * @tc.desc     Function test
288  */
289 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_002, Function | MediumTest | Level1)
290 {
291     auto preferId = 1;
292     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
293     defaultApnItem->attr_.profileId_ = preferId;
294     defaultApnItem->attr_.isEdited_ = false;
295     apnManager->allApnItem_.push_back(defaultApnItem);
296     apnManager->preferId_ = preferId;
297     ASSERT_FALSE(apnManager->IsPreferredApnUserEdited());
298 }
299 
300 /**
301  * @tc.number   IsPreferredApnUserEdited_003
302  * @tc.name     test function branch
303  * @tc.desc     Function test
304  */
305 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_003, Function | MediumTest | Level1)
306 {
307     auto preferId = 2;
308     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
309     defaultApnItem->attr_.profileId_ = 3;
310     defaultApnItem->attr_.isEdited_ = true;
311     apnManager->allApnItem_.push_back(defaultApnItem);
312     apnManager->preferId_ = preferId;
313     ASSERT_FALSE(apnManager->IsPreferredApnUserEdited());
314 }
315 
316 /**
317  * @tc.number   IsDataConnectionNotUsed_001
318  * @tc.name     test function branch
319  * @tc.desc     Function test
320  */
321 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_001, Function | MediumTest | Level1)
322 {
323     std::shared_ptr<CellularDataStateMachine> stateMachine = nullptr;
324     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
325     ASSERT_FALSE(result);
326 }
327 
328 /**
329  * @tc.number   IsDataConnectionNotUsed_002
330  * @tc.name     test function branch
331  * @tc.desc     Function test
332  */
333 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_002, Function | MediumTest | Level1)
334 {
335     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
336     auto stateMachine = machine->CreateCellularDataStateMachine(0);
337     apnManager->apnHolders_.push_back(nullptr);
338     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
339     ASSERT_TRUE(result);
340 }
341 
342 /**
343  * @tc.number   IsDataConnectionNotUsed_003
344  * @tc.name     test function branch
345  * @tc.desc     Function test
346  */
347 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_003, Function | MediumTest | Level1)
348 {
349     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
350     auto stateMachine = machine->CreateCellularDataStateMachine(0);
351     sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
352         static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
353     apnHolder->SetCellularDataStateMachine(stateMachine);
354     apnManager->apnHolders_.push_back(apnHolder);
355     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
356     ASSERT_FALSE(result);
357 }
358 
359 /**
360  * @tc.number   IsDataConnectionNotUsed_004
361  * @tc.name     test function branch
362  * @tc.desc     Function test
363  */
364 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_004, Function | MediumTest | Level1)
365 {
366     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
367     auto stateMachine = machine->CreateCellularDataStateMachine(0);
368     sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
369         static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
370     apnHolder->SetCellularDataStateMachine(nullptr);
371     apnManager->apnHolders_.push_back(apnHolder);
372     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
373     ASSERT_TRUE(result);
374 }
375 
376 /**
377  * @tc.number   IsDataConnectionNotUsed_005
378  * @tc.name     test function branch
379  * @tc.desc     Function test
380  */
381 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_005, Function | MediumTest | Level1)
382 {
383     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
384     auto stateMachine = machine->CreateCellularDataStateMachine(0);
385     sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
386         static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
387     apnHolder->SetCellularDataStateMachine(stateMachine);
388     apnManager->apnHolders_.push_back(apnHolder);
389     machine->cellularDataStateMachine_ = nullptr;
390     auto stateMachine_1 = machine->CreateCellularDataStateMachine(0);
391     bool result = apnManager->IsDataConnectionNotUsed(stateMachine_1);
392     ASSERT_TRUE(result);
393 }
394 
395 /**
396  * @tc.number   MakeSpecificApnItem_001
397  * @tc.name     test function branch
398  * @tc.desc     Function test
399  */
400 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_001, Function | MediumTest | Level1)
401 {
402     auto preferId = 1;
403     apnManager->preferId_ = preferId;
404     PdpProfile pdpProfile;
405     pdpProfile.profileId = preferId;
406     pdpProfile.apnTypes = "";
407     std::vector<PdpProfile> apnVec;
408     apnVec.push_back(pdpProfile);
409     bool result = apnManager->MakeSpecificApnItem(apnVec);
410     ASSERT_EQ(result, 1);
411 }
412 
413 /**
414  * @tc.number   MakeSpecificApnItem_002
415  * @tc.name     test function branch
416  * @tc.desc     Function test
417  */
418 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_002, Function | MediumTest | Level1)
419 {
420     auto preferId = 1;
421     apnManager->preferId_ = preferId;
422     PdpProfile pdpProfile;
423     pdpProfile.profileId = preferId;
424     pdpProfile.apnTypes = "default";
425     std::vector<PdpProfile> apnVec;
426     apnVec.push_back(pdpProfile);
427     bool result = apnManager->MakeSpecificApnItem(apnVec);
428     ASSERT_EQ(result, 1);
429 }
430 
431 /**
432  * @tc.number   MakeSpecificApnItem_003
433  * @tc.name     test function branch
434  * @tc.desc     Function test
435  */
436 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_003, Function | MediumTest | Level1)
437 {
438     auto preferId = 1;
439     apnManager->preferId_ = 2;
440     PdpProfile pdpProfile;
441     pdpProfile.profileId = preferId;
442     pdpProfile.apnTypes = "default";
443     std::vector<PdpProfile> apnVec;
444     apnVec.push_back(pdpProfile);
445     bool result = apnManager->MakeSpecificApnItem(apnVec);
446     ASSERT_EQ(result, 1);
447 }
448 
449 /**
450  * @tc.number   HasAnyConnectedState_001
451  * @tc.name     test function branch
452  * @tc.desc     Function test
453  */
454 HWTEST_F(ApnManagerTest, HasAnyConnectedState_001, Function | MediumTest | Level1)
455 {
456     std::vector<sptr<ApnHolder>> apnHolders;
457     apnManager->apnHolders_ = apnHolders;
458     bool result = apnManager->HasAnyConnectedState();
459     ASSERT_EQ(result, false);
460 }
461 
462 /**
463  * @tc.number   HasAnyConnectedState_002
464  * @tc.name     test function branch
465  * @tc.desc     Function test
466  */
467 HWTEST_F(ApnManagerTest, HasAnyConnectedState_002, Function | MediumTest | Level1)
468 {
469     std::vector<sptr<ApnHolder>> apnHolders;
470     sptr<ApnHolder> apnHolder = nullptr;
471     apnHolders.push_back(apnHolder);
472     apnManager->apnHolders_ = apnHolders;
473     bool result = apnManager->HasAnyConnectedState();
474     ASSERT_EQ(result, false);
475 }
476 
477 /**
478  * @tc.number   HasAnyConnectedState_003
479  * @tc.name     test function branch
480  * @tc.desc     Function test
481  */
482 HWTEST_F(ApnManagerTest, HasAnyConnectedState_003, Function | MediumTest | Level1)
483 {
484     std::vector<sptr<ApnHolder>> apnHolders;
485     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
486     apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_CONNECTED);
487     apnHolders.push_back(apnHolder);
488     apnManager->apnHolders_ = apnHolders;
489     bool result = apnManager->HasAnyConnectedState();
490     ASSERT_EQ(result, true);
491 }
492 
493 /**
494  * @tc.number   HasAnyConnectedState_004
495  * @tc.name     test function branch
496  * @tc.desc     Function test
497  */
498 HWTEST_F(ApnManagerTest, HasAnyConnectedState_004, Function | MediumTest | Level1)
499 {
500     std::vector<sptr<ApnHolder>> apnHolders;
501     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
502     apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_DISCONNECTING);
503     apnHolders.push_back(apnHolder);
504     apnManager->apnHolders_ = apnHolders;
505     bool result = apnManager->HasAnyConnectedState();
506     ASSERT_EQ(result, true);
507 }
508 
509 /**
510  * @tc.number   GetRilAttachApn_001
511  * @tc.name     test function branch
512  * @tc.desc     Function test
513  */
514 HWTEST_F(ApnManagerTest, GetRilAttachApn_001, Function | MediumTest | Level1)
515 {
516     std::vector<sptr<ApnItem>> allApnItem;
517     apnManager->allApnItem_ = allApnItem;
518     ASSERT_EQ(apnManager->GetRilAttachApn(), nullptr);
519 }
520 
521 /**
522  * @tc.number   ReleaseDataConnection_001
523  * @tc.name     test function branch
524  * @tc.desc     Function test
525  */
526 HWTEST_F(ApnManagerTest, ReleaseDataConnection_001, TestSize.Level0)
527 {
528     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
529     apnHolder->cellularDataStateMachine_ = nullptr;
530     apnHolder->ReleaseDataConnection();
531     ASSERT_EQ(apnHolder->cellularDataStateMachine_, nullptr);
532 }
533 
534 /**
535  * @tc.number   ReleaseDataConnection_002
536  * @tc.name     test function branch
537  * @tc.desc     Function test
538  */
539 HWTEST_F(ApnManagerTest, ReleaseDataConnection_002, TestSize.Level0)
540 {
541     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
542     auto stateMachine = machine->CreateCellularDataStateMachine(0);
543     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
544     apnHolder->SetCellularDataStateMachine(stateMachine);
545     apnHolder->ReleaseDataConnection();
546     ASSERT_EQ(apnHolder->cellularDataStateMachine_, nullptr);
547 }
548 
549 /**
550  * @tc.number   RequestCellularData_001
551  * @tc.name     test function branch
552  * @tc.desc     Function test
553  */
554 HWTEST_F(ApnManagerTest, RequestCellularData_001, TestSize.Level0)
555 {
556     NetRequest netRequest;
557     netRequest.capability = 0;
558     netRequest.ident = "ident";
559     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
560     apnHolder->RequestCellularData(netRequest);
561     ASSERT_EQ(apnHolder->dataCallEnabled_, true);
562 }
563 
564 /**
565  * @tc.number   RequestCellularData_002
566  * @tc.name     test function branch
567  * @tc.desc     Function test
568  */
569 HWTEST_F(ApnManagerTest, RequestCellularData_002, TestSize.Level0)
570 {
571     NetRequest netRequest;
572     netRequest.capability = 0;
573     netRequest.ident = "ident";
574     NetRequest netRequest1;
575     netRequest1.capability = 0;
576     netRequest1.ident = "abc";
577     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
578     apnHolder->netRequests_.push_back(netRequest1);
579     apnHolder->RequestCellularData(netRequest);
580     ASSERT_EQ(apnHolder->dataCallEnabled_, true);
581 }
582 
583 /**
584  * @tc.number   RequestCellularData_003
585  * @tc.name     test function branch
586  * @tc.desc     Function test
587  */
588 HWTEST_F(ApnManagerTest, RequestCellularData_003, TestSize.Level0)
589 {
590     NetRequest netRequest;
591     netRequest.capability = 0;
592     netRequest.ident = "ident";
593     NetRequest netRequest1;
594     netRequest1.capability = 1;
595     netRequest1.ident = "ident";
596     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
597     apnHolder->netRequests_.push_back(netRequest1);
598     apnHolder->RequestCellularData(netRequest);
599     ASSERT_EQ(apnHolder->dataCallEnabled_, true);
600 }
601 
602 /**
603  * @tc.number   RequestCellularData_004
604  * @tc.name     test function branch
605  * @tc.desc     Function test
606  */
607 HWTEST_F(ApnManagerTest, RequestCellularData_004, TestSize.Level0)
608 {
609     NetRequest netRequest;
610     netRequest.capability = 1;
611     netRequest.ident = "ident";
612     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
613     apnHolder->netRequests_.push_back(netRequest);
614     int size = apnHolder->netRequests_.size();
615     apnHolder->RequestCellularData(netRequest);
616     ASSERT_EQ(size, apnHolder->netRequests_.size());
617 }
618 
619 /**
620  * @tc.number   IsCompatibleApnItem_001
621  * @tc.name     test function branch
622  * @tc.desc     Function test
623  */
624 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_001, TestSize.Level0)
625 {
626     sptr<ApnItem> newApnItem = nullptr;
627     sptr<ApnItem> oldApnItem = nullptr;
628     bool roamingState = false;
629     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
630     bool result = apnHolder->IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
631     ASSERT_FALSE(result);
632 }
633 
634 /**
635  * @tc.number   IsCompatibleApnItem_002
636  * @tc.name     test function branch
637  * @tc.desc     Function test
638  */
639 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_002, TestSize.Level0)
640 {
641     sptr<ApnItem> newApnItem = new ApnItem();
642     sptr<ApnItem> oldApnItem = new ApnItem();
643     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
644     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
645     bool roamingState = true;
646     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
647     bool result = apnHolder->IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
648     ASSERT_TRUE(result);
649 }
650 
651 /**
652  * @tc.number   IsCompatibleApnItem_003
653  * @tc.name     test function branch
654  * @tc.desc     Function test
655  */
656 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_003, TestSize.Level0)
657 {
658     sptr<ApnItem> newApnItem = new ApnItem();
659     sptr<ApnItem> oldApnItem = new ApnItem();
660     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
661     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
662     bool roamingState = false;
663     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
664     bool result = apnHolder->IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
665     ASSERT_TRUE(result);
666 }
667 
668 /**
669  * @tc.number   GetNextRetryApnItem001
670  * @tc.name     test function branch
671  * @tc.desc     Function test
672  */
673 HWTEST_F(ApnManagerTest, GetNextRetryApnItem001, TestSize.Level0)
674 {
675     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
676     connectionRetryPolicy->matchedApns_.clear();
677     EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
678 }
679 
680 /**
681  * @tc.number   GetNextRetryApnItem002
682  * @tc.name     test function branch
683  * @tc.desc     Function test
684  */
685 HWTEST_F(ApnManagerTest, GetNextRetryApnItem002, TestSize.Level0)
686 {
687     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
688     connectionRetryPolicy->currentApnIndex_ = 10;
689     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 10);
690 }
691 
692 /**
693  * @tc.number   GetNextRetryApnItem_003
694  * @tc.name     test function branch
695  * @tc.desc     Function test
696  */
697 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_003, TestSize.Level0)
698 {
699     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
700     connectionRetryPolicy->currentApnIndex_ = -1;
701     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, -1);
702 }
703 
704 /**
705  * @tc.number   GetNextRetryApnItem_004
706  * @tc.name     test function branch
707  * @tc.desc     Function test
708  */
709 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_004, TestSize.Level0)
710 {
711     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
712     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
713     defaultApnItem->MarkBadApn(true);
714     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
715     connectionRetryPolicy->currentApnIndex_ = 0;
716     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
717 }
718 
719 /**
720  * @tc.number   GetNextRetryApnItem_005
721  * @tc.name     test function branch
722  * @tc.desc     Function test
723  */
724 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_005, TestSize.Level0)
725 {
726     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
727     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
728     defaultApnItem->MarkBadApn(false);
729     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
730     connectionRetryPolicy->tryCount_ = 10;
731     connectionRetryPolicy->maxCount_ = 0;
732     connectionRetryPolicy->currentApnIndex_ = 0;
733     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
734 }
735 
736 /**
737  * @tc.number   GetNextRetryApnItem_006
738  * @tc.name     test function branch
739  * @tc.desc     Function test
740  */
741 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_006, TestSize.Level0)
742 {
743     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
744     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
745     defaultApnItem->MarkBadApn(false);
746     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
747     connectionRetryPolicy->tryCount_ = -1;
748     connectionRetryPolicy->maxCount_ = 0;
749     connectionRetryPolicy->currentApnIndex_ = 0;
750     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
751 }
752 
753 /**
754  * @tc.number   GetNextRetryApnItem_007
755  * @tc.name     test function branch
756  * @tc.desc     Function test
757  */
758 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_007, TestSize.Level0)
759 {
760     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
761     connectionRetryPolicy->matchedApns_.push_back(nullptr);
762     connectionRetryPolicy->currentApnIndex_ = 0;
763     EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
764 }
765 
766 /**
767  * @tc.number   EnableCellularDataRoaming_001
768  * @tc.name     test function branch
769  * @tc.desc     Function test
770  */
771 HWTEST_F(ApnManagerTest, EnableCellularDataRoaming_001, TestSize.Level0)
772 {
773     int32_t result = CellularDataClient::GetInstance().EnableCellularDataRoaming(0, true);
774     EXPECT_NE(result, true);
775 }
776 
777 /**
778  * @tc.number   HasInternetCapability_001
779  * @tc.name     test function branch
780  * @tc.desc     Function test
781  */
782 HWTEST_F(ApnManagerTest, HasInternetCapability_001, TestSize.Level0)
783 {
784     int32_t result = CellularDataClient::GetInstance().HasInternetCapability(0, 0);
785     EXPECT_EQ(result, false);
786 }
787 
788 /**
789  * @tc.number   HandleApnChanged_001
790  * @tc.name     test function branch
791  * @tc.desc     Function test
792  */
793 HWTEST_F(ApnManagerTest, HandleApnChanged_001, TestSize.Level0)
794 {
795     int32_t result = CellularDataClient::GetInstance().HandleApnChanged(0);
796     EXPECT_NE(result, true);
797 }
798 
799 /**
800  * @tc.number   UpdateDefaultCellularDataSlotId_001
801  * @tc.name     test function branch
802  * @tc.desc     Function test
803  */
804 HWTEST_F(ApnManagerTest, UpdateDefaultCellularDataSlotId_001, TestSize.Level0)
805 {
806     int32_t result = CellularDataClient::GetInstance().UpdateDefaultCellularDataSlotId();
807     EXPECT_EQ(result, 0);
808 }
809 } // namespace Telephony
810 } // namespace OHOS