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