1 /*
2  * Copyright (C) 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 #define private public
16 #define protected public
17 
18 #include "cellular_call_config.h"
19 #include "cellular_call_connection_ims.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 "cellular_call_supplement.h"
25 #include "config_request.h"
26 #include "control_base.h"
27 #include "cs_control.h"
28 #include "gtest/gtest.h"
29 #include "tel_ril_call_parcel.h"
30 #include "ims_call_callback_proxy.h"
31 #include "ims_call_callback_stub.h"
32 #include "ims_call_client.h"
33 #include "ims_control.h"
34 #include "ims_error.h"
35 #include "ims_test.h"
36 #include "securec.h"
37 #include "cellular_call_hisysevent.h"
38 #include "standardize_utils.h"
39 #include "cellular_call_rdb_helper.h"
40 #include "cellular_call_dump_helper.h"
41 #include "emergency_utils.h"
42 #include "satellite_call_client.h"
43 
44 namespace OHOS {
45 namespace Telephony {
46 using namespace testing::ext;
47 
48 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
49 static const int32_t INVALID_VALUE = -1;
50 #endif
51 
52 namespace {
53 const int32_t INVALID_SLOTID = 2;
54 const int32_t SIM1_SLOTID = 0;
55 const int32_t SIM2_SLOTID = 1;
56 const std::string PHONE_NUMBER = "00000000";
57 const int32_t DEFAULT_INDEX = 1;
58 } // namespace
59 
60 class DemoHandler : public AppExecFwk::EventHandler {
61 public:
DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> & runner)62     explicit DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> &runner) : AppExecFwk::EventHandler(runner) {}
~DemoHandler()63     virtual ~DemoHandler() {}
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)64     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) {}
65 };
66 
67 class BranchTest : public testing::Test {
68 public:
69     static void SetUpTestCase();
70     static void TearDownTestCase();
71     void SetUp();
72     void TearDown();
73     int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo);
74     void InitImsCallInfoList(ImsCurrentCallList &callInfoList, int32_t num);
75     void InitCsCallInfoList(CallInfoList &callInfoList, int32_t num);
76     void MakeCallInfoParcelData(bool isError, MessageParcel &data);
77 };
78 
SetUpTestCase()79 void BranchTest::SetUpTestCase()
80 {
81     std::cout << "---------- CellularCallService start ------------" << std::endl;
82     DelayedSingleton<CellularCallService>::GetInstance()->Init();
83     DelayedSingleton<ImsCallClient>::GetInstance()->Init();
84 }
85 
TearDownTestCase()86 void BranchTest::TearDownTestCase() {}
87 
SetUp()88 void BranchTest::SetUp() {}
89 
TearDown()90 void BranchTest::TearDown() {}
91 
InitCellularCallInfo(int32_t accountId,std::string phonenumber,CellularCallInfo & callInfo)92 int32_t BranchTest::InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo)
93 {
94     callInfo.accountId = accountId;
95     callInfo.slotId = accountId;
96     callInfo.index = accountId;
97     callInfo.callType = CallType::TYPE_IMS;
98     callInfo.videoState = 0; // 0 means audio
99     if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
100         return TELEPHONY_ERR_MEMSET_FAIL;
101     }
102     if (phonenumber.length() > static_cast<size_t>(kMaxNumberLen)) {
103         return CALL_ERR_NUMBER_OUT_OF_RANGE;
104     }
105     if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) {
106         return TELEPHONY_ERR_MEMCPY_FAIL;
107     }
108     return TELEPHONY_SUCCESS;
109 }
110 
InitImsCallInfoList(ImsCurrentCallList & callInfoList,int32_t num)111 void BranchTest::InitImsCallInfoList(ImsCurrentCallList &callInfoList, int32_t num)
112 {
113     callInfoList.callSize = num;
114     ImsCurrentCall call;
115     int32_t callStateSum = 6;
116     for (int32_t i = 0; i < num; ++i) {
117         call.index = i;
118         call.state = i % callStateSum;
119         callInfoList.calls.push_back(call);
120     }
121 }
122 
MakeCallInfoParcelData(bool isError,MessageParcel & data)123 void BranchTest::MakeCallInfoParcelData(bool isError, MessageParcel &data)
124 {
125     if (isError) {
126         int32_t errorSize = 0;
127         data.WriteInt32(errorSize);
128     } else {
129         CellularCallInfo callInfo;
130         callInfo.slotId = -1;
131         int32_t size = 1;
132         data.WriteInt32(size);
133         data.WriteRawData(static_cast<const void *>(&callInfo), sizeof(CellularCallInfo));
134     }
135 }
136 
InitCsCallInfoList(CallInfoList & callInfoList,int32_t num)137 void BranchTest::InitCsCallInfoList(CallInfoList &callInfoList, int32_t num)
138 {
139     callInfoList.callSize = num;
140     CallInfo call;
141     int32_t callStateSum = 9;
142     for (int32_t i = 0; i < num; ++i) {
143         call.index = i;
144         call.state = i % callStateSum;
145         callInfoList.calls.push_back(call);
146     }
147 }
148 
149 /**
150  * @tc.number   Telephony_CellularCallConfig_001
151  * @tc.name     Test error branch
152  * @tc.desc     Function test
153  */
154 HWTEST_F(BranchTest, Telephony_CellularCallConfig_001, Function | MediumTest | Level3)
155 {
156     AccessToken token;
157     CellularCallConfig config;
158     config.SetDomainPreferenceMode(SIM1_SLOTID, 1);
159     config.SetDomainPreferenceMode(SIM1_SLOTID, -1);
160     config.GetDomainPreferenceMode(SIM1_SLOTID);
161     bool enabled = false;
162     config.SetImsSwitchStatus(INVALID_SLOTID, enabled);
163     config.SetImsSwitchStatus(SIM1_SLOTID, enabled);
164     config.volteSupported_[SIM1_SLOTID] = true;
165     config.volteSupported_[INVALID_SLOTID] = true;
166     config.volteProvisioningSupported_[SIM1_SLOTID] = true;
167     config.volteProvisioningSupported_[INVALID_SLOTID] = true;
168     config.SetImsSwitchStatus(INVALID_SLOTID, enabled);
169     config.SetImsSwitchStatus(SIM1_SLOTID, true);
170     config.volteSupported_[SIM1_SLOTID] = enabled;
171     config.volteSupported_[INVALID_SLOTID] = enabled;
172     config.volteProvisioningSupported_[SIM1_SLOTID] = enabled;
173     config.volteProvisioningSupported_[INVALID_SLOTID] = enabled;
174     config.GetImsSwitchStatus(SIM1_SLOTID, enabled);
175     config.saveImsSwitchStatusToLocalForPowerOn(SIM1_SLOTID);
176     config.saveImsSwitchStatusToLocal(SIM1_SLOTID, true);
177     config.GetImsSwitchStatus(SIM1_SLOTID, enabled);
178     int32_t state = 0;
179     config.SetVoNRSwitchStatus(SIM1_SLOTID, state);
180     config.SetVoNRSwitchStatus(INVALID_SLOTID, state);
181     config.GetVoNRSwitchStatus(SIM1_SLOTID, state);
182     config.GetVoNRSwitchStatus(SIM2_SLOTID, state);
183     config.GetDomainPreferenceModeResponse(SIM1_SLOTID, 1);
184     config.GetImsSwitchStatusResponse(SIM1_SLOTID, 1);
185     config.GetPreferenceMode(SIM1_SLOTID);
186     std::string value = "";
187     config.SetImsConfig(ImsConfigItem::ITEM_VIDEO_QUALITY, value);
188     config.SetImsConfig(ImsConfigItem::ITEM_VIDEO_QUALITY, 1);
189     config.GetImsConfig(ImsConfigItem::ITEM_VIDEO_QUALITY);
190     config.SetImsFeatureValue(FeatureType::TYPE_VOICE_OVER_LTE, 1);
191     int32_t res = config.GetImsFeatureValue(FeatureType::TYPE_VOICE_OVER_LTE);
192     config.HandleFactoryReset(0);
193     config.HandleFactoryReset(1);
194 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
195     ASSERT_EQ(res, CALL_ERR_RESOURCE_UNAVAILABLE);
196 #else
197     ASSERT_EQ(res, TELEPHONY_SUCCESS);
198 #endif
199 }
200 
201 /**
202  * @tc.number   Telephony_CellularCallConfig_002
203  * @tc.name     Test error branch
204  * @tc.desc     Function test
205  */
206 HWTEST_F(BranchTest, Telephony_CellularCallConfig_002, Function | MediumTest | Level3)
207 {
208     AccessToken token;
209     CellularCallConfig config;
210     config.SetMute(SIM1_SLOTID, 0);
211     config.GetMute(SIM1_SLOTID);
212     config.GetEmergencyCallList(SIM1_SLOTID);
213     std::vector<EmergencyCall> eccVec = {};
214     config.SetEmergencyCallList(SIM1_SLOTID, eccVec);
215     config.SetTempMode(SIM1_SLOTID);
216     config.InitModeActive();
217     EmergencyInfoList eccList;
218     config.UpdateEmergencyCallFromRadio(SIM1_SLOTID, eccList);
219     config.GetEccCallList(SIM1_SLOTID);
220     config.GetMcc(SIM1_SLOTID);
221     config.SetReadyToCall(SIM1_SLOTID, true);
222     config.SetReadyToCall(INVALID_SLOTID, true);
223     config.IsReadyToCall(SIM1_SLOTID);
224     config.IsReadyToCall(INVALID_SLOTID);
225 
226     config.HandleSimStateChanged(SIM1_SLOTID);
227     config.HandleSetLteImsSwitchResult(SIM1_SLOTID, ErrType::NONE);
228     config.HandleSetVoNRSwitchResult(SIM1_SLOTID, ErrType::NONE);
229     config.HandleSimRecordsLoaded(SIM1_SLOTID);
230     config.HandleOperatorConfigChanged(SIM1_SLOTID);
231     OperatorConfig poc;
232     config.ParseAndCacheOperatorConfigs(SIM1_SLOTID, poc);
233     config.UpdateImsCapabilities(SIM1_SLOTID, true);
234     bool enabled = false;
235     config.ChangeImsSwitchWithOperatorConfig(SIM1_SLOTID, true);
236     config.SaveImsSwitch(SIM1_SLOTID, true);
237     config.IsUtProvisioned(SIM1_SLOTID);
238     config.utProvisioningSupported_[SIM1_SLOTID] = true;
239     config.IsUtProvisioned(SIM1_SLOTID);
240     config.utProvisioningSupported_[SIM1_SLOTID] = enabled;
241     config.ResetImsSwitch(SIM1_SLOTID);
242     config.HandleSimAccountLoaded(SIM1_SLOTID);
243     ASSERT_FALSE(config.utProvisioningSupported_[SIM1_SLOTID]);
244 }
245 
246 /**
247  * @tc.number   Telephony_CellularCallSupplement_001
248  * @tc.name     Test error branch
249  * @tc.desc     Function test
250  */
251 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_001, Function | MediumTest | Level3)
252 {
253     AccessToken token;
254     CellularCallSupplement callSup;
255     MMIData mmiDataEmp = {};
256     MMIData mmiDataAct = { .actionString = "*" };
257     MMIData mmiDataDeact = { .actionString = "#" };
258     MMIData mmiDataInterrogate = { .actionString = "*#" };
259     callSup.HandleClip(SIM1_SLOTID, mmiDataEmp);
260     callSup.HandleClip(SIM1_SLOTID, mmiDataAct);
261     callSup.HandleClip(SIM1_SLOTID, mmiDataDeact);
262     callSup.HandleClip(SIM1_SLOTID, mmiDataInterrogate);
263     callSup.HandleClir(SIM1_SLOTID, mmiDataEmp);
264     callSup.HandleClir(SIM1_SLOTID, mmiDataAct);
265     callSup.HandleClir(SIM1_SLOTID, mmiDataDeact);
266     callSup.HandleClir(SIM1_SLOTID, mmiDataInterrogate);
267     callSup.HandleColr(SIM1_SLOTID, mmiDataEmp);
268     callSup.HandleColr(SIM1_SLOTID, mmiDataAct);
269     callSup.HandleColr(SIM1_SLOTID, mmiDataDeact);
270     callSup.HandleColr(SIM1_SLOTID, mmiDataInterrogate);
271     callSup.HandleColp(SIM1_SLOTID, mmiDataEmp);
272     callSup.HandleColp(SIM1_SLOTID, mmiDataAct);
273     callSup.HandleColp(SIM1_SLOTID, mmiDataDeact);
274     callSup.HandleColp(SIM1_SLOTID, mmiDataInterrogate);
275     callSup.HandleCallTransfer(SIM1_SLOTID, mmiDataEmp);
276     callSup.HandleCallTransfer(SIM1_SLOTID, mmiDataInterrogate);
277     callSup.HandleCallTransfer(SIM1_SLOTID, mmiDataAct);
278     callSup.HandleCallRestriction(SIM1_SLOTID, mmiDataEmp);
279     callSup.HandleCallRestriction(SIM1_SLOTID, mmiDataAct);
280     callSup.HandleCallRestriction(SIM1_SLOTID, mmiDataDeact);
281     callSup.HandleCallRestriction(SIM1_SLOTID, mmiDataInterrogate);
282     callSup.HandleCallWaiting(SIM1_SLOTID, mmiDataEmp);
283     callSup.HandleCallWaiting(SIM1_SLOTID, mmiDataAct);
284     callSup.HandleCallWaiting(SIM1_SLOTID, mmiDataDeact);
285     ASSERT_FALSE(mmiDataAct.actionString.empty());
286 }
287 
288 /**
289  * @tc.number   Telephony_CellularCallSupplement_002
290  * @tc.name     Test error branch
291  * @tc.desc     Function test
292  */
293 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_002, Function | MediumTest | Level3)
294 {
295     AccessToken token;
296     CellularCallSupplement callSup;
297     callSup.SendUssd(SIM1_SLOTID, "*#21#");
298     PinPukResponse pinPuk;
299     callSup.EventSetPinPuk(pinPuk);
300     MMIData mmiDataPin = { .serviceInfoA = "1234", .serviceInfoB = "1111", .serviceInfoC = "1111" };
301     callSup.AlterPinPassword(SIM1_SLOTID, mmiDataPin);
302     callSup.UnlockPuk(SIM1_SLOTID, mmiDataPin);
303     callSup.AlterPin2Password(SIM1_SLOTID, mmiDataPin);
304     callSup.UnlockPuk2(SIM1_SLOTID, mmiDataPin);
305     mmiDataPin = { .serviceInfoA = "1234", .serviceInfoB = "1111", .serviceInfoC = "1112" };
306     callSup.AlterPinPassword(SIM1_SLOTID, mmiDataPin);
307     callSup.UnlockPuk(SIM1_SLOTID, mmiDataPin);
308     callSup.AlterPin2Password(SIM1_SLOTID, mmiDataPin);
309     callSup.UnlockPuk2(SIM1_SLOTID, mmiDataPin);
310     mmiDataPin = { .serviceInfoA = "1234", .serviceInfoB = "1111", .serviceInfoC = "111111111" };
311     callSup.AlterPinPassword(SIM1_SLOTID, mmiDataPin);
312     callSup.UnlockPuk(SIM1_SLOTID, mmiDataPin);
313     callSup.AlterPin2Password(SIM1_SLOTID, mmiDataPin);
314     callSup.UnlockPuk2(SIM1_SLOTID, mmiDataPin);
315     callSup.CloseUnFinishedUssd(SIM1_SLOTID);
316     GetClipResult getClipResult;
317     std::string message = "";
318     callSup.EventGetClip(getClipResult, message, 0);
319     callSup.EventGetClip(getClipResult, message, 1);
320     callSup.EventSetClip(0, message, 0);
321     callSup.EventSetClip(0, message, 1);
322     GetClirResult getClirResult;
323     callSup.EventGetClir(getClirResult, message, 0);
324     callSup.EventGetClir(getClirResult, message, 1);
325     callSup.EventSetClir(0, message, 0);
326     callSup.EventSetClir(0, message, 1);
327     GetColrResult getColrResult;
328     callSup.EventGetColr(getColrResult, message, 0);
329     callSup.EventGetColr(getColrResult, message, 1);
330     callSup.EventSetColr(0, message, 0);
331     callSup.EventSetColr(0, message, 1);
332     ASSERT_TRUE(mmiDataPin.actionString.empty());
333 }
334 
335 /**
336  * @tc.number   Telephony_CellularCallSupplement_003
337  * @tc.name     Test error branch
338  * @tc.desc     Function test
339  */
340 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_003, Function | MediumTest | Level3)
341 {
342     AccessToken token;
343     CellularCallSupplement callSup;
344     GetColpResult getColpResult;
345     std::string message = "";
346     callSup.EventGetColp(getColpResult, message, 0);
347     callSup.EventGetColp(getColpResult, message, 1);
348     callSup.EventSetColp(0, message, 0);
349     callSup.EventSetColp(0, message, 1);
350     CallRestrictionResult callResResult;
351     callSup.EventGetCallRestriction(callResResult, message, 0);
352     callSup.EventGetCallRestriction(callResResult, message, 1);
353     callResResult.status = 1;
354     callSup.EventGetCallRestriction(callResResult, message, 0);
355     callResResult.result.result = 1;
356     callSup.EventGetCallRestriction(callResResult, message, 0);
357     callSup.EventSetCallRestriction(0, message, 0);
358     callSup.EventSetCallRestriction(0, message, 1);
359     callSup.EventSetBarringPassword(0, message, 0);
360     callSup.EventSetBarringPassword(0, message, 1);
361     callSup.EventSetCallWaiting(0, message, 0);
362     callSup.EventSetCallWaiting(0, message, 1);
363     CallForwardQueryInfoList cFQueryList;
364     callSup.EventGetCallTransferInfo(cFQueryList, message, 0);
365     CallForwardQueryResult queryResult;
366     callSup.BuildCallForwardQueryInfo(queryResult, message, 0);
367     callSup.BuildCallForwardQueryInfo(queryResult, message, 1);
368     queryResult.classx = 1;
369     callSup.BuildCallForwardQueryInfo(queryResult, message, 0);
370     queryResult.status = 1;
371     callSup.BuildCallForwardQueryInfo(queryResult, message, 0);
372     queryResult.reason = 2;
373     callSup.BuildCallForwardQueryInfo(queryResult, message, 0);
374     callSup.EventSetCallTransferInfo(0, message, 0);
375     callSup.EventSetCallTransferInfo(0, message, 1);
376     RadioResponseInfo responseInfo;
377     callSup.EventSendUssd(responseInfo);
378     SsNoticeInfo ssNoticeInfo;
379     callSup.EventSsNotify(ssNoticeInfo);
380     UssdNoticeInfo ussdNoticeInfo;
381     callSup.EventUssdNotify(ussdNoticeInfo);
382     RadioResponseInfo response;
383     callSup.EventCloseUnFinishedUssd(response);
384     callSup.GetCallTransferInfo(SIM1_SLOTID, CallTransferType::TRANSFER_TYPE_UNCONDITIONAL);
385     ASSERT_NE(callSup.GetCallTransferInfo(SIM2_SLOTID, CallTransferType::TRANSFER_TYPE_UNCONDITIONAL),
386         TELEPHONY_SUCCESS);
387 }
388 
389 /**
390  * @tc.number   Telephony_CellularCallSupplement_004
391  * @tc.name     Test error branch
392  * @tc.desc     Function test
393  */
394 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_004, Function | MediumTest | Level3)
395 {
396     AccessToken token;
397     CellularCallSupplement callSup;
398     CallWaitResult waitingInfo;
399     std::string message = "";
400     callSup.EventGetCallWaiting(waitingInfo, message, 0);
401     callSup.EventGetCallWaiting(waitingInfo, message, 1);
402     waitingInfo.status =1;
403     callSup.EventGetCallWaiting(waitingInfo, message, 0);
404     waitingInfo.classCw =1;
405     callSup.EventGetCallWaiting(waitingInfo, message, 0);
406     waitingInfo.classCw =4;
407     callSup.EventGetCallWaiting(waitingInfo, message, 0);
408     waitingInfo.classCw =8;
409     callSup.EventGetCallWaiting(waitingInfo, message, 0);
410     waitingInfo.classCw =16;
411     callSup.EventGetCallWaiting(waitingInfo, message, 0);
412     waitingInfo.classCw =32;
413     callSup.EventGetCallWaiting(waitingInfo, message, 0);
414     waitingInfo.classCw =64;
415     callSup.EventGetCallWaiting(waitingInfo, message, 0);
416     waitingInfo.classCw =128;
417     callSup.EventGetCallWaiting(waitingInfo, message, 0);
418     CallTransferInfo cfInfo;
419     callSup.SetCallTransferInfo(SIM1_SLOTID, cfInfo);
420     strcpy_s(cfInfo.transferNum, kMaxNumberLen + 1, "111");
421     callSup.SetCallTransferInfo(SIM1_SLOTID, cfInfo);
422     callSup.SetCallTransferInfo(SIM2_SLOTID, cfInfo);
423     auto utCommand = std::make_shared<SsRequestCommand>();
424     callSup.SetCallTransferInfoByIms(SIM1_SLOTID, cfInfo, utCommand);
425     callSup.SetCallTransferInfoByIms(SIM2_SLOTID, cfInfo, utCommand);
426     bool activate = false;
427     callSup.SetCallWaiting(SIM1_SLOTID, activate);
428     callSup.SetCallWaiting(SIM2_SLOTID, activate);
429     callSup.GetCallWaiting(SIM1_SLOTID);
430     callSup.GetCallWaiting(SIM2_SLOTID);
431     CallRestrictionInfo crInfo;
432     callSup.SetCallRestriction(SIM1_SLOTID, crInfo);
433     callSup.SetCallRestriction(SIM2_SLOTID, crInfo);
434     auto crCommand = std::make_shared<SsRequestCommand>();
435     std::string info(crInfo.password);
436     std::string fac("AO");
437     callSup.SetCallRestrictionByIms(SIM1_SLOTID, fac, static_cast<int32_t>(crInfo.mode), info, crCommand);
438     callSup.SetCallRestrictionByIms(SIM2_SLOTID, fac, static_cast<int32_t>(crInfo.mode), info, crCommand);
439     callSup.GetCallRestriction(SIM1_SLOTID, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING);
440     callSup.GetCallRestriction(SIM2_SLOTID, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING);
441     callSup.SetBarringPassword(SIM1_SLOTID, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING, "1111", "0000");
442     ASSERT_NE(callSup.SetBarringPassword(SIM2_SLOTID, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING,
443         "1111", "0000"), TELEPHONY_SUCCESS);
444 }
445 
446 /**
447  * @tc.number   Telephony_CellularCallSupplement_005
448  * @tc.name     Test error branch
449  * @tc.desc     Function test
450  */
451 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_005, Function | MediumTest | Level3)
452 {
453     AccessToken token;
454     CellularCallSupplement callSup;
455     MMIData mmiDataEmp = {};
456     MMIData mmiDataAct = { .actionString = "*" };
457     MMIData mmiDataDeact = { .actionString = "#" };
458     MMIData mmiDataInterrogate = { .actionString = "*#" };
459     callSup.HandleClip(SIM2_SLOTID, mmiDataEmp);
460     callSup.HandleClip(SIM2_SLOTID, mmiDataAct);
461     callSup.HandleClip(SIM2_SLOTID, mmiDataDeact);
462     callSup.HandleClip(SIM2_SLOTID, mmiDataInterrogate);
463     callSup.HandleColr(SIM2_SLOTID, mmiDataEmp);
464     callSup.HandleColr(SIM2_SLOTID, mmiDataAct);
465     callSup.HandleColr(SIM2_SLOTID, mmiDataDeact);
466     callSup.HandleColr(SIM2_SLOTID, mmiDataInterrogate);
467     callSup.HandleColp(SIM2_SLOTID, mmiDataEmp);
468     callSup.HandleColp(SIM2_SLOTID, mmiDataAct);
469     callSup.HandleColp(SIM2_SLOTID, mmiDataDeact);
470     callSup.HandleColp(SIM2_SLOTID, mmiDataInterrogate);
471     callSup.HandleCallTransfer(SIM2_SLOTID, mmiDataEmp);
472     callSup.HandleCallTransfer(SIM2_SLOTID, mmiDataInterrogate);
473     callSup.HandleCallTransfer(SIM2_SLOTID, mmiDataAct);
474     callSup.HandleCallRestriction(SIM2_SLOTID, mmiDataEmp);
475     callSup.HandleCallRestriction(SIM2_SLOTID, mmiDataAct);
476     callSup.HandleCallRestriction(SIM2_SLOTID, mmiDataDeact);
477     callSup.HandleCallRestriction(SIM2_SLOTID, mmiDataInterrogate);
478     callSup.HandleCallWaiting(SIM2_SLOTID, mmiDataEmp);
479     callSup.HandleCallWaiting(SIM2_SLOTID, mmiDataAct);
480     callSup.HandleCallWaiting(SIM2_SLOTID, mmiDataDeact);
481     bool enable = false;
482 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
483     ASSERT_EQ(callSup.CanSetCallTransferTime(SIM1_SLOTID, enable), CALL_ERR_RESOURCE_UNAVAILABLE);
484 #else
485     ASSERT_EQ(callSup.CanSetCallTransferTime(SIM1_SLOTID, enable), TELEPHONY_SUCCESS);
486 #endif
487 }
488 
489 /**
490  * @tc.number   Telephony_CellularCallSupplement_006
491  * @tc.name     Test error branch
492  * @tc.desc     Function test
493  */
494 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_006, Function | MediumTest | Level3)
495 {
496     AccessToken token;
497     CellularCallSupplement callSup;
498     MMIData mmiDataEmp = {};
499     MMIData mmiDataAct = { .actionString = "*" };
500     MMIData mmiDataDeact = { .actionString = "#" };
501     MMIData mmiDataInterrogate = { .actionString = "*#" };
502     EventFwk::MatchingSkills matchingSkills;
503     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
504     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
505     auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
506     auto callClient = DelayedSingleton<SatelliteCallClient>::GetInstance();
507     ASSERT_EQ(callClient->RegisterSatelliteCallCallbackHandler(SIM1_SLOTID, handler), TELEPHONY_SUCCESS);
508     callSup.HandleClip(SIM1_SLOTID, mmiDataAct);
509     callSup.HandleClip(SIM1_SLOTID, mmiDataDeact);
510     callSup.HandleClip(SIM1_SLOTID, mmiDataInterrogate);
511     callSup.HandleColr(SIM1_SLOTID, mmiDataAct);
512     callSup.HandleColr(SIM1_SLOTID, mmiDataDeact);
513     callSup.HandleColr(SIM1_SLOTID, mmiDataInterrogate);
514     callSup.HandleColp(SIM1_SLOTID, mmiDataAct);
515     callSup.HandleColp(SIM1_SLOTID, mmiDataDeact);
516     callSup.HandleColp(SIM1_SLOTID, mmiDataInterrogate);
517     int32_t cause = 0;
518     callSup.HandleGetCallTransfer(SIM1_SLOTID, cause);
519     int32_t serviceCode = 0;
520     std::string phoneNumber("1234567890");
521     CallTransferSettingType callTransferAction = CallTransferSettingType::CALL_TRANSFER_DISABLE;
522     callSup.HandleSetCallTransfer(SIM1_SLOTID, serviceCode, cause, phoneNumber, callTransferAction);
523     callSup.HandleCallRestriction(SIM1_SLOTID, mmiDataAct);
524     callSup.HandleCallRestriction(SIM1_SLOTID, mmiDataDeact);
525     callSup.HandleCallRestriction(SIM1_SLOTID, mmiDataInterrogate);
526     callSup.HandleCallWaiting(SIM1_SLOTID, mmiDataAct);
527     callSup.HandleCallWaiting(SIM1_SLOTID, mmiDataDeact);
528     callSup.HandleCallWaiting(SIM1_SLOTID, mmiDataInterrogate);
529 }
530 
531 /**
532  * @tc.number   Telephony_CellularCallSupplement_007
533  * @tc.name     Test error branch
534  * @tc.desc     Function test
535  */
536 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_007, Function | MediumTest | Level3)
537 {
538     AccessToken token;
539     CellularCallSupplement callSup;
540     MMIData mmiDataEmp = {};
541     MMIData mmiDataAct = { .actionString = "*" };
542     MMIData mmiDataDeact = { .actionString = "#" };
543     MMIData mmiDataInterrogate = { .actionString = "*#" };
544     EventFwk::MatchingSkills matchingSkills;
545     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
546     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
547     auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
548     auto callClient = DelayedSingleton<SatelliteCallClient>::GetInstance();
549     ASSERT_EQ(callClient->RegisterSatelliteCallCallbackHandler(SIM1_SLOTID, handler), TELEPHONY_SUCCESS);
550     std::string serviceInfoB("10");
551     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 13);
552     serviceInfoB = "11";
553     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 1);
554     serviceInfoB = "12";
555     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 12);
556     serviceInfoB = "13";
557     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 4);
558     serviceInfoB = "16";
559     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 8);
560     serviceInfoB = "19";
561     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 5);
562     serviceInfoB = "20";
563     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 48);
564     serviceInfoB = "21";
565     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 160);
566     serviceInfoB = "22";
567     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 80);
568     serviceInfoB = "24";
569     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 16);
570     serviceInfoB = "25";
571     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 32);
572     serviceInfoB = "99";
573     ASSERT_EQ(callSup.ObtainServiceCode(serviceInfoB), 64);
574     std::string phoneNumber("1234");
575     CallTransferSettingType callTransferAction;
576     ASSERT_EQ(callSup.ObtainCallTrasferAction("*", phoneNumber, callTransferAction), TELEPHONY_SUCCESS);
577     ASSERT_EQ(callSup.ObtainCallTrasferAction("**", phoneNumber, callTransferAction), TELEPHONY_SUCCESS);
578     ASSERT_EQ(callSup.ObtainCallTrasferAction("#", phoneNumber, callTransferAction), TELEPHONY_SUCCESS);
579     ASSERT_EQ(callSup.ObtainCallTrasferAction("##", phoneNumber, callTransferAction), TELEPHONY_SUCCESS);
580     ASSERT_EQ(callSup.ObtainCause("21"), static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_UNCONDITIONAL));
581     ASSERT_EQ(callSup.ObtainCause("61"), static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NOT_REACHABLE));
582     ASSERT_EQ(callSup.ObtainCause("62"), static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NO_REPLY));
583     ASSERT_EQ(callSup.ObtainCause("67"), static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_BUSY));
584     ASSERT_EQ(callSup.ObtainCause("99"), TELEPHONY_ERROR);
585 }
586 
587 /**
588  * @tc.number   Telephony_CellularCallSupplement_008
589  * @tc.name     Test error branch
590  * @tc.desc     Function test
591  */
592 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_008, Function | MediumTest | Level3)
593 {
594     AccessToken token;
595     CellularCallSupplement callSup;
596     MMIData mmiDataAct = { .actionString = "*" };
597     EventFwk::MatchingSkills matchingSkills;
598     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
599     EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
600     auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
601     auto callClient = DelayedSingleton<SatelliteCallClient>::GetInstance();
602     ASSERT_EQ(callClient->RegisterSatelliteCallCallbackHandler(SIM1_SLOTID, handler), TELEPHONY_SUCCESS);
603     ASSERT_EQ(callSup.ObtainBarringInstallation("33"), "AO");
604     ASSERT_EQ(callSup.ObtainBarringInstallation("331"), "OI");
605     ASSERT_EQ(callSup.ObtainBarringInstallation("332"), "OX");
606     ASSERT_EQ(callSup.ObtainBarringInstallation("351"), "IR");
607     ASSERT_EQ(callSup.ObtainBarringInstallation("35"), "AI");
608     ASSERT_EQ(callSup.ObtainBarringInstallation("330"), "AB");
609     ASSERT_EQ(callSup.ObtainBarringInstallation("333"), "AG");
610     ASSERT_EQ(callSup.ObtainBarringInstallation("353"), "AC");
611     ASSERT_EQ(callSup.ObtainBarringInstallation("1000"), "");
612     std::string fac;
613     ASSERT_EQ(callSup.CheckCallRestrictionType(fac, CallRestrictionType::RESTRICTION_TYPE_ALL_OUTGOING),
614         TELEPHONY_SUCCESS);
615     ASSERT_EQ(callSup.CheckCallRestrictionType(fac, CallRestrictionType::RESTRICTION_TYPE_INTERNATIONAL),
616         TELEPHONY_SUCCESS);
617     ASSERT_EQ(callSup.CheckCallRestrictionType(fac,
618         CallRestrictionType::RESTRICTION_TYPE_INTERNATIONAL_EXCLUDING_HOME), TELEPHONY_SUCCESS);
619     ASSERT_EQ(callSup.CheckCallRestrictionType(fac, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING),
620         TELEPHONY_SUCCESS);
621     ASSERT_EQ(callSup.CheckCallRestrictionType(fac, CallRestrictionType::RESTRICTION_TYPE_ROAMING_INCOMING),
622         TELEPHONY_SUCCESS);
623     ASSERT_EQ(callSup.CheckCallRestrictionType(fac, CallRestrictionType::RESTRICTION_TYPE_ALL_CALLS),
624         TELEPHONY_SUCCESS);
625     ASSERT_EQ(callSup.CheckCallRestrictionType(fac, CallRestrictionType::RESTRICTION_TYPE_OUTGOING_SERVICES),
626         TELEPHONY_SUCCESS);
627     ASSERT_EQ(callSup.CheckCallRestrictionType(fac, CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES),
628         TELEPHONY_SUCCESS);
629     MmiCodeInfo mmiCodeInfo;
630     SsNoticeInfo ssNoticeInfo;
631     ssNoticeInfo.result = 0;
632     callSup.GetMessage(mmiCodeInfo, ssNoticeInfo);
633     ssNoticeInfo.result = 1;
634     ssNoticeInfo.serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_UNCONDITIONAL);
635     callSup.GetMessage(mmiCodeInfo, ssNoticeInfo);
636     ssNoticeInfo.serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_BUSY);
637     callSup.GetMessage(mmiCodeInfo, ssNoticeInfo);
638     ssNoticeInfo.serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NO_REPLY);
639     callSup.GetMessage(mmiCodeInfo, ssNoticeInfo);
640     ssNoticeInfo.serviceType = static_cast<int32_t>(CallTransferType::TRANSFER_TYPE_NOT_REACHABLE);
641     callSup.GetMessage(mmiCodeInfo, ssNoticeInfo);
642     callSup.AlterPinPassword(SIM1_SLOTID, mmiDataAct);
643     callSup.UnlockPuk(SIM1_SLOTID, mmiDataAct);
644     callSup.AlterPin2Password(SIM1_SLOTID, mmiDataAct);
645     callSup.UnlockPuk2(SIM1_SLOTID, mmiDataAct);
646     ASSERT_FALSE(callSup.IsVaildPinOrPuk("123", "123"));
647     ASSERT_FALSE(callSup.IsVaildPinOrPuk("1234567", "123"));
648     ASSERT_TRUE(callSup.IsVaildPinOrPuk("1234567", "1234567"));
649 }
650 
651 /**
652  * @tc.number   Telephony_CellularCallSupplement_009
653  * @tc.name     Test error branch
654  * @tc.desc     Function test
655  */
656 HWTEST_F(BranchTest, Telephony_CellularCallSupplement_009, Function | MediumTest | Level3)
657 {
658     AccessToken token;
659     CellularCallSupplement callSup;
660     auto command = std::make_shared<SsRequestCommand>();
661     CallTransferInfo cfInfo;
662 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
663     ASSERT_EQ(callSup.SetCallTransferInfoByIms(SIM1_SLOTID, cfInfo, command), TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL);
664 #else
665     ASSERT_EQ(callSup.SetCallTransferInfoByIms(SIM1_SLOTID, cfInfo, command), TELEPHONY_SUCCESS);
666 #endif
667     ASSERT_EQ(callSup.SetCallTransferInfo(SIM1_SLOTID, cfInfo), TELEPHONY_ERR_ARGUMENT_INVALID);
668     ASSERT_EQ(callSup.GetCallTransferInfo(SIM1_SLOTID, CallTransferType::TRANSFER_TYPE_UNCONDITIONAL),
669         CALL_ERR_UNSUPPORTED_NETWORK_TYPE);
670     bool activate = true;
671     ASSERT_EQ(callSup.SetCallWaiting(SIM1_SLOTID, activate), CALL_ERR_UNSUPPORTED_NETWORK_TYPE);
672     ASSERT_EQ(callSup.GetCallWaiting(SIM1_SLOTID), CALL_ERR_UNSUPPORTED_NETWORK_TYPE);
673     CallRestrictionInfo cRInfo;
674     std::string info(cRInfo.password);
675     std::string fac("AO");
676 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
677     ASSERT_EQ(callSup.SetCallRestrictionByIms(SIM1_SLOTID, fac, static_cast<int32_t>(cRInfo.mode), info, command),
678         TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL);
679 #else
680     ASSERT_EQ(callSup.SetCallRestrictionByIms(SIM1_SLOTID, fac, static_cast<int32_t>(cRInfo.mode), info, command),
681         TELEPHONY_SUCCESS);
682 #endif
683     ASSERT_EQ(callSup.GetCallRestriction(SIM1_SLOTID, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING),
684         CALL_ERR_UNSUPPORTED_NETWORK_TYPE);
685     ASSERT_EQ(callSup.SetBarringPassword(SIM1_SLOTID, CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING,
686         "1111", "0000"), CALL_ERR_UNSUPPORTED_NETWORK_TYPE);
687     ASSERT_EQ(callSup.SetCallRestriction(SIM1_SLOTID, cRInfo), CALL_ERR_UNSUPPORTED_NETWORK_TYPE);
688 }
689 
690 /**
691  * @tc.number   Telephony_CellularCallCsControl_001
692  * @tc.name     Test error branch
693  * @tc.desc     Function test
694  */
695 HWTEST_F(BranchTest, Telephony_CellularCallCsControl_001, Function | MediumTest | Level3)
696 {
697     AccessToken token;
698     CSControl csControl;
699     CellularCallInfo cellularCallInfo;
700     InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, cellularCallInfo);
701     CallInfoList callInfoList;
702     csControl.ReportCallsData(SIM1_SLOTID, callInfoList);
703     csControl.connectionMap_.insert(std::make_pair(1, CellularCallConnectionCS()));
704     csControl.ReportCallsData(SIM1_SLOTID, callInfoList);
705     csControl.connectionMap_.insert(std::make_pair(1, CellularCallConnectionCS()));
706     InitCsCallInfoList(callInfoList, 5);
707     csControl.ReportCallsData(SIM1_SLOTID, callInfoList);
708     csControl.connectionMap_.clear();
709     csControl.ReportCallsData(SIM1_SLOTID, callInfoList);
710     bool enabled = false;
711     csControl.Dial(cellularCallInfo, enabled);
712     csControl.DialCdma(cellularCallInfo);
713     csControl.DialGsm(cellularCallInfo);
714     csControl.CalculateInternationalRoaming(SIM1_SLOTID);
715     csControl.Answer(cellularCallInfo);
716     csControl.Reject(cellularCallInfo);
717     csControl.SeparateConference(SIM1_SLOTID, PHONE_NUMBER, 1);
718     csControl.SeparateConference(SIM1_SLOTID, "", 1);
719     int32_t invlaidCallType = -1;
720     csControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_DEFAULT);
721     csControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ACTIVE);
722     csControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ALL);
723     csControl.HangUp(cellularCallInfo, static_cast<CallSupplementType>(invlaidCallType));
724     csControl.HoldCall(SIM1_SLOTID);
725     csControl.UnHoldCall(SIM1_SLOTID);
726     csControl.SwitchCall(SIM1_SLOTID);
727     csControl.CombineConference(SIM1_SLOTID);
728     csControl.HangUpAllConnection(SIM1_SLOTID);
729     csControl.GetConnectionMap();
730     csControl.ReportHangUpInfo(SIM1_SLOTID);
731     csControl.ReportIncomingInfo(SIM1_SLOTID, callInfoList);
732     csControl.ReportUpdateInfo(SIM1_SLOTID, callInfoList);
733     CallInfo callInfo;
734     csControl.EncapsulationCallReportInfo(SIM1_SLOTID, callInfo);
735     std::string phoneNum = "00000000";
736     CLIRMode clirMode = CLIRMode::DEFAULT;
737     int res = csControl.EncapsulateDialCommon(SIM1_SLOTID, phoneNum, clirMode);
738     CallsReportInfo callsReportInfo;
739     csControl.DeleteConnection(callsReportInfo, callInfoList);
740     csControl.ReleaseAllConnection();
741     ASSERT_EQ(res, TELEPHONY_SUCCESS);
742 }
743 
744 /**
745  * @tc.number   Telephony_CellularCallCsControl_002
746  * @tc.name     Test error branch
747  * @tc.desc     Function test
748  */
749 HWTEST_F(BranchTest, Telephony_CellularCallCsControl_002, Function | MediumTest | Level3)
750 {
751     AccessToken token;
752     CSControl csControl;
753     CellularCallInfo cellularCallInfo;
754     InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, cellularCallInfo);
755     CellularCallInfo cellularCallInfo_new;
756     cellularCallInfo_new.callType = CallType::TYPE_CS;
757     std::vector<CellularCallInfo> infos;
758     bool enabled = false;
759     infos.emplace_back(cellularCallInfo);
760     infos.emplace_back(cellularCallInfo_new);
761     csControl.PostDialProceed(cellularCallInfo, true);
762     csControl.PostDialProceed(cellularCallInfo, enabled);
763     csControl.ExecutePostDial(SIM1_SLOTID, 0);
764     csControl.connectionMap_.insert(std::make_pair(1, CellularCallConnectionCS()));
765     cellularCallInfo.index = 1;
766     csControl.Answer(cellularCallInfo);
767     csControl.PostDialProceed(cellularCallInfo, true);
768     csControl.ExecutePostDial(SIM1_SLOTID, 0);
769     csControl.ExecutePostDial(SIM1_SLOTID, 1);
770     csControl.connectionMap_.clear();
771     for (uint16_t i = 0; i <= 7; ++i) {
772         csControl.connectionMap_.insert(std::make_pair(i, CellularCallConnectionCS()));
773     }
774     csControl.DialCdma(cellularCallInfo);
775     csControl.DialGsm(cellularCallInfo);
776     csControl.connectionMap_.clear();
777     ASSERT_EQ(csControl.ReportHangUp(infos, SIM1_SLOTID), TELEPHONY_SUCCESS);
778 }
779 
780 /**
781  * @tc.number   Telephony_CellularCallImsControl_001
782  * @tc.name     Test error branch
783  * @tc.desc     Function test
784  */
785 HWTEST_F(BranchTest, Telephony_CellularCallImsControl_001, Function | MediumTest | Level3)
786 {
787     AccessToken token;
788     IMSControl imsControl;
789     CellularCallInfo cellularCallInfo;
790     std::vector<CellularCallInfo> infos;
791     infos.emplace_back(cellularCallInfo);
792     CellularCallInfo cellularCallInfo_new;
793     bool enabled = false;
794     int32_t invalidSupType = -1;
795     ImsCurrentCallList ImsCallList;
796     InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, cellularCallInfo);
797     imsControl.ReportImsCallsData(SIM1_SLOTID, ImsCallList);
798     InitImsCallInfoList(ImsCallList, 5);
799     imsControl.ReportImsCallsData(SIM1_SLOTID, ImsCallList);
800     imsControl.Dial(cellularCallInfo, true);
801     cellularCallInfo_new.slotId = 1;
802     imsControl.Dial(cellularCallInfo_new, true);
803     cellularCallInfo_new.callType = CallType::TYPE_IMS;
804     infos.emplace_back(cellularCallInfo_new);
805     imsControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_DEFAULT);
806     imsControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_HOLD_WAIT);
807     imsControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ACTIVE);
808     imsControl.HangUp(cellularCallInfo, CallSupplementType::TYPE_HANG_UP_ALL);
809     imsControl.HangUp(cellularCallInfo, static_cast<CallSupplementType>(invalidSupType));
810     imsControl.Answer(cellularCallInfo);
811     imsControl.Reject(cellularCallInfo);
812     imsControl.PostDialProceed(cellularCallInfo, true);
813     imsControl.PostDialProceed(cellularCallInfo, enabled);
814     imsControl.RestoreConnection(infos, SIM1_SLOTID);
815     imsControl.RestoreConnection(infos, SIM2_SLOTID);
816     imsControl.ReportHangUp(infos, SIM1_SLOTID);
817     imsControl.ReportHangUp(infos, SIM2_SLOTID);
818     imsControl.HoldCall(SIM1_SLOTID);
819     imsControl.UnHoldCall(SIM1_SLOTID);
820     imsControl.SwitchCall(SIM1_SLOTID);
821     imsControl.CombineConference(SIM1_SLOTID);
822     std::vector<std::string> numberList;
823     imsControl.InviteToConference(SIM1_SLOTID, numberList);
824     std::string kickOutStr = "";
825     imsControl.KickOutFromConference(SIM1_SLOTID, kickOutStr, 0);
826     kickOutStr = "111";
827     imsControl.KickOutFromConference(SIM1_SLOTID, kickOutStr, 0);
828     imsControl.HangUpAllConnection(SIM1_SLOTID);
829     CLIRMode clirMode = CLIRMode::DEFAULT;
830     int32_t videoState = 0;
831     imsControl.DialJudgment(SIM1_SLOTID, PHONE_NUMBER, clirMode, videoState);
832 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
833     ASSERT_EQ(imsControl.EncapsulateDial(SIM1_SLOTID, PHONE_NUMBER, clirMode, videoState),
834         TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL);
835 #else
836     ASSERT_EQ(imsControl.EncapsulateDial(SIM1_SLOTID, PHONE_NUMBER, clirMode, videoState), TELEPHONY_SUCCESS);
837 #endif
838 }
839 
840 /**
841  * @tc.number   Telephony_CellularCallImsControl_002
842  * @tc.name     Test error branch
843  * @tc.desc     Function test
844  */
845 HWTEST_F(BranchTest, Telephony_CellularCallImsControl_002, Function | MediumTest | Level3)
846 {
847     AccessToken token;
848     IMSControl imsControl;
849     ImsCurrentCallList ImsCallList;
850     imsControl.ReportImsCallsData(SIM1_SLOTID, ImsCallList);
851     InitImsCallInfoList(ImsCallList, 5);
852     imsControl.ReportImsCallsData(SIM1_SLOTID, ImsCallList);
853     CallInfoList callInfoList;
854     imsControl.ReportCallsData(SIM1_SLOTID, callInfoList);
855     imsControl.ReportHangUpInfo(SIM1_SLOTID);
856     imsControl.ReportIncomingInfo(SIM1_SLOTID, ImsCallList);
857     imsControl.ReportUpdateInfo(SIM1_SLOTID, ImsCallList);
858     ImsCurrentCall ImsCallInfo;
859     imsControl.EncapsulationCallReportInfo(SIM1_SLOTID, ImsCallInfo);
860     CallsReportInfo callsReportInfo;
861     imsControl.DeleteConnection(callsReportInfo, ImsCallList);
862     imsControl.ReleaseAllConnection();
863     imsControl.DialAfterHold(SIM1_SLOTID);
864     std::string msg = "";
865     imsControl.StartRtt(SIM1_SLOTID, msg);
866     int res = imsControl.StopRtt(SIM1_SLOTID);
867     imsControl.GetConnectionMap();
868     imsControl.ReleaseAllConnection();
869 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
870     ASSERT_EQ(res, INVALID_VALUE);
871 #else
872     ASSERT_EQ(res, TELEPHONY_SUCCESS);
873 #endif
874 }
875 
876 /**
877  * @tc.number   Telephony_CellularCallImsControl_003
878  * @tc.name     Test error branch
879  * @tc.desc     Function test
880  */
881 HWTEST_F(BranchTest, Telephony_CellularCallImsControl_003, Function | MediumTest | Level3)
882 {
883     AccessToken token;
884     IMSControl imsControl;
885     imsControl.connectionMap_.insert(std::make_pair(1, CellularCallConnectionIMS()));
886     imsControl.RecoverPendingHold();
887     imsControl.DialAfterHold(SIM1_SLOTID);
888     imsControl.HangUpAllConnection(SIM1_SLOTID);
889     ImsCurrentCallList imsCallList;
890     CallsReportInfo callsReportInfo;
891     imsControl.DeleteConnection(callsReportInfo, imsCallList);
892     ASSERT_EQ(imsControl.ReportHangUpInfo(SIM1_SLOTID), TELEPHONY_SUCCESS);
893 }
894 
895 /**
896  * @tc.number   Telephony_ImsVideoCallControl_001
897  * @tc.name     Test error branch
898  * @tc.desc     Function test
899  */
900 HWTEST_F(BranchTest, Telephony_ImsVideoCallControl_001, Function | MediumTest | Level3)
901 {
902     AccessToken token;
903     auto imsVideoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
904     ASSERT_NE(imsVideoCallControl, nullptr);
905     std::string cameraId = "";
906     std::string surfaceId = "";
907     std::string path = "";
908     CellularCallInfo cellularCallInfo;
909     InitCellularCallInfo(SIM1_SLOTID, PHONE_NUMBER, cellularCallInfo);
910 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
911     ASSERT_EQ(imsVideoCallControl->ControlCamera(SIM1_SLOTID, DEFAULT_INDEX, cameraId), INVALID_VALUE);
912     ASSERT_EQ(imsVideoCallControl->SetPreviewWindow(SIM1_SLOTID, DEFAULT_INDEX, surfaceId, nullptr),
913         INVALID_VALUE);
914     ASSERT_EQ(imsVideoCallControl->SetDisplayWindow(SIM1_SLOTID, DEFAULT_INDEX, surfaceId, nullptr),
915         INVALID_VALUE);
916     ASSERT_EQ(imsVideoCallControl->SetCameraZoom(1.0), INVALID_VALUE);
917     ASSERT_EQ(imsVideoCallControl->SetPausePicture(SIM1_SLOTID, DEFAULT_INDEX, path), INVALID_VALUE);
918     ASSERT_EQ(imsVideoCallControl->SetDeviceDirection(SIM1_SLOTID, DEFAULT_INDEX, 0), INVALID_VALUE);
919     ASSERT_EQ(imsVideoCallControl->SendUpdateCallMediaModeRequest(cellularCallInfo, ImsCallMode::CALL_MODE_AUDIO_ONLY),
920         INVALID_VALUE);
921     ASSERT_EQ(imsVideoCallControl->SendUpdateCallMediaModeResponse(cellularCallInfo, ImsCallMode::CALL_MODE_AUDIO_ONLY),
922         INVALID_VALUE);
923     ASSERT_EQ(imsVideoCallControl->CancelCallUpgrade(SIM1_SLOTID, DEFAULT_INDEX), INVALID_VALUE);
924     ASSERT_EQ(imsVideoCallControl->RequestCameraCapabilities(SIM1_SLOTID, DEFAULT_INDEX), INVALID_VALUE);
925 #else
926     ASSERT_EQ(imsVideoCallControl->ControlCamera(SIM1_SLOTID, DEFAULT_INDEX, cameraId), TELEPHONY_SUCCESS);
927     ASSERT_EQ(imsVideoCallControl->SetPreviewWindow(SIM1_SLOTID, DEFAULT_INDEX, surfaceId, nullptr),
928         TELEPHONY_SUCCESS);
929     ASSERT_EQ(imsVideoCallControl->SetDisplayWindow(SIM1_SLOTID, DEFAULT_INDEX, surfaceId, nullptr),
930         TELEPHONY_SUCCESS);
931     ASSERT_EQ(imsVideoCallControl->SetCameraZoom(1.0), TELEPHONY_SUCCESS);
932     ASSERT_EQ(imsVideoCallControl->SetPausePicture(SIM1_SLOTID, DEFAULT_INDEX, path), TELEPHONY_SUCCESS);
933     ASSERT_EQ(imsVideoCallControl->SetDeviceDirection(SIM1_SLOTID, DEFAULT_INDEX, 0), TELEPHONY_SUCCESS);
934     ASSERT_EQ(imsVideoCallControl->SendUpdateCallMediaModeRequest(cellularCallInfo, ImsCallMode::CALL_MODE_AUDIO_ONLY),
935         TELEPHONY_ERR_FAIL);
936     ASSERT_EQ(imsVideoCallControl->SendUpdateCallMediaModeResponse(cellularCallInfo, ImsCallMode::CALL_MODE_AUDIO_ONLY),
937         TELEPHONY_ERR_FAIL);
938     ASSERT_EQ(imsVideoCallControl->CancelCallUpgrade(SIM1_SLOTID, DEFAULT_INDEX), TELEPHONY_SUCCESS);
939     ASSERT_EQ(imsVideoCallControl->RequestCameraCapabilities(SIM1_SLOTID, DEFAULT_INDEX), TELEPHONY_SUCCESS);
940 #endif
941 }
942 
943 /**
944  * @tc.number   Telephony_ImsVideoCallControl_002
945  * @tc.name     Test error branch
946  * @tc.desc     Function test
947  */
948 HWTEST_F(BranchTest, Telephony_ImsVideoCallControl_002, Function | MediumTest | Level3)
949 {
950     AccessToken token;
951     auto imsVideoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
952     ASSERT_NE(imsVideoCallControl, nullptr);
953     ImsCallMode mode = ImsCallMode::CALL_MODE_AUDIO_ONLY;
954     ASSERT_EQ(imsVideoCallControl->ConverToImsCallType(mode), ImsCallType::TEL_IMS_CALL_TYPE_VOICE);
955     mode = ImsCallMode::CALL_MODE_RECEIVE_ONLY;
956     ASSERT_EQ(imsVideoCallControl->ConverToImsCallType(mode), ImsCallType::TEL_IMS_CALL_TYPE_VT_RX);
957     mode = ImsCallMode::CALL_MODE_SEND_ONLY;
958     ASSERT_EQ(imsVideoCallControl->ConverToImsCallType(mode), ImsCallType::TEL_IMS_CALL_TYPE_VT_TX);
959     mode = ImsCallMode::CALL_MODE_SEND_RECEIVE;
960     ASSERT_EQ(imsVideoCallControl->ConverToImsCallType(mode), ImsCallType::TEL_IMS_CALL_TYPE_VT);
961     mode = ImsCallMode::CALL_MODE_VIDEO_PAUSED;
962     ASSERT_EQ(imsVideoCallControl->ConverToImsCallType(mode), ImsCallType::TEL_IMS_CALL_TYPE_PAUSE);
963 }
964 
965 /**
966  * @tc.number   Telephony_CellularCallConnectionIms_001
967  * @tc.name     Test error branch
968  * @tc.desc     Function test
969  */
970 HWTEST_F(BranchTest, Telephony_CellularCallConnectionIms_001, Function | MediumTest | Level3)
971 {
972     AccessToken token;
973     CellularCallConnectionIMS callConn;
974     ImsDialInfoStruct dialRequest;
975     std::vector<std::string> numberList = {};
976     std::string msg = "";
977 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
978     ASSERT_EQ(callConn.DialRequest(SIM1_SLOTID, dialRequest), TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL);
979     ASSERT_EQ(callConn.HangUpRequest(SIM1_SLOTID, PHONE_NUMBER, 0), INVALID_VALUE);
980     ASSERT_EQ(callConn.AnswerRequest(SIM1_SLOTID, PHONE_NUMBER, 0, 0), INVALID_VALUE);
981     ASSERT_EQ(callConn.RejectRequest(SIM1_SLOTID, PHONE_NUMBER, 0), INVALID_VALUE);
982     ASSERT_EQ(callConn.HoldCallRequest(SIM1_SLOTID), INVALID_VALUE);
983     ASSERT_EQ(callConn.UnHoldCallRequest(SIM1_SLOTID), INVALID_VALUE);
984     ASSERT_EQ(callConn.SwitchCallRequest(SIM1_SLOTID), INVALID_VALUE);
985     ASSERT_EQ(callConn.CombineConferenceRequest(SIM1_SLOTID, 0), INVALID_VALUE);
986     ASSERT_EQ(callConn.InviteToConferenceRequest(SIM1_SLOTID, numberList), INVALID_VALUE);
987     ASSERT_EQ(callConn.KickOutFromConferenceRequest(SIM1_SLOTID, 0), INVALID_VALUE);
988     ASSERT_EQ(callConn.CallSupplementRequest(SIM1_SLOTID, CallSupplementType::TYPE_DEFAULT), TELEPHONY_SUCCESS);
989     ASSERT_EQ(callConn.StartRttRequest(SIM1_SLOTID, msg), INVALID_VALUE);
990     ASSERT_EQ(callConn.StopRttRequest(SIM1_SLOTID), INVALID_VALUE);
991     ASSERT_EQ(callConn.GetImsCallsDataRequest(SIM1_SLOTID, 0), INVALID_VALUE);
992     ASSERT_EQ(callConn.SendDtmfRequest(SIM1_SLOTID, '*', 0), INVALID_VALUE);
993     ASSERT_EQ(callConn.StartDtmfRequest(SIM1_SLOTID, '*', 0), INVALID_VALUE);
994     ASSERT_EQ(callConn.StopDtmfRequest(SIM1_SLOTID, 0), INVALID_VALUE);
995     ASSERT_EQ(callConn.GetCallFailReasonRequest(SIM1_SLOTID), INVALID_VALUE);
996 #else
997     ASSERT_EQ(callConn.DialRequest(SIM1_SLOTID, dialRequest), TELEPHONY_SUCCESS);
998     ASSERT_EQ(callConn.HangUpRequest(SIM1_SLOTID, PHONE_NUMBER, 0), TELEPHONY_SUCCESS);
999     ASSERT_EQ(callConn.AnswerRequest(SIM1_SLOTID, PHONE_NUMBER, 0, 0), TELEPHONY_SUCCESS);
1000     ASSERT_EQ(callConn.RejectRequest(SIM1_SLOTID, PHONE_NUMBER, 0), TELEPHONY_SUCCESS);
1001     ASSERT_EQ(callConn.HoldCallRequest(SIM1_SLOTID), TELEPHONY_SUCCESS);
1002     ASSERT_EQ(callConn.UnHoldCallRequest(SIM1_SLOTID), TELEPHONY_SUCCESS);
1003     ASSERT_EQ(callConn.SwitchCallRequest(SIM1_SLOTID), TELEPHONY_SUCCESS);
1004     ASSERT_EQ(callConn.CombineConferenceRequest(SIM1_SLOTID, 0), TELEPHONY_SUCCESS);
1005     ASSERT_EQ(callConn.InviteToConferenceRequest(SIM1_SLOTID, numberList), TELEPHONY_SUCCESS);
1006     ASSERT_EQ(callConn.KickOutFromConferenceRequest(SIM1_SLOTID, 0), TELEPHONY_SUCCESS);
1007     ASSERT_EQ(callConn.CallSupplementRequest(SIM1_SLOTID, CallSupplementType::TYPE_DEFAULT), TELEPHONY_SUCCESS);
1008     ASSERT_EQ(callConn.StartRttRequest(SIM1_SLOTID, msg), TELEPHONY_SUCCESS);
1009     ASSERT_EQ(callConn.StopRttRequest(SIM1_SLOTID), TELEPHONY_SUCCESS);
1010     ASSERT_EQ(callConn.GetImsCallsDataRequest(SIM1_SLOTID, 0), TELEPHONY_SUCCESS);
1011     ASSERT_EQ(callConn.SendDtmfRequest(SIM1_SLOTID, '*', 0), TELEPHONY_SUCCESS);
1012     ASSERT_EQ(callConn.StartDtmfRequest(SIM1_SLOTID, '*', 0), TELEPHONY_SUCCESS);
1013     ASSERT_EQ(callConn.StopDtmfRequest(SIM1_SLOTID, 0), TELEPHONY_SUCCESS);
1014     ASSERT_EQ(callConn.GetCallFailReasonRequest(SIM1_SLOTID), TELEPHONY_SUCCESS);
1015 #endif
1016 }
1017 
1018 /**
1019  * @tc.number   Telephony_CellularCallConfigRequest_001
1020  * @tc.name     Test error branch
1021  * @tc.desc     Function test
1022  */
1023 HWTEST_F(BranchTest, Telephony_CellularCallConfigRequest_001, Function | MediumTest | Level3)
1024 {
1025     AccessToken token;
1026     ConfigRequest configReq;
1027     configReq.SetDomainPreferenceModeRequest(SIM1_SLOTID, 1);
1028     configReq.GetDomainPreferenceModeRequest(SIM1_SLOTID);
1029     configReq.SetDomainPreferenceModeRequest(SIM2_SLOTID, 1);
1030     configReq.GetDomainPreferenceModeRequest(SIM2_SLOTID);
1031     bool enabled = false;
1032     configReq.SetImsSwitchStatusRequest(SIM1_SLOTID, enabled);
1033     configReq.GetImsSwitchStatusRequest(SIM1_SLOTID);
1034     int32_t state = 0;
1035     configReq.SetVoNRSwitchStatusRequest(SIM1_SLOTID, state);
1036     configReq.SetVoNRSwitchStatusRequest(SIM2_SLOTID, state);
1037     std::string value = "";
1038     configReq.SetImsConfigRequest(ImsConfigItem::ITEM_VIDEO_QUALITY, value);
1039     configReq.SetImsConfigRequest(ImsConfigItem::ITEM_VIDEO_QUALITY, 1);
1040     configReq.GetImsConfigRequest(ImsConfigItem::ITEM_VIDEO_QUALITY);
1041     configReq.SetImsFeatureValueRequest(FeatureType::TYPE_VOICE_OVER_LTE, 1);
1042     int32_t imsFeature = 0;
1043     configReq.GetImsFeatureValueRequest(FeatureType::TYPE_VOICE_OVER_LTE, imsFeature);
1044     configReq.SetMuteRequest(SIM1_SLOTID, 0);
1045     configReq.GetMuteRequest(SIM1_SLOTID);
1046     configReq.SetMuteRequest(SIM2_SLOTID, 0);
1047     configReq.GetMuteRequest(SIM2_SLOTID);
1048     std::vector<EmergencyCall> eccVec = {};
1049     configReq.GetEmergencyCallListRequest(SIM1_SLOTID);
1050     configReq.SetEmergencyCallListRequest(SIM1_SLOTID, eccVec);
1051     configReq.GetEmergencyCallListRequest(SIM2_SLOTID);
1052     configReq.SetEmergencyCallListRequest(SIM2_SLOTID, eccVec);
1053     ImsCapabilityList imsCapabilityList;
1054 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
1055     ASSERT_EQ(configReq.UpdateImsCapabilities(SIM1_SLOTID, imsCapabilityList), CALL_ERR_RESOURCE_UNAVAILABLE);
1056 #else
1057     ASSERT_EQ(configReq.UpdateImsCapabilities(SIM1_SLOTID, imsCapabilityList), TELEPHONY_SUCCESS);
1058 #endif
1059 }
1060 } // namespace Telephony
1061 } // namespace OHOS