1 /*
2  * Copyright (C) 2021 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 
16 #include <cstdint>
17 #include <string>
18 
19 #define private public
20 #include <gtest/gtest.h>
21 
22 #include "cellular_data_client.h"
23 #include "cellular_data_error.h"
24 #include "cellular_data_service.h"
25 #include "cellular_data_types.h"
26 #include "core_service_client.h"
27 #include "data_access_token.h"
28 #include "gtest/gtest-message.h"
29 #include "gtest/gtest-test-part.h"
30 #include "gtest/gtest_pred_impl.h"
31 #include "gtest/hwext/gtest-tag.h"
32 #include "hap_token_info.h"
33 #include "i_cellular_data_manager.h"
34 #include "iosfwd"
35 #include "iostream"
36 #include "net_conn_callback_stub.h"
37 #include "net_supplier_callback_base.h"
38 #include "net_conn_client.h"
39 #include "net_handle.h"
40 #include "net_specifier.h"
41 #include "ostream"
42 #include "permission_def.h"
43 #include "permission_state_full.h"
44 #include "refbase.h"
45 #include "telephony_ext_wrapper.h"
46 #include "telephony_types.h"
47 #include "token_setproc.h"
48 #include "unistd.h"
49 #include "apn_item.h"
50 #include "cellular_data_constant.h"
51 
52 namespace OHOS {
53 namespace Telephony {
54 using namespace testing::ext;
55 using namespace OHOS::NetManagerStandard;
56 
57 static const int32_t SLEEP_TIME = 1;
58 static const int32_t SIM_SLOT_ID_1 = DEFAULT_SIM_SLOT_ID + 1;
59 static const int32_t DATA_SLOT_ID_INVALID = DEFAULT_SIM_SLOT_ID + 10;
60 static const int32_t PING_CHECK_SUCCESS = 0;
61 static const int32_t PING_CHECK_FAIL = 1;
62 static const int32_t MAX_TIMES = 60;
63 static const int32_t CMD_BUF_SIZE = 10240;
64 static const int32_t NET_REGISTER_TIMEOUT_MS = 20000;
65 
66 class TestCallback : public NetManagerStandard::NetConnCallbackStub {
NetAvailable(sptr<NetManagerStandard::NetHandle> & netHandle)67     int32_t NetAvailable(sptr<NetManagerStandard::NetHandle> &netHandle) override
68     {
69         isCallback_ = true;
70         std::cout << "TestCallback::NetAvailable" << std::endl;
71         return 0;
72     }
73 
NetCapabilitiesChange(sptr<NetManagerStandard::NetHandle> & netHandle,const sptr<NetManagerStandard::NetAllCapabilities> & netAllCap)74     int32_t NetCapabilitiesChange(sptr<NetManagerStandard::NetHandle> &netHandle,
75         const sptr<NetManagerStandard::NetAllCapabilities> &netAllCap) override
76     {
77         isCallback_ = true;
78         std::cout << "TestCallback::NetCapabilitiesChange" << std::endl;
79         return 0;
80     }
81 
NetConnectionPropertiesChange(sptr<NetManagerStandard::NetHandle> & netHandle,const sptr<NetManagerStandard::NetLinkInfo> & info)82     int32_t NetConnectionPropertiesChange(
83         sptr<NetManagerStandard::NetHandle> &netHandle, const sptr<NetManagerStandard::NetLinkInfo> &info) override
84     {
85         isCallback_ = true;
86         std::cout << "TestCallback::NetConnectionPropertiesChange" << std::endl;
87         return 0;
88     }
89 
NetLost(sptr<NetManagerStandard::NetHandle> & netHandle)90     int32_t NetLost(sptr<NetManagerStandard::NetHandle> &netHandle) override
91     {
92         isCallback_ = true;
93         std::cout << "TestCallback::NetLost" << std::endl;
94         return 0;
95     }
96 
NetUnavailable()97     int32_t NetUnavailable() override
98     {
99         isCallback_ = true;
100         std::cout << "TestCallback::NetUnavailable" << std::endl;
101         return 0;
102     }
103 
NetBlockStatusChange(sptr<NetManagerStandard::NetHandle> & netHandle,bool blocked)104     int32_t NetBlockStatusChange(sptr<NetManagerStandard::NetHandle> &netHandle, bool blocked) override
105     {
106         isCallback_ = true;
107         std::cout << "TestCallback::NetBlockStatusChange" << std::endl;
108         return 0;
109     }
110 
111 public:
112     bool isCallback_ = false;
113 };
114 
115 class CellularDataTest : public testing::Test {
116 public:
117     static void SetUpTestCase();
118     static void TearDownTestCase();
119     virtual void SetUp();
120     virtual void TearDown();
121     static bool HasSimCard(const int32_t slotId);
122     static int32_t IsCellularDataEnabledTest(bool &dataEnabled);
123     static int32_t EnableCellularDataTest(bool enable);
124     static int32_t EnableIntelligenceSwitchTest(bool enable);
125     static int32_t GetCellularDataStateTest();
126     static int32_t IsCellularDataRoamingEnabledTest(int32_t slotId, bool &dataRoamingEnabled);
127     static int32_t EnableCellularDataRoamingTest(int32_t slotId, bool enable);
128     static int32_t GetDefaultCellularDataSlotIdTest();
129     static int32_t GetDefaultCellularDataSimIdTest();
130     static int32_t SetDefaultCellularDataSlotIdTest(int32_t slotId);
131     static int32_t GetCellularDataFlowTypeTest();
132     static void WaitTestTimeout(const int32_t status);
133     static sptr<ICellularDataManager> GetProxy();
134     static string GetCmdResult();
135     static int32_t PingTest();
136     static int32_t HasInternetCapability(int32_t slotId, int32_t cid);
137     static int32_t ClearCellularDataConnections(int32_t slotId);
138     static int32_t ClearAllConnections(int32_t slotId, DisConnectionReason reason);
139     static int32_t GetApnState(int32_t slotId, const std::string &apnTyp);
140     static int32_t GetDataRecoveryState();
141     static int32_t GetDataConnApnAttr(int32_t slotId, ApnItem::Attribute &apnAttr);
142     static int32_t GetDataConnIpType(int32_t slotId, std::string &ipType);
143     static int32_t IsNeedDoRecovery(int32_t slotId, bool needDoRecovery);
144     static int32_t InitCellularDataController(int32_t slotId);
145     static int32_t GetIntelligenceSwitchStateTest(bool &state);
146     sptr<NetManagerCallBack> callback_ = nullptr;
147     sptr<NetManagerTacticsCallBack> tacticsCallBack_;
148 };
149 
HasSimCard(const int32_t slotId)150 bool CellularDataTest::HasSimCard(const int32_t slotId)
151 {
152     bool hasSimCard = false;
153     DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
154     return hasSimCard;
155 }
156 
TearDownTestCase()157 void CellularDataTest::TearDownTestCase()
158 {
159     if (CoreServiceClient::GetInstance().GetProxy() == nullptr) {
160         std::cout << "connect coreService server failed!" << std::endl;
161         return;
162     }
163     DataAccessToken token;
164     int32_t slotId = DATA_SLOT_ID_INVALID;
165     if (HasSimCard(DEFAULT_SIM_SLOT_ID)) {
166         slotId = DEFAULT_SIM_SLOT_ID;
167     } else if (HasSimCard(SIM_SLOT_ID_1)) {
168         slotId = SIM_SLOT_ID_1;
169     }
170     if (slotId == DATA_SLOT_ID_INVALID) {
171         return;
172     }
173     // Set the default slot
174     int32_t result = CellularDataClient::GetInstance().SetDefaultCellularDataSlotId(slotId);
175     if (result != TELEPHONY_ERR_SUCCESS) {
176         return;
177     }
178     int32_t enable = CellularDataClient::GetInstance().EnableCellularData(true);
179     ASSERT_TRUE(enable == TELEPHONY_ERR_SUCCESS);
180     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
181 }
182 
SetUp()183 void CellularDataTest::SetUp() {}
184 
TearDown()185 void CellularDataTest::TearDown() {}
186 
SetUpTestCase()187 void CellularDataTest::SetUpTestCase()
188 {
189     if (CoreServiceClient::GetInstance().GetProxy() == nullptr) {
190         std::cout << "connect coreService server failed!" << std::endl;
191         return;
192     }
193     DataAccessToken token;
194     int32_t slotId = DATA_SLOT_ID_INVALID;
195     if (HasSimCard(DEFAULT_SIM_SLOT_ID)) {
196         slotId = DEFAULT_SIM_SLOT_ID;
197     } else if (HasSimCard(SIM_SLOT_ID_1)) {
198         slotId = SIM_SLOT_ID_1;
199     }
200     if (slotId == DATA_SLOT_ID_INVALID) {
201         return;
202     }
203     // Set the default slot
204     int32_t result = CellularDataClient::GetInstance().SetDefaultCellularDataSlotId(slotId);
205     if (result != TELEPHONY_ERR_SUCCESS) {
206         return;
207     }
208     int32_t enable = CellularDataClient::GetInstance().EnableCellularData(true);
209     ASSERT_TRUE(enable == TELEPHONY_ERR_SUCCESS);
210     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
211 }
212 
WaitTestTimeout(const int32_t status)213 void CellularDataTest::WaitTestTimeout(const int32_t status)
214 {
215     int32_t count = 0;
216     while (count < MAX_TIMES) {
217         sleep(SLEEP_TIME);
218         if (CellularDataClient::GetInstance().GetCellularDataState() == status) {
219             return;
220         }
221         count++;
222     }
223 }
224 
GetCmdResult()225 string CellularDataTest::GetCmdResult()
226 {
227     string strCmd = "ping -c3 www.openharmony.cn";
228     char buf[CMD_BUF_SIZE] = { 0 };
229     FILE *pf;
230 
231     if ((pf = popen(strCmd.c_str(), "r")) == nullptr) {
232         return "";
233     }
234     string strResult;
235     while (fgets(buf, sizeof(buf), pf) != nullptr) {
236         strResult += buf;
237     }
238     pclose(pf);
239     unsigned int iSize = strResult.size();
240     if (iSize > 0 && strResult[iSize - 1] == '\n') {
241         strResult = strResult.substr(0, iSize - 1);
242     }
243     return strResult;
244 }
245 
PingTest()246 int32_t CellularDataTest::PingTest()
247 {
248     string strRe = GetCmdResult();
249     std::cout << strRe << std::endl;
250 
251     // if ping succeed, the result should contains something like:
252     // 3 packets transmitted, 3 received, 0% packet loss, time 5440ms
253     if (strRe.find("3 packets") != string::npos) {
254         return PING_CHECK_SUCCESS;
255     } else {
256         return PING_CHECK_FAIL;
257     }
258 }
259 
IsCellularDataRoamingEnabledTest(int32_t slotId,bool & dataRoamingEnabled)260 int32_t CellularDataTest::IsCellularDataRoamingEnabledTest(int32_t slotId, bool &dataRoamingEnabled)
261 {
262     return CellularDataClient::GetInstance().IsCellularDataRoamingEnabled(slotId, dataRoamingEnabled);
263 }
264 
IsCellularDataEnabledTest(bool & dataEnabled)265 int32_t CellularDataTest::IsCellularDataEnabledTest(bool &dataEnabled)
266 {
267     return CellularDataClient::GetInstance().IsCellularDataEnabled(dataEnabled);
268 }
269 
EnableCellularDataTest(bool enable)270 int32_t CellularDataTest::EnableCellularDataTest(bool enable)
271 {
272     return CellularDataClient::GetInstance().EnableCellularData(enable);
273 }
274 
EnableIntelligenceSwitchTest(bool enable)275 int32_t CellularDataTest::EnableIntelligenceSwitchTest(bool enable)
276 {
277     return CellularDataClient::GetInstance().EnableIntelligenceSwitch(enable);
278 }
279 
GetCellularDataStateTest()280 int32_t CellularDataTest::GetCellularDataStateTest()
281 {
282     return CellularDataClient::GetInstance().GetCellularDataState();
283 }
284 
GetIntelligenceSwitchStateTest(bool & state)285 int32_t CellularDataTest::GetIntelligenceSwitchStateTest(bool &state)
286 {
287     return CellularDataClient::GetInstance().GetIntelligenceSwitchState(state);
288 }
289 
EnableCellularDataRoamingTest(int32_t slotId,bool enable)290 int32_t CellularDataTest::EnableCellularDataRoamingTest(int32_t slotId, bool enable)
291 {
292     return CellularDataClient::GetInstance().EnableCellularDataRoaming(slotId, enable);
293 }
294 
GetDefaultCellularDataSlotIdTest()295 int32_t CellularDataTest::GetDefaultCellularDataSlotIdTest()
296 {
297     return CellularDataClient::GetInstance().GetDefaultCellularDataSlotId();
298 }
299 
GetDefaultCellularDataSimIdTest()300 int32_t CellularDataTest::GetDefaultCellularDataSimIdTest()
301 {
302     int32_t simId = 0;
303     return CellularDataClient::GetInstance().GetDefaultCellularDataSimId(simId);
304 }
305 
SetDefaultCellularDataSlotIdTest(int32_t slotId)306 int32_t CellularDataTest::SetDefaultCellularDataSlotIdTest(int32_t slotId)
307 {
308     return CellularDataClient::GetInstance().SetDefaultCellularDataSlotId(slotId);
309 }
310 
GetCellularDataFlowTypeTest()311 int32_t CellularDataTest::GetCellularDataFlowTypeTest()
312 {
313     return CellularDataClient::GetInstance().GetCellularDataFlowType();
314 }
315 
HasInternetCapability(int32_t slotId,int32_t cid)316 int32_t CellularDataTest::HasInternetCapability(int32_t slotId, int32_t cid)
317 {
318     CellularDataClient::GetInstance().IsConnect();
319     return CellularDataClient::GetInstance().HasInternetCapability(slotId, cid);
320 }
321 
ClearCellularDataConnections(int32_t slotId)322 int32_t CellularDataTest::ClearCellularDataConnections(int32_t slotId)
323 {
324     CellularDataClient::GetInstance().IsConnect();
325     return CellularDataClient::GetInstance().ClearCellularDataConnections(slotId);
326 }
327 
ClearAllConnections(int32_t slotId,DisConnectionReason reason)328 int32_t CellularDataTest::ClearAllConnections(int32_t slotId, DisConnectionReason reason)
329 {
330     return CellularDataClient::GetInstance().ClearAllConnections(slotId, reason);
331 }
332 
GetApnState(int32_t slotId,const std::string & apnTyp)333 int32_t CellularDataTest::GetApnState(int32_t slotId, const std::string &apnTyp)
334 {
335     return CellularDataClient::GetInstance().GetApnState(slotId, apnTyp);
336 }
337 
GetDataRecoveryState()338 int32_t CellularDataTest::GetDataRecoveryState()
339 {
340     return CellularDataClient::GetInstance().GetDataRecoveryState();
341 }
342 
GetDataConnApnAttr(int32_t slotId,ApnItem::Attribute & apnAttr)343 int32_t CellularDataTest::GetDataConnApnAttr(int32_t slotId, ApnItem::Attribute &apnAttr)
344 {
345     return CellularDataClient::GetInstance().GetDataConnApnAttr(slotId, apnAttr);
346 }
347 
GetDataConnIpType(int32_t slotId,std::string & ipType)348 int32_t CellularDataTest::GetDataConnIpType(int32_t slotId, std::string &ipType)
349 {
350     return CellularDataClient::GetInstance().GetDataConnIpType(slotId, ipType);
351 }
352 
IsNeedDoRecovery(int32_t slotId,bool needDoRecovery)353 int32_t CellularDataTest::IsNeedDoRecovery(int32_t slotId, bool needDoRecovery)
354 {
355     return CellularDataClient::GetInstance().IsNeedDoRecovery(slotId, needDoRecovery);
356 }
357 
InitCellularDataController(int32_t slotId)358 int32_t CellularDataTest::InitCellularDataController(int32_t slotId)
359 {
360     return CellularDataClient::GetInstance().InitCellularDataController(slotId);
361 }
362 #ifndef TEL_TEST_UNSUPPORT
363 /**
364  * @tc.number   IsCellularDataEnabled_Test
365  * @tc.name     Test cellular data switch status(enabled or disabled)
366  * @tc.desc     Function test
367  */
368 HWTEST_F(CellularDataTest, IsCellularDataEnabled_Test, TestSize.Level1)
369 {
370     DataAccessToken token;
371     bool dataEnabled = false;
372     CellularDataTest::IsCellularDataEnabledTest(dataEnabled);
373     ASSERT_TRUE(dataEnabled >= static_cast<int32_t>(DataSwitchCode::CELLULAR_DATA_DISABLED));
374 }
375 
376 /**
377  * @tc.number   DefaultCellularDataSlotId_Test
378  * @tc.name     Test set default data card slot
379  * @tc.desc     Function test
380  */
381 HWTEST_F(CellularDataTest, DefaultCellularDataSlotId_Test, TestSize.Level2)
382 {
383     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
384         return;
385     }
386     DataAccessToken token;
387     int32_t result = CellularDataTest::GetDefaultCellularDataSlotIdTest();
388     if (result < DEFAULT_SIM_SLOT_ID_REMOVE) {
389         return;
390     }
391     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
392     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
393     // Multiple cards will need to be optimized again
394     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID - 1);
395     ASSERT_TRUE(result != TELEPHONY_ERR_SUCCESS);
396     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(DATA_SLOT_ID_INVALID);
397     ASSERT_TRUE(result != TELEPHONY_ERR_SUCCESS);
398 }
399 
400 /**
401  * @tc.number   GetDefaultCellularDataSimId
402  * @tc.name     Test get default data sim id
403  * @tc.desc     Function test
404  */
405 HWTEST_F(CellularDataTest, DefaultCellularDataSimId_Test, TestSize.Level2)
406 {
407     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
408         return;
409     }
410     int32_t result = CellularDataTest::GetDefaultCellularDataSimIdTest();
411     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
412 }
413 
414 /**
415  * @tc.number   DefaultCellularDataSlotId_Test_01
416  * @tc.name     Test set default data card slot
417  * @tc.desc     Function test
418  */
419 HWTEST_F(CellularDataTest, DefaultCellularDataSlotId_Test_01, TestSize.Level2)
420 {
421     if (!HasSimCard(SIM_SLOT_ID_1)) {
422         return;
423     }
424     DataAccessToken token;
425     int32_t result = CellularDataTest::GetDefaultCellularDataSlotIdTest();
426     if (result < DEFAULT_SIM_SLOT_ID_REMOVE) {
427         return;
428     }
429     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(SIM_SLOT_ID_1);
430     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
431     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(DATA_SLOT_ID_INVALID);
432     ASSERT_TRUE(result != TELEPHONY_ERR_SUCCESS);
433 }
434 
435 /**
436  * @tc.number   EnableCellularData_Test_01
437  * @tc.name     Test cellular data switch
438  * @tc.desc     Function test
439  */
440 HWTEST_F(CellularDataTest, EnableCellularData_Test_01, TestSize.Level2)
441 {
442     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
443         return;
444     }
445     DataAccessToken token;
446     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
447     CellularDataTest::EnableCellularDataTest(false);
448     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
449     sleep(SLEEP_TIME);
450     int32_t result = CellularDataTest::EnableCellularDataTest(true);
451     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
452     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
453     sleep(SLEEP_TIME);
454     std::cout << "Cellular Data Connected Ping..." << std::endl;
455     int32_t pingResult = CellularDataTest::PingTest();
456     ASSERT_TRUE(pingResult >= PING_CHECK_SUCCESS);
457     CellularDataTest::EnableCellularDataTest(false);
458     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
459     sleep(SLEEP_TIME);
460     std::cout << "Cellular Data Disconnected Ping..." << std::endl;
461     pingResult = CellularDataTest::PingTest();
462     ASSERT_TRUE(pingResult == PING_CHECK_FAIL);
463 }
464 
465 /**
466  * @tc.number   EnableCellularData_Test_02
467  * @tc.name     Test cellular data switch
468  * @tc.desc     Function test
469  */
470 HWTEST_F(CellularDataTest, EnableCellularData_Test_02, TestSize.Level2)
471 {
472     if (!HasSimCard(SIM_SLOT_ID_1)) {
473         return;
474     }
475     DataAccessToken token;
476     CellularDataTest::SetDefaultCellularDataSlotIdTest(SIM_SLOT_ID_1);
477     CellularDataTest::EnableCellularDataTest(false);
478     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
479     sleep(SLEEP_TIME);
480     int32_t result = CellularDataTest::EnableCellularDataTest(true);
481     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
482     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
483     sleep(SLEEP_TIME);
484     std::cout << "Cellular Data Connected Ping..." << std::endl;
485     int32_t pingResult = CellularDataTest::PingTest();
486     ASSERT_TRUE(pingResult >= PING_CHECK_SUCCESS);
487     CellularDataTest::EnableCellularDataTest(false);
488     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
489     sleep(SLEEP_TIME);
490     std::cout << "Cellular Data Disconnected Ping..." << std::endl;
491     pingResult = CellularDataTest::PingTest();
492     ASSERT_TRUE(pingResult == PING_CHECK_FAIL);
493 }
494 
495 /**
496  * @tc.number   DataRoamingState_ValidSlot_Test_01
497  * @tc.name     Test the cellular data roaming switch with a slot id
498  * @tc.desc     Function test
499  */
500 HWTEST_F(CellularDataTest, DataRoamingState_ValidSlot_Test_01, TestSize.Level3)
501 {
502     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
503         return;
504     }
505     DataAccessToken token;
506     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
507     int32_t disabled = CellularDataTest::EnableCellularDataTest(false);
508     ASSERT_TRUE(disabled == TELEPHONY_ERR_SUCCESS);
509     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
510 
511     // slot0 enable data roaming
512     int32_t enabled = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, true);
513     ASSERT_TRUE(enabled == TELEPHONY_ERR_SUCCESS);
514     bool dataRoamingEnabled = false;
515     CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID, dataRoamingEnabled);
516     ASSERT_TRUE(dataRoamingEnabled);
517     // slot0 close
518     int32_t enable = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, false);
519     ASSERT_TRUE(enable == TELEPHONY_ERR_SUCCESS);
520     CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID, dataRoamingEnabled);
521     ASSERT_TRUE(!dataRoamingEnabled);
522 
523     // At present, multiple card problems, the subsequent need to continue to deal with
524     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
525     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
526     int32_t result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID, dataRoamingEnabled);
527     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
528     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
529     // At present, multiple card problems, the subsequent need to continue to deal with
530     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
531     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID, dataRoamingEnabled);
532     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
533 }
534 
535 /**
536  * @tc.number   DataRoamingState_ValidSlot_Test_02
537  * @tc.name     Test the cellular data roaming switch with a slot id
538  * @tc.desc     Function test
539  */
540 HWTEST_F(CellularDataTest, DataRoamingState_ValidSlot_Test_02, TestSize.Level3)
541 {
542     if (!HasSimCard(SIM_SLOT_ID_1)) {
543         return;
544     }
545     DataAccessToken token;
546     CellularDataTest::SetDefaultCellularDataSlotIdTest(SIM_SLOT_ID_1);
547     int32_t disabled = CellularDataTest::EnableCellularDataTest(false);
548     ASSERT_TRUE(disabled == TELEPHONY_ERR_SUCCESS);
549     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
550 
551     // slot1 enable data roaming
552     int32_t enabled = CellularDataTest::EnableCellularDataRoamingTest(SIM_SLOT_ID_1, true);
553     ASSERT_TRUE(enabled == TELEPHONY_ERR_SUCCESS);
554     bool dataRoamingEnabled = false;
555     CellularDataTest::IsCellularDataRoamingEnabledTest(SIM_SLOT_ID_1, dataRoamingEnabled);
556     ASSERT_TRUE(dataRoamingEnabled);
557     // slot1 close
558     int32_t enable = CellularDataTest::EnableCellularDataRoamingTest(SIM_SLOT_ID_1, false);
559     ASSERT_TRUE(enable == TELEPHONY_ERR_SUCCESS);
560     CellularDataTest::IsCellularDataRoamingEnabledTest(SIM_SLOT_ID_1, dataRoamingEnabled);
561     ASSERT_TRUE(!dataRoamingEnabled);
562 
563     // At present, multiple card problems, the subsequent need to continue to deal with
564     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
565     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
566     int32_t result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID, dataRoamingEnabled);
567     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
568     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
569     // At present, multiple card problems, the subsequent need to continue to deal with
570     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
571     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID, dataRoamingEnabled);
572     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
573 }
574 
575 /**
576  * @tc.number   EnableCellularDataRoaming_ValidSlot_Test_01
577  * @tc.name     Test the cellular data roaming switch with a slot id
578  * @tc.desc     Function test
579  */
580 HWTEST_F(CellularDataTest, EnableCellularDataRoaming_ValidSlot_Test_01, TestSize.Level3)
581 {
582     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
583         return;
584     }
585     DataAccessToken token;
586     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
587     int32_t disabled = CellularDataTest::EnableCellularDataTest(false);
588     ASSERT_TRUE(disabled == TELEPHONY_ERR_SUCCESS);
589     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
590 
591     bool dataRoamingEnabled = false;
592     CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID, dataRoamingEnabled);
593     if (dataRoamingEnabled) {
594         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, false);
595         ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
596     } else {
597         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, true);
598         ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
599     }
600     // At present, multiple card problems, the subsequent need to continue to deal with
601     CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID, dataRoamingEnabled);
602     if (dataRoamingEnabled) {
603         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
604         ASSERT_TRUE(result != TELEPHONY_ERR_SUCCESS);
605     } else {
606         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
607         ASSERT_TRUE(result != TELEPHONY_ERR_SUCCESS);
608     }
609 }
610 
611 /**
612  * @tc.number   EnableCellularDataRoaming_ValidSlot_Test_02
613  * @tc.name     Test the cellular data roaming switch with a slot id
614  * @tc.desc     Function test
615  */
616 HWTEST_F(CellularDataTest, EnableCellularDataRoaming_ValidSlot_Test_02, TestSize.Level3)
617 {
618     if (!HasSimCard(SIM_SLOT_ID_1)) {
619         return;
620     }
621     DataAccessToken token;
622     CellularDataTest::SetDefaultCellularDataSlotIdTest(SIM_SLOT_ID_1);
623     int32_t disabled = CellularDataTest::EnableCellularDataTest(false);
624     ASSERT_TRUE(disabled == TELEPHONY_ERR_SUCCESS);
625     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
626 
627     bool dataRoamingEnabled = false;
628     CellularDataTest::IsCellularDataRoamingEnabledTest(SIM_SLOT_ID_1, dataRoamingEnabled);
629     if (dataRoamingEnabled) {
630         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(SIM_SLOT_ID_1, false);
631         ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
632     } else {
633         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(SIM_SLOT_ID_1, true);
634         ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
635     }
636     // At present, multiple card problems, the subsequent need to continue to deal with
637     CellularDataTest::IsCellularDataRoamingEnabledTest(SIM_SLOT_ID_1, dataRoamingEnabled);
638     if (dataRoamingEnabled) {
639         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
640         ASSERT_TRUE(result != TELEPHONY_ERR_SUCCESS);
641     } else {
642         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
643         ASSERT_TRUE(result != TELEPHONY_ERR_SUCCESS);
644     }
645 }
646 
647 /**
648  * @tc.number   GetCellularDataState_ValidityTest_01
649  * @tc.name     Test the GetCellularDataState function
650  * @tc.desc     Function test
651  */
652 HWTEST_F(CellularDataTest, GetCellularDataState_ValidityTest_01, TestSize.Level3)
653 {
654     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
655         return;
656     }
657     DataAccessToken token;
658     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
659     bool dataEnabled = false;
660     CellularDataTest::IsCellularDataEnabledTest(dataEnabled);
661     if (dataEnabled) {
662         CellularDataTest::EnableCellularDataTest(false);
663         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
664         sleep(SLEEP_TIME);
665         CellularDataTest::EnableCellularDataTest(true);
666         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
667         int32_t result = CellularDataTest::GetCellularDataStateTest();
668         ASSERT_TRUE(result == static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
669     } else {
670         CellularDataTest::EnableCellularDataTest(true);
671         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
672         sleep(SLEEP_TIME);
673         CellularDataTest::EnableCellularDataTest(false);
674         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
675         int32_t result = CellularDataTest::GetCellularDataStateTest();
676         ASSERT_TRUE(result == static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
677     }
678     CellularDataTest::EnableCellularDataTest(false);
679     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
680 }
681 
682 /**
683  * @tc.number   GetCellularDataState_ValidityTest_02
684  * @tc.name     Test the GetCellularDataState function
685  * @tc.desc     Function test
686  */
687 HWTEST_F(CellularDataTest, GetCellularDataState_ValidityTest_02, TestSize.Level3)
688 {
689     if (!HasSimCard(SIM_SLOT_ID_1)) {
690         return;
691     }
692     DataAccessToken token;
693     CellularDataTest::SetDefaultCellularDataSlotIdTest(SIM_SLOT_ID_1);
694     bool dataEnabled = false;
695     CellularDataTest::IsCellularDataEnabledTest(dataEnabled);
696     if (dataEnabled) {
697         CellularDataTest::EnableCellularDataTest(false);
698         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
699         sleep(SLEEP_TIME);
700         CellularDataTest::EnableCellularDataTest(true);
701         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
702         int32_t result = CellularDataTest::GetCellularDataStateTest();
703         ASSERT_TRUE(result == static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
704     } else {
705         CellularDataTest::EnableCellularDataTest(true);
706         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
707         sleep(SLEEP_TIME);
708         CellularDataTest::EnableCellularDataTest(false);
709         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
710         int32_t result = CellularDataTest::GetCellularDataStateTest();
711         ASSERT_TRUE(result == static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
712     }
713     CellularDataTest::EnableCellularDataTest(false);
714     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
715 }
716 
717 /**
718  * @tc.number   DataRoamingState_InValidSlot_Test_01
719  * @tc.name     Test the EnableCellularDataRoaming function with a invalid slot id
720  * @tc.desc     Function test
721  */
722 HWTEST_F(CellularDataTest, DataRoamingState_InValidSlot_Test_01, TestSize.Level3)
723 {
724     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
725         return;
726     }
727     DataAccessToken token;
728     // invalid slot turn on data roaming
729     int32_t enable = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID - 1, true);
730     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
731     bool dataRoamingEnabled = false;
732     int32_t result = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID - 1, dataRoamingEnabled);
733     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
734     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
735     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
736     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID, dataRoamingEnabled);
737     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
738     // invalid slot disable roaming
739     enable = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID - 1, false);
740     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
741     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID - 1, dataRoamingEnabled);
742     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
743     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
744     ASSERT_TRUE(enable != TELEPHONY_ERR_SUCCESS);
745     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID, dataRoamingEnabled);
746     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
747 }
748 
749 /**
750  * @tc.number   DataFlowType_Test_01
751  * @tc.name     Test the GetCellularDataFlowType function
752  * @tc.desc     Function test
753  */
754 HWTEST_F(CellularDataTest, DataFlowType_Test_01, TestSize.Level3)
755 {
756     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
757         return;
758     }
759     DataAccessToken token;
760     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
761     CellularDataTest::EnableCellularDataTest(false);
762     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
763     sleep(SLEEP_TIME);
764 
765     CellularDataTest::EnableCellularDataTest(true);
766     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
767     sleep(SLEEP_TIME);
768     std::cout << "Cellular Data Connected Ping..." << std::endl;
769     int32_t pingResult = CellularDataTest::PingTest();
770     ASSERT_TRUE(pingResult >= PING_CHECK_SUCCESS);
771     int32_t dataFlowType = CellularDataTest::GetCellularDataFlowTypeTest();
772     ASSERT_TRUE(dataFlowType >= 0);
773 
774     CellularDataTest::EnableCellularDataTest(false);
775     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
776     sleep(SLEEP_TIME);
777     std::cout << "Cellular Data Disconnected Ping..." << std::endl;
778     pingResult = CellularDataTest::PingTest();
779     ASSERT_TRUE(pingResult == PING_CHECK_FAIL);
780     dataFlowType = CellularDataTest::GetCellularDataFlowTypeTest();
781     ASSERT_TRUE(dataFlowType == 0);
782 }
783 
784 /**
785  * @tc.number   DataFlowType_Test_02
786  * @tc.name     Test the GetCellularDataFlowType function
787  * @tc.desc     Function test
788  */
789 HWTEST_F(CellularDataTest, DataFlowType_Test_02, TestSize.Level3)
790 {
791     if (!HasSimCard(SIM_SLOT_ID_1)) {
792         return;
793     }
794     DataAccessToken token;
795     CellularDataTest::SetDefaultCellularDataSlotIdTest(SIM_SLOT_ID_1);
796     CellularDataTest::EnableCellularDataTest(false);
797     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
798     sleep(SLEEP_TIME);
799 
800     CellularDataTest::EnableCellularDataTest(true);
801     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
802     sleep(SLEEP_TIME);
803     std::cout << "Cellular Data Connected Ping..." << std::endl;
804     int32_t pingResult = CellularDataTest::PingTest();
805     ASSERT_TRUE(pingResult >= PING_CHECK_SUCCESS);
806     int32_t dataFlowType = CellularDataTest::GetCellularDataFlowTypeTest();
807     ASSERT_TRUE(dataFlowType >= 0);
808 
809     CellularDataTest::EnableCellularDataTest(false);
810     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
811     sleep(SLEEP_TIME);
812     std::cout << "Cellular Data Disconnected Ping..." << std::endl;
813     pingResult = CellularDataTest::PingTest();
814     ASSERT_TRUE(pingResult == PING_CHECK_FAIL);
815     dataFlowType = CellularDataTest::GetCellularDataFlowTypeTest();
816     ASSERT_TRUE(dataFlowType == 0);
817 }
818 
819 /**
820  * @tc.number   MmsApn_Test_01
821  * @tc.name     Test the Mms apn function
822  * @tc.desc     Function test
823  */
824 HWTEST_F(CellularDataTest, MmsApn_Test_01, TestSize.Level3)
825 {
826     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
827         return;
828     }
829     DataAccessToken token;
830     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
831     if (callback == nullptr) {
832         std::cout << "callback is null" << std::endl;
833         return;
834     }
835     NetSpecifier netSpecifier;
836     NetAllCapabilities netAllCapabilities;
837     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_MMS);
838     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
839     int32_t simId = CoreServiceClient::GetInstance().GetSimId(DEFAULT_SIM_SLOT_ID);
840     netSpecifier.ident_ = "simId" + std::to_string(simId);
841     netSpecifier.netCapabilities_ = netAllCapabilities;
842     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
843     if (specifier == nullptr) {
844         std::cout << "specifier is null" << std::endl;
845         return;
846     }
847     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
848     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
849     auto mmsCallback = static_cast<TestCallback *>(callback.GetRefPtr());
850     if (mmsCallback == nullptr) {
851         std::cout << "mmsCallback is null" << std::endl;
852         return;
853     }
854     int32_t count = 0;
855     while (count < MAX_TIMES) {
856         sleep(SLEEP_TIME);
857         if (mmsCallback->isCallback_ == true) {
858             break;
859         }
860         count++;
861     }
862     ASSERT_TRUE(mmsCallback->isCallback_);
863     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
864     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
865 }
866 
867 /**
868  * @tc.number   MmsApn_Test_02
869  * @tc.name     Test the Mms apn function
870  * @tc.desc     Function test
871  */
872 HWTEST_F(CellularDataTest, MmsApn_Test_02, TestSize.Level3)
873 {
874     if (!HasSimCard(SIM_SLOT_ID_1)) {
875         return;
876     }
877     DataAccessToken token;
878     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
879     if (callback == nullptr) {
880         std::cout << "callback is null" << std::endl;
881         return;
882     }
883     NetSpecifier netSpecifier;
884     NetAllCapabilities netAllCapabilities;
885     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_MMS);
886     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
887     int32_t simId = CoreServiceClient::GetInstance().GetSimId(SIM_SLOT_ID_1);
888     netSpecifier.ident_ = "simId" + std::to_string(simId);
889     netSpecifier.netCapabilities_ = netAllCapabilities;
890     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
891     if (specifier == nullptr) {
892         std::cout << "specifier is null" << std::endl;
893         return;
894     }
895     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
896     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
897     auto mmsCallback = static_cast<TestCallback *>(callback.GetRefPtr());
898     if (mmsCallback == nullptr) {
899         std::cout << "mmsCallback is null" << std::endl;
900         return;
901     }
902     int32_t count = 0;
903     while (count < MAX_TIMES) {
904         sleep(SLEEP_TIME);
905         if (mmsCallback->isCallback_ == true) {
906             break;
907         }
908         count++;
909     }
910     ASSERT_TRUE(mmsCallback->isCallback_);
911     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
912     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
913 }
914 
915 /**
916  * @tc.number   HasInternetCapability_Test_01
917  * @tc.name     Test the HasInternetCapability function
918  * @tc.desc     Function test
919  */
920 HWTEST_F(CellularDataTest, HasInternetCapability_Test_01, TestSize.Level3)
921 {
922     if (!HasSimCard(SIM_SLOT_ID_1)) {
923         return;
924     }
925 
926     int32_t cid = 1;
927     int32_t result = CellularDataTest::HasInternetCapability(SIM_SLOT_ID_1, cid);
928     ASSERT_TRUE(result == static_cast<int32_t>(RequestNetCode::REQUEST_FAILED));
929 }
930 
931 /**
932  * @tc.number   HasInternetCapability_Test_02
933  * @tc.name     Test the HasInternetCapability function
934  * @tc.desc     Function test
935  */
936 HWTEST_F(CellularDataTest, HasInternetCapability_Test_02, TestSize.Level3)
937 {
938     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
939         return;
940     }
941 
942     int32_t cid = 1;
943     int32_t result = CellularDataTest::HasInternetCapability(DEFAULT_SIM_SLOT_ID, cid);
944     ASSERT_TRUE(result == static_cast<int32_t>(RequestNetCode::REQUEST_FAILED));
945 }
946 
947 /**
948  * @tc.number   ClearCellularDataConnections_Test_01
949  * @tc.name     Test the ClearCellularDataConnections function
950  * @tc.desc     Function test
951  */
952 HWTEST_F(CellularDataTest, ClearCellularDataConnections_Test_01, TestSize.Level3)
953 {
954     if (!HasSimCard(SIM_SLOT_ID_1)) {
955         return;
956     }
957     DataAccessToken token;
958     int32_t result = CellularDataTest::ClearCellularDataConnections(SIM_SLOT_ID_1);
959     ASSERT_TRUE(result == static_cast<int32_t>(RequestNetCode::REQUEST_SUCCESS));
960 }
961 
962 /**
963  * @tc.number   ClearCellularDataConnections_Test_02
964  * @tc.name     Test the ClearCellularDataConnections function
965  * @tc.desc     Function test
966  */
967 HWTEST_F(CellularDataTest, ClearCellularDataConnections_Test_02, TestSize.Level3)
968 {
969     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
970         return;
971     }
972     DataAccessToken token;
973     int32_t result = CellularDataTest::ClearCellularDataConnections(DEFAULT_SIM_SLOT_ID);
974     ASSERT_TRUE(result == static_cast<int32_t>(RequestNetCode::REQUEST_SUCCESS));
975 }
976 
977 /**
978  * @tc.number   ClearAllConnections
979  * @tc.name     Test the ClearAllConnections function
980  * @tc.desc     Function test
981  */
982 HWTEST_F(CellularDataTest, ClearAllConnections_Test_01, TestSize.Level3)
983 {
984     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
985         return;
986     }
987     DataAccessToken token;
988     int32_t result = CellularDataTest::ClearAllConnections(
989         DEFAULT_SIM_SLOT_ID, DisConnectionReason::REASON_RETRY_CONNECTION);
990     ASSERT_TRUE(result == static_cast<int32_t>(RequestNetCode::REQUEST_SUCCESS));
991 }
992 
993 /**
994  * @tc.number   GetApnState
995  * @tc.name     Test the GetApnState function
996  * @tc.desc     Function test
997  */
998 HWTEST_F(CellularDataTest, GetApnState_Test_01, TestSize.Level3)
999 {
1000     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1001         return;
1002     }
1003     DataAccessToken token;
1004     int32_t result = CellularDataTest::GetApnState(DEFAULT_SIM_SLOT_ID, "default");
1005     ASSERT_TRUE(result >= 0 && result <= 5);
1006 }
1007 
1008 /**
1009  * @tc.number   GetDataRecoveryState
1010  * @tc.name     Test the GetDataRecoveryState function
1011  * @tc.desc     Function test
1012  */
1013 HWTEST_F(CellularDataTest, GetDataRecoveryState_Test_01, TestSize.Level3)
1014 {
1015     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1016         return;
1017     }
1018     DataAccessToken token;
1019     int32_t result = CellularDataTest::GetDataRecoveryState();
1020     ASSERT_TRUE(result >= 0 && result <= 3);
1021 }
1022 
1023 /**
1024  * @tc.number   CellularDataDump_Test_01
1025  * @tc.name    TestDump
1026  * @tc.desc     Function test
1027  */
1028 HWTEST_F(CellularDataTest, CellularDataDump_Test_01, Function | MediumTest | Level3)
1029 {
1030     std::vector<std::u16string> emptyArgs = {};
1031     std::vector<std::u16string> args = { u"test", u"test1" };
1032     EXPECT_GE(DelayedSingleton<CellularDataService>::GetInstance()->Dump(-1, args), 0);
1033     EXPECT_GE(DelayedSingleton<CellularDataService>::GetInstance()->Dump(0, emptyArgs), 0);
1034     EXPECT_GE(DelayedSingleton<CellularDataService>::GetInstance()->Dump(0, args), 0);
1035 }
1036 
1037 /**
1038  * @tc.number   Telephony_Cellulardata_InitTelephonyExtService_0100
1039  * @tc.name     Init Telephony Ext Service.
1040  * @tc.desc     Function test
1041  */
1042 HWTEST_F(CellularDataTest, Telephony_Cellulardata_InitTelephonyExtService_0100, Function | MediumTest | Level1)
1043 {
1044     DataAccessToken token;
1045     TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
1046     if (TELEPHONY_EXT_WRAPPER.telephonyExtWrapperHandle_ == nullptr) {
1047         TELEPHONY_LOGI("telephonyExtWrapperHandle_ null");
1048     } else {
1049         TELEPHONY_LOGI("telephonyExtWrapperHandle_ not null");
1050         EXPECT_EQ(TELEPHONY_EXT_WRAPPER.dataEndSelfCure_ != nullptr, true);
1051     }
1052 }
1053 
1054 /**
1055  * @tc.number   GetDataConnApnAttr_Test_01
1056  * @tc.name     Test the GetDataConnApnAttr function
1057  * @tc.desc     Function test
1058  */
1059 HWTEST_F(CellularDataTest, GetDataConnApnAttr_Test_01, TestSize.Level3)
1060 {
1061     if (!HasSimCard(SIM_SLOT_ID_1)) {
1062         return;
1063     }
1064     DataAccessToken token;
1065     ApnItem::Attribute apnAttr;
1066     int32_t result = CellularDataTest::GetDataConnApnAttr(SIM_SLOT_ID_1, apnAttr);
1067     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
1068 }
1069 
1070 /**
1071  * @tc.number   GetDataConnApnAttr_Test_02
1072  * @tc.name     Test the GetDataConnApnAttr function
1073  * @tc.desc     Function test
1074  */
1075 HWTEST_F(CellularDataTest, GetDataConnApnAttr_Test_02, TestSize.Level3)
1076 {
1077     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1078         return;
1079     }
1080     DataAccessToken token;
1081     ApnItem::Attribute apnAttr;
1082     int32_t result = CellularDataTest::GetDataConnApnAttr(DEFAULT_SIM_SLOT_ID, apnAttr);
1083     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
1084 }
1085 
1086 /**
1087  * @tc.number   GetDataConnIpType_Test_01
1088  * @tc.name     Test the GetDataConnIpType function
1089  * @tc.desc     Function test
1090  */
1091 HWTEST_F(CellularDataTest, GetDataConnIpType_Test_01, TestSize.Level3)
1092 {
1093     if (!HasSimCard(SIM_SLOT_ID_1)) {
1094         return;
1095     }
1096     DataAccessToken token;
1097     std::string ipType;
1098     int32_t result = CellularDataTest::GetDataConnIpType(SIM_SLOT_ID_1, ipType);
1099     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
1100 }
1101 
1102 /**
1103  * @tc.number   GetDataConnIpType_Test_02
1104  * @tc.name     Test the GetDataConnIpType function
1105  * @tc.desc     Function test
1106  */
1107 HWTEST_F(CellularDataTest, GetDataConnIpType_Test_02, TestSize.Level3)
1108 {
1109     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1110         return;
1111     }
1112     DataAccessToken token;
1113     std::string ipType;
1114     int32_t result = CellularDataTest::GetDataConnIpType(DEFAULT_SIM_SLOT_ID, ipType);
1115     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
1116 }
1117 
1118 /**
1119  * @tc.number   IsNeedDoRecovery_Test_01
1120  * @tc.name     Test the IsNeedDoRecovery function
1121  * @tc.desc     Function test
1122  */
1123 HWTEST_F(CellularDataTest, IsNeedDoRecovery_Test_01, TestSize.Level3)
1124 {
1125     if (!HasSimCard(SIM_SLOT_ID_1)) {
1126         return;
1127     }
1128     DataAccessToken token;
1129     bool needDoRecovery = true;
1130     int32_t result = CellularDataTest::IsNeedDoRecovery(SIM_SLOT_ID_1, needDoRecovery);
1131     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
1132 }
1133 
1134 /**
1135  * @tc.number   IsNeedDoRecovery_Test_02
1136  * @tc.name     Test the IsNeedDoRecovery function
1137  * @tc.desc     Function test
1138  */
1139 HWTEST_F(CellularDataTest, IsNeedDoRecovery_Test_02, TestSize.Level3)
1140 {
1141     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1142         return;
1143     }
1144     DataAccessToken token;
1145     bool needDoRecovery = true;
1146     int32_t result = CellularDataTest::IsNeedDoRecovery(DEFAULT_SIM_SLOT_ID, needDoRecovery);
1147     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
1148 }
1149 
1150 /**
1151  * @tc.number   EnableIntelligenceSwitch_Test_01
1152  * @tc.name     Test Intelligence switch
1153  * @tc.desc     Function test
1154  */
1155 HWTEST_F(CellularDataTest, EnableIntelligenceSwitch_Test_01, TestSize.Level2)
1156 {
1157     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1158         return;
1159     }
1160     DataAccessToken token;
1161     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
1162     int32_t result1 = CellularDataTest::EnableIntelligenceSwitchTest(true);
1163     ASSERT_TRUE(result1 == TELEPHONY_ERR_SUCCESS);
1164     sleep(SLEEP_TIME);
1165     std::cout << "EnableIntelligenceSwitch ..." << std::endl;
1166     int32_t result2 = CellularDataTest::EnableIntelligenceSwitchTest(false);
1167     ASSERT_TRUE(result2 == TELEPHONY_ERR_SUCCESS);
1168     sleep(SLEEP_TIME);
1169     std::cout << "DisableIntelligenceSwitch ..." << std::endl;
1170 }
1171 
1172 /**
1173  * @tc.number   GetIntelligenceSwitchState_Test_01
1174  * @tc.name     Test Intelligence switch
1175  * @tc.desc     Function test
1176  */
1177 HWTEST_F(CellularDataTest, GetIntelligenceSwitchState_Test_01, TestSize.Level2)
1178 {
1179     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1180         return;
1181     }
1182     DataAccessToken token;
1183     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
1184     int32_t result1 = CellularDataTest::EnableIntelligenceSwitchTest(true);
1185     ASSERT_TRUE(result1 == TELEPHONY_ERR_SUCCESS);
1186     bool res1 = false;
1187     CellularDataTest::GetIntelligenceSwitchStateTest(res1);
1188     ASSERT_TRUE(res1 == true);
1189     std::cout << "Test GetIntelligenceSwitchState Of True..." << std::endl;
1190     int32_t result2 = CellularDataTest::EnableIntelligenceSwitchTest(false);
1191     ASSERT_TRUE(result2 == TELEPHONY_ERR_SUCCESS);
1192     bool res2 = true;
1193     CellularDataTest::GetIntelligenceSwitchStateTest(res2);
1194     ASSERT_TRUE(res2 == false);
1195     std::cout << "Test GetIntelligenceSwitchState Of False..." << std::endl;
1196 }
1197 
1198 /**
1199  * @tc.number   InitCellularDataController_Test_01
1200  * @tc.name     Test the InitCellularDataController function
1201  * @tc.desc     Function test
1202  */
1203 HWTEST_F(CellularDataTest, InitCellularDataController_Test_01, TestSize.Level3)
1204 {
1205     if (!HasSimCard(SIM_SLOT_ID_1)) {
1206         return;
1207     }
1208     DataAccessToken token;
1209     int32_t result = CellularDataTest::InitCellularDataController(SIM_SLOT_ID_1);
1210     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
1211 }
1212 
1213 /**
1214  * @tc.number   InitCellularDataController_Test_02
1215  * @tc.name     Test the InitCellularDataController function
1216  * @tc.desc     Function test
1217  */
1218 HWTEST_F(CellularDataTest, InitCellularDataController_Test_02, TestSize.Level3)
1219 {
1220     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1221         return;
1222     }
1223     DataAccessToken token;
1224     int32_t result = CellularDataTest::InitCellularDataController(DEFAULT_SIM_SLOT_ID);
1225     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
1226 }
1227 
1228 /**
1229  * @tc.number   InitCellularDataController_Test_03
1230  * @tc.name     Test the InitCellularDataController function
1231  * @tc.desc     Function test
1232  */
1233 HWTEST_F(CellularDataTest, InitCellularDataController_Test_03, TestSize.Level3)
1234 {
1235     DataAccessToken token;
1236     int32_t ret = DelayedRefSingleton<CoreServiceClient>::GetInstance().InitExtraModule(CELLULAR_DATA_VSIM_SLOT_ID);
1237     if (ret != TELEPHONY_SUCCESS) {
1238         return;
1239     }
1240     int32_t result = CellularDataTest::InitCellularDataController(CELLULAR_DATA_VSIM_SLOT_ID);
1241     ASSERT_TRUE(result == TELEPHONY_ERR_SUCCESS);
1242 }
1243 
1244 /**
1245  * @tc.number   SUPL_Apn_Test_01
1246  * @tc.name     Test the SUPL apn function
1247  * @tc.desc     Function test
1248  */
1249 HWTEST_F(CellularDataTest, SUPL_Apn_Test_01, TestSize.Level3)
1250 {
1251     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1252         return;
1253     }
1254     DataAccessToken token;
1255     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1256     if (callback == nullptr) {
1257         std::cout << "callback is null" << std::endl;
1258         return;
1259     }
1260     NetSpecifier netSpecifier;
1261     NetAllCapabilities netAllCapabilities;
1262     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_SUPL);
1263     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1264     int32_t simId = CoreServiceClient::GetInstance().GetSimId(DEFAULT_SIM_SLOT_ID);
1265     netSpecifier.ident_ = "simId" + std::to_string(simId);
1266     netSpecifier.netCapabilities_ = netAllCapabilities;
1267     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1268     if (specifier == nullptr) {
1269         std::cout << "specifier is null" << std::endl;
1270         return;
1271     }
1272     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1273     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1274     auto suplCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1275     if (suplCallback == nullptr) {
1276         std::cout << "suplCallback is null" << std::endl;
1277         return;
1278     }
1279     int32_t count = 0;
1280     while (count < MAX_TIMES) {
1281         sleep(SLEEP_TIME);
1282         if (suplCallback->isCallback_ == true) {
1283             break;
1284         }
1285         count++;
1286     }
1287     ASSERT_TRUE(suplCallback->isCallback_);
1288     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1289     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1290 }
1291 
1292 /**
1293  * @tc.number   SUPL_Apn_Test_02
1294  * @tc.name     Test the SUPL apn function
1295  * @tc.desc     Function test
1296  */
1297 HWTEST_F(CellularDataTest, SUPL_Apn_Test_02, TestSize.Level3)
1298 {
1299     if (!HasSimCard(SIM_SLOT_ID_1)) {
1300         return;
1301     }
1302     DataAccessToken token;
1303     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1304     if (callback == nullptr) {
1305         std::cout << "callback is null" << std::endl;
1306         return;
1307     }
1308     NetSpecifier netSpecifier;
1309     NetAllCapabilities netAllCapabilities;
1310     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_SUPL);
1311     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1312     int32_t simId = CoreServiceClient::GetInstance().GetSimId(SIM_SLOT_ID_1);
1313     netSpecifier.ident_ = "simId" + std::to_string(simId);
1314     netSpecifier.netCapabilities_ = netAllCapabilities;
1315     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1316     if (specifier == nullptr) {
1317         std::cout << "specifier is null" << std::endl;
1318         return;
1319     }
1320     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1321     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1322     auto suplCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1323     if (suplCallback == nullptr) {
1324         std::cout << "suplCallback is null" << std::endl;
1325         return;
1326     }
1327     int32_t count = 0;
1328     while (count < MAX_TIMES) {
1329         sleep(SLEEP_TIME);
1330         if (suplCallback->isCallback_ == true) {
1331             break;
1332         }
1333         count++;
1334     }
1335     ASSERT_TRUE(suplCallback->isCallback_);
1336     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1337     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1338 }
1339 
1340 /**
1341  * @tc.number   DUN_Apn_Test_01
1342  * @tc.name     Test the DUN apn function
1343  * @tc.desc     Function test
1344  */
1345 HWTEST_F(CellularDataTest, DUN_Apn_Test_01, TestSize.Level3)
1346 {
1347     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1348         return;
1349     }
1350     DataAccessToken token;
1351     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1352     if (callback == nullptr) {
1353         std::cout << "callback is null" << std::endl;
1354         return;
1355     }
1356     NetSpecifier netSpecifier;
1357     NetAllCapabilities netAllCapabilities;
1358     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_DUN);
1359     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1360     int32_t simId = CoreServiceClient::GetInstance().GetSimId(DEFAULT_SIM_SLOT_ID);
1361     netSpecifier.ident_ = "simId" + std::to_string(simId);
1362     netSpecifier.netCapabilities_ = netAllCapabilities;
1363     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1364     if (specifier == nullptr) {
1365         std::cout << "specifier is null" << std::endl;
1366         return;
1367     }
1368     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1369     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1370     auto dunCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1371     if (dunCallback == nullptr) {
1372         std::cout << "dunCallback is null" << std::endl;
1373         return;
1374     }
1375     int32_t count = 0;
1376     while (count < MAX_TIMES) {
1377         sleep(SLEEP_TIME);
1378         if (dunCallback->isCallback_ == true) {
1379             break;
1380         }
1381         count++;
1382     }
1383     ASSERT_TRUE(dunCallback->isCallback_);
1384     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1385     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1386 }
1387 
1388 /**
1389  * @tc.number   DUN_Apn_Test_02
1390  * @tc.name     Test the DUN apn function
1391  * @tc.desc     Function test
1392  */
1393 HWTEST_F(CellularDataTest, DUN_Apn_Test_02, TestSize.Level3)
1394 {
1395     if (!HasSimCard(SIM_SLOT_ID_1)) {
1396         return;
1397     }
1398     DataAccessToken token;
1399     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1400     if (callback == nullptr) {
1401         std::cout << "callback is null" << std::endl;
1402         return;
1403     }
1404     NetSpecifier netSpecifier;
1405     NetAllCapabilities netAllCapabilities;
1406     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_DUN);
1407     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1408     int32_t simId = CoreServiceClient::GetInstance().GetSimId(SIM_SLOT_ID_1);
1409     netSpecifier.ident_ = "simId" + std::to_string(simId);
1410     netSpecifier.netCapabilities_ = netAllCapabilities;
1411     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1412     if (specifier == nullptr) {
1413         std::cout << "specifier is null" << std::endl;
1414         return;
1415     }
1416     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1417     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1418     auto dunCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1419     if (dunCallback == nullptr) {
1420         std::cout << "dunCallback is null" << std::endl;
1421         return;
1422     }
1423     int32_t count = 0;
1424     while (count < MAX_TIMES) {
1425         sleep(SLEEP_TIME);
1426         if (dunCallback->isCallback_ == true) {
1427             break;
1428         }
1429         count++;
1430     }
1431     ASSERT_TRUE(dunCallback->isCallback_);
1432     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1433     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1434 }
1435 
1436 /**
1437  * @tc.number   IA_Apn_Test_01
1438  * @tc.name     Test the IA apn function
1439  * @tc.desc     Function test
1440  */
1441 HWTEST_F(CellularDataTest, IA_Apn_Test_01, TestSize.Level3)
1442 {
1443     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1444         return;
1445     }
1446     DataAccessToken token;
1447     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1448     if (callback == nullptr) {
1449         std::cout << "callback is null" << std::endl;
1450         return;
1451     }
1452     NetSpecifier netSpecifier;
1453     NetAllCapabilities netAllCapabilities;
1454     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_IA);
1455     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1456     int32_t simId = CoreServiceClient::GetInstance().GetSimId(DEFAULT_SIM_SLOT_ID);
1457     netSpecifier.ident_ = "simId" + std::to_string(simId);
1458     netSpecifier.netCapabilities_ = netAllCapabilities;
1459     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1460     if (specifier == nullptr) {
1461         std::cout << "specifier is null" << std::endl;
1462         return;
1463     }
1464     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1465     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1466     auto iaCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1467     if (iaCallback == nullptr) {
1468         std::cout << "iaCallback is null" << std::endl;
1469         return;
1470     }
1471     int32_t count = 0;
1472     while (count < MAX_TIMES) {
1473         sleep(SLEEP_TIME);
1474         if (iaCallback->isCallback_ == true) {
1475             break;
1476         }
1477         count++;
1478     }
1479     ASSERT_TRUE(iaCallback->isCallback_);
1480     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1481     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1482 }
1483 
1484 /**
1485  * @tc.number   IA_Apn_Test_02
1486  * @tc.name     Test the IA apn function
1487  * @tc.desc     Function test
1488  */
1489 HWTEST_F(CellularDataTest, IA_Apn_Test_02, TestSize.Level3)
1490 {
1491     if (!HasSimCard(SIM_SLOT_ID_1)) {
1492         return;
1493     }
1494     DataAccessToken token;
1495     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1496     if (callback == nullptr) {
1497         std::cout << "callback is null" << std::endl;
1498         return;
1499     }
1500     NetSpecifier netSpecifier;
1501     NetAllCapabilities netAllCapabilities;
1502     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_IA);
1503     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1504     int32_t simId = CoreServiceClient::GetInstance().GetSimId(SIM_SLOT_ID_1);
1505     netSpecifier.ident_ = "simId" + std::to_string(simId);
1506     netSpecifier.netCapabilities_ = netAllCapabilities;
1507     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1508     if (specifier == nullptr) {
1509         std::cout << "specifier is null" << std::endl;
1510         return;
1511     }
1512     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1513     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1514     auto iaCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1515     if (iaCallback == nullptr) {
1516         std::cout << "iaCallback is null" << std::endl;
1517         return;
1518     }
1519     int32_t count = 0;
1520     while (count < MAX_TIMES) {
1521         sleep(SLEEP_TIME);
1522         if (iaCallback->isCallback_ == true) {
1523             break;
1524         }
1525         count++;
1526     }
1527     ASSERT_TRUE(iaCallback->isCallback_);
1528     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1529     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1530 }
1531 
1532 /**
1533  * @tc.number   XCAP_Apn_Test_01
1534  * @tc.name     Test the XCAP apn function
1535  * @tc.desc     Function test
1536  */
1537 HWTEST_F(CellularDataTest, XCAP_Apn_Test_01, TestSize.Level3)
1538 {
1539     if (!HasSimCard(DEFAULT_SIM_SLOT_ID)) {
1540         return;
1541     }
1542     DataAccessToken token;
1543     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1544     if (callback == nullptr) {
1545         std::cout << "callback is null" << std::endl;
1546         return;
1547     }
1548     NetSpecifier netSpecifier;
1549     NetAllCapabilities netAllCapabilities;
1550     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_XCAP);
1551     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1552     int32_t simId = CoreServiceClient::GetInstance().GetSimId(DEFAULT_SIM_SLOT_ID);
1553     netSpecifier.ident_ = "simId" + std::to_string(simId);
1554     netSpecifier.netCapabilities_ = netAllCapabilities;
1555     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1556     if (specifier == nullptr) {
1557         std::cout << "specifier is null" << std::endl;
1558         return;
1559     }
1560     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1561     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1562     auto xcapCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1563     if (xcapCallback == nullptr) {
1564         std::cout << "xcapCallback is null" << std::endl;
1565         return;
1566     }
1567     int32_t count = 0;
1568     while (count < MAX_TIMES) {
1569         sleep(SLEEP_TIME);
1570         if (xcapCallback->isCallback_ == true) {
1571             break;
1572         }
1573         count++;
1574     }
1575     ASSERT_TRUE(xcapCallback->isCallback_);
1576     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1577     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1578 }
1579 
1580 /**
1581  * @tc.number   XCAP_Apn_Test_02
1582  * @tc.name     Test the XCAP apn function
1583  * @tc.desc     Function test
1584  */
1585 HWTEST_F(CellularDataTest, XCAP_Apn_Test_02, TestSize.Level3)
1586 {
1587     if (!HasSimCard(SIM_SLOT_ID_1)) {
1588         return;
1589     }
1590     DataAccessToken token;
1591     sptr<INetConnCallback> callback = new (std::nothrow) TestCallback();
1592     if (callback == nullptr) {
1593         std::cout << "callback is null" << std::endl;
1594         return;
1595     }
1596     NetSpecifier netSpecifier;
1597     NetAllCapabilities netAllCapabilities;
1598     netAllCapabilities.netCaps_.insert(NetCap::NET_CAPABILITY_XCAP);
1599     netAllCapabilities.bearerTypes_.insert(NetBearType::BEARER_CELLULAR);
1600     int32_t simId = CoreServiceClient::GetInstance().GetSimId(SIM_SLOT_ID_1);
1601     netSpecifier.ident_ = "simId" + std::to_string(simId);
1602     netSpecifier.netCapabilities_ = netAllCapabilities;
1603     sptr<NetSpecifier> specifier = new (std::nothrow) NetSpecifier(netSpecifier);
1604     if (specifier == nullptr) {
1605         std::cout << "specifier is null" << std::endl;
1606         return;
1607     }
1608     int32_t result = NetConnClient::GetInstance().RegisterNetConnCallback(specifier, callback, NET_REGISTER_TIMEOUT_MS);
1609     std::cout << "RegisterNetConnCallback result [" << result << "]" << std::endl;
1610     auto xcapCallback = static_cast<TestCallback *>(callback.GetRefPtr());
1611     if (xcapCallback == nullptr) {
1612         std::cout << "xcapCallback is null" << std::endl;
1613         return;
1614     }
1615     int32_t count = 0;
1616     while (count < MAX_TIMES) {
1617         sleep(SLEEP_TIME);
1618         if (xcapCallback->isCallback_ == true) {
1619             break;
1620         }
1621         count++;
1622     }
1623     ASSERT_TRUE(xcapCallback->isCallback_);
1624     result = NetConnClient::GetInstance().UnregisterNetConnCallback(callback);
1625     std::cout << "UnregisterNetConnCallback result [" << result << "]" << std::endl;
1626 }
1627 
1628 /**
1629  * @tc.number   RequestNetwork_001
1630  * @tc.name     Test the function
1631  * @tc.desc     Function test
1632  */
1633 HWTEST_F(CellularDataTest, RequestNetwork_001, TestSize.Level3)
1634 {
1635     std::string ident = "testIdent";
1636     std::set<NetCap> netCaps;
1637     NetManagerStandard::NetRequest netrequest;
1638     if (callback_ == nullptr) {
1639         callback_ = std::make_unique<NetManagerCallBack>().release();
1640     }
1641     int32_t result = callback_->RequestNetwork(ident, netCaps, netrequest);
1642     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
1643 }
1644 
1645 /**
1646  * @tc.number   RequestNetwork_002
1647  * @tc.name     Test the function
1648  * @tc.desc     Function test
1649  */
1650 HWTEST_F(CellularDataTest, RequestNetwork_002, TestSize.Level3)
1651 {
1652     std::string ident = "testIdent";
1653     std::set<NetCap> netCaps = { NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET };
1654     NetManagerStandard::NetRequest netrequest;
1655     if (callback_ == nullptr) {
1656         callback_ = std::make_unique<NetManagerCallBack>().release();
1657     }
1658     int32_t result = callback_->RequestNetwork(ident, netCaps, netrequest);
1659     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
1660 }
1661 
1662 /**
1663  * @tc.number   ReleaseNetwork_001
1664  * @tc.name     Test the function
1665  * @tc.desc     Function test
1666  */
1667 HWTEST_F(CellularDataTest, ReleaseNetwork_001, TestSize.Level3)
1668 {
1669     std::string ident = "testIdent";
1670     std::set<NetCap> netCaps;
1671     if (callback_ == nullptr) {
1672         callback_ = std::make_unique<NetManagerCallBack>().release();
1673     }
1674     int32_t result = callback_->ReleaseNetwork(ident, netCaps);
1675     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
1676 }
1677 
1678 /**
1679  * @tc.number   ReleaseNetwork_002
1680  * @tc.name     Test the function
1681  * @tc.desc     Function test
1682  */
1683 HWTEST_F(CellularDataTest, ReleaseNetwork_002, TestSize.Level3)
1684 {
1685     std::string ident = "testIdent";
1686     std::set<NetCap> netCaps = { NetManagerStandard::NetCap::NET_CAPABILITY_INTERNET };
1687     if (callback_ == nullptr) {
1688         callback_ = std::make_unique<NetManagerCallBack>().release();
1689     }
1690     int32_t result = callback_->ReleaseNetwork(ident, netCaps);
1691     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
1692 }
1693 
1694 /**
1695  * @tc.number   NetStrategySwitch_001
1696  * @tc.name     Test the function
1697  * @tc.desc     Function test
1698  */
1699 HWTEST_F(CellularDataTest, NetStrategySwitch_001, TestSize.Level3)
1700 {
1701     if (tacticsCallBack_ == nullptr) {
1702         tacticsCallBack_ = std::make_unique<NetManagerTacticsCallBack>().release();
1703     }
1704     int32_t result = tacticsCallBack_->NetStrategySwitch("", true);
1705     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
1706 }
1707 
1708 /**
1709  * @tc.number   NetStrategySwitch_002
1710  * @tc.name     Test the function
1711  * @tc.desc     Function test
1712  */
1713 HWTEST_F(CellularDataTest, NetStrategySwitch_002, TestSize.Level3)
1714 {
1715     if (tacticsCallBack_ == nullptr) {
1716         tacticsCallBack_ = std::make_unique<NetManagerTacticsCallBack>().release();
1717     }
1718     int32_t result = tacticsCallBack_->NetStrategySwitch("abc", true);
1719     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
1720 }
1721 
1722 /**
1723  * @tc.number   NetStrategySwitch_003
1724  * @tc.name     Test the function
1725  * @tc.desc     Function test
1726  */
1727 HWTEST_F(CellularDataTest, NetStrategySwitch_003, TestSize.Level3)
1728 {
1729     if (tacticsCallBack_ == nullptr) {
1730         tacticsCallBack_ = std::make_unique<NetManagerTacticsCallBack>().release();
1731     }
1732     int32_t result = tacticsCallBack_->NetStrategySwitch("123", true);
1733     ASSERT_EQ(result, CELLULAR_DATA_INVALID_PARAM);
1734 }
1735 
1736 /**
1737  * @tc.number   RdbUpdate_001
1738  * @tc.name     Test the function
1739  * @tc.desc     Function test
1740  */
1741 HWTEST_F(CellularDataTest, RdbUpdate_001, TestSize.Level3)
1742 {
1743     DataShare::DataShareValuesBucket values;
1744     DataShare::DataSharePredicates predicates;
1745     CellularDataRdbHelper cellularDataRdbHelper;
1746     int result = cellularDataRdbHelper.Update(values, predicates);
1747     ASSERT_EQ(result, NULL_POINTER_EXCEPTION);
1748 }
1749 
1750 /**
1751  * @tc.number   RdbInsert_001
1752  * @tc.name     Test the function
1753  * @tc.desc     Function test
1754  */
1755 HWTEST_F(CellularDataTest, RdbInsert_001, TestSize.Level3)
1756 {
1757     DataShare::DataShareValuesBucket values;
1758     CellularDataRdbHelper cellularDataRdbHelper;
1759     int result = cellularDataRdbHelper.Insert(values);
1760     ASSERT_EQ(result, NULL_POINTER_EXCEPTION);
1761 }
1762 
1763 /**
1764  * @tc.number   QueryApns_001
1765  * @tc.name     Test the function
1766  * @tc.desc     Function test
1767  */
1768 HWTEST_F(CellularDataTest, QueryApns_001, TestSize.Level3)
1769 {
1770     std::string mcc = "123";
1771     std::string mnc = "456";
1772     std::vector<PdpProfile> apnVec;
1773     int32_t slotId = 0;
1774     CellularDataRdbHelper cellularDataRdbHelper;
1775     bool result = cellularDataRdbHelper.QueryApns(mcc, mnc, apnVec, slotId);
1776     ASSERT_FALSE(result);
1777 }
1778 
1779 
1780 /**
1781  * @tc.number   QueryMvnoApnsByType_001
1782  * @tc.name     Test the function
1783  * @tc.desc     Function test
1784  */
1785 HWTEST_F(CellularDataTest, QueryMvnoApnsByType_001, TestSize.Level3)
1786 {
1787     std::string mcc = "123";
1788     std::string mnc = "456";
1789     std::string mvnoType = "789";
1790     std::string mvnoDataFromSim = "";
1791     std::vector<PdpProfile> mvnoApnVec;
1792     int32_t slotId = 0;
1793     CellularDataRdbHelper cellularDataRdbHelper;
1794     bool result = cellularDataRdbHelper.QueryMvnoApnsByType(mcc, mnc, mvnoType, mvnoDataFromSim, mvnoApnVec, slotId);
1795     ASSERT_TRUE(result);
1796 }
1797 
1798 /**
1799  * @tc.number   QueryMvnoApnsByType_002
1800  * @tc.name     Test the function
1801  * @tc.desc     Function test
1802  */
1803 HWTEST_F(CellularDataTest, QueryMvnoApnsByType_002, TestSize.Level3)
1804 {
1805     std::string mcc = "123";
1806     std::string mnc = "456";
1807     std::string mvnoType = "789";
1808     std::string mvnoDataFromSim = "012";
1809     std::vector<PdpProfile> mvnoApnVec;
1810     int32_t slotId = 0;
1811     CellularDataRdbHelper cellularDataRdbHelper;
1812     bool result = cellularDataRdbHelper.QueryMvnoApnsByType(mcc, mnc, mvnoType, mvnoDataFromSim, mvnoApnVec, slotId);
1813     ASSERT_FALSE(result);
1814 }
1815 
1816 /**
1817  * @tc.number   ReadApnResult_001
1818  * @tc.name     Test the function
1819  * @tc.desc     Function test
1820  */
1821 HWTEST_F(CellularDataTest, ReadApnResult_001, TestSize.Level3)
1822 {
1823     std::shared_ptr<DataShare::DataShareResultSet> result = nullptr;
1824     std::vector<PdpProfile> apnVec;
1825     CellularDataRdbHelper cellularDataRdbHelper;
1826     cellularDataRdbHelper.ReadApnResult(nullptr, apnVec);
1827     ASSERT_TRUE(apnVec.empty());
1828 }
1829 
1830 /**
1831  * @tc.number   ReadApnResult_002
1832  * @tc.name     Test the function
1833  * @tc.desc     Function test
1834  */
1835 HWTEST_F(CellularDataTest, ReadApnResult_002, TestSize.Level3)
1836 {
1837     std::shared_ptr<DataShare::DataShareResultSet> result = std::make_shared<DataShare::DataShareResultSet>();
1838     std::vector<PdpProfile> apnVec;
1839     CellularDataRdbHelper cellularDataRdbHelper;
1840     cellularDataRdbHelper.ReadApnResult(nullptr, apnVec);
1841     ASSERT_TRUE(apnVec.empty());
1842 }
1843 
1844 #else  // TEL_TEST_UNSUPPORT
1845 /**
1846  * @tc.number   DataMock_Test_01
1847  * @tc.name     Test for unsupport platform
1848  * @tc.desc     Function test
1849  */
1850 HWTEST_F(CellularDataTest, DataMock_Test_01, TestSize.Level3)
1851 {
1852     EXPECT_TRUE(true);
1853 }
1854 #endif // TEL_TEST_UNSUPPORT
1855 } // namespace Telephony
1856 } // namespace OHOS
1857