• 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 "cellular_data_error.h"
19 #include "cellular_data_service.h"
20 #include "data_access_token.h"
21 #include "data_connection_monitor.h"
22 #include "gtest/gtest.h"
23 #include "tel_ril_network_parcel.h"
24 #include "traffic_management.h"
25 #include "apn_attribute.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 using namespace testing::ext;
30 
31 static const int32_t SLEEP_TIME = 3;
32 
33 class CellularDataServiceTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp();
38     void TearDown();
39     std::shared_ptr<CellularDataService> service = DelayedSingleton<CellularDataService>::GetInstance();
40 };
SetUpTestCase()41 void CellularDataServiceTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void CellularDataServiceTest::TearDownTestCase()
44 {
45     sleep(SLEEP_TIME);
46 }
47 
SetUp()48 void CellularDataServiceTest::SetUp() {}
49 
TearDown()50 void CellularDataServiceTest::TearDown() {}
51 
52 /**
53  * @tc.number   CellularDataService_001
54  * @tc.name     test function branch
55  * @tc.desc     Function test
56  */
57 HWTEST_F(CellularDataServiceTest, CellularDataService_001, TestSize.Level1)
58 {
59     DataAccessToken token;
60     service->OnStart();
61     service->isInitSuccess_ = true;
62     bool dataEnabled = false;
63     bool dataRoamingEnabled = false;
64     int32_t state;
65     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->IsCellularDataEnabled(dataEnabled));
66     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->EnableCellularData(false));
67     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->EnableCellularData(true));
68     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->EnableIntelligenceSwitch(false));
69     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->EnableIntelligenceSwitch(true));
70     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->GetCellularDataState(state));
71     ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->GetApnState(DEFAULT_SIM_SLOT_ID, std::string(), state));
72     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->IsCellularDataRoamingEnabled(DEFAULT_SIM_SLOT_ID, dataRoamingEnabled));
73     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->EnableCellularDataRoaming(DEFAULT_SIM_SLOT_ID, true));
74     NetRequest request;
75     request.ident = "simId12";
76     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->RequestNet(request));
77     request.ident = "simId2";
78     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->ReleaseNet(request));
79     auto event = AppExecFwk::InnerEvent::Get(0);
80     service->DispatchEvent(DEFAULT_SIM_SLOT_ID, event);
81     ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->HandleApnChanged(DEFAULT_SIM_SLOT_ID));
82 }
83 
84 /**
85  * @tc.number   CellularDataService_002
86  * @tc.name     test function branch
87  * @tc.desc     Function test
88  */
89 HWTEST_F(CellularDataServiceTest, CellularDataService_002, TestSize.Level1)
90 {
91     int32_t type;
92     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->GetCellularDataFlowType(type));
93     ASSERT_EQ("default slotId: -1", service->GetStateMachineCurrentStatusDump());
94     service->GetFlowDataInfoDump();
95     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->StrategySwitch(DEFAULT_SIM_SLOT_ID, false));
96     int32_t capability;
97     ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->HasInternetCapability(DEFAULT_SIM_SLOT_ID, 0, capability));
98     int32_t reason = static_cast<int32_t>(DisConnectionReason::REASON_NORMAL);
99     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->ClearAllConnections(DEFAULT_SIM_SLOT_ID, reason));
100     ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->ChangeConnectionForDsds(DEFAULT_SIM_SLOT_ID, false));
101     ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->ChangeConnectionForDsds(DEFAULT_SIM_SLOT_ID, true));
102     ApnAttribute apnAttr;
103     ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->GetDataConnApnAttr(DEFAULT_SIM_SLOT_ID, apnAttr));
104     std::string ipType;
105     ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->GetDataConnIpType(DEFAULT_SIM_SLOT_ID, ipType));
106     ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->IsNeedDoRecovery(DEFAULT_SIM_SLOT_ID, true));
107     uint32_t supplierId = 0;
108     ASSERT_EQ(TELEPHONY_ERR_PERMISSION_ERR,
109         service->GetCellularDataSupplierId(DEFAULT_SIM_SLOT_ID, NetCap::NET_CAPABILITY_INTERNET, supplierId));
110     ASSERT_EQ(TELEPHONY_ERR_PERMISSION_ERR,
111         service->GetCellularDataSupplierId(DEFAULT_SIM_SLOT_ID, NetCap::NET_CAPABILITY_END, supplierId));
112     service->CorrectNetSupplierNoAvailable(DEFAULT_SIM_SLOT_ID);
113     ASSERT_EQ(TELEPHONY_ERR_PERMISSION_ERR, service->EstablishAllApnsIfConnectable(DEFAULT_SIM_SLOT_ID));
114     int32_t slotId = 0;
115     std::vector<uint8_t> buffer = {};
116     ASSERT_EQ(TELEPHONY_ERR_LOCAL_PTR_NULL, service->SendUrspDecodeResult(slotId, buffer));
117     ASSERT_EQ(TELEPHONY_ERR_LOCAL_PTR_NULL, service->SendUePolicySectionIdentifier(slotId, buffer));
118     ASSERT_EQ(TELEPHONY_ERR_LOCAL_PTR_NULL, service->SendImsRsdList(slotId, buffer));
119     ASSERT_EQ(TELEPHONY_ERR_LOCAL_PTR_NULL, service->GetNetworkSliceAllowedNssai(slotId, buffer));
120     ASSERT_EQ(TELEPHONY_ERR_LOCAL_PTR_NULL, service->GetNetworkSliceEhplmn(slotId));
121     int32_t regState = -1;
122     service->GetSupplierRegisterState(supplierId, regState);
123     bool isSupportDun = false;
124     EXPECT_EQ(TELEPHONY_ERR_PERMISSION_ERR, service->GetIfSupportDunApn(isSupportDun));
125     service->OnStop();
126 }
127 
128 /**
129  * @tc.number   DataConnectionMonitor_HandleScreenStateChanged_001
130  * @tc.name     test function branch
131  * @tc.desc     Function test
132  */
133 HWTEST_F(CellularDataServiceTest, DataConnectionMonitor_HandleScreenStateChanged_001, TestSize.Level0)
134 {
135     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
136     dataConnectionMonitor->isScreenOn_ = false;
137     dataConnectionMonitor->HandleScreenStateChanged(true);
138     ASSERT_EQ(dataConnectionMonitor->isScreenOn_, true);
139     dataConnectionMonitor->isScreenOn_ = false;
140     dataConnectionMonitor->HandleScreenStateChanged(false);
141     ASSERT_EQ(dataConnectionMonitor->isScreenOn_, false);
142 }
143 
144 /**
145  * @tc.number   DataConnectionMonitor_OnStallDetectionTimer_001
146  * @tc.name     test function branch
147  * @tc.desc     Function test
148  */
149 HWTEST_F(CellularDataServiceTest, DataConnectionMonitor_OnStallDetectionTimer_001, TestSize.Level1)
150 {
151     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
152     dataConnectionMonitor->noRecvPackets_ = 20;
153     dataConnectionMonitor->stallDetectionEnabled_ = true;
154     dataConnectionMonitor->OnStallDetectionTimer();
155     ASSERT_EQ(dataConnectionMonitor->noRecvPackets_, 20);
156 }
157 
158 /**
159  * @tc.number   DataConnectionMonitor_HandleRecovery_001
160  * @tc.name     test function branch
161  * @tc.desc     Function test
162  */
163 HWTEST_F(CellularDataServiceTest, DataConnectionMonitor_HandleRecovery_001, TestSize.Level0)
164 {
165     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
166     dataConnectionMonitor->dataRecoveryState_ = RecoveryState::STATE_REQUEST_CONTEXT_LIST;
167     dataConnectionMonitor->HandleRecovery();
168     ASSERT_EQ(dataConnectionMonitor->dataRecoveryState_, RecoveryState::STATE_CLEANUP_CONNECTIONS);
169     dataConnectionMonitor->dataRecoveryState_ = RecoveryState::STATE_REREGISTER_NETWORK;
170     dataConnectionMonitor->HandleRecovery();
171     ASSERT_EQ(dataConnectionMonitor->dataRecoveryState_, RecoveryState::STATE_RADIO_STATUS_RESTART);
172     dataConnectionMonitor->dataRecoveryState_ = RecoveryState::STATE_RADIO_STATUS_RESTART;
173     dataConnectionMonitor->HandleRecovery();
174     ASSERT_EQ(dataConnectionMonitor->dataRecoveryState_, RecoveryState::STATE_REQUEST_CONTEXT_LIST);
175 }
176 
177 /**
178  * @tc.number   DataConnectionMonitor_EndNetStatistics_001
179  * @tc.name     test function branch
180  * @tc.desc     Function test
181  */
182 HWTEST_F(CellularDataServiceTest, DataConnectionMonitor_EndNetStatistics_001, TestSize.Level0)
183 {
184     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
185     dataConnectionMonitor->dataFlowType_ = CellDataFlowType::DATA_FLOW_TYPE_DOWN;
186     dataConnectionMonitor->EndNetStatistics();
187     ASSERT_EQ(dataConnectionMonitor->dataFlowType_, CellDataFlowType::DATA_FLOW_TYPE_NONE);
188 }
189 
190 /**
191  * @tc.number   DataConnectionMonitor_UpdateNetTrafficState_001
192  * @tc.name     test function branch
193  * @tc.desc     Function test
194  */
195 HWTEST_F(CellularDataServiceTest, DataConnectionMonitor_UpdateNetTrafficState_001, TestSize.Level0)
196 {
197     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
198     dataConnectionMonitor->updateNetStat_ = true;
199     dataConnectionMonitor->UpdateNetTrafficState();
200     std::shared_ptr<PreferredNetworkTypeInfo> preferredTypeInfo = std::make_shared<PreferredNetworkTypeInfo>();
201     auto event = AppExecFwk::InnerEvent::Get(0, preferredTypeInfo);
202     dataConnectionMonitor->SetPreferredNetworkPara(event);
203     ASSERT_EQ(dataConnectionMonitor->dataFlowType_, CellDataFlowType::DATA_FLOW_TYPE_NONE);
204 }
205 
206 /**
207  * @tc.number   DataConnectionMonitor_UpdateDataFlowType_001
208  * @tc.name     test function branch
209  * @tc.desc     Function test
210  */
211 HWTEST_F(CellularDataServiceTest, DataConnectionMonitor_UpdateDataFlowType_001, TestSize.Level0)
212 {
213     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
214     dataConnectionMonitor->dataFlowType_ = CellDataFlowType::DATA_FLOW_TYPE_DOWN;
215     dataConnectionMonitor->trafficManager_->sendPackets_ = 200;
216     dataConnectionMonitor->trafficManager_->recvPackets_ = 100;
217     dataConnectionMonitor->UpdateDataFlowType();
218     ASSERT_EQ(static_cast<int32_t>(dataConnectionMonitor->dataFlowType_),
219         static_cast<int32_t>(CellDataFlowType::DATA_FLOW_TYPE_NONE));
220 }
221 
222 /**
223  * @tc.number   DataConnectionMonitor_SetDataFlowType_001
224  * @tc.name     test function branch
225  * @tc.desc     Function test
226  */
227 HWTEST_F(CellularDataServiceTest, DataConnectionMonitor_SetDataFlowType_001, TestSize.Level0)
228 {
229     std::shared_ptr<DataConnectionMonitor> dataConnectionMonitor = std::make_shared<DataConnectionMonitor>(0);
230     auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_RUN_MONITOR_TASK);
231     dataConnectionMonitor->ProcessEvent(event);
232     event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_STALL_DETECTION_EVENT_ID);
233     dataConnectionMonitor->ProcessEvent(event);
234     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_DATA_CALL_LIST_CHANGED);
235     dataConnectionMonitor->ProcessEvent(event);
236     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_PREFERRED_NETWORK_MODE);
237     dataConnectionMonitor->ProcessEvent(event);
238     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_PREFERRED_NETWORK_MODE);
239     dataConnectionMonitor->ProcessEvent(event);
240     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_OFF);
241     dataConnectionMonitor->ProcessEvent(event);
242     event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_ON);
243     dataConnectionMonitor->ProcessEvent(event);
244     dataConnectionMonitor->dataFlowType_ = CellDataFlowType::DATA_FLOW_TYPE_NONE;
245     dataConnectionMonitor->SetDataFlowType(CellDataFlowType::DATA_FLOW_TYPE_DOWN);
246     ASSERT_EQ(static_cast<int32_t>(dataConnectionMonitor->dataFlowType_),
247         static_cast<int32_t>(CellDataFlowType::DATA_FLOW_TYPE_DOWN));
248 }
249 
250 /**
251  * @tc.number   CellularDataController_SetIntelligenceSwitchEnable_001
252  * @tc.name     test function branch
253  * @tc.desc     Function test
254  */
255 HWTEST_F(CellularDataServiceTest, CellularDataController_SetIntelligenceSwitchEnable_001, TestSize.Level0)
256 {
257     std::shared_ptr<CellularDataController> cellularDataController = std::make_shared<CellularDataController>(0);
258     cellularDataController->cellularDataHandler_ = nullptr;
259     int32_t result = cellularDataController->SetIntelligenceSwitchEnable(true);
260     ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
261 }
262 
263 /**
264  * @tc.number   CellularDataController_SetIntelligenceSwitchEnable_002
265  * @tc.name     test function branch
266  * @tc.desc     Function test
267  */
268 HWTEST_F(CellularDataServiceTest, CellularDataController_SetIntelligenceSwitchEnable_002, TestSize.Level0)
269 {
270     std::shared_ptr<CellularDataController> cellularDataController = std::make_shared<CellularDataController>(0);
271     cellularDataController->Init();
272     int32_t result = cellularDataController->SetIntelligenceSwitchEnable(false);
273     ASSERT_EQ(result, 0);
274 }
275 
276 /**
277  * @tc.number   CellularDataController_OnAddSystemAbility_001
278  * @tc.name     test function branch
279  * @tc.desc     Function test
280  */
281 HWTEST_F(CellularDataServiceTest, CellularDataController_OnAddSystemAbility_001, TestSize.Level0)
282 {
283     std::shared_ptr<CellularDataController> cellularDataController = std::make_shared<CellularDataController>(0);
284     cellularDataController->systemAbilityListener_ =
285         new (std::nothrow) CellularDataController::SystemAbilityStatusChangeListener(0, nullptr);
286     if (cellularDataController->systemAbilityListener_ != nullptr) {
287         cellularDataController->systemAbilityListener_->OnRemoveSystemAbility(
288             COMM_NET_CONN_MANAGER_SYS_ABILITY_ID, "");
289         cellularDataController->systemAbilityListener_->OnRemoveSystemAbility(
290             COMM_NET_POLICY_MANAGER_SYS_ABILITY_ID, "");
291         cellularDataController->systemAbilityListener_->OnRemoveSystemAbility(
292             DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, "");
293         cellularDataController->systemAbilityListener_->OnRemoveSystemAbility(-1, "");
294     }
295     ASSERT_EQ(cellularDataController->cellularDataHandler_, nullptr);
296 }
297 
298 /**
299  * @tc.number   RemoveUid_ShouldReturnInvalidParam_WhenIdentLengthLessThanIdentPreLen
300  * @tc.name     test function branch
301  * @tc.desc     Function test
302  */
303 HWTEST_F(CellularDataServiceTest, RemoveUid_WhenIdentLengthLessThanIdentPreLen, TestSize.Level1)
304 {
305     NetRequest request;
306     request.ident = "";
307     int32_t result = service->RemoveUid(request);
308     EXPECT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
309 }
310 
311 /**
312  * @tc.number   RemoveUid_ShouldReturnInvalidParam_WhenIdentIsNotValidDecValue
313  * @tc.name     test function branch
314  * @tc.desc     Function test
315  */
316 HWTEST_F(CellularDataServiceTest, RemoveUid_WhenIdentIsNotValidDecValue, TestSize.Level1)
317 {
318     NetRequest request;
319     request.ident = "simIdABC";
320     int32_t result = service->RemoveUid(request);
321     EXPECT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
322 }
323 
324 /**
325  * @tc.number   RemoveUid_ShouldReturnInvalidParam_WhenCellularDataControllerIsNull
326  * @tc.name     test function branch
327  * @tc.desc     Function test
328  */
329 HWTEST_F(CellularDataServiceTest, RemoveUid_WhenCellularDataControllerIsNull, TestSize.Level1)
330 {
331     NetRequest request;
332     request.ident = "simId1";
333     int32_t result = service->RemoveUid(request);
334     EXPECT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
335 }
336 
337 /**
338  * @tc.number   AddUid_ShouldReturnInvalidParam_WhenIdentLengthLessThanIdentPreLen
339  * @tc.name     test function branch
340  * @tc.desc     Function test
341  */
342 HWTEST_F(CellularDataServiceTest, AddUid_WhenIdentLengthLessThanIdentPreLen, TestSize.Level1)
343 {
344     NetRequest request;
345     request.ident = "";
346     int32_t result = service->AddUid(request);
347     EXPECT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
348 }
349 
350 /**
351  * @tc.number   AddUid_ShouldReturnInvalidParam_WhenIdentIsNotValidDecValue
352  * @tc.name     test function branch
353  * @tc.desc     Function test
354  */
355 HWTEST_F(CellularDataServiceTest, AddUid_WhenIdentIsNotValidDecValue, TestSize.Level1)
356 {
357     NetRequest request;
358     request.ident = "simIdABC";
359     int32_t result = service->AddUid(request);
360     EXPECT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
361 }
362 
363 /**
364  * @tc.number   AddUid_ShouldReturnInvalidParam_WhenCellularDataControllerIsNull
365  * @tc.name     test function branch
366  * @tc.desc     Function test
367  */
368 HWTEST_F(CellularDataServiceTest, AddUid_WhenCellularDataControllerIsNull, TestSize.Level1)
369 {
370     NetRequest request;
371     request.ident = "simId1";
372     int32_t result = service->AddUid(request);
373     EXPECT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
374 }
375 
376 /**
377  * @tc.number   RemoveOrAddUidTest001
378  * @tc.name     test function branch
379  * @tc.desc     Function test
380  */
381 HWTEST_F(CellularDataServiceTest, RemoveOrAddUidTest001, TestSize.Level0)
382 {
383     NetRequest request;
384     request.ident = "simId123456789123";
385     EXPECT_EQ(service->AddUid(request), CELLULAR_DATA_INVALID_PARAM);
386     EXPECT_EQ(service->RemoveUid(request), CELLULAR_DATA_INVALID_PARAM);
387     request.ident = "simId12";
388     EXPECT_EQ(service->AddUid(request), CELLULAR_DATA_INVALID_PARAM);
389     EXPECT_EQ(service->RemoveUid(request), CELLULAR_DATA_INVALID_PARAM);
390 }
391 
392 /**
393  * @tc.number   EstablishAllApnsIfConnectableTest001
394  * @tc.name     test function branch
395  * @tc.desc     Function test
396  */
397 HWTEST_F(CellularDataServiceTest, EstablishAllApnsIfConnectableTest001, TestSize.Level0)
398 {
399     int32_t slotId = -1;
400     EXPECT_EQ(service->EstablishAllApnsIfConnectable(slotId), TELEPHONY_ERR_PERMISSION_ERR);
401     EXPECT_EQ(service->ReleaseCellularDataConnection(slotId), TELEPHONY_ERR_PERMISSION_ERR);
402 }
403 
404 /**
405  * @tc.number   EstablishAllApnsIfConnectableTest002
406  * @tc.name     test function branch
407  * @tc.desc     Function test
408  */
409 HWTEST_F(CellularDataServiceTest, EstablishAllApnsIfConnectableTest002, TestSize.Level0)
410 {
411     DataAccessToken token;
412     int32_t slotId = -1;
413     EXPECT_EQ(service->EstablishAllApnsIfConnectable(slotId), CELLULAR_DATA_INVALID_PARAM);
414     EXPECT_EQ(service->ReleaseCellularDataConnection(slotId), CELLULAR_DATA_INVALID_PARAM);
415 }
416 
417 /**
418  * @tc.number   GetActReportInfoTest001
419  * @tc.name     test GetDefaultActReportInfo and GetInternalActReportInfo
420  * @tc.desc     Function test
421  */
422 HWTEST_F(CellularDataServiceTest, GetActReportInfoTest001, TestSize.Level0)
423 {
424     ApnActivateReportInfoIpc infoIpc;
425     int32_t slotId = -1;
426     EXPECT_EQ(service->GetDefaultActReportInfo(slotId, infoIpc), TELEPHONY_ERR_PERMISSION_ERR);
427     EXPECT_EQ(service->GetInternalActReportInfo(slotId, infoIpc), TELEPHONY_ERR_PERMISSION_ERR);
428 }
429 
430 /**
431  * @tc.number   GetActReportInfoTest002
432  * @tc.name     test GetDefaultActReportInfo and GetInternalActReportInfo
433  * @tc.desc     Function test
434  */
435 HWTEST_F(CellularDataServiceTest, GetActReportInfoTest002, TestSize.Level0)
436 {
437     DataAccessToken token;
438     ApnActivateReportInfoIpc infoIpc;
439     int32_t slotId = -1;
440     EXPECT_EQ(service->GetDefaultActReportInfo(slotId, infoIpc), CELLULAR_DATA_INVALID_PARAM);
441     EXPECT_EQ(service->GetInternalActReportInfo(slotId, infoIpc), CELLULAR_DATA_INVALID_PARAM);
442 }
443 
444 /**
445  * @tc.number   ApnInfoTest001
446  * @tc.name     test QueryApnIds, SetPreferApn and QueryAllApnInfo
447  * @tc.desc     Function test
448  */
449 HWTEST_F(CellularDataServiceTest, ApnInfoTest001, TestSize.Level0)
450 {
451     ApnInfo apnInfo;
452     std::vector<uint32_t> apnIdList;
453     std::vector<ApnInfo> allApnInfoList;
454     int32_t apnId = 1;
455     EXPECT_EQ(service->QueryApnIds(apnInfo, apnIdList), TELEPHONY_ERR_PERMISSION_ERR);
456     EXPECT_EQ(service->SetPreferApn(apnId), TELEPHONY_ERR_PERMISSION_ERR);
457     EXPECT_EQ(service->QueryAllApnInfo(allApnInfoList), TELEPHONY_ERR_PERMISSION_ERR);
458 }
459 
460 /**
461  * @tc.number   ApnInfoTest002
462  * @tc.name     test QueryApnIds, SetPreferApn and QueryAllApnInfo
463  * @tc.desc     Function test
464  */
465 HWTEST_F(CellularDataServiceTest, ApnInfoTest002, TestSize.Level0)
466 {
467     DataAccessToken token;
468     ApnInfo apnInfo;
469     std::vector<uint32_t> apnIdList;
470     std::vector<ApnInfo> allApnInfoList;
471     int32_t apnId = 1;
472     EXPECT_EQ(service->QueryApnIds(apnInfo, apnIdList), 0);
473     EXPECT_EQ(service->SetPreferApn(apnId), -1);
474     EXPECT_EQ(service->QueryAllApnInfo(allApnInfoList), 0);
475 }
476 
477 /**
478  * @tc.number   GetActiveApnName001
479  * @tc.name     test GetActiveApnName
480  * @tc.desc     Function test
481  */
482 HWTEST_F(CellularDataServiceTest, GetActiveApnName001, TestSize.Level0)
483 {
484     std::string apnName;
485     EXPECT_EQ(service->GetActiveApnName(apnName), TELEPHONY_ERR_PERMISSION_ERR);
486 }
487 
488 /**
489  * @tc.number   GetActiveApnName002
490  * @tc.name     test GetActiveApnName
491  * @tc.desc     Function test
492  */
493 HWTEST_F(CellularDataServiceTest, GetActiveApnName002, TestSize.Level0)
494 {
495     DataAccessToken token;
496     std::string apnName;
497     EXPECT_EQ(service->GetActiveApnName(apnName), 0);
498 }
499 
500 /**
501  * @tc.number   ReleaseNet_001
502  * @tc.name     test function branch
503  * @tc.desc     Function test
504  */
505 HWTEST_F(CellularDataServiceTest, ReleaseNet_001, TestSize.Level1)
506 {
507     NetRequest request;
508     request.ident = "1";
509     ASSERT_EQ(CELLULAR_DATA_INVALID_PARAM, service->RequestNet(request));
510     ASSERT_EQ(CELLULAR_DATA_INVALID_PARAM, service->ReleaseNet(request));
511 }
512 } // namespace Telephony
513 } // namespace OHOS