1 /*
2 * Copyright (C) 2021-2023 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 "gtest/gtest.h"
17 #include <random>
18
19 #define private public
20 #define protected public
21 #include "cellular_call_callback.h"
22 #include "cellular_call_handler.h"
23 #include "cellular_call_proxy.h"
24 #include "cellular_call_register.h"
25 #include "cellular_call_service.h"
26 #include "cellular_call_supplement.h"
27 #include "config_request.h"
28 #include "core_service_client.h"
29 #include "cs_control.h"
30 #include "tel_ril_call_parcel.h"
31 #include "operator_config_types.h"
32 #include "radio_event.h"
33 #include "securec.h"
34 #include "sim_state_type.h"
35 #include "system_ability_definition.h"
36 #include "token.h"
37
38 namespace OHOS {
39 namespace Telephony {
40 using namespace testing::ext;
41 const int32_t SIM1_SLOTID = 0;
42 const int32_t SIM2_SLOTID = 1;
43 const int32_t INVALID_SLOTID = 0xFF;
44 const int32_t SUCCESS_RESULT = 0;
45 const int32_t ERROR_RESULT = 1;
46 const int32_t USSD_MODE_NOTIFY = 0;
47 const std::string PHONE_NUMBER = "0000000";
48
49 class Cs2Test : public testing::Test {
50 public:
51 static void SetUpTestCase();
52 static void TearDownTestCase();
53 void SetUp();
54 void TearDown();
55 int32_t TestDialCallByCs(int32_t slotId, std::string code);
HasSimCard(int32_t slotId)56 bool HasSimCard(int32_t slotId)
57 {
58 bool hasSimCard = false;
59 DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
60 return hasSimCard;
61 }
62 int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo);
63 };
64
TestDialCallByCs(int32_t slotId,std::string code)65 int32_t Cs2Test::TestDialCallByCs(int32_t slotId, std::string code)
66 {
67 AccessToken token;
68 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
69 if (systemAbilityMgr == nullptr) {
70 return TELEPHONY_ERR_FAIL;
71 }
72 auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
73 if (remote == nullptr) {
74 return TELEPHONY_ERR_FAIL;
75 }
76 auto telephonyService = iface_cast<CellularCallInterface>(remote);
77 if (telephonyService == nullptr) {
78 return TELEPHONY_ERR_FAIL;
79 }
80 CellularCallInfo callInfo;
81 int32_t ret = TELEPHONY_SUCCESS;
82 ret = InitCellularCallInfo(slotId, code, callInfo);
83 if (ret != TELEPHONY_SUCCESS) {
84 return ret;
85 }
86 // close ims, make this time use cs to test
87 ret = telephonyService->SetImsSwitchStatus(slotId, false);
88 if (ret != TELEPHONY_SUCCESS) {
89 return ret;
90 }
91 ret = telephonyService->Dial(callInfo);
92 return ret;
93 };
94
InitCellularCallInfo(int32_t accountId,std::string phonenumber,CellularCallInfo & callInfo)95 int32_t Cs2Test::InitCellularCallInfo(int32_t accountId, std::string phonenumber,
96 CellularCallInfo &callInfo)
97 {
98 callInfo.accountId = accountId;
99 callInfo.slotId = accountId;
100 callInfo.index = accountId;
101 callInfo.callType = CallType::TYPE_CS;
102 callInfo.videoState = 0; // 0 means audio
103 if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
104 return TELEPHONY_ERR_MEMSET_FAIL;
105 }
106 if (phonenumber.length() > static_cast<size_t>(kMaxNumberLen)) {
107 return CALL_ERR_NUMBER_OUT_OF_RANGE;
108 }
109 if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) {
110 return TELEPHONY_ERR_MEMCPY_FAIL;
111 }
112 return TELEPHONY_SUCCESS;
113 };
114
SetUpTestCase(void)115 void Cs2Test::SetUpTestCase(void)
116 {
117 // step 3: Set Up Test Case
118 }
119
TearDownTestCase(void)120 void Cs2Test::TearDownTestCase(void)
121 {
122 // step 3: Tear Down Test Case
123 }
124
SetUp(void)125 void Cs2Test::SetUp(void)
126 {
127 // step 3: input testcase setup step
128 }
129
TearDown(void)130 void Cs2Test::TearDown(void)
131 {
132 // step 3: input testcase teardown step
133 }
134
135 /**
136 * @tc.number cellular_call_HangUpAllConnection_0001
137 * @tc.name Test for hangup all connection function by cs
138 * @tc.desc Function test
139 */
140 HWTEST_F(Cs2Test, cellular_call_HangUpAllConnection_0001, Function | MediumTest | Level2)
141 {
142 AccessToken token;
143 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
144 ASSERT_TRUE(systemAbilityMgr != nullptr);
145 auto hangUpAllConRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
146 ASSERT_TRUE(hangUpAllConRemote != nullptr);
147 auto telephonyService = iface_cast<CellularCallInterface>(hangUpAllConRemote);
148 ASSERT_TRUE(telephonyService != nullptr);
149 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
150 return;
151 }
152 if (HasSimCard(SIM1_SLOTID)) {
153 int32_t ret = telephonyService->HangUpAllConnection();
154 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
155 }
156 if (HasSimCard(SIM2_SLOTID)) {
157 int32_t ret = telephonyService->HangUpAllConnection();
158 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
159 }
160 }
161
162 /**
163 * @tc.number cellular_call_GetDomainPreferenceMode_0001
164 * @tc.name Test for GetDomainPreferenceMode function by invalid slotId
165 * @tc.desc Function test
166 */
167 HWTEST_F(Cs2Test, cellular_call_GetDomainPreferenceMode_0001, Function | MediumTest | Level3)
168 {
169 AccessToken token;
170 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
171 ASSERT_TRUE(systemAbilityMgr != nullptr);
172 auto domainPrefModeRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
173 ASSERT_TRUE(domainPrefModeRemote != nullptr);
174 auto telephonyService = iface_cast<CellularCallInterface>(domainPrefModeRemote);
175 ASSERT_TRUE(telephonyService != nullptr);
176 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
177 return;
178 }
179 if (HasSimCard(SIM1_SLOTID)) {
180 int32_t ret = telephonyService->GetDomainPreferenceMode(INVALID_SLOTID);
181 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID);
182 }
183 if (HasSimCard(SIM2_SLOTID)) {
184 int32_t ret = telephonyService->GetDomainPreferenceMode(INVALID_SLOTID);
185 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID);
186 }
187 }
188
189 /**
190 * @tc.number cellular_call_GetDomainPreferenceMode_0002
191 * @tc.name Test for GetDomainPreferenceMode function by valid slotId
192 * @tc.desc Function test
193 */
194 HWTEST_F(Cs2Test, cellular_call_GetDomainPreferenceMode_0002, Function | MediumTest | Level3)
195 {
196 AccessToken token;
197 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
198 return;
199 }
200 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
201 ASSERT_TRUE(systemAbilityMgr != nullptr);
202 auto domainPrefModeRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
203 ASSERT_TRUE(domainPrefModeRemote != nullptr);
204 auto telephonyService = iface_cast<CellularCallInterface>(domainPrefModeRemote);
205 ASSERT_TRUE(telephonyService != nullptr);
206 if (HasSimCard(SIM1_SLOTID)) {
207 int32_t ret = telephonyService->GetDomainPreferenceMode(SIM1_SLOTID);
208 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
209 }
210 if (HasSimCard(SIM2_SLOTID)) {
211 int32_t ret = telephonyService->GetDomainPreferenceMode(SIM2_SLOTID);
212 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
213 }
214 }
215
216 /**
217 * @tc.number cellular_call_GetMute_0001
218 * @tc.name Test for GetMute function by invalid slotId
219 * @tc.desc Function test
220 */
221 HWTEST_F(Cs2Test, cellular_call_GetMute_0001, Function | MediumTest | Level3)
222 {
223 AccessToken token;
224 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
225 ASSERT_TRUE(systemAbilityMgr != nullptr);
226 auto getMuteRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
227 ASSERT_TRUE(getMuteRemote != nullptr);
228 auto telephonyService = iface_cast<CellularCallInterface>(getMuteRemote);
229 ASSERT_TRUE(telephonyService != nullptr);
230 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
231 return;
232 }
233 if (HasSimCard(SIM1_SLOTID)) {
234 int32_t ret = telephonyService->GetMute(INVALID_SLOTID);
235 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID);
236 }
237 if (HasSimCard(SIM2_SLOTID)) {
238 int32_t ret = telephonyService->GetMute(INVALID_SLOTID);
239 EXPECT_EQ(ret, CALL_ERR_INVALID_SLOT_ID);
240 }
241 }
242
243 /**
244 * @tc.number cellular_call_GetMute_0002
245 * @tc.name Test for GetMute function by valid slotId
246 * @tc.desc Function test
247 */
248 HWTEST_F(Cs2Test, cellular_call_GetMute_0002, Function | MediumTest | Level3)
249 {
250 AccessToken token;
251 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
252 return;
253 }
254 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
255 ASSERT_TRUE(systemAbilityMgr != nullptr);
256 auto getMuteRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
257 ASSERT_TRUE(getMuteRemote != nullptr);
258 auto telephonyService = iface_cast<CellularCallInterface>(getMuteRemote);
259 ASSERT_TRUE(telephonyService != nullptr);
260 if (HasSimCard(SIM1_SLOTID)) {
261 int32_t ret = telephonyService->GetMute(SIM1_SLOTID);
262 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
263 }
264 if (HasSimCard(SIM2_SLOTID)) {
265 int32_t ret = telephonyService->GetMute(SIM2_SLOTID);
266 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
267 }
268 }
269
270 /**
271 * @tc.number cellular_call_CellularCallConnectionCS_0001
272 * @tc.name Test for CellularCallConnectionCS
273 * @tc.desc Function test
274 */
275 HWTEST_F(Cs2Test, cellular_call_CellularCallConnectionCS_0001, Function | MediumTest | Level3)
276 {
277 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
278 ASSERT_TRUE(systemAbilityMgr != nullptr);
279 auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
280 ASSERT_TRUE(remote != nullptr);
281 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
282 return;
283 }
284
285 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
286 if (!HasSimCard(slotId)) {
287 continue;
288 }
289 CellularCallConnectionCS csConnection;
290 EXPECT_EQ(csConnection.SendDtmfRequest(slotId, '1', 1), CALL_ERR_RESOURCE_UNAVAILABLE);
291 EXPECT_EQ(csConnection.StartDtmfRequest(slotId, '1', 1), CALL_ERR_RESOURCE_UNAVAILABLE);
292 EXPECT_EQ(csConnection.StopDtmfRequest(slotId, 1), CALL_ERR_RESOURCE_UNAVAILABLE);
293 EXPECT_EQ(csConnection.GetCsCallsDataRequest(slotId, 1), CALL_ERR_RESOURCE_UNAVAILABLE);
294 EXPECT_EQ(csConnection.GetCallFailReasonRequest(slotId), CALL_ERR_RESOURCE_UNAVAILABLE);
295 MMICodeUtils utils;
296 ASSERT_FALSE(utils.IsNeedExecuteMmi("", false));
297 ASSERT_FALSE(utils.ExecuteMmiCode(slotId));
298 }
299 }
300
301 /**
302 * @tc.number cellular_call_CellularCallRegister_0001
303 * @tc.name Test for CellularCallRegister
304 * @tc.desc Function test
305 */
306 HWTEST_F(Cs2Test, cellular_call_CellularCallRegister_0001, Function | MediumTest | Level3)
307 {
308 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
309 ASSERT_TRUE(systemAbilityMgr != nullptr);
310 auto cellularCallRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
311 ASSERT_TRUE(cellularCallRemote != nullptr);
312 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
313 return;
314 }
315 auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
316 ASSERT_TRUE(callRegister != nullptr);
317 CellularCallEventInfo callEvent;
318 callRegister->ReportEventResultInfo(callEvent);
319 CallWaitResponse waitResponse;
320 callRegister->ReportGetWaitingResult(waitResponse);
321 callRegister->ReportSetWaitingResult(ERROR_RESULT);
322 CallRestrictionResponse restrictionResponse;
323 callRegister->ReportGetRestrictionResult(restrictionResponse);
324 callRegister->ReportSetRestrictionResult(ERROR_RESULT);
325 callRegister->ReportSetBarringPasswordResult(ERROR_RESULT);
326 CallTransferResponse transferResponse;
327 callRegister->ReportGetTransferResult(transferResponse);
328 callRegister->ReportSetTransferResult(ERROR_RESULT);
329 ClipResponse clipResponse;
330 callRegister->ReportGetClipResult(clipResponse);
331 ClirResponse clirResponse;
332 callRegister->ReportGetClirResult(clirResponse);
333 callRegister->ReportSetClirResult(ERROR_RESULT);
334 callRegister->ReportCallRingBackResult(ERROR_RESULT);
335 DisconnectedDetails details;
336 callRegister->ReportCallFailReason(details);
337 MuteControlResponse muteResponse;
338 callRegister->ReportSetMuteResult(muteResponse);
339 callRegister->ReportGetMuteResult(muteResponse);
340 callRegister->ReportInviteToConferenceResult(ERROR_RESULT);
341 callRegister->ReportGetCallDataResult(ERROR_RESULT);
342 callRegister->ReportStartDtmfResult(ERROR_RESULT);
343 callRegister->ReportStopDtmfResult(ERROR_RESULT);
344 callRegister->ReportStartRttResult(ERROR_RESULT);
345 callRegister->ReportStopRttResult(ERROR_RESULT);
346 callRegister->ReportSendUssdResult(ERROR_RESULT);
347 SetEccListResponse eccListResponse;
348 callRegister->ReportSetEmergencyCallListResponse(eccListResponse);
349 MmiCodeInfo mmiInfo;
350 callRegister->ReportMmiCodeResult(mmiInfo);
351 ASSERT_FALSE(callRegister->IsCallManagerCallBackRegistered());
352 }
353
354 /**
355 * @tc.number cellular_call_CellularCallRegister_0002
356 * @tc.name Test for CellularCallRegister
357 * @tc.desc Function test
358 */
359 HWTEST_F(Cs2Test, cellular_call_CellularCallRegister_0002, Function | MediumTest | Level3)
360 {
361 auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
362 CallReportInfo callRepotInfo;
363 callRepotInfo.callType = CallType::TYPE_CS;
364 callRepotInfo.accountId = INVALID_SLOTID;
365 callRepotInfo.state = TelCallState::CALL_STATUS_INCOMING;
366 callRepotInfo.callMode = VideoStateType::TYPE_VOICE;
367 CallsReportInfo calls;
368 calls.slotId = INVALID_SLOTID;
369 calls.callVec.push_back(callRepotInfo);
370 callRegister->ReportCallsInfo(calls);
371 callRegister->ReportSingleCallInfo(callRepotInfo, TelCallState::CALL_STATUS_INCOMING);
372 EXPECT_EQ(callRegister->RegisterCallManagerCallBack(nullptr), TELEPHONY_SUCCESS);
373 EXPECT_EQ(callRegister->UnRegisterCallManagerCallBack(), TELEPHONY_SUCCESS);
374 }
375
376 /**
377 * @tc.number cellular_call_SupplementRequestCs_0001
378 * @tc.name Test for SupplementRequestCs
379 * @tc.desc Function test
380 */
381 HWTEST_F(Cs2Test, cellular_call_SupplementRequestCs_0001, Function | MediumTest | Level3)
382 {
383 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
384 return;
385 }
386
387 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
388 if (!HasSimCard(slotId)) {
389 continue;
390 }
391 SupplementRequestCs request;
392 std::string fac = "fac";
393 std::string pw = "test";
394 int32_t index = 1;
395 int32_t mode = 1;
396 int32_t classType = 1;
397 const char *oldPassword = "oldpwd";
398 const char *newPassword = "newpwd";
399 bool active = true;
400 CallTransferParam param;
401 EXPECT_NE(request.GetCallRestrictionRequest(slotId, fac, index), TELEPHONY_SUCCESS);
402 EXPECT_NE(request.SetCallRestrictionRequest(slotId, fac, mode, pw, index), TELEPHONY_SUCCESS);
403 EXPECT_NE(request.SetBarringPasswordRequest(slotId, fac, index, oldPassword, newPassword), TELEPHONY_SUCCESS);
404 EXPECT_NE(request.GetCallWaitingRequest(slotId, index), TELEPHONY_SUCCESS);
405 EXPECT_NE(request.SetCallWaitingRequest(slotId, active, classType, index), TELEPHONY_SUCCESS);
406 EXPECT_NE(request.GetClipRequest(slotId, index), TELEPHONY_SUCCESS);
407 EXPECT_NE(request.GetClirRequest(slotId, index), TELEPHONY_SUCCESS);
408 EXPECT_NE(request.SetClirRequest(slotId, mode, index), TELEPHONY_SUCCESS);
409 EXPECT_NE(request.GetCallTransferRequest(slotId, mode, index), TELEPHONY_SUCCESS);
410 EXPECT_NE(request.SetCallTransferRequest(slotId, param, index), TELEPHONY_SUCCESS);
411 }
412 }
413
414 /**
415 * @tc.number cellular_call_ConfigRequest_0001
416 * @tc.name Test for ConfigRequest
417 * @tc.desc Function test
418 */
419 HWTEST_F(Cs2Test, cellular_call_ConfigRequest_0001, Function | MediumTest | Level3)
420 {
421 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
422 return;
423 }
424
425 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
426 if (!HasSimCard(slotId)) {
427 continue;
428 }
429 ConfigRequest config;
430 int32_t mode = 1;
431 EXPECT_NE(config.SetDomainPreferenceModeRequest(slotId, mode), TELEPHONY_SUCCESS);
432 EXPECT_NE(config.GetDomainPreferenceModeRequest(slotId), TELEPHONY_SUCCESS);
433 EXPECT_NE(config.SetMuteRequest(slotId, mode), TELEPHONY_SUCCESS);
434 EXPECT_NE(config.GetMuteRequest(slotId), TELEPHONY_SUCCESS);
435 }
436 }
437
438 /**
439 * @tc.number cellular_call_CellularCallSupplement_0001
440 * @tc.name Test for CellularCallSupplement
441 * @tc.desc Function test
442 */
443 HWTEST_F(Cs2Test, cellular_call_CellularCallSupplement_0001, Function | MediumTest | Level3)
444 {
445 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
446 return;
447 }
448
449 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
450 if (!HasSimCard(slotId)) {
451 continue;
452 }
453 MMIData mmiData;
454 CellularCallSupplement supplement;
455 mmiData.actionString = "";
456 supplement.AlterPinPassword(slotId, mmiData);
457 supplement.AlterPin2Password(slotId, mmiData);
458 supplement.UnlockPuk(slotId, mmiData);
459 supplement.UnlockPuk2(slotId, mmiData);
460 mmiData.actionString = "test";
461 mmiData.serviceInfoA = "infoA";
462 mmiData.serviceInfoB = "infoB";
463 mmiData.serviceInfoC = "infoC";
464 supplement.AlterPinPassword(slotId, mmiData);
465 supplement.AlterPin2Password(slotId, mmiData);
466 supplement.UnlockPuk(slotId, mmiData);
467 supplement.UnlockPuk2(slotId, mmiData);
468 mmiData.serviceInfoC = "infoB";
469 supplement.AlterPinPassword(slotId, mmiData);
470 supplement.AlterPin2Password(slotId, mmiData);
471 supplement.UnlockPuk(slotId, mmiData);
472 supplement.UnlockPuk2(slotId, mmiData);
473 ASSERT_FALSE(supplement.IsVaildPinOrPuk("B", "B"));
474 EXPECT_NE(supplement.SendUssd(slotId, "test"), TELEPHONY_SUCCESS);
475 }
476 }
477
478 /**
479 * @tc.number cellular_call_CellularCallSupplement_0002
480 * @tc.name Test for CellularCallSupplement
481 * @tc.desc Function test
482 */
483 HWTEST_F(Cs2Test, cellular_call_CellularCallSupplement_0002, Function | MediumTest | Level3)
484 {
485 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
486 return;
487 }
488
489 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
490 if (!HasSimCard(slotId)) {
491 continue;
492 }
493 CellularCallSupplement supplement;
494 supplement.ObtainBarringInstallation("33");
495 supplement.ObtainBarringInstallation("331");
496 supplement.ObtainBarringInstallation("332");
497 supplement.ObtainBarringInstallation("351");
498 supplement.ObtainBarringInstallation("35");
499 supplement.ObtainBarringInstallation("330");
500 supplement.ObtainBarringInstallation("333");
501 supplement.ObtainBarringInstallation("353");
502 supplement.ObtainBarringInstallation("1000");
503
504 EXPECT_NE(supplement.ObtainServiceCode("10"), TELEPHONY_SUCCESS);
505 EXPECT_NE(supplement.ObtainServiceCode("11"), TELEPHONY_SUCCESS);
506 EXPECT_NE(supplement.ObtainServiceCode("12"), TELEPHONY_SUCCESS);
507 EXPECT_NE(supplement.ObtainServiceCode("13"), TELEPHONY_SUCCESS);
508 EXPECT_NE(supplement.ObtainServiceCode("16"), TELEPHONY_SUCCESS);
509 EXPECT_NE(supplement.ObtainServiceCode("19"), TELEPHONY_SUCCESS);
510 EXPECT_NE(supplement.ObtainServiceCode("20"), TELEPHONY_SUCCESS);
511 EXPECT_NE(supplement.ObtainServiceCode("21"), TELEPHONY_SUCCESS);
512 EXPECT_NE(supplement.ObtainServiceCode("22"), TELEPHONY_SUCCESS);
513 EXPECT_NE(supplement.ObtainServiceCode("24"), TELEPHONY_SUCCESS);
514 EXPECT_NE(supplement.ObtainServiceCode("25"), TELEPHONY_SUCCESS);
515 EXPECT_NE(supplement.ObtainServiceCode("99"), TELEPHONY_SUCCESS);
516 EXPECT_EQ(supplement.ObtainServiceCode("100"), TELEPHONY_SUCCESS);
517
518 EXPECT_EQ(supplement.ObtainCause("21"), TELEPHONY_SUCCESS);
519 EXPECT_NE(supplement.ObtainCause("61"), TELEPHONY_SUCCESS);
520 EXPECT_NE(supplement.ObtainCause("62"), TELEPHONY_SUCCESS);
521 EXPECT_NE(supplement.ObtainCause("67"), TELEPHONY_SUCCESS);
522 EXPECT_EQ(supplement.ObtainCause("99"), TELEPHONY_ERROR);
523 }
524 }
525
526 /**
527 * @tc.number cellular_call_CellularCallSupplement_0003
528 * @tc.name Test for CellularCallSupplement
529 * @tc.desc Function test
530 */
531 HWTEST_F(Cs2Test, cellular_call_CellularCallSupplement_0003, Function | MediumTest | Level3)
532 {
533 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
534 return;
535 }
536
537 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
538 if (!HasSimCard(slotId)) {
539 continue;
540 }
541 CellularCallSupplement supplement;
542 std::string action = "*";
543 std::string number = "";
544 CallTransferSettingType type;
545 EXPECT_EQ(supplement.ObtainCallTrasferAction(action.c_str(), number, type), TELEPHONY_SUCCESS);
546 EXPECT_EQ(supplement.ObtainCallTrasferAction(action.c_str(), PHONE_NUMBER, type), TELEPHONY_SUCCESS);
547 action = "#";
548 EXPECT_EQ(supplement.ObtainCallTrasferAction(action.c_str(), number, type), TELEPHONY_SUCCESS);
549 action = "**";
550 EXPECT_EQ(supplement.ObtainCallTrasferAction(action.c_str(), number, type), TELEPHONY_SUCCESS);
551 action = "##";
552 EXPECT_EQ(supplement.ObtainCallTrasferAction(action.c_str(), number, type), TELEPHONY_SUCCESS);
553 action = "*#";
554 EXPECT_NE(supplement.ObtainCallTrasferAction(action.c_str(), number, type), TELEPHONY_SUCCESS);
555 }
556 }
557
558 /**
559 * @tc.number cellular_call_CellularCallHandler_0001
560 * @tc.name Test for CellularCallHandler
561 * @tc.desc Function test
562 */
563 HWTEST_F(Cs2Test, cellular_call_CellularCallHandler_0001, Function | MediumTest | Level3)
564 {
565 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
566 return;
567 }
568
569 EventFwk::MatchingSkills matchingSkills;
570 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
571 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
572 CellularCallHandler firstHandler { subscriberInfo };
573 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
574 if (!HasSimCard(slotId)) {
575 continue;
576 }
577 firstHandler.SetSlotId(slotId);
578 auto event = AppExecFwk::InnerEvent::Get(0);
579 auto rilRadioResponse = std::make_shared<RadioResponseInfo>();
580 rilRadioResponse->error = ErrType::ERR_GENERIC_FAILURE;
581 firstHandler.CellularCallIncomingStartTrace(static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING));
582 firstHandler.CellularCallIncomingFinishTrace(static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING));
583 firstHandler.GetCsCallsDataResponse(event);
584 firstHandler.GetCsCallsDataRequest(event);
585 firstHandler.GetMMIResponse(event);
586 auto ringbackResponse = std::make_shared<RingbackVoice>();
587 ringbackResponse->status = ERROR_RESULT;
588 auto ringbackEvent = AppExecFwk::InnerEvent::Get(0, ringbackResponse);
589 firstHandler.CallRingBackVoiceResponse(event);
590 firstHandler.CallRingBackVoiceResponse(ringbackEvent);
591 auto srvccStatus = std::make_shared<SrvccStatus>();
592 srvccStatus->status = SrvccState::SRVCC_NONE;
593 auto srvccEvent1 = AppExecFwk::InnerEvent::Get(0, srvccStatus);
594 firstHandler.UpdateSrvccStateReport(event);
595 firstHandler.UpdateSrvccStateReport(srvccEvent1);
596 srvccStatus->status = SrvccState::COMPLETED;
597 auto srvccEvent2 = AppExecFwk::InnerEvent::Get(0, srvccStatus);
598 firstHandler.UpdateSrvccStateReport(srvccEvent2);
599 firstHandler.UpdateRsrvccStateReport(event);
600 firstHandler.GetCallFailReasonResponse(event);
601 firstHandler.GetEmergencyCallListResponse(event);
602 firstHandler.ReportEccChanged(event);
603 firstHandler.SetEmergencyCallListResponse(event);
604 firstHandler.SendUssdResponse(event);
605 ASSERT_EQ(firstHandler.GetSlotId(), slotId);
606 }
607 }
608
609 /**
610 * @tc.number cellular_call_CellularCallHandler_0002
611 * @tc.name Test for CellularCallHandler
612 * @tc.desc Function test
613 */
614 HWTEST_F(Cs2Test, cellular_call_CellularCallHandler_0002, Function | MediumTest | Level3)
615 {
616 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
617 return;
618 }
619
620 EventFwk::MatchingSkills matchingSkills;
621 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
622 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
623 CellularCallHandler secondHandler { subscriberInfo };
624 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
625 if (!HasSimCard(slotId)) {
626 continue;
627 }
628 secondHandler.SetSlotId(slotId);
629 auto event = AppExecFwk::InnerEvent::Get(0);
630 auto rilRadioResponse = std::make_shared<RadioResponseInfo>();
631 rilRadioResponse->error = ErrType::ERR_GENERIC_FAILURE;
632 secondHandler.CommonResultResponse(event);
633 auto rejectEvent = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_REJECT_CALL, rilRadioResponse);
634 secondHandler.CommonResultResponse(rejectEvent);
635 auto supplementEvent = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_CALL_SUPPLEMENT, rilRadioResponse);
636 secondHandler.CommonResultResponse(supplementEvent);
637
638 rilRadioResponse->error = ErrType::NONE;
639 auto hangupConnectEvent = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_HANGUP_CONNECT, rilRadioResponse);
640 secondHandler.CommonResultResponse(hangupConnectEvent);
641 auto acceptEvent = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_ACCEPT_CALL, rilRadioResponse);
642 secondHandler.CommonResultResponse(acceptEvent);
643 auto splitNoErrorEvent = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SPLIT_CALL, rilRadioResponse);
644 secondHandler.CommonResultResponse(splitNoErrorEvent);
645
646 auto ssResult = std::make_shared<SsBaseResult>();
647 ssResult->index = INVALID_INDEX;
648 ssResult->result = SUCCESS_RESULT;
649 auto errorEvent = AppExecFwk::InnerEvent::Get(0, ssResult);
650 secondHandler.SetCallRestrictionResponse(event);
651 secondHandler.SetCallRestrictionResponse(errorEvent);
652 secondHandler.SetBarringPasswordResponse(event);
653 secondHandler.SetCallTransferInfoResponse(event);
654 secondHandler.SetCallWaitingResponse(event);
655 secondHandler.SetClipResponse(event);
656 secondHandler.SetClirResponse(event);
657 secondHandler.SetColpResponse(event);
658 secondHandler.SetColrResponse(event);
659
660 auto responseEvent = AppExecFwk::InnerEvent::Get(0, rilRadioResponse);
661 secondHandler.SetMuteResponse(event);
662 secondHandler.SetMuteResponse(responseEvent);
663 secondHandler.GetMuteResponse(event);
664 secondHandler.GetMuteResponse(responseEvent);
665 ASSERT_EQ(secondHandler.GetSlotId(), slotId);
666 }
667 }
668
669 /**
670 * @tc.number cellular_call_CellularCallHandler_0003
671 * @tc.name Test for CellularCallHandler
672 * @tc.desc Function test
673 */
674 HWTEST_F(Cs2Test, cellular_call_CellularCallHandler_0003, Function | MediumTest | Level3)
675 {
676 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
677 return;
678 }
679 EventFwk::MatchingSkills matchingSkills;
680 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
681 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
682 CellularCallHandler thirdhandler { subscriberInfo };
683 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
684 if (!HasSimCard(slotId)) {
685 continue;
686 }
687 thirdhandler.SetSlotId(slotId);
688 auto event = AppExecFwk::InnerEvent::Get(0);
689 auto ussdNoticeResponse = std::make_shared<UssdNoticeInfo>();
690 ussdNoticeResponse->m = USSD_MODE_NOTIFY;
691 ussdNoticeResponse->str = "tdd test";
692 auto successEvent = AppExecFwk::InnerEvent::Get(0, ussdNoticeResponse);
693 thirdhandler.UssdNotifyResponse(event);
694 thirdhandler.UssdNotifyResponse(successEvent);
695 ussdNoticeResponse->str = "";
696 auto errorEvent = AppExecFwk::InnerEvent::Get(0, ussdNoticeResponse);
697 thirdhandler.UssdNotifyResponse(errorEvent);
698
699 auto ssNoticeResponse = std::make_shared<SsNoticeInfo>();
700 ssNoticeResponse->result = ERROR_RESULT;
701 auto defaultEvent = AppExecFwk::InnerEvent::Get(0, ssNoticeResponse);
702 thirdhandler.SsNotifyResponse(event);
703 thirdhandler.SsNotifyResponse(defaultEvent);
704 ssNoticeResponse->requestType = SUCCESS_RESULT;
705 auto noticeErrorEvent = AppExecFwk::InnerEvent::Get(0, ssNoticeResponse);
706 thirdhandler.SsNotifyResponse(noticeErrorEvent);
707 ssNoticeResponse->result = SUCCESS_RESULT;
708 auto noticeDefaultEvent = AppExecFwk::InnerEvent::Get(0, ssNoticeResponse);
709 thirdhandler.SsNotifyResponse(noticeDefaultEvent);
710 ssNoticeResponse->serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_UNCONDITIONAL);
711 auto noticeUnconditinalEvent = AppExecFwk::InnerEvent::Get(0, ssNoticeResponse);
712 thirdhandler.SsNotifyResponse(noticeUnconditinalEvent);
713 ssNoticeResponse->serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_BUSY);
714 auto noticeBusyEvent = AppExecFwk::InnerEvent::Get(0, ssNoticeResponse);
715 thirdhandler.SsNotifyResponse(noticeBusyEvent);
716 ssNoticeResponse->serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NO_REPLY);
717 auto noticeNoReplyEvent = AppExecFwk::InnerEvent::Get(0, ssNoticeResponse);
718 thirdhandler.SsNotifyResponse(noticeNoReplyEvent);
719 ssNoticeResponse->serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NOT_REACHABLE);
720 auto noticeNotReachableEvent = AppExecFwk::InnerEvent::Get(0, ssNoticeResponse);
721 thirdhandler.SsNotifyResponse(noticeNotReachableEvent);
722 ASSERT_EQ(thirdhandler.GetSlotId(), slotId);
723 }
724 }
725
726 /**
727 * @tc.number cellular_call_CellularCallHandler_0004
728 * @tc.name Test for CellularCallHandler
729 * @tc.desc Function test
730 */
731 HWTEST_F(Cs2Test, cellular_call_CellularCallHandler_0004, Function | MediumTest | Level3)
732 {
733 EventFwk::MatchingSkills matchingSkills;
734 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
735 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
736 CellularCallHandler fourthHandler { subscriberInfo };
737 auto callInfoList = std::make_shared<CallInfoList>();
738 callInfoList->callSize = 1;
739 std::string expectedPhoneNumber = "+861565910xxxx";
740 std::string unexpectedPhoneNumber = "00861565910xxxx";
741 std::vector<CallInfo> callInfoLists;
742 CallInfo callInfo;
743 callInfo.number = unexpectedPhoneNumber;
744 callInfoLists.push_back(callInfo);
745 callInfoList->calls = callInfoLists;
746 fourthHandler.ProcessCsPhoneNumber(*callInfoList);
747 EXPECT_EQ(callInfoList->calls[0].number, expectedPhoneNumber);
748 auto callInfoListFirst = std::make_shared<CallInfoList>();
749 callInfoListFirst->callSize = 0;
750 callInfoLists.clear();
751 callInfo.number = unexpectedPhoneNumber;
752 callInfoLists.push_back(callInfo);
753 callInfoListFirst->calls = callInfoLists;
754 fourthHandler.ProcessCsPhoneNumber(*callInfoListFirst);
755 EXPECT_EQ(callInfoListFirst->calls[0].number, unexpectedPhoneNumber);
756 auto callInfoListSecond = std::make_shared<CallInfoList>();
757 callInfoListSecond->callSize = 1;
758 fourthHandler.ProcessCsPhoneNumber(*callInfoListSecond);
759 EXPECT_EQ(callInfoListSecond->callSize, 1);
760 auto callInfoListThird = std::make_shared<CallInfoList>();
761 callInfoListThird->callSize = 1;
762 expectedPhoneNumber = "+861565910xxxx";
763 unexpectedPhoneNumber = "123";
764 callInfoLists.clear();
765 callInfo.number = unexpectedPhoneNumber;
766 callInfoLists.push_back(callInfo);
767 callInfoListThird->calls = callInfoLists;
768 fourthHandler.ProcessCsPhoneNumber(*callInfoListThird);
769 EXPECT_EQ(callInfoListThird->calls[0].number, unexpectedPhoneNumber);
770 callInfoLists.clear();
771 unexpectedPhoneNumber = "0861565910xxxx";
772 callInfo.number = unexpectedPhoneNumber;
773 callInfoLists.push_back(callInfo);
774 callInfoListThird->calls = callInfoLists;
775 fourthHandler.ProcessCsPhoneNumber(*callInfoListThird);
776 EXPECT_EQ(callInfoListThird->calls[0].number, unexpectedPhoneNumber);
777 }
778
779 /**
780 * @tc.number cellular_call_CellularCallHandler_0005
781 * @tc.name Test for CellularCallHandler
782 * @tc.desc Function test
783 */
784 HWTEST_F(Cs2Test, cellular_call_CellularCallHandler_0005, Function | MediumTest | Level3)
785 {
786 EventFwk::MatchingSkills matchingSkills;
787 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
788 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
789 CellularCallHandler fifthHandler { subscriberInfo };
790 auto callInfoList = std::make_shared<CallInfoList>();
791 callInfoList->callSize = 1;
792 std::random_device rd;
793 std::mt19937 gen(rd());
794 std::uniform_int_distribution<> distrib(0, 9);
795 int randomNumber = 0;
796 int phonenumberLength = 8;
797 for (int i = 0; i < phonenumberLength; i++) {
798 randomNumber = randomNumber * 10 + distrib(gen);
799 }
800 std::string expectedPhoneNumber = "+86156" + std::to_string(randomNumber);
801 std::string unexpectedPhoneNumber = "+8686156" + std::to_string(randomNumber);
802 CallInfo callInfo;
803 callInfo.number = unexpectedPhoneNumber;
804 callInfo.type = 145;
805 callInfoList->calls.push_back(callInfo);
806 fifthHandler.ProcessRedundantCode(*callInfoList);
807 EXPECT_EQ(callInfoList->calls[0].number, expectedPhoneNumber);
808 callInfoList->calls[0].number = unexpectedPhoneNumber;
809 callInfoList->callSize = 0;
810 fifthHandler.ProcessRedundantCode(*callInfoList);
811 EXPECT_EQ(callInfoList->calls[0].number, unexpectedPhoneNumber);
812 callInfoList->callSize = 1;
813 callInfoList->calls.clear();
814 fifthHandler.ProcessRedundantCode(*callInfoList);
815 EXPECT_EQ(callInfoList->callSize, 1);
816 callInfo.number = unexpectedPhoneNumber;
817 callInfo.type = 136;
818 callInfoList->calls.push_back(callInfo);
819 fifthHandler.ProcessRedundantCode(*callInfoList);
820 EXPECT_EQ(callInfoList->calls[0].number, unexpectedPhoneNumber);
821 unexpectedPhoneNumber = "+561565910xxxx";
822 callInfo.number = unexpectedPhoneNumber;
823 callInfo.type = 145;
824 callInfoList->calls.clear();
825 callInfoList->calls.push_back(callInfo);
826 fifthHandler.ProcessRedundantCode(*callInfoList);
827 EXPECT_EQ(callInfoList->calls[0].number, unexpectedPhoneNumber);
828 unexpectedPhoneNumber = "+861565910";
829 callInfo.number = unexpectedPhoneNumber;
830 callInfoList->calls.clear();
831 callInfoList->calls.push_back(callInfo);
832 fifthHandler.ProcessRedundantCode(*callInfoList);
833 EXPECT_EQ(callInfoList->calls[0].number, unexpectedPhoneNumber);
834 }
835
836 /**
837 * @tc.number cellular_call_TestDump_0001
838 * @tc.name TestDump
839 * @tc.desc Function test
840 */
841 HWTEST_F(Cs2Test, cellular_call_TestDump_0001, Function | MediumTest | Level3)
842 {
843 std::vector<std::u16string> emptyArgs = {};
844 std::vector<std::u16string> args = { u"test", u"test1" };
845 EXPECT_GE(DelayedSingleton<CellularCallService>::GetInstance()->Dump(-1, args), 0);
846 EXPECT_GE(DelayedSingleton<CellularCallService>::GetInstance()->Dump(0, emptyArgs), 0);
847 EXPECT_GE(DelayedSingleton<CellularCallService>::GetInstance()->Dump(0, args), 0);
848 }
849
850 /**
851 * @tc.number cellular_call_ModuleServiceUtils_0001
852 * @tc.name ModuleServiceUtils
853 * @tc.desc Function test
854 */
855 HWTEST_F(Cs2Test, cellular_call_ModuleServiceUtils_0001, Function | MediumTest | Level3)
856 {
857 ModuleServiceUtils moduleServiceUtils;
858 bool airplaneModeOn = false;
859 moduleServiceUtils.GetCsRegState(SIM1_SLOTID);
860 moduleServiceUtils.GetPsRegState(SIM1_SLOTID);
861 moduleServiceUtils.GetRadioState(SIM1_SLOTID);
862 moduleServiceUtils.GetNetworkStatus(SIM1_SLOTID);
863 moduleServiceUtils.GetIsoCountryCode(SIM1_SLOTID);
864 moduleServiceUtils.GetNetworkCountryCode(SIM1_SLOTID);
865 moduleServiceUtils.GetImsRegistrationState(SIM1_SLOTID);
866 moduleServiceUtils.GetSatelliteStatus();
867 moduleServiceUtils.GetSlotInfo();
868 moduleServiceUtils.NeedCallImsService();
869 moduleServiceUtils.GetImsServiceRemoteObject();
870 EXPECT_NE(moduleServiceUtils.GetAirplaneMode(airplaneModeOn), TELEPHONY_SUCCESS);
871 EXPECT_NE(moduleServiceUtils.UpdateRadioOn(SIM1_SLOTID), TELEPHONY_SUCCESS);
872 }
873
874 /**
875 * @tc.number cellular_call_CellularCallConfig_0001
876 * @tc.name CellularCallConfig
877 * @tc.desc Function test
878 */
879 HWTEST_F(Cs2Test, cellular_call_CellularCallConfig_0001, Function | MediumTest | Level3)
880 {
881 CellularCallConfig CellularCallConfig;
882 bool isReadyToCall = false;
883 bool csType = 0;
884 CellularCallConfig.SetReadyToCall(SIM1_SLOTID, isReadyToCall);
885 CellularCallCallback cellularCallCallback;
886 cellularCallCallback.SetReadyToCall(SIM1_SLOTID, csType, isReadyToCall);
887 EXPECT_EQ(CellularCallConfig.IsReadyToCall(SIM1_SLOTID), TELEPHONY_SUCCESS);
888 }
889 } // namespace Telephony
890 } // namespace OHOS
891