• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
17 
18 #include "gtest/gtest.h"
19 #include "iservice_registry.h"
20 #include "system_ability_definition.h"
21 
22 #include "core_service_client.h"
23 #include "telephony_types.h"
24 
25 #include "cellular_data_error.h"
26 #include "cellular_data_types.h"
27 #include "i_cellular_data_manager.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 using namespace testing::ext;
32 
33 class CellularDataTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     virtual void SetUp();
38     virtual void TearDown();
39     static int32_t IsCellularDataEnabledTest();
40     static int32_t EnableCellularDataTest(bool enable);
41     static int32_t GetCellularDataStateTest();
42     static int32_t IsCellularDataRoamingEnabledTest(int32_t slotId);
43     static int32_t EnableCellularDataRoamingTest(int32_t slotId, bool enable);
44     static int32_t GetDefaultCellularDataSlotIdTest();
45     static int32_t SetDefaultCellularDataSlotIdTest(int32_t slotId);
46     static int32_t GetCellularDataFlowTypeTest();
47     static void WaitTestTimeout(const int32_t status);
48     static sptr<ICellularDataManager> GetProxy();
49     static string GetCmdResult(const string &strCmd);
50     static int32_t PingTest();
51 
52 public:
53     static sptr<ICellularDataManager> proxy_;
54     static const int32_t SLEEP_TIME = 1;
55     static const int32_t DATA_SLOT_ID_INVALID = DEFAULT_SIM_SLOT_ID + 10;
56     static const int32_t PING_CHECK_SUCCESS = 0;
57     static const int32_t PING_CHECK_FAIL = 1;
58 };
59 
60 sptr<ICellularDataManager> CellularDataTest::proxy_;
61 
TearDownTestCase()62 void CellularDataTest::TearDownTestCase()
63 {}
64 
SetUp()65 void CellularDataTest::SetUp()
66 {}
67 
TearDown()68 void CellularDataTest::TearDown()
69 {}
70 
SetUpTestCase()71 void CellularDataTest::SetUpTestCase()
72 {
73     if (CoreServiceClient::GetInstance().GetProxy() == nullptr) {
74         std::cout << "connect coreService server failed!" << std::endl;
75         return;
76     }
77 
78     proxy_ = GetProxy();
79     ASSERT_TRUE(proxy_ != nullptr);
80     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
81         return;
82     }
83     // Set the default slot
84     int32_t result = proxy_->SetDefaultCellularDataSlotId(DEFAULT_SIM_SLOT_ID);
85     if (result != static_cast<int32_t>(DataRespondCode::SET_SUCCESS)) {
86         return;
87     }
88     int32_t enable = proxy_->EnableCellularData(true);
89     ASSERT_TRUE(enable == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
90     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
91 }
92 
WaitTestTimeout(const int32_t status)93 void CellularDataTest::WaitTestTimeout(const int32_t status)
94 {
95     if (proxy_ == nullptr) {
96         return;
97     }
98     const int32_t maxTimes = 35;
99     int32_t count = 0;
100     while (count < maxTimes) {
101         sleep(SLEEP_TIME);
102         if (proxy_->GetCellularDataState() == status) {
103             return;
104         }
105         count++;
106     }
107 }
108 
GetCmdResult(const string & strCmd)109 string CellularDataTest::GetCmdResult(const string &strCmd)
110 {
111     char buf[10240] = {0};
112     FILE *pf;
113     char *fgetsRet;
114 
115     if ((pf = popen(strCmd.c_str(), "r")) == nullptr) {
116         return "";
117     }
118     string strResult;
119     while ((fgetsRet = fgets(buf, sizeof buf, pf)) != nullptr) {
120         strResult += buf;
121     }
122     pclose(pf);
123     unsigned int iSize = strResult.size();
124     if (iSize > 0 && strResult[iSize - 1] == '\n') {
125         strResult = strResult.substr(0, iSize - 1);
126     }
127     return strResult;
128 }
129 
PingTest()130 int32_t CellularDataTest::PingTest()
131 {
132     string strCmd = "ping -c3 www.openharmony.cn";
133     string strRe = GetCmdResult(strCmd);
134     std::cout << strRe << std::endl;
135 
136     // if ping succeed, the result should contains something like:
137     // 3 packets transmitted, 3 received, 0% packet loss, time 5440ms
138     if (strRe.find("3 received") != string::npos) {
139         return PING_CHECK_SUCCESS;
140     } else {
141         return PING_CHECK_FAIL;
142     }
143 }
144 
IsCellularDataRoamingEnabledTest(int32_t slotId)145 int32_t CellularDataTest::IsCellularDataRoamingEnabledTest(int32_t slotId)
146 {
147     if (proxy_ == nullptr) {
148         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
149     }
150     int32_t result = proxy_->IsCellularDataRoamingEnabled(slotId);
151     return result;
152 }
153 
IsCellularDataEnabledTest()154 int32_t CellularDataTest::IsCellularDataEnabledTest()
155 {
156     if (proxy_ == nullptr) {
157         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
158     }
159     int32_t result = proxy_->IsCellularDataEnabled();
160     return result;
161 }
162 
EnableCellularDataTest(bool enable)163 int32_t CellularDataTest::EnableCellularDataTest(bool enable)
164 {
165     if (proxy_ == nullptr) {
166         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
167     }
168     int32_t result = proxy_->EnableCellularData(enable);
169     return result;
170 }
171 
GetCellularDataStateTest()172 int32_t CellularDataTest::GetCellularDataStateTest()
173 {
174     if (proxy_ == nullptr) {
175         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
176     }
177     int32_t result = proxy_->GetCellularDataState();
178     return result;
179 }
180 
EnableCellularDataRoamingTest(int32_t slotId,bool enable)181 int32_t CellularDataTest::EnableCellularDataRoamingTest(int32_t slotId, bool enable)
182 {
183     if (proxy_ == nullptr) {
184         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
185     }
186     return proxy_->EnableCellularDataRoaming(slotId, enable);
187 }
188 
GetDefaultCellularDataSlotIdTest()189 int32_t CellularDataTest::GetDefaultCellularDataSlotIdTest()
190 {
191     if (proxy_ == nullptr) {
192         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
193     }
194     return proxy_->GetDefaultCellularDataSlotId();
195 }
196 
SetDefaultCellularDataSlotIdTest(int32_t slotId)197 int32_t CellularDataTest::SetDefaultCellularDataSlotIdTest(int32_t slotId)
198 {
199     if (proxy_ == nullptr) {
200         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
201     }
202     return proxy_->SetDefaultCellularDataSlotId(slotId);
203 }
204 
GetCellularDataFlowTypeTest()205 int32_t CellularDataTest::GetCellularDataFlowTypeTest()
206 {
207     if (proxy_ == nullptr) {
208         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
209     }
210     return proxy_->GetCellularDataFlowType();
211 }
212 
GetProxy()213 sptr<ICellularDataManager> CellularDataTest::GetProxy()
214 {
215     sptr<ISystemAbilityManager> systemAbilityMgr =
216         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
217     if (systemAbilityMgr == nullptr) {
218         return nullptr;
219     }
220     sptr<IRemoteObject> remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_DATA_SYS_ABILITY_ID);
221     if (remote) {
222         sptr<ICellularDataManager> dataManager = iface_cast<ICellularDataManager>(remote);
223         return dataManager;
224     }
225     return nullptr;
226 }
227 
228 #ifndef TEL_TEST_UNSUPPORT
229 /**
230  * @tc.number   GetProxy_Test
231  * @tc.name     Check whether the cellular data service(SystemAbility) is started
232  * @tc.desc     Function test
233  */
234 HWTEST_F(CellularDataTest, GetProxy_Test, TestSize.Level1)
235 {
236     CellularDataTest::proxy_ = CellularDataTest::GetProxy();
237     ASSERT_FALSE(CellularDataTest::proxy_ == nullptr);
238 }
239 
240 /**
241  * @tc.number   IsCellularDataEnabled_Test
242  * @tc.name     Test cellular data switch status(enabled or disabled)
243  * @tc.desc     Function test
244  */
245 HWTEST_F(CellularDataTest, IsCellularDataEnabled_Test, TestSize.Level1)
246 {
247     int32_t result = CellularDataTest::IsCellularDataEnabledTest();
248     ASSERT_TRUE(result >= static_cast<int32_t>(DataSwitchCode::CELLULAR_DATA_DISABLED));
249 }
250 
251 /**
252  * @tc.number   DefaultCellularDataSlotId_Test
253  * @tc.name     Test set default data card slot
254  * @tc.desc     Function test
255  */
256 HWTEST_F(CellularDataTest, DefaultCellularDataSlotId_Test, TestSize.Level2)
257 {
258     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
259         return;
260     }
261     int32_t result = CellularDataTest::GetDefaultCellularDataSlotIdTest();
262     if (result < DEFAULT_SIM_SLOT_ID) {
263         return;
264     }
265     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
266     ASSERT_TRUE(result == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
267     // Multiple cards will need to be optimized again
268     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID - 1);
269     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
270     result = CellularDataTest::SetDefaultCellularDataSlotIdTest(DATA_SLOT_ID_INVALID);
271     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
272 }
273 
274 /**
275  * @tc.number   EnableCellularData_Test
276  * @tc.name     Test cellular data switch
277  * @tc.desc     Function test
278  */
279 HWTEST_F(CellularDataTest, EnableCellularData_Test, TestSize.Level2)
280 {
281     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
282         return;
283     }
284     int32_t enabled = CellularDataTest::IsCellularDataEnabledTest();
285     if (enabled == static_cast<int32_t>(DataSwitchCode::CELLULAR_DATA_ENABLED)) {
286         // It takes seconds after being enabled for the connection status
287         // changed to DATA_STATE_CONNECTED, so we must wait it out before excecuting ping check
288         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
289         sleep(SLEEP_TIME);
290         std::cout << "Cellular Data Connected Ping..." << std::endl;
291         int32_t pingResult = CellularDataTest::PingTest();
292         ASSERT_TRUE(pingResult == PING_CHECK_SUCCESS);
293         int32_t disabled = CellularDataTest::EnableCellularDataTest(false);
294         ASSERT_TRUE(disabled == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
295         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
296         sleep(SLEEP_TIME);
297         std::cout << "Cellular Data Disconnected Ping..." << std::endl;
298         pingResult = CellularDataTest::PingTest();
299         ASSERT_TRUE(pingResult == PING_CHECK_FAIL);
300     } else {
301         int32_t result = CellularDataTest::EnableCellularDataTest(true);
302         ASSERT_TRUE(result == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
303         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
304         sleep(SLEEP_TIME);
305         std::cout << "Cellular Data Connected Ping..." << std::endl;
306         int32_t pingResult = CellularDataTest::PingTest();
307         ASSERT_TRUE(pingResult == PING_CHECK_SUCCESS);
308         CellularDataTest::EnableCellularDataTest(false);
309         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
310         sleep(SLEEP_TIME);
311         std::cout << "Cellular Data Disconnected Ping..." << std::endl;
312         pingResult = CellularDataTest::PingTest();
313         ASSERT_TRUE(pingResult == PING_CHECK_FAIL);
314     }
315 }
316 
317 /**
318  * @tc.number   DataRoamingState_ValidSlot_Test_01
319  * @tc.name     Test the cellular data roaming switch with a slot id
320  * @tc.desc     Function test
321  */
322 HWTEST_F(CellularDataTest, DataRoamingState_ValidSlot_Test_01, TestSize.Level3)
323 {
324     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
325         return;
326     }
327     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
328     int32_t disabled = CellularDataTest::EnableCellularDataTest(false);
329     ASSERT_TRUE(disabled == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
330     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
331 
332     // slot1 enable data roaming
333     int32_t enabled = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, true);
334     ASSERT_TRUE(enabled == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
335     int32_t result = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID);
336     ASSERT_TRUE(result == static_cast<int32_t>(RoamingSwitchCode::CELLULAR_DATA_ROAMING_ENABLED));
337     // slot1 close
338     int32_t enable = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, false);
339     ASSERT_TRUE(enable == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
340     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID);
341     ASSERT_TRUE(result == static_cast<int32_t>(RoamingSwitchCode::CELLULAR_DATA_ROAMING_DISABLED));
342 
343     // At present, multiple card problems, the subsequent need to continue to deal with
344     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
345     ASSERT_TRUE(enable == CELLULAR_DATA_INVALID_PARAM);
346     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID);
347     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
348     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
349     // At present, multiple card problems, the subsequent need to continue to deal with
350     ASSERT_TRUE(enable == CELLULAR_DATA_INVALID_PARAM);
351     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID);
352     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
353 }
354 
355 /**
356  * @tc.number   EnableCellularDataRoaming_ValidSlot_Test_01
357  * @tc.name     Test the cellular data roaming switch with a slot id
358  * @tc.desc     Function test
359  */
360 HWTEST_F(CellularDataTest, EnableCellularDataRoaming_ValidSlot_Test_01, TestSize.Level3)
361 {
362     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
363         return;
364     }
365     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
366     int32_t disabled = CellularDataTest::EnableCellularDataTest(false);
367     ASSERT_TRUE(disabled == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
368     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
369 
370     int32_t isDataRoaming = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID);
371     if (isDataRoaming == static_cast<int32_t>(DataSwitchCode::CELLULAR_DATA_ENABLED)) {
372         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, false);
373         ASSERT_TRUE(result == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
374     } else {
375         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID, true);
376         ASSERT_TRUE(result == static_cast<int32_t>(DataRespondCode::SET_SUCCESS));
377     }
378     // At present, multiple card problems, the subsequent need to continue to deal with
379     isDataRoaming = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID);
380     if (isDataRoaming == static_cast<int32_t>(DataSwitchCode::CELLULAR_DATA_ENABLED)) {
381         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
382         ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
383     } else {
384         int32_t result = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
385         ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
386     }
387 }
388 
389 /**
390  * @tc.number   GetCellularDataState_ValidityTest_01
391  * @tc.name     Test the GetCellularDataState function
392  * @tc.desc     Function test
393  */
394 HWTEST_F(CellularDataTest, GetCellularDataState_ValidityTest_01, TestSize.Level3)
395 {
396     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
397         return;
398     }
399     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
400     int32_t enabled = CellularDataTest::IsCellularDataEnabledTest();
401     if (enabled == static_cast<int32_t>(DataSwitchCode::CELLULAR_DATA_ENABLED)) {
402         CellularDataTest::EnableCellularDataTest(false);
403         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
404         sleep(SLEEP_TIME);
405         CellularDataTest::EnableCellularDataTest(true);
406         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
407         int32_t result = CellularDataTest::GetCellularDataStateTest();
408         ASSERT_TRUE(result == static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
409     } else {
410         CellularDataTest::EnableCellularDataTest(true);
411         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
412         sleep(SLEEP_TIME);
413         CellularDataTest::EnableCellularDataTest(false);
414         WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
415         int32_t result = CellularDataTest::GetCellularDataStateTest();
416         ASSERT_TRUE(result == static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
417     }
418     CellularDataTest::EnableCellularDataTest(false);
419     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
420 }
421 
422 /**
423  * @tc.number   DataRoamingState_InValidSlot_Test_01
424  * @tc.name     Test the EnableCellularDataRoaming function with a invalid slot id
425  * @tc.desc     Function test
426  */
427 HWTEST_F(CellularDataTest, DataRoamingState_InValidSlot_Test_01, TestSize.Level3)
428 {
429     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
430         return;
431     }
432     // invalid slot turn on data roaming
433     int32_t enable = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID -1, true);
434     ASSERT_TRUE(enable == CELLULAR_DATA_INVALID_PARAM);
435     int32_t result = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID -1);
436     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
437     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, true);
438     ASSERT_TRUE(enable == CELLULAR_DATA_INVALID_PARAM);
439     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID);
440     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
441     // invalid slot disable roaming
442     enable = CellularDataTest::EnableCellularDataRoamingTest(DEFAULT_SIM_SLOT_ID -1, false);
443     ASSERT_TRUE(enable == CELLULAR_DATA_INVALID_PARAM);
444     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DEFAULT_SIM_SLOT_ID -1);
445     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
446     enable = CellularDataTest::EnableCellularDataRoamingTest(DATA_SLOT_ID_INVALID, false);
447     ASSERT_TRUE(enable == CELLULAR_DATA_INVALID_PARAM);
448     result = CellularDataTest::IsCellularDataRoamingEnabledTest(DATA_SLOT_ID_INVALID);
449     ASSERT_TRUE(result == CELLULAR_DATA_INVALID_PARAM);
450 }
451 
452 /**
453  * @tc.number   DataFlowType_Test_01
454  * @tc.name     Test the GetCellularDataFlowType function
455  * @tc.desc     Function test
456  */
457 HWTEST_F(CellularDataTest, DataFlowType_Test_01, TestSize.Level3)
458 {
459     if (!CoreServiceClient::GetInstance().HasSimCard(DEFAULT_SIM_SLOT_ID)) {
460         return;
461     }
462     CellularDataTest::SetDefaultCellularDataSlotIdTest(DEFAULT_SIM_SLOT_ID);
463     CellularDataTest::EnableCellularDataTest(false);
464     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
465     sleep(SLEEP_TIME);
466 
467     CellularDataTest::EnableCellularDataTest(true);
468     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_CONNECTED));
469     sleep(SLEEP_TIME);
470     std::cout << "Cellular Data Connected Ping..." << std::endl;
471     int32_t pingResult = CellularDataTest::PingTest();
472     ASSERT_TRUE(pingResult == PING_CHECK_SUCCESS);
473     int32_t dataFlowType = CellularDataTest::GetCellularDataFlowTypeTest();
474     ASSERT_TRUE(dataFlowType >= 0);
475 
476     CellularDataTest::EnableCellularDataTest(false);
477     WaitTestTimeout(static_cast<int32_t>(DataConnectionStatus::DATA_STATE_DISCONNECTED));
478     sleep(SLEEP_TIME);
479     std::cout << "Cellular Data Disconnected Ping..." << std::endl;
480     pingResult = CellularDataTest::PingTest();
481     ASSERT_TRUE(pingResult == PING_CHECK_FAIL);
482     dataFlowType = CellularDataTest::GetCellularDataFlowTypeTest();
483     ASSERT_TRUE(dataFlowType == 0);
484 }
485 #else // TEL_TEST_UNSUPPORT
486 /**
487  * @tc.number   DataMock_Test_01
488  * @tc.name     Test for unsupport platform
489  * @tc.desc     Function test
490  */
491 HWTEST_F(CellularDataTest, DataMock_Test_01, TestSize.Level3)
492 {
493     EXPECT_TRUE(true);
494 }
495 #endif // TEL_TEST_UNSUPPORT
496 } // namespace Telephony
497 } // namespace OHOS
498