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 #define private public
17 #define protected public
18 #include "core_manager_inner.h"
19 #include "cellular_call_config.h"
20 #include "cellular_call_handler.h"
21 #include "cellular_call_proxy.h"
22 #include "cellular_call_register.h"
23 #include "cellular_call_service.h"
24 #include "tel_ril_call_parcel.h"
25 #include "ims_call_callback_proxy.h"
26 #include "ims_call_callback_stub.h"
27 #include "ims_call_client.h"
28 #include "ims_control.h"
29 #include "ims_error.h"
30 #include "securec.h"
31 #include "call_manager_errors.h"
32 #include "cellular_call_interface.h"
33 #include "core_service_client.h"
34 #include "gtest/gtest.h"
35 #include "gmock/gmock.h"
36 #include "mock_sim_manager.h"
37 #include "mock_tel_ril_manager.h"
38 #include "mock_network_search.h"
39 #include "ims_core_service_client.h"
40 #include "iservice_registry.h"
41 #include "system_ability_definition.h"
42 #include "token.h"
43
44 namespace OHOS {
45 namespace Telephony {
46 using namespace testing::ext;
47 using ::testing::_;
48 using ::testing::AtLeast;
49 using ::testing::DoAll;
50 using ::testing::Invoke;
51 using ::testing::Mock;
52 using ::testing::Return;
53 using ::testing::SetArgReferee;
54 const int32_t SIM1_SLOTID = 0;
55 const int32_t SIM2_SLOTID = 1;
56 const int32_t SLOT_COUNT = 2;
57 const int32_t INVALID_HANG_UP_TYPE = -1;
58 const int32_t RESULT = 1;
59 const std::string PHONE_NUMBER = "0000000";
60 const std::string PHONE_NUMBER_SECOND = "1111111";
61 const std::string PHONE_NUMBER_THIRD = "2222222";
62 const std::string PHONE_NUMBER_FOUR = "3333333";
63
64 class Ims2Test : public testing::Test {
65 public:
66 static void SetUpTestCase();
67 static void TearDownTestCase();
68 void SetUp();
69 void TearDown();
70
Ims2Test()71 Ims2Test()
72 {
73 std::shared_ptr<MockTelRilManager> mockTelRilManagerPtr(mockTelRilManager);
74 std::shared_ptr<MockNetworkSearch> mockNetworkSearchPtr(mockNetworkSearch);
75 std::shared_ptr<MockSimManager> mockSimManagerPtr(mockSimManager);
76 CoreManagerInner::GetInstance().OnInit(mockNetworkSearchPtr, mockSimManagerPtr, mockTelRilManagerPtr);
77 }
78
HasSimCard(int32_t slotId)79 bool HasSimCard(int32_t slotId)
80 {
81 bool hasSimCard = false;
82 DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
83 return hasSimCard;
84 }
CanUseImsService(int32_t slotId,ImsServiceType type)85 bool CanUseImsService(int32_t slotId, ImsServiceType type)
86 {
87 ImsRegInfo info;
88 CoreServiceClient::GetInstance().GetImsRegStatus(slotId, type, info);
89 bool imsReg = info.imsRegState == ImsRegState::IMS_REGISTERED;
90 return imsReg;
91 }
92
InitCellularCallInfo(int32_t accountId,std::string phonenumber,CellularCallInfo & callInfo)93 int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo)
94 {
95 callInfo.accountId = accountId;
96 callInfo.slotId = accountId;
97 callInfo.index = accountId;
98 callInfo.callType = CallType::TYPE_IMS;
99 callInfo.videoState = 0; // 0 means audio
100 if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
101 return TELEPHONY_ERR_MEMSET_FAIL;
102 }
103 if (phonenumber.length() > static_cast<size_t>(kMaxNumberLen)) {
104 return CALL_ERR_NUMBER_OUT_OF_RANGE;
105 }
106 if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) {
107 return TELEPHONY_ERR_MEMCPY_FAIL;
108 }
109 return TELEPHONY_SUCCESS;
110 };
111
112 MockTelRilManager *mockTelRilManager = new MockTelRilManager();
113 MockNetworkSearch *mockNetworkSearch = new MockNetworkSearch();
114 MockSimManager *mockSimManager = new MockSimManager();
115 };
116
SetUpTestCase(void)117 void Ims2Test::SetUpTestCase(void)
118 {
119 // step 3: Set Up Test Case
120 std::cout << "---------- ImsCoreServiceClient start ------------" << std::endl;
121 DelayedSingleton<ImsCoreServiceClient>::GetInstance()->Init();
122 }
123
TearDownTestCase(void)124 void Ims2Test::TearDownTestCase(void)
125 {
126 // step 3: Tear Down Test Case
127 }
128
SetUp(void)129 void Ims2Test::SetUp(void) {}
130
TearDown(void)131 void Ims2Test::TearDown(void)
132 {
133 // step 3: input testcase teardown step
134 }
135
136 /**
137 * @tc.number cellular_call_GetVoNRState_0001
138 * @tc.name Test for GetVoNRState function
139 * @tc.desc Function test
140 */
141 HWTEST_F(Ims2Test, cellular_call_GetVoNRState_0001, Function | MediumTest | Level2)
142 {
143 AccessToken token;
144 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
145 ASSERT_TRUE(systemAbilityMgr != nullptr);
146 auto getVoNRRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
147 ASSERT_TRUE(getVoNRRemote != nullptr);
148 auto telephonyService = iface_cast<CellularCallInterface>(getVoNRRemote);
149 ASSERT_TRUE(telephonyService != nullptr);
150 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
151 return;
152 }
153 if (HasSimCard(SIM1_SLOTID)) {
154 int32_t result;
155 int32_t ret = telephonyService->GetVoNRState(SIM1_SLOTID, result);
156 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
157 }
158 if (HasSimCard(SIM2_SLOTID)) {
159 int32_t result;
160 int32_t ret = telephonyService->GetVoNRState(SIM2_SLOTID, result);
161 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
162 }
163 }
164
165 /**
166 * @tc.number cellular_call_StartRtt_0001
167 * @tc.name Test for StartRtt function
168 * @tc.desc Function test
169 */
170 HWTEST_F(Ims2Test, cellular_call_StartRtt_0001, Function | MediumTest | Level2)
171 {
172 AccessToken token;
173 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
174 ASSERT_TRUE(systemAbilityMgr != nullptr);
175 auto startRttRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
176 ASSERT_TRUE(startRttRemote != nullptr);
177 auto telephonyService = iface_cast<CellularCallInterface>(startRttRemote);
178 ASSERT_TRUE(telephonyService != nullptr);
179 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
180 return;
181 }
182 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
183 int32_t ret = telephonyService->StartRtt(SIM1_SLOTID, PHONE_NUMBER);
184 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
185 }
186 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
187 int32_t ret = telephonyService->StartRtt(SIM2_SLOTID, PHONE_NUMBER);
188 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
189 }
190 }
191
192 /**
193 * @tc.number cellular_call_StopRtt_0001
194 * @tc.name Test for StopRtt function
195 * @tc.desc Function test
196 */
197 HWTEST_F(Ims2Test, cellular_call_StopRtt_0001, Function | MediumTest | Level2)
198 {
199 AccessToken token;
200 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
201 ASSERT_TRUE(systemAbilityMgr != nullptr);
202 auto stopRttRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
203 ASSERT_TRUE(stopRttRemote != nullptr);
204 auto telephonyService = iface_cast<CellularCallInterface>(stopRttRemote);
205 ASSERT_TRUE(telephonyService != nullptr);
206 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
207 return;
208 }
209 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
210 int32_t ret = telephonyService->StopRtt(SIM1_SLOTID);
211 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
212 }
213 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
214 int32_t ret = telephonyService->StopRtt(SIM2_SLOTID);
215 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
216 }
217 }
218
219 /**
220 * @tc.number cellular_call_SetDomainPreferenceMode_0001
221 * @tc.name Test for SetDomainPreferenceMode function
222 * @tc.desc Function test
223 */
224 HWTEST_F(Ims2Test, cellular_call_SetDomainPreferenceMode_0001, Function | MediumTest | Level2)
225 {
226 AccessToken token;
227 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
228 ASSERT_TRUE(systemAbilityMgr != nullptr);
229 auto domainPrefModeRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
230 ASSERT_TRUE(domainPrefModeRemote != nullptr);
231 auto telephonyService = iface_cast<CellularCallInterface>(domainPrefModeRemote);
232 ASSERT_TRUE(telephonyService != nullptr);
233 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
234 return;
235 }
236 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
237 int32_t mode = -1;
238 int32_t ret = telephonyService->SetDomainPreferenceMode(SIM1_SLOTID, mode);
239 EXPECT_EQ(ret, CALL_ERR_PARAMETER_OUT_OF_RANGE);
240 }
241 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
242 int32_t mode = -1;
243 int32_t ret = telephonyService->SetDomainPreferenceMode(SIM2_SLOTID, mode);
244 EXPECT_EQ(ret, CALL_ERR_PARAMETER_OUT_OF_RANGE);
245 }
246 }
247
248 /**
249 * @tc.number cellular_call_GetImsConfig_0001
250 * @tc.name Test for GetImsConfig function
251 * @tc.desc Function test
252 */
253 HWTEST_F(Ims2Test, cellular_call_GetImsConfig_0001, Function | MediumTest | Level2)
254 {
255 AccessToken token;
256 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
257 ASSERT_TRUE(systemAbilityMgr != nullptr);
258 auto getImsConfigRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
259 ASSERT_TRUE(getImsConfigRemote != nullptr);
260 auto telephonyService = iface_cast<CellularCallInterface>(getImsConfigRemote);
261 ASSERT_TRUE(telephonyService != nullptr);
262 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
263 return;
264 }
265 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
266 ImsConfigItem mode = ITEM_IMS_SWITCH_STATUS;
267 int32_t ret = telephonyService->GetImsConfig(SIM1_SLOTID, mode);
268 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
269 }
270 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
271 ImsConfigItem mode = ITEM_IMS_SWITCH_STATUS;
272 int32_t ret = telephonyService->GetImsConfig(SIM2_SLOTID, mode);
273 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
274 }
275 }
276
277 /**
278 * @tc.number cellular_call_GetImsFeatureValue_0001
279 * @tc.name Test for GetImsFeatureValue function
280 * @tc.desc Function test
281 */
282 HWTEST_F(Ims2Test, cellular_call_GetImsFeatureValue_0001, Function | MediumTest | Level2)
283 {
284 AccessToken token;
285 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
286 ASSERT_TRUE(systemAbilityMgr != nullptr);
287 auto getImsFeatureRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
288 ASSERT_TRUE(getImsFeatureRemote != nullptr);
289 auto telephonyService = iface_cast<CellularCallInterface>(getImsFeatureRemote);
290 ASSERT_TRUE(telephonyService != nullptr);
291 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
292 return;
293 }
294 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
295 FeatureType mode = TYPE_VOICE_OVER_LTE;
296 int32_t ret = telephonyService->GetImsFeatureValue(SIM1_SLOTID, mode);
297 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
298 }
299 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
300 FeatureType mode = TYPE_VOICE_OVER_LTE;
301 int32_t ret = telephonyService->GetImsFeatureValue(SIM2_SLOTID, mode);
302 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
303 }
304 }
305
306 /**
307 * @tc.number cellular_call_SetMute_0001
308 * @tc.name Test for SetMute function
309 * @tc.desc Function test
310 */
311 HWTEST_F(Ims2Test, cellular_call_SetMute_0001, Function | MediumTest | Level2)
312 {
313 AccessToken token;
314 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
315 ASSERT_TRUE(systemAbilityMgr != nullptr);
316 auto setMuteRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
317 ASSERT_TRUE(setMuteRemote != nullptr);
318 auto telephonyService = iface_cast<CellularCallInterface>(setMuteRemote);
319 ASSERT_TRUE(telephonyService != nullptr);
320 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
321 return;
322 }
323 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
324 int32_t mode = 0;
325 int32_t ret = telephonyService->SetMute(SIM1_SLOTID, mode);
326 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
327 }
328 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_VOICE)) {
329 int32_t mode = 0;
330 int32_t ret = telephonyService->SetMute(SIM2_SLOTID, mode);
331 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
332 }
333 }
334
335 /**
336 * @tc.number cellular_call_SetCallWaiting_0001
337 * @tc.name Test for SetCallWaiting function
338 * @tc.desc Function test
339 */
340 HWTEST_F(Ims2Test, cellular_call_SetCallWaiting_0001, Function | MediumTest | Level2)
341 {
342 AccessToken token;
343 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
344 ASSERT_TRUE(systemAbilityMgr != nullptr);
345 auto SetCWRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
346 ASSERT_TRUE(SetCWRemote != nullptr);
347 auto telephonyService = iface_cast<CellularCallInterface>(SetCWRemote);
348 ASSERT_TRUE(telephonyService != nullptr);
349 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
350 return;
351 }
352 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
353 bool act = true;
354 int32_t ret = telephonyService->SetCallWaiting(SIM1_SLOTID, act);
355 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
356 }
357 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
358 bool act = true;
359 int32_t ret = telephonyService->SetCallWaiting(SIM2_SLOTID, act);
360 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
361 }
362 }
363
364 /**
365 * @tc.number cellular_call_GetCallWaiting_0001
366 * @tc.name Test for GetCallWaiting function
367 * @tc.desc Function test
368 */
369 HWTEST_F(Ims2Test, cellular_call_GetCallWaiting_0001, Function | MediumTest | Level2)
370 {
371 AccessToken token;
372 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
373 ASSERT_TRUE(systemAbilityMgr != nullptr);
374 auto getCWRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
375 ASSERT_TRUE(getCWRemote != nullptr);
376 auto telephonyService = iface_cast<CellularCallInterface>(getCWRemote);
377 ASSERT_TRUE(telephonyService != nullptr);
378 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
379 return;
380 }
381 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
382 int32_t ret = telephonyService->GetCallWaiting(SIM1_SLOTID);
383 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
384 }
385 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
386 int32_t ret = telephonyService->GetCallWaiting(SIM2_SLOTID);
387 EXPECT_EQ(ret, TELEPHONY_SUCCESS);
388 }
389 }
390
391 /**
392 * @tc.number cellular_call_SetCallRestriction_0001
393 * @tc.name Test for SetCallRestriction function
394 * @tc.desc Function test
395 */
396 HWTEST_F(Ims2Test, cellular_call_SetCallRestriction_0001, Function | MediumTest | Level2)
397 {
398 AccessToken token;
399 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
400 ASSERT_TRUE(systemAbilityMgr != nullptr);
401 auto setCRRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
402 ASSERT_TRUE(setCRRemote != nullptr);
403 auto telephonyService = iface_cast<CellularCallInterface>(setCRRemote);
404 ASSERT_TRUE(telephonyService != nullptr);
405 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
406 return;
407 }
408 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
409 CallRestrictionInfo crInfo;
410 int32_t ret = telephonyService->SetCallRestriction(SIM1_SLOTID, crInfo);
411 EXPECT_NE(ret, TELEPHONY_SUCCESS);
412 }
413 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
414 CallRestrictionInfo crInfo;
415 int32_t ret = telephonyService->SetCallRestriction(SIM2_SLOTID, crInfo);
416 EXPECT_NE(ret, TELEPHONY_SUCCESS);
417 }
418 }
419
420 /**
421 * @tc.number cellular_call_GetCallRestriction_0001
422 * @tc.name Test for GetCallRestriction function
423 * @tc.desc Function test
424 */
425 HWTEST_F(Ims2Test, cellular_call_GetCallRestriction_0001, Function | MediumTest | Level2)
426 {
427 AccessToken token;
428 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
429 ASSERT_TRUE(systemAbilityMgr != nullptr);
430 auto getCRRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
431 ASSERT_TRUE(getCRRemote != nullptr);
432 auto telephonyService = iface_cast<CellularCallInterface>(getCRRemote);
433 ASSERT_TRUE(telephonyService != nullptr);
434 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
435 return;
436 }
437 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
438 CallRestrictionType facType = CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING;
439 int32_t ret = telephonyService->GetCallRestriction(SIM1_SLOTID, facType);
440 EXPECT_NE(ret, TELEPHONY_SUCCESS);
441 }
442 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
443 CallRestrictionType facType = CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING;
444 int32_t ret = telephonyService->GetCallRestriction(SIM2_SLOTID, facType);
445 EXPECT_NE(ret, TELEPHONY_SUCCESS);
446 }
447 }
448
449 /**
450 * @tc.number cellular_call_SetCallTransferInfo_0001
451 * @tc.name Test for SetCallTransferInfo function
452 * @tc.desc Function test
453 */
454 HWTEST_F(Ims2Test, cellular_call_SetCallTransferInfo_0001, Function | MediumTest | Level2)
455 {
456 AccessToken token;
457 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
458 ASSERT_TRUE(systemAbilityMgr != nullptr);
459 auto setTransferRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
460 ASSERT_TRUE(setTransferRemote != nullptr);
461 auto telephonyService = iface_cast<CellularCallInterface>(setTransferRemote);
462 ASSERT_TRUE(telephonyService != nullptr);
463 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
464 return;
465 }
466 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
467 CallTransferInfo ctInfo;
468 int32_t ret = telephonyService->SetCallTransferInfo(SIM1_SLOTID, ctInfo);
469 EXPECT_NE(ret, TELEPHONY_SUCCESS);
470 }
471 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
472 CallTransferInfo ctInfo;
473 int32_t ret = telephonyService->SetCallTransferInfo(SIM2_SLOTID, ctInfo);
474 EXPECT_NE(ret, TELEPHONY_SUCCESS);
475 }
476 }
477
478 /**
479 * @tc.number cellular_call_GetCallTransferInfo_0001
480 * @tc.name Test for GetCallTransferInfo function
481 * @tc.desc Function test
482 */
483 HWTEST_F(Ims2Test, cellular_call_GetCallTransferInfo_0001, Function | MediumTest | Level2)
484 {
485 AccessToken token;
486 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
487 ASSERT_TRUE(systemAbilityMgr != nullptr);
488 auto getTransferRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
489 ASSERT_TRUE(getTransferRemote != nullptr);
490 auto telephonyService = iface_cast<CellularCallInterface>(getTransferRemote);
491 ASSERT_TRUE(telephonyService != nullptr);
492 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
493 return;
494 }
495 if (HasSimCard(SIM1_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
496 CallTransferType type = CallTransferType::TRANSFER_TYPE_UNCONDITIONAL;
497 int32_t ret = telephonyService->GetCallTransferInfo(SIM1_SLOTID, type);
498 EXPECT_NE(ret, TELEPHONY_SUCCESS);
499 }
500 if (HasSimCard(SIM2_SLOTID) && CanUseImsService(SIM2_SLOTID, ImsServiceType::TYPE_UT)) {
501 CallTransferType type = CallTransferType::TRANSFER_TYPE_UNCONDITIONAL;
502 int32_t ret = telephonyService->GetCallTransferInfo(SIM2_SLOTID, type);
503 EXPECT_NE(ret, TELEPHONY_SUCCESS);
504 }
505 }
506
507 /**
508 * @tc.number cellular_call_ImsControl_0001
509 * @tc.name Test for ImsControl
510 * @tc.desc Function test
511 */
512 HWTEST_F(Ims2Test, cellular_call_ImsControl_0001, Function | MediumTest | Level3)
513 {
514 AccessToken token;
515 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
516 ASSERT_TRUE(systemAbilityMgr != nullptr);
517 auto imsControlRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
518 ASSERT_TRUE(imsControlRemote != nullptr);
519 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
520 return;
521 }
522 auto imsControl = std::make_shared<IMSControl>();
523 CellularCallInfo cellularCallInfo;
524 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
525 if (!HasSimCard(slotId) || !CanUseImsService(slotId, ImsServiceType::TYPE_VOICE)) {
526 continue;
527 }
528 EXPECT_NE(imsControl->Answer(cellularCallInfo), TELEPHONY_SUCCESS);
529 EXPECT_NE(imsControl->Reject(cellularCallInfo), TELEPHONY_SUCCESS);
530 EXPECT_EQ(InitCellularCallInfo(slotId, PHONE_NUMBER, cellularCallInfo), TELEPHONY_SUCCESS);
531 bool enabled = false;
532 EXPECT_EQ(imsControl->Dial(cellularCallInfo, enabled), CALL_ERR_GET_RADIO_STATE_FAILED);
533 CLIRMode mode = CLIRMode::DEFAULT;
534 EXPECT_EQ(imsControl->DialJudgment(slotId, PHONE_NUMBER_SECOND, mode, 0), TELEPHONY_SUCCESS);
535 EXPECT_EQ(imsControl->DialJudgment(slotId, PHONE_NUMBER_THIRD, mode, 0), TELEPHONY_SUCCESS);
536 EXPECT_EQ(InitCellularCallInfo(slotId, PHONE_NUMBER_SECOND, cellularCallInfo), TELEPHONY_SUCCESS);
537 EXPECT_NE(imsControl->Answer(cellularCallInfo), TELEPHONY_SUCCESS);
538 EXPECT_EQ(InitCellularCallInfo(slotId, PHONE_NUMBER_THIRD, cellularCallInfo), TELEPHONY_SUCCESS);
539 EXPECT_NE(imsControl->Answer(cellularCallInfo), TELEPHONY_SUCCESS);
540 EXPECT_EQ(InitCellularCallInfo(slotId, PHONE_NUMBER_FOUR, cellularCallInfo), TELEPHONY_SUCCESS);
541 EXPECT_NE(imsControl->Answer(cellularCallInfo), TELEPHONY_SUCCESS);
542 EXPECT_NE(imsControl->Reject(cellularCallInfo), TELEPHONY_SUCCESS);
543 EXPECT_EQ(imsControl->HoldCall(slotId), TELEPHONY_SUCCESS);
544 std::vector<std::string> numberList;
545 EXPECT_EQ(imsControl->KickOutFromConference(slotId, PHONE_NUMBER, cellularCallInfo.index), TELEPHONY_SUCCESS);
546 EXPECT_EQ(imsControl->InviteToConference(slotId, numberList), TELEPHONY_SUCCESS);
547 EXPECT_EQ(imsControl->StartRtt(slotId, PHONE_NUMBER), TELEPHONY_SUCCESS);
548 EXPECT_EQ(imsControl->StopRtt(slotId), TELEPHONY_SUCCESS);
549 EXPECT_NE(imsControl->HangUp(cellularCallInfo, CallSupplementType::TYPE_DEFAULT), TELEPHONY_SUCCESS);
550 EXPECT_EQ(imsControl->HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ACTIVE),
551 CALL_ERR_RESOURCE_UNAVAILABLE);
552 EXPECT_EQ(imsControl->HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ALL), TELEPHONY_SUCCESS);
553 EXPECT_EQ(imsControl->HangUp(cellularCallInfo, static_cast<CallSupplementType>(INVALID_HANG_UP_TYPE)),
554 TELEPHONY_ERR_ARGUMENT_INVALID);
555 }
556 }
557
558 /**
559 * @tc.number cellular_call_ImsControl_0002
560 * @tc.name Test for ImsControl
561 * @tc.desc Function test
562 */
563 HWTEST_F(Ims2Test, cellular_call_ImsControl_0002, Function | MediumTest | Level3)
564 {
565 AccessToken token;
566 auto imsControl = std::make_shared<IMSControl>();
567 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
568 if (!HasSimCard(slotId) || !CanUseImsService(slotId, ImsServiceType::TYPE_VOICE)) {
569 continue;
570 }
571 ImsCurrentCallList callList;
572 callList.callSize = 0;
573 CallInfoList callInfoList;
574 EXPECT_EQ(imsControl->ReportCallsData(slotId, callInfoList), TELEPHONY_ERROR);
575 EXPECT_EQ(imsControl->ReportImsCallsData(slotId, callList), TELEPHONY_ERROR);
576 EXPECT_NE(imsControl->ReportUpdateInfo(slotId, callList), TELEPHONY_SUCCESS);
577 ImsCurrentCall callInfo;
578 callList.callSize = 1;
579 callInfo.number = PHONE_NUMBER;
580 callInfo.index = 1;
581 callInfo.state = static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING);
582 callList.calls.push_back(callInfo);
583 EXPECT_EQ(imsControl->ReportImsCallsData(slotId, callList), TELEPHONY_SUCCESS);
584 callList.calls[0].number = "";
585 callList.calls[0].name = "anonymous";
586 EXPECT_EQ(imsControl->ReportImsCallsData(slotId, callList), TELEPHONY_SUCCESS);
587 EXPECT_EQ(imsControl->HangUpAllConnection(slotId), TELEPHONY_SUCCESS);
588 callList.callSize = 2;
589 callInfo.index = 2;
590 callInfo.state = static_cast<int32_t>(TelCallState::CALL_STATUS_ACTIVE);
591 callInfo.number = PHONE_NUMBER_SECOND;
592 callList.calls.push_back(callInfo);
593 callList.callSize = 3;
594 callInfo.index = 3;
595 callInfo.state = static_cast<int32_t>(TelCallState::CALL_STATUS_WAITING);
596 callInfo.number = PHONE_NUMBER_THIRD;
597 callList.calls.push_back(callInfo);
598 callList.callSize = 4;
599 callInfo.index = 4;
600 callInfo.state = static_cast<int32_t>(TelCallState::CALL_STATUS_DISCONNECTED);
601 callInfo.number = PHONE_NUMBER_FOUR;
602 callList.calls.push_back(callInfo);
603 EXPECT_EQ(imsControl->ReportImsCallsData(slotId, callList), TELEPHONY_SUCCESS);
604 callList.callSize = 0;
605 EXPECT_EQ(imsControl->ReportImsCallsData(slotId, callList), TELEPHONY_SUCCESS);
606 }
607 }
608
609 /**
610 * @tc.number cellular_call_CellularCallConnectionIMS_0001
611 * @tc.name Test for CellularCallConnectionIMS
612 * @tc.desc Function test
613 */
614 HWTEST_F(Ims2Test, cellular_call_CellularCallConnectionIMS_0001, Function | MediumTest | Level3)
615 {
616 AccessToken token;
617 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
618 ASSERT_TRUE(systemAbilityMgr != nullptr);
619 auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
620 ASSERT_TRUE(remote != nullptr);
621 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
622 return;
623 }
624 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
625 if (!HasSimCard(slotId) || !CanUseImsService(slotId, ImsServiceType::TYPE_VOICE)) {
626 continue;
627 }
628 CellularCallConnectionIMS imsConnection;
629 EXPECT_EQ(imsConnection.SendDtmfRequest(slotId, '1', 1), TELEPHONY_SUCCESS);
630 EXPECT_EQ(imsConnection.StartDtmfRequest(slotId, '1', 1), TELEPHONY_SUCCESS);
631 EXPECT_EQ(imsConnection.StopDtmfRequest(slotId, 1), TELEPHONY_SUCCESS);
632 EXPECT_EQ(imsConnection.GetImsCallsDataRequest(slotId, 1), TELEPHONY_SUCCESS);
633 EXPECT_EQ(imsConnection.GetCallFailReasonRequest(slotId), TELEPHONY_SUCCESS);
634 EXPECT_EQ(imsConnection.AnswerRequest(slotId, PHONE_NUMBER, 0, slotId), TELEPHONY_SUCCESS);
635 ImsDialInfoStruct imsDialInfo;
636 imsDialInfo.phoneNum = PHONE_NUMBER_SECOND;
637 EXPECT_EQ(imsConnection.DialRequest(slotId, imsDialInfo), TELEPHONY_SUCCESS);
638 EXPECT_EQ(imsConnection.HangUpRequest(slotId, PHONE_NUMBER_SECOND, slotId), TELEPHONY_SUCCESS);
639 EXPECT_EQ(imsConnection.StartRttRequest(slotId, PHONE_NUMBER_THIRD), TELEPHONY_SUCCESS);
640 EXPECT_EQ(imsConnection.StopRttRequest(slotId), TELEPHONY_SUCCESS);
641 }
642 }
643
644 /**
645 * @tc.number cellular_call_CellularCallRegister_0001
646 * @tc.name Test for CellularCallRegister
647 * @tc.desc Function test
648 */
649 HWTEST_F(Ims2Test, cellular_call_CellularCallRegister_0001, Function | MediumTest | Level3)
650 {
651 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
652 ASSERT_TRUE(systemAbilityMgr != nullptr);
653 auto registerRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
654 ASSERT_TRUE(registerRemote != nullptr);
655 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
656 return;
657 }
658 auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
659 ASSERT_TRUE(callRegister != nullptr);
660 GetImsConfigResponse imsConfigResponse;
661 callRegister->ReportGetImsConfigResult(imsConfigResponse);
662 callRegister->ReportSetImsConfigResult(RESULT);
663 GetImsFeatureValueResponse imsFeatureValueResponse;
664 callRegister->ReportGetImsFeatureResult(imsFeatureValueResponse);
665 callRegister->ReportSetImsFeatureResult(RESULT);
666 ImsCallModeReceiveInfo callModeInfo;
667 callRegister->ReceiveUpdateCallMediaModeRequest(-1, callModeInfo);
668 callRegister->ReceiveUpdateCallMediaModeResponse(-1, callModeInfo);
669 ImsCallSessionEventInfo callSessionEventInfo;
670 callRegister->HandleCallSessionEventChanged(callSessionEventInfo);
671 ImsCallPeerDimensionsInfo callPeerDimensionsInfo;
672 callRegister->HandlePeerDimensionsChanged(callPeerDimensionsInfo);
673 ImsCallDataUsageInfo callDataUsageInfo;
674 callRegister->HandleCallDataUsageChanged(callDataUsageInfo);
675 CameraCapabilitiesInfo cameraCapabilitiesInfo;
676 callRegister->HandleCameraCapabilitiesChanged(cameraCapabilitiesInfo);
677 }
678
679 /**
680 * @tc.number cellular_call_CellularCallRegister_0002
681 * @tc.name Test for CellularCallRegister
682 * @tc.desc Function test
683 */
684 HWTEST_F(Ims2Test, cellular_call_CellularCallRegister_0002, Function | MediumTest | Level3)
685 {
686 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
687 ASSERT_TRUE(systemAbilityMgr != nullptr);
688 auto registerRemote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
689 ASSERT_TRUE(registerRemote != nullptr);
690 auto callRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
691 ASSERT_TRUE(callRegister != nullptr);
692 GetImsConfigResponse imsConfigResponse;
693 callRegister->ReportGetImsConfigResult(imsConfigResponse);
694 callRegister->ReportSetImsConfigResult(RESULT);
695 GetImsFeatureValueResponse imsFeatureValueResponse;
696 callRegister->ReportGetImsFeatureResult(imsFeatureValueResponse);
697 callRegister->ReportSetImsFeatureResult(RESULT);
698 ImsCallModeReceiveInfo callModeInfo;
699 callRegister->ReceiveUpdateCallMediaModeRequest(-1, callModeInfo);
700 callRegister->ReceiveUpdateCallMediaModeResponse(-1, callModeInfo);
701 ImsCallSessionEventInfo callSessionEventInfo;
702 callRegister->HandleCallSessionEventChanged(callSessionEventInfo);
703 ImsCallPeerDimensionsInfo callPeerDimensionsInfo;
704 callRegister->HandlePeerDimensionsChanged(callPeerDimensionsInfo);
705 ImsCallDataUsageInfo callDataUsageInfo;
706 callRegister->HandleCallDataUsageChanged(callDataUsageInfo);
707 CameraCapabilitiesInfo cameraCapabilitiesInfo;
708 callRegister->HandleCameraCapabilitiesChanged(cameraCapabilitiesInfo);
709 }
710
711 /**
712 * @tc.number cellular_call_CellularCallHandler_0001
713 * @tc.name Test for CellularCallHandler
714 * @tc.desc Function test
715 */
716 HWTEST_F(Ims2Test, cellular_call_CellularCallHandler_0001, Function | MediumTest | Level3)
717 {
718 EventFwk::MatchingSkills matchingSkills;
719 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
720 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
721 CellularCallHandler handler { subscriberInfo };
722 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
723 return;
724 }
725 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
726 if (!HasSimCard(slotId)) {
727 continue;
728 }
729 handler.SetSlotId(slotId);
730 auto event = AppExecFwk::InnerEvent::Get(0);
731 handler.GetImsCallsDataResponse(event);
732 handler.GetImsCallsDataRequest(event);
733 auto rilRadioResponse = std::make_shared<RadioResponseInfo>();
734 rilRadioResponse->error = ErrType::ERR_GENERIC_FAILURE;
735 auto responseEvent = AppExecFwk::InnerEvent::Get(0, rilRadioResponse);
736 handler.SetDomainPreferenceModeResponse(responseEvent);
737 handler.GetDomainPreferenceModeResponse(event);
738 handler.SetDomainPreferenceModeResponse(event);
739 handler.SetVoNRSwitchStatusResponse(responseEvent);
740 handler.NvCfgFinishedIndication(responseEvent);
741 handler.GetImsCapabilities(slotId);
742 handler.GetImsCapResponse(responseEvent);
743 ASSERT_EQ(handler.GetSlotId(), slotId);
744 handler.OnRilAdapterHostDied(event);
745 auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
746 if (serviceInstance != nullptr) {
747 std::shared_ptr<CSControl> csControl;
748 serviceInstance->SetCsControl(slotId, csControl);
749 std::shared_ptr<IMSControl> imsControl;
750 serviceInstance->SetImsControl(slotId, imsControl);
751 handler.OnRilAdapterHostDied(event);
752 ASSERT_TRUE(serviceInstance->GetCsControl(slotId) == nullptr);
753 ASSERT_TRUE(serviceInstance->GetCsControl(slotId) == nullptr);
754 }
755 }
756 }
757
758 /**
759 * @tc.number cellular_call_CellularCallHandler_0002
760 * @tc.name Test for CellularCallHandler
761 * @tc.desc Function test
762 */
763 HWTEST_F(Ims2Test, cellular_call_CellularCallHandler_0002, Function | MediumTest | Level3)
764 {
765 EventFwk::MatchingSkills matchingSkills;
766 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
767 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
768 CellularCallHandler handler { subscriberInfo };
769 if (!HasSimCard(SIM1_SLOTID) && !HasSimCard(SIM2_SLOTID)) {
770 return;
771 }
772 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
773 if (!HasSimCard(slotId)) {
774 continue;
775 }
776 handler.SetSlotId(slotId);
777 auto event = AppExecFwk::InnerEvent::Get(0);
778 handler.ReceiveUpdateCallMediaModeRequest(event);
779 handler.ReceiveUpdateCallMediaModeResponse(event);
780 handler.HandleCallSessionEventChanged(event);
781 handler.HandlePeerDimensionsChanged(event);
782 handler.HandleCallDataUsageChanged(event);
783 handler.HandleCameraCapabilitiesChanged(event);
784 EXPECT_TRUE(event != nullptr);
785 }
786 }
787
788 /**
789 * @tc.number cellular_call_CellularCallHandler_0003
790 * @tc.name Test for CellularCallHandler
791 * @tc.desc Function test
792 */
793 HWTEST_F(Ims2Test, cellular_call_CellularCallHandler_0003, Function | MediumTest | Level3)
794 {
795 EventFwk::MatchingSkills matchingSkills;
796 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
797 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
798 CellularCallHandler handler { subscriberInfo };
799 for (int32_t slotId = 0; slotId < SLOT_COUNT; slotId++) {
800 handler.SetSlotId(slotId);
801 auto event = AppExecFwk::InnerEvent::Get(0);
802 handler.GetImsCallsDataResponse(event);
803 handler.GetImsCallsDataRequest(event);
804 auto rilRadioResponse = std::make_shared<RadioResponseInfo>();
805 rilRadioResponse->error = ErrType::ERR_GENERIC_FAILURE;
806 auto responseEvent = AppExecFwk::InnerEvent::Get(0, rilRadioResponse);
807 handler.SetDomainPreferenceModeResponse(responseEvent);
808 handler.GetDomainPreferenceModeResponse(event);
809 handler.SetDomainPreferenceModeResponse(event);
810 handler.SetVoNRSwitchStatusResponse(responseEvent);
811 ASSERT_EQ(handler.GetSlotId(), slotId);
812 handler.OnRilAdapterHostDied(event);
813 auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
814 if (serviceInstance != nullptr) {
815 std::shared_ptr<CSControl> csControl;
816 serviceInstance->SetCsControl(slotId, csControl);
817 std::shared_ptr<IMSControl> imsControl;
818 serviceInstance->SetImsControl(slotId, imsControl);
819 handler.OnRilAdapterHostDied(event);
820 ASSERT_TRUE(serviceInstance->GetCsControl(slotId) == nullptr);
821 ASSERT_TRUE(serviceInstance->GetCsControl(slotId) == nullptr);
822 }
823 }
824 }
825
826 /**
827 * @tc.number cellular_call_CellularCallHandler_0004
828 * @tc.name Test for CellularCallHandler
829 * @tc.desc Function test
830 */
831 HWTEST_F(Ims2Test, cellular_call_CellularCallHandler_0004, Function | MediumTest | Level3)
832 {
833 EventFwk::MatchingSkills matchingSkills;
834 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
835 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
836 CellularCallHandler handler { subscriberInfo };
837 for (int32_t slotId = 0; slotId < SLOT_COUNT; slotId++) {
838 handler.SetSlotId(slotId);
839 auto event = AppExecFwk::InnerEvent::Get(0);
840 handler.ReceiveUpdateCallMediaModeRequest(event);
841 handler.ReceiveUpdateCallMediaModeResponse(event);
842 handler.HandleCallSessionEventChanged(event);
843 handler.HandlePeerDimensionsChanged(event);
844 handler.HandleCallDataUsageChanged(event);
845 handler.HandleCameraCapabilitiesChanged(event);
846 ASSERT_EQ(handler.GetSlotId(), slotId);
847 }
848 }
849
850 /**
851 * @tc.number cellular_call_CellularCallHandler_0005
852 * @tc.name Test for CellularCallHandler
853 * @tc.desc Function test
854 */
855 HWTEST_F(Ims2Test, cellular_call_CellularCallHandler_0005, Function | MediumTest | Level3)
856 {
857 EventFwk::MatchingSkills matchingSkills;
858 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
859 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
860 CellularCallHandler handler { subscriberInfo };
861 auto imsCurrentCallList = std::make_shared<ImsCurrentCallList>();
862 imsCurrentCallList->callSize = 0;
863 handler.ProcessImsPhoneNumber(*imsCurrentCallList);
864 EXPECT_EQ(imsCurrentCallList->callSize, 0);
865 imsCurrentCallList->callSize = 1;
866 handler.ProcessImsPhoneNumber(*imsCurrentCallList);
867 EXPECT_EQ(imsCurrentCallList->callSize, 1);
868 imsCurrentCallList->callSize = 1;
869 ImsCurrentCall imsCurrent;
870 std::string phoneNumber = "123";
871 imsCurrent.number = phoneNumber;
872 imsCurrentCallList->calls.push_back(imsCurrent);
873 handler.ProcessImsPhoneNumber(*imsCurrentCallList);
874 EXPECT_EQ(imsCurrentCallList->calls[0].number, phoneNumber);
875 imsCurrentCallList->calls.clear();
876 std::string unexpected = "00861565910xxxx";
877 std::string expected = "+861565910xxxx";
878 imsCurrent.number = unexpected;
879 imsCurrentCallList->calls.push_back(imsCurrent);
880 handler.ProcessImsPhoneNumber(*imsCurrentCallList);
881 EXPECT_EQ(imsCurrentCallList->calls[0].number, expected);
882 imsCurrentCallList->calls.clear();
883 unexpected = "0861565910xxxx";
884 imsCurrent.number = unexpected;
885 imsCurrentCallList->calls.push_back(imsCurrent);
886 handler.ProcessImsPhoneNumber(*imsCurrentCallList);
887 EXPECT_EQ(imsCurrentCallList->calls[0].number, unexpected);
888 }
889
890 /**
891 * @tc.number cellular_call_ImsCallClient_0001
892 * @tc.name test for ImsCallClient
893 * @tc.desc Function test
894 */
895 HWTEST_F(Ims2Test, cellular_call_ImsCallClient_0001, Function | MediumTest | Level3)
896 {
897 auto listen = std::make_shared<ImsCallClient::SystemAbilityListener>();
898 int32_t systemAbilityId = 1;
899 std::string deviceId = "123";
900 listen->OnAddSystemAbility(systemAbilityId, deviceId);
901 listen->OnRemoveSystemAbility(systemAbilityId, deviceId);
902 listen->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, deviceId);
903 listen->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, deviceId);
904 EXPECT_TRUE(listen != nullptr);
905 }
906
907 /**
908 * @tc.number cellular_call_NvCfgFinishedIndication_0001
909 * @tc.name test for NvCfgFinishedIndication
910 * @tc.desc Function test
911 */
912 HWTEST_F(Ims2Test, cellular_call_NvCfgFinishedIndication_0001, Function | MediumTest | Level3)
913 {
914 EventFwk::MatchingSkills matchingSkills;
915 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
916 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
917 CellularCallHandler handler { subscriberInfo };
918 handler.SetSlotId(SIM1_SLOTID);
919 auto responseEvent = AppExecFwk::InnerEvent::Get(0);
920 handler.NvCfgFinishedIndication(responseEvent);
921 auto nvCfgFinishedIndication = std::make_shared<Int32Parcel>();
922 nvCfgFinishedIndication->data = 0;
923 responseEvent = AppExecFwk::InnerEvent::Get(0, nvCfgFinishedIndication);
924 handler.NvCfgFinishedIndication(responseEvent);
925 nvCfgFinishedIndication->data = 1;
926 responseEvent = AppExecFwk::InnerEvent::Get(0, nvCfgFinishedIndication);
927 handler.NvCfgFinishedIndication(responseEvent);
928 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).WillRepeatedly(DoAll(SetArgReferee<1>(true), Return(0)));
929 handler.NvCfgFinishedIndication(responseEvent);
930 ASSERT_EQ(handler.GetSlotId(), SIM1_SLOTID);
931 }
932
933 /**
934 * @tc.number cellular_call_GetImsCapResponse_0001
935 * @tc.name test for GetImsCapResponse
936 * @tc.desc Function test
937 */
938 HWTEST_F(Ims2Test, cellular_call_GetImsCapResponse_0001, Function | MediumTest | Level3)
939 {
940 EventFwk::MatchingSkills matchingSkills;
941 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
942 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
943 CellularCallHandler handler { subscriberInfo };
944 handler.SetSlotId(SIM1_SLOTID);
945 auto imsCap1 = std::make_shared<Int32Parcel>();
946 auto responseEvent = AppExecFwk::InnerEvent::Get(0, imsCap1);
947 handler.GetImsCapResponse(responseEvent);
948 EXPECT_CALL(*mockSimManager, HasSimCard(_, _)).WillRepeatedly(DoAll(SetArgReferee<1>(true), Return(0)));
949 auto imsCap = std::make_shared<ImsCapFromChip>();
950 imsCap->volteCap = 1;
951 responseEvent = AppExecFwk::InnerEvent::Get(0, imsCap);
952 handler.GetImsCapResponse(responseEvent);
953 std::string volteCapKey =
954 KEY_PERSIST_TELEPHONY_VOLTE_CAP_IN_CHIP + std::string("_slot") + std::to_string(SIM1_SLOTID);
955 int32_t voltCapInProp = GetIntParameter(volteCapKey.c_str(), -1);
956 ASSERT_EQ(voltCapInProp, 1);
957 }
958
959 /**
960 * @tc.number cellular_call_GetImsSwitchStatusResponse_0001
961 * @tc.name test for GetImsSwitchStatusResponse
962 * @tc.desc Function test
963 */
964 HWTEST_F(Ims2Test, cellular_call_GetImsSwitchStatusResponse_0001, Function | MediumTest | Level3)
965 {
966 EventFwk::MatchingSkills matchingSkills;
967 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
968 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
969 CellularCallHandler handler { subscriberInfo };
970 handler.SetSlotId(SIM1_SLOTID);
971 auto responseInfo = std::make_shared<RadioResponseInfo>();
972 auto responseEvent = AppExecFwk::InnerEvent::Get(0, responseInfo);
973 handler.GetImsSwitchStatusResponse(responseEvent);
974 auto imsActive = std::make_shared<int32_t>(1);
975 responseEvent = AppExecFwk::InnerEvent::Get(0, imsActive);
976 handler.GetImsSwitchStatusResponse(responseEvent);
977 ASSERT_EQ(handler.GetSlotId(), SIM1_SLOTID);
978 }
979 } // namespace Telephony
980 } // namespace OHOS
981