• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ims_unit_test.h"
17 
18 #include "iservice_registry.h"
19 #include "securec.h"
20 #include "system_ability_definition.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 using namespace testing::ext;
25 const int32_t CELLULAR_CALL_ERROR = -1;
26 const int32_t CELLULAR_CALL_SUCCESS = 0;
27 
SetUpTestCase(void)28 void ImsUnitTest::SetUpTestCase(void)
29 {
30     // step 3: Set Up Test Case
31 }
32 
TearDownTestCase(void)33 void ImsUnitTest::TearDownTestCase(void)
34 {
35     // step 3: Tear Down Test Case
36 }
37 
SetUp(void)38 void ImsUnitTest::SetUp(void)
39 {
40     // step 3: input testcase setup step
41     requestFuncMap_[ImsInterface::IMS_DIAL] = &ImsUnitTest::Dial;
42     requestFuncMap_[ImsInterface::IMS_HANG_UP] = &ImsUnitTest::HangUp;
43     requestFuncMap_[ImsInterface::IMS_REJECT] = &ImsUnitTest::Reject;
44     requestFuncMap_[ImsInterface::IMS_ANSWER] = &ImsUnitTest::Answer;
45     requestFuncMap_[ImsInterface::IMS_HOLD] = &ImsUnitTest::HoldCall;
46     requestFuncMap_[ImsInterface::IMS_UN_HOLD] = &ImsUnitTest::UnHoldCall;
47     requestFuncMap_[ImsInterface::IMS_SWITCH] = &ImsUnitTest::SwitchCall;
48     requestFuncMap_[ImsInterface::IMS_COMBINE_CONFERENCE] = &ImsUnitTest::CombineConference;
49     requestFuncMap_[ImsInterface::IMS_INVITE_TO_CONFERENCE] = &ImsUnitTest::InviteToConference;
50     requestFuncMap_[ImsInterface::IMS_KICK_OUT_CONFERENCE] = &ImsUnitTest::KickOutFromConference;
51     requestFuncMap_[ImsInterface::IMS_UPDATE_CALL_MEDIA_MODE] = &ImsUnitTest::UpdateImsCallMode;
52     requestFuncMap_[ImsInterface::IMS_EMERGENCY_CALL] = &ImsUnitTest::IsEmergencyPhoneNumber;
53     requestFuncMap_[ImsInterface::GET_CALL_FAIL_REASON] = &ImsUnitTest::GetCallFailReason;
54     requestFuncMap_[ImsInterface::IMS_START_DTMF] = &ImsUnitTest::StartDtmf;
55     requestFuncMap_[ImsInterface::IMS_SEND_DTMF] = &ImsUnitTest::SendDtmf;
56     requestFuncMap_[ImsInterface::IMS_STOP_DTMF] = &ImsUnitTest::StopDtmf;
57     requestFuncMap_[ImsInterface::IMS_START_RTT] = &ImsUnitTest::StartRtt;
58     requestFuncMap_[ImsInterface::IMS_STOP_RTT] = &ImsUnitTest::StopRtt;
59     requestFuncMap_[ImsInterface::IMS_SET_DOMAIN_PREFERENCE_MODE] = &ImsUnitTest::SetDomainPreferenceMode;
60     requestFuncMap_[ImsInterface::IMS_GET_DOMAIN_PREFERENCE_MODE] = &ImsUnitTest::GetDomainPreferenceMode;
61     requestFuncMap_[ImsInterface::IMS_SET_LTE_IMS_SWITCH_STATUS] = &ImsUnitTest::SetLteImsSwitchStatus;
62     requestFuncMap_[ImsInterface::IMS_GET_LTE_IMS_SWITCH_STATUS] = &ImsUnitTest::GetLteImsSwitchStatus;
63     requestFuncMap_[ImsInterface::IMS_SET_IMS_CONFIG_STRING] = &ImsUnitTest::SetImsConfigString;
64     requestFuncMap_[ImsInterface::IMS_SET_IMS_CONFIG_INT] = &ImsUnitTest::SetImsConfigInt;
65     requestFuncMap_[ImsInterface::IMS_GET_IMS_CONFIG] = &ImsUnitTest::GetImsConfig;
66     requestFuncMap_[ImsInterface::IMS_SET_IMS_FEATURE] = &ImsUnitTest::SetImsFeatureValue;
67     requestFuncMap_[ImsInterface::IMS_GET_IMS_FEATURE] = &ImsUnitTest::GetImsFeatureValue;
68     requestFuncMap_[ImsInterface::IMS_SET_IMS_SWITCH_ENHANCE_MODE] = &ImsUnitTest::SetImsSwitchEnhanceMode;
69     requestFuncMap_[ImsInterface::IMS_GET_IMS_SWITCH_ENHANCE_MODE] = &ImsUnitTest::GetImsSwitchEnhanceMode;
70     requestFuncMap_[ImsInterface::IMS_CTRL_CAMERA] = &ImsUnitTest::CtrlCamera;
71     requestFuncMap_[ImsInterface::IMS_SET_PREVIEW_WINDOW] = &ImsUnitTest::SetPreviewWindow;
72     requestFuncMap_[ImsInterface::IMS_SET_DISPLAY_WINDOW] = &ImsUnitTest::SetDisplayWindow;
73     requestFuncMap_[ImsInterface::IMS_SET_CAMERA_ZOOM] = &ImsUnitTest::SetCameraZoom;
74     requestFuncMap_[ImsInterface::IMS_SET_PAUSE_IMAGE] = &ImsUnitTest::SetPauseImage;
75     requestFuncMap_[ImsInterface::IMS_SET_DEVICE_DIRECTION] = &ImsUnitTest::SetDeviceDirection;
76     requestFuncMap_[ImsInterface::IMS_REGISTER_CALLBACK] = &ImsUnitTest::RegisterCellularCallBack;
77     requestFuncMap_[ImsInterface::IMS_IS_CALLBACK_EXISTS] = &ImsUnitTest::IsCallBackExists;
78     requestFuncMap_[ImsInterface::IMS_SET_MUTE] = &ImsUnitTest::SetMute;
79     requestFuncMap_[ImsInterface::IMS_GET_MUTE] = &ImsUnitTest::GetMute;
80     requestFuncMap_[ImsInterface::IMS_SET_CALL_TRANSFER] = &ImsUnitTest::SetCallTransfer;
81     requestFuncMap_[ImsInterface::IMS_GET_CALL_TRANSFER] = &ImsUnitTest::GetCallTransfer;
82     requestFuncMap_[ImsInterface::IMS_SET_CALL_RESTRICTION] = &ImsUnitTest::SetCallRestriction;
83     requestFuncMap_[ImsInterface::IMS_GET_CALL_RESTRICTION] = &ImsUnitTest::GetCallRestriction;
84     requestFuncMap_[ImsInterface::IMS_SET_CALL_WAITING] = &ImsUnitTest::SetCallWaiting;
85     requestFuncMap_[ImsInterface::IMS_GET_CALL_WAITING] = &ImsUnitTest::GetCallWaiting;
86 }
87 
TearDown(void)88 void ImsUnitTest::TearDown(void)
89 {
90     // step 3: input testcase teardown step
91 }
92 
Dial(const sptr<ImsInterface> & telephonyService) const93 int32_t ImsUnitTest::Dial(const sptr<ImsInterface> &telephonyService) const
94 {
95     std::cout << "test Dial entry." << std::endl;
96     ImsCallInfo callInfo;
97     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
98         std::cout << "Dial return, memset_s failed." << std::endl;
99         return CELLULAR_CALL_ERROR;
100     }
101     std::cout << "please enter the phone number:";
102     std::cin >> callInfo.phoneNum;
103     callInfo.videoState = 1;
104     callInfo.slotId = 0;
105     CLIRMode mode = CLIRMode::DEFAULT;
106     telephonyService->Dial(callInfo, mode);
107     return CELLULAR_CALL_SUCCESS;
108 }
109 
HangUp(const sptr<ImsInterface> & telephonyService) const110 int32_t ImsUnitTest::HangUp(const sptr<ImsInterface> &telephonyService) const
111 {
112     std::cout << "test HangUp entry." << std::endl;
113     ImsCallInfo callInfo;
114     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
115         std::cout << "HangUp return, memset_s failed." << std::endl;
116         return CELLULAR_CALL_ERROR;
117     }
118     std::cout << "please enter the phone number:";
119     std::cin >> callInfo.phoneNum;
120     callInfo.videoState = 1;
121     callInfo.slotId = 0;
122     std::cout << "please enter the connect index:";
123     std::cin >> callInfo.index;
124     telephonyService->HangUp(callInfo);
125     return CELLULAR_CALL_SUCCESS;
126 }
127 
Reject(const sptr<ImsInterface> & telephonyService) const128 int32_t ImsUnitTest::Reject(const sptr<ImsInterface> &telephonyService) const
129 {
130     std::cout << "test Reject entry." << std::endl;
131     ImsCallInfo callInfo;
132     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
133         std::cout << "Reject return, memset_s failed." << std::endl;
134         return CELLULAR_CALL_ERROR;
135     }
136     std::cout << "please enter the phone number:";
137     std::cin >> callInfo.phoneNum;
138     callInfo.videoState = 1;
139     callInfo.slotId = 0;
140     std::cout << "please enter the connect index:";
141     std::cin >> callInfo.index;
142     telephonyService->Reject(callInfo);
143     return CELLULAR_CALL_SUCCESS;
144 }
145 
Answer(const sptr<ImsInterface> & telephonyService) const146 int32_t ImsUnitTest::Answer(const sptr<ImsInterface> &telephonyService) const
147 {
148     std::cout << "test Answer entry." << std::endl;
149     ImsCallInfo callInfo;
150     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
151         std::cout << "Answer return, memset_s failed." << std::endl;
152         return CELLULAR_CALL_ERROR;
153     }
154     std::cout << "please enter the phone number:";
155     std::cin >> callInfo.phoneNum;
156     callInfo.videoState = 1;
157     callInfo.slotId = 0;
158     std::cout << "please enter the connect index:";
159     std::cin >> callInfo.index;
160     telephonyService->Answer(callInfo);
161     return CELLULAR_CALL_SUCCESS;
162 }
163 
HoldCall(const sptr<ImsInterface> & telephonyService) const164 int32_t ImsUnitTest::HoldCall(const sptr<ImsInterface> &telephonyService) const
165 {
166     std::cout << "test HoldCall entry." << std::endl;
167     int32_t slotId;
168     std::cout << "please enter the slot id:";
169     std::cin >> slotId;
170     telephonyService->HoldCall(slotId);
171     return CELLULAR_CALL_SUCCESS;
172 }
173 
UnHoldCall(const sptr<ImsInterface> & telephonyService) const174 int32_t ImsUnitTest::UnHoldCall(const sptr<ImsInterface> &telephonyService) const
175 {
176     std::cout << "test UnHoldCall entry." << std::endl;
177     int32_t slotId;
178     std::cout << "please enter the slot id:";
179     std::cin >> slotId;
180     telephonyService->UnHoldCall(slotId);
181     return CELLULAR_CALL_SUCCESS;
182 }
183 
SwitchCall(const sptr<ImsInterface> & telephonyService) const184 int32_t ImsUnitTest::SwitchCall(const sptr<ImsInterface> &telephonyService) const
185 {
186     std::cout << "test SwitchCall entry." << std::endl;
187     int32_t slotId;
188     std::cout << "please enter the slot id:";
189     std::cin >> slotId;
190     telephonyService->SwitchCall(slotId);
191     return CELLULAR_CALL_SUCCESS;
192 }
193 
CombineConference(const sptr<ImsInterface> & telephonyService) const194 int32_t ImsUnitTest::CombineConference(const sptr<ImsInterface> &telephonyService) const
195 {
196     std::cout << "test CombineConference entry." << std::endl;
197     std::cout << "please enter the slotId:";
198     int32_t slotId = 0;
199     telephonyService->CombineConference(slotId);
200     return CELLULAR_CALL_SUCCESS;
201 }
202 
InviteToConference(const sptr<ImsInterface> & telephonyService) const203 int32_t ImsUnitTest::InviteToConference(const sptr<ImsInterface> &telephonyService) const
204 {
205     std::cout << "test InviteToConference entry." << std::endl;
206     std::vector<std::string> numberList;
207     std::cout << "please enter the invite phone number:";
208     std::string phoneNum;
209     std::cin >> phoneNum;
210     numberList.push_back(phoneNum);
211     std::cout << "please enter the slotId:";
212     int32_t slotId = 0;
213     telephonyService->InviteToConference(slotId, numberList);
214     return CELLULAR_CALL_SUCCESS;
215 }
216 
KickOutFromConference(const sptr<ImsInterface> & telephonyService) const217 int32_t ImsUnitTest::KickOutFromConference(const sptr<ImsInterface> &telephonyService) const
218 {
219     std::cout << "test KickOutFromConference entry." << std::endl;
220     std::vector<std::string> numberList;
221     std::cout << "please enter the kick out phone number:";
222     std::string phoneNum;
223     std::cin >> phoneNum;
224     numberList.push_back(phoneNum);
225     std::cout << "please enter the slotId:";
226     int32_t slotId = 0;
227     telephonyService->KickOutFromConference(slotId, numberList);
228     return CELLULAR_CALL_SUCCESS;
229 }
230 
UpdateImsCallMode(const sptr<ImsInterface> & telephonyService) const231 int32_t ImsUnitTest::UpdateImsCallMode(const sptr<ImsInterface> &telephonyService) const
232 {
233     std::cout << "test UpdateImsCallMode entry." << std::endl;
234     ImsCallInfo callInfo;
235     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
236         std::cout << "UpdateImsCallMode return, memset_s failed." << std::endl;
237         return CELLULAR_CALL_ERROR;
238     }
239     std::cout << "please enter the phone number:";
240     std::cin >> callInfo.phoneNum;
241     callInfo.videoState = 1;
242     callInfo.slotId = 0;
243     std::cout << "please enter the connect index:";
244     std::cin >> callInfo.index;
245     std::cout << "please enter the update call mode():";
246     int32_t mode = 0;
247     std::cin >> mode;
248     telephonyService->UpdateImsCallMode(callInfo, static_cast<ImsCallMode>(mode));
249     return CELLULAR_CALL_SUCCESS;
250 }
251 
IsEmergencyPhoneNumber(const sptr<ImsInterface> & telephonyService) const252 int32_t ImsUnitTest::IsEmergencyPhoneNumber(const sptr<ImsInterface> &telephonyService) const
253 {
254     std::cout << "test IsEmergencyPhoneNumber entry." << std::endl;
255     std::cout << "please enter the phone number:";
256     std::string phoneNum;
257     std::cin >> phoneNum;
258     std::cout << "please enter the slot id:";
259     int32_t slotId = 0;
260     std::cin >> slotId;
261     telephonyService->IsEmergencyPhoneNumber(slotId, phoneNum);
262     return CELLULAR_CALL_SUCCESS;
263 }
264 
GetCallFailReason(const sptr<ImsInterface> & telephonyService) const265 int32_t ImsUnitTest::GetCallFailReason(const sptr<ImsInterface> &telephonyService) const
266 {
267     std::cout << "test GetCallFailReason entry." << std::endl;
268     std::cout << "please enter the slot id:";
269     int32_t slotId = 0;
270     std::cin >> slotId;
271     telephonyService->GetCallFailReason(slotId);
272     return CELLULAR_CALL_SUCCESS;
273 }
274 
StartDtmf(const sptr<ImsInterface> & telephonyService) const275 int32_t ImsUnitTest::StartDtmf(const sptr<ImsInterface> &telephonyService) const
276 {
277     std::cout << "test StartDtmf entry." << std::endl;
278     std::cout << "please enter the dtmf code(0-9,#,*,A,D):";
279     char dtmfCode;
280     std::cin >> dtmfCode;
281     std::cout << "please enter the index:";
282     int32_t index = 0;
283     std::cin >> index;
284     std::cout << "please enter the slot id:";
285     int32_t slotId = 0;
286     std::cin >> slotId;
287     telephonyService->StartDtmf(slotId, dtmfCode, index);
288     return CELLULAR_CALL_SUCCESS;
289 }
290 
SendDtmf(const sptr<ImsInterface> & telephonyService) const291 int32_t ImsUnitTest::SendDtmf(const sptr<ImsInterface> &telephonyService) const
292 {
293     std::cout << "test SendDtmf entry." << std::endl;
294     std::cout << "please enter the dtmf code(0-9,#,*,A,D):";
295     char dtmfCode;
296     std::cin >> dtmfCode;
297     std::cout << "please enter the index:";
298     int32_t index = 0;
299     std::cin >> index;
300     std::cout << "please enter the slot id:";
301     int32_t slotId = 0;
302     std::cin >> slotId;
303     telephonyService->SendDtmf(slotId, dtmfCode, index);
304     return CELLULAR_CALL_SUCCESS;
305 }
306 
StopDtmf(const sptr<ImsInterface> & telephonyService) const307 int32_t ImsUnitTest::StopDtmf(const sptr<ImsInterface> &telephonyService) const
308 {
309     std::cout << "test StopDtmf entry." << std::endl;
310     std::cout << "please enter the index:";
311     int32_t index = 0;
312     std::cin >> index;
313     std::cout << "please enter the slot id:";
314     int32_t slotId = 0;
315     std::cin >> slotId;
316     telephonyService->StopDtmf(slotId, index);
317     return CELLULAR_CALL_SUCCESS;
318 }
319 
StartRtt(const sptr<ImsInterface> & telephonyService) const320 int32_t ImsUnitTest::StartRtt(const sptr<ImsInterface> &telephonyService) const
321 {
322     std::cout << "test StartRtt entry." << std::endl;
323     std::cout << "please enter the send msg:";
324     std::string msg;
325     std::cin >> msg;
326     std::cout << "please enter the slot id:";
327     int32_t slotId = 0;
328     std::cin >> slotId;
329     telephonyService->StartRtt(slotId, msg);
330     return CELLULAR_CALL_SUCCESS;
331 }
332 
StopRtt(const sptr<ImsInterface> & telephonyService) const333 int32_t ImsUnitTest::StopRtt(const sptr<ImsInterface> &telephonyService) const
334 {
335     std::cout << "test StopRtt entry." << std::endl;
336     std::cout << "please enter the slot id:";
337     int32_t slotId = 0;
338     std::cin >> slotId;
339     telephonyService->StopRtt(slotId);
340     return CELLULAR_CALL_SUCCESS;
341 }
342 
SetDomainPreferenceMode(const sptr<ImsInterface> & telephonyService) const343 int32_t ImsUnitTest::SetDomainPreferenceMode(const sptr<ImsInterface> &telephonyService) const
344 {
345     std::cout << "test SetDomainPreferenceMode entry." << std::endl;
346     std::cout << "please enter the need mode:(1 - 4)";
347     int32_t mode;
348     std::cin >> mode;
349     std::cout << "please enter the slot id:";
350     int32_t slotId = 0;
351     std::cin >> slotId;
352     telephonyService->SetDomainPreferenceMode(slotId, mode);
353     return CELLULAR_CALL_SUCCESS;
354 }
355 
GetDomainPreferenceMode(const sptr<ImsInterface> & telephonyService) const356 int32_t ImsUnitTest::GetDomainPreferenceMode(const sptr<ImsInterface> &telephonyService) const
357 {
358     std::cout << "test GetDomainPreferenceMode entry." << std::endl;
359     std::cout << "please enter the slot id:";
360     int32_t slotId = 0;
361     std::cin >> slotId;
362     telephonyService->GetDomainPreferenceMode(slotId);
363     return CELLULAR_CALL_SUCCESS;
364 }
365 
SetLteImsSwitchStatus(const sptr<ImsInterface> & telephonyService) const366 int32_t ImsUnitTest::SetLteImsSwitchStatus(const sptr<ImsInterface> &telephonyService) const
367 {
368     std::cout << "test SetLteImsSwitchStatus entry." << std::endl;
369     std::cout << "please enter the switch state:";
370     bool active;
371     std::cin >> active;
372     std::cout << "please enter the slot id:";
373     int32_t slotId = 0;
374     std::cin >> slotId;
375     telephonyService->SetLteImsSwitchStatus(slotId, active);
376     return CELLULAR_CALL_SUCCESS;
377 }
378 
GetLteImsSwitchStatus(const sptr<ImsInterface> & telephonyService) const379 int32_t ImsUnitTest::GetLteImsSwitchStatus(const sptr<ImsInterface> &telephonyService) const
380 {
381     std::cout << "test GetLteImsSwitchStatus entry." << std::endl;
382     std::cout << "please enter the slot id:";
383     int32_t slotId = 0;
384     std::cin >> slotId;
385     telephonyService->GetLteImsSwitchStatus(slotId);
386     return CELLULAR_CALL_SUCCESS;
387 }
388 
SetImsConfigString(const sptr<ImsInterface> & telephonyService) const389 int32_t ImsUnitTest::SetImsConfigString(const sptr<ImsInterface> &telephonyService) const
390 {
391     std::cout << "test SetImsConfigString entry." << std::endl;
392     std::cout << "please enter the item id:";
393     int32_t item = 0;
394     std::cin >> item;
395     std::cout << "please enter the item value:";
396     std::string value;
397     std::cin >> value;
398     telephonyService->SetImsConfig(static_cast<ImsConfigItem>(item), value);
399     return CELLULAR_CALL_SUCCESS;
400 }
401 
SetImsConfigInt(const sptr<ImsInterface> & telephonyService) const402 int32_t ImsUnitTest::SetImsConfigInt(const sptr<ImsInterface> &telephonyService) const
403 {
404     std::cout << "test SetImsConfigInt entry." << std::endl;
405     std::cout << "please enter the item id:";
406     int32_t item = 0;
407     std::cin >> item;
408     std::cout << "please enter the item value:";
409     int32_t value = 0;
410     std::cin >> value;
411     telephonyService->SetImsConfig(static_cast<ImsConfigItem>(item), value);
412     return CELLULAR_CALL_SUCCESS;
413 }
414 
GetImsConfig(const sptr<ImsInterface> & telephonyService) const415 int32_t ImsUnitTest::GetImsConfig(const sptr<ImsInterface> &telephonyService) const
416 {
417     std::cout << "test GetImsConfig entry." << std::endl;
418     std::cout << "please enter the item id:";
419     int32_t item = 0;
420     std::cin >> item;
421     telephonyService->GetImsConfig(static_cast<ImsConfigItem>(item));
422     return CELLULAR_CALL_SUCCESS;
423 }
424 
SetImsFeatureValue(const sptr<ImsInterface> & telephonyService) const425 int32_t ImsUnitTest::SetImsFeatureValue(const sptr<ImsInterface> &telephonyService) const
426 {
427     std::cout << "test SetImsFeatureValue entry." << std::endl;
428     std::cout << "please enter the feature type:";
429     int32_t type = 0;
430     std::cin >> type;
431     std::cout << "please enter the feature value:";
432     int32_t value = 0;
433     std::cin >> value;
434     telephonyService->SetImsFeatureValue(static_cast<FeatureType>(type), value);
435     return CELLULAR_CALL_SUCCESS;
436 }
437 
GetImsFeatureValue(const sptr<ImsInterface> & telephonyService) const438 int32_t ImsUnitTest::GetImsFeatureValue(const sptr<ImsInterface> &telephonyService) const
439 {
440     std::cout << "test GetImsFeatureValue entry." << std::endl;
441     std::cout << "please enter the feature type:";
442     int32_t type = 0;
443     std::cin >> type;
444     telephonyService->GetImsFeatureValue(static_cast<FeatureType>(type));
445     return CELLULAR_CALL_SUCCESS;
446 }
447 
SetImsSwitchEnhanceMode(const sptr<ImsInterface> & telephonyService) const448 int32_t ImsUnitTest::SetImsSwitchEnhanceMode(const sptr<ImsInterface> &telephonyService) const
449 {
450     std::cout << "test SetImsSwitchEnhanceMode entry." << std::endl;
451     std::cout << "please enter the ImsSwitch enhance mode:";
452     bool mode;
453     std::cin >> mode;
454     telephonyService->SetImsSwitchEnhanceMode(mode);
455     return CELLULAR_CALL_SUCCESS;
456 }
457 
GetImsSwitchEnhanceMode(const sptr<ImsInterface> & telephonyService) const458 int32_t ImsUnitTest::GetImsSwitchEnhanceMode(const sptr<ImsInterface> &telephonyService) const
459 {
460     std::cout << "test GetImsSwitchEnhanceMode entry." << std::endl;
461     telephonyService->GetImsSwitchEnhanceMode();
462     return CELLULAR_CALL_SUCCESS;
463 }
464 
CtrlCamera(const sptr<ImsInterface> & telephonyService) const465 int32_t ImsUnitTest::CtrlCamera(const sptr<ImsInterface> &telephonyService) const
466 {
467     std::cout << "test CtrlCamera entry." << std::endl;
468     std::u16string cameraId = u"cameraId";
469     int32_t callingUid = 0;
470     int32_t callingPid = 0;
471     telephonyService->CtrlCamera(cameraId, callingUid, callingPid);
472     return CELLULAR_CALL_SUCCESS;
473 }
474 
SetPreviewWindow(const sptr<ImsInterface> & telephonyService) const475 int32_t ImsUnitTest::SetPreviewWindow(const sptr<ImsInterface> &telephonyService) const
476 {
477     std::cout << "test SetPreviewWindow entry." << std::endl;
478     int32_t x = 0;
479     int32_t y = 0;
480     int32_t z = 0;
481     int32_t width = 0;
482     int32_t height = 0;
483     telephonyService->SetPreviewWindow(x, y, z, width, height);
484     return CELLULAR_CALL_SUCCESS;
485 }
486 
SetDisplayWindow(const sptr<ImsInterface> & telephonyService) const487 int32_t ImsUnitTest::SetDisplayWindow(const sptr<ImsInterface> &telephonyService) const
488 {
489     std::cout << "test SetDisplayWindow entry." << std::endl;
490     int32_t x = 0;
491     int32_t y = 0;
492     int32_t z = 0;
493     int32_t width = 0;
494     int32_t height = 0;
495     telephonyService->SetDisplayWindow(x, y, z, width, height);
496     return CELLULAR_CALL_SUCCESS;
497 }
498 
SetCameraZoom(const sptr<ImsInterface> & telephonyService) const499 int32_t ImsUnitTest::SetCameraZoom(const sptr<ImsInterface> &telephonyService) const
500 {
501     std::cout << "test SetCameraZoom entry." << std::endl;
502     float zoomRatio = 1.0;
503     telephonyService->SetCameraZoom(zoomRatio);
504     return CELLULAR_CALL_SUCCESS;
505 }
506 
SetPauseImage(const sptr<ImsInterface> & telephonyService) const507 int32_t ImsUnitTest::SetPauseImage(const sptr<ImsInterface> &telephonyService) const
508 {
509     std::cout << "test SetPauseImage entry." << std::endl;
510     std::u16string path = u"path";
511     telephonyService->SetPauseImage(path);
512     return CELLULAR_CALL_SUCCESS;
513 }
514 
SetDeviceDirection(const sptr<ImsInterface> & telephonyService) const515 int32_t ImsUnitTest::SetDeviceDirection(const sptr<ImsInterface> &telephonyService) const
516 {
517     std::cout << "test SetDeviceDirection entry." << std::endl;
518     int32_t rotation = 0;
519     telephonyService->SetDeviceDirection(rotation);
520     return CELLULAR_CALL_SUCCESS;
521 }
522 
RegisterCellularCallBack(const sptr<ImsInterface> & telephonyService) const523 int32_t ImsUnitTest::RegisterCellularCallBack(const sptr<ImsInterface> &telephonyService) const
524 {
525     std::cout << "test RegisterCellularCallBack entry." << std::endl;
526     return CELLULAR_CALL_SUCCESS;
527 }
528 
IsCallBackExists(const sptr<ImsInterface> & telephonyService) const529 int32_t ImsUnitTest::IsCallBackExists(const sptr<ImsInterface> &telephonyService) const
530 {
531     std::cout << "test IsCallBackExists entry." << std::endl;
532     bool ret = telephonyService->IsCallBackExists();
533     std::cout << "test IsCallBackExists:" << ret << std::endl;
534     return CELLULAR_CALL_SUCCESS;
535 }
536 
SetMute(const sptr<ImsInterface> & telephonyService) const537 int32_t ImsUnitTest::SetMute(const sptr<ImsInterface> &telephonyService) const
538 {
539     std::cout << "test SetMute entry.\n";
540     int32_t slotId = 0;
541     std::cout << "please enter the mute(0 - 1):";
542     int32_t mute = -1;
543     std::cin >> mute;
544     return telephonyService->SetMute(slotId, mute);
545 }
546 
GetMute(const sptr<ImsInterface> & telephonyService) const547 int32_t ImsUnitTest::GetMute(const sptr<ImsInterface> &telephonyService) const
548 {
549     std::cout << "test GetMute entry.\n";
550     int32_t slotId = 0;
551     return telephonyService->GetMute(slotId);
552 }
553 
SetCallTransfer(const sptr<ImsInterface> & telephonyService) const554 int32_t ImsUnitTest::SetCallTransfer(const sptr<ImsInterface> &telephonyService) const
555 {
556     std::cout << "test SetCallTransfer entry.\n";
557     int32_t slotId = 0;
558     std::cout << "please enter the transfer type(0 - 5):";
559     int32_t type = 0;
560     std::cin >> type;
561     std::cout << "please enter the transfer mode(0 - 4):";
562     int32_t mode = 0;
563     std::cin >> mode;
564     std::cout << "please enter the phone number:";
565     std::string transferNum;
566     std::cin >> transferNum;
567     int32_t classType = 1;
568     return telephonyService->SetCallTransfer(slotId, type, mode, transferNum, classType);
569 }
570 
GetCallTransfer(const sptr<ImsInterface> & telephonyService) const571 int32_t ImsUnitTest::GetCallTransfer(const sptr<ImsInterface> &telephonyService) const
572 {
573     std::cout << "test GetCallTransfer entry.\n";
574     int32_t slotId = 0;
575     std::cout << "please enter the transfer type(0 - 5):";
576     int32_t type = 0;
577     std::cin >> type;
578     return telephonyService->GetCallTransfer(slotId, type);
579 }
580 
SetCallRestriction(const sptr<ImsInterface> & telephonyService) const581 int32_t ImsUnitTest::SetCallRestriction(const sptr<ImsInterface> &telephonyService) const
582 {
583     std::cout << "test SetCallRestriction entry.\n";
584     int32_t slotId = 0;
585     std::cout << "please enter the fac:";
586     std::string fac = "AO";
587     std::cout << "please enter the phone password:";
588     std::string password;
589     std::cin >> password;
590     std::cout << "please enter the mode:";
591     int32_t mode = 0;
592     std::cin >> mode;
593     return telephonyService->SetCallRestriction(slotId, fac, mode, password);
594 }
595 
GetCallRestriction(const sptr<ImsInterface> & telephonyService) const596 int32_t ImsUnitTest::GetCallRestriction(const sptr<ImsInterface> &telephonyService) const
597 {
598     std::cout << "test GetCallRestriction entry.\n";
599     int32_t slotId = 0;
600     std::cout << "please enter the fac:";
601     std::string facType = "AO";
602     return telephonyService->GetCallRestriction(slotId, facType);
603 }
604 
SetCallWaiting(const sptr<ImsInterface> & telephonyService) const605 int32_t ImsUnitTest::SetCallWaiting(const sptr<ImsInterface> &telephonyService) const
606 {
607     std::cout << "test SetCallWaiting entry.\n";
608     bool activate = true;
609     int32_t slotId = 0;
610     return telephonyService->SetCallWaiting(slotId, activate);
611 }
612 
GetCallWaiting(const sptr<ImsInterface> & telephonyService) const613 int32_t ImsUnitTest::GetCallWaiting(const sptr<ImsInterface> &telephonyService) const
614 {
615     std::cout << "test GetCallWaiting entry.\n";
616     int32_t slotId = 0;
617     return telephonyService->GetCallWaiting(slotId);
618 }
619 
InputNumForInterface(const sptr<ImsInterface> & telephonyService) const620 int32_t ImsUnitTest::InputNumForInterface(const sptr<ImsInterface> &telephonyService) const
621 {
622     int32_t ret = -1;
623     int32_t InputNum = 0;
624     int32_t returnNum = 1000; // end loop variable value
625     bool loopFlag = true;
626     while (loopFlag) {
627         std::cout << "\n**********Unit Test Start**********\n"
628                      "Usage: please input a cmd num:\n"
629                      "1:Dial\n2:HangUp\n3:Reject\n4:Answer\n5:HoldCall\n6:UnHoldCall\n7:SwitchCall\n"
630                      "8:CombineConference\n9:InviteToConference\n10:KickOutFromConference\n11:UpdateImsCallMode\n"
631                      "12:IsEmergencyPhoneNumber\n13:GetCallFailReason\n100:StartDtmf\n101:SendDtmf\n102:StopDtmf\n"
632                      "103:StartRtt\n104:StopRtt\n200:SetCallPreferenceMode\n201:GetCallPreferenceMode\n202:"
633                      "SetLteImsSwitchStatus\n203:GetLteImsSwitchStatus\n204:SetImsConfigString\n205:SetImsConfigInt\n"
634                      "206:GetImsConfig\n207:SetImsFeatureValue\n208:GetImsFeatureValue\n209:SetImsSwitchEnhanceMode\n"
635                      "210:GetImsSwitchEnhanceMode\n211:SetMUte\n212:GetMute\n300:CtrlCamera\n301:SetPreviewWindow\n"
636                      "302:SetDisplayWindow\n303:SetCameraZoom\n304:SetPauseImage\n305:SetDeviceDirection\n"
637                      "403:SetCallTransfer\n404:GetCallTransfer\n405:SetCallRestriction\n406:GetCallRestriction\n"
638                      "407:SetCallWaiting\n408:GetCallWaiting\n"
639                      "500:RegisterCellularCallBack\n501:IsCallBackExists\n"
640                      "1000:Exit\n"
641                      "***********************************\n"
642                      "Your choice: ";
643         std::cin >> InputNum;
644         if (InputNum == returnNum) {
645             std::cout << "exiting...\n";
646             break;
647         }
648         auto itFunc = requestFuncMap_.find(InputNum);
649         if (itFunc != requestFuncMap_.end()) {
650             auto requestFunc = itFunc->second;
651             if (requestFunc != nullptr) {
652                 ret = (this->*requestFunc)(telephonyService);
653             }
654         }
655         if (ret != CELLULAR_CALL_SUCCESS) {
656             std::cout << "this execution did not return a successful value, please check.\n";
657             return ret;
658         }
659     }
660     return CELLULAR_CALL_SUCCESS;
661 }
662 
663 /**
664  * @tc.number   ims_vendor_test_001
665  * @tc.name     Test the corresponding functions by entering commands, such as 1 -- Dial, 2 -- Hangup, 3 -- Reject, etc
666  * @tc.desc     Function test
667  */
668 HWTEST_F(ImsUnitTest, ims_vendor_test_001, TestSize.Level0)
669 {
670     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
671     if (systemAbilityMgr == nullptr) {
672         std::cout << "ImsUnitTest return, Get ISystemAbilityManager failed!\n";
673         return;
674     }
675     auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_IMS_SYS_ABILITY_ID);
676     if (remote == nullptr) {
677         std::cout << "ImsUnitTest return, Remote service not exists!\n";
678         return;
679     }
680     auto telephonyService = iface_cast<ImsInterface>(remote);
681     std::cout << "ImsUnitTest HWTEST_F ims_vendor_test_001";
682 }
683 
684 /**
685  * @tc.number   ims_vendor_test_002
686  * @tc.name     Test the corresponding functions by entering commands, such as 1 -- Dial, 2 -- Hangup, 3 -- Reject, etc
687  * @tc.desc     Function test
688  */
689 HWTEST_F(ImsUnitTest, ims_vendor_test_002, TestSize.Level1)
690 {
691     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
692     if (systemAbilityMgr == nullptr) {
693         std::cout << "ImsUnitTest return, Get ISystemAbilityManager failed!\n";
694         return;
695     }
696     auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_IMS_SYS_ABILITY_ID);
697     if (remote == nullptr) {
698         std::cout << "ImsUnitTest return, Remote service not exists!\n";
699         return;
700     }
701     auto telephonyService = iface_cast<ImsInterface>(remote);
702     std::cout << "ImsUnitTest HWTEST_F ims_vendor_test_002";
703 }
704 } // namespace Telephony
705 } // namespace OHOS