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