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