• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 <iostream>
19 
20 #include "ims_call_client.h"
21 #include "ims_core_service_client.h"
22 #include "ims_sms_client.h"
23 #include "ims_sms_types.h"
24 #include "ims_test_handler.h"
25 #include "iservice_registry.h"
26 #include "securec.h"
27 #include "system_ability_definition.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 const int32_t IMS_TEST_ERROR = -1;
32 const int32_t IMS_TEST_SUCCESS = 0;
33 const int32_t IMS_TEST_MAX_PASSWORD = 6;
34 
SetUpTestCase(void)35 void ImsUnitTest::SetUpTestCase(void)
36 {
37     // step 3: Set Up Test Case
38 }
39 
TearDownTestCase(void)40 void ImsUnitTest::TearDownTestCase(void)
41 {
42     // step 3: Tear Down Test Case
43 }
44 
SetUp(void)45 void ImsUnitTest::SetUp(void)
46 {
47     // step 3: input testcase setup step
48     InitBasicFuncMap();
49     InitConfigFuncMap();
50     InitVideoCallFuncMap();
51     InitSupplementFuncMap();
52     InitSmsFuncMap();
53     InitCoreServiceFuncMap();
54 }
55 
InitBasicFuncMap(void)56 void ImsUnitTest::InitBasicFuncMap(void)
57 {
58     requestCallFuncMap_[ImsCallInterface::IMS_DIAL] = &ImsUnitTest::Dial;
59     requestCallFuncMap_[ImsCallInterface::IMS_HANG_UP] = &ImsUnitTest::HangUp;
60     requestCallFuncMap_[ImsCallInterface::IMS_REJECT_WITH_REASON] = &ImsUnitTest::RejectWithReason;
61     requestCallFuncMap_[ImsCallInterface::IMS_ANSWER] = &ImsUnitTest::Answer;
62     requestCallFuncMap_[ImsCallInterface::IMS_HOLD] = &ImsUnitTest::HoldCall;
63     requestCallFuncMap_[ImsCallInterface::IMS_UN_HOLD] = &ImsUnitTest::UnHoldCall;
64     requestCallFuncMap_[ImsCallInterface::IMS_SWITCH] = &ImsUnitTest::SwitchCall;
65     requestCallFuncMap_[ImsCallInterface::IMS_COMBINE_CONFERENCE] = &ImsUnitTest::CombineConference;
66     requestCallFuncMap_[ImsCallInterface::IMS_INVITE_TO_CONFERENCE] = &ImsUnitTest::InviteToConference;
67     requestCallFuncMap_[ImsCallInterface::IMS_KICK_OUT_CONFERENCE] = &ImsUnitTest::KickOutFromConference;
68     requestCallFuncMap_[ImsCallInterface::IMS_UPDATE_CALL_MEDIA_MODE] = &ImsUnitTest::UpdateImsCallMode;
69     requestCallFuncMap_[ImsCallInterface::IMS_GET_CALL_DATA] = &ImsUnitTest::GetImsCallsDataRequest;
70     requestCallFuncMap_[ImsCallInterface::IMS_GET_LAST_CALL_FAIL_REASON] = &ImsUnitTest::GetLastCallFailReason;
71     requestCallFuncMap_[ImsCallInterface::IMS_START_DTMF] = &ImsUnitTest::StartDtmf;
72     requestCallFuncMap_[ImsCallInterface::IMS_SEND_DTMF] = &ImsUnitTest::SendDtmf;
73     requestCallFuncMap_[ImsCallInterface::IMS_STOP_DTMF] = &ImsUnitTest::StopDtmf;
74     requestCallFuncMap_[ImsCallInterface::IMS_START_RTT] = &ImsUnitTest::StartRtt;
75     requestCallFuncMap_[ImsCallInterface::IMS_STOP_RTT] = &ImsUnitTest::StopRtt;
76 }
77 
InitConfigFuncMap(void)78 void ImsUnitTest::InitConfigFuncMap(void)
79 {
80     requestCallFuncMap_[ImsCallInterface::IMS_SET_DOMAIN_PREFERENCE_MODE] = &ImsUnitTest::SetDomainPreferenceMode;
81     requestCallFuncMap_[ImsCallInterface::IMS_GET_DOMAIN_PREFERENCE_MODE] = &ImsUnitTest::GetDomainPreferenceMode;
82     requestCallFuncMap_[ImsCallInterface::IMS_SET_SWITCH_STATUS] = &ImsUnitTest::SetImsSwitchStatus;
83     requestCallFuncMap_[ImsCallInterface::IMS_GET_SWITCH_STATUS] = &ImsUnitTest::GetImsSwitchStatus;
84     requestCallFuncMap_[ImsCallInterface::IMS_SET_IMS_CONFIG_STRING] = &ImsUnitTest::SetImsConfigString;
85     requestCallFuncMap_[ImsCallInterface::IMS_SET_IMS_CONFIG_INT] = &ImsUnitTest::SetImsConfigInt;
86     requestCallFuncMap_[ImsCallInterface::IMS_GET_IMS_CONFIG] = &ImsUnitTest::GetImsConfig;
87     requestCallFuncMap_[ImsCallInterface::IMS_SET_IMS_FEATURE] = &ImsUnitTest::SetImsFeatureValue;
88     requestCallFuncMap_[ImsCallInterface::IMS_GET_IMS_FEATURE] = &ImsUnitTest::GetImsFeatureValue;
89     requestCallFuncMap_[ImsCallInterface::IMS_SET_MUTE] = &ImsUnitTest::SetMute;
90     requestCallFuncMap_[ImsCallInterface::IMS_GET_MUTE] = &ImsUnitTest::GetMute;
91 }
92 
InitVideoCallFuncMap(void)93 void ImsUnitTest::InitVideoCallFuncMap(void)
94 {
95     requestCallFuncMap_[ImsCallInterface::IMS_CTRL_CAMERA] = &ImsUnitTest::CtrlCamera;
96     requestCallFuncMap_[ImsCallInterface::IMS_SET_PREVIEW_WINDOW] = &ImsUnitTest::SetPreviewWindow;
97     requestCallFuncMap_[ImsCallInterface::IMS_SET_DISPLAY_WINDOW] = &ImsUnitTest::SetDisplayWindow;
98     requestCallFuncMap_[ImsCallInterface::IMS_SET_CAMERA_ZOOM] = &ImsUnitTest::SetCameraZoom;
99     requestCallFuncMap_[ImsCallInterface::IMS_SET_PAUSE_IMAGE] = &ImsUnitTest::SetPauseImage;
100     requestCallFuncMap_[ImsCallInterface::IMS_SET_DEVICE_DIRECTION] = &ImsUnitTest::SetDeviceDirection;
101 }
102 
InitSupplementFuncMap(void)103 void ImsUnitTest::InitSupplementFuncMap(void)
104 {
105     requestCallFuncMap_[ImsCallInterface::IMS_GET_CLIP] = &ImsUnitTest::GetClip;
106     requestCallFuncMap_[ImsCallInterface::IMS_SET_CLIR] = &ImsUnitTest::SetClir;
107     requestCallFuncMap_[ImsCallInterface::IMS_GET_CLIR] = &ImsUnitTest::GetClir;
108     requestCallFuncMap_[ImsCallInterface::IMS_SET_CALL_TRANSFER] = &ImsUnitTest::SetCallTransfer;
109     requestCallFuncMap_[ImsCallInterface::IMS_GET_CALL_TRANSFER] = &ImsUnitTest::GetCallTransfer;
110     requestCallFuncMap_[ImsCallInterface::IMS_SET_CALL_RESTRICTION] = &ImsUnitTest::SetCallRestriction;
111     requestCallFuncMap_[ImsCallInterface::IMS_GET_CALL_RESTRICTION] = &ImsUnitTest::GetCallRestriction;
112     requestCallFuncMap_[ImsCallInterface::IMS_SET_CALL_WAITING] = &ImsUnitTest::SetCallWaiting;
113     requestCallFuncMap_[ImsCallInterface::IMS_GET_CALL_WAITING] = &ImsUnitTest::GetCallWaiting;
114 }
115 
InitSmsFuncMap(void)116 void ImsUnitTest::InitSmsFuncMap(void)
117 {
118     requestSmsFuncMap_[ImsSmsInterface::IMS_SET_SMS_CONFIG] = &ImsUnitTest::SetSmsConfig;
119     requestSmsFuncMap_[ImsSmsInterface::IMS_GET_SMS_CONFIG] = &ImsUnitTest::GetSmsConfig;
120     requestSmsFuncMap_[ImsSmsInterface::IMS_SEND_MESSAGE] = &ImsUnitTest::SendMessage;
121 }
122 
InitCoreServiceFuncMap(void)123 void ImsUnitTest::InitCoreServiceFuncMap(void)
124 {
125     requestCoreServiceFuncMap_[ImsCoreServiceInterface::IMS_GET_REGISTRATION_STATUS] =
126         &ImsUnitTest::GetImsRegistrationStatus;
127 }
128 
TearDown(void)129 void ImsUnitTest::TearDown(void)
130 {
131     // step 3: input testcase teardown step
132 }
133 
Dial(const sptr<ImsCallInterface> & imsCallPtr) const134 int32_t ImsUnitTest::Dial(const sptr<ImsCallInterface> &imsCallPtr) const
135 {
136     std::cout << "test Dial entry." << std::endl;
137     ImsCallInfo callInfo;
138     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
139         std::cout << "Dial return, memset_s failed." << std::endl;
140         return IMS_TEST_ERROR;
141     }
142     std::cout << "please enter the phone number:";
143     std::cin >> callInfo.phoneNum;
144     callInfo.videoState = 1;
145     callInfo.slotId = 0;
146     CLIRMode mode = CLIRMode::DEFAULT;
147     imsCallPtr->Dial(callInfo, mode);
148     return IMS_TEST_SUCCESS;
149 }
150 
HangUp(const sptr<ImsCallInterface> & imsCallPtr) const151 int32_t ImsUnitTest::HangUp(const sptr<ImsCallInterface> &imsCallPtr) const
152 {
153     std::cout << "test HangUp entry." << std::endl;
154     ImsCallInfo callInfo;
155     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
156         std::cout << "HangUp return, memset_s failed." << std::endl;
157         return IMS_TEST_ERROR;
158     }
159     std::cout << "please enter the phone number:";
160     std::cin >> callInfo.phoneNum;
161     callInfo.videoState = 1;
162     callInfo.slotId = 0;
163     std::cout << "please enter the connect index:";
164     std::cin >> callInfo.index;
165     imsCallPtr->HangUp(callInfo);
166     return IMS_TEST_SUCCESS;
167 }
168 
RejectWithReason(const sptr<ImsCallInterface> & imsCallPtr) const169 int32_t ImsUnitTest::RejectWithReason(const sptr<ImsCallInterface> &imsCallPtr) const
170 {
171     std::cout << "test RejectWithReason entry." << std::endl;
172     ImsCallInfo callInfo;
173     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
174         std::cout << "RejectWithReason return, memset_s failed." << std::endl;
175         return IMS_TEST_ERROR;
176     }
177     std::cout << "please enter the phone number:";
178     std::cin >> callInfo.phoneNum;
179     callInfo.videoState = 1;
180     callInfo.slotId = 0;
181     std::cout << "please enter the connect index:";
182     std::cin >> callInfo.index;
183     imsCallPtr->RejectWithReason(callInfo, ImsRejectReason::USER_DECLINE);
184     return IMS_TEST_SUCCESS;
185 }
186 
Answer(const sptr<ImsCallInterface> & imsCallPtr) const187 int32_t ImsUnitTest::Answer(const sptr<ImsCallInterface> &imsCallPtr) const
188 {
189     std::cout << "test Answer entry." << std::endl;
190     ImsCallInfo callInfo;
191     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
192         std::cout << "Answer return, memset_s failed." << std::endl;
193         return IMS_TEST_ERROR;
194     }
195     std::cout << "please enter the phone number:";
196     std::cin >> callInfo.phoneNum;
197     callInfo.videoState = 1;
198     callInfo.slotId = 0;
199     std::cout << "please enter the connect index:";
200     std::cin >> callInfo.index;
201     imsCallPtr->Answer(callInfo);
202     return IMS_TEST_SUCCESS;
203 }
204 
HoldCall(const sptr<ImsCallInterface> & imsCallPtr) const205 int32_t ImsUnitTest::HoldCall(const sptr<ImsCallInterface> &imsCallPtr) const
206 {
207     std::cout << "test HoldCall entry." << std::endl;
208     int32_t slotId;
209     int32_t callType;
210     std::cout << "please enter the slot id:";
211     std::cin >> slotId;
212     std::cout << "please enter the callType(0->CS, 1->IMS, 2->OTT, 3->OTHER):";
213     std::cin >> callType;
214     imsCallPtr->HoldCall(slotId, callType);
215     return IMS_TEST_SUCCESS;
216 }
217 
UnHoldCall(const sptr<ImsCallInterface> & imsCallPtr) const218 int32_t ImsUnitTest::UnHoldCall(const sptr<ImsCallInterface> &imsCallPtr) const
219 {
220     std::cout << "test UnHoldCall entry." << std::endl;
221     int32_t slotId;
222     int32_t callType;
223     std::cout << "please enter the slot id:";
224     std::cin >> slotId;
225     std::cout << "please enter the callType(0->CS, 1->IMS, 2->OTT, 3->OTHER):";
226     std::cin >> callType;
227     imsCallPtr->UnHoldCall(slotId, callType);
228     return IMS_TEST_SUCCESS;
229 }
230 
SwitchCall(const sptr<ImsCallInterface> & imsCallPtr) const231 int32_t ImsUnitTest::SwitchCall(const sptr<ImsCallInterface> &imsCallPtr) const
232 {
233     std::cout << "test SwitchCall entry." << std::endl;
234     int32_t slotId;
235     int32_t callType;
236     std::cout << "please enter the slot id:";
237     std::cin >> slotId;
238     std::cout << "please enter the callType(0->CS, 1->IMS, 2->OTT, 3->OTHER):";
239     std::cin >> callType;
240     imsCallPtr->SwitchCall(slotId, callType);
241     return IMS_TEST_SUCCESS;
242 }
243 
CombineConference(const sptr<ImsCallInterface> & imsCallPtr) const244 int32_t ImsUnitTest::CombineConference(const sptr<ImsCallInterface> &imsCallPtr) const
245 {
246     std::cout << "test CombineConference entry." << std::endl;
247     std::cout << "please enter the slotId:";
248     int32_t slotId = 0;
249     imsCallPtr->CombineConference(slotId);
250     return IMS_TEST_SUCCESS;
251 }
252 
InviteToConference(const sptr<ImsCallInterface> & imsCallPtr) const253 int32_t ImsUnitTest::InviteToConference(const sptr<ImsCallInterface> &imsCallPtr) const
254 {
255     std::cout << "test InviteToConference entry." << std::endl;
256     std::vector<std::string> numberList;
257     std::cout << "please enter the invite phone number:";
258     std::string phoneNum;
259     std::cin >> phoneNum;
260     numberList.push_back(phoneNum);
261     std::cout << "please enter the slotId:";
262     int32_t slotId = 0;
263     imsCallPtr->InviteToConference(slotId, numberList);
264     return IMS_TEST_SUCCESS;
265 }
266 
KickOutFromConference(const sptr<ImsCallInterface> & imsCallPtr) const267 int32_t ImsUnitTest::KickOutFromConference(const sptr<ImsCallInterface> &imsCallPtr) const
268 {
269     std::cout << "test KickOutFromConference entry." << std::endl;
270     std::vector<std::string> numberList;
271     std::cout << "please enter the kick out phone number:";
272     std::string phoneNum;
273     std::cin >> phoneNum;
274     numberList.push_back(phoneNum);
275     std::cout << "please enter the slotId:";
276     int32_t slotId = 0;
277     imsCallPtr->KickOutFromConference(slotId, numberList);
278     return IMS_TEST_SUCCESS;
279 }
280 
UpdateImsCallMode(const sptr<ImsCallInterface> & imsCallPtr) const281 int32_t ImsUnitTest::UpdateImsCallMode(const sptr<ImsCallInterface> &imsCallPtr) const
282 {
283     std::cout << "test UpdateImsCallMode entry." << std::endl;
284     ImsCallInfo callInfo;
285     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
286         std::cout << "UpdateImsCallMode return, memset_s failed." << std::endl;
287         return IMS_TEST_ERROR;
288     }
289     std::cout << "please enter the phone number:";
290     std::cin >> callInfo.phoneNum;
291     callInfo.videoState = 1;
292     callInfo.slotId = 0;
293     std::cout << "please enter the connect index:";
294     std::cin >> callInfo.index;
295     std::cout << "please enter the update call mode():";
296     int32_t mode = 0;
297     std::cin >> mode;
298     imsCallPtr->UpdateImsCallMode(callInfo, static_cast<ImsCallMode>(mode));
299     return IMS_TEST_SUCCESS;
300 }
301 
GetImsCallsDataRequest(const sptr<ImsCallInterface> & imsCallPtr) const302 int32_t ImsUnitTest::GetImsCallsDataRequest(const sptr<ImsCallInterface> &imsCallPtr) const
303 {
304     std::cout << "please enter the slot id:";
305     int32_t slotId = 0;
306     std::cin >> slotId;
307     std::cout << "please enter the last calls data flag:";
308     int64_t flag = 0;
309     std::cin >> flag;
310     imsCallPtr->GetImsCallsDataRequest(slotId, flag);
311     return IMS_TEST_SUCCESS;
312 }
313 
GetLastCallFailReason(const sptr<ImsCallInterface> & imsCallPtr) const314 int32_t ImsUnitTest::GetLastCallFailReason(const sptr<ImsCallInterface> &imsCallPtr) const
315 {
316     std::cout << "please enter the slot id:";
317     int32_t slotId = 0;
318     std::cin >> slotId;
319     imsCallPtr->GetLastCallFailReason(slotId);
320     return IMS_TEST_SUCCESS;
321 }
322 
StartDtmf(const sptr<ImsCallInterface> & imsCallPtr) const323 int32_t ImsUnitTest::StartDtmf(const sptr<ImsCallInterface> &imsCallPtr) const
324 {
325     std::cout << "test StartDtmf entry." << std::endl;
326     std::cout << "please enter the dtmf code(0-9,#,*,A,D):";
327     char dtmfCode;
328     std::cin >> dtmfCode;
329     std::cout << "please enter the index:";
330     int32_t index = 0;
331     std::cin >> index;
332     std::cout << "please enter the slot id:";
333     int32_t slotId = 0;
334     std::cin >> slotId;
335     imsCallPtr->StartDtmf(slotId, dtmfCode, index);
336     return IMS_TEST_SUCCESS;
337 }
338 
SendDtmf(const sptr<ImsCallInterface> & imsCallPtr) const339 int32_t ImsUnitTest::SendDtmf(const sptr<ImsCallInterface> &imsCallPtr) const
340 {
341     std::cout << "test SendDtmf entry." << std::endl;
342     std::cout << "please enter the dtmf code(0-9,#,*,A,D):";
343     char dtmfCode;
344     std::cin >> dtmfCode;
345     std::cout << "please enter the index:";
346     int32_t index = 0;
347     std::cin >> index;
348     std::cout << "please enter the slot id:";
349     int32_t slotId = 0;
350     std::cin >> slotId;
351     imsCallPtr->SendDtmf(slotId, dtmfCode, index);
352     return IMS_TEST_SUCCESS;
353 }
354 
StopDtmf(const sptr<ImsCallInterface> & imsCallPtr) const355 int32_t ImsUnitTest::StopDtmf(const sptr<ImsCallInterface> &imsCallPtr) const
356 {
357     std::cout << "test StopDtmf entry." << std::endl;
358     std::cout << "please enter the index:";
359     int32_t index = 0;
360     std::cin >> index;
361     std::cout << "please enter the slot id:";
362     int32_t slotId = 0;
363     std::cin >> slotId;
364     imsCallPtr->StopDtmf(slotId, index);
365     return IMS_TEST_SUCCESS;
366 }
367 
StartRtt(const sptr<ImsCallInterface> & imsCallPtr) const368 int32_t ImsUnitTest::StartRtt(const sptr<ImsCallInterface> &imsCallPtr) const
369 {
370     std::cout << "test StartRtt entry." << std::endl;
371     std::cout << "please enter the send msg:";
372     std::string msg;
373     std::cin >> msg;
374     std::cout << "please enter the slot id:";
375     int32_t slotId = 0;
376     std::cin >> slotId;
377     imsCallPtr->StartRtt(slotId, msg);
378     return IMS_TEST_SUCCESS;
379 }
380 
StopRtt(const sptr<ImsCallInterface> & imsCallPtr) const381 int32_t ImsUnitTest::StopRtt(const sptr<ImsCallInterface> &imsCallPtr) const
382 {
383     std::cout << "test StopRtt entry." << std::endl;
384     std::cout << "please enter the slot id:";
385     int32_t slotId = 0;
386     std::cin >> slotId;
387     imsCallPtr->StopRtt(slotId);
388     return IMS_TEST_SUCCESS;
389 }
390 
SetDomainPreferenceMode(const sptr<ImsCallInterface> & imsCallPtr) const391 int32_t ImsUnitTest::SetDomainPreferenceMode(const sptr<ImsCallInterface> &imsCallPtr) const
392 {
393     std::cout << "test SetDomainPreferenceMode entry." << std::endl;
394     std::cout << "please enter the need mode:(1 - 4)";
395     int32_t mode;
396     std::cin >> mode;
397     std::cout << "please enter the slot id:";
398     int32_t slotId = 0;
399     std::cin >> slotId;
400     imsCallPtr->SetDomainPreferenceMode(slotId, mode);
401     return IMS_TEST_SUCCESS;
402 }
403 
GetDomainPreferenceMode(const sptr<ImsCallInterface> & imsCallPtr) const404 int32_t ImsUnitTest::GetDomainPreferenceMode(const sptr<ImsCallInterface> &imsCallPtr) const
405 {
406     std::cout << "test GetDomainPreferenceMode entry." << std::endl;
407     std::cout << "please enter the slot id:";
408     int32_t slotId = 0;
409     std::cin >> slotId;
410     imsCallPtr->GetDomainPreferenceMode(slotId);
411     return IMS_TEST_SUCCESS;
412 }
413 
SetImsSwitchStatus(const sptr<ImsCallInterface> & imsCallPtr) const414 int32_t ImsUnitTest::SetImsSwitchStatus(const sptr<ImsCallInterface> &imsCallPtr) const
415 {
416     std::cout << "test SetImsSwitchStatus entry." << std::endl;
417     std::cout << "please enter the switch state:";
418     bool active;
419     std::cin >> active;
420     std::cout << "please enter the slot id:";
421     int32_t slotId = 0;
422     std::cin >> slotId;
423     imsCallPtr->SetImsSwitchStatus(slotId, active);
424     return IMS_TEST_SUCCESS;
425 }
426 
GetImsSwitchStatus(const sptr<ImsCallInterface> & imsCallPtr) const427 int32_t ImsUnitTest::GetImsSwitchStatus(const sptr<ImsCallInterface> &imsCallPtr) const
428 {
429     std::cout << "test GetImsSwitchStatus entry." << std::endl;
430     std::cout << "please enter the slot id:";
431     int32_t slotId = 0;
432     std::cin >> slotId;
433     imsCallPtr->GetImsSwitchStatus(slotId);
434     return IMS_TEST_SUCCESS;
435 }
436 
SetImsConfigString(const sptr<ImsCallInterface> & imsCallPtr) const437 int32_t ImsUnitTest::SetImsConfigString(const sptr<ImsCallInterface> &imsCallPtr) const
438 {
439     std::cout << "test SetImsConfigString entry." << std::endl;
440     std::cout << "please enter the item id:";
441     int32_t item = 0;
442     std::cin >> item;
443     std::cout << "please enter the item value:";
444     std::string value;
445     std::cin >> value;
446     imsCallPtr->SetImsConfig(static_cast<ImsConfigItem>(item), value);
447     return IMS_TEST_SUCCESS;
448 }
449 
SetImsConfigInt(const sptr<ImsCallInterface> & imsCallPtr) const450 int32_t ImsUnitTest::SetImsConfigInt(const sptr<ImsCallInterface> &imsCallPtr) const
451 {
452     std::cout << "test SetImsConfigInt entry." << std::endl;
453     std::cout << "please enter the item id:";
454     int32_t item = 0;
455     std::cin >> item;
456     std::cout << "please enter the item value:";
457     int32_t value = 0;
458     std::cin >> value;
459     imsCallPtr->SetImsConfig(static_cast<ImsConfigItem>(item), value);
460     return IMS_TEST_SUCCESS;
461 }
462 
GetImsConfig(const sptr<ImsCallInterface> & imsCallPtr) const463 int32_t ImsUnitTest::GetImsConfig(const sptr<ImsCallInterface> &imsCallPtr) const
464 {
465     std::cout << "test GetImsConfig entry." << std::endl;
466     std::cout << "please enter the item id:";
467     int32_t item = 0;
468     std::cin >> item;
469     imsCallPtr->GetImsConfig(static_cast<ImsConfigItem>(item));
470     return IMS_TEST_SUCCESS;
471 }
472 
SetImsFeatureValue(const sptr<ImsCallInterface> & imsCallPtr) const473 int32_t ImsUnitTest::SetImsFeatureValue(const sptr<ImsCallInterface> &imsCallPtr) const
474 {
475     std::cout << "test SetImsFeatureValue entry." << std::endl;
476     std::cout << "please enter the feature type:";
477     int32_t type = 0;
478     std::cin >> type;
479     std::cout << "please enter the feature value:";
480     int32_t value = 0;
481     std::cin >> value;
482     imsCallPtr->SetImsFeatureValue(static_cast<FeatureType>(type), value);
483     return IMS_TEST_SUCCESS;
484 }
485 
GetImsFeatureValue(const sptr<ImsCallInterface> & imsCallPtr) const486 int32_t ImsUnitTest::GetImsFeatureValue(const sptr<ImsCallInterface> &imsCallPtr) const
487 {
488     std::cout << "test GetImsFeatureValue entry." << std::endl;
489     std::cout << "please enter the feature type:";
490     int32_t type = 0;
491     std::cin >> type;
492     int32_t value;
493     imsCallPtr->GetImsFeatureValue(static_cast<FeatureType>(type), value);
494     std::cout << "test GetImsFeatureValue value:" << value;
495     return IMS_TEST_SUCCESS;
496 }
497 
SetMute(const sptr<ImsCallInterface> & imsCallPtr) const498 int32_t ImsUnitTest::SetMute(const sptr<ImsCallInterface> &imsCallPtr) const
499 {
500     std::cout << "test SetMute entry.\n";
501     int32_t slotId = 0;
502     std::cout << "please enter the mute(0 - 1):";
503     int32_t mute = -1;
504     std::cin >> mute;
505     return imsCallPtr->SetMute(slotId, mute);
506 }
507 
GetMute(const sptr<ImsCallInterface> & imsCallPtr) const508 int32_t ImsUnitTest::GetMute(const sptr<ImsCallInterface> &imsCallPtr) const
509 {
510     std::cout << "test GetMute entry.\n";
511     int32_t slotId = 0;
512     return imsCallPtr->GetMute(slotId);
513 }
514 
CtrlCamera(const sptr<ImsCallInterface> & imsCallPtr) const515 int32_t ImsUnitTest::CtrlCamera(const sptr<ImsCallInterface> &imsCallPtr) const
516 {
517     std::cout << "test CtrlCamera entry." << std::endl;
518     std::u16string cameraId = u"cameraId";
519     int32_t callingUid = 0;
520     int32_t callingPid = 0;
521     imsCallPtr->CtrlCamera(cameraId, callingUid, callingPid);
522     return IMS_TEST_SUCCESS;
523 }
524 
SetPreviewWindow(const sptr<ImsCallInterface> & imsCallPtr) const525 int32_t ImsUnitTest::SetPreviewWindow(const sptr<ImsCallInterface> &imsCallPtr) const
526 {
527     std::cout << "test SetPreviewWindow entry." << std::endl;
528     int32_t x = 0;
529     int32_t y = 0;
530     int32_t z = 0;
531     int32_t width = 0;
532     int32_t height = 0;
533     imsCallPtr->SetPreviewWindow(x, y, z, width, height);
534     return IMS_TEST_SUCCESS;
535 }
536 
SetDisplayWindow(const sptr<ImsCallInterface> & imsCallPtr) const537 int32_t ImsUnitTest::SetDisplayWindow(const sptr<ImsCallInterface> &imsCallPtr) const
538 {
539     std::cout << "test SetDisplayWindow entry." << std::endl;
540     int32_t x = 0;
541     int32_t y = 0;
542     int32_t z = 0;
543     int32_t width = 0;
544     int32_t height = 0;
545     imsCallPtr->SetDisplayWindow(x, y, z, width, height);
546     return IMS_TEST_SUCCESS;
547 }
548 
SetCameraZoom(const sptr<ImsCallInterface> & imsCallPtr) const549 int32_t ImsUnitTest::SetCameraZoom(const sptr<ImsCallInterface> &imsCallPtr) const
550 {
551     std::cout << "test SetCameraZoom entry." << std::endl;
552     float zoomRatio = 1.0;
553     imsCallPtr->SetCameraZoom(zoomRatio);
554     return IMS_TEST_SUCCESS;
555 }
556 
SetPauseImage(const sptr<ImsCallInterface> & imsCallPtr) const557 int32_t ImsUnitTest::SetPauseImage(const sptr<ImsCallInterface> &imsCallPtr) const
558 {
559     std::cout << "test SetPauseImage entry." << std::endl;
560     std::u16string path = u"path";
561     imsCallPtr->SetPauseImage(path);
562     return IMS_TEST_SUCCESS;
563 }
564 
SetDeviceDirection(const sptr<ImsCallInterface> & imsCallPtr) const565 int32_t ImsUnitTest::SetDeviceDirection(const sptr<ImsCallInterface> &imsCallPtr) const
566 {
567     std::cout << "test SetDeviceDirection entry." << std::endl;
568     int32_t rotation = 0;
569     imsCallPtr->SetDeviceDirection(rotation);
570     return IMS_TEST_SUCCESS;
571 }
572 
GetClip(const sptr<ImsCallInterface> & imsCallPtr) const573 int32_t ImsUnitTest::GetClip(const sptr<ImsCallInterface> &imsCallPtr) const
574 {
575     std::cout << "please enter the slot id:";
576     int32_t slotId = 0;
577     std::cin >> slotId;
578     imsCallPtr->GetClip(slotId);
579     return IMS_TEST_SUCCESS;
580 }
581 
SetClir(const sptr<ImsCallInterface> & imsCallPtr) const582 int32_t ImsUnitTest::SetClir(const sptr<ImsCallInterface> &imsCallPtr) const
583 {
584     std::cout << "please enter the slot id:";
585     int32_t slotId = 0;
586     std::cin >> slotId;
587     std::cout << "please enter the action:";
588     int32_t action = 0;
589     std::cin >> action;
590     imsCallPtr->SetClir(slotId, action);
591     return IMS_TEST_SUCCESS;
592 }
593 
GetClir(const sptr<ImsCallInterface> & imsCallPtr) const594 int32_t ImsUnitTest::GetClir(const sptr<ImsCallInterface> &imsCallPtr) const
595 {
596     std::cout << "please enter the slot id:";
597     int32_t slotId = 0;
598     std::cin >> slotId;
599     imsCallPtr->GetClir(slotId);
600     return IMS_TEST_SUCCESS;
601 }
602 
SetCallTransfer(const sptr<ImsCallInterface> & imsCallPtr) const603 int32_t ImsUnitTest::SetCallTransfer(const sptr<ImsCallInterface> &imsCallPtr) const
604 {
605     std::cout << "test SetCallTransfer entry.\n";
606     int32_t slotId = 0;
607     std::cout << "please enter the transfer type(0 - 5):";
608     int32_t type = 0;
609     std::cin >> type;
610     std::cout << "please enter the transfer mode(0 - 4):";
611     int32_t mode = 0;
612     std::cin >> mode;
613     std::cout << "please enter the phone number:";
614     std::string transferNum;
615     std::cin >> transferNum;
616     int32_t classType = 1;
617     return imsCallPtr->SetCallTransfer(slotId, type, mode, transferNum, classType);
618 }
619 
GetCallTransfer(const sptr<ImsCallInterface> & imsCallPtr) const620 int32_t ImsUnitTest::GetCallTransfer(const sptr<ImsCallInterface> &imsCallPtr) const
621 {
622     std::cout << "test GetCallTransfer entry.\n";
623     int32_t slotId = 0;
624     std::cout << "please enter the transfer type(0 - 5):";
625     int32_t type = 0;
626     std::cin >> type;
627     return imsCallPtr->GetCallTransfer(slotId, type);
628 }
629 
SetCallRestriction(const sptr<ImsCallInterface> & imsCallPtr) const630 int32_t ImsUnitTest::SetCallRestriction(const sptr<ImsCallInterface> &imsCallPtr) const
631 {
632     std::cout << "test SetCallRestriction entry.\n";
633     int32_t slotId = 0;
634     std::cout << "please enter the fac:";
635     std::string fac = "AO";
636     std::cout << "please enter the call restriction password:";
637     char password[IMS_TEST_MAX_PASSWORD] = { 0 };
638     std::cin >> password;
639     std::cout << "please enter the mode:";
640     int32_t mode = 0;
641     std::cin >> mode;
642     int32_t ret = imsCallPtr->SetCallRestriction(slotId, fac, mode, password);
643     memset_s(password, sizeof(password), 0, sizeof(password));
644     return ret;
645 }
646 
GetCallRestriction(const sptr<ImsCallInterface> & imsCallPtr) const647 int32_t ImsUnitTest::GetCallRestriction(const sptr<ImsCallInterface> &imsCallPtr) const
648 {
649     std::cout << "test GetCallRestriction entry.\n";
650     int32_t slotId = 0;
651     std::cout << "please enter the fac:";
652     std::string facType = "AO";
653     return imsCallPtr->GetCallRestriction(slotId, facType);
654 }
655 
SetCallWaiting(const sptr<ImsCallInterface> & imsCallPtr) const656 int32_t ImsUnitTest::SetCallWaiting(const sptr<ImsCallInterface> &imsCallPtr) const
657 {
658     std::cout << "test SetCallWaiting entry.\n";
659     bool activate = true;
660     int32_t slotId = 0;
661     return imsCallPtr->SetCallWaiting(slotId, activate, ServiceClassType::VOICE);
662 }
663 
GetCallWaiting(const sptr<ImsCallInterface> & imsCallPtr) const664 int32_t ImsUnitTest::GetCallWaiting(const sptr<ImsCallInterface> &imsCallPtr) const
665 {
666     std::cout << "test GetCallWaiting entry.\n";
667     int32_t slotId = 0;
668     return imsCallPtr->GetCallWaiting(slotId);
669 }
670 
SetSmsConfig(const sptr<ImsSmsInterface> & imsSmsPtr) const671 int32_t ImsUnitTest::SetSmsConfig(const sptr<ImsSmsInterface> &imsSmsPtr) const
672 {
673     std::cout << "test SetSmsConfig entry.\n";
674     int32_t slotId = 0;
675     int32_t imsSmsConfig = 1;
676     return imsSmsPtr->ImsSetSmsConfig(slotId, imsSmsConfig);
677 }
678 
GetSmsConfig(const sptr<ImsSmsInterface> & imsSmsPtr) const679 int32_t ImsUnitTest::GetSmsConfig(const sptr<ImsSmsInterface> &imsSmsPtr) const
680 {
681     std::cout << "test GetSmsConfig entry.\n";
682     int32_t slotId = 0;
683     return imsSmsPtr->ImsGetSmsConfig(slotId);
684 }
685 
SendMessage(const sptr<ImsSmsInterface> & imsSmsPtr) const686 int32_t ImsUnitTest::SendMessage(const sptr<ImsSmsInterface> &imsSmsPtr) const
687 {
688     std::cout << "test SendMessage entry.\n";
689     int32_t slotId = 0;
690     ImsMessageInfo imsMessageInfo;
691     imsMessageInfo.refId = 1;
692     return imsSmsPtr->ImsSendMessage(slotId, imsMessageInfo);
693 }
694 
GetImsRegistrationStatus(const sptr<ImsCoreServiceInterface> & imsCoreSerivcePtr) const695 int32_t ImsUnitTest::GetImsRegistrationStatus(const sptr<ImsCoreServiceInterface> &imsCoreSerivcePtr) const
696 {
697     std::cout << "test GetImsRegistrationStatus entry.\n";
698     int32_t slotId = 0;
699     return imsCoreSerivcePtr->GetImsRegistrationStatus(slotId);
700 }
701 
ImsCallTest() const702 int32_t ImsUnitTest::ImsCallTest() const
703 {
704     auto imsCallPtr = DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
705     if (imsCallPtr == nullptr) {
706         std::cout << "\nimsCallPtr is nullptr, Init ImsCall Failed!\n";
707         return IMS_TEST_ERROR;
708     }
709     std::shared_ptr<ImsTestHandler> handler = std::make_shared<ImsTestHandler>();
710     handler->RegisterImsCall();
711     int32_t ret = -1;
712     int32_t InputNum = 0;
713     int32_t returnNum = 1000; //  end loop variable value
714     bool loopFlag = true;
715     while (loopFlag) {
716         std::cout << "\n**********Unit Test Start**********\n"
717                      "Usage: please input a cmd num:\n"
718                      "1:Dial\n2:HangUp\n3:RejectWithReason\n4:Answer\n5:HoldCall\n6:UnHoldCall\n7:SwitchCall\n"
719                      "8:CombineConference\n9:InviteToConference\n10:KickOutFromConference\n11:UpdateImsCallMode\n"
720                      "13:GetImsCallsDataRequest\n14:GetLastCallFailReason\n100:StartDtmf\n101:SendDtmf\n102:StopDtmf\n"
721                      "103:StartRtt\n104:StopRtt\n200:SetCallPreferenceMode\n201:GetCallPreferenceMode\n202:"
722                      "SetImsSwitchStatus\n203:GetImsSwitchStatus\n204:SetImsConfigString\n205:SetImsConfigInt\n"
723                      "206:GetImsConfig\n207:SetImsFeatureValue\n208:GetImsFeatureValue\n"
724                      "209:SetMute\n210:GetMute\n300:CtrlCamera\n301:SetPreviewWindow\n"
725                      "302:SetDisplayWindow\n303:SetCameraZoom\n304:SetPauseImage\n305:SetDeviceDirection\n"
726                      "400:GetClip\n401:SetClir\n402:GetClir\n"
727                      "403:SetCallTransfer\n404:GetCallTransfer\n405:SetCallRestriction\n406:GetCallRestriction\n"
728                      "407:SetCallWaiting\n408:GetCallWaiting\n"
729                      "500:RegisterCellularCallBack\n501:IsCallBackExists\n"
730                      "1000:Exit\n"
731                      "***********************************\n"
732                      "Your choice: ";
733         std::cin >> InputNum;
734         if (InputNum == returnNum) {
735             std::cout << "exiting...\n";
736             break;
737         }
738         auto itFunc = requestCallFuncMap_.find(InputNum);
739         if (itFunc != requestCallFuncMap_.end()) {
740             auto requestFunc = itFunc->second;
741             if (requestFunc != nullptr) {
742                 ret = (this->*requestFunc)(imsCallPtr);
743             }
744         }
745         if (ret != IMS_TEST_SUCCESS) {
746             std::cout << "this execution did not return a successful value, please check.\n";
747             return ret;
748         }
749     }
750     return IMS_TEST_SUCCESS;
751 }
752 
ImsSmsTest() const753 int32_t ImsUnitTest::ImsSmsTest() const
754 {
755     auto imsSmsPtr = DelayedSingleton<ImsSmsClient>::GetInstance()->GetImsSmsProxy();
756     if (imsSmsPtr == nullptr) {
757         std::cout << "\nimsSmsPtr is nullptr, Init ImsSms Failed!\n";
758         return IMS_TEST_ERROR;
759     }
760     std::shared_ptr<ImsTestHandler> handler = std::make_shared<ImsTestHandler>();
761     handler->RegisterImsSms();
762     int32_t ret = -1;
763     int32_t InputNum = 0;
764     int32_t returnNum = 1000; //  end loop variable value
765     bool loopFlag = true;
766     while (loopFlag) {
767         std::cout << "\n**********Unit Test Start**********\n"
768                      "Usage: please input a cmd num:\n"
769                      "0:SendMessage\n"
770                      "100:SetSmsConfig\n"
771                      "101:GetSmsConfig\n"
772                      "1000:Exit\n"
773                      "***********************************\n"
774                      "Your choice: ";
775         std::cin >> InputNum;
776         if (InputNum == returnNum) {
777             std::cout << "exiting...\n";
778             break;
779         }
780         auto itFunc = requestSmsFuncMap_.find(InputNum);
781         if (itFunc != requestSmsFuncMap_.end()) {
782             auto requestFunc = itFunc->second;
783             if (requestFunc != nullptr) {
784                 ret = (this->*requestFunc)(imsSmsPtr);
785             }
786         }
787         if (ret != IMS_TEST_SUCCESS) {
788             std::cout << "this execution did not return a successful value, please check.\n";
789             return ret;
790         }
791     }
792     return IMS_TEST_SUCCESS;
793 }
794 
ImsCoreServiceTest() const795 int32_t ImsUnitTest::ImsCoreServiceTest() const
796 {
797     auto imsCoreSerivcePtr = DelayedSingleton<ImsCoreServiceClient>::GetInstance()->GetImsCoreServiceProxy();
798     if (imsCoreSerivcePtr == nullptr) {
799         std::cout << "\nimsCoreSerivcePtr is nullptr, Init ImsCoreService Failed!\n";
800         return IMS_TEST_ERROR;
801     }
802     std::shared_ptr<ImsTestHandler> handler = std::make_shared<ImsTestHandler>();
803     handler->RegisterImsCoreService();
804     int32_t ret = -1;
805     int32_t InputNum = 0;
806     int32_t returnNum = 1000; //  end loop variable value
807     bool loopFlag = true;
808     while (loopFlag) {
809         std::cout << "\n**********Unit Test Start**********\n"
810                      "Usage: please input a cmd num:\n"
811                      "0:GetImsRegistrationStatus\n"
812                      "1000:Exit\n"
813                      "***********************************\n"
814                      "Your choice: ";
815         std::cin >> InputNum;
816         if (InputNum == returnNum) {
817             std::cout << "exiting...\n";
818             break;
819         }
820         auto itFunc = requestCoreServiceFuncMap_.find(InputNum);
821         if (itFunc != requestCoreServiceFuncMap_.end()) {
822             auto requestFunc = itFunc->second;
823             if (requestFunc != nullptr) {
824                 ret = (this->*requestFunc)(imsCoreSerivcePtr);
825             }
826         }
827         if (ret != IMS_TEST_SUCCESS) {
828             std::cout << "this execution did not return a successful value, please check.\n";
829             return ret;
830         }
831     }
832     return IMS_TEST_SUCCESS;
833 }
834 } // namespace Telephony
835 } // namespace OHOS
836 
837 using namespace OHOS::Telephony;
main()838 int32_t main()
839 {
840     std::unique_ptr<ImsUnitTest> test = std::make_unique<ImsUnitTest>();
841     const int32_t callTest = 1;
842     const int32_t smsTest = 2;
843     const int32_t coreServiceTest = 3;
844     const int32_t codeExit = 1000;
845     int32_t code;
846     test->SetUp();
847     std::cout << "Please select interface type...." << std::endl;
848     while (true) {
849         std::cout << "\n1:ims call interface\n"
850                   << "2:ims sms interface\n"
851                   << "3:ims core service interface\n"
852                   << "1000:exit\n";
853         std::cin >> code;
854         switch (code) {
855             case callTest:
856                 test->ImsCallTest();
857                 break;
858             case smsTest:
859                 test->ImsSmsTest();
860                 break;
861             case coreServiceTest:
862                 test->ImsCoreServiceTest();
863                 break;
864             case codeExit:
865                 break;
866             default:
867                 std::cout << "invalid input" << std::endl;
868                 break;
869         }
870         if (code == codeExit) {
871             break;
872         }
873     }
874     return OHOS::Telephony::TELEPHONY_SUCCESS;
875 }
876