• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cellular_data_constant.h"
23 #include "data_connection_manager.h"
24 #include "gtest/gtest.h"
25 #include "tel_event_handler.h"
26 #include "pdp_profile_data.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 using namespace testing::ext;
31 
32 class ApnManagerTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp();
37     void TearDown();
38     std::shared_ptr<ApnManager> apnManager;
39 };
SetUpTestCase()40 void ApnManagerTest::SetUpTestCase() {}
41 
TearDownTestCase()42 void ApnManagerTest::TearDownTestCase() {}
43 
SetUp()44 void ApnManagerTest::SetUp()
45 {
46     apnManager = std::make_shared<ApnManager>();
47 }
48 
TearDown()49 void ApnManagerTest::TearDown()
50 {
51     apnManager.reset();
52 }
53 
54 class StateMachineTest : public TelEventHandler {
55 public:
StateMachineTest()56     StateMachineTest() : TelEventHandler("StateMachineTest") {}
57     ~StateMachineTest() = default;
58     std::shared_ptr<CellularDataStateMachine> CreateCellularDataStateMachine(int32_t slotId);
59 
60 public:
61     std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_ = nullptr;
62 };
63 
CreateCellularDataStateMachine(int32_t slotId)64 std::shared_ptr<CellularDataStateMachine> StateMachineTest::CreateCellularDataStateMachine(int32_t slotId)
65 {
66     if (cellularDataStateMachine_ != nullptr) {
67         return cellularDataStateMachine_;
68     }
69     sptr<DataConnectionManager> connectionManager = std::make_unique<DataConnectionManager>(slotId).release();
70     if (connectionManager == nullptr) {
71         return nullptr;
72     }
73     connectionManager->Init();
74     cellularDataStateMachine_ = std::make_shared<CellularDataStateMachine>(
75         connectionManager, std::static_pointer_cast<TelEventHandler>(shared_from_this()));
76     return cellularDataStateMachine_;
77 }
78 
79 /**
80  * @tc.number   FindApnNameByApnId_001
81  * @tc.name     test function branch
82  * @tc.desc     Function test
83  */
84 HWTEST_F(ApnManagerTest, FindApnNameByApnId_001, Function | MediumTest | Level1)
85 {
86     int32_t id = 1;
87     std::string result = apnManager->FindApnNameByApnId(id);
88     ASSERT_EQ(result, DATA_CONTEXT_ROLE_DEFAULT);
89 }
90 
91 /**
92  * @tc.number   FindApnNameByApnId_002
93  * @tc.name     test function branch
94  * @tc.desc     Function test
95  */
96 HWTEST_F(ApnManagerTest, FindApnNameByApnId_002, Function | MediumTest | Level1)
97 {
98     int32_t id = 2;
99     std::string result = apnManager->FindApnNameByApnId(id);
100     ASSERT_EQ(result, DATA_CONTEXT_ROLE_MMS);
101 }
102 
103 /**
104  * @tc.number   FindApnNameByApnId_003
105  * @tc.name     test function branch
106  * @tc.desc     Function test
107  */
108 HWTEST_F(ApnManagerTest, FindApnNameByApnId_003, Function | MediumTest | Level1)
109 {
110     std::string result = apnManager->FindApnNameByApnId(DATA_CONTEXT_ROLE_BIP_ID);
111     ASSERT_EQ(result, DATA_CONTEXT_ROLE_BIP);
112 }
113 
114 /**
115  * @tc.number   FindApnIdByCapability_001
116  * @tc.name     test function branch
117  * @tc.desc     Function test
118  */
119 HWTEST_F(ApnManagerTest, FindApnIdByCapability_001, Function | MediumTest | Level1)
120 {
121     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET;
122     int32_t expected = DATA_CONTEXT_ROLE_DEFAULT_ID;
123     int32_t actual = apnManager->FindApnIdByCapability(capability);
124     ASSERT_EQ(actual, expected);
125 }
126 
127 /**
128  * @tc.number   FindApnIdByCapability_002
129  * @tc.name     test function branch
130  * @tc.desc     Function test
131  */
132 HWTEST_F(ApnManagerTest, FindApnIdByCapability_002, Function | MediumTest | Level1)
133 {
134     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_MMS;
135     int32_t expected = DATA_CONTEXT_ROLE_MMS_ID;
136     int32_t actual = apnManager->FindApnIdByCapability(capability);
137     ASSERT_EQ(actual, expected);
138 }
139 
140 /**
141  * @tc.number   FindApnIdByCapability_003
142  * @tc.name     test function branch
143  * @tc.desc     Function test
144  */
145 HWTEST_F(ApnManagerTest, FindApnIdByCapability_003, Function | MediumTest | Level1)
146 {
147     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNAL_DEFAULT;
148     int32_t expected = DATA_CONTEXT_ROLE_INTERNAL_DEFAULT_ID;
149     int32_t actual = apnManager->FindApnIdByCapability(capability);
150     ASSERT_EQ(actual, expected);
151 }
152 
153 /**
154  * @tc.number   FindApnIdByCapability_004
155  * @tc.name     test function branch
156  * @tc.desc     Function test
157  */
158 HWTEST_F(ApnManagerTest, FindApnIdByCapability_004, Function | MediumTest | Level1)
159 {
160     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_IA;
161     int32_t expected = DATA_CONTEXT_ROLE_IA_ID;
162     int32_t actual = apnManager->FindApnIdByCapability(capability);
163     ASSERT_EQ(actual, expected);
164 }
165 
166 /**
167  * @tc.number   FindApnIdByCapability_005
168  * @tc.name     test function branch
169  * @tc.desc     Function test
170  */
171 HWTEST_F(ApnManagerTest, FindApnIdByCapability_005, Function | MediumTest | Level1)
172 {
173     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
174     int32_t expected = DATA_CONTEXT_ROLE_XCAP_ID;
175     int32_t actual = apnManager->FindApnIdByCapability(capability);
176     ASSERT_EQ(actual, expected);
177 }
178 
179 /**
180  * @tc.number   FindApnIdByCapability_006
181  * @tc.name     test function branch
182  * @tc.desc     Function test
183  */
184 HWTEST_F(ApnManagerTest, FindApnIdByCapability_006, Function | MediumTest | Level1)
185 {
186     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
187     int32_t expected = DATA_CONTEXT_ROLE_SUPL_ID;
188     int32_t actual = apnManager->FindApnIdByCapability(capability);
189     ASSERT_EQ(actual, expected);
190 }
191 
192 /**
193  * @tc.number   FindApnIdByCapability_007
194  * @tc.name     test function branch
195  * @tc.desc     Function test
196  */
197 HWTEST_F(ApnManagerTest, FindApnIdByCapability_007, Function | MediumTest | Level1)
198 {
199     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
200     int32_t expected = DATA_CONTEXT_ROLE_DUN_ID;
201     int32_t actual = apnManager->FindApnIdByCapability(capability);
202     ASSERT_EQ(actual, expected);
203 }
204 
205 /**
206  * @tc.number   FindApnIdByCapability_008
207  * @tc.name     test function branch
208  * @tc.desc     Function test
209  */
210 HWTEST_F(ApnManagerTest, FindApnIdByCapability_008, Function | MediumTest | Level1)
211 {
212     uint64_t capability = 100;
213     int32_t expected = DATA_CONTEXT_ROLE_INVALID_ID;
214     int32_t actual = apnManager->FindApnIdByCapability(capability);
215     ASSERT_EQ(actual, expected);
216 }
217 
218 /**
219  * @tc.number   FindApnIdByCapability_009
220  * @tc.name     test function branch
221  * @tc.desc     Function test
222  */
223 HWTEST_F(ApnManagerTest, FindApnIdByCapability_009, Function | MediumTest | Level1)
224 {
225     uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_BIP;
226     int32_t expected = DATA_CONTEXT_ROLE_BIP_ID;
227     int32_t actual = apnManager->FindApnIdByCapability(capability);
228     ASSERT_EQ(actual, expected);
229 }
230 
231 /**
232  * @tc.number   FindBestCapability_001
233  * @tc.name     test function branch
234  * @tc.desc     Function test
235  */
236 HWTEST_F(ApnManagerTest, FindBestCapability_001, Function | MediumTest | Level1)
237 {
238     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
239     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
240     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SUPL);
241 }
242 
243 /**
244  * @tc.number   FindBestCapability_002
245  * @tc.name     test function branch
246  * @tc.desc     Function test
247  */
248 HWTEST_F(ApnManagerTest, FindBestCapability_002, Function | MediumTest | Level1)
249 {
250     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
251     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
252     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_DUN);
253 }
254 
255 /**
256  * @tc.number   FindBestCapability_003
257  * @tc.name     test function branch
258  * @tc.desc     Function test
259  */
260 HWTEST_F(ApnManagerTest, FindBestCapability_003, Function | MediumTest | Level1)
261 {
262     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
263     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
264     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_XCAP);
265 }
266 
267 /**
268  * @tc.number   FindBestCapability_004
269  * @tc.name     test function branch
270  * @tc.desc     Function test
271  */
272 HWTEST_F(ApnManagerTest, FindBestCapability_004, Function | MediumTest | Level1)
273 {
274     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_IA;
275     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
276     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_IA);
277 }
278 
279 /**
280  * @tc.number   FindBestCapability_005
281  * @tc.name     test function branch
282  * @tc.desc     Function test
283  */
284 HWTEST_F(ApnManagerTest, FindBestCapability_005, Function | MediumTest | Level1)
285 {
286     uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_BIP;
287     NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
288     ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_BIP);
289 }
290 
291 /**
292  * @tc.number   CreateMvnoApnItems_001
293  * @tc.name     test function branch
294  * @tc.desc     Function test
295  */
296 HWTEST_F(ApnManagerTest, CreateMvnoApnItems_001, Function | MediumTest | Level1)
297 {
298     int32_t slotId = 0;
299     std::string mcc = "460";
300     std::string mnc = "00";
301     int32_t result = apnManager->CreateMvnoApnItems(slotId, mcc, mnc);
302     ASSERT_EQ(result, 0);
303 }
304 
305 /**
306  * @tc.number   IsPreferredApnUserEdited_001
307  * @tc.name     test function branch
308  * @tc.desc     Function test
309  */
310 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_001, Function | MediumTest | Level1)
311 {
312     auto preferId = 1;
313     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
314     defaultApnItem->attr_.profileId_ = preferId;
315     defaultApnItem->attr_.isEdited_ = true;
316     apnManager->allApnItem_.push_back(defaultApnItem);
317     apnManager->preferId_ = preferId;
318     ASSERT_TRUE(apnManager->IsPreferredApnUserEdited());
319 }
320 
321 /**
322  * @tc.number   IsPreferredApnUserEdited_002
323  * @tc.name     test function branch
324  * @tc.desc     Function test
325  */
326 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_002, Function | MediumTest | Level1)
327 {
328     auto preferId = 1;
329     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
330     defaultApnItem->attr_.profileId_ = preferId;
331     defaultApnItem->attr_.isEdited_ = false;
332     apnManager->allApnItem_.push_back(defaultApnItem);
333     apnManager->preferId_ = preferId;
334     ASSERT_FALSE(apnManager->IsPreferredApnUserEdited());
335 }
336 
337 /**
338  * @tc.number   IsPreferredApnUserEdited_003
339  * @tc.name     test function branch
340  * @tc.desc     Function test
341  */
342 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_003, Function | MediumTest | Level1)
343 {
344     auto preferId = 2;
345     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
346     defaultApnItem->attr_.profileId_ = 3;
347     defaultApnItem->attr_.isEdited_ = true;
348     apnManager->allApnItem_.push_back(defaultApnItem);
349     apnManager->preferId_ = preferId;
350     ASSERT_FALSE(apnManager->IsPreferredApnUserEdited());
351 }
352 
353 /**
354  * @tc.number   IsDataConnectionNotUsed_001
355  * @tc.name     test function branch
356  * @tc.desc     Function test
357  */
358 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_001, Function | MediumTest | Level1)
359 {
360     std::shared_ptr<CellularDataStateMachine> stateMachine = nullptr;
361     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
362     ASSERT_FALSE(result);
363 }
364 
365 /**
366  * @tc.number   IsDataConnectionNotUsed_002
367  * @tc.name     test function branch
368  * @tc.desc     Function test
369  */
370 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_002, Function | MediumTest | Level1)
371 {
372     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
373     auto stateMachine = machine->CreateCellularDataStateMachine(0);
374     apnManager->apnHolders_.push_back(nullptr);
375     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
376     ASSERT_TRUE(result);
377 }
378 
379 /**
380  * @tc.number   IsDataConnectionNotUsed_003
381  * @tc.name     test function branch
382  * @tc.desc     Function test
383  */
384 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_003, Function | MediumTest | Level1)
385 {
386     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
387     auto stateMachine = machine->CreateCellularDataStateMachine(0);
388     sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
389         static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
390     apnHolder->SetCellularDataStateMachine(stateMachine);
391     apnManager->apnHolders_.push_back(apnHolder);
392     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
393     ASSERT_FALSE(result);
394 }
395 
396 /**
397  * @tc.number   IsDataConnectionNotUsed_004
398  * @tc.name     test function branch
399  * @tc.desc     Function test
400  */
401 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_004, Function | MediumTest | Level1)
402 {
403     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
404     auto stateMachine = machine->CreateCellularDataStateMachine(0);
405     sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
406         static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
407     apnHolder->SetCellularDataStateMachine(nullptr);
408     apnManager->apnHolders_.push_back(apnHolder);
409     bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
410     ASSERT_TRUE(result);
411 }
412 
413 /**
414  * @tc.number   IsDataConnectionNotUsed_005
415  * @tc.name     test function branch
416  * @tc.desc     Function test
417  */
418 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_005, Function | MediumTest | Level1)
419 {
420     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
421     auto stateMachine = machine->CreateCellularDataStateMachine(0);
422     sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
423         static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
424     apnHolder->SetCellularDataStateMachine(stateMachine);
425     apnManager->apnHolders_.push_back(apnHolder);
426     machine->cellularDataStateMachine_ = nullptr;
427     auto stateMachine_1 = machine->CreateCellularDataStateMachine(0);
428     bool result = apnManager->IsDataConnectionNotUsed(stateMachine_1);
429     ASSERT_TRUE(result);
430 }
431 
432 /**
433  * @tc.number   MakeSpecificApnItem_001
434  * @tc.name     test function branch
435  * @tc.desc     Function test
436  */
437 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_001, Function | MediumTest | Level1)
438 {
439     auto preferId = 1;
440     apnManager->preferId_ = preferId;
441     PdpProfile pdpProfile;
442     pdpProfile.profileId = preferId;
443     pdpProfile.apnTypes = "";
444     std::vector<PdpProfile> apnVec;
445     apnVec.push_back(pdpProfile);
446     bool result = apnManager->MakeSpecificApnItem(apnVec, 0);
447     ASSERT_EQ(result, 1);
448 }
449 
450 /**
451  * @tc.number   MakeSpecificApnItem_002
452  * @tc.name     test function branch
453  * @tc.desc     Function test
454  */
455 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_002, Function | MediumTest | Level1)
456 {
457     auto preferId = 1;
458     apnManager->preferId_ = preferId;
459     PdpProfile pdpProfile;
460     pdpProfile.profileId = preferId;
461     pdpProfile.apnTypes = "default";
462     std::vector<PdpProfile> apnVec;
463     apnVec.push_back(pdpProfile);
464     bool result = apnManager->MakeSpecificApnItem(apnVec, 0);
465     ASSERT_EQ(result, 1);
466 }
467 
468 /**
469  * @tc.number   MakeSpecificApnItem_003
470  * @tc.name     test function branch
471  * @tc.desc     Function test
472  */
473 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_003, Function | MediumTest | Level1)
474 {
475     auto preferId = 1;
476     apnManager->preferId_ = 2;
477     PdpProfile pdpProfile;
478     pdpProfile.profileId = preferId;
479     pdpProfile.apnTypes = "default";
480     std::vector<PdpProfile> apnVec;
481     apnVec.push_back(pdpProfile);
482     bool result = apnManager->MakeSpecificApnItem(apnVec, 0);
483     ASSERT_EQ(result, 1);
484 }
485 
486 /**
487  * @tc.number   HasAnyConnectedState_001
488  * @tc.name     test function branch
489  * @tc.desc     Function test
490  */
491 HWTEST_F(ApnManagerTest, HasAnyConnectedState_001, Function | MediumTest | Level1)
492 {
493     std::vector<sptr<ApnHolder>> apnHolders;
494     apnManager->apnHolders_ = apnHolders;
495     bool result = apnManager->HasAnyConnectedState();
496     ASSERT_EQ(result, false);
497 }
498 
499 /**
500  * @tc.number   HasAnyConnectedState_002
501  * @tc.name     test function branch
502  * @tc.desc     Function test
503  */
504 HWTEST_F(ApnManagerTest, HasAnyConnectedState_002, Function | MediumTest | Level1)
505 {
506     std::vector<sptr<ApnHolder>> apnHolders;
507     sptr<ApnHolder> apnHolder = nullptr;
508     apnHolders.push_back(apnHolder);
509     apnManager->apnHolders_ = apnHolders;
510     bool result = apnManager->HasAnyConnectedState();
511     ASSERT_EQ(result, false);
512 }
513 
514 /**
515  * @tc.number   HasAnyConnectedState_003
516  * @tc.name     test function branch
517  * @tc.desc     Function test
518  */
519 HWTEST_F(ApnManagerTest, HasAnyConnectedState_003, Function | MediumTest | Level1)
520 {
521     std::vector<sptr<ApnHolder>> apnHolders;
522     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
523     apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_CONNECTED);
524     apnHolders.push_back(apnHolder);
525     apnManager->apnHolders_ = apnHolders;
526     bool result = apnManager->HasAnyConnectedState();
527     ASSERT_EQ(result, true);
528 }
529 
530 /**
531  * @tc.number   HasAnyConnectedState_004
532  * @tc.name     test function branch
533  * @tc.desc     Function test
534  */
535 HWTEST_F(ApnManagerTest, HasAnyConnectedState_004, Function | MediumTest | Level1)
536 {
537     std::vector<sptr<ApnHolder>> apnHolders;
538     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
539     apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_DISCONNECTING);
540     apnHolders.push_back(apnHolder);
541     apnManager->apnHolders_ = apnHolders;
542     bool result = apnManager->HasAnyConnectedState();
543     ASSERT_EQ(result, true);
544 }
545 
546 /**
547  * @tc.number   GetRilAttachApn_001
548  * @tc.name     test function branch
549  * @tc.desc     Function test
550  */
551 HWTEST_F(ApnManagerTest, GetRilAttachApn_001, Function | MediumTest | Level1)
552 {
553     std::vector<sptr<ApnItem>> allApnItem;
554     apnManager->allApnItem_ = allApnItem;
555     ASSERT_EQ(apnManager->GetRilAttachApn(), nullptr);
556 }
557 
558 /**
559  * @tc.number   GetRilAttachApn_002
560  * @tc.name     test function branch
561  * @tc.desc     Function test
562  */
563 HWTEST_F(ApnManagerTest, GetRilAttachApn_002, Function | MediumTest | Level1)
564 {
565     std::vector<sptr<ApnItem>> allApnItem;
566     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
567     allApnItem.push_back(defaultApnItem);
568     apnManager->allApnItem_ = allApnItem;
569     ASSERT_NE(apnManager->GetRilAttachApn(), nullptr);
570 }
571 
572 /**
573  * @tc.number   GetRilAttachApn_003
574  * @tc.name     test function branch
575  * @tc.desc     Function test
576  */
577 HWTEST_F(ApnManagerTest, GetRilAttachApn_003, Function | MediumTest | Level1)
578 {
579     std::vector<sptr<ApnItem>> allApnItem;
580     sptr<ApnItem> apnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_IA);
581     allApnItem.push_back(apnItem);
582     apnManager->allApnItem_ = allApnItem;
583     ASSERT_NE(apnManager->GetRilAttachApn(), nullptr);
584 }
585 
586 /**
587  * @tc.number   GetRilAttachApn_004
588  * @tc.name     test function branch
589  * @tc.desc     Function test
590  */
591 HWTEST_F(ApnManagerTest, GetRilAttachApn_004, Function | MediumTest | Level1)
592 {
593     std::vector<sptr<ApnItem>> allApnItem;
594     sptr<ApnItem> apnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_MMS);
595     allApnItem.push_back(apnItem);
596     apnManager->allApnItem_ = allApnItem;
597     ASSERT_NE(apnManager->GetRilAttachApn(), nullptr);
598 }
599 
600 /**
601  * @tc.number   ReleaseDataConnection_001
602  * @tc.name     test function branch
603  * @tc.desc     Function test
604  */
605 HWTEST_F(ApnManagerTest, ReleaseDataConnection_001, TestSize.Level0)
606 {
607     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
608     apnHolder->cellularDataStateMachine_ = nullptr;
609     apnHolder->ReleaseDataConnection();
610     ASSERT_EQ(apnHolder->cellularDataStateMachine_, nullptr);
611 }
612 
613 /**
614  * @tc.number   ReleaseDataConnection_002
615  * @tc.name     test function branch
616  * @tc.desc     Function test
617  */
618 HWTEST_F(ApnManagerTest, ReleaseDataConnection_002, TestSize.Level0)
619 {
620     std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
621     auto stateMachine = machine->CreateCellularDataStateMachine(0);
622     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
623     apnHolder->SetCellularDataStateMachine(stateMachine);
624     apnHolder->ReleaseDataConnection();
625     ASSERT_NE(apnHolder->cellularDataStateMachine_, nullptr);
626 }
627 
628 /**
629  * @tc.number   RequestCellularData_001
630  * @tc.name     test function branch
631  * @tc.desc     Function test
632  */
633 HWTEST_F(ApnManagerTest, RequestCellularData_001, TestSize.Level0)
634 {
635     NetRequest netRequest;
636     netRequest.capability = 0;
637     netRequest.ident = "ident";
638     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
639     apnHolder->RequestCellularData(netRequest);
640     ASSERT_EQ(apnHolder->dataCallEnabled_, true);
641 }
642 
643 /**
644  * @tc.number   RequestCellularData_002
645  * @tc.name     test function branch
646  * @tc.desc     Function test
647  */
648 HWTEST_F(ApnManagerTest, RequestCellularData_002, TestSize.Level0)
649 {
650     NetRequest netRequest;
651     netRequest.capability = 0;
652     netRequest.ident = "ident";
653     NetRequest netRequest1;
654     netRequest1.capability = 0;
655     netRequest1.ident = "abc";
656     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
657     apnHolder->netRequests_.push_back(netRequest1);
658     apnHolder->RequestCellularData(netRequest);
659     ASSERT_EQ(apnHolder->dataCallEnabled_, true);
660 }
661 
662 /**
663  * @tc.number   RequestCellularData_003
664  * @tc.name     test function branch
665  * @tc.desc     Function test
666  */
667 HWTEST_F(ApnManagerTest, RequestCellularData_003, TestSize.Level0)
668 {
669     NetRequest netRequest;
670     netRequest.capability = 0;
671     netRequest.ident = "ident";
672     NetRequest netRequest1;
673     netRequest1.capability = 1;
674     netRequest1.ident = "ident";
675     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
676     apnHolder->netRequests_.push_back(netRequest1);
677     apnHolder->RequestCellularData(netRequest);
678     ASSERT_EQ(apnHolder->dataCallEnabled_, true);
679 }
680 
681 /**
682  * @tc.number   RequestCellularData_004
683  * @tc.name     test function branch
684  * @tc.desc     Function test
685  */
686 HWTEST_F(ApnManagerTest, RequestCellularData_004, TestSize.Level0)
687 {
688     NetRequest netRequest;
689     netRequest.capability = 1;
690     netRequest.ident = "ident";
691     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
692     apnHolder->netRequests_.push_back(netRequest);
693     int size = apnHolder->netRequests_.size();
694     apnHolder->RequestCellularData(netRequest);
695     ASSERT_EQ(size, apnHolder->netRequests_.size());
696 }
697 
698 /**
699  * @tc.number   IsCompatibleApnItem_001
700  * @tc.name     test function branch
701  * @tc.desc     Function test
702  */
703 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_001, TestSize.Level0)
704 {
705     sptr<ApnItem> newApnItem = nullptr;
706     sptr<ApnItem> oldApnItem = nullptr;
707     bool roamingState = false;
708     bool result = ApnHolder::IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
709     ASSERT_FALSE(result);
710 }
711 
712 /**
713  * @tc.number   IsCompatibleApnItem_002
714  * @tc.name     test function branch
715  * @tc.desc     Function test
716  */
717 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_002, TestSize.Level0)
718 {
719     sptr<ApnItem> newApnItem = new ApnItem();
720     sptr<ApnItem> oldApnItem = new ApnItem();
721     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
722     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
723     bool roamingState = true;
724     bool result = ApnHolder::IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
725     ASSERT_TRUE(result);
726 }
727 
728 /**
729  * @tc.number   IsCompatibleApnItem_003
730  * @tc.name     test function branch
731  * @tc.desc     Function test
732  */
733 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_003, TestSize.Level0)
734 {
735     sptr<ApnItem> newApnItem = new ApnItem();
736     sptr<ApnItem> oldApnItem = new ApnItem();
737     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
738     std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
739     bool roamingState = false;
740     bool result = ApnHolder::IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
741     ASSERT_TRUE(result);
742 }
743 
744 /**
745  * @tc.number   GetNextRetryApnItem001
746  * @tc.name     test function branch
747  * @tc.desc     Function test
748  */
749 HWTEST_F(ApnManagerTest, GetNextRetryApnItem001, TestSize.Level0)
750 {
751     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
752     connectionRetryPolicy->matchedApns_.clear();
753     EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
754 
755     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
756     defaultApnItem->MarkBadApn(true);
757     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
758     connectionRetryPolicy->currentApnIndex_ = 0;
759     EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
760     defaultApnItem->MarkBadApn(false);
761     EXPECT_NE(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
762 }
763 
764 /**
765  * @tc.number   GetNextRetryApnItem002
766  * @tc.name     test function branch
767  * @tc.desc     Function test
768  */
769 HWTEST_F(ApnManagerTest, GetNextRetryApnItem002, TestSize.Level0)
770 {
771     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
772     connectionRetryPolicy->currentApnIndex_ = 10;
773     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 10);
774 }
775 
776 /**
777  * @tc.number   GetNextRetryApnItem_003
778  * @tc.name     test function branch
779  * @tc.desc     Function test
780  */
781 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_003, TestSize.Level0)
782 {
783     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
784     connectionRetryPolicy->currentApnIndex_ = -1;
785     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, -1);
786 }
787 
788 /**
789  * @tc.number   GetNextRetryApnItem_004
790  * @tc.name     test function branch
791  * @tc.desc     Function test
792  */
793 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_004, TestSize.Level0)
794 {
795     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
796     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
797     defaultApnItem->MarkBadApn(true);
798     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
799     connectionRetryPolicy->currentApnIndex_ = 0;
800     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
801 }
802 
803 /**
804  * @tc.number   GetNextRetryApnItem_005
805  * @tc.name     test function branch
806  * @tc.desc     Function test
807  */
808 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_005, TestSize.Level0)
809 {
810     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
811     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
812     defaultApnItem->MarkBadApn(false);
813     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
814     connectionRetryPolicy->tryCount_ = 10;
815     connectionRetryPolicy->maxCount_ = 0;
816     connectionRetryPolicy->currentApnIndex_ = 0;
817     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
818 }
819 
820 /**
821  * @tc.number   GetNextRetryApnItem_006
822  * @tc.name     test function branch
823  * @tc.desc     Function test
824  */
825 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_006, TestSize.Level0)
826 {
827     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
828     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
829     defaultApnItem->MarkBadApn(false);
830     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
831     connectionRetryPolicy->tryCount_ = -1;
832     connectionRetryPolicy->maxCount_ = 0;
833     connectionRetryPolicy->currentApnIndex_ = 0;
834     EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
835 }
836 
837 /**
838  * @tc.number   GetNextRetryApnItem_007
839  * @tc.name     test function branch
840  * @tc.desc     Function test
841  */
842 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_007, TestSize.Level0)
843 {
844     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
845     connectionRetryPolicy->matchedApns_.clear();
846     connectionRetryPolicy->currentApnIndex_ = 0;
847     EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
848 }
849 
850 /**
851  * @tc.number   OnPropChanged_001
852  * @tc.name     test function branch
853  * @tc.desc     Function test
854  */
855 HWTEST_F(ApnManagerTest, OnPropChanged_001, TestSize.Level0)
856 {
857     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
858     connectionRetryPolicy->OnPropChanged(nullptr, nullptr, nullptr);
859     EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
860     connectionRetryPolicy->OnPropChanged("persist.telephony.retrystrategy.allow", nullptr, nullptr);
861     EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
862     connectionRetryPolicy->OnPropChanged("persist.telephony.retrystrategy.allow", "true", nullptr);
863     EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
864     connectionRetryPolicy->OnPropChanged("fakeKey", nullptr, nullptr);
865     EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
866     connectionRetryPolicy->OnPropChanged("fakeKey", "true", nullptr);
867     EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
868     connectionRetryPolicy->OnPropChanged("persist.telephony.setupfail.delay", "3000", nullptr);
869     EXPECT_EQ(connectionRetryPolicy->defaultSetupFailDelay_, 3000);
870     connectionRetryPolicy->OnPropChanged("persist.telephony.setupfail.delay", "ABC", nullptr);
871     EXPECT_EQ(connectionRetryPolicy->defaultSetupFailDelay_, 3000);
872     connectionRetryPolicy->OnPropChanged("persist.telephony.modemdend.delay", "1000", nullptr);
873     EXPECT_EQ(connectionRetryPolicy->defaultModemDendDelay_, 1000);
874     connectionRetryPolicy->OnPropChanged("persist.telephony.modemdend.delay", "ABNC", nullptr);
875     EXPECT_EQ(connectionRetryPolicy->defaultModemDendDelay_, 1000);
876 }
877 
878 /**
879  * @tc.number   IsAllBadApn_001
880  * @tc.name     test function branch
881  * @tc.desc     Function test
882  */
883 HWTEST_F(ApnManagerTest, IsAllBadApn_001, TestSize.Level0)
884 {
885     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
886     connectionRetryPolicy->matchedApns_.clear();
887     EXPECT_TRUE(connectionRetryPolicy->IsAllBadApn());
888     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
889     defaultApnItem->MarkBadApn(false);
890     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
891     EXPECT_FALSE(connectionRetryPolicy->IsAllBadApn());
892     defaultApnItem->MarkBadApn(true);
893     EXPECT_TRUE(connectionRetryPolicy->IsAllBadApn());
894 }
895 
896 /**
897  * @tc.number   GetNextRetryDelay_001
898  * @tc.name     test function branch
899  * @tc.desc     Function test
900  */
901 HWTEST_F(ApnManagerTest, GetNextRetryDelay_001, TestSize.Level0)
902 {
903     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
904     connectionRetryPolicy->matchedApns_.clear();
905     auto delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0,
906         RetryScene::RETRY_SCENE_OTHERS, true);
907     EXPECT_GE(delay, 0);
908     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
909     defaultApnItem->MarkBadApn(true);
910     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
911     delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
912         true);
913     EXPECT_GE(delay, 0);
914     delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_INTERNAL_DEFAULT, 0, 0,
915         RetryScene::RETRY_SCENE_OTHERS, true);
916     EXPECT_GE(delay, 60);
917     delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_INTERNAL_DEFAULT, 0, 0,
918         RetryScene::RETRY_SCENE_OTHERS, false);
919     EXPECT_GE(delay, 5);
920 }
921 
922 /**
923  * @tc.number   GetNextRetryDelay_002
924  * @tc.name     test function branch
925  * @tc.desc     Function test
926  */
927 HWTEST_F(ApnManagerTest, GetNextRetryDelay_002, TestSize.Level0)
928 {
929     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
930     connectionRetryPolicy->matchedApns_.clear();
931     sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
932     defaultApnItem->MarkBadApn(false);
933     connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
934     auto delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0,
935         RetryScene::RETRY_SCENE_OTHERS, true);
936     EXPECT_GE(delay, 0);
937     connectionRetryPolicy->isPropOn_ = false;
938     delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
939         true);
940     EXPECT_GE(delay, 0);
941     connectionRetryPolicy->isPropOn_ = true;
942     delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
943         true);
944     EXPECT_GE(delay, 0);
945     delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_MMS, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
946         true);
947     EXPECT_GE(delay, 0);
948 }
949 
950 /**
951  * @tc.number   SetMatchedApns_001
952  * @tc.name     test function branch
953  * @tc.desc     Function test
954  */
955 HWTEST_F(ApnManagerTest, SetMatchedApns_001, TestSize.Level0)
956 {
957     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
958     std::vector<sptr<ApnItem>> matchedApns = {};
959     connectionRetryPolicy->SetMatchedApns(matchedApns);
960     EXPECT_EQ(connectionRetryPolicy->GetMatchedApns().size(), 0);
961 }
962 
963 /**
964  * @tc.number   GetRandomDelay_001
965  * @tc.name     test function branch
966  * @tc.desc     Function test
967  */
968 HWTEST_F(ApnManagerTest, GetRandomDelay_001, TestSize.Level0)
969 {
970     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
971     EXPECT_GE(connectionRetryPolicy->GetRandomDelay(), 0);
972     EXPECT_LE(connectionRetryPolicy->GetRandomDelay(), 2000);
973 }
974 
975 /**
976  * @tc.number   ConvertPdpErrorToDisconnReason_001
977  * @tc.name     test function branch
978  * @tc.desc     Function test
979  */
980 HWTEST_F(ApnManagerTest, ConvertPdpErrorToDisconnReason_001, TestSize.Level0)
981 {
982     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
983     auto res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
984         PdpErrorReason::PDP_ERR_OPERATOR_DETERMINED_BARRING);
985     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
986     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
987         PdpErrorReason::PDP_ERR_MISSING_OR_UNKNOWN_APN);
988     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
989     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
990         PdpErrorReason::PDP_ERR_UNKNOWN_PDP_ADDR_OR_TYPE);
991     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
992     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
993         PdpErrorReason::PDP_ERR_USER_VERIFICATION);
994     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
995     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
996         PdpErrorReason::PDP_ERR_ACTIVATION_REJECTED_GGSN);
997     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
998     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
999         PdpErrorReason::PDP_ERR_SERVICE_OPTION_NOT_SUPPORTED);
1000     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1001     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1002         PdpErrorReason::PDP_ERR_REQUESTED_SERVICE_OPTION_NOT_SUBSCRIBED);
1003     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1004 }
1005 
1006 /**
1007  * @tc.number   ConvertPdpErrorToDisconnReason_002
1008  * @tc.name     test function branch
1009  * @tc.desc     Function test
1010  */
1011 HWTEST_F(ApnManagerTest, ConvertPdpErrorToDisconnReason_002, TestSize.Level0)
1012 {
1013     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1014     auto res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1015         PdpErrorReason::PDP_ERR_NSAPI_ALREADY_USED);
1016     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1017     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1018         PdpErrorReason::PDP_ERR_IPV4_ONLY_ALLOWED);
1019     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1020     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1021         PdpErrorReason::PDP_ERR_IPV6_ONLY_ALLOWED);
1022     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1023     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1024         PdpErrorReason::PDP_ERR_PROTOCOL_ERRORS);
1025     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1026     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1027         PdpErrorReason::PDP_ERR_RETRY);
1028     EXPECT_EQ(res, DisConnectionReason::REASON_RETRY_CONNECTION);
1029     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1030         PdpErrorReason::PDP_ERR_TO_NORMAL);
1031     EXPECT_EQ(res, DisConnectionReason::REASON_NORMAL);
1032     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1033         PdpErrorReason::PDP_ERR_TO_GSM_AND_CALLING_ONLY);
1034     EXPECT_EQ(res, DisConnectionReason::REASON_GSM_AND_CALLING_ONLY);
1035     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1036         PdpErrorReason::PDP_ERR_TO_CLEAR_CONNECTION);
1037     EXPECT_EQ(res, DisConnectionReason::REASON_CLEAR_CONNECTION);
1038     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1039         PdpErrorReason::PDP_ERR_TO_CHANGE_CONNECTION);
1040     EXPECT_EQ(res, DisConnectionReason::REASON_CHANGE_CONNECTION);
1041     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1042         PdpErrorReason::PDP_ERR_TO_PERMANENT_REJECT);
1043     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1044 }
1045 
1046 /**
1047 @tc.number ConvertPdpErrorToDisconnReason_003
1048 @tc.name test function branch
1049 @tc.desc Function test
1050 */
1051 HWTEST_F(ApnManagerTest, ConvertPdpErrorToDisconnReason_003, TestSize.Level0)
1052 {
1053     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1054     connectionRetryPolicy->isPropOn_ = false;
1055     auto res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1056         PdpErrorReason::PDP_ERR_TO_PERMANENT_REJECT);
1057     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1058     connectionRetryPolicy->isPropOn_ = true;
1059     res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1060         PdpErrorReason::PDP_ERR_TO_PERMANENT_REJECT);
1061     EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1062 }
1063 
1064 /**
1065 
1066 @tc.number RestartRadioIfRequired_001
1067 @tc.name test function branch
1068 @tc.desc Function test
1069 */
1070 HWTEST_F(ApnManagerTest, RestartRadioIfRequired_003, TestSize.Level0)
1071 {
1072     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1073     connectionRetryPolicy->isPropOn_ = true;
1074     int32_t failCause = 65536;
1075     connectionRetryPolicy->RestartRadioIfRequired(failCause, 0);
1076     connectionRetryPolicy->isPropOn_ = false;
1077     connectionRetryPolicy->RestartRadioIfRequired(failCause, 0);
1078     EXPECT_FALSE(connectionRetryPolicy->isPropOn_);
1079 }
1080 
1081 /**
1082  * @tc.number   InitialRetryCountValue_001
1083  * @tc.name     test function branch
1084  * @tc.desc     Function test
1085  */
1086 HWTEST_F(ApnManagerTest, InitialRetryCountValue_001, TestSize.Level0)
1087 {
1088     std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1089     connectionRetryPolicy->InitialRetryCountValue();
1090     EXPECT_EQ(connectionRetryPolicy->tryCount_, 0);
1091 }
1092 
1093 /**
1094  * @tc.number   EnableCellularDataRoaming_001
1095  * @tc.name     test function branch
1096  * @tc.desc     Function test
1097  */
1098 HWTEST_F(ApnManagerTest, EnableCellularDataRoaming_001, TestSize.Level0)
1099 {
1100     int32_t result = CellularDataClient::GetInstance().EnableCellularDataRoaming(0, true);
1101     EXPECT_NE(result, true);
1102 }
1103 
1104 /**
1105  * @tc.number   HasInternetCapability_001
1106  * @tc.name     test function branch
1107  * @tc.desc     Function test
1108  */
1109 HWTEST_F(ApnManagerTest, HasInternetCapability_001, TestSize.Level0)
1110 {
1111     int32_t result = CellularDataClient::GetInstance().HasInternetCapability(0, 0);
1112     EXPECT_EQ(result, false);
1113 }
1114 
1115 /**
1116  * @tc.number   HandleApnChanged_001
1117  * @tc.name     test function branch
1118  * @tc.desc     Function test
1119  */
1120 HWTEST_F(ApnManagerTest, HandleApnChanged_001, TestSize.Level0)
1121 {
1122     int32_t result = CellularDataClient::GetInstance().HandleApnChanged(0);
1123     EXPECT_NE(result, true);
1124 }
1125 
1126 /**
1127  * @tc.number   UpdateDefaultCellularDataSlotId_001
1128  * @tc.name     test function branch
1129  * @tc.desc     Function test
1130  */
1131 HWTEST_F(ApnManagerTest, UpdateDefaultCellularDataSlotId_001, TestSize.Level0)
1132 {
1133     int32_t result = CellularDataClient::GetInstance().UpdateDefaultCellularDataSlotId();
1134     EXPECT_EQ(result, 0);
1135 }
1136 
1137 /**
1138  * @tc.name  : ApnItem_CanDealWithType_001
1139  * @tc.number: ApnItemTest_001
1140  * @tc.desc  : Test when the type matches with the apnTypes_ then CanDealWithType returns true
1141  */
1142 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_001, TestSize.Level0)
1143 {
1144     ApnItem apnItem;
1145     apnItem.apnTypes_.push_back("default");
1146     EXPECT_TRUE(apnItem.CanDealWithType("default"));
1147 }
1148 
1149 /**
1150  * @tc.name  : ApnItem_CanDealWithType_002
1151  * @tc.number: ApnItemTest_002
1152  * @tc.desc  : Test when the type is DATA_CONTEXT_ROLE_INTERNAL_DEFAULT
1153  * and apnTypes_ contains DATA_CONTEXT_ROLE_DEFAULT then CanDealWithType returns true
1154  */
1155 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_002, TestSize.Level0)
1156 {
1157     ApnItem apnItem;
1158     apnItem.apnTypes_.push_back(DATA_CONTEXT_ROLE_DEFAULT);
1159     EXPECT_TRUE(apnItem.CanDealWithType(DATA_CONTEXT_ROLE_INTERNAL_DEFAULT));
1160 }
1161 
1162 /**
1163  * @tc.name  : ApnItem_CanDealWithType_003
1164  * @tc.number: ApnItemTest_003
1165  * @tc.desc  : Test when the type is not DATA_CONTEXT_ROLE_IA and
1166  * apnTypes_ contains DATA_CONTEXT_ROLE_ALL then CanDealWithType returns true
1167  */
1168 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_003, TestSize.Level0)
1169 {
1170     ApnItem apnItem;
1171     apnItem.apnTypes_.push_back(DATA_CONTEXT_ROLE_ALL);
1172     EXPECT_TRUE(apnItem.CanDealWithType("not_ia"));
1173 }
1174 
1175 /**
1176  * @tc.name  : ApnItem_CanDealWithType_004
1177  * @tc.number: ApnItemTest_004
1178  * @tc.desc  : Test when the type does not match with the apnTypes_ then CanDealWithType returns false
1179  */
1180 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_004, TestSize.Level0)
1181 {
1182     ApnItem apnItem;
1183     apnItem.apnTypes_.push_back("default");
1184     EXPECT_FALSE(apnItem.CanDealWithType("other"));
1185 }
1186 
1187 /**
1188  * @tc.name  : ApnManager_FindApnHolderById_001
1189  * @tc.number: ApnItemTest_004
1190  * @tc.desc  : Test when the type does not match with the apnTypes_ then CanDealWithType returns false
1191  */
1192 HWTEST_F(ApnManagerTest, ApnManager_FindApnHolderById_001, TestSize.Level0)
1193 {
1194     apnManager->apnIdApnHolderMap_.clear();
1195     EXPECT_EQ(apnManager->FindApnHolderById(0), nullptr);
1196     apnManager->AddApnHolder("default", 10);
1197     EXPECT_EQ(apnManager->FindApnTypeByApnName("abc"), static_cast<uint64_t>(ApnTypes::NONETYPE));
1198 }
1199 
1200 HWTEST_F(ApnManagerTest, ApnHolderAddUid001, TestSize.Level0)
1201 {
1202     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
1203     EXPECT_TRUE(apnHolder != nullptr);
1204     apnHolder->AddUid(1);
1205     apnHolder->AddUid(1);
1206 }
1207 
1208 HWTEST_F(ApnManagerTest, ApnHolderRemoveUid001, TestSize.Level0)
1209 {
1210     sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
1211     EXPECT_TRUE(apnHolder != nullptr);
1212     apnHolder->RemoveUid(1);
1213     apnHolder->RemoveUid(1);
1214 }
1215 
1216 /**
1217  * @tc.name  : ApnItem_IsSimilarPdpProfile_001
1218  * @tc.number: ApnItemTest_005
1219  */
1220 HWTEST_F(ApnManagerTest, ApnItem_IsSimilarPdpProfile_001, TestSize.Level0)
1221 {
1222     PdpProfile p1;
1223     PdpProfile p2;
1224     EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1225     p1.apn = "1";
1226     p2.apn = "2";
1227     EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1228     p1.apn = "";
1229     p2.apn = "";
1230     p1.authType = 1;
1231     p2.authType = 2;
1232     EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1233     p1.authType = 1;
1234     p2.authType = 1;
1235     p1.authUser = "1";
1236     p2.authUser = "2";
1237     EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1238     p1.authUser = "1";
1239     p2.authUser = "1";
1240     p1.authPwd = "1";
1241     p2.authPwd = "2";
1242     EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1243 }
1244 
1245 /**
1246  * @tc.name  : ApnItem_IsSimilarProtocol_001
1247  * @tc.number: ApnItemTest_006
1248  */
1249 HWTEST_F(ApnManagerTest, ApnItem_IsSimilarProtocol_001, TestSize.Level0)
1250 {
1251     std::string newProtocol;
1252     std::string oldProtocol;
1253     EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1254     newProtocol = "IPV4V6";
1255     oldProtocol = "IP";
1256     EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1257     newProtocol = "IPV4V6";
1258     oldProtocol = "IPV6";
1259     EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1260     newProtocol = "IP";
1261     oldProtocol = "IPV4V6";
1262     EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1263     newProtocol = "IPV6";
1264     oldProtocol = "IPV4V6";
1265     EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1266     newProtocol = "IPV6";
1267     oldProtocol = "IPV4";
1268     EXPECT_FALSE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1269 }
1270 
1271 /**
1272  * @tc.name  : ApnManager_TryMergeSimilarPdpProfile_001
1273  * @tc.number: ApnManagerTest_005
1274  */
1275 HWTEST_F(ApnManagerTest, ApnManager_TryMergeSimilarPdpProfile_001, TestSize.Level0)
1276 {
1277     auto preferId = 1;
1278     apnManager->preferId_ = preferId;
1279     PdpProfile pdpProfile;
1280     pdpProfile.profileId = preferId;
1281     pdpProfile.apnTypes = "";
1282     std::vector<PdpProfile> apnVec;
1283     apnVec.push_back(pdpProfile);
1284     apnManager->TryMergeSimilarPdpProfile(apnVec);
1285     EXPECT_EQ(apnVec.size(), 1);
1286     PdpProfile pdpProfile2 = pdpProfile;
1287     apnVec.push_back(pdpProfile2);
1288     apnManager->TryMergeSimilarPdpProfile(apnVec);
1289     EXPECT_EQ(apnVec.size(), 1);
1290 }
1291 
1292 /**
1293  * @tc.name  : ApnManager_TryMergeSimilarPdpProfile_002
1294  * @tc.number: ApnManagerTest_005
1295  */
1296 HWTEST_F(ApnManagerTest, ApnManager_TryMergeSimilarPdpProfile_002, TestSize.Level0)
1297 {
1298     uint64_t expected = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET;
1299     int32_t apnId = DATA_CONTEXT_ROLE_DEFAULT_ID;
1300     uint64_t actual = apnManager->FindCapabilityByApnId(apnId);
1301     EXPECT_EQ(actual, expected);
1302     expected = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNAL_DEFAULT;
1303     apnId = DATA_CONTEXT_ROLE_MMS_ID;
1304     actual = apnManager->FindCapabilityByApnId(apnId);
1305     EXPECT_NE(actual, expected);
1306     expected = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNAL_DEFAULT;
1307     apnId = DATA_CONTEXT_ROLE_INTERNAL_DEFAULT_ID;
1308     actual = apnManager->FindCapabilityByApnId(apnId);
1309     EXPECT_EQ(actual, expected);
1310     expected = NetManagerStandard::NetCap::NET_CAPABILITY_IA;
1311     apnId = DATA_CONTEXT_ROLE_IA_ID;
1312     actual = apnManager->FindCapabilityByApnId(apnId);
1313     EXPECT_EQ(actual, expected);
1314     expected = NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
1315     apnId = DATA_CONTEXT_ROLE_XCAP_ID;
1316     actual = apnManager->FindCapabilityByApnId(apnId);
1317     EXPECT_EQ(actual, expected);
1318     expected = NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
1319     apnId = DATA_CONTEXT_ROLE_SUPL_ID;
1320     actual = apnManager->FindCapabilityByApnId(apnId);
1321     EXPECT_EQ(actual, expected);
1322     expected = NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
1323     apnId = DATA_CONTEXT_ROLE_DUN_ID;
1324     actual = apnManager->FindCapabilityByApnId(apnId);
1325     EXPECT_EQ(actual, expected);
1326     expected = NetManagerStandard::NetCap::NET_CAPABILITY_BIP;
1327     apnId = DATA_CONTEXT_ROLE_BIP_ID;
1328     actual = apnManager->FindCapabilityByApnId(apnId);
1329     EXPECT_EQ(actual, expected);
1330     expected = NetManagerStandard::NetCap::NET_CAPABILITY_END;
1331     apnId = -1;
1332     actual = apnManager->FindCapabilityByApnId(apnId);
1333     EXPECT_EQ(actual, expected);
1334 }
1335 
1336 } // namespace Telephony
1337 } // namespace OHOS