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 #include "telephony_ext_wrapper.h"
28
29 namespace OHOS {
30 namespace Telephony {
31 using namespace testing::ext;
32
33 class ApnManagerTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp();
38 void TearDown();
39 std::shared_ptr<ApnManager> apnManager;
40 };
SetUpTestCase()41 void ApnManagerTest::SetUpTestCase() {}
42
TearDownTestCase()43 void ApnManagerTest::TearDownTestCase() {}
44
SetUp()45 void ApnManagerTest::SetUp()
46 {
47 apnManager = std::make_shared<ApnManager>();
48 }
49
TearDown()50 void ApnManagerTest::TearDown()
51 {
52 apnManager.reset();
53 }
54
55 class StateMachineTest : public TelEventHandler {
56 public:
StateMachineTest()57 StateMachineTest() : TelEventHandler("StateMachineTest") {}
58 ~StateMachineTest() = default;
59 std::shared_ptr<CellularDataStateMachine> CreateCellularDataStateMachine(int32_t slotId);
60
61 public:
62 std::shared_ptr<CellularDataStateMachine> cellularDataStateMachine_ = nullptr;
63 };
64
CreateCellularDataStateMachine(int32_t slotId)65 std::shared_ptr<CellularDataStateMachine> StateMachineTest::CreateCellularDataStateMachine(int32_t slotId)
66 {
67 if (cellularDataStateMachine_ != nullptr) {
68 return cellularDataStateMachine_;
69 }
70 sptr<DataConnectionManager> connectionManager = std::make_unique<DataConnectionManager>(slotId).release();
71 if (connectionManager == nullptr) {
72 return nullptr;
73 }
74 connectionManager->Init();
75 cellularDataStateMachine_ = std::make_shared<CellularDataStateMachine>(
76 connectionManager, std::static_pointer_cast<TelEventHandler>(shared_from_this()));
77 return cellularDataStateMachine_;
78 }
79
80 /**
81 * @tc.number FindApnNameByApnId_001
82 * @tc.name test function branch
83 * @tc.desc Function test
84 */
85 HWTEST_F(ApnManagerTest, FindApnNameByApnId_001, Function | MediumTest | Level1)
86 {
87 int32_t id = 1;
88 std::string result = apnManager->FindApnNameByApnId(id);
89 ASSERT_EQ(result, DATA_CONTEXT_ROLE_DEFAULT);
90 }
91
92 /**
93 * @tc.number FindApnNameByApnId_002
94 * @tc.name test function branch
95 * @tc.desc Function test
96 */
97 HWTEST_F(ApnManagerTest, FindApnNameByApnId_002, Function | MediumTest | Level1)
98 {
99 int32_t id = 2;
100 std::string result = apnManager->FindApnNameByApnId(id);
101 ASSERT_EQ(result, DATA_CONTEXT_ROLE_MMS);
102 }
103
104 /**
105 * @tc.number FindApnNameByApnId_003
106 * @tc.name test function branch
107 * @tc.desc Function test
108 */
109 HWTEST_F(ApnManagerTest, FindApnNameByApnId_003, Function | MediumTest | Level1)
110 {
111 std::string result = apnManager->FindApnNameByApnId(DATA_CONTEXT_ROLE_BIP_ID);
112 ASSERT_EQ(result, DATA_CONTEXT_ROLE_BIP);
113 }
114
115 /**
116 * @tc.number FindApnIdByCapability_001
117 * @tc.name test function branch
118 * @tc.desc Function test
119 */
120 HWTEST_F(ApnManagerTest, FindApnIdByCapability_001, Function | MediumTest | Level1)
121 {
122 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET;
123 int32_t expected = DATA_CONTEXT_ROLE_DEFAULT_ID;
124 int32_t actual = apnManager->FindApnIdByCapability(capability);
125 ASSERT_EQ(actual, expected);
126 }
127
128 /**
129 * @tc.number FindApnIdByCapability_002
130 * @tc.name test function branch
131 * @tc.desc Function test
132 */
133 HWTEST_F(ApnManagerTest, FindApnIdByCapability_002, Function | MediumTest | Level1)
134 {
135 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_MMS;
136 int32_t expected = DATA_CONTEXT_ROLE_MMS_ID;
137 int32_t actual = apnManager->FindApnIdByCapability(capability);
138 ASSERT_EQ(actual, expected);
139 }
140
141 /**
142 * @tc.number FindApnIdByCapability_003
143 * @tc.name test function branch
144 * @tc.desc Function test
145 */
146 HWTEST_F(ApnManagerTest, FindApnIdByCapability_003, Function | MediumTest | Level1)
147 {
148 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNAL_DEFAULT;
149 int32_t expected = DATA_CONTEXT_ROLE_INTERNAL_DEFAULT_ID;
150 int32_t actual = apnManager->FindApnIdByCapability(capability);
151 ASSERT_EQ(actual, expected);
152 }
153
154 /**
155 * @tc.number FindApnIdByCapability_004
156 * @tc.name test function branch
157 * @tc.desc Function test
158 */
159 HWTEST_F(ApnManagerTest, FindApnIdByCapability_004, Function | MediumTest | Level1)
160 {
161 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_IA;
162 int32_t expected = DATA_CONTEXT_ROLE_IA_ID;
163 int32_t actual = apnManager->FindApnIdByCapability(capability);
164 ASSERT_EQ(actual, expected);
165 }
166
167 /**
168 * @tc.number FindApnIdByCapability_005
169 * @tc.name test function branch
170 * @tc.desc Function test
171 */
172 HWTEST_F(ApnManagerTest, FindApnIdByCapability_005, Function | MediumTest | Level1)
173 {
174 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
175 int32_t expected = DATA_CONTEXT_ROLE_XCAP_ID;
176 int32_t actual = apnManager->FindApnIdByCapability(capability);
177 ASSERT_EQ(actual, expected);
178 }
179
180 /**
181 * @tc.number FindApnIdByCapability_006
182 * @tc.name test function branch
183 * @tc.desc Function test
184 */
185 HWTEST_F(ApnManagerTest, FindApnIdByCapability_006, Function | MediumTest | Level1)
186 {
187 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
188 int32_t expected = DATA_CONTEXT_ROLE_SUPL_ID;
189 int32_t actual = apnManager->FindApnIdByCapability(capability);
190 ASSERT_EQ(actual, expected);
191 }
192
193 /**
194 * @tc.number FindApnIdByCapability_007
195 * @tc.name test function branch
196 * @tc.desc Function test
197 */
198 HWTEST_F(ApnManagerTest, FindApnIdByCapability_007, Function | MediumTest | Level1)
199 {
200 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
201 int32_t expected = DATA_CONTEXT_ROLE_DUN_ID;
202 int32_t actual = apnManager->FindApnIdByCapability(capability);
203 ASSERT_EQ(actual, expected);
204 }
205
206 /**
207 * @tc.number FindApnIdByCapability_008
208 * @tc.name test function branch
209 * @tc.desc Function test
210 */
211 HWTEST_F(ApnManagerTest, FindApnIdByCapability_008, Function | MediumTest | Level1)
212 {
213 uint64_t capability = 100;
214 int32_t expected = DATA_CONTEXT_ROLE_INVALID_ID;
215 int32_t actual = apnManager->FindApnIdByCapability(capability);
216 ASSERT_EQ(actual, expected);
217 }
218
219 /**
220 * @tc.number FindApnIdByCapability_009
221 * @tc.name test function branch
222 * @tc.desc Function test
223 */
224 HWTEST_F(ApnManagerTest, FindApnIdByCapability_009, Function | MediumTest | Level1)
225 {
226 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_BIP;
227 int32_t expected = DATA_CONTEXT_ROLE_BIP_ID;
228 int32_t actual = apnManager->FindApnIdByCapability(capability);
229 ASSERT_EQ(actual, expected);
230 }
231
232 /**
233 * @tc.number FindApnIdByCapability_009
234 * @tc.name test function branch
235 * @tc.desc Function test
236 */
237 HWTEST_F(ApnManagerTest, FindApnIdByCapability_010, Function | MediumTest | Level1)
238 {
239 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI1;
240 int32_t expected = DATA_CONTEXT_ROLE_SNSSAI1_ID;
241 int32_t actual = apnManager->FindApnIdByCapability(capability);
242 ASSERT_EQ(actual, expected);
243 }
244
245 /**
246 * @tc.number FindApnIdByCapability_009
247 * @tc.name test function branch
248 * @tc.desc Function test
249 */
250 HWTEST_F(ApnManagerTest, FindApnIdByCapability_011, Function | MediumTest | Level1)
251 {
252 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI2;
253 int32_t expected = DATA_CONTEXT_ROLE_SNSSAI2_ID;
254 int32_t actual = apnManager->FindApnIdByCapability(capability);
255 ASSERT_EQ(actual, expected);
256 }
257
258 /**
259 * @tc.number FindApnIdByCapability_009
260 * @tc.name test function branch
261 * @tc.desc Function test
262 */
263 HWTEST_F(ApnManagerTest, FindApnIdByCapability_012, Function | MediumTest | Level1)
264 {
265 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI3;
266 int32_t expected = DATA_CONTEXT_ROLE_SNSSAI3_ID;
267 int32_t actual = apnManager->FindApnIdByCapability(capability);
268 ASSERT_EQ(actual, expected);
269 }
270
271 /**
272 * @tc.number FindApnIdByCapability_009
273 * @tc.name test function branch
274 * @tc.desc Function test
275 */
276 HWTEST_F(ApnManagerTest, FindApnIdByCapability_013, Function | MediumTest | Level1)
277 {
278 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI4;
279 int32_t expected = DATA_CONTEXT_ROLE_SNSSAI4_ID;
280 int32_t actual = apnManager->FindApnIdByCapability(capability);
281 ASSERT_EQ(actual, expected);
282 }
283
284 /**
285 * @tc.number FindApnIdByCapability_009
286 * @tc.name test function branch
287 * @tc.desc Function test
288 */
289 HWTEST_F(ApnManagerTest, FindApnIdByCapability_014, Function | MediumTest | Level1)
290 {
291 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI5;
292 int32_t expected = DATA_CONTEXT_ROLE_SNSSAI5_ID;
293 int32_t actual = apnManager->FindApnIdByCapability(capability);
294 ASSERT_EQ(actual, expected);
295 }
296
297 /**
298 * @tc.number FindApnIdByCapability_009
299 * @tc.name test function branch
300 * @tc.desc Function test
301 */
302 HWTEST_F(ApnManagerTest, FindApnIdByCapability_015, Function | MediumTest | Level1)
303 {
304 uint64_t capability = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI6;
305 int32_t expected = DATA_CONTEXT_ROLE_SNSSAI6_ID;
306 int32_t actual = apnManager->FindApnIdByCapability(capability);
307 ASSERT_EQ(actual, expected);
308 }
309
310 /**
311 * @tc.number FindBestCapability_001
312 * @tc.name test function branch
313 * @tc.desc Function test
314 */
315 HWTEST_F(ApnManagerTest, FindBestCapability_001, Function | MediumTest | Level1)
316 {
317 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
318 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
319 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SUPL);
320 }
321
322 /**
323 * @tc.number FindBestCapability_002
324 * @tc.name test function branch
325 * @tc.desc Function test
326 */
327 HWTEST_F(ApnManagerTest, FindBestCapability_002, Function | MediumTest | Level1)
328 {
329 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
330 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
331 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_DUN);
332 }
333
334 /**
335 * @tc.number FindBestCapability_003
336 * @tc.name test function branch
337 * @tc.desc Function test
338 */
339 HWTEST_F(ApnManagerTest, FindBestCapability_003, Function | MediumTest | Level1)
340 {
341 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
342 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
343 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_XCAP);
344 }
345
346 /**
347 * @tc.number FindBestCapability_004
348 * @tc.name test function branch
349 * @tc.desc Function test
350 */
351 HWTEST_F(ApnManagerTest, FindBestCapability_004, Function | MediumTest | Level1)
352 {
353 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_IA;
354 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
355 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_IA);
356 }
357
358 /**
359 * @tc.number FindBestCapability_005
360 * @tc.name test function branch
361 * @tc.desc Function test
362 */
363 HWTEST_F(ApnManagerTest, FindBestCapability_005, Function | MediumTest | Level1)
364 {
365 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_BIP;
366 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
367 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_BIP);
368 }
369
370 /**
371 * @tc.number CreateMvnoApnItems_001
372 * @tc.name test function branch
373 * @tc.desc Function test
374 */
375 HWTEST_F(ApnManagerTest, CreateMvnoApnItems_001, Function | MediumTest | Level1)
376 {
377 int32_t slotId = 0;
378 std::string mcc = "460";
379 std::string mnc = "00";
380 int32_t result = apnManager->CreateMvnoApnItems(slotId, mcc, mnc);
381 ASSERT_EQ(result, 0);
382 }
383
384 /**
385 * @tc.number IsPreferredApnUserEdited_001
386 * @tc.name test function branch
387 * @tc.desc Function test
388 */
389 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_001, Function | MediumTest | Level1)
390 {
391 auto preferId = 1;
392 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
393 defaultApnItem->attr_.profileId_ = preferId;
394 defaultApnItem->attr_.isEdited_ = true;
395 apnManager->allApnItem_.push_back(defaultApnItem);
396 apnManager->preferId_ = preferId;
397 ASSERT_TRUE(apnManager->IsPreferredApnUserEdited());
398 }
399
400 /**
401 * @tc.number IsPreferredApnUserEdited_002
402 * @tc.name test function branch
403 * @tc.desc Function test
404 */
405 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_002, Function | MediumTest | Level1)
406 {
407 auto preferId = 1;
408 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
409 defaultApnItem->attr_.profileId_ = preferId;
410 defaultApnItem->attr_.isEdited_ = false;
411 apnManager->allApnItem_.push_back(defaultApnItem);
412 apnManager->preferId_ = preferId;
413 ASSERT_FALSE(apnManager->IsPreferredApnUserEdited());
414 }
415
416 /**
417 * @tc.number IsPreferredApnUserEdited_003
418 * @tc.name test function branch
419 * @tc.desc Function test
420 */
421 HWTEST_F(ApnManagerTest, IsPreferredApnUserEdited_003, Function | MediumTest | Level1)
422 {
423 auto preferId = 2;
424 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
425 defaultApnItem->attr_.profileId_ = 3;
426 defaultApnItem->attr_.isEdited_ = true;
427 apnManager->allApnItem_.push_back(defaultApnItem);
428 apnManager->preferId_ = preferId;
429 ASSERT_FALSE(apnManager->IsPreferredApnUserEdited());
430 }
431
432 /**
433 * @tc.number IsDataConnectionNotUsed_001
434 * @tc.name test function branch
435 * @tc.desc Function test
436 */
437 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_001, Function | MediumTest | Level1)
438 {
439 std::shared_ptr<CellularDataStateMachine> stateMachine = nullptr;
440 bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
441 ASSERT_FALSE(result);
442 }
443
444 /**
445 * @tc.number IsDataConnectionNotUsed_002
446 * @tc.name test function branch
447 * @tc.desc Function test
448 */
449 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_002, Function | MediumTest | Level1)
450 {
451 std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
452 auto stateMachine = machine->CreateCellularDataStateMachine(0);
453 apnManager->apnHolders_.push_back(nullptr);
454 bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
455 ASSERT_TRUE(result);
456 }
457
458 /**
459 * @tc.number IsDataConnectionNotUsed_003
460 * @tc.name test function branch
461 * @tc.desc Function test
462 */
463 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_003, Function | MediumTest | Level1)
464 {
465 std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
466 auto stateMachine = machine->CreateCellularDataStateMachine(0);
467 sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
468 static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
469 apnHolder->SetCellularDataStateMachine(stateMachine);
470 apnManager->apnHolders_.push_back(apnHolder);
471 bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
472 ASSERT_FALSE(result);
473 }
474
475 /**
476 * @tc.number IsDataConnectionNotUsed_004
477 * @tc.name test function branch
478 * @tc.desc Function test
479 */
480 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_004, Function | MediumTest | Level1)
481 {
482 std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
483 auto stateMachine = machine->CreateCellularDataStateMachine(0);
484 sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
485 static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
486 apnHolder->SetCellularDataStateMachine(nullptr);
487 apnManager->apnHolders_.push_back(apnHolder);
488 bool result = apnManager->IsDataConnectionNotUsed(stateMachine);
489 ASSERT_TRUE(result);
490 }
491
492 /**
493 * @tc.number IsDataConnectionNotUsed_005
494 * @tc.name test function branch
495 * @tc.desc Function test
496 */
497 HWTEST_F(ApnManagerTest, IsDataConnectionNotUsed_005, Function | MediumTest | Level1)
498 {
499 std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
500 auto stateMachine = machine->CreateCellularDataStateMachine(0);
501 sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
502 static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
503 apnHolder->SetCellularDataStateMachine(stateMachine);
504 apnManager->apnHolders_.push_back(apnHolder);
505 machine->cellularDataStateMachine_ = nullptr;
506 auto stateMachine_1 = machine->CreateCellularDataStateMachine(0);
507 bool result = apnManager->IsDataConnectionNotUsed(stateMachine_1);
508 ASSERT_TRUE(result);
509 }
510
511 /**
512 * @tc.number MakeSpecificApnItem_001
513 * @tc.name test function branch
514 * @tc.desc Function test
515 */
516 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_001, Function | MediumTest | Level1)
517 {
518 auto preferId = 1;
519 apnManager->preferId_ = preferId;
520 PdpProfile pdpProfile;
521 pdpProfile.profileId = preferId;
522 pdpProfile.apnTypes = "";
523 std::vector<PdpProfile> apnVec;
524 apnVec.push_back(pdpProfile);
525 bool result = apnManager->MakeSpecificApnItem(apnVec, 0);
526 ASSERT_EQ(result, 1);
527 }
528
529 /**
530 * @tc.number MakeSpecificApnItem_002
531 * @tc.name test function branch
532 * @tc.desc Function test
533 */
534 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_002, Function | MediumTest | Level1)
535 {
536 auto preferId = 1;
537 apnManager->preferId_ = preferId;
538 PdpProfile pdpProfile;
539 pdpProfile.profileId = preferId;
540 pdpProfile.apnTypes = "default";
541 std::vector<PdpProfile> apnVec;
542 apnVec.push_back(pdpProfile);
543 bool result = apnManager->MakeSpecificApnItem(apnVec, 0);
544 ASSERT_EQ(result, 1);
545 }
546
547 /**
548 * @tc.number MakeSpecificApnItem_003
549 * @tc.name test function branch
550 * @tc.desc Function test
551 */
552 HWTEST_F(ApnManagerTest, MakeSpecificApnItem_003, Function | MediumTest | Level1)
553 {
554 auto preferId = 1;
555 apnManager->preferId_ = 2;
556 PdpProfile pdpProfile;
557 pdpProfile.profileId = preferId;
558 pdpProfile.apnTypes = "default";
559 std::vector<PdpProfile> apnVec;
560 apnVec.push_back(pdpProfile);
561 bool result = apnManager->MakeSpecificApnItem(apnVec, 0);
562 ASSERT_EQ(result, 1);
563 }
564
565 /**
566 * @tc.number HasAnyConnectedState_001
567 * @tc.name test function branch
568 * @tc.desc Function test
569 */
570 HWTEST_F(ApnManagerTest, HasAnyConnectedState_001, Function | MediumTest | Level1)
571 {
572 std::vector<sptr<ApnHolder>> apnHolders;
573 apnManager->apnHolders_ = apnHolders;
574 bool result = apnManager->HasAnyConnectedState();
575 ASSERT_EQ(result, false);
576 }
577
578 /**
579 * @tc.number HasAnyConnectedState_002
580 * @tc.name test function branch
581 * @tc.desc Function test
582 */
583 HWTEST_F(ApnManagerTest, HasAnyConnectedState_002, Function | MediumTest | Level1)
584 {
585 std::vector<sptr<ApnHolder>> apnHolders;
586 sptr<ApnHolder> apnHolder = nullptr;
587 apnHolders.push_back(apnHolder);
588 apnManager->apnHolders_ = apnHolders;
589 bool result = apnManager->HasAnyConnectedState();
590 ASSERT_EQ(result, false);
591 }
592
593 /**
594 * @tc.number HasAnyConnectedState_003
595 * @tc.name test function branch
596 * @tc.desc Function test
597 */
598 HWTEST_F(ApnManagerTest, HasAnyConnectedState_003, Function | MediumTest | Level1)
599 {
600 std::vector<sptr<ApnHolder>> apnHolders;
601 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
602 apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_CONNECTED);
603 apnHolders.push_back(apnHolder);
604 apnManager->apnHolders_ = apnHolders;
605 bool result = apnManager->HasAnyConnectedState();
606 ASSERT_EQ(result, true);
607 }
608
609 /**
610 * @tc.number HasAnyConnectedState_004
611 * @tc.name test function branch
612 * @tc.desc Function test
613 */
614 HWTEST_F(ApnManagerTest, HasAnyConnectedState_004, Function | MediumTest | Level1)
615 {
616 std::vector<sptr<ApnHolder>> apnHolders;
617 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
618 apnHolder->SetApnState(ApnProfileState::PROFILE_STATE_DISCONNECTING);
619 apnHolders.push_back(apnHolder);
620 apnManager->apnHolders_ = apnHolders;
621 bool result = apnManager->HasAnyConnectedState();
622 ASSERT_EQ(result, true);
623 }
624
625 /**
626 * @tc.number GetRilAttachApn_001
627 * @tc.name test function branch
628 * @tc.desc Function test
629 */
630 HWTEST_F(ApnManagerTest, GetRilAttachApn_001, Function | MediumTest | Level1)
631 {
632 std::vector<sptr<ApnItem>> allApnItem;
633 apnManager->allApnItem_ = allApnItem;
634 ASSERT_EQ(apnManager->GetRilAttachApn(), nullptr);
635 }
636
637 /**
638 * @tc.number GetRilAttachApn_002
639 * @tc.name test function branch
640 * @tc.desc Function test
641 */
642 HWTEST_F(ApnManagerTest, GetRilAttachApn_002, Function | MediumTest | Level1)
643 {
644 std::vector<sptr<ApnItem>> allApnItem;
645 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
646 allApnItem.push_back(defaultApnItem);
647 apnManager->allApnItem_ = allApnItem;
648 ASSERT_NE(apnManager->GetRilAttachApn(), nullptr);
649 }
650
651 /**
652 * @tc.number GetRilAttachApn_003
653 * @tc.name test function branch
654 * @tc.desc Function test
655 */
656 HWTEST_F(ApnManagerTest, GetRilAttachApn_003, Function | MediumTest | Level1)
657 {
658 std::vector<sptr<ApnItem>> allApnItem;
659 sptr<ApnItem> apnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_IA);
660 allApnItem.push_back(apnItem);
661 apnManager->allApnItem_ = allApnItem;
662 ASSERT_NE(apnManager->GetRilAttachApn(), nullptr);
663 }
664
665 /**
666 * @tc.number GetRilAttachApn_004
667 * @tc.name test function branch
668 * @tc.desc Function test
669 */
670 HWTEST_F(ApnManagerTest, GetRilAttachApn_004, Function | MediumTest | Level1)
671 {
672 std::vector<sptr<ApnItem>> allApnItem;
673 sptr<ApnItem> apnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_MMS);
674 allApnItem.push_back(apnItem);
675 apnManager->allApnItem_ = allApnItem;
676 ASSERT_NE(apnManager->GetRilAttachApn(), nullptr);
677 }
678
679 /**
680 * @tc.number ReleaseDataConnection_001
681 * @tc.name test function branch
682 * @tc.desc Function test
683 */
684 HWTEST_F(ApnManagerTest, ReleaseDataConnection_001, TestSize.Level0)
685 {
686 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
687 apnHolder->cellularDataStateMachine_ = nullptr;
688 apnHolder->ReleaseDataConnection();
689 ASSERT_EQ(apnHolder->cellularDataStateMachine_, nullptr);
690 }
691
692 /**
693 * @tc.number ReleaseDataConnection_002
694 * @tc.name test function branch
695 * @tc.desc Function test
696 */
697 HWTEST_F(ApnManagerTest, ReleaseDataConnection_002, TestSize.Level0)
698 {
699 std::shared_ptr<StateMachineTest> machine = std::make_shared<StateMachineTest>();
700 auto stateMachine = machine->CreateCellularDataStateMachine(0);
701 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
702 apnHolder->SetCellularDataStateMachine(stateMachine);
703 apnHolder->ReleaseDataConnection();
704 ASSERT_NE(apnHolder->cellularDataStateMachine_, nullptr);
705 }
706
707 /**
708 * @tc.number RequestCellularData_001
709 * @tc.name test function branch
710 * @tc.desc Function test
711 */
712 HWTEST_F(ApnManagerTest, RequestCellularData_001, TestSize.Level0)
713 {
714 NetRequest netRequest;
715 netRequest.capability = 0;
716 netRequest.ident = "ident";
717 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
718 apnHolder->RequestCellularData(netRequest);
719 ASSERT_EQ(apnHolder->dataCallEnabled_, true);
720 }
721
722 /**
723 * @tc.number RequestCellularData_002
724 * @tc.name test function branch
725 * @tc.desc Function test
726 */
727 HWTEST_F(ApnManagerTest, RequestCellularData_002, TestSize.Level0)
728 {
729 NetRequest netRequest;
730 netRequest.capability = 0;
731 netRequest.ident = "ident";
732 NetRequest netRequest1;
733 netRequest1.capability = 0;
734 netRequest1.ident = "abc";
735 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
736 apnHolder->netRequests_.push_back(netRequest1);
737 apnHolder->RequestCellularData(netRequest);
738 ASSERT_EQ(apnHolder->dataCallEnabled_, true);
739 }
740
741 /**
742 * @tc.number RequestCellularData_003
743 * @tc.name test function branch
744 * @tc.desc Function test
745 */
746 HWTEST_F(ApnManagerTest, RequestCellularData_003, TestSize.Level0)
747 {
748 NetRequest netRequest;
749 netRequest.capability = 0;
750 netRequest.ident = "ident";
751 NetRequest netRequest1;
752 netRequest1.capability = 1;
753 netRequest1.ident = "ident";
754 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
755 apnHolder->netRequests_.push_back(netRequest1);
756 apnHolder->RequestCellularData(netRequest);
757 ASSERT_EQ(apnHolder->dataCallEnabled_, true);
758 }
759
760 /**
761 * @tc.number RequestCellularData_004
762 * @tc.name test function branch
763 * @tc.desc Function test
764 */
765 HWTEST_F(ApnManagerTest, RequestCellularData_004, TestSize.Level0)
766 {
767 NetRequest netRequest;
768 netRequest.capability = 1;
769 netRequest.ident = "ident";
770 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
771 apnHolder->netRequests_.push_back(netRequest);
772 int size = apnHolder->netRequests_.size();
773 apnHolder->RequestCellularData(netRequest);
774 ASSERT_EQ(size, apnHolder->netRequests_.size());
775 }
776
777 /**
778 * @tc.number IsCompatibleApnItem_001
779 * @tc.name test function branch
780 * @tc.desc Function test
781 */
782 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_001, TestSize.Level0)
783 {
784 sptr<ApnItem> newApnItem = nullptr;
785 sptr<ApnItem> oldApnItem = nullptr;
786 bool roamingState = false;
787 bool result = ApnHolder::IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
788 ASSERT_FALSE(result);
789 }
790
791 /**
792 * @tc.number IsCompatibleApnItem_002
793 * @tc.name test function branch
794 * @tc.desc Function test
795 */
796 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_002, TestSize.Level0)
797 {
798 sptr<ApnItem> newApnItem = new ApnItem();
799 sptr<ApnItem> oldApnItem = new ApnItem();
800 std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
801 std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
802 bool roamingState = true;
803 bool result = ApnHolder::IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
804 ASSERT_TRUE(result);
805 }
806
807 /**
808 * @tc.number IsCompatibleApnItem_003
809 * @tc.name test function branch
810 * @tc.desc Function test
811 */
812 HWTEST_F(ApnManagerTest, IsCompatibleApnItem_003, TestSize.Level0)
813 {
814 sptr<ApnItem> newApnItem = new ApnItem();
815 sptr<ApnItem> oldApnItem = new ApnItem();
816 std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
817 std::strcmp(newApnItem->attr_.roamingProtocol_, "test_protocol");
818 bool roamingState = false;
819 bool result = ApnHolder::IsCompatibleApnItem(newApnItem, oldApnItem, roamingState);
820 ASSERT_TRUE(result);
821 }
822
823 /**
824 * @tc.number GetNextRetryApnItem001
825 * @tc.name test function branch
826 * @tc.desc Function test
827 */
828 HWTEST_F(ApnManagerTest, GetNextRetryApnItem001, TestSize.Level0)
829 {
830 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
831 connectionRetryPolicy->matchedApns_.clear();
832 EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
833
834 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
835 defaultApnItem->MarkBadApn(true);
836 connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
837 connectionRetryPolicy->currentApnIndex_ = 0;
838 EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
839 defaultApnItem->MarkBadApn(false);
840 EXPECT_NE(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
841 }
842
843 /**
844 * @tc.number GetNextRetryApnItem002
845 * @tc.name test function branch
846 * @tc.desc Function test
847 */
848 HWTEST_F(ApnManagerTest, GetNextRetryApnItem002, TestSize.Level0)
849 {
850 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
851 connectionRetryPolicy->currentApnIndex_ = 10;
852 EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 10);
853 }
854
855 /**
856 * @tc.number GetNextRetryApnItem_003
857 * @tc.name test function branch
858 * @tc.desc Function test
859 */
860 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_003, TestSize.Level0)
861 {
862 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
863 connectionRetryPolicy->currentApnIndex_ = -1;
864 EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, -1);
865 }
866
867 /**
868 * @tc.number GetNextRetryApnItem_004
869 * @tc.name test function branch
870 * @tc.desc Function test
871 */
872 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_004, TestSize.Level0)
873 {
874 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
875 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
876 defaultApnItem->MarkBadApn(true);
877 connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
878 connectionRetryPolicy->currentApnIndex_ = 0;
879 EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
880 }
881
882 /**
883 * @tc.number GetNextRetryApnItem_005
884 * @tc.name test function branch
885 * @tc.desc Function test
886 */
887 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_005, TestSize.Level0)
888 {
889 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
890 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
891 defaultApnItem->MarkBadApn(false);
892 connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
893 connectionRetryPolicy->tryCount_ = 10;
894 connectionRetryPolicy->maxCount_ = 0;
895 connectionRetryPolicy->currentApnIndex_ = 0;
896 EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
897 }
898
899 /**
900 * @tc.number GetNextRetryApnItem_006
901 * @tc.name test function branch
902 * @tc.desc Function test
903 */
904 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_006, TestSize.Level0)
905 {
906 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
907 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
908 defaultApnItem->MarkBadApn(false);
909 connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
910 connectionRetryPolicy->tryCount_ = -1;
911 connectionRetryPolicy->maxCount_ = 0;
912 connectionRetryPolicy->currentApnIndex_ = 0;
913 EXPECT_EQ(connectionRetryPolicy->currentApnIndex_, 0);
914 }
915
916 /**
917 * @tc.number GetNextRetryApnItem_007
918 * @tc.name test function branch
919 * @tc.desc Function test
920 */
921 HWTEST_F(ApnManagerTest, GetNextRetryApnItem_007, TestSize.Level0)
922 {
923 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
924 connectionRetryPolicy->matchedApns_.clear();
925 connectionRetryPolicy->currentApnIndex_ = 0;
926 EXPECT_EQ(connectionRetryPolicy->GetNextRetryApnItem(), nullptr);
927 }
928
929 /**
930 * @tc.number OnPropChanged_001
931 * @tc.name test function branch
932 * @tc.desc Function test
933 */
934 HWTEST_F(ApnManagerTest, OnPropChanged_001, TestSize.Level0)
935 {
936 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
937 connectionRetryPolicy->OnPropChanged(nullptr, nullptr, nullptr);
938 EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
939 connectionRetryPolicy->OnPropChanged("persist.telephony.retrystrategy.allow", nullptr, nullptr);
940 EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
941 connectionRetryPolicy->OnPropChanged("persist.telephony.retrystrategy.allow", "true", nullptr);
942 EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
943 connectionRetryPolicy->OnPropChanged("fakeKey", nullptr, nullptr);
944 EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
945 connectionRetryPolicy->OnPropChanged("fakeKey", "true", nullptr);
946 EXPECT_EQ(connectionRetryPolicy->isPropOn_, true);
947 connectionRetryPolicy->OnPropChanged("persist.telephony.setupfail.delay", "3000", nullptr);
948 EXPECT_EQ(connectionRetryPolicy->defaultSetupFailDelay_, 3000);
949 connectionRetryPolicy->OnPropChanged("persist.telephony.setupfail.delay", "ABC", nullptr);
950 EXPECT_EQ(connectionRetryPolicy->defaultSetupFailDelay_, 3000);
951 connectionRetryPolicy->OnPropChanged("persist.telephony.modemdend.delay", "1000", nullptr);
952 EXPECT_EQ(connectionRetryPolicy->defaultModemDendDelay_, 1000);
953 connectionRetryPolicy->OnPropChanged("persist.telephony.modemdend.delay", "ABNC", nullptr);
954 EXPECT_EQ(connectionRetryPolicy->defaultModemDendDelay_, 1000);
955 }
956
957 /**
958 * @tc.number IsAllBadApn_001
959 * @tc.name test function branch
960 * @tc.desc Function test
961 */
962 HWTEST_F(ApnManagerTest, IsAllBadApn_001, TestSize.Level0)
963 {
964 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
965 connectionRetryPolicy->matchedApns_.clear();
966 EXPECT_TRUE(connectionRetryPolicy->IsAllBadApn());
967 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
968 defaultApnItem->MarkBadApn(false);
969 connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
970 EXPECT_FALSE(connectionRetryPolicy->IsAllBadApn());
971 defaultApnItem->MarkBadApn(true);
972 EXPECT_TRUE(connectionRetryPolicy->IsAllBadApn());
973 }
974
975 /**
976 * @tc.number GetNextRetryDelay_001
977 * @tc.name test function branch
978 * @tc.desc Function test
979 */
980 HWTEST_F(ApnManagerTest, GetNextRetryDelay_001, TestSize.Level0)
981 {
982 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
983 connectionRetryPolicy->matchedApns_.clear();
984 auto delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0,
985 RetryScene::RETRY_SCENE_OTHERS, true);
986 EXPECT_GE(delay, 0);
987 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
988 defaultApnItem->MarkBadApn(true);
989 connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
990 delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
991 true);
992 EXPECT_GE(delay, 0);
993 delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_INTERNAL_DEFAULT, 0, 0,
994 RetryScene::RETRY_SCENE_OTHERS, true);
995 EXPECT_GE(delay, 60);
996 delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_INTERNAL_DEFAULT, 0, 0,
997 RetryScene::RETRY_SCENE_OTHERS, false);
998 EXPECT_GE(delay, 5);
999 }
1000
1001 /**
1002 * @tc.number GetNextRetryDelay_002
1003 * @tc.name test function branch
1004 * @tc.desc Function test
1005 */
1006 HWTEST_F(ApnManagerTest, GetNextRetryDelay_002, TestSize.Level0)
1007 {
1008 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1009 connectionRetryPolicy->matchedApns_.clear();
1010 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
1011 defaultApnItem->MarkBadApn(false);
1012 connectionRetryPolicy->matchedApns_.push_back(defaultApnItem);
1013 auto delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0,
1014 RetryScene::RETRY_SCENE_OTHERS, true);
1015 EXPECT_GE(delay, 0);
1016 connectionRetryPolicy->isPropOn_ = false;
1017 delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
1018 true);
1019 EXPECT_GE(delay, 0);
1020 connectionRetryPolicy->isPropOn_ = true;
1021 delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_DEFAULT, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
1022 true);
1023 EXPECT_GE(delay, 0);
1024 delay = connectionRetryPolicy->GetNextRetryDelay(DATA_CONTEXT_ROLE_MMS, 0, 0, RetryScene::RETRY_SCENE_OTHERS,
1025 true);
1026 EXPECT_GE(delay, 0);
1027 }
1028
1029 /**
1030 * @tc.number SetMatchedApns_001
1031 * @tc.name test function branch
1032 * @tc.desc Function test
1033 */
1034 HWTEST_F(ApnManagerTest, SetMatchedApns_001, TestSize.Level0)
1035 {
1036 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1037 std::vector<sptr<ApnItem>> matchedApns = {};
1038 connectionRetryPolicy->SetMatchedApns(matchedApns);
1039 EXPECT_EQ(connectionRetryPolicy->GetMatchedApns().size(), 0);
1040 }
1041
1042 /**
1043 * @tc.number GetRandomDelay_001
1044 * @tc.name test function branch
1045 * @tc.desc Function test
1046 */
1047 HWTEST_F(ApnManagerTest, GetRandomDelay_001, TestSize.Level0)
1048 {
1049 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1050 EXPECT_GE(connectionRetryPolicy->GetRandomDelay(), 0);
1051 EXPECT_LE(connectionRetryPolicy->GetRandomDelay(), 2000);
1052 }
1053
1054 /**
1055 * @tc.number ConvertPdpErrorToDisconnReason_001
1056 * @tc.name test function branch
1057 * @tc.desc Function test
1058 */
1059 HWTEST_F(ApnManagerTest, ConvertPdpErrorToDisconnReason_001, TestSize.Level0)
1060 {
1061 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1062 auto res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1063 PdpErrorReason::PDP_ERR_OPERATOR_DETERMINED_BARRING);
1064 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1065 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1066 PdpErrorReason::PDP_ERR_MISSING_OR_UNKNOWN_APN);
1067 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1068 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1069 PdpErrorReason::PDP_ERR_UNKNOWN_PDP_ADDR_OR_TYPE);
1070 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1071 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1072 PdpErrorReason::PDP_ERR_USER_VERIFICATION);
1073 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1074 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1075 PdpErrorReason::PDP_ERR_ACTIVATION_REJECTED_GGSN);
1076 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1077 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1078 PdpErrorReason::PDP_ERR_SERVICE_OPTION_NOT_SUPPORTED);
1079 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1080 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1081 PdpErrorReason::PDP_ERR_REQUESTED_SERVICE_OPTION_NOT_SUBSCRIBED);
1082 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1083 }
1084
1085 /**
1086 * @tc.number ConvertPdpErrorToDisconnReason_002
1087 * @tc.name test function branch
1088 * @tc.desc Function test
1089 */
1090 HWTEST_F(ApnManagerTest, ConvertPdpErrorToDisconnReason_002, TestSize.Level0)
1091 {
1092 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1093 auto res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1094 PdpErrorReason::PDP_ERR_NSAPI_ALREADY_USED);
1095 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1096 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1097 PdpErrorReason::PDP_ERR_IPV4_ONLY_ALLOWED);
1098 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1099 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1100 PdpErrorReason::PDP_ERR_IPV6_ONLY_ALLOWED);
1101 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1102 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1103 PdpErrorReason::PDP_ERR_PROTOCOL_ERRORS);
1104 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1105 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1106 PdpErrorReason::PDP_ERR_RETRY);
1107 EXPECT_EQ(res, DisConnectionReason::REASON_RETRY_CONNECTION);
1108 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1109 PdpErrorReason::PDP_ERR_TO_NORMAL);
1110 EXPECT_EQ(res, DisConnectionReason::REASON_NORMAL);
1111 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1112 PdpErrorReason::PDP_ERR_TO_GSM_AND_CALLING_ONLY);
1113 EXPECT_EQ(res, DisConnectionReason::REASON_GSM_AND_CALLING_ONLY);
1114 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1115 PdpErrorReason::PDP_ERR_TO_CLEAR_CONNECTION);
1116 EXPECT_EQ(res, DisConnectionReason::REASON_CLEAR_CONNECTION);
1117 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1118 PdpErrorReason::PDP_ERR_TO_CHANGE_CONNECTION);
1119 EXPECT_EQ(res, DisConnectionReason::REASON_CHANGE_CONNECTION);
1120 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1121 PdpErrorReason::PDP_ERR_TO_PERMANENT_REJECT);
1122 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1123 }
1124
1125 /**
1126 @tc.number ConvertPdpErrorToDisconnReason_003
1127 @tc.name test function branch
1128 @tc.desc Function test
1129 */
1130 HWTEST_F(ApnManagerTest, ConvertPdpErrorToDisconnReason_003, TestSize.Level0)
1131 {
1132 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1133 connectionRetryPolicy->isPropOn_ = false;
1134 auto res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1135 PdpErrorReason::PDP_ERR_TO_PERMANENT_REJECT);
1136 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1137 connectionRetryPolicy->isPropOn_ = true;
1138 res = connectionRetryPolicy->ConvertPdpErrorToDisconnReason(
1139 PdpErrorReason::PDP_ERR_TO_PERMANENT_REJECT);
1140 EXPECT_EQ(res, DisConnectionReason::REASON_PERMANENT_REJECT);
1141 }
1142
1143 /**
1144
1145 @tc.number RestartRadioIfRequired_001
1146 @tc.name test function branch
1147 @tc.desc Function test
1148 */
1149 HWTEST_F(ApnManagerTest, RestartRadioIfRequired_003, TestSize.Level0)
1150 {
1151 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1152 connectionRetryPolicy->isPropOn_ = true;
1153 int32_t failCause = 65536;
1154 connectionRetryPolicy->RestartRadioIfRequired(failCause, 0);
1155 connectionRetryPolicy->isPropOn_ = false;
1156 connectionRetryPolicy->RestartRadioIfRequired(failCause, 0);
1157 EXPECT_FALSE(connectionRetryPolicy->isPropOn_);
1158 }
1159
1160 /**
1161 * @tc.number InitialRetryCountValue_001
1162 * @tc.name test function branch
1163 * @tc.desc Function test
1164 */
1165 HWTEST_F(ApnManagerTest, InitialRetryCountValue_001, TestSize.Level0)
1166 {
1167 std::shared_ptr<ConnectionRetryPolicy> connectionRetryPolicy = std::make_shared<ConnectionRetryPolicy>();
1168 connectionRetryPolicy->InitialRetryCountValue();
1169 EXPECT_EQ(connectionRetryPolicy->tryCount_, 0);
1170 connectionRetryPolicy->isPropOn_ = true;
1171 connectionRetryPolicy->InitialRetryCountValue();
1172 EXPECT_EQ(connectionRetryPolicy->tryCount_, 0);
1173 connectionRetryPolicy->isPropOn_ = false;
1174 connectionRetryPolicy->InitialRetryCountValue();
1175 EXPECT_EQ(connectionRetryPolicy->tryCount_, 0);
1176 }
1177
1178 /**
1179 * @tc.number EnableCellularDataRoaming_001
1180 * @tc.name test function branch
1181 * @tc.desc Function test
1182 */
1183 HWTEST_F(ApnManagerTest, EnableCellularDataRoaming_001, TestSize.Level0)
1184 {
1185 int32_t result = CellularDataClient::GetInstance().EnableCellularDataRoaming(0, true);
1186 EXPECT_NE(result, true);
1187 }
1188
1189 /**
1190 * @tc.number HasInternetCapability_001
1191 * @tc.name test function branch
1192 * @tc.desc Function test
1193 */
1194 HWTEST_F(ApnManagerTest, HasInternetCapability_001, TestSize.Level0)
1195 {
1196 int32_t result = CellularDataClient::GetInstance().HasInternetCapability(0, 0);
1197 EXPECT_EQ(result, false);
1198 }
1199
1200 /**
1201 * @tc.number HandleApnChanged_001
1202 * @tc.name test function branch
1203 * @tc.desc Function test
1204 */
1205 HWTEST_F(ApnManagerTest, HandleApnChanged_001, TestSize.Level0)
1206 {
1207 int32_t result = CellularDataClient::GetInstance().HandleApnChanged(0);
1208 EXPECT_NE(result, true);
1209 }
1210
1211 /**
1212 * @tc.number UpdateDefaultCellularDataSlotId_001
1213 * @tc.name test function branch
1214 * @tc.desc Function test
1215 */
1216 HWTEST_F(ApnManagerTest, UpdateDefaultCellularDataSlotId_001, TestSize.Level0)
1217 {
1218 int32_t result = CellularDataClient::GetInstance().UpdateDefaultCellularDataSlotId();
1219 EXPECT_EQ(result, 0);
1220 }
1221
1222 /**
1223 * @tc.name : ApnItem_CanDealWithType_001
1224 * @tc.number: ApnItemTest_001
1225 * @tc.desc : Test when the type matches with the apnTypes_ then CanDealWithType returns true
1226 */
1227 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_001, TestSize.Level0)
1228 {
1229 ApnItem apnItem;
1230 apnItem.apnTypes_.push_back("default");
1231 EXPECT_TRUE(apnItem.CanDealWithType("default"));
1232 }
1233
1234 /**
1235 * @tc.name : ApnItem_CanDealWithType_002
1236 * @tc.number: ApnItemTest_002
1237 * @tc.desc : Test when the type is DATA_CONTEXT_ROLE_INTERNAL_DEFAULT
1238 * and apnTypes_ contains DATA_CONTEXT_ROLE_DEFAULT then CanDealWithType returns true
1239 */
1240 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_002, TestSize.Level0)
1241 {
1242 ApnItem apnItem;
1243 apnItem.apnTypes_.push_back(DATA_CONTEXT_ROLE_DEFAULT);
1244 EXPECT_TRUE(apnItem.CanDealWithType(DATA_CONTEXT_ROLE_INTERNAL_DEFAULT));
1245 }
1246
1247 /**
1248 * @tc.name : ApnItem_CanDealWithType_003
1249 * @tc.number: ApnItemTest_003
1250 * @tc.desc : Test when the type is not DATA_CONTEXT_ROLE_IA and
1251 * apnTypes_ contains DATA_CONTEXT_ROLE_ALL then CanDealWithType returns true
1252 */
1253 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_003, TestSize.Level0)
1254 {
1255 ApnItem apnItem;
1256 apnItem.apnTypes_.push_back(DATA_CONTEXT_ROLE_ALL);
1257 EXPECT_TRUE(apnItem.CanDealWithType("not_ia"));
1258 }
1259
1260 /**
1261 * @tc.name : ApnItem_CanDealWithType_004
1262 * @tc.number: ApnItemTest_004
1263 * @tc.desc : Test when the type does not match with the apnTypes_ then CanDealWithType returns false
1264 */
1265 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_004, TestSize.Level0)
1266 {
1267 ApnItem apnItem;
1268 apnItem.apnTypes_.push_back("default");
1269 EXPECT_FALSE(apnItem.CanDealWithType("other"));
1270 }
1271
1272 /**
1273 * @tc.name : ApnManager_FindApnHolderById_001
1274 * @tc.number: ApnItemTest_004
1275 * @tc.desc : Test when the type does not match with the apnTypes_ then CanDealWithType returns false
1276 */
1277 HWTEST_F(ApnManagerTest, ApnManager_FindApnHolderById_001, TestSize.Level0)
1278 {
1279 apnManager->apnIdApnHolderMap_.clear();
1280 EXPECT_EQ(apnManager->FindApnHolderById(0), nullptr);
1281 apnManager->AddApnHolder("default", 10);
1282 EXPECT_EQ(apnManager->FindApnTypeByApnName("abc"), static_cast<uint64_t>(ApnTypes::NONETYPE));
1283 }
1284
1285 HWTEST_F(ApnManagerTest, ApnHolderAddUid001, TestSize.Level0)
1286 {
1287 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
1288 EXPECT_TRUE(apnHolder != nullptr);
1289 apnHolder->AddUid(1);
1290 apnHolder->AddUid(1);
1291 }
1292
1293 HWTEST_F(ApnManagerTest, ApnHolderRemoveUid001, TestSize.Level0)
1294 {
1295 sptr<ApnHolder> apnHolder = new ApnHolder("", 0);
1296 EXPECT_TRUE(apnHolder != nullptr);
1297 apnHolder->RemoveUid(1);
1298 apnHolder->RemoveUid(1);
1299 }
1300
1301 /**
1302 * @tc.name : ApnItem_IsSimilarPdpProfile_001
1303 * @tc.number: ApnItemTest_005
1304 */
1305 HWTEST_F(ApnManagerTest, ApnItem_IsSimilarPdpProfile_001, TestSize.Level0)
1306 {
1307 PdpProfile p1;
1308 PdpProfile p2;
1309 EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1310 p1.apn = "1";
1311 p2.apn = "2";
1312 EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1313 p1.apn = "";
1314 p2.apn = "";
1315 p1.proxyIpAddress = "1";
1316 p2.proxyIpAddress = "";
1317 EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1318 p1.proxyIpAddress = "";
1319 p2.proxyIpAddress = "1";
1320 EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1321 p1.proxyIpAddress = "1";
1322 p2.proxyIpAddress = "2";
1323 EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1324 p1.proxyIpAddress = "";
1325 p2.proxyIpAddress = "";
1326 p1.mvnoType = "1";
1327 p2.mvnoType = "";
1328 EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1329 }
1330
1331 /**
1332 * @tc.name : ApnItem_IsSimilarPdpProfile_002
1333 * @tc.number: ApnItemTest_007
1334 */
1335 HWTEST_F(ApnManagerTest, ApnItem_IsSimilarPdpProfile_002, TestSize.Level0)
1336 {
1337 PdpProfile p1;
1338 PdpProfile p2;
1339 p1.mvnoMatchData = "1";
1340 p2.mvnoMatchData = "";
1341 EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1342 p1.mvnoMatchData = "";
1343 p2.mvnoMatchData = "";
1344 p1.homeUrl = "1";
1345 p2.homeUrl = "";
1346 EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1347 p1.homeUrl = "";
1348 p2.homeUrl = "1";
1349 EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1350 p1.homeUrl = "1";
1351 p2.homeUrl = "2";
1352 EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1353 p1.homeUrl = "";
1354 p2.homeUrl = "";
1355 p1.mmsIpAddress = "1";
1356 p2.mmsIpAddress = "";
1357 EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1358 p1.mmsIpAddress = "";
1359 p2.mmsIpAddress = "1";
1360 EXPECT_TRUE(ApnItem::IsSimilarPdpProfile(p1, p2));
1361 p1.mmsIpAddress = "1";
1362 p2.mmsIpAddress = "2";
1363 EXPECT_FALSE(ApnItem::IsSimilarPdpProfile(p1, p2));
1364 }
1365
1366 /**
1367 * @tc.name : ApnItem_IsSimilarProtocol_001
1368 * @tc.number: ApnItemTest_006
1369 */
1370 HWTEST_F(ApnManagerTest, ApnItem_IsSimilarProtocol_001, TestSize.Level0)
1371 {
1372 std::string newProtocol;
1373 std::string oldProtocol;
1374 EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1375 newProtocol = "IPV4V6";
1376 oldProtocol = "IP";
1377 EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1378 newProtocol = "IPV4V6";
1379 oldProtocol = "IPV6";
1380 EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1381 newProtocol = "IP";
1382 oldProtocol = "IPV4V6";
1383 EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1384 newProtocol = "IPV6";
1385 oldProtocol = "IPV4V6";
1386 EXPECT_TRUE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1387 newProtocol = "IPV6";
1388 oldProtocol = "IPV4";
1389 EXPECT_FALSE(ApnItem::IsSimilarProtocol(newProtocol, oldProtocol));
1390 }
1391
1392 /**
1393 * @tc.name : ApnManager_TryMergeSimilarPdpProfile_001
1394 * @tc.number: ApnManagerTest_005
1395 */
1396 HWTEST_F(ApnManagerTest, ApnManager_TryMergeSimilarPdpProfile_001, TestSize.Level0)
1397 {
1398 auto preferId = 1;
1399 apnManager->preferId_ = preferId;
1400 PdpProfile pdpProfile;
1401 pdpProfile.profileId = preferId;
1402 pdpProfile.apnTypes = "";
1403 std::vector<PdpProfile> apnVec;
1404 apnVec.push_back(pdpProfile);
1405 apnManager->TryMergeSimilarPdpProfile(apnVec);
1406 EXPECT_EQ(apnVec.size(), 1);
1407 PdpProfile pdpProfile2 = pdpProfile;
1408 apnVec.push_back(pdpProfile2);
1409 apnManager->TryMergeSimilarPdpProfile(apnVec);
1410 EXPECT_EQ(apnVec.size(), 1);
1411 PdpProfile pdpProfile3 = pdpProfile;
1412 pdpProfile3.apnTypes = "default";
1413 apnVec.push_back(pdpProfile3);
1414 apnManager->TryMergeSimilarPdpProfile(apnVec);
1415 EXPECT_EQ(apnVec.size(), 1);
1416 }
1417
1418 /**
1419 * @tc.name : ApnManager_TryMergeSimilarPdpProfile_002
1420 * @tc.number: ApnManagerTest_005
1421 */
1422 HWTEST_F(ApnManagerTest, ApnManager_TryMergeSimilarPdpProfile_002, TestSize.Level1)
1423 {
1424 uint64_t expected = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET;
1425 int32_t apnId = DATA_CONTEXT_ROLE_DEFAULT_ID;
1426 uint64_t actual = apnManager->FindCapabilityByApnId(apnId);
1427 EXPECT_EQ(actual, expected);
1428 expected = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNAL_DEFAULT;
1429 apnId = DATA_CONTEXT_ROLE_MMS_ID;
1430 actual = apnManager->FindCapabilityByApnId(apnId);
1431 EXPECT_EQ(actual, expected);
1432 expected = NetManagerStandard::NetCap::NET_CAPABILITY_INTERNAL_DEFAULT;
1433 apnId = DATA_CONTEXT_ROLE_INTERNAL_DEFAULT_ID;
1434 actual = apnManager->FindCapabilityByApnId(apnId);
1435 EXPECT_EQ(actual, expected);
1436 expected = NetManagerStandard::NetCap::NET_CAPABILITY_IA;
1437 apnId = DATA_CONTEXT_ROLE_IA_ID;
1438 actual = apnManager->FindCapabilityByApnId(apnId);
1439 EXPECT_EQ(actual, expected);
1440 expected = NetManagerStandard::NetCap::NET_CAPABILITY_XCAP;
1441 apnId = DATA_CONTEXT_ROLE_XCAP_ID;
1442 actual = apnManager->FindCapabilityByApnId(apnId);
1443 EXPECT_EQ(actual, expected);
1444 expected = NetManagerStandard::NetCap::NET_CAPABILITY_SUPL;
1445 apnId = DATA_CONTEXT_ROLE_SUPL_ID;
1446 actual = apnManager->FindCapabilityByApnId(apnId);
1447 EXPECT_EQ(actual, expected);
1448 expected = NetManagerStandard::NetCap::NET_CAPABILITY_DUN;
1449 apnId = DATA_CONTEXT_ROLE_DUN_ID;
1450 actual = apnManager->FindCapabilityByApnId(apnId);
1451 EXPECT_EQ(actual, expected);
1452 expected = NetManagerStandard::NetCap::NET_CAPABILITY_BIP;
1453 apnId = DATA_CONTEXT_ROLE_BIP_ID;
1454 actual = apnManager->FindCapabilityByApnId(apnId);
1455 EXPECT_EQ(actual, expected);
1456 expected = NetManagerStandard::NetCap::NET_CAPABILITY_END;
1457 apnId = -1;
1458 actual = apnManager->FindCapabilityByApnId(apnId);
1459 EXPECT_EQ(actual, expected);
1460 }
1461
1462 /**
1463 * @tc.name : ApnItem_IsSimilarProperty_001
1464 * @tc.number: ApnItemTest_006
1465 */
1466 HWTEST_F(ApnManagerTest, ApnItem_IsSimilarProperty_001, TestSize.Level0)
1467 {
1468 std::string newProtocol;
1469 std::string oldProtocol;
1470 EXPECT_TRUE(ApnItem::IsSimilarProperty(newProtocol, oldProtocol));
1471 newProtocol = "IPV4V6";
1472 oldProtocol = "IPV4V6";
1473 EXPECT_TRUE(ApnItem::IsSimilarProperty(newProtocol, oldProtocol));
1474 newProtocol = "";
1475 oldProtocol = "IPV6";
1476 EXPECT_TRUE(ApnItem::IsSimilarProperty(newProtocol, oldProtocol));
1477 newProtocol = "IP";
1478 oldProtocol = "";
1479 EXPECT_TRUE(ApnItem::IsSimilarProperty(newProtocol, oldProtocol));
1480 newProtocol = "IP";
1481 oldProtocol = "IPV6";
1482 EXPECT_FALSE(ApnItem::IsSimilarProperty(newProtocol, oldProtocol));
1483 }
1484
1485 /**
1486 * @tc.name : ApnItem_CanDealWithType_005
1487 * @tc.number: ApnItemTest_004
1488 * @tc.desc : Test when the type does not match with the apnTypes_ then CanDealWithType returns false
1489 */
1490 HWTEST_F(ApnManagerTest, ApnItem_CanDealWithType_005, TestSize.Level0)
1491 {
1492 ApnItem apnItem;
1493 apnItem.apnTypes_.push_back("default");
1494 EXPECT_TRUE(apnItem.CanDealWithType("bip"));
1495 }
1496
1497 /**
1498 * @tc.number FetchBipApns_001
1499 * @tc.name test function branch
1500 * @tc.desc Function test
1501 */
1502 HWTEST_F(ApnManagerTest, FetchBipApns_001, TestSize.Level0)
1503 {
1504 sptr<ApnItem> defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT);
1505 apnManager->allApnItem_.push_back(defaultApnItem);
1506 std::vector<sptr<ApnItem>> bipApnList;
1507 apnManager->FetchBipApns(bipApnList);
1508 sptr<ApnItem> bipApn = nullptr;
1509 apnManager->GetBipApnItem(bipApn);
1510 EXPECT_GE(bipApnList.size(), 0);
1511 EXPECT_EQ(bipApn, nullptr);
1512 sptr<ApnItem> bipApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_BIP);
1513 apnManager->allApnItem_.push_back(bipApnItem);
1514 bipApnList.clear();
1515 apnManager->FetchBipApns(bipApnList);
1516 apnManager->GetBipApnItem(bipApn);
1517 EXPECT_GE(bipApnList.size(), 0);
1518 EXPECT_NE(bipApn, nullptr);
1519 }
1520
1521 /**
1522 * @tc.number FindBestCapability_006
1523 * @tc.name test function branch
1524 * @tc.desc Function test
1525 */
1526 HWTEST_F(ApnManagerTest, FindBestCapability_006, Function | MediumTest | Level1)
1527 {
1528 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI1;
1529 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
1530 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI1);
1531 }
1532
1533 /**
1534 * @tc.number FindBestCapability_007
1535 * @tc.name test function branch
1536 * @tc.desc Function test
1537 */
1538 HWTEST_F(ApnManagerTest, FindBestCapability_007, Function | MediumTest | Level1)
1539 {
1540 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI2;
1541 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
1542 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI2);
1543 }
1544
1545 /**
1546 * @tc.number FindBestCapability_008
1547 * @tc.name test function branch
1548 * @tc.desc Function test
1549 */
1550 HWTEST_F(ApnManagerTest, FindBestCapability_008, Function | MediumTest | Level1)
1551 {
1552 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI3;
1553 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
1554 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI3);
1555 }
1556
1557 /**
1558 * @tc.number FindBestCapability_009
1559 * @tc.name test function branch
1560 * @tc.desc Function test
1561 */
1562 HWTEST_F(ApnManagerTest, FindBestCapability_009, Function | MediumTest | Level1)
1563 {
1564 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI4;
1565 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
1566 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI4);
1567 }
1568
1569 /**
1570 * @tc.number FindBestCapability_010
1571 * @tc.name test function branch
1572 * @tc.desc Function test
1573 */
1574 HWTEST_F(ApnManagerTest, FindBestCapability_010, Function | MediumTest | Level1)
1575 {
1576 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI5;
1577 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
1578 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI5);
1579 }
1580
1581 /**
1582 * @tc.number FindBestCapability_011
1583 * @tc.name test function branch
1584 * @tc.desc Function test
1585 */
1586 HWTEST_F(ApnManagerTest, FindBestCapability_011, Function | MediumTest | Level1)
1587 {
1588 uint64_t capabilities = 1L << NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI6;
1589 NetManagerStandard::NetCap netCap = apnManager->FindBestCapability(capabilities);
1590 ASSERT_EQ(netCap, NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI6);
1591 }
1592
1593 /**
1594 * @tc.number AddApnHolder_001
1595 * @tc.name test function branch
1596 * @tc.desc Function test
1597 */
1598 HWTEST_F(ApnManagerTest, AddApnHolder_001, TestSize.Level0)
1599 {
1600 apnManager->apnIdApnHolderMap_.clear();
1601 EXPECT_EQ(apnManager->FindApnHolderById(0), nullptr);
1602 std::string apnType = "hello";
1603 int32_t priority = 123;
1604 EXPECT_EQ(apnManager->FindApnIdByApnName(apnType), DATA_CONTEXT_ROLE_INVALID_ID);
1605 apnManager->AddApnHolder(apnType, priority);
1606 EXPECT_EQ(apnManager->FindApnTypeByApnName("abc"), static_cast<uint64_t>(ApnTypes::NONETYPE));
1607 }
1608
1609 /**
1610 * @tc.number ReportApnInfo_001
1611 * @tc.name test function branch
1612 * @tc.desc Function test
1613 */
1614 HWTEST_F(ApnManagerTest, ReportApnInfo_001, TestSize.Level0)
1615 {
1616 int32_t slotId = 123;
1617 PdpProfile apnData;
1618 apnManager->ReportApnInfo(slotId, apnData);
1619 EXPECT_EQ(apnData.apnTypes, "");
1620 apnData.apnTypes = "hello";
1621 apnManager->ReportApnInfo(slotId, apnData);
1622 }
1623
1624 /**
1625 * @tc.number GetOverallApnState_001
1626 * @tc.name test function branch
1627 * @tc.desc Function test
1628 */
1629 HWTEST_F(ApnManagerTest, GetOverallApnState_001, TestSize.Level0)
1630 {
1631 sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
1632 static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
1633 apnHolder->apnState_ = ApnProfileState::PROFILE_STATE_FAILED;
1634 apnManager->apnHolders_.push_back(nullptr);
1635 apnManager->apnHolders_.push_back(apnHolder);
1636 auto result = apnManager->GetOverallApnState();
1637 EXPECT_EQ(result, ApnProfileState::PROFILE_STATE_FAILED);
1638 }
1639
1640 /**
1641 * @tc.number GetOverallDefaultApnState_001
1642 * @tc.name test function branch
1643 * @tc.desc Function test
1644 */
1645 HWTEST_F(ApnManagerTest, GetOverallDefaultApnState_001, TestSize.Level0)
1646 {
1647 sptr<ApnHolder> apnHolder = std::make_unique<ApnHolder>(DATA_CONTEXT_ROLE_DEFAULT,
1648 static_cast<int32_t>(DataContextPriority::PRIORITY_LOW)).release();
1649 apnHolder->apnState_ = ApnProfileState::PROFILE_STATE_FAILED;
1650 apnManager->apnHolders_.push_back(nullptr);
1651 apnManager->apnHolders_.push_back(apnHolder);
1652 auto result = apnManager->GetOverallDefaultApnState();
1653 EXPECT_EQ(result, ApnProfileState::PROFILE_STATE_IDLE);
1654 }
1655
1656 /**
1657 * @tc.number FindCapabilityByApnId_001
1658 * @tc.name test function branch
1659 * @tc.desc Function test
1660 */
1661 HWTEST_F(ApnManagerTest, FindCapabilityByApnId_001, TestSize.Level1)
1662 {
1663 uint64_t expected = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI1;
1664 int32_t apnId = DATA_CONTEXT_ROLE_SNSSAI1_ID;
1665 uint64_t actual = apnManager->FindCapabilityByApnId(apnId);
1666 EXPECT_EQ(actual, expected);
1667 expected = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI2;
1668 apnId = DATA_CONTEXT_ROLE_SNSSAI2_ID;
1669 actual = apnManager->FindCapabilityByApnId(apnId);
1670 EXPECT_EQ(actual, expected);
1671 expected = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI3;
1672 apnId = DATA_CONTEXT_ROLE_SNSSAI3_ID;
1673 actual = apnManager->FindCapabilityByApnId(apnId);
1674 EXPECT_EQ(actual, expected);
1675 expected = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI4;
1676 apnId = DATA_CONTEXT_ROLE_SNSSAI4_ID;
1677 actual = apnManager->FindCapabilityByApnId(apnId);
1678 EXPECT_EQ(actual, expected);
1679 expected = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI5;
1680 apnId = DATA_CONTEXT_ROLE_SNSSAI5_ID;
1681 actual = apnManager->FindCapabilityByApnId(apnId);
1682 EXPECT_EQ(actual, expected);
1683 expected = NetManagerStandard::NetCap::NET_CAPABILITY_SNSSAI6;
1684 apnId = DATA_CONTEXT_ROLE_SNSSAI6_ID;
1685 actual = apnManager->FindCapabilityByApnId(apnId);
1686 EXPECT_EQ(actual, expected);
1687 }
1688
1689 /**
1690 * @tc.number GetPreferId_001
1691 * @tc.name test function branch
1692 * @tc.desc Function test
1693 */
1694 HWTEST_F(ApnManagerTest, GetPreferId_001, TestSize.Level0)
1695 {
1696 int32_t slotId = 123;
1697 auto result = apnManager->GetPreferId(slotId);
1698 EXPECT_EQ(result, false);
1699 }
1700
CreateDcApnItemExtMock(int32_t slotId,sptr<ApnItem> & apnItem)1701 bool CreateDcApnItemExtMock(int32_t slotId, sptr<ApnItem> &apnItem)
1702 {
1703 return true;
1704 }
1705
1706 /**
1707 * @tc.number ApnItem_CreateAllApnItemByDatabaseTest_001
1708 * @tc.name test create dc apn item scene
1709 * @tc.desc Function test
1710 */
1711 HWTEST_F(ApnManagerTest, ApnItem_CreateAllApnItemByDatabaseTest_001, TestSize.Level0)
1712 {
1713 TELEPHONY_EXT_WRAPPER.createAllApnItemExt_ = nullptr;
1714 TELEPHONY_EXT_WRAPPER.createAllApnItemExt_ = CreateDcApnItemExtMock;
1715 int32_t result = apnManager->CreateAllApnItemByDatabase(0);
1716 EXPECT_EQ(result, 1);
1717 }
1718
1719 /**
1720 * @tc.number ApnItem_CreateAllApnItemByDatabaseTest_002
1721 * @tc.name test create normal apn item
1722 * @tc.desc Function test
1723 */
1724 HWTEST_F(ApnManagerTest, ApnItem_CreateAllApnItemByDatabaseTest_002, TestSize.Level0)
1725 {
1726 int32_t result = apnManager->CreateAllApnItemByDatabase(0);
1727 EXPECT_EQ(result, 1);
1728 }
1729 } // namespace Telephony
1730 } // namespace OHOS